1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-15 19:27:31 +00:00

Merge branch 'master' into feature/search-history

This commit is contained in:
Ammar Githam 2021-04-15 22:35:31 +09:00
commit 1ee12f71f4
11 changed files with 110 additions and 88 deletions

View File

@ -55,7 +55,7 @@ public abstract class FeedItemViewHolder extends RecyclerView.ViewHolder {
private void setupComments(@NonNull final Media feedModel) { private void setupComments(@NonNull final Media feedModel) {
final long commentsCount = feedModel.getCommentCount(); final long commentsCount = feedModel.getCommentCount();
bottomBinding.commentsCount.setText(String.valueOf(commentsCount)); bottomBinding.commentsCount.setText(String.valueOf(commentsCount));
bottomBinding.commentsCount.setOnClickListener(v -> feedItemCallback.onCommentsClick(feedModel)); bottomBinding.btnComments.setOnClickListener(v -> feedItemCallback.onCommentsClick(feedModel));
} }
private void setupProfilePic(@NonNull final Media media) { private void setupProfilePic(@NonNull final Media media) {
@ -75,6 +75,7 @@ public abstract class FeedItemViewHolder extends RecyclerView.ViewHolder {
// final SpannableString spannableString = new SpannableString(); // final SpannableString spannableString = new SpannableString();
// spannableString.setSpan(new CommentMentionClickSpan(), 0, titleLen, 0); // spannableString.setSpan(new CommentMentionClickSpan(), 0, titleLen, 0);
final User user = media.getUser(); final User user = media.getUser();
if (user == null) return;
final String title = "@" + user.getUsername(); final String title = "@" + user.getUsername();
topBinding.title.setText(title); topBinding.title.setText(title);
topBinding.title.setOnClickListener(v -> feedItemCallback.onNameClick(media, topBinding.ivProfilePic)); topBinding.title.setOnClickListener(v -> feedItemCallback.onNameClick(media, topBinding.ivProfilePic));
@ -120,8 +121,7 @@ public abstract class FeedItemViewHolder extends RecyclerView.ViewHolder {
topBinding.title.setLayoutParams(new RelativeLayout.LayoutParams( topBinding.title.setLayoutParams(new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT
)); ));
} } else {
else {
final String locationName = location.getName(); final String locationName = location.getName();
if (TextUtils.isEmpty(locationName)) { if (TextUtils.isEmpty(locationName)) {
topBinding.location.setVisibility(View.GONE); topBinding.location.setVisibility(View.GONE);

View File

@ -12,9 +12,6 @@ import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.utils.NetworkUtils; import awais.instagrabber.utils.NetworkUtils;
import awais.instagrabber.utils.ResponseBodyUtils; import awais.instagrabber.utils.ResponseBodyUtils;
//import awaisomereport.LogCollector;
//import static awais.instagrabber.utils.Utils.logCollector;
public final class PostFetcher extends AsyncTask<Void, Void, Media> { public final class PostFetcher extends AsyncTask<Void, Void, Media> {
private static final String TAG = "PostFetcher"; private static final String TAG = "PostFetcher";

View File

@ -14,8 +14,8 @@ import androidx.appcompat.widget.AppCompatTextView;
import androidx.appcompat.widget.PopupMenu; import androidx.appcompat.widget.PopupMenu;
import com.facebook.drawee.backends.pipeline.Fresco; import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder;
import com.facebook.drawee.controller.BaseControllerListener; import com.facebook.drawee.controller.BaseControllerListener;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.imagepipeline.image.ImageInfo; import com.facebook.imagepipeline.image.ImageInfo;
import com.facebook.imagepipeline.request.ImageRequest; import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.request.ImageRequestBuilder; import com.facebook.imagepipeline.request.ImageRequestBuilder;
@ -156,12 +156,15 @@ public class VideoPlayerViewHelper implements Player.EventListener {
private void setThumbnail() { private void setThumbnail() {
binding.thumbnail.setAspectRatio(thumbnailAspectRatio); binding.thumbnail.setAspectRatio(thumbnailAspectRatio);
final ImageRequest thumbnailRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(thumbnailUrl)) ImageRequest thumbnailRequest = null;
.build(); if (thumbnailUrl != null) {
final DraweeController controller = Fresco.newDraweeControllerBuilder() thumbnailRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(thumbnailUrl)).build();
}
final PipelineDraweeControllerBuilder builder = Fresco.newDraweeControllerBuilder()
.setControllerListener(new BaseControllerListener<ImageInfo>() { .setControllerListener(new BaseControllerListener<ImageInfo>() {
@Override @Override
public void onFailure(final String id, final Throwable throwable) { public void onFailure(final String id,
final Throwable throwable) {
if (videoPlayerCallback != null) { if (videoPlayerCallback != null) {
videoPlayerCallback.onThumbnailLoaded(); videoPlayerCallback.onThumbnailLoaded();
} }
@ -175,10 +178,11 @@ public class VideoPlayerViewHelper implements Player.EventListener {
videoPlayerCallback.onThumbnailLoaded(); videoPlayerCallback.onThumbnailLoaded();
} }
} }
}) });
.setImageRequest(thumbnailRequest) if (thumbnailRequest != null) {
.build(); builder.setImageRequest(thumbnailRequest);
binding.thumbnail.setController(controller); }
binding.thumbnail.setController(builder.build());
} }
private void loadPlayer() { private void loadPlayer() {

View File

@ -26,6 +26,7 @@ import androidx.appcompat.app.ActionBar;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.PermissionChecker; import androidx.core.content.PermissionChecker;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.navigation.NavController; import androidx.navigation.NavController;
import androidx.navigation.NavDirections; import androidx.navigation.NavDirections;
import androidx.navigation.fragment.NavHostFragment; import androidx.navigation.fragment.NavHostFragment;
@ -60,6 +61,7 @@ import awais.instagrabber.repositories.requests.StoryViewerOptions;
import awais.instagrabber.repositories.responses.Hashtag; import awais.instagrabber.repositories.responses.Hashtag;
import awais.instagrabber.repositories.responses.Location; import awais.instagrabber.repositories.responses.Location;
import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils; import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.DownloadUtils; import awais.instagrabber.utils.DownloadUtils;
@ -213,7 +215,9 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
final View mainPostImage, final View mainPostImage,
final int position) { final int position) {
if (opening) return; if (opening) return;
if (TextUtils.isEmpty(feedModel.getUser().getUsername())) { final User user = feedModel.getUser();
if (user == null) return;
if (TextUtils.isEmpty(user.getUsername())) {
opening = true; opening = true;
new PostFetcher(feedModel.getCode(), newFeedModel -> { new PostFetcher(feedModel.getCode(), newFeedModel -> {
opening = false; opening = false;
@ -231,7 +235,9 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
builder.setSharedProfilePicElement(profilePicView) builder.setSharedProfilePicElement(profilePicView)
.setSharedMainPostElement(mainPostImage); .setSharedMainPostElement(mainPostImage);
} }
builder.build().show(getChildFragmentManager(), "post_view"); final FragmentManager fragmentManager = getChildFragmentManager();
if (fragmentManager.isDestroyed()) return;
builder.build().show(fragmentManager, "post_view");
opening = false; opening = false;
} }
}; };
@ -403,8 +409,7 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
try { try {
Toast.makeText(getContext(), R.string.error_loading_hashtag, Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), R.string.error_loading_hashtag, Toast.LENGTH_SHORT).show();
binding.swipeRefreshLayout.setEnabled(false); binding.swipeRefreshLayout.setEnabled(false);
} } catch (Exception ignored) {}
catch (Exception ignored) {}
return; return;
} }
setTitle(); setTitle();

View File

@ -24,6 +24,7 @@ import androidx.appcompat.app.ActionBar;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.PermissionChecker; import androidx.core.content.PermissionChecker;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.navigation.NavController; import androidx.navigation.NavController;
import androidx.navigation.NavDirections; import androidx.navigation.NavDirections;
import androidx.navigation.fragment.NavHostFragment; import androidx.navigation.fragment.NavHostFragment;
@ -56,6 +57,7 @@ import awais.instagrabber.models.enums.FavoriteType;
import awais.instagrabber.repositories.requests.StoryViewerOptions; import awais.instagrabber.repositories.requests.StoryViewerOptions;
import awais.instagrabber.repositories.responses.Location; import awais.instagrabber.repositories.responses.Location;
import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils; import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.DownloadUtils; import awais.instagrabber.utils.DownloadUtils;
@ -204,7 +206,9 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
final View mainPostImage, final View mainPostImage,
final int position) { final int position) {
if (opening) return; if (opening) return;
if (TextUtils.isEmpty(feedModel.getUser().getUsername())) { final User user = feedModel.getUser();
if (user == null) return;
if (TextUtils.isEmpty(user.getUsername())) {
opening = true; opening = true;
new PostFetcher(feedModel.getCode(), newFeedModel -> { new PostFetcher(feedModel.getCode(), newFeedModel -> {
opening = false; opening = false;
@ -223,7 +227,9 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
builder.setSharedProfilePicElement(profilePicView) builder.setSharedProfilePicElement(profilePicView)
.setSharedMainPostElement(mainPostImage); .setSharedMainPostElement(mainPostImage);
} }
builder.build().show(getChildFragmentManager(), "post_view"); final FragmentManager fragmentManager = getChildFragmentManager();
if (fragmentManager.isDestroyed()) return;
builder.build().show(fragmentManager, "post_view");
opening = false; opening = false;
} }
}; };
@ -399,8 +405,7 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
try { try {
Toast.makeText(getContext(), R.string.error_loading_location, Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), R.string.error_loading_location, Toast.LENGTH_SHORT).show();
binding.swipeRefreshLayout.setEnabled(false); binding.swipeRefreshLayout.setEnabled(false);
} } catch (Exception ignored) {}
catch (Exception ignored) {}
return; return;
} }
setTitle(); setTitle();

View File

@ -2,14 +2,12 @@ package awais.instagrabber.fragments;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.drawable.Animatable; import android.graphics.drawable.Animatable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.util.Log; import android.util.Log;
import android.util.Pair;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.Gravity; import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -72,7 +70,6 @@ import awais.instagrabber.BuildConfig;
import awais.instagrabber.R; import awais.instagrabber.R;
import awais.instagrabber.adapters.StoriesAdapter; import awais.instagrabber.adapters.StoriesAdapter;
import awais.instagrabber.asyncs.CreateThreadAction; import awais.instagrabber.asyncs.CreateThreadAction;
import awais.instagrabber.asyncs.PostFetcher;
import awais.instagrabber.customviews.helpers.SwipeGestureListener; import awais.instagrabber.customviews.helpers.SwipeGestureListener;
import awais.instagrabber.databinding.FragmentStoryViewerBinding; import awais.instagrabber.databinding.FragmentStoryViewerBinding;
import awais.instagrabber.fragments.main.ProfileFragmentDirections; import awais.instagrabber.fragments.main.ProfileFragmentDirections;
@ -105,7 +102,6 @@ import awais.instagrabber.webservices.DirectMessagesService;
import awais.instagrabber.webservices.MediaService; import awais.instagrabber.webservices.MediaService;
import awais.instagrabber.webservices.ServiceCallback; import awais.instagrabber.webservices.ServiceCallback;
import awais.instagrabber.webservices.StoriesService; import awais.instagrabber.webservices.StoriesService;
//import awaisomereport.LogCollector;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
import retrofit2.Response; import retrofit2.Response;
@ -113,7 +109,6 @@ import retrofit2.Response;
import static awais.instagrabber.customviews.helpers.SwipeGestureListener.SWIPE_THRESHOLD; import static awais.instagrabber.customviews.helpers.SwipeGestureListener.SWIPE_THRESHOLD;
import static awais.instagrabber.customviews.helpers.SwipeGestureListener.SWIPE_VELOCITY_THRESHOLD; import static awais.instagrabber.customviews.helpers.SwipeGestureListener.SWIPE_VELOCITY_THRESHOLD;
import static awais.instagrabber.utils.Constants.MARK_AS_SEEN; import static awais.instagrabber.utils.Constants.MARK_AS_SEEN;
//import static awais.instagrabber.utils.Utils.logCollector;
import static awais.instagrabber.utils.Utils.settingsHelper; import static awais.instagrabber.utils.Utils.settingsHelper;
public class StoryViewerFragment extends Fragment { public class StoryViewerFragment extends Fragment {
@ -838,7 +833,7 @@ public class StoryViewerFragment extends Fragment {
} }
} }
private void refreshStory() { private synchronized void refreshStory() {
if (binding.storiesList.getVisibility() == View.VISIBLE) { if (binding.storiesList.getVisibility() == View.VISIBLE) {
final List<StoryModel> storyModels = storiesViewModel.getList().getValue(); final List<StoryModel> storyModels = storiesViewModel.getList().getValue();
if (storyModels != null && storyModels.size() > 0) { if (storyModels != null && storyModels.size() > 0) {

View File

@ -285,8 +285,13 @@ public final class InboxManager {
if (index < 0) return; if (index < 0) return;
final List<DirectThread> threads = inbox.getThreads(); final List<DirectThread> threads = inbox.getThreads();
final DirectThread thread = threads.get(index); final DirectThread thread = threads.get(index);
thread.setItems(updatedItems); try {
setThread(inbox, index, thread); final DirectThread threadClone = (DirectThread) thread.clone();
threadClone.setItems(updatedItems);
setThread(inbox, index, threadClone);
} catch (Exception e) {
Log.e(TAG, "setItemsToThread: ", e);
}
} }
} }

View File

@ -92,14 +92,14 @@ public final class ThreadManager {
private final MutableLiveData<DirectThreadParticipantRequestsResponse> pendingRequests = new MutableLiveData<>(null); private final MutableLiveData<DirectThreadParticipantRequestsResponse> pendingRequests = new MutableLiveData<>(null);
private final String threadId; private final String threadId;
private final DirectMessagesService service;
private final long viewerId; private final long viewerId;
private final ThreadIdOrUserIds threadIdOrUserIds; private final ThreadIdOrUserIds threadIdOrUserIds;
private final User currentUser; private final User currentUser;
private final ContentResolver contentResolver; private final ContentResolver contentResolver;
private final MediaService mediaService;
private final FriendshipService friendshipService;
private DirectMessagesService service;
private MediaService mediaService;
private FriendshipService friendshipService;
private InboxManager inboxManager; private InboxManager inboxManager;
private LiveData<DirectThread> thread; private LiveData<DirectThread> thread;
private LiveData<Integer> inputMode; private LiveData<Integer> inputMode;
@ -157,6 +157,7 @@ public final class ThreadManager {
viewerId = CookieUtils.getUserIdFromCookie(cookie); viewerId = CookieUtils.getUserIdFromCookie(cookie);
final String deviceUuid = settingsHelper.getString(Constants.DEVICE_UUID); final String deviceUuid = settingsHelper.getString(Constants.DEVICE_UUID);
final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie); final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
if (csrfToken == null) return;
// if (TextUtils.isEmpty(csrfToken) || viewerId <= 0 || TextUtils.isEmpty(deviceUuid)) { // if (TextUtils.isEmpty(csrfToken) || viewerId <= 0 || TextUtils.isEmpty(deviceUuid)) {
// throw new IllegalArgumentException("User is not logged in!"); // throw new IllegalArgumentException("User is not logged in!");
// } // }

View File

@ -34,7 +34,7 @@ public class Media implements Serializable {
private final boolean hasAudio; private final boolean hasAudio;
private final double videoDuration; private final double videoDuration;
private final long viewCount; private final long viewCount;
private final Caption caption; private Caption caption;
private final boolean canViewerSave; private final boolean canViewerSave;
private final Audio audio; private final Audio audio;
private final String title; private final String title;
@ -271,7 +271,14 @@ public class Media implements Serializable {
} }
public void setPostCaption(final String caption) { public void setPostCaption(final String caption) {
final Caption caption1 = getCaption(); Caption caption1 = getCaption();
if (caption1 == null) {
final User user = getUser();
if (user == null) return;
caption1 = new Caption(user.getPk(), caption);
this.caption = caption1;
return;
}
caption1.setText(caption); caption1.setText(caption);
} }

View File

@ -5,6 +5,7 @@ import android.view.View;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import androidx.fragment.app.FragmentManager;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
@ -59,7 +60,7 @@ public class IgErrorsInterceptor implements Interceptor {
return; return;
case 302: // redirect case 302: // redirect
final String location = response.header("location"); final String location = response.header("location");
if (location.equals("https://www.instagram.com/accounts/login/")) { if (location != null && location.equals("https://www.instagram.com/accounts/login/")) {
// rate limited // rate limited
showErrorDialog(R.string.rate_limit); showErrorDialog(R.string.rate_limit);
} }
@ -70,7 +71,7 @@ public class IgErrorsInterceptor implements Interceptor {
try { try {
final String bodyString = body.string(); final String bodyString = body.string();
final JSONObject jsonObject = new JSONObject(bodyString); final JSONObject jsonObject = new JSONObject(bodyString);
String message = jsonObject.optString("message", null); String message = jsonObject.optString("message");
if (!TextUtils.isEmpty(message)) { if (!TextUtils.isEmpty(message)) {
message = message.toLowerCase(); message = message.toLowerCase();
switch (message) { switch (message) {
@ -91,7 +92,7 @@ public class IgErrorsInterceptor implements Interceptor {
return; return;
} }
} }
final String errorType = jsonObject.optString("error_type", null); final String errorType = jsonObject.optString("error_type");
if (TextUtils.isEmpty(errorType)) return; if (TextUtils.isEmpty(errorType)) return;
if (errorType.equals("sentry_block")) { if (errorType.equals("sentry_block")) {
showErrorDialog(R.string.sentry_block); showErrorDialog(R.string.sentry_block);
@ -127,7 +128,9 @@ public class IgErrorsInterceptor implements Interceptor {
0, 0,
0 0
); );
dialogFragment.show(mainActivity.getSupportFragmentManager(), "network_error_dialog"); final FragmentManager fragmentManager = mainActivity.getSupportFragmentManager();
if (fragmentManager.isStateSaved()) return;
dialogFragment.show(fragmentManager, "network_error_dialog");
} }
public void destroy() { public void destroy() {

View File

@ -126,7 +126,7 @@
<item name="android:dialogTheme">@style/Widget.Dialog.Dark.Black</item> <item name="android:dialogTheme">@style/Widget.Dialog.Dark.Black</item>
<item name="alertDialogTheme">@style/Widget.AlertDialog.Dark.Black</item> <item name="alertDialogTheme">@style/Widget.AlertDialog.Dark.Black</item>
<item name="switchStyle">@style/Widget.AppCompat.CompoundButton.Switch.Dark.Black</item> <item name="switchStyle">@style/Widget.AppCompat.CompoundButton.Switch.Dark.Black</item>
<item name="android:dropDownListViewStyle">@style/Widget.AppCompat.ListView.DropDown.Dark.Black</item> <!--<item name="android:dropDownListViewStyle">@style/Widget.AppCompat.ListView.DropDown.Dark.Black</item>-->
<item name="preferenceFragmentCompatStyle">@style/PreferenceFragmentCompatStyle.Dark.Black</item> <item name="preferenceFragmentCompatStyle">@style/PreferenceFragmentCompatStyle.Dark.Black</item>
<item name="appBarLayoutStyle">@style/Widget.MaterialComponents.AppBarLayout.Primary</item> <item name="appBarLayoutStyle">@style/Widget.MaterialComponents.AppBarLayout.Primary</item>
<item name="dmIncomingBgColor">@color/grey_600</item> <item name="dmIncomingBgColor">@color/grey_600</item>