Skip to content

Commit

Permalink
allow to set tags on profiles (deltachat#3373)
Browse files Browse the repository at this point in the history
allow to set tags on profiles

---------

Co-authored-by: bjoern <[email protected]>
  • Loading branch information
adbenitez and r10s authored Oct 23, 2024
1 parent deacf8e commit 021a98c
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;
Expand All @@ -35,6 +36,7 @@
import org.thoughtcrime.securesms.util.ViewUtil;

import static com.b44t.messenger.DcContact.DC_CONTACT_ID_ADD_ACCOUNT;
import static org.thoughtcrime.securesms.connect.DcHelper.CONFIG_PRIVATE_TAG;

public class AccountSelectionListFragment extends DialogFragment
{
Expand Down Expand Up @@ -113,9 +115,36 @@ private void onContextItemSelected(MenuItem item, int accountId) {
case R.id.menu_mute_notifications:
onToggleMute(accountId);
break;
case R.id.menu_set_tag:
onSetTag(accountId);
break;
}
}

private void onSetTag(int accountId) {
Activity activity = getActivity();
if (activity == null) return;
AccountSelectionListFragment.this.dismiss();

DcContext dcContext = DcHelper.getAccounts(activity).getAccount(accountId);
View view = View.inflate(activity, R.layout.single_line_input, null);
EditText inputField = view.findViewById(R.id.input_field);
inputField.setHint(R.string.profile_tag_hint);
inputField.setText(dcContext.getConfig(CONFIG_PRIVATE_TAG));

new AlertDialog.Builder(activity)
.setTitle(R.string.profile_tag)
.setMessage(R.string.profile_tag_explain)
.setView(view)
.setPositiveButton(android.R.string.ok, (d, b) -> {
String newTag = inputField.getText().toString().trim();
dcContext.setConfig(CONFIG_PRIVATE_TAG, newTag);
AccountManager.getInstance().showSwitchAccountMenu(activity);
})
.setNegativeButton(R.string.cancel, (d, b) -> AccountManager.getInstance().showSwitchAccountMenu(activity))
.show();
}

private void onDeleteAccount(int accountId) {
Activity activity = getActivity();
AccountSelectionListFragment.this.dismiss();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.thoughtcrime.securesms.accounts;

import static org.thoughtcrime.securesms.connect.DcHelper.CONFIG_DISPLAY_NAME;
import static org.thoughtcrime.securesms.connect.DcHelper.CONFIG_PRIVATE_TAG;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
Expand Down Expand Up @@ -27,7 +30,7 @@ public class AccountSelectionListItem extends LinearLayout {

private AvatarImageView contactPhotoImage;
private View addrContainer;
private TextView addrView;
private TextView addrOrTagView;
private TextView nameView;
private ImageView unreadIndicator;

Expand All @@ -46,7 +49,7 @@ protected void onFinishInflate() {
super.onFinishInflate();
this.contactPhotoImage = findViewById(R.id.contact_photo_image);
this.addrContainer = findViewById(R.id.addr_container);
this.addrView = findViewById(R.id.addr);
this.addrOrTagView = findViewById(R.id.addr_or_tag);
this.nameView = findViewById(R.id.name);
this.unreadIndicator = findViewById(R.id.unread_indicator);

Expand All @@ -57,20 +60,21 @@ public void bind(@NonNull GlideRequests glideRequests, int accountId, DcContext
this.accountId = accountId;
DcContact self = null;
String name;
String addr = null;
String addrOrTag = null;
int unreadCount = 0;
boolean isMuted = dcContext.isMuted();

if (accountId == DcContact.DC_CONTACT_ID_ADD_ACCOUNT) {
name = getContext().getString(R.string.add_account);
} else {
self = dcContext.getContact(DcContact.DC_CONTACT_ID_SELF);
name = dcContext.getConfig("displayname");
name = dcContext.getConfig(CONFIG_DISPLAY_NAME);
if (TextUtils.isEmpty(name)) {
name = self.getAddr();
}
if (!dcContext.isChatmail()) {
addr = self.getAddr();
addrOrTag = dcContext.getConfig(CONFIG_PRIVATE_TAG);
if ("".equals(addrOrTag) && !dcContext.isChatmail()) {
addrOrTag = self.getAddr();
}
unreadCount = dcContext.getFreshMsgs().length;
}
Expand All @@ -87,15 +91,15 @@ public void bind(@NonNull GlideRequests glideRequests, int accountId, DcContext

setSelected(selected);
if (selected) {
addrView.setTypeface(null, Typeface.BOLD);
addrOrTagView.setTypeface(null, Typeface.BOLD);
nameView.setTypeface(null, Typeface.BOLD);
} else {
addrView.setTypeface(null, Typeface.NORMAL);
addrOrTagView.setTypeface(null, Typeface.NORMAL);
nameView.setTypeface(null, Typeface.NORMAL);
}

updateUnreadIndicator(unreadCount, isMuted);
setText(name, addr);
setText(name, addrOrTag);

if (accountId != DcContact.DC_CONTACT_ID_ADD_ACCOUNT) {
fragment.registerForContextMenu(this);
Expand Down Expand Up @@ -125,11 +129,11 @@ private void updateUnreadIndicator(int unreadCount, boolean isMuted) {
}
}

private void setText(String name, String addr) {
private void setText(String name, String addrOrTag) {
this.nameView.setText(name==null? "#" : name);

if(addr != null) {
this.addrView.setText(addr);
if(!TextUtils.isEmpty(addrOrTag)) {
this.addrOrTagView.setText(addrOrTag);
this.addrContainer.setVisibility(View.VISIBLE);
} else {
this.addrContainer.setVisibility(View.GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class DcHelper {
public static final String CONFIG_PROXY_URL = "proxy_url";
public static final String CONFIG_VERIFIED_ONE_ON_ONE_CHATS = "verified_one_on_one_chats";
public static final String CONFIG_WEBXDC_REALTIME_ENABLED = "webxdc_realtime_enabled";
public static final String CONFIG_PRIVATE_TAG = "private_tag";

public static DcContext getContext(@NonNull Context context) {
return ApplicationContext.getInstance(context).dcContext;
Expand Down
20 changes: 10 additions & 10 deletions src/main/res/layout/account_selection_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<TextView android:id="@+id/addr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textDirection="ltr"
android:singleLine="true"
android:ellipsize="marquee"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="14sp"
android:fontFamily="sans-serif-light"
tools:text="[email protected]" />
<org.thoughtcrime.securesms.components.emoji.EmojiTextView
android:id="@+id/addr_or_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="14sp"
android:fontFamily="sans-serif-light"
tools:text="[email protected]" />

</LinearLayout>

Expand Down
3 changes: 3 additions & 0 deletions src/main/res/menu/account_item_context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<item android:title="@string/menu_mute"
android:id="@+id/menu_mute_notifications"/>

<item android:title="@string/profile_tag"
android:id="@+id/menu_set_tag"/>

<item android:title="@string/delete"
android:id="@+id/delete"/>

Expand Down
3 changes: 3 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,9 @@
<string name="accept_invalid_certificates">Accept invalid certificates</string>
<string name="switch_account">Switch Profile</string>
<string name="add_account">Add Profile</string>
<string name="profile_tag">Private Tag</string>
<string name="profile_tag_hint">eg. Work, Family</string>
<string name="profile_tag_explain">Tag that is visible only for you; helping you to differ between your profiles.</string>
<string name="delete_account">Delete Profile</string>
<string name="delete_account_ask">Are you sure you want to delete your profile data?</string>
<string name="delete_account_explain_with_name">All profile data of \"%s\" on this device will be deleted, including your end-to-end encryption setup, contacts, chats, messages and media. This action cannot be undone.</string>
Expand Down

0 comments on commit 021a98c

Please sign in to comment.