diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/BaseFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/BaseFragment.java index 886a98b2b..3a9db6599 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/BaseFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/BaseFragment.java @@ -16,8 +16,6 @@ package com.keylesspalace.tusky.fragment; import android.os.Bundle; -import android.os.Handler; -import android.os.Looper; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; @@ -28,21 +26,11 @@ import retrofit2.Call; public class BaseFragment extends Fragment { protected List callList; - private final Handler handler = new Handler(Looper.getMainLooper()); @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); callList = new ArrayList<>(); - handler.post(this::onPostCreate); - } - - /** - * For actions which should happen only once per lifecycle but after onCreate. - * Example: subscribe for events in {@code onCreate()} but need dependencies to be injected - */ - public void onPostCreate() { - // No-op } @Override diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java index f1662fcde..d0394834f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java @@ -214,23 +214,6 @@ public class NotificationsFragment extends SFragment implements return rootView; } - @Override - public void onPostCreate() { - super.onPostCreate(); - eventHub.getEvents() - .observeOn(AndroidSchedulers.mainThread()) - .as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY))) - .subscribe(event -> { - if (event instanceof FavoriteEvent) { - handleFavEvent((FavoriteEvent) event); - } else if (event instanceof ReblogEvent) { - handleReblogEvent((ReblogEvent) event); - } else if (event instanceof BlockEvent) { - removeAllByAccountId(((BlockEvent) event).getAccountId()); - } - }); - } - private void setupNothingView() { Drawable top = AppCompatResources.getDrawable(Objects.requireNonNull(getContext()), R.drawable.elephant_friend); @@ -320,6 +303,19 @@ public class NotificationsFragment extends SFragment implements }; recyclerView.addOnScrollListener(scrollListener); + + eventHub.getEvents() + .observeOn(AndroidSchedulers.mainThread()) + .as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY))) + .subscribe(event -> { + if (event instanceof FavoriteEvent) { + handleFavEvent((FavoriteEvent) event); + } else if (event instanceof ReblogEvent) { + handleReblogEvent((ReblogEvent) event); + } else if (event instanceof BlockEvent) { + removeAllByAccountId(((BlockEvent) event).getAccountId()); + } + }); } @Override diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java index f6ff4d66b..e6b54eb6e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java @@ -293,47 +293,6 @@ public class TimelineFragment extends SFragment implements recyclerView.setAdapter(adapter); } - @Override - public void onPostCreate() { - super.onPostCreate(); - - eventHub.getEvents() - .observeOn(AndroidSchedulers.mainThread()) - .as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY))) - .subscribe(event -> { - if (event instanceof FavoriteEvent) { - FavoriteEvent favEvent = ((FavoriteEvent) event); - handleFavEvent(favEvent); - } else if (event instanceof ReblogEvent) { - ReblogEvent reblogEvent = (ReblogEvent) event; - handleReblogEvent(reblogEvent); - } else if (event instanceof UnfollowEvent) { - if (kind == Kind.HOME) { - 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); - } - }); - } - private void deleteStatusById(String id) { for (int i = 0; i < statuses.size(); i++) { Either either = statuses.get(i); @@ -414,6 +373,42 @@ public class TimelineFragment extends SFragment implements }; } recyclerView.addOnScrollListener(scrollListener); + + eventHub.getEvents() + .observeOn(AndroidSchedulers.mainThread()) + .as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY))) + .subscribe(event -> { + if (event instanceof FavoriteEvent) { + FavoriteEvent favEvent = ((FavoriteEvent) event); + handleFavEvent(favEvent); + } else if (event instanceof ReblogEvent) { + ReblogEvent reblogEvent = (ReblogEvent) event; + handleReblogEvent(reblogEvent); + } else if (event instanceof UnfollowEvent) { + if (kind == Kind.HOME) { + 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); + } + }); } @Override diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/ViewThreadFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/ViewThreadFragment.java index 70209e9e6..93cb00717 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/ViewThreadFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/ViewThreadFragment.java @@ -124,28 +124,6 @@ public final class ViewThreadFragment extends SFragment implements adapter = new ThreadAdapter(this); } - @Override - public void onPostCreate() { - super.onPostCreate(); - - eventHub.getEvents() - .observeOn(AndroidSchedulers.mainThread()) - .as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY))) - .subscribe(event -> { - if (event instanceof FavoriteEvent) { - handleFavEvent((FavoriteEvent) event); - } else if (event instanceof ReblogEvent) { - handleReblogEvent((ReblogEvent) event); - } else if (event instanceof BlockEvent) { - removeAllByAccountId(((BlockEvent) event).getAccountId()); - } else if (event instanceof StatusComposedEvent) { - handleStatusComposedEvent((StatusComposedEvent) event); - } else if (event instanceof StatusDeletedEvent) { - handleStatusDeletedEvent((StatusDeletedEvent) event); - } - }); - } - @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -192,6 +170,23 @@ public final class ViewThreadFragment extends SFragment implements public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); onRefresh(); + + eventHub.getEvents() + .observeOn(AndroidSchedulers.mainThread()) + .as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY))) + .subscribe(event -> { + if (event instanceof FavoriteEvent) { + handleFavEvent((FavoriteEvent) event); + } else if (event instanceof ReblogEvent) { + handleReblogEvent((ReblogEvent) event); + } else if (event instanceof BlockEvent) { + removeAllByAccountId(((BlockEvent) event).getAccountId()); + } else if (event instanceof StatusComposedEvent) { + handleStatusComposedEvent((StatusComposedEvent) event); + } else if (event instanceof StatusDeletedEvent) { + handleStatusDeletedEvent((StatusDeletedEvent) event); + } + }); } public void onRevealPressed() {