ImIn.kt 9.22 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 12 13
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
import com.netease.nimlib.sdk.uinfo.UserService
import com.netease.nimlib.sdk.uinfo.constant.UserInfoFieldEnum
konghaorui committed
14 15
import com.ydl.confide.api.IConfideService
import com.ydl.course.api.ICourseService
konghaorui committed
16 17 18 19
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
20
import com.ydl.ydlcommon.data.http.GsonProvider
konghaorui committed
21 22
import com.ydl.ydlcommon.modular.ModularServiceManager
import com.ydl.ydlcommon.router.IYDLRouterConstant
konghaorui committed
23 24 25 26 27
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
28 29
import com.yidianling.im.config.constants.UserPreferences
import com.yidianling.im.preference.IMCache
konghaorui committed
30
import com.yidianling.tests.api.service.ITestsApiService
konghaorui committed
31
import com.yidianling.uikit.api.NimUIKit
konghaorui committed
32
import com.yidianling.user.api.bean.UserResponseBean
konghaorui committed
33
import com.yidianling.user.api.service.IAppService
konghaorui committed
34 35 36 37 38 39 40 41 42
import com.yidianling.user.api.service.IUserService

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

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

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

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

konghaorui committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
    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
79 80 81 82
    /**
     * 获取专家主页url
     */
    fun getExpertHost(): String {
刘鹏 committed
83
        return  HttpConfig.MH5_URL + "jy/experts/"
konghaorui committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


    fun inputPhoneIntent(activity: Activity, smsAction: String): Intent? {
konghaorui committed
175
        return getUserService().inputPhoneIntent(activity, smsAction)
konghaorui committed
176 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
    }

    /**
     * 获取私聊未读数
     */
    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
266
        return getUserService()?.isLogin()?:false
konghaorui committed
267 268
    }

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

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

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

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

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

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

    fun getGlobalInfo(): GlobalInfo? {
        return PlatformDataManager.getRam().getGlobalInfo()
    }
296 297 298 299 300 301 302 303
    /**
     * 调用优先使用一键登录,并返回调用时的登录状态,
     * @param isOpenDialog true:一键登录使用弹窗展示 false:一键登录使用全屏模式
     * @return true:已登录,不触发登录跳转,false:未登录,优先一键登录
     * */
    fun loginByOneKeyLogin(context: Context, isOpenDialog: Boolean) :Boolean{
        return getUserService().loginByOneKeyLogin(context,isOpenDialog)
    }
konghaorui committed
304
}