diff --git a/.gradle/7.3.3/checksums/checksums.lock b/.gradle/7.3.3/checksums/checksums.lock index f7ccf9d..a6d42d4 100644 Binary files a/.gradle/7.3.3/checksums/checksums.lock and b/.gradle/7.3.3/checksums/checksums.lock differ diff --git a/.gradle/7.3.3/checksums/md5-checksums.bin b/.gradle/7.3.3/checksums/md5-checksums.bin index b555d08..8e8fa8e 100644 Binary files a/.gradle/7.3.3/checksums/md5-checksums.bin and b/.gradle/7.3.3/checksums/md5-checksums.bin differ diff --git a/.gradle/7.3.3/checksums/sha1-checksums.bin b/.gradle/7.3.3/checksums/sha1-checksums.bin index 9ae2745..c73947a 100644 Binary files a/.gradle/7.3.3/checksums/sha1-checksums.bin and b/.gradle/7.3.3/checksums/sha1-checksums.bin differ diff --git a/.gradle/7.3.3/executionHistory/executionHistory.bin b/.gradle/7.3.3/executionHistory/executionHistory.bin index b73cd3d..7368903 100644 Binary files a/.gradle/7.3.3/executionHistory/executionHistory.bin and b/.gradle/7.3.3/executionHistory/executionHistory.bin differ diff --git a/.gradle/7.3.3/executionHistory/executionHistory.lock b/.gradle/7.3.3/executionHistory/executionHistory.lock index 532408d..f4f1790 100644 Binary files a/.gradle/7.3.3/executionHistory/executionHistory.lock and b/.gradle/7.3.3/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.3.3/fileHashes/fileHashes.bin b/.gradle/7.3.3/fileHashes/fileHashes.bin index 75c5615..e7f83fa 100644 Binary files a/.gradle/7.3.3/fileHashes/fileHashes.bin and b/.gradle/7.3.3/fileHashes/fileHashes.bin differ diff --git a/.gradle/7.3.3/fileHashes/fileHashes.lock b/.gradle/7.3.3/fileHashes/fileHashes.lock index 89a87f1..50fdcac 100644 Binary files a/.gradle/7.3.3/fileHashes/fileHashes.lock and b/.gradle/7.3.3/fileHashes/fileHashes.lock differ diff --git a/.gradle/7.3.3/fileHashes/resourceHashesCache.bin b/.gradle/7.3.3/fileHashes/resourceHashesCache.bin index f75d617..339dd16 100644 Binary files a/.gradle/7.3.3/fileHashes/resourceHashesCache.bin and b/.gradle/7.3.3/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 3208f4a..d605513 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin index 2b4c499..d601468 100644 Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index c2bbd11..f8a311c 100644 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/app/build.gradle b/app/build.gradle index 9e47899..125e6ea 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -27,8 +27,8 @@ android { applicationId "com.coldmint.rust.pro" minSdkVersion 21 targetSdkVersion 32 - versionCode 19 - versionName "2.1 Beta1 (2022-9-1)" + versionCode 21 + versionName "2.1 Bata1_patch4(2022-9-3)" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -91,10 +91,10 @@ dependencies { implementation 'com.github.promeg:tinypinyin:2.0.3' implementation 'io.github.youth5201314:banner:2.2.2' implementation 'androidx.core:core-ktx:1.8.0' - implementation 'com.github.deano2390:MaterialShowcaseView:1.3.4' +// implementation 'com.github.deano2390:MaterialShowcaseView:1.3.4' implementation 'com.google.code.gson:gson:2.9.1' implementation 'com.github.yalantis:ucrop:2.2.8-native' - implementation 'com.kongzue.stacklabel:stacklabelview:1.1.9' +// implementation 'com.kongzue.stacklabel:stacklabelview:1.1.9' implementation 'io.github.Rosemoe.sora-editor:editor:0.16.5' implementation project(path: ':assistantCoreLibrary') implementation project(path: ':dialog') @@ -107,7 +107,7 @@ dependencies { implementation 'cat.ereza:customactivityoncrash:2.3.0' implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" implementation 'androidx.appcompat:appcompat:1.5.0' - implementation 'com.google.android.material:material:1.7.0-beta01' + implementation 'com.google.android.material:material:1.7.0-rc01' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" implementation "androidx.navigation:navigation-ui-ktx:$nav_version" diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json index c2258b3..fc42f88 100644 --- a/app/release/output-metadata.json +++ b/app/release/output-metadata.json @@ -11,8 +11,8 @@ "type": "SINGLE", "filters": [], "attributes": [], - "versionCode": 19, - "versionName": "2.1 Beta1 (2022-9-1)", + "versionCode": 21, + "versionName": "2.1 Bata1_patch4(2022-9-3)", "outputFile": "app-release.apk" } ], diff --git a/app/src/main/assets/dataBase_en.rdb b/app/src/main/assets/dataBase_en.rdb new file mode 100644 index 0000000..ef284b5 Binary files /dev/null and b/app/src/main/assets/dataBase_en.rdb differ diff --git a/app/src/main/java/com/coldmint/rust/pro/AboutActivity.kt b/app/src/main/java/com/coldmint/rust/pro/AboutActivity.kt index 35d936b..2285c9a 100644 --- a/app/src/main/java/com/coldmint/rust/pro/AboutActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/AboutActivity.kt @@ -53,7 +53,8 @@ class AboutActivity : BaseActivity() { | |

《铁锈助手》2.0版本,用零零散散的时间开发了1年。开发语言以及开发环境都特别的正式了。

|

环境移到了电脑上使用《Android Studio》开发,开发语言也从java迁移至了Kotlin。

- |

越来越正式了,更多的新功能也在慢慢的加入。

+ | + |

为了安全使用了加固。

| | """.trimMargin() diff --git a/app/src/main/java/com/coldmint/rust/pro/CodeTableActivity.kt b/app/src/main/java/com/coldmint/rust/pro/CodeTableActivity.kt index c161391..4b54382 100644 --- a/app/src/main/java/com/coldmint/rust/pro/CodeTableActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/CodeTableActivity.kt @@ -8,11 +8,7 @@ import android.text.method.LinkMovementMethod import android.text.style.ClickableSpan import android.view.* import androidx.core.view.isVisible -import com.afollestad.materialdialogs.MaterialDialog -import com.afollestad.materialdialogs.WhichButton -import com.afollestad.materialdialogs.actions.setActionButtonEnabled -import com.afollestad.materialdialogs.input.getInputField -import com.afollestad.materialdialogs.input.input +import com.coldmint.dialog.InputDialog import com.coldmint.rust.core.database.code.CodeDataBase import com.coldmint.rust.core.database.code.CodeInfo import com.coldmint.rust.core.database.code.SectionInfo @@ -163,20 +159,18 @@ class CodeTableActivity : BaseActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.filter_units -> { - MaterialDialog(this).show { - title(R.string.filter).message(R.string.filter_tip) - input(maxLength = 20, waitForPositiveButton = false) { dialog, text -> - if (text.isNotEmpty()) { - dialog.setActionButtonEnabled(WhichButton.POSITIVE, true) - } - }.positiveButton(R.string.dialog_ok, null) { dialog -> - var key = dialog.getInputField().text.toString() + InputDialog(this).setTitle(R.string.filter).setMessage(R.string.filter_tip) + .setInputCanBeEmpty(false).setMaxNumber(20) + .setPositiveButton(R.string.dialog_ok) { text -> + var key = text if (key.length > 20) { key = key.substring(0, 20) } loadData(key) - }.negativeButton(R.string.dialog_close) - } + true + }.setNegativeButton(R.string.dialog_close) { + + }.show() } android.R.id.home -> { ifNeedFinish() diff --git a/app/src/main/java/com/coldmint/rust/pro/CustomizeEditTextActivity.kt b/app/src/main/java/com/coldmint/rust/pro/CustomizeEditTextActivity.kt index cae6c28..d0b38ca 100644 --- a/app/src/main/java/com/coldmint/rust/pro/CustomizeEditTextActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/CustomizeEditTextActivity.kt @@ -12,7 +12,6 @@ import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts import androidx.core.view.isVisible import androidx.palette.graphics.Palette -import com.afollestad.materialdialogs.utils.MDUtil.getWidthAndHeight import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions.bitmapTransform import com.coldmint.dialog.CoreDialog @@ -62,8 +61,8 @@ class CustomizeEditTextActivity : BaseActivity val type = FileOperator.getFileType(file) if (type == "png" || type == "jpg") { val bitmap = BitmapFactory.decodeFile(path) - val width = windowManager.getWidthAndHeight().first - val height = windowManager.getWidthAndHeight().second + val width = windowManager.defaultDisplay.width + val height = windowManager.defaultDisplay.height val imageWidth = bitmap.width val imageHeight = bitmap.height if (width % imageWidth == 0 && height % imageHeight == 0) { diff --git a/app/src/main/java/com/coldmint/rust/pro/EditActivity.kt b/app/src/main/java/com/coldmint/rust/pro/EditActivity.kt index 4bf7b84..4c45c91 100644 --- a/app/src/main/java/com/coldmint/rust/pro/EditActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/EditActivity.kt @@ -19,16 +19,12 @@ import androidx.drawerlayout.widget.DrawerLayout import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView -import com.afollestad.materialdialogs.MaterialDialog -import com.afollestad.materialdialogs.WhichButton -import com.afollestad.materialdialogs.actions.setActionButtonEnabled -import com.afollestad.materialdialogs.bottomsheets.BottomSheet -import com.afollestad.materialdialogs.input.getInputField -import com.afollestad.materialdialogs.input.input import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.target.CustomTarget import com.bumptech.glide.request.transition.Transition +import com.coldmint.dialog.CoreDialog +import com.coldmint.dialog.InputDialog import com.coldmint.rust.core.ModClass import com.coldmint.rust.core.database.code.CodeDataBase import com.coldmint.rust.core.database.file.FileDataBase @@ -51,6 +47,11 @@ import com.coldmint.rust.pro.viewmodel.EditStartViewModel import com.coldmint.rust.pro.viewmodel.EditViewModel import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.snackbar.Snackbar +import io.github.rosemoe.sora.lang.completion.CompletionPublisher +import io.github.rosemoe.sora.text.CharPosition +import io.github.rosemoe.sora.text.ContentReference +import io.github.rosemoe.sora.widget.EditorSearcher +import io.github.rosemoe.sora.widget.component.EditorAutoCompletion import io.github.rosemoe.sora.widget.schemes.EditorColorScheme import jp.wasabeef.glide.transformations.BlurTransformation import java.io.File @@ -161,32 +162,33 @@ class EditActivity : BaseActivity() { fun loadMainObserve() { viewModel.needSaveLiveData.observe(this) { if (it) { - MaterialDialog(this).show { - title(R.string.edit_function).message(R.string.text_changed) - .positiveButton(R.string.edit_function) { - viewModel.saveAllFile( - viewBinding.tabLayout.selectedTabPosition, - viewBinding.codeEditor.text.toString() - ) { + CoreDialog(this).setTitle(R.string.edit_function).setMessage(R.string.text_changed) + .setPositiveButton(R.string.edit_function) { + viewModel.saveAllFile( + viewBinding.tabLayout.selectedTabPosition, + viewBinding.codeEditor.text.toString() + ) { + viewModel.needCheckAutoSave = false + finish() + } + }.setNegativeButton(R.string.dialog_cancel) { + + }.setNeutralButton(R.string.not_save_exit) { + CoreDialog(this@EditActivity).setTitle(R.string.not_save_exit) + .setMessage(R.string.not_save_exit_tip) + .setNegativeButton(R.string.dialog_cancel) { + + } + .setPositiveButton(R.string.dialog_ok) { viewModel.needCheckAutoSave = false finish() - } - }.negativeButton(R.string.dialog_cancel) - .neutralButton(R.string.not_save_exit).neutralButton { - MaterialDialog(this@EditActivity).show { - title(R.string.not_save_exit).message(R.string.not_save_exit_tip) - .negativeButton(R.string.dialog_cancel) - .positiveButton(R.string.dialog_ok) { - viewModel.needCheckAutoSave = false - finish() - }.cancelable(false) - } - }.cancelable(false) - } + }.setCancelable(false).show() + }.setCancelable(false).show() } } - viewModel.englishModeLiveData.observe(this) { + viewModel.englishModeLiveData.observe(this) + { rustLanguage.setEnglish(it) } @@ -225,7 +227,8 @@ class EditActivity : BaseActivity() { // } // true // } - viewModel.openedSourceFileListLiveData.observe(this) { + viewModel.openedSourceFileListLiveData.observe(this) + { viewBinding.tabLayout.removeAllTabs() viewBinding.tabLayout.isVisible = true it.forEach { @@ -271,17 +274,14 @@ class EditActivity : BaseActivity() { when (it.title.toString()) { getString(R.string.close) -> { if (openedSourceFile.isNeedSave()) { - MaterialDialog(this).show { - title(R.string.edit_function).message( - R.string.text_changed - ).positiveButton(R.string.edit_function).positiveButton { + CoreDialog(this).setTitle(R.string.edit_function) + .setMessage(R.string.text_changed) + .setPositiveButton(R.string.edit_function) { viewModel.saveOneFile(openedSourceFile) viewModel.closeFile(openedSourceFile) - } - .negativeButton(R.string.dialog_cancel).negativeButton { - viewModel.closeFile(openedSourceFile) - } - } + }.setNegativeButton(R.string.dialog_cancel) { + viewModel.closeFile(openedSourceFile) + }.show() } else { viewModel.closeFile(openedSourceFile) } @@ -305,7 +305,8 @@ class EditActivity : BaseActivity() { } } - viewModel.codeLiveData.observe(this) { + viewModel.codeLiveData.observe(this) + { // rustLanguage.autoCompleteProvider.setSourceFolder( // FileOperator.getSuperDirectory( // viewModel.getNowOpenFilePath() @@ -319,7 +320,8 @@ class EditActivity : BaseActivity() { } viewModel.loadingLiveData.observe( this - ) { + ) + { if (it) { viewBinding.myProgressBar.isVisible = true viewBinding.codeEditor.isVisible = false @@ -478,6 +480,7 @@ class EditActivity : BaseActivity() { // initEndView() showRenewalTip() loadCustomStyle() + loadSearchLayout() turretCoordinateResults = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { viewModel.reloadCode() @@ -557,30 +560,26 @@ class EditActivity : BaseActivity() { startActivityForResult(intent, 3) } getText(R.string.create_folder) -> { - MaterialDialog(this).show { - title(R.string.create_folder) - input(maxLength = 255, waitForPositiveButton = false) { dialog, text -> - if (text.length in 1..255) { - dialog.setActionButtonEnabled(WhichButton.POSITIVE, true) + InputDialog(this).setTitle(R.string.create_folder) + .setHint(R.string.file_name) + .setCancelable(false).setInputCanBeEmpty(false).setMaxNumber(255) + .setErrorTip { s, textInputLayout -> + val newFolder = + File(editStartViewModel.loadPathLiveData.value + "/" + s) + if (newFolder.exists()) { + textInputLayout.error = getString(R.string.folder_error) + } else { + textInputLayout.isErrorEnabled = false } - }.positiveButton(R.string.dialog_ok, null) { dialog -> - val string = dialog.getInputField().text.toString() - if (!string.isEmpty()) { - val file = - File(editStartViewModel.loadPathLiveData.value + "/" + string) - if (file.exists()) { - Toast.makeText( - this@EditActivity, - R.string.folder_error, - Toast.LENGTH_SHORT - ).show() - } else { - file.mkdirs() - editStartViewModel.reloadList() - } - } - }.negativeButton(R.string.dialog_close) - } + }.setPositiveButton(R.string.dialog_ok) { i -> + val newFolder = + File(editStartViewModel.loadPathLiveData.value + "/" + i) + val res = newFolder.mkdirs() + editStartViewModel.reloadList() + res + }.setNegativeButton(R.string.dialog_cancel) { + + }.show() } getText(R.string.copy_to_this) -> { viewModel.executorService.submit { @@ -832,28 +831,19 @@ class EditActivity : BaseActivity() { return@OnMenuItemClickListener false } val oldName = file.name - MaterialDialog(this@EditActivity).show { - title(R.string.rename) - input( - maxLength = 255, - waitForPositiveButton = false, prefill = oldName - ) { dialog, text -> - if (text.length in 1..255) { - dialog.setActionButtonEnabled( - WhichButton.POSITIVE, - true - ) - } - }.positiveButton(R.string.dialog_ok, null) { dialog -> - val newName = dialog.getInputField().text.toString() + InputDialog(this).setTitle(R.string.rename).setMaxNumber(255) + .setText(oldName).setPositiveButton(R.string.dialog_ok) { it -> + val newName = it if (newName != oldName) { val reNameFile = File(editStartViewModel.loadPathLiveData.value + "/" + newName) file.renameTo(reNameFile) editStartViewModel.reloadList() } - }.negativeButton(R.string.dialog_close) - } + true + }.setNegativeButton(R.string.dialog_close) { + + }.show() } else if (title == getString(R.string.remove_bookmark)) { viewBinding.editDrawerlayout.closeDrawer(GravityCompat.START) val removeBookmark = @@ -957,7 +947,7 @@ class EditActivity : BaseActivity() { } val codeToolAdapter = CodeToolAdapter(this, items) codeToolAdapter.setItemEvent { i, codeToolItemBinding, viewHolder, item -> - codeToolItemBinding.root.setOnClickListener { + codeToolItemBinding.codeTextItemView.setOnClickListener { if (item == getString(R.string.symbol11)) { GlobalMethod.showColorPickerDialog(this) { viewBinding.codeEditor.insertText(it, it.length) @@ -978,7 +968,9 @@ class EditActivity : BaseActivity() { ).show() } } else if (item == getString(R.string.code_tip)) { -// viewModel.executorService.submit { + viewBinding.codeEditor.getComponent(EditorAutoCompletion::class.java) + .requireCompletion() + // viewModel.executorService.submit { // try { // val list = ArrayList() // //如果不包含:搜索键 @@ -1112,7 +1104,12 @@ class EditActivity : BaseActivity() { ) ) rustLanguage.setCodeEditor(viewBinding.codeEditor) - viewBinding.codeEditor.setAutoCompletionItemAdapter(RustCompletionAdapter()) + + val codeEditBackGroundEnable = + AppSettings.getValue(AppSettings.Setting.CodeEditBackGroundEnable, false) + val rustCompletionAdapter = RustCompletionAdapter() + rustCompletionAdapter.setEditBackground(codeEditBackGroundEnable) + viewBinding.codeEditor.setAutoCompletionItemAdapter(rustCompletionAdapter) viewBinding.codeEditor.isVerticalScrollBarEnabled = false val path = viewModel.modClass?.modFile?.absolutePath ?: "" CompletionItemConverter.configurationFileConversion( @@ -1275,10 +1272,9 @@ class EditActivity : BaseActivity() { R.id.display_source_code -> { val file = File(viewModel.getNowOpenFilePath()) val code = FileOperator.readFile(file) - MaterialDialog(this, BottomSheet()).show { - title(text = file.name).message(text = code).negativeButton(R.string.dialog_ok) - .cancelable(false) - } + MaterialAlertDialogBuilder(this).setTitle(file.name).setMessage(code).setNegativeButton(R.string.dialog_ok){ + i,i2-> + }.setCancelable(false).show() } R.id.clear_code_cache -> { Snackbar.make( @@ -1396,14 +1392,59 @@ class EditActivity : BaseActivity() { viewBinding.codeEditor.redo() } R.id.search_view -> { - viewBinding.codeEditor.searcher.stopSearch() - viewBinding.codeEditor.beginSearchMode() + viewBinding.searchLayout.isVisible = true + viewBinding.allButton.isVisible = false + viewBinding.replaceEditText.setText("") + viewBinding.replaceEditText.isVisible = false + viewBinding.findEditText.setText("") } } return super.onOptionsItemSelected(item) } + /** + * 加载搜索布局 + */ + fun loadSearchLayout() { + viewBinding.closeButton.setOnClickListener { + viewBinding.searchLayout.isVisible = false + viewBinding.codeEditor.searcher.stopSearch() + } + viewBinding.nextButton.setOnClickListener { + val find = viewBinding.findEditText.text.toString() + viewBinding.codeEditor.searcher.search(find, EditorSearcher.SearchOptions(false, false)) + viewBinding.codeEditor.searcher.gotoNext() + } + viewBinding.lastButton.setOnClickListener { + val find = viewBinding.findEditText.text.toString() + viewBinding.codeEditor.searcher.search(find, EditorSearcher.SearchOptions(false, false)) + viewBinding.codeEditor.searcher.gotoPrevious() + + } + viewBinding.allButton.setOnClickListener { + val find = viewBinding.findEditText.text.toString() + val re = viewBinding.replaceEditText.text.toString() + viewBinding.codeEditor.searcher.search(find, EditorSearcher.SearchOptions(false, false)) + viewBinding.codeEditor.searcher.replaceAll(re) + } + viewBinding.replaceButton.setOnClickListener { + val isVisible = viewBinding.replaceLayout.isVisible + if (isVisible) { + val find = viewBinding.findEditText.text.toString() + val re = viewBinding.replaceEditText.text.toString() + viewBinding.codeEditor.searcher.search( + find, + EditorSearcher.SearchOptions(false, false) + ) + viewBinding.codeEditor.searcher.replaceThis(re) + } else { + viewBinding.replaceLayout.isVisible = true + viewBinding.allButton.isVisible = true + } + } + } + /** * 打开侧滑 */ diff --git a/app/src/main/java/com/coldmint/rust/pro/EditUserInfoActivity.kt b/app/src/main/java/com/coldmint/rust/pro/EditUserInfoActivity.kt index 7f209ff..ce50093 100644 --- a/app/src/main/java/com/coldmint/rust/pro/EditUserInfoActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/EditUserInfoActivity.kt @@ -14,16 +14,13 @@ import android.view.View import android.widget.PopupMenu import android.widget.Toast import androidx.core.view.isVisible -import com.afollestad.materialdialogs.MaterialDialog -import com.afollestad.materialdialogs.WhichButton -import com.afollestad.materialdialogs.actions.setActionButtonEnabled -import com.afollestad.materialdialogs.input.getInputField -import com.afollestad.materialdialogs.input.input import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions +import com.coldmint.dialog.InputDialog import com.coldmint.rust.core.dataBean.ApiResponse import com.coldmint.rust.core.dataBean.user.SpaceInfoData import com.coldmint.rust.core.interfaces.ApiCallBack +import com.coldmint.rust.core.tool.DebugHelper import com.coldmint.rust.core.tool.FileOperator import com.coldmint.rust.core.web.Community import com.coldmint.rust.core.web.ServerConfiguration @@ -171,20 +168,20 @@ class EditUserInfoActivity : BaseActivity() { startIntent.putExtra("data", fileBundle) startActivityForResult(startIntent, 1) } else if (title == getString(R.string.from_url)) { - MaterialDialog(this).show { - title(R.string.from_url).message(R.string.from_url_tip) - input(waitForPositiveButton = false) { dialog, text -> - if (text.matches(Regex("^http://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$|^https://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$"))) { - dialog.setActionButtonEnabled(WhichButton.POSITIVE, true) - } else { - dialog.setActionButtonEnabled(WhichButton.POSITIVE, false) - } - }.positiveButton(R.string.dialog_ok, null) { dialog -> - val input = dialog.getInputField().text.toString() - needCleanCache = true - loadIcon(input) - }.negativeButton(R.string.dialog_close) - } + InputDialog(this).setTitle(R.string.from_url).setMessage(R.string.from_url_tip).setErrorTip { s, textInputLayout -> + if (s.matches(Regex("^http://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$|^https://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$"))) { + textInputLayout.error = getString(R.string.from_url_tip) + } else { + textInputLayout.isErrorEnabled = false + } + }.setPositiveButton(R.string.dialog_ok){ + input-> + needCleanCache = true + loadIcon(input) + true + }.setNegativeButton(R.string.dialog_close){ + + }.show() } else { val link = iconLink if (link != null) { @@ -217,20 +214,22 @@ class EditUserInfoActivity : BaseActivity() { startIntent.putExtra("data", fileBundle) startActivityForResult(startIntent, 2) } else if (title == getString(R.string.from_url)) { - MaterialDialog(this).show { - title(R.string.from_url).message(R.string.from_url_tip) - input(waitForPositiveButton = false) { dialog, text -> - if (text.matches(Regex("^http://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$|^https://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$"))) { - dialog.setActionButtonEnabled(WhichButton.POSITIVE, true) - } else { - dialog.setActionButtonEnabled(WhichButton.POSITIVE, false) - } - }.positiveButton(R.string.dialog_ok, null) { dialog -> - val input = dialog.getInputField().text.toString() - needCleanCache = true - loadCover(input) - }.negativeButton(R.string.dialog_close) - } + InputDialog(this).setTitle(R.string.from_url).setMessage(R.string.from_url_tip).setErrorTip { s, textInputLayout -> + if (s.matches(Regex("^http://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$|^https://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$"))) { + textInputLayout.error = getString(R.string.from_url_tip) + } else { + textInputLayout.isErrorEnabled = false + } + }.setPositiveButton(R.string.dialog_ok){ + input-> + needCleanCache = true + loadCover(input) + true + }.setNegativeButton(R.string.dialog_close){ + + }.show() + + } else { val link = coverLink if (link != null) { diff --git a/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt b/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt index 74ebe19..22d256e 100644 --- a/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt @@ -15,17 +15,11 @@ import android.net.Uri import android.os.* import android.view.* import android.widget.* +import android.widget.Toast.makeText import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts import androidx.core.view.isVisible import androidx.lifecycle.ViewModelProvider -import com.afollestad.materialdialogs.MaterialDialog -import com.afollestad.materialdialogs.WhichButton -import com.afollestad.materialdialogs.actions.setActionButtonEnabled -import com.afollestad.materialdialogs.input.getInputField -import com.afollestad.materialdialogs.input.input -import com.afollestad.materialdialogs.list.listItems -import com.afollestad.materialdialogs.utils.MDUtil.isLandscape import com.bumptech.glide.Glide import com.coldmint.dialog.CoreDialog import com.coldmint.dialog.InputDialog @@ -42,6 +36,9 @@ import com.coldmint.rust.pro.viewmodel.FileManagerViewModel import com.google.android.material.chip.Chip import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.snackbar.SnackbarContentLayout +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Job +import kotlinx.coroutines.launch import me.zhanghai.android.fastscroll.FastScrollerBuilder import java.io.BufferedReader import java.io.File @@ -49,6 +46,7 @@ import java.io.InputStreamReader import java.lang.Exception import java.util.* import java.util.concurrent.Executors +import javax.sql.CommonDataSource import kotlin.collections.ArrayList class FileManagerActivity : BaseActivity() { @@ -229,16 +227,16 @@ class FileManagerActivity : BaseActivity() { // } FileManagerViewModel.StartType.DEFAULT, FileManagerViewModel.StartType.SELECT_FILE, FileManagerViewModel.StartType.SELECT_DIRECTORY -> { val popupMenu = PopupMenu(this@FileManagerActivity, viewBinding.fab) -// if (mFileAdapter != null) { -// val selectPath = mFileAdapter!!.selectPath -// if (selectPath != null && mProcessFiles == false) { -// if (mFileAdapter!!.isCopyFile) { -// popupMenu.menu.add(R.string.copy_to_this) -// } else { -// popupMenu.menu.add(R.string.cut_to_this) -// } -// } -// } + if (adapter != null) { + val selectPath = adapter!!.selectPath + if (selectPath != null) { + if (adapter!!.isCopyFile) { + popupMenu.menu.add(R.string.copy_to_this) + } else { + popupMenu.menu.add(R.string.cut_to_this) + } + } + } popupMenu.menu.add(R.string.create_unit) popupMenu.menu.add(R.string.create_folder) popupMenu.menu.add(R.string.select_file) @@ -270,52 +268,63 @@ class FileManagerActivity : BaseActivity() { getText(R.string.create_folder) -> { createFolderAction() } -// getText(R.string.copy_to_this) -> { -// Thread { -// mProcessFiles = true -// val oldFile = File(mFileAdapter!!.selectPath) -// val newFile = File(directs.absolutePath + "/" + oldFile.name) -// if (FileOperator.copyFiles(oldFile, newFile)) { -// handler.post { -// loadFiles(directs) -// mFileAdapter!!.cleanSelectPath() -// mProcessFiles = false -// } -// } else { -// handler.post { -// Toast.makeText( -// this@FileManagerActivity, -// getText(R.string.copy_failed), -// Toast.LENGTH_SHORT -// ).show() -// mProcessFiles = false -// } -// } -// }.start() -// } -// getText(R.string.cut_to_this) -> { -// Thread { -// mProcessFiles = true -// val oldFile = File(mFileAdapter!!.selectPath) -// val newFile = File(directs.absolutePath + "/" + oldFile.name) -// if (FileOperator.removeFiles(oldFile, newFile)) { -// handler.post { -// loadFiles(directs) -// mFileAdapter!!.cleanSelectPath() -// mProcessFiles = false -// } -// } else { -// handler.post { -// Toast.makeText( -// this@FileManagerActivity, -// getText(R.string.cut_failed), -// Toast.LENGTH_SHORT -// ).show() -// mProcessFiles = false -// } -// } -// }.start() -// } + getText(R.string.copy_to_this) -> { + val job = Job() + val handler = Handler(Looper.getMainLooper()) + val scope = CoroutineScope(job) + scope.launch { + val oldFile = File(adapter!!.selectPath) + val newFile = + File(viewModel.getCurrentPath() + "/" + oldFile.name) + DebugHelper.printLog( + "文件管理器", + "复制文件 旧文件${oldFile.absolutePath} 新文件${newFile.absolutePath}" + ) + adapter!!.cleanSelectPath() + if (FileOperator.copyFiles(oldFile, newFile)) { + handler.post { + viewModel.loadFiles(viewModel.getCurrentPath()) + } + } else { + + handler.post { + Snackbar.make( + viewBinding.fab, + getText(R.string.copy_failed), + Snackbar.LENGTH_SHORT + ).show() + } + } + } + } + getText(R.string.cut_to_this) -> { + val job = Job() + val handler = Handler(Looper.getMainLooper()) + val scope = CoroutineScope(job) + scope.launch { + val oldFile = File(adapter!!.selectPath) + val newFile = + File(viewModel.getCurrentPath() + "/" + oldFile.name) + DebugHelper.printLog( + "文件管理器", + "移动文件 旧文件${oldFile.absolutePath} 新文件${newFile.absolutePath}" + ) + adapter!!.cleanSelectPath() + if (FileOperator.removeFiles(oldFile, newFile)) { + handler.post { + viewModel.loadFiles(viewModel.getCurrentPath()) + } + } else { + handler.post { + Snackbar.make( + viewBinding.fab, + getText(R.string.cut_failed), + Snackbar.LENGTH_SHORT + ).show() + } + } + } + } } false } @@ -478,7 +487,7 @@ class FileManagerActivity : BaseActivity() { * 使用系统文件选择器选择回调 * @param uri Uri */ - fun selectFileCallback(uri: Uri?){ + fun selectFileCallback(uri: Uri?) { val path = viewModel.parseFilePath(this, uri) if (path != null) { CoreDialog(this).setTitle(R.string.system_file_manager).setMessage(path) @@ -520,7 +529,7 @@ class FileManagerActivity : BaseActivity() { } systemFileManagerResultLauncher = registerForActivityResult(ActivityResultContracts.GetContent()) { - selectFileCallback(it) + selectFileCallback(it) } FastScrollerBuilder(viewBinding.recyclerView).useMd2Style() .setPopupTextProvider(adapter).build() @@ -690,6 +699,26 @@ class FileManagerActivity : BaseActivity() { ).setAction(R.string.dialog_ok) { setResultAndFinish(file.absolutePath) }.setGestureInsetBottomIgnored(true).show() + } else if (viewModel.startTypeData == FileManagerViewModel.StartType.DEFAULT) { + val type = FileOperator.getFileType(file) + if (type == "ini" || type == "txt") { + val intent = Intent(this, EditActivity::class.java) + val bundle = Bundle() + bundle.putString("path", file.absolutePath) + bundle.putString( + "modPath", + FileOperator.getSuperDirectory(file) + ) + intent.putExtra("data", bundle) + startActivity(intent) + } else { + Snackbar.make( + viewBinding.fab, String.format( + getString(R.string.an_unsupported_file_type), + type + ), Snackbar.LENGTH_SHORT + ).show() + } } } } @@ -789,6 +818,17 @@ class FileManagerActivity : BaseActivity() { }.show() } + R.id.copyAction -> { + val finalFile = + adapter!!.getItemData(viewHolder.absoluteAdapterPosition) + adapter!!.setSelectPath(finalFile!!.absolutePath, true) + } + R.id.cutOffAction -> { + val finalFile = + adapter!!.getItemData(viewHolder.absoluteAdapterPosition) + adapter!!.setSelectPath(finalFile!!.absolutePath, false) + } + } true } diff --git a/app/src/main/java/com/coldmint/rust/pro/GlobalOperationsActivity.kt b/app/src/main/java/com/coldmint/rust/pro/GlobalOperationsActivity.kt index 987c1be..bbe598d 100644 --- a/app/src/main/java/com/coldmint/rust/pro/GlobalOperationsActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/GlobalOperationsActivity.kt @@ -14,7 +14,7 @@ import androidx.core.view.isVisible import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager -import com.afollestad.materialdialogs.MaterialDialog +import com.coldmint.dialog.CoreDialog import com.coldmint.rust.core.ModClass import com.coldmint.rust.pro.adapters.AttachFileAdapter import com.coldmint.rust.pro.base.BaseActivity @@ -145,9 +145,9 @@ class GlobalOperationsActivity : BaseActivity() viewBinding.actionEditText1.text.toString(), viewBinding.actionEditText2.text.toString() ) - MaterialDialog(this).title(text = data).message(R.string.figure_out) - .cancelable(false) - .positiveButton(R.string.dialog_ok).show() + CoreDialog(this).setTitle(data).setMessage(R.string.figure_out).setPositiveButton(R.string.dialog_ok){ + + }.setCancelable(false).show() } } diff --git a/app/src/main/java/com/coldmint/rust/pro/ImporterActivity.kt b/app/src/main/java/com/coldmint/rust/pro/ImporterActivity.kt index 3e04acb..c8a7212 100644 --- a/app/src/main/java/com/coldmint/rust/pro/ImporterActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/ImporterActivity.kt @@ -7,7 +7,7 @@ import android.view.LayoutInflater import android.widget.Toast import androidx.core.view.isVisible import androidx.lifecycle.ViewModelProvider -import com.afollestad.materialdialogs.MaterialDialog +import com.coldmint.dialog.CoreDialog import com.coldmint.rust.core.CompressionManager import com.coldmint.rust.core.LocalTemplatePackage import com.coldmint.rust.core.dataBean.template.TemplateInfo @@ -235,24 +235,23 @@ class ImporterActivity : BaseActivity() { } if (newInfo.versionNum < oldInfo.versionNum) { handler.post { - MaterialDialog(this).show { - title(text = oldInfo.name).cancelable(false).message( - text = String.format( + CoreDialog(this).setTitle(oldInfo.name).setCancelable(false) + .setMessage( + String.format( getString(R.string.covers_the_import), newInfo.versionName, oldInfo.versionName ) - ).positiveButton(R.string.dialog_ok).positiveButton { + ).setPositiveButton(R.string.dialog_ok) { FileOperator.delete_files(templateDirectory) importTemplate(outputDirectory, templateDirectory) - }.negativeButton(R.string.dialog_cancel).negativeButton { + }.setNegativeButton(R.string.dialog_cancel) { viewBinding.okButton.setBackgroundColor( GlobalMethod.getColorPrimary( this@ImporterActivity ) ) viewBinding.okButton.setText(R.string.import_name) - } - } + }.show() } return@Runnable } else { diff --git a/app/src/main/java/com/coldmint/rust/pro/LibraryActivity.kt b/app/src/main/java/com/coldmint/rust/pro/LibraryActivity.kt index 301233b..35a3232 100644 --- a/app/src/main/java/com/coldmint/rust/pro/LibraryActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/LibraryActivity.kt @@ -183,11 +183,12 @@ class LibraryActivity : BaseActivity() { if (canUseView) { setReturnButton() title = getString(R.string.libs) + val divider = MaterialDividerItemDecoration( + this, + MaterialDividerItemDecoration.VERTICAL + ) viewBinding.libsView.addItemDecoration( - DividerItemDecoration( - this, - DividerItemDecoration.VERTICAL - ) + divider ) viewBinding.libsView.layoutManager = LinearLayoutManager(this@LibraryActivity) val libAdapter = LibAdapter(this@LibraryActivity, getLibInfoList()) diff --git a/app/src/main/java/com/coldmint/rust/pro/LoginActivity.kt b/app/src/main/java/com/coldmint/rust/pro/LoginActivity.kt index f775ac1..b5f0c3d 100644 --- a/app/src/main/java/com/coldmint/rust/pro/LoginActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/LoginActivity.kt @@ -17,11 +17,6 @@ import android.util.Log import android.view.LayoutInflater import android.view.View import androidx.core.view.isVisible -import com.afollestad.materialdialogs.MaterialDialog -import com.afollestad.materialdialogs.WhichButton -import com.afollestad.materialdialogs.actions.setActionButtonEnabled -import com.afollestad.materialdialogs.input.getInputField -import com.afollestad.materialdialogs.input.input import com.coldmint.dialog.InputDialog import com.coldmint.rust.core.dataBean.ApiResponse import com.coldmint.rust.core.dataBean.LoginRequestData @@ -42,10 +37,10 @@ class LoginActivity : BaseActivity() { private var isLogin = false private fun initAction() { - immersionBar { - transparentStatusBar().statusBarDarkFont(true) - .transparentNavigationBar().navigationBarDarkIcon(true) - } +// immersionBar { +// transparentStatusBar().statusBarDarkFont(true) +// .transparentNavigationBar().navigationBarDarkIcon(true) +// } Log.d("应用识别码", AppSettings.getValue(AppSettings.Setting.AppID, "无")) viewBinding.changeServerView.isVisible = BuildConfig.DEBUG viewBinding.changePasswordView.setOnClickListener { @@ -147,27 +142,13 @@ class LoginActivity : BaseActivity() { } else { when (userData.message) { "请先激活您的账户" -> { - MaterialDialog(this@LoginActivity).show { - title(R.string.activate_the_account).message(R.string.activate_the_account_tip) - .cancelable(false) - input( - maxLength = 6, - waitForPositiveButton = false - ) { dialog, text -> - if (text.length == 6) { - dialog.setActionButtonEnabled( - WhichButton.POSITIVE, - true - ) - } else { - dialog.setActionButtonEnabled( - WhichButton.POSITIVE, - false - ) - } - }.positiveButton(R.string.dialog_ok, null) { dialog -> + InputDialog(this@LoginActivity).setTitle(R.string.activate_the_account) + .setMessage(R.string.activate_the_account_tip) + .setHint(R.string.verification_code) + .setCancelable(false).setMaxNumber(6) + .setPositiveButton(R.string.dialog_ok) { text -> User.activateAccount(account, - dialog.getInputField().text.toString(), + text, object : ApiCallBack { override fun onResponse(t: ApiResponse) { if (t.code == ServerConfiguration.Success_Code) { @@ -190,8 +171,10 @@ class LoginActivity : BaseActivity() { } }) - }.negativeButton(R.string.dialog_close) - } + true + }.setNegativeButton(R.string.dialog_close) { + + }.show() } "找不到用户" -> { setErrorAndInput( @@ -226,32 +209,16 @@ class LoginActivity : BaseActivity() { override fun onResponse(t: ApiResponse) { viewBinding.button.isEnabled = true if (t.code == ServerConfiguration.Success_Code) { - MaterialDialog(this@LoginActivity).show { - title(R.string.verification).message( - R.string.activate_the_account_tip - ) - .cancelable(false) - input( - maxLength = 6, - waitForPositiveButton = false - ) { dialog, text -> - if (text.length == 6) { - dialog.setActionButtonEnabled( - WhichButton.POSITIVE, - true - ) - } else { - dialog.setActionButtonEnabled( - WhichButton.POSITIVE, - false - ) - } - }.positiveButton( - R.string.dialog_ok, - null - ) { dialog -> + InputDialog(this@LoginActivity).setMaxNumber( + 6 + ).setHint(R.string.verification_code) + .setInputCanBeEmpty(false) + .setTitle(R.string.verification) + .setMessage(R.string.activate_the_account_tip) + .setCancelable(false) + .setPositiveButton(R.string.dialog_ok) { it -> User.changeAppId(account, - dialog.getInputField().text.toString(), + it, appId, object : ApiCallBack { @@ -279,8 +246,11 @@ class LoginActivity : BaseActivity() { } }) - }.negativeButton(R.string.dialog_close) - } + true + } + .setNegativeButton(R.string.dialog_close) { + + }.show() } else { Snackbar.make( viewBinding.button, diff --git a/app/src/main/java/com/coldmint/rust/pro/MainActivity.kt b/app/src/main/java/com/coldmint/rust/pro/MainActivity.kt index aa26d25..847a3a5 100644 --- a/app/src/main/java/com/coldmint/rust/pro/MainActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/MainActivity.kt @@ -7,11 +7,14 @@ import android.content.pm.PackageInfo import com.coldmint.rust.pro.tool.AppSettings import android.content.Intent import android.content.pm.PackageManager +import android.content.res.Resources import com.google.android.material.snackbar.Snackbar import android.os.* import android.util.Log import android.view.* import androidx.appcompat.app.ActionBarDrawerToggle +import androidx.appcompat.widget.Toolbar +import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.core.view.GravityCompat import androidx.core.view.isVisible import androidx.lifecycle.ViewModelProvider @@ -20,7 +23,6 @@ import androidx.navigation.ui.AppBarConfiguration import androidx.navigation.ui.navigateUp import androidx.navigation.ui.setupActionBarWithNavController import androidx.navigation.ui.setupWithNavController -import com.afollestad.materialdialogs.MaterialDialog import com.bumptech.glide.Glide import com.coldmint.dialog.CoreDialog import com.coldmint.rust.core.CompressionManager @@ -39,6 +41,7 @@ import com.coldmint.rust.pro.viewmodel.StartViewModel import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.tabs.TabLayout import com.google.gson.Gson +import com.gyf.immersionbar.ImmersionBar import org.json.JSONObject import java.io.File import java.util.concurrent.Executors @@ -107,6 +110,8 @@ class MainActivity : BaseActivity() { ) viewBinding.drawerlayout.addDrawerListener(actionToggle) actionToggle.syncState() + + } /** @@ -669,13 +674,11 @@ class MainActivity : BaseActivity() { startViewModel.signatureErrorLiveData.observe(this) { if (it) { //显示签名错误 - MaterialDialog(this).show { - title(R.string.sign_error).cancelable(false) - .message(R.string.sign_error_message) - .positiveButton(R.string.dialog_close) { - finish() - } - } + CoreDialog(this).setTitle(R.string.sign_error) + .setMessage(R.string.sign_error_message).setCancelable(false) + .setPositiveButton(R.string.dialog_close) { + finish() + } } } @@ -709,6 +712,18 @@ class MainActivity : BaseActivity() { useToolbarSetSupportActionBar() initNav() observeStartViewModel() + //偏移fab + if (ImmersionBar.hasNavigationBar(this)) { + val layoutParams = + viewBinding.mainButton.layoutParams as CoordinatorLayout.LayoutParams + layoutParams.setMargins( + GlobalMethod.dp2px(16), + GlobalMethod.dp2px(16), + GlobalMethod.dp2px(16), + ImmersionBar.getNavigationBarHeight(this) + GlobalMethod.dp2px(16) + ) + DebugHelper.printLog("导航适配", "已调整fab按钮的位置。") + } checkAppUpdate() } else { startViewModel.initAllData() diff --git a/app/src/main/java/com/coldmint/rust/pro/NetworkTemplatePackageDetailsActivity.kt b/app/src/main/java/com/coldmint/rust/pro/NetworkTemplatePackageDetailsActivity.kt index 6a9baff..2b52117 100644 --- a/app/src/main/java/com/coldmint/rust/pro/NetworkTemplatePackageDetailsActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/NetworkTemplatePackageDetailsActivity.kt @@ -15,10 +15,11 @@ import com.coldmint.rust.pro.adapters.TemplateItemAdapter import com.coldmint.rust.pro.base.BaseActivity import com.coldmint.rust.pro.databinding.ActivityNetworkTemplatePackageDetailsBinding import com.coldmint.rust.pro.tool.AppSettings +import com.google.android.material.divider.MaterialDividerItemDecoration class NetworkTemplatePackageDetailsActivity : BaseActivity() { -// private var createDirectory: String? = null + // private var createDirectory: String? = null override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { val id = intent.getStringExtra("id") if (id == null) { @@ -31,11 +32,12 @@ class NetworkTemplatePackageDetailsActivity : title = getString(R.string.title) setReturnButton() viewBinding.recyclerView.layoutManager = LinearLayoutManager(this) + val divider = MaterialDividerItemDecoration( + this, + MaterialDividerItemDecoration.VERTICAL + ) viewBinding.recyclerView.addItemDecoration( - DividerItemDecoration( - this, - DividerItemDecoration.VERTICAL - ) + divider ) TemplatePhp.instance.getTemplateList( id, @@ -52,10 +54,13 @@ class NetworkTemplatePackageDetailsActivity : ) adapter.setItemEvent { i, itemTemplateBinding, viewHolder, template -> itemTemplateBinding.root.setOnClickListener { - val intent = Intent(this@NetworkTemplatePackageDetailsActivity,TemplateMakerActivity::class.java) - intent.putExtra("name",template.title) - intent.putExtra("local",false) - intent.putExtra("path",template.id) + val intent = Intent( + this@NetworkTemplatePackageDetailsActivity, + TemplateMakerActivity::class.java + ) + intent.putExtra("name", template.title) + intent.putExtra("local", false) + intent.putExtra("path", template.id) startActivity(intent) } } diff --git a/app/src/main/java/com/coldmint/rust/pro/OrderListActivity.kt b/app/src/main/java/com/coldmint/rust/pro/OrderListActivity.kt index 9a13dcd..486d7cc 100644 --- a/app/src/main/java/com/coldmint/rust/pro/OrderListActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/OrderListActivity.kt @@ -9,7 +9,7 @@ import android.view.ViewGroup import android.widget.PopupMenu import androidx.core.view.isVisible import androidx.recyclerview.widget.LinearLayoutManager -import com.afollestad.materialdialogs.MaterialDialog +import com.coldmint.dialog.CoreDialog import com.coldmint.rust.core.dataBean.ApiResponse import com.coldmint.rust.core.dataBean.OrderListDataBean import com.coldmint.rust.core.interfaces.ApiCallBack @@ -80,16 +80,11 @@ class OrderListActivity : BaseActivity() { "设置订单" -> { when (data.state) { "false" -> { - MaterialDialog(this@OrderListActivity).show { - title(text = data.name).message(text = "确认收到" + data.account + "的付款了嘛?\n订单创建时间:" + data.createTime) - .positiveButton(R.string.pay_yes) - .positiveButton { - confirmOrder(data.flag, true) - }.negativeButton(R.string.pay_no) - .negativeButton { - confirmOrder(data.flag, false) - } - } + CoreDialog(this@OrderListActivity).setTitle(data.name).setMessage("确认收到" + data.account + "的付款了嘛?\n订单创建时间:" + data.createTime).setPositiveButton(R.string.pay_yes){ + confirmOrder(data.flag, true) + }.setNegativeButton(R.string.pay_no){ + confirmOrder(data.flag, false) + }.show() } else -> { showToast("无需处理") @@ -109,26 +104,23 @@ class OrderListActivity : BaseActivity() { } } else { - MaterialDialog(this@OrderListActivity).show { - title(text = data.name).message( - text = String.format( - getString(R.string.copy_orderid), - data.flag - ) - ).positiveButton(R.string.copy).positiveButton { - val flag = data.flag - GlobalMethod.copyText(this@OrderListActivity, flag) - Snackbar.make( - viewBinding.progressBar, - String.format( - getString(R.string.copy_complete), - flag - ), - Snackbar.LENGTH_SHORT - ).show() - }.cancelable(false) - .negativeButton(R.string.dialog_cancel) - } + CoreDialog(this@OrderListActivity).setTitle(String.format( + getString(R.string.copy_orderid), + data.flag + )).setPositiveButton(R.string.copy){ + val flag = data.flag + GlobalMethod.copyText(this@OrderListActivity, flag) + Snackbar.make( + viewBinding.progressBar, + String.format( + getString(R.string.copy_complete), + flag + ), + Snackbar.LENGTH_SHORT + ).show() + }.setNegativeButton(R.string.dialog_cancel){ + + }.setCancelable(false).show() } } } diff --git a/app/src/main/java/com/coldmint/rust/pro/PayActivity.kt b/app/src/main/java/com/coldmint/rust/pro/PayActivity.kt index 6d6b747..be05cb7 100644 --- a/app/src/main/java/com/coldmint/rust/pro/PayActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/PayActivity.kt @@ -1,11 +1,14 @@ package com.coldmint.rust.pro +import android.content.Intent import android.graphics.Color import android.graphics.Typeface import android.os.Bundle import android.os.CountDownTimer +import android.text.Editable import android.text.SpannableString import android.text.Spanned +import android.text.TextWatcher import android.view.View import android.widget.AdapterView import android.widget.Toast @@ -20,7 +23,7 @@ import android.view.KeyEvent import android.view.LayoutInflater import android.view.MenuItem import androidx.core.view.isVisible -import com.afollestad.materialdialogs.MaterialDialog +import com.coldmint.dialog.CoreDialog import com.coldmint.rust.core.dataBean.OrderDataBean import com.coldmint.rust.core.interfaces.ApiCallBack import com.coldmint.rust.core.tool.AppOperator @@ -53,9 +56,14 @@ class PayActivity : BaseActivity() { //倒计时器 var countDownTimer: CountDownTimer? = null + val color by lazy { + GlobalMethod.getColorPrimary(this) + } + + override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { if (canUseView) { - viewBinding.toolbar.title = getText(R.string.pay) + title = getText(R.string.pay) setReturnButton() val thisIntent = intent val uuid = thisIntent.getStringExtra("uuid") @@ -70,112 +78,129 @@ class PayActivity : BaseActivity() { ServerConfiguration.getRealLink("/resources/image/Payment/Alipay.png") hashMap[getString(R.string.wechat_pay)] = ServerConfiguration.getRealLink("/resources/image/Payment/WeChat.png") - val array = resources.getStringArray(R.array.pay_type_entries) - viewBinding.typeSpinner.onItemSelectedListener = - object : AdapterView.OnItemSelectedListener { - override fun onItemSelected( - parent: AdapterView<*>?, - view: View?, - position: Int, - id: Long - ) { - when (val type = array[position]) { - getString(R.string.qq_pay), getString(R.string.alipay), getString(R.string.wechat_pay) -> { - Glide.with(this@PayActivity) - .load(hashMap[type]).apply(GlobalMethod.getRequestOptions()) - .into(viewBinding.baseImageView) - } - } - } - - override fun onNothingSelected(parent: AdapterView<*>?) { - - } - + Glide.with(this@PayActivity) + .load(hashMap[getString(R.string.wechat_pay)]).apply(GlobalMethod.getRequestOptions()) + .into(viewBinding.baseImageView) + viewBinding.typeAutoCompleteTextView.addTextChangedListener(object : TextWatcher { + override fun beforeTextChanged( + s: CharSequence?, + start: Int, + count: Int, + after: Int + ) { } + override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { + } + + override fun afterTextChanged(s: Editable?) { + val type = s.toString() + when (type) { + getString(R.string.qq_pay), getString(R.string.alipay), getString(R.string.wechat_pay) -> { + viewBinding.saveCode.text = getString(R.string.sava_code_and_copy_id) + viewBinding.cardView.isVisible = true + Glide.with(this@PayActivity) + .load(hashMap[type]).apply(GlobalMethod.getRequestOptions()) + .into(viewBinding.baseImageView) + } +// getString(R.string.paypal) -> { +// viewBinding.cardView.isVisible = false +// viewBinding.saveCode.text = getString(R.string.paypal_payment) +// } + } + } + + }) + viewBinding.saveCode.setOnClickListener { - GlobalMethod.copyText(this, uuid) - val type = array[viewBinding.typeSpinner.selectedItemPosition] - val link = hashMap[type] - val appName = when (type) { - getString(R.string.qq_pay) -> { - getString(R.string.qq) - } - getString(R.string.wechat_pay) -> { - getString(R.string.wechat) - } - else -> { - getString(R.string.alipay) - } - } - val targetFile = File(AppSettings.dataRootDirectory + "/pay/" + type + ".png") - //获取下载链接,保存二维码(如果二维码存在则不会保存) - if (link != null && !targetFile.exists()) { - val okHttpClient = ServerConfiguration.initOkHttpClient() - val request = Request.Builder() - .url(link).build() - val call = okHttpClient.newCall(request) - call.enqueue(object : Callback { - override fun onFailure(call: Call, e: IOException) { - Snackbar.make( - viewBinding.saveCode, - R.string.file_download_fail, - Snackbar.LENGTH_SHORT - ).show() + val text = viewBinding.saveCode.text.toString() + if (text == getString(R.string.paypal_payment)) { +//启动paypal +// val intent = Intent(this, BrowserActivity::class.java) +// intent.putExtra("link", "https://paypal.me/coldmint") +// startActivity(intent) + } else { + GlobalMethod.copyText(this, uuid) + val type = viewBinding.typeAutoCompleteTextView.text.toString() + val link = hashMap[type] + val appName = when (type) { + getString(R.string.qq_pay) -> { + getString(R.string.qq) } - - override fun onResponse(call: Call, response: Response) { - val body = response.body - if (body != null) { - val inputStream = body.byteStream() - FileOperator.copyFile( - inputStream, - targetFile - ) - } else { + getString(R.string.wechat_pay) -> { + getString(R.string.wechat) + } + else -> { + getString(R.string.alipay) + } + } + val targetFile = File(AppSettings.dataRootDirectory + "/pay/" + type + ".png") + //获取下载链接,保存二维码(如果二维码存在则不会保存) + if (link != null && !targetFile.exists()) { + val okHttpClient = ServerConfiguration.initOkHttpClient() + val request = Request.Builder() + .url(link).build() + val call = okHttpClient.newCall(request) + call.enqueue(object : Callback { + override fun onFailure(call: Call, e: IOException) { Snackbar.make( viewBinding.saveCode, R.string.file_download_fail, Snackbar.LENGTH_SHORT ).show() } + + override fun onResponse(call: Call, response: Response) { + val body = response.body + if (body != null) { + val inputStream = body.byteStream() + FileOperator.copyFile( + inputStream, + targetFile + ) + } else { + Snackbar.make( + viewBinding.saveCode, + R.string.file_download_fail, + Snackbar.LENGTH_SHORT + ).show() + } + } + + }) + } + AppOperator.updateTheAlbum(this, targetFile) + CoreDialog(this).setTitle(R.string.pay).setMessage(String.format( + getString(R.string.pay_tip2), + appName + )).setPositiveButton(R.string.dialog_ok){ + val packName = when (type) { + getString(R.string.qq_pay) -> { + "com.tencent.mobileqq" + } + getString(R.string.wechat_pay) -> { + "com.tencent.mm" + } + else -> { + "com.eg.android.AlipayGphone" + } } + if (AppOperator.isAppInstalled(this@PayActivity, packName)) { + AppOperator.openApp(this@PayActivity, packName) + } else { + Snackbar.make( + viewBinding.saveCode, + String.format( + getString(R.string.no_app_installed), + appName + ), + Snackbar.LENGTH_SHORT + ).show() + } + }.setNegativeButton(R.string.dialog_cancel){ - }) + }.setCancelable(false).show() } - AppOperator.updateTheAlbum(this, targetFile) - MaterialDialog(this).show { - title(R.string.pay).message( - text = String.format( - getString(R.string.pay_tip2), - appName - ) - ) - .positiveButton(R.string.dialog_ok).positiveButton { - val packName = when (type) { - getString(R.string.qq_pay) -> { - "com.tencent.mobileqq" - } - getString(R.string.wechat_pay) -> { - "com.tencent.mm" - } - else -> { - "com.eg.android.AlipayGphone" - } - } - if (AppOperator.isAppInstalled(this@PayActivity, packName)) { - AppOperator.openApp(this@PayActivity, packName) - } else { - Snackbar.make( - viewBinding.saveCode, - String.format(getString(R.string.no_app_installed), appName), - Snackbar.LENGTH_SHORT - ).show() - } - }.negativeButton(R.string.dialog_cancel).cancelable(false) - } - } ActivationApp.instance.getOrderInfo(account, uuid, object : ApiCallBack { @@ -221,7 +246,7 @@ class PayActivity : BaseActivity() { override fun onFinish() { past = true - viewBinding.typeSpinner.isEnabled = false + viewBinding.typeAutoCompleteTextView.isEnabled = false viewBinding.baseImageView.isVisible = false viewBinding.payMoneyView.text = getString(R.string.order_timeout) viewBinding.saveCode.isEnabled = false @@ -249,15 +274,13 @@ class PayActivity : BaseActivity() { first = false } else { if (!past) { - MaterialDialog(this).show { - title(R.string.pay).message(R.string.is_paid).positiveButton(R.string.paid_yes) - .positiveButton { - finish() - } - .negativeButton(R.string.paid_no).negativeButton { - askingQuit() - }.cancelable(false).neutralButton(R.string.paid_continue) - } + CoreDialog(this).setTitle(R.string.pay).setMessage(R.string.is_paid).setPositiveButton(R.string.paid_yes){ + finish() + }.setNegativeButton(R.string.paid_no){ + askingQuit() + }.setNeutralButton(R.string.paid_continue){ + + }.setCancelable(false).show() } } } @@ -287,17 +310,15 @@ class PayActivity : BaseActivity() { countDownTimer?.cancel() finish() } else { - MaterialDialog(this).show { - title(R.string.paid_no).message( - text = String.format( - getString(R.string.preferential_price), - difference - ) - ).positiveButton(R.string.dialog_ok).positiveButton { - countDownTimer?.cancel() - finish() - }.negativeButton(R.string.dialog_cancel).cancelable(false) - } + CoreDialog(this).setTitle(R.string.paid_no).setMessage(String.format( + getString(R.string.preferential_price), + difference + )).setPositiveButton(R.string.dialog_ok){ + countDownTimer?.cancel() + finish() + }.setNegativeButton(R.string.dialog_cancel){ + + }.setCancelable(false).show() } } @@ -316,8 +337,8 @@ class PayActivity : BaseActivity() { val start2 = tip.indexOf("付") + 1 val end2 = tip.indexOf("元") val spannableString = SpannableString(tip) - val colorSpan = ForegroundColorSpan(Color.parseColor("#0099EE")) - val colorSpan2 = ForegroundColorSpan(Color.parseColor("#0099EE")) + val colorSpan = ForegroundColorSpan(color) + val colorSpan2 = ForegroundColorSpan(color) spannableString.setSpan( colorSpan, start, diff --git a/app/src/main/java/com/coldmint/rust/pro/RegisterActivity.kt b/app/src/main/java/com/coldmint/rust/pro/RegisterActivity.kt index 534de0a..e366e52 100644 --- a/app/src/main/java/com/coldmint/rust/pro/RegisterActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/RegisterActivity.kt @@ -8,12 +8,11 @@ import android.view.LayoutInflater import com.coldmint.rust.pro.base.BaseActivity import android.view.View import androidx.core.view.isVisible +import com.coldmint.dialog.CoreDialog import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.tool.GlobalMethod import com.coldmint.rust.core.interfaces.ApiCallBack import com.coldmint.rust.core.web.ServerConfiguration -import com.afollestad.materialdialogs.MaterialDialog -import com.afollestad.materialdialogs.input.input import com.coldmint.rust.core.dataBean.ApiResponse import com.coldmint.rust.core.dataBean.RegisterRequestData import com.coldmint.rust.core.web.User @@ -164,12 +163,11 @@ class RegisterActivity : BaseActivity() { AppSettings.forceSetValue(AppSettings.Setting.Account, account) AppSettings.forceSetValue(AppSettings.Setting.PassWord, passWord) AppSettings.forceSetValue(AppSettings.Setting.UserName, userName) - MaterialDialog(this@RegisterActivity).show { - title(R.string.register_successed).message(R.string.registration_success_message) - .cancelable(false).positiveButton(R.string.close) { - finish() - } - } + CoreDialog(this@RegisterActivity).setTitle(R.string.register_successed) + .setMessage(R.string.registration_success_message) + .setCancelable(false).setPositiveButton(R.string.close) { + finish() + }.show() } else { val data = apiResponse.data if (data != null && ServerConfiguration.isEvent(data)) { diff --git a/app/src/main/java/com/coldmint/rust/pro/ReleaseModActivity.kt b/app/src/main/java/com/coldmint/rust/pro/ReleaseModActivity.kt index ab1ad04..6f9cf35 100644 --- a/app/src/main/java/com/coldmint/rust/pro/ReleaseModActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/ReleaseModActivity.kt @@ -15,15 +15,9 @@ import android.widget.Toast import androidx.core.view.isVisible import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView -import androidx.recyclerview.widget.SnapHelper -import com.afollestad.materialdialogs.MaterialDialog -import com.afollestad.materialdialogs.WhichButton -import com.afollestad.materialdialogs.actions.setActionButtonEnabled -import com.afollestad.materialdialogs.customview.customView -import com.afollestad.materialdialogs.input.getInputField -import com.afollestad.materialdialogs.input.input -import com.afollestad.materialdialogs.list.listItems import com.bumptech.glide.Glide +import com.coldmint.dialog.CoreDialog +import com.coldmint.dialog.InputDialog import com.coldmint.rust.core.CompressionManager import com.coldmint.rust.core.ModClass import com.coldmint.rust.core.ModConfigurationManager @@ -45,6 +39,8 @@ import com.coldmint.rust.pro.tool.GlobalMethod import com.coldmint.rust.pro.base.BaseActivity import com.coldmint.rust.pro.databinding.LoadFileLayoutBinding import com.github.promeg.pinyinhelper.Pinyin +import com.google.android.material.chip.Chip +import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.snackbar.Snackbar import com.gyf.immersionbar.ktx.fitsStatusBarView import com.yalantis.ucrop.UCrop @@ -63,9 +59,10 @@ class ReleaseModActivity : BaseActivity() { private val list by lazy { ArrayList() } - private val tags by lazy { - ArrayList() - } + + // private val tags by lazy { +// ArrayList() +// } lateinit var screenshotAdapter: ScreenshotAdapter private var modClass: ModClass? = null private var iconLink: String? = null @@ -122,12 +119,12 @@ class ReleaseModActivity : BaseActivity() { showError("模组id为空") return } - val account = AppSettings.getValue(AppSettings.Setting.Account, "") - if (account.isBlank()) { + val token = AppSettings.getValue(AppSettings.Setting.Token, "") + if (token.isBlank()) { showError(getString(R.string.please_login_first)) return } - WebMod.instance.getInfo(account, modId, object : ApiCallBack { + WebMod.instance.getInfo(token, modId, object : ApiCallBack { override fun onResponse(t: WebModInfoData) { if (t.code == ServerConfiguration.Success_Code) { loadLoadModeAction(t) @@ -296,47 +293,44 @@ class ReleaseModActivity : BaseActivity() { viewBinding.addScreenshotButton.setOnClickListener { val fromUrl = getString(R.string.from_url) val selectImage = getString(R.string.select_image) - MaterialDialog(this).show { - title(R.string.add).listItems( - R.array.screenshot_addType, - waitForPositiveButton = false - ) { dialog: MaterialDialog, index: Int, text: CharSequence -> - when (text) { - fromUrl -> { - MaterialDialog(this@ReleaseModActivity).show { - title(R.string.from_url).message(R.string.from_url_tip) - input(waitForPositiveButton = false) { dialog, text -> - if (text.matches(Regex("^http://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$|^https://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$"))) { - dialog.setActionButtonEnabled(WhichButton.POSITIVE, true) - } else { - dialog.setActionButtonEnabled(WhichButton.POSITIVE, false) - } - }.positiveButton(R.string.dialog_ok, null) { dialog -> - val input = dialog.getInputField().text.toString() - screenshotAdapter.addItem(input) - }.negativeButton(R.string.dialog_close) - } - } - selectImage -> { - val startIntent = - Intent(this@ReleaseModActivity, FileManagerActivity::class.java) - val fileBundle = Bundle() - if (modClass != null) { - fileBundle.putString("path", modClass!!.modFile.absolutePath) - } - fileBundle.putString("type", "selectFile") - startIntent.putExtra("data", fileBundle) - startActivityForResult(startIntent, 2) - } - else -> { - Toast.makeText(this@ReleaseModActivity, "未知的操作", Toast.LENGTH_SHORT) - .show() - } + val array = resources.getStringArray(R.array.screenshot_addType) + MaterialAlertDialogBuilder(this).setTitle(R.string.add).setItems(array) { i, i2 -> + val text = array[i2] + when (text) { + fromUrl -> { + InputDialog(this).setTitle(R.string.from_url) + .setMessage(R.string.from_url_tip).setErrorTip { s, textInputLayout -> + if (s.matches(Regex("^http://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$|^https://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$"))) { + textInputLayout.error = getString(R.string.from_url_tip) + } else { + textInputLayout.isErrorEnabled = false + } + }.setPositiveButton(R.string.dialog_ok) { input -> + screenshotAdapter.addItem(input) + true + }.setNegativeButton(R.string.dialog_close) { + }.show() } - dialog.dismiss() - }.positiveButton(R.string.dialog_cancel) - } + selectImage -> { + val startIntent = + Intent(this@ReleaseModActivity, FileManagerActivity::class.java) + val fileBundle = Bundle() + if (modClass != null) { + fileBundle.putString("path", modClass!!.modFile.absolutePath) + } + fileBundle.putString("type", "selectFile") + startIntent.putExtra("data", fileBundle) + startActivityForResult(startIntent, 2) + } + else -> { + Toast.makeText(this@ReleaseModActivity, "未知的操作", Toast.LENGTH_SHORT) + .show() + } + + } + }.setPositiveButton(R.string.dialog_cancel) { i1, i2 -> + }.show() } @@ -381,19 +375,33 @@ class ReleaseModActivity : BaseActivity() { val tag = s.toString() checkModTag(tag) lineParser.text = tag - tags.clear() + var isNotEmpty = false +// tags.clear() + viewBinding.chipGroup.removeAllViews() lineParser.analyse { lineNum, lineData, isEnd -> + isNotEmpty = true if (lineData.isNotBlank()) { - tags.add(lineData) +// tags.add(lineData) + val chip = Chip(this@ReleaseModActivity) + chip.text = lineData + chip.setOnClickListener { + val bundle = Bundle() + bundle.putString("tag", lineData) + bundle.putString( + "title", + String.format(getString(R.string.tag_title), s) + ) + bundle.putString("action", "tag") + val thisIntent = + Intent(this@ReleaseModActivity, TagActivity::class.java) + thisIntent.putExtra("data", bundle) + startActivity(thisIntent) + } + viewBinding.chipGroup.addView(chip) } true } - if (tags.size > 0) { - viewBinding.belongStackLabelView.labels = tags - viewBinding.belongStackLabelView.isVisible = true - } else { - viewBinding.belongStackLabelView.isVisible = false - } + viewBinding.chipGroup.isVisible = isNotEmpty } }) @@ -427,19 +435,6 @@ class ReleaseModActivity : BaseActivity() { ) ) - viewBinding.belongStackLabelView.setOnLabelClickListener { index, v, s -> - val bundle = Bundle() - bundle.putString("tag", s) - bundle.putString( - "title", - String.format(getString(R.string.tag_title), s) - ) - bundle.putString("action", "tag") - val thisIntent = - Intent(this, TagActivity::class.java) - thisIntent.putExtra("data", bundle) - startActivity(thisIntent) - } } private fun selectModFile() { @@ -476,19 +471,19 @@ class ReleaseModActivity : BaseActivity() { startIntent.putExtra("data", fileBundle) startActivityForResult(startIntent, 3) } else if (title == getString(R.string.from_url)) { - MaterialDialog(this).show { - title(R.string.from_url).message(R.string.from_url_tip) - input(waitForPositiveButton = false) { dialog, text -> - if (text.matches(Regex("^http://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$|^https://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$"))) { - dialog.setActionButtonEnabled(WhichButton.POSITIVE, true) + InputDialog(this).setTitle(R.string.from_url).setMessage(R.string.from_url_tip) + .setErrorTip { s, textInputLayout -> + if (s.matches(Regex("^http://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$|^https://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$"))) { + textInputLayout.error = getString(R.string.from_url_tip) } else { - dialog.setActionButtonEnabled(WhichButton.POSITIVE, false) + textInputLayout.isErrorEnabled = false } - }.positiveButton(R.string.dialog_ok, null) { dialog -> - val input = dialog.getInputField().text.toString() + }.setPositiveButton(R.string.dialog_ok) { input -> loadIcon(input) - }.negativeButton(R.string.dialog_close) - } + true + }.setNegativeButton(R.string.dialog_close) { + + }.show() } else { val link = iconLink if (link != null) { @@ -767,33 +762,32 @@ class ReleaseModActivity : BaseActivity() { ) } else { releaseModWork( - modId, account, modName, modDescribe, versionName, + modId, modName, modDescribe, versionName, tagsBuilder, file ) } } else { - MaterialDialog(this).show { - title(R.string.using_mobile_networks).message(R.string.using_mobile_networks_msg) - .positiveButton(R.string.only_one) { - if (isUpdateMode) { - updateModWork( - modId, - account, - modName, - modDescribe, - updateLog, - versionName, - tagsBuilder, - file - ) - } else { - releaseModWork( - modId, account, modName, modDescribe, versionName, - tagsBuilder, file - ) - } + CoreDialog(this).setTitle(R.string.using_mobile_networks) + .setMessage(R.string.using_mobile_networks_msg) + .setPositiveButton(R.string.only_one) { + if (isUpdateMode) { + updateModWork( + modId, + account, + modName, + modDescribe, + updateLog, + versionName, + tagsBuilder, + file + ) + } else { + releaseModWork( + modId, modName, modDescribe, versionName, + tagsBuilder, file + ) } - negativeButton(R.string.always_allow) { + }.setNegativeButton(R.string.always_allow) { AppSettings.setValue(AppSettings.Setting.UseMobileNetwork, true) if (isUpdateMode) { updateModWork( @@ -808,15 +802,13 @@ class ReleaseModActivity : BaseActivity() { ) } else { releaseModWork( - modId, account, modName, modDescribe, versionName, + modId, modName, modDescribe, versionName, tagsBuilder, file ) } - } - neutralButton(R.string.dialog_cancel) { + }.setNeutralButton(R.string.dialog_cancel) { - } - } + }.show() } } AppOperator.NetWorkType.NetWorkType_Wifi -> { @@ -833,7 +825,7 @@ class ReleaseModActivity : BaseActivity() { ) } else { releaseModWork( - modId, account, modName, modDescribe, versionName, + modId, modName, modDescribe, versionName, tagsBuilder, file ) } @@ -853,7 +845,6 @@ class ReleaseModActivity : BaseActivity() { */ fun releaseModWork( modId: String, - account: String, modName: String, modDescribe: String, versionName: String, @@ -861,11 +852,10 @@ class ReleaseModActivity : BaseActivity() { ) { val loadFileLayoutBinding = LoadFileLayoutBinding.inflate(layoutInflater) loadFileLayoutBinding.LinearProgressIndicator.max = 100 + val dialog = MaterialAlertDialogBuilder(this).setTitle(R.string.release) + .setView(loadFileLayoutBinding.root).setPositiveButton(R.string.dialog_ok) { i1, i2 -> + }.setCancelable(false).show() - val dialog = MaterialDialog(this).show { - title(R.string.release).customView(view = loadFileLayoutBinding.root) - .positiveButton(R.string.dialog_ok).cancelable(false) - } WebMod.instance.releaseMod(AppSettings.getValue(AppSettings.Setting.AppID, ""), modId, AppSettings.getValue(AppSettings.Setting.Token, ""), modName, @@ -904,15 +894,11 @@ class ReleaseModActivity : BaseActivity() { }) } - - MaterialDialog(this@ReleaseModActivity).show { - title(R.string.release).message( - text = t.message - ).positiveButton(R.string.dialog_ok).cancelable(false) - .positiveButton { - finish() - } - } + CoreDialog(this@ReleaseModActivity).setTitle(R.string.release) + .setMessage(t.message).setCancelable(false) + .setPositiveButton(R.string.dialog_ok) { + finish() + }.show() } else { handleEvent(t) } @@ -965,10 +951,11 @@ class ReleaseModActivity : BaseActivity() { val loadFileLayoutBinding = LoadFileLayoutBinding.inflate(layoutInflater) loadFileLayoutBinding.LinearProgressIndicator.max = 100 - val dialog = MaterialDialog(this).show { - title(R.string.release).customView(view = loadFileLayoutBinding.root) - .positiveButton(R.string.dialog_ok).cancelable(false) - } + val dialog = MaterialAlertDialogBuilder(this).setTitle(R.string.release) + .setView(loadFileLayoutBinding.root).setPositiveButton(R.string.dialog_ok) { i1, i2 -> + }.setCancelable(false).show() + + WebMod.instance.updateMod(AppSettings.getValue(AppSettings.Setting.AppID, ""), modId, account, modName, @@ -1014,14 +1001,11 @@ class ReleaseModActivity : BaseActivity() { }) } - MaterialDialog(this@ReleaseModActivity).show { - title(R.string.release).message( - text = t.message - ).positiveButton(R.string.dialog_ok).cancelable(false) - .positiveButton { - finish() - } - } + CoreDialog(this@ReleaseModActivity).setTitle(R.string.release).setMessage( + t.message + ).setPositiveButton(R.string.dialog_ok) { + finish() + }.setCancelable(false).show() } else { handleEvent(t) } @@ -1103,7 +1087,6 @@ class ReleaseModActivity : BaseActivity() { } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (data == null) { diff --git a/app/src/main/java/com/coldmint/rust/pro/ReportActivity.kt b/app/src/main/java/com/coldmint/rust/pro/ReportActivity.kt index 0027962..c22f464 100644 --- a/app/src/main/java/com/coldmint/rust/pro/ReportActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/ReportActivity.kt @@ -5,7 +5,6 @@ import android.text.Editable import android.text.TextWatcher import android.view.LayoutInflater import android.widget.ArrayAdapter -import com.afollestad.materialdialogs.MaterialDialog import com.coldmint.rust.core.dataBean.ApiResponse import com.coldmint.rust.core.interfaces.ApiCallBack import com.coldmint.rust.core.web.Report diff --git a/app/src/main/java/com/coldmint/rust/pro/SettingsActivity.kt b/app/src/main/java/com/coldmint/rust/pro/SettingsActivity.kt index d1543ce..d10d6d2 100644 --- a/app/src/main/java/com/coldmint/rust/pro/SettingsActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/SettingsActivity.kt @@ -11,15 +11,18 @@ import android.view.LayoutInflater import android.widget.Toast import androidx.appcompat.app.AppCompatDelegate import androidx.preference.* -import com.afollestad.materialdialogs.MaterialDialog -import com.afollestad.materialdialogs.list.listItemsMultiChoice import com.bumptech.glide.Glide import com.coldmint.rust.core.tool.FileOperator import com.coldmint.rust.pro.databinding.ActivitySettingsBinding import com.coldmint.rust.pro.tool.GlobalMethod import com.google.android.material.color.DynamicColors +import com.google.android.material.dialog.MaterialAlertDialogBuilder +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Job +import kotlinx.coroutines.launch import java.io.File import java.util.* +import kotlin.collections.ArrayList import kotlin.concurrent.thread class SettingsActivity : BaseActivity() { @@ -98,16 +101,26 @@ class SettingsActivity : BaseActivity() { manager.findPreference(getString(R.string.setting_clear_cache)) clearCache!!.onPreferenceClickListener = Preference.OnPreferenceClickListener { + val items = ArrayList() val listData = listOf( getString(R.string.history_cache), getString(R.string.code_cache), getString(R.string.glide_cache) ) - MaterialDialog(requireContext()).show { - title(R.string.clear_cache).listItemsMultiChoice(items = listData) - { dialog, indices, items -> + MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.clear_cache) + .setMultiChoiceItems(listData.toTypedArray(), null) { dialog, index, bool -> + val string = listData[index] + if (bool) { + items.add(string) + } else { + items.remove(string) + } + } + .setPositiveButton(R.string.dialog_ok) { i, i2 -> val handler = Handler(Looper.getMainLooper()) - thread { + val job = Job() + val scope = CoroutineScope(job) + scope.launch { if (items.isNotEmpty()) { for (item in items) { when (item) { @@ -146,8 +159,10 @@ class SettingsActivity : BaseActivity() { } } } - }.positiveButton(R.string.dialog_ok).negativeButton(R.string.dialog_cancel) - } + + }.setNegativeButton(R.string.dialog_cancel) { i, i2 -> + }.show() + true } diff --git a/app/src/main/java/com/coldmint/rust/pro/TemplateMakerActivity.kt b/app/src/main/java/com/coldmint/rust/pro/TemplateMakerActivity.kt index 11e57d6..4cfa20e 100644 --- a/app/src/main/java/com/coldmint/rust/pro/TemplateMakerActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/TemplateMakerActivity.kt @@ -15,9 +15,6 @@ import android.os.Looper import android.view.* import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.get -import com.afollestad.materialdialogs.MaterialDialog -import com.afollestad.materialdialogs.bottomsheets.BottomSheet -import com.afollestad.materialdialogs.list.listItemsMultiChoice import com.coldmint.dialog.CoreDialog import com.coldmint.rust.core.LocalTemplatePackage import com.coldmint.rust.core.interfaces.LineParserEvent diff --git a/app/src/main/java/com/coldmint/rust/pro/TemplateParserActivity.kt b/app/src/main/java/com/coldmint/rust/pro/TemplateParserActivity.kt index a050515..50c0da6 100644 --- a/app/src/main/java/com/coldmint/rust/pro/TemplateParserActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/TemplateParserActivity.kt @@ -22,7 +22,6 @@ import android.view.inputmethod.InputMethodManager import android.widget.* import androidx.core.view.isVisible import androidx.lifecycle.viewModelScope -import com.afollestad.materialdialogs.MaterialDialog import com.coldmint.dialog.CoreDialog import com.coldmint.rust.core.LocalTemplatePackage import com.coldmint.rust.core.dataBean.InputParserDataBean @@ -113,7 +112,9 @@ class TemplateParserActivity : BaseActivity() { if (name.isNotBlank()) { val build = viewModel.buildFile(this, name) if (build) { - setResult(RESULT_OK) + val data = Intent() + data.putExtra("File", viewModel.getOutputPath()) + setResult(RESULT_OK, data) finish() } else { Snackbar.make( diff --git a/app/src/main/java/com/coldmint/rust/pro/ThanksActivity.kt b/app/src/main/java/com/coldmint/rust/pro/ThanksActivity.kt index 25b2cc0..82b5f89 100644 --- a/app/src/main/java/com/coldmint/rust/pro/ThanksActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/ThanksActivity.kt @@ -24,11 +24,13 @@ class ThanksActivity : BaseActivity() { if (canUseView) { title = getString(R.string.special_thanks_to) setReturnButton() + val divider = MaterialDividerItemDecoration( + this, + MaterialDividerItemDecoration.VERTICAL + ) + viewBinding.recyclerView.addItemDecoration( - DividerItemDecoration( - this, - DividerItemDecoration.VERTICAL - ) + divider ) viewBinding.recyclerView.layoutManager = LinearLayoutManager(this) val list = ArrayList() diff --git a/app/src/main/java/com/coldmint/rust/pro/UnitsActivity.kt b/app/src/main/java/com/coldmint/rust/pro/UnitsActivity.kt index a2fae81..d335363 100644 --- a/app/src/main/java/com/coldmint/rust/pro/UnitsActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/UnitsActivity.kt @@ -12,12 +12,7 @@ import com.google.android.material.snackbar.Snackbar import android.view.* import android.widget.* import androidx.core.view.isVisible -import com.afollestad.materialdialogs.MaterialDialog -import com.afollestad.materialdialogs.WhichButton -import com.afollestad.materialdialogs.actions.setActionButtonEnabled -import com.afollestad.materialdialogs.customview.customView -import com.afollestad.materialdialogs.input.getInputField -import com.afollestad.materialdialogs.input.input +import com.coldmint.dialog.InputDialog import com.coldmint.rust.core.database.code.CodeDataBase import com.coldmint.rust.core.tool.FileOperator import com.coldmint.rust.pro.adapters.ModPageAdapter @@ -77,21 +72,19 @@ class UnitsActivity : BaseActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.filter_units -> { - MaterialDialog(this).show { - title(R.string.filter).message(R.string.filter_tip) - input(maxLength = 20, waitForPositiveButton = false) { dialog, text -> - if (text.isNotEmpty()) { - dialog.setActionButtonEnabled(WhichButton.POSITIVE, true) - } - }.positiveButton(R.string.dialog_ok, null) { dialog -> - var key = dialog.getInputField().text.toString() + InputDialog(this).setTitle(R.string.filter).setMessage(R.string.filter_tip) + .setHint(R.string.key_word) + .setMaxNumber(20).setInputCanBeEmpty(false) + .setPositiveButton(R.string.dialog_ok) { text -> + var key = text if (key.length > 20) { key = key.substring(0, 20) } viewBinding.tabLayout.selectTab(viewBinding.tabLayout.getTabAt(1)) modPageAdapter.allUnitsFragment.filter(key) - }.negativeButton(R.string.dialog_close) - } + true + }.setNegativeButton(R.string.dialog_cancel) { + }.show() } R.id.search_units -> { viewBinding.tabLayout.selectTab(viewBinding.tabLayout.getTabAt(1)) @@ -155,23 +148,21 @@ class UnitsActivity : BaseActivity() { } }) - MaterialDialog(this).show { - title(R.string.search) - customView(view = dialogSearchUnitsBinding.root) - .positiveButton(R.string.dialog_ok).positiveButton { - modPageAdapter.allUnitsFragment.advancedSearch( - configuration = AllUnitsFragment.SearchConfiguration( - dialogSearchUnitsBinding.unitNameInputView.text.toString(), - dialogSearchUnitsBinding.fileNameInputView.text.toString(), - dialogSearchUnitsBinding.matchesFileNamesByReBox.isChecked, - dialogSearchUnitsBinding.fileContentInputView.text.toString(), - dialogSearchUnitsBinding.advancedSearchBox.isChecked, - dialogSearchUnitsBinding.isCodeBox.isChecked - ) + MaterialAlertDialogBuilder(this).setTitle(R.string.search) + .setView(dialogSearchUnitsBinding.root) + .setPositiveButton(R.string.dialog_ok) { i, i1 -> + modPageAdapter.allUnitsFragment.advancedSearch( + configuration = AllUnitsFragment.SearchConfiguration( + dialogSearchUnitsBinding.unitNameInputView.text.toString(), + dialogSearchUnitsBinding.fileNameInputView.text.toString(), + dialogSearchUnitsBinding.matchesFileNamesByReBox.isChecked, + dialogSearchUnitsBinding.fileContentInputView.text.toString(), + dialogSearchUnitsBinding.advancedSearchBox.isChecked, + dialogSearchUnitsBinding.isCodeBox.isChecked ) - } - .negativeButton(R.string.dialog_close) - } + ) + }.setNegativeButton(R.string.dialog_close) { i1, i2 -> + }.show() } R.id.rebuild -> { MaterialAlertDialogBuilder(this).setTitle(R.string.rebuild_project) diff --git a/app/src/main/java/com/coldmint/rust/pro/UserHomePageActivity.kt b/app/src/main/java/com/coldmint/rust/pro/UserHomePageActivity.kt index ee3c555..bc1c21b 100644 --- a/app/src/main/java/com/coldmint/rust/pro/UserHomePageActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/UserHomePageActivity.kt @@ -12,16 +12,14 @@ import android.view.LayoutInflater import android.view.View import android.view.inputmethod.EditorInfo import android.widget.EditText +import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.core.view.isVisible -import com.afollestad.materialdialogs.LayoutMode -import com.afollestad.materialdialogs.MaterialDialog -import com.afollestad.materialdialogs.bottomsheets.BottomSheet -import com.afollestad.materialdialogs.input.getInputField -import com.afollestad.materialdialogs.input.input import com.bumptech.glide.Glide +import com.coldmint.dialog.CoreDialog import com.coldmint.rust.core.dataBean.ApiResponse import com.coldmint.rust.core.dataBean.user.SpaceInfoData import com.coldmint.rust.core.interfaces.ApiCallBack +import com.coldmint.rust.core.tool.DebugHelper import com.coldmint.rust.core.web.* import com.coldmint.rust.pro.adapters.UserHomeStateAdapter import com.coldmint.rust.pro.base.BaseActivity @@ -34,6 +32,7 @@ import com.google.android.material.appbar.CollapsingToolbarLayout import com.google.android.material.snackbar.Snackbar import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayoutMediator +import com.gyf.immersionbar.ImmersionBar import com.gyf.immersionbar.ktx.immersionBar @@ -53,10 +52,26 @@ class UserHomePageActivity : BaseActivity() { @SuppressLint("CheckResult") private fun initView() { -// immersionBar { -// transparentStatusBar().statusBarDarkFont(true) -// .navigationBarDarkIcon(true) -// } + if (ImmersionBar.hasNavigationBar(this)) { + val layoutParams = + viewBinding.fab.layoutParams as CoordinatorLayout.LayoutParams + layoutParams.setMargins( + GlobalMethod.dp2px(16), + GlobalMethod.dp2px(16), + GlobalMethod.dp2px(16), + ImmersionBar.getNavigationBarHeight(this) + GlobalMethod.dp2px(16) + ) + DebugHelper.printLog("导航适配", "已调整fab按钮的位置。") + } + val s = ImmersionBar.getStatusBarHeight(this) + val layoutParams = + viewBinding.toolbar.layoutParams as CollapsingToolbarLayout.LayoutParams + layoutParams.setMargins( + 0, + s, + 0, + 0 + ) val thisIntent = intent val temUserId = thisIntent.getStringExtra("userId") @@ -84,17 +99,6 @@ class UserHomePageActivity : BaseActivity() { openUserList(userId, false) } initButton() -// val dlist = ArrayList() -// for (i in 1..30) { -//// dlist.add(getDrawable(R.drawable.emoji_2_3)!!) -// dlist.add(getDrawable(R.drawable.emoji_1_3)!!) -// } -// viewBinding.bubbleView.setDrawableList(dlist) -// viewBinding.bubbleView.startAnimation(5000, 5000,30) -// viewBinding.emojiRainLayout.addEmoji(R.drawable.emoji_1_3) -// viewBinding.emojiRainLayout.addEmoji(R.drawable.emoji_2_3) -// viewBinding.emojiRainLayout.addEmoji(R.drawable.emoji_3_3) -// viewBinding.emojiRainLayout.startDropping() } @@ -231,7 +235,6 @@ class UserHomePageActivity : BaseActivity() { val cover = spaceInfoData.data.cover if (cover != null) { Glide.with(this).load(ServerConfiguration.getRealLink(cover)) - .apply(GlobalMethod.getRequestOptions()) .into(viewBinding.coverView) } @@ -429,50 +432,49 @@ class UserHomePageActivity : BaseActivity() { } getString(R.string.followed), getString(R.string.each_other_follow) -> { val de = String.format(getString(R.string.defollow_tip), userName ?: userId) - MaterialDialog(this).show { - title(R.string.defollow).message(text = de) - .positiveButton(R.string.dialog_ok).positiveButton { - viewBinding.button.setBackgroundColor( - GlobalMethod.getThemeColor( - this@UserHomePageActivity, - R.attr.colorPrimaryVariant - ) + CoreDialog(this).setTitle(R.string.defollow).setMessage(de) + .setPositiveButton(R.string.dialog_ok) { + viewBinding.button.setBackgroundColor( + GlobalMethod.getThemeColor( + this@UserHomePageActivity, + R.attr.colorPrimaryVariant ) - viewBinding.button.setText(R.string.request_data) - Community.deFollow( - account, - userId, - object : ApiCallBack { - override fun onResponse(t: ApiResponse) { - viewBinding.button.setBackgroundColor( - GlobalMethod.getColorPrimary( - this@UserHomePageActivity - ) + ) + viewBinding.button.setText(R.string.request_data) + Community.deFollow( + account, + userId, + object : ApiCallBack { + override fun onResponse(t: ApiResponse) { + viewBinding.button.setBackgroundColor( + GlobalMethod.getColorPrimary( + this@UserHomePageActivity ) - if (t.code == ServerConfiguration.Success_Code) { - fans-- - viewBinding.fansNumView.text = - ServerConfiguration.numberToString(fans) - viewBinding.button.text = - getString(R.string.follow) - } else { - Snackbar.make( - viewBinding.button, - t.message, - Snackbar.LENGTH_SHORT - ).show() - viewBinding.button.text = type - } + ) + if (t.code == ServerConfiguration.Success_Code) { + fans-- + viewBinding.fansNumView.text = + ServerConfiguration.numberToString(fans) + viewBinding.button.text = + getString(R.string.follow) + } else { + Snackbar.make( + viewBinding.button, + t.message, + Snackbar.LENGTH_SHORT + ).show() + viewBinding.button.text = type } + } - override fun onFailure(e: Exception) { - showInternetError(viewBinding.button, e) - } + override fun onFailure(e: Exception) { + showInternetError(viewBinding.button, e) + } - }) - } + }) + }.setNegativeButton(R.string.dialog_cancel) { - }.negativeButton(R.string.dialog_cancel) + }.show() } getString(R.string.editData) -> { val intent = Intent(this, EditUserInfoActivity::class.java) diff --git a/app/src/main/java/com/coldmint/rust/pro/UserListActivity.kt b/app/src/main/java/com/coldmint/rust/pro/UserListActivity.kt index 442049f..59d2ffc 100644 --- a/app/src/main/java/com/coldmint/rust/pro/UserListActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/UserListActivity.kt @@ -20,6 +20,7 @@ import com.coldmint.rust.core.web.ServerConfiguration import com.coldmint.rust.pro.adapters.UserAdapter import com.coldmint.rust.pro.base.BaseActivity import com.coldmint.rust.pro.databinding.ActivityUserListBinding +import com.google.android.material.divider.MaterialDividerItemDecoration import com.google.android.material.snackbar.Snackbar class UserListActivity : BaseActivity() { @@ -70,11 +71,13 @@ class UserListActivity : BaseActivity() { } viewBinding.recyclerView.layoutManager = LinearLayoutManager(this@UserListActivity) + val divider = MaterialDividerItemDecoration( + this, + MaterialDividerItemDecoration.VERTICAL + ) + viewBinding.recyclerView.addItemDecoration( - DividerItemDecoration( - this, - DividerItemDecoration.VERTICAL - ) + divider ) loadList(account, isFollowMode, canRemoveFans) } diff --git a/app/src/main/java/com/coldmint/rust/pro/ValueTypeActivity.kt b/app/src/main/java/com/coldmint/rust/pro/ValueTypeActivity.kt index 3be3453..51a6500 100644 --- a/app/src/main/java/com/coldmint/rust/pro/ValueTypeActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/ValueTypeActivity.kt @@ -290,7 +290,7 @@ class ValueTypeActivity : BaseActivity() { override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { if (canUseView) { - viewBinding.toolbar.title = getText(R.string.value_type_manager) + title = getText(R.string.value_type_manager) viewBinding.valueList.layoutManager = LinearLayoutManager(this@ValueTypeActivity) setReturnButton() loadList() diff --git a/app/src/main/java/com/coldmint/rust/pro/WorkManagementActivity.kt b/app/src/main/java/com/coldmint/rust/pro/WorkManagementActivity.kt index 365a75b..f60c472 100644 --- a/app/src/main/java/com/coldmint/rust/pro/WorkManagementActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/WorkManagementActivity.kt @@ -23,6 +23,7 @@ import com.coldmint.rust.pro.base.BaseActivity import com.coldmint.rust.pro.databinding.ActivityWorkmangementBinding import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.tool.GlobalMethod +import com.google.android.material.divider.MaterialDividerItemDecoration import com.google.android.material.snackbar.Snackbar /** @@ -259,11 +260,13 @@ class WorkManagementActivity : BaseActivity() { title = getString(R.string.work_management) setReturnButton() viewBinding.recyclerView.layoutManager = LinearLayoutManager(this) + val divider = MaterialDividerItemDecoration( + this, + MaterialDividerItemDecoration.VERTICAL + ) + viewBinding.recyclerView.addItemDecoration( - DividerItemDecoration( - this, - DividerItemDecoration.VERTICAL - ) + divider ) } } diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/CodeTableAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/CodeTableAdapter.kt index 4cab753..cf7eec7 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/CodeTableAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/CodeTableAdapter.kt @@ -2,7 +2,6 @@ package com.coldmint.rust.pro.adapters import android.widget.BaseExpandableListAdapter import android.view.LayoutInflater -import com.kongzue.stacklabelview.interfaces.OnLabelClickListener import android.view.ViewGroup import com.coldmint.rust.pro.R import android.content.Context @@ -20,6 +19,7 @@ import com.coldmint.rust.pro.databinding.CodeTableGroupBinding import com.coldmint.rust.pro.databinding.CodeTableItemBinding import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.tool.GlobalMethod +import com.google.android.material.chip.Chip import java.util.concurrent.Executors class CodeTableAdapter( @@ -131,9 +131,9 @@ class CodeTableAdapter( val resultView: CodeTableItemBinding = CodeTableItemBinding.inflate(layoutInflater, parent, false) val codeInfo = itemList[groupPosition][childPosition] - resultView.belongStackLabelView.onLabelClickListener = OnLabelClickListener { index, v, s -> - labelFunction?.invoke(index, v, s) - } + +// resultView.belongStackLabelView.onLabelClickListener = OnLabelClickListener { index, v, s -> +// } resultView.descriptionView.text = codeInfo.description resultView.descriptionView.setOnClickListener { GlobalMethod.copyText(context, codeInfo.description, it) @@ -147,13 +147,22 @@ class CodeTableAdapter( GlobalMethod.copyText(context, codeInfo.code, it) } resultView.valueTypeView.text = typeNameMap?.get(codeInfo.type) ?: codeInfo.type - val list = ArrayList() lineParser.text = codeInfo.section + resultView.chipGroup.removeAllViews() + var isNotEmpty = false lineParser.analyse { lineNum, lineData, isEnd -> - list.add(sectionMap?.get(lineData) ?: lineData) + isNotEmpty = true + val text = sectionMap?.get(lineData) ?: lineData + val chip = Chip(context) + chip.text = text + chip.setOnClickListener { + labelFunction?.invoke(lineNum, it, text ) + } + resultView.chipGroup.addView(chip) + true } - resultView.belongStackLabelView.isVisible = list.isNotEmpty() - resultView.belongStackLabelView.labels = list + + resultView.chipGroup.isVisible = isNotEmpty resultView.valueTypeView.setOnClickListener { val handler = Handler(Looper.getMainLooper()) executorService.submit { diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/LibAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/LibAdapter.kt index f99fdc0..58dbb53 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/LibAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/LibAdapter.kt @@ -9,7 +9,6 @@ import android.content.Intent import android.net.Uri import android.view.View import android.widget.ImageView -import com.afollestad.materialdialogs.MaterialDialog import android.widget.TextView import androidx.core.view.isVisible import com.coldmint.rust.pro.base.BaseAdapter diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateListAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateListAdapter.kt index 36fd9ba..6a328af 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateListAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateListAdapter.kt @@ -24,6 +24,7 @@ import com.coldmint.rust.pro.base.BaseAdapter import com.coldmint.rust.pro.databinding.TemplateBottomDialogBinding import com.coldmint.rust.pro.databinding.TemplateListItemBinding import com.google.android.material.bottomsheet.BottomSheetDialog +import com.google.android.material.divider.MaterialDividerItemDecoration import java.io.File class TemplateListAdapter( @@ -316,11 +317,13 @@ class TemplateListAdapter( } } templateBottomDialogBinding.templateActionList.adapter = adapter + val divider = MaterialDividerItemDecoration( + context, + MaterialDividerItemDecoration.VERTICAL + ) + templateBottomDialogBinding.templateActionList.addItemDecoration( - DividerItemDecoration( - context, - DividerItemDecoration.VERTICAL - ) + divider ) bottomSheetDialog.show() } diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/UnitAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/UnitAdapter.kt index c0e3dfc..262fe83 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/UnitAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/UnitAdapter.kt @@ -13,15 +13,18 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy import com.coldmint.rust.pro.base.BaseAdapter import com.coldmint.rust.pro.databinding.UnitItemBinding import com.coldmint.rust.pro.tool.GlobalMethod +import me.zhanghai.android.fastscroll.PopupTextProvider import java.text.SimpleDateFormat import java.util.* import kotlin.Exception class UnitAdapter( - context: Context, + context: Context, dataList: MutableList, val key: String -) : BaseAdapter(context, dataList) { +) : BaseAdapter(context, dataList), PopupTextProvider { + + private val language: String by lazy { AppSettings.getValue( @@ -29,8 +32,15 @@ class UnitAdapter( Locale.getDefault().language ) } + private val formatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss") + init { + dataList.sortBy { + getInitial(it.getName(language)) + } + } + override fun getViewBindingObject( layoutInflater: LayoutInflater, parent: ViewGroup, @@ -82,5 +92,9 @@ class UnitAdapter( } } + override fun getPopupText(position: Int): String { + return getInitial(dataList[position].getName(language)).toString() + } + } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/WebModAllInfoAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/WebModAllInfoAdapter.kt index c576ed8..b7d3c08 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/WebModAllInfoAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/WebModAllInfoAdapter.kt @@ -5,7 +5,6 @@ import android.content.ServiceConnection import android.view.LayoutInflater import android.view.ViewGroup import android.widget.PopupMenu -import com.afollestad.materialdialogs.MaterialDialog import com.bumptech.glide.Glide import com.coldmint.rust.core.dataBean.ApiResponse import com.coldmint.rust.core.dataBean.mod.WebModAllInfoData diff --git a/app/src/main/java/com/coldmint/rust/pro/base/BaseActivity.kt b/app/src/main/java/com/coldmint/rust/pro/base/BaseActivity.kt index dbb3abd..cac73c6 100644 --- a/app/src/main/java/com/coldmint/rust/pro/base/BaseActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/base/BaseActivity.kt @@ -17,7 +17,6 @@ import androidx.core.view.WindowCompat import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import androidx.viewbinding.ViewBinding -import com.afollestad.materialdialogs.MaterialDialog import com.coldmint.dialog.CoreDialog import com.coldmint.rust.pro.R import com.google.android.material.appbar.MaterialToolbar @@ -131,9 +130,7 @@ abstract class BaseActivity : * @param msg String */ protected fun showDialog(msg: String) { - MaterialDialog(this).show { - message(text = msg) - } + CoreDialog(this).setMessage(msg).show() } /** @@ -163,10 +160,10 @@ abstract class BaseActivity : Snackbar.LENGTH_SHORT ) .setAction(R.string.show_details) { - MaterialDialog(this).show { - title(R.string.details).message(text = thisMsg) - .positiveButton(R.string.dialog_ok) - } + CoreDialog(this).setTitle(R.string.details).setMessage( thisMsg) + .setPositiveButton(R.string.dialog_ok){ + + }.show() }.show() } } diff --git a/app/src/main/java/com/coldmint/rust/pro/edit/RustAutoCompleteProvider.kt b/app/src/main/java/com/coldmint/rust/pro/edit/RustAutoCompleteProvider.kt index a4463ed..6686248 100644 --- a/app/src/main/java/com/coldmint/rust/pro/edit/RustAutoCompleteProvider.kt +++ b/app/src/main/java/com/coldmint/rust/pro/edit/RustAutoCompleteProvider.kt @@ -14,7 +14,8 @@ class RustAutoCompleteProvider { private val key = "自动完成提供者" private val jobList = ArrayList() - companion object{ + + companion object { var keyWord = "" } @@ -58,31 +59,40 @@ class RustAutoCompleteProvider { } else { //行内容 val lineData = contentReference.getLine(charPosition.getLine()) - if (lineData.isBlank()) { - DebugHelper.printLog(requireKey, "行内容为空,无需提示。") - return - } - //光标前内容 - val cursorPrefix = lineData.subSequence(0, charPosition.getColumn()).toString() - val symbolIndex = cursorPrefix.lastIndexOf(':') - keyWord = if (symbolIndex > 0) { - //有冒号 - cursorPrefix.substring(symbolIndex + 1) + keyWord = if (lineData.isNullOrBlank()) { + "" } else { - //无 - cursorPrefix + //光标前内容 + val cursorPrefix = lineData.subSequence(0, charPosition.getColumn()).toString() + val symbolIndex = cursorPrefix.lastIndexOf(':') + if (symbolIndex > 0) { + //有冒号 + cursorPrefix.substring(symbolIndex + 1) + } else { + //无 + cursorPrefix + } } var executeNumber = 0 jobList.forEach { //如果需要执行 if (it.needPerform(contentReference, charPosition)) { executeNumber++ - it.requireAutoComplete( - contentReference, - charPosition, - completionPublisher, - lineData, keyWord - ) + if (keyWord.isBlank()) { + DebugHelper.printLog(key, "${it.getName()}执行了空关键字响应。", requireKey) + it.respondingEmptyKeyword( + contentReference, + charPosition, + completionPublisher, lineData + ) + } else { + it.requireAutoComplete( + contentReference, + charPosition, + completionPublisher, + lineData, keyWord + ) + } } } DebugHelper.printLog(key, "执行了${executeNumber}个任务。", requireKey) diff --git a/app/src/main/java/com/coldmint/rust/pro/edit/RustCompletionAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/edit/RustCompletionAdapter.kt index 20544d6..4a0531e 100644 --- a/app/src/main/java/com/coldmint/rust/pro/edit/RustCompletionAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/edit/RustCompletionAdapter.kt @@ -12,7 +12,9 @@ import com.bumptech.glide.Glide import android.text.style.ForegroundColorSpan import android.util.TypedValue import androidx.core.view.isVisible +import com.coldmint.rust.pro.R import com.coldmint.rust.pro.databinding.EditItemBinding +import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.tool.GlobalMethod import io.github.rosemoe.sora.widget.component.EditorCompletionAdapter import java.util.* @@ -29,17 +31,36 @@ class RustCompletionAdapter : EditorCompletionAdapter() { private val layoutInflater by lazy { LayoutInflater.from(context) } + private val simpleDisplayOfAutoCompleteMenu by lazy { + AppSettings.getValue(AppSettings.Setting.SimpleDisplayOfAutoCompleteMenu, true) + } private val spannableStringBuilder: SpannableStringBuilder = SpannableStringBuilder() - private val colorSpan: ForegroundColorSpan = ForegroundColorSpan(Color.parseColor("#2196F3")) + private val colorSpan: ForegroundColorSpan by lazy { + ForegroundColorSpan(GlobalMethod.getColorPrimary(context)) + } private val bold = StyleSpan(Typeface.BOLD) + private var useEditBackground = false + + /** + * 使用编辑器背景 + * @param enable Boolean + */ + fun setEditBackground(enable: Boolean) { + useEditBackground = enable + } + override fun getView( position: Int, view: View?, parent: ViewGroup, isCurrentCursorPosition: Boolean ): View { + val editItem = EditItemBinding.inflate(layoutInflater, parent, false) + if (useEditBackground) { + editItem.root.setBackgroundResource(R.drawable.edit_item_background) + } val completionItem = getItem(position) as RustCompletionItem spannableStringBuilder.clear() val label = completionItem.title @@ -47,7 +68,10 @@ class RustCompletionAdapter : EditorCompletionAdapter() { //节补丁 if (RustAutoCompleteProvider.keyWord.startsWith('[') && RustAutoCompleteProvider.keyWord.length > 1) { RustAutoCompleteProvider.keyWord = - RustAutoCompleteProvider.keyWord.subSequence(0, RustAutoCompleteProvider.keyWord.length) + RustAutoCompleteProvider.keyWord.subSequence( + 0, + RustAutoCompleteProvider.keyWord.length + ) .toString() } val start = label.lowercase(Locale.getDefault()) @@ -63,15 +87,26 @@ class RustCompletionAdapter : EditorCompletionAdapter() { spannableStringBuilder.setSpan(bold, start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE) } editItem.titleView.text = spannableStringBuilder - editItem.contentView.text = completionItem.desc - if (completionItem.subtitle != null) { - editItem.subTitleView.text = completionItem.subtitle - } else { + if (simpleDisplayOfAutoCompleteMenu) { + editItem.contentView.isVisible = false editItem.subTitleView.isVisible = false - } - val icon = completionItem.icon - if (icon != null) { - Glide.with(context).load(icon).apply(GlobalMethod.getRequestOptions()).into(editItem.iconView) + editItem.iconView.isVisible = false + + } else { + editItem.contentView.isVisible = true + editItem.subTitleView.isVisible = true + editItem.iconView.isVisible = true + editItem.contentView.text = completionItem.desc + if (completionItem.subtitle != null) { + editItem.subTitleView.text = completionItem.subtitle + } else { + editItem.subTitleView.isVisible = false + } + val icon = completionItem.icon + if (icon != null) { + Glide.with(context).load(icon).apply(GlobalMethod.getRequestOptions()) + .into(editItem.iconView) + } } return editItem.root } diff --git a/app/src/main/java/com/coldmint/rust/pro/edit/RustFormatter.kt b/app/src/main/java/com/coldmint/rust/pro/edit/RustFormatter.kt index 4fac112..8a9ea30 100644 --- a/app/src/main/java/com/coldmint/rust/pro/edit/RustFormatter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/edit/RustFormatter.kt @@ -1,24 +1,40 @@ package com.coldmint.rust.pro.edit +import com.coldmint.rust.core.CodeTranslate +import com.coldmint.rust.core.tool.DebugHelper import io.github.rosemoe.sora.lang.format.Formatter import io.github.rosemoe.sora.text.Content import io.github.rosemoe.sora.text.TextRange class RustFormatter : Formatter { + private val key = "Rust代码格式化" + private var formatResultReceiver: Formatter.FormatResultReceiver? = null + private var running = false override fun format(p0: Content, p1: TextRange) { + running = true + //io.github.rosemoe. ora.lang. Format . formatter将给定的内容从开始位置格式化到结束位置 + //直接格式化内容,并调用Formatter。FormatResultReceiver,用于在格式化完成时从编辑器接收格式化的内容* + DebugHelper.printLog(key, "调用了格式化${p0} 文本范围${p1}") + formatResultReceiver?.onFormatSucceed(CodeTranslate.format(p0.toString()), null) + running = false } override fun formatRegion(p0: Content, p1: TextRange, p2: TextRange) { +// io.github.rosemoe. ora.lang. Format . formatter将给定的内容从开始位置格式化到结束位置 +// 直接格式化内容,并调用Formatter。FormatResultReceiver用于在格式化完成时从编辑器接收格式化的内容 + DebugHelper.printLog(key, "调用了格式化区域${p0} 文本范围${p1}") } override fun setReceiver(p0: Formatter.FormatResultReceiver?) { - +//设置结果接收器 + DebugHelper.printLog(key, "设置了结果接收器 为空?${p0 == null}") + formatResultReceiver = p0 } override fun isRunning(): Boolean { - return false + return running } override fun destroy() { diff --git a/app/src/main/java/com/coldmint/rust/pro/edit/RustLanguage.kt b/app/src/main/java/com/coldmint/rust/pro/edit/RustLanguage.kt index 5494569..d7d451c 100644 --- a/app/src/main/java/com/coldmint/rust/pro/edit/RustLanguage.kt +++ b/app/src/main/java/com/coldmint/rust/pro/edit/RustLanguage.kt @@ -68,6 +68,7 @@ class RustLanguage() : Language, EnglishMode { private var codeDataBase: CodeDataBase? = null + /** * 设置代码数据库 * @param codeDataBean CodeDataBase diff --git a/app/src/main/java/com/coldmint/rust/pro/edit/autoComplete/AutoCompleteJob.kt b/app/src/main/java/com/coldmint/rust/pro/edit/autoComplete/AutoCompleteJob.kt index e1bc6dc..17126ab 100644 --- a/app/src/main/java/com/coldmint/rust/pro/edit/autoComplete/AutoCompleteJob.kt +++ b/app/src/main/java/com/coldmint/rust/pro/edit/autoComplete/AutoCompleteJob.kt @@ -17,7 +17,7 @@ interface AutoCompleteJob { /** * 获取工作名称 */ - fun getName():String + fun getName(): String /** @@ -31,6 +31,18 @@ interface AutoCompleteJob { charPosition: CharPosition ): Boolean + + /** + * 处理空白关键字,或者行内容响应 + * 即不输入任何内容执行的操作 + * @return Boolean 返回true即响应,返回false反之 + */ + fun respondingEmptyKeyword( + contentReference: ContentReference, + charPosition: CharPosition, + completionPublisher: CompletionPublisher, lineData: String + ) + /** * 请求自动完成 * @param contentReference ContentReference @@ -44,7 +56,7 @@ interface AutoCompleteJob { charPosition: CharPosition, completionPublisher: CompletionPublisher, lineData: String, - keyWord:String + keyWord: String ) } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/edit/autoComplete/CodeAutoCompleteJob.kt b/app/src/main/java/com/coldmint/rust/pro/edit/autoComplete/CodeAutoCompleteJob.kt index 08f42d8..5ececdc 100644 --- a/app/src/main/java/com/coldmint/rust/pro/edit/autoComplete/CodeAutoCompleteJob.kt +++ b/app/src/main/java/com/coldmint/rust/pro/edit/autoComplete/CodeAutoCompleteJob.kt @@ -76,6 +76,35 @@ class CodeAutoCompleteJob : AutoCompleteJob { return true } + override fun respondingEmptyKeyword( + contentReference: ContentReference, + charPosition: CharPosition, + completionPublisher: CompletionPublisher, + lineData: String + ) { + val section = getSection(charPosition.getLine(), contentReference) + if (section != null) { + val trueSection = getSectionType(section) + val list = codeDao.findCodeBySection( + trueSection + ) + list?.forEach { codeInfo -> + completionPublisher.addItem( + CompletionItemConverter.codeInfoToCompletionItem( + codeInfo + ) + ) + } + DebugHelper.printLog( + debugKey, + "${getName()}响应空白关键字,查询${trueSection}节,返回了${list?.size ?: -1}个内容。" + ) + } else { + DebugHelper.printLog(debugKey, "${getName()}响应空白关键字,无法获取节。") + } + } + + override fun requireAutoComplete( contentReference: ContentReference, charPosition: CharPosition, diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/AllUnitsFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/AllUnitsFragment.kt index 5e0a4e6..18d92e4 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/AllUnitsFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/AllUnitsFragment.kt @@ -14,6 +14,7 @@ import android.view.LayoutInflater import android.view.View import androidx.core.view.isVisible import androidx.fragment.app.FragmentActivity +import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import com.coldmint.rust.core.ModClass import com.coldmint.rust.core.SourceFile @@ -29,6 +30,8 @@ import com.coldmint.rust.pro.adapters.UnitAdapter import com.coldmint.rust.pro.base.BaseFragment import com.coldmint.rust.pro.databinding.FragmentAllUnitsBinding import com.coldmint.rust.pro.tool.AppSettings +import com.google.android.material.divider.MaterialDividerItemDecoration +import me.zhanghai.android.fastscroll.FastScrollerBuilder import java.io.File import java.text.SimpleDateFormat import java.util.* @@ -51,6 +54,18 @@ class AllUnitsFragment( override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) { viewBinding.unitList.layoutManager = LinearLayoutManager(requireContext()) + val divider = MaterialDividerItemDecoration( + requireContext(), + MaterialDividerItemDecoration.VERTICAL + ) + + viewBinding.unitList.addItemDecoration( + divider + ) + viewBinding.swipeRefreshLayout.setOnRefreshListener { + loadFiles() + viewBinding.swipeRefreshLayout.isRefreshing = false + } loadFiles() } @@ -129,7 +144,7 @@ class AllUnitsFragment( val handler = Handler(Looper.getMainLooper()) executorService.submit { handler.post { - viewBinding.unitList.isVisible = false + viewBinding.swipeRefreshLayout.isVisible = false viewBinding.progressBar.isVisible = true viewBinding.unitError.isVisible = false } @@ -166,7 +181,7 @@ class AllUnitsFragment( notFindUnits(handler) } else { handler.post { - viewBinding.unitList.isVisible = true + viewBinding.swipeRefreshLayout.isVisible = true viewBinding.progressBar.isVisible = false viewBinding.unitError.isVisible = false val adapter = UnitAdapter(requireContext(), dataList, "") @@ -181,6 +196,8 @@ class AllUnitsFragment( loadFiles() } } + FastScrollerBuilder(viewBinding.unitList).useMd2Style() + .setPopupTextProvider(adapter).build() viewBinding.unitList.adapter = adapter whenNumberChanged?.invoke(dataList.size) } @@ -196,7 +213,7 @@ class AllUnitsFragment( fun notFindUnits(handler: Handler? = null, key: String? = null, searchMode: Boolean = false) { val temHandler = handler ?: Handler(Looper.getMainLooper()) temHandler.post { - viewBinding.unitList.isVisible = false + viewBinding.swipeRefreshLayout.isVisible = false viewBinding.progressBar.isVisible = false viewBinding.unitError.isVisible = true if (key != null) { @@ -233,7 +250,7 @@ class AllUnitsFragment( val handler = Handler(Looper.getMainLooper()) executorService.submit { handler.post { - viewBinding.unitList.isVisible = false + viewBinding.swipeRefreshLayout.isVisible = false viewBinding.progressBar.isVisible = true viewBinding.unitError.isVisible = false } @@ -295,7 +312,7 @@ class AllUnitsFragment( notFindUnits(handler, searchMode = true) } else { handler.post { - viewBinding.unitList.isVisible = true + viewBinding.swipeRefreshLayout.isVisible = true viewBinding.progressBar.isVisible = false viewBinding.unitError.isVisible = true viewBinding.unitError.text = getString(R.string.search_tip) @@ -343,7 +360,7 @@ class AllUnitsFragment( notFindUnits(handler, key) } else { handler.post { - viewBinding.unitList.isVisible = true + viewBinding.swipeRefreshLayout.isVisible = true viewBinding.progressBar.isVisible = false viewBinding.unitError.isVisible = true viewBinding.unitError.text = getString(R.string.not_find_units_action) diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/DatabaseFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/DatabaseFragment.kt index a8997d6..c18a66f 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/DatabaseFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/DatabaseFragment.kt @@ -33,12 +33,11 @@ import kotlin.collections.ArrayList class DatabaseFragment : BaseFragment() { - - override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) { + fun loadList() { viewBinding.databaseList.layoutManager = LinearLayoutManager(requireContext()) val database_directory = AppSettings.getValue( AppSettings.Setting.DatabaseDirectory, - requireContext().filesDir.absolutePath + "/database/" + requireContext().filesDir.absolutePath + "/databases/" ) val directory = File(database_directory) if (!directory.exists()) { @@ -165,6 +164,15 @@ class DatabaseFragment : BaseFragment() { } + override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) { + + } + + override fun onResume() { + super.onResume() + loadList() + } + override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentDatabaseBinding { return FragmentDatabaseBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/HistoryUnitFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/HistoryUnitFragment.kt index 4331138..cecbdbd 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/HistoryUnitFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/HistoryUnitFragment.kt @@ -8,6 +8,7 @@ import android.os.Looper import android.view.LayoutInflater import androidx.core.view.isVisible import androidx.fragment.app.FragmentActivity +import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import com.coldmint.rust.core.ModClass import com.coldmint.rust.core.SourceFile @@ -16,6 +17,7 @@ import com.coldmint.rust.pro.R import com.coldmint.rust.pro.adapters.HistoryAdapter import com.coldmint.rust.pro.base.BaseFragment import com.coldmint.rust.pro.databinding.FragmentHistoryBinding +import com.google.android.material.divider.MaterialDividerItemDecoration import java.io.File import java.util.concurrent.ExecutorService import java.util.concurrent.Executors @@ -34,6 +36,14 @@ class HistoryUnitFragment( val executorService: ExecutorService = Executors.newSingleThreadExecutor() override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) { viewBinding.unitList.layoutManager = LinearLayoutManager(requireContext()) + val divider = MaterialDividerItemDecoration( + requireContext(), + MaterialDividerItemDecoration.VERTICAL + ) + + viewBinding.unitList.addItemDecoration( + divider + ) loadList() } @@ -96,6 +106,7 @@ class HistoryUnitFragment( } } viewBinding.unitList.adapter = adapter + whenNumberChanged?.invoke(dataList.size) } } @@ -110,12 +121,6 @@ class HistoryUnitFragment( fun openEditActivity(file: SourceFile) { val bundle = Bundle() val path = file.file.absolutePath -// val name = fileClass.getName( -// AppSettings.getValue( -// AppSettings.Setting.AppLanguage, -// Locale.getDefault().language -// ) -// ) bundle.putString("path", path) bundle.putString("modPath", modClass.modFile.absolutePath) val intent = Intent(requireContext(), EditActivity::class.java) diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/InsertCoinsFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/InsertCoinsFragment.kt index 49ed464..bbe0c49 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/InsertCoinsFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/InsertCoinsFragment.kt @@ -1,5 +1,6 @@ package com.coldmint.rust.pro.fragments +import android.content.Intent import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -15,10 +16,12 @@ import com.coldmint.rust.core.dataBean.mod.InsertCoinHistoryData import com.coldmint.rust.core.interfaces.ApiCallBack import com.coldmint.rust.core.web.WebMod import com.coldmint.rust.pro.R +import com.coldmint.rust.pro.UserHomePageActivity import com.coldmint.rust.pro.adapters.InsertCoinsAdapter import com.coldmint.rust.pro.base.BaseFragment import com.coldmint.rust.pro.databinding.FragmentInsertCoinsBinding import com.coldmint.rust.pro.tool.AppSettings +import com.google.android.material.divider.MaterialDividerItemDecoration /** * 投币碎片 @@ -30,11 +33,13 @@ class InsertCoinsFragment(val modId: String) : BaseFragment + itemInsertCoinsBinding.imageView.setOnClickListener { + gotoUserPage(data.account) + } + } viewBinding.recyclerView.adapter = - InsertCoinsAdapter(requireContext(), dataList) + adapter val data = getString(R.string.coin_records) + "(" + dataList.size + ")" viewBinding.coinRecordsView.text = data viewBinding.recyclerView.isVisible = true @@ -110,6 +121,21 @@ class InsertCoinsFragment(val modId: String) : BaseFragment { override fun onResponse(t: CoinStatusData) { diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/InstalledTemplateFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/InstalledTemplateFragment.kt index e60098f..7236952 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/InstalledTemplateFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/InstalledTemplateFragment.kt @@ -14,6 +14,7 @@ import android.widget.TextView import android.widget.Toast import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts +import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.MutableLiveData import com.coldmint.dialog.CoreDialog import com.coldmint.rust.core.LocalTemplatePackage @@ -133,6 +134,7 @@ class InstalledTemplateFragment : BaseFragment registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { if (it.resultCode == Activity.RESULT_OK) { Log.d("启动模板解析器", "收到成功回调,关闭界面。") + requireActivity().setResult(AppCompatActivity.RESULT_OK, it.data) requireActivity().finish() } else { Log.w("启动模板解析器", "未收到有效回调。") diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/MapFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/MapFragment.kt index 26116f6..5d453ce 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/MapFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/MapFragment.kt @@ -12,7 +12,7 @@ import androidx.core.content.FileProvider import androidx.core.view.isVisible import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager -import com.afollestad.materialdialogs.MaterialDialog +import com.coldmint.dialog.CoreDialog import com.coldmint.rust.core.MapClass import com.coldmint.rust.core.tool.AppOperator import com.coldmint.rust.core.tool.FileOperator @@ -59,27 +59,27 @@ class MapFragment : BaseFragment() { itemMapBinding.mapLinearlayout.setOnClickListener { val packName = "com.mirwanda.nottiled" val materialDialog = - MaterialDialog(requireContext()).title(R.string.edit_map) - .message(R.string.edit_map_tip) - .negativeButton(R.string.dialog_close).cancelable(false) + CoreDialog(requireContext()).setTitle(R.string.edit_map) + .setMessage(R.string.edit_map_tip) + .setNegativeButton(R.string.dialog_close) { + + }.setCancelable(false) if (AppOperator.isAppInstalled( requireContext(), packName ) ) { - materialDialog.positiveButton(R.string.open_nottiled) - .positiveButton { - materialDialog.dismiss() - AppOperator.openApp(requireContext(), packName) - } + materialDialog.setPositiveButton(R.string.open_nottiled) { + materialDialog.dismiss() + AppOperator.openApp(requireContext(), packName) + } } else { - materialDialog.positiveButton(R.string.downlod_nottiled) - .positiveButton { - AppOperator.useBrowserAccessWebPage( - requireContext(), - "https://mint.lanzouo.com/ilXgJyfol8h" - ) - } + materialDialog.setPositiveButton(R.string.downlod_nottiled) { + AppOperator.useBrowserAccessWebPage( + requireContext(), + "https://mint.lanzouo.com/ilXgJyfol8h" + ) + } } materialDialog.show() } @@ -137,11 +137,13 @@ class MapFragment : BaseFragment() { override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) { viewBinding.mapList.layoutManager = LinearLayoutManager(requireContext()) + val divider = MaterialDividerItemDecoration( + requireContext(), + MaterialDividerItemDecoration.VERTICAL + ) + viewBinding.mapList.addItemDecoration( - DividerItemDecoration( - requireContext(), - DividerItemDecoration.VERTICAL - ) + divider ) val path = AppSettings.getValue(AppSettings.Setting.MapFolder, "") if (path.isNotBlank()) { diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/ModCommentsFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/ModCommentsFragment.kt index 06871e0..8d461cf 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/ModCommentsFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/ModCommentsFragment.kt @@ -24,6 +24,7 @@ import com.coldmint.rust.pro.base.BaseFragment import com.coldmint.rust.pro.databinding.FragmentModCommentsBinding import com.coldmint.rust.pro.dialog.CommentDialog import com.coldmint.rust.pro.tool.AppSettings +import com.google.android.material.divider.MaterialDividerItemDecoration import com.google.android.material.snackbar.Snackbar /** @@ -32,11 +33,13 @@ import com.google.android.material.snackbar.Snackbar class ModCommentsFragment(val modId: String) : BaseFragment() { override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) { viewBinding.recyclerView.layoutManager = LinearLayoutManager(requireContext()) + val divider = MaterialDividerItemDecoration( + requireContext(), + MaterialDividerItemDecoration.VERTICAL + ) + viewBinding.recyclerView.addItemDecoration( - DividerItemDecoration( - requireContext(), - DividerItemDecoration.VERTICAL - ) + divider ) viewBinding.swipeRefreshLayout.setOnRefreshListener { loadCommentList(modId, false) diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/ModFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/ModFragment.kt index 26a3eaa..7313401 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/ModFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/ModFragment.kt @@ -22,6 +22,7 @@ import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.tool.GlobalMethod import com.coldmint.rust.pro.viewmodel.ModViewModel import com.google.android.material.bottomsheet.BottomSheetDialog +import com.google.android.material.divider.MaterialDividerItemDecoration import com.google.android.material.snackbar.Snackbar import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job @@ -337,11 +338,12 @@ class ModFragment : BaseFragment() { override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) { viewBinding.modList.layoutManager = LinearLayoutManager(context) + val divider = MaterialDividerItemDecoration( + requireContext(), + MaterialDividerItemDecoration.VERTICAL + ) viewBinding.modList.addItemDecoration( - DividerItemDecoration( - requireContext(), - DividerItemDecoration.VERTICAL - ) + divider ) viewBinding.swipeRefreshLayout.setOnRefreshListener { loadModList() diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/RecommendedFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/RecommendedFragment.kt index 0aef577..e66602a 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/RecommendedFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/RecommendedFragment.kt @@ -7,8 +7,8 @@ import android.view.LayoutInflater import android.view.View import androidx.core.view.isVisible import androidx.recyclerview.widget.LinearLayoutManager -import com.afollestad.materialdialogs.MaterialDialog import com.bumptech.glide.Glide +import com.coldmint.dialog.CoreDialog import com.coldmint.rust.core.dataBean.BannerItemDataBean import com.coldmint.rust.core.dataBean.mod.WebModListData import com.coldmint.rust.core.interfaces.ApiCallBack @@ -163,10 +163,11 @@ class RecommendedFragment : BaseFragment() { val type = textStyleMaker.getType(data.link) val linkData = textStyleMaker.getData(data.link) if (type == null || linkData == null) { - MaterialDialog(requireContext()).show { - title(text = data.title).message(text = data.link) - .positiveButton(R.string.dialog_ok) - } + CoreDialog(requireContext()).setTitle(data.title) + .setMessage(data.link) + .setPositiveButton(R.string.dialog_ok) { + + }.setCancelable(false).show() } else { textStyleMaker.clickEvent( requireContext(), diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/TemplateCommunityFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/TemplateCommunityFragment.kt index 8199bec..ee4a3ce 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/TemplateCommunityFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/TemplateCommunityFragment.kt @@ -19,6 +19,7 @@ import com.coldmint.rust.pro.adapters.WebTemplateAdapter import com.coldmint.rust.pro.base.BaseFragment import com.coldmint.rust.pro.databinding.FragmentTemplateCommunityBinding import com.coldmint.rust.pro.tool.AppSettings +import com.google.android.material.divider.MaterialDividerItemDecoration import me.zhanghai.android.fastscroll.FastScrollerBuilder /** @@ -28,11 +29,12 @@ class TemplateCommunityFragment : BaseFragment val token = AppSettings.getValue(AppSettings.Setting.Token, "") override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) { + val divider = MaterialDividerItemDecoration( + requireContext(), + MaterialDividerItemDecoration.VERTICAL + ) viewBinding.recyclerView.addItemDecoration( - DividerItemDecoration( - requireContext(), - DividerItemDecoration.VERTICAL - ) + divider ) viewBinding.recyclerView.layoutManager = LinearLayoutManager(requireContext()) @@ -55,10 +57,12 @@ class TemplateCommunityFragment : BaseFragment val adapter = WebTemplateAdapter(requireContext(), t.data!!) adapter.setItemEvent { i, itemWebTemplateBinding, viewHolder, data -> itemWebTemplateBinding.root.setOnClickListener { - val intent = Intent(requireContext(), - NetworkTemplatePackageDetailsActivity::class.java) - intent.putExtra("id",data.id) - intent.putExtra("createDirectory",data.id) + val intent = Intent( + requireContext(), + NetworkTemplatePackageDetailsActivity::class.java + ) + intent.putExtra("id", data.id) + intent.putExtra("createDirectory", data.id) startActivity(intent) } itemWebTemplateBinding.button.setOnClickListener { diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/WebModDetailsFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/WebModDetailsFragment.kt index 62b1c49..8335b8a 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/WebModDetailsFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/WebModDetailsFragment.kt @@ -42,9 +42,6 @@ class WebModDetailsFragment(val modId: String,val modNameLiveData: MutableLiveDa return link } - - - /** * 获取此模组是否对外开放 * @return Boolean diff --git a/app/src/main/java/com/coldmint/rust/pro/tool/AppSettings.kt b/app/src/main/java/com/coldmint/rust/pro/tool/AppSettings.kt index 3bd1cd2..efeda3c 100644 --- a/app/src/main/java/com/coldmint/rust/pro/tool/AppSettings.kt +++ b/app/src/main/java/com/coldmint/rust/pro/tool/AppSettings.kt @@ -38,7 +38,7 @@ object AppSettings { } enum class Setting { - DatabaseDirectory, DatabasePath, TemplateDirectory, AppLanguage, DeveloperMode, CustomSymbol, AutoCreateNomedia, OnlyLoadConantLanguageTemple, NightMode, GamePackage, KeywordColor, KeywordColorDark, AnnotationColor, AnnotationColorDark, TextColor, TextColorDark, SectionColor, SectionColorDark, KeepRwmodFile, EnableRecoveryStation, RecoveryStationFileSaveDays, RecoveryStationFolder, IndependentFolder, SetGameStorage, PackDirectory, IdentifiersPromptNumber, UserName, UseJetBrainsMonoFont, AppID, Account, PassWord, ExpirationTime, CheckBetaUpdate, UpdateData, ShareTip, AgreePolicy, EnglishEditingMode, NightModeFollowSystem, UseMobileNetwork, MapFolder, ModFolder, UseTheCommunityAsTheLaunchPage, AutoSave, ServerAddress, Token, LoginStatus, DynamicColor, ExperiencePlan, FileSortType, CodeEditBackGroundEnable, BlurTransformationValue, CodeEditBackGroundPath + DatabaseDirectory, DatabasePath, TemplateDirectory, AppLanguage, DeveloperMode, CustomSymbol, AutoCreateNomedia, OnlyLoadConantLanguageTemple, NightMode, GamePackage, KeywordColor, KeywordColorDark, AnnotationColor, AnnotationColorDark, TextColor, TextColorDark, SectionColor, SectionColorDark, KeepRwmodFile, EnableRecoveryStation, RecoveryStationFileSaveDays, RecoveryStationFolder, IndependentFolder, SetGameStorage, PackDirectory, IdentifiersPromptNumber, UserName, UseJetBrainsMonoFont, AppID, Account, PassWord, ExpirationTime, CheckBetaUpdate, UpdateData, ShareTip, AgreePolicy, EnglishEditingMode, NightModeFollowSystem, UseMobileNetwork, MapFolder, ModFolder, UseTheCommunityAsTheLaunchPage, AutoSave, ServerAddress, Token, LoginStatus, DynamicColor, ExperiencePlan, FileSortType, CodeEditBackGroundEnable, BlurTransformationValue, CodeEditBackGroundPath, SimpleDisplayOfAutoCompleteMenu } @@ -130,6 +130,8 @@ object AppSettings { map[Setting.DynamicColor] = mApplication.getString(R.string.setting_dynamic_color) map[Setting.ExperiencePlan] = mApplication.getString(R.string.setting_experience_the_plan) map[Setting.FileSortType] = mApplication.getString(R.string.setting_file_sort_type) + map[Setting.SimpleDisplayOfAutoCompleteMenu] = + mApplication.getString(R.string.setting_simple_display_of_auto_complete_menu) //仅保存不可显示 map[Setting.SetGameStorage] = "SetGameStorage" map[Setting.AppID] = "AppId" diff --git a/app/src/main/java/com/coldmint/rust/pro/tool/GlobalMethod.kt b/app/src/main/java/com/coldmint/rust/pro/tool/GlobalMethod.kt index 6b32fec..fd9e06a 100644 --- a/app/src/main/java/com/coldmint/rust/pro/tool/GlobalMethod.kt +++ b/app/src/main/java/com/coldmint/rust/pro/tool/GlobalMethod.kt @@ -5,6 +5,7 @@ import android.content.ClipData import android.content.ClipboardManager import android.content.Context import android.content.res.ColorStateList +import android.content.res.Resources import android.graphics.Bitmap import android.graphics.Color import android.graphics.Paint @@ -16,8 +17,6 @@ import android.widget.TextView import android.widget.Toast import androidx.core.graphics.drawable.DrawableCompat import androidx.fragment.app.FragmentActivity -import com.afollestad.materialdialogs.MaterialDialog -import com.afollestad.materialdialogs.bottomsheets.BottomSheet import com.bumptech.glide.load.MultiTransformation import com.bumptech.glide.request.RequestOptions import com.coldmint.rust.core.dataBean.mod.WebModUpdateLogData @@ -27,6 +26,7 @@ import com.coldmint.rust.core.web.WebMod import com.coldmint.rust.pro.R import com.flask.colorpicker.ColorPickerView import com.flask.colorpicker.builder.ColorPickerDialogBuilder +import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.snackbar.Snackbar import com.permissionx.guolindev.PermissionX import jp.wasabeef.glide.transformations.* @@ -43,6 +43,15 @@ object GlobalMethod { const val DEBUG_SIGN = "963dfd616924b27f9247a35e45bc130a" const val RELEASE_SIGN = "5320b24894fe7ed449842a81a2dfceda" + /** + * 转dp + * @param i Int + * @return Int + */ + fun dp2px(i: Int): Int { + return (Resources.getSystem().displayMetrics.density * i + 0.5f).toInt() + } + /** * 获取主题色 @@ -211,11 +220,10 @@ object GlobalMethod { } val title = context.getString(R.string.update_record) + "(" + data.size + ")" - MaterialDialog(context, BottomSheet()).show { - title(text = title).message(text = stringBuilder.toString()) - .cancelable(false) - .positiveButton(R.string.dialog_ok) - } + MaterialAlertDialogBuilder(context).setTitle(title) + .setMessage(stringBuilder.toString()).setCancelable(false) + .setPositiveButton(R.string.dialog_ok) { i, i2 -> + }.show() } else { Toast.makeText(context, t.message, Toast.LENGTH_SHORT).show() } diff --git a/app/src/main/java/com/coldmint/rust/pro/viewmodel/StartViewModel.kt b/app/src/main/java/com/coldmint/rust/pro/viewmodel/StartViewModel.kt index dc19396..c6e6354 100644 --- a/app/src/main/java/com/coldmint/rust/pro/viewmodel/StartViewModel.kt +++ b/app/src/main/java/com/coldmint/rust/pro/viewmodel/StartViewModel.kt @@ -17,7 +17,6 @@ import androidx.appcompat.app.AppCompatDelegate import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import androidx.lifecycle.MutableLiveData -import com.afollestad.materialdialogs.MaterialDialog import com.coldmint.rust.core.CompressionManager import com.coldmint.rust.core.DataSet import com.coldmint.rust.core.dataBean.LoginRequestData @@ -28,6 +27,7 @@ import com.coldmint.rust.core.database.code.CodeDataBase import com.coldmint.rust.core.interfaces.ApiCallBack import com.coldmint.rust.core.interfaces.UnzipListener import com.coldmint.rust.core.tool.AppOperator +import com.coldmint.rust.core.tool.DebugHelper import com.coldmint.rust.core.tool.FileOperator import com.coldmint.rust.core.web.ServerConfiguration import com.coldmint.rust.core.web.User @@ -184,7 +184,7 @@ class StartViewModel(application: Application) : BaseAndroidViewModel(applicatio AppSettings.initSetting(AppSettings.Setting.DeveloperMode, false) AppSettings.initSetting( AppSettings.Setting.DatabaseDirectory, - context.filesDir.absolutePath + "/database/" + context.filesDir.absolutePath + "/databases/" ) AppSettings.initSetting( AppSettings.Setting.TemplateDirectory, @@ -221,6 +221,7 @@ class StartViewModel(application: Application) : BaseAndroidViewModel(applicatio AppSettings.initSetting(AppSettings.Setting.EnglishEditingMode, false) AppSettings.initSetting(AppSettings.Setting.NightModeFollowSystem, true) AppSettings.initSetting(AppSettings.Setting.UseTheCommunityAsTheLaunchPage, true) + AppSettings.initSetting(AppSettings.Setting.SimpleDisplayOfAutoCompleteMenu, true) AppSettings.initSetting( AppSettings.Setting.ServerAddress, ServerConfiguration.defaultIp @@ -265,60 +266,89 @@ class StartViewModel(application: Application) : BaseAndroidViewModel(applicatio } + + /** + * 解压数据集 + * @param resFileName String + * @param useDataSet Boolean + */ + private fun unzipDataSet(resFileName: String, useDataSet: Boolean = false) { + val cacheFile = File(context.cacheDir.toString() + "/system/" + resFileName) + val prefixName = FileOperator.getPrefixName(resFileName) + val cacheFolder = + File(context.cacheDir.toString() + "/system/" + prefixName) + FileOperator.outputResourceFile(context, resFileName, cacheFile) + val databaseFolder = File( + AppSettings.getValue( + AppSettings.Setting.DatabaseDirectory, + context.filesDir.absolutePath + "/databases/" + ) + prefixName + ) + val updateDataSet: (File) -> Unit = { + CompressionManager.instance.unzip( + cacheFile, + it, + object : UnzipListener { + override fun whenUnzipFile(zipEntry: ZipEntry, file: File): Boolean { + return true + } + + override fun whenUnzipFolder(zipEntry: ZipEntry, folder: File): Boolean { + return true + } + + override fun whenUnzipComplete(result: Boolean) { + if (useDataSet) { + val init = AppSettings.initSetting( + AppSettings.Setting.DatabasePath, + databaseFolder.absolutePath + ) + if (init) { + DebugHelper.printLog("加载数据集", "已初始化加载" + databaseFolder) + var codeDataBase = CodeDataBase.getInstance(context) + codeDataBase.loadDataSet( + DataSet(databaseFolder), + CodeDataBase.ReadMode.Copy + ) + } else { + DebugHelper.printLog("加载数据集", "无法二次加载" + databaseFolder) + } + } else { + DebugHelper.printLog("加载数据集", "已解压" + databaseFolder + "但不使用。") + } + } + + }) + } + + if (databaseFolder.exists()) { + updateDataSet.invoke(cacheFolder) + val oldDataSet = DataSet(databaseFolder) + val newDataSet = DataSet(cacheFolder) + val update = oldDataSet.update(newDataSet) + if (update) { + dataSetMsgLiveData.value = context.getString(R.string.dataset_update_ok) + } + } else { + updateDataSet.invoke(databaseFolder) + } + } + /** * 初始化资源 */ private fun initRes() { - val defaultDatabase = File( - AppSettings.getValue( - AppSettings.Setting.DatabaseDirectory, - context.filesDir.absolutePath + "/database/" - ) + "official" - ) - AppSettings.initSetting( - AppSettings.Setting.DatabasePath, - defaultDatabase.absolutePath - ) - val cacheFile = File(context.cacheDir.toString() + "/System/DataBase.rdb") - val cacheFolder = File(context.cacheDir.toString() + "/System/official") - FileOperator.outputResourceFile(context, "dataBase.rdb", cacheFile) try { - val updateDataSet: (File) -> Unit = { - CompressionManager.instance.unzip( - cacheFile, - it, - object : UnzipListener { - override fun whenUnzipFile(zipEntry: ZipEntry, file: File): Boolean { - return true - } - - override fun whenUnzipFolder(zipEntry: ZipEntry, folder: File): Boolean { - return true - } - - override fun whenUnzipComplete(result: Boolean) { - var codeDataBase = CodeDataBase.getInstance(context) - - codeDataBase.loadDataSet( - DataSet(defaultDatabase), - CodeDataBase.ReadMode.Copy - ) - } - - }) - } - - if (defaultDatabase.exists()) { - updateDataSet.invoke(cacheFolder) - val oldDataSet = DataSet(defaultDatabase) - val newDataSet = DataSet(cacheFolder) - val update = oldDataSet.update(newDataSet) - if (update) { - dataSetMsgLiveData.value = context.getString(R.string.dataset_update_ok) - } + val language = Locale.getDefault().language + DebugHelper.printLog("初始化资源","语言"+language) + if (language == "zh") { + unzipDataSet("dataBase.rdb", true) + unzipDataSet("dataBase_en.rdb") } else { - updateDataSet.invoke(defaultDatabase) + unzipDataSet("dataBase.rdb") + unzipDataSet("dataBase_en.rdb", true) } + val defaultValues = File(context.filesDir.absolutePath + "/values.json") if (!defaultValues.exists()) { FileOperator.outputResourceFile( diff --git a/app/src/main/java/com/coldmint/rust/pro/viewmodel/TemplateParserViewModel.kt b/app/src/main/java/com/coldmint/rust/pro/viewmodel/TemplateParserViewModel.kt index 7561afd..60259a9 100644 --- a/app/src/main/java/com/coldmint/rust/pro/viewmodel/TemplateParserViewModel.kt +++ b/app/src/main/java/com/coldmint/rust/pro/viewmodel/TemplateParserViewModel.kt @@ -26,6 +26,8 @@ class TemplateParserViewModel : BaseViewModel() { private var jsonData: JSONObject? = null private var template: Template? = null private lateinit var arrayList :ArrayList + //文件输出目录 + private var outPutPath : String? = null //创建目录 @@ -111,9 +113,18 @@ class TemplateParserViewModel : BaseViewModel() { Log.e("构建文件", "目标文件${path}已存在。") return false } + outPutPath = path.absolutePath return FileOperator.writeFile(path, generatingCode(context)) } + /** + * 获取文件输出目录(当构建文件完毕后,返回有效值。否则返回null) + * @return String? + */ + fun getOutputPath():String?{ + return outPutPath + } + /** * 生成代码 * @return String diff --git a/app/src/main/res/drawable/edit_item_background.xml b/app/src/main/res/drawable/edit_item_background.xml new file mode 100644 index 0000000..8a0c9a6 --- /dev/null +++ b/app/src/main/res/drawable/edit_item_background.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/round_background_false.xml b/app/src/main/res/drawable/round_background_false.xml index a8ba70d..255294e 100644 --- a/app/src/main/res/drawable/round_background_false.xml +++ b/app/src/main/res/drawable/round_background_false.xml @@ -8,5 +8,5 @@ android:topRightRadius="16dp" /> + android:color="?attr/textFillColor" /> \ No newline at end of file diff --git a/app/src/main/res/drawable/user_home_background.xml b/app/src/main/res/drawable/user_home_background.xml new file mode 100644 index 0000000..3230568 --- /dev/null +++ b/app/src/main/res/drawable/user_home_background.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml index 9c1d3f4..ae14fb9 100644 --- a/app/src/main/res/layout/activity_about.xml +++ b/app/src/main/res/layout/activity_about.xml @@ -97,7 +97,9 @@ android:id="@+id/action_divider" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_above="@id/privacyPolicyView" /> + android:layout_above="@id/privacyPolicyView" + android:layout_marginTop="16dp" + app:dividerThickness="0.8dp" />