mirror of https://github.com/deniscerri/ytdlnis
new update notification cards in home screen and notifications background job checking app update and package update
parent
b5cf907dc6
commit
37df34ebc5
@ -1,20 +0,0 @@
|
||||
package com.deniscerri.ytdl.work
|
||||
|
||||
import android.content.Context
|
||||
import androidx.work.Worker
|
||||
import androidx.work.WorkerParameters
|
||||
|
||||
|
||||
class AutoGenerateWebPoTokenWorker(
|
||||
private val context: Context,
|
||||
workerParams: WorkerParameters
|
||||
) : Worker(context, workerParams) {
|
||||
override fun doWork(): Result {
|
||||
return Result.success()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "AutoGenerateWebPoTokenWorker"
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
package com.deniscerri.ytdl.work
|
||||
|
||||
import android.content.Context
|
||||
import androidx.work.CoroutineWorker
|
||||
import androidx.work.WorkerParameters
|
||||
import com.deniscerri.ytdl.util.UpdateUtil
|
||||
|
||||
|
||||
class UpdateYTDLWorker(
|
||||
private val context: Context,
|
||||
workerParams: WorkerParameters
|
||||
) : CoroutineWorker(context, workerParams) {
|
||||
override suspend fun doWork(): Result {
|
||||
UpdateUtil(context).updateYTDL()
|
||||
return Result.success()
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,79 @@
|
||||
package com.deniscerri.ytdl.work.background
|
||||
|
||||
import android.content.Context
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.work.Constraints
|
||||
import androidx.work.CoroutineWorker
|
||||
import androidx.work.ExistingPeriodicWorkPolicy
|
||||
import androidx.work.NetworkType
|
||||
import androidx.work.PeriodicWorkRequestBuilder
|
||||
import androidx.work.WorkManager
|
||||
import androidx.work.WorkerParameters
|
||||
import com.deniscerri.ytdl.App
|
||||
import com.deniscerri.ytdl.BuildConfig
|
||||
import com.deniscerri.ytdl.core.RuntimeManager
|
||||
import com.deniscerri.ytdl.util.NotificationUtil
|
||||
import com.deniscerri.ytdl.util.UpdateUtil
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class UpdateCheckWorker(
|
||||
private val context: Context,
|
||||
workerParams: WorkerParameters
|
||||
) : CoroutineWorker(context, workerParams) {
|
||||
override suspend fun doWork(): Result {
|
||||
val updateUtil = UpdateUtil(App.instance)
|
||||
val notificationUtil = NotificationUtil(App.instance)
|
||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
|
||||
val newRelease = updateUtil.tryGetNewVersion()
|
||||
if (newRelease.isSuccess && BuildConfig.FLAVOR == "github") {
|
||||
notificationUtil.showNewAppUpdate(newRelease.getOrNull()!!.tag_name)
|
||||
}
|
||||
|
||||
val skipRemindingPackageUpdate = sharedPreferences.getStringSet("skip_reminding_package_update", setOf())!!.toMutableSet()
|
||||
RuntimeManager.packages.forEach { pkg ->
|
||||
val instance = pkg.plugin.getInstance()
|
||||
if (instance.bundledVersion.isNullOrBlank() && instance.downloadedVersion.isNullOrBlank()) return@forEach
|
||||
instance.getReleases().apply {
|
||||
val releases = this.getOrElse { listOf() }
|
||||
if (releases.isEmpty()) return@apply
|
||||
|
||||
val latestRelease = releases.first()
|
||||
if (latestRelease.isBundled || latestRelease.isInstalled) return@apply
|
||||
if (skipRemindingPackageUpdate.contains(latestRelease.tag_name)) return@apply
|
||||
|
||||
notificationUtil.showNewPackageUpdate(pkg.title, latestRelease.tag_name)
|
||||
|
||||
skipRemindingPackageUpdate.add(latestRelease.tag_name)
|
||||
sharedPreferences.edit().putStringSet("skip_reminding_package_update", skipRemindingPackageUpdate).apply()
|
||||
}
|
||||
}
|
||||
|
||||
return Result.success()
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
const val WORK_NAME = "ytdlnis_update_check"
|
||||
|
||||
fun schedule(context: Context, intervalMinutes: Long = 24 * 60L) {
|
||||
val constraints = Constraints.Builder()
|
||||
.setRequiredNetworkType(NetworkType.CONNECTED)
|
||||
.build()
|
||||
|
||||
val request = PeriodicWorkRequestBuilder<UpdateCheckWorker>(
|
||||
intervalMinutes, TimeUnit.MINUTES
|
||||
)
|
||||
.setConstraints(constraints)
|
||||
.setInitialDelay(intervalMinutes, TimeUnit.MINUTES)
|
||||
.build()
|
||||
|
||||
WorkManager.getInstance(context).enqueueUniquePeriodicWork(
|
||||
WORK_NAME,
|
||||
ExistingPeriodicWorkPolicy.UPDATE,
|
||||
request
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,82 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="12dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
app:cardCornerRadius="20dp"
|
||||
app:cardElevation="0dp"
|
||||
app:strokeWidth="1dp"
|
||||
app:strokeColor="?attr/colorTertiaryContainer"
|
||||
app:cardBackgroundColor="?attr/colorTertiaryContainer">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingVertical="12dp"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<!-- Circular Indicator Container matching App Palette -->
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
app:cardCornerRadius="18dp"
|
||||
app:cardElevation="0dp"
|
||||
app:strokeWidth="0dp"
|
||||
app:cardBackgroundColor="?attr/colorTertiary"
|
||||
android:layout_marginEnd="14dp">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="18dp"
|
||||
android:layout_height="18dp"
|
||||
android:layout_gravity="center"
|
||||
android:src="@android:drawable/stat_sys_download_done"
|
||||
app:tint="?attr/colorPrimaryContainer" />
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/newVersionTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/package_version_ready_to_download"
|
||||
android:textStyle="bold"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:textColor="?attr/colorOnSurface"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_update_details"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/tap_to_see_changes_and_install"
|
||||
android:textColor="?attr/colorOnSurfaceVariant"
|
||||
android:textSize="12sp"
|
||||
android:layout_marginTop="1dp" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btn_close_update"
|
||||
style="@style/Widget.Material3.Button.IconButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="13sp"
|
||||
app:icon="@drawable/baseline_close_24"
|
||||
app:iconTint="?attr/colorTertiary"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:paddingHorizontal="12dp"
|
||||
app:rippleColor="?attr/colorTertiaryContainer" />
|
||||
|
||||
</LinearLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
@ -0,0 +1,88 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="12dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
app:cardCornerRadius="20dp"
|
||||
app:cardElevation="0dp"
|
||||
app:strokeWidth="1dp"
|
||||
app:strokeColor="?attr/colorPrimaryContainer"
|
||||
app:cardBackgroundColor="?attr/colorPrimaryContainer">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingVertical="12dp"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<!-- Circular Indicator Container matching App Palette -->
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
app:cardCornerRadius="18dp"
|
||||
app:cardElevation="0dp"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
app:strokeWidth="0dp"
|
||||
app:cardBackgroundColor="?attr/colorSecondary"
|
||||
android:layout_marginEnd="14dp">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="18dp"
|
||||
android:layout_height="18dp"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:layout_gravity="center"
|
||||
android:src="@android:drawable/stat_sys_download_done"
|
||||
app:tint="?attr/colorPrimaryContainer" />
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/newVersionTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/version_ready_to_download"
|
||||
android:textStyle="bold"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:textColor="?attr/colorOnSurface"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_update_details"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:text="@string/tap_to_see_changes_and_install"
|
||||
android:textColor="?attr/colorOnSurfaceVariant"
|
||||
android:textSize="12sp"
|
||||
android:layout_marginTop="1dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btn_close_update"
|
||||
style="@style/Widget.Material3.Button.IconButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="13sp"
|
||||
app:icon="@drawable/baseline_close_24"
|
||||
app:iconTint="?attr/colorTertiary"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:paddingHorizontal="12dp"
|
||||
app:rippleColor="?attr/colorTertiaryContainer" />
|
||||
|
||||
</LinearLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
Loading…
Reference in New Issue