Use main switcher activity, small improvements

- hosts EULA
- goto either setup or messages
pull/30/head
M66B 6 years ago
parent 54f8bf357f
commit d48c2cd87a

@ -5,7 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- uses-permission android:name="android.permission.READ_CONTACTS" /-->
<!-- uses-permission android:name="android.permission.READ_CONTACTS" / -->
<application
android:name=".ApplicationEx"
@ -26,13 +26,8 @@
android:value="false" />
<activity
android:name=".ActivitySetup"
android:launchMode="singleTop"
android:parentActivityName=".ActivityView" />
<activity
android:name=".ActivityView"
android:launchMode="singleTop">
android:name=".ActivityMain"
android:theme="@style/Theme.Transparent">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@ -40,6 +35,16 @@
</intent-filter>
</activity>
<activity
android:name=".ActivitySetup"
android:launchMode="singleTop"
android:parentActivityName=".ActivityMain" />
<activity
android:name=".ActivityView"
android:launchMode="singleTop"
android:parentActivityName=".ActivityMain" />
<activity
android:name=".ActivityCompose"
android:parentActivityName=".ActivityView" />

@ -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);
}
});

@ -1,12 +1,6 @@
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ActivityCompose">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.drawerlayout.widget.DrawerLayout>
tools:context=".ActivityCompose" />

@ -0,0 +1,6 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ActivityMain" />

@ -1,12 +1,6 @@
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ActivityCompose">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.drawerlayout.widget.DrawerLayout>
tools:context=".ActivitySetup" />

@ -219,9 +219,10 @@
<Spinner
android:id="@+id/spDrafts"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tvDrafts"
app:layout_constraintTop_toBottomOf="@id/btnCheck" />
@ -238,8 +239,9 @@
<Spinner
android:id="@+id/spSent"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tvSent"
app:layout_constraintTop_toBottomOf="@id/spDrafts" />
@ -256,8 +258,9 @@
<Spinner
android:id="@+id/spAll"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tvAll"
app:layout_constraintTop_toBottomOf="@id/spSent" />
@ -274,8 +277,9 @@
<Spinner
android:id="@+id/spTrash"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tvTrash"
app:layout_constraintTop_toBottomOf="@id/spAll" />
@ -292,8 +296,9 @@
<Spinner
android:id="@+id/spJunk"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tvJunk"
app:layout_constraintTop_toBottomOf="@id/spTrash" />

@ -135,6 +135,19 @@
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"
@ -144,7 +157,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvPermissionsDone" />
app:layout_constraintTop_toBottomOf="@id/btnMessages" />
<CheckBox
android:id="@+id/cbDebug"

@ -29,6 +29,7 @@
<string name="menu_faq">FAQ</string>
<string name="menu_about">About</string>
<string name="title_eula">End-user license agreement</string>
<string name="title_agree">I agree</string>
<string name="title_disagree">I disagree</string>
@ -48,6 +49,7 @@
<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 read contacts (optional)</string>
<string name="title_setup_messages">View messages</string>
<string name="title_setup_done">Done</string>
<string name="title_setup_dark_theme">Dark theme</string>
<string name="title_setup_debug">Debug</string>

@ -32,4 +32,13 @@
<item name="colorDrawerText">@color/darkColorDrawerText</item>
<item name="colorDrawerBackground">@color/darkColorDrawerBackground</item>
</style>
<style name="Theme.Transparent" parent="Theme.AppCompat">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>

Loading…
Cancel
Save