add documentation

This commit is contained in:
Bnyro 2022-08-20 09:42:24 +02:00
parent 40fd1862c4
commit f5e83d7dd6
4 changed files with 38 additions and 9 deletions

View File

@ -55,3 +55,8 @@ const val PUSH_CHANNEL_ID = "notification_worker"
* Database
*/
const val DATABASE_NAME = "LibreTubeDatabase"
/**
* New Streams notifications
*/
const val NOTIFICATION_WORK_NAME = "NotificationService"

View File

@ -10,6 +10,7 @@ import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.NetworkType
import androidx.work.PeriodicWorkRequest
import androidx.work.WorkManager
import com.github.libretube.NOTIFICATION_WORK_NAME
import com.github.libretube.PUSH_CHANNEL_ID
import com.github.libretube.PUSH_NOTIFICATION_ID
import com.github.libretube.R
@ -23,6 +24,9 @@ import kotlinx.coroutines.runBlocking
import java.util.concurrent.TimeUnit
object NotificationHelper {
/**
* Enqueue the work manager task
*/
fun enqueueWork(
context: Context,
existingPeriodicWorkPolicy: ExistingPeriodicWorkPolicy
@ -39,8 +43,6 @@ object NotificationHelper {
"60"
).toLong()
val uniqueWorkName = "NotificationService"
// schedule the work manager request if logged in and notifications enabled
if (notificationsEnabled && PreferenceHelper.getToken() != "") {
// required network type for the work
@ -71,14 +73,14 @@ object NotificationHelper {
// enqueue the task
WorkManager.getInstance(context)
.enqueueUniquePeriodicWork(
uniqueWorkName,
NOTIFICATION_WORK_NAME,
existingPeriodicWorkPolicy,
notificationWorker
)
} else {
// cancel the work if notifications are disabled or the user is not logged in
WorkManager.getInstance(context)
.cancelUniqueWork(uniqueWorkName)
.cancelUniqueWork(NOTIFICATION_WORK_NAME)
}
}

View File

@ -8,8 +8,10 @@ import android.os.Environment
import androidx.core.app.ActivityCompat
object PermissionHelper {
/**
* request storage permissions if not granted yet
*/
fun requestReadWrite(activity: Activity): Boolean {
// request storage permissions if not granted yet
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (!Environment.isExternalStorageManager()) {
ActivityCompat.requestPermissions(

View File

@ -17,6 +17,9 @@ import com.google.android.material.color.DynamicColors
object ThemeHelper {
/**
* Set the theme, including accent color and night mode
*/
fun updateTheme(activity: AppCompatActivity) {
val themeMode = PreferenceHelper.getString(PreferenceKeys.THEME_MODE, "A")
val pureThemeEnabled = PreferenceHelper.getBoolean(PreferenceKeys.PURE_THEME, false)
@ -25,6 +28,9 @@ object ThemeHelper {
updateThemeMode(themeMode)
}
/**
* Update the accent color of the app
*/
private fun updateAccentColor(
activity: AppCompatActivity,
pureThemeEnabled: Boolean
@ -51,13 +57,16 @@ object ThemeHelper {
activity.setTheme(theme)
}
/**
* apply dynamic colors to the activity
*/
private fun applyDynamicColors(activity: AppCompatActivity) {
/**
* apply dynamic colors to the activity
*/
DynamicColors.applyToActivityIfAvailable(activity)
}
/**
* set the theme mode (light, dark, auto)
*/
private fun updateThemeMode(themeMode: String) {
val mode = when (themeMode) {
"A" -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
@ -68,6 +77,9 @@ object ThemeHelper {
AppCompatDelegate.setDefaultNightMode(mode)
}
/**
* change the app icon
*/
fun changeIcon(context: Context, newLogoActivityAlias: String) {
val activityAliases = context.resources.getStringArray(R.array.iconsValue)
// 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) {
// kill player notification
val nManager = context
@ -111,12 +125,18 @@ object ThemeHelper {
android.os.Process.killProcess(android.os.Process.myPid())
}
/**
* Get a color by a resource code
*/
fun getThemeColor(context: Context, colorCode: Int): Int {
val value = TypedValue()
context.theme.resolveAttribute(colorCode, value, true)
return value.data
}
/**
* Get the styled app name
*/
fun getStyledAppName(context: Context): Spanned {
val colorPrimary = getThemeColor(context, R.attr.colorPrimaryDark)
val hexColor = String.format("#%06X", (0xFFFFFF and colorPrimary))