-
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 - add apropriate schedulers and convert justs to fromCallable
- Loading branch information
Showing
14 changed files
with
124 additions
and
157 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
48 changes: 0 additions & 48 deletions
48
app/src/main/java/fr/free/nrw/commons/upload/ReadFBMD.java
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package fr.free.nrw.commons.upload | ||
|
||
import fr.free.nrw.commons.utils.ImageUtils | ||
import io.reactivex.Single | ||
import io.reactivex.schedulers.Schedulers | ||
import java.io.FileInputStream | ||
import java.io.IOException | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
/** | ||
* 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 | ||
class ReadFBMD @Inject constructor() { | ||
fun processMetadata(path: String?) = Single.fromCallable { | ||
try { | ||
val fileStr = FileInputStream(path).use { | ||
ByteArray(4096).apply { it.read(this) }.toString() | ||
} | ||
if (isFbmd(fileStr.indexOf("8BIM"), fileStr.indexOf("FBMD"))) | ||
return@fromCallable ImageUtils.FILE_FBMD | ||
} catch (e: IOException) { | ||
e.printStackTrace() | ||
} | ||
ImageUtils.IMAGE_OK | ||
}.subscribeOn(Schedulers.io()) | ||
|
||
private fun isFbmd(psBlockOffset: Int, fbmdOffset: Int) = | ||
psBlockOffset > 0 && fbmdOffset > 0 && | ||
fbmdOffset > psBlockOffset && | ||
fbmdOffset - psBlockOffset < 0x80 | ||
} |
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
31 changes: 0 additions & 31 deletions
31
app/src/main/java/fr/free/nrw/commons/utils/ImageUtilsWrapper.java
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
app/src/main/java/fr/free/nrw/commons/utils/ImageUtilsWrapper.kt
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package fr.free.nrw.commons.utils | ||
|
||
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 | ||
class ImageUtilsWrapper @Inject constructor() { | ||
fun checkIfImageIsTooDark(bitmapPath: String?) = | ||
Single.fromCallable { ImageUtils.checkIfImageIsTooDark(bitmapPath) } | ||
.subscribeOn(Schedulers.computation()) | ||
|
||
fun checkImageGeolocationIsDifferent(geolocationOfFileString: String?, latLng: LatLng?) = | ||
Single.just(ImageUtils.checkImageGeolocationIsDifferent(geolocationOfFileString, latLng)) | ||
.subscribeOn(Schedulers.computation()) | ||
.map { isDifferent: Boolean -> if (isDifferent) ImageUtils.IMAGE_GEOLOCATION_DIFFERENT else ImageUtils.IMAGE_OK } | ||
} |
Oops, something went wrong.