blob: c039e96f83b401db546838f0c18c59f173a3e0e9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
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.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.fragment.MiroGuideChannellistFragment;
import de.danoeh.antennapod.preferences.UserPreferences;
/**
* Shows channels of a category sorted by different criteria in lists. The
* activity uses MiroGuideChannelListFragments for these lists. If the user
* selects a channel, the MiroGuideChannelViewActivity is started.
*/
public class MiroGuideCategoryActivity extends ActionBarActivity {
private static final String TAG = "MiroGuideCategoryActivity";
public static String EXTRA_CATEGORY = "category";
private ViewPager viewpager;
private CategoryPagerAdapter pagerAdapter;
private String category;
@Override
protected void onCreate(Bundle arg0) {
setTheme(UserPreferences.getTheme());
super.onCreate(arg0);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.miroguide_category);
viewpager = (ViewPager) findViewById(R.id.viewpager);
category = getIntent().getStringExtra(EXTRA_CATEGORY);
if (category != null) {
getSupportActionBar().setTitle(category);
pagerAdapter = new CategoryPagerAdapter(getSupportFragmentManager());
viewpager.setAdapter(pagerAdapter);
} 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;
}
}
}
|