mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-17 03:22:04 +00:00
commit
ccc937d2cf
19 changed files with 687 additions and 28 deletions
42
Habitica/res/layout/fragment_inbox.xml
Normal file
42
Habitica/res/layout/fragment_inbox.xml
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/inbox_refresh_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
<android.support.v4.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/SectionTitle"
|
||||
android:text="@string/sidebar.inbox"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<android.support.v7.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="@dimen/card_large_text"
|
||||
style="@style/CardView.Default">
|
||||
<LinearLayout
|
||||
android:id="@+id/inbox_messages"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:divider="?android:listDivider"
|
||||
android:showDividers="middle">
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
18
Habitica/res/layout/fragment_inbox_message_list.xml
Normal file
18
Habitica/res/layout/fragment_inbox_message_list.xml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/inbox_refresh_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/chat.list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:divider="@null"
|
||||
android:scrollbars="vertical" />
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
<string name="sidebar.tasks">Tasks</string>
|
||||
<string name="sidebar.skills">Skills</string>
|
||||
<string name="sidebar.section.social">Social</string>
|
||||
<string name="sidebar.inbox">Inbox</string>
|
||||
<string name="sidebar.tavern">Tavern</string>
|
||||
<string name="sidebar.party">Party</string>
|
||||
<string name="sidebar.purchaseGems">Purchase Gems</string>
|
||||
|
|
|
|||
|
|
@ -56,9 +56,9 @@
|
|||
<string name="about.bugreport">Report a Bug</string>
|
||||
<string name="about.source_code">Source Code</string>
|
||||
|
||||
<!-- Network Errors -->
|
||||
<string name="network_error_title">Connection Error</string>
|
||||
<string name="network_error_no_network_body">You are not connected to the internet.</string>
|
||||
<!-- Network Errors -->
|
||||
<string name="network_error_title">Connection Error</string>
|
||||
<string name="network_error_no_network_body">You are not connected to the internet.</string>
|
||||
<string name="internal_error_api">There seems to be a problem with the server. Try again later.</string>
|
||||
|
||||
<string name="authentication_error_title">Authentication Error</string>
|
||||
|
|
|
|||
|
|
@ -91,6 +91,7 @@ import okhttp3.Request;
|
|||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import okio.Buffer;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Converter;
|
||||
import retrofit2.Retrofit;
|
||||
|
|
@ -151,7 +152,7 @@ public class APIHelper implements Action1<Throwable> {
|
|||
|
||||
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
|
||||
if (BuildConfig.DEBUG) {
|
||||
logging.setLevel(HttpLoggingInterceptor.Level.BASIC);
|
||||
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
}
|
||||
|
||||
OkHttpClient client = new OkHttpClient.Builder()
|
||||
|
|
|
|||
|
|
@ -7,5 +7,5 @@ public class HabitDatabase {
|
|||
|
||||
public static final String NAME = "Habitica";
|
||||
|
||||
public static final int VERSION = 21;
|
||||
public static final int VERSION = 23;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ import com.habitrpg.android.habitica.ui.fragments.social.ChatListFragment;
|
|||
import com.habitrpg.android.habitica.ui.fragments.social.GroupInformationFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.social.GuildFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.social.GuildsOverviewFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.social.InboxFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.social.InboxMessageListFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.social.PublicGuildsFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.social.TavernFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.social.party.PartyFragment;
|
||||
|
|
@ -144,4 +146,8 @@ public interface AppComponent {
|
|||
void inject(HabiticaApplication habiticaApplication);
|
||||
|
||||
void inject(PreferencesFragment preferencesFragment);
|
||||
|
||||
void inject(InboxFragment inboxFragment);
|
||||
|
||||
void inject(InboxMessageListFragment inboxMessageListFragment);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
package com.habitrpg.android.habitica.events.commands;
|
||||
|
||||
/**
|
||||
* Created by keithholliday on 6/22/16.
|
||||
*/
|
||||
public class SendNewInboxMessageCommand {
|
||||
public String Message;
|
||||
public String UserToSendTo;
|
||||
|
||||
public SendNewInboxMessageCommand(String userToSendTo, String message) {
|
||||
UserToSendTo = userToSendTo;
|
||||
Message = message;
|
||||
}
|
||||
}
|
||||
|
|
@ -63,9 +63,12 @@ import com.magicmicky.habitrpgwrapper.lib.models.tasks.TaskTag;
|
|||
import com.mikepenz.materialdrawer.AccountHeader;
|
||||
import com.mikepenz.materialdrawer.Drawer;
|
||||
import com.mikepenz.materialdrawer.DrawerBuilder;
|
||||
import com.mikepenz.materialdrawer.holder.BadgeStyle;
|
||||
import com.mikepenz.materialdrawer.holder.StringHolder;
|
||||
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.interfaces.IProfile;
|
||||
import com.mikepenz.materialdrawer.model.utils.BadgeDrawableBuilder;
|
||||
import com.raizlabs.android.dbflow.runtime.TransactionManager;
|
||||
import com.raizlabs.android.dbflow.runtime.transaction.BaseTransaction;
|
||||
import com.raizlabs.android.dbflow.runtime.transaction.TransactionListener;
|
||||
|
|
@ -97,6 +100,7 @@ import android.database.sqlite.SQLiteDoneException;
|
|||
import android.databinding.DataBindingUtil;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
|
|
@ -346,6 +350,9 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
|||
displayDeathDialogIfNeeded();
|
||||
|
||||
if (!fromLocalDb) {
|
||||
|
||||
displayNewInboxMessagesBadge();
|
||||
|
||||
// Update the oldEntries
|
||||
new Thread(() -> {
|
||||
|
||||
|
|
@ -441,6 +448,31 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
|||
}
|
||||
}
|
||||
|
||||
private void displayNewInboxMessagesBadge() {
|
||||
Integer numberOfUnreadPms = this.user.getInbox().getNewMessages();
|
||||
IDrawerItem newInboxItem;
|
||||
|
||||
if (numberOfUnreadPms <= 0) {
|
||||
newInboxItem = new PrimaryDrawerItem()
|
||||
.withName(this.getString(R.string.sidebar_inbox))
|
||||
.withIdentifier(MainDrawerBuilder.SIDEBAR_INBOX);
|
||||
} else {
|
||||
String numberOfUnreadPmsLabel = String.valueOf(numberOfUnreadPms);
|
||||
BadgeStyle badgeStyle = new BadgeStyle()
|
||||
.withTextColor(Color.WHITE)
|
||||
.withColorRes(R.color.md_red_700);
|
||||
|
||||
newInboxItem = new PrimaryDrawerItem()
|
||||
.withName(this.getString(R.string.sidebar_inbox))
|
||||
.withIdentifier(MainDrawerBuilder.SIDEBAR_INBOX)
|
||||
.withBadge(numberOfUnreadPmsLabel)
|
||||
.withBadgeStyle(badgeStyle);
|
||||
}
|
||||
|
||||
this.drawer.updateItemAtPosition(newInboxItem, MainDrawerBuilder.SIDEBAR_INBOX + 2);
|
||||
}
|
||||
|
||||
|
||||
private void loadAndRemoveOldChecklists(final List<ChecklistItem> onlineEntries) {
|
||||
final ArrayList<String> onlineChecklistItemIdList = new ArrayList<>();
|
||||
|
||||
|
|
|
|||
|
|
@ -7,12 +7,14 @@ import com.habitrpg.android.habitica.events.commands.DeleteChatMessageCommand;
|
|||
import com.habitrpg.android.habitica.events.commands.FlagChatMessageCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.OpenNewPMActivityCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.SendNewGroupMessageCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.SendNewInboxMessageCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.ToggleInnCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.ToggleLikeMessageCommand;
|
||||
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;
|
||||
|
|
@ -26,6 +28,7 @@ import android.support.v4.content.ContextCompat;
|
|||
import android.support.v7.widget.PopupMenu;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
|
@ -51,6 +54,9 @@ public class ChatRecyclerViewAdapter extends RecyclerView.Adapter<ChatRecyclerVi
|
|||
private String uuid;
|
||||
private String groupId;
|
||||
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;
|
||||
|
|
@ -59,6 +65,15 @@ public class ChatRecyclerViewAdapter extends RecyclerView.Adapter<ChatRecyclerVi
|
|||
this.isTavern = isTavern;
|
||||
}
|
||||
|
||||
public void setToInboxChat(String replyToUserUUID) {
|
||||
this.replyToUserUUID = replyToUserUUID;
|
||||
this.isInboxChat = true;
|
||||
}
|
||||
|
||||
public void setSendingUser(HabitRPGUser user) {
|
||||
this.sendingUser = user;
|
||||
}
|
||||
|
||||
public void setMessages(List<ChatMessage> messages) {
|
||||
this.messages = messages;
|
||||
this.notifyDataSetChanged();
|
||||
|
|
@ -229,19 +244,31 @@ 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());
|
||||
|
||||
if (messageText != null) {
|
||||
messageText.setText(msg.parsedText);
|
||||
if (msg.parsedText == null) {
|
||||
messageText.setText(msg.text);
|
||||
}
|
||||
this.messageText.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
|
||||
|
|
@ -376,7 +403,11 @@ public class ChatRecyclerViewAdapter extends RecyclerView.Adapter<ChatRecyclerVi
|
|||
if (textNewMessage != null) {
|
||||
String text = textNewMessage.getText().toString();
|
||||
if (!text.equals("")) {
|
||||
EventBus.getDefault().post(new SendNewGroupMessageCommand(groupId, text));
|
||||
if (isInboxChat) {
|
||||
EventBus.getDefault().post(new SendNewInboxMessageCommand(replyToUserUUID, text));
|
||||
} else {
|
||||
EventBus.getDefault().post(new SendNewGroupMessageCommand(groupId, text));
|
||||
}
|
||||
}
|
||||
textNewMessage.setText("");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,119 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.social;
|
||||
|
||||
import com.facebook.internal.BoltsMeasurementEventListener;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.callbacks.HabitRPGUserCallback;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.ChatMessage;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class InboxFragment extends BaseMainFragment
|
||||
implements SwipeRefreshLayout.OnRefreshListener, View.OnClickListener, HabitRPGUserCallback.OnUserReceived {
|
||||
|
||||
@BindView(R.id.inbox_messages)
|
||||
LinearLayout inboxMessagesListView;
|
||||
|
||||
@BindView(R.id.inbox_refresh_layout)
|
||||
SwipeRefreshLayout swipeRefreshLayout;
|
||||
|
||||
Map<String, ChatMessage> messages;
|
||||
Map<String, String> roomsAdded;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
|
||||
this.apiHelper.apiService.markPrivateMessagesRead()
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(aVoid -> {}, throwable -> {});
|
||||
|
||||
View v = inflater.inflate(R.layout.fragment_inbox, container, false);
|
||||
unbinder = ButterKnife.bind(this, v);
|
||||
|
||||
swipeRefreshLayout.setOnRefreshListener(this);
|
||||
|
||||
this.messages = this.user.getInbox().getMessages();
|
||||
if (this.messages != null) {
|
||||
this.setInboxMessages();
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectFragment(AppComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
swipeRefreshLayout.setRefreshing(true);
|
||||
this.apiHelper.retrieveUser(true)
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(new HabitRPGUserCallback(this), throwable -> {});
|
||||
}
|
||||
|
||||
public void setInboxMessages() {
|
||||
if (this.inboxMessagesListView == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.inboxMessagesListView.removeAllViewsInLayout();
|
||||
|
||||
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
||||
roomsAdded = new HashMap<String, String>();
|
||||
|
||||
Iterator it = this.messages.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry pair = (Map.Entry)it.next();
|
||||
|
||||
ChatMessage message = (ChatMessage) pair.getValue();
|
||||
if (roomsAdded.get(message.user) != null) continue;
|
||||
roomsAdded.put(message.user, message.uuid);
|
||||
|
||||
TextView entry = (TextView) inflater.inflate(R.layout.plain_list_item, this.inboxMessagesListView, false);
|
||||
entry.setText(message.user);
|
||||
entry.setOnClickListener(this);
|
||||
this.inboxMessagesListView.addView(entry);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
TextView entry = (TextView) v;
|
||||
InboxMessageListFragment inboxMessageListFragment = new InboxMessageListFragment();
|
||||
String replyToUserName = entry.getText().toString();
|
||||
inboxMessageListFragment.setMessages(this.messages, replyToUserName, this.roomsAdded.get(replyToUserName));
|
||||
this.activity.displayFragment(inboxMessageListFragment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserReceived(HabitRPGUser user) {
|
||||
this.user = user;
|
||||
this.messages = user.getInbox().getMessages();
|
||||
this.setInboxMessages();
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.social;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.habitrpg.android.habitica.HabiticaApplication;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.callbacks.HabitRPGUserCallback;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.events.commands.SendNewInboxMessageCommand;
|
||||
import com.habitrpg.android.habitica.ui.adapter.social.ChatRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment;
|
||||
import com.habitrpg.android.habitica.ui.helpers.UiUtils;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.ChatMessage;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by keithholliday on 6/20/16.
|
||||
*/
|
||||
public class InboxMessageListFragment extends BaseMainFragment
|
||||
implements SwipeRefreshLayout.OnRefreshListener, HabitRPGUserCallback.OnUserReceived {
|
||||
|
||||
@BindView(R.id.inbox_refresh_layout)
|
||||
SwipeRefreshLayout swipeRefreshLayout;
|
||||
|
||||
@BindView(R.id.chat_list)
|
||||
RecyclerView chatRecyclerView;
|
||||
|
||||
List<ChatMessage> messages;
|
||||
ChatRecyclerViewAdapter chatAdapter;
|
||||
String chatRoomUser;
|
||||
String replyToUserUUID;
|
||||
|
||||
public InboxMessageListFragment() {
|
||||
messages = new ArrayList<ChatMessage>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
|
||||
View view = inflater.inflate(R.layout.fragment_inbox_message_list, container, false);
|
||||
ButterKnife.bind(this, view);
|
||||
swipeRefreshLayout.setOnRefreshListener(this);
|
||||
|
||||
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this.getActivity());
|
||||
chatRecyclerView.setLayoutManager(layoutManager);
|
||||
|
||||
chatAdapter = new ChatRecyclerViewAdapter(messages, null, null, false);
|
||||
chatAdapter.setToInboxChat(this.replyToUserUUID);
|
||||
chatAdapter.setSendingUser(this.user);
|
||||
chatRecyclerView.setAdapter(chatAdapter);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectFragment(AppComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
private void refreshUserInbox () {
|
||||
this.swipeRefreshLayout.setRefreshing(true);
|
||||
this.apiHelper.retrieveUser(true)
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(new HabitRPGUserCallback(this), throwable -> {});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
this.refreshUserInbox();
|
||||
}
|
||||
|
||||
public void setMessages(Map<String, ChatMessage> messages, String chatRoomUser, String replyToUserUUID) {
|
||||
this.chatRoomUser = chatRoomUser;
|
||||
this.replyToUserUUID = replyToUserUUID;
|
||||
|
||||
this.messages = new ArrayList<ChatMessage>();
|
||||
|
||||
Iterator it = messages.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry pair = (Map.Entry)it.next();
|
||||
ChatMessage message = (ChatMessage) pair.getValue();
|
||||
if (!message.user.equals(chatRoomUser)) continue;
|
||||
this.messages.add(0, message);
|
||||
}
|
||||
|
||||
Collections.sort(this.messages,
|
||||
(message1, message2) -> new Date(message2.timestamp).compareTo(new Date(message1.timestamp)));
|
||||
|
||||
if (this.chatAdapter != null) {
|
||||
chatAdapter.setToInboxChat(replyToUserUUID);
|
||||
this.chatAdapter.setMessages(this.messages);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserReceived(HabitRPGUser user) {
|
||||
this.user = user;
|
||||
this.setMessages(user.getInbox().getMessages(), this.chatRoomUser, this.replyToUserUUID);
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEvent(SendNewInboxMessageCommand cmd) {
|
||||
HashMap<String, String> messageObject = new HashMap<>();
|
||||
messageObject.put("message", cmd.Message);
|
||||
messageObject.put("toUserId", cmd.UserToSendTo);
|
||||
|
||||
apiHelper.apiService.postPrivateMessage(messageObject)
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(postChatMessageResult -> {
|
||||
this.refreshUserInbox();
|
||||
}, throwable -> {
|
||||
});
|
||||
|
||||
UiUtils.dismissKeyboard(HabiticaApplication.currentActivity);
|
||||
}
|
||||
}
|
||||
|
|
@ -14,6 +14,7 @@ import com.habitrpg.android.habitica.ui.fragments.inventory.items.ItemsFragment;
|
|||
import com.habitrpg.android.habitica.ui.fragments.inventory.stable.StableFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.skills.SkillsFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.social.GuildsOverviewFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.social.InboxFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.social.TavernFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.social.party.PartyFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.tasks.TasksFragment;
|
||||
|
|
@ -32,6 +33,7 @@ public class MainDrawerBuilder {
|
|||
// Change the identificationIDs to the position IDs so that its easier to set the selected entry
|
||||
public static final int SIDEBAR_TASKS = 0;
|
||||
public static final int SIDEBAR_SKILLS = 1;
|
||||
public static final int SIDEBAR_INBOX = 2;
|
||||
public static final int SIDEBAR_TAVERN = 3;
|
||||
public static final int SIDEBAR_PARTY = 4;
|
||||
public static final int SIDEBAR_GUILDS = 5;
|
||||
|
|
@ -45,7 +47,6 @@ public class MainDrawerBuilder {
|
|||
public static final int SIDEBAR_HELP = 13;
|
||||
public static final int SIDEBAR_ABOUT = 14;
|
||||
|
||||
|
||||
public static AccountHeaderBuilder CreateDefaultAccountHeader(final Activity activity) {
|
||||
return new AccountHeaderBuilder()
|
||||
.withActivity(activity)
|
||||
|
|
@ -73,6 +74,7 @@ public class MainDrawerBuilder {
|
|||
new PrimaryDrawerItem().withName(activity.getString(R.string.sidebar_skills)).withIdentifier(SIDEBAR_SKILLS),
|
||||
|
||||
new SectionIconDrawerItem().withName(activity.getString(R.string.sidebar_section_social).toUpperCase()),
|
||||
new PrimaryDrawerItem().withName(activity.getString(R.string.sidebar_inbox)).withIdentifier(SIDEBAR_INBOX),
|
||||
new PrimaryDrawerItem().withName(activity.getString(R.string.sidebar_tavern)).withIdentifier(SIDEBAR_TAVERN),
|
||||
new PrimaryDrawerItem().withName(activity.getString(R.string.sidebar_party)).withIdentifier(SIDEBAR_PARTY),
|
||||
new PrimaryDrawerItem().withName(activity.getString(R.string.sidebar_guilds)).withIdentifier(SIDEBAR_GUILDS),
|
||||
|
|
@ -106,6 +108,10 @@ public class MainDrawerBuilder {
|
|||
fragment = new SkillsFragment();
|
||||
break;
|
||||
}
|
||||
case SIDEBAR_INBOX: {
|
||||
fragment = new InboxFragment();
|
||||
break;
|
||||
}
|
||||
case SIDEBAR_PARTY: {
|
||||
fragment = new PartyFragment();
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -144,6 +144,9 @@ public interface ApiService {
|
|||
@POST("user/disable-classes")
|
||||
Observable<HabitRPGUser> disableClasses();
|
||||
|
||||
@POST("user/mark-pms-read")
|
||||
Observable<Void> markPrivateMessagesRead();
|
||||
|
||||
/* Group API */
|
||||
|
||||
@GET("groups")
|
||||
|
|
@ -213,6 +216,9 @@ public interface ApiService {
|
|||
@POST("/iap/android/verify")
|
||||
Call<PurchaseValidationResult> validatePurchase(@Body PurchaseValidationRequest request);
|
||||
|
||||
//Members URL
|
||||
@POST("members/send-private-message")
|
||||
Observable<PostChatMessageResult> postPrivateMessage(@Body HashMap<String, String> messageDetails);
|
||||
|
||||
//DEBUG: These calls only work on a local development server
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -43,6 +43,12 @@ public class HabitRPGUser extends BaseModel {
|
|||
foreignColumnName = "id")})
|
||||
private Stats stats;
|
||||
|
||||
@Column
|
||||
@ForeignKey(references = {@ForeignKeyReference(columnName = "inbox_id",
|
||||
columnType = String.class,
|
||||
foreignColumnName = "user_Id")})
|
||||
private Inbox inbox;
|
||||
|
||||
@Column
|
||||
@ForeignKey(references = {@ForeignKeyReference(columnName = "preferences_id",
|
||||
columnType = String.class,
|
||||
|
|
@ -80,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;
|
||||
|
|
@ -104,10 +116,19 @@ public class HabitRPGUser extends BaseModel {
|
|||
return stats;
|
||||
}
|
||||
|
||||
public void setInbox(Inbox inbox) {
|
||||
this.inbox = inbox;
|
||||
}
|
||||
|
||||
public Inbox getInbox() {
|
||||
return inbox;
|
||||
}
|
||||
|
||||
public void setStats(Stats stats) {
|
||||
this.stats = stats;
|
||||
}
|
||||
|
||||
|
||||
public Profile getProfile() {
|
||||
return profile;
|
||||
}
|
||||
|
|
@ -116,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;
|
||||
}
|
||||
|
|
@ -258,9 +288,11 @@ public class HabitRPGUser extends BaseModel {
|
|||
preferences.user_id = id;
|
||||
stats.id = id;
|
||||
profile.user_Id = id;
|
||||
inbox.user_Id = id;
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,115 @@
|
|||
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.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.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by keithholliday on 6/20/16.
|
||||
*/
|
||||
@Table(databaseName = HabitDatabase.NAME)
|
||||
public class Inbox extends BaseModel {
|
||||
|
||||
@Column
|
||||
@PrimaryKey
|
||||
// @NotNull
|
||||
String user_Id;
|
||||
|
||||
@SerializedName("optOut")
|
||||
@Expose
|
||||
private Boolean optOut;
|
||||
|
||||
@SerializedName("messages")
|
||||
@Expose
|
||||
private Map<String, ChatMessage> messages;
|
||||
|
||||
@SerializedName("blocks")
|
||||
@Expose
|
||||
private List<Object> blocks = new ArrayList<Object>();
|
||||
|
||||
@SerializedName("newMessages")
|
||||
@Expose
|
||||
private Integer newMessages;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* The optOut
|
||||
*/
|
||||
public Boolean getOptOut() {
|
||||
return optOut;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param optOut
|
||||
* The optOut
|
||||
*/
|
||||
public void setOptOut(Boolean optOut) {
|
||||
this.optOut = optOut;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* The messages
|
||||
*/
|
||||
public Map<String, ChatMessage> getMessages() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param messages
|
||||
* The messages
|
||||
*/
|
||||
public void setMessages(Map<String, ChatMessage> messages) {
|
||||
this.messages = messages;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* The blocks
|
||||
*/
|
||||
public List<Object> getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param blocks
|
||||
* The blocks
|
||||
*/
|
||||
public void setBlocks(List<Object> blocks) {
|
||||
this.blocks = blocks;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* The newMessages
|
||||
*/
|
||||
public Integer getNewMessages() {
|
||||
return newMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param newMessages
|
||||
* The newMessages
|
||||
*/
|
||||
public void setNewMessages(Integer newMessages) {
|
||||
this.newMessages = newMessages;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue