use preference value

pull/646/head
asdoi 5 years ago
parent a59321e03e
commit c79916de01

@ -59,6 +59,7 @@ class ListHabitsActivity : HabitsActivity() {
override fun onResume() { override fun onResume() {
adapter.refresh() adapter.refresh()
adapter.notifyDataSetChanged()
screen.onAttached() screen.onAttached()
rootView.postInvalidate() rootView.postInvalidate()
midnightTimer.onResume() midnightTimer.onResume()

@ -33,6 +33,7 @@ import org.isoron.androidbase.activities.*
import org.isoron.uhabits.* import org.isoron.uhabits.*
import org.isoron.uhabits.activities.common.views.* import org.isoron.uhabits.activities.common.views.*
import org.isoron.uhabits.core.models.* import org.isoron.uhabits.core.models.*
import org.isoron.uhabits.core.preferences.Preferences
import org.isoron.uhabits.core.ui.screens.habits.list.* import org.isoron.uhabits.core.ui.screens.habits.list.*
import org.isoron.uhabits.core.utils.* import org.isoron.uhabits.core.utils.*
import org.isoron.uhabits.utils.* import org.isoron.uhabits.utils.*
@ -40,6 +41,7 @@ import org.isoron.uhabits.utils.*
@AutoFactory @AutoFactory
class HabitCardView( class HabitCardView(
@Provided @ActivityContext context: Context, @Provided @ActivityContext context: Context,
@Provided private val preferences: Preferences,
@Provided private val checkmarkPanelFactory: CheckmarkPanelViewFactory, @Provided private val checkmarkPanelFactory: CheckmarkPanelViewFactory,
@Provided private val numberPanelFactory: NumberPanelViewFactory, @Provided private val numberPanelFactory: NumberPanelViewFactory,
@Provided private val behavior: ListHabitsBehavior @Provided private val behavior: ListHabitsBehavior
@ -89,7 +91,7 @@ class HabitCardView(
set(values) { set(values) {
checkmarkPanel.values = values checkmarkPanel.values = values
numberPanel.values = values.map { it / 1000.0 }.toDoubleArray() numberPanel.values = values.map { it / 1000.0 }.toDoubleArray()
if (habit?.isNumerical == false) { if (habit?.isNumerical == false && scoreAsText) {
streakText.apply { streakText.apply {
visibility = if (values[0] == 0) View.GONE else View.VISIBLE visibility = if (values[0] == 0) View.GONE else View.VISIBLE
} }
@ -102,6 +104,9 @@ class HabitCardView(
numberPanel.threshold = value numberPanel.threshold = value
} }
private val scoreAsText: Boolean
get() = preferences.scoreAsText
private var checkmarkPanel: CheckmarkPanelView private var checkmarkPanel: CheckmarkPanelView
private var numberPanel: NumberPanelView private var numberPanel: NumberPanelView
private var innerFrame: LinearLayout private var innerFrame: LinearLayout
@ -110,8 +115,6 @@ class HabitCardView(
private var scoreText: TextView private var scoreText: TextView
private var streakText: TextView private var streakText: TextView
private val showScoreText = true //Use value from Preferences.getScoreAsText()
init { init {
scoreRing = RingView(context).apply { scoreRing = RingView(context).apply {
val thickness = dp(3f) val thickness = dp(3f)
@ -174,11 +177,9 @@ class HabitCardView(
layoutParams = LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT) layoutParams = LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT)
if (SDK_INT >= LOLLIPOP) elevation = dp(1f) if (SDK_INT >= LOLLIPOP) elevation = dp(1f)
if (showScoreText) { addView(scoreText)
addView(scoreText) addView(streakText)
addView(streakText) addView(scoreRing)
} else
addView(scoreRing)
addView(label) addView(label)
addView(checkmarkPanel) addView(checkmarkPanel)
addView(numberPanel) addView(numberPanel)
@ -243,12 +244,14 @@ class HabitCardView(
} }
scoreRing.apply { scoreRing.apply {
color = c color = c
visibility = if (scoreAsText) View.GONE else View.VISIBLE
} }
scoreText.apply { scoreText.apply {
setTextColor(c) setTextColor(c)
visibility = if (scoreAsText) View.VISIBLE else View.GONE
} }
if (!h.isNumerical) { if (!h.isNumerical && scoreAsText) {
val streaks = h.streaks.all val streaks = h.streaks.all
var isLastStreakBestStreak = false var isLastStreakBestStreak = false
val lastStreak = val lastStreak =

Loading…
Cancel
Save