Move device linking logic into LinkedDeviceActivity.

This commit is contained in:
Mikunj
2019-11-20 11:44:44 +11:00
parent 0f5db5aa33
commit ba78fcb9b1
4 changed files with 20 additions and 17 deletions

View File

@@ -3,7 +3,6 @@ package org.thoughtcrime.securesms.loki
import org.whispersystems.signalservice.loki.api.PairingAuthorisation
interface DeviceLinkingDialogDelegate {
fun handleDeviceLinkAuthorized(pairingAuthorisation: PairingAuthorisation) { }
fun handleDeviceLinkingDialogDismissed() { }
fun sendPairingAuthorizedMessage(pairingAuthorisation: PairingAuthorisation) { }

View File

@@ -11,8 +11,9 @@ import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.sms.MessageSender
import org.thoughtcrime.securesms.util.TextSecurePreferences
import org.whispersystems.signalservice.loki.api.LokiStorageAPI
import org.whispersystems.signalservice.loki.api.PairingAuthorisation
class LinkedDevicesActivity : PassphraseRequiredActionBarActivity() {
class LinkedDevicesActivity : PassphraseRequiredActionBarActivity(), DeviceLinkingDialogDelegate {
companion object {
private val TAG = DeviceActivity::class.java.simpleName
@@ -33,7 +34,7 @@ class LinkedDevicesActivity : PassphraseRequiredActionBarActivity() {
supportActionBar?.setTitle(R.string.AndroidManifest__linked_devices)
this.deviceListFragment = DeviceListFragment()
this.deviceListFragment.setAddDeviceButtonListener {
// TODO: Hook up add device
DeviceLinkingDialog.show(this, DeviceLinkingView.Mode.Master, this)
}
this.deviceListFragment.setHandleDisconnectDevice { devicePublicKey ->
// Purge the device pairing from our database
@@ -45,19 +46,11 @@ class LinkedDevicesActivity : PassphraseRequiredActionBarActivity() {
// Send a background message to let the device know that it has been revoked
MessageSender.sendBackgroundMessage(this, devicePublicKey)
// Refresh the list
refresh()
this.deviceListFragment.refresh()
Toast.makeText(this, R.string.DeviceListActivity_unlinked_device, Toast.LENGTH_LONG).show()
return@setHandleDisconnectDevice null
}
initFragment(android.R.id.content, deviceListFragment, dynamicLanguage.currentLocale)
refresh()
}
private fun refresh() {
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this)
val isDeviceLinkingEnabled = DatabaseFactory.getLokiAPIDatabase(this).getPairingAuthorisations(userHexEncodedPublicKey).isEmpty()
this.deviceListFragment.setAddDeviceButtonVisible(isDeviceLinkingEnabled)
this.deviceListFragment.refresh()
}
public override fun onResume() {
@@ -73,4 +66,9 @@ class LinkedDevicesActivity : PassphraseRequiredActionBarActivity() {
}
return false
}
override fun sendPairingAuthorizedMessage(pairingAuthorisation: PairingAuthorisation) {
signAndSendPairingAuthorisationMessage(this, pairingAuthorisation)
this.deviceListFragment.refresh()
}
}