Refactor EnvironmentalSensor fragment to use cards.

This commit is contained in:
Denis-Cosmin Nutiu 2020-11-24 23:31:42 +02:00
parent c3ed9e569a
commit b6f42a7358
4 changed files with 101 additions and 52 deletions

View file

@ -10,6 +10,7 @@ import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders; import androidx.lifecycle.ViewModelProviders;
import com.google.android.material.chip.Chip;
import dev.nuculabs.grpc.EnvironmentSensorData; import dev.nuculabs.grpc.EnvironmentSensorData;
import dev.nuculabs.grpc.EnvironmentSensorService; import dev.nuculabs.grpc.EnvironmentSensorService;
import dev.nuculabs.nucuhub.R; import dev.nuculabs.nucuhub.R;
@ -19,7 +20,7 @@ public class SensorsFragment extends Fragment {
private EnvironmentSensorService environmentSensorService; private EnvironmentSensorService environmentSensorService;
// ui elements // ui elements
private ImageView sensorStatusImageView; private ImageView sensorStatusImageView;
private TextView sensorStatusText; private Chip sensorStatusText;
private TextView temperatureText; private TextView temperatureText;
private TextView humidityText; private TextView humidityText;
private TextView pressureText; private TextView pressureText;
@ -34,7 +35,7 @@ public class SensorsFragment extends Fragment {
pressureText = root.findViewById(R.id.envSensorPressureText); pressureText = root.findViewById(R.id.envSensorPressureText);
vocText = root.findViewById(R.id.envSensorVocText); vocText = root.findViewById(R.id.envSensorVocText);
sensorStatusImageView = root.findViewById(R.id.sensorStatusImageView); sensorStatusImageView = root.findViewById(R.id.sensorStatusImageView);
sensorStatusText = root.findViewById(R.id.sensorStatusText); sensorStatusText = root.findViewById(R.id.sensorStatusChip);
environmentSensorService = new EnvironmentSensorService("192.168.0.100", 8000); environmentSensorService = new EnvironmentSensorService("192.168.0.100", 8000);

View file

@ -29,10 +29,12 @@
tools:srcCompat="@drawable/status_neutral" android:adjustViewBounds="true" tools:srcCompat="@drawable/status_neutral" android:adjustViewBounds="true"
android:scaleType="center" android:scaleType="center"
/> />
<TextView <com.google.android.material.chip.Chip
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="19dp" android:id="@+id/sensorStatusText" android:layout_height="wrap_content" android:id="@+id/sensorStatusChip"
tools:text="Sensor Status Explain" android:textStyle="bold" android:layout_margin="20dp"/> android:layout_marginEnd="30dp" android:layout_marginStart="30dp" android:textAlignment="center"
tools:text="Sensor Status Explain" android:textStyle="bold" android:layout_marginTop="15dp"
android:layout_marginBottom="15dp" android:clickable="false"/>
</LinearLayout> </LinearLayout>
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>
<LinearLayout <LinearLayout
@ -65,16 +67,30 @@
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:layout_marginStart="29dp" android:layout_marginStart="29dp"
android:layout_marginTop="21dp"/> android:layout_marginTop="21dp"/>
<TextView <LinearLayout
android:layout_width="55dp" android:orientation="vertical"
android:layout_height="52dp" android:id="@+id/envSensorTempText" android:layout_width="wrap_content"
android:gravity="center" android:foregroundGravity="center" android:layout_height="wrap_content"
android:backgroundTint="#00FFFEFE" android:layout_marginStart="29dp"
android:clickable="false" android:drawableTint="#00FFFFFF" android:layout_marginTop="21dp"
android:textStyle="bold" android:textColor="#000000" android:layout_marginBottom="25dp"
android:textSize="16sp" android:layout_marginTop="21dp" >
android:layout_marginStart="29dp" tools:text="10000" <TextView
android:layout_marginBottom="25dp"/> android:layout_width="55dp"
android:layout_height="26dp" android:id="@+id/envSensorTempText"
android:gravity="center" android:foregroundGravity="center"
android:backgroundTint="#00FFFEFE"
android:clickable="false" android:drawableTint="#00FFFFFF"
android:textStyle="bold" android:textColor="#000000"
android:textSize="16sp"
tools:text="10000"
/>
<TextView
android:text="@string/temp_sensor_unit"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/envSensorTempUnitDesc"
android:gravity="center"/>
</LinearLayout>
</LinearLayout> </LinearLayout>
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView <androidx.cardview.widget.CardView
@ -92,18 +108,29 @@
android:contentDescription="@string/humidity_icon_desc" android:contentDescription="@string/humidity_icon_desc"
android:layout_marginStart="29dp" android:layout_marginStart="29dp"
android:layout_marginTop="21dp"/> android:layout_marginTop="21dp"/>
<TextView <LinearLayout
android:layout_width="55dp" android:orientation="vertical"
android:layout_height="52dp" android:id="@+id/envSensorHumidityText" android:layout_width="wrap_content"
android:gravity="center" android:foregroundGravity="center" android:layout_height="wrap_content"
android:backgroundTint="#00FFFEFE"
android:clickable="false" android:drawableTint="#00FFFFFF"
android:textStyle="bold" android:textColor="#000000"
android:textSize="16sp"
tools:text="100.11"
android:layout_marginStart="29dp" android:layout_marginStart="29dp"
android:layout_marginTop="21dp" android:layout_marginTop="21dp"
android:layout_marginBottom="25dp"/> android:layout_marginBottom="25dp"
>
<TextView
android:layout_width="55dp"
android:layout_height="26dp" android:id="@+id/envSensorHumidityText"
android:gravity="center" android:foregroundGravity="center"
android:backgroundTint="#00FFFEFE"
android:clickable="false" android:drawableTint="#00FFFFFF"
android:textStyle="bold" android:textColor="#000000"
android:textSize="16sp"
tools:text="100.11"/>
<TextView
android:text="@string/humidity_sensor_unit"
android:layout_width="55dp"
android:layout_height="0dp" android:id="@+id/envSensorHumidityUnitDesc"
android:layout_weight="1" android:gravity="center"/>
</LinearLayout>
</LinearLayout> </LinearLayout>
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>
</LinearLayout> </LinearLayout>
@ -126,18 +153,27 @@
android:contentDescription="@string/barometer_icon_desc" android:contentDescription="@string/barometer_icon_desc"
android:layout_marginStart="29dp" android:layout_marginStart="29dp"
android:layout_marginTop="21dp"/> android:layout_marginTop="21dp"/>
<TextView <LinearLayout
android:layout_width="55dp" android:orientation="vertical"
android:layout_height="52dp" android:id="@+id/envSensorPressureText" android:layout_width="wrap_content"
android:gravity="center" android:foregroundGravity="center" android:layout_height="wrap_content" android:layout_marginStart="29dp"
android:backgroundTint="#00FFFEFE" android:layout_marginTop="21dp" android:layout_marginBottom="25dp">
android:clickable="false" android:drawableTint="#00FFFFFF" <TextView
android:textStyle="bold" android:textColor="#000000" android:layout_width="55dp"
android:textSize="16sp" android:layout_height="26dp" android:id="@+id/envSensorPressureText"
tools:text="1000.5" android:gravity="center" android:foregroundGravity="center"
android:layout_marginStart="29dp" android:backgroundTint="#00FFFEFE"
android:layout_marginTop="21dp" android:clickable="false" android:drawableTint="#00FFFFFF"
android:layout_marginBottom="25dp"/> android:textStyle="bold" android:textColor="#000000"
android:textSize="16sp"
tools:text="1000.5"
/>
<TextView
android:text="@string/pressure_unit_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/envSensorPressureUnitDesc"
android:gravity="center"/>
</LinearLayout>
</LinearLayout> </LinearLayout>
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView <androidx.cardview.widget.CardView
@ -155,19 +191,27 @@
android:layout_marginStart="29dp" android:layout_marginStart="29dp"
android:layout_marginTop="21dp" android:layout_marginTop="21dp"
/> />
<TextView <LinearLayout
android:layout_width="55dp" android:orientation="vertical"
android:layout_height="52dp" android:id="@+id/envSensorVocText" android:layout_width="wrap_content"
android:gravity="center" android:foregroundGravity="center" android:layout_height="wrap_content" android:layout_marginStart="29dp"
android:backgroundTint="#00FFFEFE" android:layout_marginTop="21dp" android:layout_marginBottom="25dp">
android:clickable="false" android:drawableTint="#00FFFFFF" <TextView
android:textStyle="bold" android:textColor="#000000" android:layout_width="55dp"
android:textSize="16sp" android:layout_height="26dp" android:id="@+id/envSensorVocText"
tools:text="100.11" android:gravity="center" android:foregroundGravity="center"
android:layout_marginStart="29dp" android:backgroundTint="#00FFFEFE"
android:layout_marginTop="21dp" android:clickable="false" android:drawableTint="#00FFFFFF"
android:layout_marginBottom="25dp" android:textStyle="bold" android:textColor="#000000"
/> android:textSize="16sp"
tools:text="100.11"
/>
<TextView
android:text="@string/gasvoc_sensor_unit_descriptio"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/textView5"
android:gravity="center"/>
</LinearLayout>
</LinearLayout> </LinearLayout>
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>
</LinearLayout> </LinearLayout>

View file

@ -15,4 +15,8 @@
<string name="temperature_icon_desc">temperature icon</string> <string name="temperature_icon_desc">temperature icon</string>
<string name="barometer_icon_desc">barometer icon</string> <string name="barometer_icon_desc">barometer icon</string>
<string name="voc_icon_desc">voc icon</string> <string name="voc_icon_desc">voc icon</string>
<string name="humidity_sensor_unit">Rh%</string>
<string name="temp_sensor_unit">Celsius</string>
<string name="pressure_unit_desc">hPa</string>
<string name="gasvoc_sensor_unit_descriptio">VOC Ω</string>
</resources> </resources>

View file

@ -1,6 +1,6 @@
<resources> <resources>
<!-- Base application theme. --> <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <style name="AppTheme" parent="Theme.MaterialComponents.Light">
<!-- Customize your theme here. --> <!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item>