diff options
-rw-r--r-- | app/.gitignore | 4 | ||||
-rw-r--r-- | app/src/main/java/com/javispedro/rempe/Device.java | 4 | ||||
-rw-r--r-- | app/src/main/java/com/javispedro/rempe/DeviceListRecyclerViewListAdapter.java | 27 | ||||
-rw-r--r-- | app/src/main/java/com/javispedro/rempe/DeviceViewHolder.java | 42 | ||||
-rw-r--r-- | app/src/main/java/com/javispedro/rempe/MainActivity.java | 18 | ||||
-rw-r--r-- | app/src/main/res/drawable/ic_baseline_check_24.xml | 10 | ||||
-rw-r--r-- | app/src/main/res/drawable/ic_baseline_error_24.xml | 10 | ||||
-rw-r--r-- | app/src/main/res/layout/activity_main.xml | 27 | ||||
-rw-r--r-- | app/src/main/res/layout/fragment_device.xml | 38 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 4 |
10 files changed, 154 insertions, 30 deletions
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<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) { 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 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24" + android:tint="?attr/colorControlNormal"> + <path + android:fillColor="@android:color/white" + android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"/> +</vector> 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 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24" + android:tint="?attr/colorControlNormal"> + <path + android:fillColor="@android:color/white" + android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-2h2v2zM13,13h-2L11,7h2v6z"/> +</vector> 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"> - <androidx.recyclerview.widget.RecyclerView - android:id="@+id/list" - android:name="com.javispedro.rempe.DeviceFragment" + <androidx.swiperefreshlayout.widget.SwipeRefreshLayout + android:id="@+id/srlList" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_marginLeft="16dp" - android:layout_marginRight="16dp" - app:layout_behavior="@string/appbar_scrolling_view_behavior" - app:layoutManager="LinearLayoutManager" - tools:context=".DeviceFragment" - tools:listitem="@layout/fragment_device"> - - </androidx.recyclerview.widget.RecyclerView> + app:layout_behavior="@string/appbar_scrolling_view_behavior"> + + <androidx.recyclerview.widget.RecyclerView + android:id="@+id/list" + android:name="com.javispedro.rempe.DeviceFragment" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_marginLeft="16dp" + android:layout_marginRight="16dp" + app:layoutManager="LinearLayoutManager" + tools:context=".DeviceFragment" + tools:listitem="@layout/fragment_device" /> + + </androidx.swiperefreshlayout.widget.SwipeRefreshLayout> <com.google.android.material.appbar.AppBarLayout android:layout_width="match_parent" diff --git a/app/src/main/res/layout/fragment_device.xml b/app/src/main/res/layout/fragment_device.xml index 0a39ba4..74e067d 100644 --- a/app/src/main/res/layout/fragment_device.xml +++ b/app/src/main/res/layout/fragment_device.xml @@ -1,9 +1,11 @@ <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal"> + android:orientation="horizontal" + android:padding="16dp"> <TextView android:id="@+id/nameView" @@ -22,6 +24,25 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/nameView" /> + <ImageView + android:id="@+id/statusImageView" + android:layout_width="20dp" + android:layout_height="20dp" + android:layout_marginStart="8dp" + android:visibility="invisible" + app:layout_constraintStart_toEndOf="@+id/statusView" + app:layout_constraintTop_toTopOf="@+id/statusView" /> + + <ProgressBar + android:id="@+id/statusProgressBar" + style="?android:attr/progressBarStyle" + android:layout_width="20dp" + android:layout_height="20dp" + android:layout_marginStart="8dp" + android:indeterminate="true" + app:layout_constraintStart_toEndOf="@+id/statusView" + app:layout_constraintTop_toTopOf="@+id/statusView" /> + <TextView android:id="@+id/temperatureView" android:layout_width="wrap_content" @@ -30,8 +51,19 @@ android:text="@string/temperature_nothing" android:textAppearance="@style/TextAppearance.AppCompat.Large" android:textSize="72sp" - app:layout_constraintTop_toTopOf="parent" - app:layout_constraintEnd_toEndOf="parent" /> + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + <TextView + android:id="@+id/minmaxTemperatureLabel" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginEnd="8dp" + android:text="@string/last_24h" + android:visibility="invisible" + app:layout_constraintBottom_toBottomOf="@+id/minTemperatureView" + app:layout_constraintEnd_toStartOf="@+id/minTemperatureView" + app:layout_constraintTop_toTopOf="@+id/minTemperatureView" /> <TextView android:id="@+id/maxTemperatureView" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 97e603d..7db9d07 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -13,12 +13,14 @@ <string name="temperature_nothing">--</string> <string name="temperature_celsius">%1$s °C</string> + <string name="last_24h">Last 24h:</string> + <string name="signal_level">Signal:</string> <string name="state_dead">Disconnected</string> <string name="state_closed">Disconnected</string> <string name="state_searching">Searching</string> - <string name="state_tracking">Tracking</string> + <string name="state_tracking">Connected</string> <string name="state_processing">Processing request</string> <string name="state_unrecognized">Unrecognized</string> <string name="state_unknown">Unknown state</string> |