aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-10-20 20:19:10 -0700
committerScott Jackson <daneren2005@gmail.com>2014-10-20 20:19:10 -0700
commitfdb8b2d94dc8a9ac216eb501a514b47199092949 (patch)
treee330c9a5da311fbb477646a768904cfda8e8aa5e
parent3aca5d5f895ebf3283ffc0b05eb3cfbfd526d440 (diff)
parent08c7e436bdd25e72a386b45e2bdbb719ffde8f3c (diff)
downloaddsub-fdb8b2d94dc8a9ac216eb501a514b47199092949.tar.gz
dsub-fdb8b2d94dc8a9ac216eb501a514b47199092949.tar.bz2
dsub-fdb8b2d94dc8a9ac216eb501a514b47199092949.zip
Merge branch 'Tasker'
-rw-r--r--res/layout/edit_play_action.xml95
-rw-r--r--res/values/arrays.xml6
-rw-r--r--res/values/strings.xml5
-rw-r--r--src/github/daneren2005/dsub/activity/EditPlayActionActivity.java171
-rw-r--r--src/github/daneren2005/dsub/receiver/PlayActionReceiver.java4
-rw-r--r--src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java29
6 files changed, 303 insertions, 7 deletions
diff --git a/res/layout/edit_play_action.xml b/res/layout/edit_play_action.xml
index 6eb3b651..a1115da6 100644
--- a/res/layout/edit_play_action.xml
+++ b/res/layout/edit_play_action.xml
@@ -10,7 +10,6 @@
android:layout_height="wrap_content">
<TextView
- android:id="@+id/edit_shuffle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
@@ -23,4 +22,98 @@
android:longClickable="true"
/>
</LinearLayout>
+
+ <LinearLayout
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="4dp"
+ android:textSize="20dp"
+ android:text="@string/tasker.edit_shuffle_start_year" />
+
+ <CheckBox
+ android:id="@+id/edit_start_year_checkbox"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:longClickable="true"
+ android:enabled="false"/>
+
+ <EditText
+ android:id="@+id/edit_start_year"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:inputType="number"
+ android:hint="@string/shuffle.startYear"
+ android:enabled="false"/>
+ </LinearLayout>
+
+ <LinearLayout
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="4dp"
+ android:textSize="20dp"
+ android:text="@string/tasker.edit_shuffle_end_year" />
+
+ <CheckBox
+ android:id="@+id/edit_end_year_checkbox"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:longClickable="true"
+ android:enabled="false"/>
+
+ <EditText
+ android:id="@+id/edit_end_year"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:inputType="number"
+ android:hint="@string/shuffle.endYear"
+ android:enabled="false"/>
+ </LinearLayout>
+
+ <LinearLayout
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="4dp"
+ android:textSize="20dp"
+ android:text="@string/tasker.edit_shuffle_genre"/>
+
+ <Button
+ android:id="@+id/edit_genre_spinner"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ style="?android:attr/spinnerStyle"
+ android:enabled="false"/>
+ </LinearLayout>
+
+ <LinearLayout
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="4dp"
+ android:textSize="20dp"
+ android:text="@string/tasker.edit_server_offline"/>
+
+ <Spinner
+ android:id="@+id/edit_offline_spinner"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"/>
+ </LinearLayout>
</LinearLayout> \ No newline at end of file
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 3e85c982..19758562 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -235,4 +235,10 @@
<item>@string/settings.replay_gain_type.album</item>
<item>@string/settings.replay_gain_type.track</item>
</string-array>
+
+ <string-array name="editServerOptions">
+ <item>@string/tasker.edit_do_nothing</item>
+ <item>@string/main.online</item>
+ <item>@string/main.offline</item>
+ </string-array>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 0fdb2361..33a40981 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -559,6 +559,11 @@
<string name="tasker.start_playing_shuffled">Start playing in Shuffle Mode</string>
<string name="tasker.start_playing_title">Tasker -> Start DSub</string>
<string name="tasker.edit_shuffle_mode">Start in shuffle mode: </string>
+ <string name="tasker.edit_shuffle_start_year">Shuffle start year:</string>
+ <string name="tasker.edit_shuffle_end_year">Shuffle end year:</string>
+ <string name="tasker.edit_shuffle_genre">Shuffle from genre:</string>
+ <string name="tasker.edit_server_offline">Toggle offline: </string>
+ <string name="tasker.edit_do_nothing">Do Nothing</string>
<plurals name="select_album_n_songs">
<item quantity="zero">No songs</item>
diff --git a/src/github/daneren2005/dsub/activity/EditPlayActionActivity.java b/src/github/daneren2005/dsub/activity/EditPlayActionActivity.java
index b7f9de94..e1f2cad3 100644
--- a/src/github/daneren2005/dsub/activity/EditPlayActionActivity.java
+++ b/src/github/daneren2005/dsub/activity/EditPlayActionActivity.java
@@ -16,29 +16,168 @@
package github.daneren2005.dsub.activity;
import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
+import android.view.View;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
import android.widget.CheckBox;
+import android.widget.CompoundButton;
+import android.widget.EditText;
+import android.widget.Spinner;
+
+import java.util.ArrayList;
+import java.util.List;
import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.domain.Genre;
+import github.daneren2005.dsub.service.MusicService;
+import github.daneren2005.dsub.service.MusicServiceFactory;
+import github.daneren2005.dsub.service.OfflineException;
+import github.daneren2005.dsub.service.ServerTooOldException;
import github.daneren2005.dsub.util.Constants;
+import github.daneren2005.dsub.util.LoadingTask;
+import github.daneren2005.dsub.util.Util;
public class EditPlayActionActivity extends SubsonicActivity {
- private CheckBox checkBox;
+ private CheckBox shuffleCheckbox;
+ private CheckBox startYearCheckbox;
+ private EditText startYearBox;
+ private CheckBox endYearCheckbox;
+ private EditText endYearBox;
+ private Button genreButton;
+ private Spinner offlineSpinner;
+
+ private String doNothing;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(R.string.tasker_start_playing_title);
setContentView(R.layout.edit_play_action);
+ final Activity context = this;
+ doNothing = context.getResources().getString(R.string.tasker_edit_do_nothing);
+
+ shuffleCheckbox = (CheckBox) findViewById(R.id.edit_shuffle_checkbox);
+ shuffleCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton view, boolean isChecked) {
+ startYearCheckbox.setEnabled(isChecked);
+ endYearCheckbox.setEnabled(isChecked);
+ genreButton.setEnabled(isChecked);
+ }
+ });
+
+ startYearCheckbox = (CheckBox) findViewById(R.id.edit_start_year_checkbox);
+ startYearBox = (EditText) findViewById(R.id.edit_start_year);
+ // Disable/enable number box if checked
+ startYearCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton view, boolean isChecked) {
+ startYearBox.setEnabled(isChecked);
+ }
+ });
+
+ endYearCheckbox = (CheckBox) findViewById(R.id.edit_end_year_checkbox);
+ endYearBox = (EditText) findViewById(R.id.edit_end_year);
+ endYearCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton view, boolean isChecked) {
+ endYearBox.setEnabled(isChecked);
+ }
+ });
+
+ genreButton = (Button) findViewById(R.id.edit_genre_spinner);
+ genreButton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ new LoadingTask<List<Genre>>(context, true) {
+ @Override
+ protected List<Genre> doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+ return musicService.getGenres(false, context, this);
+ }
+
+ @Override
+ protected void done(final List<Genre> genres) {
+ List<String> names = new ArrayList<String>();
+ String blank = context.getResources().getString(R.string.select_genre_blank);
+ names.add(doNothing);
+ names.add(blank);
+ for(Genre genre: genres) {
+ names.add(genre.getName());
+ }
+ final List<String> finalNames = names;
- checkBox = (CheckBox) findViewById(R.id.edit_shuffle_checkbox);
- if(getIntent().getBundleExtra(Constants.TASKER_EXTRA_BUNDLE) != null && getIntent().getBundleExtra(Constants.TASKER_EXTRA_BUNDLE).getBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE)) {
- checkBox.setChecked(true);
+ AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ builder.setTitle(R.string.shuffle_pick_genre)
+ .setItems(names.toArray(new CharSequence[names.size()]), new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ if(which == 1) {
+ genreButton.setText("");
+ } else {
+ genreButton.setText(finalNames.get(which));
+ }
+ }
+ });
+ AlertDialog dialog = builder.create();
+ dialog.show();
+ }
+
+ @Override
+ protected void error(Throwable error) {
+ String msg;
+ if (error instanceof OfflineException || error instanceof ServerTooOldException) {
+ msg = getErrorMessage(error);
+ } else {
+ msg = context.getResources().getString(R.string.playlist_error) + " " + getErrorMessage(error);
+ }
+
+ Util.toast(context, msg, false);
+ }
+ }.execute();
+ }
+ });
+ genreButton.setText(doNothing);
+
+ offlineSpinner = (Spinner) findViewById(R.id.edit_offline_spinner);
+ ArrayAdapter<CharSequence> offlineAdapter = ArrayAdapter.createFromResource(this, R.array.editServerOptions, android.R.layout.simple_spinner_item);
+ offlineAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ offlineSpinner.setAdapter(offlineAdapter);
+
+ // Setup default for everything
+ Bundle extras = getIntent().getBundleExtra(Constants.TASKER_EXTRA_BUNDLE);
+ if(extras != null) {
+ if(extras.getBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE)) {
+ shuffleCheckbox.setChecked(true);
+ }
+
+ String startYear = extras.getString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, null);
+ if(startYear != null) {
+ startYearCheckbox.setEnabled(true);
+ startYearBox.setText(startYear);
+ }
+ String endYear = extras.getString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, null);
+ if(endYear != null) {
+ endYearCheckbox.setEnabled(true);
+ endYearBox.setText(endYear);
+ }
+
+ String genre = extras.getString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, doNothing);
+ if(genre != null) {
+ genreButton.setText(genre);
+ }
+
+ int offline = extras.getInt(Constants.PREFERENCES_KEY_OFFLINE, 0);
+ if(offline != 0) {
+ offlineSpinner.setSelection(offline);
+ }
}
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
@@ -70,11 +209,31 @@ public class EditPlayActionActivity extends SubsonicActivity {
private void accept() {
Intent intent = new Intent();
- String blurb = getResources().getString(checkBox.isChecked() ? R.string.tasker_start_playing_shuffled : R.string.tasker_start_playing);
+ String blurb = getResources().getString(shuffleCheckbox.isChecked() ? R.string.tasker_start_playing_shuffled : R.string.tasker_start_playing);
intent.putExtra("com.twofortyfouram.locale.intent.extra.BLURB", blurb);
+ // Get settings user specified
Bundle data = new Bundle();
- data.putBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE, checkBox.isChecked());
+ boolean shuffle = shuffleCheckbox.isChecked();
+ data.putBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE, shuffle);
+ if(shuffle) {
+ if(startYearCheckbox.isChecked()) {
+ data.putString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, startYearBox.getText().toString());
+ }
+ if(endYearCheckbox.isChecked()) {
+ data.putString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, endYearBox.getText().toString());
+ }
+ String genre = genreButton.getText().toString();
+ if(!genre.equals(doNothing)) {
+ data.putString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, genre);
+ }
+ }
+
+ int offline = offlineSpinner.getSelectedItemPosition();
+ if(offline != 0) {
+ data.putInt(Constants.PREFERENCES_KEY_OFFLINE, offline);
+ }
+
intent.putExtra(Constants.TASKER_EXTRA_BUNDLE, data);
setResult(Activity.RESULT_OK, intent);
diff --git a/src/github/daneren2005/dsub/receiver/PlayActionReceiver.java b/src/github/daneren2005/dsub/receiver/PlayActionReceiver.java
index 60814cc6..2c04d829 100644
--- a/src/github/daneren2005/dsub/receiver/PlayActionReceiver.java
+++ b/src/github/daneren2005/dsub/receiver/PlayActionReceiver.java
@@ -36,6 +36,10 @@ public class PlayActionReceiver extends BroadcastReceiver {
Intent start = new Intent(context, DownloadService.class);
start.setAction(DownloadService.START_PLAY);
start.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, startShuffled);
+ start.putExtra(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, data.getString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR));
+ start.putExtra(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, data.getString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR));
+ start.putExtra(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, data.getString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE));
+ start.putExtra(Constants.PREFERENCES_KEY_OFFLINE, data.getInt(Constants.PREFERENCES_KEY_OFFLINE));
context.startService(start);
}
}
diff --git a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
index 13c3cea7..0a1e2cdd 100644
--- a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
+++ b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
@@ -167,8 +167,37 @@ public class DownloadServiceLifecycleSupport {
lock.lock();
lock.unlock();
}
+
+ int offlinePref = intent.getIntExtra(Constants.PREFERENCES_KEY_OFFLINE, 0);
+ if(offlinePref != 0) {
+ boolean offline = (offlinePref == 2);
+ Util.setOffline(downloadService, offline);
+ if (offline) {
+ downloadService.clearIncomplete();
+ } else {
+ downloadService.checkDownloads();
+ }
+ }
if(intent.getBooleanExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, false)) {
+ // Add shuffle parameters
+ SharedPreferences.Editor editor = Util.getPreferences(downloadService).edit();
+ String startYear = intent.getStringExtra(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR);
+ if(startYear != null) {
+ editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, startYear);
+ }
+
+ String endYear = intent.getStringExtra(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR);
+ if(endYear != null) {
+ editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, endYear);
+ }
+
+ String genre = intent.getStringExtra(Constants.PREFERENCES_KEY_SHUFFLE_GENRE);
+ if(genre != null) {
+ editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, genre);
+ }
+ editor.commit();
+
downloadService.setShufflePlayEnabled(true);
} else {
downloadService.start();