Skip to content

Commit

Permalink
(feat) added splash screen to open required activity on app start.
Browse files Browse the repository at this point in the history
  • Loading branch information
parthfloyd committed Jul 29, 2024
1 parent fc99313 commit e12f5d8
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 104 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ android {
}

dependencies {
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")
implementation("androidx.activity:activity:1.9.0")
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")
implementation("androidx.activity:activity-ktx:1.8.2")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
Expand Down
55 changes: 19 additions & 36 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,68 +1,51 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
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.
-->
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:name="org.openmrs.android.fhir.FhirApplication"
android:name=".FhirApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_fire_engine"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_fire_engine_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
>
android:theme="@style/AppTheme">
<activity
android:name="org.openmrs.android.fhir.LoginActivity"
android:exported="true"
>
android:name=".SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name="org.openmrs.android.fhir.MainActivity"
android:windowSoftInputMode="adjustResize"
android:exported="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
android:name=".LoginActivity"
android:exported="false">

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:exported="false"
android:windowSoftInputMode="adjustResize">
</activity>
<activity
android:name="net.openid.appauth.RedirectUriReceiverActivity"
android:exported="true"
>
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:scheme="https"
android:host="org.openmrs.android.fhir"
android:path="/oauth2redirect"
/>
android:scheme="https" />
</intent-filter>
</activity>
</application>
</manifest>

</manifest>
6 changes: 5 additions & 1 deletion app/src/main/java/org/openmrs/android/fhir/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ class LoginActivity : AppCompatActivity() {
setContentView(binding.root)
lifecycleScope.launchWhenResumed {
val loginIntent = viewModel.createIntent()
binding.buttonLogin.setOnClickListener { getContent.launch(loginIntent) }
binding.buttonLogin.setOnClickListener {
if (loginIntent != null) {
getContent.launch(loginIntent)
}
}
}
}
}
31 changes: 31 additions & 0 deletions app/src/main/java/org/openmrs/android/fhir/SplashActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.openmrs.android.fhir

import android.content.Intent
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import org.openmrs.android.fhir.auth.AuthStateManager

class SplashActivity : AppCompatActivity() {

private lateinit var authStateManager: AuthStateManager
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_splash)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
authStateManager = AuthStateManager.getInstance(applicationContext)
if (authStateManager.current.isAuthorized) {
startActivity(Intent(this, MainActivity::class.java))
} else {
startActivity(Intent(this, LoginActivity::class.java))
}

}
}
10 changes: 10 additions & 0 deletions app/src/main/res/layout/activity_splash.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SplashActivity">

</androidx.constraintlayout.widget.ConstraintLayout>
126 changes: 61 additions & 65 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,73 +14,69 @@
limitations under the License.
-->
<resources>
<string name="app_name">OpenMRS</string>
<string name="app_name">OpenMRS</string>

<string name="title_patient_list">Registered Patients</string>
<string name="title_patient_detail">SamplePatient Detail</string>
<string name="title_patient_list">Registered Patients</string>
<string name="title_patient_detail">SamplePatient Detail</string>

<string name="menu_about">About Fhir Engine</string>
<string name="menu_sync_resources">Sync Resources</string>
<string name="menu_patient_edit">@string/edit_patient</string>
<string name="menu_about">About Fhir Engine</string>
<string name="menu_sync_resources">Sync Resources</string>
<string name="menu_patient_edit">@string/edit_patient</string>

