Commit 6ce8edd6 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Added a dialog for refreshing sources and configuring whether they should auto-refresh

parent 6a472bfa
package com.frostnerd.smokescreen.dialog
import android.content.Context
import android.content.DialogInterface
import androidx.appcompat.app.AlertDialog
import com.frostnerd.smokescreen.R
import com.frostnerd.smokescreen.getPreferences
import kotlinx.android.synthetic.main.dialog_host_source_refresh.view.*
/*
* Copyright (C) 2019 Daniel Wolf (Ch4t4r)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* You can contact the developer at daniel.wolf@frostnerd.com.
*/
class HostSourceRefreshDialog(context:Context,
runRefresh:() -> Unit):AlertDialog(context, context.getPreferences().theme.dialogStyle) {
init {
setTitle(R.string.dialog_hostsourcerefresh_title)
val view = layoutInflater.inflate(R.layout.dialog_host_source_refresh, null, false)
setView(view)
view.refreshNow.setOnClickListener {
runRefresh()
}
view.automaticRefresh.setOnCheckedChangeListener { _, isChecked ->
view.refreshWifiOnly.isEnabled = isChecked
}
view.automaticRefresh.isChecked = context.getPreferences().automaticHostRefresh
view.refreshWifiOnly.isChecked = context.getPreferences().automaticHostRefreshWifiOnly
setButton(DialogInterface.BUTTON_NEUTRAL, context.getString(R.string.all_close)) { dialog, _ ->
dialog.dismiss()
}
setButton(DialogInterface.BUTTON_POSITIVE, context.getString(android.R.string.ok)) { dialog, _ ->
dialog.dismiss()
context.getPreferences().automaticHostRefresh = view.automaticRefresh.isChecked
context.getPreferences().automaticHostRefreshWifiOnly = view.refreshWifiOnly.isChecked
}
}
}
\ No newline at end of file
......@@ -243,6 +243,9 @@ class AppSettingsSharedPreferences(context: Context) : AppSettings, SimpleTypedP
var vpnServiceState:VpnServiceState by enumPref("vpn_service_state", VpnServiceState.STOPPED)
var ignoreServiceKilled:Boolean by booleanPref("ignore_service_killed", false)
var automaticHostRefresh:Boolean by booleanPref("automatic_host_refresh", false)
var automaticHostRefreshWifiOnly:Boolean by booleanPref("automatic_host_refresh_wifi_only", true)
}
fun AppSettings.Companion.fromSharedPreferences(context: Context): AppSettingsSharedPreferences {
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:paddingLeft="@dimen/dialog_horizontal_margin"
android:paddingRight="@dimen/dialog_horizontal_margin"
android:paddingTop="@dimen/dialog_vertical_margin"
android:paddingBottom="@dimen/dialog_vertical_margin"
android:layout_height="match_parent">
<CheckBox
android:layout_width="wrap_content"
android:text="@string/dialog_hostsourcerefresh_automatic_refresh"
android:textColor="?android:attr/textColor"
android:id="@+id/automaticRefresh"
android:layout_height="wrap_content"/>
<CheckBox
android:layout_width="wrap_content"
android:text="@string/dialog_hostsourcerefresh_wifi_only"
android:textColor="?android:attr/textColor"
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"
android:layout_height="wrap_content"/>
</LinearLayout>
\ No newline at end of file
......@@ -157,4 +157,10 @@
<string name="dialog_overlaydetected_title">System-wide overlay detected</string>
<string name="dialog_overlaydetected_message">There seems to be a system-wide overlay (e.g. a chat bubble, color- or nightfilter) active. Most device don\'t allow you to enable a VPN in this case.\n\nIf you can\'t click OK in the next dialog please disable the overlay.</string>
<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_now">Refresh now</string>
</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