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

Feat/profile sign out #202

Open
wants to merge 7 commits into
base: development
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
.idea/jsLibraryMappings.xml
.idea/libraries
.idea/libraries/
.idea/codeStyles/
.idea/misc.xml
.idea/modules.xml
.idea/mongoSettings.xml
Expand Down
15 changes: 12 additions & 3 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 25 additions & 3 deletions app/src/main/java/com/fightpandemics/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import androidx.navigation.NavController
import androidx.navigation.NavDestination
import androidx.navigation.ui.setupActionBarWithNavController
import com.fightpandemics.R
import com.fightpandemics.core.utils.getBooleanPreference
import com.fightpandemics.core.utils.removePreference
import com.fightpandemics.utils.setupWithNavController
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.button.MaterialButton
Expand Down Expand Up @@ -53,6 +55,7 @@ class MainActivity : AppCompatActivity(), NavController.OnDestinationChangedList
setupBottomNavigationBar()
} // Else, need to wait for onRestoreInstanceState
setUpBottomNavigationAndFab()
checkThatUserSignedInFromProfile()
}

override fun onRestoreInstanceState(savedInstanceState: Bundle) {
Expand Down Expand Up @@ -100,14 +103,19 @@ class MainActivity : AppCompatActivity(), NavController.OnDestinationChangedList
arguments: Bundle?,
) {
when (destination.id) {
R.id.homeFragment, R.id.searchFragment,
R.id.inboxFragment, R.id.profileFragment,
R.id.homeFragment
-> {
showBottomBar(destination)
dot.visibility = View.VISIBLE
fab.show()
}
R.id.filterFragment, R.id.createPostFragment, R.id.settingFragment -> hideBottomBar()
R.id.searchFragment, R.id.inboxFragment, R.id.profileFragment, R.id.indivProfileSettings, R.id.profileSignedOutFragment
-> {
showBottomBar(destination)
dot.visibility = View.VISIBLE
fab.hide()
}
R.id.filterFragment, R.id.createPostFragment, R.id.settingFragment, R.id.onboardFragment -> hideBottomBar()
}
}

Expand Down Expand Up @@ -248,4 +256,18 @@ class MainActivity : AppCompatActivity(), NavController.OnDestinationChangedList
}
dot.layoutParams = layoutParams
}

private fun checkThatUserSignedInFromProfile() {
val isUserSignedInFromProfile = getBooleanPreference(applicationContext, "isUserSignedInFromProfile", false)
val isUserSignedUpFromProfile = getBooleanPreference(applicationContext, "isUserSignedUpFromProfile", false)
if (isUserSignedInFromProfile || isUserSignedUpFromProfile) {
bottomNavigationView.selectedItemId = R.id.nav_profile
}
}

override fun onDestroy() {
super.onDestroy()
removePreference(applicationContext, "isUserSignedInFromProfile")
removePreference(applicationContext, "isUserSignedUpFromProfile")
}
}
30 changes: 30 additions & 0 deletions app/src/main/res/navigation/nav_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
android:id="@+id/action_profileFragment_to_settingFragment"
app:destination="@id/settingFragment"
app:launchSingleTop="true"/>
<action
android:id="@+id/action_profileFragment_to_profileSignedOutFragment"
app:popUpTo="@id/profileFragment"
app:popUpToInclusive="false"
app:destination="@id/profileSignedOutFragment" />
</fragment>

<include app:graph="@navigation/nav_create_post" />
Expand Down Expand Up @@ -151,4 +156,29 @@
</fragment>

<include app:graph="@navigation/nav_splash_onboard" />

<fragment
android:id="@+id/profileSignedOutFragment"
android:name="com.fightpandemics.profile.ui.profile.ProfileSignedOutFragment"
app:moduleName="Fight_Pandemics.profile"
android:label="Profile"
tools:layout="@layout/profile_signed_out_fragment">

<action
android:id="@+id/action_profileSignedOutFragment_to_signInFragment"
app:destination="@id/nav_sign_in"/>

<action
android:id="@+id/action_profileSignedOutFragment_to_signUpFragment"
app:destination="@id/nav_sign_up"/>

