mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-29 21:34:44 +02:00
Added search folder interface
This commit is contained in:
@@ -49,6 +49,7 @@ import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.view.MenuCompat;
|
||||
@@ -108,6 +109,7 @@ public class FragmentFolders extends FragmentBase {
|
||||
private boolean primary;
|
||||
private boolean show_hidden = false;
|
||||
private boolean show_flagged = false;
|
||||
private String searching = null;
|
||||
private AdapterFolder adapter;
|
||||
|
||||
private NumberFormat NF = NumberFormat.getNumberInstance();
|
||||
@@ -282,10 +284,20 @@ public class FragmentFolders extends FragmentBase {
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putString("fair:searching", searching);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
if (savedInstanceState != null)
|
||||
searching = savedInstanceState.getString("fair:searching");
|
||||
adapter.search(searching);
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
boolean folder_actions = prefs.getBoolean("folder_actions", false);
|
||||
boolean folder_sync = prefs.getBoolean("folder_sync", false);
|
||||
@@ -456,6 +468,37 @@ public class FragmentFolders extends FragmentBase {
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
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);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
@@ -502,6 +545,9 @@ public class FragmentFolders extends FragmentBase {
|
||||
} else if (itemId == R.id.menu_subscribed_only) {
|
||||
onMenuSubscribedOnly();
|
||||
return true;
|
||||
} else if (itemId == R.id.menu_search_folder) {
|
||||
onMenuSearchFolder(item);
|
||||
return true;
|
||||
} else if (itemId == R.id.menu_apply_all) {
|
||||
onMenuApplyToAll();
|
||||
return true;
|
||||
@@ -592,6 +638,13 @@ public class FragmentFolders extends FragmentBase {
|
||||
adapter.setSubscribedOnly(subscribed_only);
|
||||
}
|
||||
|
||||
private void onMenuSearchFolder(MenuItem item) {
|
||||
if (item.isActionViewExpanded())
|
||||
item.collapseActionView();
|
||||
else
|
||||
item.expandActionView();
|
||||
}
|
||||
|
||||
private void onMenuApplyToAll() {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("account", account);
|
||||
|
||||
Reference in New Issue
Block a user