Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve profile deletion dialog #3273

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/com/b44t/messenger/rpc/Rpc.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ public void leaveWebxdcRealtime(Integer accountId, Integer instanceMessageId) th
getResult("leave_webxdc_realtime", accountId, instanceMessageId);
}

public int getAccountFileSize(int accountId) throws RpcException {
return getResult("get_account_file_size", accountId).getAsInt();
}

private static class Request {
private final String jsonrpc = "2.0";
public final String method;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
Expand All @@ -16,13 +18,18 @@
import androidx.recyclerview.widget.RecyclerView;

import com.b44t.messenger.DcAccounts;
import com.b44t.messenger.DcContact;
import com.b44t.messenger.DcContext;
import com.b44t.messenger.rpc.Rpc;
import com.b44t.messenger.rpc.RpcException;

import org.thoughtcrime.securesms.ConnectivityActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.components.AvatarView;
import org.thoughtcrime.securesms.connect.AccountManager;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.mms.GlideApp;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.ViewUtil;

Expand Down Expand Up @@ -113,9 +120,34 @@ private void onDeleteAccount(int accountId) {
AccountSelectionListFragment.this.dismiss();
if (activity == null) return;
DcAccounts accounts = DcHelper.getAccounts(activity);
Rpc rpc = DcHelper.getRpc(activity);

View dialogView = View.inflate(activity, R.layout.dialog_delete_profile, null);
AvatarView avatar = dialogView.findViewById(R.id.avatar);
TextView nameView = dialogView.findViewById(R.id.name);
TextView addrView = dialogView.findViewById(R.id.address);
TextView sizeView = dialogView.findViewById(R.id.size_label);
TextView description = dialogView.findViewById(R.id.description);
DcContext dcContext = accounts.getAccount(accountId);
String name = dcContext.getConfig("displayname");
DcContact contact = dcContext.getContact(DcContact.DC_CONTACT_ID_SELF);
if (TextUtils.isEmpty(name)) {
name = contact.getAddr();
}
Recipient recipient = new Recipient(getContext(), contact, name);
avatar.setAvatar(GlideApp.with(activity), recipient, false);
nameView.setText(name);
addrView.setText(contact.getAddr());
try {
sizeView.setText(Util.getPrettyFileSize(rpc.getAccountFileSize(accountId)));
} catch (RpcException e) {
e.printStackTrace();
}
description.setText(activity.getString(R.string.delete_account_explain_with_name, name));

AlertDialog dialog = new AlertDialog.Builder(activity)
.setTitle(accounts.getAccount(accountId).getNameNAddr())
.setMessage(R.string.forget_login_confirmation_desktop)
.setTitle(R.string.delete_account)
.setView(dialogView)
.setNegativeButton(R.string.cancel, (d, which) -> AccountManager.getInstance().showSwitchAccountMenu(activity))
.setPositiveButton(R.string.delete, (d2, which2) -> {
boolean selected = accountId == accounts.getSelectedAccount().getAccountId();
Expand Down
7 changes: 7 additions & 0 deletions src/main/res/drawable/delete_account_item_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- read issue: https://github.com/deltachat/deltachat-android/issues/480 before introducing an attr here. -->
<solid android:color="@color/delete_account_item_bg" />
<corners android:radius="8dp" />
</shape>
96 changes: 96 additions & 0 deletions src/main/res/layout/dialog_delete_profile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:text="@string/delete_account_ask" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:background="@drawable/delete_account_item_background">

<org.thoughtcrime.securesms.components.AvatarView
android:id="@+id/avatar"
android:layout_width="50dp"
android:layout_height="50dp" />

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:paddingRight="16dp"
android:paddingEnd="16dp"
android:orientation="vertical">

<org.thoughtcrime.securesms.components.emoji.EmojiTextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:singleLine="true"
android:fontFamily="sans-serif"
android:textSize="16sp"
tools:text="Frieeeeeeedrich Nieeeeeeeeeetzsche" />

<TextView
android:id="@+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textDirection="ltr"
android:singleLine="true"
android:ellipsize="marquee"

android:textSize="14sp"
android:fontFamily="sans-serif-light"
tools:text="[email protected]" />

<TextView
android:id="@+id/size_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="12sp"
android:fontFamily="sans-serif-light"
tools:text="150 MB" />

</LinearLayout>

</LinearLayout>

<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:text="@string/delete_account_explain_with_name"/>

</LinearLayout>

</ScrollView>

2 changes: 2 additions & 0 deletions src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@

<color name="action_mode_status_bar">@color/gray78</color>
<color name="dummy_avatar_color">#808080</color>

<color name="delete_account_item_bg">#222222</color>
</resources>
2 changes: 2 additions & 0 deletions src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,6 @@
<color name="reaction_pill_background_selected">@color/light_green</color>
<color name="reaction_pill_border_selected">@color/reaction_pill_border</color>
<color name="reaction_pill_text_color_selected">@color/reaction_pill_text_color</color>

<color name="delete_account_item_bg">#eeeeee</color>
</resources>
Loading