1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-18 04:37:30 +00:00

Complete almost all Profile actions using service

This commit is contained in:
Ammar Githam 2020-08-30 17:55:09 +09:00
parent 40e810e88c
commit 6ee476b590
14 changed files with 390 additions and 90 deletions

View File

@ -114,7 +114,7 @@ public final class SavedViewer extends BaseLanguageActivity implements SwipeRefr
savedBinding.mainPosts.setVisibility(View.VISIBLE); savedBinding.mainPosts.setVisibility(View.VISIBLE);
}); });
final PostModel model = result[result.length - 1]; final PostModel model = result.length > 0 ? result[result.length - 1] : null;
if (model != null) { if (model != null) {
endCursor = model.getEndCursor(); endCursor = model.getEndCursor();
@ -130,14 +130,13 @@ public final class SavedViewer extends BaseLanguageActivity implements SwipeRefr
} }
model.setPageCursor(false, null); model.setPageCursor(false, null);
} }
} else { }
savedBinding.swipeRefreshLayout.setRefreshing(false); savedBinding.swipeRefreshLayout.setRefreshing(false);
// if (oldSize == 0) { // if (oldSize == 0) {
// Toast.makeText(getApplicationContext(), R.string.empty_list, Toast.LENGTH_SHORT).show(); // Toast.makeText(getApplicationContext(), R.string.empty_list, Toast.LENGTH_SHORT).show();
// finish(); // finish();
// } // }
} }
}
}; };
@Override @Override

View File

