1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 22:57:29 +00:00

fix #385, fix #417, fix #429, cleanup, prep for splash

This commit is contained in:
Austin Huang 2020-12-19 16:59:09 -05:00
parent 3899b9adfa
commit 8240829fa8
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
10 changed files with 37 additions and 248 deletions

View File

@ -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<PostChild> 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<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);
// }
// }
// }

View File

@ -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) {

View File

@ -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<HighlightModel> 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<StoryModel> storyModels = storiesViewModel.getList().getValue();
if (storyModels != null) {
if (storyModels != null && storyModels.size() > 0) {
StoryModel item = storyModels.get(lastSlidePos);
if (item != null) {
item.setCurrentSlide(false);

View File

@ -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);

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="@color/white"/>
</layer-list>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="@color/black"/>
</layer-list>

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--
<style name="AppTheme.LaunchTheme" parent="AppTheme">
<item name="android:windowBackground">@drawable/launch_dark</item>
</style>
-->
<style name="AppTheme.BottomSheetDialog" parent="Theme.MaterialComponents.BottomSheetDialog" />

View File

@ -8,9 +8,6 @@
<color name="btn_green_background">#5CE362</color>
<color name="btn_green_text_color">@color/text_color_light</color>
<color name="btn_black_background">#000000</color>
<color name="btn_black_text_color">@color/text_color_dark</color>
<color name="btn_blue_background">#0288D1</color>
<color name="btn_blue_text_color">@color/text_color_light</color>
@ -18,8 +15,6 @@
<color name="btn_red_text_color">@color/text_color_dark</color>
<color name="btn_purple_background">#909090</color>
<color name="btn_pink_background">#FF69B4</color>
<color name="btn_pink_text_color">@color/text_color_dark</color>
<color name="btn_lightpink_background">#FFB6C1</color>
<color name="btn_lightpink_text_color">@color/text_color_light</color>

View File

@ -325,4 +325,5 @@
<item quantity="one">%d comment</item>
<item quantity="other">%d comments</item>
</plurals>
<string name="download_permission">Storage permission not granted!</string>
</resources>

View File

@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<!--
<style name="AppTheme.LaunchTheme" parent="AppTheme">
<item name="android:windowBackground">@drawable/launch</item>
</style>
-->
<style name="Theme.AppCompat.Translucent" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
@ -11,10 +17,12 @@
<style name="PlayButtonCard" parent="CardView.Dark" />
<!--
<style name="FlyingGayDialog" parent="Theme.MaterialComponents.DayNight.Dialog.FixedSize">
<item name="windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
</style>
-->
<!--<style name="AppTheme.BottomSheetDialog" parent="Theme.MaterialComponents.Light.BottomSheetDialog" />-->