Implemented GridView in FeedlistFragment
This commit is contained in:
parent
168d48cd02
commit
522d61577b
13
res/drawable/badge.xml
Normal file
13
res/drawable/badge.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle" >
|
||||
|
||||
<solid android:color="@color/bright_blue" />
|
||||
|
||||
<padding
|
||||
android:bottom="5dip"
|
||||
android:left="5dip"
|
||||
android:right="5dip"
|
||||
android:top="5dip" />
|
||||
|
||||
</shape>
|
24
res/layout-large/feedlist.xml
Normal file
24
res/layout-large/feedlist.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?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" >
|
||||
|
||||
<GridView
|
||||
android:id="@+id/grid"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:horizontalSpacing="32dp"
|
||||
android:numColumns="auto_fit"
|
||||
android:verticalSpacing="32dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@id/android:empty"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center"
|
||||
android:text="@string/no_feeds_label" />
|
||||
|
||||
</LinearLayout>
|
71
res/layout/feedlist_item_grid.xml
Normal file
71
res/layout/feedlist_item_grid.xml
Normal file
@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imgvFeedimage"
|
||||
android:layout_width="160dip"
|
||||
android:layout_height="160dip"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_margin="8dp"
|
||||
android:cropToPadding="true" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignLeft="@id/imgvFeedimage"
|
||||
android:layout_alignRight="@id/imgvFeedimage"
|
||||
android:layout_below="@id/imgvFeedimage"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvFeedname"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:maxLines="2"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvLastUpdate"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:textColor="@color/gray"
|
||||
android:textStyle="italic" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvNumEpisodes"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:textColor="@color/gray" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="25dp"
|
||||
android:layout_alignRight="@id/imgvFeedimage"
|
||||
android:layout_alignTop="@id/imgvFeedimage" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvNewEps"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/badge"
|
||||
android:gravity="center"
|
||||
android:maxLines="1"
|
||||
android:textColor="@color/white"
|
||||
android:textStyle="bold"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
5
res/values-large/refs.xml
Normal file
5
res/values-large/refs.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<item type="layout" name="feedlist_item">@layout/feedlist_item_grid</item>
|
||||
|
||||
</resources>
|
@ -9,6 +9,7 @@ import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import de.danoeh.antennapod.activity.OpmlImportActivity;
|
||||
@ -113,4 +114,9 @@ public class PodcastApp extends Application implements
|
||||
public static float getLogicalDensity() {
|
||||
return LOGICAL_DENSITY;
|
||||
}
|
||||
|
||||
public boolean isLargeScreen() {
|
||||
return (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE || (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||
import de.danoeh.antennapod.asynctask.FeedImageLoader;
|
||||
import de.danoeh.antennapod.feed.Feed;
|
||||
import de.danoeh.antennapod.storage.DownloadRequester;
|
||||
import de.danoeh.antennapod.PodcastApp;
|
||||
import de.danoeh.antennapod.R;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
@ -93,9 +94,11 @@ public class FeedlistAdapter extends ArrayAdapter<Feed> {
|
||||
holder.newEpisodes.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
holder.image.setTag(feed.getImage());
|
||||
imageLoader.loadThumbnailBitmap(feed.getImage(), holder.image);
|
||||
|
||||
// TODO find new Episodes txtvNewEpisodes.setText(feed)
|
||||
if (PodcastApp.getInstance().isLargeScreen()) {
|
||||
imageLoader.loadCoverBitmap(feed.getImage(), holder.image);
|
||||
} else {
|
||||
imageLoader.loadThumbnailBitmap(feed.getImage(), holder.image);
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ public abstract class BitmapDecodeWorkerTask extends Thread {
|
||||
this.target = target;
|
||||
this.fileUrl = fileUrl;
|
||||
this.baseLength = length;
|
||||
this.PREFERRED_LENGTH = (int) (length * PodcastApp.getLogicalDensity());
|
||||
this.PREFERRED_LENGTH = (int) (length * PodcastApp.getLogicalDensity() + 0.5f);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,7 +22,11 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemLongClickListener;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockFragment;
|
||||
import com.actionbarsherlock.app.SherlockListFragment;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import com.actionbarsherlock.view.ActionMode;
|
||||
@ -31,8 +35,9 @@ import com.actionbarsherlock.view.MenuInflater;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
import android.util.Log;
|
||||
|
||||
public class FeedlistFragment extends SherlockListFragment implements
|
||||
ActionMode.Callback {
|
||||
public class FeedlistFragment extends SherlockFragment implements
|
||||
ActionMode.Callback, AdapterView.OnItemClickListener,
|
||||
AdapterView.OnItemLongClickListener {
|
||||
private static final String TAG = "FeedlistFragment";
|
||||
public static final String EXTRA_SELECTED_FEED = "extra.de.danoeh.antennapod.activity.selected_feed";
|
||||
|
||||
@ -43,6 +48,10 @@ public class FeedlistFragment extends SherlockListFragment implements
|
||||
private Feed selectedFeed;
|
||||
private ActionMode mActionMode;
|
||||
|
||||
private GridView gridView;
|
||||
private ListView listView;
|
||||
private TextView txtvEmpty;
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
@ -62,49 +71,44 @@ public class FeedlistFragment extends SherlockListFragment implements
|
||||
Log.d(TAG, "Creating");
|
||||
manager = FeedManager.getInstance();
|
||||
fla = new FeedlistAdapter(pActivity, 0, manager.getFeeds());
|
||||
setListAdapter(fla);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.feedlist, container, false);
|
||||
View result = inflater.inflate(R.layout.feedlist, container, false);
|
||||
listView = (ListView) result.findViewById(android.R.id.list);
|
||||
gridView = (GridView) result.findViewById(R.id.grid);
|
||||
txtvEmpty = (TextView) result.findViewById(android.R.id.empty);
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
getListView().setOnItemLongClickListener(new OnItemLongClickListener() {
|
||||
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view,
|
||||
int position, long id) {
|
||||
Feed selection = fla.getItem(position);
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG,
|
||||
"Selected Feed with title " + selection.getTitle());
|
||||
if (selection != null) {
|
||||
if (mActionMode != null) {
|
||||
mActionMode.finish();
|
||||
}
|
||||
fla.setSelectedItemIndex(position);
|
||||
selectedFeed = selection;
|
||||
mActionMode = getSherlockActivity().startActionMode(
|
||||
FeedlistFragment.this);
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
});
|
||||
if (listView != null) {
|
||||
listView.setOnItemClickListener(this);
|
||||
listView.setOnItemLongClickListener(this);
|
||||
listView.setAdapter(fla);
|
||||
listView.setEmptyView(txtvEmpty);
|
||||
if (AppConfig.DEBUG) Log.d(TAG, "Using ListView");
|
||||
} else {
|
||||
gridView.setOnItemClickListener(this);
|
||||
gridView.setOnItemLongClickListener(this);
|
||||
gridView.setAdapter(fla);
|
||||
gridView.setEmptyView(txtvEmpty);
|
||||
if (AppConfig.DEBUG) Log.d(TAG, "Using GridView");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (AppConfig.DEBUG) Log.d(TAG, "Resuming");
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Resuming");
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(DownloadRequester.ACTION_DOWNLOAD_QUEUED);
|
||||
filter.addAction(FeedManager.ACTION_UNREAD_ITEMS_UPDATE);
|
||||
@ -139,15 +143,6 @@ public class FeedlistFragment extends SherlockListFragment implements
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
Feed selection = fla.getItem(position);
|
||||
Intent showFeed = new Intent(pActivity, FeedItemlistActivity.class);
|
||||
showFeed.putExtra(EXTRA_SELECTED_FEED, selection.getId());
|
||||
|
||||
pActivity.startActivity(showFeed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||
FeedMenuHandler.onCreateOptionsMenu(mode.getMenuInflater(), menu);
|
||||
@ -196,4 +191,32 @@ public class FeedlistFragment extends SherlockListFragment implements
|
||||
fla.setSelectedItemIndex(FeedlistAdapter.SELECTION_NONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
|
||||
long id) {
|
||||
Feed selection = fla.getItem(position);
|
||||
Intent showFeed = new Intent(pActivity, FeedItemlistActivity.class);
|
||||
showFeed.putExtra(EXTRA_SELECTED_FEED, selection.getId());
|
||||
|
||||
pActivity.startActivity(showFeed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view,
|
||||
int position, long id) {
|
||||
Feed selection = fla.getItem(position);
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Selected Feed with title " + selection.getTitle());
|
||||
if (selection != null) {
|
||||
if (mActionMode != null) {
|
||||
mActionMode.finish();
|
||||
}
|
||||
fla.setSelectedItemIndex(position);
|
||||
selectedFeed = selection;
|
||||
mActionMode = getSherlockActivity().startActionMode(
|
||||
FeedlistFragment.this);
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user