Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit f7716ce

Browse files
committed
Switch realm on listView item click
1 parent b050b83 commit f7716ce

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

app/src/main/java/com/zulip/android/activities/RealmDialog.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,36 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
5252
realmsList = new ArrayList<String>(app.serverStringSet);
5353
realmsAdapter = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, realmsList);
5454
listView.setAdapter(realmsAdapter);
55+
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
56+
@Override
57+
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
58+
new AlertDialog.Builder(context)
59+
.setTitle(R.string.realm_switch)
60+
.setMessage(context.getString(R.string.realm_switch_confirm, realmsAdapter.getItem(position)))
61+
.setPositiveButton(getResources().getString(android.R.string.yes), new DialogInterface.OnClickListener() {
62+
public void onClick(final DialogInterface dialog, int whichButton) {
63+
if (position == app.currentRealm) {
64+
Toast.makeText(context, R.string.realm_this_is_current, Toast.LENGTH_LONG).show();
65+
return;
66+
}
67+
final ProgressDialog progressDialog = new ProgressDialog(getActivity());
68+
progressDialog.setCancelable(false);
69+
progressDialog.setTitle(app.getString(R.string.realm_switching));
70+
progressDialog.setMessage(app.getString(R.string.please_wait));
71+
progressDialog.show();
72+
((ZulipActivity) getActivity()).switchRealm(progressDialog, position);
73+
if (RealmDialog.this.getDialog() != null)
74+
RealmDialog.this.getDialog().cancel();
75+
}
76+
})
77+
.setNegativeButton(getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
78+
public void onClick(DialogInterface dialog, int whichButton) {
79+
dialog.dismiss();
80+
}
81+
})
82+
.show();
83+
}
84+
});
5585
builder.setView(rootView)
5686
.setPositiveButton(R.string.realm_add, new DialogInterface.OnClickListener() {
5787
@Override

app/src/main/res/values/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,10 @@
6464

6565
<string name="tap_message">Tap on a message to send reply</string>
6666
<string name="realm_title">Realms</string>
67+
<string name="realm_switch">Switch to this Realm</string>
68+
<string name="realm_switch_confirm">"Do you want to switch to %s ?"</string>
69+
<string name="realm_this_is_current">This is the current realm only!</string>
70+
<string name="realm_switching">Switching Realm</string>
71+
<string name="please_wait">Please wait</string>
6772
<string name="realm_add">Add Realm</string>
6873
</resources>

0 commit comments

Comments
 (0)