From 2553b4835b7a76f56bc4a35b190973cfeb2b5ae3 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 30 Jul 2022 18:47:30 +0200 Subject: [PATCH] Some fixes --- app/build.gradle | 2 + .../android/activities/ProfileActivity.java | 4 +- .../activities/WebviewConnectActivity.java | 53 ++++++++++--------- .../android/ui/drawer/ComposeAdapter.java | 10 +++- .../ui/fragment/media/FragmentMedia.java | 22 ++++---- .../FragmentMastodonConversation.java | 2 +- .../timeline/FragmentMastodonTimeline.java | 25 ++++++--- .../ui/pageadapter/FedilabPageAdapter.java | 2 +- app/src/main/res/values/strings.xml | 1 + 9 files changed, 72 insertions(+), 49 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 613ef003..29a9501a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,6 +24,7 @@ android { } } compileOptions { + coreLibraryDesugaringEnabled true sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } @@ -128,4 +129,5 @@ dependencies { androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' // debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1' + coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' } \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java b/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java index 16b5d297..7edfebec 100644 --- a/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java @@ -479,7 +479,9 @@ public class ProfileActivity extends BaseActivity { * This methode is called to update the view once an action has been performed */ private void updateAccount() { - + if (currentAccount == null || account == null) { + return; + } //The value for account is from same server so id can be used if (account.id.equals(currentAccount.user_id)) { binding.accountFollow.setVisibility(View.GONE); diff --git a/app/src/main/java/app/fedilab/android/activities/WebviewConnectActivity.java b/app/src/main/java/app/fedilab/android/activities/WebviewConnectActivity.java index 5ac5c306..f33fecf3 100644 --- a/app/src/main/java/app/fedilab/android/activities/WebviewConnectActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/WebviewConnectActivity.java @@ -207,34 +207,37 @@ public class WebviewConnectActivity extends BaseActivity { String scope = requestedAdmin ? Helper.OAUTH_SCOPES_ADMIN : Helper.OAUTH_SCOPES; oauthVM.createToken(currentInstanceLogin, "authorization_code", client_idLogin, client_secretLogin, Helper.REDIRECT_CONTENT_WEB, scope, code) .observe(WebviewConnectActivity.this, tokenObj -> { - Account account = new Account(); - account.client_id = client_idLogin; - account.client_secret = client_secretLogin; - account.token = tokenObj.token_type + " " + tokenObj.access_token; - account.api = apiLogin; - account.software = softwareLogin; - account.instance = currentInstanceLogin; - //API call to retrieve account information for the new token - AccountsVM accountsVM = new ViewModelProvider(WebviewConnectActivity.this).get(AccountsVM.class); - accountsVM.getConnectedAccount(currentInstanceLogin, account.token).observe(WebviewConnectActivity.this, mastodonAccount -> { - if (mastodonAccount != null) { - account.mastodon_account = mastodonAccount; - account.user_id = mastodonAccount.id; - //We check if user have really moderator rights - if (requestedAdmin) { - AdminVM adminVM = new ViewModelProvider(WebviewConnectActivity.this).get(AdminVM.class); - adminVM.getAccount(account.instance, account.token, account.user_id).observe(WebviewConnectActivity.this, adminAccount -> { - account.admin = adminAccount != null; + if (tokenObj != null) { + Account account = new Account(); + account.client_id = client_idLogin; + account.client_secret = client_secretLogin; + account.token = tokenObj.token_type + " " + tokenObj.access_token; + account.api = apiLogin; + account.software = softwareLogin; + account.instance = currentInstanceLogin; + //API call to retrieve account information for the new token + AccountsVM accountsVM = new ViewModelProvider(WebviewConnectActivity.this).get(AccountsVM.class); + accountsVM.getConnectedAccount(currentInstanceLogin, account.token).observe(WebviewConnectActivity.this, mastodonAccount -> { + if (mastodonAccount != null) { + account.mastodon_account = mastodonAccount; + account.user_id = mastodonAccount.id; + //We check if user have really moderator rights + if (requestedAdmin) { + AdminVM adminVM = new ViewModelProvider(WebviewConnectActivity.this).get(AdminVM.class); + adminVM.getAccount(account.instance, account.token, account.user_id).observe(WebviewConnectActivity.this, adminAccount -> { + account.admin = adminAccount != null; + proceedLogin(WebviewConnectActivity.this, account); + }); + } else { proceedLogin(WebviewConnectActivity.this, account); - }); + } } else { - proceedLogin(WebviewConnectActivity.this, account); + Toasty.error(WebviewConnectActivity.this, getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); } - } else { - Toasty.error(WebviewConnectActivity.this, getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); - } - - }); + }); + } else { + Toasty.error(WebviewConnectActivity.this, getString(R.string.toast_token), Toasty.LENGTH_SHORT).show(); + } }); return true; } else { diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java index ccbe3cd0..264fb227 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java @@ -1298,13 +1298,19 @@ public class ComposeAdapter extends RecyclerView.Adapter max_car + 1) { + int max_car = MastodonHelper.getInstanceMaxChars(context); + if (currentLength > max_car) { + holder.binding.characterCount.setTextColor(Color.RED); + } else { + holder.binding.characterCount.setTextColor(holder.binding.content.getTextColors()); + } + /*if (currentLength > max_car + 1) { holder.binding.contentSpoiler.setText(s.delete(max_car - holder.binding.content.getText().length(), (currentLength - holder.binding.content.getText().length()))); buttonVisibility(holder); } else if (currentLength > max_car) { buttonVisibility(holder); holder.binding.contentSpoiler.setText(s.delete(cPosition, cPosition + 1)); - } + }*/ statusList.get(holder.getBindingAdapterPosition()).spoiler_text = s.toString(); if (s.toString().trim().length() < 2) { buttonVisibility(holder); diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/media/FragmentMedia.java b/app/src/main/java/app/fedilab/android/ui/fragment/media/FragmentMedia.java index 44f9547a..056c08e0 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/media/FragmentMedia.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/media/FragmentMedia.java @@ -37,12 +37,12 @@ import androidx.preference.PreferenceManager; import com.bumptech.glide.Glide; import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.transition.Transition; +import com.google.android.exoplayer2.ExoPlayer; +import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.Player; -import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.exoplayer2.source.ProgressiveMediaSource; import com.google.android.exoplayer2.upstream.DataSource; -import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; -import com.google.android.exoplayer2.util.Util; +import com.google.android.exoplayer2.upstream.DefaultDataSource; import java.util.Timer; @@ -61,7 +61,7 @@ import app.fedilab.android.webview.FedilabWebViewClient; public class FragmentMedia extends Fragment { - private SimpleExoPlayer player; + private ExoPlayer player; private Timer timer; private String url; private boolean canSwipe; @@ -261,26 +261,26 @@ public class FragmentMedia extends Fragment { binding.mediaVideo.setVisibility(View.VISIBLE); Uri uri = Uri.parse(url); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); - String userAgent = sharedpreferences.getString(getString(R.string.SET_CUSTOM_USER_AGENT), Helper.USER_AGENT); int video_cache = sharedpreferences.getInt(getString(R.string.SET_VIDEO_CACHE), Helper.DEFAULT_VIDEO_CACHE_MB); ProgressiveMediaSource videoSource; + MediaItem mediaItem = new MediaItem.Builder().setUri(uri).build(); if (video_cache == 0) { - DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(requireActivity(), - Util.getUserAgent(requireActivity(), userAgent), null); + DataSource.Factory dataSourceFactory = new DefaultDataSource.Factory(requireActivity()); videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory) - .createMediaSource(uri); + .createMediaSource(mediaItem); } else { CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(requireActivity()); videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory) - .createMediaSource(uri); + .createMediaSource(mediaItem); } - player = new SimpleExoPlayer.Builder(requireActivity()).build(); + player = new ExoPlayer.Builder(requireActivity()).build(); if (type.equalsIgnoreCase("gifv")) player.setRepeatMode(Player.REPEAT_MODE_ONE); binding.mediaVideo.setPlayer(player); binding.loader.setVisibility(View.GONE); binding.mediaPicture.setVisibility(View.GONE); - player.prepare(videoSource); + player.setMediaSource(videoSource); + player.prepare(); player.setPlayWhenReady(true); } diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonConversation.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonConversation.java index 74485bb1..e5aef311 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonConversation.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonConversation.java @@ -137,7 +137,7 @@ public class FragmentMastodonConversation extends Fragment { } }); binding.swipeContainer.setOnRefreshListener(() -> { - if (this.conversations.size() > 0) { + if (this.conversations != null && this.conversations.size() > 0) { binding.swipeContainer.setRefreshing(true); max_id = null; flagLoading = false; diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java index f1aa8fd7..48f2defa 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -61,6 +61,7 @@ import app.fedilab.android.ui.drawer.StatusAdapter; import app.fedilab.android.viewmodel.mastodon.AccountsVM; import app.fedilab.android.viewmodel.mastodon.SearchVM; import app.fedilab.android.viewmodel.mastodon.TimelinesVM; +import es.dmoral.toasty.Toasty; public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.FetchMoreCallBack { @@ -809,19 +810,27 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. SearchVM searchVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, SearchVM.class); searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, search.trim(), null, null, false, true, false, 0, null, null, MastodonHelper.STATUSES_PER_CALL) .observe(getViewLifecycleOwner(), results -> { - Statuses statuses = new Statuses(); - statuses.statuses = results.statuses; - statuses.pagination = new Pagination(); - initializeStatusesCommonView(statuses); + if (results != null) { + Statuses statuses = new Statuses(); + statuses.statuses = results.statuses; + statuses.pagination = new Pagination(); + initializeStatusesCommonView(statuses); + } else { + Toasty.error(requireActivity(), getString(R.string.toast_error), Toasty.LENGTH_LONG).show(); + } }); } else if (searchCache != null) { SearchVM searchVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, SearchVM.class); searchVM.searchCache(BaseMainActivity.currentInstance, BaseMainActivity.currentUserID, searchCache.trim()) .observe(getViewLifecycleOwner(), results -> { - Statuses statuses = new Statuses(); - statuses.statuses = results.statuses; - statuses.pagination = new Pagination(); - initializeStatusesCommonView(statuses); + if (results != null) { + Statuses statuses = new Statuses(); + statuses.statuses = results.statuses; + statuses.pagination = new Pagination(); + initializeStatusesCommonView(statuses); + } else { + Toasty.error(requireActivity(), getString(R.string.toast_error), Toasty.LENGTH_LONG).show(); + } }); } else if (timelineType == Timeline.TimeLineEnum.FAVOURITE_TIMELINE) { if (direction == null) { diff --git a/app/src/main/java/app/fedilab/android/ui/pageadapter/FedilabPageAdapter.java b/app/src/main/java/app/fedilab/android/ui/pageadapter/FedilabPageAdapter.java index cda3578d..9904904b 100644 --- a/app/src/main/java/app/fedilab/android/ui/pageadapter/FedilabPageAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/pageadapter/FedilabPageAdapter.java @@ -108,7 +108,7 @@ public class FedilabPageAdapter extends FragmentStatePagerAdapter { } else if (pinnedTimeline.type == Timeline.TimeLineEnum.TAG) { bundle.putSerializable(Helper.ARG_TAG_TIMELINE, pinnedTimeline.tagTimeline); } else if (pinnedTimeline.type == Timeline.TimeLineEnum.REMOTE) { - bundle.putSerializable(Helper.ARG_REMOTE_INSTANCE, pinnedTimeline); + bundle.putSerializable(Helper.ARG_REMOTE_INSTANCE, pinned); } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fc65901e..e9b406ad 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -991,6 +991,7 @@ My account Set your max char count Release notes + The app failed to get a token