diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java index febaa68e5..ab3e2eb8d 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -1,8 +1,10 @@ package de.danoeh.antennapod.activity; import android.annotation.TargetApi; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.PixelFormat; import android.media.AudioManager; import android.net.Uri; @@ -43,6 +45,8 @@ import de.danoeh.antennapod.dialog.SleepTimerDialog; public abstract class MediaplayerActivity extends ActionBarActivity implements OnSeekBarChangeListener { private static final String TAG = "MediaplayerActivity"; + private static final String PREFS = "MediaPlayerActivityPreferences"; + private static final String PREF_SHOW_TIME_LEFT = "showTimeLeft"; protected PlaybackController controller; @@ -51,6 +55,7 @@ public abstract class MediaplayerActivity extends ActionBarActivity protected SeekBar sbPosition; protected ImageButton butPlay; protected ImageButton butRev; + protected boolean showTimeLeft = false; protected TextView txtvRev; protected ImageButton butFF; protected TextView txtvFF; @@ -413,7 +418,14 @@ public abstract class MediaplayerActivity extends ActionBarActivity && controller.getMedia() != null) { txtvPosition.setText(Converter .getDurationStringLong(currentPosition)); - txtvLength.setText(Converter.getDurationStringLong(duration)); + if(showTimeLeft) { + txtvLength.setText("-"+Converter + .getDurationStringLong(duration - currentPosition)); + } + else { + txtvLength.setText(Converter + .getDurationStringLong(duration)); + } updateProgressbarPosition(currentPosition, duration); } else { Log.w(TAG, "Could not react to position observer update because of invalid time"); @@ -436,6 +448,8 @@ public abstract class MediaplayerActivity extends ActionBarActivity protected boolean loadMediaInfo() { Log.d(TAG, "loadMediaInfo()"); Playable media = controller.getMedia(); + SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE); + showTimeLeft = prefs.getBoolean(PREF_SHOW_TIME_LEFT,false); if (media != null) { txtvPosition.setText(Converter.getDurationStringLong((media .getPosition()))); @@ -446,6 +460,10 @@ public abstract class MediaplayerActivity extends ActionBarActivity float progress = ((float) media.getPosition()) / media.getDuration(); sbPosition.setProgress((int) (progress * sbPosition.getMax())); + if(showTimeLeft) { + txtvLength.setText("-"+Converter.getDurationStringLong((media + .getDuration()-media.getPosition()))); + } } return true; } else { @@ -457,7 +475,30 @@ public abstract class MediaplayerActivity extends ActionBarActivity setContentView(getContentViewResourceId()); sbPosition = (SeekBar) findViewById(R.id.sbPosition); txtvPosition = (TextView) findViewById(R.id.txtvPosition); + + SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE); + showTimeLeft = prefs.getBoolean(PREF_SHOW_TIME_LEFT,false); + Log.d("timeleft",showTimeLeft? "true":"false"); txtvLength = (TextView) findViewById(R.id.txtvLength); + txtvLength.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showTimeLeft = !showTimeLeft; + Playable media = controller.getMedia(); + if(showTimeLeft) { + txtvLength.setText("-"+Converter.getDurationStringLong((media + .getDuration()-media.getPosition()))); + }else{ + txtvLength.setText("-"+Converter.getDurationStringLong((media.getDuration()))); + } + + SharedPreferences.Editor editor = prefs.edit(); + editor.putBoolean(PREF_SHOW_TIME_LEFT,showTimeLeft); + editor.commit(); + Log.d("timeleft on click",showTimeLeft? "true":"false"); + } + }); + butPlay = (ImageButton) findViewById(R.id.butPlay); butRev = (ImageButton) findViewById(R.id.butRev); txtvRev = (TextView) findViewById(R.id.txtvRev); @@ -598,6 +639,11 @@ public abstract class MediaplayerActivity extends ActionBarActivity if (controller != null) { prog = controller.onSeekBarProgressChanged(seekBar, progress, fromUser, txtvPosition); + if(showTimeLeft && prog!=0) { + int duration = controller.getDuration(); + txtvLength.setText("-"+Converter + .getDurationStringLong(duration - (int) (prog * duration))); + } } }