Revise account layout

This commit is contained in:
M66B 2018-12-26 11:34:05 +00:00
parent 7590a6ffae
commit b5b805672d
3 changed files with 147 additions and 127 deletions

View File

@ -43,9 +43,9 @@ public class EntityAccount {
@PrimaryKey(autoGenerate = true)
public Long id;
public String name;
public String signature; // obsolete
public String prefix; // namespace
@NonNull
public Integer auth_type;
@NonNull
public String host; // IMAP
@NonNull
@ -58,19 +58,23 @@ public class EntityAccount {
public String user;
@NonNull
public String password;
@NonNull
public Integer auth_type;
public String name;
public String signature; // obsolete
public Integer color;
@NonNull
public Boolean synchronize;
@NonNull
public Boolean primary;
@NonNull
public Boolean browse;
public Integer color;
@NonNull
public Boolean notify;
@NonNull
public Boolean browse;
@NonNull
public Integer poll_interval; // keep-alive interval
public String prefix; // namespace
public Long created;
public Boolean tbd;
public String state;

View File

@ -95,6 +95,7 @@ public class FragmentAccount extends FragmentEx {
private EditText etDomain;
private Button btnAutoConfig;
private Button btnAuthorize;
private EditText etHost;
private CheckBox cbStartTls;
private CheckBox cbInsecure;
@ -102,26 +103,22 @@ public class FragmentAccount extends FragmentEx {
private EditText etUser;
private TextInputLayout tilPassword;
private Button btnAuthorize;
private Button btnAdvanced;
private TextView tvName;
private EditText etName;
private EditText etPrefix;
private Button btnColor;
private View vwColor;
private ImageView ibColorDefault;
private CheckBox cbNotify;
private Button btnAdvanced;
private CheckBox cbSynchronize;
private CheckBox cbPrimary;
private CheckBox cbNotify;
private CheckBox cbBrowse;
private EditText etInterval;
private EditText etPrefix;
private Button btnCheck;
private ProgressBar pbCheck;
private TextView tvIdle;
private ArrayAdapter<EntityFolder> adapter;
@ -170,6 +167,7 @@ public class FragmentAccount extends FragmentEx {
etDomain = view.findViewById(R.id.etDomain);
btnAutoConfig = view.findViewById(R.id.btnAutoConfig);
btnAuthorize = view.findViewById(R.id.btnAuthorize);
etHost = view.findViewById(R.id.etHost);
etPort = view.findViewById(R.id.etPort);
cbStartTls = view.findViewById(R.id.cbStartTls);
@ -177,22 +175,19 @@ public class FragmentAccount extends FragmentEx {
etUser = view.findViewById(R.id.etUser);
tilPassword = view.findViewById(R.id.tilPassword);
btnAuthorize = view.findViewById(R.id.btnAuthorize);
btnAdvanced = view.findViewById(R.id.btnAdvanced);
etName = view.findViewById(R.id.etName);
tvName = view.findViewById(R.id.tvName);
etPrefix = view.findViewById(R.id.etPrefix);
btnColor = view.findViewById(R.id.btnColor);
vwColor = view.findViewById(R.id.vwColor);
ibColorDefault = view.findViewById(R.id.ibColorDefault);
cbNotify = view.findViewById(R.id.cbNotify);
btnAdvanced = view.findViewById(R.id.btnAdvanced);
cbSynchronize = view.findViewById(R.id.cbSynchronize);
cbPrimary = view.findViewById(R.id.cbPrimary);
cbNotify = view.findViewById(R.id.cbNotify);
cbBrowse = view.findViewById(R.id.cbBrowse);
etInterval = view.findViewById(R.id.etInterval);
etPrefix = view.findViewById(R.id.etPrefix);
btnCheck = view.findViewById(R.id.btnCheck);
pbCheck = view.findViewById(R.id.pbCheck);
@ -259,6 +254,23 @@ public class FragmentAccount extends FragmentEx {
}
});
etDomain.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence text, int start, int before, int count) {
btnAutoConfig.setEnabled(text.length() > 0);
}
@Override
public void afterTextChanged(Editable s) {
}
});
btnAutoConfig.setEnabled(false);
btnAutoConfig.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -271,8 +283,10 @@ public class FragmentAccount extends FragmentEx {
new SimpleTask<SRVRecord>() {
@Override
protected SRVRecord onLoad(Context context, Bundle args) throws Throwable {
String domain = args.getString("domain");
Record[] records = new Lookup("_imaps._tcp." + domain, Type.SRV).run();
String dns = "_imaps._tcp." + args.getString("domain");
Log.i("Lookup dns=" + dns);
Record[] records = new Lookup(dns, Type.SRV).run();
Log.i("Found dns=" + (records == null ? -1 : records.length));
if (records != null)
for (int i = 0; i < records.length; i++) {
SRVRecord srv = (SRVRecord) records[i];
@ -330,39 +344,6 @@ public class FragmentAccount extends FragmentEx {
}
});
btnAuthorize.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Provider provider = (Provider) spProvider.getSelectedItem();
Log.i("Authorize " + provider);
if ("com.google".equals(provider.type)) {
String permission = Manifest.permission.GET_ACCOUNTS;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O &&
ContextCompat.checkSelfPermission(getContext(), permission) != PackageManager.PERMISSION_GRANTED) {
Log.i("Requesting " + permission);
requestPermissions(new String[]{permission}, ActivitySetup.REQUEST_PERMISSION);
} else
selectAccount();
}
}
});
btnAdvanced.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int visibility = (grpAdvanced.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
grpAdvanced.setVisibility(visibility);
if (visibility == View.VISIBLE)
new Handler().post(new Runnable() {
@Override
public void run() {
((ScrollView) view).smoothScrollTo(0, tvName.getTop());
}
});
}
});
vwColor.setBackgroundColor(color);
btnColor.setOnClickListener(new View.OnClickListener() {
@Override
@ -394,6 +375,46 @@ public class FragmentAccount extends FragmentEx {
}
});
btnAuthorize.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Provider provider = (Provider) spProvider.getSelectedItem();
Log.i("Authorize " + provider);
if ("com.google".equals(provider.type)) {
String permission = Manifest.permission.GET_ACCOUNTS;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O &&
ContextCompat.checkSelfPermission(getContext(), permission) != PackageManager.PERMISSION_GRANTED) {
Log.i("Requesting " + permission);
requestPermissions(new String[]{permission}, ActivitySetup.REQUEST_PERMISSION);
} else
selectAccount();
}
}
});
btnAdvanced.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int visibility = (grpAdvanced.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
grpAdvanced.setVisibility(visibility);
if (visibility == View.VISIBLE)
new Handler().post(new Runnable() {
@Override
public void run() {
((ScrollView) view).smoothScrollTo(0, cbPrimary.getTop());
}
});
}
});
cbSynchronize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
cbPrimary.setEnabled(checked);
}
});
cbNotify.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@ -408,13 +429,6 @@ public class FragmentAccount extends FragmentEx {
}
});
cbSynchronize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
cbPrimary.setEnabled(checked);
}
});
btnCheck.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -594,23 +608,24 @@ public class FragmentAccount extends FragmentEx {
Bundle args = new Bundle();
args.putLong("id", id);
args.putInt("auth_type", authorized == null ? Helper.AUTH_TYPE_PASSWORD : provider.getAuthType());
args.putString("host", etHost.getText().toString());
args.putBoolean("starttls", cbStartTls.isChecked());
args.putBoolean("insecure", cbInsecure.isChecked());
args.putString("port", etPort.getText().toString());
args.putString("user", etUser.getText().toString());
args.putString("password", tilPassword.getEditText().getText().toString());
args.putInt("auth_type", authorized == null ? Helper.AUTH_TYPE_PASSWORD : provider.getAuthType());
args.putString("name", etName.getText().toString());
args.putString("prefix", etPrefix.getText().toString());
args.putInt("color", color);
args.putBoolean("notify", cbNotify.isChecked());
args.putBoolean("synchronize", cbSynchronize.isChecked());
args.putBoolean("primary", cbPrimary.isChecked());
args.putBoolean("notify", cbNotify.isChecked());
args.putBoolean("browse", cbBrowse.isChecked());
args.putString("interval", etInterval.getText().toString());
args.putString("prefix", etPrefix.getText().toString());
args.putSerializable("drafts", drafts);
args.putSerializable("sent", sent);
@ -622,23 +637,24 @@ public class FragmentAccount extends FragmentEx {
@Override
protected Void onLoad(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
int auth_type = args.getInt("auth_type");
String host = args.getString("host");
boolean starttls = args.getBoolean("starttls");
boolean insecure = args.getBoolean("insecure");
String port = args.getString("port");
String user = args.getString("user");
String password = args.getString("password");
int auth_type = args.getInt("auth_type");
String name = args.getString("name");
String prefix = args.getString("prefix");
Integer color = args.getInt("color");
boolean notify = args.getBoolean("notify");
boolean synchronize = args.getBoolean("synchronize");
boolean primary = args.getBoolean("primary");
boolean notify = args.getBoolean("notify");
boolean browse = args.getBoolean("browse");
String interval = args.getString("interval");
String prefix = args.getString("prefix");
EntityFolder drafts = (EntityFolder) args.getSerializable("drafts");
EntityFolder sent = (EntityFolder) args.getSerializable("sent");
@ -659,10 +675,10 @@ public class FragmentAccount extends FragmentEx {
if (synchronize && drafts == null)
throw new Throwable(context.getString(R.string.title_no_drafts));
if (TextUtils.isEmpty(prefix))
prefix = null;
if (Color.TRANSPARENT == color)
color = null;
if (TextUtils.isEmpty(prefix))
prefix = null;
long now = new Date().getTime();
Character separator = null;
@ -713,23 +729,23 @@ public class FragmentAccount extends FragmentEx {
if (account == null)
account = new EntityAccount();
account.auth_type = auth_type;
account.host = host;
account.starttls = starttls;
account.insecure = insecure;
account.port = Integer.parseInt(port);
account.user = user;
account.password = password;
account.auth_type = auth_type;
account.name = name;
account.prefix = prefix;
account.color = color;
account.notify = notify;
account.synchronize = synchronize;
account.primary = (account.synchronize && primary);
account.notify = notify;
account.browse = browse;
account.poll_interval = Integer.parseInt(interval);
account.prefix = prefix;
if (!update)
account.created = now;

View File

@ -212,18 +212,6 @@
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/btnAdvanced"
style="@style/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:minWidth="0dp"
android:minHeight="0dp"
android:text="@string/title_setup_advanced"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tilPassword" />
<!-- name -->
<TextView
@ -234,7 +222,7 @@
android:text="@string/title_account_name"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnAdvanced" />
app:layout_constraintTop_toBottomOf="@id/tilPassword" />
<TextView
android:id="@+id/tvNameRemark"
@ -257,37 +245,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvNameRemark" />
<TextView
android:id="@+id/tvPrefix"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_account_prefix"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etName" />
<TextView
android:id="@+id/tvPrefixRemark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:text="@string/title_account_prefix_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvPrefix" />
<EditText
android:id="@+id/etPrefix"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/title_optional"
android:inputType="text"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvPrefixRemark" />
<Button
android:id="@+id/btnColor"
style="@style/buttonStyleSmall"
@ -298,7 +255,7 @@
android:minHeight="0dp"
android:text="@string/title_account_color"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etPrefix" />
app:layout_constraintTop_toBottomOf="@id/etName" />
<View
android:id="@+id/vwColor"
@ -320,12 +277,15 @@
app:layout_constraintStart_toEndOf="@id/vwColor"
app:layout_constraintTop_toTopOf="@id/btnColor" />
<CheckBox
android:id="@+id/cbNotify"
<Button
android:id="@+id/btnAdvanced"
style="@style/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_account_notify"
android:minWidth="0dp"
android:minHeight="0dp"
android:text="@string/title_setup_advanced"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnColor" />
@ -336,7 +296,7 @@
android:layout_marginTop="12dp"
android:text="@string/title_synchronize_account"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbNotify" />
app:layout_constraintTop_toBottomOf="@id/btnAdvanced" />
<CheckBox
android:id="@+id/cbPrimary"
@ -347,6 +307,15 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbSynchronize" />
<CheckBox
android:id="@+id/cbNotify"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_account_notify"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbPrimary" />
<CheckBox
android:id="@+id/cbBrowse"
android:layout_width="wrap_content"
@ -354,7 +323,7 @@
android:layout_marginTop="12dp"
android:text="@string/title_advanced_browse"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbPrimary" />
app:layout_constraintTop_toBottomOf="@id/cbNotify" />
<TextView
android:id="@+id/tvBrowseHint"
@ -388,6 +357,37 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvInterval" />
<TextView
android:id="@+id/tvPrefix"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_account_prefix"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etInterval" />
<TextView
android:id="@+id/tvPrefixRemark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:text="@string/title_account_prefix_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvPrefix" />
<EditText
android:id="@+id/etPrefix"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/title_optional"
android:inputType="text"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvPrefixRemark" />
<!-- check -->
<Button
@ -397,7 +397,7 @@
android:layout_marginTop="12dp"
android:text="@string/title_check"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etInterval" />
app:layout_constraintTop_toBottomOf="@id/etPrefix" />
<ProgressBar
android:id="@+id/pbCheck"
@ -573,13 +573,13 @@
android:id="@+id/grpAuthorize"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvUser,etUser,tvPassword,tilPassword" />
app:constraint_referenced_ids="tvUser,etUser,tvPassword,tilPassword,tvName,tvNameRemark,etName,btnColor,vwColor,ibColorDefault" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpAdvanced"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvName,tvNameRemark,etName,tvPrefix,tvPrefixRemark,etPrefix,btnColor,vwColor,ibColorDefault,cbNotify,cbSynchronize,cbPrimary,cbBrowse,tvBrowseHint,tvInterval,etInterval" />
app:constraint_referenced_ids="tvPrefix,tvPrefixRemark,etPrefix,cbNotify,cbSynchronize,cbPrimary,cbBrowse,tvBrowseHint,tvInterval,etInterval" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpFolders"