From f25c0cc8902874b76c710de9340708550955b0ff Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Wed, 15 Nov 2023 15:27:53 +0800 Subject: [PATCH] Fix Automatic update subscriptions --- .../v2ray/ang/service/SubscriptionUpdater.kt | 26 +++++------ .../com/v2ray/ang/ui/SettingsActivity.kt | 6 +-- .../src/main/res/layout/activity_sub_edit.xml | 43 ++++++++++--------- .../src/main/res/values-zh-rCN/strings.xml | 4 +- .../src/main/res/values-zh-rTW/strings.xml | 4 +- V2rayNG/app/src/main/res/values/strings.xml | 6 +-- 6 files changed, 40 insertions(+), 49 deletions(-) diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/SubscriptionUpdater.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/SubscriptionUpdater.kt index 4eeaaa7e..acbe0040 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/SubscriptionUpdater.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/SubscriptionUpdater.kt @@ -1,29 +1,24 @@ package com.v2ray.ang.service -import android.Manifest import android.annotation.SuppressLint import android.app.NotificationChannel import android.app.NotificationManager import android.content.Context -import android.content.pm.PackageManager import android.os.Build import android.util.Log -import androidx.core.app.ActivityCompat import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import androidx.work.CoroutineWorker import androidx.work.WorkerParameters import com.v2ray.ang.AppConfig import com.v2ray.ang.R -import com.v2ray.ang.extension.toast import com.v2ray.ang.util.AngConfigManager import com.v2ray.ang.util.MmkvManager import com.v2ray.ang.util.Utils -import kotlinx.coroutines.delay object SubscriptionUpdater { - const val notificationChannel = "update-subscription-channel" + const val notificationChannel = "subscription_update_channel" class UpdateTask(context: Context, params: WorkerParameters) : CoroutineWorker(context, params) { @@ -31,23 +26,20 @@ object SubscriptionUpdater { private val notificationManager = NotificationManagerCompat.from(applicationContext) private val notification = NotificationCompat.Builder(applicationContext, notificationChannel) - .setWhen(0) .setTicker("Update") - .setContentTitle("Subscription Update") + .setContentTitle(context.getString(R.string.title_pref_auto_update_subscription)) .setSmallIcon(R.drawable.ic_stat_name) .setCategory(NotificationCompat.CATEGORY_SERVICE) - .setPriority(NotificationCompat.PRIORITY_MIN) + .setPriority(NotificationCompat.PRIORITY_DEFAULT) @SuppressLint("MissingPermission") override suspend fun doWork(): Result { - Log.d(AppConfig.ANG_PACKAGE, "start updating subscriptions") - + Log.d(AppConfig.ANG_PACKAGE, "subscription automatic update starting") val subs = MmkvManager.decodeSubscriptions().filter { it.second.autoUpdate } for (i in subs) { - val subscription = i.second if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { @@ -61,7 +53,10 @@ object SubscriptionUpdater { notificationManager.createNotificationChannel(channel) } notificationManager.notify(3, notification.build()) - Log.d(AppConfig.ANG_PACKAGE, "update: ${subscription.remarks} subscription") + Log.d( + AppConfig.ANG_PACKAGE, + "subscription automatic update: ---${subscription.remarks}" + ) val configs = Utils.getUrlContentWithCustomUserAgent(subscription.url) importBatchConfig(configs, i.first) notification.setContentText("Updating ${subscription.remarks}") @@ -72,10 +67,9 @@ object SubscriptionUpdater { } fun importBatchConfig(server: String?, subid: String = "") { + val append = subid.isEmpty() - val append = subid.isNullOrEmpty() - - var count = AngConfigManager.importBatchConfig(server, subid, append) + val count = AngConfigManager.importBatchConfig(server, subid, append) if (count <= 0) { AngConfigManager.importBatchConfig(Utils.decode(server!!), subid, append) } diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/SettingsActivity.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/SettingsActivity.kt index 452f0983..c93fae00 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/SettingsActivity.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/SettingsActivity.kt @@ -243,11 +243,7 @@ class SettingsActivity : BaseActivity() { .apply { setInitialDelay(interval, TimeUnit.MINUTES) } - .setConstraints( - Constraints( - NetworkType.CONNECTED, - ) - ).build() + .build() ) } diff --git a/V2rayNG/app/src/main/res/layout/activity_sub_edit.xml b/V2rayNG/app/src/main/res/layout/activity_sub_edit.xml index d61169cf..1bf37ac7 100644 --- a/V2rayNG/app/src/main/res/layout/activity_sub_edit.xml +++ b/V2rayNG/app/src/main/res/layout/activity_sub_edit.xml @@ -69,6 +69,28 @@ + + + + + + + + + - - - - - - - - diff --git a/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml b/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml index 4ceb4ad0..b07c2c55 100644 --- a/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml +++ b/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml @@ -165,7 +165,7 @@ 一些推广,点击查看详情(捐赠可去除) 自动更新订阅 - 在后台按一定时间间隔自动更新您的订阅 + 在后台按一定时间间隔自动更新您的订阅。受设备影响,此功能不一定总是有效 订阅自动更新间隔(分钟) 日志级别 @@ -186,7 +186,7 @@ 备注 可选地址(url) 启用更新 - 自动更新 + 启用自动更新 更新订阅 测试全部配置Tcping 测试全部配置真连接 diff --git a/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml b/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml index c1050ae8..2fbd228a 100644 --- a/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml +++ b/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml @@ -165,7 +165,7 @@ 一些推廣,輕觸以檢視 (捐贈可去除) 自動更新訂閱 - 在後台以一定時間間隔自動更新您的訂閱 + 在後台以一定時間間隔自動更新您的訂閱。受設備影響,此功能不一定總是有效 訂閱自動更新間隔(分鐘) 記錄層級 @@ -186,7 +186,7 @@ 備註 Optional URL 啟用更新 - 自動更新 + 啟用自動更新 更新訂閱 偵測所有組態 Tcping 偵測所有組態真延遲 diff --git a/V2rayNG/app/src/main/res/values/strings.xml b/V2rayNG/app/src/main/res/values/strings.xml index 4e792fd1..a27d1398 100644 --- a/V2rayNG/app/src/main/res/values/strings.xml +++ b/V2rayNG/app/src/main/res/values/strings.xml @@ -173,7 +173,7 @@ Promotion,click for details(Donation can be removed) Automatic update subscriptions - Update your subscriptions automatically with an interval in background + Update your subscriptions automatically with an interval in background. Depending on the device, this feature may not always work Subscription Auto Update Interval (Minutes) Log Level @@ -193,8 +193,8 @@ Subscription group setting remarks Optional URL - enable update - Automatic update + Enable update + Enable automatic update Update subscription Tcping all configuration Real delay all configuration