Added activity for viewing a specific miroguide category

This commit is contained in:
daniel oeh 2012-08-03 12:08:48 +02:00
parent 941154704b
commit 1b347032d4
5 changed files with 143 additions and 0 deletions

View File

@ -195,6 +195,7 @@
android:name="android.app.default_searchable"
android:value=".activity.MiroSearchActivity" />
</activity>
<activity android:name=".activity.MiroGuideCategoryActivity" android:configChanges="keyboardHidden|orientation" android:theme="@style/StyledIndicators"></activity>
</application>
</manifest>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.viewpagerindicator.TabPageIndicator
android:id="@+id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1">
</android.support.v4.view.ViewPager>
</LinearLayout>

View File

@ -164,6 +164,8 @@
<string name="miro_guide_label">Miro Guide</string>
<string name="loading_label">Loading...</string>
<string name="miro_search_hint">Search Miro Guide</string>
<string name="popular_label">Popular</string>
<string name="best_rating_label">Best rating</string>
</resources>

View File

@ -0,0 +1,107 @@
package de.danoeh.antennapod.activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.viewpagerindicator.TabPageIndicator;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.fragment.MiroGuideChannellistFragment;
public class MiroGuideCategoryActivity extends SherlockFragmentActivity {
private static final String TAG = "MiroGuideCategoryActivity";
public static String EXTRA_CATEGORY = "category";
private ViewPager viewpager;
private CategoryPagerAdapter pagerAdapter;
private TabPageIndicator tabs;
private String category;
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.miroguide_category);
viewpager = (ViewPager) findViewById(R.id.viewpager);
tabs = (TabPageIndicator) findViewById(R.id.tabs);
category = getIntent().getStringExtra(EXTRA_CATEGORY);
if (category != null) {
getSupportActionBar().setTitle(category);
pagerAdapter = new CategoryPagerAdapter(getSupportFragmentManager());
viewpager.setAdapter(pagerAdapter);
tabs.setViewPager(viewpager);
} else {
Log.e(TAG, "Activity was started with invalid arguments");
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
default:
return false;
}
}
public class CategoryPagerAdapter extends FragmentStatePagerAdapter {
public CategoryPagerAdapter(FragmentManager fm) {
super(fm);
}
private static final int NUM_ITEMS = 2;
private static final int POS_RATING = 0;
private static final int POS_POPULAR = 1;
@Override
public Fragment getItem(int position) {
switch (position) {
case POS_RATING:
return MiroGuideChannellistFragment.newInstance("category",
category, "rating");
case POS_POPULAR:
return MiroGuideChannellistFragment.newInstance("category",
category, "popular");
default:
return null;
}
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case POS_RATING:
return getString(R.string.best_rating_label);
case POS_POPULAR:
return getString(R.string.popular_label);
default:
return null;
}
}
@Override
public int getCount() {
return NUM_ITEMS;
}
}
}

View File

@ -1,10 +1,13 @@
package de.danoeh.antennapod.activity;
import android.annotation.SuppressLint;
import android.content.Intent;
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.TextView;
import com.actionbarsherlock.app.SherlockListActivity;
@ -49,6 +52,15 @@ public class MiroGuideMainActivity extends SherlockListActivity {
}
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String selection = listAdapter.getItem(position);
Intent launchIntent = new Intent(this, MiroGuideCategoryActivity.class);
launchIntent.putExtra(MiroGuideCategoryActivity.EXTRA_CATEGORY, selection);
startActivity(launchIntent);
}
private void createAdapter() {
if (categories != null) {
listAdapter = new ArrayAdapter<String>(this,