@@ -148,7 +148,7 @@ public class ZulipActivity extends BaseActivity implements
148
148
private static final int MAX_THRESOLD_EMOJI_HINT = 5 ;
149
149
//At these many letters the emoji/person hint starts to show up
150
150
private static final int MIN_THRESOLD_EMOJI_HINT = 1 ;
151
- private static final int PERMISSION_REQUEST_READ_CONTACTS = 1 ;
151
+ private static final int PERMISSION_REQUEST_READ_STORAGE = 1 ;
152
152
private static final int REQUEST_TAKE_PHOTO = 2 ;
153
153
private static final Interpolator FAST_OUT_SLOW_IN_INTERPOLATOR = new FastOutSlowInInterpolator ();
154
154
private static final int HIDE_FAB_AFTER_SEC = 5 ;
@@ -201,7 +201,7 @@ public void onReceive(Context contenxt, Intent intent) {
201
201
private ExpandableStreamDrawerAdapter streamsDrawerAdapter ;
202
202
private List <PeopleDrawerList > recentPeopleDrawerList ;
203
203
private List <PeopleDrawerList > filteredRecentPeopleDrawerList ;
204
- private Uri mImageUri ;
204
+ private Uri mFileUri ;
205
205
private ImageView cameraBtn ;
206
206
private String mCurrentPhotoPath ;
207
207
private Uri mPhotoURI ;
@@ -536,12 +536,12 @@ public Cursor runQuery(CharSequence charSequence) {
536
536
String type = intent .getType ();
537
537
538
538
if (Intent .ACTION_SEND .equals (action ) && type != null ) {
539
- if (type .startsWith ("image/" )) {
540
- // Handle single image being sent
541
- handleSentImage (intent );
542
- } else if ("text/plain" .equals (type )) {
539
+ if ("text/plain" .equals (type )) {
543
540
// Handle text being sent
544
541
handleSentText (intent );
542
+ } else {
543
+ // Handle single file being sent
544
+ handleSentFile (intent );
545
545
}
546
546
}
547
547
// if device doesn't have camera, disable camera button
@@ -868,7 +868,7 @@ protected void onNewIntent(Intent intent) {
868
868
if (Intent .ACTION_SEND .equals (action ) && type != null ) {
869
869
if (type .startsWith ("image/" )) {
870
870
// Handle single image being sent
871
- handleSentImage (intent );
871
+ handleSentFile (intent );
872
872
} else if ("text/plain" .equals (type )) {
873
873
// Handle text being sent
874
874
handleSentText (intent );
@@ -930,9 +930,9 @@ private void handleSentText(Intent intent) {
930
930
* @param intent passed to the activity with action SEND
931
931
*/
932
932
@ SuppressLint ("InlinedApi" )
933
- private void handleSentImage (Intent intent ) {
934
- mImageUri = ( Uri ) intent .getParcelableExtra (Intent .EXTRA_STREAM );
935
- if (mImageUri != null ) {
933
+ private void handleSentFile (Intent intent ) {
934
+ mFileUri = intent .getParcelableExtra (Intent .EXTRA_STREAM );
935
+ if (mFileUri != null ) {
936
936
// check if user has granted read external storage permission
937
937
// for Android 6.0 or higher
938
938
if (ContextCompat .checkSelfPermission (this ,
@@ -941,14 +941,14 @@ private void handleSentImage(Intent intent) {
941
941
// we need to request the permission.
942
942
ActivityCompat .requestPermissions (this ,
943
943
new String []{Manifest .permission .READ_EXTERNAL_STORAGE },
944
- PERMISSION_REQUEST_READ_CONTACTS );
944
+ PERMISSION_REQUEST_READ_STORAGE );
945
945
} else {
946
946
// permission already granted
947
947
// start with file upload
948
948
startFileUpload ();
949
949
}
950
950
} else {
951
- Toast .makeText (this , R .string .cannot_find_image , Toast .LENGTH_SHORT ).show ();
951
+ Toast .makeText (this , R .string .cannot_find_file , Toast .LENGTH_SHORT ).show ();
952
952
}
953
953
}
954
954
@@ -957,7 +957,7 @@ public void onRequestPermissionsResult(int requestCode,
957
957
String permissions [], int [] grantResults ) {
958
958
959
959
switch (requestCode ) {
960
- case PERMISSION_REQUEST_READ_CONTACTS : {
960
+ case PERMISSION_REQUEST_READ_STORAGE : {
961
961
// If request is cancelled, the result arrays are empty.
962
962
if (grantResults .length > 0
963
963
&& grantResults [0 ] == PackageManager .PERMISSION_GRANTED ) {
@@ -966,7 +966,7 @@ public void onRequestPermissionsResult(int requestCode,
966
966
startFileUpload ();
967
967
} else {
968
968
// permission denied
969
- Toast .makeText (this , R .string .cannot_upload_image , Toast .LENGTH_SHORT ).show ();
969
+ Toast .makeText (this , R .string .cannot_upload_file , Toast .LENGTH_SHORT ).show ();
970
970
}
971
971
}
972
972
break ;
@@ -1036,32 +1036,25 @@ private File createPhotoFile() throws IOException {
1036
1036
}
1037
1037
1038
1038
/**
1039
- * Helper function to update UI to indicate image is being uploaded and call
1040
- * {@link ZulipActivity #uploadFile(File)} to upload the image.
1039
+ * Helper function to update UI to indicate file is being uploaded and call
1040
+ * {@link #uploadFile(File)} to upload the image.
1041
1041
*/
1042
1042
private void startFileUpload () {
1043
- // Update UI to indicate image is being loaded
1044
- // hide fab and display chatbox
1045
- displayFAB (false );
1046
- displayChatBox (true );
1047
- String loadingMsg = getResources ().getString (R .string .uploading_message );
1048
- sendingMessage (true , loadingMsg );
1049
-
1050
1043
File file = null ;
1051
- if (FilePathHelper .isLegacy (mImageUri )) {
1052
- file = FilePathHelper .getTempFileFromContentUri (this , mImageUri );
1044
+ if (FilePathHelper .isLegacy (mFileUri )) {
1045
+ file = FilePathHelper .getTempFileFromContentUri (this , mFileUri );
1053
1046
} else {
1054
1047
// get actual file path
1055
- String imageFilePath = FilePathHelper .getPath (this , mImageUri );
1056
- if (imageFilePath != null ) {
1057
- file = new File (imageFilePath );
1058
- } else if ("content" .equalsIgnoreCase (mImageUri .getScheme ())) {
1059
- file = FilePathHelper .getTempFileFromContentUri (this , mImageUri );
1048
+ String filePath = FilePathHelper .getPath (this , mFileUri );
1049
+ if (filePath != null ) {
1050
+ file = new File (filePath );
1051
+ } else if ("content" .equalsIgnoreCase (mFileUri .getScheme ())) {
1052
+ file = FilePathHelper .getTempFileFromContentUri (this , mFileUri );
1060
1053
}
1061
1054
}
1062
1055
1063
1056
if (file == null ) {
1064
- Toast .makeText (this , R .string .invalid_image , Toast .LENGTH_SHORT ).show ();
1057
+ Toast .makeText (this , R .string .invalid_file , Toast .LENGTH_SHORT ).show ();
1065
1058
return ;
1066
1059
}
1067
1060
// upload the file asynchronously to the server
@@ -1082,7 +1075,7 @@ private void uploadFile(File file) {
1082
1075
1083
1076
// MultipartBody.Part is used to send also the actual file name
1084
1077
MultipartBody .Part body =
1085
- MultipartBody .Part .createFormData ("picture " , file .getName (), requestFile );
1078
+ MultipartBody .Part .createFormData ("file " , file .getName (), requestFile );
1086
1079
1087
1080
final String loadingMsg = getResources ().getString (R .string .uploading_message );
1088
1081
0 commit comments