移除无用文件
This commit is contained in:
parent
0262a19fba
commit
0233f4476f
|
|
@ -1,91 +0,0 @@
|
|||
[
|
||||
{
|
||||
"id": "push_001_v2",
|
||||
"title": "Time to claim coins!",
|
||||
"desc": "You have free coins today!Open to claim!",
|
||||
"buttonText": "111",
|
||||
"iconType": 1,
|
||||
"actionType": 1
|
||||
},
|
||||
{
|
||||
"id": "push_002_v2",
|
||||
"title": "Time to claim cash!",
|
||||
"desc": "You have free cash today!Open to claim!",
|
||||
"buttonText": "222",
|
||||
"iconType": 2,
|
||||
"actionType": 2
|
||||
},
|
||||
{
|
||||
"id": "push_003_v2",
|
||||
"title": "Hey!",
|
||||
"desc": "You received R$10, click to withdraw immediately!",
|
||||
"buttonText": "333",
|
||||
"iconType": 5,
|
||||
"actionType": 5
|
||||
},
|
||||
{
|
||||
"id": "push_004_v2",
|
||||
"title": "\uD83D\uDCDE\uD83D\uDCDE\uD83D\uDCDE Do you miss me? ",
|
||||
"desc": "Come play the game and withdraw now!",
|
||||
"buttonText": "444",
|
||||
"iconType": 3,
|
||||
"actionType": 3
|
||||
},
|
||||
{
|
||||
"id": "push_005_v2",
|
||||
"title": "\uD83D\uDCDE\uD83D\uDCDE\uD83D\uDCDE Do you miss me? ",
|
||||
"desc": "Come play the game and withdraw now!",
|
||||
"buttonText": "555",
|
||||
"iconType": 3,
|
||||
"actionType": 3
|
||||
},
|
||||
{
|
||||
"id": "push_006_v2",
|
||||
"title": "\uD83D\uDCDE\uD83D\uDCDE\uD83D\uDCDE Do you miss me? ",
|
||||
"desc": "Come play the game and withdraw now!",
|
||||
"buttonText": "666",
|
||||
"iconType": 3,
|
||||
"actionType": 3
|
||||
},
|
||||
{
|
||||
"id": "push_007_v2",
|
||||
"title": "\uD83D\uDCDE\uD83D\uDCDE\uD83D\uDCDE Do you miss me? ",
|
||||
"desc": "Come play the game and withdraw now!",
|
||||
"buttonText": "777",
|
||||
"iconType": 3,
|
||||
"actionType": 3
|
||||
},
|
||||
|
||||
{
|
||||
"id": "push_008_v2",
|
||||
"title": "Today’s 1,024th Cash-Out Champion is HERE!",
|
||||
"desc": "You’re the missing piece! Join now!",
|
||||
"buttonText": "888",
|
||||
"iconType": 4,
|
||||
"actionType": 4
|
||||
},
|
||||
{
|
||||
"id": "push_009_v2",
|
||||
"title": "User #888 Just Cashed Out!",
|
||||
"desc": "Don’t be left behind! Tap to claim yours!",
|
||||
"buttonText": "999",
|
||||
"iconType": 6,
|
||||
"actionType": 6
|
||||
},
|
||||
{
|
||||
"id": "push_010_v2",
|
||||
"title": "You missed(2) calls",
|
||||
"desc": "+86-12345, +86-666999",
|
||||
"buttonText": "1010",
|
||||
"iconType": 1,
|
||||
"actionType": 1
|
||||
},
|
||||
{
|
||||
"id": "push_011_v2",
|
||||
"title": "Gmail",
|
||||
"desc": "support.gov@gmail.com",
|
||||
"buttonText": "1111",
|
||||
"iconType": 1,
|
||||
"actionType": 1
|
||||
}
|
||||
]
|
||||
|
|
@ -1,150 +0,0 @@
|
|||
package com.remax.notification.config
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonSyntaxException
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.remax.base.ext.KvStringDelegate
|
||||
import com.remax.base.utils.RemoteConfigManager
|
||||
import com.remax.notification.utils.NotiLogger
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* 推送通知内容控制器
|
||||
*/
|
||||
object PushContentController {
|
||||
|
||||
private const val CONTENT_CONFIG_FILE_NAME = "push_content_config.json"
|
||||
private const val SP_NAME = "push_content_prefs"
|
||||
private const val KEY_CURRENT_INDEX = "current_index"
|
||||
|
||||
private var pushContents: List<PushContent>? = null
|
||||
private lateinit var sharedPreferences: SharedPreferences
|
||||
private var contentJsonFromRemote by KvStringDelegate("notificationContentJsonRemote", "")
|
||||
|
||||
/**
|
||||
* 初始化内容配置
|
||||
* @param context 上下文
|
||||
* @return 是否初始化成功
|
||||
*/
|
||||
fun initialize(context: Context): Boolean {
|
||||
return try {
|
||||
sharedPreferences = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE)
|
||||
val jsonString = contentJsonFromRemote.orEmpty().takeIf { it.isNotEmpty() }?:loadContentConfigFromAssets(context)
|
||||
pushContents = parseContentConfig(jsonString)
|
||||
NotiLogger.d("推送内容配置初始化成功,共 ${pushContents?.size} 条")
|
||||
|
||||
// 异步获取远程配置
|
||||
//fetchRemotePushContent()
|
||||
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
NotiLogger.e("推送内容配置初始化失败", e)
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取下一个推送内容(顺序获取)
|
||||
* @return 推送内容,首次调用返回第一条,之后按顺序返回
|
||||
*/
|
||||
fun getNextPushContent(): PushContent? {
|
||||
val contents = pushContents ?: return null
|
||||
if (contents.isEmpty()) return null
|
||||
|
||||
val currentIndex = getCurrentIndex()
|
||||
val nextIndex = if (currentIndex == -1) 0 else (currentIndex + 1) % contents.size
|
||||
|
||||
// 保存下一个索引
|
||||
saveCurrentIndex(nextIndex)
|
||||
|
||||
val content = contents[nextIndex]
|
||||
NotiLogger.d("获取推送内容: ${content.id}, 索引: $nextIndex")
|
||||
|
||||
return content
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否已初始化
|
||||
* @return 是否已初始化
|
||||
*/
|
||||
fun isInitialized(): Boolean {
|
||||
return pushContents != null
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步获取远程推送内容配置
|
||||
*/
|
||||
private fun fetchRemotePushContent() {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
NotiLogger.d("开始获取远程推送内容配置")
|
||||
val remoteJsonString = RemoteConfigManager.getString("pushContentJson", "")
|
||||
|
||||
if (remoteJsonString != null && remoteJsonString.isNotEmpty()) {
|
||||
NotiLogger.d("成功获取远程推送内容配置")
|
||||
val remoteContents = parseContentConfig(remoteJsonString)
|
||||
|
||||
// 更新本地配置
|
||||
pushContents = remoteContents
|
||||
contentJsonFromRemote = remoteJsonString
|
||||
NotiLogger.d("远程推送内容配置更新成功,共 ${remoteContents.size} 条")
|
||||
} else {
|
||||
NotiLogger.w("远程推送内容配置为空或获取超时,使用本地配置")
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
NotiLogger.e("获取远程推送内容配置异常", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 assets 加载内容配置文件
|
||||
* @param context 上下文
|
||||
* @return JSON 字符串
|
||||
*/
|
||||
private fun loadContentConfigFromAssets(context: Context): String {
|
||||
return try {
|
||||
context.assets.open(CONTENT_CONFIG_FILE_NAME).bufferedReader().use { it.readText() }
|
||||
} catch (e: IOException) {
|
||||
NotiLogger.e("加载推送内容配置文件失败", e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析内容配置 JSON
|
||||
* @param jsonString JSON 字符串
|
||||
* @return 内容列表
|
||||
*/
|
||||
private fun parseContentConfig(jsonString: String): List<PushContent> {
|
||||
return try {
|
||||
val type = object : TypeToken<List<PushContent>>() {}.type
|
||||
Gson().fromJson(jsonString, type)
|
||||
} catch (e: JsonSyntaxException) {
|
||||
NotiLogger.e("解析推送内容配置文件失败", e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前索引
|
||||
* @return 当前索引,首次调用返回-1
|
||||
*/
|
||||
private fun getCurrentIndex(): Int {
|
||||
return sharedPreferences.getInt(KEY_CURRENT_INDEX, -1)
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存当前索引到 SharedPreferences
|
||||
* @param index 索引
|
||||
*/
|
||||
private fun saveCurrentIndex(index: Int) {
|
||||
sharedPreferences.edit().putInt(KEY_CURRENT_INDEX, index).apply()
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,6 @@ import android.database.Cursor
|
|||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import com.remax.notification.config.NotificationConfigController
|
||||
import com.remax.notification.config.PushContentController
|
||||
import com.remax.notification.controller.NotificationTriggerController
|
||||
import com.remax.notification.timing.NotificationTimingController
|
||||
import com.remax.notification.check.NotificationCheckController
|
||||
|
|
@ -65,15 +64,6 @@ class NotificationProvider : ContentProvider() {
|
|||
} else {
|
||||
NotiLogger.e("推送配置控制器初始化失败")
|
||||
}
|
||||
|
||||
// 初始化推送内容控制器
|
||||
val contentSuccess = PushContentController.initialize(context!!)
|
||||
if (contentSuccess) {
|
||||
NotiLogger.d("推送内容控制器初始化成功")
|
||||
} else {
|
||||
NotiLogger.e("推送内容控制器初始化失败")
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
NotiLogger.e("初始化配置控制器时发生异常", e)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue