mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-05 00:23:09 +02:00
Option to show messages, folders and accounts on startup
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -45,6 +45,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHolder> {
|
||||
private Context context;
|
||||
private boolean settings;
|
||||
private LayoutInflater inflater;
|
||||
|
||||
private List<EntityAccount> items = new ArrayList<>();
|
||||
@@ -92,6 +93,8 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
|
||||
ivPrimary.setVisibility(account.primary ? View.VISIBLE : View.INVISIBLE);
|
||||
tvName.setText(account.name);
|
||||
ivSync.setImageResource(account.synchronize ? R.drawable.baseline_sync_24 : R.drawable.baseline_sync_disabled_24);
|
||||
ivSync.setVisibility(settings ? View.VISIBLE : View.GONE);
|
||||
|
||||
tvUser.setText(account.user);
|
||||
|
||||
if ("connected".equals(account.state))
|
||||
@@ -124,13 +127,14 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
|
||||
|
||||
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
||||
lbm.sendBroadcast(
|
||||
new Intent(ActivitySetup.ACTION_EDIT_ACCOUNT)
|
||||
new Intent(settings ? ActivitySetup.ACTION_EDIT_ACCOUNT : ActivityView.ACTION_VIEW_FOLDERS)
|
||||
.putExtra("id", account.id));
|
||||
}
|
||||
}
|
||||
|
||||
AdapterAccount(Context context) {
|
||||
AdapterAccount(Context context, boolean settings) {
|
||||
this.context = context;
|
||||
this.settings = settings;
|
||||
this.inflater = LayoutInflater.from(context);
|
||||
|
||||
setHasStableIds(true);
|
||||
|
||||
@@ -38,8 +38,9 @@ public interface DaoAccount {
|
||||
@Query("SELECT * FROM account WHERE tbd = 1")
|
||||
List<EntityAccount> getAccountsTbd();
|
||||
|
||||
@Query("SELECT * FROM account")
|
||||
LiveData<List<EntityAccount>> liveAccounts();
|
||||
@Query("SELECT * FROM account" +
|
||||
" WHERE :all OR account.synchronize")
|
||||
LiveData<List<EntityAccount>> liveAccounts(boolean all);
|
||||
|
||||
@Query("SELECT * FROM account WHERE synchronize")
|
||||
LiveData<List<EntityAccount>> liveSynchronizingAccounts();
|
||||
|
||||
@@ -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<List<EntityAccount>>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable List<EntityAccount> accounts) {
|
||||
if (accounts == null)
|
||||
accounts = new ArrayList<>();
|
||||
DB.getInstance(getContext()).account().liveAccounts(settings)
|
||||
.observe(getViewLifecycleOwner(), new Observer<List<EntityAccount>>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable List<EntityAccount> 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();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user