ImIn.kt 9.45 KB
Newer Older
konghaorui committed
1 2 3 4 5 6
package com.yidianling.im.router

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.util.Log
konghaorui committed
7
import com.alibaba.android.arouter.launcher.ARouter
konghaorui committed
8 9 10 11
import com.netease.nimlib.sdk.NIMClient
import com.netease.nimlib.sdk.RequestCallback
import com.netease.nimlib.sdk.auth.LoginInfo
import com.netease.nimlib.sdk.msg.MsgService
霍志良 committed
12
import com.netease.nimlib.sdk.msg.model.IMMessage
konghaorui committed
13 14
import com.netease.nimlib.sdk.uinfo.UserService
import com.netease.nimlib.sdk.uinfo.constant.UserInfoFieldEnum
konghaorui committed
15 16
import com.ydl.confide.api.IConfideService
import com.ydl.course.api.ICourseService
konghaorui committed
17 18 19 20
import com.ydl.ydl_router.manager.YDLRouterManager
import com.ydl.ydlcommon.base.config.HttpConfig
import com.ydl.ydlcommon.bean.GlobalInfo
import com.ydl.ydlcommon.data.PlatformDataManager
konghaorui committed
21
import com.ydl.ydlcommon.data.http.GsonProvider
konghaorui committed
22 23
import com.ydl.ydlcommon.modular.ModularServiceManager
import com.ydl.ydlcommon.router.IYDLRouterConstant
konghaorui committed
24 25 26 27 28
import com.yidianling.consultant.api.IConsultantService
import com.yidianling.dynamic.api.IDynamicService
import com.yidianling.fm.api.service.IFMService
import com.yidianling.im.api.bean.ReceiveRedPacketParam
import com.yidianling.im.api.service.IImService
konghaorui committed
29 30
import com.yidianling.im.config.constants.UserPreferences
import com.yidianling.im.preference.IMCache
konghaorui committed
31
import com.yidianling.tests.api.service.ITestsApiService
konghaorui committed
32
import com.yidianling.uikit.api.NimUIKit
konghaorui committed
33
import com.yidianling.user.api.bean.UserResponseBean
konghaorui committed
34
import com.yidianling.user.api.service.IAppService
konghaorui committed
35 36 37 38 39 40 41 42 43
import com.yidianling.user.api.service.IUserService

/**
 * 功能输入接口
 * 暴漏给app模块使用
 * Created by hgw on 2018/3/19.
 */
object ImIn {

konghaorui committed
44 45 46 47 48 49
    fun getImService(): IImService {
        return ModularServiceManager.provide(IImService::class.java)
    }

    fun getAppService(): IAppService {
        return ModularServiceManager.provide(IAppService::class.java)
konghaorui committed
50 51
    }

konghaorui committed
52 53 54 55
    fun getUserService(): IUserService {
        return ModularServiceManager.provide(IUserService::class.java)
    }

konghaorui committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
    fun getDynamicService(): IDynamicService {
        return ModularServiceManager.provide(IDynamicService::class.java)
    }

    fun getCourseService(): ICourseService{
        return ModularServiceManager.provide(ICourseService::class.java)
    }

    fun getTestsService(): ITestsApiService{
        return ModularServiceManager.provide(ITestsApiService::class.java)
    }

    fun getFMService(): IFMService{
        return ModularServiceManager.provide(IFMService::class.java)
    }

    fun getConsultService(): IConsultantService {
        return ModularServiceManager.provide(IConsultantService::class.java)
    }

    fun getConfideService(): IConfideService {
        return ModularServiceManager.provide(IConfideService::class.java)
    }

konghaorui committed
80 81 82 83
    /**
     * 获取专家主页url
     */
    fun getExpertHost(): String {
刘鹏 committed
84
        return  HttpConfig.MH5_URL + "jy/experts/"
konghaorui committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98
    }

    fun getShareExpertHost(): String {
        return  HttpConfig.MH5_URL+ "experts/"
    }

    fun getReserveHost(): String {
        return  HttpConfig.H5_URL+"booking/order-detail?orderid="
    }

    /**
     * 更新用户设置
     */
    fun setChatTeamHisShowed(){
konghaorui committed
99
        getUserService()?.setChatTeamHisShowed(true)
konghaorui committed
100 101 102 103 104 105 106
    }

    /**
     * 是否登录
     */
    fun isLogin(activity: Context,flag : Boolean):Boolean{
        if (!isLogin() && flag) {
107
            getUserService().loginByOneKeyLogin(activity,true)
konghaorui committed
108 109 110 111 112 113 114
            return false
        }else{
            return true
        }
    }

    fun membersIntent(activity: Activity, userId: String): Intent? {
konghaorui committed
115
        return getDynamicService().membersIntent(activity, userId)
konghaorui committed
116 117 118
    }

    fun replayInfoIntent(activity: Activity, replyId: String, aid: String): Intent? {
konghaorui committed
119
        return getDynamicService().replyInfoIntent(activity, replyId, aid)
konghaorui committed
120 121
    }

konghaorui committed
122 123
    fun myRedPockIntent(activity: Activity){
        getAppService().myRedPockIntent(activity)
konghaorui committed
124 125 126
    }

    fun trendsDetailIntent(activity: Activity, trendId: Int): Intent? {
konghaorui committed
127
        return getDynamicService().trendsDetailIntent(activity, trendId)
konghaorui committed
128 129 130
    }

    fun trendsDetailIntent(activity: Activity, trendId: Int, isScrollToZan: Boolean): Intent? {
konghaorui committed
131
        return getDynamicService().trendsDetailIntent(activity, trendId, isScrollToZan)
konghaorui committed
132 133 134
    }

    fun trendsDetailIntent(activity: Activity, trendId: Int, isScrollToZan: Boolean, lastId: Int): Intent? {
konghaorui committed
135
        return getDynamicService().trendsDetailIntent(activity, trendId, isScrollToZan, lastId)
konghaorui committed
136 137 138 139 140
    }

    /**
     * 跳转话题详情
     */
ydl committed
141
    fun topicDetailActivity(context: Activity,topic_id : String){
konghaorui committed
142
        var intent = getDynamicService().topicDetailIntent(context, false,topic_id)
konghaorui committed
143 144 145 146 147 148 149 150
        intent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        context.startActivity(intent)
    }

    /**
     * 课程专题页面
     */
    fun courseTopic(activity: Activity,id : String){
konghaorui committed
151
        getCourseService().courseTopic(activity,id)
konghaorui committed
152 153 154
    }

    fun fmDetailIntent(activity: Activity, id: Int): Intent? {
konghaorui committed
155
        return getFMService().fmDetailIntent(activity, id)
konghaorui committed
156 157
    }

konghaorui committed
158
    fun sendRedPacketIntent(activity: Activity, toUid: String,code:Int){
159
        ARouter.getInstance().build("/user/sendRedPacket").withString("to_uid",toUid).navigation(activity,code)
konghaorui committed
160 161 162
    }

    fun testResultH5(testResultId: Int){
konghaorui committed
163
        getTestsService().testH5Result(testResultId.toString())
konghaorui committed
164 165 166
    }

    fun testDetailH5(testId: Int){
konghaorui committed
167
        getTestsService().testDetailH5(testId.toString());
konghaorui committed
168 169
    }

konghaorui committed
170 171
    fun receiveRedPacketIntent(activity: Activity, param: ReceiveRedPacketParam){
        getAppService().receiverRedPacketIntent(activity, GsonProvider.getGson().toJson(param))
konghaorui committed
172 173 174 175
    }


    fun inputPhoneIntent(activity: Activity, smsAction: String): Intent? {
konghaorui committed
176
        return getUserService().inputPhoneIntent(activity, smsAction)
konghaorui committed
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
    }

    /**
     * 获取私聊未读数
     */
    fun getInUnreadNum():Int{
        return NIMClient.getService(MsgService::class.java).getTotalUnreadCount()
    }

    /**
     * 登录im
     */
    fun loginIm(uid : String,pwd : String){
        var info = LoginInfo(uid, pwd);
        var callback :  RequestCallback<LoginInfo>  = object : RequestCallback<LoginInfo> {
            override fun onSuccess(param: LoginInfo?) {
                Log.d("", "")
            }

            override fun onFailed(code: Int) {
            }

            override fun onException(exception: Throwable?) {
            }
        }
        IMCache.setAccount(uid)
        //此代码进行登录,并且会进行回调
        NimUIKit.login(info, callback);
    }

