-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3493 App freezes for 15 seconds when you press Next in UploadMediaDe…
…tailsFragment (#3499) * #3493 App freezes for 15 seconds when you press Next in UploadMediaDetailsFragment - add apropriate schedulers and convert justs to fromCallable * #3493 App freezes for 15 seconds when you press Next in UploadMediaDetailsFragment - remove test for removed functionality * #3493 App freezes for 15 seconds when you press Next in UploadMediaDetailsFragment - replace kotlin with java
- Loading branch information
Showing
12 changed files
with
118 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 32 additions & 32 deletions
64
app/src/main/java/fr/free/nrw/commons/upload/ReadFBMD.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,48 @@ | ||
package fr.free.nrw.commons.upload; | ||
|
||
import fr.free.nrw.commons.utils.ImageUtils; | ||
import io.reactivex.Single; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
import fr.free.nrw.commons.utils.ImageUtils; | ||
import io.reactivex.Single; | ||
|
||
/** | ||
* We want to discourage users from uploading images to Commons that were taken from Facebook. | ||
* This attempts to detect whether an image was downloaded from Facebook by heuristically | ||
* searching for metadata that is specific to images that come from Facebook. | ||
* We want to discourage users from uploading images to Commons that were taken from Facebook. This | ||
* attempts to detect whether an image was downloaded from Facebook by heuristically searching for | ||
* metadata that is specific to images that come from Facebook. | ||
*/ | ||
@Singleton | ||
public class ReadFBMD { | ||
|
||
@Inject | ||
public ReadFBMD() { | ||
} | ||
|
||
public Single<Integer> processMetadata(String path) { | ||
try { | ||
int psBlockOffset; | ||
int fbmdOffset; | ||
|
||
try (FileInputStream fs = new FileInputStream(path)) { | ||
byte[] bytes = new byte[4096]; | ||
fs.read(bytes); | ||
fs.close(); | ||
String fileStr = new String(bytes); | ||
psBlockOffset = fileStr.indexOf("8BIM"); | ||
fbmdOffset = fileStr.indexOf("FBMD"); | ||
} | ||
@Inject | ||
public ReadFBMD() { | ||
} | ||
|
||
public Single<Integer> processMetadata(String path) { | ||
return Single.fromCallable(() -> { | ||
try { | ||
int psBlockOffset; | ||
int fbmdOffset; | ||
|
||
try (FileInputStream fs = new FileInputStream(path)) { | ||
byte[] bytes = new byte[4096]; | ||
fs.read(bytes); | ||
fs.close(); | ||
String fileStr = new String(bytes); | ||
psBlockOffset = fileStr.indexOf("8BIM"); | ||
fbmdOffset = fileStr.indexOf("FBMD"); | ||
} | ||
|
||
if (psBlockOffset > 0 && fbmdOffset > 0 | ||
&& fbmdOffset > psBlockOffset && fbmdOffset - psBlockOffset < 0x80) { | ||
return Single.just(ImageUtils.FILE_FBMD); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
if (psBlockOffset > 0 && fbmdOffset > 0 | ||
&& fbmdOffset > psBlockOffset && fbmdOffset - psBlockOffset < 0x80) { | ||
return ImageUtils.FILE_FBMD; | ||
} | ||
return Single.just(ImageUtils.IMAGE_OK); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return ImageUtils.IMAGE_OK; | ||
}); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 17 additions & 18 deletions
35
app/src/main/java/fr/free/nrw/commons/utils/ImageUtilsWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,30 @@ | ||
package fr.free.nrw.commons.utils; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
import fr.free.nrw.commons.location.LatLng; | ||
import io.reactivex.Single; | ||
import io.reactivex.schedulers.Schedulers; | ||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
@Singleton | ||
public class ImageUtilsWrapper { | ||
|
||
@Inject | ||
public ImageUtilsWrapper() { | ||
@Inject | ||
public ImageUtilsWrapper() { | ||
|
||
} | ||
} | ||
|
||
public Single<Integer> checkIfImageIsTooDark(String bitmapPath) { | ||
return Single.just(ImageUtils.checkIfImageIsTooDark(bitmapPath)) | ||
.subscribeOn(Schedulers.computation()) | ||
.observeOn(Schedulers.computation()); | ||
} | ||
public Single<Integer> checkIfImageIsTooDark(String bitmapPath) { | ||
return Single.fromCallable(() -> ImageUtils.checkIfImageIsTooDark(bitmapPath)) | ||
.subscribeOn(Schedulers.computation()); | ||
} | ||
|
||
public Single<Integer> checkImageGeolocationIsDifferent(String geolocationOfFileString, LatLng latLng) { | ||
boolean isImageGeoLocationDifferent = ImageUtils.checkImageGeolocationIsDifferent(geolocationOfFileString, latLng); | ||
return Single.just(isImageGeoLocationDifferent) | ||
.subscribeOn(Schedulers.computation()) | ||
.observeOn(Schedulers.computation()) | ||
.map(isDifferent -> isDifferent ? ImageUtils.IMAGE_GEOLOCATION_DIFFERENT : ImageUtils.IMAGE_OK); | ||
} | ||
public Single<Integer> checkImageGeolocationIsDifferent(String geolocationOfFileString, | ||
LatLng latLng) { | ||
return Single.fromCallable( | ||
() -> ImageUtils.checkImageGeolocationIsDifferent(geolocationOfFileString, latLng)) | ||
.subscribeOn(Schedulers.computation()) | ||
.map(isDifferent -> isDifferent ? ImageUtils.IMAGE_GEOLOCATION_DIFFERENT | ||
: ImageUtils.IMAGE_OK); | ||
} | ||
} |
Oops, something went wrong.