Commit 3015ac1b authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Added configuring a time unit for automatic updating

parent 6ce8edd6
......@@ -37,9 +37,13 @@ class HostSourceRefreshDialog(context:Context,
}
view.automaticRefresh.setOnCheckedChangeListener { _, isChecked ->
view.refreshWifiOnly.isEnabled = isChecked
view.timeAmountTil.isEnabled = isChecked
view.timeUnit.isEnabled = isChecked
}
view.automaticRefresh.isChecked = context.getPreferences().automaticHostRefresh
view.refreshWifiOnly.isChecked = context.getPreferences().automaticHostRefreshWifiOnly
view.timeAmount.setText(context.getPreferences().automaticHostRefreshTimeAmount.toString())
view.timeUnit.setSelection(context.getPreferences().automaticHostRefreshTimeUnit.ordinal)
setButton(DialogInterface.BUTTON_NEUTRAL, context.getString(R.string.all_close)) { dialog, _ ->
dialog.dismiss()
}
......@@ -47,7 +51,13 @@ class HostSourceRefreshDialog(context:Context,
dialog.dismiss()
context.getPreferences().automaticHostRefresh = view.automaticRefresh.isChecked
context.getPreferences().automaticHostRefreshWifiOnly = view.refreshWifiOnly.isChecked
context.getPreferences().automaticHostRefreshTimeAmount = view.timeAmount.text.toString().toInt()
context.getPreferences().automaticHostRefreshTimeUnit = TimeUnit.values().find { it.ordinal == view.timeUnit.selectedItemPosition }!!
}
}
enum class TimeUnit {
HOURS, DAYS, WEEKS
}
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ import com.frostnerd.preferenceskt.typedpreferences.cache.ExpirationCacheControl
import com.frostnerd.preferenceskt.typedpreferences.cache.buildCacheStrategy
import com.frostnerd.preferenceskt.typedpreferences.types.*
import com.frostnerd.smokescreen.BuildConfig
import com.frostnerd.smokescreen.dialog.HostSourceRefreshDialog
import java.util.*
/*
......@@ -246,6 +247,8 @@ class AppSettingsSharedPreferences(context: Context) : AppSettings, SimpleTypedP
var automaticHostRefresh:Boolean by booleanPref("automatic_host_refresh", false)
var automaticHostRefreshWifiOnly:Boolean by booleanPref("automatic_host_refresh_wifi_only", true)
var automaticHostRefreshTimeUnit:HostSourceRefreshDialog.TimeUnit by enumPref("automatic_host_refresh_timeunit", HostSourceRefreshDialog.TimeUnit.HOURS)
var automaticHostRefreshTimeAmount:Int by intPref("automatic_host_refresh_timeamount", 12)
}
fun AppSettings.Companion.fromSharedPreferences(context: Context): AppSettingsSharedPreferences {
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:paddingLeft="@dimen/dialog_horizontal_margin"
......@@ -22,12 +24,48 @@
android:id="@+id/refreshWifiOnly"
android:layout_height="wrap_content"/>
<Button
android:layout_width="match_parent"
android:background="@drawable/main_roundbuttons"
android:id="@+id/refreshNow"
android:text="@string/dialog_hostsourcerefresh_refresh_now"
style="@style/Base.Widget.AppCompat.Button.Borderless.Colored"
<TextView
android:layout_width="wrap_content"
android:text="@string/dialog_hostsourcerefresh_refresh_every"
android:layout_height="wrap_content"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="wrap_content"
android:id="@+id/timeAmountTil"
android:layout_above="@id/refreshNow"
android:layout_alignParentTop="true"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:id="@+id/timeAmount"
android:inputType="numberSigned"
android:imeOptions="actionNext"
android:text="12"
android:maxLines="1"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<Spinner
android:layout_width="wrap_content"
android:layout_alignParentEnd="true"
android:layout_toEndOf="@id/timeAmountTil"
android:id="@+id/timeUnit"
android:layout_alignBaseline="@id/timeAmountTil"
android:entries="@array/dialog_hostsourcerefresh_timeunits"
android:layout_height="wrap_content"/>
<Button
android:layout_width="match_parent"
android:background="@drawable/main_roundbuttons"
android:id="@+id/refreshNow"
android:layout_alignParentBottom="true"
android:text="@string/dialog_hostsourcerefresh_refresh_now"
style="@style/Base.Widget.AppCompat.Button.Borderless.Colored"
android:layout_height="wrap_content"/>
</RelativeLayout>
</LinearLayout>
\ No newline at end of file
......@@ -161,6 +161,15 @@
<string name="dialog_hostsourcerefresh_title">Refresh host sources</string>
<string name="dialog_hostsourcerefresh_automatic_refresh">Refresh host sources</string>
<string name="dialog_hostsourcerefresh_wifi_only">Refresh on WIFI only</string>
<string name="dialog_hostsourcerefresh_refresh_every">Refresh every</string>
<string name="dialog_hostsourcerefresh_refresh_now">Refresh now</string>
<string name="dialog_hostsourcerefresh_timeunit_hours">Hours</string>
<string name="dialog_hostsourcerefresh_timeunit_days">Days</string>
<string name="dialog_hostsourcerefresh_timeunit_weeks">Weeks</string>
<string-array name="dialog_hostsourcerefresh_timeunits">
<item>@string/dialog_hostsourcerefresh_timeunit_hours</item>
<item>@string/dialog_hostsourcerefresh_timeunit_days</item>
<item>@string/dialog_hostsourcerefresh_timeunit_weeks</item>
</string-array>
</resources>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment