From ff77c69eb10643f68a8698b779600a04cd5e90bb Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 1 Jul 2022 21:32:26 +0200 Subject: [PATCH] fix crash in settings --- app/src/main/AndroidManifest.xml | 2 +- .../libretube/activities/MainActivity.kt | 3 +- .../libretube/dialogs/CustomInstanceDialog.kt | 5 +- .../libretube/fragments/LibraryFragment.kt | 3 +- .../libretube/preferences/AdvancedSettings.kt | 5 +- .../preferences/AppearanceSettings.kt | 5 +- .../libretube/preferences/InstanceSettings.kt | 4 +- .../main/res/drawable/ic_time_outlined.xml | 30 ++--- .../main/res/layout/activity_nointernet.xml | 4 +- app/src/main/res/layout/fragment_library.xml | 126 +++++++++--------- .../res/layout/fragment_watch_history.xml | 2 +- app/src/main/res/navigation/nav.xml | 2 +- 12 files changed, 102 insertions(+), 89 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3081a7847..a548dad46 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -27,7 +27,7 @@ android:exported="false" /> + android:label="@string/noInternet" /> diff --git a/app/src/main/java/com/github/libretube/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/activities/MainActivity.kt index eb4b5eef5..b4d137e4c 100644 --- a/app/src/main/java/com/github/libretube/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/MainActivity.kt @@ -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")) { diff --git a/app/src/main/java/com/github/libretube/dialogs/CustomInstanceDialog.kt b/app/src/main/java/com/github/libretube/dialogs/CustomInstanceDialog.kt index 9cd1769fe..b4d6261b2 100644 --- a/app/src/main/java/com/github/libretube/dialogs/CustomInstanceDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/CustomInstanceDialog.kt @@ -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 diff --git a/app/src/main/java/com/github/libretube/fragments/LibraryFragment.kt b/app/src/main/java/com/github/libretube/fragments/LibraryFragment.kt index 893f7249c..e45779148 100644 --- a/app/src/main/java/com/github/libretube/fragments/LibraryFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/LibraryFragment.kt @@ -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 { diff --git a/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt b/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt index 91a38d072..eb9208e24 100644 --- a/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/AdvancedSettings.kt @@ -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) diff --git a/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt b/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt index a43d17d86..09c642a23 100644 --- a/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt @@ -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("accent_color") accentColor?.setOnPreferenceChangeListener { _, _ -> requireMainActivityRestart = true - activity?.recreate() + val intent = Intent(context, SettingsActivity::class.java) + startActivity(intent) true } diff --git a/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt b/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt index 5fa8b51a1..de307f8dd 100644 --- a/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt @@ -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("clearCustomInstances") clearCustomInstances?.setOnPreferenceClickListener { PreferenceHelper.removePreference(requireContext(), "customInstances") - activity?.recreate() + val intent = Intent(context, SettingsActivity::class.java) + startActivity(intent) true } diff --git a/app/src/main/res/drawable/ic_time_outlined.xml b/app/src/main/res/drawable/ic_time_outlined.xml index 255a78753..82baa4c1d 100644 --- a/app/src/main/res/drawable/ic_time_outlined.xml +++ b/app/src/main/res/drawable/ic_time_outlined.xml @@ -4,19 +4,19 @@ android:tint="?android:attr/colorControlNormal" android:viewportWidth="24" android:viewportHeight="24"> - - + + diff --git a/app/src/main/res/layout/activity_nointernet.xml b/app/src/main/res/layout/activity_nointernet.xml index c0fde8737..e131d0f7c 100644 --- a/app/src/main/res/layout/activity_nointernet.xml +++ b/app/src/main/res/layout/activity_nointernet.xml @@ -6,12 +6,12 @@ diff --git a/app/src/main/res/layout/fragment_library.xml b/app/src/main/res/layout/fragment_library.xml index e437eb9cb..797826685 100644 --- a/app/src/main/res/layout/fragment_library.xml +++ b/app/src/main/res/layout/fragment_library.xml @@ -11,88 +11,88 @@ android:layout_height="match_parent" android:orientation="vertical"> - - - + android:background="?attr/selectableItemBackground" + android:orientation="horizontal" + android:padding="10dp"> - + - + - + - - - - + android:layout_centerVertical="true"> - + - + + + - + android:layout_height="match_parent"> - + android:orientation="vertical"> - + android:descendantFocusability="blocksDescendants"> - - - - + + + + + + diff --git a/app/src/main/res/layout/fragment_watch_history.xml b/app/src/main/res/layout/fragment_watch_history.xml index 1a1bfe464..af694e030 100644 --- a/app/src/main/res/layout/fragment_watch_history.xml +++ b/app/src/main/res/layout/fragment_watch_history.xml @@ -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" /> diff --git a/app/src/main/res/navigation/nav.xml b/app/src/main/res/navigation/nav.xml index 31d75575c..50e5f51cb 100644 --- a/app/src/main/res/navigation/nav.xml +++ b/app/src/main/res/navigation/nav.xml @@ -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" /> \ No newline at end of file