Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Start implementing device aliases (#1888)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashimokawa committed Jun 12, 2020
1 parent 8400568 commit 53f5439
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
### Changelog

#### 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 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class GBDaoGenerator {


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 user = addUserInfo(schema, userAttributes);
Expand Down Expand Up @@ -171,6 +171,7 @@ private static Entity addDevice(Schema schema, Entity deviceAttributes) {
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.addStringProperty("model").javaDocGetterAndSetter("An optional model, further specifying the kind of device-");
device.addStringProperty("alias");
Property deviceId = deviceAttributes.addLongProperty("deviceId").notNull().getProperty();
// sorted by the from-date, newest first
Property deviceAttributesSortProperty = getPropertyByName(deviceAttributes, VALID_FROM_UTC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,10 @@ private void justifyListViewHeightBasedOnChildren(ListView listView) {
}

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 (device.getModel() != null) {
deviceName = deviceName + " " + device.getModel();
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Collection<? extends ScanFilter> createBLEScanFilters() {

@Override
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ protected void performPair(GBDevice gbDevice) {

private void performConnect(GBDevice gbDevice) {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public GBDevice[] newArray(int size) {
private static final String DEVINFO_ADDR = "ADDR: ";
private static final String DEVINFO_ADDR2 = "ADDR2: ";
private String mName;
private String mAlias;
private final String mAddress;
private String mVolatileAddress;
private final DeviceType mDeviceType;
Expand All @@ -86,20 +87,22 @@ public GBDevice[] newArray(int size) {
private int mNotificationIconDisconnected = R.drawable.ic_notification_disconnected;
private int mNotificationIconLowBattery = R.drawable.ic_notification_low_battery;

public GBDevice(String address, String name, DeviceType deviceType) {
this(address, null, name, deviceType);
public GBDevice(String address, String name, String alias, DeviceType 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;
mVolatileAddress = address2;
mName = (name != null) ? name : mAddress;
mAlias = alias;
mDeviceType = deviceType;
validate();
}

private GBDevice(Parcel in) {
mName = in.readString();
mAlias = in.readString();
mAddress = in.readString();
mVolatileAddress = in.readString();
mDeviceType = DeviceType.values()[in.readInt()];
Expand All @@ -124,6 +127,7 @@ private GBDevice(Parcel in) {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mName);
dest.writeString(mAlias);
dest.writeString(mAddress);
dest.writeString(mVolatileAddress);
dest.writeInt(mDeviceType.ordinal());
Expand Down Expand Up @@ -153,6 +157,10 @@ public String getName() {
return mName;
}

public String getAlias() {
return mAlias;
}

public void setName(String name) {
if (name == null) {
LOG.warn("Ignoring setting of GBDevice name to null for " + this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ public Set<GBDevice> getAvailableDevices(Context context) {
Prefs prefs = GBApplication.getPrefs();
String miAddr = prefs.getString(MiBandConst.PREF_MIBAND_ADDRESS, "");
if (miAddr.length() > 0) {
GBDevice miDevice = new GBDevice(miAddr, "MI", DeviceType.MIBAND);
GBDevice miDevice = new GBDevice(miAddr, "MI", null, DeviceType.MIBAND);
availableDevices.add(miDevice);
}

String pebbleEmuAddr = prefs.getString("pebble_emu_addr", "");
String pebbleEmuPort = prefs.getString("pebble_emu_port", "");
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);
}
return availableDevices;
Expand Down Expand Up @@ -280,7 +280,7 @@ private List<GBDevice> getDatabaseDevices() {
*/
public GBDevice toGBDevice(Device dbDevice) {
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();
if (deviceAttributesList.size() > 0) {
gbDevice.setModel(dbDevice.getModel());
Expand Down

0 comments on commit 53f5439

Please sign in to comment.