16
16
import android .app .DatePickerDialog ;
17
17
import android .app .SearchManager ;
18
18
import android .content .BroadcastReceiver ;
19
+ import android .content .ClipData ;
19
20
import android .content .ComponentName ;
20
21
import android .content .Context ;
21
22
import android .content .DialogInterface ;
@@ -152,6 +153,10 @@ public class ZulipActivity extends BaseActivity implements
152
153
private static final int REQUEST_TAKE_PHOTO = 2 ;
153
154
private static final Interpolator FAST_OUT_SLOW_IN_INTERPOLATOR = new FastOutSlowInInterpolator ();
154
155
private static final int HIDE_FAB_AFTER_SEC = 5 ;
156
+ private static final int REQUEST_PICK_FILE = 3 ;
157
+ // row number which is used to differentiate the 'All private messages'
158
+ // row from the people
159
+ final int allPeopleId = -1 ;
155
160
public MessageListFragment currentList ;
156
161
public CommonProgressDialog commonProgressDialog ;
157
162
FloatingActionButton fab ;
@@ -541,7 +546,7 @@ public Cursor runQuery(CharSequence charSequence) {
541
546
handleSentText (intent );
542
547
} else {
543
548
// Handle single file being sent
544
- handleSentFile (intent );
549
+ handleSentFile (( Uri ) intent . getParcelableExtra ( Intent . EXTRA_STREAM ) );
545
550
}
546
551
}
547
552
// if device doesn't have camera, disable camera button
@@ -866,12 +871,12 @@ protected void onNewIntent(Intent intent) {
866
871
String type = intent .getType ();
867
872
868
873
if (Intent .ACTION_SEND .equals (action ) && type != null ) {
869
- if (type .startsWith ("image/" )) {
870
- // Handle single image being sent
871
- handleSentFile (intent );
872
- } else if ("text/plain" .equals (type )) {
874
+ if ("text/plain" .equals (type )) {
873
875
// Handle text being sent
874
876
handleSentText (intent );
877
+ } else {
878
+ // Handle single file being sent
879
+ handleSentFile ((Uri ) intent .getParcelableExtra (Intent .EXTRA_STREAM ));
875
880
}
876
881
}
877
882
@@ -908,10 +913,31 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
908
913
// activity transition animation
909
914
ActivityTransitionAnim .transition (ZulipActivity .this );
910
915
}
916
+
917
+ // TODO: rearrange code
918
+ // in else if upload file sent and show notification for it
919
+ else if (requestCode == REQUEST_PICK_FILE && resultCode == RESULT_OK ) {
920
+ List <Uri > fileUris = new ArrayList <>();
921
+ if (data .getData () != null ) {
922
+ fileUris .add (data .getData ());
923
+ }
924
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN ) {
925
+ ClipData clipData = data .getClipData ();
926
+ if (clipData != null ) {
927
+ for (int i = 0 ; i < clipData .getItemCount (); i ++) {
928
+ fileUris .add (clipData .getItemAt (i ).getUri ());
929
+ }
930
+ }
931
+ }
932
+ for (Uri file : fileUris ) {
933
+ handleSentFile (file );
934
+ }
935
+ }
911
936
}
912
937
913
938
/**
914
939
* Function invoked when a user shares a text with the zulip app
940
+ *
915
941
* @param intent passed to the activity with action SEND
916
942
*/
917
943
private void handleSentText (Intent intent ) {
@@ -927,11 +953,11 @@ private void handleSentText(Intent intent) {
927
953
/**
928
954
* Function invoked when a user shares an image with the zulip app
929
955
*
930
- * @param intent passed to the activity with action SEND
956
+ * @param fileUri obtained from intent passed to the activity
931
957
*/
932
958
@ SuppressLint ("InlinedApi" )
933
- private void handleSentFile (Intent intent ) {
934
- mFileUri = intent . getParcelableExtra ( Intent . EXTRA_STREAM ) ;
959
+ private void handleSentFile (Uri fileUri ) {
960
+ mFileUri = fileUri ;
935
961
if (mFileUri != null ) {
936
962
// check if user has granted read external storage permission
937
963
// for Android 6.0 or higher
@@ -2197,12 +2223,31 @@ public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
2197
2223
case R .id .legal :
2198
2224
openLegal ();
2199
2225
break ;
2226
+ case R .id .attach :
2227
+ dispatchPickIntent ();
2228
+ break ;
2200
2229
default :
2201
2230
return super .onOptionsItemSelected (item );
2202
2231
}
2203
2232
return true ;
2204
2233
}
2205
2234
2235
+ private void dispatchPickIntent () {
2236
+ Intent intent = new Intent (Intent .ACTION_GET_CONTENT );
2237
+ intent .setType ("*/*" );
2238
+ intent .addCategory (Intent .CATEGORY_OPENABLE );
2239
+ intent .putExtra (Intent .EXTRA_LOCAL_ONLY , true );
2240
+
2241
+ // For Api level greater than or equal to 18, allow user to select multiple files
2242
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR2 ) {
2243
+ intent .putExtra (Intent .EXTRA_ALLOW_MULTIPLE , true );
2244
+ }
2245
+
2246
+ if (intent .resolveActivity (getPackageManager ()) != null ) {
2247
+ startActivityForResult (intent , REQUEST_PICK_FILE );
2248
+ }
2249
+ }
2250
+
2206
2251
/**
2207
2252
* Switches the current Day/Night mode to Night/Day mode
2208
2253
*
0 commit comments