Extract play pause button in separate layout

Use drawable for play/pause button
This commit is contained in:
Daniel Schaal 2015-07-14 17:48:31 +02:00
parent 2d92094dad
commit d2da52686b
17 changed files with 220 additions and 259 deletions

View file

@ -155,21 +155,11 @@ public class NewsListRecyclerAdapter extends RecyclerView.Adapter<ViewHolder> {
if(holder.flPlayPausePodcastWrapper != null) {
if (DatabaseConnectionOrm.ALLOWED_PODCASTS_TYPES.contains(item.getEnclosureMime())) {
final boolean isPlaying = idOfCurrentlyPlayedPodcast == item.getId();
int drawableResource;
int state = (isPlaying ? 1 : -1) * android.R.attr.state_active;
//Enable podcast buttons in view
holder.flPlayPausePodcastWrapper.setVisibility(View.VISIBLE);
// TODO: material icons for dark theme
if (ThemeChooser.isDarkTheme(activity)) {
drawableResource = isPlaying ? android.R.drawable.ic_media_pause : android.R.drawable.ic_media_play;
} else {
drawableResource = isPlaying ? R.drawable.ic_action_pause : R.drawable.ic_action_play_arrow;
}
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) holder.btnPlayPausePodcast.getLayoutParams();
params.setMargins(DpToPx(activity, isPlaying ? 0 : 2), 0, 0, 0);
holder.btnPlayPausePodcast.setLayoutParams(params);
holder.btnPlayPausePodcast.setBackgroundResource(drawableResource);
holder.btnPlayPausePodcast.getDrawable().setState(new int[]{state});
holder.flPlayPausePodcastWrapper.setOnClickListener(new View.OnClickListener() {
@Override

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 B

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_active="true">
<bitmap android:src="@drawable/ic_action_pause_dark" />
</item>
<item>
<bitmap android:src="@drawable/ic_action_play_arrow_dark" />
</item>
</selector>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_active="true">
<bitmap android:src="@drawable/ic_action_pause" />
</item>
<item>
<bitmap android:src="@drawable/ic_action_play_arrow" />
</item>
</selector>

View file

@ -1,153 +1,109 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:paddingLeft="@dimen/listview_row_margin_left"
android:background="?attr/selectableItemBackground"
android:id="@+id/list_item_header">
<!--
android:background="@drawable/checkbox_background"
android:button="@drawable/checkbox"
-->
android:layout_width="wrap_content">
<View
android:id="@+id/color_line_feed"
android:layout_width="@dimen/color_bar_of_feeds"
android:layout_height="match_parent"
android:background="?attr/dividerLineColor"
android:layout_alignParentStart="true"
android:layout_marginRight="@dimen/listview_row_margin_right"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/tv_subscription"
android:layout_alignBottom="@+id/body" />
android:layout_width="4dp"
android:background="?attr/dividerLineColor" />
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:id="@+id/imgViewFavIcon"
tools:src="@drawable/default_feed_icon_light"
android:layout_alignStart="@+id/summary"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:background="?attr/selectableItemBackground"
android:layout_marginStart="@dimen/listview_row_margin_left"
android:layout_marginEnd="@dimen/listview_row_margin_right"
android:layout_marginTop="@dimen/listview_row_margin_top"
android:layout_marginRight="5dp" />
android:layout_marginBottom="@dimen/listview_row_margin_bottom"
android:id="@+id/list_item_header">
<TextView
android:id="@+id/tv_subscription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center_vertical"
android:layout_gravity="left"
android:singleLine="true"
tools:text="Subscription"
android:textSize="15sp"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imgViewFavIcon"
android:layout_toEndOf="@+id/imgViewFavIcon"
android:paddingTop="@dimen/listview_row_margin_top" />
<!--
android:background="@drawable/checkbox_background"
android:button="@drawable/checkbox"
-->
<TextView
android:id="@+id/tv_item_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_gravity="right"
tools:text="21.09.2013"
android:singleLine="true"
android:textSize="15sp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="@dimen/listview_row_margin_top"
android:layout_marginRight="@dimen/listview_row_margin_right" />
<TextView
android:id="@+id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center_vertical"
android:textSize="17sp"
tools:text="Summary"
android:textStyle="bold"
android:layout_below="@+id/imgViewFavIcon"
android:layout_toRightOf="@+id/color_line_feed"
android:layout_toLeftOf="@+id/button_layout"
android:layout_toStartOf="@+id/button_layout"
android:maxLines="4"
android:layout_marginTop="5dp" />
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:id="@+id/imgViewFavIcon"
tools:src="@drawable/default_feed_icon_light"
android:layout_alignStart="@+id/summary"
android:layout_marginTop="@dimen/listview_row_margin_top"
android:layout_marginEnd="5dp"
android:layout_alignParentStart="true" />
<TextView
android:id="@+id/body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
tools:text="Body"
android:textColor="@color/extended_listview_item_body_text_color_light_theme"
android:textSize="14sp"
android:autoLink="none"
android:layout_below="@+id/summary"
android:layout_toRightOf="@+id/color_line_feed"
android:layout_alignRight="@+id/summary"
android:layout_alignEnd="@+id/summary"
android:maxLines="4"
android:layout_marginTop="5dp"
android:paddingBottom="@dimen/listview_row_margin_bottom" />
<LinearLayout
android:id="@+id/button_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentRight="true"
android:layout_below="@+id/tv_item_date"
android:paddingRight="@dimen/listview_row_margin_right"
android:paddingLeft="@dimen/listview_row_margin_left">
<CheckBox
android:id="@+id/cb_lv_item_starred"
<TextView
android:id="@+id/tv_subscription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:layout_gravity="center_horizontal"
android:button="@drawable/checkbox_background_holo_light"
android:layout_marginTop="5dp" />
android:ellipsize="end"
android:gravity="center_vertical"
android:layout_gravity="start"
android:singleLine="true"
tools:text="Subscription"
android:textSize="15sp"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imgViewFavIcon"
android:layout_toEndOf="@+id/imgViewFavIcon"
android:paddingTop="@dimen/listview_row_margin_top" />
<FrameLayout
android:id="@+id/fl_playPausePodcastWrapper"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<ImageView
android:id="@+id/btn_playPausePodcast"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:background="@drawable/ic_action_play_arrow"/>
<com.pascalwelsch.holocircularprogressbar.HoloCircularProgressBar
android:id="@+id/podcastDownloadProgress"
android:layout_gravity="center"
android:layout_width="50dp"
android:layout_height="50dp"
app:stroke_width="2dp"
app:progress_color="@android:color/holo_blue_dark"
app:progress_background_color="#cccccc"
app:marker_visible="false"
app:thumb_visible="false"/>
</FrameLayout>
<CheckBox
android:id="@+id/cb_lv_item_read"
<TextView
android:id="@+id/tv_item_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:layout_gravity="center_horizontal" />
</LinearLayout>
android:gravity="center_vertical"
android:layout_gravity="end"
tools:text="21.09.2013"
android:singleLine="true"
android:textSize="15sp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="@dimen/listview_row_margin_top" />
</RelativeLayout>
<TextView
android:id="@+id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center_vertical"
android:textSize="17sp"
tools:text="Summary"
android:textStyle="bold"
android:layout_below="@+id/imgViewFavIcon"
android:layout_toStartOf="@layout/subscription_detail_list_item_podcast_wrapper"
android:maxLines="4"
android:layout_marginTop="5dp"
android:layout_alignParentStart="true" />
<TextView
android:id="@+id/body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
tools:text="Body"
android:textColor="@color/extended_listview_item_body_text_color_light_theme"
android:textSize="14sp"
android:autoLink="none"
android:layout_below="@+id/summary"
android:layout_alignRight="@+id/summary"
android:layout_alignEnd="@+id/summary"
android:maxLines="4"
android:layout_marginTop="5dp"
android:paddingBottom="@dimen/listview_row_margin_bottom"
android:layout_alignParentStart="true" />
<include
layout="@layout/subscription_detail_list_item_podcast_wrapper"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="@+id/imgViewFavIcon"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</LinearLayout>

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fl_playPausePodcastWrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:showIn="@layout/subscription_detail_list_item_simple">
<ImageView
android:id="@+id/btn_playPausePodcast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="?attr/playpauseDrawable" />
<com.pascalwelsch.holocircularprogressbar.HoloCircularProgressBar
android:id="@+id/podcastDownloadProgress"
android:layout_width="32dp"
android:layout_height="32dp"
app:stroke_width="2dp"
app:progress_color="?attr/colorAccent"
app:progress_background_color="#cccccc"
app:marker_visible="false"
app:thumb_visible="false"
android:layout_gravity="center" />
</FrameLayout>

View file

@ -1,132 +1,94 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:descendantFocusability="blocksDescendants"
android:paddingLeft="@dimen/listview_row_margin_left"
android:paddingRight="@dimen/listview_row_margin_right"
android:paddingBottom="@dimen/listview_row_margin_bottom"
android:paddingTop="@dimen/listview_row_margin_top"
android:id="@+id/list_item_header">
android:layout_width="wrap_content">
<View
android:id="@+id/color_line_feed"
android:layout_width="@dimen/color_bar_of_feeds"
android:layout_height="match_parent"
android:background="?attr/dividerLineColor"
android:layout_centerVertical="true"
android:layout_alignTop="@+id/summary"
android:layout_alignBottom="@+id/tv_subscription" />
android:layout_width="4dp"
android:background="?attr/dividerLineColor" />
<CheckBox
android:id="@+id/cb_lv_item_starred"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_toEndOf="@+id/color_line_feed"
android:layout_toRightOf="@+id/color_line_feed"
android:button="@drawable/checkbox_background_holo_light"
android:clickable="false"
android:layout_margin="5dp" />
<TextView
android:id="@+id/summary"
android:layout_width="wrap_content"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="2"
android:textSize="17sp"
android:textStyle="bold"
tools:text="Summary Text\nSecond Line"
android:layout_toRightOf="@+id/cb_lv_item_starred"
android:minLines="2"
android:maxLines="2"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/fl_playPausePodcastWrapper"
android:layout_toStartOf="@+id/fl_playPausePodcastWrapper" />
android:background="?android:attr/selectableItemBackground"
android:descendantFocusability="blocksDescendants"
android:layout_marginStart="@dimen/listview_row_margin_left"
android:layout_marginEnd="@dimen/listview_row_margin_right"
android:layout_marginTop="@dimen/listview_row_margin_top"
android:layout_marginBottom="@dimen/listview_row_margin_bottom"
android:id="@+id/list_item_header">
<ImageView
android:id="@+id/imgViewFavIcon"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_below="@+id/summary"
android:layout_toRightOf="@+id/cb_lv_item_starred"
android:layout_toEndOf="@+id/cb_lv_item_starred"
android:layout_marginRight="5dp" />
<TextView
android:id="@+id/tv_subscription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:ellipsize="end"
android:singleLine="true"
android:textSize="13sp"
tools:text="PortableApps.com"
android:layout_below="@+id/summary"
android:layout_toRightOf="@+id/imgViewFavIcon"
android:layout_toEndOf="@+id/imgViewFavIcon" />
<TextView
android:id="@+id/tv_item_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:ellipsize="end"
android:singleLine="true"
android:textSize="13sp"
tools:text="vor 13 Stunden"
android:layout_below="@+id/summary"
android:layout_toLeftOf="@+id/fl_playPausePodcastWrapper"
android:layout_toStartOf="@+id/fl_playPausePodcastWrapper" />
<FrameLayout
android:id="@+id/fl_playPausePodcastWrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/listview_row_margin_left"
android:layout_toLeftOf="@+id/cb_lv_item_read"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true">
<TextView
android:id="@+id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="2"
android:textSize="17sp"
android:textStyle="bold"
tools:text="Summary Text\nSecond Line"
android:layout_alignParentStart="true"
android:minLines="2"
android:maxLines="2"
android:layout_alignParentTop="true"
android:layout_toStartOf="@layout/subscription_detail_list_item_podcast_wrapper" />
<ImageView
android:id="@+id/btn_playPausePodcast"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_marginLeft="2dp"
android:background="@drawable/ic_action_play_arrow"/>
android:id="@+id/imgViewFavIcon"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_below="@+id/summary"
android:layout_marginEnd="5dp"
android:layout_alignParentStart="true"
tools:src="@drawable/default_feed_icon_light" />
<com.pascalwelsch.holocircularprogressbar.HoloCircularProgressBar
android:id="@+id/podcastDownloadProgress"
android:layout_width="50dp"
android:layout_height="50dp"
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:id="@+id/star_imageview"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_action_star_light"
android:layout_below="@+id/summary"
android:layout_alignParentStart="false"
android:layout_toEndOf="@+id/imgViewFavIcon" />
app:stroke_width="2dp"
app:progress_color="@android:color/holo_blue_dark"
app:progress_background_color="#cccccc"
app:marker_visible="false"
app:thumb_visible="false"
android:layout_gravity="center" />
<TextView
android:id="@+id/tv_subscription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:textSize="13sp"
tools:text="PortableApps.com"
android:layout_below="@+id/summary"
android:layout_toRightOf="@+id/star_imageview"
android:layout_toLeftOf="@+id/tv_item_date"
android:layout_toStartOf="@+id/tv_item_date"
android:layout_toEndOf="@+id/imgViewFavIcon" />
</FrameLayout>
<TextView
android:id="@+id/tv_item_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:textSize="13sp"
tools:text="vor 13 Stunden"
android:layout_toStartOf="@layout/subscription_detail_list_item_podcast_wrapper"
android:layout_alignParentEnd="true"
android:layout_alignBaseline="@id/tv_subscription"/>
<CheckBox
android:id="@+id/cb_lv_item_read"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<include
layout="@layout/subscription_detail_list_item_podcast_wrapper"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignBottom="@+id/summary" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>

View file

@ -5,4 +5,6 @@
<attr name="rssItemListBackground" format="color" />
<attr name="playpauseDrawable" format="reference" />
</resources>

View file

@ -11,6 +11,8 @@
<item name="dividerLineColor">#1effffff</item>
<item name="rssItemListBackground">@color/material_grey_900</item>
<item name="playpauseDrawable">@drawable/newsreader_playpause</item>
</style>
@ -29,6 +31,8 @@
<item name="dividerLineColor">#1e000000</item>
<item name="rssItemListBackground">#ffdedede</item>
<item name="playpauseDrawable">@drawable/newsreader_playpause_light</item>
</style>
<style name="ToolbarTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar">