mirror of
https://github.com/fumiama/simple-dict-android.git
synced 2026-06-05 00:30:24 +08:00
v1.9.2
1. 修正连接失败处理逻辑
This commit is contained in:
@@ -12,8 +12,8 @@ android {
|
||||
applicationId "top.fumiama.simpledict"
|
||||
minSdkVersion 26
|
||||
targetSdkVersion 30
|
||||
versionCode 12
|
||||
versionName '1.9.1'
|
||||
versionCode 13
|
||||
versionName '1.9.2'
|
||||
resConfigs "zh", "zh-rCN"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
@@ -47,8 +47,8 @@ dependencies {
|
||||
implementation 'androidx.appcompat:appcompat:1.2.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.3'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.3.3'
|
||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
|
||||
@@ -157,12 +157,6 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
})
|
||||
|
||||
setOnClearClickListener(object : SearchLayout.OnClearClickListener {
|
||||
override fun onClearClick() {
|
||||
Toast.makeText(this@MainActivity, "clear", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
})
|
||||
|
||||
setOnFocusChangeListener(object : SearchLayout.OnFocusChangeListener {
|
||||
override fun onFocusChange(hasFocus: Boolean) {
|
||||
navigationIconSupport = if (hasFocus) SearchLayout.NavigationIconSupport.ARROW
|
||||
@@ -206,9 +200,16 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
private fun fetchThread(doWhenFinish: (()->Unit)? = null) {
|
||||
Thread{
|
||||
dict?.fetchDict {
|
||||
dict?.fetchDict({
|
||||
runOnUiThread {
|
||||
Toast.makeText(this@MainActivity, "刷新失败", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}, {
|
||||
runOnUiThread {
|
||||
Toast.makeText(this@MainActivity, "刷新成功", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}) {
|
||||
runOnUiThread {
|
||||
ffsw.isRefreshing = false
|
||||
ad?.capacity = 5
|
||||
ad?.refresh()
|
||||
|
||||
@@ -8,7 +8,7 @@ class SimpleDict(private val client: Client, private val pwd: String) { //must
|
||||
val size get() = dict.size
|
||||
val keys get() = dict.keys
|
||||
var latestKeys = arrayOf<String>()
|
||||
private val raw: ByteArray
|
||||
private val raw: ByteArray?
|
||||
get() {
|
||||
var times = 3
|
||||
var re: ByteArray
|
||||
@@ -36,7 +36,7 @@ class SimpleDict(private val client: Client, private val pwd: String) { //must
|
||||
closeDict()
|
||||
}
|
||||
} while (times-- > 0)
|
||||
return re
|
||||
return if(re.isEmpty()) null else re
|
||||
}
|
||||
|
||||
private fun sendMessageWithDelay(msg: CharSequence, delay: Long = 233) = Thread{
|
||||
@@ -77,16 +77,19 @@ class SimpleDict(private val client: Client, private val pwd: String) { //must
|
||||
|
||||
fun filterValues(predicate: (String?) -> Boolean) = dict.filterValues(predicate)
|
||||
|
||||
fun fetchDict(doOnLoadSuccess: ()->Unit = {
|
||||
fun fetchDict(doOnLoadFailure: ()->Unit = {
|
||||
Log.d("MySD", "Fetch dict success")
|
||||
}) {
|
||||
}, doOnLoadSuccess: ()->Unit = {
|
||||
Log.d("MySD", "Fetch dict success")
|
||||
}, doCommon: (() -> Unit)? = null) {
|
||||
val dictBlock = ByteArray(128)
|
||||
dict = hashMapOf()
|
||||
latestKeys = arrayOf()
|
||||
raw.inputStream().let {
|
||||
raw?.inputStream()?.let {
|
||||
while (it.read(dictBlock, 0, 128) == 128) analyzeDictBlk(dictBlock)
|
||||
doOnLoadSuccess()
|
||||
}
|
||||
}?:doOnLoadFailure()
|
||||
doCommon?.let { it() }
|
||||
}
|
||||
|
||||
operator fun minusAssign(key: String) {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.4.31'
|
||||
ext.kotlin_version = '1.4.32'
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath "com.android.tools.build:gradle:4.1.2"
|
||||
classpath 'com.android.tools.build:gradle:4.1.3'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
|
||||
Reference in New Issue
Block a user