    fun loginIm(uid : String,pwd : String,callback: RequestCallback<LoginInfo>){
        var info = LoginInfo(uid, pwd);
        IMCache.setAccount(uid)
        //此代码进行登录,并且会进行回调
        NimUIKit.login(info, callback);
    }

    /**
     * 更新听筒模式
     */
    fun updateEarMode(boo : Boolean){
        NimUIKit.setEarPhoneModeEnable(boo)
    }

    /**
     * 获取当前听筒模式是否开启
     */
    fun getEarModeIsOpen() : Boolean{
        return NimUIKit.isEarPhoneModeEnable()
    }

    /**
     * 更新用户头像
     */
    fun updateUserHead(head : String){
        var fields = HashMap<UserInfoFieldEnum,Any>(1)
        fields.put(UserInfoFieldEnum.AVATAR, head)
        NIMClient.getService(UserService::class.java).updateUserInfo(fields)
    }

    /**
     * 更新用户昵称
     */
    fun updateUserName(name : String){
        var fields = HashMap<UserInfoFieldEnum,Any>(1)
        fields.put(UserInfoFieldEnum.Name, name)
        NIMClient.getService(UserService::class.java).updateUserInfo(fields)
    }

    /**
     * 设置通知声音开关
     */
    fun setRing(boo: Boolean){
        val config = UserPreferences.getStatusConfig()
        config.ring = boo
        UserPreferences.setStatusConfig(config)
        NIMClient.updateStatusBarNotificationConfig(config)
    }

    /**
     * 设置震动开关
     */
    fun setVibrate(boo: Boolean){
        val config = UserPreferences.getStatusConfig()
        config.vibrate = boo
        UserPreferences.setStatusConfig(config)
        NIMClient.updateStatusBarNotificationConfig(config)
    }

    fun isLogin(): Boolean {
konghaorui committed
267
        return getUserService()?.isLogin()?:false
konghaorui committed
268 269
    }

konghaorui committed
270 271
    fun getUserInfo(): UserResponseBean.UserInfo? {
        return getUserService().getUserInfo()
konghaorui committed
272 273
    }

konghaorui committed
274 275
    fun getUserResponse():UserResponseBean?{
        return getUserService().getUserResponse()
konghaorui committed
276
    }
konghaorui committed
277

konghaorui committed
278
    fun getChatTeamHisShow(): Boolean {
konghaorui committed
279
        return getUserService().getChatTeamHisShow()?:false
konghaorui committed
280 281 282
    }

    fun loginWayIntent(context: Context): Intent? {
konghaorui committed
283
        return getUserService().loginWayIntent(context)
konghaorui committed
284 285
    }

konghaorui committed
286 287
    fun mainIntent(context: Context, selectTab: Int){
        getAppService().mainIntent(context, selectTab, false)
konghaorui committed
288 289
    }

konghaorui committed
290 291
    fun feedBackIntent(activity: Activity){
        getAppService().feedBackIntent(activity)
konghaorui committed
292 293 294 295 296
    }

    fun getGlobalInfo(): GlobalInfo? {
        return PlatformDataManager.getRam().getGlobalInfo()
    }
297 298 299 300 301 302 303 304
    /**
     * 调用优先使用一键登录,并返回调用时的登录状态,
     * @param isOpenDialog true:一键登录使用弹窗展示 false:一键登录使用全屏模式
     * @return true:已登录,不触发登录跳转,false:未登录,优先一键登录
     * */
    fun loginByOneKeyLogin(context: Context, isOpenDialog: Boolean) :Boolean{
        return getUserService().loginByOneKeyLogin(context,isOpenDialog)
    }
霍志良 committed
305 306 307 308 309 310 311 312
    lateinit var  imMessage:IMMessage

    fun setLocalExten(imMessage:IMMessage){
        this.imMessage=imMessage
    }
    fun getImmessage():IMMessage {
        return imMessage
    }
konghaorui committed
313
}