forked from commons-app/apps-android-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrated from Rxjava to Retroift, added MVVM Architecture.
- Loading branch information
1 parent
f1e8e48
commit 614892c
Showing
10 changed files
with
302 additions
and
203 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
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
23 changes: 23 additions & 0 deletions
23
app/src/main/java/fr/free/nrw/commons/network/APIService.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,23 @@ | ||
package fr.free.nrw.commons.network | ||
|
||
import fr.free.nrw.commons.profile.model.AchievementResponse | ||
import retrofit2.Response | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
|
||
interface APIService { | ||
|
||
// https://tools.wmflabs.org/commons-android-app/tool-commons-android-app/uploadsbyuser.py?user=Devanonymous | ||
@GET("uploadsbyuser.py") | ||
suspend fun getImageUploadCount( | ||
@Query("user") username : String | ||
) : Response<Int> | ||
|
||
|
||
// https://tools.wmflabs.org/commons-android-app/tool-commons-android-app//feedback.py?user=Devanonymous | ||
@GET("feedback.py") | ||
suspend fun getUserAchievements( | ||
@Query("user") username: String | ||
) : Response<AchievementResponse> | ||
} |
41 changes: 41 additions & 0 deletions
41
app/src/main/java/fr/free/nrw/commons/profile/achievements/AchievementViewModel.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,41 @@ | ||
package fr.free.nrw.commons.profile.achievements | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import fr.free.nrw.commons.profile.model.UserAchievements | ||
import fr.free.nrw.commons.repository.ProfileRepository | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
class AchievementViewModel @Inject constructor( | ||
private val repository: ProfileRepository | ||
) : ViewModel() { | ||
|
||
private val _achievements = MutableStateFlow(UserAchievements( | ||
LevelController.LevelInfo.LEVEL_1, | ||
articlesUsingImagesCount = 0, | ||
thanksReceivedCount = 0, | ||
featuredImagesCount = 0, | ||
qualityImagesCount = 0, | ||
imagesUploadedCount = 0, | ||
revertedCount = 0, | ||
uniqueImagesCount = 0, | ||
imagesEditedBySomeoneElseCount = 0 | ||
) | ||
) | ||
val achievements : StateFlow<UserAchievements> = _achievements | ||
|
||
private val _loading = MutableStateFlow(true) | ||
val loading : StateFlow<Boolean> = _loading | ||
|
||
fun getUserAchievements(username: String){ | ||
viewModelScope.launch { | ||
repository.getUserLevel(username = username).collect { | ||
_loading.value = false | ||
_achievements.value = it | ||
} | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/fr/free/nrw/commons/profile/achievements/AchievementViewModelFactory.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,23 @@ | ||
package fr.free.nrw.commons.profile.achievements | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import javax.inject.Inject | ||
import javax.inject.Provider | ||
|
||
/** | ||
* This class extends the ViewModelProvider.Factory and creates a ViewModelFactory class | ||
* for AchievementViewModel | ||
*/ | ||
class AchievementViewModelFactory @Inject constructor( | ||
private val viewModelProvider: Provider<AchievementViewModel> | ||
): ViewModelProvider.Factory { | ||
override fun <T : ViewModel> create(modelClass: Class<T>): T { | ||
if (modelClass.isAssignableFrom(AchievementViewModel::class.java)) { | ||
(@Suppress("UNCHECKED_CAST") | ||
return viewModelProvider.get() as T) | ||
} else { | ||
throw IllegalArgumentException("Unknown class name") | ||
} | ||
} | ||
} |
Oops, something went wrong.