Minor changes

This commit is contained in:
Martin Fietz 2016-01-26 18:48:43 +01:00
parent c80ee1b282
commit 748a6c2745
3 changed files with 48 additions and 58 deletions

View File

@ -25,13 +25,10 @@ public class DownloadedEpisodesListAdapter extends BaseAdapter {
private final Context context; private final Context context;
private final ItemAccess itemAccess; private final ItemAccess itemAccess;
private final int imageSize;
public DownloadedEpisodesListAdapter(Context context, ItemAccess itemAccess) { public DownloadedEpisodesListAdapter(Context context, ItemAccess itemAccess) {
super(); super();
this.context = context; this.context = context;
this.itemAccess = itemAccess; this.itemAccess = itemAccess;
this.imageSize = (int) context.getResources().getDimension(R.dimen.thumbnail_length_downloaded_item);
} }
@Override @Override
@ -52,7 +49,7 @@ public class DownloadedEpisodesListAdapter extends BaseAdapter {
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
Holder holder; Holder holder;
final FeedItem item = (FeedItem) getItem(position); final FeedItem item = getItem(position);
if (item == null) return null; if (item == null) return null;
if (convertView == null) { if (convertView == null) {
@ -63,35 +60,17 @@ public class DownloadedEpisodesListAdapter extends BaseAdapter {
parent, false); parent, false);
holder.imageView = (ImageView) convertView.findViewById(R.id.imgvImage); holder.imageView = (ImageView) convertView.findViewById(R.id.imgvImage);
holder.title = (TextView) convertView.findViewById(R.id.txtvTitle); holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
holder.txtvSize = (TextView) convertView.findViewById(R.id.txtvSize);
holder.queueStatus = (ImageView) convertView.findViewById(R.id.imgvInPlaylist);
holder.pubDate = (TextView) convertView holder.pubDate = (TextView) convertView
.findViewById(R.id.txtvPublished); .findViewById(R.id.txtvPublished);
holder.butSecondary = (ImageButton) convertView holder.butSecondary = (ImageButton) convertView
.findViewById(R.id.butSecondaryAction); .findViewById(R.id.butSecondaryAction);
holder.imageView = (ImageView) convertView.findViewById(R.id.imgvImage);
holder.txtvSize = (TextView) convertView.findViewById(R.id.txtvSize);
convertView.setTag(holder); convertView.setTag(holder);
} else { } else {
holder = (Holder) convertView.getTag(); holder = (Holder) convertView.getTag();
} }
holder.title.setText(item.getTitle());
holder.queueStatus.setVisibility(item.isTagged(FeedItem.TAG_QUEUE) ? View.VISIBLE : View.GONE);
String pubDateStr = DateUtils.formatAbbrev(context, item.getPubDate());
holder.pubDate.setText(pubDateStr);
holder.txtvSize.setText(Converter.byteToString(item.getMedia().getSize()));
FeedItem.State state = item.getState();
if (state == FeedItem.State.PLAYING) {
holder.butSecondary.setEnabled(false);
} else {
holder.butSecondary.setEnabled(true);
}
holder.butSecondary.setFocusable(false);
holder.butSecondary.setTag(item);
holder.butSecondary.setOnClickListener(secondaryActionListener);
Glide.with(context) Glide.with(context)
.load(item.getImageUri()) .load(item.getImageUri())
.placeholder(R.color.light_gray) .placeholder(R.color.light_gray)
@ -101,6 +80,22 @@ public class DownloadedEpisodesListAdapter extends BaseAdapter {
.dontAnimate() .dontAnimate()
.into(holder.imageView); .into(holder.imageView);
holder.title.setText(item.getTitle());
holder.txtvSize.setText(Converter.byteToString(item.getMedia().getSize()));
holder.queueStatus.setVisibility(item.isTagged(FeedItem.TAG_QUEUE) ? View.VISIBLE : View.GONE);
String pubDateStr = DateUtils.formatAbbrev(context, item.getPubDate());
holder.pubDate.setText(pubDateStr);
FeedItem.State state = item.getState();
if (state == FeedItem.State.PLAYING) {
holder.butSecondary.setEnabled(false);
} else {
holder.butSecondary.setEnabled(true);
}
holder.butSecondary.setFocusable(false);
holder.butSecondary.setTag(item);
holder.butSecondary.setOnClickListener(secondaryActionListener);
return convertView; return convertView;
} }
@ -114,11 +109,11 @@ public class DownloadedEpisodesListAdapter extends BaseAdapter {
static class Holder { static class Holder {
TextView title;
TextView pubDate;
ImageView imageView; ImageView imageView;
TextView title;
TextView txtvSize; TextView txtvSize;
ImageView queueStatus; ImageView queueStatus;
TextView pubDate;
ImageButton butSecondary; ImageButton butSecondary;
} }

View File

@ -1,7 +1,6 @@
package de.danoeh.antennapod.dialog; package de.danoeh.antennapod.dialog;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
@ -18,10 +17,6 @@ import android.widget.Button;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Toast; import android.widget.Toast;
import com.joanzapata.iconify.Icon;
import com.joanzapata.iconify.IconDrawable;
import com.joanzapata.iconify.fonts.FontAwesomeIcons;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -122,11 +117,6 @@ public class EpisodesApplyActionFragment extends Fragment {
super.onCreateOptionsMenu(menu, inflater); super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.episodes_apply_action_options, menu); inflater.inflate(R.menu.episodes_apply_action_options, menu);
int[] attrs = { android.R.attr.textColor };
TypedArray ta = getActivity().obtainStyledAttributes(attrs);
textColor = ta.getColor(0, Color.GRAY);
ta.recycle();
mSelectToggle = menu.findItem(R.id.select_toggle); mSelectToggle = menu.findItem(R.id.select_toggle);
mSelectToggle.setOnMenuItemClickListener(item -> { mSelectToggle.setOnMenuItemClickListener(item -> {
if (checkedIds.size() == episodes.size()) { if (checkedIds.size() == episodes.size()) {
@ -140,22 +130,21 @@ public class EpisodesApplyActionFragment extends Fragment {
@Override @Override
public void onPrepareOptionsMenu (Menu menu) { public void onPrepareOptionsMenu (Menu menu) {
/* // Prepare icon for select toggle button
* Prepare icon for select toggle button
*/
// Find icon attribute
int[] icon = new int[1]; int[] icon = new int[1];
if(checkedIds.size() == episodes.size()) icon[0] = R.attr.ic_check_box; if (checkedIds.size() == episodes.size()) {
else if(checkedIds.size() == 0) icon[0] = R.attr.ic_check_box_outline; icon[0] = R.attr.ic_check_box;
else icon[0] = R.attr.ic_indeterminate_check_box; } else if (checkedIds.size() == 0) {
icon[0] = R.attr.ic_check_box_outline;
} else {
icon[0] = R.attr.ic_indeterminate_check_box;
}
// Get Drawable from attribute
TypedArray a = getActivity().obtainStyledAttributes(icon); TypedArray a = getActivity().obtainStyledAttributes(icon);
Drawable iconDrawable = a.getDrawable(0); Drawable iconDrawable = a.getDrawable(0);
a.recycle(); a.recycle();
// Set icon
mSelectToggle.setIcon(iconDrawable); mSelectToggle.setIcon(iconDrawable);
} }

View File

@ -1,12 +1,20 @@
package de.danoeh.antennapod.fragment; package de.danoeh.antennapod.fragment;
import android.app.Activity; import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.ListFragment; import android.support.v4.app.ListFragment;
import android.util.Log; import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.ListView; import android.widget.ListView;
import com.joanzapata.iconify.IconDrawable;
import com.joanzapata.iconify.fonts.FontAwesomeIcons;
import java.util.List; import java.util.List;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
@ -14,8 +22,10 @@ import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.adapter.DownloadedEpisodesListAdapter; import de.danoeh.antennapod.adapter.DownloadedEpisodesListAdapter;
import de.danoeh.antennapod.core.feed.EventDistributor; import de.danoeh.antennapod.core.feed.EventDistributor;
import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.dialog.EpisodesApplyActionFragment;
import rx.Observable; import rx.Observable;
import rx.Subscription; import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers; import rx.android.schedulers.AndroidSchedulers;
@ -28,16 +38,14 @@ public class CompletedDownloadsFragment extends ListFragment {
private static final String TAG = CompletedDownloadsFragment.class.getSimpleName(); private static final String TAG = CompletedDownloadsFragment.class.getSimpleName();
private static final int EVENTS = private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED |
EventDistributor.DOWNLOAD_HANDLED | EventDistributor.DOWNLOADLOG_UPDATE |
EventDistributor.DOWNLOADLOG_UPDATE | EventDistributor.UNREAD_ITEMS_UPDATE;
EventDistributor.UNREAD_ITEMS_UPDATE;
private List<FeedItem> items; private List<FeedItem> items;
private DownloadedEpisodesListAdapter listAdapter; private DownloadedEpisodesListAdapter listAdapter;
private boolean viewCreated = false; private boolean viewCreated = false;
private boolean itemsLoaded = false;
private Subscription subscription; private Subscription subscription;
@ -81,9 +89,9 @@ public class CompletedDownloadsFragment extends ListFragment {
} }
@Override @Override
public void onAttach(Activity activity) { public void onAttach(Context context) {
super.onAttach(activity); super.onAttach(context);
if (viewCreated && itemsLoaded) { if (viewCreated && items != null) {
onFragmentLoaded(); onFragmentLoaded();
} }
} }
@ -99,7 +107,7 @@ public class CompletedDownloadsFragment extends ListFragment {
lv.setPadding(0, vertPadding, 0, vertPadding); lv.setPadding(0, vertPadding, 0, vertPadding);
viewCreated = true; viewCreated = true;
if (itemsLoaded && getActivity() != null) { if (items != null && getActivity() != null) {
onFragmentLoaded(); onFragmentLoaded();
} }
} }
@ -111,7 +119,6 @@ public class CompletedDownloadsFragment extends ListFragment {
if (item != null) { if (item != null) {
((MainActivity) getActivity()).loadChildFragment(ItemFragment.newInstance(item.getId())); ((MainActivity) getActivity()).loadChildFragment(ItemFragment.newInstance(item.getId()));
} }
} }
private void onFragmentLoaded() { private void onFragmentLoaded() {
@ -157,7 +164,7 @@ public class CompletedDownloadsFragment extends ListFragment {
if(subscription != null) { if(subscription != null) {
subscription.unsubscribe(); subscription.unsubscribe();
} }
if (!itemsLoaded && viewCreated) { if (items == null && viewCreated) {
setListShown(false); setListShown(false);
} }
subscription = Observable.fromCallable(() -> DBReader.getDownloadedItems()) subscription = Observable.fromCallable(() -> DBReader.getDownloadedItems())
@ -166,7 +173,6 @@ public class CompletedDownloadsFragment extends ListFragment {
.subscribe(result -> { .subscribe(result -> {
if (result != null) { if (result != null) {
items = result; items = result;
itemsLoaded = true;
if (viewCreated && getActivity() != null) { if (viewCreated && getActivity() != null) {
onFragmentLoaded(); onFragmentLoaded();
} }