|
@@ -15,6 +15,7 @@ import androidx.lifecycle.MutableLiveData
|
|
import androidx.lifecycle.ViewModel
|
|
import androidx.lifecycle.ViewModel
|
|
import androidx.lifecycle.lifecycleScope
|
|
import androidx.lifecycle.lifecycleScope
|
|
import com.doverfuelingsolutions.issp.R
|
|
import com.doverfuelingsolutions.issp.R
|
|
|
|
+import com.doverfuelingsolutions.issp.api.CloudApi
|
|
import com.doverfuelingsolutions.issp.data.GlobalData
|
|
import com.doverfuelingsolutions.issp.data.GlobalData
|
|
import com.doverfuelingsolutions.issp.databinding.ActivityMainBinding
|
|
import com.doverfuelingsolutions.issp.databinding.ActivityMainBinding
|
|
import com.doverfuelingsolutions.issp.fusion.FusionError
|
|
import com.doverfuelingsolutions.issp.fusion.FusionError
|
|
@@ -27,6 +28,7 @@ import com.doverfuelingsolutions.issp.view.fragment.*
|
|
import com.wayne.www.waynelib.fdc.FdcClient
|
|
import com.wayne.www.waynelib.fdc.FdcClient
|
|
import com.youth.banner.adapter.BannerImageAdapter
|
|
import com.youth.banner.adapter.BannerImageAdapter
|
|
import com.youth.banner.holder.BannerImageHolder
|
|
import com.youth.banner.holder.BannerImageHolder
|
|
|
|
+import kotlinx.coroutines.delay
|
|
import kotlinx.coroutines.launch
|
|
import kotlinx.coroutines.launch
|
|
import java.io.File
|
|
import java.io.File
|
|
|
|
|
|
@@ -41,7 +43,12 @@ class MainActivity : AppCompatActivity(),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private val binding: ActivityMainBinding by lazy { DataBindingUtil.setContentView(this, R.layout.activity_main) }
|
|
|
|
|
|
+ private val binding: ActivityMainBinding by lazy {
|
|
|
|
+ DataBindingUtil.setContentView(
|
|
|
|
+ this,
|
|
|
|
+ R.layout.activity_main
|
|
|
|
+ )
|
|
|
|
+ }
|
|
private val mainViewModel: MainViewModel by viewModels()
|
|
private val mainViewModel: MainViewModel by viewModels()
|
|
|
|
|
|
private val fragmentHolder = FragmentHolder()
|
|
private val fragmentHolder = FragmentHolder()
|
|
@@ -57,8 +64,7 @@ class MainActivity : AppCompatActivity(),
|
|
binding.mainViewModel = mainViewModel
|
|
binding.mainViewModel = mainViewModel
|
|
initView()
|
|
initView()
|
|
initFusion()
|
|
initFusion()
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ refreshToken()
|
|
}
|
|
}
|
|
|
|
|
|
override fun onResume() {
|
|
override fun onResume() {
|
|
@@ -79,8 +85,10 @@ class MainActivity : AppCompatActivity(),
|
|
when (requestCode) {
|
|
when (requestCode) {
|
|
PreferenceActivity.codeRequestResult -> {
|
|
PreferenceActivity.codeRequestResult -> {
|
|
data?.let {
|
|
data?.let {
|
|
- val isMiddleModified = it.getBooleanExtra(PreferenceActivity.isMiddleModified, false)
|
|
|
|
- val isFuelModified = it.getBooleanExtra(PreferenceActivity.isFuelModified, false)
|
|
|
|
|
|
+ val isMiddleModified =
|
|
|
|
+ it.getBooleanExtra(PreferenceActivity.isMiddleModified, false)
|
|
|
|
+ val isFuelModified =
|
|
|
|
+ it.getBooleanExtra(PreferenceActivity.isFuelModified, false)
|
|
if (!isFuelModified && !isMiddleModified) return@let
|
|
if (!isFuelModified && !isMiddleModified) return@let
|
|
|
|
|
|
setFragment(fragmentHolder)
|
|
setFragment(fragmentHolder)
|
|
@@ -107,7 +115,10 @@ class MainActivity : AppCompatActivity(),
|
|
when (result.getString(FragmentConstants.eventType)) {
|
|
when (result.getString(FragmentConstants.eventType)) {
|
|
FragmentConstants.eventHome -> {
|
|
FragmentConstants.eventHome -> {
|
|
if (supportFragmentManager.backStackEntryCount > 0)
|
|
if (supportFragmentManager.backStackEntryCount > 0)
|
|
- supportFragmentManager.popBackStack(supportFragmentManager.getBackStackEntryAt(0).id, FragmentManager.POP_BACK_STACK_INCLUSIVE)
|
|
|
|
|
|
+ supportFragmentManager.popBackStack(
|
|
|
|
+ supportFragmentManager.getBackStackEntryAt(0).id,
|
|
|
|
+ FragmentManager.POP_BACK_STACK_INCLUSIVE
|
|
|
|
+ )
|
|
}
|
|
}
|
|
FragmentConstants.eventBack -> {
|
|
FragmentConstants.eventBack -> {
|
|
supportFragmentManager.popBackStack()
|
|
supportFragmentManager.popBackStack()
|
|
@@ -163,13 +174,19 @@ class MainActivity : AppCompatActivity(),
|
|
} else {
|
|
} else {
|
|
StringUtil.get(R.string.go_check_fusion)
|
|
StringUtil.get(R.string.go_check_fusion)
|
|
}
|
|
}
|
|
- fragmentHolder.action(StringUtil.get(R.string.connect_fail_reason, msg), buttonText) {
|
|
|
|
|
|
+ fragmentHolder.action(
|
|
|
|
+ StringUtil.get(R.string.connect_fail_reason, msg),
|
|
|
|
+ buttonText
|
|
|
|
+ ) {
|
|
PreferenceActivity.startForResult(this@MainActivity)
|
|
PreferenceActivity.startForResult(this@MainActivity)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
FusionError.Login -> {
|
|
FusionError.Login -> {
|
|
setFragment(fragmentHolder)
|
|
setFragment(fragmentHolder)
|
|
- fragmentHolder.action(StringUtil.get(R.string.connect_fail_reason, msg), StringUtil.get(R.string.retry_login)) {
|
|
|
|
|
|
+ fragmentHolder.action(
|
|
|
|
+ StringUtil.get(R.string.connect_fail_reason, msg),
|
|
|
|
+ StringUtil.get(R.string.retry_login)
|
|
|
|
+ ) {
|
|
FusionManager.loginFetchInfo()
|
|
FusionManager.loginFetchInfo()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -192,20 +209,36 @@ class MainActivity : AppCompatActivity(),
|
|
supportActionBar?.hide()
|
|
supportActionBar?.hide()
|
|
mainViewModel.stationName.value = GlobalData.businessName.get()
|
|
mainViewModel.stationName.value = GlobalData.businessName.get()
|
|
if (GlobalData.stationLogoFileName.get().isNotEmpty())
|
|
if (GlobalData.stationLogoFileName.get().isNotEmpty())
|
|
- binding.stationLogo.setImageURI(Uri.fromFile(File(filesDir, GlobalData.stationLogoFileName.get())))
|
|
|
|
|
|
+ binding.stationLogo.setImageURI(
|
|
|
|
+ Uri.fromFile(
|
|
|
|
+ File(
|
|
|
|
+ filesDir,
|
|
|
|
+ GlobalData.stationLogoFileName.get()
|
|
|
|
+ )
|
|
|
|
+ )
|
|
|
|
+ )
|
|
binding.banner.run {
|
|
binding.banner.run {
|
|
addBannerLifecycleObserver(this@MainActivity)
|
|
addBannerLifecycleObserver(this@MainActivity)
|
|
scrollTime = 500
|
|
scrollTime = 500
|
|
adapter =
|
|
adapter =
|
|
object : BannerImageAdapter<Int>(listOf(R.mipmap.banner_1, R.mipmap.banner_2)) {
|
|
object : BannerImageAdapter<Int>(listOf(R.mipmap.banner_1, R.mipmap.banner_2)) {
|
|
- override fun onBindView(holder: BannerImageHolder, data: Int, position: Int, size: Int) {
|
|
|
|
|
|
+ override fun onBindView(
|
|
|
|
+ holder: BannerImageHolder,
|
|
|
|
+ data: Int,
|
|
|
|
+ position: Int,
|
|
|
|
+ size: Int
|
|
|
|
+ ) {
|
|
holder.imageView.setImageResource(data)
|
|
holder.imageView.setImageResource(data)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
binding.clock.setOnLongClickListener(this)
|
|
binding.clock.setOnLongClickListener(this)
|
|
|
|
|
|
- supportFragmentManager.setFragmentResultListener(FragmentConstants.fragmentEvent, this, this)
|
|
|
|
|
|
+ supportFragmentManager.setFragmentResultListener(
|
|
|
|
+ FragmentConstants.fragmentEvent,
|
|
|
|
+ this,
|
|
|
|
+ this
|
|
|
|
+ )
|
|
setFragment(fragmentPayType)
|
|
setFragment(fragmentPayType)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -227,6 +260,21 @@ class MainActivity : AppCompatActivity(),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private fun refreshToken() {
|
|
|
|
+ // FIXME 如果当前正在进行支付,如果刷新失败则会导致支付中断的问题
|
|
|
|
+ lifecycleScope.launchWhenResumed {
|
|
|
|
+ val duration = GlobalData.accessTokenExpire.get() - System.currentTimeMillis()
|
|
|
|
+ repeat(99999) {
|
|
|
|
+ delay(duration)
|
|
|
|
+ val result = CloudApi.login(GlobalData.accountName.get(), GlobalData.password.get())
|
|
|
|
+ if (!result.success) {
|
|
|
|
+ this@MainActivity.startActivity(Intent(this@MainActivity, LoginActivity::class.java))
|
|
|
|
+ finish()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
class MainViewModel : ViewModel() {
|
|
class MainViewModel : ViewModel() {
|
|
val stationName = MutableLiveData("")
|
|
val stationName = MutableLiveData("")
|
|
}
|
|
}
|