MainActivity.kt 7.75 KB
Newer Older
konghaorui committed
1 2
package com.ydl.component

konghaorui committed
3
//import com.ydl.confide.home.ConfideHomeActivity
4 5
import android.Manifest
import android.annotation.SuppressLint
konghaorui committed
6 7
import android.content.ComponentName
import android.content.Context
8
import android.content.Intent
konghaorui committed
9
import android.content.ServiceConnection
10
import android.net.Uri
konghaorui committed
11
import android.os.IBinder
12
import android.provider.Settings
konghaorui committed
13
import android.util.Log
14
import com.alibaba.android.arouter.facade.annotation.Route
konghaorui committed
15
import com.alibaba.android.arouter.launcher.ARouter
16
import com.tbruyelle.rxpermissions2.RxPermissions
konghaorui committed
17
import com.umeng.analytics.MobclickAgent
konghaorui committed
18
import com.ydl.component.music.FragmentContainerActivity
konghaorui committed
19 20
import com.ydl.component.mvp.DemoContract
import com.ydl.component.mvp.DemoPresenter
konghaorui committed
21
import com.ydl.media.audio.PlayService
徐健 committed
22 23
import com.ydl.ydl_router.manager.YDLRouterManager
import com.ydl.ydl_router.manager.YDLRouterParams
徐健 committed
24
import com.ydl.ydlcommon.modular.ModularServiceManager
25
import com.ydl.ydlcommon.mvp.lce.BaseLceActivity
徐健 committed
26
import com.ydl.ydlcommon.router.IYDLRouterConstant
27
import com.yidianling.common.tools.ToastUtil
28 29
import com.yidianling.consultant.ExpertSearchActivity.Companion.HOT_SEARCH_DOCTOR_NAME
import com.yidianling.consultant.api.IConsultantService
徐健 committed
30
import com.yidianling.fm.api.service.IFMService
徐健 committed
31
import com.yidianling.tests.home.NewTestHomeActivity
konghaorui committed
32 33 34 35 36 37
import kotlinx.android.synthetic.main.activity_main.*

/**
 * Created by haorui on 2019-09-01 .
 * Des:
 */
