Added Gmail/POP3 recent support

pull/208/head
M66B 2 years ago
parent db00417fb7
commit 8adf33ce9a

@ -48,6 +48,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ScrollView; import android.widget.ScrollView;
import android.widget.TextView; import android.widget.TextView;
@ -68,6 +69,7 @@ public class FragmentGmail extends FragmentBase {
private String personal; private String personal;
private String address; private String address;
private boolean pop; private boolean pop;
private boolean recent;
private boolean update; private boolean update;
private ViewGroup view; private ViewGroup view;
@ -79,6 +81,7 @@ public class FragmentGmail extends FragmentBase {
private TextView tvGranted; private TextView tvGranted;
private EditText etName; private EditText etName;
private CheckBox cbPop; private CheckBox cbPop;
private CheckBox cbRecent;
private CheckBox cbUpdate; private CheckBox cbUpdate;
private Button btnSelect; private Button btnSelect;
private ContentLoadingProgressBar pbSelect; private ContentLoadingProgressBar pbSelect;
@ -101,6 +104,7 @@ public class FragmentGmail extends FragmentBase {
personal = args.getString("personal"); personal = args.getString("personal");
address = args.getString("address"); address = args.getString("address");
pop = args.getBoolean("pop", false); pop = args.getBoolean("pop", false);
recent = args.getBoolean("recent", false);
update = args.getBoolean("update", true); update = args.getBoolean("update", true);
} }
@ -120,6 +124,7 @@ public class FragmentGmail extends FragmentBase {
tvGranted = view.findViewById(R.id.tvGranted); tvGranted = view.findViewById(R.id.tvGranted);
etName = view.findViewById(R.id.etName); etName = view.findViewById(R.id.etName);
cbPop = view.findViewById(R.id.cbPop); cbPop = view.findViewById(R.id.cbPop);
cbRecent = view.findViewById(R.id.cbRecent);
cbUpdate = view.findViewById(R.id.cbUpdate); cbUpdate = view.findViewById(R.id.cbUpdate);
btnSelect = view.findViewById(R.id.btnSelect); btnSelect = view.findViewById(R.id.btnSelect);
pbSelect = view.findViewById(R.id.pbSelect); pbSelect = view.findViewById(R.id.pbSelect);
@ -152,6 +157,13 @@ public class FragmentGmail extends FragmentBase {
} }
}); });
cbPop.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
cbRecent.setVisibility(checked ? View.VISIBLE : View.GONE);
}
});
btnSelect.setOnClickListener(new View.OnClickListener() { btnSelect.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -208,6 +220,8 @@ public class FragmentGmail extends FragmentBase {
tvTitle.setText(getString(R.string.title_setup_oauth_rationale, "Gmail")); tvTitle.setText(getString(R.string.title_setup_oauth_rationale, "Gmail"));
etName.setText(personal); etName.setText(personal);
cbPop.setChecked(pop); cbPop.setChecked(pop);
cbRecent.setChecked(recent);
cbRecent.setVisibility(pop ? View.VISIBLE : View.GONE);
cbUpdate.setChecked(update); cbUpdate.setChecked(update);
pbSelect.setVisibility(View.GONE); pbSelect.setVisibility(View.GONE);
grpError.setVisibility(View.GONE); grpError.setVisibility(View.GONE);
@ -268,6 +282,7 @@ public class FragmentGmail extends FragmentBase {
etName.setEnabled(granted); etName.setEnabled(granted);
cbPop.setEnabled(granted); cbPop.setEnabled(granted);
cbRecent.setEnabled(granted);
cbUpdate.setEnabled(granted); cbUpdate.setEnabled(granted);
btnSelect.setEnabled(granted); btnSelect.setEnabled(granted);
@ -381,6 +396,7 @@ public class FragmentGmail extends FragmentBase {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString("name", etName.getText().toString().trim()); args.putString("name", etName.getText().toString().trim());
args.putBoolean("pop", cbPop.isChecked()); args.putBoolean("pop", cbPop.isChecked());
args.putBoolean("recent", cbRecent.isChecked());
args.putBoolean("update", cbUpdate.isChecked()); args.putBoolean("update", cbUpdate.isChecked());
args.putString("user", user); args.putString("user", user);
args.putString("password", state.jsonSerializeString()); args.putString("password", state.jsonSerializeString());
@ -390,6 +406,7 @@ public class FragmentGmail extends FragmentBase {
protected void onPreExecute(Bundle args) { protected void onPreExecute(Bundle args) {
etName.setEnabled(false); etName.setEnabled(false);
cbPop.setEnabled(false); cbPop.setEnabled(false);
cbRecent.setEnabled(false);
cbUpdate.setEnabled(false); cbUpdate.setEnabled(false);
btnSelect.setEnabled(false); btnSelect.setEnabled(false);
pbSelect.setVisibility(View.VISIBLE); pbSelect.setVisibility(View.VISIBLE);
@ -399,6 +416,7 @@ public class FragmentGmail extends FragmentBase {
protected void onPostExecute(Bundle args) { protected void onPostExecute(Bundle args) {
etName.setEnabled(true); etName.setEnabled(true);
cbPop.setEnabled(true); cbPop.setEnabled(true);
cbRecent.setEnabled(true);
cbUpdate.setEnabled(true); cbUpdate.setEnabled(true);
btnSelect.setEnabled(true); btnSelect.setEnabled(true);
pbSelect.setVisibility(View.GONE); pbSelect.setVisibility(View.GONE);
@ -408,6 +426,7 @@ public class FragmentGmail extends FragmentBase {
protected Void onExecute(Context context, Bundle args) throws Throwable { protected Void onExecute(Context context, Bundle args) throws Throwable {
String name = args.getString("name"); String name = args.getString("name");
boolean pop = args.getBoolean("pop"); boolean pop = args.getBoolean("pop");
boolean recent = args.getBoolean("recent");
String user = args.getString("user"); String user = args.getString("user");
String password = args.getString("password"); String password = args.getString("password");
@ -425,6 +444,9 @@ public class FragmentGmail extends FragmentBase {
int at = user.indexOf('@'); int at = user.indexOf('@');
String username = user.substring(0, at); String username = user.substring(0, at);
if (pop && recent)
user = "recent:" + user;
EmailProvider provider = EmailProvider EmailProvider provider = EmailProvider
.fromDomain(context, "gmail.com", EmailProvider.Discover.ALL) .fromDomain(context, "gmail.com", EmailProvider.Discover.ALL)
.get(0); .get(0);

@ -83,7 +83,7 @@ public class GmailState {
Log.e(ex); Log.e(ex);
} }
Account account = getAccount(context, user); Account account = getAccount(context, user.replace("recent:", ""));
if (account == null) if (account == null)
throw new AuthenticatorException("Account not found for " + user); throw new AuthenticatorException("Account not found for " + user);

@ -100,6 +100,17 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etName" /> app:layout_constraintTop_toBottomOf="@id/etName" />
<CheckBox
android:id="@+id/cbRecent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:text="@string/title_setup_recent"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbPop" />
<CheckBox <CheckBox
android:id="@+id/cbUpdate" android:id="@+id/cbUpdate"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -108,7 +119,7 @@
android:text="@string/title_setup_oauth_update" android:text="@string/title_setup_oauth_update"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbPop" /> app:layout_constraintTop_toBottomOf="@id/cbRecent" />
<Button <Button
android:id="@+id/btnSelect" android:id="@+id/btnSelect"

@ -256,6 +256,7 @@
<string name="title_setup_still">Still to do</string> <string name="title_setup_still">Still to do</string>
<string name="title_setup_error">Error</string> <string name="title_setup_error">Error</string>
<string name="title_setup_pop">Use POP3 (not recommended)</string> <string name="title_setup_pop">Use POP3 (not recommended)</string>
<string name="title_setup_recent">Use \'recent\' for multiple email clients</string>
<string name="title_setup_configuring">Configuring account &#8230;</string> <string name="title_setup_configuring">Configuring account &#8230;</string>
<string name="title_setup_app_password">You might need to use an app password</string> <string name="title_setup_app_password">You might need to use an app password</string>
<string name="title_setup_extra">Extra</string> <string name="title_setup_extra">Extra</string>

Loading…
Cancel
Save