1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-25 10:05:49 +01:00

Fossil Hybrid HR: Show progress bar while installing watchface

This commit is contained in:
Arjan Schrijver 2021-07-22 22:04:31 +02:00
parent ba5c87e7a8
commit 35da8fcad0
3 changed files with 47 additions and 3 deletions

View File

@ -18,9 +18,12 @@ package nodomain.freeyourgadget.gadgetbridge.devices.qhybrid;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@ -49,6 +52,8 @@ import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@ -72,6 +77,7 @@ import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBActivity;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport;
import nodomain.freeyourgadget.gadgetbridge.util.BitmapUtil;
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
@ -88,6 +94,28 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
final private ArrayList<HybridHRWatchfaceWidget> widgets = new ArrayList<>();
private HybridHRWatchfaceSettings watchfaceSettings = new HybridHRWatchfaceSettings();
private int defaultWidgetColor = HybridHRWatchfaceWidget.COLOR_WHITE;
private boolean readyToCloseActivity = false;
BroadcastReceiver fileUploadReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(QHybridSupport.QHYBRID_ACTION_UPLOADED_FILE)) {
boolean success = intent.getBooleanExtra("EXTRA_SUCCESS", false);
findViewById(R.id.watchface_upload_progress_bar).setVisibility(View.GONE);
if (success) {
if (readyToCloseActivity) {
finish();
}
} else {
readyToCloseActivity = false;
new AlertDialog.Builder(HybridHRWatchfaceDesignerActivity.this)
.setMessage(R.string.watchface_upload_failed)
.setPositiveButton(R.string.ok, null)
.show();
}
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -102,6 +130,10 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
throw new IllegalArgumentException("Must provide a device when invoking this activity");
}
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(QHybridSupport.QHYBRID_ACTION_UPLOADED_FILE);
LocalBroadcastManager.getInstance(this).registerReceiver(fileUploadReceiver, intentFilter);
mCoordinator = DeviceHelper.getInstance().getCoordinator(mGBDevice);
calculateDisplayImageSize();
backgroundImageView = findViewById(R.id.hybridhr_background_image);
@ -619,14 +651,16 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
fos.close();
final Uri tempAppFileUri = Uri.fromFile(tempFile);
if (preview) {
findViewById(R.id.watchface_upload_progress_bar).setVisibility(View.VISIBLE);
GBApplication.deviceService().onInstallApp(tempAppFileUri);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
GBApplication.deviceService().onInstallApp(tempAppFileUri);
GBApplication.deviceService().onAppDelete(UUID.nameUUIDFromBytes("previewWatchface".getBytes(StandardCharsets.UTF_8)));
}
}, 10000);
} else {
readyToCloseActivity = true;
final FossilFileReader fossilFile = new FossilFileReader(tempAppFileUri, this);
GBDeviceApp app = fossilFile.getGBDeviceApp();
File cacheDir = mCoordinator.getAppCacheDir();
@ -638,16 +672,16 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
findViewById(R.id.watchface_upload_progress_bar).setVisibility(View.VISIBLE);
GBApplication.deviceService().onInstallApp(tempAppFileUri);
FossilHRInstallHandler.saveAppInCache(fossilFile, processedBackgroundImage, mCoordinator, HybridHRWatchfaceDesignerActivity.this);
finish();
}
})
.show();
} else {
findViewById(R.id.watchface_upload_progress_bar).setVisibility(View.VISIBLE);
GBApplication.deviceService().onInstallApp(tempAppFileUri);
FossilHRInstallHandler.saveAppInCache(fossilFile, processedBackgroundImage, mCoordinator, HybridHRWatchfaceDesignerActivity.this);
finish();
}
}
} catch (IOException e) {

View File

@ -11,6 +11,15 @@
android:orientation="vertical"
tools:context=".devices.qhybrid.HybridHRWatchfaceDesignerActivity">
<ProgressBar
style="@android:style/Widget.DeviceDefault.ProgressBar.Horizontal"
android:id="@+id/watchface_upload_progress_bar"
android:layout_width="match_parent"
android:layout_height="10dp"
android:scaleY="3"
android:indeterminate="true"
android:visibility="gone" />
<RelativeLayout
android:id="@+id/watchface_name_layout"
android:layout_width="match_parent"

View File

@ -1242,4 +1242,5 @@
<string name="watchface_setting_wrist_flick_minute">Minute hand (-360 to 360):</string>
<string name="watchface_setting_wrist_flick_duration">Duration (in ms):</string>
<string name="watchface_cache_confirm_overwrite">A watchface with this name already exists in the cache. Do you want to overwrite it?</string>
<string name="watchface_upload_failed">Upload of the watchface failed. Please try again.</string>
</resources>