diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/settings')
4 files changed, 248 insertions, 0 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt new file mode 100644 index 00000000..267e5e75 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt @@ -0,0 +1,126 @@ +package com.pitchedapps.frost.settings + +import ca.allanwang.kau.kpref.KPrefAdapterBuilder +import ca.allanwang.kau.kpref.items.KPrefColorPicker +import ca.allanwang.kau.utils.string +import ca.allanwang.kau.views.RippleCanvas +import com.pitchedapps.frost.MainActivity +import com.pitchedapps.frost.R +import com.pitchedapps.frost.SettingsActivity +import com.pitchedapps.frost.injectors.CssAssets +import com.pitchedapps.frost.utils.* +import com.pitchedapps.frost.utils.iab.IS_FROST_PRO +import com.pitchedapps.frost.utils.iab.openPlayProPurchase + +/** + * Created by Allan Wang on 2017-06-29. + */ +fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { + + header(R.string.theme_customization) + + text(R.string.theme, { Prefs.theme }, { Prefs.theme = it }) { + onClick = { + _, _, item -> + materialDialogThemed { + title(R.string.theme) + items(Theme.values() + .map { if (it == Theme.CUSTOM && !IS_FROST_PRO) R.string.custom_pro else it.textRes } + .map { context.string(it) }) + itemsCallbackSingleChoice(item.pref) { + _, _, which, text -> + if (item.pref != which) { + if (which == Theme.CUSTOM.ordinal && !IS_FROST_PRO) { + openPlayProPurchase(9) + return@itemsCallbackSingleChoice true + } + item.pref = which + shouldRestartMain() + reload() + setFrostTheme(true) + themeExterior() + invalidateOptionsMenu() + frostAnswersCustom("Theme") { putCustomAttribute("Count", text.toString()) } + } + true + } + } + true + } + textGetter = { + string(Theme(it).textRes) + } + } + + fun KPrefColorPicker.KPrefColorContract.dependsOnCustom() { + enabler = { Prefs.isCustomTheme } + onDisabledClick = { itemView, _, _ -> itemView.frostSnackbar(R.string.requires_custom_theme); true } + allowCustom = true + } + + fun invalidateCustomTheme() { + CssAssets.CUSTOM.injector = null + } + + colorPicker(R.string.text_color, { Prefs.customTextColor }, { + Prefs.customTextColor = it + reload() + invalidateCustomTheme() + shouldRestartMain() + }) { + dependsOnCustom() + allowCustomAlpha = false + } + + colorPicker(R.string.background_color, { Prefs.customBackgroundColor }, { + Prefs.customBackgroundColor = it + bgCanvas.ripple(it, duration = 500L) + invalidateCustomTheme() + setFrostTheme(true) + shouldRestartMain() + }) { + dependsOnCustom() + allowCustomAlpha = true + } + + colorPicker(R.string.header_color, { Prefs.customHeaderColor }, { + Prefs.customHeaderColor = it + if (Prefs.tintNavBar) frostNavigationBar() + toolbarCanvas.ripple(it, RippleCanvas.MIDDLE, RippleCanvas.END, duration = 500L) + reload() + shouldRestartMain() + }) { + dependsOnCustom() + allowCustomAlpha = true + } + + colorPicker(R.string.icon_color, { Prefs.customIconColor }, { + Prefs.customIconColor = it + invalidateOptionsMenu() + shouldRestartMain() + }) { + dependsOnCustom() + allowCustomAlpha = false + } + + header(R.string.global_customization) + + checkbox(R.string.rounded_icons, { Prefs.showRoundedIcons }, { + Prefs.showRoundedIcons = it + setResult(MainActivity.REQUEST_REFRESH) + }) { + descRes = R.string.rounded_icons_desc + } + + checkbox(R.string.fancy_animations, { Prefs.animate }, { Prefs.animate = it; animate = it }) { + descRes = R.string.fancy_animations_desc + } + + checkbox(R.string.tint_nav, { Prefs.tintNavBar }, { + Prefs.tintNavBar = it + frostNavigationBar() + setResult(MainActivity.REQUEST_NAV) + }) { + descRes = R.string.tint_nav_desc + } +}
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt new file mode 100644 index 00000000..2184a111 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt @@ -0,0 +1,15 @@ +package com.pitchedapps.frost.settings + +import ca.allanwang.kau.kpref.KPrefAdapterBuilder +import com.pitchedapps.frost.R +import com.pitchedapps.frost.SettingsActivity +import com.pitchedapps.frost.utils.Prefs + +/** + * Created by Allan Wang on 2017-06-29. + */ +fun SettingsActivity.getExperimentalPrefs(): KPrefAdapterBuilder.() -> Unit = { + checkbox(R.string.search, { Prefs.searchBar }, { Prefs.searchBar = it }) { + descRes = R.string.search_desc + } +}
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Feed.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Feed.kt new file mode 100644 index 00000000..60b0d2e9 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Feed.kt @@ -0,0 +1,55 @@ +package com.pitchedapps.frost.settings + +import ca.allanwang.kau.kpref.KPrefAdapterBuilder +import ca.allanwang.kau.utils.string +import com.pitchedapps.frost.MainActivity +import com.pitchedapps.frost.R +import com.pitchedapps.frost.SettingsActivity +import com.pitchedapps.frost.facebook.FeedSort +import com.pitchedapps.frost.utils.Prefs +import com.pitchedapps.frost.utils.materialDialogThemed + +/** + * Created by Allan Wang on 2017-06-29. + */ +fun SettingsActivity.getFeedPrefs(): KPrefAdapterBuilder.() -> Unit = { + + text(R.string.newsfeed_sort, { Prefs.feedSort }, { Prefs.feedSort = it }) { + descRes = R.string.newsfeed_sort_desc + onClick = { + _, _, item -> + materialDialogThemed { + title(R.string.newsfeed_sort) + items(FeedSort.values().map { string(it.textRes) }) + itemsCallbackSingleChoice(item.pref, { + _, _, which, text -> + if (item.pref != which) { + item.pref = which + shouldRestartMain() + } + true + }) + } + true + } + textGetter = { string(FeedSort(it).textRes) } + } + + header(R.string.pro_features) + + checkbox(R.string.suggested_friends, { Prefs.showSuggestedFriends }, { + Prefs.showSuggestedFriends = it + setResult(MainActivity.REQUEST_REFRESH) + }) { + descRes = R.string.suggested_friends_desc + dependsOnPro() + } + + checkbox(R.string.facebook_ads, { Prefs.showFacebookAds }, { + Prefs.showFacebookAds = it + setResult(MainActivity.REQUEST_REFRESH) + }) { + descRes = R.string.facebook_ads_desc + dependsOnPro() + } +}
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt new file mode 100644 index 00000000..03ed517b --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt @@ -0,0 +1,52 @@ +package com.pitchedapps.frost.settings + +import ca.allanwang.kau.kpref.KPrefAdapterBuilder +import ca.allanwang.kau.utils.minuteToText +import com.pitchedapps.frost.R +import com.pitchedapps.frost.SettingsActivity +import com.pitchedapps.frost.utils.Prefs +import com.pitchedapps.frost.utils.materialDialogThemed +import com.pitchedapps.frost.utils.scheduleNotifications +import com.pitchedapps.frost.views.Keywords + +/** + * Created by Allan Wang on 2017-06-29. + */ +fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { + + text(R.string.notification_frequency, { Prefs.notificationFreq }, { Prefs.notificationFreq = it }) { + val options = longArrayOf(-1, 15, 30, 60, 120, 180, 300, 1440, 2880) + val texts = options.map { minuteToText(it) } + onClick = { + _, _, item -> + materialDialogThemed { + title(R.string.notification_frequency) + items(texts) + itemsCallbackSingleChoice(options.indexOf(item.pref), { + _, _, which, _ -> + item.pref = options[which] + scheduleNotifications(item.pref) + true + }) + } + true + } + textGetter = { minuteToText(it) } + } + + plainText(R.string.notification_keywords) { + descRes = R.string.notification_keywords_desc + onClick = { + _, _, _ -> + val keywordView = Keywords(this@getNotificationPrefs) + materialDialogThemed { + title(R.string.notification_keywords) + customView(keywordView, false) + dismissListener { keywordView.save() } + positiveText(R.string.kau_done) + } + true + } + } + +}
\ No newline at end of file |