-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add chat MVP framework and message repository foundation
- Loading branch information
1 parent
f2d6f3d
commit 8408a6b
Showing
10 changed files
with
215 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...ger/factory/src/main/java/com/savypan/italker/factory/data/message/MessageDataSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.savypan.italker.factory.data.message; | ||
|
||
import com.savypan.italker.factory.data.DBDataSource; | ||
import com.savypan.italker.factory.model.db.Message; | ||
|
||
/*** | ||
* 消息的数据源定义 | ||
* 它的实现是MessageRepository, 关注的对象是Message table | ||
*/ | ||
public interface MessageDataSource extends DBDataSource<Message> { | ||
} |
66 changes: 66 additions & 0 deletions
66
...ger/factory/src/main/java/com/savypan/italker/factory/data/message/MessageRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.savypan.italker.factory.data.message; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
import com.raizlabs.android.dbflow.sql.language.OperatorGroup; | ||
import com.raizlabs.android.dbflow.sql.language.SQLite; | ||
import com.raizlabs.android.dbflow.structure.database.transaction.QueryTransaction; | ||
import com.savypan.italker.factory.data.BaseDBRepository; | ||
import com.savypan.italker.factory.model.db.Message; | ||
import com.savypan.italker.factory.model.db.Message_Table; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/*** | ||
* 跟某人聊天的时候的聊天记录列表 | ||
* 关注的内容要么是我发给这个人的,要么是这个人发给我的 | ||
*/ | ||
public class MessageRepository extends BaseDBRepository<Message> | ||
implements MessageDataSource { | ||
|
||
private String receiverId; //聊天的对象Id | ||
|
||
public MessageRepository(String receiverId) { | ||
super(); | ||
this.receiverId = receiverId; | ||
} | ||
|
||
|
||
@Override | ||
public void load(SuccessCallback<List<Message>> callback) { | ||
super.load(callback); | ||
SQLite.select() | ||
.from(Message.class) | ||
.where(OperatorGroup.clause().and(Message_Table.sender_id.eq(receiverId)) | ||
.and(Message_Table.group_id.isNull())) | ||
.or(Message_Table.receiver_id.eq(receiverId)) | ||
.orderBy(Message_Table.createAt, false) | ||
.limit(30) | ||
.async() | ||
.queryListResultCallback(this) | ||
.execute(); | ||
} | ||
|
||
|
||
@Override | ||
protected boolean isQualifiedUser(Message data) { | ||
//处理合理接收者的判断逻辑 | ||
// 1. 非群聊消息的情况下,发送消息给我的人是我发送消息的接收者 | ||
// 2. 如果消息的接收者不为空,那一定是发送给某个人的,这个人只能是我或者某个人 | ||
// 3. 如果这个"某个人"就是receiverId,那么就是我需要关注的信息 | ||
return (receiverId.equalsIgnoreCase(data.getSender().getId()) | ||
&& data.getGroup() == null) | ||
|| | ||
(data.getReceiver() != null | ||
&& data.getReceiver().getId().equalsIgnoreCase(receiverId)); | ||
} | ||
|
||
|
||
@Override | ||
public void onListQueryResult(QueryTransaction transaction, @NonNull List<Message> tResult) { | ||
//倒序操作 | ||
Collections.reverse(tResult); | ||
super.onListQueryResult(transaction, tResult); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...ager/factory/src/main/java/com/savypan/italker/factory/presenter/mesage/ChatContract.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.savypan.italker.factory.presenter.mesage; | ||
|
||
import com.savypan.italker.factory.model.db.Group; | ||
import com.savypan.italker.factory.model.db.Message; | ||
import com.savypan.italker.factory.model.db.User; | ||
import com.savypan.italker.factory.presenter.BaseContract; | ||
|
||
public interface ChatContract { | ||
interface IPresenter extends BaseContract.IPresenter { | ||
void transText(String content); | ||
void transAudio(String path); | ||
void transImage(String[] paths); | ||
boolean isRetrans(Message message); //resend a message, return if it is being distributed | ||
} | ||
|
||
interface IView<InitModel> extends BaseContract.IRecyclerView<Message, IPresenter> { | ||
void onInit(InitModel model); | ||
} | ||
|
||
//人聊天的界面 | ||
interface IUserView extends IView<User> { | ||
|
||
} | ||
|
||
//群聊天的界面 | ||
interface IGroupView extends IView<Group> { | ||
|
||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...ger/factory/src/main/java/com/savypan/italker/factory/presenter/mesage/ChatPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.savypan.italker.factory.presenter.mesage; | ||
|
||
import com.savypan.italker.factory.data.message.MessageDataSource; | ||
import com.savypan.italker.factory.model.db.Message; | ||
import com.savypan.italker.factory.presenter.BaseSourcePresenter; | ||
|
||
import java.util.List; | ||
|
||
/*** | ||
* 聊天presenter的基础类 | ||
*/ | ||
public class ChatPresenter<View extends ChatContract.IView> | ||
extends BaseSourcePresenter<Message, Message, MessageDataSource, View> | ||
implements ChatContract.IPresenter{ | ||
|
||
public ChatPresenter(View view, MessageDataSource source) { | ||
super(view, source); | ||
} | ||
|
||
@Override | ||
public void onDataLoaded(List<Message> messages) { | ||
|
||
} | ||
|
||
@Override | ||
public void transText(String content) { | ||
|
||
} | ||
|
||
@Override | ||
public void transAudio(String path) { | ||
|
||
} | ||
|
||
@Override | ||
public void transImage(String[] paths) { | ||
|
||
} | ||
|
||
@Override | ||
public boolean isRetrans(Message message) { | ||
return false; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...er/factory/src/main/java/com/savypan/italker/factory/presenter/mesage/GroupPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.savypan.italker.factory.presenter.mesage; | ||
|
||
public class GroupPresenter { | ||
} |
4 changes: 4 additions & 0 deletions
4
...ger/factory/src/main/java/com/savypan/italker/factory/presenter/mesage/UserPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.savypan.italker.factory.presenter.mesage; | ||
|
||
public class UserPresenter { | ||
} |