Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,31 @@ internal class SettingsPreferenceLoader(fragment: PreferenceFragmentCompat) : Ba
}

findPreference(R.string.preference_key_selected_app_icon).let {
it.isVisible = true // TODO - something based on YiR state
it.isVisible = YearInReviewViewModel.isCustomIconAllowed
it.summary = fragment.getString(R.string.settings_app_icon_preference_subtitle, YearInReviewViewModel.YIR_YEAR)
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
ExclusiveBottomSheetPresenter.show(fragment.parentFragmentManager, AppIconDialog())
true
}
}

findPreference(R.string.preference_key_year_in_review_is_enabled).onPreferenceChangeListener = Preference.OnPreferenceChangeListener { preference, newValue ->
if (newValue as Boolean) {
return@OnPreferenceChangeListener true
}
MaterialAlertDialogBuilder(activity)
.setTitle(R.string.year_in_review_disable_title)
.setMessage(R.string.year_in_review_setting_subtitle)
.setPositiveButton(R.string.year_in_review_disable_positive_button) { _, _ ->
Prefs.yearInReviewModelData = emptyMap()
(preference as SwitchPreferenceCompat).isChecked = false
findPreference(R.string.preference_key_year_in_review_is_enabled).let {
it.isVisible = YearInReviewViewModel.isAccessible
it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { preference, newValue ->
if (newValue as Boolean) {
return@OnPreferenceChangeListener true
}
.setNegativeButton(R.string.year_in_review_disable_negative_button, null)
.show()
false
MaterialAlertDialogBuilder(activity)
.setTitle(R.string.year_in_review_disable_title)
.setMessage(R.string.year_in_review_setting_subtitle)
.setPositiveButton(R.string.year_in_review_disable_positive_button) { _, _ ->
Prefs.yearInReviewModelData = emptyMap()
(preference as SwitchPreferenceCompat).isChecked = false
}
.setNegativeButton(R.string.year_in_review_disable_negative_button, null)
.show()
false
}
}

findPreference(R.string.preference_key_about_wikipedia_app).onPreferenceClickListener = Preference.OnPreferenceClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ data class YearInReviewModel(
val closestLocation: Pair<Double, Double>,
val closestArticles: List<String>,
val userEditsCount: Int,
val userEditsViewedTimes: Long
val userEditsViewedTimes: Long,
val isCustomIconUnlocked: Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,7 @@ class YearInReviewSlides(
}

private fun unlockedIconRoute(): YearInReviewScreenData? {
val isIconUnlocked = yearInReviewModel.userEditsCount > 0 || Prefs.donationResults.isNotEmpty()
return if (isIconUnlocked) {
return if (yearInReviewModel.isCustomIconUnlocked) {
val contributorType = if (yearInReviewModel.userEditsCount > 0 && Prefs.donationResults.isNotEmpty()) {
context.getString(R.string.year_in_review_slide_app_icon_donor_and_editor)
} else if (yearInReviewModel.userEditsCount > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.wikipedia.dataclient.growthtasks.GrowthUserImpact
import org.wikipedia.json.JsonUtil
import org.wikipedia.page.PageTitle
import org.wikipedia.settings.Prefs
import org.wikipedia.settings.RemoteConfig
import org.wikipedia.util.GeoUtil
import org.wikipedia.util.StringUtil
import org.wikipedia.util.UiState
Expand Down Expand Up @@ -206,7 +207,8 @@ class YearInReviewViewModel() : ViewModel() {
closestLocation = Pair(0.0, 0.0),
closestArticles = emptyList(),
userEditsCount = editCount,
userEditsViewedTimes = impactDataJob.await().totalPageviewsCount
userEditsViewedTimes = impactDataJob.await().totalPageviewsCount,
isCustomIconUnlocked = editCount > 0 || Prefs.donationResults.isNotEmpty()
)

Prefs.yearInReviewModelData = yearInReviewModelMap
Expand Down Expand Up @@ -242,5 +244,23 @@ class YearInReviewViewModel() : ViewModel() {
const val MIN_READING_ARTICLES = 5
const val MIN_READING_MINUTES = 1
const val MIN_READING_PATTERNS_ARTICLES = 5

// Whether Year-in-Review should be accessible at all.
// (different from the user enabling/disabling it in Settings.)
val isAccessible get(): Boolean {
if (Prefs.isShowDeveloperSettingsEnabled) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that YiR is always accessible if Developer settings are enabled. I thought this would be more flexible than doing it by isPreBetaRelease etc.

return true
}
val config = RemoteConfig.config.commonv1?.getYirForYear(YIR_YEAR)
val now = LocalDateTime.now()
return (config != null &&
!config.hideCountryCodes.contains(GeoUtil.geoIPCountry) &&
now.isAfter(config.activeStartDate) &&
now.isBefore(config.activeEndDate))
}

val isCustomIconAllowed get(): Boolean {
return Prefs.yearInReviewModelData[YIR_YEAR]?.isCustomIconUnlocked == true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that this is independent of the overall YiR isAccessible, because if the user unlocks their icon, we want it to be accessible afterwards, even after the YiR feature itself goes away.

}
}
}
Loading