mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-03 11:28:41 +01:00
Use main switcher activity, small improvements
- hosts EULA - goto either setup or messages
This commit is contained in:
68
app/src/main/java/eu/faircode/email/ActivityMain.java
Normal file
68
app/src/main/java/eu/faircode/email/ActivityMain.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package eu.faircode.email;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
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);
|
||||
|
||||
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) {
|
||||
if (accounts.size() == 0)
|
||||
startActivity(new Intent(ActivityMain.this, ActivitySetup.class));
|
||||
else {
|
||||
startActivity(new Intent(ActivityMain.this, ActivityView.class));
|
||||
ServiceSynchronize.start(ActivityMain.this);
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_setup);
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
||||
|
||||
getSupportFragmentManager().addOnBackStackChangedListener(this);
|
||||
|
||||
|
||||
@@ -23,11 +23,9 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
@@ -56,7 +54,7 @@ import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
public class ActivityView extends ActivityBase implements FragmentManager.OnBackStackChangedListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
public class ActivityView extends ActivityBase implements FragmentManager.OnBackStackChangedListener {
|
||||
private boolean newIntent = false;
|
||||
private DrawerLayout drawerLayout;
|
||||
private ListView drawerList;
|
||||
@@ -66,14 +64,15 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
|
||||
static final int LOADER_ACCOUNT_PUT = 2;
|
||||
static final int LOADER_IDENTITY_PUT = 3;
|
||||
static final int LOADER_FOLDER_PUT = 4;
|
||||
static final int LOADER_MESSAGE_SEEN = 5;
|
||||
static final int LOADER_MESSAGE_EDIT = 6;
|
||||
static final int LOADER_MESSAGE_SPAM = 7;
|
||||
static final int LOADER_MESSAGE_TRASH = 8;
|
||||
static final int LOADER_MESSAGE_MOVE = 9;
|
||||
static final int LOADER_MESSAGE_ARCHIVE = 10;
|
||||
static final int LOADER_SEEN_UNTIL = 11;
|
||||
static final int LOADER_DEBUG_INFO = 12;
|
||||
static final int LOADER_MESSAGE_VIEW = 5;
|
||||
static final int LOADER_MESSAGE_SEEN = 6;
|
||||
static final int LOADER_MESSAGE_EDIT = 7;
|
||||
static final int LOADER_MESSAGE_SPAM = 8;
|
||||
static final int LOADER_MESSAGE_TRASH = 9;
|
||||
static final int LOADER_MESSAGE_MOVE = 10;
|
||||
static final int LOADER_MESSAGE_ARCHIVE = 11;
|
||||
static final int LOADER_SEEN_UNTIL = 12;
|
||||
static final int LOADER_DEBUG_INFO = 13;
|
||||
|
||||
static final int REQUEST_VIEW = 1;
|
||||
static final int REQUEST_UNSEEN = 2;
|
||||
@@ -132,7 +131,6 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
|
||||
}
|
||||
});
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
|
||||
getSupportFragmentManager().addOnBackStackChangedListener(this);
|
||||
|
||||
DB.getInstance(this).account().liveAccounts().observe(this, new Observer<List<EntityAccount>>() {
|
||||
@@ -162,8 +160,17 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
|
||||
}
|
||||
});
|
||||
|
||||
if (getSupportFragmentManager().getFragments().size() == 0)
|
||||
init();
|
||||
if (getSupportFragmentManager().getFragments().size() == 0) {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("folder", -1);
|
||||
|
||||
FragmentMessages fragment = new FragmentMessages();
|
||||
fragment.setArguments(args);
|
||||
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("unified");
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
checkIntent(getIntent());
|
||||
}
|
||||
@@ -173,14 +180,13 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
|
||||
Log.i(Helper.TAG, "View post create");
|
||||
super.onPostCreate(savedInstanceState);
|
||||
drawerToggle.syncState();
|
||||
syncState();
|
||||
}
|
||||
|
||||
private void syncState() {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
boolean eula = prefs.getBoolean("eula", false);
|
||||
int count = getSupportFragmentManager().getBackStackEntryCount();
|
||||
drawerToggle.setDrawerIndicatorEnabled(count == 1 && eula);
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
newIntent = true;
|
||||
checkIntent(intent);
|
||||
super.onNewIntent(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -209,29 +215,19 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
|
||||
lbm.unregisterReceiver(receiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
newIntent = true;
|
||||
checkIntent(intent);
|
||||
super.onNewIntent(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
Log.i(Helper.TAG, "View configuration changed");
|
||||
super.onConfigurationChanged(newConfig);
|
||||
drawerToggle.onConfigurationChanged(newConfig);
|
||||
syncState();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
Log.i(Helper.TAG, "View destroyed");
|
||||
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (drawerLayout.isDrawerOpen(drawerList))
|
||||
@@ -245,14 +241,8 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
|
||||
int count = getSupportFragmentManager().getBackStackEntryCount();
|
||||
if (count == 0)
|
||||
finish();
|
||||
syncState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
||||
super.onSharedPreferenceChanged(prefs, key);
|
||||
if ("eula".equals(key))
|
||||
init();
|
||||
else
|
||||
drawerToggle.setDrawerIndicatorEnabled(count == 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -300,39 +290,6 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
|
||||
}
|
||||
}
|
||||
|
||||
private void init() {
|
||||
invalidateOptionsMenu();
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
if (prefs.getBoolean("eula", false)) {
|
||||
getSupportFragmentManager().popBackStack(); // eula
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("folder", -1);
|
||||
|
||||
FragmentMessages fragment = new FragmentMessages();
|
||||
fragment.setArguments(args);
|
||||
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("unified");
|
||||
fragmentTransaction.commit();
|
||||
|
||||
DB.getInstance(this).account().liveAccounts(true).observe(this, new Observer<List<EntityAccount>>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable List<EntityAccount> accounts) {
|
||||
if (accounts.size() == 0)
|
||||
startActivity(new Intent(ActivityView.this, ActivitySetup.class));
|
||||
else
|
||||
ServiceSynchronize.start(ActivityView.this);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
fragmentTransaction.replace(R.id.content_frame, new FragmentEula()).addToBackStack("eula");
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
}
|
||||
|
||||
private Intent getIntentFAQ() {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse("https://github.com/M66B/open-source-email/blob/master/FAQ.md"));
|
||||
@@ -432,6 +389,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("messages");
|
||||
fragmentTransaction.commit();
|
||||
|
||||
} else if (ACTION_VIEW_MESSAGE.equals(intent.getAction())) {
|
||||
|
||||
new SimpleLoader() {
|
||||
@@ -476,7 +434,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
|
||||
} else
|
||||
Toast.makeText(ActivityView.this, result.ex.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}.load(ActivityView.this, 0000, intent.getExtras());
|
||||
}.load(ActivityView.this, LOADER_MESSAGE_VIEW, intent.getExtras());
|
||||
|
||||
} else if (ACTION_EDIT_FOLDER.equals(intent.getAction())) {
|
||||
FragmentFolder fragment = new FragmentFolder();
|
||||
|
||||
@@ -22,6 +22,7 @@ package eu.faircode.email;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -35,6 +36,7 @@ import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -139,6 +141,7 @@ public class FragmentAccount extends FragmentEx {
|
||||
etName.setText(provider.name);
|
||||
etHost.setText(provider.imap_host);
|
||||
etPort.setText(Integer.toString(provider.imap_port));
|
||||
etUser.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -474,6 +477,12 @@ public class FragmentAccount extends FragmentEx {
|
||||
|
||||
grpFolders.setVisibility(View.VISIBLE);
|
||||
btnSave.setVisibility(View.VISIBLE);
|
||||
new Handler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
((ScrollView) view).smoothScrollTo(0, btnSave.getBottom());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Log.w(Helper.TAG, data.ex + "\n" + Log.getStackTraceString(data.ex));
|
||||
Toast.makeText(getContext(), Helper.formatThrowable(data.ex), Toast.LENGTH_LONG).show();
|
||||
|
||||
@@ -35,6 +35,8 @@ public class FragmentEula extends FragmentEx {
|
||||
@Override
|
||||
@Nullable
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
setSubtitle(R.string.title_eula);
|
||||
|
||||
View view = inflater.inflate(R.layout.fragment_eula, container, false);
|
||||
|
||||
Button btnAgree = view.findViewById(R.id.btnOk);
|
||||
|
||||
@@ -277,11 +277,12 @@ public class FragmentIdentity extends FragmentEx {
|
||||
btnSave.setEnabled(true);
|
||||
pbWait.setVisibility(View.GONE);
|
||||
|
||||
etName.requestFocus();
|
||||
|
||||
db.account().liveAccounts().removeObservers(getViewLifecycleOwner());
|
||||
db.account().liveAccounts().observe(getViewLifecycleOwner(), new Observer<List<EntityAccount>>() {
|
||||
@Override
|
||||
public void onChanged(List<EntityAccount> accounts) {
|
||||
|
||||
EntityAccount unselected = new EntityAccount();
|
||||
unselected.id = -1L;
|
||||
unselected.name = "";
|
||||
|
||||
@@ -20,6 +20,7 @@ package eu.faircode.email;
|
||||
*/
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
@@ -55,6 +56,8 @@ public class FragmentSetup extends FragmentEx {
|
||||
private Button btnPermissions;
|
||||
private TextView tvPermissionsDone;
|
||||
|
||||
private Button btnMessages;
|
||||
|
||||
private CheckBox cbDarkTheme;
|
||||
private CheckBox cbDebug;
|
||||
|
||||
@@ -83,6 +86,8 @@ 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);
|
||||
|
||||
@@ -113,6 +118,14 @@ 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");
|
||||
@@ -145,6 +158,7 @@ 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++)
|
||||
@@ -182,6 +196,7 @@ 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);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user