Commit 0e10cf35 authored by Ulan's avatar Ulan Committed by Ulan

Added loop video feature


(cherry picked from commit 9fbcaff5)

(cherry picked from commit 228883a7caf1ef2b61cb84b22eaee08e790371c0)
parent 459ac3a4
......@@ -37,6 +37,7 @@ import android.view.View;
import android.view.WindowManager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.widget.CheckBox;
import android.widget.Toast;
import com.google.android.exoplayer2.C;
......@@ -81,6 +82,7 @@ import org.horaapps.leafpic.R;
import org.horaapps.leafpic.activities.base.BaseActivity;
import org.horaapps.leafpic.util.Measure;
import org.horaapps.leafpic.util.StringUtils;
import org.horaapps.leafpic.util.preferences.Prefs;
import org.horaapps.leafpic.views.videoplayer.CustomExoPlayerView;
import org.horaapps.leafpic.views.videoplayer.CustomPlayBackController;
import org.horaapps.leafpic.views.videoplayer.TrackSelectionHelper;
......@@ -138,11 +140,9 @@ public class PlayerActivity extends BaseActivity implements CustomPlayBackContro
if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) {
CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER);
}
setContentView(R.layout.activity_player);
initUi();
rootView = findViewById(R.id.root);
simpleExoPlayerView = findViewById(R.id.player_view);
simpleExoPlayerView.setControllerVisibilityListener(this);
simpleExoPlayerView.requestFocus();
......@@ -255,7 +255,11 @@ public class PlayerActivity extends BaseActivity implements CustomPlayBackContro
player.addListener(new PlayerEventListener());
simpleExoPlayerView.setPlayer(player);
player.setPlayWhenReady(shouldAutoPlay);
if (Prefs.getLoopVideo()) {
player.setRepeatMode(Player.REPEAT_MODE_ALL);
} else {
player.setRepeatMode(Player.REPEAT_MODE_OFF);
}
}
String action = intent.getAction();
......@@ -443,6 +447,9 @@ public class PlayerActivity extends BaseActivity implements CustomPlayBackContro
}
MenuItem repeat = menu.findItem(R.id.loop_video);
repeat.setChecked(Prefs.getLoopVideo());
return true;
}
......@@ -496,6 +503,18 @@ public class PlayerActivity extends BaseActivity implements CustomPlayBackContro
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
return true;
case R.id.loop_video:
if(item.isChecked()) {
item.setChecked(false);
Prefs.setLoopVideo(false);
player.setRepeatMode(Player.REPEAT_MODE_OFF);
} else {
item.setChecked(true);
Prefs.setLoopVideo(true);
player.setRepeatMode(Player.REPEAT_MODE_ALL);
}
return true;
default:
return super.onOptionsItemSelected(item);
......
......@@ -36,4 +36,5 @@ public final class Defaults {
public static final boolean ANIMATIONS_DISABLED = false;
public static final boolean TIMELINE_ENABLED = false;
public static final boolean LOOP_VIDEO = false;
}
......@@ -28,6 +28,7 @@ public final class Keys {
public static final String ANIMATIONS_DISABLED = "disable_animations";
public static final String FORCE_ENGLISH = "force_english_locale";
public static final String LOOP_VIDEO = "loop_video";
// Feature flags
public static final String TIMELINE_ENABLED = "enable_timeline";
......
......@@ -234,6 +234,14 @@ public class Prefs {
return getPrefs().get(key, defaultValue);
}
public static boolean getLoopVideo() {
return getPrefs().get(Keys.LOOP_VIDEO, Defaults.LOOP_VIDEO);
}
public static void setLoopVideo(boolean value) {
getPrefs().put(Keys.LOOP_VIDEO, value);
}
// ***** Remove these methods when SettingWithSwitchView is refactored.
@NonNull
......
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_share"
......@@ -24,6 +25,11 @@
android:title="@string/text"
android:visible="false"
app:showAsAction="never"/>
<item
android:id="@+id/loop_video"
android:title="@string/loop_video"
android:checkable="true"
app:showAsAction="never"/>
<item
android:id="@+id/action_settings"
android:title="@string/settings"
......
......@@ -337,6 +337,7 @@
<string name="text">Text</string>
<string name="retry">Retry</string>
<string name="off">Off</string>
<string name="loop_video">Loop video</string>
<!--ERRORS-->
<string name="error_drm_not_supported">Protected content is supported on Android 4.3 and later</string>
......@@ -417,4 +418,7 @@
<string name="timeline_grouping_menu_month">Month</string>
<string name="timeline_grouping_menu_year">Year</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment