Add auto update option in create profile page
This commit is contained in:
@@ -8,6 +8,7 @@ import androidx.core.view.isVisible
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import io.nekohasekai.libbox.Libbox
|
import io.nekohasekai.libbox.Libbox
|
||||||
import io.nekohasekai.sfa.R
|
import io.nekohasekai.sfa.R
|
||||||
|
import io.nekohasekai.sfa.constant.EnabledType
|
||||||
import io.nekohasekai.sfa.database.Profile
|
import io.nekohasekai.sfa.database.Profile
|
||||||
import io.nekohasekai.sfa.database.ProfileManager
|
import io.nekohasekai.sfa.database.ProfileManager
|
||||||
import io.nekohasekai.sfa.database.TypedProfile
|
import io.nekohasekai.sfa.database.TypedProfile
|
||||||
@@ -51,6 +52,14 @@ class NewProfileActivity : AbstractActivity() {
|
|||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
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.name.removeErrorIfNotEmpty()
|
||||||
binding.type.addTextChangedListener {
|
binding.type.addTextChangedListener {
|
||||||
when (it) {
|
when (it) {
|
||||||
@@ -62,6 +71,9 @@ class NewProfileActivity : AbstractActivity() {
|
|||||||
TypedProfile.Type.Remote.name -> {
|
TypedProfile.Type.Remote.name -> {
|
||||||
binding.localFields.isVisible = false
|
binding.localFields.isVisible = false
|
||||||
binding.remoteFields.isVisible = true
|
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")
|
startFilesForResult(importFile, "application/json")
|
||||||
}
|
}
|
||||||
binding.createProfile.setOnClickListener(this::createProfile)
|
binding.createProfile.setOnClickListener(this::createProfile)
|
||||||
intent.getStringExtra("importName")?.also { importName ->
|
binding.autoUpdateInterval.addTextChangedListener(this::updateAutoUpdateInterval)
|
||||||
intent.getStringExtra("importURL")?.also { importURL ->
|
|
||||||
binding.name.editText?.setText(importName)
|
|
||||||
binding.type.text = TypedProfile.Type.Remote.name
|
|
||||||
binding.remoteURL.editText?.setText(importURL)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
@@ -179,6 +185,10 @@ class NewProfileActivity : AbstractActivity() {
|
|||||||
typedProfile.path = configFile.path
|
typedProfile.path = configFile.path
|
||||||
typedProfile.remoteURL = remoteURL
|
typedProfile.remoteURL = remoteURL
|
||||||
typedProfile.lastUpdated = Date()
|
typedProfile.lastUpdated = Date()
|
||||||
|
typedProfile.autoUpdate = EnabledType.valueOf(binding.autoUpdate.text).boolValue
|
||||||
|
binding.autoUpdateInterval.text.toIntOrNull()?.also {
|
||||||
|
typedProfile.autoUpdateInterval = it
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ProfileManager.create(profile)
|
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"
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
@@ -82,6 +83,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
|
tools:visibility="visible"
|
||||||
android:text="@string/profile_import_file"
|
android:text="@string/profile_import_file"
|
||||||
android:visibility="gone">
|
android:visibility="gone">
|
||||||
|
|
||||||
@@ -101,7 +103,6 @@
|
|||||||
|
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
@@ -124,6 +125,37 @@
|
|||||||
|
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</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>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user