2018-02-26 14:27:32 +01:00
|
|
|
/* Copyright (C) 2015-2018 Andreas Shimokawa, Carsten Pfeiffer, Daniele
|
2017-03-16 17:36:15 +01:00
|
|
|
Gobbetti, Lem Dulfo
|
|
|
|
|
|
|
|
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;
|
2018-03-31 16:21:25 +02:00
|
|
|
import android.support.annotation.NonNull;
|
2016-10-29 18:20:53 +02:00
|
|
|
import android.support.design.widget.Snackbar;
|
2016-10-25 17:49:21 +02:00
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
2016-10-29 18:20:53 +02:00
|
|
|
import android.support.v7.widget.CardView;
|
2016-10-24 17:41:56 +02:00
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
|
import android.transition.TransitionManager;
|
2016-10-21 13:01:30 +02:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.ListView;
|
|
|
|
import android.widget.ProgressBar;
|
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
import android.widget.TextView;
|
2016-10-25 17:49:21 +02:00
|
|
|
import android.widget.Toast;
|
2016-10-21 13:01:30 +02:00
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
2017-10-19 21:52:38 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.ActivitySummariesActivity;
|
2016-10-21 13:01:30 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.ConfigureAlarms;
|
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;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
2016-10-25 17:49:21 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
|
2016-10-21 13:01:30 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
|
|
|
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;
|
2016-10-21 13:01:30 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
2016-10-25 17:49:21 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
2016-10-21 13:01:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adapter for displaying GBDevice instances.
|
|
|
|
*/
|
2016-10-24 17:41:56 +02:00
|
|
|
public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.ViewHolder> {
|
2016-10-21 13:01:30 +02:00
|
|
|
|
|
|
|
private final Context context;
|
2016-10-24 17:41:56 +02:00
|
|
|
private List<GBDevice> deviceList;
|
|
|
|
private int expandedDevicePosition = RecyclerView.NO_POSITION;
|
|
|
|
private ViewGroup parent;
|
2016-10-21 13:01:30 +02:00
|
|
|
|
|
|
|
public GBDeviceAdapterv2(Context context, List<GBDevice> deviceList) {
|
|
|
|
this.context = context;
|
2016-10-24 17:41:56 +02:00
|
|
|
this.deviceList = deviceList;
|
2016-10-21 13:01:30 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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) {
|
2016-10-24 17:41:56 +02:00
|
|
|
final GBDevice device = deviceList.get(position);
|
2017-03-16 17:36:46 +01:00
|
|
|
final DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
2016-10-21 13:01:30 +02:00
|
|
|
|
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) {
|
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) {
|
2017-03-13 22:27:59 +01:00
|
|
|
if (device.getState() != GBDevice.State.NOT_CONNECTED) {
|
2016-10-30 14:42:08 +01:00
|
|
|
showTransientSnackbar(R.string.controlcenter_snackbar_disconnecting);
|
|
|
|
GBApplication.deviceService().disconnect();
|
|
|
|
}
|
2016-10-21 17:44:36 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2016-10-29 18:20:53 +02:00
|
|
|
holder.deviceImageView.setImageResource(R.drawable.level_list_device);
|
|
|
|
//level-list does not allow negative values, hence we always add 100 to the key.
|
|
|
|
holder.deviceImageView.setImageLevel(device.getType().getKey() + 100 + (device.isInitialized() ? 100 : 0));
|
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
|
2016-10-24 17:41:56 +02:00
|
|
|
holder.batteryStatusBox.setVisibility(View.GONE);
|
2016-10-21 13:01:30 +02:00
|
|
|
short batteryLevel = device.getBatteryLevel();
|
|
|
|
if (batteryLevel != GBDevice.BATTERY_UNKNOWN) {
|
2016-10-24 17:41:56 +02:00
|
|
|
holder.batteryStatusBox.setVisibility(View.VISIBLE);
|
|
|
|
holder.batteryStatusLabel.setText(device.getBatteryLevel() + "%");
|
2016-10-21 13:01:30 +02:00
|
|
|
BatteryState batteryState = device.getBatteryState();
|
2016-10-21 17:44:36 +02:00
|
|
|
if (BatteryState.BATTERY_CHARGING.equals(batteryState) ||
|
|
|
|
BatteryState.BATTERY_CHARGING_FULL.equals(batteryState)) {
|
2016-10-24 17:41:56 +02:00
|
|
|
holder.batteryIcon.setImageLevel(device.getBatteryLevel() + 100);
|
2016-10-21 13:01:30 +02:00
|
|
|
} else {
|
2016-10-24 17:41:56 +02:00
|
|
|
holder.batteryIcon.setImageLevel(device.getBatteryLevel());
|
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
|
2016-10-24 17:41:56 +02:00
|
|
|
holder.setAlarmsView.setVisibility(coordinator.supportsAlarmConfiguration() ? View.VISIBLE : View.GONE);
|
|
|
|
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
|
|
|
);
|
|
|
|
|
|
|
|
//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
|
|
|
|
2016-10-24 17:41:56 +02:00
|
|
|
final boolean detailsShown = position == expandedDevicePosition;
|
2016-10-21 13:01:30 +02:00
|
|
|
boolean showInfoIcon = device.hasDeviceInfos() && !device.isBusy();
|
2016-10-24 17:41:56 +02:00
|
|
|
holder.deviceInfoView.setVisibility(showInfoIcon ? View.VISIBLE : View.GONE);
|
|
|
|
holder.deviceInfoBox.setActivated(detailsShown);
|
|
|
|
holder.deviceInfoBox.setVisibility(detailsShown ? View.VISIBLE : View.GONE);
|
|
|
|
holder.deviceInfoView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
expandedDevicePosition = detailsShown ? -1 : position;
|
|
|
|
TransitionManager.beginDelayedTransition(parent);
|
|
|
|
notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
2016-10-21 17:44:36 +02:00
|
|
|
|
|
|
|
);
|
2016-10-21 13:01:30 +02:00
|
|
|
|
2016-10-24 17:41:56 +02:00
|
|
|
holder.findDevice.setVisibility(device.isInitialized() ? View.VISIBLE : View.GONE);
|
|
|
|
holder.findDevice.setOnClickListener(new View.OnClickListener()
|
2016-10-21 17:44:36 +02:00
|
|
|
|
2016-10-24 17:41:56 +02:00
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-03-16 17:36:46 +01:00
|
|
|
if (device.getType() == DeviceType.VIBRATISSIMO) {
|
|
|
|
Intent startIntent;
|
|
|
|
startIntent = new Intent(context, VibrationActivity.class);
|
|
|
|
startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
|
|
|
|
context.startActivity(startIntent);
|
|
|
|
return;
|
|
|
|
}
|
2016-10-24 17:41:56 +02:00
|
|
|
GBApplication.deviceService().onFindDevice(true);
|
2016-10-30 15:15:34 +01:00
|
|
|
//TODO: extract string resource if we like this solution.
|
|
|
|
Snackbar.make(parent, R.string.control_center_find_lost_device, Snackbar.LENGTH_INDEFINITE).setAction("Found it!", new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
GBApplication.deviceService().onFindDevice(false);
|
|
|
|
}
|
2016-10-30 15:21:06 +01:00
|
|
|
}).setCallback(new Snackbar.Callback() {
|
|
|
|
@Override
|
|
|
|
public void onDismissed(Snackbar snackbar, int event) {
|
|
|
|
GBApplication.deviceService().onFindDevice(false);
|
|
|
|
super.onDismissed(snackbar, event);
|
|
|
|
}
|
2016-10-30 15:15:34 +01:00
|
|
|
}).show();
|
|
|
|
// ProgressDialog.show(
|
|
|
|
// 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 17:44:36 +02:00
|
|
|
|
2016-10-21 13:01:30 +02:00
|
|
|
);
|
|
|
|
|
2016-10-24 17:41:56 +02:00
|
|
|
//remove device, hidden under details
|
|
|
|
holder.removeDevice.setOnClickListener(new View.OnClickListener()
|
2016-10-21 17:44:36 +02:00
|
|
|
|
|
|
|
{
|
2016-10-24 17:41:56 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2016-10-25 17:49:21 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
DeviceHelper.getInstance().removeBond(device);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
GB.toast(context, "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();
|
2016-10-24 17:41:56 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
return deviceList.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
static class ViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
|
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
|
|
|
|
LinearLayout batteryStatusBox;
|
|
|
|
TextView batteryStatusLabel;
|
|
|
|
ImageView batteryIcon;
|
|
|
|
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;
|
|
|
|
ImageView showActivityGraphs;
|
2017-10-19 21:52:38 +02:00
|
|
|
ImageView showActivityTracks;
|
2016-10-24 17:41:56 +02:00
|
|
|
|
|
|
|
ImageView deviceInfoView;
|
|
|
|
//overflow
|
|
|
|
final RelativeLayout deviceInfoBox;
|
|
|
|
ListView deviceInfoList;
|
|
|
|
ImageView findDevice;
|
|
|
|
ImageView removeDevice;
|
|
|
|
|
|
|
|
ViewHolder(View view) {
|
|
|
|
super(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
|
2018-03-31 16:21:25 +02:00
|
|
|
batteryStatusBox = view.findViewById(R.id.device_battery_status_box);
|
|
|
|
batteryStatusLabel = view.findViewById(R.id.battery_status);
|
|
|
|
batteryIcon = view.findViewById(R.id.device_battery_status);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
removeDevice = view.findViewById(R.id.device_action_remove);
|
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) {
|
|
|
|
String deviceName = device.getName();
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2016-10-21 13:01:30 +02:00
|
|
|
}
|