mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 06:37:30 +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:
parent
6e2e3c139c
commit
29d2b894d8
@ -36,7 +36,7 @@ import awais.instagrabber.utils.CookieUtils;
|
|||||||
import awais.instagrabber.utils.CoroutineUtilsKt;
|
import awais.instagrabber.utils.CoroutineUtilsKt;
|
||||||
import awais.instagrabber.utils.DownloadUtils;
|
import awais.instagrabber.utils.DownloadUtils;
|
||||||
import awais.instagrabber.utils.TextUtils;
|
import awais.instagrabber.utils.TextUtils;
|
||||||
import awais.instagrabber.webservices.UserService;
|
import awais.instagrabber.webservices.UserRepository;
|
||||||
import kotlinx.coroutines.Dispatchers;
|
import kotlinx.coroutines.Dispatchers;
|
||||||
|
|
||||||
import static awais.instagrabber.utils.Utils.settingsHelper;
|
import static awais.instagrabber.utils.Utils.settingsHelper;
|
||||||
@ -132,8 +132,8 @@ public class ProfilePicDialogFragment extends DialogFragment {
|
|||||||
|
|
||||||
private void fetchAvatar() {
|
private void fetchAvatar() {
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
final UserService userService = UserService.INSTANCE;
|
final UserRepository repository = UserRepository.INSTANCE;
|
||||||
userService.getUserInfo(id, CoroutineUtilsKt.getContinuation((user, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
|
repository.getUserInfo(id, CoroutineUtilsKt.getContinuation((user, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
|
@ -96,7 +96,7 @@ import awais.instagrabber.webservices.GraphQLService;
|
|||||||
import awais.instagrabber.webservices.MediaService;
|
import awais.instagrabber.webservices.MediaService;
|
||||||
import awais.instagrabber.webservices.ServiceCallback;
|
import awais.instagrabber.webservices.ServiceCallback;
|
||||||
import awais.instagrabber.webservices.StoriesService;
|
import awais.instagrabber.webservices.StoriesService;
|
||||||
import awais.instagrabber.webservices.UserService;
|
import awais.instagrabber.webservices.UserRepository;
|
||||||
import kotlinx.coroutines.Dispatchers;
|
import kotlinx.coroutines.Dispatchers;
|
||||||
|
|
||||||
import static androidx.core.content.PermissionChecker.checkSelfPermission;
|
import static androidx.core.content.PermissionChecker.checkSelfPermission;
|
||||||
@ -120,7 +120,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
private FriendshipService friendshipService;
|
private FriendshipService friendshipService;
|
||||||
private StoriesService storiesService;
|
private StoriesService storiesService;
|
||||||
private MediaService mediaService;
|
private MediaService mediaService;
|
||||||
private UserService userService;
|
private UserRepository userRepository;
|
||||||
private GraphQLService graphQLService;
|
private GraphQLService graphQLService;
|
||||||
private DirectMessagesService directMessagesService;
|
private DirectMessagesService directMessagesService;
|
||||||
private boolean shouldRefresh = true;
|
private boolean shouldRefresh = true;
|
||||||
@ -336,7 +336,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
directMessagesService = isLoggedIn ? DirectMessagesService.INSTANCE : null;
|
directMessagesService = isLoggedIn ? DirectMessagesService.INSTANCE : null;
|
||||||
storiesService = isLoggedIn ? StoriesService.INSTANCE : null;
|
storiesService = isLoggedIn ? StoriesService.INSTANCE : null;
|
||||||
mediaService = isLoggedIn ? MediaService.INSTANCE : null;
|
mediaService = isLoggedIn ? MediaService.INSTANCE : null;
|
||||||
userService = isLoggedIn ? UserService.INSTANCE : null;
|
userRepository = isLoggedIn ? UserRepository.INSTANCE : null;
|
||||||
graphQLService = isLoggedIn ? null : GraphQLService.INSTANCE;
|
graphQLService = isLoggedIn ? null : GraphQLService.INSTANCE;
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
if (context == null) return;
|
if (context == null) return;
|
||||||
@ -629,7 +629,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
userService.getUsernameInfo(
|
userRepository.getUsernameInfo(
|
||||||
usernameTemp,
|
usernameTemp,
|
||||||
CoroutineUtilsKt.getContinuation((user, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
|
CoroutineUtilsKt.getContinuation((user, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
@ -639,7 +639,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
Toast.makeText(context, throwable.getMessage(), Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, throwable.getMessage(), Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
userService.getUserFriendship(
|
userRepository.getUserFriendship(
|
||||||
user.getPk(),
|
user.getPk(),
|
||||||
CoroutineUtilsKt.getContinuation(
|
CoroutineUtilsKt.getContinuation(
|
||||||
(friendshipStatus, throwable1) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
|
(friendshipStatus, throwable1) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
|
||||||
|
@ -39,7 +39,7 @@ import awais.instagrabber.utils.FlavorTown;
|
|||||||
import awais.instagrabber.utils.ProcessPhoenix;
|
import awais.instagrabber.utils.ProcessPhoenix;
|
||||||
import awais.instagrabber.utils.TextUtils;
|
import awais.instagrabber.utils.TextUtils;
|
||||||
import awais.instagrabber.utils.Utils;
|
import awais.instagrabber.utils.Utils;
|
||||||
import awais.instagrabber.webservices.UserService;
|
import awais.instagrabber.webservices.UserRepository;
|
||||||
import kotlinx.coroutines.Dispatchers;
|
import kotlinx.coroutines.Dispatchers;
|
||||||
|
|
||||||
import static awais.instagrabber.utils.Utils.settingsHelper;
|
import static awais.instagrabber.utils.Utils.settingsHelper;
|
||||||
@ -285,8 +285,8 @@ public class MorePreferencesFragment extends BasePreferencesFragment {
|
|||||||
|
|
||||||
// adds cookies to database for quick access
|
// adds cookies to database for quick access
|
||||||
final long uid = CookieUtils.getUserIdFromCookie(cookie);
|
final long uid = CookieUtils.getUserIdFromCookie(cookie);
|
||||||
final UserService userService = UserService.INSTANCE;
|
final UserRepository userRepository = UserRepository.INSTANCE;
|
||||||
userService.getUserInfo(uid, CoroutineUtilsKt.getContinuation((user, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
|
userRepository.getUserInfo(uid, CoroutineUtilsKt.getContinuation((user, throwable) -> AppExecutors.INSTANCE.getMainThread().execute(() -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
Log.e(TAG, "Error fetching user info", throwable);
|
Log.e(TAG, "Error fetching user info", throwable);
|
||||||
return;
|
return;
|
||||||
|
@ -7,7 +7,7 @@ import retrofit2.http.GET
|
|||||||
import retrofit2.http.Path
|
import retrofit2.http.Path
|
||||||
import retrofit2.http.Query
|
import retrofit2.http.Query
|
||||||
|
|
||||||
interface UserRepository {
|
interface UserService {
|
||||||
@GET("/api/v1/users/{uid}/info/")
|
@GET("/api/v1/users/{uid}/info/")
|
||||||
suspend fun getUserInfo(@Path("uid") uid: Long): WrappedUser
|
suspend fun getUserInfo(@Path("uid") uid: Long): WrappedUser
|
||||||
|
|
@ -14,7 +14,7 @@ import awais.instagrabber.utils.Constants;
|
|||||||
import awais.instagrabber.utils.CookieUtils;
|
import awais.instagrabber.utils.CookieUtils;
|
||||||
import awais.instagrabber.utils.CoroutineUtilsKt;
|
import awais.instagrabber.utils.CoroutineUtilsKt;
|
||||||
import awais.instagrabber.utils.TextUtils;
|
import awais.instagrabber.utils.TextUtils;
|
||||||
import awais.instagrabber.webservices.UserService;
|
import awais.instagrabber.webservices.UserRepository;
|
||||||
import kotlinx.coroutines.Dispatchers;
|
import kotlinx.coroutines.Dispatchers;
|
||||||
|
|
||||||
import static awais.instagrabber.utils.Utils.settingsHelper;
|
import static awais.instagrabber.utils.Utils.settingsHelper;
|
||||||
@ -25,7 +25,7 @@ public class AppStateViewModel extends AndroidViewModel {
|
|||||||
private final String cookie;
|
private final String cookie;
|
||||||
private final MutableLiveData<User> currentUser = new MutableLiveData<>();
|
private final MutableLiveData<User> currentUser = new MutableLiveData<>();
|
||||||
|
|
||||||
private UserService userService;
|
private UserRepository userRepository;
|
||||||
|
|
||||||
public AppStateViewModel(@NonNull final Application application) {
|
public AppStateViewModel(@NonNull final Application application) {
|
||||||
super(application);
|
super(application);
|
||||||
@ -33,7 +33,7 @@ public class AppStateViewModel extends AndroidViewModel {
|
|||||||
cookie = settingsHelper.getString(Constants.COOKIE);
|
cookie = settingsHelper.getString(Constants.COOKIE);
|
||||||
final boolean isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != 0;
|
final boolean isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != 0;
|
||||||
if (!isLoggedIn) return;
|
if (!isLoggedIn) return;
|
||||||
userService = UserService.INSTANCE;
|
userRepository = UserRepository.INSTANCE;
|
||||||
// final AccountRepository accountRepository = AccountRepository.getInstance(AccountDataSource.getInstance(application));
|
// final AccountRepository accountRepository = AccountRepository.getInstance(AccountDataSource.getInstance(application));
|
||||||
fetchProfileDetails();
|
fetchProfileDetails();
|
||||||
}
|
}
|
||||||
@ -49,8 +49,8 @@ public class AppStateViewModel extends AndroidViewModel {
|
|||||||
|
|
||||||
private void fetchProfileDetails() {
|
private void fetchProfileDetails() {
|
||||||
final long uid = CookieUtils.getUserIdFromCookie(cookie);
|
final long uid = CookieUtils.getUserIdFromCookie(cookie);
|
||||||
if (userService == null) return;
|
if (userRepository == null) return;
|
||||||
userService.getUserInfo(uid, CoroutineUtilsKt.getContinuation((user, throwable) -> {
|
userRepository.getUserInfo(uid, CoroutineUtilsKt.getContinuation((user, throwable) -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
Log.e(TAG, "onFailure: ", throwable);
|
Log.e(TAG, "onFailure: ", throwable);
|
||||||
return;
|
return;
|
||||||
|
@ -32,7 +32,7 @@ import awais.instagrabber.utils.Debouncer;
|
|||||||
import awais.instagrabber.utils.RankedRecipientsCache;
|
import awais.instagrabber.utils.RankedRecipientsCache;
|
||||||
import awais.instagrabber.utils.TextUtils;
|
import awais.instagrabber.utils.TextUtils;
|
||||||
import awais.instagrabber.webservices.DirectMessagesService;
|
import awais.instagrabber.webservices.DirectMessagesService;
|
||||||
import awais.instagrabber.webservices.UserService;
|
import awais.instagrabber.webservices.UserRepository;
|
||||||
import kotlinx.coroutines.Dispatchers;
|
import kotlinx.coroutines.Dispatchers;
|
||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
@ -58,7 +58,7 @@ public class UserSearchViewModel extends ViewModel {
|
|||||||
private final MutableLiveData<Boolean> showAction = new MutableLiveData<>(false);
|
private final MutableLiveData<Boolean> showAction = new MutableLiveData<>(false);
|
||||||
private final Debouncer<String> searchDebouncer;
|
private final Debouncer<String> searchDebouncer;
|
||||||
private final Set<RankedRecipient> selectedRecipients = new HashSet<>();
|
private final Set<RankedRecipient> selectedRecipients = new HashSet<>();
|
||||||
private final UserService userService;
|
private final UserRepository userRepository;
|
||||||
private final DirectMessagesService directMessagesService;
|
private final DirectMessagesService directMessagesService;
|
||||||
private final RankedRecipientsCache rankedRecipientsCache;
|
private final RankedRecipientsCache rankedRecipientsCache;
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ public class UserSearchViewModel extends ViewModel {
|
|||||||
if (TextUtils.isEmpty(csrfToken) || viewerId <= 0 || TextUtils.isEmpty(deviceUuid)) {
|
if (TextUtils.isEmpty(csrfToken) || viewerId <= 0 || TextUtils.isEmpty(deviceUuid)) {
|
||||||
throw new IllegalArgumentException("User is not logged in!");
|
throw new IllegalArgumentException("User is not logged in!");
|
||||||
}
|
}
|
||||||
userService = UserService.INSTANCE;
|
userRepository = UserRepository.INSTANCE;
|
||||||
directMessagesService = DirectMessagesService.INSTANCE;
|
directMessagesService = DirectMessagesService.INSTANCE;
|
||||||
rankedRecipientsCache = RankedRecipientsCache.INSTANCE;
|
rankedRecipientsCache = RankedRecipientsCache.INSTANCE;
|
||||||
if ((rankedRecipientsCache.isFailed() || rankedRecipientsCache.isExpired()) && !rankedRecipientsCache.isUpdateInitiated()) {
|
if ((rankedRecipientsCache.isFailed() || rankedRecipientsCache.isExpired()) && !rankedRecipientsCache.isUpdateInitiated()) {
|
||||||
@ -168,7 +168,7 @@ public class UserSearchViewModel extends ViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void defaultUserSearch() {
|
private void defaultUserSearch() {
|
||||||
userService.search(currentQuery, CoroutineUtilsKt.getContinuation((userSearchResponse, throwable) -> {
|
userRepository.search(currentQuery, CoroutineUtilsKt.getContinuation((userSearchResponse, throwable) -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
Log.e(TAG, "onFailure: ", throwable);
|
Log.e(TAG, "onFailure: ", throwable);
|
||||||
recipients.postValue(Resource.error(throwable.getMessage(), getCachedRecipients()));
|
recipients.postValue(Resource.error(throwable.getMessage(), getCachedRecipients()));
|
||||||
|
@ -1,29 +1,29 @@
|
|||||||
package awais.instagrabber.webservices
|
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.FriendshipStatus
|
||||||
import awais.instagrabber.repositories.responses.User
|
import awais.instagrabber.repositories.responses.User
|
||||||
import awais.instagrabber.repositories.responses.UserSearchResponse
|
import awais.instagrabber.repositories.responses.UserSearchResponse
|
||||||
import awais.instagrabber.webservices.RetrofitFactory.retrofit
|
import awais.instagrabber.webservices.RetrofitFactory.retrofit
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
object UserService : BaseService() {
|
object UserRepository : BaseService() {
|
||||||
private val repository: UserRepository = retrofit.create(UserRepository::class.java)
|
private val service: UserService = retrofit.create(UserService::class.java)
|
||||||
|
|
||||||
suspend fun getUserInfo(uid: Long): User {
|
suspend fun getUserInfo(uid: Long): User {
|
||||||
val response = repository.getUserInfo(uid)
|
val response = service.getUserInfo(uid)
|
||||||
return response.user
|
return response.user
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getUsernameInfo(username: String): User {
|
suspend fun getUsernameInfo(username: String): User {
|
||||||
val response = repository.getUsernameInfo(username)
|
val response = service.getUsernameInfo(username)
|
||||||
return response.user
|
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 {
|
suspend fun search(query: String): UserSearchResponse {
|
||||||
val timezoneOffset = TimeZone.getDefault().rawOffset.toFloat() / 1000
|
val timezoneOffset = TimeZone.getDefault().rawOffset.toFloat() / 1000
|
||||||
return repository.search(timezoneOffset, query)
|
return service.search(timezoneOffset, query)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user