2019-11-20 09:50:40 +11:00
|
|
|
package org.thoughtcrime.securesms.loki
|
|
|
|
|
2019-11-20 14:55:42 +11:00
|
|
|
import android.os.AsyncTask
|
2019-11-20 09:50:40 +11:00
|
|
|
import android.os.Bundle
|
|
|
|
import android.view.MenuItem
|
|
|
|
import android.widget.Toast
|
|
|
|
import org.thoughtcrime.securesms.*
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage
|
|
|
|
import network.loki.messenger.R
|
2019-11-21 12:43:33 +11:00
|
|
|
import nl.komponents.kovenant.then
|
2019-11-20 09:50:40 +11:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory
|
|
|
|
import org.thoughtcrime.securesms.sms.MessageSender
|
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
2019-11-20 14:55:42 +11:00
|
|
|
import org.thoughtcrime.securesms.util.Util
|
2019-11-20 09:50:40 +11:00
|
|
|
import org.whispersystems.signalservice.loki.api.LokiStorageAPI
|
2019-11-20 11:44:44 +11:00
|
|
|
import org.whispersystems.signalservice.loki.api.PairingAuthorisation
|
2019-11-20 09:50:40 +11:00
|
|
|
|
2019-11-20 14:55:42 +11:00
|
|
|
class LinkedDevicesActivity : PassphraseRequiredActionBarActivity(), DeviceLinkingDelegate {
|
2019-11-20 09:50:40 +11:00
|
|
|
|
|
|
|
companion object {
|
|
|
|
private val TAG = DeviceActivity::class.java.simpleName
|
|
|
|
}
|
|
|
|
|
|
|
|
private val dynamicTheme = DynamicTheme()
|
|
|
|
private val dynamicLanguage = DynamicLanguage()
|
|
|
|
private lateinit var deviceListFragment: DeviceListFragment
|
|
|
|
|
|
|
|
public override fun onPreCreate() {
|
|
|
|
dynamicTheme.onCreate(this)
|
|
|
|
dynamicLanguage.onCreate(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?, ready: Boolean) {
|
|
|
|
super.onCreate(savedInstanceState, ready)
|
|
|
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
|
|
|
supportActionBar?.setTitle(R.string.AndroidManifest__linked_devices)
|
|
|
|
this.deviceListFragment = DeviceListFragment()
|
|
|
|
this.deviceListFragment.setAddDeviceButtonListener {
|
2019-11-20 11:44:44 +11:00
|
|
|
DeviceLinkingDialog.show(this, DeviceLinkingView.Mode.Master, this)
|
2019-11-20 09:50:40 +11:00
|
|
|
}
|
|
|
|
this.deviceListFragment.setHandleDisconnectDevice { devicePublicKey ->
|
|
|
|
// Purge the device pairing from our database
|
|
|
|
val ourPublicKey = TextSecurePreferences.getLocalNumber(this)
|
|
|
|
val database = DatabaseFactory.getLokiAPIDatabase(this)
|
|
|
|
database.removePairingAuthorisation(ourPublicKey, devicePublicKey)
|
|
|
|
// Update mapping on the file server
|
2019-11-21 12:43:33 +11:00
|
|
|
LokiStorageAPI.shared.updateUserDeviceMappings().success {
|
|
|
|
// Send an unpair request to let the device know that it has been revoked
|
|
|
|
MessageSender.sendUnpairRequest(this, devicePublicKey)
|
|
|
|
}
|
2019-11-20 09:50:40 +11:00
|
|
|
// Refresh the list
|
2019-11-20 11:44:44 +11:00
|
|
|
this.deviceListFragment.refresh()
|
2019-11-20 09:50:40 +11:00
|
|
|
Toast.makeText(this, R.string.DeviceListActivity_unlinked_device, Toast.LENGTH_LONG).show()
|
|
|
|
return@setHandleDisconnectDevice null
|
|
|
|
}
|
2019-11-21 10:50:33 +11:00
|
|
|
this.deviceListFragment.setHandleDeviceNameChange { pair ->
|
|
|
|
DatabaseFactory.getLokiUserDatabase(this).setDisplayName(pair.first, pair.second)
|
|
|
|
this.deviceListFragment.refresh()
|
|
|
|
return@setHandleDeviceNameChange null
|
|
|
|
}
|
2019-11-20 09:50:40 +11:00
|
|
|
initFragment(android.R.id.content, deviceListFragment, dynamicLanguage.currentLocale)
|
|
|
|
}
|
|
|
|
|
|
|
|
public override fun onResume() {
|
|
|
|
super.onResume()
|
|
|
|
dynamicTheme.onResume(this)
|
|
|
|
dynamicLanguage.onResume(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
|
|
if (item.itemId == android.R.id.home) {
|
|
|
|
finish()
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2019-11-20 11:44:44 +11:00
|
|
|
|
|
|
|
override fun sendPairingAuthorizedMessage(pairingAuthorisation: PairingAuthorisation) {
|
2019-11-20 14:55:42 +11:00
|
|
|
AsyncTask.execute {
|
|
|
|
signAndSendPairingAuthorisationMessage(this, pairingAuthorisation)
|
|
|
|
Util.runOnMain { this.deviceListFragment.refresh() }
|
|
|
|
}
|
|
|
|
}
|
2019-11-20 09:50:40 +11:00
|
|
|
}
|