Skip to content

Commit

Permalink
fixes blank screen decrepancy when sharing items from external apps (#…
Browse files Browse the repository at this point in the history
…5345)

* fixes blank screen decrepancy when sharing items from external apps

* reverts comment removal
  • Loading branch information
srishti-R authored Oct 18, 2023
1 parent f130851 commit 64652b9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public interface Constants {
*/
interface RequestCodes {
int LOCATION = 1;
int STORAGE = 2;
int FILE_PICKER_IMAGE_IDENTIFICATOR = 0b1101101100; //876
int SOURCE_CHOOSER = 1 << 15;

Expand Down
62 changes: 47 additions & 15 deletions app/src/main/java/fr/free/nrw/commons/upload/UploadActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationManager;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.provider.Settings;
import android.util.DisplayMetrics;
Expand All @@ -21,6 +24,7 @@
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
Expand All @@ -38,6 +42,7 @@
import fr.free.nrw.commons.auth.LoginActivity;
import fr.free.nrw.commons.auth.SessionManager;
import fr.free.nrw.commons.contributions.ContributionController;
import fr.free.nrw.commons.filepicker.Constants.RequestCodes;
import fr.free.nrw.commons.filepicker.UploadableFile;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.location.LatLng;
Expand All @@ -59,7 +64,6 @@
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
import java.security.Permission;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -150,11 +154,6 @@ protected void onCreate(Bundle savedInstanceState) {
compositeDisposable = new CompositeDisposable();
init();
nearbyPopupAnswers = new HashMap<>();
PermissionUtils.checkPermissionsAndPerformAction(this,
this::receiveSharedItems,
R.string.storage_permission_title,
R.string.write_storage_permission_rationale_for_image_share,
PERMISSIONS_STORAGE);
//getting the current dpi of the device and if it is less than 320dp i.e. overlapping
//threshold, thumbnails automatically minimizes
DisplayMetrics metrics = getResources().getDisplayMetrics();
Expand All @@ -167,6 +166,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
locationManager.requestLocationUpdatesFromProvider(LocationManager.GPS_PROVIDER);
locationManager.requestLocationUpdatesFromProvider(LocationManager.NETWORK_PROVIDER);
checkStoragePermissions();
}

private void init() {
Expand Down Expand Up @@ -232,7 +232,6 @@ protected void onResume() {
askUserToLogIn();
}
checkBlockStatus();
checkStoragePermissions();
}

/**
Expand All @@ -255,14 +254,10 @@ protected void checkBlockStatus() {

private void checkStoragePermissions() {
final boolean hasAllPermissions = PermissionUtils.hasPermission(this, PERMISSIONS_STORAGE);
if (!hasAllPermissions) {
PermissionUtils.checkPermissionsAndPerformAction(this,
() -> {
//TODO handle this
},
R.string.storage_permission_title,
R.string.write_storage_permission_rationale_for_image_share,
PERMISSIONS_STORAGE);
if (hasAllPermissions) {
receiveSharedItems();
} else if (VERSION.SDK_INT >= VERSION_CODES.M) {
requestPermissions(PERMISSIONS_STORAGE, RequestCodes.STORAGE);
}
}

Expand Down Expand Up @@ -350,7 +345,44 @@ public void askUserToLogIn() {
startActivity(loginIntent);
}

@Override
public void onRequestPermissionsResult(final int requestCode,
@NonNull final String[] permissions,
@NonNull final int[] grantResults) {
boolean areAllGranted = false;
if (requestCode == RequestCodes.STORAGE) {
if (VERSION.SDK_INT >= VERSION_CODES.M) {
for (int i = 0; i < grantResults.length; i++) {
String permission = permissions[i];
areAllGranted = grantResults[i] == PackageManager.PERMISSION_GRANTED;
if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
boolean showRationale = shouldShowRequestPermissionRationale(permission);
if (!showRationale) {
DialogUtil.showAlertDialog(this,
getString(R.string.storage_permissions_denied),
getString(R.string.unable_to_share_upload_item),
getString(android.R.string.ok),
this::finish,
false);
} else {
DialogUtil.showAlertDialog(this,
getString(R.string.storage_permission_title),
getString(
R.string.write_storage_permission_rationale_for_image_share),
getString(android.R.string.ok),
this::checkStoragePermissions,
false);
}
}
}

if (areAllGranted) {
receiveSharedItems();
}
}
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,8 @@ Upload your first media by tapping on the add button.</string>
<string name="full_screen_mode_features_info">Swipe fast and long to perform these actions: \n- Left/Right: Go to previous/next \n- Up: Select\n- Down: Mark as not for upload.</string>
<string name="set_up_avatar_toast_string">To set up your leaderboard avatar, tap \"Set as avatar\" in the three-dots menu of any image.</string>
<string name="similar_coordinate_description_auto_set">The coordinates are not the exact coordinates, but the person who uploaded this picture thinks they are close enough.</string>
<string name="storage_permissions_denied">Storage Permissions Denied</string>
<string name="unable_to_share_upload_item">Unable to share this item</string>
<plurals name="custom_picker_images_selected_title_appendix">
<item quantity="one">%d image selected</item>
<item quantity="other">%d images selected</item>
Expand Down

0 comments on commit 64652b9

Please sign in to comment.