Skip to content

Commit

Permalink
Merge pull request #476 from openforis/image-compress-decimals-android
Browse files Browse the repository at this point in the history
Android decimals compress image error
  • Loading branch information
ramirobg94 authored Aug 16, 2023
2 parents 1c5d4c4 + 2a44e7c commit 5aaad5e
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 16 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ android {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 38
versionName "1.0.14"
versionName "1.0.15"


buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
Expand Down
4 changes: 2 additions & 2 deletions src/form/Attributes/File/hooks/useImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ const useGetImage = ({cropping = false} = {}) => {
Platform.OS === 'ios'
? Math.min(0.8, compressQuality) // this is because in IOS 0.8 is more than enough
: compressQuality,
compressImageMaxHeight: compressMaxHeight,
compressImageMaxWidth: compressMaxWidth,
compressImageMaxHeight: Math.floor(compressMaxHeight),
compressImageMaxWidth: Math.floor(compressMaxWidth),
}),
});

Expand Down
10 changes: 9 additions & 1 deletion src/infra/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,17 @@ export default ({serverUrl = SERVER_URL}) => {
contentType,
});

const postFile = async (uri, file, onProgress) => {
const postFile = async (
uri,
file,
onProgress,
conflictResolutionStrategy,
) => {
let formData = new FormData();
formData.append('file', file);
if (conflictResolutionStrategy) {
formData.append('conflictResolutionStrategy', conflictResolutionStrategy);
}
return axios.post(uri, formData, {
headers: {'Content-Type': 'multipart/form-data'},
onUploadProgress: onProgress,
Expand Down
25 changes: 18 additions & 7 deletions src/infra/fs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,13 @@ export const deleteDir = async path => {
return RNFetchBlob.fs.unlink(_path);
};

export const uploadFiles = async ({uploadUrl, files, onStart, onProgress}) => {
export const uploadFiles = async ({
uploadUrl,
files,
onStart,
onProgress,
conflictResolutionStrategy,
}) => {
const _files = files.map(file =>
Object.assign({}, file, {
type: file.filetype,
Expand All @@ -147,12 +153,17 @@ export const uploadFiles = async ({uploadUrl, files, onStart, onProgress}) => {
type: _files[0].type,
};

return API({}).postFile(uploadUrl, file, progress => {
onProgress({
totalBytesSent: progress.loaded,
totalBytesExpectedToSend: progress.total,
});
});
return API({}).postFile(
uploadUrl,
file,
progress => {
onProgress({
totalBytesSent: progress.loaded,
totalBytesExpectedToSend: progress.total,
});
},
conflictResolutionStrategy,
);
};

const blobToBase64 = data => {
Expand Down
5 changes: 4 additions & 1 deletion src/screens/Form/components/EntityPage/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ const EntityPage = () => {
() => NodeDefs.getLayoutRenderType(cycle)(nodeDef) === 'table',
[nodeDef, cycle],
);
const isMultiple = useMemo(() => NodeDefs.isMultiple(nodeDef), [nodeDef]);
const isMultiple = useMemo(
() => (nodeDef?.props ? NodeDefs.isMultiple(nodeDef) : false),
[nodeDef],
);

if (nodeDef?.uuid && NodeDefs.isEntity(nodeDef)) {
return isTable || isMultiple ? <TableEntity /> : <Entity />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const SettingsImagesQualityAndSize = () => {
value => {
dispatch(
appActions.setImagesCompressMaxHeight({
compressMaxHeight: value,
compressMaxHeight: Math.floor(value),
}),
);
},
Expand All @@ -47,7 +47,7 @@ const SettingsImagesQualityAndSize = () => {
value => {
dispatch(
appActions.setImagesCompressMaxWidth({
compressMaxWidth: value,
compressMaxWidth: Math.floor(value),
}),
);
},
Expand Down
12 changes: 10 additions & 2 deletions src/state/survey/sagas/uploadData/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function* checkIfShouldUpdate({recordUuid}) {
}

function* handlePrepareRecordsData() {
let numberOfRecordsToUpload = 0;
try {
yield call(fs.mkdir, {dirPath: RECORDS_BASE_PATH});
const surveyUuid = yield select(surveySelectors.getSelectedSurveyUuid);
Expand All @@ -58,6 +59,7 @@ function* handlePrepareRecordsData() {
const shouldUpdate = yield call(checkIfShouldUpdate, {recordUuid});
if (shouldUpdate) {
recordsJson.push({uuid: recordUuid, cycle});
numberOfRecordsToUpload = numberOfRecordsToUpload + 1;
yield call(fs.copyFile, {
sourcePath: recordFile.path,
destinationPath: `${RECORDS_BASE_PATH}/${recordUuid}.json`,
Expand All @@ -74,6 +76,7 @@ function* handlePrepareRecordsData() {
} finally {
console.log('Finally:recordsData');
}
return numberOfRecordsToUpload;
}

function* handlePrepareFilesData() {
Expand Down Expand Up @@ -139,8 +142,9 @@ function* handlePrepareFilesData() {
}

function* handlePrepareZipData() {
let numberOfRecordsToUpload = 0;
try {
yield call(handlePrepareRecordsData);
numberOfRecordsToUpload = yield call(handlePrepareRecordsData);
yield call(handlePrepareFilesData);

yield call(zip, {
Expand All @@ -154,6 +158,7 @@ function* handlePrepareZipData() {
} finally {
console.log('Finally');
}
return numberOfRecordsToUpload;
}

function* cleanTmpFolder() {
Expand Down Expand Up @@ -223,9 +228,12 @@ function* handleUploadData() {

yield call(cleanTmpFolder);
yield call(fs.mkdir, {dirPath: TMP_SURVEYS_BASE_PATH});
yield call(handlePrepareZipData);
const numberOfRecordsToUpload = yield call(handlePrepareZipData);
// UPLOAD DATA and track progress

if (numberOfRecordsToUpload === 0) {
return;
}
yield call(WS({serverUrl}).create);
yield call(WS({serverUrl}).on, {
eventName: WebSocketEvents.jobUpdate,
Expand Down
1 change: 1 addition & 0 deletions src/state/surveys/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const uploadSurveyZip = async ({
files,
onStart,
onProgress,
conflictResolutionStrategy: 'overwriteIfUpdated',
});
};

Expand Down

0 comments on commit 5aaad5e

Please sign in to comment.