Skip to content

Commit

Permalink
Added Navigation library to Reference app. (#533)
Browse files Browse the repository at this point in the history
* Added Navigation library to Reference app. Also updated the patient details page

* Review comment changes

* Spotless apply
  • Loading branch information
aditya-07 committed Jun 14, 2021
1 parent 33e0df9 commit 125a979
Show file tree
Hide file tree
Showing 19 changed files with 457 additions and 527 deletions.
1 change: 1 addition & 0 deletions reference/build.gradle.kts
Expand Up @@ -2,6 +2,7 @@ plugins {
id(Plugins.BuildPlugins.application)
id(Plugins.BuildPlugins.kotlinAndroid)
id(Plugins.BuildPlugins.kotlinKapt)
id(Plugins.BuildPlugins.navSafeArgs)
}

android {
Expand Down
13 changes: 1 addition & 12 deletions reference/src/main/AndroidManifest.xml
Expand Up @@ -30,7 +30,7 @@
android:theme="@style/AppTheme"
>
<activity
android:name="com.google.android.fhir.reference.PatientListActivity"
android:name="com.google.android.fhir.reference.MainActivity"
android:label="@string/title_patient_list"
android:theme="@style/AppTheme.NoActionBar"
>
Expand All @@ -40,17 +40,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.google.android.fhir.reference.PatientDetailActivity"
android:label="@string/title_patient_detail"
android:parentActivityName="com.google.android.fhir.reference.PatientListActivity"
android:theme="@style/AppTheme.NoActionBar"
>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.google.android.fhir.reference.PatientListActivity"
/>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
@@ -0,0 +1,49 @@
/*
* Copyright 2020 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.reference

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.work.Constraints
import com.google.android.fhir.reference.data.FhirPeriodicSyncWorker
import com.google.android.fhir.sync.PeriodicSyncConfiguration
import com.google.android.fhir.sync.RepeatInterval
import com.google.android.fhir.sync.Sync
import java.util.concurrent.TimeUnit

const val MAX_RESOURCE_COUNT = 20

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val toolbar = findViewById<Toolbar>(R.id.toolbar)
setSupportActionBar(toolbar)
toolbar.title = title

Sync.periodicSync<FhirPeriodicSyncWorker>(
this,
PeriodicSyncConfiguration(
syncConstraints = Constraints.Builder().build(),
repeat = RepeatInterval(interval = 1, timeUnit = TimeUnit.MINUTES)
)
)
}
}

This file was deleted.

This file was deleted.

@@ -0,0 +1,103 @@
/*
* Copyright 2020 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.reference

import android.os.Bundle
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.text.HtmlCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.RecyclerView
import com.google.android.fhir.FhirEngine

/**
* A fragment representing a single Patient detail screen. This fragment is contained in a
* [MainActivity].
*/
class PatientDetailsFragment : Fragment() {
private lateinit var fhirEngine: FhirEngine
private lateinit var patientDetailsViewModel: PatientDetailsViewModel
private val args: PatientDetailsFragmentArgs by navArgs()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? = inflater.inflate(R.layout.patient_detail, container, false)

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val recyclerView: RecyclerView = view.findViewById(R.id.observation_list)
val adapter = ObservationItemRecyclerViewAdapter()
recyclerView.adapter = adapter
fhirEngine = FhirApplication.fhirEngine(requireContext())
patientDetailsViewModel =
ViewModelProvider(
this,
PatientDetailsViewModelFactory(requireActivity().application, fhirEngine, args.patientId)
)
.get(PatientDetailsViewModel::class.java)
patientDetailsViewModel.livePatientData.observe(viewLifecycleOwner) {
setupPatientData(view, it)
}
patientDetailsViewModel.livePatientObservation.observe(viewLifecycleOwner) {
adapter.submitList(it)
}
}

private fun setupPatientData(view: View, patient: PatientListViewModel.PatientItem?) {
patient?.let {
view.findViewById<TextView>(R.id.patient_detail).text =
HtmlCompat.fromHtml(it.html, HtmlCompat.FROM_HTML_MODE_LEGACY)
view.findViewById<TextView>(R.id.name).text = it.name
view.findViewById<TextView>(R.id.dob).text = it.dob
view.findViewById<TextView>(R.id.gender).text = it.phone

(requireActivity() as AppCompatActivity).supportActionBar?.apply {
title = it.name
setDisplayHomeAsUpEnabled(true)
}
}
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
android.R.id.home -> {
NavHostFragment.findNavController(this).navigateUp()
true
}
else -> super.onOptionsItemSelected(item)
}
}

companion object {
/** The fragment argument representing the patient item ID that this fragment represents. */
const val ARG_ITEM_ID = "patient_item_id"
}
}

0 comments on commit 125a979

Please sign in to comment.