2020-01-09 10:44:32 +01:00
|
|
|
/* Copyright (C) 2015-2020 Andreas Shimokawa, Carsten Pfeiffer, Daniele
|
2018-08-29 21:30:23 +02:00
|
|
|
Gobbetti, José Rebelo, Lem Dulfo, maxirnilian
|
2017-03-16 17:36:15 +01:00
|
|
|
|
|
|
|
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/>. */
|
2016-10-21 13:01:30 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.adapter;
|
|
|
|
|
2016-10-24 17:41:56 +02:00
|
|
|
import android.app.Activity;
|
2016-10-25 17:49:21 +02:00
|
|
|
import android.app.AlertDialog;
|
2016-10-21 13:01:30 +02:00
|
|
|
import android.content.Context;
|
2016-10-24 17:41:56 +02:00
|
|
|
import android.content.DialogInterface;
|
2016-10-21 13:01:30 +02:00
|
|
|
import android.content.Intent;
|
2021-11-18 21:19:03 +01:00
|
|
|
import android.content.SharedPreferences;
|
2022-06-23 23:12:08 +02:00
|
|
|
import android.content.res.Resources;
|
2021-11-20 15:56:12 +01:00
|
|
|
import android.graphics.Color;
|
2018-07-28 17:23:58 +02:00
|
|
|
import android.graphics.drawable.GradientDrawable;
|
2022-06-26 18:12:13 +02:00
|
|
|
import android.text.Editable;
|
2018-07-28 17:23:58 +02:00
|
|
|
import android.text.InputType;
|
2021-12-18 23:45:49 +01:00
|
|
|
import android.text.TextUtils;
|
2022-06-26 18:12:13 +02:00
|
|
|
import android.text.TextWatcher;
|
2022-06-23 23:12:08 +02:00
|
|
|
import android.util.ArraySet;
|
2021-12-04 20:33:30 +01:00
|
|
|
import android.util.Pair;
|
2022-06-23 23:12:08 +02:00
|
|
|
import android.util.TypedValue;
|
2016-10-21 13:01:30 +02:00
|
|
|
import android.view.LayoutInflater;
|
2022-06-23 23:12:08 +02:00
|
|
|
import android.view.MenuItem;
|
2016-10-21 13:01:30 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2022-06-26 18:12:13 +02:00
|
|
|
import android.widget.AdapterView;
|
2016-10-21 13:01:30 +02:00
|
|
|
import android.widget.ArrayAdapter;
|
2021-11-18 21:19:03 +01:00
|
|
|
import android.widget.Button;
|
2018-07-28 17:23:58 +02:00
|
|
|
import android.widget.EditText;
|
2020-08-24 13:50:10 +02:00
|
|
|
import android.widget.FrameLayout;
|
2016-10-21 13:01:30 +02:00
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.ListView;
|
2021-11-18 21:19:03 +01:00
|
|
|
import android.widget.NumberPicker;
|
2022-06-23 23:12:08 +02:00
|
|
|
import android.widget.PopupMenu;
|
2016-10-21 13:01:30 +02:00
|
|
|
import android.widget.ProgressBar;
|
|
|
|
import android.widget.RelativeLayout;
|
2022-06-26 18:12:13 +02:00
|
|
|
import android.widget.Spinner;
|
2016-10-21 13:01:30 +02:00
|
|
|
import android.widget.TextView;
|
2016-10-25 17:49:21 +02:00
|
|
|
import android.widget.Toast;
|
2016-10-21 13:01:30 +02:00
|
|
|
|
2020-05-24 23:25:52 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.cardview.widget.CardView;
|
2022-06-23 23:12:08 +02:00
|
|
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
2020-05-24 23:25:52 +02:00
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
2022-06-28 21:31:58 +02:00
|
|
|
import androidx.recyclerview.widget.DiffUtil;
|
|
|
|
import androidx.recyclerview.widget.ListAdapter;
|
2020-05-24 23:25:52 +02:00
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
2021-11-20 15:56:12 +01:00
|
|
|
import com.github.mikephil.charting.charts.PieChart;
|
|
|
|
import com.github.mikephil.charting.data.PieData;
|
|
|
|
import com.github.mikephil.charting.data.PieDataSet;
|
|
|
|
import com.github.mikephil.charting.data.PieEntry;
|
|
|
|
import com.github.mikephil.charting.utils.MPPointF;
|
2022-06-23 23:12:08 +02:00
|
|
|
import com.google.android.flexbox.FlexboxLayout;
|
2019-01-26 15:52:40 +01:00
|
|
|
import com.google.android.material.snackbar.Snackbar;
|
2018-07-28 17:23:58 +02:00
|
|
|
import com.jaredrummler.android.colorpicker.ColorPickerDialog;
|
|
|
|
import com.jaredrummler.android.colorpicker.ColorPickerDialogListener;
|
|
|
|
|
2022-06-28 21:31:58 +02:00
|
|
|
import org.apache.commons.lang3.builder.EqualsBuilder;
|
2020-08-02 10:55:06 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2021-11-20 15:56:12 +01:00
|
|
|
import java.util.ArrayList;
|
2021-11-18 12:22:43 +01:00
|
|
|
import java.util.HashMap;
|
2021-12-04 20:33:30 +01:00
|
|
|
import java.util.Hashtable;
|
2016-10-21 13:01:30 +02:00
|
|
|
import java.util.List;
|
2018-07-28 17:23:58 +02:00
|
|
|
import java.util.Locale;
|
2021-12-04 20:33:30 +01:00
|
|
|
import java.util.Map;
|
2022-06-23 23:12:08 +02:00
|
|
|
import java.util.Set;
|
2021-11-18 12:22:43 +01:00
|
|
|
import java.util.concurrent.TimeUnit;
|
2016-10-21 13:01:30 +02:00
|
|
|
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
2017-10-19 21:52:38 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.ActivitySummariesActivity;
|
2021-01-31 11:10:03 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.BatteryInfoActivity;
|
2016-10-21 13:01:30 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.ConfigureAlarms;
|
2021-12-04 16:55:09 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.ConfigureReminders;
|
2021-08-08 11:11:05 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenterv2;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.HeartRateDialog;
|
2017-03-16 17:36:46 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.VibrationActivity;
|
2016-10-21 13:01:30 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity;
|
2019-04-21 21:18:08 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsActivity;
|
2021-11-18 12:22:43 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
|
2020-06-12 22:38:37 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
2016-10-21 13:01:30 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
2016-10-25 17:49:21 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
|
2020-06-12 22:38:37 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
2016-10-21 13:01:30 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
2022-06-23 23:12:08 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceFolder;
|
2021-08-08 11:11:05 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
2021-11-18 12:22:43 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
2016-10-21 13:01:30 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
2017-03-16 17:36:46 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
2018-03-31 16:21:25 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes;
|
2021-11-18 12:22:43 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
2016-10-21 13:01:30 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
2021-12-28 22:10:06 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.FormatUtils;
|
2016-10-25 17:49:21 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
2022-06-23 23:12:08 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
2016-10-21 13:01:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adapter for displaying GBDevice instances.
|
|
|
|
*/
|
2022-06-28 21:31:58 +02:00
|
|
|
public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.ViewHolder> {
|
2020-08-02 10:55:06 +02:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(GBDeviceAdapterv2.class);
|
2016-10-21 13:01:30 +02:00
|
|
|
|
|
|
|
private final Context context;
|
2016-10-24 17:41:56 +02:00
|
|
|
private List<GBDevice> deviceList;
|
2022-06-23 23:12:08 +02:00
|
|
|
private List<GBDevice> devicesListWithFolders;
|
2021-12-19 00:08:57 +01:00
|
|
|
private String expandedDeviceAddress = "";
|
2022-06-23 23:12:08 +02:00
|
|
|
private String expandedFolderName = "";
|
2016-10-24 17:41:56 +02:00
|
|
|
private ViewGroup parent;
|
2021-11-18 12:22:43 +01:00
|
|
|
private HashMap<String, long[]> deviceActivityMap = new HashMap();
|
2022-06-28 21:31:58 +02:00
|
|
|
private StableIdGenerator idGenerator = new StableIdGenerator();
|
2016-10-21 13:01:30 +02:00
|
|
|
|
2021-11-18 12:22:43 +01:00
|
|
|
public GBDeviceAdapterv2(Context context, List<GBDevice> deviceList, HashMap<String,long[]> deviceMap) {
|
2022-06-28 21:31:58 +02:00
|
|
|
super(new GBDeviceDiffUtil());
|
2016-10-21 13:01:30 +02:00
|
|
|
this.context = context;
|
2016-10-24 17:41:56 +02:00
|
|
|
this.deviceList = deviceList;
|
2022-06-23 23:12:08 +02:00
|
|
|
rebuildFolders();
|
2021-11-18 12:22:43 +01:00
|
|
|
this.deviceActivityMap = deviceMap;
|
2016-10-21 13:01:30 +02:00
|
|
|
}
|
|
|
|
|
2022-06-23 23:12:08 +02:00
|
|
|
public void rebuildFolders(){
|
|
|
|
this.devicesListWithFolders = enrichDeviceListWithFolder(deviceList);
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<GBDevice> enrichDeviceListWithFolder(List<GBDevice> deviceList) {
|
|
|
|
ArrayList<GBDevice> enrichedList = new ArrayList<>();
|
|
|
|
Set<String> folders = new ArraySet<>();
|
|
|
|
for(GBDevice device : deviceList){
|
|
|
|
String parentFolder = device.getParentFolder();
|
|
|
|
if(StringUtils.isNullOrEmpty(parentFolder)){
|
|
|
|
enrichedList.add(device);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
folders.add(parentFolder);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(String folder : folders){
|
|
|
|
enrichedList.add(new GBDeviceFolder(folder));
|
|
|
|
for(GBDevice potentialChild : deviceList){
|
|
|
|
String parentFolder = potentialChild.getParentFolder();
|
|
|
|
if(StringUtils.isNullOrEmpty(parentFolder)){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(!parentFolder.equals(folder)){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
enrichedList.add(potentialChild);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return enrichedList;
|
|
|
|
}
|
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
@NonNull
|
2016-10-21 13:01:30 +02:00
|
|
|
@Override
|
2018-03-31 16:21:25 +02:00
|
|
|
public GBDeviceAdapterv2.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
2016-10-24 17:41:56 +02:00
|
|
|
this.parent = parent;
|
|
|
|
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.device_itemv2, parent, false);
|
2018-03-31 16:21:25 +02:00
|
|
|
return new ViewHolder(view);
|
2016-10-24 17:41:56 +02:00
|
|
|
}
|
2016-10-21 13:01:30 +02:00
|
|
|
|
2022-06-23 23:12:08 +02:00
|
|
|
private int countDevicesInFolder(String folderName, boolean needsToBeConnected){
|
|
|
|
int count = 0;
|
|
|
|
for(GBDevice device : deviceList){
|
|
|
|
if(folderName.equals(device.getParentFolder()) && ((!needsToBeConnected) || device.isConnected())){
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showDeviceFolder(ViewHolder holder, final GBDeviceFolder folder){
|
|
|
|
holder.container.setVisibility(View.VISIBLE);
|
|
|
|
holder.deviceNameLabel.setText(folder.getName());
|
|
|
|
holder.infoIcons.setVisibility(View.GONE);
|
2022-06-27 14:42:02 +02:00
|
|
|
holder.deviceInfoBox.setVisibility(View.GONE);
|
2022-06-23 23:12:08 +02:00
|
|
|
holder.cardViewActivityCardLayout.setVisibility(View.GONE);
|
|
|
|
if(countDevicesInFolder(folder.getName(), true) == 0){
|
|
|
|
holder.deviceImageView.setImageResource(R.drawable.ic_device_folder_disabled);
|
|
|
|
}else{
|
|
|
|
|
|
|
|
holder.deviceImageView.setImageResource(R.drawable.ic_device_folder);
|
|
|
|
}
|
|
|
|
holder.deviceInfoView.setVisibility(View.GONE);
|
|
|
|
int countInFolder = countDevicesInFolder(folder.getName(), false);
|
|
|
|
int connectedInFolder = countDevicesInFolder(folder.getName(), true);
|
|
|
|
holder.deviceStatusLabel.setText(context.getString(R.string.controlcenter_connected_fraction, connectedInFolder, countInFolder));
|
|
|
|
|
|
|
|
holder.container.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if(expandedFolderName.equals(folder.getName())){
|
|
|
|
// collapse open folder
|
|
|
|
expandedFolderName = "";
|
|
|
|
}else {
|
|
|
|
expandedFolderName = folder.getName();
|
|
|
|
}
|
|
|
|
notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
holder.container.setOnLongClickListener(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setItemMargin(ViewHolder holder, GBDevice device){
|
|
|
|
Resources r = context.getResources();
|
|
|
|
int widthDp = 8;
|
|
|
|
if(!StringUtils.isNullOrEmpty(device.getParentFolder())){
|
|
|
|
widthDp = 16;
|
|
|
|
}
|
|
|
|
float px = TypedValue.applyDimension(
|
|
|
|
TypedValue.COMPLEX_UNIT_DIP,
|
|
|
|
widthDp,
|
|
|
|
r.getDisplayMetrics()
|
|
|
|
);
|
|
|
|
CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) holder.container.getLayoutParams();
|
|
|
|
layoutParams.setMarginStart((int) px);
|
|
|
|
holder.container.setLayoutParams(layoutParams);
|
|
|
|
|
|
|
|
int alpha = 0;
|
|
|
|
if(device instanceof GBDeviceFolder && device.getName().equals(expandedFolderName)){
|
|
|
|
alpha = 50;
|
|
|
|
}else if(!StringUtils.isNullOrEmpty(device.getParentFolder()) && expandedFolderName.equals(device.getParentFolder())){
|
|
|
|
alpha = 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
holder.root.setBackgroundColor(Color.argb(alpha, 0, 0, 0));
|
|
|
|
}
|
|
|
|
|
2016-10-24 17:41:56 +02:00
|
|
|
@Override
|
2018-03-31 16:21:25 +02:00
|
|
|
public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
|
2022-06-23 23:12:08 +02:00
|
|
|
final GBDevice device = devicesListWithFolders.get(position);
|
|
|
|
|
|
|
|
setItemMargin(holder, device);
|
|
|
|
|
|
|
|
if(device instanceof GBDeviceFolder){
|
|
|
|
showDeviceFolder(holder, (GBDeviceFolder) device);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
String parentFolder = device.getParentFolder();
|
|
|
|
if(!StringUtils.isNullOrEmpty(parentFolder)){
|
|
|
|
if(parentFolder.equals(expandedFolderName)){
|
|
|
|
holder.container.setVisibility(View.VISIBLE);
|
|
|
|
}else{
|
|
|
|
holder.container.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
holder.container.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
2021-11-18 12:22:43 +01:00
|
|
|
long[] dailyTotals = new long[]{0, 0};
|
|
|
|
if (deviceActivityMap.containsKey(device.getAddress())) {
|
|
|
|
dailyTotals = deviceActivityMap.get(device.getAddress());
|
|
|
|
}
|
|
|
|
|
2017-03-16 17:36:46 +01:00
|
|
|
final DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
2016-10-29 18:20:53 +02:00
|
|
|
holder.container.setOnClickListener(new View.OnClickListener() {
|
2016-10-21 13:01:30 +02:00
|
|
|
|
2016-10-24 17:41:56 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2021-12-24 15:20:57 +01:00
|
|
|
|
2016-10-29 18:20:53 +02:00
|
|
|
if (device.isInitialized() || device.isConnected()) {
|
|
|
|
showTransientSnackbar(R.string.controlcenter_snackbar_need_longpress);
|
|
|
|
} else {
|
|
|
|
showTransientSnackbar(R.string.controlcenter_snackbar_connecting);
|
|
|
|
GBApplication.deviceService().connect(device);
|
|
|
|
}
|
2016-10-24 17:41:56 +02:00
|
|
|
}
|
|
|
|
});
|
2016-10-21 17:44:36 +02:00
|
|
|
|
2016-10-29 18:20:53 +02:00
|
|
|
holder.container.setOnLongClickListener(new View.OnLongClickListener() {
|
2016-10-21 17:44:36 +02:00
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
2022-06-23 23:12:08 +02:00
|
|
|
showDeviceSubmenu(v, device);
|
2016-10-21 17:44:36 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2018-07-30 22:48:11 +02:00
|
|
|
holder.deviceImageView.setImageResource(device.isInitialized() ? device.getType().getIcon() : device.getType().getDisabledIcon());
|
2016-10-21 13:01:30 +02:00
|
|
|
|
2016-10-24 17:41:56 +02:00
|
|
|
holder.deviceNameLabel.setText(getUniqueDeviceName(device));
|
2016-10-21 13:01:30 +02:00
|
|
|
|
|
|
|
if (device.isBusy()) {
|
2016-10-24 17:41:56 +02:00
|
|
|
holder.deviceStatusLabel.setText(device.getBusyTask());
|
|
|
|
holder.busyIndicator.setVisibility(View.VISIBLE);
|
2016-10-21 13:01:30 +02:00
|
|
|
} else {
|
2016-10-24 17:41:56 +02:00
|
|
|
holder.deviceStatusLabel.setText(device.getStateString());
|
|
|
|
holder.busyIndicator.setVisibility(View.INVISIBLE);
|
2016-10-21 13:01:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//begin of action row
|
|
|
|
//battery
|
2021-10-16 22:40:30 +02:00
|
|
|
// multiple battery support: at this point we support up to three batteries
|
|
|
|
// to support more batteries, the battery UI would need to be extended
|
|
|
|
|
|
|
|
holder.batteryStatusBox0.setVisibility(coordinator.getBatteryCount() > 0 ? View.VISIBLE : View.GONE);
|
|
|
|
holder.batteryStatusBox1.setVisibility(coordinator.getBatteryCount() > 1 ? View.VISIBLE : View.GONE);
|
|
|
|
holder.batteryStatusBox2.setVisibility(coordinator.getBatteryCount() > 2 ? View.VISIBLE : View.GONE);
|
|
|
|
|
|
|
|
LinearLayout[] batteryStatusBoxes = {holder.batteryStatusBox0, holder.batteryStatusBox1, holder.batteryStatusBox2};
|
|
|
|
TextView[] batteryStatusLabels = {holder.batteryStatusLabel0, holder.batteryStatusLabel1, holder.batteryStatusLabel2};
|
|
|
|
ImageView[] batteryIcons = {holder.batteryIcon0, holder.batteryIcon1, holder.batteryIcon2};
|
|
|
|
|
2021-10-31 17:36:04 +01:00
|
|
|
for (int batteryIndex = 0; batteryIndex < coordinator.getBatteryCount(); batteryIndex++) {
|
|
|
|
|
|
|
|
int batteryLevel = device.getBatteryLevel(batteryIndex);
|
|
|
|
float batteryVoltage = device.getBatteryVoltage(batteryIndex);
|
|
|
|
BatteryState batteryState = device.getBatteryState(batteryIndex);
|
|
|
|
int batteryIcon = device.getBatteryIcon(batteryIndex);
|
2021-11-02 18:16:41 +01:00
|
|
|
int batteryLabel = device.getBatteryLabel(batteryIndex); //unused for now
|
|
|
|
batteryIcons[batteryIndex].setImageResource(R.drawable.level_list_battery);
|
2021-10-31 17:36:04 +01:00
|
|
|
|
|
|
|
if (batteryIcon != GBDevice.BATTERY_ICON_DEFAULT){
|
|
|
|
batteryIcons[batteryIndex].setImageResource(batteryIcon);
|
|
|
|
}
|
2021-10-16 22:40:30 +02:00
|
|
|
|
|
|
|
if (batteryLevel != GBDevice.BATTERY_UNKNOWN) {
|
2021-10-31 17:36:04 +01:00
|
|
|
batteryStatusLabels[batteryIndex].setText(device.getBatteryLevel(batteryIndex) + "%");
|
2021-10-16 22:40:30 +02:00
|
|
|
if (BatteryState.BATTERY_CHARGING.equals(batteryState) ||
|
|
|
|
BatteryState.BATTERY_CHARGING_FULL.equals(batteryState)) {
|
2021-10-31 17:36:04 +01:00
|
|
|
batteryIcons[batteryIndex].setImageLevel(device.getBatteryLevel(batteryIndex) + 100);
|
2021-10-16 22:40:30 +02:00
|
|
|
} else {
|
2021-10-31 17:36:04 +01:00
|
|
|
batteryIcons[batteryIndex].setImageLevel(device.getBatteryLevel(batteryIndex));
|
2021-10-16 22:40:30 +02:00
|
|
|
}
|
|
|
|
} else if (BatteryState.NO_BATTERY.equals(batteryState) && batteryVoltage != GBDevice.BATTERY_UNKNOWN) {
|
2021-10-31 17:36:04 +01:00
|
|
|
batteryStatusLabels[batteryIndex].setText(String.format(Locale.getDefault(), "%.2f", batteryVoltage));
|
|
|
|
batteryIcons[batteryIndex].setImageLevel(200);
|
2021-11-05 18:33:33 +01:00
|
|
|
} else {
|
|
|
|
//should be the "default" status, shown when the device is not connected
|
|
|
|
batteryStatusLabels[batteryIndex].setText("");
|
|
|
|
batteryIcons[batteryIndex].setImageLevel(50);
|
2016-10-21 13:01:30 +02:00
|
|
|
}
|
2021-10-31 17:36:04 +01:00
|
|
|
final int finalBatteryIndex = batteryIndex;
|
|
|
|
batteryStatusBoxes[batteryIndex].setOnClickListener(new View.OnClickListener() {
|
2021-10-16 22:40:30 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent startIntent;
|
|
|
|
startIntent = new Intent(context, BatteryInfoActivity.class);
|
|
|
|
startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
|
2021-10-31 17:36:04 +01:00
|
|
|
startIntent.putExtra(GBDevice.BATTERY_INDEX, finalBatteryIndex);
|
2021-10-16 22:40:30 +02:00
|
|
|
context.startActivity(startIntent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2021-01-31 11:10:03 +01:00
|
|
|
|
2021-12-18 23:45:49 +01:00
|
|
|
// Hide the battery status level, if it has no text
|
|
|
|
if (TextUtils.isEmpty(batteryStatusLabels[batteryIndex].getText())) {
|
|
|
|
batteryStatusLabels[batteryIndex].setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
batteryStatusLabels[batteryIndex].setVisibility(View.VISIBLE);
|
|
|
|
}
|
2021-10-16 22:40:30 +02:00
|
|
|
}
|
2021-08-09 17:43:46 +02:00
|
|
|
holder.heartRateStatusBox.setVisibility((device.isInitialized() && coordinator.supportsRealtimeData() && coordinator.supportsHeartRateMeasurement(device)) ? View.VISIBLE : View.GONE);
|
2021-08-08 11:11:05 +02:00
|
|
|
if (parent.getContext() instanceof ControlCenterv2) {
|
|
|
|
ActivitySample sample = ((ControlCenterv2) parent.getContext()).getCurrentHRSample();
|
|
|
|
if (sample != null) {
|
|
|
|
holder.heartRateStatusLabel.setText(String.valueOf(sample.getHeartRate()));
|
|
|
|
} else {
|
|
|
|
holder.heartRateStatusLabel.setText("");
|
|
|
|
}
|
2021-12-19 00:21:47 +01:00
|
|
|
|
|
|
|
// Hide the level, if it has no text
|
|
|
|
if (TextUtils.isEmpty(holder.heartRateStatusLabel.getText())) {
|
|
|
|
holder.heartRateStatusLabel.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
holder.heartRateStatusLabel.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2021-08-08 11:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
holder.heartRateStatusBox.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
GBApplication.deviceService().onHeartRateTest();
|
|
|
|
HeartRateDialog dialog = new HeartRateDialog(context);
|
|
|
|
dialog.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2016-10-21 13:01:30 +02:00
|
|
|
|
2019-04-21 15:59:39 +02:00
|
|
|
//device specific settings
|
2022-06-14 18:05:41 +02:00
|
|
|
holder.deviceSpecificSettingsView.setVisibility(coordinator.getSupportedDeviceSpecificConnectionSettings() != null ? View.VISIBLE : View.GONE);
|
2019-04-21 21:18:08 +02:00
|
|
|
holder.deviceSpecificSettingsView.setOnClickListener(new View.OnClickListener()
|
|
|
|
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent startIntent;
|
|
|
|
startIntent = new Intent(context, DeviceSettingsActivity.class);
|
|
|
|
startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
|
|
|
|
context.startActivity(startIntent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2019-04-21 15:59:39 +02:00
|
|
|
|
2016-10-21 13:01:30 +02:00
|
|
|
//fetch activity data
|
2016-10-24 17:41:56 +02:00
|
|
|
holder.fetchActivityDataBox.setVisibility((device.isInitialized() && coordinator.supportsActivityDataFetching()) ? View.VISIBLE : View.GONE);
|
|
|
|
holder.fetchActivityData.setOnClickListener(new View.OnClickListener()
|
|
|
|
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2016-10-29 18:20:53 +02:00
|
|
|
showTransientSnackbar(R.string.busy_task_fetch_activity_data);
|
2018-03-31 16:21:25 +02:00
|
|
|
GBApplication.deviceService().onFetchRecordedData(RecordedDataTypes.TYPE_ACTIVITY);
|
2016-10-24 17:41:56 +02:00
|
|
|
}
|
|
|
|
}
|
2016-10-21 13:01:30 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
//take screenshot
|
2016-10-24 17:41:56 +02:00
|
|
|
holder.takeScreenshotView.setVisibility((device.isInitialized() && coordinator.supportsScreenshots()) ? View.VISIBLE : View.GONE);
|
|
|
|
holder.takeScreenshotView.setOnClickListener(new View.OnClickListener()
|
|
|
|
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2016-10-29 18:20:53 +02:00
|
|
|
showTransientSnackbar(R.string.controlcenter_snackbar_requested_screenshot);
|
2016-10-24 17:41:56 +02:00
|
|
|
GBApplication.deviceService().onScreenshotReq();
|
|
|
|
}
|
|
|
|
}
|
2016-10-21 13:01:30 +02:00
|
|
|
);
|
|
|
|
|
2016-10-25 17:49:21 +02:00
|
|
|
//manage apps
|
|
|
|
holder.manageAppsView.setVisibility((device.isInitialized() && coordinator.supportsAppsManagement()) ? View.VISIBLE : View.GONE);
|
|
|
|
holder.manageAppsView.setOnClickListener(new View.OnClickListener()
|
|
|
|
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
|
|
|
Class<? extends Activity> appsManagementActivity = coordinator.getAppsManagementActivity();
|
|
|
|
if (appsManagementActivity != null) {
|
|
|
|
Intent startIntent = new Intent(context, appsManagementActivity);
|
|
|
|
startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
|
|
|
|
context.startActivity(startIntent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2016-10-21 13:01:30 +02:00
|
|
|
//set alarms
|
2019-01-11 23:26:00 +01:00
|
|
|
holder.setAlarmsView.setVisibility(coordinator.getAlarmSlotCount() > 0 ? View.VISIBLE : View.GONE);
|
2016-10-24 17:41:56 +02:00
|
|
|
holder.setAlarmsView.setOnClickListener(new View.OnClickListener()
|
|
|
|
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent startIntent;
|
|
|
|
startIntent = new Intent(context, ConfigureAlarms.class);
|
2017-08-22 01:01:35 +02:00
|
|
|
startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
|
2016-10-24 17:41:56 +02:00
|
|
|
context.startActivity(startIntent);
|
|
|
|
}
|
|
|
|
}
|
2016-10-21 13:01:30 +02:00
|
|
|
);
|
|
|
|
|
2021-12-04 16:55:09 +01:00
|
|
|
//set reminders
|
|
|
|
holder.setRemindersView.setVisibility(coordinator.getReminderSlotCount() > 0 ? View.VISIBLE : View.GONE);
|
|
|
|
holder.setRemindersView.setOnClickListener(new View.OnClickListener()
|
|
|
|
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent startIntent;
|
|
|
|
startIntent = new Intent(context, ConfigureReminders.class);
|
|
|
|
startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
|
|
|
|
context.startActivity(startIntent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2016-10-21 13:01:30 +02:00
|
|
|
//show graphs
|
2016-10-24 17:41:56 +02:00
|
|
|
holder.showActivityGraphs.setVisibility(coordinator.supportsActivityTracking() ? View.VISIBLE : View.GONE);
|
|
|
|
holder.showActivityGraphs.setOnClickListener(new View.OnClickListener()
|
|
|
|
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent startIntent;
|
|
|
|
startIntent = new Intent(context, ChartsActivity.class);
|
|
|
|
startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
|
|
|
|
context.startActivity(startIntent);
|
|
|
|
}
|
|
|
|
}
|
2016-10-21 13:01:30 +02:00
|
|
|
);
|
|
|
|
|
2017-10-19 21:52:38 +02:00
|
|
|
//show activity tracks
|
|
|
|
holder.showActivityTracks.setVisibility(coordinator.supportsActivityTracks() ? View.VISIBLE : View.GONE);
|
|
|
|
holder.showActivityTracks.setOnClickListener(new View.OnClickListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent startIntent;
|
|
|
|
startIntent = new Intent(context, ActivitySummariesActivity.class);
|
|
|
|
startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
|
|
|
|
context.startActivity(startIntent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2016-10-21 13:01:30 +02:00
|
|
|
ItemWithDetailsAdapter infoAdapter = new ItemWithDetailsAdapter(context, device.getDeviceInfos());
|
|
|
|
infoAdapter.setHorizontalAlignment(true);
|
2016-10-24 17:41:56 +02:00
|
|
|
holder.deviceInfoList.setAdapter(infoAdapter);
|
|
|
|
justifyListViewHeightBasedOnChildren(holder.deviceInfoList);
|
|
|
|
holder.deviceInfoList.setFocusable(false);
|
2016-10-21 17:44:36 +02:00
|
|
|
|
2022-06-23 23:12:08 +02:00
|
|
|
holder.infoIcons.setVisibility(View.VISIBLE);
|
|
|
|
|
2021-12-19 00:08:57 +01:00
|
|
|
final boolean detailsShown = expandedDeviceAddress.equals(device.getAddress());
|
2016-10-21 13:01:30 +02:00
|
|
|
boolean showInfoIcon = device.hasDeviceInfos() && !device.isBusy();
|
2016-10-24 17:41:56 +02:00
|
|
|
holder.deviceInfoBox.setActivated(detailsShown);
|
|
|
|
holder.deviceInfoBox.setVisibility(detailsShown ? View.VISIBLE : View.GONE);
|
2022-06-23 23:12:08 +02:00
|
|
|
holder.deviceInfoView.setVisibility(View.VISIBLE);
|
2016-10-24 17:41:56 +02:00
|
|
|
holder.deviceInfoView.setOnClickListener(new View.OnClickListener() {
|
2022-06-23 23:12:08 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
showDeviceSubmenu(v, device);
|
|
|
|
}
|
|
|
|
});
|
2016-10-21 13:01:30 +02:00
|
|
|
|
2018-07-26 21:57:12 +02:00
|
|
|
holder.findDevice.setVisibility(device.isInitialized() && coordinator.supportsFindDevice() ? View.VISIBLE : View.GONE);
|
2020-11-01 14:41:58 +01:00
|
|
|
holder.findDevice.setOnClickListener(new View.OnClickListener() {
|
2016-10-24 17:41:56 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2020-11-01 14:41:58 +01:00
|
|
|
new AlertDialog.Builder(context)
|
|
|
|
.setCancelable(true)
|
|
|
|
.setTitle(context.getString(R.string.controlcenter_find_device))
|
|
|
|
.setMessage(context.getString(R.string.find_lost_device_message, device.getName()))
|
|
|
|
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
if (device.getType() == DeviceType.VIBRATISSIMO) {
|
|
|
|
Intent startIntent;
|
|
|
|
startIntent = new Intent(context, VibrationActivity.class);
|
|
|
|
startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
|
|
|
|
context.startActivity(startIntent);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GBApplication.deviceService().onFindDevice(true);
|
|
|
|
Snackbar.make(parent, R.string.control_center_find_lost_device, Snackbar.LENGTH_INDEFINITE).setAction(R.string.find_lost_device_you_found_it, new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
GBApplication.deviceService().onFindDevice(false);
|
|
|
|
}
|
|
|
|
}).setCallback(new Snackbar.Callback() {
|
|
|
|
@Override
|
|
|
|
public void onDismissed(Snackbar snackbar, int event) {
|
|
|
|
GBApplication.deviceService().onFindDevice(false);
|
|
|
|
super.onDismissed(snackbar, event);
|
|
|
|
}
|
|
|
|
}).show();
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.show();
|
|
|
|
// ProgressDialog.show(
|
2016-10-30 15:15:34 +01:00
|
|
|
// context,
|
|
|
|
// context.getString(R.string.control_center_find_lost_device),
|
|
|
|
// context.getString(R.string.control_center_cancel_to_stop_vibration),
|
|
|
|
// true, true,
|
|
|
|
// new DialogInterface.OnCancelListener() {
|
|
|
|
// @Override
|
|
|
|
// public void onCancel(DialogInterface dialog) {
|
|
|
|
// GBApplication.deviceService().onFindDevice(false);
|
|
|
|
// }
|
|
|
|
// });
|
2016-10-24 17:41:56 +02:00
|
|
|
}
|
|
|
|
}
|
2016-10-21 13:01:30 +02:00
|
|
|
);
|
|
|
|
|
2020-05-24 23:25:52 +02:00
|
|
|
holder.calibrateDevice.setVisibility(device.isInitialized() && (coordinator.getCalibrationActivity() != null) ? View.VISIBLE : View.GONE);
|
2018-08-05 18:52:44 +02:00
|
|
|
holder.calibrateDevice.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2020-05-24 23:25:52 +02:00
|
|
|
Intent startIntent = new Intent(context, coordinator.getCalibrationActivity());
|
2018-08-05 18:52:44 +02:00
|
|
|
startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
|
|
|
|
context.startActivity(startIntent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-07-28 17:23:58 +02:00
|
|
|
holder.fmFrequencyBox.setVisibility(View.GONE);
|
|
|
|
if (device.isInitialized() && device.getExtraInfo("fm_frequency") != null) {
|
|
|
|
holder.fmFrequencyBox.setVisibility(View.VISIBLE);
|
|
|
|
holder.fmFrequencyLabel.setText(String.format(Locale.getDefault(), "%.1f", (float) device.getExtraInfo("fm_frequency")));
|
|
|
|
}
|
|
|
|
final TextView fmFrequencyLabel = holder.fmFrequencyLabel;
|
2021-11-18 21:19:03 +01:00
|
|
|
final float FREQ_MIN = 87.5F;
|
|
|
|
final float FREQ_MAX = 108.0F;
|
|
|
|
final int FREQ_MIN_INT = (int) Math.floor(FREQ_MIN);
|
|
|
|
final int FREQ_MAX_INT = (int) Math.round(FREQ_MAX);
|
|
|
|
final AlertDialog alert[] = new AlertDialog[1];
|
|
|
|
|
2018-07-28 17:23:58 +02:00
|
|
|
holder.fmFrequencyBox.setOnClickListener(new View.OnClickListener() {
|
2021-11-18 21:19:03 +01:00
|
|
|
|
2018-07-28 17:23:58 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2021-11-18 21:19:03 +01:00
|
|
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
2021-12-25 17:04:59 +01:00
|
|
|
final LayoutInflater inflater = LayoutInflater.from(context);
|
|
|
|
final View frequency_picker_view = inflater.inflate(R.layout.dialog_frequency_picker, null);
|
2018-07-28 17:23:58 +02:00
|
|
|
builder.setTitle(R.string.preferences_fm_frequency);
|
2021-11-18 21:19:03 +01:00
|
|
|
final float[] fm_presets = new float[3];
|
|
|
|
|
|
|
|
fm_presets[0] = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getFloat("fm_preset0", 99);
|
|
|
|
fm_presets[1] = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getFloat("fm_preset1", 100);
|
|
|
|
fm_presets[2] = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getFloat("fm_preset2", 101);
|
|
|
|
|
|
|
|
final NumberPicker frequency_decimal_picker = frequency_picker_view.findViewById(R.id.frequency_dec);
|
|
|
|
frequency_decimal_picker.setMinValue(FREQ_MIN_INT);
|
|
|
|
frequency_decimal_picker.setMaxValue(FREQ_MAX_INT);
|
|
|
|
|
|
|
|
final NumberPicker frequency_fraction_picker = frequency_picker_view.findViewById(R.id.frequency_fraction);
|
|
|
|
frequency_fraction_picker.setMinValue(0);
|
|
|
|
frequency_fraction_picker.setMaxValue(9);
|
|
|
|
|
|
|
|
final NumberPicker.OnValueChangeListener picker_listener = new NumberPicker.OnValueChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onValueChange(NumberPicker numberPicker, int oldVal, int newVal) {
|
|
|
|
|
|
|
|
int decimal_value = numberPicker.getValue();
|
|
|
|
if (decimal_value == FREQ_MIN_INT) {
|
|
|
|
frequency_fraction_picker.setMinValue(5);
|
|
|
|
frequency_fraction_picker.setMaxValue(9);
|
|
|
|
} else if (decimal_value == FREQ_MAX_INT) {
|
|
|
|
frequency_fraction_picker.setMinValue(0);
|
|
|
|
frequency_fraction_picker.setMaxValue(0);
|
|
|
|
} else {
|
|
|
|
frequency_fraction_picker.setMinValue(0);
|
|
|
|
frequency_fraction_picker.setMaxValue(9);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
frequency_decimal_picker.setOnValueChangedListener(picker_listener);
|
|
|
|
|
|
|
|
final Button[] button_presets = new Button[]{
|
|
|
|
frequency_picker_view.findViewById(R.id.frequency_preset1),
|
|
|
|
frequency_picker_view.findViewById(R.id.frequency_preset2),
|
|
|
|
frequency_picker_view.findViewById(R.id.frequency_preset3)
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int i = 0; i < button_presets.length; i++) {
|
|
|
|
final int index = i;
|
|
|
|
button_presets[index].setText(String.valueOf(fm_presets[index]));
|
|
|
|
button_presets[index].setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2021-12-25 17:04:59 +01:00
|
|
|
final float frequency = fm_presets[index];
|
|
|
|
device.setExtraInfo("fm_frequency", fm_presets[index]);
|
2021-11-18 21:19:03 +01:00
|
|
|
fmFrequencyLabel.setText(String.format(Locale.getDefault(), "%.1f", (float) frequency));
|
|
|
|
GBApplication.deviceService().onSetFmFrequency(frequency);
|
|
|
|
alert[0].dismiss();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
button_presets[index].setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View view) {
|
2021-12-25 17:04:59 +01:00
|
|
|
final float frequency = (float) (frequency_decimal_picker.getValue() + (0.1 * frequency_fraction_picker.getValue()));
|
2021-11-18 21:19:03 +01:00
|
|
|
fm_presets[index] = frequency;
|
|
|
|
button_presets[index].setText(String.valueOf(frequency));
|
|
|
|
SharedPreferences.Editor editor = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).edit();
|
|
|
|
editor.putFloat((String.format("fm_preset%s", index)), frequency);
|
|
|
|
editor.apply();
|
|
|
|
editor.commit();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2018-07-28 17:23:58 +02:00
|
|
|
|
2021-12-25 17:04:59 +01:00
|
|
|
final float frequency = (float) device.getExtraInfo("fm_frequency");
|
|
|
|
final int decimal = (int) frequency;
|
|
|
|
final int fraction = Math.round((frequency - decimal) * 10);
|
2021-11-18 21:19:03 +01:00
|
|
|
frequency_decimal_picker.setValue(decimal);
|
|
|
|
picker_listener.onValueChange(frequency_decimal_picker, frequency_decimal_picker.getValue(), decimal);
|
|
|
|
frequency_fraction_picker.setValue(fraction);
|
2018-07-28 17:23:58 +02:00
|
|
|
|
2021-11-18 21:19:03 +01:00
|
|
|
builder.setView(frequency_picker_view);
|
2018-07-28 17:23:58 +02:00
|
|
|
|
|
|
|
builder.setPositiveButton(context.getResources().getString(android.R.string.ok),
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2021-11-18 21:19:03 +01:00
|
|
|
float frequency = (float) (frequency_decimal_picker.getValue() + (0.1 * frequency_fraction_picker.getValue()));
|
|
|
|
if (frequency < FREQ_MIN || frequency > FREQ_MAX) {
|
2018-07-28 17:23:58 +02:00
|
|
|
new AlertDialog.Builder(context)
|
|
|
|
.setTitle(R.string.pref_invalid_frequency_title)
|
|
|
|
.setMessage(R.string.pref_invalid_frequency_message)
|
|
|
|
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.show();
|
|
|
|
} else {
|
|
|
|
device.setExtraInfo("fm_frequency", frequency);
|
2021-12-25 17:04:59 +01:00
|
|
|
fmFrequencyLabel.setText(String.format(Locale.getDefault(), "%.1f", frequency));
|
2018-07-28 17:23:58 +02:00
|
|
|
GBApplication.deviceService().onSetFmFrequency(frequency);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(context.getResources().getString(R.string.Cancel), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
dialog.cancel();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-11-18 21:19:03 +01:00
|
|
|
alert[0] = builder.create();
|
|
|
|
alert[0].show();
|
2018-07-28 17:23:58 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
holder.ledColor.setVisibility(View.GONE);
|
|
|
|
if (device.isInitialized() && device.getExtraInfo("led_color") != null && coordinator.supportsLedColor()) {
|
|
|
|
holder.ledColor.setVisibility(View.VISIBLE);
|
|
|
|
final GradientDrawable ledColor = (GradientDrawable) holder.ledColor.getDrawable().mutate();
|
|
|
|
ledColor.setColor((int) device.getExtraInfo("led_color"));
|
|
|
|
holder.ledColor.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
ColorPickerDialog.Builder builder = ColorPickerDialog.newBuilder();
|
|
|
|
builder.setDialogTitle(R.string.preferences_led_color);
|
|
|
|
|
2018-09-28 16:50:11 +02:00
|
|
|
int[] presets = coordinator.getColorPresets();
|
|
|
|
|
2018-07-28 17:23:58 +02:00
|
|
|
builder.setColor((int) device.getExtraInfo("led_color"));
|
2018-09-28 16:50:11 +02:00
|
|
|
builder.setShowAlphaSlider(false);
|
|
|
|
builder.setShowColorShades(false);
|
2018-07-28 17:23:58 +02:00
|
|
|
if (coordinator.supportsRgbLedColor()) {
|
|
|
|
builder.setAllowCustom(true);
|
2018-09-28 16:50:11 +02:00
|
|
|
if (presets.length == 0) {
|
|
|
|
builder.setDialogType(ColorPickerDialog.TYPE_CUSTOM);
|
|
|
|
}
|
2018-07-28 17:23:58 +02:00
|
|
|
} else {
|
|
|
|
builder.setAllowCustom(false);
|
2018-09-28 16:50:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (presets.length > 0) {
|
2018-07-28 17:23:58 +02:00
|
|
|
builder.setAllowPresets(true);
|
2018-09-28 16:50:11 +02:00
|
|
|
builder.setPresets(presets);
|
2018-07-28 17:23:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ColorPickerDialog dialog = builder.create();
|
|
|
|
dialog.setColorPickerDialogListener(new ColorPickerDialogListener() {
|
|
|
|
@Override
|
|
|
|
public void onColorSelected(int dialogId, int color) {
|
|
|
|
ledColor.setColor(color);
|
|
|
|
device.setExtraInfo("led_color", color);
|
|
|
|
GBApplication.deviceService().onSetLedColor(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDialogDismissed(int dialogId) {
|
|
|
|
// Nothing to do
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialog.show(((Activity) context).getFragmentManager(), "color-picker-dialog");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-12-24 15:20:57 +01:00
|
|
|
holder.powerOff.setVisibility(View.GONE);
|
|
|
|
if (device.isInitialized() && coordinator.supportsPowerOff()) {
|
|
|
|
holder.powerOff.setVisibility(View.VISIBLE);
|
|
|
|
holder.powerOff.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
new AlertDialog.Builder(context)
|
|
|
|
.setTitle(R.string.controlcenter_power_off_confirm_title)
|
|
|
|
.setMessage(R.string.controlcenter_power_off_confirm_description)
|
|
|
|
.setIcon(R.drawable.ic_power_settings_new)
|
|
|
|
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
|
|
|
public void onClick(final DialogInterface dialog, final int whichButton) {
|
|
|
|
GBApplication.deviceService().onPowerOff();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(android.R.string.no, null)
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-06-23 23:12:08 +02:00
|
|
|
holder.cardViewActivityCardLayout.setVisibility(coordinator.supportsActivityTracking() ? View.VISIBLE : View.GONE);
|
|
|
|
holder.cardViewActivityCardLayout.setMinimumWidth(coordinator.supportsActivityTracking() ? View.VISIBLE : View.GONE);
|
|
|
|
|
|
|
|
if (coordinator.supportsActivityTracking()) {
|
|
|
|
setActivityCard(holder, device, dailyTotals);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showDeviceSubmenu(final View v, final GBDevice device) {
|
|
|
|
boolean deviceConnected = device.getState() != GBDevice.State.NOT_CONNECTED;
|
|
|
|
|
|
|
|
PopupMenu menu = new PopupMenu(v.getContext(), v);
|
|
|
|
menu.inflate(R.menu.activity_controlcenterv2_device_submenu);
|
|
|
|
|
|
|
|
final boolean detailsShown = expandedDeviceAddress.equals(device.getAddress());
|
|
|
|
boolean showInfoIcon = device.hasDeviceInfos() && !device.isBusy();
|
2016-10-21 17:44:36 +02:00
|
|
|
|
2022-06-23 23:12:08 +02:00
|
|
|
menu.getMenu().findItem(R.id.controlcenter_device_submenu_connect).setVisible(!deviceConnected);
|
|
|
|
menu.getMenu().findItem(R.id.controlcenter_device_submenu_disconnect).setVisible(deviceConnected);
|
|
|
|
menu.getMenu().findItem(R.id.controlcenter_device_submenu_show_details).setEnabled(showInfoIcon);
|
|
|
|
|
|
|
|
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
2016-10-24 17:41:56 +02:00
|
|
|
@Override
|
2022-06-23 23:12:08 +02:00
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
switch (item.getItemId()){
|
|
|
|
case R.id.controlcenter_device_submenu_connect:
|
|
|
|
if (device.getState() != GBDevice.State.CONNECTED) {
|
|
|
|
showTransientSnackbar(R.string.controlcenter_snackbar_connecting);
|
|
|
|
GBApplication.deviceService().connect(device);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case R.id.controlcenter_device_submenu_disconnect:
|
|
|
|
if (device.getState() != GBDevice.State.NOT_CONNECTED) {
|
|
|
|
showTransientSnackbar(R.string.controlcenter_snackbar_disconnecting);
|
|
|
|
GBApplication.deviceService().disconnect(device);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case R.id.controlcenter_device_submenu_set_alias:
|
|
|
|
showSetAliasDialog(device);
|
|
|
|
return true;
|
|
|
|
case R.id.controlcenter_device_submenu_remove:
|
|
|
|
showRemoveDeviceDialog(device);
|
|
|
|
return true;
|
|
|
|
case R.id.controlcenter_device_submenu_show_details:
|
2022-06-28 21:31:58 +02:00
|
|
|
final String previouslyExpandedDeviceAddress = expandedDeviceAddress;
|
2022-06-23 23:12:08 +02:00
|
|
|
expandedDeviceAddress = detailsShown ? "" : device.getAddress();
|
2022-06-28 21:31:58 +02:00
|
|
|
|
|
|
|
if (!previouslyExpandedDeviceAddress.isEmpty()) {
|
|
|
|
// Notify the previously expanded device for a change (collapsing it)
|
|
|
|
for (int i = 0; i < devicesListWithFolders.size(); i++) {
|
|
|
|
final GBDevice gbDevice = devicesListWithFolders.get(i);
|
|
|
|
if (gbDevice.getAddress().equals(previouslyExpandedDeviceAddress)) {
|
|
|
|
notifyItemChanged(devicesListWithFolders.indexOf(gbDevice));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the current one
|
|
|
|
notifyItemChanged(devicesListWithFolders.indexOf(device));
|
2022-06-23 23:12:08 +02:00
|
|
|
return true;
|
|
|
|
case R.id.controlcenter_device_submenu_set_parent_folder:
|
|
|
|
showSetParentFolderDialog(device);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2016-10-24 17:41:56 +02:00
|
|
|
}
|
|
|
|
});
|
2022-06-23 23:12:08 +02:00
|
|
|
menu.show();
|
|
|
|
}
|
2016-10-24 17:41:56 +02:00
|
|
|
|
2022-06-23 23:12:08 +02:00
|
|
|
private void showRemoveDeviceDialog(final GBDevice device) {
|
|
|
|
new AlertDialog.Builder(context)
|
|
|
|
.setCancelable(true)
|
|
|
|
.setTitle(context.getString(R.string.controlcenter_delete_device_name, device.getName()))
|
|
|
|
.setMessage(R.string.controlcenter_delete_device_dialogmessage)
|
|
|
|
.setPositiveButton(R.string.Delete, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
try {
|
|
|
|
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
|
|
|
if (coordinator != null) {
|
|
|
|
coordinator.deleteDevice(device);
|
2020-06-12 22:38:37 +02:00
|
|
|
}
|
2022-06-23 23:12:08 +02:00
|
|
|
DeviceHelper.getInstance().removeBond(device);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
GB.toast(context, context.getString(R.string.error_deleting_device, ex.getMessage()), Toast.LENGTH_LONG, GB.ERROR, ex);
|
|
|
|
} finally {
|
|
|
|
Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
|
|
|
|
LocalBroadcastManager.getInstance(context).sendBroadcast(refreshIntent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.show();
|
|
|
|
}
|
2021-11-18 12:22:43 +01:00
|
|
|
|
2022-06-23 23:12:08 +02:00
|
|
|
private void showSetParentFolderDialog(final GBDevice device) {
|
2022-06-26 18:12:13 +02:00
|
|
|
final String[] selectedFolder = new String[1];
|
|
|
|
|
|
|
|
final LinearLayout linearLayout = new LinearLayout(context);
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
|
|
|
|
final LinearLayout newFolderLayout = new LinearLayout(context);
|
|
|
|
newFolderLayout.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
newFolderLayout.setPadding(context.getResources().getDimensionPixelSize(R.dimen.dialog_margin),
|
|
|
|
0, context.getResources().getDimensionPixelSize(R.dimen.dialog_margin), 0);
|
|
|
|
|
|
|
|
final TextView newFolderLabel = new TextView(context);
|
|
|
|
newFolderLabel.setText(R.string.controlcenter_folder_name);
|
|
|
|
final EditText newFolderInput = new EditText(context);
|
|
|
|
newFolderInput.setInputType(InputType.TYPE_CLASS_TEXT);
|
|
|
|
|
|
|
|
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
|
|
|
ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
|
newFolderInput.setLayoutParams(params);
|
|
|
|
|
|
|
|
newFolderInput.addTextChangedListener(new TextWatcher() {
|
|
|
|
@Override
|
|
|
|
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void afterTextChanged(Editable editable) {
|
|
|
|
selectedFolder[0] = editable.toString();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
newFolderLayout.addView(newFolderLabel);
|
|
|
|
newFolderLayout.addView(newFolderInput);
|
|
|
|
|
|
|
|
final Spinner deviceListSpinner = new Spinner(context);
|
|
|
|
ArrayList<SpinnerWithIconItem> foldersList = new ArrayList<>();
|
|
|
|
for (GBDevice oneDevice : deviceList) {
|
|
|
|
String folder = oneDevice.getParentFolder();
|
|
|
|
if (StringUtils.isNullOrEmpty(folder)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (folderListContainsName(foldersList, folder)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
foldersList.add(new SpinnerWithIconItem(folder, 2L, R.drawable.ic_folder));
|
|
|
|
}
|
|
|
|
|
|
|
|
foldersList.add(new SpinnerWithIconItem(context.getString(R.string.controlcenter_add_new_folder), 0L, R.drawable.ic_create_new_folder));
|
|
|
|
if (foldersList.toArray().length > 1) {
|
|
|
|
foldersList.add(new SpinnerWithIconItem(context.getString(R.string.controlcenter_unset_folder), 1L, R.drawable.ic_folder_delete));
|
|
|
|
}
|
|
|
|
|
|
|
|
final SpinnerWithIconAdapter deviceListAdapter = new SpinnerWithIconAdapter((Activity) context,
|
|
|
|
R.layout.spinner_with_image_layout, R.id.spinner_item_text, foldersList);
|
|
|
|
deviceListSpinner.setAdapter(deviceListAdapter);
|
|
|
|
|
|
|
|
deviceListSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
|
|
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
|
|
|
|
SpinnerWithIconItem selectedItem = (SpinnerWithIconItem) parent.getItemAtPosition(pos);
|
|
|
|
int folderId = selectedItem.getId().intValue();
|
|
|
|
switch (folderId) {
|
|
|
|
case 0: //Add new folder from test input
|
|
|
|
newFolderLayout.setVisibility(View.VISIBLE);
|
|
|
|
selectedFolder[0] = newFolderInput.getText().toString();
|
|
|
|
break;
|
|
|
|
case 1: //Unset folder
|
|
|
|
newFolderLayout.setVisibility(View.GONE);
|
|
|
|
selectedFolder[0] = "";
|
|
|
|
break;
|
|
|
|
default: //Set folder from selection
|
|
|
|
newFolderLayout.setVisibility(View.GONE);
|
|
|
|
selectedFolder[0] = selectedItem.getText();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> arg0) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
linearLayout.addView(deviceListSpinner);
|
|
|
|
linearLayout.addView(newFolderLayout);
|
2022-06-23 23:12:08 +02:00
|
|
|
|
|
|
|
new AlertDialog.Builder(context)
|
|
|
|
.setCancelable(true)
|
2022-06-26 18:12:13 +02:00
|
|
|
.setTitle(R.string.controlcenter_set_folder_title)
|
|
|
|
.setView(linearLayout)
|
2022-06-23 23:12:08 +02:00
|
|
|
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2022-06-26 18:12:13 +02:00
|
|
|
|
2022-06-23 23:12:08 +02:00
|
|
|
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
|
|
|
DaoSession session = dbHandler.getDaoSession();
|
|
|
|
Device dbDevice = DBHelper.getDevice(device, session);
|
2022-06-26 18:12:13 +02:00
|
|
|
String parentFolder = selectedFolder[0];
|
2022-06-23 23:12:08 +02:00
|
|
|
dbDevice.setParentFolder(parentFolder);
|
|
|
|
dbDevice.update();
|
|
|
|
device.setParentFolder(parentFolder);
|
|
|
|
expandedFolderName = parentFolder;
|
|
|
|
} catch (Exception ex) {
|
|
|
|
GB.toast(context, context.getString(R.string.error_setting_parent_folder, ex.getMessage()), Toast.LENGTH_LONG, GB.ERROR, ex);
|
|
|
|
} finally {
|
|
|
|
Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
|
|
|
|
LocalBroadcastManager.getInstance(context).sendBroadcast(refreshIntent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.show();
|
|
|
|
}
|
2021-12-04 11:19:59 +01:00
|
|
|
|
2022-06-26 18:12:13 +02:00
|
|
|
private boolean folderListContainsName(ArrayList<SpinnerWithIconItem> list, String name){
|
|
|
|
for (SpinnerWithIconItem item: list) {
|
|
|
|
if (item.getText().equals(name)){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-06-23 23:12:08 +02:00
|
|
|
private void showSetAliasDialog(final GBDevice device) {
|
|
|
|
final EditText input = new EditText(context);
|
|
|
|
input.setInputType(InputType.TYPE_CLASS_TEXT);
|
|
|
|
input.setText(device.getAlias());
|
|
|
|
FrameLayout container = new FrameLayout(context);
|
|
|
|
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
|
params.leftMargin = context.getResources().getDimensionPixelSize(R.dimen.dialog_margin);
|
|
|
|
params.rightMargin = context.getResources().getDimensionPixelSize(R.dimen.dialog_margin);
|
|
|
|
input.setLayoutParams(params);
|
|
|
|
container.addView(input);
|
|
|
|
// Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
|
|
|
|
|
|
|
|
new AlertDialog.Builder(context)
|
|
|
|
.setView(container)
|
|
|
|
.setCancelable(true)
|
|
|
|
.setTitle(context.getString(R.string.controlcenter_set_alias))
|
|
|
|
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
|
|
|
DaoSession session = dbHandler.getDaoSession();
|
|
|
|
Device dbDevice = DBHelper.getDevice(device, session);
|
|
|
|
String alias = input.getText().toString();
|
|
|
|
dbDevice.setAlias(alias);
|
|
|
|
dbDevice.update();
|
|
|
|
device.setAlias(alias);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
GB.toast(context, context.getString(R.string.error_setting_alias) + ex.getMessage(), Toast.LENGTH_LONG, GB.ERROR, ex);
|
|
|
|
} finally {
|
|
|
|
Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
|
|
|
|
LocalBroadcastManager.getInstance(context).sendBroadcast(refreshIntent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.show();
|
2016-10-24 17:41:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
2022-06-23 23:12:08 +02:00
|
|
|
return devicesListWithFolders.size();
|
2016-10-24 17:41:56 +02:00
|
|
|
}
|
|
|
|
|
2022-06-28 21:31:58 +02:00
|
|
|
@Override
|
|
|
|
public long getItemId(int position) {
|
|
|
|
return idGenerator.getId(devicesListWithFolders.get(position));
|
|
|
|
}
|
|
|
|
|
2016-10-24 17:41:56 +02:00
|
|
|
static class ViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
|
2022-06-23 23:12:08 +02:00
|
|
|
View root;
|
2016-10-29 18:20:53 +02:00
|
|
|
CardView container;
|
|
|
|
|
2016-10-24 17:41:56 +02:00
|
|
|
ImageView deviceImageView;
|
|
|
|
TextView deviceNameLabel;
|
|
|
|
TextView deviceStatusLabel;
|
|
|
|
|
|
|
|
//actions
|
2021-10-16 22:40:30 +02:00
|
|
|
LinearLayout batteryStatusBox0;
|
|
|
|
TextView batteryStatusLabel0;
|
|
|
|
ImageView batteryIcon0;
|
|
|
|
LinearLayout batteryStatusBox1;
|
|
|
|
TextView batteryStatusLabel1;
|
|
|
|
ImageView batteryIcon1;
|
|
|
|
LinearLayout batteryStatusBox2;
|
|
|
|
TextView batteryStatusLabel2;
|
|
|
|
ImageView batteryIcon2;
|
2019-04-21 15:59:39 +02:00
|
|
|
ImageView deviceSpecificSettingsView;
|
2016-10-24 17:41:56 +02:00
|
|
|
LinearLayout fetchActivityDataBox;
|
|
|
|
ImageView fetchActivityData;
|
|
|
|
ProgressBar busyIndicator;
|
|
|
|
ImageView takeScreenshotView;
|
2016-10-25 17:49:21 +02:00
|
|
|
ImageView manageAppsView;
|
2016-10-24 17:41:56 +02:00
|
|
|
ImageView setAlarmsView;
|
2021-12-04 16:55:09 +01:00
|
|
|
ImageView setRemindersView;
|
2016-10-24 17:41:56 +02:00
|
|
|
ImageView showActivityGraphs;
|
2017-10-19 21:52:38 +02:00
|
|
|
ImageView showActivityTracks;
|
2018-08-05 18:52:44 +02:00
|
|
|
ImageView calibrateDevice;
|
2021-08-08 11:11:05 +02:00
|
|
|
LinearLayout heartRateStatusBox;
|
|
|
|
ImageView heartRateIcon;
|
|
|
|
TextView heartRateStatusLabel;
|
2022-06-23 23:12:08 +02:00
|
|
|
FlexboxLayout infoIcons;
|
2021-08-08 11:11:05 +02:00
|
|
|
|
2016-10-24 17:41:56 +02:00
|
|
|
|
|
|
|
ImageView deviceInfoView;
|
|
|
|
//overflow
|
|
|
|
final RelativeLayout deviceInfoBox;
|
|
|
|
ListView deviceInfoList;
|
|
|
|
ImageView findDevice;
|
2018-07-28 17:23:58 +02:00
|
|
|
LinearLayout fmFrequencyBox;
|
|
|
|
TextView fmFrequencyLabel;
|
|
|
|
ImageView ledColor;
|
2021-12-24 15:20:57 +01:00
|
|
|
ImageView powerOff;
|
2016-10-24 17:41:56 +02:00
|
|
|
|
2021-11-20 15:56:12 +01:00
|
|
|
//activity card
|
2021-11-18 12:22:43 +01:00
|
|
|
LinearLayout cardViewActivityCardLayout;
|
2021-11-20 15:56:12 +01:00
|
|
|
PieChart TotalStepsChart;
|
|
|
|
PieChart TotalDistanceChart;
|
|
|
|
PieChart SleepTimeChart;
|
2021-11-18 12:22:43 +01:00
|
|
|
|
2016-10-24 17:41:56 +02:00
|
|
|
ViewHolder(View view) {
|
|
|
|
super(view);
|
2021-11-18 12:22:43 +01:00
|
|
|
|
2022-06-23 23:12:08 +02:00
|
|
|
root = view;
|
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
container = view.findViewById(R.id.card_view);
|
2016-10-29 18:20:53 +02:00
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
deviceImageView = view.findViewById(R.id.device_image);
|
|
|
|
deviceNameLabel = view.findViewById(R.id.device_name);
|
|
|
|
deviceStatusLabel = view.findViewById(R.id.device_status);
|
2016-10-24 17:41:56 +02:00
|
|
|
|
|
|
|
//actions
|
2021-10-16 22:40:30 +02:00
|
|
|
batteryStatusBox0 = view.findViewById(R.id.device_battery_status_box);
|
|
|
|
batteryStatusLabel0 = view.findViewById(R.id.battery_status);
|
|
|
|
batteryIcon0 = view.findViewById(R.id.device_battery_status);
|
|
|
|
batteryStatusBox1 = view.findViewById(R.id.device_battery_status_box1);
|
|
|
|
batteryStatusLabel1 = view.findViewById(R.id.battery_status1);
|
|
|
|
batteryIcon1 = view.findViewById(R.id.device_battery_status1);
|
|
|
|
batteryStatusBox2 = view.findViewById(R.id.device_battery_status_box2);
|
|
|
|
batteryStatusLabel2 = view.findViewById(R.id.battery_status2);
|
|
|
|
batteryIcon2 = view.findViewById(R.id.device_battery_status2);
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-21 15:59:39 +02:00
|
|
|
deviceSpecificSettingsView = view.findViewById(R.id.device_specific_settings);
|
2018-03-31 16:21:25 +02:00
|
|
|
fetchActivityDataBox = view.findViewById(R.id.device_action_fetch_activity_box);
|
|
|
|
fetchActivityData = view.findViewById(R.id.device_action_fetch_activity);
|
|
|
|
busyIndicator = view.findViewById(R.id.device_busy_indicator);
|
|
|
|
takeScreenshotView = view.findViewById(R.id.device_action_take_screenshot);
|
|
|
|
manageAppsView = view.findViewById(R.id.device_action_manage_apps);
|
|
|
|
setAlarmsView = view.findViewById(R.id.device_action_set_alarms);
|
2021-12-04 16:55:09 +01:00
|
|
|
setRemindersView = view.findViewById(R.id.device_action_set_reminders);
|
2018-03-31 16:21:25 +02:00
|
|
|
showActivityGraphs = view.findViewById(R.id.device_action_show_activity_graphs);
|
|
|
|
showActivityTracks = view.findViewById(R.id.device_action_show_activity_tracks);
|
|
|
|
deviceInfoView = view.findViewById(R.id.device_info_image);
|
2018-08-05 18:52:44 +02:00
|
|
|
calibrateDevice = view.findViewById(R.id.device_action_calibrate);
|
2018-03-31 16:21:25 +02:00
|
|
|
|
|
|
|
deviceInfoBox = view.findViewById(R.id.device_item_infos_box);
|
2016-10-24 17:41:56 +02:00
|
|
|
//overflow
|
2018-03-31 16:21:25 +02:00
|
|
|
deviceInfoList = view.findViewById(R.id.device_item_infos);
|
|
|
|
findDevice = view.findViewById(R.id.device_action_find);
|
2018-07-28 17:23:58 +02:00
|
|
|
fmFrequencyBox = view.findViewById(R.id.device_fm_frequency_box);
|
|
|
|
fmFrequencyLabel = view.findViewById(R.id.fm_frequency);
|
|
|
|
ledColor = view.findViewById(R.id.device_led_color);
|
2021-12-24 15:20:57 +01:00
|
|
|
powerOff = view.findViewById(R.id.device_action_power_off);
|
2021-08-08 11:11:05 +02:00
|
|
|
heartRateStatusBox = view.findViewById(R.id.device_heart_rate_status_box);
|
|
|
|
heartRateStatusLabel = view.findViewById(R.id.heart_rate_status);
|
|
|
|
heartRateIcon = view.findViewById(R.id.device_heart_rate_status);
|
2022-06-23 23:12:08 +02:00
|
|
|
infoIcons = view.findViewById(R.id.device_info_icons);
|
2021-12-24 15:20:57 +01:00
|
|
|
|
2021-11-18 12:22:43 +01:00
|
|
|
cardViewActivityCardLayout = view.findViewById(R.id.card_view_activity_card_layout);
|
|
|
|
|
2021-11-20 15:56:12 +01:00
|
|
|
TotalStepsChart = view.findViewById(R.id.activity_dashboard_piechart1);
|
|
|
|
TotalDistanceChart = view.findViewById(R.id.activity_dashboard_piechart2);
|
|
|
|
SleepTimeChart = view.findViewById(R.id.activity_dashboard_piechart3);
|
2016-10-24 17:41:56 +02:00
|
|
|
}
|
2016-10-21 13:01:30 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
private void justifyListViewHeightBasedOnChildren(ListView listView) {
|
2016-10-21 13:01:30 +02:00
|
|
|
ArrayAdapter adapter = (ArrayAdapter) listView.getAdapter();
|
|
|
|
|
|
|
|
if (adapter == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int totalHeight = 0;
|
|
|
|
for (int i = 0; i < adapter.getCount(); i++) {
|
2018-03-31 16:21:25 +02:00
|
|
|
View listItem = adapter.getView(i, null, listView);
|
2016-10-21 13:01:30 +02:00
|
|
|
listItem.measure(0, 0);
|
|
|
|
totalHeight += listItem.getMeasuredHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
ViewGroup.LayoutParams par = listView.getLayoutParams();
|
|
|
|
par.height = totalHeight + (listView.getDividerHeight() * (adapter.getCount() - 1));
|
|
|
|
listView.setLayoutParams(par);
|
|
|
|
listView.requestLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getUniqueDeviceName(GBDevice device) {
|
2020-06-12 22:49:16 +02:00
|
|
|
String deviceName = device.getAliasOrName();
|
|
|
|
|
2016-10-21 13:01:30 +02:00
|
|
|
if (!isUniqueDeviceName(device, deviceName)) {
|
|
|
|
if (device.getModel() != null) {
|
|
|
|
deviceName = deviceName + " " + device.getModel();
|
|
|
|
if (!isUniqueDeviceName(device, deviceName)) {
|
|
|
|
deviceName = deviceName + " " + device.getShortAddress();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
deviceName = deviceName + " " + device.getShortAddress();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return deviceName;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isUniqueDeviceName(GBDevice device, String deviceName) {
|
2016-10-24 17:41:56 +02:00
|
|
|
for (int i = 0; i < deviceList.size(); i++) {
|
|
|
|
GBDevice item = deviceList.get(i);
|
2016-10-21 13:01:30 +02:00
|
|
|
if (item == device) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (deviceName.equals(item.getName())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2016-10-29 18:20:53 +02:00
|
|
|
|
|
|
|
private void showTransientSnackbar(int resource) {
|
|
|
|
Snackbar snackbar = Snackbar.make(parent, resource, Snackbar.LENGTH_SHORT);
|
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
//View snackbarView = snackbar.getView();
|
2016-10-29 18:20:53 +02:00
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
// change snackbar text color
|
|
|
|
//int snackbarTextId = android.support.design.R.id.snackbar_text;
|
|
|
|
//TextView textView = snackbarView.findViewById(snackbarTextId);
|
2016-10-29 18:20:53 +02:00
|
|
|
//textView.setTextColor();
|
|
|
|
//snackbarView.setBackgroundColor(Color.MAGENTA);
|
|
|
|
snackbar.show();
|
|
|
|
}
|
|
|
|
|
2021-12-04 11:19:59 +01:00
|
|
|
private void setActivityCard(ViewHolder holder, final GBDevice device, long[] dailyTotals) {
|
2021-11-18 12:22:43 +01:00
|
|
|
int steps = (int) dailyTotals[0];
|
|
|
|
int sleep = (int) dailyTotals[1];
|
|
|
|
ActivityUser activityUser = new ActivityUser();
|
|
|
|
int stepGoal = activityUser.getStepsGoal();
|
2021-12-05 10:32:35 +01:00
|
|
|
int sleepGoal = activityUser.getSleepDurationGoal();
|
2021-11-18 12:22:43 +01:00
|
|
|
int sleepGoalMinutes = sleepGoal * 60;
|
2021-12-05 10:32:35 +01:00
|
|
|
int distanceGoal = activityUser.getDistanceGoalMeters() * 100;
|
2021-11-18 12:22:43 +01:00
|
|
|
int stepLength = activityUser.getStepLengthCm();
|
2021-12-05 10:32:35 +01:00
|
|
|
double distanceMeters = dailyTotals[0] * stepLength * 0.01;
|
2021-12-28 22:10:06 +01:00
|
|
|
String distanceFormatted = FormatUtils.getFormattedDistanceLabel(distanceMeters);
|
2021-11-18 12:22:43 +01:00
|
|
|
|
2021-11-20 15:56:12 +01:00
|
|
|
setUpChart(holder.TotalStepsChart);
|
2021-11-25 12:30:03 +01:00
|
|
|
setChartsData(holder.TotalStepsChart, steps, stepGoal, context.getString(R.string.steps), String.valueOf(steps), context);
|
2021-11-20 15:56:12 +01:00
|
|
|
|
|
|
|
setUpChart(holder.TotalDistanceChart);
|
2021-12-28 22:10:06 +01:00
|
|
|
setChartsData(holder.TotalDistanceChart, steps * stepLength, distanceGoal, context.getString(R.string.distance), distanceFormatted, context);
|
2021-11-20 15:56:12 +01:00
|
|
|
|
|
|
|
setUpChart(holder.SleepTimeChart);
|
2021-11-25 12:30:03 +01:00
|
|
|
setChartsData(holder.SleepTimeChart, sleep, sleepGoalMinutes, context.getString(R.string.prefs_activity_in_device_card_sleep_title), String.format("%1s", getHM(sleep)), context);
|
2021-11-20 15:56:12 +01:00
|
|
|
|
2021-11-18 12:22:43 +01:00
|
|
|
boolean showActivityCard = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD, true);
|
|
|
|
holder.cardViewActivityCardLayout.setVisibility(showActivityCard ? View.VISIBLE : View.GONE);
|
|
|
|
|
|
|
|
boolean showActivitySteps = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD_STEPS, true);
|
|
|
|
boolean showActivitySleep = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD_SLEEP, true);
|
|
|
|
boolean showActivityDistance = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD_DISTANCE, true);
|
2021-12-04 20:33:30 +01:00
|
|
|
|
|
|
|
//do the multiple mini-charts for activities in a loop
|
|
|
|
Hashtable<PieChart, Pair<Boolean, Integer>> activitiesStatusMiniCharts = new Hashtable<>();
|
|
|
|
activitiesStatusMiniCharts.put(holder.TotalStepsChart, new Pair<>(showActivitySteps && steps > 0, ChartsActivity.getChartsTabIndex("stepsweek", device, context)));
|
|
|
|
activitiesStatusMiniCharts.put(holder.SleepTimeChart, new Pair<>(showActivitySleep && sleep > 0, ChartsActivity.getChartsTabIndex("sleep", device, context)));
|
|
|
|
activitiesStatusMiniCharts.put(holder.TotalDistanceChart, new Pair<>(showActivityDistance && steps > 0, ChartsActivity.getChartsTabIndex("activity", device, context)));
|
|
|
|
|
|
|
|
for (Map.Entry<PieChart, Pair<Boolean, Integer>> miniCharts : activitiesStatusMiniCharts.entrySet()) {
|
|
|
|
PieChart miniChart = miniCharts.getKey();
|
|
|
|
final Pair<Boolean, Integer> parameters = miniCharts.getValue();
|
|
|
|
miniChart.setVisibility(parameters.first ? View.VISIBLE : View.GONE);
|
|
|
|
miniChart.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent startIntent;
|
|
|
|
startIntent = new Intent(context, ChartsActivity.class);
|
|
|
|
startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
|
|
|
|
startIntent.putExtra(ChartsActivity.EXTRA_FRAGMENT_ID, parameters.second);
|
|
|
|
context.startActivity(startIntent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2021-11-18 12:22:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private String getHM(long value) {
|
|
|
|
return DateTimeUtils.formatDurationHoursMinutes(value, TimeUnit.MINUTES);
|
|
|
|
}
|
2021-11-20 15:56:12 +01:00
|
|
|
private void setUpChart(PieChart DashboardChart) {
|
2021-11-20 17:04:39 +01:00
|
|
|
DashboardChart.setTouchEnabled(false);
|
2021-11-20 15:56:12 +01:00
|
|
|
DashboardChart.setNoDataText("");
|
|
|
|
DashboardChart.getLegend().setEnabled(false);
|
|
|
|
DashboardChart.setDrawHoleEnabled(true);
|
|
|
|
DashboardChart.setHoleColor(Color.WHITE);
|
|
|
|
DashboardChart.getDescription().setText("");
|
|
|
|
DashboardChart.setTransparentCircleColor(Color.WHITE);
|
|
|
|
DashboardChart.setTransparentCircleAlpha(110);
|
|
|
|
DashboardChart.setHoleRadius(70f);
|
|
|
|
DashboardChart.setTransparentCircleRadius(75f);
|
|
|
|
DashboardChart.setDrawCenterText(true);
|
|
|
|
DashboardChart.setRotationEnabled(true);
|
|
|
|
DashboardChart.setHighlightPerTapEnabled(true);
|
|
|
|
DashboardChart.setCenterTextOffset(0, 0);
|
|
|
|
}
|
2021-11-25 12:30:03 +01:00
|
|
|
private void setChartsData(PieChart pieChart, float value, float target, String label, String stringValue, Context context) {
|
2021-11-20 15:56:12 +01:00
|
|
|
final String CHART_COLOR_START = "#e74c3c";
|
|
|
|
final String CHART_COLOR_END = "#2ecc71";
|
|
|
|
|
|
|
|
ArrayList<PieEntry> entries = new ArrayList<>();
|
|
|
|
entries.add(new PieEntry((float) value, context.getResources().getDrawable(R.drawable.ic_star_gold)));
|
|
|
|
|
|
|
|
if (value < target) {
|
|
|
|
entries.add(new PieEntry((float) (target - value)));
|
|
|
|
}
|
|
|
|
|
2021-11-25 12:30:03 +01:00
|
|
|
pieChart.setCenterText(String.format("%s\n%s", stringValue, label));
|
2021-11-20 15:56:12 +01:00
|
|
|
float colorValue = Math.max(0, Math.min(1, value / target));
|
|
|
|
int chartColor = interpolateColor(Color.parseColor(CHART_COLOR_START), Color.parseColor(CHART_COLOR_END), colorValue);
|
|
|
|
|
|
|
|
PieDataSet dataSet = new PieDataSet(entries, "");
|
|
|
|
dataSet.setDrawIcons(false);
|
|
|
|
dataSet.setIconsOffset(new MPPointF(0, -66));
|
|
|
|
|
|
|
|
if (colorValue == 1) {
|
|
|
|
dataSet.setDrawIcons(true);
|
|
|
|
}
|
|
|
|
dataSet.setSliceSpace(0f);
|
|
|
|
dataSet.setSelectionShift(5f);
|
|
|
|
dataSet.setColors(chartColor, Color.LTGRAY);
|
|
|
|
|
|
|
|
PieData data = new PieData(dataSet);
|
|
|
|
data.setValueTextSize(0f);
|
|
|
|
data.setValueTextColor(Color.WHITE);
|
|
|
|
|
|
|
|
pieChart.setData(data);
|
|
|
|
pieChart.invalidate();
|
|
|
|
}
|
|
|
|
private float interpolate(float a, float b, float proportion) {
|
|
|
|
return (a + ((b - a) * proportion));
|
|
|
|
}
|
|
|
|
|
|
|
|
private int interpolateColor(int a, int b, float proportion) {
|
|
|
|
float[] hsva = new float[3];
|
|
|
|
float[] hsvb = new float[3];
|
|
|
|
Color.colorToHSV(a, hsva);
|
|
|
|
Color.colorToHSV(b, hsvb);
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
hsvb[i] = interpolate(hsva[i], hsvb[i], proportion);
|
|
|
|
}
|
|
|
|
return Color.HSVToColor(hsvb);
|
|
|
|
}
|
|
|
|
|
2022-06-28 21:31:58 +02:00
|
|
|
private static class GBDeviceDiffUtil extends DiffUtil.ItemCallback<GBDevice> {
|
|
|
|
@Override
|
|
|
|
public boolean areItemsTheSame(@NonNull GBDevice oldItem, @NonNull GBDevice newItem) {
|
|
|
|
return new EqualsBuilder()
|
|
|
|
.append(oldItem.getAddress(), newItem.getAddress())
|
|
|
|
.append(oldItem.getName(), newItem.getName())
|
|
|
|
.isEquals();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean areContentsTheSame(@NonNull GBDevice oldItem, @NonNull GBDevice newItem) {
|
|
|
|
return EqualsBuilder.reflectionEquals(oldItem, newItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A generator of stable IDs, given a string, since hashCode can easily have collisions.
|
|
|
|
*/
|
|
|
|
private static class StableIdGenerator {
|
|
|
|
private final Map<String, Long> idMapping = new HashMap<String, Long>();
|
|
|
|
|
|
|
|
private long nextId = 0;
|
|
|
|
|
|
|
|
public long getId(final GBDevice device) {
|
|
|
|
final String str = String.format("%s_%s", device.getAddress(), device.getName());
|
|
|
|
|
|
|
|
if (!idMapping.containsKey(str)) {
|
|
|
|
idMapping.put(str, nextId++);
|
|
|
|
}
|
|
|
|
|
|
|
|
return idMapping.get(str);
|
|
|
|
}
|
|
|
|
}
|
2016-10-21 13:01:30 +02:00
|
|
|
}
|