mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-25 20:47:20 +00:00
Allow users to edit device name.
This commit is contained in:
parent
b61b4c581d
commit
c66786e0f1
@ -11,7 +11,7 @@
|
|||||||
android:id="@+id/editDisplayNameText"
|
android:id="@+id/editDisplayNameText"
|
||||||
style="@style/ActionItem"
|
style="@style/ActionItem"
|
||||||
android:drawableStart="@drawable/ic_edit_white_24dp"
|
android:drawableStart="@drawable/ic_edit_white_24dp"
|
||||||
android:text="@string/fragment_device_list_edit_display_name_title"/>
|
android:text="@string/fragment_device_list_edit_device_name_title"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/unlinkDeviceText"
|
android:id="@+id/unlinkDeviceText"
|
||||||
|
@ -300,6 +300,7 @@
|
|||||||
<string name="DeviceListActivity_unlinking_device_no_ellipsis">Unlinking device</string>
|
<string name="DeviceListActivity_unlinking_device_no_ellipsis">Unlinking device</string>
|
||||||
<string name="DeviceListActivity_network_failed">Network failed!</string>
|
<string name="DeviceListActivity_network_failed">Network failed!</string>
|
||||||
<string name="DeviceListActivity_unlinked_device">Successfully unlinked device</string>
|
<string name="DeviceListActivity_unlinked_device">Successfully unlinked device</string>
|
||||||
|
<string name="DeviceListActivity_edit_device_name">Edit device name</string>
|
||||||
|
|
||||||
<!-- DeviceListItem -->
|
<!-- DeviceListItem -->
|
||||||
<string name="DeviceListItem_unnamed_device">Unnamed device</string>
|
<string name="DeviceListItem_unnamed_device">Unnamed device</string>
|
||||||
@ -1644,7 +1645,7 @@
|
|||||||
<!-- Conversation list activity -->
|
<!-- Conversation list activity -->
|
||||||
<string name="activity_conversation_list_add_public_chat_button_title">Add Public Chat</string>
|
<string name="activity_conversation_list_add_public_chat_button_title">Add Public Chat</string>
|
||||||
<!-- Device list bottom sheet fragment -->
|
<!-- Device list bottom sheet fragment -->
|
||||||
<string name="fragment_device_list_edit_display_name_title">Edit display name</string>
|
<string name="fragment_device_list_edit_device_name_title">Edit device name</string>
|
||||||
<string name="fragment_device_list_unlink_device_title">Unlink device</string>
|
<string name="fragment_device_list_unlink_device_title">Unlink device</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -15,6 +15,7 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
import com.melnykov.fab.FloatingActionButton;
|
import com.melnykov.fab.FloatingActionButton;
|
||||||
@ -34,6 +35,8 @@ import java.util.Locale;
|
|||||||
|
|
||||||
import org.whispersystems.libsignal.util.guava.Function;
|
import org.whispersystems.libsignal.util.guava.Function;
|
||||||
|
|
||||||
|
import kotlin.Pair;
|
||||||
|
import kotlin.Unit;
|
||||||
import network.loki.messenger.R;
|
import network.loki.messenger.R;
|
||||||
|
|
||||||
public class DeviceListFragment extends ListFragment
|
public class DeviceListFragment extends ListFragment
|
||||||
@ -50,6 +53,7 @@ public class DeviceListFragment extends ListFragment
|
|||||||
private FloatingActionButton addDeviceButton;
|
private FloatingActionButton addDeviceButton;
|
||||||
private Button.OnClickListener addDeviceButtonListener;
|
private Button.OnClickListener addDeviceButtonListener;
|
||||||
private Function<String, Void> handleDisconnectDevice;
|
private Function<String, Void> handleDisconnectDevice;
|
||||||
|
private Function<Pair<String, String>, Void> handleDeviceNameChange;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@ -92,6 +96,10 @@ public class DeviceListFragment extends ListFragment
|
|||||||
this.handleDisconnectDevice = handler;
|
this.handleDisconnectDevice = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setHandleDeviceNameChange(Function<Pair<String, String>, Void> handler) {
|
||||||
|
this.handleDeviceNameChange = handler;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull Loader<List<Device>> onCreateLoader(int id, Bundle args) {
|
public @NonNull Loader<List<Device>> onCreateLoader(int id, Bundle args) {
|
||||||
empty.setVisibility(View.GONE);
|
empty.setVisibility(View.GONE);
|
||||||
@ -126,12 +134,30 @@ public class DeviceListFragment extends ListFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
final boolean hasDeviceName = ((DeviceListItem)view).hasDeviceName(); // Tells us whether the name is set to shortId or the device name
|
||||||
final String deviceName = ((DeviceListItem)view).getDeviceName();
|
final String deviceName = ((DeviceListItem)view).getDeviceName();
|
||||||
final String deviceId = ((DeviceListItem)view).getDeviceId();
|
final String deviceId = ((DeviceListItem)view).getDeviceId();
|
||||||
|
|
||||||
DeviceListBottomSheetFragment fragment = new DeviceListBottomSheetFragment();
|
DeviceListBottomSheetFragment bottomSheet = new DeviceListBottomSheetFragment();
|
||||||
fragment.show(getFragmentManager(), fragment.getTag());
|
bottomSheet.setOnEditTapped(() -> {
|
||||||
/*
|
bottomSheet.dismiss();
|
||||||
|
EditText deviceNameText = new EditText(getContext());
|
||||||
|
deviceNameText.setText(hasDeviceName ? deviceName : "");
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
|
builder.setTitle(R.string.DeviceListActivity_edit_device_name);
|
||||||
|
builder.setView(deviceNameText);
|
||||||
|
builder.setNegativeButton(android.R.string.cancel, null);
|
||||||
|
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
if (handleDeviceNameChange != null) { handleDeviceNameChange.apply(new Pair<>(deviceId, deviceNameText.getText().toString().trim())); }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.show();
|
||||||
|
return Unit.INSTANCE;
|
||||||
|
});
|
||||||
|
bottomSheet.setOnUnlinkTapped(() -> {
|
||||||
|
bottomSheet.dismiss();
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
builder.setTitle(getActivity().getString(R.string.DeviceListActivity_unlink_s, deviceName));
|
builder.setTitle(getActivity().getString(R.string.DeviceListActivity_unlink_s, deviceName));
|
||||||
builder.setMessage(R.string.DeviceListActivity_by_unlinking_this_device_it_will_no_longer_be_able_to_send_or_receive);
|
builder.setMessage(R.string.DeviceListActivity_by_unlinking_this_device_it_will_no_longer_be_able_to_send_or_receive);
|
||||||
@ -143,8 +169,9 @@ public class DeviceListFragment extends ListFragment
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.show();
|
builder.show();
|
||||||
|
return Unit.INSTANCE;
|
||||||
*/
|
});
|
||||||
|
bottomSheet.show(getFragmentManager(), bottomSheet.getTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
|
@ -50,4 +50,8 @@ public class DeviceListItem extends LinearLayout {
|
|||||||
return name.getText().toString();
|
return name.getText().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasDeviceName() {
|
||||||
|
return shortId.getVisibility() == VISIBLE;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,11 @@ class LinkedDevicesActivity : PassphraseRequiredActionBarActivity(), DeviceLinki
|
|||||||
Toast.makeText(this, R.string.DeviceListActivity_unlinked_device, Toast.LENGTH_LONG).show()
|
Toast.makeText(this, R.string.DeviceListActivity_unlinked_device, Toast.LENGTH_LONG).show()
|
||||||
return@setHandleDisconnectDevice null
|
return@setHandleDisconnectDevice null
|
||||||
}
|
}
|
||||||
|
this.deviceListFragment.setHandleDeviceNameChange { pair ->
|
||||||
|
DatabaseFactory.getLokiUserDatabase(this).setDisplayName(pair.first, pair.second)
|
||||||
|
this.deviceListFragment.refresh()
|
||||||
|
return@setHandleDeviceNameChange null
|
||||||
|
}
|
||||||
initFragment(android.R.id.content, deviceListFragment, dynamicLanguage.currentLocale)
|
initFragment(android.R.id.content, deviceListFragment, dynamicLanguage.currentLocale)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user