1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-21 14:17:29 +00:00

Merge remote-tracking branch 'origin/master'

This commit is contained in:
Austin Huang 2021-04-17 16:24:31 -04:00
commit 42e4580209
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
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) {
final long commentsCount = feedModel.getCommentCount();
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) {
@ -75,6 +75,7 @@ public abstract class FeedItemViewHolder extends RecyclerView.ViewHolder {
// final SpannableString spannableString = new SpannableString();
// spannableString.setSpan(new CommentMentionClickSpan(), 0, titleLen, 0);
final User user = media.getUser();
if (user == null) return;
final String title = "@" + user.getUsername();
topBinding.title.setText(title);
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(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT
));
}
else {
} else {
final String locationName = location.getName();
if (TextUtils.isEmpty(locationName)) {
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.utils.NetworkUtils;
import awais.instagrabber.utils.ResponseBodyUtils;
//import awaisomereport.LogCollector;
//import static awais.instagrabber.utils.Utils.logCollector;
public final class PostFetcher extends AsyncTask<Void, Void, Media> {
private static final String TAG = "PostFetcher";
@ -136,9 +133,9 @@ public final class PostFetcher extends AsyncTask<Void, Void, Media> {
return ResponseBodyUtils.parseGraphQLItem(media, null);
}
} 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);
} finally {
if (conn != null) {

View File

@ -14,8 +14,8 @@ import androidx.appcompat.widget.AppCompatTextView;
import androidx.appcompat.widget.PopupMenu;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder;
import com.facebook.drawee.controller.BaseControllerListener;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.imagepipeline.image.ImageInfo;
import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.request.ImageRequestBuilder;
@ -156,29 +156,33 @@ public class VideoPlayerViewHelper implements Player.EventListener {
private void setThumbnail() {
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();
}
}
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();
}
}
})
.setImageRequest(thumbnailRequest)
.build();
binding.thumbnail.setController(controller);
@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() {

View File

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

View File

@ -24,6 +24,7 @@ import androidx.appcompat.app.ActionBar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.PermissionChecker;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.navigation.NavController;
import androidx.navigation.NavDirections;
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.responses.Location;
import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.DownloadUtils;
@ -204,7 +206,9 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
final View mainPostImage,
final int position) {
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;
new PostFetcher(feedModel.getCode(), newFeedModel -> {
opening = false;
@ -223,7 +227,9 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
builder.setSharedProfilePicElement(profilePicView)
.setSharedMainPostElement(mainPostImage);
}
builder.build().show(getChildFragmentManager(), "post_view");
final FragmentManager fragmentManager = getChildFragmentManager();
if (fragmentManager.isDestroyed()) return;
builder.build().show(fragmentManager, "post_view");
opening = false;
}
};
@ -399,8 +405,7 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
try {
Toast.makeText(getContext(), R.string.error_loading_location, Toast.LENGTH_SHORT).show();
binding.swipeRefreshLayout.setEnabled(false);
}
catch (Exception ignored) {}
} catch (Exception ignored) {}
return;
}
setTitle();
@ -409,16 +414,16 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
final long locationId = locationModel.getPk();
// binding.swipeRefreshLayout.setRefreshing(true);
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());
CharSequence biography = locationModel.getAddress() + "\n" + locationModel.getCity();
// binding.locationBiography.setCaptionIsExpandable(true);
@ -431,22 +436,22 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
} else {
locationDetailsBinding.locationBiography.setVisibility(View.VISIBLE);
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 -> {
Utils.copyText(context, biography);
return true;

View File

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

View File

@ -285,8 +285,13 @@ public final class InboxManager {
if (index < 0) return;
final List<DirectThread> threads = inbox.getThreads();
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);
}
}
}

View File

@ -92,14 +92,14 @@ public final class ThreadManager {
private final MutableLiveData<DirectThreadParticipantRequestsResponse> pendingRequests = new MutableLiveData<>(null);
private final String threadId;
private final DirectMessagesService service;
private final long viewerId;
private final ThreadIdOrUserIds threadIdOrUserIds;
private final User currentUser;
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 LiveData<DirectThread> thread;
private LiveData<Integer> inputMode;
@ -157,6 +157,7 @@ public final class ThreadManager {
viewerId = CookieUtils.getUserIdFromCookie(cookie);
final String deviceUuid = settingsHelper.getString(Constants.DEVICE_UUID);
final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
if (csrfToken == null) return;
// if (TextUtils.isEmpty(csrfToken) || viewerId <= 0 || TextUtils.isEmpty(deviceUuid)) {
// 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 double videoDuration;
private final long viewCount;
private final Caption caption;
private Caption caption;
private final boolean canViewerSave;
private final Audio audio;
private final String title;
@ -271,7 +271,14 @@ public class Media implements Serializable {
}
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);
}

View File

@ -5,6 +5,7 @@ import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.fragment.app.FragmentManager;
import com.google.android.material.snackbar.Snackbar;
@ -59,7 +60,7 @@ public class IgErrorsInterceptor implements Interceptor {
return;
case 302: // redirect
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
showErrorDialog(R.string.rate_limit);
}
@ -70,7 +71,7 @@ public class IgErrorsInterceptor implements Interceptor {
try {
final String bodyString = body.string();
final JSONObject jsonObject = new JSONObject(bodyString);
String message = jsonObject.optString("message", null);
String message = jsonObject.optString("message");
if (!TextUtils.isEmpty(message)) {
message = message.toLowerCase();
switch (message) {
@ -91,7 +92,7 @@ public class IgErrorsInterceptor implements Interceptor {
return;
}
}
final String errorType = jsonObject.optString("error_type", null);
final String errorType = jsonObject.optString("error_type");
if (TextUtils.isEmpty(errorType)) return;
if (errorType.equals("sentry_block")) {
showErrorDialog(R.string.sentry_block);
@ -127,7 +128,9 @@ public class IgErrorsInterceptor implements Interceptor {
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() {

View File

@ -126,7 +126,7 @@
<item name="android:dialogTheme">@style/Widget.Dialog.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="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="appBarLayoutStyle">@style/Widget.MaterialComponents.AppBarLayout.Primary</item>
<item name="dmIncomingBgColor">@color/grey_600</item>