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

Commit ee90be6

Browse files
Sam1301kunall17
authored andcommitted
Add custom dialog fragment ListDialog.
1 parent d151494 commit ee90be6

16 files changed

+171
-24
lines changed

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

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.annotation.TargetApi;
77
import android.app.AlertDialog;
88
import android.app.DatePickerDialog;
9+
import android.app.DialogFragment;
910
import android.app.NotificationManager;
1011
import android.app.PendingIntent;
1112
import android.app.SearchManager;
@@ -110,6 +111,7 @@
110111
import com.zulip.android.util.CommonProgressDialog;
111112
import com.zulip.android.util.Constants;
112113
import com.zulip.android.util.FileUtils;
114+
import com.zulip.android.util.ListDialog;
113115
import com.zulip.android.util.MutedTopics;
114116
import com.zulip.android.util.RemoveViewsOnScroll;
115117
import com.zulip.android.util.SwipeRemoveLinearLayout;
@@ -143,7 +145,8 @@
143145
* messages
144146
*/
145147
public class ZulipActivity extends BaseActivity implements
146-
MessageListFragment.Listener, NarrowListener, SwipeRemoveLinearLayout.leftToRightSwipeListener {
148+
MessageListFragment.Listener, NarrowListener, SwipeRemoveLinearLayout.leftToRightSwipeListener,
149+
ListDialog.ListDialogListener {
147150

148151
private static final String NARROW = "narrow";
149152
private static final String PARAMS = "params";
@@ -209,7 +212,6 @@ public void onReceive(Context contenxt, Intent intent) {
209212
private List<PeopleDrawerList> recentPeopleDrawerList;
210213
private List<PeopleDrawerList> filteredRecentPeopleDrawerList;
211214
private Uri mFileUri;
212-
private ImageView cameraBtn;
213215
private String mCurrentPhotoPath;
214216
private Menu menu;
215217
private Calendar calendar;
@@ -220,6 +222,7 @@ public void onReceive(Context contenxt, Intent intent) {
220222
private Toast toast;
221223
private RecyclerView peopleDrawer;
222224
private List<PeopleDrawerList> peopleDrawerList;
225+
private ImageView addFileBtn;
223226
//
224227
private String streamSearchFilterKeyword = "";
225228
private RefreshableCursorAdapter peopleAdapter;
@@ -344,7 +347,7 @@ public void onClick(View v) {
344347
messageEt = (AutoCompleteTextView) findViewById(R.id.message_et);
345348
textView = (TextView) findViewById(R.id.textView);
346349
sendBtn = (ImageView) findViewById(R.id.send_btn);
347-
cameraBtn = (ImageView) findViewById(R.id.camera_btn);
350+
addFileBtn = (ImageView) findViewById(R.id.add_btn);
348351
appBarLayout = (AppBarLayout) findViewById(R.id.appBarLayout);
349352
boolean isCurrentThemeNight = (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES);
350353
etSearchPeople = (EditText) findViewById(R.id.people_drawer_search);
@@ -443,14 +446,15 @@ public void onClick(View v) {
443446
}
444447
});
445448

446-
// set onClick listener on camera button to dispatch camera intent when clicked
447-
cameraBtn.setOnClickListener(new View.OnClickListener() {
449+
/**
450+
* set click listener on add file button to open custom list dialog {@link ListDialog}
451+
*/
452+
addFileBtn.setOnClickListener(new View.OnClickListener() {
448453
@Override
449-
public void onClick(View view) {
450-
dispatchTakePictureIntent();
454+
public void onClick(View v) {
455+
showListDialog();
451456
}
452457
});
453-
454458
composeStatus = (LinearLayout) findViewById(R.id.composeStatus);
455459
setUpAdapter();
456460
streamActv.setAdapter(streamActvAdapter);
@@ -553,17 +557,36 @@ public Cursor runQuery(CharSequence charSequence) {
553557
handleSentFile((Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM));
554558
}
555559
}
556-
// if device doesn't have camera, disable camera button
557-
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
558-
cameraBtn.setEnabled(false);
559-
}
560560
handleOnFragmentChange();
561561
calendar = Calendar.getInstance();
562562
setupSnackBar();
563563
//Hides Keyboard if it was open with focus on an editText before restart of the activity
564564
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
565565
}
566566

567+
public void showListDialog() {
568+
// Create an instance of the dialog fragment and show it
569+
DialogFragment dialog = new ListDialog();
570+
dialog.show(getFragmentManager(), "ListDialogFragment");
571+
}
572+
573+
// The dialog fragment receives a reference to this Activity through the
574+
// Fragment.onAttach() callback, which it uses to call the following methods
575+
// defined by the ListDialogFragment.ListDialogListener interface
576+
@Override
577+
public void onDialogPhotoClick(DialogFragment dialog) {
578+
// User touched the dialog's "Take picture" button
579+
dialog.dismiss();
580+
dispatchTakePictureIntent();
581+
}
582+
583+
@Override
584+
public void onDialogFileClick(DialogFragment dialog) {
585+
// User touched the dialog's "Pick a file" button
586+
dialog.dismiss();
587+
dispatchPickIntent();
588+
}
589+
567590
/**
568591
* Updates recentPMPersons in ZulipApp
569592
*/
@@ -1632,7 +1655,7 @@ private void sendingMessage(boolean isSending, String message) {
16321655
messageEt.setEnabled(!isSending);
16331656
topicActv.setEnabled(!isSending);
16341657
sendBtn.setEnabled(!isSending);
1635-
cameraBtn.setEnabled(!isSending);
1658+
addFileBtn.setEnabled(!isSending);
16361659
togglePrivateStreamBtn.setEnabled(!isSending);
16371660
if (isSending) {
16381661
TextView msg = (TextView) composeStatus.findViewById(R.id.sending_message);
@@ -2319,9 +2342,6 @@ public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
23192342
case R.id.legal:
23202343
openLegal();
23212344
break;
2322-
case R.id.attach:
2323-
dispatchPickIntent();
2324-
break;
23252345
default:
23262346
return super.onOptionsItemSelected(item);
23272347
}
@@ -2341,6 +2361,8 @@ private void dispatchPickIntent() {
23412361

23422362
if (intent.resolveActivity(getPackageManager()) != null) {
23432363
startActivityForResult(intent, REQUEST_PICK_FILE);
2364+
// activity transition animation
2365+
ActivityTransitionAnim.transition(ZulipActivity.this);
23442366
}
23452367
}
23462368

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.zulip.android.util;
2+
3+
import android.app.AlertDialog;
4+
import android.app.Dialog;
5+
import android.app.DialogFragment;
6+
import android.content.Context;
7+
import android.content.pm.PackageManager;
8+
import android.os.Bundle;
9+
import android.view.LayoutInflater;
10+
import android.view.View;
11+
12+
import com.zulip.android.R;
13+
14+
/**
15+
* TODO: add description
16+
*/
17+
18+
public class ListDialog extends DialogFragment {
19+
20+
/* The activity that creates an instance of this dialog fragment must
21+
* implement this interface in order to receive event callbacks.
22+
* Each method passes the DialogFragment in case the host needs to query it. */
23+
public interface ListDialogListener {
24+
void onDialogPhotoClick(DialogFragment dialog);
25+
void onDialogFileClick(DialogFragment dialog);
26+
}
27+
28+
// Use this instance of the interface to deliver action events
29+
ListDialogListener mListener;
30+
31+
// Override the Fragment.onAttach() method to instantiate the ListDialogListener
32+
@Override
33+
public void onAttach(Context context) {
34+
super.onAttach(context);
35+
// Verify that the host activity implements the callback interface
36+
try {
37+
// Instantiate the ListDialogListener so we can send events to the host
38+
mListener = (ListDialogListener) context;
39+
} catch (ClassCastException e) {
40+
// The activity doesn't implement the interface, throw exception
41+
throw new ClassCastException(context.toString()
42+
+ " must implement ListDialogListener");
43+
}
44+
}
45+
46+
@Override
47+
public Dialog onCreateDialog(Bundle savedInstanceState) {
48+
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
49+
// Get the layout inflater
50+
LayoutInflater inflater = getActivity().getLayoutInflater();
51+
52+
// Inflate and set the layout for the dialog
53+
// Pass null as the parent view because its going in the dialog layout
54+
View rootView = inflater.inflate(R.layout.list_dialog, null);
55+
View cameraListItem = rootView.findViewById(R.id.picture_dialog);
56+
View fileListItem = rootView.findViewById(R.id.pick_file_dialog);
57+
58+
// if device doesn't have camera, disable camera option
59+
if (!getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
60+
cameraListItem.setEnabled(false);
61+
} else {
62+
cameraListItem.setOnClickListener(new View.OnClickListener() {
63+
@Override
64+
public void onClick(View v) {
65+
mListener.onDialogPhotoClick(ListDialog.this);
66+
}
67+
});
68+
}
69+
70+
fileListItem.setOnClickListener(new View.OnClickListener() {
71+
@Override
72+
public void onClick(View v) {
73+
mListener.onDialogFileClick(ListDialog.this);
74+
}
75+
});
76+
builder.setView(rootView);
77+
return builder.create();
78+
}
79+
}
490 Bytes
Loading
149 Bytes
Loading
321 Bytes
Loading
131 Bytes
Loading
638 Bytes
Loading
197 Bytes
Loading
933 Bytes
Loading
273 Bytes
Loading

0 commit comments

Comments
 (0)