Option to show messages, folders and accounts on startup

This commit is contained in:
M66B 2019-03-19 08:19:12 +00:00
parent ac11e117a6
commit 1fe82710fd
9 changed files with 127 additions and 57 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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();

View File

@ -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();
}
});
}
}

View File

@ -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));

View File

@ -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();
}
}
}

View File

@ -218,30 +218,29 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSectionDisplay" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swUnified"
android:layout_width="match_parent"
<TextView
android:id="@+id/tvStartup"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="12dp"
android:text="@string/title_advanced_unified"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vSeparatorDisplay"
app:switchPadding="12dp" />
<TextView
android:id="@+id/tvUnifiedHint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="60dp"
android:text="@string/title_advanced_unified_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
android:text="@string/title_advanced_startup"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swUnified" />
app:layout_constraintTop_toBottomOf="@id/vSeparatorDisplay" />
<Spinner
android:id="@+id/spStartup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="6dp"
android:entries="@array/startupNames"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvStartup" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swDate"
@ -252,7 +251,7 @@
android:layout_marginEnd="12dp"
android:text="@string/title_advanced_date_header"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvUnifiedHint"
app:layout_constraintTop_toBottomOf="@id/spStartup"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat

View File

@ -72,7 +72,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toStartOf="@+id/ivSync"
app:layout_constraintStart_toEndOf="@+id/ivPrimary"
app:layout_constraintTop_toBottomOf="@id/ivSync" />
app:layout_constraintTop_toBottomOf="@id/ivPrimary" />
<ImageView
android:id="@+id/ivState"

View File

@ -156,7 +156,7 @@
<string name="title_advanced_download">Automatically download messages and attachments on a metered connection up to</string>
<string name="title_advanced_browse">Browse messages on the server</string>
<string name="title_advanced_unified">Unified inbox</string>
<string name="title_advanced_startup">Show on start screen</string>
<string name="title_advanced_date_header">Group by date</string>
<string name="title_advanced_threading">Conversation threading</string>
<string name="title_advanced_avatars">Show contact photos</string>
@ -193,7 +193,6 @@
<string name="title_advanced_enabled_hint">Globally disable or enable receiving and sending of messages</string>
<string name="title_advanced_metered_hint">Metered connections are generally mobile connections or paid Wi-Fi hotspots</string>
<string name="title_advanced_browse_hint">Fetch more messages when scrolling down</string>
<string name="title_advanced_unified_hint">Show unified inbox folders or unified inbox messages</string>
<string name="title_advanced_threading_hint">Group messages related to each other</string>
<string name="title_advanced_name_email_hint">When disabled only names will be shown when available</string>
<string name="title_advanced_flags_hint">Note that starred messages will always be kept locally</string>
@ -585,6 +584,18 @@
<item>&#8734;</item>
</string-array>
<string-array name="startupValues" translatable="false">
<item>unified</item>
<item>folders</item>
<item>accounts</item>
</string-array>
<string-array name="startupNames">
<item>Unified inbox</item>
<item>Unified folders</item>
<item>Accounts</item>
</string-array>
<integer-array name="downloadValues" translatable="false">
<item>16384</item>
<item>32768</item>