Converted FeedlistActivity into ListFragment
This commit is contained in:
parent
2df0fb4774
commit
92c53bcf92
|
@ -23,8 +23,6 @@
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name="de.podfetcher.activity.FeedlistActivity"
|
|
||||||
android:label="@string/feeds_label"/>
|
|
||||||
<activity android:name="de.podfetcher.activity.AddFeedActivity"
|
<activity android:name="de.podfetcher.activity.AddFeedActivity"
|
||||||
android:label="@string/add_new_feed_label"/>
|
android:label="@string/add_new_feed_label"/>
|
||||||
<activity android:name="de.podfetcher.activity.FeedItemlistActivity"/>
|
<activity android:name="de.podfetcher.activity.FeedItemlistActivity"/>
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="fill_parent"
|
android:id="@+id/main_view"
|
||||||
android:layout_height="fill_parent"
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical" >
|
android:orientation="vertical" >
|
||||||
<EditText
|
<FrameLayout
|
||||||
android:id="@+id/textedit"
|
android:id="@+id/main_fragment"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="0px"
|
||||||
<Button
|
android:layout_weight="1">
|
||||||
android:id="@+id/testbutton"
|
</FrameLayout>
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Test2" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
@ -7,6 +7,7 @@ import android.os.Bundle;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import de.podfetcher.feed.*;
|
import de.podfetcher.feed.*;
|
||||||
import de.podfetcher.adapter.FeedItemlistAdapter;
|
import de.podfetcher.adapter.FeedItemlistAdapter;
|
||||||
|
import de.podfetcher.fragment.FeedlistFragment;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
/** Displays a List of FeedItems */
|
/** Displays a List of FeedItems */
|
||||||
|
@ -24,7 +25,7 @@ public class FeedItemlistActivity extends SherlockListActivity {
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
manager = FeedManager.getInstance();
|
manager = FeedManager.getInstance();
|
||||||
long feedId = getIntent().getLongExtra(FeedlistActivity.EXTRA_SELECTED_FEED, -1);
|
long feedId = getIntent().getLongExtra(FeedlistFragment.EXTRA_SELECTED_FEED, -1);
|
||||||
if(feedId == -1) Log.e(TAG, "Received invalid feed selection.");
|
if(feedId == -1) Log.e(TAG, "Received invalid feed selection.");
|
||||||
|
|
||||||
feed = manager.getFeed(feedId);
|
feed = manager.getFeed(feedId);
|
||||||
|
@ -39,7 +40,7 @@ public class FeedItemlistActivity extends SherlockListActivity {
|
||||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||||
FeedItem selection = fila.getItem(position);
|
FeedItem selection = fila.getItem(position);
|
||||||
Intent showItem = new Intent(this, ItemviewActivity.class);
|
Intent showItem = new Intent(this, ItemviewActivity.class);
|
||||||
showItem.putExtra(FeedlistActivity.EXTRA_SELECTED_FEED, feed.getId());
|
showItem.putExtra(FeedlistFragment.EXTRA_SELECTED_FEED, feed.getId());
|
||||||
showItem.putExtra(EXTRA_SELECTED_FEEDITEM, selection.getId());
|
showItem.putExtra(EXTRA_SELECTED_FEEDITEM, selection.getId());
|
||||||
|
|
||||||
startActivity(showItem);
|
startActivity(showItem);
|
||||||
|
|
|
@ -18,6 +18,7 @@ import android.widget.ImageView;
|
||||||
import de.podfetcher.R;
|
import de.podfetcher.R;
|
||||||
import de.podfetcher.service.DownloadObserver;
|
import de.podfetcher.service.DownloadObserver;
|
||||||
import de.podfetcher.storage.DownloadRequester;
|
import de.podfetcher.storage.DownloadRequester;
|
||||||
|
import de.podfetcher.fragment.FeedlistFragment;
|
||||||
|
|
||||||
/** Displays a single FeedItem and provides various actions */
|
/** Displays a single FeedItem and provides various actions */
|
||||||
public class ItemviewActivity extends SherlockActivity {
|
public class ItemviewActivity extends SherlockActivity {
|
||||||
|
@ -56,7 +57,7 @@ public class ItemviewActivity extends SherlockActivity {
|
||||||
/** Extracts FeedItem object the activity is supposed to display */
|
/** Extracts FeedItem object the activity is supposed to display */
|
||||||
private void extractFeeditem() {
|
private void extractFeeditem() {
|
||||||
long itemId = getIntent().getLongExtra(FeedItemlistActivity.EXTRA_SELECTED_FEEDITEM, -1);
|
long itemId = getIntent().getLongExtra(FeedItemlistActivity.EXTRA_SELECTED_FEEDITEM, -1);
|
||||||
long feedId = getIntent().getLongExtra(FeedlistActivity.EXTRA_SELECTED_FEED, -1);
|
long feedId = getIntent().getLongExtra(FeedlistFragment.EXTRA_SELECTED_FEED, -1);
|
||||||
if(itemId == -1 || feedId == -1) {
|
if(itemId == -1 || feedId == -1) {
|
||||||
Log.e(TAG, "Received invalid selection of either feeditem or feed.");
|
Log.e(TAG, "Received invalid selection of either feeditem or feed.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import org.xml.sax.SAXException;
|
||||||
import de.podfetcher.R;
|
import de.podfetcher.R;
|
||||||
import de.podfetcher.feed.*;
|
import de.podfetcher.feed.*;
|
||||||
import de.podfetcher.storage.DownloadRequester;
|
import de.podfetcher.storage.DownloadRequester;
|
||||||
|
import de.podfetcher.fragment.FeedlistFragment;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
@ -14,33 +15,30 @@ import android.widget.ListView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import com.actionbarsherlock.app.SherlockListActivity;
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
|
import com.actionbarsherlock.app.SherlockListFragment;
|
||||||
|
import android.support.v4.app.FragmentManager;
|
||||||
|
import android.support.v4.app.FragmentTransaction;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class PodfetcherActivity extends SherlockListActivity {
|
public class PodfetcherActivity extends SherlockFragmentActivity {
|
||||||
private static final String TAG = "PodfetcherActivity";
|
private static final String TAG = "PodfetcherActivity";
|
||||||
|
|
||||||
private final String[] ITEMS = {"Feeds", "Settings"};
|
private FeedlistFragment feedlist;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.main);
|
||||||
|
|
||||||
|
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||||
|
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
||||||
|
feedlist = new FeedlistFragment();
|
||||||
|
fragmentTransaction.replace(R.id.main_fragment, feedlist);
|
||||||
|
fragmentTransaction.setTransition(
|
||||||
|
FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
|
||||||
|
fragmentTransaction.commit();
|
||||||
|
|
||||||
// Add navigation menu
|
|
||||||
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, ITEMS));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
|
||||||
final String selection = (String) l.getAdapter().getItem(position);
|
|
||||||
|
|
||||||
if(selection.equals(ITEMS[0])) {
|
|
||||||
Intent intent = new Intent(PodfetcherActivity.this, FeedlistActivity.class);
|
|
||||||
startActivity(intent);
|
|
||||||
} else if(selection.equals(ITEMS[1])){
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,55 +1,71 @@
|
||||||
package de.podfetcher.activity;
|
package de.podfetcher.fragment;
|
||||||
|
|
||||||
import de.podfetcher.R;
|
import de.podfetcher.R;
|
||||||
import de.podfetcher.feed.*;
|
import de.podfetcher.feed.*;
|
||||||
|
import de.podfetcher.activity.*;
|
||||||
import de.podfetcher.adapter.FeedlistAdapter;
|
import de.podfetcher.adapter.FeedlistAdapter;
|
||||||
import de.podfetcher.storage.DownloadRequester;
|
import de.podfetcher.storage.DownloadRequester;
|
||||||
import de.podfetcher.service.DownloadService;
|
import de.podfetcher.service.DownloadService;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.app.Activity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import com.actionbarsherlock.app.SherlockListActivity;
|
import com.actionbarsherlock.app.SherlockListFragment;
|
||||||
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
import com.actionbarsherlock.view.Menu;
|
import com.actionbarsherlock.view.Menu;
|
||||||
import com.actionbarsherlock.view.MenuInflater;
|
import com.actionbarsherlock.view.MenuInflater;
|
||||||
import com.actionbarsherlock.view.MenuItem;
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
|
||||||
public class FeedlistActivity extends SherlockListActivity {
|
public class FeedlistFragment extends SherlockListFragment {
|
||||||
private static final String TAG = "FeedlistActivity";
|
private static final String TAG = "FeedlistActivity";
|
||||||
public static final String EXTRA_SELECTED_FEED = "extra.de.podfetcher.activity.selected_feed";
|
public static final String EXTRA_SELECTED_FEED = "extra.de.podfetcher.activity.selected_feed";
|
||||||
|
|
||||||
private FeedManager manager;
|
private FeedManager manager;
|
||||||
private FeedlistAdapter fla;
|
private FeedlistAdapter fla;
|
||||||
|
private SherlockFragmentActivity pActivity;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
public void onAttach(Activity activity) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onAttach(activity);
|
||||||
|
pActivity = (SherlockFragmentActivity) activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetach() {
|
||||||
|
super.onDetach();
|
||||||
|
pActivity = null;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
Log.d(TAG, "Creating");
|
||||||
|
setHasOptionsMenu(true);
|
||||||
manager = FeedManager.getInstance();
|
manager = FeedManager.getInstance();
|
||||||
fla = new FeedlistAdapter(this, 0, manager.getFeeds());
|
fla = new FeedlistAdapter(pActivity, 0, manager.getFeeds());
|
||||||
setListAdapter(fla);
|
setListAdapter(fla);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
MenuInflater inflater = getSupportMenuInflater();
|
|
||||||
inflater.inflate(R.menu.feedlist, menu);
|
inflater.inflate(R.menu.feedlist, menu);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch(item.getItemId()) {
|
switch(item.getItemId()) {
|
||||||
case R.id.add_feed:
|
case R.id.add_feed:
|
||||||
startActivity(new Intent(this, AddFeedActivity.class));
|
startActivity(new Intent(pActivity, AddFeedActivity.class));
|
||||||
return true;
|
return true;
|
||||||
case R.id.all_feed_refresh:
|
case R.id.all_feed_refresh:
|
||||||
manager.refreshAllFeeds(this);
|
manager.refreshAllFeeds(pActivity);
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
|
@ -57,18 +73,18 @@ public class FeedlistActivity extends SherlockListActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
filter.addAction(DownloadService.ACTION_FEED_SYNC_COMPLETED);
|
filter.addAction(DownloadService.ACTION_FEED_SYNC_COMPLETED);
|
||||||
|
|
||||||
registerReceiver(contentUpdate, filter);
|
pActivity.registerReceiver(contentUpdate, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
unregisterReceiver(contentUpdate);
|
pActivity.unregisterReceiver(contentUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BroadcastReceiver contentUpdate = new BroadcastReceiver() {
|
private BroadcastReceiver contentUpdate = new BroadcastReceiver() {
|
||||||
|
@ -79,11 +95,11 @@ public class FeedlistActivity extends SherlockListActivity {
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||||
Feed selection = fla.getItem(position);
|
Feed selection = fla.getItem(position);
|
||||||
Intent showFeed = new Intent(this, FeedItemlistActivity.class);
|
Intent showFeed = new Intent(pActivity, FeedItemlistActivity.class);
|
||||||
showFeed.putExtra(EXTRA_SELECTED_FEED, selection.getId());
|
showFeed.putExtra(EXTRA_SELECTED_FEED, selection.getId());
|
||||||
|
|
||||||
startActivity(showFeed);
|
pActivity.startActivity(showFeed);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue