Add assets download

This commit is contained in:
Vincent BRIDIER 2022-09-30 17:13:43 +02:00
parent 49b26e1a3b
commit 322ed3406c
No known key found for this signature in database
GPG key ID: 8571BFA20420D512
3 changed files with 42 additions and 32 deletions

View file

@ -12,7 +12,6 @@ import { Setting } from "../../Database";
// FileSytem
import * as FileSystem from 'expo-file-system';
const api_token = 'toto';
class InstallController {
@ -29,38 +28,43 @@ class InstallController {
},
})
.then(function (response) {
if (response.data) {
if (response.data.status === "OK") {
_.forEach(response.data.datas, function (value, key) {
switch (key) {
case "MainColor":
Setting.add({ key: key, value: value });
break;
case "SquaredLogo":
console.log("SquaredLogo");
break;
case "RectangleLogo":
console.log("RectangleLogo");
break;
case "BackgroundImage":
console.log("BackgroundImage");
break;
case "HomeButtonImage":
console.log("HomeButtonImage");
break;
}
});
} else {
Alert.alert(i18n.t("error.error"), i18n.t("error.error_has_occurred"));
if (response.data) {
if (response.data.status === "OK") {
_.forEach(response.data.datas, function (value, key) {
switch (key) {
case "MainColor":
Setting.add({ key: key, value: value });
break;
case "SquaredLogo":
case "RectangleLogo":
case "BackgroundImage":
case "HomeButtonImage":
FileSystem.downloadAsync(
url + "/" + value,
FileSystem.documentDirectory + key + '.png'
)
.then(({ uri }) => {
console.log('Finished downloading to ', uri);
})
.catch(error => {
Alert.alert(i18n.t("alert.error"), i18n.t("install.resource_dl_error") + key);
console.error(error);
});
break;
}
});
Alert.alert(i18n.t("alert.info"), i18n.t("install.install_complete"));
} else {
Alert.alert(i18n.t("alert.error"), i18n.t("alert.error_has_occurred"));
}
}
}
})
})
.catch(function (error) {
console.log(error)
Alert.alert(i18n.t("error.error"), i18n.t("error.error_has_occurred"));
})
Alert.alert(i18n.t("alert.error"), i18n.t("alert.error_has_occurred"));
})
} else {
Alert.alert(i18n.t("error.error"), i18n.t("error.tablet_not_connected_internet"));
Alert.alert(i18n.t("alert.error"), i18n.t("error.tablet_not_connected_internet"));
}
});
}

View file

@ -31,12 +31,12 @@ class InstallScreen extends React.Component {
title={ i18n.t('install.install')}
onPress={() => {
if (this.state.url.length === 0) {
Alert.alert(i18n.t("error.error"), i18n.t("install.enter_url"));
Alert.alert(i18n.t("alert.error"), i18n.t("install.enter_url"));
} else {
if (Helpers.isUrlValid(this.state.url)) {
InstallController.getConfig(this.state.url);
} else {
Alert.alert(i18n.t("error.error"), i18n.t("install.url_invalid"));
Alert.alert(i18n.t("alert.error"), i18n.t("install.url_invalid"));
}
}
}}

View file

@ -2,7 +2,9 @@
"install": {
"install": "Installer",
"enter_url": "Veuillez entrer le lien de votre back-office",
"url_invalid": "Le lien saisi est invalide."
"url_invalid": "Le lien saisi est invalide.",
"resource_dl_error": "Une erreur est survenue lors du téléchargement de la ressource suivante : ",
"install_complete": "Installation terminée !"
},
"global": {
"yes": "Oui",
@ -110,6 +112,10 @@
"camera_permission_denied": "Permission caméra refusée",
"pending_camera_permission": "En attente de permission caméra"
},
"alert": {
"error": "Erreur",
"info": "Information"
},
"custom": {
"select-1": {
"title": "Type de commerce",