mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-31 19:20:34 +00:00
Refactor into SocialRepository
This commit is contained in:
parent
03fa516207
commit
529f3f316b
28 changed files with 538 additions and 414 deletions
47
Habitica/res/layout/fragment_chat.xml
Normal file
47
Habitica/res/layout/fragment_chat.xml
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<com.habitrpg.android.habitica.ui.helpers.RecyclerViewEmptySupport
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="@color/brand_200">
|
||||
<ImageButton
|
||||
android:id="@+id/emoji.toggle.btn"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:src="@drawable/ic_emoticon_grey600_24dp"
|
||||
android:scaleType="center"
|
||||
android:backgroundTint="@color/transparent"
|
||||
android:contentDescription="Toogle Emojis"
|
||||
android:layout_gravity="center"/>
|
||||
|
||||
<net.pherth.android.emoji_library.EmojiEditText
|
||||
android:id="@+id/edit.new.message.text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="5dp"
|
||||
android:hint="@string/write_message"
|
||||
android:textColor="@android:color/white"
|
||||
android:inputType="textCapSentences|textMultiLine"
|
||||
style="@style/LoginEditTextTheme"/>
|
||||
<Button
|
||||
android:id="@+id/btn.send.message"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="50dp"
|
||||
android:textColor="@color/white"
|
||||
android:text="@string/post"
|
||||
android:drawableTint="@color/white"
|
||||
android:layout_gravity="center"
|
||||
android:background="@color/transparent"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
@ -1,35 +1,34 @@
|
|||
package com.habitrpg.android.habitica.api;
|
||||
|
||||
import com.habitrpg.android.habitica.models.AchievementResult;
|
||||
import com.habitrpg.android.habitica.models.social.Challenge;
|
||||
import com.habitrpg.android.habitica.models.social.ChatMessage;
|
||||
import com.habitrpg.android.habitica.models.ContentResult;
|
||||
import com.habitrpg.android.habitica.models.social.Group;
|
||||
import com.habitrpg.android.habitica.models.user.HabitRPGUser;
|
||||
import com.habitrpg.android.habitica.models.user.Items;
|
||||
import com.habitrpg.android.habitica.models.LeaveChallengeBody;
|
||||
import com.habitrpg.android.habitica.models.responses.PostChatMessageResult;
|
||||
import com.habitrpg.android.habitica.models.PurchaseValidationRequest;
|
||||
import com.habitrpg.android.habitica.models.PurchaseValidationResult;
|
||||
import com.habitrpg.android.habitica.models.inventory.Quest;
|
||||
import com.habitrpg.android.habitica.models.shops.Shop;
|
||||
import com.habitrpg.android.habitica.models.responses.Status;
|
||||
import com.habitrpg.android.habitica.models.SubscriptionValidationRequest;
|
||||
import com.habitrpg.android.habitica.models.Tag;
|
||||
import com.habitrpg.android.habitica.models.responses.TaskDirectionData;
|
||||
import com.habitrpg.android.habitica.models.auth.UserAuth;
|
||||
import com.habitrpg.android.habitica.models.auth.UserAuthResponse;
|
||||
import com.habitrpg.android.habitica.models.auth.UserAuthSocial;
|
||||
import com.habitrpg.android.habitica.models.inventory.Quest;
|
||||
import com.habitrpg.android.habitica.models.responses.BuyResponse;
|
||||
import com.habitrpg.android.habitica.models.responses.FeedResponse;
|
||||
import com.habitrpg.android.habitica.models.responses.HabitResponse;
|
||||
import com.habitrpg.android.habitica.models.responses.PostChatMessageResult;
|
||||
import com.habitrpg.android.habitica.models.responses.SkillResponse;
|
||||
import com.habitrpg.android.habitica.models.responses.Status;
|
||||
import com.habitrpg.android.habitica.models.responses.TaskDirectionData;
|
||||
import com.habitrpg.android.habitica.models.responses.UnlockResponse;
|
||||
import com.habitrpg.android.habitica.models.shops.Shop;
|
||||
import com.habitrpg.android.habitica.models.social.Challenge;
|
||||
import com.habitrpg.android.habitica.models.social.ChatMessage;
|
||||
import com.habitrpg.android.habitica.models.social.Group;
|
||||
import com.habitrpg.android.habitica.models.tasks.ItemData;
|
||||
import com.habitrpg.android.habitica.models.tasks.Task;
|
||||
import com.habitrpg.android.habitica.models.tasks.TaskList;
|
||||
import com.habitrpg.android.habitica.models.user.HabitRPGUser;
|
||||
import com.habitrpg.android.habitica.models.user.Items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -109,7 +108,7 @@ public interface ApiService {
|
|||
Observable<HabitResponse<TaskDirectionData>> postTaskDirection(@Path("id") String id, @Path("direction") String direction);
|
||||
|
||||
@POST("tasks/{id}/move/to/{position}")
|
||||
Observable<HabitResponse<ArrayList<String>>> postTaskNewPosition(@Path("id") String id, @Path("position") String position);
|
||||
Observable<HabitResponse<List<String>>> postTaskNewPosition(@Path("id") String id, @Path("position") String position);
|
||||
|
||||
@POST("tasks/{taskId}/checklist/{itemId}/score")
|
||||
Observable<HabitResponse<Task>> scoreChecklistItem(@Path("taskId") String taskId, @Path("itemId") String itemId);
|
||||
|
|
@ -273,7 +272,7 @@ public interface ApiService {
|
|||
/* challenges api */
|
||||
|
||||
@GET("challenges/user")
|
||||
Observable<HabitResponse<ArrayList<Challenge>>> getUserChallenges();
|
||||
Observable<HabitResponse<List<Challenge>>> getUserChallenges();
|
||||
|
||||
@GET("tasks/challenge/{challengeId}")
|
||||
Observable<HabitResponse<TaskList>> getChallengeTasks(@Path("challengeId") String challengeId);
|
||||
|
|
|
|||
|
|
@ -4,33 +4,32 @@ import android.support.annotation.Nullable;
|
|||
|
||||
import com.habitrpg.android.habitica.ErrorResponse;
|
||||
import com.habitrpg.android.habitica.models.AchievementResult;
|
||||
import com.habitrpg.android.habitica.models.social.Challenge;
|
||||
import com.habitrpg.android.habitica.models.social.ChatMessage;
|
||||
import com.habitrpg.android.habitica.models.ContentResult;
|
||||
import com.habitrpg.android.habitica.models.social.Group;
|
||||
import com.habitrpg.android.habitica.models.user.HabitRPGUser;
|
||||
import com.habitrpg.android.habitica.models.user.Items;
|
||||
import com.habitrpg.android.habitica.models.LeaveChallengeBody;
|
||||
import com.habitrpg.android.habitica.models.responses.PostChatMessageResult;
|
||||
import com.habitrpg.android.habitica.models.PurchaseValidationRequest;
|
||||
import com.habitrpg.android.habitica.models.PurchaseValidationResult;
|
||||
import com.habitrpg.android.habitica.models.inventory.Quest;
|
||||
import com.habitrpg.android.habitica.models.shops.Shop;
|
||||
import com.habitrpg.android.habitica.models.responses.Status;
|
||||
import com.habitrpg.android.habitica.models.SubscriptionValidationRequest;
|
||||
import com.habitrpg.android.habitica.models.Tag;
|
||||
import com.habitrpg.android.habitica.models.responses.TaskDirectionData;
|
||||
import com.habitrpg.android.habitica.models.auth.UserAuthResponse;
|
||||
import com.habitrpg.android.habitica.models.inventory.Quest;
|
||||
import com.habitrpg.android.habitica.models.responses.BuyResponse;
|
||||
import com.habitrpg.android.habitica.models.responses.FeedResponse;
|
||||
import com.habitrpg.android.habitica.models.responses.HabitResponse;
|
||||
import com.habitrpg.android.habitica.models.responses.PostChatMessageResult;
|
||||
import com.habitrpg.android.habitica.models.responses.SkillResponse;
|
||||
import com.habitrpg.android.habitica.models.responses.Status;
|
||||
import com.habitrpg.android.habitica.models.responses.TaskDirectionData;
|
||||
import com.habitrpg.android.habitica.models.responses.UnlockResponse;
|
||||
import com.habitrpg.android.habitica.models.shops.Shop;
|
||||
import com.habitrpg.android.habitica.models.social.Challenge;
|
||||
import com.habitrpg.android.habitica.models.social.ChatMessage;
|
||||
import com.habitrpg.android.habitica.models.social.Group;
|
||||
import com.habitrpg.android.habitica.models.tasks.ItemData;
|
||||
import com.habitrpg.android.habitica.models.tasks.Task;
|
||||
import com.habitrpg.android.habitica.models.tasks.TaskList;
|
||||
import com.habitrpg.android.habitica.models.user.HabitRPGUser;
|
||||
import com.habitrpg.android.habitica.models.user.Items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -83,7 +82,7 @@ public interface ApiClient {
|
|||
|
||||
Observable<TaskDirectionData> postTaskDirection(String id, String direction);
|
||||
|
||||
Observable<ArrayList<String>> postTaskNewPosition(String id, String position);
|
||||
Observable<List<String>> postTaskNewPosition(String id, String position);
|
||||
|
||||
Observable<Task> scoreChecklistItem(String taskId, String itemId);
|
||||
|
||||
|
|
@ -190,7 +189,7 @@ public interface ApiClient {
|
|||
|
||||
/* challenges api */
|
||||
|
||||
Observable<ArrayList<Challenge>> getUserChallenges();
|
||||
Observable<List<Challenge>> getUserChallenges();
|
||||
|
||||
Observable<TaskList> getChallengeTasks(String challengeId);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
package com.habitrpg.android.habitica.data;
|
||||
|
||||
import com.habitrpg.android.habitica.models.responses.PostChatMessageResult;
|
||||
import com.habitrpg.android.habitica.models.social.Challenge;
|
||||
import com.habitrpg.android.habitica.models.social.ChatMessage;
|
||||
import com.habitrpg.android.habitica.models.social.Group;
|
||||
import com.habitrpg.android.habitica.models.user.HabitRPGUser;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import rx.Observable;
|
||||
|
||||
public interface SocialRepository extends BaseRepository {
|
||||
Observable<List<ChatMessage>> retrieveGroupChat(String groupId);
|
||||
Observable<List<ChatMessage>> getGroupChat(String groupId);
|
||||
|
||||
void markMessagesSeen(String seenGroupId);
|
||||
|
||||
Observable<Void> flagMessage(String groupId, String id);
|
||||
|
||||
Observable<ChatMessage> likeMessage(String groupId, String id);
|
||||
|
||||
Observable<Void> deleteMessage(String groupId, String id);
|
||||
|
||||
Observable<PostChatMessageResult> postGroupChat(String groupId, HashMap<String, String> messageObject);
|
||||
Observable<PostChatMessageResult> postGroupChat(String groupId, String message);
|
||||
|
||||
Observable<Group> retrieveGroup(String id);
|
||||
Observable<Group> getGroup(String id);
|
||||
|
||||
Observable<Void> leaveGroup(String id);
|
||||
|
||||
Observable<Group> joinGroup(String id);
|
||||
|
||||
Observable<Void> updateGroup(Group group);
|
||||
|
||||
Observable<List<Group>> retrieveGroups(String type);
|
||||
Observable<List<Group>> getGroups(String type);
|
||||
|
||||
Observable<PostChatMessageResult> postPrivateMessage(HashMap<String, String> messageObject);
|
||||
Observable<PostChatMessageResult> postPrivateMessage(String recipientId, String message);
|
||||
|
||||
|
||||
Observable<List<HabitRPGUser>> getGroupMembers(String id, boolean includeAllPublicFields);
|
||||
|
||||
Observable<Void> inviteToGroup(String id, Map<String, Object> inviteData);
|
||||
|
||||
Observable<List<Challenge>> getUserChallenges();
|
||||
}
|
||||
|
|
@ -19,4 +19,6 @@ public interface UserRepository extends BaseRepository {
|
|||
Observable<HabitRPGUser> revive(HabitRPGUser user);
|
||||
|
||||
void resetTutorial(@Nullable HabitRPGUser user);
|
||||
|
||||
Observable<HabitRPGUser> sleep(HabitRPGUser user);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -562,7 +562,7 @@ public class ApiClientImpl implements Action1<Throwable>, ApiClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Observable<ArrayList<String>> postTaskNewPosition(String id, String position) {
|
||||
public Observable<List<String>> postTaskNewPosition(String id, String position) {
|
||||
return apiService.postTaskNewPosition(id, position).compose(configureApiCallObserver());
|
||||
}
|
||||
|
||||
|
|
@ -802,7 +802,7 @@ public class ApiClientImpl implements Action1<Throwable>, ApiClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Observable<ArrayList<Challenge>> getUserChallenges() {
|
||||
public Observable<List<Challenge>> getUserChallenges() {
|
||||
return apiService.getUserChallenges().compose(configureApiCallObserver());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,138 @@
|
|||
package com.habitrpg.android.habitica.data.implementation;
|
||||
|
||||
import com.habitrpg.android.habitica.data.ApiClient;
|
||||
import com.habitrpg.android.habitica.data.SocialRepository;
|
||||
import com.habitrpg.android.habitica.data.local.SocialLocalRepository;
|
||||
import com.habitrpg.android.habitica.models.responses.PostChatMessageResult;
|
||||
import com.habitrpg.android.habitica.models.social.Challenge;
|
||||
import com.habitrpg.android.habitica.models.social.ChatMessage;
|
||||
import com.habitrpg.android.habitica.models.social.Group;
|
||||
import com.habitrpg.android.habitica.models.user.HabitRPGUser;
|
||||
import com.habitrpg.android.habitica.ui.helpers.MarkdownParser;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
|
||||
public class SocialRepositoryImpl extends BaseRepositoryImpl<SocialLocalRepository> implements SocialRepository {
|
||||
|
||||
public SocialRepositoryImpl(SocialLocalRepository localRepository, ApiClient apiClient) {
|
||||
super(localRepository, apiClient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<List<ChatMessage>> retrieveGroupChat(String groupId) {
|
||||
return apiClient.listGroupChat(groupId)
|
||||
.flatMap(Observable::from)
|
||||
.map(chatMessage -> {
|
||||
chatMessage.parsedText = MarkdownParser.parseMarkdown(chatMessage.text);
|
||||
return chatMessage;
|
||||
})
|
||||
.toList()
|
||||
.subscribeOn(Schedulers.io());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<List<ChatMessage>> getGroupChat(String groupId) {
|
||||
return retrieveGroupChat(groupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markMessagesSeen(String seenGroupId) {
|
||||
apiClient.seenMessages(seenGroupId).subscribe(aVoid -> {}, throwable -> {});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<Void> flagMessage(String groupId, String id) {
|
||||
return apiClient.flagMessage(groupId, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<ChatMessage> likeMessage(String groupId, String id) {
|
||||
return apiClient.likeMessage(groupId, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<Void> deleteMessage(String groupId, String id) {
|
||||
return apiClient.deleteMessage(groupId, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<PostChatMessageResult> postGroupChat(String groupId, HashMap<String, String> messageObject) {
|
||||
return apiClient.postGroupChat(groupId, messageObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<PostChatMessageResult> postGroupChat(String groupId, String message) {
|
||||
HashMap<String, String> messageObject = new HashMap<>();
|
||||
messageObject.put("message", message);
|
||||
return postGroupChat(groupId, messageObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<Group> retrieveGroup(String id) {
|
||||
return apiClient.getGroup(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<Group> getGroup(String id) {
|
||||
return retrieveGroup(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<Void> leaveGroup(String id) {
|
||||
return apiClient.leaveGroup(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<Group> joinGroup(String id) {
|
||||
return apiClient.joinGroup(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<Void> updateGroup(Group group) {
|
||||
return apiClient.updateGroup(group.id, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<List<Group>> retrieveGroups(String type) {
|
||||
return apiClient.listGroups(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<List<Group>> getGroups(String type) {
|
||||
return retrieveGroups(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<PostChatMessageResult> postPrivateMessage(HashMap<String, String> messageObject) {
|
||||
return apiClient.postPrivateMessage(messageObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<PostChatMessageResult> postPrivateMessage(String recipientId, String message) {
|
||||
HashMap<String, String> messageObject = new HashMap<>();
|
||||
messageObject.put("message", message);
|
||||
messageObject.put("toUserId", recipientId);
|
||||
return postPrivateMessage(messageObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<List<HabitRPGUser>> getGroupMembers(String id, boolean includeAllPublicFields) {
|
||||
return apiClient.getGroupMembers(id, includeAllPublicFields);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<Void> inviteToGroup(String id, Map<String, Object> inviteData) {
|
||||
return apiClient.inviteToGroup(id, inviteData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<List<Challenge>> getUserChallenges() {
|
||||
return apiClient.getUserChallenges();
|
||||
}
|
||||
}
|
||||
|
|
@ -70,6 +70,16 @@ public class UserRepositoryImpl extends BaseRepositoryImpl<UserLocalRepository>
|
|||
.subscribe(tutorialSteps -> {}, throwable -> {});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<HabitRPGUser> sleep(HabitRPGUser user) {
|
||||
return apiClient.sleep()
|
||||
.map(isSleeping -> {
|
||||
user.getPreferences().setSleep(isSleeping);
|
||||
localRepository.saveUser(user);
|
||||
return user;
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private HabitRPGUser mergeUser(@Nullable HabitRPGUser oldUser, HabitRPGUser newUser) {
|
||||
if (oldUser == null) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
package com.habitrpg.android.habitica.data.local;
|
||||
|
||||
public interface SocialLocalRepository extends BaseLocalRepository {
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.habitrpg.android.habitica.data.local.implementation;
|
||||
|
||||
import com.habitrpg.android.habitica.data.local.SocialLocalRepository;
|
||||
|
||||
|
||||
public class DbFlowSocialLocalRepository implements SocialLocalRepository {
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -4,11 +4,11 @@ package com.habitrpg.android.habitica.events.commands;
|
|||
* Created by Negue on 24.08.2015.
|
||||
*/
|
||||
public class SendNewGroupMessageCommand {
|
||||
public String Message;
|
||||
public String TargetGroupId;
|
||||
public String message;
|
||||
public String targetGroupId;
|
||||
|
||||
public SendNewGroupMessageCommand(String targetGroupId, String message) {
|
||||
TargetGroupId = targetGroupId;
|
||||
Message = message;
|
||||
this.targetGroupId = targetGroupId;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ package com.habitrpg.android.habitica.events.commands;
|
|||
* Created by keithholliday on 6/22/16.
|
||||
*/
|
||||
public class SendNewInboxMessageCommand {
|
||||
public String Message;
|
||||
public String UserToSendTo;
|
||||
public String message;
|
||||
public String userToSendTo;
|
||||
|
||||
public SendNewInboxMessageCommand(String userToSendTo, String message) {
|
||||
UserToSendTo = userToSendTo;
|
||||
Message = message;
|
||||
this.userToSendTo = userToSendTo;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,16 +2,20 @@ package com.habitrpg.android.habitica.modules;
|
|||
|
||||
|
||||
import com.habitrpg.android.habitica.data.SetupCustomizationRepository;
|
||||
import com.habitrpg.android.habitica.data.SocialRepository;
|
||||
import com.habitrpg.android.habitica.data.TagRepository;
|
||||
import com.habitrpg.android.habitica.data.TaskRepository;
|
||||
import com.habitrpg.android.habitica.data.UserRepository;
|
||||
import com.habitrpg.android.habitica.data.implementation.SetupCustomizationRepositoryImpl;
|
||||
import com.habitrpg.android.habitica.data.implementation.SocialRepositoryImpl;
|
||||
import com.habitrpg.android.habitica.data.implementation.TagRepositoryImpl;
|
||||
import com.habitrpg.android.habitica.data.implementation.TaskRepositoryImpl;
|
||||
import com.habitrpg.android.habitica.data.implementation.UserRepositoryImpl;
|
||||
import com.habitrpg.android.habitica.data.local.SocialLocalRepository;
|
||||
import com.habitrpg.android.habitica.data.local.TagLocalRepository;
|
||||
import com.habitrpg.android.habitica.data.local.TaskLocalRepository;
|
||||
import com.habitrpg.android.habitica.data.local.UserLocalRepository;
|
||||
import com.habitrpg.android.habitica.data.local.implementation.DbFlowSocialLocalRepository;
|
||||
import com.habitrpg.android.habitica.data.local.implementation.DbFlowTaskLocalRepository;
|
||||
import com.habitrpg.android.habitica.data.local.implementation.DbFlowTagLocalRepository;
|
||||
import com.habitrpg.android.habitica.data.ApiClient;
|
||||
|
|
@ -63,4 +67,14 @@ public class RepositoryModule {
|
|||
UserRepository providesUserRepository(UserLocalRepository localRepository, ApiClient apiClient) {
|
||||
return new UserRepositoryImpl(localRepository, apiClient);
|
||||
}
|
||||
|
||||
@Provides
|
||||
SocialLocalRepository providesSocialLocalRepository() {
|
||||
return new DbFlowSocialLocalRepository();
|
||||
}
|
||||
|
||||
@Provides
|
||||
SocialRepository providesSocialRepository(SocialLocalRepository localRepository, ApiClient apiClient) {
|
||||
return new SocialRepositoryImpl(localRepository, apiClient);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,28 +1,5 @@
|
|||
package com.habitrpg.android.habitica.ui.adapter.social;
|
||||
|
||||
import com.habitrpg.android.habitica.HabiticaApplication;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.events.commands.CopyChatAsTodoCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.CopyChatMessageCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.DeleteChatMessageCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.FlagChatMessageCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.OpenFullProfileCommand;
|
||||
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.habitrpg.android.habitica.models.social.ChatMessage;
|
||||
import com.habitrpg.android.habitica.models.user.HabitRPGUser;
|
||||
|
||||
import net.pherth.android.emoji_library.EmojiEditText;
|
||||
import net.pherth.android.emoji_library.EmojiTextView;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
|
|
@ -38,12 +15,27 @@ import android.view.LayoutInflater;
|
|||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.events.commands.CopyChatAsTodoCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.CopyChatMessageCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.DeleteChatMessageCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.FlagChatMessageCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.OpenFullProfileCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.OpenNewPMActivityCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.ToggleLikeMessageCommand;
|
||||
import com.habitrpg.android.habitica.models.social.ChatMessage;
|
||||
import com.habitrpg.android.habitica.models.user.HabitRPGUser;
|
||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils;
|
||||
|
||||
import net.pherth.android.emoji_library.EmojiTextView;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -52,25 +44,20 @@ import butterknife.BindView;
|
|||
import butterknife.ButterKnife;
|
||||
|
||||
public class ChatRecyclerViewAdapter extends RecyclerView.Adapter<ChatRecyclerViewAdapter.ChatRecyclerViewHolder> {
|
||||
private static final int TYPE_DANIEL = 0;
|
||||
private static final int TYPE_NEW_MESSAGE = 1;
|
||||
private static final int TYPE_MESSAGE = 2;
|
||||
|
||||
private List<ChatMessage> messages;
|
||||
private HabitRPGUser user;
|
||||
private String uuid;
|
||||
private String groupId;
|
||||
private boolean isTavern;
|
||||
private boolean isInboxChat = false;
|
||||
private String replyToUserUUID;
|
||||
private HabitRPGUser sendingUser;
|
||||
|
||||
public ChatRecyclerViewAdapter(List<ChatMessage> messages, HabitRPGUser user, String groupId, boolean isTavern) {
|
||||
public ChatRecyclerViewAdapter(List<ChatMessage> messages, HabitRPGUser user, String groupId) {
|
||||
this.messages = messages;
|
||||
this.user = user;
|
||||
if (user != null) this.uuid = user.getId();
|
||||
this.groupId = groupId;
|
||||
this.isTavern = isTavern;
|
||||
}
|
||||
|
||||
public void setToInboxChat(String replyToUserUUID) {
|
||||
|
|
@ -78,7 +65,7 @@ public class ChatRecyclerViewAdapter extends RecyclerView.Adapter<ChatRecyclerVi
|
|||
this.isInboxChat = true;
|
||||
}
|
||||
|
||||
public void setSendingUser(HabitRPGUser user) {
|
||||
public void setSendingUser(@Nullable HabitRPGUser user) {
|
||||
this.sendingUser = user;
|
||||
}
|
||||
|
||||
|
|
@ -87,106 +74,39 @@ public class ChatRecyclerViewAdapter extends RecyclerView.Adapter<ChatRecyclerVi
|
|||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
switch (position) {
|
||||
case 0: {
|
||||
return isTavern ? TYPE_DANIEL : TYPE_NEW_MESSAGE;
|
||||
}
|
||||
case 1: {
|
||||
return isTavern ? TYPE_NEW_MESSAGE : TYPE_MESSAGE;
|
||||
}
|
||||
default: {
|
||||
return TYPE_MESSAGE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
int rLayout = R.layout.tavern_chat_item;
|
||||
|
||||
switch (viewType) {
|
||||
case TYPE_DANIEL: {
|
||||
rLayout = R.layout.tavern_daniel_item;
|
||||
break;
|
||||
}
|
||||
|
||||
case TYPE_NEW_MESSAGE: {
|
||||
rLayout = R.layout.tavern_chat_new_entry_item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(rLayout, parent, false);
|
||||
|
||||
.inflate(R.layout.tavern_chat_item, parent, false);
|
||||
return new ChatRecyclerViewHolder(view, viewType, uuid, groupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ChatRecyclerViewHolder holder, int position) {
|
||||
if (!isTavern && position > 0) {
|
||||
holder.bind(messages.get(position - 1));
|
||||
return;
|
||||
}
|
||||
|
||||
if (position > 1) {
|
||||
holder.bind(messages.get(position - 2));
|
||||
}
|
||||
holder.bind(messages.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
int messageCount = messages.size();
|
||||
|
||||
if (isTavern) {
|
||||
// if there are no entries, we just show the toggle inn button
|
||||
messageCount += (messageCount == 0) ? 1 : 2;
|
||||
} else {
|
||||
messageCount += 1;
|
||||
}
|
||||
|
||||
return messageCount;
|
||||
return messages != null ? messages.size() : 0;
|
||||
}
|
||||
|
||||
public class ChatRecyclerViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, PopupMenu.OnMenuItemClickListener {
|
||||
|
||||
// Toggle Inn State
|
||||
@BindView(R.id.btn_toggle_inn)
|
||||
@Nullable
|
||||
Button btnToggleInn;
|
||||
// New Msg
|
||||
@BindView(R.id.edit_new_message_text)
|
||||
@Nullable
|
||||
EmojiEditText textNewMessage;
|
||||
@BindView(R.id.btn_send_message)
|
||||
@Nullable
|
||||
Button btnSendNewMessage;
|
||||
@BindView(R.id.btn_options)
|
||||
@Nullable
|
||||
ImageView btnOptions;
|
||||
@BindView(R.id.user_background_layout)
|
||||
@Nullable
|
||||
LinearLayout userBackground;
|
||||
@BindView(R.id.like_background_layout)
|
||||
@Nullable
|
||||
LinearLayout likeBackground;
|
||||
@BindView(R.id.user_label)
|
||||
@Nullable
|
||||
TextView userLabel;
|
||||
@BindView(R.id.message_text)
|
||||
@Nullable
|
||||
EmojiTextView messageText;
|
||||
@BindView(R.id.ago_label)
|
||||
@Nullable
|
||||
TextView agoLabel;
|
||||
@BindView(R.id.tvLikes)
|
||||
@Nullable
|
||||
TextView tvLikes;
|
||||
@BindView(R.id.community_guidelines_view)
|
||||
@Nullable
|
||||
TextView communityGuidelinesView;
|
||||
|
||||
Context context;
|
||||
Resources res;
|
||||
|
|
@ -209,102 +129,58 @@ public class ChatRecyclerViewAdapter extends RecyclerView.Adapter<ChatRecyclerVi
|
|||
|
||||
res = context.getResources();
|
||||
|
||||
switch (layoutType) {
|
||||
case TYPE_DANIEL: {
|
||||
if (btnToggleInn != null) {
|
||||
btnToggleInn.setOnClickListener(this);
|
||||
}
|
||||
|
||||
ViewHelper.SetBackgroundTint(btnToggleInn, ContextCompat.getColor(context, R.color.brand));
|
||||
if (HabiticaApplication.User != null && HabiticaApplication.User.getPreferences().getSleep()) {
|
||||
btnToggleInn.setText(R.string.tavern_inn_checkOut);
|
||||
} else {
|
||||
btnToggleInn.setText(R.string.tavern_inn_rest);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case TYPE_NEW_MESSAGE: {
|
||||
if (btnSendNewMessage != null) {
|
||||
btnSendNewMessage.setOnClickListener(this);
|
||||
}
|
||||
int color = ContextCompat.getColor(context, R.color.brand);
|
||||
|
||||
ViewHelper.SetBackgroundTint(btnSendNewMessage, color);
|
||||
|
||||
// Set up the emoji keyboard
|
||||
EmojiKeyboard.createKeyboard(itemView, context);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
if (btnOptions != null) {
|
||||
btnOptions.setOnClickListener(this);
|
||||
}
|
||||
if (tvLikes != null) {
|
||||
tvLikes.setOnClickListener(this);
|
||||
}
|
||||
}
|
||||
if (btnOptions != null) {
|
||||
btnOptions.setOnClickListener(this);
|
||||
}
|
||||
|
||||
if (communityGuidelinesView != null) {
|
||||
communityGuidelinesView.setPaintFlags(communityGuidelinesView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
||||
communityGuidelinesView.setOnClickListener(v -> {
|
||||
Intent i = new Intent(Intent.ACTION_VIEW);
|
||||
i.setData(Uri.parse("https://habitica.com/static/community-guidelines"));
|
||||
context.startActivity(i);
|
||||
});
|
||||
if (tvLikes != null) {
|
||||
tvLikes.setOnClickListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void bind(final ChatMessage msg) {
|
||||
currentMsg = msg;
|
||||
|
||||
if (layoutType != TYPE_DANIEL && layoutType != TYPE_NEW_MESSAGE) {
|
||||
setLikeProperties(msg);
|
||||
setLikeProperties(msg);
|
||||
|
||||
if (userBackground != null) {
|
||||
if (msg.sent != null && msg.sent.equals("true")) {
|
||||
DataBindingUtils.setRoundedBackgroundInt(userBackground, sendingUser.getContributor().getContributorColor());
|
||||
} else {
|
||||
DataBindingUtils.setRoundedBackgroundInt(userBackground, msg.getContributorColor());
|
||||
}
|
||||
if (userBackground != null) {
|
||||
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) {
|
||||
if (msg.sent != null && msg.sent.equals("true")) {
|
||||
userLabel.setText(sendingUser.getProfile().getName());
|
||||
} else {
|
||||
userLabel.setText(msg.user);
|
||||
}
|
||||
|
||||
if (msg.user == null || msg.user.equals("")) {
|
||||
msg.user = "system";
|
||||
userLabel.setClickable(true);
|
||||
userLabel.setOnClickListener(view -> {
|
||||
OpenFullProfileCommand cmd = new OpenFullProfileCommand(msg.uuid);
|
||||
|
||||
EventBus.getDefault().post(cmd);
|
||||
});
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
if (userLabel != null) {
|
||||
if (msg.sent != null && msg.sent.equals("true")) {
|
||||
userLabel.setText(sendingUser.getProfile().getName());
|
||||
} else {
|
||||
userLabel.setText(msg.user);
|
||||
}
|
||||
|
||||
userLabel.setClickable(true);
|
||||
userLabel.setOnClickListener(view -> {
|
||||
OpenFullProfileCommand cmd = new OpenFullProfileCommand(msg.uuid);
|
||||
|
||||
EventBus.getDefault().post(cmd);
|
||||
});
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
if (agoLabel != null) {
|
||||
agoLabel.setText(msg.getAgoString(res));
|
||||
}
|
||||
if (agoLabel != null) {
|
||||
agoLabel.setText(msg.getAgoString(res));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -417,33 +293,6 @@ public class ChatRecyclerViewAdapter extends RecyclerView.Adapter<ChatRecyclerVi
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (v == btnToggleInn) {
|
||||
EventBus.getDefault().post(new ToggleInnCommand());
|
||||
if (!HabiticaApplication.User.getPreferences().getSleep()) {
|
||||
if (btnToggleInn != null) {
|
||||
btnToggleInn.setText(R.string.tavern_inn_checkOut);
|
||||
}
|
||||
} else {
|
||||
if (btnToggleInn != null) {
|
||||
btnToggleInn.setText(R.string.tavern_inn_rest);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (textNewMessage != null) {
|
||||
String text = textNewMessage.getText().toString();
|
||||
if (!text.equals("")) {
|
||||
if (isInboxChat) {
|
||||
EventBus.getDefault().post(new SendNewInboxMessageCommand(replyToUserUUID, text));
|
||||
} else {
|
||||
EventBus.getDefault().post(new SendNewGroupMessageCommand(groupId, text));
|
||||
}
|
||||
}
|
||||
textNewMessage.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
private void toggleLike() {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.social;
|
||||
|
||||
import com.habitrpg.android.habitica.data.ApiClient;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.data.SocialRepository;
|
||||
import com.habitrpg.android.habitica.data.UserRepository;
|
||||
import com.habitrpg.android.habitica.events.ToggledInnStateEvent;
|
||||
import com.habitrpg.android.habitica.events.commands.CopyChatMessageCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.DeleteChatMessageCommand;
|
||||
|
|
@ -13,7 +14,6 @@ import com.habitrpg.android.habitica.events.commands.ToggleLikeMessageCommand;
|
|||
import com.habitrpg.android.habitica.ui.activities.MainActivity;
|
||||
import com.habitrpg.android.habitica.ui.adapter.social.ChatRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseFragment;
|
||||
import com.habitrpg.android.habitica.ui.helpers.MarkdownParser;
|
||||
import com.habitrpg.android.habitica.ui.helpers.UiUtils;
|
||||
import com.habitrpg.android.habitica.models.social.ChatMessage;
|
||||
import com.habitrpg.android.habitica.models.user.HabitRPGUser;
|
||||
|
|
@ -26,7 +26,6 @@ import org.greenrobot.eventbus.Subscribe;
|
|||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
|
|
@ -38,7 +37,6 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -51,12 +49,12 @@ public class ChatListFragment extends BaseFragment implements SwipeRefreshLayout
|
|||
|
||||
public String seenGroupId;
|
||||
@Inject
|
||||
public ApiClient apiClient;
|
||||
SocialRepository socialRepository;
|
||||
@Inject
|
||||
UserRepository userRepository;
|
||||
public boolean isTavern;
|
||||
@BindView(R.id.recyclerView)
|
||||
RecyclerView mRecyclerView;
|
||||
@BindView(R.id.refresh_layout)
|
||||
SwipeRefreshLayout swipeRefreshLayout;
|
||||
LinearLayoutManager layoutManager;
|
||||
private String groupId;
|
||||
private HabitRPGUser user;
|
||||
|
|
@ -67,7 +65,7 @@ public class ChatListFragment extends BaseFragment implements SwipeRefreshLayout
|
|||
private boolean navigatedOnceToFragment = false;
|
||||
private boolean gotNewMessages = false;
|
||||
|
||||
public void configure(String groupId, HabitRPGUser user, boolean isTavern) {
|
||||
public void configure(String groupId, @Nullable HabitRPGUser user, boolean isTavern) {
|
||||
this.groupId = groupId;
|
||||
this.user = user;
|
||||
if (this.user != null) {
|
||||
|
|
@ -99,7 +97,7 @@ public class ChatListFragment extends BaseFragment implements SwipeRefreshLayout
|
|||
}
|
||||
|
||||
if (view == null)
|
||||
view = inflater.inflate(R.layout.fragment_refresh_recyclerview, container, false);
|
||||
view = inflater.inflate(R.layout.fragment_chat, container, false);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
|
@ -125,7 +123,7 @@ public class ChatListFragment extends BaseFragment implements SwipeRefreshLayout
|
|||
mRecyclerView.setLayoutManager(layoutManager);
|
||||
}
|
||||
|
||||
chatAdapter = new ChatRecyclerViewAdapter(new ArrayList<>(), user, groupId, isTavern);
|
||||
chatAdapter = new ChatRecyclerViewAdapter(new ArrayList<>(), user, groupId);
|
||||
|
||||
mRecyclerView.setAdapter(chatAdapter);
|
||||
|
||||
|
|
@ -136,7 +134,7 @@ public class ChatListFragment extends BaseFragment implements SwipeRefreshLayout
|
|||
public void onRefresh() {
|
||||
swipeRefreshLayout.setRefreshing(true);
|
||||
|
||||
apiClient.listGroupChat(groupId)
|
||||
socialRepository.getGroupChat(groupId)
|
||||
.subscribe(this, throwable -> {
|
||||
});
|
||||
}
|
||||
|
|
@ -154,17 +152,14 @@ public class ChatListFragment extends BaseFragment implements SwipeRefreshLayout
|
|||
|
||||
gotNewMessages = false;
|
||||
|
||||
apiClient.seenMessages(seenGroupId)
|
||||
.subscribe(s -> {
|
||||
}, throwable -> {
|
||||
});
|
||||
socialRepository.markMessagesSeen(seenGroupId);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEvent(CopyChatMessageCommand cmd) {
|
||||
ClipboardManager clipMan = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData chatMessage = ClipData.newPlainText("Chat Message", cmd.chatMessage.text);
|
||||
ClipData chatMessage = ClipData.newPlainText("Chat message", cmd.chatMessage.text);
|
||||
clipMan.setPrimaryClip(chatMessage);
|
||||
MainActivity activity = (MainActivity) getActivity();
|
||||
UiUtils.showSnackbar(activity, activity.getFloatingMenuWrapper(), getString(R.string.chat_message_copied), UiUtils.SnackbarDisplayType.NORMAL);
|
||||
|
|
@ -175,8 +170,7 @@ public class ChatListFragment extends BaseFragment implements SwipeRefreshLayout
|
|||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setMessage(R.string.chat_flag_confirmation)
|
||||
.setPositiveButton(R.string.flag_confirm, (dialog, id) -> {
|
||||
apiClient.flagMessage(cmd.groupId, cmd.chatMessage.id)
|
||||
|
||||
socialRepository.flagMessage(cmd.groupId, cmd.chatMessage.id)
|
||||
.subscribe(aVoid -> {
|
||||
MainActivity activity = (MainActivity) getActivity();
|
||||
UiUtils.showSnackbar(activity, activity.getFloatingMenuWrapper(), "Flagged message by " + cmd.chatMessage.user, UiUtils.SnackbarDisplayType.NORMAL);
|
||||
|
|
@ -190,7 +184,7 @@ public class ChatListFragment extends BaseFragment implements SwipeRefreshLayout
|
|||
|
||||
@Subscribe
|
||||
public void onEvent(final ToggleLikeMessageCommand cmd) {
|
||||
apiClient.likeMessage(cmd.groupId, cmd.chatMessage.id)
|
||||
socialRepository.likeMessage(cmd.groupId, cmd.chatMessage.id)
|
||||
.subscribe(voids -> {
|
||||
}, throwable -> {
|
||||
});
|
||||
|
|
@ -198,12 +192,10 @@ public class ChatListFragment extends BaseFragment implements SwipeRefreshLayout
|
|||
|
||||
@Subscribe
|
||||
public void onEvent(final DeleteChatMessageCommand cmd) {
|
||||
apiClient.deleteMessage(cmd.groupId, cmd.chatMessage.id)
|
||||
|
||||
socialRepository.deleteMessage(cmd.groupId, cmd.chatMessage.id)
|
||||
.subscribe(aVoid -> {
|
||||
if (currentChatMessages != null) {
|
||||
currentChatMessages.remove(cmd.chatMessage);
|
||||
|
||||
ChatListFragment.this.call(currentChatMessages);
|
||||
}
|
||||
}, throwable -> {
|
||||
|
|
@ -212,14 +204,10 @@ public class ChatListFragment extends BaseFragment implements SwipeRefreshLayout
|
|||
|
||||
@Subscribe
|
||||
public void onEvent(SendNewGroupMessageCommand cmd) {
|
||||
HashMap<String, String> messageObject = new HashMap<>();
|
||||
messageObject.put("message", cmd.Message);
|
||||
apiClient.postGroupChat(cmd.TargetGroupId, messageObject)
|
||||
|
||||
socialRepository.postGroupChat(cmd.targetGroupId, cmd.message)
|
||||
.subscribe(postChatMessageResult -> {
|
||||
if (currentChatMessages != null) {
|
||||
currentChatMessages.add(0, postChatMessageResult.message);
|
||||
|
||||
ChatListFragment.this.call(currentChatMessages);
|
||||
}
|
||||
}, throwable -> {
|
||||
|
|
@ -231,13 +219,10 @@ public class ChatListFragment extends BaseFragment implements SwipeRefreshLayout
|
|||
// If the ChatList is Tavern, we're able to toggle the sleep-mode
|
||||
@Subscribe
|
||||
public void onEvent(ToggleInnCommand event) {
|
||||
apiClient.sleep()
|
||||
.subscribe(aVoid -> {
|
||||
userRepository.sleep(user)
|
||||
.subscribe(habitRPGUser -> {
|
||||
ToggledInnStateEvent innState = new ToggledInnStateEvent();
|
||||
innState.Inn = !user.getPreferences().getSleep();
|
||||
|
||||
user.getPreferences().setSleep(innState.Inn);
|
||||
|
||||
innState.Inn = habitRPGUser.getPreferences().getSleep();
|
||||
EventBus.getDefault().post(innState);
|
||||
}, throwable -> {
|
||||
});
|
||||
|
|
@ -255,7 +240,6 @@ public class ChatListFragment extends BaseFragment implements SwipeRefreshLayout
|
|||
public void call(List<ChatMessage> chatMessages) {
|
||||
currentChatMessages = chatMessages;
|
||||
|
||||
//Load unparsed messages first
|
||||
if (chatAdapter != null) {
|
||||
chatAdapter.setMessages(chatMessages);
|
||||
}
|
||||
|
|
@ -263,41 +247,8 @@ public class ChatListFragment extends BaseFragment implements SwipeRefreshLayout
|
|||
if (swipeRefreshLayout != null) {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
|
||||
//Parse chatMessages in AsyncTask
|
||||
ParseMessages parseMessages = new ParseMessages(chatMessages);
|
||||
parseMessages.execute();
|
||||
gotNewMessages = true;
|
||||
|
||||
markMessagesAsSeen();
|
||||
}
|
||||
|
||||
private class ParseMessages extends AsyncTask<Void, Void, Void> {
|
||||
private List<ChatMessage> chatMessages;
|
||||
|
||||
public ParseMessages(List<ChatMessage> chatMessages) {
|
||||
this.chatMessages = chatMessages;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
|
||||
for (int i = 0; i < chatMessages.size(); i++) {
|
||||
chatMessages.get(i).parsedText = MarkdownParser.parseMarkdown(chatMessages.get(i).text);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void onPostExecute(Void result) {
|
||||
if (chatAdapter != null) {
|
||||
chatAdapter.setMessages(chatMessages);
|
||||
}
|
||||
|
||||
if (swipeRefreshLayout != null) {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ public class GroupInformationFragment extends BaseFragment {
|
|||
|
||||
}
|
||||
|
||||
public static GroupInformationFragment newInstance(@Nullable Group group, HabitRPGUser user) {
|
||||
public static GroupInformationFragment newInstance(@Nullable Group group, @Nullable HabitRPGUser user) {
|
||||
Bundle args = new Bundle();
|
||||
|
||||
GroupInformationFragment fragment = new GroupInformationFragment();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.habitrpg.android.habitica.ui.fragments.social;
|
|||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.data.SocialRepository;
|
||||
import com.habitrpg.android.habitica.ui.activities.GroupFormActivity;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment;
|
||||
import com.habitrpg.android.habitica.models.social.Group;
|
||||
|
|
@ -19,10 +20,15 @@ import android.view.MenuItem;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import rx.functions.Action1;
|
||||
|
||||
public class GuildFragment extends BaseMainFragment implements Action1<Group> {
|
||||
|
||||
@Inject
|
||||
SocialRepository socialRepository;
|
||||
|
||||
public boolean isMember;
|
||||
public ViewPager viewPager;
|
||||
private Group guild;
|
||||
|
|
@ -34,8 +40,8 @@ public class GuildFragment extends BaseMainFragment implements Action1<Group> {
|
|||
if (this.guildInformationFragment != null) {
|
||||
this.guildInformationFragment.setGroup(guild);
|
||||
}
|
||||
if (this.guild.chat == null && this.apiClient != null) {
|
||||
apiClient.getGroup(this.guild.id)
|
||||
if (this.guild.chat == null && this.socialRepository != null) {
|
||||
socialRepository.retrieveGroup(this.guild.id)
|
||||
.subscribe(this, throwable -> {
|
||||
});
|
||||
}
|
||||
|
|
@ -65,8 +71,8 @@ public class GuildFragment extends BaseMainFragment implements Action1<Group> {
|
|||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
if (this.apiClient != null && this.guild != null) {
|
||||
apiClient.getGroup(this.guild.id)
|
||||
if (this.socialRepository != null && this.guild != null) {
|
||||
socialRepository.retrieveGroup(this.guild.id)
|
||||
.subscribe(this, throwable -> {
|
||||
});
|
||||
}
|
||||
|
|
@ -74,14 +80,16 @@ public class GuildFragment extends BaseMainFragment implements Action1<Group> {
|
|||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
if (this.isMember) {
|
||||
if (this.user != null && this.user.getId().equals(this.guild.leaderID)) {
|
||||
this.activity.getMenuInflater().inflate(R.menu.guild_admin, menu);
|
||||
if (this.activity != null) {
|
||||
if (this.isMember) {
|
||||
if (this.user != null && this.user.getId().equals(this.guild.leaderID)) {
|
||||
this.activity.getMenuInflater().inflate(R.menu.guild_admin, menu);
|
||||
} else {
|
||||
this.activity.getMenuInflater().inflate(R.menu.guild_member, menu);
|
||||
}
|
||||
} else {
|
||||
this.activity.getMenuInflater().inflate(R.menu.guild_member, menu);
|
||||
this.activity.getMenuInflater().inflate(R.menu.guild_nonmember, menu);
|
||||
}
|
||||
} else {
|
||||
this.activity.getMenuInflater().inflate(R.menu.guild_nonmember, menu);
|
||||
}
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
|
@ -92,14 +100,18 @@ public class GuildFragment extends BaseMainFragment implements Action1<Group> {
|
|||
|
||||
switch (id) {
|
||||
case R.id.menu_guild_join:
|
||||
this.apiClient.joinGroup(this.guild.id)
|
||||
this.socialRepository.joinGroup(this.guild.id)
|
||||
.subscribe(this, throwable -> {
|
||||
});
|
||||
this.isMember = true;
|
||||
return true;
|
||||
case R.id.menu_guild_leave:
|
||||
this.apiClient.leaveGroup(this.guild.id)
|
||||
.subscribe(aVoid -> this.activity.supportInvalidateOptionsMenu(), throwable -> {
|
||||
this.socialRepository.leaveGroup(this.guild.id)
|
||||
.subscribe(aVoid -> {
|
||||
if (this.activity != null) {
|
||||
this.activity.supportInvalidateOptionsMenu();
|
||||
}
|
||||
}, throwable -> {
|
||||
});
|
||||
this.isMember = false;
|
||||
return true;
|
||||
|
|
@ -147,9 +159,9 @@ public class GuildFragment extends BaseMainFragment implements Action1<Group> {
|
|||
public CharSequence getPageTitle(int position) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
return activity.getString(R.string.guild);
|
||||
return getContext().getString(R.string.guild);
|
||||
case 1:
|
||||
return activity.getString(R.string.chat);
|
||||
return getContext().getString(R.string.chat);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
|
@ -220,8 +232,7 @@ public class GuildFragment extends BaseMainFragment implements Action1<Group> {
|
|||
needsSaving = true;
|
||||
}
|
||||
if (needsSaving) {
|
||||
this.apiClient.updateGroup(this.guild.id, this.guild)
|
||||
|
||||
this.socialRepository.updateGroup(this.guild)
|
||||
.subscribe(aVoid -> {
|
||||
}, throwable -> {
|
||||
});
|
||||
|
|
@ -246,7 +257,9 @@ public class GuildFragment extends BaseMainFragment implements Action1<Group> {
|
|||
|
||||
this.guild = group;
|
||||
}
|
||||
this.activity.supportInvalidateOptionsMenu();
|
||||
if (this.activity != null) {
|
||||
this.activity.supportInvalidateOptionsMenu();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,10 +1,5 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.social;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment;
|
||||
import com.habitrpg.android.habitica.models.social.Group;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
|
|
@ -15,14 +10,25 @@ import android.widget.Button;
|
|||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.data.SocialRepository;
|
||||
import com.habitrpg.android.habitica.models.social.Group;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class GuildsOverviewFragment extends BaseMainFragment implements View.OnClickListener, SwipeRefreshLayout.OnRefreshListener {
|
||||
|
||||
@Inject
|
||||
SocialRepository socialRepository;
|
||||
|
||||
@BindView(R.id.my_guilds_listview)
|
||||
LinearLayout guildsListView;
|
||||
|
||||
|
|
@ -68,9 +74,8 @@ public class GuildsOverviewFragment extends BaseMainFragment implements View.OnC
|
|||
}
|
||||
|
||||
private void fetchGuilds() {
|
||||
if (this.apiClient != null && this.apiClient != null) {
|
||||
this.apiClient.listGroups("guilds")
|
||||
|
||||
if (this.socialRepository != null) {
|
||||
this.socialRepository.retrieveGroups("guilds")
|
||||
.subscribe(groups -> {
|
||||
GuildsOverviewFragment.this.guilds = groups;
|
||||
GuildsOverviewFragment.this.setGuildsOnListView();
|
||||
|
|
@ -100,16 +105,20 @@ public class GuildsOverviewFragment extends BaseMainFragment implements View.OnC
|
|||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
BaseMainFragment fragment;
|
||||
if (v == this.publicGuildsButton) {
|
||||
PublicGuildsFragment publicGuildsFragment = new PublicGuildsFragment();
|
||||
publicGuildsFragment.memberGuildIDs = this.guildIDs;
|
||||
this.activity.displayFragment(publicGuildsFragment);
|
||||
fragment = publicGuildsFragment;
|
||||
} else {
|
||||
Integer guildIndex = ((ViewGroup) v.getParent()).indexOfChild(v);
|
||||
GuildFragment guildFragment = new GuildFragment();
|
||||
guildFragment.setGuild(this.guilds.get(guildIndex));
|
||||
guildFragment.isMember = true;
|
||||
this.activity.displayFragment(guildFragment);
|
||||
fragment = guildFragment;
|
||||
}
|
||||
if (this.activity != null) {
|
||||
this.activity.displayFragment(fragment);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.habitrpg.android.habitica.ui.fragments.social;
|
|||
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.data.UserRepository;
|
||||
import com.habitrpg.android.habitica.prefs.scanner.IntentIntegrator;
|
||||
import com.habitrpg.android.habitica.prefs.scanner.IntentResult;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment;
|
||||
|
|
@ -31,12 +32,17 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class InboxFragment extends BaseMainFragment
|
||||
implements SwipeRefreshLayout.OnRefreshListener, View.OnClickListener, HabitRPGUserCallback.OnUserReceived {
|
||||
|
||||
@Inject
|
||||
UserRepository userRepository;
|
||||
|
||||
@BindView(R.id.inbox_messages)
|
||||
LinearLayout inboxMessagesListView;
|
||||
|
||||
|
|
@ -53,7 +59,6 @@ public class InboxFragment extends BaseMainFragment
|
|||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
|
||||
this.apiClient.markPrivateMessagesRead()
|
||||
|
||||
.subscribe(aVoid -> {
|
||||
}, throwable -> {
|
||||
});
|
||||
|
|
@ -75,7 +80,9 @@ public class InboxFragment extends BaseMainFragment
|
|||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
this.activity.getMenuInflater().inflate(R.menu.inbox, menu);
|
||||
if (this.activity != null) {
|
||||
this.activity.getMenuInflater().inflate(R.menu.inbox, menu);
|
||||
}
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
|
|
@ -92,6 +99,7 @@ public class InboxFragment extends BaseMainFragment
|
|||
}
|
||||
|
||||
private void openNewMessageDialog() {
|
||||
assert this.activity != null;
|
||||
this.chooseRecipientDialogView = this.activity.getLayoutInflater().inflate(R.layout.dialog_choose_message_recipient, null);
|
||||
|
||||
Button scaneQRCodeButton = (Button) chooseRecipientDialogView.findViewById(R.id.scanQRCodeButton);
|
||||
|
|
@ -123,8 +131,8 @@ public class InboxFragment extends BaseMainFragment
|
|||
@Override
|
||||
public void onRefresh() {
|
||||
swipeRefreshLayout.setRefreshing(true);
|
||||
this.apiClient.retrieveUser(true)
|
||||
.subscribe(new HabitRPGUserCallback(this), throwable -> {
|
||||
this.userRepository.retrieveUser(true)
|
||||
.subscribe(this::onUserReceived, throwable -> {
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -173,7 +181,9 @@ public class InboxFragment extends BaseMainFragment
|
|||
private void openInboxMessages(String userID, String username) {
|
||||
InboxMessageListFragment inboxMessageListFragment = new InboxMessageListFragment();
|
||||
inboxMessageListFragment.setMessages(this.messages, username, userID);
|
||||
this.activity.displayFragment(inboxMessageListFragment);
|
||||
if (this.activity != null) {
|
||||
this.activity.displayFragment(inboxMessageListFragment);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package com.habitrpg.android.habitica.ui.fragments.social;
|
|||
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.data.SocialRepository;
|
||||
import com.habitrpg.android.habitica.data.UserRepository;
|
||||
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;
|
||||
|
|
@ -26,6 +28,8 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
|
|
@ -35,6 +39,11 @@ import butterknife.ButterKnife;
|
|||
public class InboxMessageListFragment extends BaseMainFragment
|
||||
implements SwipeRefreshLayout.OnRefreshListener, HabitRPGUserCallback.OnUserReceived {
|
||||
|
||||
@Inject
|
||||
SocialRepository socialRepository;
|
||||
@Inject
|
||||
UserRepository userRepository;
|
||||
|
||||
@BindView(R.id.refresh_layout)
|
||||
SwipeRefreshLayout swipeRefreshLayout;
|
||||
|
||||
|
|
@ -47,7 +56,7 @@ public class InboxMessageListFragment extends BaseMainFragment
|
|||
String replyToUserUUID;
|
||||
|
||||
public InboxMessageListFragment() {
|
||||
messages = new ArrayList<ChatMessage>();
|
||||
messages = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -62,7 +71,7 @@ public class InboxMessageListFragment extends BaseMainFragment
|
|||
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this.getActivity());
|
||||
chatRecyclerView.setLayoutManager(layoutManager);
|
||||
|
||||
chatAdapter = new ChatRecyclerViewAdapter(messages, user, null, false);
|
||||
chatAdapter = new ChatRecyclerViewAdapter(messages, user, null);
|
||||
chatAdapter.setToInboxChat(this.replyToUserUUID);
|
||||
chatAdapter.setSendingUser(this.user);
|
||||
chatRecyclerView.setAdapter(chatAdapter);
|
||||
|
|
@ -75,12 +84,11 @@ public class InboxMessageListFragment extends BaseMainFragment
|
|||
component.inject(this);
|
||||
}
|
||||
|
||||
private void refreshUserInbox () {
|
||||
this.swipeRefreshLayout.setRefreshing(true);
|
||||
this.apiClient.retrieveUser(true)
|
||||
|
||||
.subscribe(new HabitRPGUserCallback(this), throwable -> {});
|
||||
}
|
||||
private void refreshUserInbox () {
|
||||
this.swipeRefreshLayout.setRefreshing(true);
|
||||
this.userRepository.retrieveUser(true)
|
||||
.subscribe(this::onUserReceived, throwable -> {});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
|
|
@ -118,17 +126,9 @@ public class InboxMessageListFragment extends BaseMainFragment
|
|||
|
||||
@Subscribe
|
||||
public void onEvent(SendNewInboxMessageCommand cmd) {
|
||||
HashMap<String, String> messageObject = new HashMap<>();
|
||||
messageObject.put("message", cmd.Message);
|
||||
messageObject.put("toUserId", cmd.UserToSendTo);
|
||||
|
||||
apiClient.postPrivateMessage(messageObject)
|
||||
|
||||
.subscribe(postChatMessageResult -> {
|
||||
this.refreshUserInbox();
|
||||
}, throwable -> {
|
||||
});
|
||||
|
||||
socialRepository.postPrivateMessage(cmd.userToSendTo, cmd.message)
|
||||
.subscribe(postChatMessageResult -> this.refreshUserInbox(), throwable -> {
|
||||
});
|
||||
UiUtils.dismissKeyboard(getActivity());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.habitrpg.android.habitica.ui.fragments.social;
|
|||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.data.SocialRepository;
|
||||
import com.habitrpg.android.habitica.ui.adapter.social.PublicGuildsRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment;
|
||||
import com.habitrpg.android.habitica.ui.helpers.UiUtils;
|
||||
|
|
@ -23,11 +24,16 @@ import android.view.ViewGroup;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class PublicGuildsFragment extends BaseMainFragment implements SearchView.OnQueryTextListener {
|
||||
|
||||
@Inject
|
||||
SocialRepository socialRepository;
|
||||
|
||||
List<String> memberGuildIDs;
|
||||
List<Group> guilds;
|
||||
|
||||
|
|
@ -36,7 +42,6 @@ public class PublicGuildsFragment extends BaseMainFragment implements SearchView
|
|||
|
||||
private View view;
|
||||
private PublicGuildsRecyclerViewAdapter viewAdapter;
|
||||
private SearchView guildSearchView;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
|
|
@ -71,9 +76,8 @@ public class PublicGuildsFragment extends BaseMainFragment implements SearchView
|
|||
}
|
||||
|
||||
private void fetchGuilds() {
|
||||
if (this.apiClient != null) {
|
||||
this.apiClient.listGroups("publicGuilds")
|
||||
|
||||
if (this.socialRepository != null) {
|
||||
this.socialRepository.getGroups("publicGuilds")
|
||||
.subscribe(groups -> {
|
||||
PublicGuildsFragment.this.guilds = groups;
|
||||
if (PublicGuildsFragment.this.viewAdapter != null) {
|
||||
|
|
@ -89,9 +93,9 @@ public class PublicGuildsFragment extends BaseMainFragment implements SearchView
|
|||
inflater.inflate(R.menu.menu_public_guild, menu);
|
||||
|
||||
MenuItem searchItem = menu.findItem(R.id.action_guild_search);
|
||||
guildSearchView = (SearchView) searchItem.getActionView();
|
||||
SearchView guildSearchView = (SearchView) searchItem.getActionView();
|
||||
SearchView.SearchAutoComplete theTextArea = (SearchView.SearchAutoComplete) guildSearchView.findViewById(R.id.search_src_text);
|
||||
theTextArea.setHintTextColor(ContextCompat.getColor(this.activity, R.color.white));
|
||||
theTextArea.setHintTextColor(ContextCompat.getColor(getContext(), R.color.white));
|
||||
guildSearchView.setQueryHint(getString(R.string.guild_search_hint));
|
||||
guildSearchView.setOnQueryTextListener(this);
|
||||
|
||||
|
|
@ -100,7 +104,9 @@ public class PublicGuildsFragment extends BaseMainFragment implements SearchView
|
|||
@Override
|
||||
public boolean onQueryTextSubmit(String s) {
|
||||
viewAdapter.getFilter().filter(s);
|
||||
UiUtils.dismissKeyboard(this.activity);
|
||||
if (this.activity != null) {
|
||||
UiUtils.dismissKeyboard(this.activity);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.habitrpg.android.habitica.ui.fragments.social;
|
|||
import com.habitrpg.android.habitica.ContentCache;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.data.SocialRepository;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment;
|
||||
import com.habitrpg.android.habitica.models.social.Group;
|
||||
|
||||
|
|
@ -18,6 +19,9 @@ import javax.inject.Inject;
|
|||
|
||||
public class TavernFragment extends BaseMainFragment {
|
||||
|
||||
@Inject
|
||||
SocialRepository socialRepository;
|
||||
|
||||
public ViewPager viewPager;
|
||||
Group tavern;
|
||||
|
||||
|
|
@ -53,8 +57,8 @@ public class TavernFragment extends BaseMainFragment {
|
|||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
if (this.apiClient != null) {
|
||||
apiClient.getGroup("habitrpg")
|
||||
if (this.socialRepository != null) {
|
||||
socialRepository.getGroup("habitrpg")
|
||||
.subscribe(group -> {
|
||||
TavernFragment.this.tavern = group;
|
||||
if (group.quest != null && group.quest.key != null && TavernFragment.this.isAdded()) {
|
||||
|
|
@ -118,9 +122,9 @@ public class TavernFragment extends BaseMainFragment {
|
|||
public CharSequence getPageTitle(int position) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
return activity.getString(R.string.chat);
|
||||
return getContext().getString(R.string.chat);
|
||||
case 1:
|
||||
return activity.getString(R.string.world_quest);
|
||||
return getContext().getString(R.string.world_quest);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
|
|||
|
||||
private ChallengeFilterOptions lastFilterOptions;
|
||||
|
||||
public void setObservable(Observable<ArrayList<Challenge>> listObservable) {
|
||||
public void setObservable(Observable<List<Challenge>> listObservable) {
|
||||
listObservable
|
||||
.subscribe(challenges -> {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,6 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.social.challenges;
|
||||
|
||||
|
||||
import com.habitrpg.android.habitica.helpers.TaskFilterHelper;
|
||||
import com.habitrpg.android.habitica.data.ApiClient;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.ui.adapter.tasks.BaseTasksRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.adapter.tasks.SortableTasksRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseFragment;
|
||||
import com.habitrpg.android.habitica.ui.viewHolders.tasks.BaseTaskViewHolder;
|
||||
import com.habitrpg.android.habitica.ui.viewHolders.tasks.DailyViewHolder;
|
||||
import com.habitrpg.android.habitica.ui.viewHolders.tasks.HabitViewHolder;
|
||||
import com.habitrpg.android.habitica.ui.viewHolders.tasks.RewardViewHolder;
|
||||
import com.habitrpg.android.habitica.ui.viewHolders.tasks.TodoViewHolder;
|
||||
import com.habitrpg.android.habitica.models.user.HabitRPGUser;
|
||||
import com.habitrpg.android.habitica.models.tasks.Task;
|
||||
|
||||
import android.content.Context;
|
||||
import android.databinding.ObservableList;
|
||||
import android.os.Bundle;
|
||||
|
|
@ -27,6 +12,20 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.helpers.TaskFilterHelper;
|
||||
import com.habitrpg.android.habitica.models.tasks.Task;
|
||||
import com.habitrpg.android.habitica.models.user.HabitRPGUser;
|
||||
import com.habitrpg.android.habitica.ui.adapter.tasks.BaseTasksRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.adapter.tasks.SortableTasksRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseFragment;
|
||||
import com.habitrpg.android.habitica.ui.viewHolders.tasks.BaseTaskViewHolder;
|
||||
import com.habitrpg.android.habitica.ui.viewHolders.tasks.DailyViewHolder;
|
||||
import com.habitrpg.android.habitica.ui.viewHolders.tasks.HabitViewHolder;
|
||||
import com.habitrpg.android.habitica.ui.viewHolders.tasks.RewardViewHolder;
|
||||
import com.habitrpg.android.habitica.ui.viewHolders.tasks.TodoViewHolder;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
|
|
@ -36,8 +35,6 @@ public class ChallengeTasksRecyclerViewFragment extends BaseFragment {
|
|||
@Inject
|
||||
@Named("UserID")
|
||||
String userID;
|
||||
@Inject
|
||||
ApiClient apiClient;
|
||||
|
||||
ObservableList<Task> tasksOnInitialize;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.habitrpg.android.habitica.ui.fragments.social.challenges;
|
|||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.data.SocialRepository;
|
||||
import com.habitrpg.android.habitica.events.commands.ShowChallengeDetailActivityCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.ShowChallengeDetailDialogCommand;
|
||||
import com.habitrpg.android.habitica.ui.activities.ChallengeDetailActivity;
|
||||
|
|
@ -22,18 +23,24 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import rx.subjects.PublishSubject;
|
||||
|
||||
public class ChallengesOverviewFragment extends BaseMainFragment {
|
||||
|
||||
@Inject
|
||||
SocialRepository socialRepository;
|
||||
|
||||
public ViewPager viewPager;
|
||||
public FragmentStatePagerAdapter statePagerAdapter;
|
||||
int currentPage;
|
||||
private Stack<Integer> pageHistory;
|
||||
private boolean saveToHistory;
|
||||
private PublishSubject<ArrayList<Challenge>> getUserChallengesObservable;
|
||||
private PublishSubject<List<Challenge>> getUserChallengesObservable;
|
||||
private ChallengeListFragment userChallengesFragment;
|
||||
private ChallengeListFragment availableChallengesFragment;
|
||||
|
||||
|
|
@ -71,8 +78,7 @@ public class ChallengesOverviewFragment extends BaseMainFragment {
|
|||
}
|
||||
|
||||
private void subscribeGetChallenges() {
|
||||
this.apiClient.getUserChallenges()
|
||||
|
||||
this.socialRepository.getUserChallenges()
|
||||
.subscribe(challenges -> getUserChallengesObservable.onNext(challenges),
|
||||
e -> getUserChallengesObservable.onError(e));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.habitrpg.android.habitica.ui.fragments.social.party;
|
|||
import com.habitrpg.android.habitica.ContentCache;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.data.SocialRepository;
|
||||
import com.habitrpg.android.habitica.ui.activities.GroupFormActivity;
|
||||
import com.habitrpg.android.habitica.ui.activities.PartyInviteActivity;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment;
|
||||
|
|
@ -37,6 +38,9 @@ import javax.inject.Inject;
|
|||
|
||||
public class PartyFragment extends BaseMainFragment {
|
||||
|
||||
@Inject
|
||||
SocialRepository socialRepository;
|
||||
|
||||
public ViewPager viewPager;
|
||||
@Inject
|
||||
ContentCache contentCache;
|
||||
|
|
@ -60,7 +64,8 @@ public class PartyFragment extends BaseMainFragment {
|
|||
|
||||
// Get the full group data
|
||||
if (this.user != null && this.user.getParty() != null && this.user.getParty().id != null) {
|
||||
apiClient.getGroup("party")
|
||||
socialRepository.getGroup("party")
|
||||
.filter(group1 -> group1 != null)
|
||||
.subscribe(group -> {
|
||||
if (group == null) {
|
||||
return;
|
||||
|
|
@ -69,8 +74,7 @@ public class PartyFragment extends BaseMainFragment {
|
|||
|
||||
updateGroupUI();
|
||||
|
||||
apiClient.getGroupMembers(group.id, true)
|
||||
|
||||
socialRepository.getGroupMembers(group.id, true)
|
||||
.subscribe(members -> {
|
||||
PartyFragment.this.group.members = members;
|
||||
updateGroupUI();
|
||||
|
|
@ -122,7 +126,9 @@ public class PartyFragment extends BaseMainFragment {
|
|||
chatListFragment.seenGroupId = group.id;
|
||||
}
|
||||
|
||||
PartyFragment.this.activity.supportInvalidateOptionsMenu();
|
||||
if (this.activity != null) {
|
||||
this.activity.supportInvalidateOptionsMenu();
|
||||
}
|
||||
|
||||
if (group != null && group.quest != null && group.quest.key != null && !group.quest.key.isEmpty()) {
|
||||
contentCache.getQuestContent(group.quest.key, content -> {
|
||||
|
|
@ -166,7 +172,7 @@ public class PartyFragment extends BaseMainFragment {
|
|||
.setMessage(viewPager.getContext().getString(R.string.party_leave_confirmation))
|
||||
.setPositiveButton(viewPager.getContext().getString(R.string.yes), (dialog, which) -> {
|
||||
if (this.group != null){
|
||||
this.apiClient.leaveGroup(this.group.id)
|
||||
this.socialRepository.leaveGroup(this.group.id)
|
||||
.subscribe(group -> getActivity().getSupportFragmentManager().beginTransaction().remove(PartyFragment.this).commit(), throwable -> {
|
||||
});
|
||||
}
|
||||
|
|
@ -220,8 +226,7 @@ public class PartyFragment extends BaseMainFragment {
|
|||
needsSaving = true;
|
||||
}
|
||||
if (needsSaving) {
|
||||
this.apiClient.updateGroup(this.group.id, this.group)
|
||||
|
||||
this.socialRepository.updateGroup(this.group)
|
||||
.subscribe(aVoid -> {
|
||||
}, throwable -> {
|
||||
});
|
||||
|
|
@ -251,8 +256,7 @@ public class PartyFragment extends BaseMainFragment {
|
|||
inviteData.put("uuids", invites);
|
||||
}
|
||||
if (this.group != null) {
|
||||
this.apiClient.inviteToGroup(this.group.id, inviteData)
|
||||
|
||||
this.socialRepository.inviteToGroup(this.group.id, inviteData)
|
||||
.subscribe(aVoid -> {
|
||||
}, throwable -> {
|
||||
});
|
||||
|
|
@ -323,11 +327,11 @@ public class PartyFragment extends BaseMainFragment {
|
|||
public CharSequence getPageTitle(int position) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
return activity.getString(R.string.party);
|
||||
return getContext().getString(R.string.party);
|
||||
case 1:
|
||||
return activity.getString(R.string.chat);
|
||||
return getContext().getString(R.string.chat);
|
||||
case 2:
|
||||
return activity.getString(R.string.members);
|
||||
return getContext().getString(R.string.members);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ public class PartyMemberListFragment extends BaseFragment {
|
|||
private PartyMemberRecyclerViewAdapter viewAdapter;
|
||||
private View view;
|
||||
|
||||
public void configure(Context ctx, @Nullable List<HabitRPGUser> members) {
|
||||
public void configure(@Nullable Context ctx, @Nullable List<HabitRPGUser> members) {
|
||||
this.ctx = ctx;
|
||||
this.members = members;
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public class UiUtils {
|
|||
*
|
||||
* @param context Context.
|
||||
* @param container Parent view where Snackbar will appear.
|
||||
* @param content Message.
|
||||
* @param content message.
|
||||
*/
|
||||
public static void showSnackbar(Context context, View container, String content, SnackbarDisplayType displayType) {
|
||||
Snackbar snackbar = Snackbar.make(container, content, Snackbar.LENGTH_LONG);
|
||||
|
|
|
|||
Loading…
Reference in a new issue