Broadcasts now cause a refresh on timelines after a post is composed instead of listeners.

As a side effect, pagers don't have to keep track of "registered fragments", which was a bad idea and caused crashes.
This commit is contained in:
Vavassor 2017-06-06 18:20:55 -04:00
commit a4ee128e26
8 changed files with 36 additions and 108 deletions

View file

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import com.keylesspalace.tusky.fragment.TimelineFragment;
import com.keylesspalace.tusky.interfaces.AdapterItemRemover;
@ -14,19 +15,39 @@ public class TimelineReceiver extends BroadcastReceiver {
public static final String UNFOLLOW_ACCOUNT = "UNFOLLOW_ACCOUNT";
public static final String BLOCK_ACCOUNT = "BLOCK_ACCOUNT";
public static final String MUTE_ACCOUNT = "MUTE_ACCOUNT";
public static final String STATUS_COMPOSED = "STATUS_COMPOSED";
}
AdapterItemRemover adapter;
SwipeRefreshLayout.OnRefreshListener refreshListener;
public TimelineReceiver(AdapterItemRemover adapter) {
super();
this.adapter = adapter;
}
public TimelineReceiver(AdapterItemRemover adapter,
SwipeRefreshLayout.OnRefreshListener refreshListener) {
super();
this.adapter = adapter;
this.refreshListener = refreshListener;
}
@Override
public void onReceive(Context context, final Intent intent) {
String id = intent.getStringExtra("id");
adapter.removeAllByAccountId(id);
switch (intent.getAction()) {
case Types.STATUS_COMPOSED: {
if (refreshListener != null) {
refreshListener.onRefresh();
}
break;
}
default: {
String id = intent.getStringExtra("id");
adapter.removeAllByAccountId(id);
break;
}
}
}
public static IntentFilter getFilter(@Nullable TimelineFragment.Kind kind) {
@ -36,6 +57,12 @@ public class TimelineReceiver extends BroadcastReceiver {
}
intentFilter.addAction(Types.BLOCK_ACCOUNT);
intentFilter.addAction(Types.MUTE_ACCOUNT);
if (kind == null
|| kind == TimelineFragment.Kind.HOME
|| kind == TimelineFragment.Kind.PUBLIC_FEDERATED
|| kind == TimelineFragment.Kind.PUBLIC_LOCAL) {
intentFilter.addAction(Types.STATUS_COMPOSED);
}
return intentFilter;
}