1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-12-23 13:26:59 +00:00

Migrate FeedModel and ProfileModel to Media and User

This commit is contained in:
Ammar Githam 2021-01-07 21:36:33 +09:00
parent bca17d3383
commit 0018cd0b7f
198 changed files with 3976 additions and 4540 deletions

View File

@ -22,9 +22,9 @@ import androidx.core.content.ContextCompat;
import awais.instagrabber.R;
import awais.instagrabber.asyncs.PostFetcher;
import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.models.IntentModel;
import awais.instagrabber.models.enums.IntentModelType;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.DownloadUtils;
@ -123,7 +123,7 @@ public final class DirectDownload extends AppCompatActivity {
return;
}
final String text = model.getText();
new PostFetcher(text, new FetchListener<FeedModel>() {
new PostFetcher(text, new FetchListener<Media>() {
@Override
public void doBefore() {
if (notificationManager == null) return;
@ -138,7 +138,7 @@ public final class DirectDownload extends AppCompatActivity {
}
@Override
public void onResult(final FeedModel result) {
public void onResult(final Media result) {
if (notificationManager != null) notificationManager.cancel(NOTIFICATION_ID);
if (result == null) {
finish();

View File

@ -388,7 +388,7 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
private void setupBottomNavigationBar(final boolean setDefaultFromSettings) {
int main_nav_ids = R.array.main_nav_ids;
final String cookie = settingsHelper.getString(Constants.COOKIE);
final boolean isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != null;
final boolean isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != 0;
if (!isLoggedIn) {
main_nav_ids = R.array.logged_out_main_nav_ids;
final int selectedItemId = binding.bottomNavView.getSelectedItemId();

View File

@ -46,8 +46,8 @@ import awais.instagrabber.databinding.LayoutDmReelShareBinding;
import awais.instagrabber.databinding.LayoutDmStoryShareBinding;
import awais.instagrabber.databinding.LayoutDmTextBinding;
import awais.instagrabber.databinding.LayoutDmVoiceMediaBinding;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.models.enums.DirectItemType;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
import awais.instagrabber.utils.DateUtils;
@ -55,7 +55,7 @@ import awais.instagrabber.utils.DateUtils;
public final class DirectItemsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final String TAG = DirectItemsAdapter.class.getSimpleName();
private final ProfileModel currentUser;
private final User currentUser;
private DirectThread thread;
private final AsyncListDiffer<DirectItemOrHeader> differ;
private List<DirectItem> items;
@ -98,7 +98,7 @@ public final class DirectItemsAdapter extends RecyclerView.Adapter<RecyclerView.
}
};
public DirectItemsAdapter(@NonNull final ProfileModel currentUser,
public DirectItemsAdapter(@NonNull final User currentUser,
@NonNull final DirectThread thread) {
this.currentUser = currentUser;
this.thread = thread;

View File

@ -17,7 +17,7 @@ import awais.instagrabber.R;
import awais.instagrabber.adapters.viewholder.DirectUserViewHolder;
import awais.instagrabber.databinding.ItemFavSectionHeaderBinding;
import awais.instagrabber.databinding.LayoutDmUserItemBinding;
import awais.instagrabber.repositories.responses.directmessages.DirectUser;
import awais.instagrabber.repositories.responses.User;
public final class DirectUsersAdapter extends ListAdapter<DirectUsersAdapter.DirectUserOrHeader, RecyclerView.ViewHolder> {
@ -71,13 +71,13 @@ public final class DirectUsersAdapter extends ListAdapter<DirectUsersAdapter.Dir
setHasStableIds(true);
}
public void submitUsers(final List<DirectUser> users, final List<DirectUser> leftUsers) {
public void submitUsers(final List<User> users, final List<User> leftUsers) {
if (users == null && leftUsers == null) return;
final List<DirectUserOrHeader> userOrHeaders = combineLists(users, leftUsers);
submitList(userOrHeaders);
}
private List<DirectUserOrHeader> combineLists(final List<DirectUser> users, final List<DirectUser> leftUsers) {
private List<DirectUserOrHeader> combineLists(final List<User> users, final List<User> leftUsers) {
final ImmutableList.Builder<DirectUserOrHeader> listBuilder = ImmutableList.builder();
if (users != null && !users.isEmpty()) {
listBuilder.add(new DirectUserOrHeader(R.string.members));
@ -116,7 +116,7 @@ public final class DirectUsersAdapter extends ListAdapter<DirectUsersAdapter.Dir
return;
}
if (holder instanceof DirectUserViewHolder) {
final DirectUser user = getItem(position).user;
final User user = getItem(position).user;
((DirectUserViewHolder) holder).bind(position,
user,
user != null && adminUserIds != null && adminUserIds.contains(user.getPk()),
@ -145,13 +145,13 @@ public final class DirectUsersAdapter extends ListAdapter<DirectUsersAdapter.Dir
public static class DirectUserOrHeader {
int headerTitle;
DirectUser user;
User user;
public DirectUserOrHeader(final int headerTitle) {
this.headerTitle = headerTitle;
}
public DirectUserOrHeader(final DirectUser user) {
public DirectUserOrHeader(final User user) {
this.user = user;
}
@ -174,10 +174,10 @@ public final class DirectUsersAdapter extends ListAdapter<DirectUsersAdapter.Dir
}
public interface OnDirectUserClickListener {
void onClick(int position, DirectUser user, boolean selected);
void onClick(int position, User user, boolean selected);
}
public interface OnDirectUserLongClickListener {
boolean onLongClick(int position, DirectUser user);
boolean onLongClick(int position, User user);
}
}

View File

@ -11,6 +11,7 @@ import androidx.recyclerview.widget.ListAdapter;
import awais.instagrabber.adapters.viewholder.TopicClusterViewHolder;
import awais.instagrabber.databinding.ItemDiscoverTopicBinding;
import awais.instagrabber.models.TopicCluster;
import awais.instagrabber.utils.ResponseBodyUtils;
public class DiscoverTopicsAdapter extends ListAdapter<TopicCluster, TopicClusterViewHolder> {
private static final DiffUtil.ItemCallback<TopicCluster> DIFF_CALLBACK = new DiffUtil.ItemCallback<TopicCluster>() {
@ -21,7 +22,8 @@ public class DiscoverTopicsAdapter extends ListAdapter<TopicCluster, TopicCluste
@Override
public boolean areContentsTheSame(@NonNull final TopicCluster oldItem, @NonNull final TopicCluster newItem) {
return oldItem.getCoverMedia().getDisplayUrl().equals(newItem.getCoverMedia().getDisplayUrl())
final String oldThumbUrl = ResponseBodyUtils.getThumbUrl(oldItem.getCoverMedia());
return oldThumbUrl != null && oldThumbUrl.equals(ResponseBodyUtils.getThumbUrl(newItem.getCoverMedia()))
&& oldItem.getTitle().equals(newItem.getTitle());
}
};

View File

@ -11,6 +11,7 @@ import androidx.recyclerview.widget.ListAdapter;
import androidx.recyclerview.widget.RecyclerView;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import awais.instagrabber.adapters.viewholder.FeedGridItemViewHolder;
@ -22,36 +23,44 @@ import awais.instagrabber.databinding.ItemFeedGridBinding;
import awais.instagrabber.databinding.ItemFeedPhotoBinding;
import awais.instagrabber.databinding.ItemFeedSliderBinding;
import awais.instagrabber.databinding.ItemFeedVideoBinding;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.models.PostsLayoutPreferences;
import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.repositories.responses.Caption;
import awais.instagrabber.repositories.responses.Media;
public final class FeedAdapterV2 extends ListAdapter<FeedModel, RecyclerView.ViewHolder> {
public final class FeedAdapterV2 extends ListAdapter<Media, RecyclerView.ViewHolder> {
private static final String TAG = "FeedAdapterV2";
private final FeedItemCallback feedItemCallback;
private final SelectionModeCallback selectionModeCallback;
private final Set<Integer> selectedPositions = new HashSet<>();
private final Set<FeedModel> selectedFeedModels = new HashSet<>();
private final Set<Media> selectedFeedModels = new HashSet<>();
private PostsLayoutPreferences layoutPreferences;
private boolean selectionModeActive = false;
private static final DiffUtil.ItemCallback<FeedModel> DIFF_CALLBACK = new DiffUtil.ItemCallback<FeedModel>() {
private static final DiffUtil.ItemCallback<Media> DIFF_CALLBACK = new DiffUtil.ItemCallback<Media>() {
@Override
public boolean areItemsTheSame(@NonNull final FeedModel oldItem, @NonNull final FeedModel newItem) {
return oldItem.getPostId().equals(newItem.getPostId());
public boolean areItemsTheSame(@NonNull final Media oldItem, @NonNull final Media newItem) {
return oldItem.getPk().equals(newItem.getPk());
}
@Override
public boolean areContentsTheSame(@NonNull final FeedModel oldItem, @NonNull final FeedModel newItem) {
return oldItem.getPostId().equals(newItem.getPostId()) && oldItem.getPostCaption().equals(newItem.getPostCaption());
public boolean areContentsTheSame(@NonNull final Media oldItem, @NonNull final Media newItem) {
final Caption oldItemCaption = oldItem.getCaption();
final Caption newItemCaption = newItem.getCaption();
return oldItem.getPk().equals(newItem.getPk()) && Objects.equals(getCaptionText(oldItemCaption), getCaptionText(newItemCaption));
}
private String getCaptionText(final Caption caption) {
if (caption == null) return null;
return caption.getText();
}
};
private final AdapterSelectionCallback adapterSelectionCallback = new AdapterSelectionCallback() {
@Override
public boolean onPostLongClick(final int position, final FeedModel feedModel) {
public boolean onPostLongClick(final int position, final Media feedModel) {
if (!selectionModeActive) {
selectionModeActive = true;
notifyDataSetChanged();
@ -69,7 +78,7 @@ public final class FeedAdapterV2 extends ListAdapter<FeedModel, RecyclerView.Vie
}
@Override
public void onPostClick(final int position, final FeedModel feedModel) {
public void onPostClick(final int position, final Media feedModel) {
if (!selectionModeActive) return;
if (selectedPositions.contains(position)) {
selectedPositions.remove(position);
@ -140,7 +149,7 @@ public final class FeedAdapterV2 extends ListAdapter<FeedModel, RecyclerView.Vie
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, final int position) {
final FeedModel feedModel = getItem(position);
final Media feedModel = getItem(position);
if (feedModel == null) return;
switch (layoutPreferences.getType()) {
case LINEAR:
@ -161,7 +170,7 @@ public final class FeedAdapterV2 extends ListAdapter<FeedModel, RecyclerView.Vie
@Override
public int getItemViewType(final int position) {
return getItem(position).getItemType().getId();
return getItem(position).getMediaType().getId();
}
public void setLayoutPreferences(@NonNull final PostsLayoutPreferences layoutPreferences) {
@ -198,43 +207,43 @@ public final class FeedAdapterV2 extends ListAdapter<FeedModel, RecyclerView.Vie
// }
public interface FeedItemCallback {
void onPostClick(final FeedModel feedModel,
void onPostClick(final Media feedModel,
final View profilePicView,
final View mainPostImage);
void onProfilePicClick(final FeedModel feedModel,
void onProfilePicClick(final Media feedModel,
final View profilePicView);
void onNameClick(final FeedModel feedModel,
void onNameClick(final Media feedModel,
final View profilePicView);
void onLocationClick(final FeedModel feedModel);
void onLocationClick(final Media feedModel);
void onMentionClick(final String mention);
void onHashtagClick(final String hashtag);
void onCommentsClick(final FeedModel feedModel);
void onCommentsClick(final Media feedModel);
void onDownloadClick(final FeedModel feedModel, final int childPosition);
void onDownloadClick(final Media feedModel, final int childPosition);
void onEmailClick(final String emailId);
void onURLClick(final String url);
void onSliderClick(FeedModel feedModel, int position);
void onSliderClick(Media feedModel, int position);
}
public interface AdapterSelectionCallback {
boolean onPostLongClick(final int position, FeedModel feedModel);
boolean onPostLongClick(final int position, Media feedModel);
void onPostClick(final int position, FeedModel feedModel);
void onPostClick(final int position, Media feedModel);
}
public interface SelectionModeCallback {
void onSelectionStart();
void onSelectionChange(final Set<FeedModel> selectedFeedModels);
void onSelectionChange(final Set<Media> selectedFeedModels);
void onSelectionEnd();
}

View File

@ -2,20 +2,21 @@ package awais.instagrabber.adapters;
import android.view.View;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.repositories.responses.Media;
public class FeedItemCallbackAdapter implements FeedAdapterV2.FeedItemCallback {
@Override
public void onPostClick(final FeedModel feedModel, final View profilePicView, final View mainPostImage) {}
public void onPostClick(final Media media, final View profilePicView, final View mainPostImage) {}
@Override
public void onProfilePicClick(final FeedModel feedModel, final View profilePicView) {}
public void onProfilePicClick(final Media media, final View profilePicView) {}
@Override
public void onNameClick(final FeedModel feedModel, final View profilePicView) {}
public void onNameClick(final Media media, final View profilePicView) {}
@Override
public void onLocationClick(final FeedModel feedModel) {}
public void onLocationClick(final Media media) {}
@Override
public void onMentionClick(final String mention) {}
@ -24,10 +25,10 @@ public class FeedItemCallbackAdapter implements FeedAdapterV2.FeedItemCallback {
public void onHashtagClick(final String hashtag) {}
@Override
public void onCommentsClick(final FeedModel feedModel) {}
public void onCommentsClick(final Media media) {}
@Override
public void onDownloadClick(final FeedModel feedModel, final int childPosition) {}
public void onDownloadClick(final Media media, final int childPosition) {}
@Override
public void onEmailClick(final String emailId) {}
@ -36,5 +37,5 @@ public class FeedItemCallbackAdapter implements FeedAdapterV2.FeedItemCallback {
public void onURLClick(final String url) {}
@Override
public void onSliderClick(final FeedModel feedModel, final int position) {}
public void onSliderClick(final Media media, final int position) {}
}

View File

@ -1,6 +1,5 @@
package awais.instagrabber.adapters;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -12,13 +11,13 @@ import java.util.List;
import awais.instagrabber.adapters.viewholder.FollowsViewHolder;
import awais.instagrabber.databinding.ItemFollowBinding;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.repositories.responses.User;
public final class LikesAdapter extends RecyclerView.Adapter<FollowsViewHolder> {
private final List<ProfileModel> profileModels;
private final List<User> profileModels;
private final View.OnClickListener onClickListener;
public LikesAdapter(final List<ProfileModel> profileModels,
public LikesAdapter(final List<User> profileModels,
final View.OnClickListener onClickListener) {
this.profileModels = profileModels;
this.onClickListener = onClickListener;
@ -34,7 +33,7 @@ public final class LikesAdapter extends RecyclerView.Adapter<FollowsViewHolder>
@Override
public void onBindViewHolder(@NonNull final FollowsViewHolder holder, final int position) {
final ProfileModel model = profileModels.get(position);
final User model = profileModels.get(position);
holder.bind(model, null, onClickListener);
}

View File

@ -1,206 +0,0 @@
package awais.instagrabber.adapters;
import android.net.Uri;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ListAdapter;
import androidx.recyclerview.widget.RecyclerView;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.request.ImageRequestBuilder;
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.ui.PlayerView;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import awais.instagrabber.customviews.drawee.ZoomableDraweeView;
import awais.instagrabber.models.ViewerPostModel;
import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.Utils;
public class PostViewerChildAdapter extends ListAdapter<ViewerPostModel, PostViewerChildAdapter.ChildViewHolder> {
private static final DiffUtil.ItemCallback<ViewerPostModel> diffCallback = new DiffUtil.ItemCallback<ViewerPostModel>() {
@Override
public boolean areItemsTheSame(@NonNull final ViewerPostModel oldItem, @NonNull final ViewerPostModel newItem) {
return oldItem.getPostId().equals(newItem.getPostId()) && oldItem.getShortCode().equals(newItem.getShortCode());
}
@Override
public boolean areContentsTheSame(@NonNull final ViewerPostModel oldItem, @NonNull final ViewerPostModel newItem) {
return oldItem.getPostId().equals(newItem.getPostId()) && oldItem.getShortCode().equals(newItem.getShortCode());
}
};
public PostViewerChildAdapter() {
super(diffCallback);
}
@NonNull
@Override
public ChildViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) {
// final AppCompatTextView textView = new AppCompatTextView(parent.getContext());
// textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
// return new ChildViewHolder(textView);
final MediaItemType mediaItemType = MediaItemType.valueOf(viewType);
if (mediaItemType == null) return getPlaceholder(parent);
switch (mediaItemType) {
case MEDIA_TYPE_IMAGE:
return getImageViewHolder(parent);
case MEDIA_TYPE_VIDEO:
return getVideoViewHolder(parent);
default:
return getPlaceholder(parent);
}
}
private ChildViewHolder getImageViewHolder(final ViewGroup parent) {
final ZoomableDraweeView view = new ZoomableDraweeView(parent.getContext());
view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
return new ChildViewHolder(view);
}
private ChildViewHolder getVideoViewHolder(final ViewGroup parent) {
final PlayerView view = new PlayerView(parent.getContext());
view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
return new ChildViewHolder(view);
}
private ChildViewHolder getPlaceholder(final ViewGroup parent) {
final AppCompatTextView textView = new AppCompatTextView(parent.getContext());
textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
textView.setGravity(Gravity.CENTER);
textView.setText("Placeholder");
return new ChildViewHolder(textView);
}
@Override
public void onBindViewHolder(@NonNull final ChildViewHolder holder, final int position) {
holder.bind(getItem(position));
}
@Override
public int getItemViewType(final int position) {
final ViewerPostModel item = getItem(position);
return item.getItemType().getId();
}
@Override
public void onViewDetachedFromWindow(@NonNull final ChildViewHolder holder) {
if (holder.itemView instanceof PlayerView) {
final Player player = ((PlayerView) holder.itemView).getPlayer();
if (player != null) {
player.setPlayWhenReady(false);
}
}
}
@Override
public void onViewRecycled(@NonNull final ChildViewHolder holder) {
if (holder.itemView instanceof PlayerView) {
final Player player = ((PlayerView) holder.itemView).getPlayer();
if (player != null) {
player.release();
}
return;
}
if (holder.itemView instanceof ZoomableDraweeView) {
((ZoomableDraweeView) holder.itemView).setController(null);
}
}
public static class ChildViewHolder extends RecyclerView.ViewHolder {
public ChildViewHolder(@NonNull final View itemView) {
super(itemView);
}
public void bind(final ViewerPostModel item) {
final MediaItemType mediaItemType = item.getItemType();
switch (mediaItemType) {
case MEDIA_TYPE_IMAGE:
bindImage(item);
break;
case MEDIA_TYPE_VIDEO:
bindVideo(item);
break;
default:
}
}
private void bindImage(final ViewerPostModel item) {
final ZoomableDraweeView imageView = (ZoomableDraweeView) itemView;
imageView.setController(null);
final ImageRequest requestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(item.getDisplayUrl()))
.setLocalThumbnailPreviewsEnabled(true)
.setProgressiveRenderingEnabled(true)
.build();
final DraweeController controller = Fresco.newDraweeControllerBuilder()
.setImageRequest(requestBuilder)
.setOldController(imageView.getController())
// .setControllerListener(new BaseControllerListener<ImageInfo>() {
//
// @Override
// public void onFailure(final String id, final Throwable throwable) {
// // viewerBinding.progressView.setVisibility(View.GONE);
// }
//
// @Override
// public void onFinalImageSet(final String id, final ImageInfo imageInfo, final Animatable animatable) {
// // viewerBinding.progressView.setVisibility(View.GONE);
// }
// })
.build();
imageView.setController(controller);
}
private void bindVideo(final ViewerPostModel item) {
final SimpleExoPlayer player = new SimpleExoPlayer.Builder(itemView.getContext()).build();
final PlayerView playerView = (PlayerView) itemView;
playerView.setPlayer(player);
float vol = Utils.settingsHelper.getBoolean(Constants.MUTED_VIDEOS) ? 0f : 1f;
if (vol == 0f && Utils.sessionVolumeFull) vol = 1f;
player.setVolume(vol);
player.setPlayWhenReady(Utils.settingsHelper.getBoolean(Constants.AUTOPLAY_VIDEOS));
final ProgressiveMediaSource mediaSource = new ProgressiveMediaSource.Factory(
new DefaultDataSourceFactory(itemView.getContext(), "instagram")
).createMediaSource(MediaItem.fromUri(item.getDisplayUrl()));
// mediaSource.addEventListener(new Handler(), new MediaSourceEventListener() {
// @Override
// public void onLoadCompleted(final int windowIndex, @Nullable final MediaSource.MediaPeriodId mediaPeriodId, final LoadEventInfo loadEventInfo, final MediaLoadData mediaLoadData) {
// viewerBinding.progressView.setVisibility(View.GONE);
// }
//
// @Override
// public void onLoadStarted(final int windowIndex, @Nullable final MediaSource.MediaPeriodId mediaPeriodId, final LoadEventInfo loadEventInfo, final MediaLoadData mediaLoadData) {
// viewerBinding.progressView.setVisibility(View.VISIBLE);
// }
//
// @Override
// public void onLoadCanceled(final int windowIndex, @Nullable final MediaSource.MediaPeriodId mediaPeriodId, final LoadEventInfo loadEventInfo, final MediaLoadData mediaLoadData) {
// viewerBinding.progressView.setVisibility(View.GONE);
// }
//
// @Override
// public void onLoadError(final int windowIndex, @Nullable final MediaSource.MediaPeriodId mediaPeriodId, final LoadEventInfo loadEventInfo, final MediaLoadData mediaLoadData, final IOException error, final boolean wasCanceled) {
// viewerBinding.progressView.setVisibility(View.GONE);
// }
// });
player.setMediaSource(mediaSource);
player.prepare();
player.setVolume(vol);
// viewerBinding.bottomPanel.btnMute.setImageResource(vol == 0f ? R.drawable.ic_volume_up_24 : R.drawable.ic_volume_off_24);
// viewerBinding.bottomPanel.btnMute.setOnClickListener(onClickListener);
}
}
}

View File

@ -1,45 +0,0 @@
package awais.instagrabber.adapters;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DiffUtil;
import awais.instagrabber.adapters.viewholder.PostViewHolder;
import awais.instagrabber.databinding.ItemPostBinding;
import awais.instagrabber.models.PostModel;
public final class PostsAdapter extends MultiSelectListAdapter<PostModel, PostViewHolder> {
private static final DiffUtil.ItemCallback<PostModel> DIFF_CALLBACK = new DiffUtil.ItemCallback<PostModel>() {
@Override
public boolean areItemsTheSame(@NonNull final PostModel oldItem, @NonNull final PostModel newItem) {
return oldItem.getPostId().equals(newItem.getPostId());
}
@Override
public boolean areContentsTheSame(@NonNull final PostModel oldItem, @NonNull final PostModel newItem) {
return oldItem.getPostId().equals(newItem.getPostId());
}
};
public PostsAdapter(final OnItemClickListener<PostModel> clickListener,
final OnItemLongClickListener<PostModel> longClickListener) {
super(DIFF_CALLBACK, clickListener, longClickListener);
}
@NonNull
@Override
public PostViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) {
final LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
final ItemPostBinding binding = ItemPostBinding.inflate(layoutInflater, parent, false);
return new PostViewHolder(binding);
}
@Override
public void onBindViewHolder(@NonNull final PostViewHolder holder, final int position) {
final PostModel postModel = getItem(position);
holder.bind(postModel, position, getInternalOnItemClickListener(), getInternalOnLongItemClickListener());
}
}

View File

@ -14,25 +14,25 @@ import awais.instagrabber.customviews.VerticalDragHelper;
import awais.instagrabber.databinding.ItemSliderPhotoBinding;
import awais.instagrabber.databinding.LayoutExoCustomControlsBinding;
import awais.instagrabber.databinding.LayoutVideoPlayerWithThumbnailBinding;
import awais.instagrabber.models.PostChild;
import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.repositories.responses.Media;
public final class SliderItemsAdapter extends ListAdapter<PostChild, SliderItemViewHolder> {
public final class SliderItemsAdapter extends ListAdapter<Media, SliderItemViewHolder> {
private final VerticalDragHelper.OnVerticalDragListener onVerticalDragListener;
private final boolean loadVideoOnItemClick;
private final SliderCallback sliderCallback;
private final LayoutExoCustomControlsBinding controlsBinding;
private static final DiffUtil.ItemCallback<PostChild> DIFF_CALLBACK = new DiffUtil.ItemCallback<PostChild>() {
private static final DiffUtil.ItemCallback<Media> DIFF_CALLBACK = new DiffUtil.ItemCallback<Media>() {
@Override
public boolean areItemsTheSame(@NonNull final PostChild oldItem, @NonNull final PostChild newItem) {
return oldItem.getPostId().equals(newItem.getPostId());
public boolean areItemsTheSame(@NonNull final Media oldItem, @NonNull final Media newItem) {
return oldItem.getPk().equals(newItem.getPk());
}
@Override
public boolean areContentsTheSame(@NonNull final PostChild oldItem, @NonNull final PostChild newItem) {
return oldItem.getPostId().equals(newItem.getPostId());
public boolean areContentsTheSame(@NonNull final Media oldItem, @NonNull final Media newItem) {
return oldItem.getPk().equals(newItem.getPk());
}
};
@ -66,14 +66,14 @@ public final class SliderItemsAdapter extends ListAdapter<PostChild, SliderItemV
@Override
public void onBindViewHolder(@NonNull final SliderItemViewHolder holder, final int position) {
final PostChild model = getItem(position);
holder.bind(model, position, sliderCallback);
final Media media = getItem(position);
holder.bind(media, position, sliderCallback);
}
@Override
public int getItemViewType(final int position) {
final PostChild viewerPostModel = getItem(position);
return viewerPostModel.getItemType().getId();
final Media media = getItem(position);
return media.getMediaType().getId();
}
// @NonNull

View File

@ -14,18 +14,18 @@ import java.util.Set;
import awais.instagrabber.adapters.DirectUsersAdapter.OnDirectUserClickListener;
import awais.instagrabber.adapters.viewholder.DirectUserViewHolder;
import awais.instagrabber.databinding.LayoutDmUserItemBinding;
import awais.instagrabber.repositories.responses.directmessages.DirectUser;
import awais.instagrabber.repositories.responses.User;
public final class UserSearchResultsAdapter extends ListAdapter<DirectUser, DirectUserViewHolder> {
public final class UserSearchResultsAdapter extends ListAdapter<User, DirectUserViewHolder> {
private static final DiffUtil.ItemCallback<DirectUser> DIFF_CALLBACK = new DiffUtil.ItemCallback<DirectUser>() {
private static final DiffUtil.ItemCallback<User> DIFF_CALLBACK = new DiffUtil.ItemCallback<User>() {
@Override
public boolean areItemsTheSame(@NonNull final DirectUser oldItem, @NonNull final DirectUser newItem) {
public boolean areItemsTheSame(@NonNull final User oldItem, @NonNull final User newItem) {
return oldItem.getPk() == newItem.getPk();
}
@Override
public boolean areContentsTheSame(@NonNull final DirectUser oldItem, @NonNull final DirectUser newItem) {
public boolean areContentsTheSame(@NonNull final User oldItem, @NonNull final User newItem) {
return oldItem.getUsername().equals(newItem.getUsername()) &&
oldItem.getFullName().equals(newItem.getFullName());
}
@ -54,7 +54,7 @@ public final class UserSearchResultsAdapter extends ListAdapter<DirectUser, Dire
@Override
public void onBindViewHolder(@NonNull final DirectUserViewHolder holder, final int position) {
final DirectUser user = getItem(position);
final User user = getItem(position);
boolean isSelected = selectedUserIds != null && selectedUserIds.contains(user.getPk());
holder.bind(position, user, false, false, showSelection, isSelected);
}
@ -67,7 +67,7 @@ public final class UserSearchResultsAdapter extends ListAdapter<DirectUser, Dire
public void setSelectedUser(final long userId, final boolean selected) {
if (selectedUserIds == null) return;
int position = -1;
final List<DirectUser> currentList = getCurrentList();
final List<User> currentList = getCurrentList();
for (int i = 0; i < currentList.size(); i++) {
if (currentList.get(i).getPk() == userId) {
position = i;

View File

@ -22,13 +22,13 @@ import awais.instagrabber.adapters.DirectMessageInboxAdapter.OnItemClickListener
import awais.instagrabber.databinding.LayoutDmInboxItemBinding;
import awais.instagrabber.models.enums.DirectItemType;
import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectItemReelShare;
import awais.instagrabber.repositories.responses.directmessages.DirectItemVisualMedia;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
import awais.instagrabber.repositories.responses.directmessages.DirectThreadDirectStory;
import awais.instagrabber.repositories.responses.directmessages.DirectThreadLastSeenAt;
import awais.instagrabber.repositories.responses.directmessages.DirectUser;
import awais.instagrabber.repositories.responses.directmessages.RavenExpiringMediaActionSummary;
import awais.instagrabber.utils.ResponseBodyUtils;
import awais.instagrabber.utils.TextUtils;
@ -72,12 +72,12 @@ public final class DirectInboxItemViewHolder extends RecyclerView.ViewHolder {
}
private void setProfilePics(@NonNull final DirectThread thread) {
final List<DirectUser> users = thread.getUsers();
final List<User> users = thread.getUsers();
if (users.size() > 1) {
binding.profilePic.setVisibility(View.GONE);
binding.multiPicContainer.setVisibility(View.VISIBLE);
for (int i = 0; i < Math.min(3, users.size()); ++i) {
final DirectUser user = users.get(i);
final User user = users.get(i);
final SimpleDraweeView view = multipleProfilePics.get(i);
view.setVisibility(user == null ? View.GONE : View.VISIBLE);
if (user == null) return;
@ -323,17 +323,17 @@ public final class DirectInboxItemViewHolder extends RecyclerView.ViewHolder {
return subtitle;
}
private String getUsername(final List<DirectUser> users,
private String getUsername(final List<User> users,
final long userId,
final long viewerId) {
if (userId == viewerId) {
return "You";
}
final Optional<DirectUser> senderOptional = users.stream()
.filter(Objects::nonNull)
.filter(user -> user.getPk() == userId)
.findFirst();
return senderOptional.map(DirectUser::getUsername).orElse(null);
final Optional<User> senderOptional = users.stream()
.filter(Objects::nonNull)
.filter(user -> user.getPk() == userId)
.findFirst();
return senderOptional.map(User::getUsername).orElse(null);
}
private void setDateTime(@NonNull final DirectItem item) {

View File

@ -15,7 +15,7 @@ import awais.instagrabber.adapters.DirectUsersAdapter.OnDirectUserClickListener;
import awais.instagrabber.adapters.DirectUsersAdapter.OnDirectUserLongClickListener;
import awais.instagrabber.customviews.VerticalImageSpan;
import awais.instagrabber.databinding.LayoutDmUserItemBinding;
import awais.instagrabber.repositories.responses.directmessages.DirectUser;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.utils.Utils;
public class DirectUserViewHolder extends RecyclerView.ViewHolder {
@ -39,7 +39,7 @@ public class DirectUserViewHolder extends RecyclerView.ViewHolder {
}
public void bind(final int position,
final DirectUser user,
final User user,
final boolean isAdmin,
final boolean isInviter,
final boolean showSelection,
@ -60,7 +60,7 @@ public class DirectUserViewHolder extends RecyclerView.ViewHolder {
setSelection(showSelection, isSelected);
}
private void setFullName(final DirectUser user) {
private void setFullName(final User user) {
final SpannableStringBuilder sb = new SpannableStringBuilder(user.getFullName());
if (user.isVerified()) {
if (verifiedSpan == null) {

View File

@ -11,6 +11,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder;
import com.facebook.imagepipeline.common.ResizeOptions;
import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.request.ImageRequestBuilder;
@ -20,9 +21,10 @@ import awais.instagrabber.R;
import awais.instagrabber.adapters.FeedAdapterV2;
import awais.instagrabber.asyncs.DownloadedCheckerAsyncTask;
import awais.instagrabber.databinding.ItemFeedGridBinding;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.models.PostChild;
import awais.instagrabber.models.PostsLayoutPreferences;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.utils.ResponseBodyUtils;
import awais.instagrabber.utils.TextUtils;
import static awais.instagrabber.models.PostsLayoutPreferences.PostsLayoutType.STAGGERED_GRID;
@ -36,7 +38,7 @@ public class FeedGridItemViewHolder extends RecyclerView.ViewHolder {
}
public void bind(final int position,
@NonNull final FeedModel feedModel,
@NonNull final Media media,
@NonNull final PostsLayoutPreferences layoutPreferences,
final FeedAdapterV2.FeedItemCallback feedItemCallback,
final FeedAdapterV2.AdapterSelectionCallback adapterSelectionCallback,
@ -44,28 +46,117 @@ public class FeedGridItemViewHolder extends RecyclerView.ViewHolder {
final boolean selected) {
itemView.setOnClickListener(v -> {
if (!selectionModeActive && feedItemCallback != null) {
feedItemCallback.onPostClick(feedModel, binding.profilePic, binding.postImage);
feedItemCallback.onPostClick(media, binding.profilePic, binding.postImage);
return;
}
if (selectionModeActive && adapterSelectionCallback != null) {
adapterSelectionCallback.onPostClick(position, feedModel);
adapterSelectionCallback.onPostClick(position, media);
}
});
if (adapterSelectionCallback != null) {
itemView.setOnLongClickListener(v -> adapterSelectionCallback.onPostLongClick(position, feedModel));
itemView.setOnLongClickListener(v -> adapterSelectionCallback.onPostLongClick(position, media));
}
binding.selectedView.setVisibility(selected ? View.VISIBLE : View.GONE);
// for rounded borders (clip view to background shape)
itemView.setClipToOutline(layoutPreferences.getHasRoundedCorners());
if (layoutPreferences.getType() == STAGGERED_GRID) {
final float aspectRatio = (float) feedModel.getImageWidth() / feedModel.getImageHeight();
final float aspectRatio = (float) media.getOriginalWidth() / media.getOriginalHeight();
binding.postImage.setAspectRatio(aspectRatio);
} else {
binding.postImage.setAspectRatio(1);
}
setUserDetails(media, layoutPreferences);
String thumbnailUrl = null;
final int typeIconRes;
switch (media.getMediaType()) {
case MEDIA_TYPE_IMAGE:
typeIconRes = -1;
thumbnailUrl = ResponseBodyUtils.getThumbUrl(media);
break;
case MEDIA_TYPE_VIDEO:
thumbnailUrl = ResponseBodyUtils.getThumbUrl(media);
typeIconRes = R.drawable.exo_icon_play;
break;
case MEDIA_TYPE_SLIDER:
final List<Media> sliderItems = media.getCarouselMedia();
if (sliderItems != null) {
final Media child = sliderItems.get(0);
if (child != null) {
thumbnailUrl = ResponseBodyUtils.getThumbUrl(child);
}
}
typeIconRes = R.drawable.ic_checkbox_multiple_blank_stroke;
break;
default:
typeIconRes = -1;
thumbnailUrl = null;
}
setThumbImage(thumbnailUrl);
if (typeIconRes <= 0) {
binding.typeIcon.setVisibility(View.GONE);
} else {
binding.typeIcon.setVisibility(View.VISIBLE);
binding.typeIcon.setImageResource(typeIconRes);
}
final DownloadedCheckerAsyncTask task = new DownloadedCheckerAsyncTask(result -> {
final List<Boolean> checkList = result.get(media.getPk());
if (checkList == null || checkList.isEmpty()) {
return;
}
switch (media.getMediaType()) {
case MEDIA_TYPE_IMAGE:
case MEDIA_TYPE_VIDEO:
binding.downloaded.setVisibility(checkList.get(0) ? View.VISIBLE : View.GONE);
binding.downloaded.setImageTintList(ColorStateList.valueOf(itemView.getResources().getColor(R.color.green_A400)));
break;
case MEDIA_TYPE_SLIDER:
binding.downloaded.setVisibility(checkList.get(0) ? View.VISIBLE : View.GONE);
final List<Media> carouselMedia = media.getCarouselMedia();
boolean allDownloaded = checkList.size() == (carouselMedia == null ? 0 : carouselMedia.size());
if (allDownloaded) {
allDownloaded = checkList.stream().allMatch(downloaded -> downloaded);
}
binding.downloaded.setImageTintList(ColorStateList.valueOf(itemView.getResources().getColor(
allDownloaded ? R.color.green_A400 : R.color.yellow_400)));
break;
default:
}
});
task.execute(media);
}
private void setThumbImage(final String thumbnailUrl) {
if (TextUtils.isEmpty(thumbnailUrl)) {
binding.postImage.setController(null);
return;
}
final ImageRequest requestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(thumbnailUrl))
.setResizeOptions(ResizeOptions.forDimensions(binding.postImage.getWidth(),
binding.postImage.getHeight()))
.setLocalThumbnailPreviewsEnabled(true)
.setProgressiveRenderingEnabled(true)
.build();
final PipelineDraweeControllerBuilder builder = Fresco.newDraweeControllerBuilder()
.setImageRequest(requestBuilder)
.setOldController(binding.postImage.getController());
binding.postImage.setController(builder.build());
}
private void setUserDetails(@NonNull final Media media,
@NonNull final PostsLayoutPreferences layoutPreferences) {
final User user = media.getUser();
if (layoutPreferences.isAvatarVisible()) {
binding.profilePic.setVisibility(TextUtils.isEmpty(feedModel.getProfileModel().getSdProfilePic()) ? View.GONE : View.VISIBLE);
binding.profilePic.setImageURI(feedModel.getProfileModel().getSdProfilePic());
if (user == null) {
binding.profilePic.setVisibility(View.GONE);
} else {
final String profilePicUrl = user.getProfilePicUrl();
if (TextUtils.isEmpty(profilePicUrl)) {
binding.profilePic.setVisibility(View.GONE);
} else {
binding.profilePic.setVisibility(View.VISIBLE);
binding.profilePic.setImageURI(profilePicUrl);
}
}
final ViewGroup.LayoutParams layoutParams = binding.profilePic.getLayoutParams();
@DimenRes final int dimenRes;
switch (layoutPreferences.getProfilePicSize()) {
@ -88,74 +179,19 @@ public class FeedGridItemViewHolder extends RecyclerView.ViewHolder {
binding.profilePic.setVisibility(View.GONE);
}
if (layoutPreferences.isNameVisible()) {
binding.name.setVisibility(TextUtils.isEmpty(feedModel.getProfileModel().getUsername()) ? View.GONE : View.VISIBLE);
binding.name.setText(feedModel.getProfileModel().getUsername());
if (user == null) {
binding.name.setVisibility(View.GONE);
} else {
final String username = user.getUsername();
if (username == null) {
binding.name.setVisibility(View.GONE);
} else {
binding.name.setVisibility(View.VISIBLE);
binding.name.setText(username);
}
}
} else {
binding.name.setVisibility(View.GONE);
}
String thumbnailUrl = null;
final int typeIconRes;
switch (feedModel.getItemType()) {
case MEDIA_TYPE_IMAGE:
typeIconRes = -1;
thumbnailUrl = feedModel.getThumbnailUrl();
break;
case MEDIA_TYPE_VIDEO:
thumbnailUrl = feedModel.getThumbnailUrl();
typeIconRes = R.drawable.exo_icon_play;
break;
case MEDIA_TYPE_SLIDER:
final List<PostChild> sliderItems = feedModel.getSliderItems();
if (sliderItems != null) {
thumbnailUrl = sliderItems.get(0).getThumbnailUrl();
}
typeIconRes = R.drawable.ic_checkbox_multiple_blank_stroke;
break;
default:
typeIconRes = -1;
thumbnailUrl = null;
}
if (TextUtils.isEmpty(thumbnailUrl)) {
binding.postImage.setController(null);
return;
}
if (typeIconRes <= 0) {
binding.typeIcon.setVisibility(View.GONE);
} else {
binding.typeIcon.setVisibility(View.VISIBLE);
binding.typeIcon.setImageResource(typeIconRes);
}
final ImageRequest requestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(thumbnailUrl))
.setLocalThumbnailPreviewsEnabled(true)
.setProgressiveRenderingEnabled(true)
.build();
final PipelineDraweeControllerBuilder builder = Fresco.newDraweeControllerBuilder()
.setImageRequest(requestBuilder)
.setOldController(binding.postImage.getController());
binding.postImage.setController(builder.build());
final DownloadedCheckerAsyncTask task = new DownloadedCheckerAsyncTask(result -> {
final List<Boolean> checkList = result.get(feedModel.getPostId());
if (checkList == null || checkList.isEmpty()) {
return;
}
switch (feedModel.getItemType()) {
case MEDIA_TYPE_IMAGE:
case MEDIA_TYPE_VIDEO:
binding.downloaded.setVisibility(checkList.get(0) ? View.VISIBLE : View.GONE);
binding.downloaded.setImageTintList(ColorStateList.valueOf(itemView.getResources().getColor(R.color.green_A400)));
break;
case MEDIA_TYPE_SLIDER:
binding.downloaded.setVisibility(checkList.get(0) ? View.VISIBLE : View.GONE);
boolean allDownloaded = checkList.size() == feedModel.getSliderItems().size();
if (allDownloaded) {
allDownloaded = checkList.stream().allMatch(downloaded -> downloaded);
}
binding.downloaded.setImageTintList(ColorStateList.valueOf(itemView.getResources().getColor(
allDownloaded ? R.color.green_A400 : R.color.yellow_400)));
break;
default:
}
});
task.execute(feedModel);
}
}

View File

@ -5,7 +5,7 @@ import androidx.recyclerview.widget.RecyclerView;
import awais.instagrabber.adapters.FeedStoriesAdapter;
import awais.instagrabber.databinding.ItemHighlightBinding;
import awais.instagrabber.models.FeedStoryModel;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.repositories.responses.User;
public final class FeedStoryViewHolder extends RecyclerView.ViewHolder {
@ -28,10 +28,10 @@ public final class FeedStoryViewHolder extends RecyclerView.ViewHolder {
if (listener != null) listener.onFeedStoryLongClick(model, position);
return true;
});
final ProfileModel profileModel = model.getProfileModel();
final User profileModel = model.getProfileModel();
binding.title.setText(profileModel.getUsername());
binding.title.setAlpha(model.isFullyRead() ? 0.5F : 1.0F);
binding.icon.setImageURI(profileModel.getSdProfilePic());
binding.icon.setImageURI(profileModel.getProfilePicUrl());
binding.icon.setAlpha(model.isFullyRead() ? 0.5F : 1.0F);
}
}

View File

@ -1,6 +1,5 @@
package awais.instagrabber.adapters.viewholder;
import android.util.Log;
import android.view.View;
import androidx.recyclerview.widget.RecyclerView;
@ -9,7 +8,7 @@ import java.util.List;
import awais.instagrabber.databinding.ItemFollowBinding;
import awais.instagrabber.models.FollowModel;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.repositories.responses.User;
public final class FollowsViewHolder extends RecyclerView.ViewHolder {
@ -20,18 +19,18 @@ public final class FollowsViewHolder extends RecyclerView.ViewHolder {
this.binding = binding;
}
public void bind(final ProfileModel model,
public void bind(final User model,
final List<Long> admins,
final View.OnClickListener onClickListener) {
if (model == null) return;
itemView.setTag(model);
itemView.setOnClickListener(onClickListener);
binding.tvUsername.setText(model.getUsername());
binding.tvFullName.setText(model.getName());
if (admins != null && admins.contains(Long.parseLong(model.getId()))) {
binding.tvFullName.setText(model.getFullName());
if (admins != null && admins.contains(model.getPk())) {
binding.isAdmin.setVisibility(View.VISIBLE);
}
binding.ivProfilePic.setImageURI(model.getSdProfilePic());
binding.ivProfilePic.setImageURI(model.getProfilePicUrl());
}
public void bind(final FollowModel model,

View File

@ -1,43 +0,0 @@
package awais.instagrabber.adapters.viewholder;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import awais.instagrabber.R;
import awais.instagrabber.adapters.MultiSelectListAdapter.OnItemClickListener;
import awais.instagrabber.adapters.MultiSelectListAdapter.OnItemLongClickListener;
import awais.instagrabber.databinding.ItemPostBinding;
import awais.instagrabber.models.PostModel;
import awais.instagrabber.models.enums.MediaItemType;
public final class PostViewHolder extends RecyclerView.ViewHolder {
private final ItemPostBinding binding;
public PostViewHolder(@NonNull final ItemPostBinding binding) {
super(binding.getRoot());
this.binding = binding;
}
public void bind(final PostModel postModel,
final int position,
final OnItemClickListener<PostModel> clickListener,
final OnItemLongClickListener<PostModel> longClickListener) {
if (postModel == null) return;
// postModel.setPosition(position);
itemView.setOnClickListener(v -> clickListener.onItemClick(postModel, position));
itemView.setOnLongClickListener(v -> longClickListener.onItemLongClick(postModel, position));
final MediaItemType itemType = postModel.getItemType();
final boolean isSlider = itemType == MediaItemType.MEDIA_TYPE_SLIDER;
binding.isDownloaded.setVisibility(postModel.isDownloaded() ? View.VISIBLE : View.GONE);
binding.typeIcon.setVisibility(itemType == MediaItemType.MEDIA_TYPE_VIDEO || isSlider ? View.VISIBLE : View.GONE);
binding.typeIcon.setImageResource(isSlider ? R.drawable.ic_slider_24 : R.drawable.ic_video_24);
binding.selectedView.setVisibility(postModel.isSelected() ? View.VISIBLE : View.GONE);
binding.postImage.setImageURI(postModel.getThumbnailUrl());
}
}

View File

@ -6,7 +6,7 @@ import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import awais.instagrabber.adapters.SliderItemsAdapter;
import awais.instagrabber.models.PostChild;
import awais.instagrabber.repositories.responses.Media;
public abstract class SliderItemViewHolder extends RecyclerView.ViewHolder {
private static final String TAG = "FeedSliderItemViewHolder";
@ -15,7 +15,7 @@ public abstract class SliderItemViewHolder extends RecyclerView.ViewHolder {
super(itemView);
}
public abstract void bind(final PostChild model,
public abstract void bind(final Media media,
final int position,
final SliderItemsAdapter.SliderCallback sliderCallback);
}

View File

@ -17,7 +17,8 @@ import awais.instagrabber.adapters.SliderItemsAdapter;
import awais.instagrabber.customviews.VerticalDragHelper;
import awais.instagrabber.customviews.drawee.AnimatedZoomableController;
import awais.instagrabber.databinding.ItemSliderPhotoBinding;
import awais.instagrabber.models.PostChild;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.utils.ResponseBodyUtils;
public class SliderPhotoViewHolder extends SliderItemViewHolder {
private static final String TAG = "FeedSliderPhotoViewHolder";
@ -32,11 +33,11 @@ public class SliderPhotoViewHolder extends SliderItemViewHolder {
this.onVerticalDragListener = onVerticalDragListener;
}
public void bind(@NonNull final PostChild model,
public void bind(@NonNull final Media model,
final int position,
final SliderItemsAdapter.SliderCallback sliderCallback) {
final ImageRequest requestBuilder = ImageRequestBuilder
.newBuilderWithSource(Uri.parse(model.getDisplayUrl()))
.newBuilderWithSource(Uri.parse(ResponseBodyUtils.getImageUrl(model)))
.setLocalThumbnailPreviewsEnabled(true)
.build();
binding.getRoot()
@ -59,7 +60,7 @@ public class SliderPhotoViewHolder extends SliderItemViewHolder {
}
}
})
.setLowResImageRequest(ImageRequest.fromUri(model.getThumbnailUrl()))
.setLowResImageRequest(ImageRequest.fromUri(ResponseBodyUtils.getThumbUrl(model)))
.build());
// binding.getRoot().setOnClickListener(v -> {
// if (sliderCallback != null) {

View File

@ -5,15 +5,19 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull;
import java.util.List;
import awais.instagrabber.adapters.SliderItemsAdapter;
import awais.instagrabber.customviews.VerticalDragHelper;
import awais.instagrabber.customviews.VideoPlayerCallbackAdapter;
import awais.instagrabber.customviews.VideoPlayerViewHelper;
import awais.instagrabber.databinding.LayoutExoCustomControlsBinding;
import awais.instagrabber.databinding.LayoutVideoPlayerWithThumbnailBinding;
import awais.instagrabber.models.PostChild;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.VideoVersion;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.NumberUtils;
import awais.instagrabber.utils.ResponseBodyUtils;
import awais.instagrabber.utils.Utils;
import static awais.instagrabber.utils.Utils.settingsHelper;
@ -57,7 +61,7 @@ public class SliderVideoViewHolder extends SliderItemViewHolder {
}
}
public void bind(@NonNull final PostChild model,
public void bind(@NonNull final Media media,
final int position,
final SliderItemsAdapter.SliderCallback sliderCallback) {
final float vol = settingsHelper.getBoolean(Constants.MUTED_VIDEOS) ? 0f : 1f;
@ -82,7 +86,7 @@ public class SliderVideoViewHolder extends SliderItemViewHolder {
// binding.itemFeedBottom.btnMute.setVisibility(View.VISIBLE);
final ViewGroup.LayoutParams layoutParams = binding.playerView.getLayoutParams();
final int requiredWidth = Utils.displayMetrics.widthPixels;
final int resultingHeight = NumberUtils.getResultingHeight(requiredWidth, model.getHeight(), model.getWidth());
final int resultingHeight = NumberUtils.getResultingHeight(requiredWidth, media.getOriginalHeight(), media.getOriginalWidth());
layoutParams.width = requiredWidth;
layoutParams.height = resultingHeight;
binding.playerView.requestLayout();
@ -103,13 +107,21 @@ public class SliderVideoViewHolder extends SliderItemViewHolder {
}
}
};
final float aspectRatio = (float) model.getWidth() / model.getHeight();
final float aspectRatio = (float) media.getOriginalWidth() / media.getOriginalHeight();
String videoUrl = null;
final List<VideoVersion> videoVersions = media.getVideoVersions();
if (videoVersions != null && !videoVersions.isEmpty()) {
final VideoVersion videoVersion = videoVersions.get(0);
if (videoVersion != null) {
videoUrl = videoVersion.getUrl();
}
}
videoPlayerViewHelper = new VideoPlayerViewHelper(binding.getRoot().getContext(),
binding,
model.getDisplayUrl(),
videoUrl,
vol,
aspectRatio,
model.getThumbnailUrl(),
ResponseBodyUtils.getThumbUrl(media),
loadVideoOnItemClick,
controlsBinding,
videoPlayerCallback);

View File

@ -1,6 +1,5 @@
package awais.instagrabber.adapters.viewholder;
import android.text.TextUtils;
import android.view.View;
import androidx.recyclerview.widget.RecyclerView;
@ -34,7 +33,7 @@ public final class StoryListViewHolder extends RecyclerView.ViewHolder {
binding.tvDate.setText(model.getDateTime());
binding.tvUsername.setText(model.getProfileModel().getUsername());
binding.ivProfilePic.setImageURI(model.getProfileModel().getSdProfilePic());
binding.ivProfilePic.setImageURI(model.getProfileModel().getProfilePicUrl());
binding.ivProfilePic.setOnClickListener(v -> {
if (notificationClickListener == null) return;
notificationClickListener.onProfileClick(model.getProfileModel().getUsername());
@ -43,8 +42,7 @@ public final class StoryListViewHolder extends RecyclerView.ViewHolder {
if (model.getFirstStoryModel() != null) {
binding.ivPreviewPic.setVisibility(View.VISIBLE);
binding.ivPreviewPic.setImageURI(model.getFirstStoryModel().getThumbnail());
}
else binding.ivPreviewPic.setVisibility(View.INVISIBLE);
} else binding.ivPreviewPic.setVisibility(View.INVISIBLE);
float alpha = model.isFullyRead() ? 0.5F : 1.0F;
binding.ivProfilePic.setAlpha(alpha);

View File

@ -27,6 +27,7 @@ import awais.instagrabber.R;
import awais.instagrabber.adapters.DiscoverTopicsAdapter;
import awais.instagrabber.databinding.ItemDiscoverTopicBinding;
import awais.instagrabber.models.TopicCluster;
import awais.instagrabber.utils.ResponseBodyUtils;
public class TopicClusterViewHolder extends RecyclerView.ViewHolder {
private final ItemDiscoverTopicBinding binding;
@ -57,43 +58,48 @@ public class TopicClusterViewHolder extends RecyclerView.ViewHolder {
}
// binding.title.setTransitionName("title-" + topicCluster.getId());
binding.cover.setTransitionName("cover-" + topicCluster.getId());
final ImageRequest imageRequest = ImageRequestBuilder
.newBuilderWithSource(Uri.parse(topicCluster.getCoverMedia().getDisplayUrl()))
.build();
final ImagePipeline imagePipeline = Fresco.getImagePipeline();
final DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline
.fetchDecodedImage(imageRequest, CallerThreadExecutor.getInstance());
dataSource.subscribe(new BaseBitmapDataSubscriber() {
@Override
public void onNewResultImpl(@Nullable Bitmap bitmap) {
if (dataSource.isFinished()) {
final String thumbUrl = ResponseBodyUtils.getThumbUrl(topicCluster.getCoverMedia());
if (thumbUrl == null) {
binding.cover.setImageURI((String) null);
} else {
final ImageRequest imageRequest = ImageRequestBuilder
.newBuilderWithSource(Uri.parse(thumbUrl))
.build();
final ImagePipeline imagePipeline = Fresco.getImagePipeline();
final DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline
.fetchDecodedImage(imageRequest, CallerThreadExecutor.getInstance());
dataSource.subscribe(new BaseBitmapDataSubscriber() {
@Override
public void onNewResultImpl(@Nullable Bitmap bitmap) {
if (dataSource.isFinished()) {
dataSource.close();
}
if (bitmap != null) {
Palette.from(bitmap).generate(p -> {
final Palette.Swatch swatch = p.getDominantSwatch();
final Resources resources = itemView.getResources();
int titleTextColor = resources.getColor(R.color.white);
if (swatch != null) {
backgroundColor.set(swatch.getRgb());
GradientDrawable gd = new GradientDrawable(
GradientDrawable.Orientation.TOP_BOTTOM,
new int[]{Color.TRANSPARENT, backgroundColor.get()});
titleTextColor = swatch.getTitleTextColor();
binding.background.setBackground(gd);
}
titleColor.set(titleTextColor);
binding.title.setTextColor(titleTextColor);
});
}
}
@Override
public void onFailureImpl(@NonNull DataSource dataSource) {
dataSource.close();
}
if (bitmap != null) {
Palette.from(bitmap).generate(p -> {
final Palette.Swatch swatch = p.getDominantSwatch();
final Resources resources = itemView.getResources();
int titleTextColor = resources.getColor(R.color.white);
if (swatch != null) {
backgroundColor.set(swatch.getRgb());
GradientDrawable gd = new GradientDrawable(
GradientDrawable.Orientation.TOP_BOTTOM,
new int[]{Color.TRANSPARENT, backgroundColor.get()});
titleTextColor = swatch.getTitleTextColor();
binding.background.setBackground(gd);
}
titleColor.set(titleTextColor);
binding.title.setTextColor(titleTextColor);
});
}
}
@Override
public void onFailureImpl(@NonNull DataSource dataSource) {
dataSource.close();
}
}, CallerThreadExecutor.getInstance());
binding.cover.setImageRequest(imageRequest);
}, CallerThreadExecutor.getInstance());
binding.cover.setImageRequest(imageRequest);
}
binding.title.setText(topicCluster.getTitle());
}
}

View File

@ -9,7 +9,7 @@ import awais.instagrabber.R;
import awais.instagrabber.adapters.CommentsAdapter.CommentCallback;
import awais.instagrabber.databinding.ItemCommentSmallBinding;
import awais.instagrabber.models.CommentModel;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.utils.Utils;
public final class ChildCommentViewHolder extends RecyclerView.ViewHolder {
@ -75,10 +75,10 @@ public final class ChildCommentViewHolder extends RecyclerView.ViewHolder {
}
private void setUser(final CommentModel comment) {
final ProfileModel profileModel = comment.getProfileModel();
final User profileModel = comment.getProfileModel();
if (profileModel == null) return;
binding.tvUsername.setText(profileModel.getUsername());
binding.ivProfilePic.setImageURI(profileModel.getSdProfilePic());
binding.ivProfilePic.setImageURI(profileModel.getProfilePicUrl());
binding.isVerified.setVisibility(profileModel.isVerified() ? View.VISIBLE : View.GONE);
}

View File

@ -9,7 +9,7 @@ import awais.instagrabber.R;
import awais.instagrabber.adapters.CommentsAdapter.CommentCallback;
import awais.instagrabber.databinding.ItemCommentBinding;
import awais.instagrabber.models.CommentModel;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.utils.Utils;
public final class ParentCommentViewHolder extends RecyclerView.ViewHolder {
@ -75,10 +75,10 @@ public final class ParentCommentViewHolder extends RecyclerView.ViewHolder {
}
private void setUser(final CommentModel comment) {
final ProfileModel profileModel = comment.getProfileModel();
final User profileModel = comment.getProfileModel();
if (profileModel == null) return;
binding.tvUsername.setText(profileModel.getUsername());
binding.ivProfilePic.setImageURI(profileModel.getSdProfilePic());
binding.ivProfilePic.setImageURI(profileModel.getProfilePicUrl());
binding.isVerified.setVisibility(profileModel.isVerified() ? View.VISIBLE : View.GONE);
}

View File

@ -16,7 +16,7 @@ import awais.instagrabber.R;
import awais.instagrabber.databinding.LayoutDmActionLogBinding;
import awais.instagrabber.databinding.LayoutDmBaseBinding;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectItemActionLog;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
@ -28,7 +28,7 @@ public class DirectItemActionLogViewHolder extends DirectItemViewHolder {
public DirectItemActionLogViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
final LayoutDmActionLogBinding binding,
final ProfileModel currentUser,
final User currentUser,
final DirectThread thread,
final MentionClickListener mentionClickListener,
final View.OnClickListener onClickListener) {

View File

@ -11,9 +11,9 @@ import com.facebook.drawee.backends.pipeline.Fresco;
import awais.instagrabber.databinding.LayoutDmAnimatedMediaBinding;
import awais.instagrabber.databinding.LayoutDmBaseBinding;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.repositories.responses.directmessages.AnimatedMediaFixedHeight;
import awais.instagrabber.repositories.responses.directmessages.AnimatedMediaImages;
import awais.instagrabber.repositories.responses.AnimatedMediaFixedHeight;
import awais.instagrabber.repositories.responses.AnimatedMediaImages;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectItemAnimatedMedia;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
@ -25,7 +25,7 @@ public class DirectItemAnimatedMediaViewHolder extends DirectItemViewHolder {
public DirectItemAnimatedMediaViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
@NonNull final LayoutDmAnimatedMediaBinding binding,
final ProfileModel currentUser,
final User currentUser,
final DirectThread thread,
final MentionClickListener mentionClickListener,
final View.OnClickListener onClickListener) {

View File

@ -9,7 +9,7 @@ import awais.instagrabber.R;
import awais.instagrabber.databinding.LayoutDmBaseBinding;
import awais.instagrabber.databinding.LayoutDmTextBinding;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
@ -19,7 +19,7 @@ public class DirectItemDefaultViewHolder extends DirectItemViewHolder {
public DirectItemDefaultViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
@NonNull final LayoutDmTextBinding binding,
final ProfileModel currentUser,
final User currentUser,
final DirectThread thread,
final MentionClickListener mentionClickListener,
final View.OnClickListener onClickListener) {

View File

@ -7,22 +7,19 @@ import androidx.annotation.NonNull;
import awais.instagrabber.databinding.LayoutDmBaseBinding;
import awais.instagrabber.databinding.LayoutDmLikeBinding;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
public class DirectItemLikeViewHolder extends DirectItemViewHolder {
private final LayoutDmLikeBinding binding;
public DirectItemLikeViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
@NonNull final LayoutDmLikeBinding binding,
final ProfileModel currentUser,
final User currentUser,
final DirectThread thread,
final View.OnClickListener onClickListener,
final MentionClickListener mentionClickListener) {
super(baseBinding, currentUser, thread, onClickListener);
this.binding = binding;
setItemView(binding.getRoot());
}

View File

@ -8,7 +8,7 @@ import androidx.annotation.NonNull;
import awais.instagrabber.databinding.LayoutDmBaseBinding;
import awais.instagrabber.databinding.LayoutDmLinkBinding;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectItemLink;
import awais.instagrabber.repositories.responses.directmessages.DirectItemLinkContext;
@ -21,7 +21,7 @@ public class DirectItemLinkViewHolder extends DirectItemViewHolder {
public DirectItemLinkViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
final LayoutDmLinkBinding binding,
final ProfileModel currentUser,
final User currentUser,
final DirectThread thread,
final MentionClickListener mentionClickListener,
final View.OnClickListener onClickListener) {

View File

@ -15,35 +15,32 @@ import awais.instagrabber.R;
import awais.instagrabber.databinding.LayoutDmBaseBinding;
import awais.instagrabber.databinding.LayoutDmMediaShareBinding;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.models.enums.DirectItemType;
import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.repositories.responses.directmessages.Caption;
import awais.instagrabber.repositories.responses.Caption;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectItemClip;
import awais.instagrabber.repositories.responses.directmessages.DirectItemFelixShare;
import awais.instagrabber.repositories.responses.directmessages.DirectItemMedia;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
import awais.instagrabber.repositories.responses.directmessages.DirectUser;
import awais.instagrabber.utils.NumberUtils;
import awais.instagrabber.utils.ResponseBodyUtils;
public class DirectItemMediaShareViewHolder extends DirectItemViewHolder {
private final LayoutDmMediaShareBinding binding;
private final int maxWidth;
private final RoundingParams incomingRoundingParams;
private final RoundingParams outgoingRoundingParams;
public DirectItemMediaShareViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
@NonNull final LayoutDmMediaShareBinding binding,
final ProfileModel currentUser,
final User currentUser,
final DirectThread thread,
final MentionClickListener mentionClickListener,
final View.OnClickListener onClickListener) {
super(baseBinding, currentUser, thread, onClickListener);
this.binding = binding;
maxWidth = windowWidth - margin - dmRadiusSmall;
incomingRoundingParams = RoundingParams.fromCornersRadii(dmRadiusSmall, dmRadius, dmRadius, dmRadius);
outgoingRoundingParams = RoundingParams.fromCornersRadii(dmRadius, dmRadiusSmall, dmRadius, dmRadius);
setItemView(binding.getRoot());
@ -59,7 +56,7 @@ public class DirectItemMediaShareViewHolder extends DirectItemViewHolder {
binding.topBg.setBackgroundResource(messageDirection == MessageDirection.INCOMING
? R.drawable.bg_media_share_top_incoming
: R.drawable.bg_media_share_top_outgoing);
DirectItemMedia media = null;
Media media = null;
if (item.getItemType() == DirectItemType.MEDIA_SHARE) {
media = item.getMediaShare();
} else if (item.getItemType() == DirectItemType.CLIP) {
@ -72,7 +69,7 @@ public class DirectItemMediaShareViewHolder extends DirectItemViewHolder {
media = felixShare.getVideo();
}
if (media == null) return;
final DirectUser user = media.getUser();
final User user = media.getUser();
if (user != null) {
binding.username.setVisibility(View.VISIBLE);
binding.profilePic.setVisibility(View.VISIBLE);

View File

@ -13,12 +13,12 @@ import com.facebook.drawee.generic.RoundingParams;
import awais.instagrabber.databinding.LayoutDmBaseBinding;
import awais.instagrabber.databinding.LayoutDmMediaBinding;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.repositories.responses.ImageVersions2;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectItemMedia;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
import awais.instagrabber.repositories.responses.directmessages.ImageVersions2;
import awais.instagrabber.utils.NumberUtils;
import awais.instagrabber.utils.ResponseBodyUtils;
@ -30,7 +30,7 @@ public class DirectItemMediaViewHolder extends DirectItemViewHolder {
public DirectItemMediaViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
@NonNull final LayoutDmMediaBinding binding,
final ProfileModel currentUser,
final User currentUser,
final DirectThread thread,
final MentionClickListener mentionClickListener,
final View.OnClickListener onClickListener) {
@ -48,7 +48,7 @@ public class DirectItemMediaViewHolder extends DirectItemViewHolder {
.setRoundingParams(roundingParams)
.setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP)
.build());
final DirectItemMedia media = directItemModel.getMedia();
final Media media = directItemModel.getMedia();
final MediaItemType modelMediaType = media.getMediaType();
binding.typeIcon.setVisibility(modelMediaType == MediaItemType.MEDIA_TYPE_VIDEO || modelMediaType == MediaItemType.MEDIA_TYPE_SLIDER
? View.VISIBLE

View File

@ -7,7 +7,7 @@ import androidx.annotation.NonNull;
import awais.instagrabber.databinding.LayoutDmBaseBinding;
import awais.instagrabber.databinding.LayoutDmTextBinding;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
@ -17,7 +17,7 @@ public class DirectItemPlaceholderViewHolder extends DirectItemViewHolder {
public DirectItemPlaceholderViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
final LayoutDmTextBinding binding,
final ProfileModel currentUser,
final User currentUser,
final DirectThread thread,
final MentionClickListener mentionClickListener,
final View.OnClickListener onClickListener) {

View File

@ -16,14 +16,13 @@ import awais.instagrabber.R;
import awais.instagrabber.databinding.LayoutDmBaseBinding;
import awais.instagrabber.databinding.LayoutDmProfileBinding;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.models.enums.DirectItemType;
import awais.instagrabber.repositories.responses.ImageVersions2;
import awais.instagrabber.repositories.responses.Location;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectItemLocation;
import awais.instagrabber.repositories.responses.directmessages.DirectItemMedia;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
import awais.instagrabber.repositories.responses.directmessages.DirectUser;
import awais.instagrabber.repositories.responses.directmessages.ImageVersions2;
import awais.instagrabber.utils.ResponseBodyUtils;
import awais.instagrabber.utils.TextUtils;
@ -34,7 +33,7 @@ public class DirectItemProfileViewHolder extends DirectItemViewHolder {
public DirectItemProfileViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
@NonNull final LayoutDmProfileBinding binding,
final ProfileModel currentUser,
final User currentUser,
final DirectThread thread,
final MentionClickListener mentionClickListener,
final View.OnClickListener onClickListener) {
@ -74,7 +73,7 @@ public class DirectItemProfileViewHolder extends DirectItemViewHolder {
for (final SimpleDraweeView previewView : previewViews) {
previewView.setImageURI((String) null);
}
final List<DirectItemMedia> previewMedias = item.getPreviewMedias();
final List<Media> previewMedias = item.getPreviewMedias();
if (previewMedias.size() <= 0) {
binding.firstRow.setVisibility(View.GONE);
binding.secondRow.setVisibility(View.GONE);
@ -85,7 +84,7 @@ public class DirectItemProfileViewHolder extends DirectItemViewHolder {
binding.secondRow.setVisibility(View.GONE);
}
for (int i = 0; i < previewMedias.size(); i++) {
final DirectItemMedia previewMedia = previewMedias.get(i);
final Media previewMedia = previewMedias.get(i);
if (previewMedia == null) continue;
final ImageVersions2 imageVersions2 = previewMedia.getImageVersions2();
final String url = ResponseBodyUtils.getThumbUrl(imageVersions2);
@ -95,7 +94,7 @@ public class DirectItemProfileViewHolder extends DirectItemViewHolder {
}
private void setProfile(@NonNull final DirectItem item) {
final DirectUser profile = item.getProfile();
final User profile = item.getProfile();
if (profile == null) return;
binding.profilePic.setImageURI(profile.getProfilePicUrl());
binding.username.setText(profile.getUsername());
@ -104,7 +103,7 @@ public class DirectItemProfileViewHolder extends DirectItemViewHolder {
}
private void setLocation(@NonNull final DirectItem item) {
final DirectItemLocation location = item.getLocation();
final Location location = item.getLocation();
if (location == null) return;
binding.profilePic.setVisibility(View.GONE);
binding.username.setText(location.getName());

View File

@ -14,14 +14,14 @@ import com.facebook.drawee.generic.RoundingParams;
import awais.instagrabber.databinding.LayoutDmBaseBinding;
import awais.instagrabber.databinding.LayoutDmRavenMediaBinding;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.models.enums.RavenMediaViewMode;
import awais.instagrabber.repositories.responses.ImageVersions2;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectItemMedia;
import awais.instagrabber.repositories.responses.directmessages.DirectItemVisualMedia;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
import awais.instagrabber.repositories.responses.directmessages.ImageVersions2;
import awais.instagrabber.utils.NumberUtils;
import awais.instagrabber.utils.ResponseBodyUtils;
@ -32,7 +32,7 @@ public class DirectItemRavenMediaViewHolder extends DirectItemViewHolder {
public DirectItemRavenMediaViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
@NonNull final LayoutDmRavenMediaBinding binding,
final ProfileModel currentUser,
final User currentUser,
final DirectThread thread,
final MentionClickListener mentionClickListener,
final View.OnClickListener onClickListener) {
@ -47,7 +47,7 @@ public class DirectItemRavenMediaViewHolder extends DirectItemViewHolder {
public void bindItem(final DirectItem directItemModel, final MessageDirection messageDirection) {
removeBg();
final DirectItemVisualMedia visualMedia = directItemModel.getVisualMedia();
final DirectItemMedia media = visualMedia.getMedia();
final Media media = visualMedia.getMedia();
if (media == null) return;
setExpiryInfo(visualMedia);
setPreview(visualMedia, messageDirection);
@ -114,7 +114,7 @@ public class DirectItemRavenMediaViewHolder extends DirectItemViewHolder {
}
private void setExpiryInfo(final DirectItemVisualMedia visualMedia) {
final DirectItemMedia media = visualMedia.getMedia();
final Media media = visualMedia.getMedia();
final RavenMediaViewMode viewMode = visualMedia.getViewMode();
if (viewMode != RavenMediaViewMode.PERMANENT) {
final MediaItemType mediaType = media.getMediaType();
@ -152,7 +152,7 @@ public class DirectItemRavenMediaViewHolder extends DirectItemViewHolder {
private void setPreview(final DirectItemVisualMedia visualMedia,
final MessageDirection messageDirection) {
final DirectItemMedia media = visualMedia.getMedia();
final Media media = visualMedia.getMedia();
final boolean expired = media.getPk() == null;
if (expired) {
binding.preview.setVisibility(View.GONE);

View File

@ -13,14 +13,13 @@ import awais.instagrabber.R;
import awais.instagrabber.databinding.LayoutDmBaseBinding;
import awais.instagrabber.databinding.LayoutDmReelShareBinding;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.repositories.responses.ImageVersions2;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectItemMedia;
import awais.instagrabber.repositories.responses.directmessages.DirectItemReelShare;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
import awais.instagrabber.repositories.responses.directmessages.DirectUser;
import awais.instagrabber.repositories.responses.directmessages.ImageVersions2;
import awais.instagrabber.utils.ResponseBodyUtils;
import awais.instagrabber.utils.TextUtils;
@ -30,7 +29,7 @@ public class DirectItemReelShareViewHolder extends DirectItemViewHolder {
public DirectItemReelShareViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
@NonNull final LayoutDmReelShareBinding binding,
final ProfileModel currentUser,
final User currentUser,
final DirectThread thread,
final MentionClickListener mentionClickListener,
final View.OnClickListener onClickListener) {
@ -46,9 +45,9 @@ public class DirectItemReelShareViewHolder extends DirectItemViewHolder {
final String type = reelShare.getType();
if (type == null) return;
final boolean isSelf = isSelf(item);
final DirectItemMedia media = reelShare.getMedia();
final Media media = reelShare.getMedia();
if (media == null) return;
final DirectUser user = media.getUser();
final User user = media.getUser();
if (user == null) return;
final boolean expired = media.getMediaType() == null;
if (expired) {
@ -155,7 +154,7 @@ public class DirectItemReelShareViewHolder extends DirectItemViewHolder {
binding.message.setText(text);
}
private void setPreview(final DirectItemMedia media) {
private void setPreview(final Media media) {
final MediaItemType mediaType = media.getMediaType();
if (mediaType == null) return;
binding.typeIcon.setVisibility(mediaType == MediaItemType.MEDIA_TYPE_VIDEO || mediaType == MediaItemType.MEDIA_TYPE_SLIDER

View File

@ -13,13 +13,13 @@ import com.facebook.drawee.generic.RoundingParams;
import awais.instagrabber.databinding.LayoutDmBaseBinding;
import awais.instagrabber.databinding.LayoutDmStoryShareBinding;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.repositories.responses.ImageVersions2;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectItemMedia;
import awais.instagrabber.repositories.responses.directmessages.DirectItemStoryShare;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
import awais.instagrabber.repositories.responses.directmessages.ImageVersions2;
import awais.instagrabber.utils.NumberUtils;
import awais.instagrabber.utils.ResponseBodyUtils;
import awais.instagrabber.utils.TextUtils;
@ -31,7 +31,7 @@ public class DirectItemStoryShareViewHolder extends DirectItemViewHolder {
public DirectItemStoryShareViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
@NonNull final LayoutDmStoryShareBinding binding,
final ProfileModel currentUser,
final User currentUser,
final DirectThread thread,
final MentionClickListener mentionClickListener,
final View.OnClickListener onClickListener) {
@ -64,7 +64,7 @@ public class DirectItemStoryShareViewHolder extends DirectItemViewHolder {
binding.text.setVisibility(View.VISIBLE);
return;
}
final DirectItemMedia storyShareMedia = storyShare.getMedia();
final Media storyShareMedia = storyShare.getMedia();
final MediaItemType mediaType = storyShareMedia.getMediaType();
binding.typeIcon.setVisibility(mediaType == MediaItemType.MEDIA_TYPE_VIDEO ? View.VISIBLE : View.GONE);
final RoundingParams roundingParams = messageDirection == MessageDirection.INCOMING

View File

@ -7,7 +7,7 @@ import androidx.annotation.NonNull;
import awais.instagrabber.databinding.LayoutDmBaseBinding;
import awais.instagrabber.databinding.LayoutDmTextBinding;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
@ -17,7 +17,7 @@ public class DirectItemTextViewHolder extends DirectItemViewHolder {
public DirectItemTextViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
@NonNull final LayoutDmTextBinding binding,
final ProfileModel currentUser,
final User currentUser,
final DirectThread thread,
final View.OnClickListener onClickListener,
final MentionClickListener mentionClickListener) {

View File

@ -14,7 +14,7 @@ import awais.instagrabber.R;
import awais.instagrabber.databinding.LayoutDmActionLogBinding;
import awais.instagrabber.databinding.LayoutDmBaseBinding;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectItemActionLog;
import awais.instagrabber.repositories.responses.directmessages.DirectItemVideoCallEvent;
@ -27,7 +27,7 @@ public class DirectItemVideoCallEventViewHolder extends DirectItemViewHolder {
public DirectItemVideoCallEventViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
final LayoutDmActionLogBinding binding,
final ProfileModel currentUser,
final User currentUser,
final DirectThread thread,
final MentionClickListener mentionClickListener,
final View.OnClickListener onClickListener) {

View File

@ -20,22 +20,21 @@ import java.util.stream.Collectors;
import awais.instagrabber.R;
import awais.instagrabber.databinding.LayoutDmBaseBinding;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.models.enums.DirectItemType;
import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectItemEmojiReaction;
import awais.instagrabber.repositories.responses.directmessages.DirectItemMedia;
import awais.instagrabber.repositories.responses.directmessages.DirectItemReactions;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
import awais.instagrabber.repositories.responses.directmessages.DirectUser;
import awais.instagrabber.utils.ResponseBodyUtils;
public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder {
private static final String TAG = DirectItemViewHolder.class.getSimpleName();
private final LayoutDmBaseBinding binding;
private final DirectUser currentUser;
private final User currentUser;
private final DirectThread thread;
protected final int margin;
protected final int dmRadius;
@ -48,16 +47,16 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder {
protected final int mediaImageMaxWidth;
public DirectItemViewHolder(@NonNull final LayoutDmBaseBinding binding,
@NonNull final ProfileModel currentUser,
@NonNull final User currentUser,
@NonNull final DirectThread thread,
@NonNull final View.OnClickListener onClickListener) {
super(binding.getRoot());
this.binding = binding;
this.currentUser = DirectUser.fromProfileModel(currentUser);
this.currentUser = currentUser;
this.thread = thread;
userIds = thread.getUsers()
.stream()
.map(DirectUser::getPk)
.map(User::getPk)
.collect(Collectors.toList());
binding.ivProfilePic.setVisibility(thread.isGroup() ? View.VISIBLE : View.GONE);
binding.ivProfilePic.setOnClickListener(thread.isGroup() ? onClickListener : null);
@ -91,7 +90,7 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder {
binding.ivProfilePic.setVisibility(messageDirection == MessageDirection.INCOMING && thread.isGroup() ? View.VISIBLE : View.GONE);
binding.tvUsername.setVisibility(messageDirection == MessageDirection.INCOMING && thread.isGroup() ? View.VISIBLE : View.GONE);
if (messageDirection == MessageDirection.INCOMING && thread.isGroup()) {
final DirectUser user = getUser(item.getUserId(), thread.getUsers());
final User user = getUser(item.getUserId(), thread.getUsers());
if (user != null) {
binding.tvUsername.setText(user.getUsername());
binding.ivProfilePic.setImageURI(user.getProfilePicUrl());
@ -152,7 +151,7 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder {
private void setReply(final DirectItem item,
final MessageDirection messageDirection,
final List<DirectUser> users) {
final List<User> users) {
final DirectItem replied = item.getRepliedToMessage();
final DirectItemType itemType = replied.getItemType();
String text = null;
@ -177,7 +176,7 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder {
text = "Voice message";
break;
case MEDIA_SHARE:
DirectItemMedia mediaShare = replied.getMediaShare();
Media mediaShare = replied.getMediaShare();
if (mediaShare.getMediaType() == MediaItemType.MEDIA_TYPE_SLIDER) {
mediaShare = mediaShare.getCarouselMedia().get(0);
}
@ -236,7 +235,7 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder {
private String setReplyInfo(final DirectItem item,
final DirectItem replied,
final List<DirectUser> users) {
final List<User> users) {
final long repliedToUserId = replied.getUserId();
if (repliedToUserId == item.getUserId() && item.getUserId() == currentUser.getPk()) {
// User replied to own message
@ -246,7 +245,7 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder {
// opposite user replied to their own message
return "Replied to themself";
}
final DirectUser user = getUser(repliedToUserId, users);
final User user = getUser(repliedToUserId, users);
final String repliedToUsername = user != null ? user.getUsername() : "";
if (item.getUserId() == currentUser.getPk()) {
return !thread.isGroup() ? "You replied" : String.format("You replied to %s", repliedToUsername);
@ -275,7 +274,7 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder {
replyInfoLayoutParams.endToStart = isIncoming ? ConstraintLayout.LayoutParams.UNSET : quoteLineId;
}
private void setReactions(final DirectItem item, final List<DirectUser> users) {
private void setReactions(final DirectItem item, final List<User> users) {
final DirectItemReactions reactions = item.getReactions();
final List<DirectItemEmojiReaction> emojis = reactions != null ? reactions.getEmojis() : null;
if (emojis == null || emojis.isEmpty()) {
@ -313,12 +312,12 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder {
public abstract void bindItem(final DirectItem directItemModel, final MessageDirection messageDirection);
@Nullable
protected DirectUser getUser(final long userId, final List<DirectUser> users) {
protected User getUser(final long userId, final List<User> users) {
if (userId == currentUser.getPk()) {
return currentUser;
}
if (users == null) return null;
for (final DirectUser user : users) {
for (final User user : users) {
if (userId != user.getPk()) continue;
return user;
}

View File

@ -20,10 +20,10 @@ import awais.instagrabber.R;
import awais.instagrabber.databinding.LayoutDmBaseBinding;
import awais.instagrabber.databinding.LayoutDmVoiceMediaBinding;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.repositories.responses.directmessages.Audio;
import awais.instagrabber.repositories.responses.Audio;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectItemMedia;
import awais.instagrabber.repositories.responses.directmessages.DirectItemVoiceMedia;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
import awais.instagrabber.utils.TextUtils;
@ -43,7 +43,7 @@ public class DirectItemVoiceMediaViewHolder extends DirectItemViewHolder {
public DirectItemVoiceMediaViewHolder(@NonNull final LayoutDmBaseBinding baseBinding,
@NonNull final LayoutDmVoiceMediaBinding binding,
final ProfileModel currentUser,
final User currentUser,
final DirectThread thread,
final MentionClickListener mentionClickListener,
final View.OnClickListener onClickListener) {
@ -59,7 +59,7 @@ public class DirectItemVoiceMediaViewHolder extends DirectItemViewHolder {
removeBg();
final DirectItemVoiceMedia voiceMedia = directItemModel.getVoiceMedia();
if (voiceMedia == null) return;
final DirectItemMedia media = voiceMedia.getMedia();
final Media media = voiceMedia.getMedia();
if (media == null) return;
final Audio audio = media.getAudio();
if (audio == null) return;

View File

@ -11,9 +11,11 @@ import androidx.recyclerview.widget.RecyclerView;
import awais.instagrabber.adapters.FeedAdapterV2;
import awais.instagrabber.databinding.ItemFeedBottomBinding;
import awais.instagrabber.databinding.ItemFeedTopBinding;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.repositories.responses.Caption;
import awais.instagrabber.repositories.responses.Location;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.utils.TextUtils;
import static android.text.TextUtils.TruncateAt.END;
@ -35,52 +37,60 @@ public abstract class FeedItemViewHolder extends RecyclerView.ViewHolder {
this.feedItemCallback = feedItemCallback;
}
public void bind(final FeedModel feedModel) {
if (feedModel == null) {
public void bind(final Media media) {
if (media == null) {
return;
}
setupProfilePic(feedModel);
setupLocation(feedModel);
bottomBinding.tvPostDate.setText(feedModel.getPostDate());
setupComments(feedModel);
setupCaption(feedModel);
if (feedModel.getItemType() != MediaItemType.MEDIA_TYPE_SLIDER) {
bottomBinding.btnDownload.setOnClickListener(v -> feedItemCallback.onDownloadClick(feedModel, -1));
setupProfilePic(media);
setupLocation(media);
bottomBinding.tvPostDate.setText(media.getDate());
setupComments(media);
setupCaption(media);
if (media.getMediaType() != MediaItemType.MEDIA_TYPE_SLIDER) {
bottomBinding.btnDownload.setOnClickListener(v -> feedItemCallback.onDownloadClick(media, -1));
}
bindItem(feedModel);
bindItem(media);
}
private void setupComments(final FeedModel feedModel) {
final long commentsCount = feedModel.getCommentsCount();
private void setupComments(@NonNull final Media feedModel) {
final long commentsCount = feedModel.getCommentCount();
bottomBinding.commentsCount.setText(String.valueOf(commentsCount));
bottomBinding.commentsCount.setOnClickListener(v -> feedItemCallback.onCommentsClick(feedModel));
}
private void setupProfilePic(final FeedModel feedModel) {
final ProfileModel profileModel = feedModel.getProfileModel();
if (profileModel != null) {
topBinding.ivProfilePic.setOnClickListener(v -> feedItemCallback.onProfilePicClick(feedModel, topBinding.ivProfilePic));
topBinding.ivProfilePic.setImageURI(profileModel.getSdProfilePic());
setupTitle(feedModel);
private void setupProfilePic(@NonNull final Media media) {
final User user = media.getUser();
if (user == null) {
topBinding.ivProfilePic.setVisibility(View.GONE);
topBinding.title.setVisibility(View.GONE);
return;
}
topBinding.ivProfilePic.setOnClickListener(v -> feedItemCallback.onProfilePicClick(media, topBinding.ivProfilePic));
topBinding.ivProfilePic.setImageURI(user.getProfilePicUrl());
setupTitle(media);
}
private void setupTitle(final FeedModel feedModel) {
private void setupTitle(@NonNull final Media media) {
// final int titleLen = profileModel.getUsername().length() + 1;
// final SpannableString spannableString = new SpannableString();
// spannableString.setSpan(new CommentMentionClickSpan(), 0, titleLen, 0);
final ProfileModel profileModel = feedModel.getProfileModel();
final String title = "@" + profileModel.getUsername();
final User user = media.getUser();
final String title = "@" + user.getUsername();
topBinding.title.setText(title);
topBinding.title.setOnClickListener(v -> feedItemCallback.onNameClick(feedModel, topBinding.ivProfilePic));
topBinding.title.setOnClickListener(v -> feedItemCallback.onNameClick(media, topBinding.ivProfilePic));
}
private void setupCaption(final FeedModel feedModel) {
private void setupCaption(final Media media) {
bottomBinding.viewerCaption.clearOnMentionClickListeners();
bottomBinding.viewerCaption.clearOnHashtagClickListeners();
bottomBinding.viewerCaption.clearOnURLClickListeners();
bottomBinding.viewerCaption.clearOnEmailClickListeners();
final CharSequence postCaption = feedModel.getPostCaption();
final Caption caption = media.getCaption();
if (caption == null) {
bottomBinding.viewerCaption.setVisibility(View.GONE);
return;
}
final CharSequence postCaption = caption.getText();
final boolean captionEmpty = TextUtils.isEmpty(postCaption);
bottomBinding.viewerCaption.setVisibility(captionEmpty ? View.GONE : View.VISIBLE);
if (captionEmpty) return;
@ -103,8 +113,9 @@ public abstract class FeedItemViewHolder extends RecyclerView.ViewHolder {
bottomBinding.viewerCaption.addOnURLClickListener(autoLinkItem -> feedItemCallback.onURLClick(autoLinkItem.getOriginalText()));
}
private void setupLocation(final FeedModel feedModel) {
final String locationName = feedModel.getLocationName();
private void setupLocation(@NonNull final Media media) {
final Location location = media.getLocation();
final String locationName = location.getName();
if (TextUtils.isEmpty(locationName)) {
topBinding.location.setVisibility(View.GONE);
topBinding.title.setLayoutParams(new RelativeLayout.LayoutParams(
@ -116,9 +127,9 @@ public abstract class FeedItemViewHolder extends RecyclerView.ViewHolder {
topBinding.title.setLayoutParams(new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT
));
topBinding.location.setOnClickListener(v -> feedItemCallback.onLocationClick(feedModel));
topBinding.location.setOnClickListener(v -> feedItemCallback.onLocationClick(media));
}
}
public abstract void bindItem(final FeedModel feedModel);
public abstract void bindItem(final Media media);
}

View File

@ -16,7 +16,8 @@ import com.facebook.imagepipeline.request.ImageRequestBuilder;
import awais.instagrabber.adapters.FeedAdapterV2;
import awais.instagrabber.databinding.ItemFeedPhotoBinding;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.utils.ResponseBodyUtils;
import awais.instagrabber.utils.TextUtils;
public class FeedPhotoViewHolder extends FeedItemViewHolder {
@ -40,14 +41,12 @@ public class FeedPhotoViewHolder extends FeedItemViewHolder {
}
@Override
public void bindItem(final FeedModel feedModel) {
if (feedModel == null) {
return;
}
public void bindItem(final Media media) {
if (media == null) return;
binding.getRoot().post(() -> {
setDimensions(feedModel);
final String thumbnailUrl = feedModel.getThumbnailUrl();
String url = feedModel.getDisplayUrl();
setDimensions(media);
final String thumbnailUrl = ResponseBodyUtils.getThumbUrl(media);
String url = ResponseBodyUtils.getImageUrl(media);
if (TextUtils.isEmpty(url)) url = thumbnailUrl;
final ImageRequest requestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url))
// .setLocalThumbnailPreviewsEnabled(true)
@ -62,7 +61,7 @@ public class FeedPhotoViewHolder extends FeedItemViewHolder {
@Override
public boolean onSingleTapConfirmed(final MotionEvent e) {
if (feedItemCallback != null) {
feedItemCallback.onPostClick(feedModel, binding.itemFeedTop.ivProfilePic, binding.imageViewer);
feedItemCallback.onPostClick(media, binding.itemFeedTop.ivProfilePic, binding.imageViewer);
return true;
}
return false;
@ -71,8 +70,8 @@ public class FeedPhotoViewHolder extends FeedItemViewHolder {
});
}
private void setDimensions(final FeedModel feedModel) {
final float aspectRatio = (float) feedModel.getImageWidth() / feedModel.getImageHeight();
private void setDimensions(final Media feedModel) {
final float aspectRatio = (float) feedModel.getOriginalWidth() / feedModel.getOriginalHeight();
binding.imageViewer.setAspectRatio(aspectRatio);
}
}

View File

@ -13,8 +13,7 @@ import awais.instagrabber.adapters.FeedAdapterV2;
import awais.instagrabber.adapters.SliderCallbackAdapter;
import awais.instagrabber.adapters.SliderItemsAdapter;
import awais.instagrabber.databinding.ItemFeedSliderBinding;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.models.PostChild;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.utils.NumberUtils;
import awais.instagrabber.utils.Utils;
@ -39,8 +38,8 @@ public class FeedSliderViewHolder extends FeedItemViewHolder {
}
@Override
public void bindItem(final FeedModel feedModel) {
final List<PostChild> sliderItems = feedModel.getSliderItems();
public void bindItem(final Media feedModel) {
final List<Media> sliderItems = feedModel.getCarouselMedia();
final int sliderItemLen = sliderItems != null ? sliderItems.size() : 0;
if (sliderItemLen <= 0) return;
final String text = "1/" + sliderItemLen;
@ -68,7 +67,7 @@ public class FeedSliderViewHolder extends FeedItemViewHolder {
adapter.submitList(sliderItems);
}
private void setDimensions(final View view, final PostChild model) {
private void setDimensions(final View view, final Media model) {
final ViewGroup.LayoutParams layoutParams = binding.mediaList.getLayoutParams();
int requiredWidth = layoutParams.width;
if (requiredWidth <= 0) {
@ -86,10 +85,10 @@ public class FeedSliderViewHolder extends FeedItemViewHolder {
setLayoutParamDimens(binding.mediaList, model);
}
private void setLayoutParamDimens(final View view, final PostChild model) {
private void setLayoutParamDimens(final View view, final Media model) {
final int requiredWidth = view.getMeasuredWidth();
final ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
final int spanHeight = NumberUtils.getResultingHeight(requiredWidth, model.getHeight(), model.getWidth());
final int spanHeight = NumberUtils.getResultingHeight(requiredWidth, model.getOriginalHeight(), model.getOriginalWidth());
layoutParams.height = spanHeight == 0 ? requiredWidth + 1 : spanHeight;
view.requestLayout();
}

View File

@ -12,13 +12,17 @@ import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory;
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
import java.util.List;
import awais.instagrabber.adapters.FeedAdapterV2;
import awais.instagrabber.customviews.VideoPlayerCallbackAdapter;
import awais.instagrabber.customviews.VideoPlayerViewHelper;
import awais.instagrabber.databinding.ItemFeedVideoBinding;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.VideoVersion;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.NumberUtils;
import awais.instagrabber.utils.ResponseBodyUtils;
import awais.instagrabber.utils.Utils;
import static awais.instagrabber.utils.Utils.settingsHelper;
@ -32,7 +36,7 @@ public class FeedVideoViewHolder extends FeedItemViewHolder {
private final DefaultDataSourceFactory dataSourceFactory;
private CacheDataSourceFactory cacheDataSourceFactory;
private FeedModel feedModel;
private Media media;
// private final Runnable loadRunnable = new Runnable() {
// @Override
@ -57,40 +61,46 @@ public class FeedVideoViewHolder extends FeedItemViewHolder {
}
@Override
public void bindItem(final FeedModel feedModel) {
public void bindItem(final Media media) {
// Log.d(TAG, "Binding post: " + feedModel.getPostId());
this.feedModel = feedModel;
binding.itemFeedBottom.tvVideoViews.setText(String.valueOf(feedModel.getViewCount()));
this.media = media;
binding.itemFeedBottom.tvVideoViews.setText(String.valueOf(media.getViewCount()));
final float vol = settingsHelper.getBoolean(Constants.MUTED_VIDEOS) ? 0f : 1f;
final VideoPlayerViewHelper.VideoPlayerCallback videoPlayerCallback = new VideoPlayerCallbackAdapter() {
@Override
public void onThumbnailClick() {
feedItemCallback.onPostClick(feedModel, binding.itemFeedTop.ivProfilePic, binding.videoPost.thumbnail);
feedItemCallback.onPostClick(media, binding.itemFeedTop.ivProfilePic, binding.videoPost.thumbnail);
}
@Override
public void onPlayerViewLoaded() {
final ViewGroup.LayoutParams layoutParams = binding.videoPost.playerView.getLayoutParams();
final int requiredWidth = Utils.displayMetrics.widthPixels;
final int resultingHeight = NumberUtils.getResultingHeight(requiredWidth, feedModel.getImageHeight(), feedModel.getImageWidth());
final int resultingHeight = NumberUtils.getResultingHeight(requiredWidth, media.getOriginalHeight(), media.getOriginalWidth());
layoutParams.width = requiredWidth;
layoutParams.height = resultingHeight;
binding.videoPost.playerView.requestLayout();
}
};
final float aspectRatio = (float) feedModel.getImageWidth() / feedModel.getImageHeight();
final float aspectRatio = (float) media.getOriginalWidth() / media.getOriginalHeight();
String videoUrl = null;
final List<VideoVersion> videoVersions = media.getVideoVersions();
if (videoVersions != null && !videoVersions.isEmpty()) {
final VideoVersion videoVersion = videoVersions.get(0);
videoUrl = videoVersion.getUrl();
}
final VideoPlayerViewHelper videoPlayerViewHelper = new VideoPlayerViewHelper(binding.getRoot().getContext(),
binding.videoPost,
feedModel.getDisplayUrl(),
videoUrl,
vol,
aspectRatio,
feedModel.getThumbnailUrl(),
ResponseBodyUtils.getThumbUrl(media),
false,
null,
videoPlayerCallback);
binding.videoPost.thumbnail.post(() -> {
if (feedModel.getImageHeight() > 0.8 * Utils.displayMetrics.heightPixels) {
if (media.getOriginalHeight() > 0.8 * Utils.displayMetrics.heightPixels) {
final ViewGroup.LayoutParams layoutParams = binding.videoPost.thumbnail.getLayoutParams();
layoutParams.height = (int) (0.8 * Utils.displayMetrics.heightPixels);
binding.videoPost.thumbnail.requestLayout();
@ -98,8 +108,8 @@ public class FeedVideoViewHolder extends FeedItemViewHolder {
});
}
public FeedModel getCurrentFeedModel() {
return feedModel;
public Media getCurrentFeedModel() {
return media;
}
// public void stopPlaying() {

View File

@ -17,7 +17,8 @@ import java.util.List;
import awais.instagrabber.BuildConfig;
import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.CommentModel;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.repositories.responses.FriendshipStatus;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.NetworkUtils;
import awais.instagrabber.utils.TextUtils;
@ -106,33 +107,22 @@ public final class CommentsFetcher extends AsyncTask<Void, Void, List<CommentMod
if (childComment != null) {
final JSONObject owner = childComment.getJSONObject("owner");
final ProfileModel profileModel = new ProfileModel(false,
false,
false,
owner.getString(Constants.EXTRAS_ID),
owner.getString(Constants.EXTRAS_USERNAME),
null,
null,
null,
owner.getString("profile_pic_url"),
null,
0,
0,
0,
false,
false,
false,
false,
false);
final User user = new User(
owner.optLong(Constants.EXTRAS_ID, 0),
owner.getString(Constants.EXTRAS_USERNAME),
null,
false,
owner.getString("profile_pic_url"),
null,
new FriendshipStatus(false, false, false, false, false, false, false, false, false, false),
false, false, false, false, false, null, null, 0, 0, 0, 0, null, null, 0, null);
final JSONObject likedBy = childComment.optJSONObject("edge_liked_by");
commentModels.add(new CommentModel(childComment.getString(Constants.EXTRAS_ID),
childComment.getString("text"),
childComment.getLong("created_at"),
likedBy != null ? likedBy.optLong("count", 0) : 0,
childComment.getBoolean("viewer_has_liked"),
profileModel));
user));
}
}
}
@ -156,138 +146,121 @@ public final class CommentsFetcher extends AsyncTask<Void, Void, List<CommentMod
@NonNull
private synchronized List<CommentModel> getParentComments() {
final List<CommentModel> commentModels = new ArrayList<>();
final String url = "https://www.instagram.com/graphql/query/?query_hash=bc3296d1ce80a24b1b6e40b1e72903f5&variables=" +
"{\"shortcode\":\"" + shortCode + "\",\"first\":50,\"after\":\"" + endCursor.replace("\"", "\\\"") + "\"}";
final String url = "https://www.instagram.com/graphql/query/?query_hash=bc3296d1ce80a24b1b6e40b1e72903f5&variables=" +
"{\"shortcode\":\"" + shortCode + "\",\"first\":50,\"after\":\"" + endCursor.replace("\"", "\\\"") + "\"}";
try {
final HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
conn.setUseCaches(false);
conn.connect();
final HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
conn.setUseCaches(false);
conn.connect();
if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) return null;
else {
final JSONObject parentComments = new JSONObject(NetworkUtils.readFromConnection(conn)).getJSONObject("data")
.getJSONObject("shortcode_media")
.getJSONObject(
"edge_media_to_parent_comment");
if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) return null;
else {
final JSONObject parentComments = new JSONObject(NetworkUtils.readFromConnection(conn)).getJSONObject("data")
.getJSONObject("shortcode_media")
.getJSONObject(
"edge_media_to_parent_comment");
final JSONObject pageInfo = parentComments.getJSONObject("page_info");
final String foundEndCursor = pageInfo.optString("end_cursor");
final boolean hasNextPage = pageInfo.optBoolean("has_next_page", !TextUtils.isEmpty(foundEndCursor));
final JSONObject pageInfo = parentComments.getJSONObject("page_info");
final String foundEndCursor = pageInfo.optString("end_cursor");
final boolean hasNextPage = pageInfo.optBoolean("has_next_page", !TextUtils.isEmpty(foundEndCursor));
// final boolean containsToken = endCursor.contains("bifilter_token");
// if (!Utils.isEmpty(endCursor) && (containsToken || endCursor.contains("cached_comments_cursor"))) {
// final JSONObject endCursorObject = new JSONObject(endCursor);
// endCursor = endCursorObject.optString("cached_comments_cursor");
//
// if (!Utils.isEmpty(endCursor))
// endCursor = "{\\\"cached_comments_cursor\\\": \\\"" + endCursor + "\\\", ";
// else
// endCursor = "{";
//
// endCursor = endCursor + "\\\"bifilter_token\\\": \\\"" + endCursorObject.getString("bifilter_token") + "\\\"}";
// }
// else if (containsToken) endCursor = null;
// final boolean containsToken = endCursor.contains("bifilter_token");
// if (!Utils.isEmpty(endCursor) && (containsToken || endCursor.contains("cached_comments_cursor"))) {
// final JSONObject endCursorObject = new JSONObject(endCursor);
// endCursor = endCursorObject.optString("cached_comments_cursor");
//
// if (!Utils.isEmpty(endCursor))
// endCursor = "{\\\"cached_comments_cursor\\\": \\\"" + endCursor + "\\\", ";
// else
// endCursor = "{";
//
// endCursor = endCursor + "\\\"bifilter_token\\\": \\\"" + endCursorObject.getString("bifilter_token") + "\\\"}";
// }
// else if (containsToken) endCursor = null;
final JSONArray comments = parentComments.getJSONArray("edges");
final int commentsLen = comments.length();
for (int i = 0; i < commentsLen; ++i) {
final JSONObject comment = comments.getJSONObject(i).getJSONObject("node");
final JSONArray comments = parentComments.getJSONArray("edges");
final int commentsLen = comments.length();
for (int i = 0; i < commentsLen; ++i) {
final JSONObject comment = comments.getJSONObject(i).getJSONObject("node");
final JSONObject owner = comment.getJSONObject("owner");
final ProfileModel profileModel = new ProfileModel(false,
false,
owner.optBoolean("is_verified"),
owner.getString(Constants.EXTRAS_ID),
owner.getString(Constants.EXTRAS_USERNAME),
null,
null,
null,
owner.getString("profile_pic_url"),
null,
0,
0,
0,
false,
false,
false,
false,
false);
final JSONObject owner = comment.getJSONObject("owner");
final User user = new User(
owner.optLong(Constants.EXTRAS_ID, 0),
owner.getString(Constants.EXTRAS_USERNAME),
null,
false,
owner.getString("profile_pic_url"),
null,
new FriendshipStatus(false, false, false, false, false, false, false, false, false, false),
owner.optBoolean("is_verified"),
false, false, false, false, null, null, 0, 0, 0, 0, null, null, 0, null);
final JSONObject likedBy = comment.optJSONObject("edge_liked_by");
final String commentId = comment.getString(Constants.EXTRAS_ID);
final CommentModel commentModel = new CommentModel(commentId,
comment.getString("text"),
comment.getLong("created_at"),
likedBy != null ? likedBy.optLong("count", 0) : 0,
comment.getBoolean("viewer_has_liked"),
user);
if (i == 0 && !foundEndCursor.contains("tao_cursor"))
commentModel.setPageCursor(hasNextPage, TextUtils.isEmpty(foundEndCursor) ? null : foundEndCursor);
JSONObject tempJsonObject;
final JSONArray childCommentsArray;
final int childCommentsLen;
if ((tempJsonObject = comment.optJSONObject("edge_threaded_comments")) != null &&
(childCommentsArray = tempJsonObject.optJSONArray("edges")) != null
&& (childCommentsLen = childCommentsArray.length()) > 0) {
final JSONObject likedBy = comment.optJSONObject("edge_liked_by");
final String commentId = comment.getString(Constants.EXTRAS_ID);
final CommentModel commentModel = new CommentModel(commentId,
comment.getString("text"),
comment.getLong("created_at"),
likedBy != null ? likedBy.optLong("count", 0) : 0,
comment.getBoolean("viewer_has_liked"),
profileModel);
if (i == 0 && !foundEndCursor.contains("tao_cursor"))
commentModel.setPageCursor(hasNextPage, TextUtils.isEmpty(foundEndCursor) ? null : foundEndCursor);
JSONObject tempJsonObject;
final JSONArray childCommentsArray;
final int childCommentsLen;
if ((tempJsonObject = comment.optJSONObject("edge_threaded_comments")) != null &&
(childCommentsArray = tempJsonObject.optJSONArray("edges")) != null
&& (childCommentsLen = childCommentsArray.length()) > 0) {
final String childEndCursor;
final boolean childHasNextPage;
if ((tempJsonObject = tempJsonObject.optJSONObject("page_info")) != null) {
childEndCursor = tempJsonObject.optString("end_cursor");
childHasNextPage = tempJsonObject.optBoolean("has_next_page", !TextUtils.isEmpty(childEndCursor));
} else {
childEndCursor = null;
childHasNextPage = false;
}
final List<CommentModel> childCommentModels = new ArrayList<>();
for (int j = 0; j < childCommentsLen; ++j) {
final JSONObject childComment = childCommentsArray.getJSONObject(j).getJSONObject("node");
tempJsonObject = childComment.getJSONObject("owner");
final ProfileModel childProfileModel = new ProfileModel(false,
false,
tempJsonObject.optBoolean("is_verified"),
tempJsonObject.getString(Constants.EXTRAS_ID),
tempJsonObject.getString(Constants.EXTRAS_USERNAME),
null,
null,
null,
tempJsonObject.getString("profile_pic_url"),
null,
0,
0,
0,
false,
false,
false,
false,
false);
tempJsonObject = childComment.optJSONObject("edge_liked_by");
childCommentModels.add(new CommentModel(childComment.getString(Constants.EXTRAS_ID),
childComment.getString("text"),
childComment.getLong("created_at"),
tempJsonObject != null ? tempJsonObject.optLong("count", 0) : 0,
childComment.getBoolean("viewer_has_liked"),
childProfileModel));
}
childCommentModels.get(childCommentsLen - 1).setPageCursor(childHasNextPage, childEndCursor);
commentModel.setChildCommentModels(childCommentModels);
final String childEndCursor;
final boolean childHasNextPage;
if ((tempJsonObject = tempJsonObject.optJSONObject("page_info")) != null) {
childEndCursor = tempJsonObject.optString("end_cursor");
childHasNextPage = tempJsonObject.optBoolean("has_next_page", !TextUtils.isEmpty(childEndCursor));
} else {
childEndCursor = null;
childHasNextPage = false;
}
commentModels.add(commentModel);
}
}
conn.disconnect();
} catch (final Exception e) {
if (logCollector != null)
logCollector.appendException(e, LogCollector.LogFile.ASYNC_COMMENTS_FETCHER, "getParentComments",
new Pair<>("commentModelsList.size", commentModels.size()));
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e);
if (fetchListener != null) fetchListener.onFailure(e);
return null;
final List<CommentModel> childCommentModels = new ArrayList<>();
for (int j = 0; j < childCommentsLen; ++j) {
final JSONObject childComment = childCommentsArray.getJSONObject(j).getJSONObject("node");
tempJsonObject = childComment.getJSONObject("owner");
final User childUser = new User(
tempJsonObject.optLong(Constants.EXTRAS_ID, 0),
tempJsonObject.getString(Constants.EXTRAS_USERNAME),
null,
false,
tempJsonObject.getString("profile_pic_url"),
null,
new FriendshipStatus(false, false, false, false, false, false, false, false, false, false),
tempJsonObject.optBoolean("is_verified"), false, false, false, false, null, null, 0, 0, 0, 0, null, null, 0,
null);
tempJsonObject = childComment.optJSONObject("edge_liked_by");
childCommentModels.add(new CommentModel(childComment.getString(Constants.EXTRAS_ID),
childComment.getString("text"),
childComment.getLong("created_at"),
tempJsonObject != null ? tempJsonObject.optLong("count", 0) : 0,
childComment.getBoolean("viewer_has_liked"),
childUser));
}
childCommentModels.get(childCommentsLen - 1).setPageCursor(childHasNextPage, childEndCursor);
commentModel.setChildCommentModels(childCommentModels);
}
commentModels.add(commentModel);
}
}
conn.disconnect();
} catch (final Exception e) {
if (logCollector != null)
logCollector.appendException(e, LogCollector.LogFile.ASYNC_COMMENTS_FETCHER, "getParentComments",
new Pair<>("commentModelsList.size", commentModels.size()));
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e);
if (fetchListener != null) fetchListener.onFailure(e);
return null;
}
return commentModels;
}
}

View File

@ -1,10 +1,15 @@
package awais.instagrabber.asyncs;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import awais.instagrabber.customviews.helpers.PostFetcher;
import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.discover.TopicalExploreFeedResponse;
import awais.instagrabber.repositories.responses.discover.TopicalExploreItem;
import awais.instagrabber.webservices.DiscoverService;
import awais.instagrabber.webservices.ServiceCallback;
@ -20,18 +25,28 @@ public class DiscoverPostFetchService implements PostFetcher.PostFetchService {
}
@Override
public void fetch(final FetchListener<List<FeedModel>> fetchListener) {
discoverService.topicalExplore(topicalExploreRequest, new ServiceCallback<DiscoverService.TopicalExploreResponse>() {
public void fetch(final FetchListener<List<Media>> fetchListener) {
discoverService.topicalExplore(topicalExploreRequest, new ServiceCallback<TopicalExploreFeedResponse>() {
@Override
public void onSuccess(final DiscoverService.TopicalExploreResponse result) {
public void onSuccess(final TopicalExploreFeedResponse result) {
if (result == null) {
onFailure(new RuntimeException("result is null"));
return;
}
moreAvailable = result.isMoreAvailable();
topicalExploreRequest.setMaxId(result.getNextMaxId());
final List<TopicalExploreItem> items = result.getItems();
final List<Media> posts;
if (items == null) {
posts = Collections.emptyList();
} else {
posts = items.stream()
.map(TopicalExploreItem::getMedia)
.filter(Objects::nonNull)
.collect(Collectors.toList());
}
if (fetchListener != null) {
fetchListener.onResult(result.getItems());
fetchListener.onResult(posts);
}
}
@ -46,7 +61,7 @@ public class DiscoverPostFetchService implements PostFetcher.PostFetchService {
@Override
public void reset() {
topicalExploreRequest.setMaxId(-1);
topicalExploreRequest.setMaxId(null);
}
@Override

View File

@ -6,10 +6,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.utils.DownloadUtils;
public final class DownloadedCheckerAsyncTask extends AsyncTask<FeedModel, Void, Map<String, List<Boolean>>> {
public final class DownloadedCheckerAsyncTask extends AsyncTask<Media, Void, Map<String, List<Boolean>>> {
private static final String TAG = "DownloadedCheckerAsyncTask";
private final OnCheckResultListener listener;
@ -19,13 +19,13 @@ public final class DownloadedCheckerAsyncTask extends AsyncTask<FeedModel, Void,
}
@Override
protected Map<String, List<Boolean>> doInBackground(final FeedModel... feedModels) {
protected Map<String, List<Boolean>> doInBackground(final Media... feedModels) {
if (feedModels == null) {
return null;
}
final Map<String, List<Boolean>> map = new HashMap<>();
for (final FeedModel feedModel : feedModels) {
map.put(feedModel.getPostId(), DownloadUtils.checkDownloaded(feedModel));
for (final Media media : feedModels) {
map.put(media.getPk(), DownloadUtils.checkDownloaded(media));
}
return map;
}

View File

@ -1,14 +1,11 @@
package awais.instagrabber.asyncs;
//import android.os.Handler;
//import android.util.Log;
import java.util.ArrayList;
import java.util.List;
import awais.instagrabber.customviews.helpers.PostFetcher;
import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.PostsFetchResponse;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils;
@ -21,18 +18,15 @@ public class FeedPostFetchService implements PostFetcher.PostFetchService {
private static final String TAG = "FeedPostFetchService";
private final FeedService feedService;
private String nextCursor;
// private final Handler handler;
private boolean hasNextPage;
// private static final int DELAY_MILLIS = 500;
public FeedPostFetchService() {
feedService = FeedService.getInstance();
// handler = new Handler();
}
@Override
public void fetch(final FetchListener<List<FeedModel>> fetchListener) {
final List<FeedModel> feedModels = new ArrayList<>();
public void fetch(final FetchListener<List<Media>> fetchListener) {
final List<Media> feedModels = new ArrayList<>();
final String cookie = settingsHelper.getString(Constants.COOKIE);
final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
feedModels.clear();
@ -42,18 +36,14 @@ public class FeedPostFetchService implements PostFetcher.PostFetchService {
if (result == null && feedModels.size() > 0) {
fetchListener.onResult(feedModels);
return;
}
else if (result == null) return;
} else if (result == null) return;
nextCursor = result.getNextCursor();
hasNextPage = result.hasNextPage();
feedModels.addAll(result.getFeedModels());
if (fetchListener != null) {
if (feedModels.size() < 15 && hasNextPage) {
// handler.postDelayed(() -> {
feedService.fetch(csrfToken, nextCursor, this);
// }, DELAY_MILLIS);
}
else {
feedService.fetch(csrfToken, nextCursor, this);
} else {
fetchListener.onResult(feedModels);
}
}
@ -61,7 +51,6 @@ public class FeedPostFetchService implements PostFetcher.PostFetchService {
@Override
public void onFailure(final Throwable t) {
// Log.e(TAG, "onFailure: ", t);
if (fetchListener != null) {
fetchListener.onFailure(t);
}

View File

@ -3,6 +3,8 @@ package awais.instagrabber.asyncs;
import android.os.AsyncTask;
import android.util.Log;
import androidx.annotation.NonNull;
import org.json.JSONObject;
import java.net.HttpURLConnection;
@ -35,7 +37,7 @@ public class GetActivityAsyncTask extends AsyncTask<String, Void, GetActivityAsy
if (cookiesArray == null) return null;
final String cookie = cookiesArray[0];
if (TextUtils.isEmpty(cookie)) return null;
final String uid = CookieUtils.getUserIdFromCookie(cookie);
final long uid = CookieUtils.getUserIdFromCookie(cookie);
final String url = "https://www.instagram.com/graphql/query/?query_hash=0f318e8cfff9cc9ef09f88479ff571fb"
+ "&variables={\"id\":\"" + uid + "\"}";
HttpURLConnection urlConnection = null;
@ -117,6 +119,7 @@ public class GetActivityAsyncTask extends AsyncTask<String, Void, GetActivityAsy
return likesCount;
}
@NonNull
@Override
public String toString() {
return "NotificationCounts{" +

View File

@ -4,8 +4,8 @@ import java.util.List;
import awais.instagrabber.customviews.helpers.PostFetcher;
import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.models.HashtagModel;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.PostsFetchResponse;
import awais.instagrabber.webservices.GraphQLService;
import awais.instagrabber.webservices.ServiceCallback;
@ -27,8 +27,8 @@ public class HashtagPostFetchService implements PostFetcher.PostFetchService {
}
@Override
public void fetch(final FetchListener<List<FeedModel>> fetchListener) {
final ServiceCallback cb = new ServiceCallback<PostsFetchResponse>() {
public void fetch(final FetchListener<List<Media>> fetchListener) {
final ServiceCallback<PostsFetchResponse> cb = new ServiceCallback<PostsFetchResponse>() {
@Override
public void onSuccess(final PostsFetchResponse result) {
if (result == null) return;

View File

@ -24,9 +24,9 @@ public final class LocationFetcher extends AsyncTask<Void, Void, LocationModel>
private static final String TAG = "LocationFetcher";
private final FetchListener<LocationModel> fetchListener;
private final String id;
private final long id;
public LocationFetcher(final String id, final FetchListener<LocationModel> fetchListener) {
public LocationFetcher(final long id, final FetchListener<LocationModel> fetchListener) {
// idSlug = id + "/" + slug UPDATE: slug can be ignored tbh
this.id = id;
this.fetchListener = fetchListener;

View File

@ -4,8 +4,8 @@ import java.util.List;
import awais.instagrabber.customviews.helpers.PostFetcher;
import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.models.LocationModel;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.PostsFetchResponse;
import awais.instagrabber.webservices.GraphQLService;
import awais.instagrabber.webservices.LocationService;
@ -27,8 +27,8 @@ public class LocationPostFetchService implements PostFetcher.PostFetchService {
}
@Override
public void fetch(final FetchListener<List<FeedModel>> fetchListener) {
final ServiceCallback cb = new ServiceCallback<PostsFetchResponse>() {
public void fetch(final FetchListener<List<Media>> fetchListener) {
final ServiceCallback<PostsFetchResponse> cb = new ServiceCallback<PostsFetchResponse>() {
@Override
public void onSuccess(final PostsFetchResponse result) {
if (result == null) return;

View File

@ -3,40 +3,32 @@ package awais.instagrabber.asyncs;
import android.os.AsyncTask;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONObject;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.models.PostChild;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.utils.NetworkUtils;
import awais.instagrabber.utils.ResponseBodyUtils;
import awais.instagrabber.utils.TextUtils;
import awaisomereport.LogCollector;
import static awais.instagrabber.utils.Utils.logCollector;
public final class PostFetcher extends AsyncTask<Void, Void, FeedModel> {
public final class PostFetcher extends AsyncTask<Void, Void, Media> {
private static final String TAG = "PostFetcher";
private final String shortCode;
private final FetchListener<FeedModel> fetchListener;
private final FetchListener<Media> fetchListener;
public PostFetcher(final String shortCode, final FetchListener<FeedModel> fetchListener) {
public PostFetcher(final String shortCode, final FetchListener<Media> fetchListener) {
this.shortCode = shortCode;
this.fetchListener = fetchListener;
}
@Override
protected FeedModel doInBackground(final Void... voids) {
protected Media doInBackground(final Void... voids) {
HttpURLConnection conn = null;
try {
conn = (HttpURLConnection) new URL("https://www.instagram.com/p/" + shortCode + "/?__a=1").openConnection();
@ -47,100 +39,101 @@ public final class PostFetcher extends AsyncTask<Void, Void, FeedModel> {
final JSONObject media = new JSONObject(NetworkUtils.readFromConnection(conn)).getJSONObject("graphql")
.getJSONObject("shortcode_media");
ProfileModel profileModel = null;
if (media.has("owner")) {
final JSONObject owner = media.getJSONObject("owner");
profileModel = new ProfileModel(
owner.optBoolean("is_private"),
owner.optBoolean("is_private"),
owner.optBoolean("is_verified"),
owner.optString("id"),
owner.optString("username"),
owner.optString("full_name"),
null,
null,
owner.optString("profile_pic_url"),
owner.optString("profile_pic_url"),
owner.optInt("edge_owner_to_timeline_media"),
owner.optInt("edge_followed_by"),
-1,
owner.optBoolean("followed_by_viewer"),
false,
owner.optBoolean("restricted_by_viewer"),
owner.optBoolean("blocked_by_viewer"),
owner.optBoolean("requested_by_viewer")
);
}
final long timestamp = media.getLong("taken_at_timestamp");
final boolean isVideo = media.has("is_video") && media.optBoolean("is_video");
final boolean isSlider = media.has("edge_sidecar_to_children");
final MediaItemType mediaItemType;
if (isSlider) mediaItemType = MediaItemType.MEDIA_TYPE_SLIDER;
else if (isVideo) mediaItemType = MediaItemType.MEDIA_TYPE_VIDEO;
else mediaItemType = MediaItemType.MEDIA_TYPE_IMAGE;
final String postCaption;
final JSONObject mediaToCaption = media.optJSONObject("edge_media_to_caption");
if (mediaToCaption == null) postCaption = null;
else {
final JSONArray captions = mediaToCaption.optJSONArray("edges");
postCaption = captions != null && captions.length() > 0 ?
captions.getJSONObject(0).getJSONObject("node").optString("text") : null;
}
JSONObject commentObject = media.optJSONObject("edge_media_to_parent_comment");
final long commentsCount = commentObject != null ? commentObject.optLong("count") : 0;
final FeedModel.Builder feedModelBuilder = new FeedModel.Builder()
.setItemType(mediaItemType)
.setPostId(media.getString(Constants.EXTRAS_ID))
.setDisplayUrl(isVideo ? media.getString("video_url")
: ResponseBodyUtils.getHighQualityImage(media))
.setThumbnailUrl(media.getString("display_url"))
.setImageHeight(media.getJSONObject("dimensions").getInt("height"))
.setImageWidth(media.getJSONObject("dimensions").getInt("width"))
.setShortCode(shortCode)
.setPostCaption(TextUtils.isEmpty(postCaption) ? null : postCaption)
.setProfileModel(profileModel)
.setViewCount(isVideo && media.has("video_view_count")
? media.getLong("video_view_count")
: -1)
.setTimestamp(timestamp)
.setLiked(media.getBoolean("viewer_has_liked"))
.setBookmarked(media.getBoolean("viewer_has_saved"))
.setLikesCount(media.getJSONObject("edge_media_preview_like")
.getLong("count"))
.setLocationName(media.isNull("location")
? null
: media.getJSONObject("location").optString("name"))
.setLocationId(media.isNull("location")
? null
: media.getJSONObject("location").optString("id"))
.setCommentsCount(commentsCount);
if (isSlider) {
final JSONArray children = media.getJSONObject("edge_sidecar_to_children").getJSONArray("edges");
final List<PostChild> postModels = new ArrayList<>();
for (int i = 0; i < children.length(); ++i) {
final JSONObject childNode = children.getJSONObject(i).getJSONObject("node");
final boolean isChildVideo = childNode.getBoolean("is_video");
postModels.add(new PostChild.Builder()
.setItemType(isChildVideo ? MediaItemType.MEDIA_TYPE_VIDEO
: MediaItemType.MEDIA_TYPE_IMAGE)
.setDisplayUrl(isChildVideo ? childNode.getString("video_url")
: childNode.getString("display_url"))
.setShortCode(media.getString(Constants.EXTRAS_SHORTCODE))
.setVideoViews(isChildVideo && childNode.has("video_view_count")
? childNode.getLong("video_view_count")
: -1)
.setThumbnailUrl(childNode.getString("display_url"))
.setHeight(childNode.getJSONObject("dimensions").getInt("height"))
.setWidth(childNode.getJSONObject("dimensions").getInt("width"))
.build());
}
feedModelBuilder.setSliderItems(postModels);
}
return feedModelBuilder.build();
// ProfileModel profileModel = null;
// if (media.has("owner")) {
// final JSONObject owner = media.getJSONObject("owner");
// profileModel = new ProfileModel(
// owner.optBoolean("is_private"),
// owner.optBoolean("is_private"),
// owner.optBoolean("is_verified"),
// owner.optString("id"),
// owner.optString("username"),
// owner.optString("full_name"),
// null,
// null,
// owner.optString("profile_pic_url"),
// owner.optString("profile_pic_url"),
// owner.optInt("edge_owner_to_timeline_media"),
// owner.optInt("edge_followed_by"),
// -1,
// owner.optBoolean("followed_by_viewer"),
// false,
// owner.optBoolean("restricted_by_viewer"),
// owner.optBoolean("blocked_by_viewer"),
// owner.optBoolean("requested_by_viewer")
// );
// }
// final long timestamp = media.getLong("taken_at_timestamp");
//
// final boolean isVideo = media.has("is_video") && media.optBoolean("is_video");
// final boolean isSlider = media.has("edge_sidecar_to_children");
//
// final MediaItemType mediaItemType;
// if (isSlider) mediaItemType = MediaItemType.MEDIA_TYPE_SLIDER;
// else if (isVideo) mediaItemType = MediaItemType.MEDIA_TYPE_VIDEO;
// else mediaItemType = MediaItemType.MEDIA_TYPE_IMAGE;
//
// final String postCaption;
// final JSONObject mediaToCaption = media.optJSONObject("edge_media_to_caption");
// if (mediaToCaption == null) postCaption = null;
// else {
// final JSONArray captions = mediaToCaption.optJSONArray("edges");
// postCaption = captions != null && captions.length() > 0 ?
// captions.getJSONObject(0).getJSONObject("node").optString("text") : null;
// }
//
// JSONObject commentObject = media.optJSONObject("edge_media_to_parent_comment");
// final long commentsCount = commentObject != null ? commentObject.optLong("count") : 0;
// final FeedModel.Builder feedModelBuilder = new FeedModel.Builder()
// .setItemType(mediaItemType)
// .setPostId(media.getString(Constants.EXTRAS_ID))
// .setDisplayUrl(isVideo ? media.getString("video_url")
// : ResponseBodyUtils.getHighQualityImage(media))
// .setThumbnailUrl(media.getString("display_url"))
// .setImageHeight(media.getJSONObject("dimensions").getInt("height"))
// .setImageWidth(media.getJSONObject("dimensions").getInt("width"))
// .setShortCode(shortCode)
// .setPostCaption(TextUtils.isEmpty(postCaption) ? null : postCaption)
// .setProfileModel(profileModel)
// .setViewCount(isVideo && media.has("video_view_count")
// ? media.getLong("video_view_count")
// : -1)
// .setTimestamp(timestamp)
// .setLiked(media.getBoolean("viewer_has_liked"))
// .setBookmarked(media.getBoolean("viewer_has_saved"))
// .setLikesCount(media.getJSONObject("edge_media_preview_like")
// .getLong("count"))
// .setLocationName(media.isNull("location")
// ? null
// : media.getJSONObject("location").optString("name"))
// .setLocationId(media.isNull("location")
// ? null
// : media.getJSONObject("location").optString("id"))
// .setCommentsCount(commentsCount);
// if (isSlider) {
// final JSONArray children = media.getJSONObject("edge_sidecar_to_children").getJSONArray("edges");
// final List<PostChild> postModels = new ArrayList<>();
// for (int i = 0; i < children.length(); ++i) {
// final JSONObject childNode = children.getJSONObject(i).getJSONObject("node");
// final boolean isChildVideo = childNode.getBoolean("is_video");
// postModels.add(new PostChild.Builder()
// .setItemType(isChildVideo ? MediaItemType.MEDIA_TYPE_VIDEO
// : MediaItemType.MEDIA_TYPE_IMAGE)
// .setDisplayUrl(isChildVideo ? childNode.getString("video_url")
// : childNode.getString("display_url"))
// .setShortCode(media.getString(Constants.EXTRAS_SHORTCODE))
// .setVideoViews(isChildVideo && childNode.has("video_view_count")
// ? childNode.getLong("video_view_count")
// : -1)
// .setThumbnailUrl(childNode.getString("display_url"))
// .setHeight(childNode.getJSONObject("dimensions").getInt("height"))
// .setWidth(childNode.getJSONObject("dimensions").getInt("width"))
// .build());
// }
// feedModelBuilder.setSliderItems(postModels);
// }
// return feedModelBuilder.build();
return ResponseBodyUtils.parseGraphQLItem(media);
}
} catch (Exception e) {
if (logCollector != null) {
@ -161,7 +154,7 @@ public final class PostFetcher extends AsyncTask<Void, Void, FeedModel> {
}
@Override
protected void onPostExecute(final FeedModel feedModel) {
protected void onPostExecute(final Media feedModel) {
if (fetchListener != null) fetchListener.onResult(feedModel);
}
}

View File

@ -5,7 +5,6 @@ import android.util.Log;
import androidx.annotation.Nullable;
import org.json.JSONArray;
import org.json.JSONObject;
import java.net.HttpURLConnection;
@ -13,7 +12,8 @@ import java.net.URL;
import awais.instagrabber.BuildConfig;
import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.repositories.responses.FriendshipStatus;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.NetworkUtils;
@ -23,19 +23,21 @@ import awaisomereport.LogCollector;
import static awais.instagrabber.utils.Utils.logCollector;
import static awais.instagrabber.utils.Utils.settingsHelper;
public final class ProfileFetcher extends AsyncTask<Void, Void, ProfileModel> {
private final FetchListener<ProfileModel> fetchListener;
public final class ProfileFetcher extends AsyncTask<Void, Void, User> {
private static final String TAG = ProfileFetcher.class.getSimpleName();
private final FetchListener<User> fetchListener;
private final String userName;
public ProfileFetcher(String userName, FetchListener<ProfileModel> fetchListener) {
public ProfileFetcher(String userName, FetchListener<User> fetchListener) {
this.userName = userName;
this.fetchListener = fetchListener;
}
@Nullable
@Override
protected ProfileModel doInBackground(final Void... voids) {
ProfileModel result = null;
protected User doInBackground(final Void... voids) {
User result = null;
try {
final HttpURLConnection conn = (HttpURLConnection) new URL("https://www.instagram.com/" + userName + "/?__a=1").openConnection();
@ -43,39 +45,77 @@ public final class ProfileFetcher extends AsyncTask<Void, Void, ProfileModel> {
conn.connect();
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
final JSONObject user = new JSONObject(NetworkUtils.readFromConnection(conn)).getJSONObject("graphql").getJSONObject(Constants.EXTRAS_USER);
final String json = NetworkUtils.readFromConnection(conn);
Log.d(TAG, "doInBackground: " + json);
final JSONObject userJson = new JSONObject(json).getJSONObject("graphql")
.getJSONObject(Constants.EXTRAS_USER);
final String cookie = settingsHelper.getString(Constants.COOKIE);
boolean isPrivate = user.getBoolean("is_private");
final String id = user.getString(Constants.EXTRAS_ID);
final String uid = CookieUtils.getUserIdFromCookie(cookie);
final JSONObject timelineMedia = user.getJSONObject("edge_owner_to_timeline_media");
if (timelineMedia.has("edges")) {
final JSONArray edges = timelineMedia.getJSONArray("edges");
}
boolean isPrivate = userJson.getBoolean("is_private");
final long id = userJson.optLong(Constants.EXTRAS_ID, 0);
final long uid = CookieUtils.getUserIdFromCookie(cookie);
final JSONObject timelineMedia = userJson.getJSONObject("edge_owner_to_timeline_media");
// if (timelineMedia.has("edges")) {
// final JSONArray edges = timelineMedia.getJSONArray("edges");
// }
String url = user.optString("external_url");
String url = userJson.optString("external_url");
if (TextUtils.isEmpty(url)) url = null;
result = new ProfileModel(isPrivate,
user.optBoolean("followed_by_viewer") ? false : (id.equals(uid) ? false : isPrivate),
user.getBoolean("is_verified"),
return new User(
id,
userName,
user.getString("full_name"),
user.getString("biography"),
url,
user.getString("profile_pic_url"),
user.getString("profile_pic_url_hd"),
userJson.getString("full_name"),
isPrivate,
userJson.getString("profile_pic_url_hd"),
null,
new FriendshipStatus(
userJson.optBoolean("followed_by_viewer"),
userJson.optBoolean("follows_viewer"),
userJson.optBoolean("blocked_by_viewer"),
false,
isPrivate,
false,
userJson.optBoolean("restricted_by_viewer"),
false,
userJson.optBoolean("restricted_by_viewer"),
false
),
userJson.getBoolean("is_verified"),
false,
false,
false,
false,
null,
null,
timelineMedia.getLong("count"),
user.getJSONObject("edge_followed_by").getLong("count"),
user.getJSONObject("edge_follow").getLong("count"),
user.optBoolean("followed_by_viewer"),
user.optBoolean("follows_viewer"),
user.optBoolean("restricted_by_viewer"),
user.optBoolean("blocked_by_viewer"),
user.optBoolean("requested_by_viewer"));
userJson.getJSONObject("edge_followed_by").getLong("count"),
userJson.getJSONObject("edge_follow").getLong("count"),
0,
userJson.getString("biography"),
url,
0,
null);
// result = new ProfileModel(isPrivate,
// !user.optBoolean("followed_by_viewer") && (id != uid && isPrivate),
// user.getBoolean("is_verified"),
// id,
// userName,
// user.getString("full_name"),
// user.getString("biography"),
// url,
// user.getString("profile_pic_url"),
// user.getString("profile_pic_url_hd"),
// timelineMedia.getLong("count"),
// user.getJSONObject("edge_followed_by").getLong("count"),
// user.getJSONObject("edge_follow").getLong("count"),
// user.optBoolean("followed_by_viewer"),
// user.optBoolean("follows_viewer"),
// user.optBoolean("restricted_by_viewer"),
// user.optBoolean("blocked_by_viewer"),
// user.optBoolean("requested_by_viewer"));
}
conn.disconnect();
@ -89,7 +129,7 @@ public final class ProfileFetcher extends AsyncTask<Void, Void, ProfileModel> {
}
@Override
protected void onPostExecute(final ProfileModel result) {
protected void onPostExecute(final User result) {
if (fetchListener != null) fetchListener.onResult(result);
}
}

View File

@ -4,9 +4,9 @@ import java.util.List;
import awais.instagrabber.customviews.helpers.PostFetcher;
import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.PostsFetchResponse;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.webservices.GraphQLService;
import awais.instagrabber.webservices.ProfileService;
import awais.instagrabber.webservices.ServiceCallback;
@ -15,12 +15,12 @@ public class ProfilePostFetchService implements PostFetcher.PostFetchService {
private static final String TAG = "ProfilePostFetchService";
private final ProfileService profileService;
private final GraphQLService graphQLService;
private final ProfileModel profileModel;
private final User profileModel;
private final boolean isLoggedIn;
private String nextMaxId;
private boolean moreAvailable;
public ProfilePostFetchService(final ProfileModel profileModel, final boolean isLoggedIn) {
public ProfilePostFetchService(final User profileModel, final boolean isLoggedIn) {
this.profileModel = profileModel;
this.isLoggedIn = isLoggedIn;
graphQLService = isLoggedIn ? null : GraphQLService.getInstance();
@ -28,8 +28,8 @@ public class ProfilePostFetchService implements PostFetcher.PostFetchService {
}
@Override
public void fetch(final FetchListener<List<FeedModel>> fetchListener) {
final ServiceCallback cb = new ServiceCallback<PostsFetchResponse>() {
public void fetch(final FetchListener<List<Media>> fetchListener) {
final ServiceCallback<PostsFetchResponse> cb = new ServiceCallback<PostsFetchResponse>() {
@Override
public void onSuccess(final PostsFetchResponse result) {
if (result == null) return;
@ -48,8 +48,8 @@ public class ProfilePostFetchService implements PostFetcher.PostFetchService {
}
}
};
if (isLoggedIn) profileService.fetchPosts(profileModel.getId(), nextMaxId, cb);
else graphQLService.fetchProfilePosts(profileModel.getId(), 30, nextMaxId, cb);
if (isLoggedIn) profileService.fetchPosts(profileModel.getPk(), nextMaxId, cb);
else graphQLService.fetchProfilePosts(profileModel.getPk(), 30, nextMaxId, cb);
}
@Override

View File

@ -4,8 +4,8 @@ import java.util.List;
import awais.instagrabber.customviews.helpers.PostFetcher;
import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.models.enums.PostItemType;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.PostsFetchResponse;
import awais.instagrabber.webservices.GraphQLService;
import awais.instagrabber.webservices.ProfileService;
@ -14,14 +14,14 @@ import awais.instagrabber.webservices.ServiceCallback;
public class SavedPostFetchService implements PostFetcher.PostFetchService {
private final ProfileService profileService;
private final GraphQLService graphQLService;
private final String profileId;
private final long profileId;
private final PostItemType type;
private final boolean isLoggedIn;
private String nextMaxId;
private boolean moreAvailable;
public SavedPostFetchService(final String profileId, final PostItemType type, final boolean isLoggedIn) {
public SavedPostFetchService(final long profileId, final PostItemType type, final boolean isLoggedIn) {
this.profileId = profileId;
this.type = type;
this.isLoggedIn = isLoggedIn;
@ -30,7 +30,7 @@ public class SavedPostFetchService implements PostFetcher.PostFetchService {
}
@Override
public void fetch(final FetchListener<List<FeedModel>> fetchListener) {
public void fetch(final FetchListener<List<Media>> fetchListener) {
final ServiceCallback<PostsFetchResponse> callback = new ServiceCallback<PostsFetchResponse>() {
@Override
public void onSuccess(final PostsFetchResponse result) {

View File

@ -17,9 +17,9 @@ import awais.instagrabber.utils.NetworkUtils;
public final class UsernameFetcher extends AsyncTask<Void, Void, String> {
private final FetchListener<String> fetchListener;
private final String uid;
private final long uid;
public UsernameFetcher(final String uid, final FetchListener<String> fetchListener) {
public UsernameFetcher(final long uid, final FetchListener<String> fetchListener) {
this.uid = uid;
this.fetchListener = fetchListener;
}

View File

@ -20,10 +20,10 @@ public class CreateThreadAction extends AsyncTask<Void, Void, String> {
private static final String TAG = "CommentAction";
private final String cookie;
private final String userId;
private final long userId;
private final OnTaskCompleteListener onTaskCompleteListener;
public CreateThreadAction(final String cookie, final String userId, final OnTaskCompleteListener onTaskCompleteListener) {
public CreateThreadAction(final String cookie, final long userId, final OnTaskCompleteListener onTaskCompleteListener) {
this.cookie = cookie;
this.userId = userId;
this.onTaskCompleteListener = onTaskCompleteListener;

View File

@ -30,11 +30,11 @@ import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration;
import awais.instagrabber.customviews.helpers.PostFetcher;
import awais.instagrabber.customviews.helpers.RecyclerLazyLoaderAtEdge;
import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.models.PostChild;
import awais.instagrabber.models.PostsLayoutPreferences;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.utils.ResponseBodyUtils;
import awais.instagrabber.utils.Utils;
import awais.instagrabber.viewmodels.FeedViewModel;
import awais.instagrabber.viewmodels.MediaViewModel;
import awais.instagrabber.workers.DownloadWorker;
public class PostsRecyclerView extends RecyclerView {
@ -48,7 +48,7 @@ public class PostsRecyclerView extends RecyclerView {
private ViewModelStoreOwner viewModelStoreOwner;
private FeedAdapterV2 feedAdapter;
private LifecycleOwner lifeCycleOwner;
private FeedViewModel feedViewModel;
private MediaViewModel mediaViewModel;
private boolean initCalled = false;
private GridSpacingItemDecoration gridSpacingItemDecoration;
private RecyclerLazyLoaderAtEdge lazyLoader;
@ -58,20 +58,20 @@ public class PostsRecyclerView extends RecyclerView {
private final List<FetchStatusChangeListener> fetchStatusChangeListeners = new ArrayList<>();
private final FetchListener<List<FeedModel>> fetchListener = new FetchListener<List<FeedModel>>() {
private final FetchListener<List<Media>> fetchListener = new FetchListener<List<Media>>() {
@Override
public void onResult(final List<FeedModel> result) {
public void onResult(final List<Media> result) {
final int currentPage = lazyLoader.getCurrentPage();
if (currentPage == 0) {
feedViewModel.getList().postValue(result);
mediaViewModel.getList().postValue(result);
shouldScrollToTop = true;
dispatchFetchStatus();
return;
}
final List<FeedModel> models = feedViewModel.getList().getValue();
final List<FeedModel> modelsCopy = models == null ? new ArrayList<>() : new ArrayList<>(models);
final List<Media> models = mediaViewModel.getList().getValue();
final List<Media> modelsCopy = models == null ? new ArrayList<>() : new ArrayList<>(models);
modelsCopy.addAll(result);
feedViewModel.getList().postValue(modelsCopy);
mediaViewModel.getList().postValue(modelsCopy);
dispatchFetchStatus();
}
@ -182,8 +182,8 @@ public class PostsRecyclerView extends RecyclerView {
}
private void initSelf() {
feedViewModel = new ViewModelProvider(viewModelStoreOwner).get(FeedViewModel.class);
feedViewModel.getList().observe(lifeCycleOwner, list -> {
mediaViewModel = new ViewModelProvider(viewModelStoreOwner).get(MediaViewModel.class);
mediaViewModel.getList().observe(lifeCycleOwner, list -> {
if (list.size() > 0) feedAdapter.submitList(list, () -> {
if (!shouldScrollToTop) return;
smoothScrollToPosition(0);
@ -217,10 +217,10 @@ public class PostsRecyclerView extends RecyclerView {
final float progressPercent = progress.getFloat(DownloadWorker.PROGRESS, 0);
if (progressPercent != 100) continue;
final String url = progress.getString(DownloadWorker.URL);
final List<FeedModel> feedModels = feedViewModel.getList().getValue();
final List<Media> feedModels = mediaViewModel.getList().getValue();
if (feedModels == null) continue;
for (int i = 0; i < feedModels.size(); i++) {
final FeedModel feedModel = feedModels.get(i);
final Media feedModel = feedModels.get(i);
final List<String> displayUrls = getDisplayUrl(feedModel);
if (displayUrls.contains(url)) {
feedAdapter.notifyItemChanged(i);
@ -231,19 +231,19 @@ public class PostsRecyclerView extends RecyclerView {
});
}
private List<String> getDisplayUrl(final FeedModel feedModel) {
private List<String> getDisplayUrl(final Media feedModel) {
List<String> urls = Collections.emptyList();
switch (feedModel.getItemType()) {
switch (feedModel.getMediaType()) {
case MEDIA_TYPE_IMAGE:
case MEDIA_TYPE_VIDEO:
urls = Collections.singletonList(feedModel.getDisplayUrl());
urls = Collections.singletonList(ResponseBodyUtils.getImageUrl(feedModel));
break;
case MEDIA_TYPE_SLIDER:
final List<PostChild> sliderItems = feedModel.getSliderItems();
final List<Media> sliderItems = feedModel.getCarouselMedia();
if (sliderItems != null) {
final ImmutableList.Builder<String> builder = ImmutableList.builder();
for (final PostChild child : sliderItems) {
builder.add(child.getDisplayUrl());
for (final Media child : sliderItems) {
builder.add(ResponseBodyUtils.getImageUrl(child));
}
urls = builder.build();
}

View File

@ -24,9 +24,9 @@ import androidx.appcompat.widget.AppCompatTextView;
import awais.instagrabber.R;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.utils.TextUtils;
@Deprecated
public final class RamboTextView extends AppCompatTextView {
private static final String TAG = "RamboTextView";
private static final int highlightBackgroundSpanKey = R.id.tvComment;
@ -90,8 +90,8 @@ public final class RamboTextView extends AppCompatTextView {
// if (isExpandable && !touchStartedOverAClickableSpan)
// return !isExpanded | super.onTouchEvent(event); // short operator, because we want two shits to work
final Object tag = getTag();
final FeedModel feedModel = tag instanceof FeedModel ? (FeedModel) tag : null;
// final Object tag = getTag();
// final FeedModel feedModel = tag instanceof FeedModel ? (FeedModel) tag : null;
switch (action) {
case MotionEvent.ACTION_DOWN:

View File

@ -1,17 +1,21 @@
package awais.instagrabber.customviews.helpers;
import android.util.Log;
import java.util.List;
import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.repositories.responses.Media;
public class PostFetcher {
private static final String TAG = PostFetcher.class.getSimpleName();
private final PostFetchService postFetchService;
private final FetchListener<List<FeedModel>> fetchListener;
private final FetchListener<List<Media>> fetchListener;
private boolean fetching;
public PostFetcher(final PostFetchService postFetchService,
final FetchListener<List<FeedModel>> fetchListener) {
final FetchListener<List<Media>> fetchListener) {
this.postFetchService = postFetchService;
this.fetchListener = fetchListener;
}
@ -19,9 +23,17 @@ public class PostFetcher {
public void fetch() {
if (!fetching) {
fetching = true;
postFetchService.fetch(result -> {
fetching = false;
fetchListener.onResult(result);
postFetchService.fetch(new FetchListener<List<Media>>() {
@Override
public void onResult(final List<Media> result) {
fetching = false;
fetchListener.onResult(result);
}
@Override
public void onFailure(final Throwable t) {
Log.e(TAG, "onFailure: ", t);
}
});
}
}
@ -39,7 +51,7 @@ public class PostFetcher {
}
public interface PostFetchService {
void fetch(FetchListener<List<FeedModel>> fetchListener);
void fetch(FetchListener<List<Media>> fetchListener);
void reset();

View File

@ -12,7 +12,7 @@ import com.google.android.exoplayer2.SimpleExoPlayer;
import awais.instagrabber.R;
import awais.instagrabber.adapters.viewholder.feed.FeedVideoViewHolder;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.repositories.responses.Media;
import static androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_DRAGGING;
import static androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE;
@ -75,8 +75,8 @@ public class VideoAwareRecyclerScroller extends RecyclerView.OnScrollListener {
}
return;
}
if (currentlyPlayingViewHolder != null && currentlyPlayingViewHolder.getCurrentFeedModel().getPostId()
.equals(videoHolder.getCurrentFeedModel().getPostId())) {
if (currentlyPlayingViewHolder != null && currentlyPlayingViewHolder.getCurrentFeedModel().getPk()
.equals(videoHolder.getCurrentFeedModel().getPk())) {
return;
}
if (currentlyPlayingViewHolder != null) {
@ -203,10 +203,10 @@ public class VideoAwareRecyclerScroller extends RecyclerView.OnScrollListener {
final boolean result = viewSwitcher.getGlobalVisibleRect(visibleItemRect, offset);
if (!result) continue;
final FeedVideoViewHolder viewHolder = (FeedVideoViewHolder) recyclerView.getChildViewHolder(view);
final FeedModel currentFeedModel = viewHolder.getCurrentFeedModel();
final Media currentFeedModel = viewHolder.getCurrentFeedModel();
visibleItemRect.offset(-offset.x, -offset.y);
final int visibleHeight = visibleItemRect.height();
if (visibleHeight < currentFeedModel.getImageHeight()) {
if (visibleHeight < currentFeedModel.getOriginalHeight()) {
continue;
}
// Log.d(TAG, "post:" + currentFeedModel.getPostId() + ", visibleHeight: " + visibleHeight + ", post height: " + currentFeedModel.getImageHeight());

View File

@ -28,11 +28,11 @@ public class AccountRepository {
return instance;
}
public void getAccount(final String uid,
public void getAccount(final long uid,
final RepositoryCallback<Account> callback) {
// request on the I/O thread
appExecutors.diskIO().execute(() -> {
final Account account = accountDataSource.getAccount(uid);
final Account account = accountDataSource.getAccount(String.valueOf(uid));
// notify on the main thread
appExecutors.mainThread().execute(() -> {
if (callback == null) return;
@ -81,7 +81,7 @@ public class AccountRepository {
});
}
public void insertOrUpdateAccount(final String uid,
public void insertOrUpdateAccount(final long uid,
final String username,
final String cookie,
final String fullName,
@ -89,8 +89,8 @@ public class AccountRepository {
final RepositoryCallback<Account> callback) {
// request on the I/O thread
appExecutors.diskIO().execute(() -> {
accountDataSource.insertOrUpdateAccount(uid, username, cookie, fullName, profilePicUrl);
final Account updated = accountDataSource.getAccount(uid);
accountDataSource.insertOrUpdateAccount(String.valueOf(uid), username, cookie, fullName, profilePicUrl);
final Account updated = accountDataSource.getAccount(String.valueOf(uid));
// notify on the main thread
appExecutors.mainThread().execute(() -> {
if (callback == null) return;

View File

@ -28,7 +28,7 @@ import java.io.File;
import awais.instagrabber.R;
import awais.instagrabber.databinding.DialogProfilepicBinding;
import awais.instagrabber.repositories.responses.UserInfo;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.DownloadUtils;
@ -41,7 +41,7 @@ import static awais.instagrabber.utils.Utils.settingsHelper;
public class ProfilePicDialogFragment extends DialogFragment {
private static final String TAG = "ProfilePicDlgFragment";
private final String id;
private final long id;
private final String name;
private final String fallbackUrl;
@ -49,7 +49,7 @@ public class ProfilePicDialogFragment extends DialogFragment {
private DialogProfilepicBinding binding;
private String url;
public ProfilePicDialogFragment(final String id, final String name, final String fallbackUrl) {
public ProfilePicDialogFragment(final long id, final String name, final String fallbackUrl) {
this.id = id;
this.name = name;
this.fallbackUrl = fallbackUrl;
@ -61,7 +61,7 @@ public class ProfilePicDialogFragment extends DialogFragment {
final Bundle savedInstanceState) {
binding = DialogProfilepicBinding.inflate(inflater, container, false);
final String cookie = settingsHelper.getString(Constants.COOKIE);
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != null;
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) > 0;
return binding.getRoot();
}
@ -116,11 +116,11 @@ public class ProfilePicDialogFragment extends DialogFragment {
private void fetchAvatar() {
if (isLoggedIn) {
final UserService userService = UserService.getInstance();
userService.getUserInfo(id, new ServiceCallback<UserInfo>() {
userService.getUserInfo(id, new ServiceCallback<User>() {
@Override
public void onSuccess(final UserInfo result) {
public void onSuccess(final User result) {
if (result != null) {
setupPhoto(result.getHDProfilePicUrl());
setupPhoto(result.getProfilePicUrl());
}
}
@ -131,8 +131,7 @@ public class ProfilePicDialogFragment extends DialogFragment {
getDialog().dismiss();
}
});
}
else setupPhoto(fallbackUrl);
} else setupPhoto(fallbackUrl);
}
private void setupPhoto(final String result) {

View File

@ -22,8 +22,6 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.LinearLayoutCompat;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavController;
import androidx.navigation.NavDirections;
@ -43,10 +41,9 @@ import awais.instagrabber.adapters.CommentsAdapter;
import awais.instagrabber.asyncs.CommentsFetcher;
import awais.instagrabber.customviews.helpers.RecyclerLazyLoader;
import awais.instagrabber.databinding.FragmentCommentsBinding;
import awais.instagrabber.dialogs.ProfilePicDialogFragment;
import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.CommentModel;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.TextUtils;
@ -66,7 +63,9 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
private FragmentCommentsBinding binding;
private LinearLayoutManager layoutManager;
private RecyclerLazyLoader lazyLoader;
private String shortCode, userId, endCursor = null;
private String shortCode;
private long userId;
private String endCursor = null;
private Resources resources;
private InputMethodManager imm;
private AppCompatActivity fragmentActivity;
@ -141,8 +140,8 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
Toast.makeText(context, R.string.comment_send_empty_comment, Toast.LENGTH_SHORT).show();
return;
}
final String userId = CookieUtils.getUserIdFromCookie(cookie);
if (userId == null) return;
final long userId = CookieUtils.getUserIdFromCookie(cookie);
if (userId == 0) return;
String replyToId = null;
final CommentModel commentModel = commentsAdapter.getSelected();
if (commentModel != null) {
@ -280,7 +279,7 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
// final ActionBar actionBar = fragmentActivity.getSupportActionBar();
// if (actionBar == null) return;
// actionBar.setTitle(R.string.title_comments);
// actionBar.setSubtitle(shortCode);
// actionBar.setSubtitle(shortCode);
// }
private void onCommentClick(final CommentModel commentModel) {
@ -290,10 +289,10 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
String[] commentDialogList;
final String userIdFromCookie = CookieUtils.getUserIdFromCookie(cookie);
final long userIdFromCookie = CookieUtils.getUserIdFromCookie(cookie);
if (!TextUtils.isEmpty(cookie)
&& userIdFromCookie != null
&& (userIdFromCookie.equals(commentModel.getProfileModel().getId()) || userIdFromCookie.equals(userId))) {
&& userIdFromCookie != 0
&& (userIdFromCookie == commentModel.getProfileModel().getPk() || userIdFromCookie == userId)) {
commentDialogList = new String[]{
resources.getString(R.string.open_profile),
resources.getString(R.string.comment_viewer_copy_comment),
@ -324,7 +323,7 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
final Context context = getContext();
if (context == null) return;
final DialogInterface.OnClickListener profileDialogListener = (dialog, which) -> {
final ProfileModel profileModel = commentModel.getProfileModel();
final User profileModel = commentModel.getProfileModel();
final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
switch (which) {
case 0: // open profile
@ -340,8 +339,7 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
bundle.putString("postId", commentModel.getId());
bundle.putBoolean("isComment", true);
navController.navigate(R.id.action_global_likesViewerFragment, bundle);
}
else Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
} else Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
break;
case 3: // reply to comment
commentsAdapter.setSelected(commentModel);
@ -418,8 +416,8 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
});
break;
case 6: // delete comment
final String userId = CookieUtils.getUserIdFromCookie(cookie);
if (userId == null) return;
final long userId = CookieUtils.getUserIdFromCookie(cookie);
if (userId == 0) return;
mediaService.deleteComment(
postId, userId, commentModel.getId(), csrfToken,
new ServiceCallback<Boolean>() {

View File

@ -30,7 +30,7 @@ import awais.instagrabber.adapters.FollowAdapter;
import awais.instagrabber.customviews.helpers.RecyclerLazyLoader;
import awais.instagrabber.databinding.FragmentFollowersViewerBinding;
import awais.instagrabber.models.FollowModel;
import awais.instagrabber.repositories.responses.FriendshipRepoListFetchResponse;
import awais.instagrabber.repositories.responses.FriendshipListFetchResponse;
import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.webservices.FriendshipService;
import awais.instagrabber.webservices.ServiceCallback;
@ -45,7 +45,11 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
private final ArrayList<FollowModel> allFollowing = new ArrayList<>();
private boolean moreAvailable = true, isFollowersList, isCompare = false, loading = false, shouldRefresh = true;
private String profileId, username, namePost, type, endCursor;
private long profileId;
private String username;
private String namePost;
private String type;
private String endCursor;
private Resources resources;
private LinearLayoutManager layoutManager;
private RecyclerLazyLoader lazyLoader;
@ -58,9 +62,9 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
private FriendshipService friendshipService;
private AppCompatActivity fragmentActivity;
final ServiceCallback<FriendshipRepoListFetchResponse> followingFetchCb = new ServiceCallback<FriendshipRepoListFetchResponse>() {
final ServiceCallback<FriendshipListFetchResponse> followingFetchCb = new ServiceCallback<FriendshipListFetchResponse>() {
@Override
public void onSuccess(final FriendshipRepoListFetchResponse result) {
public void onSuccess(final FriendshipListFetchResponse result) {
if (result != null) {
followingModels.addAll(result.getItems());
if (!isFollowersList) followModels.addAll(result.getItems());
@ -84,9 +88,9 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
Log.e(TAG, "Error fetching list (double, following)", t);
}
};
final ServiceCallback<FriendshipRepoListFetchResponse> followersFetchCb = new ServiceCallback<FriendshipRepoListFetchResponse>() {
final ServiceCallback<FriendshipListFetchResponse> followersFetchCb = new ServiceCallback<FriendshipListFetchResponse>() {
@Override
public void onSuccess(final FriendshipRepoListFetchResponse result) {
public void onSuccess(final FriendshipListFetchResponse result) {
if (result != null) {
followersModels.addAll(result.getItems());
if (isFollowersList) followModels.addAll(result.getItems());
@ -195,27 +199,24 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
private void listFollows() {
type = resources.getString(isFollowersList ? R.string.followers_type_followers : R.string.followers_type_following);
setSubtitle(type);
final ServiceCallback<FriendshipRepoListFetchResponse> cb = new ServiceCallback<FriendshipRepoListFetchResponse>() {
final ServiceCallback<FriendshipListFetchResponse> cb = new ServiceCallback<FriendshipListFetchResponse>() {
@Override
public void onSuccess(final FriendshipRepoListFetchResponse result) {
public void onSuccess(final FriendshipListFetchResponse result) {
if (result == null) {
binding.swipeRefreshLayout.setRefreshing(false);
return;
}
else {
int oldSize = followModels.size() == 0 ? 0 : followModels.size() - 1;
followModels.addAll(result.getItems());
if (result.isMoreAvailable()) {
moreAvailable = true;
endCursor = result.getNextMaxId();
}
else moreAvailable = false;
binding.swipeRefreshLayout.setRefreshing(false);
if (isFollowersList) followersModels.addAll(result.getItems());
else followingModels.addAll(result.getItems());
refreshAdapter(followModels, null, null, null);
layoutManager.scrollToPosition(oldSize);
}
int oldSize = followModels.size() == 0 ? 0 : followModels.size() - 1;
followModels.addAll(result.getItems());
if (result.isMoreAvailable()) {
moreAvailable = true;
endCursor = result.getNextMaxId();
} else moreAvailable = false;
binding.swipeRefreshLayout.setRefreshing(false);
if (isFollowersList) followersModels.addAll(result.getItems());
else followingModels.addAll(result.getItems());
refreshAdapter(followModels, null, null, null);
layoutManager.scrollToPosition(oldSize);
}
@Override
@ -239,8 +240,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
if (moreAvailable) {
binding.swipeRefreshLayout.setRefreshing(true);
friendshipService.getList(isFollowersList, profileId, endCursor, cb);
}
else {
} else {
refreshAdapter(followModels, null, null, null);
layoutManager.scrollToPosition(0);
}
@ -256,19 +256,17 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
binding.swipeRefreshLayout.setRefreshing(true);
Toast.makeText(getContext(), R.string.follower_start_compare, Toast.LENGTH_LONG).show();
friendshipService.getList(isFollowersList,
profileId,
endCursor,
isFollowersList ? followersFetchCb : followingFetchCb);
}
else if (followersModels.size() == 0 || followingModels.size() == 0) {
profileId,
endCursor,
isFollowersList ? followersFetchCb : followingFetchCb);
} else if (followersModels.size() == 0 || followingModels.size() == 0) {
binding.swipeRefreshLayout.setRefreshing(true);
Toast.makeText(getContext(), R.string.follower_start_compare, Toast.LENGTH_LONG).show();
friendshipService.getList(!isFollowersList,
profileId,
null,
isFollowersList ? followingFetchCb : followersFetchCb);
}
else showCompare();
profileId,
null,
isFollowersList ? followingFetchCb : followersFetchCb);
} else showCompare();
}
private void showCompare() {
@ -383,8 +381,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
else if (isCompare) {
isCompare = !isCompare;
listFollows();
}
else {
} else {
isCompare = !isCompare;
listCompare();
}

View File

@ -55,11 +55,12 @@ import awais.instagrabber.db.repositories.FavoriteRepository;
import awais.instagrabber.db.repositories.RepositoryCallback;
import awais.instagrabber.dialogs.PostsLayoutPreferencesDialogFragment;
import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.models.HashtagModel;
import awais.instagrabber.models.PostsLayoutPreferences;
import awais.instagrabber.models.StoryModel;
import awais.instagrabber.models.enums.FavoriteType;
import awais.instagrabber.repositories.responses.Location;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.DownloadUtils;
@ -96,8 +97,8 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
private boolean isLoggedIn;
private TagsService tagsService;
private boolean storiesFetching;
private Set<FeedModel> selectedFeedModels;
private FeedModel downloadFeedModel;
private Set<Media> selectedFeedModels;
private Media downloadFeedModel;
private int downloadChildPosition = -1;
private PostsLayoutPreferences layoutPreferences = Utils.getPostsLayoutPreferences(Constants.PREF_HASHTAG_POSTS_LAYOUT);
private LayoutHashtagDetailsBinding hashtagDetailsBinding;
@ -135,27 +136,27 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
});
private final FeedAdapterV2.FeedItemCallback feedItemCallback = new FeedAdapterV2.FeedItemCallback() {
@Override
public void onPostClick(final FeedModel feedModel, final View profilePicView, final View mainPostImage) {
public void onPostClick(final Media feedModel, final View profilePicView, final View mainPostImage) {
openPostDialog(feedModel, profilePicView, mainPostImage, -1);
}
@Override
public void onSliderClick(final FeedModel feedModel, final int position) {
public void onSliderClick(final Media feedModel, final int position) {
openPostDialog(feedModel, null, null, position);
}
@Override
public void onCommentsClick(final FeedModel feedModel) {
public void onCommentsClick(final Media feedModel) {
final NavDirections commentsAction = HashTagFragmentDirections.actionGlobalCommentsViewerFragment(
feedModel.getShortCode(),
feedModel.getPostId(),
feedModel.getProfileModel().getId()
feedModel.getCode(),
feedModel.getCode(),
feedModel.getUser().getPk()
);
NavHostFragment.findNavController(HashTagFragment.this).navigate(commentsAction);
}
@Override
public void onDownloadClick(final FeedModel feedModel, final int childPosition) {
public void onDownloadClick(final Media feedModel, final int childPosition) {
final Context context = getContext();
if (context == null) return;
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
@ -174,8 +175,10 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
}
@Override
public void onLocationClick(final FeedModel feedModel) {
final NavDirections action = HashTagFragmentDirections.actionGlobalLocationFragment(feedModel.getLocationId());
public void onLocationClick(final Media media) {
final Location location = media.getLocation();
if (location == null) return;
final NavDirections action = HashTagFragmentDirections.actionGlobalLocationFragment(location.getPk());
NavHostFragment.findNavController(HashTagFragment.this).navigate(action);
}
@ -185,13 +188,13 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
}
@Override
public void onNameClick(final FeedModel feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getProfileModel().getUsername());
public void onNameClick(final Media feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getUser().getUsername());
}
@Override
public void onProfilePicClick(final FeedModel feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getProfileModel().getUsername());
public void onProfilePicClick(final Media feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getUser().getUsername());
}
@Override
@ -204,14 +207,14 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
Utils.openEmailAddress(getContext(), emailId);
}
private void openPostDialog(@NonNull final FeedModel feedModel,
private void openPostDialog(@NonNull final Media feedModel,
final View profilePicView,
final View mainPostImage,
final int position) {
if (opening) return;
if (TextUtils.isEmpty(feedModel.getProfileModel().getUsername())) {
if (TextUtils.isEmpty(feedModel.getUser().getUsername())) {
opening = true;
new PostFetcher(feedModel.getShortCode(), newFeedModel -> {
new PostFetcher(feedModel.getCode(), newFeedModel -> {
opening = false;
if (newFeedModel == null) return;
openPostDialog(newFeedModel, profilePicView, mainPostImage, position);
@ -246,7 +249,7 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
}
@Override
public void onSelectionChange(final Set<FeedModel> selectedFeedModels) {
public void onSelectionChange(final Set<Media> selectedFeedModels) {
final String title = getString(R.string.number_selected, selectedFeedModels.size());
if (actionMode != null) {
actionMode.setTitle(title);
@ -355,7 +358,7 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
private void init() {
if (getArguments() == null) return;
final String cookie = settingsHelper.getString(Constants.COOKIE);
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != null;
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) > 0;
final HashTagFragmentArgs fragmentArgs = HashTagFragmentArgs.fromBundle(getArguments());
hashtag = fragmentArgs.getHashtag();
fetchHashtagModel();
@ -544,8 +547,10 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
hashtagDetailsBinding.mainHashtagImage.setImageURI(hashtagModel.getSdProfilePic());
final String postCount = String.valueOf(hashtagModel.getPostCount());
final SpannableStringBuilder span = new SpannableStringBuilder(getResources().getQuantityString(R.plurals.main_posts_count_inline,
hashtagModel.getPostCount() > 2000000000L ? 2000000000 : hashtagModel.getPostCount().intValue(),
postCount));
hashtagModel.getPostCount() > 2000000000L
? 2000000000
: hashtagModel.getPostCount().intValue(),
postCount));
span.setSpan(new RelativeSizeSpan(1.2f), 0, postCount.length(), 0);
span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0);
hashtagDetailsBinding.mainTagPostCount.setText(span);

View File

@ -1,8 +1,6 @@
package awais.instagrabber.fragments;
import android.content.Context;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
@ -12,8 +10,6 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.LinearLayoutCompat;
import androidx.navigation.fragment.NavHostFragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@ -26,12 +22,11 @@ import awais.instagrabber.R;
import awais.instagrabber.adapters.LikesAdapter;
import awais.instagrabber.customviews.helpers.RecyclerLazyLoader;
import awais.instagrabber.databinding.FragmentLikesBinding;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.repositories.responses.GraphQLUserListFetchResponse;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.utils.Utils;
import awais.instagrabber.webservices.GraphQLService;
import awais.instagrabber.webservices.MediaService;
import awais.instagrabber.webservices.ServiceCallback;
@ -41,14 +36,7 @@ import static awais.instagrabber.utils.Utils.settingsHelper;
public final class LikesViewerFragment extends BottomSheetDialogFragment implements SwipeRefreshLayout.OnRefreshListener {
private static final String TAG = "LikesViewerFragment";
private final String cookie = Utils.settingsHelper.getString(Constants.COOKIE);
private LikesAdapter likesAdapter;
private FragmentLikesBinding binding;
private LinearLayoutManager layoutManager;
private Resources resources;
private AppCompatActivity fragmentActivity;
private LinearLayoutCompat root;
private RecyclerLazyLoader lazyLoader;
private MediaService mediaService;
private GraphQLService graphQLService;
@ -56,13 +44,13 @@ public final class LikesViewerFragment extends BottomSheetDialogFragment impleme
private String postId, endCursor;
private boolean isComment;
private final ServiceCallback<List<ProfileModel>> cb = new ServiceCallback<List<ProfileModel>>() {
private final ServiceCallback<List<User>> cb = new ServiceCallback<List<User>>() {
@Override
public void onSuccess(final List<ProfileModel> result) {
public void onSuccess(final List<User> result) {
final LikesAdapter likesAdapter = new LikesAdapter(result, v -> {
final Object tag = v.getTag();
if (tag instanceof ProfileModel) {
ProfileModel model = (ProfileModel) tag;
if (tag instanceof User) {
User model = (User) tag;
final Bundle bundle = new Bundle();
bundle.putString("username", "@" + model.getUsername());
NavHostFragment.findNavController(LikesViewerFragment.this).navigate(R.id.action_global_profileFragment, bundle);
@ -79,8 +67,7 @@ public final class LikesViewerFragment extends BottomSheetDialogFragment impleme
try {
final Context context = getContext();
Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show();
}
catch (Exception e) {}
} catch (Exception ignored) {}
}
};
@ -90,8 +77,8 @@ public final class LikesViewerFragment extends BottomSheetDialogFragment impleme
endCursor = result.getNextMaxId();
final LikesAdapter likesAdapter = new LikesAdapter(result.getItems(), v -> {
final Object tag = v.getTag();
if (tag instanceof ProfileModel) {
ProfileModel model = (ProfileModel) tag;
if (tag instanceof User) {
User model = (User) tag;
final Bundle bundle = new Bundle();
bundle.putString("username", "@" + model.getUsername());
NavHostFragment.findNavController(LikesViewerFragment.this).navigate(R.id.action_global_profileFragment, bundle);
@ -107,8 +94,7 @@ public final class LikesViewerFragment extends BottomSheetDialogFragment impleme
try {
final Context context = getContext();
Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show();
}
catch (Exception e) {}
} catch (Exception ignored) {}
}
};
@ -116,8 +102,8 @@ public final class LikesViewerFragment extends BottomSheetDialogFragment impleme
public void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final String cookie = settingsHelper.getString(Constants.COOKIE);
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != null;
fragmentActivity = (AppCompatActivity) getActivity();
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) > 0;
// final AppCompatActivity fragmentActivity = (AppCompatActivity) getActivity();
mediaService = isLoggedIn ? MediaService.getInstance() : null;
graphQLService = isLoggedIn ? null : GraphQLService.getInstance();
// setHasOptionsMenu(true);
@ -129,8 +115,7 @@ public final class LikesViewerFragment extends BottomSheetDialogFragment impleme
binding = FragmentLikesBinding.inflate(getLayoutInflater());
binding.swipeRefreshLayout.setEnabled(false);
binding.swipeRefreshLayout.setNestedScrollingEnabled(false);
root = binding.getRoot();
return root;
return binding.getRoot();
}
@Override
@ -143,8 +128,7 @@ public final class LikesViewerFragment extends BottomSheetDialogFragment impleme
if (isComment && !isLoggedIn) {
lazyLoader.resetState();
graphQLService.fetchCommentLikers(postId, null, acb);
}
else mediaService.fetchLikes(postId, isComment, cb);
} else mediaService.fetchLikes(postId, isComment, cb);
}
private void init() {
@ -154,9 +138,8 @@ public final class LikesViewerFragment extends BottomSheetDialogFragment impleme
isComment = fragmentArgs.getIsComment();
binding.swipeRefreshLayout.setOnRefreshListener(this);
binding.swipeRefreshLayout.setRefreshing(true);
resources = getResources();
if (isComment && !isLoggedIn) {
layoutManager = new LinearLayoutManager(getContext());
final LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
binding.rvLikes.setLayoutManager(layoutManager);
lazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> {
if (!TextUtils.isEmpty(endCursor))

View File

@ -57,11 +57,11 @@ import awais.instagrabber.db.entities.Favorite;
import awais.instagrabber.db.repositories.FavoriteRepository;
import awais.instagrabber.db.repositories.RepositoryCallback;
import awais.instagrabber.dialogs.PostsLayoutPreferencesDialogFragment;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.models.LocationModel;
import awais.instagrabber.models.PostsLayoutPreferences;
import awais.instagrabber.models.StoryModel;
import awais.instagrabber.models.enums.FavoriteType;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.DownloadUtils;
@ -87,15 +87,15 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
private boolean shouldRefresh = true;
private boolean hasStories = false;
private boolean opening = false;
private String locationId;
private long locationId;
private LocationModel locationModel;
private ActionMode actionMode;
private StoriesService storiesService;
private AsyncTask<?, ?, ?> currentlyExecuting;
private boolean isLoggedIn;
private boolean storiesFetching;
private Set<FeedModel> selectedFeedModels;
private FeedModel downloadFeedModel;
private Set<Media> selectedFeedModels;
private Media downloadFeedModel;
private int downloadChildPosition = -1;
private PostsLayoutPreferences layoutPreferences = Utils.getPostsLayoutPreferences(Constants.PREF_LOCATION_POSTS_LAYOUT);
private LayoutLocationDetailsBinding locationDetailsBinding;
@ -132,27 +132,27 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
});
private final FeedAdapterV2.FeedItemCallback feedItemCallback = new FeedAdapterV2.FeedItemCallback() {
@Override
public void onPostClick(final FeedModel feedModel, final View profilePicView, final View mainPostImage) {
public void onPostClick(final Media feedModel, final View profilePicView, final View mainPostImage) {
openPostDialog(feedModel, profilePicView, mainPostImage, -1);
}
@Override
public void onSliderClick(final FeedModel feedModel, final int position) {
public void onSliderClick(final Media feedModel, final int position) {
openPostDialog(feedModel, null, null, position);
}
@Override
public void onCommentsClick(final FeedModel feedModel) {
public void onCommentsClick(final Media feedModel) {
final NavDirections commentsAction = LocationFragmentDirections.actionGlobalCommentsViewerFragment(
feedModel.getShortCode(),
feedModel.getPostId(),
feedModel.getProfileModel().getId()
feedModel.getCode(),
feedModel.getPk(),
feedModel.getUser().getPk()
);
NavHostFragment.findNavController(LocationFragment.this).navigate(commentsAction);
}
@Override
public void onDownloadClick(final FeedModel feedModel, final int childPosition) {
public void onDownloadClick(final Media feedModel, final int childPosition) {
final Context context = getContext();
if (context == null) return;
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
@ -171,8 +171,8 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
}
@Override
public void onLocationClick(final FeedModel feedModel) {
final NavDirections action = LocationFragmentDirections.actionGlobalLocationFragment(feedModel.getLocationId());
public void onLocationClick(final Media feedModel) {
final NavDirections action = LocationFragmentDirections.actionGlobalLocationFragment(feedModel.getLocation().getPk());
NavHostFragment.findNavController(LocationFragment.this).navigate(action);
}
@ -182,13 +182,13 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
}
@Override
public void onNameClick(final FeedModel feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getProfileModel().getUsername());
public void onNameClick(final Media feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getUser().getUsername());
}
@Override
public void onProfilePicClick(final FeedModel feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getProfileModel().getUsername());
public void onProfilePicClick(final Media feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getUser().getUsername());
}
@Override
@ -201,14 +201,14 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
Utils.openEmailAddress(getContext(), emailId);
}
private void openPostDialog(@NonNull final FeedModel feedModel,
private void openPostDialog(@NonNull final Media feedModel,
final View profilePicView,
final View mainPostImage,
final int position) {
if (opening) return;
if (TextUtils.isEmpty(feedModel.getProfileModel().getUsername())) {
if (TextUtils.isEmpty(feedModel.getUser().getUsername())) {
opening = true;
new PostFetcher(feedModel.getShortCode(), newFeedModel -> {
new PostFetcher(feedModel.getCode(), newFeedModel -> {
opening = false;
if (newFeedModel == null) return;
openPostDialog(newFeedModel, profilePicView, mainPostImage, position);
@ -244,7 +244,7 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
}
@Override
public void onSelectionChange(final Set<FeedModel> selectedFeedModels) {
public void onSelectionChange(final Set<Media> selectedFeedModels) {
final String title = getString(R.string.number_selected, selectedFeedModels.size());
if (actionMode != null) {
actionMode.setTitle(title);
@ -354,7 +354,7 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
private void init() {
if (getArguments() == null) return;
final String cookie = settingsHelper.getString(Constants.COOKIE);
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != null;
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) > 0;
final LocationFragmentArgs fragmentArgs = LocationFragmentArgs.fromBundle(getArguments());
locationId = fragmentArgs.getLocationId();
locationDetailsBinding.favChip.setVisibility(View.GONE);
@ -401,8 +401,10 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
locationDetailsBinding.mainLocationImage.setImageURI(locationModel.getSdProfilePic());
final String postCount = String.valueOf(locationModel.getPostCount());
final SpannableStringBuilder span = new SpannableStringBuilder(getResources().getQuantityString(R.plurals.main_posts_count_inline,
locationModel.getPostCount() > 2000000000L ? 2000000000 : locationModel.getPostCount().intValue(),
postCount));
locationModel.getPostCount() > 2000000000L
? 2000000000
: locationModel.getPostCount().intValue(),
postCount));
span.setSpan(new RelativeSizeSpan(1.2f), 0, postCount.length(), 0);
span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0);
locationDetailsBinding.mainLocPostCount.setText(span);
@ -540,7 +542,7 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
private void fetchStories() {
if (isLoggedIn) {
storiesFetching = true;
storiesService.getUserStory(locationId,
storiesService.getUserStory(String.valueOf(locationId),
null,
true,
false,

View File

@ -18,8 +18,6 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.NotificationManagerCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavDirections;
import androidx.navigation.fragment.NavHostFragment;
@ -32,16 +30,14 @@ 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.dialogs.ProfilePicDialogFragment;
import awais.instagrabber.fragments.settings.MorePreferencesFragmentDirections;
import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.models.NotificationModel;
import awais.instagrabber.models.enums.NotificationType;
import awais.instagrabber.repositories.responses.FriendshipRepoChangeRootResponse;
import awais.instagrabber.repositories.responses.FriendshipChangeResponse;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.TextUtils;
@ -63,8 +59,9 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
private NotificationViewModel notificationViewModel;
private FriendshipService friendshipService;
private MediaService mediaService;
private NewsService newsService;
private String userId, csrfToken, type;
private long userId;
private String csrfToken;
private String type;
private Context context;
private final OnNotificationClickListener clickListener = new OnNotificationClickListener() {
@ -79,11 +76,10 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
final NavDirections action = NotificationsViewerFragmentDirections.actionNotificationsViewerFragmentToStoryViewerFragment(
-1, null, false, false, model.getPostId(), model.getUsername(), false, true);
NavHostFragment.findNavController(NotificationsViewerFragment.this).navigate(action);
}
else {
mediaService.fetch(model.getPostId(), new ServiceCallback<FeedModel>() {
} else {
mediaService.fetch(model.getPostId(), new ServiceCallback<Media>() {
@Override
public void onSuccess(final FeedModel feedModel) {
public void onSuccess(final Media feedModel) {
final PostViewV2Fragment fragment = PostViewV2Fragment
.builder(feedModel)
.build();
@ -104,8 +100,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
final String username = model.getUsername();
if (model.getType() == NotificationType.FOLLOW || model.getType() == NotificationType.AYML) {
openProfile(username);
}
else {
} else {
final SpannableString title = new SpannableString(username + (TextUtils.isEmpty(model.getText()) ? "" : (":\n" + model.getText())));
title.setSpan(new RelativeSizeSpan(1.23f), 0, username.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
@ -115,21 +110,18 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
getString(R.string.open_profile),
getString(R.string.view_story)
};
}
else if (model.getPostId() != null) {
} else if (model.getPostId() != null) {
commentDialogList = new String[]{
getString(R.string.open_profile),
getString(R.string.view_post)
};
}
else if (model.getType() == NotificationType.REQUEST) {
} else if (model.getType() == NotificationType.REQUEST) {
commentDialogList = new String[]{
getString(R.string.open_profile),
getString(R.string.request_approve),
getString(R.string.request_reject)
};
}
else commentDialogList = null; // shouldn't happen
} else commentDialogList = null; // shouldn't happen
final Context context = getContext();
if (context == null) return;
final DialogInterface.OnClickListener profileDialogListener = (dialog, which) -> {
@ -139,9 +131,9 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
break;
case 1:
if (model.getType() == NotificationType.REQUEST) {
friendshipService.approve(userId, model.getUserId(), csrfToken, new ServiceCallback<FriendshipRepoChangeRootResponse>() {
friendshipService.approve(userId, model.getUserId(), csrfToken, new ServiceCallback<FriendshipChangeResponse>() {
@Override
public void onSuccess(final FriendshipRepoChangeRootResponse result) {
public void onSuccess(final FriendshipChangeResponse result) {
onRefresh();
Log.e(TAG, "approve: status was not ok!");
}
@ -152,10 +144,10 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
}
});
return;
}
else if (model.getType() == NotificationType.RESPONDED_STORY) {
final NavDirections action = NotificationsViewerFragmentDirections.actionNotificationsViewerFragmentToStoryViewerFragment(
-1, null, false, false, model.getPostId(), model.getUsername(), false, true);
} else if (model.getType() == NotificationType.RESPONDED_STORY) {
final NavDirections action = NotificationsViewerFragmentDirections
.actionNotificationsViewerFragmentToStoryViewerFragment(
-1, null, false, false, model.getPostId(), model.getUsername(), false, true);
NavHostFragment.findNavController(NotificationsViewerFragment.this).navigate(action);
return;
}
@ -164,9 +156,9 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
.setView(R.layout.dialog_opening_post)
.create();
alertDialog.show();
mediaService.fetch(model.getPostId(), new ServiceCallback<FeedModel>() {
mediaService.fetch(model.getPostId(), new ServiceCallback<Media>() {
@Override
public void onSuccess(final FeedModel feedModel) {
public void onSuccess(final Media feedModel) {
final PostViewV2Fragment fragment = PostViewV2Fragment
.builder(feedModel)
.build();
@ -181,9 +173,9 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
});
break;
case 2:
friendshipService.ignore(userId, model.getUserId(), csrfToken, new ServiceCallback<FriendshipRepoChangeRootResponse>() {
friendshipService.ignore(userId, model.getUserId(), csrfToken, new ServiceCallback<FriendshipChangeResponse>() {
@Override
public void onSuccess(final FriendshipRepoChangeRootResponse result) {
public void onSuccess(final FriendshipChangeResponse result) {
onRefresh();
}
@ -283,7 +275,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
break;
case "ayml":
newsService = NewsService.getInstance();
final NewsService newsService = NewsService.getInstance();
newsService.fetchSuggestions(csrfToken, new ServiceCallback<List<NotificationModel>>() {
@Override
public void onSuccess(final List<NotificationModel> notificationModels) {

View File

@ -61,7 +61,7 @@ import com.google.android.material.snackbar.BaseTransientBottomBar;
import com.google.android.material.snackbar.Snackbar;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import awais.instagrabber.R;
import awais.instagrabber.activities.MainActivity;
@ -74,14 +74,17 @@ import awais.instagrabber.customviews.VideoPlayerCallbackAdapter;
import awais.instagrabber.customviews.VideoPlayerViewHelper;
import awais.instagrabber.customviews.drawee.AnimatedZoomableController;
import awais.instagrabber.databinding.DialogPostViewBinding;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.models.PostChild;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.repositories.responses.Caption;
import awais.instagrabber.repositories.responses.Location;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.VideoVersion;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.DownloadUtils;
import awais.instagrabber.utils.NumberUtils;
import awais.instagrabber.utils.ResponseBodyUtils;
import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.utils.Utils;
import awais.instagrabber.webservices.MediaService;
@ -100,10 +103,9 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
private static final String ARG_SLIDER_POSITION = "position";
private static final int STORAGE_PERM_REQUEST_CODE = 8020;
private FeedModel feedModel;
private Media feedModel;
private View sharedProfilePicElement;
private View sharedMainPostElement;
private MainActivity fragmentActivity;
private DialogPostViewBinding binding;
private MediaService mediaService;
private Context context;
@ -166,7 +168,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
}
public static class Builder {
private final FeedModel feedModel;
private final Media feedModel;
private View profilePicElement;
private View mainPostElement;
private int position;
@ -190,12 +192,12 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
return PostViewV2Fragment.newInstance(feedModel, profilePicElement, mainPostElement, position);
}
public Builder(final FeedModel feedModel) {
public Builder(final Media feedModel) {
this.feedModel = feedModel;
}
}
private static PostViewV2Fragment newInstance(final FeedModel feedModel,
private static PostViewV2Fragment newInstance(final Media feedModel,
final View profilePicElement,
final View mainPostElement,
final int position) {
@ -209,7 +211,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
return f;
}
public static Builder builder(final FeedModel feedModel) {
public static Builder builder(final Media feedModel) {
return new Builder(feedModel);
}
@ -226,7 +228,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
public void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_FRAME, R.style.PostViewV2Style);
fragmentActivity = (MainActivity) getActivity();
final MainActivity fragmentActivity = (MainActivity) getActivity();
mediaService = MediaService.getInstance();
final Bundle arguments = getArguments();
if (arguments == null) return;
@ -235,12 +237,12 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
Log.e(TAG, "onCreate: feedModelSerializable is null");
return;
}
if (!(feedModelSerializable instanceof FeedModel)) {
if (!(feedModelSerializable instanceof Media)) {
return;
}
feedModel = (FeedModel) feedModelSerializable;
feedModel = (Media) feedModelSerializable;
if (feedModel == null) return;
if (feedModel.getItemType() == MediaItemType.MEDIA_TYPE_SLIDER) {
if (feedModel.getMediaType() == MediaItemType.MEDIA_TYPE_SLIDER) {
sliderPosition = arguments.getInt(ARG_SLIDER_POSITION, 0);
}
}
@ -312,7 +314,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
public void onDestroyView() {
super.onDestroyView();
if (feedModel == null) return;
switch (feedModel.getItemType()) {
switch (feedModel.getMediaType()) {
case MEDIA_TYPE_VIDEO:
if (videoPlayerViewHelper != null) {
videoPlayerViewHelper.releasePlayer();
@ -330,7 +332,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
public void onSaveInstanceState(@NonNull final Bundle outState) {
super.onSaveInstanceState(outState);
if (feedModel == null) return;
if (feedModel.getItemType() == MediaItemType.MEDIA_TYPE_SLIDER) {
if (feedModel.getMediaType() == MediaItemType.MEDIA_TYPE_SLIDER) {
outState.putInt(ARG_SLIDER_POSITION, sliderPosition);
}
}
@ -420,7 +422,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
private void init() {
if (feedModel == null) return;
isLoggedIn = !TextUtils.isEmpty(COOKIE) && CookieUtils.getUserIdFromCookie(COOKIE) != null;
isLoggedIn = !TextUtils.isEmpty(COOKIE) && CookieUtils.getUserIdFromCookie(COOKIE) > 0;
if (!wasPaused && (sharedProfilePicElement != null || sharedMainPostElement != null)) {
binding.getRoot().getBackground().mutate().setAlpha(0);
}
@ -441,14 +443,14 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
private void setupComment() {
binding.comment.setOnClickListener(v -> {
final ProfileModel profileModel = feedModel.getProfileModel();
final User profileModel = feedModel.getUser();
if (profileModel == null) return;
final NavController navController = getNavController();
if (navController == null) return;
final Bundle bundle = new Bundle();
bundle.putString("shortCode", feedModel.getShortCode());
bundle.putString("postId", feedModel.getPostId());
bundle.putString("postUserId", profileModel.getId());
bundle.putString("shortCode", feedModel.getCode());
bundle.putString("postId", feedModel.getPk());
bundle.putLong("postUserId", profileModel.getPk());
navController.navigate(R.id.action_global_commentsViewerFragment, bundle);
});
binding.comment.setOnLongClickListener(v -> {
@ -477,23 +479,23 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
return;
}
if (mediaService == null) return;
setLikedResources(feedModel.getLike());
setLikedResources(feedModel.hasLiked());
final ServiceCallback<Boolean> likeCallback = new ServiceCallback<Boolean>() {
@Override
public void onSuccess(final Boolean result) {
binding.like.setEnabled(true);
if (result) {
setLikedResources(!feedModel.getLike());
final long currentLikesCount = feedModel.getLikesCount();
setLikedResources(!feedModel.hasLiked());
final long currentLikesCount = feedModel.getLikeCount();
final long updatedCount;
if (!feedModel.getLike()) {
if (!feedModel.hasLiked()) {
updatedCount = currentLikesCount + 1;
feedModel.setLiked(true);
feedModel.setHasLiked(true);
} else {
updatedCount = currentLikesCount - 1;
feedModel.setLiked(false);
feedModel.setHasLiked(false);
}
feedModel.setLikesCount(updatedCount);
feedModel.setLikeCount(updatedCount);
setupCounts();
return;
}
@ -509,21 +511,21 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
private void unsuccessfulLike() {
final int errorTextResId;
if (!feedModel.getLike()) {
if (!feedModel.hasLiked()) {
Log.e(TAG, "like unsuccessful!");
errorTextResId = R.string.like_unsuccessful;
} else {
Log.e(TAG, "unlike unsuccessful!");
errorTextResId = R.string.unlike_unsuccessful;
}
setLikedResources(feedModel.getLike());
setLikedResources(feedModel.hasLiked());
final Snackbar snackbar = Snackbar.make(binding.getRoot(), errorTextResId, BaseTransientBottomBar.LENGTH_INDEFINITE);
snackbar.setAction(R.string.ok, null);
snackbar.show();
}
};
binding.like.setOnClickListener(v -> {
final String userId = CookieUtils.getUserIdFromCookie(COOKIE);
final long userId = CookieUtils.getUserIdFromCookie(COOKIE);
final String csrfToken = CookieUtils.getCsrfTokenFromCookie(COOKIE);
v.setEnabled(false);
// final int textRes;
@ -532,17 +534,17 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
// } else {
// textRes = R.string.unliking;
// }
if (!feedModel.getLike()) {
mediaService.like(feedModel.getPostId(), userId, csrfToken, likeCallback);
if (!feedModel.hasLiked()) {
mediaService.like(feedModel.getPk(), userId, csrfToken, likeCallback);
} else {
mediaService.unlike(feedModel.getPostId(), userId, csrfToken, likeCallback);
mediaService.unlike(feedModel.getPk(), userId, csrfToken, likeCallback);
}
});
binding.like.setOnLongClickListener(v -> {
final NavController navController = getNavController();
if (navController != null && isLoggedIn) {
final Bundle bundle = new Bundle();
bundle.putString("postId", feedModel.getPostId());
bundle.putString("postId", feedModel.getPk());
bundle.putBoolean("isComment", false);
navController.navigate(R.id.action_global_likesViewerFragment, bundle);
} else {
@ -576,14 +578,14 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
return;
}
if (mediaService == null) return;
setSavedResources(feedModel.isSaved());
setSavedResources(feedModel.hasViewerSaved());
final ServiceCallback<Boolean> saveCallback = new ServiceCallback<Boolean>() {
@Override
public void onSuccess(final Boolean result) {
binding.save.setEnabled(true);
if (result) {
setSavedResources(!feedModel.isSaved());
feedModel.setSaved(!feedModel.isSaved());
setSavedResources(!feedModel.hasViewerSaved());
feedModel.setHasViewerSaved(!feedModel.hasViewerSaved());
return;
}
unsuccessfulSave();
@ -591,14 +593,14 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
private void unsuccessfulSave() {
final int errorTextResId;
if (!feedModel.isSaved()) {
if (!feedModel.hasViewerSaved()) {
Log.e(TAG, "save unsuccessful!");
errorTextResId = R.string.save_unsuccessful;
} else {
Log.e(TAG, "save remove unsuccessful!");
errorTextResId = R.string.save_remove_unsuccessful;
}
setSavedResources(feedModel.isSaved());
setSavedResources(feedModel.hasViewerSaved());
final Snackbar snackbar = Snackbar.make(binding.getRoot(), errorTextResId, BaseTransientBottomBar.LENGTH_INDEFINITE);
snackbar.setAction(R.string.ok, null);
snackbar.show();
@ -612,7 +614,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
}
};
binding.save.setOnClickListener(v -> {
final String userId = CookieUtils.getUserIdFromCookie(COOKIE);
final long userId = CookieUtils.getUserIdFromCookie(COOKIE);
final String csrfToken = CookieUtils.getCsrfTokenFromCookie(COOKIE);
binding.save.setEnabled(false);
// final int textRes;
@ -621,10 +623,10 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
// } else {
// textRes = R.string.removing;
// }
if (!feedModel.isSaved()) {
mediaService.save(feedModel.getPostId(), userId, csrfToken, saveCallback);
if (!feedModel.hasViewerSaved()) {
mediaService.save(feedModel.getPk(), userId, csrfToken, saveCallback);
} else {
mediaService.unsave(feedModel.getPostId(), userId, csrfToken, saveCallback);
mediaService.unsave(feedModel.getPk(), userId, csrfToken, saveCallback);
}
});
binding.save.setOnLongClickListener(v -> {
@ -655,12 +657,12 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
if (!wasPaused && sharedProfilePicElement != null) {
addSharedElement(sharedProfilePicElement, binding.profilePic);
}
final ProfileModel profileModel = feedModel.getProfileModel();
final User profileModel = feedModel.getUser();
if (profileModel == null) {
binding.profilePic.setVisibility(View.GONE);
return;
}
final String uri = profileModel.getSdProfilePic();
final String uri = profileModel.getProfilePicUrl();
final ImageRequest requestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(uri)).build();
final DraweeController controller = Fresco
.newDraweeControllerBuilder()
@ -685,7 +687,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
}
private void setupTitles() {
final ProfileModel profileModel = feedModel.getProfileModel();
final User profileModel = feedModel.getUser();
if (profileModel == null) {
binding.title.setVisibility(View.GONE);
binding.righttitle.setVisibility(View.GONE);
@ -693,11 +695,12 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
return;
}
binding.title.setText(profileModel.getUsername());
binding.righttitle.setText(profileModel.getName());
binding.righttitle.setText(profileModel.getFullName());
binding.isVerified.setVisibility(profileModel.isVerified() ? View.VISIBLE : View.GONE);
binding.title.setOnClickListener(v -> navigateToProfile("@" + profileModel.getUsername()));
binding.righttitle.setOnClickListener(v -> navigateToProfile("@" + profileModel.getUsername()));
final String locationName = feedModel.getLocationName();
final Location location = feedModel.getLocation();
final String locationName = location != null ? location.getName() : "";
if (!TextUtils.isEmpty(locationName)) {
binding.subtitle.setText(locationName);
binding.subtitle.setVisibility(View.VISIBLE);
@ -705,7 +708,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
final NavController navController = getNavController();
if (navController == null) return;
final Bundle bundle = new Bundle();
bundle.putString("locationId", feedModel.getLocationId());
bundle.putLong("locationId", location.getPk());
navController.navigate(R.id.action_global_locationFragment, bundle);
});
return;
@ -714,15 +717,17 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
}
private void setupCaption() {
postCaption = feedModel.getPostCaption();
binding.date.setText(Utils.datetimeParser.format(new Date(feedModel.getTimestamp() * 1000L)));
if (!feedModel.getProfileModel().getId().equals(CookieUtils.getUserIdFromCookie(COOKIE)) && TextUtils.isEmpty(postCaption)) {
final Caption caption = feedModel.getCaption();
postCaption = caption != null ? caption.getText() : null;
binding.date.setText(feedModel.getDate());
final long userId = CookieUtils.getUserIdFromCookie(COOKIE);
if (feedModel.getUser().getPk() != userId && TextUtils.isEmpty(postCaption)) {
binding.caption.setVisibility(View.GONE);
binding.translateTitle.setVisibility(View.GONE);
binding.captionToggle.setVisibility(View.GONE);
return;
}
if (feedModel.getProfileModel().getId().equals(CookieUtils.getUserIdFromCookie(COOKIE))) {
if (feedModel.getUser().getPk() == userId) {
binding.editCaption.setVisibility(View.VISIBLE);
binding.editCaption.setOnClickListener(v -> {
final EditText input = new EditText(context);
@ -733,8 +738,8 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
.setPositiveButton(R.string.confirm, (d, w) -> {
binding.editCaption.setVisibility(View.GONE);
mediaService.editCaption(
feedModel.getPostId(),
CookieUtils.getUserIdFromCookie(COOKIE),
feedModel.getPk(),
userId,
input.getText().toString(),
CookieUtils.getCsrfTokenFromCookie(COOKIE),
new ServiceCallback<Boolean>() {
@ -793,10 +798,10 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) return;
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
});
if (TextUtils.isEmpty(feedModel.getCaptionId()))
if (caption.getPk() <= 0)
binding.translateTitle.setVisibility(View.GONE);
else binding.translateTitle.setOnClickListener(v -> {
mediaService.translate(feedModel.getCaptionId(), "1", new ServiceCallback<String>() {
mediaService.translate(String.valueOf(caption.getPk()), "1", new ServiceCallback<String>() {
@Override
public void onSuccess(final String result) {
if (TextUtils.isEmpty(result)) {
@ -854,14 +859,14 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
return true;
});
binding.share.setOnClickListener(v -> {
final ProfileModel profileModel = feedModel.getProfileModel();
final User profileModel = feedModel.getUser();
if (profileModel == null) return;
final boolean isPrivate = profileModel.isPrivate();
if (isPrivate)
Toast.makeText(context, R.string.share_private_post, Toast.LENGTH_LONG).show();
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "https://instagram.com/p/" + feedModel.getShortCode());
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "https://instagram.com/p/" + feedModel.getCode());
startActivity(Intent.createChooser(sharingIntent,
isPrivate ? getString(R.string.share_private_post) : getString(R.string.share_public_post)));
});
@ -869,17 +874,17 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
private void setupCounts() {
try {
final int commentsCount = (int) feedModel.getCommentsCount();
final String commentsString = getResources().getQuantityString(R.plurals.comments_count, commentsCount, commentsCount);
final long commentsCount = (int) feedModel.getCommentCount();
final String commentsString = getResources().getQuantityString(R.plurals.comments_count, (int) commentsCount, (int) commentsCount);
binding.commentsCount.setText(commentsString);
final int likesCount = (int) feedModel.getLikesCount();
final int likesCount = (int) feedModel.getLikeCount();
final String likesString = getResources().getQuantityString(R.plurals.likes_count, likesCount, likesCount);
binding.likesCount.setText(likesString);
} catch (IllegalStateException ignored) {}
}
private void setupPostTypeLayout() {
switch (feedModel.getItemType()) {
switch (feedModel.getMediaType()) {
case MEDIA_TYPE_IMAGE:
setupPostImage();
break;
@ -904,12 +909,12 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
binding.postImage.getHierarchy().setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP);
addSharedElement(sharedMainPostElement, binding.postImage);
}
final ImageRequest requestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(feedModel.getDisplayUrl()))
final ImageRequest requestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(ResponseBodyUtils.getImageUrl(feedModel)))
.setLocalThumbnailPreviewsEnabled(true)
.build();
final DraweeController controller = Fresco
.newDraweeControllerBuilder()
.setLowResImageRequest(ImageRequest.fromUri(feedModel.getThumbnailUrl()))
.setLowResImageRequest(ImageRequest.fromUri(ResponseBodyUtils.getThumbUrl(feedModel)))
.setImageRequest(requestBuilder)
.setControllerListener(new BaseControllerListener<ImageInfo>() {
@Override
@ -951,13 +956,13 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
if (!wasPaused && sharedMainPostElement != null) {
addSharedElement(sharedMainPostElement, binding.sliderParent);
}
final boolean hasVideo = feedModel.getSliderItems()
final boolean hasVideo = feedModel.getCarouselMedia()
.stream()
.anyMatch(postChild -> postChild.getItemType() == MediaItemType.MEDIA_TYPE_VIDEO);
.anyMatch(postChild -> postChild.getMediaType() == MediaItemType.MEDIA_TYPE_VIDEO);
if (hasVideo) {
final View child = binding.sliderParent.getChildAt(0);
if (child instanceof RecyclerView) {
((RecyclerView) child).setItemViewCacheSize(feedModel.getSliderItems().size());
((RecyclerView) child).setItemViewCacheSize(feedModel.getCarouselMedia().size());
((RecyclerView) child).addRecyclerListener(holder -> {
if (holder instanceof SliderVideoViewHolder) {
((SliderVideoViewHolder) holder).releasePlayer();
@ -990,7 +995,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
}
});
binding.sliderParent.setAdapter(sliderItemsAdapter);
if (sliderPosition >= 0 && sliderPosition < feedModel.getSliderItems().size()) {
if (sliderPosition >= 0 && sliderPosition < feedModel.getCarouselMedia().size()) {
binding.sliderParent.setCurrentItem(sliderPosition);
}
binding.sliderParent.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
@ -1012,12 +1017,12 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
@Override
public void onPageSelected(final int position) {
final int size = feedModel.getSliderItems().size();
final int size = feedModel.getCarouselMedia().size();
if (position < 0 || position >= size) return;
sliderPosition = position;
final String text = (position + 1) + "/" + size;
binding.mediaCounter.setText(text);
final PostChild postChild = feedModel.getSliderItems().get(position);
final Media postChild = feedModel.getCarouselMedia().get(position);
final View view = binding.sliderParent.getChildAt(0);
if (prevPosition != -1) {
if (view instanceof RecyclerView) {
@ -1027,7 +1032,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
}
}
}
if (postChild.getItemType() == MediaItemType.MEDIA_TYPE_VIDEO) {
if (postChild.getMediaType() == MediaItemType.MEDIA_TYPE_VIDEO) {
if (view instanceof RecyclerView) {
final RecyclerView.ViewHolder viewHolder = ((RecyclerView) view).findViewHolderForAdapterPosition(position);
if (viewHolder instanceof SliderVideoViewHolder) {
@ -1047,9 +1052,9 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
}
}
});
final String text = "1/" + feedModel.getSliderItems().size();
final String text = "1/" + feedModel.getCarouselMedia().size();
binding.mediaCounter.setText(text);
sliderItemsAdapter.submitList(feedModel.getSliderItems());
sliderItemsAdapter.submitList(feedModel.getCarouselMedia());
}
private void releaseAllSliderPlayers() {
@ -1078,8 +1083,8 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
binding.videoPost.root.setVisibility(View.VISIBLE);
final VerticalDragHelper thumbnailVerticalDragHelper = new VerticalDragHelper(binding.videoPost.thumbnailParent);
final VerticalDragHelper playerVerticalDragHelper = new VerticalDragHelper(binding.videoPost.playerView);
thumbnailVerticalDragHelper.setOnVerticalDragListener(onVerticalDragListener);
playerVerticalDragHelper.setOnVerticalDragListener(onVerticalDragListener);
// thumbnailVerticalDragHelper.setOnVerticalDragListener(onVerticalDragListener);
// playerVerticalDragHelper.setOnVerticalDragListener(onVerticalDragListener);
enablePlayerControls(true);
binding.videoPost.thumbnailParent.setOnTouchListener((v, event) -> {
final boolean onDragTouch = thumbnailVerticalDragHelper.onDragTouch(event);
@ -1108,7 +1113,8 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
binding.playerControls.getRoot().setVisibility(View.VISIBLE);
final ViewGroup.LayoutParams layoutParams = binding.videoPost.playerView.getLayoutParams();
final int requiredWidth = Utils.displayMetrics.widthPixels;
final int resultingHeight = NumberUtils.getResultingHeight(requiredWidth, feedModel.getImageHeight(), feedModel.getImageWidth());
final int resultingHeight = NumberUtils
.getResultingHeight(requiredWidth, feedModel.getOriginalHeight(), feedModel.getOriginalWidth());
layoutParams.width = requiredWidth;
layoutParams.height = resultingHeight;
binding.videoPost.playerView.requestLayout();
@ -1121,14 +1127,22 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
}
}
};
final float aspectRatio = (float) feedModel.getImageWidth() / feedModel.getImageHeight();
final float aspectRatio = (float) feedModel.getOriginalWidth() / feedModel.getOriginalHeight();
String videoUrl = null;
final List<VideoVersion> videoVersions = feedModel.getVideoVersions();
if (videoVersions != null && !videoVersions.isEmpty()) {
final VideoVersion videoVersion = videoVersions.get(0);
if (videoVersion != null) {
videoUrl = videoVersion.getUrl();
}
}
videoPlayerViewHelper = new VideoPlayerViewHelper(
binding.getRoot().getContext(),
binding.videoPost,
feedModel.getDisplayUrl(),
videoUrl,
vol,
aspectRatio,
feedModel.getThumbnailUrl(),
ResponseBodyUtils.getThumbUrl(feedModel),
true,
binding.playerControls,
videoPlayerCallback);
@ -1255,8 +1269,8 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
}
binding.profilePic.setVisibility(View.VISIBLE);
binding.title.setVisibility(View.VISIBLE);
binding.isVerified.setVisibility(feedModel.getProfileModel() != null
? feedModel.getProfileModel().isVerified() ? View.VISIBLE : View.GONE
binding.isVerified.setVisibility(feedModel.getUser() != null
? feedModel.getUser().isVerified() ? View.VISIBLE : View.GONE
: View.GONE);
binding.righttitle.setVisibility(View.VISIBLE);
binding.topBg.setVisibility(View.VISIBLE);
@ -1282,7 +1296,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
if (wasControlsVisible) {
showPlayerControls();
}
if (feedModel.getItemType() == MediaItemType.MEDIA_TYPE_SLIDER) {
if (feedModel.getMediaType() == MediaItemType.MEDIA_TYPE_SLIDER) {
binding.mediaCounter.setVisibility(View.VISIBLE);
}
detailsVisible = true;

View File

@ -36,9 +36,9 @@ import awais.instagrabber.customviews.PrimaryActionModeCallback;
import awais.instagrabber.databinding.FragmentSavedBinding;
import awais.instagrabber.dialogs.PostsLayoutPreferencesDialogFragment;
import awais.instagrabber.fragments.main.ProfileFragmentDirections;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.models.PostsLayoutPreferences;
import awais.instagrabber.models.enums.PostItemType;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.DownloadUtils;
@ -54,14 +54,15 @@ public final class SavedViewerFragment extends Fragment implements SwipeRefreshL
private static final int STORAGE_PERM_REQUEST_CODE_FOR_SELECTION = 8030;
private FragmentSavedBinding binding;
private String username, cookie, profileId;
private String username;
private long profileId;
private ActionMode actionMode;
private SwipeRefreshLayout root;
private AppCompatActivity fragmentActivity;
private boolean isLoggedIn, shouldRefresh = true;
private PostItemType type;
private Set<FeedModel> selectedFeedModels;
private FeedModel downloadFeedModel;
private Set<Media> selectedFeedModels;
private Media downloadFeedModel;
private int downloadChildPosition = -1;
private PostsLayoutPreferences layoutPreferences;
@ -97,27 +98,27 @@ public final class SavedViewerFragment extends Fragment implements SwipeRefreshL
});
private final FeedAdapterV2.FeedItemCallback feedItemCallback = new FeedAdapterV2.FeedItemCallback() {
@Override
public void onPostClick(final FeedModel feedModel, final View profilePicView, final View mainPostImage) {
public void onPostClick(final Media feedModel, final View profilePicView, final View mainPostImage) {
openPostDialog(feedModel, profilePicView, mainPostImage, -1);
}
@Override
public void onSliderClick(final FeedModel feedModel, final int position) {
public void onSliderClick(final Media feedModel, final int position) {
openPostDialog(feedModel, null, null, position);
}
@Override
public void onCommentsClick(final FeedModel feedModel) {
public void onCommentsClick(final Media feedModel) {
final NavDirections commentsAction = ProfileFragmentDirections.actionGlobalCommentsViewerFragment(
feedModel.getShortCode(),
feedModel.getPostId(),
feedModel.getProfileModel().getId()
feedModel.getCode(),
feedModel.getPk(),
feedModel.getUser().getPk()
);
NavHostFragment.findNavController(SavedViewerFragment.this).navigate(commentsAction);
}
@Override
public void onDownloadClick(final FeedModel feedModel, final int childPosition) {
public void onDownloadClick(final Media feedModel, final int childPosition) {
final Context context = getContext();
if (context == null) return;
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
@ -136,8 +137,8 @@ public final class SavedViewerFragment extends Fragment implements SwipeRefreshL
}
@Override
public void onLocationClick(final FeedModel feedModel) {
final NavDirections action = ProfileFragmentDirections.actionGlobalLocationFragment(feedModel.getLocationId());
public void onLocationClick(final Media feedModel) {
final NavDirections action = ProfileFragmentDirections.actionGlobalLocationFragment(feedModel.getLocation().getPk());
NavHostFragment.findNavController(SavedViewerFragment.this).navigate(action);
}
@ -147,13 +148,13 @@ public final class SavedViewerFragment extends Fragment implements SwipeRefreshL
}
@Override
public void onNameClick(final FeedModel feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getProfileModel().getUsername());
public void onNameClick(final Media feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getUser().getUsername());
}
@Override
public void onProfilePicClick(final FeedModel feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getProfileModel().getUsername());
public void onProfilePicClick(final Media feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getUser().getUsername());
}
@Override
@ -166,7 +167,7 @@ public final class SavedViewerFragment extends Fragment implements SwipeRefreshL
Utils.openEmailAddress(getContext(), emailId);
}
private void openPostDialog(final FeedModel feedModel,
private void openPostDialog(final Media feedModel,
final View profilePicView,
final View mainPostImage,
final int position) {
@ -197,7 +198,7 @@ public final class SavedViewerFragment extends Fragment implements SwipeRefreshL
}
@Override
public void onSelectionChange(final Set<FeedModel> selectedFeedModels) {
public void onSelectionChange(final Set<Media> selectedFeedModels) {
final String title = getString(R.string.number_selected, selectedFeedModels.size());
if (actionMode != null) {
actionMode.setTitle(title);
@ -227,8 +228,8 @@ public final class SavedViewerFragment extends Fragment implements SwipeRefreshL
@Override
public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) {
cookie = settingsHelper.getString(Constants.COOKIE);
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != null;
final String cookie = settingsHelper.getString(Constants.COOKIE);
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) > 0;
if (root != null) {
shouldRefresh = false;
return root;

View File

@ -29,21 +29,16 @@ import awais.instagrabber.adapters.HighlightStoriesListAdapter;
import awais.instagrabber.adapters.HighlightStoriesListAdapter.OnHighlightStoryClickListener;
import awais.instagrabber.customviews.helpers.RecyclerLazyLoader;
import awais.instagrabber.databinding.FragmentStoryListViewerBinding;
import awais.instagrabber.fragments.main.FeedFragment;
import awais.instagrabber.fragments.settings.MorePreferencesFragmentDirections;
import awais.instagrabber.models.FeedStoryModel;
import awais.instagrabber.models.HighlightModel;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.viewmodels.FeedStoriesViewModel;
import awais.instagrabber.viewmodels.ArchivesViewModel;
import awais.instagrabber.viewmodels.FeedStoriesViewModel;
import awais.instagrabber.webservices.ServiceCallback;
import awais.instagrabber.webservices.StoriesService;
import awais.instagrabber.webservices.StoriesService.ArchiveFetchResponse;
import static awais.instagrabber.utils.Utils.settingsHelper;
public final class StoryListViewerFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
private static final String TAG = "StoryListViewerFragment";
@ -56,14 +51,14 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr
private StoriesService storiesService;
private Context context;
private String type, endCursor = null;
private RecyclerLazyLoader lazyLoader;
private FeedStoriesListAdapter adapter;
private final OnFeedStoryClickListener clickListener = new OnFeedStoryClickListener() {
@Override
public void onFeedStoryClick(final FeedStoryModel model, final int position) {
if (model == null) return;
final NavDirections action = StoryListViewerFragmentDirections.actionStoryListFragmentToStoryViewerFragment(position, null, false, false, null, null, false, false);
final NavDirections action = StoryListViewerFragmentDirections
.actionStoryListFragmentToStoryViewerFragment(position, null, false, false, null, null, false, false);
NavHostFragment.findNavController(StoryListViewerFragment.this).navigate(action);
}
@ -105,8 +100,7 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr
try {
final Context context = getContext();
Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show();
}
catch (Exception e) {}
} catch (Exception ignored) {}
}
};
@ -142,7 +136,7 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr
public void onResume() {
super.onResume();
final ActionBar actionBar = fragmentActivity.getSupportActionBar();
if (actionBar != null) actionBar.setTitle(type == "feed" ? R.string.feed_stories : R.string.action_archive);
if (actionBar != null) actionBar.setTitle(type.equals("feed") ? R.string.feed_stories : R.string.action_archive);
}
@Override
@ -159,17 +153,16 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr
binding.swipeRefreshLayout.setOnRefreshListener(this);
final LinearLayoutManager layoutManager = new LinearLayoutManager(context);
final ActionBar actionBar = fragmentActivity.getSupportActionBar();
if (type == "feed") {
if (type.equals("feed")) {
if (actionBar != null) actionBar.setTitle(R.string.feed_stories);
feedStoriesViewModel = new ViewModelProvider(fragmentActivity).get(FeedStoriesViewModel.class);
adapter = new FeedStoriesListAdapter(clickListener);
binding.rvStories.setLayoutManager(layoutManager);
binding.rvStories.setAdapter(adapter);
feedStoriesViewModel.getList().observe(getViewLifecycleOwner(), adapter::submitList);
}
else {
} else {
if (actionBar != null) actionBar.setTitle(R.string.action_archive);
lazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> {
final RecyclerLazyLoader lazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> {
if (!TextUtils.isEmpty(endCursor)) onRefresh();
endCursor = null;
});
@ -186,14 +179,12 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr
@Override
public void onRefresh() {
binding.swipeRefreshLayout.setRefreshing(true);
if (type == "feed" && firstRefresh) {
if (type.equals("feed") && firstRefresh) {
binding.swipeRefreshLayout.setRefreshing(false);
adapter.submitList(feedStoriesViewModel.getList().getValue());
firstRefresh = false;
}
else if (type == "feed") {
final String cookie = settingsHelper.getString(Constants.COOKIE);
storiesService.getFeedStories(CookieUtils.getCsrfTokenFromCookie(cookie), new ServiceCallback<List<FeedStoryModel>>() {
} else if (type.equals("feed")) {
storiesService.getFeedStories(new ServiceCallback<List<FeedStoryModel>>() {
@Override
public void onSuccess(final List<FeedStoryModel> result) {
feedStoriesViewModel.getList().postValue(result);
@ -206,8 +197,7 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr
Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
else if (type == "archive") {
} else if (type.equals("archive")) {
storiesService.fetchArchive(endCursor, cb);
}
}

View File

@ -146,7 +146,7 @@ public class StoryViewerFragment extends Fragment {
private final String cookie = settingsHelper.getString(Constants.COOKIE);
private final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
private final String userIdFromCookie = CookieUtils.getUserIdFromCookie(cookie);
private final long userIdFromCookie = CookieUtils.getUserIdFromCookie(cookie);
private final String deviceId = settingsHelper.getString(Constants.DEVICE_UUID);
@Override
@ -214,7 +214,7 @@ public class StoryViewerFragment extends Fragment {
.broadcastStoryReply(BroadcastOptions.ThreadIdOrUserIds.of(threadId),
input.getText().toString(),
currentStory.getStoryMediaId(),
currentStory.getUserId());
String.valueOf(currentStory.getUserId()));
request.enqueue(new Callback<DirectThreadBroadcastResponse>() {
@Override
public void onResponse(@NonNull final Call<DirectThreadBroadcastResponse> call,
@ -682,8 +682,8 @@ public class StoryViewerFragment extends Fragment {
currentStoryMediaId = model.getStoryMediaId();
currentStoryUsername = model.getProfileModel().getUsername();
}
} else if (!TextUtils.isEmpty(fragmentArgs.getProfileId()) && !TextUtils.isEmpty(fragmentArgs.getUsername())) {
currentStoryMediaId = fragmentArgs.getProfileId();
} else if (fragmentArgs.getProfileId() > 0 && !TextUtils.isEmpty(fragmentArgs.getUsername())) {
currentStoryMediaId = String.valueOf(fragmentArgs.getProfileId());
currentStoryUsername = fragmentArgs.getUsername();
}
isHashtag = fragmentArgs.getIsHashtag();
@ -965,7 +965,8 @@ public class StoryViewerFragment extends Fragment {
final NavDirections action = HashTagFragmentDirections.actionGlobalHashTagFragment(username.substring(1));
NavHostFragment.findNavController(this).navigate(action);
} else {
final NavDirections action = ProfileFragmentDirections.actionGlobalLocationFragment(username.split(" \\(")[1].replace(")", ""));
final NavDirections action = ProfileFragmentDirections
.actionGlobalLocationFragment(Long.parseLong(username.split(" \\(")[1].replace(")", "")));
NavHostFragment.findNavController(this).navigate(action);
}
}

View File

@ -50,11 +50,12 @@ import awais.instagrabber.customviews.PrimaryActionModeCallback;
import awais.instagrabber.databinding.FragmentTopicPostsBinding;
import awais.instagrabber.dialogs.PostsLayoutPreferencesDialogFragment;
import awais.instagrabber.fragments.main.DiscoverFragmentDirections;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.models.PostsLayoutPreferences;
import awais.instagrabber.models.TopicCluster;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.DownloadUtils;
import awais.instagrabber.utils.ResponseBodyUtils;
import awais.instagrabber.utils.Utils;
import awais.instagrabber.webservices.DiscoverService;
@ -71,8 +72,8 @@ public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.O
private boolean shouldRefresh = true;
private TopicCluster topicCluster;
private ActionMode actionMode;
private Set<FeedModel> selectedFeedModels;
private FeedModel downloadFeedModel;
private Set<Media> selectedFeedModels;
private Media downloadFeedModel;
private int downloadChildPosition = -1;
private PostsLayoutPreferences layoutPreferences = Utils.getPostsLayoutPreferences(Constants.PREF_TOPIC_POSTS_LAYOUT);
@ -108,27 +109,27 @@ public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.O
});
private final FeedAdapterV2.FeedItemCallback feedItemCallback = new FeedAdapterV2.FeedItemCallback() {
@Override
public void onPostClick(final FeedModel feedModel, final View profilePicView, final View mainPostImage) {
public void onPostClick(final Media feedModel, final View profilePicView, final View mainPostImage) {
openPostDialog(feedModel, profilePicView, mainPostImage, -1);
}
@Override
public void onSliderClick(final FeedModel feedModel, final int position) {
public void onSliderClick(final Media feedModel, final int position) {
openPostDialog(feedModel, null, null, position);
}
@Override
public void onCommentsClick(final FeedModel feedModel) {
public void onCommentsClick(final Media feedModel) {
final NavDirections commentsAction = DiscoverFragmentDirections.actionGlobalCommentsViewerFragment(
feedModel.getShortCode(),
feedModel.getPostId(),
feedModel.getProfileModel().getId()
feedModel.getCode(),
feedModel.getPk(),
feedModel.getUser().getPk()
);
NavHostFragment.findNavController(TopicPostsFragment.this).navigate(commentsAction);
}
@Override
public void onDownloadClick(final FeedModel feedModel, final int childPosition) {
public void onDownloadClick(final Media feedModel, final int childPosition) {
final Context context = getContext();
if (context == null) return;
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
@ -147,8 +148,8 @@ public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.O
}
@Override
public void onLocationClick(final FeedModel feedModel) {
final NavDirections action = DiscoverFragmentDirections.actionGlobalLocationFragment(feedModel.getLocationId());
public void onLocationClick(final Media feedModel) {
final NavDirections action = DiscoverFragmentDirections.actionGlobalLocationFragment(feedModel.getLocation().getPk());
NavHostFragment.findNavController(TopicPostsFragment.this).navigate(action);
}
@ -158,13 +159,13 @@ public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.O
}
@Override
public void onNameClick(final FeedModel feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getProfileModel().getUsername());
public void onNameClick(final Media feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getUser().getUsername());
}
@Override
public void onProfilePicClick(final FeedModel feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getProfileModel().getUsername());
public void onProfilePicClick(final Media feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getUser().getUsername());
}
@Override
@ -177,7 +178,7 @@ public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.O
Utils.openEmailAddress(getContext(), emailId);
}
private void openPostDialog(final FeedModel feedModel,
private void openPostDialog(final Media feedModel,
final View profilePicView,
final View mainPostImage,
final int position) {
@ -208,7 +209,7 @@ public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.O
}
@Override
public void onSelectionChange(final Set<FeedModel> selectedFeedModels) {
public void onSelectionChange(final Set<Media> selectedFeedModels) {
final String title = getString(R.string.number_selected, selectedFeedModels.size());
if (actionMode != null) {
actionMode.setTitle(title);
@ -370,7 +371,7 @@ public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.O
}
private void setupCover() {
final String coverUrl = topicCluster.getCoverMedia().getDisplayUrl();
final String coverUrl = ResponseBodyUtils.getImageUrl(topicCluster.getCoverMedia());
final DraweeController controller = Fresco
.newDraweeControllerBuilder()
.setOldController(binding.cover.getController())

View File

@ -27,7 +27,7 @@ import awais.instagrabber.activities.MainActivity;
import awais.instagrabber.adapters.UserSearchResultsAdapter;
import awais.instagrabber.customviews.helpers.TextWatcherAdapter;
import awais.instagrabber.databinding.FragmentUserSearchBinding;
import awais.instagrabber.repositories.responses.directmessages.DirectUser;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.utils.Utils;
import awais.instagrabber.utils.ViewUtils;
@ -193,7 +193,7 @@ public class UserSearchFragment extends Fragment {
viewModel.showAction().observe(getViewLifecycleOwner(), showAction -> binding.done.setVisibility(showAction ? View.VISIBLE : View.GONE));
}
private void createUserChip(final DirectUser user) {
private void createUserChip(final User user) {
final Context context = getContext();
if (context == null) return;
final Chip chip = new Chip(context);
@ -210,7 +210,7 @@ public class UserSearchFragment extends Fragment {
}
private void removeSelectedUser(final View chip) {
final DirectUser user = (DirectUser) chip.getTag();
final User user = (User) chip.getTag();
if (user == null) return;
viewModel.setSelectedUser(user, false);
resultsAdapter.setSelectedUser(user.getPk(), false);
@ -225,7 +225,7 @@ public class UserSearchFragment extends Fragment {
for (int i = childCount - 1; i >= 0; i--) {
final View child = binding.group.getChildAt(i);
if (child == null) continue;
final DirectUser user = (DirectUser) child.getTag();
final User user = (User) child.getTag();
if (user != null && user.getPk() == userId) {
return child;
}

View File

@ -39,8 +39,8 @@ import awais.instagrabber.databinding.FragmentDirectMessagesSettingsBinding;
import awais.instagrabber.dialogs.MultiOptionDialogFragment;
import awais.instagrabber.dialogs.MultiOptionDialogFragment.Option;
import awais.instagrabber.models.Resource;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
import awais.instagrabber.repositories.responses.directmessages.DirectUser;
import awais.instagrabber.viewmodels.DirectInboxViewModel;
import awais.instagrabber.viewmodels.DirectSettingsViewModel;
@ -50,7 +50,7 @@ public class DirectMessageSettingsFragment extends Fragment {
private FragmentDirectMessagesSettingsBinding binding;
private DirectSettingsViewModel viewModel;
private DirectUsersAdapter usersAdapter;
private List<Option<String>> options;
// private List<Option<String>> options;
@Override
public void onCreate(@Nullable final Bundle savedInstanceState) {
@ -171,14 +171,14 @@ public class DirectMessageSettingsFragment extends Fragment {
final MutableLiveData<Object> resultLiveData = backStackEntry.getSavedStateHandle().getLiveData("result");
resultLiveData.observe(getViewLifecycleOwner(), result -> {
LiveData<Resource<Object>> detailsChangeResourceLiveData = null;
if ((result instanceof DirectUser)) {
if ((result instanceof User)) {
// Log.d(TAG, "result: " + result);
detailsChangeResourceLiveData = viewModel.addMembers(Collections.singleton((DirectUser) result));
detailsChangeResourceLiveData = viewModel.addMembers(Collections.singleton((User) result));
} else if ((result instanceof Set)) {
try {
// Log.d(TAG, "result: " + result);
//noinspection unchecked
detailsChangeResourceLiveData = viewModel.addMembers((Set<DirectUser>) result);
detailsChangeResourceLiveData = viewModel.addMembers((Set<User>) result);
} catch (Exception e) {
Log.e(TAG, "search users result: ", e);
}
@ -221,12 +221,12 @@ public class DirectMessageSettingsFragment extends Fragment {
final NavDestination currentDestination = navController.getCurrentDestination();
if (currentDestination == null) return;
if (currentDestination.getId() != R.id.directMessagesSettingsFragment) return;
final Pair<List<DirectUser>, List<DirectUser>> users = viewModel.getUsers().getValue();
final Pair<List<User>, List<User>> users = viewModel.getUsers().getValue();
final long[] currentUserIds;
if (users != null && users.first != null) {
final List<DirectUser> currentMembers = users.first;
final List<User> currentMembers = users.first;
currentUserIds = currentMembers.stream()
.mapToLong(DirectUser::getPk)
.mapToLong(User::getPk)
.sorted()
.toArray();
} else {
@ -246,7 +246,7 @@ public class DirectMessageSettingsFragment extends Fragment {
final Context context = getContext();
if (context == null) return;
binding.users.setLayoutManager(new LinearLayoutManager(context));
final DirectUser inviter = viewModel.getThread().getInviter();
final User inviter = viewModel.getThread().getInviter();
usersAdapter = new DirectUsersAdapter(
inviter != null ? inviter.getPk() : -1,
(position, user, selected) -> {

View File

@ -68,8 +68,8 @@ import awais.instagrabber.customviews.helpers.RecyclerLazyLoaderAtEdge;
import awais.instagrabber.customviews.helpers.TextWatcherAdapter;
import awais.instagrabber.databinding.FragmentDirectMessagesThreadBinding;
import awais.instagrabber.dialogs.MediaPickerBottomDialogFragment;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.models.Resource;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.directmessages.DirectItem;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
import awais.instagrabber.utils.AppExecutors;
@ -584,7 +584,7 @@ public class DirectMessageThreadFragment extends Fragment {
});
}
private void setupItemsAdapter(final ProfileModel currentUser, final DirectThread thread) {
private void setupItemsAdapter(final User currentUser, final DirectThread thread) {
if (itemsAdapter != null) {
if (itemsAdapter.getThread() == thread) return;
itemsAdapter.setThread(thread);
@ -1105,11 +1105,11 @@ public class DirectMessageThreadFragment extends Fragment {
animatorSet.start();
}
public static class ItemsAdapterDataMerger extends MediatorLiveData<Pair<ProfileModel, DirectThread>> {
private ProfileModel user;
public static class ItemsAdapterDataMerger extends MediatorLiveData<Pair<User, DirectThread>> {
private User user;
private DirectThread thread;
public ItemsAdapterDataMerger(final LiveData<ProfileModel> userLiveData,
public ItemsAdapterDataMerger(final LiveData<User> userLiveData,
final LiveData<DirectThread> threadLiveData) {
addSource(userLiveData, user -> {
this.user = user;

View File

@ -19,6 +19,7 @@ import awais.instagrabber.activities.MainActivity;
import awais.instagrabber.adapters.DiscoverTopicsAdapter;
import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration;
import awais.instagrabber.databinding.FragmentDiscoverBinding;
import awais.instagrabber.repositories.responses.discover.TopicalExploreFeedResponse;
import awais.instagrabber.utils.Utils;
import awais.instagrabber.viewmodels.TopicClusterViewModel;
import awais.instagrabber.webservices.DiscoverService;
@ -88,9 +89,9 @@ public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnR
private void fetchTopics() {
binding.swipeRefreshLayout.setRefreshing(true);
discoverService.topicalExplore(new DiscoverService.TopicalExploreRequest(), new ServiceCallback<DiscoverService.TopicalExploreResponse>() {
discoverService.topicalExplore(new DiscoverService.TopicalExploreRequest(), new ServiceCallback<TopicalExploreFeedResponse>() {
@Override
public void onSuccess(final DiscoverService.TopicalExploreResponse result) {
public void onSuccess(final TopicalExploreFeedResponse result) {
if (result == null) return;
topicClusterViewModel.getList().postValue(result.getClusters());
binding.swipeRefreshLayout.setRefreshing(false);

View File

@ -44,11 +44,10 @@ import awais.instagrabber.customviews.PrimaryActionModeCallback;
import awais.instagrabber.databinding.FragmentFeedBinding;
import awais.instagrabber.dialogs.PostsLayoutPreferencesDialogFragment;
import awais.instagrabber.fragments.PostViewV2Fragment;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.models.FeedStoryModel;
import awais.instagrabber.models.PostsLayoutPreferences;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.DownloadUtils;
import awais.instagrabber.utils.Utils;
import awais.instagrabber.viewmodels.FeedStoriesViewModel;
@ -72,8 +71,8 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
private FeedStoriesViewModel feedStoriesViewModel;
private boolean storiesFetching;
private ActionMode actionMode;
private Set<FeedModel> selectedFeedModels;
private FeedModel downloadFeedModel;
private Set<Media> selectedFeedModels;
private Media downloadFeedModel;
private int downloadChildPosition = -1;
private PostsLayoutPreferences layoutPreferences = Utils.getPostsLayoutPreferences(Constants.PREF_POSTS_LAYOUT);
private RecyclerView storiesRecyclerView;
@ -81,27 +80,27 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
private final FeedAdapterV2.FeedItemCallback feedItemCallback = new FeedAdapterV2.FeedItemCallback() {
@Override
public void onPostClick(final FeedModel feedModel, final View profilePicView, final View mainPostImage) {
public void onPostClick(final Media feedModel, final View profilePicView, final View mainPostImage) {
openPostDialog(feedModel, profilePicView, mainPostImage, -1);
}
@Override
public void onSliderClick(final FeedModel feedModel, final int position) {
public void onSliderClick(final Media feedModel, final int position) {
openPostDialog(feedModel, null, null, position);
}
@Override
public void onCommentsClick(final FeedModel feedModel) {
public void onCommentsClick(final Media feedModel) {
final NavDirections commentsAction = FeedFragmentDirections.actionGlobalCommentsViewerFragment(
feedModel.getShortCode(),
feedModel.getPostId(),
feedModel.getProfileModel().getId()
feedModel.getCode(),
feedModel.getPk(),
feedModel.getUser().getPk()
);
NavHostFragment.findNavController(FeedFragment.this).navigate(commentsAction);
}
@Override
public void onDownloadClick(final FeedModel feedModel, final int childPosition) {
public void onDownloadClick(final Media feedModel, final int childPosition) {
final Context context = getContext();
if (context == null) return;
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
@ -120,8 +119,8 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
}
@Override
public void onLocationClick(final FeedModel feedModel) {
final NavDirections action = FeedFragmentDirections.actionGlobalLocationFragment(feedModel.getLocationId());
public void onLocationClick(final Media feedModel) {
final NavDirections action = FeedFragmentDirections.actionGlobalLocationFragment(feedModel.getLocation().getPk());
NavHostFragment.findNavController(FeedFragment.this).navigate(action);
}
@ -131,13 +130,13 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
}
@Override
public void onNameClick(final FeedModel feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getProfileModel().getUsername());
public void onNameClick(final Media feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getUser().getUsername());
}
@Override
public void onProfilePicClick(final FeedModel feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getProfileModel().getUsername());
public void onProfilePicClick(final Media feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getUser().getUsername());
}
@Override
@ -150,7 +149,7 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
Utils.openEmailAddress(getContext(), emailId);
}
private void openPostDialog(final FeedModel feedModel,
private void openPostDialog(final Media feedModel,
final View profilePicView,
final View mainPostImage,
final int position) {
@ -212,7 +211,7 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
}
@Override
public void onSelectionChange(final Set<FeedModel> selectedFeedModels) {
public void onSelectionChange(final Set<Media> selectedFeedModels) {
final String title = getString(R.string.number_selected, selectedFeedModels.size());
if (actionMode != null) {
actionMode.setTitle(title);
@ -285,8 +284,7 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
if (item.getItemId() == R.id.storyList) {
final NavDirections action = FeedFragmentDirections.actionGlobalStoryListViewerFragment("feed");
NavHostFragment.findNavController(FeedFragment.this).navigate(action);
}
else if (item.getItemId() == R.id.layout) {
} else if (item.getItemId() == R.id.layout) {
showPostsLayoutPreferences();
return true;
}
@ -354,18 +352,19 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
if (storyListMenu != null) storyListMenu.setVisible(false);
feedStoriesViewModel = new ViewModelProvider(fragmentActivity).get(FeedStoriesViewModel.class);
final FeedStoriesAdapter feedStoriesAdapter = new FeedStoriesAdapter(
new FeedStoriesAdapter.OnFeedStoryClickListener() {
@Override
public void onFeedStoryClick(FeedStoryModel model, int position) {
final NavDirections action = FeedFragmentDirections.actionFeedFragmentToStoryViewerFragment(position, null, false, false, null, null, false, false);
NavHostFragment.findNavController(FeedFragment.this).navigate(action);
}
new FeedStoriesAdapter.OnFeedStoryClickListener() {
@Override
public void onFeedStoryClick(FeedStoryModel model, int position) {
final NavDirections action = FeedFragmentDirections
.actionFeedFragmentToStoryViewerFragment(position, null, false, false, null, null, false, false);
NavHostFragment.findNavController(FeedFragment.this).navigate(action);
}
@Override
public void onFeedStoryLongClick(FeedStoryModel model, int position) {
navigateToProfile("@" + model.getProfileModel().getUsername());
@Override
public void onFeedStoryLongClick(FeedStoryModel model, int position) {
navigateToProfile("@" + model.getProfileModel().getUsername());
}
}
}
);
final Context context = getContext();
if (context == null) return;
@ -386,7 +385,7 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
final String cookie = settingsHelper.getString(Constants.COOKIE);
storiesFetching = true;
updateSwipeRefreshState();
storiesService.getFeedStories(CookieUtils.getCsrfTokenFromCookie(cookie), new ServiceCallback<List<FeedStoryModel>>() {
storiesService.getFeedStories(new ServiceCallback<List<FeedStoryModel>>() {
@Override
public void onSuccess(final List<FeedStoryModel> result) {
feedStoriesViewModel.getList().postValue(result);

View File

@ -28,6 +28,7 @@ import androidx.annotation.NonNull;
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.core.content.PermissionChecker;
import androidx.fragment.app.Fragment;
@ -48,6 +49,7 @@ import com.google.common.collect.ImmutableList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import awais.instagrabber.R;
@ -73,15 +75,16 @@ import awais.instagrabber.dialogs.PostsLayoutPreferencesDialogFragment;
import awais.instagrabber.dialogs.ProfilePicDialogFragment;
import awais.instagrabber.fragments.PostViewV2Fragment;
import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.FeedModel;
import awais.instagrabber.models.HighlightModel;
import awais.instagrabber.models.PostsLayoutPreferences;
import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.models.StoryModel;
import awais.instagrabber.models.enums.FavoriteType;
import awais.instagrabber.models.enums.PostItemType;
import awais.instagrabber.repositories.responses.FriendshipRepoChangeRootResponse;
import awais.instagrabber.repositories.responses.FriendshipRepoRestrictRootResponse;
import awais.instagrabber.repositories.responses.FriendshipChangeResponse;
import awais.instagrabber.repositories.responses.FriendshipRestrictResponse;
import awais.instagrabber.repositories.responses.FriendshipStatus;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.DownloadUtils;
@ -109,7 +112,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
private boolean isLoggedIn;
private String cookie;
private String username;
private ProfileModel profileModel;
private User profileModel;
private ActionMode actionMode;
private Handler usernameSettingHandler;
private FriendshipService friendshipService;
@ -123,8 +126,8 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
private MenuItem restrictMenuItem;
private boolean highlightsFetching;
private boolean postsSetupDone = false;
private Set<FeedModel> selectedFeedModels;
private FeedModel downloadFeedModel;
private Set<Media> selectedFeedModels;
private Media downloadFeedModel;
private int downloadChildPosition = -1;
private PostsLayoutPreferences layoutPreferences = Utils.getPostsLayoutPreferences(Constants.PREF_PROFILE_POSTS_LAYOUT);
@ -170,27 +173,27 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
});
private final FeedAdapterV2.FeedItemCallback feedItemCallback = new FeedAdapterV2.FeedItemCallback() {
@Override
public void onPostClick(final FeedModel feedModel, final View profilePicView, final View mainPostImage) {
public void onPostClick(final Media feedModel, final View profilePicView, final View mainPostImage) {
openPostDialog(feedModel, profilePicView, mainPostImage, -1);
}
@Override
public void onSliderClick(final FeedModel feedModel, final int position) {
public void onSliderClick(final Media feedModel, final int position) {
openPostDialog(feedModel, null, null, position);
}
@Override
public void onCommentsClick(final FeedModel feedModel) {
public void onCommentsClick(final Media feedModel) {
final NavDirections commentsAction = FeedFragmentDirections.actionGlobalCommentsViewerFragment(
feedModel.getShortCode(),
feedModel.getPostId(),
feedModel.getProfileModel().getId()
feedModel.getCode(),
feedModel.getPk(),
feedModel.getUser().getPk()
);
NavHostFragment.findNavController(ProfileFragment.this).navigate(commentsAction);
}
@Override
public void onDownloadClick(final FeedModel feedModel, final int childPosition) {
public void onDownloadClick(final Media feedModel, final int childPosition) {
final Context context = getContext();
if (context == null) return;
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
@ -209,8 +212,8 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
}
@Override
public void onLocationClick(final FeedModel feedModel) {
final NavDirections action = FeedFragmentDirections.actionGlobalLocationFragment(feedModel.getLocationId());
public void onLocationClick(final Media feedModel) {
final NavDirections action = FeedFragmentDirections.actionGlobalLocationFragment(feedModel.getLocation().getPk());
NavHostFragment.findNavController(ProfileFragment.this).navigate(action);
}
@ -220,13 +223,13 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
}
@Override
public void onNameClick(final FeedModel feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getProfileModel().getUsername());
public void onNameClick(final Media feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getUser().getUsername());
}
@Override
public void onProfilePicClick(final FeedModel feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getProfileModel().getUsername());
public void onProfilePicClick(final Media feedModel, final View profilePicView) {
navigateToProfile("@" + feedModel.getUser().getUsername());
}
@Override
@ -239,7 +242,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
Utils.openEmailAddress(getContext(), emailId);
}
private void openPostDialog(final FeedModel feedModel,
private void openPostDialog(final Media feedModel,
final View profilePicView,
final View mainPostImage,
final int position) {
@ -270,7 +273,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
}
@Override
public void onSelectionChange(final Set<FeedModel> selectedFeedModels) {
public void onSelectionChange(final Set<Media> selectedFeedModels) {
final String title = getString(R.string.number_selected, selectedFeedModels.size());
if (actionMode != null) {
actionMode.setTitle(title);
@ -311,7 +314,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
final ViewGroup container,
final Bundle savedInstanceState) {
cookie = settingsHelper.getString(Constants.COOKIE);
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != null;
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) > 0;
if (root != null) {
if (getArguments() != null) {
final ProfileFragmentArgs fragmentArgs = ProfileFragmentArgs.fromBundle(getArguments());
@ -373,14 +376,14 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
}
if (item.getItemId() == R.id.restrict) {
if (!isLoggedIn) return false;
final String action = profileModel.isRestricted() ? "Unrestrict" : "Restrict";
final String action = profileModel.getFriendshipStatus().isRestricted() ? "Unrestrict" : "Restrict";
friendshipService.toggleRestrict(
profileModel.getId(),
!profileModel.isRestricted(),
profileModel.getPk(),
!profileModel.getFriendshipStatus().isRestricted(),
CookieUtils.getCsrfTokenFromCookie(cookie),
new ServiceCallback<FriendshipRepoRestrictRootResponse>() {
new ServiceCallback<FriendshipRestrictResponse>() {
@Override
public void onSuccess(final FriendshipRepoRestrictRootResponse result) {
public void onSuccess(final FriendshipRestrictResponse result) {
Log.d(TAG, action + " success: " + result);
fetchProfileDetails();
}
@ -393,16 +396,16 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
return true;
}
if (item.getItemId() == R.id.block) {
final String userIdFromCookie = CookieUtils.getUserIdFromCookie(cookie);
final long userIdFromCookie = CookieUtils.getUserIdFromCookie(cookie);
if (!isLoggedIn) return false;
if (profileModel.isBlocked()) {
if (profileModel.getFriendshipStatus().isBlocking()) {
friendshipService.unblock(
userIdFromCookie,
profileModel.getId(),
profileModel.getPk(),
CookieUtils.getCsrfTokenFromCookie(cookie),
new ServiceCallback<FriendshipRepoChangeRootResponse>() {
new ServiceCallback<FriendshipChangeResponse>() {
@Override
public void onSuccess(final FriendshipRepoChangeRootResponse result) {
public void onSuccess(final FriendshipChangeResponse result) {
Log.d(TAG, "Unblock success: " + result);
fetchProfileDetails();
}
@ -416,11 +419,11 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
}
friendshipService.block(
userIdFromCookie,
profileModel.getId(),
profileModel.getPk(),
CookieUtils.getCsrfTokenFromCookie(cookie),
new ServiceCallback<FriendshipRepoChangeRootResponse>() {
new ServiceCallback<FriendshipChangeResponse>() {
@Override
public void onSuccess(final FriendshipRepoChangeRootResponse result) {
public void onSuccess(final FriendshipChangeResponse result) {
Log.d(TAG, "Block success: " + result);
fetchProfileDetails();
}
@ -504,8 +507,8 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
}
private void fetchUsername() {
final String uid = CookieUtils.getUserIdFromCookie(cookie);
if (TextUtils.isEmpty(username) && uid != null) {
final long uid = CookieUtils.getUserIdFromCookie(cookie);
if (TextUtils.isEmpty(username) && uid > 0) {
final FetchListener<String> fetchListener = username -> {
if (TextUtils.isEmpty(username)) return;
this.username = username;
@ -569,8 +572,8 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
binding.postsRecyclerView.refresh();
}
profileDetailsBinding.isVerified.setVisibility(profileModel.isVerified() ? View.VISIBLE : View.GONE);
final String profileId = profileModel.getId();
final String myId = CookieUtils.getUserIdFromCookie(cookie);
final long profileId = profileModel.getPk();
final long myId = CookieUtils.getUserIdFromCookie(cookie);
if (isLoggedIn) {
fetchStoryAndHighlights(profileId);
}
@ -586,8 +589,8 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
result.getId(),
profileModel.getUsername(),
FavoriteType.USER,
profileModel.getName(),
profileModel.getSdProfilePic(),
profileModel.getFullName(),
profileModel.getProfilePicUrl(),
result.getDateAdded()
), new RepositoryCallback<Void>() {
@Override
@ -627,8 +630,8 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
0,
profileModel.getUsername(),
FavoriteType.USER,
profileModel.getName(),
profileModel.getSdProfilePic(),
profileModel.getFullName(),
profileModel.getProfilePicUrl(),
new Date()
), new RepositoryCallback<Void>() {
@Override
@ -643,17 +646,19 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
});
}
}));
profileDetailsBinding.mainProfileImage.setImageURI(profileModel.getHdProfilePic());
profileDetailsBinding.mainProfileImage.setImageURI(profileModel.getProfilePicUrl());
profileDetailsBinding.mainProfileImage.setVisibility(View.VISIBLE);
final Long followersCount = profileModel.getFollowersCount();
final Long followingCount = profileModel.getFollowingCount();
final long followersCount = profileModel.getFollowerCount();
final long followingCount = profileModel.getFollowingCount();
final String postCount = String.valueOf(profileModel.getPostCount());
final String postCount = String.valueOf(profileModel.getMediaCount());
SpannableStringBuilder span = new SpannableStringBuilder(getResources().getQuantityString(R.plurals.main_posts_count_inline,
profileModel.getPostCount() > 2000000000L ? 2000000000 : profileModel.getPostCount().intValue(),
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);
@ -662,8 +667,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 : followersCount.intValue(),
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);
@ -678,8 +683,8 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
profileDetailsBinding.mainFollowing.setText(span);
profileDetailsBinding.mainFollowing.setVisibility(View.VISIBLE);
profileDetailsBinding.mainFullName.setText(TextUtils.isEmpty(profileModel.getName()) ? profileModel.getUsername()
: profileModel.getName());
profileDetailsBinding.mainFullName.setText(TextUtils.isEmpty(profileModel.getFullName()) ? profileModel.getUsername()
: profileModel.getFullName());
final String biography = profileModel.getBiography();
if (!TextUtils.isEmpty(biography)) {
@ -713,13 +718,13 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
};
}
new AlertDialog.Builder(context)
.setItems(commentDialogList, (d,w) -> {
.setItems(commentDialogList, (d, w) -> {
switch (w) {
case 0:
Utils.copyText(context, biography);
break;
case 1:
mediaService.translate(profileModel.getId(), "3", new ServiceCallback<String>() {
mediaService.translate(String.valueOf(profileModel.getPk()), "3", new ServiceCallback<String>() {
@Override
public void onSuccess(final String result) {
if (TextUtils.isEmpty(result)) {
@ -750,7 +755,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
return true;
});
}
final String url = profileModel.getUrl();
final String url = profileModel.getExternalUrl();
if (TextUtils.isEmpty(url)) {
profileDetailsBinding.mainUrl.setVisibility(View.GONE);
} else {
@ -762,7 +767,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
return true;
});
}
if (!profileModel.isReallyPrivate()) {
if (!isReallyPrivate()) {
if (isLoggedIn) {
profileDetailsBinding.mainFollowing.setClickable(true);
profileDetailsBinding.mainFollowers.setClickable(true);
@ -791,10 +796,10 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
}
}
private void setupButtons(final String profileId, final String myId) {
profileDetailsBinding.btnTagged.setVisibility(profileModel.isReallyPrivate() ? View.GONE : View.VISIBLE);
private void setupButtons(final long profileId, final long myId) {
profileDetailsBinding.btnTagged.setVisibility(isReallyPrivate() ? View.GONE : View.VISIBLE);
if (isLoggedIn) {
if (profileId.equals(myId)) {
if (Objects.equals(profileId, myId)) {
profileDetailsBinding.btnTagged.setVisibility(View.VISIBLE);
profileDetailsBinding.btnSaved.setVisibility(View.VISIBLE);
profileDetailsBinding.btnLiked.setVisibility(View.VISIBLE);
@ -806,25 +811,25 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
profileDetailsBinding.btnLiked.setVisibility(View.GONE);
profileDetailsBinding.btnDM.setVisibility(View.VISIBLE); // maybe there is a judgment mechanism?
profileDetailsBinding.btnFollow.setVisibility(View.VISIBLE);
if (profileModel.isFollowing() || profileModel.isFollower()) {
final Context context = getContext();
if (context == null) return;
if (profileModel.getFriendshipStatus().isFollowing() || profileModel.getFriendshipStatus().isFollowedBy()) {
profileDetailsBinding.mainStatus.setVisibility(View.VISIBLE);
if (!profileModel.isFollowing()) {
profileDetailsBinding.mainStatus.setChipBackgroundColor(getResources().getColorStateList(R.color.blue_800));
if (!profileModel.getFriendshipStatus().isFollowing()) {
profileDetailsBinding.mainStatus.setChipBackgroundColor(AppCompatResources.getColorStateList(context, R.color.blue_800));
profileDetailsBinding.mainStatus.setText(R.string.status_follower);
}
else if (!profileModel.isFollower()) {
profileDetailsBinding.mainStatus.setChipBackgroundColor(getResources().getColorStateList(R.color.deep_orange_800));
} else if (!profileModel.getFriendshipStatus().isFollowedBy()) {
profileDetailsBinding.mainStatus.setChipBackgroundColor(AppCompatResources.getColorStateList(context, R.color.deep_orange_800));
profileDetailsBinding.mainStatus.setText(R.string.status_following);
}
else {
profileDetailsBinding.mainStatus.setChipBackgroundColor(getResources().getColorStateList(R.color.green_800));
} else {
profileDetailsBinding.mainStatus.setChipBackgroundColor(AppCompatResources.getColorStateList(context, R.color.green_800));
profileDetailsBinding.mainStatus.setText(R.string.status_mutual);
}
}
if (profileModel.isFollowing()) {
if (profileModel.getFriendshipStatus().isFollowing()) {
profileDetailsBinding.btnFollow.setText(R.string.unfollow);
profileDetailsBinding.btnFollow.setIconResource(R.drawable.ic_outline_person_add_disabled_24);
} else if (profileModel.isRequested()) {
} else if (profileModel.getFriendshipStatus().isOutgoingRequest()) {
profileDetailsBinding.btnFollow.setText(R.string.cancel);
profileDetailsBinding.btnFollow.setIconResource(R.drawable.ic_outline_person_add_disabled_24);
} else {
@ -833,7 +838,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
}
if (restrictMenuItem != null) {
restrictMenuItem.setVisible(true);
if (profileModel.isRestricted()) {
if (profileModel.getFriendshipStatus().isRestricted()) {
restrictMenuItem.setTitle(R.string.unrestrict);
} else {
restrictMenuItem.setTitle(R.string.restrict);
@ -841,7 +846,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
}
if (blockMenuItem != null) {
blockMenuItem.setVisible(true);
if (profileModel.isBlocked()) {
if (profileModel.getFriendshipStatus().isBlocking()) {
blockMenuItem.setTitle(R.string.unblock);
} else {
blockMenuItem.setTitle(R.string.block);
@ -849,9 +854,9 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
}
return;
}
if (!profileModel.isReallyPrivate() && restrictMenuItem != null) {
if (!isReallyPrivate() && restrictMenuItem != null) {
restrictMenuItem.setVisible(true);
if (profileModel.isRestricted()) {
if (profileModel.getFriendshipStatus().isRestricted()) {
restrictMenuItem.setTitle(R.string.unrestrict);
} else {
restrictMenuItem.setTitle(R.string.restrict);
@ -859,8 +864,8 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
}
}
private void fetchStoryAndHighlights(final String profileId) {
storiesService.getUserStory(profileId,
private void fetchStoryAndHighlights(final long profileId) {
storiesService.getUserStory(String.valueOf(profileId),
profileModel.getUsername(),
false,
false,
@ -880,61 +885,59 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
}
});
storiesService.fetchHighlights(profileId,
new ServiceCallback<List<HighlightModel>>() {
@Override
public void onSuccess(final List<HighlightModel> result) {
highlightsFetching = false;
if (result != null) {
profileDetailsBinding.highlightsList.setVisibility(View.VISIBLE);
highlightsViewModel.getList().postValue(result);
}
else profileDetailsBinding.highlightsList.setVisibility(View.GONE);
}
new ServiceCallback<List<HighlightModel>>() {
@Override
public void onSuccess(final List<HighlightModel> result) {
highlightsFetching = false;
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() {
final Context context = getContext();
final String userIdFromCookie = CookieUtils.getUserIdFromCookie(cookie);
final long userIdFromCookie = CookieUtils.getUserIdFromCookie(cookie);
profileDetailsBinding.btnFollow.setOnClickListener(v -> {
if (profileModel.isFollowing() && profileModel.isPrivate()) {
if (profileModel.getFriendshipStatus().isFollowing() && profileModel.isPrivate()) {
new AlertDialog.Builder(context)
.setTitle(R.string.priv_acc)
.setMessage(R.string.priv_acc_confirm)
.setPositiveButton(R.string.confirm, (d, w) ->
friendshipService.unfollow(
userIdFromCookie,
profileModel.getId(),
CookieUtils.getCsrfTokenFromCookie(cookie),
new ServiceCallback<FriendshipRepoChangeRootResponse>() {
@Override
public void onSuccess(final FriendshipRepoChangeRootResponse result) {
// Log.d(TAG, "Unfollow success: " + result);
onRefresh();
}
friendshipService.unfollow(
userIdFromCookie,
profileModel.getPk(),
CookieUtils.getCsrfTokenFromCookie(cookie),
new ServiceCallback<FriendshipChangeResponse>() {
@Override
public void onSuccess(final FriendshipChangeResponse result) {
// Log.d(TAG, "Unfollow success: " + result);
onRefresh();
}
@Override
public void onFailure(final Throwable t) {
Log.e(TAG, "Error unfollowing", t);
}
}))
@Override
public void onFailure(final Throwable t) {
Log.e(TAG, "Error unfollowing", t);
}
}))
.setNegativeButton(R.string.cancel, null)
.show();
}
else if (profileModel.isFollowing() || profileModel.isRequested()) {
} else if (profileModel.getFriendshipStatus().isFollowing() || profileModel.getFriendshipStatus().isOutgoingRequest()) {
friendshipService.unfollow(
userIdFromCookie,
profileModel.getId(),
profileModel.getPk(),
CookieUtils.getCsrfTokenFromCookie(cookie),
new ServiceCallback<FriendshipRepoChangeRootResponse>() {
new ServiceCallback<FriendshipChangeResponse>() {
@Override
public void onSuccess(final FriendshipRepoChangeRootResponse result) {
public void onSuccess(final FriendshipChangeResponse result) {
// Log.d(TAG, "Unfollow success: " + result);
onRefresh();
}
@ -947,11 +950,11 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
} else {
friendshipService.follow(
userIdFromCookie,
profileModel.getId(),
profileModel.getPk(),
CookieUtils.getCsrfTokenFromCookie(cookie),
new ServiceCallback<FriendshipRepoChangeRootResponse>() {
new ServiceCallback<FriendshipChangeResponse>() {
@Override
public void onSuccess(final FriendshipRepoChangeRootResponse result) {
public void onSuccess(final FriendshipChangeResponse result) {
// Log.d(TAG, "Follow success: " + result);
onRefresh();
}
@ -965,25 +968,25 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
});
profileDetailsBinding.btnSaved.setOnClickListener(v -> {
final NavDirections action = ProfileFragmentDirections.actionProfileFragmentToSavedViewerFragment(profileModel.getUsername(),
profileModel.getId(),
profileModel.getPk(),
PostItemType.SAVED);
NavHostFragment.findNavController(this).navigate(action);
});
profileDetailsBinding.btnLiked.setOnClickListener(v -> {
final NavDirections action = ProfileFragmentDirections.actionProfileFragmentToSavedViewerFragment(profileModel.getUsername(),
profileModel.getId(),
profileModel.getPk(),
PostItemType.LIKED);
NavHostFragment.findNavController(this).navigate(action);
});
profileDetailsBinding.btnTagged.setOnClickListener(v -> {
final NavDirections action = ProfileFragmentDirections.actionProfileFragmentToSavedViewerFragment(profileModel.getUsername(),
profileModel.getId(),
profileModel.getPk(),
PostItemType.TAGGED);
NavHostFragment.findNavController(this).navigate(action);
});
profileDetailsBinding.btnDM.setOnClickListener(v -> {
profileDetailsBinding.btnDM.setEnabled(false);
new CreateThreadAction(cookie, profileModel.getId(), threadId -> {
new CreateThreadAction(cookie, profileModel.getPk(), threadId -> {
if (isAdded()) {
final NavDirections action = ProfileFragmentDirections
.actionProfileFragmentToDMThreadFragment(threadId, profileModel.getUsername());
@ -1008,7 +1011,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
if (which == 1) {
// show stories
final NavDirections action = ProfileFragmentDirections
.actionProfileFragmentToStoryViewerFragment(-1, null, false, false, profileModel.getId(), username, false, false);
.actionProfileFragmentToStoryViewerFragment(-1, null, false, false, profileModel.getPk(), username, false, false);
NavHostFragment.findNavController(this).navigate(action);
return;
}
@ -1033,7 +1036,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
private void showProfilePicDialog() {
if (profileModel != null) {
final FragmentManager fragmentManager = getParentFragmentManager();
final ProfilePicDialogFragment fragment = new ProfilePicDialogFragment(profileModel.getId(), username, profileModel.getHdProfilePic());
final ProfilePicDialogFragment fragment = new ProfilePicDialogFragment(profileModel.getPk(), username, profileModel.getProfilePicUrl());
final FragmentTransaction ft = fragmentManager.beginTransaction();
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.add(fragment, "profilePicDialog")
@ -1069,7 +1072,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
highlightsViewModel = new ViewModelProvider(fragmentActivity).get(HighlightsViewModel.class);
highlightsAdapter = new HighlightsAdapter((model, position) -> {
final NavDirections action = ProfileFragmentDirections
.actionProfileFragmentToStoryViewerFragment(position, model.getTitle(), false, false, null, null, false, false);
.actionProfileFragmentToStoryViewerFragment(position, model.getTitle(), false, false, 0, null, false, false);
NavHostFragment.findNavController(this).navigate(action);
});
final Context context = getContext();
@ -1104,4 +1107,10 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
});
fragment.show(getChildFragmentManager(), "posts_layout_preferences");
}
private boolean isReallyPrivate() {
final long myId = CookieUtils.getUserIdFromCookie(cookie);
final FriendshipStatus friendshipStatus = profileModel.getFriendshipStatus();
return !friendshipStatus.isFollowedBy() && (profileModel.getPk() != myId) && profileModel.isPrivate();
}
}

View File

@ -32,7 +32,7 @@ import awais.instagrabber.db.entities.Account;
import awais.instagrabber.db.repositories.AccountRepository;
import awais.instagrabber.db.repositories.RepositoryCallback;
import awais.instagrabber.dialogs.AccountSwitcherDialogFragment;
import awais.instagrabber.repositories.responses.UserInfo;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.FlavorTown;
@ -54,7 +54,7 @@ public class MorePreferencesFragment extends BasePreferencesFragment {
@Override
void setupPreferenceScreen(final PreferenceScreen screen) {
final String cookie = settingsHelper.getString(Constants.COOKIE);
final boolean isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != null;
final boolean isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) > 0;
// screen.addPreference(new MoreHeaderPreference(getContext()));
final Context context = getContext();
if (context == null) return;
@ -198,11 +198,11 @@ public class MorePreferencesFragment extends BasePreferencesFragment {
// Toast.makeText(getContext(), R.string.login_success_loading_cookies, Toast.LENGTH_SHORT).show();
// adds cookies to database for quick access
final String uid = CookieUtils.getUserIdFromCookie(cookie);
final long uid = CookieUtils.getUserIdFromCookie(cookie);
final UserService userService = UserService.getInstance();
userService.getUserInfo(uid, new ServiceCallback<UserInfo>() {
userService.getUserInfo(uid, new ServiceCallback<User>() {
@Override
public void onSuccess(final UserInfo result) {
public void onSuccess(final User result) {
// Log.d(TAG, "adding userInfo: " + result);
if (result != null) {
accountRepository.insertOrUpdateAccount(
@ -321,8 +321,8 @@ public class MorePreferencesFragment extends BasePreferencesFragment {
final View root = holder.itemView;
if (onClickListener != null) root.setOnClickListener(onClickListener);
final PrefAccountSwitcherBinding binding = PrefAccountSwitcherBinding.bind(root);
final String uid = CookieUtils.getUserIdFromCookie(cookie);
if (uid == null) return;
final long uid = CookieUtils.getUserIdFromCookie(cookie);
if (uid <= 0) return;
accountRepository.getAccount(uid, new RepositoryCallback<Account>() {
@Override
public void onSuccess(final Account account) {

View File

@ -40,7 +40,7 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
@Override
void setupPreferenceScreen(final PreferenceScreen screen) {
final String cookie = settingsHelper.getString(Constants.COOKIE);
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != null;
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) > 0;
final Context context = getContext();
if (context == null) return;
final PreferenceCategory generalCategory = new PreferenceCategory(context);
@ -84,12 +84,12 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
loggedInUsersPreferenceCategory.addPreference(getMarkDMSeenPreference());
loggedInUsersPreferenceCategory.addPreference(getEnableActivityNotificationsPreference());
}
// else {
// final PreferenceCategory anonUsersPreferenceCategory = new PreferenceCategory(context);
// screen.addPreference(anonUsersPreferenceCategory);
// anonUsersPreferenceCategory.setIconSpaceReserved(false);
// anonUsersPreferenceCategory.setTitle(R.string.anonymous_settings);
// }
// else {
// final PreferenceCategory anonUsersPreferenceCategory = new PreferenceCategory(context);
// screen.addPreference(anonUsersPreferenceCategory);
// anonUsersPreferenceCategory.setIconSpaceReserved(false);
// anonUsersPreferenceCategory.setTitle(R.string.anonymous_settings);
// }
}
private Preference getLanguagePreference() {

View File

@ -1,11 +0,0 @@
package awais.instagrabber.interfaces;
import java.io.Serializable;
import java.util.List;
import awais.instagrabber.models.BasePostModel;
import awais.instagrabber.models.enums.PostItemType;
public interface ItemGetter extends Serializable {
List<? extends BasePostModel> get(final PostItemType postItemType);
}

View File

@ -2,6 +2,7 @@ package awais.instagrabber.interfaces;
import awais.instagrabber.customviews.RamboTextView;
@Deprecated
public interface MentionClickListener {
void onClick(final RamboTextView view,
final String text,

View File

@ -1,98 +0,0 @@
package awais.instagrabber.models;
import androidx.annotation.NonNull;
import androidx.core.util.ObjectsCompat;
import java.io.Serializable;
import java.util.Date;
import awais.instagrabber.adapters.MultiSelectListAdapter.Selectable;
import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.utils.Utils;
public abstract class BasePostModel implements Serializable, Selectable {
protected String postId, displayUrl, shortCode, captionId;
protected CharSequence postCaption;
protected MediaItemType itemType;
protected boolean isSelected, isDownloaded;
protected long timestamp;
boolean liked, saved;
public boolean getLike() {
return liked;
}
public boolean isSaved() {
return saved;
}
public MediaItemType getItemType() {
return itemType;
}
public final String getPostId() {
return postId;
}
public final String getDisplayUrl() {
return displayUrl;
}
public final CharSequence getPostCaption() {
return postCaption;
}
public final String getCaptionId() {
return captionId;
}
public final String getShortCode() {
return shortCode;
}
public final long getTimestamp() {
return timestamp;
}
public boolean isSelected() {
return isSelected;
}
public boolean isDownloaded() {
return isDownloaded;
}
public void setItemType(final MediaItemType itemType) {
this.itemType = itemType;
}
public void setPostId(final String postId) {
this.postId = postId;
}
public void setSelected(final boolean selected) {
this.isSelected = selected;
}
public void setDownloaded(final boolean downloaded) {
isDownloaded = downloaded;
}
@NonNull
public final String getPostDate() {
return Utils.datetimeParser.format(new Date(timestamp * 1000L));
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final BasePostModel that = (BasePostModel) o;
return ObjectsCompat.equals(postId, that.postId) && ObjectsCompat.equals(shortCode, that.shortCode);
}
@Override
public int hashCode() {
return ObjectsCompat.hash(postId, shortCode);
}
}

View File

@ -5,10 +5,11 @@ import androidx.annotation.NonNull;
import java.util.Date;
import java.util.List;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.utils.Utils;
public class CommentModel {
private final ProfileModel profileModel;
private final User profileModel;
private final String id;
private final String text;
private long likes;
@ -22,7 +23,7 @@ public class CommentModel {
final long timestamp,
final long likes,
final boolean liked,
final ProfileModel profileModel) {
final User profileModel) {
this.id = id;
this.text = text;
this.likes = likes;
@ -57,7 +58,7 @@ public class CommentModel {
this.liked = liked;
}
public ProfileModel getProfileModel() {
public User getProfileModel() {
return profileModel;
}

View File

@ -1,29 +0,0 @@
package awais.instagrabber.models;
import awais.instagrabber.models.enums.MediaItemType;
public final class DiscoverItemModel extends BasePostModel {
private boolean moreAvailable;
private String nextMaxId;
public DiscoverItemModel(final MediaItemType mediaType, final String postId, final String shortCode, final String thumbnail) {
this.postId = postId;
this.itemType = mediaType;
this.shortCode = shortCode;
this.displayUrl = thumbnail;
}
public void setMore(final boolean moreAvailable, final String nextMaxId) {
this.moreAvailable = moreAvailable;
this.nextMaxId = nextMaxId;
}
public boolean hasMore() {
return moreAvailable;
}
public String getNextMaxId() {
return nextMaxId;
}
}

View File

@ -1,26 +0,0 @@
package awais.instagrabber.models;
import java.io.Serializable;
public final class DiscoverTopicModel implements Serializable {
private final String[] id, name;
private final String rankToken;
public DiscoverTopicModel(final String[] id, final String[] name, final String rankToken) {
this.id = id;
this.name = name;
this.rankToken = rankToken;
}
public String[] getIds() {
return id;
}
public String[] getNames() {
return name;
}
public String getToken() {
return rankToken;
}
}

View File

@ -1,234 +0,0 @@
package awais.instagrabber.models;
import java.util.List;
import awais.instagrabber.models.enums.MediaItemType;
public final class FeedModel extends PostModel {
private final ProfileModel profileModel;
private final long commentsCount;
private long likesCount;
private final long viewCount;
private final List<PostChild> sliderItems;
private final int imageWidth;
private final int imageHeight;
private final String locationName;
private final String locationId;
public static class Builder {
private ProfileModel profileModel;
private MediaItemType itemType;
private long viewCount;
private String postId;
private String displayUrl;
private String thumbnailUrl;
private String shortCode;
private String postCaption, captionId;
private long commentsCount;
private long timestamp;
private boolean liked;
private boolean bookmarked;
private long likesCount;
private String locationName;
private String locationId;
private List<PostChild> sliderItems;
private int imageWidth;
private int imageHeight;
public Builder setProfileModel(final ProfileModel profileModel) {
this.profileModel = profileModel;
return this;
}
public Builder setItemType(final MediaItemType itemType) {
this.itemType = itemType;
return this;
}
public Builder setViewCount(final long viewCount) {
this.viewCount = viewCount;
return this;
}
public Builder setPostId(final String postId) {
this.postId = postId;
return this;
}
public Builder setDisplayUrl(final String displayUrl) {
this.displayUrl = displayUrl;
return this;
}
public Builder setThumbnailUrl(final String thumbnailUrl) {
this.thumbnailUrl = thumbnailUrl;
return this;
}
public Builder setShortCode(final String shortCode) {
this.shortCode = shortCode;
return this;
}
public Builder setPostCaption(final String postCaption) {
this.postCaption = postCaption;
return this;
}
public Builder setCaptionId(final String captionId) {
this.captionId = captionId;
return this;
}
public Builder setCommentsCount(final long commentsCount) {
this.commentsCount = commentsCount;
return this;
}
public Builder setTimestamp(final long timestamp) {
this.timestamp = timestamp;
return this;
}
public Builder setLiked(final boolean liked) {
this.liked = liked;
return this;
}
public Builder setBookmarked(final boolean bookmarked) {
this.bookmarked = bookmarked;
return this;
}
public Builder setLikesCount(final long likesCount) {
this.likesCount = likesCount;
return this;
}
public Builder setLocationName(final String locationName) {
this.locationName = locationName;
return this;
}
public Builder setLocationId(final String locationId) {
this.locationId = locationId;
return this;
}
public Builder setSliderItems(final List<PostChild> sliderItems) {
this.sliderItems = sliderItems;
return this;
}
public Builder setImageHeight(final int imageHeight) {
this.imageHeight = imageHeight;
return this;
}
public Builder setImageWidth(final int imageWidth) {
this.imageWidth = imageWidth;
return this;
}
public FeedModel build() {
return new FeedModel(profileModel, itemType, viewCount, postId, displayUrl, thumbnailUrl, shortCode, postCaption, captionId,
commentsCount, timestamp, liked, bookmarked, likesCount, locationName, locationId, sliderItems, imageHeight, imageWidth);
}
}
private FeedModel(final ProfileModel profileModel,
final MediaItemType itemType,
final long viewCount,
final String postId,
final String displayUrl,
final String thumbnailUrl,
final String shortCode,
final String postCaption,
final String captionId,
final long commentsCount,
final long timestamp,
final boolean liked,
final boolean bookmarked,
final long likesCount,
final String locationName,
final String locationId,
final List<PostChild> sliderItems,
final int imageHeight,
final int imageWidth) {
super(itemType, postId, displayUrl, thumbnailUrl, shortCode, postCaption, captionId, timestamp, liked, bookmarked);
this.profileModel = profileModel;
this.commentsCount = commentsCount;
this.likesCount = likesCount;
this.viewCount = viewCount;
this.locationName = locationName;
this.locationId = locationId;
this.sliderItems = sliderItems;
this.imageHeight = imageHeight;
this.imageWidth = imageWidth;
}
public ProfileModel getProfileModel() {
return profileModel;
}
public List<PostChild> getSliderItems() {
return sliderItems;
}
public long getViewCount() {
return viewCount;
}
public long getCommentsCount() {
return commentsCount;
}
public long getLikesCount() {
return likesCount;
}
public int getImageWidth() {
return imageWidth;
}
public int getImageHeight() {
return imageHeight;
}
public String getLocationName() {
return locationName;
}
public String getLocationId() {
return locationId;
}
public void setLiked(final boolean liked) {
this.liked = liked;
}
public void setLikesCount(final long count) {
this.likesCount = count;
}
public void setSaved(final boolean saved) {
this.saved = saved;
}
@Override
public String toString() {
return "FeedModel{" +
"type=" + itemType +
", displayUrl=" + displayUrl +
", thumbnailUrl=" + thumbnailUrl +
", commentsCount=" + commentsCount +
", viewCount=" + viewCount +
// ", sliderItems=" + sliderItems +
", imageWidth=" + imageWidth +
", imageHeight=" + imageHeight +
", locationName='" + locationName + '\'' +
", locationId='" + locationId + '\'' +
'}';
}
}

View File

@ -1,23 +1,22 @@
package awais.instagrabber.models;
import android.util.Log;
import androidx.annotation.NonNull;
import java.io.Serializable;
import java.util.Date;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.utils.Utils;
public final class FeedStoryModel implements Serializable {
private final String storyMediaId;
private final ProfileModel profileModel;
private final User profileModel;
private final StoryModel firstStoryModel;
private Boolean fullyRead;
private final long timestamp;
private final int mediaCount;
public FeedStoryModel(final String storyMediaId, final ProfileModel profileModel, final boolean fullyRead,
public FeedStoryModel(final String storyMediaId, final User profileModel, final boolean fullyRead,
final long timestamp, final StoryModel firstStoryModel, final int mediaCount) {
this.storyMediaId = storyMediaId;
this.profileModel = profileModel;
@ -44,13 +43,13 @@ public final class FeedStoryModel implements Serializable {
return mediaCount;
}
public ProfileModel getProfileModel() {
public User getProfileModel() {
return profileModel;
}
// public void setFirstStoryModel(final StoryModel firstStoryModel) {
// this.firstStoryModel = firstStoryModel;
// }
// public void setFirstStoryModel(final StoryModel firstStoryModel) {
// this.firstStoryModel = firstStoryModel;
// }
public StoryModel getFirstStoryModel() {
return firstStoryModel;

View File

@ -5,9 +5,13 @@ import androidx.annotation.Nullable;
import java.io.Serializable;
public final class FollowModel implements Serializable {
private final String id, username, fullName, profilePicUrl;
private final String id;
private final String username;
private final String fullName;
private final String profilePicUrl;
private String endCursor;
private boolean hasNextPage, isShown = true;
private boolean hasNextPage;
private boolean isShown = true;
public FollowModel(final String id, final String username, final String fullName, final String profilePicUrl) {
this.id = id;

View File

@ -10,7 +10,7 @@ import awais.instagrabber.utils.Utils;
public final class NotificationModel {
private final String id;
private final String userId;
private final long userId;
private final String username;
private final String profilePicUrl;
private final String postId;
@ -22,7 +22,7 @@ public final class NotificationModel {
public NotificationModel(final String id,
final String text,
final long timestamp,
final String userId,
final long userId,
final String username,
final String profilePicUrl,
final String postId,
@ -56,7 +56,7 @@ public final class NotificationModel {
return Utils.datetimeParser.format(new Date(timestamp * 1000L));
}
public String getUserId() {
public long getUserId() {
return userId;
}

View File

@ -1,132 +0,0 @@
package awais.instagrabber.models;
import java.io.Serializable;
import awais.instagrabber.models.enums.MediaItemType;
public final class PostChild implements Serializable {
private final String postId;
private final String displayUrl;
private final String shortCode;
private final MediaItemType itemType;
private final String thumbnailUrl;
private final long videoViews;
private final int width;
private final int height;
public static class Builder {
private String postId, displayUrl, shortCode, thumbnailUrl;
private MediaItemType itemType;
private long videoViews;
private int width;
private int height;
public Builder setPostId(final String postId) {
this.postId = postId;
return this;
}
public Builder setShortCode(final String shortCode) {
this.shortCode = shortCode;
return this;
}
public Builder setItemType(final MediaItemType itemType) {
this.itemType = itemType;
return this;
}
public Builder setDisplayUrl(final String displayUrl) {
this.displayUrl = displayUrl;
return this;
}
public Builder setVideoViews(final long videoViews) {
this.videoViews = videoViews;
return this;
}
public Builder setHeight(final int height) {
this.height = height;
return this;
}
public Builder setWidth(final int width) {
this.width = width;
return this;
}
public Builder setThumbnailUrl(final String thumbnailUrl) {
this.thumbnailUrl = thumbnailUrl;
return this;
}
public PostChild build() {
return new PostChild(postId, shortCode, itemType, displayUrl, thumbnailUrl, videoViews, height, width);
}
}
public PostChild(final String postId,
final String shortCode,
final MediaItemType itemType,
final String displayUrl,
final String thumbnailUrl,
final long videoViews,
final int height,
final int width) {
this.postId = postId;
this.shortCode = shortCode;
this.itemType = itemType;
this.displayUrl = displayUrl;
this.thumbnailUrl = thumbnailUrl;
this.height = height;
this.width = width;
this.videoViews = videoViews;
}
public String getPostId() {
return postId;
}
public String getShortCode() {
return shortCode;
}
public MediaItemType getItemType() {
return itemType;
}
public String getDisplayUrl() {
return displayUrl;
}
public String getThumbnailUrl() {
return thumbnailUrl;
}
public long getVideoViews() {
return videoViews;
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
@Override
public String toString() {
return "PostChild{" +
"postId='" + postId + '\'' +
", shortCode=" + shortCode +
", itemType=" + itemType +
", displayUrl='" + displayUrl + '\'' +
", thumbnailUrl='" + thumbnailUrl + '\'' +
", videoViews=" + videoViews +
", width=" + width +
", height=" + height +
'}';
}
}

View File

@ -1,64 +0,0 @@
package awais.instagrabber.models;
import awais.instagrabber.models.enums.MediaItemType;
public class PostModel extends BasePostModel {
protected final String thumbnailUrl;
protected String endCursor;
protected boolean hasNextPage;
public PostModel(final String shortCode, final boolean isid) {
if (!isid) this.shortCode = shortCode;
else this.postId = shortCode;
this.thumbnailUrl = null;
}
public PostModel(final MediaItemType itemType,
final String postId,
final String displayUrl,
final String thumbnailUrl,
final String shortCode,
final CharSequence postCaption,
final String captionId,
long timestamp,
boolean liked,
boolean bookmarked) {
this.itemType = itemType;
this.postId = postId;
this.displayUrl = displayUrl;
this.thumbnailUrl = thumbnailUrl;
this.shortCode = shortCode;
this.postCaption = postCaption;
this.captionId = captionId;
this.timestamp = timestamp;
this.liked = liked;
this.saved = bookmarked;
}
public String getThumbnailUrl() {
return thumbnailUrl;
}
public String getEndCursor() {
return endCursor;
}
public boolean hasNextPage() {
return endCursor != null && hasNextPage;
}
public void setPostCaption(final CharSequence postCaption) {
this.postCaption = postCaption;
}
public void setTimestamp(final long timestamp) {
this.timestamp = timestamp;
}
public void setPageCursor(final boolean hasNextPage, final String endCursor) {
this.endCursor = endCursor;
this.hasNextPage = hasNextPage;
}
}

View File

@ -1,118 +0,0 @@
package awais.instagrabber.models;
import java.io.Serializable;
public final class ProfileModel implements Serializable {
private final boolean isPrivate, reallyPrivate, isVerified, following, follower, restricted, blocked, requested;
private final long postCount, followersCount, followingCount;
private final String id, username, name, biography, url, sdProfilePic, hdProfilePic;
public ProfileModel(final boolean isPrivate, final boolean reallyPrivate,
final boolean isVerified, final String id, final String username, final String name, final String biography,
final String url, final String sdProfilePic, final String hdProfilePic, final long postCount,
final long followersCount, final long followingCount, final boolean following, final boolean follower,
final boolean restricted, final boolean blocked, final boolean requested) {
this.isPrivate = isPrivate;
this.reallyPrivate = reallyPrivate;
this.isVerified = isVerified;
this.id = id;
this.url = url;
this.name = name;
this.username = username;
this.biography = biography;
this.sdProfilePic = sdProfilePic;
this.hdProfilePic = hdProfilePic;
this.postCount = postCount;
this.followersCount = followersCount;
this.followingCount = followingCount;
this.following = following;
this.follower = follower;
this.restricted = restricted;
this.blocked = blocked;
this.requested = requested;
}
public static ProfileModel getDefaultProfileModel() {
return new ProfileModel(false, false, false, null, null, null, null, null, null, null, 0, 0, 0, false, false, false, false, false);
}
public static ProfileModel getDefaultProfileModel(final String userId) {
return new ProfileModel(false, false, false, userId, null, null, null, null, null, null, 0, 0, 0, false, false, false, false, false);
}
public static ProfileModel getDefaultProfileModel(final String userId, final String username) {
return new ProfileModel(false, false, false, userId, username, null, null, null, null, null, 0, 0, 0, false, false, false, false, false);
}
public boolean isPrivate() {
return isPrivate;
}
public boolean isReallyPrivate() {
return reallyPrivate;
}
public boolean isVerified() {
return isVerified;
}
public String getId() {
return id;
}
public String getUsername() {
return username;
}
public String getName() {
return name;
}
public String getBiography() {
return biography;
}
public String getUrl() {
return url;
}
public String getSdProfilePic() {
return sdProfilePic;
}
public String getHdProfilePic() {
return hdProfilePic;
}
public Long getPostCount() {
return postCount;
}
public Long getFollowersCount() {
return followersCount;
}
public Long getFollowingCount() {
return followingCount;
}
public boolean isFollowing() {
return following;
}
public boolean isFollower() {
return follower;
}
public boolean isRestricted() {
return restricted;
}
public boolean isBlocked() {
return blocked;
}
public boolean isRequested() {
return requested;
}
}

View File

@ -14,7 +14,7 @@ public final class StoryModel implements Serializable {
private final String storyUrl;
private String thumbnail;
private final String username;
private final String userId;
private final long userId;
private final MediaItemType itemType;
private final long timestamp;
private String videoUrl;
@ -32,7 +32,7 @@ public final class StoryModel implements Serializable {
private final boolean canReply;
public StoryModel(final String storyMediaId, final String storyUrl, final String thumbnail, final MediaItemType itemType,
final long timestamp, final String username, final String userId, final boolean canReply) {
final long timestamp, final String username, final long userId, final boolean canReply) {
this.storyMediaId = storyMediaId;
this.storyUrl = storyUrl;
this.thumbnail = thumbnail;
@ -161,7 +161,7 @@ public final class StoryModel implements Serializable {
return username;
}
public String getUserId() {
public long getUserId() {
return userId;
}
}

View File

@ -2,14 +2,16 @@ package awais.instagrabber.models;
import java.io.Serializable;
import awais.instagrabber.repositories.responses.Media;
public class TopicCluster implements Serializable {
private String id;
private String title;
private String type;
private boolean canMute;
private boolean isMuted;
private int rankedPosition;
private FeedModel coverMedia;
private final String id;
private final String title;
private final String type;
private final boolean canMute;
private final boolean isMuted;
private final int rankedPosition;
private final Media coverMedia;
public TopicCluster(final String id,
final String title,
@ -17,7 +19,7 @@ public class TopicCluster implements Serializable {
final boolean canMute,
final boolean isMuted,
final int rankedPosition,
final FeedModel coverMedia) {
final Media coverMedia) {
this.id = id;
this.title = title;
this.type = type;
@ -51,7 +53,7 @@ public class TopicCluster implements Serializable {
return rankedPosition;
}
public FeedModel getCoverMedia() {
public Media getCoverMedia() {
return coverMedia;
}
}

View File

@ -1,219 +0,0 @@
package awais.instagrabber.models;
import awais.instagrabber.models.enums.MediaItemType;
public final class ViewerPostModel extends BasePostModel {
protected final ProfileModel profileModel;
protected final String locationName;
protected final String location;
protected final long videoViews;
private final String thumbnailUrl;
protected long commentsCount;
protected long likes;
private int imageWidth;
private int imageHeight;
private boolean isCurrentSlide = false;
public static class Builder {
private MediaItemType itemType;
private String postId;
private String displayUrl;
private String shortCode;
private String postCaption;
private ProfileModel profileModel;
private long videoViews;
private long timestamp;
private boolean liked;
private boolean bookmarked;
private long likes;
private String locationName;
private String location;
private String thumbnailUrl;
private int imageWidth;
private int imageHeight;
public Builder setItemType(final MediaItemType itemType) {
this.itemType = itemType;
return this;
}
public Builder setPostId(final String postId) {
this.postId = postId;
return this;
}
public Builder setDisplayUrl(final String displayUrl) {
this.displayUrl = displayUrl;
return this;
}
public Builder setShortCode(final String shortCode) {
this.shortCode = shortCode;
return this;
}
// public Builder setPostCaption(final String postCaption) {
// this.postCaption = postCaption;
// return this;
// }
// public Builder setProfileModel(final ProfileModel profileModel) {
// this.profileModel = profileModel;
// return this;
// }
public Builder setVideoViews(final long videoViews) {
this.videoViews = videoViews;
return this;
}
// public Builder setTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public Builder setLiked(final boolean liked) {
// this.liked = liked;
// return this;
// }
//
// public Builder setBookmarked(final boolean bookmarked) {
// this.bookmarked = bookmarked;
// return this;
// }
//
// public Builder setLikes(final long likes) {
// this.likes = likes;
// return this;
// }
// public Builder setLocationName(final String locationName) {
// this.locationName = locationName;
// return this;
// }
//
// public Builder setLocation(final String location) {
// this.location = location;
// return this;
// }
public Builder setImageHeight(final int imageHeight) {
this.imageHeight = imageHeight;
return this;
}
public Builder setImageWidth(final int imageWidth) {
this.imageWidth = imageWidth;
return this;
}
public Builder setThumbnailUrl(final String thumbnailUrl) {
this.thumbnailUrl = thumbnailUrl;
return this;
}
public ViewerPostModel build() {
return new ViewerPostModel(itemType, postId, displayUrl, thumbnailUrl, imageHeight, imageWidth, shortCode, postCaption, profileModel,
videoViews, timestamp, liked, bookmarked, likes, locationName, location);
}
}
public ViewerPostModel(final MediaItemType itemType,
final String postId,
final String displayUrl,
final String thumbnailUrl,
final int imageHeight,
final int imageWidth,
final String shortCode,
final String postCaption,
final ProfileModel profileModel,
final long videoViews,
final long timestamp,
boolean liked,
boolean bookmarked,
long likes,
final String locationName,
final String location) {
this.itemType = itemType;
this.postId = postId;
this.displayUrl = displayUrl;
this.thumbnailUrl = thumbnailUrl;
this.imageHeight = imageHeight;
this.imageWidth = imageWidth;
this.postCaption = postCaption;
this.profileModel = profileModel;
this.shortCode = shortCode;
this.videoViews = videoViews;
this.timestamp = timestamp;
this.liked = liked;
this.likes = likes;
this.saved = bookmarked;
this.locationName = locationName;
this.location = location;
}
public long getCommentsCount() {
return commentsCount;
}
public ProfileModel getProfileModel() {
return profileModel;
}
public String getLocationName() {
return locationName;
}
public String getLocation() {
return location;
}
public final long getVideoViews() {
return videoViews;
}
public long getLikes() {
return likes;
}
// setManualLike means user liked from InstaGrabber
public void setManualLike(final boolean like) {
liked = like;
likes = (like) ? (likes + 1) : (likes - 1);
}
public boolean isCurrentSlide() {
return isCurrentSlide;
}
public String getThumbnailUrl() {
return thumbnailUrl;
}
public int getImageHeight() {
return imageHeight;
}
public int getImageWidth() {
return imageWidth;
}
@Override
public String toString() {
return "ViewerPostModel{" +
"type=" + itemType +
", displayUrl=" + displayUrl +
", thumbnailUrl=" + thumbnailUrl +
", locationName='" + locationName + '\'' +
", location='" + location + '\'' +
", videoViews=" + videoViews +
", thumbnailUrl='" + thumbnailUrl + '\'' +
", commentsCount=" + commentsCount +
", likes=" + likes +
", imageWidth=" + imageWidth +
", imageHeight=" + imageHeight +
", isCurrentSlide=" + isCurrentSlide +
'}';
}
}

Some files were not shown because too many files have changed in this diff Show More