Skip to content

Commit a095a4e

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/2.7.x-release'
2 parents 23b2f3c + adff920 commit a095a4e

File tree

6 files changed

+49
-37
lines changed

6 files changed

+49
-37
lines changed

app/src/main/java/fr/free/nrw/commons/category/CategorizationFragment.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,11 @@ private Observable<CategoryItem> defaultCategories() {
280280

281281
private Observable<CategoryItem> directCategories() {
282282
String directCategory = directPrefs.getString("Category", "");
283+
// Strip newlines to prevent blank categories, and to tidy existing categories
284+
directCategory = directCategory.replace("\n", "");
285+
283286
List<String> categoryList = new ArrayList<>();
284-
Timber.d("Direct category found: " + directCategory);
287+
Timber.d("Direct category found: " + "'" + directCategory + "'");
285288

286289
if (!directCategory.equals("")) {
287290
hasDirectCategories = true;

app/src/main/java/fr/free/nrw/commons/nearby/DirectUpload.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import fr.free.nrw.commons.R;
1010
import fr.free.nrw.commons.contributions.ContributionController;
11+
import timber.log.Timber;
1112

1213
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
1314
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
@@ -23,53 +24,56 @@ class DirectUpload {
2324
this.controller = controller;
2425
}
2526

26-
void initiateCameraUpload() {
27+
// These permission requests will be handled by the Fragments.
28+
// Do not use requestCode 1 as it will conflict with NearbyActivity's requestCodes
29+
void initiateGalleryUpload() {
2730
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
28-
if (ContextCompat.checkSelfPermission(fragment.getActivity(), WRITE_EXTERNAL_STORAGE) != PERMISSION_GRANTED) {
29-
if (fragment.getActivity().shouldShowRequestPermissionRationale(WRITE_EXTERNAL_STORAGE)) {
31+
if (ContextCompat.checkSelfPermission(fragment.getActivity(), READ_EXTERNAL_STORAGE) != PERMISSION_GRANTED) {
32+
if (fragment.shouldShowRequestPermissionRationale(READ_EXTERNAL_STORAGE)) {
3033
new AlertDialog.Builder(fragment.getActivity())
31-
.setMessage(fragment.getActivity().getString(R.string.write_storage_permission_rationale))
34+
.setMessage(fragment.getActivity().getString(R.string.read_storage_permission_rationale))
3235
.setPositiveButton("OK", (dialog, which) -> {
33-
fragment.getActivity().requestPermissions(new String[]{WRITE_EXTERNAL_STORAGE}, 3);
36+
Timber.d("Requesting permissions for read external storage");
37+
fragment.requestPermissions(new String[]{READ_EXTERNAL_STORAGE}, 4);
3438
dialog.dismiss();
3539
})
3640
.setNegativeButton("Cancel", null)
3741
.create()
3842
.show();
3943
} else {
40-
fragment.getActivity().requestPermissions(new String[]{WRITE_EXTERNAL_STORAGE}, 3);
44+
fragment.requestPermissions(new String[]{READ_EXTERNAL_STORAGE},
45+
4);
4146
}
4247
} else {
43-
controller.startCameraCapture();
48+
controller.startGalleryPick();
4449
}
45-
} else {
46-
controller.startCameraCapture();
50+
}
51+
else {
52+
controller.startGalleryPick();
4753
}
4854
}
4955

50-
void initiateGalleryUpload() {
56+
void initiateCameraUpload() {
5157
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
52-
if (ContextCompat.checkSelfPermission(fragment.getActivity(), READ_EXTERNAL_STORAGE) != PERMISSION_GRANTED) {
53-
if (fragment.getActivity().shouldShowRequestPermissionRationale(READ_EXTERNAL_STORAGE)) {
58+
if (ContextCompat.checkSelfPermission(fragment.getActivity(), WRITE_EXTERNAL_STORAGE) != PERMISSION_GRANTED) {
59+
if (fragment.shouldShowRequestPermissionRationale(WRITE_EXTERNAL_STORAGE)) {
5460
new AlertDialog.Builder(fragment.getActivity())
55-
.setMessage(fragment.getActivity().getString(R.string.read_storage_permission_rationale))
61+
.setMessage(fragment.getActivity().getString(R.string.write_storage_permission_rationale))
5662
.setPositiveButton("OK", (dialog, which) -> {
57-
fragment.getActivity().requestPermissions(new String[]{READ_EXTERNAL_STORAGE}, 1);
63+
fragment.requestPermissions(new String[]{WRITE_EXTERNAL_STORAGE}, 5);
5864
dialog.dismiss();
5965
})
6066
.setNegativeButton("Cancel", null)
6167
.create()
6268
.show();
6369
} else {
64-
fragment.getActivity().requestPermissions(new String[]{READ_EXTERNAL_STORAGE},
65-
1);
70+
fragment.requestPermissions(new String[]{WRITE_EXTERNAL_STORAGE}, 5);
6671
}
6772
} else {
68-
controller.startGalleryPick();
73+
controller.startCameraCapture();
6974
}
70-
}
71-
else {
72-
controller.startGalleryPick();
75+
} else {
76+
controller.startCameraCapture();
7377
}
7478
}
7579
}

app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
165165
showLocationPermissionDeniedErrorDialog();
166166
}
167167
}
168+
break;
169+
170+
default:
171+
// This is needed to allow the request codes from the Fragments to be routed appropriately
172+
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
168173
}
169174
}
170175

app/src/main/java/fr/free/nrw/commons/nearby/NearbyListFragment.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,17 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
106106
Timber.d("onRequestPermissionsResult: req code = " + " perm = " + permissions + " grant =" + grantResults);
107107

108108
switch (requestCode) {
109-
// 1 = "Read external storage" allowed when gallery selected
110-
case 1: {
109+
// 4 = "Read external storage" allowed when gallery selected
110+
case 4: {
111111
if (grantResults.length > 0 && grantResults[0] == PERMISSION_GRANTED) {
112112
Timber.d("Call controller.startGalleryPick()");
113113
controller.startGalleryPick();
114114
}
115115
}
116116
break;
117117

118-
// 3 = "Write external storage" allowed when camera selected
119-
case 3: {
118+
// 5 = "Write external storage" allowed when camera selected
119+
case 5: {
120120
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
121121
Timber.d("Call controller.startCameraCapture()");
122122
controller.startCameraCapture();

app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public class NearbyMapFragment extends DaggerFragment {
9999
private Animation fab_open;
100100
private Animation rotate_forward;
101101
private ContributionController controller;
102+
private DirectUpload directUpload;
102103

103104
private Place place;
104105
private Marker selected;
@@ -123,6 +124,10 @@ public NearbyMapFragment() {
123124
@Override
124125
public void onCreate(Bundle savedInstanceState) {
125126
super.onCreate(savedInstanceState);
127+
128+
controller = new ContributionController(this);
129+
directUpload = new DirectUpload(this, controller);
130+
126131
Bundle bundle = this.getArguments();
127132
Gson gson = new GsonBuilder()
128133
.registerTypeAdapter(Uri.class, new UriDeserializer())
@@ -681,9 +686,6 @@ private void passInfoToSheet(Place place) {
681686
fabCamera.setOnClickListener(view -> {
682687
if (fabCamera.isShown()) {
683688
Timber.d("Camera button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
684-
controller = new ContributionController(this);
685-
686-
DirectUpload directUpload = new DirectUpload(this, controller);
687689
storeSharedPrefs();
688690
directUpload.initiateCameraUpload();
689691
}
@@ -692,9 +694,6 @@ private void passInfoToSheet(Place place) {
692694
fabGallery.setOnClickListener(view -> {
693695
if (fabGallery.isShown()) {
694696
Timber.d("Gallery button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
695-
controller = new ContributionController(this);
696-
697-
DirectUpload directUpload = new DirectUpload(this, controller);
698697
storeSharedPrefs();
699698
directUpload.initiateGalleryUpload();
700699
}
@@ -713,18 +712,19 @@ void storeSharedPrefs() {
713712
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
714713
Timber.d("onRequestPermissionsResult: req code = " + " perm = " + permissions + " grant =" + grantResults);
715714

715+
// Do not use requestCode 1 as it will conflict with NearbyActivity's requestCodes
716716
switch (requestCode) {
717-
// 1 = "Read external storage" allowed when gallery selected
718-
case 1: {
717+
// 4 = "Read external storage" allowed when gallery selected
718+
case 4: {
719719
if (grantResults.length > 0 && grantResults[0] == PERMISSION_GRANTED) {
720720
Timber.d("Call controller.startGalleryPick()");
721721
controller.startGalleryPick();
722722
}
723723
}
724724
break;
725725

726-
// 3 = "Write external storage" allowed when camera selected
727-
case 3: {
726+
// 5 = "Write external storage" allowed when camera selected
727+
case 5: {
728728
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
729729
Timber.d("Call controller.startCameraCapture()");
730730
controller.startCameraCapture();

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@
154154
<string name="detail_description_empty">No description</string>
155155
<string name="detail_license_empty">Unknown license</string>
156156
<string name="menu_refresh">Refresh</string>
157-
<string name="read_storage_permission_rationale">Required permission: Read external storage. App cannot function without this.</string>
158-
<string name="write_storage_permission_rationale">Required permission: Write external storage. App cannot function without this.</string>
157+
<string name="read_storage_permission_rationale">Required permission: Read external storage. App cannot access your gallery without this.</string>
158+
<string name="write_storage_permission_rationale">Required permission: Write external storage. App cannot access your camera without this.</string>
159159
<string name="location_permission_rationale">Optional permission: Get current location for category suggestions</string>
160160
<string name="ok">OK</string>
161161
<string name="title_activity_nearby">Nearby Places</string>

0 commit comments

Comments
 (0)