Added setting to enable/disabled unified inbox

pull/146/head
M66B 6 years ago
parent 4fe9be72b5
commit a941094216

@ -91,15 +91,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
finish();
if (this.getClass().equals(ActivitySetup.class))
startActivity(getIntent());
} else if (!this.getClass().equals(ActivitySetup.class) &&
("threading".equals(key) ||
"compact".equals(key) ||
"avatars".equals(key) ||
"identicons".equals(key) ||
"preview".equals(key) ||
"actionbar".equals(key) ||
"confirm".equals(key) ||
"debug".equals(key)))
} else if (!this.getClass().equals(ActivitySetup.class))
finish();
}

@ -98,6 +98,8 @@ import androidx.lifecycle.ViewModelProviders;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
public class ActivityView extends ActivityBilling implements FragmentManager.OnBackStackChangedListener {
private boolean unified;
private View view;
private DrawerLayout drawerLayout;
private Group grpPane;
@ -138,6 +140,9 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
unified = prefs.getBoolean("unified", true);
view = LayoutInflater.from(this).inflate(R.layout.activity_view, null);
setContentView(view);
@ -299,11 +304,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
});
if (getSupportFragmentManager().getFragments().size() == 0) {
Bundle args = new Bundle();
args.putLong("folder", -1);
FragmentMessages fragment = new FragmentMessages();
fragment.setArguments(args);
FragmentEx fragment = (unified ? new FragmentMessages() : new FragmentFolders());
fragment.setArguments(new Bundle());
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("unified");

@ -23,6 +23,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.preference.PreferenceManager;
@ -54,7 +55,7 @@ import androidx.recyclerview.widget.RecyclerView;
public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder> {
private Context context;
private LifecycleOwner owner;
private String accountState = null;
private long account;
private boolean debug;
private List<TupleFolderEx> all = new ArrayList<>();
@ -62,6 +63,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
private View itemView;
private View vwColor;
private ImageView ivState;
private TextView tvName;
private TextView tvMessages;
@ -82,6 +84,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
super(itemView);
this.itemView = itemView.findViewById(R.id.clItem);
vwColor = itemView.findViewById(R.id.vwColor);
ivState = itemView.findViewById(R.id.ivState);
tvName = itemView.findViewById(R.id.tvName);
tvMessages = itemView.findViewById(R.id.tvMessages);
@ -106,6 +109,9 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
private void bindTo(TupleFolderEx folder) {
itemView.setAlpha(folder.hide ? 0.5f : 1.0f);
vwColor.setBackgroundColor(folder.accountColor == null ? Color.TRANSPARENT : folder.accountColor);
vwColor.setVisibility(account < 0 ? View.VISIBLE : View.GONE);
if ("connected".equals(folder.state))
ivState.setImageResource(R.drawable.baseline_cloud_24);
else if ("connecting".equals(folder.state))
@ -130,13 +136,17 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
tvMessages.setText(String.format("%d/%d", folder.content, folder.messages));
ivUnified.setVisibility(folder.unified ? View.VISIBLE : View.INVISIBLE);
ivUnified.setVisibility(account > 0 && folder.unified ? View.VISIBLE : View.INVISIBLE);
if (account < 0)
tvType.setText(folder.accountName);
else {
int resid = context.getResources().getIdentifier(
"title_folder_" + folder.type.toLowerCase(),
"string",
context.getPackageName());
tvType.setText(resid > 0 ? context.getString(resid) : folder.type);
}
if (folder.account == null) {
tvAfter.setText(null);
@ -180,7 +190,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
PopupMenu popupMenu = new PopupMenu(context, itemView);
popupMenu.getMenu().add(Menu.NONE, action_synchronize_now, 1, R.string.title_synchronize_now);
popupMenu.getMenu().findItem(action_synchronize_now).setEnabled("connected".equals(accountState));
popupMenu.getMenu().findItem(action_synchronize_now).setEnabled("connected".equals(folder.state));
if (!EntityFolder.DRAFTS.equals(folder.type))
popupMenu.getMenu().add(Menu.NONE, action_delete_local, 2, R.string.title_delete_local);
@ -334,11 +344,13 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
void showHidden(boolean show) {
showAll = show;
set(all);
set(account, all);
}
public void set(@NonNull List<TupleFolderEx> folders) {
Log.i(Helper.TAG, "Set folders=" + folders.size());
public void set(long account, @NonNull List<TupleFolderEx> folders) {
Log.i(Helper.TAG, "Set account=" + account + " folders=" + folders.size());
this.account = account;
final Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
@ -396,10 +408,6 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
diff.dispatchUpdatesTo(this);
}
void setAccountState(String state) {
this.accountState = state;
}
private class MessageDiffCallback extends DiffUtil.Callback {
private List<TupleFolderEx> prev;
private List<TupleFolderEx> next;

@ -44,23 +44,26 @@ public interface DaoFolder {
" AND type = '" + EntityFolder.USER + "'")
List<EntityFolder> getUserFolders(long account);
@Query("SELECT folder.*, account.name AS accountName" +
@Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor" +
", COUNT(message.id) AS messages" +
", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" +
", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
" FROM folder" +
" LEFT JOIN account ON account.id = folder.account" +
" LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide AND NOT message.ui_found" +
" WHERE folder.account = :account OR folder.account IS NULL" +
" WHERE CASE WHEN :account IS NULL" +
" THEN folder.unified AND account.synchronize" +
" ELSE folder.account = :account OR folder.account IS NULL" +
" END" +
" GROUP BY folder.id")
LiveData<List<TupleFolderEx>> liveFolders(long account);
LiveData<List<TupleFolderEx>> liveFolders(Long account);
@Query("SELECT * FROM folder" +
" WHERE (:account < 0 OR folder.account = :account)" +
" AND type <> '" + EntityFolder.USER + "'")
LiveData<List<EntityFolder>> liveSystemFolders(long account);
@Query("SELECT folder.*, account.name AS accountName" +
@Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor" +
", COUNT(message.id) AS messages" +
", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" +
", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
@ -72,7 +75,7 @@ public interface DaoFolder {
" GROUP BY folder.id")
LiveData<List<TupleFolderEx>> liveUnified();
@Query("SELECT folder.*, account.name AS accountName" +
@Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor" +
", COUNT(message.id) AS messages" +
", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" +
", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
@ -135,7 +138,13 @@ public interface DaoFolder {
", `sync_days` = :sync_days" +
", `keep_days` = :keep_days" +
" WHERE id = :id")
int setFolderProperties(long id, String name, String display, boolean hide, boolean synchronize, boolean unified, int sync_days, int keep_days);
int setFolderProperties(
long id,
String name, String display,
boolean hide,
boolean synchronize,
boolean unified,
int sync_days, int keep_days);
@Query("UPDATE folder SET keywords = :keywords WHERE id = :id")
int setFolderKeywords(long id, String keywords);

@ -60,7 +60,7 @@ public class FragmentFolders extends FragmentEx {
// Get arguments
Bundle args = getArguments();
account = (args == null ? -1 : args.getLong("account"));
account = args.getLong("account", -1);
}
@Override
@ -119,6 +119,8 @@ public class FragmentFolders extends FragmentEx {
tbShowHidden.setVisibility(View.GONE);
grpReady.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE);
if (account < 0)
fab.hide();
return view;
}
@ -133,16 +135,18 @@ public class FragmentFolders extends FragmentEx {
DB db = DB.getInstance(getContext());
// Observe account
if (account < 0)
setSubtitle(R.string.title_folder_unified);
else
db.account().liveAccount(account).observe(getViewLifecycleOwner(), new Observer<EntityAccount>() {
@Override
public void onChanged(@Nullable EntityAccount account) {
setSubtitle(account == null ? null : account.name);
adapter.setAccountState(account.state);
}
});
// Observe folders
db.folder().liveFolders(account).observe(getViewLifecycleOwner(), new Observer<List<TupleFolderEx>>() {
db.folder().liveFolders(account < 0 ? null : account).observe(getViewLifecycleOwner(), new Observer<List<TupleFolderEx>>() {
@Override
public void onChanged(@Nullable List<TupleFolderEx> folders) {
if (folders == null) {
@ -158,7 +162,7 @@ public class FragmentFolders extends FragmentEx {
}
tbShowHidden.setVisibility(hidden ? View.VISIBLE : View.GONE);
adapter.set(folders);
adapter.set(account, folders);
pbWait.setVisibility(View.GONE);
grpReady.setVisibility(View.VISIBLE);

@ -43,6 +43,7 @@ import androidx.appcompat.widget.SwitchCompat;
public class FragmentOptions extends FragmentEx implements SharedPreferences.OnSharedPreferenceChangeListener {
private SwitchCompat swEnabled;
private SwitchCompat swMetered;
private SwitchCompat swUnified;
private SwitchCompat swThreading;
private SwitchCompat swCompact;
private SwitchCompat swAvatars;
@ -70,6 +71,7 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS
// Get controls
swEnabled = view.findViewById(R.id.swEnabled);
swMetered = view.findViewById(R.id.swMetered);
swUnified = view.findViewById(R.id.swUnified);
swThreading = view.findViewById(R.id.swThreading);
swCompact = view.findViewById(R.id.swCompact);
swAvatars = view.findViewById(R.id.swAvatars);
@ -109,6 +111,14 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS
}
});
swUnified.setChecked(prefs.getBoolean("unified", true));
swUnified.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("unified", checked).apply();
}
});
swThreading.setChecked(prefs.getBoolean("threading", true));
swThreading.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override

@ -21,6 +21,7 @@ package eu.faircode.email;
public class TupleFolderEx extends EntityFolder {
public String accountName;
public Integer accountColor;
public int messages;
public int content;
public int unseen;
@ -31,6 +32,7 @@ public class TupleFolderEx extends EntityFolder {
TupleFolderEx other = (TupleFolderEx) obj;
return (super.equals(obj) &&
(this.accountName == null ? other.accountName == null : accountName.equals(other.accountName)) &&
(this.accountColor == null ? other.accountColor == null : this.accountColor.equals(other.accountColor)) &&
this.messages == other.messages &&
this.content == other.content &&
this.unseen == other.unseen);

@ -29,6 +29,15 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swEnabled" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swUnified"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_unified"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swMetered" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swThreading"
android:layout_width="match_parent"
@ -36,7 +45,7 @@
android:layout_marginTop="12dp"
android:text="@string/title_advanced_threading"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swMetered" />
app:layout_constraintTop_toBottomOf="@id/swUnified" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swCompact"

@ -9,6 +9,15 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="@+id/vwColor"
android:layout_width="6dp"
android:layout_height="0dp"
android:background="@color/colorAccent"
app:layout_constraintBottom_toTopOf="@+id/vSeparator"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/ivState"
android:layout_width="24dp"
@ -16,7 +25,7 @@
android:layout_marginStart="6dp"
android:layout_marginEnd="6dp"
android:src="@drawable/baseline_cloud_off_24"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="@id/vwColor"
app:layout_constraintTop_toTopOf="parent" />
<TextView
@ -67,7 +76,7 @@
android:layout_height="24dp"
android:layout_marginStart="6dp"
android:src="@drawable/baseline_folder_special_24"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="@id/vwColor"
app:layout_constraintTop_toBottomOf="@id/barrier1" />
<TextView
@ -131,7 +140,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?attr/colorWarning"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="@id/vwColor"
app:layout_constraintTop_toBottomOf="@id/tvKeywords" />
<View

@ -98,6 +98,7 @@
<string name="title_advanced">Advanced options</string>
<string name="title_advanced_enabled">Synchronize</string>
<string name="title_advanced_metered">Use metered connections</string>
<string name="title_advanced_unified">Unified inbox</string>
<string name="title_advanced_threading">Conversation threading</string>
<string name="title_advanced_compact">Compact message view</string>
<string name="title_advanced_avatars">Show contact photos</string>

Loading…
Cancel
Save