新增自动打招呼功能
This commit is contained in:
@@ -7,6 +7,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
import com.mango.core.base.IModel;
|
||||
import com.mango.core.bean.response.ServiceResult;
|
||||
import com.mango.core.home.bean.MainTabInfo;
|
||||
import com.mango.core.initial.bean.BoxInfo;
|
||||
import com.mango.core.initial.bean.InitInfo;
|
||||
@@ -14,6 +15,7 @@ import com.mango.core.initial.bean.InitInfo;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Single;
|
||||
import retrofit2.http.GET;
|
||||
|
||||
/**
|
||||
* @author: hewenhao
|
||||
@@ -55,4 +57,8 @@ public interface IInitialModel extends IModel {
|
||||
int getTeenagerMode();
|
||||
|
||||
int getDefaultHomeTab();
|
||||
|
||||
void heartbeat();
|
||||
|
||||
void startApp();
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@ import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.bumptech.glide.request.FutureTarget;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.mango.core.user.event.LoadLoginUserInfoEvent;
|
||||
import com.netease.nim.uikit.support.glide.GlideApp;
|
||||
import com.mango.core.DemoCache;
|
||||
import com.mango.core.base.BaseModel;
|
||||
@@ -36,12 +37,22 @@ import com.mango.xchat_android_library.utils.JavaUtil;
|
||||
import com.mango.xchat_android_library.utils.ListUtils;
|
||||
import com.mango.xchat_android_library.utils.NetworkUtils;
|
||||
import com.mango.xchat_android_library.utils.config.BasicConfig;
|
||||
import com.tencent.bugly.proguard.A;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.reactivex.Flowable;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableSource;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.SingleOnSubscribe;
|
||||
import io.reactivex.SingleSource;
|
||||
@@ -106,6 +117,7 @@ public class InitialModel extends BaseModel implements IInitialModel {
|
||||
|
||||
private InitialModel() {
|
||||
api = RxNet.create(Api.class);
|
||||
EventBus.getDefault().register(this);
|
||||
loadMainTabInfoList();
|
||||
List<MainTabInfo> tabInfoList = DemoCache.readMainTabInfoList();
|
||||
if (ListUtils.isListEmpty(tabInfoList)) {
|
||||
@@ -180,6 +192,12 @@ public class InitialModel extends BaseModel implements IInitialModel {
|
||||
));
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onLoadLoginUserInfoEvent(LoadLoginUserInfoEvent event) {
|
||||
heartbeat();
|
||||
startApp();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public LiveData<List<MainTabInfo>> getMainTabInfosLiveData() {
|
||||
@@ -196,11 +214,11 @@ public class InitialModel extends BaseModel implements IInitialModel {
|
||||
api.init()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread()).doFinally(new Action() {
|
||||
@Override
|
||||
public void run() {
|
||||
requesting = false;
|
||||
}
|
||||
})
|
||||
@Override
|
||||
public void run() {
|
||||
requesting = false;
|
||||
}
|
||||
})
|
||||
.flatMap((Function<ServiceResult<InitInfo>, SingleSource<InitInfo>>) initInfoServiceResult -> {
|
||||
if (initInfoServiceResult.isSuccess() && initInfoServiceResult.getData() != null) {
|
||||
CurrentTimeUtils.initTime(initInfoServiceResult.getTimestamp());
|
||||
@@ -440,6 +458,22 @@ public class InitialModel extends BaseModel implements IInitialModel {
|
||||
return defaultHomeTab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heartbeat() {
|
||||
Observable.timer(30, TimeUnit.SECONDS)
|
||||
.flatMap(aLong -> api.heartbeat())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.doFinally(this::heartbeat)
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startApp() {
|
||||
api.startApp()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFindNewbieCharmLevel() {
|
||||
return findNewbieCharmLevel;
|
||||
@@ -454,6 +488,22 @@ public class InitialModel extends BaseModel implements IInitialModel {
|
||||
@GET("/client/init")
|
||||
Single<ServiceResult<InitInfo>> init();
|
||||
|
||||
/**
|
||||
* 心跳接口
|
||||
*
|
||||
* @return -
|
||||
*/
|
||||
@POST("/client/heartbeat")
|
||||
Observable<ServiceResult<String>> heartbeat();
|
||||
|
||||
/**
|
||||
* 心跳接口
|
||||
*
|
||||
* @return -
|
||||
*/
|
||||
@POST("/client/start_app")
|
||||
Single<ServiceResult<String>> startApp();
|
||||
|
||||
/**
|
||||
* 获取首页Tab配置
|
||||
*
|
||||
|
@@ -8,8 +8,10 @@ import com.mango.core.bean.response.ServiceResult;
|
||||
import com.mango.core.home.bean.VisitorInfo;
|
||||
import com.mango.core.user.bean.GiftAchievementInfo;
|
||||
import com.mango.core.user.bean.GiftWallInfo;
|
||||
import com.mango.core.user.bean.HelloUserInfo;
|
||||
import com.mango.core.user.bean.NewUserInfo;
|
||||
import com.mango.core.user.bean.ProtocolInfo;
|
||||
import com.mango.core.user.bean.SayHelloInfo;
|
||||
import com.mango.core.user.bean.UserDetailInfo;
|
||||
import com.mango.core.user.bean.UserGameInfo;
|
||||
import com.mango.core.user.bean.UserInfo;
|
||||
@@ -18,6 +20,9 @@ import com.mango.core.user.bean.UserRandomConfig;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Single;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
/**
|
||||
* Created by chenran on 2017/3/15.
|
||||
@@ -229,4 +234,34 @@ public interface IUserModel extends IModel {
|
||||
Single<String> visitUserDetail(long uid);
|
||||
|
||||
Single<List<VisitorInfo>> getVisitorUserList(int pageNum, int pageSize);
|
||||
|
||||
|
||||
/**
|
||||
* 主播评级信息
|
||||
*
|
||||
* @return -
|
||||
*/
|
||||
Single<SayHelloInfo> getSayHelloInfo();
|
||||
|
||||
/**
|
||||
* 开启关闭自动打招呼
|
||||
*
|
||||
* @return -
|
||||
*/
|
||||
Single<String> enableSayHello(boolean enable);
|
||||
|
||||
/**
|
||||
* 打招呼列表
|
||||
*
|
||||
* @return -
|
||||
*/
|
||||
Single<List<HelloUserInfo>> getSayHelloList();
|
||||
|
||||
/**
|
||||
* 点击私聊按钮
|
||||
*
|
||||
* @return -
|
||||
*/
|
||||
Single<String> clickSayHelloChat(long toUserUid);
|
||||
|
||||
}
|
||||
|
@@ -22,8 +22,10 @@ import com.mango.core.level.event.LevelUpEvent;
|
||||
import com.mango.core.noble.NobleUtil;
|
||||
import com.mango.core.user.bean.GiftAchievementInfo;
|
||||
import com.mango.core.user.bean.GiftWallInfo;
|
||||
import com.mango.core.user.bean.HelloUserInfo;
|
||||
import com.mango.core.user.bean.NewUserInfo;
|
||||
import com.mango.core.user.bean.ProtocolInfo;
|
||||
import com.mango.core.user.bean.SayHelloInfo;
|
||||
import com.mango.core.user.bean.UserDetailInfo;
|
||||
import com.mango.core.user.bean.UserGameInfo;
|
||||
import com.mango.core.user.bean.UserInfo;
|
||||
@@ -65,27 +67,21 @@ import retrofit2.http.Query;
|
||||
|
||||
public final class UserModel extends BaseModel implements IUserModel {
|
||||
private static final String TAG = "UserModel";
|
||||
|
||||
private final Api api = RxNet.create(Api.class);
|
||||
private volatile UserInfo currentUserInfo = null;
|
||||
private volatile LruCache<Long, UserInfo> cache = new LruCache<>(50);
|
||||
private final Api api = RxNet.create(Api.class);
|
||||
|
||||
//用户信息不全的情况下,currentUserInfo并不会被保存,这里单独保存下预填写的邀请码...
|
||||
private String preFillInviteCode;
|
||||
|
||||
private static final class Helper {
|
||||
public static final IUserModel INSTANCE = new UserModel();
|
||||
}
|
||||
|
||||
public static IUserModel get() {
|
||||
return Helper.INSTANCE;
|
||||
}
|
||||
|
||||
private UserModel() {
|
||||
super();
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
public static IUserModel get() {
|
||||
return Helper.INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录进来接受事件
|
||||
*
|
||||
@@ -106,7 +102,6 @@ public final class UserModel extends BaseModel implements IUserModel {
|
||||
onLogout();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户等级升级从后台刷新一下用户信息
|
||||
*
|
||||
@@ -127,8 +122,6 @@ public final class UserModel extends BaseModel implements IUserModel {
|
||||
updateCurrentUserInfo().subscribe();
|
||||
}
|
||||
|
||||
/******************************************************************************************************/
|
||||
|
||||
/**
|
||||
* 登录后第一次获取用户信息
|
||||
*
|
||||
@@ -174,6 +167,8 @@ public final class UserModel extends BaseModel implements IUserModel {
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************************************/
|
||||
|
||||
private void onLogout() {
|
||||
currentUserInfo = null;
|
||||
cache.evictAll();
|
||||
@@ -345,7 +340,6 @@ public final class UserModel extends BaseModel implements IUserModel {
|
||||
.compose(RxHelper.handleSchedulers());
|
||||
}
|
||||
|
||||
|
||||
//此方法兼容其他端,其他端最好改为 return Single的同名方法
|
||||
@Override
|
||||
public void requestCompleteUserInfo(final UserInfo userInfo, String shareChannel, String shareUid, String roomUid) {
|
||||
@@ -572,8 +566,8 @@ public final class UserModel extends BaseModel implements IUserModel {
|
||||
@Override
|
||||
public Single<List<GiftWallInfo>> requestUserGiftWall(long uid, int giftType, int orderType) {
|
||||
return api.giftWall(String.valueOf(uid),
|
||||
giftType,
|
||||
String.valueOf(orderType))
|
||||
giftType,
|
||||
String.valueOf(orderType))
|
||||
.compose(RxHelper.handleBeanData())
|
||||
.compose(RxHelper.handleSchedulers());
|
||||
}
|
||||
@@ -584,7 +578,6 @@ public final class UserModel extends BaseModel implements IUserModel {
|
||||
.compose(RxHelper.handleSchedulers());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 重置支付密码
|
||||
*
|
||||
@@ -649,7 +642,6 @@ public final class UserModel extends BaseModel implements IUserModel {
|
||||
.compose(RxHelper.singleMainResult());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Single<String> useOrDelete(long id, int status) {
|
||||
return api.useOrDeleteTag(id, status)
|
||||
@@ -753,7 +745,7 @@ public final class UserModel extends BaseModel implements IUserModel {
|
||||
|
||||
@Override
|
||||
public Single<ServiceResult> deleteInRoomRecord(@Nullable String roomUid) {
|
||||
return api.deleteInRoomRecord(AuthModel.get().getCurrentUid(),roomUid)
|
||||
return api.deleteInRoomRecord(AuthModel.get().getCurrentUid(), roomUid)
|
||||
.compose(RxHelper.handleSchAndExce());
|
||||
}
|
||||
|
||||
@@ -818,7 +810,33 @@ public final class UserModel extends BaseModel implements IUserModel {
|
||||
.compose(RxHelper.handleSchedulers());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Single<SayHelloInfo> getSayHelloInfo() {
|
||||
return api.getSayHelloInfo()
|
||||
.compose(RxHelper.handleBeanData())
|
||||
.compose(RxHelper.handleSchedulers());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Single<String> enableSayHello(boolean enable) {
|
||||
return api.enableSayHello(enable)
|
||||
.compose(RxHelper.handleStringData())
|
||||
.compose(RxHelper.handleSchedulers());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Single<List<HelloUserInfo>> getSayHelloList() {
|
||||
return api.getSayHelloList()
|
||||
.compose(RxHelper.handleBeanData())
|
||||
.compose(RxHelper.handleSchedulers());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Single<String> clickSayHelloChat(long toUserUid) {
|
||||
return api.clickSayHelloChat(toUserUid)
|
||||
.compose(RxHelper.handleStringData())
|
||||
.compose(RxHelper.handleSchedulers());
|
||||
}
|
||||
|
||||
private interface Api {
|
||||
/**
|
||||
@@ -1043,5 +1061,44 @@ public final class UserModel extends BaseModel implements IUserModel {
|
||||
@GET("/uservisitrecord/visitUserList")
|
||||
Single<ServiceResult<List<VisitorInfo>>> getVisitorUserList(@Query("pageNum") int pageNum,
|
||||
@Query("pageSize") int pageSize);
|
||||
|
||||
/**
|
||||
* 主播评级信息
|
||||
*
|
||||
* @return -
|
||||
*/
|
||||
@POST("shunt/level_info")
|
||||
Single<ServiceResult<SayHelloInfo>> getSayHelloInfo();
|
||||
|
||||
/**
|
||||
* 开启关闭自动打招呼
|
||||
*
|
||||
* @return -
|
||||
*/
|
||||
@FormUrlEncoded
|
||||
@POST("shunt/enable")
|
||||
Single<ServiceResult<String>> enableSayHello(@Field("enable") boolean enable);
|
||||
|
||||
/**
|
||||
* 打招呼列表
|
||||
*
|
||||
* @return -
|
||||
*/
|
||||
@POST("shunt/list")
|
||||
Single<ServiceResult<List<HelloUserInfo>>> getSayHelloList();
|
||||
|
||||
/**
|
||||
* 点击私聊按钮
|
||||
*
|
||||
* @return -
|
||||
*/
|
||||
@FormUrlEncoded
|
||||
@POST("shunt/click_chat")
|
||||
Single<ServiceResult<String>> clickSayHelloChat(@Field("toUserId") long toUserUid);
|
||||
|
||||
}
|
||||
|
||||
private static final class Helper {
|
||||
public static final IUserModel INSTANCE = new UserModel();
|
||||
}
|
||||
}
|
||||
|
13
core/src/main/java/com/mango/core/user/bean/HelloUserInfo.kt
Normal file
13
core/src/main/java/com/mango/core/user/bean/HelloUserInfo.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.mango.core.user.bean
|
||||
|
||||
import com.mango.core.level.UserLevelVo
|
||||
|
||||
data class HelloUserInfo(
|
||||
val avatar: String = "",
|
||||
val content: String = "",
|
||||
val gender: Int = 0,
|
||||
val name: String = "",
|
||||
val onlineDesc: String = "",
|
||||
val uid: Long = 0,
|
||||
val userLevelVo: UserLevelVo? = null
|
||||
)
|
@@ -0,0 +1,9 @@
|
||||
package com.mango.core.user.bean
|
||||
|
||||
data class SayHelloInfo(
|
||||
val currentLevel: String = "",
|
||||
val currentMultiple: Int = 0,
|
||||
val helloCount: Int = 0,
|
||||
val desc: String = "",
|
||||
val enable: Boolean = false
|
||||
)
|
Reference in New Issue
Block a user