mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-06-05 21:49:48 +02:00
HPlus: Deprecate DeviceType constructor
This commit is contained in:
1
.idea/dictionaries/t.xml
generated
1
.idea/dictionaries/t.xml
generated
@@ -93,6 +93,7 @@
|
||||
<w>lacross</w>
|
||||
<w>ladbsoft</w>
|
||||
<w>ladera</w>
|
||||
<w>lemfo</w>
|
||||
<w>lenovo</w>
|
||||
<w>liebergeld</w>
|
||||
<w>lightforce</w>
|
||||
|
@@ -21,10 +21,13 @@ package nodomain.freeyourgadget.gadgetbridge.devices.hplus;
|
||||
* @author Quallenauge <Hamsi2k@freenet.de>
|
||||
*/
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.hplus.EXRIZUK8Support;
|
||||
|
||||
/**
|
||||
* Pseudo Coordinator for the EXRIZU K8, a sub type of the HPLUS devices
|
||||
@@ -44,4 +47,10 @@ public class EXRIZUK8Coordinator extends HPlusCoordinator {
|
||||
public int getDeviceNameResource() {
|
||||
return R.string.devicetype_exrizu_k8;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Class<? extends DeviceSupport> getDeviceSupportClass() {
|
||||
return EXRIZUK8Support.class;
|
||||
}
|
||||
}
|
||||
|
@@ -253,7 +253,6 @@ public class HPlusCoordinator extends AbstractBLEDeviceCoordinator {
|
||||
return HPlusSupport.class;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getDeviceNameResource() {
|
||||
return R.string.devicetype_hplus;
|
||||
@@ -270,4 +269,3 @@ public class HPlusCoordinator extends AbstractBLEDeviceCoordinator {
|
||||
return R.drawable.ic_device_hplus_disabled;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -21,27 +21,21 @@ package nodomain.freeyourgadget.gadgetbridge.devices.hplus;
|
||||
* @author João Paulo Barraca <jpbarraca@gmail.com>
|
||||
*/
|
||||
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.hplus.MakibesF68Support;
|
||||
|
||||
/**
|
||||
* Pseudo Coordinator for the Makibes F68, a sub type of the HPLUS devices
|
||||
*/
|
||||
public class MakibesF68Coordinator extends HPlusCoordinator {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public boolean supports(GBDeviceCandidate candidate) {
|
||||
String name = candidate.getName();
|
||||
if(name != null && name.startsWith("SPORT") && !name.startsWith("SPORTAGE")){
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return name != null && name.startsWith("SPORT") && !name.startsWith("SPORTAGE");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,4 +47,10 @@ public class MakibesF68Coordinator extends HPlusCoordinator {
|
||||
public int getDeviceNameResource() {
|
||||
return R.string.devicetype_makibes_f68;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Class<? extends DeviceSupport> getDeviceSupportClass() {
|
||||
return MakibesF68Support.class;
|
||||
}
|
||||
}
|
||||
|
@@ -21,14 +21,13 @@ package nodomain.freeyourgadget.gadgetbridge.devices.hplus;
|
||||
* @author Alejandro Ladera Chamorro <11555126+tiparega@users.noreply.github.com>
|
||||
*/
|
||||
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.hplus.Q8Support;
|
||||
|
||||
/**
|
||||
* Pseudo Coordinator for the Q8, a sub type of the HPLUS devices
|
||||
@@ -48,4 +47,10 @@ public class Q8Coordinator extends HPlusCoordinator {
|
||||
public int getDeviceNameResource() {
|
||||
return R.string.devicetype_q8;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Class<? extends DeviceSupport> getDeviceSupportClass() {
|
||||
return Q8Support.class;
|
||||
}
|
||||
}
|
||||
|
@@ -21,14 +21,13 @@ import androidx.annotation.NonNull;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.hplus.SG2Support;
|
||||
|
||||
/**
|
||||
* Pseudo Coordinator for the Lemfo SG2, a sub type of the HPLUS devices
|
||||
*/
|
||||
public class SG2Coordinator extends HPlusCoordinator {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public boolean supports(GBDeviceCandidate candidate) {
|
||||
String name = candidate.getName();
|
||||
@@ -66,4 +65,10 @@ public class SG2Coordinator extends HPlusCoordinator {
|
||||
public int getDeviceNameResource() {
|
||||
return R.string.devicetype_sg2;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Class<? extends DeviceSupport> getDeviceSupportClass() {
|
||||
return SG2Support.class;
|
||||
}
|
||||
}
|
||||
|
@@ -27,7 +27,6 @@ package nodomain.freeyourgadget.gadgetbridge.service;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@@ -36,15 +35,11 @@ import org.slf4j.LoggerFactory;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.BluetoothConnectReceiver;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.EnumSet;
|
||||
|
||||
public class DeviceSupportFactory {
|
||||
@@ -108,22 +103,11 @@ public class DeviceSupportFactory {
|
||||
}
|
||||
|
||||
private ServiceDeviceSupport createServiceDeviceSupport(GBDevice device) throws GBException {
|
||||
DeviceCoordinator coordinator = device.getDeviceCoordinator();
|
||||
Class supportClass = coordinator.getDeviceSupportClass();
|
||||
final DeviceCoordinator coordinator = device.getDeviceCoordinator();
|
||||
final Class<?> supportClass = coordinator.getDeviceSupportClass();
|
||||
|
||||
try {
|
||||
Constructor supportConstructor = supportClass.getConstructor(DeviceType.class);
|
||||
DeviceSupport supportInstance = (DeviceSupport) supportConstructor.newInstance(device.getType());
|
||||
return new ServiceDeviceSupport(supportInstance, coordinator.getInitialFlags());
|
||||
} catch (NoSuchMethodException e) {
|
||||
// ignore, let next call get the default, zero-argument constructor
|
||||
} catch (ReflectiveOperationException e) {
|
||||
LOG.error("error calling DeviceSupport constructor with argument 'DeviceType'");
|
||||
throw new GBException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
DeviceSupport supportInstance = (DeviceSupport) supportClass.newInstance();
|
||||
final DeviceSupport supportInstance = (DeviceSupport) supportClass.newInstance();
|
||||
return new ServiceDeviceSupport(supportInstance, coordinator.getInitialFlags());
|
||||
} catch (ReflectiveOperationException e) {
|
||||
LOG.error("error calling DeviceSupport constructor with zero arguments");
|
||||
@@ -131,15 +115,13 @@ public class DeviceSupportFactory {
|
||||
}
|
||||
}
|
||||
|
||||
private DeviceSupport createBTDeviceSupport(GBDevice gbDevice) throws GBException {
|
||||
private DeviceSupport createBTDeviceSupport(final GBDevice gbDevice) throws GBException {
|
||||
if (mBtAdapter != null && mBtAdapter.isEnabled()) {
|
||||
try {
|
||||
DeviceSupport deviceSupport = createServiceDeviceSupport(gbDevice);
|
||||
if (deviceSupport != null) {
|
||||
final DeviceSupport deviceSupport = createServiceDeviceSupport(gbDevice);
|
||||
deviceSupport.setContext(gbDevice, mBtAdapter, mContext);
|
||||
return deviceSupport;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
throw new GBException(mContext.getString(R.string.cannot_connect_bt_address_invalid_), e);
|
||||
}
|
||||
}
|
||||
@@ -155,5 +137,4 @@ public class DeviceSupportFactory {
|
||||
throw new GBException("cannot connect to " + gbDevice, e); // FIXME: localize
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,25 @@
|
||||
/* Copyright (C) 2025 José Rebelo
|
||||
|
||||
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 <https://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.hplus;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||
|
||||
public class EXRIZUK8Support extends HPlusSupport {
|
||||
public EXRIZUK8Support() {
|
||||
super(DeviceType.EXRIZUK8);
|
||||
}
|
||||
}
|
@@ -66,11 +66,15 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
public BluetoothGattCharacteristic ctrlCharacteristic = null;
|
||||
public BluetoothGattCharacteristic measureCharacteristic = null;
|
||||
private HPlusHandlerThread syncHelper;
|
||||
private DeviceType deviceType = DeviceType.UNKNOWN;
|
||||
private final DeviceType deviceType;
|
||||
|
||||
public HPlusSupport(DeviceType type) {
|
||||
public HPlusSupport() {
|
||||
this(DeviceType.HPLUS);
|
||||
}
|
||||
|
||||
protected HPlusSupport(final DeviceType type) {
|
||||
super(LOG);
|
||||
LOG.info("HPlusSupport Instance Created");
|
||||
LOG.info("HPlusSupport Instance created for {}", type);
|
||||
deviceType = type;
|
||||
|
||||
addSupportedService(HPlusConstants.UUID_SERVICE_HP);
|
||||
|
@@ -0,0 +1,25 @@
|
||||
/* Copyright (C) 2025 José Rebelo
|
||||
|
||||
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 <https://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.hplus;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||
|
||||
public class MakibesF68Support extends HPlusSupport {
|
||||
public MakibesF68Support() {
|
||||
super(DeviceType.MAKIBESF68);
|
||||
}
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
/* Copyright (C) 2025 José Rebelo
|
||||
|
||||
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 <https://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.hplus;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||
|
||||
public class Q8Support extends HPlusSupport {
|
||||
public Q8Support() {
|
||||
super(DeviceType.Q8);
|
||||
}
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
/* Copyright (C) 2025 José Rebelo
|
||||
|
||||
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 <https://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.hplus;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||
|
||||
public class SG2Support extends HPlusSupport {
|
||||
public SG2Support() {
|
||||
super(DeviceType.SG2);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user