-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:PeriodPals/periodpals into feat/pro…
…file/view-model
- Loading branch information
Showing
41 changed files
with
8,907 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
app/src/androidTest/java/com/android/periodpals/MainActivityTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.android.periodpals | ||
|
||
import android.Manifest | ||
import android.content.pm.PackageManager | ||
import androidx.core.content.ContextCompat | ||
import androidx.test.core.app.ActivityScenario | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.rule.GrantPermissionRule | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class MainActivityTest { | ||
|
||
@get:Rule | ||
val permissionRule: GrantPermissionRule = | ||
GrantPermissionRule.grant(Manifest.permission.ACCESS_FINE_LOCATION) | ||
|
||
@Test | ||
fun testLocationPermissionGranted() { | ||
val scenario = ActivityScenario.launch(MainActivity::class.java) | ||
scenario.onActivity { activity -> | ||
val permissionStatus = | ||
ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) | ||
assertTrue(permissionStatus == PackageManager.PERMISSION_GRANTED) | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
app/src/androidTest/java/com/android/periodpals/ui/map/MapScreenTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.android.periodpals.ui.map | ||
|
||
// UI test for MapViewContainer.kt | ||
|
||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithTag | ||
import com.android.periodpals.ui.theme.PeriodPalsAppTheme | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class MapScreenTest { | ||
|
||
@get:Rule val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun testMapScreenWithPermissionGranted() { | ||
composeTestRule.setContent { | ||
PeriodPalsAppTheme { MapScreen(locationPermissionGranted = true) } | ||
} | ||
// Verify that the map is displayed when permission is granted | ||
composeTestRule.onNodeWithTag("MapView").assertExists() | ||
} | ||
|
||
@Test | ||
fun testMapScreenWithoutPermission() { | ||
composeTestRule.setContent { | ||
PeriodPalsAppTheme { MapScreen(locationPermissionGranted = false) } | ||
} | ||
// Verify that the map is still displayed even if permission is not granted | ||
composeTestRule.onNodeWithTag("MapView").assertExists() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
app/src/main/java/com/android/periodpals/model/auth/AuthViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.android.periodpals.model.auth | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import androidx.compose.runtime.State | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.android.periodpals.model.user.UserAuthState | ||
import kotlinx.coroutines.launch | ||
|
||
private const val TAG = "AuthViewModel" | ||
|
||
class AuthViewModel(private val authModel: AuthModel) : ViewModel() { | ||
|
||
private val _userAuthState = mutableStateOf<UserAuthState>(UserAuthState.Loading) | ||
val userAuthState: State<UserAuthState> = _userAuthState | ||
|
||
fun signUpWithEmail(context: Context, userEmail: String, userPassword: String) { | ||
_userAuthState.value = UserAuthState.Loading | ||
viewModelScope.launch { | ||
authModel.register( | ||
userEmail = userEmail, | ||
userPassword = userPassword, | ||
onSuccess = { | ||
Log.d(TAG, "signUpWithEmail: registered user successfully") | ||
_userAuthState.value = UserAuthState.Success("Registered user successfully") | ||
}, | ||
onFailure = { e: Exception -> | ||
Log.d(TAG, "signUpWithEmail: failed to register user: $e") | ||
_userAuthState.value = UserAuthState.Error("Error: $e") | ||
}, | ||
) | ||
} | ||
} | ||
|
||
fun logInWithEmail(context: Context, userEmail: String, userPassword: String) { | ||
_userAuthState.value = UserAuthState.Loading | ||
viewModelScope.launch { | ||
authModel.login( | ||
userEmail = userEmail, | ||
userPassword = userPassword, | ||
onSuccess = { | ||
Log.d(TAG, "logInWithEmail: logged in successfully") | ||
_userAuthState.value = UserAuthState.Success("Logged in successfully") | ||
}, | ||
onFailure = { e: Exception -> | ||
Log.d(TAG, "logInWithEmail: failed to log in: $e") | ||
_userAuthState.value = UserAuthState.Error("Error: $e") | ||
}, | ||
) | ||
} | ||
} | ||
|
||
fun logOut(context: Context) { | ||
// val sharedPreferenceHelper = SharedPreferenceHelper(context) | ||
_userAuthState.value = UserAuthState.Loading | ||
viewModelScope.launch { | ||
authModel.logout( | ||
onSuccess = { | ||
Log.d(TAG, "logOut: logged out successfully") | ||
// sharedPreferenceHelper.clearPreferences() | ||
_userAuthState.value = UserAuthState.Success("Logged out successfully") | ||
}, | ||
onFailure = { e: Exception -> | ||
Log.d(TAG, "logOut: failed to log out: $e") | ||
_userAuthState.value = UserAuthState.Error("Error: $e") | ||
}, | ||
) | ||
} | ||
} | ||
|
||
fun isUserLoggedIn(context: Context) { | ||
viewModelScope.launch { | ||
// call model for this ofc | ||
authModel.isUserLoggedIn( | ||
token = "", | ||
onSuccess = { | ||
Log.d(TAG, "isUserLoggedIn: user is confirmed logged in") | ||
_userAuthState.value = UserAuthState.Success("User is logged in") | ||
}, | ||
onFailure = { | ||
Log.d(TAG, "isUserLoggedIn: user is not logged in") | ||
_userAuthState.value = UserAuthState.Error("User is not logged in") | ||
}) | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/android/periodpals/model/user/UserAuthState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.android.periodpals.model.user | ||
|
||
sealed class UserAuthState { | ||
data object Loading : UserAuthState() | ||
|
||
data class Success(val message: String) : UserAuthState() | ||
|
||
data class Error(val message: String) : UserAuthState() | ||
} |
Oops, something went wrong.