2018-08-10 13:32:07 +00:00
|
|
|
package eu.faircode.email;
|
|
|
|
|
2018-08-14 05:53:24 +00:00
|
|
|
/*
|
|
|
|
This file is part of FairEmail.
|
|
|
|
|
|
|
|
FairEmail is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
2018-10-29 10:46:49 +00:00
|
|
|
FairEmail is distributed in the hope that it will be useful,
|
2018-08-14 05:53:24 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2018-10-29 10:46:49 +00:00
|
|
|
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
2018-08-14 05:53:24 +00:00
|
|
|
|
2018-12-31 08:04:33 +00:00
|
|
|
Copyright 2018-2019 by Marcel Bokhorst (M66B)
|
2018-08-14 05:53:24 +00:00
|
|
|
*/
|
|
|
|
|
2019-01-25 17:55:22 +00:00
|
|
|
import android.content.Context;
|
2018-08-10 13:32:07 +00:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2019-03-27 08:08:06 +00:00
|
|
|
import android.content.res.Configuration;
|
2018-08-10 13:32:07 +00:00
|
|
|
import android.os.Bundle;
|
2019-06-09 09:47:57 +00:00
|
|
|
import android.os.Handler;
|
2018-08-10 13:32:07 +00:00
|
|
|
|
|
|
|
import androidx.fragment.app.FragmentManager;
|
|
|
|
import androidx.fragment.app.FragmentTransaction;
|
2019-03-15 13:54:25 +00:00
|
|
|
import androidx.preference.PreferenceManager;
|
2018-08-10 13:32:07 +00:00
|
|
|
|
2019-04-17 18:21:44 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
2019-07-11 05:41:20 +00:00
|
|
|
public class ActivityMain extends ActivityBase implements FragmentManager.OnBackStackChangedListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
2019-08-12 09:54:34 +00:00
|
|
|
private static final String ACTION_REFRESH = BuildConfig.APPLICATION_ID + ".REFRESH";
|
|
|
|
|
2018-08-10 13:32:07 +00:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
getSupportFragmentManager().addOnBackStackChangedListener(this);
|
|
|
|
|
2019-09-10 07:05:21 +00:00
|
|
|
if (!Log.isSupportedDevice() && Helper.isPlayStoreInstall()) {
|
2019-03-08 07:08:50 +00:00
|
|
|
setTheme(R.style.AppThemeLight);
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_unsupported);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-10 13:32:07 +00:00
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
2019-07-10 15:58:26 +00:00
|
|
|
boolean eula = prefs.getBoolean("eula", false);
|
|
|
|
|
2018-08-10 13:32:07 +00:00
|
|
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
|
|
|
|
2019-07-10 15:58:26 +00:00
|
|
|
if (eula) {
|
2018-10-30 13:47:10 +00:00
|
|
|
super.onCreate(savedInstanceState);
|
2019-06-09 09:22:50 +00:00
|
|
|
|
2019-07-10 15:58:26 +00:00
|
|
|
final SimpleTask start = new SimpleTask<Boolean>() {
|
2019-06-09 09:47:57 +00:00
|
|
|
@Override
|
2019-07-10 15:58:26 +00:00
|
|
|
protected void onPreExecute(Bundle args) {
|
|
|
|
new Handler().postDelayed(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
getWindow().setBackgroundDrawableResource(R.drawable.splash);
|
|
|
|
}
|
|
|
|
}, 1500);
|
2019-06-09 09:47:57 +00:00
|
|
|
}
|
|
|
|
|
2018-08-10 13:32:07 +00:00
|
|
|
@Override
|
2019-06-09 09:22:50 +00:00
|
|
|
protected Boolean onExecute(Context context, Bundle args) {
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
if (prefs.getBoolean("has_accounts", false))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
List<EntityAccount> accounts = db.account().getSynchronizingAccounts();
|
|
|
|
boolean hasAccounts = (accounts != null && accounts.size() > 0);
|
|
|
|
|
|
|
|
prefs.edit().putBoolean("has_accounts", hasAccounts).apply();
|
|
|
|
|
|
|
|
return hasAccounts;
|
2019-01-25 17:55:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-06-09 09:22:50 +00:00
|
|
|
protected void onExecuted(Bundle args, Boolean hasAccounts) {
|
2019-08-03 14:05:30 +00:00
|
|
|
if (hasAccounts) {
|
2019-09-18 08:42:13 +00:00
|
|
|
Log.logBundle(args);
|
2019-09-27 08:43:01 +00:00
|
|
|
|
|
|
|
Intent view = new Intent(ActivityMain.this, ActivityView.class);
|
2019-08-12 14:11:06 +00:00
|
|
|
if (ACTION_REFRESH.equals(getIntent().getAction()))
|
|
|
|
view.putExtra("refresh", true);
|
2019-09-27 08:43:01 +00:00
|
|
|
|
|
|
|
Intent saved = args.getParcelable("intent");
|
|
|
|
if (saved == null)
|
|
|
|
startActivity(view);
|
|
|
|
else
|
|
|
|
try {
|
|
|
|
startActivity(saved);
|
|
|
|
} catch (SecurityException ex) {
|
|
|
|
Log.w(ex);
|
|
|
|
startActivity(view);
|
|
|
|
}
|
|
|
|
|
2019-08-12 13:18:35 +00:00
|
|
|
ServiceSynchronize.watchdog(ActivityMain.this);
|
2019-08-03 14:05:30 +00:00
|
|
|
ServiceSend.watchdog(ActivityMain.this);
|
|
|
|
} else
|
2019-06-09 09:22:50 +00:00
|
|
|
startActivity(new Intent(ActivityMain.this, ActivitySetup.class));
|
2018-08-10 13:32:07 +00:00
|
|
|
finish();
|
|
|
|
}
|
2019-01-25 17:55:22 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
2019-07-01 12:06:15 +00:00
|
|
|
Helper.unexpectedError(getSupportFragmentManager(), ex);
|
2019-01-25 17:55:22 +00:00
|
|
|
}
|
2019-07-10 15:58:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (Helper.shouldAuthenticate(this))
|
|
|
|
Helper.authenticate(ActivityMain.this, null,
|
|
|
|
new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2019-09-18 08:42:13 +00:00
|
|
|
Intent intent = getIntent();
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
if (intent.hasExtra("intent"))
|
|
|
|
args.putParcelable("intent", intent.getParcelableExtra("intent"));
|
|
|
|
start.execute(ActivityMain.this, args, "main:accounts");
|
2019-07-10 15:58:26 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2019-07-11 05:34:02 +00:00
|
|
|
try {
|
|
|
|
finish();
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.w(ex);
|
|
|
|
/*
|
|
|
|
java.lang.NullPointerException: Attempt to invoke virtual method 'int com.android.server.fingerprint.ClientMonitor.stop(boolean)' on a null object reference
|
|
|
|
at android.os.Parcel.createException(Parcel.java:1956)
|
|
|
|
at android.os.Parcel.readException(Parcel.java:1918)
|
|
|
|
at android.os.Parcel.readException(Parcel.java:1868)
|
|
|
|
at android.app.IActivityManager$Stub$Proxy.finishActivity(IActivityManager.java:3797)
|
|
|
|
at android.app.Activity.finish(Activity.java:5608)
|
|
|
|
at android.app.Activity.finish(Activity.java:5632)
|
|
|
|
at eu.faircode.email.ActivityMain$3.run(SourceFile:111)
|
|
|
|
at eu.faircode.email.Helper$3$1.run(SourceFile:706)
|
|
|
|
at android.os.Handler.handleCallback(Handler.java:873)
|
|
|
|
at android.os.Handler.dispatchMessage(Handler.java:99)
|
|
|
|
at android.os.Looper.loop(Looper.java:193)
|
|
|
|
at android.app.ActivityThread.main(ActivityThread.java:6718)
|
|
|
|
at java.lang.reflect.Method.invoke(Method.java:-2)
|
|
|
|
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
|
|
|
|
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
|
|
|
|
Caused by: android.os.RemoteException: Remote stack trace:
|
|
|
|
at com.android.server.fingerprint.FingerprintService$5.onTaskStackChanged(FingerprintService.java:239)
|
|
|
|
at com.android.server.am.TaskChangeNotificationController.lambda$new$0(TaskChangeNotificationController.java:70)
|
|
|
|
at com.android.server.am.-$$Lambda$TaskChangeNotificationController$kftD881t3KfWCASQEbeTkieVI2M.accept(Unknown Source:0)
|
|
|
|
at com.android.server.am.TaskChangeNotificationController.forAllLocalListeners(TaskChangeNotificationController.java:263)
|
|
|
|
at com.android.server.am.TaskChangeNotificationController.notifyTaskStackChanged(TaskChangeNotificationController.java:276)
|
|
|
|
*/
|
|
|
|
}
|
2019-07-10 15:58:26 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
else
|
|
|
|
start.execute(this, new Bundle(), "main:accounts");
|
2018-08-10 13:32:07 +00:00
|
|
|
} else {
|
2019-03-27 08:08:06 +00:00
|
|
|
// Enable compact view on small screens
|
2019-08-11 16:23:32 +00:00
|
|
|
if (!getResources().getConfiguration().isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE))
|
2019-03-26 19:48:26 +00:00
|
|
|
prefs.edit().putBoolean("compact", true).apply();
|
|
|
|
|
2018-08-10 13:32:07 +00:00
|
|
|
setTheme(R.style.AppThemeLight);
|
2018-10-30 13:47:10 +00:00
|
|
|
super.onCreate(savedInstanceState);
|
2018-08-10 13:32:07 +00:00
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
|
|
|
|
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
|
|
|
fragmentTransaction.replace(R.id.content_frame, new FragmentEula()).addToBackStack("eula");
|
|
|
|
fragmentTransaction.commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
|
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackStackChanged() {
|
|
|
|
int count = getSupportFragmentManager().getBackStackEntryCount();
|
|
|
|
if (count == 0)
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
|
|
|
if ("eula".equals(key))
|
|
|
|
if (prefs.getBoolean(key, false))
|
|
|
|
recreate();
|
|
|
|
}
|
|
|
|
}
|