Merge pull request #382 from Bnyro/master

OLED Accent colors
This commit is contained in:
Bnyro 2022-06-05 10:53:20 +02:00 committed by GitHub
commit 69f0ac197d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 73 additions and 56 deletions

View File

@ -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 =

View File

@ -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"

View File

@ -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) {

View File

@ -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")
}
}

View File

@ -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()

View File

@ -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<LinearLayout>(R.id.relPlayer_share).setOnClickListener {
showShareDialog(requireContext(), videoId!!)
val shareDialog = ShareDialog(videoId!!)
shareDialog.show(childFragmentManager, "ShareDialog")
}
// check if livestream
if (response.duration!! > 0) {

View File

@ -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")

View File

@ -148,14 +148,4 @@
</style>
<style name="Theme.OLED" parent="Theme.Material3.Dark.NoActionBar">
<item name="android:colorBackground">@color/black</item>
<item name="colorSurface">@color/black</item>
<item name="android:statusBarColor" tools:targetApi="m">@android:color/transparent</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">false</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
</style>
</resources>

View File

@ -5,4 +5,14 @@
<item name="cornerFamily">rounded</item>
<item name="cornerSize">10%</item>
</style>
<style name="OLED">
<item name="android:colorBackground">@color/black</item>
<item name="colorSurface">@color/black</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
</style>
</resources>