Merge pull request #833 from Bnyro/master

cleanup and bug fixes
This commit is contained in:
Bnyro 2022-07-20 22:04:25 +02:00 committed by GitHub
commit febfa26eee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 131 additions and 62 deletions

View File

@ -3,6 +3,7 @@ package com.github.libretube.activities
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.pm.ActivityInfo
import android.content.res.Configuration
import android.net.Uri
import android.os.Build
@ -47,6 +48,7 @@ class MainActivity : AppCompatActivity() {
lateinit var navController: NavController
private var startFragmentId = R.id.homeFragment
var autoRotationEnabled = false
override fun onCreate(savedInstanceState: Bundle?) {
// set the app theme (e.g. Material You)
@ -57,6 +59,12 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
autoRotationEnabled = PreferenceHelper.getBoolean(PreferenceKeys.AUTO_ROTATION, false)
// enable auto rotation if turned on
requestedOrientation = if (autoRotationEnabled) ActivityInfo.SCREEN_ORIENTATION_USER
else ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
// start service that gets called on closure
startService(Intent(this, ClosingService::class.java))
@ -323,6 +331,8 @@ class MainActivity : AppCompatActivity() {
}
findViewById<LinearLayout>(R.id.linLayout).visibility = View.VISIBLE
Globals.IS_FULL_SCREEN = false
requestedOrientation = if (autoRotationEnabled) ActivityInfo.SCREEN_ORIENTATION_USER
else ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
}
override fun onConfigurationChanged(newConfig: Configuration) {

View File

@ -563,7 +563,6 @@ class PlayerFragment : Fragment() {
binding.linLayout.visibility = View.GONE
playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen_exit)
playerBinding.exoTitle.visibility = View.VISIBLE
playerBinding.closeImageButton.visibility = View.GONE
scaleControls(1.3F)
@ -585,6 +584,7 @@ class PlayerFragment : Fragment() {
}
mainActivity.requestedOrientation = orientation
}
binding.player.setDoubleTapOverlayLayoutParams(90)
Globals.IS_FULL_SCREEN = true
}
@ -600,7 +600,6 @@ class PlayerFragment : Fragment() {
binding.linLayout.visibility = View.VISIBLE
playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen)
playerBinding.exoTitle.visibility = View.INVISIBLE
playerBinding.closeImageButton.visibility = View.VISIBLE
scaleControls(1F)
@ -667,6 +666,8 @@ class PlayerFragment : Fragment() {
) as NotificationManager
notificationManager.cancel(1)
exoPlayer.release()
activity?.requestedOrientation = if ((activity as MainActivity).autoRotationEnabled) ActivityInfo.SCREEN_ORIENTATION_USER
else ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
} catch (e: Exception) {
}
}
@ -1527,12 +1528,6 @@ class PlayerFragment : Fragment() {
Globals.IS_FULL_SCREEN
) View.VISIBLE else View.INVISIBLE
// hide the close image button
playerBinding.closeImageButton.visibility =
if (isLocked &&
!(Globals.IS_FULL_SCREEN && !autoRotationEnabled)
) View.VISIBLE else View.GONE
// disable double tap to seek when the player is locked
if (isLocked) {
// enable fast forward and rewind by double tapping

View File

@ -53,13 +53,6 @@ class AppearanceSettings : PreferenceFragmentCompat() {
true
}
val hideTrending = findPreference<SwitchPreferenceCompat>(PreferenceKeys.HIDE_TRENDING_PAGE)
hideTrending?.setOnPreferenceChangeListener { _, _ ->
val restartDialog = RequireRestartDialog()
restartDialog.show(childFragmentManager, "RequireRestartDialog")
true
}
val labelVisibilityMode = findPreference<ListPreference>(PreferenceKeys.LABEL_VISIBILITY)
labelVisibilityMode?.setOnPreferenceChangeListener { _, _ ->
val restartDialog = RequireRestartDialog()

View File

@ -0,0 +1,49 @@
package com.github.libretube.preferences
import android.os.Bundle
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreferenceCompat
import com.github.libretube.R
import com.github.libretube.activities.SettingsActivity
import com.github.libretube.dialogs.RequireRestartDialog
class GeneralSettings : PreferenceFragmentCompat() {
val TAG = "SettingsFragment"
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.general_settings, rootKey)
val settingsActivity = activity as SettingsActivity
settingsActivity.changeTopBarText(getString(R.string.general))
val region = findPreference<Preference>("region")
region?.setOnPreferenceChangeListener { _, _ ->
val restartDialog = RequireRestartDialog()
restartDialog.show(childFragmentManager, "RequireRestartDialog")
true
}
val language = findPreference<ListPreference>("language")
language?.setOnPreferenceChangeListener { _, _ ->
val restartDialog = RequireRestartDialog()
restartDialog.show(childFragmentManager, "RequireRestartDialog")
true
}
val autoRotation = findPreference<SwitchPreferenceCompat>(PreferenceKeys.AUTO_ROTATION)
autoRotation?.setOnPreferenceChangeListener { _, _ ->
val restartDialog = RequireRestartDialog()
restartDialog.show(childFragmentManager, "RequireRestartDialog")
true
}
val hideTrending = findPreference<SwitchPreferenceCompat>(PreferenceKeys.HIDE_TRENDING_PAGE)
hideTrending?.setOnPreferenceChangeListener { _, _ ->
val restartDialog = RequireRestartDialog()
restartDialog.show(childFragmentManager, "RequireRestartDialog")
true
}
}
}

