From 8240829fa81586c0064b7d9368ccae0e920cba47 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Sat, 19 Dec 2020 16:59:09 -0500 Subject: [PATCH] fix #385, fix #417, fix #429, cleanup, prep for splash --- .../viewholder/PostViewerViewHolder.java | 240 ------------------ .../fragments/PostViewV2Fragment.java | 1 + .../fragments/StoryViewerFragment.java | 8 +- .../fragments/main/FeedFragment.java | 7 +- app/src/main/res/drawable/launch.xml | 5 + app/src/main/res/drawable/launch_dark.xml | 5 + app/src/main/res/values-night/styles.xml | 5 + app/src/main/res/values/color.xml | 5 - app/src/main/res/values/strings.xml | 1 + app/src/main/res/values/styles.xml | 8 + 10 files changed, 37 insertions(+), 248 deletions(-) delete mode 100644 app/src/main/java/awais/instagrabber/adapters/viewholder/PostViewerViewHolder.java create mode 100644 app/src/main/res/drawable/launch.xml create mode 100644 app/src/main/res/drawable/launch_dark.xml diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/PostViewerViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/PostViewerViewHolder.java deleted file mode 100644 index dcb2f9fc..00000000 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/PostViewerViewHolder.java +++ /dev/null @@ -1,240 +0,0 @@ -// package awais.instagrabber.adapters.viewholder; -// -// import android.content.res.ColorStateList; -// import android.content.res.Resources; -// import android.util.Log; -// import android.view.View; -// import android.widget.TextView; -// -// import androidx.annotation.NonNull; -// import androidx.core.content.ContextCompat; -// import androidx.core.view.ViewCompat; -// 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.PostChild; -// 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.TextUtils; -// 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 List items = wrapper.getViewerPostModels(); -// if (items == null || items.size() == 0) return; -// if (items.get(0) == null) return; -// final PostViewerChildAdapter adapter = new PostViewerChildAdapter(); -// binding.mediaViewPager.setAdapter(adapter); -// final PostChild firstPost = items.get(0); -// setPostInfo(firstPost, mentionClickListener); -// setMediaItems(items, adapter); -// setupListeners(wrapper, -// position, -// clickListener, -// longClickListener, -// mentionClickListener, -// firstPost.getLocation()); -// } -// -// private void setPostInfo(final PostChild 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 (!TextUtils.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 (TextUtils.hasMentions(postCaption)) { -// binding.bottomPanel.viewerCaption.setMentionClickListener(mentionClickListener); -// binding.bottomPanel.viewerCaption -// .setText(TextUtils.getMentionText(postCaption), TextView.BufferType.SPANNABLE); -// } else { -// binding.bottomPanel.viewerCaption.setMentionClickListener(null); -// binding.bottomPanel.viewerCaption.setText(postCaption); -// } -// binding.bottomPanel.tvPostDate.setText(firstPost.getPostDate()); -// setupLikes(firstPost); -// setupSave(firstPost); -// } -// -// private void setupLikes(final ViewerPostModel firstPost) { -// final boolean liked = firstPost.getLike(); -// final long likeCount = firstPost.getLikes(); -// final Resources resources = itemView.getContext().getResources(); -// if (liked) { -// final String unlikeString = resources.getString(R.string.unlike, String.valueOf(likeCount)); -// binding.btnLike.setText(unlikeString); -// ViewCompat.setBackgroundTintList(binding.btnLike, -// ColorStateList.valueOf(ContextCompat.getColor(itemView.getContext(), R.color.btn_pink_background))); -// } else { -// final String likeString = resources.getString(R.string.like, String.valueOf(likeCount)); -// binding.btnLike.setText(likeString); -// ViewCompat.setBackgroundTintList(binding.btnLike, -// ColorStateList.valueOf(ContextCompat.getColor(itemView.getContext(), R.color.btn_lightpink_background))); -// } -// } -// -// private void setupSave(final ViewerPostModel firstPost) { -// final boolean saved = firstPost.isSaved(); -// if (saved) { -// binding.btnBookmark.setText(R.string.unbookmark); -// ViewCompat.setBackgroundTintList(binding.btnBookmark, -// ColorStateList.valueOf(ContextCompat.getColor(itemView.getContext(), R.color.btn_orange_background))); -// } else { -// binding.btnBookmark.setText(R.string.bookmark); -// ViewCompat.setBackgroundTintList( -// binding.btnBookmark, -// ColorStateList.valueOf(ContextCompat.getColor(itemView.getContext(), R.color.btn_lightorange_background))); -// } -// } -// -// 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.btnLike.setOnClickListener(onClickListener); -// binding.btnBookmark.setOnClickListener(onClickListener); -// binding.bottomPanel.viewerCaption.setOnLongClickListener(v -> { -// longClickListener.onLongClick(binding.bottomPanel.viewerCaption.getText().toString()); -// return true; -// }); -// if (!TextUtils.isEmpty(location)) { -// binding.topPanel.location.setOnClickListener(v -> mentionClickListener -// .onClick(binding.topPanel.location, location, false, true)); -// } -// } -// -// private void setMediaItems(final List items, -// final PostViewerChildAdapter adapter) { -// final List 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); -// } -// } -// } diff --git a/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java b/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java index 4b77b6e3..ad1fd41d 100644 --- a/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java @@ -306,6 +306,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment { @Override public void onDestroyView() { super.onDestroyView(); + if (feedModel == null) return; switch (feedModel.getItemType()) { case MEDIA_TYPE_VIDEO: if (videoPlayerViewHelper != null) { diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java index 1a90128c..6c1fd576 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -612,6 +612,7 @@ public class StoryViewerFragment extends Fragment { } private void resetView() { + final Context context = getContext(); slidePos = 0; lastSlidePos = 0; if (menuDownload != null) menuDownload.setVisible(false); @@ -623,7 +624,10 @@ public class StoryViewerFragment extends Fragment { if (isHighlight) { final HighlightsViewModel highlightsViewModel = (HighlightsViewModel) viewModel; final List models = highlightsViewModel.getList().getValue(); - if (models == null || models.isEmpty() || currentFeedStoryIndex >= models.size()) return; + if (models == null || models.isEmpty() || currentFeedStoryIndex >= models.size()) { + Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); + return; + } final HighlightModel model = models.get(currentFeedStoryIndex); currentStoryMediaId = model.getId(); currentStoryUsername = model.getTitle(); @@ -683,7 +687,7 @@ public class StoryViewerFragment extends Fragment { private void refreshStory() { if (binding.storiesList.getVisibility() == View.VISIBLE) { final List storyModels = storiesViewModel.getList().getValue(); - if (storyModels != null) { + if (storyModels != null && storyModels.size() > 0) { StoryModel item = storyModels.get(lastSlidePos); if (item != null) { item.setCurrentSlide(false); diff --git a/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java index 91fbb6f8..f562770a 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java @@ -12,6 +12,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.Toast; import androidx.activity.OnBackPressedCallback; import androidx.activity.OnBackPressedDispatcher; @@ -311,9 +312,13 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre @Override public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); - final boolean granted = grantResults[0] == PackageManager.PERMISSION_GRANTED; + final boolean granted = grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED; final Context context = getContext(); if (context == null) return; + if (!granted) { + Toast.makeText(context, R.string.download_permission, Toast.LENGTH_SHORT).show(); + return; + } if (requestCode == STORAGE_PERM_REQUEST_CODE && granted) { if (downloadFeedModel == null) return; DownloadUtils.showDownloadDialog(context, downloadFeedModel, downloadChildPosition); diff --git a/app/src/main/res/drawable/launch.xml b/app/src/main/res/drawable/launch.xml new file mode 100644 index 00000000..c34eafaa --- /dev/null +++ b/app/src/main/res/drawable/launch.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/launch_dark.xml b/app/src/main/res/drawable/launch_dark.xml new file mode 100644 index 00000000..d436940f --- /dev/null +++ b/app/src/main/res/drawable/launch_dark.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values-night/styles.xml b/app/src/main/res/values-night/styles.xml index e5fbb438..aa7d71de 100755 --- a/app/src/main/res/values-night/styles.xml +++ b/app/src/main/res/values-night/styles.xml @@ -1,5 +1,10 @@ + + --> + + -->