From 77fbebf4a71bb1f7bb7f11abcd68ae6d137559f6 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 24 Jan 2023 15:03:02 +0100 Subject: [PATCH] improvements --- app/src/main/AndroidManifest.xml | 4 +- .../app/fedilab/android/BaseMainActivity.java | 89 ++++++++++++++----- .../mastodon/client/entities/app/Account.java | 9 +- .../android/mastodon/helper/Helper.java | 16 +++- .../mastodon/ui/drawer/StatusAdapter.java | 7 ++ .../peertube/activities/AccountActivity.java | 3 +- .../peertube/activities/LoginActivity.java | 10 +-- .../activities/MyAccountActivity.java | 4 +- .../peertube/activities/PeertubeActivity.java | 19 ++-- .../PeertubeEditUploadActivity.java | 3 +- .../activities/PeertubeMainActivity.java | 36 +++++--- .../activities/SepiaSearchActivity.java | 4 +- .../activities/ShowChannelActivity.java | 3 +- .../peertube/client/RetrofitPeertubeAPI.java | 23 +++-- .../peertube/client/data/VideoData.java | 4 +- .../peertube/drawer/AboutInstanceAdapter.java | 3 +- .../peertube/drawer/ChannelListAdapter.java | 3 +- .../peertube/drawer/PeertubeAdapter.java | 3 +- .../fragment/DisplaySepiaSearchFragment.java | 3 +- .../fragment/DisplayVideosFragment.java | 5 +- .../peertube/fragment/SettingsFragment.java | 6 +- .../android/peertube/helper/Helper.java | 17 ++-- .../peertube/helper/HelperInstance.java | 4 +- .../peertube/helper/SwitchAccountHelper.java | 9 +- .../services/GlobalUploadObserver.java | 4 +- .../peertube/sqlite/StoredInstanceDAO.java | 5 +- .../peertube/worker/NotificationsWorker.java | 3 +- ...ertube.xml => exo_player_control_view.xml} | 0 28 files changed, 209 insertions(+), 90 deletions(-) rename app/src/main/res/layouts/peertube/layout/{exo_player_control_view_peertube.xml => exo_player_control_view.xml} (100%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index be9a9a63..ecdc571e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -358,7 +358,9 @@ - + = Build.VERSION_CODES.TIRAMISU) { ActivityResultLauncher permissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { @@ -346,17 +354,11 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt currentToken = sharedpreferences.getString(Helper.PREF_USER_TOKEN, null); } currentAccount = new Account(BaseMainActivity.this).getConnectedAccount(); - Log.v(TAG, "currentToken! " + currentToken); - Log.v(TAG, "currentAccount! " + currentAccount); - if (currentAccount != null && currentAccount.api == Account.API.PEERTUBE) { - startActivity(new Intent(this, PeertubeBaseMainActivity.class)); - finish(); - } } catch (DBException e) { e.printStackTrace(); } //If the attached account is null, the app will fetch remote instance to get up-to-date values - if (currentAccount != null && currentAccount.mastodon_account == null) { + if (currentAccount != null && currentAccount.mastodon_account == null && currentAccount.peertube_account == null) { OkHttpClient okHttpClient = new OkHttpClient.Builder() .readTimeout(60, TimeUnit.SECONDS) .connectTimeout(60, TimeUnit.SECONDS) @@ -383,11 +385,22 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt } Handler mainHandler = new Handler(Looper.getMainLooper()); Runnable myRunnable = () -> { - if (currentAccount == null || currentAccount.mastodon_account == null) { + if (currentAccount == null || (currentAccount.mastodon_account == null && currentAccount.peertube_account == null)) { //It is not, the user is redirected to the login page - Intent myIntent = new Intent(BaseMainActivity.this, LoginActivity.class); - startActivity(myIntent); - finish(); + if (currentAccount != null) { + try { + Helper.removeAccount(BaseMainActivity.this); + } catch (DBException e) { + Intent myIntent = new Intent(BaseMainActivity.this, LoginActivity.class); + startActivity(myIntent); + finish(); + e.printStackTrace(); + } + } else { + Intent myIntent = new Intent(BaseMainActivity.this, LoginActivity.class); + startActivity(myIntent); + finish(); + } return; } bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(currentAccount, binding.bottomNavView); @@ -654,13 +667,25 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt if (currentSubmenu == null) { continue; } - final MenuItem item = currentSubmenu.add("@" + account.mastodon_account.acct); - item.setIcon(R.drawable.ic_person); + String acct = ""; + String url = ""; boolean disableGif = sharedpreferences.getBoolean(getString(R.string.SET_DISABLE_GIF), false); - String url = !disableGif ? account.mastodon_account.avatar : account.mastodon_account.avatar_static; - if (url != null && url.startsWith("/")) { - url = "https://" + account.instance + account.mastodon_account.avatar; + if (account.mastodon_account != null) { + acct = account.mastodon_account.acct; + url = !disableGif ? account.mastodon_account.avatar : account.mastodon_account.avatar_static; + if (url != null && url.startsWith("/")) { + url = "https://" + account.instance + account.mastodon_account.avatar; + } + } else if (account.peertube_account != null) { + acct = account.peertube_account.getAcct(); + url = account.peertube_account.getAvatar().getPath(); + if (url != null && url.startsWith("/")) { + url = "https://" + account.instance + account.peertube_account.getAvatar().getPath(); + } } + + final MenuItem item = currentSubmenu.add("@" + acct); + item.setIcon(R.drawable.ic_person); if (!this.isDestroyed() && !this.isFinishing() && url != null) { if (url.contains(".gif")) { Glide.with(BaseMainActivity.this) @@ -706,6 +731,8 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt api = account.api; SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_USER_TOKEN, account.token); + editor.putString(PREF_USER_SOFTWARE, account.software); + Log.v(TAG, "put 2: " + account.software); editor.commit(); //The user is now aut //The user is now authenticated, it will be redirected to MainActivity @@ -908,9 +935,11 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt e.printStackTrace(); } } - MutedAccounts mutedAccounts = new MutedAccounts(BaseMainActivity.this).getMutedAccount(currentAccount); - if (mutedAccounts != null && mutedAccounts.accounts != null) { - filteredAccounts = mutedAccounts.accounts; + if (currentAccount != null) { + MutedAccounts mutedAccounts = new MutedAccounts(BaseMainActivity.this).getMutedAccount(currentAccount); + if (mutedAccounts != null && mutedAccounts.accounts != null) { + filteredAccounts = mutedAccounts.accounts; + } } //Delete cache older than 7 days new StatusCache(BaseMainActivity.this).deleteForAllAccountAfter7Days(); @@ -930,12 +959,19 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt headerMainBinding.otherAccount1.setVisibility(View.VISIBLE); headerMainBinding.otherAccount1.setOnClickListener(v -> { headerMenuOpen = false; - Toasty.info(BaseMainActivity.this, getString(R.string.toast_account_changed, "@" + accounts.get(0).mastodon_account.acct + "@" + accounts.get(0).instance), Toasty.LENGTH_LONG).show(); + String account = ""; + if (accounts.get(0).mastodon_account != null) { + account = "@" + accounts.get(0).mastodon_account.acct + "@" + accounts.get(0).instance; + } else if (accounts.get(0).peertube_account != null) { + account = "@" + accounts.get(0).peertube_account.getAcct() + "@" + accounts.get(0).instance; + } + Toasty.info(BaseMainActivity.this, getString(R.string.toast_account_changed, account), Toasty.LENGTH_LONG).show(); BaseMainActivity.currentToken = accounts.get(0).token; BaseMainActivity.currentUserID = accounts.get(0).user_id; api = accounts.get(0).api; SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_USER_TOKEN, accounts.get(0).token); + editor.putString(PREF_USER_SOFTWARE, accounts.get(0).software); editor.commit(); //The user is now aut //The user is now authenticated, it will be redirected to MainActivity @@ -948,12 +984,19 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt headerMainBinding.otherAccount2.setVisibility(View.VISIBLE); headerMainBinding.otherAccount2.setOnClickListener(v -> { headerMenuOpen = false; - Toasty.info(BaseMainActivity.this, getString(R.string.toast_account_changed, "@" + accounts.get(1).mastodon_account.acct + "@" + accounts.get(1).instance), Toasty.LENGTH_LONG).show(); + String account = ""; + if (accounts.get(1).mastodon_account != null) { + account = "@" + accounts.get(1).mastodon_account.acct + "@" + accounts.get(1).instance; + } else if (accounts.get(1).peertube_account != null) { + account = "@" + accounts.get(1).peertube_account.getAcct() + "@" + accounts.get(1).instance; + } + Toasty.info(BaseMainActivity.this, getString(R.string.toast_account_changed, account), Toasty.LENGTH_LONG).show(); BaseMainActivity.currentToken = accounts.get(1).token; BaseMainActivity.currentUserID = accounts.get(1).user_id; api = accounts.get(1).api; SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_USER_TOKEN, accounts.get(1).token); + editor.putString(PREF_USER_SOFTWARE, accounts.get(1).software); editor.commit(); //The user is now aut //The user is now authenticated, it will be redirected to MainActivity @@ -1034,6 +1077,8 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt api = account.api; SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_USER_TOKEN, account.token); + editor.putString(PREF_USER_SOFTWARE, account.software); + Log.v(TAG, "put 3: " + account.software); editor.commit(); Intent mainActivity = new Intent(this, MainActivity.class); mainActivity.putExtra(Helper.INTENT_ACTION, Helper.OPEN_NOTIFICATION); diff --git a/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/Account.java b/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/Account.java index 085125ed..7b310b4d 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/Account.java +++ b/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/Account.java @@ -526,12 +526,19 @@ public class Account extends BaseAccount implements Serializable { case "PLEROMA": api = API.PLEROMA; break; + case "PEERTUBE": + api = API.PEERTUBE; + break; default: api = API.UNKNOWN; break; } account.api = api; - account.mastodon_account = restoreAccountFromString(c.getString(c.getColumnIndexOrThrow(Sqlite.COL_ACCOUNT))); + if (api != API.PEERTUBE) { + account.mastodon_account = restoreAccountFromString(c.getString(c.getColumnIndexOrThrow(Sqlite.COL_ACCOUNT))); + } else { + account.peertube_account = restorePeertubeAccountFromString(c.getString(c.getColumnIndexOrThrow(Sqlite.COL_ACCOUNT))); + } return account; } diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java index aeacb46b..284be164 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java @@ -58,6 +58,7 @@ import android.provider.MediaStore; import android.provider.OpenableColumns; import android.text.TextUtils; import android.util.DisplayMetrics; +import android.util.Log; import android.util.TypedValue; import android.view.Menu; import android.view.MenuItem; @@ -298,6 +299,7 @@ public class Helper { public static final String PREF_USER_TOKEN = "PREF_USER_TOKEN"; public static final String PREF_USER_ID = "PREF_USER_ID"; public static final String PREF_USER_INSTANCE = "PREF_USER_INSTANCE"; + public static final String PREF_USER_SOFTWARE = "PREF_USER_SOFTWARE"; public static final String PREF_IS_MODERATOR = "PREF_IS_MODERATOR"; public static final String PREF_IS_ADMINISTRATOR = "PREF_IS_ADMINISTRATOR"; public static final String PREF_MESSAGE_URL = "PREF_MESSAGE_URL"; @@ -922,6 +924,7 @@ public class Helper { if (newAccount == null) { editor.putString(PREF_USER_TOKEN, null); editor.putString(PREF_USER_INSTANCE, null); + // editor.putString(PREF_USER_SOFTWARE, null); editor.putString(PREF_USER_ID, null); editor.commit(); Intent loginActivity = new Intent(activity, LoginActivity.class); @@ -930,6 +933,8 @@ public class Helper { } else { currentAccount = newAccount; editor.putString(PREF_USER_TOKEN, newAccount.token); + editor.putString(PREF_USER_SOFTWARE, newAccount.software); + Log.v(TAG, "put 4: " + newAccount.software); editor.putString(PREF_USER_INSTANCE, newAccount.instance); editor.putString(PREF_USER_ID, newAccount.user_id); BaseMainActivity.currentUserID = newAccount.user_id; @@ -1073,7 +1078,16 @@ public class Helper { public static void loadPP(Activity activity, ImageView view, BaseAccount account, boolean crop) { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity); boolean disableGif = sharedpreferences.getBoolean(activity.getString(R.string.SET_DISABLE_GIF), false); - String targetedUrl = disableGif ? account.mastodon_account.avatar_static : account.mastodon_account.avatar; + String targetedUrl = ""; + if (account.mastodon_account != null) { + targetedUrl = disableGif ? account.mastodon_account.avatar_static : account.mastodon_account.avatar; + } else if (account.peertube_account != null) { + targetedUrl = account.peertube_account.getAvatar().getPath(); + if (targetedUrl != null && targetedUrl.startsWith("/")) { + targetedUrl = "https://" + account.instance + account.peertube_account.getAvatar().getPath(); + } + } + if (targetedUrl != null && Helper.isValidContextForGlide(activity)) { if (disableGif || (!targetedUrl.endsWith(".gif"))) { try { diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java index bfda3bd8..54e7aef9 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java @@ -28,7 +28,9 @@ import static app.fedilab.android.mastodon.activities.ContextActivity.expand; import static app.fedilab.android.mastodon.helper.Helper.ARG_TIMELINE_REFRESH_ALL; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE; +import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_SOFTWARE; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN; +import static app.fedilab.android.mastodon.helper.Helper.TAG; import android.annotation.SuppressLint; import android.app.Activity; @@ -49,6 +51,7 @@ import android.os.Looper; import android.text.Html; import android.text.SpannableString; import android.text.TextUtils; +import android.util.Log; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.MotionEvent; @@ -1995,6 +1998,8 @@ public class StatusAdapter extends RecyclerView.Adapter currentAccount = account; SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_USER_TOKEN, account.token); + editor.putString(PREF_USER_SOFTWARE, account.software); + Log.v(TAG, "put 5: " + account.software); editor.putString(PREF_USER_INSTANCE, account.instance); editor.putString(PREF_USER_ID, account.user_id); editor.commit(); @@ -2020,6 +2025,8 @@ public class StatusAdapter extends RecyclerView.Adapter currentAccount = account; SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_USER_TOKEN, account.token); + editor.putString(PREF_USER_SOFTWARE, account.software); + Log.v(TAG, "put 6: " + account.software); editor.putString(PREF_USER_INSTANCE, account.instance); editor.putString(PREF_USER_ID, account.user_id); editor.commit(); diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/AccountActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/AccountActivity.java index ee6bc5da..dbb3ff86 100644 --- a/app/src/main/java/app/fedilab/android/peertube/activities/AccountActivity.java +++ b/app/src/main/java/app/fedilab/android/peertube/activities/AccountActivity.java @@ -36,6 +36,7 @@ import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentStatePagerAdapter; +import androidx.preference.PreferenceManager; import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.ViewPager; @@ -79,7 +80,7 @@ public class AccountActivity extends BaseBarActivity { Spanned.SPAN_INCLUSIVE_EXCLUSIVE); - SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(AccountActivity.this); String token = sharedpreferences.getString(PREF_USER_TOKEN, null); BaseAccount baseAccount = null; diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/LoginActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/LoginActivity.java index 9ccf5608..5f07ad06 100644 --- a/app/src/main/java/app/fedilab/android/peertube/activities/LoginActivity.java +++ b/app/src/main/java/app/fedilab/android/peertube/activities/LoginActivity.java @@ -14,7 +14,6 @@ package app.fedilab.android.peertube.activities; * You should have received a copy of the GNU General Public License along with TubeLab; if not, * see . */ -import static app.fedilab.android.mastodon.helper.Helper.TAG; import static app.fedilab.android.peertube.client.RetrofitPeertubeAPI.updateCredential; import android.annotation.SuppressLint; @@ -25,7 +24,6 @@ import android.text.SpannableString; import android.text.Spanned; import android.text.style.ForegroundColorSpan; import android.text.style.UnderlineSpan; -import android.util.Log; import android.util.Patterns; import android.view.MenuItem; import android.view.View; @@ -33,6 +31,8 @@ import android.view.ViewGroup; import android.widget.TextView; import android.widget.Toast; +import androidx.preference.PreferenceManager; + import java.net.MalformedURLException; import java.net.URL; @@ -163,9 +163,7 @@ public class LoginActivity extends BaseBarActivity { } client_id = oauth.getClient_id(); client_secret = oauth.getClient_secret(); - Log.v(TAG, "client_id: " + client_id); - Log.v(TAG, "client_secret: " + client_secret); - SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(Helper.CLIENT_ID, client_id); editor.putString(Helper.CLIENT_SECRET, client_secret); @@ -182,9 +180,7 @@ public class LoginActivity extends BaseBarActivity { oauthParams.setPassword(binding.loginPasswd.getText().toString()); } try { - Log.v(TAG, "token: GET"); Token token = new RetrofitPeertubeAPI(LoginActivity.this, finalInstance, null).manageToken(oauthParams); - Log.v(TAG, ">token: " + token); proceedLogin(token, finalInstance); } catch (final Exception e) { oauthParams.setUsername(binding.loginUid.getText().toString().toLowerCase().trim()); diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/MyAccountActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/MyAccountActivity.java index 11ffd307..55031178 100644 --- a/app/src/main/java/app/fedilab/android/peertube/activities/MyAccountActivity.java +++ b/app/src/main/java/app/fedilab/android/peertube/activities/MyAccountActivity.java @@ -19,7 +19,6 @@ import static app.fedilab.android.peertube.worker.WorkHelper.NOTIFICATION_WORKER import android.Manifest; import android.app.Activity; -import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; @@ -38,6 +37,7 @@ import androidx.appcompat.widget.SwitchCompat; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import androidx.documentfile.provider.DocumentFile; +import androidx.preference.PreferenceManager; import androidx.work.WorkManager; import com.bumptech.glide.Glide; @@ -102,7 +102,7 @@ public class MyAccountActivity extends BaseBarActivity { android.R.layout.simple_spinner_dropdown_item, refresh_array); binding.refreshTime.setAdapter(refreshArray); - SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(MyAccountActivity.this); int interval = sharedpreferences.getInt(Helper.NOTIFICATION_INTERVAL, 60); binding.refreshTime.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeActivity.java index f236ef90..c46736d0 100644 --- a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeActivity.java @@ -80,6 +80,7 @@ import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import androidx.core.graphics.drawable.DrawableCompat; import androidx.lifecycle.ViewModelProvider; +import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -213,7 +214,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis setContentView(binding.getRoot()); videoOrientationType = videoOrientation.LANDSCAPE; max_id = "0"; - SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeActivity.this); String token = sharedpreferences.getString(PREF_USER_TOKEN, null); if (Helper.canMakeAction(PeertubeActivity.this) && !sepiaSearch) { BaseAccount account = null; @@ -954,7 +955,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis }); fetchComments(); - SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeActivity.this); setTitle(peertube.getName()); binding.peertubeDescription.setText(peertube.getDescription()); @@ -1148,7 +1149,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis if (subtitles != null) { subtitlesStr = subtitles.toString(); } - SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeActivity.this); int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB); ProgressiveMediaSource videoSource = null; HlsMediaSource hlsMediaSource = null; @@ -1242,7 +1243,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis return; } - SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeActivity.this); String nsfwAction = sharedpreferences.getString(getString(R.string.set_video_sensitive_choice), Helper.BLUR); if (promptNSFW && peertube != null && peertube.isNsfw() && (nsfwAction.compareTo(Helper.BLUR) == 0 || nsfwAction.compareTo(Helper.DO_NOT_LIST) == 0)) { AlertDialog alertDialog; @@ -1346,7 +1347,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis 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); + final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeActivity.this); mPowerKeyReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -1597,7 +1598,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis break; case AUTONEXT: binding.subMenuTitle.setText(R.string.set_autoplay_next_video_settings); - SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeActivity.this); boolean autoplayNextVideo = sharedpreferences.getBoolean(getString(R.string.set_autoplay_next_video_choice), true); items.add(new MenuItemView(0, getString(R.string.no), !autoplayNextVideo)); items.add(new MenuItemView(1, getString(R.string.yes), autoplayNextVideo)); @@ -1693,7 +1694,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis ); break; case AUTONEXT: - SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeActivity.this); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putBoolean(getString(R.string.set_autoplay_next_video_choice), item.getId() == 1); editor.apply(); @@ -2141,7 +2142,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis } private void updateHistory(long position) { - SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeActivity.this); boolean storeInHistory = sharedpreferences.getBoolean(getString(R.string.set_store_in_history), true); if (Helper.isLoggedIn(PeertubeActivity.this) && peertube != null && storeInHistory) { new Thread(() -> { @@ -2176,7 +2177,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis @Override public void onMediaItemTransition(MediaItem mediaItem, int reason) { - SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeActivity.this); boolean autoplayNextVideo = sharedpreferences.getBoolean(getString(R.string.set_autoplay_next_video_choice), true); if (reason == MEDIA_ITEM_TRANSITION_REASON_AUTO) { player.removeMediaItems(0, player.getMediaItemCount()); diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeEditUploadActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeEditUploadActivity.java index 680fb36f..0bd10d09 100644 --- a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeEditUploadActivity.java +++ b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeEditUploadActivity.java @@ -37,6 +37,7 @@ import androidx.appcompat.app.AlertDialog; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import androidx.lifecycle.ViewModelProvider; +import androidx.preference.PreferenceManager; import com.bumptech.glide.Glide; import com.bumptech.glide.load.resource.bitmap.CenterCrop; @@ -91,7 +92,7 @@ public class PeertubeEditUploadActivity extends BaseBarActivity { View view = binding.getRoot(); setContentView(view); - SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeEditUploadActivity.this); Bundle b = getIntent().getExtras(); diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeMainActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeMainActivity.java index d2e24f09..9dae9f49 100644 --- a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeMainActivity.java +++ b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeMainActivity.java @@ -16,11 +16,13 @@ package app.fedilab.android.peertube.activities; import static app.fedilab.android.mastodon.helper.Helper.PREF_INSTANCE; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID; +import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_SOFTWARE; +import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN; +import static app.fedilab.android.mastodon.helper.Helper.TAG; import static app.fedilab.android.peertube.helper.Helper.peertubeInformation; import android.annotation.SuppressLint; import android.app.Activity; -import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.database.sqlite.SQLiteDatabase; @@ -28,6 +30,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; @@ -44,6 +47,7 @@ import androidx.appcompat.widget.TooltipCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentStatePagerAdapter; +import androidx.preference.PreferenceManager; import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.ViewPager; @@ -127,7 +131,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { @SuppressLint("ApplySharedPref") public static void showRadioButtonDialogFullInstances(Activity activity, boolean storeInDb) { - final SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity); AlertDialog.Builder alt_bld = new AlertDialog.Builder(activity); alt_bld.setTitle(R.string.instance_choice); String instance = HelperInstance.getLiveInstance(activity); @@ -259,6 +263,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { invalidateOptionsMenu(); }).start(); } + Log.v(TAG, "logged: " + Helper.isLoggedIn(PeertubeMainActivity.this)); if (Helper.isLoggedIn(PeertubeMainActivity.this)) { binding.viewpager.setOffscreenPageLimit(5); } else { @@ -321,7 +326,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { } - final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeMainActivity.this); int search_cast = sharedpreferences.getInt(getString(R.string.set_cast_choice), 0); if (search_cast == 1) { super.discoverCast(); @@ -355,10 +360,9 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { private void refreshToken() { new Thread(() -> { - final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeMainActivity.this); String tokenStr = Helper.getToken(PeertubeMainActivity.this); String instance = HelperInstance.getLiveInstance(PeertubeMainActivity.this); - SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); String instanceShar = sharedpreferences.getString(PREF_INSTANCE, null); String userIdShar = sharedpreferences.getString(PREF_USER_ID, null); BaseAccount account = null; @@ -387,6 +391,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { if (token == null) { return; } + runOnUiThread(() -> { //To avoid a token issue with subscriptions, adding fragment is done when the token is refreshed. new Handler().post(() -> { @@ -398,6 +403,17 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { }); userMe = new RetrofitPeertubeAPI(PeertubeMainActivity.this, instance, token.getAccess_token()).verifyCredentials(); + account.token = token.getAccess_token(); + account.refresh_token = token.getRefresh_token(); + account.peertube_account = userMe.getAccount(); + account.software = Account.API.PEERTUBE.name(); + account.user_id = userMe.getAccount().getUserId(); + account.instance = userMe.getAccount().getHost(); + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putString(PREF_USER_TOKEN, token.getAccess_token()); + editor.putString(PREF_USER_SOFTWARE, account.software); + Log.v(TAG, "put 7: " + account.software); + editor.apply(); if (userMe != null && userMe.getAccount() != null) { account.peertube_account = userMe.getAccount(); try { @@ -405,7 +421,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { } catch (DBException e) { e.printStackTrace(); } - SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putString(PREF_USER_ID, account.user_id); editor.putBoolean(getString(R.string.set_autoplay_choice), userMe.isAutoPlayVideo()); editor.putBoolean(getString(R.string.set_store_in_history), userMe.isVideosHistoryEnabled()); @@ -531,7 +547,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { settingsItem.setVisible(false); mostLikedItem.setVisible(true); incognitoItem.setVisible(true); - final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeMainActivity.this); boolean checked = sharedpreferences.getBoolean(getString(R.string.set_store_in_history), true); incognitoItem.setChecked(checked); } else { @@ -634,7 +650,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { startActivity(intent); } else if (item.getItemId() == R.id.action_incognito) { item.setChecked(!item.isChecked()); - final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeMainActivity.this); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putBoolean(getString(R.string.set_store_in_history), item.isChecked()); editor.apply(); @@ -673,7 +689,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { AlertDialog.Builder alt_bld = new AlertDialog.Builder(this); alt_bld.setTitle(R.string.instance_choice); - final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeMainActivity.this); String acad = HelperInstance.getLiveInstance(PeertubeMainActivity.this); int i = 0; List acadInstances = AcadInstances.getInstances(); @@ -708,7 +724,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { super.onActivityResult(requestCode, resultCode, data); if (requestCode == PICK_INSTANCE && resultCode == Activity.RESULT_OK) { if (data != null && data.getData() != null) { - final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeMainActivity.this); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_INSTANCE, String.valueOf(data.getData())); editor.commit(); diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/SepiaSearchActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/SepiaSearchActivity.java index 57e3d849..37ee6287 100644 --- a/app/src/main/java/app/fedilab/android/peertube/activities/SepiaSearchActivity.java +++ b/app/src/main/java/app/fedilab/android/peertube/activities/SepiaSearchActivity.java @@ -17,7 +17,6 @@ package app.fedilab.android.peertube.activities; import static app.fedilab.android.peertube.activities.PeertubeActivity.hideKeyboard; import static app.fedilab.android.peertube.helper.Helper.peertubeInformation; -import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.view.MenuItem; @@ -27,6 +26,7 @@ import android.widget.ArrayAdapter; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentTransaction; +import androidx.preference.PreferenceManager; import com.mancj.materialsearchbar.MaterialSearchBar; @@ -65,7 +65,7 @@ public class SepiaSearchActivity extends BaseBarActivity { sepiaSearchVideo = new SepiaSearch(); sepiaSearchChannel = new SepiaSearch(); - SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(SepiaSearchActivity.this); sepiaSearchVideo.setCount(String.valueOf(sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE))); sepiaSearchVideo.setDurationMin(0); sepiaSearchVideo.setDurationMax(9999999); diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/ShowChannelActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/ShowChannelActivity.java index dc71bd01..338c47ce 100644 --- a/app/src/main/java/app/fedilab/android/peertube/activities/ShowChannelActivity.java +++ b/app/src/main/java/app/fedilab/android/peertube/activities/ShowChannelActivity.java @@ -46,6 +46,7 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentStatePagerAdapter; import androidx.lifecycle.ViewModelProvider; +import androidx.preference.PreferenceManager; import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.ViewPager; @@ -172,7 +173,7 @@ public class ShowChannelActivity extends BaseBarActivity { } private void manageChannel() { - SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(ShowChannelActivity.this); String accountIdRelation = channel.getAcct(); if (isLoggedIn(ShowChannelActivity.this)) { diff --git a/app/src/main/java/app/fedilab/android/peertube/client/RetrofitPeertubeAPI.java b/app/src/main/java/app/fedilab/android/peertube/client/RetrofitPeertubeAPI.java index 18a6edf6..69257c62 100644 --- a/app/src/main/java/app/fedilab/android/peertube/client/RetrofitPeertubeAPI.java +++ b/app/src/main/java/app/fedilab/android/peertube/client/RetrofitPeertubeAPI.java @@ -16,6 +16,7 @@ package app.fedilab.android.peertube.client; import static app.fedilab.android.mastodon.helper.Helper.PREF_INSTANCE; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID; +import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_SOFTWARE; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN; import static app.fedilab.android.mastodon.helper.Helper.TAG; @@ -32,6 +33,7 @@ import android.webkit.MimeTypeMap; import android.webkit.URLUtil; import androidx.documentfile.provider.DocumentFile; +import androidx.preference.PreferenceManager; import org.jetbrains.annotations.NotNull; import org.json.JSONException; @@ -52,6 +54,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; +import app.fedilab.android.BaseMainActivity; import app.fedilab.android.R; import app.fedilab.android.mastodon.client.entities.app.Account; import app.fedilab.android.mastodon.exception.DBException; @@ -121,7 +124,7 @@ public class RetrofitPeertubeAPI { _context = context; instance = HelperInstance.getLiveInstance(context); finalUrl = "https://" + HelperInstance.getLiveInstance(context) + "/api/v1/"; - SharedPreferences sharedpreferences = _context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(_context); count = String.valueOf(sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE)); String currentSensitive = sharedpreferences.getString(_context.getString(R.string.set_video_sensitive_choice), Helper.BLUR); if (currentSensitive.compareTo(Helper.DO_NOT_LIST) == 0) { @@ -138,7 +141,7 @@ public class RetrofitPeertubeAPI { this.instance = instance; this.token = token; finalUrl = "https://" + instance + "/api/v1/"; - SharedPreferences sharedpreferences = _context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(_context); count = String.valueOf(sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE)); String currentSensitive = sharedpreferences.getString(_context.getString(R.string.set_video_sensitive_choice), Helper.BLUR); if (currentSensitive.compareTo(Helper.DO_NOT_LIST) == 0) { @@ -158,7 +161,7 @@ public class RetrofitPeertubeAPI { String instance = host; try { UserMe userMe = new RetrofitPeertubeAPI(activity, instance, token).verifyCredentials(); - Log.v(TAG, "userMe: " + userMe); + peertubeAccount = userMe.getAccount(); } catch (Error error) { Error.displayError(activity, error); @@ -170,7 +173,7 @@ public class RetrofitPeertubeAPI { instance = URLDecoder.decode(instance, "utf-8"); } catch (UnsupportedEncodingException ignored) { } - SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity); account.token = token; account.client_id = client_id; account.client_secret = client_secret; @@ -179,12 +182,16 @@ public class RetrofitPeertubeAPI { account.api = Account.API.PEERTUBE; account.software = Account.API.PEERTUBE.name(); account.peertube_account = peertubeAccount; - account.user_id = peertubeAccount.getId(); + account.user_id = peertubeAccount.getUserId(); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_USER_ID, account.user_id); editor.putString(PREF_INSTANCE, host); editor.putString(PREF_USER_TOKEN, token); + editor.putString(PREF_USER_SOFTWARE, account.software); + Log.v(TAG, "put 8: " + account.software); editor.apply(); + + Log.v(TAG, "PREF_USER_SOFTWARE: " + account.software); try { new Account(activity).insertOrUpdate(account); } catch (DBException e) { @@ -215,7 +222,7 @@ public class RetrofitPeertubeAPI { .addConverterFactory(GsonConverterFactory.create()) .client(okHttpClient) .build(); - SharedPreferences sharedpreferences = _context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(_context); if (token == null) { token = Helper.getToken(_context); } @@ -242,6 +249,7 @@ public class RetrofitPeertubeAPI { public Token manageToken(OauthParams oauthParams) throws Error { PeertubeService peertubeService = init(); Call refreshTokenCall = null; + Log.v(TAG, "oauthParams.getGrant_type(): " + oauthParams.getGrant_type()); if (oauthParams.getGrant_type().compareTo("password") == 0) { refreshTokenCall = peertubeService.createToken(oauthParams.getClient_id(), oauthParams.getClient_secret(), oauthParams.getGrant_type(), oauthParams.getUsername(), oauthParams.getPassword()); } else if (oauthParams.getGrant_type().compareTo("refresh_token") == 0) { @@ -254,11 +262,12 @@ public class RetrofitPeertubeAPI { if (response.isSuccessful()) { Token tokenReply = response.body(); if (oauthParams.getGrant_type().compareTo("refresh_token") == 0 && tokenReply != null) { - SharedPreferences sharedpreferences = _context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(_context); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_USER_TOKEN, tokenReply.getAccess_token()); editor.apply(); SQLiteDatabase db = Sqlite.getInstance(_context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + BaseMainActivity.currentToken = tokenReply.getAccess_token(); new Account(_context).updatePeertubeToken(tokenReply); } return tokenReply; diff --git a/app/src/main/java/app/fedilab/android/peertube/client/data/VideoData.java b/app/src/main/java/app/fedilab/android/peertube/client/data/VideoData.java index 78db69ea..1e50475f 100644 --- a/app/src/main/java/app/fedilab/android/peertube/client/data/VideoData.java +++ b/app/src/main/java/app/fedilab/android/peertube/client/data/VideoData.java @@ -18,6 +18,8 @@ package app.fedilab.android.peertube.client.data; import android.content.Context; import android.content.SharedPreferences; +import androidx.preference.PreferenceManager; + import com.google.gson.annotations.SerializedName; import java.io.Serializable; @@ -133,7 +135,7 @@ public class VideoData implements Serializable { } public String getFileUrl(String resolution, Context context) { - SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); int mode = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL); List files = getAllFile(context); if (files != null && files.size() > 0) { diff --git a/app/src/main/java/app/fedilab/android/peertube/drawer/AboutInstanceAdapter.java b/app/src/main/java/app/fedilab/android/peertube/drawer/AboutInstanceAdapter.java index 5ca20c1a..4d133d5b 100644 --- a/app/src/main/java/app/fedilab/android/peertube/drawer/AboutInstanceAdapter.java +++ b/app/src/main/java/app/fedilab/android/peertube/drawer/AboutInstanceAdapter.java @@ -37,6 +37,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.widget.PopupMenu; +import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.RecyclerView; import java.util.List; @@ -127,7 +128,7 @@ public class AboutInstanceAdapter extends RecyclerView.Adapter { - final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_INSTANCE, aboutInstance.getHost()); editor.commit(); diff --git a/app/src/main/java/app/fedilab/android/peertube/drawer/ChannelListAdapter.java b/app/src/main/java/app/fedilab/android/peertube/drawer/ChannelListAdapter.java index 53953f15..ed8d41c7 100644 --- a/app/src/main/java/app/fedilab/android/peertube/drawer/ChannelListAdapter.java +++ b/app/src/main/java/app/fedilab/android/peertube/drawer/ChannelListAdapter.java @@ -34,6 +34,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.widget.PopupMenu; +import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.RecyclerView; import java.util.List; @@ -136,7 +137,7 @@ public class ChannelListAdapter extends RecyclerView.Adapter. */ import static android.content.Context.DOWNLOAD_SERVICE; -import static android.content.Context.MODE_PRIVATE; import static app.fedilab.android.mastodon.helper.Helper.PREF_INSTANCE; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN; @@ -52,6 +51,7 @@ import android.widget.Toast; import androidx.appcompat.app.AlertDialog; import androidx.core.content.ContextCompat; +import androidx.preference.PreferenceManager; import com.avatarfirst.avatargenlib.AvatarGenerator; import com.bumptech.glide.Glide; @@ -455,7 +455,7 @@ public class Helper { } else { webView = rootView.findViewById(webviewId); } - final SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setUseWideViewPort(true); @@ -563,13 +563,14 @@ public class Helper { * @param activity Activity */ public static void logoutNoRemoval(Activity activity) { - SharedPreferences sharedpreferences = activity.getSharedPreferences(APP_PREFS, MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_USER_TOKEN, null); editor.putString(CLIENT_ID, null); editor.putString(CLIENT_SECRET, null); editor.putString(PREF_USER_ID, null); editor.putString(PREF_INSTANCE, null); + // editor.putString(PREF_USER_SOFTWARE, null); editor.apply(); Intent loginActivity = new Intent(activity, PeertubeMainActivity.class); activity.startActivity(loginActivity); @@ -618,7 +619,7 @@ public class Helper { * @return PeertubeMainActivity.TypeOfConnection */ public static PeertubeMainActivity.TypeOfConnection isLoggedInType(Context context) { - SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); String prefKeyOauthTokenT = sharedpreferences.getString(PREF_USER_TOKEN, null); String prefSoftware = sharedpreferences.getString(PREF_SOFTWARE, null); if (prefKeyOauthTokenT != null && prefSoftware == null) { @@ -632,7 +633,7 @@ public class Helper { public static String getToken(Context context) { if (isLoggedInType(context) == PeertubeMainActivity.TypeOfConnection.NORMAL) { - SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); return sharedpreferences.getString(PREF_USER_TOKEN, null); } else { return null; @@ -659,14 +660,14 @@ public class Helper { public static boolean isOwner(Context context, AccountData.PeertubeAccount account) { - SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); String userId = sharedpreferences.getString(PREF_USER_ID, ""); String instance = sharedpreferences.getString(PREF_INSTANCE, ""); return account.getUserId().compareTo(userId) == 0 && account.getHost().compareTo(instance) == 0; } public static boolean isVideoOwner(Context context, VideoData.Video video) { - SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); String userId = sharedpreferences.getString(PREF_USER_ID, null); String instance = sharedpreferences.getString(PREF_INSTANCE, null); if (video == null) { @@ -696,7 +697,7 @@ public class Helper { if (files == null || files.size() == 0) { return null; } - SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); int video_quality = sharedpreferences.getInt(Helper.SET_QUALITY_MODE, Helper.QUALITY_HIGH); if (video_quality == QUALITY_HIGH) { return files.get(0); diff --git a/app/src/main/java/app/fedilab/android/peertube/helper/HelperInstance.java b/app/src/main/java/app/fedilab/android/peertube/helper/HelperInstance.java index 325760c5..fbffd98d 100644 --- a/app/src/main/java/app/fedilab/android/peertube/helper/HelperInstance.java +++ b/app/src/main/java/app/fedilab/android/peertube/helper/HelperInstance.java @@ -19,6 +19,8 @@ import static app.fedilab.android.mastodon.helper.Helper.PREF_INSTANCE; import android.content.Context; import android.content.SharedPreferences; +import androidx.preference.PreferenceManager; + public class HelperInstance { @@ -30,7 +32,7 @@ public class HelperInstance { * @return String domain instance */ public static String getLiveInstance(Context context) { - final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); return sharedpreferences.getString(PREF_INSTANCE, null); } diff --git a/app/src/main/java/app/fedilab/android/peertube/helper/SwitchAccountHelper.java b/app/src/main/java/app/fedilab/android/peertube/helper/SwitchAccountHelper.java index a3705eb6..21d10d81 100644 --- a/app/src/main/java/app/fedilab/android/peertube/helper/SwitchAccountHelper.java +++ b/app/src/main/java/app/fedilab/android/peertube/helper/SwitchAccountHelper.java @@ -14,16 +14,19 @@ package app.fedilab.android.peertube.helper; * You should have received a copy of the GNU General Public License along with TubeLab; if not, * see . */ -import static android.content.Context.MODE_PRIVATE; import static app.fedilab.android.mastodon.helper.Helper.PREF_INSTANCE; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID; +import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_SOFTWARE; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN; +import static app.fedilab.android.mastodon.helper.Helper.TAG; import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; +import android.util.Log; import androidx.appcompat.app.AlertDialog; +import androidx.preference.PreferenceManager; import java.util.List; @@ -58,9 +61,11 @@ public class SwitchAccountHelper { } builderSingle.setAdapter(accountsListAdapter, (dialog, which) -> { final BaseAccount account = accountArray[which]; - SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PREF_USER_TOKEN, account.token); + editor.putString(PREF_USER_SOFTWARE, account.software); + Log.v(TAG, "put 1: " + account.software); editor.putString(PREF_INSTANCE, account.instance); editor.putString(PREF_USER_ID, account.user_id); editor.apply(); diff --git a/app/src/main/java/app/fedilab/android/peertube/services/GlobalUploadObserver.java b/app/src/main/java/app/fedilab/android/peertube/services/GlobalUploadObserver.java index dce27c45..aa9220c6 100644 --- a/app/src/main/java/app/fedilab/android/peertube/services/GlobalUploadObserver.java +++ b/app/src/main/java/app/fedilab/android/peertube/services/GlobalUploadObserver.java @@ -18,6 +18,8 @@ import android.annotation.SuppressLint; import android.content.Context; import android.content.SharedPreferences; +import androidx.preference.PreferenceManager; + import net.gotev.uploadservice.data.UploadInfo; import net.gotev.uploadservice.network.ServerResponse; import net.gotev.uploadservice.observer.request.RequestObserverDelegate; @@ -55,7 +57,7 @@ public class GlobalUploadObserver implements RequestObserverDelegate { if (response.has("video")) { String videoUuid = response.getJSONObject("video").getString("uuid"); - SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(Helper.VIDEO_ID, videoUuid); editor.commit(); diff --git a/app/src/main/java/app/fedilab/android/peertube/sqlite/StoredInstanceDAO.java b/app/src/main/java/app/fedilab/android/peertube/sqlite/StoredInstanceDAO.java index 5374f6cb..fb185035 100644 --- a/app/src/main/java/app/fedilab/android/peertube/sqlite/StoredInstanceDAO.java +++ b/app/src/main/java/app/fedilab/android/peertube/sqlite/StoredInstanceDAO.java @@ -22,13 +22,14 @@ import android.content.SharedPreferences; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; +import androidx.preference.PreferenceManager; + import com.google.gson.Gson; import java.util.ArrayList; import java.util.List; import app.fedilab.android.peertube.client.data.InstanceData; -import app.fedilab.android.peertube.helper.Helper; import app.fedilab.android.peertube.helper.HelperInstance; import app.fedilab.android.sqlite.Sqlite; @@ -89,7 +90,7 @@ public class StoredInstanceDAO { return true; } ContentValues values = new ContentValues(); - SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); String userId = sharedpreferences.getString(PREF_USER_ID, null); String instance = HelperInstance.getLiveInstance(context); diff --git a/app/src/main/java/app/fedilab/android/peertube/worker/NotificationsWorker.java b/app/src/main/java/app/fedilab/android/peertube/worker/NotificationsWorker.java index 73e21565..c2a923a1 100644 --- a/app/src/main/java/app/fedilab/android/peertube/worker/NotificationsWorker.java +++ b/app/src/main/java/app/fedilab/android/peertube/worker/NotificationsWorker.java @@ -30,6 +30,7 @@ import android.text.Html; import androidx.annotation.NonNull; import androidx.core.app.NotificationCompat; +import androidx.preference.PreferenceManager; import androidx.work.ForegroundInfo; import androidx.work.Worker; import androidx.work.WorkerParameters; @@ -90,7 +91,7 @@ public class NotificationsWorker extends Worker { @SuppressWarnings({"SwitchStatementWithoutDefaultBranch", "DuplicateBranchesInSwitch"}) private void fetchNotification() { List accounts = new Account(getApplicationContext()).getPeertubeAccounts(); - SharedPreferences sharedpreferences = getApplicationContext().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor editor = sharedpreferences.edit(); for (BaseAccount account : accounts) { RetrofitPeertubeAPI retrofitPeertubeAPI = new RetrofitPeertubeAPI(getApplicationContext(), account.instance, account.token); diff --git a/app/src/main/res/layouts/peertube/layout/exo_player_control_view_peertube.xml b/app/src/main/res/layouts/peertube/layout/exo_player_control_view.xml similarity index 100% rename from app/src/main/res/layouts/peertube/layout/exo_player_control_view_peertube.xml rename to app/src/main/res/layouts/peertube/layout/exo_player_control_view.xml