1
0
mirror of https://github.com/fumiama/simple-dict-android.git synced 2026-06-11 21:50:34 +08:00
1. 修正连接失败处理逻辑
This commit is contained in:
fumiama
2021-04-10 21:44:59 +08:00
parent e76dd415b9
commit 516727ee7e
4 changed files with 23 additions and 19 deletions

View File

@@ -12,8 +12,8 @@ android {
applicationId "top.fumiama.simpledict" applicationId "top.fumiama.simpledict"
minSdkVersion 26 minSdkVersion 26
targetSdkVersion 30 targetSdkVersion 30
versionCode 12 versionCode 13
versionName '1.9.1' versionName '1.9.2'
resConfigs "zh", "zh-rCN" resConfigs "zh", "zh-rCN"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -47,8 +47,8 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0' implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.3' implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.3' implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.ext:junit:1.1.2'

View File

@@ -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 { setOnFocusChangeListener(object : SearchLayout.OnFocusChangeListener {
override fun onFocusChange(hasFocus: Boolean) { override fun onFocusChange(hasFocus: Boolean) {
navigationIconSupport = if (hasFocus) SearchLayout.NavigationIconSupport.ARROW navigationIconSupport = if (hasFocus) SearchLayout.NavigationIconSupport.ARROW
@@ -206,9 +200,16 @@ class MainActivity : AppCompatActivity() {
private fun fetchThread(doWhenFinish: (()->Unit)? = null) { private fun fetchThread(doWhenFinish: (()->Unit)? = null) {
Thread{ Thread{
dict?.fetchDict { dict?.fetchDict({
runOnUiThread {
Toast.makeText(this@MainActivity, "刷新失败", Toast.LENGTH_SHORT).show()
}
}, {
runOnUiThread { runOnUiThread {
Toast.makeText(this@MainActivity, "刷新成功", Toast.LENGTH_SHORT).show() Toast.makeText(this@MainActivity, "刷新成功", Toast.LENGTH_SHORT).show()
}
}) {
runOnUiThread {
ffsw.isRefreshing = false ffsw.isRefreshing = false
ad?.capacity = 5 ad?.capacity = 5
ad?.refresh() ad?.refresh()

View File

@@ -8,7 +8,7 @@ class SimpleDict(private val client: Client, private val pwd: String) { //must
val size get() = dict.size val size get() = dict.size
val keys get() = dict.keys val keys get() = dict.keys
var latestKeys = arrayOf<String>() var latestKeys = arrayOf<String>()
private val raw: ByteArray private val raw: ByteArray?
get() { get() {
var times = 3 var times = 3
var re: ByteArray var re: ByteArray
@@ -36,7 +36,7 @@ class SimpleDict(private val client: Client, private val pwd: String) { //must
closeDict() closeDict()
} }
} while (times-- > 0) } while (times-- > 0)
return re return if(re.isEmpty()) null else re
} }
private fun sendMessageWithDelay(msg: CharSequence, delay: Long = 233) = Thread{ 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 filterValues(predicate: (String?) -> Boolean) = dict.filterValues(predicate)
fun fetchDict(doOnLoadSuccess: ()->Unit = { fun fetchDict(doOnLoadFailure: ()->Unit = {
Log.d("MySD", "Fetch dict success") Log.d("MySD", "Fetch dict success")
}) { }, doOnLoadSuccess: ()->Unit = {
Log.d("MySD", "Fetch dict success")
}, doCommon: (() -> Unit)? = null) {
val dictBlock = ByteArray(128) val dictBlock = ByteArray(128)
dict = hashMapOf() dict = hashMapOf()
latestKeys = arrayOf() latestKeys = arrayOf()
raw.inputStream().let { raw?.inputStream()?.let {
while (it.read(dictBlock, 0, 128) == 128) analyzeDictBlk(dictBlock) while (it.read(dictBlock, 0, 128) == 128) analyzeDictBlk(dictBlock)
doOnLoadSuccess() doOnLoadSuccess()
} }?:doOnLoadFailure()
doCommon?.let { it() }
} }
operator fun minusAssign(key: String) { operator fun minusAssign(key: String) {

View File

@@ -1,12 +1,12 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { buildscript {
ext.kotlin_version = '1.4.31' ext.kotlin_version = '1.4.32'
repositories { repositories {
google() google()
jcenter() jcenter()
} }
dependencies { 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" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong