mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-16 19:57:31 +00:00
close #808
This commit is contained in:
parent
e6961fcee6
commit
7f4196e119
@ -2,23 +2,46 @@ package awais.instagrabber.adapters;
|
|||||||
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Filter;
|
||||||
|
import android.widget.Filterable;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.recyclerview.widget.DiffUtil;
|
import androidx.recyclerview.widget.DiffUtil;
|
||||||
import androidx.recyclerview.widget.ListAdapter;
|
import androidx.recyclerview.widget.ListAdapter;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import awais.instagrabber.adapters.viewholder.StoryListViewHolder;
|
import awais.instagrabber.adapters.viewholder.StoryListViewHolder;
|
||||||
import awais.instagrabber.databinding.ItemNotificationBinding;
|
import awais.instagrabber.databinding.ItemNotificationBinding;
|
||||||
import awais.instagrabber.models.FeedStoryModel;
|
import awais.instagrabber.models.FeedStoryModel;
|
||||||
import awais.instagrabber.utils.Utils;
|
import awais.instagrabber.utils.TextUtils;
|
||||||
|
|
||||||
public final class FeedStoriesListAdapter extends ListAdapter<FeedStoryModel, StoryListViewHolder> {
|
public final class FeedStoriesListAdapter extends ListAdapter<FeedStoryModel, StoryListViewHolder> implements Filterable {
|
||||||
private final OnFeedStoryClickListener listener;
|
private final OnFeedStoryClickListener listener;
|
||||||
|
private List<FeedStoryModel> list;
|
||||||
|
|
||||||
|
private final Filter filter = new Filter() {
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
protected FilterResults performFiltering(final CharSequence filter) {
|
||||||
|
final boolean isFilterEmpty = TextUtils.isEmpty(filter);
|
||||||
|
final String query = isFilterEmpty ? null : filter.toString().toLowerCase();
|
||||||
|
|
||||||
|
for (FeedStoryModel item : list) {
|
||||||
|
if (isFilterEmpty) item.setShown(true);
|
||||||
|
else item.setShown(item.getProfileModel().getUsername().toLowerCase().contains(query));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void publishResults(final CharSequence constraint, final FilterResults results) {
|
||||||
|
submitList(list);
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private static final DiffUtil.ItemCallback<FeedStoryModel> diffCallback = new DiffUtil.ItemCallback<FeedStoryModel>() {
|
private static final DiffUtil.ItemCallback<FeedStoryModel> diffCallback = new DiffUtil.ItemCallback<FeedStoryModel>() {
|
||||||
@Override
|
@Override
|
||||||
@ -37,6 +60,17 @@ public final class FeedStoriesListAdapter extends ListAdapter<FeedStoryModel, St
|
|||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Filter getFilter() {
|
||||||
|
return filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void submitList(final List<FeedStoryModel> list) {
|
||||||
|
super.submitList(list.stream().filter(i -> i.isShown()).collect(Collectors.toList()));
|
||||||
|
this.list = list;
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public StoryListViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) {
|
public StoryListViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) {
|
||||||
|
@ -4,6 +4,9 @@ import android.content.Context;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@ -12,6 +15,7 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.appcompat.widget.SearchView;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.navigation.NavDirections;
|
import androidx.navigation.NavDirections;
|
||||||
@ -51,8 +55,9 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr
|
|||||||
private ArchivesViewModel archivesViewModel;
|
private ArchivesViewModel archivesViewModel;
|
||||||
private StoriesService storiesService;
|
private StoriesService storiesService;
|
||||||
private Context context;
|
private Context context;
|
||||||
private String type, endCursor = null;
|
private String type, currentQuery, endCursor = null;
|
||||||
private FeedStoriesListAdapter adapter;
|
private FeedStoriesListAdapter adapter;
|
||||||
|
private MenuItem menuSearch;
|
||||||
|
|
||||||
private final OnFeedStoryClickListener clickListener = new OnFeedStoryClickListener() {
|
private final OnFeedStoryClickListener clickListener = new OnFeedStoryClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -119,6 +124,7 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr
|
|||||||
fragmentActivity = (AppCompatActivity) requireActivity();
|
fragmentActivity = (AppCompatActivity) requireActivity();
|
||||||
context = getContext();
|
context = getContext();
|
||||||
if (context == null) return;
|
if (context == null) return;
|
||||||
|
setHasOptionsMenu(true);
|
||||||
storiesService = StoriesService.getInstance(null, 0L, null);
|
storiesService = StoriesService.getInstance(null, 0L, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,6 +147,30 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr
|
|||||||
shouldRefresh = false;
|
shouldRefresh = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreateOptionsMenu(@NonNull final Menu menu, final MenuInflater inflater) {
|
||||||
|
inflater.inflate(R.menu.search, menu);
|
||||||
|
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() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onQueryTextSubmit(final String query) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onQueryTextChange(final String query) {
|
||||||
|
if (adapter != null) {
|
||||||
|
currentQuery = query;
|
||||||
|
adapter.getFilter().filter(query);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
@ -16,6 +16,7 @@ public final class FeedStoryModel implements Serializable {
|
|||||||
private final boolean isLive, isBestie;
|
private final boolean isLive, isBestie;
|
||||||
private final long timestamp;
|
private final long timestamp;
|
||||||
private final int mediaCount;
|
private final int mediaCount;
|
||||||
|
private boolean isShown = true;
|
||||||
|
|
||||||
public FeedStoryModel(final String storyMediaId, final User profileModel, final boolean fullyRead,
|
public FeedStoryModel(final String storyMediaId, final User profileModel, final boolean fullyRead,
|
||||||
final long timestamp, final StoryModel firstStoryModel, final int mediaCount,
|
final long timestamp, final StoryModel firstStoryModel, final int mediaCount,
|
||||||
@ -74,4 +75,12 @@ public final class FeedStoryModel implements Serializable {
|
|||||||
public boolean isBestie() {
|
public boolean isBestie() {
|
||||||
return isBestie;
|
return isBestie;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isShown() {
|
||||||
|
return isShown;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShown(final boolean shown) {
|
||||||
|
isShown = shown;
|
||||||
|
}
|
||||||
}
|
}
|
13
app/src/main/res/menu/search.xml
Executable file
13
app/src/main/res/menu/search.xml
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_search"
|
||||||
|
android:actionLayout="@layout/layout_searchview"
|
||||||
|
android:icon="@drawable/ic_search_24"
|
||||||
|
android:title="@string/action_search"
|
||||||
|
android:titleCondensed="@string/action_search"
|
||||||
|
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
||||||
|
app:showAsAction="always|collapseActionView" />
|
||||||
|
</menu>
|
Loading…
Reference in New Issue
Block a user