mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
allow to set tags on profiles (#3373)
allow to set tags on profiles --------- Co-authored-by: bjoern <r10s@b44t.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import android.view.ContextMenu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -35,6 +36,7 @@ import org.thoughtcrime.securesms.util.Util;
|
||||
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
|
||||
{
|
||||
@@ -113,9 +115,36 @@ public class AccountSelectionListFragment extends DialogFragment
|
||||
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();
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
@@ -46,7 +49,7 @@ public class AccountSelectionListItem extends LinearLayout {
|
||||
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);
|
||||
|
||||
@@ -57,7 +60,7 @@ public class AccountSelectionListItem extends LinearLayout {
|
||||
this.accountId = accountId;
|
||||
DcContact self = null;
|
||||
String name;
|
||||
String addr = null;
|
||||
String addrOrTag = null;
|
||||
int unreadCount = 0;
|
||||
boolean isMuted = dcContext.isMuted();
|
||||
|
||||
@@ -65,12 +68,13 @@ public class AccountSelectionListItem extends LinearLayout {
|
||||
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;
|
||||
}
|
||||
@@ -87,15 +91,15 @@ public class AccountSelectionListItem extends LinearLayout {
|
||||
|
||||
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);
|
||||
@@ -125,11 +129,11 @@ public class AccountSelectionListItem extends LinearLayout {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user