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 ItemAccess itemAccess;
private final int imageSize;
public DownloadedEpisodesListAdapter(Context context, ItemAccess itemAccess) {
super();
this.context = context;
this.itemAccess = itemAccess;
this.imageSize = (int) context.getResources().getDimension(R.dimen.thumbnail_length_downloaded_item);
}
@Override
@ -52,7 +49,7 @@ public class DownloadedEpisodesListAdapter extends BaseAdapter {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Holder holder;
final FeedItem item = (FeedItem) getItem(position);
final FeedItem item = getItem(position);
if (item == null) return null;
if (convertView == null) {
@ -63,35 +60,17 @@ public class DownloadedEpisodesListAdapter extends BaseAdapter {
parent, false);
holder.imageView = (ImageView) convertView.findViewById(R.id.imgvImage);
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
.findViewById(R.id.txtvPublished);
holder.butSecondary = (ImageButton) convertView
.findViewById(R.id.butSecondaryAction);
holder.imageView = (ImageView) convertView.findViewById(R.id.imgvImage);
holder.txtvSize = (TextView) convertView.findViewById(R.id.txtvSize);
convertView.setTag(holder);
} else {
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)
.load(item.getImageUri())
.placeholder(R.color.light_gray)
@ -101,6 +80,22 @@ public class DownloadedEpisodesListAdapter extends BaseAdapter {
.dontAnimate()
.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;
}
@ -114,11 +109,11 @@ public class DownloadedEpisodesListAdapter extends BaseAdapter {
static class Holder {
TextView title;
TextView pubDate;
ImageView imageView;
TextView title;
TextView txtvSize;
ImageView queueStatus;
TextView pubDate;
ImageButton butSecondary;
}

View File

@ -1,7 +1,6 @@
package de.danoeh.antennapod.dialog;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
@ -18,10 +17,6 @@ import android.widget.Button;
import android.widget.ListView;
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.Collections;
import java.util.List;
@ -122,11 +117,6 @@ public class EpisodesApplyActionFragment extends Fragment {
super.onCreateOptionsMenu(menu, inflater);
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.setOnMenuItemClickListener(item -> {
if (checkedIds.size() == episodes.size()) {
@ -140,22 +130,21 @@ public class EpisodesApplyActionFragment extends Fragment {
@Override
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];
if(checkedIds.size() == episodes.size()) icon[0] = R.attr.ic_check_box;
else if(checkedIds.size() == 0) icon[0] = R.attr.ic_check_box_outline;
else icon[0] = R.attr.ic_indeterminate_check_box;
if (checkedIds.size() == episodes.size()) {
icon[0] = R.attr.ic_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);
Drawable iconDrawable = a.getDrawable(0);
a.recycle();
// Set icon
mSelectToggle.setIcon(iconDrawable);
}

View File

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