Broadcasts now used everywhere for signalling to remove accounts' posts instead of listeners.
This commit is contained in:
parent
19f140f9c6
commit
9c56f0e7bc
15 changed files with 64 additions and 127 deletions
|
@ -32,7 +32,6 @@ import android.support.design.widget.CollapsingToolbarLayout;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.design.widget.TabLayout;
|
import android.support.design.widget.TabLayout;
|
||||||
import android.support.v4.app.Fragment;
|
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.support.v4.view.ViewCompat;
|
import android.support.v4.view.ViewCompat;
|
||||||
import android.support.v4.view.ViewPager;
|
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.Account;
|
||||||
import com.keylesspalace.tusky.entity.Relationship;
|
import com.keylesspalace.tusky.entity.Relationship;
|
||||||
import com.keylesspalace.tusky.fragment.SFragment;
|
|
||||||
import com.keylesspalace.tusky.interfaces.LinkListener;
|
import com.keylesspalace.tusky.interfaces.LinkListener;
|
||||||
import com.keylesspalace.tusky.interfaces.StatusRemoveListener;
|
|
||||||
import com.keylesspalace.tusky.pager.AccountPagerAdapter;
|
import com.keylesspalace.tusky.pager.AccountPagerAdapter;
|
||||||
import com.keylesspalace.tusky.receiver.TimelineReceiver;
|
import com.keylesspalace.tusky.receiver.TimelineReceiver;
|
||||||
import com.keylesspalace.tusky.util.LinkHelper;
|
import com.keylesspalace.tusky.util.LinkHelper;
|
||||||
|
@ -68,7 +65,7 @@ import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
import retrofit2.Response;
|
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 static final String TAG = "AccountActivity"; // logging tag
|
||||||
|
|
||||||
private enum FollowState {
|
private enum FollowState {
|
||||||
|
@ -82,7 +79,6 @@ public class AccountActivity extends BaseActivity implements SFragment.OnUserRem
|
||||||
private boolean blocking;
|
private boolean blocking;
|
||||||
private boolean muting;
|
private boolean muting;
|
||||||
private boolean isSelf;
|
private boolean isSelf;
|
||||||
private AccountPagerAdapter pagerAdapter;
|
|
||||||
private Account loadedAccount;
|
private Account loadedAccount;
|
||||||
|
|
||||||
@BindView(R.id.account_avatar) CircularImageView avatar;
|
@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.
|
// Setup the tabs and timeline pager.
|
||||||
AccountPagerAdapter adapter = new AccountPagerAdapter(getSupportFragmentManager(), this,
|
AccountPagerAdapter adapter = new AccountPagerAdapter(getSupportFragmentManager(), this,
|
||||||
accountId);
|
accountId);
|
||||||
pagerAdapter = adapter;
|
|
||||||
String[] pageTitles = {
|
String[] pageTitles = {
|
||||||
getString(R.string.title_statuses),
|
getString(R.string.title_statuses),
|
||||||
getString(R.string.title_follows),
|
getString(R.string.title_follows),
|
||||||
|
@ -357,16 +352,6 @@ public class AccountActivity extends BaseActivity implements SFragment.OnUserRem
|
||||||
updateButtons();
|
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) {
|
private void updateFollowButton(FloatingActionButton button) {
|
||||||
switch (followState) {
|
switch (followState) {
|
||||||
case NOT_FOLLOWING: {
|
case NOT_FOLLOWING: {
|
||||||
|
|
|
@ -23,13 +23,9 @@ import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import com.keylesspalace.tusky.fragment.SFragment;
|
|
||||||
import com.keylesspalace.tusky.fragment.TimelineFragment;
|
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
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -48,8 +44,6 @@ public class FavouritesActivity extends BaseActivity implements SFragment.OnUser
|
||||||
Fragment fragment = TimelineFragment.newInstance(TimelineFragment.Kind.FAVOURITES);
|
Fragment fragment = TimelineFragment.newInstance(TimelineFragment.Kind.FAVOURITES);
|
||||||
fragmentTransaction.add(R.id.fragment_container, fragment);
|
fragmentTransaction.add(R.id.fragment_container, fragment);
|
||||||
fragmentTransaction.commit();
|
fragmentTransaction.commit();
|
||||||
|
|
||||||
statusRemoveListener = (StatusRemoveListener) fragment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -62,9 +56,4 @@ public class FavouritesActivity extends BaseActivity implements SFragment.OnUser
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onUserRemoved(String accountId) {
|
|
||||||
statusRemoveListener.removePostsByUser(accountId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,6 @@ import com.arlib.floatingsearchview.suggestions.SearchSuggestionsAdapter;
|
||||||
import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion;
|
import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion;
|
||||||
import com.keylesspalace.tusky.entity.Account;
|
import com.keylesspalace.tusky.entity.Account;
|
||||||
import com.keylesspalace.tusky.fragment.SFragment;
|
import com.keylesspalace.tusky.fragment.SFragment;
|
||||||
import com.keylesspalace.tusky.interfaces.StatusRemoveListener;
|
|
||||||
import com.keylesspalace.tusky.pager.TimelinePagerAdapter;
|
import com.keylesspalace.tusky.pager.TimelinePagerAdapter;
|
||||||
import com.keylesspalace.tusky.util.ThemeUtils;
|
import com.keylesspalace.tusky.util.ThemeUtils;
|
||||||
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
|
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
|
||||||
|
@ -74,7 +73,7 @@ import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
import retrofit2.Response;
|
import retrofit2.Response;
|
||||||
|
|
||||||
public class MainActivity extends BaseActivity implements SFragment.OnUserRemovedListener {
|
public class MainActivity extends BaseActivity {
|
||||||
private static final String TAG = "MainActivity"; // logging tag
|
private static final String TAG = "MainActivity"; // logging tag
|
||||||
protected static int COMPOSE_RESULT = 1;
|
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.)
|
// Fix for GitHub issues #190, #259 (MainActivity won't restart on screen rotation.)
|
||||||
@Override
|
@Override
|
||||||
public void onConfigurationChanged(Configuration newConfig) {
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
|
|
|
@ -23,16 +23,12 @@ import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import com.keylesspalace.tusky.fragment.SFragment;
|
|
||||||
import com.keylesspalace.tusky.fragment.TimelineFragment;
|
import com.keylesspalace.tusky.fragment.TimelineFragment;
|
||||||
import com.keylesspalace.tusky.interfaces.StatusRemoveListener;
|
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
|
||||||
public class ViewTagActivity extends BaseActivity implements SFragment.OnUserRemovedListener {
|
public class ViewTagActivity extends BaseActivity {
|
||||||
private Fragment timelineFragment;
|
|
||||||
|
|
||||||
@BindView(R.id.toolbar) Toolbar toolbar;
|
@BindView(R.id.toolbar) Toolbar toolbar;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -57,8 +53,6 @@ public class ViewTagActivity extends BaseActivity implements SFragment.OnUserRem
|
||||||
Fragment fragment = TimelineFragment.newInstance(TimelineFragment.Kind.TAG, hashtag);
|
Fragment fragment = TimelineFragment.newInstance(TimelineFragment.Kind.TAG, hashtag);
|
||||||
fragmentTransaction.add(R.id.fragment_container, fragment);
|
fragmentTransaction.add(R.id.fragment_container, fragment);
|
||||||
fragmentTransaction.commit();
|
fragmentTransaction.commit();
|
||||||
|
|
||||||
timelineFragment = fragment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -71,10 +65,4 @@ public class ViewTagActivity extends BaseActivity implements SFragment.OnUserRem
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onUserRemoved(String accountId) {
|
|
||||||
StatusRemoveListener listener = (StatusRemoveListener) timelineFragment;
|
|
||||||
listener.removePostsByUser(accountId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,13 +25,9 @@ import android.support.v7.widget.Toolbar;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import com.keylesspalace.tusky.fragment.SFragment;
|
|
||||||
import com.keylesspalace.tusky.fragment.ViewThreadFragment;
|
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
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -51,8 +47,6 @@ public class ViewThreadActivity extends BaseActivity implements SFragment.OnUser
|
||||||
Fragment fragment = ViewThreadFragment.newInstance(id);
|
Fragment fragment = ViewThreadFragment.newInstance(id);
|
||||||
fragmentTransaction.add(R.id.fragment_container, fragment);
|
fragmentTransaction.add(R.id.fragment_container, fragment);
|
||||||
fragmentTransaction.commit();
|
fragmentTransaction.commit();
|
||||||
|
|
||||||
viewThreadFragment = fragment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -72,14 +66,6 @@ public class ViewThreadActivity extends BaseActivity implements SFragment.OnUser
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onUserRemoved(String accountId) {
|
|
||||||
if (viewThreadFragment instanceof StatusRemoveListener) {
|
|
||||||
StatusRemoveListener listener = (StatusRemoveListener) viewThreadFragment;
|
|
||||||
listener.removePostsByUser(accountId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConfigurationChanged(Configuration newConfig) {
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
super.onConfigurationChanged(newConfig);
|
super.onConfigurationChanged(newConfig);
|
||||||
|
|
|
@ -209,11 +209,13 @@ public class NotificationsAdapter extends RecyclerView.Adapter implements Adapte
|
||||||
notifyItemRangeInserted(end, new_notifications.size());
|
notifyItemRangeInserted(end, new_notifications.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void removeItem(int position) {
|
public void removeItem(int position) {
|
||||||
notifications.remove(position);
|
notifications.remove(position);
|
||||||
notifyItemChanged(position);
|
notifyItemChanged(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void removeAllByAccountId(String id) {
|
public void removeAllByAccountId(String id) {
|
||||||
for (int i = 0; i < notifications.size();) {
|
for (int i = 0; i < notifications.size();) {
|
||||||
Notification notification = notifications.get(i);
|
Notification notification = notifications.get(i);
|
||||||
|
|
|
@ -62,11 +62,13 @@ public class ThreadAdapter extends RecyclerView.Adapter implements AdapterItemRe
|
||||||
return statuses.get(position);
|
return statuses.get(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void removeItem(int position) {
|
public void removeItem(int position) {
|
||||||
statuses.remove(position);
|
statuses.remove(position);
|
||||||
notifyItemRemoved(position);
|
notifyItemRemoved(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void removeAllByAccountId(String accountId) {
|
public void removeAllByAccountId(String accountId) {
|
||||||
for (int i = 0; i < statuses.size();) {
|
for (int i = 0; i < statuses.size();) {
|
||||||
Status status = statuses.get(i);
|
Status status = statuses.get(i);
|
||||||
|
|
|
@ -140,16 +140,13 @@ public class TimelineAdapter extends RecyclerView.Adapter implements AdapterItem
|
||||||
notifyItemRangeInserted(end, newStatuses.size());
|
notifyItemRangeInserted(end, newStatuses.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void removeItem(int position) {
|
public void removeItem(int position) {
|
||||||
statuses.remove(position);
|
statuses.remove(position);
|
||||||
notifyItemRemoved(position);
|
notifyItemRemoved(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
@Override
|
||||||
statuses.clear();
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeAllByAccountId(String accountId) {
|
public void removeAllByAccountId(String accountId) {
|
||||||
for (int i = 0; i < statuses.size();) {
|
for (int i = 0; i < statuses.size();) {
|
||||||
Status status = statuses.get(i);
|
Status status = statuses.get(i);
|
||||||
|
@ -162,6 +159,11 @@ public class TimelineAdapter extends RecyclerView.Adapter implements AdapterItem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
statuses.clear();
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Status getItem(int position) {
|
public Status getItem(int position) {
|
||||||
if (position >= 0 && position < statuses.size()) {
|
if (position >= 0 && position < statuses.size()) {
|
||||||
|
|
|
@ -23,6 +23,7 @@ import android.preference.PreferenceManager;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.design.widget.TabLayout;
|
import android.support.design.widget.TabLayout;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.support.v7.widget.DividerItemDecoration;
|
import android.support.v7.widget.DividerItemDecoration;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
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.Notification;
|
||||||
import com.keylesspalace.tusky.entity.Status;
|
import com.keylesspalace.tusky.entity.Status;
|
||||||
import com.keylesspalace.tusky.interfaces.StatusActionListener;
|
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.util.ThemeUtils;
|
||||||
import com.keylesspalace.tusky.view.EndlessOnScrollListener;
|
import com.keylesspalace.tusky.view.EndlessOnScrollListener;
|
||||||
|
|
||||||
|
import java.sql.Time;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
|
@ -50,8 +52,9 @@ import retrofit2.Callback;
|
||||||
import retrofit2.Response;
|
import retrofit2.Response;
|
||||||
|
|
||||||
public class NotificationsFragment extends SFragment implements
|
public class NotificationsFragment extends SFragment implements
|
||||||
SwipeRefreshLayout.OnRefreshListener, StatusActionListener, StatusRemoveListener,
|
SwipeRefreshLayout.OnRefreshListener, StatusActionListener,
|
||||||
NotificationsAdapter.NotificationActionListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
NotificationsAdapter.NotificationActionListener,
|
||||||
|
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
private static final String TAG = "Notifications"; // logging tag
|
private static final String TAG = "Notifications"; // logging tag
|
||||||
|
|
||||||
private SwipeRefreshLayout swipeRefreshLayout;
|
private SwipeRefreshLayout swipeRefreshLayout;
|
||||||
|
@ -62,6 +65,7 @@ public class NotificationsFragment extends SFragment implements
|
||||||
private TabLayout.OnTabSelectedListener onTabSelectedListener;
|
private TabLayout.OnTabSelectedListener onTabSelectedListener;
|
||||||
private Call<List<Notification>> listCall;
|
private Call<List<Notification>> listCall;
|
||||||
private boolean hideFab;
|
private boolean hideFab;
|
||||||
|
private TimelineReceiver timelineReceiver;
|
||||||
|
|
||||||
public static NotificationsFragment newInstance() {
|
public static NotificationsFragment newInstance() {
|
||||||
NotificationsFragment fragment = new NotificationsFragment();
|
NotificationsFragment fragment = new NotificationsFragment();
|
||||||
|
@ -110,6 +114,10 @@ public class NotificationsFragment extends SFragment implements
|
||||||
};
|
};
|
||||||
layout.addOnTabSelectedListener(onTabSelectedListener);
|
layout.addOnTabSelectedListener(onTabSelectedListener);
|
||||||
|
|
||||||
|
timelineReceiver = new TimelineReceiver(adapter);
|
||||||
|
LocalBroadcastManager.getInstance(context.getApplicationContext())
|
||||||
|
.registerReceiver(timelineReceiver, TimelineReceiver.getFilter(null));
|
||||||
|
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,6 +176,10 @@ public class NotificationsFragment extends SFragment implements
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
TabLayout tabLayout = (TabLayout) getActivity().findViewById(R.id.tab_layout);
|
TabLayout tabLayout = (TabLayout) getActivity().findViewById(R.id.tab_layout);
|
||||||
tabLayout.removeOnTabSelectedListener(onTabSelectedListener);
|
tabLayout.removeOnTabSelectedListener(onTabSelectedListener);
|
||||||
|
|
||||||
|
LocalBroadcastManager.getInstance(getContext())
|
||||||
|
.unregisterReceiver(timelineReceiver);
|
||||||
|
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,10 +217,6 @@ public class NotificationsFragment extends SFragment implements
|
||||||
sendFetchNotificationsRequest(null, null);
|
sendFetchNotificationsRequest(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removePostsByUser(String accountId) {
|
|
||||||
adapter.removeAllByAccountId(accountId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean findNotification(List<Notification> notifications, String id) {
|
private static boolean findNotification(List<Notification> notifications, String id) {
|
||||||
for (Notification notification : notifications) {
|
for (Notification notification : notifications) {
|
||||||
if (notification.id.equals(id)) {
|
if (notification.id.equals(id)) {
|
||||||
|
|
|
@ -21,6 +21,7 @@ import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.support.v7.widget.PopupMenu;
|
import android.support.v7.widget.PopupMenu;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
|
@ -39,6 +40,7 @@ import com.keylesspalace.tusky.entity.Relationship;
|
||||||
import com.keylesspalace.tusky.entity.Status;
|
import com.keylesspalace.tusky.entity.Status;
|
||||||
import com.keylesspalace.tusky.interfaces.AdapterItemRemover;
|
import com.keylesspalace.tusky.interfaces.AdapterItemRemover;
|
||||||
import com.keylesspalace.tusky.network.MastodonAPI;
|
import com.keylesspalace.tusky.network.MastodonAPI;
|
||||||
|
import com.keylesspalace.tusky.receiver.TimelineReceiver;
|
||||||
import com.keylesspalace.tusky.util.HtmlUtils;
|
import com.keylesspalace.tusky.util.HtmlUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
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
|
* overlap functionality. So, I'm momentarily leaving it and hopefully working on those will clear
|
||||||
* up what needs to be where. */
|
* up what needs to be where. */
|
||||||
public abstract class SFragment extends BaseFragment {
|
public abstract class SFragment extends BaseFragment {
|
||||||
public interface OnUserRemovedListener {
|
|
||||||
void onUserRemoved(String accountId);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String loggedInAccountId;
|
protected String loggedInAccountId;
|
||||||
protected String loggedInUsername;
|
protected String loggedInUsername;
|
||||||
protected MastodonAPI mastodonAPI;
|
protected MastodonAPI mastodonAPI;
|
||||||
protected OnUserRemovedListener userRemovedListener;
|
|
||||||
protected static int COMPOSE_RESULT = 1;
|
protected static int COMPOSE_RESULT = 1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -80,7 +77,6 @@ public abstract class SFragment extends BaseFragment {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
BaseActivity activity = (BaseActivity) getActivity();
|
BaseActivity activity = (BaseActivity) getActivity();
|
||||||
mastodonAPI = activity.mastodonAPI;
|
mastodonAPI = activity.mastodonAPI;
|
||||||
userRemovedListener = (OnUserRemovedListener) activity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void reply(Status status) {
|
protected void reply(Status status) {
|
||||||
|
@ -188,7 +184,10 @@ public abstract class SFragment extends BaseFragment {
|
||||||
public void onFailure(Call<Relationship> call, Throwable t) {}
|
public void onFailure(Call<Relationship> call, Throwable t) {}
|
||||||
});
|
});
|
||||||
callList.add(call);
|
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) {
|
private void block(String id) {
|
||||||
|
@ -201,7 +200,10 @@ public abstract class SFragment extends BaseFragment {
|
||||||
public void onFailure(Call<Relationship> call, Throwable t) {}
|
public void onFailure(Call<Relationship> call, Throwable t) {}
|
||||||
});
|
});
|
||||||
callList.add(call);
|
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) {
|
private void delete(String id) {
|
||||||
|
|
|
@ -38,7 +38,6 @@ import com.keylesspalace.tusky.R;
|
||||||
import com.keylesspalace.tusky.adapter.TimelineAdapter;
|
import com.keylesspalace.tusky.adapter.TimelineAdapter;
|
||||||
import com.keylesspalace.tusky.entity.Status;
|
import com.keylesspalace.tusky.entity.Status;
|
||||||
import com.keylesspalace.tusky.interfaces.StatusActionListener;
|
import com.keylesspalace.tusky.interfaces.StatusActionListener;
|
||||||
import com.keylesspalace.tusky.interfaces.StatusRemoveListener;
|
|
||||||
import com.keylesspalace.tusky.receiver.TimelineReceiver;
|
import com.keylesspalace.tusky.receiver.TimelineReceiver;
|
||||||
import com.keylesspalace.tusky.util.ThemeUtils;
|
import com.keylesspalace.tusky.util.ThemeUtils;
|
||||||
import com.keylesspalace.tusky.view.EndlessOnScrollListener;
|
import com.keylesspalace.tusky.view.EndlessOnScrollListener;
|
||||||
|
@ -53,7 +52,6 @@ import retrofit2.Response;
|
||||||
public class TimelineFragment extends SFragment implements
|
public class TimelineFragment extends SFragment implements
|
||||||
SwipeRefreshLayout.OnRefreshListener,
|
SwipeRefreshLayout.OnRefreshListener,
|
||||||
StatusActionListener,
|
StatusActionListener,
|
||||||
StatusRemoveListener,
|
|
||||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
private static final String TAG = "Timeline"; // logging tag
|
private static final String TAG = "Timeline"; // logging tag
|
||||||
|
|
||||||
|
@ -128,7 +126,8 @@ public class TimelineFragment extends SFragment implements
|
||||||
recyclerView.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
timelineReceiver = new TimelineReceiver(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;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,10 +284,6 @@ public class TimelineFragment extends SFragment implements
|
||||||
listCall.enqueue(callback);
|
listCall.enqueue(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removePostsByUser(String accountId) {
|
|
||||||
adapter.removeAllByAccountId(accountId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean findStatus(List<Status> statuses, String id) {
|
private static boolean findStatus(List<Status> statuses, String id) {
|
||||||
for (Status status : statuses) {
|
for (Status status : statuses) {
|
||||||
if (status.id.equals(id)) {
|
if (status.id.equals(id)) {
|
||||||
|
|
|
@ -21,6 +21,7 @@ import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.support.v7.widget.DividerItemDecoration;
|
import android.support.v7.widget.DividerItemDecoration;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
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.network.MastodonAPI;
|
||||||
import com.keylesspalace.tusky.R;
|
import com.keylesspalace.tusky.R;
|
||||||
import com.keylesspalace.tusky.interfaces.StatusActionListener;
|
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.util.ThemeUtils;
|
||||||
import com.keylesspalace.tusky.view.ConversationLineItemDecoration;
|
import com.keylesspalace.tusky.view.ConversationLineItemDecoration;
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@ import retrofit2.Callback;
|
||||||
import retrofit2.Response;
|
import retrofit2.Response;
|
||||||
|
|
||||||
public class ViewThreadFragment extends SFragment implements
|
public class ViewThreadFragment extends SFragment implements
|
||||||
SwipeRefreshLayout.OnRefreshListener, StatusActionListener, StatusRemoveListener {
|
SwipeRefreshLayout.OnRefreshListener, StatusActionListener {
|
||||||
private static final String TAG = "ViewThreadFragment";
|
private static final String TAG = "ViewThreadFragment";
|
||||||
|
|
||||||
private SwipeRefreshLayout swipeRefreshLayout;
|
private SwipeRefreshLayout swipeRefreshLayout;
|
||||||
|
@ -55,6 +56,7 @@ public class ViewThreadFragment extends SFragment implements
|
||||||
private ThreadAdapter adapter;
|
private ThreadAdapter adapter;
|
||||||
private MastodonAPI mastodonApi;
|
private MastodonAPI mastodonApi;
|
||||||
private String thisThreadsStatusId;
|
private String thisThreadsStatusId;
|
||||||
|
private TimelineReceiver timelineReceiver;
|
||||||
|
|
||||||
public static ViewThreadFragment newInstance(String id) {
|
public static ViewThreadFragment newInstance(String id) {
|
||||||
Bundle arguments = new Bundle();
|
Bundle arguments = new Bundle();
|
||||||
|
@ -92,9 +94,20 @@ public class ViewThreadFragment extends SFragment implements
|
||||||
mastodonApi = null;
|
mastodonApi = null;
|
||||||
thisThreadsStatusId = null;
|
thisThreadsStatusId = null;
|
||||||
|
|
||||||
|
timelineReceiver = new TimelineReceiver(adapter);
|
||||||
|
LocalBroadcastManager.getInstance(context.getApplicationContext())
|
||||||
|
.registerReceiver(timelineReceiver, TimelineReceiver.getFilter(null));
|
||||||
|
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
LocalBroadcastManager.getInstance(getContext())
|
||||||
|
.unregisterReceiver(timelineReceiver);
|
||||||
|
super.onDestroyView();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(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() {
|
public void onRefresh() {
|
||||||
sendStatusRequest(thisThreadsStatusId);
|
sendStatusRequest(thisThreadsStatusId);
|
||||||
sendThreadRequest(thisThreadsStatusId);
|
sendThreadRequest(thisThreadsStatusId);
|
||||||
|
|
|
@ -17,4 +17,5 @@ package com.keylesspalace.tusky.interfaces;
|
||||||
|
|
||||||
public interface AdapterItemRemover {
|
public interface AdapterItemRemover {
|
||||||
void removeItem(int position);
|
void removeItem(int position);
|
||||||
|
void removeAllByAccountId(String accountId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 <http://www.gnu.org/licenses>. */
|
|
||||||
|
|
||||||
package com.keylesspalace.tusky.interfaces;
|
|
||||||
|
|
||||||
public interface StatusRemoveListener {
|
|
||||||
void removePostsByUser(String accountId);
|
|
||||||
}
|
|
|
@ -4,9 +4,10 @@ import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
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.fragment.TimelineFragment;
|
||||||
|
import com.keylesspalace.tusky.interfaces.AdapterItemRemover;
|
||||||
|
|
||||||
public class TimelineReceiver extends BroadcastReceiver {
|
public class TimelineReceiver extends BroadcastReceiver {
|
||||||
public static final class Types {
|
public static final class Types {
|
||||||
|
@ -15,9 +16,9 @@ public class TimelineReceiver extends BroadcastReceiver {
|
||||||
public static final String MUTE_ACCOUNT = "MUTE_ACCOUNT";
|
public static final String MUTE_ACCOUNT = "MUTE_ACCOUNT";
|
||||||
}
|
}
|
||||||
|
|
||||||
TimelineAdapter adapter;
|
AdapterItemRemover adapter;
|
||||||
|
|
||||||
public TimelineReceiver(TimelineAdapter adapter) {
|
public TimelineReceiver(AdapterItemRemover adapter) {
|
||||||
super();
|
super();
|
||||||
this.adapter = adapter;
|
this.adapter = adapter;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +29,7 @@ public class TimelineReceiver extends BroadcastReceiver {
|
||||||
adapter.removeAllByAccountId(id);
|
adapter.removeAllByAccountId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IntentFilter getFilter(TimelineFragment.Kind kind) {
|
public static IntentFilter getFilter(@Nullable TimelineFragment.Kind kind) {
|
||||||
IntentFilter intentFilter = new IntentFilter();
|
IntentFilter intentFilter = new IntentFilter();
|
||||||
if (kind == TimelineFragment.Kind.HOME) {
|
if (kind == TimelineFragment.Kind.HOME) {
|
||||||
intentFilter.addAction(Types.UNFOLLOW_ACCOUNT);
|
intentFilter.addAction(Types.UNFOLLOW_ACCOUNT);
|
||||||
|
|
Loading…
Add table
Reference in a new issue