@ -103,7 +103,7 @@ public class DirectMessageInboxFragment extends Fragment implements SwipeRefresh
NavHostFragment.findNavController(this).navigate(action); NavHostFragment.findNavController(this).navigate(action);
}); });
inboxList.setAdapter(inboxAdapter); inboxList.setAdapter(inboxAdapter);
listViewModel = new ViewModelProvider(fragmentActivity).get(InboxThreadModelListViewModel.class); listViewModel = new ViewModelProvider(this).get(InboxThreadModelListViewModel.class);
listViewModel.getList().observe(fragmentActivity, inboxAdapter::submitList); listViewModel.getList().observe(fragmentActivity, inboxAdapter::submitList);
initData(); initData();
return root; return root;
@ -127,6 +127,12 @@ public class DirectMessageInboxFragment extends Fragment implements SwipeRefresh
} }
} }
@Override
public void onDestroy() {
super.onDestroy();
listViewModel.getList().postValue(Collections.emptyList());
}
private void initData() { private void initData() {
lazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> { lazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> {
if (!Utils.isEmpty(endCursor)) if (!Utils.isEmpty(endCursor))

View File

@ -59,7 +59,8 @@ import awais.instagrabber.models.ProfileModel;
import awais.instagrabber.models.StoryModel; import awais.instagrabber.models.StoryModel;
import awais.instagrabber.models.enums.DownloadMethod; import awais.instagrabber.models.enums.DownloadMethod;
import awais.instagrabber.models.enums.ItemGetType; import awais.instagrabber.models.enums.ItemGetType;
import awais.instagrabber.repositories.responses.FriendshipRepositoryChangeResponseRootObject; import awais.instagrabber.repositories.responses.FriendshipRepoChangeRootResponse;
import awais.instagrabber.repositories.responses.FriendshipRepoRestrictRootResponse;
import awais.instagrabber.services.FriendshipService; import awais.instagrabber.services.FriendshipService;
import awais.instagrabber.services.ServiceCallback; import awais.instagrabber.services.ServiceCallback;
import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Constants;
@ -222,10 +223,10 @@ public class ProfileFragment extends Fragment {
} }
setupPosts(); setupPosts();
setupCommonListeners(); setupCommonListeners();
fetchProfile(); fetchUsername();
} }
private void fetchProfile() { private void fetchUsername() {
final String uid = Utils.getUserIdFromCookie(cookie); final String uid = Utils.getUserIdFromCookie(cookie);
if (username == null && uid != null) { if (username == null && uid != null) {
final FetchListener<String> fetchListener = username -> { final FetchListener<String> fetchListener = username -> {
@ -339,9 +340,8 @@ public class ProfileFragment extends Fragment {
binding.btnRestrict, binding.btnRestrict,
ColorStateList.valueOf(ContextCompat.getColor(requireContext(), R.color.btn_orange_background))); ColorStateList.valueOf(ContextCompat.getColor(requireContext(), R.color.btn_orange_background)));
} }
if (profileModel.isReallyPrivate()) {
binding.btnBlock.setVisibility(View.VISIBLE); binding.btnBlock.setVisibility(View.VISIBLE);
binding.btnTagged.setVisibility(View.GONE); binding.btnTagged.setVisibility(View.VISIBLE);
if (profileModel.getBlocked()) { if (profileModel.getBlocked()) {
binding.btnBlock.setText(R.string.unblock); binding.btnBlock.setText(R.string.unblock);
ViewCompat.setBackgroundTintList( ViewCompat.setBackgroundTintList(
@ -353,23 +353,6 @@ public class ProfileFragment extends Fragment {
binding.btnBlock, binding.btnBlock,
ColorStateList.valueOf(ContextCompat.getColor(requireContext(), R.color.btn_red_background))); ColorStateList.valueOf(ContextCompat.getColor(requireContext(), R.color.btn_red_background)));
} }
} else {
binding.btnBlock.setVisibility(View.GONE);
binding.btnSaved.setVisibility(View.VISIBLE);
binding.btnTagged.setVisibility(View.VISIBLE);
if (profileModel.getBlocked()) {
binding.btnSaved.setText(R.string.unblock);
ViewCompat.setBackgroundTintList(
binding.btnSaved,
ColorStateList.valueOf(ContextCompat.getColor(requireContext(), R.color.btn_green_background)));
} else {
binding.btnSaved.setText(R.string.block);
ViewCompat.setBackgroundTintList(
binding.btnSaved,
ColorStateList.valueOf(ContextCompat.getColor(requireContext(), R.color.btn_red_background))
);
}
}
} }
} else { } else {
if (Utils.dataBox.getFavorite(username) != null) { if (Utils.dataBox.getFavorite(username) != null) {
@ -511,10 +494,11 @@ public class ProfileFragment extends Fragment {
userIdFromCookie, userIdFromCookie,
profileModel.getId(), profileModel.getId(),
Utils.getCsrfTokenFromCookie(cookie), Utils.getCsrfTokenFromCookie(cookie),
new ServiceCallback<FriendshipRepositoryChangeResponseRootObject>() { new ServiceCallback<FriendshipRepoChangeRootResponse>() {
@Override @Override
public void onSuccess(final FriendshipRepositoryChangeResponseRootObject result) { public void onSuccess(final FriendshipRepoChangeRootResponse result) {
Log.d(TAG, "Unfollow success: " + result); Log.d(TAG, "Unfollow success: " + result);
fetchProfileDetails();
} }
@Override @Override
@ -527,10 +511,11 @@ public class ProfileFragment extends Fragment {
userIdFromCookie, userIdFromCookie,
profileModel.getId(), profileModel.getId(),
Utils.getCsrfTokenFromCookie(cookie), Utils.getCsrfTokenFromCookie(cookie),
new ServiceCallback<FriendshipRepositoryChangeResponseRootObject>() { new ServiceCallback<FriendshipRepoChangeRootResponse>() {
@Override @Override
public void onSuccess(final FriendshipRepositoryChangeResponseRootObject result) { public void onSuccess(final FriendshipRepoChangeRootResponse result) {
Log.d(TAG, "Follow success: " + result); Log.d(TAG, "Follow success: " + result);
fetchProfileDetails();
} }
@Override @Override
@ -543,12 +528,61 @@ public class ProfileFragment extends Fragment {
binding.btnRestrict.setOnClickListener(v -> { binding.btnRestrict.setOnClickListener(v -> {
if (!isLoggedIn) return; if (!isLoggedIn) return;
// restrict final String action = profileModel.getRestricted() ? "Unrestrict" : "Restrict";
// new ProfileAction().execute("restrict"); friendshipService.toggleRestrict(
profileModel.getId(),
!profileModel.getRestricted(),
Utils.getCsrfTokenFromCookie(cookie),
new ServiceCallback<FriendshipRepoRestrictRootResponse>() {
@Override
public void onSuccess(final FriendshipRepoRestrictRootResponse result) {
Log.d(TAG, action + " success: " + result);
fetchProfileDetails();
}
@Override
public void onFailure(final Throwable t) {
Log.e(TAG, "Error while performing " + action, t);
}
});
}); });
binding.btnBlock.setOnClickListener(v -> { binding.btnBlock.setOnClickListener(v -> {
if (!isLoggedIn) return; if (!isLoggedIn) return;
// new MainHelper.ProfileAction().execute("block"); if (profileModel.getBlocked()) {
friendshipService.unblock(
userIdFromCookie,
profileModel.getId(),
Utils.getCsrfTokenFromCookie(cookie),
new ServiceCallback<FriendshipRepoChangeRootResponse>() {
@Override
public void onSuccess(final FriendshipRepoChangeRootResponse result) {
Log.d(TAG, "Unblock success: " + result);
fetchProfileDetails();
}
@Override
public void onFailure(final Throwable t) {
Log.e(TAG, "Error unblocking", t);
}
});
return;
}
friendshipService.block(
userIdFromCookie,
profileModel.getId(),
Utils.getCsrfTokenFromCookie(cookie),
new ServiceCallback<FriendshipRepoChangeRootResponse>() {
@Override
public void onSuccess(final FriendshipRepoChangeRootResponse result) {
Log.d(TAG, "Block success: " + result);
fetchProfileDetails();
}
@Override
public void onFailure(final Throwable t) {
Log.e(TAG, "Error blocking", t);
}
});
}); });
binding.btnSaved.setOnClickListener(v -> startActivity(new Intent(requireContext(), SavedViewer.class) binding.btnSaved.setOnClickListener(v -> startActivity(new Intent(requireContext(), SavedViewer.class)
.putExtra(Constants.EXTRAS_INDEX, "$" + profileModel.getId()) .putExtra(Constants.EXTRAS_INDEX, "$" + profileModel.getId())

View File

@ -1,4 +0,0 @@
package awais.instagrabber.fragments.settings.helpers;
public class AutoSummaryDropDownPreference {
}

View File

@ -2,10 +2,12 @@ package awais.instagrabber.repositories;
import java.util.Map; import java.util.Map;
import awais.instagrabber.repositories.responses.FriendshipRepositoryChangeResponseRootObject; import awais.instagrabber.repositories.responses.FriendshipRepoChangeRootResponse;
import awais.instagrabber.repositories.responses.FriendshipRepoRestrictRootResponse;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.http.FieldMap; import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded; import retrofit2.http.FormUrlEncoded;
import retrofit2.http.Header;
import retrofit2.http.POST; import retrofit2.http.POST;
import retrofit2.http.Path; import retrofit2.http.Path;
@ -13,7 +15,14 @@ public interface FriendshipRepository {
@FormUrlEncoded @FormUrlEncoded
@POST("/api/v1/friendships/{action}/{id}/") @POST("/api/v1/friendships/{action}/{id}/")
Call<FriendshipRepositoryChangeResponseRootObject> change(@Path("action") String action, Call<FriendshipRepoChangeRootResponse> change(@Header("User-Agent") String userAgent,
@Path("action") String action,
@Path("id") String id, @Path("id") String id,
@FieldMap Map<String, String> form); @FieldMap Map<String, String> form);
@FormUrlEncoded
@POST("/api/v1/restrict_action/{action}/")
Call<FriendshipRepoRestrictRootResponse> toggleRestrict(@Header("User-Agent") String userAgent,
@Path("action") String action,
@FieldMap Map<String, String> form);
} }

View File

@ -1,6 +1,8 @@
package awais.instagrabber.repositories.responses; package awais.instagrabber.repositories.responses;
public class FriendshipRepositoryChangeResponseFriendshipStatus { import androidx.annotation.NonNull;
public class FriendshipRepoChangeResponseFriendshipStatus {
private boolean following; private boolean following;
private boolean followedBy; private boolean followedBy;
private boolean blocking; private boolean blocking;
@ -10,7 +12,7 @@ public class FriendshipRepositoryChangeResponseFriendshipStatus {
private boolean outgoingRequest; private boolean outgoingRequest;
private boolean isBestie; private boolean isBestie;
public FriendshipRepositoryChangeResponseFriendshipStatus(final boolean following, public FriendshipRepoChangeResponseFriendshipStatus(final boolean following,
final boolean followedBy, final boolean followedBy,
final boolean blocking, final boolean blocking,
final boolean muting, final boolean muting,
@ -60,6 +62,7 @@ public class FriendshipRepositoryChangeResponseFriendshipStatus {
return isBestie; return isBestie;
} }
@NonNull
@Override @Override
public String toString() { public String toString() {
return "FriendshipRepositoryChangeResponseFriendshipStatus{" + return "FriendshipRepositoryChangeResponseFriendshipStatus{" +

View File

@ -1,15 +1,16 @@
package awais.instagrabber.repositories.responses; package awais.instagrabber.repositories.responses;
public class FriendshipRepositoryChangeResponseRootObject { public class FriendshipRepoChangeRootResponse {
private FriendshipRepositoryChangeResponseFriendshipStatus friendshipStatus; private FriendshipRepoChangeResponseFriendshipStatus friendshipStatus;
private String status; private String status;
public FriendshipRepositoryChangeResponseRootObject(final FriendshipRepositoryChangeResponseFriendshipStatus friendshipStatus, final String status) { public FriendshipRepoChangeRootResponse(final FriendshipRepoChangeResponseFriendshipStatus friendshipStatus,
final String status) {
this.friendshipStatus = friendshipStatus; this.friendshipStatus = friendshipStatus;
this.status = status; this.status = status;
} }
public FriendshipRepositoryChangeResponseFriendshipStatus getFriendshipStatus() { public FriendshipRepoChangeResponseFriendshipStatus getFriendshipStatus() {
return friendshipStatus; return friendshipStatus;
} }

View File

@ -0,0 +1,40 @@
package awais.instagrabber.repositories.responses;
import androidx.annotation.NonNull;
public class FriendshipRepoRestrictResponseFriendshipStatus extends FriendshipRepoChangeResponseFriendshipStatus {
private boolean isRestricted;
public FriendshipRepoRestrictResponseFriendshipStatus(final boolean following,
final boolean followedBy,
final boolean blocking,
final boolean muting,
final boolean isPrivate,
final boolean incomingRequest,
final boolean outgoingRequest,
final boolean isBestie,
final boolean isRestricted) {
super(following, followedBy, blocking, muting, isPrivate, incomingRequest, outgoingRequest, isBestie);
this.isRestricted = isRestricted;
}
public boolean isRestricted() {
return isRestricted;
}
@NonNull
@Override
public String toString() {
return "FriendshipRepoRestrictResponseFriendshipStatus{" +
"following=" + isFollowing() +
", followedBy=" + isFollowedBy() +
", blocking=" + isBlocking() +
", muting=" + isMuting() +
", isPrivate=" + isPrivate() +
", incomingRequest=" + isIncomingRequest() +
", outgoingRequest=" + isOutgoingRequest() +
", isBestie=" + isBestie() +
", isRestricted=" + isRestricted() +
'}';
}
}

View File

@ -0,0 +1,65 @@
package awais.instagrabber.repositories.responses;
import androidx.annotation.NonNull;
public class FriendshipRepoRestrictResponseUsersItem {
private long pk;
private String username;
private String fullName;
private boolean isPrivate;
private String profilePicUrl;
private FriendshipRepoRestrictResponseFriendshipStatus friendshipStatus;
private boolean isVerified;
public FriendshipRepoRestrictResponseUsersItem(final long pk, final String username, final String fullName, final boolean isPrivate, final String profilePicUrl, final FriendshipRepoRestrictResponseFriendshipStatus friendshipStatus, final boolean isVerified) {
this.pk = pk;
this.username = username;
this.fullName = fullName;
this.isPrivate = isPrivate;
this.profilePicUrl = profilePicUrl;
this.friendshipStatus = friendshipStatus;
this.isVerified = isVerified;
}
public long getPk() {
return pk;
}
public String getUsername() {
return username;
}
public String getFullName() {
return fullName;
}
public boolean isPrivate() {
return isPrivate;
}
public String getProfilePicUrl() {
return profilePicUrl;
}
public FriendshipRepoRestrictResponseFriendshipStatus getFriendshipStatus() {
return friendshipStatus;
}
public boolean isVerified() {
return isVerified;
}
@NonNull
@Override
public String toString() {
return "FriendshipRepoRestrictResponseUsersItem{" +
"pk=" + pk +
", username='" + username + '\'' +
", fullName='" + fullName + '\'' +
", isPrivate=" + isPrivate +
", profilePicUrl='" + profilePicUrl + '\'' +
", friendshipStatus=" + friendshipStatus +
", isVerified=" + isVerified +
'}';
}
}

View File

@ -0,0 +1,32 @@
package awais.instagrabber.repositories.responses;
import androidx.annotation.NonNull;
import java.util.List;
public class FriendshipRepoRestrictRootResponse {
private List<FriendshipRepoRestrictResponseUsersItem> users;
private String status;
public FriendshipRepoRestrictRootResponse(final List<FriendshipRepoRestrictResponseUsersItem> users, final String status) {
this.users = users;
this.status = status;
}
public List<FriendshipRepoRestrictResponseUsersItem> getUsers() {
return users;
}
public String getStatus() {
return status;
}
@NonNull
@Override
public String toString() {
return "FriendshipRepoRestrictRootResponse{" +
"users=" + users +
", status='" + status + '\'' +
'}';
}
}

View File

@ -0,0 +1,25 @@
package awais.instagrabber.repositories.responses;
public class LoginRequiredResponse {
private String message = "login_required";
private int logoutReason;
private String status = "fail";
public LoginRequiredResponse(final String message, final int logoutReason, final String status) {
this.message = message;
this.logoutReason = logoutReason;
this.status = status;
}
public String getMessage() {
return message;
}
public int getLogoutReason() {
return logoutReason;
}
public String getStatus() {
return status;
}
}

View File

@ -1,5 +1,10 @@
package awais.instagrabber.services; package awais.instagrabber.services;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import awais.instagrabber.BuildConfig;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import retrofit2.Retrofit; import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.converter.gson.GsonConverterFactory;
@ -11,15 +16,20 @@ public abstract class BaseService {
Retrofit.Builder getRetrofitBuilder() { Retrofit.Builder getRetrofitBuilder() {
if (builder == null) { if (builder == null) {
final OkHttpClient client = new OkHttpClient.Builder() final OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder()
.addInterceptor(new AddCookiesInterceptor()) .addInterceptor(new AddCookiesInterceptor())
.followRedirects(false) .followRedirects(true)
.followSslRedirects(false) .followSslRedirects(true);
.build(); if (BuildConfig.DEBUG) {
// clientBuilder.addInterceptor(new LoggingInterceptor());
}
final Gson gson = new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.create();
builder = new Retrofit.Builder() builder = new Retrofit.Builder()
.addConverterFactory(ScalarsConverterFactory.create()) .addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create(gson))
.client(client); .client(clientBuilder.build());
} }
return builder; return builder;
} }

View File

@ -7,7 +7,9 @@ import java.util.Map;
import java.util.UUID; import java.util.UUID;
import awais.instagrabber.repositories.FriendshipRepository; import awais.instagrabber.repositories.FriendshipRepository;
import awais.instagrabber.repositories.responses.FriendshipRepositoryChangeResponseRootObject; import awais.instagrabber.repositories.responses.FriendshipRepoChangeRootResponse;
import awais.instagrabber.repositories.responses.FriendshipRepoRestrictRootResponse;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
@ -38,40 +40,89 @@ public class FriendshipService extends BaseService {
public void follow(final String userId, public void follow(final String userId,
final String targetUserId, final String targetUserId,
final String crsfToken, final String crsfToken,
final ServiceCallback<FriendshipRepositoryChangeResponseRootObject> callback) { final ServiceCallback<FriendshipRepoChangeRootResponse> callback) {
change("create", userId, targetUserId, crsfToken, callback); change("create", userId, targetUserId, crsfToken, callback);
} }
public void unfollow(final String userId, public void unfollow(final String userId,
final String targetUserId, final String targetUserId,
final String crsfToken, final String crsfToken,
final ServiceCallback<FriendshipRepositoryChangeResponseRootObject> callback) { final ServiceCallback<FriendshipRepoChangeRootResponse> callback) {
change("destroy", userId, targetUserId, crsfToken, callback); change("destroy", userId, targetUserId, crsfToken, callback);
} }
private void change(final String action, public void block(final String userId,
final String userId,
final String targetUserId, final String targetUserId,
final String crsfToken, final String crsfToken,
final ServiceCallback<FriendshipRepositoryChangeResponseRootObject> callback) { final ServiceCallback<FriendshipRepoChangeRootResponse> callback) {
final Map<String, Object> form = new HashMap<>(5); change("block", userId, targetUserId, crsfToken, callback);
form.put("_csrftoken", crsfToken); }
form.put("_uid", userId);
public void unblock(final String userId,
final String targetUserId,
final String crsfToken,
final ServiceCallback<FriendshipRepoChangeRootResponse> callback) {
change("unblock", userId, targetUserId, crsfToken, callback);
}
public void restrict(final String targetUserId,
final String csrfToken,
final ServiceCallback<FriendshipRepoRestrictRootResponse> callback) {
}
public void toggleRestrict(final String targetUserId,
final boolean restrict,
final String csrfToken,
final ServiceCallback<FriendshipRepoRestrictRootResponse> callback) {
final Map<String, String> form = new HashMap<>(3);
form.put("_csrftoken", csrfToken);
form.put("_uuid", UUID.randomUUID().toString()); form.put("_uuid", UUID.randomUUID().toString());
form.put("user_id", targetUserId); form.put("target_user_id", targetUserId);
final Map<String, String> signedForm = Utils.sign(form); final String action = restrict ? "restrict" : "unrestrict";
final Call<FriendshipRepositoryChangeResponseRootObject> request = repository.change(action, targetUserId, signedForm); final Call<FriendshipRepoRestrictRootResponse> request = repository.toggleRestrict(Constants.I_USER_AGENT, action, form);
request.enqueue(new Callback<FriendshipRepositoryChangeResponseRootObject>() { request.enqueue(new Callback<FriendshipRepoRestrictRootResponse>() {
@Override @Override
public void onResponse(@NonNull final Call<FriendshipRepositoryChangeResponseRootObject> call, public void onResponse(@NonNull final Call<FriendshipRepoRestrictRootResponse> call,
@NonNull final Response<FriendshipRepositoryChangeResponseRootObject> response) { @NonNull final Response<FriendshipRepoRestrictRootResponse> response) {
if (callback != null) { if (callback != null) {
callback.onSuccess(response.body()); callback.onSuccess(response.body());
} }
} }
@Override @Override
public void onFailure(@NonNull final Call<FriendshipRepositoryChangeResponseRootObject> call, public void onFailure(@NonNull final Call<FriendshipRepoRestrictRootResponse> call,
@NonNull final Throwable t) {
if (callback != null) {
callback.onFailure(t);
}
}
});
}
private void change(final String action,
final String userId,
final String targetUserId,
final String csrfToken,
final ServiceCallback<FriendshipRepoChangeRootResponse> callback) {
final Map<String, Object> form = new HashMap<>(5);
form.put("_csrftoken", csrfToken);
form.put("_uid", userId);
form.put("_uuid", UUID.randomUUID().toString());
form.put("radio_type", "wifi-none");
form.put("user_id", targetUserId);
final Map<String, String> signedForm = Utils.sign(form);
final Call<FriendshipRepoChangeRootResponse> request = repository.change(Constants.I_USER_AGENT, action, targetUserId, signedForm);
request.enqueue(new Callback<FriendshipRepoChangeRootResponse>() {
@Override
public void onResponse(@NonNull final Call<FriendshipRepoChangeRootResponse> call,
@NonNull final Response<FriendshipRepoChangeRootResponse> response) {
if (callback != null) {
callback.onSuccess(response.body());
}
}
@Override
public void onFailure(@NonNull final Call<FriendshipRepoChangeRootResponse> call,
@NonNull final Throwable t) { @NonNull final Throwable t) {
if (callback != null) { if (callback != null) {
callback.onFailure(t); callback.onFailure(t);

View File

@ -0,0 +1,29 @@
package awais.instagrabber.services;
import android.util.Log;
import androidx.annotation.NonNull;
import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
class LoggingInterceptor implements Interceptor {
private static final String TAG = "LoggingInterceptor";
@NonNull
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
Request request = chain.request();
long t1 = System.nanoTime();
Log.i(TAG, String.format("Sending request %s on %s%n%s",
request.url(), chain.connection(), request.headers()));
Response response = chain.proceed(request);
long t2 = System.nanoTime();
Log.i(TAG, String.format("Received response for %s in %.1fms%n%s\nbody: %s",
response.request().url(), (t2 - t1) / 1e6d, response.headers(), response.body()));
return response;
}
}