mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-12 01:03:49 +00:00
WIP
This commit is contained in:
parent
e77ee30c9b
commit
d8e86a5e42
@ -7,27 +7,62 @@ import android.support.v7.app.AlertDialog
|
||||
import android.util.AttributeSet
|
||||
import android.widget.LinearLayout
|
||||
import kotlinx.android.synthetic.main.view_device_linking.view.*
|
||||
import kotlinx.android.synthetic.main.view_qr_code.view.cancelButton
|
||||
import network.loki.messenger.R
|
||||
|
||||
object DeviceLinkingDialog {
|
||||
|
||||
fun show(context: Context) {
|
||||
val view = DeviceLinkingView(context)
|
||||
fun show(context: Context, mode: DeviceLinkingView.Mode) {
|
||||
val view = DeviceLinkingView(context, mode)
|
||||
val dialog = AlertDialog.Builder(context).setView(view).show()
|
||||
view.onCancel = { dialog.dismiss() }
|
||||
}
|
||||
}
|
||||
|
||||
class DeviceLinkingView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : LinearLayout(context, attrs, defStyleAttr) {
|
||||
class DeviceLinkingView private constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : LinearLayout(context, attrs, defStyleAttr) {
|
||||
private lateinit var mode: Mode
|
||||
private var delegate: DeviceLinkingDialogDelegate? = null
|
||||
var onCancel: (() -> Unit)? = null
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
|
||||
constructor(context: Context) : this(context, null)
|
||||
// region Types
|
||||
enum class Mode { Master, Slave }
|
||||
// endregion
|
||||
|
||||
// region Lifecycle
|
||||
constructor(context: Context, mode: Mode) : this(context, null, 0) {
|
||||
this.mode = mode
|
||||
}
|
||||
private constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
|
||||
private constructor(context: Context) : this(context, null)
|
||||
|
||||
init {
|
||||
if (mode == Mode.Slave) {
|
||||
if (delegate == null) { throw IllegalStateException("Missing delegate for device linking dialog in slave mode.") }
|
||||
}
|
||||
setUpViewHierarchy()
|
||||
when (mode) {
|
||||
Mode.Master -> throw IllegalStateException() // DeviceLinkingSession.startListeningForLinkingRequests(this)
|
||||
Mode.Slave -> throw IllegalStateException() // DeviceLinkingSession.startListeningForAuthorization(this)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setUpViewHierarchy() {
|
||||
inflate(context, R.layout.view_device_linking, this)
|
||||
spinner.indeterminateDrawable.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN)
|
||||
cancelButton.setOnClickListener { onCancel?.invoke() }
|
||||
}
|
||||
// endregion
|
||||
|
||||
// region Device Linking
|
||||
private fun requestUserAuthorization() { // TODO: Device link
|
||||
// Called by DeviceLinkingSession when a linking request has been received
|
||||
}
|
||||
|
||||
private fun authorizeDeviceLink() {
|
||||
|
||||
}
|
||||
|
||||
private fun handleDeviceLinkAuthorized() { // TODO: Device link
|
||||
// Called by DeviceLinkingSession when a device link has been authorized
|
||||
}
|
||||
// endregion
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package org.thoughtcrime.securesms.loki
|
||||
|
||||
interface DeviceLinkingDialogDelegate {
|
||||
|
||||
fun handleDeviceLinkAuthorized() // TODO: Device link
|
||||
fun handleDeviceLinkingDialogDismissed()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user