mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-03 19:34:15 +01:00
Navigate from setup to messages when account set
This commit is contained in:
@@ -31,6 +31,8 @@ import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
public class ActivitySetup extends ActivityBase implements FragmentManager.OnBackStackChangedListener {
|
||||
static final int LOADER_CREATE_OUTBOX = 1;
|
||||
|
||||
static final String ACTION_EDIT_ACCOUNT = BuildConfig.APPLICATION_ID + ".EDIT_ACCOUNT";
|
||||
static final String ACTION_EDIT_IDENTITY = BuildConfig.APPLICATION_ID + ".EDIT_IDENTITY";
|
||||
|
||||
|
||||
@@ -260,7 +260,10 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
getSupportFragmentManager().popBackStack("unified", 0);
|
||||
if (intent.getBooleanExtra("setup", false))
|
||||
intent.getExtras().remove("setup");
|
||||
else
|
||||
getSupportFragmentManager().popBackStack("unified", 0);
|
||||
checkIntent(intent);
|
||||
super.onNewIntent(intent);
|
||||
}
|
||||
@@ -336,9 +339,9 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("time", new Date().getTime());
|
||||
|
||||
new SimpleLoader<Object>() {
|
||||
new SimpleLoader<Void>() {
|
||||
@Override
|
||||
public Object onLoad(Bundle args) {
|
||||
public Void onLoad(Bundle args) {
|
||||
long time = args.getLong("time");
|
||||
DaoAccount dao = DB.getInstance(getContext()).account();
|
||||
for (EntityAccount account : dao.getAccounts(true)) {
|
||||
@@ -458,9 +461,9 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
|
||||
|
||||
} else if (ACTION_VIEW_MESSAGE.equals(intent.getAction())) {
|
||||
|
||||
new SimpleLoader<Object>() {
|
||||
new SimpleLoader<Void>() {
|
||||
@Override
|
||||
public Object onLoad(Bundle args) {
|
||||
public Void onLoad(Bundle args) {
|
||||
long id = args.getLong("id");
|
||||
DB db = DB.getInstance(ActivityView.this);
|
||||
EntityMessage message = db.message().getMessage(id);
|
||||
@@ -490,7 +493,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaded(Bundle args, Object result) {
|
||||
public void onLoaded(Bundle args, Void result) {
|
||||
FragmentMessage fragment = new FragmentMessage();
|
||||
fragment.setArguments(args);
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
|
||||
@@ -413,9 +413,9 @@ public class FragmentCompose extends FragmentEx {
|
||||
args.putLong("id", id);
|
||||
args.putParcelable("uri", data.getData());
|
||||
|
||||
new SimpleLoader<Object>() {
|
||||
new SimpleLoader<Void>() {
|
||||
@Override
|
||||
public Object onLoad(Bundle args) throws IOException {
|
||||
public Void onLoad(Bundle args) throws IOException {
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
Uri uri = args.getParcelable("uri");
|
||||
|
||||
@@ -402,9 +402,9 @@ public class FragmentMessage extends FragmentEx {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", id);
|
||||
|
||||
new SimpleLoader<Object>() {
|
||||
new SimpleLoader<Void>() {
|
||||
@Override
|
||||
public Object onLoad(Bundle args) {
|
||||
public Void onLoad(Bundle args) {
|
||||
long id = args.getLong("id");
|
||||
DB db = DB.getInstance(getContext());
|
||||
try {
|
||||
@@ -428,7 +428,7 @@ public class FragmentMessage extends FragmentEx {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaded(Bundle args, Object data) {
|
||||
public void onLoaded(Bundle args, Void data) {
|
||||
item.setEnabled(true);
|
||||
item.setIcon(icon);
|
||||
}
|
||||
@@ -513,9 +513,9 @@ public class FragmentMessage extends FragmentEx {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", id);
|
||||
|
||||
new SimpleLoader<Object>() {
|
||||
new SimpleLoader<Void>() {
|
||||
@Override
|
||||
public Object onLoad(Bundle args) {
|
||||
public Void onLoad(Bundle args) {
|
||||
long id = args.getLong("id");
|
||||
DB db = DB.getInstance(getContext());
|
||||
try {
|
||||
@@ -539,7 +539,7 @@ public class FragmentMessage extends FragmentEx {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaded(Bundle args, Object result) {
|
||||
public void onLoaded(Bundle args, Void result) {
|
||||
item.setEnabled(true);
|
||||
item.setIcon(icon);
|
||||
}
|
||||
@@ -575,9 +575,9 @@ public class FragmentMessage extends FragmentEx {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", id);
|
||||
|
||||
new SimpleLoader<Object>() {
|
||||
new SimpleLoader<Void>() {
|
||||
@Override
|
||||
public Object onLoad(Bundle args) {
|
||||
public Void onLoad(Bundle args) {
|
||||
long id = args.getLong("id");
|
||||
DB db = DB.getInstance(getContext());
|
||||
try {
|
||||
@@ -599,7 +599,7 @@ public class FragmentMessage extends FragmentEx {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaded(Bundle args, Object result) {
|
||||
public void onLoaded(Bundle args, Void result) {
|
||||
item.setEnabled(true);
|
||||
item.setIcon(icon);
|
||||
}
|
||||
@@ -624,9 +624,9 @@ public class FragmentMessage extends FragmentEx {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", id);
|
||||
|
||||
new SimpleLoader<Object>() {
|
||||
new SimpleLoader<Void>() {
|
||||
@Override
|
||||
public Object onLoad(Bundle args) {
|
||||
public Void onLoad(Bundle args) {
|
||||
long id = args.getLong("id");
|
||||
DB db = DB.getInstance(getContext());
|
||||
try {
|
||||
@@ -650,7 +650,7 @@ public class FragmentMessage extends FragmentEx {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaded(Bundle args, Object result) {
|
||||
public void onLoaded(Bundle args, Void result) {
|
||||
item.setEnabled(true);
|
||||
item.setIcon(icon);
|
||||
}
|
||||
@@ -682,9 +682,9 @@ public class FragmentMessage extends FragmentEx {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", id);
|
||||
|
||||
new SimpleLoader<Object>() {
|
||||
new SimpleLoader<Void>() {
|
||||
@Override
|
||||
public Object onLoad(Bundle args) {
|
||||
public Void onLoad(Bundle args) {
|
||||
long id = args.getLong("id");
|
||||
DB db = DB.getInstance(getContext());
|
||||
try {
|
||||
@@ -708,7 +708,7 @@ public class FragmentMessage extends FragmentEx {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaded(Bundle args, Object result) {
|
||||
public void onLoaded(Bundle args, Void result) {
|
||||
item.setEnabled(true);
|
||||
item.setIcon(icon);
|
||||
}
|
||||
@@ -801,9 +801,9 @@ public class FragmentMessage extends FragmentEx {
|
||||
Bundle args = ((MoveLoader) loader).args;
|
||||
args.putLong("target", target.getItemId());
|
||||
|
||||
new SimpleLoader<Object>() {
|
||||
new SimpleLoader<Void>() {
|
||||
@Override
|
||||
public Object onLoad(Bundle args) {
|
||||
public Void onLoad(Bundle args) {
|
||||
long id = args.getLong("id");
|
||||
long target = args.getLong("target");
|
||||
DB db = DB.getInstance(getContext());
|
||||
@@ -827,7 +827,7 @@ public class FragmentMessage extends FragmentEx {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaded(Bundle args, Object result) {
|
||||
public void onLoaded(Bundle args, Void result) {
|
||||
item.setEnabled(true);
|
||||
item.setIcon(icon);
|
||||
}
|
||||
|
||||
@@ -33,10 +33,9 @@ import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -56,13 +55,9 @@ public class FragmentSetup extends FragmentEx {
|
||||
private Button btnPermissions;
|
||||
private TextView tvPermissionsDone;
|
||||
|
||||
private Button btnMessages;
|
||||
|
||||
private CheckBox cbDarkTheme;
|
||||
private CheckBox cbDebug;
|
||||
|
||||
private ExecutorService executor = Executors.newCachedThreadPool();
|
||||
|
||||
private static final String[] permissions = new String[]{
|
||||
Manifest.permission.READ_CONTACTS
|
||||
};
|
||||
@@ -86,8 +81,6 @@ public class FragmentSetup extends FragmentEx {
|
||||
btnPermissions = view.findViewById(R.id.btnPermissions);
|
||||
tvPermissionsDone = view.findViewById(R.id.tvPermissionsDone);
|
||||
|
||||
btnMessages = view.findViewById(R.id.btnMessages);
|
||||
|
||||
cbDarkTheme = view.findViewById(R.id.cbDarkTheme);
|
||||
cbDebug = view.findViewById(R.id.cbDebug);
|
||||
|
||||
@@ -119,14 +112,6 @@ public class FragmentSetup extends FragmentEx {
|
||||
}
|
||||
});
|
||||
|
||||
btnMessages.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startActivity(new Intent(getContext(), ActivityView.class));
|
||||
getFragmentManager().popBackStack();
|
||||
}
|
||||
});
|
||||
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
|
||||
String theme = prefs.getString("theme", "light");
|
||||
@@ -159,7 +144,6 @@ public class FragmentSetup extends FragmentEx {
|
||||
tvAccountDone.setVisibility(View.INVISIBLE);
|
||||
tvIdentityDone.setVisibility(View.INVISIBLE);
|
||||
tvPermissionsDone.setVisibility(View.INVISIBLE);
|
||||
btnMessages.setEnabled(false);
|
||||
|
||||
int[] grantResults = new int[permissions.length];
|
||||
for (int i = 0; i < permissions.length; i++)
|
||||
@@ -168,9 +152,9 @@ public class FragmentSetup extends FragmentEx {
|
||||
onRequestPermissionsResult(0, permissions, grantResults);
|
||||
|
||||
// Create outbox
|
||||
executor.submit(new Runnable() {
|
||||
new SimpleLoader<Void>() {
|
||||
@Override
|
||||
public void run() {
|
||||
public Void onLoad(Bundle args) throws Throwable {
|
||||
DB db = DB.getInstance(getContext());
|
||||
EntityFolder outbox = db.folder().getOutbox();
|
||||
if (outbox == null) {
|
||||
@@ -181,8 +165,14 @@ public class FragmentSetup extends FragmentEx {
|
||||
outbox.after = 0;
|
||||
outbox.id = db.folder().insertFolder(outbox);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public void onException(Bundle args, Throwable ex) {
|
||||
Toast.makeText(getContext(), ex.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}.load(this, ActivitySetup.LOADER_CREATE_OUTBOX, new Bundle());
|
||||
|
||||
return view;
|
||||
}
|
||||
@@ -197,7 +187,6 @@ public class FragmentSetup extends FragmentEx {
|
||||
@Override
|
||||
public void onChanged(@Nullable List<EntityAccount> accounts) {
|
||||
tvAccountDone.setVisibility(accounts.size() > 0 ? View.VISIBLE : View.INVISIBLE);
|
||||
btnMessages.setEnabled(accounts.size() > 0);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -209,6 +198,13 @@ public class FragmentSetup extends FragmentEx {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if (tvAccountDone.getVisibility() == View.VISIBLE)
|
||||
startActivity(new Intent(getContext(), ActivityView.class).putExtra("setup", true));
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
boolean has = (grantResults.length > 0);
|
||||
|
||||
@@ -132,19 +132,6 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvPermissions" />
|
||||
|
||||
<!-- read -->
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnMessages"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:text="@string/title_setup_messages"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvPermissionsDone" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbDarkTheme"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -154,7 +141,7 @@
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnMessages" />
|
||||
app:layout_constraintTop_toBottomOf="@id/tvPermissionsDone" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbDebug"
|
||||
|
||||
@@ -49,7 +49,6 @@
|
||||
<string name="title_setup_identity_remark">To send email</string>
|
||||
<string name="title_setup_permissions">Grant permissions</string>
|
||||
<string name="title_setup_permissions_remark">To autocomplete addresses (optional)</string>
|
||||
<string name="title_setup_messages">View messages</string>
|
||||
<string name="title_setup_done">Done</string>
|
||||
<string name="title_setup_granted">Granted</string>
|
||||
<string name="title_setup_dark_theme">Dark theme</string>
|
||||
|
||||
Reference in New Issue
Block a user