Added search folder interface

pull/205/head
M66B 3 years ago
parent aa3a102edb
commit 548048d372

@ -49,6 +49,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.SearchView;
import androidx.constraintlayout.widget.Group; import androidx.constraintlayout.widget.Group;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.core.view.MenuCompat; import androidx.core.view.MenuCompat;
@ -108,6 +109,7 @@ public class FragmentFolders extends FragmentBase {
private boolean primary; private boolean primary;
private boolean show_hidden = false; private boolean show_hidden = false;
private boolean show_flagged = false; private boolean show_flagged = false;
private String searching = null;
private AdapterFolder adapter; private AdapterFolder adapter;
private NumberFormat NF = NumberFormat.getNumberInstance(); private NumberFormat NF = NumberFormat.getNumberInstance();
@ -282,10 +284,20 @@ public class FragmentFolders extends FragmentBase {
return view; return view;
} }
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putString("fair:searching", searching);
super.onSaveInstanceState(outState);
}
@Override @Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) { public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
if (savedInstanceState != null)
searching = savedInstanceState.getString("fair:searching");
adapter.search(searching);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean folder_actions = prefs.getBoolean("folder_actions", false); boolean folder_actions = prefs.getBoolean("folder_actions", false);
boolean folder_sync = prefs.getBoolean("folder_sync", false); boolean folder_sync = prefs.getBoolean("folder_sync", false);
@ -456,6 +468,37 @@ public class FragmentFolders extends FragmentBase {
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_folders, menu); inflater.inflate(R.menu.menu_folders, menu);
MenuItem menuSearch = menu.findItem(R.id.menu_search_folder);
SearchView searchView = (SearchView) menuSearch.getActionView();
searchView.setQueryHint(getString(R.string.title_search));
if (TextUtils.isEmpty(searching))
menuSearch.collapseActionView();
else {
menuSearch.expandActionView();
searchView.setQuery(searching, true);
}
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextChange(String newText) {
if (getView() != null) {
searching = newText;
adapter.search(newText);
}
return true;
}
@Override
public boolean onQueryTextSubmit(String query) {
searching = query;
adapter.search(query);
return true;
}
});
MenuCompat.setGroupDividerEnabled(menu, true); MenuCompat.setGroupDividerEnabled(menu, true);
super.onCreateOptionsMenu(menu, inflater); super.onCreateOptionsMenu(menu, inflater);
} }
@ -502,6 +545,9 @@ public class FragmentFolders extends FragmentBase {
} else if (itemId == R.id.menu_subscribed_only) { } else if (itemId == R.id.menu_subscribed_only) {
onMenuSubscribedOnly(); onMenuSubscribedOnly();
return true; return true;
} else if (itemId == R.id.menu_search_folder) {
onMenuSearchFolder(item);
return true;
} else if (itemId == R.id.menu_apply_all) { } else if (itemId == R.id.menu_apply_all) {
onMenuApplyToAll(); onMenuApplyToAll();
return true; return true;
@ -592,6 +638,13 @@ public class FragmentFolders extends FragmentBase {
adapter.setSubscribedOnly(subscribed_only); adapter.setSubscribedOnly(subscribed_only);
} }
private void onMenuSearchFolder(MenuItem item) {
if (item.isActionViewExpanded())
item.collapseActionView();
else
item.expandActionView();
}
private void onMenuApplyToAll() { private void onMenuApplyToAll() {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("account", account); args.putLong("account", account);

@ -48,6 +48,12 @@
</group> </group>
<group android:id="@+id/group_operations"> <group android:id="@+id/group_operations">
<item
android:id="@+id/menu_search_folder"
android:title="@string/title_search"
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="collapseActionView|never" />
<item <item
android:id="@+id/menu_apply_all" android:id="@+id/menu_apply_all"
android:title="@string/title_apply_to_all" android:title="@string/title_apply_to_all"

Loading…
Cancel
Save