Created Activity for displaying information about a channel
This commit is contained in:
parent
b712ffee8f
commit
b91a04fc8c
|
@ -196,6 +196,7 @@
|
|||
android:value=".activity.MiroGuideSearchActivity" />
|
||||
</activity>
|
||||
<activity android:name=".activity.MiroGuideCategoryActivity" android:configChanges="keyboardHidden|orientation" android:theme="@style/StyledIndicators"></activity>
|
||||
<activity android:name=".activity.MiroGuideChannelViewActivity" android:configChanges="keyboard|orientation"></activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -0,0 +1,63 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progLoading"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:indeterminateOnly="true" />
|
||||
|
||||
<RelativeLayout
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/layout_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="invisible" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_margin="8dp"
|
||||
android:gravity="center"
|
||||
android:textSize="20dp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<View
|
||||
android:id="@+id/title_divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0.5dp"
|
||||
android:layout_below="@id/txtvTitle"
|
||||
android:background="@color/ics_gray" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvDescription"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/title_divider"
|
||||
android:layout_margin="8dp"
|
||||
android:maxLines="8"
|
||||
android:textSize="16dp" />
|
||||
|
||||
<View
|
||||
android:id="@+id/description_divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0.5dp"
|
||||
android:layout_below="@id/txtvDescription"
|
||||
android:background="@color/ics_gray" />
|
||||
|
||||
<ListView
|
||||
android:id="@+id/itemlist"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_below="@id/description_divider"
|
||||
tools:listitem="@android:layout/simple_list_item_1" >
|
||||
</ListView>
|
||||
</RelativeLayout>
|
||||
|
||||
</FrameLayout>
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
android:gravity="center_vertical"
|
||||
android:maxLines="2"
|
||||
android:textSize="16dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvDate"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textColor="@color/gray" />
|
||||
|
||||
</LinearLayout>
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<item android:id="@+id/add_feed" android:icon="@drawable/content_new" android:title="@string/add_new_feed_label" android:showAsAction="ifRoom"></item>
|
||||
<item android:id="@+id/visit_website_item" android:title="@string/visit_website_label" android:showAsAction="ifRoom" android:icon="@drawable/location_web_site"></item>
|
||||
|
||||
|
||||
</menu>
|
|
@ -0,0 +1,149 @@
|
|||
package de.danoeh.antennapod.activity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockActivity;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuInflater;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
|
||||
import de.danoeh.antennapod.AppConfig;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.adapter.MiroGuideItemlistAdapter;
|
||||
import de.danoeh.antennapod.feed.FeedManager;
|
||||
import de.danoeh.antennapod.miroguide.con.MiroGuideException;
|
||||
import de.danoeh.antennapod.miroguide.con.MiroGuideService;
|
||||
import de.danoeh.antennapod.miroguide.model.MiroChannel;
|
||||
import de.danoeh.antennapod.miroguide.model.MiroItem;
|
||||
import de.danoeh.antennapod.storage.DownloadRequester;
|
||||
|
||||
public class MiroGuideChannelViewActivity extends SherlockActivity {
|
||||
private static final String TAG = "MiroGuideChannelViewActivity";
|
||||
|
||||
public static final String EXTRA_CHANNEL_ID = "id";
|
||||
public static final String EXTRA_CHANNEL_URL = "url";
|
||||
|
||||
private RelativeLayout layoutContent;
|
||||
private ProgressBar progLoading;
|
||||
private TextView txtvTitle;
|
||||
private TextView txtVDescription;
|
||||
private ListView listEntries;
|
||||
|
||||
private long channelId;
|
||||
private String channelUrl;
|
||||
private MiroChannel channel;
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
channelLoader.cancel(true);
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
setContentView(R.layout.miroguide_channelview);
|
||||
|
||||
layoutContent = (RelativeLayout) findViewById(R.id.layout_content);
|
||||
progLoading = (ProgressBar) findViewById(R.id.progLoading);
|
||||
txtvTitle = (TextView) findViewById(R.id.txtvTitle);
|
||||
txtVDescription = (TextView) findViewById(R.id.txtvDescription);
|
||||
listEntries = (ListView) findViewById(R.id.itemlist);
|
||||
|
||||
channelId = getIntent().getLongExtra(EXTRA_CHANNEL_ID, -1);
|
||||
channelUrl = getIntent().getStringExtra(EXTRA_CHANNEL_URL);
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
channelLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
channelLoader.execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private AsyncTask<Void, Void, Void> channelLoader = new AsyncTask<Void, Void, Void>() {
|
||||
private static final String TAG = "ChannelLoader";
|
||||
private Exception exception;
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Starting background task");
|
||||
MiroGuideService service = new MiroGuideService();
|
||||
try {
|
||||
channel = service.getChannel(channelId);
|
||||
} catch (MiroGuideException e) {
|
||||
e.printStackTrace();
|
||||
exception = e;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Loading finished");
|
||||
if (exception == null) {
|
||||
txtvTitle.setText(channel.getName());
|
||||
txtVDescription.setText(channel.getDescription());
|
||||
String[] entryNames = new String[channel.getItems().size()];
|
||||
for (int i = 0; i < channel.getItems().size(); i++) {
|
||||
entryNames[i] = channel.getItems().get(i).getName();
|
||||
}
|
||||
MiroGuideItemlistAdapter listAdapter = new MiroGuideItemlistAdapter(
|
||||
MiroGuideChannelViewActivity.this, 0,
|
||||
channel.getItems());
|
||||
listEntries.setAdapter(listAdapter);
|
||||
progLoading.setVisibility(View.GONE);
|
||||
layoutContent.setVisibility(View.VISIBLE);
|
||||
invalidateOptionsMenu();
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = new MenuInflater(this);
|
||||
inflater.inflate(R.menu.channelview, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
boolean channelLoaded = channel != null;
|
||||
boolean notAdded = channelLoaded
|
||||
&& !((FeedManager.getInstance().feedExists(channel
|
||||
.getDownloadUrl())) || (DownloadRequester.getInstance()
|
||||
.isDownloadingFile(channel.getDownloadUrl())));
|
||||
menu.findItem(R.id.add_feed).setVisible(notAdded);
|
||||
menu.findItem(R.id.visit_website_item).setVisible(
|
||||
channelLoaded && channel.getWebsiteUrl() != null);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package de.danoeh.antennapod.adapter;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.List;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.format.DateUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.miroguide.model.MiroItem;
|
||||
|
||||
public class MiroGuideItemlistAdapter extends ArrayAdapter<MiroItem> {
|
||||
|
||||
public MiroGuideItemlistAdapter(Context context, int textViewResourceId,
|
||||
List<MiroItem> objects) {
|
||||
super(context, textViewResourceId, objects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
Holder holder;
|
||||
MiroItem item = getItem(position);
|
||||
|
||||
// Inflate Layout
|
||||
if (convertView == null) {
|
||||
holder = new Holder();
|
||||
LayoutInflater inflater = (LayoutInflater) getContext()
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
||||
convertView = inflater.inflate(R.layout.miroguide_itemlist_item,
|
||||
null);
|
||||
holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
|
||||
holder.date = (TextView) convertView.findViewById(R.id.txtvDate);
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (Holder) convertView.getTag();
|
||||
}
|
||||
|
||||
holder.title.setText(item.getName());
|
||||
if (item.getDate() != null) {
|
||||
holder.date.setText(DateUtils.formatSameDayTime(item.getDate()
|
||||
.getTime(), System.currentTimeMillis(), DateFormat.SHORT,
|
||||
DateFormat.SHORT));
|
||||
holder.date.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.date.setVisibility(View.GONE);
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
|
||||
static class Holder {
|
||||
TextView title;
|
||||
TextView date;
|
||||
}
|
||||
|
||||
}
|
|
@ -448,6 +448,16 @@ public class FeedManager {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Returns true if a feed with the given download link is already in the feedlist. */
|
||||
public boolean feedExists(String downloadUrl) {
|
||||
for (Feed feed : feeds) {
|
||||
if (feed.getDownload_url().equals(downloadUrl)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Get a FeedItem by its identifying value. */
|
||||
private FeedItem searchFeedItemByIdentifyingValue(Feed feed,
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.annotation.SuppressLint;
|
|||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
@ -14,11 +15,13 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.AbsListView.OnScrollListener;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockListFragment;
|
||||
|
||||
import de.danoeh.antennapod.AppConfig;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.activity.MiroGuideChannelViewActivity;
|
||||
import de.danoeh.antennapod.adapter.MiroGuideChannelListAdapter;
|
||||
import de.danoeh.antennapod.asynctask.FeedImageLoader;
|
||||
import de.danoeh.antennapod.miroguide.con.MiroGuideException;
|
||||
|
@ -153,6 +156,21 @@ public class MiroGuideChannellistFragment extends SherlockListFragment {
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
super.onListItemClick(l, v, position, id);
|
||||
if (listAdapter != null) {
|
||||
MiroChannel selection = listAdapter.getItem(position);
|
||||
Intent launchIntent = new Intent(getActivity(),
|
||||
MiroGuideChannelViewActivity.class);
|
||||
launchIntent.putExtra(MiroGuideChannelViewActivity.EXTRA_CHANNEL_ID,
|
||||
selection.getId());
|
||||
launchIntent.putExtra(MiroGuideChannelViewActivity.EXTRA_CHANNEL_URL,
|
||||
selection.getDownloadUrl());
|
||||
startActivity(launchIntent);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private void loadChannels() {
|
||||
if (!isLoadingChannels) {
|
||||
|
|
|
@ -180,6 +180,16 @@ public class DownloadRequester {// TODO handle externalstorage missing
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Checks if feedfile with the given download url is in the downloads list */
|
||||
public boolean isDownloadingFile(String downloadUrl) {
|
||||
for (FeedFile f : downloads) {
|
||||
if (f.getDownload_url().equals(downloadUrl)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasNoDownloads() {
|
||||
return downloads.isEmpty();
|
||||
|
|
Loading…
Reference in New Issue