mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
nice support for communities
This commit is contained in:
@@ -1398,6 +1398,16 @@ JNIEXPORT jint Java_com_b44t_messenger_DcMsg_getId(JNIEnv *env, jobject obj)
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jboolean Java_com_b44t_messenger_DcMsg_isOutgoing(JNIEnv *env, jobject obj)
|
||||
{
|
||||
return (jboolean)(dc_msg_is_outgoing(get_dc_msg(env, obj))!=0);
|
||||
}
|
||||
|
||||
JNIEXPORT jint Java_com_b44t_messenger_DcMsg_getSenderColor(JNIEnv *env, jobject obj)
|
||||
{
|
||||
return dc_msg_get_sender_color(get_dc_msg(env, obj));
|
||||
}
|
||||
|
||||
JNIEXPORT jstring Java_com_b44t_messenger_DcMsg_getText(JNIEnv *env, jobject obj)
|
||||
{
|
||||
char* temp = dc_msg_get_text(get_dc_msg(env, obj));
|
||||
|
||||
@@ -25,6 +25,31 @@
|
||||
android:textSize="16sp"
|
||||
android:textColor="?android:attr/textColorPrimary" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/community_user_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_marginBottom="40dp"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp">
|
||||
|
||||
<org.thoughtcrime.securesms.components.emoji.EmojiEditText
|
||||
android:id="@+id/overriden_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/pref_your_name"
|
||||
android:inputType="textCapWords" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="community">Comunidad</string>
|
||||
<string name="description">Descripción</string>
|
||||
<!-- common strings without special context -->
|
||||
<string name="app_name">DeltaLab</string>
|
||||
<string name="ok">OK</string>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="community">Community</string>
|
||||
<string name="description">Description</string>
|
||||
<string name="could_not_open_file">Could not open file</string>
|
||||
<!-- common strings without special context -->
|
||||
<string name="app_name">DeltaLab</string>
|
||||
|
||||
@@ -247,6 +247,23 @@ public class DcContext {
|
||||
return ret.trim();
|
||||
}
|
||||
|
||||
public boolean isCommunity() {
|
||||
return getConfigInt("is_community") == 1;
|
||||
}
|
||||
|
||||
public void setCommunityMode(boolean enable) {
|
||||
setConfig("is_community", enable? "1" : null);
|
||||
}
|
||||
|
||||
public String getCommunityUser() {
|
||||
String name = getConfig("ui.community.selfname");
|
||||
return name == null? "" : name;
|
||||
}
|
||||
|
||||
public void setCommunityUser(String name) {
|
||||
setConfig("ui.community.selfname", name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if at least one chat has location streaming enabled
|
||||
*/
|
||||
|
||||
@@ -166,6 +166,8 @@ public class DcMsg {
|
||||
public native String getQuotedText ();
|
||||
public native String getError ();
|
||||
public native String getOverrideSenderName();
|
||||
public native boolean isOutgoing();
|
||||
public native int getSenderColor();
|
||||
|
||||
public String getSenderName(DcContact dcContact, boolean markOverride) {
|
||||
String overrideName = getOverrideSenderName();
|
||||
@@ -205,10 +207,6 @@ public class DcMsg {
|
||||
return ids;
|
||||
}
|
||||
|
||||
public boolean isOutgoing() {
|
||||
return getFromId() == DcContact.DC_CONTACT_ID_SELF;
|
||||
}
|
||||
|
||||
public String getDisplayBody() {
|
||||
return getText();
|
||||
}
|
||||
|
||||
@@ -131,6 +131,9 @@ public class ApplicationContext extends MultiDexApplication {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if ("deltafans@nine.testrun.org".equals(ac.getConfig("configured_addr")) && !ac.isCommunity()) {
|
||||
ac.setCommunityMode(true);
|
||||
}
|
||||
}
|
||||
if (allAccounts.length == 0) {
|
||||
dcAccounts.addAccount();
|
||||
|
||||
@@ -173,7 +173,7 @@ public class ConversationItem extends BaseConversationItem
|
||||
bind(messageRecord, dcChat, batchSelected, pulseHighlight, recipients);
|
||||
this.locale = locale;
|
||||
this.glideRequests = glideRequests;
|
||||
this.showSender = dcChat.isMultiUser() || messageRecord.getOverrideSenderName() != null;
|
||||
this.showSender = dcContext.isCommunity() || dcChat.isMultiUser() || messageRecord.getOverrideSenderName() != null;
|
||||
|
||||
if (showSender && !messageRecord.isOutgoing()) {
|
||||
this.dcContact = dcContext.getContact(messageRecord.getFromId());
|
||||
@@ -635,7 +635,9 @@ public class ConversationItem extends BaseConversationItem
|
||||
if (messageRecord.isOutgoing() || !showSender || dcContact ==null) {
|
||||
contactPhoto.setVisibility(View.GONE);
|
||||
} else {
|
||||
contactPhoto.setAvatar(glideRequests, new Recipient(context, dcContact), true);
|
||||
int color = messageRecord.getSenderColor();
|
||||
Recipient recipient = new Recipient(context, dcContact, messageRecord.getSenderName(dcContact, !dcContext.isCommunity()), color);
|
||||
contactPhoto.setAvatar(glideRequests, recipient, true);
|
||||
contactPhoto.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
@@ -660,7 +662,7 @@ public class ConversationItem extends BaseConversationItem
|
||||
Recipient author = null;
|
||||
SlideDeck slideDeck = new SlideDeck();
|
||||
if (msg != null) {
|
||||
author = new Recipient(context, dcContext.getContact(msg.getFromId()));
|
||||
author = new Recipient(context, dcContext.getContact(msg.getFromId()), msg.getSenderColor());
|
||||
if (msg.getType() != DcMsg.DC_MSG_TEXT) {
|
||||
Slide slide = MediaUtil.getSlideForMsg(context, msg);
|
||||
if (slide != null) {
|
||||
@@ -767,7 +769,8 @@ public class ConversationItem extends BaseConversationItem
|
||||
}
|
||||
else if (showSender && !messageRecord.isOutgoing() && dcContact !=null) {
|
||||
this.groupSender.setText(messageRecord.getSenderName(dcContact, true));
|
||||
this.groupSender.setTextColor(Util.rgbToArgbColor(dcContact.getColor()));
|
||||
int color = messageRecord.getSenderColor();
|
||||
this.groupSender.setTextColor(Util.rgbToArgbColor(color!=0? color : dcContact.getColor()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,9 +26,11 @@ import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.loader.app.LoaderManager;
|
||||
|
||||
import com.b44t.messenger.DcContext;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
import com.soundcloud.android.crop.Crop;
|
||||
|
||||
import org.thoughtcrime.securesms.components.AvatarSelector;
|
||||
@@ -63,6 +65,7 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Emoj
|
||||
private InputAwareLayout container;
|
||||
private ImageView avatar;
|
||||
private EditText name;
|
||||
private EditText overridenName;
|
||||
private MediaKeyboard emojiDrawer;
|
||||
private EditText statusView;
|
||||
|
||||
@@ -202,6 +205,7 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Emoj
|
||||
TextView loginSuccessText = ViewUtil.findById(this, R.id.login_success_text);
|
||||
this.avatar = ViewUtil.findById(this, R.id.avatar);
|
||||
this.name = ViewUtil.findById(this, R.id.name_text);
|
||||
this.overridenName = ViewUtil.findById(this, R.id.overriden_name);
|
||||
this.emojiDrawer = ViewUtil.findById(this, R.id.emoji_drawer);
|
||||
this.container = ViewUtil.findById(this, R.id.container);
|
||||
this.statusView = ViewUtil.findById(this, R.id.status_text);
|
||||
@@ -212,6 +216,12 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Emoj
|
||||
ViewUtil.findById(this, R.id.status_text_layout).setVisibility(View.GONE);
|
||||
ViewUtil.findById(this, R.id.information_label).setVisibility(View.GONE);
|
||||
} else {
|
||||
if (DcHelper.getContext(this).isCommunity()) {
|
||||
ViewUtil.findById(this, R.id.community_user_container).setVisibility(View.VISIBLE);
|
||||
ViewUtil.findById(this, R.id.information_label).setVisibility(View.GONE);
|
||||
((TextInputLayout)ViewUtil.findById(this, R.id.name)).setHint(R.string.community);
|
||||
((TextInputLayout)ViewUtil.findById(this, R.id.status_text_layout)).setHint(R.string.description);
|
||||
}
|
||||
loginSuccessText.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
@@ -222,6 +232,10 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Emoj
|
||||
name.setText(profileName);
|
||||
name.setSelection(profileName.length(), profileName.length());
|
||||
}
|
||||
DcContext dcContext = DcHelper.getContext(this);
|
||||
if (dcContext.isCommunity()) {
|
||||
overridenName.setText(dcContext.getCommunityUser());
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeProfileAvatar() {
|
||||
@@ -280,11 +294,15 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Emoj
|
||||
return;
|
||||
}
|
||||
final String name = this.name.getText().toString();
|
||||
final String ovName = this.overridenName.getText().toString().trim();
|
||||
|
||||
new AsyncTask<Void, Void, Boolean>() {
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
Context context = CreateProfileActivity.this;
|
||||
if (DcHelper.getContext(context).isCommunity()) {
|
||||
DcHelper.getContext(context).setCommunityUser(ovName);
|
||||
}
|
||||
DcHelper.set(context, DcHelper.CONFIG_DISPLAY_NAME, name);
|
||||
setStatusText();
|
||||
|
||||
|
||||
@@ -170,8 +170,9 @@ public class QuoteView extends FrameLayout implements RecipientForeverObserver {
|
||||
authorView.setTextColor(getResources().getColor(R.color.core_dark_05));
|
||||
quoteBarView.setBackgroundColor(getResources().getColor(R.color.core_dark_05));
|
||||
} else {
|
||||
authorView.setTextColor(Util.rgbToArgbColor(contact.getColor()));
|
||||
quoteBarView.setBackgroundColor(Util.rgbToArgbColor(contact.getColor()));
|
||||
int color = author.getColor()==0? contact.getColor() : author.getColor();
|
||||
authorView.setTextColor(Util.rgbToArgbColor(color));
|
||||
quoteBarView.setBackgroundColor(Util.rgbToArgbColor(color));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ public class Recipient {
|
||||
|
||||
private final @Nullable DcChat dcChat;
|
||||
private @Nullable DcContact dcContact;
|
||||
private int color = 0;
|
||||
|
||||
public static @NonNull Recipient fromChat(@NonNull Context context, int dcMsgId) {
|
||||
DcContext dcContext = DcHelper.getContext(context);
|
||||
@@ -97,10 +98,20 @@ public class Recipient {
|
||||
this(context, null, dcContact, null);
|
||||
}
|
||||
|
||||
public Recipient(@NonNull Context context, @NonNull DcContact dcContact, int color) {
|
||||
this(context, null, dcContact, null);
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public Recipient(@NonNull Context context, @NonNull DcContact dcContact, @NonNull String profileName) {
|
||||
this(context, null, dcContact, profileName);
|
||||
}
|
||||
|
||||
public Recipient(@NonNull Context context, @NonNull DcContact dcContact, @NonNull String profileName, int color) {
|
||||
this(context, null, dcContact, profileName);
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
private Recipient(@NonNull Context context, @Nullable DcChat dcChat, @Nullable DcContact dcContact, @Nullable String profileName) {
|
||||
this.dcChat = dcChat;
|
||||
this.dcContact = dcContact;
|
||||
@@ -197,6 +208,9 @@ public class Recipient {
|
||||
if(dcChat!=null) {
|
||||
rgb = dcChat.getColor();
|
||||
}
|
||||
else if(color!=0) {
|
||||
rgb = color;
|
||||
}
|
||||
else if(dcContact!=null) {
|
||||
rgb = dcContact.getColor();
|
||||
}
|
||||
@@ -216,6 +230,10 @@ public class Recipient {
|
||||
}
|
||||
|
||||
public synchronized @Nullable ContactPhoto getContactPhoto(Context context) {
|
||||
if (color != 0) { // community nick
|
||||
return null;
|
||||
}
|
||||
|
||||
LocalFileContactPhoto contactPhoto = null;
|
||||
if (dcChat!=null) {
|
||||
contactPhoto = new GroupRecordContactPhoto(context, address, dcChat);
|
||||
@@ -290,6 +308,11 @@ public class Recipient {
|
||||
return dcChat!=null? dcChat : new DcChat(0, 0);
|
||||
}
|
||||
|
||||
public int getColor()
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Recipient{" +
|
||||
|
||||
Reference in New Issue
Block a user