Skip to content

Commit

Permalink
feat: add confirm delete all function
Browse files Browse the repository at this point in the history
  • Loading branch information
shitlime committed Aug 1, 2023
1 parent 7c50708 commit 7120e40
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
18 changes: 17 additions & 1 deletion app/src/main/java/com/osfans/trime/ime/symbol/FlexibleAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.PopupMenu
import androidx.appcompat.app.AlertDialog
import androidx.cardview.widget.CardView
import androidx.lifecycle.findViewTreeLifecycleOwner
import androidx.lifecycle.lifecycleScope
Expand All @@ -16,6 +17,8 @@ import com.osfans.trime.data.db.DatabaseBean
import com.osfans.trime.data.theme.FontManager
import com.osfans.trime.data.theme.Theme
import com.osfans.trime.databinding.SimpleKeyItemBinding
import com.osfans.trime.ime.core.Trime
import com.osfans.trime.util.appContext
import kotlinx.coroutines.launch

class FlexibleAdapter(
Expand Down Expand Up @@ -159,7 +162,7 @@ class FlexibleAdapter(
setIcon(R.drawable.ic_baseline_delete_sweep_24)
setOnMenuItemClickListener {
scope.launch {
listener.onDeleteAll()
askToDeleteAll()
}
true
}
Expand Down Expand Up @@ -193,6 +196,19 @@ class FlexibleAdapter(
updateBeans(mBeans)
}

private fun askToDeleteAll() {
val service = Trime.getService()
val askDialog = AlertDialog.Builder(
appContext, androidx.appcompat.R.style.Theme_AppCompat_DayNight_Dialog_Alert
).setTitle("Delete All ?").setPositiveButton("Yes") { dialog, which ->
service.lifecycleScope.launch {
listener.onDeleteAll()
}
}.setNegativeButton("No") { dialog, which ->
}.create()
service.showDialogAboveInputView(askDialog)
}

// 添加回调
interface Listener {
fun onPaste(bean: DatabaseBean)
Expand Down
21 changes: 12 additions & 9 deletions app/src/main/java/com/osfans/trime/ime/symbol/LiquidKeyboard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,17 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard
}
}

private fun launchLiquidKeyboardEditText(context: Context, type: SymbolKeyboardType, id: Int, text: String) {
context.startActivity(
Intent(context, LiquidKeyboardEditActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtra(LiquidKeyboardEditActivity.DB_BEAN_ID, id)
putExtra(LiquidKeyboardEditActivity.DB_BEAN_TEXT, text)
putExtra(LiquidKeyboardEditActivity.LIQUID_KEYBOARD_TYPE, type.name)
}
)
private fun launchLiquidKeyboardEditText(
context: Context,
type: SymbolKeyboardType,
id: Int,
text: String
) {
context.startActivity(Intent(context, LiquidKeyboardEditActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtra(LiquidKeyboardEditActivity.DB_BEAN_ID, id)
putExtra(LiquidKeyboardEditActivity.DB_BEAN_TEXT, text)
putExtra(LiquidKeyboardEditActivity.LIQUID_KEYBOARD_TYPE, type.name)
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class LiquidKeyboardEditActivity : AppCompatActivity() {
val text = intent.getStringExtra(DB_BEAN_TEXT)
editText.setText(text)
Timber.d(
"LiquidKeyboardEditActivity:" +
"processIntent (type=$type, id=$id, text=$text)"
"LiquidKeyboardEditActivity:" + "processIntent (type=$type, id=$id, text=$text)"
)
}
}
Expand Down Expand Up @@ -83,6 +82,11 @@ class LiquidKeyboardEditActivity : AppCompatActivity() {
super.onNewIntent(intent)
}

override fun onStop() {
super.onStop()
finish()
}

companion object {
const val DB_BEAN_ID = "db_bean_id"
const val DB_BEAN_TEXT = "db_bean_text"
Expand Down

0 comments on commit 7120e40

Please sign in to comment.