Skip to content

Commit

Permalink
Merge branch 'master' into master-release
Browse files Browse the repository at this point in the history
  • Loading branch information
ndegwamartin committed Nov 4, 2024
2 parents 10e24ef + 6977691 commit 2355d0d
Show file tree
Hide file tree
Showing 81 changed files with 4,185 additions and 628 deletions.
11 changes: 0 additions & 11 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,6 @@ object Dependencies {
const val playServicesLocation =
"com.google.android.gms:play-services-location:${Versions.playServicesLocation}"

const val androidFhirGroup = "org.smartregister"
const val androidFhirEngineModule = "engine"
const val androidFhirKnowledgeModule = "knowledge"
const val androidFhirCommon = "$androidFhirGroup:common:${Versions.androidFhirCommon}"
const val androidFhirEngine =
"$androidFhirGroup:$androidFhirEngineModule:${Versions.androidFhirEngine}"
const val androidFhirKnowledge = "$androidFhirGroup:knowledge:${Versions.androidFhirKnowledge}"

const val apacheCommonsCompress =
"org.apache.commons:commons-compress:${Versions.apacheCommonsCompress}"

Expand Down Expand Up @@ -131,9 +123,6 @@ object Dependencies {
const val xmlUnit = "org.xmlunit:xmlunit-core:${Versions.xmlUnit}"

object Versions {
const val androidFhirCommon = "0.1.0-alpha05-preview3-SNAPSHOT"
const val androidFhirEngine = "1.0.0-preview13-SNAPSHOT"
const val androidFhirKnowledge = "0.1.0-beta01-preview-SNAPSHOT"
const val apacheCommonsCompress = "1.21"
const val desugarJdkLibs = "2.0.3"
const val caffeine = "2.9.1"
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Releases.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ object Releases {

object Workflow : LibraryArtifact {
override val artifactId = "workflow"
override val version = "0.1.0-alpha04-preview13-SNAPSHOT"
override val version = "0.1.0-beta01"
override val name = "Android FHIR Workflow Library"
}

Expand Down
4 changes: 2 additions & 2 deletions datacapture/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ dependencies {
exclude(module = "commons-logging")
exclude(module = "httpclient")
}
implementation(Dependencies.androidFhirCommon)
implementation(Dependencies.material)
implementation(Dependencies.timber)
implementation(libs.android.fhir.common)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.constraintlayout)
implementation(libs.androidx.core)
Expand All @@ -106,7 +106,7 @@ dependencies {
testImplementation(Dependencies.mockitoKotlin)
testImplementation(Dependencies.robolectric)
testImplementation(project(":knowledge")) {
exclude(group = Dependencies.androidFhirGroup, module = Dependencies.androidFhirEngineModule)
exclude(group = "com.google.android.fhir", module = "engine")
}
testImplementation(libs.androidx.test.core)
testImplementation(libs.androidx.fragment.testing)
Expand Down
2 changes: 1 addition & 1 deletion demo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ dependencies {
implementation(libs.kotlinx.coroutines.android)
implementation(libs.kotlinx.coroutines.core)
implementation(project(":datacapture")) {
exclude(group = Dependencies.androidFhirGroup, module = Dependencies.androidFhirEngineModule)
exclude(group = "com.google.android.fhir", module = "engine")
}
implementation(project(":engine"))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 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.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import com.google.android.fhir.FhirEngine
import com.google.android.fhir.demo.extensions.isFirstLaunch
import com.google.android.fhir.demo.extensions.setFirstLaunchCompleted
import com.google.android.fhir.demo.helpers.PatientCreationHelper
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import timber.log.Timber

class ActivityViewModel(application: Application) : AndroidViewModel(application) {
private var fhirEngine: FhirEngine = FhirApplication.fhirEngine(application.applicationContext)

fun createPatientsOnAppFirstLaunch() {
viewModelScope.launch(Dispatchers.IO) {
if (getApplication<FhirApplication>().applicationContext.isFirstLaunch()) {
Timber.i("Creating patients on first launch")
PatientCreationHelper.createSamplePatients().forEach { fhirEngine.create(it) }
getApplication<FhirApplication>().applicationContext.setFirstLaunchCompleted()
Timber.i("Patients created on first launch")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class AddPatientFragment : Fragment(R.layout.add_patient_fragment) {
addQuestionnaireFragment()
}
observePatientSaveAction()
(activity as MainActivity).setDrawerEnabled(false)

/** Use the provided cancel|submit buttons from the sdc library */
childFragmentManager.setFragmentResultListener(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class EditPatientFragment : Fragment(R.layout.add_patient_fragment) {
Toast.makeText(requireContext(), R.string.message_patient_updated, Toast.LENGTH_SHORT).show()
NavHostFragment.findNavController(this).navigateUp()
}
(activity as MainActivity).setDrawerEnabled(false)

/** Use the provided cancel|submit buttons from the sdc library */
childFragmentManager.setFragmentResultListener(
Expand Down
26 changes: 7 additions & 19 deletions demo/src/main/java/com/google/android/fhir/demo/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
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
Expand All @@ -30,32 +29,21 @@ class HomeFragment : Fragment(R.layout.fragment_home) {
super.onViewCreated(view, savedInstanceState)
(requireActivity() as AppCompatActivity).supportActionBar?.apply {
title = resources.getString(R.string.app_name)
setDisplayHomeAsUpEnabled(true)
setDisplayHomeAsUpEnabled(false)
}
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
requireView().findViewById<CardView>(R.id.item_sync).setOnClickListener {
findNavController().navigate(HomeFragmentDirections.actionHomeFragmentToSyncFragment())
}
requireView().findViewById<CardView>(R.id.item_periodic_sync).setOnClickListener {
findNavController()
.navigate(HomeFragmentDirections.actionHomeFragmentToPeriodicSyncFragment())
}
}
}
56 changes: 2 additions & 54 deletions demo/src/main/java/com/google/android/fhir/demo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,78 +17,26 @@
package com.google.android.fhir.demo

import android.os.Bundle
import android.view.MenuItem
import android.widget.TextView
import androidx.activity.viewModels
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.GravityCompat
import androidx.drawerlayout.widget.DrawerLayout
import com.google.android.fhir.demo.databinding.ActivityMainBinding

const val MAX_RESOURCE_COUNT = 20

class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
private lateinit var drawerToggle: ActionBarDrawerToggle
private val viewModel: MainActivityViewModel by viewModels()
private val activityViewModel: ActivityViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
initActionBar()
initNavigationDrawer()
observeLastSyncTime()
viewModel.updateLastSyncTimestamp()
}

override fun onBackPressed() {
if (binding.drawer.isDrawerOpen(GravityCompat.START)) {
binding.drawer.closeDrawer(GravityCompat.START)
return
}
super.onBackPressed()
}

fun setDrawerEnabled(enabled: Boolean) {
val lockMode =
if (enabled) DrawerLayout.LOCK_MODE_UNLOCKED else DrawerLayout.LOCK_MODE_LOCKED_CLOSED
binding.drawer.setDrawerLockMode(lockMode)
drawerToggle.isDrawerIndicatorEnabled = enabled
}

fun openNavigationDrawer() {
binding.drawer.openDrawer(GravityCompat.START)
viewModel.updateLastSyncTimestamp()
activityViewModel.createPatientsOnAppFirstLaunch()
}

private fun initActionBar() {
val toolbar = binding.toolbar
setSupportActionBar(toolbar)
}

private fun initNavigationDrawer() {
binding.navigationView.setNavigationItemSelectedListener(this::onNavigationItemSelected)
drawerToggle = ActionBarDrawerToggle(this, binding.drawer, R.string.open, R.string.close)
binding.drawer.addDrawerListener(drawerToggle)
drawerToggle.syncState()
}

private fun onNavigationItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_sync -> {
viewModel.triggerOneTimeSync()
binding.drawer.closeDrawer(GravityCompat.START)
return false
}
}
return false
}

private fun observeLastSyncTime() {
viewModel.lastSyncTimestampLiveData.observe(this) {
binding.navigationView.getHeaderView(0).findViewById<TextView>(R.id.last_sync_tv).text = it
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Google LLC
* 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.
Expand Down Expand Up @@ -82,7 +82,6 @@ class PatientDetailsFragment : Fragment() {
}
}
patientDetailsViewModel.getPatientDetailData()
(activity as MainActivity).setDrawerEnabled(false)
}

private fun onAddScreenerClick() {
Expand Down
Loading

0 comments on commit 2355d0d

Please sign in to comment.