1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-26 08:37:29 +00:00

Allow opening PostViewV2Fragment from NotificationsViewerFragment, StoryViewerFragment and when opening from a Share dialog

This commit is contained in:
Ammar Githam 2020-11-04 20:24:53 +09:00
parent a08167381f
commit 850e119236
14 changed files with 95 additions and 371 deletions

View File

@ -9,7 +9,6 @@ import android.content.Intent;
import android.content.ServiceConnection;
import android.content.res.TypedArray;
import android.database.MatrixCursor;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
@ -25,6 +24,7 @@ import android.widget.AutoCompleteTextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
@ -51,9 +51,11 @@ import java.util.Map;
import awais.instagrabber.R;
import awais.instagrabber.adapters.SuggestionsAdapter;
import awais.instagrabber.asyncs.PostFetcher;
import awais.instagrabber.asyncs.SuggestionsFetcher;
import awais.instagrabber.customviews.helpers.CustomHideBottomViewOnScrollBehavior;
import awais.instagrabber.databinding.ActivityMainBinding;
import awais.instagrabber.fragments.PostViewV2Fragment;
import awais.instagrabber.fragments.settings.MorePreferencesFragmentDirections;
import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.IntentModel;
@ -574,13 +576,18 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
private void showPostView(@NonNull final IntentModel intentModel) {
final String shortCode = intentModel.getText();
// Log.d(TAG, "shortCode: " + shortCode);
final NavController navController = currentNavControllerLiveData.getValue();
if (currentNavControllerLiveData == null || navController == null) return;
final Bundle bundle = new Bundle();
bundle.putStringArray("idOrCodeArray", new String[]{shortCode});
bundle.putInt("index", 0);
bundle.putBoolean("isId", false);
navController.navigate(R.id.action_global_postViewFragment, bundle);
final AlertDialog alertDialog = new AlertDialog.Builder(this)
.setCancelable(false)
.setView(R.layout.dialog_opening_post)
.create();
alertDialog.show();
new PostFetcher(shortCode, feedModel -> {
final PostViewV2Fragment fragment = PostViewV2Fragment
.builder(feedModel)
.build();
fragment.setOnShowListener(dialog -> alertDialog.dismiss());
fragment.show(getSupportFragmentManager(), "post_view");
}).execute();
}
private void showLocationView(@NonNull final IntentModel intentModel) {
@ -629,20 +636,20 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
return binding.bottomNavView;
}
public void fitSystemWindows(final boolean fit) {
binding.appBarLayout.setBackground(null);
binding.appBarLayout.setFitsSystemWindows(fit);
binding.collapsingToolbarLayout.setBackground(null);
binding.collapsingToolbarLayout.setFitsSystemWindows(fit);
final Drawable toolbarBackground = binding.toolbar.getBackground();
binding.toolbar.setFitsSystemWindows(fit);
binding.toolbar.setBackground(null);
binding.toolbar.setClickable(false);
}
public int getNavHostContainerId() {
return binding.mainNavHost.getId();
}
// public void fitSystemWindows(final boolean fit) {
// binding.appBarLayout.setBackground(null);
// binding.appBarLayout.setFitsSystemWindows(fit);
// binding.collapsingToolbarLayout.setBackground(null);
// binding.collapsingToolbarLayout.setFitsSystemWindows(fit);
// final Drawable toolbarBackground = binding.toolbar.getBackground();
// binding.toolbar.setFitsSystemWindows(fit);
// binding.toolbar.setBackground(null);
// binding.toolbar.setClickable(false);
// }
//
// public int getNavHostContainerId() {
// return binding.mainNavHost.getId();
// }
public void setToolbar(final Toolbar toolbar) {
binding.appBarLayout.setVisibility(View.GONE);

View File

@ -28,6 +28,7 @@ import awais.instagrabber.R;
import awais.instagrabber.adapters.NotificationsAdapter;
import awais.instagrabber.adapters.NotificationsAdapter.OnNotificationClickListener;
import awais.instagrabber.asyncs.NotificationsFetcher;
import awais.instagrabber.asyncs.PostFetcher;
import awais.instagrabber.databinding.FragmentNotificationsViewerBinding;
import awais.instagrabber.fragments.settings.MorePreferencesFragmentDirections;
import awais.instagrabber.interfaces.MentionClickListener;
@ -75,7 +76,8 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
} else {
commentDialogList = new String[]{getString(R.string.open_profile)};
}
if (getContext() == null) return;
final Context context = getContext();
if (context == null) return;
final DialogInterface.OnClickListener profileDialogListener = (dialog, which) -> {
switch (which) {
case 0:
@ -101,9 +103,18 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
});
return;
}
final NavDirections action = MorePreferencesFragmentDirections
.actionGlobalPostViewFragment(0, new String[]{model.getShortCode()}, false);
NavHostFragment.findNavController(this).navigate(action);
final AlertDialog alertDialog = new AlertDialog.Builder(context)
.setCancelable(false)
.setView(R.layout.dialog_opening_post)
.create();
alertDialog.show();
new PostFetcher(model.getShortCode(), feedModel -> {
final PostViewV2Fragment fragment = PostViewV2Fragment
.builder(feedModel)
.build();
fragment.setOnShowListener(dialog1 -> alertDialog.dismiss());
fragment.show(getChildFragmentManager(), "post_view");
}).execute();
break;
case 2:
friendshipService.ignore(userId, model.getUserId(), csrfToken, new ServiceCallback<FriendshipRepoChangeRootResponse>() {
@ -125,7 +136,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
break;
}
};
new AlertDialog.Builder(getContext())
new AlertDialog.Builder(context)
.setTitle(title)
.setItems(commentDialogList, profileDialogListener)
.setNegativeButton(R.string.cancel, null)

View File

@ -8,6 +8,7 @@ import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.drawable.Animatable;
@ -105,6 +106,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
private boolean wasPaused;
private int captionState = BottomSheetBehavior.STATE_HIDDEN;
private int sliderPosition = -1;
private DialogInterface.OnShowListener onShowListener;
private final VerticalDragHelper.OnVerticalDragListener onVerticalDragListener = new VerticalDragHelper.OnVerticalDragListener() {
@ -147,6 +149,10 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
}
};
public void setOnShowListener(final DialogInterface.OnShowListener onShowListener) {
this.onShowListener = onShowListener;
}
public static class Builder {
private final FeedModel feedModel;
private View profilePicElement;
@ -204,150 +210,6 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
this.sharedMainPostElement = sharedMainPostElement;
}
// private FetchListener<FeedModel> pfl = result -> {
// if (result == null) return;
// final List<ViewerPostModelWrapper> viewerPostModels = viewerPostViewModel.getList().getValue();
// final List<ViewerPostModelWrapper> temp = viewerPostModels == null ? new ArrayList<>(idOrCodeList.size())
// : new ArrayList<>(viewerPostModels);
// String idOrCode = isId ? result.getPostId() : result.getShortCode();
// if (idOrCode == null) return;
// if (isId) {
// // the post id is appended with `_` in the result
// idOrCode = idOrCode.substring(0, idOrCode.indexOf('_'));
// }
// final int index = idOrCodeList.indexOf(idOrCode);
// if (index < 0) return;
// final ViewerPostModelWrapper viewerPostModelWrapper = temp.get(index);
// viewerPostModelWrapper.setViewerPostModels(result.getSliderItems() == null ? Collections.emptyList() : result.getSliderItems());
// temp.set(index, viewerPostModelWrapper);
// viewerPostViewModel.getList().setValue(temp);
// adapter.notifyItemChanged(index);
// if (!hasInitialResult) {
// Log.d(TAG, "setting delayed position to: " + currentPostIndex);
// binding.getRoot()
// .postDelayed(() -> binding.getRoot().setCurrentItem(currentPostIndex), 200);
// }
// hasInitialResult = true;
// };
// private MentionClickListener mentionListener = (view, text, isHashtag, isLocation) -> {
// if (isHashtag) {
// final NavDirections action = PostViewFragmentDirections
// .actionGlobalHashTagFragment(text);
// NavHostFragment.findNavController(this).navigate(action);
// return;
// }
// if (isLocation) {
// final NavDirections action = PostViewFragmentDirections
// .actionGlobalLocationFragment(text);
// NavHostFragment.findNavController(this).navigate(action);
// return;
// }
// final NavDirections action = PostViewFragmentDirections
// .actionGlobalProfileFragment("@" + text);
// NavHostFragment.findNavController(this).navigate(action);
// };
// private OnPostViewChildViewClickListener clickListener = (v, wrapper, postPosition, childPosition) -> {
// final ViewerPostModel postModel = wrapper.getViewerPostModels().get(0);
// final String username = postModel.getProfileModel().getUsername();
// final int id = v.getId();
// switch (id) {
// case R.id.viewerCaption:
// break;
// case R.id.btnComments:
// String postId = postModel.getPostId();
// if (postId.contains("_")) postId = postId.substring(0, postId.indexOf("_"));
// final NavDirections commentsAction = PostViewFragmentDirections.actionGlobalCommentsViewerFragment(
// postModel.getShortCode(),
// postId,
// postModel.getProfileModel().getId()
// );
// NavHostFragment.findNavController(this).navigate(commentsAction);
// break;
// case R.id.btnDownload:
// final Context context = getContext();
// if (context == null) return;
// if (checkSelfPermission(context,
// DownloadUtils.PERMS[0]) == PackageManager.PERMISSION_GRANTED) {
// showDownloadDialog(wrapper.getViewerPostModels(),
// childPosition,
// username);
// return;
// }
// requestPermissions(DownloadUtils.PERMS, 8020);
// break;
// case R.id.ivProfilePic:
// case R.id.title:
// mentionListener.onClick(null, username, false, false);
// break;
// case R.id.btnLike:
// if (mediaService != null) {
// final String userId = CookieUtils.getUserIdFromCookie(COOKIE);
// final String csrfToken = CookieUtils.getCsrfTokenFromCookie(COOKIE);
// v.setEnabled(false);
// final ServiceCallback<Boolean> likeCallback = new ServiceCallback<Boolean>() {
// @Override
// public void onSuccess(final Boolean result) {
// v.setEnabled(true);
// if (result) {
// postModel.setManualLike(!postModel.getLike());
// adapter.notifyItemChanged(postPosition);
// return;
// }
// Log.e(TAG, "like/unlike unsuccessful!");
// }
//
// @Override
// public void onFailure(final Throwable t) {
// v.setEnabled(true);
// Log.e(TAG, "Error during like/unlike", t);
// }
// };
// if (!postModel.getLike()) {
// mediaService.like(postModel.getPostId(), userId, csrfToken, likeCallback);
// } else {
// mediaService.unlike(postModel.getPostId(), userId, csrfToken, likeCallback);
// }
// }
// break;
// case R.id.btnBookmark:
// if (mediaService != null) {
// final String userId = CookieUtils.getUserIdFromCookie(COOKIE);
// final String csrfToken = CookieUtils.getCsrfTokenFromCookie(COOKIE);
// v.setEnabled(false);
// final ServiceCallback<Boolean> saveCallback = new ServiceCallback<Boolean>() {
// @Override
// public void onSuccess(final Boolean result) {
// v.setEnabled(true);
// if (result) {
// // postModel.setBookmarked(!postModel.isSaved());
// adapter.notifyItemChanged(postPosition);
// return;
// }
// Log.e(TAG, "save/unsave unsuccessful!");
// }
//
// @Override
// public void onFailure(final Throwable t) {
// v.setEnabled(true);
// Log.e(TAG, "Error during save/unsave", t);
// }
// };
// if (!postModel.isSaved()) {
// mediaService.save(postModel.getPostId(), userId, csrfToken, saveCallback);
// } else {
// mediaService.unsave(postModel.getPostId(), userId, csrfToken, saveCallback);
// }
// }
// break;
// }
// };
// private PostViewAdapter.OnPostCaptionLongClickListener captionLongClickListener = text -> {
// final Context context = getContext();
// if (context == null) return;
// Utils.copyText(context, text);
// };
@Override
public void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -411,6 +273,9 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
);
addAnimator(animator);
}
if (onShowListener != null) {
onShowListener.onShow(dialog);
}
}
@Override

