1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-12 17:57:29 +00:00

Interchange UserService and UserRepository names. Check description.

As per the sample provided at https://github.com/android/architecture-components-samples/tree/main/GithubBrowserSample, the Retrofit interfaces should be named Services and the classes using the services are Repositories.

Once all are properly named, we can move the db repositories inside the repositories package.
This commit is contained in:
Ammar Githam 2021-06-09 08:40:13 +09:00
parent 6e2e3c139c
commit 29d2b894d8
7 changed files with 28 additions and 28 deletions

View File

@ -36,7 +36,7 @@ import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.CoroutineUtilsKt;
import awais.instagrabber.utils.DownloadUtils;
import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.webservices.UserService;
import awais.instagrabber.webservices.UserRepository;
import kotlinx.coroutines.Dispatchers;
import static awais.instagrabber.utils.Utils.settingsHelper;
@ -132,8 +132,8 @@ public class ProfilePicDialogFragment extends DialogFragment {
private void fetchAvatar() {
if (isLoggedIn) {
final UserService userService = UserService.INSTANCE;
userService.getUserInfo(id, CoroutineUtilsKt.getContinuation((user, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
final UserRepository repository = UserRepository.INSTANCE;
repository.getUserInfo(id, CoroutineUtilsKt.getContinuation((user, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
if (throwable != null) {
final Context context = getContext();
if (context == null) {

View File

@ -96,7 +96,7 @@ import awais.instagrabber.webservices.GraphQLService;
import awais.instagrabber.webservices.MediaService;
import awais.instagrabber.webservices.ServiceCallback;
import awais.instagrabber.webservices.StoriesService;
import awais.instagrabber.webservices.UserService;
import awais.instagrabber.webservices.UserRepository;
import kotlinx.coroutines.Dispatchers;
import static androidx.core.content.PermissionChecker.checkSelfPermission;
@ -120,7 +120,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
private FriendshipService friendshipService;
private StoriesService storiesService;
private MediaService mediaService;
private UserService userService;
private UserRepository userRepository;
private GraphQLService graphQLService;
private DirectMessagesService directMessagesService;
private boolean shouldRefresh = true;
@ -336,7 +336,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
directMessagesService = isLoggedIn ? DirectMessagesService.INSTANCE : null;
storiesService = isLoggedIn ? StoriesService.INSTANCE : null;
mediaService = isLoggedIn ? MediaService.INSTANCE : null;
userService = isLoggedIn ? UserService.INSTANCE : null;
userRepository = isLoggedIn ? UserRepository.INSTANCE : null;
graphQLService = isLoggedIn ? null : GraphQLService.INSTANCE;
final Context context = getContext();
if (context == null) return;
@ -629,7 +629,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
return;
}
if (isLoggedIn) {
userService.getUsernameInfo(
userRepository.getUsernameInfo(
usernameTemp,
CoroutineUtilsKt.getContinuation((user, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
if (throwable != null) {
@ -639,7 +639,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
Toast.makeText(context, throwable.getMessage(), Toast.LENGTH_SHORT).show();
return;
}
userService.getUserFriendship(
userRepository.getUserFriendship(
user.getPk(),
CoroutineUtilsKt.getContinuation(
(friendshipStatus, throwable1) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {

View File

@ -39,7 +39,7 @@ import awais.instagrabber.utils.FlavorTown;
import awais.instagrabber.utils.ProcessPhoenix;
import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.utils.Utils;
import awais.instagrabber.webservices.UserService;
import awais.instagrabber.webservices.UserRepository;
import kotlinx.coroutines.Dispatchers;
import static awais.instagrabber.utils.Utils.settingsHelper;
@ -285,8 +285,8 @@ public class MorePreferencesFragment extends BasePreferencesFragment {
// adds cookies to database for quick access
final long uid = CookieUtils.getUserIdFromCookie(cookie);
final UserService userService = UserService.INSTANCE;
userService.getUserInfo(uid, CoroutineUtilsKt.getContinuation((user, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
final UserRepository userRepository = UserRepository.INSTANCE;
userRepository.getUserInfo(uid, CoroutineUtilsKt.getContinuation((user, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
if (throwable != null) {
Log.e(TAG, "Error fetching user info", throwable);
return;

View File

@ -7,7 +7,7 @@ import retrofit2.http.GET
import retrofit2.http.Path
import retrofit2.http.Query
interface UserRepository {
interface UserService {
@GET("/api/v1/users/{uid}/info/")
suspend fun getUserInfo(@Path("uid") uid: Long): WrappedUser

View File

@ -14,7 +14,7 @@ import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.CoroutineUtilsKt;
import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.webservices.UserService;
import awais.instagrabber.webservices.UserRepository;
import kotlinx.coroutines.Dispatchers;
import static awais.instagrabber.utils.Utils.settingsHelper;
@ -25,7 +25,7 @@ public class AppStateViewModel extends AndroidViewModel {
private final String cookie;
private final MutableLiveData<User> currentUser = new MutableLiveData<>();
private UserService userService;
private UserRepository userRepository;
public AppStateViewModel(@NonNull final Application application) {
super(application);
@ -33,7 +33,7 @@ public class AppStateViewModel extends AndroidViewModel {
cookie = settingsHelper.getString(Constants.COOKIE);
final boolean isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != 0;
if (!isLoggedIn) return;
userService = UserService.INSTANCE;
userRepository = UserRepository.INSTANCE;
// final AccountRepository accountRepository = AccountRepository.getInstance(AccountDataSource.getInstance(application));
fetchProfileDetails();
}
@ -49,8 +49,8 @@ public class AppStateViewModel extends AndroidViewModel {
private void fetchProfileDetails() {
final long uid = CookieUtils.getUserIdFromCookie(cookie);
if (userService == null) return;
userService.getUserInfo(uid, CoroutineUtilsKt.getContinuation((user, throwable) -> {
if (userRepository == null) return;
userRepository.getUserInfo(uid, CoroutineUtilsKt.getContinuation((user, throwable) -> {
if (throwable != null) {
Log.e(TAG, "onFailure: ", throwable);
return;

View File

@ -32,7 +32,7 @@ import awais.instagrabber.utils.Debouncer;
import awais.instagrabber.utils.RankedRecipientsCache;
import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.webservices.DirectMessagesService;
import awais.instagrabber.webservices.UserService;
import awais.instagrabber.webservices.UserRepository;
import kotlinx.coroutines.Dispatchers;
import okhttp3.ResponseBody;
import retrofit2.Call;
@ -58,7 +58,7 @@ public class UserSearchViewModel extends ViewModel {
private final MutableLiveData<Boolean> showAction = new MutableLiveData<>(false);
private final Debouncer<String> searchDebouncer;
private final Set<RankedRecipient> selectedRecipients = new HashSet<>();
private final UserService userService;
private final UserRepository userRepository;
private final DirectMessagesService directMessagesService;
private final RankedRecipientsCache rankedRecipientsCache;
@ -70,7 +70,7 @@ public class UserSearchViewModel extends ViewModel {
if (TextUtils.isEmpty(csrfToken) || viewerId <= 0 || TextUtils.isEmpty(deviceUuid)) {
throw new IllegalArgumentException("User is not logged in!");
}
userService = UserService.INSTANCE;
userRepository = UserRepository.INSTANCE;
directMessagesService = DirectMessagesService.INSTANCE;
rankedRecipientsCache = RankedRecipientsCache.INSTANCE;
if ((rankedRecipientsCache.isFailed() || rankedRecipientsCache.isExpired()) && !rankedRecipientsCache.isUpdateInitiated()) {
@ -168,7 +168,7 @@ public class UserSearchViewModel extends ViewModel {
}
private void defaultUserSearch() {
userService.search(currentQuery, CoroutineUtilsKt.getContinuation((userSearchResponse, throwable) -> {
userRepository.search(currentQuery, CoroutineUtilsKt.getContinuation((userSearchResponse, throwable) -> {
if (throwable != null) {
Log.e(TAG, "onFailure: ", throwable);
recipients.postValue(Resource.error(throwable.getMessage(), getCachedRecipients()));

View File

@ -1,29 +1,29 @@
package awais.instagrabber.webservices
import awais.instagrabber.repositories.UserRepository
import awais.instagrabber.repositories.UserService
import awais.instagrabber.repositories.responses.FriendshipStatus
import awais.instagrabber.repositories.responses.User
import awais.instagrabber.repositories.responses.UserSearchResponse
import awais.instagrabber.webservices.RetrofitFactory.retrofit
import java.util.*
object UserService : BaseService() {
private val repository: UserRepository = retrofit.create(UserRepository::class.java)
object UserRepository : BaseService() {
private val service: UserService = retrofit.create(UserService::class.java)
suspend fun getUserInfo(uid: Long): User {
val response = repository.getUserInfo(uid)
val response = service.getUserInfo(uid)
return response.user
}
suspend fun getUsernameInfo(username: String): User {
val response = repository.getUsernameInfo(username)
val response = service.getUsernameInfo(username)
return response.user
}
suspend fun getUserFriendship(uid: Long): FriendshipStatus = repository.getUserFriendship(uid)
suspend fun getUserFriendship(uid: Long): FriendshipStatus = service.getUserFriendship(uid)
suspend fun search(query: String): UserSearchResponse {
val timezoneOffset = TimeZone.getDefault().rawOffset.toFloat() / 1000
return repository.search(timezoneOffset, query)
return service.search(timezoneOffset, query)
}
}