1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-12-23 05:16:58 +00:00

comments and verified

* fix comments count on profile posts
* all comments should be visible now
* add verified badge to comments and post title
This commit is contained in:
Austin Huang 2020-11-02 21:12:18 -05:00
parent 92f7e04757
commit c19ff317fd
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
10 changed files with 58 additions and 352 deletions

View File

@ -142,10 +142,12 @@ public final class CommentsAdapter extends ListAdapter<CommentModel, RecyclerVie
flatList.add(parent);
positionTypeMap.put(lastCommentIndex, TYPE_PARENT);
final List<CommentModel> children = parent.getChildCommentModels();
for (final CommentModel child : children) {
lastCommentIndex++;
flatList.add(child);
positionTypeMap.put(lastCommentIndex, TYPE_CHILD);
if (children != null) {
for (final CommentModel child : children) {
lastCommentIndex++;
flatList.add(child);
positionTypeMap.put(lastCommentIndex, TYPE_CHILD);
}
}
}
return flatList;

View File

@ -1,5 +1,7 @@
package awais.instagrabber.adapters.viewholder.comments;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
@ -77,6 +79,7 @@ public final class ChildCommentViewHolder extends RecyclerView.ViewHolder {
if (profileModel == null) return;
binding.tvUsername.setText(profileModel.getUsername());
binding.ivProfilePic.setImageURI(profileModel.getSdProfilePic());
binding.isVerified.setVisibility(profileModel.isVerified() ? View.VISIBLE : View.GONE);
}
private void setLikes(final int likes) {

View File

@ -1,5 +1,7 @@
package awais.instagrabber.adapters.viewholder.comments;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
@ -77,6 +79,7 @@ public final class ParentCommentViewHolder extends RecyclerView.ViewHolder {
if (profileModel == null) return;
binding.tvUsername.setText(profileModel.getUsername());
binding.ivProfilePic.setImageURI(profileModel.getSdProfilePic());
binding.isVerified.setVisibility(profileModel.isVerified() ? View.VISIBLE : View.GONE);
}
private void setLikes(final int likes) {

View File

@ -269,8 +269,8 @@ public final class CommentsFetcher extends AsyncTask<Void, Void, List<CommentMod
}
childCommentModels.get(childCommentsLen - 1).setPageCursor(hasNextPage, childEndCursor);
commentModel.setChildCommentModels(childCommentModels);
commentModels.add(commentModel);
}
commentModels.add(commentModel);
}
}

View File

