Some new features

This commit is contained in:
Thomas 2020-11-05 17:38:57 +01:00
parent 825a74de4a
commit 0c048877e0
11 changed files with 175 additions and 47 deletions

View File

@ -12,6 +12,12 @@
<string name="set_fullscreen_choice" translatable="false">set_fullscreen_choice</string>
<string name="set_autoplay_next_video_choice" translatable="false">set_autoplay_next_video_choice</string>
<string name="set_store_in_history" translatable="false">set_store_in_history</string>
<string name="set_play_screen_lock_choice" translatable="false">set_play_screen_lock_choice</string>
<string name="set_play_screen_lock">Verrouillage d\'écran</string>
<string name="set_play_screen_lock_description">Continuer à lire des vidéos lorsque l\'écran est verrouillé</string>
<string name="change_profile_picture">Modifier la photo de profil</string>
<string name="account_updated">Le compte a été mis à jour !</string>

View File

@ -1,2 +1,10 @@
Added:
- Double tap video left/right to seek - or + 10 seconds
- Automatically adapt full-screen in portrait or landscape
- Incognito: Enable/disable reccords in history
- Video suggestions
- Enable/Disable playback when screen is off (default: disabled)
Fix:
- Enable to end playing with top back button
- Fix FP message with token

View File

@ -11,6 +11,10 @@
<string name="set_autoplay_next_video_choice" translatable="false">set_autoplay_next_video_choice</string>
<string name="set_theme_choice" translatable="false">set_theme_choice</string>
<string name="set_fullscreen_choice" translatable="false">set_fullscreen_choice</string>
<string name="set_play_screen_lock_choice" translatable="false">set_play_screen_lock_choice</string>
<string name="set_play_screen_lock">Screen lock</string>
<string name="set_play_screen_lock_description">Keep playing videos when the screen is locked</string>
<string name="save">Save</string>
<string name="enable_history">Enable history</string>

View File

