Start implementing device aliases (#1888)

This commit is contained in:
Andreas Shimokawa 2020-06-12 18:04:53 +02:00
parent 8400568aed
commit 53f5439444
8 changed files with 61 additions and 11 deletions

View File

@ -1,7 +1,7 @@
### Changelog ### Changelog
#### Next #### Next
* Haumi: Support flashing newer GPS firmware and GPS ALM * Huami: Support flashing newer GPS firmware and GPS ALM
* Amazfit Bip S: Support music control * Amazfit Bip S: Support music control
* Amazfit Bip S: Support flashing firmware, res, gps firmware, watchfaces, fonts and GPS CEP * Amazfit Bip S: Support flashing firmware, res, gps firmware, watchfaces, fonts and GPS CEP
* Amazfit Bip S: Allow setting high MTU (much faster firmware installation, default off since it does not work for some) * Amazfit Bip S: Allow setting high MTU (much faster firmware installation, default off since it does not work for some)

View File

@ -43,7 +43,7 @@ public class GBDaoGenerator {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Schema schema = new Schema(26, MAIN_PACKAGE + ".entities"); Schema schema = new Schema(27, MAIN_PACKAGE + ".entities");
Entity userAttributes = addUserAttributes(schema); Entity userAttributes = addUserAttributes(schema);
Entity user = addUserInfo(schema, userAttributes); Entity user = addUserInfo(schema, userAttributes);
@ -171,6 +171,7 @@ public class GBDaoGenerator {
device.addStringProperty("identifier").notNull().unique().javaDocGetterAndSetter("The fixed identifier, i.e. MAC address of the device."); device.addStringProperty("identifier").notNull().unique().javaDocGetterAndSetter("The fixed identifier, i.e. MAC address of the device.");
device.addIntProperty("type").notNull().javaDocGetterAndSetter("The DeviceType key, i.e. the GBDevice's type."); device.addIntProperty("type").notNull().javaDocGetterAndSetter("The DeviceType key, i.e. the GBDevice's type.");
device.addStringProperty("model").javaDocGetterAndSetter("An optional model, further specifying the kind of device-"); device.addStringProperty("model").javaDocGetterAndSetter("An optional model, further specifying the kind of device-");
device.addStringProperty("alias");
Property deviceId = deviceAttributes.addLongProperty("deviceId").notNull().getProperty(); Property deviceId = deviceAttributes.addLongProperty("deviceId").notNull().getProperty();
// sorted by the from-date, newest first // sorted by the from-date, newest first
Property deviceAttributesSortProperty = getPropertyByName(deviceAttributes, VALID_FROM_UTC); Property deviceAttributesSortProperty = getPropertyByName(deviceAttributes, VALID_FROM_UTC);

View File

@ -564,7 +564,10 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
} }
private String getUniqueDeviceName(GBDevice device) { private String getUniqueDeviceName(GBDevice device) {
String deviceName = device.getName(); String deviceName = device.getAlias();
if (deviceName == null || deviceName.equals("")) {
deviceName = device.getName();
}
if (!isUniqueDeviceName(device, deviceName)) { if (!isUniqueDeviceName(device, deviceName)) {
if (device.getModel() != null) { if (device.getModel() != null) {
deviceName = deviceName + " " + device.getModel(); deviceName = deviceName + " " + device.getModel();

View File

@ -0,0 +1,38 @@
/* Copyright (C) 2017-2020 Andreas Shimokawa, protomors
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.database.schema;
import android.database.sqlite.SQLiteDatabase;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.database.DBUpdateScript;
import nodomain.freeyourgadget.gadgetbridge.entities.DeviceDao;
public class GadgetbridgeUpdate_27 implements DBUpdateScript {
@Override
public void upgradeSchema(SQLiteDatabase db) {
if (!DBHelper.existsColumn(DeviceDao.TABLENAME, DeviceDao.Properties.Alias.columnName, db)) {
String ADD_COLUMN_ALIAS = "ALTER TABLE " + DeviceDao.TABLENAME + " ADD COLUMN "
+ DeviceDao.Properties.Alias.columnName + " TEXT";
db.execSQL(ADD_COLUMN_ALIAS);
}
}
@Override
public void downgradeSchema(SQLiteDatabase db) {
}
}

View File

@ -68,7 +68,7 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator {
@Override @Override
public GBDevice createDevice(GBDeviceCandidate candidate) { public GBDevice createDevice(GBDeviceCandidate candidate) {
return new GBDevice(candidate.getDevice().getAddress(), candidate.getName(), getDeviceType()); return new GBDevice(candidate.getDevice().getAddress(), candidate.getName(), null, getDeviceType());
} }
@Override @Override

View File

@ -219,7 +219,7 @@ public class PebblePairingActivity extends AbstractGBActivity {
private void performConnect(GBDevice gbDevice) { private void performConnect(GBDevice gbDevice) {
if (gbDevice == null) { if (gbDevice == null) {
gbDevice = new GBDevice(mBtDevice.getAddress(), mBtDevice.getName(), DeviceType.PEBBLE); gbDevice = new GBDevice(mBtDevice.getAddress(), mBtDevice.getName(), null, DeviceType.PEBBLE);
} }
GBApplication.deviceService().connect(gbDevice); GBApplication.deviceService().connect(gbDevice);
} }

View File

@ -66,6 +66,7 @@ public class GBDevice implements Parcelable {
private static final String DEVINFO_ADDR = "ADDR: "; private static final String DEVINFO_ADDR = "ADDR: ";
private static final String DEVINFO_ADDR2 = "ADDR2: "; private static final String DEVINFO_ADDR2 = "ADDR2: ";
private String mName; private String mName;
private String mAlias;
private final String mAddress; private final String mAddress;
private String mVolatileAddress; private String mVolatileAddress;
private final DeviceType mDeviceType; private final DeviceType mDeviceType;
@ -86,20 +87,22 @@ public class GBDevice implements Parcelable {
private int mNotificationIconDisconnected = R.drawable.ic_notification_disconnected; private int mNotificationIconDisconnected = R.drawable.ic_notification_disconnected;
private int mNotificationIconLowBattery = R.drawable.ic_notification_low_battery; private int mNotificationIconLowBattery = R.drawable.ic_notification_low_battery;
public GBDevice(String address, String name, DeviceType deviceType) { public GBDevice(String address, String name, String alias, DeviceType deviceType) {
this(address, null, name, deviceType); this(address, null, name, alias, deviceType);
} }
public GBDevice(String address, String address2, String name, DeviceType deviceType) { public GBDevice(String address, String address2, String name, String alias, DeviceType deviceType) {
mAddress = address; mAddress = address;
mVolatileAddress = address2; mVolatileAddress = address2;
mName = (name != null) ? name : mAddress; mName = (name != null) ? name : mAddress;
mAlias = alias;
mDeviceType = deviceType; mDeviceType = deviceType;
validate(); validate();
} }
private GBDevice(Parcel in) { private GBDevice(Parcel in) {
mName = in.readString(); mName = in.readString();
mAlias = in.readString();
mAddress = in.readString(); mAddress = in.readString();
mVolatileAddress = in.readString(); mVolatileAddress = in.readString();
mDeviceType = DeviceType.values()[in.readInt()]; mDeviceType = DeviceType.values()[in.readInt()];
@ -124,6 +127,7 @@ public class GBDevice implements Parcelable {
@Override @Override
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mName); dest.writeString(mName);
dest.writeString(mAlias);
dest.writeString(mAddress); dest.writeString(mAddress);
dest.writeString(mVolatileAddress); dest.writeString(mVolatileAddress);
dest.writeInt(mDeviceType.ordinal()); dest.writeInt(mDeviceType.ordinal());
@ -153,6 +157,10 @@ public class GBDevice implements Parcelable {
return mName; return mName;
} }
public String getAlias() {
return mAlias;
}
public void setName(String name) { public void setName(String name) {
if (name == null) { if (name == null) {
LOG.warn("Ignoring setting of GBDevice name to null for " + this); LOG.warn("Ignoring setting of GBDevice name to null for " + this);

View File

@ -154,14 +154,14 @@ public class DeviceHelper {
Prefs prefs = GBApplication.getPrefs(); Prefs prefs = GBApplication.getPrefs();
String miAddr = prefs.getString(MiBandConst.PREF_MIBAND_ADDRESS, ""); String miAddr = prefs.getString(MiBandConst.PREF_MIBAND_ADDRESS, "");
if (miAddr.length() > 0) { if (miAddr.length() > 0) {
GBDevice miDevice = new GBDevice(miAddr, "MI", DeviceType.MIBAND); GBDevice miDevice = new GBDevice(miAddr, "MI", null, DeviceType.MIBAND);
availableDevices.add(miDevice); availableDevices.add(miDevice);
} }
String pebbleEmuAddr = prefs.getString("pebble_emu_addr", ""); String pebbleEmuAddr = prefs.getString("pebble_emu_addr", "");
String pebbleEmuPort = prefs.getString("pebble_emu_port", ""); String pebbleEmuPort = prefs.getString("pebble_emu_port", "");
if (pebbleEmuAddr.length() >= 7 && pebbleEmuPort.length() > 0) { if (pebbleEmuAddr.length() >= 7 && pebbleEmuPort.length() > 0) {
GBDevice pebbleEmuDevice = new GBDevice(pebbleEmuAddr + ":" + pebbleEmuPort, "Pebble qemu", DeviceType.PEBBLE); GBDevice pebbleEmuDevice = new GBDevice(pebbleEmuAddr + ":" + pebbleEmuPort, "Pebble qemu", "", DeviceType.PEBBLE);
availableDevices.add(pebbleEmuDevice); availableDevices.add(pebbleEmuDevice);
} }
return availableDevices; return availableDevices;
@ -280,7 +280,7 @@ public class DeviceHelper {
*/ */
public GBDevice toGBDevice(Device dbDevice) { public GBDevice toGBDevice(Device dbDevice) {
DeviceType deviceType = DeviceType.fromKey(dbDevice.getType()); DeviceType deviceType = DeviceType.fromKey(dbDevice.getType());
GBDevice gbDevice = new GBDevice(dbDevice.getIdentifier(), dbDevice.getName(), deviceType); GBDevice gbDevice = new GBDevice(dbDevice.getIdentifier(), dbDevice.getName(), dbDevice.getAlias(), deviceType);
List<DeviceAttributes> deviceAttributesList = dbDevice.getDeviceAttributesList(); List<DeviceAttributes> deviceAttributesList = dbDevice.getDeviceAttributesList();
if (deviceAttributesList.size() > 0) { if (deviceAttributesList.size() > 0) {
gbDevice.setModel(dbDevice.getModel()); gbDevice.setModel(dbDevice.getModel());