@ -1,340 +0,0 @@
// package awais.instagrabber.fragments;
//
// import android.content.Context;
// import android.content.DialogInterface;
// import android.content.pm.PackageManager;
// import android.os.AsyncTask;
// import android.os.Bundle;
// import android.util.Log;
// import android.view.LayoutInflater;
// import android.view.View;
// import android.view.ViewGroup;
//
// import androidx.annotation.NonNull;
// import androidx.annotation.Nullable;
// import androidx.appcompat.app.AlertDialog;
// import androidx.fragment.app.Fragment;
// import androidx.fragment.app.FragmentActivity;
// import androidx.lifecycle.ViewModelProvider;
// import androidx.navigation.NavDirections;
// import androidx.navigation.fragment.NavHostFragment;
// import androidx.viewpager2.widget.ViewPager2;
//
// import java.util.ArrayList;
// import java.util.Arrays;
// import java.util.Collections;
// import java.util.List;
//
// import awais.instagrabber.R;
// import awais.instagrabber.adapters.PostViewAdapter;
// import awais.instagrabber.adapters.PostViewAdapter.OnPostViewChildViewClickListener;
// import awais.instagrabber.asyncs.PostFetcher;
// import awais.instagrabber.asyncs.i.iPostFetcher;
// import awais.instagrabber.databinding.FragmentPostViewBinding;
// import awais.instagrabber.interfaces.FetchListener;
// import awais.instagrabber.interfaces.MentionClickListener;
// import awais.instagrabber.models.FeedModel;
// import awais.instagrabber.models.ViewerPostModel;
// import awais.instagrabber.models.ViewerPostModelWrapper;
// import awais.instagrabber.models.enums.DownloadMethod;
// import awais.instagrabber.utils.Constants;
// import awais.instagrabber.utils.CookieUtils;
// import awais.instagrabber.utils.DownloadUtils;
// import awais.instagrabber.utils.Utils;
// import awais.instagrabber.viewmodels.ViewerPostViewModel;
// import awais.instagrabber.webservices.MediaService;
// import awais.instagrabber.webservices.ServiceCallback;
//
// import static androidx.core.content.ContextCompat.checkSelfPermission;
// import static awais.instagrabber.utils.Utils.settingsHelper;
//
// public class PostViewFragment extends Fragment {
// private static final String TAG = "PostViewFragment";
// private static final String COOKIE = settingsHelper.getString(Constants.COOKIE);
//
// private FragmentActivity fragmentActivity;
// private FragmentPostViewBinding binding;
// private ViewPager2 root;
// private boolean shouldRefresh = true;
// private ViewerPostViewModel viewerPostViewModel;
// private boolean isId;
// private int currentPostIndex;
// private List<String> idOrCodeList;
// private boolean hasInitialResult = false;
// private PostViewAdapter adapter;
// private boolean session;
// private MediaService mediaService;
//
// 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);
// fragmentActivity = getActivity();
// mediaService = MediaService.getInstance();
// }
//
// @Nullable
// @Override
// public View onCreateView(@NonNull final LayoutInflater inflater,
// @Nullable final ViewGroup container,
// @Nullable final Bundle savedInstanceState) {
// if (root != null) {
// shouldRefresh = false;
// return root;
// }
// binding = FragmentPostViewBinding.inflate(inflater, container, false);
// root = binding.getRoot();
// setupViewPager();
// return root;
// }
//
// @Override
// public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
// if (!shouldRefresh) return;
// init();
// shouldRefresh = false;
// }
//
// private void setupViewPager() {
// viewerPostViewModel = new ViewModelProvider(fragmentActivity)
// .get(ViewerPostViewModel.class);
// adapter = new PostViewAdapter(clickListener, captionLongClickListener, mentionListener);
// root.setAdapter(adapter);
// root.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
//
// @Override
// public void onPageSelected(final int position) {
// // Log.d(TAG, "onPageSelected: " + position + ", hasInitialResult: " + hasInitialResult);
// if (!hasInitialResult) {
// return;
// }
// currentPostIndex = position;
// fetchPost();
// }
// });
// viewerPostViewModel.getList().observe(fragmentActivity, list -> adapter.submitList(list));
// }
//
// private void init() {
// if (getArguments() == null) return;
// final PostViewFragmentArgs fragmentArgs = PostViewFragmentArgs.fromBundle(getArguments());
// final String[] idOrCodeArray = fragmentArgs.getIdOrCodeArray();
// if (idOrCodeArray.length == 0) return;
// currentPostIndex = fragmentArgs.getIndex();
// if (currentPostIndex < 0) return;
// if (currentPostIndex >= idOrCodeArray.length) return;
// idOrCodeList = Arrays.asList(idOrCodeArray);
// viewerPostViewModel.getList().setValue(createPlaceholderModels(idOrCodeArray.length));
// isId = fragmentArgs.getIsId();
// fetchPost();
// }
//
// private List<ViewerPostModelWrapper> createPlaceholderModels(final int size) {
// final List<ViewerPostModelWrapper> viewerPostModels = new ArrayList<>(size);
// for (int i = 0; i < size; i++) {
// // viewerPostModels.add(new ViewerPostModel[]{ViewerPostModel.getDefaultModel(-i, "")});
// viewerPostModels.add(new ViewerPostModelWrapper(i, null));
// }
// return viewerPostModels;
// }
//
// private void fetchPost() {
// // Log.d(TAG, "fetchPost, currentPostIndex: " + currentPostIndex);
// final List<ViewerPostModelWrapper> list = viewerPostViewModel.getList().getValue();
// if (list != null) {
// final ViewerPostModelWrapper viewerPostModels = list.get(currentPostIndex);
// if (viewerPostModels != null && viewerPostModels
// .getViewerPostModels() != null && viewerPostModels
// .getViewerPostModels().size() > 0) {
// Log.d(TAG, "returning without fetching");
// return;
// }
// }
// if (currentPostIndex >= idOrCodeList.size() || currentPostIndex < 0) return;
// final String idOrShortCode = idOrCodeList.get(currentPostIndex);
// if (isId) {
// new iPostFetcher(idOrShortCode, pfl).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
// return;
// }
// new PostFetcher(idOrShortCode, pfl).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
// }
//
// private void showDownloadDialog(final List<ViewerPostModel> postModels,
// final int childPosition,
// final String username) {
// final List<ViewerPostModel> postModelsToDownload = new ArrayList<>();
// final Context context = getContext();
// if (context == null) return;
// if (!session && postModels.size() > 1) {
// final DialogInterface.OnClickListener clickListener = (dialog, which) -> {
// if (which == DialogInterface.BUTTON_NEGATIVE) {
// postModelsToDownload.addAll(postModels);
// } else if (which == DialogInterface.BUTTON_POSITIVE) {
// postModelsToDownload.add(postModels.get(childPosition));
// } else {
// session = true;
// postModelsToDownload.add(postModels.get(childPosition));
// }
// if (postModelsToDownload.size() > 0) {
// DownloadUtils.batchDownload(context,
// username,
// DownloadMethod.DOWNLOAD_POST_VIEWER,
// postModelsToDownload);
// }
// };
// new AlertDialog.Builder(context)
// .setTitle(R.string.post_viewer_download_dialog_title)
// .setMessage(R.string.post_viewer_download_message)
// .setNeutralButton(R.string.post_viewer_download_session, clickListener)
// .setPositiveButton(R.string.post_viewer_download_current, clickListener)
// .setNegativeButton(R.string.post_viewer_download_album, clickListener).show();
// } else {
// DownloadUtils.batchDownload(context,
// username,
// DownloadMethod.DOWNLOAD_POST_VIEWER,
// Collections.singletonList(postModels.get(childPosition)));
// }
// }
// }

View File

@ -764,6 +764,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
private void setupTitles() {
binding.title.setText(feedModel.getProfileModel().getUsername());
binding.righttitle.setText(feedModel.getProfileModel().getName());
binding.isVerified.setVisibility(feedModel.getProfileModel().isVerified() ? View.VISIBLE : View.GONE);
binding.title.setOnClickListener(v -> navigateToProfile("@" + feedModel.getProfileModel().getUsername()));
binding.righttitle.setOnClickListener(v -> navigateToProfile("@" + feedModel.getProfileModel().getUsername()));
final String locationName = feedModel.getLocationName();

View File

@ -172,7 +172,7 @@ public class ProfileService extends BaseService {
} else {
resourceUrl = mediaNode.has("display_resources") ? ResponseBodyUtils.getHighQualityImage(mediaNode) : displayUrl;
}
JSONObject tempJsonObject = mediaNode.optJSONObject("edge_media_preview_comment");
JSONObject tempJsonObject = mediaNode.optJSONObject("edge_media_to_comment");
final long commentsCount = tempJsonObject != null ? tempJsonObject.optLong("count") : 0;
tempJsonObject = mediaNode.optJSONObject("edge_media_preview_like");
final long likesCount = tempJsonObject != null ? tempJsonObject.optLong("count") : 0;

View File

@ -65,29 +65,42 @@
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:ellipsize="marquee"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
android:textColor="@color/white"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@id/subtitle"
app:layout_constraintEnd_toEndOf="@id/righttitle"
app:layout_constraintEnd_toStartOf="@id/isVerified"
app:layout_constraintStart_toEndOf="@id/profile_pic"
app:layout_constraintTop_toTopOf="@id/profile_pic"
tools:text="Username Username Username" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/isVerified"
android:layout_width="20dp"
android:layout_height="0dp"
android:scaleType="fitCenter"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@id/title"
app:layout_constraintStart_toEndOf="@id/title"
app:layout_constraintTop_toTopOf="@id/title"
app:srcCompat="@drawable/verified"
tools:visibility="visible" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/righttitle"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginStart="4dp"
android:ellipsize="marquee"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
android:textColor="@color/grey_600"
app:layout_constraintBottom_toBottomOf="@id/title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/title"
app:layout_constraintStart_toEndOf="@id/isVerified"
app:layout_constraintTop_toTopOf="@id/title"
tools:text="Full name Full name Full name Full name Full name Full name Full name " />

View File

@ -24,7 +24,7 @@
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tvUsername"
android:layout_width="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:paddingStart="4dp"
@ -36,11 +36,23 @@
android:textColor="?android:textColorPrimary"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@id/tvComment"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/ivProfilePic"
app:layout_constraintTop_toTopOf="parent"
tools:text="username" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/isVerified"
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="fitStart"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@id/tvUsername"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tvUsername"
app:layout_constraintTop_toTopOf="@id/tvUsername"
app:srcCompat="@drawable/verified"
tools:visibility="visible" />
<awais.instagrabber.customviews.RamboTextViewV2
android:id="@+id/tvComment"
android:layout_width="0dp"

View File

@ -35,11 +35,23 @@
android:textColor="?android:textColorPrimary"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@id/tvComment"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/ivProfilePic"
app:layout_constraintTop_toTopOf="parent"
tools:text="username" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/isVerified"
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="fitStart"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@id/tvUsername"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tvUsername"
app:layout_constraintTop_toTopOf="@id/tvUsername"
app:srcCompat="@drawable/verified"
tools:visibility="visible" />
<awais.instagrabber.customviews.RamboTextViewV2
android:id="@+id/tvComment"
android:layout_width="0dp"