From 87a80b4dd7b12a78b10e317f4f3ecddaf62f9971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Christian=20Gr=C3=BCnhage?= Date: Sun, 1 Jan 2017 19:37:12 +0100 Subject: [PATCH 1/4] Added exception type to the crash log, which was previously unavailable. The log in the crash handler now contains what kind of exception is being handled by the handler. --- .../main/java/de/arcus/framework/crashhandler/CrashHandler.java | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/src/main/java/de/arcus/framework/crashhandler/CrashHandler.java b/framework/src/main/java/de/arcus/framework/crashhandler/CrashHandler.java index 6315962..d4be390 100644 --- a/framework/src/main/java/de/arcus/framework/crashhandler/CrashHandler.java +++ b/framework/src/main/java/de/arcus/framework/crashhandler/CrashHandler.java @@ -77,6 +77,7 @@ public class CrashHandler implements Thread.UncaughtExceptionHandler { logBuilder.append("----------- Exception ------------\n"); logBuilder.append(ex.getMessage()).append("\n"); + logBuilder.append(ex.getClass().getCanonicalName()).append(" at \n"); // Log stack trace for (StackTraceElement stackTraceElement : ex.getStackTrace()) From 903a1162e705f92636d465b003e23958c86d889e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Christian=20Gr=C3=BCnhage?= Date: Sat, 14 Jan 2017 16:58:16 +0100 Subject: [PATCH 2/4] Continued work on new settings --- .idea/misc.xml | 2 +- framework/framework.iml | 16 ++--- playmusicexporter/playmusicexporter.iml | 20 +++--- .../activities/SettingsActivity.java | 71 ++++++++++++++++++- .../services/ExportAllJob.java | 15 ++-- .../services/ExportAllService.java | 12 ++++ .../PlayMusicExporterPreferences.java | 44 ++++++------ .../src/main/res/values-de/strings.xml | 4 +- .../src/main/res/values/strings.xml | 5 +- .../src/main/res/xml/pref_automation.xml | 7 +- .../src/main/res/xml/pref_export.xml | 4 +- .../arcus/playmusiclib/PlayMusicManager.java | 2 +- 12 files changed, 144 insertions(+), 58 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 5d19981..fbb6828 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -37,7 +37,7 @@ - + diff --git a/framework/framework.iml b/framework/framework.iml index dad98d5..4465d18 100644 --- a/framework/framework.iml +++ b/framework/framework.iml @@ -67,14 +67,6 @@ - - - - - - - - @@ -83,6 +75,14 @@ + + + + + + + + diff --git a/playmusicexporter/playmusicexporter.iml b/playmusicexporter/playmusicexporter.iml index fc48e4c..4fb6484 100644 --- a/playmusicexporter/playmusicexporter.iml +++ b/playmusicexporter/playmusicexporter.iml @@ -23,7 +23,7 @@ - + @@ -66,14 +66,6 @@ - - - - - - - - @@ -82,6 +74,14 @@ + + + + + + + + @@ -98,6 +98,7 @@ + @@ -126,6 +127,7 @@ + diff --git a/playmusicexporter/src/main/java/re/jcg/playmusicexporter/activities/SettingsActivity.java b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/activities/SettingsActivity.java index 7f8a356..faa4ca2 100644 --- a/playmusicexporter/src/main/java/re/jcg/playmusicexporter/activities/SettingsActivity.java +++ b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/activities/SettingsActivity.java @@ -13,13 +13,13 @@ import android.preference.Preference; import android.preference.PreferenceActivity; import android.support.v7.app.ActionBar; import android.preference.PreferenceFragment; -import android.preference.PreferenceManager; import android.util.Log; import android.view.MenuItem; import android.support.v4.app.NavUtils; import re.jcg.playmusicexporter.BuildConfig; import re.jcg.playmusicexporter.R; +import re.jcg.playmusicexporter.services.ExportAllJob; import re.jcg.playmusicexporter.services.ExportAllService; import re.jcg.playmusicexporter.settings.PlayMusicExporterPreferences; @@ -40,6 +40,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { private static final String TAG = "MusicExporter_Settings"; private static final int REQUEST_CODE_OPEN_DOCUMENT_TREE_ALBA_PATH = 0; private static final int REQUEST_CODE_OPEN_DOCUMENT_TREE_GROUPS_PATH = 1; + private static final int REQUEST_CODE_OPEN_DOCUMENT_TREE_AUTO_PATH = 2; /** * A preference value change listener that updates the preference's summary * to reflect its new value. @@ -129,7 +130,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { // Remove the Debug Fragment if (!BuildConfig.DEBUG) { for (int i = 0; i < target.size(); i++) { - if ("Debug".equals(target.get(i).title)){ + if ("Debug".equals(target.get(i).title)) { target.remove(i); break; } @@ -214,11 +215,77 @@ public class SettingsActivity extends AppCompatPreferenceActivity { } public static class AutomationPreferenceFragment extends PreferenceFragment { + + + /** + * Little helper method to get the context. + * If the Android version is high enough, the newer {@link PreferenceFragment#getContext()} is used, + * else, the older {@link PreferenceFragment#getActivity()}, since activities are contexts too. + * + * @return The context. + */ + @Override + public Context getContext() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + return super.getContext(); + } else { + return super.getActivity(); + } + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.pref_automation); setHasOptionsMenu(true); + //Schedules an export with the current settings. + ExportAllJob.scheduleExport(getContext()); + + setupOnClickListeners(); + } + + private void setupOnClickListeners() { + findPreference(PlayMusicExporterPreferences.AUTO_EXPORT_PATH).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + startActivityForResult(new Intent("android.intent.action.OPEN_DOCUMENT_TREE"), REQUEST_CODE_OPEN_DOCUMENT_TREE_AUTO_PATH); + return true; + } + }); + + //For every setting that is used to define the export job, setup a listener that + setupRescheduler(PlayMusicExporterPreferences.AUTO_EXPORT_REQUIRE_CHARGING); + setupRescheduler(PlayMusicExporterPreferences.AUTO_EXPORT_REQUIRE_UNMETERED); + setupRescheduler(PlayMusicExporterPreferences.AUTO_EXPORT_ENABLED); + setupRescheduler(PlayMusicExporterPreferences.AUTO_EXPORT_FREQUENCY); + } + + private void setupRescheduler(String preference) { + findPreference(preference).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + ExportAllJob.scheduleExport(getContext()); + return false; + } + }); + } + + public void onActivityResult(int requestCode, int resultCode, Intent resultData) { + switch (requestCode) { + case REQUEST_CODE_OPEN_DOCUMENT_TREE_AUTO_PATH: + if (resultCode == RESULT_OK) { + Uri treeUri = resultData.getData(); + PlayMusicExporterPreferences.init(getActivity()); + PlayMusicExporterPreferences.setAutoExportPath(treeUri); + getActivity().getContentResolver().takePersistableUriPermission(treeUri, + Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + Log.i(TAG, "Selected " + treeUri.toString()); + } + break; + default: + Log.i(TAG, "Received activityResult with unknown requestCode"); + + } } @Override 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 6b93a58..9d2fd31 100644 --- a/playmusicexporter/src/main/java/re/jcg/playmusicexporter/services/ExportAllJob.java +++ b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/services/ExportAllJob.java @@ -6,7 +6,6 @@ import android.app.job.JobScheduler; import android.app.job.JobService; import android.content.ComponentName; import android.content.Context; -import android.content.SharedPreferences; import android.util.Log; import re.jcg.playmusicexporter.settings.PlayMusicExporterPreferences; @@ -15,17 +14,13 @@ public class ExportAllJob extends JobService { public static final String TAG = "AutoGPME_ExportJob"; + /** + * Schedules an export with the current settings + * + * @param pContext + */ public static void scheduleExport(final Context pContext) { PlayMusicExporterPreferences.init(pContext); - PlayMusicExporterPreferences.registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener() { - @Override - public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - if (key.contains("auto")) { - scheduleExport(pContext); - Log.i(TAG, "Preference changed: " + key); - } - } - }); if (PlayMusicExporterPreferences.getAutoExportEnabled()) { long lInterval = PlayMusicExporterPreferences.getAutoExportFrequency(); boolean lRequireUnmeteredNetwork = PlayMusicExporterPreferences.getAutoExportRequireUnmetered(); 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 ac72805..053c4b3 100644 --- a/playmusicexporter/src/main/java/re/jcg/playmusicexporter/services/ExportAllService.java +++ b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/services/ExportAllService.java @@ -67,6 +67,18 @@ public class ExportAllService extends IntentService { for (MusicTrack lTrack : lAlbum.getMusicTrackList()) { if (lTrack.isOfflineAvailable()) { String lPath = MusicPathBuilder.Build(lTrack, lExportStructure); + try { + + } catch (IllegalArgumentException e) { + if (e.getMessage().contains("Invalid URI:")) { + /* + TODO: Make it impossible to reach this point + This happens when the user has not yet set the export path. + + */ + Log.i(TAG, "Automatic export failed, because the URI is invalid."); + } else throw e; + } if (!isAlreadyThere(lUri, lPath)) { if (lPlayMusicManager.exportMusicTrack(lTrack, lUri, lPath)) { Log.i(TAG, "Exported Music Track: " + getStringForTrack(lTrack)); diff --git a/playmusicexporter/src/main/java/re/jcg/playmusicexporter/settings/PlayMusicExporterPreferences.java b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/settings/PlayMusicExporterPreferences.java index edb53d1..855cb69 100644 --- a/playmusicexporter/src/main/java/re/jcg/playmusicexporter/settings/PlayMusicExporterPreferences.java +++ b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/settings/PlayMusicExporterPreferences.java @@ -11,33 +11,33 @@ import re.jcg.playmusicexporter.fragments.NavigationDrawerFragment; public class PlayMusicExporterPreferences { private static SharedPreferences preferences; - private static final String AUTO_EXPORT_ENABLED = "preference_auto_export_enabled"; - private static final boolean AUTO_EXPORT_ENABLED_DEFAULT = false; - 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_FREQUENCY = "preference_auto_export_frequency"; - private static final String AUTO_EXPORT_FREQUENCY_DEFAULT = "86400000"; + public static final String AUTO_EXPORT_ENABLED = "preference_auto_export_enabled"; + public static final boolean AUTO_EXPORT_ENABLED_DEFAULT = false; + public static final String AUTO_EXPORT_USES_DIFFERENT_PATH = "preference_auto_export_use_different_path"; + public static final boolean AUTO_EXPORT_USES_DIFFERENT_PATH_DEFAULT = false; + public static final String AUTO_EXPORT_USES_DIFFERENT_STRUCTURE = "preference_auto_export_use_different_structure"; + public static final boolean AUTO_EXPORT_USES_DIFFERENT_STRUCTURE_DEFAULT = false; + public static final String AUTO_EXPORT_FREQUENCY = "preference_auto_export_frequency"; + public static final String AUTO_EXPORT_FREQUENCY_DEFAULT = "86400000"; public static final String AUTO_EXPORT_REQUIRE_CHARGING = "preference_auto_export_require_charging"; public static final String AUTO_EXPORT_REQUIRE_UNMETERED = "preference_auto_export_require_unmetered"; public static final boolean AUTO_EXPORT_REQUIRE_CONDITION_DEFAULT = false; - private static final String AUTO_EXPORT_PATH = "preference_auto_export_path"; + public 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 GROUPS_EXPORT_PATH = "preference_groups_export_path"; - private static final String URI_DEFAULT = Uri.EMPTY.toString(); + public static final String ALBA_EXPORT_PATH = "preference_alba_export_path"; + public static final String GROUPS_EXPORT_PATH = "preference_groups_export_path"; + public 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_alba_export_structure"; - private static final String GROUPS_EXPORT_STRUCTURE = "preference_groups_export_structure"; - private static final String EXPORT_STRUCTURE_DEFAULT = "{album-artist}/{album}/{disc=CD $}/{no=$$.} {title}.mp3"; + public static final String AUTO_EXPORT_STRUCTURE = "preference_auto_export_structure"; + public static final String ALBA_EXPORT_STRUCTURE = "preference_alba_export_structure"; + public static final String GROUPS_EXPORT_STRUCTURE = "preference_groups_export_structure"; + public static final String EXPORT_STRUCTURE_DEFAULT = "{album-artist}/{album}/{disc=CD $}/{no=$$.} {title}.mp3"; - private static final String DRAWER_LEARNED = "pref_drawer_learned"; - private static final boolean DRAWER_LEARNED_DEFAULT = false; - private static final String DRAWER_SELECTED_TYPE = "pref_drawer_selected_type"; - private static final String DRAWER_SELECTED_TYPE_DEFAULT = "Album"; + public static final String DRAWER_LEARNED = "pref_drawer_learned"; + public static final boolean DRAWER_LEARNED_DEFAULT = false; + public static final String DRAWER_SELECTED_TYPE = "pref_drawer_selected_type"; + public static final String DRAWER_SELECTED_TYPE_DEFAULT = "Album"; private PlayMusicExporterPreferences() { @@ -141,4 +141,8 @@ public class PlayMusicExporterPreferences { public static boolean getAutoExportRequireCharging() { return preferences.getBoolean(AUTO_EXPORT_REQUIRE_CHARGING, AUTO_EXPORT_REQUIRE_CONDITION_DEFAULT); } + + public static void setAutoExportPath(Uri treeUri) { + preferences.edit().putString(AUTO_EXPORT_PATH, treeUri.toString()).apply(); + } } diff --git a/playmusicexporter/src/main/res/values-de/strings.xml b/playmusicexporter/src/main/res/values-de/strings.xml index a24989e..d7bc129 100644 --- a/playmusicexporter/src/main/res/values-de/strings.xml +++ b/playmusicexporter/src/main/res/values-de/strings.xml @@ -73,10 +73,10 @@ Spende an David Schulte via PayPal Unterstützt den ursprünglichen Entwickler Verzeichnisbaum für Alben - Setze den Verzeichnisbaum + Setze den Verzeichnisbaum Beispiel: Beatles/Help!/13. Yesterday.mp3 "Nutze / für einen neuen Order. Available Tags: - {album-artist} - {album} - {artist} - {title} - {disc=CD $} - {no=$$.} - {year} - {genre} " - Setze den Verzeichnisbaum + Setze den Verzeichnisbaum Beispiel: Great Songs/4. Beatles - Yesterday.mp3 Versionsnummer Jetzt den ExportAllService starten diff --git a/playmusicexporter/src/main/res/values/strings.xml b/playmusicexporter/src/main/res/values/strings.xml index 9984a2b..81f1791 100644 --- a/playmusicexporter/src/main/res/values/strings.xml +++ b/playmusicexporter/src/main/res/values/strings.xml @@ -85,6 +85,7 @@ Use a different subdirectory structure Off means that the automatic export uses the same subdirectory structure as alba. Subdirectory structure + Subdirectory structure Export Location Export Base Path @@ -93,12 +94,12 @@ Export path for alba Subdirectory structure for albums - Set your subdirectory structure + Set your subdirectory structure Example: Beatles/Help!/13. Yesterday.mp3 Export path for groups Subdirectory structure for playlists - Set your subdirectory structure + Set your subdirectory structure Example: Great Songs/4. Beatles - Yesterday.mp3 ID3 Tags diff --git a/playmusicexporter/src/main/res/xml/pref_automation.xml b/playmusicexporter/src/main/res/xml/pref_automation.xml index b724a24..ce9956a 100644 --- a/playmusicexporter/src/main/res/xml/pref_automation.xml +++ b/playmusicexporter/src/main/res/xml/pref_automation.xml @@ -20,8 +20,13 @@ android:key="preference_auto_export_use_different_structure" android:summary="@string/settings_auto_export_different_structure_switch_summary" android:title="@string/settings_auto_export_different_structure_switch" /> - diff --git a/playmusicexporter/src/main/res/xml/pref_export.xml b/playmusicexporter/src/main/res/xml/pref_export.xml index 1512d53..ffd2ae4 100644 --- a/playmusicexporter/src/main/res/xml/pref_export.xml +++ b/playmusicexporter/src/main/res/xml/pref_export.xml @@ -9,7 +9,7 @@ Date: Thu, 19 Jan 2017 00:42:22 +0100 Subject: [PATCH 3/4] Added Translation, moved code in ExportAllService, try catch was not trying anything. --- framework/framework.iml | 22 +++++++------------ playmusicexporter/playmusicexporter.iml | 6 ----- .../services/ExportAllService.java | 19 ++++++++-------- .../src/main/res/values-de/strings.xml | 1 + 4 files changed, 18 insertions(+), 30 deletions(-) diff --git a/framework/framework.iml b/framework/framework.iml index dad98d5..9a58259 100644 --- a/framework/framework.iml +++ b/framework/framework.iml @@ -9,7 +9,6 @@ @@ -48,7 +47,6 @@ - @@ -56,7 +54,6 @@ - @@ -64,25 +61,22 @@ - - - - - - - - - - + + + + + + + diff --git a/playmusicexporter/playmusicexporter.iml b/playmusicexporter/playmusicexporter.iml index ba68838..168f989 100644 --- a/playmusicexporter/playmusicexporter.iml +++ b/playmusicexporter/playmusicexporter.iml @@ -9,7 +9,6 @@