mirror of
https://github.com/M66B/NetGuard.git
synced 2025-01-01 12:54:07 +00:00
parent
06f3ea9a79
commit
55de37cb5c
4 changed files with 25 additions and 20 deletions
|
@ -217,29 +217,34 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
|
|||
});
|
||||
|
||||
// Hosts file settings
|
||||
Preference pref_hosts = screen.findPreference("hosts");
|
||||
Preference pref_block_domains = screen.findPreference("use_hosts");
|
||||
Preference pref_hosts_import = screen.findPreference("hosts_import");
|
||||
EditTextPreference pref_hosts_url = (EditTextPreference) screen.findPreference("hosts_url");
|
||||
final Preference pref_hosts_download = screen.findPreference("hosts_download");
|
||||
String last = prefs.getString("hosts_last", null);
|
||||
if (last != null)
|
||||
pref_hosts_download.setSummary(getString(R.string.msg_download_last, last));
|
||||
|
||||
if (Util.isPlayStoreInstall(this)) {
|
||||
PreferenceCategory pref_category = (PreferenceCategory) screen.findPreference("category_advanced_options");
|
||||
pref_category.removePreference(pref_block_domains);
|
||||
|
||||
PreferenceCategory pref_backup = (PreferenceCategory) screen.findPreference("category_backup");
|
||||
pref_backup.removePreference(pref_hosts);
|
||||
pref_backup.removePreference(pref_hosts_import);
|
||||
pref_backup.removePreference(pref_hosts_url);
|
||||
pref_backup.removePreference(pref_hosts_download);
|
||||
|
||||
} else {
|
||||
pref_block_domains.setEnabled(new File(getFilesDir(), "hosts.txt").exists());
|
||||
|
||||
String last_import = prefs.getString("hosts_last_import", null);
|
||||
String last_download = prefs.getString("hosts_last_download", null);
|
||||
if (last_import != null)
|
||||
pref_hosts_import.setSummary(getString(R.string.msg_import_last, last_import));
|
||||
if (last_download != null)
|
||||
pref_hosts_download.setSummary(getString(R.string.msg_download_last, last_download));
|
||||
|
||||
// Handle hosts import
|
||||
// https://github.com/Free-Software-for-Android/AdAway/wiki/HostsSources
|
||||
pref_hosts.setEnabled(getIntentOpenHosts().resolveActivity(getPackageManager()) != null);
|
||||
pref_hosts.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
pref_hosts_import.setEnabled(getIntentOpenHosts().resolveActivity(getPackageManager()) != null);
|
||||
pref_hosts_import.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
startActivityForResult(getIntentOpenHosts(), ActivitySettings.REQUEST_HOSTS);
|
||||
|
@ -264,7 +269,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
|
|||
tmp.renameTo(hosts);
|
||||
|
||||
String last = SimpleDateFormat.getDateTimeInstance().format(new Date().getTime());
|
||||
prefs.edit().putString("hosts_last", last).apply();
|
||||
prefs.edit().putString("hosts_last_download", last).apply();
|
||||
|
||||
if (running) {
|
||||
getPreferenceScreen().findPreference("use_hosts").setEnabled(true);
|
||||
|
@ -848,15 +853,17 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
|
|||
protected void onPostExecute(Throwable ex) {
|
||||
if (running) {
|
||||
if (ex == null) {
|
||||
Toast.makeText(ActivitySettings.this, R.string.msg_completed, Toast.LENGTH_LONG).show();
|
||||
|
||||
getPreferenceScreen().findPreference("use_hosts").setEnabled(true);
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivitySettings.this);
|
||||
prefs.edit().remove("hosts_last").apply();
|
||||
getPreferenceScreen().findPreference("hosts_download").setSummary(null);
|
||||
String last = SimpleDateFormat.getDateTimeInstance().format(new Date().getTime());
|
||||
prefs.edit().putString("hosts_last_import", last).apply();
|
||||
|
||||
SinkholeService.reload(null, "hosts", ActivitySettings.this);
|
||||
if (running) {
|
||||
getPreferenceScreen().findPreference("use_hosts").setEnabled(true);
|
||||
getPreferenceScreen().findPreference("hosts_import").setSummary(getString(R.string.msg_import_last, last));
|
||||
Toast.makeText(ActivitySettings.this, R.string.msg_completed, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
SinkholeService.reload(null, "hosts import", ActivitySettings.this);
|
||||
} else
|
||||
Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
|
|
@ -117,7 +117,6 @@ however it is impossible to guarantee NetGuard will work correctly on every devi
|
|||
<string name="summary_block_domains">Respond with \'name error\' (NXDOMAIN) for blocked domain names. This switch is disabled when no hosts file is available.</string>
|
||||
|
||||
<string name="summary_stats">Show network speed graph in status bar notification</string>
|
||||
<string name="summary_hosts">Import a standard hosts file. A host file will not be exported when exporting settings.</string>
|
||||
|
||||
<string-array name="default_wifi_home" />
|
||||
|
||||
|
@ -146,6 +145,7 @@ Your internet traffic is not being sent to a remote VPN server.</string>
|
|||
<string name="msg_log_disabled">Traffic logging is disabled, use the switch above to enable logging. Traffic logging might result in extra battery usage.</string>
|
||||
<string name="msg_clear_rules">This will reset the rules and conditions to their default values</string>
|
||||
<string name="msg_reset_access">This will delete access attempt log lines without allow/block rules</string>
|
||||
<string name="msg_import_last">Last import: %s</string>
|
||||
<string name="msg_downloading">Downloading\n%1s</string>
|
||||
<string name="msg_downloaded">Hosts file downloaded</string>
|
||||
<string name="msg_download_last">Last download: %s</string>
|
||||
|
|
|
@ -184,8 +184,7 @@
|
|||
android:title="@string/setting_import" />
|
||||
<Preference
|
||||
android:dependency="filter"
|
||||
android:key="hosts"
|
||||
android:summary="@string/summary_hosts"
|
||||
android:key="hosts_import"
|
||||
android:title="@string/setting_hosts" />
|
||||
<EditTextPreference
|
||||
android:defaultValue="http://www.netguard.me/hosts"
|
||||
|
|
|
@ -184,8 +184,7 @@
|
|||
android:title="@string/setting_import" />
|
||||
<Preference
|
||||
android:dependency="filter"
|
||||
android:key="hosts"
|
||||
android:summary="@string/summary_hosts"
|
||||
android:key="hosts_import"
|
||||
android:title="@string/setting_hosts" />
|
||||
<EditTextPreference
|
||||
android:defaultValue="http://www.netguard.me/hosts"
|
||||
|
|
Loading…
Reference in a new issue