Skip to content

Commit

Permalink
Use 'entered' instead of 'completed' when ? or skips are enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqua authored and iSoron committed Aug 6, 2021
1 parent 7fe3ce9 commit f8c7abf
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 8 deletions.
Expand Up @@ -38,7 +38,7 @@ import org.isoron.uhabits.inject.ActivityContextModule
import org.isoron.uhabits.inject.DaggerHabitsActivityComponent
import org.isoron.uhabits.utils.restartWithFade

class ListHabitsActivity : AppCompatActivity() {
class ListHabitsActivity : AppCompatActivity(), Preferences.Listener {

var pureBlack: Boolean = false
lateinit var taskRunner: TaskRunner
Expand All @@ -51,6 +51,10 @@ class ListHabitsActivity : AppCompatActivity() {

private lateinit var menu: ListHabitsMenu

override fun onQuestionMarksChanged() {
invalidateOptionsMenu()
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand All @@ -63,6 +67,7 @@ class ListHabitsActivity : AppCompatActivity() {
component.themeSwitcher.apply()

prefs = appComponent.preferences
prefs.addListener(this)
pureBlack = prefs.isPureBlackEnabled
midnightTimer = appComponent.midnightTimer
rootView = component.listHabitsRootView
Expand Down
Expand Up @@ -52,6 +52,11 @@ class ListHabitsMenu @Inject constructor(
nightModeItem.isChecked = themeSwitcher.isNightMode
hideArchivedItem.isChecked = !preferences.showArchived
hideCompletedItem.isChecked = !preferences.showCompleted
if (preferences.areQuestionMarksEnabled || preferences.isSkipEnabled) {
hideCompletedItem.title = activity.resources.getString(R.string.hide_entered)
} else {
hideCompletedItem.title = activity.resources.getString(R.string.hide_completed)
}
updateArrows(menu)
}

Expand Down
Expand Up @@ -131,7 +131,7 @@ class CheckmarkButtonView(
paint.color = when (value) {
YES_MANUAL, YES_AUTO, SKIP -> color
NO -> {
if (preferences.areQuestionMarksEnabled()) mediumContrastColor
if (preferences.areQuestionMarksEnabled) mediumContrastColor
else lowContrastColor
}
else -> lowContrastColor
Expand All @@ -140,7 +140,7 @@ class CheckmarkButtonView(
SKIP -> R.string.fa_skipped
NO -> R.string.fa_times
UNKNOWN -> {
if (preferences.areQuestionMarksEnabled()) R.string.fa_question
if (preferences.areQuestionMarksEnabled) R.string.fa_question
else R.string.fa_times
}
else -> R.string.fa_check
Expand Down
Expand Up @@ -169,7 +169,7 @@ class NumberButtonView(
typeface = BOLD_TYPEFACE
textSize = dim(R.dimen.smallTextSize)
}
preferences.areQuestionMarksEnabled() -> {
preferences.areQuestionMarksEnabled -> {
label = resources.getString(R.string.fa_question)
typeface = getFontAwesome()
textSize = dim(R.dimen.smallerTextSize)
Expand Down
Expand Up @@ -92,6 +92,9 @@ class SharedPreferencesStorage
preferences.setNotificationsSticky(getBoolean(key, false))
"pref_led_notifications" ->
preferences.setNotificationsLed(getBoolean(key, false))
"pref_unknown_enabled" -> {
preferences.areQuestionMarksEnabled = getBoolean(key, false)
}
}
sharedPreferences.registerOnSharedPreferenceChangeListener(this)
}
Expand Down
Expand Up @@ -102,7 +102,7 @@ class CheckmarkWidgetView : HabitWidgetView {
SKIP -> resources.getString(R.string.fa_skipped)
UNKNOWN -> {
run {
if (preferences!!.areQuestionMarksEnabled()) {
if (preferences!!.areQuestionMarksEnabled) {
return resources.getString(R.string.fa_question)
} else {
resources.getString(R.string.fa_times)
Expand Down
1 change: 1 addition & 0 deletions uhabits-android/src/main/res/values/strings.xml
Expand Up @@ -161,6 +161,7 @@
<string name="none">None</string>
<string name="filter">Filter</string>
<string name="hide_completed">Hide completed</string>
<string name="hide_entered">Hide entered</string>

This comment has been minimized.

Copy link
@KristianTashkov

KristianTashkov Aug 6, 2021

Contributor

Isn't this a bit confusing since YES_AUTO is grouped under this new "entered" category even though it's an implicit value and not specifically entered? @iSoron @hiqua

<string name="hide_archived">Hide archived</string>
<string name="sticky_notifications">Make notifications sticky</string>
<string name="sticky_notifications_description">Prevents notifications from being swiped away.</string>
Expand Down
Expand Up @@ -205,9 +205,12 @@ open class Preferences(private val storage: Storage) {
storage.putBoolean("pref_skip_enabled", value)
}

fun areQuestionMarksEnabled(): Boolean {
return storage.getBoolean("pref_unknown_enabled", false)
}
var areQuestionMarksEnabled: Boolean
get() = storage.getBoolean("pref_unknown_enabled", false)
set(value) {
storage.putBoolean("pref_unknown_enabled", value)
for (l in listeners) l.onQuestionMarksChanged()
}

/**
* @return An integer representing the first day of the week. Sunday
Expand Down Expand Up @@ -240,6 +243,7 @@ open class Preferences(private val storage: Storage) {
interface Listener {
fun onCheckmarkSequenceChanged() {}
fun onNotificationsChanged() {}
fun onQuestionMarksChanged() {}
}

interface Storage {
Expand Down

0 comments on commit f8c7abf

Please sign in to comment.