Browse Source

close #660

renovate/org.robolectric-robolectric-4.x
Austin Huang 4 years ago
parent
commit
d551969da3
No known key found for this signature in database GPG Key ID: 84C23AA04587A91F
  1. 88
      app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java
  2. 5
      app/src/main/java/awais/instagrabber/repositories/FriendshipRepository.java
  3. 32
      app/src/main/java/awais/instagrabber/webservices/FriendshipService.java
  4. 1
      app/src/main/java/awais/instagrabber/webservices/StoriesService.java
  5. 14
      app/src/main/res/menu/profile_menu.xml
  6. 4
      app/src/main/res/values/strings.xml

88
app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java

@ -122,9 +122,8 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
private boolean hasStories = false;
private HighlightsAdapter highlightsAdapter;
private HighlightsViewModel highlightsViewModel;
private MenuItem blockMenuItem;
private MenuItem restrictMenuItem;
private MenuItem chainingMenuItem;
private MenuItem blockMenuItem, restrictMenuItem, chainingMenuItem;
private MenuItem muteStoriesMenuItem, mutePostsMenuItem;
private boolean highlightsFetching;
private boolean postsSetupDone = false;
private Set<Media> selectedFeedModels;
@ -381,6 +380,25 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
restrictMenuItem.setVisible(false);
}
}
muteStoriesMenuItem = menu.findItem(R.id.mute_stories);
if (muteStoriesMenuItem != null) {
if (profileModel != null) {
muteStoriesMenuItem.setVisible(!Objects.equals(profileModel.getPk(), CookieUtils.getUserIdFromCookie(cookie)));
muteStoriesMenuItem.setTitle(profileModel.getFriendshipStatus().isMutingReel() ? R.string.mute_stories : R.string.unmute_stories);
} else {
muteStoriesMenuItem.setVisible(false);
}
}
mutePostsMenuItem = menu.findItem(R.id.mute_posts);
if (mutePostsMenuItem != null) {
if (profileModel != null) {
mutePostsMenuItem.setVisible(!Objects.equals(profileModel.getPk(), CookieUtils.getUserIdFromCookie(cookie)));
mutePostsMenuItem.setTitle(profileModel.getFriendshipStatus().isMuting() ? R.string.mute_posts : R.string.unmute_posts);
}
else {
mutePostsMenuItem.setVisible(false);
}
}
chainingMenuItem = menu.findItem(R.id.chaining);
if (chainingMenuItem != null) {
if (profileModel != null) {
@ -459,6 +477,48 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
NavHostFragment.findNavController(this).navigate(navDirections);
return true;
}
if (item.getItemId() == R.id.mute_stories) {
if (!isLoggedIn) return false;
final String action = profileModel.getFriendshipStatus().isMutingReel() ? "Unmute stories" : "Mute stories";
friendshipService.changeMute(
profileModel.getFriendshipStatus().isMutingReel(),
profileModel.getPk(),
true,
new ServiceCallback<FriendshipChangeResponse>() {
@Override
public void onSuccess(final FriendshipChangeResponse result) {
Log.d(TAG, action + " success: " + result);
fetchProfileDetails();
}
@Override
public void onFailure(final Throwable t) {
Log.e(TAG, "Error while performing " + action, t);
}
});
return true;
}
if (item.getItemId() == R.id.mute_posts) {
if (!isLoggedIn) return false;
final String action = profileModel.getFriendshipStatus().isMuting() ? "Unmute stories" : "Mute stories";
friendshipService.changeMute(
profileModel.getFriendshipStatus().isMuting(),
profileModel.getPk(),
false,
new ServiceCallback<FriendshipChangeResponse>() {
@Override
public void onSuccess(final FriendshipChangeResponse result) {
Log.d(TAG, action + " success: " + result);
fetchProfileDetails();
}
@Override
public void onFailure(final Throwable t) {
Log.e(TAG, "Error while performing " + action, t);
}
});
return true;
}
return super.onOptionsItemSelected(item);
}
@ -896,21 +956,21 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
}
if (restrictMenuItem != null) {
restrictMenuItem.setVisible(true);
if (profileModel.getFriendshipStatus().isRestricted()) {
restrictMenuItem.setTitle(R.string.unrestrict);
} else {
restrictMenuItem.setTitle(R.string.restrict);
}
restrictMenuItem.setTitle(profileModel.getFriendshipStatus().isRestricted() ? R.string.unrestrict : R.string.restrict);
}
if (blockMenuItem != null) {
blockMenuItem.setVisible(true);
if (profileModel.getFriendshipStatus().isBlocking()) {
blockMenuItem.setTitle(R.string.unblock);
} else {
blockMenuItem.setTitle(R.string.block);
}
blockMenuItem.setTitle(profileModel.getFriendshipStatus().isBlocking() ? R.string.unblock : R.string.block);
}
if (muteStoriesMenuItem != null) {
muteStoriesMenuItem.setVisible(true);
muteStoriesMenuItem.setTitle(profileModel.getFriendshipStatus().isMutingReel() ? R.string.unmute_stories : R.string.mute_stories);
}
if (mutePostsMenuItem != null) {
mutePostsMenuItem.setVisible(true);
mutePostsMenuItem.setTitle(profileModel.getFriendshipStatus().isMuting() ? R.string.unmute_posts : R.string.mute_posts);
}
if (chainingMenuItem != null && !Objects.equals(profileId, myId)) {
if (chainingMenuItem != null) {
chainingMenuItem.setVisible(true);
}
return;

5
app/src/main/java/awais/instagrabber/repositories/FriendshipRepository.java

@ -29,4 +29,9 @@ public interface FriendshipRepository {
Call<String> getList(@Path("userId") long userId,
@Path("type") String type, // following or followers
@QueryMap(encoded = true) Map<String, String> queryParams);
@FormUrlEncoded
@POST("/api/v1/friendships/{action}/")
Call<FriendshipChangeResponse> changeMute(@Path("action") String action,
@FieldMap Map<String, String> form);
}

32
app/src/main/java/awais/instagrabber/webservices/FriendshipService.java

@ -158,6 +158,38 @@ public class FriendshipService extends BaseService {
});
}
public void changeMute(final boolean unmute,
final long targetUserId,
final boolean story, // true for story, false for posts
final ServiceCallback<FriendshipChangeResponse> callback) {
final Map<String, String> form = new HashMap<>(4);
form.put("_csrftoken", csrfToken);
form.put("_uid", String.valueOf(userId));
form.put("_uuid", deviceUuid);
form.put(story ? "target_reel_author_id" : "target_posts_author_id", String.valueOf(targetUserId));
final Call<FriendshipChangeResponse> request = repository.changeMute(unmute ?
"unmute_posts_or_story_from_follow" :
"mute_posts_or_story_from_follow",
form);
request.enqueue(new Callback<FriendshipChangeResponse>() {
@Override
public void onResponse(@NonNull final Call<FriendshipChangeResponse> call,
@NonNull final Response<FriendshipChangeResponse> response) {
if (callback != null) {
callback.onSuccess(response.body());
}
}
@Override
public void onFailure(@NonNull final Call<FriendshipChangeResponse> call,
@NonNull final Throwable t) {
if (callback != null) {
callback.onFailure(t);
}
}
});
}
public void getList(final boolean follower,
final long targetUserId,
final String maxId,

1
app/src/main/java/awais/instagrabber/webservices/StoriesService.java

@ -137,6 +137,7 @@ public class StoriesService extends BaseService {
final JSONArray feedStoriesReel = new JSONObject(body).getJSONArray("tray");
for (int i = 0; i < feedStoriesReel.length(); ++i) {
final JSONObject node = feedStoriesReel.getJSONObject(i);
if (node.optBoolean("hide_from_feed_unit")) continue;
final JSONObject userJson = node.getJSONObject(node.has("user") ? "user" : "owner");
try {
final User user = new User(userJson.getLong("pk"),

14
app/src/main/res/menu/profile_menu.xml

@ -26,4 +26,18 @@
android:title="@string/action_ayml"
android:visible="false"
app:showAsAction="never" />
<item
android:id="@+id/mute_stories"
android:icon="@drawable/ic_highlight_off_24"
android:title="@string/mute_stories"
android:visible="false"
app:showAsAction="never" />
<item
android:id="@+id/mute_posts"
android:icon="@drawable/ic_highlight_off_24"
android:title="@string/mute_posts"
android:visible="false"
app:showAsAction="never" />
</menu>

4
app/src/main/res/values/strings.xml

@ -123,6 +123,10 @@
<string name="unblock">Unblock</string>
<string name="restrict">Restrict</string>
<string name="unrestrict">Unrestrict</string>
<string name="mute_stories">Mute stories</string>
<string name="mute_posts">Mute posts</string>
<string name="unmute_stories">Unmute stories</string>
<string name="unmute_posts">Unmute posts</string>
<string name="bio_copy">Copy bio</string>
<string name="bio_translate">Translate bio</string>
<string name="status_mutual">Mutual</string>

Loading…
Cancel
Save