Skip to content

Commit

Permalink
Playback timer
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyPavlenko committed May 16, 2020
1 parent f39a7cb commit 0991105
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1265,4 +1265,34 @@ public int hashCode() {
return view.hashCode();
}
}

private PlaybackTimer playbackTimer;

public int getPlaybackTimer() {
return (playbackTimer == null) ? 0
: Math.max((int) (playbackTimer.time - System.currentTimeMillis()) / 1000, 0);
}

public void setPlaybackTimer(int time) {
if (time == 0) {
playbackTimer = null;
} else {
int delay = time * 1000;
PlaybackTimer timer = this.playbackTimer = new PlaybackTimer(delay + System.currentTimeMillis());
handler.postDelayed(timer, delay);
}
}

private final class PlaybackTimer implements Runnable {
final long time;

public PlaybackTimer(long time) {
this.time = time;
}

@Override
public void run() {
if (playbackTimer == this) onStop();
}
}
}
51 changes: 51 additions & 0 deletions fermata/src/main/java/me/aap/fermata/ui/view/ControlPanelView.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import me.aap.utils.app.App;
import me.aap.utils.function.BooleanSupplier;
import me.aap.utils.function.DoubleSupplier;
import me.aap.utils.function.IntSupplier;
import me.aap.utils.pref.BasicPreferenceStore;
import me.aap.utils.pref.PreferenceSet;
import me.aap.utils.pref.PreferenceStore;
Expand Down Expand Up @@ -320,6 +321,7 @@ protected void buildPlayableMenu(MainActivityDelegate a, OverlayMenu.Builder b,

b.addItem(R.id.audio_effects, R.drawable.equalizer, R.string.audio_effects);
b.addItem(R.id.speed, R.drawable.speed, R.string.speed).setSubmenu(s -> new SpeedMenuHandler().build(s, getItem()));
b.addItem(R.id.timer, R.drawable.timer, R.string.timer).setSubmenu(s -> new TimerMenuHandler(a).build(s));
}

@Override
Expand Down Expand Up @@ -550,6 +552,55 @@ public void applyFloatPref(Pref<? extends DoubleSupplier> pref, float value) {
}
}

private static final class TimerMenuHandler implements OverlayMenu.CloseHandler {
private final Pref<IntSupplier> H = Pref.i("H", 0);
private final Pref<IntSupplier> M = Pref.i("M", 0);
private PreferenceStore store = new BasicPreferenceStore();
private final MediaSessionCallback cb;

TimerMenuHandler(MainActivityDelegate activity) {
cb = activity.getMediaSessionCallback();
}

void build(OverlayMenu.Builder b) {
PreferenceSet set = new PreferenceSet();
int time = cb.getPlaybackTimer();

if (time > 0) {
int h = time / 3600;
int m = (time - h * 3600) / 60;
store.applyIntPref(H, h);
store.applyIntPref(M, m);
}

set.addIntPref(o -> {
o.title = R.string.hours;
o.store = store;
o.pref = H;
o.seekMin = 0;
o.seekMax = 12;
});
set.addIntPref(o -> {
o.title = R.string.minutes;
o.store = store;
o.pref = M;
o.seekMin = 0;
o.seekMax = 60;
o.seekScale = 5;
});

set.addToMenu(b, true);
b.setCloseHandlerHandler(this);
}

@Override
public void menuClosed(OverlayMenu menu) {
int h = store.getIntPref(H);
int m = store.getIntPref(M);
cb.setPlaybackTimer(h * 3600 + m * 60);
}
}

private int getStartDelay() {
return (prefs == null) ? 0 : prefs.getVideoControlStartDelayPref() * 1000;
}
Expand Down
18 changes: 18 additions & 0 deletions fermata/src/main/res/drawable/timer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M12,17m-1,0a1,1 0,1 1,2 0a1,1 0,1 1,-2 0"
android:fillColor="#000000"/>
<path
android:pathData="M7,12m-1,0a1,1 0,1 1,2 0a1,1 0,1 1,-2 0"
android:fillColor="#000000"/>
<path
android:pathData="M17,12m-1,0a1,1 0,1 1,2 0a1,1 0,1 1,-2 0"
android:fillColor="#000000"/>
<path
android:pathData="M12,3c-0.55,0 -1,0.45 -1,1v2c0,0.55 0.45,1 1,1s1,-0.45 1,-1v-0.92c3.31,0.48 5.87,3.25 6,6.66 0.14,3.85 -3.03,7.2 -6.88,7.26C8.19,19.06 5,15.91 5,12c0,-1.68 0.59,-3.22 1.58,-4.42l4.71,4.72c0.39,0.39 1.02,0.39 1.41,0 0.39,-0.39 0.39,-1.02 0,-1.41L7.26,5.46c-0.38,-0.38 -1,-0.39 -1.4,-0.02C4.1,7.07 3,9.4 3,12c0,5.04 4.14,9.12 9.21,9 4.7,-0.11 8.63,-4.01 8.78,-8.71C21.16,7.19 17.07,3 12,3z"
android:fillColor="#000000"/>
</vector>
4 changes: 4 additions & 0 deletions fermata/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@
<string name="donate_text">Если вам нравится приложение, вы можете купить мне кофе.</string>
<string name="use_phone_for_donation">Пожалуйста, воспользуйтесь телефоном, чтобы купить кофе.</string>

<string name="timer">Таймер</string>
<string name="hours">Часы</string>
<string name="minutes">Минуты</string>

<string name="about">О приложении</string>
<string name="about_html"><![CDATA[<H1 align="center">Fermata Media Player</H1>
<p>Fermata Media Player - это бесплатный, с открытым исходным кодом, аудио и видео плеер
Expand Down
1 change: 1 addition & 0 deletions fermata/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<item name="shuffle_disable" type="id" />

<item name="speed" type="id" />
<item name="timer" type="id" />

<item name="vfs_content" type="id" />
<item name="vfs_file_system" type="id" />
Expand Down
5 changes: 4 additions & 1 deletion fermata/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
<string name="video_scaling_4" translatable="false">4x3</string>
<string name="video_scaling_16" translatable="false">16x9</string>


<string name="audio">Audio</string>
<string name="audio_delay">Audio delay</string>
<string name="preferred_audio_lang">Preferred audio stream languages</string>
Expand Down Expand Up @@ -204,6 +203,10 @@
<string name="donate_text">If you like the application, please consider buying me a coffee.</string>
<string name="use_phone_for_donation">Please use your phone to buy a coffee.</string>

<string name="timer">Timer</string>
<string name="hours">Hours</string>
<string name="minutes">Minutes</string>

<string name="about">About</string>
<string name="about_html"><![CDATA[<H1 align="center">Fermata Media Player</H1>
<p>Fermata Media Player is a free, open source audio and video player with a simple and
Expand Down

0 comments on commit 0991105

Please sign in to comment.