StackWidget: Raise exception instead of returning invalid default value

pull/1050/head
Alinson S. Xavier 4 years ago
parent b54711243f
commit d0ef749f19
No known key found for this signature in database
GPG Key ID: DCA0DAD4D2F58624

@ -93,20 +93,20 @@ internal class StackRemoteViewsFactory(private val context: Context, intent: Int
habit: Habit, habit: Habit,
prefs: Preferences prefs: Preferences
): BaseWidget { ): BaseWidget {
when (widgetType) { return when (widgetType) {
StackWidgetType.CHECKMARK -> return CheckmarkWidget(context, widgetId, habit, true) StackWidgetType.CHECKMARK -> CheckmarkWidget(context, widgetId, habit, true)
StackWidgetType.FREQUENCY -> return FrequencyWidget( StackWidgetType.FREQUENCY -> FrequencyWidget(
context, context,
widgetId, widgetId,
habit, habit,
prefs.firstWeekdayInt, prefs.firstWeekdayInt,
true true
) )
StackWidgetType.SCORE -> return ScoreWidget(context, widgetId, habit, true) StackWidgetType.SCORE -> ScoreWidget(context, widgetId, habit, true)
StackWidgetType.HISTORY -> return HistoryWidget(context, widgetId, habit, true) StackWidgetType.HISTORY -> HistoryWidget(context, widgetId, habit, true)
StackWidgetType.STREAKS -> return StreakWidget(context, widgetId, habit, true) StackWidgetType.STREAKS -> StreakWidget(context, widgetId, habit, true)
else -> throw IllegalStateException()
} }
throw IllegalStateException()
} }
override fun getLoadingView(): RemoteViews { override fun getLoadingView(): RemoteViews {

@ -19,10 +19,8 @@
package org.isoron.uhabits.widgets package org.isoron.uhabits.widgets
import org.isoron.uhabits.R import org.isoron.uhabits.R
import java.lang.IllegalStateException
/**
* Created by victoryu on 11/3/17.
*/
enum class StackWidgetType(val value: Int) { enum class StackWidgetType(val value: Int) {
CHECKMARK(0), FREQUENCY(1), SCORE(2), // habit strength widget CHECKMARK(0), FREQUENCY(1), SCORE(2), // habit strength widget
HISTORY(3), STREAKS(4), TARGET(5); HISTORY(3), STREAKS(4), TARGET(5);
@ -36,44 +34,44 @@ enum class StackWidgetType(val value: Int) {
HISTORY.value == value -> HISTORY HISTORY.value == value -> HISTORY
STREAKS.value == value -> STREAKS STREAKS.value == value -> STREAKS
TARGET.value == value -> TARGET TARGET.value == value -> TARGET
else -> null else -> throw IllegalStateException()
} }
} }
fun getStackWidgetLayoutId(type: StackWidgetType?): Int { fun getStackWidgetLayoutId(type: StackWidgetType?): Int {
when (type) { return when (type) {
CHECKMARK -> return R.layout.checkmark_stackview_widget CHECKMARK -> R.layout.checkmark_stackview_widget
FREQUENCY -> return R.layout.frequency_stackview_widget FREQUENCY -> R.layout.frequency_stackview_widget
SCORE -> return R.layout.score_stackview_widget SCORE -> R.layout.score_stackview_widget
HISTORY -> return R.layout.history_stackview_widget HISTORY -> R.layout.history_stackview_widget
STREAKS -> return R.layout.streak_stackview_widget STREAKS -> R.layout.streak_stackview_widget
TARGET -> return R.layout.target_stackview_widget TARGET -> R.layout.target_stackview_widget
else -> throw IllegalStateException()
} }
return 0
} }
fun getStackWidgetAdapterViewId(type: StackWidgetType?): Int { fun getStackWidgetAdapterViewId(type: StackWidgetType?): Int {
when (type) { return when (type) {
CHECKMARK -> return R.id.checkmarkStackWidgetView CHECKMARK -> R.id.checkmarkStackWidgetView
FREQUENCY -> return R.id.frequencyStackWidgetView FREQUENCY -> R.id.frequencyStackWidgetView
SCORE -> return R.id.scoreStackWidgetView SCORE -> R.id.scoreStackWidgetView
HISTORY -> return R.id.historyStackWidgetView HISTORY -> R.id.historyStackWidgetView
STREAKS -> return R.id.streakStackWidgetView STREAKS -> R.id.streakStackWidgetView
TARGET -> return R.id.targetStackWidgetView TARGET -> R.id.targetStackWidgetView
else -> throw IllegalStateException()
} }
return 0
} }
fun getStackWidgetEmptyViewId(type: StackWidgetType?): Int { fun getStackWidgetEmptyViewId(type: StackWidgetType?): Int {
when (type) { return when (type) {
CHECKMARK -> return R.id.checkmarkStackWidgetEmptyView CHECKMARK -> R.id.checkmarkStackWidgetEmptyView
FREQUENCY -> return R.id.frequencyStackWidgetEmptyView FREQUENCY -> R.id.frequencyStackWidgetEmptyView
SCORE -> return R.id.scoreStackWidgetEmptyView SCORE -> R.id.scoreStackWidgetEmptyView
HISTORY -> return R.id.historyStackWidgetEmptyView HISTORY -> R.id.historyStackWidgetEmptyView
STREAKS -> return R.id.streakStackWidgetEmptyView STREAKS -> R.id.streakStackWidgetEmptyView
TARGET -> return R.id.targetStackWidgetEmptyView TARGET -> R.id.targetStackWidgetEmptyView
else -> throw IllegalStateException()
} }
return 0
} }
} }
} }

Loading…
Cancel
Save