diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-01-24 21:57:08 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-01-24 21:57:08 -0800 |
commit | eb6034ccd8e68e63414f3159854da69f03c4d61e (patch) | |
tree | 94c52b32b93aba968d36156128be6e44248720de /src | |
parent | 47189ecb92977410eb00b1817dd885a4314d9904 (diff) | |
download | dsub-eb6034ccd8e68e63414f3159854da69f03c4d61e.tar.gz dsub-eb6034ccd8e68e63414f3159854da69f03c4d61e.tar.bz2 dsub-eb6034ccd8e68e63414f3159854da69f03c4d61e.zip |
#269 Convert timer to slider
Diffstat (limited to 'src')
-rw-r--r-- | src/github/daneren2005/dsub/fragments/DownloadFragment.java | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/src/github/daneren2005/dsub/fragments/DownloadFragment.java index ea8e8c3c..e58de995 100644 --- a/src/github/daneren2005/dsub/fragments/DownloadFragment.java +++ b/src/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -880,10 +880,33 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe protected void startTimer() {
View dialogView = context.getLayoutInflater().inflate(R.layout.start_timer, null);
- final EditText lengthBox = (EditText)dialogView.findViewById(R.id.timer_length);
+ // Setup length label
+ final TextView lengthBox = (TextView) dialogView.findViewById(R.id.timer_length_label);
final SharedPreferences prefs = Util.getPreferences(context);
- lengthBox.setText(prefs.getString(Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION, ""));
+ String lengthString = prefs.getString(Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION, "5");
+ int length = Integer.parseInt(lengthString);
+ lengthBox.setText(Util.formatDuration(length));
+
+ // Setup length slider
+ final SeekBar lengthBar = (SeekBar) dialogView.findViewById(R.id.timer_length_bar);
+ lengthBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ if(fromUser) {
+ int length = getMinutes(progress);
+ lengthBox.setText(Util.formatDuration(length));
+ }
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ }
+ });
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.menu_set_timer)
@@ -891,13 +914,13 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
- String length = lengthBox.getText().toString();
+ int length = getMinutes(lengthBar.getProgress());
SharedPreferences.Editor editor = prefs.edit();
- editor.putString(Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION, length);
+ editor.putString(Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION, Integer.toString(length));
editor.commit();
- getDownloadService().setSleepTimerDuration(Integer.parseInt(length));
+ getDownloadService().setSleepTimerDuration(length);
getDownloadService().startSleepTimer();
context.supportInvalidateOptionsMenu();
}
@@ -907,6 +930,16 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe dialog.show();
}
+ private int getMinutes(int progress) {
+ if(progress < 30) {
+ return progress + 1;
+ } else if(progress < 61) {
+ return (progress - 30) * 5 + getMinutes(29);
+ } else {
+ return (progress - 61) * 15 + getMinutes(60);
+ }
+ }
+
private void toggleFullscreenAlbumArt() {
if (playlistFlipper.getDisplayedChild() == 1) {
playlistFlipper.setInAnimation(AnimationUtils.loadAnimation(context, R.anim.push_down_in));
|