convert prefs to viewbinding

This commit is contained in:
Bnyro 2022-07-01 10:29:00 +02:00
parent 9ebd3d5f7e
commit 92993db5c7
10 changed files with 46 additions and 42 deletions

View File

@ -3,11 +3,9 @@ package com.github.libretube
import android.app.NotificationManager import android.app.NotificationManager
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.View
import android.widget.ImageButton
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat import androidx.core.app.ActivityCompat
import com.github.libretube.databinding.ActivitySettingsBinding
import com.github.libretube.preferences.MainSettings import com.github.libretube.preferences.MainSettings
import com.github.libretube.util.ThemeHelper import com.github.libretube.util.ThemeHelper
import com.google.android.material.color.DynamicColors import com.google.android.material.color.DynamicColors
@ -17,24 +15,27 @@ var requireMainActivityRestart = false
class SettingsActivity : AppCompatActivity() { class SettingsActivity : AppCompatActivity() {
val TAG = "SettingsActivity" val TAG = "SettingsActivity"
lateinit var binding: ActivitySettingsBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
DynamicColors.applyToActivityIfAvailable(this) DynamicColors.applyToActivityIfAvailable(this)
ThemeHelper.updateTheme(this) ThemeHelper.updateTheme(this)
// makes the preference dialogs use material dialogs // makes the preference dialogs use material dialogs
setTheme(R.style.MaterialAlertDialog) setTheme(R.style.MaterialAlertDialog)
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = ActivitySettingsBinding.inflate(layoutInflater)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
overridePendingTransition(50, 50) overridePendingTransition(50, 50)
} }
val view = this.findViewById<View>(android.R.id.content) binding.root.alpha = 0F
view.alpha = 0F binding.root.animate().alpha(1F).duration = 300
view.animate().alpha(1F).duration = 300
setContentView(R.layout.activity_settings) setContentView(binding.root)
val backButton = view.findViewById<ImageButton>(R.id.back_imageButton) binding.backImageButton.setOnClickListener {
backButton.setOnClickListener {
onBackPressed() onBackPressed()
} }
@ -66,8 +67,7 @@ class SettingsActivity : AppCompatActivity() {
.beginTransaction() .beginTransaction()
.replace(R.id.settings, MainSettings()) .replace(R.id.settings, MainSettings())
.commit() .commit()
val topBarTextView = findViewById<TextView>(R.id.topBar_textView) binding.topBarTextView.text = getString(R.string.settings)
topBarTextView?.text = getString(R.string.settings)
} }
} }
} }

View File

@ -29,7 +29,8 @@ class LoginDialog : DialogFragment() {
binding.login.setOnClickListener { binding.login.setOnClickListener {
if (binding.username.text.toString() != "" && binding.password.text.toString() != "") { if (binding.username.text.toString() != "" && binding.password.text.toString() != "") {
val login = Login(binding.username.text.toString(), binding.password.text.toString()) val login =
Login(binding.username.text.toString(), binding.password.text.toString())
login(login) login(login)
} else { } else {
Toast.makeText(context, R.string.empty, Toast.LENGTH_SHORT).show() Toast.makeText(context, R.string.empty, Toast.LENGTH_SHORT).show()

View File

@ -17,15 +17,19 @@ import com.github.libretube.DONATE_URL
import com.github.libretube.PIPED_GITHUB_URL import com.github.libretube.PIPED_GITHUB_URL
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.WEBSITE_URL import com.github.libretube.WEBSITE_URL
import com.github.libretube.databinding.FragmentAboutBinding
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
class AboutFragment : Fragment() { class AboutFragment : Fragment() {
private lateinit var binding: FragmentAboutBinding
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, inflater: LayoutInflater,
container: ViewGroup?, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View {
return inflater.inflate(R.layout.fragment_about, container, false) binding = FragmentAboutBinding.inflate(layoutInflater)
return binding.root
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {

View File

@ -1,10 +1,10 @@
package com.github.libretube.preferences package com.github.libretube.preferences
import android.os.Bundle import android.os.Bundle
import android.widget.TextView
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.SettingsActivity
import com.github.libretube.requireMainActivityRestart import com.github.libretube.requireMainActivityRestart
import com.github.libretube.util.PreferenceHelper import com.github.libretube.util.PreferenceHelper
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
@ -15,8 +15,8 @@ class AdvancedSettings : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.advanced_settings, rootKey) setPreferencesFromResource(R.xml.advanced_settings, rootKey)
val topBarTextView = activity?.findViewById<TextView>(R.id.topBar_textView) val settingsActivity = activity as SettingsActivity
topBarTextView?.text = getString(R.string.advanced) settingsActivity.binding.topBarTextView.text = getString(R.string.advanced)
val clearHistory = findPreference<Preference>("clear_history") val clearHistory = findPreference<Preference>("clear_history")
clearHistory?.setOnPreferenceClickListener { clearHistory?.setOnPreferenceClickListener {

View File

@ -1,12 +1,12 @@
package com.github.libretube.preferences package com.github.libretube.preferences
import android.os.Bundle import android.os.Bundle
import android.widget.TextView
import androidx.preference.ListPreference import androidx.preference.ListPreference
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference import androidx.preference.SwitchPreference
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.SettingsActivity
import com.github.libretube.requireMainActivityRestart import com.github.libretube.requireMainActivityRestart
import com.github.libretube.util.ThemeHelper import com.github.libretube.util.ThemeHelper
@ -15,8 +15,8 @@ class AppearanceSettings : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.appearance_settings, rootKey) setPreferencesFromResource(R.xml.appearance_settings, rootKey)
val topBarTextView = activity?.findViewById<TextView>(R.id.topBar_textView) val settingsActivity = activity as SettingsActivity
topBarTextView?.text = getString(R.string.appearance) settingsActivity.binding.topBarTextView.text = getString(R.string.appearance)
val themeToggle = findPreference<ListPreference>("theme_togglee") val themeToggle = findPreference<ListPreference>("theme_togglee")
themeToggle?.setOnPreferenceChangeListener { _, _ -> themeToggle?.setOnPreferenceChangeListener { _, _ ->

View File

@ -8,7 +8,6 @@ import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.text.TextUtils import android.text.TextUtils
import android.util.Log import android.util.Log
import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.app.ActivityCompat import androidx.core.app.ActivityCompat
@ -19,6 +18,7 @@ import androidx.preference.ListPreference
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.SettingsActivity
import com.github.libretube.dialogs.CustomInstanceDialog import com.github.libretube.dialogs.CustomInstanceDialog
import com.github.libretube.dialogs.DeleteAccountDialog import com.github.libretube.dialogs.DeleteAccountDialog
import com.github.libretube.dialogs.LoginDialog import com.github.libretube.dialogs.LoginDialog
@ -111,8 +111,8 @@ class InstanceSettings : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.instance_settings, rootKey) setPreferencesFromResource(R.xml.instance_settings, rootKey)
val topBarTextView = activity?.findViewById<TextView>(R.id.topBar_textView) val settingsActivity = activity as SettingsActivity
topBarTextView?.text = getString(R.string.instance) settingsActivity.binding.topBarTextView.text = getString(R.string.instance)
val instance = findPreference<ListPreference>("selectInstance") val instance = findPreference<ListPreference>("selectInstance")
// fetchInstance() // fetchInstance()

View File

@ -1,9 +1,9 @@
package com.github.libretube.preferences package com.github.libretube.preferences
import android.os.Bundle import android.os.Bundle
import android.widget.TextView
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.SettingsActivity
class PlayerSettings : PreferenceFragmentCompat() { class PlayerSettings : PreferenceFragmentCompat() {
val TAG = "PlayerSettings" val TAG = "PlayerSettings"
@ -11,7 +11,7 @@ class PlayerSettings : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.player_settings, rootKey) setPreferencesFromResource(R.xml.player_settings, rootKey)
val topBarTextView = activity?.findViewById<TextView>(R.id.topBar_textView) val settingsActivity = activity as SettingsActivity
topBarTextView?.text = getString(R.string.player) settingsActivity.binding.topBarTextView.text = getString(R.string.player)
} }
} }

View File

@ -1,9 +1,9 @@
package com.github.libretube.preferences package com.github.libretube.preferences
import android.os.Bundle import android.os.Bundle
import android.widget.TextView
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.SettingsActivity
class SponsorBlockSettings : PreferenceFragmentCompat() { class SponsorBlockSettings : PreferenceFragmentCompat() {
private val TAG = "SponsorBlockSettings" private val TAG = "SponsorBlockSettings"
@ -11,7 +11,7 @@ class SponsorBlockSettings : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.sponsorblock_settings, rootKey) setPreferencesFromResource(R.xml.sponsorblock_settings, rootKey)
val topBarTextView = activity?.findViewById<TextView>(R.id.topBar_textView) val settingsActivity = activity as SettingsActivity
topBarTextView?.text = getString(R.string.sponsorblock) settingsActivity.binding.topBarTextView.text = getString(R.string.sponsorblock)
} }
} }

View File

@ -1,17 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" <vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="1280dp" android:width="1280dp"
android:height="1280dp" android:height="1280dp"
android:viewportWidth="1280" android:viewportWidth="1280"
android:viewportHeight="1280"> android:viewportHeight="1280">
<path <path
android:pathData="m863.3,639.7c0,-2.3 -1.2,-4.4 -3.1,-5.5L527.9,437.1c-5.8,-3.4 -13.1,0.8 -13.1,7.6v85c0,3.2 1.7,6.1 4.4,7.7l165.6,94.8c5.9,3.4 5.9,12 0,15.4l-165.6,94.8c-2.7,1.6 -4.4,4.5 -4.4,7.7v84.9c0,6.8 7.3,11.1 13.1,7.6L860.1,645.2c1.9,-1.2 3.1,-3.3 3.1,-5.5z" android:fillColor="#00000000"
android:strokeWidth="30" android:pathData="m863.3,639.7c0,-2.3 -1.2,-4.4 -3.1,-5.5L527.9,437.1c-5.8,-3.4 -13.1,0.8 -13.1,7.6v85c0,3.2 1.7,6.1 4.4,7.7l165.6,94.8c5.9,3.4 5.9,12 0,15.4l-165.6,94.8c-2.7,1.6 -4.4,4.5 -4.4,7.7v84.9c0,6.8 7.3,11.1 13.1,7.6L860.1,645.2c1.9,-1.2 3.1,-3.3 3.1,-5.5z"
android:fillColor="#00000000" android:strokeWidth="30"
android:strokeColor="#000000"/> android:strokeColor="#000000" />
<path <path
android:pathData="m582.8,634.5c4.2,2.4 4.2,8.5 0,10.9l-73.8,42.5c-4.1,2.4 -9.2,-0.6 -9.2,-5.4v-85.1c0,-4.8 5.1,-7.8 9.2,-5.4z" android:fillColor="#000000"
android:strokeWidth="0" android:pathData="m582.8,634.5c4.2,2.4 4.2,8.5 0,10.9l-73.8,42.5c-4.1,2.4 -9.2,-0.6 -9.2,-5.4v-85.1c0,-4.8 5.1,-7.8 9.2,-5.4z"
android:fillColor="#000000" android:strokeWidth="0"
android:strokeColor="#000000"/> android:strokeColor="#000000" />
</vector> </vector>

View File

@ -3,9 +3,9 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="100dp" android:layout_width="100dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingHorizontal="5dp"
android:background="?attr/selectableItemBackground" android:background="?attr/selectableItemBackground"
android:orientation="vertical"> android:orientation="vertical"
android:paddingHorizontal="5dp">
<com.google.android.material.imageview.ShapeableImageView <com.google.android.material.imageview.ShapeableImageView
android:id="@+id/chapter_image" android:id="@+id/chapter_image"