mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
Move device linking logic into LinkedDeviceActivity.
This commit is contained in:
parent
0f5db5aa33
commit
ba78fcb9b1
@ -353,7 +353,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
||||
case PREFERENCE_CATEGORY_LINKED_DEVICES:
|
||||
Intent intent = new Intent(getActivity(), LinkedDevicesActivity.class);
|
||||
startActivity(intent);
|
||||
DeviceLinkingDialog.Companion.show(getContext(), DeviceLinkingView.Mode.Master, this);
|
||||
break;
|
||||
case PREFERENCE_CATEGORY_SEED:
|
||||
Analytics.Companion.getShared().track("Seed Modal Shown");
|
||||
|
@ -19,6 +19,7 @@ import android.widget.ListView;
|
||||
|
||||
import com.melnykov.fab.FloatingActionButton;
|
||||
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.loaders.DeviceListLoader;
|
||||
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
||||
import org.thoughtcrime.securesms.devicelist.Device;
|
||||
@ -69,6 +70,7 @@ public class DeviceListFragment extends ListFragment
|
||||
this.progressContainer = view.findViewById(R.id.progress_container);
|
||||
this.addDeviceButton = ViewUtil.findById(view, R.id.add_device);
|
||||
this.addDeviceButton.setOnClickListener(this);
|
||||
updateAddDeviceButtonVisibility();
|
||||
|
||||
return view;
|
||||
}
|
||||
@ -89,10 +91,6 @@ public class DeviceListFragment extends ListFragment
|
||||
this.handleDisconnectDevice = handler;
|
||||
}
|
||||
|
||||
public void setAddDeviceButtonVisible(boolean visible) {
|
||||
addDeviceButton.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Loader<List<Device>> onCreateLoader(int id, Bundle args) {
|
||||
empty.setVisibility(View.GONE);
|
||||
@ -144,9 +142,18 @@ public class DeviceListFragment extends ListFragment
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
updateAddDeviceButtonVisibility();
|
||||
getLoaderManager().restartLoader(0, null, DeviceListFragment.this);
|
||||
}
|
||||
|
||||
private void updateAddDeviceButtonVisibility() {
|
||||
if (addDeviceButton != null) {
|
||||
String userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(getContext());
|
||||
boolean isDeviceLinkingEnabled = DatabaseFactory.getLokiAPIDatabase(getContext()).getPairingAuthorisations(userHexEncodedPublicKey).isEmpty();
|
||||
addDeviceButton.setVisibility(isDeviceLinkingEnabled ? View.VISIBLE : View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleLoaderFailed() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setMessage(R.string.DeviceListActivity_network_connection_failed);
|
||||
|
@ -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) { }
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user