mirror of
https://github.com/fumiama/simple-dict-android.git
synced 2026-06-06 17:20:26 +08:00
v3.1
1. 自动去重,去错 2. 优化删除步骤 3. 翻页位置指示 4. 向前翻页
This commit is contained in:
2
.idea/compiler.xml
generated
2
.idea/compiler.xml
generated
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="11" />
|
||||
<bytecodeTargetLevel target="1.8" />
|
||||
</component>
|
||||
</project>
|
||||
3
.idea/gradle.xml
generated
3
.idea/gradle.xml
generated
@@ -4,7 +4,7 @@
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="testRunner" value="PLATFORM" />
|
||||
<option name="testRunner" value="GRADLE" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="1.8" />
|
||||
@@ -15,7 +15,6 @@
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
<option name="useQualifiedModuleNames" value="true" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
|
||||
10
.idea/misc.xml
generated
10
.idea/misc.xml
generated
@@ -1,6 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="DesignSurface">
|
||||
<option name="filePathToZoomLevelMap">
|
||||
<map>
|
||||
<entry key="app/src/main/res/layout/activity_main.xml" value="0.5286458333333334" />
|
||||
<entry key="app/src/main/res/layout/line_word.xml" value="0.5427083333333333" />
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
||||
10
.idea/runConfigurations.xml
generated
10
.idea/runConfigurations.xml
generated
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
@@ -43,8 +43,8 @@ android {
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
implementation 'androidx.core:core-ktx:1.3.2'
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||
implementation 'androidx.core:core-ktx:1.5.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.3.0'
|
||||
implementation 'com.google.android.material:material:1.3.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
|
||||
|
||||
@@ -30,7 +30,6 @@ import kotlinx.android.synthetic.main.dialog_input.view.*
|
||||
import kotlinx.android.synthetic.main.line_word.view.*
|
||||
import kotlinx.android.synthetic.main.line_word.view.tb
|
||||
import kotlinx.android.synthetic.main.line_word.view.tn
|
||||
import java.io.File
|
||||
import java.io.FileNotFoundException
|
||||
import java.lang.Exception
|
||||
|
||||
@@ -44,6 +43,8 @@ class MainActivity : AppCompatActivity() {
|
||||
private var cm: ClipboardManager? = null
|
||||
private var ad: LikeViewHolder.RecyclerViewAdapter? = null
|
||||
private var lastLikeLine: View? = null
|
||||
private var end = 0
|
||||
private var start = 0
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -113,7 +114,7 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
override fun onQueryTextSubmit(query: CharSequence): Boolean {
|
||||
if(query.isNotEmpty()) {
|
||||
val key = query.toString().trim().replace(Regex("[\\uFF00-\\uFF5E]")) { (it.value[0] - 0xFEE0).toString() }
|
||||
val key = query.toString()
|
||||
val data = dict?.get(key)
|
||||
showDictAlert(key, data, recyclerView.children.toList().let {
|
||||
val i = it.map { it.ta.text }.indexOf(key)
|
||||
@@ -204,7 +205,8 @@ class MainActivity : AppCompatActivity() {
|
||||
}*/
|
||||
|
||||
private fun updateSize() = runOnUiThread {
|
||||
lastLikeLine?.fftc?.text = dict?.size?.toString()?:"0"
|
||||
lastLikeLine?.fftt?.text = "${dict?.size?.toString()?:"0"} syez rjimj"
|
||||
lastLikeLine?.fftc?.text = "${start}-${end}"
|
||||
}
|
||||
|
||||
private fun fetchThread(doWhenFinish: (()->Unit)? = null) {
|
||||
@@ -221,6 +223,7 @@ class MainActivity : AppCompatActivity() {
|
||||
runOnUiThread {
|
||||
ffsw.isRefreshing = false
|
||||
ad?.capacity = 5
|
||||
ad?.offset = 0
|
||||
ad?.refresh()
|
||||
doWhenFinish?.apply { this() }
|
||||
}
|
||||
@@ -244,7 +247,8 @@ class MainActivity : AppCompatActivity() {
|
||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
val newText = t.diet.text.toString().trim().replace(Regex("[\\uFF00-\\uFF5E]")) { (it.value[0] - 0xFEE0).toString() }
|
||||
if (t.diet.text.isNotEmpty() && newText != data) Thread {
|
||||
if(dict?.set(key, newText) == true) {
|
||||
val k = key.trim().replace(Regex("[\\uFF00-\\uFF5E]")) { (it.value[0] - 0xFEE0).toString() }
|
||||
if(dict?.set(k, newText) == true) {
|
||||
line?.tb?.text = newText
|
||||
updateSize()
|
||||
} else runOnUiThread {
|
||||
@@ -258,7 +262,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
.setNeutralButton("删除") { _, _ ->
|
||||
Thread{
|
||||
if(dict?.del(key) == true) line?.apply {
|
||||
if(dict?.send_del(key) == true) line?.apply {
|
||||
val delKey = SpannableString(key)
|
||||
val delData = SpannableString(data)
|
||||
delKey.setSpan(StrikethroughSpan(), 0, key.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
@@ -297,14 +301,23 @@ class MainActivity : AppCompatActivity() {
|
||||
inner class LikeViewHolder(itemView: View) : ListViewHolder(itemView) {
|
||||
inner class RecyclerViewAdapter: ListViewHolder.RecyclerViewAdapter(true){
|
||||
var capacity = 5
|
||||
var offset = 0
|
||||
override fun loadMore() {
|
||||
capacity += 5
|
||||
refresh()
|
||||
if(offset+5<dict?.latestKeys?.size?:0) {
|
||||
offset += 5
|
||||
refresh()
|
||||
}
|
||||
}
|
||||
override fun loadLess() {
|
||||
if(offset>=5) {
|
||||
offset -= 5
|
||||
refresh()
|
||||
}
|
||||
}
|
||||
override fun getKeys(filterText: CharSequence?) = getSharedPreferences("dict", MODE_PRIVATE).all.keys.toTypedArray().let{
|
||||
dict?.let { d ->
|
||||
val end = d.latestKeys.size
|
||||
val start = if(end > capacity) end - capacity else 0
|
||||
end = d.latestKeys.size - offset
|
||||
start = if(end > capacity) end - capacity else 0
|
||||
(it + d.latestKeys.copyOfRange(start, end).reversedArray()).toList()
|
||||
}?: emptyList()
|
||||
}
|
||||
@@ -319,6 +332,7 @@ class MainActivity : AppCompatActivity() {
|
||||
open fun getKeys(filterText: CharSequence? = null): List<String>? = null
|
||||
open fun getValue(key: String): String? = null
|
||||
open fun loadMore() {}
|
||||
open fun loadLess() {}
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ListViewHolder {
|
||||
return ListViewHolder(
|
||||
LayoutInflater.from(parent.context)
|
||||
@@ -376,11 +390,15 @@ class MainActivity : AppCompatActivity() {
|
||||
ta.visibility = View.GONE
|
||||
lwclast.visibility = View.VISIBLE
|
||||
tn.text = "motkyep..."
|
||||
tb.text = "加载更多..."
|
||||
tb.text = "加载更多(长按返回上页)..."
|
||||
updateSize()
|
||||
setOnClickListener {
|
||||
loadMore()
|
||||
}
|
||||
setOnLongClickListener {
|
||||
loadLess()
|
||||
return@setOnLongClickListener true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,8 +75,19 @@ class SimpleDict(private val client: Client, private val pwd: String, private va
|
||||
SimpleProtobuf.getDictArray(datas).forEach { d ->
|
||||
d?.apply {
|
||||
val k = key.decodeToString()
|
||||
dict[k] = data.decodeToString()
|
||||
latestKeys += k
|
||||
if(saveDict) {
|
||||
if(k.toByteArray().contentEquals(key)) {
|
||||
dict[k] = data.decodeToString()
|
||||
latestKeys += k
|
||||
} else {
|
||||
send_del(key) // 去错
|
||||
}
|
||||
} else if(!dict.containsKey(k)){
|
||||
dict[k] = data.decodeToString()
|
||||
latestKeys += k
|
||||
} else {
|
||||
send_del(key) // 去重
|
||||
}
|
||||
}
|
||||
}
|
||||
if(saveDict) saveDict(datas)
|
||||
@@ -97,7 +108,7 @@ class SimpleDict(private val client: Client, private val pwd: String, private va
|
||||
doCommon?.let { it() }
|
||||
}
|
||||
|
||||
fun del(key: String): Boolean {
|
||||
fun send_del(key: String): Boolean {
|
||||
if(spwd == null) return false
|
||||
else if(initDict()) {
|
||||
val delPass = "del$spwd"
|
||||
@@ -122,12 +133,26 @@ class SimpleDict(private val client: Client, private val pwd: String, private va
|
||||
return false
|
||||
}
|
||||
|
||||
private fun send_del(key: ByteArray): Boolean {
|
||||
if(spwd == null) return false
|
||||
else if(initDict()) {
|
||||
val delPass = "del$spwd"
|
||||
client.sendMessage(delPass)
|
||||
client.receiveRawMessage(delPass.length)
|
||||
client.sendMessage(key)
|
||||
if(client.receiveMessage(4) == "succ") {
|
||||
return closeDict()
|
||||
} else closeDict()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
operator fun get(key: String) = dict[key]
|
||||
|
||||
fun set(key: String, value: String): Boolean {
|
||||
//if(spwd == null) return false
|
||||
val contain = dict.containsKey(key)
|
||||
if((contain && del(key)) || !contain) {
|
||||
if((contain && send_del(key)) || !contain) {
|
||||
if(initDict()) {
|
||||
val setPass = "set$spwd"
|
||||
client.sendMessage(setPass)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/ffc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
android:id="@+id/fftc"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:fontFamily="@font/nisi"
|
||||
android:text="0"
|
||||
android:textSize="18sp"
|
||||
@@ -33,6 +35,7 @@
|
||||
android:id="@+id/fftt"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:fontFamily="@font/nisi"
|
||||
android:text="hv#st"
|
||||
android:textSize="18sp"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.4.32'
|
||||
ext.kotlin_version = '1.5.20'
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
|
||||
Reference in New Issue
Block a user