mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
#1694 Feed intelligence filter
This commit is contained in:
parent
f56b0bdfbc
commit
a8626b430f
10 changed files with 73 additions and 178 deletions
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="true" android:drawable="@drawable/toggle_bg_selected" />
|
||||
<item android:state_enabled="false" android:drawable="@drawable/toggle_bg_selected" />
|
||||
<item android:state_focused="true" android:drawable="@android:color/transparent" />
|
||||
<item android:drawable="@android:color/transparent" />
|
||||
</selector>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/toggle_bg_selected" android:state_pressed="true" />
|
||||
<item android:drawable="@drawable/toggle_bg_selected" android:state_enabled="false" />
|
||||
<item android:drawable="@android:color/transparent" android:state_focused="true" />
|
||||
<item android:drawable="@android:color/transparent" />
|
||||
</selector>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle" >
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@color/bg_midgray" />
|
||||
<corners android:radius="4dp" />
|
||||
</shape>
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<item>
|
||||
<shape>
|
||||
<!-- on API 14 and 15, the default solid is a black square, not nothing. -->
|
||||
<solid android:color="@android:color/transparent" />
|
||||
<padding
|
||||
android:bottom="1.5dp"
|
||||
android:top="1.5dp"
|
||||
android:left="1.5dp"
|
||||
android:right="1.5dp"
|
||||
/>
|
||||
<stroke
|
||||
android:color="@color/gray55"
|
||||
android:width="1.5dp"
|
||||
android:height="1.5dp"
|
||||
/>
|
||||
<corners android:radius="2dp" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
</layer-list>
|
|
@ -196,16 +196,16 @@
|
|||
|
||||
<!-- top_bar_border -->
|
||||
<View
|
||||
style="?delimiter"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/gray55"
|
||||
android:layout_above="@id/swipe_container" />
|
||||
|
||||
<!-- feedintelligenceselector_border -->
|
||||
<View
|
||||
style="?delimiter"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/gray55"
|
||||
android:layout_below="@id/swipe_container" />
|
||||
|
||||
<TextView
|
||||
|
|
|
@ -2,26 +2,24 @@
|
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:background="@drawable/toggle_set_border"
|
||||
android:baselineAligned="false"
|
||||
android:animateLayoutChanges="true"
|
||||
>
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/toggle_all"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="1dp"
|
||||
android:layout_weight="1"
|
||||
android:animateLayoutChanges="true"
|
||||
android:background="@drawable/intel_toggle_background_selector"
|
||||
android:paddingLeft="9dp"
|
||||
android:paddingRight="9dp"
|
||||
android:paddingTop="6dp"
|
||||
android:paddingBottom="6dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:animateLayoutChanges="true" >
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingTop="6dp"
|
||||
android:paddingRight="8dp"
|
||||
android:paddingBottom="6dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/toggle_all_icon"
|
||||
|
@ -32,108 +30,77 @@
|
|||
|
||||
<TextView
|
||||
android:id="@+id/toggle_all_text"
|
||||
style="?toggleText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:enabled="false"
|
||||
android:text="@string/state_all"
|
||||
style="?toggleText"
|
||||
/>
|
||||
android:gravity="center"
|
||||
android:text="@string/state_all" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/toggle_some"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="1dp"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/intel_toggle_background_selector"
|
||||
android:paddingLeft="9dp"
|
||||
android:paddingRight="9dp"
|
||||
android:paddingTop="6dp"
|
||||
android:paddingBottom="6dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:animateLayoutChanges="true" >
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingTop="6dp"
|
||||
android:paddingRight="8dp"
|
||||
android:paddingBottom="6dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/toggle_some_icon"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:paddingRight="4dp"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@drawable/ic_indicator_unread" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/toggle_some_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:enabled="false"
|
||||
android:text="@string/state_unread"
|
||||
style="?toggleText"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/toggle_focus"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="1dp"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/intel_toggle_background_selector"
|
||||
android:paddingLeft="9dp"
|
||||
android:paddingRight="9dp"
|
||||
android:paddingTop="6dp"
|
||||
android:paddingBottom="6dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:animateLayoutChanges="true" >
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingTop="6dp"
|
||||
android:paddingRight="8dp"
|
||||
android:paddingBottom="6dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/toggle_focus_icon"
|
||||
android:layout_width="18dp"
|
||||
android:layout_height="18dp"
|
||||
android:paddingRight="4dp"
|
||||
android:src="@drawable/ic_indicator_focus" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/toggle_focus_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="@string/state_focus"
|
||||
style="?toggleText"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/toggle_saved"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="1dp"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/intel_toggle_background_selector"
|
||||
android:paddingLeft="9dp"
|
||||
android:paddingRight="9dp"
|
||||
android:paddingTop="6dp"
|
||||
android:paddingBottom="6dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:animateLayoutChanges="true" >
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingTop="6dp"
|
||||
android:paddingRight="8dp"
|
||||
android:paddingBottom="6dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/toggle_saved_icon"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:paddingRight="4dp"
|
||||
android:src="@drawable/ic_saved" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/toggle_saved_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="@string/state_saved"
|
||||
style="?toggleText"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
<attr name="selectorOverlayBackgroundText" format="string" />
|
||||
<attr name="muteicon" format="string" />
|
||||
<attr name="circleProgressIndicator" format="string" />
|
||||
<attr name="delimiter" format="string" />
|
||||
|
||||
<attr name="flow" format="string" />
|
||||
<attr name="imageViewSize" format="integer" />
|
||||
|
|
|
@ -32,6 +32,13 @@
|
|||
<item name="fontFamily">@font/whitney</item>
|
||||
</style>
|
||||
|
||||
<style name="delimiter">
|
||||
<item name="android:background">@color/gray85</item>
|
||||
</style>
|
||||
<style name="delimiter.dark">
|
||||
<item name="android:background">@color/gray30</item>
|
||||
</style>
|
||||
|
||||
<style name="selectorFolderParent">
|
||||
<item name="android:paddingTop">2dp</item>
|
||||
<item name="android:paddingBottom">2dp</item>
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
<item name="activityDetailsPager">@style/activityDetailsPager</item>
|
||||
<item name="explainerText">@style/explainerText</item>
|
||||
<item name="toggleText">@style/toggleText</item>
|
||||
<item name="delimiter">@style/delimiter</item>
|
||||
<item name="selectorOverlayBackgroundLeft">@style/selectorOverlayBackgroundLeft</item>
|
||||
<item name="selectorOverlayBackgroundRight">@style/selectorOverlayBackgroundRight</item>
|
||||
<item name="selectorOverlayBackgroundRightDone">@style/selectorOverlayBackgroundRightDone</item>
|
||||
|
@ -93,6 +94,7 @@
|
|||
<item name="activityDetailsPager">@style/activityDetailsPager.dark</item>
|
||||
<item name="explainerText">@style/explainerText.dark</item>
|
||||
<item name="toggleText">@style/toggleText.dark</item>
|
||||
<item name="delimiter">@style/delimiter.dark</item>
|
||||
<item name="selectorOverlayBackgroundLeft">@style/selectorOverlayBackgroundLeft.dark</item>
|
||||
<item name="selectorOverlayBackgroundRight">@style/selectorOverlayBackgroundRight.dark</item>
|
||||
<item name="selectorOverlayBackgroundRightDone">@style/selectorOverlayBackgroundRightDone.dark</item>
|
||||
|
@ -147,6 +149,7 @@
|
|||
<item name="activityDetailsPager">@style/activityDetailsPager.black</item>
|
||||
<item name="explainerText">@style/explainerText.dark</item>
|
||||
<item name="toggleText">@style/toggleText.dark</item>
|
||||
<item name="delimiter">@style/delimiter.dark</item>
|
||||
<item name="selectorOverlayBackgroundLeft">@style/selectorOverlayBackgroundLeft.dark</item>
|
||||
<item name="selectorOverlayBackgroundRight">@style/selectorOverlayBackgroundRight.dark</item>
|
||||
<item name="selectorOverlayBackgroundRightDone">@style/selectorOverlayBackgroundRightDone.dark</item>
|
||||
|
|
|
@ -21,13 +21,6 @@ public class FeedIntelligenceSelectorFragment extends Fragment implements StateC
|
|||
final View v = inflater.inflate(R.layout.fragment_intelligenceselector, null);
|
||||
button = (StateToggleButton) v.findViewById(R.id.fragment_intelligence_statebutton);
|
||||
button.setStateListener(this);
|
||||
v.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
button.setParentWidthPX(v.getWidth());
|
||||
}
|
||||
});
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
@ -39,5 +32,4 @@ public class FeedIntelligenceSelectorFragment extends Fragment implements StateC
|
|||
public void setState(StateFilter state) {
|
||||
button.setState(state);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.newsblur.view;
|
||||
|
||||
import android.animation.LayoutTransition;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -10,105 +9,53 @@ import android.widget.LinearLayout;
|
|||
import com.newsblur.R;
|
||||
import com.newsblur.databinding.StateToggleBinding;
|
||||
import com.newsblur.util.StateFilter;
|
||||
import com.newsblur.util.UIUtils;
|
||||
|
||||
public class StateToggleButton extends LinearLayout {
|
||||
|
||||
/** the parent width in dp under which the widget will auto-collapse to a compact form */
|
||||
private final static int COLLAPSE_WIDTH_DP = 450;
|
||||
private StateFilter state = StateFilter.SOME;
|
||||
private StateChangedListener stateChangedListener;
|
||||
private final StateToggleBinding binding;
|
||||
|
||||
private StateFilter state = StateFilter.SOME;
|
||||
|
||||
private StateChangedListener stateChangedListener;
|
||||
|
||||
private int parentWidthPX = 0;
|
||||
|
||||
private StateToggleBinding binding;
|
||||
|
||||
public StateToggleButton(Context context, AttributeSet art) {
|
||||
super(context, art);
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
View view = inflater.inflate(R.layout.state_toggle, this);
|
||||
public StateToggleButton(Context context, AttributeSet art) {
|
||||
super(context, art);
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
View view = inflater.inflate(R.layout.state_toggle, this);
|
||||
binding = StateToggleBinding.bind(view);
|
||||
setState(state);
|
||||
|
||||
// smooth layout transitions are enabled in our layout XML; this smooths out toggle
|
||||
// transitions on newer devices
|
||||
binding.toggleAll.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
|
||||
binding.toggleSome.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
|
||||
binding.toggleFocus.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
|
||||
binding.toggleSaved.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
|
||||
|
||||
setState(state);
|
||||
|
||||
binding.toggleAll.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
setState(StateFilter.ALL);
|
||||
}
|
||||
});
|
||||
binding.toggleSome.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
setState(StateFilter.SOME);
|
||||
}
|
||||
});
|
||||
binding.toggleFocus.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
setState(StateFilter.BEST);
|
||||
}
|
||||
});
|
||||
binding.toggleSaved.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
setState(StateFilter.SAVED);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setStateListener(final StateChangedListener stateChangedListener) {
|
||||
this.stateChangedListener = stateChangedListener;
|
||||
}
|
||||
|
||||
public void setState(StateFilter state) {
|
||||
this.state = state;
|
||||
updateButtonStates();
|
||||
if (stateChangedListener != null) {
|
||||
stateChangedListener.changedState(this.state);
|
||||
}
|
||||
binding.toggleAll.setOnClickListener(v -> setState(StateFilter.ALL));
|
||||
binding.toggleSome.setOnClickListener(v -> setState(StateFilter.SOME));
|
||||
binding.toggleFocus.setOnClickListener(v -> setState(StateFilter.BEST));
|
||||
binding.toggleSaved.setOnClickListener(v -> setState(StateFilter.SAVED));
|
||||
}
|
||||
|
||||
public void setParentWidthPX(int parentWidthPX) {
|
||||
this.parentWidthPX = parentWidthPX;
|
||||
public void setStateListener(final StateChangedListener stateChangedListener) {
|
||||
this.stateChangedListener = stateChangedListener;
|
||||
}
|
||||
|
||||
public void setState(StateFilter state) {
|
||||
this.state = state;
|
||||
updateButtonStates();
|
||||
if (stateChangedListener != null) {
|
||||
stateChangedListener.changedState(this.state);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateButtonStates() {
|
||||
boolean compactMode = true;
|
||||
if (parentWidthPX > 0) {
|
||||
float widthDP = UIUtils.px2dp(getContext(), parentWidthPX);
|
||||
if (widthDP > COLLAPSE_WIDTH_DP) compactMode = false;
|
||||
}
|
||||
|
||||
binding.toggleAllText.setVisibility((!compactMode || state == StateFilter.ALL) ? View.VISIBLE : View.GONE);
|
||||
binding.toggleAll.setEnabled(state != StateFilter.ALL);
|
||||
binding.toggleAllIcon.setAlpha(state == StateFilter.ALL ? 1.0f : 0.6f);
|
||||
|
||||
binding.toggleSomeText.setVisibility((!compactMode || state == StateFilter.SOME) ? View.VISIBLE : View.GONE);
|
||||
binding.toggleSome.setEnabled(state != StateFilter.SOME);
|
||||
binding.toggleSomeIcon.setAlpha(state == StateFilter.SOME ? 1.0f : 0.6f);
|
||||
|
||||
binding.toggleFocusText.setVisibility((!compactMode || state == StateFilter.BEST) ? View.VISIBLE : View.GONE);
|
||||
binding.toggleFocus.setEnabled(state != StateFilter.BEST);
|
||||
binding.toggleFocusIcon.setAlpha(state == StateFilter.BEST ? 1.0f : 0.6f);
|
||||
|
||||
binding.toggleSavedText.setVisibility((!compactMode || state == StateFilter.SAVED) ? View.VISIBLE : View.GONE);
|
||||
binding.toggleSaved.setEnabled(state != StateFilter.SAVED);
|
||||
binding.toggleSavedIcon.setAlpha(state == StateFilter.SAVED ? 1.0f : 0.6f);
|
||||
}
|
||||
|
||||
public interface StateChangedListener {
|
||||
public void changedState(StateFilter state);
|
||||
}
|
||||
}
|
||||
|
||||
public interface StateChangedListener {
|
||||
void changedState(StateFilter state);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue