Browse Source
Added post viewer fragment. Updated almost all places to use this
Added post viewer fragment. Updated almost all places to use this
Remaining places are SavedViewer and DirectMessageThreadFragmentrenovate/org.robolectric-robolectric-4.x
Ammar Githam
4 years ago
56 changed files with 3003 additions and 757 deletions
-
168app/src/main/java/awais/instagrabber/MainHelper.java
-
8app/src/main/java/awais/instagrabber/activities/MainActivityBackup.java
-
197app/src/main/java/awais/instagrabber/activities/PostViewer.java
-
92app/src/main/java/awais/instagrabber/activities/ProfileViewer.java
-
27app/src/main/java/awais/instagrabber/activities/SavedViewer.java
-
77app/src/main/java/awais/instagrabber/adapters/PostViewAdapter.java
-
203app/src/main/java/awais/instagrabber/adapters/PostViewerChildAdapter.java
-
199app/src/main/java/awais/instagrabber/adapters/viewholder/PostViewerViewHolder.java
-
24app/src/main/java/awais/instagrabber/adapters/viewholder/feed/FeedItemViewHolder.java
-
22app/src/main/java/awais/instagrabber/asyncs/DiscoverFetcher.java
-
55app/src/main/java/awais/instagrabber/asyncs/FeedFetcher.java
-
44app/src/main/java/awais/instagrabber/asyncs/LocationFetcher.java
-
6app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java
-
33app/src/main/java/awais/instagrabber/asyncs/PostsFetcher.java
-
2app/src/main/java/awais/instagrabber/asyncs/direct_messages/DirectThreadBroadcaster.java
-
109app/src/main/java/awais/instagrabber/asyncs/i/iPostFetcher.java
-
112app/src/main/java/awais/instagrabber/customviews/helpers/NestedScrollableHost.java
-
13app/src/main/java/awais/instagrabber/customviews/helpers/RecyclerLazyLoader.java
-
2app/src/main/java/awais/instagrabber/directdownload/DirectDownload.java
-
2app/src/main/java/awais/instagrabber/directdownload/MultiDirectDialog.java
-
50app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java
-
113app/src/main/java/awais/instagrabber/fragments/LocationFragment.java
-
287app/src/main/java/awais/instagrabber/fragments/PostViewFragment.java
-
574app/src/main/java/awais/instagrabber/fragments/PostViewFragmentBackup.java
-
80app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java
-
16app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageInboxFragment.java
-
6app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java
-
42app/src/main/java/awais/instagrabber/fragments/main/DiscoverFragment.java
-
96app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java
-
516app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java
-
19app/src/main/java/awais/instagrabber/fragments/main/viewmodels/BasePostViewModel.java
-
3app/src/main/java/awais/instagrabber/fragments/main/viewmodels/DiscoverItemViewModel.java
-
3app/src/main/java/awais/instagrabber/fragments/main/viewmodels/FeedViewModel.java
-
3app/src/main/java/awais/instagrabber/fragments/main/viewmodels/PostsViewModel.java
-
18app/src/main/java/awais/instagrabber/fragments/main/viewmodels/ViewerPostViewModel.java
-
4app/src/main/java/awais/instagrabber/interfaces/ItemGetter.java
-
4app/src/main/java/awais/instagrabber/models/BasePostModel.java
-
54app/src/main/java/awais/instagrabber/models/FeedModel.java
-
31app/src/main/java/awais/instagrabber/models/LocationModel.java
-
4app/src/main/java/awais/instagrabber/models/ProfileModel.java
-
32app/src/main/java/awais/instagrabber/models/ViewerPostModel.java
-
23app/src/main/java/awais/instagrabber/models/ViewerPostModelWrapper.java
-
0app/src/main/java/awais/instagrabber/models/enums/PostItemType.java
-
12app/src/main/java/awais/instagrabber/services/LoggingInterceptor.java
-
4app/src/main/java/awais/instagrabber/utils/LocaleUtils.java
-
4app/src/main/res/layout/fragment_post_view.xml
-
5app/src/main/res/layout/item_feed_bottom.xml
-
4app/src/main/res/layout/item_feed_top.xml
-
105app/src/main/res/layout/item_full_post_view.xml
-
44app/src/main/res/layout/item_full_post_view_bk.xml
-
20app/src/main/res/navigation/discover_nav_graph.xml
-
40app/src/main/res/navigation/feed_nav_graph.xml
-
15app/src/main/res/navigation/hashtag_nav_graph.xml
-
42app/src/main/res/navigation/location_nav_graph.xml
-
67app/src/main/res/navigation/post_view_nav_graph.xml
-
25app/src/main/res/navigation/profile_nav_graph.xml
@ -0,0 +1,77 @@ |
|||
package awais.instagrabber.adapters; |
|||
|
|||
import android.view.LayoutInflater; |
|||
import android.view.View; |
|||
import android.view.ViewGroup; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
import androidx.recyclerview.widget.DiffUtil; |
|||
import androidx.recyclerview.widget.ListAdapter; |
|||
|
|||
import java.util.Arrays; |
|||
|
|||
import awais.instagrabber.adapters.viewholder.PostViewerViewHolder; |
|||
import awais.instagrabber.databinding.ItemFullPostViewBinding; |
|||
import awais.instagrabber.interfaces.MentionClickListener; |
|||
import awais.instagrabber.models.ViewerPostModelWrapper; |
|||
|
|||
public class PostViewAdapter extends ListAdapter<ViewerPostModelWrapper, PostViewerViewHolder> { |
|||
private final OnPostViewChildViewClickListener clickListener; |
|||
private final OnPostCaptionLongClickListener longClickListener; |
|||
private final MentionClickListener mentionClickListener; |
|||
|
|||
private static final DiffUtil.ItemCallback<ViewerPostModelWrapper> diffCallback = new DiffUtil.ItemCallback<ViewerPostModelWrapper>() { |
|||
@Override |
|||
public boolean areItemsTheSame(@NonNull final ViewerPostModelWrapper oldItem, |
|||
@NonNull final ViewerPostModelWrapper newItem) { |
|||
return oldItem.getPosition() == newItem.getPosition(); |
|||
} |
|||
|
|||
@Override |
|||
public boolean areContentsTheSame(@NonNull final ViewerPostModelWrapper oldItem, |
|||
@NonNull final ViewerPostModelWrapper newItem) { |
|||
return Arrays.equals(oldItem.getViewerPostModels(), newItem.getViewerPostModels()); |
|||
} |
|||
}; |
|||
|
|||
public PostViewAdapter(final OnPostViewChildViewClickListener clickListener, |
|||
final OnPostCaptionLongClickListener longClickListener, |
|||
final MentionClickListener mentionClickListener) { |
|||
super(diffCallback); |
|||
this.clickListener = clickListener; |
|||
this.longClickListener = longClickListener; |
|||
this.mentionClickListener = mentionClickListener; |
|||
} |
|||
|
|||
@Override |
|||
public void onViewDetachedFromWindow(@NonNull final PostViewerViewHolder holder) { |
|||
holder.stopPlayingVideo(); |
|||
} |
|||
|
|||
@NonNull |
|||
@Override |
|||
public PostViewerViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, |
|||
final int viewType) { |
|||
final LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext()); |
|||
final ItemFullPostViewBinding binding = ItemFullPostViewBinding |
|||
.inflate(layoutInflater, parent, false); |
|||
return new PostViewerViewHolder(binding); |
|||
} |
|||
|
|||
@Override |
|||
public void onBindViewHolder(@NonNull final PostViewerViewHolder holder, final int position) { |
|||
final ViewerPostModelWrapper item = getItem(position); |
|||
holder.bind(item, position, clickListener, longClickListener, mentionClickListener); |
|||
} |
|||
|
|||
public interface OnPostViewChildViewClickListener { |
|||
void onClick(View v, |
|||
ViewerPostModelWrapper viewerPostModelWrapper, |
|||
int postPosition, |
|||
int childPosition); |
|||
} |
|||
|
|||
public interface OnPostCaptionLongClickListener { |
|||
void onLongClick(String text); |
|||
} |
|||
} |
@ -0,0 +1,203 @@ |
|||
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.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(Uri.parse(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.prepare(mediaSource); |
|||
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); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,199 @@ |
|||
package awais.instagrabber.adapters.viewholder; |
|||
|
|||
import android.util.Log; |
|||
import android.view.View; |
|||
import android.widget.TextView; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
import androidx.recyclerview.widget.RecyclerView; |
|||
import androidx.viewpager2.widget.ViewPager2; |
|||
|
|||
import com.google.android.exoplayer2.Player; |
|||
import com.google.android.exoplayer2.SimpleExoPlayer; |
|||
import com.google.android.exoplayer2.ui.PlayerView; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
import awais.instagrabber.R; |
|||
import awais.instagrabber.adapters.PostViewAdapter.OnPostCaptionLongClickListener; |
|||
import awais.instagrabber.adapters.PostViewAdapter.OnPostViewChildViewClickListener; |
|||
import awais.instagrabber.adapters.PostViewerChildAdapter; |
|||
import awais.instagrabber.databinding.ItemFullPostViewBinding; |
|||
import awais.instagrabber.interfaces.MentionClickListener; |
|||
import awais.instagrabber.models.ProfileModel; |
|||
import awais.instagrabber.models.ViewerPostModel; |
|||
import awais.instagrabber.models.ViewerPostModelWrapper; |
|||
import awais.instagrabber.models.enums.MediaItemType; |
|||
import awais.instagrabber.utils.Utils; |
|||
|
|||
public class PostViewerViewHolder extends RecyclerView.ViewHolder { |
|||
private static final String TAG = "PostViewerViewHolder"; |
|||
|
|||
private final ItemFullPostViewBinding binding; |
|||
private int currentChildPosition; |
|||
|
|||
public PostViewerViewHolder(@NonNull final ItemFullPostViewBinding binding) { |
|||
super(binding.getRoot()); |
|||
this.binding = binding; |
|||
binding.topPanel.viewStoryPost.setVisibility(View.GONE); |
|||
} |
|||
|
|||
public void bind(final ViewerPostModelWrapper wrapper, |
|||
final int position, |
|||
final OnPostViewChildViewClickListener clickListener, |
|||
final OnPostCaptionLongClickListener longClickListener, |
|||
final MentionClickListener mentionClickListener) { |
|||
if (wrapper == null) return; |
|||
final ViewerPostModel[] items = wrapper.getViewerPostModels(); |
|||
if (items == null || items.length <= 0) return; |
|||
if (items[0] == null) return; |
|||
final PostViewerChildAdapter adapter = new PostViewerChildAdapter(); |
|||
binding.mediaViewPager.setAdapter(adapter); |
|||
final ViewerPostModel firstPost = items[0]; |
|||
setPostInfo(firstPost, mentionClickListener); |
|||
setMediaItems(items, adapter); |
|||
setupListeners(wrapper, |
|||
position, |
|||
clickListener, |
|||
longClickListener, |
|||
mentionClickListener, |
|||
firstPost.getLocation()); |
|||
} |
|||
|
|||
private void setPostInfo(final ViewerPostModel firstPost, |
|||
final MentionClickListener mentionClickListener) { |
|||
final ProfileModel profileModel = firstPost.getProfileModel(); |
|||
if (profileModel == null) return; |
|||
binding.topPanel.title.setText(profileModel.getUsername()); |
|||
final String locationName = firstPost.getLocationName(); |
|||
if (!Utils.isEmpty(locationName)) { |
|||
binding.topPanel.location.setVisibility(View.VISIBLE); |
|||
binding.topPanel.location.setText(locationName); |
|||
} else binding.topPanel.location.setVisibility(View.GONE); |
|||
binding.topPanel.ivProfilePic.setImageURI(profileModel.getSdProfilePic()); |
|||
binding.bottomPanel.commentsCount.setText(String.valueOf(firstPost.getCommentsCount())); |
|||
final CharSequence postCaption = firstPost.getPostCaption(); |
|||
if (Utils.hasMentions(postCaption)) { |
|||
binding.bottomPanel.viewerCaption |
|||
.setText(Utils.getMentionText(postCaption), TextView.BufferType.SPANNABLE); |
|||
binding.bottomPanel.viewerCaption.setMentionClickListener(mentionClickListener); |
|||
} else { |
|||
binding.bottomPanel.viewerCaption.setMentionClickListener(null); |
|||
binding.bottomPanel.viewerCaption.setText(postCaption); |
|||
} |
|||
binding.bottomPanel.tvPostDate.setText(firstPost.getPostDate()); |
|||
} |
|||
|
|||
private void setupListeners(final ViewerPostModelWrapper wrapper, |
|||
final int position, |
|||
final OnPostViewChildViewClickListener clickListener, |
|||
final OnPostCaptionLongClickListener longClickListener, |
|||
final MentionClickListener mentionClickListener, |
|||
final String location) { |
|||
final View.OnClickListener onClickListener = v -> clickListener |
|||
.onClick(v, wrapper, position, currentChildPosition); |
|||
binding.bottomPanel.btnComments.setOnClickListener(onClickListener); |
|||
binding.topPanel.title.setOnClickListener(onClickListener); |
|||
binding.topPanel.ivProfilePic.setOnClickListener(onClickListener); |
|||
binding.bottomPanel.btnDownload.setOnClickListener(onClickListener); |
|||
binding.bottomPanel.viewerCaption.setOnClickListener(onClickListener); |
|||
binding.bottomPanel.viewerCaption.setOnLongClickListener(v -> { |
|||
longClickListener.onLongClick(binding.bottomPanel.viewerCaption.getText().toString()); |
|||
return true; |
|||
}); |
|||
if (!Utils.isEmpty(location)) { |
|||
binding.topPanel.location.setOnClickListener(v -> mentionClickListener |
|||
.onClick(binding.topPanel.location, location, false, true)); |
|||
} |
|||
} |
|||
|
|||
private void setMediaItems(final ViewerPostModel[] items, |
|||
final PostViewerChildAdapter adapter) { |
|||
final List<ViewerPostModel> filteredList = new ArrayList<>(); |
|||
for (final ViewerPostModel model : items) { |
|||
final MediaItemType itemType = model.getItemType(); |
|||
if (itemType == MediaItemType.MEDIA_TYPE_VIDEO || itemType == MediaItemType.MEDIA_TYPE_IMAGE) { |
|||
filteredList.add(model); |
|||
} |
|||
} |
|||
binding.mediaCounter.setVisibility(filteredList.size() > 1 ? View.VISIBLE : View.GONE); |
|||
final String counter = "1/" + filteredList.size(); |
|||
binding.mediaCounter.setText(counter); |
|||
adapter.submitList(filteredList); |
|||
binding.mediaViewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { |
|||
@Override |
|||
public void onPageSelected(final int position) { |
|||
if (filteredList.size() <= 0 || position >= filteredList.size()) return; |
|||
currentChildPosition = position; |
|||
final String counter = (position + 1) + "/" + filteredList.size(); |
|||
binding.mediaCounter.setText(counter); |
|||
final ViewerPostModel viewerPostModel = filteredList.get(position); |
|||
if (viewerPostModel.getItemType() == MediaItemType.MEDIA_TYPE_VIDEO) { |
|||
setVideoDetails(viewerPostModel); |
|||
setVolumeListener(position); |
|||
return; |
|||
} |
|||
setImageDetails(); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
private void setVolumeListener(final int position) { |
|||
binding.bottomPanel.btnMute.setOnClickListener(v -> { |
|||
try { |
|||
final RecyclerView.ViewHolder viewHolder = ((RecyclerView) binding.mediaViewPager |
|||
.getChildAt(0)).findViewHolderForAdapterPosition(position); |
|||
if (viewHolder != null) { |
|||
final View itemView = viewHolder.itemView; |
|||
if (itemView instanceof PlayerView) { |
|||
final SimpleExoPlayer player = (SimpleExoPlayer) ((PlayerView) itemView) |
|||
.getPlayer(); |
|||
if (player == null) return; |
|||
final float vol = player.getVolume() == 0f ? 1f : 0f; |
|||
player.setVolume(vol); |
|||
binding.bottomPanel.btnMute |
|||
.setImageResource(vol == 0f ? R.drawable.ic_volume_up_24 : R.drawable.ic_volume_off_24); |
|||
Utils.sessionVolumeFull = vol == 1f; |
|||
} |
|||
} |
|||
} catch (Exception e) { |
|||
Log.e(TAG, "Error", e); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
private void setImageDetails() { |
|||
binding.bottomPanel.btnMute.setVisibility(View.GONE); |
|||
binding.bottomPanel.videoViewsContainer.setVisibility(View.GONE); |
|||
} |
|||
|
|||
private void setVideoDetails(final ViewerPostModel viewerPostModel) { |
|||
binding.bottomPanel.btnMute.setVisibility(View.VISIBLE); |
|||
final long videoViews = viewerPostModel.getVideoViews(); |
|||
if (videoViews < 0) { |
|||
binding.bottomPanel.videoViewsContainer.setVisibility(View.GONE); |
|||
return; |
|||
} |
|||
binding.bottomPanel.tvVideoViews.setText(String.valueOf(videoViews)); |
|||
binding.bottomPanel.videoViewsContainer.setVisibility(View.VISIBLE); |
|||
} |
|||
|
|||
public void stopPlayingVideo() { |
|||
try { |
|||
final RecyclerView.ViewHolder viewHolder = ((RecyclerView) binding.mediaViewPager |
|||
.getChildAt(0)).findViewHolderForAdapterPosition(currentChildPosition); |
|||
if (viewHolder != null) { |
|||
final View itemView = viewHolder.itemView; |
|||
if (itemView instanceof PlayerView) { |
|||
final Player player = ((PlayerView) itemView).getPlayer(); |
|||
if (player != null) { |
|||
player.setPlayWhenReady(false); |
|||
} |
|||
} |
|||
} |
|||
} catch (Exception e) { |
|||
Log.e(TAG, "Error", e); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,112 @@ |
|||
package awais.instagrabber.customviews.helpers; |
|||
|
|||
import android.content.Context; |
|||
import android.util.AttributeSet; |
|||
import android.view.MotionEvent; |
|||
import android.view.View; |
|||
import android.view.ViewConfiguration; |
|||
import android.widget.FrameLayout; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
import androidx.annotation.Nullable; |
|||
import androidx.viewpager2.widget.ViewPager2; |
|||
|
|||
import static androidx.viewpager2.widget.ViewPager2.ORIENTATION_HORIZONTAL; |
|||
|
|||
public class NestedScrollableHost extends FrameLayout { |
|||
|
|||
private int touchSlop; |
|||
private float initialX = 0f; |
|||
private float initialY = 0f; |
|||
|
|||
public NestedScrollableHost(@NonNull final Context context) { |
|||
this(context, null); |
|||
} |
|||
|
|||
public NestedScrollableHost(@NonNull final Context context, @Nullable final AttributeSet attrs) { |
|||
super(context, attrs); |
|||
touchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); |
|||
} |
|||
|
|||
@Override |
|||
public boolean onInterceptTouchEvent(final MotionEvent ev) { |
|||
handleInterceptTouchEvent(ev); |
|||
return super.onInterceptTouchEvent(ev); |
|||
} |
|||
|
|||
private void handleInterceptTouchEvent(final MotionEvent e) { |
|||
if (getParentViewPager() == null) return; |
|||
final int orientation = getParentViewPager().getOrientation(); |
|||
// Early return if child can't scroll in same direction as parent |
|||
if (!canChildScroll(orientation, -1f) && !canChildScroll(orientation, 1f)) return; |
|||
|
|||
if (e.getAction() == MotionEvent.ACTION_DOWN) { |
|||
initialX = e.getX(); |
|||
initialY = e.getY(); |
|||
getParent().requestDisallowInterceptTouchEvent(true); |
|||
} else if (e.getAction() == MotionEvent.ACTION_MOVE) { |
|||
final float dx = e.getX() - initialX; |
|||
final float dy = e.getY() - initialY; |
|||
final boolean isVpHorizontal = orientation == ORIENTATION_HORIZONTAL; |
|||
|
|||
// assuming ViewPager2 touch-slop is 2x touch-slop of child |
|||
final float scaledDx = Math.abs(dx) * (isVpHorizontal ? .5f : 1f); |
|||
final float scaledDy = Math.abs(dy) * (isVpHorizontal ? 1f : .5f); |
|||
|
|||
if (scaledDx > touchSlop || scaledDy > touchSlop) { |
|||
if (isVpHorizontal == (scaledDy > scaledDx)) { |
|||
// Gesture is perpendicular, allow all parents to intercept |
|||
getParent().requestDisallowInterceptTouchEvent(false); |
|||
} else { |
|||
// Gesture is parallel, query child if movement in that direction is possible |
|||
if (canChildScroll(orientation, (isVpHorizontal ? dx : dy))) { |
|||
// Child can scroll, disallow all parents to intercept |
|||
getParent().requestDisallowInterceptTouchEvent(true); |
|||
} else { |
|||
// Child cannot scroll, allow all parents to intercept |
|||
getParent().requestDisallowInterceptTouchEvent(false); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
private boolean canChildScroll(final int orientation, final float delta) { |
|||
final int direction = -(int) Math.signum(delta); |
|||
final View child = getChild(); |
|||
if (child == null) return false; |
|||
ViewPager2 viewPagerChild = null; |
|||
if (child instanceof ViewPager2) { |
|||
viewPagerChild = (ViewPager2) child; |
|||
} |
|||
|
|||
boolean canScroll; |
|||
switch (orientation) { |
|||
case 0: |
|||
canScroll = child.canScrollHorizontally(direction); |
|||
break; |
|||
case 1: |
|||
canScroll = child.canScrollVertically(direction); |
|||
break; |
|||
default: |
|||
throw new IllegalArgumentException(); |
|||
} |
|||
if (!canScroll || viewPagerChild == null || viewPagerChild.getAdapter() == null) |
|||
return canScroll; |
|||
// check if viewpager has reached its limits and decide accordingly |
|||
return (direction < 0 && viewPagerChild.getCurrentItem() > 0) |
|||
|| (direction > 0 && viewPagerChild.getCurrentItem() < viewPagerChild.getAdapter().getItemCount() - 1); |
|||
} |
|||
|
|||
public ViewPager2 getParentViewPager() { |
|||
View v = (View) getParent(); |
|||
while (v != null && !(v instanceof ViewPager2)) { |
|||
v = (View) v.getParent(); |
|||
} |
|||
return (ViewPager2) v; |
|||
} |
|||
|
|||
public View getChild() { |
|||
return getChildCount() > 0 ? getChildAt(0) : null; |
|||
} |
|||
} |
@ -0,0 +1,287 @@ |
|||
package awais.instagrabber.fragments; |
|||
|
|||
import android.content.DialogInterface; |
|||
import android.content.Intent; |
|||
import android.content.pm.PackageManager; |
|||
import android.os.AsyncTask; |
|||
import android.os.Bundle; |
|||
import android.util.Log; |
|||
import android.view.LayoutInflater; |
|||
import android.view.View; |
|||
import android.view.ViewGroup; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
import androidx.annotation.Nullable; |
|||
import androidx.appcompat.app.AlertDialog; |
|||
import androidx.fragment.app.Fragment; |
|||
import androidx.fragment.app.FragmentActivity; |
|||
import androidx.lifecycle.ViewModelProvider; |
|||
import androidx.navigation.NavDirections; |
|||
import androidx.navigation.fragment.NavHostFragment; |
|||
import androidx.viewpager2.widget.ViewPager2; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.Arrays; |
|||
import java.util.Collections; |
|||
import java.util.List; |
|||
|
|||
import awais.instagrabber.R; |
|||
import awais.instagrabber.activities.CommentsViewer; |
|||
import awais.instagrabber.adapters.PostViewAdapter; |
|||
import awais.instagrabber.adapters.PostViewAdapter.OnPostViewChildViewClickListener; |
|||
import awais.instagrabber.asyncs.PostFetcher; |
|||
import awais.instagrabber.asyncs.i.iPostFetcher; |
|||
import awais.instagrabber.databinding.FragmentPostViewBinding; |
|||
import awais.instagrabber.fragments.main.viewmodels.ViewerPostViewModel; |
|||
import awais.instagrabber.interfaces.FetchListener; |
|||
import awais.instagrabber.interfaces.MentionClickListener; |
|||
import awais.instagrabber.models.ViewerPostModel; |
|||
import awais.instagrabber.models.ViewerPostModelWrapper; |
|||
import awais.instagrabber.models.enums.DownloadMethod; |
|||
import awais.instagrabber.utils.Constants; |
|||
import awais.instagrabber.utils.Utils; |
|||
|
|||
import static androidx.core.content.ContextCompat.checkSelfPermission; |
|||
import static awais.instagrabber.utils.Utils.settingsHelper; |
|||
|
|||
public class PostViewFragment extends Fragment { |
|||
private static final String TAG = "PostViewFragment"; |
|||
|
|||
private FragmentActivity fragmentActivity; |
|||
private FragmentPostViewBinding binding; |
|||
private ViewPager2 root; |
|||
private boolean shouldRefresh = true; |
|||
private ViewerPostViewModel viewerPostViewModel; |
|||
private boolean isId; |
|||
private int currentPostIndex; |
|||
private List<String> idOrCodeList; |
|||
private boolean hasInitialResult = false; |
|||
private PostViewAdapter adapter; |
|||
private boolean session; |
|||
|
|||
private FetchListener<ViewerPostModel[]> pfl = result -> { |
|||
if (result == null) return; |
|||
if (result.length <= 0) return; |
|||
final List<ViewerPostModelWrapper> viewerPostModels = viewerPostViewModel.getList() |
|||
.getValue(); |
|||
final List<ViewerPostModelWrapper> temp = viewerPostModels == null ? new ArrayList<>( |
|||
idOrCodeList.size()) : new ArrayList<>(viewerPostModels); |
|||
final ViewerPostModel firstPost = result[0]; |
|||
if (firstPost == null) return; |
|||
String idOrCode = isId ? firstPost.getPostId() : firstPost.getShortCode(); |
|||
if (idOrCode == null) return; |
|||
// some values are appended to the post/short code with `_` |
|||
idOrCode = idOrCode.substring(0, idOrCode.indexOf('_')); |
|||
final int index = idOrCodeList.indexOf(idOrCode); |
|||
if (index < 0) return; |
|||
final ViewerPostModelWrapper viewerPostModelWrapper = temp.get(index); |
|||
viewerPostModelWrapper.setViewerPostModels(result); |
|||
temp.set(index, viewerPostModelWrapper); |
|||
viewerPostViewModel.getList().setValue(temp); |
|||
adapter.notifyItemChanged(index); |
|||
if (!hasInitialResult) { |
|||
Log.d(TAG, "setting delayed position to: " + currentPostIndex); |
|||
binding.getRoot() |
|||
.postDelayed(() -> binding.getRoot().setCurrentItem(currentPostIndex), 200); |
|||
} |
|||
hasInitialResult = true; |
|||
}; |
|||
private MentionClickListener mentionListener = (view, text, isHashtag, isLocation) -> { |
|||
if (isHashtag) { |
|||
final NavDirections action = PostViewFragmentDirections |
|||
.actionGlobalHashTagFragment(text); |
|||
NavHostFragment.findNavController(this).navigate(action); |
|||
return; |
|||
} |
|||
if (isLocation) { |
|||
final NavDirections action = PostViewFragmentDirections |
|||
.actionGlobalLocationFragment(text); |
|||
NavHostFragment.findNavController(this).navigate(action); |
|||
return; |
|||
} |
|||
final NavDirections action = PostViewFragmentDirections |
|||
.actionGlobalProfileFragment("@" + text); |
|||
NavHostFragment.findNavController(this).navigate(action); |
|||
}; |
|||
private OnPostViewChildViewClickListener clickListener = (v, wrapper, postPosition, childPosition) -> { |
|||
// final FeedModel feedModel = (FeedModel) tag; |
|||
// if (v.getId() == ) { |
|||
// if (feedModel.isMentionClicked()) |
|||
// feedModel.toggleCaption(); |
|||
// feedModel.setMentionClicked(false); |
|||
// if (!FeedItemViewHolder.expandCollapseTextView((RamboTextView) v, feedModel.getPostCaption())) |
|||
// feedModel.toggleCaption(); |
|||
// return; |
|||
// } |
|||
final ViewerPostModel postModel = wrapper.getViewerPostModels()[0]; |
|||
final String username = postModel.getProfileModel().getUsername(); |
|||
final int id = v.getId(); |
|||
switch (id) { |
|||
case R.id.viewerCaption: |
|||
break; |
|||
case R.id.btnComments: |
|||
startActivity(new Intent(requireContext(), CommentsViewer.class) |
|||
.putExtra(Constants.EXTRAS_SHORTCODE, |
|||
postModel.getShortCode()) |
|||
.putExtra(Constants.EXTRAS_POST, postModel.getPostId()) |
|||
.putExtra(Constants.EXTRAS_USER, |
|||
Utils.getUserIdFromCookie(settingsHelper.getString( |
|||
Constants.COOKIE)))); |
|||
break; |
|||
case R.id.btnDownload: |
|||
if (checkSelfPermission(requireContext(), |
|||
Utils.PERMS[0]) == PackageManager.PERMISSION_GRANTED) { |
|||
showDownloadDialog(Arrays.asList(wrapper.getViewerPostModels()), |
|||
childPosition, |
|||
username); |
|||
return; |
|||
} |
|||
requestPermissions(Utils.PERMS, 8020); |
|||
break; |
|||
case R.id.ivProfilePic: |
|||
case R.id.title: |
|||
mentionListener.onClick(null, username, false, false); |
|||
break; |
|||
} |
|||
}; |
|||
private PostViewAdapter.OnPostCaptionLongClickListener captionLongClickListener = text -> Utils |
|||
.copyText(requireContext(), text); |
|||
|
|||
@Override |
|||
public void onCreate(@Nullable final Bundle savedInstanceState) { |
|||
super.onCreate(savedInstanceState); |
|||
fragmentActivity = getActivity(); |
|||
} |
|||
|
|||
@Nullable |
|||
@Override |
|||
public View onCreateView(@NonNull final LayoutInflater inflater, |
|||
@Nullable final ViewGroup container, |
|||
@Nullable final Bundle savedInstanceState) { |
|||
if (root != null) { |
|||
shouldRefresh = false; |
|||
return root; |
|||
} |
|||
binding = FragmentPostViewBinding.inflate(inflater, container, false); |
|||
root = binding.getRoot(); |
|||
setupViewPager(); |
|||
return root; |
|||
} |
|||
|
|||
@Override |
|||
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { |
|||
if (!shouldRefresh) return; |
|||
init(); |
|||
} |
|||
|
|||
private void setupViewPager() { |
|||
viewerPostViewModel = new ViewModelProvider(fragmentActivity) |
|||
.get(ViewerPostViewModel.class); |
|||
adapter = new PostViewAdapter(clickListener, captionLongClickListener, mentionListener); |
|||
root.setAdapter(adapter); |
|||
root.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { |
|||
|
|||
@Override |
|||
public void onPageSelected(final int position) { |
|||
// Log.d(TAG, "onPageSelected: " + position + ", hasInitialResult: " + hasInitialResult); |
|||
if (!hasInitialResult) { |
|||
return; |
|||
} |
|||
currentPostIndex = position; |
|||
fetchPost(); |
|||
} |
|||
}); |
|||
viewerPostViewModel.getList().observe(fragmentActivity, list -> adapter.submitList(list)); |
|||
} |
|||
|
|||
private void init() { |
|||
if (getArguments() == null) return; |
|||
final PostViewFragmentArgs fragmentArgs = PostViewFragmentArgs.fromBundle(getArguments()); |
|||
final String[] idOrCodeArray = fragmentArgs.getIdOrCodeArray(); |
|||
if (idOrCodeArray.length == 0) return; |
|||
currentPostIndex = fragmentArgs.getIndex(); |
|||
if (currentPostIndex < 0) return; |
|||
if (currentPostIndex >= idOrCodeArray.length) return; |
|||
idOrCodeList = Arrays.asList(idOrCodeArray); |
|||
viewerPostViewModel.getList().setValue(createPlaceholderModels(idOrCodeArray.length)); |
|||
isId = fragmentArgs.getIsId(); |
|||
// binding.getRoot().postDelayed(() -> binding.getRoot().setCurrentItem(currentPostIndex), 500); |
|||
fetchPost(); |
|||
// binding.getRoot().setCurrentItem(currentPostIndex); |
|||
} |
|||
|
|||
private List<ViewerPostModelWrapper> createPlaceholderModels(final int size) { |
|||
final List<ViewerPostModelWrapper> viewerPostModels = new ArrayList<>(size); |
|||
for (int i = 0; i < size; i++) { |
|||
// viewerPostModels.add(new ViewerPostModel[]{ViewerPostModel.getDefaultModel(-i, "")}); |
|||
viewerPostModels.add(new ViewerPostModelWrapper(i, null)); |
|||
} |
|||
return viewerPostModels; |
|||
} |
|||
|
|||
private void fetchPost() { |
|||
// Log.d(TAG, "fetchPost, currentPostIndex: " + currentPostIndex); |
|||
final List<ViewerPostModelWrapper> list = viewerPostViewModel.getList().getValue(); |
|||
if (list != null) { |
|||
final ViewerPostModelWrapper viewerPostModels = list.get(currentPostIndex); |
|||
if (viewerPostModels != null && viewerPostModels |
|||
.getViewerPostModels() != null && viewerPostModels |
|||
.getViewerPostModels().length > 0) { |
|||
// final ViewerPostModel viewerPostModel = viewerPostModels[0]; |
|||
// if (viewerPostModel != null) { |
|||
// final String postId = viewerPostModel.getPostId(); |
|||
// try { |
|||
// if (postId != null && Integer.parseInt(postId) > 0) { |
|||
// // already fetched, don't fetch again |
|||
// Log.d(TAG, "returning without fetching"); |
|||
// return; |
|||
// } |
|||
// } catch (NumberFormatException ignored) {} |
|||
// } |
|||
Log.d(TAG, "returning without fetching"); |
|||
return; |
|||
} |
|||
} |
|||
final String idOrShortCode = idOrCodeList.get(currentPostIndex); |
|||
if (isId) { |
|||
new iPostFetcher(idOrShortCode, pfl).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
|||
return; |
|||
} |
|||
new PostFetcher(idOrShortCode, pfl).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
|||
} |
|||
|
|||
private void showDownloadDialog(final List<ViewerPostModel> postModels, |
|||
final int childPosition, |
|||
final String username) { |
|||
final List<ViewerPostModel> postModelsToDownload = new ArrayList<>(); |
|||
if (!session && postModels.size() > 1) { |
|||
final DialogInterface.OnClickListener clickListener = (dialog, which) -> { |
|||
if (which == DialogInterface.BUTTON_NEGATIVE) { |
|||
postModelsToDownload.addAll(postModels); |
|||
} else if (which == DialogInterface.BUTTON_POSITIVE) { |
|||
postModelsToDownload.add(postModels.get(childPosition)); |
|||
} else { |
|||
session = true; |
|||
postModelsToDownload.add(postModels.get(childPosition)); |
|||
} |
|||
if (postModelsToDownload.size() > 0) { |
|||
Utils.batchDownload(requireContext(), |
|||
username, |
|||
DownloadMethod.DOWNLOAD_POST_VIEWER, |
|||
postModelsToDownload); |
|||
} |
|||
}; |
|||
new AlertDialog.Builder(requireContext()) |
|||
.setTitle(R.string.post_viewer_download_dialog_title) |
|||
.setMessage(R.string.post_viewer_download_message) |
|||
.setNeutralButton(R.string.post_viewer_download_session, clickListener) |
|||
.setPositiveButton(R.string.post_viewer_download_current, clickListener) |
|||
.setNegativeButton(R.string.post_viewer_download_album, clickListener).show(); |
|||
} else { |
|||
Utils.batchDownload(requireContext(), |
|||
username, |
|||
DownloadMethod.DOWNLOAD_POST_VIEWER, |
|||
Collections.singletonList(postModels.get(childPosition))); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,574 @@ |
|||
// package awais.instagrabber.fragments; |
|||
// |
|||
// import android.content.Context; |
|||
// import android.content.Intent; |
|||
// import android.graphics.drawable.Animatable; |
|||
// import android.net.Uri; |
|||
// import android.os.AsyncTask; |
|||
// import android.os.Bundle; |
|||
// import android.os.Handler; |
|||
// import android.text.SpannableString; |
|||
// import android.view.LayoutInflater; |
|||
// import android.view.View; |
|||
// import android.view.ViewGroup; |
|||
// import android.widget.LinearLayout; |
|||
// import android.widget.RelativeLayout; |
|||
// import android.widget.TextView; |
|||
// import android.widget.Toast; |
|||
// |
|||
// import androidx.annotation.NonNull; |
|||
// import androidx.annotation.Nullable; |
|||
// import androidx.appcompat.app.AppCompatActivity; |
|||
// import androidx.core.view.GestureDetectorCompat; |
|||
// import androidx.fragment.app.Fragment; |
|||
// import androidx.lifecycle.ViewModelProvider; |
|||
// import androidx.recyclerview.widget.LinearLayoutManager; |
|||
// import androidx.recyclerview.widget.RecyclerView; |
|||
// |
|||
// import com.facebook.drawee.backends.pipeline.Fresco; |
|||
// import com.facebook.drawee.controller.BaseControllerListener; |
|||
// import com.facebook.imagepipeline.image.ImageInfo; |
|||
// import com.facebook.imagepipeline.request.ImageRequest; |
|||
// import com.facebook.imagepipeline.request.ImageRequestBuilder; |
|||
// import com.google.android.exoplayer2.SimpleExoPlayer; |
|||
// import com.google.android.exoplayer2.source.MediaSource; |
|||
// import com.google.android.exoplayer2.source.MediaSourceEventListener; |
|||
// import com.google.android.exoplayer2.source.ProgressiveMediaSource; |
|||
// import com.google.android.exoplayer2.upstream.DataSource; |
|||
// 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.io.IOException; |
|||
// import java.util.List; |
|||
// |
|||
// import awais.instagrabber.R; |
|||
// import awais.instagrabber.adapters.PostsMediaAdapter; |
|||
// import awais.instagrabber.asyncs.PostFetcher; |
|||
// import awais.instagrabber.asyncs.ProfileFetcher; |
|||
// import awais.instagrabber.asyncs.i.iPostFetcher; |
|||
// import awais.instagrabber.customviews.CommentMentionClickSpan; |
|||
// import awais.instagrabber.customviews.helpers.SwipeGestureListener; |
|||
// import awais.instagrabber.databinding.FragmentPostViewBinding; |
|||
// import awais.instagrabber.fragments.main.viewmodels.BasePostViewModel; |
|||
// import awais.instagrabber.fragments.main.viewmodels.DiscoverItemViewModel; |
|||
// import awais.instagrabber.fragments.main.viewmodels.FeedViewModel; |
|||
// import awais.instagrabber.interfaces.FetchListener; |
|||
// import awais.instagrabber.interfaces.SwipeEvent; |
|||
// import awais.instagrabber.models.BasePostModel; |
|||
// import awais.instagrabber.models.PostModel; |
|||
// import awais.instagrabber.models.ProfileModel; |
|||
// import awais.instagrabber.models.ViewerPostModel; |
|||
// import awais.instagrabber.models.enums.MediaItemType; |
|||
// import awais.instagrabber.models.enums.PostItemType; |
|||
// import awais.instagrabber.utils.Constants; |
|||
// import awais.instagrabber.utils.Utils; |
|||
// |
|||
// import static awais.instagrabber.utils.Utils.settingsHelper; |
|||
// |
|||
// public class PostViewFragmentBackup extends Fragment { |
|||
// |
|||
// private FragmentPostViewBinding binding; |
|||
// private LinearLayout root; |
|||
// private AppCompatActivity fragmentActivity; |
|||
// private PostItemType postType; |
|||
// private int postIndex; |
|||
// private String postId; |
|||
// private SimpleExoPlayer player; |
|||
// private String postShortCode; |
|||
// private BasePostViewModel<?> postViewModel; |
|||
// private ViewerPostModel currentPost; |
|||
// private List<? extends BasePostModel> postList; |
|||
// private LinearLayout.LayoutParams containerLayoutParams; |
|||
// private BasePostModel basePostModel; |
|||
// private String prevUsername; |
|||
// private ProfileModel profileModel; |
|||
// private String postUserId; |
|||
// private CharSequence postCaption; |
|||
// |
|||
// private final View.OnClickListener onClickListener = new View.OnClickListener() { |
|||
// @Override |
|||
// public void onClick(final View v) { |
|||
// // if (v == binding.topPanel.ivProfilePic) { |
|||
// // new AlertDialog.Builder(requireContext()).setAdapter(profileDialogAdapter, profileDialogListener) |
|||
// //.setNeutralButton(R.string.cancel, null).setTitle(viewerPostModel.getUsername()).show(); |
|||
// // return; |
|||
// // } |
|||
// if (v == binding.ivToggleFullScreen) { |
|||
// // toggleFullscreen(); |
|||
// |
|||
// final LinearLayout topPanelRoot = binding.topPanel.getRoot(); |
|||
// final int iconRes; |
|||
// |
|||
// if (containerLayoutParams.weight != 3.3f) { |
|||
// containerLayoutParams.weight = 3.3f; |
|||
// iconRes = R.drawable.ic_fullscreen_exit; |
|||
// topPanelRoot.setVisibility(View.GONE); |
|||
// binding.btnDownload.setVisibility(View.VISIBLE); |
|||
// binding.bottomPanel.tvPostDate.setVisibility(View.GONE); |
|||
// } else { |
|||
// containerLayoutParams.weight = (binding.mediaList.getVisibility() == View.VISIBLE) ? 1.35f : 1.9f; |
|||
// containerLayoutParams.weight += (Utils.isEmpty(settingsHelper.getString(Constants.COOKIE))) ? 0.3f : 0; |
|||
// iconRes = R.drawable.ic_fullscreen; |
|||
// topPanelRoot.setVisibility(View.VISIBLE); |
|||
// binding.btnDownload.setVisibility(View.GONE); |
|||
// binding.bottomPanel.tvPostDate.setVisibility(View.VISIBLE); |
|||
// } |
|||
// |
|||
// binding.ivToggleFullScreen.setImageResource(iconRes); |
|||
// binding.container.setLayoutParams(containerLayoutParams); |
|||
// |
|||
// } else if (v == binding.bottomPanel.btnMute) { |
|||
// if (player != null) { |
|||
// final float intVol = player.getVolume() == 0f ? 1f : 0f; |
|||
// player.setVolume(intVol); |
|||
// binding.bottomPanel.btnMute.setImageResource(intVol == 0f ? R.drawable.ic_volume_off_24 : R.drawable.ic_volume_up_24); |
|||
// Utils.sessionVolumeFull = intVol == 1f; |
|||
// } |
|||
// } else if (v == binding.btnLike) { |
|||
// // new PostViewer.PostAction().execute("likes"); |
|||
// } else if (v == binding.btnBookmark) { |
|||
// // new PostViewer.PostAction().execute("save"); |
|||
// } else { |
|||
// // final Object tag = v.getTag(); |
|||
// // if (tag instanceof ViewerPostModel) { |
|||
// // viewerPostModel = (ViewerPostModel) tag; |
|||
// // slidePos = Math.max(0, viewerPostModel.getPosition()); |
|||
// // refreshPost(); |
|||
// // } |
|||
// } |
|||
// } |
|||
// }; |
|||
// private final PostsMediaAdapter mediaAdapter = new PostsMediaAdapter(null, onClickListener); |
|||
// private final FetchListener<ViewerPostModel[]> pfl = result -> { |
|||
// final Context context = getContext(); |
|||
// if (result == null || result.length < 1 && context != null) { |
|||
// Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); |
|||
// return; |
|||
// } |
|||
// currentPost = result[0]; |
|||
// mediaAdapter.setData(result); |
|||
// if (result.length > 1) { |
|||
// binding.mediaList.setLayoutParams(new LinearLayout.LayoutParams( |
|||
// LinearLayout.LayoutParams.MATCH_PARENT, 0, 0.55f |
|||
// )); |
|||
// containerLayoutParams.weight = 1.35f; |
|||
// containerLayoutParams.weight += (Utils.isEmpty(settingsHelper.getString(Constants.COOKIE))) ? 0.3f : 0; |
|||
// binding.container.setLayoutParams(containerLayoutParams); |
|||
// binding.mediaList.setVisibility(View.VISIBLE); |
|||
// } |
|||
// |
|||
// // viewerCaptionParent.setOnTouchListener(gestureTouchListener); |
|||
// // binding.playerView.setOnTouchListener(gestureTouchListener); |
|||
// // binding.imageViewer.setOnSingleFlingListener((e1, e2, velocityX, velocityY) -> { |
|||
// // final float diffX = e2.getX() - e1.getX(); |
|||
// // if (Math.abs(diffX) > Math.abs(e2.getY() - e1.getY()) && Math.abs(diffX) > SwipeGestureListener.SWIPE_THRESHOLD |
|||
// // && Math.abs(velocityX) > SwipeGestureListener.SWIPE_VELOCITY_THRESHOLD) { |
|||
// // swipeEvent.onSwipe(diffX > 0); |
|||
// // return true; |
|||
// // } |
|||
// // return false; |
|||
// // }); |
|||
// |
|||
// final long commentsCount = currentPost.getCommentsCount(); |
|||
// binding.bottomPanel.commentsCount.setText(String.valueOf(commentsCount)); |
|||
// binding.bottomPanel.btnComments.setVisibility(View.VISIBLE); |
|||
// |
|||
// // binding.bottomPanel.btnComments.setOnClickListener(v -> startActivityForResult( |
|||
// // new Intent(requireContext(), CommentsViewer.class) |
|||
// // .putExtra(Constants.EXTRAS_SHORTCODE, postModel.getShortCode()) |
|||
// // .putExtra(Constants.EXTRAS_POST, currentPost.getPostId()) |
|||
// // .putExtra(Constants.EXTRAS_USER, postUserId), 6969) |
|||
// binding.bottomPanel.btnComments.setClickable(true); |
|||
// binding.bottomPanel.btnComments.setEnabled(true); |
|||
// |
|||
// if (basePostModel instanceof PostModel) { |
|||
// final PostModel postModel = (PostModel) basePostModel; |
|||
// postModel.setPostId(currentPost.getPostId()); |
|||
// postModel.setTimestamp(currentPost.getTimestamp()); |
|||
// postModel.setPostCaption(currentPost.getPostCaption()); |
|||
// // if (!ok) { |
|||
// // liked = currentPost.getLike(); |
|||
// // saved = currentPost.getBookmark(); |
|||
// // } |
|||
// } |
|||
// showCurrentPost(); |
|||
// // refreshPost(); |
|||
// }; |
|||
// private int lastSlidePos; |
|||
// private int slidePos; |
|||
// private String url; |
|||
// private SwipeEvent swipeEvent; |
|||
// private GestureDetectorCompat gestureDetector; |
|||
// |
|||
// @Override |
|||
// public void onCreate(@Nullable final Bundle savedInstanceState) { |
|||
// super.onCreate(savedInstanceState); |
|||
// fragmentActivity = (AppCompatActivity) requireActivity(); |
|||
// if (fragmentActivity.getSupportActionBar() != null) { |
|||
// fragmentActivity.getSupportActionBar().setTitle(""); |
|||
// } |
|||
// setHasOptionsMenu(true); |
|||
// } |
|||
// |
|||
// @Nullable |
|||
// @Override |
|||
// public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { |
|||
// if (root != null) { |
|||
// return root; |
|||
// } |
|||
// binding = FragmentPostViewBinding.inflate(inflater, container, false); |
|||
// root = binding.getRoot(); |
|||
// binding.mediaList.setLayoutManager(new LinearLayoutManager(requireContext(), RecyclerView.HORIZONTAL, false)); |
|||
// binding.mediaList.setAdapter(mediaAdapter); |
|||
// binding.mediaList.setVisibility(View.GONE); |
|||
// return root; |
|||
// } |
|||
// |
|||
// @Override |
|||
// public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { |
|||
// containerLayoutParams = (LinearLayout.LayoutParams) binding.container.getLayoutParams(); |
|||
// init(); |
|||
// } |
|||
// |
|||
// @Override |
|||
// public void onDestroy() { |
|||
// super.onDestroy(); |
|||
// } |
|||
// |
|||
// private void init() { |
|||
// final Bundle arguments = getArguments(); |
|||
// if (arguments == null) return; |
|||
// final PostViewFragmentArgs fragmentArgs = PostViewFragmentArgs.fromBundle(arguments); |
|||
// postType = fragmentArgs.getPostType() == null ? null : PostItemType.valueOf(fragmentArgs.getPostType()); |
|||
// postIndex = fragmentArgs.getPostIndex(); |
|||
// postId = fragmentArgs.getPostId(); |
|||
// postShortCode = fragmentArgs.getPostShortCode(); |
|||
// setupSwipe(); |
|||
// if (postType != null && postIndex >= 0) { |
|||
// basePostModel = getBasePostFromViewModel(); |
|||
// if (basePostModel != null) { |
|||
// if (basePostModel.getShortCode() != null) { |
|||
// fetchPostFromShortCode(basePostModel.getShortCode()); |
|||
// return; |
|||
// } |
|||
// fetchPostFromPostId(basePostModel.getPostId()); |
|||
// return; |
|||
// } |
|||
// } |
|||
// // getStartPost(); |
|||
// // showCurrentPost(); |
|||
// // setupTop(); |
|||
// // setupPost(); |
|||
// // setupBottom(); |
|||
// } |
|||
// |
|||
// private void setupSwipe() { |
|||
// swipeEvent = isRight -> { |
|||
// // final List<? extends BasePostModel> itemGetterItems; |
|||
// // final boolean isMainSwipe; |
|||
// // |
|||
// // if (postType == PostItemType.SAVED && SavedViewer.itemGetter != null) { |
|||
// // itemGetterItems = SavedViewer.itemGetter.get(postType); |
|||
// // isMainSwipe = !(itemGetterItems.size() < 1 || postType == PostItemType.SAVED && isFromShare); |
|||
// // } else if (postType != null && MainActivityBackup.itemGetter != null) { |
|||
// // itemGetterItems = MainActivityBackup.itemGetter.get(postType); |
|||
// // isMainSwipe = !(itemGetterItems.size() < 1 || postType == PostItemType.MAIN && isFromShare); |
|||
// // } else { |
|||
// // itemGetterItems = null; |
|||
// // isMainSwipe = false; |
|||
// // } |
|||
// // |
|||
// // final BasePostModel[] basePostModels = mediaAdapter.getPostModels(); |
|||
// // final int slides = basePostModels.length; |
|||
// // |
|||
// // int position = basePostModel.getPosition(); |
|||
// // |
|||
// // if (isRight) { |
|||
// // --slidePos; |
|||
// // if (!isMainSwipe && slidePos < 0) slidePos = 0; |
|||
// // if (slides > 0 && slidePos >= 0) { |
|||
// // if (basePostModels[slidePos] instanceof ViewerPostModel) { |
|||
// // currentPost = (ViewerPostModel) basePostModels[slidePos]; |
|||
// // } |
|||
// // showCurrentPost(); |
|||
// // return; |
|||
// // } |
|||
// // if (isMainSwipe && --position < 0) position = itemGetterItems.size() - 1; |
|||
// // } else { |
|||
// // ++slidePos; |
|||
// // if (!isMainSwipe && slidePos >= slides) slidePos = slides - 1; |
|||
// // if (slides > 0 && slidePos < slides) { |
|||
// // if (basePostModels[slidePos] instanceof ViewerPostModel) { |
|||
// // currentPost = (ViewerPostModel) basePostModels[slidePos]; |
|||
// // } |
|||
// // showCurrentPost(); |
|||
// // return; |
|||
// // } |
|||
// // if (isMainSwipe && ++position >= itemGetterItems.size()) position = 0; |
|||
// // } |
|||
// // |
|||
// // if (isMainSwipe) { |
|||
// // slidePos = 0; |
|||
// // ok = false; |
|||
// // Log.d("AWAISKING_APP", "swipe left <<< post[" + position + "]: " + basePostModel + " -- " + slides); |
|||
// // basePostModel = itemGetterItems.get(position); |
|||
// // basePostModel.setPosition(position); |
|||
// // showCurrentPost(); |
|||
// // } |
|||
// }; |
|||
// gestureDetector = new GestureDetectorCompat(requireContext(), new SwipeGestureListener(swipeEvent)); |
|||
// } |
|||
// |
|||
// private void fetchPostFromPostId(final String postId) { |
|||
// new iPostFetcher(postId, pfl).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
|||
// } |
|||
// |
|||
// private void fetchPostFromShortCode(final String shortCode) { |
|||
// new PostFetcher(shortCode, pfl) |
|||
// .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
|||
// } |
|||
// |
|||
// private BasePostModel getBasePostFromViewModel() { |
|||
// switch (postType) { |
|||
// case FEED: |
|||
// postViewModel = new ViewModelProvider(fragmentActivity).get(FeedViewModel.class); |
|||
// break; |
|||
// case MAIN: |
|||
// // ??? |
|||
// break; |
|||
// case SAVED: |
|||
// // ??? |
|||
// break; |
|||
// case DISCOVER: |
|||
// postViewModel = new ViewModelProvider(fragmentActivity).get(DiscoverItemViewModel.class); |
|||
// } |
|||
// if (postViewModel == null) return null; |
|||
// postList = postViewModel.getList().getValue(); |
|||
// if (postList == null) return null; |
|||
// return postList.get(postIndex); |
|||
// } |
|||
// |
|||
// private void showCurrentPost() { |
|||
// setupPostInfoBar("@" + currentPost.getUsername(), |
|||
// currentPost.getItemType(), |
|||
// currentPost.getLocationName(), |
|||
// currentPost.getLocation()); |
|||
// // postCaption = basePostModel.getPostCaption(); |
|||
// ((View) binding.bottomPanel.viewerCaption.getParent()).setVisibility(View.VISIBLE); |
|||
// // binding.bottomPanel.btnDownload.setOnClickListener(downloadClickListener); |
|||
// if (containerLayoutParams.weight != 3.3f) { |
|||
// containerLayoutParams.weight = (binding.mediaList.getVisibility() == View.VISIBLE) ? 1.35f : 1.9f; |
|||
// binding.container.setLayoutParams(containerLayoutParams); |
|||
// } |
|||
// if (binding.mediaList.getVisibility() == View.VISIBLE) { |
|||
// ViewerPostModel item = mediaAdapter.getItemAt(lastSlidePos); |
|||
// if (item != null) { |
|||
// item.setCurrentSlide(false); |
|||
// mediaAdapter.notifyItemChanged(lastSlidePos, item); |
|||
// } |
|||
// |
|||
// item = mediaAdapter.getItemAt(slidePos); |
|||
// if (item != null) { |
|||
// item.setCurrentSlide(true); |
|||
// mediaAdapter.notifyItemChanged(slidePos, item); |
|||
// } |
|||
// } |
|||
// lastSlidePos = slidePos; |
|||
// postCaption = currentPost.getPostCaption(); |
|||
// |
|||
// if (Utils.hasMentions(postCaption)) { |
|||
// binding.bottomPanel.viewerCaption.setText(Utils.getMentionText(postCaption), TextView.BufferType.SPANNABLE); |
|||
// // binding.bottomPanel.viewerCaption.setMentionClickListener((view, text, isHashtag, isLocation) -> searchUsername(text)); |
|||
// } else { |
|||
// binding.bottomPanel.viewerCaption.setMentionClickListener(null); |
|||
// binding.bottomPanel.viewerCaption.setText(postCaption); |
|||
// } |
|||
// |
|||
// // setupPostInfoBar("@" + viewerPostModel.getUsername(), viewerPostModel.getItemType(), |
|||
// // viewerPostModel.getLocationName(), viewerPostModel.getLocation()); |
|||
// |
|||
// // if (postModel instanceof PostModel) { |
|||
// // final PostModel postModel = (PostModel) this.postModel; |
|||
// // postModel.setPostId(viewerPostModel.getPostId()); |
|||
// // postModel.setTimestamp(viewerPostModel.getTimestamp()); |
|||
// // postModel.setPostCaption(viewerPostModel.getPostCaption()); |
|||
// // if (liked == true) { |
|||
// // binding.btnLike.setText(resources.getString(R.string.unlike, viewerPostModel.getLikes() |
|||
// // + ((ok && viewerPostModel.getLike() != liked) ? (liked ? 1L : -1L) : 0L))); |
|||
// // binding.btnLike.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( |
|||
// // getApplicationContext(), R.color.btn_pink_background))); |
|||
// // } else { |
|||
// // binding.btnLike.setText(resources.getString(R.string.like, viewerPostModel.getLikes() |
|||
// // + ((ok && viewerPostModel.getLike() != liked) ? (liked ? 1L : -1L) : 0L))); |
|||
// // binding.btnLike.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( |
|||
// // getApplicationContext(), R.color.btn_lightpink_background))); |
|||
// // } |
|||
// // if (saved == true) { |
|||
// // binding.btnBookmark.setText(R.string.unbookmark); |
|||
// // binding.btnBookmark.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( |
|||
// // getApplicationContext(), R.color.btn_orange_background))); |
|||
// // } else { |
|||
// // binding.btnBookmark.setText(R.string.bookmark); |
|||
// // binding.btnBookmark.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( |
|||
// // getApplicationContext(), R.color.btn_lightorange_background))); |
|||
// // } |
|||
// // } |
|||
// |
|||
// binding.bottomPanel.tvPostDate.setText(currentPost.getPostDate()); |
|||
// binding.bottomPanel.tvPostDate.setVisibility(containerLayoutParams.weight != 3.3f ? View.VISIBLE : View.GONE); |
|||
// binding.bottomPanel.tvPostDate.setSelected(true); |
|||
// |
|||
// url = currentPost.getDisplayUrl(); |
|||
// // releasePlayer(); |
|||
// |
|||
// binding.btnDownload.setVisibility(containerLayoutParams.weight == 3.3f ? View.VISIBLE : View.GONE); |
|||
// if (currentPost.getItemType() == MediaItemType.MEDIA_TYPE_VIDEO) setupVideo(); |
|||
// else setupImage(); |
|||
// } |
|||
// |
|||
// private void setupPostInfoBar(final String username, |
|||
// final MediaItemType itemType, |
|||
// final String locationName, |
|||
// final String location) { |
|||
// if (prevUsername == null || !prevUsername.equals(username)) { |
|||
// binding.topPanel.ivProfilePic.setImageRequest(null); |
|||
// if (!Utils.isEmpty(username) && username.charAt(0) == '@') { |
|||
// new ProfileFetcher(username.substring(1), result -> { |
|||
// profileModel = result; |
|||
// |
|||
// if (result != null) { |
|||
// // final String hdProfilePic = result.getHdProfilePic(); |
|||
// // final String sdProfilePic = result.getSdProfilePic(); |
|||
// postUserId = result.getId(); |
|||
// // final boolean hdPicEmpty = Utils.isEmpty(hdProfilePic); |
|||
// binding.topPanel.ivProfilePic.setImageURI(profileModel.getSdProfilePic()); |
|||
// binding.topPanel.viewStoryPost.setOnClickListener(v -> { |
|||
// if (result.isPrivate()) { |
|||
// Toast.makeText(requireContext(), R.string.share_private_post, Toast.LENGTH_LONG).show(); |
|||
// } |
|||
// Intent sharingIntent = new Intent(Intent.ACTION_SEND); |
|||
// sharingIntent.setType("text/plain"); |
|||
// sharingIntent.putExtra(Intent.EXTRA_TEXT, "https://instagram.com/p/" + postShortCode); |
|||
// startActivity(Intent.createChooser(sharingIntent, result.isPrivate() |
|||
// ? getString(R.string.share_private_post) |
|||
// : getString(R.string.share_public_post))); |
|||
// }); |
|||
// } |
|||
// }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
|||
// } |
|||
// prevUsername = username; |
|||
// } |
|||
// |
|||
// final String titlePrefix = getString(itemType == MediaItemType.MEDIA_TYPE_VIDEO ? R.string.post_viewer_video_post : R.string.post_viewer_image_post); |
|||
// if (Utils.isEmpty(username)) binding.topPanel.title.setText(titlePrefix); |
|||
// else { |
|||
// final int titleLen = username.length(); |
|||
// final SpannableString spannableString = new SpannableString(username); |
|||
// spannableString.setSpan(new CommentMentionClickSpan(), 0, titleLen, 0); |
|||
// binding.topPanel.title.setText(spannableString); |
|||
// } |
|||
// |
|||
// if (location == null) { |
|||
// binding.topPanel.location.setVisibility(View.GONE); |
|||
// binding.topPanel.title.setLayoutParams(new RelativeLayout.LayoutParams( |
|||
// RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); |
|||
// } else { |
|||
// binding.topPanel.location.setVisibility(View.VISIBLE); |
|||
// binding.topPanel.location.setText(locationName); |
|||
// // binding.topPanel.location.setOnClickListener(v -> searchUsername(location)); |
|||
// binding.topPanel.title.setLayoutParams(new RelativeLayout.LayoutParams( |
|||
// RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT |
|||
// )); |
|||
// } |
|||
// } |
|||
// |
|||
// private void setupVideo() { |
|||
// binding.playerView.setVisibility(View.VISIBLE); |
|||
// binding.bottomPanel.btnDownload.setVisibility(View.VISIBLE); |
|||
// binding.bottomPanel.btnMute.setVisibility(View.VISIBLE); |
|||
// binding.progressView.setVisibility(View.GONE); |
|||
// binding.imageViewer.setVisibility(View.GONE); |
|||
// binding.imageViewer.setController(null); |
|||
// |
|||
// if (currentPost.getVideoViews() > -1) { |
|||
// binding.bottomPanel.videoViewsContainer.setVisibility(View.VISIBLE); |
|||
// binding.bottomPanel.tvVideoViews.setText(String.valueOf(currentPost.getVideoViews())); |
|||
// } |
|||
// |
|||
// player = new SimpleExoPlayer.Builder(requireContext()).build(); |
|||
// binding.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 Context context = requireContext(); |
|||
// final DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(context, "instagram"); |
|||
// final SimpleCache simpleCache = Utils.getSimpleCacheInstance(context); |
|||
// CacheDataSourceFactory cacheDataSourceFactory = null; |
|||
// if (simpleCache != null) { |
|||
// cacheDataSourceFactory = new CacheDataSourceFactory(simpleCache, dataSourceFactory); |
|||
// } |
|||
// final DataSource.Factory factory = cacheDataSourceFactory != null ? cacheDataSourceFactory : dataSourceFactory; |
|||
// final ProgressiveMediaSource mediaSource = new ProgressiveMediaSource.Factory(factory).createMediaSource(Uri.parse(url)); |
|||
// mediaSource.addEventListener(new Handler(), new MediaSourceEventListener() { |
|||
// @Override |
|||
// public void onLoadCompleted(final int windowIndex, @Nullable final MediaSource.MediaPeriodId mediaPeriodId, final LoadEventInfo loadEventInfo, final MediaLoadData mediaLoadData) { |
|||
// binding.progressView.setVisibility(View.GONE); |
|||
// } |
|||
// |
|||
// @Override |
|||
// public void onLoadStarted(final int windowIndex, @Nullable final MediaSource.MediaPeriodId mediaPeriodId, final LoadEventInfo loadEventInfo, final MediaLoadData mediaLoadData) { |
|||
// binding.progressView.setVisibility(View.VISIBLE); |
|||
// } |
|||
// |
|||
// @Override |
|||
// public void onLoadCanceled(final int windowIndex, @Nullable final MediaSource.MediaPeriodId mediaPeriodId, final LoadEventInfo loadEventInfo, final MediaLoadData mediaLoadData) { |
|||
// binding.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) { |
|||
// binding.progressView.setVisibility(View.GONE); |
|||
// } |
|||
// }); |
|||
// player.prepare(mediaSource); |
|||
// player.setVolume(vol); |
|||
// binding.bottomPanel.btnMute.setImageResource(vol == 0f ? R.drawable.ic_volume_up_24 : R.drawable.ic_volume_off_24); |
|||
// binding.bottomPanel.btnMute.setOnClickListener(onClickListener); |
|||
// } |
|||
// |
|||
// private void setupImage() { |
|||
// binding.bottomPanel.videoViewsContainer.setVisibility(View.GONE); |
|||
// binding.playerView.setVisibility(View.GONE); |
|||
// binding.progressView.setVisibility(View.VISIBLE); |
|||
// binding.bottomPanel.btnMute.setVisibility(View.GONE); |
|||
// binding.bottomPanel.btnDownload.setVisibility(View.VISIBLE); |
|||
// binding.imageViewer.setVisibility(View.VISIBLE); |
|||
// |
|||
// final ImageRequest requestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url)) |
|||
// .setLocalThumbnailPreviewsEnabled(true) |
|||
// .setProgressiveRenderingEnabled(true) |
|||
// .build(); |
|||
// binding.imageViewer.setController( |
|||
// Fresco.newDraweeControllerBuilder() |
|||
// .setImageRequest(requestBuilder) |
|||
// .setOldController(binding.imageViewer.getController()) |
|||
// .setLowResImageRequest(ImageRequest.fromUri(url)) |
|||
// .setControllerListener(new BaseControllerListener<ImageInfo>() { |
|||
// |
|||
// @Override |
|||
// public void onFailure(final String id, final Throwable throwable) { |
|||
// binding.progressView.setVisibility(View.GONE); |
|||
// } |
|||
// |
|||
// @Override |
|||
// public void onFinalImageSet(final String id, final ImageInfo imageInfo, final Animatable animatable) { |
|||
// binding.progressView.setVisibility(View.GONE); |
|||
// } |
|||
// }) |
|||
// .build() |
|||
// ); |
|||
// } |
|||
// } |
@ -0,0 +1,19 @@ |
|||
package awais.instagrabber.fragments.main.viewmodels; |
|||
|
|||
import androidx.lifecycle.MutableLiveData; |
|||
import androidx.lifecycle.ViewModel; |
|||
|
|||
import java.util.List; |
|||
|
|||
import awais.instagrabber.models.DiscoverItemModel; |
|||
|
|||
public class DiscoverItemViewModel extends ViewModel { |
|||
private MutableLiveData<List<DiscoverItemModel>> list; |
|||
|
|||
public MutableLiveData<List<DiscoverItemModel>> getList() { |
|||
if (list == null) { |
|||
list = new MutableLiveData<>(); |
|||
} |
|||
return list; |
|||
} |
|||
} |
@ -0,0 +1,18 @@ |
|||
package awais.instagrabber.fragments.main.viewmodels; |
|||
|
|||
import androidx.lifecycle.MutableLiveData; |
|||
|
|||
import java.util.List; |
|||
|
|||
import awais.instagrabber.models.ViewerPostModel; |
|||
|
|||
public class ViewPostViewModel extends BasePostViewModel<ViewerPostModel> { |
|||
private MutableLiveData<List<ViewerPostModel>> list; |
|||
|
|||
public MutableLiveData<List<ViewerPostModel>> getList() { |
|||
if (list == null) { |
|||
list = new MutableLiveData<>(); |
|||
} |
|||
return list; |
|||
} |
|||
} |
@ -0,0 +1,23 @@ |
|||
package awais.instagrabber.models; |
|||
|
|||
public class ViewerPostModelWrapper { |
|||
private int position; |
|||
private ViewerPostModel[] viewerPostModels; |
|||
|
|||
public ViewerPostModelWrapper(final int position, final ViewerPostModel[] viewerPostModels) { |
|||
this.position = position; |
|||
this.viewerPostModels = viewerPostModels; |
|||
} |
|||
|
|||
public int getPosition() { |
|||
return position; |
|||
} |
|||
|
|||
public ViewerPostModel[] getViewerPostModels() { |
|||
return viewerPostModels; |
|||
} |
|||
|
|||
public void setViewerPostModels(final ViewerPostModel[] viewerPostModels) { |
|||
this.viewerPostModels = viewerPostModels; |
|||
} |
|||
} |
@ -0,0 +1,4 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<androidx.viewpager2.widget.ViewPager2 xmlns:android="http://schemas.android.com/apk/res/android" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="match_parent" /> |
@ -0,0 +1,105 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|||
xmlns:app="http://schemas.android.com/apk/res-auto" |
|||
xmlns:tools="http://schemas.android.com/tools" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="match_parent" |
|||
android:layout_marginTop="?attr/actionBarSize" |
|||
android:animateLayoutChanges="true" |
|||
android:orientation="vertical" |
|||
android:weightSum="3.2" |
|||
tools:context=".activities.PostViewer"> |
|||
|
|||
<include |
|||
android:id="@+id/topPanel" |
|||
layout="@layout/item_feed_top" /> |
|||
|
|||
<FrameLayout |
|||
android:id="@+id/container" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="0dp" |
|||
android:layout_weight="1.9"> |
|||
|
|||
<awais.instagrabber.customviews.helpers.NestedScrollableHost |
|||
android:layout_width="match_parent" |
|||
android:layout_height="match_parent"> |
|||
|
|||
<androidx.viewpager2.widget.ViewPager2 |
|||
android:id="@+id/mediaViewPager" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="match_parent" /> |
|||
</awais.instagrabber.customviews.helpers.NestedScrollableHost> |
|||
|
|||
<androidx.appcompat.widget.AppCompatTextView |
|||
android:id="@+id/mediaCounter" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:layout_gravity="center_horizontal|bottom" |
|||
android:background="@drawable/rounder_corner_semi_black_bg" |
|||
android:gravity="center" |
|||
android:padding="5dp" |
|||
android:textAppearance="@style/TextAppearance.AppCompat.Caption" |
|||
android:textColor="@android:color/white" |
|||
android:visibility="gone" /> |
|||
|
|||
<ProgressBar |
|||
android:id="@+id/progressView" |
|||
android:layout_width="48dp" |
|||
android:layout_height="48dp" |
|||
android:layout_gravity="center" |
|||
android:visibility="gone" /> |
|||
|
|||
<androidx.appcompat.widget.AppCompatImageView |
|||
android:id="@+id/ivToggleFullScreen" |
|||
android:layout_width="48dp" |
|||
android:layout_height="48dp" |
|||
android:layout_gravity="end|top" |
|||
android:background="?selectableItemBackgroundBorderless" |
|||
android:padding="4dp" |
|||
app:srcCompat="@drawable/ic_fullscreen" |
|||
app:tint="?android:textColorPrimary" /> |
|||
</FrameLayout> |
|||
|
|||
<include |
|||
android:id="@+id/bottomPanel" |
|||
layout="@layout/item_feed_bottom" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="0dp" |
|||
android:layout_weight="1" /> |
|||
|
|||
<androidx.appcompat.widget.LinearLayoutCompat |
|||
android:id="@+id/postActions" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="0dp" |
|||
android:layout_weight="0.3" |
|||
android:background="#0000" |
|||
android:weightSum="2"> |
|||
|
|||
<androidx.appcompat.widget.AppCompatButton |
|||
android:id="@+id/btnLike" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="wrap_content" |
|||
android:layout_marginStart="6dp" |
|||
android:layout_marginLeft="8dp" |
|||
android:layout_marginRight="8dp" |
|||
android:layout_weight="1" |
|||
android:textColor="@color/btn_lightpink_text_color" |
|||
android:textSize="18sp" |
|||
app:backgroundTint="@color/btn_lightpink_background" |
|||
tools:text="@string/like" /> |
|||
|
|||
<androidx.appcompat.widget.AppCompatButton |
|||
android:id="@+id/btnBookmark" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="wrap_content" |
|||
android:layout_alignParentBottom="true" |
|||
android:layout_marginLeft="8dp" |
|||
android:layout_marginEnd="6dp" |
|||
android:layout_marginRight="8dp" |
|||
android:layout_weight="1" |
|||
android:text="@string/bookmark" |
|||
android:textColor="@color/btn_lightorange_text_color" |
|||
android:textSize="18sp" |
|||
app:backgroundTint="@color/btn_lightorange_background" /> |
|||
</androidx.appcompat.widget.LinearLayoutCompat> |
|||
</LinearLayout> |
@ -1,11 +1,29 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<navigation xmlns:android="http://schemas.android.com/apk/res/android" |
|||
xmlns:app="http://schemas.android.com/apk/res-auto" |
|||
xmlns:tools="http://schemas.android.com/tools" |
|||
android:id="@+id/discover_nav_graph" |
|||
app:startDestination="@id/discoverFragment"> |
|||
|
|||
<include app:graph="@navigation/post_view_nav_graph" /> |
|||
|
|||
<action |
|||
android:id="@+id/action_global_postViewFragment" |
|||
app:destination="@id/post_view_nav_graph"> |
|||
<argument |
|||
android:name="index" |
|||
app:argType="integer" /> |
|||
<argument |
|||
android:name="idOrCodeArray" |
|||
app:argType="string[]" /> |
|||
<argument |
|||
android:name="isId" |
|||
app:argType="boolean" /> |
|||
</action> |
|||
|
|||
<fragment |
|||
android:id="@+id/discoverFragment" |
|||
android:name="awais.instagrabber.fragments.main.DiscoverFragment" |
|||
android:label="DiscoverFragment" /> |
|||
android:label="DiscoverFragment" |
|||
tools:layout="@layout/fragment_discover" /> |
|||
</navigation> |
@ -0,0 +1,42 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<navigation xmlns:android="http://schemas.android.com/apk/res/android" |
|||
xmlns:app="http://schemas.android.com/apk/res-auto" |
|||
xmlns:tools="http://schemas.android.com/tools" |
|||
android:id="@+id/location_nav_graph" |
|||
app:startDestination="@id/locationFragment"> |
|||
|
|||
<!--<include app:graph="@navigation/post_view_nav_graph" />--> |
|||
|
|||
<action |
|||
android:id="@+id/action_global_postViewFragment" |
|||
app:destination="@id/post_view_nav_graph"> |
|||
<argument |
|||
android:name="index" |
|||
app:argType="integer" /> |
|||
<argument |
|||
android:name="idOrCodeArray" |
|||
app:argType="string[]" /> |
|||
<argument |
|||
android:name="isId" |
|||
app:argType="boolean" /> |
|||
</action> |
|||
|
|||
<fragment |
|||
android:id="@+id/locationFragment" |
|||
android:name="awais.instagrabber.fragments.LocationFragment" |
|||
android:label="" |
|||
tools:layout="@layout/fragment_location"> |
|||
<argument |
|||
android:name="locationId" |
|||
app:argType="string" |
|||
app:nullable="false" /> |
|||
</fragment> |
|||
<action |
|||
android:id="@+id/action_global_locationFragment" |
|||
app:destination="@id/locationFragment"> |
|||
<argument |
|||
android:name="locationId" |
|||
app:argType="string" |
|||
app:nullable="false" /> |
|||
</action> |
|||
</navigation> |
@ -0,0 +1,67 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<navigation xmlns:android="http://schemas.android.com/apk/res/android" |
|||
xmlns:app="http://schemas.android.com/apk/res-auto" |
|||
xmlns:tools="http://schemas.android.com/tools" |
|||
android:id="@+id/post_view_nav_graph" |
|||
app:startDestination="@id/postViewFragment"> |
|||
|
|||
<include app:graph="@navigation/hashtag_nav_graph" /> |
|||
|
|||
<action |
|||
android:id="@+id/action_global_hashTagFragment" |
|||
app:destination="@id/hashtag_nav_graph"> |
|||
<argument |
|||
android:name="hashtag" |
|||
app:argType="string" |
|||
app:nullable="false" /> |
|||
</action> |
|||
<!--<include app:graph="@navigation/profile_nav_graph" />--> |
|||
|
|||
<action |
|||
android:id="@+id/action_global_profileFragment" |
|||
app:destination="@id/profile_nav_graph"> |
|||
<argument |
|||
android:name="username" |
|||
app:argType="string" |
|||
app:nullable="true" /> |
|||
</action> |
|||
|
|||
<include app:graph="@navigation/location_nav_graph" /> |
|||
|
|||
<action |
|||
android:id="@+id/action_global_locationFragment" |
|||
app:destination="@id/location_nav_graph"> |
|||
<argument |
|||
android:name="locationId" |
|||
app:argType="string" |
|||
app:nullable="false" /> |
|||
</action> |
|||
<fragment |
|||
android:id="@+id/postViewFragment" |
|||
android:name="awais.instagrabber.fragments.PostViewFragment" |
|||
tools:layout="@layout/item_full_post_view"> |
|||
<argument |
|||
android:name="index" |
|||
app:argType="integer" /> |
|||
<argument |
|||
android:name="idOrCodeArray" |
|||
app:argType="string[]" /> |
|||
<argument |
|||
android:name="isId" |
|||
app:argType="boolean" /> |
|||
</fragment> |
|||
<action |
|||
android:id="@+id/action_global_postViewFragment" |
|||
app:destination="@id/postViewFragment"> |
|||
<argument |
|||
android:name="index" |
|||
app:argType="integer" /> |
|||
<argument |
|||
android:name="idOrCodeArray" |
|||
app:argType="string[]" /> |
|||
<argument |
|||
android:name="isId" |
|||
app:argType="boolean" /> |
|||
</action> |
|||
|
|||
</navigation> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue