1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-12-23 13:26:59 +00:00

Convert follower activity to fragment

This commit is contained in:
Ammar Githam 2020-09-05 03:19:06 +09:00
parent c64ae3a101
commit 290ed50287
10 changed files with 460 additions and 400 deletions

View File

@ -159,14 +159,14 @@
<!-- android:value=".activities.MainActivity" />-->
<!--</activity>-->
<activity
android:name=".activities.FollowViewer"
android:parentActivityName=".activities.MainActivity">
<!--<activity-->
<!-- android:name=".activities.FollowViewerFragment"-->
<!-- android:parentActivityName=".activities.MainActivity">-->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.MainActivity" />
</activity>
<!-- <meta-data-->
<!-- android:name="android.support.PARENT_ACTIVITY"-->
<!-- android:value=".activities.MainActivity" />-->
<!--</activity>-->
<activity
android:name=".activities.ProfilePicViewer"

View File

@ -50,10 +50,8 @@ import java.util.HashMap;
import java.util.Map;
import awais.instagrabber.activities.CommentsViewerFragment;
import awais.instagrabber.activities.FollowViewer;
import awais.instagrabber.activities.MainActivityBackup;
import awais.instagrabber.activities.PostViewer;
import awais.instagrabber.fragments.SavedViewerFragment;
import awais.instagrabber.adapters.DiscoverAdapter;
import awais.instagrabber.adapters.FeedAdapter;
import awais.instagrabber.adapters.PostsAdapter;
@ -75,6 +73,7 @@ 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;
@ -1151,16 +1150,16 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener {
mainActivity.mainBinding.profileView.mainFollowers.setClickable(true);
if (isLoggedIn) {
final View.OnClickListener followClickListener = v -> 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) {

View File

@ -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<FollowModel> followModels = new ArrayList<>();
private final ArrayList<FollowModel> followingModels = new ArrayList<>();
private final ArrayList<FollowModel> followersModels = new ArrayList<>();
private final ArrayList<FollowModel> 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<Void, Void, FollowModel[]> 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<FollowModel[]> fetchListener = new FetchListener<FollowModel[]>() {
@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<FollowModel[]> followingFetchListener = new FetchListener<FollowModel[]>() {
@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<FollowModel[]> followersFetchListener = new FetchListener<FollowModel[]>() {
@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<FollowModel> searchFollowModels = new ArrayList<>(followModels.size() / 2);
// private final ArrayList<FollowModel> searchFollowingModels = new ArrayList<>(followingModels.size() / 2);
// private final ArrayList<FollowModel> searchFollowersModels = new ArrayList<>(followersModels.size() / 2);
// private final ArrayList<FollowModel> 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<FollowModel> followModels, final ArrayList<FollowModel> followingModels,
final ArrayList<FollowModel> followersModels, final ArrayList<FollowModel> allFollowing) {
final ArrayList<ExpandableGroup> 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);
}
}
}
}

View File

@ -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<FollowModel> followModels = new ArrayList<>();
private final ArrayList<FollowModel> followingModels = new ArrayList<>();
private final ArrayList<FollowModel> followersModels = new ArrayList<>();
private final ArrayList<FollowModel> 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<Void, Void, FollowModel[]> 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<FollowModel[]> fetchListener = new FetchListener<FollowModel[]>() {
@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<FollowModel[]> followingFetchListener = new FetchListener<FollowModel[]>() {
@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<FollowModel[]> followersFetchListener = new FetchListener<FollowModel[]>() {
@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<FollowModel> searchFollowModels = new ArrayList<>(followModels.size() / 2);
// private final ArrayList<FollowModel> searchFollowingModels = new ArrayList<>(followingModels.size() / 2);
// private final ArrayList<FollowModel> searchFollowersModels = new ArrayList<>(followersModels.size() / 2);
// private final ArrayList<FollowModel> 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<FollowModel> followModels,
final ArrayList<FollowModel> followingModels,
final ArrayList<FollowModel> followersModels,
final ArrayList<FollowModel> allFollowing) {
final ArrayList<ExpandableGroup> 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);
}
}
}
}
}

View File

@ -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<Integer> REMOVE_COLLAPSING_TOOLBAR_SCROLL_DESTINATIONS = Collections.singletonList(R.id.commentsViewerFragment);
private ActivityMainBinding binding;
private LiveData<NavController> currentNavControllerLiveData;

View File

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

View File

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

View File

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activities.FollowViewer">
<include
android:id="@+id/toolbar"
layout="@layout/layout_include_toolbar" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvFollow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingStart="8dp"
android:paddingLeft="8dp"
android:paddingEnd="8dp"
android:paddingRight="8dp"
app:layoutManager="LinearLayoutManager"
tools:listitem="@layout/item_follow" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.FollowViewerFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvFollow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingStart="8dp"
android:paddingLeft="8dp"
android:paddingEnd="8dp"
android:paddingRight="8dp"
app:layoutManager="LinearLayoutManager"
tools:listitem="@layout/item_follow" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

View File

@ -57,6 +57,9 @@
<action
android:id="@+id/action_profileFragment_to_savedViewerFragment"
app:destination="@id/savedViewerFragment" />
<action
android:id="@+id/action_profileFragment_to_followViewerFragment"
app:destination="@id/followViewerFragment" />
</fragment>
<fragment
android:id="@+id/savedViewerFragment"
@ -76,4 +79,31 @@
app:argType="awais.instagrabber.models.enums.PostItemType"
app:nullable="false" />
</fragment>
<fragment
android:id="@+id/followViewerFragment"
android:name="awais.instagrabber.activities.FollowViewerFragment"
android:label="Followers"
tools:layout="@layout/fragment_followers_viewer">
<argument
android:name="profileId"
app:argType="string"
app:nullable="false" />
<argument
android:name="isFollowersList"
app:argType="boolean"
app:nullable="false" />
<argument
android:name="username"
app:argType="string"
app:nullable="false" />
<action
android:id="@+id/action_followViewerFragment_to_profileFragment"
app:destination="@id/profileFragment">
<argument
android:name="username"
android:defaultValue=""
app:argType="string"
app:nullable="true" />
</action>
</fragment>
</navigation>