Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Release

See merge request sschueller/peertube!23
  • Loading branch information
sschueller committed Feb 20, 2021
2 parents 27f5f45 + 5622b76 commit 6a4088e
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ dependencies {
implementation "com.google.android.exoplayer:extension-mediasession:$exoplayer"
implementation "com.google.android.exoplayer:extension-okhttp:$exoplayer"

// date formatter
implementation 'org.ocpsoft.prettytime:prettytime:5.0.0.Final'
// date formatter, do not update past 4.0.4 https://github.com/sschueller/peertube-android/issues/262
implementation 'org.ocpsoft.prettytime:prettytime:4.0.4.Final'

// Version comparison
implementation 'org.apache.maven:maven-artifact:3.6.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
*/
package net.schueller.peertube.fragment;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -72,8 +74,7 @@ public View onCreateView(LayoutInflater inflater,
TextView speed15 = view.findViewById(R.id.video_speed15);
TextView speed20 = view.findViewById(R.id.video_speed20);

// Default
setVideoSpeed(1.0f, speed10Icon);
setDefaultVideoSpeed();

// Attach the listener
speed05.setOnClickListener(v -> setVideoSpeed(0.5f, speed05Icon));
Expand Down Expand Up @@ -103,4 +104,30 @@ private void setVideoSpeed(Float speed, TextView icon) {
new Iconics.Builder().on(icon).build();
}

private void setDefaultVideoSpeed() {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
String speed = sharedPref.getString(getString(R.string.pref_video_speed_key), "1.0");

switch (speed) {
case "0.5":
setVideoSpeed(0.5f, speed05Icon);
break;
case "0.75":
setVideoSpeed(0.75f, speed075Icon);
break;
case "1.0":
setVideoSpeed(1.0f, speed10Icon);
break;
case "1.25":
setVideoSpeed(1.25f, speed125Icon);
break;
case "1.5":
setVideoSpeed(1.5f, speed15Icon);
break;
case "2.0":
setVideoSpeed(2.0f, speed20Icon);
break;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.media.AudioManager;
Expand All @@ -32,6 +33,7 @@
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.webkit.URLUtil;
import androidx.annotation.Nullable;

Expand Down Expand Up @@ -255,8 +257,11 @@ public void playVideo() {
// Auto play
player.setPlayWhenReady(true);

//reset playback speed
this.setPlayBackSpeed(1.0f);
//set playback speed to global default
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
float speed = Float.parseFloat(sharedPref.getString(getString(R.string.pref_video_speed_key), "1.0"));

this.setPlayBackSpeed(speed);

playerNotificationManager = PlayerNotificationManager.createWithNotificationChannel(
context, PLAYBACK_CHANNEL_ID, R.string.playback_channel_name,
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/res/values/constants.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<string name="pref_show_nsfw_key" translatable="false">pref_show_nsfw</string>
<string name="pref_video_language_key" translatable="false">pref_language</string>

<string name="pref_video_speed_key" translatable="false">pref_video_speed</string>
<string name="pref_back_pause_key" translatable="false">pref_back_pause</string>
<string name="pref_background_behavior_key" translatable="false">pref_background_behavior</string>
<string name="pref_torrent_player_key" translatable="false">pref_torrent_player</string>
Expand Down Expand Up @@ -582,4 +583,22 @@
<item>High</item>
</string-array>

<string-array name="videoSpeed">
<item>0.5x</item>
<item>0.75x</item>
<item>Normal</item>
<item>1.25x</item>
<item>1.5x</item>
<item>2x</item>
</string-array>

<string-array name="videoSpeedValues">
<item>0.5</item>
<item>0.75</item>
<item>1.0</item>
<item>1.25</item>
<item>1.5</item>
<item>2.0</item>
</string-array>

</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
<string name="pref_title_peertube_server">PeerTube Server</string>
<string name="pref_title_background_play">Background Playback</string>
<string name="pref_description_background_play">If enabled, continues to play video in background.</string>
<string name="pref_title_video_speed">Default Playback Speed</string>
<string name="pref_description_video_speed">Select the global Video Playback Speed</string>
<string name="pref_title_back_pause">Pause on back button</string>
<string name="pref_description_back_pause">Pause background play when pressing back during video playback.</string>
<string name="pref_language_app">Application Language</string>
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@

<PreferenceCategory app:title="@string/settings_activity_video_playback_category_title" app:iconSpaceReserved="false">

<ListPreference
app:defaultValue="1.0"
app:entries="@array/videoSpeed"
app:entryValues="@array/videoSpeedValues"
app:key="@string/pref_video_speed_key"
app:summary="@string/pref_description_video_speed"
app:title="@string/pref_title_video_speed"
app:iconSpaceReserved="false"/>

<SwitchPreference
app:defaultValue="true"
app:key="@string/pref_back_pause_key"
Expand Down

0 comments on commit 6a4088e

Please sign in to comment.