From 9c56f0e7bca6e6a85a099fdeced930f8ea11488a Mon Sep 17 00:00:00 2001 From: Vavassor Date: Tue, 6 Jun 2017 17:15:29 -0400 Subject: [PATCH] Broadcasts now used everywhere for signalling to remove accounts' posts instead of listeners. --- .../keylesspalace/tusky/AccountActivity.java | 17 +------------- .../tusky/FavouritesActivity.java | 13 +---------- .../com/keylesspalace/tusky/MainActivity.java | 14 +----------- .../keylesspalace/tusky/ViewTagActivity.java | 14 +----------- .../tusky/ViewThreadActivity.java | 16 +------------- .../tusky/adapter/NotificationsAdapter.java | 2 ++ .../tusky/adapter/ThreadAdapter.java | 2 ++ .../tusky/adapter/TimelineAdapter.java | 12 +++++----- .../tusky/fragment/NotificationsFragment.java | 22 +++++++++++++------ .../tusky/fragment/SFragment.java | 18 ++++++++------- .../tusky/fragment/TimelineFragment.java | 9 ++------ .../tusky/fragment/ViewThreadFragment.java | 22 +++++++++++++------ .../tusky/interfaces/AdapterItemRemover.java | 1 + .../interfaces/StatusRemoveListener.java | 20 ----------------- .../tusky/receiver/TimelineReceiver.java | 9 ++++---- 15 files changed, 64 insertions(+), 127 deletions(-) delete mode 100644 app/src/main/java/com/keylesspalace/tusky/interfaces/StatusRemoveListener.java diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java index 59539931..616d9e00 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java @@ -32,7 +32,6 @@ import android.support.design.widget.CollapsingToolbarLayout; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.design.widget.TabLayout; -import android.support.v4.app.Fragment; import android.support.v4.content.LocalBroadcastManager; import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewPager; @@ -47,9 +46,7 @@ import android.widget.TextView; import com.keylesspalace.tusky.entity.Account; import com.keylesspalace.tusky.entity.Relationship; -import com.keylesspalace.tusky.fragment.SFragment; import com.keylesspalace.tusky.interfaces.LinkListener; -import com.keylesspalace.tusky.interfaces.StatusRemoveListener; import com.keylesspalace.tusky.pager.AccountPagerAdapter; import com.keylesspalace.tusky.receiver.TimelineReceiver; import com.keylesspalace.tusky.util.LinkHelper; @@ -68,7 +65,7 @@ import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; -public class AccountActivity extends BaseActivity implements SFragment.OnUserRemovedListener { +public class AccountActivity extends BaseActivity { private static final String TAG = "AccountActivity"; // logging tag private enum FollowState { @@ -82,7 +79,6 @@ public class AccountActivity extends BaseActivity implements SFragment.OnUserRem private boolean blocking; private boolean muting; private boolean isSelf; - private AccountPagerAdapter pagerAdapter; private Account loadedAccount; @BindView(R.id.account_avatar) CircularImageView avatar; @@ -177,7 +173,6 @@ public class AccountActivity extends BaseActivity implements SFragment.OnUserRem // Setup the tabs and timeline pager. AccountPagerAdapter adapter = new AccountPagerAdapter(getSupportFragmentManager(), this, accountId); - pagerAdapter = adapter; String[] pageTitles = { getString(R.string.title_statuses), getString(R.string.title_follows), @@ -357,16 +352,6 @@ public class AccountActivity extends BaseActivity implements SFragment.OnUserRem updateButtons(); } - @Override - public void onUserRemoved(String accountId) { - for (Fragment fragment : pagerAdapter.getRegisteredFragments()) { - if (fragment instanceof StatusRemoveListener) { - StatusRemoveListener listener = (StatusRemoveListener) fragment; - listener.removePostsByUser(accountId); - } - } - } - private void updateFollowButton(FloatingActionButton button) { switch (followState) { case NOT_FOLLOWING: { diff --git a/app/src/main/java/com/keylesspalace/tusky/FavouritesActivity.java b/app/src/main/java/com/keylesspalace/tusky/FavouritesActivity.java index 7755f217..257b37bc 100644 --- a/app/src/main/java/com/keylesspalace/tusky/FavouritesActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/FavouritesActivity.java @@ -23,13 +23,9 @@ import android.support.v7.app.ActionBar; import android.support.v7.widget.Toolbar; import android.view.MenuItem; -import com.keylesspalace.tusky.fragment.SFragment; import com.keylesspalace.tusky.fragment.TimelineFragment; -import com.keylesspalace.tusky.interfaces.StatusRemoveListener; - -public class FavouritesActivity extends BaseActivity implements SFragment.OnUserRemovedListener { - private StatusRemoveListener statusRemoveListener; +public class FavouritesActivity extends BaseActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -48,8 +44,6 @@ public class FavouritesActivity extends BaseActivity implements SFragment.OnUser Fragment fragment = TimelineFragment.newInstance(TimelineFragment.Kind.FAVOURITES); fragmentTransaction.add(R.id.fragment_container, fragment); fragmentTransaction.commit(); - - statusRemoveListener = (StatusRemoveListener) fragment; } @Override @@ -62,9 +56,4 @@ public class FavouritesActivity extends BaseActivity implements SFragment.OnUser } return super.onOptionsItemSelected(item); } - - @Override - public void onUserRemoved(String accountId) { - statusRemoveListener.removePostsByUser(accountId); - } } diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java index d3d85a9b..ed800e9e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java @@ -46,7 +46,6 @@ import com.arlib.floatingsearchview.suggestions.SearchSuggestionsAdapter; import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion; import com.keylesspalace.tusky.entity.Account; import com.keylesspalace.tusky.fragment.SFragment; -import com.keylesspalace.tusky.interfaces.StatusRemoveListener; import com.keylesspalace.tusky.pager.TimelinePagerAdapter; import com.keylesspalace.tusky.util.ThemeUtils; import com.mikepenz.google_material_typeface_library.GoogleMaterial; @@ -74,7 +73,7 @@ import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; -public class MainActivity extends BaseActivity implements SFragment.OnUserRemovedListener { +public class MainActivity extends BaseActivity { private static final String TAG = "MainActivity"; // logging tag protected static int COMPOSE_RESULT = 1; @@ -568,17 +567,6 @@ public class MainActivity extends BaseActivity implements SFragment.OnUserRemove } } - @Override - public void onUserRemoved(String accountId) { - TimelinePagerAdapter adapter = (TimelinePagerAdapter) viewPager.getAdapter(); - for (Fragment fragment : adapter.getRegisteredFragments()) { - if (fragment instanceof StatusRemoveListener) { - StatusRemoveListener listener = (StatusRemoveListener) fragment; - listener.removePostsByUser(accountId); - } - } - } - // Fix for GitHub issues #190, #259 (MainActivity won't restart on screen rotation.) @Override public void onConfigurationChanged(Configuration newConfig) { diff --git a/app/src/main/java/com/keylesspalace/tusky/ViewTagActivity.java b/app/src/main/java/com/keylesspalace/tusky/ViewTagActivity.java index e73d490a..3401195c 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ViewTagActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ViewTagActivity.java @@ -23,16 +23,12 @@ import android.support.v7.app.ActionBar; import android.support.v7.widget.Toolbar; import android.view.MenuItem; -import com.keylesspalace.tusky.fragment.SFragment; import com.keylesspalace.tusky.fragment.TimelineFragment; -import com.keylesspalace.tusky.interfaces.StatusRemoveListener; import butterknife.BindView; import butterknife.ButterKnife; -public class ViewTagActivity extends BaseActivity implements SFragment.OnUserRemovedListener { - private Fragment timelineFragment; - +public class ViewTagActivity extends BaseActivity { @BindView(R.id.toolbar) Toolbar toolbar; @Override @@ -57,8 +53,6 @@ public class ViewTagActivity extends BaseActivity implements SFragment.OnUserRem Fragment fragment = TimelineFragment.newInstance(TimelineFragment.Kind.TAG, hashtag); fragmentTransaction.add(R.id.fragment_container, fragment); fragmentTransaction.commit(); - - timelineFragment = fragment; } @Override @@ -71,10 +65,4 @@ public class ViewTagActivity extends BaseActivity implements SFragment.OnUserRem } return super.onOptionsItemSelected(item); } - - @Override - public void onUserRemoved(String accountId) { - StatusRemoveListener listener = (StatusRemoveListener) timelineFragment; - listener.removePostsByUser(accountId); - } } diff --git a/app/src/main/java/com/keylesspalace/tusky/ViewThreadActivity.java b/app/src/main/java/com/keylesspalace/tusky/ViewThreadActivity.java index 20b3534a..f118d21d 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ViewThreadActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ViewThreadActivity.java @@ -25,13 +25,9 @@ import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; -import com.keylesspalace.tusky.fragment.SFragment; import com.keylesspalace.tusky.fragment.ViewThreadFragment; -import com.keylesspalace.tusky.interfaces.StatusRemoveListener; - -public class ViewThreadActivity extends BaseActivity implements SFragment.OnUserRemovedListener { - Fragment viewThreadFragment; +public class ViewThreadActivity extends BaseActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -51,8 +47,6 @@ public class ViewThreadActivity extends BaseActivity implements SFragment.OnUser Fragment fragment = ViewThreadFragment.newInstance(id); fragmentTransaction.add(R.id.fragment_container, fragment); fragmentTransaction.commit(); - - viewThreadFragment = fragment; } @Override @@ -72,14 +66,6 @@ public class ViewThreadActivity extends BaseActivity implements SFragment.OnUser return super.onOptionsItemSelected(item); } - @Override - public void onUserRemoved(String accountId) { - if (viewThreadFragment instanceof StatusRemoveListener) { - StatusRemoveListener listener = (StatusRemoveListener) viewThreadFragment; - listener.removePostsByUser(accountId); - } - } - @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java b/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java index 639bfea3..ba3c1426 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java @@ -209,11 +209,13 @@ public class NotificationsAdapter extends RecyclerView.Adapter implements Adapte notifyItemRangeInserted(end, new_notifications.size()); } + @Override public void removeItem(int position) { notifications.remove(position); notifyItemChanged(position); } + @Override public void removeAllByAccountId(String id) { for (int i = 0; i < notifications.size();) { Notification notification = notifications.get(i); diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/ThreadAdapter.java b/app/src/main/java/com/keylesspalace/tusky/adapter/ThreadAdapter.java index 46523f52..0bfccbf5 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/ThreadAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/ThreadAdapter.java @@ -62,11 +62,13 @@ public class ThreadAdapter extends RecyclerView.Adapter implements AdapterItemRe return statuses.get(position); } + @Override public void removeItem(int position) { statuses.remove(position); notifyItemRemoved(position); } + @Override public void removeAllByAccountId(String accountId) { for (int i = 0; i < statuses.size();) { Status status = statuses.get(i); diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/TimelineAdapter.java b/app/src/main/java/com/keylesspalace/tusky/adapter/TimelineAdapter.java index 4f06ef47..5fb3c873 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/TimelineAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/TimelineAdapter.java @@ -140,16 +140,13 @@ public class TimelineAdapter extends RecyclerView.Adapter implements AdapterItem notifyItemRangeInserted(end, newStatuses.size()); } + @Override public void removeItem(int position) { statuses.remove(position); notifyItemRemoved(position); } - public void clear() { - statuses.clear(); - notifyDataSetChanged(); - } - + @Override public void removeAllByAccountId(String accountId) { for (int i = 0; i < statuses.size();) { Status status = statuses.get(i); @@ -162,6 +159,11 @@ public class TimelineAdapter extends RecyclerView.Adapter implements AdapterItem } } + public void clear() { + statuses.clear(); + notifyDataSetChanged(); + } + @Nullable public Status getItem(int position) { if (position >= 0 && position < statuses.size()) { 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 17e5ec35..8acbdcf9 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java @@ -23,6 +23,7 @@ import android.preference.PreferenceManager; import android.support.annotation.Nullable; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.TabLayout; +import android.support.v4.content.LocalBroadcastManager; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.LinearLayoutManager; @@ -39,10 +40,11 @@ import com.keylesspalace.tusky.R; import com.keylesspalace.tusky.entity.Notification; import com.keylesspalace.tusky.entity.Status; import com.keylesspalace.tusky.interfaces.StatusActionListener; -import com.keylesspalace.tusky.interfaces.StatusRemoveListener; +import com.keylesspalace.tusky.receiver.TimelineReceiver; import com.keylesspalace.tusky.util.ThemeUtils; import com.keylesspalace.tusky.view.EndlessOnScrollListener; +import java.sql.Time; import java.util.List; import retrofit2.Call; @@ -50,8 +52,9 @@ import retrofit2.Callback; import retrofit2.Response; public class NotificationsFragment extends SFragment implements - SwipeRefreshLayout.OnRefreshListener, StatusActionListener, StatusRemoveListener, - NotificationsAdapter.NotificationActionListener, SharedPreferences.OnSharedPreferenceChangeListener { + SwipeRefreshLayout.OnRefreshListener, StatusActionListener, + NotificationsAdapter.NotificationActionListener, + SharedPreferences.OnSharedPreferenceChangeListener { private static final String TAG = "Notifications"; // logging tag private SwipeRefreshLayout swipeRefreshLayout; @@ -62,6 +65,7 @@ public class NotificationsFragment extends SFragment implements private TabLayout.OnTabSelectedListener onTabSelectedListener; private Call> listCall; private boolean hideFab; + private TimelineReceiver timelineReceiver; public static NotificationsFragment newInstance() { NotificationsFragment fragment = new NotificationsFragment(); @@ -110,6 +114,10 @@ public class NotificationsFragment extends SFragment implements }; layout.addOnTabSelectedListener(onTabSelectedListener); + timelineReceiver = new TimelineReceiver(adapter); + LocalBroadcastManager.getInstance(context.getApplicationContext()) + .registerReceiver(timelineReceiver, TimelineReceiver.getFilter(null)); + return rootView; } @@ -168,6 +176,10 @@ public class NotificationsFragment extends SFragment implements public void onDestroyView() { TabLayout tabLayout = (TabLayout) getActivity().findViewById(R.id.tab_layout); tabLayout.removeOnTabSelectedListener(onTabSelectedListener); + + LocalBroadcastManager.getInstance(getContext()) + .unregisterReceiver(timelineReceiver); + super.onDestroyView(); } @@ -205,10 +217,6 @@ public class NotificationsFragment extends SFragment implements sendFetchNotificationsRequest(null, null); } - public void removePostsByUser(String accountId) { - adapter.removeAllByAccountId(accountId); - } - private static boolean findNotification(List notifications, String id) { for (Notification notification : notifications) { if (notification.id.equals(id)) { diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java index 71b04426..0094b526 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java @@ -21,6 +21,7 @@ import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.DialogFragment; import android.support.v4.app.FragmentTransaction; +import android.support.v4.content.LocalBroadcastManager; import android.support.v7.widget.PopupMenu; import android.support.v7.widget.RecyclerView; import android.text.Spanned; @@ -39,6 +40,7 @@ import com.keylesspalace.tusky.entity.Relationship; import com.keylesspalace.tusky.entity.Status; import com.keylesspalace.tusky.interfaces.AdapterItemRemover; import com.keylesspalace.tusky.network.MastodonAPI; +import com.keylesspalace.tusky.receiver.TimelineReceiver; import com.keylesspalace.tusky.util.HtmlUtils; import java.util.ArrayList; @@ -56,14 +58,9 @@ import retrofit2.Response; * overlap functionality. So, I'm momentarily leaving it and hopefully working on those will clear * up what needs to be where. */ public abstract class SFragment extends BaseFragment { - public interface OnUserRemovedListener { - void onUserRemoved(String accountId); - } - protected String loggedInAccountId; protected String loggedInUsername; protected MastodonAPI mastodonAPI; - protected OnUserRemovedListener userRemovedListener; protected static int COMPOSE_RESULT = 1; @Override @@ -80,7 +77,6 @@ public abstract class SFragment extends BaseFragment { super.onActivityCreated(savedInstanceState); BaseActivity activity = (BaseActivity) getActivity(); mastodonAPI = activity.mastodonAPI; - userRemovedListener = (OnUserRemovedListener) activity; } protected void reply(Status status) { @@ -188,7 +184,10 @@ public abstract class SFragment extends BaseFragment { public void onFailure(Call call, Throwable t) {} }); callList.add(call); - userRemovedListener.onUserRemoved(id); + Intent intent = new Intent(TimelineReceiver.Types.MUTE_ACCOUNT); + intent.putExtra("id", id); + LocalBroadcastManager.getInstance(getContext()) + .sendBroadcast(intent); } private void block(String id) { @@ -201,7 +200,10 @@ public abstract class SFragment extends BaseFragment { public void onFailure(Call call, Throwable t) {} }); callList.add(call); - userRemovedListener.onUserRemoved(id); + Intent intent = new Intent(TimelineReceiver.Types.BLOCK_ACCOUNT); + intent.putExtra("id", id); + LocalBroadcastManager.getInstance(getContext()) + .sendBroadcast(intent); } private void delete(String id) { 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 48471016..23722ffc 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java @@ -38,7 +38,6 @@ import com.keylesspalace.tusky.R; import com.keylesspalace.tusky.adapter.TimelineAdapter; import com.keylesspalace.tusky.entity.Status; import com.keylesspalace.tusky.interfaces.StatusActionListener; -import com.keylesspalace.tusky.interfaces.StatusRemoveListener; import com.keylesspalace.tusky.receiver.TimelineReceiver; import com.keylesspalace.tusky.util.ThemeUtils; import com.keylesspalace.tusky.view.EndlessOnScrollListener; @@ -53,7 +52,6 @@ import retrofit2.Response; public class TimelineFragment extends SFragment implements SwipeRefreshLayout.OnRefreshListener, StatusActionListener, - StatusRemoveListener, SharedPreferences.OnSharedPreferenceChangeListener { private static final String TAG = "Timeline"; // logging tag @@ -128,7 +126,8 @@ public class TimelineFragment extends SFragment implements recyclerView.setAdapter(adapter); timelineReceiver = new TimelineReceiver(adapter); - LocalBroadcastManager.getInstance(context.getApplicationContext()).registerReceiver(timelineReceiver, TimelineReceiver.getFilter(kind)); + LocalBroadcastManager.getInstance(context.getApplicationContext()) + .registerReceiver(timelineReceiver, TimelineReceiver.getFilter(kind)); return rootView; } @@ -285,10 +284,6 @@ public class TimelineFragment extends SFragment implements listCall.enqueue(callback); } - public void removePostsByUser(String accountId) { - adapter.removeAllByAccountId(accountId); - } - private static boolean findStatus(List statuses, String id) { for (Status status : statuses) { if (status.id.equals(id)) { 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 a7daa2d8..1518b7dd 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/ViewThreadFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/ViewThreadFragment.java @@ -21,6 +21,7 @@ import android.os.Bundle; import android.support.annotation.Nullable; import android.support.design.widget.Snackbar; import android.support.v4.content.ContextCompat; +import android.support.v4.content.LocalBroadcastManager; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.LinearLayoutManager; @@ -38,7 +39,7 @@ import com.keylesspalace.tusky.entity.StatusContext; import com.keylesspalace.tusky.network.MastodonAPI; import com.keylesspalace.tusky.R; import com.keylesspalace.tusky.interfaces.StatusActionListener; -import com.keylesspalace.tusky.interfaces.StatusRemoveListener; +import com.keylesspalace.tusky.receiver.TimelineReceiver; import com.keylesspalace.tusky.util.ThemeUtils; import com.keylesspalace.tusky.view.ConversationLineItemDecoration; @@ -47,7 +48,7 @@ import retrofit2.Callback; import retrofit2.Response; public class ViewThreadFragment extends SFragment implements - SwipeRefreshLayout.OnRefreshListener, StatusActionListener, StatusRemoveListener { + SwipeRefreshLayout.OnRefreshListener, StatusActionListener { private static final String TAG = "ViewThreadFragment"; private SwipeRefreshLayout swipeRefreshLayout; @@ -55,6 +56,7 @@ public class ViewThreadFragment extends SFragment implements private ThreadAdapter adapter; private MastodonAPI mastodonApi; private String thisThreadsStatusId; + private TimelineReceiver timelineReceiver; public static ViewThreadFragment newInstance(String id) { Bundle arguments = new Bundle(); @@ -92,9 +94,20 @@ public class ViewThreadFragment extends SFragment implements mastodonApi = null; thisThreadsStatusId = null; + timelineReceiver = new TimelineReceiver(adapter); + LocalBroadcastManager.getInstance(context.getApplicationContext()) + .registerReceiver(timelineReceiver, TimelineReceiver.getFilter(null)); + return rootView; } + @Override + public void onDestroyView() { + LocalBroadcastManager.getInstance(getContext()) + .unregisterReceiver(timelineReceiver); + super.onDestroyView(); + } + @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); @@ -169,11 +182,6 @@ public class ViewThreadFragment extends SFragment implements } } - @Override - public void removePostsByUser(String accountId) { - adapter.removeAllByAccountId(accountId); - } - public void onRefresh() { sendStatusRequest(thisThreadsStatusId); sendThreadRequest(thisThreadsStatusId); diff --git a/app/src/main/java/com/keylesspalace/tusky/interfaces/AdapterItemRemover.java b/app/src/main/java/com/keylesspalace/tusky/interfaces/AdapterItemRemover.java index 5b49cbfa..8754ac5b 100644 --- a/app/src/main/java/com/keylesspalace/tusky/interfaces/AdapterItemRemover.java +++ b/app/src/main/java/com/keylesspalace/tusky/interfaces/AdapterItemRemover.java @@ -17,4 +17,5 @@ package com.keylesspalace.tusky.interfaces; public interface AdapterItemRemover { void removeItem(int position); + void removeAllByAccountId(String accountId); } diff --git a/app/src/main/java/com/keylesspalace/tusky/interfaces/StatusRemoveListener.java b/app/src/main/java/com/keylesspalace/tusky/interfaces/StatusRemoveListener.java deleted file mode 100644 index c05f7657..00000000 --- a/app/src/main/java/com/keylesspalace/tusky/interfaces/StatusRemoveListener.java +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright 2017 Andrew Dawson - * - * This file is a part of Tusky. - * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation; either version 3 of the - * License, or (at your option) any later version. - * - * Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even - * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. - * - * You should have received a copy of the GNU General Public License along with Tusky; if not, - * see . */ - -package com.keylesspalace.tusky.interfaces; - -public interface StatusRemoveListener { - void removePostsByUser(String accountId); -} diff --git a/app/src/main/java/com/keylesspalace/tusky/receiver/TimelineReceiver.java b/app/src/main/java/com/keylesspalace/tusky/receiver/TimelineReceiver.java index 71a09413..89ebe925 100644 --- a/app/src/main/java/com/keylesspalace/tusky/receiver/TimelineReceiver.java +++ b/app/src/main/java/com/keylesspalace/tusky/receiver/TimelineReceiver.java @@ -4,9 +4,10 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.support.annotation.Nullable; -import com.keylesspalace.tusky.adapter.TimelineAdapter; import com.keylesspalace.tusky.fragment.TimelineFragment; +import com.keylesspalace.tusky.interfaces.AdapterItemRemover; public class TimelineReceiver extends BroadcastReceiver { public static final class Types { @@ -15,9 +16,9 @@ public class TimelineReceiver extends BroadcastReceiver { public static final String MUTE_ACCOUNT = "MUTE_ACCOUNT"; } - TimelineAdapter adapter; + AdapterItemRemover adapter; - public TimelineReceiver(TimelineAdapter adapter) { + public TimelineReceiver(AdapterItemRemover adapter) { super(); this.adapter = adapter; } @@ -28,7 +29,7 @@ public class TimelineReceiver extends BroadcastReceiver { adapter.removeAllByAccountId(id); } - public static IntentFilter getFilter(TimelineFragment.Kind kind) { + public static IntentFilter getFilter(@Nullable TimelineFragment.Kind kind) { IntentFilter intentFilter = new IntentFilter(); if (kind == TimelineFragment.Kind.HOME) { intentFilter.addAction(Types.UNFOLLOW_ACCOUNT);