Added the option to hide or not toolbar when scrolling

This commit is contained in:
ztimms73
2021-05-15 08:56:03 +03:00
parent 24d9a49420
commit 51dc2ac046
7 changed files with 23 additions and 0 deletions

View File

@@ -15,6 +15,8 @@ import androidx.core.content.ContextCompat
import androidx.core.graphics.Insets
import androidx.core.view.*
import androidx.viewbinding.ViewBinding
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.appbar.AppBarLayout.LayoutParams.*
import org.koin.android.ext.android.get
import org.koitharu.kotatsu.BuildConfig
import org.koitharu.kotatsu.R
@@ -57,7 +59,13 @@ abstract class BaseActivity<B : ViewBinding> : AppCompatActivity(), OnApplyWindo
this.binding = binding
super.setContentView(binding.root)
(binding.root.findViewById<View>(R.id.toolbar) as? Toolbar)?.let(this::setSupportActionBar)
val params = (binding.root.findViewById<View>(R.id.toolbar) as? Toolbar)?.layoutParams as AppBarLayout.LayoutParams
ViewCompat.setOnApplyWindowInsetsListener(binding.root, this)
if (get<AppSettings>().isToolbarHideWhenScrolling) {
params.scrollFlags = SCROLL_FLAG_SCROLL or SCROLL_FLAG_ENTER_ALWAYS
} else {
params.scrollFlags = SCROLL_FLAG_NO_SCROLL
}
}
override fun onApplyWindowInsets(v: View, insets: WindowInsetsCompat): WindowInsetsCompat {

View File

@@ -41,6 +41,8 @@ class AppSettings private constructor(private val prefs: SharedPreferences) :
val isAmoledTheme by BoolPreferenceDelegate(KEY_THEME_AMOLED, defaultValue = false)
val isToolbarHideWhenScrolling by BoolPreferenceDelegate(KEY_HIDE_TOOLBAR, defaultValue = true)
var gridSize by IntPreferenceDelegate(KEY_GRID_SIZE, defaultValue = 100)
val readerPageSwitch by StringSetPreferenceDelegate(
@@ -147,6 +149,7 @@ class AppSettings private constructor(private val prefs: SharedPreferences) :
const val KEY_APP_SECTION = "app_section"
const val KEY_THEME = "theme"
const val KEY_THEME_AMOLED = "amoled_theme"
const val KEY_HIDE_TOOLBAR = "hide_toolbar"
const val KEY_SOURCES_ORDER = "sources_order"
const val KEY_SOURCES_HIDDEN = "sources_hidden"
const val KEY_TRAFFIC_WARNING = "traffic_warning"

View File

@@ -73,6 +73,9 @@ class MainSettingsFragment : BasePreferenceFragment(R.string.settings),
AppSettings.KEY_THEME_AMOLED -> {
findPreference<Preference>(key)?.setSummary(R.string.restart_required)
}
AppSettings.KEY_HIDE_TOOLBAR -> {
findPreference<SwitchPreference>(key)?.setSummary(R.string.restart_required)
}
AppSettings.KEY_LOCAL_STORAGE -> {
findPreference<Preference>(key)?.run {
summary = settings.getStorageDir(context)?.getStorageName(context)

View File

@@ -207,4 +207,5 @@
<string name="protect_application_subtitle">Калі ласка, увядзіце пароль, які спатрэбіцца пры запуску прыкладання</string>
<string name="confirm">Пацвярджаць</string>
<string name="password_length_hint">Пароль павінен змяшчаць не менш за 4 сімвалаў</string>
<string name="hide_toolbar">Схаваць загаловак пры прагортцы</string>
</resources>

View File

@@ -205,4 +205,5 @@
<string name="protect_application_subtitle">Введите пароль, который вам понадобится при запуске приложения</string>
<string name="confirm">Confirm</string>
<string name="password_length_hint">Пароль должен содержать не менее 4 символов</string>
<string name="hide_toolbar">Прятать заголовок при прокрутке</string>
</resources>

View File

@@ -207,4 +207,5 @@
<string name="protect_application_subtitle">Enter password that will be required when the application starts</string>
<string name="confirm">Confirm</string>
<string name="password_length_hint">Password must be at least 4 characters</string>
<string name="hide_toolbar">Hide toolbar when scrolling</string>
</resources>

View File

@@ -20,6 +20,12 @@
android:title="@string/black_dark_theme"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="true"
android:key="hide_toolbar"
android:title="@string/hide_toolbar"
app:iconSpaceReserved="false" />
<ListPreference
android:entries="@array/list_modes"
android:key="list_mode_2"