Gestita installazione delle versioni beta
This commit is contained in:
parent
d3b7cd8cd6
commit
6105c44dab
@ -132,8 +132,8 @@ public class MainApplicationModule {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
UpdatesManager provideUpdatesManager() {
|
UpdatesManager provideUpdatesManager(ExecutorService executorService, Handler handler, SystemRESTConsumer systemRESTConsumer) {
|
||||||
return new UpdatesManager();
|
return new UpdatesManager(executorService, handler, systemRESTConsumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
|||||||
@ -45,25 +45,16 @@ public class SystemRESTConsumer extends _BaseRESTConsumer {
|
|||||||
this.restBuilder = restBuilder;
|
this.restBuilder = restBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void retrieveUpdatesInfo(final RunnableArgs<LatestAppVersionInfoDTO> onSuccess, final RunnableArgs<Exception> onFailed) {
|
public LatestAppVersionInfoDTO retrieveUpdatesInfoSynchronized(boolean betaVersion) throws Exception {
|
||||||
SystemRESTConsumerService systemRESTConsumerService = restBuilder.getService(SystemRESTConsumerService.class);
|
SystemRESTConsumerService systemRESTConsumerService = restBuilder.getService(SystemRESTConsumerService.class);
|
||||||
systemRESTConsumerService.retrieveUpdatesInfo()
|
var response = systemRESTConsumerService.retrieveUpdatesInfo(betaVersion ? "beta" : null)
|
||||||
.enqueue(new ManagedErrorCallback<>() {
|
.execute();
|
||||||
@Override
|
|
||||||
public void onResponse(Call<LatestAppVersionInfoDTO> call, Response<LatestAppVersionInfoDTO> response) {
|
|
||||||
if(response.code() == 404) {
|
|
||||||
onSuccess.run(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
analyzeAnswerGeneric(response, "updates", onSuccess, onFailed);
|
if (response.code() == 404) {
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
return analyzeAnswerGeneric(response, "updates");
|
||||||
public void onFailure(Call<LatestAppVersionInfoDTO> call, @NonNull final Exception e) {
|
|
||||||
onFailed.run(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import retrofit2.http.Query;
|
|||||||
public interface SystemRESTConsumerService {
|
public interface SystemRESTConsumerService {
|
||||||
|
|
||||||
@GET("wms/currentVersion")
|
@GET("wms/currentVersion")
|
||||||
Call<LatestAppVersionInfoDTO> retrieveUpdatesInfo();
|
Call<LatestAppVersionInfoDTO> retrieveUpdatesInfo(@Query("suffix") String suffix);
|
||||||
|
|
||||||
@POST("device/register")
|
@POST("device/register")
|
||||||
Call<ServiceRESTResponse<Void>> registerDevice(@Body RegisterDeviceRequestDTO registerDeviceRequestDTO);
|
Call<ServiceRESTResponse<Void>> registerDevice(@Body RegisterDeviceRequestDTO registerDeviceRequestDTO);
|
||||||
|
|||||||
@ -1,13 +1,17 @@
|
|||||||
package it.integry.integrywmsnative.core.update;
|
package it.integry.integrywmsnative.core.update;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.os.Handler;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
@ -17,37 +21,62 @@ import it.integry.integrywmsnative.core.rest.model.system.LatestAppVersionInfoDT
|
|||||||
import it.integry.integrywmsnative.core.settings.SettingsManager;
|
import it.integry.integrywmsnative.core.settings.SettingsManager;
|
||||||
import it.integry.integrywmsnative.core.utility.FileDownloader;
|
import it.integry.integrywmsnative.core.utility.FileDownloader;
|
||||||
import it.integry.integrywmsnative.core.utility.UtilityExceptions;
|
import it.integry.integrywmsnative.core.utility.UtilityExceptions;
|
||||||
|
import it.integry.integrywmsnative.gest.settings.MainSettingsFragment;
|
||||||
import it.integry.integrywmsnative.view.dialogs.DialogProgressView;
|
import it.integry.integrywmsnative.view.dialogs.DialogProgressView;
|
||||||
import it.integry.integrywmsnative.view.dialogs.update_available.DialogUpdateAvailableView;
|
import it.integry.integrywmsnative.view.dialogs.update_available.DialogUpdateAvailableView;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class UpdatesManager {
|
public class UpdatesManager {
|
||||||
|
|
||||||
|
private final ExecutorService executorService;
|
||||||
|
private final Handler handler;
|
||||||
|
private final SystemRESTConsumer systemRESTConsumer;
|
||||||
|
|
||||||
private AppCompatActivity mContext;
|
private AppCompatActivity mContext;
|
||||||
|
|
||||||
public void init(AppCompatActivity activityContext, SystemRESTConsumer systemRESTConsumer) {
|
public UpdatesManager(ExecutorService executorService, Handler handler, SystemRESTConsumer systemRESTConsumer) {
|
||||||
|
this.executorService = executorService;
|
||||||
|
this.handler = handler;
|
||||||
|
this.systemRESTConsumer = systemRESTConsumer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(AppCompatActivity activityContext) {
|
||||||
this.mContext = activityContext;
|
this.mContext = activityContext;
|
||||||
|
|
||||||
final String baseEndpoint = SettingsManager.i().getServer().getProtocol() + "://" + SettingsManager.i().getServer().getHost() +
|
executorService.execute(() -> {
|
||||||
(SettingsManager.i().getServer().getPort() > 0 ? ":" + SettingsManager.i().getServer().getPort() : "");
|
|
||||||
|
|
||||||
final String currentVersionUrl = baseEndpoint + "/ems-api/wms/currentVersion";
|
try {
|
||||||
final String currentDownloadUrl = baseEndpoint + "/ems-api/wms/android-release.apk";
|
final String baseEndpoint = SettingsManager.i().getServer().getProtocol() + "://" + SettingsManager.i().getServer().getHost() +
|
||||||
|
(SettingsManager.i().getServer().getPort() > 0 ? ":" + SettingsManager.i().getServer().getPort() : "");
|
||||||
|
|
||||||
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(activityContext);
|
||||||
|
var betaEnabled = sharedPreferences.getBoolean(MainSettingsFragment.KEY_BUTTON_ENABLE_BETA, false);
|
||||||
|
|
||||||
systemRESTConsumer.retrieveUpdatesInfo(latestData -> {
|
LatestAppVersionInfoDTO latestData = systemRESTConsumer.retrieveUpdatesInfoSynchronized(betaEnabled);
|
||||||
|
|
||||||
if (latestData == null)
|
if (latestData == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(latestData.getLatestVersionCode() <= BuildConfig.VERSION_CODE)
|
if (latestData.getLatestVersionCode() < BuildConfig.VERSION_CODE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
showDialog(latestData, () -> {
|
boolean currentVersionIsBeta = BuildConfig.VERSION_NAME.contains("beta");
|
||||||
installAPK(currentDownloadUrl);
|
|
||||||
});
|
if(currentVersionIsBeta == betaEnabled && latestData.getLatestVersionCode() == BuildConfig.VERSION_CODE)
|
||||||
}, ex -> UtilityExceptions.defaultException(mContext, ex));
|
return;
|
||||||
|
|
||||||
|
String currentDownloadUrl = baseEndpoint + latestData.getUrl();
|
||||||
|
|
||||||
|
showDialog(latestData, () -> {
|
||||||
|
installAPK(currentDownloadUrl);
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
handler.post(() -> {
|
||||||
|
UtilityExceptions.defaultException(mContext, e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showDialog(LatestAppVersionInfoDTO updatesData, Runnable onUpdateStart) {
|
private void showDialog(LatestAppVersionInfoDTO updatesData, Runnable onUpdateStart) {
|
||||||
@ -67,13 +96,13 @@ public class UpdatesManager {
|
|||||||
.setDestFolder(destination)
|
.setDestFolder(destination)
|
||||||
.setUrlString(downloadURL)
|
.setUrlString(downloadURL)
|
||||||
.setOnProgressUpdate(progress -> {
|
.setOnProgressUpdate(progress -> {
|
||||||
mContext.runOnUiThread(() -> {
|
handler.post(() -> {
|
||||||
progressDialogBuilder.setProgress(progress);
|
progressDialogBuilder.setProgress(progress);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.setOnDownloadCompleted(destPath -> {
|
.setOnDownloadCompleted(destPath -> {
|
||||||
|
|
||||||
mContext.runOnUiThread(() -> {
|
handler.post(() -> {
|
||||||
progressDialogBuilder.dismiss();
|
progressDialogBuilder.dismiss();
|
||||||
|
|
||||||
if (!destination.exists()) {
|
if (!destination.exists()) {
|
||||||
@ -103,13 +132,13 @@ public class UpdatesManager {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
new Thread(() -> {
|
executorService.execute(() -> {
|
||||||
try {
|
try {
|
||||||
fileDownloader.download();
|
fileDownloader.download();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
progressDialogBuilder.dismissAllowingStateLoss();
|
progressDialogBuilder.dismissAllowingStateLoss();
|
||||||
UtilityExceptions.defaultException(mContext, e);
|
UtilityExceptions.defaultException(mContext, e);
|
||||||
}
|
}
|
||||||
}).start();
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -89,7 +89,7 @@ public class MainActivity extends BaseActivity
|
|||||||
mBinding = DataBindingUtil.inflate(LayoutInflater.from(this), R.layout.activity_main, null, false);
|
mBinding = DataBindingUtil.inflate(LayoutInflater.from(this), R.layout.activity_main, null, false);
|
||||||
setContentView(mBinding.getRoot());
|
setContentView(mBinding.getRoot());
|
||||||
|
|
||||||
updatesManager.init(this, systemRESTConsumer);
|
updatesManager.init(this);
|
||||||
UtilityContext.initMainActivity(this);
|
UtilityContext.initMainActivity(this);
|
||||||
|
|
||||||
setSupportActionBar(mBinding.appBarMain.toolbar);
|
setSupportActionBar(mBinding.appBarMain.toolbar);
|
||||||
|
|||||||
@ -76,6 +76,7 @@ public class MainSettingsFragment extends PreferenceFragmentCompat implements IT
|
|||||||
public static final String KEY_PALLET_BT_DEVICE = "pallet_scale_bt_device";
|
public static final String KEY_PALLET_BT_DEVICE = "pallet_scale_bt_device";
|
||||||
public static final String KEY_TRIGGER_SCAN_MODE = "TRIG_SCAN_MODE";
|
public static final String KEY_TRIGGER_SCAN_MODE = "TRIG_SCAN_MODE";
|
||||||
public static final String KEY_TRIGGER_SCAN_DELAY = "TRIG_SCAN_DELAY";
|
public static final String KEY_TRIGGER_SCAN_DELAY = "TRIG_SCAN_DELAY";
|
||||||
|
public static final String KEY_BUTTON_ENABLE_BETA = "ENABLE_BETA";
|
||||||
public static final String KEY_BUTTON_EXPORT_LOG = "EXPORT_LOG";
|
public static final String KEY_BUTTON_EXPORT_LOG = "EXPORT_LOG";
|
||||||
|
|
||||||
private Collection<BluetoothDevice> btPairedDevices;
|
private Collection<BluetoothDevice> btPairedDevices;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user