Browse Source

Simplified setup, added debug setting

main
M66B 6 years ago
parent
commit
27fef56a77
3 changed files with 25 additions and 107 deletions
  1. +18
    -82
      app/src/main/java/eu/faircode/email/FragmentSetup.java
  2. +4
    -21
      app/src/main/res/layout/fragment_setup.xml
  3. +3
    -4
      app/src/main/res/values/strings.xml

+ 18
- 82
app/src/main/java/eu/faircode/email/FragmentSetup.java View File

@ -55,9 +55,7 @@ public class FragmentSetup extends FragmentEx {
private TextView tvPermissionsDone; private TextView tvPermissionsDone;
private CheckBox cbDarkTheme; private CheckBox cbDarkTheme;
private Button btnAccountManage;
private Button btnIdentityManage;
private CheckBox cbDebug;
private ExecutorService executor = Executors.newCachedThreadPool(); private ExecutorService executor = Executors.newCachedThreadPool();
@ -85,107 +83,37 @@ public class FragmentSetup extends FragmentEx {
tvPermissionsDone = view.findViewById(R.id.tvPermissionsDone); tvPermissionsDone = view.findViewById(R.id.tvPermissionsDone);
cbDarkTheme = view.findViewById(R.id.cbDarkTheme); cbDarkTheme = view.findViewById(R.id.cbDarkTheme);
btnAccountManage = view.findViewById(R.id.btnAccountManage);
btnIdentityManage = view.findViewById(R.id.btnIdentityManage);
cbDebug = view.findViewById(R.id.cbDebug);
// Wire controls // Wire controls
btnAccount.setOnClickListener(new View.OnClickListener() { btnAccount.setOnClickListener(new View.OnClickListener() {
private boolean once;
@Override @Override
public void onClick(View view) { public void onClick(View view) {
once = false;
btnAccount.setEnabled(false);
pbAccount.setVisibility(View.VISIBLE);
DB.getInstance(getContext()).account().liveFirstAccount().observe(FragmentSetup.this, new Observer<EntityAccount>() {
@Override
public void onChanged(@Nullable EntityAccount account) {
if (!once) {
once = true;
Bundle args = new Bundle();
if (account != null)
args.putLong("id", account.id);
FragmentAccount fragment = new FragmentAccount();
fragment.setArguments(args);
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("account");
fragmentTransaction.commit();
btnAccount.setEnabled(true);
pbAccount.setVisibility(View.GONE);
}
}
});
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, new FragmentAccounts()).addToBackStack("accounts");
fragmentTransaction.commit();
} }
}); });
btnIdentity.setOnClickListener(new View.OnClickListener() { btnIdentity.setOnClickListener(new View.OnClickListener() {
private boolean once;
@Override
public void onClick(View view) {
once = false;
btnIdentity.setEnabled(false);
pbIdentity.setVisibility(View.VISIBLE);
DB.getInstance(getContext()).identity().liveFirstIdentity().observe(FragmentSetup.this, new Observer<EntityIdentity>() {
@Override
public void onChanged(@Nullable EntityIdentity identity) {
if (!once) {
once = true;
Bundle args = new Bundle();
if (identity != null)
args.putLong("id", identity.id);
FragmentIdentity fragment = new FragmentIdentity();
fragment.setArguments(args);
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("identity");
fragmentTransaction.commit();
}
btnIdentity.setEnabled(true);
pbIdentity.setVisibility(View.GONE);
}
});
}
});
btnPermissions.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
requestPermissions(permissions, 1);
}
});
btnAccountManage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//getFragmentManager().popBackStack();
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, new FragmentAccounts()).addToBackStack("accounts");
fragmentTransaction.replace(R.id.content_frame, new FragmentIdentities()).addToBackStack("identities");
fragmentTransaction.commit(); fragmentTransaction.commit();
} }
}); });
btnIdentityManage.setOnClickListener(new View.OnClickListener() {
btnPermissions.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
//getFragmentManager().popBackStack();
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, new FragmentIdentities()).addToBackStack("identities");
fragmentTransaction.commit();
requestPermissions(permissions, 1);
} }
}); });
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
String theme = prefs.getString("theme", "light"); String theme = prefs.getString("theme", "light");
boolean dark = "dark".equals(theme); boolean dark = "dark".equals(theme);
cbDarkTheme.setTag(dark); cbDarkTheme.setTag(dark);
@ -201,6 +129,14 @@ public class FragmentSetup extends FragmentEx {
} }
}); });
cbDebug.setChecked(prefs.getBoolean("debug", false));
cbDebug.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("debug", checked).apply();
}
});
// Initialize // Initialize
pbAccount.setVisibility(View.GONE); pbAccount.setVisibility(View.GONE);
@ -231,7 +167,7 @@ public class FragmentSetup extends FragmentEx {
onRequestPermissionsResult(0, permissions, grantResults); onRequestPermissionsResult(0, permissions, grantResults);
// Creat outbox
// Create outbox
executor.submit(new Runnable() { executor.submit(new Runnable() {
@Override @Override
public void run() { public void run() {


+ 4
- 21
app/src/main/res/layout/fragment_setup.xml View File

@ -62,7 +62,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="24dp" android:layout_marginTop="24dp"
android:text="@string/title_setup_indentity"
android:text="@string/title_setup_identity"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
@ -146,32 +146,15 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvPermissionsDone" /> app:layout_constraintTop_toBottomOf="@id/tvPermissionsDone" />
<Button
android:id="@+id/btnAccountManage"
style="?android:attr/buttonStyleSmall"
<CheckBox
android:id="@+id/cbDebug"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="24dp" android:layout_marginTop="24dp"
android:minHeight="0dp"
android:minWidth="0dp"
android:text="@string/title_setup_account_manage"
android:text="@string/title_setup_debug"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbDarkTheme" /> app:layout_constraintTop_toBottomOf="@id/cbDarkTheme" />
<Button
android:id="@+id/btnIdentityManage"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:minHeight="0dp"
android:minWidth="0dp"
android:text="@string/title_setup_identity_manage"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnAccountManage" />
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>
</ScrollView> </ScrollView>

+ 3
- 4
app/src/main/res/values/strings.xml View File

@ -27,16 +27,15 @@
<string name="title_edit_folder">Edit folder</string> <string name="title_edit_folder">Edit folder</string>
<string name="title_setup">Setup</string> <string name="title_setup">Setup</string>
<string name="title_setup_account">Configure account</string>
<string name="title_setup_account">Manage accounts</string>
<string name="title_setup_account_remark">To receive email</string> <string name="title_setup_account_remark">To receive email</string>
<string name="title_setup_account_manage">Manage accounts</string>
<string name="title_setup_indentity">Configure identity</string>
<string name="title_setup_identity">Manage identities</string>
<string name="title_setup_identity_remark">To send email</string> <string name="title_setup_identity_remark">To send email</string>
<string name="title_setup_identity_manage">Manage identities</string>
<string name="title_setup_permissions">Grant permissions</string> <string name="title_setup_permissions">Grant permissions</string>
<string name="title_setup_permissions_remark">To read contacts (optional)</string> <string name="title_setup_permissions_remark">To read contacts (optional)</string>
<string name="title_setup_done">Done</string> <string name="title_setup_done">Done</string>
<string name="title_setup_dark_theme">Dark theme</string> <string name="title_setup_dark_theme">Dark theme</string>
<string name="title_setup_debug">Debug</string>
<string name="title_name">Your name</string> <string name="title_name">Your name</string>
<string name="title_email">Your email address</string> <string name="title_email">Your email address</string>


Loading…
Cancel
Save