From 2d44033d3c10b2956df1a184bb137f7587831f47 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Mon, 7 Sep 2020 16:01:44 -0400 Subject: [PATCH] small polishings (see description) * General (makeshift): Set default first-tab to be profile, adjust search button appearance logic, add fragment labels * DM inbox items: Adjust group chat avatar sizes, reinstate unread indicators * DM thread: Swap buttons per spirit of #122 * Profile: Fix story fetcher logic * Story: Fix bug where first story can't scroll to next user, unify subtitle to timestamp, swap buttons per #122 * Comment: Unfocus replying comment when X is pressed --- .../instagrabber/activities/MainActivity.java | 24 +++++----- .../DirectMessageInboxItemViewHolder.java | 2 +- .../viewholder/PostViewerViewHolder.java | 2 +- .../fragments/CommentsViewerFragment.java | 6 ++- .../fragments/StoryViewerFragment.java | 20 ++++----- .../DirectMessageSettingsFragment.java | 45 +++++++++---------- .../fragments/main/ProfileFragment.java | 2 +- .../instagrabber/utils/SettingsHelper.java | 3 +- .../main/res/layout/layout_dm_inbox_item.xml | 7 +++ app/src/main/res/menu/dm_thread_menu.xml | 10 ++--- app/src/main/res/menu/story_menu.xml | 12 ++--- .../res/navigation/discover_nav_graph.xml | 2 +- .../main/res/navigation/feed_nav_graph.xml | 2 +- .../main/res/navigation/more_nav_graph.xml | 2 +- app/src/main/res/values/dimens.xml | 2 +- 15 files changed, 74 insertions(+), 67 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/activities/MainActivity.java b/app/src/main/java/awais/instagrabber/activities/MainActivity.java index 1efb8e79..4e3a0aa9 100644 --- a/app/src/main/java/awais/instagrabber/activities/MainActivity.java +++ b/app/src/main/java/awais/instagrabber/activities/MainActivity.java @@ -323,20 +323,18 @@ public class MainActivity extends BaseLanguageActivity { navIds.recycle(); if (setDefaultFromSettings) { final String defaultTabIdString = settingsHelper.getString(Constants.DEFAULT_TAB); - if (!Utils.isEmpty(defaultTabIdString)) { - try { - final int defaultNavId = Integer.parseInt(defaultTabIdString); - final int index = mainNavList.indexOf(defaultNavId); - if (index >= 0) { - firstFragmentGraphIndex = index; - final Integer menuId = NAV_TO_MENU_ID_MAP.get(defaultNavId); - if (menuId != null) { - binding.bottomNavView.setSelectedItemId(menuId); - } + try { + final int defaultNavId = Utils.isEmpty(defaultTabIdString) ? mainNavList.get(2) : Integer.parseInt(defaultTabIdString); + final int index = mainNavList.indexOf(defaultNavId); + if (index >= 0) { + firstFragmentGraphIndex = index; + final Integer menuId = NAV_TO_MENU_ID_MAP.get(defaultNavId); + if (menuId != null) { + binding.bottomNavView.setSelectedItemId(menuId); } - } catch (NumberFormatException e) { - Log.e(TAG, "Error parsing id", e); } + } catch (NumberFormatException e) { + Log.e(TAG, "Error parsing id", e); } } final LiveData navControllerLiveData = setupWithNavController( @@ -374,7 +372,7 @@ public class MainActivity extends BaseLanguageActivity { private void setupMenu(final int backStackSize, final int destinationId) { if (searchMenuItem == null) return; - if (backStackSize == 2 && destinationId != R.id.morePreferencesFragment) { + if (backStackSize >= 2 && destinationId == R.id.profileFragment) { showSearch = true; searchMenuItem.setVisible(true); return; diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/DirectMessageInboxItemViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/DirectMessageInboxItemViewHolder.java index 2b214887..cd975fa7 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/DirectMessageInboxItemViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/DirectMessageInboxItemViewHolder.java @@ -119,6 +119,6 @@ public final class DirectMessageInboxItemViewHolder extends RecyclerView.ViewHol } binding.tvComment.setText(HtmlCompat.fromHtml(messageText.toString(), HtmlCompat.FROM_HTML_MODE_COMPACT)); binding.tvDate.setText(lastItemModel.getDateTime()); - // binding.unread.setVisibility(model.getUnreadCount() > 0L ? View.VISIBLE : View.GONE); + binding.unread.setVisibility(model.getUnreadCount() > 0L ? View.VISIBLE : View.INVISIBLE); } } \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/PostViewerViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/PostViewerViewHolder.java index 02fc3d96..b3eb2058 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/PostViewerViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/PostViewerViewHolder.java @@ -79,9 +79,9 @@ public class PostViewerViewHolder extends RecyclerView.ViewHolder { binding.bottomPanel.commentsCount.setText(String.valueOf(firstPost.getCommentsCount())); final CharSequence postCaption = firstPost.getPostCaption(); if (Utils.hasMentions(postCaption)) { + binding.bottomPanel.viewerCaption.setMentionClickListener(mentionClickListener); binding.bottomPanel.viewerCaption .setText(Utils.getMentionText(postCaption), TextView.BufferType.SPANNABLE); - binding.bottomPanel.viewerCaption.setMentionClickListener(mentionClickListener); } else { binding.bottomPanel.viewerCaption.setMentionClickListener(null); binding.bottomPanel.viewerCaption.setText(postCaption); diff --git a/app/src/main/java/awais/instagrabber/fragments/CommentsViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/CommentsViewerFragment.java index 37fb410a..cba8a89c 100644 --- a/app/src/main/java/awais/instagrabber/fragments/CommentsViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/CommentsViewerFragment.java @@ -152,7 +152,11 @@ public final class CommentsViewerFragment extends Fragment implements SwipeRefre public void afterTextChanged(final Editable s) {} }); binding.commentField.setStartIconOnClickListener(v -> { - commentModel = null; + if (commentModel != null) { + final View focus = binding.rvComments.findViewWithTag(commentModel); + focus.setBackgroundColor(0x00000000); + commentModel = null; + } binding.commentText.setText(""); }); binding.commentField.setEndIconOnClickListener(newCommentListener); diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java index fe2d177e..fa084e94 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -270,7 +270,7 @@ public class StoryViewerFragment extends Fragment { private void setupListeners() { final boolean hasFeedStories; List models = null; - if (currentFeedStoryIndex > 0) { + if (currentFeedStoryIndex >= 0) { if (isHighlight) { final HighlightsViewModel highlightsViewModel = (HighlightsViewModel) viewModel; models = highlightsViewModel.getList().getValue(); @@ -498,11 +498,11 @@ public class StoryViewerFragment extends Fragment { // actionBar.setOnClickListener(v -> { // searchUsername(username); // }); - if (isHighlight) { - actionBar.setSubtitle(getString(R.string.title_highlight, highlight)); - } else { - actionBar.setSubtitle(R.string.title_user_story); - } +// if (isHighlight) { +// actionBar.setSubtitle(getString(R.string.title_highlight, highlight)); +// } else { +// actionBar.setSubtitle(R.string.title_user_story); +// } } } storiesViewModel.getList().setValue(Collections.emptyList()); @@ -596,11 +596,9 @@ public class StoryViewerFragment extends Fragment { if (itemType == MediaItemType.MEDIA_TYPE_VIDEO) setupVideo(); else setupImage(); - if (Utils.isEmpty(highlight)) { - final ActionBar actionBar = fragmentActivity.getSupportActionBar(); - if (actionBar != null) { - actionBar.setSubtitle(Utils.datetimeParser.format(new Date(currentStory.getTimestamp() * 1000L))); - } + final ActionBar actionBar = fragmentActivity.getSupportActionBar(); + if (actionBar != null) { + actionBar.setSubtitle(Utils.datetimeParser.format(new Date(currentStory.getTimestamp() * 1000L))); } if (settingsHelper.getBoolean(MARK_AS_SEEN)) new SeenAction(cookie, currentStory).execute(); diff --git a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageSettingsFragment.java b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageSettingsFragment.java index 4bc8d93c..91e7f030 100644 --- a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageSettingsFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageSettingsFragment.java @@ -21,6 +21,7 @@ import androidx.appcompat.widget.AppCompatButton; import androidx.appcompat.widget.AppCompatImageView; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; +import androidx.navigation.NavDirections; import androidx.navigation.fragment.NavHostFragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -38,6 +39,7 @@ import awais.instagrabber.R; import awais.instagrabber.adapters.DirectMessageMembersAdapter; import awais.instagrabber.asyncs.direct_messages.DirectMessageInboxThreadFetcher; import awais.instagrabber.databinding.FragmentDirectMessagesSettingsBinding; +import awais.instagrabber.fragments.PostViewFragmentDirections; import awais.instagrabber.interfaces.FetchListener; import awais.instagrabber.models.ProfileModel; import awais.instagrabber.models.direct_messages.InboxThreadModel; @@ -95,8 +97,9 @@ public class DirectMessageSettingsFragment extends Fragment implements SwipeRefr final Object tag = v.getTag(); if (tag instanceof ProfileModel) { ProfileModel model = (ProfileModel) tag; - // startActivity(new Intent(requireContext(), ProfileViewer.class) - // .putExtra(Constants.EXTRAS_USERNAME, model.getUsername())); + /*final NavDirections action = PostViewFragmentDirections + .actionGlobalProfileFragment("@" + model.getUsername()); + NavHostFragment.findNavController(this).navigate(action);*/ } }; @@ -104,27 +107,23 @@ public class DirectMessageSettingsFragment extends Fragment implements SwipeRefr final Object tag = v.getTag(); if (tag instanceof ProfileModel) { ProfileModel model = (ProfileModel) tag; - if (!amAdmin || model.getId().equals(Utils.getUserIdFromCookie(cookie))) { - // startActivity(new Intent(requireContext(), ProfileViewer.class) - // .putExtra(Constants.EXTRAS_USERNAME, model.getUsername())); - } else { - final ArrayAdapter adapter = new ArrayAdapter<>(requireContext(), android.R.layout.simple_list_item_1, new String[]{ - getString(R.string.open_profile), - getString(R.string.dms_action_kick), - }); - final DialogInterface.OnClickListener clickListener = (d, w) -> { - if (w == 0) { - // startActivity(new Intent(requireContext(), ProfileViewer.class) - // .putExtra(Constants.EXTRAS_USERNAME, model.getUsername())); - } else if (w == 1) { - new ChangeSettings().execute("remove_users", model.getId()); - onRefresh(); - } - }; - new AlertDialog.Builder(requireContext()) - .setAdapter(adapter, clickListener) - .show(); - } + final ArrayAdapter adapter = new ArrayAdapter<>(requireContext(), android.R.layout.simple_list_item_1, new String[]{ + getString(R.string.open_profile), + getString(R.string.dms_action_kick), + }); + final DialogInterface.OnClickListener clickListener = (d, w) -> { + if (w == 0) { + /*final NavDirections action = PostViewFragmentDirections + .actionGlobalProfileFragment("@" + model.getUsername()); + NavHostFragment.findNavController(this).navigate(action);*/ + } else if (w == 1) { + new ChangeSettings().execute("remove_users", model.getId()); + onRefresh(); + } + }; + new AlertDialog.Builder(requireContext()) + .setAdapter(adapter, clickListener) + .show(); } }; } 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 be6152ae..329177ac 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -346,7 +346,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe } binding.isVerified.setVisibility(profileModel.isVerified() ? View.VISIBLE : View.GONE); final String profileId = profileModel.getId(); - if (settingsHelper.getBoolean(Constants.STORIESIG)) { + if (settingsHelper.getBoolean(Constants.STORIESIG) || isLoggedIn) { new iStoryStatusFetcher(profileId, profileModel.getUsername(), false, diff --git a/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java b/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java index b03e9a57..7c397358 100755 --- a/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java +++ b/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java @@ -121,7 +121,8 @@ public final class SettingsHelper { } @StringDef( - {APP_LANGUAGE, APP_THEME, COOKIE, FOLDER_PATH, DATE_TIME_FORMAT, DATE_TIME_SELECTION, CUSTOM_DATE_TIME_FORMAT, DEVICE_UUID, SKIPPED_VERSION, DEFAULT_TAB}) + {APP_LANGUAGE, APP_THEME, COOKIE, FOLDER_PATH, DATE_TIME_FORMAT, DATE_TIME_SELECTION, CUSTOM_DATE_TIME_FORMAT, + DEVICE_UUID, SKIPPED_VERSION, DEFAULT_TAB}) public @interface StringSettings {} @StringDef({DOWNLOAD_USER_FOLDER, BOTTOM_TOOLBAR, FOLDER_SAVE_TO, AUTOPLAY_VIDEOS, SHOW_QUICK_ACCESS_DIALOG, MUTED_VIDEOS, diff --git a/app/src/main/res/layout/layout_dm_inbox_item.xml b/app/src/main/res/layout/layout_dm_inbox_item.xml index 3adcec21..5bc7fb8d 100644 --- a/app/src/main/res/layout/layout_dm_inbox_item.xml +++ b/app/src/main/res/layout/layout_dm_inbox_item.xml @@ -52,6 +52,13 @@ app:roundAsCircle="true" /> + + + - \ No newline at end of file diff --git a/app/src/main/res/menu/story_menu.xml b/app/src/main/res/menu/story_menu.xml index c1178c99..5340b01c 100644 --- a/app/src/main/res/menu/story_menu.xml +++ b/app/src/main/res/menu/story_menu.xml @@ -2,16 +2,16 @@ + - \ No newline at end of file diff --git a/app/src/main/res/navigation/discover_nav_graph.xml b/app/src/main/res/navigation/discover_nav_graph.xml index a80ecb70..82e87b5e 100644 --- a/app/src/main/res/navigation/discover_nav_graph.xml +++ b/app/src/main/res/navigation/discover_nav_graph.xml @@ -26,6 +26,6 @@ \ No newline at end of file diff --git a/app/src/main/res/navigation/feed_nav_graph.xml b/app/src/main/res/navigation/feed_nav_graph.xml index 01d376a6..19f3ce50 100644 --- a/app/src/main/res/navigation/feed_nav_graph.xml +++ b/app/src/main/res/navigation/feed_nav_graph.xml @@ -76,7 +76,7 @@ + android:label="@string/more"> diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index d6eb3ac9..1f9d9ed4 100755 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -13,7 +13,7 @@ 45dp 80dp - 40dp + 35dp @dimen/simple_item_picture_size @dimen/feed_profile_size