|
|
@ -4,24 +4,27 @@ import android.content.Context; |
|
|
|
import android.graphics.Typeface; |
|
|
|
import android.os.AsyncTask; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.Handler; |
|
|
|
import android.text.SpannableStringBuilder; |
|
|
|
import android.text.style.RelativeSizeSpan; |
|
|
|
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; |
|
|
|
import android.widget.Toast; |
|
|
|
|
|
|
|
import androidx.activity.OnBackPressedCallback; |
|
|
|
import androidx.activity.OnBackPressedDispatcher; |
|
|
|
import androidx.annotation.NonNull; |
|
|
|
import androidx.annotation.Nullable; |
|
|
|
import androidx.appcompat.app.ActionBar; |
|
|
|
import androidx.core.content.PermissionChecker; |
|
|
|
import androidx.fragment.app.Fragment; |
|
|
|
import androidx.lifecycle.ViewModelProvider; |
|
|
|
import androidx.navigation.NavController; |
|
|
|
import androidx.navigation.NavDirections; |
|
|
|
import androidx.navigation.fragment.NavHostFragment; |
|
|
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
|
|
@ -29,73 +32,67 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
|
|
|
import com.google.android.material.snackbar.BaseTransientBottomBar; |
|
|
|
import com.google.android.material.snackbar.Snackbar; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import awais.instagrabber.R; |
|
|
|
import awais.instagrabber.activities.MainActivity; |
|
|
|
import awais.instagrabber.adapters.PostsAdapter; |
|
|
|
import awais.instagrabber.adapters.FeedAdapterV2; |
|
|
|
import awais.instagrabber.asyncs.HashtagFetcher; |
|
|
|
import awais.instagrabber.asyncs.PostsFetcher; |
|
|
|
import awais.instagrabber.asyncs.HashtagPostFetchService; |
|
|
|
import awais.instagrabber.customviews.PrimaryActionModeCallback; |
|
|
|
import awais.instagrabber.customviews.helpers.GridAutofitLayoutManager; |
|
|
|
import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration; |
|
|
|
import awais.instagrabber.customviews.helpers.NestedCoordinatorLayout; |
|
|
|
import awais.instagrabber.customviews.helpers.RecyclerLazyLoader; |
|
|
|
import awais.instagrabber.databinding.FragmentHashtagBinding; |
|
|
|
import awais.instagrabber.interfaces.FetchListener; |
|
|
|
import awais.instagrabber.dialogs.PostsLayoutPreferencesDialogFragment; |
|
|
|
import awais.instagrabber.fragments.main.FeedFragmentDirections; |
|
|
|
import awais.instagrabber.models.FeedModel; |
|
|
|
import awais.instagrabber.models.HashtagModel; |
|
|
|
import awais.instagrabber.models.PostModel; |
|
|
|
import awais.instagrabber.models.PostsLayoutPreferences; |
|
|
|
import awais.instagrabber.models.StoryModel; |
|
|
|
import awais.instagrabber.models.enums.DownloadMethod; |
|
|
|
import awais.instagrabber.models.enums.FavoriteType; |
|
|
|
import awais.instagrabber.models.enums.PostItemType; |
|
|
|
import awais.instagrabber.utils.Constants; |
|
|
|
import awais.instagrabber.utils.CookieUtils; |
|
|
|
import awais.instagrabber.utils.DataBox; |
|
|
|
import awais.instagrabber.utils.DownloadUtils; |
|
|
|
import awais.instagrabber.utils.TextUtils; |
|
|
|
import awais.instagrabber.utils.Utils; |
|
|
|
import awais.instagrabber.viewmodels.PostsViewModel; |
|
|
|
import awais.instagrabber.webservices.ServiceCallback; |
|
|
|
import awais.instagrabber.webservices.StoriesService; |
|
|
|
import awais.instagrabber.webservices.TagsService; |
|
|
|
import awaisomereport.LogCollector; |
|
|
|
|
|
|
|
import static androidx.core.content.PermissionChecker.checkSelfPermission; |
|
|
|
import static awais.instagrabber.utils.DownloadUtils.WRITE_PERMISSION; |
|
|
|
import static awais.instagrabber.utils.Utils.logCollector; |
|
|
|
import static awais.instagrabber.utils.Utils.settingsHelper; |
|
|
|
|
|
|
|
public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener { |
|
|
|
private static final String TAG = "HashTagFragment"; |
|
|
|
private static final int STORAGE_PERM_REQUEST_CODE = 8020; |
|
|
|
|
|
|
|
public static final String ARG_HASHTAG = "hashtag"; |
|
|
|
|
|
|
|
private MainActivity fragmentActivity; |
|
|
|
private FragmentHashtagBinding binding; |
|
|
|
private NestedCoordinatorLayout root; |
|
|
|
private boolean shouldRefresh = true, hasStories = false; |
|
|
|
private boolean shouldRefresh = true; |
|
|
|
private boolean hasStories = false; |
|
|
|
private String hashtag; |
|
|
|
private HashtagModel hashtagModel; |
|
|
|
private PostsViewModel postsViewModel; |
|
|
|
private PostsAdapter postsAdapter; |
|
|
|
private ActionMode actionMode; |
|
|
|
private StoriesService storiesService; |
|
|
|
private boolean hasNextPage; |
|
|
|
private String endCursor; |
|
|
|
private AsyncTask<?, ?, ?> currentlyExecuting; |
|
|
|
private boolean isLoggedIn; |
|
|
|
private TagsService tagsService; |
|
|
|
private boolean isPullToRefresh; |
|
|
|
private boolean storiesFetching; |
|
|
|
|
|
|
|
private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) { |
|
|
|
@Override |
|
|
|
public void handleOnBackPressed() { |
|
|
|
setEnabled(false); |
|
|
|
remove(); |
|
|
|
if (postsAdapter == null) return; |
|
|
|
postsAdapter.clearSelection(); |
|
|
|
// if (postsAdapter == null) return; |
|
|
|
// postsAdapter.clearSelection(); |
|
|
|
} |
|
|
|
}; |
|
|
|
private final PrimaryActionModeCallback multiSelectAction = new PrimaryActionModeCallback( |
|
|
@ -109,47 +106,132 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe |
|
|
|
@Override |
|
|
|
public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { |
|
|
|
if (item.getItemId() == R.id.action_download) { |
|
|
|
if (postsAdapter == null || hashtag == null) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
final Context context = getContext(); |
|
|
|
if (context == null) return false; |
|
|
|
DownloadUtils.batchDownload(context, |
|
|
|
hashtag, |
|
|
|
DownloadMethod.DOWNLOAD_MAIN, |
|
|
|
postsAdapter.getSelectedModels()); |
|
|
|
checkAndResetAction(); |
|
|
|
// if (postsAdapter == null || hashtag == null) { |
|
|
|
// return false; |
|
|
|
// } |
|
|
|
// final Context context = getContext(); |
|
|
|
// if (context == null) return false; |
|
|
|
// DownloadUtils.batchDownload(context, |
|
|
|
// hashtag, |
|
|
|
// DownloadMethod.DOWNLOAD_MAIN, |
|
|
|
// postsAdapter.getSelectedModels()); |
|
|
|
// checkAndResetAction(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
}); |
|
|
|
private final FetchListener<List<PostModel>> postsFetchListener = new FetchListener<List<PostModel>>() { |
|
|
|
// private final FetchListener<List<PostModel>> postsFetchListener = new FetchListener<List<PostModel>>() { |
|
|
|
// @Override |
|
|
|
// public void onResult(final List<PostModel> result) { |
|
|
|
// binding.swipeRefreshLayout.setRefreshing(false); |
|
|
|
// if (result == null) return; |
|
|
|
// binding.mainPosts.post(() -> binding.mainPosts.setVisibility(View.VISIBLE)); |
|
|
|
// final List<PostModel> postModels = postsViewModel.getList().getValue(); |
|
|
|
// List<PostModel> finalList = postModels == null || postModels.isEmpty() |
|
|
|
// ? new ArrayList<>() |
|
|
|
// : new ArrayList<>(postModels); |
|
|
|
// if (isPullToRefresh) { |
|
|
|
// finalList = result; |
|
|
|
// isPullToRefresh = false; |
|
|
|
// } else { |
|
|
|
// finalList.addAll(result); |
|
|
|
// } |
|
|
|
// finalList.addAll(result); |
|
|
|
// postsViewModel.getList().postValue(finalList); |
|
|
|
// PostModel model = null; |
|
|
|
// if (!result.isEmpty()) { |
|
|
|
// model = result.get(result.size() - 1); |
|
|
|
// } |
|
|
|
// if (model == null) return; |
|
|
|
// endCursor = model.getEndCursor(); |
|
|
|
// hasNextPage = model.hasNextPage(); |
|
|
|
// model.setPageCursor(false, null); |
|
|
|
// } |
|
|
|
// }; |
|
|
|
private final FeedAdapterV2.FeedItemCallback feedItemCallback = new FeedAdapterV2.FeedItemCallback() { |
|
|
|
@Override |
|
|
|
public void onResult(final List<PostModel> result) { |
|
|
|
binding.swipeRefreshLayout.setRefreshing(false); |
|
|
|
if (result == null) return; |
|
|
|
binding.mainPosts.post(() -> binding.mainPosts.setVisibility(View.VISIBLE)); |
|
|
|
final List<PostModel> postModels = postsViewModel.getList().getValue(); |
|
|
|
List<PostModel> finalList = postModels == null || postModels.isEmpty() |
|
|
|
? new ArrayList<>() |
|
|
|
: new ArrayList<>(postModels); |
|
|
|
if (isPullToRefresh) { |
|
|
|
finalList = result; |
|
|
|
isPullToRefresh = false; |
|
|
|
} else { |
|
|
|
finalList.addAll(result); |
|
|
|
public void onPostClick(final FeedModel feedModel, final View profilePicView, final View mainPostImage) { |
|
|
|
openPostDialog(feedModel, profilePicView, mainPostImage, -1); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onSliderClick(final FeedModel feedModel, final int position) { |
|
|
|
openPostDialog(feedModel, null, null, position); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onCommentsClick(final FeedModel feedModel) { |
|
|
|
final NavDirections commentsAction = HashTagFragmentDirections.actionGlobalCommentsViewerFragment( |
|
|
|
feedModel.getShortCode(), |
|
|
|
feedModel.getPostId(), |
|
|
|
feedModel.getProfileModel().getId() |
|
|
|
); |
|
|
|
NavHostFragment.findNavController(HashTagFragment.this).navigate(commentsAction); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onDownloadClick(final FeedModel feedModel) { |
|
|
|
final Context context = getContext(); |
|
|
|
if (context == null) return; |
|
|
|
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) { |
|
|
|
showDownloadDialog(feedModel); |
|
|
|
return; |
|
|
|
} |
|
|
|
finalList.addAll(result); |
|
|
|
postsViewModel.getList().postValue(finalList); |
|
|
|
PostModel model = null; |
|
|
|
if (!result.isEmpty()) { |
|
|
|
model = result.get(result.size() - 1); |
|
|
|
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onHashtagClick(final String hashtag) { |
|
|
|
final NavDirections action = FeedFragmentDirections.actionGlobalHashTagFragment(hashtag); |
|
|
|
NavHostFragment.findNavController(HashTagFragment.this).navigate(action); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onLocationClick(final FeedModel feedModel) { |
|
|
|
final NavDirections action = FeedFragmentDirections.actionGlobalLocationFragment(feedModel.getLocationId()); |
|
|
|
NavHostFragment.findNavController(HashTagFragment.this).navigate(action); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onMentionClick(final String mention) { |
|
|
|
navigateToProfile(mention.trim()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onNameClick(final FeedModel feedModel, final View profilePicView) { |
|
|
|
navigateToProfile("@" + feedModel.getProfileModel().getUsername()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onProfilePicClick(final FeedModel feedModel, final View profilePicView) { |
|
|
|
navigateToProfile("@" + feedModel.getProfileModel().getUsername()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onURLClick(final String url) { |
|
|
|
Utils.openURL(getContext(), url); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onEmailClick(final String emailId) { |
|
|
|
Utils.openEmailAddress(getContext(), emailId); |
|
|
|
} |
|
|
|
|
|
|
|
private void openPostDialog(final FeedModel feedModel, |
|
|
|
final View profilePicView, |
|
|
|
final View mainPostImage, |
|
|
|
final int position) { |
|
|
|
final PostViewV2Fragment.Builder builder = PostViewV2Fragment |
|
|
|
.builder(feedModel); |
|
|
|
if (position >= 0) { |
|
|
|
builder.setPosition(position); |
|
|
|
} |
|
|
|
if (model == null) return; |
|
|
|
endCursor = model.getEndCursor(); |
|
|
|
hasNextPage = model.hasNextPage(); |
|
|
|
model.setPageCursor(false, null); |
|
|
|
final PostViewV2Fragment fragment = builder |
|
|
|
.setSharedProfilePicElement(profilePicView) |
|
|
|
.setSharedMainPostElement(mainPostImage) |
|
|
|
.build(); |
|
|
|
fragment.show(getChildFragmentManager(), "post_view"); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
@ -159,6 +241,7 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe |
|
|
|
fragmentActivity = (MainActivity) requireActivity(); |
|
|
|
tagsService = TagsService.getInstance(); |
|
|
|
storiesService = StoriesService.getInstance(); |
|
|
|
setHasOptionsMenu(true); |
|
|
|
} |
|
|
|
|
|
|
|
@Nullable |
|
|
@ -183,9 +266,8 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefresh() { |
|
|
|
isPullToRefresh = true; |
|
|
|
endCursor = null; |
|
|
|
fetchHashtagModel(); |
|
|
|
binding.posts.refresh(); |
|
|
|
fetchStories(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -195,11 +277,17 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onDestroy() { |
|
|
|
super.onDestroy(); |
|
|
|
if (postsViewModel != null) { |
|
|
|
postsViewModel.getList().postValue(Collections.emptyList()); |
|
|
|
public void onCreateOptionsMenu(@NonNull final Menu menu, @NonNull final MenuInflater inflater) { |
|
|
|
inflater.inflate(R.menu.topic_posts_menu, menu); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean onOptionsItemSelected(@NonNull final MenuItem item) { |
|
|
|
if (item.getItemId() == R.id.layout) { |
|
|
|
showPostsLayoutPreferences(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
return super.onOptionsItemSelected(item); |
|
|
|
} |
|
|
|
|
|
|
|
private void init() { |
|
|
@ -208,114 +296,96 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe |
|
|
|
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != null; |
|
|
|
final HashTagFragmentArgs fragmentArgs = HashTagFragmentArgs.fromBundle(getArguments()); |
|
|
|
hashtag = fragmentArgs.getHashtag(); |
|
|
|
// setTitle(); |
|
|
|
setupPosts(); |
|
|
|
fetchHashtagModel(); |
|
|
|
} |
|
|
|
|
|
|
|
private void setupPosts() { |
|
|
|
postsViewModel = new ViewModelProvider(this).get(PostsViewModel.class); |
|
|
|
final Context context = getContext(); |
|
|
|
if (context == null) return; |
|
|
|
final GridAutofitLayoutManager layoutManager = new GridAutofitLayoutManager(context, Utils.convertDpToPx(110)); |
|
|
|
binding.mainPosts.setLayoutManager(layoutManager); |
|
|
|
binding.mainPosts.addItemDecoration(new GridSpacingItemDecoration(Utils.convertDpToPx(4))); |
|
|
|
postsAdapter = new PostsAdapter((postModel, position) -> { |
|
|
|
if (postsAdapter.isSelecting()) { |
|
|
|
if (actionMode == null) return; |
|
|
|
final String title = getString(R.string.number_selected, postsAdapter.getSelectedModels().size()); |
|
|
|
actionMode.setTitle(title); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (checkAndResetAction()) return; |
|
|
|
final List<PostModel> postModels = postsViewModel.getList().getValue(); |
|
|
|
if (postModels == null || postModels.size() == 0) return; |
|
|
|
if (postModels.get(0) == null) return; |
|
|
|
final String postId = postModels.get(0).getPostId(); |
|
|
|
final boolean isId = postId != null && isLoggedIn; |
|
|
|
final String[] idsOrShortCodes = new String[postModels.size()]; |
|
|
|
for (int i = 0; i < postModels.size(); i++) { |
|
|
|
idsOrShortCodes[i] = isId ? postModels.get(i).getPostId() |
|
|
|
: postModels.get(i).getShortCode(); |
|
|
|
} |
|
|
|
final NavDirections action = HashTagFragmentDirections.actionGlobalPostViewFragment( |
|
|
|
position, |
|
|
|
idsOrShortCodes, |
|
|
|
isId); |
|
|
|
NavHostFragment.findNavController(this).navigate(action); |
|
|
|
|
|
|
|
}, (model, position) -> { |
|
|
|
if (!postsAdapter.isSelecting()) { |
|
|
|
checkAndResetAction(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (onBackPressedCallback.isEnabled()) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
final OnBackPressedDispatcher onBackPressedDispatcher = fragmentActivity.getOnBackPressedDispatcher(); |
|
|
|
onBackPressedCallback.setEnabled(true); |
|
|
|
actionMode = fragmentActivity.startActionMode(multiSelectAction); |
|
|
|
final String title = getString(R.string.number_selected, 1); |
|
|
|
actionMode.setTitle(title); |
|
|
|
onBackPressedDispatcher.addCallback(getViewLifecycleOwner(), onBackPressedCallback); |
|
|
|
return true; |
|
|
|
}); |
|
|
|
postsViewModel.getList().observe(fragmentActivity, postsAdapter::submitList); |
|
|
|
binding.mainPosts.setAdapter(postsAdapter); |
|
|
|
final RecyclerLazyLoader lazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> { |
|
|
|
if (!hasNextPage || getContext() == null) return; |
|
|
|
binding.swipeRefreshLayout.setRefreshing(true); |
|
|
|
fetchPosts(); |
|
|
|
endCursor = null; |
|
|
|
}); |
|
|
|
binding.mainPosts.addOnScrollListener(lazyLoader); |
|
|
|
} |
|
|
|
|
|
|
|
private void fetchHashtagModel() { |
|
|
|
stopCurrentExecutor(); |
|
|
|
binding.swipeRefreshLayout.setRefreshing(true); |
|
|
|
currentlyExecuting = new HashtagFetcher(hashtag.substring(1), result -> { |
|
|
|
final Context context = getContext(); |
|
|
|
if (context == null) return; |
|
|
|
hashtagModel = result; |
|
|
|
binding.swipeRefreshLayout.setRefreshing(false); |
|
|
|
final Context context = getContext(); |
|
|
|
if (context == null) return; |
|
|
|
if (hashtagModel == null) { |
|
|
|
Toast.makeText(context, R.string.error_loading_profile, Toast.LENGTH_SHORT).show(); |
|
|
|
return; |
|
|
|
} |
|
|
|
setTitle(); |
|
|
|
fetchPosts(); |
|
|
|
setHashtagDetails(); |
|
|
|
setupPosts(); |
|
|
|
fetchStories(); |
|
|
|
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
|
|
|
} |
|
|
|
|
|
|
|
private void fetchPosts() { |
|
|
|
stopCurrentExecutor(); |
|
|
|
private void setupPosts() { |
|
|
|
binding.posts.setViewModelStoreOwner(this) |
|
|
|
.setLifeCycleOwner(this) |
|
|
|
.setPostFetchService(new HashtagPostFetchService(hashtagModel)) |
|
|
|
.setLayoutPreferences(PostsLayoutPreferences.fromJson(settingsHelper.getString(Constants.PREF_HASHTAG_POSTS_LAYOUT))) |
|
|
|
.addFetchStatusChangeListener(fetching -> updateSwipeRefreshState()) |
|
|
|
.setFeedItemCallback(feedItemCallback) |
|
|
|
.init(); |
|
|
|
binding.swipeRefreshLayout.setRefreshing(true); |
|
|
|
if (TextUtils.isEmpty(hashtag)) return; |
|
|
|
currentlyExecuting = new PostsFetcher(hashtag.substring(1), PostItemType.HASHTAG, endCursor, postsFetchListener) |
|
|
|
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
|
|
|
final Context context = getContext(); |
|
|
|
if (context == null) return; |
|
|
|
// postsViewModel = new ViewModelProvider(this).get(PostsViewModel.class); |
|
|
|
// final Context context = getContext(); |
|
|
|
// if (context == null) return; |
|
|
|
// final GridAutofitLayoutManager layoutManager = new GridAutofitLayoutManager(context, Utils.convertDpToPx(110)); |
|
|
|
// binding.mainPosts.setLayoutManager(layoutManager); |
|
|
|
// binding.mainPosts.addItemDecoration(new GridSpacingItemDecoration(Utils.convertDpToPx(4))); |
|
|
|
// postsAdapter = new PostsAdapter((postModel, position) -> { |
|
|
|
// if (postsAdapter.isSelecting()) { |
|
|
|
// if (actionMode == null) return; |
|
|
|
// final String title = getString(R.string.number_selected, postsAdapter.getSelectedModels().size()); |
|
|
|
// actionMode.setTitle(title); |
|
|
|
// return; |
|
|
|
// } |
|
|
|
// if (checkAndResetAction()) return; |
|
|
|
// final List<PostModel> postModels = postsViewModel.getList().getValue(); |
|
|
|
// if (postModels == null || postModels.size() == 0) return; |
|
|
|
// if (postModels.get(0) == null) return; |
|
|
|
// final String postId = postModels.get(0).getPostId(); |
|
|
|
// final boolean isId = postId != null && isLoggedIn; |
|
|
|
// final String[] idsOrShortCodes = new String[postModels.size()]; |
|
|
|
// for (int i = 0; i < postModels.size(); i++) { |
|
|
|
// idsOrShortCodes[i] = isId ? postModels.get(i).getPostId() |
|
|
|
// : postModels.get(i).getShortCode(); |
|
|
|
// } |
|
|
|
// final NavDirections action = HashTagFragmentDirections.actionGlobalPostViewFragment( |
|
|
|
// position, |
|
|
|
// idsOrShortCodes, |
|
|
|
// isId); |
|
|
|
// NavHostFragment.findNavController(this).navigate(action); |
|
|
|
// |
|
|
|
// }, (model, position) -> { |
|
|
|
// if (!postsAdapter.isSelecting()) { |
|
|
|
// checkAndResetAction(); |
|
|
|
// return true; |
|
|
|
// } |
|
|
|
// if (onBackPressedCallback.isEnabled()) { |
|
|
|
// return true; |
|
|
|
// } |
|
|
|
// final OnBackPressedDispatcher onBackPressedDispatcher = fragmentActivity.getOnBackPressedDispatcher(); |
|
|
|
// onBackPressedCallback.setEnabled(true); |
|
|
|
// actionMode = fragmentActivity.startActionMode(multiSelectAction); |
|
|
|
// final String title = getString(R.string.number_selected, 1); |
|
|
|
// actionMode.setTitle(title); |
|
|
|
// onBackPressedDispatcher.addCallback(getViewLifecycleOwner(), onBackPressedCallback); |
|
|
|
// return true; |
|
|
|
// }); |
|
|
|
// postsViewModel.getList().observe(fragmentActivity, postsAdapter::submitList); |
|
|
|
// binding.mainPosts.setAdapter(postsAdapter); |
|
|
|
// final RecyclerLazyLoader lazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> { |
|
|
|
// if (!hasNextPage || getContext() == null) return; |
|
|
|
// binding.swipeRefreshLayout.setRefreshing(true); |
|
|
|
// fetchPosts(); |
|
|
|
// endCursor = null; |
|
|
|
// }); |
|
|
|
// binding.mainPosts.addOnScrollListener(lazyLoader); |
|
|
|
} |
|
|
|
|
|
|
|
private void setHashtagDetails() { |
|
|
|
if (isLoggedIn) { |
|
|
|
storiesService.getUserStory(hashtagModel.getName(), |
|
|
|
null, |
|
|
|
false, |
|
|
|
true, |
|
|
|
false, |
|
|
|
new ServiceCallback<List<StoryModel>>() { |
|
|
|
@Override |
|
|
|
public void onSuccess(final List<StoryModel> storyModels) { |
|
|
|
if (storyModels != null && !storyModels.isEmpty()) { |
|
|
|
binding.mainHashtagImage.setStoriesBorder(); |
|
|
|
hasStories = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(final Throwable t) { |
|
|
|
Log.e(TAG, "Error", t); |
|
|
|
} |
|
|
|
}); |
|
|
|
binding.btnFollowTag.setVisibility(View.VISIBLE); |
|
|
|
binding.btnFollowTag.setText(hashtagModel.getFollowing() ? R.string.unfollow : R.string.follow); |
|
|
|
binding.btnFollowTag.setChipIconResource(hashtagModel.getFollowing() |
|
|
@ -422,15 +492,43 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe |
|
|
|
binding.mainTagPostCount.setText(span); |
|
|
|
binding.mainTagPostCount.setVisibility(View.VISIBLE); |
|
|
|
binding.mainHashtagImage.setOnClickListener(v -> { |
|
|
|
if (hasStories) { |
|
|
|
// show stories |
|
|
|
final NavDirections action = HashTagFragmentDirections |
|
|
|
.actionHashtagFragmentToStoryViewerFragment(-1, null, true, false, hashtagModel.getName(), hashtagModel.getName()); |
|
|
|
NavHostFragment.findNavController(this).navigate(action); |
|
|
|
} |
|
|
|
if (!hasStories) return; |
|
|
|
// show stories |
|
|
|
final NavDirections action = HashTagFragmentDirections |
|
|
|
.actionHashtagFragmentToStoryViewerFragment(-1, null, true, false, hashtagModel.getName(), hashtagModel.getName()); |
|
|
|
NavHostFragment.findNavController(this).navigate(action); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private void fetchStories() { |
|
|
|
if (!isLoggedIn) return; |
|
|
|
storiesFetching = true; |
|
|
|
storiesService.getUserStory( |
|
|
|
hashtagModel.getName(), |
|
|
|
null, |
|
|
|
false, |
|
|
|
true, |
|
|
|
false, |
|
|
|
new ServiceCallback<List<StoryModel>>() { |
|
|
|
@Override |
|
|
|
public void onSuccess(final List<StoryModel> storyModels) { |
|
|
|
if (storyModels != null && !storyModels.isEmpty()) { |
|
|
|
binding.mainHashtagImage.setStoriesBorder(); |
|
|
|
hasStories = true; |
|
|
|
} else { |
|
|
|
hasStories = false; |
|
|
|
} |
|
|
|
storiesFetching = false; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(final Throwable t) { |
|
|
|
Log.e(TAG, "Error", t); |
|
|
|
storiesFetching = false; |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public void stopCurrentExecutor() { |
|
|
|
if (currentlyExecuting != null) { |
|
|
|
try { |
|
|
@ -453,6 +551,59 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void updateSwipeRefreshState() { |
|
|
|
binding.swipeRefreshLayout.setRefreshing(binding.posts.isFetching() || storiesFetching); |
|
|
|
} |
|
|
|
|
|
|
|
private void showDownloadDialog(final FeedModel feedModel) { |
|
|
|
final Context context = getContext(); |
|
|
|
if (context == null) return; |
|
|
|
DownloadUtils.download(context, feedModel); |
|
|
|
// switch (feedModel.getItemType()) { |
|
|
|
// case MEDIA_TYPE_IMAGE: |
|
|
|
// case MEDIA_TYPE_VIDEO: |
|
|
|
// break; |
|
|
|
// case MEDIA_TYPE_SLIDER: |
|
|
|
// break; |
|
|
|
// } |
|
|
|
// final List<ViewerPostModel> postModelsToDownload = new ArrayList<>(); |
|
|
|
// // if (!session) { |
|
|
|
// final DialogInterface.OnClickListener clickListener = (dialog, which) -> { |
|
|
|
// if (which == DialogInterface.BUTTON_NEGATIVE) { |
|
|
|
// postModelsToDownload.addAll(postModels); |
|
|
|
// } else if (which == DialogInterface.BUTTON_POSITIVE) { |
|
|
|
// postModelsToDownload.add(postModels.get(childPosition)); |
|
|
|
// } else { |
|
|
|
// session = true; |
|
|
|
// postModelsToDownload.add(postModels.get(childPosition)); |
|
|
|
// } |
|
|
|
// if (postModelsToDownload.size() > 0) { |
|
|
|
// DownloadUtils.batchDownload(context, |
|
|
|
// username, |
|
|
|
// DownloadMethod.DOWNLOAD_POST_VIEWER, |
|
|
|
// postModelsToDownload); |
|
|
|
// } |
|
|
|
// }; |
|
|
|
// new AlertDialog.Builder(context) |
|
|
|
// .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 { |
|
|
|
// DownloadUtils.batchDownload(context, |
|
|
|
// username, |
|
|
|
// DownloadMethod.DOWNLOAD_POST_VIEWER, |
|
|
|
// Collections.singletonList(postModels.get(childPosition))); |
|
|
|
} |
|
|
|
|
|
|
|
private void navigateToProfile(final String username) { |
|
|
|
final NavController navController = NavHostFragment.findNavController(this); |
|
|
|
final Bundle bundle = new Bundle(); |
|
|
|
bundle.putString("username", username); |
|
|
|
navController.navigate(R.id.action_global_profileFragment, bundle); |
|
|
|
} |
|
|
|
|
|
|
|
private boolean checkAndResetAction() { |
|
|
|
if (!onBackPressedCallback.isEnabled() && actionMode == null) { |
|
|
|
return false; |
|
|
@ -467,4 +618,11 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private void showPostsLayoutPreferences() { |
|
|
|
final PostsLayoutPreferencesDialogFragment fragment = new PostsLayoutPreferencesDialogFragment( |
|
|
|
Constants.PREF_HASHTAG_POSTS_LAYOUT, |
|
|
|
preferences -> new Handler().postDelayed(() -> binding.posts.setLayoutPreferences(preferences), 200)); |
|
|
|
fragment.show(getChildFragmentManager(), "posts_layout_preferences"); |
|
|
|
} |
|
|
|
} |