pref: Target SDK 31
This commit is contained in:
parent
6b3ecf37da
commit
37aab60ddc
|
|
@ -27,7 +27,7 @@ android {
|
||||||
applicationId "com.huanchengfly.tieba.post"
|
applicationId "com.huanchengfly.tieba.post"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
//noinspection OldTargetApi
|
//noinspection OldTargetApi
|
||||||
targetSdkVersion 30
|
targetSdkVersion 31
|
||||||
versionCode applicationVersionCode
|
versionCode applicationVersionCode
|
||||||
versionName applicationVersionName
|
versionName applicationVersionName
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
@ -64,7 +64,6 @@ android {
|
||||||
}
|
}
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
jvmTarget = '1.8'
|
jvmTarget = '1.8'
|
||||||
useIR = true
|
|
||||||
}
|
}
|
||||||
packagingOptions {
|
packagingOptions {
|
||||||
resources {
|
resources {
|
||||||
|
|
@ -74,11 +73,11 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "org.jetbrains:annotations:19.0.0"
|
implementation 'org.jetbrains:annotations:23.0.0'
|
||||||
|
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2"
|
api 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.2'
|
||||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2"
|
api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.2'
|
||||||
|
|
||||||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
|
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
|
||||||
|
|
||||||
|
|
@ -126,13 +125,13 @@ dependencies {
|
||||||
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
|
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
|
||||||
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
|
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
|
||||||
|
|
||||||
implementation "com.google.code.gson:gson:2.8.7"
|
implementation 'com.google.code.gson:gson:2.9.0'
|
||||||
implementation "cn.dreamtobe.kpswitch:library:1.6.2"
|
implementation "cn.dreamtobe.kpswitch:library:1.6.2"
|
||||||
implementation "org.litepal.android:kotlin:3.0.0"
|
implementation "org.litepal.android:kotlin:3.0.0"
|
||||||
implementation "com.github.SheHuan:RecyclerViewAdapter:1.2.9"
|
implementation "com.github.SheHuan:RecyclerViewAdapter:1.2.9"
|
||||||
implementation "com.davemorrissey.labs:subsampling-scale-image-view-androidx:3.10.0"
|
implementation "com.davemorrissey.labs:subsampling-scale-image-view-androidx:3.10.0"
|
||||||
implementation "com.bm.photoview:library:2.0.7"
|
implementation "com.bm.photoview:library:2.0.7"
|
||||||
implementation "cn.jzvd:jiaozivideoplayer:7.7.0"
|
implementation 'cn.jzvd:jiaozivideoplayer:7.7.2.3300'
|
||||||
implementation "com.jrummyapps:colorpicker:2.1.7"
|
implementation "com.jrummyapps:colorpicker:2.1.7"
|
||||||
|
|
||||||
implementation "com.scwang.smart:refresh-layout-kernel:2.0.1"
|
implementation "com.scwang.smart:refresh-layout-kernel:2.0.1"
|
||||||
|
|
@ -149,11 +148,11 @@ dependencies {
|
||||||
implementation "com.jakewharton:butterknife:10.2.3"
|
implementation "com.jakewharton:butterknife:10.2.3"
|
||||||
kapt "com.jakewharton:butterknife-compiler:10.2.3"
|
kapt "com.jakewharton:butterknife-compiler:10.2.3"
|
||||||
|
|
||||||
implementation ("com.alibaba.android:vlayout:1.2.31@aar") {
|
implementation ('com.alibaba.android:vlayout:1.3.0@aar') {
|
||||||
transitive = true
|
transitive = true
|
||||||
}
|
}
|
||||||
|
|
||||||
def appCenterSdkVersion = '4.3.1'
|
def appCenterSdkVersion = '4.4.3'
|
||||||
implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
|
implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
|
||||||
implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"
|
implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"
|
||||||
implementation "com.microsoft.appcenter:appcenter-distribute:${appCenterSdkVersion}"
|
implementation "com.microsoft.appcenter:appcenter-distribute:${appCenterSdkVersion}"
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
|
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
|
||||||
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />
|
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />
|
||||||
<uses-permission android:name="com.miui.personalassistant.permission.FAVORITE" />
|
<uses-permission android:name="com.miui.personalassistant.permission.FAVORITE" />
|
||||||
|
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||||
|
|
||||||
<queries>
|
<queries>
|
||||||
<package android:name="com.baidu.tieba" />
|
<package android:name="com.baidu.tieba" />
|
||||||
|
|
@ -101,6 +102,7 @@
|
||||||
android:configChanges="screenSize|screenLayout|orientation|smallestScreenSize|keyboardHidden"
|
android:configChanges="screenSize|screenLayout|orientation|smallestScreenSize|keyboardHidden"
|
||||||
android:resizeableActivity="true"
|
android:resizeableActivity="true"
|
||||||
android:theme="@style/AppTheme.Splash"
|
android:theme="@style/AppTheme.Splash"
|
||||||
|
android:exported="true"
|
||||||
android:windowSoftInputMode="adjustResize">
|
android:windowSoftInputMode="adjustResize">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
@ -156,7 +158,9 @@
|
||||||
android:name=".activities.AboutActivity"
|
android:name=".activities.AboutActivity"
|
||||||
android:configChanges="screenSize|screenLayout|orientation|smallestScreenSize|keyboardHidden"
|
android:configChanges="screenSize|screenLayout|orientation|smallestScreenSize|keyboardHidden"
|
||||||
android:windowSoftInputMode="adjustResize" />
|
android:windowSoftInputMode="adjustResize" />
|
||||||
<activity android:name=".activities.DispatchActivity">
|
<activity
|
||||||
|
android:name=".activities.DispatchActivity"
|
||||||
|
android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<data
|
<data
|
||||||
android:host="tieba.baidu.com"
|
android:host="tieba.baidu.com"
|
||||||
|
|
@ -198,6 +202,7 @@
|
||||||
android:windowSoftInputMode="adjustPan" />
|
android:windowSoftInputMode="adjustPan" />
|
||||||
|
|
||||||
<service
|
<service
|
||||||
|
android:exported="true"
|
||||||
android:name=".services.OKSignTileService"
|
android:name=".services.OKSignTileService"
|
||||||
android:icon="@drawable/ic_oksign"
|
android:icon="@drawable/ic_oksign"
|
||||||
android:label="@string/title_oksign"
|
android:label="@string/title_oksign"
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,13 @@ package com.huanchengfly.tieba.post
|
||||||
|
|
||||||
import android.animation.LayoutTransition
|
import android.animation.LayoutTransition
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
|
import android.app.PendingIntent
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.res.ColorStateList
|
import android.content.res.ColorStateList
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.content.res.Configuration.SCREENLAYOUT_SIZE_MASK
|
import android.content.res.Configuration.SCREENLAYOUT_SIZE_MASK
|
||||||
|
import android.os.Build
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
|
@ -103,4 +105,20 @@ val Configuration.isTablet: Boolean
|
||||||
get() = (screenLayout and SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE
|
get() = (screenLayout and SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE
|
||||||
|
|
||||||
val Context.isTablet: Boolean
|
val Context.isTablet: Boolean
|
||||||
get() = resources.configuration.isTablet
|
get() = resources.configuration.isTablet
|
||||||
|
|
||||||
|
fun pendingIntentFlagMutable(): Int {
|
||||||
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
|
PendingIntent.FLAG_MUTABLE
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun pendingIntentFlagImmutable(): Int {
|
||||||
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
PendingIntent.FLAG_IMMUTABLE
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
package com.huanchengfly.tieba.post.components.workers
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.work.Worker
|
|
||||||
import androidx.work.WorkerParameters
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
import kotlin.coroutines.CoroutineContext
|
|
||||||
|
|
||||||
class OKSignWorker(
|
|
||||||
context: Context,
|
|
||||||
workerParams: WorkerParameters
|
|
||||||
) : Worker(context, workerParams), CoroutineScope {
|
|
||||||
override fun doWork(): Result {
|
|
||||||
return Result.success()
|
|
||||||
}
|
|
||||||
|
|
||||||
val job = Job()
|
|
||||||
|
|
||||||
override val coroutineContext: CoroutineContext
|
|
||||||
get() = Dispatchers.Main + job
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +1,14 @@
|
||||||
package com.huanchengfly.tieba.post.fragments
|
package com.huanchengfly.tieba.post.fragments
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.PowerManager
|
||||||
|
import android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
|
@ -20,9 +24,9 @@ import com.huanchengfly.tieba.post.components.prefs.TimePickerPreference
|
||||||
import com.huanchengfly.tieba.post.fragments.preference.PreferencesFragment
|
import com.huanchengfly.tieba.post.fragments.preference.PreferencesFragment
|
||||||
import com.huanchengfly.tieba.post.models.database.Account
|
import com.huanchengfly.tieba.post.models.database.Account
|
||||||
import com.huanchengfly.tieba.post.models.database.Block
|
import com.huanchengfly.tieba.post.models.database.Block
|
||||||
|
import com.huanchengfly.tieba.post.toastShort
|
||||||
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils
|
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils
|
||||||
import com.huanchengfly.tieba.post.utils.*
|
import com.huanchengfly.tieba.post.utils.*
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class SettingsFragment : PreferencesFragment() {
|
class SettingsFragment : PreferencesFragment() {
|
||||||
private var loginInfo: Account? = null
|
private var loginInfo: Account? = null
|
||||||
|
|
@ -31,6 +35,18 @@ class SettingsFragment : PreferencesFragment() {
|
||||||
refresh()
|
refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//忽略电池优化
|
||||||
|
private fun ignoreBatteryOptimization() {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
val powerManager = attachContext.getSystemService(Context.POWER_SERVICE) as PowerManager
|
||||||
|
if (!powerManager.isIgnoringBatteryOptimizations(attachContext.packageName)) {
|
||||||
|
val intent = Intent(ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
|
||||||
|
intent.data = Uri.parse("package:${attachContext.packageName}")
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun refresh() {
|
private fun refresh() {
|
||||||
loginInfo = AccountUtil.getLoginInfo(attachContext)
|
loginInfo = AccountUtil.getLoginInfo(attachContext)
|
||||||
val accounts = AccountUtil.allAccounts
|
val accounts = AccountUtil.allAccounts
|
||||||
|
|
@ -56,23 +72,62 @@ class SettingsFragment : PreferencesFragment() {
|
||||||
preferenceManager.sharedPreferencesName = "settings"
|
preferenceManager.sharedPreferencesName = "settings"
|
||||||
addPreferencesFromResource(R.xml.preferences)
|
addPreferencesFromResource(R.xml.preferences)
|
||||||
val accountsPreference = findPreference<ListPreference>("switch_account")
|
val accountsPreference = findPreference<ListPreference>("switch_account")
|
||||||
accountsPreference!!.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any? ->
|
accountsPreference!!.onPreferenceChangeListener =
|
||||||
if (AccountUtil.switchUser(attachContext, Integer.valueOf((newValue as String?)!!))) {
|
Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any? ->
|
||||||
refresh()
|
if (AccountUtil.switchUser(
|
||||||
Toast.makeText(attachContext, R.string.toast_switch_success, Toast.LENGTH_SHORT).show()
|
attachContext,
|
||||||
|
Integer.valueOf((newValue as String?)!!)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
refresh()
|
||||||
|
Toast.makeText(attachContext, R.string.toast_switch_success, Toast.LENGTH_SHORT)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
false
|
||||||
}
|
}
|
||||||
false
|
findPreference<Preference>("ignore_battery_optimization")?.let {
|
||||||
}
|
val powerManager = attachContext.getSystemService(Context.POWER_SERVICE) as PowerManager
|
||||||
findPreference<Preference>("copy_bduss")!!.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||||
val account = AccountUtil.getLoginInfo(attachContext)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
if (account != null) {
|
if (!powerManager.isIgnoringBatteryOptimizations(attachContext.packageName)) {
|
||||||
TiebaUtil.copyText(attachContext, account.bduss)
|
ignoreBatteryOptimization()
|
||||||
|
} else {
|
||||||
|
attachContext.toastShort(R.string.toast_ignore_battery_optimization_already)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
it.isEnabled =
|
||||||
|
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !powerManager.isIgnoringBatteryOptimizations(
|
||||||
|
attachContext.packageName
|
||||||
|
)
|
||||||
|
it.setSummaryProvider {
|
||||||
|
when {
|
||||||
|
Build.VERSION.SDK_INT < Build.VERSION_CODES.M -> {
|
||||||
|
attachContext.getString(R.string.summary_battery_optimization_old_android_version)
|
||||||
|
}
|
||||||
|
powerManager.isIgnoringBatteryOptimizations(attachContext.packageName) -> {
|
||||||
|
attachContext.getString(R.string.summary_battery_optimization_ignored)
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
attachContext.getString(R.string.summary_ignore_battery_optimization)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
true
|
|
||||||
}
|
}
|
||||||
findPreference<Preference>("exit_account")!!.isEnabled = AccountUtil.isLoggedIn(attachContext)
|
findPreference<Preference>("copy_bduss")!!.onPreferenceClickListener =
|
||||||
findPreference<Preference>("exit_account")!!.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
Preference.OnPreferenceClickListener {
|
||||||
DialogUtil.build(attachContext)
|
val account = AccountUtil.getLoginInfo(attachContext)
|
||||||
|
if (account != null) {
|
||||||
|
TiebaUtil.copyText(attachContext, account.bduss)
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
findPreference<Preference>("exit_account")!!.isEnabled =
|
||||||
|
AccountUtil.isLoggedIn(attachContext)
|
||||||
|
findPreference<Preference>("exit_account")!!.onPreferenceClickListener =
|
||||||
|
Preference.OnPreferenceClickListener {
|
||||||
|
DialogUtil.build(attachContext)
|
||||||
.setMessage(R.string.title_dialog_exit_account)
|
.setMessage(R.string.title_dialog_exit_account)
|
||||||
.setPositiveButton(R.string.button_sure_default) { _: DialogInterface?, _: Int ->
|
.setPositiveButton(R.string.button_sure_default) { _: DialogInterface?, _: Int ->
|
||||||
AccountUtil.exit(attachContext)
|
AccountUtil.exit(attachContext)
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import android.app.PendingIntent
|
||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
import com.huanchengfly.tieba.post.pendingIntentFlagImmutable
|
||||||
import com.huanchengfly.tieba.post.utils.TiebaUtil
|
import com.huanchengfly.tieba.post.utils.TiebaUtil
|
||||||
import com.huanchengfly.tieba.post.utils.Util
|
import com.huanchengfly.tieba.post.utils.Util
|
||||||
import com.huanchengfly.tieba.post.utils.appPreferences
|
import com.huanchengfly.tieba.post.utils.appPreferences
|
||||||
|
|
@ -28,12 +28,12 @@ class BootCompleteSignReceiver : BroadcastReceiver() {
|
||||||
val time = Util.time2Calendar(autoSignTimeStr).apply {
|
val time = Util.time2Calendar(autoSignTimeStr).apply {
|
||||||
add(Calendar.DAY_OF_MONTH, 1)
|
add(Calendar.DAY_OF_MONTH, 1)
|
||||||
}.timeInMillis
|
}.timeInMillis
|
||||||
val pendingIntent = PendingIntent.getBroadcast(context, 0, Intent(context, AutoSignAlarm::class.java),
|
val pendingIntent = PendingIntent.getBroadcast(
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
context,
|
||||||
PendingIntent.FLAG_IMMUTABLE
|
0,
|
||||||
} else {
|
Intent(context, AutoSignAlarm::class.java),
|
||||||
0
|
pendingIntentFlagImmutable()
|
||||||
})
|
)
|
||||||
alarmManager.setInexactRepeating(AlarmManager.RTC, time, AlarmManager.INTERVAL_DAY, pendingIntent)
|
alarmManager.setInexactRepeating(AlarmManager.RTC, time, AlarmManager.INTERVAL_DAY, pendingIntent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import com.huanchengfly.tieba.post.activities.MessageActivity
|
||||||
import com.huanchengfly.tieba.post.api.TiebaApi
|
import com.huanchengfly.tieba.post.api.TiebaApi
|
||||||
import com.huanchengfly.tieba.post.api.models.MsgBean
|
import com.huanchengfly.tieba.post.api.models.MsgBean
|
||||||
import com.huanchengfly.tieba.post.fragments.MessageFragment
|
import com.huanchengfly.tieba.post.fragments.MessageFragment
|
||||||
|
import com.huanchengfly.tieba.post.pendingIntentFlagImmutable
|
||||||
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils
|
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils
|
||||||
import retrofit2.Call
|
import retrofit2.Call
|
||||||
import retrofit2.Callback
|
import retrofit2.Callback
|
||||||
|
|
@ -104,14 +105,10 @@ class NotifyJobService : JobService() {
|
||||||
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||||
.setContentIntent(
|
.setContentIntent(
|
||||||
PendingIntent.getActivity(
|
PendingIntent.getActivity(
|
||||||
this,
|
this,
|
||||||
0,
|
0,
|
||||||
intent,
|
intent,
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
pendingIntentFlagImmutable()
|
||||||
PendingIntent.FLAG_IMMUTABLE
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.setColor(ThemeUtils.getColorByAttr(this, R.attr.colorPrimary))
|
.setColor(ThemeUtils.getColorByAttr(this, R.attr.colorPrimary))
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import android.app.NotificationManager
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.*
|
import android.os.Build
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import com.huanchengfly.tieba.post.R
|
import com.huanchengfly.tieba.post.R
|
||||||
|
|
@ -14,11 +14,17 @@ import com.huanchengfly.tieba.post.activities.LoginActivity
|
||||||
import com.huanchengfly.tieba.post.activities.MainActivity
|
import com.huanchengfly.tieba.post.activities.MainActivity
|
||||||
import com.huanchengfly.tieba.post.api.models.SignResultBean
|
import com.huanchengfly.tieba.post.api.models.SignResultBean
|
||||||
import com.huanchengfly.tieba.post.models.SignDataBean
|
import com.huanchengfly.tieba.post.models.SignDataBean
|
||||||
|
import com.huanchengfly.tieba.post.pendingIntentFlagImmutable
|
||||||
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils
|
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils
|
||||||
import com.huanchengfly.tieba.post.utils.*
|
import com.huanchengfly.tieba.post.utils.AccountUtil
|
||||||
import kotlinx.coroutines.*
|
import com.huanchengfly.tieba.post.utils.ProgressListener
|
||||||
|
import com.huanchengfly.tieba.post.utils.SingleAccountSigner
|
||||||
|
import com.huanchengfly.tieba.post.utils.addFlag
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers.Main
|
import kotlinx.coroutines.Dispatchers.Main
|
||||||
import java.util.*
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.cancel
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
class OKSignService : IntentService(TAG), CoroutineScope, ProgressListener {
|
class OKSignService : IntentService(TAG), CoroutineScope, ProgressListener {
|
||||||
|
|
@ -54,13 +60,15 @@ class OKSignService : IntentService(TAG), CoroutineScope, ProgressListener {
|
||||||
|
|
||||||
private fun updateNotification(title: String, text: String, intent: Intent) {
|
private fun updateNotification(title: String, text: String, intent: Intent) {
|
||||||
manager.notify(1,
|
manager.notify(1,
|
||||||
buildNotification(title, text)
|
buildNotification(title, text)
|
||||||
.setContentIntent(PendingIntent.getActivity(this, 0, intent,
|
.setContentIntent(
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
PendingIntent.getActivity(
|
||||||
PendingIntent.FLAG_IMMUTABLE
|
this,
|
||||||
} else {
|
0,
|
||||||
0
|
intent,
|
||||||
}))
|
pendingIntentFlagImmutable()
|
||||||
|
)
|
||||||
|
)
|
||||||
.build())
|
.build())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package com.huanchengfly.tieba.post.utils;
|
package com.huanchengfly.tieba.post.utils;
|
||||||
|
|
||||||
|
import static com.huanchengfly.tieba.post.ExtensionsKt.pendingIntentFlagMutable;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.AlarmManager;
|
import android.app.AlarmManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
|
|
@ -114,7 +116,7 @@ public class CrashUtil {
|
||||||
context.getApplicationContext(),
|
context.getApplicationContext(),
|
||||||
0,
|
0,
|
||||||
intent,
|
intent,
|
||||||
0
|
pendingIntentFlagMutable()
|
||||||
);
|
);
|
||||||
mAlarmManager.set(AlarmManager.RTC, System.currentTimeMillis() + 1000,
|
mAlarmManager.set(AlarmManager.RTC, System.currentTimeMillis() + 1000,
|
||||||
restartIntent);
|
restartIntent);
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ abstract class IOKSigner(
|
||||||
|
|
||||||
abstract suspend fun start(): Boolean
|
abstract suspend fun start(): Boolean
|
||||||
|
|
||||||
|
abstract suspend fun startSync(): Boolean
|
||||||
|
|
||||||
suspend fun sign(signDataBean: SignDataBean): ApiResult<SignResultBean> {
|
suspend fun sign(signDataBean: SignDataBean): ApiResult<SignResultBean> {
|
||||||
return TiebaApi.getInstance()
|
return TiebaApi.getInstance()
|
||||||
.signAsync(signDataBean.forumName, signDataBean.tbs)
|
.signAsync(signDataBean.forumName, signDataBean.tbs)
|
||||||
|
|
@ -98,12 +100,50 @@ class SingleAccountSigner(
|
||||||
private var successCount = 0
|
private var successCount = 0
|
||||||
private var totalCount = 0
|
private var totalCount = 0
|
||||||
|
|
||||||
|
var lastFailure: Throwable? = null
|
||||||
|
|
||||||
private var mProgressListener: ProgressListener? = null
|
private var mProgressListener: ProgressListener? = null
|
||||||
|
|
||||||
fun setProgressListener(listener: ProgressListener?) {
|
fun setProgressListener(listener: ProgressListener?) {
|
||||||
mProgressListener = listener
|
mProgressListener = listener
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun startSync(): Boolean {
|
||||||
|
var result = false
|
||||||
|
signData.clear()
|
||||||
|
var userName: String by Delegates.notNull()
|
||||||
|
var tbs: String by Delegates.notNull()
|
||||||
|
AccountUtil.updateUserInfoAsync(coroutineScope, account.bduss)
|
||||||
|
.await()
|
||||||
|
.fetchIfSuccess {
|
||||||
|
userName = it.data.name
|
||||||
|
tbs = it.data.itbTbs
|
||||||
|
TiebaApi.getInstance().forumRecommendAsync().getData()
|
||||||
|
}
|
||||||
|
.doIfSuccess { forumRecommend ->
|
||||||
|
signData.addAll(forumRecommend.likeForum.filter { it.isSign != "1" }
|
||||||
|
.map { SignDataBean(it.forumName, userName, tbs) })
|
||||||
|
totalCount = signData.size
|
||||||
|
mProgressListener?.onStart(totalCount)
|
||||||
|
if (signData.isNotEmpty()) {
|
||||||
|
result = sign(0)
|
||||||
|
} else {
|
||||||
|
mProgressListener?.onFinish(true, 0, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.doIfFailure {
|
||||||
|
lastFailure = it
|
||||||
|
mProgressListener?.onFailure(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
it.getErrorCode(),
|
||||||
|
it.getErrorMessage()
|
||||||
|
)
|
||||||
|
throw it
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun start(): Boolean {
|
override suspend fun start(): Boolean {
|
||||||
var result = false
|
var result = false
|
||||||
signData.clear()
|
signData.clear()
|
||||||
|
|
@ -128,6 +168,7 @@ class SingleAccountSigner(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.doIfFailure {
|
.doIfFailure {
|
||||||
|
lastFailure = it
|
||||||
mProgressListener?.onFailure(
|
mProgressListener?.onFailure(
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import com.huanchengfly.tieba.post.activities.WebViewActivity
|
||||||
import com.huanchengfly.tieba.post.api.TiebaApi
|
import com.huanchengfly.tieba.post.api.TiebaApi
|
||||||
import com.huanchengfly.tieba.post.api.models.CheckReportBean
|
import com.huanchengfly.tieba.post.api.models.CheckReportBean
|
||||||
import com.huanchengfly.tieba.post.components.dialogs.LoadingDialog
|
import com.huanchengfly.tieba.post.components.dialogs.LoadingDialog
|
||||||
|
import com.huanchengfly.tieba.post.pendingIntentFlagImmutable
|
||||||
import com.huanchengfly.tieba.post.receivers.AutoSignAlarm
|
import com.huanchengfly.tieba.post.receivers.AutoSignAlarm
|
||||||
import com.huanchengfly.tieba.post.services.OKSignService
|
import com.huanchengfly.tieba.post.services.OKSignService
|
||||||
import com.huanchengfly.tieba.post.toastShort
|
import com.huanchengfly.tieba.post.toastShort
|
||||||
|
|
@ -41,11 +42,7 @@ object TiebaUtil {
|
||||||
context,
|
context,
|
||||||
0,
|
0,
|
||||||
Intent(context, AutoSignAlarm::class.java),
|
Intent(context, AutoSignAlarm::class.java),
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
pendingIntentFlagImmutable()
|
||||||
PendingIntent.FLAG_IMMUTABLE
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
if (autoSign) {
|
if (autoSign) {
|
||||||
val autoSignTimeStr = context.appPreferences.autoSignTime!!
|
val autoSignTimeStr = context.appPreferences.autoSignTime!!
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:tint="?attr/colorControlNormal"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M15.67,4L14,4L14,3c0,-0.55 -0.45,-1 -1,-1h-2c-0.55,0 -1,0.45 -1,1v1L8.33,4C7.6,4 7,4.6 7,5.33v15.33C7,21.4 7.6,22 8.34,22h7.32c0.74,0 1.34,-0.6 1.34,-1.33L17,5.33C17,4.6 16.4,4 15.67,4zM13,18h-2v-2h2v2zM13,13c0,0.55 -0.45,1 -1,1s-1,-0.45 -1,-1v-3c0,-0.55 0.45,-1 1,-1s1,0.45 1,1v3z" />
|
||||||
|
</vector>
|
||||||
|
|
@ -201,7 +201,7 @@
|
||||||
<string name="summary_auto_sign">开启后,将每天定时运行一键签到</string>
|
<string name="summary_auto_sign">开启后,将每天定时运行一键签到</string>
|
||||||
<string name="summary_auto_sign_on">自动签到已开启</string>
|
<string name="summary_auto_sign_on">自动签到已开启</string>
|
||||||
<string name="summary_auto_sign_time">当前设置为 %1$s</string>
|
<string name="summary_auto_sign_time">当前设置为 %1$s</string>
|
||||||
<string name="tip_auto_sign">提示:请您允许贴吧 Lite 的自启动,否则可能无法正常唤醒签到。</string>
|
<string name="tip_auto_sign">提示:请允许贴吧 Lite 的自启动,否则可能无法正常唤醒签到。\n若使用的是 MIUI 等国产定制 UI,你还需要在系统设置中进行相应修改。</string>
|
||||||
<string name="update_tip_no_content">点击查看完整更新日志</string>
|
<string name="update_tip_no_content">点击查看完整更新日志</string>
|
||||||
<string name="title_forum">%1$s吧</string>
|
<string name="title_forum">%1$s吧</string>
|
||||||
<string name="menu_edit_info">编辑资料</string>
|
<string name="menu_edit_info">编辑资料</string>
|
||||||
|
|
@ -498,4 +498,9 @@
|
||||||
<string name="toast_official_client_not_install">未安装官方版客户端</string>
|
<string name="toast_official_client_not_install">未安装官方版客户端</string>
|
||||||
<string name="button_pc_web_post">使用 PC 网页版发贴</string>
|
<string name="button_pc_web_post">使用 PC 网页版发贴</string>
|
||||||
<string name="title_post_or_reply_warning">发贴回贴风险提示</string>
|
<string name="title_post_or_reply_warning">发贴回贴风险提示</string>
|
||||||
|
<string name="summary_ignore_battery_optimization">请忽略“电池优化”以允许应用启动自动签到</string>
|
||||||
|
<string name="title_ignore_battery_optimization">忽略“电池优化”</string>
|
||||||
|
<string name="summary_battery_optimization_old_android_version">旧版 Android 无“电池优化”</string>
|
||||||
|
<string name="summary_battery_optimization_ignored">“电池优化”已忽略</string>
|
||||||
|
<string name="toast_ignore_battery_optimization_already">已忽略电池优化</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
|
|
@ -228,6 +228,12 @@
|
||||||
android:key="auto_sign_time"
|
android:key="auto_sign_time"
|
||||||
android:title="@string/title_auto_sign_time" />
|
android:title="@string/title_auto_sign_time" />
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:icon="@drawable/ic_round_battery_alert"
|
||||||
|
android:key="ignore_battery_optimization"
|
||||||
|
android:summary="@string/summary_ignore_battery_optimization"
|
||||||
|
android:title="@string/title_ignore_battery_optimization" />
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:layout="@layout/layout_preference_dense"
|
android:layout="@layout/layout_preference_dense"
|
||||||
android:summary="@string/tip_auto_sign" />
|
android:summary="@string/tip_auto_sign" />
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
ext {
|
ext {
|
||||||
glide_version = "4.12.0"
|
glide_version = '4.13.2'
|
||||||
retrofit_version = "2.9.0"
|
retrofit_version = "2.9.0"
|
||||||
kotlin_version = '1.5.31'
|
kotlin_version = '1.7.0'
|
||||||
}
|
}
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue