mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-28 11:35:48 +01:00
Testing with dummy onboarding activity
crashes
This commit is contained in:
parent
2a2ad20aa3
commit
ec4469a87b
@ -18,8 +18,8 @@ android {
|
||||
targetSdkVersion 23
|
||||
|
||||
// note: always bump BOTH versionCode and versionName!
|
||||
versionName "0.11.2"
|
||||
versionCode 58
|
||||
versionName "0.12.0"
|
||||
versionCode 59
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
|
@ -226,6 +226,11 @@
|
||||
android:parentActivityName=".activities.ControlCenter"
|
||||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="stateHidden" />
|
||||
<activity
|
||||
android:name=".activities.OnboardingActivity"
|
||||
android:label="@string/title_activity_debug"
|
||||
android:parentActivityName=".activities.ControlCenter"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name=".activities.DiscoveryActivity"
|
||||
android:label="@string/title_activity_discovery"
|
||||
|
@ -38,8 +38,11 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity;
|
||||
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
@ -128,6 +131,16 @@ public class ControlCenter extends GBActivity {
|
||||
}
|
||||
} else {
|
||||
GBApplication.deviceService().connect(gbDevice);
|
||||
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
||||
DaoSession session = dbHandler.getDaoSession();
|
||||
|
||||
if (DBHelper.findDevice(gbDevice, session) == null) {
|
||||
Intent startIntent = new Intent(ControlCenter.this, OnboardingActivity.class);
|
||||
startIntent.putExtra(GBDevice.EXTRA_DEVICE, gbDevice);
|
||||
startActivity(startIntent);
|
||||
}
|
||||
} catch (Exception _ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -0,0 +1,73 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.ActivityDatabaseHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
|
||||
public class OnboardingActivity extends GBActivity {
|
||||
|
||||
private Button importOldActivityDataButton;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_onboarding);
|
||||
|
||||
Bundle extras = getIntent().getExtras();
|
||||
|
||||
GBDevice device = null;
|
||||
if (extras != null) {
|
||||
device = extras.getParcelable(GBDevice.EXTRA_DEVICE);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Must provide a device when invoking this activity");
|
||||
}
|
||||
|
||||
importOldActivityDataButton = (Button) findViewById(R.id.mergeOldActivityData);
|
||||
final GBDevice finalDevice = device;
|
||||
importOldActivityDataButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mergeOldActivityDbContents(finalDevice);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void mergeOldActivityDbContents(final GBDevice device) {
|
||||
if (device == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final DBHelper helper = new DBHelper(getBaseContext());
|
||||
final ActivityDatabaseHandler oldHandler = helper.getOldActivityDatabaseHandler();
|
||||
if (oldHandler == null) {
|
||||
GB.toast(this, "No old activity database found, nothing to import.", Toast.LENGTH_LONG, GB.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
try (DBHandler targetHandler = GBApplication.acquireDB()) {
|
||||
final ProgressDialog progress = ProgressDialog.show(OnboardingActivity.this, "Merging Activity Data", "Please wait while merging your activity data...", true, false);
|
||||
new AsyncTask<Object, ProgressDialog, Object>() {
|
||||
@Override
|
||||
protected Object doInBackground(Object[] params) {
|
||||
helper.importOldDb(oldHandler, device, targetHandler);
|
||||
progress.dismiss();
|
||||
return null;
|
||||
}
|
||||
}.execute((Object[]) null);
|
||||
} catch (Exception ex) {
|
||||
GB.toast(OnboardingActivity.this, "Error importing old activity data into new database.", Toast.LENGTH_LONG, GB.ERROR, ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
19
app/src/main/res/layout/activity_onboarding.xml
Normal file
19
app/src/main/res/layout/activity_onboarding.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context="nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter">
|
||||
|
||||
|
||||
<Button
|
||||
android:id="@+id/mergeOldActivityData"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="fill_horizontal"
|
||||
android:text="Merge old activity data" />
|
||||
|
||||
</RelativeLayout>
|
Loading…
Reference in New Issue
Block a user