This commit is contained in:
ocean 2024-05-30 16:08:57 +08:00
parent 0defee50f6
commit bc774071bc
5 changed files with 47 additions and 22 deletions

View File

@ -16,8 +16,8 @@ android {
applicationId = "relax.offline.mp3.music" applicationId = "relax.offline.mp3.music"
minSdk = 24 minSdk = 24
targetSdk = 34 targetSdk = 34
versionCode = 3 versionCode = 4
versionName = "1.0.3" versionName = "1.0.4"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

View File

@ -27,10 +27,12 @@ import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.json.JSONObject
import relax.offline.music.App import relax.offline.music.App
import relax.offline.music.R import relax.offline.music.R
import relax.offline.music.bean.FavoriteBean import relax.offline.music.bean.FavoriteBean
import relax.offline.music.bean.OfflineBean import relax.offline.music.bean.OfflineBean
import relax.offline.music.http.getAppVersionCode
import relax.offline.music.media.MediaControllerManager import relax.offline.music.media.MediaControllerManager
import relax.offline.music.sp.AppStore import relax.offline.music.sp.AppStore
import relax.offline.music.util.LogTag import relax.offline.music.util.LogTag
@ -261,14 +263,26 @@ abstract class MoBaseActivity : AppCompatActivity(), CoroutineScope by MainScope
fun withPermission(): Boolean { fun withPermission(): Boolean {
//先判断当前配置的开关是否为true为false的话就直接进入A //先判断当前配置的开关是否为true为false的话就直接进入A
val jsonString = appStore.shouldEnterMusicPageJson//得到配置的json
LogTag.LogD(TAG, "withPermission jsonString->${jsonString}")
val json = JSONObject(jsonString)
val versionCode = json.optInt("versionCode")//得到配置的code
val enter = json.optBoolean("enter")//得到配置的开关
val currentVersionCode = getAppVersionCode(this)//得到当前应用的code
//如果配置的code 等于 当前app的code则把配置赋值给shouldEnterMusicPage
if (versionCode.toLong() == currentVersionCode) {
appStore.shouldEnterMusicPage = enter
} else {
appStore.shouldEnterMusicPage = true
}
LogTag.LogD(TAG, "withPermission shouldEnterMusicPage->${appStore.shouldEnterMusicPage}") LogTag.LogD(TAG, "withPermission shouldEnterMusicPage->${appStore.shouldEnterMusicPage}")
if (!appStore.shouldEnterMusicPage) { if (!appStore.shouldEnterMusicPage) {
return false return false
} }
// 不允许的国家代码 // 不允许的国家代码
val restrictedCountries = setOf( val restrictedCountries = setOf(
// "CN", "CN",
// "HK", "HK",
"TW", "TW",
"JP", "JP",
"KR", "KR",
@ -300,9 +314,9 @@ abstract class MoBaseActivity : AppCompatActivity(), CoroutineScope by MainScope
//525 Singapore (Republic of) //525 Singapore (Republic of)
val restrictedCountryCodes = val restrictedCountryCodes =
setOf( setOf(
// "460", "460",
// "461", "461",
// "454", "454",
"466", "466",
"440", "440",
"441", "441",

View File

@ -1,7 +1,13 @@
package relax.offline.music.firebase package relax.offline.music.firebase
object Constants { object Constants {
const val KEY_SHOULD_ENTER_MUSIC_PAGE = "key_should_enter_music_page"
const val DEFAULT_SHOULD_ENTER_MUSIC_PAGE = false const val KEY_SHOULD_ENTER_MUSIC_JSON = "key_should_enter_music_json"
const val DEFAULT_SHOULD_ENTER_MUSIC_JSON = """
{
"versionCode": 4,
"enter": false
}
"""
} }

View File

@ -63,14 +63,16 @@ class RemoteConfig {
mFirebaseRemoteConfig!!.addOnConfigUpdateListener(object : ConfigUpdateListener { mFirebaseRemoteConfig!!.addOnConfigUpdateListener(object : ConfigUpdateListener {
override fun onUpdate(configUpdate: ConfigUpdate) { override fun onUpdate(configUpdate: ConfigUpdate) {
LogTag.LogD(TAG, "Updated keys: " + configUpdate.updatedKeys) LogTag.LogD(TAG, "Updated keys: " + configUpdate.updatedKeys)
try {
if (configUpdate.updatedKeys.contains(Constants.KEY_SHOULD_ENTER_MUSIC_PAGE)) { if (configUpdate.updatedKeys.contains(Constants.KEY_SHOULD_ENTER_MUSIC_JSON)) {
mFirebaseRemoteConfig!!.activate().addOnCompleteListener { task -> mFirebaseRemoteConfig!!.activate().addOnCompleteListener { task ->
if (task.isSuccessful) { if (task.isSuccessful) {
updateData("onConfigUpdate", mFirebaseRemoteConfig!!.all) updateData("onConfigUpdate", mFirebaseRemoteConfig!!.all)
} }
} }
} }
}catch (ignore: Exception) {
}
} }
override fun onError(error: FirebaseRemoteConfigException) { override fun onError(error: FirebaseRemoteConfigException) {
@ -112,12 +114,9 @@ class RemoteConfig {
TAG, TAG,
"from = " + from + "Key = " + key + " Value = " + value.asString() "from = " + from + "Key = " + key + " Value = " + value.asString()
) )
if (TextUtils.equals( if (TextUtils.equals(Constants.KEY_SHOULD_ENTER_MUSIC_JSON, key)) {
Constants.KEY_SHOULD_ENTER_MUSIC_PAGE, key val shouldJson = value.asString()
) appStore.shouldEnterMusicPageJson = shouldJson
) {
val shouldEnterMusicPage = value.asBoolean()
appStore.shouldEnterMusicPage = shouldEnterMusicPage
} }
} catch (ignore: Exception) { } catch (ignore: Exception) {

View File

@ -49,8 +49,13 @@ class AppStore(context: Context) {
) )
var shouldEnterMusicPage: Boolean by store.boolean( var shouldEnterMusicPage: Boolean by store.boolean(
key = Constants.KEY_SHOULD_ENTER_MUSIC_PAGE, key = SHOULD_ENTER_MUSIC_PAGE,
defaultValue = Constants.DEFAULT_SHOULD_ENTER_MUSIC_PAGE defaultValue = true
)
var shouldEnterMusicPageJson: String by store.string(
key = Constants.KEY_SHOULD_ENTER_MUSIC_JSON,
defaultValue = Constants.DEFAULT_SHOULD_ENTER_MUSIC_JSON
) )
companion object { companion object {
@ -62,5 +67,6 @@ class AppStore(context: Context) {
const val APP_UUID = "app_uuid" const val APP_UUID = "app_uuid"
const val IP_COUNTRY_CODE = "ip_country_code" const val IP_COUNTRY_CODE = "ip_country_code"
const val FIRST_OPEN_IS_SUCCEED = "first_open_is_succeed" const val FIRST_OPEN_IS_SUCCEED = "first_open_is_succeed"
const val SHOULD_ENTER_MUSIC_PAGE = "key_should_enter_music_page"
} }
} }