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

Commit 9aca458

Browse files
committed
Switch realm on listView item click
1 parent 635536f commit 9aca458

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

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

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

0 commit comments

Comments
 (0)