Commit c193239a authored by Vitaliy Vashchenko's avatar Vitaliy Vashchenko

#884 code refactoring

parent b744b4e6
......@@ -229,9 +229,8 @@ task prepareHdAssets(dependsOn: [prepareAssets, prepareSoundAssets, prepareJsonA
String dirName = dir.getName()
String destDir = "${buildDir}/${assetsDirName}/" + "hd/" + "${assetsSourceDirName}/${dirName}"
task("${name}_${dirName}", type: Copy) {
from sourceDir.absolutePath + "/common"
from hdSourceDir.absolutePath + "/common"
from dir.absolutePath
from hdSourceDir.absolutePath + "/common"
from hdSourceDir.absolutePath + "/" + dirName
into destDir
}.execute()
......@@ -402,7 +401,7 @@ task zipHdAssets(dependsOn: prepareHdGraphicAssets) {
if (!dir.name.equals('common')) {
task("${name}_${dir.name}", type: Zip) {
archiveName = "hd_" + dir.getName() + "_SNAPSHOT.zip"
archiveName = dir.getName() + "_SNAPSHOT_HD.zip"
destinationDir = rootProject.ext.assetsHdPackDir
from "${buildDir}/${assetsDirName}/" + "hd/" + "${assetsDestinationDirName}/${dir.name}"
}.execute()
......
......@@ -87,6 +87,7 @@ public class TablexiaSettings {
private User selectedUser;
private boolean soundMuted = false;
private boolean hdAssets = false;
protected static boolean languageChosen = false;
......@@ -220,12 +221,13 @@ public class TablexiaSettings {
private static TablexiaSettings instance;
private TablexiaSettings(BuildType buildType, Locale systemLocale, boolean hasSoftBackButton, boolean supportAlternativeControls) {
private TablexiaSettings(BuildType buildType, Locale systemLocale, boolean hasSoftBackButton, boolean supportAlternativeControls, boolean hdAssets) {
BUILD_TYPE = buildType;
HAS_SOFT_BACK_BUTTON = hasSoftBackButton;
SUPPORT_ALTERNATIVE_CONTROLS = supportAlternativeControls;
this.systemLocale = LocaleDefinition.getLocaleDefinitionForLocale(systemLocale);
languageChosen = selectedLocale == LocaleDefinition.FALLBACK_VARIANT || languageChosen;
this.hdAssets = hdAssets;
}
public static TablexiaSettings getInstance() {
......@@ -236,19 +238,19 @@ public class TablexiaSettings {
return instance;
}
static void init(String buildTypeKey, Locale systemLocale, boolean hasSoftBackButton, boolean supportAlternativeControls, String hwSerial) {
TablexiaSettings.init(BuildType.getBuildTypeForKey(buildTypeKey), systemLocale, hasSoftBackButton, supportAlternativeControls, hwSerial);
static void init(String buildTypeKey, Locale systemLocale, boolean hasSoftBackButton, boolean supportAlternativeControls, String hwSerial, boolean hdAssets) {
TablexiaSettings.init(BuildType.getBuildTypeForKey(buildTypeKey), systemLocale, hasSoftBackButton, supportAlternativeControls, hwSerial, hdAssets);
}
static void init(BuildType buildType, Locale systemLocale, boolean hasSoftBackButton, boolean supportAlternativeControls, String hwSerialNumber) {
static void init(BuildType buildType, Locale systemLocale, boolean hasSoftBackButton, boolean supportAlternativeControls, String hwSerialNumber, boolean hdAssets) {
if (instance != null) {
String exceptionMessage = "Tablexia settings already initialized!";
Log.err(TablexiaSettings.class, exceptionMessage);
return;
}
instance = new TablexiaSettings(buildType, systemLocale, hasSoftBackButton, supportAlternativeControls);
instance = new TablexiaSettings(buildType, systemLocale, hasSoftBackButton, supportAlternativeControls, hdAssets);
TablexiaSettings.HW_SERIAL_NUMBER = hwSerialNumber;
}
......@@ -344,7 +346,11 @@ public class TablexiaSettings {
return DEFAULT_FONT_COLOR;
}
//////////////////////////// SOUND MUTE
public boolean isHdAssets() {
return hdAssets;
}
//////////////////////////// SOUND MUTE
public boolean isSoundMuted() { return soundMuted; }
......@@ -452,6 +458,26 @@ public class TablexiaSettings {
}
public enum AssetsPackDefinition {
DEFAULT(""),
HD("_HD");
private String packSuffix;
AssetsPackDefinition(String packSuffix) {
this.packSuffix = packSuffix;
}
public String getPackSuffix() {
return packSuffix;
}
public static String getAssetsPackSuffix(){
return TablexiaSettings.getInstance().isHdAssets() ? HD.getPackSuffix() : DEFAULT.getPackSuffix();
}
}
//////////////////////////// LOCALE SETTINGS
public static class LocaleChangedEvent implements ApplicationBus.ApplicationEvent {
......
......@@ -71,8 +71,8 @@ public class TablexiaAssetsAsyncTask implements AsyncTask<Void>, TablexiaAssetsM
//Delete ..assets/
TablexiaAssetsUtil.deleteDirectory(TablexiaAbstractFileManager.getFileStoragePathFileHandle(TablexiaAbstractFileManager.AssetsStorageType.EXTERNAL).file());
String assetsPackageName = locale.getLanguage() + "_" + checksum + ZIP_FILE_EXTENSION;
String checksumPackageName = locale.getLanguage() + "_" + checksum + CHECKSUM_FILE_EXTENSION;
String assetsPackageName = locale.getLanguage() + "_" + checksum + TablexiaSettings.AssetsPackDefinition.getAssetsPackSuffix() + ZIP_FILE_EXTENSION;
String checksumPackageName = locale.getLanguage() + "_" + checksum + TablexiaSettings.AssetsPackDefinition.getAssetsPackSuffix() + CHECKSUM_FILE_EXTENSION;
FileHandle assetsPackageFileHandle = TablexiaAbstractFileManager.getFileStoragePathFileHandle(TablexiaAbstractFileManager.DownloadStorageType.EXTERNAL, assetsPackageName);
FileHandle checksumPackageFileHandle = TablexiaAbstractFileManager.getFileStoragePathFileHandle(TablexiaAbstractFileManager.DownloadStorageType.EXTERNAL, checksumPackageName);
......@@ -112,9 +112,9 @@ public class TablexiaAssetsAsyncTask implements AsyncTask<Void>, TablexiaAssetsM
return null;
}else {
assetsPackageFileHandle = TablexiaAbstractFileManager.getFileStoragePathFileHandle(TablexiaAbstractFileManager.DownloadStorageType.EXTERNAL,
locale.getLanguage() + "_" + SNAPSHOT_FILE_NAME + ZIP_FILE_EXTENSION);
locale.getLanguage() + "_" + SNAPSHOT_FILE_NAME + TablexiaSettings.AssetsPackDefinition.getAssetsPackSuffix() + ZIP_FILE_EXTENSION);
checksumPackageFileHandle = TablexiaAbstractFileManager.getFileStoragePathFileHandle(TablexiaAbstractFileManager.DownloadStorageType.EXTERNAL,
locale.getLanguage() + "_" + SNAPSHOT_FILE_NAME + CHECKSUM_FILE_EXTENSION);
locale.getLanguage() + "_" + SNAPSHOT_FILE_NAME + TablexiaSettings.AssetsPackDefinition.getAssetsPackSuffix() + CHECKSUM_FILE_EXTENSION);
if (!TablexiaAssetsUtil.checkAssetsPackage(checksumPackageFileHandle, assetsPackageFileHandle)) {
Log.info(getClass(), "Local snapshot isn't valid.");
......
......@@ -67,8 +67,8 @@ public class TablexiaAssetsManager extends TablexiaDataManager<Void> implements
ArrayList<TablexiaSettings.LocaleDefinition> availableLocale = new ArrayList<>();
for (TablexiaSettings.LocaleDefinition localeDefinition : TablexiaSettings.LocaleDefinition.getSelectableLocaleDefinitions()){
String localeChecksum = buildChecksumMap.get(localeDefinition.getLocale().getLanguage());
FileHandle checksumFileHandle = TablexiaAbstractFileManager.getFileStoragePathFileHandle(TablexiaAbstractFileManager.DownloadStorageType.EXTERNAL, localeDefinition.getLocale().getLanguage() + "_" + localeChecksum + ".checksum");
FileHandle packageFileHandle = TablexiaAbstractFileManager.getFileStoragePathFileHandle(TablexiaAbstractFileManager.DownloadStorageType.EXTERNAL, localeDefinition.getLocale().getLanguage() + "_" + localeChecksum + ".zip");
FileHandle checksumFileHandle = TablexiaAbstractFileManager.getFileStoragePathFileHandle(TablexiaAbstractFileManager.DownloadStorageType.EXTERNAL, localeDefinition.getLocale().getLanguage() + "_" + localeChecksum + TablexiaSettings.AssetsPackDefinition.getAssetsPackSuffix() + ".checksum");
FileHandle packageFileHandle = TablexiaAbstractFileManager.getFileStoragePathFileHandle(TablexiaAbstractFileManager.DownloadStorageType.EXTERNAL, localeDefinition.getLocale().getLanguage() + "_" + localeChecksum + TablexiaSettings.AssetsPackDefinition.getAssetsPackSuffix() + ".zip");
if (TablexiaAssetsUtil.checkAssetsPackage(checksumFileHandle, packageFileHandle)) {
Log.info(getClass(),"Found valid package: " + localeDefinition.name());
availableLocale.add(localeDefinition);
......
......@@ -40,6 +40,7 @@ import java.util.zip.ZipInputStream;
import cz.nic.tablexia.Tablexia;
import cz.nic.tablexia.TablexiaBuildConfig;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.checksum.Checksum;
import cz.nic.tablexia.loader.IApplicationLoader;
......@@ -318,8 +319,8 @@ public class ZipAssetLoader extends TablexiaDataManager<Void> implements IApplic
Log.err(getClass(), String.format("Cannot download assets package: %s", zipAssetsPackageName));
Log.info(ZipAssetLoader.class, "Devel mode --> try to use SNAPSHOT assets package");
String snapshotAssetsPackageName = language + "_" + SNAPSHOT_PACKAGE_NAME;
String snapshotZipAssetsPackageName = snapshotAssetsPackageName + ZIP_FILE_EXTENSION;
String snapshotAssetsPackageName = language + "_" + SNAPSHOT_PACKAGE_NAME + TablexiaSettings.AssetsPackDefinition.getAssetsPackSuffix();
String snapshotZipAssetsPackageName = snapshotAssetsPackageName + TablexiaSettings.AssetsPackDefinition.getAssetsPackSuffix() + ZIP_FILE_EXTENSION;
if (checkAndDownload(snapshotAssetsPackageName)) {
assetsPackageFileHandle = TablexiaAbstractFileManager.getFileStoragePathFileHandle(ZIP_FILES_STORAGE_TYPE, snapshotZipAssetsPackageName);
......@@ -391,8 +392,8 @@ public class ZipAssetLoader extends TablexiaDataManager<Void> implements IApplic
private boolean checkAndDownload(final String fileName) {
int tryCounter = 0;
String zipFileName = fileName + ZIP_FILE_EXTENSION;
String checksumFileName = fileName + CHECKSUM_FILE_EXTENSION;
String zipFileName = fileName + TablexiaSettings.AssetsPackDefinition.getAssetsPackSuffix() + ZIP_FILE_EXTENSION;
String checksumFileName = fileName + TablexiaSettings.AssetsPackDefinition.getAssetsPackSuffix() + CHECKSUM_FILE_EXTENSION;
// load checksum and package file
FileHandle zipFileHandle = TablexiaAbstractFileManager.getFileStoragePathFileHandle(TablexiaAbstractFileManager.DownloadStorageType.EXTERNAL, zipFileName);
......@@ -439,13 +440,13 @@ public class ZipAssetLoader extends TablexiaDataManager<Void> implements IApplic
Log.info(ZipAssetLoader.class, String.format("Downloading checksum file: %s try %d/%d", checksumFileName, tryCounter + 1, DOWNLOAD_TRY_COUNT));
startTimer();
checksumDownloadSuccess = downloadToOutputStream(fileName + CHECKSUM_FILE_EXTENSION, checksumFileHandle.write(false));
checksumDownloadSuccess = downloadToOutputStream(fileName + TablexiaSettings.AssetsPackDefinition.getAssetsPackSuffix() + CHECKSUM_FILE_EXTENSION, checksumFileHandle.write(false));
resultTimer("Download delay of " + checksumFileName);
if(checksumDownloadSuccess) {
Log.info(ZipAssetLoader.class, String.format("Downloading assets package file: %s try %d/%d", zipFileName, tryCounter + 1, DOWNLOAD_TRY_COUNT));
startTimer();
assetsDownloadSuccess = downloadToOutputStream(fileName + ZIP_FILE_EXTENSION, zipFileHandle.write(false));
assetsDownloadSuccess = downloadToOutputStream(fileName + TablexiaSettings.AssetsPackDefinition.getAssetsPackSuffix() + ZIP_FILE_EXTENSION, zipFileHandle.write(false));
resultTimer("Download delay of " + zipFileName);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment