|
|
@ -44,42 +44,45 @@ import java.io.OutputStream; |
|
|
|
@EBean(scope = Scope.Singleton) |
|
|
|
@EBean(scope = Scope.Singleton) |
|
|
|
public class SettingsPersistence { |
|
|
|
public class SettingsPersistence { |
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
@Bean |
|
|
|
protected ApplicationSettings applicationSettings; |
|
|
|
protected ApplicationSettings applicationSettings; |
|
|
|
@Bean |
|
|
|
@Bean |
|
|
|
protected SystemSettings systemSettings; |
|
|
|
protected SystemSettings systemSettings; |
|
|
|
|
|
|
|
|
|
|
|
public static final String DEFAULT_SETTINGS_DIR = Environment.getExternalStorageDirectory().toString() |
|
|
|
public static final String DEFAULT_SETTINGS_DIR = Environment.getExternalStorageDirectory().toString() |
|
|
|
+ "/Transdroid/"; |
|
|
|
+ "/Transdroid/"; |
|
|
|
public static final String DEFAULT_SETTINGS_FILENAME = "settings.json"; |
|
|
|
public static final String DEFAULT_SETTINGS_FILENAME = "settings.json"; |
|
|
|
public static final File DEFAULT_SETTINGS_FILE = new File(DEFAULT_SETTINGS_DIR + DEFAULT_SETTINGS_FILENAME); |
|
|
|
public static final File DEFAULT_SETTINGS_FILE = new File(DEFAULT_SETTINGS_DIR + DEFAULT_SETTINGS_FILENAME); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Reads the server, web searches, RSS feed, background service and system settings from a JSON-encoded String, such as when read via a QR code. |
|
|
|
* Reads the server, web searches, RSS feed, background service and system settings from a JSON-encoded String, such as when read via a QR code. |
|
|
|
* @param prefs The application-global preferences object to write settings to |
|
|
|
* |
|
|
|
* @param contents The JSON-encoded settings as raw String |
|
|
|
* @param prefs The application-global preferences object to write settings to |
|
|
|
* @throws JSONException Thrown when the file did not contain valid JSON content |
|
|
|
* @param contents The JSON-encoded settings as raw String |
|
|
|
*/ |
|
|
|
* @throws JSONException Thrown when the file did not contain valid JSON content |
|
|
|
public void importSettingsAsString(SharedPreferences prefs, String contents) throws JSONException { |
|
|
|
*/ |
|
|
|
importSettings(prefs, new JSONObject(contents)); |
|
|
|
public void importSettingsAsString(SharedPreferences prefs, String contents) throws JSONException { |
|
|
|
} |
|
|
|
importSettings(prefs, new JSONObject(contents)); |
|
|
|
|
|
|
|
} |
|
|
|
/** |
|
|
|
|
|
|
|
* Synchronously reads the server, web searches, RSS feed, background service and system settings from a file in |
|
|
|
/** |
|
|
|
* JSON format. |
|
|
|
* Synchronously reads the server, web searches, RSS feed, background service and system settings from a file in |
|
|
|
* @param prefs The application-global preferences object to write settings to |
|
|
|
* JSON format. |
|
|
|
* @param settingsFile The local file to read the settings from |
|
|
|
* |
|
|
|
* @throws FileNotFoundException Thrown when the settings file doesn't exist or couldn't be read |
|
|
|
* @param prefs The application-global preferences object to write settings to |
|
|
|
* @throws JSONException Thrown when the file did not contain valid JSON content |
|
|
|
* @param settingsFile The local file to read the settings from |
|
|
|
*/ |
|
|
|
* @throws FileNotFoundException Thrown when the settings file doesn't exist or couldn't be read |
|
|
|
public void importSettingsFromFile(SharedPreferences prefs, File settingsFile) throws FileNotFoundException, JSONException { |
|
|
|
* @throws JSONException Thrown when the file did not contain valid JSON content |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void importSettingsFromFile(SharedPreferences prefs, File settingsFile) throws FileNotFoundException, JSONException { |
|
|
|
importSettingsFromStream(prefs, new FileInputStream(settingsFile)); |
|
|
|
importSettingsFromStream(prefs, new FileInputStream(settingsFile)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Synchronously reads the server, web searches, RSS feed, background service and system settings from a stream (file) in |
|
|
|
* Synchronously reads the server, web searches, RSS feed, background service and system settings from a stream (file) in |
|
|
|
* JSON format. |
|
|
|
* JSON format. |
|
|
|
* @param prefs The application-global preferences object to write settings to |
|
|
|
* |
|
|
|
|
|
|
|
* @param prefs The application-global preferences object to write settings to |
|
|
|
* @param settingsStream The stream to read the settings from |
|
|
|
* @param settingsStream The stream to read the settings from |
|
|
|
* @throws JSONException Thrown when the file did not contain valid JSON content |
|
|
|
* @throws JSONException Thrown when the file did not contain valid JSON content |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -88,287 +91,289 @@ public class SettingsPersistence { |
|
|
|
importSettings(prefs, new JSONObject(raw)); |
|
|
|
importSettings(prefs, new JSONObject(raw)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void importSettings(SharedPreferences prefs, JSONObject json) throws JSONException { |
|
|
|
public void importSettings(SharedPreferences prefs, JSONObject json) throws JSONException { |
|
|
|
|
|
|
|
|
|
|
|
Editor editor = prefs.edit(); |
|
|
|
Editor editor = prefs.edit(); |
|
|
|
|
|
|
|
|
|
|
|
// Import servers
|
|
|
|
// Import servers
|
|
|
|
if (json.has("servers")) { |
|
|
|
if (json.has("servers")) { |
|
|
|
JSONArray servers = json.getJSONArray("servers"); |
|
|
|
JSONArray servers = json.getJSONArray("servers"); |
|
|
|
for (int i = 0; i < servers.length(); i++) { |
|
|
|
for (int i = 0; i < servers.length(); i++) { |
|
|
|
JSONObject server = servers.getJSONObject(i); |
|
|
|
JSONObject server = servers.getJSONObject(i); |
|
|
|
String postfix = Integer.toString(applicationSettings.getMaxOfAllServers() + 1 + i); |
|
|
|
String postfix = Integer.toString(applicationSettings.getMaxOfAllServers() + 1 + i); |
|
|
|
|
|
|
|
|
|
|
|
if (server.has("name")) |
|
|
|
if (server.has("name")) |
|
|
|
editor.putString("server_name_" + postfix, server.getString("name")); |
|
|
|
editor.putString("server_name_" + postfix, server.getString("name")); |
|
|
|
if (server.has("type")) |
|
|
|
if (server.has("type")) |
|
|
|
editor.putString("server_type_" + postfix, server.getString("type")); |
|
|
|
editor.putString("server_type_" + postfix, server.getString("type")); |
|
|
|
if (server.has("host")) |
|
|
|
if (server.has("host")) |
|
|
|
editor.putString("server_address_" + postfix, server.getString("host")); |
|
|
|
editor.putString("server_address_" + postfix, server.getString("host")); |
|
|
|
if (server.has("local_network")) |
|
|
|
if (server.has("local_network")) |
|
|
|
editor.putString("server_localnetwork_" + postfix, server.getString("local_network")); |
|
|
|
editor.putString("server_localnetwork_" + postfix, server.getString("local_network")); |
|
|
|
if (server.has("local_host")) |
|
|
|
if (server.has("local_host")) |
|
|
|
editor.putString("server_localaddress_" + postfix, server.getString("local_host")); |
|
|
|
editor.putString("server_localaddress_" + postfix, server.getString("local_host")); |
|
|
|
if (server.has("local_port")) |
|
|
|
if (server.has("local_port")) |
|
|
|
editor.putString("server_localport_" + postfix, server.getString("local_port")); |
|
|
|
editor.putString("server_localport_" + postfix, server.getString("local_port")); |
|
|
|
if (server.has("port")) |
|
|
|
if (server.has("port")) |
|
|
|
editor.putString("server_port_" + postfix, server.getString("port")); |
|
|
|
editor.putString("server_port_" + postfix, server.getString("port")); |
|
|
|
if (server.has("ssl")) |
|
|
|
if (server.has("ssl")) |
|
|
|
editor.putBoolean("server_sslenabled_" + postfix, server.getBoolean("ssl")); |
|
|
|
editor.putBoolean("server_sslenabled_" + postfix, server.getBoolean("ssl")); |
|
|
|
if (server.has("local_ssl")) |
|
|
|
if (server.has("local_ssl")) |
|
|
|
editor.putBoolean("server_localsslenabled_" + postfix, server.getBoolean("local_ssl")); |
|
|
|
editor.putBoolean("server_localsslenabled_" + postfix, server.getBoolean("local_ssl")); |
|
|
|
if (server.has("ssl_accept_all")) |
|
|
|
if (server.has("ssl_accept_all")) |
|
|
|
editor.putBoolean("server_ssltrustall_" + postfix, server.getBoolean("ssl_accept_all")); |
|
|
|
editor.putBoolean("server_ssltrustall_" + postfix, server.getBoolean("ssl_accept_all")); |
|
|
|
if (server.has("ssl_trust_key")) |
|
|
|
if (server.has("ssl_trust_key")) |
|
|
|
editor.putString("server_ssltrustkey_" + postfix, server.getString("ssl_trust_key")); |
|
|
|
editor.putString("server_ssltrustkey_" + postfix, server.getString("ssl_trust_key")); |
|
|
|
if (server.has("folder")) |
|
|
|
if (server.has("folder")) |
|
|
|
editor.putString("server_folder_" + postfix, server.getString("folder")); |
|
|
|
editor.putString("server_folder_" + postfix, server.getString("folder")); |
|
|
|
if (server.has("use_auth")) |
|
|
|
if (server.has("use_auth")) |
|
|
|
editor.putBoolean("server_disableauth_" + postfix, !server.getBoolean("use_auth")); |
|
|
|
editor.putBoolean("server_disableauth_" + postfix, !server.getBoolean("use_auth")); |
|
|
|
if (server.has("username")) |
|
|
|
if (server.has("username")) |
|
|
|
editor.putString("server_user_" + postfix, server.getString("username")); |
|
|
|
editor.putString("server_user_" + postfix, server.getString("username")); |
|
|
|
if (server.has("password")) |
|
|
|
if (server.has("password")) |
|
|
|
editor.putString("server_pass_" + postfix, server.getString("password")); |
|
|
|
editor.putString("server_pass_" + postfix, server.getString("password")); |
|
|
|
if (server.has("extra_password")) |
|
|
|
if (server.has("extra_password")) |
|
|
|
editor.putString("server_extrapass_" + postfix, server.getString("extra_password")); |
|
|
|
editor.putString("server_extrapass_" + postfix, server.getString("extra_password")); |
|
|
|
if (server.has("os_type")) |
|
|
|
if (server.has("os_type")) |
|
|
|
editor.putString("server_os_" + postfix, server.getString("os_type")); |
|
|
|
editor.putString("server_os_" + postfix, server.getString("os_type")); |
|
|
|
if (server.has("downloads_dir")) |
|
|
|
if (server.has("downloads_dir")) |
|
|
|
editor.putString("server_downloaddir_" + postfix, server.getString("downloads_dir")); |
|
|
|
editor.putString("server_downloaddir_" + postfix, server.getString("downloads_dir")); |
|
|
|
if (server.has("base_ftp_url")) |
|
|
|
if (server.has("base_ftp_url")) |
|
|
|
editor.putString("server_ftpurl_" + postfix, server.getString("base_ftp_url")); |
|
|
|
editor.putString("server_ftpurl_" + postfix, server.getString("base_ftp_url")); |
|
|
|
if (server.has("ftp_password")) |
|
|
|
if (server.has("ftp_password")) |
|
|
|
editor.putString("server_ftppass_" + postfix, server.getString("ftp_password")); |
|
|
|
editor.putString("server_ftppass_" + postfix, server.getString("ftp_password")); |
|
|
|
if (server.has("server_timeout")) |
|
|
|
if (server.has("server_timeout")) |
|
|
|
editor.putString("server_timeout_" + postfix, server.getString("server_timeout")); |
|
|
|
editor.putString("server_timeout_" + postfix, server.getString("server_timeout")); |
|
|
|
if (server.has("download_alarm")) |
|
|
|
if (server.has("download_alarm")) |
|
|
|
editor.putBoolean("server_alarmfinished_" + postfix, server.getBoolean("download_alarm")); |
|
|
|
editor.putBoolean("server_alarmfinished_" + postfix, server.getBoolean("download_alarm")); |
|
|
|
if (server.has("new_torrent_alarm")) |
|
|
|
if (server.has("new_torrent_alarm")) |
|
|
|
editor.putBoolean("server_alarmnew_" + postfix, server.getBoolean("new_torrent_alarm")); |
|
|
|
editor.putBoolean("server_alarmnew_" + postfix, server.getBoolean("new_torrent_alarm")); |
|
|
|
if (server.has("alarm_filter_exclude")) |
|
|
|
if (server.has("alarm_filter_exclude")) |
|
|
|
editor.putString("server_alarmexclude_" + postfix, server.getString("alarm_filter_exclude")); |
|
|
|
editor.putString("server_alarmexclude_" + postfix, server.getString("alarm_filter_exclude")); |
|
|
|
if (server.has("alarm_filter_include")) |
|
|
|
if (server.has("alarm_filter_include")) |
|
|
|
editor.putString("server_alarminclude_" + postfix, server.getString("alarm_filter_include")); |
|
|
|
editor.putString("server_alarminclude_" + postfix, server.getString("alarm_filter_include")); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Import web search sites
|
|
|
|
// Import web search sites
|
|
|
|
if (json.has("websites")) { |
|
|
|
if (json.has("websites")) { |
|
|
|
JSONArray sites = json.getJSONArray("websites"); |
|
|
|
JSONArray sites = json.getJSONArray("websites"); |
|
|
|
for (int i = 0; i < sites.length(); i++) { |
|
|
|
for (int i = 0; i < sites.length(); i++) { |
|
|
|
JSONObject site = sites.getJSONObject(i); |
|
|
|
JSONObject site = sites.getJSONObject(i); |
|
|
|
String postfix = Integer.toString(applicationSettings.getMaxWebsearch() + 1 + i); |
|
|
|
String postfix = Integer.toString(applicationSettings.getMaxWebsearch() + 1 + i); |
|
|
|
|
|
|
|
|
|
|
|
if (site.has("name")) |
|
|
|
if (site.has("name")) |
|
|
|
editor.putString("websearch_name_" + postfix, site.getString("name")); |
|
|
|
editor.putString("websearch_name_" + postfix, site.getString("name")); |
|
|
|
if (site.has("url")) |
|
|
|
if (site.has("url")) |
|
|
|
editor.putString("websearch_baseurl_" + postfix, site.getString("url")); |
|
|
|
editor.putString("websearch_baseurl_" + postfix, site.getString("url")); |
|
|
|
if (site.has("cookies")) |
|
|
|
if (site.has("cookies")) |
|
|
|
editor.putString("websearch_cookies_" + postfix, site.getString("cookies")); |
|
|
|
editor.putString("websearch_cookies_" + postfix, site.getString("cookies")); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Import RSS feeds
|
|
|
|
// Import RSS feeds
|
|
|
|
if (json.has("rssfeeds")) { |
|
|
|
if (json.has("rssfeeds")) { |
|
|
|
JSONArray feeds = json.getJSONArray("rssfeeds"); |
|
|
|
JSONArray feeds = json.getJSONArray("rssfeeds"); |
|
|
|
for (int i = 0; i < feeds.length(); i++) { |
|
|
|
for (int i = 0; i < feeds.length(); i++) { |
|
|
|
JSONObject feed = feeds.getJSONObject(i); |
|
|
|
JSONObject feed = feeds.getJSONObject(i); |
|
|
|
String postfix = Integer.toString(applicationSettings.getMaxRssfeed() + 1 + i); |
|
|
|
String postfix = Integer.toString(applicationSettings.getMaxRssfeed() + 1 + i); |
|
|
|
|
|
|
|
|
|
|
|
if (feed.has("name")) |
|
|
|
if (feed.has("name")) |
|
|
|
editor.putString("rssfeed_name_" + postfix, feed.getString("name")); |
|
|
|
editor.putString("rssfeed_name_" + postfix, feed.getString("name")); |
|
|
|
if (feed.has("url")) |
|
|
|
if (feed.has("url")) |
|
|
|
editor.putString("rssfeed_url_" + postfix, feed.getString("url")); |
|
|
|
editor.putString("rssfeed_url_" + postfix, feed.getString("url")); |
|
|
|
if (feed.has("needs_auth")) |
|
|
|
if (feed.has("needs_auth")) |
|
|
|
editor.putBoolean("rssfeed_reqauth_" + postfix, feed.getBoolean("needs_auth")); |
|
|
|
editor.putBoolean("rssfeed_reqauth_" + postfix, feed.getBoolean("needs_auth")); |
|
|
|
if (feed.has("new_item_alarm")) |
|
|
|
if (feed.has("new_item_alarm")) |
|
|
|
editor.putBoolean("rssfeed_alarmnew_" + postfix, feed.getBoolean("new_item_alarm")); |
|
|
|
editor.putBoolean("rssfeed_alarmnew_" + postfix, feed.getBoolean("new_item_alarm")); |
|
|
|
if (feed.has("alarm_filter_include")) |
|
|
|
if (feed.has("alarm_filter_include")) |
|
|
|
editor.putString("rssfeed_include_" + postfix, feed.getString("alarm_filter_include")); |
|
|
|
editor.putString("rssfeed_include_" + postfix, feed.getString("alarm_filter_include")); |
|
|
|
if (feed.has("alarm_filter_exclude")) |
|
|
|
if (feed.has("alarm_filter_exclude")) |
|
|
|
editor.putString("rssfeed_exclude_" + postfix, feed.getString("alarm_filter_exclude")); |
|
|
|
editor.putString("rssfeed_exclude_" + postfix, feed.getString("alarm_filter_exclude")); |
|
|
|
if (feed.has("last_seen_time")) |
|
|
|
if (feed.has("last_seen_time")) |
|
|
|
editor.putLong("rssfeed_lastviewed_" + postfix, feed.getLong("last_seen_time")); |
|
|
|
editor.putLong("rssfeed_lastviewed_" + postfix, feed.getLong("last_seen_time")); |
|
|
|
if (feed.has("last_seen_item")) |
|
|
|
if (feed.has("last_seen_item")) |
|
|
|
editor.putString("rssfeed_lastvieweditemurl_" + postfix, feed.getString("last_seen_item")); |
|
|
|
editor.putString("rssfeed_lastvieweditemurl_" + postfix, feed.getString("last_seen_item")); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Import background service and system settings
|
|
|
|
// Import background service and system settings
|
|
|
|
if (json.has("alarm_enabled_rss")) |
|
|
|
if (json.has("alarm_enabled_rss")) |
|
|
|
editor.putBoolean("notifications_enabledrss", json.getBoolean("alarm_enabled_rss")); |
|
|
|
editor.putBoolean("notifications_enabledrss", json.getBoolean("alarm_enabled_rss")); |
|
|
|
if (json.has("alarm_enabled_torrents")) |
|
|
|
if (json.has("alarm_enabled_torrents")) |
|
|
|
editor.putBoolean("notifications_enabled", json.getBoolean("alarm_enabled_torrents")); |
|
|
|
editor.putBoolean("notifications_enabled", json.getBoolean("alarm_enabled_torrents")); |
|
|
|
else if (json.has("alarm_enabled")) // Compat
|
|
|
|
else if (json.has("alarm_enabled")) // Compat
|
|
|
|
editor.putBoolean("notifications_enabled", json.getBoolean("alarm_enabled")); |
|
|
|
editor.putBoolean("notifications_enabled", json.getBoolean("alarm_enabled")); |
|
|
|
if (json.has("alarm_interval")) |
|
|
|
if (json.has("alarm_interval")) |
|
|
|
editor.putString("notifications_interval", json.getString("alarm_interval")); |
|
|
|
editor.putString("notifications_interval", json.getString("alarm_interval")); |
|
|
|
if (json.has("alarm_sound_uri")) |
|
|
|
if (json.has("alarm_sound_uri")) |
|
|
|
editor.putString("notifications_sound", json.getString("alarm_sound_uri")); |
|
|
|
editor.putString("notifications_sound", json.getString("alarm_sound_uri")); |
|
|
|
if (json.has("alarm_vibrate")) |
|
|
|
if (json.has("alarm_vibrate")) |
|
|
|
editor.putBoolean("notifications_vibrate", json.getBoolean("alarm_vibrate")); |
|
|
|
editor.putBoolean("notifications_vibrate", json.getBoolean("alarm_vibrate")); |
|
|
|
if (json.has("alarm_ledcolour")) |
|
|
|
if (json.has("alarm_ledcolour")) |
|
|
|
editor.putInt("notifications_ledcolour", json.getInt("alarm_ledcolour")); |
|
|
|
editor.putInt("notifications_ledcolour", json.getInt("alarm_ledcolour")); |
|
|
|
if (json.has("alarm_adwnotifications")) |
|
|
|
if (json.has("alarm_adwnotifications")) |
|
|
|
editor.putBoolean("notifications_adwnotify", json.getBoolean("alarm_adwnotifications")); |
|
|
|
editor.putBoolean("notifications_adwnotify", json.getBoolean("alarm_adwnotifications")); |
|
|
|
if (json.has("system_dormantasinactive")) |
|
|
|
if (json.has("system_dormantasinactive")) |
|
|
|
editor.putBoolean("system_dormantasinactive", json.getBoolean("system_dormantasinactive")); |
|
|
|
editor.putBoolean("system_dormantasinactive", json.getBoolean("system_dormantasinactive")); |
|
|
|
if (json.has("system_autorefresh")) |
|
|
|
if (json.has("system_autorefresh")) |
|
|
|
editor.putString("system_autorefresh", json.getString("system_autorefresh")); |
|
|
|
editor.putString("system_autorefresh", json.getString("system_autorefresh")); |
|
|
|
if (json.has("system_checkupdates")) |
|
|
|
if (json.has("system_checkupdates")) |
|
|
|
editor.putBoolean("system_checkupdates", json.getBoolean("system_checkupdates")); |
|
|
|
editor.putBoolean("system_checkupdates", json.getBoolean("system_checkupdates")); |
|
|
|
if (json.has("system_usedarktheme")) |
|
|
|
if (json.has("system_usedarktheme")) |
|
|
|
editor.putBoolean("system_usedarktheme", json.getBoolean("system_usedarktheme")); |
|
|
|
editor.putBoolean("system_usedarktheme", json.getBoolean("system_usedarktheme")); |
|
|
|
|
|
|
|
|
|
|
|
editor.apply(); |
|
|
|
editor.apply(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Returns encoded server, web searches, RSS feed, background service and system settings as a JSON data object structure, serialized to a String. |
|
|
|
* Returns encoded server, web searches, RSS feed, background service and system settings as a JSON data object structure, serialized to a String. |
|
|
|
* @param prefs The application-global preferences object to read settings from |
|
|
|
* |
|
|
|
* @throws JSONException Thrown when the JSON content could not be constructed properly |
|
|
|
* @param prefs The application-global preferences object to read settings from |
|
|
|
*/ |
|
|
|
* @throws JSONException Thrown when the JSON content could not be constructed properly |
|
|
|
public String exportSettingsAsString(SharedPreferences prefs) throws JSONException { |
|
|
|
*/ |
|
|
|
return exportSettings(prefs).toString(); |
|
|
|
public String exportSettingsAsString(SharedPreferences prefs) throws JSONException { |
|
|
|
} |
|
|
|
return exportSettings(prefs).toString(); |
|
|
|
|
|
|
|
} |
|
|
|
/** |
|
|
|
|
|
|
|
* Synchronously writes the server, web searches, RSS feed, background service and system settings to a file in JSON |
|
|
|
/** |
|
|
|
* format. |
|
|
|
* Synchronously writes the server, web searches, RSS feed, background service and system settings to a file in JSON |
|
|
|
* @param prefs The application-global preferences object to read settings from |
|
|
|
* format. |
|
|
|
* @param settingsFile The local file to read the settings from |
|
|
|
* |
|
|
|
* @throws JSONException Thrown when the JSON content could not be constructed properly |
|
|
|
* @param prefs The application-global preferences object to read settings from |
|
|
|
* @throws IOException Thrown when the settings file could not be created or written to |
|
|
|
* @param settingsFile The local file to read the settings from |
|
|
|
*/ |
|
|
|
* @throws JSONException Thrown when the JSON content could not be constructed properly |
|
|
|
public void exportSettingsToFile(SharedPreferences prefs, File settingsFile) throws JSONException, IOException { |
|
|
|
* @throws IOException Thrown when the settings file could not be created or written to |
|
|
|
if (settingsFile.exists()) { |
|
|
|
*/ |
|
|
|
settingsFile.delete(); |
|
|
|
public void exportSettingsToFile(SharedPreferences prefs, File settingsFile) throws JSONException, IOException { |
|
|
|
} |
|
|
|
if (settingsFile.exists()) { |
|
|
|
settingsFile.getParentFile().mkdirs(); |
|
|
|
settingsFile.delete(); |
|
|
|
settingsFile.createNewFile(); |
|
|
|
} |
|
|
|
exportSettingsToStream(prefs, new FileOutputStream(settingsFile)); |
|
|
|
settingsFile.getParentFile().mkdirs(); |
|
|
|
} |
|
|
|
settingsFile.createNewFile(); |
|
|
|
|
|
|
|
exportSettingsToStream(prefs, new FileOutputStream(settingsFile)); |
|
|
|
/** |
|
|
|
} |
|
|
|
* Synchronously writes the server, web searches, RSS feed, background service and system settings to a stream (file) in JSON format. The stream |
|
|
|
|
|
|
|
* will be closed regardless of success. |
|
|
|
/** |
|
|
|
* |
|
|
|
* Synchronously writes the server, web searches, RSS feed, background service and system settings to a stream (file) in JSON format. The stream |
|
|
|
* @param prefs The application-global preferences object to read settings from |
|
|
|
* will be closed regardless of success. |
|
|
|
* @param settingsStream The stream to read the settings to |
|
|
|
* |
|
|
|
* @throws JSONException Thrown when the JSON content could not be constructed properly |
|
|
|
* @param prefs The application-global preferences object to read settings from |
|
|
|
* @throws IOException Thrown when the settings file could not be created or written to |
|
|
|
* @param settingsStream The stream to read the settings to |
|
|
|
*/ |
|
|
|
* @throws JSONException Thrown when the JSON content could not be constructed properly |
|
|
|
public void exportSettingsToStream(SharedPreferences prefs, OutputStream settingsStream) throws JSONException, IOException { |
|
|
|
* @throws IOException Thrown when the settings file could not be created or written to |
|
|
|
try { |
|
|
|
*/ |
|
|
|
JSONObject json = exportSettings(prefs); |
|
|
|
public void exportSettingsToStream(SharedPreferences prefs, OutputStream settingsStream) throws JSONException, IOException { |
|
|
|
settingsStream.write(json.toString(2).getBytes()); |
|
|
|
try { |
|
|
|
} finally { |
|
|
|
JSONObject json = exportSettings(prefs); |
|
|
|
settingsStream.close(); |
|
|
|
settingsStream.write(json.toString(2).getBytes()); |
|
|
|
} |
|
|
|
} finally { |
|
|
|
} |
|
|
|
settingsStream.close(); |
|
|
|
|
|
|
|
} |
|
|
|
private JSONObject exportSettings(SharedPreferences prefs) throws JSONException { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Create a single JSON object that will contain all settings
|
|
|
|
private JSONObject exportSettings(SharedPreferences prefs) throws JSONException { |
|
|
|
JSONObject json = new JSONObject(); |
|
|
|
|
|
|
|
|
|
|
|
// Create a single JSON object that will contain all settings
|
|
|
|
// Convert server settings into JSON
|
|
|
|
JSONObject json = new JSONObject(); |
|
|
|
JSONArray servers = new JSONArray(); |
|
|
|
|
|
|
|
int i = 0; |
|
|
|
// Convert server settings into JSON
|
|
|
|
String postfixi = "0"; |
|
|
|
JSONArray servers = new JSONArray(); |
|
|
|
while (prefs.contains("server_type_" + postfixi)) { |
|
|
|
int i = 0; |
|
|
|
|
|
|
|
String postfixi = "0"; |
|
|
|
JSONObject server = new JSONObject(); |
|
|
|
while (prefs.contains("server_type_" + postfixi)) { |
|
|
|
server.put("name", prefs.getString("server_name_" + postfixi, null)); |
|
|
|
|
|
|
|
server.put("type", prefs.getString("server_type_" + postfixi, null)); |
|
|
|
JSONObject server = new JSONObject(); |
|
|
|
server.put("host", prefs.getString("server_address_" + postfixi, null)); |
|
|
|
server.put("name", prefs.getString("server_name_" + postfixi, null)); |
|
|
|
server.put("local_network", prefs.getString("server_localnetwork_" + postfixi, null)); |
|
|
|
server.put("type", prefs.getString("server_type_" + postfixi, null)); |
|
|
|
server.put("local_host", prefs.getString("server_localaddress_" + postfixi, null)); |
|
|
|
server.put("host", prefs.getString("server_address_" + postfixi, null)); |
|
|
|
server.put("local_port", prefs.getString("server_localport_" + postfixi, null)); |
|
|
|
server.put("local_network", prefs.getString("server_localnetwork_" + postfixi, null)); |
|
|
|
server.put("port", prefs.getString("server_port_" + postfixi, null)); |
|
|
|
server.put("local_host", prefs.getString("server_localaddress_" + postfixi, null)); |
|
|
|
server.put("ssl", prefs.getBoolean("server_sslenabled_" + postfixi, false)); |
|
|
|
server.put("local_port", prefs.getString("server_localport_" + postfixi, null)); |
|
|
|
server.put("local_ssl", prefs.getBoolean("server_localsslenabled_" + postfixi, false)); |
|
|
|
server.put("port", prefs.getString("server_port_" + postfixi, null)); |
|
|
|
server.put("ssl_accept_all", prefs.getBoolean("server_ssltrustall_" + postfixi, false)); |
|
|
|
server.put("ssl", prefs.getBoolean("server_sslenabled_" + postfixi, false)); |
|
|
|
server.put("ssl_trust_key", prefs.getString("server_ssltrustkey_" + postfixi, null)); |
|
|
|
server.put("local_ssl", prefs.getBoolean("server_localsslenabled_" + postfixi, false)); |
|
|
|
server.put("folder", prefs.getString("server_folder_" + postfixi, null)); |
|
|
|
server.put("ssl_accept_all", prefs.getBoolean("server_ssltrustall_" + postfixi, false)); |
|
|
|
server.put("use_auth", !prefs.getBoolean("server_disableauth_" + postfixi, false)); |
|
|
|
server.put("ssl_trust_key", prefs.getString("server_ssltrustkey_" + postfixi, null)); |
|
|
|
server.put("username", prefs.getString("server_user_" + postfixi, null)); |
|
|
|
server.put("folder", prefs.getString("server_folder_" + postfixi, null)); |
|
|
|
server.put("password", prefs.getString("server_pass_" + postfixi, null)); |
|
|
|
server.put("use_auth", !prefs.getBoolean("server_disableauth_" + postfixi, false)); |
|
|
|
server.put("extra_password", prefs.getString("server_extrapass_" + postfixi, null)); |
|
|
|
server.put("username", prefs.getString("server_user_" + postfixi, null)); |
|
|
|
server.put("os_type", prefs.getString("server_os_" + postfixi, null)); |
|
|
|
server.put("password", prefs.getString("server_pass_" + postfixi, null)); |
|
|
|
server.put("downloads_dir", prefs.getString("server_downloaddir_" + postfixi, null)); |
|
|
|
server.put("extra_password", prefs.getString("server_extrapass_" + postfixi, null)); |
|
|
|
server.put("base_ftp_url", prefs.getString("server_ftpurl_" + postfixi, null)); |
|
|
|
server.put("os_type", prefs.getString("server_os_" + postfixi, null)); |
|
|
|
server.put("ftp_password", prefs.getString("server_ftppass_" + postfixi, null)); |
|
|
|
server.put("downloads_dir", prefs.getString("server_downloaddir_" + postfixi, null)); |
|
|
|
server.put("server_timeout", prefs.getString("server_timeout_" + postfixi, null)); |
|
|
|
server.put("base_ftp_url", prefs.getString("server_ftpurl_" + postfixi, null)); |
|
|
|
server.put("download_alarm", prefs.getBoolean("server_alarmfinished_" + postfixi, false)); |
|
|
|
server.put("ftp_password", prefs.getString("server_ftppass_" + postfixi, null)); |
|
|
|
server.put("new_torrent_alarm", prefs.getBoolean("server_alarmnew_" + postfixi, false)); |
|
|
|
server.put("server_timeout", prefs.getString("server_timeout_" + postfixi, null)); |
|
|
|
server.put("alarm_filter_exclude", prefs.getString("server_alarmexclude_" + postfixi, null)); |
|
|
|
server.put("download_alarm", prefs.getBoolean("server_alarmfinished_" + postfixi, false)); |
|
|
|
server.put("alarm_filter_include", prefs.getString("server_alarminclude_" + postfixi, null)); |
|
|
|
server.put("new_torrent_alarm", prefs.getBoolean("server_alarmnew_" + postfixi, false)); |
|
|
|
|
|
|
|
server.put("alarm_filter_exclude", prefs.getString("server_alarmexclude_" + postfixi, null)); |
|
|
|
servers.put(server); |
|
|
|
server.put("alarm_filter_include", prefs.getString("server_alarminclude_" + postfixi, null)); |
|
|
|
i++; |
|
|
|
|
|
|
|
postfixi = Integer.toString(i); |
|
|
|
servers.put(server); |
|
|
|
} |
|
|
|
i++; |
|
|
|
json.put("servers", servers); |
|
|
|
postfixi = Integer.toString(i); |
|
|
|
|
|
|
|
} |
|
|
|
// Convert web search settings into JSON
|
|
|
|
json.put("servers", servers); |
|
|
|
JSONArray sites = new JSONArray(); |
|
|
|
|
|
|
|
int j = 0; |
|
|
|
// Convert web search settings into JSON
|
|
|
|
String postfixj = "0"; |
|
|
|
JSONArray sites = new JSONArray(); |
|
|
|
while (prefs.contains("websearch_baseurl_" + postfixj)) { |
|
|
|
int j = 0; |
|
|
|
|
|
|
|
String postfixj = "0"; |
|
|
|
JSONObject site = new JSONObject(); |
|
|
|
while (prefs.contains("websearch_baseurl_" + postfixj)) { |
|
|
|
site.put("name", prefs.getString("websearch_name_" + postfixj, null)); |
|
|
|
|
|
|
|
site.put("url", prefs.getString("websearch_baseurl_" + postfixj, null)); |
|
|
|
JSONObject site = new JSONObject(); |
|
|
|
site.put("cookies", prefs.getString("websearch_cookies_" + postfixj, null)); |
|
|
|
site.put("name", prefs.getString("websearch_name_" + postfixj, null)); |
|
|
|
|
|
|
|
site.put("url", prefs.getString("websearch_baseurl_" + postfixj, null)); |
|
|
|
sites.put(site); |
|
|
|
site.put("cookies", prefs.getString("websearch_cookies_" + postfixj, null)); |
|
|
|
j++; |
|
|
|
|
|
|
|
postfixj = Integer.toString(j); |
|
|
|
sites.put(site); |
|
|
|
} |
|
|
|
j++; |
|
|
|
json.put("websites", sites); |
|
|
|
postfixj = Integer.toString(j); |
|
|
|
|
|
|
|
} |
|
|
|
// Convert RSS feed settings into JSON
|
|
|
|
json.put("websites", sites); |
|
|
|
JSONArray feeds = new JSONArray(); |
|
|
|
|
|
|
|
int k = 0; |
|
|
|
// Convert RSS feed settings into JSON
|
|
|
|
String postfixk = "0"; |
|
|
|
JSONArray feeds = new JSONArray(); |
|
|
|
while (prefs.contains("rssfeed_url_" + postfixk)) { |
|
|
|
int k = 0; |
|
|
|
|
|
|
|
String postfixk = "0"; |
|
|
|
JSONObject feed = new JSONObject(); |
|
|
|
while (prefs.contains("rssfeed_url_" + postfixk)) { |
|
|
|
feed.put("name", prefs.getString("rssfeed_name_" + postfixk, null)); |
|
|
|
|
|
|
|
feed.put("url", prefs.getString("rssfeed_url_" + postfixk, null)); |
|
|
|
JSONObject feed = new JSONObject(); |
|
|
|
feed.put("needs_auth", prefs.getBoolean("rssfeed_reqauth_" + postfixk, false)); |
|
|
|
feed.put("name", prefs.getString("rssfeed_name_" + postfixk, null)); |
|
|
|
feed.put("new_item_alarm", prefs.getBoolean("rssfeed_alarmnew_" + postfixk, false)); |
|
|
|
feed.put("url", prefs.getString("rssfeed_url_" + postfixk, null)); |
|
|
|
feed.put("alarm_filter_exclude", prefs.getString("rssfeed_exclude_" + postfixk, null)); |
|
|
|
feed.put("needs_auth", prefs.getBoolean("rssfeed_reqauth_" + postfixk, false)); |
|
|
|
feed.put("alarm_filter_include", prefs.getString("rssfeed_include_" + postfixk, null)); |
|
|
|
feed.put("new_item_alarm", prefs.getBoolean("rssfeed_alarmnew_" + postfixk, false)); |
|
|
|
feed.put("last_seen_time", prefs.getLong("rssfeed_lastviewed_" + postfixk, -1)); |
|
|
|
feed.put("alarm_filter_exclude", prefs.getString("rssfeed_exclude_" + postfixk, null)); |
|
|
|
feed.put("last_seen_item", prefs.getString("rssfeed_lastvieweditemurl_" + postfixk, null)); |
|
|
|
feed.put("alarm_filter_include", prefs.getString("rssfeed_include_" + postfixk, null)); |
|
|
|
|
|
|
|
feed.put("last_seen_time", prefs.getLong("rssfeed_lastviewed_" + postfixk, -1)); |
|
|
|
feeds.put(feed); |
|
|
|
feed.put("last_seen_item", prefs.getString("rssfeed_lastvieweditemurl_" + postfixk, null)); |
|
|
|
k++; |
|
|
|
|
|
|
|
postfixk = Integer.toString(k); |
|
|
|
feeds.put(feed); |
|
|
|
} |
|
|
|
k++; |
|
|
|
json.put("rssfeeds", feeds); |
|
|
|
postfixk = Integer.toString(k); |
|
|
|
|
|
|
|
} |
|
|
|
// Convert background service and system settings into JSON
|
|
|
|
json.put("rssfeeds", feeds); |
|
|
|
json.put("alarm_enabled_rss", prefs.getBoolean("notifications_enabledrss", true)); |
|
|
|
|
|
|
|
json.put("alarm_enabled_torrents", prefs.getBoolean("notifications_enabled", true)); |
|
|
|
// Convert background service and system settings into JSON
|
|
|
|
json.put("alarm_interval", prefs.getString("notifications_interval", null)); |
|
|
|
json.put("alarm_enabled_rss", prefs.getBoolean("notifications_enabledrss", true)); |
|
|
|
json.put("alarm_sound_uri", prefs.getString("notifications_sound", null)); |
|
|
|
json.put("alarm_enabled_torrents", prefs.getBoolean("notifications_enabled", true)); |
|
|
|
json.put("alarm_vibrate", prefs.getBoolean("notifications_vibrate", false)); |
|
|
|
json.put("alarm_interval", prefs.getString("notifications_interval", null)); |
|
|
|
json.put("alarm_ledcolour", prefs.getInt("notifications_ledcolour", -1)); |
|
|
|
json.put("alarm_sound_uri", prefs.getString("notifications_sound", null)); |
|
|
|
json.put("alarm_adwnotifications", prefs.getBoolean("notifications_adwnotify", false)); |
|
|
|
json.put("alarm_vibrate", prefs.getBoolean("notifications_vibrate", false)); |
|
|
|
json.put("system_dormantasinactive", prefs.getBoolean("system_dormantasinactive", false)); |
|
|
|
json.put("alarm_ledcolour", prefs.getInt("notifications_ledcolour", -1)); |
|
|
|
json.put("system_autorefresh", prefs.getString("system_autorefresh", "0")); |
|
|
|
json.put("alarm_adwnotifications", prefs.getBoolean("notifications_adwnotify", false)); |
|
|
|
json.put("system_usedarktheme", prefs.getBoolean("system_usedarktheme", false)); |
|
|
|
json.put("system_dormantasinactive", prefs.getBoolean("system_dormantasinactive", false)); |
|
|
|
json.put("system_checkupdates", prefs.getBoolean("system_checkupdates", true)); |
|
|
|
json.put("system_autorefresh", prefs.getString("system_autorefresh", "0")); |
|
|
|
|
|
|
|
json.put("system_usedarktheme", prefs.getBoolean("system_usedarktheme", false)); |
|
|
|
return json; |
|
|
|
json.put("system_checkupdates", prefs.getBoolean("system_checkupdates", true)); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
return json; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|