Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Navigation library to Reference app. (#533)
* Added Navigation library to Reference app. Also updated the patient details page * Review comment changes * Spotless apply
- Loading branch information
Showing
19 changed files
with
457 additions
and
527 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
reference/src/main/java/com/google/android/fhir/reference/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
) | ||
) | ||
} | ||
} |
64 changes: 0 additions & 64 deletions
64
reference/src/main/java/com/google/android/fhir/reference/PatientDetailActivity.kt
This file was deleted.
Oops, something went wrong.
65 changes: 0 additions & 65 deletions
65
reference/src/main/java/com/google/android/fhir/reference/PatientDetailFragment.kt
This file was deleted.
Oops, something went wrong.
103 changes: 103 additions & 0 deletions
103
reference/src/main/java/com/google/android/fhir/reference/PatientDetailsFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
Oops, something went wrong.