Simplified setup, added debug setting

pull/12/merge
M66B 6 years ago
parent 80ca58d2a2
commit 27fef56a77

@ -55,9 +55,7 @@ public class FragmentSetup extends FragmentEx {
private TextView tvPermissionsDone; private TextView tvPermissionsDone;
private CheckBox cbDarkTheme; private CheckBox cbDarkTheme;
private CheckBox cbDebug;
private Button btnAccountManage;
private Button btnIdentityManage;
private ExecutorService executor = Executors.newCachedThreadPool(); private ExecutorService executor = Executors.newCachedThreadPool();
@ -85,77 +83,26 @@ 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);
cbDebug = view.findViewById(R.id.cbDebug);
btnAccountManage = view.findViewById(R.id.btnAccountManage);
btnIdentityManage = view.findViewById(R.id.btnIdentityManage);
// 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 fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("account"); fragmentTransaction.replace(R.id.content_frame, new FragmentAccounts()).addToBackStack("accounts");
fragmentTransaction.commit(); fragmentTransaction.commit();
btnAccount.setEnabled(true);
pbAccount.setVisibility(View.GONE);
}
}
});
} }
}); });
btnIdentity.setOnClickListener(new View.OnClickListener() { btnIdentity.setOnClickListener(new View.OnClickListener() {
private boolean once;
@Override @Override
public void onClick(View view) { 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 fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("identity"); fragmentTransaction.replace(R.id.content_frame, new FragmentIdentities()).addToBackStack("identities");
fragmentTransaction.commit(); fragmentTransaction.commit();
} }
btnIdentity.setEnabled(true);
pbIdentity.setVisibility(View.GONE);
}
});
}
}); });
btnPermissions.setOnClickListener(new View.OnClickListener() { btnPermissions.setOnClickListener(new View.OnClickListener() {
@ -165,27 +112,8 @@ public class FragmentSetup extends FragmentEx {
} }
}); });
btnAccountManage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//getFragmentManager().popBackStack();
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, new FragmentAccounts()).addToBackStack("accounts");
fragmentTransaction.commit();
}
});
btnIdentityManage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//getFragmentManager().popBackStack();
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, new FragmentIdentities()).addToBackStack("identities");
fragmentTransaction.commit();
}
});
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() {

@ -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 <CheckBox
android:id="@+id/btnAccountManage" android:id="@+id/cbDebug"
style="?android:attr/buttonStyleSmall"
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:text="@string/title_setup_debug"
android:minWidth="0dp"
android:text="@string/title_setup_account_manage"
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>

@ -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_identity">Manage identities</string>
<string name="title_setup_indentity">Configure identity</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