mirror of
https://github.com/openlibrecommunity/olcng.git
synced 2026-07-03 14:05:17 +02:00
Fix Automatic update subscriptions
This commit is contained in:
@@ -94,7 +94,7 @@ object AppConfig {
|
||||
// subscription settings
|
||||
const val SUBSCRIPTION_AUTO_UPDATE = "pref_auto_update_subscription"
|
||||
const val SUBSCRIPTION_AUTO_UPDATE_INTERVAL = "pref_auto_update_interval"
|
||||
const val DEFAULT_UPDATE_INTERVAL = "1440" // 24 hours
|
||||
const val UPDATE_TASK_NAME = "subscription-updater"
|
||||
const val SUBSCRIPTION_DEFAULT_UPDATE_INTERVAL = "1440" // 24 hours
|
||||
const val SUBSCRIPTION_UPDATE_TASK_NAME = "subscription_updater"
|
||||
|
||||
}
|
||||
|
||||
@@ -14,13 +14,10 @@ import androidx.work.multiprocess.RemoteWorkManager
|
||||
import com.v2ray.ang.AngApplication
|
||||
import com.v2ray.ang.AppConfig
|
||||
import com.v2ray.ang.R
|
||||
import com.v2ray.ang.dto.AngConfig
|
||||
import com.v2ray.ang.service.SubscriptionUpdater
|
||||
import com.v2ray.ang.util.Utils
|
||||
import com.v2ray.ang.viewmodel.SettingsViewModel
|
||||
import java.sql.Time
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.time.toDuration
|
||||
|
||||
class SettingsActivity : BaseActivity() {
|
||||
private val settingsViewModel: SettingsViewModel by viewModels()
|
||||
@@ -81,7 +78,7 @@ class SettingsActivity : BaseActivity() {
|
||||
autoUpdateInterval?.setOnPreferenceChangeListener { _, any ->
|
||||
val nval = any as String
|
||||
autoUpdateInterval?.summary =
|
||||
if (TextUtils.isEmpty(nval) or (nval.toLong() < 15)) AppConfig.DEFAULT_UPDATE_INTERVAL else nval
|
||||
if (TextUtils.isEmpty(nval) or (nval.toLong() < 15)) AppConfig.SUBSCRIPTION_DEFAULT_UPDATE_INTERVAL else nval
|
||||
configureUpdateTask(nval.toLong())
|
||||
false
|
||||
}
|
||||
@@ -180,7 +177,7 @@ class SettingsActivity : BaseActivity() {
|
||||
httpPort?.summary = defaultSharedPreferences.getString(AppConfig.PREF_HTTP_PORT, AppConfig.PORT_HTTP)
|
||||
updateMux(defaultSharedPreferences.getBoolean(AppConfig.PREF_MUX_ENABLED, false))
|
||||
muxXudpConcurrency?.summary = defaultSharedPreferences.getString(AppConfig.PREF_MUX_XUDP_CONCURRENCY, "8")
|
||||
autoUpdateInterval?.summary = defaultSharedPreferences.getString(AppConfig.SUBSCRIPTION_AUTO_UPDATE_INTERVAL,AppConfig.DEFAULT_UPDATE_INTERVAL)
|
||||
autoUpdateInterval?.summary = defaultSharedPreferences.getString(AppConfig.SUBSCRIPTION_AUTO_UPDATE_INTERVAL,AppConfig.SUBSCRIPTION_DEFAULT_UPDATE_INTERVAL)
|
||||
|
||||
if (TextUtils.isEmpty(remoteDnsString)) {
|
||||
remoteDnsString = AppConfig.DNS_AGENT
|
||||
@@ -233,9 +230,9 @@ class SettingsActivity : BaseActivity() {
|
||||
|
||||
private fun configureUpdateTask(interval: Long) {
|
||||
val rw = RemoteWorkManager.getInstance(AngApplication.application)
|
||||
rw.cancelUniqueWork(AppConfig.UPDATE_TASK_NAME)
|
||||
rw.cancelUniqueWork(AppConfig.SUBSCRIPTION_UPDATE_TASK_NAME)
|
||||
rw.enqueueUniquePeriodicWork(
|
||||
AppConfig.UPDATE_TASK_NAME,
|
||||
AppConfig.SUBSCRIPTION_UPDATE_TASK_NAME,
|
||||
ExistingPeriodicWorkPolicy.UPDATE,
|
||||
PeriodicWorkRequest.Builder(
|
||||
SubscriptionUpdater.UpdateTask::class.java,
|
||||
@@ -255,7 +252,8 @@ class SettingsActivity : BaseActivity() {
|
||||
|
||||
private fun cancelUpdateTask() {
|
||||
val rw = RemoteWorkManager.getInstance(AngApplication.application)
|
||||
rw.cancelUniqueWork(AppConfig.UPDATE_TASK_NAME)
|
||||
rw.cancelUniqueWork(AppConfig.SUBSCRIPTION_UPDATE_TASK_NAME)
|
||||
}
|
||||
|
||||
private fun updateMux(enabled: Boolean) {
|
||||
val defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity())
|
||||
|
||||
@@ -40,6 +40,7 @@ class SettingsViewModel(application: Application) : AndroidViewModel(application
|
||||
AppConfig.PREF_V2RAY_ROUTING_AGENT,
|
||||
AppConfig.PREF_V2RAY_ROUTING_BLOCKED,
|
||||
AppConfig.PREF_V2RAY_ROUTING_DIRECT,
|
||||
AppConfig.SUBSCRIPTION_AUTO_UPDATE_INTERVAL,
|
||||
AppConfig.PREF_MUX_XUDP_QUIC, -> {
|
||||
settingsStorage?.encode(key, sharedPreferences.getString(key, ""))
|
||||
}
|
||||
@@ -53,6 +54,7 @@ class SettingsViewModel(application: Application) : AndroidViewModel(application
|
||||
AppConfig.PREF_BYPASS_APPS,
|
||||
AppConfig.PREF_CONFIRM_REMOVE,
|
||||
AppConfig.PREF_START_SCAN_IMMEDIATE,
|
||||
AppConfig.SUBSCRIPTION_AUTO_UPDATE,
|
||||
AppConfig.PREF_MUX_ENABLED, -> {
|
||||
settingsStorage?.encode(key, sharedPreferences.getBoolean(key, false))
|
||||
}
|
||||
|
||||
@@ -172,6 +172,10 @@
|
||||
<string name="title_pref_promotion">Promotion</string>
|
||||
<string name="summary_pref_promotion">Promotion,click for details(Donation can be removed)</string>
|
||||
|
||||
<string name="title_pref_auto_update_subscription">Automatic update subscriptions</string>
|
||||
<string name="summary_pref_auto_update_subscription">Update your subscriptions automatically with an interval in background</string>
|
||||
<string name="title_pref_auto_update_interval">Subscription Auto Update Interval (Minutes)</string>
|
||||
|
||||
<string name="title_core_loglevel">Log Level</string>
|
||||
<string name="title_mode">Mode</string>
|
||||
<string name="title_mode_help">Click me for more help</string>
|
||||
@@ -190,7 +194,7 @@
|
||||
<string name="sub_setting_remarks">remarks</string>
|
||||
<string name="sub_setting_url">Optional URL</string>
|
||||
<string name="sub_setting_enable">enable update</string>
|
||||
<string name="sub_auto_update">Auto update</string>
|
||||
<string name="sub_auto_update">Automatic update</string>
|
||||
<string name="title_sub_update">Update subscription</string>
|
||||
<string name="title_ping_all_server">Tcping all configuration</string>
|
||||
<string name="title_real_ping_all_server">Real delay all configuration</string>
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="pref_sniffing_enabled"
|
||||
android:summary="@string/summary_pref_sniffing_enabled"
|
||||
android:title="@string/title_pref_sniffing_enabled" />
|
||||
android:defaultValue="true"
|
||||
android:key="pref_sniffing_enabled"
|
||||
android:summary="@string/summary_pref_sniffing_enabled"
|
||||
android:title="@string/title_pref_sniffing_enabled" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="pref_mux_enabled"
|
||||
@@ -33,25 +33,25 @@
|
||||
android:title="@string/title_pref_per_app_proxy" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="pref_local_dns_enabled"
|
||||
android:summary="@string/summary_pref_local_dns_enabled"
|
||||
android:title="@string/title_pref_local_dns_enabled" />
|
||||
android:key="pref_local_dns_enabled"
|
||||
android:summary="@string/summary_pref_local_dns_enabled"
|
||||
android:title="@string/title_pref_local_dns_enabled" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="pref_fake_dns_enabled"
|
||||
android:summary="@string/summary_pref_fake_dns_enabled"
|
||||
android:title="@string/title_pref_fake_dns_enabled" />
|
||||
android:key="pref_fake_dns_enabled"
|
||||
android:summary="@string/summary_pref_fake_dns_enabled"
|
||||
android:title="@string/title_pref_fake_dns_enabled" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="pref_local_dns_port"
|
||||
android:summary="10853"
|
||||
android:inputType="number"
|
||||
android:title="@string/title_pref_local_dns_port" />
|
||||
android:key="pref_local_dns_port"
|
||||
android:summary="10853"
|
||||
android:inputType="number"
|
||||
android:title="@string/title_pref_local_dns_port" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="pref_vpn_dns"
|
||||
android:summary="@string/summary_pref_remote_dns"
|
||||
android:title="@string/title_pref_vpn_dns" />
|
||||
android:key="pref_vpn_dns"
|
||||
android:summary="@string/summary_pref_remote_dns"
|
||||
android:title="@string/title_pref_vpn_dns" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/title_pref_routing">
|
||||
@@ -78,6 +78,18 @@
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/title_sub_setting">
|
||||
<CheckBoxPreference
|
||||
android:key="pref_auto_update_subscription"
|
||||
android:summary="@string/summary_pref_auto_update_subscription"
|
||||
android:title="@string/title_pref_auto_update_subscription" />
|
||||
<EditTextPreference
|
||||
android:key="pref_auto_update_interval"
|
||||
android:summary="1440"
|
||||
android:inputType="number"
|
||||
android:title="@string/title_pref_auto_update_interval" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/title_ui_settings">
|
||||
<CheckBoxPreference
|
||||
android:key="pref_speed_enabled"
|
||||
@@ -141,9 +153,9 @@
|
||||
android:title="@string/title_pref_remote_dns" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="pref_domestic_dns"
|
||||
android:summary="@string/summary_pref_domestic_dns"
|
||||
android:title="@string/title_pref_domestic_dns" />
|
||||
android:key="pref_domestic_dns"
|
||||
android:summary="@string/summary_pref_domestic_dns"
|
||||
android:title="@string/title_pref_domestic_dns" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="warning"
|
||||
@@ -154,50 +166,12 @@
|
||||
android:title="@string/title_core_loglevel" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="VPN"
|
||||
android:entries="@array/mode_entries"
|
||||
android:entryValues="@array/mode_value"
|
||||
android:key="pref_mode"
|
||||
android:summary="%s"
|
||||
android:title="@string/title_mode" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="Subscription">
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="pref_auto_update_subscription"
|
||||
android:summary="Update your subscriptions automatically with an interval in background"
|
||||
android:title="Automatic update subscriptions" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="pref_auto_update_interval"
|
||||
android:summary="1440 min"
|
||||
android:inputType="number"
|
||||
android:title="Subscription Update Interval (Minutes)" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/title_ui_settings">
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="pref_confirm_remove"
|
||||
android:summary="@string/summary_pref_confirm_remove"
|
||||
android:title="@string/title_pref_confirm_remove" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="pref_start_scan_immediate"
|
||||
android:summary="@string/summary_pref_start_scan_immediate"
|
||||
android:title="@string/title_pref_start_scan_immediate" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="auto"
|
||||
android:entries="@array/language_select"
|
||||
android:entryValues="@array/language_select_value"
|
||||
android:key="pref_language"
|
||||
android:defaultValue="VPN"
|
||||
android:entries="@array/mode_entries"
|
||||
android:entryValues="@array/mode_value"
|
||||
android:key="pref_mode"
|
||||
android:summary="%s"
|
||||
android:title="@string/title_language" />
|
||||
android:title="@string/title_mode" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
</PreferenceScreen>
|
||||
Reference in New Issue
Block a user