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
|
|
|
|
|
|
|
Copyright 2018 by Marcel Bokhorst (M66B)
|
|
|
|
*/
|
|
|
|
|
2018-08-10 13:32:07 +00:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.PreferenceManager;
|
2018-09-09 06:09:59 +00:00
|
|
|
import android.util.Log;
|
2018-08-10 13:32:07 +00:00
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.fragment.app.FragmentManager;
|
|
|
|
import androidx.fragment.app.FragmentTransaction;
|
|
|
|
import androidx.lifecycle.Observer;
|
|
|
|
|
|
|
|
public class ActivityMain extends AppCompatActivity implements FragmentManager.OnBackStackChangedListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
getSupportFragmentManager().addOnBackStackChangedListener(this);
|
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
|
|
|
|
2018-09-09 06:09:59 +00:00
|
|
|
if (!Helper.isPlayStoreInstall(this)) {
|
|
|
|
Log.i(Helper.TAG, "Third party install");
|
|
|
|
prefs.edit().putBoolean("play_store", false).apply();
|
|
|
|
}
|
|
|
|
|
2018-08-10 13:32:07 +00:00
|
|
|
if (prefs.getBoolean("eula", false)) {
|
|
|
|
DB.getInstance(this).account().liveAccounts(true).observe(this, new Observer<List<EntityAccount>>() {
|
|
|
|
@Override
|
|
|
|
public void onChanged(@Nullable List<EntityAccount> accounts) {
|
2018-08-12 15:31:43 +00:00
|
|
|
if (accounts == null || accounts.size() == 0)
|
2018-08-10 13:32:07 +00:00
|
|
|
startActivity(new Intent(ActivityMain.this, ActivitySetup.class));
|
|
|
|
else {
|
|
|
|
startActivity(new Intent(ActivityMain.this, ActivityView.class));
|
2018-10-13 13:30:00 +00:00
|
|
|
ServiceSynchronize.init(ActivityMain.this);
|
2018-08-10 13:32:07 +00:00
|
|
|
}
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
setTheme(R.style.AppThemeLight);
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|