Merge branch 'issue_133' of https://github.com/raphaelm/Tusky into raphaelm-issue_133

This commit is contained in:
Vavassor 2017-05-01 21:50:24 -04:00
commit 9bb8c96f00
5 changed files with 65 additions and 0 deletions

View File

@ -142,6 +142,11 @@ class TimelineAdapter extends RecyclerView.Adapter implements AdapterItemRemover
notifyItemRemoved(position);
}
public void clear() {
statuses.clear();
notifyDataSetChanged();
}
void removeAllByAccountId(String accountId) {
for (int i = 0; i < statuses.size();) {
Status status = statuses.get(i);

View File

@ -33,6 +33,7 @@ import android.view.ViewGroup;
import com.keylesspalace.tusky.entity.Status;
import java.util.Iterator;
import java.util.List;
import retrofit2.Call;
@ -64,6 +65,9 @@ public class TimelineFragment extends SFragment implements
private LinearLayoutManager layoutManager;
private EndlessOnScrollListener scrollListener;
private TabLayout.OnTabSelectedListener onTabSelectedListener;
private SharedPreferences preferences;
private boolean filterRemoveReplies;
private boolean filterRemoveReblogs;
private boolean hideFab;
public static TimelineFragment newInstance(Kind kind) {
@ -189,6 +193,8 @@ public class TimelineFragment extends SFragment implements
};
}
recyclerView.addOnScrollListener(scrollListener);
preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
}
@Override
@ -288,7 +294,36 @@ public class TimelineFragment extends SFragment implements
return false;
}
protected void filterStatuses(List<Status> statuses) {
Iterator<Status> it = statuses.iterator();
while (it.hasNext()) {
Status status = it.next();
if ((status.inReplyToId != null && filterRemoveReplies) || (status.reblog != null && filterRemoveReblogs)) {
it.remove();
}
}
}
protected void setFiltersFromSettings() {
boolean oldRemoveReplies = filterRemoveReplies;
boolean oldRemoveReblogs = filterRemoveReblogs;
filterRemoveReplies = (kind == Kind.HOME && !preferences.getBoolean("tabFilterHomeReplies", true));
filterRemoveReblogs = (kind == Kind.HOME && !preferences.getBoolean("tabFilterHomeBoosts", true));
if (adapter.getItemCount() > 1 && (oldRemoveReblogs != filterRemoveReblogs || oldRemoveReplies != filterRemoveReplies)) {
adapter.clear();
sendFetchTimelineRequest();
}
}
@Override
public void onResume() {
super.onResume();
setFiltersFromSettings();
}
public void onFetchTimelineSuccess(List<Status> statuses, String fromId) {
filterStatuses(statuses);
if (fromId != null) {
if (statuses.size() > 0 && !findStatus(statuses, fromId)) {
adapter.addItems(statuses);

View File

@ -20,6 +20,7 @@
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/toolbar_background_color"
app:collapsedTitleTextAppearance="?attr/android:textColorPrimary"
android:fitsSystemWindows="true"
app:titleEnabled="false">

View File

@ -156,6 +156,10 @@
<string name="pref_title_browser_settings">Browser</string>
<string name="pref_title_custom_tabs">Use Chrome Custom Tabs</string>
<string name="pref_title_hide_follow_button">Hide follow button while scrolling</string>
<string name="pref_title_status_filter">Toot filtering</string>
<string name="pref_title_status_tabs">Tabs</string>
<string name="pref_title_show_boosts">Show boosts</string>
<string name="pref_title_show_replies">Show replies</string>
<string name="notification_mention_format">%s mentioned you</string>
<string name="notification_summary_large">%1$s, %2$s, %3$s and %4$d others</string>

View File

@ -21,6 +21,26 @@
android:title="@string/pref_title_custom_tabs"
android:defaultValue="true" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_title_status_filter">
<PreferenceScreen android:title="@string/pref_title_status_tabs">
<PreferenceCategory
android:dependency="notificationsEnabled"
android:title="@string/title_home">
<CheckBoxPreference
android:key="tabFilterHomeBoosts"
android:title="@string/pref_title_show_boosts"
android:defaultValue="true" />
<CheckBoxPreference
android:key="tabFilterHomeReplies"
android:title="@string/pref_title_show_replies"
android:defaultValue="true" />
</PreferenceCategory>
</PreferenceScreen>
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_title_notification_settings">
<PreferenceScreen android:title="@string/pref_title_edit_notification_settings">