feat: V12 API
This commit is contained in:
parent
2828a122b3
commit
18cbbe1b76
|
|
@ -50,6 +50,7 @@ import com.huanchengfly.tieba.post.utils.Util
|
|||
import com.huanchengfly.tieba.post.utils.appPreferences
|
||||
import com.huanchengfly.tieba.post.utils.applicationMetaData
|
||||
import com.huanchengfly.tieba.post.utils.launchUrl
|
||||
import com.huanchengfly.tieba.post.utils.packageInfo
|
||||
import com.microsoft.appcenter.AppCenter
|
||||
import com.microsoft.appcenter.analytics.Analytics
|
||||
import com.microsoft.appcenter.crashes.Crashes
|
||||
|
|
@ -208,10 +209,11 @@ class App : Application(), IApp, SketchFactory {
|
|||
var encodedOAID: String = ""
|
||||
var isTrackLimited: Boolean = false
|
||||
var userAgent: String? = null
|
||||
var appFirstInstallTime: Long = 0L
|
||||
var appLastUpdateTime: Long = 0L
|
||||
|
||||
fun init(context: Context) {
|
||||
if (!inited) {
|
||||
userAgent = WebSettings.getDefaultUserAgent(context)
|
||||
isOAIDSupported = DeviceID.supportedOAID(context)
|
||||
if (isOAIDSupported) {
|
||||
DeviceID.getOAID(context, OAIDGetter)
|
||||
|
|
@ -219,6 +221,9 @@ class App : Application(), IApp, SketchFactory {
|
|||
statusCode = -200
|
||||
isTrackLimited = false
|
||||
}
|
||||
userAgent = WebSettings.getDefaultUserAgent(context)
|
||||
appFirstInstallTime = context.packageInfo.firstInstallTime
|
||||
appLastUpdateTime = context.packageInfo.lastUpdateTime
|
||||
inited = true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ import com.huanchengfly.tieba.post.ui.widgets.compose.DialogNegativeButton
|
|||
import com.huanchengfly.tieba.post.ui.widgets.compose.DialogPositiveButton
|
||||
import com.huanchengfly.tieba.post.ui.widgets.compose.rememberDialogState
|
||||
import com.huanchengfly.tieba.post.utils.AccountUtil
|
||||
import com.huanchengfly.tieba.post.utils.ClientUtils
|
||||
import com.huanchengfly.tieba.post.utils.JobServiceUtil
|
||||
import com.huanchengfly.tieba.post.utils.PermissionUtils
|
||||
import com.huanchengfly.tieba.post.utils.TiebaUtil
|
||||
|
|
@ -176,6 +177,9 @@ class MainActivityV2 : BaseComposeActivity() {
|
|||
super.onCreate(savedInstanceState)
|
||||
window.decorView.setBackgroundColor(Color.TRANSPARENT)
|
||||
window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
||||
launch {
|
||||
ClientUtils.setActiveTimestamp()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateContent(systemUiController: SystemUiController) {
|
||||
|
|
|
|||
|
|
@ -173,6 +173,9 @@ open class MainActivity : BaseActivity(), NavigationBarView.OnItemSelectedListen
|
|||
.collect()
|
||||
}
|
||||
}
|
||||
launch {
|
||||
ClientUtils.setActiveTimestamp()
|
||||
}
|
||||
mViewPager.post {
|
||||
Crashes.hasCrashedInLastSession()
|
||||
.thenAccept { hasCrashed ->
|
||||
|
|
|
|||
|
|
@ -112,5 +112,15 @@ fun buildCommonRequest(
|
|||
pversion = "1.0.3",
|
||||
sample_id = ClientUtils.sampleId,
|
||||
stoken = AccountUtil.getSToken(),
|
||||
scr_dip = App.ScreenInfo.DENSITY.toDouble(),
|
||||
scr_h = getScreenHeight(),
|
||||
scr_w = getScreenWidth(),
|
||||
sdk_ver = "2.34.0",
|
||||
framework_ver = "3340042",
|
||||
swan_game_ver = "1038000",
|
||||
cmode = 1,
|
||||
active_timestamp = ClientUtils.activeTimestamp,
|
||||
first_install_time = App.Config.appFirstInstallTime,
|
||||
user_agent = getUserAgent("tieba/${ClientVersion.TIEBA_V12}")
|
||||
)
|
||||
}
|
||||
|
|
@ -2,7 +2,9 @@ package com.huanchengfly.tieba.post.utils
|
|||
|
||||
import android.content.Context
|
||||
import androidx.datastore.preferences.core.edit
|
||||
import androidx.datastore.preferences.core.longPreferencesKey
|
||||
import androidx.datastore.preferences.core.stringPreferencesKey
|
||||
import com.huanchengfly.tieba.post.App
|
||||
import com.huanchengfly.tieba.post.api.TiebaApi
|
||||
import com.huanchengfly.tieba.post.dataStore
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
|
|
@ -12,21 +14,30 @@ import kotlinx.coroutines.flow.firstOrNull
|
|||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
object ClientUtils {
|
||||
private const val CLIENT_ID = "client_id"
|
||||
private const val SAMPLE_ID = "sample_id"
|
||||
private const val BAIDU_ID = "baidu_id"
|
||||
private const val ACTIVE_TIMESTAMP = "active_timestamp"
|
||||
|
||||
private val clientIdKey = stringPreferencesKey(CLIENT_ID)
|
||||
private val sampleIdKey = stringPreferencesKey(SAMPLE_ID)
|
||||
private val baiduIdKey = stringPreferencesKey(BAIDU_ID)
|
||||
private val clientIdKey by lazy { stringPreferencesKey(CLIENT_ID) }
|
||||
private val sampleIdKey by lazy { stringPreferencesKey(SAMPLE_ID) }
|
||||
private val baiduIdKey by lazy { stringPreferencesKey(BAIDU_ID) }
|
||||
private val activeTimestampKey by lazy { longPreferencesKey(ACTIVE_TIMESTAMP) }
|
||||
|
||||
private lateinit var contextWeakReference: WeakReference<Context>
|
||||
private val context: Context
|
||||
get() = contextWeakReference.get() ?: App.INSTANCE
|
||||
|
||||
var clientId: String? = null
|
||||
var sampleId: String? = null
|
||||
var baiduId: String? = null
|
||||
var activeTimestamp: Long = System.currentTimeMillis()
|
||||
|
||||
fun init(context: Context) {
|
||||
contextWeakReference = WeakReference(context)
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
clientId = withContext(Dispatchers.IO) {
|
||||
context.dataStore.data.map { it[clientIdKey] }.firstOrNull()
|
||||
|
|
@ -37,6 +48,10 @@ object ClientUtils {
|
|||
baiduId = withContext(Dispatchers.IO) {
|
||||
context.dataStore.data.map { it[baiduIdKey] }.firstOrNull()
|
||||
}
|
||||
activeTimestamp = withContext(Dispatchers.IO) {
|
||||
context.dataStore.data.map { it[activeTimestampKey] }.firstOrNull()
|
||||
?: System.currentTimeMillis()
|
||||
}
|
||||
sync(context)
|
||||
}
|
||||
}
|
||||
|
|
@ -48,6 +63,13 @@ object ClientUtils {
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun setActiveTimestamp() {
|
||||
activeTimestamp = System.currentTimeMillis()
|
||||
context.dataStore.edit {
|
||||
it[activeTimestampKey] = activeTimestamp
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun save(context: Context, clientId: String, sampleId: String) {
|
||||
context.dataStore.edit {
|
||||
it[clientIdKey] = clientId
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.huanchengfly.tieba.post.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageInfo
|
||||
|
||||
fun Context.isPackageInstalled(packageName: String): Boolean {
|
||||
return try {
|
||||
|
|
@ -11,6 +12,9 @@ fun Context.isPackageInstalled(packageName: String): Boolean {
|
|||
}
|
||||
}
|
||||
|
||||
val Context.packageInfo: PackageInfo
|
||||
get() = packageManager.getPackageInfo(packageName, 0)
|
||||
|
||||
fun Context.isAnyPackageInstalled(packages: Array<String>): Boolean {
|
||||
return packages.any {
|
||||
isPackageInstalled(it)
|
||||
|
|
|
|||
Loading…
Reference in New Issue