fix crash in settings

This commit is contained in:
Bnyro 2022-07-01 21:32:26 +02:00
parent 0e9f3ad96f
commit ff77c69eb1
12 changed files with 102 additions and 89 deletions

View File

@ -27,7 +27,7 @@
android:exported="false" />
<activity
android:name=".activities.NoInternetActivity"
android:label="@string/noInternet"/>
android:label="@string/noInternet" />
<activity
android:name=".activities.SettingsActivity"
android:label="@string/settings" />

View File

@ -79,7 +79,8 @@ class MainActivity : AppCompatActivity() {
// hide the trending page if enabled
val hideTrendingPage = PreferenceHelper.getBoolean(this, "hide_trending_page", false)
if (hideTrendingPage) bottomNavigationView.menu.findItem(R.id.homeFragment).isVisible = false
if (hideTrendingPage) bottomNavigationView.menu.findItem(R.id.homeFragment).isVisible =
false
// navigate to the default start tab
when (PreferenceHelper.getString(this, "default_tab", "home")) {

View File

@ -1,12 +1,14 @@
package com.github.libretube.dialogs
import android.app.Dialog
import android.content.Intent
import android.os.Bundle
import android.util.TypedValue
import android.widget.Toast
import androidx.core.text.HtmlCompat
import androidx.fragment.app.DialogFragment
import com.github.libretube.R
import com.github.libretube.activities.SettingsActivity
import com.github.libretube.databinding.DialogCustomInstanceBinding
import com.github.libretube.obj.CustomInstance
import com.github.libretube.util.PreferenceHelper
@ -43,7 +45,8 @@ class CustomInstanceDialog : DialogFragment() {
URL(customInstance.frontendUrl).toURI()
PreferenceHelper.saveCustomInstance(requireContext(), customInstance)
activity?.recreate()
val intent = Intent(context, SettingsActivity::class.java)
startActivity(intent)
dismiss()
} catch (e: Exception) {
// invalid URL

View File

@ -46,7 +46,8 @@ class LibraryFragment : Fragment() {
token = PreferenceHelper.getToken(requireContext())
// hide watch history button of history disabled
val watchHistoryEnabled = PreferenceHelper.getBoolean(requireContext(), "watch_history_toggle", true)
val watchHistoryEnabled =
PreferenceHelper.getBoolean(requireContext(), "watch_history_toggle", true)
if (!watchHistoryEnabled) {
binding.showWatchHistory.visibility = View.GONE
} else {

View File

@ -1,6 +1,8 @@
package com.github.libretube.preferences
import android.content.Intent
import android.os.Bundle
import androidx.navigation.fragment.findNavController
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import com.github.libretube.R
@ -49,7 +51,8 @@ class AdvancedSettings : PreferenceFragmentCompat() {
PreferenceHelper.setToken(requireContext(), "")
requireMainActivityRestart = true
activity?.recreate()
val intent = Intent(context, SettingsActivity::class.java)
startActivity(intent)
}
.setNegativeButton(getString(R.string.cancel)) { _, _ -> }
.setTitle(R.string.reset)

View File

@ -1,6 +1,8 @@
package com.github.libretube.preferences
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
@ -28,7 +30,8 @@ class AppearanceSettings : PreferenceFragmentCompat() {
val accentColor = findPreference<Preference>("accent_color")
accentColor?.setOnPreferenceChangeListener { _, _ ->
requireMainActivityRestart = true
activity?.recreate()
val intent = Intent(context, SettingsActivity::class.java)
startActivity(intent)
true
}

View File

@ -2,6 +2,7 @@ package com.github.libretube.preferences
import android.Manifest
import android.content.ContentResolver
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
@ -135,7 +136,8 @@ class InstanceSettings : PreferenceFragmentCompat() {
val clearCustomInstances = findPreference<Preference>("clearCustomInstances")
clearCustomInstances?.setOnPreferenceClickListener {
PreferenceHelper.removePreference(requireContext(), "customInstances")
activity?.recreate()
val intent = Intent(context, SettingsActivity::class.java)
startActivity(intent)
true
}

View File

@ -5,18 +5,18 @@
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M21.25,12C21.25,17.108 17.109,21.25 12,21.25C6.892,21.25 2.75,17.108 2.75,12C2.75,6.891 6.892,2.75 12,2.75C17.109,2.75 21.25,6.891 21.25,12Z"
android:strokeLineJoin="round"
android:strokeWidth="2.5"
android:fillColor="#00000000"
android:fillType="evenOdd"
android:strokeColor="#130F26"
android:strokeLineCap="round"/>
<path
android:pathData="M16.191,12.767L11.661,12.693V7.846"
android:strokeLineJoin="round"
android:pathData="M21.25,12C21.25,17.108 17.109,21.25 12,21.25C6.892,21.25 2.75,17.108 2.75,12C2.75,6.891 6.892,2.75 12,2.75C17.109,2.75 21.25,6.891 21.25,12Z"
android:strokeWidth="2.5"
android:fillColor="#00000000"
android:strokeColor="#130F26"
android:strokeLineCap="round"/>
android:strokeLineCap="round"
android:strokeLineJoin="round" />
<path
android:fillColor="#00000000"
android:pathData="M16.191,12.767L11.661,12.693V7.846"
android:strokeWidth="2.5"
android:strokeColor="#130F26"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
</vector>

View File

@ -6,12 +6,12 @@
<ImageView
android:id="@+id/noInternet_settingsImageView"
android:padding="3dp"
android:layout_width="33dp"
android:layout_height="33dp"
android:layout_margin="16dp"
android:src="@drawable/ic_settings"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="3dp"
android:src="@drawable/ic_settings"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

View File

@ -15,24 +15,24 @@
android:id="@+id/showWatchHistory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:background="?attr/selectableItemBackground"
android:orientation="horizontal">
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:src="@drawable/ic_time_outlined"
android:layout_gravity="center"/>
android:src="@drawable/ic_time_outlined" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="@string/watch_history"
android:textStyle="bold"
android:textSize="18sp"/>
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>

View File

@ -21,8 +21,8 @@
android:id="@+id/clearHistory"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginRight="5dp"
android:layout_gravity="center"
android:layout_marginRight="5dp"
android:src="@drawable/ic_reset" />
</LinearLayout>

View File

@ -47,5 +47,5 @@
android:id="@+id/watchHistoryFragment"
android:name="com.github.libretube.fragments.WatchHistoryFragment"
android:label="@string/watch_history"
tools:layout="@layout/fragment_watch_history"/>
tools:layout="@layout/fragment_watch_history" />
</navigation>