diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index ef87c491bf..26f85ee724 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -93,7 +93,7 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.preference.PreferenceManager; public class ActivityView extends ActivityBilling implements FragmentManager.OnBackStackChangedListener { - private boolean unified; + private String startup; private View view; private DrawerLayout drawerLayout; @@ -121,6 +121,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB static final int REQUEST_SENDER = 5; static final int REQUEST_RECIPIENT = 6; + static final String ACTION_VIEW_FOLDERS = BuildConfig.APPLICATION_ID + ".VIEW_FOLDERS"; static final String ACTION_VIEW_MESSAGES = BuildConfig.APPLICATION_ID + ".VIEW_MESSAGES"; static final String ACTION_VIEW_THREAD = BuildConfig.APPLICATION_ID + ".VIEW_THREAD"; static final String ACTION_STORE_RAW = BuildConfig.APPLICATION_ID + ".STORE_RAW"; @@ -144,7 +145,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB super.onCreate(savedInstanceState); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - unified = prefs.getBoolean("unified", true); + startup = prefs.getString("startup", "unified"); view = LayoutInflater.from(this).inflate(R.layout.activity_view, null); setContentView(view); @@ -412,8 +413,22 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } private void init() { - FragmentBase fragment = (unified ? new FragmentMessages() : new FragmentFolders()); - fragment.setArguments(new Bundle()); + Bundle args = new Bundle(); + + FragmentBase fragment; + switch (startup) { + case "accounts": + fragment = new FragmentAccounts(); + args.putBoolean("settings", false); + break; + case "folders": + fragment = new FragmentFolders(); + break; + default: + fragment = new FragmentMessages(); + } + + fragment.setArguments(args); FragmentManager fm = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fm.beginTransaction(); @@ -545,6 +560,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this); IntentFilter iff = new IntentFilter(); + iff.addAction(ACTION_VIEW_FOLDERS); iff.addAction(ACTION_VIEW_MESSAGES); iff.addAction(ACTION_VIEW_THREAD); iff.addAction(ACTION_STORE_RAW); @@ -1056,7 +1072,9 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) { String action = intent.getAction(); - if (ACTION_VIEW_MESSAGES.equals(action)) + if (ACTION_VIEW_FOLDERS.equals(action)) + onViewFolders(intent); + else if (ACTION_VIEW_MESSAGES.equals(action)) onViewMessages(intent); else if (ACTION_VIEW_THREAD.equals(action)) onViewThread(intent); @@ -1084,6 +1102,11 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } }; + private void onViewFolders(Intent intent) { + long account = intent.getLongExtra("id", -1); + onMenuFolders(account); + } + private void onViewMessages(Intent intent) { if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) getSupportFragmentManager().popBackStack("messages", FragmentManager.POP_BACK_STACK_INCLUSIVE); diff --git a/app/src/main/java/eu/faircode/email/AdapterAccount.java b/app/src/main/java/eu/faircode/email/AdapterAccount.java index 9c03710542..b734cf6e0a 100644 --- a/app/src/main/java/eu/faircode/email/AdapterAccount.java +++ b/app/src/main/java/eu/faircode/email/AdapterAccount.java @@ -45,6 +45,7 @@ import androidx.recyclerview.widget.RecyclerView; public class AdapterAccount extends RecyclerView.Adapter { private Context context; + private boolean settings; private LayoutInflater inflater; private List items = new ArrayList<>(); @@ -92,6 +93,8 @@ public class AdapterAccount extends RecyclerView.Adapter getAccountsTbd(); - @Query("SELECT * FROM account") - LiveData> liveAccounts(); + @Query("SELECT * FROM account" + + " WHERE :all OR account.synchronize") + LiveData> liveAccounts(boolean all); @Query("SELECT * FROM account WHERE synchronize") LiveData> liveSynchronizingAccounts(); diff --git a/app/src/main/java/eu/faircode/email/FragmentAccounts.java b/app/src/main/java/eu/faircode/email/FragmentAccounts.java index d2332ce60b..a9d693e3fb 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccounts.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccounts.java @@ -40,6 +40,7 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; public class FragmentAccounts extends FragmentBase { + private boolean settings; private RecyclerView rvAccount; private ContentLoadingProgressBar pbWait; private Group grpReady; @@ -48,6 +49,13 @@ public class FragmentAccounts extends FragmentBase { private AdapterAccount adapter; + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Bundle args = getArguments(); + settings = (args == null || args.getBoolean("settings", true)); + } + @Override @Nullable public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -67,7 +75,7 @@ public class FragmentAccounts extends FragmentBase { LinearLayoutManager llm = new LinearLayoutManager(getContext()); rvAccount.setLayoutManager(llm); - adapter = new AdapterAccount(getContext()); + adapter = new AdapterAccount(getContext(), settings); rvAccount.setAdapter(adapter); fab.setOnClickListener(new View.OnClickListener() { @@ -104,22 +112,23 @@ public class FragmentAccounts extends FragmentBase { super.onActivityCreated(savedInstanceState); // Observe accounts - DB.getInstance(getContext()).account().liveAccounts().observe(getViewLifecycleOwner(), new Observer>() { - @Override - public void onChanged(@Nullable List accounts) { - if (accounts == null) - accounts = new ArrayList<>(); + DB.getInstance(getContext()).account().liveAccounts(settings) + .observe(getViewLifecycleOwner(), new Observer>() { + @Override + public void onChanged(@Nullable List accounts) { + if (accounts == null) + accounts = new ArrayList<>(); - adapter.set(accounts); + adapter.set(accounts); - pbWait.setVisibility(View.GONE); - grpReady.setVisibility(View.VISIBLE); + pbWait.setVisibility(View.GONE); + grpReady.setVisibility(View.VISIBLE); - if (accounts.size() == 0) - animator.start(); - else - animator.end(); - } - }); + if (accounts.size() == 0) + animator.start(); + else + animator.end(); + } + }); } } diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index 42e6011698..cbce254149 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -72,7 +72,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O private SwitchCompat swMetered; private Spinner spDownload; - private SwitchCompat swUnified; + private Spinner spStartup; private SwitchCompat swDate; private SwitchCompat swThreading; private SwitchCompat swAvatars; @@ -111,7 +111,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O private Group grpNotification; static String[] OPTIONS_RESTART = new String[]{ - "unified", "date", "threading", "avatars", "identicons", "name_email", "subject_italic", "flags", "preview", + "startup", "date", "threading", "avatars", "identicons", "name_email", "subject_italic", "flags", "preview", "addresses", "autohtml", "autoimages", "actionbar", "pull", "swipenav", "autoexpand", "autoclose", "autonext", "debug" @@ -120,7 +120,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O private final static String[] ADVANCED_OPTIONS = new String[]{ "enabled", "schedule_start", "schedule_end", "metered", "download", - "unified", "date", "threading", "avatars", "identicons", "name_email", "subject_italic", "flags", "preview", + "startup", "date", "threading", "avatars", "identicons", "name_email", "subject_italic", "flags", "preview", "addresses", "autohtml", "remove_tracking", "autoimages", "actionbar", "pull", "swipenav", "autoexpand", "autoclose", "autonext", "collapse", "autoread", "automove", "autoresize", "sender", "autosend", @@ -148,7 +148,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O swMetered = view.findViewById(R.id.swMetered); spDownload = view.findViewById(R.id.spDownload); - swUnified = view.findViewById(R.id.swUnified); + spStartup = view.findViewById(R.id.spStartup); swDate = view.findViewById(R.id.swDate); swThreading = view.findViewById(R.id.swThreading); swAvatars = view.findViewById(R.id.swAvatars); @@ -278,10 +278,16 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O } }); - swUnified.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + spStartup.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - prefs.edit().putBoolean("unified", checked).apply(); + public void onItemSelected(AdapterView adapterView, View view, int position, long id) { + String[] values = getResources().getStringArray(R.array.startupValues); + prefs.edit().putString("startup", values[position]).apply(); + } + + @Override + public void onNothingSelected(AdapterView parent) { + prefs.edit().remove("startup").apply(); } }); @@ -568,9 +574,9 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O swMetered.setChecked(prefs.getBoolean("metered", true)); int download = prefs.getInt("download", 32768); - int[] values = getResources().getIntArray(R.array.downloadValues); - for (int pos = 0; pos < values.length; pos++) - if (values[pos] == download) { + int[] downloadValues = getResources().getIntArray(R.array.downloadValues); + for (int pos = 0; pos < downloadValues.length; pos++) + if (downloadValues[pos] == download) { spDownload.setTag(pos); spDownload.setSelection(pos); break; @@ -578,7 +584,14 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O boolean compact = prefs.getBoolean("compact", false); - swUnified.setChecked(prefs.getBoolean("unified", true)); + String startup = prefs.getString("startup", "unified"); + String[] startupValues = getResources().getStringArray(R.array.startupValues); + for (int pos = 0; pos < startupValues.length; pos++) + if (startupValues[pos].equals(startup)) { + spStartup.setSelection(pos); + break; + } + swDate.setChecked(prefs.getBoolean("date", true)); swThreading.setChecked(prefs.getBoolean("threading", true)); swAvatars.setChecked(prefs.getBoolean("avatars", true)); diff --git a/app/src/main/java/eu/faircode/email/ReceiverAutostart.java b/app/src/main/java/eu/faircode/email/ReceiverAutostart.java index 32d229fb95..61e15d9de8 100644 --- a/app/src/main/java/eu/faircode/email/ReceiverAutostart.java +++ b/app/src/main/java/eu/faircode/email/ReceiverAutostart.java @@ -22,6 +22,9 @@ package eu.faircode.email; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; + +import androidx.preference.PreferenceManager; public class ReceiverAutostart extends BroadcastReceiver { @Override @@ -31,6 +34,13 @@ public class ReceiverAutostart extends BroadcastReceiver { Log.i("Received " + intent); ServiceSynchronize.boot(context); ServiceSend.boot(context); + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + SharedPreferences.Editor editor = prefs.edit(); + if (!prefs.getBoolean("unified", true)) + editor.putString("startup", "folders"); + editor.remove("unified"); + editor.apply(); } } } diff --git a/app/src/main/res/layout/fragment_options.xml b/app/src/main/res/layout/fragment_options.xml index e6919807b9..98e88204fb 100644 --- a/app/src/main/res/layout/fragment_options.xml +++ b/app/src/main/res/layout/fragment_options.xml @@ -218,30 +218,29 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvSectionDisplay" /> - - - + app:layout_constraintTop_toBottomOf="@id/vSeparatorDisplay" /> + + + app:layout_constraintTop_toBottomOf="@id/ivPrimary" /> Automatically download messages and attachments on a metered connection up to Browse messages on the server - Unified inbox + Show on start screen Group by date Conversation threading Show contact photos @@ -193,7 +193,6 @@ Globally disable or enable receiving and sending of messages Metered connections are generally mobile connections or paid Wi-Fi hotspots Fetch more messages when scrolling down - Show unified inbox folders or unified inbox messages Group messages related to each other When disabled only names will be shown when available Note that starred messages will always be kept locally @@ -585,6 +584,18 @@ + + unified + folders + accounts + + + + Unified inbox + Unified folders + Accounts + + 16384 32768