View File

@ -3,13 +3,11 @@ package com.github.libretube.preferences
import android.os.Bundle
import androidx.activity.result.ActivityResultLauncher
import androidx.fragment.app.Fragment
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import com.github.libretube.BuildConfig
import com.github.libretube.R
import com.github.libretube.activities.SettingsActivity
import com.github.libretube.dialogs.RequireRestartDialog
import com.github.libretube.dialogs.UpdateDialog
import com.github.libretube.update.UpdateChecker
import com.google.android.material.snackbar.Snackbar
@ -27,17 +25,10 @@ class MainSettings : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.settings, rootKey)
val region = findPreference<Preference>("region")
region?.setOnPreferenceChangeListener { _, _ ->
val restartDialog = RequireRestartDialog()
restartDialog.show(childFragmentManager, "RequireRestartDialog")
true
}
val language = findPreference<ListPreference>("language")
language?.setOnPreferenceChangeListener { _, _ ->
val restartDialog = RequireRestartDialog()
restartDialog.show(childFragmentManager, "RequireRestartDialog")
val general = findPreference<Preference>("general")
general?.setOnPreferenceClickListener {
val newFragment = GeneralSettings()
navigateToSettingsFragment(newFragment)
true
}
@ -90,6 +81,7 @@ class MainSettings : PreferenceFragmentCompat() {
else getString(R.string.version, BuildConfig.VERSION_NAME)
update?.title = versionString
// checking for update: yes -> dialog, no -> snackBar
update?.setOnPreferenceClickListener {
CoroutineScope(Dispatchers.IO).launch {
// check for update

View File

@ -9,6 +9,7 @@ object PreferenceKeys {
*/
const val LANGUAGE = "language"
const val REGION = "region"
const val AUTO_ROTATION = "auto_rotation"
/**
* Appearance

View File

@ -35,7 +35,7 @@ internal class CustomExoPlayerView(
}
// set the top and bottom margin of the double tap overlay
private fun setDoubleTapOverlayLayoutParams(margin: Int) {
fun setDoubleTapOverlayLayoutParams(margin: Int) {
val dpMargin = resources?.displayMetrics?.density!!.toInt() * margin
val doubleTapOverlay = binding.root.findViewById<DoubleTapOverlay>(R.id.doubleTapOverlay)
val params = doubleTapOverlay.layoutParams as MarginLayoutParams

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?android:attr/colorControlNormal"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:fillColor="#FF000000"
android:pathData="M25.8,38.45 L9.55,22.2q-0.4,-0.4 -0.7,-1.075 -0.3,-0.675 -0.3,-1.225t0.3,-1.225q0.3,-0.675 0.7,-1.075l8.3,-8.25q0.4,-0.4 1.075,-0.725Q19.6,8.3 20.15,8.3t1.225,0.325q0.675,0.325 1.075,0.725L38.7,25.6q0.4,0.4 0.7,1.075 0.3,0.675 0.3,1.225t-0.3,1.225q-0.3,0.675 -0.7,1.075l-8.3,8.25q-0.4,0.4 -1.075,0.725 -0.675,0.325 -1.225,0.325t-1.225,-0.325q-0.675,-0.325 -1.075,-0.725ZM23.9,48.05q-4.95,0 -9.3,-1.875 -4.35,-1.875 -7.6,-5.15Q3.75,37.75 1.875,33.4T0,24.1h3q0,4 1.45,7.575t3.975,6.35Q10.95,40.8 14.35,42.55q3.4,1.75 7.3,2.15l-6.5,-6.5 2.15,-2.15 11.4,11.4q-1.25,0.35 -2.475,0.475t-2.325,0.125ZM45,24.1q0,-4 -1.425,-7.575T39.65,10.15q-2.5,-2.8 -5.875,-4.575Q30.4,3.8 26.5,3.4l6.4,6.4 -2.15,2.15L19.35,0.55Q20.55,0.2 21.675,0.1 22.8,0 23.9,0q4.95,0 9.325,1.9Q37.6,3.8 40.9,7.1q3.3,3.3 5.2,7.675Q48,19.15 48,24.1Z" />
</vector>

View File

@ -255,4 +255,6 @@
<string name="update_now">Do you want to update the app now?</string>
<string name="seekbar_preview">Seekbar preview</string>
<string name="seekbar_preview_summary">Preview the video by seeking to the position when scrubbing the seekbar.</string>
<string name="general">General</string>
<string name="general_summary">Language, region</string>
</resources>

View File

@ -88,15 +88,4 @@
</PreferenceCategory>
<PreferenceCategory>
<SwitchPreferenceCompat
android:defaultValue="true"
android:icon="@drawable/ic_list"
app:key="related_streams_toggle"
app:summary="@string/related_streams_summary"
app:title="@string/related_streams" />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory app:title="@string/location">
<ListPreference
android:icon="@drawable/ic_region"
app:defaultValue="sys"
app:entries="@array/regions"
app:entryValues="@array/regionsValue"
app:key="region"
app:title="@string/region"
app:useSimpleSummaryProvider="true" />
<ListPreference
android:icon="@drawable/ic_translate"
app:defaultValue="sys"
app:entries="@array/languages"
app:entryValues="@array/languagesValue"
app:key="language"
app:title="@string/changeLanguage"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>
<PreferenceCategory app:title="@string/customization">
<SwitchPreferenceCompat
android:defaultValue="false"
android:icon="@drawable/ic_screen_rotation"
app:key="auto_rotation"
app:title="@string/auto_rotation" />
<SwitchPreferenceCompat
android:defaultValue="true"
android:icon="@drawable/ic_list"
app:key="related_streams_toggle"
app:summary="@string/related_streams_summary"
app:title="@string/related_streams" />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -2,29 +2,13 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory app:title="@string/location">
<PreferenceCategory>
<ListPreference
android:icon="@drawable/ic_region"
app:defaultValue="sys"
app:entries="@array/regions"
app:entryValues="@array/regionsValue"
app:key="region"
app:title="@string/region"
app:useSimpleSummaryProvider="true" />
<ListPreference
android:icon="@drawable/ic_translate"
app:defaultValue="sys"
app:entries="@array/languages"
app:entryValues="@array/languagesValue"
app:key="language"
app:title="@string/changeLanguage"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>
<PreferenceCategory app:title="@string/customization">
<Preference
android:icon="@drawable/ic_settings"
app:key="general"
android:summary="@string/general_summary"
app:title="@string/general" />
<Preference
android:icon="@drawable/ic_server"