From 4fafdb37fb23d12469cc1ac4b23efe9583f87407 Mon Sep 17 00:00:00 2001 From: Javier Date: Fri, 26 Mar 2021 15:21:13 +0100 Subject: Add status icons and clearer status messages --- app/.gitignore | 4 ++- app/src/main/java/com/javispedro/rempe/Device.java | 4 +++ .../rempe/DeviceListRecyclerViewListAdapter.java | 27 +++++++++----- .../com/javispedro/rempe/DeviceViewHolder.java | 42 ++++++++++++++++++++-- .../java/com/javispedro/rempe/MainActivity.java | 18 ++++++++-- app/src/main/res/drawable/ic_baseline_check_24.xml | 10 ++++++ app/src/main/res/drawable/ic_baseline_error_24.xml | 10 ++++++ app/src/main/res/layout/activity_main.xml | 27 ++++++++------ app/src/main/res/layout/fragment_device.xml | 38 ++++++++++++++++++-- app/src/main/res/values/strings.xml | 4 ++- 10 files changed, 154 insertions(+), 30 deletions(-) create mode 100644 app/src/main/res/drawable/ic_baseline_check_24.xml create mode 100644 app/src/main/res/drawable/ic_baseline_error_24.xml diff --git a/app/.gitignore b/app/.gitignore index 42afabf..ea11cb5 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1 +1,3 @@ -/build \ No newline at end of file +/build +/release/app-release.apk +/release/output-metadata.json 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 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 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 mDevices = new ArrayList(); private DeviceListRecyclerViewListAdapter mDeviceListAdapter; + private SwipeRefreshLayout mSrlList; + private RecyclerView mList; private PccReleaseHandle 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) { diff --git a/app/src/main/res/drawable/ic_baseline_check_24.xml b/app/src/main/res/drawable/ic_baseline_check_24.xml new file mode 100644 index 0000000..0432fa6 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_check_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_baseline_error_24.xml b/app/src/main/res/drawable/ic_baseline_error_24.xml new file mode 100644 index 0000000..b915a34 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_error_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index fe4da78..aecd8c6 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,19 +6,24 @@ android:layout_height="match_parent" tools:context=".MainActivity"> - - - + app:layout_behavior="@string/appbar_scrolling_view_behavior"> + + + + + android:orientation="horizontal" + android:padding="16dp"> + + + + + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + -- %1$s °C + Last 24h: + Signal: Disconnected Disconnected Searching - Tracking + Connected Processing request Unrecognized Unknown state -- cgit v1.2.3