aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--res/layout/edit_play_action.xml20
-rw-r--r--res/values/strings.xml1
-rw-r--r--src/github/daneren2005/dsub/activity/EditPlayActionActivity.java70
3 files changed, 89 insertions, 2 deletions
diff --git a/res/layout/edit_play_action.xml b/res/layout/edit_play_action.xml
index 1043e2e2..ef5408ee 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"
@@ -30,7 +29,24 @@
android:layout_height="wrap_content">
<TextView
- android:id="@+id/edit_offline_label"
+ 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"/>
+ </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"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 15dc020d..8d7cc873 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -559,6 +559,7 @@
<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_genre">Shuffle from genre:</string>
<string name="tasker.edit_server_offline">Toggle offline: </string>
<string name="tasker.edit_do_nothing">Do Nothing</string>
diff --git a/src/github/daneren2005/dsub/activity/EditPlayActionActivity.java b/src/github/daneren2005/dsub/activity/EditPlayActionActivity.java
index c59b679f..ef960822 100644
--- a/src/github/daneren2005/dsub/activity/EditPlayActionActivity.java
+++ b/src/github/daneren2005/dsub/activity/EditPlayActionActivity.java
@@ -16,21 +16,37 @@
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.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 shuffleCheckbox;
+ private Button genreButton;
private Spinner offlineSpinner;
@Override
@@ -38,12 +54,66 @@ public class EditPlayActionActivity extends SubsonicActivity {
super.onCreate(savedInstanceState);
setTitle(R.string.tasker_start_playing_title);
setContentView(R.layout.edit_play_action);
+ final Activity context = this;
shuffleCheckbox = (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)) {
shuffleCheckbox.setChecked(true);
}
+ 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);
+ String doNothing = context.getResources().getString(R.string.tasker_edit_do_nothing);
+ names.add(doNothing);
+ names.add(blank);
+ for(Genre genre: genres) {
+ names.add(genre.getName());
+ }
+ final List<String> finalNames = names;
+
+ 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("Do Nothing");
+
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);