Browse Source

feat: 开屏页

tongmengxiao 3 months ago
parent
commit
b500d5deb5

+ 78 - 3
app/src/main/java/com/swago/app/SplashActivity.kt

@@ -3,24 +3,40 @@ package com.swago.app
 import android.Manifest
 import android.os.Build
 import android.os.Bundle
-import android.util.Log
+import android.os.CountDownTimer
+import android.text.TextUtils
+import android.view.View
+import android.widget.ImageView
+import android.widget.TextView
 import android.widget.Toast
 import androidx.activity.viewModels
 import androidx.appcompat.app.AppCompatActivity
 import com.alibaba.android.arouter.launcher.ARouter
-import com.swago.baseswago.constant.ARouteConstant
 import com.permissionx.guolindev.PermissionX
+import com.swago.baseswago.constant.ARouteConstant
 import com.swago.baseswago.constant.UrlConstant
+import com.swago.baseswago.model.ConfigModel
 import com.swago.baseswago.util.AppContext
 import com.swago.baseswago.util.FileUtil
-import com.swago.baseswago.util.MD5Util
 import com.swago.baseswago.util.SpUtil
+import com.swago.loadUrl
 import java.io.File
+import java.text.SimpleDateFormat
+import java.util.Date
+import java.util.Locale
+
 
 class SplashActivity : AppCompatActivity() {
 
     private val splashVm by viewModels<SplashVm>()
 
+    private val currentDate: String = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date())
+    private var mSplashImage:ImageView ?= null
+    private var mSplashTime:TextView ?= null
+    private lateinit var countDownTimer: CountDownTimer
+    private val totalTimeInMillis: Long = 5000
+    private var configModel:ConfigModel ?= null
+
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
         setContentView(R.layout.activity_splash)
@@ -81,6 +97,65 @@ class SplashActivity : AppCompatActivity() {
             val t = UrlConstant.appGameRootPath + File.separator + 8
             FileUtil.upZipFile(UrlConstant.appGameRootPath + File.separator + 8 + File.separator + "com-swago-magical-piggy.zip" , t + File.separator)
         }
+        setSplashImage()
+    }
+
+    private fun setSplashImage() {
+        mSplashImage = findViewById(R.id.iv_splash)
+        mSplashTime = findViewById(R.id.skip_time)
+        countDownTimer = object : CountDownTimer(totalTimeInMillis, 1000) {
+            override fun onTick(millisUntilFinished: Long) {
+                val secondsRemaining = millisUntilFinished / 1000
+                mSplashTime?.text = "Skip $secondsRemaining"
+            }
+
+            override fun onFinish() {
+                splashVm.loginByAuto()
+            }
+        }
+
+        splashVm.jumpToHomeLiveData.observe(this){
+            if (it == null || TextUtils.isEmpty(it.rotation_img_url)){
+                splashVm.loginByAuto()
+            } else {
+                var count = SpUtil.readInt("splashCount")
+                val lastDate = SpUtil.readString("lastShowDate")
+                configModel = it
+                if (currentDate == lastDate){
+                    if (count <= 3){
+                        count++
+                        countDownTimer.start()
+                        mSplashTime?.visibility = View.VISIBLE
+                        mSplashImage?.loadUrl(this, it.rotation_img_url,R.drawable.default_splash)
+                        SpUtil.putInt("splashCount" , count)
+                    } else {
+                        splashVm.loginByAuto()
+                    }
+                } else {
+                    SpUtil.putInt("splashCount" , 1)
+                    SpUtil.putString("lastShowDate",currentDate)
+                    countDownTimer.start()
+                    mSplashTime?.visibility = View.VISIBLE
+                    mSplashImage?.loadUrl(this, it.rotation_img_url,R.drawable.default_splash)
+                }
+            }
+        }
+
+        mSplashImage?.setOnClickListener {
+            configModel?.rotation_url?.let {
+                ARouter.getInstance().build(ARouteConstant.Base.webView)
+                    .withString("url", it)
+                    .navigation()
+            }
+        }
+
+        mSplashTime?.setOnClickListener {
+            splashVm.loginByAuto()
+        }
+    }
 
+    override fun onDestroy() {
+        super.onDestroy()
+        countDownTimer.cancel()
     }
 }

+ 6 - 1
app/src/main/java/com/swago/app/SplashVm.kt

@@ -12,6 +12,7 @@ import com.swago.baseswago.constant.ARouteConstant
 import com.swago.baseswago.constant.UrlConstant
 import com.swago.baseswago.http.RetrofitManager
 import com.swago.baseswago.inter.ApiManager
