From 1240e2663413b56c5b97c8ff40cb5c1bdc2df23b Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 19 Aug 2017 21:07:54 -0700 Subject: Add bottom bar layout --- .../pitchedapps/frost/activities/MainActivity.kt | 5 ++- .../pitchedapps/frost/enums/MainActivityLayout.kt | 29 +++++++++++++ .../com/pitchedapps/frost/settings/Appearance.kt | 28 ++++++++++-- .../kotlin/com/pitchedapps/frost/utils/Prefs.kt | 6 +++ .../com/pitchedapps/frost/views/BadgedIcon.kt | 6 +-- .../main/res/layout/activity_main_bottom_tabs.xml | 50 ++++++++++++++++++++++ app/src/main/res/values/strings.xml | 3 ++ .../main/res/values/strings_pref_appearance.xml | 3 ++ 8 files changed, 122 insertions(+), 8 deletions(-) create mode 100644 app/src/main/kotlin/com/pitchedapps/frost/enums/MainActivityLayout.kt create mode 100644 app/src/main/res/layout/activity_main_bottom_tabs.xml diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt index 45488c94..6d7f0aad 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt @@ -125,7 +125,7 @@ class MainActivity : BaseActivity(), SearchWebView.SearchContract, "Frost id" to Prefs.frostId) } } - setContentView(R.layout.activity_main) + setContentView(Prefs.mainActivityLayout.layoutRes) setSupportActionBar(toolbar) adapter = SectionsPagerAdapter(supportFragmentManager, loadFbTabs()) viewPager.adapter = adapter @@ -159,7 +159,8 @@ class MainActivity : BaseActivity(), SearchWebView.SearchContract, // Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) // .setAction("Action", null).show() // } - setFrostColors(toolbar, themeWindow = false, headers = arrayOf(tabs, appBar), backgrounds = arrayOf(viewPager)) + setFrostColors(toolbar, themeWindow = false, headers = arrayOf(appBar), backgrounds = arrayOf(viewPager)) + tabs.setBackgroundColor(Prefs.mainActivityLayout.backgroundColor()) onCreateBilling() setNetworkObserver { connectivity -> diff --git a/app/src/main/kotlin/com/pitchedapps/frost/enums/MainActivityLayout.kt b/app/src/main/kotlin/com/pitchedapps/frost/enums/MainActivityLayout.kt new file mode 100644 index 00000000..b3d71cfc --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/enums/MainActivityLayout.kt @@ -0,0 +1,29 @@ +package com.pitchedapps.frost.enums + +import com.pitchedapps.frost.R +import com.pitchedapps.frost.utils.Prefs + +/** + * Created by Allan Wang on 2017-08-19. + */ +enum class MainActivityLayout( + val titleRes: Int, + val layoutRes: Int, + val backgroundColor: () -> Int, + val iconColor: () -> Int) { + + TOP_BAR(R.string.top_bar, + R.layout.activity_main, + { Prefs.headerColor }, + { Prefs.iconColor }), + + BOTTOM_BAR(R.string.bottom_bar, + R.layout.activity_main_bottom_tabs, + { Prefs.bgColor }, + { Prefs.textColor }); + + companion object { + val values = MainActivityLayout.values() //save one instance + operator fun invoke(index: Int) = values[index] + } +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt index 7dff5b16..43a186db 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt @@ -8,6 +8,7 @@ import ca.allanwang.kau.utils.string import com.pitchedapps.frost.R import com.pitchedapps.frost.activities.MainActivity import com.pitchedapps.frost.activities.SettingsActivity +import com.pitchedapps.frost.enums.MainActivityLayout import com.pitchedapps.frost.injectors.CssAssets import com.pitchedapps.frost.utils.* import com.pitchedapps.frost.utils.iab.IS_FROST_PRO @@ -27,9 +28,9 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { 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) }) + .map { string(it) }) itemsCallbackSingleChoice(item.pref) { - _, _, which, text -> + _, _, which, _ -> if (item.pref != which) { if (which == Theme.CUSTOM.ordinal && !IS_FROST_PRO) { purchasePro() @@ -41,7 +42,7 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { setFrostTheme(true) themeExterior() invalidateOptionsMenu() - frostAnswersCustom("Theme", "Count" to text) + frostAnswersCustom("Theme", "Count" to Theme(which).name) } true } @@ -117,6 +118,27 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { header(R.string.global_customization) + text(R.string.main_activity_layout, { Prefs.mainActivityLayoutType }, { Prefs.mainActivityLayoutType = it }) { + textGetter = { string(Prefs.mainActivityLayout.titleRes) } + onClick = { + _, _, item -> + materialDialogThemed { + title(R.string.set_main_activity_layout) + items(MainActivityLayout.values.map { string(it.titleRes) }) + itemsCallbackSingleChoice(item.pref) { + _, _, which, _ -> + if (item.pref != which) { + item.pref = which + shouldRestartMain() + frostAnswersCustom("Main Layout", "Type" to MainActivityLayout(which).name) + } + true + } + } + true + } + } + checkbox(R.string.rounded_icons, { Prefs.showRoundedIcons }, { Prefs.showRoundedIcons = it setFrostResult(MainActivity.REQUEST_REFRESH) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt index 126bd500..56c33b4b 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt @@ -6,6 +6,7 @@ import ca.allanwang.kau.kpref.KPref import ca.allanwang.kau.kpref.StringSet import ca.allanwang.kau.kpref.kpref import ca.allanwang.kau.utils.isColorVisibleOn +import com.pitchedapps.frost.enums.MainActivityLayout import com.pitchedapps.frost.facebook.FeedSort import com.pitchedapps.frost.injectors.InjectorContract @@ -132,4 +133,9 @@ object Prefs : KPref() { var debugSettings: Boolean by kpref("debug_settings", false) var linksInDefaultApp: Boolean by kpref("link_in_default_app", false) + + var mainActivityLayoutType: Int by kpref("main_activity_layout_type", 0) + + val mainActivityLayout: MainActivityLayout + get() = MainActivityLayout(mainActivityLayoutType) } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt index 8ae54ef3..c1015aad 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt @@ -24,11 +24,11 @@ class BadgedIcon @JvmOverloads constructor( init { inflate(context, R.layout.view_badged_icon, this) - val badgeColor = Prefs.headerColor.withAlpha(255).colorToForeground(0.2f) + val badgeColor = Prefs.mainActivityLayout.backgroundColor().withAlpha(255).colorToForeground(0.2f) val badgeBackground = GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, intArrayOf(badgeColor, badgeColor)) badgeBackground.cornerRadius = 13.dpToPx.toFloat() badgeTextView.background = badgeBackground - badgeTextView.setTextColor(Prefs.iconColor) + badgeTextView.setTextColor(Prefs.mainActivityLayout.iconColor()) } @@ -36,7 +36,7 @@ class BadgedIcon @JvmOverloads constructor( get() = field set(value) { field = value - badgeImage.setImageDrawable(value?.toDrawable(context, color = Prefs.iconColor)) + badgeImage.setImageDrawable(value?.toDrawable(context, color = Prefs.mainActivityLayout.iconColor())) } fun setAllAlpha(alpha: Float) { diff --git a/app/src/main/res/layout/activity_main_bottom_tabs.xml b/app/src/main/res/layout/activity_main_bottom_tabs.xml new file mode 100644 index 00000000..e10a1cb9 --- /dev/null +++ b/app/src/main/res/layout/activity_main_bottom_tabs.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index eff04778..c8a97c92 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -64,4 +64,7 @@ The request has been cancelled. The request has timed out. File chooser not found + + Top Bar + Bottom Bar diff --git a/app/src/main/res/values/strings_pref_appearance.xml b/app/src/main/res/values/strings_pref_appearance.xml index 513baf5f..f2e0f9e0 100644 --- a/app/src/main/res/values/strings_pref_appearance.xml +++ b/app/src/main/res/values/strings_pref_appearance.xml @@ -12,6 +12,9 @@ Global Customization + Main Activity Layout + Set Main Activity Layout + Rounded Icons Profile photos and group conversation icons will be rounded -- cgit v1.2.3