Added contributor info to user model. Added distinction when user sent message in inbox

This commit is contained in:
Keith Holliday 2016-07-06 16:59:51 -05:00
parent 70fec9fa45
commit eb21f18867
7 changed files with 151 additions and 22 deletions

View file

@ -7,5 +7,5 @@ public class HabitDatabase {
public static final String NAME = "Habitica";
public static final int VERSION = 22;
public static final int VERSION = 23;
}

View file

@ -14,6 +14,7 @@ import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils;
import com.habitrpg.android.habitica.ui.helpers.EmojiKeyboard;
import com.habitrpg.android.habitica.ui.helpers.ViewHelper;
import com.magicmicky.habitrpgwrapper.lib.models.ChatMessage;
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
import net.pherth.android.emoji_library.EmojiEditText;
import net.pherth.android.emoji_library.EmojiTextView;
@ -55,6 +56,7 @@ public class ChatRecyclerViewAdapter extends RecyclerView.Adapter<ChatRecyclerVi
private boolean isTavern;
private boolean isInboxChat = false;
private String replyToUserUUID;
private HabitRPGUser sendingUser;
public ChatRecyclerViewAdapter(List<ChatMessage> messages, String uuid, String groupId, boolean isTavern) {
this.messages = messages;
@ -68,6 +70,10 @@ public class ChatRecyclerViewAdapter extends RecyclerView.Adapter<ChatRecyclerVi
this.isInboxChat = true;
}
public void setSendingUser(HabitRPGUser user) {
this.sendingUser = user;
}
public void setMessages(List<ChatMessage> messages) {
this.messages = messages;
this.notifyDataSetChanged();
@ -238,14 +244,22 @@ public class ChatRecyclerViewAdapter extends RecyclerView.Adapter<ChatRecyclerVi
if (layoutType != TYPE_DANIEL && layoutType != TYPE_NEW_MESSAGE) {
setLikeProperties(msg);
DataBindingUtils.setRoundedBackgroundInt(userBackground, msg.getContributorColor());
if (msg.sent != null && msg.sent.equals("true")) {
DataBindingUtils.setRoundedBackgroundInt(userBackground, sendingUser.getContributor().getContributorColor());
} else {
DataBindingUtils.setRoundedBackgroundInt(userBackground, msg.getContributorColor());
}
if (msg.user == null || msg.user.equals("")) {
msg.user = "system";
}
if (userLabel != null) {
userLabel.setText(msg.user);
if (msg.sent != null && msg.sent.equals("true")) {
userLabel.setText(sendingUser.getProfile().getName());
} else {
userLabel.setText(msg.user);
}
}
DataBindingUtils.setForegroundTintColor(userLabel, msg.getContributorForegroundColor());

View file

@ -67,6 +67,7 @@ public class InboxMessageListFragment extends BaseMainFragment
chatAdapter = new ChatRecyclerViewAdapter(messages, null, null, false);
chatAdapter.setToInboxChat(this.replyToUserUUID);
chatAdapter.setSendingUser(this.user);
chatRecyclerView.setAdapter(chatAdapter);
return view;

View file

@ -13,23 +13,6 @@ import java.util.HashMap;
*/
public class ChatMessage {
private static final HashMap<Integer, Integer> CONTRIBUTOR_COLOR_DICT;
static {
CONTRIBUTOR_COLOR_DICT = new HashMap<>();
CONTRIBUTOR_COLOR_DICT.put(0, R.color.contributor_0);
CONTRIBUTOR_COLOR_DICT.put(1, R.color.contributor_1);
CONTRIBUTOR_COLOR_DICT.put(2, R.color.contributor_2);
CONTRIBUTOR_COLOR_DICT.put(3, R.color.contributor_3);
CONTRIBUTOR_COLOR_DICT.put(4, R.color.contributor_4);
CONTRIBUTOR_COLOR_DICT.put(5, R.color.contributor_5);
CONTRIBUTOR_COLOR_DICT.put(6, R.color.contributor_6);
CONTRIBUTOR_COLOR_DICT.put(7, R.color.contributor_7);
CONTRIBUTOR_COLOR_DICT.put(8, R.color.contributor_mod);
CONTRIBUTOR_COLOR_DICT.put(9, R.color.contributor_staff);
}
public String id;
public String text;
@ -50,13 +33,15 @@ public class ChatMessage {
public String user;
public String sent;
public int getContributorColor() {
int rColor = android.R.color.black;
if (contributor != null) {
if (CONTRIBUTOR_COLOR_DICT.containsKey(contributor.level)) {
rColor = CONTRIBUTOR_COLOR_DICT.get(contributor.level);
if (ContributorInfo.CONTRIBUTOR_COLOR_DICT.containsKey(contributor.level)) {
rColor = ContributorInfo.CONTRIBUTOR_COLOR_DICT.get(contributor.level);
}
}

View file

@ -0,0 +1,105 @@
package com.magicmicky.habitrpgwrapper.lib.models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.habitrpg.android.habitica.HabitDatabase;
import com.habitrpg.android.habitica.R;
import com.raizlabs.android.dbflow.annotation.Column;
import com.raizlabs.android.dbflow.annotation.NotNull;
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
import com.raizlabs.android.dbflow.annotation.Table;
import com.raizlabs.android.dbflow.structure.BaseModel;
import java.util.HashMap;
/**
* Created by keithholliday on 7/6/16.
*/
@Table(databaseName = HabitDatabase.NAME)
public class ContributorInfo extends BaseModel {
public static final HashMap<Integer, Integer> CONTRIBUTOR_COLOR_DICT;
static {
CONTRIBUTOR_COLOR_DICT = new HashMap<>();
CONTRIBUTOR_COLOR_DICT.put(0, R.color.contributor_0);
CONTRIBUTOR_COLOR_DICT.put(1, R.color.contributor_1);
CONTRIBUTOR_COLOR_DICT.put(2, R.color.contributor_2);
CONTRIBUTOR_COLOR_DICT.put(3, R.color.contributor_3);
CONTRIBUTOR_COLOR_DICT.put(4, R.color.contributor_4);
CONTRIBUTOR_COLOR_DICT.put(5, R.color.contributor_5);
CONTRIBUTOR_COLOR_DICT.put(6, R.color.contributor_6);
CONTRIBUTOR_COLOR_DICT.put(7, R.color.contributor_7);
CONTRIBUTOR_COLOR_DICT.put(8, R.color.contributor_mod);
CONTRIBUTOR_COLOR_DICT.put(9, R.color.contributor_staff);
}
@Column
@PrimaryKey
@NotNull
public String user_id;
@SerializedName("admin")
@Expose
private boolean admin;
@SerializedName("contributions")
@Expose
private String contributions;
@SerializedName("level")
@Expose
private int level;
@SerializedName("text")
@Expose
private String text;
public void setAdmin(Boolean admin) {
this.admin = admin;
}
public Boolean getAdmin() {
return this.admin;
}
public void setContributions(String contributions) {
this.contributions = contributions;
}
public String getContributions() {
return this.contributions;
}
public void setLevel(int level) {
this.level = level;
}
public int getLevel() {
return this.level;
}
public void setText(String text) {
this.text = text;
}
public String getText() {
return this.text;
}
public int getContributorColor() {
int rColor = android.R.color.black;
if (CONTRIBUTOR_COLOR_DICT.containsKey(this.level)) {
rColor = CONTRIBUTOR_COLOR_DICT.get(this.level);
}
return rColor;
}
public int getContributorForegroundColor() {
int rColor = android.R.color.white;
return rColor;
}
}

View file

@ -86,6 +86,12 @@ public class HabitRPGUser extends BaseModel {
foreignColumnName = "user_id")})
private Flags flags;
@Column
@ForeignKey(references = {@ForeignKeyReference(columnName = "contributor_id",
columnType = String.class,
foreignColumnName = "user_id")})
private ContributorInfo contributor;
private Purchases purchased;
private TasksOrder tasksOrder;
@ -131,6 +137,15 @@ public class HabitRPGUser extends BaseModel {
this.profile = profile;
}
public ContributorInfo getContributor() {
return contributor;
}
public void setContributor(ContributorInfo contributor) {
this.contributor = contributor;
}
public UserParty getParty() {
return party;
}
@ -277,6 +292,7 @@ public class HabitRPGUser extends BaseModel {
items.user_id = id;
authentication.user_id = id;
flags.user_id = id;
contributor.user_id = id;
ArrayList<Task> allTasks = new ArrayList<Task>();
if (dailys != null) {

View file

@ -35,9 +35,11 @@ public class ChatMessageDeserializer implements JsonDeserializer<ChatMessage> {
if (obj.has("flagCount")) {
message.flagCount = obj.get("flagCount").getAsInt();
}
if (obj.has("uuid")) {
message.uuid = obj.get("uuid").getAsString();
}
if (obj.has("contributor")) {
if (!obj.get("contributor").isJsonNull()) {
if (obj.get("contributor").isJsonObject()) {
@ -49,13 +51,19 @@ public class ChatMessageDeserializer implements JsonDeserializer<ChatMessage> {
}
}
}
if (obj.has("backer")) {
message.backer = context.deserialize(obj.get("backer"), Backer.class);
}
if (obj.has("user")) {
message.user = obj.get("user").getAsString();
}
if (obj.has("sent")) {
message.sent = obj.get("sent").getAsString();
}
return message;
}
}