mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-19 10:25:29 +00:00
Added search folder interface
This commit is contained in:
parent
aa3a102edb
commit
548048d372
2 changed files with 59 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -48,6 +48,12 @@
|
|||
</group>
|
||||
|
||||
<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
|
||||
android:id="@+id/menu_apply_all"
|
||||
android:title="@string/title_apply_to_all"
|
||||
|
|
Loading…
Add table
Reference in a new issue