From dd3d372b800295c79547e6d19a7f4fe1a2d1b826 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Sun, 16 Aug 2020 10:01:51 +0200 Subject: [PATCH] add setting to hide top toolbar --- .../com/keylesspalace/tusky/MainActivity.kt | 26 +++++++++++++++---- .../tusky/PreferencesActivity.kt | 3 ++- .../preference/PreferencesFragment.kt | 6 +++++ .../tusky/settings/SettingsConstants.kt | 1 + app/src/main/res/values/strings.xml | 1 + 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt b/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt index 4cb737f3c..32222251d 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt @@ -59,6 +59,7 @@ import com.keylesspalace.tusky.interfaces.AccountSelectionListener import com.keylesspalace.tusky.interfaces.ActionButtonActivity import com.keylesspalace.tusky.interfaces.ReselectableFragment import com.keylesspalace.tusky.pager.MainPagerAdapter +import com.keylesspalace.tusky.settings.PrefKeys import com.keylesspalace.tusky.util.* import com.mikepenz.iconics.IconicsDrawable import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial @@ -95,6 +96,8 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje private var notificationTabPosition = 0 private var onTabSelectedListener: OnTabSelectedListener? = null + private val preferences by lazy { PreferenceManager.getDefaultSharedPreferences(this) } + private val emojiInitCallback = object : InitCallback() { override fun onInitialized() { if (!isDestroyed) { @@ -163,6 +166,9 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje startActivity(composeIntent) } + val hideTopToolbar = preferences.getBoolean(PrefKeys.HIDE_TOP_TOOLBAR, false) + mainToolbar.visible(!hideTopToolbar) + mainToolbar.menu.add(R.string.action_search).apply { setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM) icon = IconicsDrawable(this@MainActivity, GoogleMaterial.Icon.gmd_search).apply { @@ -175,7 +181,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje } } - setupDrawer(savedInstanceState) + setupDrawer(savedInstanceState, addSearchButton = hideTopToolbar) /* Fetch user info while we're doing other things. This has to be done after setting up the * drawer, though, because its callback touches the header in the drawer. */ @@ -280,7 +286,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje finish() } - private fun setupDrawer(savedInstanceState: Bundle?) { + private fun setupDrawer(savedInstanceState: Bundle?, addSearchButton: Boolean) { drawerToggle = ActionBarDrawerToggle(this, mainDrawerLayout, mainToolbar, com.mikepenz.materialdrawer.R.string.material_drawer_open, com.mikepenz.materialdrawer.R.string.material_drawer_close) @@ -301,8 +307,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje header.accountHeaderBackground.setColorFilter(ContextCompat.getColor(this, R.color.headerBackgroundFilter)) header.accountHeaderBackground.setBackgroundColor(ThemeUtils.getColor(this, R.attr.colorBackgroundAccent)) - val animateAvatars = PreferenceManager.getDefaultSharedPreferences(this) - .getBoolean("animateGifAvatars", false) + val animateAvatars = preferences.getBoolean("animateGifAvatars", false) DrawerImageLoader.init(object : AbstractDrawerImageLoader() { override fun set(imageView: ImageView, uri: Uri, placeholder: Drawable, tag: String?) { @@ -414,6 +419,18 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje onClick = ::logout } ) + + if(addSearchButton) { + mainDrawer.addItemsAtPosition(4, + primaryDrawerItem { + nameRes = R.string.action_search + iconicsIcon = GoogleMaterial.Icon.gmd_search + onClick = { + startActivityWithSlideInAnimation(SearchActivity.getIntent(context)) + } + }) + } + setSavedInstance(savedInstanceState) } @@ -446,7 +463,6 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje } private fun setupTabs(selectNotificationTab: Boolean) { - val preferences = PreferenceManager.getDefaultSharedPreferences(this) val activeTabLayout = if(preferences.getString("mainNavPosition", "top") == "bottom") { val actionBarSize = ThemeUtils.getDimension(this, R.attr.actionBarSize) diff --git a/app/src/main/java/com/keylesspalace/tusky/PreferencesActivity.kt b/app/src/main/java/com/keylesspalace/tusky/PreferencesActivity.kt index 6ba86e2c2..383a07ae3 100644 --- a/app/src/main/java/com/keylesspalace/tusky/PreferencesActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/PreferencesActivity.kt @@ -26,6 +26,7 @@ import androidx.preference.PreferenceManager import com.keylesspalace.tusky.appstore.EventHub import com.keylesspalace.tusky.appstore.PreferenceChangedEvent import com.keylesspalace.tusky.fragment.preference.* +import com.keylesspalace.tusky.settings.PrefKeys import com.keylesspalace.tusky.util.ThemeUtils import com.keylesspalace.tusky.util.getNonNullString import dagger.android.DispatchingAndroidInjector @@ -129,7 +130,7 @@ class PreferencesActivity : BaseActivity(), SharedPreferences.OnSharedPreference } "statusTextSize", "absoluteTimeView", "showBotOverlay", "animateGifAvatars", - "useBlurhash", "showCardsInTimelines", "confirmReblogs", "enableSwipeForTabs", "mainNavPosition" -> { + "useBlurhash", "showCardsInTimelines", "confirmReblogs", "enableSwipeForTabs", "mainNavPosition", PrefKeys.HIDE_TOP_TOOLBAR -> { restartActivitiesOnExit = true } "language" -> { diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/preference/PreferencesFragment.kt b/app/src/main/java/com/keylesspalace/tusky/fragment/preference/PreferencesFragment.kt index cb12f60ec..6dec7273b 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/preference/PreferencesFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/preference/PreferencesFragment.kt @@ -85,6 +85,12 @@ class PreferencesFragment : PreferenceFragmentCompat() { setTitle(R.string.pref_main_nav_position) } + switchPreference { + setDefaultValue(false) + key = PrefKeys.HIDE_TOP_TOOLBAR + setTitle(R.string.pref_title_hide_top_toolbar) + } + switchPreference { setDefaultValue(false) key = PrefKeys.FAB_HIDE diff --git a/app/src/main/java/com/keylesspalace/tusky/settings/SettingsConstants.kt b/app/src/main/java/com/keylesspalace/tusky/settings/SettingsConstants.kt index 4d208b85c..8178bc63b 100644 --- a/app/src/main/java/com/keylesspalace/tusky/settings/SettingsConstants.kt +++ b/app/src/main/java/com/keylesspalace/tusky/settings/SettingsConstants.kt @@ -22,6 +22,7 @@ object PrefKeys { const val LANGUAGE = "language" const val STATUS_TEXT_SIZE = "statusTextSize" const val MAIN_NAV_POSITION = "mainNavPosition" + const val HIDE_TOP_TOOLBAR = "hideTopToolbar" const val ABSOLUTE_TIME_VIEW = "absoluteTimeView" const val SHOW_BOT_OVERLAY = "showBotOverlay" const val ANIMATE_GIF_AVATARS = "animateGifAvatars" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3eafa8c40..800e62dcd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -573,5 +573,6 @@ Mastodon has a minimum scheduling interval of 5 minutes. Show link previews in timelines Show confirmation dialog before boosting + Hide the title of the top toolbar