Prevent multiple registrations to eventHub on same TimelineFragment (#879)
This commit is contained in:
parent
25c3defd33
commit
1556a88d05
|
@ -119,6 +119,7 @@ public class TimelineFragment extends SFragment implements
|
||||||
public TimelineCases timelineCases;
|
public TimelineCases timelineCases;
|
||||||
@Inject
|
@Inject
|
||||||
public EventHub eventHub;
|
public EventHub eventHub;
|
||||||
|
private boolean eventRegistered = false;
|
||||||
|
|
||||||
private SwipeRefreshLayout swipeRefreshLayout;
|
private SwipeRefreshLayout swipeRefreshLayout;
|
||||||
private RecyclerView recyclerView;
|
private RecyclerView recyclerView;
|
||||||
|
@ -304,7 +305,7 @@ public class TimelineFragment extends SFragment implements
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(statuses.size() == 0) {
|
if (statuses.size() == 0) {
|
||||||
nothingMessageView.setVisibility(View.VISIBLE);
|
nothingMessageView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -378,41 +379,44 @@ public class TimelineFragment extends SFragment implements
|
||||||
}
|
}
|
||||||
recyclerView.addOnScrollListener(scrollListener);
|
recyclerView.addOnScrollListener(scrollListener);
|
||||||
|
|
||||||
eventHub.getEvents()
|
if (!eventRegistered) {
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
eventHub.getEvents()
|
||||||
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(event -> {
|
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
|
||||||
if (event instanceof FavoriteEvent) {
|
.subscribe(event -> {
|
||||||
FavoriteEvent favEvent = ((FavoriteEvent) event);
|
if (event instanceof FavoriteEvent) {
|
||||||
handleFavEvent(favEvent);
|
FavoriteEvent favEvent = ((FavoriteEvent) event);
|
||||||
} else if (event instanceof ReblogEvent) {
|
handleFavEvent(favEvent);
|
||||||
ReblogEvent reblogEvent = (ReblogEvent) event;
|
} else if (event instanceof ReblogEvent) {
|
||||||
handleReblogEvent(reblogEvent);
|
ReblogEvent reblogEvent = (ReblogEvent) event;
|
||||||
} else if (event instanceof UnfollowEvent) {
|
handleReblogEvent(reblogEvent);
|
||||||
if (kind == Kind.HOME) {
|
} else if (event instanceof UnfollowEvent) {
|
||||||
String id = ((UnfollowEvent) event).getAccountId();
|
if (kind == Kind.HOME) {
|
||||||
removeAllByAccountId(id);
|
String id = ((UnfollowEvent) event).getAccountId();
|
||||||
|
removeAllByAccountId(id);
|
||||||
|
}
|
||||||
|
} else if (event instanceof BlockEvent) {
|
||||||
|
if (kind != Kind.USER && kind != Kind.USER_WITH_REPLIES) {
|
||||||
|
String id = ((BlockEvent) event).getAccountId();
|
||||||
|
removeAllByAccountId(id);
|
||||||
|
}
|
||||||
|
} else if (event instanceof MuteEvent) {
|
||||||
|
if (kind != Kind.USER && kind != Kind.USER_WITH_REPLIES) {
|
||||||
|
String id = ((MuteEvent) event).getAccountId();
|
||||||
|
removeAllByAccountId(id);
|
||||||
|
}
|
||||||
|
} else if (event instanceof StatusDeletedEvent) {
|
||||||
|
if (kind != Kind.USER && kind != Kind.USER_WITH_REPLIES) {
|
||||||
|
String id = ((StatusDeletedEvent) event).getStatusId();
|
||||||
|
deleteStatusById(id);
|
||||||
|
}
|
||||||
|
} else if (event instanceof StatusComposedEvent) {
|
||||||
|
Status status = ((StatusComposedEvent) event).getStatus();
|
||||||
|
handleStatusComposeEvent(status);
|
||||||
}
|
}
|
||||||
} else if (event instanceof BlockEvent) {
|
});
|
||||||
if (kind != Kind.USER && kind != Kind.USER_WITH_REPLIES) {
|
eventRegistered = true;
|
||||||
String id = ((BlockEvent) event).getAccountId();
|
}
|
||||||
removeAllByAccountId(id);
|
|
||||||
}
|
|
||||||
} else if (event instanceof MuteEvent) {
|
|
||||||
if (kind != Kind.USER && kind != Kind.USER_WITH_REPLIES) {
|
|
||||||
String id = ((MuteEvent) event).getAccountId();
|
|
||||||
removeAllByAccountId(id);
|
|
||||||
}
|
|
||||||
} else if (event instanceof StatusDeletedEvent) {
|
|
||||||
if (kind != Kind.USER && kind != Kind.USER_WITH_REPLIES) {
|
|
||||||
String id = ((StatusDeletedEvent) event).getStatusId();
|
|
||||||
deleteStatusById(id);
|
|
||||||
}
|
|
||||||
} else if (event instanceof StatusComposedEvent) {
|
|
||||||
Status status = ((StatusComposedEvent) event).getStatus();
|
|
||||||
handleStatusComposeEvent(status);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -583,7 +587,7 @@ public class TimelineFragment extends SFragment implements
|
||||||
"Expected StatusViewData.Concrete, got %s instead at position: %d of %d",
|
"Expected StatusViewData.Concrete, got %s instead at position: %d of %d",
|
||||||
status == null ? "<null>" : status.getClass().getSimpleName(),
|
status == null ? "<null>" : status.getClass().getSimpleName(),
|
||||||
position,
|
position,
|
||||||
statuses.size() -1
|
statuses.size() - 1
|
||||||
));
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue