Skip to content

Commit

Permalink
Fix: wrongly invoke setOnCheckedChangeListener twice
Browse files Browse the repository at this point in the history
Fix: rules do not take effect
  • Loading branch information
lz233 committed Oct 15, 2023
1 parent d792835 commit 304fd66
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 32 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
minSdk 27
targetSdk 34
versionCode = date.format("yyyyMMdd").toInteger()
versionName "1.5.4"
versionName "1.5.5"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.os.Build
import android.os.Bundle
import cn.ac.lz233.tarnhelm.App
import cn.ac.lz233.tarnhelm.ui.BaseActivity
import cn.ac.lz233.tarnhelm.util.LogUtil
import cn.ac.lz233.tarnhelm.util.ktx.doTarnhelms
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
Expand All @@ -21,8 +20,6 @@ class ProcessShareActivity : BaseActivity() {
if (Build.VERSION.SDK_INT >= 33) {
launch {
delay(50)
LogUtil._d(App.clipboardManager.primaryClip?.getItemAt(0)?.text)
LogUtil._d(intent.getStringExtra(Intent.EXTRA_TEXT))
if (App.clipboardManager.primaryClip?.getItemAt(0)?.text == intent.getStringExtra(Intent.EXTRA_TEXT))
copyToClipboard()
else
Expand All @@ -43,7 +40,7 @@ class ProcessShareActivity : BaseActivity() {
putExtra(Intent.EXTRA_SUBJECT, (intent.getStringExtra(Intent.EXTRA_SUBJECT)?.doTarnhelms()))
putExtra(Intent.EXTRA_TEXT, (intent.getStringExtra(Intent.EXTRA_TEXT)?.doTarnhelms()))
//putExtra(Intent.EXTRA_TITLE, (intent.getStringExtra(Intent.EXTRA_TITLE)?.doTarnhelms() ?: ""))
type = "text/plain"
type = intent.type
}, null).apply {
putExtra(Intent.EXTRA_EXCLUDE_COMPONENTS, arrayOf(ComponentName(App.context, ProcessShareActivity::class.java)))
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ import cn.ac.lz233.tarnhelm.logic.dao.SettingsDao
import cn.ac.lz233.tarnhelm.logic.module.meta.ParameterRule
import cn.ac.lz233.tarnhelm.ui.rules.IDragSwipe
import cn.ac.lz233.tarnhelm.util.LogUtil
import cn.ac.lz233.tarnhelm.util.ktx.*
import cn.ac.lz233.tarnhelm.util.ktx.encodeBase64
import cn.ac.lz233.tarnhelm.util.ktx.encodeURL
import cn.ac.lz233.tarnhelm.util.ktx.getModeButtonId
import cn.ac.lz233.tarnhelm.util.ktx.getModeId
import cn.ac.lz233.tarnhelm.util.ktx.getString
import cn.ac.lz233.tarnhelm.util.ktx.toJSONArray
import cn.ac.lz233.tarnhelm.util.ktx.toJSONObject
import cn.ac.lz233.tarnhelm.util.ktx.toMultiString
import com.google.android.material.card.MaterialCardView
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.materialswitch.MaterialSwitch
Expand Down Expand Up @@ -89,18 +96,20 @@ class ParameterRulesAdapter(private val rulesList: MutableList<ParameterRule>) :
}
holder.ruleEnableSwitch.isChecked = rule.enabled
holder.ruleEnableSwitch.setOnCheckedChangeListener { compoundButton, b ->
val item = ParameterRule(
rule.id,
rule.description,
rule.domain,
rule.mode,
rule.parametersArray,
rule.author,
rule.sourceType,
b
)
App.parameterRuleDao.insert(item)
rulesList[position] = item
if (compoundButton.isShown) {
val item = ParameterRule(
rule.id,
rule.description,
rule.domain,
rule.mode,
rule.parametersArray,
rule.author,
rule.sourceType,
b
)
App.parameterRuleDao.insert(item)
rulesList[position] = item
}
}
holder.descriptionContentTextView.text = rule.description
holder.domainContentTextView.text = rule.domain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import cn.ac.lz233.tarnhelm.logic.dao.SettingsDao
import cn.ac.lz233.tarnhelm.logic.module.meta.RegexRule
import cn.ac.lz233.tarnhelm.ui.rules.IDragSwipe
import cn.ac.lz233.tarnhelm.util.LogUtil
import cn.ac.lz233.tarnhelm.util.ktx.*
import cn.ac.lz233.tarnhelm.util.ktx.encodeBase64
import cn.ac.lz233.tarnhelm.util.ktx.encodeURL
import cn.ac.lz233.tarnhelm.util.ktx.toJSONArray
import cn.ac.lz233.tarnhelm.util.ktx.toJSONObject
import cn.ac.lz233.tarnhelm.util.ktx.toMultiString
import com.google.android.material.card.MaterialCardView
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.materialswitch.MaterialSwitch
Expand Down Expand Up @@ -86,17 +90,19 @@ class RegexRulesAdapter(private val rulesList: MutableList<RegexRule>) : Recycle
}
holder.ruleEnableSwitch.isChecked = rule.enabled
holder.ruleEnableSwitch.setOnCheckedChangeListener { compoundButton, b ->
val item = RegexRule(
rule.id,
rule.description,
rule.regexArray,
rule.replaceArray,
rule.author,
rule.sourceType,
b
)
App.regexRuleDao.insert(item)
rulesList[position] = item
if (compoundButton.isShown) {
val item = RegexRule(
rule.id,
rule.description,
rule.regexArray,
rule.replaceArray,
rule.author,
rule.sourceType,
b
)
App.regexRuleDao.insert(item)
rulesList[position] = item
}
}
holder.descriptionContentTextView.text = rule.description
holder.regexesContentTextView.text = JSONArray(rule.regexArray).toMultiString()
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/cn/ac/lz233/tarnhelm/util/ktx/String.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ fun String.toJSONArray() = JSONArray().apply {
}

fun String.doTarnhelm(): CharSequence {
LogUtil._d("Original Url: $this")
LogUtil._d("Original URL: $this")
var result = this
val parameterRules = App.parameterRuleDao.getAll()
var httpUrl = result.toHttpUrlOrNull()
LogUtil._d("HTTP URL: $httpUrl")
if (httpUrl != null) {
for (rule in parameterRules) {
if ((rule.enabled) and (rule.domain == httpUrl!!.host)) {
Expand All @@ -64,7 +65,7 @@ fun String.doTarnhelm(): CharSequence {
}
}
}
//result = httpUrl.toString().decodeURL()
result = httpUrl.toString()//.decodeURL()
LogUtil._d("After Parameters: $result")
}
val regexRules = App.regexRuleDao.getAll()
Expand Down

0 comments on commit 304fd66

Please sign in to comment.