整理:code review

This commit is contained in:
pppscn 2022-09-23 00:37:07 +08:00
parent 3430dbbe8e
commit 668847c91f
26 changed files with 200 additions and 101 deletions

1
.gitignore vendored
View File

@ -35,3 +35,4 @@
/app/seeds.txt /app/seeds.txt
/app/unused.txt /app/unused.txt
/pic/*.bkp /pic/*.bkp
/*.txt

View File

@ -203,11 +203,11 @@ dependencies {
implementation 'com.github.xuexiangjys.AgentWeb:agentweb-core:1.0.0' implementation 'com.github.xuexiangjys.AgentWeb:agentweb-core:1.0.0'
implementation 'com.github.xuexiangjys.AgentWeb:agentweb-download:1.0.0'// implementation 'com.github.xuexiangjys.AgentWeb:agentweb-download:1.0.0'//
//mmkvhttps://github.com/Tencent/MMKV //mmkvhttps://github.com/Tencent/MMKV
implementation 'com.tencent:mmkv:1.2.13' implementation 'com.tencent:mmkv:1.2.14'
//AutoSizehttps://github.com/JessYanCoding/AndroidAutoSize //AutoSizehttps://github.com/JessYanCoding/AndroidAutoSize
implementation 'me.jessyan:autosize:1.2.1' implementation 'me.jessyan:autosize:1.2.1'
//umeng统计 //umeng统计
implementation 'com.umeng.umsdk:common:9.5.0' implementation 'com.umeng.umsdk:common:9.5.2'
implementation 'com.umeng.umsdk:asms:1.6.3' implementation 'com.umeng.umsdk:asms:1.6.3'
// //

View File

@ -166,8 +166,6 @@
-dontwarn com.squareup.okhttp3.** -dontwarn com.squareup.okhttp3.**
-keep class com.squareup.okhttp3.** { *;} -keep class com.squareup.okhttp3.** { *;}
-dontwarn okio.** -dontwarn okio.**
-dontwarn javax.annotation.Nullable
-dontwarn javax.annotation.ParametersAreNonnullByDefault
-dontwarn javax.annotation.** -dontwarn javax.annotation.**
#如果用到Gson解析包的直接添加下面这几行就能成功混淆不然会报错 #如果用到Gson解析包的直接添加下面这几行就能成功混淆不然会报错
@ -208,8 +206,6 @@
#} #}
-dontwarn okio.** -dontwarn okio.**
-dontwarn javax.annotation.Nullable
-dontwarn javax.annotation.ParametersAreNonnullByDefault
-dontwarn javax.annotation.** -dontwarn javax.annotation.**
# fastjson # fastjson

View File

@ -19,7 +19,9 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" /> <uses-permission
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.RECEIVE_SMS" /> <uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" /> <uses-permission android:name="android.permission.READ_SMS" />

View File

@ -44,7 +44,14 @@ import com.xuexiang.xutil.net.JsonUtil
* @author xuexiang * @author xuexiang
* @since 2019/1/4 下午11:13 * @since 2019/1/4 下午11:13
*/ */
@Suppress("unused", "MemberVisibilityCanBePrivate", "ProtectedInFinal", "NAME_SHADOWING", "UNUSED_PARAMETER", "OVERRIDE_DEPRECATION") @Suppress(
"unused",
"MemberVisibilityCanBePrivate",
"ProtectedInFinal",
"NAME_SHADOWING",
"UNUSED_PARAMETER",
"OVERRIDE_DEPRECATION"
)
class AgentWebFragment : Fragment(), FragmentKeyDown { class AgentWebFragment : Fragment(), FragmentKeyDown {
private var mBackImageView: ImageView? = null private var mBackImageView: ImageView? = null
private var mLineView: View? = null private var mLineView: View? = null
@ -372,11 +379,11 @@ class AgentWebFragment : Fragment(), FragmentKeyDown {
override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) { override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) {
Log.i(TAG, "mUrl:$url onPageStarted target:$url") Log.i(TAG, "mUrl:$url onPageStarted target:$url")
timer[url] = System.currentTimeMillis() timer[url] = System.currentTimeMillis()
if (url == url) { //if (url == url) {
pageNavigator(View.GONE) // pageNavigator(View.GONE)
} else { //} else {
pageNavigator(View.VISIBLE) pageNavigator(View.VISIBLE)
} //}
} }
override fun onPageFinished(view: WebView, url: String) { override fun onPageFinished(view: WebView, url: String) {
@ -495,7 +502,8 @@ class AgentWebFragment : Fragment(), FragmentKeyDown {
* @param text * @param text
*/ */
private fun toCopy(context: Context?, text: String) { private fun toCopy(context: Context?, text: String) {
val manager = requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager val manager =
requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
manager.setPrimaryClip(ClipData.newPlainText(null, text)) manager.setPrimaryClip(ClipData.newPlainText(null, text))
} }

View File

@ -360,11 +360,11 @@ class XPageWebViewFragment : BaseFragment<FragmentAgentwebBinding?>(), View.OnCl
override fun onPageStarted(view: WebView, url: String, favicon: Bitmap) { override fun onPageStarted(view: WebView, url: String, favicon: Bitmap) {
mTimer[url] = System.currentTimeMillis() mTimer[url] = System.currentTimeMillis()
if (url == url) { //if (url == url) {
pageNavigator(View.GONE) // pageNavigator(View.GONE)
} else { //} else {
pageNavigator(View.VISIBLE) pageNavigator(View.VISIBLE)
} //}
} }
override fun onPageFinished(view: WebView, url: String) { override fun onPageFinished(view: WebView, url: String) {
@ -480,7 +480,8 @@ class XPageWebViewFragment : BaseFragment<FragmentAgentwebBinding?>(), View.OnCl
* @param text * @param text
*/ */
private fun toCopy(context: Context?, text: String) { private fun toCopy(context: Context?, text: String) {
val manager = requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager val manager =
requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
manager.setPrimaryClip(ClipData.newPlainText(null, text)) manager.setPrimaryClip(ClipData.newPlainText(null, text))
} }

View File

@ -44,13 +44,13 @@ abstract class AppDatabase : RoomDatabase() {
} }
private fun buildDatabase(context: Context): AppDatabase { private fun buildDatabase(context: Context): AppDatabase {
var builder = Room.databaseBuilder( val builder = Room.databaseBuilder(
context.applicationContext, context.applicationContext,
AppDatabase::class.java, AppDatabase::class.java,
DATABASE_NAME DATABASE_NAME
) )
.allowMainThreadQueries() //TODO:允许主线程访问,后面再优化 .allowMainThreadQueries() //TODO:允许主线程访问,后面再优化
.addCallback(object : RoomDatabase.Callback() { .addCallback(object : Callback() {
override fun onCreate(db: SupportSQLiteDatabase) { override fun onCreate(db: SupportSQLiteDatabase) {
//fillInDb(context.applicationContext) //fillInDb(context.applicationContext)
db.execSQL( db.execSQL(

View File

@ -635,7 +635,7 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding?>(), View.OnClickL
KeepAliveUtils.ignoreBatteryOptimization(requireActivity()) KeepAliveUtils.ignoreBatteryOptimization(requireActivity())
} else if (isChecked) { } else if (isChecked) {
XToastUtils.info(R.string.isIgnored) XToastUtils.info(R.string.isIgnored)
sbBatterySetting.isChecked = isIgnoreBatteryOptimization sbBatterySetting.isChecked = true
} else { } else {
XToastUtils.info(R.string.isIgnored2) XToastUtils.info(R.string.isIgnored2)
sbBatterySetting.isChecked = isIgnoreBatteryOptimization sbBatterySetting.isChecked = isIgnoreBatteryOptimization

View File

@ -75,7 +75,8 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
.request(object : OnPermissionCallback { .request(object : OnPermissionCallback {
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun onGranted(permissions: List<String>, all: Boolean) { override fun onGranted(permissions: List<String>, all: Boolean) {
backupPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).path backupPath =
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).path
binding!!.tvBackupPath.text = backupPath + File.separator + backupFile binding!!.tvBackupPath.text = backupPath + File.separator + backupFile
} }
@ -105,7 +106,8 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
//按钮增加倒计时,避免重复点击 //按钮增加倒计时,避免重复点击
pushCountDownHelper = CountDownButtonHelper(binding!!.btnPush, SettingUtils.requestTimeout) pushCountDownHelper = CountDownButtonHelper(binding!!.btnPush, SettingUtils.requestTimeout)
pushCountDownHelper!!.setOnCountDownListener(object : CountDownButtonHelper.OnCountDownListener { pushCountDownHelper!!.setOnCountDownListener(object :
CountDownButtonHelper.OnCountDownListener {
override fun onCountDown(time: Int) { override fun onCountDown(time: Int) {
binding!!.btnPush.text = String.format(getString(R.string.seconds_n), time) binding!!.btnPush.text = String.format(getString(R.string.seconds_n), time)
} }
@ -115,7 +117,8 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
} }
}) })
pullCountDownHelper = CountDownButtonHelper(binding!!.btnPull, SettingUtils.requestTimeout) pullCountDownHelper = CountDownButtonHelper(binding!!.btnPull, SettingUtils.requestTimeout)
pullCountDownHelper!!.setOnCountDownListener(object : CountDownButtonHelper.OnCountDownListener { pullCountDownHelper!!.setOnCountDownListener(object :
CountDownButtonHelper.OnCountDownListener {
override fun onCountDown(time: Int) { override fun onCountDown(time: Int) {
binding!!.btnPull.text = String.format(getString(R.string.seconds_n), time) binding!!.btnPull.text = String.format(getString(R.string.seconds_n), time)
} }
@ -125,7 +128,8 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
} }
}) })
exportCountDownHelper = CountDownButtonHelper(binding!!.btnExport, 3) exportCountDownHelper = CountDownButtonHelper(binding!!.btnExport, 3)
exportCountDownHelper!!.setOnCountDownListener(object : CountDownButtonHelper.OnCountDownListener { exportCountDownHelper!!.setOnCountDownListener(object :
CountDownButtonHelper.OnCountDownListener {
override fun onCountDown(time: Int) { override fun onCountDown(time: Int) {
binding!!.btnExport.text = String.format(getString(R.string.seconds_n), time) binding!!.btnExport.text = String.format(getString(R.string.seconds_n), time)
} }
@ -135,7 +139,8 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
} }
}) })
importCountDownHelper = CountDownButtonHelper(binding!!.btnImport, 3) importCountDownHelper = CountDownButtonHelper(binding!!.btnImport, 3)
importCountDownHelper!!.setOnCountDownListener(object : CountDownButtonHelper.OnCountDownListener { importCountDownHelper!!.setOnCountDownListener(object :
CountDownButtonHelper.OnCountDownListener {
override fun onCountDown(time: Int) { override fun onCountDown(time: Int) {
binding!!.btnImport.text = String.format(getString(R.string.seconds_n), time) binding!!.btnImport.text = String.format(getString(R.string.seconds_n), time)
} }
@ -176,7 +181,12 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
XToastUtils.error(getString(R.string.export_failed)) XToastUtils.error(getString(R.string.export_failed))
} }
} catch (e: Exception) { } catch (e: Exception) {
XToastUtils.error(String.format(getString(R.string.export_failed_tips), e.message)) XToastUtils.error(
String.format(
getString(R.string.export_failed_tips),
e.message
)
)
} }
} }
//导入配置 //导入配置
@ -199,7 +209,9 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
//替换Date字段为当前时间 //替换Date字段为当前时间
val builder = GsonBuilder() val builder = GsonBuilder()
builder.registerTypeAdapter(Date::class.java, JsonDeserializer<Any?> { _, _, _ -> Date() }) builder.registerTypeAdapter(
Date::class.java,
JsonDeserializer<Any?> { _, _, _ -> Date() })
val gson = builder.create() val gson = builder.create()
val cloneInfo = gson.fromJson(jsonStr, CloneInfo::class.java) val cloneInfo = gson.fromJson(jsonStr, CloneInfo::class.java)
Log.d(TAG, "cloneInfo = $cloneInfo") Log.d(TAG, "cloneInfo = $cloneInfo")
@ -213,7 +225,12 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
XToastUtils.error(getString(R.string.import_failed)) XToastUtils.error(getString(R.string.import_failed))
} }
} catch (e: Exception) { } catch (e: Exception) {
XToastUtils.error(String.format(getString(R.string.import_failed_tips), e.message)) XToastUtils.error(
String.format(
getString(R.string.import_failed_tips),
e.message
)
)
} }
} }
} }
@ -236,7 +253,8 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
msgMap["timestamp"] = timestamp msgMap["timestamp"] = timestamp
val clientSignKey = HttpServerUtils.clientSignKey val clientSignKey = HttpServerUtils.clientSignKey
if (!TextUtils.isEmpty(clientSignKey)) { if (!TextUtils.isEmpty(clientSignKey)) {
msgMap["sign"] = HttpServerUtils.calcSign(timestamp.toString(), clientSignKey.toString()) msgMap["sign"] =
HttpServerUtils.calcSign(timestamp.toString(), clientSignKey.toString())
} }
msgMap["data"] = HttpServerUtils.exportSettings() msgMap["data"] = HttpServerUtils.exportSettings()
@ -261,7 +279,10 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
override fun onSuccess(response: String) { override fun onSuccess(response: String) {
Log.i(TAG, response) Log.i(TAG, response)
try { try {
val resp: BaseResponse<String> = Gson().fromJson(response, object : TypeToken<BaseResponse<String>>() {}.type) val resp: BaseResponse<String> = Gson().fromJson(
response,
object : TypeToken<BaseResponse<String>>() {}.type
)
if (resp.code == 200) { if (resp.code == 200) {
XToastUtils.success(ResUtils.getString(R.string.request_succeeded)) XToastUtils.success(ResUtils.getString(R.string.request_succeeded))
} else { } else {
@ -283,7 +304,7 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
XToastUtils.error(getString(R.string.invalid_service_address)) XToastUtils.error(getString(R.string.invalid_service_address))
return return
} }
exportCountDownHelper?.start() exportCountDownHelper?.start()
val requestUrl: String = HttpServerUtils.serverAddress + "/clone/pull" val requestUrl: String = HttpServerUtils.serverAddress + "/clone/pull"
@ -294,7 +315,8 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
msgMap["timestamp"] = timestamp msgMap["timestamp"] = timestamp
val clientSignKey = HttpServerUtils.clientSignKey val clientSignKey = HttpServerUtils.clientSignKey
if (!TextUtils.isEmpty(clientSignKey)) { if (!TextUtils.isEmpty(clientSignKey)) {
msgMap["sign"] = HttpServerUtils.calcSign(timestamp.toString(), clientSignKey.toString()) msgMap["sign"] =
HttpServerUtils.calcSign(timestamp.toString(), clientSignKey.toString())
} }
val dataMap: MutableMap<String, Any> = mutableMapOf() val dataMap: MutableMap<String, Any> = mutableMapOf()
@ -324,15 +346,20 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
try { try {
//替换Date字段为当前时间 //替换Date字段为当前时间
val builder = GsonBuilder() val builder = GsonBuilder()
builder.registerTypeAdapter(Date::class.java, JsonDeserializer<Any?> { _, _, _ -> Date() }) builder.registerTypeAdapter(
Date::class.java,
JsonDeserializer<Any?> { _, _, _ -> Date() })
val gson = builder.create() val gson = builder.create()
val resp: BaseResponse<CloneInfo> = gson.fromJson(response, object : TypeToken<BaseResponse<CloneInfo>>() {}.type) val resp: BaseResponse<CloneInfo> = gson.fromJson(
response,
object : TypeToken<BaseResponse<CloneInfo>>() {}.type
)
if (resp.code == 200) { if (resp.code == 200) {
val cloneInfo = resp.data val cloneInfo = resp.data
Log.d(TAG, "cloneInfo = $cloneInfo") Log.d(TAG, "cloneInfo = $cloneInfo")
if (cloneInfo == null) { if (cloneInfo == null) {
XToastUtils.error(ResUtils.getString(R.string.request_failed) + cloneInfo) XToastUtils.error(ResUtils.getString(R.string.request_failed))
return return
} }

View File

@ -51,7 +51,8 @@ class WolSendFragment : BaseFragment<FragmentClientWolSendBinding?>(), View.OnCl
override fun initViews() { override fun initViews() {
//发送按钮增加倒计时,避免重复点击 //发送按钮增加倒计时,避免重复点击
mCountDownHelper = CountDownButtonHelper(binding!!.btnSubmit, SettingUtils.requestTimeout) mCountDownHelper = CountDownButtonHelper(binding!!.btnSubmit, SettingUtils.requestTimeout)
mCountDownHelper!!.setOnCountDownListener(object : CountDownButtonHelper.OnCountDownListener { mCountDownHelper!!.setOnCountDownListener(object :
CountDownButtonHelper.OnCountDownListener {
override fun onCountDown(time: Int) { override fun onCountDown(time: Int) {
binding!!.btnSubmit.text = String.format(getString(R.string.seconds_n), time) binding!!.btnSubmit.text = String.format(getString(R.string.seconds_n), time)
} }
@ -64,7 +65,8 @@ class WolSendFragment : BaseFragment<FragmentClientWolSendBinding?>(), View.OnCl
//取出历史记录 //取出历史记录
val history = HttpServerUtils.wolHistory val history = HttpServerUtils.wolHistory
if (!TextUtils.isEmpty(history)) { if (!TextUtils.isEmpty(history)) {
wolHistory = Gson().fromJson(history, object : TypeToken<MutableMap<String, String>>() {}.type) wolHistory =
Gson().fromJson(history, object : TypeToken<MutableMap<String, String>>() {}.type)
} }
} }
@ -83,7 +85,7 @@ class WolSendFragment : BaseFragment<FragmentClientWolSendBinding?>(), View.OnCl
} }
Log.d(TAG, "wolHistory = $wolHistory") Log.d(TAG, "wolHistory = $wolHistory")
MaterialDialog.Builder(context!!) MaterialDialog.Builder(requireContext())
.title(R.string.server_history) .title(R.string.server_history)
.items(wolHistory.keys) .items(wolHistory.keys)
.itemsCallbackSingleChoice(0) { _: MaterialDialog?, _: View?, _: Int, text: CharSequence -> .itemsCallbackSingleChoice(0) { _: MaterialDialog?, _: View?, _: Int, text: CharSequence ->
@ -111,7 +113,8 @@ class WolSendFragment : BaseFragment<FragmentClientWolSendBinding?>(), View.OnCl
msgMap["timestamp"] = timestamp msgMap["timestamp"] = timestamp
val clientSignKey = HttpServerUtils.clientSignKey val clientSignKey = HttpServerUtils.clientSignKey
if (!TextUtils.isEmpty(clientSignKey)) { if (!TextUtils.isEmpty(clientSignKey)) {
msgMap["sign"] = HttpServerUtils.calcSign(timestamp.toString(), clientSignKey.toString()) msgMap["sign"] =
HttpServerUtils.calcSign(timestamp.toString(), clientSignKey.toString())
} }
val mac = binding!!.etMac.text.toString() val mac = binding!!.etMac.text.toString()
@ -161,7 +164,10 @@ class WolSendFragment : BaseFragment<FragmentClientWolSendBinding?>(), View.OnCl
override fun onSuccess(response: String) { override fun onSuccess(response: String) {
Log.i(TAG, response) Log.i(TAG, response)
try { try {
val resp: BaseResponse<String> = Gson().fromJson(response, object : TypeToken<BaseResponse<String>>() {}.type) val resp: BaseResponse<String> = Gson().fromJson(
response,
object : TypeToken<BaseResponse<String>>() {}.type
)
if (resp.code == 200) { if (resp.code == 200) {
XToastUtils.success(ResUtils.getString(R.string.request_succeeded)) XToastUtils.success(ResUtils.getString(R.string.request_succeeded))
//添加到历史记录 //添加到历史记录

View File

@ -21,7 +21,6 @@ import com.idormy.sms.forwarder.utils.PhoneUtils
import com.idormy.sms.forwarder.utils.SettingUtils import com.idormy.sms.forwarder.utils.SettingUtils
import com.idormy.sms.forwarder.utils.Worker import com.idormy.sms.forwarder.utils.Worker
import com.idormy.sms.forwarder.workers.SendWorker import com.idormy.sms.forwarder.workers.SendWorker
import com.xuexiang.xutil.resource.ResUtils
import com.xuexiang.xutil.resource.ResUtils.getString import com.xuexiang.xutil.resource.ResUtils.getString
import java.util.* import java.util.*
@ -40,7 +39,11 @@ class PhoneStateReceiver : BroadcastReceiver() {
if (TelephonyManager.ACTION_PHONE_STATE_CHANGED != intent.action) return if (TelephonyManager.ACTION_PHONE_STATE_CHANGED != intent.action) return
//权限判断 //权限判断
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) return if (ActivityCompat.checkSelfPermission(
context,
Manifest.permission.READ_PHONE_STATE
) != PackageManager.PERMISSION_GRANTED
) return
//获取来电号码 //获取来电号码
val number = intent.extras!!.getString(TelephonyManager.EXTRA_INCOMING_NUMBER) val number = intent.extras!!.getString(TelephonyManager.EXTRA_INCOMING_NUMBER)
@ -80,11 +83,12 @@ class PhoneStateReceiver : BroadcastReceiver() {
//来电提醒 //来电提醒
if (!TextUtils.isEmpty(number) && SettingUtils.enableCallType4) { if (!TextUtils.isEmpty(number) && SettingUtils.enableCallType4) {
val contacts = PhoneUtils.getContactByNumber(number) val contacts = PhoneUtils.getContactByNumber(number)
val contactName = if (contacts.isNotEmpty()) contacts[0].name else getString(R.string.unknown_number) val contactName =
if (contacts.isNotEmpty()) contacts[0].name else getString(R.string.unknown_number)
val sb = StringBuilder() val sb = StringBuilder()
sb.append(getString(R.string.linkman)).append(contactName).append("\n") sb.append(getString(R.string.linkman)).append(contactName).append("\n")
sb.append(ResUtils.getString(R.string.mandatory_type)) sb.append(getString(R.string.mandatory_type))
sb.append(getString(R.string.incoming_call)) sb.append(getString(R.string.incoming_call))
val msgInfo = MsgInfo("call", number.toString(), sb.toString(), Date(), "", -1) val msgInfo = MsgInfo("call", number.toString(), sb.toString(), Date(), "", -1)
@ -117,15 +121,27 @@ class PhoneStateReceiver : BroadcastReceiver() {
when { when {
lastState == TelephonyManager.CALL_STATE_RINGING -> { lastState == TelephonyManager.CALL_STATE_RINGING -> {
Log.d(TAG, "来电未接") Log.d(TAG, "来电未接")
sendReceiveCallMsg(context, 3, MMKVUtils.getString("CALL_SAVED_NUMBER", null)) sendReceiveCallMsg(
context,
3,
MMKVUtils.getString("CALL_SAVED_NUMBER", null)
)
} }
MMKVUtils.getBoolean("CALL_IS_INCOMING", false) -> { MMKVUtils.getBoolean("CALL_IS_INCOMING", false) -> {
Log.d(TAG, "来电挂机") Log.d(TAG, "来电挂机")
sendReceiveCallMsg(context, 1, MMKVUtils.getString("CALL_SAVED_NUMBER", null)) sendReceiveCallMsg(
context,
1,
MMKVUtils.getString("CALL_SAVED_NUMBER", null)
)
} }
else -> { else -> {
Log.d(TAG, "去电挂机") Log.d(TAG, "去电挂机")
sendReceiveCallMsg(context, 2, MMKVUtils.getString("CALL_SAVED_NUMBER", null)) sendReceiveCallMsg(
context,
2,
MMKVUtils.getString("CALL_SAVED_NUMBER", null)
)
} }
} }
} }
@ -161,10 +177,18 @@ class PhoneStateReceiver : BroadcastReceiver() {
//获取联系人姓名 //获取联系人姓名
if (TextUtils.isEmpty(callInfo.name)) { if (TextUtils.isEmpty(callInfo.name)) {
val contacts = PhoneUtils.getContactByNumber(phoneNumber) val contacts = PhoneUtils.getContactByNumber(phoneNumber)
callInfo.name = if (contacts.isNotEmpty()) contacts[0].name else getString(R.string.unknown_number) callInfo.name =
if (contacts.isNotEmpty()) contacts[0].name else getString(R.string.unknown_number)
} }
val msgInfo = MsgInfo("call", callInfo.number, PhoneUtils.getCallMsg(callInfo), Date(), simInfo, simSlot) val msgInfo = MsgInfo(
"call",
callInfo.number,
PhoneUtils.getCallMsg(callInfo),
Date(),
simInfo,
simSlot
)
val request = OneTimeWorkRequestBuilder<SendWorker>() val request = OneTimeWorkRequestBuilder<SendWorker>()
.setInputData( .setInputData(
workDataOf( workDataOf(

View File

@ -230,7 +230,10 @@ class PhoneUtils private constructor() {
Log.i(TAG, "cursor count:" + cursor.count) Log.i(TAG, "cursor count:" + cursor.count)
// 避免超过总数后循环取出 // 避免超过总数后循环取出
if (cursor.count == 0 || offset >= cursor.count) return callInfoList if (cursor.count == 0 || offset >= cursor.count) {
cursor.close()
return callInfoList
}
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
Log.d(TAG, "Call ColumnNames=${cursor.columnNames.contentToString()}") Log.d(TAG, "Call ColumnNames=${cursor.columnNames.contentToString()}")
@ -328,7 +331,10 @@ class PhoneUtils private constructor() {
Log.i(TAG, "cursor count:" + cursor.count) Log.i(TAG, "cursor count:" + cursor.count)
// 避免超过总数后循环取出 // 避免超过总数后循环取出
if (cursor.count == 0 || offset >= cursor.count) return contactInfoList if (cursor.count == 0 || offset >= cursor.count) {
cursor.close()
return contactInfoList
}
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
val displayNameIndex = val displayNameIndex =
@ -424,7 +430,10 @@ class PhoneUtils private constructor() {
selectionArgs.toTypedArray(), selectionArgs.toTypedArray(),
"date desc" "date desc"
) ?: return smsInfoList ) ?: return smsInfoList
if (offset >= cursorTotal.count) return smsInfoList if (offset >= cursorTotal.count) {
cursorTotal.close()
return smsInfoList
}
val cursor = Core.app.contentResolver.query( val cursor = Core.app.contentResolver.query(
Uri.parse("content://sms/"), Uri.parse("content://sms/"),
@ -435,7 +444,10 @@ class PhoneUtils private constructor() {
) ?: return smsInfoList ) ?: return smsInfoList
Log.i(TAG, "cursor count:" + cursor.count) Log.i(TAG, "cursor count:" + cursor.count)
if (cursor.count == 0) return smsInfoList if (cursor.count == 0) {
cursor.close()
return smsInfoList
}
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
Log.d(TAG, "SMS ColumnNames=${cursor.columnNames.contentToString()}") Log.d(TAG, "SMS ColumnNames=${cursor.columnNames.contentToString()}")
@ -474,6 +486,8 @@ class PhoneUtils private constructor() {
) else -1 ) else -1
smsInfoList.add(smsInfo) smsInfoList.add(smsInfo)
} while (cursor.moveToNext()) } while (cursor.moveToNext())
if (!cursorTotal.isClosed) cursorTotal.close()
if (!cursor.isClosed) cursor.close() if (!cursor.isClosed) cursor.close()
} }
} catch (e: java.lang.Exception) { } catch (e: java.lang.Exception) {

View File

@ -34,7 +34,7 @@ object MailUtil {
properties["mail.smtp.auth"] = "true" properties["mail.smtp.auth"] = "true"
properties["mail.smtp.ssl.enable"] = mail.openSSL properties["mail.smtp.ssl.enable"] = mail.openSSL
if (mail.startTls) { if (mail.startTls) {
properties["mail.smtp.starttls.enable"] = mail.startTls properties["mail.smtp.starttls.enable"] = true
} }
if (mail.openSSL) { if (mail.openSSL) {
properties["mail.smtp.socketFactory.class"] = mail.sslFactory properties["mail.smtp.socketFactory.class"] = mail.sslFactory
@ -94,7 +94,10 @@ object MailUtil {
// 邮件正文 // 邮件正文
val textBodyPart = MimeBodyPart() val textBodyPart = MimeBodyPart()
if (mail.content is Spanned) { if (mail.content is Spanned) {
textBodyPart.setContent(Html.toHtml(mail.content as Spanned), "text/html;charset=UTF-8") textBodyPart.setContent(
Html.toHtml(mail.content as Spanned),
"text/html;charset=UTF-8"
)
} else { } else {
textBodyPart.setContent(mail.content, "text/html;charset=UTF-8") textBodyPart.setContent(mail.content, "text/html;charset=UTF-8")
} }

View File

@ -78,7 +78,7 @@ class UMengInit private constructor() {
* @param context * @param context
* @return * @return
*/ */
private fun getChannel(context: Context?): String? { private fun getChannel(context: Context?): String {
//return WalleChannelReader.getChannel(context!!, DEFAULT_CHANNEL_ID) //return WalleChannelReader.getChannel(context!!, DEFAULT_CHANNEL_ID)
return DEFAULT_CHANNEL_ID return DEFAULT_CHANNEL_ID
} }

View File

@ -65,7 +65,7 @@ class GuideTipsDialog(context: Context?, tips: List<TipInfo>) :
*/ */
private fun updateTips(tips: List<TipInfo>) { private fun updateTips(tips: List<TipInfo>) {
mTips = tips mTips = tips
if (mTips != null && mTips!!.isNotEmpty() && mTvContent != null) { if (mTips!!.isNotEmpty() && mTvContent != null) {
mIndex = 0 mIndex = 0
showRichText(mTips!![mIndex]) showRichText(mTips!![mIndex])
} }

View File

@ -1,5 +1,6 @@
package com.idormy.sms.forwarder.workers package com.idormy.sms.forwarder.workers
import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.util.Log import android.util.Log
import androidx.work.CoroutineWorker import androidx.work.CoroutineWorker
@ -23,6 +24,7 @@ class SendWorker(
workerParams: WorkerParameters, workerParams: WorkerParameters,
) : CoroutineWorker(context, workerParams) { ) : CoroutineWorker(context, workerParams) {
@SuppressLint("SimpleDateFormat")
override suspend fun doWork(): Result { override suspend fun doWork(): Result {
return withContext(Dispatchers.IO) { return withContext(Dispatchers.IO) {
@ -41,8 +43,10 @@ class SendWorker(
val dateFmt = SimpleDateFormat("yyyy-MM-dd") val dateFmt = SimpleDateFormat("yyyy-MM-dd")
val mTimeOption = DataProvider.timePeriodOption val mTimeOption = DataProvider.timePeriodOption
val periodStartStr = dateFmt.format(periodStartDay) + " " + mTimeOption[SettingUtils.silentPeriodStart] + ":00" val periodStartStr =
val periodEndStr = dateFmt.format(periodStartEnd) + " " + mTimeOption[SettingUtils.silentPeriodEnd] + ":00" dateFmt.format(periodStartDay) + " " + mTimeOption[SettingUtils.silentPeriodStart] + ":00"
val periodEndStr =
dateFmt.format(periodStartEnd) + " " + mTimeOption[SettingUtils.silentPeriodEnd] + ":00"
val timeFmt = SimpleDateFormat("yyyy-MM-dd HH:mm:ss") val timeFmt = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
val periodStart = timeFmt.parse(periodStartStr, ParsePosition(0)).time val periodStart = timeFmt.parse(periodStartStr, ParsePosition(0)).time
@ -75,14 +79,22 @@ class SendWorker(
//【注意】卡槽id-1=获取失败、0=卡槽1、1=卡槽2但是 Rule 表里存的是 SIM1/SIM2 //【注意】卡槽id-1=获取失败、0=卡槽1、1=卡槽2但是 Rule 表里存的是 SIM1/SIM2
val simSlot = "SIM" + (msgInfo.simSlot + 1) val simSlot = "SIM" + (msgInfo.simSlot + 1)
val ruleList: List<RuleAndSender> = Core.rule.getRuleAndSender(msgInfo.type, 1, simSlot) val ruleList: List<RuleAndSender> =
Core.rule.getRuleAndSender(msgInfo.type, 1, simSlot)
if (ruleList.isEmpty()) { if (ruleList.isEmpty()) {
return@withContext Result.failure(workDataOf("send" to "failed")) return@withContext Result.failure(workDataOf("send" to "failed"))
} }
for (rule in ruleList) { for (rule in ruleList) {
if (!rule.rule.checkMsg(msgInfo)) continue if (!rule.rule.checkMsg(msgInfo)) continue
val log = Logs(0, msgInfo.type, msgInfo.from, msgInfo.content, rule.rule.id, msgInfo.simInfo) val log = Logs(
0,
msgInfo.type,
msgInfo.from,
msgInfo.content,
rule.rule.id,
msgInfo.simInfo
)
val logId = Core.logs.insert(log) val logId = Core.logs.insert(log)
SendUtils.sendMsgSender(msgInfo, rule.rule, rule.sender, logId) SendUtils.sendMsgSender(msgInfo, rule.rule, rule.sender, logId)
} }

View File

@ -1,17 +0,0 @@
<!--有公司logo-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="@color/xui_config_color_white" />
<item android:bottom="@dimen/xui_config_app_logo_bottom">
<bitmap
android:gravity="center"
android:src="@drawable/ic_splash_app_logo" />
</item>
<item android:bottom="@dimen/xui_config_company_logo_bottom">
<bitmap
android:gravity="bottom"
android:src="@drawable/ic_splash_company_logo" />
</item>
</layer-list>

View File

@ -65,7 +65,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="bottom" android:gravity="bottom"
android:orientation="horizontal"> android:orientation="horizontal"
tools:ignore="UseCompoundDrawables">
<TextView <TextView
android:id="@+id/tv_content" android:id="@+id/tv_content"

View File

@ -11,7 +11,8 @@
android:layout_width="280dp" android:layout_width="280dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="72dp" android:layout_marginBottom="72dp"
android:orientation="vertical"> android:orientation="vertical"
tools:ignore="UselessParent">
<com.xuexiang.xui.widget.alpha.XUIAlphaImageView <com.xuexiang.xui.widget.alpha.XUIAlphaImageView
android:id="@+id/iv_close" android:id="@+id/iv_close"

View File

@ -1,10 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/xui_config_color_background" android:background="?attr/xui_config_color_background"
android:orientation="vertical"> android:orientation="vertical"
tools:ignore="Overdraw">
<androidx.core.widget.NestedScrollView style="@style/ScrollViewStyle"> <androidx.core.widget.NestedScrollView style="@style/ScrollViewStyle">

View File

@ -4,7 +4,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/xui_config_color_background" android:background="?attr/xui_config_color_background"
android:orientation="vertical"> android:orientation="vertical"
tools:ignore="Overdraw">
<androidx.core.widget.NestedScrollView style="@style/ScrollViewStyle"> <androidx.core.widget.NestedScrollView style="@style/ScrollViewStyle">

View File

@ -1,10 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/xui_config_color_background" android:background="?attr/xui_config_color_background"
android:orientation="vertical"> android:orientation="vertical"
tools:ignore="Overdraw">
<androidx.core.widget.NestedScrollView style="@style/ScrollViewStyle"> <androidx.core.widget.NestedScrollView style="@style/ScrollViewStyle">

View File

@ -166,7 +166,7 @@
android:inputType="number" android:inputType="number"
android:maxLength="1" android:maxLength="1"
android:singleLine="true" android:singleLine="true"
android:text="1" android:text="@string/_1"
app:met_clearButton="true" /> app:met_clearButton="true" />
</LinearLayout> </LinearLayout>

View File

@ -123,7 +123,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:singleLine="true" android:singleLine="true"
android:text="@string/missed_call" android:text="@string/missed_call"
android:textSize="10sp" /> android:textSize="10sp"
tools:ignore="SmallSp" />
<com.xuexiang.xui.widget.button.SmoothCheckBox <com.xuexiang.xui.widget.button.SmoothCheckBox
android:id="@+id/scb_call_type1" android:id="@+id/scb_call_type1"
@ -137,7 +138,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:singleLine="true" android:singleLine="true"
android:text="@string/received_call" android:text="@string/received_call"
android:textSize="10sp" /> android:textSize="10sp"
tools:ignore="SmallSp" />
<com.xuexiang.xui.widget.button.SmoothCheckBox <com.xuexiang.xui.widget.button.SmoothCheckBox
android:id="@+id/scb_call_type2" android:id="@+id/scb_call_type2"
@ -151,7 +153,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:singleLine="true" android:singleLine="true"
android:text="@string/local_outgoing_call" android:text="@string/local_outgoing_call"
android:textSize="10sp" /> android:textSize="10sp"
tools:ignore="SmallSp" />
<com.xuexiang.xui.widget.button.SmoothCheckBox <com.xuexiang.xui.widget.button.SmoothCheckBox
android:id="@+id/scb_call_type4" android:id="@+id/scb_call_type4"
@ -165,7 +168,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:singleLine="true" android:singleLine="true"
android:text="@string/incoming_call" android:text="@string/incoming_call"
android:textSize="10sp" /> android:textSize="10sp"
tools:ignore="SmallSp" />
</LinearLayout> </LinearLayout>
@ -230,7 +234,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/cancel_app_notify" android:text="@string/cancel_app_notify"
android:textSize="10sp" /> android:textSize="10sp"
tools:ignore="SmallSp" />
<com.xuexiang.xui.widget.button.SmoothCheckBox <com.xuexiang.xui.widget.button.SmoothCheckBox
android:id="@+id/scb_not_user_present" android:id="@+id/scb_not_user_present"
@ -243,7 +248,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/not_user_present" android:text="@string/not_user_present"
android:textSize="10sp" /> android:textSize="10sp"
tools:ignore="SmallSp" />
</LinearLayout> </LinearLayout>
@ -307,7 +313,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:checked="true" android:checked="true"
android:text="@string/user_app" android:text="@string/user_app"
android:textSize="10sp" /> android:textSize="10sp"
tools:ignore="SmallSp" />
<com.xuexiang.xui.widget.button.SmoothCheckBox <com.xuexiang.xui.widget.button.SmoothCheckBox
android:id="@+id/scb_load_system_app" android:id="@+id/scb_load_system_app"
@ -320,7 +327,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/system_app" android:text="@string/system_app"
android:textSize="10sp" /> android:textSize="10sp"
tools:ignore="SmallSp" />
</LinearLayout> </LinearLayout>
@ -589,7 +597,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/keep_reminding" android:text="@string/keep_reminding"
android:textSize="10sp" /> android:textSize="10sp"
tools:ignore="SmallSp" />
</LinearLayout> </LinearLayout>
@ -861,7 +870,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/play_silence_music" android:text="@string/play_silence_music"
android:textSize="10sp" /> android:textSize="10sp"
tools:ignore="SmallSp" />
<LinearLayout <LinearLayout
android:id="@+id/layout_one_pixel_activity" android:id="@+id/layout_one_pixel_activity"
@ -880,7 +890,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/one_pixel_activity" android:text="@string/one_pixel_activity"
android:textSize="10sp" /> android:textSize="10sp"
tools:ignore="SmallSp" />
</LinearLayout> </LinearLayout>

View File

@ -17,8 +17,12 @@
<style name="AppTheme.Launch"> <style name="AppTheme.Launch">
<item name="xui_config_color_splash_bg">@color/xui_config_color_white</item> <item name="xui_config_color_splash_bg">@color/xui_config_color_white</item>
<item name="xui_config_app_logo_bottom" tools:ignore="PrivateResource">@dimen/xui_config_app_logo_bottom</item> <item name="xui_config_app_logo_bottom" tools:ignore="PrivateResource">
<item name="xui_config_company_logo_bottom" tools:ignore="PrivateResource">@dimen/xui_config_company_logo_bottom</item> @dimen/xui_config_app_logo_bottom
</item>
<item name="xui_config_company_logo_bottom" tools:ignore="PrivateResource">
@dimen/xui_config_company_logo_bottom
</item>
<item name="android:windowBackground">@drawable/xui_config_bg_splash</item> <item name="android:windowBackground">@drawable/xui_config_bg_splash</item>
<item name="android:windowFullscreen">true</item> <item name="android:windowFullscreen">true</item>
</style> </style>
@ -43,7 +47,7 @@
<!--无标题--> <!--无标题-->
<item name="android:windowNoTitle">true</item>      <item name="android:windowNoTitle">true</item>     
<!--是否浮现在activity之上--> <!--是否浮现在activity之上-->
<item name="android:windowIsFloating">true</item> <item name="android:windowIsFloating" tools:ignore="TranslucentOrientation">true</item>
<!--是否半透明--> <!--是否半透明-->
<item name="android:windowIsTranslucent">true</item> <item name="android:windowIsTranslucent">true</item>
<!--是否有覆盖--> <!--是否有覆盖-->