Added subscribe button to online feed view
This commit is contained in:
parent
864a6b476b
commit
a60ff4dd36
|
@ -6,8 +6,8 @@
|
|||
|
||||
<ImageView
|
||||
android:id="@+id/imgvCover"
|
||||
android:layout_width="@dimen/thumbnail_length_itemlist"
|
||||
android:layout_height="@dimen/thumbnail_length_itemlist"
|
||||
android:layout_width="@dimen/thumbnail_length_onlinefeedview"
|
||||
android:layout_height="@dimen/thumbnail_length_onlinefeedview"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_margin="4dp"/>
|
||||
|
@ -15,25 +15,52 @@
|
|||
<TextView
|
||||
android:id="@+id/txtvTitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_alignTop="@id/imgvCover"
|
||||
android:layout_alignBottom="@id/imgvCover"
|
||||
android:layout_toRightOf="@id/imgvCover"
|
||||
android:layout_alignParentRight="true"
|
||||
android:lines="1"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="@dimen/text_size_large"
|
||||
android:textSize="@dimen/text_size_medium"
|
||||
android:layout_margin="4dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvAuthor"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:layout_below="@id/txtvTitle"
|
||||
android:layout_toRightOf="@id/imgvCover"
|
||||
android:lines="1"
|
||||
android:ellipsize="end"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textSize="@dimen/text_size_small"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/butSubscribe"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:text="@string/subscribe_label"
|
||||
android:layout_below="@id/txtvAuthor"
|
||||
android:layout_alignParentRight="true"
|
||||
/>
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvDescription"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/imgvCover"
|
||||
android:layout_below="@id/butSubscribe"
|
||||
android:maxLines="3"
|
||||
android:ellipsize="end"
|
||||
android:textColor="?android:attr/textColorTertiary"
|
||||
android:textSize="@dimen/text_size_micro"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="8dp"
|
||||
android:layout_margin="4dp"/>
|
||||
</RelativeLayout>
|
|
@ -12,4 +12,5 @@
|
|||
<dimen name="text_size_large">22sp</dimen>
|
||||
<dimen name="status_indicator_width">36dp</dimen>
|
||||
<dimen name="thumbnail_length_itemlist">80dp</dimen>
|
||||
<dimen name="thumbnail_length_onlinefeedview">110dp</dimen>
|
||||
</resources>
|
|
@ -256,4 +256,8 @@
|
|||
<string name="folder_not_empty_dialog_msg">The folder you have selected is not empty. Media downloads and other files will be placed directly in this folder. Continue anyway?</string>
|
||||
<string name="set_to_default_folder">Choose default folder</string>
|
||||
|
||||
<!-- Online feed view -->
|
||||
<string name="subscribe_label">Subscribe</string>
|
||||
<string name="subscribed_label">Subscribed</string>
|
||||
<string name="downloading_label">Downloading...</string>
|
||||
</resources>
|
|
@ -1,26 +1,50 @@
|
|||
package de.danoeh.antennapod.activity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.adapter.FeedItemlistDescriptionAdapter;
|
||||
import de.danoeh.antennapod.asynctask.ImageDiskCache;
|
||||
import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator;
|
||||
import de.danoeh.antennapod.feed.EventDistributor;
|
||||
import de.danoeh.antennapod.feed.Feed;
|
||||
import de.danoeh.antennapod.storage.DBReader;
|
||||
import de.danoeh.antennapod.storage.DownloadRequestException;
|
||||
import de.danoeh.antennapod.storage.DownloadRequester;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by daniel on 24.08.13.
|
||||
*/
|
||||
public class DefaultOnlineFeedViewActivity extends OnlineFeedViewActivity {
|
||||
|
||||
private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED | EventDistributor.DOWNLOAD_QUEUED | EventDistributor.FEED_LIST_UPDATE;
|
||||
private volatile List<Feed> feeds;
|
||||
private Feed feed;
|
||||
|
||||
private Button subscribeButton;
|
||||
|
||||
@Override
|
||||
protected void showFeedInformation(Feed feed) {
|
||||
protected void loadData() {
|
||||
super.loadData();
|
||||
feeds = DBReader.getFeedList(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showFeedInformation(final Feed feed) {
|
||||
super.showFeedInformation(feed);
|
||||
setContentView(R.layout.listview_activity);
|
||||
|
||||
this.feed = feed;
|
||||
EventDistributor.getInstance().register(listener);
|
||||
ListView listView = (ListView) findViewById(R.id.listview);
|
||||
LayoutInflater inflater = (LayoutInflater)
|
||||
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
@ -31,16 +55,91 @@ public class DefaultOnlineFeedViewActivity extends OnlineFeedViewActivity {
|
|||
|
||||
ImageView cover = (ImageView) header.findViewById(R.id.imgvCover);
|
||||
TextView title = (TextView) header.findViewById(R.id.txtvTitle);
|
||||
TextView author = (TextView) header.findViewById(R.id.txtvAuthor);
|
||||
TextView description = (TextView) header.findViewById(R.id.txtvDescription);
|
||||
subscribeButton = (Button) header.findViewById(R.id.butSubscribe);
|
||||
|
||||
if (feed.getImage() != null) {
|
||||
ImageDiskCache.getDefaultInstance().loadThumbnailBitmap(feed.getImage().getDownload_url(), cover, (int) getResources().getDimension(
|
||||
R.dimen.thumbnail_length));
|
||||
}
|
||||
title.setText(feed.getTitle());
|
||||
author.setText(feed.getAuthor());
|
||||
description.setText(feed.getDescription());
|
||||
|
||||
subscribeButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
try {
|
||||
DownloadRequester.getInstance().downloadFeed(
|
||||
DefaultOnlineFeedViewActivity.this,
|
||||
new Feed(feed.getDownload_url(), new Date(), feed
|
||||
.getTitle()));
|
||||
} catch (DownloadRequestException e) {
|
||||
e.printStackTrace();
|
||||
DownloadRequestErrorDialogCreator.newRequestErrorDialog(DefaultOnlineFeedViewActivity.this,
|
||||
e.getMessage());
|
||||
}
|
||||
setSubscribeButtonState(feed);
|
||||
}
|
||||
});
|
||||
setSubscribeButtonState(feed);
|
||||
|
||||
}
|
||||
|
||||
private boolean feedInFeedlist(Feed feed) {
|
||||
if (feeds == null || feed == null)
|
||||
return false;
|
||||
for (Feed f : feeds) {
|
||||
if (f.getIdentifyingValue().equals(feed.getIdentifyingValue())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void setSubscribeButtonState(Feed feed) {
|
||||
if (subscribeButton != null && feed != null) {
|
||||
if (DownloadRequester.getInstance().isDownloadingFile(feed.getDownload_url())) {
|
||||
subscribeButton.setEnabled(false);
|
||||
subscribeButton.setText(R.string.downloading_label);
|
||||
} else if (feedInFeedlist(feed)) {
|
||||
subscribeButton.setEnabled(false);
|
||||
subscribeButton.setText(R.string.subscribed_label);
|
||||
} else {
|
||||
subscribeButton.setEnabled(true);
|
||||
subscribeButton.setText(R.string.subscribe_label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EventDistributor.EventListener listener = new EventDistributor.EventListener() {
|
||||
@Override
|
||||
public void update(EventDistributor eventDistributor, Integer arg) {
|
||||
if ((arg & EventDistributor.FEED_LIST_UPDATE) != 0) {
|
||||
new AsyncTask<Void, Void, List<Feed>>() {
|
||||
@Override
|
||||
protected List<Feed> doInBackground(Void... params) {
|
||||
return DBReader.getFeedList(DefaultOnlineFeedViewActivity.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<Feed> feeds) {
|
||||
super.onPostExecute(feeds);
|
||||
DefaultOnlineFeedViewActivity.this.feeds = feeds;
|
||||
setSubscribeButtonState(feed);
|
||||
}
|
||||
}.execute();
|
||||
} else if ((arg & EVENTS) != 0) {
|
||||
setSubscribeButtonState(feed);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
EventDistributor.getInstance().unregister(listener);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -129,6 +129,7 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
|
|||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
loadData();
|
||||
downloader.call();
|
||||
onDownloadCompleted(downloader);
|
||||
}
|
||||
|
@ -218,6 +219,13 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
|
|||
thread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to load data asynchronously.
|
||||
* */
|
||||
protected void loadData() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when feed parsed successfully
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue