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"
minSdk = 24
targetSdk = 34
versionCode = 3
versionName = "1.0.3"
versionCode = 4
versionName = "1.0.4"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

View File

@ -27,10 +27,12 @@ import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.json.JSONObject
import relax.offline.music.App
import relax.offline.music.R
import relax.offline.music.bean.FavoriteBean
import relax.offline.music.bean.OfflineBean
import relax.offline.music.http.getAppVersionCode
import relax.offline.music.media.MediaControllerManager
import relax.offline.music.sp.AppStore
import relax.offline.music.util.LogTag
@ -261,14 +263,26 @@ abstract class MoBaseActivity : AppCompatActivity(), CoroutineScope by MainScope
fun withPermission(): Boolean {
//先判断当前配置的开关是否为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}")
if (!appStore.shouldEnterMusicPage) {
return false
}
// 不允许的国家代码
val restrictedCountries = setOf(
// "CN",
// "HK",
"CN",
"HK",
"TW",
"JP",
"KR",
@ -300,9 +314,9 @@ abstract class MoBaseActivity : AppCompatActivity(), CoroutineScope by MainScope
//525 Singapore (Republic of)
val restrictedCountryCodes =
setOf(
// "460",
// "461",
// "454",
"460",
"461",
"454",
"466",
"440",
"441",

View File

@ -1,7 +1,13 @@
package relax.offline.music.firebase
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,13 +63,15 @@ class RemoteConfig {
mFirebaseRemoteConfig!!.addOnConfigUpdateListener(object : ConfigUpdateListener {
override fun onUpdate(configUpdate: ConfigUpdate) {
LogTag.LogD(TAG, "Updated keys: " + configUpdate.updatedKeys)
if (configUpdate.updatedKeys.contains(Constants.KEY_SHOULD_ENTER_MUSIC_PAGE)) {
mFirebaseRemoteConfig!!.activate().addOnCompleteListener { task ->
if (task.isSuccessful) {
updateData("onConfigUpdate", mFirebaseRemoteConfig!!.all)
try {
if (configUpdate.updatedKeys.contains(Constants.KEY_SHOULD_ENTER_MUSIC_JSON)) {
mFirebaseRemoteConfig!!.activate().addOnCompleteListener { task ->
if (task.isSuccessful) {
updateData("onConfigUpdate", mFirebaseRemoteConfig!!.all)
}
}
}
}catch (ignore: Exception) {
}
}
@ -112,12 +114,9 @@ class RemoteConfig {
TAG,
"from = " + from + "Key = " + key + " Value = " + value.asString()
)
if (TextUtils.equals(
Constants.KEY_SHOULD_ENTER_MUSIC_PAGE, key
)
) {
val shouldEnterMusicPage = value.asBoolean()
appStore.shouldEnterMusicPage = shouldEnterMusicPage
if (TextUtils.equals(Constants.KEY_SHOULD_ENTER_MUSIC_JSON, key)) {
val shouldJson = value.asString()
appStore.shouldEnterMusicPageJson = shouldJson
}
} catch (ignore: Exception) {

View File

@ -49,8 +49,13 @@ class AppStore(context: Context) {
)
var shouldEnterMusicPage: Boolean by store.boolean(
key = Constants.KEY_SHOULD_ENTER_MUSIC_PAGE,
defaultValue = Constants.DEFAULT_SHOULD_ENTER_MUSIC_PAGE
key = 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 {
@ -62,5 +67,6 @@ class AppStore(context: Context) {
const val APP_UUID = "app_uuid"
const val IP_COUNTRY_CODE = "ip_country_code"
const val FIRST_OPEN_IS_SUCCEED = "first_open_is_succeed"
const val SHOULD_ENTER_MUSIC_PAGE = "key_should_enter_music_page"
}
}