|
@@ -1,12 +1,8 @@
|
|
|
package com.khmer9.sbcmain.screen.main
|
|
|
|
|
|
-import android.Manifest
|
|
|
import android.annotation.SuppressLint
|
|
|
import android.content.Intent
|
|
|
-import android.content.pm.PackageManager
|
|
|
-import android.content.res.AssetManager
|
|
|
import android.media.MediaPlayer
|
|
|
-import android.net.Uri
|
|
|
import android.os.Bundle
|
|
|
import android.util.Log
|
|
|
import android.view.View
|
|
@@ -14,7 +10,6 @@ import android.widget.Toast
|
|
|
import androidx.lifecycle.Observer
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
-import com.google.android.material.snackbar.Snackbar
|
|
|
import com.khmer9.sbcmain.R
|
|
|
import com.khmer9.sbcmain.adapter.MainModuleAdapter
|
|
|
import com.khmer9.sbcmain.app.App
|
|
@@ -27,21 +22,34 @@ import com.khmer9.sbcmain.remote.service.ConnectivityStates
|
|
|
import com.khmer9.sbcmain.screen.report.StatementFragment
|
|
|
import com.khmer9.sbcmain.screen.setting.SettingFragment
|
|
|
import com.khmer9.sbcmain.screen.splash.SplashScreenActivity
|
|
|
-import kotlinx.android.synthetic.main.layout_fragment_main_yuki.*
|
|
|
-import java.io.File
|
|
|
-import java.io.FileOutputStream
|
|
|
-import java.io.InputStream
|
|
|
-import java.io.OutputStream
|
|
|
|
|
|
|
|
|
class MainFragment : BaseFragment(R.layout.layout_fragment_main_yuki) {
|
|
|
private val shareViewModel = App.injectShareViewModel()
|
|
|
- private val sharePref = App.injectPrefHelper()
|
|
|
private lateinit var user: User
|
|
|
private lateinit var adapter: MainModuleAdapter
|
|
|
private lateinit var recyclerView: RecyclerView
|
|
|
private lateinit var betTouch: MediaPlayer
|
|
|
+
|
|
|
private val YUKI_APP_ID = "630478c22983a591133f0492"
|
|
|
+ private val YUKI_DOWNLOAD = "https://www.dropbox.com/s/uzvfo7jahmcl8pe/Khmer9_Yuki_devDebug_1.0.1-dev.apk?dl=1"
|
|
|
+ private val YUKI_PACKAGE = "com.khmer9.yuki"
|
|
|
+
|
|
|
+ private val LOTTO_APP_ID = ""
|
|
|
+ private val LOTTO_DOWNLOAD = ""
|
|
|
+ private val LOTTO_PACKAGE = ""
|
|
|
+
|
|
|
+ private val LOTTO_PLUS_APP_ID = ""
|
|
|
+ private val LOTTO_PLUS_DOWNLOAD = ""
|
|
|
+ private val LOTTO_PLUS_PACKAGE = ""
|
|
|
+
|
|
|
+ private val COCK_FIGHT_APP_ID = ""
|
|
|
+ private val COCK_FIGHT_DOWNLOAD = ""
|
|
|
+ private val COCK_FIGHT_PACKAGE = ""
|
|
|
+
|
|
|
+ private val APONG_APP_ID = ""
|
|
|
+ private val APONG_DOWNLOAD = ""
|
|
|
+ private val APONG_PACKAGE = ""
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
@@ -115,6 +123,21 @@ class MainFragment : BaseFragment(R.layout.layout_fragment_main_yuki) {
|
|
|
shareViewModel.getMainModuleState.observe(viewLifecycleOwner, Observer {
|
|
|
setModuleMain(it)
|
|
|
})
|
|
|
+
|
|
|
+ shareViewModel.getMoudleTokenState.observe(viewLifecycleOwner, Observer {
|
|
|
+ (requireActivity() as ShareActivity).apply {
|
|
|
+ if (it != null) {
|
|
|
+ if (it.intent != null && it.tokenData != null) {
|
|
|
+ val launchIntent = it.intent
|
|
|
+ launchIntent?.putExtra("token", it.tokenData?.token)
|
|
|
+ startActivity(launchIntent)
|
|
|
+
|
|
|
+ it.intent = null
|
|
|
+ it.tokenData = null
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
private fun setModuleMain(state: ResultMainState) {
|
|
@@ -146,49 +169,56 @@ class MainFragment : BaseFragment(R.layout.layout_fragment_main_yuki) {
|
|
|
.commit()
|
|
|
}
|
|
|
} else {
|
|
|
- if (appId == YUKI_APP_ID) {
|
|
|
- (requireActivity() as ShareActivity).apply {
|
|
|
- val launchIntent = packageManager.getLaunchIntentForPackage("com.khmer9.yuki")
|
|
|
- if (launchIntent != null) {
|
|
|
- startActivity(launchIntent)
|
|
|
- } else {
|
|
|
- //installed
|
|
|
- val assetManager: AssetManager = assets
|
|
|
- var inputStream: InputStream? = null
|
|
|
- var outPutStream: OutputStream? = null
|
|
|
-
|
|
|
- try {
|
|
|
- /*inputStream = assetManager.open("Khmer9_Yuki_prodRelease_1.0.1.apk")
|
|
|
- outPutStream = FileOutputStream(filesDir.path + "/" + "Khmer9_Yuki_prodRelease_1.0.1.apk")
|
|
|
- val buffer = ByteArray(1024)
|
|
|
-
|
|
|
- var read: Int
|
|
|
-
|
|
|
- while (inputStream.read(buffer).also { read = it } !== -1) {
|
|
|
- outPutStream?.write(buffer, 0, read)
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- inputStream.close()
|
|
|
- inputStream = null
|
|
|
-
|
|
|
- outPutStream?.flush()
|
|
|
- outPutStream?.close()
|
|
|
- outPutStream = null
|
|
|
-
|
|
|
- val intent: Intent = Intent(Intent.ACTION_VIEW)
|
|
|
- intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
|
|
- intent.setDataAndType(Uri.fromFile(File(filesDir.path + "/" + "Khmer9_Yuki_prodRelease_1.0.1.apk")), "application/vnd.android.package-archive")
|
|
|
- startActivity(intent)*/
|
|
|
-
|
|
|
- (requireActivity() as ShareActivity).apply {
|
|
|
- downloadController = DownloadController(this, "https://www.dropbox.com/s/779i8wxxwg0zwdd/Khmer9_Yuki_prodRelease_1.0.1.apk?dl=1")
|
|
|
-
|
|
|
- checkStoragePermission()
|
|
|
- }
|
|
|
-
|
|
|
- } catch (e: Exception) {
|
|
|
- e.printStackTrace()
|
|
|
+ when (appId) {
|
|
|
+ YUKI_APP_ID -> {
|
|
|
+ (requireActivity() as ShareActivity).apply {
|
|
|
+ val launchIntent = packageManager.getLaunchIntentForPackage(YUKI_PACKAGE)
|
|
|
+ if (launchIntent != null) {
|
|
|
+ //launch
|
|
|
+ shareViewModel.getModuleToken(appId, launchIntent)
|
|
|
+ } else {
|
|
|
+ //installed
|
|
|
+ doDownload(YUKI_DOWNLOAD)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LOTTO_APP_ID -> {
|
|
|
+ (requireActivity() as ShareActivity).apply {
|
|
|
+ val launchIntent = packageManager.getLaunchIntentForPackage(LOTTO_PACKAGE)
|
|
|
+ if (launchIntent != null) {
|
|
|
+ shareViewModel.getModuleToken(appId, launchIntent)
|
|
|
+ } else {
|
|
|
+ doDownload(LOTTO_DOWNLOAD)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LOTTO_PLUS_APP_ID -> {
|
|
|
+ (requireActivity() as ShareActivity).apply {
|
|
|
+ val launchIntent = packageManager.getLaunchIntentForPackage(LOTTO_PLUS_PACKAGE)
|
|
|
+ if (launchIntent != null) {
|
|
|
+ shareViewModel.getModuleToken(appId, launchIntent)
|
|
|
+ } else {
|
|
|
+ doDownload(LOTTO_PLUS_DOWNLOAD)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ COCK_FIGHT_APP_ID -> {
|
|
|
+ (requireActivity() as ShareActivity).apply {
|
|
|
+ val launchIntent = packageManager.getLaunchIntentForPackage(COCK_FIGHT_PACKAGE)
|
|
|
+ if (launchIntent != null) {
|
|
|
+ shareViewModel.getModuleToken(appId, launchIntent)
|
|
|
+ } else {
|
|
|
+ doDownload(COCK_FIGHT_DOWNLOAD)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ APONG_APP_ID -> {
|
|
|
+ (requireActivity() as ShareActivity).apply {
|
|
|
+ val launchIntent = packageManager.getLaunchIntentForPackage(APONG_PACKAGE)
|
|
|
+ if (launchIntent != null) {
|
|
|
+ shareViewModel.getModuleToken(appId, launchIntent)
|
|
|
+ } else {
|
|
|
+ doDownload(APONG_DOWNLOAD)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -199,6 +229,18 @@ class MainFragment : BaseFragment(R.layout.layout_fragment_main_yuki) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private fun doDownload(url: String) {
|
|
|
+ try {
|
|
|
+ (requireActivity() as ShareActivity).apply {
|
|
|
+ downloadController = DownloadController(this, url)
|
|
|
+ checkStoragePermission()
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (e: Exception) {
|
|
|
+ e.printStackTrace()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@SuppressLint("CheckResult")
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
|
|
super.onActivityCreated(savedInstanceState)
|