Commit ec1e6273 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Adjusted the settings import/export to the new API

parent e758f92c
......@@ -43,6 +43,7 @@ dependencies {
implementation project(path: ':AndroidUtils:library')
testImplementation 'junit:junit:4.12'
testImplementation "org.robolectric:robolectric:3.6.1"
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'dnsjava:dnsjava:2.1.8'
implementation 'org.pcap4j:pcap4j-core:1.7.3'
implementation 'org.pcap4j:pcap4j-packetfactory-static:1.7.3'
......
......@@ -569,6 +569,7 @@ public class MainActivity extends NavigationDrawerActivity implements RuleImport
licenseText += "\n\n- - - - - - - - - - - -\npcap4j by Kaito Yamada\n\nAvailable under the [3]MIT License[4]";
licenseText += "\n\n- - - - - - - - - - - -\nMiniDNS by Measite\n\nAvailable under the [5]Apache License 2.0[6]";
licenseText += "\n\n- - - - - - - - - - - -\nMaterial icon pack by Google\n\nAvailable under the [7]Apache License 2.0[8]";
licenseText += "\n\n- - - - - - - - - - - -\nGson by google\n\nAvailable under the [9]Apache License 2.0[a]";
ClickableSpan span = new ClickableSpan() {
@Override
public void onClick(View view) {
......@@ -593,12 +594,18 @@ public class MainActivity extends NavigationDrawerActivity implements RuleImport
public void onClick(View view) {
new AlertDialog.Builder(MainActivity.this).setTitle("Apache License 2.0").setPositiveButton(R.string.close, null).setMessage(R.string.license_apache_2).show();
}
};
}, span5 = new ClickableSpan() {
@Override
public void onClick(View view) {
new AlertDialog.Builder(MainActivity.this).setTitle("Apache License 2.0").setPositiveButton(R.string.close, null).setMessage(R.string.license_apache_2).show();
}
};;
SpannableString spannable = new SpannableString(licenseText.replaceAll("\\[.]",""));
spannable.setSpan(span3, licenseText.indexOf("[1]"), licenseText.indexOf("[2]")-3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(span2, licenseText.indexOf("[3]")-6, licenseText.indexOf("[4]")-9, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(span, licenseText.indexOf("[5]")-12, licenseText.indexOf("[6]")-15, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(span4, licenseText.indexOf("[7]")-18, licenseText.indexOf("[8]")-21, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(span5, licenseText.indexOf("[9]")-24, licenseText.indexOf("[a]")-27, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
dialog1 = new AlertDialog.Builder(MainActivity.this).setTitle(R.string.nav_title_libraries).setNegativeButton(R.string.close, null)
.setMessage(spannable).show();
((TextView)dialog1.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
......
......@@ -12,6 +12,10 @@ import com.frostnerd.dnschanger.util.ThemeHandler;
import com.frostnerd.utils.permissions.PermissionsUtil;
import com.frostnerd.dnschanger.util.Preferences;
import com.frostnerd.utils.preferences.util.PreferenceHelper;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.File;
......@@ -78,7 +82,7 @@ public class SettingsImportActivity extends Activity {
else data.append(line);
}
LogFactory.writeMessage(c, LOG_TAG, "Data read: " + data);
PreferenceHelper.importFromStringAndPut(Preferences.getInstance(c), data.toString(), "<<>>");
PreferenceHelper.importFromJSON(Preferences.getInstance(c), new Gson().fromJson(data.toString(), JsonObject.class));
LogFactory.writeMessage(c, LOG_TAG, "Imported data and added to preferences.");
} catch (Exception e) {
LogFactory.writeStackTrace(c, LogFactory.Tag.ERROR, e);
......
......@@ -12,12 +12,13 @@ import com.frostnerd.dnschanger.R;
import com.frostnerd.dnschanger.database.DatabaseHelper;
import com.frostnerd.dnschanger.database.entities.Shortcut;
import com.frostnerd.dnschanger.util.ThemeHandler;
import com.frostnerd.dnschanger.util.Util;
import com.frostnerd.utils.design.dialogs.FileChooserDialog;
import com.frostnerd.dnschanger.util.Preferences;
import com.frostnerd.utils.lifecyclehelper.UtilityDialog;
import com.frostnerd.utils.preferences.util.PreferenceHelper;
import org.json.JSONException;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
......@@ -98,11 +99,11 @@ public class ExportSettingsDialog extends UtilityDialog {
LogFactory.writeMessage(context, LOG_TAG, "Stream opened. Starting to write");
writer.write("[DNSChanger Settings - " + BuildConfig.VERSION_NAME + "]\n");
writer.write("[Developer: Frostnerd.com]\n");
writer.write("[DO NOT TAMPER WITH THIS FILE");
writer.write("[IT WAS AUTOGENERATED AND YOU MIGHT BREAK IT]");
writer.write("[DO NOT TAMPER WITH THIS FILE]\n");
writer.write("[IT WAS AUTOGENERATED AND YOU MIGHT BREAK IT]\n");
LogFactory.writeMessage(context, LOG_TAG, "Flushing Headers");
writer.flush();
writer.write(PreferenceHelper.exportToString(Preferences.getInstance(context),false,"<<>>\n","first_run","device_admin"));
writer.write(PreferenceHelper.exportToJSON(Preferences.getInstance(context),false,"<<>>\n","first_run","device_admin", "launches", "rated").toString());
LogFactory.writeMessage(context, LOG_TAG, "Flushing data");
writer.flush();
if(exportShortcuts){
......@@ -140,7 +141,9 @@ public class ExportSettingsDialog extends UtilityDialog {
} catch (IOException e) {
LogFactory.writeStackTrace(context, new String[]{LogFactory.Tag.ERROR.toString()}, e);
e.printStackTrace();
}finally {
} catch (JSONException e) {
e.printStackTrace();
} finally {
try {
if(writer != null)writer.close();
if(fw != null)fw.close();
......
......@@ -126,7 +126,7 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Search
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
LogFactory.writeMessage(requireContext(), LOG_TAG, "Preference " + preference.getKey() + " was changed to " +
newValue + ", Type: " + PreferenceHelper.getType(newValue));
newValue + ", Type: " + Preferences.guessType(newValue));
boolean value = (Boolean) newValue;
if (value && !devicePolicyManager.isAdminActive(deviceAdmin)) {
LogFactory.writeMessage(requireContext(), LOG_TAG, "User wants app to function as DeviceAdmin but access isn't granted yet. Showing dialog explaining Device Admin");
......@@ -171,7 +171,7 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Search
public boolean onPreferenceChange(Preference preference, Object newValue) {
preferences.put(preference.getKey(), newValue);
LogFactory.writeMessage(requireContext(), LOG_TAG, "Preference " + preference.getKey() + " was changed to " +
newValue + ", Type: " + PreferenceHelper.getType(newValue));
newValue + ", Type: " + Preferences.guessType(newValue));
boolean val = (Boolean) newValue;
if (!val) {
debugCategory.removePreference(sendDebugPreference);
......@@ -447,7 +447,7 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Search
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
LogFactory.writeMessage(requireContext(), LOG_TAG, "Preference " + preference.getKey() + " was changed to " +
newValue + ", Type: " + PreferenceHelper.getType(newValue));
newValue + ", Type: " + Preferences.guessType(newValue));
Preferences.getInstance(requireContext()).put(preference.getKey(), newValue, false);
String key = preference.getKey();
if((key.equalsIgnoreCase("setting_show_notification") || key.equalsIgnoreCase("show_used_dns") ||
......
Supports Markdown
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