diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-10-20 20:19:10 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-10-20 20:19:10 -0700 |
commit | fdb8b2d94dc8a9ac216eb501a514b47199092949 (patch) | |
tree | e330c9a5da311fbb477646a768904cfda8e8aa5e /src/github | |
parent | 3aca5d5f895ebf3283ffc0b05eb3cfbfd526d440 (diff) | |
parent | 08c7e436bdd25e72a386b45e2bdbb719ffde8f3c (diff) | |
download | dsub-fdb8b2d94dc8a9ac216eb501a514b47199092949.tar.gz dsub-fdb8b2d94dc8a9ac216eb501a514b47199092949.tar.bz2 dsub-fdb8b2d94dc8a9ac216eb501a514b47199092949.zip |
Merge branch 'Tasker'
Diffstat (limited to 'src/github')
3 files changed, 198 insertions, 6 deletions
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(); |