5
5
import android .content .pm .PackageManager ;
6
6
import android .content .pm .ResolveInfo ;
7
7
import android .net .Uri ;
8
+ import android .os .Build ;
8
9
import android .os .Bundle ;
9
10
import android .provider .MediaStore ;
10
11
import android .support .annotation .Nullable ;
12
+ import android .support .annotation .RequiresApi ;
11
13
import android .support .v4 .app .Fragment ;
12
14
import android .support .v4 .app .FragmentActivity ;
13
15
import android .support .v4 .content .FileProvider ;
14
16
15
17
import java .io .File ;
18
+ import java .util .ArrayList ;
16
19
import java .util .Date ;
17
20
import java .util .List ;
18
21
21
24
22
25
import static android .content .Intent .ACTION_GET_CONTENT ;
23
26
import static android .content .Intent .ACTION_SEND ;
27
+ import static android .content .Intent .ACTION_SEND_MULTIPLE ;
24
28
import static android .content .Intent .EXTRA_STREAM ;
25
29
import static fr .free .nrw .commons .contributions .Contribution .SOURCE_CAMERA ;
26
30
import static fr .free .nrw .commons .contributions .Contribution .SOURCE_GALLERY ;
@@ -31,6 +35,7 @@ public class ContributionController {
31
35
32
36
public static final int SELECT_FROM_GALLERY = 1 ;
33
37
public static final int SELECT_FROM_CAMERA = 2 ;
38
+ public static final int PICK_IMAGE_MULTIPLE = 3 ;
34
39
35
40
private Fragment fragment ;
36
41
@@ -79,6 +84,14 @@ public void startCameraCapture() {
79
84
}
80
85
81
86
public void startGalleryPick () {
87
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR2 ) {
88
+ startMultipleGalleryPick ();
89
+ } else {
90
+ startSingleGalleryPick ();
91
+ }
92
+ }
93
+
94
+ public void startSingleGalleryPick () {
82
95
//FIXME: Starts gallery (opens Google Photos)
83
96
Intent pickImageIntent = new Intent (ACTION_GET_CONTENT );
84
97
pickImageIntent .setType ("image/*" );
@@ -92,6 +105,32 @@ public void startGalleryPick() {
92
105
fragment .startActivityForResult (pickImageIntent , SELECT_FROM_GALLERY );
93
106
}
94
107
108
+ @ RequiresApi (api = Build .VERSION_CODES .JELLY_BEAN_MR2 )
109
+ public void startMultipleGalleryPick () {
110
+ Intent pickImageIntent = new Intent (ACTION_GET_CONTENT );
111
+ pickImageIntent .putExtra (Intent .EXTRA_ALLOW_MULTIPLE , true );
112
+ pickImageIntent .setType ("image/*" );
113
+ if (!fragment .isAdded ()) {
114
+ Timber .d ("Fragment is not added, startActivityForResult cannot be called" );
115
+ return ;
116
+ }
117
+ Timber .d ("startGalleryPick() called with pickImageIntent" );
118
+
119
+ fragment .startActivityForResult (pickImageIntent , PICK_IMAGE_MULTIPLE );
120
+ }
121
+
122
+ public void handleImagesPicked (int requestCode , @ Nullable ArrayList <Uri > uri ) {
123
+ FragmentActivity activity = fragment .getActivity ();
124
+ Intent shareIntent = new Intent (activity , UploadActivity .class );
125
+ shareIntent .setAction (ACTION_SEND_MULTIPLE );
126
+ shareIntent .putExtra (EXTRA_SOURCE , SOURCE_GALLERY );
127
+ shareIntent .putExtra (EXTRA_STREAM , uri );
128
+ shareIntent .setType ("image/jpeg" );
129
+ if (activity != null ) {
130
+ activity .startActivity (shareIntent );
131
+ }
132
+ }
133
+
95
134
public void handleImagePicked (int requestCode , @ Nullable Uri uri , boolean isDirectUpload , String wikiDataEntityId ) {
96
135
FragmentActivity activity = fragment .getActivity ();
97
136
Timber .d ("handleImagePicked() called with onActivityResult(). Boolean isDirectUpload: " + isDirectUpload + "String wikiDataEntityId: " + wikiDataEntityId );
0 commit comments