Simple email application for Android. Original source code: https://framagit.org/dystopia-project/simple-email
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.4 KiB

  1. package eu.faircode.email;
  2. /*
  3. This file is part of FairEmail.
  4. FairEmail is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. NetGuard is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
  14. Copyright 2018 by Marcel Bokhorst (M66B)
  15. */
  16. import android.content.Intent;
  17. import android.content.SharedPreferences;
  18. import android.os.Bundle;
  19. import android.preference.PreferenceManager;
  20. import android.util.Log;
  21. import java.util.List;
  22. import androidx.annotation.Nullable;
  23. import androidx.appcompat.app.AppCompatActivity;
  24. import androidx.fragment.app.FragmentManager;
  25. import androidx.fragment.app.FragmentTransaction;
  26. import androidx.lifecycle.Observer;
  27. public class ActivityMain extends AppCompatActivity implements FragmentManager.OnBackStackChangedListener, SharedPreferences.OnSharedPreferenceChangeListener {
  28. @Override
  29. protected void onCreate(Bundle savedInstanceState) {
  30. super.onCreate(savedInstanceState);
  31. getSupportFragmentManager().addOnBackStackChangedListener(this);
  32. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
  33. prefs.registerOnSharedPreferenceChangeListener(this);
  34. if (!Helper.isPlayStoreInstall(this)) {
  35. Log.i(Helper.TAG, "Third party install");
  36. prefs.edit().putBoolean("play_store", false).apply();
  37. }
  38. if (prefs.getBoolean("eula", false)) {
  39. DB.getInstance(this).account().liveAccounts(true).observe(this, new Observer<List<EntityAccount>>() {
  40. @Override
  41. public void onChanged(@Nullable List<EntityAccount> accounts) {
  42. if (accounts == null || accounts.size() == 0)
  43. startActivity(new Intent(ActivityMain.this, ActivitySetup.class));
  44. else {
  45. startActivity(new Intent(ActivityMain.this, ActivityView.class));
  46. ServiceSynchronize.init(ActivityMain.this);
  47. }
  48. finish();
  49. }
  50. });
  51. } else {
  52. setTheme(R.style.AppThemeLight);
  53. setContentView(R.layout.activity_main);
  54. FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
  55. fragmentTransaction.replace(R.id.content_frame, new FragmentEula()).addToBackStack("eula");
  56. fragmentTransaction.commit();
  57. }
  58. }
  59. @Override
  60. protected void onDestroy() {
  61. PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
  62. super.onDestroy();
  63. }
  64. @Override
  65. public void onBackStackChanged() {
  66. int count = getSupportFragmentManager().getBackStackEntryCount();
  67. if (count == 0)
  68. finish();
  69. }
  70. @Override
  71. public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
  72. if ("eula".equals(key))
  73. if (prefs.getBoolean(key, false))
  74. recreate();
  75. }
  76. }