From 8210347e66907866756d3910b675d83f14895c0f Mon Sep 17 00:00:00 2001 From: Rania Pilioura Date: Sat, 8 May 2021 06:35:57 +0300 Subject: [PATCH 1/9] Disable scrolling when profile has no posts Fix #1093 --- .../instagrabber/fragments/main/ProfileFragment.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java index 75802ac0..a3db54e0 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -40,6 +40,7 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.snackbar.BaseTransientBottomBar; import com.google.android.material.snackbar.Snackbar; import com.google.common.collect.ImmutableList; @@ -686,6 +687,13 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe } else { binding.postsRecyclerView.refresh(); } + + //Disable scrolling when profile has no posts + if (profileModel.getMediaCount() == 0){ + AppBarLayout.LayoutParams toolbarLayoutParams = (AppBarLayout.LayoutParams) fragmentActivity.getCollapsingToolbarView().getLayoutParams(); + toolbarLayoutParams.setScrollFlags(0); + } + profileDetailsBinding.isVerified.setVisibility(profileModel.isVerified() ? View.VISIBLE : View.GONE); profileDetailsBinding.isPrivate.setVisibility(profileModel.isPrivate() ? View.VISIBLE : View.GONE); final long profileId = profileModel.getPk(); From 798d646674c710c7ad406882655024fe10202d88 Mon Sep 17 00:00:00 2001 From: Rania Pilioura Date: Sat, 8 May 2021 06:45:10 +0300 Subject: [PATCH 2/9] Add margin between chat bubble and bottom controls in DM Fix #1135 --- app/src/main/res/layout/fragment_direct_messages_thread.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/layout/fragment_direct_messages_thread.xml b/app/src/main/res/layout/fragment_direct_messages_thread.xml index 96b0bc34..0da43ae3 100644 --- a/app/src/main/res/layout/fragment_direct_messages_thread.xml +++ b/app/src/main/res/layout/fragment_direct_messages_thread.xml @@ -10,6 +10,7 @@ android:id="@+id/chats" android:layout_width="0dp" android:layout_height="0dp" + android:layout_marginBottom="8dp" android:scrollbars="none" app:layout_constraintBottom_toTopOf="@id/chats_barrier" app:layout_constraintEnd_toEndOf="parent" From 247a2b4bf548246528d7735f3705229bf3573267 Mon Sep 17 00:00:00 2001 From: Rania Pilioura Date: Sat, 8 May 2021 06:58:43 +0300 Subject: [PATCH 3/9] Increase profile picture download button margin Fix #1061 --- app/src/main/res/layout/dialog_profilepic.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/res/layout/dialog_profilepic.xml b/app/src/main/res/layout/dialog_profilepic.xml index c589cad3..adb825d3 100644 --- a/app/src/main/res/layout/dialog_profilepic.xml +++ b/app/src/main/res/layout/dialog_profilepic.xml @@ -35,6 +35,8 @@ style="@style/Widget.MaterialComponents.Button.TextButton" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginRight="8dp" + android:layout_marginBottom="4dp" android:layout_gravity="bottom|end" android:backgroundTint="@color/black_a50" android:text="@string/action_download" From 6502bceb2e45d530977de00d99715336c78cade5 Mon Sep 17 00:00:00 2001 From: Rania Pilioura Date: Sat, 8 May 2021 14:59:24 +0300 Subject: [PATCH 4/9] Make AppBarLayout.LayoutParams toolbarLayoutParams final --- .../java/awais/instagrabber/fragments/main/ProfileFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java index a3db54e0..ca279646 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -690,7 +690,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe //Disable scrolling when profile has no posts if (profileModel.getMediaCount() == 0){ - AppBarLayout.LayoutParams toolbarLayoutParams = (AppBarLayout.LayoutParams) fragmentActivity.getCollapsingToolbarView().getLayoutParams(); + final AppBarLayout.LayoutParams toolbarLayoutParams = (AppBarLayout.LayoutParams) fragmentActivity.getCollapsingToolbarView().getLayoutParams(); toolbarLayoutParams.setScrollFlags(0); } From 78484a86aca3e09bda679d1872eeb6f895746ae7 Mon Sep 17 00:00:00 2001 From: Rania Pilioura Date: Fri, 14 May 2021 14:19:59 +0300 Subject: [PATCH 5/9] Trying to solve merge conflicts disable scrolling functionality first try removed --- .../fragments/main/ProfileFragment.java | 62 +++++++------------ 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java index ca279646..5e40818f 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -27,7 +27,8 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.content.res.AppCompatResources; -import androidx.coordinatorlayout.widget.CoordinatorLayout; +import androidx.constraintlayout.motion.widget.MotionLayout; +import androidx.constraintlayout.motion.widget.MotionScene; import androidx.core.content.PermissionChecker; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -109,7 +110,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe private static final int STORAGE_PERM_REQUEST_CODE_FOR_SELECTION = 8030; private MainActivity fragmentActivity; - private CoordinatorLayout root; + private MotionLayout root; private FragmentProfileBinding binding; private boolean isLoggedIn; private String cookie; @@ -251,23 +252,15 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe final View profilePicView, final View mainPostImage, final int position) { - final PostViewV2Fragment.Builder builder = PostViewV2Fragment - .builder(feedModel); - if (position >= 0) { - builder.setPosition(position); + final NavController navController = NavHostFragment.findNavController(ProfileFragment.this); + final Bundle bundle = new Bundle(); + bundle.putSerializable(PostViewV2Fragment.ARG_MEDIA, feedModel); + bundle.putInt(PostViewV2Fragment.ARG_SLIDER_POSITION, position); + try { + navController.navigate(R.id.action_global_post_view, bundle); + } catch (Exception e) { + Log.e(TAG, "openPostDialog: ", e); } - if (!layoutPreferences.isAnimationDisabled()) { - builder.setSharedProfilePicElement(profilePicView) - .setSharedMainPostElement(mainPostImage); - } - final PostViewV2Fragment postViewV2Fragment = builder.build(); - postViewV2Fragment.setOnDeleteListener(() -> { - postViewV2Fragment.dismiss(); - binding.postsRecyclerView.refresh(); - }); - final FragmentManager fragmentManager = getChildFragmentManager(); - if (fragmentManager.isDestroyed() || fragmentManager.isStateSaved()) return; - postViewV2Fragment.show(fragmentManager, "post_view"); } }; private final FeedAdapterV2.SelectionModeCallback selectionModeCallback = new FeedAdapterV2.SelectionModeCallback() { @@ -346,26 +339,22 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe final boolean isSame = ("@" + profileModelUsername).equals(this.username); if (isSame) { setUsernameDelayed(); - fragmentActivity.setCollapsingView(profileDetailsBinding.getRoot()); shouldRefresh = false; return root; } } if (username == null || !username.equals(this.username)) { - fragmentActivity.setCollapsingView(profileDetailsBinding.getRoot()); shouldRefresh = true; return root; } } setUsernameDelayed(); - fragmentActivity.setCollapsingView(profileDetailsBinding.getRoot()); shouldRefresh = false; return root; } binding = FragmentProfileBinding.inflate(inflater, container, false); root = binding.getRoot(); - profileDetailsBinding = LayoutProfileDetailsBinding.inflate(inflater, fragmentActivity.getCollapsingToolbarView(), false); - fragmentActivity.setCollapsingView(profileDetailsBinding.getRoot()); + profileDetailsBinding = binding.header; return root; } @@ -555,14 +544,6 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe } } - @Override - public void onDestroyView() { - super.onDestroyView(); - if (profileDetailsBinding != null) { - fragmentActivity.removeCollapsingView(profileDetailsBinding.getRoot()); - } - } - @Override public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); @@ -590,7 +571,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe setUsernameDelayed(); } if (TextUtils.isEmpty(username) && !isLoggedIn) { - profileDetailsBinding.infoContainer.setVisibility(View.GONE); + binding.header.getRoot().setVisibility(View.GONE); binding.swipeRefreshLayout.setEnabled(false); binding.privatePage1.setImageResource(R.drawable.ic_outline_info_24); binding.privatePage2.setText(R.string.no_acc); @@ -688,12 +669,6 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe binding.postsRecyclerView.refresh(); } - //Disable scrolling when profile has no posts - if (profileModel.getMediaCount() == 0){ - final AppBarLayout.LayoutParams toolbarLayoutParams = (AppBarLayout.LayoutParams) fragmentActivity.getCollapsingToolbarView().getLayoutParams(); - toolbarLayoutParams.setScrollFlags(0); - } - profileDetailsBinding.isVerified.setVisibility(profileModel.isVerified() ? View.VISIBLE : View.GONE); profileDetailsBinding.isPrivate.setVisibility(profileModel.isPrivate() ? View.VISIBLE : View.GONE); final long profileId = profileModel.getPk(); @@ -1217,6 +1192,17 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe .setFeedItemCallback(feedItemCallback) .setSelectionModeCallback(selectionModeCallback) .init(); + binding.postsRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrolled(@NonNull final RecyclerView recyclerView, final int dx, final int dy) { + super.onScrolled(recyclerView, dx, dy); + final boolean canScrollVertically = recyclerView.canScrollVertically(-1); + final MotionScene.Transition transition = root.getTransition(R.id.transition); + if (transition != null) { + transition.setEnable(!canScrollVertically); + } + } + }); binding.swipeRefreshLayout.setRefreshing(true); postsSetupDone = true; } From 86b724d998c92eaca344a1d2d73588280fdab8e4 Mon Sep 17 00:00:00 2001 From: Rania Pilioura Date: Mon, 17 May 2021 05:38:30 +0300 Subject: [PATCH 6/9] Disable scrolling on blank or private profiles works with MotionLayout See #1219 --- .../awais/instagrabber/fragments/main/ProfileFragment.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java index 45564d61..88f4e838 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -757,6 +757,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe final String postCount = String.valueOf(profileModel.getMediaCount()); + SpannableStringBuilder span = new SpannableStringBuilder(getResources().getQuantityString(R.plurals.main_posts_count, profileModel.getMediaCount() > 2000000000L ? 2000000000 @@ -915,7 +916,13 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe binding.privatePage2.setVisibility(View.VISIBLE); binding.postsRecyclerView.setVisibility(View.GONE); binding.swipeRefreshLayout.setRefreshing(false); + root.getTransition(R.id.transition).setEnable(false); } + + if (profileModel.getMediaCount() == 0) { + root.getTransition(R.id.transition).setEnable(false); + } + } private void setupButtons(final long profileId) { From 89139618a5fea9d0054ef051d453916264246711 Mon Sep 17 00:00:00 2001 From: Rania Pilioura Date: Mon, 17 May 2021 05:44:19 +0300 Subject: [PATCH 7/9] Add margin between chat bubble and bottom controls in DM Similar previous commmit was reverted Fix #1135 --- app/src/main/res/layout/fragment_direct_messages_thread.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/layout/fragment_direct_messages_thread.xml b/app/src/main/res/layout/fragment_direct_messages_thread.xml index 50120027..df098c98 100644 --- a/app/src/main/res/layout/fragment_direct_messages_thread.xml +++ b/app/src/main/res/layout/fragment_direct_messages_thread.xml @@ -11,6 +11,7 @@ android:id="@+id/chats" android:layout_width="match_parent" android:layout_height="0dp" + android:layout_marginBottom="8dp" android:layout_weight="1" android:scrollbars="none" tools:listitem="@layout/layout_dm_base" /> From c0cc45bcc33b30c38bdf84eb635c73a636158913 Mon Sep 17 00:00:00 2001 From: Rania Pilioura Date: Mon, 17 May 2021 05:51:56 +0300 Subject: [PATCH 8/9] Format code --- .../fragments/main/ProfileFragment.java | 122 ++++++++++-------- 1 file changed, 65 insertions(+), 57 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java index 88f4e838..66f5ade5 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -41,7 +41,6 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; -import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.snackbar.BaseTransientBottomBar; import com.google.android.material.snackbar.Snackbar; import com.google.common.collect.ImmutableList; @@ -141,7 +140,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe final ActionBar actionBar = fragmentActivity.getSupportActionBar(); if (actionBar != null && !TextUtils.isEmpty(username)) { final String finalUsername = username.startsWith("@") ? username.substring(1) - : username; + : username; actionBar.setTitle(finalUsername); actionBar.setSubtitle(null); } @@ -617,9 +616,12 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe Log.e(TAG, "Error fetching profile relationship", t); final Context context = getContext(); try { - if (t == null) Toast.makeText(context, R.string.error_loading_profile_loggedin, Toast.LENGTH_LONG).show(); - else Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show(); - } catch (final Throwable ignored) {} + if (t == null) + Toast.makeText(context, R.string.error_loading_profile_loggedin, Toast.LENGTH_LONG).show(); + else + Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show(); + } catch (final Throwable ignored) { + } } }); } @@ -629,9 +631,11 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe Log.e(TAG, "Error fetching profile", t); final Context context = getContext(); try { - if (t == null) Toast.makeText(context, R.string.error_loading_profile_loggedin, Toast.LENGTH_LONG).show(); + if (t == null) + Toast.makeText(context, R.string.error_loading_profile_loggedin, Toast.LENGTH_LONG).show(); else Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show(); - } catch (final Throwable ignored) {} + } catch (final Throwable ignored) { + } } }); return; @@ -648,9 +652,11 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe Log.e(TAG, "Error fetching profile", t); final Context context = getContext(); try { - if (t == null) Toast.makeText(context, R.string.error_loading_profile, Toast.LENGTH_LONG).show(); + if (t == null) + Toast.makeText(context, R.string.error_loading_profile, Toast.LENGTH_LONG).show(); else Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show(); - } catch (final Throwable ignored) {} + } catch (final Throwable ignored) { + } } }); } @@ -667,8 +673,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe if (!isReallyPrivate()) { if (!postsSetupDone) { setupPosts(); - } - else { + } else { binding.postsRecyclerView.refresh(); } if (isLoggedIn) { @@ -695,10 +700,12 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe result.getDateAdded() ), new RepositoryCallback() { @Override - public void onSuccess(final Void result) {} + public void onSuccess(final Void result) { + } @Override - public void onDataNotAvailable() {} + public void onDataNotAvailable() { + } }); } @@ -721,7 +728,8 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe } @Override - public void onDataNotAvailable() {} + public void onDataNotAvailable() { + } }); } @@ -743,7 +751,8 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe } @Override - public void onDataNotAvailable() {} + public void onDataNotAvailable() { + } }); } })); @@ -756,13 +765,12 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe final long followingCount = profileModel.getFollowingCount(); final String postCount = String.valueOf(profileModel.getMediaCount()); - - + SpannableStringBuilder span = new SpannableStringBuilder(getResources().getQuantityString(R.plurals.main_posts_count, - profileModel.getMediaCount() > 2000000000L - ? 2000000000 - : (int) profileModel.getMediaCount(), - postCount)); + profileModel.getMediaCount() > 2000000000L + ? 2000000000 + : (int) profileModel.getMediaCount(), + postCount)); span.setSpan(new RelativeSizeSpan(1.2f), 0, postCount.length(), 0); span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0); profileDetailsBinding.mainPostCount.setText(span); @@ -771,8 +779,8 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe final String followersCountStr = String.valueOf(followersCount); final int followersCountStrLen = followersCountStr.length(); span = new SpannableStringBuilder(getResources().getQuantityString(R.plurals.main_posts_followers, - followersCount > 2000000000L ? 2000000000 : (int) followersCount, - followersCountStr)); + followersCount > 2000000000L ? 2000000000 : (int) followersCount, + followersCountStr)); span.setSpan(new RelativeSizeSpan(1.2f), 0, followersCountStrLen, 0); span.setSpan(new StyleSpan(Typeface.BOLD), 0, followersCountStrLen, 0); profileDetailsBinding.mainFollowers.setText(span); @@ -781,14 +789,14 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe final String followingCountStr = String.valueOf(followingCount); final int followingCountStrLen = followingCountStr.length(); span = new SpannableStringBuilder(getString(R.string.main_posts_following, - followingCountStr)); + followingCountStr)); span.setSpan(new RelativeSizeSpan(1.2f), 0, followingCountStrLen, 0); span.setSpan(new StyleSpan(Typeface.BOLD), 0, followingCountStrLen, 0); profileDetailsBinding.mainFollowing.setText(span); profileDetailsBinding.mainFollowing.setVisibility(View.VISIBLE); profileDetailsBinding.mainFullName.setText(TextUtils.isEmpty(profileModel.getFullName()) ? profileModel.getUsername() - : profileModel.getFullName()); + : profileModel.getFullName()); final String biography = profileModel.getBiography(); if (TextUtils.isEmpty(biography)) { @@ -808,8 +816,8 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe navigateToProfile(originalText); }); profileDetailsBinding.mainBiography.addOnEmailClickListener(autoLinkItem -> Utils.openEmailAddress(getContext(), - autoLinkItem.getOriginalText() - .trim())); + autoLinkItem.getOriginalText() + .trim())); profileDetailsBinding.mainBiography .addOnURLClickListener(autoLinkItem -> Utils.openURL(getContext(), autoLinkItem.getOriginalText().trim())); profileDetailsBinding.mainBiography.setOnLongClickListener(v -> { @@ -1029,21 +1037,21 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe } }); storiesService.fetchHighlights(profileId, - new ServiceCallback>() { - @Override - public void onSuccess(final List result) { - if (result != null) { - profileDetailsBinding.highlightsList.setVisibility(View.VISIBLE); - highlightsViewModel.getList().postValue(result); - } else profileDetailsBinding.highlightsList.setVisibility(View.GONE); - } + new ServiceCallback>() { + @Override + public void onSuccess(final List result) { + if (result != null) { + profileDetailsBinding.highlightsList.setVisibility(View.VISIBLE); + highlightsViewModel.getList().postValue(result); + } else profileDetailsBinding.highlightsList.setVisibility(View.GONE); + } - @Override - public void onFailure(final Throwable t) { - profileDetailsBinding.highlightsList.setVisibility(View.GONE); - Log.e(TAG, "Error", t); - } - }); + @Override + public void onFailure(final Throwable t) { + profileDetailsBinding.highlightsList.setVisibility(View.GONE); + Log.e(TAG, "Error", t); + } + }); } private void setupCommonListeners() { @@ -1108,14 +1116,14 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe }); profileDetailsBinding.btnLiked.setOnClickListener(v -> { final NavDirections action = ProfileFragmentDirections.actionProfileFragmentToSavedViewerFragment(profileModel.getUsername(), - profileModel.getPk(), - PostItemType.LIKED); + profileModel.getPk(), + PostItemType.LIKED); NavHostFragment.findNavController(this).navigate(action); }); profileDetailsBinding.btnTagged.setOnClickListener(v -> { final NavDirections action = ProfileFragmentDirections.actionProfileFragmentToSavedViewerFragment(profileModel.getUsername(), - profileModel.getPk(), - PostItemType.TAGGED); + profileModel.getPk(), + PostItemType.TAGGED); NavHostFragment.findNavController(this).navigate(action); }); if (!disableDm) { @@ -1154,7 +1162,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe // show stories final NavDirections action = ProfileFragmentDirections .actionProfileFragmentToStoryViewerFragment(StoryViewerOptions.forUser(profileModel.getPk(), - profileModel.getFullName())); + profileModel.getFullName())); NavHostFragment.findNavController(this).navigate(action); return; } @@ -1180,12 +1188,12 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe if (profileModel != null) { final FragmentManager fragmentManager = getParentFragmentManager(); final ProfilePicDialogFragment fragment = ProfilePicDialogFragment.getInstance(profileModel.getPk(), - username, - profileModel.getProfilePicUrl()); + username, + profileModel.getProfilePicUrl()); final FragmentTransaction ft = fragmentManager.beginTransaction(); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) - .add(fragment, "profilePicDialog") - .commit(); + .add(fragment, "profilePicDialog") + .commit(); } } @@ -1198,13 +1206,13 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe private void setupPosts() { binding.postsRecyclerView.setViewModelStoreOwner(this) - .setLifeCycleOwner(this) - .setPostFetchService(new ProfilePostFetchService(profileModel, isLoggedIn)) - .setLayoutPreferences(layoutPreferences) - .addFetchStatusChangeListener(fetching -> updateSwipeRefreshState()) - .setFeedItemCallback(feedItemCallback) - .setSelectionModeCallback(selectionModeCallback) - .init(); + .setLifeCycleOwner(this) + .setPostFetchService(new ProfilePostFetchService(profileModel, isLoggedIn)) + .setLayoutPreferences(layoutPreferences) + .addFetchStatusChangeListener(fetching -> updateSwipeRefreshState()) + .setFeedItemCallback(feedItemCallback) + .setSelectionModeCallback(selectionModeCallback) + .init(); binding.postsRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(@NonNull final RecyclerView recyclerView, final int dx, final int dy) { From 644f2ddff8bbf75f33807a3b6531b2a5251743c4 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Wed, 19 May 2021 20:09:49 +0900 Subject: [PATCH 9/9] Add some null checks and formatting. --- .../fragments/main/ProfileFragment.java | 101 +++++++++--------- 1 file changed, 51 insertions(+), 50 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java index 66f5ade5..8fc98002 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -140,7 +140,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe final ActionBar actionBar = fragmentActivity.getSupportActionBar(); if (actionBar != null && !TextUtils.isEmpty(username)) { final String finalUsername = username.startsWith("@") ? username.substring(1) - : username; + : username; actionBar.setTitle(finalUsername); actionBar.setSubtitle(null); } @@ -765,12 +765,12 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe final long followingCount = profileModel.getFollowingCount(); final String postCount = String.valueOf(profileModel.getMediaCount()); - - SpannableStringBuilder span = new SpannableStringBuilder(getResources().getQuantityString(R.plurals.main_posts_count, - profileModel.getMediaCount() > 2000000000L - ? 2000000000 - : (int) profileModel.getMediaCount(), - postCount)); + + SpannableStringBuilder span = new SpannableStringBuilder(getResources().getQuantityString( + R.plurals.main_posts_count, + profileModel.getMediaCount() > 2000000000L ? 2000000000 : (int) profileModel.getMediaCount(), + postCount) + ); span.setSpan(new RelativeSizeSpan(1.2f), 0, postCount.length(), 0); span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0); profileDetailsBinding.mainPostCount.setText(span); @@ -778,9 +778,11 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe final String followersCountStr = String.valueOf(followersCount); final int followersCountStrLen = followersCountStr.length(); - span = new SpannableStringBuilder(getResources().getQuantityString(R.plurals.main_posts_followers, + span = new SpannableStringBuilder(getResources().getQuantityString( + R.plurals.main_posts_followers, followersCount > 2000000000L ? 2000000000 : (int) followersCount, - followersCountStr)); + followersCountStr) + ); span.setSpan(new RelativeSizeSpan(1.2f), 0, followersCountStrLen, 0); span.setSpan(new StyleSpan(Typeface.BOLD), 0, followersCountStrLen, 0); profileDetailsBinding.mainFollowers.setText(span); @@ -788,15 +790,14 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe final String followingCountStr = String.valueOf(followingCount); final int followingCountStrLen = followingCountStr.length(); - span = new SpannableStringBuilder(getString(R.string.main_posts_following, - followingCountStr)); + span = new SpannableStringBuilder(getString(R.string.main_posts_following, followingCountStr)); span.setSpan(new RelativeSizeSpan(1.2f), 0, followingCountStrLen, 0); span.setSpan(new StyleSpan(Typeface.BOLD), 0, followingCountStrLen, 0); profileDetailsBinding.mainFollowing.setText(span); profileDetailsBinding.mainFollowing.setVisibility(View.VISIBLE); profileDetailsBinding.mainFullName.setText(TextUtils.isEmpty(profileModel.getFullName()) ? profileModel.getUsername() - : profileModel.getFullName()); + : profileModel.getFullName()); final String biography = profileModel.getBiography(); if (TextUtils.isEmpty(biography)) { @@ -815,9 +816,8 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe final String originalText = autoLinkItem.getOriginalText().trim(); navigateToProfile(originalText); }); - profileDetailsBinding.mainBiography.addOnEmailClickListener(autoLinkItem -> Utils.openEmailAddress(getContext(), - autoLinkItem.getOriginalText() - .trim())); + profileDetailsBinding.mainBiography.addOnEmailClickListener(autoLinkItem -> Utils.openEmailAddress( + getContext(), autoLinkItem.getOriginalText().trim())); profileDetailsBinding.mainBiography .addOnURLClickListener(autoLinkItem -> Utils.openURL(getContext(), autoLinkItem.getOriginalText().trim())); profileDetailsBinding.mainBiography.setOnLongClickListener(v -> { @@ -899,6 +899,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe return true; }); } + final MotionScene.Transition transition = root.getTransition(R.id.transition); if (!isReallyPrivate()) { if (isLoggedIn) { profileDetailsBinding.mainFollowing.setClickable(true); @@ -924,13 +925,13 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe binding.privatePage2.setVisibility(View.VISIBLE); binding.postsRecyclerView.setVisibility(View.GONE); binding.swipeRefreshLayout.setRefreshing(false); - root.getTransition(R.id.transition).setEnable(false); + if (transition != null) { + transition.setEnable(false); + } } - - if (profileModel.getMediaCount() == 0) { - root.getTransition(R.id.transition).setEnable(false); + if (profileModel.getMediaCount() == 0 && transition != null) { + transition.setEnable(false); } - } private void setupButtons(final long profileId) { @@ -1037,21 +1038,21 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe } }); storiesService.fetchHighlights(profileId, - new ServiceCallback>() { - @Override - public void onSuccess(final List result) { - if (result != null) { - profileDetailsBinding.highlightsList.setVisibility(View.VISIBLE); - highlightsViewModel.getList().postValue(result); - } else profileDetailsBinding.highlightsList.setVisibility(View.GONE); - } + new ServiceCallback>() { + @Override + public void onSuccess(final List result) { + if (result != null) { + profileDetailsBinding.highlightsList.setVisibility(View.VISIBLE); + highlightsViewModel.getList().postValue(result); + } else profileDetailsBinding.highlightsList.setVisibility(View.GONE); + } - @Override - public void onFailure(final Throwable t) { - profileDetailsBinding.highlightsList.setVisibility(View.GONE); - Log.e(TAG, "Error", t); - } - }); + @Override + public void onFailure(final Throwable t) { + profileDetailsBinding.highlightsList.setVisibility(View.GONE); + Log.e(TAG, "Error", t); + } + }); } private void setupCommonListeners() { @@ -1116,14 +1117,14 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe }); profileDetailsBinding.btnLiked.setOnClickListener(v -> { final NavDirections action = ProfileFragmentDirections.actionProfileFragmentToSavedViewerFragment(profileModel.getUsername(), - profileModel.getPk(), - PostItemType.LIKED); + profileModel.getPk(), + PostItemType.LIKED); NavHostFragment.findNavController(this).navigate(action); }); profileDetailsBinding.btnTagged.setOnClickListener(v -> { final NavDirections action = ProfileFragmentDirections.actionProfileFragmentToSavedViewerFragment(profileModel.getUsername(), - profileModel.getPk(), - PostItemType.TAGGED); + profileModel.getPk(), + PostItemType.TAGGED); NavHostFragment.findNavController(this).navigate(action); }); if (!disableDm) { @@ -1162,7 +1163,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe // show stories final NavDirections action = ProfileFragmentDirections .actionProfileFragmentToStoryViewerFragment(StoryViewerOptions.forUser(profileModel.getPk(), - profileModel.getFullName())); + profileModel.getFullName())); NavHostFragment.findNavController(this).navigate(action); return; } @@ -1188,12 +1189,12 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe if (profileModel != null) { final FragmentManager fragmentManager = getParentFragmentManager(); final ProfilePicDialogFragment fragment = ProfilePicDialogFragment.getInstance(profileModel.getPk(), - username, - profileModel.getProfilePicUrl()); + username, + profileModel.getProfilePicUrl()); final FragmentTransaction ft = fragmentManager.beginTransaction(); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) - .add(fragment, "profilePicDialog") - .commit(); + .add(fragment, "profilePicDialog") + .commit(); } } @@ -1206,13 +1207,13 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe private void setupPosts() { binding.postsRecyclerView.setViewModelStoreOwner(this) - .setLifeCycleOwner(this) - .setPostFetchService(new ProfilePostFetchService(profileModel, isLoggedIn)) - .setLayoutPreferences(layoutPreferences) - .addFetchStatusChangeListener(fetching -> updateSwipeRefreshState()) - .setFeedItemCallback(feedItemCallback) - .setSelectionModeCallback(selectionModeCallback) - .init(); + .setLifeCycleOwner(this) + .setPostFetchService(new ProfilePostFetchService(profileModel, isLoggedIn)) + .setLayoutPreferences(layoutPreferences) + .addFetchStatusChangeListener(fetching -> updateSwipeRefreshState()) + .setFeedItemCallback(feedItemCallback) + .setSelectionModeCallback(selectionModeCallback) + .init(); binding.postsRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(@NonNull final RecyclerView recyclerView, final int dx, final int dy) {