From cc9348d8c578261e98b871816545a10cfa0ab70f Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sat, 5 Sep 2020 16:16:11 +0900 Subject: [PATCH] Fix DM fragments, comment out deprecated activities --- .../instagrabber/InstaGrabberApplication.java | 12 +- .../java/awais/instagrabber/MainHelper.java | 3042 ++++++++--------- .../activities/DirectMessagesActivity.java | 188 +- .../instagrabber/activities/MainActivity.java | 3 +- .../activities/MainActivityBackup.java | 1214 +++---- .../activities/NotificationsViewer.java | 9 +- .../instagrabber/activities/PostViewer.java | 1572 ++++----- .../activities/ProfileViewer.java | 1900 +++++----- .../DirectMessageInboxItemViewHolder.java | 26 +- .../dialogs/QuickAccessDialog.java | 18 +- .../fragments/HashTagFragment.java | 5 - .../fragments/LocationFragment.java | 6 - .../fragments/StoryViewerFragment.java | 2 - .../DirectMessageSettingsFragment.java | 104 +- .../DirectMessageThreadFragment.java | 119 +- .../fragments/main/DiscoverFragment.java | 4 - .../fragments/main/ProfileFragment.java | 31 +- .../main/res/layout/layout_dm_inbox_item.xml | 140 +- app/src/main/res/menu/dm_thread_menu.xml | 14 + app/src/main/res/menu/main_menu.xml | 15 +- app/src/main/res/menu/profile_menu.xml | 12 + app/src/main/res/values/strings.xml | 2 + 22 files changed, 4258 insertions(+), 4180 deletions(-) create mode 100644 app/src/main/res/menu/dm_thread_menu.xml create mode 100644 app/src/main/res/menu/profile_menu.xml diff --git a/app/src/main/java/awais/instagrabber/InstaGrabberApplication.java b/app/src/main/java/awais/instagrabber/InstaGrabberApplication.java index 38c62547..422a1d2d 100644 --- a/app/src/main/java/awais/instagrabber/InstaGrabberApplication.java +++ b/app/src/main/java/awais/instagrabber/InstaGrabberApplication.java @@ -8,6 +8,7 @@ import androidx.core.app.NotificationManagerCompat; import androidx.multidex.MultiDexApplication; import com.facebook.drawee.backends.pipeline.Fresco; +import com.facebook.imagepipeline.core.ImagePipelineConfig; import java.net.CookieHandler; import java.text.SimpleDateFormat; @@ -36,7 +37,12 @@ public final class InstaGrabberApplication extends MultiDexApplication { @Override public void onCreate() { super.onCreate(); - Fresco.initialize(this); + final ImagePipelineConfig imagePipelineConfig = ImagePipelineConfig + .newBuilder(this) + // .setMainDiskCacheConfig(diskCacheConfig) + .setDownsampleEnabled(true) + .build(); + Fresco.initialize(this, imagePipelineConfig); if (BuildConfig.DEBUG) { try { @@ -74,8 +80,8 @@ public final class InstaGrabberApplication extends MultiDexApplication { if (datetimeParser == null) datetimeParser = new SimpleDateFormat( settingsHelper.getBoolean(Constants.CUSTOM_DATE_TIME_FORMAT_ENABLED) ? - settingsHelper.getString(Constants.CUSTOM_DATE_TIME_FORMAT) : - settingsHelper.getString(Constants.DATE_TIME_FORMAT), LocaleUtils.getCurrentLocale()); + settingsHelper.getString(Constants.CUSTOM_DATE_TIME_FORMAT) : + settingsHelper.getString(Constants.DATE_TIME_FORMAT), LocaleUtils.getCurrentLocale()); settingsHelper.putString(Constants.DEVICE_UUID, UUID.randomUUID().toString()); } diff --git a/app/src/main/java/awais/instagrabber/MainHelper.java b/app/src/main/java/awais/instagrabber/MainHelper.java index 432720f6..0769093a 100755 --- a/app/src/main/java/awais/instagrabber/MainHelper.java +++ b/app/src/main/java/awais/instagrabber/MainHelper.java @@ -1,1521 +1,1521 @@ -package awais.instagrabber; - -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.res.ColorStateList; -import android.content.res.Resources; -import android.graphics.Typeface; -import android.net.Uri; -import android.os.AsyncTask; -import android.os.Bundle; -import android.text.SpannableStringBuilder; -import android.text.method.LinkMovementMethod; -import android.text.style.RelativeSizeSpan; -import android.text.style.StyleSpan; -import android.util.Log; -import android.util.TypedValue; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; -import androidx.core.content.ContextCompat; -import androidx.core.view.GravityCompat; -import androidx.core.widget.ImageViewCompat; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; - -import com.bumptech.glide.Glide; -import com.bumptech.glide.RequestManager; -import com.facebook.common.executors.UiThreadImmediateExecutorService; -import com.facebook.datasource.BaseDataSubscriber; -import com.facebook.datasource.DataSource; -import com.facebook.drawee.backends.pipeline.Fresco; -import com.facebook.imagepipeline.request.ImageRequest; - -import java.io.DataOutputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import awais.instagrabber.activities.CommentsViewerFragment; -import awais.instagrabber.activities.MainActivityBackup; -import awais.instagrabber.activities.PostViewer; -import awais.instagrabber.adapters.DiscoverAdapter; -import awais.instagrabber.adapters.FeedAdapter; -import awais.instagrabber.adapters.PostsAdapter; -import awais.instagrabber.adapters.viewholder.feed.FeedItemViewHolder; -import awais.instagrabber.asyncs.DiscoverFetcher; -import awais.instagrabber.asyncs.FeedFetcher; -import awais.instagrabber.asyncs.FeedStoriesFetcher; -import awais.instagrabber.asyncs.HashtagFetcher; -import awais.instagrabber.asyncs.HighlightsFetcher; -import awais.instagrabber.asyncs.LocationFetcher; -import awais.instagrabber.asyncs.PostsFetcher; -import awais.instagrabber.asyncs.ProfileFetcher; -import awais.instagrabber.asyncs.i.iStoryStatusFetcher; -import awais.instagrabber.asyncs.i.iTopicFetcher; -import awais.instagrabber.customviews.MouseDrawer; -import awais.instagrabber.customviews.RamboTextView; -import awais.instagrabber.customviews.helpers.GridAutofitLayoutManager; -import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration; -import awais.instagrabber.customviews.helpers.PauseGlideOnFlingScrollListener; -import awais.instagrabber.customviews.helpers.RecyclerLazyLoader; -import awais.instagrabber.customviews.helpers.VideoAwareRecyclerScroller; -import awais.instagrabber.fragments.SavedViewerFragment; -import awais.instagrabber.interfaces.FetchListener; -import awais.instagrabber.interfaces.MentionClickListener; -import awais.instagrabber.models.BasePostModel; -import awais.instagrabber.models.DiscoverItemModel; -import awais.instagrabber.models.DiscoverTopicModel; -import awais.instagrabber.models.FeedModel; -import awais.instagrabber.models.FeedStoryModel; -import awais.instagrabber.models.IntentModel; -import awais.instagrabber.models.PostModel; -import awais.instagrabber.models.ProfileModel; -import awais.instagrabber.models.ViewerPostModel; -import awais.instagrabber.models.enums.DownloadMethod; -import awais.instagrabber.models.enums.IntentModelType; -import awais.instagrabber.models.enums.MediaItemType; -import awais.instagrabber.models.enums.PostItemType; -import awais.instagrabber.utils.Constants; -import awais.instagrabber.utils.DataBox; -import awais.instagrabber.utils.Utils; -import awaisomereport.LogCollector; - -import static awais.instagrabber.utils.Constants.AUTOLOAD_POSTS; -import static awais.instagrabber.utils.Constants.BOTTOM_TOOLBAR; -import static awais.instagrabber.utils.Utils.logCollector; -import static awais.instagrabber.utils.Utils.settingsHelper; - -@Deprecated -public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener { - private static final String TAG = "MainHelper"; - private static final double MAX_VIDEO_HEIGHT = 0.9 * Utils.displayMetrics.heightPixels; - private static final int RESIZED_VIDEO_HEIGHT = (int) (0.8 * Utils.displayMetrics.heightPixels); - public static final boolean SHOULD_AUTO_PLAY = settingsHelper.getBoolean(Constants.AUTOPLAY_VIDEOS); - - private static AsyncTask currentlyExecuting; - private AsyncTask prevStoriesFetcher; - private FeedStoryModel[] stories; - private boolean hasNextPage = false; - private boolean feedHasNextPage = false; - private boolean discoverHasMore = false; - private String endCursor = null; - private String feedEndCursor = null; - private String discoverEndMaxId = null; - private String topic = null; - private String rankToken = null; - private String[] topicIds = null; - - private final boolean autoloadPosts; - private final FetchListener postsFetchListener = new FetchListener() { - @Override - public void onResult(final PostModel[] result) { - if (result != null) { - final int oldSize = mainActivity.allItems.size(); - mainActivity.allItems.addAll(Arrays.asList(result)); - - postsAdapter.notifyItemRangeInserted(oldSize, result.length); - - mainActivity.mainBinding.profileView.mainPosts.post(() -> { - mainActivity.mainBinding.profileView.mainPosts.setNestedScrollingEnabled(true); - mainActivity.mainBinding.profileView.mainPosts.setVisibility(View.VISIBLE); - }); - - if (isHashtag) - mainActivity.mainBinding.toolbar.toolbar.setTitle(mainActivity.userQuery); - else if (isLocation) - mainActivity.mainBinding.toolbar.toolbar.setTitle(mainActivity.locationModel.getName()); - else - mainActivity.mainBinding.toolbar.toolbar.setTitle("@" + mainActivity.profileModel.getUsername()); - - final PostModel model = result[result.length - 1]; - if (model != null) { - endCursor = model.getEndCursor(); - hasNextPage = model.hasNextPage(); - if (autoloadPosts && hasNextPage) - currentlyExecuting = new PostsFetcher( - mainActivity.profileModel != null ? mainActivity.profileModel.getId() - : (mainActivity.hashtagModel != null - ? mainActivity.userQuery - : mainActivity.locationModel.getId()), - mainActivity.profileModel != null - ? PostItemType.MAIN - : (mainActivity.hashtagModel != null ? PostItemType.HASHTAG : PostItemType.LOCATION), - endCursor, - this) - .setUsername((isLocation || isHashtag) ? null : mainActivity.profileModel.getUsername()) - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - else { - mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(false); - } - model.setPageCursor(false, null); - } - } else { - mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(false); - mainActivity.mainBinding.profileView.privatePage1.setImageResource(R.drawable.ic_cancel); - mainActivity.mainBinding.profileView.privatePage2.setText(R.string.empty_acc); - mainActivity.mainBinding.profileView.privatePage.setVisibility(View.VISIBLE); - } - } - }; - private final FetchListener feedFetchListener = new FetchListener() { - @Override - public void doBefore() { - mainActivity.mainBinding.feedView.feedSwipeRefreshLayout - .post(() -> mainActivity.mainBinding.feedView.feedSwipeRefreshLayout.setRefreshing(true)); - } - - @Override - public void onResult(final FeedModel[] result) { - if (result == null) { - return; - } - final int oldSize = mainActivity.feedItems.size(); - final HashMap thumbToFeedMap = new HashMap<>(); - for (final FeedModel feedModel : result) { - thumbToFeedMap.put(feedModel.getThumbnailUrl(), feedModel); - } - final BaseDataSubscriber subscriber = new BaseDataSubscriber() { - int success = 0; - int failed = 0; - - @Override - protected void onNewResultImpl(@NonNull final DataSource dataSource) { - // dataSource - final Map extras = dataSource.getExtras(); - if (extras == null) { - return; - } - // Log.d(TAG, "extras: " + extras); - final Uri thumbUri = (Uri) extras.get("uri_source"); - if (thumbUri == null) { - return; - } - final Integer encodedWidth = (Integer) extras.get("encoded_width"); - final Integer encodedHeight = (Integer) extras.get("encoded_height"); - if (encodedWidth == null || encodedHeight == null) { - return; - } - final FeedModel feedModel = thumbToFeedMap.get(thumbUri.toString()); - if (feedModel == null) { - return; - } - int requiredWidth = Utils.displayMetrics.widthPixels; - int resultingHeight = Utils.getResultingHeight(requiredWidth, encodedHeight, encodedWidth); - if (feedModel.getItemType() == MediaItemType.MEDIA_TYPE_VIDEO && resultingHeight >= MAX_VIDEO_HEIGHT) { - // If its a video and the height is too large, need to reduce the height, - // so that entire video fits on screen - resultingHeight = RESIZED_VIDEO_HEIGHT; - requiredWidth = Utils.getResultingWidth(RESIZED_VIDEO_HEIGHT, resultingHeight, requiredWidth); - } - feedModel.setImageWidth(requiredWidth); - feedModel.setImageHeight(resultingHeight); - success++; - updateAdapter(); - } - - @Override - protected void onFailureImpl(@NonNull final DataSource dataSource) { - failed++; - updateAdapter(); - } - - public void updateAdapter() { - if (failed + success != result.length) return; - mainActivity.feedItems.addAll(Arrays.asList(result)); - feedAdapter.submitList(mainActivity.feedItems); - feedAdapter.notifyItemRangeInserted(oldSize, result.length); - - mainActivity.mainBinding.feedView.feedPosts - .post(() -> mainActivity.mainBinding.feedView.feedPosts.setNestedScrollingEnabled(true)); - - final PostModel feedPostModel = result[result.length - 1]; - if (feedPostModel != null) { - feedEndCursor = feedPostModel.getEndCursor(); - feedHasNextPage = feedPostModel.hasNextPage(); - feedPostModel.setPageCursor(false, null); - } - mainActivity.mainBinding.feedView.feedSwipeRefreshLayout.setRefreshing(false); - } - }; - for (final FeedModel feedModel : result) { - final DataSource ds = Fresco.getImagePipeline().prefetchToBitmapCache(ImageRequest.fromUri(feedModel.getThumbnailUrl()), null); - ds.subscribe(subscriber, UiThreadImmediateExecutorService.getInstance()); - } - } - }; - private final FetchListener discoverFetchListener = new FetchListener() { - @Override - public void doBefore() { - mainActivity.mainBinding.discoverSwipeRefreshLayout.setRefreshing(true); - } - - @Override - public void onResult(final DiscoverItemModel[] result) { - if (result == null || result.length == 0) { - Toast.makeText(mainActivity, R.string.discover_empty, Toast.LENGTH_SHORT).show(); - } else { - final int oldSize = mainActivity.discoverItems.size(); - mainActivity.discoverItems.addAll(Arrays.asList(result)); - discoverAdapter.notifyItemRangeInserted(oldSize, result.length); - - final DiscoverItemModel discoverItemModel = result[result.length - 1]; - if (discoverItemModel != null) { - discoverEndMaxId = discoverItemModel.getNextMaxId(); - discoverHasMore = discoverItemModel.hasMore(); - discoverItemModel.setMore(false, null); - } - } - - mainActivity.mainBinding.discoverSwipeRefreshLayout.setRefreshing(false); - } - }; - private final FetchListener topicFetchListener = new FetchListener() { - @Override - public void doBefore() {} - - @Override - public void onResult(final DiscoverTopicModel result) { - if (result != null) { - topicIds = result.getIds(); - rankToken = result.getToken(); - ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<>( - mainActivity, android.R.layout.simple_spinner_dropdown_item, result.getNames()); - mainActivity.mainBinding.discoverType.setAdapter(spinnerArrayAdapter); - } - } - }; - private final FetchListener feedStoriesListener = new FetchListener() { - @Override - public void doBefore() { - mainActivity.mainBinding.feedView.feedStories.setVisibility(View.GONE); - } - - @Override - public void onResult(final FeedStoryModel[] result) { - // feedStoriesAdapter.setData(result); - if (result != null && result.length > 0) { - mainActivity.mainBinding.feedView.feedStories.setVisibility(View.VISIBLE); - stories = result; - } - } - }; - private final MentionClickListener mentionClickListener = new MentionClickListener() { - @Override - public void onClick(final RamboTextView view, final String text, final boolean isHashtag, final boolean isLocation) { - new AlertDialog.Builder(mainActivity) - .setMessage(isHashtag ? R.string.comment_view_mention_hash_search : R.string.comment_view_mention_user_search) - .setTitle(text).setNegativeButton(R.string.cancel, null).setPositiveButton(R.string.ok, (dialog, which) -> { - if (MainActivityBackup.scanHack != null) MainActivityBackup.scanHack.onResult(text); - }).show(); - } - }; - // private final FeedStoriesAdapter feedStoriesAdapter = new FeedStoriesAdapter(null, new View.OnClickListener() { - // @Override - // public void onClick(final View v) { - // final Object tag = v.getTag(); - // if (tag instanceof FeedStoryModel) { - // final FeedStoryModel feedStoryModel = (FeedStoryModel) tag; - // final int index = indexOfIntArray(stories, feedStoryModel); - // new iStoryStatusFetcher(feedStoryModel.getStoryMediaId(), null, false, false, false, false, result -> { - // if (result != null && result.length > 0) - // mainActivity.startActivity(new Intent(mainActivity, StoryViewer.class) - // .putExtra(Constants.EXTRAS_STORIES, result) - // .putExtra(Constants.EXTRAS_USERNAME, feedStoryModel.getProfileModel().getUsername()) - // .putExtra(Constants.FEED, stories) - // .putExtra(Constants.FEED_ORDER, index) - // ); - // else - // Toast.makeText(mainActivity, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); - // }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - // } - // } - // }); - private MainActivityBackup mainActivity; - private Resources resources; - private final View collapsingToolbar; - private final RecyclerLazyLoader lazyLoader; - private boolean isHashtag; - private boolean isLocation; - private PostsAdapter postsAdapter; - private FeedAdapter feedAdapter; - private RecyclerLazyLoader feedLazyLoader, discoverLazyLoader; - private DiscoverAdapter discoverAdapter; - private String cookie = settingsHelper.getString(Constants.COOKIE); - private boolean isLoggedIn; - private RequestManager glide; - private VideoAwareRecyclerScroller videoAwareRecyclerScroller; - - public MainHelper(@NonNull final MainActivityBackup mainActivity) { - stopCurrentExecutor(); - - this.mainActivity = mainActivity; - this.resources = mainActivity.getResources(); - this.autoloadPosts = settingsHelper.getBoolean(AUTOLOAD_POSTS); - glide = Glide.with(mainActivity); - - mainActivity.mainBinding.profileView.swipeRefreshLayout.setOnRefreshListener(this); - mainActivity.mainBinding.profileView.mainUrl.setMovementMethod(new LinkMovementMethod()); - - final LinearLayout iconSlider = mainActivity.findViewById(R.id.iconSlider); - final ImageView iconFeed = (ImageView) iconSlider.getChildAt(0); - final ImageView iconProfile = (ImageView) iconSlider.getChildAt(1); - final ImageView iconDiscover = (ImageView) iconSlider.getChildAt(2); - - final boolean isBottomToolbar = settingsHelper.getBoolean(BOTTOM_TOOLBAR); - isLoggedIn = !Utils.isEmpty(cookie) && Utils.getUserIdFromCookie(cookie) != null; - if (!isLoggedIn) { - mainActivity.mainBinding.drawerLayout.removeView(mainActivity.mainBinding.feedView.feedLayout); - mainActivity.mainBinding.drawerLayout.removeView(mainActivity.mainBinding.discoverLayout); - iconFeed.setAlpha(0.4f); - iconDiscover.setAlpha(0.4f); - } else { - iconFeed.setAlpha(1f); - iconDiscover.setAlpha(1f); - - setupExplore(); - - setupFeed(); - - final TypedValue resolvedAttr = new TypedValue(); - mainActivity.getTheme().resolveAttribute(android.R.attr.textColorPrimary, resolvedAttr, true); - - final int selectedItem = ContextCompat.getColor(mainActivity, resolvedAttr.resourceId != 0 ? resolvedAttr.resourceId : resolvedAttr.data); - final ColorStateList colorStateList = ColorStateList.valueOf(selectedItem); - - mainActivity.mainBinding.toolbar.toolbar.measure(0, -1); - final int toolbarMeasuredHeight = mainActivity.mainBinding.toolbar.toolbar.getMeasuredHeight(); - - final ViewGroup.LayoutParams layoutParams = mainActivity.mainBinding.toolbar.toolbar.getLayoutParams(); - final MouseDrawer.DrawerListener simpleDrawerListener = new MouseDrawer.DrawerListener() { - private final String titleDiscover = resources.getString(R.string.title_discover); - - @Override - public void onDrawerSlide(final View drawerView, @MouseDrawer.EdgeGravity final int gravity, final float slideOffset) { - final int currentIconAlpha = (int) Math.max(100, 255 - 255 * slideOffset); - final int otherIconAlpha = (int) Math.max(100, 255 * slideOffset); - - ImageViewCompat.setImageTintList(iconProfile, colorStateList.withAlpha(currentIconAlpha)); - - final boolean drawerOpening = slideOffset > 0.0f; - final int alpha; - final ColorStateList imageTintList; - - if (gravity == GravityCompat.START) { - // this helps hide the toolbar when opening feed - - final int roundedToolbarHeight; - final float toolbarHeight; - - if (isBottomToolbar) { - toolbarHeight = toolbarMeasuredHeight * slideOffset; - roundedToolbarHeight = -Math.round(toolbarHeight); - } else { - toolbarHeight = -toolbarMeasuredHeight * slideOffset; - roundedToolbarHeight = Math.round(toolbarHeight); - } - - layoutParams.height = Math.max(0, Math.min(toolbarMeasuredHeight, toolbarMeasuredHeight + roundedToolbarHeight)); - mainActivity.mainBinding.toolbar.toolbar.setLayoutParams(layoutParams); - mainActivity.mainBinding.toolbar.toolbar.setTranslationY(toolbarHeight); - - imageTintList = ImageViewCompat.getImageTintList(iconDiscover); - alpha = imageTintList != null ? (imageTintList.getDefaultColor() & 0xFF_000000) >> 24 : 0; - - if (drawerOpening && alpha > 100) - ImageViewCompat.setImageTintList(iconDiscover, colorStateList.withAlpha(currentIconAlpha)); - - ImageViewCompat.setImageTintList(iconFeed, colorStateList.withAlpha(otherIconAlpha)); - } else { - // this changes toolbar title - mainActivity.mainBinding.toolbar.toolbar.setTitle(slideOffset >= 0.466 ? titleDiscover : - (mainActivity.userQuery == null - ? resources.getString(R.string.app_name) - : mainActivity.userQuery)); - - imageTintList = ImageViewCompat.getImageTintList(iconFeed); - alpha = imageTintList != null ? (imageTintList.getDefaultColor() & 0xFF_000000) >> 24 : 0; - - if (drawerOpening && alpha > 100) - ImageViewCompat.setImageTintList(iconFeed, colorStateList.withAlpha(currentIconAlpha)); - - ImageViewCompat.setImageTintList(iconDiscover, colorStateList.withAlpha(otherIconAlpha)); - } - } - - @Override - public void onDrawerOpened(@NonNull final View drawerView, @MouseDrawer.EdgeGravity final int gravity) { - if (gravity == GravityCompat.START || drawerView == mainActivity.mainBinding.feedView.feedLayout) { - if (videoAwareRecyclerScroller != null) { - if (SHOULD_AUTO_PLAY) { - videoAwareRecyclerScroller.startPlaying(); - } - } - } else { - // clear selection - isSelectionCleared(); - } - } - - @Override - public void onDrawerClosed(@NonNull final View drawerView, @MouseDrawer.EdgeGravity final int gravity) { - if (gravity == GravityCompat.START || drawerView == mainActivity.mainBinding.feedView.feedLayout) { - if (videoAwareRecyclerScroller != null) { - videoAwareRecyclerScroller.stopPlaying(); - } - } else { - // clear selection - isSelectionCleared(); - } - } - }; - - ImageViewCompat.setImageTintList(iconFeed, colorStateList.withAlpha(100)); // to change colors when created - ImageViewCompat.setImageTintList(iconProfile, colorStateList.withAlpha(255)); // to change colors when created - ImageViewCompat.setImageTintList(iconDiscover, colorStateList.withAlpha(100)); // to change colors when created - - mainActivity.mainBinding.drawerLayout.addDrawerListener(simpleDrawerListener); - } - - collapsingToolbar = mainActivity.mainBinding.profileView.appBarLayout.getChildAt(0); - - mainActivity.mainBinding.profileView.mainPosts.setNestedScrollingEnabled(false); - mainActivity.mainBinding.profileView.highlightsList - .setLayoutManager(new LinearLayoutManager(mainActivity, LinearLayoutManager.HORIZONTAL, false)); - mainActivity.mainBinding.profileView.highlightsList.setAdapter(mainActivity.highlightsAdapter); - - // int color = -1; - // final Drawable background = main.mainBinding.profileView.appBarLayout.getBackground(); - // if (background instanceof MaterialShapeDrawable) { - // final MaterialShapeDrawable drawable = (MaterialShapeDrawable) background; - // final ColorStateList fillColor = drawable.getFillColor(); - // if (fillColor != null) color = fillColor.getDefaultColor(); - // } else { - // final Bitmap bitmap = Bitmap.createBitmap(9, 9, Bitmap.Config.ARGB_8888); - // final Canvas canvas = new Canvas(); - // canvas.setBitmap(bitmap); - // background.draw(canvas); - // color = bitmap.getPixel(4, 4); - // if (!bitmap.isRecycled()) bitmap.recycle(); - // } - // if (color == -1 || color == 0) color = resources.getBoolean(R.bool.isNight) ? 0xff212121 : 0xfff5f5f5; - // main.mainBinding.profileView.profileInfo.setBackgroundColor(color); - // if (!isBottomToolbar) main.mainBinding.toolbar.toolbar.setBackgroundColor(color); - - // main.mainBinding.profileView.appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { - // private int height; - // - // @Override - // public void onOffsetChanged(final AppBarLayout appBarLayout, final int verticalOffset) { - // if (height == 0) { - // height = main.mainBinding.profileView.profileInfo.getHeight(); - // collapsingToolbar.setMinimumHeight(height); - // } - // main.mainBinding.profileView.profileInfo.setTranslationY(-Math.min(0, verticalOffset)); - // } - // }); - - mainActivity.setSupportActionBar(mainActivity.mainBinding.toolbar.toolbar); - if (isBottomToolbar) { - final LinearLayout linearLayout = (LinearLayout) mainActivity.mainBinding.toolbar.toolbar.getParent(); - linearLayout.removeView(mainActivity.mainBinding.toolbar.toolbar); - linearLayout.addView(mainActivity.mainBinding.toolbar.toolbar, linearLayout.getChildCount()); - } - - // change the next number to adjust grid - final GridAutofitLayoutManager layoutManager = new GridAutofitLayoutManager(mainActivity, Utils.convertDpToPx(110)); - mainActivity.mainBinding.profileView.mainPosts.setLayoutManager(layoutManager); - mainActivity.mainBinding.profileView.mainPosts.addItemDecoration(new GridSpacingItemDecoration(Utils.convertDpToPx(4))); - // mainActivity.mainBinding.profileView.mainPosts.setAdapter(postsAdapter = new PostsAdapter(/*mainActivity.allItems,*/ v -> { - // final Object tag = v.getTag(); - // if (tag instanceof PostModel) { - // final PostModel postModel = (PostModel) tag; - // - // if (postsAdapter.isSelecting) toggleSelection(postModel); - // else mainActivity.startActivity(new Intent(mainActivity, PostViewer.class) - // .putExtra(Constants.EXTRAS_INDEX, postModel.getPosition()) - // .putExtra(Constants.EXTRAS_POST, postModel) - // .putExtra(Constants.EXTRAS_USER, mainActivity.userQuery) - // .putExtra(Constants.EXTRAS_TYPE, ItemGetType.MAIN_ITEMS)); - // } - // }, v -> { // long click listener - // // final Object tag = v.getTag(); - // // if (tag instanceof PostModel) { - // // postsAdapter.isSelecting = true; - // // toggleSelection((PostModel) tag); - // // } - // // return true; - // return false; - // })); - - this.lazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> { - if ((!autoloadPosts || isHashtag) && hasNextPage) { - mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(true); - stopCurrentExecutor(); - currentlyExecuting = new PostsFetcher(mainActivity.profileModel != null ? mainActivity.profileModel.getId() - : (mainActivity.hashtagModel != null - ? mainActivity.userQuery - : mainActivity.locationModel.getId()), - mainActivity.profileModel != null - ? PostItemType.MAIN - : (mainActivity.hashtagModel != null ? PostItemType.HASHTAG : PostItemType.LOCATION), - endCursor, - postsFetchListener) - .setUsername((isHashtag || isLocation) ? null : mainActivity.profileModel.getUsername()) - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - endCursor = null; - } - }); - mainActivity.mainBinding.profileView.mainPosts.addOnScrollListener(lazyLoader); - } - - private final View.OnClickListener clickListener = v -> { - if (mainActivity == null) { - return; - } - final Object tag = v.getTag(); - final Context context = v.getContext(); - - if (tag instanceof FeedModel) { - final FeedModel feedModel = (FeedModel) tag; - - if (v instanceof RamboTextView) { - if (feedModel.isMentionClicked()) - feedModel.toggleCaption(); - feedModel.setMentionClicked(false); - if (!FeedItemViewHolder.expandCollapseTextView((RamboTextView) v, feedModel.getPostCaption())) - feedModel.toggleCaption(); - - } else { - final int id = v.getId(); - switch (id) { - case R.id.btnComments: - mainActivity.startActivityForResult(new Intent(mainActivity, CommentsViewerFragment.class) - .putExtra(Constants.EXTRAS_SHORTCODE, feedModel.getShortCode()) - .putExtra(Constants.EXTRAS_POST, feedModel.getPostId()) - .putExtra(Constants.EXTRAS_USER, feedModel.getProfileModel().getId()), 6969); - break; - - case R.id.viewStoryPost: - mainActivity.startActivity(new Intent(mainActivity, PostViewer.class) - .putExtra(Constants.EXTRAS_INDEX, feedModel.getPosition()) - .putExtra(Constants.EXTRAS_POST, new PostModel(feedModel.getShortCode(), false)) - .putExtra(Constants.EXTRAS_TYPE, PostItemType.FEED)); - break; - - case R.id.btnDownload: - ProfileModel profileModel = feedModel.getProfileModel(); - final String username = profileModel != null ? profileModel.getUsername() : null; - - final ViewerPostModel[] sliderItems = feedModel.getSliderItems(); - - if (feedModel.getItemType() != MediaItemType.MEDIA_TYPE_SLIDER || sliderItems == null || sliderItems.length == 1) - Utils.batchDownload(context, username, DownloadMethod.DOWNLOAD_FEED, Collections.singletonList(feedModel)); - else { - final ArrayList postModels = new ArrayList<>(); - final DialogInterface.OnClickListener clickListener1 = (dialog, which) -> { - postModels.clear(); - - final boolean breakWhenFoundSelected = which == DialogInterface.BUTTON_POSITIVE; - - for (final ViewerPostModel sliderItem : sliderItems) { - if (sliderItem != null) { - if (!breakWhenFoundSelected) - postModels.add(sliderItem); - else if (sliderItem.isSelected()) { - postModels.add(sliderItem); - break; - } - } - } - - // shows 0 items on first item of viewpager cause onPageSelected hasn't been called yet - if (breakWhenFoundSelected && postModels.size() == 0) - postModels.add(sliderItems[0]); - - if (postModels.size() > 0) - Utils.batchDownload(context, username, DownloadMethod.DOWNLOAD_FEED, postModels); - }; - - new AlertDialog.Builder(context).setTitle(R.string.post_viewer_download_dialog_title) - .setPositiveButton(R.string.post_viewer_download_current, clickListener1) - .setNegativeButton(R.string.post_viewer_download_album, clickListener1).show(); - } - break; - - case R.id.ivProfilePic: - profileModel = feedModel.getProfileModel(); - if (profileModel != null) - mentionClickListener.onClick(null, profileModel.getUsername(), false, false); - break; - } - } - } - }; - - private void setupFeed() { - mainActivity.mainBinding.feedView.feedStories.setLayoutManager(new LinearLayoutManager(mainActivity, LinearLayoutManager.HORIZONTAL, false)); - // mainActivity.mainBinding.feedView.feedStories.setAdapter(feedStoriesAdapter); - refreshFeedStories(); - - final LinearLayoutManager layoutManager = new LinearLayoutManager(mainActivity); - mainActivity.mainBinding.feedView.feedPosts.setHasFixedSize(true); - mainActivity.mainBinding.feedView.feedPosts.setLayoutManager(layoutManager); - mainActivity.mainBinding.feedView.feedPosts.setAdapter(feedAdapter = new FeedAdapter(clickListener, (view, text, isHashtag, isLocation) -> - new AlertDialog.Builder(mainActivity) - .setMessage(isHashtag ? R.string.comment_view_mention_hash_search : R.string.comment_view_mention_user_search) - .setTitle(text).setNegativeButton(R.string.cancel, null).setPositiveButton(R.string.ok, (dialog, which) -> { - if (MainActivityBackup.scanHack != null) { - mainActivity.mainBinding.drawerLayout.closeDrawers(); - MainActivityBackup.scanHack.onResult(text); - } - }).show())); - - mainActivity.mainBinding.feedView.feedSwipeRefreshLayout.setOnRefreshListener(() -> { - refreshFeedStories(); - - if (feedLazyLoader != null) feedLazyLoader.resetState(); - mainActivity.feedItems.clear(); - if (feedAdapter != null) feedAdapter.notifyDataSetChanged(); - new FeedFetcher(feedFetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - }); - - mainActivity.mainBinding.feedView.feedPosts - .addOnScrollListener(feedLazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> { - if (feedHasNextPage) { - mainActivity.mainBinding.feedView.feedSwipeRefreshLayout.setRefreshing(true); - new FeedFetcher(feedEndCursor, feedFetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - feedEndCursor = null; - } - })); - - if (SHOULD_AUTO_PLAY) { - videoAwareRecyclerScroller = new VideoAwareRecyclerScroller(); - mainActivity.mainBinding.feedView.feedPosts.addOnScrollListener(videoAwareRecyclerScroller); - } - mainActivity.mainBinding.feedView.feedPosts.addOnScrollListener(new PauseGlideOnFlingScrollListener(glide)); - - new FeedFetcher(feedFetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - private void refreshFeedStories() { - // todo setup feed stories - if (prevStoriesFetcher != null) { - try { - prevStoriesFetcher.cancel(true); - } catch (final Exception e) { - // ignore - } - } - prevStoriesFetcher = new FeedStoriesFetcher(feedStoriesListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - private void setupExplore() { - final GridAutofitLayoutManager layoutManager = new GridAutofitLayoutManager(mainActivity, Utils.convertDpToPx(110)); - mainActivity.mainBinding.discoverPosts.setLayoutManager(layoutManager); - mainActivity.mainBinding.discoverPosts.addItemDecoration(new GridSpacingItemDecoration(Utils.convertDpToPx(4))); - - new iTopicFetcher(topicFetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - mainActivity.mainBinding.discoverType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView parent, View view, int pos, long id) { - if (topicIds != null) { - topic = topicIds[pos]; - mainActivity.mainBinding.discoverSwipeRefreshLayout.setRefreshing(true); - if (discoverLazyLoader != null) discoverLazyLoader.resetState(); - mainActivity.discoverItems.clear(); - if (discoverAdapter != null) discoverAdapter.notifyDataSetChanged(); - new DiscoverFetcher(topic, null, rankToken, discoverFetchListener, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - } - - @Override - public void onNothingSelected(AdapterView parent) { - } - }); - - mainActivity.mainBinding.discoverSwipeRefreshLayout.setOnRefreshListener(() -> { - if (discoverLazyLoader != null) discoverLazyLoader.resetState(); - mainActivity.discoverItems.clear(); - if (discoverAdapter != null) discoverAdapter.notifyDataSetChanged(); - new DiscoverFetcher(topic, null, rankToken, discoverFetchListener, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - }); - - // mainActivity.mainBinding.discoverPosts.setAdapter(discoverAdapter = new DiscoverAdapter(mainActivity.discoverItems, v -> { - // final Object tag = v.getTag(); - // if (tag instanceof DiscoverItemModel) { - // final DiscoverItemModel itemModel = (DiscoverItemModel) tag; - // - // if (discoverAdapter.isSelecting) toggleDiscoverSelection(itemModel); - // else mainActivity.startActivity(new Intent(mainActivity, PostViewer.class) - // .putExtra(Constants.EXTRAS_INDEX, itemModel.getPosition()) - // .putExtra(Constants.EXTRAS_TYPE, ItemGetType.DISCOVER_ITEMS) - // .putExtra(Constants.EXTRAS_POST, new PostModel(itemModel.getShortCode(), false))); - // } - // }, v -> { - // final Object tag = v.getTag(); - // if (tag instanceof DiscoverItemModel) { - // discoverAdapter.isSelecting = true; - // toggleDiscoverSelection((DiscoverItemModel) tag); - // } - // return true; - // })); - - mainActivity.mainBinding.discoverPosts - .addOnScrollListener(discoverLazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> { - if (discoverHasMore) { - mainActivity.mainBinding.discoverSwipeRefreshLayout.setRefreshing(true); - new DiscoverFetcher(topic, discoverEndMaxId, rankToken, discoverFetchListener, false) - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - discoverEndMaxId = null; - } - })); - } - - public void onIntent(final Intent intent) { - if (intent != null) { - final String action = intent.getAction(); - if (!Utils.isEmpty(action) && !Intent.ACTION_MAIN.equals(action)) { - intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); - - boolean error = true; - - String data = null; - final Bundle extras = intent.getExtras(); - if (extras != null) { - final Object extraData = extras.get(Intent.EXTRA_TEXT); - if (extraData != null) { - error = false; - data = extraData.toString(); - } - } - - if (error) { - final Uri intentData = intent.getData(); - if (intentData != null) data = intentData.toString(); - } - - if (data != null && !Utils.isEmpty(data)) { - if (data.indexOf('\n') > 0) data = data.substring(data.lastIndexOf('\n') + 1); - - final IntentModel model = Utils.stripString(data); - if (model != null) { - final String modelText = model.getText(); - final IntentModelType modelType = model.getType(); - - if (modelType == IntentModelType.POST) { - mainActivity.startActivityForResult(new Intent(mainActivity, PostViewer.class) - .putExtra(Constants.EXTRAS_USER, mainActivity.userQuery) - .putExtra(Constants.EXTRAS_POST, new PostModel(modelText, false)), 9629); - } else { - mainActivity.addToStack(); - mainActivity.userQuery = modelType == IntentModelType.HASHTAG ? ('#' + modelText) : - (modelType == IntentModelType.LOCATION ? modelText : ('@' + modelText)); - onRefresh(); - } - } - } - } - } - } - - @Override - public void onRefresh() { - mainActivity.mainBinding.drawerLayout.closeDrawers(); - if (lazyLoader != null) lazyLoader.resetState(); - stopCurrentExecutor(); - mainActivity.allItems.clear(); - mainActivity.selectedItems.clear(); - if (postsAdapter != null) { - // postsAdapter.isSelecting = false; - postsAdapter.notifyDataSetChanged(); - } - mainActivity.mainBinding.profileView.appBarLayout.setExpanded(true, true); - mainActivity.mainBinding.profileView.privatePage.setVisibility(View.GONE); - mainActivity.mainBinding.profileView.privatePage2.setTextSize(28); - // mainActivity.mainBinding.profileView.mainProfileImage.setImageBitmap(null); - // mainActivity.mainBinding.profileView.mainHashtagImage.setImageBitmap(null); - // mainActivity.mainBinding.profileView.mainLocationImage.setImageBitmap(null); - mainActivity.mainBinding.profileView.mainUrl.setText(null); - mainActivity.mainBinding.profileView.locationUrl.setText(null); - mainActivity.mainBinding.profileView.mainFullName.setText(null); - mainActivity.mainBinding.profileView.locationFullName.setText(null); - mainActivity.mainBinding.profileView.mainPostCount.setText(null); - mainActivity.mainBinding.profileView.mainLocPostCount.setText(null); - mainActivity.mainBinding.profileView.mainTagPostCount.setText(null); - mainActivity.mainBinding.profileView.mainFollowers.setText(null); - mainActivity.mainBinding.profileView.mainFollowing.setText(null); - mainActivity.mainBinding.profileView.mainBiography.setText(null); - mainActivity.mainBinding.profileView.locationBiography.setText(null); - mainActivity.mainBinding.profileView.mainBiography.setEnabled(false); - mainActivity.mainBinding.profileView.locationBiography.setEnabled(false); - mainActivity.mainBinding.profileView.mainProfileImage.setEnabled(false); - mainActivity.mainBinding.profileView.mainLocationImage.setEnabled(false); - mainActivity.mainBinding.profileView.mainHashtagImage.setEnabled(false); - mainActivity.mainBinding.profileView.mainBiography.setMentionClickListener(null); - mainActivity.mainBinding.profileView.locationBiography.setMentionClickListener(null); - mainActivity.mainBinding.profileView.mainUrl.setVisibility(View.GONE); - mainActivity.mainBinding.profileView.locationUrl.setVisibility(View.GONE); - mainActivity.mainBinding.profileView.isVerified.setVisibility(View.GONE); - mainActivity.mainBinding.profileView.btnFollow.setVisibility(View.GONE); - mainActivity.mainBinding.profileView.btnRestrict.setVisibility(View.GONE); - mainActivity.mainBinding.profileView.btnBlock.setVisibility(View.GONE); - mainActivity.mainBinding.profileView.btnSaved.setVisibility(View.GONE); - mainActivity.mainBinding.profileView.btnLiked.setVisibility(View.GONE); - mainActivity.mainBinding.profileView.btnTagged.setVisibility(View.GONE); - mainActivity.mainBinding.profileView.btnMap.setVisibility(View.GONE); - - mainActivity.mainBinding.profileView.btnFollow.setOnClickListener(profileActionListener); - mainActivity.mainBinding.profileView.btnRestrict.setOnClickListener(profileActionListener); - mainActivity.mainBinding.profileView.btnBlock.setOnClickListener(profileActionListener); - mainActivity.mainBinding.profileView.btnSaved.setOnClickListener(profileActionListener); - mainActivity.mainBinding.profileView.btnLiked.setOnClickListener(profileActionListener); - mainActivity.mainBinding.profileView.btnTagged.setOnClickListener(profileActionListener); - mainActivity.mainBinding.profileView.btnFollowTag.setOnClickListener(profileActionListener); - - mainActivity.mainBinding.profileView.infoContainer.setVisibility(View.GONE); - mainActivity.mainBinding.profileView.tagInfoContainer.setVisibility(View.GONE); - mainActivity.mainBinding.profileView.locInfoContainer.setVisibility(View.GONE); - - mainActivity.mainBinding.profileView.mainPosts.setNestedScrollingEnabled(false); - mainActivity.mainBinding.profileView.highlightsList.setVisibility(View.GONE); - collapsingToolbar.setVisibility(View.GONE); - mainActivity.highlightsAdapter.setData(null); - - mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(mainActivity.userQuery != null); - if (mainActivity.userQuery == null) { - mainActivity.mainBinding.toolbar.toolbar.setTitle(R.string.app_name); - return; - } - - isHashtag = mainActivity.userQuery.charAt(0) == '#'; - final boolean isUser = mainActivity.userQuery.charAt(0) == '@'; - isLocation = mainActivity.userQuery.contains("/"); - collapsingToolbar.setVisibility(isUser ? View.VISIBLE : View.GONE); - - if (isHashtag) { - mainActivity.profileModel = null; - mainActivity.locationModel = null; - mainActivity.mainBinding.toolbar.toolbar.setTitle(mainActivity.userQuery); - mainActivity.mainBinding.profileView.tagInfoContainer.setVisibility(View.VISIBLE); - mainActivity.mainBinding.profileView.btnFollowTag.setVisibility(View.GONE); - - currentlyExecuting = new HashtagFetcher(mainActivity.userQuery.substring(1), hashtagModel -> { - mainActivity.hashtagModel = hashtagModel; - - if (hashtagModel == null) { - mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(false); - Toast.makeText(mainActivity, R.string.error_loading_profile, Toast.LENGTH_SHORT).show(); - mainActivity.mainBinding.toolbar.toolbar.setTitle(R.string.app_name); - return; - } - - currentlyExecuting = new PostsFetcher(mainActivity.userQuery, PostItemType.HASHTAG, null, postsFetchListener) - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - - mainActivity.mainBinding.profileView.btnFollowTag.setVisibility(View.VISIBLE); - - if (isLoggedIn) { - new iStoryStatusFetcher(hashtagModel.getName(), null, false, true, false, false, result -> { - mainActivity.storyModels = result; - if (result != null && result.length > 0) - mainActivity.mainBinding.profileView.mainHashtagImage.setStoriesBorder(); - }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - - if (hashtagModel.getFollowing()) { - mainActivity.mainBinding.profileView.btnFollowTag.setText(R.string.unfollow); - mainActivity.mainBinding.profileView.btnFollowTag.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - mainActivity, R.color.btn_purple_background))); - } else { - mainActivity.mainBinding.profileView.btnFollowTag.setText(R.string.follow); - mainActivity.mainBinding.profileView.btnFollowTag.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - mainActivity, R.color.btn_pink_background))); - } - } else { - if (Utils.dataBox.getFavorite(mainActivity.userQuery) != null) { - mainActivity.mainBinding.profileView.btnFollowTag.setText(R.string.unfavorite_short); - mainActivity.mainBinding.profileView.btnFollowTag.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - mainActivity, R.color.btn_purple_background))); - } else { - mainActivity.mainBinding.profileView.btnFollowTag.setText(R.string.favorite_short); - mainActivity.mainBinding.profileView.btnFollowTag.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - mainActivity, R.color.btn_pink_background))); - } - } - - mainActivity.mainBinding.profileView.mainHashtagImage.setEnabled(false); - // new MyTask().execute(); - mainActivity.mainBinding.profileView.mainHashtagImage.setImageURI(hashtagModel.getSdProfilePic()); - mainActivity.mainBinding.profileView.mainHashtagImage.setEnabled(true); - - final String postCount = String.valueOf(hashtagModel.getPostCount()); - - SpannableStringBuilder span = new SpannableStringBuilder(resources.getString(R.string.main_posts_count, postCount)); - span.setSpan(new RelativeSizeSpan(1.2f), 0, postCount.length(), 0); - span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0); - mainActivity.mainBinding.profileView.mainTagPostCount.setText(span); - mainActivity.mainBinding.profileView.mainTagPostCount.setVisibility(View.VISIBLE); - }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else if (isUser) { - mainActivity.hashtagModel = null; - mainActivity.locationModel = null; - mainActivity.mainBinding.toolbar.toolbar.setTitle(mainActivity.userQuery); - mainActivity.mainBinding.profileView.infoContainer.setVisibility(View.VISIBLE); - mainActivity.mainBinding.profileView.btnFollowTag.setVisibility(View.GONE); - - currentlyExecuting = new ProfileFetcher(mainActivity.userQuery.substring(1), profileModel -> { - mainActivity.profileModel = profileModel; - - if (profileModel == null) { - mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(false); - Toast.makeText(mainActivity, R.string.error_loading_profile, Toast.LENGTH_SHORT).show(); - mainActivity.mainBinding.toolbar.toolbar.setTitle(R.string.app_name); - return; - } - - mainActivity.mainBinding.profileView.isVerified.setVisibility(profileModel.isVerified() ? View.VISIBLE : View.GONE); - final String profileId = profileModel.getId(); - - if (isLoggedIn || settingsHelper.getBoolean(Constants.STORIESIG)) { - new iStoryStatusFetcher(profileId, profileModel.getUsername(), false, false, - (!isLoggedIn && settingsHelper.getBoolean(Constants.STORIESIG)), false, - result -> { - mainActivity.storyModels = result; - if (result != null && result.length > 0) - mainActivity.mainBinding.profileView.mainProfileImage.setStoriesBorder(); - }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - - new HighlightsFetcher(profileId, (!isLoggedIn && settingsHelper.getBoolean(Constants.STORIESIG)), result -> { - if (result != null && result.length > 0) { - mainActivity.mainBinding.profileView.highlightsList.setVisibility(View.VISIBLE); - mainActivity.highlightsAdapter.setData(result); - } else - mainActivity.mainBinding.profileView.highlightsList.setVisibility(View.GONE); - }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - if (isLoggedIn) { - final String myId = Utils.getUserIdFromCookie(cookie); - if (!profileId.equals(myId)) { - mainActivity.mainBinding.profileView.btnTagged.setVisibility(View.GONE); - mainActivity.mainBinding.profileView.btnSaved.setVisibility(View.GONE); - mainActivity.mainBinding.profileView.btnLiked.setVisibility(View.GONE); - mainActivity.mainBinding.profileView.btnFollow.setVisibility(View.VISIBLE); - if (profileModel.getFollowing() == true) { - mainActivity.mainBinding.profileView.btnFollow.setText(R.string.unfollow); - mainActivity.mainBinding.profileView.btnFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - mainActivity, R.color.btn_purple_background))); - } else if (profileModel.getRequested() == true) { - mainActivity.mainBinding.profileView.btnFollow.setText(R.string.cancel); - mainActivity.mainBinding.profileView.btnFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - mainActivity, R.color.btn_purple_background))); - } else { - mainActivity.mainBinding.profileView.btnFollow.setText(R.string.follow); - mainActivity.mainBinding.profileView.btnFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - mainActivity, R.color.btn_pink_background))); - } - mainActivity.mainBinding.profileView.btnRestrict.setVisibility(View.VISIBLE); - if (profileModel.getRestricted() == true) { - mainActivity.mainBinding.profileView.btnRestrict.setText(R.string.unrestrict); - mainActivity.mainBinding.profileView.btnRestrict.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - mainActivity, R.color.btn_green_background))); - } else { - mainActivity.mainBinding.profileView.btnRestrict.setText(R.string.restrict); - mainActivity.mainBinding.profileView.btnRestrict.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - mainActivity, R.color.btn_orange_background))); - } - if (profileModel.isReallyPrivate()) { - mainActivity.mainBinding.profileView.btnBlock.setVisibility(View.VISIBLE); - mainActivity.mainBinding.profileView.btnTagged.setVisibility(View.GONE); - if (profileModel.getBlocked() == true) { - mainActivity.mainBinding.profileView.btnBlock.setText(R.string.unblock); - mainActivity.mainBinding.profileView.btnBlock.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - mainActivity, R.color.btn_green_background))); - } else { - mainActivity.mainBinding.profileView.btnBlock.setText(R.string.block); - mainActivity.mainBinding.profileView.btnBlock.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - mainActivity, R.color.btn_red_background))); - } - } else { - mainActivity.mainBinding.profileView.btnBlock.setVisibility(View.GONE); - mainActivity.mainBinding.profileView.btnSaved.setVisibility(View.VISIBLE); - mainActivity.mainBinding.profileView.btnTagged.setVisibility(View.VISIBLE); - if (profileModel.getBlocked() == true) { - mainActivity.mainBinding.profileView.btnSaved.setText(R.string.unblock); - mainActivity.mainBinding.profileView.btnSaved.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - mainActivity, R.color.btn_green_background))); - } else { - mainActivity.mainBinding.profileView.btnSaved.setText(R.string.block); - mainActivity.mainBinding.profileView.btnSaved.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - mainActivity, R.color.btn_red_background))); - } - } - } else { - mainActivity.mainBinding.profileView.btnTagged.setVisibility(View.VISIBLE); - mainActivity.mainBinding.profileView.btnSaved.setVisibility(View.VISIBLE); - mainActivity.mainBinding.profileView.btnLiked.setVisibility(View.VISIBLE); - mainActivity.mainBinding.profileView.btnSaved.setText(R.string.saved); - mainActivity.mainBinding.profileView.btnSaved.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - mainActivity, R.color.btn_orange_background))); - } - } else { - if (Utils.dataBox.getFavorite(mainActivity.userQuery) != null) { - mainActivity.mainBinding.profileView.btnFollow.setText(R.string.unfavorite_short); - mainActivity.mainBinding.profileView.btnFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - mainActivity, R.color.btn_purple_background))); - } else { - mainActivity.mainBinding.profileView.btnFollow.setText(R.string.favorite_short); - mainActivity.mainBinding.profileView.btnFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - mainActivity, R.color.btn_pink_background))); - } - mainActivity.mainBinding.profileView.btnFollow.setVisibility(View.VISIBLE); - if (!profileModel.isReallyPrivate()) { - mainActivity.mainBinding.profileView.btnRestrict.setVisibility(View.VISIBLE); - mainActivity.mainBinding.profileView.btnRestrict.setText(R.string.tagged); - mainActivity.mainBinding.profileView.btnRestrict.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - mainActivity, R.color.btn_blue_background))); - } - } - - // mainActivity.mainBinding.profileView.mainProfileImage.setEnabled(false); - // new MyTask().execute(); - mainActivity.mainBinding.profileView.mainProfileImage.setImageURI(profileModel.getSdProfilePic()); - // mainActivity.mainBinding.profileView.mainProfileImage.setEnabled(true); - - final long followersCount = profileModel.getFollowersCount(); - final long followingCount = profileModel.getFollowingCount(); - - final String postCount = String.valueOf(profileModel.getPostCount()); - - SpannableStringBuilder span = new SpannableStringBuilder(resources.getString(R.string.main_posts_count, postCount)); - span.setSpan(new RelativeSizeSpan(1.2f), 0, postCount.length(), 0); - span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0); - mainActivity.mainBinding.profileView.mainPostCount.setText(span); - - final String followersCountStr = String.valueOf(followersCount); - final int followersCountStrLen = followersCountStr.length(); - span = new SpannableStringBuilder(resources.getString(R.string.main_posts_followers, followersCountStr)); - span.setSpan(new RelativeSizeSpan(1.2f), 0, followersCountStrLen, 0); - span.setSpan(new StyleSpan(Typeface.BOLD), 0, followersCountStrLen, 0); - mainActivity.mainBinding.profileView.mainFollowers.setText(span); - - final String followingCountStr = String.valueOf(followingCount); - final int followingCountStrLen = followingCountStr.length(); - span = new SpannableStringBuilder(resources.getString(R.string.main_posts_following, followingCountStr)); - span.setSpan(new RelativeSizeSpan(1.2f), 0, followingCountStrLen, 0); - span.setSpan(new StyleSpan(Typeface.BOLD), 0, followingCountStrLen, 0); - mainActivity.mainBinding.profileView.mainFollowing.setText(span); - - mainActivity.mainBinding.profileView.mainFullName - .setText(Utils.isEmpty(profileModel.getName()) ? profileModel.getUsername() : profileModel.getName()); - - CharSequence biography = profileModel.getBiography(); - mainActivity.mainBinding.profileView.mainBiography.setCaptionIsExpandable(true); - mainActivity.mainBinding.profileView.mainBiography.setCaptionIsExpanded(true); - if (Utils.hasMentions(biography)) { - biography = Utils.getMentionText(biography); - mainActivity.mainBinding.profileView.mainBiography.setText(biography, TextView.BufferType.SPANNABLE); - mainActivity.mainBinding.profileView.mainBiography.setMentionClickListener(mentionClickListener); - } else { - mainActivity.mainBinding.profileView.mainBiography.setText(biography); - mainActivity.mainBinding.profileView.mainBiography.setMentionClickListener(null); - } - - final String url = profileModel.getUrl(); - if (Utils.isEmpty(url)) { - mainActivity.mainBinding.profileView.mainUrl.setVisibility(View.GONE); - } else { - mainActivity.mainBinding.profileView.mainUrl.setVisibility(View.VISIBLE); - mainActivity.mainBinding.profileView.mainUrl.setText(Utils.getSpannableUrl(url)); - } - - mainActivity.mainBinding.profileView.mainFullName.setSelected(true); - mainActivity.mainBinding.profileView.mainBiography.setEnabled(true); - - if (!profileModel.isReallyPrivate()) { - mainActivity.mainBinding.profileView.mainFollowing.setClickable(true); - mainActivity.mainBinding.profileView.mainFollowers.setClickable(true); - - if (isLoggedIn) { - // final View.OnClickListener followClickListener = v -> mainActivity.startActivity(new Intent(mainActivity, FollowViewerFragment.class) - // .putExtra(Constants.EXTRAS_FOLLOWERS, - // v == mainActivity.mainBinding.profileView.mainFollowers) - // .putExtra(Constants.EXTRAS_NAME, - // profileModel.getUsername()) - // .putExtra(Constants.EXTRAS_ID, - // profileId)); - // - // mainActivity.mainBinding.profileView.mainFollowers.setOnClickListener(followersCount > 0 ? followClickListener : null); - // mainActivity.mainBinding.profileView.mainFollowing.setOnClickListener(followingCount > 0 ? followClickListener : null); - } - - if (profileModel.getPostCount() == 0) { - mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(false); - mainActivity.mainBinding.profileView.privatePage1.setImageResource(R.drawable.ic_cancel); - mainActivity.mainBinding.profileView.privatePage2.setText(R.string.empty_acc); - mainActivity.mainBinding.profileView.privatePage.setVisibility(View.VISIBLE); - } else { - mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(true); - mainActivity.mainBinding.profileView.mainPosts.setVisibility(View.VISIBLE); - currentlyExecuting = new PostsFetcher(profileId, PostItemType.MAIN, null, postsFetchListener) - .setUsername(profileModel.getUsername()) - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - } else { - mainActivity.mainBinding.profileView.mainFollowers.setClickable(false); - mainActivity.mainBinding.profileView.mainFollowing.setClickable(false); - mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(false); - // error - mainActivity.mainBinding.profileView.privatePage1.setImageResource(R.drawable.lock); - mainActivity.mainBinding.profileView.privatePage2.setText(R.string.priv_acc); - mainActivity.mainBinding.profileView.privatePage.setVisibility(View.VISIBLE); - mainActivity.mainBinding.profileView.mainPosts.setVisibility(View.GONE); - } - } - ).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else if (isLocation) { - mainActivity.profileModel = null; - mainActivity.hashtagModel = null; - mainActivity.mainBinding.toolbar.toolbar.setTitle(mainActivity.userQuery); - mainActivity.mainBinding.profileView.locInfoContainer.setVisibility(View.VISIBLE); - - currentlyExecuting = new LocationFetcher(mainActivity.userQuery.split("/")[0], locationModel -> { - mainActivity.locationModel = locationModel; - - if (locationModel == null) { - mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(false); - Toast.makeText(mainActivity, R.string.error_loading_profile, Toast.LENGTH_SHORT).show(); - mainActivity.mainBinding.toolbar.toolbar.setTitle(R.string.app_name); - return; - } - mainActivity.mainBinding.toolbar.toolbar.setTitle(locationModel.getName()); - - final String profileId = locationModel.getId(); - - if (isLoggedIn) { - new iStoryStatusFetcher(profileId.split("/")[0], null, true, false, false, false, result -> { - mainActivity.storyModels = result; - if (result != null && result.length > 0) - mainActivity.mainBinding.profileView.mainLocationImage.setStoriesBorder(); - }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - // mainActivity.mainBinding.profileView.mainLocationImage.setEnabled(false); - // new MyTask().execute(); - mainActivity.mainBinding.profileView.mainLocationImage.setImageURI(locationModel.getSdProfilePic()); - // mainActivity.mainBinding.profileView.mainLocationImage.setEnabled(true); - - final String postCount = String.valueOf(locationModel.getPostCount()); - - SpannableStringBuilder span = new SpannableStringBuilder(resources.getString(R.string.main_posts_count, postCount)); - span.setSpan(new RelativeSizeSpan(1.2f), 0, postCount.length(), 0); - span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0); - mainActivity.mainBinding.profileView.mainLocPostCount.setText(span); - - mainActivity.mainBinding.profileView.locationFullName.setText(locationModel.getName()); - - CharSequence biography = locationModel.getBio(); - mainActivity.mainBinding.profileView.locationBiography.setCaptionIsExpandable(true); - mainActivity.mainBinding.profileView.locationBiography.setCaptionIsExpanded(true); - - if (Utils.isEmpty(biography)) { - mainActivity.mainBinding.profileView.locationBiography.setVisibility(View.GONE); - } else if (Utils.hasMentions(biography)) { - mainActivity.mainBinding.profileView.locationBiography.setVisibility(View.VISIBLE); - biography = Utils.getMentionText(biography); - mainActivity.mainBinding.profileView.locationBiography.setText(biography, TextView.BufferType.SPANNABLE); - mainActivity.mainBinding.profileView.locationBiography.setMentionClickListener(mentionClickListener); - } else { - mainActivity.mainBinding.profileView.locationBiography.setVisibility(View.VISIBLE); - mainActivity.mainBinding.profileView.locationBiography.setText(biography); - mainActivity.mainBinding.profileView.locationBiography.setMentionClickListener(null); - } - - if (!locationModel.getGeo().startsWith("geo:0.0,0.0?z=17")) { - mainActivity.mainBinding.profileView.btnMap.setVisibility(View.VISIBLE); - mainActivity.mainBinding.profileView.btnMap.setOnClickListener(v -> { - final Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(locationModel.getGeo())); - mainActivity.startActivity(intent); - }); - } else { - mainActivity.mainBinding.profileView.btnMap.setVisibility(View.GONE); - mainActivity.mainBinding.profileView.btnMap.setOnClickListener(null); - } - - final String url = locationModel.getUrl(); - if (Utils.isEmpty(url)) { - mainActivity.mainBinding.profileView.locationUrl.setVisibility(View.GONE); - } else if (!url.startsWith("http")) { - mainActivity.mainBinding.profileView.locationUrl.setVisibility(View.VISIBLE); - mainActivity.mainBinding.profileView.locationUrl.setText(Utils.getSpannableUrl("http://" + url)); - } else { - mainActivity.mainBinding.profileView.locationUrl.setVisibility(View.VISIBLE); - mainActivity.mainBinding.profileView.locationUrl.setText(Utils.getSpannableUrl(url)); - } - - mainActivity.mainBinding.profileView.locationFullName.setSelected(true); - mainActivity.mainBinding.profileView.locationBiography.setEnabled(true); - - if (locationModel.getPostCount() == 0) { - mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(false); - mainActivity.mainBinding.profileView.privatePage1.setImageResource(R.drawable.ic_cancel); - mainActivity.mainBinding.profileView.privatePage2.setText(R.string.empty_acc); - mainActivity.mainBinding.profileView.privatePage.setVisibility(View.VISIBLE); - } else { - mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(true); - mainActivity.mainBinding.profileView.mainPosts.setVisibility(View.VISIBLE); - currentlyExecuting = new PostsFetcher(profileId, PostItemType.LOCATION, null, postsFetchListener) - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - } - ).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - } - - public static void stopCurrentExecutor() { - if (currentlyExecuting != null) { - try { - currentlyExecuting.cancel(true); - } catch (final Exception e) { - if (logCollector != null) - logCollector.appendException(e, LogCollector.LogFile.MAIN_HELPER, "stopCurrentExecutor"); - if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e); - } - } - } - - private void toggleSelection(final PostModel postModel) { - if (postModel != null && postsAdapter != null && mainActivity.selectedItems.size() >= 100) { - Toast.makeText(mainActivity, R.string.downloader_too_many, Toast.LENGTH_SHORT); - } else if (postModel != null && postsAdapter != null) { - if (postModel.isSelected()) mainActivity.selectedItems.remove(postModel); - else if (mainActivity.selectedItems.size() >= 100) { - Toast.makeText(mainActivity, R.string.downloader_too_many, Toast.LENGTH_SHORT); - return; - } else mainActivity.selectedItems.add(postModel); - postModel.setSelected(!postModel.isSelected()); - notifyAdapter(postModel); - } - } - - private void notifyAdapter(final PostModel postModel) { - // if (mainActivity.selectedItems.size() < 1) postsAdapter.isSelecting = false; - // if (postModel.getPosition() < 0) postsAdapter.notifyDataSetChanged(); - // else postsAdapter.notifyItemChanged(postModel.getPosition(), postModel); - // - // if (mainActivity.downloadAction != null) - // mainActivity.downloadAction.setVisible(postsAdapter.isSelecting); - } - - private void toggleDiscoverSelection(final DiscoverItemModel itemModel) { - if (itemModel != null && discoverAdapter != null) { - if (itemModel.isSelected()) mainActivity.selectedDiscoverItems.remove(itemModel); - else mainActivity.selectedDiscoverItems.add(itemModel); - itemModel.setSelected(!itemModel.isSelected()); - notifyDiscoverAdapter(itemModel); - } - } - - private void notifyDiscoverAdapter(final DiscoverItemModel itemModel) { - // if (mainActivity.selectedDiscoverItems.size() < 1) discoverAdapter.isSelecting = false; - // if (itemModel.getPosition() < 0) discoverAdapter.notifyDataSetChanged(); - // else discoverAdapter.notifyItemChanged(itemModel.getPosition(), itemModel); - // - // if (mainActivity.downloadAction != null) - // mainActivity.downloadAction.setVisible(discoverAdapter.isSelecting); - } - - public boolean isSelectionCleared() { - // if (postsAdapter != null && postsAdapter.isSelecting()) { - // for (final PostModel postModel : mainActivity.selectedItems) - // postModel.setSelected(false); - // mainActivity.selectedItems.clear(); - // // postsAdapter.isSelecting = false; - // postsAdapter.notifyDataSetChanged(); - // if (mainActivity.downloadAction != null) mainActivity.downloadAction.setVisible(false); - // return false; - // } else if (discoverAdapter != null && discoverAdapter.isSelecting) { - // for (final DiscoverItemModel itemModel : mainActivity.selectedDiscoverItems) - // itemModel.setSelected(false); - // mainActivity.selectedDiscoverItems.clear(); - // discoverAdapter.isSelecting = false; - // discoverAdapter.notifyDataSetChanged(); - // if (mainActivity.downloadAction != null) mainActivity.downloadAction.setVisible(false); - // return false; - // } - // return true; - return false; - } - - public void deselectSelection(final BasePostModel postModel) { - if (postModel instanceof PostModel) { - mainActivity.selectedItems.remove(postModel); - postModel.setSelected(false); - if (postsAdapter != null) notifyAdapter((PostModel) postModel); - } else if (postModel instanceof DiscoverItemModel) { - mainActivity.selectedDiscoverItems.remove(postModel); - postModel.setSelected(false); - if (discoverAdapter != null) notifyDiscoverAdapter((DiscoverItemModel) postModel); - } - } - - public void onPause() { - if (videoAwareRecyclerScroller != null) { - videoAwareRecyclerScroller.stopPlaying(); - } - } - - public void onResume() { - if (videoAwareRecyclerScroller != null && SHOULD_AUTO_PLAY) { - videoAwareRecyclerScroller.startPlaying(); - } - } - - public static int indexOfIntArray(Object[] array, Object key) { - int returnvalue = -1; - for (int i = 0; i < array.length; ++i) { - if (key == array[i]) { - returnvalue = i; - break; - } - } - return returnvalue; - } - - private final View.OnClickListener profileActionListener = new View.OnClickListener() { - @Override - public void onClick(final View v) { - final String userIdFromCookie = Utils.getUserIdFromCookie(MainHelper.this.cookie); - final boolean isSelf = (isLoggedIn && mainActivity.profileModel != null) && userIdFromCookie != null && userIdFromCookie - .equals(mainActivity.profileModel.getId()); - if (!isLoggedIn - && Utils.dataBox.getFavorite(mainActivity.userQuery) != null - && v == mainActivity.mainBinding.profileView.btnFollow) { - Utils.dataBox.delFavorite(new DataBox.FavoriteModel(mainActivity.userQuery, - Long.parseLong(Utils.dataBox.getFavorite(mainActivity.userQuery).split("/")[1]), - mainActivity.locationModel != null - ? mainActivity.locationModel.getName() - : mainActivity.userQuery.replaceAll("^@", ""))); - onRefresh(); - } else if (!isLoggedIn - && (v == mainActivity.mainBinding.profileView.btnFollow || v == mainActivity.mainBinding.profileView.btnFollowTag)) { - Utils.dataBox.addFavorite(new DataBox.FavoriteModel(mainActivity.userQuery, System.currentTimeMillis(), - mainActivity.locationModel != null - ? mainActivity.locationModel.getName() - : mainActivity.userQuery.replaceAll("^@", ""))); - onRefresh(); - } else if (v == mainActivity.mainBinding.profileView.btnFollow) { - if (mainActivity.profileModel.isPrivate() && mainActivity.profileModel.getFollowing()) { - new AlertDialog.Builder(mainActivity) - .setTitle(R.string.priv_acc) - .setMessage(R.string.priv_acc_confirm) - .setNegativeButton(R.string.no, null) - .setPositiveButton(R.string.yes, (dialog, which) -> new ProfileAction().execute("follow")) - .show(); - } else new ProfileAction().execute("follow"); - } else if (v == mainActivity.mainBinding.profileView.btnRestrict && isLoggedIn) { - new ProfileAction().execute("restrict"); - } else if (v == mainActivity.mainBinding.profileView.btnSaved && !isSelf) { - new ProfileAction().execute("block"); - } else if (v == mainActivity.mainBinding.profileView.btnFollowTag) { - new ProfileAction().execute("followtag"); - } else if (v == mainActivity.mainBinding.profileView.btnTagged || v == mainActivity.mainBinding.profileView.btnRestrict) { - mainActivity.startActivity(new Intent(mainActivity, SavedViewerFragment.class) - .putExtra(Constants.EXTRAS_INDEX, "%" + mainActivity.profileModel.getId()) - .putExtra(Constants.EXTRAS_USER, "@" + mainActivity.profileModel.getUsername()) - ); - } else if (v == mainActivity.mainBinding.profileView.btnSaved) { - mainActivity.startActivity(new Intent(mainActivity, SavedViewerFragment.class) - .putExtra(Constants.EXTRAS_INDEX, "$" + mainActivity.profileModel.getId()) - .putExtra(Constants.EXTRAS_USER, "@" + mainActivity.profileModel.getUsername()) - ); - } else if (v == mainActivity.mainBinding.profileView.btnLiked) { - mainActivity.startActivity(new Intent(mainActivity, SavedViewerFragment.class) - .putExtra(Constants.EXTRAS_INDEX, "^" + mainActivity.profileModel.getId()) - .putExtra(Constants.EXTRAS_USER, "@" + mainActivity.profileModel.getUsername()) - ); - } - } - }; - - class ProfileAction extends AsyncTask { - boolean ok = false; - String action; - - protected Void doInBackground(String... rawAction) { - action = rawAction[0]; - final String url = "https://www.instagram.com/web/" + (action.equals("followtag") && mainActivity.hashtagModel != null - ? "tags/" + (mainActivity.hashtagModel.getFollowing() - ? "unfollow/" - : "follow/") + mainActivity.hashtagModel.getName() + "/" - : (action.equals("restrict") && mainActivity.profileModel != null - ? "restrict_action" - : "friendships/" + mainActivity.profileModel.getId()) + "/" + (action.equals( - "follow") ? - mainActivity.profileModel - .getFollowing() || mainActivity.profileModel - .getRequested() - ? "unfollow/" - : "follow/" : - action.equals( - "restrict") - ? - mainActivity.profileModel - .getRestricted() - ? "unrestrict/" - : "restrict/" - : - mainActivity.profileModel - .getBlocked() - ? "unblock/" - : "block/")); - try { - final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); - urlConnection.setRequestMethod("POST"); - urlConnection.setUseCaches(false); - urlConnection.setRequestProperty("User-Agent", Constants.USER_AGENT); - urlConnection.setRequestProperty("x-csrftoken", cookie.split("csrftoken=")[1].split(";")[0]); - if (action == "restrict") { - final String urlParameters = "target_user_id=" + mainActivity.profileModel.getId(); - urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - urlConnection.setRequestProperty("Content-Length", "" + - urlParameters.getBytes().length); - urlConnection.setDoOutput(true); - DataOutputStream wr = new DataOutputStream(urlConnection.getOutputStream()); - wr.writeBytes(urlParameters); - wr.flush(); - wr.close(); - } else urlConnection.connect(); - if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { - ok = true; - } else - Toast.makeText(mainActivity, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); - urlConnection.disconnect(); - } catch (Throwable ex) { - Log.e("austin_debug", action + ": " + ex); - } - return null; - } - - @Override - protected void onPostExecute(Void result) { - if (ok == true) { - onRefresh(); - } - } - } -} +// package awais.instagrabber; +// +// import android.content.Context; +// import android.content.DialogInterface; +// import android.content.Intent; +// import android.content.res.ColorStateList; +// import android.content.res.Resources; +// import android.graphics.Typeface; +// import android.net.Uri; +// import android.os.AsyncTask; +// import android.os.Bundle; +// import android.text.SpannableStringBuilder; +// import android.text.method.LinkMovementMethod; +// import android.text.style.RelativeSizeSpan; +// import android.text.style.StyleSpan; +// import android.util.Log; +// import android.util.TypedValue; +// import android.view.View; +// import android.view.ViewGroup; +// import android.widget.AdapterView; +// import android.widget.ArrayAdapter; +// import android.widget.ImageView; +// import android.widget.LinearLayout; +// import android.widget.TextView; +// import android.widget.Toast; +// +// import androidx.annotation.NonNull; +// import androidx.appcompat.app.AlertDialog; +// import androidx.core.content.ContextCompat; +// import androidx.core.view.GravityCompat; +// import androidx.core.widget.ImageViewCompat; +// import androidx.recyclerview.widget.LinearLayoutManager; +// import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +// +// import com.bumptech.glide.Glide; +// import com.bumptech.glide.RequestManager; +// import com.facebook.common.executors.UiThreadImmediateExecutorService; +// import com.facebook.datasource.BaseDataSubscriber; +// import com.facebook.datasource.DataSource; +// import com.facebook.drawee.backends.pipeline.Fresco; +// import com.facebook.imagepipeline.request.ImageRequest; +// +// import java.io.DataOutputStream; +// import java.net.HttpURLConnection; +// import java.net.URL; +// import java.util.ArrayList; +// import java.util.Arrays; +// import java.util.Collections; +// import java.util.HashMap; +// import java.util.Map; +// +// import awais.instagrabber.activities.CommentsViewerFragment; +// import awais.instagrabber.activities.MainActivityBackup; +// import awais.instagrabber.activities.PostViewer; +// import awais.instagrabber.adapters.DiscoverAdapter; +// import awais.instagrabber.adapters.FeedAdapter; +// import awais.instagrabber.adapters.PostsAdapter; +// import awais.instagrabber.adapters.viewholder.feed.FeedItemViewHolder; +// import awais.instagrabber.asyncs.DiscoverFetcher; +// import awais.instagrabber.asyncs.FeedFetcher; +// import awais.instagrabber.asyncs.FeedStoriesFetcher; +// import awais.instagrabber.asyncs.HashtagFetcher; +// import awais.instagrabber.asyncs.HighlightsFetcher; +// import awais.instagrabber.asyncs.LocationFetcher; +// import awais.instagrabber.asyncs.PostsFetcher; +// import awais.instagrabber.asyncs.ProfileFetcher; +// import awais.instagrabber.asyncs.i.iStoryStatusFetcher; +// import awais.instagrabber.asyncs.i.iTopicFetcher; +// import awais.instagrabber.customviews.MouseDrawer; +// import awais.instagrabber.customviews.RamboTextView; +// import awais.instagrabber.customviews.helpers.GridAutofitLayoutManager; +// import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration; +// import awais.instagrabber.customviews.helpers.PauseGlideOnFlingScrollListener; +// import awais.instagrabber.customviews.helpers.RecyclerLazyLoader; +// import awais.instagrabber.customviews.helpers.VideoAwareRecyclerScroller; +// import awais.instagrabber.fragments.SavedViewerFragment; +// import awais.instagrabber.interfaces.FetchListener; +// import awais.instagrabber.interfaces.MentionClickListener; +// import awais.instagrabber.models.BasePostModel; +// import awais.instagrabber.models.DiscoverItemModel; +// import awais.instagrabber.models.DiscoverTopicModel; +// import awais.instagrabber.models.FeedModel; +// import awais.instagrabber.models.FeedStoryModel; +// import awais.instagrabber.models.IntentModel; +// import awais.instagrabber.models.PostModel; +// import awais.instagrabber.models.ProfileModel; +// import awais.instagrabber.models.ViewerPostModel; +// import awais.instagrabber.models.enums.DownloadMethod; +// import awais.instagrabber.models.enums.IntentModelType; +// import awais.instagrabber.models.enums.MediaItemType; +// import awais.instagrabber.models.enums.PostItemType; +// import awais.instagrabber.utils.Constants; +// import awais.instagrabber.utils.DataBox; +// import awais.instagrabber.utils.Utils; +// import awaisomereport.LogCollector; +// +// import static awais.instagrabber.utils.Constants.AUTOLOAD_POSTS; +// import static awais.instagrabber.utils.Constants.BOTTOM_TOOLBAR; +// import static awais.instagrabber.utils.Utils.logCollector; +// import static awais.instagrabber.utils.Utils.settingsHelper; +// +// @Deprecated +// public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener { +// private static final String TAG = "MainHelper"; +// private static final double MAX_VIDEO_HEIGHT = 0.9 * Utils.displayMetrics.heightPixels; +// private static final int RESIZED_VIDEO_HEIGHT = (int) (0.8 * Utils.displayMetrics.heightPixels); +// public static final boolean SHOULD_AUTO_PLAY = settingsHelper.getBoolean(Constants.AUTOPLAY_VIDEOS); +// +// private static AsyncTask currentlyExecuting; +// private AsyncTask prevStoriesFetcher; +// private FeedStoryModel[] stories; +// private boolean hasNextPage = false; +// private boolean feedHasNextPage = false; +// private boolean discoverHasMore = false; +// private String endCursor = null; +// private String feedEndCursor = null; +// private String discoverEndMaxId = null; +// private String topic = null; +// private String rankToken = null; +// private String[] topicIds = null; +// +// private final boolean autoloadPosts; +// private final FetchListener postsFetchListener = new FetchListener() { +// @Override +// public void onResult(final PostModel[] result) { +// if (result != null) { +// final int oldSize = mainActivity.allItems.size(); +// mainActivity.allItems.addAll(Arrays.asList(result)); +// +// postsAdapter.notifyItemRangeInserted(oldSize, result.length); +// +// mainActivity.mainBinding.profileView.mainPosts.post(() -> { +// mainActivity.mainBinding.profileView.mainPosts.setNestedScrollingEnabled(true); +// mainActivity.mainBinding.profileView.mainPosts.setVisibility(View.VISIBLE); +// }); +// +// if (isHashtag) +// mainActivity.mainBinding.toolbar.toolbar.setTitle(mainActivity.userQuery); +// else if (isLocation) +// mainActivity.mainBinding.toolbar.toolbar.setTitle(mainActivity.locationModel.getName()); +// else +// mainActivity.mainBinding.toolbar.toolbar.setTitle("@" + mainActivity.profileModel.getUsername()); +// +// final PostModel model = result[result.length - 1]; +// if (model != null) { +// endCursor = model.getEndCursor(); +// hasNextPage = model.hasNextPage(); +// if (autoloadPosts && hasNextPage) +// currentlyExecuting = new PostsFetcher( +// mainActivity.profileModel != null ? mainActivity.profileModel.getId() +// : (mainActivity.hashtagModel != null +// ? mainActivity.userQuery +// : mainActivity.locationModel.getId()), +// mainActivity.profileModel != null +// ? PostItemType.MAIN +// : (mainActivity.hashtagModel != null ? PostItemType.HASHTAG : PostItemType.LOCATION), +// endCursor, +// this) +// .setUsername((isLocation || isHashtag) ? null : mainActivity.profileModel.getUsername()) +// .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// else { +// mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(false); +// } +// model.setPageCursor(false, null); +// } +// } else { +// mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(false); +// mainActivity.mainBinding.profileView.privatePage1.setImageResource(R.drawable.ic_cancel); +// mainActivity.mainBinding.profileView.privatePage2.setText(R.string.empty_acc); +// mainActivity.mainBinding.profileView.privatePage.setVisibility(View.VISIBLE); +// } +// } +// }; +// private final FetchListener feedFetchListener = new FetchListener() { +// @Override +// public void doBefore() { +// mainActivity.mainBinding.feedView.feedSwipeRefreshLayout +// .post(() -> mainActivity.mainBinding.feedView.feedSwipeRefreshLayout.setRefreshing(true)); +// } +// +// @Override +// public void onResult(final FeedModel[] result) { +// if (result == null) { +// return; +// } +// final int oldSize = mainActivity.feedItems.size(); +// final HashMap thumbToFeedMap = new HashMap<>(); +// for (final FeedModel feedModel : result) { +// thumbToFeedMap.put(feedModel.getThumbnailUrl(), feedModel); +// } +// final BaseDataSubscriber subscriber = new BaseDataSubscriber() { +// int success = 0; +// int failed = 0; +// +// @Override +// protected void onNewResultImpl(@NonNull final DataSource dataSource) { +// // dataSource +// final Map extras = dataSource.getExtras(); +// if (extras == null) { +// return; +// } +// // Log.d(TAG, "extras: " + extras); +// final Uri thumbUri = (Uri) extras.get("uri_source"); +// if (thumbUri == null) { +// return; +// } +// final Integer encodedWidth = (Integer) extras.get("encoded_width"); +// final Integer encodedHeight = (Integer) extras.get("encoded_height"); +// if (encodedWidth == null || encodedHeight == null) { +// return; +// } +// final FeedModel feedModel = thumbToFeedMap.get(thumbUri.toString()); +// if (feedModel == null) { +// return; +// } +// int requiredWidth = Utils.displayMetrics.widthPixels; +// int resultingHeight = Utils.getResultingHeight(requiredWidth, encodedHeight, encodedWidth); +// if (feedModel.getItemType() == MediaItemType.MEDIA_TYPE_VIDEO && resultingHeight >= MAX_VIDEO_HEIGHT) { +// // If its a video and the height is too large, need to reduce the height, +// // so that entire video fits on screen +// resultingHeight = RESIZED_VIDEO_HEIGHT; +// requiredWidth = Utils.getResultingWidth(RESIZED_VIDEO_HEIGHT, resultingHeight, requiredWidth); +// } +// feedModel.setImageWidth(requiredWidth); +// feedModel.setImageHeight(resultingHeight); +// success++; +// updateAdapter(); +// } +// +// @Override +// protected void onFailureImpl(@NonNull final DataSource dataSource) { +// failed++; +// updateAdapter(); +// } +// +// public void updateAdapter() { +// if (failed + success != result.length) return; +// mainActivity.feedItems.addAll(Arrays.asList(result)); +// feedAdapter.submitList(mainActivity.feedItems); +// feedAdapter.notifyItemRangeInserted(oldSize, result.length); +// +// mainActivity.mainBinding.feedView.feedPosts +// .post(() -> mainActivity.mainBinding.feedView.feedPosts.setNestedScrollingEnabled(true)); +// +// final PostModel feedPostModel = result[result.length - 1]; +// if (feedPostModel != null) { +// feedEndCursor = feedPostModel.getEndCursor(); +// feedHasNextPage = feedPostModel.hasNextPage(); +// feedPostModel.setPageCursor(false, null); +// } +// mainActivity.mainBinding.feedView.feedSwipeRefreshLayout.setRefreshing(false); +// } +// }; +// for (final FeedModel feedModel : result) { +// final DataSource ds = Fresco.getImagePipeline().prefetchToBitmapCache(ImageRequest.fromUri(feedModel.getThumbnailUrl()), null); +// ds.subscribe(subscriber, UiThreadImmediateExecutorService.getInstance()); +// } +// } +// }; +// private final FetchListener discoverFetchListener = new FetchListener() { +// @Override +// public void doBefore() { +// mainActivity.mainBinding.discoverSwipeRefreshLayout.setRefreshing(true); +// } +// +// @Override +// public void onResult(final DiscoverItemModel[] result) { +// if (result == null || result.length == 0) { +// Toast.makeText(mainActivity, R.string.discover_empty, Toast.LENGTH_SHORT).show(); +// } else { +// final int oldSize = mainActivity.discoverItems.size(); +// mainActivity.discoverItems.addAll(Arrays.asList(result)); +// discoverAdapter.notifyItemRangeInserted(oldSize, result.length); +// +// final DiscoverItemModel discoverItemModel = result[result.length - 1]; +// if (discoverItemModel != null) { +// discoverEndMaxId = discoverItemModel.getNextMaxId(); +// discoverHasMore = discoverItemModel.hasMore(); +// discoverItemModel.setMore(false, null); +// } +// } +// +// mainActivity.mainBinding.discoverSwipeRefreshLayout.setRefreshing(false); +// } +// }; +// private final FetchListener topicFetchListener = new FetchListener() { +// @Override +// public void doBefore() {} +// +// @Override +// public void onResult(final DiscoverTopicModel result) { +// if (result != null) { +// topicIds = result.getIds(); +// rankToken = result.getToken(); +// ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<>( +// mainActivity, android.R.layout.simple_spinner_dropdown_item, result.getNames()); +// mainActivity.mainBinding.discoverType.setAdapter(spinnerArrayAdapter); +// } +// } +// }; +// private final FetchListener feedStoriesListener = new FetchListener() { +// @Override +// public void doBefore() { +// mainActivity.mainBinding.feedView.feedStories.setVisibility(View.GONE); +// } +// +// @Override +// public void onResult(final FeedStoryModel[] result) { +// // feedStoriesAdapter.setData(result); +// if (result != null && result.length > 0) { +// mainActivity.mainBinding.feedView.feedStories.setVisibility(View.VISIBLE); +// stories = result; +// } +// } +// }; +// private final MentionClickListener mentionClickListener = new MentionClickListener() { +// @Override +// public void onClick(final RamboTextView view, final String text, final boolean isHashtag, final boolean isLocation) { +// new AlertDialog.Builder(mainActivity) +// .setMessage(isHashtag ? R.string.comment_view_mention_hash_search : R.string.comment_view_mention_user_search) +// .setTitle(text).setNegativeButton(R.string.cancel, null).setPositiveButton(R.string.ok, (dialog, which) -> { +// if (MainActivityBackup.scanHack != null) MainActivityBackup.scanHack.onResult(text); +// }).show(); +// } +// }; +// // private final FeedStoriesAdapter feedStoriesAdapter = new FeedStoriesAdapter(null, new View.OnClickListener() { +// // @Override +// // public void onClick(final View v) { +// // final Object tag = v.getTag(); +// // if (tag instanceof FeedStoryModel) { +// // final FeedStoryModel feedStoryModel = (FeedStoryModel) tag; +// // final int index = indexOfIntArray(stories, feedStoryModel); +// // new iStoryStatusFetcher(feedStoryModel.getStoryMediaId(), null, false, false, false, false, result -> { +// // if (result != null && result.length > 0) +// // mainActivity.startActivity(new Intent(mainActivity, StoryViewer.class) +// // .putExtra(Constants.EXTRAS_STORIES, result) +// // .putExtra(Constants.EXTRAS_USERNAME, feedStoryModel.getProfileModel().getUsername()) +// // .putExtra(Constants.FEED, stories) +// // .putExtra(Constants.FEED_ORDER, index) +// // ); +// // else +// // Toast.makeText(mainActivity, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); +// // }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// // } +// // } +// // }); +// private MainActivityBackup mainActivity; +// private Resources resources; +// private final View collapsingToolbar; +// private final RecyclerLazyLoader lazyLoader; +// private boolean isHashtag; +// private boolean isLocation; +// private PostsAdapter postsAdapter; +// private FeedAdapter feedAdapter; +// private RecyclerLazyLoader feedLazyLoader, discoverLazyLoader; +// private DiscoverAdapter discoverAdapter; +// private String cookie = settingsHelper.getString(Constants.COOKIE); +// private boolean isLoggedIn; +// private RequestManager glide; +// private VideoAwareRecyclerScroller videoAwareRecyclerScroller; +// +// public MainHelper(@NonNull final MainActivityBackup mainActivity) { +// stopCurrentExecutor(); +// +// this.mainActivity = mainActivity; +// this.resources = mainActivity.getResources(); +// this.autoloadPosts = settingsHelper.getBoolean(AUTOLOAD_POSTS); +// glide = Glide.with(mainActivity); +// +// mainActivity.mainBinding.profileView.swipeRefreshLayout.setOnRefreshListener(this); +// mainActivity.mainBinding.profileView.mainUrl.setMovementMethod(new LinkMovementMethod()); +// +// final LinearLayout iconSlider = mainActivity.findViewById(R.id.iconSlider); +// final ImageView iconFeed = (ImageView) iconSlider.getChildAt(0); +// final ImageView iconProfile = (ImageView) iconSlider.getChildAt(1); +// final ImageView iconDiscover = (ImageView) iconSlider.getChildAt(2); +// +// final boolean isBottomToolbar = settingsHelper.getBoolean(BOTTOM_TOOLBAR); +// isLoggedIn = !Utils.isEmpty(cookie) && Utils.getUserIdFromCookie(cookie) != null; +// if (!isLoggedIn) { +// mainActivity.mainBinding.drawerLayout.removeView(mainActivity.mainBinding.feedView.feedLayout); +// mainActivity.mainBinding.drawerLayout.removeView(mainActivity.mainBinding.discoverLayout); +// iconFeed.setAlpha(0.4f); +// iconDiscover.setAlpha(0.4f); +// } else { +// iconFeed.setAlpha(1f); +// iconDiscover.setAlpha(1f); +// +// setupExplore(); +// +// setupFeed(); +// +// final TypedValue resolvedAttr = new TypedValue(); +// mainActivity.getTheme().resolveAttribute(android.R.attr.textColorPrimary, resolvedAttr, true); +// +// final int selectedItem = ContextCompat.getColor(mainActivity, resolvedAttr.resourceId != 0 ? resolvedAttr.resourceId : resolvedAttr.data); +// final ColorStateList colorStateList = ColorStateList.valueOf(selectedItem); +// +// mainActivity.mainBinding.toolbar.toolbar.measure(0, -1); +// final int toolbarMeasuredHeight = mainActivity.mainBinding.toolbar.toolbar.getMeasuredHeight(); +// +// final ViewGroup.LayoutParams layoutParams = mainActivity.mainBinding.toolbar.toolbar.getLayoutParams(); +// final MouseDrawer.DrawerListener simpleDrawerListener = new MouseDrawer.DrawerListener() { +// private final String titleDiscover = resources.getString(R.string.title_discover); +// +// @Override +// public void onDrawerSlide(final View drawerView, @MouseDrawer.EdgeGravity final int gravity, final float slideOffset) { +// final int currentIconAlpha = (int) Math.max(100, 255 - 255 * slideOffset); +// final int otherIconAlpha = (int) Math.max(100, 255 * slideOffset); +// +// ImageViewCompat.setImageTintList(iconProfile, colorStateList.withAlpha(currentIconAlpha)); +// +// final boolean drawerOpening = slideOffset > 0.0f; +// final int alpha; +// final ColorStateList imageTintList; +// +// if (gravity == GravityCompat.START) { +// // this helps hide the toolbar when opening feed +// +// final int roundedToolbarHeight; +// final float toolbarHeight; +// +// if (isBottomToolbar) { +// toolbarHeight = toolbarMeasuredHeight * slideOffset; +// roundedToolbarHeight = -Math.round(toolbarHeight); +// } else { +// toolbarHeight = -toolbarMeasuredHeight * slideOffset; +// roundedToolbarHeight = Math.round(toolbarHeight); +// } +// +// layoutParams.height = Math.max(0, Math.min(toolbarMeasuredHeight, toolbarMeasuredHeight + roundedToolbarHeight)); +// mainActivity.mainBinding.toolbar.toolbar.setLayoutParams(layoutParams); +// mainActivity.mainBinding.toolbar.toolbar.setTranslationY(toolbarHeight); +// +// imageTintList = ImageViewCompat.getImageTintList(iconDiscover); +// alpha = imageTintList != null ? (imageTintList.getDefaultColor() & 0xFF_000000) >> 24 : 0; +// +// if (drawerOpening && alpha > 100) +// ImageViewCompat.setImageTintList(iconDiscover, colorStateList.withAlpha(currentIconAlpha)); +// +// ImageViewCompat.setImageTintList(iconFeed, colorStateList.withAlpha(otherIconAlpha)); +// } else { +// // this changes toolbar title +// mainActivity.mainBinding.toolbar.toolbar.setTitle(slideOffset >= 0.466 ? titleDiscover : +// (mainActivity.userQuery == null +// ? resources.getString(R.string.app_name) +// : mainActivity.userQuery)); +// +// imageTintList = ImageViewCompat.getImageTintList(iconFeed); +// alpha = imageTintList != null ? (imageTintList.getDefaultColor() & 0xFF_000000) >> 24 : 0; +// +// if (drawerOpening && alpha > 100) +// ImageViewCompat.setImageTintList(iconFeed, colorStateList.withAlpha(currentIconAlpha)); +// +// ImageViewCompat.setImageTintList(iconDiscover, colorStateList.withAlpha(otherIconAlpha)); +// } +// } +// +// @Override +// public void onDrawerOpened(@NonNull final View drawerView, @MouseDrawer.EdgeGravity final int gravity) { +// if (gravity == GravityCompat.START || drawerView == mainActivity.mainBinding.feedView.feedLayout) { +// if (videoAwareRecyclerScroller != null) { +// if (SHOULD_AUTO_PLAY) { +// videoAwareRecyclerScroller.startPlaying(); +// } +// } +// } else { +// // clear selection +// isSelectionCleared(); +// } +// } +// +// @Override +// public void onDrawerClosed(@NonNull final View drawerView, @MouseDrawer.EdgeGravity final int gravity) { +// if (gravity == GravityCompat.START || drawerView == mainActivity.mainBinding.feedView.feedLayout) { +// if (videoAwareRecyclerScroller != null) { +// videoAwareRecyclerScroller.stopPlaying(); +// } +// } else { +// // clear selection +// isSelectionCleared(); +// } +// } +// }; +// +// ImageViewCompat.setImageTintList(iconFeed, colorStateList.withAlpha(100)); // to change colors when created +// ImageViewCompat.setImageTintList(iconProfile, colorStateList.withAlpha(255)); // to change colors when created +// ImageViewCompat.setImageTintList(iconDiscover, colorStateList.withAlpha(100)); // to change colors when created +// +// mainActivity.mainBinding.drawerLayout.addDrawerListener(simpleDrawerListener); +// } +// +// collapsingToolbar = mainActivity.mainBinding.profileView.appBarLayout.getChildAt(0); +// +// mainActivity.mainBinding.profileView.mainPosts.setNestedScrollingEnabled(false); +// mainActivity.mainBinding.profileView.highlightsList +// .setLayoutManager(new LinearLayoutManager(mainActivity, LinearLayoutManager.HORIZONTAL, false)); +// mainActivity.mainBinding.profileView.highlightsList.setAdapter(mainActivity.highlightsAdapter); +// +// // int color = -1; +// // final Drawable background = main.mainBinding.profileView.appBarLayout.getBackground(); +// // if (background instanceof MaterialShapeDrawable) { +// // final MaterialShapeDrawable drawable = (MaterialShapeDrawable) background; +// // final ColorStateList fillColor = drawable.getFillColor(); +// // if (fillColor != null) color = fillColor.getDefaultColor(); +// // } else { +// // final Bitmap bitmap = Bitmap.createBitmap(9, 9, Bitmap.Config.ARGB_8888); +// // final Canvas canvas = new Canvas(); +// // canvas.setBitmap(bitmap); +// // background.draw(canvas); +// // color = bitmap.getPixel(4, 4); +// // if (!bitmap.isRecycled()) bitmap.recycle(); +// // } +// // if (color == -1 || color == 0) color = resources.getBoolean(R.bool.isNight) ? 0xff212121 : 0xfff5f5f5; +// // main.mainBinding.profileView.profileInfo.setBackgroundColor(color); +// // if (!isBottomToolbar) main.mainBinding.toolbar.toolbar.setBackgroundColor(color); +// +// // main.mainBinding.profileView.appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { +// // private int height; +// // +// // @Override +// // public void onOffsetChanged(final AppBarLayout appBarLayout, final int verticalOffset) { +// // if (height == 0) { +// // height = main.mainBinding.profileView.profileInfo.getHeight(); +// // collapsingToolbar.setMinimumHeight(height); +// // } +// // main.mainBinding.profileView.profileInfo.setTranslationY(-Math.min(0, verticalOffset)); +// // } +// // }); +// +// mainActivity.setSupportActionBar(mainActivity.mainBinding.toolbar.toolbar); +// if (isBottomToolbar) { +// final LinearLayout linearLayout = (LinearLayout) mainActivity.mainBinding.toolbar.toolbar.getParent(); +// linearLayout.removeView(mainActivity.mainBinding.toolbar.toolbar); +// linearLayout.addView(mainActivity.mainBinding.toolbar.toolbar, linearLayout.getChildCount()); +// } +// +// // change the next number to adjust grid +// final GridAutofitLayoutManager layoutManager = new GridAutofitLayoutManager(mainActivity, Utils.convertDpToPx(110)); +// mainActivity.mainBinding.profileView.mainPosts.setLayoutManager(layoutManager); +// mainActivity.mainBinding.profileView.mainPosts.addItemDecoration(new GridSpacingItemDecoration(Utils.convertDpToPx(4))); +// // mainActivity.mainBinding.profileView.mainPosts.setAdapter(postsAdapter = new PostsAdapter(/*mainActivity.allItems,*/ v -> { +// // final Object tag = v.getTag(); +// // if (tag instanceof PostModel) { +// // final PostModel postModel = (PostModel) tag; +// // +// // if (postsAdapter.isSelecting) toggleSelection(postModel); +// // else mainActivity.startActivity(new Intent(mainActivity, PostViewer.class) +// // .putExtra(Constants.EXTRAS_INDEX, postModel.getPosition()) +// // .putExtra(Constants.EXTRAS_POST, postModel) +// // .putExtra(Constants.EXTRAS_USER, mainActivity.userQuery) +// // .putExtra(Constants.EXTRAS_TYPE, ItemGetType.MAIN_ITEMS)); +// // } +// // }, v -> { // long click listener +// // // final Object tag = v.getTag(); +// // // if (tag instanceof PostModel) { +// // // postsAdapter.isSelecting = true; +// // // toggleSelection((PostModel) tag); +// // // } +// // // return true; +// // return false; +// // })); +// +// this.lazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> { +// if ((!autoloadPosts || isHashtag) && hasNextPage) { +// mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(true); +// stopCurrentExecutor(); +// currentlyExecuting = new PostsFetcher(mainActivity.profileModel != null ? mainActivity.profileModel.getId() +// : (mainActivity.hashtagModel != null +// ? mainActivity.userQuery +// : mainActivity.locationModel.getId()), +// mainActivity.profileModel != null +// ? PostItemType.MAIN +// : (mainActivity.hashtagModel != null ? PostItemType.HASHTAG : PostItemType.LOCATION), +// endCursor, +// postsFetchListener) +// .setUsername((isHashtag || isLocation) ? null : mainActivity.profileModel.getUsername()) +// .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// endCursor = null; +// } +// }); +// mainActivity.mainBinding.profileView.mainPosts.addOnScrollListener(lazyLoader); +// } +// +// private final View.OnClickListener clickListener = v -> { +// if (mainActivity == null) { +// return; +// } +// final Object tag = v.getTag(); +// final Context context = v.getContext(); +// +// if (tag instanceof FeedModel) { +// final FeedModel feedModel = (FeedModel) tag; +// +// if (v instanceof RamboTextView) { +// if (feedModel.isMentionClicked()) +// feedModel.toggleCaption(); +// feedModel.setMentionClicked(false); +// if (!FeedItemViewHolder.expandCollapseTextView((RamboTextView) v, feedModel.getPostCaption())) +// feedModel.toggleCaption(); +// +// } else { +// final int id = v.getId(); +// switch (id) { +// case R.id.btnComments: +// mainActivity.startActivityForResult(new Intent(mainActivity, CommentsViewerFragment.class) +// .putExtra(Constants.EXTRAS_SHORTCODE, feedModel.getShortCode()) +// .putExtra(Constants.EXTRAS_POST, feedModel.getPostId()) +// .putExtra(Constants.EXTRAS_USER, feedModel.getProfileModel().getId()), 6969); +// break; +// +// case R.id.viewStoryPost: +// mainActivity.startActivity(new Intent(mainActivity, PostViewer.class) +// .putExtra(Constants.EXTRAS_INDEX, feedModel.getPosition()) +// .putExtra(Constants.EXTRAS_POST, new PostModel(feedModel.getShortCode(), false)) +// .putExtra(Constants.EXTRAS_TYPE, PostItemType.FEED)); +// break; +// +// case R.id.btnDownload: +// ProfileModel profileModel = feedModel.getProfileModel(); +// final String username = profileModel != null ? profileModel.getUsername() : null; +// +// final ViewerPostModel[] sliderItems = feedModel.getSliderItems(); +// +// if (feedModel.getItemType() != MediaItemType.MEDIA_TYPE_SLIDER || sliderItems == null || sliderItems.length == 1) +// Utils.batchDownload(context, username, DownloadMethod.DOWNLOAD_FEED, Collections.singletonList(feedModel)); +// else { +// final ArrayList postModels = new ArrayList<>(); +// final DialogInterface.OnClickListener clickListener1 = (dialog, which) -> { +// postModels.clear(); +// +// final boolean breakWhenFoundSelected = which == DialogInterface.BUTTON_POSITIVE; +// +// for (final ViewerPostModel sliderItem : sliderItems) { +// if (sliderItem != null) { +// if (!breakWhenFoundSelected) +// postModels.add(sliderItem); +// else if (sliderItem.isSelected()) { +// postModels.add(sliderItem); +// break; +// } +// } +// } +// +// // shows 0 items on first item of viewpager cause onPageSelected hasn't been called yet +// if (breakWhenFoundSelected && postModels.size() == 0) +// postModels.add(sliderItems[0]); +// +// if (postModels.size() > 0) +// Utils.batchDownload(context, username, DownloadMethod.DOWNLOAD_FEED, postModels); +// }; +// +// new AlertDialog.Builder(context).setTitle(R.string.post_viewer_download_dialog_title) +// .setPositiveButton(R.string.post_viewer_download_current, clickListener1) +// .setNegativeButton(R.string.post_viewer_download_album, clickListener1).show(); +// } +// break; +// +// case R.id.ivProfilePic: +// profileModel = feedModel.getProfileModel(); +// if (profileModel != null) +// mentionClickListener.onClick(null, profileModel.getUsername(), false, false); +// break; +// } +// } +// } +// }; +// +// private void setupFeed() { +// mainActivity.mainBinding.feedView.feedStories.setLayoutManager(new LinearLayoutManager(mainActivity, LinearLayoutManager.HORIZONTAL, false)); +// // mainActivity.mainBinding.feedView.feedStories.setAdapter(feedStoriesAdapter); +// refreshFeedStories(); +// +// final LinearLayoutManager layoutManager = new LinearLayoutManager(mainActivity); +// mainActivity.mainBinding.feedView.feedPosts.setHasFixedSize(true); +// mainActivity.mainBinding.feedView.feedPosts.setLayoutManager(layoutManager); +// mainActivity.mainBinding.feedView.feedPosts.setAdapter(feedAdapter = new FeedAdapter(clickListener, (view, text, isHashtag, isLocation) -> +// new AlertDialog.Builder(mainActivity) +// .setMessage(isHashtag ? R.string.comment_view_mention_hash_search : R.string.comment_view_mention_user_search) +// .setTitle(text).setNegativeButton(R.string.cancel, null).setPositiveButton(R.string.ok, (dialog, which) -> { +// if (MainActivityBackup.scanHack != null) { +// mainActivity.mainBinding.drawerLayout.closeDrawers(); +// MainActivityBackup.scanHack.onResult(text); +// } +// }).show())); +// +// mainActivity.mainBinding.feedView.feedSwipeRefreshLayout.setOnRefreshListener(() -> { +// refreshFeedStories(); +// +// if (feedLazyLoader != null) feedLazyLoader.resetState(); +// mainActivity.feedItems.clear(); +// if (feedAdapter != null) feedAdapter.notifyDataSetChanged(); +// new FeedFetcher(feedFetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// }); +// +// mainActivity.mainBinding.feedView.feedPosts +// .addOnScrollListener(feedLazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> { +// if (feedHasNextPage) { +// mainActivity.mainBinding.feedView.feedSwipeRefreshLayout.setRefreshing(true); +// new FeedFetcher(feedEndCursor, feedFetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// feedEndCursor = null; +// } +// })); +// +// if (SHOULD_AUTO_PLAY) { +// videoAwareRecyclerScroller = new VideoAwareRecyclerScroller(); +// mainActivity.mainBinding.feedView.feedPosts.addOnScrollListener(videoAwareRecyclerScroller); +// } +// mainActivity.mainBinding.feedView.feedPosts.addOnScrollListener(new PauseGlideOnFlingScrollListener(glide)); +// +// new FeedFetcher(feedFetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } +// +// private void refreshFeedStories() { +// // todo setup feed stories +// if (prevStoriesFetcher != null) { +// try { +// prevStoriesFetcher.cancel(true); +// } catch (final Exception e) { +// // ignore +// } +// } +// prevStoriesFetcher = new FeedStoriesFetcher(feedStoriesListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } +// +// private void setupExplore() { +// final GridAutofitLayoutManager layoutManager = new GridAutofitLayoutManager(mainActivity, Utils.convertDpToPx(110)); +// mainActivity.mainBinding.discoverPosts.setLayoutManager(layoutManager); +// mainActivity.mainBinding.discoverPosts.addItemDecoration(new GridSpacingItemDecoration(Utils.convertDpToPx(4))); +// +// new iTopicFetcher(topicFetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// mainActivity.mainBinding.discoverType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { +// @Override +// public void onItemSelected(AdapterView parent, View view, int pos, long id) { +// if (topicIds != null) { +// topic = topicIds[pos]; +// mainActivity.mainBinding.discoverSwipeRefreshLayout.setRefreshing(true); +// if (discoverLazyLoader != null) discoverLazyLoader.resetState(); +// mainActivity.discoverItems.clear(); +// if (discoverAdapter != null) discoverAdapter.notifyDataSetChanged(); +// new DiscoverFetcher(topic, null, rankToken, discoverFetchListener, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } +// } +// +// @Override +// public void onNothingSelected(AdapterView parent) { +// } +// }); +// +// mainActivity.mainBinding.discoverSwipeRefreshLayout.setOnRefreshListener(() -> { +// if (discoverLazyLoader != null) discoverLazyLoader.resetState(); +// mainActivity.discoverItems.clear(); +// if (discoverAdapter != null) discoverAdapter.notifyDataSetChanged(); +// new DiscoverFetcher(topic, null, rankToken, discoverFetchListener, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// }); +// +// // mainActivity.mainBinding.discoverPosts.setAdapter(discoverAdapter = new DiscoverAdapter(mainActivity.discoverItems, v -> { +// // final Object tag = v.getTag(); +// // if (tag instanceof DiscoverItemModel) { +// // final DiscoverItemModel itemModel = (DiscoverItemModel) tag; +// // +// // if (discoverAdapter.isSelecting) toggleDiscoverSelection(itemModel); +// // else mainActivity.startActivity(new Intent(mainActivity, PostViewer.class) +// // .putExtra(Constants.EXTRAS_INDEX, itemModel.getPosition()) +// // .putExtra(Constants.EXTRAS_TYPE, ItemGetType.DISCOVER_ITEMS) +// // .putExtra(Constants.EXTRAS_POST, new PostModel(itemModel.getShortCode(), false))); +// // } +// // }, v -> { +// // final Object tag = v.getTag(); +// // if (tag instanceof DiscoverItemModel) { +// // discoverAdapter.isSelecting = true; +// // toggleDiscoverSelection((DiscoverItemModel) tag); +// // } +// // return true; +// // })); +// +// mainActivity.mainBinding.discoverPosts +// .addOnScrollListener(discoverLazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> { +// if (discoverHasMore) { +// mainActivity.mainBinding.discoverSwipeRefreshLayout.setRefreshing(true); +// new DiscoverFetcher(topic, discoverEndMaxId, rankToken, discoverFetchListener, false) +// .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// discoverEndMaxId = null; +// } +// })); +// } +// +// public void onIntent(final Intent intent) { +// if (intent != null) { +// final String action = intent.getAction(); +// if (!Utils.isEmpty(action) && !Intent.ACTION_MAIN.equals(action)) { +// intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); +// +// boolean error = true; +// +// String data = null; +// final Bundle extras = intent.getExtras(); +// if (extras != null) { +// final Object extraData = extras.get(Intent.EXTRA_TEXT); +// if (extraData != null) { +// error = false; +// data = extraData.toString(); +// } +// } +// +// if (error) { +// final Uri intentData = intent.getData(); +// if (intentData != null) data = intentData.toString(); +// } +// +// if (data != null && !Utils.isEmpty(data)) { +// if (data.indexOf('\n') > 0) data = data.substring(data.lastIndexOf('\n') + 1); +// +// final IntentModel model = Utils.stripString(data); +// if (model != null) { +// final String modelText = model.getText(); +// final IntentModelType modelType = model.getType(); +// +// if (modelType == IntentModelType.POST) { +// mainActivity.startActivityForResult(new Intent(mainActivity, PostViewer.class) +// .putExtra(Constants.EXTRAS_USER, mainActivity.userQuery) +// .putExtra(Constants.EXTRAS_POST, new PostModel(modelText, false)), 9629); +// } else { +// mainActivity.addToStack(); +// mainActivity.userQuery = modelType == IntentModelType.HASHTAG ? ('#' + modelText) : +// (modelType == IntentModelType.LOCATION ? modelText : ('@' + modelText)); +// onRefresh(); +// } +// } +// } +// } +// } +// } +// +// @Override +// public void onRefresh() { +// mainActivity.mainBinding.drawerLayout.closeDrawers(); +// if (lazyLoader != null) lazyLoader.resetState(); +// stopCurrentExecutor(); +// mainActivity.allItems.clear(); +// mainActivity.selectedItems.clear(); +// if (postsAdapter != null) { +// // postsAdapter.isSelecting = false; +// postsAdapter.notifyDataSetChanged(); +// } +// mainActivity.mainBinding.profileView.appBarLayout.setExpanded(true, true); +// mainActivity.mainBinding.profileView.privatePage.setVisibility(View.GONE); +// mainActivity.mainBinding.profileView.privatePage2.setTextSize(28); +// // mainActivity.mainBinding.profileView.mainProfileImage.setImageBitmap(null); +// // mainActivity.mainBinding.profileView.mainHashtagImage.setImageBitmap(null); +// // mainActivity.mainBinding.profileView.mainLocationImage.setImageBitmap(null); +// mainActivity.mainBinding.profileView.mainUrl.setText(null); +// mainActivity.mainBinding.profileView.locationUrl.setText(null); +// mainActivity.mainBinding.profileView.mainFullName.setText(null); +// mainActivity.mainBinding.profileView.locationFullName.setText(null); +// mainActivity.mainBinding.profileView.mainPostCount.setText(null); +// mainActivity.mainBinding.profileView.mainLocPostCount.setText(null); +// mainActivity.mainBinding.profileView.mainTagPostCount.setText(null); +// mainActivity.mainBinding.profileView.mainFollowers.setText(null); +// mainActivity.mainBinding.profileView.mainFollowing.setText(null); +// mainActivity.mainBinding.profileView.mainBiography.setText(null); +// mainActivity.mainBinding.profileView.locationBiography.setText(null); +// mainActivity.mainBinding.profileView.mainBiography.setEnabled(false); +// mainActivity.mainBinding.profileView.locationBiography.setEnabled(false); +// mainActivity.mainBinding.profileView.mainProfileImage.setEnabled(false); +// mainActivity.mainBinding.profileView.mainLocationImage.setEnabled(false); +// mainActivity.mainBinding.profileView.mainHashtagImage.setEnabled(false); +// mainActivity.mainBinding.profileView.mainBiography.setMentionClickListener(null); +// mainActivity.mainBinding.profileView.locationBiography.setMentionClickListener(null); +// mainActivity.mainBinding.profileView.mainUrl.setVisibility(View.GONE); +// mainActivity.mainBinding.profileView.locationUrl.setVisibility(View.GONE); +// mainActivity.mainBinding.profileView.isVerified.setVisibility(View.GONE); +// mainActivity.mainBinding.profileView.btnFollow.setVisibility(View.GONE); +// mainActivity.mainBinding.profileView.btnRestrict.setVisibility(View.GONE); +// mainActivity.mainBinding.profileView.btnBlock.setVisibility(View.GONE); +// mainActivity.mainBinding.profileView.btnSaved.setVisibility(View.GONE); +// mainActivity.mainBinding.profileView.btnLiked.setVisibility(View.GONE); +// mainActivity.mainBinding.profileView.btnTagged.setVisibility(View.GONE); +// mainActivity.mainBinding.profileView.btnMap.setVisibility(View.GONE); +// +// mainActivity.mainBinding.profileView.btnFollow.setOnClickListener(profileActionListener); +// mainActivity.mainBinding.profileView.btnRestrict.setOnClickListener(profileActionListener); +// mainActivity.mainBinding.profileView.btnBlock.setOnClickListener(profileActionListener); +// mainActivity.mainBinding.profileView.btnSaved.setOnClickListener(profileActionListener); +// mainActivity.mainBinding.profileView.btnLiked.setOnClickListener(profileActionListener); +// mainActivity.mainBinding.profileView.btnTagged.setOnClickListener(profileActionListener); +// mainActivity.mainBinding.profileView.btnFollowTag.setOnClickListener(profileActionListener); +// +// mainActivity.mainBinding.profileView.infoContainer.setVisibility(View.GONE); +// mainActivity.mainBinding.profileView.tagInfoContainer.setVisibility(View.GONE); +// mainActivity.mainBinding.profileView.locInfoContainer.setVisibility(View.GONE); +// +// mainActivity.mainBinding.profileView.mainPosts.setNestedScrollingEnabled(false); +// mainActivity.mainBinding.profileView.highlightsList.setVisibility(View.GONE); +// collapsingToolbar.setVisibility(View.GONE); +// mainActivity.highlightsAdapter.setData(null); +// +// mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(mainActivity.userQuery != null); +// if (mainActivity.userQuery == null) { +// mainActivity.mainBinding.toolbar.toolbar.setTitle(R.string.app_name); +// return; +// } +// +// isHashtag = mainActivity.userQuery.charAt(0) == '#'; +// final boolean isUser = mainActivity.userQuery.charAt(0) == '@'; +// isLocation = mainActivity.userQuery.contains("/"); +// collapsingToolbar.setVisibility(isUser ? View.VISIBLE : View.GONE); +// +// if (isHashtag) { +// mainActivity.profileModel = null; +// mainActivity.locationModel = null; +// mainActivity.mainBinding.toolbar.toolbar.setTitle(mainActivity.userQuery); +// mainActivity.mainBinding.profileView.tagInfoContainer.setVisibility(View.VISIBLE); +// mainActivity.mainBinding.profileView.btnFollowTag.setVisibility(View.GONE); +// +// currentlyExecuting = new HashtagFetcher(mainActivity.userQuery.substring(1), hashtagModel -> { +// mainActivity.hashtagModel = hashtagModel; +// +// if (hashtagModel == null) { +// mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(false); +// Toast.makeText(mainActivity, R.string.error_loading_profile, Toast.LENGTH_SHORT).show(); +// mainActivity.mainBinding.toolbar.toolbar.setTitle(R.string.app_name); +// return; +// } +// +// currentlyExecuting = new PostsFetcher(mainActivity.userQuery, PostItemType.HASHTAG, null, postsFetchListener) +// .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// +// mainActivity.mainBinding.profileView.btnFollowTag.setVisibility(View.VISIBLE); +// +// if (isLoggedIn) { +// new iStoryStatusFetcher(hashtagModel.getName(), null, false, true, false, false, result -> { +// mainActivity.storyModels = result; +// if (result != null && result.length > 0) +// mainActivity.mainBinding.profileView.mainHashtagImage.setStoriesBorder(); +// }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// +// if (hashtagModel.getFollowing()) { +// mainActivity.mainBinding.profileView.btnFollowTag.setText(R.string.unfollow); +// mainActivity.mainBinding.profileView.btnFollowTag.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// mainActivity, R.color.btn_purple_background))); +// } else { +// mainActivity.mainBinding.profileView.btnFollowTag.setText(R.string.follow); +// mainActivity.mainBinding.profileView.btnFollowTag.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// mainActivity, R.color.btn_pink_background))); +// } +// } else { +// if (Utils.dataBox.getFavorite(mainActivity.userQuery) != null) { +// mainActivity.mainBinding.profileView.btnFollowTag.setText(R.string.unfavorite_short); +// mainActivity.mainBinding.profileView.btnFollowTag.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// mainActivity, R.color.btn_purple_background))); +// } else { +// mainActivity.mainBinding.profileView.btnFollowTag.setText(R.string.favorite_short); +// mainActivity.mainBinding.profileView.btnFollowTag.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// mainActivity, R.color.btn_pink_background))); +// } +// } +// +// mainActivity.mainBinding.profileView.mainHashtagImage.setEnabled(false); +// // new MyTask().execute(); +// mainActivity.mainBinding.profileView.mainHashtagImage.setImageURI(hashtagModel.getSdProfilePic()); +// mainActivity.mainBinding.profileView.mainHashtagImage.setEnabled(true); +// +// final String postCount = String.valueOf(hashtagModel.getPostCount()); +// +// SpannableStringBuilder span = new SpannableStringBuilder(resources.getString(R.string.main_posts_count, postCount)); +// span.setSpan(new RelativeSizeSpan(1.2f), 0, postCount.length(), 0); +// span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0); +// mainActivity.mainBinding.profileView.mainTagPostCount.setText(span); +// mainActivity.mainBinding.profileView.mainTagPostCount.setVisibility(View.VISIBLE); +// }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } else if (isUser) { +// mainActivity.hashtagModel = null; +// mainActivity.locationModel = null; +// mainActivity.mainBinding.toolbar.toolbar.setTitle(mainActivity.userQuery); +// mainActivity.mainBinding.profileView.infoContainer.setVisibility(View.VISIBLE); +// mainActivity.mainBinding.profileView.btnFollowTag.setVisibility(View.GONE); +// +// currentlyExecuting = new ProfileFetcher(mainActivity.userQuery.substring(1), profileModel -> { +// mainActivity.profileModel = profileModel; +// +// if (profileModel == null) { +// mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(false); +// Toast.makeText(mainActivity, R.string.error_loading_profile, Toast.LENGTH_SHORT).show(); +// mainActivity.mainBinding.toolbar.toolbar.setTitle(R.string.app_name); +// return; +// } +// +// mainActivity.mainBinding.profileView.isVerified.setVisibility(profileModel.isVerified() ? View.VISIBLE : View.GONE); +// final String profileId = profileModel.getId(); +// +// if (isLoggedIn || settingsHelper.getBoolean(Constants.STORIESIG)) { +// new iStoryStatusFetcher(profileId, profileModel.getUsername(), false, false, +// (!isLoggedIn && settingsHelper.getBoolean(Constants.STORIESIG)), false, +// result -> { +// mainActivity.storyModels = result; +// if (result != null && result.length > 0) +// mainActivity.mainBinding.profileView.mainProfileImage.setStoriesBorder(); +// }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// +// new HighlightsFetcher(profileId, (!isLoggedIn && settingsHelper.getBoolean(Constants.STORIESIG)), result -> { +// if (result != null && result.length > 0) { +// mainActivity.mainBinding.profileView.highlightsList.setVisibility(View.VISIBLE); +// mainActivity.highlightsAdapter.setData(result); +// } else +// mainActivity.mainBinding.profileView.highlightsList.setVisibility(View.GONE); +// }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } +// +// if (isLoggedIn) { +// final String myId = Utils.getUserIdFromCookie(cookie); +// if (!profileId.equals(myId)) { +// mainActivity.mainBinding.profileView.btnTagged.setVisibility(View.GONE); +// mainActivity.mainBinding.profileView.btnSaved.setVisibility(View.GONE); +// mainActivity.mainBinding.profileView.btnLiked.setVisibility(View.GONE); +// mainActivity.mainBinding.profileView.btnFollow.setVisibility(View.VISIBLE); +// if (profileModel.getFollowing() == true) { +// mainActivity.mainBinding.profileView.btnFollow.setText(R.string.unfollow); +// mainActivity.mainBinding.profileView.btnFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// mainActivity, R.color.btn_purple_background))); +// } else if (profileModel.getRequested() == true) { +// mainActivity.mainBinding.profileView.btnFollow.setText(R.string.cancel); +// mainActivity.mainBinding.profileView.btnFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// mainActivity, R.color.btn_purple_background))); +// } else { +// mainActivity.mainBinding.profileView.btnFollow.setText(R.string.follow); +// mainActivity.mainBinding.profileView.btnFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// mainActivity, R.color.btn_pink_background))); +// } +// mainActivity.mainBinding.profileView.btnRestrict.setVisibility(View.VISIBLE); +// if (profileModel.getRestricted() == true) { +// mainActivity.mainBinding.profileView.btnRestrict.setText(R.string.unrestrict); +// mainActivity.mainBinding.profileView.btnRestrict.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// mainActivity, R.color.btn_green_background))); +// } else { +// mainActivity.mainBinding.profileView.btnRestrict.setText(R.string.restrict); +// mainActivity.mainBinding.profileView.btnRestrict.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// mainActivity, R.color.btn_orange_background))); +// } +// if (profileModel.isReallyPrivate()) { +// mainActivity.mainBinding.profileView.btnBlock.setVisibility(View.VISIBLE); +// mainActivity.mainBinding.profileView.btnTagged.setVisibility(View.GONE); +// if (profileModel.getBlocked() == true) { +// mainActivity.mainBinding.profileView.btnBlock.setText(R.string.unblock); +// mainActivity.mainBinding.profileView.btnBlock.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// mainActivity, R.color.btn_green_background))); +// } else { +// mainActivity.mainBinding.profileView.btnBlock.setText(R.string.block); +// mainActivity.mainBinding.profileView.btnBlock.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// mainActivity, R.color.btn_red_background))); +// } +// } else { +// mainActivity.mainBinding.profileView.btnBlock.setVisibility(View.GONE); +// mainActivity.mainBinding.profileView.btnSaved.setVisibility(View.VISIBLE); +// mainActivity.mainBinding.profileView.btnTagged.setVisibility(View.VISIBLE); +// if (profileModel.getBlocked() == true) { +// mainActivity.mainBinding.profileView.btnSaved.setText(R.string.unblock); +// mainActivity.mainBinding.profileView.btnSaved.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// mainActivity, R.color.btn_green_background))); +// } else { +// mainActivity.mainBinding.profileView.btnSaved.setText(R.string.block); +// mainActivity.mainBinding.profileView.btnSaved.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// mainActivity, R.color.btn_red_background))); +// } +// } +// } else { +// mainActivity.mainBinding.profileView.btnTagged.setVisibility(View.VISIBLE); +// mainActivity.mainBinding.profileView.btnSaved.setVisibility(View.VISIBLE); +// mainActivity.mainBinding.profileView.btnLiked.setVisibility(View.VISIBLE); +// mainActivity.mainBinding.profileView.btnSaved.setText(R.string.saved); +// mainActivity.mainBinding.profileView.btnSaved.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// mainActivity, R.color.btn_orange_background))); +// } +// } else { +// if (Utils.dataBox.getFavorite(mainActivity.userQuery) != null) { +// mainActivity.mainBinding.profileView.btnFollow.setText(R.string.unfavorite_short); +// mainActivity.mainBinding.profileView.btnFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// mainActivity, R.color.btn_purple_background))); +// } else { +// mainActivity.mainBinding.profileView.btnFollow.setText(R.string.favorite_short); +// mainActivity.mainBinding.profileView.btnFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// mainActivity, R.color.btn_pink_background))); +// } +// mainActivity.mainBinding.profileView.btnFollow.setVisibility(View.VISIBLE); +// if (!profileModel.isReallyPrivate()) { +// mainActivity.mainBinding.profileView.btnRestrict.setVisibility(View.VISIBLE); +// mainActivity.mainBinding.profileView.btnRestrict.setText(R.string.tagged); +// mainActivity.mainBinding.profileView.btnRestrict.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// mainActivity, R.color.btn_blue_background))); +// } +// } +// +// // mainActivity.mainBinding.profileView.mainProfileImage.setEnabled(false); +// // new MyTask().execute(); +// mainActivity.mainBinding.profileView.mainProfileImage.setImageURI(profileModel.getSdProfilePic()); +// // mainActivity.mainBinding.profileView.mainProfileImage.setEnabled(true); +// +// final long followersCount = profileModel.getFollowersCount(); +// final long followingCount = profileModel.getFollowingCount(); +// +// final String postCount = String.valueOf(profileModel.getPostCount()); +// +// SpannableStringBuilder span = new SpannableStringBuilder(resources.getString(R.string.main_posts_count, postCount)); +// span.setSpan(new RelativeSizeSpan(1.2f), 0, postCount.length(), 0); +// span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0); +// mainActivity.mainBinding.profileView.mainPostCount.setText(span); +// +// final String followersCountStr = String.valueOf(followersCount); +// final int followersCountStrLen = followersCountStr.length(); +// span = new SpannableStringBuilder(resources.getString(R.string.main_posts_followers, followersCountStr)); +// span.setSpan(new RelativeSizeSpan(1.2f), 0, followersCountStrLen, 0); +// span.setSpan(new StyleSpan(Typeface.BOLD), 0, followersCountStrLen, 0); +// mainActivity.mainBinding.profileView.mainFollowers.setText(span); +// +// final String followingCountStr = String.valueOf(followingCount); +// final int followingCountStrLen = followingCountStr.length(); +// span = new SpannableStringBuilder(resources.getString(R.string.main_posts_following, followingCountStr)); +// span.setSpan(new RelativeSizeSpan(1.2f), 0, followingCountStrLen, 0); +// span.setSpan(new StyleSpan(Typeface.BOLD), 0, followingCountStrLen, 0); +// mainActivity.mainBinding.profileView.mainFollowing.setText(span); +// +// mainActivity.mainBinding.profileView.mainFullName +// .setText(Utils.isEmpty(profileModel.getName()) ? profileModel.getUsername() : profileModel.getName()); +// +// CharSequence biography = profileModel.getBiography(); +// mainActivity.mainBinding.profileView.mainBiography.setCaptionIsExpandable(true); +// mainActivity.mainBinding.profileView.mainBiography.setCaptionIsExpanded(true); +// if (Utils.hasMentions(biography)) { +// biography = Utils.getMentionText(biography); +// mainActivity.mainBinding.profileView.mainBiography.setText(biography, TextView.BufferType.SPANNABLE); +// mainActivity.mainBinding.profileView.mainBiography.setMentionClickListener(mentionClickListener); +// } else { +// mainActivity.mainBinding.profileView.mainBiography.setText(biography); +// mainActivity.mainBinding.profileView.mainBiography.setMentionClickListener(null); +// } +// +// final String url = profileModel.getUrl(); +// if (Utils.isEmpty(url)) { +// mainActivity.mainBinding.profileView.mainUrl.setVisibility(View.GONE); +// } else { +// mainActivity.mainBinding.profileView.mainUrl.setVisibility(View.VISIBLE); +// mainActivity.mainBinding.profileView.mainUrl.setText(Utils.getSpannableUrl(url)); +// } +// +// mainActivity.mainBinding.profileView.mainFullName.setSelected(true); +// mainActivity.mainBinding.profileView.mainBiography.setEnabled(true); +// +// if (!profileModel.isReallyPrivate()) { +// mainActivity.mainBinding.profileView.mainFollowing.setClickable(true); +// mainActivity.mainBinding.profileView.mainFollowers.setClickable(true); +// +// if (isLoggedIn) { +// // final View.OnClickListener followClickListener = v -> mainActivity.startActivity(new Intent(mainActivity, FollowViewerFragment.class) +// // .putExtra(Constants.EXTRAS_FOLLOWERS, +// // v == mainActivity.mainBinding.profileView.mainFollowers) +// // .putExtra(Constants.EXTRAS_NAME, +// // profileModel.getUsername()) +// // .putExtra(Constants.EXTRAS_ID, +// // profileId)); +// // +// // mainActivity.mainBinding.profileView.mainFollowers.setOnClickListener(followersCount > 0 ? followClickListener : null); +// // mainActivity.mainBinding.profileView.mainFollowing.setOnClickListener(followingCount > 0 ? followClickListener : null); +// } +// +// if (profileModel.getPostCount() == 0) { +// mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(false); +// mainActivity.mainBinding.profileView.privatePage1.setImageResource(R.drawable.ic_cancel); +// mainActivity.mainBinding.profileView.privatePage2.setText(R.string.empty_acc); +// mainActivity.mainBinding.profileView.privatePage.setVisibility(View.VISIBLE); +// } else { +// mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(true); +// mainActivity.mainBinding.profileView.mainPosts.setVisibility(View.VISIBLE); +// currentlyExecuting = new PostsFetcher(profileId, PostItemType.MAIN, null, postsFetchListener) +// .setUsername(profileModel.getUsername()) +// .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } +// } else { +// mainActivity.mainBinding.profileView.mainFollowers.setClickable(false); +// mainActivity.mainBinding.profileView.mainFollowing.setClickable(false); +// mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(false); +// // error +// mainActivity.mainBinding.profileView.privatePage1.setImageResource(R.drawable.lock); +// mainActivity.mainBinding.profileView.privatePage2.setText(R.string.priv_acc); +// mainActivity.mainBinding.profileView.privatePage.setVisibility(View.VISIBLE); +// mainActivity.mainBinding.profileView.mainPosts.setVisibility(View.GONE); +// } +// } +// ).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } else if (isLocation) { +// mainActivity.profileModel = null; +// mainActivity.hashtagModel = null; +// mainActivity.mainBinding.toolbar.toolbar.setTitle(mainActivity.userQuery); +// mainActivity.mainBinding.profileView.locInfoContainer.setVisibility(View.VISIBLE); +// +// currentlyExecuting = new LocationFetcher(mainActivity.userQuery.split("/")[0], locationModel -> { +// mainActivity.locationModel = locationModel; +// +// if (locationModel == null) { +// mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(false); +// Toast.makeText(mainActivity, R.string.error_loading_profile, Toast.LENGTH_SHORT).show(); +// mainActivity.mainBinding.toolbar.toolbar.setTitle(R.string.app_name); +// return; +// } +// mainActivity.mainBinding.toolbar.toolbar.setTitle(locationModel.getName()); +// +// final String profileId = locationModel.getId(); +// +// if (isLoggedIn) { +// new iStoryStatusFetcher(profileId.split("/")[0], null, true, false, false, false, result -> { +// mainActivity.storyModels = result; +// if (result != null && result.length > 0) +// mainActivity.mainBinding.profileView.mainLocationImage.setStoriesBorder(); +// }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } +// +// // mainActivity.mainBinding.profileView.mainLocationImage.setEnabled(false); +// // new MyTask().execute(); +// mainActivity.mainBinding.profileView.mainLocationImage.setImageURI(locationModel.getSdProfilePic()); +// // mainActivity.mainBinding.profileView.mainLocationImage.setEnabled(true); +// +// final String postCount = String.valueOf(locationModel.getPostCount()); +// +// SpannableStringBuilder span = new SpannableStringBuilder(resources.getString(R.string.main_posts_count, postCount)); +// span.setSpan(new RelativeSizeSpan(1.2f), 0, postCount.length(), 0); +// span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0); +// mainActivity.mainBinding.profileView.mainLocPostCount.setText(span); +// +// mainActivity.mainBinding.profileView.locationFullName.setText(locationModel.getName()); +// +// CharSequence biography = locationModel.getBio(); +// mainActivity.mainBinding.profileView.locationBiography.setCaptionIsExpandable(true); +// mainActivity.mainBinding.profileView.locationBiography.setCaptionIsExpanded(true); +// +// if (Utils.isEmpty(biography)) { +// mainActivity.mainBinding.profileView.locationBiography.setVisibility(View.GONE); +// } else if (Utils.hasMentions(biography)) { +// mainActivity.mainBinding.profileView.locationBiography.setVisibility(View.VISIBLE); +// biography = Utils.getMentionText(biography); +// mainActivity.mainBinding.profileView.locationBiography.setText(biography, TextView.BufferType.SPANNABLE); +// mainActivity.mainBinding.profileView.locationBiography.setMentionClickListener(mentionClickListener); +// } else { +// mainActivity.mainBinding.profileView.locationBiography.setVisibility(View.VISIBLE); +// mainActivity.mainBinding.profileView.locationBiography.setText(biography); +// mainActivity.mainBinding.profileView.locationBiography.setMentionClickListener(null); +// } +// +// if (!locationModel.getGeo().startsWith("geo:0.0,0.0?z=17")) { +// mainActivity.mainBinding.profileView.btnMap.setVisibility(View.VISIBLE); +// mainActivity.mainBinding.profileView.btnMap.setOnClickListener(v -> { +// final Intent intent = new Intent(Intent.ACTION_VIEW); +// intent.setData(Uri.parse(locationModel.getGeo())); +// mainActivity.startActivity(intent); +// }); +// } else { +// mainActivity.mainBinding.profileView.btnMap.setVisibility(View.GONE); +// mainActivity.mainBinding.profileView.btnMap.setOnClickListener(null); +// } +// +// final String url = locationModel.getUrl(); +// if (Utils.isEmpty(url)) { +// mainActivity.mainBinding.profileView.locationUrl.setVisibility(View.GONE); +// } else if (!url.startsWith("http")) { +// mainActivity.mainBinding.profileView.locationUrl.setVisibility(View.VISIBLE); +// mainActivity.mainBinding.profileView.locationUrl.setText(Utils.getSpannableUrl("http://" + url)); +// } else { +// mainActivity.mainBinding.profileView.locationUrl.setVisibility(View.VISIBLE); +// mainActivity.mainBinding.profileView.locationUrl.setText(Utils.getSpannableUrl(url)); +// } +// +// mainActivity.mainBinding.profileView.locationFullName.setSelected(true); +// mainActivity.mainBinding.profileView.locationBiography.setEnabled(true); +// +// if (locationModel.getPostCount() == 0) { +// mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(false); +// mainActivity.mainBinding.profileView.privatePage1.setImageResource(R.drawable.ic_cancel); +// mainActivity.mainBinding.profileView.privatePage2.setText(R.string.empty_acc); +// mainActivity.mainBinding.profileView.privatePage.setVisibility(View.VISIBLE); +// } else { +// mainActivity.mainBinding.profileView.swipeRefreshLayout.setRefreshing(true); +// mainActivity.mainBinding.profileView.mainPosts.setVisibility(View.VISIBLE); +// currentlyExecuting = new PostsFetcher(profileId, PostItemType.LOCATION, null, postsFetchListener) +// .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } +// } +// ).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } +// } +// +// public static void stopCurrentExecutor() { +// if (currentlyExecuting != null) { +// try { +// currentlyExecuting.cancel(true); +// } catch (final Exception e) { +// if (logCollector != null) +// logCollector.appendException(e, LogCollector.LogFile.MAIN_HELPER, "stopCurrentExecutor"); +// if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e); +// } +// } +// } +// +// private void toggleSelection(final PostModel postModel) { +// if (postModel != null && postsAdapter != null && mainActivity.selectedItems.size() >= 100) { +// Toast.makeText(mainActivity, R.string.downloader_too_many, Toast.LENGTH_SHORT); +// } else if (postModel != null && postsAdapter != null) { +// if (postModel.isSelected()) mainActivity.selectedItems.remove(postModel); +// else if (mainActivity.selectedItems.size() >= 100) { +// Toast.makeText(mainActivity, R.string.downloader_too_many, Toast.LENGTH_SHORT); +// return; +// } else mainActivity.selectedItems.add(postModel); +// postModel.setSelected(!postModel.isSelected()); +// notifyAdapter(postModel); +// } +// } +// +// private void notifyAdapter(final PostModel postModel) { +// // if (mainActivity.selectedItems.size() < 1) postsAdapter.isSelecting = false; +// // if (postModel.getPosition() < 0) postsAdapter.notifyDataSetChanged(); +// // else postsAdapter.notifyItemChanged(postModel.getPosition(), postModel); +// // +// // if (mainActivity.downloadAction != null) +// // mainActivity.downloadAction.setVisible(postsAdapter.isSelecting); +// } +// +// private void toggleDiscoverSelection(final DiscoverItemModel itemModel) { +// if (itemModel != null && discoverAdapter != null) { +// if (itemModel.isSelected()) mainActivity.selectedDiscoverItems.remove(itemModel); +// else mainActivity.selectedDiscoverItems.add(itemModel); +// itemModel.setSelected(!itemModel.isSelected()); +// notifyDiscoverAdapter(itemModel); +// } +// } +// +// private void notifyDiscoverAdapter(final DiscoverItemModel itemModel) { +// // if (mainActivity.selectedDiscoverItems.size() < 1) discoverAdapter.isSelecting = false; +// // if (itemModel.getPosition() < 0) discoverAdapter.notifyDataSetChanged(); +// // else discoverAdapter.notifyItemChanged(itemModel.getPosition(), itemModel); +// // +// // if (mainActivity.downloadAction != null) +// // mainActivity.downloadAction.setVisible(discoverAdapter.isSelecting); +// } +// +// public boolean isSelectionCleared() { +// // if (postsAdapter != null && postsAdapter.isSelecting()) { +// // for (final PostModel postModel : mainActivity.selectedItems) +// // postModel.setSelected(false); +// // mainActivity.selectedItems.clear(); +// // // postsAdapter.isSelecting = false; +// // postsAdapter.notifyDataSetChanged(); +// // if (mainActivity.downloadAction != null) mainActivity.downloadAction.setVisible(false); +// // return false; +// // } else if (discoverAdapter != null && discoverAdapter.isSelecting) { +// // for (final DiscoverItemModel itemModel : mainActivity.selectedDiscoverItems) +// // itemModel.setSelected(false); +// // mainActivity.selectedDiscoverItems.clear(); +// // discoverAdapter.isSelecting = false; +// // discoverAdapter.notifyDataSetChanged(); +// // if (mainActivity.downloadAction != null) mainActivity.downloadAction.setVisible(false); +// // return false; +// // } +// // return true; +// return false; +// } +// +// public void deselectSelection(final BasePostModel postModel) { +// if (postModel instanceof PostModel) { +// mainActivity.selectedItems.remove(postModel); +// postModel.setSelected(false); +// if (postsAdapter != null) notifyAdapter((PostModel) postModel); +// } else if (postModel instanceof DiscoverItemModel) { +// mainActivity.selectedDiscoverItems.remove(postModel); +// postModel.setSelected(false); +// if (discoverAdapter != null) notifyDiscoverAdapter((DiscoverItemModel) postModel); +// } +// } +// +// public void onPause() { +// if (videoAwareRecyclerScroller != null) { +// videoAwareRecyclerScroller.stopPlaying(); +// } +// } +// +// public void onResume() { +// if (videoAwareRecyclerScroller != null && SHOULD_AUTO_PLAY) { +// videoAwareRecyclerScroller.startPlaying(); +// } +// } +// +// public static int indexOfIntArray(Object[] array, Object key) { +// int returnvalue = -1; +// for (int i = 0; i < array.length; ++i) { +// if (key == array[i]) { +// returnvalue = i; +// break; +// } +// } +// return returnvalue; +// } +// +// private final View.OnClickListener profileActionListener = new View.OnClickListener() { +// @Override +// public void onClick(final View v) { +// final String userIdFromCookie = Utils.getUserIdFromCookie(MainHelper.this.cookie); +// final boolean isSelf = (isLoggedIn && mainActivity.profileModel != null) && userIdFromCookie != null && userIdFromCookie +// .equals(mainActivity.profileModel.getId()); +// if (!isLoggedIn +// && Utils.dataBox.getFavorite(mainActivity.userQuery) != null +// && v == mainActivity.mainBinding.profileView.btnFollow) { +// Utils.dataBox.delFavorite(new DataBox.FavoriteModel(mainActivity.userQuery, +// Long.parseLong(Utils.dataBox.getFavorite(mainActivity.userQuery).split("/")[1]), +// mainActivity.locationModel != null +// ? mainActivity.locationModel.getName() +// : mainActivity.userQuery.replaceAll("^@", ""))); +// onRefresh(); +// } else if (!isLoggedIn +// && (v == mainActivity.mainBinding.profileView.btnFollow || v == mainActivity.mainBinding.profileView.btnFollowTag)) { +// Utils.dataBox.addFavorite(new DataBox.FavoriteModel(mainActivity.userQuery, System.currentTimeMillis(), +// mainActivity.locationModel != null +// ? mainActivity.locationModel.getName() +// : mainActivity.userQuery.replaceAll("^@", ""))); +// onRefresh(); +// } else if (v == mainActivity.mainBinding.profileView.btnFollow) { +// if (mainActivity.profileModel.isPrivate() && mainActivity.profileModel.getFollowing()) { +// new AlertDialog.Builder(mainActivity) +// .setTitle(R.string.priv_acc) +// .setMessage(R.string.priv_acc_confirm) +// .setNegativeButton(R.string.no, null) +// .setPositiveButton(R.string.yes, (dialog, which) -> new ProfileAction().execute("follow")) +// .show(); +// } else new ProfileAction().execute("follow"); +// } else if (v == mainActivity.mainBinding.profileView.btnRestrict && isLoggedIn) { +// new ProfileAction().execute("restrict"); +// } else if (v == mainActivity.mainBinding.profileView.btnSaved && !isSelf) { +// new ProfileAction().execute("block"); +// } else if (v == mainActivity.mainBinding.profileView.btnFollowTag) { +// new ProfileAction().execute("followtag"); +// } else if (v == mainActivity.mainBinding.profileView.btnTagged || v == mainActivity.mainBinding.profileView.btnRestrict) { +// mainActivity.startActivity(new Intent(mainActivity, SavedViewerFragment.class) +// .putExtra(Constants.EXTRAS_INDEX, "%" + mainActivity.profileModel.getId()) +// .putExtra(Constants.EXTRAS_USER, "@" + mainActivity.profileModel.getUsername()) +// ); +// } else if (v == mainActivity.mainBinding.profileView.btnSaved) { +// mainActivity.startActivity(new Intent(mainActivity, SavedViewerFragment.class) +// .putExtra(Constants.EXTRAS_INDEX, "$" + mainActivity.profileModel.getId()) +// .putExtra(Constants.EXTRAS_USER, "@" + mainActivity.profileModel.getUsername()) +// ); +// } else if (v == mainActivity.mainBinding.profileView.btnLiked) { +// mainActivity.startActivity(new Intent(mainActivity, SavedViewerFragment.class) +// .putExtra(Constants.EXTRAS_INDEX, "^" + mainActivity.profileModel.getId()) +// .putExtra(Constants.EXTRAS_USER, "@" + mainActivity.profileModel.getUsername()) +// ); +// } +// } +// }; +// +// class ProfileAction extends AsyncTask { +// boolean ok = false; +// String action; +// +// protected Void doInBackground(String... rawAction) { +// action = rawAction[0]; +// final String url = "https://www.instagram.com/web/" + (action.equals("followtag") && mainActivity.hashtagModel != null +// ? "tags/" + (mainActivity.hashtagModel.getFollowing() +// ? "unfollow/" +// : "follow/") + mainActivity.hashtagModel.getName() + "/" +// : (action.equals("restrict") && mainActivity.profileModel != null +// ? "restrict_action" +// : "friendships/" + mainActivity.profileModel.getId()) + "/" + (action.equals( +// "follow") ? +// mainActivity.profileModel +// .getFollowing() || mainActivity.profileModel +// .getRequested() +// ? "unfollow/" +// : "follow/" : +// action.equals( +// "restrict") +// ? +// mainActivity.profileModel +// .getRestricted() +// ? "unrestrict/" +// : "restrict/" +// : +// mainActivity.profileModel +// .getBlocked() +// ? "unblock/" +// : "block/")); +// try { +// final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); +// urlConnection.setRequestMethod("POST"); +// urlConnection.setUseCaches(false); +// urlConnection.setRequestProperty("User-Agent", Constants.USER_AGENT); +// urlConnection.setRequestProperty("x-csrftoken", cookie.split("csrftoken=")[1].split(";")[0]); +// if (action == "restrict") { +// final String urlParameters = "target_user_id=" + mainActivity.profileModel.getId(); +// urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); +// urlConnection.setRequestProperty("Content-Length", "" + +// urlParameters.getBytes().length); +// urlConnection.setDoOutput(true); +// DataOutputStream wr = new DataOutputStream(urlConnection.getOutputStream()); +// wr.writeBytes(urlParameters); +// wr.flush(); +// wr.close(); +// } else urlConnection.connect(); +// if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { +// ok = true; +// } else +// Toast.makeText(mainActivity, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); +// urlConnection.disconnect(); +// } catch (Throwable ex) { +// Log.e("austin_debug", action + ": " + ex); +// } +// return null; +// } +// +// @Override +// protected void onPostExecute(Void result) { +// if (ok == true) { +// onRefresh(); +// } +// } +// } +// } diff --git a/app/src/main/java/awais/instagrabber/activities/DirectMessagesActivity.java b/app/src/main/java/awais/instagrabber/activities/DirectMessagesActivity.java index 029ca84f..b2b9c9dc 100644 --- a/app/src/main/java/awais/instagrabber/activities/DirectMessagesActivity.java +++ b/app/src/main/java/awais/instagrabber/activities/DirectMessagesActivity.java @@ -1,94 +1,94 @@ -package awais.instagrabber.activities; - -import android.os.Bundle; -import android.view.View; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.widget.AppCompatImageView; -import androidx.appcompat.widget.Toolbar; -import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.navigation.NavController; -import androidx.navigation.NavDestination; -import androidx.navigation.Navigation; -import androidx.navigation.ui.AppBarConfiguration; -import androidx.navigation.ui.NavigationUI; - -import awais.instagrabber.R; -import awais.instagrabber.databinding.ActivityDirectMessagesBinding; -import awais.instagrabber.fragments.directmessages.DirectMessageThreadFragmentArgs; -import awais.instagrabber.utils.Constants; -import static awais.instagrabber.utils.Utils.settingsHelper; - -@Deprecated -public class DirectMessagesActivity extends BaseLanguageActivity implements NavController.OnDestinationChangedListener { - - private TextView toolbarTitle; - private AppCompatImageView dmInfo, dmSeen; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - final ActivityDirectMessagesBinding binding = ActivityDirectMessagesBinding.inflate(getLayoutInflater()); - final CoordinatorLayout root = binding.getRoot(); - setContentView(root); - - toolbarTitle = binding.toolbarTitle; - - final Toolbar toolbar = binding.toolbar; - setSupportActionBar(toolbar); - - dmInfo = binding.dmInfo; - dmSeen = binding.dmSeen; - - final NavController navController = Navigation.findNavController(this, R.id.direct_messages_nav_host_fragment); - navController.addOnDestinationChangedListener(this); - final AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(navController.getGraph()).build(); - NavigationUI.setupWithNavController(toolbar, navController, appBarConfiguration); - } - - @Override - public void onDestinationChanged(@NonNull final NavController controller, - @NonNull final NavDestination destination, - @Nullable final Bundle arguments) { - switch (destination.getId()) { - case R.id.directMessagesInboxFragment: - setToolbarTitle(R.string.action_dms); - dmInfo.setVisibility(View.GONE); - dmSeen.setVisibility(View.GONE); - return; - case R.id.directMessagesThreadFragment: - if (arguments == null) { - return; - } - final String title = DirectMessageThreadFragmentArgs.fromBundle(arguments).getTitle(); - setToolbarTitle(title); - dmInfo.setVisibility(View.VISIBLE); - dmSeen.setVisibility(settingsHelper.getBoolean(Constants.DM_MARK_AS_SEEN) ? View.GONE : View.VISIBLE); - return; - case R.id.directMessagesSettingsFragment: - if (arguments == null) { - return; - } - setToolbarTitle(R.string.action_settings); - dmInfo.setVisibility(View.GONE); - dmSeen.setVisibility(View.GONE); - return; - } - } - - private void setToolbarTitle(final String text) { - if (toolbarTitle == null) { - return; - } - toolbarTitle.setText(text); - } - - private void setToolbarTitle(final int resourceId) { - if (toolbarTitle == null) { - return; - } - toolbarTitle.setText(resourceId); - } -} +// package awais.instagrabber.activities; +// +// import android.os.Bundle; +// import android.view.View; +// import android.widget.TextView; +// +// import androidx.annotation.NonNull; +// import androidx.annotation.Nullable; +// import androidx.appcompat.widget.AppCompatImageView; +// import androidx.appcompat.widget.Toolbar; +// import androidx.coordinatorlayout.widget.CoordinatorLayout; +// import androidx.navigation.NavController; +// import androidx.navigation.NavDestination; +// import androidx.navigation.Navigation; +// import androidx.navigation.ui.AppBarConfiguration; +// import androidx.navigation.ui.NavigationUI; +// +// import awais.instagrabber.R; +// import awais.instagrabber.databinding.ActivityDirectMessagesBinding; +// import awais.instagrabber.fragments.directmessages.DirectMessageThreadFragmentArgs; +// import awais.instagrabber.utils.Constants; +// import static awais.instagrabber.utils.Utils.settingsHelper; +// +// @Deprecated +// public class DirectMessagesActivity extends BaseLanguageActivity implements NavController.OnDestinationChangedListener { +// +// private TextView toolbarTitle; +// private AppCompatImageView dmInfo, dmSeen; +// +// @Override +// protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// final ActivityDirectMessagesBinding binding = ActivityDirectMessagesBinding.inflate(getLayoutInflater()); +// final CoordinatorLayout root = binding.getRoot(); +// setContentView(root); +// +// toolbarTitle = binding.toolbarTitle; +// +// final Toolbar toolbar = binding.toolbar; +// setSupportActionBar(toolbar); +// +// dmInfo = binding.dmInfo; +// dmSeen = binding.dmSeen; +// +// final NavController navController = Navigation.findNavController(this, R.id.direct_messages_nav_host_fragment); +// navController.addOnDestinationChangedListener(this); +// final AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(navController.getGraph()).build(); +// NavigationUI.setupWithNavController(toolbar, navController, appBarConfiguration); +// } +// +// @Override +// public void onDestinationChanged(@NonNull final NavController controller, +// @NonNull final NavDestination destination, +// @Nullable final Bundle arguments) { +// switch (destination.getId()) { +// case R.id.directMessagesInboxFragment: +// setToolbarTitle(R.string.action_dms); +// dmInfo.setVisibility(View.GONE); +// dmSeen.setVisibility(View.GONE); +// return; +// case R.id.directMessagesThreadFragment: +// if (arguments == null) { +// return; +// } +// final String title = DirectMessageThreadFragmentArgs.fromBundle(arguments).getTitle(); +// setToolbarTitle(title); +// dmInfo.setVisibility(View.VISIBLE); +// dmSeen.setVisibility(settingsHelper.getBoolean(Constants.DM_MARK_AS_SEEN) ? View.GONE : View.VISIBLE); +// return; +// case R.id.directMessagesSettingsFragment: +// if (arguments == null) { +// return; +// } +// setToolbarTitle(R.string.action_settings); +// dmInfo.setVisibility(View.GONE); +// dmSeen.setVisibility(View.GONE); +// return; +// } +// } +// +// private void setToolbarTitle(final String text) { +// if (toolbarTitle == null) { +// return; +// } +// toolbarTitle.setText(text); +// } +// +// private void setToolbarTitle(final int resourceId) { +// if (toolbarTitle == null) { +// return; +// } +// toolbarTitle.setText(resourceId); +// } +// } diff --git a/app/src/main/java/awais/instagrabber/activities/MainActivity.java b/app/src/main/java/awais/instagrabber/activities/MainActivity.java index 59d19395..3c90f0f9 100644 --- a/app/src/main/java/awais/instagrabber/activities/MainActivity.java +++ b/app/src/main/java/awais/instagrabber/activities/MainActivity.java @@ -50,7 +50,8 @@ public class MainActivity extends BaseLanguageActivity { R.id.locationFragment, R.id.savedViewerFragment, R.id.commentsViewerFragment, - R.id.followViewerFragment); + R.id.followViewerFragment, + R.id.directMessagesSettingsFragment); private static final List REMOVE_COLLAPSING_TOOLBAR_SCROLL_DESTINATIONS = Collections.singletonList(R.id.commentsViewerFragment); private ActivityMainBinding binding; private LiveData currentNavControllerLiveData; diff --git a/app/src/main/java/awais/instagrabber/activities/MainActivityBackup.java b/app/src/main/java/awais/instagrabber/activities/MainActivityBackup.java index 40ac667f..0a4cb8f6 100644 --- a/app/src/main/java/awais/instagrabber/activities/MainActivityBackup.java +++ b/app/src/main/java/awais/instagrabber/activities/MainActivityBackup.java @@ -1,607 +1,607 @@ -package awais.instagrabber.activities; - -import android.app.Notification; -import android.app.PendingIntent; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.res.Resources; -import android.database.MatrixCursor; -import android.os.AsyncTask; -import android.os.Bundle; -import android.os.Handler; -import android.os.PersistableBundle; -import android.provider.BaseColumns; -import android.text.TextUtils; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.ArrayAdapter; -import android.widget.AutoCompleteTextView; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.widget.SearchView; -import androidx.core.app.NotificationCompat; -import androidx.fragment.app.FragmentManager; -import androidx.recyclerview.widget.GridLayoutManager; - -import java.util.ArrayList; -import java.util.List; -import java.util.Stack; - -import awais.instagrabber.MainHelper; -import awais.instagrabber.R; -import awais.instagrabber.adapters.HighlightsAdapter; -import awais.instagrabber.adapters.SuggestionsAdapter; -import awais.instagrabber.asyncs.GetActivityAsyncTask; -import awais.instagrabber.asyncs.SuggestionsFetcher; -import awais.instagrabber.asyncs.UsernameFetcher; -import awais.instagrabber.asyncs.i.iStoryStatusFetcher; -import awais.instagrabber.customviews.MouseDrawer; -import awais.instagrabber.databinding.ActivityMainbackupBinding; -import awais.instagrabber.dialogs.AboutDialog; -import awais.instagrabber.dialogs.QuickAccessDialog; -import awais.instagrabber.dialogs.SettingsDialog; -import awais.instagrabber.interfaces.FetchListener; -import awais.instagrabber.interfaces.ItemGetter; -import awais.instagrabber.models.DiscoverItemModel; -import awais.instagrabber.models.FeedModel; -import awais.instagrabber.models.HashtagModel; -import awais.instagrabber.models.HighlightModel; -import awais.instagrabber.models.LocationModel; -import awais.instagrabber.models.PostModel; -import awais.instagrabber.models.ProfileModel; -import awais.instagrabber.models.StoryModel; -import awais.instagrabber.models.SuggestionModel; -import awais.instagrabber.models.enums.DownloadMethod; -import awais.instagrabber.models.enums.PostItemType; -import awais.instagrabber.models.enums.SuggestionType; -import awais.instagrabber.utils.Constants; -import awais.instagrabber.utils.DataBox; -import awais.instagrabber.utils.FlavorTown; -import awais.instagrabber.utils.Utils; - -import static awais.instagrabber.utils.Utils.CHANNEL_ID; -import static awais.instagrabber.utils.Utils.notificationManager; -import static awais.instagrabber.utils.Utils.settingsHelper; - -@Deprecated -public final class MainActivityBackup extends BaseLanguageActivity { - private static final int INITIAL_DELAY_MILLIS = 200; - private static final int DELAY_MILLIS = 60000; - public static FetchListener scanHack; - public static ItemGetter itemGetter; - - public final ArrayList allItems = new ArrayList<>(); - public final ArrayList feedItems = new ArrayList<>(); - public final ArrayList discoverItems = new ArrayList<>(); - public final ArrayList selectedItems = new ArrayList<>(); - public final ArrayList selectedDiscoverItems = new ArrayList<>(); - - public final HighlightsAdapter highlightsAdapter = new HighlightsAdapter(null, new View.OnClickListener() { - @Override - public void onClick(final View v) { - final Object tag = v.getTag(); - if (tag instanceof HighlightModel) { - final HighlightModel highlightModel = (HighlightModel) tag; - new iStoryStatusFetcher(highlightModel.getId(), null, false, false, - (!isLoggedIn && Utils.settingsHelper.getBoolean(Constants.STORIESIG)), true, result -> { - if (result != null && result.length > 0) { - // startActivity(new Intent(MainActivityBackup.this, StoryViewer.class) - // .putExtra(Constants.EXTRAS_USERNAME, userQuery.replace("@", "")) - // .putExtra(Constants.EXTRAS_HIGHLIGHT, highlightModel.getTitle()) - // .putExtra(Constants.EXTRAS_STORIES, result) - // ); - } else - Toast.makeText(MainActivityBackup.this, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); - }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - } - }); - - private SuggestionsAdapter suggestionAdapter; - private MenuItem searchAction; - public @NonNull - ActivityMainbackupBinding mainBinding; - public SearchView searchView; - public MenuItem downloadAction, settingsAction, dmsAction, notifAction; - public StoryModel[] storyModels; - public String userQuery = null, cookie, uid = null; - public MainHelper mainHelper; - public ProfileModel profileModel; - public HashtagModel hashtagModel; - public LocationModel locationModel; - private AutoCompleteTextView searchAutoComplete; - private ArrayAdapter profileDialogAdapter; - private DialogInterface.OnClickListener profileDialogListener; - private Stack queriesStack; - private DataBox.CookieModel cookieModel; - private Runnable runnable; - private Handler handler; - private boolean isLoggedIn; - - @Override - protected void onCreate(@Nullable final Bundle bundle) { - super.onCreate(bundle); - mainBinding = ActivityMainbackupBinding.inflate(getLayoutInflater()); - setContentView(mainBinding.getRoot()); - - if (settingsHelper.getBoolean(Constants.CHECK_UPDATES)) FlavorTown.updateCheck(this); - FlavorTown.changelogCheck(this); - - cookie = settingsHelper.getString(Constants.COOKIE); - uid = Utils.getUserIdFromCookie(cookie); - Utils.setupCookies(cookie); - - MainHelper.stopCurrentExecutor(); - mainHelper = new MainHelper(this); - if (bundle == null) { - queriesStack = new Stack<>(); - userQuery = null; - } else { - setStack(bundle); - userQuery = bundle.getString("query"); - } - isLoggedIn = !Utils.isEmpty(cookie) && Utils.getUserIdFromCookie(cookie) != null; - - itemGetter = itemGetType -> { - if (itemGetType == PostItemType.MAIN) return allItems; - if (itemGetType == PostItemType.DISCOVER) return discoverItems; - if (itemGetType == PostItemType.FEED) return feedItems; - return null; - }; - - scanHack = result -> { - if (mainHelper != null && !Utils.isEmpty(result)) { - closeAnyOpenDrawer(); - addToStack(); - userQuery = (result.contains("/") || result.startsWith("#") || result.startsWith("@")) ? result : ("@" + result); - mainHelper.onRefresh(); - } - }; - - // searches for your userid and returns username - if (uid != null) { - final FetchListener fetchListener = username -> { - if (!Utils.isEmpty(username)) { - // if (!BuildConfig.DEBUG) { - userQuery = username; - if (mainHelper != null && !mainBinding.profileView.swipeRefreshLayout.isRefreshing()) - mainHelper.onRefresh(); - // } - // adds cookies to database for quick access - cookieModel = Utils.dataBox.getCookie(uid); - if (Utils.dataBox.getCookieCount() == 0 || cookieModel == null || Utils.isEmpty(cookieModel.getUsername())) - Utils.dataBox.addUserCookie(new DataBox.CookieModel(uid, username, cookie)); - } - }; - boolean found = false; - cookieModel = Utils.dataBox.getCookie(uid); - if (cookieModel != null) { - final String username = cookieModel.getUsername(); - if (username != null) { - found = true; - fetchListener.onResult("@" + username); - } - } - - if (!found) // if not in database, fetch info from instagram - new UsernameFetcher(uid, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - suggestionAdapter = new SuggestionsAdapter(this, v -> { - final Object tag = v.getTag(); - if (tag instanceof CharSequence) { - addToStack(); - userQuery = tag.toString(); - mainHelper.onRefresh(); - } - if (searchView != null && !searchView.isIconified()) { - if (searchAction != null) searchAction.collapseActionView(); - searchView.setIconified(true); - searchView.setIconified(true); - } - }); - - final Resources resources = getResources(); - profileDialogAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, - new String[]{resources.getString(R.string.view_pfp), resources.getString(R.string.show_stories)}); - profileDialogListener = (dialog, which) -> { - final Intent intent; - if (which == 0 || storyModels == null || storyModels.length < 1) { - intent = new Intent(this, ProfilePicViewer.class).putExtra( - ((hashtagModel != null) ? Constants.EXTRAS_HASHTAG : (locationModel != null ? Constants.EXTRAS_LOCATION : Constants.EXTRAS_PROFILE)), - ((hashtagModel != null) ? hashtagModel : (locationModel != null ? locationModel : profileModel))); - } else { - // intent = new Intent(this, StoryViewer.class).putExtra(Constants.EXTRAS_USERNAME, userQuery.replace("@", "")) - // .putExtra(Constants.EXTRAS_STORIES, storyModels) - // .putExtra(Constants.EXTRAS_HASHTAG, (hashtagModel != null)); - } - // startActivity(intent); - }; - - final View.OnClickListener onClickListener = v -> { - if (v == mainBinding.profileView.mainBiography) { - Utils.copyText(this, mainBinding.profileView.mainBiography.getText().toString()); - } else if (v == mainBinding.profileView.locationBiography) { - Utils.copyText(this, mainBinding.profileView.locationBiography.getText().toString()); - } else if (v == mainBinding.profileView.mainProfileImage || v == mainBinding.profileView.mainHashtagImage || v == mainBinding.profileView.mainLocationImage) { - if (storyModels == null || storyModels.length <= 0) { - profileDialogListener.onClick(null, 0); - } else { - // because sometimes configuration changes made this crash on some phones - new AlertDialog.Builder(this).setAdapter(profileDialogAdapter, profileDialogListener) - .setNeutralButton(R.string.cancel, null).show(); - } - } - }; - - mainBinding.profileView.mainBiography.setOnClickListener(onClickListener); - mainBinding.profileView.locationBiography.setOnClickListener(onClickListener); - mainBinding.profileView.mainProfileImage.setOnClickListener(onClickListener); - mainBinding.profileView.mainHashtagImage.setOnClickListener(onClickListener); - mainBinding.profileView.mainLocationImage.setOnClickListener(onClickListener); - - mainBinding.profileView.mainBiography.setEnabled(false); - mainBinding.profileView.mainProfileImage.setEnabled(false); - mainBinding.profileView.mainHashtagImage.setEnabled(false); - mainBinding.profileView.mainLocationImage.setEnabled(false); - - final boolean isQueryNull = userQuery == null; - if (isQueryNull) { - allItems.clear(); - mainBinding.profileView.privatePage1.setImageResource(R.drawable.ic_outline_info_24); - mainBinding.profileView.privatePage2.setTextSize(20); - mainBinding.profileView.privatePage2.setText(isLoggedIn ? R.string.no_acc_logged_in : R.string.no_acc); - mainBinding.profileView.privatePage.setVisibility(View.VISIBLE); - } - if (!mainBinding.profileView.swipeRefreshLayout.isRefreshing() && userQuery != null) - mainHelper.onRefresh(); - - mainHelper.onIntent(getIntent()); - - handler = new Handler(); - runnable = () -> { - final GetActivityAsyncTask activityAsyncTask = new GetActivityAsyncTask(uid, cookie, result -> { - if (result == null || notificationManager == null) { - return; - } - final List list = new ArrayList<>(); - if (result.getRelationshipsCount() != 0) { - list.add(getString(R.string.activity_count_relationship, result.getRelationshipsCount())); - } - if (result.getUserTagsCount() != 0) { - list.add(getString(R.string.activity_count_usertags, result.getUserTagsCount())); - } - if (result.getCommentsCount() != 0) { - list.add(getString(R.string.activity_count_comments, result.getCommentsCount())); - } - if (result.getCommentLikesCount() != 0) { - list.add(getString(R.string.activity_count_commentlikes, result.getCommentLikesCount())); - } - if (result.getLikesCount() != 0) { - list.add(getString(R.string.activity_count_likes, result.getLikesCount())); - } - if (list.isEmpty()) { - return; - } - final String join = TextUtils.join(", ", list); - final String notificationString = getString(R.string.activity_count_prefix) + " " + join + "."; - final Intent intent = new Intent(getApplicationContext(), NotificationsViewer.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - final Notification notification = new NotificationCompat.Builder(MainActivityBackup.this, CHANNEL_ID) - .setCategory(NotificationCompat.CATEGORY_STATUS) - .setSmallIcon(R.drawable.ic_notif) - .setAutoCancel(true) - .setPriority(NotificationCompat.PRIORITY_MIN) - .setContentText(notificationString) - .setContentIntent(PendingIntent.getActivity(getApplicationContext(), 1738, intent, PendingIntent.FLAG_UPDATE_CURRENT)) - .build(); - notificationManager.cancel(1800000000); - notificationManager.notify(1800000000, notification); - }); - activityAsyncTask.execute(); - if (!Utils.isEmpty(cookie) && Utils.settingsHelper.getBoolean(Constants.CHECK_ACTIVITY)) - activityAsyncTask.execute(); - handler.postDelayed(runnable, DELAY_MILLIS); - }; - handler.postDelayed(runnable, INITIAL_DELAY_MILLIS); - } - - private void downloadSelectedItems() { - if (selectedItems.size() > 0) { - Utils.batchDownload(this, userQuery, DownloadMethod.DOWNLOAD_MAIN, selectedItems); - } else if (selectedDiscoverItems.size() > 0) { - Utils.batchDownload(this, null, DownloadMethod.DOWNLOAD_DISCOVER, selectedDiscoverItems); - } - } - - @Override - protected void onNewIntent(final Intent intent) { - super.onNewIntent(intent); - mainHelper.onIntent(intent); - } - - @Override - public void onSaveInstanceState(@NonNull final Bundle outState, @NonNull final PersistableBundle outPersistentState) { - outState.putString("query", userQuery); - outState.putSerializable("stack", queriesStack); - super.onSaveInstanceState(outState, outPersistentState); - } - - @Override - public void onRestoreInstanceState(@Nullable final Bundle savedInstanceState, @Nullable final PersistableBundle persistentState) { - super.onRestoreInstanceState(savedInstanceState, persistentState); - if (savedInstanceState != null) { - userQuery = savedInstanceState.getString("query"); - setStack(savedInstanceState); - } - } - - @Override - protected void onSaveInstanceState(@NonNull final Bundle outState) { - outState.putString("query", userQuery); - outState.putSerializable("stack", queriesStack); - super.onSaveInstanceState(outState); - } - - @Override - protected void onRestoreInstanceState(@NonNull final Bundle savedInstanceState) { - super.onRestoreInstanceState(savedInstanceState); - userQuery = savedInstanceState.getString("query"); - setStack(savedInstanceState); - } - - @Override - public boolean onCreateOptionsMenu(final Menu menu) { - getMenuInflater().inflate(R.menu.menu, menu); - - final FragmentManager fragmentManager = getSupportFragmentManager(); - final MenuItem quickAccessAction = menu.findItem(R.id.action_quickaccess).setVisible(true); - - final MenuItem.OnMenuItemClickListener clickListener = item -> { - if (item == downloadAction) - downloadSelectedItems(); - else if (item == dmsAction) - startActivity(new Intent(this, DirectMessagesActivity.class)); - else if (item == notifAction) - startActivity(new Intent(this, NotificationsViewer.class)); - else if (item == settingsAction) - new SettingsDialog().show(fragmentManager, "settings"); - else if (item == quickAccessAction) - new QuickAccessDialog() - .setQuery(userQuery, locationModel != null ? locationModel.getName() : userQuery) - .show(fragmentManager, "quickAccess"); - else - new AboutDialog().show(fragmentManager, "about"); - return true; - }; - - quickAccessAction.setOnMenuItemClickListener(clickListener); - menu.findItem(R.id.action_about).setVisible(true).setOnMenuItemClickListener(clickListener); - dmsAction = menu.findItem(R.id.action_dms).setOnMenuItemClickListener(clickListener); - notifAction = menu.findItem(R.id.action_notif).setOnMenuItemClickListener(clickListener); - settingsAction = menu.findItem(R.id.action_settings).setVisible(true).setOnMenuItemClickListener(clickListener); - downloadAction = menu.findItem(R.id.action_download).setOnMenuItemClickListener(clickListener); - - if (!Utils.isEmpty(Utils.settingsHelper.getString(Constants.COOKIE))) { - notifAction.setVisible(true); - dmsAction.setVisible(true).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); - } - - searchAction = menu.findItem(R.id.action_search); - searchView = (SearchView) searchAction.getActionView(); - final View searchText = searchView.findViewById(R.id.search_src_text); - if (searchText instanceof AutoCompleteTextView) - searchAutoComplete = (AutoCompleteTextView) searchText; - - searchView.setQueryHint(getResources().getString(R.string.action_search)); - searchView.setSuggestionsAdapter(suggestionAdapter); - searchView.setOnSearchClickListener(v -> { - searchView.setQuery((cookieModel != null && userQuery != null && userQuery.equals("@" + cookieModel.getUsername())) ? "" : userQuery, false); - menu.findItem(R.id.action_about).setVisible(false); - menu.findItem(R.id.action_settings).setVisible(false); - menu.findItem(R.id.action_dms).setVisible(false); - menu.findItem(R.id.action_quickaccess).setVisible(false); - menu.findItem(R.id.action_notif).setVisible(false); - }); - searchAction.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { - @Override - public boolean onMenuItemActionExpand(MenuItem item) { - return true; - } - - @Override - public boolean onMenuItemActionCollapse(MenuItem item) { - menu.findItem(R.id.action_about).setVisible(true); - menu.findItem(R.id.action_settings).setVisible(true); - menu.findItem(R.id.action_dms).setVisible(!Utils.isEmpty(Utils.settingsHelper.getString(Constants.COOKIE))); - menu.findItem(R.id.action_quickaccess).setVisible(true); - menu.findItem(R.id.action_notif).setVisible(true); - return true; - } - }); - searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { - private boolean searchUser, searchHash; - private AsyncTask prevSuggestionAsync; - private final String[] COLUMNS = {BaseColumns._ID, Constants.EXTRAS_USERNAME, Constants.EXTRAS_NAME, - Constants.EXTRAS_TYPE, "pfp", "verified"}; - private final FetchListener fetchListener = new FetchListener() { - @Override - public void doBefore() { - suggestionAdapter.changeCursor(null); - } - - @Override - public void onResult(final SuggestionModel[] result) { - final MatrixCursor cursor; - if (result == null) cursor = null; - else { - cursor = new MatrixCursor(COLUMNS, 0); - for (int i = 0; i < result.length; i++) { - final SuggestionModel suggestionModel = result[i]; - if (suggestionModel != null) { - final SuggestionType suggestionType = suggestionModel.getSuggestionType(); - final Object[] objects = {i, - (suggestionType == SuggestionType.TYPE_LOCATION) ? suggestionModel.getName() : suggestionModel.getUsername(), - (suggestionType == SuggestionType.TYPE_LOCATION) ? suggestionModel.getUsername() : suggestionModel.getName(), - suggestionType, suggestionModel.getProfilePic(), suggestionModel.isVerified()}; - - if (!searchHash && !searchUser) cursor.addRow(objects); - else { - final boolean isCurrHash = suggestionType == SuggestionType.TYPE_HASHTAG; - if (searchHash && isCurrHash || !searchHash && !isCurrHash) - cursor.addRow(objects); - } - } - } - } - suggestionAdapter.changeCursor(cursor); - } - }; - - private void cancelSuggestionsAsync() { - if (prevSuggestionAsync != null) - try { - prevSuggestionAsync.cancel(true); - } catch (final Exception ignored) { - } - } - - @Override - public boolean onQueryTextSubmit(final String query) { - cancelSuggestionsAsync(); - menu.findItem(R.id.action_about).setVisible(true); - menu.findItem(R.id.action_settings).setVisible(true); - - closeAnyOpenDrawer(); - addToStack(); - userQuery = (query.contains("@") || query.contains("#")) ? query : ("@" + query); - searchAction.collapseActionView(); - searchView.setIconified(true); - searchView.setIconified(true); - mainHelper.onRefresh(); - return false; - } - - @Override - public boolean onQueryTextChange(final String newText) { - cancelSuggestionsAsync(); - - if (!Utils.isEmpty(newText)) { - searchUser = newText.charAt(0) == '@'; - searchHash = newText.charAt(0) == '#'; - - if (newText.length() == 1 && (searchHash || searchUser)) { - if (searchAutoComplete != null) searchAutoComplete.setThreshold(2); - } else { - if (searchAutoComplete != null) searchAutoComplete.setThreshold(1); - prevSuggestionAsync = new SuggestionsFetcher(fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, - searchUser || searchHash ? newText.substring(1) : newText); - } - } - return true; - } - }); - - return true; - } - - @Override - public void onBackPressed() { - if (closeAnyOpenDrawer()) return; - - if (searchView != null && !searchView.isIconified()) { - if (searchAction != null) searchAction.collapseActionView(); - searchView.setIconified(true); - searchView.setIconified(true); - return; - } - - if (!mainHelper.isSelectionCleared()) return; - - final GridLayoutManager layoutManager = (GridLayoutManager) mainBinding.profileView.mainPosts.getLayoutManager(); - if (layoutManager != null && layoutManager.findFirstCompletelyVisibleItemPosition() >= layoutManager.getSpanCount()) { - mainBinding.profileView.mainPosts.smoothScrollToPosition(0); - mainBinding.profileView.appBarLayout.setExpanded(true, true); - return; - } - - if (queriesStack != null && queriesStack.size() > 0) { - userQuery = queriesStack.pop(); - if (userQuery != null) { - mainHelper.onRefresh(); - return; - } - } else { - finish(); - } - } - - @Override - public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults); - if (requestCode == 8020 && grantResults[0] == PackageManager.PERMISSION_GRANTED) - downloadSelectedItems(); - } - - @Override - protected void onActivityResult(final int requestCode, final int resultCode, @Nullable final Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (requestCode == 9629 && (resultCode == 1692 || resultCode == RESULT_CANCELED)) - finish(); - else if (requestCode == 6007) - Utils.showImportExportDialog(this); - // else if (requestCode == 6969 && mainHelper.currentFeedPlayer != null) - // mainHelper.currentFeedPlayer.setPlayWhenReady(true); - } - - @Override - protected void onPause() { - if (mainHelper != null) mainHelper.onPause(); - if (handler != null && runnable != null) { - handler.removeCallbacks(runnable); - } - super.onPause(); - } - - @Override - protected void onResume() { - if (mainHelper != null) mainHelper.onResume(); - if (handler != null && runnable != null) { - handler.postDelayed(runnable, INITIAL_DELAY_MILLIS); - } - super.onResume(); - } - - private void setStack(final Bundle bundle) { - final Object stack = bundle != null ? bundle.get("stack") : null; - if (stack instanceof Stack) //noinspection unchecked - queriesStack = (Stack) stack; - } - - public void addToStack() { - if (userQuery != null) { - if (queriesStack == null) queriesStack = new Stack<>(); - queriesStack.add(userQuery); - } - } - - private boolean closeAnyOpenDrawer() { - final int childCount = mainBinding.drawerLayout.getChildCount(); - for (int i = 0; i < childCount; i++) { - final View child = mainBinding.drawerLayout.getChildAt(i); - final MouseDrawer.LayoutParams childLp = (MouseDrawer.LayoutParams) child.getLayoutParams(); - - if ((childLp.openState & MouseDrawer.LayoutParams.FLAG_IS_OPENED) == 1 || - (childLp.openState & MouseDrawer.LayoutParams.FLAG_IS_OPENING) == 2 || - childLp.onScreen >= 0.6 || childLp.isPeeking) { - mainBinding.drawerLayout.closeDrawer(child); - return true; - } - } - return false; - } -} \ No newline at end of file +// package awais.instagrabber.activities; +// +// import android.app.Notification; +// import android.app.PendingIntent; +// import android.content.DialogInterface; +// import android.content.Intent; +// import android.content.pm.PackageManager; +// import android.content.res.Resources; +// import android.database.MatrixCursor; +// import android.os.AsyncTask; +// import android.os.Bundle; +// import android.os.Handler; +// import android.os.PersistableBundle; +// import android.provider.BaseColumns; +// import android.text.TextUtils; +// import android.view.Menu; +// import android.view.MenuItem; +// import android.view.View; +// import android.widget.ArrayAdapter; +// import android.widget.AutoCompleteTextView; +// import android.widget.Toast; +// +// import androidx.annotation.NonNull; +// import androidx.annotation.Nullable; +// import androidx.appcompat.app.AlertDialog; +// import androidx.appcompat.widget.SearchView; +// import androidx.core.app.NotificationCompat; +// import androidx.fragment.app.FragmentManager; +// import androidx.recyclerview.widget.GridLayoutManager; +// +// import java.util.ArrayList; +// import java.util.List; +// import java.util.Stack; +// +// import awais.instagrabber.MainHelper; +// import awais.instagrabber.R; +// import awais.instagrabber.adapters.HighlightsAdapter; +// import awais.instagrabber.adapters.SuggestionsAdapter; +// import awais.instagrabber.asyncs.GetActivityAsyncTask; +// import awais.instagrabber.asyncs.SuggestionsFetcher; +// import awais.instagrabber.asyncs.UsernameFetcher; +// import awais.instagrabber.asyncs.i.iStoryStatusFetcher; +// import awais.instagrabber.customviews.MouseDrawer; +// import awais.instagrabber.databinding.ActivityMainbackupBinding; +// import awais.instagrabber.dialogs.AboutDialog; +// import awais.instagrabber.dialogs.QuickAccessDialog; +// import awais.instagrabber.dialogs.SettingsDialog; +// import awais.instagrabber.interfaces.FetchListener; +// import awais.instagrabber.interfaces.ItemGetter; +// import awais.instagrabber.models.DiscoverItemModel; +// import awais.instagrabber.models.FeedModel; +// import awais.instagrabber.models.HashtagModel; +// import awais.instagrabber.models.HighlightModel; +// import awais.instagrabber.models.LocationModel; +// import awais.instagrabber.models.PostModel; +// import awais.instagrabber.models.ProfileModel; +// import awais.instagrabber.models.StoryModel; +// import awais.instagrabber.models.SuggestionModel; +// import awais.instagrabber.models.enums.DownloadMethod; +// import awais.instagrabber.models.enums.PostItemType; +// import awais.instagrabber.models.enums.SuggestionType; +// import awais.instagrabber.utils.Constants; +// import awais.instagrabber.utils.DataBox; +// import awais.instagrabber.utils.FlavorTown; +// import awais.instagrabber.utils.Utils; +// +// import static awais.instagrabber.utils.Utils.CHANNEL_ID; +// import static awais.instagrabber.utils.Utils.notificationManager; +// import static awais.instagrabber.utils.Utils.settingsHelper; +// +// @Deprecated +// public final class MainActivityBackup extends BaseLanguageActivity { +// private static final int INITIAL_DELAY_MILLIS = 200; +// private static final int DELAY_MILLIS = 60000; +// public static FetchListener scanHack; +// public static ItemGetter itemGetter; +// +// public final ArrayList allItems = new ArrayList<>(); +// public final ArrayList feedItems = new ArrayList<>(); +// public final ArrayList discoverItems = new ArrayList<>(); +// public final ArrayList selectedItems = new ArrayList<>(); +// public final ArrayList selectedDiscoverItems = new ArrayList<>(); +// +// public final HighlightsAdapter highlightsAdapter = new HighlightsAdapter(null, new View.OnClickListener() { +// @Override +// public void onClick(final View v) { +// final Object tag = v.getTag(); +// if (tag instanceof HighlightModel) { +// final HighlightModel highlightModel = (HighlightModel) tag; +// new iStoryStatusFetcher(highlightModel.getId(), null, false, false, +// (!isLoggedIn && Utils.settingsHelper.getBoolean(Constants.STORIESIG)), true, result -> { +// if (result != null && result.length > 0) { +// // startActivity(new Intent(MainActivityBackup.this, StoryViewer.class) +// // .putExtra(Constants.EXTRAS_USERNAME, userQuery.replace("@", "")) +// // .putExtra(Constants.EXTRAS_HIGHLIGHT, highlightModel.getTitle()) +// // .putExtra(Constants.EXTRAS_STORIES, result) +// // ); +// } else +// Toast.makeText(MainActivityBackup.this, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); +// }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } +// } +// }); +// +// private SuggestionsAdapter suggestionAdapter; +// private MenuItem searchAction; +// public @NonNull +// ActivityMainbackupBinding mainBinding; +// public SearchView searchView; +// public MenuItem downloadAction, settingsAction, dmsAction, notifAction; +// public StoryModel[] storyModels; +// public String userQuery = null, cookie, uid = null; +// public MainHelper mainHelper; +// public ProfileModel profileModel; +// public HashtagModel hashtagModel; +// public LocationModel locationModel; +// private AutoCompleteTextView searchAutoComplete; +// private ArrayAdapter profileDialogAdapter; +// private DialogInterface.OnClickListener profileDialogListener; +// private Stack queriesStack; +// private DataBox.CookieModel cookieModel; +// private Runnable runnable; +// private Handler handler; +// private boolean isLoggedIn; +// +// @Override +// protected void onCreate(@Nullable final Bundle bundle) { +// super.onCreate(bundle); +// mainBinding = ActivityMainbackupBinding.inflate(getLayoutInflater()); +// setContentView(mainBinding.getRoot()); +// +// if (settingsHelper.getBoolean(Constants.CHECK_UPDATES)) FlavorTown.updateCheck(this); +// FlavorTown.changelogCheck(this); +// +// cookie = settingsHelper.getString(Constants.COOKIE); +// uid = Utils.getUserIdFromCookie(cookie); +// Utils.setupCookies(cookie); +// +// MainHelper.stopCurrentExecutor(); +// mainHelper = new MainHelper(this); +// if (bundle == null) { +// queriesStack = new Stack<>(); +// userQuery = null; +// } else { +// setStack(bundle); +// userQuery = bundle.getString("query"); +// } +// isLoggedIn = !Utils.isEmpty(cookie) && Utils.getUserIdFromCookie(cookie) != null; +// +// itemGetter = itemGetType -> { +// if (itemGetType == PostItemType.MAIN) return allItems; +// if (itemGetType == PostItemType.DISCOVER) return discoverItems; +// if (itemGetType == PostItemType.FEED) return feedItems; +// return null; +// }; +// +// scanHack = result -> { +// if (mainHelper != null && !Utils.isEmpty(result)) { +// closeAnyOpenDrawer(); +// addToStack(); +// userQuery = (result.contains("/") || result.startsWith("#") || result.startsWith("@")) ? result : ("@" + result); +// mainHelper.onRefresh(); +// } +// }; +// +// // searches for your userid and returns username +// if (uid != null) { +// final FetchListener fetchListener = username -> { +// if (!Utils.isEmpty(username)) { +// // if (!BuildConfig.DEBUG) { +// userQuery = username; +// if (mainHelper != null && !mainBinding.profileView.swipeRefreshLayout.isRefreshing()) +// mainHelper.onRefresh(); +// // } +// // adds cookies to database for quick access +// cookieModel = Utils.dataBox.getCookie(uid); +// if (Utils.dataBox.getCookieCount() == 0 || cookieModel == null || Utils.isEmpty(cookieModel.getUsername())) +// Utils.dataBox.addUserCookie(new DataBox.CookieModel(uid, username, cookie)); +// } +// }; +// boolean found = false; +// cookieModel = Utils.dataBox.getCookie(uid); +// if (cookieModel != null) { +// final String username = cookieModel.getUsername(); +// if (username != null) { +// found = true; +// fetchListener.onResult("@" + username); +// } +// } +// +// if (!found) // if not in database, fetch info from instagram +// new UsernameFetcher(uid, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } +// +// suggestionAdapter = new SuggestionsAdapter(this, v -> { +// final Object tag = v.getTag(); +// if (tag instanceof CharSequence) { +// addToStack(); +// userQuery = tag.toString(); +// mainHelper.onRefresh(); +// } +// if (searchView != null && !searchView.isIconified()) { +// if (searchAction != null) searchAction.collapseActionView(); +// searchView.setIconified(true); +// searchView.setIconified(true); +// } +// }); +// +// final Resources resources = getResources(); +// profileDialogAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, +// new String[]{resources.getString(R.string.view_pfp), resources.getString(R.string.show_stories)}); +// profileDialogListener = (dialog, which) -> { +// final Intent intent; +// if (which == 0 || storyModels == null || storyModels.length < 1) { +// intent = new Intent(this, ProfilePicViewer.class).putExtra( +// ((hashtagModel != null) ? Constants.EXTRAS_HASHTAG : (locationModel != null ? Constants.EXTRAS_LOCATION : Constants.EXTRAS_PROFILE)), +// ((hashtagModel != null) ? hashtagModel : (locationModel != null ? locationModel : profileModel))); +// } else { +// // intent = new Intent(this, StoryViewer.class).putExtra(Constants.EXTRAS_USERNAME, userQuery.replace("@", "")) +// // .putExtra(Constants.EXTRAS_STORIES, storyModels) +// // .putExtra(Constants.EXTRAS_HASHTAG, (hashtagModel != null)); +// } +// // startActivity(intent); +// }; +// +// final View.OnClickListener onClickListener = v -> { +// if (v == mainBinding.profileView.mainBiography) { +// Utils.copyText(this, mainBinding.profileView.mainBiography.getText().toString()); +// } else if (v == mainBinding.profileView.locationBiography) { +// Utils.copyText(this, mainBinding.profileView.locationBiography.getText().toString()); +// } else if (v == mainBinding.profileView.mainProfileImage || v == mainBinding.profileView.mainHashtagImage || v == mainBinding.profileView.mainLocationImage) { +// if (storyModels == null || storyModels.length <= 0) { +// profileDialogListener.onClick(null, 0); +// } else { +// // because sometimes configuration changes made this crash on some phones +// new AlertDialog.Builder(this).setAdapter(profileDialogAdapter, profileDialogListener) +// .setNeutralButton(R.string.cancel, null).show(); +// } +// } +// }; +// +// mainBinding.profileView.mainBiography.setOnClickListener(onClickListener); +// mainBinding.profileView.locationBiography.setOnClickListener(onClickListener); +// mainBinding.profileView.mainProfileImage.setOnClickListener(onClickListener); +// mainBinding.profileView.mainHashtagImage.setOnClickListener(onClickListener); +// mainBinding.profileView.mainLocationImage.setOnClickListener(onClickListener); +// +// mainBinding.profileView.mainBiography.setEnabled(false); +// mainBinding.profileView.mainProfileImage.setEnabled(false); +// mainBinding.profileView.mainHashtagImage.setEnabled(false); +// mainBinding.profileView.mainLocationImage.setEnabled(false); +// +// final boolean isQueryNull = userQuery == null; +// if (isQueryNull) { +// allItems.clear(); +// mainBinding.profileView.privatePage1.setImageResource(R.drawable.ic_outline_info_24); +// mainBinding.profileView.privatePage2.setTextSize(20); +// mainBinding.profileView.privatePage2.setText(isLoggedIn ? R.string.no_acc_logged_in : R.string.no_acc); +// mainBinding.profileView.privatePage.setVisibility(View.VISIBLE); +// } +// if (!mainBinding.profileView.swipeRefreshLayout.isRefreshing() && userQuery != null) +// mainHelper.onRefresh(); +// +// mainHelper.onIntent(getIntent()); +// +// handler = new Handler(); +// runnable = () -> { +// final GetActivityAsyncTask activityAsyncTask = new GetActivityAsyncTask(uid, cookie, result -> { +// if (result == null || notificationManager == null) { +// return; +// } +// final List list = new ArrayList<>(); +// if (result.getRelationshipsCount() != 0) { +// list.add(getString(R.string.activity_count_relationship, result.getRelationshipsCount())); +// } +// if (result.getUserTagsCount() != 0) { +// list.add(getString(R.string.activity_count_usertags, result.getUserTagsCount())); +// } +// if (result.getCommentsCount() != 0) { +// list.add(getString(R.string.activity_count_comments, result.getCommentsCount())); +// } +// if (result.getCommentLikesCount() != 0) { +// list.add(getString(R.string.activity_count_commentlikes, result.getCommentLikesCount())); +// } +// if (result.getLikesCount() != 0) { +// list.add(getString(R.string.activity_count_likes, result.getLikesCount())); +// } +// if (list.isEmpty()) { +// return; +// } +// final String join = TextUtils.join(", ", list); +// final String notificationString = getString(R.string.activity_count_prefix) + " " + join + "."; +// final Intent intent = new Intent(getApplicationContext(), NotificationsViewer.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); +// final Notification notification = new NotificationCompat.Builder(MainActivityBackup.this, CHANNEL_ID) +// .setCategory(NotificationCompat.CATEGORY_STATUS) +// .setSmallIcon(R.drawable.ic_notif) +// .setAutoCancel(true) +// .setPriority(NotificationCompat.PRIORITY_MIN) +// .setContentText(notificationString) +// .setContentIntent(PendingIntent.getActivity(getApplicationContext(), 1738, intent, PendingIntent.FLAG_UPDATE_CURRENT)) +// .build(); +// notificationManager.cancel(1800000000); +// notificationManager.notify(1800000000, notification); +// }); +// activityAsyncTask.execute(); +// if (!Utils.isEmpty(cookie) && Utils.settingsHelper.getBoolean(Constants.CHECK_ACTIVITY)) +// activityAsyncTask.execute(); +// handler.postDelayed(runnable, DELAY_MILLIS); +// }; +// handler.postDelayed(runnable, INITIAL_DELAY_MILLIS); +// } +// +// private void downloadSelectedItems() { +// if (selectedItems.size() > 0) { +// Utils.batchDownload(this, userQuery, DownloadMethod.DOWNLOAD_MAIN, selectedItems); +// } else if (selectedDiscoverItems.size() > 0) { +// Utils.batchDownload(this, null, DownloadMethod.DOWNLOAD_DISCOVER, selectedDiscoverItems); +// } +// } +// +// @Override +// protected void onNewIntent(final Intent intent) { +// super.onNewIntent(intent); +// mainHelper.onIntent(intent); +// } +// +// @Override +// public void onSaveInstanceState(@NonNull final Bundle outState, @NonNull final PersistableBundle outPersistentState) { +// outState.putString("query", userQuery); +// outState.putSerializable("stack", queriesStack); +// super.onSaveInstanceState(outState, outPersistentState); +// } +// +// @Override +// public void onRestoreInstanceState(@Nullable final Bundle savedInstanceState, @Nullable final PersistableBundle persistentState) { +// super.onRestoreInstanceState(savedInstanceState, persistentState); +// if (savedInstanceState != null) { +// userQuery = savedInstanceState.getString("query"); +// setStack(savedInstanceState); +// } +// } +// +// @Override +// protected void onSaveInstanceState(@NonNull final Bundle outState) { +// outState.putString("query", userQuery); +// outState.putSerializable("stack", queriesStack); +// super.onSaveInstanceState(outState); +// } +// +// @Override +// protected void onRestoreInstanceState(@NonNull final Bundle savedInstanceState) { +// super.onRestoreInstanceState(savedInstanceState); +// userQuery = savedInstanceState.getString("query"); +// setStack(savedInstanceState); +// } +// +// @Override +// public boolean onCreateOptionsMenu(final Menu menu) { +// getMenuInflater().inflate(R.menu.menu, menu); +// +// final FragmentManager fragmentManager = getSupportFragmentManager(); +// final MenuItem quickAccessAction = menu.findItem(R.id.action_quickaccess).setVisible(true); +// +// final MenuItem.OnMenuItemClickListener clickListener = item -> { +// if (item == downloadAction) +// downloadSelectedItems(); +// else if (item == dmsAction) +// startActivity(new Intent(this, DirectMessagesActivity.class)); +// else if (item == notifAction) +// startActivity(new Intent(this, NotificationsViewer.class)); +// else if (item == settingsAction) +// new SettingsDialog().show(fragmentManager, "settings"); +// else if (item == quickAccessAction) +// new QuickAccessDialog() +// .setQuery(userQuery, locationModel != null ? locationModel.getName() : userQuery) +// .show(fragmentManager, "quickAccess"); +// else +// new AboutDialog().show(fragmentManager, "about"); +// return true; +// }; +// +// quickAccessAction.setOnMenuItemClickListener(clickListener); +// menu.findItem(R.id.action_about).setVisible(true).setOnMenuItemClickListener(clickListener); +// dmsAction = menu.findItem(R.id.action_dms).setOnMenuItemClickListener(clickListener); +// notifAction = menu.findItem(R.id.action_notif).setOnMenuItemClickListener(clickListener); +// settingsAction = menu.findItem(R.id.action_settings).setVisible(true).setOnMenuItemClickListener(clickListener); +// downloadAction = menu.findItem(R.id.action_download).setOnMenuItemClickListener(clickListener); +// +// if (!Utils.isEmpty(Utils.settingsHelper.getString(Constants.COOKIE))) { +// notifAction.setVisible(true); +// dmsAction.setVisible(true).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); +// } +// +// searchAction = menu.findItem(R.id.action_search); +// searchView = (SearchView) searchAction.getActionView(); +// final View searchText = searchView.findViewById(R.id.search_src_text); +// if (searchText instanceof AutoCompleteTextView) +// searchAutoComplete = (AutoCompleteTextView) searchText; +// +// searchView.setQueryHint(getResources().getString(R.string.action_search)); +// searchView.setSuggestionsAdapter(suggestionAdapter); +// searchView.setOnSearchClickListener(v -> { +// searchView.setQuery((cookieModel != null && userQuery != null && userQuery.equals("@" + cookieModel.getUsername())) ? "" : userQuery, false); +// menu.findItem(R.id.action_about).setVisible(false); +// menu.findItem(R.id.action_settings).setVisible(false); +// menu.findItem(R.id.action_dms).setVisible(false); +// menu.findItem(R.id.action_quickaccess).setVisible(false); +// menu.findItem(R.id.action_notif).setVisible(false); +// }); +// searchAction.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { +// @Override +// public boolean onMenuItemActionExpand(MenuItem item) { +// return true; +// } +// +// @Override +// public boolean onMenuItemActionCollapse(MenuItem item) { +// menu.findItem(R.id.action_about).setVisible(true); +// menu.findItem(R.id.action_settings).setVisible(true); +// menu.findItem(R.id.action_dms).setVisible(!Utils.isEmpty(Utils.settingsHelper.getString(Constants.COOKIE))); +// menu.findItem(R.id.action_quickaccess).setVisible(true); +// menu.findItem(R.id.action_notif).setVisible(true); +// return true; +// } +// }); +// searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { +// private boolean searchUser, searchHash; +// private AsyncTask prevSuggestionAsync; +// private final String[] COLUMNS = {BaseColumns._ID, Constants.EXTRAS_USERNAME, Constants.EXTRAS_NAME, +// Constants.EXTRAS_TYPE, "pfp", "verified"}; +// private final FetchListener fetchListener = new FetchListener() { +// @Override +// public void doBefore() { +// suggestionAdapter.changeCursor(null); +// } +// +// @Override +// public void onResult(final SuggestionModel[] result) { +// final MatrixCursor cursor; +// if (result == null) cursor = null; +// else { +// cursor = new MatrixCursor(COLUMNS, 0); +// for (int i = 0; i < result.length; i++) { +// final SuggestionModel suggestionModel = result[i]; +// if (suggestionModel != null) { +// final SuggestionType suggestionType = suggestionModel.getSuggestionType(); +// final Object[] objects = {i, +// (suggestionType == SuggestionType.TYPE_LOCATION) ? suggestionModel.getName() : suggestionModel.getUsername(), +// (suggestionType == SuggestionType.TYPE_LOCATION) ? suggestionModel.getUsername() : suggestionModel.getName(), +// suggestionType, suggestionModel.getProfilePic(), suggestionModel.isVerified()}; +// +// if (!searchHash && !searchUser) cursor.addRow(objects); +// else { +// final boolean isCurrHash = suggestionType == SuggestionType.TYPE_HASHTAG; +// if (searchHash && isCurrHash || !searchHash && !isCurrHash) +// cursor.addRow(objects); +// } +// } +// } +// } +// suggestionAdapter.changeCursor(cursor); +// } +// }; +// +// private void cancelSuggestionsAsync() { +// if (prevSuggestionAsync != null) +// try { +// prevSuggestionAsync.cancel(true); +// } catch (final Exception ignored) { +// } +// } +// +// @Override +// public boolean onQueryTextSubmit(final String query) { +// cancelSuggestionsAsync(); +// menu.findItem(R.id.action_about).setVisible(true); +// menu.findItem(R.id.action_settings).setVisible(true); +// +// closeAnyOpenDrawer(); +// addToStack(); +// userQuery = (query.contains("@") || query.contains("#")) ? query : ("@" + query); +// searchAction.collapseActionView(); +// searchView.setIconified(true); +// searchView.setIconified(true); +// mainHelper.onRefresh(); +// return false; +// } +// +// @Override +// public boolean onQueryTextChange(final String newText) { +// cancelSuggestionsAsync(); +// +// if (!Utils.isEmpty(newText)) { +// searchUser = newText.charAt(0) == '@'; +// searchHash = newText.charAt(0) == '#'; +// +// if (newText.length() == 1 && (searchHash || searchUser)) { +// if (searchAutoComplete != null) searchAutoComplete.setThreshold(2); +// } else { +// if (searchAutoComplete != null) searchAutoComplete.setThreshold(1); +// prevSuggestionAsync = new SuggestionsFetcher(fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, +// searchUser || searchHash ? newText.substring(1) : newText); +// } +// } +// return true; +// } +// }); +// +// return true; +// } +// +// @Override +// public void onBackPressed() { +// if (closeAnyOpenDrawer()) return; +// +// if (searchView != null && !searchView.isIconified()) { +// if (searchAction != null) searchAction.collapseActionView(); +// searchView.setIconified(true); +// searchView.setIconified(true); +// return; +// } +// +// if (!mainHelper.isSelectionCleared()) return; +// +// final GridLayoutManager layoutManager = (GridLayoutManager) mainBinding.profileView.mainPosts.getLayoutManager(); +// if (layoutManager != null && layoutManager.findFirstCompletelyVisibleItemPosition() >= layoutManager.getSpanCount()) { +// mainBinding.profileView.mainPosts.smoothScrollToPosition(0); +// mainBinding.profileView.appBarLayout.setExpanded(true, true); +// return; +// } +// +// if (queriesStack != null && queriesStack.size() > 0) { +// userQuery = queriesStack.pop(); +// if (userQuery != null) { +// mainHelper.onRefresh(); +// return; +// } +// } else { +// finish(); +// } +// } +// +// @Override +// public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) { +// super.onRequestPermissionsResult(requestCode, permissions, grantResults); +// if (requestCode == 8020 && grantResults[0] == PackageManager.PERMISSION_GRANTED) +// downloadSelectedItems(); +// } +// +// @Override +// protected void onActivityResult(final int requestCode, final int resultCode, @Nullable final Intent data) { +// super.onActivityResult(requestCode, resultCode, data); +// if (requestCode == 9629 && (resultCode == 1692 || resultCode == RESULT_CANCELED)) +// finish(); +// else if (requestCode == 6007) +// Utils.showImportExportDialog(this); +// // else if (requestCode == 6969 && mainHelper.currentFeedPlayer != null) +// // mainHelper.currentFeedPlayer.setPlayWhenReady(true); +// } +// +// @Override +// protected void onPause() { +// if (mainHelper != null) mainHelper.onPause(); +// if (handler != null && runnable != null) { +// handler.removeCallbacks(runnable); +// } +// super.onPause(); +// } +// +// @Override +// protected void onResume() { +// if (mainHelper != null) mainHelper.onResume(); +// if (handler != null && runnable != null) { +// handler.postDelayed(runnable, INITIAL_DELAY_MILLIS); +// } +// super.onResume(); +// } +// +// private void setStack(final Bundle bundle) { +// final Object stack = bundle != null ? bundle.get("stack") : null; +// if (stack instanceof Stack) //noinspection unchecked +// queriesStack = (Stack) stack; +// } +// +// public void addToStack() { +// if (userQuery != null) { +// if (queriesStack == null) queriesStack = new Stack<>(); +// queriesStack.add(userQuery); +// } +// } +// +// private boolean closeAnyOpenDrawer() { +// final int childCount = mainBinding.drawerLayout.getChildCount(); +// for (int i = 0; i < childCount; i++) { +// final View child = mainBinding.drawerLayout.getChildAt(i); +// final MouseDrawer.LayoutParams childLp = (MouseDrawer.LayoutParams) child.getLayoutParams(); +// +// if ((childLp.openState & MouseDrawer.LayoutParams.FLAG_IS_OPENED) == 1 || +// (childLp.openState & MouseDrawer.LayoutParams.FLAG_IS_OPENING) == 2 || +// childLp.onScreen >= 0.6 || childLp.isPeeking) { +// mainBinding.drawerLayout.closeDrawer(child); +// return true; +// } +// } +// return false; +// } +// } \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/activities/NotificationsViewer.java b/app/src/main/java/awais/instagrabber/activities/NotificationsViewer.java index 50f10bbc..d227154f 100755 --- a/app/src/main/java/awais/instagrabber/activities/NotificationsViewer.java +++ b/app/src/main/java/awais/instagrabber/activities/NotificationsViewer.java @@ -76,9 +76,10 @@ public final class NotificationsViewer extends BaseLanguageActivity implements S final DialogInterface.OnClickListener profileDialogListener = (dialog, which) -> { if (which == 0) searchUsername(notificationModel.getUsername()); - else if (which == 1 && commentDialogList.length == 2) - startActivity(new Intent(getApplicationContext(), PostViewer.class) - .putExtra(Constants.EXTRAS_POST, new PostModel(notificationModel.getShortcode(), false))); + else if (which == 1 && commentDialogList.length == 2) { + // startActivity(new Intent(getApplicationContext(), PostViewer.class) + // .putExtra(Constants.EXTRAS_POST, new PostModel(notificationModel.getShortcode(), false))); + } else if (which == 1) new ProfileAction().execute("/approve/"); else if (which == 2) new ProfileAction().execute("/ignore/"); }; @@ -123,7 +124,7 @@ public final class NotificationsViewer extends BaseLanguageActivity implements S private void searchUsername(final String text) { - startActivity(new Intent(getApplicationContext(), ProfileViewer.class).putExtra(Constants.EXTRAS_USERNAME, text)); + // startActivity(new Intent(getApplicationContext(), ProfileViewer.class).putExtra(Constants.EXTRAS_USERNAME, text)); } class ProfileAction extends AsyncTask { diff --git a/app/src/main/java/awais/instagrabber/activities/PostViewer.java b/app/src/main/java/awais/instagrabber/activities/PostViewer.java index bc47dde0..95c14b7f 100755 --- a/app/src/main/java/awais/instagrabber/activities/PostViewer.java +++ b/app/src/main/java/awais/instagrabber/activities/PostViewer.java @@ -1,786 +1,786 @@ -package awais.instagrabber.activities; - -import android.annotation.SuppressLint; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.res.ColorStateList; -import android.content.res.Resources; -import android.graphics.drawable.Animatable; -import android.net.Uri; -import android.os.AsyncTask; -import android.os.Build; -import android.os.Bundle; -import android.os.Handler; -import android.text.SpannableString; -import android.text.method.LinkMovementMethod; -import android.util.Log; -import android.view.MotionEvent; -import android.view.View; -import android.widget.ArrayAdapter; -import android.widget.LinearLayout; -import android.widget.RelativeLayout; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; -import androidx.core.app.ActivityCompat; -import androidx.core.content.ContextCompat; -import androidx.core.view.GestureDetectorCompat; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.facebook.drawee.backends.pipeline.Fresco; -import com.facebook.drawee.controller.BaseControllerListener; -import com.facebook.imagepipeline.image.ImageInfo; -import com.facebook.imagepipeline.request.ImageRequest; -import com.facebook.imagepipeline.request.ImageRequestBuilder; -import com.google.android.exoplayer2.SimpleExoPlayer; -import com.google.android.exoplayer2.source.MediaSource; -import com.google.android.exoplayer2.source.MediaSourceEventListener; -import com.google.android.exoplayer2.source.ProgressiveMediaSource; -import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; - -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import awais.instagrabber.R; -import awais.instagrabber.adapters.PostsMediaAdapter; -import awais.instagrabber.asyncs.PostFetcher; -import awais.instagrabber.asyncs.ProfileFetcher; -import awais.instagrabber.asyncs.i.iPostFetcher; -import awais.instagrabber.customviews.CommentMentionClickSpan; -import awais.instagrabber.customviews.helpers.SwipeGestureListener; -import awais.instagrabber.databinding.ItemFullPostViewBkBinding; -import awais.instagrabber.interfaces.FetchListener; -import awais.instagrabber.interfaces.SwipeEvent; -import awais.instagrabber.models.BasePostModel; -import awais.instagrabber.models.PostModel; -import awais.instagrabber.models.ProfileModel; -import awais.instagrabber.models.ViewerPostModel; -import awais.instagrabber.models.enums.DownloadMethod; -import awais.instagrabber.models.enums.MediaItemType; -import awais.instagrabber.models.enums.PostItemType; -import awais.instagrabber.utils.Constants; -import awais.instagrabber.utils.Utils; - -import static awais.instagrabber.utils.Utils.settingsHelper; - -@Deprecated -public final class PostViewer extends BaseLanguageActivity { - private ItemFullPostViewBkBinding viewerBinding; - private String url, prevUsername; - private ProfileModel profileModel; - private BasePostModel postModel; - private ViewerPostModel viewerPostModel; - private SimpleExoPlayer player; - private ArrayAdapter profileDialogAdapter; - private View viewsContainer, viewerCaptionParent; - private GestureDetectorCompat gestureDetector; - private SwipeEvent swipeEvent; - private CharSequence postCaption = null, postUserId; - private Resources resources; - private boolean session = false, isFromShare, liked, saved, ok = false; - private int slidePos = 0, lastSlidePos = 0; - private PostItemType postItemType; - @SuppressLint("ClickableViewAccessibility") - final View.OnTouchListener gestureTouchListener = new View.OnTouchListener() { - private float startX; - private float startY; - - @Override - public boolean onTouch(final View v, final MotionEvent event) { - if (v == viewerCaptionParent) { - switch (event.getAction()) { - case MotionEvent.ACTION_DOWN: - startX = event.getX(); - startY = event.getY(); - break; - - case MotionEvent.ACTION_UP: - if (!(Utils.isEmpty(postCaption) || - Math.abs(startX - event.getX()) > 50 || Math.abs(startY - event.getY()) > 50)) { - Utils.copyText(PostViewer.this, postCaption); - return false; - } - } - } - return gestureDetector.onTouchEvent(event); - } - }; - private final DialogInterface.OnClickListener profileDialogListener = (dialog, which) -> { - final String username = viewerPostModel.getProfileModel().getUsername(); - - if (which == 0) { - searchUsername(username); - } else if (profileModel != null && which == 1) { - startActivity(new Intent(this, ProfilePicViewer.class) - .putExtra(Constants.EXTRAS_PROFILE, profileModel)); - } - }; - private final View.OnClickListener onClickListener = new View.OnClickListener() { - @Override - public void onClick(final View v) { - if (v == viewerBinding.topPanel.ivProfilePic) { - new AlertDialog.Builder(PostViewer.this).setAdapter(profileDialogAdapter, profileDialogListener) - .setNeutralButton(R.string.cancel, null) - .setTitle(viewerPostModel.getProfileModel().getUsername()).show(); - - } else if (v == viewerBinding.ivToggleFullScreen) { - toggleFullscreen(); - - final LinearLayout topPanelRoot = viewerBinding.topPanel.getRoot(); - final int iconRes; - - if (containerLayoutParams.weight != 3.3f) { - containerLayoutParams.weight = 3.3f; - iconRes = R.drawable.ic_fullscreen_exit; - topPanelRoot.setVisibility(View.GONE); - viewerBinding.btnDownload.setVisibility(View.VISIBLE); - viewerBinding.bottomPanel.tvPostDate.setVisibility(View.GONE); - } else { - containerLayoutParams.weight = (viewerBinding.mediaList.getVisibility() == View.VISIBLE) ? 1.35f : 1.9f; - containerLayoutParams.weight += (Utils.isEmpty(settingsHelper.getString(Constants.COOKIE))) ? 0.3f : 0; - iconRes = R.drawable.ic_fullscreen; - topPanelRoot.setVisibility(View.VISIBLE); - viewerBinding.btnDownload.setVisibility(View.GONE); - viewerBinding.bottomPanel.tvPostDate.setVisibility(View.VISIBLE); - } - - viewerBinding.ivToggleFullScreen.setImageResource(iconRes); - viewerBinding.container.setLayoutParams(containerLayoutParams); - - } else if (v == viewerBinding.bottomPanel.btnMute) { - if (player != null) { - final float intVol = player.getVolume() == 0f ? 1f : 0f; - player.setVolume(intVol); - viewerBinding.bottomPanel.btnMute.setImageResource(intVol == 0f ? R.drawable.ic_volume_off_24 : R.drawable.ic_volume_up_24); - Utils.sessionVolumeFull = intVol == 1f; - } - } else if (v == viewerBinding.btnLike) { - new PostAction().execute("likes"); - } else if (v == viewerBinding.btnBookmark) { - new PostAction().execute("save"); - } else { - final Object tag = v.getTag(); - if (tag instanceof ViewerPostModel) { - viewerPostModel = (ViewerPostModel) tag; - slidePos = Math.max(0, viewerPostModel.getPosition()); - refreshPost(); - } - } - } - }; - private final View.OnClickListener downloadClickListener = v -> { - if (ContextCompat.checkSelfPermission(this, Utils.PERMS[0]) == PackageManager.PERMISSION_GRANTED) - showDownloadDialog(); - else - ActivityCompat.requestPermissions(this, Utils.PERMS, 8020); - }; - private final PostsMediaAdapter mediaAdapter = new PostsMediaAdapter(null, onClickListener); - private LinearLayout.LayoutParams containerLayoutParams; - private final FetchListener pfl = result -> { - if (result == null || result.length < 1) { - Toast.makeText(this, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); - return; - } - - viewerPostModel = result[0]; - - mediaAdapter.setData(result); - if (result.length > 1) { - viewerBinding.mediaList.setLayoutParams(new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, 0, 0.55f - )); - containerLayoutParams.weight = 1.35f; - containerLayoutParams.weight += (Utils.isEmpty(settingsHelper.getString(Constants.COOKIE))) ? 0.3f : 0; - viewerBinding.container.setLayoutParams(containerLayoutParams); - viewerBinding.mediaList.setVisibility(View.VISIBLE); - } - - viewerCaptionParent.setOnTouchListener(gestureTouchListener); - viewerBinding.playerView.setOnTouchListener(gestureTouchListener); - // viewerBinding.imageViewer.setOnSingleFlingListener((e1, e2, velocityX, velocityY) -> { - // final float diffX = e2.getX() - e1.getX(); - // if (Math.abs(diffX) > Math.abs(e2.getY() - e1.getY()) && Math.abs(diffX) > SwipeGestureListener.SWIPE_THRESHOLD - // && Math.abs(velocityX) > SwipeGestureListener.SWIPE_VELOCITY_THRESHOLD) { - // swipeEvent.onSwipe(diffX > 0); - // return true; - // } - // return false; - // }); - - final long commentsCount = viewerPostModel.getCommentsCount(); - viewerBinding.bottomPanel.commentsCount.setText(String.valueOf(commentsCount)); - viewerBinding.bottomPanel.btnComments.setVisibility(View.VISIBLE); - - viewerBinding.bottomPanel.btnComments.setOnClickListener(v -> startActivityForResult( - new Intent(this, CommentsViewerFragment.class) - .putExtra(Constants.EXTRAS_SHORTCODE, postModel.getShortCode()) - .putExtra(Constants.EXTRAS_POST, viewerPostModel.getPostId()) - .putExtra(Constants.EXTRAS_USER, postUserId), - 6969)); - viewerBinding.bottomPanel.btnComments.setClickable(true); - viewerBinding.bottomPanel.btnComments.setEnabled(true); - - if (postModel instanceof PostModel) { - final PostModel postModel = (PostModel) this.postModel; - postModel.setPostId(viewerPostModel.getPostId()); - postModel.setTimestamp(viewerPostModel.getTimestamp()); - postModel.setPostCaption(viewerPostModel.getPostCaption()); - if (!ok) { - liked = viewerPostModel.getLike(); - saved = viewerPostModel.getBookmark(); - } - } - - setupPostInfoBar("@" + viewerPostModel.getProfileModel().getUsername(), viewerPostModel.getItemType(), - viewerPostModel.getLocationName(), viewerPostModel.getLocation()); - - postCaption = postModel.getPostCaption(); - viewerCaptionParent.setVisibility(View.VISIBLE); - - viewerBinding.bottomPanel.btnDownload.setOnClickListener(downloadClickListener); - - refreshPost(); - }; - - @Override - protected void onCreate(@Nullable final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - viewerBinding = ItemFullPostViewBkBinding.inflate(getLayoutInflater()); - setContentView(viewerBinding.getRoot()); - - final Intent intent = getIntent(); - if (intent == null || !intent.hasExtra(Constants.EXTRAS_POST) - || (postModel = (PostModel) intent.getSerializableExtra(Constants.EXTRAS_POST)) == null) { - Utils.errorFinish(this); - return; - } - - containerLayoutParams = (LinearLayout.LayoutParams) viewerBinding.container.getLayoutParams(); - - if (intent.hasExtra(Constants.EXTRAS_TYPE)) - postItemType = (PostItemType) intent.getSerializableExtra(Constants.EXTRAS_TYPE); - - resources = getResources(); - - viewerBinding.topPanel.title.setMovementMethod(new LinkMovementMethod()); - viewerBinding.topPanel.title.setMentionClickListener((view, text, isHashtag, isLocation) -> searchUsername(text)); - viewerBinding.topPanel.ivProfilePic.setOnClickListener(onClickListener); - - viewerBinding.ivToggleFullScreen.setOnClickListener(onClickListener); - if (Utils.isEmpty(settingsHelper.getString(Constants.COOKIE))) { - viewerBinding.btnLike.setVisibility(View.GONE); - viewerBinding.btnBookmark.setVisibility(View.GONE); - viewerBinding.postActions.setVisibility(View.GONE); - viewerBinding.postActions.setLayoutParams(new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, 0, 0 - )); - containerLayoutParams.weight = (containerLayoutParams.weight == 3.3f) ? 3.3f : 2.2f; - viewerBinding.container.setLayoutParams(containerLayoutParams); - } else { - viewerBinding.btnLike.setOnClickListener(onClickListener); - viewerBinding.btnBookmark.setOnClickListener(onClickListener); - } - viewerBinding.btnDownload.setOnClickListener(downloadClickListener); - - profileDialogAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, - new String[]{resources.getString(R.string.open_profile), resources.getString(R.string.view_pfp)}); - - postModel.setPosition(intent.getIntExtra(Constants.EXTRAS_INDEX, -1)); - - final boolean postIdNull = postModel.getPostId() == null; - if (!postIdNull) - setupPostInfoBar(intent.getStringExtra(Constants.EXTRAS_USER), postModel.getItemType(), null, null); - - isFromShare = postModel.getPosition() == -1 || postIdNull; - - viewerCaptionParent = (View) viewerBinding.bottomPanel.viewerCaption.getParent(); - viewsContainer = (View) viewerBinding.bottomPanel.videoViewsContainer; - - viewerBinding.mediaList.setLayoutManager(new LinearLayoutManager(this, RecyclerView.HORIZONTAL, false)); - viewerBinding.mediaList.setAdapter(mediaAdapter); - viewerBinding.mediaList.setVisibility(View.GONE); - - swipeEvent = isRight -> { - final List itemGetterItems; - final boolean isSwipeable; - - // if (postItemType == PostItemType.SAVED && SavedViewerFragment.itemGetter != null) { - // itemGetterItems = SavedViewerFragment.itemGetter.get(postItemType); - // isSwipeable = !(itemGetterItems.size() < 1 || postItemType == PostItemType.SAVED && isFromShare); - // } else - if (postItemType != null && MainActivityBackup.itemGetter != null) { - itemGetterItems = MainActivityBackup.itemGetter.get(postItemType); - isSwipeable = !(itemGetterItems.size() < 1 || postItemType == PostItemType.MAIN && isFromShare); - } else { - itemGetterItems = null; - isSwipeable = false; - } - - final BasePostModel[] basePostModels = mediaAdapter.getPostModels(); - final int slides = basePostModels.length; - - int position = postModel.getPosition(); - - if (isRight) { - --slidePos; - if (!isSwipeable && slidePos < 0) slidePos = 0; - if (slides > 0 && slidePos >= 0) { - if (basePostModels[slidePos] instanceof ViewerPostModel) { - viewerPostModel = (ViewerPostModel) basePostModels[slidePos]; - } - refreshPost(); - return; - } - if (isSwipeable && --position < 0) position = itemGetterItems.size() - 1; - } else { - ++slidePos; - if (!isSwipeable && slidePos >= slides) slidePos = slides - 1; - if (slides > 0 && slidePos < slides) { - if (basePostModels[slidePos] instanceof ViewerPostModel) { - viewerPostModel = (ViewerPostModel) basePostModels[slidePos]; - } - refreshPost(); - return; - } - if (isSwipeable && ++position >= itemGetterItems.size()) position = 0; - } - - if (isSwipeable) { - slidePos = 0; - ok = false; - Log.d("AWAISKING_APP", "swipe left <<< post[" + position + "]: " + postModel + " -- " + slides); - postModel = itemGetterItems.get(position); - postModel.setPosition(position); - viewPost(); - } - }; - gestureDetector = new GestureDetectorCompat(this, new SwipeGestureListener(swipeEvent)); - - viewPost(); - } - - private void viewPost() { - lastSlidePos = 0; - mediaAdapter.setData(null); - viewsContainer.setVisibility(View.GONE); - viewerCaptionParent.setVisibility(View.GONE); - viewerBinding.mediaList.setVisibility(View.GONE); - viewerBinding.btnDownload.setVisibility(View.GONE); - viewerBinding.bottomPanel.btnMute.setVisibility(View.GONE); - viewerBinding.bottomPanel.tvPostDate.setVisibility(View.GONE); - viewerBinding.bottomPanel.btnComments.setVisibility(View.GONE); - viewerBinding.bottomPanel.btnDownload.setVisibility(View.INVISIBLE); - viewerBinding.bottomPanel.viewerCaption.setText(null); - viewerBinding.bottomPanel.viewerCaption.setMentionClickListener(null); - - viewerBinding.playerView.setVisibility(View.GONE); - viewerBinding.playerView.setPlayer(null); - viewerBinding.imageViewer.setController(null); - - if (postModel.getShortCode() != null) - new PostFetcher(postModel.getShortCode(), pfl).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - else if (postModel.getPostId() != null) - new iPostFetcher(postModel.getPostId(), pfl).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - private void searchUsername(final String text) { - startActivity( - new Intent(getApplicationContext(), ProfileViewer.class) - .putExtra(Constants.EXTRAS_USERNAME, text) - ); - } - - private void setupVideo() { - viewerBinding.playerView.setVisibility(View.VISIBLE); - viewerBinding.bottomPanel.btnDownload.setVisibility(View.VISIBLE); - viewerBinding.bottomPanel.btnMute.setVisibility(View.VISIBLE); - viewerBinding.progressView.setVisibility(View.GONE); - viewerBinding.imageViewer.setVisibility(View.GONE); - viewerBinding.imageViewer.setController(null); - - if (viewerPostModel.getVideoViews() > -1) { - viewsContainer.setVisibility(View.VISIBLE); - viewerBinding.bottomPanel.tvVideoViews.setText(String.valueOf(viewerPostModel.getVideoViews())); - } - - player = new SimpleExoPlayer.Builder(this).build(); - viewerBinding.playerView.setPlayer(player); - float vol = Utils.settingsHelper.getBoolean(Constants.MUTED_VIDEOS) ? 0f : 1f; - if (vol == 0f && Utils.sessionVolumeFull) vol = 1f; - - player.setVolume(vol); - player.setPlayWhenReady(Utils.settingsHelper.getBoolean(Constants.AUTOPLAY_VIDEOS)); - final ProgressiveMediaSource mediaSource = new ProgressiveMediaSource.Factory(new DefaultDataSourceFactory(this, "instagram")) - .createMediaSource(Uri.parse(url)); - mediaSource.addEventListener(new Handler(), new MediaSourceEventListener() { - @Override - public void onLoadCompleted(final int windowIndex, - @Nullable final MediaSource.MediaPeriodId mediaPeriodId, - final LoadEventInfo loadEventInfo, - final MediaLoadData mediaLoadData) { - viewerBinding.progressView.setVisibility(View.GONE); - } - - @Override - public void onLoadStarted(final int windowIndex, - @Nullable final MediaSource.MediaPeriodId mediaPeriodId, - final LoadEventInfo loadEventInfo, - final MediaLoadData mediaLoadData) { - viewerBinding.progressView.setVisibility(View.VISIBLE); - } - - @Override - public void onLoadCanceled(final int windowIndex, - @Nullable final MediaSource.MediaPeriodId mediaPeriodId, - final LoadEventInfo loadEventInfo, - final MediaLoadData mediaLoadData) { - viewerBinding.progressView.setVisibility(View.GONE); - } - - @Override - public void onLoadError(final int windowIndex, - @Nullable final MediaSource.MediaPeriodId mediaPeriodId, - final LoadEventInfo loadEventInfo, - final MediaLoadData mediaLoadData, - final IOException error, - final boolean wasCanceled) { - viewerBinding.progressView.setVisibility(View.GONE); - } - }); - player.prepare(mediaSource); - - player.setVolume(vol); - viewerBinding.bottomPanel.btnMute.setImageResource(vol == 0f ? R.drawable.ic_volume_up_24 : R.drawable.ic_volume_off_24); - - viewerBinding.bottomPanel.btnMute.setOnClickListener(onClickListener); - } - - private void setupImage() { - viewsContainer.setVisibility(View.GONE); - viewerBinding.playerView.setVisibility(View.GONE); - viewerBinding.progressView.setVisibility(View.VISIBLE); - viewerBinding.bottomPanel.btnMute.setVisibility(View.GONE); - viewerBinding.bottomPanel.btnDownload.setVisibility(View.VISIBLE); - viewerBinding.imageViewer.setVisibility(View.VISIBLE); - - final ImageRequest requestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url)) - .setLocalThumbnailPreviewsEnabled(true) - .setProgressiveRenderingEnabled(true) - .build(); - viewerBinding.imageViewer.setController( - Fresco.newDraweeControllerBuilder() - .setImageRequest(requestBuilder) - .setOldController(viewerBinding.imageViewer.getController()) - .setLowResImageRequest(ImageRequest.fromUri(url)) - .setControllerListener(new BaseControllerListener() { - - @Override - public void onFailure(final String id, final Throwable throwable) { - viewerBinding.progressView.setVisibility(View.GONE); - } - - @Override - public void onFinalImageSet(final String id, final ImageInfo imageInfo, final Animatable animatable) { - viewerBinding.progressView.setVisibility(View.GONE); - } - }) - .build() - ); - } - - private void showDownloadDialog() { - final ArrayList postModels = new ArrayList<>(); - - if (!session && viewerBinding.mediaList.getVisibility() == View.VISIBLE) { - final DialogInterface.OnClickListener clickListener = (dialog, which) -> { - postModels.clear(); - - if (which == DialogInterface.BUTTON_NEGATIVE) { - final BasePostModel[] adapterPostModels = mediaAdapter.getPostModels(); - for (int i = 0, size = mediaAdapter.getItemCount(); i < size; ++i) { - if (adapterPostModels[i] instanceof ViewerPostModel) - postModels.add(adapterPostModels[i]); - } - } else if (which == DialogInterface.BUTTON_POSITIVE) { - postModels.add(viewerPostModel); - } else { - session = true; - postModels.add(viewerPostModel); - } - - if (postModels.size() > 0) - Utils.batchDownload(this, viewerPostModel.getProfileModel().getUsername(), DownloadMethod.DOWNLOAD_POST_VIEWER, postModels); - }; - - new AlertDialog.Builder(this).setTitle(R.string.post_viewer_download_dialog_title) - .setMessage(R.string.post_viewer_download_message) - .setNeutralButton(R.string.post_viewer_download_session, clickListener) - .setPositiveButton(R.string.post_viewer_download_current, clickListener) - .setNegativeButton(R.string.post_viewer_download_album, clickListener).show(); - } else { - Utils.batchDownload(this, viewerPostModel.getProfileModel().getUsername(), DownloadMethod.DOWNLOAD_POST_VIEWER, - Collections.singletonList(viewerPostModel)); - } - } - - @Override - public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults); - if (requestCode == 8020 && grantResults[0] == PackageManager.PERMISSION_GRANTED) - showDownloadDialog(); - } - - @Override - protected void onActivityResult(final int requestCode, final int resultCode, @Nullable final Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (resultCode == 6969) { - setResult(RESULT_OK); - finish(); - } - } - - @Override - public void onPause() { - super.onPause(); - if (Build.VERSION.SDK_INT < 24) releasePlayer(); - } - - @Override - public void onStop() { - super.onStop(); - if (Build.VERSION.SDK_INT >= 24) releasePlayer(); - } - - @Override - protected void onResume() { - super.onResume(); - if (player == null && viewerPostModel != null && viewerPostModel.getItemType() == MediaItemType.MEDIA_TYPE_VIDEO) - setupVideo(); - else if (player != null) { - player.setPlayWhenReady(true); - player.getPlaybackState(); - } - } - - private void refreshPost() { - if (containerLayoutParams.weight != 3.3f) { - containerLayoutParams.weight = (viewerBinding.mediaList.getVisibility() == View.VISIBLE) ? 1.35f : 1.9f; - viewerBinding.container.setLayoutParams(containerLayoutParams); - } - if (viewerBinding.mediaList.getVisibility() == View.VISIBLE) { - ViewerPostModel item = mediaAdapter.getItemAt(lastSlidePos); - if (item != null) { - item.setCurrentSlide(false); - mediaAdapter.notifyItemChanged(lastSlidePos, item); - } - - item = mediaAdapter.getItemAt(slidePos); - if (item != null) { - item.setCurrentSlide(true); - mediaAdapter.notifyItemChanged(slidePos, item); - } - } - lastSlidePos = slidePos; - - postCaption = viewerPostModel.getPostCaption(); - - if (Utils.hasMentions(postCaption)) { - viewerBinding.bottomPanel.viewerCaption.setText(Utils.getMentionText(postCaption), TextView.BufferType.SPANNABLE); - viewerBinding.bottomPanel.viewerCaption.setMentionClickListener((view, text, isHashtag, isLocation) -> searchUsername(text)); - } else { - viewerBinding.bottomPanel.viewerCaption.setMentionClickListener(null); - viewerBinding.bottomPanel.viewerCaption.setText(postCaption); - } - - setupPostInfoBar("@" + viewerPostModel.getProfileModel().getUsername(), viewerPostModel.getItemType(), - viewerPostModel.getLocationName(), viewerPostModel.getLocation()); - - if (postModel instanceof PostModel) { - final PostModel postModel = (PostModel) this.postModel; - postModel.setPostId(viewerPostModel.getPostId()); - postModel.setTimestamp(viewerPostModel.getTimestamp()); - postModel.setPostCaption(viewerPostModel.getPostCaption()); - if (liked == true) { - viewerBinding.btnLike.setText(resources.getString(R.string.unlike, viewerPostModel.getLikes() - + ((ok && viewerPostModel.getLike() != liked) ? (liked ? 1L : -1L) : 0L))); - viewerBinding.btnLike.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - getApplicationContext(), R.color.btn_pink_background))); - } else { - viewerBinding.btnLike.setText(resources.getString(R.string.like, viewerPostModel.getLikes() - + ((ok && viewerPostModel.getLike() != liked) ? (liked ? 1L : -1L) : 0L))); - viewerBinding.btnLike.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - getApplicationContext(), R.color.btn_lightpink_background))); - } - if (saved == true) { - viewerBinding.btnBookmark.setText(R.string.unbookmark); - viewerBinding.btnBookmark.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - getApplicationContext(), R.color.btn_orange_background))); - } else { - viewerBinding.btnBookmark.setText(R.string.bookmark); - viewerBinding.btnBookmark.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - getApplicationContext(), R.color.btn_lightorange_background))); - } - } - - viewerBinding.bottomPanel.tvPostDate.setText(viewerPostModel.getPostDate()); - viewerBinding.bottomPanel.tvPostDate.setVisibility(containerLayoutParams.weight != 3.3f ? View.VISIBLE : View.GONE); - viewerBinding.bottomPanel.tvPostDate.setSelected(true); - - url = viewerPostModel.getDisplayUrl(); - releasePlayer(); - - viewerBinding.btnDownload.setVisibility(containerLayoutParams.weight == 3.3f ? View.VISIBLE : View.GONE); - if (viewerPostModel.getItemType() == MediaItemType.MEDIA_TYPE_VIDEO) setupVideo(); - else setupImage(); - } - - private void releasePlayer() { - if (player != null) { - player.release(); - player = null; - } - } - - private void setupPostInfoBar(final String from, final MediaItemType mediaItemType, final String locationName, final String location) { - if (prevUsername == null || !prevUsername.equals(from)) { - // viewerBinding.topPanel.ivProfilePic.setImageBitmap(null); - // viewerBinding.topPanel.ivProfilePic.setImageDrawable(null); - // viewerBinding.topPanel.ivProfilePic.setImageResource(0); - viewerBinding.topPanel.ivProfilePic.setImageRequest(null); - - if (!Utils.isEmpty(from) && from.charAt(0) == '@') - new ProfileFetcher(from.substring(1), result -> { - profileModel = result; - - if (result != null) { - // final String hdProfilePic = result.getHdProfilePic(); - // final String sdProfilePic = result.getSdProfilePic(); - postUserId = result.getId(); - - // final boolean hdPicEmpty = Utils.isEmpty(hdProfilePic); - // glideRequestManager.load(hdPicEmpty ? sdProfilePic : hdProfilePic).listener(new RequestListener() { - // private boolean loaded = true; - // - // @Override - // public boolean onLoadFailed(@Nullable final GlideException e, final Object model, final Target target, final boolean isFirstResource) { - // viewerBinding.topPanel.ivProfilePic.setEnabled(false); - // viewerBinding.topPanel.ivProfilePic.setOnClickListener(null); - // if (loaded) { - // loaded = false; - // if (!Utils.isEmpty(sdProfilePic)) glideRequestManager.load(sdProfilePic).listener(this) - // .into(viewerBinding.topPanel.ivProfilePic); - // } - // return false; - // } - // - // @Override - // public boolean onResourceReady(final Drawable resource, final Object model, final Target target, final DataSource dataSource, final boolean isFirstResource) { - // viewerBinding.topPanel.ivProfilePic.setEnabled(true); - // viewerBinding.topPanel.ivProfilePic.setOnClickListener(onClickListener); - // return false; - // } - // }).into(viewerBinding.topPanel.ivProfilePic); - viewerBinding.topPanel.ivProfilePic.setImageURI(profileModel.getSdProfilePic()); - - final View viewStoryPost = findViewById(R.id.viewStoryPost); - if (viewStoryPost != null) { - viewStoryPost.setOnClickListener(v -> { - if (result.isPrivate()) - Toast.makeText(getApplicationContext(), R.string.share_private_post, Toast.LENGTH_LONG).show(); - Intent sharingIntent = new Intent(Intent.ACTION_SEND); - sharingIntent.setType("text/plain"); - sharingIntent.putExtra(Intent.EXTRA_TEXT, "https://instagram.com/p/" + postModel.getShortCode()); - startActivity(Intent.createChooser(sharingIntent, - (result.isPrivate()) - ? getString(R.string.share_private_post) - : getString(R.string.share_public_post))); - }); - } - } - }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - prevUsername = from; - } - - final String titlePrefix = resources.getString(mediaItemType == MediaItemType.MEDIA_TYPE_VIDEO ? - R.string.post_viewer_video_post : R.string.post_viewer_image_post); - if (Utils.isEmpty(from)) viewerBinding.topPanel.title.setText(titlePrefix); - else { - final int titleLen = from.length(); - final SpannableString spannableString = new SpannableString(from); - spannableString.setSpan(new CommentMentionClickSpan(), 0, titleLen, 0); - viewerBinding.topPanel.title.setText(spannableString); - } - - if (location == null) { - viewerBinding.topPanel.location.setVisibility(View.GONE); - viewerBinding.topPanel.title.setLayoutParams(new RelativeLayout.LayoutParams( - RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT - )); - } else { - viewerBinding.topPanel.location.setVisibility(View.VISIBLE); - viewerBinding.topPanel.location.setText(locationName); - viewerBinding.topPanel.location.setOnClickListener(v -> searchUsername(location)); - viewerBinding.topPanel.title.setLayoutParams(new RelativeLayout.LayoutParams( - RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT - )); - } - } - - private void toggleFullscreen() { - final View decorView = getWindow().getDecorView(); - int newUiOptions = decorView.getSystemUiVisibility(); - newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; - newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) - newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; - decorView.setSystemUiVisibility(newUiOptions); - } - - class PostAction extends AsyncTask { - String action; - - protected Void doInBackground(String... rawAction) { - action = rawAction[0]; - final String url = "https://www.instagram.com/web/" + action + "/" + postModel.getPostId() + "/" + (action == "save" ? - (saved ? "unsave/" : "save/") : - (liked ? "unlike/" : "like/")); - try { - final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); - urlConnection.setRequestMethod("POST"); - urlConnection.setUseCaches(false); - urlConnection.setRequestProperty("User-Agent", Constants.USER_AGENT); - urlConnection.setRequestProperty("x-csrftoken", - settingsHelper.getString(Constants.COOKIE).split("csrftoken=")[1].split(";")[0]); - urlConnection.connect(); - if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { - ok = true; - } - urlConnection.disconnect(); - } catch (Throwable ex) { - Log.e("austin_debug", action + ": " + ex); - } - return null; - } - - @Override - protected void onPostExecute(Void result) { - if (ok == true && action == "likes") { - liked = !liked; - refreshPost(); - } else if (ok == true && action == "save") { - saved = !saved; - refreshPost(); - } else - Toast.makeText(getApplicationContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); - } - } -} +// package awais.instagrabber.activities; +// +// import android.annotation.SuppressLint; +// import android.content.DialogInterface; +// import android.content.Intent; +// import android.content.pm.PackageManager; +// import android.content.res.ColorStateList; +// import android.content.res.Resources; +// import android.graphics.drawable.Animatable; +// import android.net.Uri; +// import android.os.AsyncTask; +// import android.os.Build; +// import android.os.Bundle; +// import android.os.Handler; +// import android.text.SpannableString; +// import android.text.method.LinkMovementMethod; +// import android.util.Log; +// import android.view.MotionEvent; +// import android.view.View; +// import android.widget.ArrayAdapter; +// import android.widget.LinearLayout; +// import android.widget.RelativeLayout; +// import android.widget.TextView; +// import android.widget.Toast; +// +// import androidx.annotation.NonNull; +// import androidx.annotation.Nullable; +// import androidx.appcompat.app.AlertDialog; +// import androidx.core.app.ActivityCompat; +// import androidx.core.content.ContextCompat; +// import androidx.core.view.GestureDetectorCompat; +// import androidx.recyclerview.widget.LinearLayoutManager; +// import androidx.recyclerview.widget.RecyclerView; +// +// import com.facebook.drawee.backends.pipeline.Fresco; +// import com.facebook.drawee.controller.BaseControllerListener; +// import com.facebook.imagepipeline.image.ImageInfo; +// import com.facebook.imagepipeline.request.ImageRequest; +// import com.facebook.imagepipeline.request.ImageRequestBuilder; +// import com.google.android.exoplayer2.SimpleExoPlayer; +// import com.google.android.exoplayer2.source.MediaSource; +// import com.google.android.exoplayer2.source.MediaSourceEventListener; +// import com.google.android.exoplayer2.source.ProgressiveMediaSource; +// import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; +// +// import java.io.IOException; +// import java.net.HttpURLConnection; +// import java.net.URL; +// import java.util.ArrayList; +// import java.util.Collections; +// import java.util.List; +// +// import awais.instagrabber.R; +// import awais.instagrabber.adapters.PostsMediaAdapter; +// import awais.instagrabber.asyncs.PostFetcher; +// import awais.instagrabber.asyncs.ProfileFetcher; +// import awais.instagrabber.asyncs.i.iPostFetcher; +// import awais.instagrabber.customviews.CommentMentionClickSpan; +// import awais.instagrabber.customviews.helpers.SwipeGestureListener; +// import awais.instagrabber.databinding.ItemFullPostViewBkBinding; +// import awais.instagrabber.interfaces.FetchListener; +// import awais.instagrabber.interfaces.SwipeEvent; +// import awais.instagrabber.models.BasePostModel; +// import awais.instagrabber.models.PostModel; +// import awais.instagrabber.models.ProfileModel; +// import awais.instagrabber.models.ViewerPostModel; +// import awais.instagrabber.models.enums.DownloadMethod; +// import awais.instagrabber.models.enums.MediaItemType; +// import awais.instagrabber.models.enums.PostItemType; +// import awais.instagrabber.utils.Constants; +// import awais.instagrabber.utils.Utils; +// +// import static awais.instagrabber.utils.Utils.settingsHelper; +// +// @Deprecated +// public final class PostViewer extends BaseLanguageActivity { +// private ItemFullPostViewBkBinding viewerBinding; +// private String url, prevUsername; +// private ProfileModel profileModel; +// private BasePostModel postModel; +// private ViewerPostModel viewerPostModel; +// private SimpleExoPlayer player; +// private ArrayAdapter profileDialogAdapter; +// private View viewsContainer, viewerCaptionParent; +// private GestureDetectorCompat gestureDetector; +// private SwipeEvent swipeEvent; +// private CharSequence postCaption = null, postUserId; +// private Resources resources; +// private boolean session = false, isFromShare, liked, saved, ok = false; +// private int slidePos = 0, lastSlidePos = 0; +// private PostItemType postItemType; +// @SuppressLint("ClickableViewAccessibility") +// final View.OnTouchListener gestureTouchListener = new View.OnTouchListener() { +// private float startX; +// private float startY; +// +// @Override +// public boolean onTouch(final View v, final MotionEvent event) { +// if (v == viewerCaptionParent) { +// switch (event.getAction()) { +// case MotionEvent.ACTION_DOWN: +// startX = event.getX(); +// startY = event.getY(); +// break; +// +// case MotionEvent.ACTION_UP: +// if (!(Utils.isEmpty(postCaption) || +// Math.abs(startX - event.getX()) > 50 || Math.abs(startY - event.getY()) > 50)) { +// Utils.copyText(PostViewer.this, postCaption); +// return false; +// } +// } +// } +// return gestureDetector.onTouchEvent(event); +// } +// }; +// private final DialogInterface.OnClickListener profileDialogListener = (dialog, which) -> { +// final String username = viewerPostModel.getProfileModel().getUsername(); +// +// if (which == 0) { +// searchUsername(username); +// } else if (profileModel != null && which == 1) { +// startActivity(new Intent(this, ProfilePicViewer.class) +// .putExtra(Constants.EXTRAS_PROFILE, profileModel)); +// } +// }; +// private final View.OnClickListener onClickListener = new View.OnClickListener() { +// @Override +// public void onClick(final View v) { +// if (v == viewerBinding.topPanel.ivProfilePic) { +// new AlertDialog.Builder(PostViewer.this).setAdapter(profileDialogAdapter, profileDialogListener) +// .setNeutralButton(R.string.cancel, null) +// .setTitle(viewerPostModel.getProfileModel().getUsername()).show(); +// +// } else if (v == viewerBinding.ivToggleFullScreen) { +// toggleFullscreen(); +// +// final LinearLayout topPanelRoot = viewerBinding.topPanel.getRoot(); +// final int iconRes; +// +// if (containerLayoutParams.weight != 3.3f) { +// containerLayoutParams.weight = 3.3f; +// iconRes = R.drawable.ic_fullscreen_exit; +// topPanelRoot.setVisibility(View.GONE); +// viewerBinding.btnDownload.setVisibility(View.VISIBLE); +// viewerBinding.bottomPanel.tvPostDate.setVisibility(View.GONE); +// } else { +// containerLayoutParams.weight = (viewerBinding.mediaList.getVisibility() == View.VISIBLE) ? 1.35f : 1.9f; +// containerLayoutParams.weight += (Utils.isEmpty(settingsHelper.getString(Constants.COOKIE))) ? 0.3f : 0; +// iconRes = R.drawable.ic_fullscreen; +// topPanelRoot.setVisibility(View.VISIBLE); +// viewerBinding.btnDownload.setVisibility(View.GONE); +// viewerBinding.bottomPanel.tvPostDate.setVisibility(View.VISIBLE); +// } +// +// viewerBinding.ivToggleFullScreen.setImageResource(iconRes); +// viewerBinding.container.setLayoutParams(containerLayoutParams); +// +// } else if (v == viewerBinding.bottomPanel.btnMute) { +// if (player != null) { +// final float intVol = player.getVolume() == 0f ? 1f : 0f; +// player.setVolume(intVol); +// viewerBinding.bottomPanel.btnMute.setImageResource(intVol == 0f ? R.drawable.ic_volume_off_24 : R.drawable.ic_volume_up_24); +// Utils.sessionVolumeFull = intVol == 1f; +// } +// } else if (v == viewerBinding.btnLike) { +// new PostAction().execute("likes"); +// } else if (v == viewerBinding.btnBookmark) { +// new PostAction().execute("save"); +// } else { +// final Object tag = v.getTag(); +// if (tag instanceof ViewerPostModel) { +// viewerPostModel = (ViewerPostModel) tag; +// slidePos = Math.max(0, viewerPostModel.getPosition()); +// refreshPost(); +// } +// } +// } +// }; +// private final View.OnClickListener downloadClickListener = v -> { +// if (ContextCompat.checkSelfPermission(this, Utils.PERMS[0]) == PackageManager.PERMISSION_GRANTED) +// showDownloadDialog(); +// else +// ActivityCompat.requestPermissions(this, Utils.PERMS, 8020); +// }; +// private final PostsMediaAdapter mediaAdapter = new PostsMediaAdapter(null, onClickListener); +// private LinearLayout.LayoutParams containerLayoutParams; +// private final FetchListener pfl = result -> { +// if (result == null || result.length < 1) { +// Toast.makeText(this, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); +// return; +// } +// +// viewerPostModel = result[0]; +// +// mediaAdapter.setData(result); +// if (result.length > 1) { +// viewerBinding.mediaList.setLayoutParams(new LinearLayout.LayoutParams( +// LinearLayout.LayoutParams.MATCH_PARENT, 0, 0.55f +// )); +// containerLayoutParams.weight = 1.35f; +// containerLayoutParams.weight += (Utils.isEmpty(settingsHelper.getString(Constants.COOKIE))) ? 0.3f : 0; +// viewerBinding.container.setLayoutParams(containerLayoutParams); +// viewerBinding.mediaList.setVisibility(View.VISIBLE); +// } +// +// viewerCaptionParent.setOnTouchListener(gestureTouchListener); +// viewerBinding.playerView.setOnTouchListener(gestureTouchListener); +// // viewerBinding.imageViewer.setOnSingleFlingListener((e1, e2, velocityX, velocityY) -> { +// // final float diffX = e2.getX() - e1.getX(); +// // if (Math.abs(diffX) > Math.abs(e2.getY() - e1.getY()) && Math.abs(diffX) > SwipeGestureListener.SWIPE_THRESHOLD +// // && Math.abs(velocityX) > SwipeGestureListener.SWIPE_VELOCITY_THRESHOLD) { +// // swipeEvent.onSwipe(diffX > 0); +// // return true; +// // } +// // return false; +// // }); +// +// final long commentsCount = viewerPostModel.getCommentsCount(); +// viewerBinding.bottomPanel.commentsCount.setText(String.valueOf(commentsCount)); +// viewerBinding.bottomPanel.btnComments.setVisibility(View.VISIBLE); +// +// viewerBinding.bottomPanel.btnComments.setOnClickListener(v -> startActivityForResult( +// new Intent(this, CommentsViewerFragment.class) +// .putExtra(Constants.EXTRAS_SHORTCODE, postModel.getShortCode()) +// .putExtra(Constants.EXTRAS_POST, viewerPostModel.getPostId()) +// .putExtra(Constants.EXTRAS_USER, postUserId), +// 6969)); +// viewerBinding.bottomPanel.btnComments.setClickable(true); +// viewerBinding.bottomPanel.btnComments.setEnabled(true); +// +// if (postModel instanceof PostModel) { +// final PostModel postModel = (PostModel) this.postModel; +// postModel.setPostId(viewerPostModel.getPostId()); +// postModel.setTimestamp(viewerPostModel.getTimestamp()); +// postModel.setPostCaption(viewerPostModel.getPostCaption()); +// if (!ok) { +// liked = viewerPostModel.getLike(); +// saved = viewerPostModel.getBookmark(); +// } +// } +// +// setupPostInfoBar("@" + viewerPostModel.getProfileModel().getUsername(), viewerPostModel.getItemType(), +// viewerPostModel.getLocationName(), viewerPostModel.getLocation()); +// +// postCaption = postModel.getPostCaption(); +// viewerCaptionParent.setVisibility(View.VISIBLE); +// +// viewerBinding.bottomPanel.btnDownload.setOnClickListener(downloadClickListener); +// +// refreshPost(); +// }; +// +// @Override +// protected void onCreate(@Nullable final Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// viewerBinding = ItemFullPostViewBkBinding.inflate(getLayoutInflater()); +// setContentView(viewerBinding.getRoot()); +// +// final Intent intent = getIntent(); +// if (intent == null || !intent.hasExtra(Constants.EXTRAS_POST) +// || (postModel = (PostModel) intent.getSerializableExtra(Constants.EXTRAS_POST)) == null) { +// Utils.errorFinish(this); +// return; +// } +// +// containerLayoutParams = (LinearLayout.LayoutParams) viewerBinding.container.getLayoutParams(); +// +// if (intent.hasExtra(Constants.EXTRAS_TYPE)) +// postItemType = (PostItemType) intent.getSerializableExtra(Constants.EXTRAS_TYPE); +// +// resources = getResources(); +// +// viewerBinding.topPanel.title.setMovementMethod(new LinkMovementMethod()); +// viewerBinding.topPanel.title.setMentionClickListener((view, text, isHashtag, isLocation) -> searchUsername(text)); +// viewerBinding.topPanel.ivProfilePic.setOnClickListener(onClickListener); +// +// viewerBinding.ivToggleFullScreen.setOnClickListener(onClickListener); +// if (Utils.isEmpty(settingsHelper.getString(Constants.COOKIE))) { +// viewerBinding.btnLike.setVisibility(View.GONE); +// viewerBinding.btnBookmark.setVisibility(View.GONE); +// viewerBinding.postActions.setVisibility(View.GONE); +// viewerBinding.postActions.setLayoutParams(new LinearLayout.LayoutParams( +// LinearLayout.LayoutParams.MATCH_PARENT, 0, 0 +// )); +// containerLayoutParams.weight = (containerLayoutParams.weight == 3.3f) ? 3.3f : 2.2f; +// viewerBinding.container.setLayoutParams(containerLayoutParams); +// } else { +// viewerBinding.btnLike.setOnClickListener(onClickListener); +// viewerBinding.btnBookmark.setOnClickListener(onClickListener); +// } +// viewerBinding.btnDownload.setOnClickListener(downloadClickListener); +// +// profileDialogAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, +// new String[]{resources.getString(R.string.open_profile), resources.getString(R.string.view_pfp)}); +// +// postModel.setPosition(intent.getIntExtra(Constants.EXTRAS_INDEX, -1)); +// +// final boolean postIdNull = postModel.getPostId() == null; +// if (!postIdNull) +// setupPostInfoBar(intent.getStringExtra(Constants.EXTRAS_USER), postModel.getItemType(), null, null); +// +// isFromShare = postModel.getPosition() == -1 || postIdNull; +// +// viewerCaptionParent = (View) viewerBinding.bottomPanel.viewerCaption.getParent(); +// viewsContainer = (View) viewerBinding.bottomPanel.videoViewsContainer; +// +// viewerBinding.mediaList.setLayoutManager(new LinearLayoutManager(this, RecyclerView.HORIZONTAL, false)); +// viewerBinding.mediaList.setAdapter(mediaAdapter); +// viewerBinding.mediaList.setVisibility(View.GONE); +// +// swipeEvent = isRight -> { +// final List itemGetterItems; +// final boolean isSwipeable; +// +// // if (postItemType == PostItemType.SAVED && SavedViewerFragment.itemGetter != null) { +// // itemGetterItems = SavedViewerFragment.itemGetter.get(postItemType); +// // isSwipeable = !(itemGetterItems.size() < 1 || postItemType == PostItemType.SAVED && isFromShare); +// // } else +// if (postItemType != null && MainActivityBackup.itemGetter != null) { +// itemGetterItems = MainActivityBackup.itemGetter.get(postItemType); +// isSwipeable = !(itemGetterItems.size() < 1 || postItemType == PostItemType.MAIN && isFromShare); +// } else { +// itemGetterItems = null; +// isSwipeable = false; +// } +// +// final BasePostModel[] basePostModels = mediaAdapter.getPostModels(); +// final int slides = basePostModels.length; +// +// int position = postModel.getPosition(); +// +// if (isRight) { +// --slidePos; +// if (!isSwipeable && slidePos < 0) slidePos = 0; +// if (slides > 0 && slidePos >= 0) { +// if (basePostModels[slidePos] instanceof ViewerPostModel) { +// viewerPostModel = (ViewerPostModel) basePostModels[slidePos]; +// } +// refreshPost(); +// return; +// } +// if (isSwipeable && --position < 0) position = itemGetterItems.size() - 1; +// } else { +// ++slidePos; +// if (!isSwipeable && slidePos >= slides) slidePos = slides - 1; +// if (slides > 0 && slidePos < slides) { +// if (basePostModels[slidePos] instanceof ViewerPostModel) { +// viewerPostModel = (ViewerPostModel) basePostModels[slidePos]; +// } +// refreshPost(); +// return; +// } +// if (isSwipeable && ++position >= itemGetterItems.size()) position = 0; +// } +// +// if (isSwipeable) { +// slidePos = 0; +// ok = false; +// Log.d("AWAISKING_APP", "swipe left <<< post[" + position + "]: " + postModel + " -- " + slides); +// postModel = itemGetterItems.get(position); +// postModel.setPosition(position); +// viewPost(); +// } +// }; +// gestureDetector = new GestureDetectorCompat(this, new SwipeGestureListener(swipeEvent)); +// +// viewPost(); +// } +// +// private void viewPost() { +// lastSlidePos = 0; +// mediaAdapter.setData(null); +// viewsContainer.setVisibility(View.GONE); +// viewerCaptionParent.setVisibility(View.GONE); +// viewerBinding.mediaList.setVisibility(View.GONE); +// viewerBinding.btnDownload.setVisibility(View.GONE); +// viewerBinding.bottomPanel.btnMute.setVisibility(View.GONE); +// viewerBinding.bottomPanel.tvPostDate.setVisibility(View.GONE); +// viewerBinding.bottomPanel.btnComments.setVisibility(View.GONE); +// viewerBinding.bottomPanel.btnDownload.setVisibility(View.INVISIBLE); +// viewerBinding.bottomPanel.viewerCaption.setText(null); +// viewerBinding.bottomPanel.viewerCaption.setMentionClickListener(null); +// +// viewerBinding.playerView.setVisibility(View.GONE); +// viewerBinding.playerView.setPlayer(null); +// viewerBinding.imageViewer.setController(null); +// +// if (postModel.getShortCode() != null) +// new PostFetcher(postModel.getShortCode(), pfl).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// else if (postModel.getPostId() != null) +// new iPostFetcher(postModel.getPostId(), pfl).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } +// +// private void searchUsername(final String text) { +// // startActivity( +// // new Intent(getApplicationContext(), ProfileViewer.class) +// // .putExtra(Constants.EXTRAS_USERNAME, text) +// // ); +// } +// +// private void setupVideo() { +// viewerBinding.playerView.setVisibility(View.VISIBLE); +// viewerBinding.bottomPanel.btnDownload.setVisibility(View.VISIBLE); +// viewerBinding.bottomPanel.btnMute.setVisibility(View.VISIBLE); +// viewerBinding.progressView.setVisibility(View.GONE); +// viewerBinding.imageViewer.setVisibility(View.GONE); +// viewerBinding.imageViewer.setController(null); +// +// if (viewerPostModel.getVideoViews() > -1) { +// viewsContainer.setVisibility(View.VISIBLE); +// viewerBinding.bottomPanel.tvVideoViews.setText(String.valueOf(viewerPostModel.getVideoViews())); +// } +// +// player = new SimpleExoPlayer.Builder(this).build(); +// viewerBinding.playerView.setPlayer(player); +// float vol = Utils.settingsHelper.getBoolean(Constants.MUTED_VIDEOS) ? 0f : 1f; +// if (vol == 0f && Utils.sessionVolumeFull) vol = 1f; +// +// player.setVolume(vol); +// player.setPlayWhenReady(Utils.settingsHelper.getBoolean(Constants.AUTOPLAY_VIDEOS)); +// final ProgressiveMediaSource mediaSource = new ProgressiveMediaSource.Factory(new DefaultDataSourceFactory(this, "instagram")) +// .createMediaSource(Uri.parse(url)); +// mediaSource.addEventListener(new Handler(), new MediaSourceEventListener() { +// @Override +// public void onLoadCompleted(final int windowIndex, +// @Nullable final MediaSource.MediaPeriodId mediaPeriodId, +// final LoadEventInfo loadEventInfo, +// final MediaLoadData mediaLoadData) { +// viewerBinding.progressView.setVisibility(View.GONE); +// } +// +// @Override +// public void onLoadStarted(final int windowIndex, +// @Nullable final MediaSource.MediaPeriodId mediaPeriodId, +// final LoadEventInfo loadEventInfo, +// final MediaLoadData mediaLoadData) { +// viewerBinding.progressView.setVisibility(View.VISIBLE); +// } +// +// @Override +// public void onLoadCanceled(final int windowIndex, +// @Nullable final MediaSource.MediaPeriodId mediaPeriodId, +// final LoadEventInfo loadEventInfo, +// final MediaLoadData mediaLoadData) { +// viewerBinding.progressView.setVisibility(View.GONE); +// } +// +// @Override +// public void onLoadError(final int windowIndex, +// @Nullable final MediaSource.MediaPeriodId mediaPeriodId, +// final LoadEventInfo loadEventInfo, +// final MediaLoadData mediaLoadData, +// final IOException error, +// final boolean wasCanceled) { +// viewerBinding.progressView.setVisibility(View.GONE); +// } +// }); +// player.prepare(mediaSource); +// +// player.setVolume(vol); +// viewerBinding.bottomPanel.btnMute.setImageResource(vol == 0f ? R.drawable.ic_volume_up_24 : R.drawable.ic_volume_off_24); +// +// viewerBinding.bottomPanel.btnMute.setOnClickListener(onClickListener); +// } +// +// private void setupImage() { +// viewsContainer.setVisibility(View.GONE); +// viewerBinding.playerView.setVisibility(View.GONE); +// viewerBinding.progressView.setVisibility(View.VISIBLE); +// viewerBinding.bottomPanel.btnMute.setVisibility(View.GONE); +// viewerBinding.bottomPanel.btnDownload.setVisibility(View.VISIBLE); +// viewerBinding.imageViewer.setVisibility(View.VISIBLE); +// +// final ImageRequest requestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url)) +// .setLocalThumbnailPreviewsEnabled(true) +// .setProgressiveRenderingEnabled(true) +// .build(); +// viewerBinding.imageViewer.setController( +// Fresco.newDraweeControllerBuilder() +// .setImageRequest(requestBuilder) +// .setOldController(viewerBinding.imageViewer.getController()) +// .setLowResImageRequest(ImageRequest.fromUri(url)) +// .setControllerListener(new BaseControllerListener() { +// +// @Override +// public void onFailure(final String id, final Throwable throwable) { +// viewerBinding.progressView.setVisibility(View.GONE); +// } +// +// @Override +// public void onFinalImageSet(final String id, final ImageInfo imageInfo, final Animatable animatable) { +// viewerBinding.progressView.setVisibility(View.GONE); +// } +// }) +// .build() +// ); +// } +// +// private void showDownloadDialog() { +// final ArrayList postModels = new ArrayList<>(); +// +// if (!session && viewerBinding.mediaList.getVisibility() == View.VISIBLE) { +// final DialogInterface.OnClickListener clickListener = (dialog, which) -> { +// postModels.clear(); +// +// if (which == DialogInterface.BUTTON_NEGATIVE) { +// final BasePostModel[] adapterPostModels = mediaAdapter.getPostModels(); +// for (int i = 0, size = mediaAdapter.getItemCount(); i < size; ++i) { +// if (adapterPostModels[i] instanceof ViewerPostModel) +// postModels.add(adapterPostModels[i]); +// } +// } else if (which == DialogInterface.BUTTON_POSITIVE) { +// postModels.add(viewerPostModel); +// } else { +// session = true; +// postModels.add(viewerPostModel); +// } +// +// if (postModels.size() > 0) +// Utils.batchDownload(this, viewerPostModel.getProfileModel().getUsername(), DownloadMethod.DOWNLOAD_POST_VIEWER, postModels); +// }; +// +// new AlertDialog.Builder(this).setTitle(R.string.post_viewer_download_dialog_title) +// .setMessage(R.string.post_viewer_download_message) +// .setNeutralButton(R.string.post_viewer_download_session, clickListener) +// .setPositiveButton(R.string.post_viewer_download_current, clickListener) +// .setNegativeButton(R.string.post_viewer_download_album, clickListener).show(); +// } else { +// Utils.batchDownload(this, viewerPostModel.getProfileModel().getUsername(), DownloadMethod.DOWNLOAD_POST_VIEWER, +// Collections.singletonList(viewerPostModel)); +// } +// } +// +// @Override +// public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) { +// super.onRequestPermissionsResult(requestCode, permissions, grantResults); +// if (requestCode == 8020 && grantResults[0] == PackageManager.PERMISSION_GRANTED) +// showDownloadDialog(); +// } +// +// @Override +// protected void onActivityResult(final int requestCode, final int resultCode, @Nullable final Intent data) { +// super.onActivityResult(requestCode, resultCode, data); +// if (resultCode == 6969) { +// setResult(RESULT_OK); +// finish(); +// } +// } +// +// @Override +// public void onPause() { +// super.onPause(); +// if (Build.VERSION.SDK_INT < 24) releasePlayer(); +// } +// +// @Override +// public void onStop() { +// super.onStop(); +// if (Build.VERSION.SDK_INT >= 24) releasePlayer(); +// } +// +// @Override +// protected void onResume() { +// super.onResume(); +// if (player == null && viewerPostModel != null && viewerPostModel.getItemType() == MediaItemType.MEDIA_TYPE_VIDEO) +// setupVideo(); +// else if (player != null) { +// player.setPlayWhenReady(true); +// player.getPlaybackState(); +// } +// } +// +// private void refreshPost() { +// if (containerLayoutParams.weight != 3.3f) { +// containerLayoutParams.weight = (viewerBinding.mediaList.getVisibility() == View.VISIBLE) ? 1.35f : 1.9f; +// viewerBinding.container.setLayoutParams(containerLayoutParams); +// } +// if (viewerBinding.mediaList.getVisibility() == View.VISIBLE) { +// ViewerPostModel item = mediaAdapter.getItemAt(lastSlidePos); +// if (item != null) { +// item.setCurrentSlide(false); +// mediaAdapter.notifyItemChanged(lastSlidePos, item); +// } +// +// item = mediaAdapter.getItemAt(slidePos); +// if (item != null) { +// item.setCurrentSlide(true); +// mediaAdapter.notifyItemChanged(slidePos, item); +// } +// } +// lastSlidePos = slidePos; +// +// postCaption = viewerPostModel.getPostCaption(); +// +// if (Utils.hasMentions(postCaption)) { +// viewerBinding.bottomPanel.viewerCaption.setText(Utils.getMentionText(postCaption), TextView.BufferType.SPANNABLE); +// viewerBinding.bottomPanel.viewerCaption.setMentionClickListener((view, text, isHashtag, isLocation) -> searchUsername(text)); +// } else { +// viewerBinding.bottomPanel.viewerCaption.setMentionClickListener(null); +// viewerBinding.bottomPanel.viewerCaption.setText(postCaption); +// } +// +// setupPostInfoBar("@" + viewerPostModel.getProfileModel().getUsername(), viewerPostModel.getItemType(), +// viewerPostModel.getLocationName(), viewerPostModel.getLocation()); +// +// if (postModel instanceof PostModel) { +// final PostModel postModel = (PostModel) this.postModel; +// postModel.setPostId(viewerPostModel.getPostId()); +// postModel.setTimestamp(viewerPostModel.getTimestamp()); +// postModel.setPostCaption(viewerPostModel.getPostCaption()); +// if (liked == true) { +// viewerBinding.btnLike.setText(resources.getString(R.string.unlike, viewerPostModel.getLikes() +// + ((ok && viewerPostModel.getLike() != liked) ? (liked ? 1L : -1L) : 0L))); +// viewerBinding.btnLike.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// getApplicationContext(), R.color.btn_pink_background))); +// } else { +// viewerBinding.btnLike.setText(resources.getString(R.string.like, viewerPostModel.getLikes() +// + ((ok && viewerPostModel.getLike() != liked) ? (liked ? 1L : -1L) : 0L))); +// viewerBinding.btnLike.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// getApplicationContext(), R.color.btn_lightpink_background))); +// } +// if (saved == true) { +// viewerBinding.btnBookmark.setText(R.string.unbookmark); +// viewerBinding.btnBookmark.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// getApplicationContext(), R.color.btn_orange_background))); +// } else { +// viewerBinding.btnBookmark.setText(R.string.bookmark); +// viewerBinding.btnBookmark.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// getApplicationContext(), R.color.btn_lightorange_background))); +// } +// } +// +// viewerBinding.bottomPanel.tvPostDate.setText(viewerPostModel.getPostDate()); +// viewerBinding.bottomPanel.tvPostDate.setVisibility(containerLayoutParams.weight != 3.3f ? View.VISIBLE : View.GONE); +// viewerBinding.bottomPanel.tvPostDate.setSelected(true); +// +// url = viewerPostModel.getDisplayUrl(); +// releasePlayer(); +// +// viewerBinding.btnDownload.setVisibility(containerLayoutParams.weight == 3.3f ? View.VISIBLE : View.GONE); +// if (viewerPostModel.getItemType() == MediaItemType.MEDIA_TYPE_VIDEO) setupVideo(); +// else setupImage(); +// } +// +// private void releasePlayer() { +// if (player != null) { +// player.release(); +// player = null; +// } +// } +// +// private void setupPostInfoBar(final String from, final MediaItemType mediaItemType, final String locationName, final String location) { +// if (prevUsername == null || !prevUsername.equals(from)) { +// // viewerBinding.topPanel.ivProfilePic.setImageBitmap(null); +// // viewerBinding.topPanel.ivProfilePic.setImageDrawable(null); +// // viewerBinding.topPanel.ivProfilePic.setImageResource(0); +// viewerBinding.topPanel.ivProfilePic.setImageRequest(null); +// +// if (!Utils.isEmpty(from) && from.charAt(0) == '@') +// new ProfileFetcher(from.substring(1), result -> { +// profileModel = result; +// +// if (result != null) { +// // final String hdProfilePic = result.getHdProfilePic(); +// // final String sdProfilePic = result.getSdProfilePic(); +// postUserId = result.getId(); +// +// // final boolean hdPicEmpty = Utils.isEmpty(hdProfilePic); +// // glideRequestManager.load(hdPicEmpty ? sdProfilePic : hdProfilePic).listener(new RequestListener() { +// // private boolean loaded = true; +// // +// // @Override +// // public boolean onLoadFailed(@Nullable final GlideException e, final Object model, final Target target, final boolean isFirstResource) { +// // viewerBinding.topPanel.ivProfilePic.setEnabled(false); +// // viewerBinding.topPanel.ivProfilePic.setOnClickListener(null); +// // if (loaded) { +// // loaded = false; +// // if (!Utils.isEmpty(sdProfilePic)) glideRequestManager.load(sdProfilePic).listener(this) +// // .into(viewerBinding.topPanel.ivProfilePic); +// // } +// // return false; +// // } +// // +// // @Override +// // public boolean onResourceReady(final Drawable resource, final Object model, final Target target, final DataSource dataSource, final boolean isFirstResource) { +// // viewerBinding.topPanel.ivProfilePic.setEnabled(true); +// // viewerBinding.topPanel.ivProfilePic.setOnClickListener(onClickListener); +// // return false; +// // } +// // }).into(viewerBinding.topPanel.ivProfilePic); +// viewerBinding.topPanel.ivProfilePic.setImageURI(profileModel.getSdProfilePic()); +// +// final View viewStoryPost = findViewById(R.id.viewStoryPost); +// if (viewStoryPost != null) { +// viewStoryPost.setOnClickListener(v -> { +// if (result.isPrivate()) +// Toast.makeText(getApplicationContext(), R.string.share_private_post, Toast.LENGTH_LONG).show(); +// Intent sharingIntent = new Intent(Intent.ACTION_SEND); +// sharingIntent.setType("text/plain"); +// sharingIntent.putExtra(Intent.EXTRA_TEXT, "https://instagram.com/p/" + postModel.getShortCode()); +// startActivity(Intent.createChooser(sharingIntent, +// (result.isPrivate()) +// ? getString(R.string.share_private_post) +// : getString(R.string.share_public_post))); +// }); +// } +// } +// }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// prevUsername = from; +// } +// +// final String titlePrefix = resources.getString(mediaItemType == MediaItemType.MEDIA_TYPE_VIDEO ? +// R.string.post_viewer_video_post : R.string.post_viewer_image_post); +// if (Utils.isEmpty(from)) viewerBinding.topPanel.title.setText(titlePrefix); +// else { +// final int titleLen = from.length(); +// final SpannableString spannableString = new SpannableString(from); +// spannableString.setSpan(new CommentMentionClickSpan(), 0, titleLen, 0); +// viewerBinding.topPanel.title.setText(spannableString); +// } +// +// if (location == null) { +// viewerBinding.topPanel.location.setVisibility(View.GONE); +// viewerBinding.topPanel.title.setLayoutParams(new RelativeLayout.LayoutParams( +// RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT +// )); +// } else { +// viewerBinding.topPanel.location.setVisibility(View.VISIBLE); +// viewerBinding.topPanel.location.setText(locationName); +// viewerBinding.topPanel.location.setOnClickListener(v -> searchUsername(location)); +// viewerBinding.topPanel.title.setLayoutParams(new RelativeLayout.LayoutParams( +// RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT +// )); +// } +// } +// +// private void toggleFullscreen() { +// final View decorView = getWindow().getDecorView(); +// int newUiOptions = decorView.getSystemUiVisibility(); +// newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; +// newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN; +// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) +// newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; +// decorView.setSystemUiVisibility(newUiOptions); +// } +// +// class PostAction extends AsyncTask { +// String action; +// +// protected Void doInBackground(String... rawAction) { +// action = rawAction[0]; +// final String url = "https://www.instagram.com/web/" + action + "/" + postModel.getPostId() + "/" + (action == "save" ? +// (saved ? "unsave/" : "save/") : +// (liked ? "unlike/" : "like/")); +// try { +// final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); +// urlConnection.setRequestMethod("POST"); +// urlConnection.setUseCaches(false); +// urlConnection.setRequestProperty("User-Agent", Constants.USER_AGENT); +// urlConnection.setRequestProperty("x-csrftoken", +// settingsHelper.getString(Constants.COOKIE).split("csrftoken=")[1].split(";")[0]); +// urlConnection.connect(); +// if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { +// ok = true; +// } +// urlConnection.disconnect(); +// } catch (Throwable ex) { +// Log.e("austin_debug", action + ": " + ex); +// } +// return null; +// } +// +// @Override +// protected void onPostExecute(Void result) { +// if (ok == true && action == "likes") { +// liked = !liked; +// refreshPost(); +// } else if (ok == true && action == "save") { +// saved = !saved; +// refreshPost(); +// } else +// Toast.makeText(getApplicationContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); +// } +// } +// } diff --git a/app/src/main/java/awais/instagrabber/activities/ProfileViewer.java b/app/src/main/java/awais/instagrabber/activities/ProfileViewer.java index 51d0ef5c..16744a4d 100755 --- a/app/src/main/java/awais/instagrabber/activities/ProfileViewer.java +++ b/app/src/main/java/awais/instagrabber/activities/ProfileViewer.java @@ -1,950 +1,950 @@ -package awais.instagrabber.activities; - -import android.content.DialogInterface; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.res.ColorStateList; -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Typeface; -import android.net.Uri; -import android.os.AsyncTask; -import android.os.Bundle; -import android.text.SpannableStringBuilder; -import android.text.method.LinkMovementMethod; -import android.text.style.RelativeSizeSpan; -import android.text.style.StyleSpan; -import android.util.Log; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.ArrayAdapter; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; -import androidx.core.content.ContextCompat; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; - -import java.io.DataOutputStream; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; - -import awais.instagrabber.BuildConfig; -import awais.instagrabber.R; -import awais.instagrabber.adapters.HighlightsAdapter; -import awais.instagrabber.adapters.PostsAdapter; -import awais.instagrabber.asyncs.HashtagFetcher; -import awais.instagrabber.asyncs.HighlightsFetcher; -import awais.instagrabber.asyncs.LocationFetcher; -import awais.instagrabber.asyncs.PostsFetcher; -import awais.instagrabber.asyncs.ProfileFetcher; -import awais.instagrabber.asyncs.i.iStoryStatusFetcher; -import awais.instagrabber.customviews.RamboTextView; -import awais.instagrabber.customviews.helpers.GridAutofitLayoutManager; -import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration; -import awais.instagrabber.customviews.helpers.RecyclerLazyLoader; -import awais.instagrabber.databinding.ActivityProfileBinding; -import awais.instagrabber.fragments.SavedViewerFragment; -import awais.instagrabber.interfaces.FetchListener; -import awais.instagrabber.interfaces.MentionClickListener; -import awais.instagrabber.models.BasePostModel; -import awais.instagrabber.models.HashtagModel; -import awais.instagrabber.models.HighlightModel; -import awais.instagrabber.models.LocationModel; -import awais.instagrabber.models.PostModel; -import awais.instagrabber.models.ProfileModel; -import awais.instagrabber.models.StoryModel; -import awais.instagrabber.models.enums.DownloadMethod; -import awais.instagrabber.models.enums.PostItemType; -import awais.instagrabber.utils.Constants; -import awais.instagrabber.utils.DataBox; -import awais.instagrabber.utils.Utils; -import awaisomereport.LogCollector; - -import static awais.instagrabber.utils.Constants.AUTOLOAD_POSTS; -import static awais.instagrabber.utils.Utils.logCollector; - -@Deprecated -public final class ProfileViewer extends BaseLanguageActivity implements SwipeRefreshLayout.OnRefreshListener { - private final ArrayList allItems = new ArrayList<>(), selectedItems = new ArrayList<>(); - private static AsyncTask currentlyExecuting; - private final boolean autoloadPosts = Utils.settingsHelper.getBoolean(AUTOLOAD_POSTS); - private boolean hasNextPage = false; - private View collapsingToolbar; - private String endCursor = null; - private ProfileModel profileModel; - private HashtagModel hashtagModel; - private LocationModel locationModel; - private StoryModel[] storyModels; - private MenuItem downloadAction, favouriteAction; - private final FetchListener postsFetchListener = new FetchListener() { - @Override - public void onResult(final PostModel[] result) { - if (result != null) { - final int oldSize = allItems.size(); - allItems.addAll(Arrays.asList(result)); - - postsAdapter.notifyItemRangeInserted(oldSize, result.length); - - profileBinding.profileView.mainPosts.post(() -> { - profileBinding.profileView.mainPosts.setNestedScrollingEnabled(true); - profileBinding.profileView.mainPosts.setVisibility(View.VISIBLE); - }); - - if (isHashtag) - profileBinding.toolbar.toolbar.setTitle(userQuery); - else if (isLocation) - profileBinding.toolbar.toolbar.setTitle(locationModel.getName()); - else profileBinding.toolbar.toolbar.setTitle("@" + profileModel.getUsername()); - - final PostModel model = result[result.length - 1]; - if (model != null) { - endCursor = model.getEndCursor(); - hasNextPage = model.hasNextPage(); - if (autoloadPosts && hasNextPage) - currentlyExecuting = new PostsFetcher( - profileModel != null ? profileModel.getId() - : (hashtagModel != null ? (hashtagModel.getName()) : locationModel.getId()), - profileModel != null ? PostItemType.MAIN : (hashtagModel != null ? PostItemType.HASHTAG : PostItemType.LOCATION), - endCursor, - this) - .setUsername((isLocation || isHashtag) ? null : profileModel.getUsername()) - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - else { - profileBinding.profileView.swipeRefreshLayout.setRefreshing(false); - } - model.setPageCursor(false, null); - } - } else { - profileBinding.profileView.swipeRefreshLayout.setRefreshing(false); - profileBinding.profileView.privatePage1.setImageResource(R.drawable.ic_cancel); - profileBinding.profileView.privatePage2.setText(R.string.empty_acc); - profileBinding.profileView.privatePage.setVisibility(View.VISIBLE); - } - } - }; - private final MentionClickListener mentionClickListener = new MentionClickListener() { - @Override - public void onClick(final RamboTextView view, final String text, final boolean isHashtag, final boolean isLocation) { - startActivity(new Intent(getApplicationContext(), ProfileViewer.class).putExtra(Constants.EXTRAS_USERNAME, text)); - } - }; - public final HighlightsAdapter highlightsAdapter = new HighlightsAdapter(null, new View.OnClickListener() { - @Override - public void onClick(final View v) { - final Object tag = v.getTag(); - if (tag instanceof HighlightModel) { - final HighlightModel highlightModel = (HighlightModel) tag; - new iStoryStatusFetcher(highlightModel.getId(), null, false, false, - (!isLoggedIn && Utils.settingsHelper.getBoolean(Constants.STORIESIG)), true, result -> { - if (result != null && result.length > 0) { - // startActivity(new Intent(ProfileViewer.this, StoryViewer.class) - // .putExtra(Constants.EXTRAS_USERNAME, userQuery.replace("@", "")) - // .putExtra(Constants.EXTRAS_HIGHLIGHT, highlightModel.getTitle()) - // .putExtra(Constants.EXTRAS_STORIES, result) - // ); - } else - Toast.makeText(ProfileViewer.this, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); - }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - } - }); - private Resources resources; - private RecyclerLazyLoader lazyLoader; - private boolean isHashtag, isUser, isLocation; - private PostsAdapter postsAdapter; - private String cookie = Utils.settingsHelper.getString(Constants.COOKIE), userQuery; - public boolean isLoggedIn = !Utils.isEmpty(cookie); - private ActivityProfileBinding profileBinding; - private ArrayAdapter profileDialogAdapter; - private DialogInterface.OnClickListener profileDialogListener; - - protected void onCreate(@Nullable final Bundle savedInstanceState) { - stopCurrentExecutor(); - super.onCreate(savedInstanceState); - - final Intent intent = getIntent(); - if (intent == null || !intent.hasExtra(Constants.EXTRAS_USERNAME) - || Utils.isEmpty((userQuery = intent.getStringExtra(Constants.EXTRAS_USERNAME)))) { - Utils.errorFinish(this); - return; - } - - userQuery = (userQuery.contains("/") || userQuery.startsWith("#") || userQuery.startsWith("@")) ? userQuery : ("@" + userQuery); - - profileBinding = ActivityProfileBinding.inflate(getLayoutInflater()); - setContentView(profileBinding.getRoot()); - - resources = getResources(); - - profileDialogAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, - new String[]{resources.getString(R.string.view_pfp), resources.getString(R.string.show_stories)}); - profileDialogListener = (dialog, which) -> { - final Intent newintent; - if (which == 0 || storyModels == null || storyModels.length < 1) { - newintent = new Intent(this, ProfilePicViewer.class).putExtra( - ((hashtagModel != null) - ? Constants.EXTRAS_HASHTAG - : (locationModel != null ? Constants.EXTRAS_LOCATION : Constants.EXTRAS_PROFILE)), - ((hashtagModel != null) ? hashtagModel : (locationModel != null ? locationModel : profileModel))); - } - // else - // newintent = new Intent(this, StoryViewer.class).putExtra(Constants.EXTRAS_USERNAME, userQuery.replace("@", "")) - // .putExtra(Constants.EXTRAS_STORIES, storyModels) - // .putExtra(Constants.EXTRAS_HASHTAG, (hashtagModel != null)); - // startActivity(newintent); - }; - - profileBinding.profileView.swipeRefreshLayout.setOnRefreshListener(this); - profileBinding.profileView.mainUrl.setMovementMethod(new LinkMovementMethod()); - - isLoggedIn = !Utils.isEmpty(cookie); - - collapsingToolbar = profileBinding.profileView.appBarLayout.getChildAt(0); - - profileBinding.profileView.mainPosts.setNestedScrollingEnabled(false); - profileBinding.profileView.highlightsList.setLayoutManager( - new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false)); - profileBinding.profileView.highlightsList.setAdapter(highlightsAdapter); - - setSupportActionBar(profileBinding.toolbar.toolbar); - - // change the next number to adjust grid - final GridAutofitLayoutManager layoutManager = new GridAutofitLayoutManager(ProfileViewer.this, Utils.convertDpToPx(110)); - profileBinding.profileView.mainPosts.setLayoutManager(layoutManager); - profileBinding.profileView.mainPosts.addItemDecoration(new GridSpacingItemDecoration(Utils.convertDpToPx(4))); - // profileBinding.profileView.mainPosts.setAdapter(postsAdapter = new PostsAdapter(allItems, v -> { - // final Object tag = v.getTag(); - // if (tag instanceof PostModel) { - // final PostModel postModel = (PostModel) tag; - // - // if (postsAdapter.isSelecting) toggleSelection(postModel); - // else startActivity(new Intent(ProfileViewer.this, PostViewer.class) - // .putExtra(Constants.EXTRAS_INDEX, postModel.getPosition()) - // .putExtra(Constants.EXTRAS_POST, postModel) - // .putExtra(Constants.EXTRAS_USER, userQuery) - // .putExtra(Constants.EXTRAS_TYPE, ItemGetType.MAIN_ITEMS)); - // } - // }, v -> { // long click listener - // final Object tag = v.getTag(); - // if (tag instanceof PostModel) { - // postsAdapter.isSelecting = true; - // toggleSelection((PostModel) tag); - // } - // return true; - // })); - - this.lazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> { - if ((!autoloadPosts || isHashtag) && hasNextPage) { - profileBinding.profileView.swipeRefreshLayout.setRefreshing(true); - stopCurrentExecutor(); - currentlyExecuting = new PostsFetcher(profileModel != null ? profileModel.getId() - : (hashtagModel != null - ? ("#" + hashtagModel.getName()) - : locationModel.getId()), - profileModel != null - ? PostItemType.MAIN - : (hashtagModel != null ? PostItemType.HASHTAG : PostItemType.LOCATION), - endCursor, postsFetchListener) - .setUsername((isHashtag || isLocation) ? null : profileModel.getUsername()) - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - endCursor = null; - } - }); - profileBinding.profileView.mainPosts.addOnScrollListener(lazyLoader); - - final View.OnClickListener onClickListener = v -> { - if (v == profileBinding.profileView.mainBiography) { - Utils.copyText(this, profileBinding.profileView.mainBiography.getText().toString()); - } else if (v == profileBinding.profileView.locationBiography) { - Utils.copyText(this, profileBinding.profileView.locationBiography.getText().toString()); - } else if (v == profileBinding.profileView.mainProfileImage || v == profileBinding.profileView.mainHashtagImage || v == profileBinding.profileView.mainLocationImage) { - if (storyModels == null || storyModels.length <= 0) { - profileDialogListener.onClick(null, 0); - } else { - // because sometimes configuration changes made this crash on some phones - new AlertDialog.Builder(this).setAdapter(profileDialogAdapter, profileDialogListener) - .setNeutralButton(R.string.cancel, null).show(); - } - } - }; - - profileBinding.profileView.mainBiography.setOnClickListener(onClickListener); - profileBinding.profileView.locationBiography.setOnClickListener(onClickListener); - profileBinding.profileView.mainProfileImage.setOnClickListener(onClickListener); - profileBinding.profileView.mainHashtagImage.setOnClickListener(onClickListener); - profileBinding.profileView.mainLocationImage.setOnClickListener(onClickListener); - - this.onRefresh(); - } - - @Override - public void onRefresh() { - if (lazyLoader != null) lazyLoader.resetState(); - stopCurrentExecutor(); - allItems.clear(); - selectedItems.clear(); - if (postsAdapter != null) { - // postsAdapter.isSelecting = false; - postsAdapter.notifyDataSetChanged(); - } - profileBinding.profileView.appBarLayout.setExpanded(true, true); - profileBinding.profileView.privatePage.setVisibility(View.GONE); - profileBinding.profileView.privatePage2.setTextSize(28); - // profileBinding.profileView.mainProfileImage.setImageBitmap(null); - // profileBinding.profileView.mainHashtagImage.setImageBitmap(null); - // profileBinding.profileView.mainLocationImage.setImageBitmap(null); - profileBinding.profileView.mainUrl.setText(null); - profileBinding.profileView.locationUrl.setText(null); - profileBinding.profileView.mainFullName.setText(null); - profileBinding.profileView.locationFullName.setText(null); - profileBinding.profileView.mainPostCount.setText(null); - profileBinding.profileView.mainLocPostCount.setText(null); - profileBinding.profileView.mainTagPostCount.setText(null); - profileBinding.profileView.mainFollowers.setText(null); - profileBinding.profileView.mainFollowing.setText(null); - profileBinding.profileView.mainBiography.setText(null); - profileBinding.profileView.locationBiography.setText(null); - profileBinding.profileView.mainBiography.setEnabled(false); - profileBinding.profileView.locationBiography.setEnabled(false); - profileBinding.profileView.mainProfileImage.setEnabled(false); - profileBinding.profileView.mainLocationImage.setEnabled(false); - profileBinding.profileView.mainHashtagImage.setEnabled(false); - profileBinding.profileView.mainBiography.setMentionClickListener(null); - profileBinding.profileView.locationBiography.setMentionClickListener(null); - profileBinding.profileView.mainUrl.setVisibility(View.GONE); - profileBinding.profileView.locationUrl.setVisibility(View.GONE); - profileBinding.profileView.isVerified.setVisibility(View.GONE); - profileBinding.profileView.btnFollow.setVisibility(View.GONE); - profileBinding.profileView.btnRestrict.setVisibility(View.GONE); - profileBinding.profileView.btnBlock.setVisibility(View.GONE); - profileBinding.profileView.btnSaved.setVisibility(View.GONE); - profileBinding.profileView.btnLiked.setVisibility(View.GONE); - profileBinding.profileView.btnTagged.setVisibility(View.GONE); - profileBinding.profileView.btnMap.setVisibility(View.GONE); - - profileBinding.profileView.btnFollow.setOnClickListener(profileActionListener); - profileBinding.profileView.btnRestrict.setOnClickListener(profileActionListener); - profileBinding.profileView.btnBlock.setOnClickListener(profileActionListener); - profileBinding.profileView.btnSaved.setOnClickListener(profileActionListener); - profileBinding.profileView.btnLiked.setOnClickListener(profileActionListener); - profileBinding.profileView.btnTagged.setOnClickListener(profileActionListener); - profileBinding.profileView.btnFollowTag.setOnClickListener(profileActionListener); - - profileBinding.profileView.infoContainer.setVisibility(View.GONE); - profileBinding.profileView.tagInfoContainer.setVisibility(View.GONE); - profileBinding.profileView.locInfoContainer.setVisibility(View.GONE); - - profileBinding.profileView.mainPosts.setNestedScrollingEnabled(false); - profileBinding.profileView.highlightsList.setVisibility(View.GONE); - collapsingToolbar.setVisibility(View.GONE); - highlightsAdapter.setData(null); - - profileBinding.profileView.swipeRefreshLayout.setRefreshing(userQuery != null); - if (userQuery == null) { - profileBinding.toolbar.toolbar.setTitle(R.string.app_name); - return; - } - - isHashtag = userQuery.charAt(0) == '#'; - isUser = userQuery.charAt(0) == '@'; - isLocation = userQuery.contains("/"); - collapsingToolbar.setVisibility(isUser ? View.VISIBLE : View.GONE); - - if (isHashtag) { - profileModel = null; - locationModel = null; - profileBinding.toolbar.toolbar.setTitle(userQuery); - profileBinding.profileView.tagInfoContainer.setVisibility(View.VISIBLE); - profileBinding.profileView.btnFollowTag.setVisibility(View.GONE); - - currentlyExecuting = new HashtagFetcher(userQuery.substring(1), result -> { - hashtagModel = result; - - if (hashtagModel == null) { - profileBinding.profileView.swipeRefreshLayout.setRefreshing(false); - Toast.makeText(ProfileViewer.this, R.string.error_loading_profile, Toast.LENGTH_SHORT).show(); - profileBinding.toolbar.toolbar.setTitle(R.string.app_name); - return; - } - - currentlyExecuting = new PostsFetcher(userQuery, PostItemType.HASHTAG, null, postsFetchListener) - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - - profileBinding.profileView.btnFollowTag.setVisibility(View.VISIBLE); - - if (isLoggedIn) { - new iStoryStatusFetcher(hashtagModel.getName(), null, false, true, false, false, stories -> { - storyModels = stories; - if (stories != null && stories.length > 0) - profileBinding.profileView.mainHashtagImage.setStoriesBorder(); - }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - - if (hashtagModel.getFollowing()) { - profileBinding.profileView.btnFollowTag.setText(R.string.unfollow); - profileBinding.profileView.btnFollowTag.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - ProfileViewer.this, R.color.btn_purple_background))); - } else { - profileBinding.profileView.btnFollowTag.setText(R.string.follow); - profileBinding.profileView.btnFollowTag.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - ProfileViewer.this, R.color.btn_pink_background))); - } - } else { - if (Utils.dataBox.getFavorite(userQuery) != null) { - profileBinding.profileView.btnFollowTag.setText(R.string.unfavorite_short); - profileBinding.profileView.btnFollowTag.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - ProfileViewer.this, R.color.btn_purple_background))); - } else { - profileBinding.profileView.btnFollowTag.setText(R.string.favorite_short); - profileBinding.profileView.btnFollowTag.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - ProfileViewer.this, R.color.btn_pink_background))); - } - } - - // profileBinding.profileView.mainHashtagImage.setEnabled(false); - profileBinding.profileView.mainHashtagImage.setImageURI(hashtagModel.getSdProfilePic()); - profileBinding.profileView.mainHashtagImage.setEnabled(true); - - final String postCount = String.valueOf(hashtagModel.getPostCount()); - - SpannableStringBuilder span = new SpannableStringBuilder(resources.getString(R.string.main_posts_count, postCount)); - span.setSpan(new RelativeSizeSpan(1.2f), 0, postCount.length(), 0); - span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0); - profileBinding.profileView.mainTagPostCount.setText(span); - profileBinding.profileView.mainTagPostCount.setVisibility(View.VISIBLE); - }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else if (isUser) { - hashtagModel = null; - locationModel = null; - profileBinding.toolbar.toolbar.setTitle(userQuery); - profileBinding.profileView.infoContainer.setVisibility(View.VISIBLE); - profileBinding.profileView.btnFollowTag.setVisibility(View.GONE); - - currentlyExecuting = new ProfileFetcher(userQuery.substring(1), result -> { - profileModel = result; - - if (profileModel == null) { - profileBinding.profileView.swipeRefreshLayout.setRefreshing(false); - Toast.makeText(ProfileViewer.this, R.string.error_loading_profile, Toast.LENGTH_SHORT).show(); - profileBinding.toolbar.toolbar.setTitle(R.string.app_name); - return; - } - - profileBinding.profileView.isVerified.setVisibility(profileModel.isVerified() ? View.VISIBLE : View.GONE); - final String profileId = profileModel.getId(); - - if (isLoggedIn || Utils.settingsHelper.getBoolean(Constants.STORIESIG)) { - new iStoryStatusFetcher(profileId, profileModel.getUsername(), false, false, - (!isLoggedIn && Utils.settingsHelper.getBoolean(Constants.STORIESIG)), false, - stories -> { - storyModels = stories; - if (stories != null && stories.length > 0) - profileBinding.profileView.mainProfileImage.setStoriesBorder(); - }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - - new HighlightsFetcher(profileId, (!isLoggedIn && Utils.settingsHelper.getBoolean(Constants.STORIESIG)), hls -> { - if (hls != null && hls.length > 0) { - profileBinding.profileView.highlightsList.setVisibility(View.VISIBLE); - highlightsAdapter.setData(hls); - } else profileBinding.profileView.highlightsList.setVisibility(View.GONE); - }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - if (isLoggedIn) { - final String myId = Utils.getUserIdFromCookie(cookie); - if (!profileId.equals(myId)) { - profileBinding.profileView.btnTagged.setVisibility(View.GONE); - profileBinding.profileView.btnSaved.setVisibility(View.GONE); - profileBinding.profileView.btnLiked.setVisibility(View.GONE); - profileBinding.profileView.btnFollow.setVisibility(View.VISIBLE); - if (profileModel.getFollowing() == true) { - profileBinding.profileView.btnFollow.setText(R.string.unfollow); - profileBinding.profileView.btnFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - ProfileViewer.this, R.color.btn_purple_background))); - } else if (profileModel.getRequested() == true) { - profileBinding.profileView.btnFollow.setText(R.string.cancel); - profileBinding.profileView.btnFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - ProfileViewer.this, R.color.btn_purple_background))); - } else { - profileBinding.profileView.btnFollow.setText(R.string.follow); - profileBinding.profileView.btnFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - ProfileViewer.this, R.color.btn_pink_background))); - } - profileBinding.profileView.btnRestrict.setVisibility(View.VISIBLE); - if (profileModel.getRestricted() == true) { - profileBinding.profileView.btnRestrict.setText(R.string.unrestrict); - profileBinding.profileView.btnRestrict.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - ProfileViewer.this, R.color.btn_green_background))); - } else { - profileBinding.profileView.btnRestrict.setText(R.string.restrict); - profileBinding.profileView.btnRestrict.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - ProfileViewer.this, R.color.btn_orange_background))); - } - if (profileModel.isReallyPrivate()) { - profileBinding.profileView.btnBlock.setVisibility(View.VISIBLE); - profileBinding.profileView.btnTagged.setVisibility(View.GONE); - if (profileModel.getBlocked() == true) { - profileBinding.profileView.btnBlock.setText(R.string.unblock); - profileBinding.profileView.btnBlock.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - ProfileViewer.this, R.color.btn_green_background))); - } else { - profileBinding.profileView.btnBlock.setText(R.string.block); - profileBinding.profileView.btnBlock.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - ProfileViewer.this, R.color.btn_red_background))); - } - } else { - profileBinding.profileView.btnBlock.setVisibility(View.GONE); - profileBinding.profileView.btnSaved.setVisibility(View.VISIBLE); - profileBinding.profileView.btnTagged.setVisibility(View.VISIBLE); - if (profileModel.getBlocked() == true) { - profileBinding.profileView.btnSaved.setText(R.string.unblock); - profileBinding.profileView.btnSaved.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - ProfileViewer.this, R.color.btn_green_background))); - } else { - profileBinding.profileView.btnSaved.setText(R.string.block); - profileBinding.profileView.btnSaved.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - ProfileViewer.this, R.color.btn_red_background))); - } - } - } else { - profileBinding.profileView.btnTagged.setVisibility(View.VISIBLE); - profileBinding.profileView.btnSaved.setVisibility(View.VISIBLE); - profileBinding.profileView.btnLiked.setVisibility(View.VISIBLE); - profileBinding.profileView.btnSaved.setText(R.string.saved); - profileBinding.profileView.btnSaved.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - ProfileViewer.this, R.color.btn_orange_background))); - } - } else { - if (Utils.dataBox.getFavorite(userQuery) != null) { - profileBinding.profileView.btnFollow.setText(R.string.unfavorite_short); - profileBinding.profileView.btnFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - ProfileViewer.this, R.color.btn_purple_background))); - } else { - profileBinding.profileView.btnFollow.setText(R.string.favorite_short); - profileBinding.profileView.btnFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - ProfileViewer.this, R.color.btn_pink_background))); - } - profileBinding.profileView.btnFollow.setVisibility(View.VISIBLE); - if (!profileModel.isReallyPrivate()) { - profileBinding.profileView.btnRestrict.setVisibility(View.VISIBLE); - profileBinding.profileView.btnRestrict.setText(R.string.tagged); - profileBinding.profileView.btnRestrict.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( - ProfileViewer.this, R.color.btn_blue_background))); - } - } - - // profileBinding.profileView.mainProfileImage.setEnabled(false); - profileBinding.profileView.mainProfileImage.setImageURI(profileModel.getSdProfilePic(), null); - // profileBinding.profileView.mainProfileImage.setEnabled(true); - - final long followersCount = profileModel.getFollowersCount(); - final long followingCount = profileModel.getFollowingCount(); - - final String postCount = String.valueOf(profileModel.getPostCount()); - - SpannableStringBuilder span = new SpannableStringBuilder(resources.getString(R.string.main_posts_count, postCount)); - span.setSpan(new RelativeSizeSpan(1.2f), 0, postCount.length(), 0); - span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0); - profileBinding.profileView.mainPostCount.setText(span); - - final String followersCountStr = String.valueOf(followersCount); - final int followersCountStrLen = followersCountStr.length(); - span = new SpannableStringBuilder(resources.getString(R.string.main_posts_followers, followersCountStr)); - span.setSpan(new RelativeSizeSpan(1.2f), 0, followersCountStrLen, 0); - span.setSpan(new StyleSpan(Typeface.BOLD), 0, followersCountStrLen, 0); - profileBinding.profileView.mainFollowers.setText(span); - - final String followingCountStr = String.valueOf(followingCount); - final int followingCountStrLen = followingCountStr.length(); - span = new SpannableStringBuilder(resources.getString(R.string.main_posts_following, followingCountStr)); - span.setSpan(new RelativeSizeSpan(1.2f), 0, followingCountStrLen, 0); - span.setSpan(new StyleSpan(Typeface.BOLD), 0, followingCountStrLen, 0); - profileBinding.profileView.mainFollowing.setText(span); - - profileBinding.profileView.mainFullName - .setText(Utils.isEmpty(profileModel.getName()) ? profileModel.getUsername() : profileModel.getName()); - - CharSequence biography = profileModel.getBiography(); - profileBinding.profileView.mainBiography.setCaptionIsExpandable(true); - profileBinding.profileView.mainBiography.setCaptionIsExpanded(true); - if (Utils.hasMentions(biography)) { - biography = Utils.getMentionText(biography); - profileBinding.profileView.mainBiography.setText(biography, TextView.BufferType.SPANNABLE); - profileBinding.profileView.mainBiography.setMentionClickListener(mentionClickListener); - } else { - profileBinding.profileView.mainBiography.setText(biography); - profileBinding.profileView.mainBiography.setMentionClickListener(null); - } - - final String url = profileModel.getUrl(); - if (Utils.isEmpty(url)) { - profileBinding.profileView.mainUrl.setVisibility(View.GONE); - } else { - profileBinding.profileView.mainUrl.setVisibility(View.VISIBLE); - profileBinding.profileView.mainUrl.setText(Utils.getSpannableUrl(url)); - } - - profileBinding.profileView.mainFullName.setSelected(true); - profileBinding.profileView.mainBiography.setEnabled(true); - - if (!profileModel.isReallyPrivate()) { - profileBinding.profileView.mainFollowing.setClickable(true); - profileBinding.profileView.mainFollowers.setClickable(true); - - if (isLoggedIn) { - // final View.OnClickListener followClickListener = v -> startActivity( - // new Intent(ProfileViewer.this, FollowViewerFragment.class) - // .putExtra(Constants.EXTRAS_FOLLOWERS, v == profileBinding.profileView.mainFollowers) - // .putExtra(Constants.EXTRAS_NAME, profileModel.getUsername()) - // .putExtra(Constants.EXTRAS_ID, profileId)); - // - // profileBinding.profileView.mainFollowers.setOnClickListener(followersCount > 0 ? followClickListener : null); - // profileBinding.profileView.mainFollowing.setOnClickListener(followingCount > 0 ? followClickListener : null); - } - - if (profileModel.getPostCount() == 0) { - profileBinding.profileView.swipeRefreshLayout.setRefreshing(false); - profileBinding.profileView.privatePage1.setImageResource(R.drawable.ic_cancel); - profileBinding.profileView.privatePage2.setText(R.string.empty_acc); - profileBinding.profileView.privatePage.setVisibility(View.VISIBLE); - } else { - profileBinding.profileView.swipeRefreshLayout.setRefreshing(true); - profileBinding.profileView.mainPosts.setVisibility(View.VISIBLE); - currentlyExecuting = new PostsFetcher(profileId, PostItemType.MAIN, null, postsFetchListener) - .setUsername(profileModel.getUsername()) - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - } else { - profileBinding.profileView.mainFollowers.setClickable(false); - profileBinding.profileView.mainFollowing.setClickable(false); - profileBinding.profileView.swipeRefreshLayout.setRefreshing(false); - // error - profileBinding.profileView.privatePage1.setImageResource(R.drawable.lock); - profileBinding.profileView.privatePage2.setText(R.string.priv_acc); - profileBinding.profileView.privatePage.setVisibility(View.VISIBLE); - profileBinding.profileView.mainPosts.setVisibility(View.GONE); - } - } - ).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else if (isLocation) { - profileModel = null; - hashtagModel = null; - profileBinding.toolbar.toolbar.setTitle(userQuery); - profileBinding.profileView.locInfoContainer.setVisibility(View.VISIBLE); - - currentlyExecuting = new LocationFetcher(userQuery.split("/")[0], result -> { - locationModel = result; - - if (locationModel == null) { - profileBinding.profileView.swipeRefreshLayout.setRefreshing(false); - Toast.makeText(ProfileViewer.this, R.string.error_loading_profile, Toast.LENGTH_SHORT).show(); - profileBinding.toolbar.toolbar.setTitle(R.string.app_name); - return; - } - profileBinding.toolbar.toolbar.setTitle(locationModel.getName()); - - final String profileId = locationModel.getId(); - - if (isLoggedIn) { - new iStoryStatusFetcher(profileId.split("/")[0], null, true, false, false, false, stories -> { - storyModels = stories; - if (stories != null && stories.length > 0) - profileBinding.profileView.mainLocationImage.setStoriesBorder(); - }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - // profileBinding.profileView.mainLocationImage.setEnabled(false); - profileBinding.profileView.mainLocationImage.setImageURI(locationModel.getSdProfilePic()); - profileBinding.profileView.mainLocationImage.setEnabled(true); - - final String postCount = String.valueOf(locationModel.getPostCount()); - - SpannableStringBuilder span = new SpannableStringBuilder(resources.getString(R.string.main_posts_count, postCount)); - span.setSpan(new RelativeSizeSpan(1.2f), 0, postCount.length(), 0); - span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0); - profileBinding.profileView.mainLocPostCount.setText(span); - - profileBinding.profileView.locationFullName.setText(locationModel.getName()); - - CharSequence biography = locationModel.getBio(); - profileBinding.profileView.locationBiography.setCaptionIsExpandable(true); - profileBinding.profileView.locationBiography.setCaptionIsExpanded(true); - - if (Utils.isEmpty(biography)) { - profileBinding.profileView.locationBiography.setVisibility(View.GONE); - } else if (Utils.hasMentions(biography)) { - profileBinding.profileView.locationBiography.setVisibility(View.VISIBLE); - biography = Utils.getMentionText(biography); - profileBinding.profileView.locationBiography.setText(biography, TextView.BufferType.SPANNABLE); - profileBinding.profileView.locationBiography.setMentionClickListener(mentionClickListener); - } else { - profileBinding.profileView.locationBiography.setVisibility(View.VISIBLE); - profileBinding.profileView.locationBiography.setText(biography); - profileBinding.profileView.locationBiography.setMentionClickListener(null); - } - - if (!locationModel.getGeo().startsWith("geo:0.0,0.0?z=17")) { - profileBinding.profileView.btnMap.setVisibility(View.VISIBLE); - profileBinding.profileView.btnMap.setOnClickListener(v -> { - final Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(locationModel.getGeo())); - startActivity(intent); - }); - } else { - profileBinding.profileView.btnMap.setVisibility(View.GONE); - profileBinding.profileView.btnMap.setOnClickListener(null); - } - - final String url = locationModel.getUrl(); - if (Utils.isEmpty(url)) { - profileBinding.profileView.locationUrl.setVisibility(View.GONE); - } else if (!url.startsWith("http")) { - profileBinding.profileView.locationUrl.setVisibility(View.VISIBLE); - profileBinding.profileView.locationUrl.setText(Utils.getSpannableUrl("http://" + url)); - } else { - profileBinding.profileView.locationUrl.setVisibility(View.VISIBLE); - profileBinding.profileView.locationUrl.setText(Utils.getSpannableUrl(url)); - } - - profileBinding.profileView.locationFullName.setSelected(true); - profileBinding.profileView.locationBiography.setEnabled(true); - - if (locationModel.getPostCount() == 0) { - profileBinding.profileView.swipeRefreshLayout.setRefreshing(false); - profileBinding.profileView.privatePage1.setImageResource(R.drawable.ic_cancel); - profileBinding.profileView.privatePage2.setText(R.string.empty_acc); - profileBinding.profileView.privatePage.setVisibility(View.VISIBLE); - } else { - profileBinding.profileView.swipeRefreshLayout.setRefreshing(true); - profileBinding.profileView.mainPosts.setVisibility(View.VISIBLE); - currentlyExecuting = new PostsFetcher(profileId, PostItemType.LOCATION, null, postsFetchListener) - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - } - ).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - } - - public static void stopCurrentExecutor() { - if (currentlyExecuting != null) { - try { - currentlyExecuting.cancel(true); - } catch (final Exception e) { - if (logCollector != null) - logCollector.appendException(e, LogCollector.LogFile.MAIN_HELPER, "stopCurrentExecutor"); - if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e); - } - } - } - - @Override - public boolean onCreateOptionsMenu(final Menu menu) { - getMenuInflater().inflate(R.menu.saved, menu); - - downloadAction = menu.findItem(R.id.downloadAction); - downloadAction.setVisible(false); - - favouriteAction = menu.findItem(R.id.favouriteAction); - favouriteAction.setVisible(!Utils.isEmpty(cookie)); - favouriteAction.setIcon(Utils.dataBox.getFavorite(userQuery) == null ? R.drawable.ic_not_liked : R.drawable.ic_like); - - downloadAction.setOnMenuItemClickListener(item -> { - if (selectedItems.size() > 0) { - Utils.batchDownload(this, userQuery, DownloadMethod.DOWNLOAD_MAIN, selectedItems); - } - return true; - }); - - favouriteAction.setOnMenuItemClickListener(item -> { - if (Utils.dataBox.getFavorite(userQuery) == null) { - Utils.dataBox.addFavorite(new DataBox.FavoriteModel(userQuery, System.currentTimeMillis(), - locationModel != null - ? locationModel.getName() - : userQuery.replaceAll("^@", ""))); - favouriteAction.setIcon(R.drawable.ic_like); - } else { - Utils.dataBox.delFavorite(new DataBox.FavoriteModel(userQuery, - Long.parseLong(Utils.dataBox.getFavorite(userQuery).split("/")[1]), - locationModel != null - ? locationModel.getName() - : userQuery.replaceAll("^@", ""))); - favouriteAction.setIcon(R.drawable.ic_not_liked); - } - return true; - }); - - return true; - } - - private void toggleSelection(final PostModel postModel) { - if (postModel != null && postsAdapter != null) { - if (postModel.isSelected()) selectedItems.remove(postModel); - else if (selectedItems.size() >= 100) { - Toast.makeText(ProfileViewer.this, R.string.downloader_too_many, Toast.LENGTH_SHORT); - return; - } else selectedItems.add(postModel); - postModel.setSelected(!postModel.isSelected()); - notifyAdapter(postModel); - } - } - - private void notifyAdapter(final PostModel postModel) { - // if (selectedItems.size() < 1) postsAdapter.isSelecting = false; - // if (postModel.getPosition() < 0) postsAdapter.notifyDataSetChanged(); - // else postsAdapter.notifyItemChanged(postModel.getPosition(), postModel); - // - // if (downloadAction != null) downloadAction.setVisible(postsAdapter.isSelecting); - } - - @Override - public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults); - if (requestCode == 8020 && grantResults[0] == PackageManager.PERMISSION_GRANTED && selectedItems.size() > 0) - Utils.batchDownload(this, userQuery, DownloadMethod.DOWNLOAD_MAIN, selectedItems); - } - - public void deselectSelection(final BasePostModel postModel) { - if (postModel instanceof PostModel) { - selectedItems.remove(postModel); - postModel.setSelected(false); - if (postsAdapter != null) notifyAdapter((PostModel) postModel); - } - } - - class MyTask extends AsyncTask { - private Bitmap mIcon_val; - - protected Void doInBackground(Void... voids) { - try { - String url; - if (hashtagModel != null) { - url = hashtagModel.getSdProfilePic(); - } else if (locationModel != null) { - url = locationModel.getSdProfilePic(); - } else { - url = profileModel.getSdProfilePic(); - } - mIcon_val = BitmapFactory.decodeStream((InputStream) new URL(url).getContent()); - } catch (Throwable ex) { - Log.e("austin_debug", "bitmap: " + ex); - } - return null; - } - - @Override - protected void onPostExecute(Void result) { - if (hashtagModel != null) - profileBinding.profileView.mainHashtagImage.setImageBitmap(mIcon_val); - else if (locationModel != null) - profileBinding.profileView.mainLocationImage.setImageBitmap(mIcon_val); - else profileBinding.profileView.mainProfileImage.setImageBitmap(mIcon_val); - } - } - - private final View.OnClickListener profileActionListener = new View.OnClickListener() { - @Override - public void onClick(final View v) { - final boolean iamme = (isLoggedIn && profileModel != null) && Utils.getUserIdFromCookie(cookie).equals(profileModel.getId()); - if (!isLoggedIn && Utils.dataBox.getFavorite(userQuery) != null && v == profileBinding.profileView.btnFollow) { - Utils.dataBox.delFavorite(new DataBox.FavoriteModel(userQuery, - Long.parseLong(Utils.dataBox.getFavorite(userQuery).split("/")[1]), - locationModel != null - ? locationModel.getName() - : userQuery.replaceAll("^@", ""))); - onRefresh(); - } else if (!isLoggedIn && (v == profileBinding.profileView.btnFollow || v == profileBinding.profileView.btnFollowTag)) { - Utils.dataBox.addFavorite(new DataBox.FavoriteModel(userQuery, System.currentTimeMillis(), - locationModel != null - ? locationModel.getName() - : userQuery.replaceAll("^@", ""))); - onRefresh(); - } else if (v == profileBinding.profileView.btnFollow) { - new ProfileAction().execute("follow"); - } else if (v == profileBinding.profileView.btnRestrict && isLoggedIn) { - new ProfileAction().execute("restrict"); - } else if (v == profileBinding.profileView.btnSaved && !iamme) { - new ProfileAction().execute("block"); - } else if (v == profileBinding.profileView.btnFollowTag) { - new ProfileAction().execute("followtag"); - } else if (v == profileBinding.profileView.btnTagged || (v == profileBinding.profileView.btnRestrict && !isLoggedIn)) { - startActivity(new Intent(ProfileViewer.this, SavedViewerFragment.class) - .putExtra(Constants.EXTRAS_INDEX, "%" + profileModel.getId()) - .putExtra(Constants.EXTRAS_USER, "@" + profileModel.getUsername()) - ); - } else if (v == profileBinding.profileView.btnSaved) { - startActivity(new Intent(ProfileViewer.this, SavedViewerFragment.class) - .putExtra(Constants.EXTRAS_INDEX, "$" + profileModel.getId()) - .putExtra(Constants.EXTRAS_USER, "@" + profileModel.getUsername()) - ); - } else if (v == profileBinding.profileView.btnLiked) { - startActivity(new Intent(ProfileViewer.this, SavedViewerFragment.class) - .putExtra(Constants.EXTRAS_INDEX, "^" + profileModel.getId()) - .putExtra(Constants.EXTRAS_USER, "@" + profileModel.getUsername()) - ); - } - } - }; - - class ProfileAction extends AsyncTask { - boolean ok = false; - String action; - - protected Void doInBackground(String... rawAction) { - action = rawAction[0]; - final String url = "https://www.instagram.com/web/" + - ((action.equals("followtag") && hashtagModel != null) ? ("tags/" + - (hashtagModel.getFollowing() ? "unfollow/" : "follow/") + hashtagModel.getName() + "/") : ( - ((action.equals("restrict") && profileModel != null) - ? "restrict_action" - : ("friendships/" + profileModel.getId())) + "/" + - ((action.equals("follow") && profileModel != null) ? - ((profileModel.getFollowing() || - (!profileModel.getFollowing() && profileModel.getRequested())) - ? "unfollow/" : "follow/") : - ((action.equals("restrict") && profileModel != null) ? - (profileModel.getRestricted() ? "unrestrict/" : "restrict/") : - (profileModel.getBlocked() ? "unblock/" : "block/"))))); - try { - final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); - urlConnection.setRequestMethod("POST"); - urlConnection.setUseCaches(false); - urlConnection.setRequestProperty("User-Agent", Constants.USER_AGENT); - urlConnection.setRequestProperty("x-csrftoken", cookie.split("csrftoken=")[1].split(";")[0]); - if (action == "restrict") { - final String urlParameters = "target_user_id=" + profileModel.getId(); - urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - urlConnection.setRequestProperty("Content-Length", "" + - urlParameters.getBytes().length); - urlConnection.setDoOutput(true); - DataOutputStream wr = new DataOutputStream(urlConnection.getOutputStream()); - wr.writeBytes(urlParameters); - wr.flush(); - wr.close(); - } else urlConnection.connect(); - if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { - ok = true; - } else - Toast.makeText(ProfileViewer.this, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); - urlConnection.disconnect(); - } catch (Throwable ex) { - Log.e("austin_debug", action + ": " + ex); - } - return null; - } - - @Override - protected void onPostExecute(Void result) { - if (ok) { - onRefresh(); - } - } - } -} \ No newline at end of file +// package awais.instagrabber.activities; +// +// import android.content.DialogInterface; +// import android.content.Intent; +// import android.content.pm.PackageManager; +// import android.content.res.ColorStateList; +// import android.content.res.Resources; +// import android.graphics.Bitmap; +// import android.graphics.BitmapFactory; +// import android.graphics.Typeface; +// import android.net.Uri; +// import android.os.AsyncTask; +// import android.os.Bundle; +// import android.text.SpannableStringBuilder; +// import android.text.method.LinkMovementMethod; +// import android.text.style.RelativeSizeSpan; +// import android.text.style.StyleSpan; +// import android.util.Log; +// import android.view.Menu; +// import android.view.MenuItem; +// import android.view.View; +// import android.widget.ArrayAdapter; +// import android.widget.TextView; +// import android.widget.Toast; +// +// import androidx.annotation.NonNull; +// import androidx.annotation.Nullable; +// import androidx.appcompat.app.AlertDialog; +// import androidx.core.content.ContextCompat; +// import androidx.recyclerview.widget.LinearLayoutManager; +// import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +// +// import java.io.DataOutputStream; +// import java.io.InputStream; +// import java.net.HttpURLConnection; +// import java.net.URL; +// import java.util.ArrayList; +// import java.util.Arrays; +// +// import awais.instagrabber.BuildConfig; +// import awais.instagrabber.R; +// import awais.instagrabber.adapters.HighlightsAdapter; +// import awais.instagrabber.adapters.PostsAdapter; +// import awais.instagrabber.asyncs.HashtagFetcher; +// import awais.instagrabber.asyncs.HighlightsFetcher; +// import awais.instagrabber.asyncs.LocationFetcher; +// import awais.instagrabber.asyncs.PostsFetcher; +// import awais.instagrabber.asyncs.ProfileFetcher; +// import awais.instagrabber.asyncs.i.iStoryStatusFetcher; +// import awais.instagrabber.customviews.RamboTextView; +// import awais.instagrabber.customviews.helpers.GridAutofitLayoutManager; +// import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration; +// import awais.instagrabber.customviews.helpers.RecyclerLazyLoader; +// import awais.instagrabber.databinding.ActivityProfileBinding; +// import awais.instagrabber.fragments.SavedViewerFragment; +// import awais.instagrabber.interfaces.FetchListener; +// import awais.instagrabber.interfaces.MentionClickListener; +// import awais.instagrabber.models.BasePostModel; +// import awais.instagrabber.models.HashtagModel; +// import awais.instagrabber.models.HighlightModel; +// import awais.instagrabber.models.LocationModel; +// import awais.instagrabber.models.PostModel; +// import awais.instagrabber.models.ProfileModel; +// import awais.instagrabber.models.StoryModel; +// import awais.instagrabber.models.enums.DownloadMethod; +// import awais.instagrabber.models.enums.PostItemType; +// import awais.instagrabber.utils.Constants; +// import awais.instagrabber.utils.DataBox; +// import awais.instagrabber.utils.Utils; +// import awaisomereport.LogCollector; +// +// import static awais.instagrabber.utils.Constants.AUTOLOAD_POSTS; +// import static awais.instagrabber.utils.Utils.logCollector; +// +// @Deprecated +// public final class ProfileViewer extends BaseLanguageActivity implements SwipeRefreshLayout.OnRefreshListener { +// private final ArrayList allItems = new ArrayList<>(), selectedItems = new ArrayList<>(); +// private static AsyncTask currentlyExecuting; +// private final boolean autoloadPosts = Utils.settingsHelper.getBoolean(AUTOLOAD_POSTS); +// private boolean hasNextPage = false; +// private View collapsingToolbar; +// private String endCursor = null; +// private ProfileModel profileModel; +// private HashtagModel hashtagModel; +// private LocationModel locationModel; +// private StoryModel[] storyModels; +// private MenuItem downloadAction, favouriteAction; +// private final FetchListener postsFetchListener = new FetchListener() { +// @Override +// public void onResult(final PostModel[] result) { +// if (result != null) { +// final int oldSize = allItems.size(); +// allItems.addAll(Arrays.asList(result)); +// +// postsAdapter.notifyItemRangeInserted(oldSize, result.length); +// +// profileBinding.profileView.mainPosts.post(() -> { +// profileBinding.profileView.mainPosts.setNestedScrollingEnabled(true); +// profileBinding.profileView.mainPosts.setVisibility(View.VISIBLE); +// }); +// +// if (isHashtag) +// profileBinding.toolbar.toolbar.setTitle(userQuery); +// else if (isLocation) +// profileBinding.toolbar.toolbar.setTitle(locationModel.getName()); +// else profileBinding.toolbar.toolbar.setTitle("@" + profileModel.getUsername()); +// +// final PostModel model = result[result.length - 1]; +// if (model != null) { +// endCursor = model.getEndCursor(); +// hasNextPage = model.hasNextPage(); +// if (autoloadPosts && hasNextPage) +// currentlyExecuting = new PostsFetcher( +// profileModel != null ? profileModel.getId() +// : (hashtagModel != null ? (hashtagModel.getName()) : locationModel.getId()), +// profileModel != null ? PostItemType.MAIN : (hashtagModel != null ? PostItemType.HASHTAG : PostItemType.LOCATION), +// endCursor, +// this) +// .setUsername((isLocation || isHashtag) ? null : profileModel.getUsername()) +// .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// else { +// profileBinding.profileView.swipeRefreshLayout.setRefreshing(false); +// } +// model.setPageCursor(false, null); +// } +// } else { +// profileBinding.profileView.swipeRefreshLayout.setRefreshing(false); +// profileBinding.profileView.privatePage1.setImageResource(R.drawable.ic_cancel); +// profileBinding.profileView.privatePage2.setText(R.string.empty_acc); +// profileBinding.profileView.privatePage.setVisibility(View.VISIBLE); +// } +// } +// }; +// private final MentionClickListener mentionClickListener = new MentionClickListener() { +// @Override +// public void onClick(final RamboTextView view, final String text, final boolean isHashtag, final boolean isLocation) { +// startActivity(new Intent(getApplicationContext(), ProfileViewer.class).putExtra(Constants.EXTRAS_USERNAME, text)); +// } +// }; +// public final HighlightsAdapter highlightsAdapter = new HighlightsAdapter(null, new View.OnClickListener() { +// @Override +// public void onClick(final View v) { +// final Object tag = v.getTag(); +// if (tag instanceof HighlightModel) { +// final HighlightModel highlightModel = (HighlightModel) tag; +// new iStoryStatusFetcher(highlightModel.getId(), null, false, false, +// (!isLoggedIn && Utils.settingsHelper.getBoolean(Constants.STORIESIG)), true, result -> { +// if (result != null && result.length > 0) { +// // startActivity(new Intent(ProfileViewer.this, StoryViewer.class) +// // .putExtra(Constants.EXTRAS_USERNAME, userQuery.replace("@", "")) +// // .putExtra(Constants.EXTRAS_HIGHLIGHT, highlightModel.getTitle()) +// // .putExtra(Constants.EXTRAS_STORIES, result) +// // ); +// } else +// Toast.makeText(ProfileViewer.this, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); +// }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } +// } +// }); +// private Resources resources; +// private RecyclerLazyLoader lazyLoader; +// private boolean isHashtag, isUser, isLocation; +// private PostsAdapter postsAdapter; +// private String cookie = Utils.settingsHelper.getString(Constants.COOKIE), userQuery; +// public boolean isLoggedIn = !Utils.isEmpty(cookie); +// private ActivityProfileBinding profileBinding; +// private ArrayAdapter profileDialogAdapter; +// private DialogInterface.OnClickListener profileDialogListener; +// +// protected void onCreate(@Nullable final Bundle savedInstanceState) { +// stopCurrentExecutor(); +// super.onCreate(savedInstanceState); +// +// final Intent intent = getIntent(); +// if (intent == null || !intent.hasExtra(Constants.EXTRAS_USERNAME) +// || Utils.isEmpty((userQuery = intent.getStringExtra(Constants.EXTRAS_USERNAME)))) { +// Utils.errorFinish(this); +// return; +// } +// +// userQuery = (userQuery.contains("/") || userQuery.startsWith("#") || userQuery.startsWith("@")) ? userQuery : ("@" + userQuery); +// +// profileBinding = ActivityProfileBinding.inflate(getLayoutInflater()); +// setContentView(profileBinding.getRoot()); +// +// resources = getResources(); +// +// profileDialogAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, +// new String[]{resources.getString(R.string.view_pfp), resources.getString(R.string.show_stories)}); +// profileDialogListener = (dialog, which) -> { +// final Intent newintent; +// if (which == 0 || storyModels == null || storyModels.length < 1) { +// newintent = new Intent(this, ProfilePicViewer.class).putExtra( +// ((hashtagModel != null) +// ? Constants.EXTRAS_HASHTAG +// : (locationModel != null ? Constants.EXTRAS_LOCATION : Constants.EXTRAS_PROFILE)), +// ((hashtagModel != null) ? hashtagModel : (locationModel != null ? locationModel : profileModel))); +// } +// // else +// // newintent = new Intent(this, StoryViewer.class).putExtra(Constants.EXTRAS_USERNAME, userQuery.replace("@", "")) +// // .putExtra(Constants.EXTRAS_STORIES, storyModels) +// // .putExtra(Constants.EXTRAS_HASHTAG, (hashtagModel != null)); +// // startActivity(newintent); +// }; +// +// profileBinding.profileView.swipeRefreshLayout.setOnRefreshListener(this); +// profileBinding.profileView.mainUrl.setMovementMethod(new LinkMovementMethod()); +// +// isLoggedIn = !Utils.isEmpty(cookie); +// +// collapsingToolbar = profileBinding.profileView.appBarLayout.getChildAt(0); +// +// profileBinding.profileView.mainPosts.setNestedScrollingEnabled(false); +// profileBinding.profileView.highlightsList.setLayoutManager( +// new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false)); +// profileBinding.profileView.highlightsList.setAdapter(highlightsAdapter); +// +// setSupportActionBar(profileBinding.toolbar.toolbar); +// +// // change the next number to adjust grid +// final GridAutofitLayoutManager layoutManager = new GridAutofitLayoutManager(ProfileViewer.this, Utils.convertDpToPx(110)); +// profileBinding.profileView.mainPosts.setLayoutManager(layoutManager); +// profileBinding.profileView.mainPosts.addItemDecoration(new GridSpacingItemDecoration(Utils.convertDpToPx(4))); +// // profileBinding.profileView.mainPosts.setAdapter(postsAdapter = new PostsAdapter(allItems, v -> { +// // final Object tag = v.getTag(); +// // if (tag instanceof PostModel) { +// // final PostModel postModel = (PostModel) tag; +// // +// // if (postsAdapter.isSelecting) toggleSelection(postModel); +// // else startActivity(new Intent(ProfileViewer.this, PostViewer.class) +// // .putExtra(Constants.EXTRAS_INDEX, postModel.getPosition()) +// // .putExtra(Constants.EXTRAS_POST, postModel) +// // .putExtra(Constants.EXTRAS_USER, userQuery) +// // .putExtra(Constants.EXTRAS_TYPE, ItemGetType.MAIN_ITEMS)); +// // } +// // }, v -> { // long click listener +// // final Object tag = v.getTag(); +// // if (tag instanceof PostModel) { +// // postsAdapter.isSelecting = true; +// // toggleSelection((PostModel) tag); +// // } +// // return true; +// // })); +// +// this.lazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> { +// if ((!autoloadPosts || isHashtag) && hasNextPage) { +// profileBinding.profileView.swipeRefreshLayout.setRefreshing(true); +// stopCurrentExecutor(); +// currentlyExecuting = new PostsFetcher(profileModel != null ? profileModel.getId() +// : (hashtagModel != null +// ? ("#" + hashtagModel.getName()) +// : locationModel.getId()), +// profileModel != null +// ? PostItemType.MAIN +// : (hashtagModel != null ? PostItemType.HASHTAG : PostItemType.LOCATION), +// endCursor, postsFetchListener) +// .setUsername((isHashtag || isLocation) ? null : profileModel.getUsername()) +// .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// endCursor = null; +// } +// }); +// profileBinding.profileView.mainPosts.addOnScrollListener(lazyLoader); +// +// final View.OnClickListener onClickListener = v -> { +// if (v == profileBinding.profileView.mainBiography) { +// Utils.copyText(this, profileBinding.profileView.mainBiography.getText().toString()); +// } else if (v == profileBinding.profileView.locationBiography) { +// Utils.copyText(this, profileBinding.profileView.locationBiography.getText().toString()); +// } else if (v == profileBinding.profileView.mainProfileImage || v == profileBinding.profileView.mainHashtagImage || v == profileBinding.profileView.mainLocationImage) { +// if (storyModels == null || storyModels.length <= 0) { +// profileDialogListener.onClick(null, 0); +// } else { +// // because sometimes configuration changes made this crash on some phones +// new AlertDialog.Builder(this).setAdapter(profileDialogAdapter, profileDialogListener) +// .setNeutralButton(R.string.cancel, null).show(); +// } +// } +// }; +// +// profileBinding.profileView.mainBiography.setOnClickListener(onClickListener); +// profileBinding.profileView.locationBiography.setOnClickListener(onClickListener); +// profileBinding.profileView.mainProfileImage.setOnClickListener(onClickListener); +// profileBinding.profileView.mainHashtagImage.setOnClickListener(onClickListener); +// profileBinding.profileView.mainLocationImage.setOnClickListener(onClickListener); +// +// this.onRefresh(); +// } +// +// @Override +// public void onRefresh() { +// if (lazyLoader != null) lazyLoader.resetState(); +// stopCurrentExecutor(); +// allItems.clear(); +// selectedItems.clear(); +// if (postsAdapter != null) { +// // postsAdapter.isSelecting = false; +// postsAdapter.notifyDataSetChanged(); +// } +// profileBinding.profileView.appBarLayout.setExpanded(true, true); +// profileBinding.profileView.privatePage.setVisibility(View.GONE); +// profileBinding.profileView.privatePage2.setTextSize(28); +// // profileBinding.profileView.mainProfileImage.setImageBitmap(null); +// // profileBinding.profileView.mainHashtagImage.setImageBitmap(null); +// // profileBinding.profileView.mainLocationImage.setImageBitmap(null); +// profileBinding.profileView.mainUrl.setText(null); +// profileBinding.profileView.locationUrl.setText(null); +// profileBinding.profileView.mainFullName.setText(null); +// profileBinding.profileView.locationFullName.setText(null); +// profileBinding.profileView.mainPostCount.setText(null); +// profileBinding.profileView.mainLocPostCount.setText(null); +// profileBinding.profileView.mainTagPostCount.setText(null); +// profileBinding.profileView.mainFollowers.setText(null); +// profileBinding.profileView.mainFollowing.setText(null); +// profileBinding.profileView.mainBiography.setText(null); +// profileBinding.profileView.locationBiography.setText(null); +// profileBinding.profileView.mainBiography.setEnabled(false); +// profileBinding.profileView.locationBiography.setEnabled(false); +// profileBinding.profileView.mainProfileImage.setEnabled(false); +// profileBinding.profileView.mainLocationImage.setEnabled(false); +// profileBinding.profileView.mainHashtagImage.setEnabled(false); +// profileBinding.profileView.mainBiography.setMentionClickListener(null); +// profileBinding.profileView.locationBiography.setMentionClickListener(null); +// profileBinding.profileView.mainUrl.setVisibility(View.GONE); +// profileBinding.profileView.locationUrl.setVisibility(View.GONE); +// profileBinding.profileView.isVerified.setVisibility(View.GONE); +// profileBinding.profileView.btnFollow.setVisibility(View.GONE); +// profileBinding.profileView.btnRestrict.setVisibility(View.GONE); +// profileBinding.profileView.btnBlock.setVisibility(View.GONE); +// profileBinding.profileView.btnSaved.setVisibility(View.GONE); +// profileBinding.profileView.btnLiked.setVisibility(View.GONE); +// profileBinding.profileView.btnTagged.setVisibility(View.GONE); +// profileBinding.profileView.btnMap.setVisibility(View.GONE); +// +// profileBinding.profileView.btnFollow.setOnClickListener(profileActionListener); +// profileBinding.profileView.btnRestrict.setOnClickListener(profileActionListener); +// profileBinding.profileView.btnBlock.setOnClickListener(profileActionListener); +// profileBinding.profileView.btnSaved.setOnClickListener(profileActionListener); +// profileBinding.profileView.btnLiked.setOnClickListener(profileActionListener); +// profileBinding.profileView.btnTagged.setOnClickListener(profileActionListener); +// profileBinding.profileView.btnFollowTag.setOnClickListener(profileActionListener); +// +// profileBinding.profileView.infoContainer.setVisibility(View.GONE); +// profileBinding.profileView.tagInfoContainer.setVisibility(View.GONE); +// profileBinding.profileView.locInfoContainer.setVisibility(View.GONE); +// +// profileBinding.profileView.mainPosts.setNestedScrollingEnabled(false); +// profileBinding.profileView.highlightsList.setVisibility(View.GONE); +// collapsingToolbar.setVisibility(View.GONE); +// highlightsAdapter.setData(null); +// +// profileBinding.profileView.swipeRefreshLayout.setRefreshing(userQuery != null); +// if (userQuery == null) { +// profileBinding.toolbar.toolbar.setTitle(R.string.app_name); +// return; +// } +// +// isHashtag = userQuery.charAt(0) == '#'; +// isUser = userQuery.charAt(0) == '@'; +// isLocation = userQuery.contains("/"); +// collapsingToolbar.setVisibility(isUser ? View.VISIBLE : View.GONE); +// +// if (isHashtag) { +// profileModel = null; +// locationModel = null; +// profileBinding.toolbar.toolbar.setTitle(userQuery); +// profileBinding.profileView.tagInfoContainer.setVisibility(View.VISIBLE); +// profileBinding.profileView.btnFollowTag.setVisibility(View.GONE); +// +// currentlyExecuting = new HashtagFetcher(userQuery.substring(1), result -> { +// hashtagModel = result; +// +// if (hashtagModel == null) { +// profileBinding.profileView.swipeRefreshLayout.setRefreshing(false); +// Toast.makeText(ProfileViewer.this, R.string.error_loading_profile, Toast.LENGTH_SHORT).show(); +// profileBinding.toolbar.toolbar.setTitle(R.string.app_name); +// return; +// } +// +// currentlyExecuting = new PostsFetcher(userQuery, PostItemType.HASHTAG, null, postsFetchListener) +// .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// +// profileBinding.profileView.btnFollowTag.setVisibility(View.VISIBLE); +// +// if (isLoggedIn) { +// new iStoryStatusFetcher(hashtagModel.getName(), null, false, true, false, false, stories -> { +// storyModels = stories; +// if (stories != null && stories.length > 0) +// profileBinding.profileView.mainHashtagImage.setStoriesBorder(); +// }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// +// if (hashtagModel.getFollowing()) { +// profileBinding.profileView.btnFollowTag.setText(R.string.unfollow); +// profileBinding.profileView.btnFollowTag.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// ProfileViewer.this, R.color.btn_purple_background))); +// } else { +// profileBinding.profileView.btnFollowTag.setText(R.string.follow); +// profileBinding.profileView.btnFollowTag.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// ProfileViewer.this, R.color.btn_pink_background))); +// } +// } else { +// if (Utils.dataBox.getFavorite(userQuery) != null) { +// profileBinding.profileView.btnFollowTag.setText(R.string.unfavorite_short); +// profileBinding.profileView.btnFollowTag.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// ProfileViewer.this, R.color.btn_purple_background))); +// } else { +// profileBinding.profileView.btnFollowTag.setText(R.string.favorite_short); +// profileBinding.profileView.btnFollowTag.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// ProfileViewer.this, R.color.btn_pink_background))); +// } +// } +// +// // profileBinding.profileView.mainHashtagImage.setEnabled(false); +// profileBinding.profileView.mainHashtagImage.setImageURI(hashtagModel.getSdProfilePic()); +// profileBinding.profileView.mainHashtagImage.setEnabled(true); +// +// final String postCount = String.valueOf(hashtagModel.getPostCount()); +// +// SpannableStringBuilder span = new SpannableStringBuilder(resources.getString(R.string.main_posts_count, postCount)); +// span.setSpan(new RelativeSizeSpan(1.2f), 0, postCount.length(), 0); +// span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0); +// profileBinding.profileView.mainTagPostCount.setText(span); +// profileBinding.profileView.mainTagPostCount.setVisibility(View.VISIBLE); +// }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } else if (isUser) { +// hashtagModel = null; +// locationModel = null; +// profileBinding.toolbar.toolbar.setTitle(userQuery); +// profileBinding.profileView.infoContainer.setVisibility(View.VISIBLE); +// profileBinding.profileView.btnFollowTag.setVisibility(View.GONE); +// +// currentlyExecuting = new ProfileFetcher(userQuery.substring(1), result -> { +// profileModel = result; +// +// if (profileModel == null) { +// profileBinding.profileView.swipeRefreshLayout.setRefreshing(false); +// Toast.makeText(ProfileViewer.this, R.string.error_loading_profile, Toast.LENGTH_SHORT).show(); +// profileBinding.toolbar.toolbar.setTitle(R.string.app_name); +// return; +// } +// +// profileBinding.profileView.isVerified.setVisibility(profileModel.isVerified() ? View.VISIBLE : View.GONE); +// final String profileId = profileModel.getId(); +// +// if (isLoggedIn || Utils.settingsHelper.getBoolean(Constants.STORIESIG)) { +// new iStoryStatusFetcher(profileId, profileModel.getUsername(), false, false, +// (!isLoggedIn && Utils.settingsHelper.getBoolean(Constants.STORIESIG)), false, +// stories -> { +// storyModels = stories; +// if (stories != null && stories.length > 0) +// profileBinding.profileView.mainProfileImage.setStoriesBorder(); +// }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// +// new HighlightsFetcher(profileId, (!isLoggedIn && Utils.settingsHelper.getBoolean(Constants.STORIESIG)), hls -> { +// if (hls != null && hls.length > 0) { +// profileBinding.profileView.highlightsList.setVisibility(View.VISIBLE); +// highlightsAdapter.setData(hls); +// } else profileBinding.profileView.highlightsList.setVisibility(View.GONE); +// }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } +// +// if (isLoggedIn) { +// final String myId = Utils.getUserIdFromCookie(cookie); +// if (!profileId.equals(myId)) { +// profileBinding.profileView.btnTagged.setVisibility(View.GONE); +// profileBinding.profileView.btnSaved.setVisibility(View.GONE); +// profileBinding.profileView.btnLiked.setVisibility(View.GONE); +// profileBinding.profileView.btnFollow.setVisibility(View.VISIBLE); +// if (profileModel.getFollowing() == true) { +// profileBinding.profileView.btnFollow.setText(R.string.unfollow); +// profileBinding.profileView.btnFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// ProfileViewer.this, R.color.btn_purple_background))); +// } else if (profileModel.getRequested() == true) { +// profileBinding.profileView.btnFollow.setText(R.string.cancel); +// profileBinding.profileView.btnFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// ProfileViewer.this, R.color.btn_purple_background))); +// } else { +// profileBinding.profileView.btnFollow.setText(R.string.follow); +// profileBinding.profileView.btnFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// ProfileViewer.this, R.color.btn_pink_background))); +// } +// profileBinding.profileView.btnRestrict.setVisibility(View.VISIBLE); +// if (profileModel.getRestricted() == true) { +// profileBinding.profileView.btnRestrict.setText(R.string.unrestrict); +// profileBinding.profileView.btnRestrict.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// ProfileViewer.this, R.color.btn_green_background))); +// } else { +// profileBinding.profileView.btnRestrict.setText(R.string.restrict); +// profileBinding.profileView.btnRestrict.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// ProfileViewer.this, R.color.btn_orange_background))); +// } +// if (profileModel.isReallyPrivate()) { +// profileBinding.profileView.btnBlock.setVisibility(View.VISIBLE); +// profileBinding.profileView.btnTagged.setVisibility(View.GONE); +// if (profileModel.getBlocked() == true) { +// profileBinding.profileView.btnBlock.setText(R.string.unblock); +// profileBinding.profileView.btnBlock.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// ProfileViewer.this, R.color.btn_green_background))); +// } else { +// profileBinding.profileView.btnBlock.setText(R.string.block); +// profileBinding.profileView.btnBlock.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// ProfileViewer.this, R.color.btn_red_background))); +// } +// } else { +// profileBinding.profileView.btnBlock.setVisibility(View.GONE); +// profileBinding.profileView.btnSaved.setVisibility(View.VISIBLE); +// profileBinding.profileView.btnTagged.setVisibility(View.VISIBLE); +// if (profileModel.getBlocked() == true) { +// profileBinding.profileView.btnSaved.setText(R.string.unblock); +// profileBinding.profileView.btnSaved.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// ProfileViewer.this, R.color.btn_green_background))); +// } else { +// profileBinding.profileView.btnSaved.setText(R.string.block); +// profileBinding.profileView.btnSaved.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// ProfileViewer.this, R.color.btn_red_background))); +// } +// } +// } else { +// profileBinding.profileView.btnTagged.setVisibility(View.VISIBLE); +// profileBinding.profileView.btnSaved.setVisibility(View.VISIBLE); +// profileBinding.profileView.btnLiked.setVisibility(View.VISIBLE); +// profileBinding.profileView.btnSaved.setText(R.string.saved); +// profileBinding.profileView.btnSaved.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// ProfileViewer.this, R.color.btn_orange_background))); +// } +// } else { +// if (Utils.dataBox.getFavorite(userQuery) != null) { +// profileBinding.profileView.btnFollow.setText(R.string.unfavorite_short); +// profileBinding.profileView.btnFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// ProfileViewer.this, R.color.btn_purple_background))); +// } else { +// profileBinding.profileView.btnFollow.setText(R.string.favorite_short); +// profileBinding.profileView.btnFollow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// ProfileViewer.this, R.color.btn_pink_background))); +// } +// profileBinding.profileView.btnFollow.setVisibility(View.VISIBLE); +// if (!profileModel.isReallyPrivate()) { +// profileBinding.profileView.btnRestrict.setVisibility(View.VISIBLE); +// profileBinding.profileView.btnRestrict.setText(R.string.tagged); +// profileBinding.profileView.btnRestrict.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor( +// ProfileViewer.this, R.color.btn_blue_background))); +// } +// } +// +// // profileBinding.profileView.mainProfileImage.setEnabled(false); +// profileBinding.profileView.mainProfileImage.setImageURI(profileModel.getSdProfilePic(), null); +// // profileBinding.profileView.mainProfileImage.setEnabled(true); +// +// final long followersCount = profileModel.getFollowersCount(); +// final long followingCount = profileModel.getFollowingCount(); +// +// final String postCount = String.valueOf(profileModel.getPostCount()); +// +// SpannableStringBuilder span = new SpannableStringBuilder(resources.getString(R.string.main_posts_count, postCount)); +// span.setSpan(new RelativeSizeSpan(1.2f), 0, postCount.length(), 0); +// span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0); +// profileBinding.profileView.mainPostCount.setText(span); +// +// final String followersCountStr = String.valueOf(followersCount); +// final int followersCountStrLen = followersCountStr.length(); +// span = new SpannableStringBuilder(resources.getString(R.string.main_posts_followers, followersCountStr)); +// span.setSpan(new RelativeSizeSpan(1.2f), 0, followersCountStrLen, 0); +// span.setSpan(new StyleSpan(Typeface.BOLD), 0, followersCountStrLen, 0); +// profileBinding.profileView.mainFollowers.setText(span); +// +// final String followingCountStr = String.valueOf(followingCount); +// final int followingCountStrLen = followingCountStr.length(); +// span = new SpannableStringBuilder(resources.getString(R.string.main_posts_following, followingCountStr)); +// span.setSpan(new RelativeSizeSpan(1.2f), 0, followingCountStrLen, 0); +// span.setSpan(new StyleSpan(Typeface.BOLD), 0, followingCountStrLen, 0); +// profileBinding.profileView.mainFollowing.setText(span); +// +// profileBinding.profileView.mainFullName +// .setText(Utils.isEmpty(profileModel.getName()) ? profileModel.getUsername() : profileModel.getName()); +// +// CharSequence biography = profileModel.getBiography(); +// profileBinding.profileView.mainBiography.setCaptionIsExpandable(true); +// profileBinding.profileView.mainBiography.setCaptionIsExpanded(true); +// if (Utils.hasMentions(biography)) { +// biography = Utils.getMentionText(biography); +// profileBinding.profileView.mainBiography.setText(biography, TextView.BufferType.SPANNABLE); +// profileBinding.profileView.mainBiography.setMentionClickListener(mentionClickListener); +// } else { +// profileBinding.profileView.mainBiography.setText(biography); +// profileBinding.profileView.mainBiography.setMentionClickListener(null); +// } +// +// final String url = profileModel.getUrl(); +// if (Utils.isEmpty(url)) { +// profileBinding.profileView.mainUrl.setVisibility(View.GONE); +// } else { +// profileBinding.profileView.mainUrl.setVisibility(View.VISIBLE); +// profileBinding.profileView.mainUrl.setText(Utils.getSpannableUrl(url)); +// } +// +// profileBinding.profileView.mainFullName.setSelected(true); +// profileBinding.profileView.mainBiography.setEnabled(true); +// +// if (!profileModel.isReallyPrivate()) { +// profileBinding.profileView.mainFollowing.setClickable(true); +// profileBinding.profileView.mainFollowers.setClickable(true); +// +// if (isLoggedIn) { +// // final View.OnClickListener followClickListener = v -> startActivity( +// // new Intent(ProfileViewer.this, FollowViewerFragment.class) +// // .putExtra(Constants.EXTRAS_FOLLOWERS, v == profileBinding.profileView.mainFollowers) +// // .putExtra(Constants.EXTRAS_NAME, profileModel.getUsername()) +// // .putExtra(Constants.EXTRAS_ID, profileId)); +// // +// // profileBinding.profileView.mainFollowers.setOnClickListener(followersCount > 0 ? followClickListener : null); +// // profileBinding.profileView.mainFollowing.setOnClickListener(followingCount > 0 ? followClickListener : null); +// } +// +// if (profileModel.getPostCount() == 0) { +// profileBinding.profileView.swipeRefreshLayout.setRefreshing(false); +// profileBinding.profileView.privatePage1.setImageResource(R.drawable.ic_cancel); +// profileBinding.profileView.privatePage2.setText(R.string.empty_acc); +// profileBinding.profileView.privatePage.setVisibility(View.VISIBLE); +// } else { +// profileBinding.profileView.swipeRefreshLayout.setRefreshing(true); +// profileBinding.profileView.mainPosts.setVisibility(View.VISIBLE); +// currentlyExecuting = new PostsFetcher(profileId, PostItemType.MAIN, null, postsFetchListener) +// .setUsername(profileModel.getUsername()) +// .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } +// } else { +// profileBinding.profileView.mainFollowers.setClickable(false); +// profileBinding.profileView.mainFollowing.setClickable(false); +// profileBinding.profileView.swipeRefreshLayout.setRefreshing(false); +// // error +// profileBinding.profileView.privatePage1.setImageResource(R.drawable.lock); +// profileBinding.profileView.privatePage2.setText(R.string.priv_acc); +// profileBinding.profileView.privatePage.setVisibility(View.VISIBLE); +// profileBinding.profileView.mainPosts.setVisibility(View.GONE); +// } +// } +// ).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } else if (isLocation) { +// profileModel = null; +// hashtagModel = null; +// profileBinding.toolbar.toolbar.setTitle(userQuery); +// profileBinding.profileView.locInfoContainer.setVisibility(View.VISIBLE); +// +// currentlyExecuting = new LocationFetcher(userQuery.split("/")[0], result -> { +// locationModel = result; +// +// if (locationModel == null) { +// profileBinding.profileView.swipeRefreshLayout.setRefreshing(false); +// Toast.makeText(ProfileViewer.this, R.string.error_loading_profile, Toast.LENGTH_SHORT).show(); +// profileBinding.toolbar.toolbar.setTitle(R.string.app_name); +// return; +// } +// profileBinding.toolbar.toolbar.setTitle(locationModel.getName()); +// +// final String profileId = locationModel.getId(); +// +// if (isLoggedIn) { +// new iStoryStatusFetcher(profileId.split("/")[0], null, true, false, false, false, stories -> { +// storyModels = stories; +// if (stories != null && stories.length > 0) +// profileBinding.profileView.mainLocationImage.setStoriesBorder(); +// }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } +// +// // profileBinding.profileView.mainLocationImage.setEnabled(false); +// profileBinding.profileView.mainLocationImage.setImageURI(locationModel.getSdProfilePic()); +// profileBinding.profileView.mainLocationImage.setEnabled(true); +// +// final String postCount = String.valueOf(locationModel.getPostCount()); +// +// SpannableStringBuilder span = new SpannableStringBuilder(resources.getString(R.string.main_posts_count, postCount)); +// span.setSpan(new RelativeSizeSpan(1.2f), 0, postCount.length(), 0); +// span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0); +// profileBinding.profileView.mainLocPostCount.setText(span); +// +// profileBinding.profileView.locationFullName.setText(locationModel.getName()); +// +// CharSequence biography = locationModel.getBio(); +// profileBinding.profileView.locationBiography.setCaptionIsExpandable(true); +// profileBinding.profileView.locationBiography.setCaptionIsExpanded(true); +// +// if (Utils.isEmpty(biography)) { +// profileBinding.profileView.locationBiography.setVisibility(View.GONE); +// } else if (Utils.hasMentions(biography)) { +// profileBinding.profileView.locationBiography.setVisibility(View.VISIBLE); +// biography = Utils.getMentionText(biography); +// profileBinding.profileView.locationBiography.setText(biography, TextView.BufferType.SPANNABLE); +// profileBinding.profileView.locationBiography.setMentionClickListener(mentionClickListener); +// } else { +// profileBinding.profileView.locationBiography.setVisibility(View.VISIBLE); +// profileBinding.profileView.locationBiography.setText(biography); +// profileBinding.profileView.locationBiography.setMentionClickListener(null); +// } +// +// if (!locationModel.getGeo().startsWith("geo:0.0,0.0?z=17")) { +// profileBinding.profileView.btnMap.setVisibility(View.VISIBLE); +// profileBinding.profileView.btnMap.setOnClickListener(v -> { +// final Intent intent = new Intent(Intent.ACTION_VIEW); +// intent.setData(Uri.parse(locationModel.getGeo())); +// startActivity(intent); +// }); +// } else { +// profileBinding.profileView.btnMap.setVisibility(View.GONE); +// profileBinding.profileView.btnMap.setOnClickListener(null); +// } +// +// final String url = locationModel.getUrl(); +// if (Utils.isEmpty(url)) { +// profileBinding.profileView.locationUrl.setVisibility(View.GONE); +// } else if (!url.startsWith("http")) { +// profileBinding.profileView.locationUrl.setVisibility(View.VISIBLE); +// profileBinding.profileView.locationUrl.setText(Utils.getSpannableUrl("http://" + url)); +// } else { +// profileBinding.profileView.locationUrl.setVisibility(View.VISIBLE); +// profileBinding.profileView.locationUrl.setText(Utils.getSpannableUrl(url)); +// } +// +// profileBinding.profileView.locationFullName.setSelected(true); +// profileBinding.profileView.locationBiography.setEnabled(true); +// +// if (locationModel.getPostCount() == 0) { +// profileBinding.profileView.swipeRefreshLayout.setRefreshing(false); +// profileBinding.profileView.privatePage1.setImageResource(R.drawable.ic_cancel); +// profileBinding.profileView.privatePage2.setText(R.string.empty_acc); +// profileBinding.profileView.privatePage.setVisibility(View.VISIBLE); +// } else { +// profileBinding.profileView.swipeRefreshLayout.setRefreshing(true); +// profileBinding.profileView.mainPosts.setVisibility(View.VISIBLE); +// currentlyExecuting = new PostsFetcher(profileId, PostItemType.LOCATION, null, postsFetchListener) +// .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } +// } +// ).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); +// } +// } +// +// public static void stopCurrentExecutor() { +// if (currentlyExecuting != null) { +// try { +// currentlyExecuting.cancel(true); +// } catch (final Exception e) { +// if (logCollector != null) +// logCollector.appendException(e, LogCollector.LogFile.MAIN_HELPER, "stopCurrentExecutor"); +// if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e); +// } +// } +// } +// +// @Override +// public boolean onCreateOptionsMenu(final Menu menu) { +// getMenuInflater().inflate(R.menu.saved, menu); +// +// downloadAction = menu.findItem(R.id.downloadAction); +// downloadAction.setVisible(false); +// +// favouriteAction = menu.findItem(R.id.favouriteAction); +// favouriteAction.setVisible(!Utils.isEmpty(cookie)); +// favouriteAction.setIcon(Utils.dataBox.getFavorite(userQuery) == null ? R.drawable.ic_not_liked : R.drawable.ic_like); +// +// downloadAction.setOnMenuItemClickListener(item -> { +// if (selectedItems.size() > 0) { +// Utils.batchDownload(this, userQuery, DownloadMethod.DOWNLOAD_MAIN, selectedItems); +// } +// return true; +// }); +// +// favouriteAction.setOnMenuItemClickListener(item -> { +// if (Utils.dataBox.getFavorite(userQuery) == null) { +// Utils.dataBox.addFavorite(new DataBox.FavoriteModel(userQuery, System.currentTimeMillis(), +// locationModel != null +// ? locationModel.getName() +// : userQuery.replaceAll("^@", ""))); +// favouriteAction.setIcon(R.drawable.ic_like); +// } else { +// Utils.dataBox.delFavorite(new DataBox.FavoriteModel(userQuery, +// Long.parseLong(Utils.dataBox.getFavorite(userQuery).split("/")[1]), +// locationModel != null +// ? locationModel.getName() +// : userQuery.replaceAll("^@", ""))); +// favouriteAction.setIcon(R.drawable.ic_not_liked); +// } +// return true; +// }); +// +// return true; +// } +// +// private void toggleSelection(final PostModel postModel) { +// if (postModel != null && postsAdapter != null) { +// if (postModel.isSelected()) selectedItems.remove(postModel); +// else if (selectedItems.size() >= 100) { +// Toast.makeText(ProfileViewer.this, R.string.downloader_too_many, Toast.LENGTH_SHORT); +// return; +// } else selectedItems.add(postModel); +// postModel.setSelected(!postModel.isSelected()); +// notifyAdapter(postModel); +// } +// } +// +// private void notifyAdapter(final PostModel postModel) { +// // if (selectedItems.size() < 1) postsAdapter.isSelecting = false; +// // if (postModel.getPosition() < 0) postsAdapter.notifyDataSetChanged(); +// // else postsAdapter.notifyItemChanged(postModel.getPosition(), postModel); +// // +// // if (downloadAction != null) downloadAction.setVisible(postsAdapter.isSelecting); +// } +// +// @Override +// public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) { +// super.onRequestPermissionsResult(requestCode, permissions, grantResults); +// if (requestCode == 8020 && grantResults[0] == PackageManager.PERMISSION_GRANTED && selectedItems.size() > 0) +// Utils.batchDownload(this, userQuery, DownloadMethod.DOWNLOAD_MAIN, selectedItems); +// } +// +// public void deselectSelection(final BasePostModel postModel) { +// if (postModel instanceof PostModel) { +// selectedItems.remove(postModel); +// postModel.setSelected(false); +// if (postsAdapter != null) notifyAdapter((PostModel) postModel); +// } +// } +// +// class MyTask extends AsyncTask { +// private Bitmap mIcon_val; +// +// protected Void doInBackground(Void... voids) { +// try { +// String url; +// if (hashtagModel != null) { +// url = hashtagModel.getSdProfilePic(); +// } else if (locationModel != null) { +// url = locationModel.getSdProfilePic(); +// } else { +// url = profileModel.getSdProfilePic(); +// } +// mIcon_val = BitmapFactory.decodeStream((InputStream) new URL(url).getContent()); +// } catch (Throwable ex) { +// Log.e("austin_debug", "bitmap: " + ex); +// } +// return null; +// } +// +// @Override +// protected void onPostExecute(Void result) { +// if (hashtagModel != null) +// profileBinding.profileView.mainHashtagImage.setImageBitmap(mIcon_val); +// else if (locationModel != null) +// profileBinding.profileView.mainLocationImage.setImageBitmap(mIcon_val); +// else profileBinding.profileView.mainProfileImage.setImageBitmap(mIcon_val); +// } +// } +// +// private final View.OnClickListener profileActionListener = new View.OnClickListener() { +// @Override +// public void onClick(final View v) { +// final boolean iamme = (isLoggedIn && profileModel != null) && Utils.getUserIdFromCookie(cookie).equals(profileModel.getId()); +// if (!isLoggedIn && Utils.dataBox.getFavorite(userQuery) != null && v == profileBinding.profileView.btnFollow) { +// Utils.dataBox.delFavorite(new DataBox.FavoriteModel(userQuery, +// Long.parseLong(Utils.dataBox.getFavorite(userQuery).split("/")[1]), +// locationModel != null +// ? locationModel.getName() +// : userQuery.replaceAll("^@", ""))); +// onRefresh(); +// } else if (!isLoggedIn && (v == profileBinding.profileView.btnFollow || v == profileBinding.profileView.btnFollowTag)) { +// Utils.dataBox.addFavorite(new DataBox.FavoriteModel(userQuery, System.currentTimeMillis(), +// locationModel != null +// ? locationModel.getName() +// : userQuery.replaceAll("^@", ""))); +// onRefresh(); +// } else if (v == profileBinding.profileView.btnFollow) { +// new ProfileAction().execute("follow"); +// } else if (v == profileBinding.profileView.btnRestrict && isLoggedIn) { +// new ProfileAction().execute("restrict"); +// } else if (v == profileBinding.profileView.btnSaved && !iamme) { +// new ProfileAction().execute("block"); +// } else if (v == profileBinding.profileView.btnFollowTag) { +// new ProfileAction().execute("followtag"); +// } else if (v == profileBinding.profileView.btnTagged || (v == profileBinding.profileView.btnRestrict && !isLoggedIn)) { +// startActivity(new Intent(ProfileViewer.this, SavedViewerFragment.class) +// .putExtra(Constants.EXTRAS_INDEX, "%" + profileModel.getId()) +// .putExtra(Constants.EXTRAS_USER, "@" + profileModel.getUsername()) +// ); +// } else if (v == profileBinding.profileView.btnSaved) { +// startActivity(new Intent(ProfileViewer.this, SavedViewerFragment.class) +// .putExtra(Constants.EXTRAS_INDEX, "$" + profileModel.getId()) +// .putExtra(Constants.EXTRAS_USER, "@" + profileModel.getUsername()) +// ); +// } else if (v == profileBinding.profileView.btnLiked) { +// startActivity(new Intent(ProfileViewer.this, SavedViewerFragment.class) +// .putExtra(Constants.EXTRAS_INDEX, "^" + profileModel.getId()) +// .putExtra(Constants.EXTRAS_USER, "@" + profileModel.getUsername()) +// ); +// } +// } +// }; +// +// class ProfileAction extends AsyncTask { +// boolean ok = false; +// String action; +// +// protected Void doInBackground(String... rawAction) { +// action = rawAction[0]; +// final String url = "https://www.instagram.com/web/" + +// ((action.equals("followtag") && hashtagModel != null) ? ("tags/" + +// (hashtagModel.getFollowing() ? "unfollow/" : "follow/") + hashtagModel.getName() + "/") : ( +// ((action.equals("restrict") && profileModel != null) +// ? "restrict_action" +// : ("friendships/" + profileModel.getId())) + "/" + +// ((action.equals("follow") && profileModel != null) ? +// ((profileModel.getFollowing() || +// (!profileModel.getFollowing() && profileModel.getRequested())) +// ? "unfollow/" : "follow/") : +// ((action.equals("restrict") && profileModel != null) ? +// (profileModel.getRestricted() ? "unrestrict/" : "restrict/") : +// (profileModel.getBlocked() ? "unblock/" : "block/"))))); +// try { +// final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); +// urlConnection.setRequestMethod("POST"); +// urlConnection.setUseCaches(false); +// urlConnection.setRequestProperty("User-Agent", Constants.USER_AGENT); +// urlConnection.setRequestProperty("x-csrftoken", cookie.split("csrftoken=")[1].split(";")[0]); +// if (action == "restrict") { +// final String urlParameters = "target_user_id=" + profileModel.getId(); +// urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); +// urlConnection.setRequestProperty("Content-Length", "" + +// urlParameters.getBytes().length); +// urlConnection.setDoOutput(true); +// DataOutputStream wr = new DataOutputStream(urlConnection.getOutputStream()); +// wr.writeBytes(urlParameters); +// wr.flush(); +// wr.close(); +// } else urlConnection.connect(); +// if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { +// ok = true; +// } else +// Toast.makeText(ProfileViewer.this, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); +// urlConnection.disconnect(); +// } catch (Throwable ex) { +// Log.e("austin_debug", action + ": " + ex); +// } +// return null; +// } +// +// @Override +// protected void onPostExecute(Void result) { +// if (ok) { +// onRefresh(); +// } +// } +// } +// } \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/DirectMessageInboxItemViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/DirectMessageInboxItemViewHolder.java index b8d2a12c..2b214887 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/DirectMessageInboxItemViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/DirectMessageInboxItemViewHolder.java @@ -1,6 +1,7 @@ package awais.instagrabber.adapters.viewholder; import android.content.Context; +import android.net.Uri; import android.view.View; import android.widget.LinearLayout; @@ -8,7 +9,11 @@ import androidx.annotation.NonNull; import androidx.core.text.HtmlCompat; import androidx.recyclerview.widget.RecyclerView; +import com.facebook.drawee.backends.pipeline.Fresco; import com.facebook.drawee.view.SimpleDraweeView; +import com.facebook.imagepipeline.common.ResizeOptions; +import com.facebook.imagepipeline.request.ImageRequest; +import com.facebook.imagepipeline.request.ImageRequestBuilder; import awais.instagrabber.R; import awais.instagrabber.databinding.LayoutDmInboxItemBinding; @@ -50,14 +55,27 @@ public final class DirectMessageInboxItemViewHolder extends RecyclerView.ViewHol multipleProfilePics[i].setImageURI(users[i].getSdProfilePic()); } } else { - binding.ivProfilePic.setVisibility(View.VISIBLE); - multipleProfilePicsContainer.setVisibility(View.GONE); - binding.ivProfilePic.setImageURI(users.length == 1 ? users[0].getSdProfilePic() : null); + final String uriString = users.length == 1 ? users[0].getSdProfilePic() : null; + if (uriString == null) { + binding.ivProfilePic.setVisibility(View.GONE); + } else { + binding.ivProfilePic.setVisibility(View.VISIBLE); + multipleProfilePicsContainer.setVisibility(View.GONE); + final ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(uriString)) + .setResizeOptions(new ResizeOptions(50, 50)) + .build(); + binding.ivProfilePic.setController( + Fresco.newDraweeControllerBuilder() + .setOldController(binding.ivProfilePic.getController()) + .setImageRequest(request) + .build() + ); + } } binding.tvUsername.setText(model.getThreadTitle()); final DirectItemModel lastItemModel = itemModels[itemModels.length - 1]; final DirectItemType itemType = lastItemModel.getItemType(); - binding.notTextType.setVisibility(itemType != DirectItemType.TEXT ? View.VISIBLE : View.GONE); + // binding.notTextType.setVisibility(itemType != DirectItemType.TEXT ? View.VISIBLE : View.GONE); final Context context = itemView.getContext(); final CharSequence messageText; switch (itemType) { diff --git a/app/src/main/java/awais/instagrabber/dialogs/QuickAccessDialog.java b/app/src/main/java/awais/instagrabber/dialogs/QuickAccessDialog.java index 602914a1..2480c240 100755 --- a/app/src/main/java/awais/instagrabber/dialogs/QuickAccessDialog.java +++ b/app/src/main/java/awais/instagrabber/dialogs/QuickAccessDialog.java @@ -21,8 +21,6 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment; import java.util.ArrayList; import awais.instagrabber.R; -import awais.instagrabber.activities.MainActivity; -import awais.instagrabber.activities.MainActivityBackup; import awais.instagrabber.adapters.SimpleAdapter; import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.DataBox; @@ -113,10 +111,10 @@ public final class QuickAccessDialog extends BottomSheetDialogFragment implement else Utils.showImportExportDialog(v.getContext()); } else if (tag instanceof DataBox.FavoriteModel) { - if (MainActivityBackup.scanHack != null) { - MainActivityBackup.scanHack.onResult(((DataBox.FavoriteModel) tag).getQuery()); - dismiss(); - } + // if (MainActivityBackup.scanHack != null) { + // MainActivityBackup.scanHack.onResult(((DataBox.FavoriteModel) tag).getQuery()); + // dismiss(); + // } } else if (tag instanceof DataBox.CookieModel) { final DataBox.CookieModel cookieModel = (DataBox.CookieModel) tag; @@ -140,8 +138,8 @@ public final class QuickAccessDialog extends BottomSheetDialogFragment implement Utils.dataBox.delFavorite(favoriteModel); favoritesAdapter.setItems(Utils.dataBox.getAllFavorites()); }) - .setNegativeButton(R.string.no, null).setMessage(getString(R.string.quick_access_confirm_delete, - favoriteModel.getQuery())).show(); + .setNegativeButton(R.string.no, null).setMessage(getString(R.string.quick_access_confirm_delete, + favoriteModel.getQuery())).show(); } else if (tag instanceof DataBox.CookieModel) { final DataBox.CookieModel cookieModel = (DataBox.CookieModel) tag; @@ -153,8 +151,8 @@ public final class QuickAccessDialog extends BottomSheetDialogFragment implement Utils.dataBox.delUserCookie(cookieModel); rvQuickAccess.findViewWithTag(cookieModel).setVisibility(View.GONE); }) - .setNegativeButton(R.string.no, null).setMessage(getString(R.string.quick_access_confirm_delete, - cookieModel.getUsername())).show(); + .setNegativeButton(R.string.no, null).setMessage(getString(R.string.quick_access_confirm_delete, + cookieModel.getUsername())).show(); } return true; diff --git a/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java b/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java index bfead2b0..a56c936d 100644 --- a/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java @@ -187,11 +187,6 @@ public class HashTagFragment extends Fragment { return; } if (checkAndResetAction()) return; - // startActivity(new Intent(requireContext(), PostViewer.class) - // .putExtra(Constants.EXTRAS_INDEX, position) - // .putExtra(Constants.EXTRAS_POST, postModel) - // .putExtra(Constants.EXTRAS_USER, hashtag) - // .putExtra(Constants.EXTRAS_TYPE, PostItemType.MAIN)); final List postModels = postsViewModel.getList().getValue(); if (postModels == null || postModels.size() == 0) return; if (postModels.get(0) == null) return; diff --git a/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java b/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java index 1994328c..b17ab187 100644 --- a/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java @@ -209,12 +209,6 @@ public class LocationFragment extends Fragment { idsOrShortCodes, isId); NavHostFragment.findNavController(this).navigate(action); - // startActivity(new Intent(requireContext(), PostViewer.class) - // .putExtra(Constants.EXTRAS_INDEX, position) - // .putExtra(Constants.EXTRAS_POST, postModel) - // .putExtra(Constants.EXTRAS_USER, locationId) - // .putExtra(Constants.EXTRAS_TYPE, PostItemType.MAIN)); - }, (model, position) -> { if (!postsAdapter.isSelecting()) { checkAndResetAction(); diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java index 826ca22c..9fb7106e 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -355,8 +355,6 @@ public class StoryViewerFragment extends Fragment { idsOrShortCodes, isId); NavHostFragment.findNavController(this).navigate(action); - // startActivity(new Intent(requireContext(), PostViewer.class) - // .putExtra(Constants.EXTRAS_POST, new PostModel(, )); }); final View.OnClickListener storyActionListener = v -> { final Object tag = v.getTag(); diff --git a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageSettingsFragment.java b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageSettingsFragment.java index 94792873..4bc8d93c 100644 --- a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageSettingsFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageSettingsFragment.java @@ -1,6 +1,6 @@ package awais.instagrabber.fragments.directmessages; -import android.content.Intent; +import android.content.DialogInterface; import android.os.AsyncTask; import android.os.Bundle; import android.text.Editable; @@ -35,7 +35,6 @@ import java.util.List; import awais.instagrabber.BuildConfig; import awais.instagrabber.R; -import awais.instagrabber.activities.ProfileViewer; import awais.instagrabber.adapters.DirectMessageMembersAdapter; import awais.instagrabber.asyncs.direct_messages.DirectMessageInboxThreadFetcher; import awais.instagrabber.databinding.FragmentDirectMessagesSettingsBinding; @@ -46,20 +45,23 @@ import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Utils; public class DirectMessageSettingsFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener { - private static final String TAG = "DirectMessagesSettingsFrag"; + private static final String TAG = "DirectMsgsSettingsFrag"; private FragmentActivity fragmentActivity; - private RecyclerView userList, leftUserList; + private RecyclerView userList; + private RecyclerView leftUserList; private EditText titleText; private View leftTitle; private AppCompatImageView titleSend; private AppCompatButton btnLeave; - private LinearLayoutManager layoutManager, layoutManagerDos; + private LinearLayoutManager layoutManager; + private LinearLayoutManager layoutManagerDos; private String threadId, threadTitle; private final String cookie = Utils.settingsHelper.getString(Constants.COOKIE); private boolean amAdmin; private AsyncTask currentlyRunning; - private DirectMessageMembersAdapter memberAdapter, leftAdapter; + private DirectMessageMembersAdapter memberAdapter; + private DirectMessageMembersAdapter leftAdapter; private View.OnClickListener clickListener, basicClickListener; private final FetchListener fetchListener = new FetchListener() { @@ -69,8 +71,13 @@ public class DirectMessageSettingsFragment extends Fragment implements SwipeRefr @Override public void onResult(final InboxThreadModel threadModel) { final List adminList = Arrays.asList(threadModel.getAdmins()); - amAdmin = adminList.contains(Long.parseLong(Utils.getUserIdFromCookie(cookie))); - memberAdapter = new DirectMessageMembersAdapter(threadModel.getUsers(), adminList, requireContext(), amAdmin ? clickListener : basicClickListener); + final String userIdFromCookie = Utils.getUserIdFromCookie(cookie); + if (userIdFromCookie == null) return; + amAdmin = adminList.contains(Long.parseLong(userIdFromCookie)); + memberAdapter = new DirectMessageMembersAdapter(threadModel.getUsers(), + adminList, + requireContext(), + amAdmin ? clickListener : basicClickListener); userList.setAdapter(memberAdapter); if (threadModel.getLeftUsers() != null && threadModel.getLeftUsers().length > 0) { leftTitle.setVisibility(View.VISIBLE); @@ -84,15 +91,12 @@ public class DirectMessageSettingsFragment extends Fragment implements SwipeRefr public void onCreate(@Nullable final Bundle savedInstanceState) { super.onCreate(savedInstanceState); fragmentActivity = requireActivity(); - basicClickListener = v -> { final Object tag = v.getTag(); if (tag instanceof ProfileModel) { ProfileModel model = (ProfileModel) tag; - startActivity( - new Intent(requireContext(), ProfileViewer.class) - .putExtra(Constants.EXTRAS_USERNAME, model.getUsername()) - ); + // startActivity(new Intent(requireContext(), ProfileViewer.class) + // .putExtra(Constants.EXTRAS_USERNAME, model.getUsername())); } }; @@ -101,28 +105,25 @@ public class DirectMessageSettingsFragment extends Fragment implements SwipeRefr if (tag instanceof ProfileModel) { ProfileModel model = (ProfileModel) tag; if (!amAdmin || model.getId().equals(Utils.getUserIdFromCookie(cookie))) { - startActivity( - new Intent(requireContext(), ProfileViewer.class) - .putExtra(Constants.EXTRAS_USERNAME, model.getUsername()) - ); - } - else { - new AlertDialog.Builder(requireContext()).setAdapter( - new ArrayAdapter<>(requireContext(), android.R.layout.simple_list_item_1, new String[]{ - getString(R.string.open_profile), - getString(R.string.dms_action_kick), - }), - (d,w) -> { - if (w == 0) - startActivity( - new Intent(requireContext(), ProfileViewer.class) - .putExtra(Constants.EXTRAS_USERNAME, model.getUsername()) - ); - else if (w == 1) { - new ChangeSettings().execute("remove_users", model.getId()); - onRefresh(); - } - }).show(); + // startActivity(new Intent(requireContext(), ProfileViewer.class) + // .putExtra(Constants.EXTRAS_USERNAME, model.getUsername())); + } else { + final ArrayAdapter adapter = new ArrayAdapter<>(requireContext(), android.R.layout.simple_list_item_1, new String[]{ + getString(R.string.open_profile), + getString(R.string.dms_action_kick), + }); + final DialogInterface.OnClickListener clickListener = (d, w) -> { + if (w == 0) { + // startActivity(new Intent(requireContext(), ProfileViewer.class) + // .putExtra(Constants.EXTRAS_USERNAME, model.getUsername())); + } else if (w == 1) { + new ChangeSettings().execute("remove_users", model.getId()); + onRefresh(); + } + }; + new AlertDialog.Builder(requireContext()) + .setAdapter(adapter, clickListener) + .show(); } } }; @@ -146,7 +147,9 @@ public class DirectMessageSettingsFragment extends Fragment implements SwipeRefr return false; } }; - + if (getArguments() == null) { + return null; + } threadId = DirectMessageSettingsFragmentArgs.fromBundle(getArguments()).getThreadId(); threadTitle = DirectMessageSettingsFragmentArgs.fromBundle(getArguments()).getTitle(); binding.swipeRefreshLayout.setEnabled(false); @@ -185,11 +188,9 @@ public class DirectMessageSettingsFragment extends Fragment implements SwipeRefr btnLeave = binding.btnLeave; btnLeave.setOnClickListener(v -> { new AlertDialog.Builder(requireContext()).setTitle(R.string.dms_action_leave_question) - .setPositiveButton(R.string.yes, (x,y) -> { - new ChangeSettings().execute("leave"); - }) - .setNegativeButton(R.string.no, null) - .show(); + .setPositiveButton(R.string.yes, (x, y) -> new ChangeSettings().execute("leave")) + .setNegativeButton(R.string.no, null) + .show(); }); currentlyRunning = new DirectMessageInboxThreadFetcher(threadId, null, null, fetchListener).execute(); @@ -207,7 +208,9 @@ public class DirectMessageSettingsFragment extends Fragment implements SwipeRefr try { currentlyRunning.cancel(true); } catch (final Exception e) { - if (BuildConfig.DEBUG) Log.e(TAG, "", e); + if (BuildConfig.DEBUG) { + Log.e(TAG, "", e); + } } } } @@ -219,14 +222,14 @@ public class DirectMessageSettingsFragment extends Fragment implements SwipeRefr protected Void doInBackground(String... rawAction) { action = rawAction[0]; if (rawAction.length == 2) argument = rawAction[1]; - final String url = "https://i.instagram.com/api/v1/direct_v2/threads/"+threadId+"/"+action+"/"; + final String url = "https://i.instagram.com/api/v1/direct_v2/threads/" + threadId + "/" + action + "/"; try { String urlParameters = "_csrftoken=" + cookie.split("csrftoken=")[1].split(";")[0] - +"&_uuid=" + Utils.settingsHelper.getString(Constants.DEVICE_UUID); + + "&_uuid=" + Utils.settingsHelper.getString(Constants.DEVICE_UUID); if (action.equals("update_title")) urlParameters += "&title=" + URLEncoder.encode(titleText.getText().toString(), "UTF-8") - .replaceAll("\\+", "%20").replaceAll("%21", "!").replaceAll("%27", "'") - .replaceAll("%28", "(").replaceAll("%29", ")").replaceAll("%7E", "~"); + .replaceAll("\\+", "%20").replaceAll("%21", "!").replaceAll("%27", "'") + .replaceAll("%28", "(").replaceAll("%29", ")").replaceAll("%7E", "~"); else if (action.startsWith("remove_users")) urlParameters += ("&user_ids=[" + argument + "]"); final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); @@ -260,16 +263,13 @@ public class DirectMessageSettingsFragment extends Fragment implements SwipeRefr titleSend.setVisibility(View.GONE); titleText.clearFocus(); DirectMessageThreadFragment.hasSentSomething = true; - } - else if (action.equals("leave")) { + } else if (action.equals("leave")) { DirectMessageInboxFragment.refreshPlease = true; NavHostFragment.findNavController(DirectMessageSettingsFragment.this).popBackStack(R.id.directMessagesInboxFragment, false); - } - else { + } else { DirectMessageThreadFragment.hasSentSomething = true; } - } - else Toast.makeText(requireContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); + } else Toast.makeText(requireContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); } } } diff --git a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java index 5022fb76..f8fddc1b 100644 --- a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java @@ -12,6 +12,7 @@ import android.os.Handler; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -25,7 +26,6 @@ import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentContainerView; import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModelProvider; @@ -50,7 +50,6 @@ import java.util.LinkedList; import java.util.List; import awais.instagrabber.R; -import awais.instagrabber.activities.PostViewer; import awais.instagrabber.adapters.DirectMessageItemsAdapter; import awais.instagrabber.asyncs.ImageUploader; import awais.instagrabber.asyncs.direct_messages.DirectMessageInboxThreadFetcher; @@ -60,7 +59,6 @@ import awais.instagrabber.databinding.FragmentDirectMessagesThreadBinding; import awais.instagrabber.interfaces.FetchListener; import awais.instagrabber.interfaces.MentionClickListener; import awais.instagrabber.models.ImageUploadOptions; -import awais.instagrabber.models.PostModel; import awais.instagrabber.models.ProfileModel; import awais.instagrabber.models.direct_messages.DirectItemModel; import awais.instagrabber.models.direct_messages.InboxThreadModel; @@ -76,14 +74,16 @@ public class DirectMessageThreadFragment extends Fragment { private static final int PICK_IMAGE = 100; private AppCompatActivity fragmentActivity; - private String threadId, threadTitle, cursor, lastMessage; + private String threadId; + private String threadTitle; + private String cursor; + private String lastMessage; private final String cookie = Utils.settingsHelper.getString(Constants.COOKIE); private final String myId = Utils.getUserIdFromCookie(cookie); private FragmentDirectMessagesThreadBinding binding; private DirectItemModelListViewModel listViewModel; private DirectItemModel directItemModel; private RecyclerView messageList; - // private AppCompatImageView dmInfo, dmSeen; private boolean hasDeletedSomething; private boolean hasOlder = true; public static boolean hasSentSomething; @@ -158,6 +158,8 @@ public class DirectMessageThreadFragment extends Fragment { binding.swipeRefreshLayout.setRefreshing(false); } }; + private LinearLayout root; + private boolean shouldRefresh = true; @Override public void onCreate(@Nullable final Bundle savedInstanceState) { @@ -166,27 +168,29 @@ public class DirectMessageThreadFragment extends Fragment { setHasOptionsMenu(true); } - @Override - public void onResume() { - super.onResume(); - if (hasSentSomething) { - new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - } - @Override public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { - binding = FragmentDirectMessagesThreadBinding.inflate(inflater, container, false); - final FragmentContainerView containerTwo = (FragmentContainerView) container.getParent(); - // dmInfo = containerTwo.findViewById(R.id.dmInfo); - // dmSeen = containerTwo.findViewById(R.id.dmSeen); - final LinearLayout root = binding.getRoot(); - listViewModel = new ViewModelProvider(fragmentActivity).get(DirectItemModelListViewModel.class); - if (getArguments() == null) { + if (root != null) { + shouldRefresh = false; return root; } + binding = FragmentDirectMessagesThreadBinding.inflate(inflater, container, false); + root = binding.getRoot(); + return root; + } + + @Override + public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { + if (!shouldRefresh) return; + init(); + shouldRefresh = false; + } + + private void init() { + listViewModel = new ViewModelProvider(fragmentActivity).get(DirectItemModelListViewModel.class); + if (getArguments() == null) return; if (!DirectMessageThreadFragmentArgs.fromBundle(getArguments()).getThreadId().equals(threadId)) { listViewModel.empty(); threadId = DirectMessageThreadFragmentArgs.fromBundle(getArguments()).getThreadId(); @@ -203,25 +207,14 @@ public class DirectMessageThreadFragment extends Fragment { binding.image.setOnClickListener(clickListener); final LinearLayoutManager layoutManager = new LinearLayoutManager(requireContext()); layoutManager.setReverseLayout(true); - // layoutManager.setStackFromEnd(true); messageList.setLayoutManager(layoutManager); messageList.addOnScrollListener(new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> { if (Utils.isEmpty(cursor) || !hasOlder) { return; } - new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, cursor, fetchListener).execute(); // serial because we don't want messages to be randomly ordered + new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, cursor, fetchListener) + .execute(); // serial because we don't want messages to be randomly ordered })); - // dmInfo.setOnClickListener(v -> { - // final NavDirections action = - // DirectMessageThreadFragmentDirections.actionDMThreadFragmentToDMSettingsFragment(threadId, threadTitle); - // NavHostFragment.findNavController(DirectMessageThreadFragment.this).navigate(action); - // }); - - // dmSeen.setOnClickListener(v -> { - // new ThreadAction().execute("seen", lastMessage); - // dmSeen.setVisibility(View.GONE); - // }); - final DialogInterface.OnClickListener onDialogListener = (dialogInterface, which) -> { if (which == 0) { final DirectItemType itemType = directItemModel.getItemType(); @@ -248,11 +241,12 @@ public class DirectMessageThreadFragment extends Fragment { final ProfileModel user = getUser(directItemModel.getUserId()); final DirectItemModel.DirectItemMediaModel selectedItem = itemType == DirectItemType.MEDIA ? directItemModel.getMediaModel() : directItemModel.getRavenMediaModel().getMedia(); - final String url = selectedItem.getMediaType() == MediaItemType.MEDIA_TYPE_VIDEO ? selectedItem.getVideoUrl() : selectedItem.getThumbUrl(); + final String url = selectedItem.getMediaType() == MediaItemType.MEDIA_TYPE_VIDEO + ? selectedItem.getVideoUrl() + : selectedItem.getThumbUrl(); if (url == null) { Toast.makeText(requireContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); - } - else { + } else { Utils.dmDownload(requireContext(), user.getUsername(), DownloadMethod.DOWNLOAD_DIRECT, selectedItem); Toast.makeText(requireContext(), R.string.downloader_downloading_media, Toast.LENGTH_SHORT).show(); } @@ -283,7 +277,7 @@ public class DirectMessageThreadFragment extends Fragment { searchUsername(directItemModel.getText().toString().split("@")[1].split(" ")[0]); break; default: - Log.d("austin_debug", "unsupported type " + itemType); + Log.d(TAG, "unsupported type " + itemType); } } else if (which == 1) { sendText(null, directItemModel.getItemId(), directItemModel.isLiked()); @@ -350,9 +344,22 @@ public class DirectMessageThreadFragment extends Fragment { messageList.setAdapter(adapter); listViewModel.getList().observe(fragmentActivity, adapter::submitList); if (listViewModel.isEmpty()) { - new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener) + .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + } + + @Override + public void onResume() { + super.onResume(); + if (hasSentSomething) { + new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener) + .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + final ActionBar actionBar = fragmentActivity.getSupportActionBar(); + if (actionBar != null) { + actionBar.setTitle(threadTitle); } - return root; } @Override @@ -361,6 +368,27 @@ public class DirectMessageThreadFragment extends Fragment { item.setVisible(false); } + @Override + public void onCreateOptionsMenu(@NonNull final Menu menu, @NonNull final MenuInflater inflater) { + inflater.inflate(R.menu.dm_thread_menu, menu); + } + + @Override + public boolean onOptionsItemSelected(@NonNull final MenuItem item) { + final int itemId = item.getItemId(); + switch (itemId) { + case R.id.info: + final NavDirections action = DirectMessageThreadFragmentDirections.actionDMThreadFragmentToDMSettingsFragment(threadId, threadTitle); + NavHostFragment.findNavController(this).navigate(action); + return true; + case R.id.mark_as_seen: + new ThreadAction().execute("seen", lastMessage); + item.setVisible(false); + return true; + } + return super.onOptionsItemSelected(item); + } + @Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); @@ -409,7 +437,8 @@ public class DirectMessageThreadFragment extends Fragment { } DirectMessageInboxFragment.refreshPlease = true; hasSentSomething = true; - new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener) + .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }); } @@ -433,7 +462,9 @@ public class DirectMessageThreadFragment extends Fragment { // Broadcast final DirectThreadBroadcaster.ImageBroadcastOptions options = new DirectThreadBroadcaster.ImageBroadcastOptions(true, uploadId); hasSentSomething = true; - broadcast(options, broadcastResponse -> new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)); + broadcast(options, + broadcastResponse -> new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener) + .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)); } catch (JSONException e) { Log.e(TAG, "Error parsing json response", e); } @@ -446,7 +477,8 @@ public class DirectMessageThreadFragment extends Fragment { } } - private void broadcast(final DirectThreadBroadcaster.BroadcastOptions broadcastOptions, final DirectThreadBroadcaster.OnBroadcastCompleteListener listener) { + private void broadcast(final DirectThreadBroadcaster.BroadcastOptions broadcastOptions, + final DirectThreadBroadcaster.OnBroadcastCompleteListener listener) { final DirectThreadBroadcaster broadcaster = new DirectThreadBroadcaster(threadId); broadcaster.setOnTaskCompleteListener(listener); broadcaster.execute(broadcastOptions); @@ -529,7 +561,8 @@ public class DirectMessageThreadFragment extends Fragment { protected void onPostExecute(Void result) { if (hasDeletedSomething) { directItemModel = null; - new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener) + .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } } diff --git a/app/src/main/java/awais/instagrabber/fragments/main/DiscoverFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/DiscoverFragment.java index 71eb75b0..1e8c1566 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/DiscoverFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/DiscoverFragment.java @@ -202,10 +202,6 @@ public class DiscoverFragment extends Fragment { return; } if (checkAndResetAction()) return; - // startActivity(new Intent(requireContext(), PostViewer.class) - // .putExtra(Constants.EXTRAS_INDEX, position) - // .putExtra(Constants.EXTRAS_TYPE, PostItemType.DISCOVER) - // .putExtra(Constants.EXTRAS_POST, new PostModel(model.getShortCode(), false))); final List discoverItemModels = discoverItemViewModel.getList().getValue(); if (discoverItemModels == null || discoverItemModels.size() == 0) return; if (discoverItemModels.get(0) == null) return; diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java index 1e4ff6eb..c9c0e0e6 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -12,6 +12,8 @@ import android.text.style.StyleSpan; import android.util.Log; import android.view.ActionMode; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -179,12 +181,14 @@ public class ProfileFragment extends Fragment { action.setUsername("@" + text); NavHostFragment.findNavController(this).navigate(action); }; + private MenuItem favMenuItem; @Override public void onCreate(@Nullable final Bundle savedInstanceState) { super.onCreate(savedInstanceState); fragmentActivity = (MainActivity) requireActivity(); friendshipService = FriendshipService.getInstance(); + setHasOptionsMenu(true); } @Override @@ -225,6 +229,12 @@ public class ProfileFragment extends Fragment { shouldRefresh = false; } + @Override + public void onCreateOptionsMenu(@NonNull final Menu menu, @NonNull final MenuInflater inflater) { + inflater.inflate(R.menu.profile_menu, menu); + favMenuItem = menu.findItem(R.id.favourites); + } + @Override public void onDestroy() { super.onDestroy(); @@ -289,6 +299,12 @@ public class ProfileFragment extends Fragment { private void fetchProfileDetails() { new ProfileFetcher(username.substring(1), profileModel -> { this.profileModel = profileModel; + final String userIdFromCookie = Utils.getUserIdFromCookie(cookie); + final boolean isSelf = isLoggedIn + && profileModel != null + && userIdFromCookie != null + && userIdFromCookie.equals(profileModel.getId()); + favMenuItem.setVisible(isSelf); setProfileDetails(); }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); @@ -423,8 +439,8 @@ public class ProfileFragment extends Fragment { span.setSpan(new StyleSpan(Typeface.BOLD), 0, followingCountStrLen, 0); binding.mainFollowing.setText(span); - binding.mainFullName.setText(Utils.isEmpty(profileModel.getName()) ? profileModel - .getUsername() : profileModel.getName()); + binding.mainFullName.setText(Utils.isEmpty(profileModel.getName()) ? profileModel.getUsername() + : profileModel.getName()); CharSequence biography = profileModel.getBiography(); binding.mainBiography.setCaptionIsExpandable(true); @@ -455,13 +471,10 @@ public class ProfileFragment extends Fragment { if (isLoggedIn) { final View.OnClickListener followClickListener = v -> { - // startActivity(new Intent(requireContext(), FollowViewerFragment.class) - // .putExtra(Constants.EXTRAS_FOLLOWERS, v == binding.mainFollowers) - // .putExtra(Constants.EXTRAS_NAME, profileModel.getUsername()) - // .putExtra(Constants.EXTRAS_ID, profileId)); - final NavDirections action = ProfileFragmentDirections.actionProfileFragmentToFollowViewerFragment(profileId, - v == binding.mainFollowers, - profileModel.getUsername()); + final NavDirections action = ProfileFragmentDirections.actionProfileFragmentToFollowViewerFragment( + profileId, + v == binding.mainFollowers, + profileModel.getUsername()); NavHostFragment.findNavController(this).navigate(action); }; diff --git a/app/src/main/res/layout/layout_dm_inbox_item.xml b/app/src/main/res/layout/layout_dm_inbox_item.xml index fa17ae41..3adcec21 100644 --- a/app/src/main/res/layout/layout_dm_inbox_item.xml +++ b/app/src/main/res/layout/layout_dm_inbox_item.xml @@ -1,5 +1,5 @@ - + android:padding="4dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + android:orientation="horizontal" + android:visibility="gone"> - + - + - + + + + + + + + + + + + + + - - - - - - - - \ No newline at end of file + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/dm_thread_menu.xml b/app/src/main/res/menu/dm_thread_menu.xml new file mode 100644 index 00000000..e0631a56 --- /dev/null +++ b/app/src/main/res/menu/dm_thread_menu.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/main_menu.xml b/app/src/main/res/menu/main_menu.xml index 2b94374d..640dc82a 100644 --- a/app/src/main/res/menu/main_menu.xml +++ b/app/src/main/res/menu/main_menu.xml @@ -1,12 +1,11 @@ - - + + + + + + + diff --git a/app/src/main/res/menu/profile_menu.xml b/app/src/main/res/menu/profile_menu.xml new file mode 100644 index 00000000..105576e7 --- /dev/null +++ b/app/src/main/res/menu/profile_menu.xml @@ -0,0 +1,12 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3bbca35b..82373257 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -249,4 +249,6 @@ Relogin Refresh your cookies if facing any issues Successfully logged out! + Info + Mark as seen \ No newline at end of file