View File

@ -66,6 +66,7 @@ import awais.instagrabber.BuildConfig;
import awais.instagrabber.R;
import awais.instagrabber.adapters.StoriesAdapter;
import awais.instagrabber.asyncs.DownloadAsync;
import awais.instagrabber.asyncs.PostFetcher;
import awais.instagrabber.asyncs.QuizAction;
import awais.instagrabber.asyncs.RespondAction;
import awais.instagrabber.asyncs.SeenAction;
@ -373,14 +374,19 @@ public class StoryViewerFragment extends Fragment {
binding.viewStoryPost.setOnClickListener(v -> {
final Object tag = v.getTag();
if (!(tag instanceof CharSequence)) return;
final String postId = tag.toString();
final boolean isId = tag.toString().matches("^[\\d]+$");
final String[] idsOrShortCodes = new String[]{postId};
final NavDirections action = HashTagFragmentDirections.actionGlobalPostViewFragment(
0,
idsOrShortCodes,
isId);
NavHostFragment.findNavController(this).navigate(action);
final String shortCode = tag.toString();
final AlertDialog alertDialog = new AlertDialog.Builder(context)
.setCancelable(false)
.setView(R.layout.dialog_opening_post)
.create();
alertDialog.show();
new PostFetcher(shortCode, feedModel -> {
final PostViewV2Fragment fragment = PostViewV2Fragment
.builder(feedModel)
.build();
fragment.setOnShowListener(dialog -> alertDialog.dismiss());
fragment.show(getChildFragmentManager(), "post_view");
}).execute();
});
final View.OnClickListener storyActionListener = v -> {
final Object tag = v.getTag();

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="@string/opening_post"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/progress_bar"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -38,22 +38,6 @@
app:nullable="false" />
</action>
<include app:graph="@navigation/post_view_nav_graph" />
<action
android:id="@+id/action_global_postViewFragment"
app:destination="@id/post_view_nav_graph">
<argument
android:name="index"
app:argType="integer" />
<argument
android:name="idOrCodeArray"
app:argType="string[]" />
<argument
android:name="isId"
app:argType="boolean" />
</action>
<fragment
android:id="@+id/directMessagesInboxFragment"
android:name="awais.instagrabber.fragments.directmessages.DirectMessageInboxFragment"

View File

@ -38,22 +38,6 @@
app:nullable="false" />
</action>
<include app:graph="@navigation/post_view_nav_graph" />
<action
android:id="@+id/action_global_postViewFragment"
app:destination="@id/post_view_nav_graph">
<argument
android:name="index"
app:argType="integer" />
<argument
android:name="idOrCodeArray"
app:argType="string[]" />
<argument
android:name="isId"
app:argType="boolean" />
</action>
<include app:graph="@navigation/comments_nav_graph" />
<action

View File

@ -38,22 +38,6 @@
app:nullable="false" />
</action>
<include app:graph="@navigation/post_view_nav_graph" />
<action
android:id="@+id/action_global_postViewFragment"
app:destination="@id/post_view_nav_graph">
<argument
android:name="index"
app:argType="integer" />
<argument
android:name="idOrCodeArray"
app:argType="string[]" />
<argument
android:name="isId"
app:argType="boolean" />
</action>
<include app:graph="@navigation/comments_nav_graph" />
<action

View File

@ -5,20 +5,6 @@
android:id="@+id/hashtag_nav_graph"
app:startDestination="@id/hashTagFragment">
<action
android:id="@+id/action_global_postViewFragment"
app:destination="@id/post_view_nav_graph">
<argument
android:name="index"
app:argType="integer" />
<argument
android:name="idOrCodeArray"
app:argType="string[]" />
<argument
android:name="isId"
app:argType="boolean" />
</action>
<include app:graph="@navigation/comments_nav_graph" />
<action

View File

@ -5,20 +5,6 @@
android:id="@+id/location_nav_graph"
app:startDestination="@id/locationFragment">
<action
android:id="@+id/action_global_postViewFragment"
app:destination="@id/post_view_nav_graph">
<argument
android:name="index"
app:argType="integer" />
<argument
android:name="idOrCodeArray"
app:argType="string[]" />
<argument
android:name="isId"
app:argType="boolean" />
</action>
<include app:graph="@navigation/comments_nav_graph" />
<action

View File

@ -5,26 +5,11 @@
android:id="@+id/more_nav_graph"
app:startDestination="@id/morePreferencesFragment">
<include app:graph="@navigation/post_view_nav_graph" />
<include app:graph="@navigation/profile_nav_graph" />
<include app:graph="@navigation/hashtag_nav_graph" />
<include app:graph="@navigation/location_nav_graph" />
<include app:graph="@navigation/comments_nav_graph" />
<action
android:id="@+id/action_global_postViewFragment"
app:destination="@id/post_view_nav_graph">
<argument
android:name="index"
app:argType="integer" />
<argument
android:name="idOrCodeArray"
app:argType="string[]" />
<argument
android:name="isId"
app:argType="boolean" />
</action>
<action
android:id="@+id/action_global_profileFragment"
app:destination="@id/profile_nav_graph">

View File

@ -1,85 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/post_view_nav_graph"
app:startDestination="@id/postViewFragment">
<include app:graph="@navigation/hashtag_nav_graph" />
<action
android:id="@+id/action_global_hashTagFragment"
app:destination="@id/hashtag_nav_graph">
<argument
android:name="hashtag"
app:argType="string"
app:nullable="false" />
</action>
<!--<include app:graph="@navigation/profile_nav_graph" />-->
<action
android:id="@+id/action_global_profileFragment"
app:destination="@id/profile_nav_graph">
<argument
android:name="username"
app:argType="string"
app:nullable="true" />
</action>
<include app:graph="@navigation/location_nav_graph" />
<action
android:id="@+id/action_global_locationFragment"
app:destination="@id/location_nav_graph">
<argument
android:name="locationId"
app:argType="string"
app:nullable="false" />
</action>
<action
android:id="@+id/action_global_commentsViewerFragment"
app:destination="@id/comments_nav_graph">
<argument
android:name="shortCode"
app:argType="string"
app:nullable="false" />
<argument
android:name="postId"
app:argType="string"
app:nullable="false" />
<argument
android:name="postUserId"
app:argType="string"
app:nullable="false" />
</action>
<fragment
android:id="@+id/postViewFragment"
android:name="awais.instagrabber.fragments.PostViewFragment"
tools:layout="@layout/item_full_post_view">
<argument
android:name="index"
app:argType="integer" />
<argument
android:name="idOrCodeArray"
app:argType="string[]" />
<argument
android:name="isId"
app:argType="boolean" />
</fragment>
<action
android:id="@+id/action_global_postViewFragment"
app:destination="@id/postViewFragment">
<argument
android:name="index"
app:argType="integer" />
<argument
android:name="idOrCodeArray"
app:argType="string[]" />
<argument
android:name="isId"
app:argType="boolean" />
</action>
</navigation>

View File

@ -35,22 +35,6 @@
app:nullable="false" />
</action>
<include app:graph="@navigation/post_view_nav_graph" />
<action
android:id="@+id/action_global_postViewFragment"
app:destination="@id/post_view_nav_graph">
<argument
android:name="index"
app:argType="integer" />
<argument
android:name="idOrCodeArray"
app:argType="string[]" />
<argument
android:name="isId"
app:argType="boolean" />
</action>
<include app:graph="@navigation/comments_nav_graph" />
<action

View File

@ -325,6 +325,7 @@
<string name="delete">Delete</string>
<string name="comment">Comment</string>
<string name="layout">Layout</string>
<string name="opening_post">Opening post...</string>
<plurals name="likes_count">
<item quantity="one">%d like</item>
<item quantity="other">%d likes</item>