优化部分对话框

This commit is contained in:
coldmint 2022-07-06 23:12:56 +08:00
parent ec39947f58
commit 09562490d7
16 changed files with 283 additions and 247 deletions

Binary file not shown.

View File

@ -24,11 +24,11 @@ android {
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.coldmint.rust.pro"
applicationId "com.coldmint.rust.beta"
minSdkVersion 21
targetSdkVersion 32
versionCode 18
versionName "2.0 release8 p3(2022-4-26)"
versionName "2.1 alpha(2022-7-6)"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

View File

@ -15,8 +15,6 @@ import androidx.core.view.isVisible
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.list.listItems
import com.coldmint.rust.core.dataBean.ApiResponse
import com.coldmint.rust.core.dataBean.CouponListDataBean
import com.coldmint.rust.core.dataBean.PlanDataBean
@ -33,6 +31,7 @@ import com.coldmint.rust.pro.databean.FunctionInfo
import com.coldmint.rust.pro.databinding.ActivityActivateBinding
import com.coldmint.rust.pro.tool.AppSettings
import com.coldmint.rust.pro.tool.GlobalMethod
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
class ActivateActivity : BaseActivity<ActivityActivateBinding>() {
@ -283,10 +282,12 @@ class ActivateActivity : BaseActivity<ActivityActivateBinding>() {
)
}
if (finalCouponId != null) {
MaterialDialog(this).title(R.string.coupon).message(R.string.use_coupon)
.positiveButton(R.string.dialog_ok).positiveButton {
MaterialAlertDialogBuilder(this).setTitle(R.string.coupon)
.setMessage(R.string.use_coupon)
.setPositiveButton(R.string.dialog_ok) { i, i2 ->
func.invoke()
}.negativeButton(R.string.dialog_cancel).show()
}.setNegativeButton(R.string.dialog_cancel) { i, i2 ->
}.show()
} else {
func.invoke()
}

View File

@ -11,14 +11,14 @@ import android.content.Intent
import android.view.KeyEvent
import android.view.MenuItem
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.core.view.isVisible
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.customview.customView
import com.coldmint.rust.pro.adapters.BookmarkAdapter
import com.coldmint.rust.pro.base.BaseActivity
import com.coldmint.rust.pro.databean.Bookmark
import com.coldmint.rust.pro.databinding.ActivityBookmarkManagerBinding
import com.coldmint.rust.pro.databinding.EditBookmarkBinding
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.io.File
import java.util.ArrayList
@ -46,7 +46,7 @@ class BookmarkManagerActivity : BaseActivity<ActivityBookmarkManagerBinding>() {
attachFileItemBinding.root.setOnLongClickListener {
bookmarkAdapter.showDeleteItemDialog(
bookmark.name,
viewHolder.adapterPosition, onClickPositiveButton = { d, b ->
viewHolder.adapterPosition, onClickPositiveButton = { i:Int, b ->
bookmarkManager.removeBookmark(bookmark)
if (list.isEmpty()) {
showNoBookmarkToView()
@ -113,25 +113,26 @@ class BookmarkManagerActivity : BaseActivity<ActivityBookmarkManagerBinding>() {
startActivityForResult(intent, 1)
}
val materialDialog =
MaterialDialog(this).title(text = title).customView(view = editBookmarkBinding.root)
.positiveButton(R.string.dialog_ok).negativeButton(R.string.dialog_close)
.noAutoDismiss().cancelable(false)
materialDialog.positiveButton {
var dialog: AlertDialog? = null
val materialAlertDialogBuilder = MaterialAlertDialogBuilder(this)
.setView(editBookmarkBinding.root)
.setTitle(title)
.setPositiveButton(R.string.dialog_ok)
{ i, i2 ->
val newPath = pathView.text.toString()
val newName = nameView.text.toString()
if (newName.isEmpty()) {
setErrorAndInput(nameView, getString(R.string.enter_bookmark_name))
return@positiveButton
return@setPositiveButton
}
if (newPath.isEmpty()) {
setErrorAndInput(pathView, getString(R.string.enter_file_path))
return@positiveButton
return@setPositiveButton
}
val file = File(newPath)
if (!file.exists()) {
setErrorAndInput(pathView, getString(R.string.bookmark_jump_failed))
return@positiveButton
return@setPositiveButton
}
if (name == null) {
val addBookmark = bookmarkManager.addBookmark(newPath, newName)
@ -146,7 +147,7 @@ class BookmarkManagerActivity : BaseActivity<ActivityBookmarkManagerBinding>() {
}
} else {
if (name == newName && path == newPath) {
materialDialog.dismiss()
dialog?.dismiss()
} else {
if (path != null) {
val oldBookmark = Bookmark(path, name)
@ -155,7 +156,7 @@ class BookmarkManagerActivity : BaseActivity<ActivityBookmarkManagerBinding>() {
bookmarkManager.replaceBookmark(oldBookmark, newBookmark)
if (addBookmark) {
updateView(bookmarkManager.list())
materialDialog.dismiss()
dialog?.dismiss()
} else {
setErrorAndInput(
pathView,
@ -165,12 +166,12 @@ class BookmarkManagerActivity : BaseActivity<ActivityBookmarkManagerBinding>() {
}
}
}
materialDialog.dismiss()
}
materialDialog.negativeButton {
materialDialog.dismiss()
.setNegativeButton(R.string.dialog_close) { i, i2 ->
dialog?.dismiss()
}
materialDialog.show()
.setCancelable(false)
dialog = materialAlertDialogBuilder.show()
}

View File

@ -27,6 +27,64 @@ class CreationWizardActivity : BaseActivity<ActivityCreationWizardBinding>() {
viewBinding.recyclerView.layoutManager = LinearLayoutManager(this)
when (temType) {
"mod" -> {
loadMod()
}
"template" -> {
loadTemplate()
}
}
}
/**
* 加载模板活动
*/
fun loadTemplate() {
val dataList = ArrayList<GuideData>()
dataList.add(
GuideData(
R.string.create_template,
R.string.create_template_describe,
R.drawable.ic_outline_create_24
)
)
dataList.add(
GuideData(
R.string.import_template,
R.string.import_template_describe,
R.drawable.folder
)
)
val adapter = GuideAdapter(this, dataList)
adapter.setItemEvent { i, itemGuideBinding, viewHolder, guideData ->
itemGuideBinding.root.setOnClickListener {
finish()
when (guideData.titleRes) {
R.string.create_template -> {
startActivity(
Intent(
this,
CreateTemplateActivity::class.java
)
)
}
R.string.import_template -> {
val startIntent =
Intent(this, FileManagerActivity::class.java)
val fileBundle = Bundle()
fileBundle.putString("type", "selectFile")
startIntent.putExtra("data", fileBundle)
startActivity(startIntent )
}
}
}
}
viewBinding.recyclerView.adapter = adapter
}
/**
* 加载模组活动
*/
fun loadMod() {
val dataList = ArrayList<GuideData>()
dataList.add(
GuideData(
@ -97,11 +155,8 @@ class CreationWizardActivity : BaseActivity<ActivityCreationWizardBinding>() {
}
}
}
viewBinding.recyclerView.adapter = adapter
}
}
}
override fun getViewBindingObject(): ActivityCreationWizardBinding {
return ActivityCreationWizardBinding.inflate(layoutInflater)

View File

@ -2,13 +2,11 @@ package com.coldmint.rust.pro
import android.Manifest
import android.content.DialogInterface
import com.coldmint.rust.pro.base.BaseActivity
import com.coldmint.rust.pro.tool.GlobalMethod
import com.coldmint.rust.core.iflynote.SquareBracketData
import android.content.pm.PackageInfo
import com.coldmint.rust.pro.tool.AppSettings
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
import android.content.Intent
import android.content.pm.PackageManager
import com.google.android.material.snackbar.Snackbar
@ -25,6 +23,7 @@ import androidx.core.view.isVisible
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.findNavController
import androidx.navigation.ui.*
import com.afollestad.materialdialogs.MaterialDialog
import com.bumptech.glide.Glide
import com.coldmint.rust.core.CompressionManager
import com.coldmint.rust.core.TemplatePackage
@ -42,6 +41,8 @@ import com.coldmint.rust.core.web.ServerConfiguration
import com.coldmint.rust.pro.databinding.ActivityMainBinding
import com.coldmint.rust.pro.databinding.HeadLayoutBinding
import com.coldmint.rust.pro.viewmodel.StartViewModel
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.tabs.TabLayout
import com.google.gson.Gson
import com.permissionx.guolindev.PermissionX
@ -188,23 +189,23 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
}
//显示对话框
runOnUiThread {
val materialDialog = MaterialDialog(this@MainActivity, BottomSheet())
materialDialog.title(text = data.title).message(text = data.content)
val materialAlertDialogBuilder =
MaterialAlertDialogBuilder(this).setTitle(data.title).setMessage(data.content)
if (data.forced) {
materialDialog.noAutoDismiss()
//禁用点击空白关闭
materialDialog.cancelable(false)
materialAlertDialogBuilder.setCancelable(false)
} else {
materialDialog.negativeButton(
materialAlertDialogBuilder.setNegativeButton(
R.string.dialog_cancel
)
) { i, i2 ->
}
materialDialog.positiveButton(
}
materialAlertDialogBuilder.setPositiveButton(
R.string.downlod
) {
) { i, i2 ->
AppOperator.useBrowserAccessWebPage(this, data.link)
}
materialDialog.show()
materialAlertDialogBuilder.show()
}
}
}
@ -223,20 +224,19 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
val versionCode = packageInfo.versionCode
//如果在1.15 p3及以上 (159)
if (versionCode >= 159) {
MaterialDialog(this).show {
title(R.string.game_configured).message(R.string.unable_to_detect)
.positiveButton(R.string.show_details)
.positiveButton {
MaterialAlertDialogBuilder(this).setTitle(R.string.game_configured)
.setMessage(R.string.unable_to_detect)
.setPositiveButton(R.string.show_details) { i, i2 ->
startActivity(
Intent(
this@MainActivity,
GameCheckActivity::class.java
)
)
}.neutralButton(R.string.no_longer_prompt).neutralButton {
}.setNeutralButton(R.string.no_longer_prompt) { i, i2 ->
appSettings.setValue(AppSettings.Setting.SetGameStorage, true)
}.negativeButton(R.string.dialog_cancel).cancelable(false)
}
}.setNeutralButton(R.string.dialog_cancel) { i, i2 ->
}.setCancelable(false).show()
} else {
appSettings.setValue(AppSettings.Setting.SetGameStorage, true)
}
@ -319,29 +319,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
startActivity(intent)
}
templateItem -> {
val popupMenu = PopupMenu(this@MainActivity, viewBinding.mainButton)
popupMenu.menu.add(R.string.create_template)
popupMenu.menu.add(R.string.import_template)
popupMenu.setOnMenuItemClickListener { item ->
val title = item.title.toString()
if (title == getString(R.string.create_template)) {
startActivity(
Intent(
this@MainActivity,
CreateTemplateActivity::class.java
)
)
} else if (title == getString(R.string.import_template)) {
val startIntent =
Intent(this@MainActivity, FileManagerActivity::class.java)
val fileBundle = Bundle()
fileBundle.putString("type", "selectFile")
startIntent.putExtra("data", fileBundle)
startActivityForResult(startIntent, 2)
}
true
}
popupMenu.show()
val intent = Intent(this, CreationWizardActivity::class.java)
intent.putExtra("type", "template")
startActivity(intent)
}
else -> {
Toast.makeText(this@MainActivity, "请设置事件", Toast.LENGTH_SHORT).show()
@ -581,17 +561,16 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
}
if (newInfo.versionNum < oldInfo.versionNum) {
handler.post {
MaterialDialog(this).show {
title(text = oldInfo.name).cancelable(false).message(
text = String.format(
MaterialAlertDialogBuilder(this).setTitle(oldInfo.name).setMessage(
String.format(
getString(R.string.covers_the_import),
newInfo.versionName, oldInfo.versionName
)
).positiveButton(R.string.dialog_ok).positiveButton {
).setPositiveButton(R.string.dialog_ok) { i, i2 ->
FileOperator.delete_files(templateDirectory)
importTemplate(formFile, templateDirectory)
}.negativeButton(R.string.dialog_cancel)
}
}.setNegativeButton(R.string.dialog_cancel) { i, i2 ->
}.show()
}
return@Runnable
} else {
@ -663,16 +642,15 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_DOWN) {
MaterialDialog(this).show {
title(R.string.dialog_close).message(
text = String.format(
MaterialAlertDialogBuilder(this).setTitle(R.string.dialog_close).setMessage(
String.format(
getString(R.string.exit_tip),
getString(R.string.app_name)
)
).cancelable(false).positiveButton(R.string.dialog_ok) {
).setPositiveButton(R.string.dialog_ok) { i, i2 ->
finish()
}.negativeButton(R.string.dialog_cancel)
}
}.setNegativeButton(R.string.dialog_cancel) { i, i2 ->
}.show()
return true
}
return super.onKeyDown(keyCode, event)
@ -722,19 +700,17 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
startViewModel.needLoginLiveData.observe(this) {
if (it) {
MaterialDialog(this, BottomSheet()).show {
title(R.string.login).message(R.string.login_tip).cancelable(false)
.positiveButton(R.string.login) {
MaterialAlertDialogBuilder(this).setTitle(R.string.login)
.setMessage(R.string.login_tip).setPositiveButton(R.string.login) { i, i2 ->
startActivity(
Intent(
context,
this,
LoginActivity::class.java
)
)
}.negativeButton(R.string.dialog_close).negativeButton {
}.setNegativeButton(R.string.dialog_close) { i, i2 ->
finish()
}
}
}.show()
} else {
showGameConfiguredDialog()
}

View File

@ -14,15 +14,15 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.checkbox.checkBoxPrompt
import com.coldmint.rust.pro.R
import com.coldmint.rust.pro.databinding.ActivityWebModInfoBinding
import com.coldmint.rust.pro.interfaces.ItemChangeEvent
import com.coldmint.rust.pro.interfaces.ItemEvent
import android.text.style.ForegroundColorSpan
import android.text.style.StyleSpan
import androidx.appcompat.app.AlertDialog
import androidx.core.text.toSpannable
import com.google.android.material.dialog.MaterialAlertDialogBuilder
abstract class BaseAdapter<ViewBindingType : ViewBinding, DataType>(
@ -147,38 +147,39 @@ abstract class BaseAdapter<ViewBindingType : ViewBinding, DataType>(
* @param cancelable Boolean 是否可取消
* @param checkBoxPrompt 选择框显示的文本
*/
@Deprecated("已废弃")
fun showDeleteItemDialog(
name: String,
index: Int,
onClickPositiveButton: ((MaterialDialog, Boolean) -> Boolean)? = null,
onClickPositiveButton: ((Int, Boolean) -> Boolean)? = null,
cancelable: Boolean = false,
checkBoxPrompt: String? = null
): MaterialDialog {
var checked = false
val dialog = MaterialDialog(context)
if (checkBoxPrompt != null) {
dialog.checkBoxPrompt(text = checkBoxPrompt, onToggle = {
checked = it
})
}
dialog.title(R.string.delete_title).message(
text = String.format(
context.getString(R.string.delete_prompt),
name
)
).positiveButton(R.string.dialog_ok).positiveButton {
if (onClickPositiveButton == null) {
removeItem(index)
} else {
if (onClickPositiveButton.invoke(dialog, checked)) {
removeItem(index)
}
}
}.negativeButton(R.string.dialog_cancel).cancelable(cancelable)
handler.post {
dialog.show()
}
return dialog
) {
// var checked = false
// val dialog = MaterialAlertDialogBuilder(context)
// if (checkBoxPrompt != null) {
// dialog.checkBoxPrompt(text = checkBoxPrompt, onToggle = {
// checked = it
// })
// }
// dialog.title(R.string.delete_title).message(
// text = String.format(
// context.getString(R.string.delete_prompt),
// name
// )
// ).positiveButton(R.string.dialog_ok).positiveButton {
// if (onClickPositiveButton == null) {
// removeItem(index)
// } else {
// if (onClickPositiveButton.invoke(dialog, checked)) {
// removeItem(index)
// }
// }
// }.negativeButton(R.string.dialog_cancel).cancelable(cancelable)
// handler.post {
// dialog.show()
// }
// return dialog
}
/**

View File

@ -119,6 +119,7 @@
<string name="open_action1">编辑文本</string>
<string name="import_template">导入模板包</string>
<string name="import_template_describe">从文件管理导入模板包。</string>
<string name="import_mod">导入模组</string>
<string name="import_mod_from_file_manager_describe">从文件管理导入模组。</string>
<string name="import_mod_from_recycle_bin">回收站</string>
@ -193,6 +194,7 @@
<string name="attach">附加</string>
<string name="template_name">模板名称</string>
<string name="create_template">创建模板包</string>
<string name="create_template_describe">创建一个模板包,用于存放单位动态模板。</string>
<string name="template_name_error">请输入模板名称。</string>
<string name="template_developer_error">请输入开发者。</string>
<string name="template_description_error">请输入描述。</string>

View File

@ -4,5 +4,5 @@
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Wed Jul 06 10:56:35 CST 2022
sdk.dir=D\:\\Android_SDK
#Wed Jul 06 21:08:32 CST 2022
sdk.dir=D\:\\Document\\AndroidSdk