<!-- For display observations in brief, for a patient -->
<string name="observation_brief_text">%1$s: %2$s\nEffective: %3$s</string>
<string name="query_hint_patient_search">Find by Patient Name</string>
<string
name="cancel_questionnaire_message"
>Are you sure you want to discard the answers?</string>
<string name="patient_id">Id</string>
<string name="patient_name">Name</string>
<string name="patient_gender">Gender</string>
<string name="patient_dob">DOB</string>
<string name="patient_phone_number">Phone Number</string>
<string name="patient_city">City</string>
<string name="patient_country">Country</string>
<string name="patient_is_active">Is Active</string>
<string name="patient_property_mobile">Mobile Number</string>
<string name="patient_property_id">ID Number</string>
<string name="patient_property_address">Address</string>
<string name="patient_property_dob">Date of Birth</string>
<string name="patient_property_gender">Gender</string>
<string name="add_patient">Add Patient</string>
<string name="edit_patient">Edit Patient</string>
<string name="edit_encounter">Edit Encounter</string>
<string name="location">Location</string>
<string name="identifier">Identifier</string>
<string name="select_a_location">Select a Location</string>
<string name="select_identifier_types">Select Identifier Types</string>
<string name="submit">Submit</string>
<string name="message_syncing">Syncing\u2026</string>
<!-- For display observations in brief, for a patient -->
<string name="observation_brief_text">%1$s: %2$s\nEffective: %3$s</string>
<string name="query_hint_patient_search">Find by Patient Name</string>
<string name="cancel_questionnaire_message">Are you sure you want to discard the answers?</string>
<string name="patient_id">Id</string>
<string name="patient_name">Name</string>
<string name="patient_gender">Gender</string>
<string name="patient_dob">DOB</string>
<string name="patient_phone_number">Phone Number</string>
<string name="patient_city">City</string>
<string name="patient_country">Country</string>
<string name="patient_is_active">Is Active</string>
<string name="patient_property_mobile">Mobile Number</string>
<string name="patient_property_id">ID Number</string>
<string name="patient_property_address">Address</string>
<string name="patient_property_dob">Date of Birth</string>
<string name="patient_property_gender">Gender</string>
<string name="add_patient">Add Patient</string>
<string name="edit_patient">Edit Patient</string>
<string name="edit_encounter">Edit Encounter</string>
<string name="location">Location</string>
<string name="identifier">Identifier</string>
<string name="select_a_location">Select a Location</string>
<string name="select_identifier_types">Select Identifier Types</string>
<string name="submit">Submit</string>
<string name="message_syncing">Syncing\u2026</string>

<string name="message_patient_updated">Patient is updated.</string>
<string name="message_encounter_updated">Encounter is updated.</string>
<string name="inputs_missing">Inputs are missing.</string>
<string name="resources_saved">Resources are saved.</string>
<string name="response_received">questionnaire response is received.</string>
<string name="html_text">Current status: <font
color="#ddd"
>UNKNOWN</font></string>
<string name="header_observation">Observations</string>
<string name="header_conditions">Conditions</string>
<string name="message_no_datetime">No effective DateTime</string>
<string name="complete_survey">Complete Survey</string>
<string name="risk_status">Current status: </string>
<string name="unknown">UNKNOWN</string>
<string name="none">none</string>
<string name="description_status">Status</string>
<string name="open">Open</string>
<string name="close">Close</string>
<string name="sync_menu">Sync</string>
<string name="last_sync">Last sync</string>
<string name="syncing">Syncing</string>
<string name="sync">Sync</string>
<string name="button_login">Log in</string>
<string name="header_encounters">Encounters</string>
<string name="component_nav_heading">Components</string>
<string name="layout_nav_heading">Layouts</string>
<string name="behavior_nav_heading">Behaviors</string>
<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>
<string name="message_patient_updated">Patient is updated.</string>
<string name="message_encounter_updated">Encounter is updated.</string>
<string name="inputs_missing">Inputs are missing.</string>
<string name="resources_saved">Resources are saved.</string>
<string name="response_received">questionnaire response is received.</string>
<string name="html_text">Current status: <font color="#ddd">UNKNOWN</font></string>
<string name="header_observation">Observations</string>
<string name="header_conditions">Conditions</string>
<string name="message_no_datetime">No effective DateTime</string>
<string name="complete_survey">Complete Survey</string>
<string name="risk_status">Current status: </string>
<string name="unknown">UNKNOWN</string>
<string name="none">none</string>
<string name="description_status">Status</string>
<string name="open">Open</string>
<string name="close">Close</string>
<string name="sync_menu">Sync</string>
<string name="last_sync">Last sync</string>
<string name="syncing">Syncing</string>
<string name="sync">Sync</string>
<string name="button_login">Log in</string>
<string name="header_encounters">Encounters</string>
<string name="component_nav_heading">Components</string>
<string name="layout_nav_heading">Layouts</string>
<string name="behavior_nav_heading">Behaviors</string>
<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>
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ buildscript {

plugins {
id("com.google.devtools.ksp") version "2.0.0-1.0.21" apply false
}
id("org.jetbrains.kotlin.android") version "2.0.0" apply false
}

allprojects {
repositories {
Expand Down

0 comments on commit e12f5d8

Please sign in to comment.