-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[optimize] Optimize settings page; support HTTP
- Loading branch information
Showing
30 changed files
with
344 additions
and
487 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
app/src/main/java/com/skyd/anivu/base/BasePreferenceFragmentCompat.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
11 changes: 0 additions & 11 deletions
11
app/src/main/java/com/skyd/anivu/model/bean/settings/SettingsBaseBean.kt
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
app/src/main/java/com/skyd/anivu/model/bean/settings/SettingsSwitchBean.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
app/src/main/java/com/skyd/anivu/ui/adapter/variety/proxy/settings/SettingsBaseProxy.kt
This file was deleted.
Oops, something went wrong.
45 changes: 0 additions & 45 deletions
45
app/src/main/java/com/skyd/anivu/ui/adapter/variety/proxy/settings/SettingsSwitchProxy.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.