Added button to disable Gmail

This commit is contained in:
M66B 2021-11-22 09:30:47 +01:00
parent edb7ab16ac
commit 3bcac5b0ed
3 changed files with 33 additions and 0 deletions

View File

@ -24,7 +24,9 @@ import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
@ -40,6 +42,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import static android.app.Activity.RESULT_OK; import static android.app.Activity.RESULT_OK;
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_GMAIL;
public class FragmentDialogAccount extends FragmentDialogBase { public class FragmentDialogAccount extends FragmentDialogBase {
@NonNull @NonNull
@ -59,6 +62,7 @@ public class FragmentDialogAccount extends FragmentDialogBase {
final TextView tvLeft = dview.findViewById(R.id.tvLeft); final TextView tvLeft = dview.findViewById(R.id.tvLeft);
final TextView tvRight = dview.findViewById(R.id.tvRight); final TextView tvRight = dview.findViewById(R.id.tvRight);
final Button btnAccount = dview.findViewById(R.id.btnAccount); final Button btnAccount = dview.findViewById(R.id.btnAccount);
final Button btnGmail = dview.findViewById(R.id.btnGmail);
final Drawable check = context.getDrawable(R.drawable.twotone_check_24); final Drawable check = context.getDrawable(R.drawable.twotone_check_24);
final Drawable close = context.getDrawable(R.drawable.twotone_close_24); final Drawable close = context.getDrawable(R.drawable.twotone_close_24);
@ -78,6 +82,7 @@ public class FragmentDialogAccount extends FragmentDialogBase {
tvRight.setText(null); tvRight.setText(null);
tvSentWarning.setVisibility(View.GONE); tvSentWarning.setVisibility(View.GONE);
btnGmail.setVisibility(View.GONE);
Bundle args = getArguments(); Bundle args = getArguments();
final long account = args.getLong("account"); final long account = args.getLong("account");
@ -94,12 +99,26 @@ public class FragmentDialogAccount extends FragmentDialogBase {
} }
}); });
Intent gmail = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
gmail.setData(Uri.parse("package:com.google.android.gm"));
boolean hasGmail = (gmail.resolveActivity(context.getPackageManager()) != null);
btnGmail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
v.getContext().startActivity(gmail);
}
});
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
db.account().liveAccount(account).observe(this, new Observer<EntityAccount>() { db.account().liveAccount(account).observe(this, new Observer<EntityAccount>() {
@Override @Override
public void onChanged(EntityAccount account) { public void onChanged(EntityAccount account) {
tvName.setText(account.name); tvName.setText(account.name);
btnGmail.setVisibility(
hasGmail && account.auth_type == AUTH_TYPE_GMAIL
? View.VISIBLE : View.GONE);
} }
}); });

View File

@ -197,5 +197,18 @@
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/btnAccount" /> app:layout_constraintTop_toBottomOf="@id/btnAccount" />
<Button
android:id="@+id/btnGmail"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:drawableEnd="@drawable/twotone_close_24"
android:drawablePadding="6dp"
android:tag="disable"
android:text="@string/title_disable_gmail"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAccount" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</eu.faircode.email.ScrollViewEx> </eu.faircode.email.ScrollViewEx>

View File

@ -156,6 +156,7 @@
<string name="title_edit_account">Edit account</string> <string name="title_edit_account">Edit account</string>
<string name="title_edit_identity">Edit identity</string> <string name="title_edit_identity">Edit identity</string>
<string name="title_edit_folder">Edit folder</string> <string name="title_edit_folder">Edit folder</string>
<string name="title_disable_gmail">Disable Gmail</string>
<string name="title_setup">Settings</string> <string name="title_setup">Settings</string>
<string name="title_setup_help">Help</string> <string name="title_setup_help">Help</string>