Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
tools:replace="android:allowBackup,android:label"
tools:targetApi="31"
tools:ignore="ExtraText">
<activity
android:name=".view.general.SplashActivity"
android:exported="true"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".WelcomeActivity"
android:exported="false" />
Expand Down Expand Up @@ -161,20 +170,17 @@
<activity
android:name=".view.general.LoginActivity"
android:exported="false" />
<activity
android:name=".view.general.ForgotPasswordActivity"
android:exported="false" />
<activity android:name=".view.general.PinCodeActivity"
android:exported="false" />
<activity
android:name=".view.general.AddNewPatientActivity"
android:exported="false" /> <!-- Kussay: may we need to change the start up page into login page -->
android:exported="false" />
<activity
android:name=".view.general.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> <!-- These are here only for UI testing -->
android:exported="false" />
<activity
android:name=".view.patient.patientdata.medicaldiagnostics.MedicalDiagnosticsActivity"
android:exported="false" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,21 @@ import deakin.gopher.guardian.view.general.TasksListActivity

class NavigationService(val activity: Activity) {
fun toHomeScreenForRole(role: Role) {
when (role) {
Role.Caretaker -> {
activity.startActivity(
Intent(
activity.applicationContext,
Homepage4caretaker::class.java,
),
)
}

Role.Nurse -> {
activity.startActivity(
Intent(
activity.applicationContext,
Homepage4nurse::class.java,
),
)
}

Role.Admin -> {
activity.startActivity(
Intent(
activity.applicationContext,
Homepage4admin::class.java,
),
)
}

Role.Doctor -> {
activity.startActivity(
Intent(
activity.applicationContext,
Homepage4doctor::class.java,
),
)
}
val intent = when (role) {
Role.Caretaker -> Intent(activity, Homepage4caretaker::class.java)
Role.Nurse -> Intent(activity, Homepage4nurse::class.java)
Role.Admin -> Intent(activity, Homepage4admin::class.java)
}
// Clear back stack so user cannot go back to Login/PIN screens
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
activity.startActivity(intent)
activity.finish()
}

fun toRegistration() {
activity.startActivity(
Intent(
activity.applicationContext,
activity,
RegisterActivity::class.java,
),
)
Expand All @@ -68,25 +40,23 @@ class NavigationService(val activity: Activity) {
fun onSettings() {
activity.startActivity(
Intent(
activity.applicationContext,
activity,
Setting::class.java,
),
)
}

fun onSignOut() {
activity.startActivity(
Intent(
activity.applicationContext,
LoginActivity::class.java,
),
)
val intent = Intent(activity, LoginActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
activity.startActivity(intent)
activity.finish()
}

fun onLaunchPatientList() {
activity.startActivity(
Intent(
activity.applicationContext,
activity,
PatientListActivity::class.java,
),
)
Expand All @@ -95,7 +65,7 @@ class NavigationService(val activity: Activity) {
fun onLaunchTasks() {
activity.startActivity(
Intent(
activity.applicationContext,
activity,
TasksListActivity::class.java,
),
)
Expand All @@ -104,24 +74,26 @@ class NavigationService(val activity: Activity) {
fun onLaunchTaskCreator() {
activity.startActivity(
Intent(
activity.applicationContext,
activity,
TaskAddActivity::class.java,
),
)
}

fun toLogin() {
activity.startActivity(
Intent(
activity.applicationContext,
LoginActivity::class.java,
),
)
val intent = Intent(activity, LoginActivity::class.java)
// If coming from Registration, we want to clear the Registration screen from stack
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
activity.startActivity(intent)
activity.finish()
}

fun toPinCodeActivity(role: Role) {
val intent = Intent(activity.applicationContext, PinCodeActivity::class.java)
val intent = Intent(activity, PinCodeActivity::class.java)
intent.putExtra("role", role)
activity.startActivity(intent)
// We keep LoginActivity in the stack in case user wants to go back from PIN screen?
// Actually, usually you'd want to finish() it too if PIN is mandatory.
// If we want the back button on PIN screen to go back to Login, we don't finish() here.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package deakin.gopher.guardian.view.general

import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.EditText
import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.TextView
import android.widget.Toast
import androidx.core.widget.addTextChangedListener
import com.google.android.material.textfield.TextInputLayout
import com.google.gson.Gson
import deakin.gopher.guardian.R
import deakin.gopher.guardian.model.ApiErrorResponse
import deakin.gopher.guardian.model.BaseModel
import deakin.gopher.guardian.model.login.EmailAddress
import deakin.gopher.guardian.services.api.ApiClient
import deakin.gopher.guardian.view.hide
import deakin.gopher.guardian.view.show
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class ForgotPasswordActivity : BaseActivity() {

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

val emailEditText: EditText = findViewById(R.id.emailEditText)
val emailLayout: TextInputLayout = findViewById(R.id.emailTextInputLayout)
val resetButton: Button = findViewById(R.id.resetButton)
val backToLoginButton: Button = findViewById(R.id.backToLoginButton)
val progressBar: ProgressBar = findViewById(R.id.progressBar)
val instructionText: TextView = findViewById(R.id.instructionText)
val statusIcon: ImageView = findViewById(R.id.statusIcon)

emailEditText.addTextChangedListener { emailLayout.error = null }

resetButton.setOnClickListener {
val email = emailEditText.text.toString().trim()

if (email.isEmpty()) {
emailLayout.error = getString(R.string.validation_empty_email)
return@setOnClickListener
}

if (!EmailAddress(email).isValid()) {
emailLayout.error = getString(R.string.validation_invalid_email_address)
return@setOnClickListener
}

setLoading(true, resetButton, progressBar)

val call = ApiClient.apiService.requestPasswordReset(email)
call.enqueue(object : Callback<BaseModel> {
override fun onResponse(call: Call<BaseModel>, response: Response<BaseModel>) {
setLoading(false, resetButton, progressBar)
if (response.isSuccessful) {
// Show success state
instructionText.text = response.body()?.apiMessage ?: getString(R.string.toast_reset_link_sent_to_your_email)
emailLayout.visibility = View.GONE
resetButton.visibility = View.GONE
statusIcon.visibility = View.VISIBLE
// Change icon to something like a success check if available,
// using agedcare_icon as placeholder
} else {
val errorResponse = parseError(response)
showMessage(errorResponse ?: response.message())
}
}

override fun onFailure(call: Call<BaseModel>, t: Throwable) {
setLoading(false, resetButton, progressBar)
showMessage(getString(R.string.toast_error_reset_link_is_not_sent_reason, t.localizedMessage))
}
})
}

backToLoginButton.setOnClickListener {
finish()
}
}

private fun setLoading(isLoading: Boolean, button: Button, progressBar: ProgressBar) {
button.isEnabled = !isLoading
if (isLoading) progressBar.show() else progressBar.hide()
}

private fun parseError(response: Response<*>): String? {
return try {
val errorResponse = Gson().fromJson(
response.errorBody()?.string(),
ApiErrorResponse::class.java,
)
errorResponse.apiError
} catch (e: Exception) {
null
}
}

private fun showMessage(message: String) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
}
}
Loading
Loading