Use ExpandableTextView on Text views that expand on clicking them

This commit is contained in:
Synced Synapse 2016-12-19 19:23:51 +00:00
parent b01e3c8ddc
commit 6245a9c7d5
7 changed files with 39 additions and 53 deletions

View File

@ -33,6 +33,7 @@ Credits
- [JmDNS](http://jmdns.sourceforge.net/) - [JmDNS](http://jmdns.sourceforge.net/)
- [PagerSlidingTabStrip](https://github.com/astuetz/PagerSlidingTabStrip) - [PagerSlidingTabStrip](https://github.com/astuetz/PagerSlidingTabStrip)
- [FloatingActionButton](https://github.com/makovkastar/FloatingActionButton) - [FloatingActionButton](https://github.com/makovkastar/FloatingActionButton)
- [ExpandableTextView](https://github.com/Blogcat/Android-ExpandableTextView)
**Translations** **Translations**
- French - Kowalski - French - Kowalski

View File

@ -117,6 +117,7 @@ dependencies {
compile 'javax.jmdns:jmdns:3.4.1' compile 'javax.jmdns:jmdns:3.4.1'
compile 'com.astuetz:pagerslidingtabstrip:1.0.1' compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
compile 'com.melnykov:floatingactionbutton:1.3.0' compile 'com.melnykov:floatingactionbutton:1.3.0'
compile 'at.blogc:expandabletextview:1.0.3'
androidTestCompile 'com.android.support.test:runner:0.5' androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5' androidTestCompile 'com.android.support.test:rules:0.5'

View File

@ -17,8 +17,6 @@
package org.xbmc.kore.ui; package org.xbmc.kore.ui;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.database.Cursor; import android.database.Cursor;
@ -65,10 +63,10 @@ import org.xbmc.kore.utils.LogUtils;
import org.xbmc.kore.utils.UIUtils; import org.xbmc.kore.utils.UIUtils;
import org.xbmc.kore.utils.Utils; import org.xbmc.kore.utils.Utils;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.Locale;
import at.blogc.android.views.ExpandableTextView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.InjectView; import butterknife.InjectView;
import butterknife.OnClick; import butterknife.OnClick;
@ -126,10 +124,9 @@ public class AlbumDetailsFragment extends AbstractDetailsFragment
@InjectView(R.id.rating) TextView mediaRating; @InjectView(R.id.rating) TextView mediaRating;
@InjectView(R.id.max_rating) TextView mediaMaxRating; @InjectView(R.id.max_rating) TextView mediaMaxRating;
@InjectView(R.id.year) TextView mediaYear; @InjectView(R.id.year) TextView mediaYear;
// @InjectView(R.id.genres) TextView mediaGenres;
@InjectView(R.id.media_description_container) LinearLayout mediaDescriptionContainer; @InjectView(R.id.media_description_container) LinearLayout mediaDescriptionContainer;
@InjectView(R.id.media_description) TextView mediaDescription; @InjectView(R.id.media_description) ExpandableTextView mediaDescription;
@InjectView(R.id.show_all) ImageView mediaShowAll; @InjectView(R.id.show_all) ImageView mediaShowAll;
@InjectView(R.id.song_list) LinearLayout songListView; @InjectView(R.id.song_list) LinearLayout songListView;
@ -346,7 +343,6 @@ public class AlbumDetailsFragment extends AbstractDetailsFragment
} }
private boolean isDescriptionExpanded = false;
/** /**
* Display the album details * Display the album details
* *
@ -377,7 +373,7 @@ public class AlbumDetailsFragment extends AbstractDetailsFragment
if (!TextUtils.isEmpty(description)) { if (!TextUtils.isEmpty(description)) {
mediaDescription.setVisibility(View.VISIBLE); mediaDescription.setVisibility(View.VISIBLE);
mediaDescription.setText(description); mediaDescription.setText(description);
final int maxLines = resources.getInteger(R.integer.description_max_lines);
Resources.Theme theme = getActivity().getTheme(); Resources.Theme theme = getActivity().getTheme();
TypedArray styledAttributes = theme.obtainStyledAttributes(new int[] { TypedArray styledAttributes = theme.obtainStyledAttributes(new int[] {
R.attr.iconExpand, R.attr.iconExpand,
@ -388,18 +384,11 @@ public class AlbumDetailsFragment extends AbstractDetailsFragment
final int iconExpandResId = final int iconExpandResId =
styledAttributes.getResourceId(styledAttributes.getIndex(1), R.drawable.ic_expand_more_white_24dp); styledAttributes.getResourceId(styledAttributes.getIndex(1), R.drawable.ic_expand_more_white_24dp);
styledAttributes.recycle(); styledAttributes.recycle();
mediaDescriptionContainer.setOnClickListener(new View.OnClickListener() { mediaDescriptionContainer.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (!isDescriptionExpanded) { mediaDescription.toggle();
mediaDescription.setMaxLines(Integer.MAX_VALUE); mediaShowAll.setImageResource(mediaDescription.isExpanded() ? iconCollapseResId: iconExpandResId);
mediaShowAll.setImageResource(iconExpandResId);
} else {
mediaDescription.setMaxLines(maxLines);
mediaShowAll.setImageResource(iconCollapseResId);
}
isDescriptionExpanded = !isDescriptionExpanded;
} }
}); });
} else { } else {
@ -426,7 +415,7 @@ public class AlbumDetailsFragment extends AbstractDetailsFragment
} }
private void setMediaRating(double rating) { private void setMediaRating(double rating) {
mediaRating.setText(String.format("%01.01f", rating)); mediaRating.setText(String.format(Locale.getDefault(), "%01.01f", rating));
mediaMaxRating.setText(getString(R.string.max_rating_music)); mediaMaxRating.setText(getString(R.string.max_rating_music));
} }
@ -560,7 +549,7 @@ public class AlbumDetailsFragment extends AbstractDetailsFragment
*/ */
private void displaySongsList(Cursor cursor) { private void displaySongsList(Cursor cursor) {
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
songInfoList = new ArrayList<FileDownloadHelper.SongInfo>(cursor.getCount()); songInfoList = new ArrayList<>(cursor.getCount());
do { do {
View songView = LayoutInflater.from(getActivity()) View songView = LayoutInflater.from(getActivity())
.inflate(R.layout.list_item_song, songListView, false); .inflate(R.layout.list_item_song, songListView, false);
@ -646,16 +635,16 @@ public class AlbumDetailsFragment extends AbstractDetailsFragment
MediaContract.Albums.RATING, MediaContract.Albums.RATING,
}; };
final int ID = 0; int ID = 0;
final int TITLE = 1; int TITLE = 1;
final int DISPLAYARTIST = 2; int DISPLAYARTIST = 2;
final int THUMBNAIL = 3; int THUMBNAIL = 3;
final int FANART = 4; int FANART = 4;
final int YEAR = 5; int YEAR = 5;
final int GENRE = 6; int GENRE = 6;
final int ALBUMLABEL = 7; int ALBUMLABEL = 7;
final int DESCRIPTION = 8; int DESCRIPTION = 8;
final int RATING = 9; int RATING = 9;
} }
/** /**

View File

@ -56,6 +56,7 @@ import org.xbmc.kore.utils.Utils;
import java.util.ArrayList; import java.util.ArrayList;
import at.blogc.android.views.ExpandableTextView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.InjectView; import butterknife.InjectView;
@ -119,7 +120,7 @@ public class TVShowDetailsFragment extends AbstractDetailsFragment
@InjectView(R.id.premiered) TextView mediaPremiered; @InjectView(R.id.premiered) TextView mediaPremiered;
@InjectView(R.id.genres) TextView mediaGenres; @InjectView(R.id.genres) TextView mediaGenres;
@InjectView(R.id.media_description) TextView mediaDescription; @InjectView(R.id.media_description) ExpandableTextView mediaDescription;
@InjectView(R.id.cast_list) GridLayout videoCastList; @InjectView(R.id.cast_list) GridLayout videoCastList;
@InjectView(R.id.next_episode_title) TextView nextEpisodeTitle; @InjectView(R.id.next_episode_title) TextView nextEpisodeTitle;
@ -131,8 +132,6 @@ public class TVShowDetailsFragment extends AbstractDetailsFragment
@InjectView(R.id.media_description_container) LinearLayout mediaDescriptionContainer; @InjectView(R.id.media_description_container) LinearLayout mediaDescriptionContainer;
@InjectView(R.id.show_all) ImageView mediaShowAll; @InjectView(R.id.show_all) ImageView mediaShowAll;
private boolean isDescriptionExpanded = false;
/** /**
* Create a new instance of this, initialized to show tvshowId * Create a new instance of this, initialized to show tvshowId
*/ */
@ -363,7 +362,6 @@ public class TVShowDetailsFragment extends AbstractDetailsFragment
mediaDescription.setText(cursor.getString(TVShowDetailsQuery.PLOT)); mediaDescription.setText(cursor.getString(TVShowDetailsQuery.PLOT));
Resources resources = getActivity().getResources(); Resources resources = getActivity().getResources();
final int maxLines = resources.getInteger(R.integer.description_max_lines);
TypedArray styledAttributes = getActivity().getTheme().obtainStyledAttributes(new int[] { TypedArray styledAttributes = getActivity().getTheme().obtainStyledAttributes(new int[] {
R.attr.iconExpand, R.attr.iconExpand,
R.attr.iconCollapse R.attr.iconCollapse
@ -376,14 +374,8 @@ public class TVShowDetailsFragment extends AbstractDetailsFragment
mediaDescriptionContainer.setOnClickListener(new View.OnClickListener() { mediaDescriptionContainer.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (!isDescriptionExpanded) { mediaDescription.toggle();
mediaDescription.setMaxLines(Integer.MAX_VALUE); mediaShowAll.setImageResource(mediaDescription.isExpanded() ? iconCollapseResId: iconExpandResId);
mediaShowAll.setImageResource(iconExpandResId);
} else {
mediaDescription.setMaxLines(maxLines);
mediaShowAll.setImageResource(iconCollapseResId);
}
isDescriptionExpanded = !isDescriptionExpanded;
} }
}); });
@ -436,7 +428,7 @@ public class TVShowDetailsFragment extends AbstractDetailsFragment
private void displayCastList(Cursor cursor) { private void displayCastList(Cursor cursor) {
// Transform the cursor into a List<VideoType.Cast> // Transform the cursor into a List<VideoType.Cast>
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
ArrayList<VideoType.Cast> castArrayList = new ArrayList<VideoType.Cast>(cursor.getCount()); ArrayList<VideoType.Cast> castArrayList = new ArrayList<>(cursor.getCount());
do { do {
castArrayList.add(new VideoType.Cast(cursor.getString(TVShowCastListQuery.NAME), castArrayList.add(new VideoType.Cast(cursor.getString(TVShowCastListQuery.NAME),
cursor.getInt(TVShowCastListQuery.ORDER), cursor.getInt(TVShowCastListQuery.ORDER),

View File

@ -177,7 +177,7 @@
android:layout_below="@id/media_details" android:layout_below="@id/media_details"
android:orientation="vertical" android:orientation="vertical"
android:background="?attr/contentBackgroundColor"> android:background="?attr/contentBackgroundColor">
<TextView <at.blogc.android.views.ExpandableTextView
android:id="@+id/media_description" android:id="@+id/media_description"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -186,7 +186,8 @@
android:paddingRight="@dimen/default_padding" android:paddingRight="@dimen/default_padding"
android:paddingBottom="0dp" android:paddingBottom="0dp"
android:maxLines="@integer/description_max_lines" android:maxLines="@integer/description_max_lines"
android:ellipsize="@null"/> android:ellipsize="end"
app:animation_duration="@integer/expandable_textview_animation_duration"/>
<ImageView <ImageView
android:id="@+id/show_all" android:id="@+id/show_all"
android:layout_width="@dimen/small_icon_size" android:layout_width="@dimen/small_icon_size"
@ -195,8 +196,7 @@
android:layout_marginBottom="@dimen/small_padding" android:layout_marginBottom="@dimen/small_padding"
android:layout_marginRight="@dimen/small_padding" android:layout_marginRight="@dimen/small_padding"
android:layout_marginEnd="@dimen/small_padding" android:layout_marginEnd="@dimen/small_padding"
android:src="?attr/iconExpand" android:src="?attr/iconExpand"/>
android:background="?android:attr/selectableItemBackground"/>
</LinearLayout> </LinearLayout>
<View <View

View File

@ -15,9 +15,11 @@
limitations under the License. limitations under the License.
--> -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout
android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"> xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView <ImageView
android:id="@+id/art" android:id="@+id/art"
@ -143,7 +145,7 @@
android:layout_below="@id/media_details" android:layout_below="@id/media_details"
android:orientation="vertical" android:orientation="vertical"
android:background="?attr/contentBackgroundColor"> android:background="?attr/contentBackgroundColor">
<TextView <at.blogc.android.views.ExpandableTextView
android:id="@+id/media_description" android:id="@+id/media_description"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -152,7 +154,8 @@
android:paddingRight="@dimen/default_padding" android:paddingRight="@dimen/default_padding"
android:paddingBottom="0dp" android:paddingBottom="0dp"
android:maxLines="@integer/description_max_lines" android:maxLines="@integer/description_max_lines"
android:ellipsize="@null"/> android:ellipsize="end"
app:animation_duration="@integer/expandable_textview_animation_duration"/>
<ImageView <ImageView
android:id="@+id/show_all" android:id="@+id/show_all"
@ -161,8 +164,7 @@
android:layout_gravity="end" android:layout_gravity="end"
android:layout_marginRight="@dimen/small_padding" android:layout_marginRight="@dimen/small_padding"
android:layout_marginEnd="@dimen/small_padding" android:layout_marginEnd="@dimen/small_padding"
android:src="?attr/iconExpand" android:src="?attr/iconExpand"/>
android:background="?android:attr/selectableItemBackground"/>
</LinearLayout> </LinearLayout>
<View <View

View File

@ -28,4 +28,5 @@
<integer name="seasons_grid_view_columns">1</integer> <integer name="seasons_grid_view_columns">1</integer>
<integer name="fab_animation_start_delay">100</integer> <integer name="fab_animation_start_delay">100</integer>
<integer name="expandable_textview_animation_duration">200</integer>
</resources> </resources>