1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-18 14:31:23 +02:00

- add more debug logs

- start delayed disconnect timer for Bluetooth connecting
This commit is contained in:
oliexdev
2019-02-11 18:23:23 +01:00
parent 6c2674caa1
commit dd3af28067
4 changed files with 24 additions and 15 deletions

View File

@@ -168,7 +168,6 @@ public class OpenScale {
}
public void selectScaleUser(int userId) {
Timber.d("Select user %d", userId);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putInt("selectedUserId", userId).apply();
@@ -207,8 +206,7 @@ public class OpenScale {
selectScaleUser(-1);
throw new Exception("could not find the selected user");
}
Timber.d("Selected user is now %s (%d)",
selectedScaleUser.getUserName(), selectedScaleUser.getId());
return selectedScaleUser;
}
} catch (Exception e) {
@@ -220,7 +218,7 @@ public class OpenScale {
}
public void deleteScaleUser(int id) {
Timber.d("Delete user %d", id);
Timber.d("Delete user " + getScaleUser(id));
userDAO.delete(userDAO.get(id));
selectedScaleUser = null;
@@ -288,6 +286,7 @@ public class OpenScale {
// don't add scale data if no user is selected
if (scaleMeasurement.getUserId() == -1) {
Timber.e("to be added measurement are thrown away because no user is selected");
return -1;
}
}
@@ -335,6 +334,7 @@ public class OpenScale {
updateScaleData();
triggerWidgetUpdate();
} else {
Timber.d("to be added measurement is thrown away because measurement with the same date and time already exist");
if (!silent) {
Toast.makeText(context, context.getString(R.string.info_new_data_duplicated), Toast.LENGTH_LONG).show();
}
@@ -365,17 +365,21 @@ public class OpenScale {
if (inRangeWeights.size() > 0) {
// return the user id which is nearest to the weight (first element of the tree map)
return inRangeWeights.entrySet().iterator().next().getValue();
int userId = inRangeWeights.entrySet().iterator().next().getValue();
Timber.d("assign measurement to the nearest measurement with the user " + getScaleUser(userId).getUserName() + " (smartUserAssignment=on)");
return userId;
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
// if ignore out of range preference is true don't add this data
if (prefs.getBoolean("ignoreOutOfRange", false)) {
Timber.d("to be added measurement is thrown away because measurement is out of range (smartUserAssignment=on;ignoreOutOfRange=on)");
return -1;
}
// return selected scale user id if not out of range preference is checked and weight is out of range of any user
Timber.d("assign measurement to the selected user (smartUserAssignment=on;ignoreOutOfRange=off)");
return getSelectedScaleUser().getId();
}

View File

@@ -485,6 +485,7 @@ public abstract class BluetoothCommunication {
|| locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
) {
Timber.d("Do LE scan before connecting to device");
disconnectWithDelay();
scanSubscription = bleClient.scanBleDevices(
new ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
@@ -495,7 +496,7 @@ public abstract class BluetoothCommunication {
.subscribe(bleScanResult -> {
if (bleScanResult.getBleDevice().getMacAddress().equals(macAddress)) {
connectToDevice(macAddress);
}}, throwable -> onError(throwable));
}}, throwable -> setBtStatus(BT_STATUS_CODE.BT_NO_DEVICE_FOUND));
}
else {
Timber.d("No coarse location permission, connecting without LE scan");
@@ -535,6 +536,7 @@ public abstract class BluetoothCommunication {
setBtMonitoringOn();
setBtMachineState(BT_MACHINE_STATE.BT_INIT_STATE);
resetDisconnectTimer();
}
}
}, 500);

View File

@@ -16,17 +16,17 @@
package com.health.openscale.core.datatypes;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey;
import androidx.annotation.NonNull;
import com.health.openscale.core.utils.Converters;
import com.health.openscale.core.utils.DateTimeHelpers;
import java.util.Calendar;
import java.util.Date;
import androidx.annotation.NonNull;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey;
@Entity(tableName = "scaleUsers")
public class ScaleUser {
@PrimaryKey(autoGenerate = true)
@@ -189,9 +189,11 @@ public class ScaleUser {
public String toString()
{
return String.format(
"ID: %d, NAME: %s, BIRTHDAY: %s, BODY_HEIGHT: %.2f, SCALE_UNIT: %s, " +
"GENDER: %s, INITIAL_WEIGHT: %.2f, GOAL_WEIGHT: %.2f, GOAL_DATE: %s",
id, userName, birthday.toString(), bodyHeight, scaleUnit.toString(),
gender.toString().toLowerCase(), initialWeight, goalWeight, goalDate.toString());
"id(%d) name(%s) birthday(%s) age(%d) body height(%.2f) scale unit(%s) " +
"gender(%s) initial weight(%.2f) goal weight(%.2f) goal date(%s) " +
"measure unt(%s) activity level(%d)",
id, userName, birthday.toString(), getAge(), bodyHeight, scaleUnit.toString(),
gender.toString().toLowerCase(), initialWeight, goalWeight, goalDate.toString(),
measureUnit.toString(), activityLevel.toInt());
}
}

View File

@@ -143,6 +143,7 @@ public class AboutPreferences extends PreferenceFragment {
getResources().getString(R.string.app_name),
BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE,
Build.VERSION.SDK_INT, Build.MANUFACTURER, Build.MODEL);
Timber.d("Selected user " + OpenScale.getInstance().getSelectedScaleUser());
}
catch (IOException ex) {
Timber.e(ex, "Failed to open debug log %s", uri.toString());