Skip to content

Commit

Permalink
- Updated MaterialDialog implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
MenosGrante committed Nov 20, 2018
1 parent 1850bc2 commit d9749f1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 42 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit d9749f1

Please sign in to comment.