From 691e2a1950e435be01efa8d2803a60c03201c0e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Christian=20Gr=C3=BCnhage?= Date: Fri, 30 Dec 2016 16:06:47 +0100 Subject: [PATCH 1/2] Extracted Strings and created a preference helper class and made use of it in the automation part of the app --- .../services/ExportAllJob.java | 20 ++--- .../services/ExportAllService.java | 12 ++- .../PlayMusicExporterPreferences.java | 79 +++++++++++++++++++ .../src/main/res/values/array.xml | 2 - .../src/main/res/values/strings.xml | 18 +++++ .../src/main/res/xml/pref_about.xml | 1 + .../src/main/res/xml/pref_automation.xml | 46 +++++++---- .../src/main/res/xml/pref_headers.xml | 2 +- 8 files changed, 141 insertions(+), 39 deletions(-) create mode 100644 playmusicexporter/src/main/java/re/jcg/playmusicexporter/settings/PlayMusicExporterPreferences.java diff --git a/playmusicexporter/src/main/java/re/jcg/playmusicexporter/services/ExportAllJob.java b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/services/ExportAllJob.java index abe15db..d5b0ffd 100644 --- a/playmusicexporter/src/main/java/re/jcg/playmusicexporter/services/ExportAllJob.java +++ b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/services/ExportAllJob.java @@ -31,18 +31,14 @@ public class ExportAllJob extends JobService { boolean lRequireCharging = lPreferences.getBoolean("settings", true); JobScheduler lJobScheduler = (JobScheduler) pContext.getSystemService(JOB_SCHEDULER_SERVICE); - if (lInterval == -1) { - lJobScheduler.cancel(42); - } else { - ComponentName lComponentName = new ComponentName(pContext, ExportAllJob.class); - JobInfo.Builder lBuilder = new JobInfo.Builder(42, lComponentName); - lBuilder.setPeriodic(lInterval); - lBuilder.setPersisted(true); - if (lRequireUnmeteredNetwork) - lBuilder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED); - lBuilder.setRequiresCharging(lRequireCharging); - lJobScheduler.schedule(lBuilder.build()); - } + ComponentName lComponentName = new ComponentName(pContext, ExportAllJob.class); + JobInfo.Builder lBuilder = new JobInfo.Builder(42, lComponentName); + lBuilder.setPeriodic(lInterval); + lBuilder.setPersisted(true); + if (lRequireUnmeteredNetwork) + lBuilder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED); + lBuilder.setRequiresCharging(lRequireCharging); + lJobScheduler.schedule(lBuilder.build()); } @Override diff --git a/playmusicexporter/src/main/java/re/jcg/playmusicexporter/services/ExportAllService.java b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/services/ExportAllService.java index 28794ff..ac72805 100644 --- a/playmusicexporter/src/main/java/re/jcg/playmusicexporter/services/ExportAllService.java +++ b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/services/ExportAllService.java @@ -3,14 +3,13 @@ package re.jcg.playmusicexporter.services; import android.app.IntentService; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.net.Uri; -import android.preference.PreferenceManager; import android.support.v4.provider.DocumentFile; import android.util.Log; import java.util.List; +import re.jcg.playmusicexporter.settings.PlayMusicExporterPreferences; import re.jcg.playmusicexporter.utils.MusicPathBuilder; import de.arcus.playmusiclib.PlayMusicManager; import de.arcus.playmusiclib.datasources.AlbumDataSource; @@ -50,7 +49,7 @@ public class ExportAllService extends IntentService { } private void export() { - SharedPreferences lPreferences = PreferenceManager.getDefaultSharedPreferences(this); + PlayMusicExporterPreferences.init(this); PlayMusicManager lPlayMusicManager = new PlayMusicManager(this); try { @@ -58,10 +57,9 @@ public class ExportAllService extends IntentService { } catch (PlayMusicNotFoundException | NoSuperUserException | CouldNotOpenDatabaseException e) { e.printStackTrace(); } - String lStringUri = lPreferences.getString("preference_export_tree_uri", null); - String lExportStructure = lPreferences.getString("preference_structure_alba", "{album-artist}/{album}/{disc=CD $}/{no=$$.} {title}.mp3"); - Log.i(TAG, lStringUri); - Uri lUri = Uri.parse(lStringUri); + Uri lUri = PlayMusicExporterPreferences.getConditionedAutoExportPath(); + String lExportStructure = PlayMusicExporterPreferences.getConditionedAutoExportStructure(); + Log.i(TAG, lUri.toString()); AlbumDataSource lAlbumDataSource = new AlbumDataSource(lPlayMusicManager); lAlbumDataSource.setOfflineOnly(true); List lAlba = lAlbumDataSource.getAll(); diff --git a/playmusicexporter/src/main/java/re/jcg/playmusicexporter/settings/PlayMusicExporterPreferences.java b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/settings/PlayMusicExporterPreferences.java new file mode 100644 index 0000000..fe8cb0b --- /dev/null +++ b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/settings/PlayMusicExporterPreferences.java @@ -0,0 +1,79 @@ +package re.jcg.playmusicexporter.settings; + + +import android.content.Context; +import android.content.SharedPreferences; +import android.net.Uri; +import android.preference.PreferenceManager; + +public class PlayMusicExporterPreferences { + private static SharedPreferences preferences; + + private static final String AUTO_EXPORT_USES_DIFFERENT_PATH = "preference_auto_export_use_different_path"; + private static final boolean AUTO_EXPORT_USES_DIFFERENT_PATH_DEFAULT = false; + private static final String AUTO_EXPORT_USES_DIFFERENT_STRUCTURE = "preference_auto_export_use_different_structure"; + private static final boolean AUTO_EXPORT_USES_DIFFERENT_STRUCTURE_DEFAULT = false; + + private static final String AUTO_EXPORT_PATH = "preference_auto_export_path"; + //TODO Split Export Paths in export prefs, this won't work else. + private static final String ALBA_EXPORT_PATH = "preference_alba_export_path"; + private static final String GROUP_EXPORT_PATH = "preference_group_export_path"; + private static final String URI_DEFAULT = Uri.EMPTY.toString(); + + private static final String AUTO_EXPORT_STRUCTURE = "preference_auto_export_structure"; + private static final String ALBA_EXPORT_STRUCTURE = "preference_auto_export_structure"; + private static final String EXPORT_STRUCTURE_DEFAULT = "{album-artist}/{album}/{disc=CD $}/{no=$$.} {title}.mp3"; + + + public static void init(Context pContext) { + preferences = PreferenceManager.getDefaultSharedPreferences(pContext); + } + + public static Uri getConditionedAutoExportPath() { + if (getAutoExportUsesDifferentPath()) { + return getAutoExportPath(); + } else { + return getAlbaExportPath(); + } + } + + public static boolean getAutoExportUsesDifferentPath() { + return preferences.getBoolean(AUTO_EXPORT_USES_DIFFERENT_PATH, AUTO_EXPORT_USES_DIFFERENT_PATH_DEFAULT); + } + + public static Uri getAutoExportPath() { + return getUri(AUTO_EXPORT_PATH); + } + + public static Uri getAlbaExportPath() { + return getUri(ALBA_EXPORT_PATH); + } + + public static Uri getGroupExportPath() { + return getUri(GROUP_EXPORT_PATH); + } + + private static Uri getUri(String key) { + return Uri.parse(preferences.getString(key, URI_DEFAULT)); + } + + public static String getConditionedAutoExportStructure() { + if (getAutoExportUsesDifferentStructure()) { + return getAutoExportStructure(); + } else { + return getAlbaExportStructure(); + } + } + + public static String getAlbaExportStructure() { + return preferences.getString(ALBA_EXPORT_STRUCTURE, EXPORT_STRUCTURE_DEFAULT); + } + + public static String getAutoExportStructure() { + return preferences.getString(AUTO_EXPORT_STRUCTURE, EXPORT_STRUCTURE_DEFAULT); + } + + public static boolean getAutoExportUsesDifferentStructure() { + return preferences.getBoolean(AUTO_EXPORT_USES_DIFFERENT_STRUCTURE, AUTO_EXPORT_USES_DIFFERENT_STRUCTURE_DEFAULT); + } +} diff --git a/playmusicexporter/src/main/res/values/array.xml b/playmusicexporter/src/main/res/values/array.xml index 727fcb8..c1bf411 100644 --- a/playmusicexporter/src/main/res/values/array.xml +++ b/playmusicexporter/src/main/res/values/array.xml @@ -6,7 +6,6 @@ Every Day Every 2 Days Every Week - Never 2160000 @@ -14,7 +13,6 @@ 86400000 172800000 604800000 - -1 diff --git a/playmusicexporter/src/main/res/values/strings.xml b/playmusicexporter/src/main/res/values/strings.xml index 5b7a770..de596d1 100644 --- a/playmusicexporter/src/main/res/values/strings.xml +++ b/playmusicexporter/src/main/res/values/strings.xml @@ -65,11 +65,25 @@ About me Thanks to About this version + Export conditions + Export path and subdirectory structure Debug + Version Number Build date + Enable automatic export + Require unmetered network? + Require charging? + Export interval + Use a different export path + Off means that the automatic export uses the same export path as alba. + Export path + Use a different subdirectory structure + Off means that the automatic export uses the same subdirectory structure as alba. + Subdirectory structure + Export Location Export Base Path Use / for a new folder \n Available Tags: \n - {album-artist} \n - {album} \n - {artist} \n - {title} \n - {disc=CD $} \n - {no=$$.} \n - {year} \n - {genre} \n @@ -108,10 +122,14 @@ %d tracks selected + Export Automation About + Debug + {album-artist}/{album}/{disc=CD $}/{no=$$.} {title}.mp3 {group}/{group-no=$$.} {artist} - {title}.mp3 + Trigger ExportAllService now diff --git a/playmusicexporter/src/main/res/xml/pref_about.xml b/playmusicexporter/src/main/res/xml/pref_about.xml index c3ce777..980a873 100644 --- a/playmusicexporter/src/main/res/xml/pref_about.xml +++ b/playmusicexporter/src/main/res/xml/pref_about.xml @@ -47,6 +47,7 @@ + - - + + + - + android:key="preference_auto_export_use_different_path" + android:summary="@string/settings_auto_export_different_path_switch_summary" + android:title="@string/settings_auto_export_different_path_switch" /> + + + + + + android:key="preference_auto_export_require_charging" + android:title="@string/settings_auto_export_require_charging_checkbox" /> - + android:key="preference_auto_export_require_unmetered" + android:title="@string/settings_auto_export_require_unmetered_checkbox" /> diff --git a/playmusicexporter/src/main/res/xml/pref_headers.xml b/playmusicexporter/src/main/res/xml/pref_headers.xml index 3dc99ac..9866a60 100644 --- a/playmusicexporter/src/main/res/xml/pref_headers.xml +++ b/playmusicexporter/src/main/res/xml/pref_headers.xml @@ -19,6 +19,6 @@
+ android:title="@string/pref_header_debug" /> From b190d510bae38bd92cf51316774b82e93e8d1c42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Christian=20Gr=C3=BCnhage?= Date: Fri, 30 Dec 2016 16:12:09 +0100 Subject: [PATCH 2/2] Added TODO to build.gradle --- framework/framework.iml | 16 ++++++++-------- playmusicexporter/build.gradle | 1 + playmusicexporter/playmusicexporter.iml | 16 ++++++++-------- playmusiclib/playmusiclib.iml | 16 ++++++++-------- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/framework/framework.iml b/framework/framework.iml index 4465d18..dad98d5 100644 --- a/framework/framework.iml +++ b/framework/framework.iml @@ -67,14 +67,6 @@ - - - - - - - - @@ -83,6 +75,14 @@ + + + + + + + + diff --git a/playmusicexporter/build.gradle b/playmusicexporter/build.gradle index 6f685fa..94f04e1 100644 --- a/playmusicexporter/build.gradle +++ b/playmusicexporter/build.gradle @@ -32,6 +32,7 @@ android { applicationId "re.jcg.playmusicexporter" minSdkVersion 21 targetSdkVersion 25 + // TODO Change Version with releases versionCode 102 versionName '2.4.2' vectorDrawables.useSupportLibrary = true diff --git a/playmusicexporter/playmusicexporter.iml b/playmusicexporter/playmusicexporter.iml index fc48e4c..9833dc1 100644 --- a/playmusicexporter/playmusicexporter.iml +++ b/playmusicexporter/playmusicexporter.iml @@ -66,14 +66,6 @@ - - - - - - - - @@ -82,6 +74,14 @@ + + + + + + + + diff --git a/playmusiclib/playmusiclib.iml b/playmusiclib/playmusiclib.iml index 11d5cb3..3b7fcb2 100644 --- a/playmusiclib/playmusiclib.iml +++ b/playmusiclib/playmusiclib.iml @@ -67,14 +67,6 @@ - - - - - - - - @@ -83,6 +75,14 @@ + + + + + + + +