mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-27 19:35:10 +01:00
Added account images
This commit is contained in:
@@ -115,6 +115,9 @@ public class FragmentAccount extends FragmentBase {
|
||||
private ViewButtonColor btnColor;
|
||||
private TextView tvColorPro;
|
||||
|
||||
private Button btnAvatar;
|
||||
private TextView tvAvatarPro;
|
||||
|
||||
private Button btnCalendar;
|
||||
private TextView tvCalendarPro;
|
||||
|
||||
@@ -179,14 +182,16 @@ public class FragmentAccount extends FragmentBase {
|
||||
private long copy = -1;
|
||||
private int auth = AUTH_TYPE_PASSWORD;
|
||||
private String provider = null;
|
||||
private String avatar = null;
|
||||
private String calendar = null;
|
||||
private String certificate = null;
|
||||
private boolean saving = false;
|
||||
|
||||
private static final int REQUEST_COLOR = 1;
|
||||
private static final int REQUEST_CALENDAR = 2;
|
||||
private static final int REQUEST_SAVE = 3;
|
||||
private static final int REQUEST_DELETE = 4;
|
||||
private static final int REQUEST_AVATAR = 2;
|
||||
private static final int REQUEST_CALENDAR = 3;
|
||||
private static final int REQUEST_SAVE = 4;
|
||||
private static final int REQUEST_DELETE = 5;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -237,6 +242,9 @@ public class FragmentAccount extends FragmentBase {
|
||||
btnColor = view.findViewById(R.id.btnColor);
|
||||
tvColorPro = view.findViewById(R.id.tvColorPro);
|
||||
|
||||
btnAvatar = view.findViewById(R.id.btnAvatar);
|
||||
tvAvatarPro = view.findViewById(R.id.tvAvatarPro);
|
||||
|
||||
btnCalendar = view.findViewById(R.id.btnCalendar);
|
||||
tvCalendarPro = view.findViewById(R.id.tvCalendarPro);
|
||||
|
||||
@@ -462,6 +470,21 @@ public class FragmentAccount extends FragmentBase {
|
||||
|
||||
Helper.linkPro(tvColorPro);
|
||||
|
||||
btnAvatar.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
intent.setType("image/*");
|
||||
Helper.openAdvanced(v.getContext(), intent);
|
||||
startActivityForResult(intent, REQUEST_AVATAR);
|
||||
}
|
||||
});
|
||||
|
||||
Helper.linkPro(tvAvatarPro);
|
||||
|
||||
btnCalendar.setEnabled(Helper.hasPermission(getContext(), Manifest.permission.WRITE_CALENDAR));
|
||||
btnCalendar.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -951,6 +974,7 @@ public class FragmentAccount extends FragmentBase {
|
||||
args.putString("name", etName.getText().toString());
|
||||
args.putString("category", etCategory.getText().toString());
|
||||
args.putInt("color", btnColor.getColor());
|
||||
args.putString("avatar", avatar);
|
||||
args.putString("calendar", calendar);
|
||||
|
||||
args.putBoolean("synchronize", cbSynchronize.isChecked());
|
||||
@@ -1030,6 +1054,7 @@ public class FragmentAccount extends FragmentBase {
|
||||
String name = args.getString("name");
|
||||
String category = args.getString("category");
|
||||
Integer color = args.getInt("color");
|
||||
String avatar = args.getString("avatar");
|
||||
String calendar = args.getString("calendar");
|
||||
|
||||
boolean synchronize = args.getBoolean("synchronize");
|
||||
@@ -1138,6 +1163,8 @@ public class FragmentAccount extends FragmentBase {
|
||||
return true;
|
||||
if (!Objects.equals(account.color, color))
|
||||
return true;
|
||||
if (!Objects.equals(account.avatar, avatar))
|
||||
return true;
|
||||
if (!Objects.equals(account.calendar, calendar))
|
||||
return true;
|
||||
if (!Objects.equals(account.synchronize, synchronize))
|
||||
@@ -1293,6 +1320,7 @@ public class FragmentAccount extends FragmentBase {
|
||||
account.name = name;
|
||||
account.category = category;
|
||||
account.color = color;
|
||||
account.avatar = avatar;
|
||||
account.calendar = calendar;
|
||||
|
||||
account.synchronize = synchronize;
|
||||
@@ -1577,6 +1605,7 @@ public class FragmentAccount extends FragmentBase {
|
||||
outState.putInt("fair:advanced", grpAdvanced == null ? View.VISIBLE : grpAdvanced.getVisibility());
|
||||
outState.putInt("fair:auth", auth);
|
||||
outState.putString("fair:authprovider", provider);
|
||||
outState.putString("fair:avatar", avatar);
|
||||
outState.putString("fair:calendar", calendar);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
@@ -1750,6 +1779,7 @@ public class FragmentAccount extends FragmentBase {
|
||||
|
||||
auth = (account == null ? AUTH_TYPE_PASSWORD : account.auth_type);
|
||||
provider = (account == null ? null : account.provider);
|
||||
avatar = (account == null ? null : account.avatar);
|
||||
calendar = (account == null ? null : account.calendar);
|
||||
|
||||
new SimpleTask<EntityAccount>() {
|
||||
@@ -1781,6 +1811,7 @@ public class FragmentAccount extends FragmentBase {
|
||||
grpAdvanced.setVisibility(savedInstanceState.getInt("fair:advanced"));
|
||||
auth = savedInstanceState.getInt("fair:auth");
|
||||
provider = savedInstanceState.getString("fair:authprovider");
|
||||
avatar = savedInstanceState.getString("fair:avatar");
|
||||
calendar = savedInstanceState.getString("fair:calendar");
|
||||
}
|
||||
|
||||
@@ -1977,6 +2008,12 @@ public class FragmentAccount extends FragmentBase {
|
||||
startActivity(new Intent(getContext(), ActivityBilling.class));
|
||||
}
|
||||
break;
|
||||
case REQUEST_AVATAR:
|
||||
if (resultCode == RESULT_OK && data != null)
|
||||
onImageSelected(data.getData());
|
||||
else
|
||||
avatar = null;
|
||||
break;
|
||||
case REQUEST_CALENDAR:
|
||||
if (resultCode == RESULT_OK && data != null) {
|
||||
if (ActivityBilling.isPro(getContext())) {
|
||||
@@ -2019,6 +2056,23 @@ public class FragmentAccount extends FragmentBase {
|
||||
}
|
||||
}
|
||||
|
||||
private void onImageSelected(Uri uri) {
|
||||
try {
|
||||
final Context context = getContext();
|
||||
NoStreamException.check(uri, context);
|
||||
|
||||
context.getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
if (!Helper.isPersisted(context, uri, true, false))
|
||||
throw new IllegalStateException("No permission granted to access selected image " + uri);
|
||||
|
||||
avatar = uri.toString();
|
||||
} catch (NoStreamException ex) {
|
||||
ex.report(getActivity());
|
||||
} catch (Throwable ex) {
|
||||
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void onDelete() {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", id);
|
||||
|
||||
Reference in New Issue
Block a user