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.
Convert profile package to kotlin (commons-app#5979)
* Convert ViewModelFactory to kotlin * Convert UpdateAvatarResponse and related test to Kotlin * Convert LeaderboardResponse and related test to kotlin * Convert LeaderboardListAdapter to kotlin * Convert UserDetailAdapter to kotlin * Convert LeaderboardListViewModel to kotlin * Convert DataSourceClass to kotlin * Convert the LeaderboardFragment to kotlin * Converted AchievementsFragment to kotlin * Revert "Converted AchievementsFragment to kotlin" This reverts commit 4fcbb81. --------- Co-authored-by: Nicolas Raoul <[email protected]>
- Loading branch information
1 parent
8265cc6
commit 33548fa
Showing
26 changed files
with
1,042 additions
and
1,694 deletions.
There are no files selected for viewing
125 changes: 0 additions & 125 deletions
125
app/src/main/java/fr/free/nrw/commons/profile/leaderboard/DataSourceClass.java
This file was deleted.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
app/src/main/java/fr/free/nrw/commons/profile/leaderboard/DataSourceClass.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,79 @@ | ||
package fr.free.nrw.commons.profile.leaderboard | ||
|
||
import android.accounts.Account | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.paging.PageKeyedDataSource | ||
import fr.free.nrw.commons.auth.SessionManager | ||
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient | ||
import fr.free.nrw.commons.profile.leaderboard.LeaderboardConstants.LoadingStatus.LOADING | ||
import fr.free.nrw.commons.profile.leaderboard.LeaderboardConstants.LoadingStatus.LOADED | ||
import io.reactivex.disposables.CompositeDisposable | ||
import io.reactivex.disposables.Disposable | ||
import timber.log.Timber | ||
import java.util.Objects | ||
|
||
/** | ||
* This class will call the leaderboard API to get new list when the pagination is performed | ||
*/ | ||
class DataSourceClass( | ||
private val okHttpJsonApiClient: OkHttpJsonApiClient, | ||
private val sessionManager: SessionManager, | ||
private val duration: String?, | ||
private val category: String?, | ||
private val limit: Int, | ||
private val offset: Int | ||
) : PageKeyedDataSource<Int, LeaderboardList>() { | ||
val progressLiveStatus: MutableLiveData<LeaderboardConstants.LoadingStatus> = MutableLiveData() | ||
private val compositeDisposable = CompositeDisposable() | ||
|
||
|
||
override fun loadInitial( | ||
params: LoadInitialParams<Int>, callback: LoadInitialCallback<Int, LeaderboardList?> | ||
) { | ||
compositeDisposable.add(okHttpJsonApiClient.getLeaderboard( | ||
sessionManager.currentAccount?.name, | ||
duration, | ||
category, | ||
limit.toString(), | ||
offset.toString() | ||
).doOnSubscribe { disposable: Disposable? -> | ||
compositeDisposable.add(disposable!!) | ||
progressLiveStatus.postValue(LOADING) | ||
}.subscribe({ response: LeaderboardResponse? -> | ||
if (response != null && response.status == 200) { | ||
progressLiveStatus.postValue(LOADED) | ||
callback.onResult(response.leaderboardList!!, null, response.limit) | ||
} | ||
}, { t: Throwable? -> | ||
Timber.e(t, "Fetching leaderboard statistics failed") | ||
progressLiveStatus.postValue(LOADING) | ||
})) | ||
} | ||
|
||
override fun loadBefore( | ||
params: LoadParams<Int>, callback: LoadCallback<Int, LeaderboardList?> | ||
) = Unit | ||
|
||
override fun loadAfter( | ||
params: LoadParams<Int>, callback: LoadCallback<Int, LeaderboardList?> | ||
) { | ||
compositeDisposable.add(okHttpJsonApiClient.getLeaderboard( | ||
Objects.requireNonNull<Account?>(sessionManager.currentAccount).name, | ||
duration, | ||
category, | ||
limit.toString(), | ||
params.key.toString() | ||
).doOnSubscribe { disposable: Disposable? -> | ||
compositeDisposable.add(disposable!!) | ||
progressLiveStatus.postValue(LOADING) | ||
}.subscribe({ response: LeaderboardResponse? -> | ||
if (response != null && response.status == 200) { | ||
progressLiveStatus.postValue(LOADED) | ||
callback.onResult(response.leaderboardList!!, params.key + limit) | ||
} | ||
}, { t: Throwable? -> | ||
Timber.e(t, "Fetching leaderboard statistics failed") | ||
progressLiveStatus.postValue(LOADING) | ||
})) | ||
} | ||
} |
110 changes: 0 additions & 110 deletions
110
app/src/main/java/fr/free/nrw/commons/profile/leaderboard/DataSourceFactory.java
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
app/src/main/java/fr/free/nrw/commons/profile/leaderboard/DataSourceFactory.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,27 @@ | ||
package fr.free.nrw.commons.profile.leaderboard | ||
|
||
import androidx.lifecycle.MutableLiveData | ||
import androidx.paging.DataSource | ||
import fr.free.nrw.commons.auth.SessionManager | ||
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient | ||
|
||
/** | ||
* This class will create a new instance of the data source class on pagination | ||
*/ | ||
class DataSourceFactory( | ||
private val okHttpJsonApiClient: OkHttpJsonApiClient, | ||
private val sessionManager: SessionManager | ||
) : DataSource.Factory<Int, LeaderboardList>() { | ||
val mutableLiveData: MutableLiveData<DataSourceClass> = MutableLiveData() | ||
var duration: String? = null | ||
var category: String? = null | ||
var limit: Int = 0 | ||
var offset: Int = 0 | ||
|
||
/** | ||
* Creates the new instance of data source class | ||
*/ | ||
override fun create(): DataSource<Int, LeaderboardList> = DataSourceClass( | ||
okHttpJsonApiClient, sessionManager, duration, category, limit, offset | ||
).also { mutableLiveData.postValue(it) } | ||
} |
45 changes: 0 additions & 45 deletions
45
app/src/main/java/fr/free/nrw/commons/profile/leaderboard/LeaderboardConstants.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.