mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-01-06 01:20:29 +05:30
commit
d1c1c83e44
@ -55,3 +55,8 @@ const val PUSH_CHANNEL_ID = "notification_worker"
|
|||||||
* Database
|
* Database
|
||||||
*/
|
*/
|
||||||
const val DATABASE_NAME = "LibreTubeDatabase"
|
const val DATABASE_NAME = "LibreTubeDatabase"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New Streams notifications
|
||||||
|
*/
|
||||||
|
const val NOTIFICATION_WORK_NAME = "NotificationService"
|
@ -29,6 +29,7 @@ import androidx.core.net.toUri
|
|||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
@ -1638,6 +1639,12 @@ class PlayerFragment : BaseFragment() {
|
|||||||
binding.linLayout.visibility = View.GONE
|
binding.linLayout.visibility = View.GONE
|
||||||
|
|
||||||
viewModel.isFullscreen.value = false
|
viewModel.isFullscreen.value = false
|
||||||
|
} else if (lifecycle.currentState == Lifecycle.State.CREATED) {
|
||||||
|
// close button got clicked in PiP mode
|
||||||
|
// destroying the fragment, player and notification
|
||||||
|
onDestroy()
|
||||||
|
// finish the activity
|
||||||
|
activity?.finishAndRemoveTask()
|
||||||
} else {
|
} else {
|
||||||
// enable exoPlayer controls again
|
// enable exoPlayer controls again
|
||||||
exoPlayerView.useController = true
|
exoPlayerView.useController = true
|
||||||
|
@ -10,6 +10,7 @@ import androidx.work.ExistingPeriodicWorkPolicy
|
|||||||
import androidx.work.NetworkType
|
import androidx.work.NetworkType
|
||||||
import androidx.work.PeriodicWorkRequest
|
import androidx.work.PeriodicWorkRequest
|
||||||
import androidx.work.WorkManager
|
import androidx.work.WorkManager
|
||||||
|
import com.github.libretube.NOTIFICATION_WORK_NAME
|
||||||
import com.github.libretube.PUSH_CHANNEL_ID
|
import com.github.libretube.PUSH_CHANNEL_ID
|
||||||
import com.github.libretube.PUSH_NOTIFICATION_ID
|
import com.github.libretube.PUSH_NOTIFICATION_ID
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
@ -23,6 +24,9 @@ import kotlinx.coroutines.runBlocking
|
|||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
object NotificationHelper {
|
object NotificationHelper {
|
||||||
|
/**
|
||||||
|
* Enqueue the work manager task
|
||||||
|
*/
|
||||||
fun enqueueWork(
|
fun enqueueWork(
|
||||||
context: Context,
|
context: Context,
|
||||||
existingPeriodicWorkPolicy: ExistingPeriodicWorkPolicy
|
existingPeriodicWorkPolicy: ExistingPeriodicWorkPolicy
|
||||||
@ -39,8 +43,6 @@ object NotificationHelper {
|
|||||||
"60"
|
"60"
|
||||||
).toLong()
|
).toLong()
|
||||||
|
|
||||||
val uniqueWorkName = "NotificationService"
|
|
||||||
|
|
||||||
// schedule the work manager request if logged in and notifications enabled
|
// schedule the work manager request if logged in and notifications enabled
|
||||||
if (notificationsEnabled && PreferenceHelper.getToken() != "") {
|
if (notificationsEnabled && PreferenceHelper.getToken() != "") {
|
||||||
// required network type for the work
|
// required network type for the work
|
||||||
@ -71,14 +73,14 @@ object NotificationHelper {
|
|||||||
// enqueue the task
|
// enqueue the task
|
||||||
WorkManager.getInstance(context)
|
WorkManager.getInstance(context)
|
||||||
.enqueueUniquePeriodicWork(
|
.enqueueUniquePeriodicWork(
|
||||||
uniqueWorkName,
|
NOTIFICATION_WORK_NAME,
|
||||||
existingPeriodicWorkPolicy,
|
existingPeriodicWorkPolicy,
|
||||||
notificationWorker
|
notificationWorker
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// cancel the work if notifications are disabled or the user is not logged in
|
// cancel the work if notifications are disabled or the user is not logged in
|
||||||
WorkManager.getInstance(context)
|
WorkManager.getInstance(context)
|
||||||
.cancelUniqueWork(uniqueWorkName)
|
.cancelUniqueWork(NOTIFICATION_WORK_NAME)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,8 +8,10 @@ import android.os.Environment
|
|||||||
import androidx.core.app.ActivityCompat
|
import androidx.core.app.ActivityCompat
|
||||||
|
|
||||||
object PermissionHelper {
|
object PermissionHelper {
|
||||||
|
/**
|
||||||
|
* request storage permissions if not granted yet
|
||||||
|
*/
|
||||||
fun requestReadWrite(activity: Activity): Boolean {
|
fun requestReadWrite(activity: Activity): Boolean {
|
||||||
// request storage permissions if not granted yet
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
if (!Environment.isExternalStorageManager()) {
|
if (!Environment.isExternalStorageManager()) {
|
||||||
ActivityCompat.requestPermissions(
|
ActivityCompat.requestPermissions(
|
||||||
|
@ -17,6 +17,9 @@ import com.google.android.material.color.DynamicColors
|
|||||||
|
|
||||||
object ThemeHelper {
|
object ThemeHelper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the theme, including accent color and night mode
|
||||||
|
*/
|
||||||
fun updateTheme(activity: AppCompatActivity) {
|
fun updateTheme(activity: AppCompatActivity) {
|
||||||
val themeMode = PreferenceHelper.getString(PreferenceKeys.THEME_MODE, "A")
|
val themeMode = PreferenceHelper.getString(PreferenceKeys.THEME_MODE, "A")
|
||||||
val pureThemeEnabled = PreferenceHelper.getBoolean(PreferenceKeys.PURE_THEME, false)
|
val pureThemeEnabled = PreferenceHelper.getBoolean(PreferenceKeys.PURE_THEME, false)
|
||||||
@ -25,6 +28,9 @@ object ThemeHelper {
|
|||||||
updateThemeMode(themeMode)
|
updateThemeMode(themeMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the accent color of the app
|
||||||
|
*/
|
||||||
private fun updateAccentColor(
|
private fun updateAccentColor(
|
||||||
activity: AppCompatActivity,
|
activity: AppCompatActivity,
|
||||||
pureThemeEnabled: Boolean
|
pureThemeEnabled: Boolean
|
||||||
@ -51,13 +57,16 @@ object ThemeHelper {
|
|||||||
activity.setTheme(theme)
|
activity.setTheme(theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* apply dynamic colors to the activity
|
||||||
|
*/
|
||||||
private fun applyDynamicColors(activity: AppCompatActivity) {
|
private fun applyDynamicColors(activity: AppCompatActivity) {
|
||||||
/**
|
|
||||||
* apply dynamic colors to the activity
|
|
||||||
*/
|
|
||||||
DynamicColors.applyToActivityIfAvailable(activity)
|
DynamicColors.applyToActivityIfAvailable(activity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the theme mode (light, dark, auto)
|
||||||
|
*/
|
||||||
private fun updateThemeMode(themeMode: String) {
|
private fun updateThemeMode(themeMode: String) {
|
||||||
val mode = when (themeMode) {
|
val mode = when (themeMode) {
|
||||||
"A" -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
"A" -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||||
@ -68,6 +77,9 @@ object ThemeHelper {
|
|||||||
AppCompatDelegate.setDefaultNightMode(mode)
|
AppCompatDelegate.setDefaultNightMode(mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* change the app icon
|
||||||
|
*/
|
||||||
fun changeIcon(context: Context, newLogoActivityAlias: String) {
|
fun changeIcon(context: Context, newLogoActivityAlias: String) {
|
||||||
val activityAliases = context.resources.getStringArray(R.array.iconsValue)
|
val activityAliases = context.resources.getStringArray(R.array.iconsValue)
|
||||||
// Disable Old Icon(s)
|
// Disable Old Icon(s)
|
||||||
@ -96,7 +108,9 @@ object ThemeHelper {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Needed due to different MainActivity Aliases because of the app icons
|
/**
|
||||||
|
* Needed due to different MainActivity Aliases because of the app icons
|
||||||
|
*/
|
||||||
fun restartMainActivity(context: Context) {
|
fun restartMainActivity(context: Context) {
|
||||||
// kill player notification
|
// kill player notification
|
||||||
val nManager = context
|
val nManager = context
|
||||||
@ -111,12 +125,18 @@ object ThemeHelper {
|
|||||||
android.os.Process.killProcess(android.os.Process.myPid())
|
android.os.Process.killProcess(android.os.Process.myPid())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a color by a resource code
|
||||||
|
*/
|
||||||
fun getThemeColor(context: Context, colorCode: Int): Int {
|
fun getThemeColor(context: Context, colorCode: Int): Int {
|
||||||
val value = TypedValue()
|
val value = TypedValue()
|
||||||
context.theme.resolveAttribute(colorCode, value, true)
|
context.theme.resolveAttribute(colorCode, value, true)
|
||||||
return value.data
|
return value.data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the styled app name
|
||||||
|
*/
|
||||||
fun getStyledAppName(context: Context): Spanned {
|
fun getStyledAppName(context: Context): Spanned {
|
||||||
val colorPrimary = getThemeColor(context, R.attr.colorPrimaryDark)
|
val colorPrimary = getThemeColor(context, R.attr.colorPrimaryDark)
|
||||||
val hexColor = String.format("#%06X", (0xFFFFFF and colorPrimary))
|
val hexColor = String.format("#%06X", (0xFFFFFF and colorPrimary))
|
||||||
|
Loading…
Reference in New Issue
Block a user