+import com.swago.baseswago.model.ConfigModel
 import com.swago.baseswago.model.DomainConfig
 import com.swago.baseswago.util.*
 import org.jsoup.Jsoup
@@ -31,6 +32,10 @@ class SplashVm(application: Application) : BaseViewModel(application) {
         MutableLiveData<Boolean>()
     }
 
+    val jumpToHomeLiveData by lazy {
+        MutableLiveData<ConfigModel>()
+    }
+
     var retry = 0
 
     private val executorService by lazy {
@@ -64,7 +69,7 @@ class SplashVm(application: Application) : BaseViewModel(application) {
                 if (UserInfo.getLoginModel() == null) {
                     jumpToLoginLiveData.value = false
                 } else {
-                    loginByAuto()
+                    jumpToHomeLiveData.value = data
                 }
             }
 

+ 2 - 0
baseswago/src/main/java/com/swago/baseswago/model/ConfigModel.kt

@@ -12,6 +12,8 @@ data class ConfigModel(
     val im_app_id:Int,
     var language_lables: List<Label>?,
     var special_zip_url:String = "",
+    var rotation_img_url:String = "",
+    var rotation_url:String = "",
 
     //版本更新
     val app_version:Int,

+ 1 - 0
room/src/main/java/com/swago/room/giftdandao/GiftDanDaoManager.kt

@@ -56,6 +56,7 @@ class GiftDanDaoManager  : IRoomActiveListener {
         giftModelList.clear()
         giftDanDaoViewList.forEach {
             it.clear()
+            it.closeRoom()
         }
         loopJob?.cancel()
         loopJob = null

+ 15 - 0
room/src/main/java/com/swago/room/giftdandao/GiftDanDaoView.kt

@@ -561,4 +561,19 @@ class GiftDanDaoView : FrameLayout {
         vibrator?.cancel()
     }
 
+    fun closeRoom(){
+        if (aniamtionRotate?.isRunning == true){
+            aniamtionRotate?.cancel()
+        }
+        if (aniamtionNum?.isRunning == true){
+            aniamtionNum?.cancel()
+        }
+        if (aniamtionScale?.isRunning == true){
+            aniamtionScale?.cancel()
+        }
+        aniamtionRotate?.removeAllListeners()
+        aniamtionNum?.removeAllListeners()
+        aniamtionScale?.removeAllListeners()
+    }
+
 }

+ 3 - 2
room/src/main/res/layout/fragment_base_com.xml

@@ -144,11 +144,12 @@
         app:layout_constraintTop_toTopOf="parent"
         app:layout_constraintStart_toStartOf="parent"
         android:layout_width="match_parent"
+        android:layout_marginTop="@dimen/dp_40"
         android:layout_height="300dp"/>
 
     <com.swago.room.giftdandao.GiftDanDaoView
         android:id="@+id/danDaoView2"
-        android:layout_marginTop="60dp"
+        android:layout_marginTop="100dp"
         app:layout_constraintTop_toTopOf="parent"
         app:layout_constraintStart_toStartOf="parent"
         android:layout_width="match_parent"
@@ -156,7 +157,7 @@
 
     <com.swago.room.giftdandao.GiftDanDaoView
         android:id="@+id/danDaoView3"
-        android:layout_marginTop="120dp"
+        android:layout_marginTop="160dp"
         app:layout_constraintTop_toTopOf="parent"
         app:layout_constraintStart_toStartOf="parent"
         android:layout_width="match_parent"

+ 3 - 1
room/src/main/res/layout/view_item_gift.xml

@@ -230,6 +230,7 @@
             android:src="@mipmap/gift_bg_prize_1000"
             android:scaleType="centerInside"
             android:layout_marginStart="40dp"
+            android:layout_marginTop="30dp"
             android:layout_alignParentTop="true"
             app:layout_constraintStart_toStartOf="parent"
             app:layout_constraintTop_toTopOf="parent"/>
@@ -239,6 +240,7 @@
             android:layout_height="match_parent"
             android:src="@mipmap/gift_prize_frame_1000"
             android:scaleType="centerInside"
+            android:layout_marginTop="30dp"
             android:layout_alignParentTop="true"
             app:layout_constraintEnd_toEndOf="@+id/iv_prize_bg"
             app:layout_constraintStart_toStartOf="@+id/iv_prize_bg"
@@ -250,7 +252,7 @@
             app:layout_constraintStart_toStartOf="@+id/iv_prize_frame"
             app:layout_constraintBottom_toBottomOf="parent"
             app:layout_constraintTop_toTopOf="parent"
-            android:layout_marginTop="@dimen/dp_10"
+            android:layout_marginTop="40dp"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content">