Skip to content

Commit

Permalink
(feat) init: added current location in side-pane.
Browse files Browse the repository at this point in the history
  • Loading branch information
parthfloyd committed Jun 7, 2024
1 parent 1221b20 commit d75a001
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/src/main/java/org/openmrs/android/fhir/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ import androidx.core.view.GravityCompat
import androidx.drawerlayout.widget.DrawerLayout
import androidx.lifecycle.lifecycleScope
import com.google.android.fhir.sync.CurrentSyncJobStatus
import kotlinx.coroutines.flow.first
import org.openmrs.android.fhir.databinding.ActivityMainBinding
import kotlinx.coroutines.launch
import org.openmrs.android.fhir.auth.dataStore
import org.openmrs.android.fhir.data.PreferenceKeys
import org.openmrs.android.fhir.viewmodel.MainActivityViewModel
import timber.log.Timber

Expand Down Expand Up @@ -79,6 +82,21 @@ class MainActivity : AppCompatActivity() {
drawerToggle = ActionBarDrawerToggle(this, binding.drawer, R.string.open, R.string.close)
binding.drawer.addDrawerListener(drawerToggle)
drawerToggle.syncState()
setLocationInDrawer()
}

private fun setLocationInDrawer() {
lifecycleScope.launch {
val selectedLocationName = applicationContext?.dataStore?.data?.first()?.get(
PreferenceKeys.LOCATION_NAME)
if (selectedLocationName != null) {
binding.navigationView.menu.findItem(R.id.menu_current_location).title = selectedLocationName
}
}
}

fun updateLocationName(locationName: String) {
binding.navigationView.menu.findItem(R.id.menu_current_location).title = locationName
}

private fun onNavigationItemSelected(item: MenuItem): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class LocationFragment: Fragment(R.layout.fragment_location) {
preferences[PreferenceKeys.LOCATION_NAME] = selectedLocation.name
}
binding.selectedLocationTv.text = selectedLocation.name
(activity as MainActivity).updateLocationName(selectedLocation.name)
Toast.makeText(context, "Location Updated", Toast.LENGTH_SHORT).show()
}
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/menu/drawer_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
android:icon="@android:drawable/ic_popup_sync"
android:title="@string/sync_menu"
/>
<item
android:id="@+id/menu_current_location"
android:icon="@drawable/ic_location"
android:title="@string/no_location_selected"
/>
</group>
</menu>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@
<string name="error">Error</string>
<string name="open_questionnaire">Open questionnaire</string>
<string name="current_location_label">Current Location : </string>
<string name="no_location_selected">No Location Selected</string>
</resources>

0 comments on commit d75a001

Please sign in to comment.