Some fixes

This commit is contained in:
Thomas 2020-11-28 10:33:13 +01:00
parent e7f55aace9
commit b0e29c0ba4
4 changed files with 98 additions and 69 deletions

View File

@ -18,6 +18,9 @@
<string name="set_video_in_list">Vidéos dans une liste</string>
<string name="set_video_in_list_description">Change la mise en page pour afficher les vidéos dans une liste</string>
<string name="_retry">Réessayer</string>
<string name="refresh_token_failed">Échec de rafraîchissement du jeton d\'accès</string>
<string name="refresh_token_failed_message">Vous pouvez réessayer de le rafraîchir ou simplement déconnecter le compte</string>
<string name="export_list">Exporter</string>
<string name="import_list">Importer</string>
<string name="originally_published">Date de publication</string>

View File

@ -105,6 +105,9 @@
<item>12 hours</item>
</string-array>
<string name="_retry">Retry</string>
<string name="refresh_token_failed">Token refresh failed!</string>
<string name="refresh_token_failed_message">You can retry this action or simply disconnect the current account</string>
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="cancel">Cancel</string>

View File

@ -24,6 +24,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -194,6 +195,7 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v(Helper.TAG, "onCreate: " + savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater());
View view = binding.getRoot();
setContentView(view);
@ -238,7 +240,7 @@ public class MainActivity extends AppCompatActivity {
mostLikedFragment.setArguments(bundle);
overviewFragment = new DisplayOverviewFragment();
Log.v(Helper.TAG, "Helper.isLoggedIn(MainActivity.this): " + Helper.isLoggedIn(MainActivity.this));
if (!Helper.isLoggedIn(MainActivity.this)) {
PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
binding.viewpager.setAdapter(mPagerAdapter);
@ -278,6 +280,43 @@ public class MainActivity extends AppCompatActivity {
if (Helper.isLoggedIn(MainActivity.this)) {
navView.inflateMenu(R.menu.bottom_nav_menu_connected);
refreshToken();
} else {
navView.inflateMenu(R.menu.bottom_nav_menu);
}
peertubeInformation = new PeertubeInformation();
peertubeInformation.setCategories(new LinkedHashMap<>());
peertubeInformation.setLanguages(new LinkedHashMap<>());
peertubeInformation.setLicences(new LinkedHashMap<>());
peertubeInformation.setPrivacies(new LinkedHashMap<>());
peertubeInformation.setPlaylistPrivacies(new LinkedHashMap<>());
peertubeInformation.setTranslations(new LinkedHashMap<>());
startInForeground();
if (BuildConfig.google_restriction && BuildConfig.full_instances) {
RateThisApp.onCreate(this);
RateThisApp.showRateDialogIfNeeded(this);
}
if (!BuildConfig.full_instances) {
PlaylistExportHelper.manageIntentUrl(MainActivity.this, getIntent());
}
}
public DisplayVideosFragment getSubscriptionFragment() {
return subscriptionFragment;
}
private void startInForeground() {
Intent notificationIntent = new Intent(this, RetrieveInfoService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(notificationIntent);
} else {
startService(notificationIntent);
}
}
private void refreshToken() {
new Thread(() -> {
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String tokenStr = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
@ -300,7 +339,22 @@ public class MainActivity extends AppCompatActivity {
try {
Token token = new RetrofitPeertubeAPI(MainActivity.this).manageToken(oauthParams);
if (token == null && Helper.instanceOnline(instance)) {
runOnUiThread(() -> Helper.logoutCurrentUser(MainActivity.this, finalAccount));
runOnUiThread(() -> {
AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);
alt_bld.setTitle(R.string.refresh_token_failed);
alt_bld.setMessage(R.string.refresh_token_failed_message);
alt_bld.setNegativeButton(R.string.action_logout, (dialog, id) -> {
dialog.dismiss();
Helper.logoutCurrentUser(MainActivity.this, finalAccount);
});
alt_bld.setPositiveButton(R.string._retry, (dialog, id) -> {
dialog.dismiss();
refreshToken();
});
AlertDialog alert = alt_bld.create();
alert.show();
});
return;
} else if (token == null) {
return;
@ -345,40 +399,8 @@ public class MainActivity extends AppCompatActivity {
}
}
}).start();
} else {
navView.inflateMenu(R.menu.bottom_nav_menu);
}
peertubeInformation = new PeertubeInformation();
peertubeInformation.setCategories(new LinkedHashMap<>());
peertubeInformation.setLanguages(new LinkedHashMap<>());
peertubeInformation.setLicences(new LinkedHashMap<>());
peertubeInformation.setPrivacies(new LinkedHashMap<>());
peertubeInformation.setPlaylistPrivacies(new LinkedHashMap<>());
peertubeInformation.setTranslations(new LinkedHashMap<>());
startInForeground();
if (BuildConfig.google_restriction && BuildConfig.full_instances) {
RateThisApp.onCreate(this);
RateThisApp.showRateDialogIfNeeded(this);
}
if (!BuildConfig.full_instances) {
PlaylistExportHelper.manageIntentUrl(MainActivity.this, getIntent());
}
}
public DisplayVideosFragment getSubscriptionFragment() {
return subscriptionFragment;
}
private void startInForeground() {
Intent notificationIntent = new Intent(this, RetrieveInfoService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(notificationIntent);
} else {
startService(notificationIntent);
}
}
@Override
public boolean onCreateOptionsMenu(@NotNull Menu menu) {
@ -610,6 +632,7 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onNewIntent(Intent intent) {
Log.v(Helper.TAG, "onNewIntent: " + intent);
super.onNewIntent(intent);
if (intent == null)
return;

View File

@ -1519,7 +1519,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
break;
case AUTONEXT:
binding.subMenuTitle.setText(R.string.set_autoplay);
binding.subMenuTitle.setText(R.string.set_autoplay_next_video_settings);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
boolean autoplayNextVideo = sharedpreferences.getBoolean(getString(R.string.set_autoplay_next_video_choice), true);
items.add(new MenuItemView(0, getString(R.string.no), !autoplayNextVideo));