From 14e326e61bff5b9a6a2e7a1aea0b08010af26a53 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 5 Jun 2022 10:35:47 +0200 Subject: [PATCH 1/2] OLED Accent colors --- .../java/com/github/libretube/MainActivity.kt | 5 +++-- .../com/github/libretube/RouterActivity.kt | 1 + .../com/github/libretube/SettingsActivity.kt | 6 ++++-- .../com/github/libretube/util/ThemeChanger.kt | 18 +++++++++++------- app/src/main/res/values-night/themes.xml | 10 ---------- app/src/main/res/values/style.xml | 10 ++++++++++ 6 files changed, 29 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/github/libretube/MainActivity.kt b/app/src/main/java/com/github/libretube/MainActivity.kt index 6381140af..1328a6de1 100644 --- a/app/src/main/java/com/github/libretube/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/MainActivity.kt @@ -35,6 +35,8 @@ import com.github.libretube.fragments.PlayerFragment import com.github.libretube.fragments.isFullScreen import com.github.libretube.util.CronetHelper import com.github.libretube.util.RetrofitInstance +import com.github.libretube.util.updateLanguage +import com.github.libretube.util.updateTheme import com.google.android.material.bottomnavigation.BottomNavigationView import com.google.android.material.color.DynamicColors @@ -66,8 +68,7 @@ class MainActivity : AppCompatActivity() { SponsorBlockSettings.outroEnabled = sharedPreferences.getBoolean("outro_category_key", false) - updateAccentColor(this) - updateThemeMode(this) + updateTheme(this) updateLanguage(this) val connectivityManager = diff --git a/app/src/main/java/com/github/libretube/RouterActivity.kt b/app/src/main/java/com/github/libretube/RouterActivity.kt index dfd6921df..2131fa504 100644 --- a/app/src/main/java/com/github/libretube/RouterActivity.kt +++ b/app/src/main/java/com/github/libretube/RouterActivity.kt @@ -6,6 +6,7 @@ import android.net.Uri import android.os.Bundle import android.util.Log import androidx.appcompat.app.AppCompatActivity +import com.github.libretube.util.restartMainActivity class RouterActivity : AppCompatActivity() { val TAG = "RouterActivity" diff --git a/app/src/main/java/com/github/libretube/SettingsActivity.kt b/app/src/main/java/com/github/libretube/SettingsActivity.kt index b6884c606..20a91a1c7 100644 --- a/app/src/main/java/com/github/libretube/SettingsActivity.kt +++ b/app/src/main/java/com/github/libretube/SettingsActivity.kt @@ -29,6 +29,9 @@ import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceManager import com.github.libretube.dialogs.LoginDialog import com.github.libretube.util.RetrofitInstance +import com.github.libretube.util.changeIcon +import com.github.libretube.util.restartMainActivity +import com.github.libretube.util.updateTheme import com.google.android.material.color.DynamicColors import com.google.android.material.dialog.MaterialAlertDialogBuilder import java.io.IOException @@ -48,8 +51,7 @@ class SettingsActivity : override fun onCreate(savedInstanceState: Bundle?) { DynamicColors.applyToActivityIfAvailable(this) - updateAccentColor(this) - updateThemeMode(this) + updateTheme(this) super.onCreate(savedInstanceState) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { diff --git a/app/src/main/java/com/github/libretube/util/ThemeChanger.kt b/app/src/main/java/com/github/libretube/util/ThemeChanger.kt index ab312f2ce..49b6c0695 100644 --- a/app/src/main/java/com/github/libretube/util/ThemeChanger.kt +++ b/app/src/main/java/com/github/libretube/util/ThemeChanger.kt @@ -1,4 +1,4 @@ -package com.github.libretube +package com.github.libretube.util import android.app.NotificationManager import android.content.ComponentName @@ -8,8 +8,14 @@ import android.content.pm.PackageManager import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatDelegate import androidx.preference.PreferenceManager +import com.github.libretube.R import java.util.* +fun updateTheme(context: Context) { + updateAccentColor(context) + updateThemeMode(context) +} + fun updateAccentColor(context: Context) { val colorAccent = PreferenceManager.getDefaultSharedPreferences(context).getString("accent_color", "red") @@ -30,15 +36,13 @@ fun updateThemeMode(context: Context) { "A" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) "L" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) "D" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) - "O" -> oledMode(context) + "O" -> { + context.setTheme(R.style.OLED) + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) + } } } -fun oledMode(context: Context) { - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) - context.setTheme(R.style.Theme_OLED) -} - fun updateLanguage(context: Context) { val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context) val languageName = sharedPreferences.getString("language", "sys") diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 047ad87fd..b023f75c9 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -148,14 +148,4 @@ - - \ No newline at end of file diff --git a/app/src/main/res/values/style.xml b/app/src/main/res/values/style.xml index b2fd47858..aaffe0889 100644 --- a/app/src/main/res/values/style.xml +++ b/app/src/main/res/values/style.xml @@ -5,4 +5,14 @@ rounded 10% + + \ No newline at end of file From 55688921a085620b5ac6d19b5c654b867cb8a7f4 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 5 Jun 2022 10:52:35 +0200 Subject: [PATCH 2/2] share dialog rewrite --- .../github/libretube/dialogs/ShareDialog.kt | 71 ++++++++++--------- .../libretube/dialogs/VideoOptionsDialog.kt | 3 +- .../libretube/fragments/PlayerFragment.kt | 5 +- 3 files changed, 44 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt b/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt index 327eff80c..afe2b6a06 100644 --- a/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt @@ -1,41 +1,48 @@ package com.github.libretube.dialogs -import android.content.Context +import android.app.Dialog import android.content.Intent +import android.os.Bundle +import androidx.fragment.app.DialogFragment import androidx.preference.PreferenceManager import com.github.libretube.R import com.google.android.material.dialog.MaterialAlertDialogBuilder import java.net.URLEncoder -fun showShareDialog(context: Context, videoId: String) { - val sharedPreferences = - PreferenceManager.getDefaultSharedPreferences(context) - val instancePref = sharedPreferences.getString( - "instance", - "https://pipedapi.kavin.rocks" - )!! - val instance = "&instance=${URLEncoder.encode(instancePref, "UTF-8")}" - val shareOptions = arrayOf( - context.getString(R.string.piped), - context.getString(R.string.instance), - context.getString(R.string.youtube) - ) - MaterialAlertDialogBuilder(context) - .setTitle(context.getString(R.string.share)) - .setItems( - shareOptions - ) { _, id -> - val url = when (id) { - 0 -> "https://piped.kavin.rocks/watch?v=$videoId" - 1 -> "https://piped.kavin.rocks/watch?v=$videoId$instance" - 2 -> "https://youtu.be/$videoId" - else -> "https://piped.kavin.rocks/watch?v=$videoId" - } - val intent = Intent() - intent.action = Intent.ACTION_SEND - intent.putExtra(Intent.EXTRA_TEXT, url) - intent.type = "text/plain" - context.startActivity(Intent.createChooser(intent, "Share Url To:")) - } - .show() +class ShareDialog(private val videoId: String) : DialogFragment() { + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + return activity?.let { + val sharedPreferences = + PreferenceManager.getDefaultSharedPreferences(requireContext()) + val instancePref = sharedPreferences.getString( + "instance", + "https://pipedapi.kavin.rocks" + )!! + val instance = "&instance=${URLEncoder.encode(instancePref, "UTF-8")}" + val shareOptions = arrayOf( + context?.getString(R.string.piped), + context?.getString(R.string.instance), + context?.getString(R.string.youtube) + ) + MaterialAlertDialogBuilder(requireContext()) + .setTitle(context?.getString(R.string.share)) + .setItems( + shareOptions + ) { _, id -> + val url = when (id) { + 0 -> "https://piped.kavin.rocks/watch?v=$videoId" + 1 -> "https://piped.kavin.rocks/watch?v=$videoId$instance" + 2 -> "https://youtu.be/$videoId" + else -> "https://piped.kavin.rocks/watch?v=$videoId" + } + val intent = Intent() + intent.action = Intent.ACTION_SEND + intent.putExtra(Intent.EXTRA_TEXT, url) + intent.type = "text/plain" + context?.startActivity(Intent.createChooser(intent, "Share Url To:")) + } + .show() + } ?: throw IllegalStateException("Activity cannot be null") + } } diff --git a/app/src/main/java/com/github/libretube/dialogs/VideoOptionsDialog.kt b/app/src/main/java/com/github/libretube/dialogs/VideoOptionsDialog.kt index aa557fbf3..19a521ee8 100644 --- a/app/src/main/java/com/github/libretube/dialogs/VideoOptionsDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/VideoOptionsDialog.kt @@ -66,7 +66,8 @@ class VideoOptionsDialog(private val videoId: String, context: Context) : Dialog } } 2 -> { - showShareDialog(requireContext(), videoId) + val shareDialog = ShareDialog(videoId) + shareDialog.show(childFragmentManager, "ShareDialog") } else -> { dialog.dismiss() diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index e2b0c48db..f8a86cad6 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -48,7 +48,7 @@ import com.github.libretube.adapters.CommentsAdapter import com.github.libretube.adapters.TrendingAdapter import com.github.libretube.dialogs.AddtoPlaylistDialog import com.github.libretube.dialogs.DownloadDialog -import com.github.libretube.dialogs.showShareDialog +import com.github.libretube.dialogs.ShareDialog import com.github.libretube.formatShort import com.github.libretube.hideKeyboard import com.github.libretube.obj.PipedStream @@ -493,7 +493,8 @@ class PlayerFragment : Fragment() { // share button view.findViewById(R.id.relPlayer_share).setOnClickListener { - showShareDialog(requireContext(), videoId!!) + val shareDialog = ShareDialog(videoId!!) + shareDialog.show(childFragmentManager, "ShareDialog") } // check if livestream if (response.duration!! > 0) {