@ -169,9 +169,10 @@ public class MainActivity extends AppCompatActivity {
if (active == null) {
active = overviewFragment;
}
fm.beginTransaction().add(R.id.nav_host_fragment, locaFragment, "5").hide(locaFragment).commit();
if (!Helper.isLoggedIn(MainActivity.this)) {
fm.beginTransaction().add(R.id.nav_host_fragment, locaFragment, "5").hide(locaFragment).commit();
fm.beginTransaction().add(R.id.nav_host_fragment, recentFragment, "4").hide(recentFragment).commit();
fm.beginTransaction().add(R.id.nav_host_fragment, mostLikedFragment, "3").hide(mostLikedFragment).commit();
fm.beginTransaction().add(R.id.nav_host_fragment, trendingFragment, "2").hide(trendingFragment).commit();
@ -189,30 +190,35 @@ public class MainActivity extends AppCompatActivity {
if (Helper.isLoggedIn(MainActivity.this)) {
navView.inflateMenu(R.menu.bottom_nav_menu_connected);
new Thread(() -> {
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String tokenStr = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
String instance = Helper.getLiveInstance(MainActivity.this);
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String instanceShar = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
String userIdShar = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
Account account = new AccountDAO(MainActivity.this, db).getAccountByToken(tokenStr);
if( account == null) {
account = new AccountDAO(MainActivity.this, db).getAccountByIdInstance(userIdShar, instanceShar);
}
if (account != null) {
Account finalAccount = account;
OauthParams oauthParams = new OauthParams();
oauthParams.setGrant_type("refresh_token");
oauthParams.setClient_id(account.getClient_id());
oauthParams.setClient_secret(account.getClient_secret());
oauthParams.setRefresh_token(account.getRefresh_token());
oauthParams.setAccess_token(account.getToken());
new Thread(() -> {
try {
Token token = new RetrofitPeertubeAPI(MainActivity.this).manageToken(oauthParams);
if (token == null) {
runOnUiThread(() -> Helper.logoutCurrentUser(MainActivity.this, account));
if (token == null && Helper.instanceOnline(instance)) {
runOnUiThread(() -> Helper.logoutCurrentUser(MainActivity.this, finalAccount));
return;
}
runOnUiThread(() -> {
//To avoid a token issue with subscriptions, adding fragment is done when the token is refreshed.
new Handler().post(() -> {
fm.beginTransaction().add(R.id.nav_host_fragment, locaFragment, "5").hide(locaFragment).commit();
fm.beginTransaction().add(R.id.nav_host_fragment, recentFragment, "4").hide(recentFragment).commitAllowingStateLoss();
fm.beginTransaction().add(R.id.nav_host_fragment, trendingFragment, "3").hide(trendingFragment).commitAllowingStateLoss();
fm.beginTransaction().add(R.id.nav_host_fragment, subscriptionFragment, "2").hide(subscriptionFragment).commitAllowingStateLoss();
@ -243,11 +249,10 @@ public class MainActivity extends AppCompatActivity {
}
}
} catch (Error error) {
runOnUiThread(() -> Helper.logoutCurrentUser(MainActivity.this, account));
runOnUiThread(() -> Helper.logoutCurrentUser(MainActivity.this, finalAccount));
error.printStackTrace();
}
}).start();
}
}}).start();
} else {
navView.inflateMenu(R.menu.bottom_nav_menu);

View File

@ -89,6 +89,7 @@ import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoListener;
import org.jetbrains.annotations.NotNull;
@ -141,7 +142,7 @@ import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn;
import static com.google.android.exoplayer2.Player.MEDIA_ITEM_TRANSITION_REASON_AUTO;
public class PeertubeActivity extends AppCompatActivity implements CommentListAdapter.AllCommentRemoved, Player.EventListener {
public class PeertubeActivity extends AppCompatActivity implements CommentListAdapter.AllCommentRemoved, Player.EventListener, VideoListener {
public static String video_id;
private String peertubeInstance, videoUuid;
@ -171,6 +172,22 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
public static List<String> playedVideos = new ArrayList<>();
private VideoData.Video nextVideo;
@Override
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
if(width < height){
videoOrientationType = videoOrientation.PORTRAIT;
}else{
videoOrientationType = videoOrientation.LANDSCAPE;
}
}
enum videoOrientation {
LANDSCAPE,
PORTRAIT
}
private videoOrientation videoOrientationType;
public static void hideKeyboard(Activity activity) {
if (activity != null && activity.getWindow() != null) {
activity.getWindow().getDecorView();
@ -188,7 +205,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
binding = ActivityPeertubeBinding.inflate(getLayoutInflater());
View view = binding.getRoot();
setContentView(view);
videoOrientationType = videoOrientation.LANDSCAPE;
max_id = "0";
urlIntent = null;
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
@ -258,7 +275,11 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
getWindow().setAttributes(attrs);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
binding.peertubeInformationContainer.setVisibility(View.GONE);
if (videoOrientationType == videoOrientation.LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
} else {
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
@ -341,7 +362,11 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
registBroadcastReceiver();
if( autoFullscreen && autoPlay) {
openFullscreenDialog();
if (videoOrientationType == videoOrientation.LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
}
@ -480,7 +505,11 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
setFullscreen(FullScreenMediaController.fullscreen.ON);
fullScreenMode = true;
openFullscreenDialog();
if (videoOrientationType == videoOrientation.LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
} else {
fullscreen = FullScreenMediaController.fullscreen.OFF;
setFullscreen(FullScreenMediaController.fullscreen.OFF);
@ -514,10 +543,12 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
if (playInMinimized && player != null) {
enterVideoMode();
} else {
finish();
finishAndRemoveTask();
Intent intent = new Intent(PeertubeActivity.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
}
finish();
return true;
}
return super.onOptionsItemSelected(item);
@ -749,6 +780,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
ProgressiveMediaSource videoSource;
player = new SimpleExoPlayer.Builder(PeertubeActivity.this).build();
player.addVideoListener(PeertubeActivity.this);
player.addListener(this);
binding.mediaVideo.player(player);
binding.doubleTapPlayerView.setPlayer(player);
@ -980,6 +1012,21 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
}
@Override
public void onStop() {
super.onStop();
onStopCalled = true;
}
@Override
public void onResume() {
super.onResume();
onStopCalled = false;
if (player != null && !player.isPlaying()) {
player.setPlayWhenReady(autoPlay);
}
}
@Override
protected void onPause() {
super.onPause();
@ -987,25 +1034,30 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
updateHistory(player.getCurrentPosition()/1000);
}
if (player != null && !isPlayInMinimized) {
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
if( !sharedpreferences.getBoolean(getString(R.string.set_play_screen_lock_choice), false)) {
player.setPlayWhenReady(false);
}
}
}
private void registBroadcastReceiver() {
final IntentFilter theFilter = new IntentFilter();
theFilter.addAction(Intent.ACTION_SCREEN_ON);
theFilter.addAction(Intent.ACTION_SCREEN_OFF);
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
mPowerKeyReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String strAction = intent.getAction();
if (strAction.equals(Intent.ACTION_SCREEN_OFF)) {
if (player != null && isPlayInMinimized) {
if( !sharedpreferences.getBoolean(getString(R.string.set_play_screen_lock_choice), false)) {
player.setPlayWhenReady(false);
}
}
}
}
};
getApplicationContext().registerReceiver(mPowerKeyReceiver, theFilter);
}
@ -1075,20 +1127,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
}
@Override
public void onStop() {
super.onStop();
onStopCalled = true;
}
@Override
public void onResume() {
super.onResume();
onStopCalled = false;
if (player != null && !player.isPlaying()) {
player.setPlayWhenReady(autoPlay);
}
}
public void displayResolution() {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
@ -1295,7 +1333,11 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
fullScreenButton.setOnClickListener(v -> {
if (!fullScreenMode) {
openFullscreenDialog();
if (videoOrientationType == videoOrientation.LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
} else {
closeFullscreenDialog();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
@ -1308,7 +1350,11 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
playButton.setOnClickListener(v->{
if(autoFullscreen && !fullScreenMode) {
openFullscreenDialog();
if (videoOrientationType == videoOrientation.LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
player.setPlayWhenReady(true);
});
@ -1485,6 +1531,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
}
@Override
public void onPlayerError(ExoPlaybackException error) {

View File

@ -191,6 +191,11 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
}).start();
}
}
if (key.compareTo(getString(R.string.set_play_screen_lock_choice)) == 0) {
SwitchPreference set_play_screen_lock_choice = findPreference(getString(R.string.set_play_screen_lock_choice));
assert set_play_screen_lock_choice != null;
editor.putBoolean(getString(R.string.set_play_screen_lock_choice), set_play_screen_lock_choice.isChecked());
}
if (key.compareTo(getString(R.string.set_video_language_choice)) == 0) {
MultiSelectListPreference set_video_language_choice = findPreference(getString(R.string.set_video_language_choice));
assert set_video_language_choice != null;
@ -332,6 +337,13 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
assert set_autoplay_next_video_choice != null;
set_autoplay_next_video_choice.setChecked(autoplayNextVideo);
//****** Screen lock *******
boolean playScreenLock = sharedpref.getBoolean(getString(R.string.set_play_screen_lock_choice), false);
SwitchPreference set_play_screen_lock_choice = findPreference(getString(R.string.set_play_screen_lock_choice));
assert set_play_screen_lock_choice != null;
set_play_screen_lock_choice.setChecked(playScreenLock);
//****** Language filter *********
LinkedHashMap<String, String> languages = new LinkedHashMap<>(peertubeInformation.getLanguages());
List<CharSequence> entriesLanguages = new ArrayList<>();

View File

@ -49,6 +49,7 @@ import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import java.net.InetAddress;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@ -735,4 +736,15 @@ public class Helper {
activity.startActivity(chooserIntent);
}
}
public static boolean instanceOnline(String host) {
try {
InetAddress ipAddr = InetAddress.getByName(host);
return ipAddr.toString().trim().compareTo("") != 0;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}

View File

@ -249,7 +249,23 @@ public class AccountDAO {
}
}
/**
* Returns an Account by id and instance
*
* @param id String
* @param instance String
* @return Account
*/
public Account getAccountByIdInstance(String id, String instance) {
try {
Cursor c = db.query(Sqlite.TABLE_USER_ACCOUNT, null, Sqlite.COL_USER_ID + " = \"" + id + "\" AND " + Sqlite.COL_INSTANCE + " = \"" + instance + "\"", null, null, null, null, "1");
return cursorToUser(c);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* Test if the current user is already stored in data base
*

View File

@ -301,6 +301,7 @@ public class NotificationsWorker extends Worker {
NotificationChannel channel = new NotificationChannel(FETCH_NOTIFICATION_CHANNEL_ID,
getApplicationContext().getString(R.string.fetch_notification_channel_name),
NotificationManager.IMPORTANCE_DEFAULT);
channel.setSound(null, null);
notificationManager.createNotificationChannel(channel);
}
Intent myIntent = new Intent(getApplicationContext(), MainActivity.class);

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M10,16h4c0.55,0 1,-0.45 1,-1v-3c0,-0.55 -0.45,-1 -1,-1v-1c0,-1.11 -0.9,-2 -2,-2 -1.11,0 -2,0.9 -2,2v1c-0.55,0 -1,0.45 -1,1v3c0,0.55 0.45,1 1,1zM10.8,10c0,-0.66 0.54,-1.2 1.2,-1.2 0.66,0 1.2,0.54 1.2,1.2v1h-2.4v-1zM17,1L7,1c-1.1,0 -2,0.9 -2,2v18c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2L19,3c0,-1.1 -0.9,-2 -2,-2zM17,19L7,19L7,5h10v14z"/>
</vector>

View File

@ -47,6 +47,12 @@
android:summary="@string/set_autoplay_next_video_description"
android:title="@string/set_autoplay_next_video" />
<androidx.preference.SwitchPreference
android:icon="@drawable/ic_baseline_screen_lock_portrait_24"
android:key="@string/set_play_screen_lock_choice"
android:summary="@string/set_play_screen_lock_description"
android:title="@string/set_play_screen_lock" />
<androidx.preference.SeekBarPreference
android:icon="@drawable/ic_baseline_storage_24"
android:defaultValue="10"