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
class UserRepository(private val userService: UserService) { | |
fun getUsers(page: Int) = userService.getUsers(page) | |
fun getDetails(userId: Long) : Single<DetailsModel> { | |
// TODO We will implement this method | |
return Single.create { emitter -> | |
val detailsModel = DetailsModel(emptyList(), emptyList(), emptyList()) | |
emitter.onSuccess(detailsModel) | |
} |
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
class UserRepository( | |
private val userService: UserService) { | |
fun getUsers(page: Int) = userService.getUsers(page) | |
fun getDetails(userId: Long) : Single<DetailsModel> { | |
return Single.zip( | |
userService.getQuestionsByUser(userId), | |
userService.getAnswersByUser(userId), | |
userService.getFavoritesByUser(userId), |
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
class UserRepository( | |
private val userService: UserService, | |
private val questionService: QuestionService) { | |
fun getUsers(page: Int) = userService.getUsers(page) | |
fun getDetails(userId: Long) : Single<DetailsModel> { | |
return Single.zip( | |
userService.getQuestionsByUser(userId), | |
getAnswers(userId), |
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
@Dao | |
interface UserDao { | |
@Query("SELECT * FROM user ORDER BY reputation DESC LIMIT (:arg0 - 1) * 30, 30") | |
fun getUsers(page: Int) : List<User> | |
@Insert(onConflict = OnConflictStrategy.REPLACE) | |
fun insertAll(users: List<User>) | |
} |
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
@RunWith(AndroidJUnit4::class) | |
class UserDaoTest { | |
lateinit var userDao: UserDao | |
lateinit var database: AppDatabase | |
@Before | |
fun setup() { | |
val context = InstrumentationRegistry.getTargetContext() | |
database = Room.inMemoryDatabaseBuilder(context, AppDatabase::class.java).build() |
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
class UserRepository( | |
private val userService: UserService, | |
private val userDao: UserDao, | |
private val connectionHelper: ConnectionHelper, | |
private val preferencesHelper: PreferencesHelper, | |
private val calendarWrapper: CalendarWrapper) { | |
private val LAST_UPDATE_KEY = "last_update_page_" | |
fun getUsers(page: Int, forced: Boolean): Single<UserListModel> { |
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
class UserRepositoryTest { | |
@Mock | |
lateinit var mockUserService: UserService | |
@Mock | |
lateinit var mockUserDao: UserDao | |
@Mock | |
lateinit var mockConnectionHelper: ConnectionHelper |
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
class GetUsersTest { | |
@Mock | |
lateinit var mockUserRepository: UserRepository | |
lateinit var getUsers: GetUsers | |
@Before | |
fun setup() { | |
MockitoAnnotations.initMocks(this) |
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
class GetUsers(private val userRepository: UserRepository) { | |
fun execute(page: Int, forced: Boolean) : Single<List<UserViewModel>> { | |
val usersList = userRepository.getUsers(page, forced) | |
return usersList.map { userListModel: UserListModel? -> | |
val items = userListModel?.items ?: emptyList() | |
items.map { UserViewModel(it.userId, it.displayName, it.reputation, it.profileImage) } | |
} | |
} | |
} |
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
class UserListPresenter( | |
private val getUsers: GetUsers) : BasePresenter<UserListView>() { | |
private val offset = 5 | |
private var page = 1 | |
private var loading = false | |
fun getUsers(forced: Boolean = false) { | |
loading = true |
OlderNewer