diff --git a/app/build.gradle b/app/build.gradle index bc25dd4..caf1b5f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -57,6 +57,7 @@ dependencies { // Tools implementation "io.paperdb:paperdb:$paperVersion" implementation "org.greenrobot:eventbus:$eventBusVersion" + implementation "com.afollestad.material-dialogs:core:$materialDialogsVersion" // Own implementation project(":konae") diff --git a/app/src/main/java/com/pavelrekun/rekado/services/dialogs/Dialogs.kt b/app/src/main/java/com/pavelrekun/rekado/services/dialogs/Dialogs.kt index edf668b..4c60d36 100644 --- a/app/src/main/java/com/pavelrekun/rekado/services/dialogs/Dialogs.kt +++ b/app/src/main/java/com/pavelrekun/rekado/services/dialogs/Dialogs.kt @@ -1,11 +1,12 @@ package com.pavelrekun.rekado.services.dialogs import android.content.Intent -import android.view.View -import android.widget.AdapterView import androidx.annotation.StringRes import androidx.appcompat.app.AlertDialog import androidx.core.app.ActivityCompat +import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.callbacks.onDismiss +import com.afollestad.materialdialogs.list.listItems import com.pavelrekun.rekado.R import com.pavelrekun.rekado.base.BaseActivity import com.pavelrekun.rekado.data.Payload @@ -26,47 +27,17 @@ object Dialogs { dialog.show() } - fun showPayloadsDialog(activity: BaseActivity): AlertDialog { - var dialog: AlertDialog? = null - - val builder = AlertDialog.Builder(activity) - builder.setTitle(R.string.dialog_loader_title) - builder.setSingleChoiceItems(PayloadHelper.getNames().toTypedArray(), 0, null) - builder.setOnDismissListener { EventBus.getDefault().post(Events.PayloadNotSelected()) } - builder.setOnItemSelectedListener(object : AdapterView.OnItemSelectedListener { - override fun onNothingSelected(parent: AdapterView<*>?) { - EventBus.getDefault().post(Events.PayloadNotSelected()) - } - - override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { - val name = PayloadHelper.getNames()[position] - PayloadHelper.putChosen(PayloadHelper.find(name) as Payload) - EventBus.getDefault().post(Events.PayloadSelected()) - dialog?.dismiss() - } - }) - - dialog = builder.create() - - /*val dialog = MaterialDialog.Builder(activity) + fun showPayloadsDialog(activity: BaseActivity): MaterialDialog { + val dialog = MaterialDialog(activity) .title(R.string.dialog_loader_title) - .backgroundColorRes(R.color.colorPrimary) - .contentColorAttr(android.R.attr.textColorPrimary) - .titleColorAttr(android.R.attr.textColorPrimary) - .items(PayloadHelper.getNames()) - .itemsCallback { dialog, _, _, name -> - PayloadHelper.putChosen(PayloadHelper.find(name.toString()) as Payload) + .listItems(items = PayloadHelper.getNames()) { dialog, index, text -> + PayloadHelper.putChosen(PayloadHelper.find(text) as Payload) EventBus.getDefault().post(Events.PayloadSelected()) dialog.hide() } + .onDismiss { EventBus.getDefault().post(Events.PayloadNotSelected()) } - .dismissListener { - EventBus.getDefault().post(Events.PayloadNotSelected()) - } - - .build() - - dialog.show()*/ + dialog.show() return dialog } diff --git a/app/src/main/java/com/pavelrekun/rekado/services/usb/USBReceiver.kt b/app/src/main/java/com/pavelrekun/rekado/services/usb/USBReceiver.kt index 4619f26..5238e12 100644 --- a/app/src/main/java/com/pavelrekun/rekado/services/usb/USBReceiver.kt +++ b/app/src/main/java/com/pavelrekun/rekado/services/usb/USBReceiver.kt @@ -3,7 +3,7 @@ package com.pavelrekun.rekado.services.usb import android.hardware.usb.UsbDevice import android.hardware.usb.UsbManager import android.os.Bundle -import androidx.appcompat.app.AlertDialog +import com.afollestad.materialdialogs.MaterialDialog import com.pavelrekun.rekado.base.BaseActivity import com.pavelrekun.rekado.services.dialogs.Dialogs import com.pavelrekun.rekado.services.eventbus.Events @@ -24,9 +24,7 @@ class USBReceiver : BaseActivity() { private var usbHandler: USBHandler? = null - private lateinit var payloadChooserDialog: AlertDialog - - // TODO: Check payloads dialog works after changing from MaterialDialog to AlertDialog + private lateinit var payloadChooserDialog: MaterialDialog override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/build.gradle b/build.gradle index 569bba4..37fcca5 100644 --- a/build.gradle +++ b/build.gradle @@ -31,6 +31,7 @@ ext { androidXCompatVersion = '1.0.0' androidXOtherVersion = '1.0.0' materialComponentsVersion = '1.0.0' + materialDialogsVersion = '2.0.0-beta5' paperVersion = '2.6' eventBusVersion = '3.1.1'