38
@Route(path = "/main/main")
konghaorui committed
39 40
class MainActivity : BaseLceActivity<DemoContract.View, DemoContract.Presenter>(),
    DemoContract.View {
41

konghaorui committed
42 43
    private var serviceConnection: ServiceConnection? = null
    protected var playService: PlayService? = null
konghaorui committed
44

45 46 47 48 49 50 51 52
    override fun getContentViewId(): Int {
        return R.id.lce_content_view
    }

    override fun getStateViewId(): Int {
        return R.id.lce_state_view
    }

konghaorui committed
53 54 55 56 57 58 59 60 61 62 63 64 65
    override fun setData(data: String) {
        tv_content.text = data
    }

    override fun createPresenter(): DemoContract.Presenter {
        return DemoPresenter()
    }

    override fun layoutResId(): Int {
        return R.layout.activity_main
    }

    override fun initDataAndEvent() {
洪国微 committed
66

徐健 committed
67
//        YDLavManager.instances.init(this, "3387e9b251f3491e9221a9877e8f7830")
洪国微 committed
68

konghaorui committed
69
        bindService()
70
        reLoadData()
71
        requestPermission()
konghaorui committed
72
        tv_user.setOnClickListener {
73
            reLoadData()
konghaorui committed
74 75
        }

严久程 committed
76 77
        tv_home?.setOnClickListener {
            mPresenter.loadHome()
konghaorui committed
78 79 80
        }

        bt_to_other.setOnClickListener {
81
            ARouter.getInstance().build("/user/login")
konghaorui committed
82 83
                .withBoolean("bind_phone", false)
                .withBoolean("isFromGuide", true)
84 85
                .navigation()
        }
86 87 88 89 90 91 92 93 94
        bt_to_consultant.setOnClickListener {
            ARouter.getInstance()
                .build("/consult/hot_search")
                .withString(
                    HOT_SEARCH_DOCTOR_NAME,
                    this.resources?.getString(R.string.platform_search_hint)
                )
                .navigation()
        }
konghaorui committed
95
        bt_to_music.setOnClickListener {
konghaorui committed
96 97 98 99
            FragmentContainerActivity.start(this)
        }
        bt_to_im.setOnClickListener {
            FragmentContainerActivity.start(this,"NewMultiMessageFragment")
konghaorui committed
100
        }
konghaorui committed
101
        bt_to_dynamic.setOnClickListener {
102
            FragmentContainerActivity.start(this,"TrendsHomeFragment")
konghaorui committed
103
        }
104
        bt_to_tests.setOnClickListener {
徐健 committed
105
            startActivity(Intent(this, NewTestHomeActivity::class.java))
106
        }
徐健 committed
107 108 109 110
//        bt_to_confide.setOnClickListener {
//            YDLavManager.instances.login("1193016")
//            startActivity(Intent(this, ConfideHomeActivity::class.java))
//        }
徐健 committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
        bt_to_muse.setOnClickListener {
            YDLRouterManager.router(IYDLRouterConstant.ROUTER_MUSE,
                    YDLRouterParams().putExtra(IYDLRouterConstant.MUSIC_URL, "http://video.yidianling.com/2019/05/30/e6d4a71e8c895f2156a2ff37d93ca3a9.mp3")
                            .putExtra(IYDLRouterConstant.DATA_JSON, "{\n" +
                                    "        \"muses\": [{\n" +
                                    "        \"id\": 6,\n" +
                                    "        \"name\": \"冥想基础介绍-1-什么是冥想?\",\n" +
                                    "        \"audioUrl\":\n" +
                                    "        \"http://video.yidianling.com/2019/05/30/e6d4a71e8c895f2156a2ff37d93ca3a9.mp3\",\n" +
                                    "        \"backgroundUrl\":\n" +
                                    "        \"https://img.yidianling.com/file/2019/06/10/i4qdax82ok2aizq3.png\",\n" +
                                    "        \"effectCode\": 1,\n" +
                                    "        \"category\": 2,\n" +
                                    "        \"playCount\": 929,\n" +
                                    "        \"sort\": 255,\n" +
                                    "        \"isDelete\": 1,\n" +
                                    "        \"createTime\": \"May 30, 2019 4:45:17 PM\",\n" +
                                    "        \"updateTime\": \"Jun 10, 2019 7:14:23 PM\"\n" +
                                    "    }]\n" +
                                    "    }"))
        }
徐健 committed
132 133

        bt_to_fm.setOnClickListener {
徐健 committed
134 135
            startActivity(ModularServiceManager.provide(IFMService::class.java).fmListIntent(this))
//            YDLRouterManager.router(IYDLRouterConstant.ROUTER_FM_LIST)
徐健 committed
136
        }
严久程 committed
137 138 139 140 141

        bt_to_course.setOnClickListener{
            ARouter.getInstance().build("/course/home")
                .navigation()
        }
徐健 committed
142
        bt_to_home.setOnClickListener {
143
            FragmentContainerActivity.start(this,"YdlHomeFragment")
徐健 committed
144 145
        }

konghaorui committed
146 147
    }

徐健 committed
148

149
    override fun reLoadData() {
konghaorui committed
150
        mPresenter.loadHome()
konghaorui committed
151
    }
152 153 154 155 156 157 158 159 160 161 162 163


    @SuppressLint("CheckResult")
    private fun requestPermission() {
        val rxPermissions = RxPermissions(this)
        rxPermissions.requestEach(Manifest.permission.WRITE_EXTERNAL_STORAGE)
            .subscribe { permission ->
                if (permission.granted) {
                    ToastUtil.toastShort("Permission Success")
                } else if (permission.shouldShowRequestPermissionRationale) {
                    requestPermission()
                } else {
konghaorui committed
164 165 166 167
                    ToastUtil.toastLong(
                        this,
                        getString(R.string.platform_need_storage_permission_hint)
                    )
168 169 170 171 172 173 174 175 176
                    val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
                    val uri = Uri.fromParts("package", packageName, null)
                    intent.data = uri
                    startActivity(intent)
                    finish()
                }
            }

    }
konghaorui committed
177 178 179 180 181 182 183 184

    private fun bindService() {
        val intent = Intent()
        intent.setClass(this, PlayService::class.java!!)
        serviceConnection = PlayServiceConnection()
        bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE)
    }

konghaorui committed
185 186 187
    override fun onResume() {
        super.onResume()
        MobclickAgent.onResume(this)
188 189

        ModularServiceManager.provide(IConsultantService::class.java).showConsultAssistantDialog(this)
konghaorui committed
190 191
    }

徐健 committed
192 193 194 195 196 197
    override fun onPause() {
        super.onPause()

        ModularServiceManager.provide(IConsultantService::class.java).hideConsultAssistantDialog()
    }

konghaorui committed
198

199 200 201 202 203 204
    override fun onDestroy() {
        if (serviceConnection != null) {
            unbindService(serviceConnection)
        }
        super.onDestroy()
    }
konghaorui committed
205 206 207 208 209 210 211 212 213 214 215

    private inner class PlayServiceConnection : ServiceConnection {
        override fun onServiceConnected(name: ComponentName, service: IBinder) {
            playService = (service as PlayService.PlayBinder).service
        }

        override fun onServiceDisconnected(name: ComponentName) {
            Log.e(javaClass.simpleName, "service disconnected")
        }
    }

konghaorui committed
216
}