mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-27 02:55:50 +01:00
Xiaomi: WIP implementation for sending contacts
This is not useful yet because contacts just get added when sending them, instaed of replacing. Should be fixed or disabled before the release
This commit is contained in:
parent
6e5bedb365
commit
81e24e53ed
@ -367,6 +367,9 @@ public abstract class XiaomiCoordinator extends AbstractBLEDeviceCoordinator {
|
|||||||
// Other
|
// Other
|
||||||
//
|
//
|
||||||
settings.add(R.xml.devicesettings_header_other);
|
settings.add(R.xml.devicesettings_header_other);
|
||||||
|
if (getContactsSlotCount(device) > 0) {
|
||||||
|
settings.add(R.xml.devicesettings_contacts);
|
||||||
|
}
|
||||||
settings.add(R.xml.devicesettings_camera_remote);
|
settings.add(R.xml.devicesettings_camera_remote);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -27,6 +27,7 @@ import nodomain.freeyourgadget.gadgetbridge.R;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
|
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.xiaomi.XiaomiEncryptedCoordinator;
|
import nodomain.freeyourgadget.gadgetbridge.devices.xiaomi.XiaomiEncryptedCoordinator;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.xiaomi.XiaomiInstallHandler;
|
import nodomain.freeyourgadget.gadgetbridge.devices.xiaomi.XiaomiInstallHandler;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
|
|
||||||
public class RedmiWatch3ActiveCoordinator extends XiaomiEncryptedCoordinator {
|
public class RedmiWatch3ActiveCoordinator extends XiaomiEncryptedCoordinator {
|
||||||
@Override
|
@Override
|
||||||
@ -65,4 +66,9 @@ public class RedmiWatch3ActiveCoordinator extends XiaomiEncryptedCoordinator {
|
|||||||
public boolean supportsMultipleWeatherLocations() {
|
public boolean supportsMultipleWeatherLocations() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getContactsSlotCount(final GBDevice device) {
|
||||||
|
return 10; // TODO:verify
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2023 José Rebelo
|
/* Copyright (C) 2023 José Rebelo, Andreas Shimokawa
|
||||||
|
|
||||||
This file is part of Gadgetbridge.
|
This file is part of Gadgetbridge.
|
||||||
|
|
||||||
@ -30,6 +30,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -41,6 +42,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.Contact;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||||
@ -408,6 +410,11 @@ public abstract class XiaomiSupport extends AbstractBTLEDeviceSupport {
|
|||||||
weatherService.onSendWeather(weatherSpec);
|
weatherService.onSendWeather(weatherSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSetContacts(ArrayList<? extends Contact> contacts) {
|
||||||
|
phonebookService.setContacts((List<Contact>) contacts);
|
||||||
|
}
|
||||||
|
|
||||||
public XiaomiCoordinator getCoordinator() {
|
public XiaomiCoordinator getCoordinator() {
|
||||||
return (XiaomiCoordinator) gbDevice.getDeviceCoordinator();
|
return (XiaomiCoordinator) gbDevice.getDeviceCoordinator();
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2023 Yoran Vulker
|
/* Copyright (C) 2023 Yoran Vulker, Andreas Shimokawa
|
||||||
|
|
||||||
This file is part of Gadgetbridge.
|
This file is part of Gadgetbridge.
|
||||||
|
|
||||||
@ -25,10 +25,15 @@ import android.text.TextUtils;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.Contact;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.proto.xiaomi.XiaomiProto;
|
import nodomain.freeyourgadget.gadgetbridge.proto.xiaomi.XiaomiProto;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiSupport;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
||||||
|
|
||||||
public class XiaomiPhonebookService extends AbstractXiaomiService {
|
public class XiaomiPhonebookService extends AbstractXiaomiService {
|
||||||
|
|
||||||
@ -37,6 +42,7 @@ public class XiaomiPhonebookService extends AbstractXiaomiService {
|
|||||||
|
|
||||||
private static final int CMD_GET_CONTACT = 2;
|
private static final int CMD_GET_CONTACT = 2;
|
||||||
private static final int CMD_GET_CONTACT_RESPONSE = 3;
|
private static final int CMD_GET_CONTACT_RESPONSE = 3;
|
||||||
|
private static final int CMD_SET_CONTACT_LIST = 5;
|
||||||
|
|
||||||
public XiaomiPhonebookService(final XiaomiSupport support) {
|
public XiaomiPhonebookService(final XiaomiSupport support) {
|
||||||
super(support);
|
super(support);
|
||||||
@ -133,4 +139,26 @@ public class XiaomiPhonebookService extends AbstractXiaomiService {
|
|||||||
contactInfoBuilder.setDisplayName(name);
|
contactInfoBuilder.setDisplayName(name);
|
||||||
return contactInfoBuilder.build();
|
return contactInfoBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setContacts(List<Contact> contacts) {
|
||||||
|
final XiaomiProto.ContactList.Builder contactList = XiaomiProto.ContactList.newBuilder();
|
||||||
|
int maxContacts = 10; // TODO:verify, do not copy and paste
|
||||||
|
int numContacts = Math.min(contacts.size(), maxContacts);
|
||||||
|
|
||||||
|
for (int i = 0; i < numContacts; i++) {
|
||||||
|
final Contact contact = contacts.get(i);
|
||||||
|
if (!StringUtils.isNullOrEmpty(contact.getName()) && !StringUtils.isNullOrEmpty(contact.getNumber())) {
|
||||||
|
contactList.addContactInfo(XiaomiProto.ContactInfo.newBuilder().setDisplayName(contact.getName()).setPhoneNumber(contact.getNumber()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getSupport().sendCommand(
|
||||||
|
"send contact list",
|
||||||
|
XiaomiProto.Command.newBuilder()
|
||||||
|
.setType(COMMAND_TYPE)
|
||||||
|
.setSubtype(CMD_SET_CONTACT_LIST)
|
||||||
|
.setPhonebook(XiaomiProto.Phonebook.newBuilder().setContactList(contactList))
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -882,7 +882,13 @@ message ContactInfo {
|
|||||||
optional string phoneNumber = 2;
|
optional string phoneNumber = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message ContactList {
|
||||||
|
repeated ContactInfo contactInfo = 1;
|
||||||
|
optional string phoneNumber = 2;
|
||||||
|
}
|
||||||
|
|
||||||
message Phonebook {
|
message Phonebook {
|
||||||
optional string requestedPhoneNumber = 2;
|
optional string requestedPhoneNumber = 2;
|
||||||
optional ContactInfo contactInfo = 3;
|
optional ContactInfo contactInfo = 3;
|
||||||
|
optional ContactList contactList = 4;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user