Created Activity for viewing items

This commit is contained in:
Daniel Oeh 2012-04-13 16:21:34 +02:00
parent eb24d41e1d
commit d3859b6763
6 changed files with 134 additions and 1 deletions

View File

@ -28,6 +28,7 @@
<activity android:name="de.podfetcher.activity.AddFeedActivity"
android:label="@string/add_new_feed_label"/>
<activity android:name="de.podfetcher.activity.FeedItemlistActivity"/>
<activity android:name="de.podfetcher.activity.ItemviewActivity"/>
<service android:enabled="true" android:name="de.podfetcher.service.DownloadService" />
</application>

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="@+id/txtvItemname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imgvFeedimage"
android:layout_height="90dip"
android:layout_width="90dip"
android:layout_alignParentLeft="true"/>
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:orientation="vertical">
<Button
android:id="@+id/butPlay"
android:text="@string/play_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/butDownload"
android:text="@string/download_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/butRemove"
android:text="@string/remove_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>

View File

@ -10,4 +10,10 @@
<!-- -->
<string name="confirm_label">Confirm</string>
<!-- Feeditemview labels-->
<string name="download_label">Download</string>
<string name="play_label">Play</string>
<string name="description_label">Description</string>
<string name="remove_label">Remove</string>
</resources>

View File

@ -4,6 +4,7 @@ import com.actionbarsherlock.app.SherlockListActivity;
import android.view.View;
import android.widget.ListView;
import android.os.Bundle;
import android.content.Intent;
import de.podfetcher.feed.*;
import de.podfetcher.adapter.FeedItemlistAdapter;
import android.util.Log;
@ -11,6 +12,7 @@ import android.util.Log;
/** Displays a List of FeedItems */
public class FeedItemlistActivity extends SherlockListActivity {
private static final String TAG = "FeedItemlistActivity";
public static final String EXTRA_SELECTED_FEEDITEM = "extra.de.podfetcher.activity.selected_feeditem";
private FeedItemlistAdapter fila;
private FeedManager manager;
@ -35,6 +37,11 @@ public class FeedItemlistActivity extends SherlockListActivity {
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
FeedItem selection = fila.getItem(position);
Intent showItem = new Intent(this, ItemviewActivity.class);
showItem.putExtra(FeedlistActivity.EXTRA_SELECTED_FEED, feed.getId());
showItem.putExtra(EXTRA_SELECTED_FEEDITEM, selection.getId());
startActivity(showItem);
}
}

View File

@ -0,0 +1,67 @@
package de.podfetcher.activity;
import java.io.File;
import android.net.Uri;
import com.actionbarsherlock.app.SherlockActivity;
import android.view.View;
import android.widget.ListView;
import android.os.Bundle;
import de.podfetcher.feed.*;
import android.util.Log;
import android.content.Intent;
import android.widget.Button;
import android.widget.TextView;
import android.widget.ImageView;
import de.podfetcher.R;
/** Displays a single FeedItem and provides various actions */
public class ItemviewActivity extends SherlockActivity {
private static final String TAG = "ItemviewActivity";
private FeedManager manager;
private FeedItem item;
// Widgets
private ImageView imgvImage;
private TextView txtvTitle;
private Button butPlay;
private Button butDownload;
private Button butRemove;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
manager = FeedManager.getInstance();
extractFeeditem();
populateUI();
}
/** Extracts FeedItem object the activity is supposed to display */
private void extractFeeditem() {
long itemId = getIntent().getLongExtra(FeedItemlistActivity.EXTRA_SELECTED_FEEDITEM, -1);
long feedId = getIntent().getLongExtra(FeedlistActivity.EXTRA_SELECTED_FEED, -1);
if(itemId == -1 || feedId == -1) {
Log.e(TAG, "Received invalid selection of either feeditem or feed.");
}
Feed feed = manager.getFeed(feedId);
item = manager.getFeedItem(itemId, feed);
}
private void populateUI() {
setContentView(R.layout.feeditemview);
txtvTitle = (TextView) findViewById(R.id.txtvItemname);
imgvImage = (ImageView) findViewById(R.id.imgvFeedimage);
butPlay = (Button) findViewById(R.id.butPlay);
butDownload = (Button) findViewById(R.id.butDownload);
butRemove = (Button) findViewById(R.id.butRemove);
setTitle(item.getFeed().getTitle());
txtvTitle.setText(item.getTitle());
if(item.getFeed().getImage() != null) {
imgvImage.setImageURI(Uri.fromFile(new File(item.getFeed().getImage().getFile_url())));
}
}
}

View File

@ -156,6 +156,17 @@ public class FeedManager {
}
return null;
}
/** Get a Feed Item by its id and its feed*/
public FeedItem getFeedItem(long id, Feed feed) {
for(FeedItem item : feed.getItems()) {
if(item.getId() == id) {
return item;
}
}
Log.w(TAG, "Couldn't find FeedItem with id " + id);
return null;
}
/** Reads the database */
public void loadDBData(Context context) {