mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-05 20:34:49 +01:00
Added menu shortcut to folders of primary account
This commit is contained in:
@@ -41,6 +41,9 @@ public interface DaoAccount {
|
||||
@Query("SELECT * FROM account WHERE id = :id")
|
||||
EntityAccount getAccount(long id);
|
||||
|
||||
@Query("SELECT * FROM account WHERE `primary`")
|
||||
LiveData<EntityAccount> livePrimaryAccount();
|
||||
|
||||
@Query("SELECT * FROM account WHERE id = :id")
|
||||
LiveData<EntityAccount> liveAccount(long id);
|
||||
|
||||
|
||||
@@ -25,6 +25,9 @@ import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
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 android.widget.ProgressBar;
|
||||
@@ -36,6 +39,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.paging.LivePagedListBuilder;
|
||||
@@ -50,6 +54,7 @@ public class FragmentMessages extends FragmentEx {
|
||||
private Group grpReady;
|
||||
private FloatingActionButton fab;
|
||||
|
||||
private long primary = -1;
|
||||
private AdapterMessage adapter;
|
||||
|
||||
private static final int PAGE_SIZE = 100;
|
||||
@@ -63,6 +68,8 @@ public class FragmentMessages extends FragmentEx {
|
||||
Bundle args = getArguments();
|
||||
long thread = (args == null ? -1 : args.getLong("thread", -1)); // message ID
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
// Get controls
|
||||
rvMessage = view.findViewById(R.id.rvFolder);
|
||||
tvNoEmail = view.findViewById(R.id.tvNoEmail);
|
||||
@@ -112,8 +119,17 @@ public class FragmentMessages extends FragmentEx {
|
||||
long folder = (args == null ? -1 : args.getLong("folder", -1));
|
||||
long thread = (args == null ? -1 : args.getLong("thread", -1)); // message ID
|
||||
|
||||
// Observe folder/messages
|
||||
DB db = DB.getInstance(getContext());
|
||||
|
||||
db.account().livePrimaryAccount().observe(getViewLifecycleOwner(), new Observer<EntityAccount>() {
|
||||
@Override
|
||||
public void onChanged(EntityAccount account) {
|
||||
primary = (account == null ? -1 : account.id);
|
||||
getActivity().invalidateOptionsMenu();
|
||||
}
|
||||
});
|
||||
|
||||
// Observe folder/messages
|
||||
LiveData<PagedList<TupleMessageEx>> messages;
|
||||
boolean debug = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("debug", false);
|
||||
if (thread < 0)
|
||||
@@ -197,4 +213,41 @@ public class FragmentMessages extends FragmentEx {
|
||||
}
|
||||
}.load(this, getArguments());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.menu_list, menu);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(Menu menu) {
|
||||
menu.findItem(R.id.menu_folders).setVisible(primary >= 0);
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_folders:
|
||||
onMenuFolders();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void onMenuFolders() {
|
||||
getFragmentManager().popBackStack("unified", 0);
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("account", primary);
|
||||
|
||||
FragmentFolders fragment = new FragmentFolders();
|
||||
fragment.setArguments(args);
|
||||
|
||||
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
||||
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("folders");
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
}
|
||||
|
||||
10
app/src/main/res/menu/menu_list.xml
Normal file
10
app/src/main/res/menu/menu_list.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?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/menu_folders"
|
||||
android:icon="@drawable/baseline_folder_24"
|
||||
android:title="@string/title_folder_primary"
|
||||
app:showAsAction="always" />
|
||||
</menu>
|
||||
@@ -108,6 +108,7 @@
|
||||
<string name="title_folder_junk">Spam</string>
|
||||
<string name="title_folder_sent">Sent</string>
|
||||
<string name="title_folder_user">User</string>
|
||||
<string name="title_folder_primary">Folders primary account</string>
|
||||
<string name="title_folder_thread">Message thread</string>
|
||||
<string name="title_no_messages">No messages</string>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user