mirror of
https://github.com/SagerNet/sing-box-for-android.git
synced 2025-04-03 20:07:38 +03:00
Add auto update option in create profile page
This commit is contained in:
parent
1f1788ea56
commit
b55145563f
2 changed files with 71 additions and 8 deletions
|
@ -8,6 +8,7 @@ import androidx.core.view.isVisible
|
|||
import androidx.lifecycle.lifecycleScope
|
||||
import io.nekohasekai.libbox.Libbox
|
||||
import io.nekohasekai.sfa.R
|
||||
import io.nekohasekai.sfa.constant.EnabledType
|
||||
import io.nekohasekai.sfa.database.Profile
|
||||
import io.nekohasekai.sfa.database.ProfileManager
|
||||
import io.nekohasekai.sfa.database.TypedProfile
|
||||
|
@ -51,6 +52,14 @@ class NewProfileActivity : AbstractActivity() {
|
|||
setContentView(binding.root)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
|
||||
intent.getStringExtra("importName")?.also { importName ->
|
||||
intent.getStringExtra("importURL")?.also { importURL ->
|
||||
binding.name.editText?.setText(importName)
|
||||
binding.type.text = TypedProfile.Type.Remote.name
|
||||
binding.remoteURL.editText?.setText(importURL)
|
||||
}
|
||||
}
|
||||
|
||||
binding.name.removeErrorIfNotEmpty()
|
||||
binding.type.addTextChangedListener {
|
||||
when (it) {
|
||||
|
@ -62,6 +71,9 @@ class NewProfileActivity : AbstractActivity() {
|
|||
TypedProfile.Type.Remote.name -> {
|
||||
binding.localFields.isVisible = false
|
||||
binding.remoteFields.isVisible = true
|
||||
if (binding.autoUpdateInterval.text.toIntOrNull() == null) {
|
||||
binding.autoUpdateInterval.text = "60"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,13 +94,7 @@ class NewProfileActivity : AbstractActivity() {
|
|||
startFilesForResult(importFile, "application/json")
|
||||
}
|
||||
binding.createProfile.setOnClickListener(this::createProfile)
|
||||
intent.getStringExtra("importName")?.also { importName ->
|
||||
intent.getStringExtra("importURL")?.also { importURL ->
|
||||
binding.name.editText?.setText(importName)
|
||||
binding.type.text = TypedProfile.Type.Remote.name
|
||||
binding.remoteURL.editText?.setText(importURL)
|
||||
}
|
||||
}
|
||||
binding.autoUpdateInterval.addTextChangedListener(this::updateAutoUpdateInterval)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
@ -179,6 +185,10 @@ class NewProfileActivity : AbstractActivity() {
|
|||
typedProfile.path = configFile.path
|
||||
typedProfile.remoteURL = remoteURL
|
||||
typedProfile.lastUpdated = Date()
|
||||
typedProfile.autoUpdate = EnabledType.valueOf(binding.autoUpdate.text).boolValue
|
||||
binding.autoUpdateInterval.text.toIntOrNull()?.also {
|
||||
typedProfile.autoUpdateInterval = it
|
||||
}
|
||||
}
|
||||
}
|
||||
ProfileManager.create(profile)
|
||||
|
@ -188,4 +198,25 @@ class NewProfileActivity : AbstractActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun updateAutoUpdateInterval(newValue: String) {
|
||||
val binding = binding ?: return
|
||||
if (newValue.isBlank()) {
|
||||
binding.autoUpdateInterval.error = getString(R.string.profile_input_required)
|
||||
return
|
||||
}
|
||||
val intValue = try {
|
||||
newValue.toInt()
|
||||
} catch (e: Exception) {
|
||||
binding.autoUpdateInterval.error = e.localizedMessage
|
||||
return
|
||||
}
|
||||
if (intValue < 15) {
|
||||
binding.autoUpdateInterval.error =
|
||||
getString(R.string.profile_auto_update_interval_minimum_hint)
|
||||
return
|
||||
}
|
||||
binding.autoUpdateInterval.error = null
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
|
@ -82,6 +83,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
tools:visibility="visible"
|
||||
android:text="@string/profile_import_file"
|
||||
android:visibility="gone">
|
||||
|
||||
|
@ -101,7 +103,6 @@
|
|||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
@ -124,6 +125,37 @@
|
|||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/autoUpdate"
|
||||
style="@style/Widget.Material3.TextInputLayout.FilledBox.ExposedDropdownMenu"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:hint="@string/profile_auto_update">
|
||||
|
||||
<AutoCompleteTextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="none"
|
||||
android:text="@string/enabled"
|
||||
app:simpleItems="@array/enabled" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/autoUpdateInterval"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:hint="@string/profile_auto_update_interval">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue