Browse Source

Merge branch 'master' into feature/search-history

renovate/org.robolectric-robolectric-4.x
Ammar Githam 4 years ago
parent
commit
1ee12f71f4
  1. 6
      app/src/main/java/awais/instagrabber/adapters/viewholder/feed/FeedItemViewHolder.java
  2. 9
      app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java
  3. 52
      app/src/main/java/awais/instagrabber/customviews/VideoPlayerViewHelper.java
  4. 13
      app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java
  5. 65
      app/src/main/java/awais/instagrabber/fragments/LocationFragment.java
  6. 15
      app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java
  7. 9
      app/src/main/java/awais/instagrabber/managers/InboxManager.java
  8. 7
      app/src/main/java/awais/instagrabber/managers/ThreadManager.java
  9. 11
      app/src/main/java/awais/instagrabber/repositories/responses/Media.java
  10. 11
      app/src/main/java/awais/instagrabber/webservices/interceptors/IgErrorsInterceptor.java
  11. 2
      app/src/main/res/values/themes.xml

6
app/src/main/java/awais/instagrabber/adapters/viewholder/feed/FeedItemViewHolder.java

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

9
app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java

@ -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";
@ -136,9 +133,9 @@ public final class PostFetcher extends AsyncTask<Void, Void, Media> {
return ResponseBodyUtils.parseGraphQLItem(media, null); return ResponseBodyUtils.parseGraphQLItem(media, null);
} }
} catch (Exception e) { } catch (Exception e) {
// if (logCollector != null) {
// logCollector.appendException(e, LogCollector.LogFile.ASYNC_POST_FETCHER, "doInBackground");
// }
// if (logCollector != null) {
// logCollector.appendException(e, LogCollector.LogFile.ASYNC_POST_FETCHER, "doInBackground");
// }
Log.e(TAG, "Error fetching post", e); Log.e(TAG, "Error fetching post", e);
} finally { } finally {
if (conn != null) { if (conn != null) {

52
app/src/main/java/awais/instagrabber/customviews/VideoPlayerViewHelper.java

@ -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,29 +156,33 @@ 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))
.build();
final DraweeController controller = Fresco.newDraweeControllerBuilder()
.setControllerListener(new BaseControllerListener<ImageInfo>() {
@Override
public void onFailure(final String id, final Throwable throwable) {
if (videoPlayerCallback != null) {
videoPlayerCallback.onThumbnailLoaded();
}
}
@Override
public void onFinalImageSet(final String id,
final ImageInfo imageInfo,
final Animatable animatable) {
if (videoPlayerCallback != null) {
videoPlayerCallback.onThumbnailLoaded();
}
}
})
.setImageRequest(thumbnailRequest)
.build();
binding.thumbnail.setController(controller);
ImageRequest thumbnailRequest = null;
if (thumbnailUrl != null) {
thumbnailRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(thumbnailUrl)).build();
}
final PipelineDraweeControllerBuilder builder = Fresco.newDraweeControllerBuilder()
.setControllerListener(new BaseControllerListener<ImageInfo>() {
@Override
public void onFailure(final String id,
final Throwable throwable) {
if (videoPlayerCallback != null) {
videoPlayerCallback.onThumbnailLoaded();
}
}
@Override
public void onFinalImageSet(final String id,
final ImageInfo imageInfo,
final Animatable animatable) {
if (videoPlayerCallback != null) {
videoPlayerCallback.onThumbnailLoaded();
}
}
});
if (thumbnailRequest != null) {
builder.setImageRequest(thumbnailRequest);
}
binding.thumbnail.setController(builder.build());
} }
private void loadPlayer() { private void loadPlayer() {

13
app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java

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

65
app/src/main/java/awais/instagrabber/fragments/LocationFragment.java

@ -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();
@ -409,16 +414,16 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
final long locationId = locationModel.getPk(); final long locationId = locationModel.getPk();
// binding.swipeRefreshLayout.setRefreshing(true); // binding.swipeRefreshLayout.setRefreshing(true);
locationDetailsBinding.mainLocationImage.setImageURI("res:/" + R.drawable.ic_location); locationDetailsBinding.mainLocationImage.setImageURI("res:/" + R.drawable.ic_location);
// final String postCount = String.valueOf(locationModel.getCount());
// final SpannableStringBuilder span = new SpannableStringBuilder(getResources().getQuantityString(R.plurals.main_posts_count_inline,
// locationModel.getPostCount() > 2000000000L
// ? 2000000000
// : locationModel.getPostCount().intValue(),
// postCount));
// span.setSpan(new RelativeSizeSpan(1.2f), 0, postCount.length(), 0);
// span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0);
// locationDetailsBinding.mainLocPostCount.setText(span);
// locationDetailsBinding.mainLocPostCount.setVisibility(View.VISIBLE);
// final String postCount = String.valueOf(locationModel.getCount());
// final SpannableStringBuilder span = new SpannableStringBuilder(getResources().getQuantityString(R.plurals.main_posts_count_inline,
// locationModel.getPostCount() > 2000000000L
// ? 2000000000
// : locationModel.getPostCount().intValue(),
// postCount));
// span.setSpan(new RelativeSizeSpan(1.2f), 0, postCount.length(), 0);
// span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0);
// locationDetailsBinding.mainLocPostCount.setText(span);
// locationDetailsBinding.mainLocPostCount.setVisibility(View.VISIBLE);
locationDetailsBinding.locationFullName.setText(locationModel.getName()); locationDetailsBinding.locationFullName.setText(locationModel.getName());
CharSequence biography = locationModel.getAddress() + "\n" + locationModel.getCity(); CharSequence biography = locationModel.getAddress() + "\n" + locationModel.getCity();
// binding.locationBiography.setCaptionIsExpandable(true); // binding.locationBiography.setCaptionIsExpandable(true);
@ -431,22 +436,22 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
} else { } else {
locationDetailsBinding.locationBiography.setVisibility(View.VISIBLE); locationDetailsBinding.locationBiography.setVisibility(View.VISIBLE);
locationDetailsBinding.locationBiography.setText(biography); locationDetailsBinding.locationBiography.setText(biography);
// locationDetailsBinding.locationBiography.addOnHashtagListener(autoLinkItem -> {
// final NavController navController = NavHostFragment.findNavController(this);
// final Bundle bundle = new Bundle();
// final String originalText = autoLinkItem.getOriginalText().trim();
// bundle.putString(ARG_HASHTAG, originalText);
// navController.navigate(R.id.action_global_hashTagFragment, bundle);
// });
// locationDetailsBinding.locationBiography.addOnMentionClickListener(autoLinkItem -> {
// final String originalText = autoLinkItem.getOriginalText().trim();
// navigateToProfile(originalText);
// });
// locationDetailsBinding.locationBiography.addOnEmailClickListener(autoLinkItem -> Utils.openEmailAddress(context,
// autoLinkItem.getOriginalText()
// .trim()));
// locationDetailsBinding.locationBiography
// .addOnURLClickListener(autoLinkItem -> Utils.openURL(context, autoLinkItem.getOriginalText().trim()));
// locationDetailsBinding.locationBiography.addOnHashtagListener(autoLinkItem -> {
// final NavController navController = NavHostFragment.findNavController(this);
// final Bundle bundle = new Bundle();
// final String originalText = autoLinkItem.getOriginalText().trim();
// bundle.putString(ARG_HASHTAG, originalText);
// navController.navigate(R.id.action_global_hashTagFragment, bundle);
// });
// locationDetailsBinding.locationBiography.addOnMentionClickListener(autoLinkItem -> {
// final String originalText = autoLinkItem.getOriginalText().trim();
// navigateToProfile(originalText);
// });
// locationDetailsBinding.locationBiography.addOnEmailClickListener(autoLinkItem -> Utils.openEmailAddress(context,
// autoLinkItem.getOriginalText()
// .trim()));
// locationDetailsBinding.locationBiography
// .addOnURLClickListener(autoLinkItem -> Utils.openURL(context, autoLinkItem.getOriginalText().trim()));
locationDetailsBinding.locationBiography.setOnLongClickListener(v -> { locationDetailsBinding.locationBiography.setOnLongClickListener(v -> {
Utils.copyText(context, biography); Utils.copyText(context, biography);
return true; return true;

15
app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java

@ -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 {
@ -417,10 +412,10 @@ public class StoryViewerFragment extends Fragment {
return true; return true;
} }
} catch (final Exception e) { } catch (final Exception e) {
// if (logCollector != null)
// logCollector.appendException(e, LogCollector.LogFile.ACTIVITY_STORY_VIEWER, "setupListeners",
// new Pair<>("swipeEvent", swipeEvent),
// new Pair<>("diffX", diffX));
// if (logCollector != null)
// logCollector.appendException(e, LogCollector.LogFile.ACTIVITY_STORY_VIEWER, "setupListeners",
// new Pair<>("swipeEvent", swipeEvent),
// new Pair<>("diffX", diffX));
if (BuildConfig.DEBUG) Log.e(TAG, "Error", e); if (BuildConfig.DEBUG) Log.e(TAG, "Error", e);
} }
return false; return false;
@ -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) {

9
app/src/main/java/awais/instagrabber/managers/InboxManager.java

@ -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);
setThread(inbox, index, thread);
try {
final DirectThread threadClone = (DirectThread) thread.clone();
threadClone.setItems(updatedItems);
setThread(inbox, index, threadClone);
} catch (Exception e) {
Log.e(TAG, "setItemsToThread: ", e);
}
} }
} }

7
app/src/main/java/awais/instagrabber/managers/ThreadManager.java

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

11
app/src/main/java/awais/instagrabber/repositories/responses/Media.java

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

11
app/src/main/java/awais/instagrabber/webservices/interceptors/IgErrorsInterceptor.java

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

2
app/src/main/res/values/themes.xml

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

Loading…
Cancel
Save