Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple account UI #52

Open
wants to merge 3 commits into
base: client-dev
Choose a base branch
from
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.microsoft.research.karya.data.exceptions

class AccessCodeAlreadyUsedException(message: String) : Exception(message)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.microsoft.research.karya.data.exceptions

class SessionExpiredException(message: String) : Exception(message)
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.microsoft.research.karya.data.repo

import com.microsoft.research.karya.data.exceptions.AccessCodeAlreadyUsedException
import com.microsoft.research.karya.data.exceptions.IncorrectAccessCodeException
import com.microsoft.research.karya.data.exceptions.IncorrectOtpException
import com.microsoft.research.karya.data.exceptions.PhoneNumberAlreadyUsedException
import com.microsoft.research.karya.data.exceptions.SessionExpiredException
import com.microsoft.research.karya.data.exceptions.UnknownException
import com.microsoft.research.karya.data.local.daos.WorkerDao
import com.microsoft.research.karya.data.model.karya.WorkerRecord
Expand Down Expand Up @@ -35,7 +36,7 @@ constructor(private val workerAPI: WorkerAPI, private val workerDao: WorkerDao)
if (!response.isSuccessful) {
throw when (response.code()) {
404 -> IncorrectOtpException("Incorrect OTP")
403 -> PhoneNumberAlreadyUsedException("Phone Number is Already in use")
403 -> AccessCodeAlreadyUsedException("Access Code is being used by another phone number")
401 -> IncorrectAccessCodeException("Access Code is incorrect")
else -> UnknownException("Something went wrong")
}
Expand All @@ -53,7 +54,10 @@ constructor(private val workerAPI: WorkerAPI, private val workerDao: WorkerDao)
val responseBody = response.body()

if (!response.isSuccessful) {
error("Request failed, response code: ${response.code()}")
throw when (response.code()) {
401 -> IncorrectAccessCodeException("Access Code is incorrect")
else -> UnknownException("Something went wrong")
}
}

if (responseBody != null) {
Expand All @@ -70,7 +74,10 @@ constructor(private val workerAPI: WorkerAPI, private val workerDao: WorkerDao)
val workerRecord = response.body()

if (!response.isSuccessful) {
error("Request failed, response code: ${response.code()}")
throw when (response.code()) {
401 -> SessionExpiredException("Invalid id-token")
else -> UnknownException("Something went wrong")
}
}

if (workerRecord != null) {
Expand All @@ -90,7 +97,7 @@ constructor(private val workerAPI: WorkerAPI, private val workerDao: WorkerDao)

if (!response.isSuccessful) {
throw when (response.code()) {
401 -> IncorrectAccessCodeException("Access Code is incorrect")
401 -> IncorrectAccessCodeException("Invalid Access Code or id token")
else -> UnknownException("Something went wrong")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class AccessCodeFragment : Fragment(R.layout.fragment_access_code) {
when (result) {
is Result.Success<*> -> onAccessCodeVerified(result as Result.Success<Int>, accessCode)
// TODO: Use error codes and exceptions from Anurag's PR
is Result.Error -> showErrorMessage(result.exception.message ?: "Error fetching data")
is Result.Error -> showErrorMessage(getString(result.errorMessageId))
Result.Loading -> showLoading()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.microsoft.research.karya.R
import com.microsoft.research.karya.data.exceptions.AccessCodeAlreadyUsedException
import com.microsoft.research.karya.data.exceptions.IncorrectAccessCodeException
import com.microsoft.research.karya.data.exceptions.IncorrectOtpException
import com.microsoft.research.karya.data.exceptions.PhoneNumberAlreadyUsedException
import com.microsoft.research.karya.data.exceptions.UnknownException
import com.microsoft.research.karya.data.model.karya.enums.OtpSendState
import com.microsoft.research.karya.data.model.karya.enums.OtpVerifyState
Expand Down Expand Up @@ -126,7 +126,7 @@ constructor(
private fun sendGenerateOtpError(e: Throwable) {
phoneNumberFragmentErrorId =
when (e) {
is PhoneNumberAlreadyUsedException -> R.string.s_phone_number_already_used
is AccessCodeAlreadyUsedException -> R.string.s_phone_number_already_used
is IncorrectAccessCodeException ->
R.string.s_invalid_creation_code // this case should never happen
is UnknownException -> R.string.s_unknown_error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
package com.microsoft.research.karya.utils

import com.microsoft.research.karya.R
import com.microsoft.research.karya.data.exceptions.AccessCodeAlreadyUsedException
import com.microsoft.research.karya.data.exceptions.IncorrectAccessCodeException
import com.microsoft.research.karya.data.exceptions.IncorrectOtpException
import com.microsoft.research.karya.data.exceptions.UnknownException
import java.net.SocketTimeoutException
import java.net.UnknownHostException

sealed class Result {
class Success<T>(val value: T) : Result()
class Error(val exception: Throwable) : Result()
class Error(val exception: Throwable) : Result() {
val errorMessageId =
when (exception) {
is UnknownHostException -> R.string.s_no_internet_or_server_down
is SocketTimeoutException -> R.string.s_no_internet_or_server_down
// Socket Timeout may also happen due to bad internet connection, maybe indicate in the
// string?
is AccessCodeAlreadyUsedException -> R.string.s_phone_number_already_used
is IncorrectAccessCodeException -> R.string.s_invalid_creation_code
is IncorrectOtpException -> R.string.s_invalid_otp
is UnknownException -> R.string.s_unknown_error
else -> R.string.s_unknown_error
}
Comment on lines +14 to +25
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this from both of your PRs?

}
object Loading : Result()
}
24 changes: 24 additions & 0 deletions client/app/src/main/res/layout/account_chooser.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Please choose your account"
android:gravity="center"
android:textColor="#000000"
android:textSize="@dimen/_18ssp"
android:layout_marginBottom="@dimen/_18sdp"
/>

<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:itemCount="3"
tools:listitem="@layout/item_user_account" />

</LinearLayout>
38 changes: 38 additions & 0 deletions client/app/src/main/res/layout/item_user_account.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 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:layout_width="match_parent" android:layout_height="match_parent"
app:cardCornerRadius="@dimen/_10sdp"
android:elevation="@dimen/_3sdp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:src="@tools:sample/avatars"
android:padding="8dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Anurag Shukla"
android:textSize="@dimen/_28ssp"
android:textColor="@color/colorBlack"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="9399151865"
android:textSize="@dimen/_20ssp"/>
</LinearLayout>
</LinearLayout>

</androidx.cardview.widget.CardView>