Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a dashboard in the demo app. #2414

Merged
61 changes: 61 additions & 0 deletions demo/src/main/java/com/google/android/fhir/demo/HomeFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2022-2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.android.fhir.demo

import android.os.Bundle
import android.view.MenuItem
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.cardview.widget.CardView
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController

class HomeFragment : Fragment(R.layout.fragment_home) {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
(requireActivity() as AppCompatActivity).supportActionBar?.apply {
title = resources.getString(R.string.app_name)
setDisplayHomeAsUpEnabled(true)
}
setHasOptionsMenu(true)
(activity as MainActivity).setDrawerEnabled(true)
setOnClicks()
}

private fun setOnClicks() {
requireView().findViewById<CardView>(R.id.item_new_patient).setOnClickListener {
findNavController().navigate(HomeFragmentDirections.actionHomeFragmentToAddPatientFragment())
}
requireView().findViewById<CardView>(R.id.item_patient_list).setOnClickListener {
findNavController().navigate(HomeFragmentDirections.actionHomeFragmentToPatientList())
}
requireView().findViewById<CardView>(R.id.item_search).setOnClickListener {
findNavController().navigate(HomeFragmentDirections.actionHomeFragmentToPatientList())
}
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
android.R.id.home -> {
(requireActivity() as MainActivity).openNavigationDrawer()
true
}
else -> false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.RecyclerView
Expand Down Expand Up @@ -152,7 +153,7 @@ class PatientListFragment : Fragment() {
addPatient.setColorFilter(Color.WHITE)
}
setHasOptionsMenu(true)
(activity as MainActivity).setDrawerEnabled(true)
(activity as MainActivity).setDrawerEnabled(false)
santosh-pingle marked this conversation as resolved.
Show resolved Hide resolved

lifecycleScope.launch {
mainActivityViewModel.pollState.collect {
Expand Down Expand Up @@ -233,9 +234,7 @@ class PatientListFragment : Fragment() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
android.R.id.home -> {
// hide the soft keyboard when the navigation drawer is shown on the screen.
searchView.clearFocus()
(requireActivity() as MainActivity).openNavigationDrawer()
NavHostFragment.findNavController(this).navigateUp()
true
}
else -> false
Expand Down
13 changes: 13 additions & 0 deletions demo/src/main/res/drawable/ic_home_new_patient.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="34dp"
android:height="24dp"
android:viewportWidth="34"
android:viewportHeight="24"
>
<path
android:pathData="M12.289,12C15.586,12 18.257,9.315 18.257,6C18.257,2.685 15.586,0 12.289,0C8.993,0 6.322,2.685 6.322,6C6.322,9.315 8.993,12 12.289,12ZM12.289,3C13.93,3 15.273,4.35 15.273,6C15.273,7.65 13.93,9 12.289,9C10.648,9 9.306,7.65 9.306,6C9.306,4.35 10.648,3 12.289,3ZM0.355,19.5C0.355,15.51 8.306,13.5 12.289,13.5C16.272,13.5 24.224,15.51 24.224,19.5V24H0.355V19.5ZM3.339,21V19.515C3.637,18.435 8.262,16.5 12.289,16.5C16.317,16.5 20.942,18.435 21.24,19.5V21H3.339ZM25.716,10.5V15H28.699V10.5H33.175V7.5H28.699V3H25.716V7.5H21.24V10.5H25.716Z"
android:fillColor="#4285F4"
android:fillType="evenOdd"
/>
</vector>
13 changes: 13 additions & 0 deletions demo/src/main/res/drawable/ic_home_patient_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="28dp"
android:height="28dp"
android:viewportWidth="28"
android:viewportHeight="28"
>
<path
android:pathData="M25.848,0.5H1.681C0.935,0.5 0.339,1.1 0.339,1.85V26.15C0.339,26.75 0.935,27.5 1.681,27.5H25.848C26.445,27.5 27.191,26.75 27.191,26.15V1.85C27.191,1.1 26.445,0.5 25.848,0.5ZM9.289,6.5H6.306V9.5H9.289V6.5ZM21.224,6.5H12.273V9.5H21.224V6.5ZM21.224,12.5H12.273V15.5H21.224V12.5ZM12.273,18.5H21.224V21.5H12.273V18.5ZM6.306,12.5H9.289V15.5H6.306V12.5ZM9.289,18.5H6.306V21.5H9.289V18.5ZM3.322,24.5H24.208V3.5H3.322V24.5Z"
android:fillColor="#4285F4"
android:fillType="evenOdd"
/>
</vector>
13 changes: 13 additions & 0 deletions demo/src/main/res/drawable/ic_home_search.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="27dp"
android:height="27dp"
android:viewportWidth="27"
android:viewportHeight="27"
>
<path
android:pathData="M17.882,15.905L26.43,24.5L24.208,26.735L15.659,18.14C14.063,19.295 12.139,20 10.035,20C4.68,20 0.339,15.635 0.339,10.25C0.339,4.865 4.68,0.5 10.035,0.5C15.391,0.5 19.732,4.865 19.732,10.25C19.732,12.365 19.031,14.3 17.882,15.905ZM10.035,3.5C6.321,3.5 3.322,6.515 3.322,10.25C3.322,13.985 6.321,17 10.035,17C13.75,17 16.749,13.985 16.749,10.25C16.749,6.515 13.75,3.5 10.035,3.5Z"
android:fillColor="#4285F4"
android:fillType="evenOdd"
/>
</vector>
137 changes: 137 additions & 0 deletions demo/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="@dimen/dashboard_margin"
android:layout_marginTop="@dimen/dashboard_margin"
android:orientation="vertical"
>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/item_new_patient"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/cardView_margin_horizontal"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:layout_marginVertical="@dimen/cardView_margin_vertical"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="@dimen/cardView_radius_corner"
>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/new_patient_padding"
android:orientation="horizontal"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_home_new_patient"
android:contentDescription="Task Image"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?textAppearanceTitleLarge"
android:textSize="@dimen/dashboard_text_fontSize"
android:textColor="@color/dashboard_cardview_textcolor"
android:ellipsize="end"
android:maxLines="1"
android:layout_marginHorizontal="@dimen/new_patient_horizontal_margin"
android:layout_gravity="center"
android:text="Register new patient"
/>
</LinearLayout>

</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/item_patient_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/cardView_margin_horizontal"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:layout_marginVertical="@dimen/cardView_margin_vertical"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="@dimen/cardView_radius_corner"
>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/new_patient_padding"
android:orientation="horizontal"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_home_patient_list"
android:contentDescription="Task Image"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?textAppearanceTitleLarge"
android:textSize="@dimen/dashboard_text_fontSize"
android:textColor="@color/dashboard_cardview_textcolor"
android:ellipsize="end"
android:maxLines="1"
android:layout_marginHorizontal="@dimen/new_patient_horizontal_margin"
android:layout_gravity="center"
android:text="Patient list "
/>
</LinearLayout>

</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/item_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/search_patient_cardview_horizontal_margin"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:layout_marginTop="@dimen/search_patient_cardview_margin_top"
android:layout_marginVertical="@dimen/search_patient_cardview_vertical_margin"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="@dimen/cardView_radius_corner"
>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/new_patient_padding"
android:orientation="horizontal"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_home_search"
android:contentDescription="Task Image"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?textAppearanceTitleLarge"
android:textSize="@dimen/dashboard_text_fontSize"
android:textColor="@color/dashboard_cardview_textcolor"
android:ellipsize="end"
android:maxLines="1"
android:layout_marginHorizontal="@dimen/new_patient_horizontal_margin"
android:layout_gravity="center"
android:text="Find a patient"
/>
</LinearLayout>

</androidx.cardview.widget.CardView>
</LinearLayout>
18 changes: 17 additions & 1 deletion demo/src/main/res/navigation/reference_nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,25 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/reference_nav_graph"
app:startDestination="@id/patient_list"
app:startDestination="@id/home_fragment"
>

<fragment
android:id="@+id/home_fragment"
android:name="com.google.android.fhir.demo.HomeFragment"
android:label="HomeFragment"
tools:layout="@layout/fragment_home"
>
<action
android:id="@+id/action_home_fragment_to_addPatientFragment"
app:destination="@id/addPatientFragment"
/>
<action
android:id="@+id/action_home_fragment_to_patient_list"
app:destination="@id/patient_list"
/>
</fragment>

<fragment
android:id="@+id/patient_list"
android:label="Patient List"
Expand Down
9 changes: 7 additions & 2 deletions demo/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<color name="moderate_risk_background">#fff8e1</color>
<color name="high_risk">#c62828</color>
<color name="high_risk_background">#ffebee</color>
<color name="unknown_risk_background">#DADCE0</color>
<color name="unknown_risk">#ffffff</color>
<color name="unknown_risk_background">#77DADCE0</color>
<color name="unknown_risk">#FFDADCE0</color>
<color name="syncing_background">#E8F0FE</color>
<color name="disable_state">#9AFFFFFF</color>

Expand Down Expand Up @@ -87,4 +87,9 @@
<color name="onSurfaceVariant_neutral_variant_80">#C4C7C5</color>

<color name="outline_neutral_variant_60">#8E918F</color>

<color name="black">#000000</color>
<color name="white">#FFFFFFFF</color>
<color name="dashboard_cardview_textcolor">#4D4D4D</color>

</resources>
10 changes: 10 additions & 0 deletions demo/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@
<dimen name="status_margin">5dp</dimen>
<dimen name="header_height">170dp</dimen>
<dimen name="patient_count_start_margin">65dp</dimen>
<dimen name="dashboard_margin">10dp</dimen>
<dimen name="cardView_margin_horizontal">8dp</dimen>
<dimen name="cardView_margin_vertical">10dp</dimen>
<dimen name="cardView_radius_corner">10dp</dimen>
<dimen name="new_patient_padding">30dp</dimen>
<dimen name="new_patient_horizontal_margin">20dp</dimen>
<dimen name="search_patient_cardview_horizontal_margin">8dp</dimen>
<dimen name="search_patient_cardview_vertical_margin">6dp</dimen>
<dimen name="search_patient_cardview_margin_top">10dp</dimen>
<dimen name="dashboard_text_fontSize">20sp</dimen>
</resources>
Loading