mirror of
https://github.com/fumiama/simple-dict-android.git
synced 2026-06-07 19:40:29 +08:00
v3.1.1
1. 自动去重,去错 2. 优化删除步骤 3. 翻页位置指示 4. 向前翻页
This commit is contained in:
@@ -15,10 +15,10 @@
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.SimpleDict.NoActionBar">
|
||||
android:theme="@style/Theme.SimpleDict.NoActionBar"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
@@ -262,7 +262,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
.setNeutralButton("删除") { _, _ ->
|
||||
Thread{
|
||||
if(dict?.send_del(key) == true) line?.apply {
|
||||
if(dict?.del(key) == true) line?.apply {
|
||||
val delKey = SpannableString(key)
|
||||
val delData = SpannableString(data)
|
||||
delKey.setSpan(StrikethroughSpan(), 0, key.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
@@ -270,6 +270,8 @@ class MainActivity : AppCompatActivity() {
|
||||
ta.text = delKey
|
||||
tn.text = delKey
|
||||
tb.text = delData
|
||||
start--
|
||||
end--
|
||||
updateSize()
|
||||
}
|
||||
else runOnUiThread {
|
||||
|
||||
@@ -80,13 +80,13 @@ class SimpleDict(private val client: Client, private val pwd: String, private va
|
||||
dict[k] = data.decodeToString()
|
||||
latestKeys += k
|
||||
} else {
|
||||
send_del(key) // 去错
|
||||
sendel(key) // 去错
|
||||
}
|
||||
} else if(!dict.containsKey(k)){
|
||||
dict[k] = data.decodeToString()
|
||||
latestKeys += k
|
||||
} else {
|
||||
send_del(key) // 去重
|
||||
sendel(key) // 去重
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,10 +96,10 @@ class SimpleDict(private val client: Client, private val pwd: String, private va
|
||||
fun filterValues(predicate: (String?) -> Boolean) = dict.filterValues(predicate)
|
||||
|
||||
fun fetchDict(doOnLoadFailure: ()->Unit, doOnLoadSuccess: ()->Unit, doCommon: (() -> Unit)? = null) {
|
||||
dict = hashMapOf()
|
||||
latestKeys = arrayOf()
|
||||
val noChange = md5File.exists() && dspFile.exists() && !hasNewItem(md5File.readBytes())
|
||||
val data = if(noChange) dspFile.readBytes() else raw
|
||||
dict.clear()
|
||||
latestKeys = arrayOf()
|
||||
if(data == null) doOnLoadFailure()
|
||||
else {
|
||||
analyzeDict(data, !noChange)
|
||||
@@ -108,7 +108,7 @@ class SimpleDict(private val client: Client, private val pwd: String, private va
|
||||
doCommon?.let { it() }
|
||||
}
|
||||
|
||||
fun send_del(key: String): Boolean {
|
||||
fun del(key: String): Boolean {
|
||||
if(spwd == null) return false
|
||||
else if(initDict()) {
|
||||
val delPass = "del$spwd"
|
||||
@@ -133,7 +133,7 @@ class SimpleDict(private val client: Client, private val pwd: String, private va
|
||||
return false
|
||||
}
|
||||
|
||||
private fun send_del(key: ByteArray): Boolean {
|
||||
private fun sendel(key: ByteArray): Boolean {
|
||||
if(spwd == null) return false
|
||||
else if(initDict()) {
|
||||
val delPass = "del$spwd"
|
||||
@@ -152,7 +152,7 @@ class SimpleDict(private val client: Client, private val pwd: String, private va
|
||||
fun set(key: String, value: String): Boolean {
|
||||
//if(spwd == null) return false
|
||||
val contain = dict.containsKey(key)
|
||||
if((contain && send_del(key)) || !contain) {
|
||||
if((contain && sendel(key.toByteArray())) || !contain) {
|
||||
if(initDict()) {
|
||||
val setPass = "set$spwd"
|
||||
client.sendMessage(setPass)
|
||||
|
||||
Reference in New Issue
Block a user