1
0
mirror of https://github.com/fumiama/simple-dict-android.git synced 2026-06-12 06:00:34 +08:00
1. 增加 删除保护
2. 优化 修改体验
This commit is contained in:
fumiama
2021-02-20 14:53:46 +08:00
parent e2ba37c14f
commit 1367c96d0d
4 changed files with 25 additions and 10 deletions

View File

@@ -13,8 +13,8 @@ android {
applicationId "top.fumiama.simpledict" applicationId "top.fumiama.simpledict"
minSdkVersion 26 minSdkVersion 26
targetSdkVersion 30 targetSdkVersion 30
versionCode 7 versionCode 8
versionName '1.5' versionName '1.6'
resConfigs "zh", "zh-rCN" resConfigs "zh", "zh-rCN"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View File

@@ -7,6 +7,9 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.speech.RecognizerIntent import android.speech.RecognizerIntent
import android.text.SpannableString
import android.text.Spanned
import android.text.style.StrikethroughSpan
import android.util.Log import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
@@ -15,6 +18,7 @@ import android.widget.EditText
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.children
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.lapism.search.internal.SearchLayout import com.lapism.search.internal.SearchLayout
@@ -49,8 +53,9 @@ class MainActivity : AppCompatActivity() {
} }
ffms.apply { ffms.apply {
val recyclerView = findViewById<RecyclerView>(R.id.search_recycler_view)
setAdapterLayoutManager(LinearLayoutManager(this@MainActivity)) setAdapterLayoutManager(LinearLayoutManager(this@MainActivity))
val adapter = SearchViewHolder(findViewById(R.id.search_recycler_view), findViewById(R.id.search_search_edit_text)).RecyclerViewAdapter() val adapter = SearchViewHolder(recyclerView, findViewById(R.id.search_search_edit_text)).RecyclerViewAdapter()
setAdapter(adapter) setAdapter(adapter)
navigationIconSupport = SearchLayout.NavigationIconSupport.SEARCH navigationIconSupport = SearchLayout.NavigationIconSupport.SEARCH
setOnNavigationClickListener(object : SearchLayout.OnNavigationClickListener { setOnNavigationClickListener(object : SearchLayout.OnNavigationClickListener {
@@ -73,7 +78,10 @@ class MainActivity : AppCompatActivity() {
if(query.isNotEmpty()) { if(query.isNotEmpty()) {
val key = query.toString() val key = query.toString()
val data = dict[key] val data = dict[key]
showDictAlert(key, data) { adapter.refresh() } showDictAlert(key, data, recyclerView.children.toList().let {
val i = it.map { it.ta.text }.indexOf(key)
if(i >= 0) it[i] else null
}) { adapter.refresh() }
} }
return true return true
} }
@@ -126,7 +134,7 @@ class MainActivity : AppCompatActivity() {
}.start() }.start()
} }
private fun showDictAlert(key: String, data: String?, notify: ()->Unit) { private fun showDictAlert(key: String, data: String?, line: View?, refresh: (()->Unit)?=null) {
val hintAdd = if(data != null && data != "null") "重设" else "添加" val hintAdd = if(data != null && data != "null") "重设" else "添加"
hasLiked = false hasLiked = false
AlertDialog.Builder(this@MainActivity) AlertDialog.Builder(this@MainActivity)
@@ -142,7 +150,7 @@ class MainActivity : AppCompatActivity() {
val newText = t.text.toString() val newText = t.text.toString()
if (t.text.isNotEmpty() && newText != data) Thread { if (t.text.isNotEmpty() && newText != data) Thread {
dict[key] = newText dict[key] = newText
notify() line?.tb?.text = newText
}.start() }.start()
else Toast.makeText(this, "未更改", Toast.LENGTH_SHORT).show() else Toast.makeText(this, "未更改", Toast.LENGTH_SHORT).show()
} }
@@ -152,7 +160,14 @@ class MainActivity : AppCompatActivity() {
.setNeutralButton("删除") { _, _ -> .setNeutralButton("删除") { _, _ ->
Thread{ Thread{
dict -= key dict -= key
notify() line?.apply {
val delKey = SpannableString(key)
val delData = SpannableString(data)
delKey.setSpan(StrikethroughSpan(), 0, key.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
delData.setSpan(StrikethroughSpan(), 0, (data?.length?:0), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
ta.text = delKey
tb.text = delData
}
}.start() }.start()
} }
.setNegativeButton(android.R.string.cancel) { _, _ -> } .setNegativeButton(android.R.string.cancel) { _, _ -> }
@@ -218,7 +233,7 @@ class MainActivity : AppCompatActivity() {
vl.setBackgroundResource(if(like) R.drawable.ic_like_filled else R.drawable.ic_like) vl.setBackgroundResource(if(like) R.drawable.ic_like_filled else R.drawable.ic_like)
Log.d("MyMain", "Set like of $key: $like") Log.d("MyMain", "Set like of $key: $like")
setOnClickListener { setOnClickListener {
showDictAlert(key, data) {refresh()} showDictAlert(key, data, this)
} }
setOnLongClickListener { setOnLongClickListener {
cm?.setPrimaryClip(ClipData.newPlainText("SimpleDict", "$key\n$data")) cm?.setPrimaryClip(ClipData.newPlainText("SimpleDict", "$key\n$data"))

Binary file not shown.

View File

@@ -10,8 +10,8 @@
{ {
"type": "SINGLE", "type": "SINGLE",
"filters": [], "filters": [],
"versionCode": 7, "versionCode": 8,
"versionName": "1.5", "versionName": "1.6",
"outputFile": "app-winrelease.apk" "outputFile": "app-winrelease.apk"
} }
] ]