Skip to content

Commit

Permalink
[optimize] Optimize settings page; support HTTP
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyD666 committed Feb 29, 2024
1 parent c5d37eb commit dbbe9b9
Show file tree
Hide file tree
Showing 30 changed files with 344 additions and 487 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ android {
minSdk = 24
targetSdk = 34
versionCode = 5
versionName = "1.0-beta11"
versionName = "1.0-beta12"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down Expand Up @@ -137,6 +137,7 @@ dependencies {
implementation("androidx.media3:media3-exoplayer-dash:1.2.1")
implementation("androidx.media3:media3-ui:1.2.1")
implementation("androidx.paging:paging-runtime-ktx:3.2.1")
implementation("androidx.preference:preference-ktx:1.2.1")

implementation("com.google.android.material:material:1.11.0")

Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:localeConfig="@xml/locales_config"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AniVu"
Expand Down
21 changes: 0 additions & 21 deletions app/src/main/java/com/skyd/anivu/base/BaseFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import androidx.navigation.fragment.findNavController
import androidx.viewbinding.ViewBinding
import com.google.android.material.color.MaterialColors
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.BaseTransientBottomBar
import com.google.android.material.snackbar.Snackbar
import com.skyd.anivu.R
import com.skyd.anivu.ext.popBackStackWithLifecycle

Expand Down Expand Up @@ -48,25 +46,6 @@ abstract class BaseFragment<T : ViewBinding> : Fragment() {
_binding = null
}

// https://github.com/material-components/material-components-android/issues/3446
protected open fun showSnackbar(
text: CharSequence,
@BaseTransientBottomBar.Duration duration: Int = Snackbar.LENGTH_LONG,
actionText: String? = resources.getString(R.string.close),
onActionClick: (View) -> Unit? = {},
): Snackbar {
val snackbar = Snackbar.make(
binding.root,
text,
duration
).run {
if (actionText == null) this
else setAction(actionText) { onActionClick(it) }
}
snackbar.show()
return snackbar
}

protected fun checkArgument(
messageRes: Int,
action: () -> Boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.skyd.anivu.base

import android.content.Context
import android.os.Bundle
import android.view.View
import androidx.core.view.ViewCompat
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceScreen
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.appbar.CollapsingToolbarLayout
import com.google.android.material.appbar.MaterialToolbar
import com.skyd.anivu.R
import com.skyd.anivu.ext.addInsetsByPadding
import com.skyd.anivu.ext.findMainNavController
import com.skyd.anivu.ext.popBackStackWithLifecycle

abstract class BasePreferenceFragmentCompat : PreferenceFragmentCompat() {
abstract val title: String

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

view.findViewById<MaterialToolbar>(R.id.topAppBar).apply {
title = this@BasePreferenceFragmentCompat.title
setNavigationOnClickListener { findMainNavController().popBackStackWithLifecycle() }
}

view.findViewById<AppBarLayout>(R.id.abl_settings_fragment).apply {
addInsetsByPadding(top = true, left = true, right = true)
}

view.findViewById<CollapsingToolbarLayout>(R.id.ctl_settings_fragment).apply {
// Fix: https://github.com/material-components/material-components-android/issues/1310
ViewCompat.setOnApplyWindowInsetsListener(this, null)
}

listView.apply {
clipToPadding = false
addInsetsByPadding(bottom = true, left = true, right = true)
}
}

override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
val context = preferenceManager.context
val screen = preferenceManager.createPreferenceScreen(context)

context.onAddPreferences(savedInstanceState, rootKey, screen)

preferenceScreen = screen
}

abstract fun Context.onAddPreferences(
savedInstanceState: Bundle?,
rootKey: String?,
screen: PreferenceScreen,
)
}
22 changes: 22 additions & 0 deletions app/src/main/java/com/skyd/anivu/ext/FragmentExt.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
package com.skyd.anivu.ext

import android.view.View
import androidx.fragment.app.Fragment
import androidx.navigation.NavController
import androidx.navigation.Navigation
import com.google.android.material.snackbar.BaseTransientBottomBar
import com.google.android.material.snackbar.Snackbar
import com.skyd.anivu.R


fun Fragment.findMainNavController(): NavController {
return Navigation.findNavController(requireActivity(), R.id.nav_host_fragment_main)
}

// https://github.com/material-components/material-components-android/issues/3446
fun Fragment.showSnackbar(
text: CharSequence,
@BaseTransientBottomBar.Duration duration: Int = Snackbar.LENGTH_LONG,
actionText: String? = resources.getString(R.string.close),
onActionClick: (View) -> Unit? = {},
): Snackbar {
val snackbar = Snackbar.make(
view!!.rootView,
text,
duration
).run {
if (actionText == null) this
else setAction(actionText) { onActionClick(it) }
}
snackbar.show()
return snackbar
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import com.skyd.anivu.databinding.ItemMedia1Binding
import com.skyd.anivu.databinding.ItemMore1Binding
import com.skyd.anivu.databinding.ItemOtherWorks1Binding
import com.skyd.anivu.databinding.ItemParentDir1Binding
import com.skyd.anivu.databinding.ItemSettingsBaseBinding
import com.skyd.anivu.databinding.ItemSettingsSwitchBinding

abstract class BaseViewHolder<V : ViewBinding>(val binding: V) :
RecyclerView.ViewHolder(binding.root)
Expand Down Expand Up @@ -49,9 +47,3 @@ class OtherWorks1ViewHolder(binding: ItemOtherWorks1Binding) :

class License1ViewHolder(binding: ItemLicense1Binding) :
BaseViewHolder<ItemLicense1Binding>(binding)

class SettingsBaseViewHolder(binding: ItemSettingsBaseBinding) :
BaseViewHolder<ItemSettingsBaseBinding>(binding)

class SettingsSwitchViewHolder(binding: ItemSettingsSwitchBinding) :
BaseViewHolder<ItemSettingsSwitchBinding>(binding)

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.skyd.anivu.databinding.FragmentArticleBinding
import com.skyd.anivu.ext.addInsetsByPadding
import com.skyd.anivu.ext.collectIn
import com.skyd.anivu.ext.popBackStackWithLifecycle
import com.skyd.anivu.ext.showSnackbar
import com.skyd.anivu.ext.startWith
import com.skyd.anivu.ui.adapter.variety.AniSpanSize
import com.skyd.anivu.ui.adapter.variety.paging.PagingAniSpanSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.skyd.anivu.ext.addInsetsByPadding
import com.skyd.anivu.ext.collectIn
import com.skyd.anivu.ext.findMainNavController
import com.skyd.anivu.ext.gone
import com.skyd.anivu.ext.showSnackbar
import com.skyd.anivu.ext.startWith
import com.skyd.anivu.ui.adapter.variety.AniSpanSize
import com.skyd.anivu.ui.adapter.variety.paging.PagingAniSpanSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.skyd.anivu.ext.addInsetsByPadding
import com.skyd.anivu.ext.collectIn
import com.skyd.anivu.ext.findMainNavController
import com.skyd.anivu.ext.popBackStackWithLifecycle
import com.skyd.anivu.ext.showSnackbar
import com.skyd.anivu.ext.toUri
import com.skyd.anivu.model.bean.ParentDirBean
import com.skyd.anivu.ui.activity.PlayActivity
Expand Down
Loading

0 comments on commit dbbe9b9

Please sign in to comment.