66import android .annotation .TargetApi ;
77import android .app .AlertDialog ;
88import android .app .DatePickerDialog ;
9+ import android .app .DialogFragment ;
910import android .app .NotificationManager ;
1011import android .app .PendingIntent ;
1112import android .app .SearchManager ;
110111import com .zulip .android .util .CommonProgressDialog ;
111112import com .zulip .android .util .Constants ;
112113import com .zulip .android .util .FileUtils ;
114+ import com .zulip .android .util .ListDialog ;
113115import com .zulip .android .util .MutedTopics ;
114116import com .zulip .android .util .RemoveViewsOnScroll ;
115117import com .zulip .android .util .SwipeRemoveLinearLayout ;
143145 * messages
144146 */
145147public 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
0 commit comments