diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/adapters/HistoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/adapters/HistoryAdapter.kt index a052c397..dc555ba2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/adapters/HistoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/adapters/HistoryAdapter.kt @@ -1,6 +1,5 @@ package com.simplemobiletools.calculator.adapters -import android.app.Dialog import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView @@ -12,10 +11,9 @@ import com.simplemobiletools.calculator.models.History import com.simplemobiletools.commons.extensions.copyToClipboard import kotlinx.android.synthetic.main.history_view.view.* -class HistoryAdapter(val activity: SimpleActivity, val items: List, val calc: CalculatorImpl) : +class HistoryAdapter(val activity: SimpleActivity, val items: List, val calc: CalculatorImpl, val itemClick: () -> Unit) : RecyclerView.Adapter() { - private lateinit var dialog: Dialog private var textColor = activity.config.textColor override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { @@ -30,10 +28,6 @@ class HistoryAdapter(val activity: SimpleActivity, val items: List, val override fun getItemCount() = items.size - fun setDialog(dialog: Dialog) { - this.dialog = dialog - } - inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { fun bindView(item: History): View { itemView.apply { @@ -44,7 +38,7 @@ class HistoryAdapter(val activity: SimpleActivity, val items: List, val setOnClickListener { calc.addNumberToFormula(item.result) - dialog.dismiss() + itemClick() } setOnLongClickListener { activity.baseContext.copyToClipboard(item.result) diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/dialogs/HistoryDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/dialogs/HistoryDialog.kt index 6cd97acf..9931f70d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/dialogs/HistoryDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/dialogs/HistoryDialog.kt @@ -15,19 +15,20 @@ import kotlinx.android.synthetic.main.dialog_history.view.* class HistoryDialog() { constructor(activity: SimpleActivity, items: List, calculator: CalculatorImpl) : this() { val view = activity.layoutInflater.inflate(R.layout.dialog_history, null) - view.history_list.adapter = HistoryAdapter(activity, items, calculator) - AlertDialog.Builder(activity) + val dialog = AlertDialog.Builder(activity) .setPositiveButton(R.string.ok, null) .setNeutralButton(R.string.clear_history) { _, _ -> ensureBackgroundThread { activity.applicationContext.calculatorDB.deleteHistory() activity.toast(R.string.history_cleared) } - } - .create().apply { + }.create().apply { activity.setupDialogStuff(view, this, R.string.history) - (view.history_list.adapter as HistoryAdapter).setDialog(this) } + + view.history_list.adapter = HistoryAdapter(activity, items, calculator) { + dialog.dismiss() + } } }