fix a bug where favs & reblogs where not shown correctly in NotificationsFragment
This commit is contained in:
parent
5cbc7217ff
commit
9dd09d0522
2 changed files with 58 additions and 57 deletions
|
@ -21,6 +21,7 @@ import android.content.SharedPreferences;
|
|||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.design.widget.TabLayout;
|
||||
|
@ -229,15 +230,63 @@ public class NotificationsFragment extends SFragment implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onReblog(boolean reblog, int position) {
|
||||
Notification notification = notifications.get(position);
|
||||
super.reblog(notification.status, reblog, adapter, position);
|
||||
public void onReblog(final boolean reblog, final int position) {
|
||||
final Notification notification = notifications.get(position);
|
||||
final Status status = notification.status;
|
||||
reblogWithCallback(status, reblog, new Callback<Status>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<Status> call, @NonNull retrofit2.Response<Status> response) {
|
||||
if (response.isSuccessful()) {
|
||||
status.reblogged = reblog;
|
||||
|
||||
if (status.reblog != null) {
|
||||
status.reblog.reblogged = reblog;
|
||||
}
|
||||
notifications.set(position, notification);
|
||||
|
||||
adapter.updateItemWithNotify(position, notifications.getPairedItem(position), true);
|
||||
|
||||
adapter.notifyItemChanged(position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<Status> call, @NonNull Throwable t) {
|
||||
Log.d(getClass().getSimpleName(), "Failed to reblog status: " + status.id);
|
||||
t.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onFavourite(boolean favourite, int position) {
|
||||
Notification notification = notifications.get(position);
|
||||
super.favourite(notification.status, favourite, adapter, position);
|
||||
public void onFavourite(final boolean favourite, final int position) {
|
||||
final Notification notification = notifications.get(position);
|
||||
final Status status = notification.status;
|
||||
favouriteWithCallback(status, favourite, new Callback<Status>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<Status> call, @NonNull retrofit2.Response<Status> response) {
|
||||
if (response.isSuccessful()) {
|
||||
status.favourited = favourite;
|
||||
|
||||
if (status.reblog != null) {
|
||||
status.reblog.favourited = favourite;
|
||||
}
|
||||
|
||||
notifications.set(position, notification);
|
||||
|
||||
adapter.updateItemWithNotify(position, notifications.getPairedItem(position), true);
|
||||
|
||||
adapter.notifyItemChanged(position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<Status> call, @NonNull Throwable t) {
|
||||
Log.d(getClass().getSimpleName(), "Failed to favourite status: " + status.id);
|
||||
t.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -373,8 +422,8 @@ public class NotificationsFragment extends SFragment implements
|
|||
|
||||
call.enqueue(new Callback<List<Notification>>() {
|
||||
@Override
|
||||
public void onResponse(Call<List<Notification>> call,
|
||||
Response<List<Notification>> response) {
|
||||
public void onResponse(@NonNull Call<List<Notification>> call,
|
||||
@NonNull Response<List<Notification>> response) {
|
||||
if (response.isSuccessful()) {
|
||||
String linkHeader = response.headers().get("Link");
|
||||
onFetchNotificationsSuccess(response.body(), linkHeader, fetchEnd);
|
||||
|
@ -384,7 +433,7 @@ public class NotificationsFragment extends SFragment implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<List<Notification>> call, Throwable t) {
|
||||
public void onFailure(@NonNull Call<List<Notification>> call, @NonNull Throwable t) {
|
||||
onFetchNotificationsFailure((Exception) t, fetchEnd);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -111,30 +111,6 @@ public abstract class SFragment extends BaseFragment implements AdapterItemRemov
|
|||
startActivityForResult(intent, COMPOSE_RESULT);
|
||||
}
|
||||
|
||||
protected void reblog(final Status status, final boolean reblog,
|
||||
final RecyclerView.Adapter adapter, final int position) {
|
||||
reblogWithCallback(status, reblog, new Callback<Status>() {
|
||||
@Override
|
||||
public void onResponse(Call<Status> call, retrofit2.Response<Status> response) {
|
||||
if (response.isSuccessful()) {
|
||||
status.reblogged = reblog;
|
||||
|
||||
if (status.reblog != null) {
|
||||
status.reblog.reblogged = reblog;
|
||||
}
|
||||
|
||||
adapter.notifyItemChanged(position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Status> call, Throwable t) {
|
||||
Log.d(getClass().getSimpleName(), "Failed to reblog status: " + status.id);
|
||||
t.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void reblogWithCallback(final Status status, final boolean reblog,
|
||||
Callback<Status> callback) {
|
||||
String id = status.getActionableId();
|
||||
|
@ -148,30 +124,6 @@ public abstract class SFragment extends BaseFragment implements AdapterItemRemov
|
|||
call.enqueue(callback);
|
||||
}
|
||||
|
||||
protected void favourite(final Status status, final boolean favourite,
|
||||
final RecyclerView.Adapter adapter, final int position) {
|
||||
favouriteWithCallback(status, favourite, new Callback<Status>() {
|
||||
@Override
|
||||
public void onResponse(Call<Status> call, retrofit2.Response<Status> response) {
|
||||
if (response.isSuccessful()) {
|
||||
status.favourited = favourite;
|
||||
|
||||
if (status.reblog != null) {
|
||||
status.reblog.favourited = favourite;
|
||||
}
|
||||
|
||||
adapter.notifyItemChanged(position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Status> call, Throwable t) {
|
||||
Log.d(getClass().getSimpleName(), "Failed to favourite status: " + status.id);
|
||||
t.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void favouriteWithCallback(final Status status, final boolean favourite,
|
||||
final Callback<Status> callback) {
|
||||
String id = status.getActionableId();
|
||||
|
|
Loading…
Reference in a new issue