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/src/main/java/de/arcus/framework/settings/AppSettings.java b/framework/src/main/java/de/arcus/framework/settings/AppSettings.java
deleted file mode 100644
index 109df5b..0000000
--- a/framework/src/main/java/de/arcus/framework/settings/AppSettings.java
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
- * Copyright (c) 2015 David Schulte
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-package de.arcus.framework.settings;
-
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.net.Uri;
-
-/**
- * Helper class to read and write app settings without to care about to open and close an editor
- */
-public class AppSettings {
- /**
- * The default settings file
- */
- public static final String DEFAULT_SETTINGS_FILENAME = "app_settings";
-
- /**
- * The preferences
- */
- private SharedPreferences mSharedPreferences;
-
- /**
- * Creates a new instance of AppSettings that access to the default settings file
- * @param context Context of the app
- */
- public AppSettings(Context context) {
- this(context, DEFAULT_SETTINGS_FILENAME);
- }
-
- /**
- * Creates a new instance of AppSettings that access to a specific settings file
- * @param context Context of the app
- */
- public AppSettings(Context context, String settingsFilename) {
- mSharedPreferences = context.getSharedPreferences(settingsFilename, Context.MODE_PRIVATE);
- }
-
- /**
- * Gets a string from the settings
- * @param key Key of the setting
- * @param defValue Default value which is returned if the key doesn't exists
- * @return Value
- */
- public String getString(String key, String defValue) {
- return mSharedPreferences.getString(key, defValue);
- }
-
- /**
- * Gets a boolean from the settings
- * @param key Key of the setting
- * @param defValue Default value which is returned if the key doesn't exists
- * @return Value
- */
- public boolean getBoolean(String key, boolean defValue) {
- return mSharedPreferences.getBoolean(key, defValue);
- }
-
- /**
- * Gets a float from the settings
- * @param key Key of the setting
- * @param defValue Default value which is returned if the key doesn't exists
- * @return Value
- */
- public float getFloat(String key, float defValue) {
- return mSharedPreferences.getFloat(key, defValue);
- }
-
- /**
- * Gets an int from the settings
- * @param key Key of the setting
- * @param defValue Default value which is returned if the key doesn't exists
- * @return Value
- */
- public int getInt(String key, int defValue) {
- return mSharedPreferences.getInt(key, defValue);
- }
-
- /**
- * Gets a long from the settings
- * @param key Key of the setting
- * @param defValue Default value which is returned if the key doesn't exists
- * @return Value
- */
- public long getLong(String key, long defValue) {
- return mSharedPreferences.getLong(key, defValue);
- }
-
- /**
- * Gets a uri from the settings
- * @param key Key of the setting
- * @param defValue Default value which is returned if the key doesn't exists
- * @return Value
- */
- public Uri getUri(String key, Uri defValue) {
- if (mSharedPreferences.contains(key))
- return Uri.parse(mSharedPreferences.getString(key, ""));
- else return defValue;
- }
-
- /**
- * Gets an enum value from the settings
- * @param key Key of the setting
- * @param defValue Default value which is returned if the key doesn't exists
- * @param The enum type
- * @return Value
- */
- public > E getEnum(String key, E defValue) {
- String value = mSharedPreferences.getString(key, defValue.name());
-
- // Null check
- if (value != null) {
- // Checks all enum values
- for (E constant : defValue.getDeclaringClass().getEnumConstants()) {
- if (value.equals(constant.name()))
- return constant;
- }
- }
- // Return default
- return defValue;
- }
-
- /**
- * Returns whether the settings contains a specific key
- * @param key Key of the setting
- * @return Returns whether the settings contains a specific key
- */
- public boolean contains(String key) {
- return mSharedPreferences.contains(key);
- }
-
- /**
- * Removes an setting from the settings
- * @param key Key of the setting
- */
- public void remove(String key) {
- // Opens the editor
- SharedPreferences.Editor editor = mSharedPreferences.edit();
-
- // Removes the key
- editor.remove(key);
-
- // Commits the change
- editor.commit();
- }
-
- /**
- * Saves a string to the settings
- * @param key Key of the setting
- * @param value Value
- */
- public void setString(String key, String value) {
- // Opens the editor
- SharedPreferences.Editor editor = mSharedPreferences.edit();
-
- editor.putString(key, value);
-
- // Commits the change
- editor.commit();
- }
-
- /**
- * Saves a boolean to the settings
- * @param key Key of the setting
- * @param value Value
- */
- public void setBoolean(String key, boolean value) {
- // Opens the editor
- SharedPreferences.Editor editor = mSharedPreferences.edit();
-
- editor.putBoolean(key, value);
-
- // Commits the change
- editor.commit();
- }
-
- /**
- * Saves a float to the settings
- * @param key Key of the setting
- * @param value Value
- */
- public void setFloat(String key, float value) {
- // Opens the editor
- SharedPreferences.Editor editor = mSharedPreferences.edit();
-
- editor.putFloat(key, value);
-
- // Commits the change
- editor.commit();
- }
-
- /**
- * Saves an int to the settings
- * @param key Key of the setting
- * @param value Value
- */
- public void setInt(String key, int value) {
- // Opens the editor
- SharedPreferences.Editor editor = mSharedPreferences.edit();
-
- editor.putInt(key, value);
-
- // Commits the change
- editor.commit();
- }
-
- /**
- * Saves a long to the settings
- * @param key Key of the setting
- * @param value Value
- */
- public void setLong(String key, long value) {
- // Opens the editor
- SharedPreferences.Editor editor = mSharedPreferences.edit();
-
- editor.putLong(key, value);
-
- // Commits the change
- editor.commit();
- }
-
- /**
- * Saves a uri to the settings
- * @param key Key of the setting
- * @param value Value
- */
- public void setUri(String key, Uri value) {
- // Opens the editor
- SharedPreferences.Editor editor = mSharedPreferences.edit();
-
- editor.putString(key, value.toString());
-
- // Commits the change
- editor.commit();
- }
-
- /**
- * Saves an enum value to the settings
- * @param key Key of the setting
- * @param value Value
- */
- public > void setEnum(String key, E value) {
- // Opens the editor
- SharedPreferences.Editor editor = mSharedPreferences.edit();
-
- editor.putString(key, value.name());
-
- // Commits the change
- editor.commit();
- }
-}
diff --git a/playmusicexporter/playmusicexporter.iml b/playmusicexporter/playmusicexporter.iml
index 9833dc1..fc48e4c 100644
--- a/playmusicexporter/playmusicexporter.iml
+++ b/playmusicexporter/playmusicexporter.iml
@@ -66,14 +66,6 @@
-
-
-
-
-
-
-
-
@@ -82,6 +74,14 @@
+
+
+
+
+
+
+
+
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 6c7bf76..7f8a356 100644
--- a/playmusicexporter/src/main/java/re/jcg/playmusicexporter/activities/SettingsActivity.java
+++ b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/activities/SettingsActivity.java
@@ -5,8 +5,6 @@ import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
-import android.media.Ringtone;
-import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@@ -16,8 +14,6 @@ import android.preference.PreferenceActivity;
import android.support.v7.app.ActionBar;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
-import android.preference.RingtonePreference;
-import android.text.TextUtils;
import android.util.Log;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
@@ -25,11 +21,10 @@ import android.support.v4.app.NavUtils;
import re.jcg.playmusicexporter.BuildConfig;
import re.jcg.playmusicexporter.R;
import re.jcg.playmusicexporter.services.ExportAllService;
+import re.jcg.playmusicexporter.settings.PlayMusicExporterPreferences;
import java.util.List;
-import static android.os.Build.VERSION_CODES.LOLLIPOP;
-
/**
* A {@link PreferenceActivity} that presents a set of application settings. On
* handset devices, settings are presented as a single list. On tablets,
@@ -43,7 +38,8 @@ import static android.os.Build.VERSION_CODES.LOLLIPOP;
*/
public class SettingsActivity extends AppCompatPreferenceActivity {
private static final String TAG = "MusicExporter_Settings";
- private static final int OPEN_DOCUMENT_TREE_REQUEST_CODE = 0;
+ private static final int REQUEST_CODE_OPEN_DOCUMENT_TREE_ALBA_PATH = 0;
+ private static final int REQUEST_CODE_OPEN_DOCUMENT_TREE_GROUPS_PATH = 1;
/**
* A preference value change listener that updates the preference's summary
* to reflect its new value.
@@ -84,26 +80,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
& Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
}
- /**
- * Binds a preference's summary to its value. More specifically, when the
- * preference's value is changed, its summary (line of text below the
- * preference title) is updated to reflect the value. The summary is also
- * immediately updated upon calling this method. The exact display format is
- * dependent on the type of preference.
- *
- * @see #sBindPreferenceSummaryToValueListener
- */
- private static void bindPreferenceSummaryToValue(Preference preference) {
- // Set the listener to watch for value changes.
- preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
-
- // Trigger the listener immediately with the preference's
- // current value.
- sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
- PreferenceManager
- .getDefaultSharedPreferences(preference.getContext())
- .getString(preference.getKey(), ""));
- }
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -174,6 +150,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
}
public static class ExportPreferenceFragment extends PreferenceFragment {
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -181,10 +158,17 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
setHasOptionsMenu(true);
- findPreference("preference_export_path").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+ findPreference("preference_alba_export_path").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
- startActivityForResult(new Intent("android.intent.action.OPEN_DOCUMENT_TREE"), OPEN_DOCUMENT_TREE_REQUEST_CODE);
+ startActivityForResult(new Intent("android.intent.action.OPEN_DOCUMENT_TREE"), REQUEST_CODE_OPEN_DOCUMENT_TREE_ALBA_PATH);
+ return true;
+ }
+ });
+ findPreference("preference_groups_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_GROUPS_PATH);
return true;
}
});
@@ -192,10 +176,21 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
switch (requestCode) {
- case OPEN_DOCUMENT_TREE_REQUEST_CODE:
+ case REQUEST_CODE_OPEN_DOCUMENT_TREE_ALBA_PATH:
if (resultCode == RESULT_OK) {
Uri treeUri = resultData.getData();
- PreferenceManager.getDefaultSharedPreferences(getActivity()).edit().putString("preference_export_tree_uri", treeUri.toString()).apply();
+ PlayMusicExporterPreferences.init(getActivity());
+ PlayMusicExporterPreferences.setAlbaExportPath(treeUri);
+ getActivity().getContentResolver().takePersistableUriPermission(treeUri,
+ Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+ Log.i(TAG, "Selected " + treeUri.toString());
+ }
+ break;
+ case REQUEST_CODE_OPEN_DOCUMENT_TREE_GROUPS_PATH:
+ if (resultCode == RESULT_OK) {
+ Uri treeUri = resultData.getData();
+ PlayMusicExporterPreferences.init(getActivity());
+ PlayMusicExporterPreferences.setGroupsExportPath(treeUri);
getActivity().getContentResolver().takePersistableUriPermission(treeUri,
Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
Log.i(TAG, "Selected " + treeUri.toString());
diff --git a/playmusicexporter/src/main/java/re/jcg/playmusicexporter/fragments/MusicTrackListFragment.java b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/fragments/MusicTrackListFragment.java
index 6c04823..29874f2 100644
--- a/playmusicexporter/src/main/java/re/jcg/playmusicexporter/fragments/MusicTrackListFragment.java
+++ b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/fragments/MusicTrackListFragment.java
@@ -22,10 +22,8 @@
package re.jcg.playmusicexporter.fragments;
-import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
-import android.preference.PreferenceManager;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
@@ -44,7 +42,7 @@ import re.jcg.playmusicexporter.activities.MusicTrackListActivity;
import re.jcg.playmusicexporter.adapter.MusicTrackListAdapter;
import re.jcg.playmusicexporter.items.SelectedTrack;
import re.jcg.playmusicexporter.items.SelectedTrackList;
-import re.jcg.playmusicexporter.settings.PlayMusicExporterSettings;
+import re.jcg.playmusicexporter.settings.PlayMusicExporterPreferences;
import re.jcg.playmusicexporter.utils.ArtworkViewLoader;
import re.jcg.playmusicexporter.utils.MusicPathBuilder;
import de.arcus.playmusiclib.PlayMusicManager;
@@ -113,7 +111,7 @@ public class MusicTrackListFragment extends Fragment {
*/
public void selectAll() {
// Select all tracks
- for(int i = 0; i < mMusicTrackAdapter.getCount(); i++ ) {
+ for (int i = 0; i < mMusicTrackAdapter.getCount(); i++) {
MusicTrack musicTrack = mMusicTrackAdapter.getItem(i);
selectTrack(musicTrack, null, TrackSelectionState.Select);
@@ -127,7 +125,7 @@ public class MusicTrackListFragment extends Fragment {
*/
public void deselectAll() {
// Deselect all tracks
- for(int i = 0; i < mMusicTrackAdapter.getCount(); i++ ) {
+ for (int i = 0; i < mMusicTrackAdapter.getCount(); i++) {
MusicTrack musicTrack = mMusicTrackAdapter.getItem(i);
selectTrack(musicTrack, null, TrackSelectionState.Deselect);
@@ -141,7 +139,7 @@ public class MusicTrackListFragment extends Fragment {
super.onCreate(savedInstanceState);
if (getArguments().containsKey(ARG_MUSIC_TRACK_LIST_ID)
- && getArguments().containsKey(ARG_MUSIC_TRACK_LIST_TYPE)) {
+ && getArguments().containsKey(ARG_MUSIC_TRACK_LIST_TYPE)) {
// Loads the track list
long id = getArguments().getLong(ARG_MUSIC_TRACK_LIST_ID);
@@ -162,7 +160,7 @@ public class MusicTrackListFragment extends Fragment {
// Show the dummy content as text in a TextView.
if (mMusicTrackList != null) {
- mListView = (ListView)rootView.findViewById(R.id.list_music_track);
+ mListView = (ListView) rootView.findViewById(R.id.list_music_track);
mMusicTrackAdapter = new MusicTrackListAdapter(getActivity());
mMusicTrackAdapter.setShowArtworks(mMusicTrackList.getShowArtworkInTrack());
@@ -174,17 +172,17 @@ public class MusicTrackListFragment extends Fragment {
ImageView imageView;
// Sets the artwork image
- imageView = (ImageView)headerView.findViewById(R.id.image_music_track_artwork);
+ imageView = (ImageView) headerView.findViewById(R.id.image_music_track_artwork);
// Loads the artwork
ArtworkViewLoader.loadImage(mMusicTrackList, imageView, R.drawable.cd_case);
// Sets the title
- textView = (TextView)headerView.findViewById(R.id.text_music_track_list_title);
+ textView = (TextView) headerView.findViewById(R.id.text_music_track_list_title);
textView.setText(mMusicTrackList.getTitle());
// Sets the description
- textView = (TextView)headerView.findViewById(R.id.text_music_track_list_description);
+ textView = (TextView) headerView.findViewById(R.id.text_music_track_list_description);
textView.setText(mMusicTrackList.getDescription());
mListView.addHeaderView(headerView);
@@ -212,12 +210,12 @@ public class MusicTrackListFragment extends Fragment {
});
// The floating action button
- mFloatingButtonExport = (FloatingActionButton)rootView.findViewById(R.id.floating_button_export);
+ mFloatingButtonExport = (FloatingActionButton) rootView.findViewById(R.id.floating_button_export);
mFloatingButtonExport.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Export all selected tracks
- for(SelectedTrack selectedTrack : SelectedTrackList.getInstance().getSelectedItems()) {
+ for (SelectedTrack selectedTrack : SelectedTrackList.getInstance().getSelectedItems()) {
selectedTrack.export(getActivity());
}
@@ -231,33 +229,37 @@ public class MusicTrackListFragment extends Fragment {
return rootView;
}
- private enum TrackSelectionState { Deselect, Select, Toggle }
+ private enum TrackSelectionState {Deselect, Select, Toggle}
/**
* Select a track
+ *
* @param musicTrack The track
- * @param view The view
- * @param state Selection state
+ * @param view The view
+ * @param state Selection state
*/
private void selectTrack(MusicTrack musicTrack, View view, TrackSelectionState state) {
// Track is available
if (musicTrack.isOfflineAvailable()) {
- SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+ PlayMusicExporterPreferences.init(getContext());
- // Default structure
- String pathStructure = preferences.getString("preference_structure_alba", "{album-artist}/{album}/{disc=CD $}/{no=$$.} {title}.mp3");
+ //Creating Variables
+ String pathStructure;
+ Uri uri;
// Track is exported from a group (playlist or artist)
- if (!TextUtils.isEmpty(musicTrack.getContainerName())) {
- pathStructure = preferences.getString("preference_structure_groups", "{group}/{group-no=$$.} {artist} - {title}.mp3");
+ if (TextUtils.isEmpty(musicTrack.getContainerName())) {
+ pathStructure = PlayMusicExporterPreferences.getAlbaExportStructure();
+ uri = PlayMusicExporterPreferences.getAlbaExportPath();
+ } else {
+ pathStructure = PlayMusicExporterPreferences.getGroupsExportStructure();
+ uri = PlayMusicExporterPreferences.getGroupsExportPath();
}
// Build the path
String path = MusicPathBuilder.Build(musicTrack, pathStructure);
- // Gets the root uri
- Uri uri = Uri.parse(preferences.getString("preference_export_tree_uri", Uri.EMPTY.toString()));
// Prevent the closing
diff --git a/playmusicexporter/src/main/java/re/jcg/playmusicexporter/fragments/NavigationDrawerFragment.java b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/fragments/NavigationDrawerFragment.java
index c9f16da..321dd89 100644
--- a/playmusicexporter/src/main/java/re/jcg/playmusicexporter/fragments/NavigationDrawerFragment.java
+++ b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/fragments/NavigationDrawerFragment.java
@@ -23,6 +23,7 @@
package re.jcg.playmusicexporter.fragments;
import android.app.Activity;
+import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.PorterDuff;
@@ -44,7 +45,7 @@ import android.widget.Button;
import re.jcg.playmusicexporter.R;
import re.jcg.playmusicexporter.activities.SettingsActivity;
-import re.jcg.playmusicexporter.settings.PlayMusicExporterSettings;
+import re.jcg.playmusicexporter.settings.PlayMusicExporterPreferences;
/**
* Fragment used for managing interactions for and presentation of a navigation drawer.
@@ -74,7 +75,15 @@ public class NavigationDrawerFragment extends Fragment {
private Button mButtonSettings;
public enum ViewType {
- Album, Artist, Playlist, Rated
+ Album, Artist, Playlist, Rated;
+
+ public static ViewType fromName(String name) {
+ for (ViewType type : values()) {
+ if (type.name().equals(name)) return type;
+ }
+ return Album;
+ }
+
}
private ViewType mViewType;
@@ -103,8 +112,8 @@ public class NavigationDrawerFragment extends Fragment {
mViewType = viewType;
// Save the selection
- PlayMusicExporterSettings appSettings = new PlayMusicExporterSettings(getActivity());
- appSettings.setEnum(PlayMusicExporterSettings.PREF_DRAWER_SELECTED_TYPE, viewType);
+ PlayMusicExporterPreferences.init(getContext());
+ PlayMusicExporterPreferences.setDrawerViewType(viewType);
// Close the drawer
if (mDrawerLayout != null)
@@ -119,9 +128,9 @@ public class NavigationDrawerFragment extends Fragment {
super.onCreate(savedInstanceState);
// Load the settings
- PlayMusicExporterSettings appSettings = new PlayMusicExporterSettings(getActivity());
- mUserLearnedDrawer = appSettings.getBoolean(PlayMusicExporterSettings.PREF_DRAWER_LEARNED, false);
- mViewType = appSettings.getEnum(PlayMusicExporterSettings.PREF_DRAWER_SELECTED_TYPE, ViewType.Album);
+ PlayMusicExporterPreferences.init(getContext());
+ mUserLearnedDrawer = PlayMusicExporterPreferences.getDrawerLearned();
+ mViewType = PlayMusicExporterPreferences.getDrawerViewType();
}
@@ -140,12 +149,12 @@ public class NavigationDrawerFragment extends Fragment {
R.layout.fragment_navigation_drawer, container, false);
// Gets all buttons
- mButtonTypeAlbum = (Button)view.findViewById(R.id.button_type_album);
- mButtonTypeArtist = (Button)view.findViewById(R.id.button_type_artist);
- mButtonTypePlaylist = (Button)view.findViewById(R.id.button_type_playlist);
- mButtonTypeRated = (Button)view.findViewById(R.id.button_type_rated);
+ mButtonTypeAlbum = (Button) view.findViewById(R.id.button_type_album);
+ mButtonTypeArtist = (Button) view.findViewById(R.id.button_type_artist);
+ mButtonTypePlaylist = (Button) view.findViewById(R.id.button_type_playlist);
+ mButtonTypeRated = (Button) view.findViewById(R.id.button_type_rated);
- mButtonSettings = (Button)view.findViewById(R.id.button_setting);
+ mButtonSettings = (Button) view.findViewById(R.id.button_setting);
// Set the default
setViewType(mViewType);
@@ -202,6 +211,7 @@ public class NavigationDrawerFragment extends Fragment {
/**
* Format the button
+ *
* @param button The button
* @param active Active
*/
@@ -282,8 +292,8 @@ public class NavigationDrawerFragment extends Fragment {
// The user manually opened the drawer; store this flag to prevent auto-showing
// the navigation drawer automatically in the future.
mUserLearnedDrawer = true;
- PlayMusicExporterSettings appSettings = new PlayMusicExporterSettings(getActivity());
- appSettings.setBoolean(PlayMusicExporterSettings.PREF_DRAWER_LEARNED, mUserLearnedDrawer);
+ PlayMusicExporterPreferences.init(getContext());
+ PlayMusicExporterPreferences.setDrawerLearned(mUserLearnedDrawer);
}
getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu()
@@ -308,10 +318,10 @@ public class NavigationDrawerFragment extends Fragment {
}
@Override
- public void onAttach(Activity activity) {
- super.onAttach(activity);
+ public void onAttach(Context context) {
+ super.onAttach(context);
try {
- mCallbacks = (NavigationDrawerCallbacks) activity;
+ mCallbacks = (NavigationDrawerCallbacks) context;
} catch (ClassCastException e) {
throw new ClassCastException("Activity must implement NavigationDrawerCallbacks.");
}
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 d5b0ffd..6b93a58 100644
--- a/playmusicexporter/src/main/java/re/jcg/playmusicexporter/services/ExportAllJob.java
+++ b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/services/ExportAllJob.java
@@ -7,38 +7,40 @@ import android.app.job.JobService;
import android.content.ComponentName;
import android.content.Context;
import android.content.SharedPreferences;
-import android.os.Build;
-import android.preference.PreferenceManager;
-import android.support.annotation.RequiresApi;
import android.util.Log;
+import re.jcg.playmusicexporter.settings.PlayMusicExporterPreferences;
+
public class ExportAllJob extends JobService {
public static final String TAG = "AutoGPME_ExportJob";
public static void scheduleExport(final Context pContext) {
- SharedPreferences lPreferences = PreferenceManager.getDefaultSharedPreferences(pContext);
- lPreferences.registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener() {
+ PlayMusicExporterPreferences.init(pContext);
+ PlayMusicExporterPreferences.registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
- scheduleExport(pContext);
- Log.i(TAG, "Preference changed: " + key);
+ if (key.contains("auto")) {
+ scheduleExport(pContext);
+ Log.i(TAG, "Preference changed: " + key);
+ }
}
});
+ if (PlayMusicExporterPreferences.getAutoExportEnabled()) {
+ long lInterval = PlayMusicExporterPreferences.getAutoExportFrequency();
+ boolean lRequireUnmeteredNetwork = PlayMusicExporterPreferences.getAutoExportRequireUnmetered();
+ boolean lRequireCharging = PlayMusicExporterPreferences.getAutoExportRequireCharging();
- long lInterval = Long.parseLong(lPreferences.getString("settings_export_frequency", "86400000"));
- boolean lRequireUnmeteredNetwork = lPreferences.getBoolean("settings_export_", false);
- boolean lRequireCharging = lPreferences.getBoolean("settings", true);
-
- JobScheduler lJobScheduler = (JobScheduler) pContext.getSystemService(JOB_SCHEDULER_SERVICE);
- 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());
+ JobScheduler lJobScheduler = (JobScheduler) pContext.getSystemService(JOB_SCHEDULER_SERVICE);
+ 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/settings/PlayMusicExporterPreferences.java b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/settings/PlayMusicExporterPreferences.java
index fe8cb0b..edb53d1 100644
--- a/playmusicexporter/src/main/java/re/jcg/playmusicexporter/settings/PlayMusicExporterPreferences.java
+++ b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/settings/PlayMusicExporterPreferences.java
@@ -6,24 +6,42 @@ import android.content.SharedPreferences;
import android.net.Uri;
import android.preference.PreferenceManager;
+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_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";
//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 GROUPS_EXPORT_PATH = "preference_groups_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 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";
+ 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";
+
+
+ private PlayMusicExporterPreferences() {
+ }
public static void init(Context pContext) {
preferences = PreferenceManager.getDefaultSharedPreferences(pContext);
@@ -49,8 +67,8 @@ public class PlayMusicExporterPreferences {
return getUri(ALBA_EXPORT_PATH);
}
- public static Uri getGroupExportPath() {
- return getUri(GROUP_EXPORT_PATH);
+ public static Uri getGroupsExportPath() {
+ return getUri(GROUPS_EXPORT_PATH);
}
private static Uri getUri(String key) {
@@ -69,6 +87,10 @@ public class PlayMusicExporterPreferences {
return preferences.getString(ALBA_EXPORT_STRUCTURE, EXPORT_STRUCTURE_DEFAULT);
}
+ public static String getGroupsExportStructure() {
+ return preferences.getString(GROUPS_EXPORT_STRUCTURE, EXPORT_STRUCTURE_DEFAULT);
+ }
+
public static String getAutoExportStructure() {
return preferences.getString(AUTO_EXPORT_STRUCTURE, EXPORT_STRUCTURE_DEFAULT);
}
@@ -76,4 +98,47 @@ public class PlayMusicExporterPreferences {
public static boolean getAutoExportUsesDifferentStructure() {
return preferences.getBoolean(AUTO_EXPORT_USES_DIFFERENT_STRUCTURE, AUTO_EXPORT_USES_DIFFERENT_STRUCTURE_DEFAULT);
}
+
+ public static boolean getDrawerLearned() {
+ return preferences.getBoolean(DRAWER_LEARNED, DRAWER_LEARNED_DEFAULT);
+ }
+ public static void setDrawerLearned(boolean drawerLearned) {
+ preferences.edit().putBoolean(DRAWER_LEARNED, drawerLearned).apply();
+ }
+
+ public static NavigationDrawerFragment.ViewType getDrawerViewType() {
+ return NavigationDrawerFragment.ViewType.fromName(preferences.getString(DRAWER_SELECTED_TYPE, DRAWER_SELECTED_TYPE_DEFAULT));
+ }
+
+ public static void setDrawerViewType(NavigationDrawerFragment.ViewType viewType) {
+ preferences.edit().putString(DRAWER_SELECTED_TYPE, viewType.name()).apply();
+ }
+
+ public static void setAlbaExportPath(Uri treeUri) {
+ preferences.edit().putString(ALBA_EXPORT_PATH, treeUri.toString()).apply();
+ }
+
+ public static void setGroupsExportPath(Uri treeUri) {
+ preferences.edit().putString(GROUPS_EXPORT_PATH, treeUri.toString()).apply();
+ }
+
+ public static boolean getAutoExportEnabled() {
+ return preferences.getBoolean(AUTO_EXPORT_ENABLED, AUTO_EXPORT_ENABLED_DEFAULT);
+ }
+
+ public static void registerOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener) {
+ preferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
+ }
+
+ public static long getAutoExportFrequency() {
+ return Long.parseLong(preferences.getString(AUTO_EXPORT_FREQUENCY, AUTO_EXPORT_FREQUENCY_DEFAULT));
+ }
+
+ public static boolean getAutoExportRequireUnmetered() {
+ return preferences.getBoolean(AUTO_EXPORT_REQUIRE_UNMETERED, AUTO_EXPORT_REQUIRE_CONDITION_DEFAULT);
+ }
+
+ public static boolean getAutoExportRequireCharging() {
+ return preferences.getBoolean(AUTO_EXPORT_REQUIRE_CHARGING, AUTO_EXPORT_REQUIRE_CONDITION_DEFAULT);
+ }
}
diff --git a/playmusicexporter/src/main/java/re/jcg/playmusicexporter/settings/PlayMusicExporterSettings.java b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/settings/PlayMusicExporterSettings.java
deleted file mode 100644
index 020d0fb..0000000
--- a/playmusicexporter/src/main/java/re/jcg/playmusicexporter/settings/PlayMusicExporterSettings.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (c) 2015 David Schulte
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-package re.jcg.playmusicexporter.settings;
-
-import android.content.Context;
-import android.net.Uri;
-import android.os.Environment;
-
-import de.arcus.framework.settings.AppSettings;
-import re.jcg.playmusicexporter.R;
-
-/**
- * Helper class to read and write app settings without to care about to open and close an editor
- */
-public class PlayMusicExporterSettings extends AppSettings {
- private static PlayMusicExporterSettings settings;
- /**
- * The default settings file
- */
- public static final String DEFAULT_SETTINGS_FILENAME = "play_music_exporter";
-
- // Preference constants
- private static final String PREF_ID3 = "pref_id3";
- private static final String PREF_ID3_ARTWORK_SIZE = "pref_id3_artwork_size";
- public static final String PREF_EXPORT_URI = "pref_export_uri";
- private static final String PREF_STRUCTURE_ALBA = "pref_structure_albua";
- private static final String PREF_STRUCTURE_GROUPS = "pref_structure_groups";
- public static final String PREF_DRAWER_LEARNED = "pref_drawer_learned";
- public static final String PREF_DRAWER_SELECTED_TYPE = "pref_drawer_selected_type";
-
- public PlayMusicExporterSettings(Context context) {
- super(context);
- }
-
-
- /**
- * Creates a new instance of PlayMusicExporterSettings that access to the default settings file
- * @param context Context of the app
- */
- public static void init(Context context) {
- settings = new PlayMusicExporterSettings(context);
-
- // Init the default values
-
- // ID3 settings
- if (!settings.contains(PREF_ID3))
- settings.setString(PREF_ID3, "id3_with_cover");
-
- // ID3 artwork settings
- if (!settings.contains(PREF_ID3_ARTWORK_SIZE))
- settings.setInt(PREF_ID3_ARTWORK_SIZE, 1024);
-
- // Export path
- if (!settings.contains(PREF_EXPORT_URI))
- settings.setUri(PREF_EXPORT_URI, Uri.fromFile(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC)));
-
- // Alba export structure
- if (!settings.contains(PREF_STRUCTURE_ALBA))
- settings.setString(PREF_STRUCTURE_ALBA, context.getString(R.string.settings_export_structure_alba_default_value));
-
- // Groups export structure
- if (!settings.contains(PREF_STRUCTURE_GROUPS))
- settings.setString(PREF_STRUCTURE_GROUPS, context.getString(R.string.settings_export_structure_groups_default_value));
-
- // Drawer learned
- if (!settings.contains(PREF_DRAWER_LEARNED))
- settings.setBoolean(PREF_DRAWER_LEARNED, false);
-
- //
- }
-
-
-}
diff --git a/playmusicexporter/src/main/res/values/strings.xml b/playmusicexporter/src/main/res/values/strings.xml
index de596d1..6f8a9f3 100644
--- a/playmusicexporter/src/main/res/values/strings.xml
+++ b/playmusicexporter/src/main/res/values/strings.xml
@@ -68,6 +68,8 @@
Export conditions
Export path and subdirectory structure
Debug
+ Export location alba
+ Export location groups
Version Number
@@ -88,10 +90,13 @@
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
+
+ Export path for alba
Subdirectory structure for albums
Set your subdirectory structure
Example: Beatles/Help!/13. Yesterday.mp3
+ Export path for groups
Subdirectory structure for playlists
Set your subdirectory structure
Example: Great Songs/4. Beatles - Yesterday.mp3
diff --git a/playmusicexporter/src/main/res/xml/pref_export.xml b/playmusicexporter/src/main/res/xml/pref_export.xml
index 0bc455c..1512d53 100644
--- a/playmusicexporter/src/main/res/xml/pref_export.xml
+++ b/playmusicexporter/src/main/res/xml/pref_export.xml
@@ -1,20 +1,25 @@
-
-
+
+
-
+ android:key="preference_alba_export_path"
+ android:title="@string/settings_export_path_alba" />
-
+
+
+
+
+