Browse Source

Added menu shortcut to folders of primary account

main
M66B 6 years ago
parent
commit
2ac5accc00
4 changed files with 68 additions and 1 deletions
  1. +3
    -0
      app/src/main/java/eu/faircode/email/DaoAccount.java
  2. +54
    -1
      app/src/main/java/eu/faircode/email/FragmentMessages.java
  3. +10
    -0
      app/src/main/res/menu/menu_list.xml
  4. +1
    -0
      app/src/main/res/values/strings.xml

+ 3
- 0
app/src/main/java/eu/faircode/email/DaoAccount.java View File

@ -41,6 +41,9 @@ public interface DaoAccount {
@Query("SELECT * FROM account WHERE id = :id") @Query("SELECT * FROM account WHERE id = :id")
EntityAccount getAccount(long id); EntityAccount getAccount(long id);
@Query("SELECT * FROM account WHERE `primary`")
LiveData<EntityAccount> livePrimaryAccount();
@Query("SELECT * FROM account WHERE id = :id") @Query("SELECT * FROM account WHERE id = :id")
LiveData<EntityAccount> liveAccount(long id); LiveData<EntityAccount> liveAccount(long id);


+ 54
- 1
app/src/main/java/eu/faircode/email/FragmentMessages.java View File

@ -25,6 +25,9 @@ import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
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.ProgressBar; import android.widget.ProgressBar;
@ -36,6 +39,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.Group; import androidx.constraintlayout.widget.Group;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
import androidx.paging.LivePagedListBuilder; import androidx.paging.LivePagedListBuilder;
@ -50,6 +54,7 @@ public class FragmentMessages extends FragmentEx {
private Group grpReady; private Group grpReady;
private FloatingActionButton fab; private FloatingActionButton fab;
private long primary = -1;
private AdapterMessage adapter; private AdapterMessage adapter;
private static final int PAGE_SIZE = 100; private static final int PAGE_SIZE = 100;
@ -63,6 +68,8 @@ public class FragmentMessages extends FragmentEx {
Bundle args = getArguments(); Bundle args = getArguments();
long thread = (args == null ? -1 : args.getLong("thread", -1)); // message ID long thread = (args == null ? -1 : args.getLong("thread", -1)); // message ID
setHasOptionsMenu(true);
// Get controls // Get controls
rvMessage = view.findViewById(R.id.rvFolder); rvMessage = view.findViewById(R.id.rvFolder);
tvNoEmail = view.findViewById(R.id.tvNoEmail); 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 folder = (args == null ? -1 : args.getLong("folder", -1));
long thread = (args == null ? -1 : args.getLong("thread", -1)); // message ID long thread = (args == null ? -1 : args.getLong("thread", -1)); // message ID
// Observe folder/messages
DB db = DB.getInstance(getContext()); 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; LiveData<PagedList<TupleMessageEx>> messages;
boolean debug = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("debug", false); boolean debug = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("debug", false);
if (thread < 0) if (thread < 0)
@ -197,4 +213,41 @@ public class FragmentMessages extends FragmentEx {
} }
}.load(this, getArguments()); }.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
- 0
app/src/main/res/menu/menu_list.xml View 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>

+ 1
- 0
app/src/main/res/values/strings.xml View File

@ -108,6 +108,7 @@
<string name="title_folder_junk">Spam</string> <string name="title_folder_junk">Spam</string>
<string name="title_folder_sent">Sent</string> <string name="title_folder_sent">Sent</string>
<string name="title_folder_user">User</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_folder_thread">Message thread</string>
<string name="title_no_messages">No messages</string> <string name="title_no_messages">No messages</string>


Loading…
Cancel
Save