summaryrefslogtreecommitdiff
path: root/app/src/main/java/com/javispedro
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/com/javispedro')
-rw-r--r--app/src/main/java/com/javispedro/rempe/Device.java4
-rw-r--r--app/src/main/java/com/javispedro/rempe/DeviceListRecyclerViewListAdapter.java27
-rw-r--r--app/src/main/java/com/javispedro/rempe/DeviceViewHolder.java42
-rw-r--r--app/src/main/java/com/javispedro/rempe/MainActivity.java18
4 files changed, 77 insertions, 14 deletions
diff --git a/app/src/main/java/com/javispedro/rempe/Device.java b/app/src/main/java/com/javispedro/rempe/Device.java
index 4622eed..d3a0d05 100644
--- a/app/src/main/java/com/javispedro/rempe/Device.java
+++ b/app/src/main/java/com/javispedro/rempe/Device.java
@@ -106,6 +106,10 @@ public class Device {
}
}
+ public int getDeviceNumber() {
+ return mDeviceNumber;
+ }
+
public String getDeviceName() {
return mDeviceName;
}
diff --git a/app/src/main/java/com/javispedro/rempe/DeviceListRecyclerViewListAdapter.java b/app/src/main/java/com/javispedro/rempe/DeviceListRecyclerViewListAdapter.java
index 2288f20..102f1ec 100644
--- a/app/src/main/java/com/javispedro/rempe/DeviceListRecyclerViewListAdapter.java
+++ b/app/src/main/java/com/javispedro/rempe/DeviceListRecyclerViewListAdapter.java
@@ -16,6 +16,24 @@ public class DeviceListRecyclerViewListAdapter extends RecyclerView.Adapter<Devi
private List<Device> mList;
+ public DeviceListRecyclerViewListAdapter() {
+ setHasStableIds(true);
+ }
+
+ @Override
+ public int getItemCount() {
+ if (mList != null) {
+ return mList.size();
+ } else {
+ return 0;
+ }
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return mList.get(position).getDeviceNumber();
+ }
+
@Override
@NonNull
public DeviceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
@@ -29,14 +47,7 @@ public class DeviceListRecyclerViewListAdapter extends RecyclerView.Adapter<Devi
holder.setDevice(mList.get(position));
}
- @Override
- public int getItemCount() {
- if (mList != null) {
- return mList.size();
- } else {
- return 0;
- }
- }
+
public void setDeviceList(List<Device> list) {
mList = list;
diff --git a/app/src/main/java/com/javispedro/rempe/DeviceViewHolder.java b/app/src/main/java/com/javispedro/rempe/DeviceViewHolder.java
index 9731471..6306a2b 100644
--- a/app/src/main/java/com/javispedro/rempe/DeviceViewHolder.java
+++ b/app/src/main/java/com/javispedro/rempe/DeviceViewHolder.java
@@ -2,6 +2,7 @@ package com.javispedro.rempe;
import android.content.Context;
import android.view.View;
+import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
@@ -18,12 +19,15 @@ public class DeviceViewHolder extends RecyclerView.ViewHolder implements Device.
private final Context mContext;
private final TextView mTemperatureView;
+ private final TextView mMinMaxTemperatureLabel;
private final TextView mMinTemperatureView;
private final TextView mMaxTemperatureView;
private final TextView mNameView;
private final TextView mStatusView;
- private final ProgressBar mSignalBar;
+ private final ImageView mStatusImageView;
+ private final ProgressBar mStatusProgressView;
private final TextView mSignalLabel;
+ private final ProgressBar mSignalBar;
private Device mDevice;
@@ -33,7 +37,10 @@ public class DeviceViewHolder extends RecyclerView.ViewHolder implements Device.
mContext = view.getContext();
mNameView = view.findViewById(R.id.nameView);
mStatusView = view.findViewById(R.id.statusView);
+ mStatusImageView = view.findViewById(R.id.statusImageView);
+ mStatusProgressView = view.findViewById(R.id.statusProgressBar);
mTemperatureView = view.findViewById(R.id.temperatureView);
+ mMinMaxTemperatureLabel = view.findViewById(R.id.minmaxTemperatureLabel);
mMinTemperatureView = view.findViewById(R.id.minTemperatureView);
mMaxTemperatureView = view.findViewById(R.id.maxTemperatureView);
mSignalBar = view.findViewById(R.id.signalBar);
@@ -52,8 +59,9 @@ public class DeviceViewHolder extends RecyclerView.ViewHolder implements Device.
}
mDevice = device;
if (mDevice != null) {
- mNameView.setText(mDevice.getDeviceName());
mDevice.setObserver(this);
+ onDeviceInfoChanged();
+ onDeviceStateChanged();
}
}
@@ -63,12 +71,15 @@ public class DeviceViewHolder extends RecyclerView.ViewHolder implements Device.
private void resetDisplay() {
mTemperatureView.setText(mContext.getString(R.string.temperature_nothing));
+ mMinMaxTemperatureLabel.setVisibility(View.INVISIBLE);
mMinTemperatureView.setText(mContext.getString(R.string.temperature_nothing));
mMaxTemperatureView.setText(mContext.getString(R.string.temperature_nothing));
mNameView.setText("");
mStatusView.setText("");
- mSignalBar.setProgress(0);
+ mStatusImageView.setVisibility(View.INVISIBLE);
+ mStatusProgressView.setVisibility(View.INVISIBLE);
mSignalLabel.setVisibility(View.INVISIBLE);
+ mSignalBar.setProgress(0);
}
private String formatTemperature(BigDecimal temp) {
@@ -88,8 +99,32 @@ public class DeviceViewHolder extends RecyclerView.ViewHolder implements Device.
runOnUiThread(() -> {
if (mDevice.getConnectResult() != RequestAccessResult.SUCCESS) {
mStatusView.setText(Device.connectionRequestAccessResultToString(mContext, mDevice.getConnectResult()));
+ mStatusImageView.setImageResource(R.drawable.ic_baseline_error_24);
+ mStatusProgressView.setVisibility(View.INVISIBLE);
+ mStatusImageView.setVisibility(View.VISIBLE);
} else {
mStatusView.setText(Device.deviceStateToString(mContext, mDevice.getCurrentDeviceState()));
+ switch (mDevice.getCurrentDeviceState()) {
+ case TRACKING:
+ mStatusImageView.setImageResource(R.drawable.ic_baseline_check_24);
+ mStatusProgressView.setVisibility(View.INVISIBLE);
+ mStatusImageView.setVisibility(View.VISIBLE);
+ break;
+ case SEARCHING:
+ case PROCESSING_REQUEST:
+ mStatusImageView.setVisibility(View.INVISIBLE);
+ mStatusProgressView.setVisibility(View.VISIBLE);
+ break;
+ case DEAD:
+ mStatusImageView.setImageResource(R.drawable.ic_baseline_error_24);
+ mStatusProgressView.setVisibility(View.INVISIBLE);
+ mStatusImageView.setVisibility(View.VISIBLE);
+ break;
+ default:
+ mStatusImageView.setVisibility(View.INVISIBLE);
+ mStatusProgressView.setVisibility(View.INVISIBLE);
+ break;
+ }
}
});
}
@@ -99,6 +134,7 @@ public class DeviceViewHolder extends RecyclerView.ViewHolder implements Device.
runOnUiThread(() -> {
final Reading reading = mDevice.getLastReading();
mTemperatureView.setText(formatTemperature(reading.temperature));
+ mMinMaxTemperatureLabel.setVisibility(View.VISIBLE);
mMinTemperatureView.setText(formatTemperature(reading.lowLast24Hours));
mMaxTemperatureView.setText(formatTemperature(reading.highLast24Hours));
});
diff --git a/app/src/main/java/com/javispedro/rempe/MainActivity.java b/app/src/main/java/com/javispedro/rempe/MainActivity.java
index e458468..2c29bc4 100644
--- a/app/src/main/java/com/javispedro/rempe/MainActivity.java
+++ b/app/src/main/java/com/javispedro/rempe/MainActivity.java
@@ -14,6 +14,7 @@ import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.ListUpdateCallback;
import androidx.recyclerview.widget.RecyclerView;
+import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.dsi.ant.plugins.antplus.pcc.AntPlusEnvironmentPcc;
import com.dsi.ant.plugins.antplus.pcc.defines.DeviceState;
@@ -45,6 +46,8 @@ public class MainActivity extends AppCompatActivity {
private final ArrayList<Device> mDevices = new ArrayList<Device>();
private DeviceListRecyclerViewListAdapter mDeviceListAdapter;
+ private SwipeRefreshLayout mSrlList;
+ private RecyclerView mList;
private PccReleaseHandle<AntPlusEnvironmentPcc> mPccSearchHandle;
@@ -61,10 +64,13 @@ public class MainActivity extends AppCompatActivity {
FloatingActionButton fab = findViewById(R.id.fabAddDevice);
fab.setOnClickListener(view -> onConnectButtonClicked());
- RecyclerView list = findViewById(R.id.list);
- list.setLayoutManager(new LinearLayoutManager(list.getContext()));
+ mSrlList = findViewById(R.id.srlList);
+ mSrlList.setOnRefreshListener(() -> onListRefresh());
+
+ mList = findViewById(R.id.list);
+ mList.setLayoutManager(new LinearLayoutManager(mList.getContext()));
mDeviceListAdapter = new DeviceListRecyclerViewListAdapter();
- list.setAdapter(mDeviceListAdapter);
+ mList.setAdapter(mDeviceListAdapter);
refreshDevices();
}
@@ -74,6 +80,7 @@ public class MainActivity extends AppCompatActivity {
disconnectAll();
mPrefs = null;
mDeviceListAdapter = null;
+ mSrlList = null;
super.onDestroy();
}
@@ -120,6 +127,11 @@ public class MainActivity extends AppCompatActivity {
searchForNewDevice();
}
+ private void onListRefresh() {
+ connectToDevices();
+ mSrlList.setRefreshing(false);
+ }
+
public void searchForNewDevice() {
Log.d(TAG, "searchForNewDevice");
if (mPccSearchHandle != null) {