Skip to content

Commit

Permalink
feat: cải thiện hiệu suất ứng dụng
Browse files Browse the repository at this point in the history
  • Loading branch information
nqmgaming committed Dec 8, 2024
1 parent a70ac6d commit 99cad73
Show file tree
Hide file tree
Showing 38 changed files with 438 additions and 209 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ dependencies {
ksp(libs.androidx.room.compiler)
implementation(libs.compose.charts)

implementation(libs.androidx.credentials)
implementation(libs.androidx.credentials.play.services.auth)
implementation(libs.googleid)

implementation(libs.play.services.ads)

implementation(projects.composeCardstack)
Expand Down
2 changes: 1 addition & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-if class androidx.credentials.CredentialManager
-keep class androidx.credentials.playservices.** {
*;
}
}
Binary file modified app/release/app-release.aab
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ class AuthRepositoryImpl @Inject constructor(
updateFullNameRequestModel: UpdateFullNameRequestModel
): Flow<Resources<UpdateFullNameResponseModel>> {
return flow {
emit(Resources.Loading(true))
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
val response = apiService.updateFullName(
token,
Expand All @@ -153,6 +156,9 @@ class AuthRepositoryImpl @Inject constructor(
updateUsernameRequestModel: UpdateUsernameRequestModel
): Flow<Resources<UpdateUsernameResponseModel>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
val response = apiService.updateUsername(
Expand All @@ -173,6 +179,9 @@ class AuthRepositoryImpl @Inject constructor(
updateEmailRequestModel: UpdateEmailRequestModel
): Flow<Resources<UpdateEmailResponseModel>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
val response = apiService.updateEmail(
Expand All @@ -192,6 +201,9 @@ class AuthRepositoryImpl @Inject constructor(
changePasswordRequestModel: ChangePasswordRequestModel
): Flow<Resources<ChangePasswordResponseModel>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
val response = apiService.changePassword(
Expand Down Expand Up @@ -241,6 +253,9 @@ class AuthRepositoryImpl @Inject constructor(
verifyPasswordRequestModel: VerifyPasswordRequestModel
): Flow<Resources<VerifyPasswordResponseModel>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
val response = apiService.verifyPassword(
Expand All @@ -261,8 +276,11 @@ class AuthRepositoryImpl @Inject constructor(
isOwner: Boolean
): Flow<Resources<UserDetailResponseModel>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
emit(Resources.Loading())
val response = apiService.getUserDetail(
token,
userId,
Expand Down Expand Up @@ -299,6 +317,9 @@ class AuthRepositoryImpl @Inject constructor(
updateAvatarRequestModel: UpdateAvatarRequestModel
): Flow<Resources<UpdateAvatarResponseModel>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
val response = apiService.updateAvatar(
Expand All @@ -317,26 +338,34 @@ class AuthRepositoryImpl @Inject constructor(
username: String,
page: Int?
): Flow<PagingData<SearchUserResponseModel>> {
return Pager(
config = PagingConfig(
pageSize = 10,
enablePlaceholders = false
),
pagingSourceFactory = {
UserPagingSource(
userRemoteDataResource,
token,
username
)
return flow {
if (token.isEmpty()) {
return@flow
}
).flow
Pager(
config = PagingConfig(
pageSize = 10,
enablePlaceholders = false
),
pagingSourceFactory = {
UserPagingSource(
userRemoteDataResource,
token,
username
)
}
).flow
}
}

override suspend fun getUserProfile(
token: String,
userId: String
): Flow<Resources<GetUserProfileResponseModel>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
val response = apiService.getUserProfile(token, userId)
Expand All @@ -353,6 +382,9 @@ class AuthRepositoryImpl @Inject constructor(
changeRoleRequestModel: ChangeRoleRequestModel
): Flow<Resources<ChangeRoleResponseModel>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
val response = apiService.changeRole(
Expand All @@ -372,6 +404,9 @@ class AuthRepositoryImpl @Inject constructor(
updateCoinRequestModel: UpdateCoinRequestModel
): Flow<Resources<UpdateCoinResponseModel>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
val response = apiService.updateCoin(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ class ClassRepositoryImpl @Inject constructor(
createClassRequestModel: CreateClassRequestModel
): Flow<Resources<CreateClassResponseModel>> {
return flow {
emit(Resources.Loading(true))
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
val response = apiService.createClass(
token, createClassRequestModel.toDto()
Expand All @@ -57,6 +60,9 @@ class ClassRepositoryImpl @Inject constructor(
classId: String
): Flow<Resources<GetClassDetailResponseModel>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
val response = apiService.getClassByID(
Expand All @@ -80,6 +86,9 @@ class ClassRepositoryImpl @Inject constructor(
studySetId: String?
): Flow<Resources<List<GetClassByOwnerResponseModel>>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
val response = apiService.getClassByOwnerID(token, userId, folderId, studySetId)
Expand All @@ -98,6 +107,9 @@ class ClassRepositoryImpl @Inject constructor(
updateClassRequestModel: UpdateClassRequestModel
): Flow<Resources<UpdateClassResponseModel>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
val response = apiService.updateClass(
Expand All @@ -114,6 +126,9 @@ class ClassRepositoryImpl @Inject constructor(

override suspend fun deleteClass(token: String, classId: String): Flow<Resources<Unit>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
apiService.deleteClass(
Expand All @@ -132,19 +147,24 @@ class ClassRepositoryImpl @Inject constructor(
title: String,
page: Int?
): Flow<PagingData<GetClassByOwnerResponseModel>> {
return Pager(
config = PagingConfig(
pageSize = 10,
enablePlaceholders = false
),
pagingSourceFactory = {
ClassPagingSource(
classRemoteDataSource,
token,
title
)
return flow {
if (token.isEmpty()) {
return@flow
}
).flow
Pager(
config = PagingConfig(
pageSize = 10,
enablePlaceholders = false
),
pagingSourceFactory = {
ClassPagingSource(
classRemoteDataSource,
token,
title
)
}
).flow
}
}

override suspend fun getClassByCode(
Expand All @@ -153,15 +173,16 @@ class ClassRepositoryImpl @Inject constructor(
classCode: String
): Flow<Resources<GetClassDetailResponseModel>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
Timber.d("getClassByCode: token: $token, userId: $userId, classCode: $classCode")
val response = apiService.getClassByJoinToken(
token = token,
userId = userId,
joinToken = classCode
)
Timber.d("getClassByCode: $response")
emit(Resources.Success(response.toModel()))
} catch (e: Exception) {
Timber.e(e)
Expand All @@ -175,6 +196,9 @@ class ClassRepositoryImpl @Inject constructor(
joinClassRequestModel: JoinClassRequestModel
): Flow<Resources<Unit>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
apiService.joinClass(token, joinClassRequestModel.toDto())
Expand All @@ -191,6 +215,9 @@ class ClassRepositoryImpl @Inject constructor(
exitClassRequestModel: ExitClassRequestModel
): Flow<Resources<Unit>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
apiService.exitClass(token, exitClassRequestModel.toDto())
Expand All @@ -207,6 +234,9 @@ class ClassRepositoryImpl @Inject constructor(
removeMembersRequestModel: RemoveMembersRequestModel
): Flow<Resources<Unit>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
apiService.removeMembers(token, removeMembersRequestModel.toDto())
Expand All @@ -223,6 +253,9 @@ class ClassRepositoryImpl @Inject constructor(
deleteStudySetsRequestModel: DeleteStudySetsRequestModel
): Flow<Resources<Unit>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
apiService.deleteStudySetInClass(token, deleteStudySetsRequestModel.toDto())
Expand All @@ -239,6 +272,9 @@ class ClassRepositoryImpl @Inject constructor(
deleteFolderRequestModel: DeleteFolderRequestModel
): Flow<Resources<Unit>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
apiService.deleteFolderInClass(token, deleteFolderRequestModel.toDto())
Expand All @@ -255,6 +291,9 @@ class ClassRepositoryImpl @Inject constructor(
saveRecentAccessClassRequestModel: SaveRecentAccessClassRequestModel
): Flow<Resources<Unit>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
apiService.saveRecentClass(token, saveRecentAccessClassRequestModel.toDto())
Expand All @@ -271,6 +310,9 @@ class ClassRepositoryImpl @Inject constructor(
userId: String
): Flow<Resources<List<GetClassByOwnerResponseModel>>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
val response = apiService.getRecentClass(token, userId)
Expand All @@ -287,6 +329,9 @@ class ClassRepositoryImpl @Inject constructor(
inviteToClassRequestModel: InviteToClassRequestModel
): Flow<Resources<InviteToClassResponseModel>> {
return flow {
if (token.isEmpty()) {
return@flow
}
emit(Resources.Loading())
try {
val response = apiService.inviteUserToClass(
Expand Down
Loading

0 comments on commit 99cad73

Please sign in to comment.