From 290ed502871437dff427759d1e7812a25e4d61e9 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sat, 5 Sep 2020 03:19:06 +0900 Subject: [PATCH] Convert follower activity to fragment --- app/src/main/AndroidManifest.xml | 14 +- .../java/awais/instagrabber/MainHelper.java | 23 +- .../instagrabber/activities/FollowViewer.java | 333 ---------------- .../activities/FollowViewerFragment.java | 371 ++++++++++++++++++ .../instagrabber/activities/MainActivity.java | 3 +- .../activities/ProfileViewer.java | 17 +- .../fragments/main/ProfileFragment.java | 17 +- app/src/main/res/layout/activity_follow.xml | 31 -- .../res/layout/fragment_followers_viewer.xml | 21 + .../main/res/navigation/profile_nav_graph.xml | 30 ++ 10 files changed, 460 insertions(+), 400 deletions(-) delete mode 100755 app/src/main/java/awais/instagrabber/activities/FollowViewer.java create mode 100644 app/src/main/java/awais/instagrabber/activities/FollowViewerFragment.java delete mode 100755 app/src/main/res/layout/activity_follow.xml create mode 100644 app/src/main/res/layout/fragment_followers_viewer.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 566e46ed..c4838e6d 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -159,14 +159,14 @@ - + + + - - + + + + mainActivity.startActivity(new Intent(mainActivity, FollowViewer.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); + // 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) { diff --git a/app/src/main/java/awais/instagrabber/activities/FollowViewer.java b/app/src/main/java/awais/instagrabber/activities/FollowViewer.java deleted file mode 100755 index 95491188..00000000 --- a/app/src/main/java/awais/instagrabber/activities/FollowViewer.java +++ /dev/null @@ -1,333 +0,0 @@ -package awais.instagrabber.activities; - -import android.content.Intent; -import android.content.res.Resources; -import android.os.AsyncTask; -import android.os.Bundle; -import android.util.Log; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; - -import androidx.annotation.Nullable; -import androidx.appcompat.widget.SearchView; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; - -import java.util.ArrayList; -import java.util.Arrays; - -import awais.instagrabber.BuildConfig; -import awais.instagrabber.R; -import awais.instagrabber.adapters.FollowAdapter; -import awais.instagrabber.asyncs.FollowFetcher; -import awais.instagrabber.databinding.ActivityFollowBinding; -import awais.instagrabber.interfaces.FetchListener; -import awais.instagrabber.models.FollowModel; -import awais.instagrabber.utils.Constants; -import awais.instagrabber.utils.Utils; -import awaisomereport.LogCollector; -import thoughtbot.expandableadapter.ExpandableGroup; - -import static awais.instagrabber.utils.Utils.logCollector; - -public final class FollowViewer extends BaseLanguageActivity implements SwipeRefreshLayout.OnRefreshListener { - private final ArrayList followModels = new ArrayList<>(); - private final ArrayList followingModels = new ArrayList<>(); - private final ArrayList followersModels = new ArrayList<>(); - private final ArrayList allFollowing = new ArrayList<>(); - private boolean followers, isCompare = false; - private String id, name, namePost, type; - private Resources resources; - private FollowModel model; - private FollowAdapter adapter; - private View.OnClickListener clickListener; - private ActivityFollowBinding followBinding; - private AsyncTask currentlyExecuting; - - @Override - protected void onCreate(@Nullable final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - followBinding = ActivityFollowBinding.inflate(getLayoutInflater()); - setContentView(followBinding.getRoot()); - - final Intent intent = getIntent(); - if (intent == null || Utils.isEmpty(id = intent.getStringExtra(Constants.EXTRAS_ID))) { - Utils.errorFinish(this); - return; - } - - setSupportActionBar(followBinding.toolbar.toolbar); - - followers = intent.getBooleanExtra(Constants.EXTRAS_FOLLOWERS, false); - name = intent.getStringExtra(Constants.EXTRAS_NAME); - namePost = name; - if (Utils.isEmpty(name)) { - // this usually should not occur - name = "You"; - namePost = "You're"; - } - - followBinding.toolbar.toolbar.setTitle(name); - - resources = getResources(); - - clickListener = v -> { - final Object tag = v.getTag(); - if (tag instanceof FollowModel) { - model = (FollowModel) tag; - startActivity( - new Intent(getApplicationContext(), ProfileViewer.class) - .putExtra(Constants.EXTRAS_USERNAME, model.getUsername()) - ); - } - }; - - followBinding.swipeRefreshLayout.setOnRefreshListener(this); - - onRefresh(); - } - - @Override - public void onRefresh() { - if (isCompare) listCompare(); - else listFollows(); - } - - private void listFollows() { - stopCurrentExecutor(); - - type = resources.getString(followers ? R.string.followers_type_followers : R.string.followers_type_following); - followBinding.toolbar.toolbar.setSubtitle(type); - - followModels.clear(); - - final FetchListener fetchListener = new FetchListener() { - @Override - public void doBefore() { - followBinding.swipeRefreshLayout.setRefreshing(true); - } - - @Override - public void onResult(final FollowModel[] result) { - if (result == null) followBinding.swipeRefreshLayout.setRefreshing(false); - else { - followModels.addAll(Arrays.asList(result)); - - final FollowModel model = result[result.length - 1]; - if (model != null && model.hasNextPage()) { - stopCurrentExecutor(); - currentlyExecuting = new FollowFetcher(id, followers, model.getEndCursor(), this) - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - model.setPageCursor(false, null); - } else { - followBinding.swipeRefreshLayout.setRefreshing(false); - - refreshAdapter(followModels, null, null, null); - } - } - } - }; - - currentlyExecuting = new FollowFetcher(id, followers, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - private void listCompare() { - stopCurrentExecutor(); - - followBinding.toolbar.toolbar.setSubtitle(R.string.followers_compare); - - allFollowing.clear(); - followersModels.clear(); - followingModels.clear(); - - final FetchListener followingFetchListener = new FetchListener() { - @Override - public void onResult(final FollowModel[] result) { - if (result != null) { - followingModels.addAll(Arrays.asList(result)); - - final FollowModel model = result[result.length - 1]; - if (model != null && model.hasNextPage()) { - stopCurrentExecutor(); - currentlyExecuting = new FollowFetcher(id, false, model.getEndCursor(), this) - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - model.setPageCursor(false, null); - } else { - allFollowing.addAll(followersModels); - allFollowing.retainAll(followingModels); - - for (final FollowModel followModel : allFollowing) { - followersModels.remove(followModel); - followingModels.remove(followModel); - } - - allFollowing.trimToSize(); - followersModels.trimToSize(); - followingModels.trimToSize(); - - followBinding.swipeRefreshLayout.setRefreshing(false); - - refreshAdapter(null, followingModels, followersModels, allFollowing); - } - } else followBinding.swipeRefreshLayout.setRefreshing(false); - } - }; - final FetchListener followersFetchListener = new FetchListener() { - @Override - public void doBefore() { - followBinding.swipeRefreshLayout.setRefreshing(true); - } - - @Override - public void onResult(final FollowModel[] result) { - if (result != null) { - followersModels.addAll(Arrays.asList(result)); - final FollowModel model = result[result.length - 1]; - if (model == null || !model.hasNextPage()) { - stopCurrentExecutor(); - currentlyExecuting = new FollowFetcher(id, false, followingFetchListener) - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else { - stopCurrentExecutor(); - currentlyExecuting = new FollowFetcher(id, true, model.getEndCursor(), this) - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - model.setPageCursor(false, null); - } - } - } - }; - - currentlyExecuting = new FollowFetcher(id, true, followersFetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - @Override - public boolean onCreateOptionsMenu(final Menu menu) { - getMenuInflater().inflate(R.menu.follow, menu); - - final MenuItem menuSearch = menu.findItem(R.id.action_search); - - final SearchView searchView = (SearchView) menuSearch.getActionView(); - searchView.setQueryHint(getResources().getString(R.string.action_search)); - searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { -// private final Filter filter = new Filter() { -// private final ArrayList searchFollowModels = new ArrayList<>(followModels.size() / 2); -// private final ArrayList searchFollowingModels = new ArrayList<>(followingModels.size() / 2); -// private final ArrayList searchFollowersModels = new ArrayList<>(followersModels.size() / 2); -// private final ArrayList searchAllFollowing = new ArrayList<>(allFollowing.size() / 2); -// -// @Nullable -// @Override -// protected FilterResults performFiltering(@NonNull final CharSequence constraint) { -// searchFollowModels.clear(); -// searchFollowingModels.clear(); -// searchFollowersModels.clear(); -// searchAllFollowing.clear(); -// -// final int followModelsSize = followModels.size(); -// final int followingModelsSize = followingModels.size(); -// final int followersModelsSize = followersModels.size(); -// final int allFollowingSize = allFollowing.size(); -// -// int maxSize = followModelsSize; -// if (maxSize < followingModelsSize) maxSize = followingModelsSize; -// if (maxSize < followersModelsSize) maxSize = followersModelsSize; -// if (maxSize < allFollowingSize) maxSize = allFollowingSize; -// -// final String query = constraint.toString().toLowerCase(); -// FollowModel followModel; -// while (maxSize != -1) { -// if (maxSize < followModelsSize) { -// followModel = followModels.get(maxSize); -// if (Utils.hasKey(query, followModel.getUsername(), followModel.getFullName())) -// searchFollowModels.add(followModel); -// } -// -// if (maxSize < followingModelsSize) { -// followModel = followingModels.get(maxSize); -// if (Utils.hasKey(query, followModel.getUsername(), followModel.getFullName())) -// searchFollowingModels.add(followModel); -// } -// -// if (maxSize < followersModelsSize) { -// followModel = followersModels.get(maxSize); -// if (Utils.hasKey(query, followModel.getUsername(), followModel.getFullName())) -// searchFollowersModels.add(followModel); -// } -// -// if (maxSize < allFollowingSize) { -// followModel = allFollowing.get(maxSize); -// if (Utils.hasKey(query, followModel.getUsername(), followModel.getFullName())) -// searchAllFollowing.add(followModel); -// } -// -// --maxSize; -// } -// -// return null; -// } -// -// @Override -// protected void publishResults(final CharSequence query, final FilterResults results) { -// refreshAdapter(searchFollowModels, searchFollowingModels, searchFollowersModels, searchAllFollowing); -// } -// }; - - @Override - public boolean onQueryTextSubmit(final String query) { - return false; - } - - @Override - public boolean onQueryTextChange(final String query) { -// if (Utils.isEmpty(query)) refreshAdapter(followModels, followingModels, followersModels, allFollowing); -// else filter.filter(query.toLowerCase()); - if (adapter != null) adapter.getFilter().filter(query); - return true; - } - }); - - final MenuItem menuCompare = menu.findItem(R.id.action_compare); - menuCompare.setOnMenuItemClickListener(item -> { - followBinding.rvFollow.setAdapter(null); - if (isCompare) listFollows(); - else listCompare(); - isCompare = !isCompare; - return true; - }); - - return true; - } - - private void refreshAdapter(final ArrayList followModels, final ArrayList followingModels, - final ArrayList followersModels, final ArrayList allFollowing) { - final ArrayList groups = new ArrayList<>(1); - - if (isCompare) { - if (followingModels != null && followingModels.size() > 0) - groups.add(new ExpandableGroup(resources.getString(R.string.followers_not_following, name), followingModels)); - if (followersModels != null && followersModels.size() > 0) - groups.add(new ExpandableGroup(resources.getString(R.string.followers_not_follower, namePost), followersModels)); - if (allFollowing != null && allFollowing.size() > 0) - groups.add(new ExpandableGroup(resources.getString(R.string.followers_both_following), allFollowing)); - } else { - final ExpandableGroup group = new ExpandableGroup(type, followModels); - groups.add(group); - } - - adapter = new FollowAdapter(this, clickListener, groups); - adapter.toggleGroup(0); - followBinding.rvFollow.setAdapter(adapter); - } - - public 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); - } - } - } -} \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/activities/FollowViewerFragment.java b/app/src/main/java/awais/instagrabber/activities/FollowViewerFragment.java new file mode 100644 index 00000000..14751a00 --- /dev/null +++ b/app/src/main/java/awais/instagrabber/activities/FollowViewerFragment.java @@ -0,0 +1,371 @@ +package awais.instagrabber.activities; + +import android.content.res.Resources; +import android.os.AsyncTask; +import android.os.Bundle; +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; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.SearchView; +import androidx.fragment.app.Fragment; +import androidx.navigation.fragment.NavHostFragment; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; + +import java.util.ArrayList; +import java.util.Arrays; + +import awais.instagrabber.BuildConfig; +import awais.instagrabber.R; +import awais.instagrabber.adapters.FollowAdapter; +import awais.instagrabber.asyncs.FollowFetcher; +import awais.instagrabber.databinding.FragmentFollowersViewerBinding; +import awais.instagrabber.interfaces.FetchListener; +import awais.instagrabber.models.FollowModel; +import awais.instagrabber.utils.Utils; +import awaisomereport.LogCollector; +import thoughtbot.expandableadapter.ExpandableGroup; + +import static awais.instagrabber.utils.Utils.logCollector; + +public final class FollowViewerFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener { + private static final String TAG = "FollowViewerFragment"; + + private final ArrayList followModels = new ArrayList<>(); + private final ArrayList followingModels = new ArrayList<>(); + private final ArrayList followersModels = new ArrayList<>(); + private final ArrayList allFollowing = new ArrayList<>(); + + private boolean isFollowersList, isCompare = false; + private String profileId, username, namePost, type; + private Resources resources; + private FollowModel model; + private FollowAdapter adapter; + private View.OnClickListener clickListener; + private FragmentFollowersViewerBinding binding; + private AsyncTask currentlyExecuting; + private SwipeRefreshLayout root; + private boolean shouldRefresh = true; + private AppCompatActivity fragmentActivity; + + @Override + public void onCreate(@Nullable final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + fragmentActivity = (AppCompatActivity) getActivity(); + setHasOptionsMenu(true); + } + + @NonNull + @Override + public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { + if (root != null) { + shouldRefresh = false; + return root; + } + binding = FragmentFollowersViewerBinding.inflate(getLayoutInflater()); + 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() { + if (getArguments() == null) return; + final FollowViewerFragmentArgs fragmentArgs = FollowViewerFragmentArgs.fromBundle(getArguments()); + profileId = fragmentArgs.getProfileId(); + isFollowersList = fragmentArgs.getIsFollowersList(); + username = fragmentArgs.getUsername(); + namePost = username; + if (Utils.isEmpty(username)) { + // this usually should not occur + username = "You"; + namePost = "You're"; + } + setTitle(username); + resources = getResources(); + clickListener = v -> { + final Object tag = v.getTag(); + if (tag instanceof FollowModel) { + model = (FollowModel) tag; + final FollowViewerFragmentDirections.ActionFollowViewerFragmentToProfileFragment action = FollowViewerFragmentDirections + .actionFollowViewerFragmentToProfileFragment(); + action.setUsername("@" + model.getUsername()); + NavHostFragment.findNavController(this).navigate(action); + } + }; + binding.swipeRefreshLayout.setOnRefreshListener(this); + onRefresh(); + } + + private void setTitle(final String title) { + final ActionBar actionBar = fragmentActivity.getSupportActionBar(); + if (actionBar == null) return; + actionBar.setTitle(title); + } + + private void setSubtitle(final String subtitle) { + final ActionBar actionBar = fragmentActivity.getSupportActionBar(); + if (actionBar == null) return; + actionBar.setSubtitle(subtitle); + } + + private void setSubtitle(@SuppressWarnings("SameParameterValue") final int subtitleRes) { + final ActionBar actionBar = fragmentActivity.getSupportActionBar(); + if (actionBar == null) return; + actionBar.setSubtitle(subtitleRes); + } + + @Override + public void onRefresh() { + if (isCompare) listCompare(); + else listFollows(); + } + + private void listFollows() { + stopCurrentExecutor(); + type = resources.getString(isFollowersList ? R.string.followers_type_followers : R.string.followers_type_following); + setSubtitle(type); + followModels.clear(); + final FetchListener fetchListener = new FetchListener() { + @Override + public void doBefore() { + binding.swipeRefreshLayout.setRefreshing(true); + } + + @Override + public void onResult(final FollowModel[] result) { + if (result == null) binding.swipeRefreshLayout.setRefreshing(false); + else { + followModels.addAll(Arrays.asList(result)); + + final FollowModel model = result[result.length - 1]; + if (model != null && model.hasNextPage()) { + stopCurrentExecutor(); + currentlyExecuting = new FollowFetcher(profileId, isFollowersList, model.getEndCursor(), this) + .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + model.setPageCursor(false, null); + } else { + binding.swipeRefreshLayout.setRefreshing(false); + + refreshAdapter(followModels, null, null, null); + } + } + } + }; + currentlyExecuting = new FollowFetcher(profileId, isFollowersList, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + + private void listCompare() { + stopCurrentExecutor(); + setSubtitle(R.string.followers_compare); + allFollowing.clear(); + followersModels.clear(); + followingModels.clear(); + final FetchListener followingFetchListener = new FetchListener() { + @Override + public void onResult(final FollowModel[] result) { + if (result != null) { + followingModels.addAll(Arrays.asList(result)); + + final FollowModel model = result[result.length - 1]; + if (model != null && model.hasNextPage()) { + stopCurrentExecutor(); + currentlyExecuting = new FollowFetcher(profileId, false, model.getEndCursor(), this) + .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + model.setPageCursor(false, null); + } else { + allFollowing.addAll(followersModels); + allFollowing.retainAll(followingModels); + + for (final FollowModel followModel : allFollowing) { + followersModels.remove(followModel); + followingModels.remove(followModel); + } + + allFollowing.trimToSize(); + followersModels.trimToSize(); + followingModels.trimToSize(); + + binding.swipeRefreshLayout.setRefreshing(false); + + refreshAdapter(null, followingModels, followersModels, allFollowing); + } + } else binding.swipeRefreshLayout.setRefreshing(false); + } + }; + final FetchListener followersFetchListener = new FetchListener() { + @Override + public void doBefore() { + binding.swipeRefreshLayout.setRefreshing(true); + } + + @Override + public void onResult(final FollowModel[] result) { + if (result != null) { + followersModels.addAll(Arrays.asList(result)); + final FollowModel model = result[result.length - 1]; + if (model == null || !model.hasNextPage()) { + stopCurrentExecutor(); + currentlyExecuting = new FollowFetcher(profileId, false, followingFetchListener) + .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } else { + stopCurrentExecutor(); + currentlyExecuting = new FollowFetcher(profileId, true, model.getEndCursor(), this) + .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + model.setPageCursor(false, null); + } + } + } + }; + currentlyExecuting = new FollowFetcher(profileId, true, followersFetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + + @Override + public void onCreateOptionsMenu(@NonNull final Menu menu, final MenuInflater inflater) { + inflater.inflate(R.menu.follow, menu); + final MenuItem favItem = menu.findItem(R.id.favourites); + if (favItem != null) { + favItem.setVisible(false); + } + final MenuItem menuSearch = menu.findItem(R.id.action_search); + final SearchView searchView = (SearchView) menuSearch.getActionView(); + searchView.setQueryHint(getResources().getString(R.string.action_search)); + searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + // private final Filter filter = new Filter() { + // private final ArrayList searchFollowModels = new ArrayList<>(followModels.size() / 2); + // private final ArrayList searchFollowingModels = new ArrayList<>(followingModels.size() / 2); + // private final ArrayList searchFollowersModels = new ArrayList<>(followersModels.size() / 2); + // private final ArrayList searchAllFollowing = new ArrayList<>(allFollowing.size() / 2); + // + // @Nullable + // @Override + // protected FilterResults performFiltering(@NonNull final CharSequence constraint) { + // searchFollowModels.clear(); + // searchFollowingModels.clear(); + // searchFollowersModels.clear(); + // searchAllFollowing.clear(); + // + // final int followModelsSize = followModels.size(); + // final int followingModelsSize = followingModels.size(); + // final int followersModelsSize = followersModels.size(); + // final int allFollowingSize = allFollowing.size(); + // + // int maxSize = followModelsSize; + // if (maxSize < followingModelsSize) maxSize = followingModelsSize; + // if (maxSize < followersModelsSize) maxSize = followersModelsSize; + // if (maxSize < allFollowingSize) maxSize = allFollowingSize; + // + // final String query = constraint.toString().toLowerCase(); + // FollowModel followModel; + // while (maxSize != -1) { + // if (maxSize < followModelsSize) { + // followModel = followModels.get(maxSize); + // if (Utils.hasKey(query, followModel.getUsername(), followModel.getFullName())) + // searchFollowModels.add(followModel); + // } + // + // if (maxSize < followingModelsSize) { + // followModel = followingModels.get(maxSize); + // if (Utils.hasKey(query, followModel.getUsername(), followModel.getFullName())) + // searchFollowingModels.add(followModel); + // } + // + // if (maxSize < followersModelsSize) { + // followModel = followersModels.get(maxSize); + // if (Utils.hasKey(query, followModel.getUsername(), followModel.getFullName())) + // searchFollowersModels.add(followModel); + // } + // + // if (maxSize < allFollowingSize) { + // followModel = allFollowing.get(maxSize); + // if (Utils.hasKey(query, followModel.getUsername(), followModel.getFullName())) + // searchAllFollowing.add(followModel); + // } + // + // --maxSize; + // } + // + // return null; + // } + // + // @Override + // protected void publishResults(final CharSequence query, final FilterResults results) { + // refreshAdapter(searchFollowModels, searchFollowingModels, searchFollowersModels, searchAllFollowing); + // } + // }; + + @Override + public boolean onQueryTextSubmit(final String query) { + return false; + } + + @Override + public boolean onQueryTextChange(final String query) { + // if (Utils.isEmpty(query)) refreshAdapter(followModels, followingModels, followersModels, allFollowing); + // else filter.filter(query.toLowerCase()); + if (adapter != null) adapter.getFilter().filter(query); + return true; + } + }); + } + + @Override + public boolean onOptionsItemSelected(@NonNull final MenuItem item) { + if (item.getItemId() != R.id.action_compare) return super.onOptionsItemSelected(item); + binding.rvFollow.setAdapter(null); + if (isCompare) listFollows(); + else listCompare(); + isCompare = !isCompare; + return true; + } + + private void refreshAdapter(final ArrayList followModels, + final ArrayList followingModels, + final ArrayList followersModels, + final ArrayList allFollowing) { + final ArrayList groups = new ArrayList<>(1); + + if (isCompare) { + if (followingModels != null && followingModels.size() > 0) + groups.add(new ExpandableGroup(resources.getString(R.string.followers_not_following, username), followingModels)); + if (followersModels != null && followersModels.size() > 0) + groups.add(new ExpandableGroup(resources.getString(R.string.followers_not_follower, namePost), followersModels)); + if (allFollowing != null && allFollowing.size() > 0) + groups.add(new ExpandableGroup(resources.getString(R.string.followers_both_following), allFollowing)); + } else { + final ExpandableGroup group = new ExpandableGroup(type, followModels); + groups.add(group); + } + + adapter = new FollowAdapter(requireContext(), clickListener, groups); + adapter.toggleGroup(0); + binding.rvFollow.setAdapter(adapter); + } + + public 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(TAG, "", e); + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/activities/MainActivity.java b/app/src/main/java/awais/instagrabber/activities/MainActivity.java index 2aa6b32b..59d19395 100644 --- a/app/src/main/java/awais/instagrabber/activities/MainActivity.java +++ b/app/src/main/java/awais/instagrabber/activities/MainActivity.java @@ -49,7 +49,8 @@ public class MainActivity extends BaseLanguageActivity { R.id.hashTagFragment, R.id.locationFragment, R.id.savedViewerFragment, - R.id.commentsViewerFragment); + R.id.commentsViewerFragment, + R.id.followViewerFragment); 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/ProfileViewer.java b/app/src/main/java/awais/instagrabber/activities/ProfileViewer.java index 30177311..51d0ef5c 100755 --- a/app/src/main/java/awais/instagrabber/activities/ProfileViewer.java +++ b/app/src/main/java/awais/instagrabber/activities/ProfileViewer.java @@ -600,15 +600,14 @@ public final class ProfileViewer extends BaseLanguageActivity implements SwipeRe profileBinding.profileView.mainFollowers.setClickable(true); if (isLoggedIn) { - final View.OnClickListener followClickListener = v -> startActivity(new Intent(ProfileViewer.this, FollowViewer.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); + // 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) { 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 5ab38b63..1e4ff6eb 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -1,6 +1,5 @@ package awais.instagrabber.fragments.main; -import android.content.Intent; import android.content.res.ColorStateList; import android.graphics.Typeface; import android.os.AsyncTask; @@ -39,7 +38,6 @@ import java.util.List; import awais.instagrabber.ProfileNavGraphDirections; import awais.instagrabber.R; -import awais.instagrabber.activities.FollowViewer; import awais.instagrabber.activities.MainActivity; import awais.instagrabber.adapters.PostsAdapter; import awais.instagrabber.asyncs.HighlightsFetcher; @@ -456,11 +454,16 @@ public class ProfileFragment extends Fragment { binding.mainFollowers.setClickable(true); if (isLoggedIn) { - final View.OnClickListener followClickListener = v -> startActivity( - new Intent(requireContext(), FollowViewer.class) - .putExtra(Constants.EXTRAS_FOLLOWERS, v == binding.mainFollowers) - .putExtra(Constants.EXTRAS_NAME, profileModel.getUsername()) - .putExtra(Constants.EXTRAS_ID, profileId)); + 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()); + NavHostFragment.findNavController(this).navigate(action); + }; binding.mainFollowers.setOnClickListener(followersCount > 0 ? followClickListener : null); binding.mainFollowing.setOnClickListener(followingCount > 0 ? followClickListener : null); diff --git a/app/src/main/res/layout/activity_follow.xml b/app/src/main/res/layout/activity_follow.xml deleted file mode 100755 index 69c3f72f..00000000 --- a/app/src/main/res/layout/activity_follow.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_followers_viewer.xml b/app/src/main/res/layout/fragment_followers_viewer.xml new file mode 100644 index 00000000..f87d1d0c --- /dev/null +++ b/app/src/main/res/layout/fragment_followers_viewer.xml @@ -0,0 +1,21 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/navigation/profile_nav_graph.xml b/app/src/main/res/navigation/profile_nav_graph.xml index e7b998ee..b73a80fc 100644 --- a/app/src/main/res/navigation/profile_nav_graph.xml +++ b/app/src/main/res/navigation/profile_nav_graph.xml @@ -57,6 +57,9 @@ + + + + + + + + + \ No newline at end of file