<action
android:id="@+id/action_profileSignedOutFragment_to_indivProfileSettings"
app:destination="@id/indivProfileSettings" />

</fragment>

<include app:graph="@navigation/nav_sign_in" />

<include app:graph="@navigation/nav_sign_up" />
</navigation>
3 changes: 3 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ dependencies {
// Location
implementation 'com.google.android.gms:play-services-location:17.1.0'

// Shared Preference
implementation 'androidx.preference:preference:1.1.1'

}
repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ interface FightPandemicsAPI {

// Profile API calls
@GET("api/users/current")
suspend fun getCurrentUser(): IndividualProfileResponse
suspend fun getCurrentUser(): Response<IndividualProfileResponse>

@PATCH("api/users/current")
suspend fun updateCurrentUserProfile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import retrofit2.Response

interface ProfileRemoteDataSource {

suspend fun fetchCurrentUser(): IndividualProfileResponse
suspend fun fetchCurrentUser(): Response<IndividualProfileResponse>

suspend fun updateCurrentUser(patchIndividualProfileRequest: PatchIndividualProfileRequest):
Response<PatchIndividualProfileResponse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ class ProfileRemoteDataSourceImpl @Inject constructor(
private val fightPandemicsAPI: FightPandemicsAPI,
) : ProfileRemoteDataSource {

override suspend fun fetchCurrentUser(): IndividualProfileResponse {
return fightPandemicsAPI.getCurrentUser()
}
override suspend fun fetchCurrentUser(): Response<IndividualProfileResponse> =
fightPandemicsAPI.getCurrentUser()

override suspend fun updateCurrentUser(patchIndividualProfileRequest: PatchIndividualProfileRequest):
Response<PatchIndividualProfileResponse> =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.fightpandemics.core.data.repository

import com.fightpandemics.core.data.model.login.ErrorResponse
import com.fightpandemics.core.data.model.profile.IndividualProfileResponse
import com.fightpandemics.core.data.model.profile.PatchIndividualAccountRequest
import com.fightpandemics.core.data.model.profile.PatchIndividualProfileRequest
import com.fightpandemics.core.data.prefs.PreferenceStorage
Expand All @@ -15,7 +14,6 @@ import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.flow
import java.net.HttpURLConnection
import javax.inject.Inject

Expand All @@ -27,10 +25,24 @@ class ProfileRepositoryImpl @Inject constructor(
private val profileRemoteDataSource: ProfileRemoteDataSource,
) : ProfileRepository {

override fun getIndividualUser(): Flow<Result<IndividualProfileResponse>> {
return flow {
val individualUser = profileRemoteDataSource.fetchCurrentUser()
emit(Result.Success(individualUser))
override fun getIndividualUser(): Flow<Result<*>> {
return channelFlow {
val response = profileRemoteDataSource.fetchCurrentUser()
when {
response.isSuccessful && response.code() == HttpURLConnection.HTTP_OK -> {
val profileResponse = response.body()
channel.offer(Result.Success(profileResponse))
}
response.code() == HttpURLConnection.HTTP_BAD_REQUEST -> {
val myError = response.parseErrorJsonResponse<ErrorResponse>(moshi)
channel.offer(Result.Error(Exception(myError?.message)))
}
else -> {
val myError = response.parseErrorJsonResponse<ErrorResponse>(moshi)
channel.offer(Result.Error(Exception(myError?.message)))
}
}
awaitClose { }
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.fightpandemics.core.domain.repository

import com.fightpandemics.core.data.model.profile.IndividualProfileResponse
import com.fightpandemics.core.data.model.profile.PatchIndividualAccountRequest
import com.fightpandemics.core.data.model.profile.PatchIndividualProfileRequest
import com.fightpandemics.core.result.Result
import kotlinx.coroutines.flow.Flow

interface ProfileRepository {

fun getIndividualUser(): Flow<Result<IndividualProfileResponse>>
fun getIndividualUser(): Flow<Result<*>>

fun updateIndividualUserProfile(profileRequest: PatchIndividualProfileRequest): Flow<Result<*>>

Expand Down
Loading