implement browsing categories like feeds

This commit is contained in:
Andrew Dolgov 2011-11-29 13:02:16 +03:00
parent 97ecce1d42
commit 980b5696e3
7 changed files with 109 additions and 23 deletions

View File

@ -0,0 +1,11 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/browse_articles"
android:title="Browse articles"/>
<item
android:id="@+id/browse_feeds"
android:title="Browse feeds"/>
</menu>

View File

@ -52,8 +52,8 @@
<string name="back_to_categories">Close category</string>
<string name="no_feeds_to_display">No feeds to display</string>
<string name="no_headlines_to_display">No headlines to display</string>
<string name="error_template">Error: %1$s</string>
<string name="browse_cats_like_feeds">Browse categories like feeds</string>
<string name="browse_cats_like_feeds_summary">You can long-tap on a category to override this setting</string>
<string name="error_no_error">No error</string>
<string name="error_unknown">Error: Unknown error (see log)</string>

View File

@ -27,6 +27,8 @@
<CheckBoxPreference android:defaultValue="false" android:title="@string/sort_feeds_by_unread" android:key="sort_feeds_by_unread"/>
<CheckBoxPreference android:defaultValue="false" android:title="@string/download_feed_icons" android:key="download_feed_icons"/>
<CheckBoxPreference android:defaultValue="false" android:title="@string/enable_cats" android:key="enable_cats" />
<CheckBoxPreference android:defaultValue="false" android:title="@string/browse_cats_like_feeds" android:key="browse_cats_like_feeds"
android:summary="@string/browse_cats_like_feeds_summary" />
<CheckBoxPreference android:defaultValue="false" android:summary="@string/enable_ads_summary" android:title="@string/enable_ads" android:key="enable_ads" />
</PreferenceCategory>

View File

@ -11,6 +11,13 @@ public class Feed implements Comparable<Feed>, Parcelable {
boolean has_icon;
int cat_id;
int last_updated;
boolean is_cat;
public Feed(int id, String title, boolean is_cat) {
this.id = id;
this.title = title;
this.is_cat = is_cat;
}
public Feed(Parcel in) {
readFromParcel(in);
@ -37,7 +44,8 @@ public class Feed implements Comparable<Feed>, Parcelable {
out.writeInt(unread);
out.writeInt(has_icon ? 1 : 0);
out.writeInt(cat_id);
out.writeInt(last_updated);
out.writeInt(last_updated);
out.writeInt(is_cat ? 1 : 0);
}
public void readFromParcel(Parcel in) {
@ -48,6 +56,7 @@ public class Feed implements Comparable<Feed>, Parcelable {
has_icon = in.readInt() == 1;
cat_id = in.readInt();
last_updated = in.readInt();
is_cat = in.readInt() == 1;
}
@SuppressWarnings("rawtypes")

View File

@ -14,10 +14,15 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
@ -65,6 +70,39 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
getActivity().getMenuInflater().inflate(R.menu.category_menu, menu);
super.onCreateContextMenu(menu, v, menuInfo);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
FeedCategory cat = m_adapter.getItem(info.position);
MainActivity activity = (MainActivity)getActivity();
if (cat != null) {
m_selectedCatId = cat.id;
m_adapter.notifyDataSetChanged();
switch (item.getItemId()) {
case R.id.browse_articles:
activity.viewCategory(cat, true);
break;
case R.id.browse_feeds:
activity.viewCategory(cat, false);
break;
}
}
return true;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (savedInstanceState != null) {
@ -78,6 +116,7 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
m_adapter = new FeedCategoryListAdapter(getActivity(), R.layout.feeds_row, (ArrayList<FeedCategory>)m_cats);
list.setAdapter(m_adapter);
list.setOnItemClickListener(this);
registerForContextMenu(list);
if (m_cats == null || m_cats.size() == 0)
refresh(false);
@ -297,7 +336,8 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
// TODO Auto-generated method stub
sortCats();
}

View File

@ -105,6 +105,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
final String sessionId = ((MainActivity)getActivity()).getSessionId();
final boolean showUnread = ((MainActivity)getActivity()).getUnreadArticlesOnly();
final boolean isCat = m_feed.is_cat;
int skip = 0;
if (append) {
@ -131,6 +132,8 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
put("offset", String.valueOf(0));
put("view_mode", showUnread ? "adaptive" : "all_articles");
put("skip", String.valueOf(fskip));
if (isCat) put("is_cat", "true");
}
};

View File

@ -378,12 +378,19 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
findViewById(R.id.main).setAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_right));
}
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
findViewById(R.id.feeds_fragment).setVisibility(View.VISIBLE);
m_activeFeed = null;
if (m_activeFeed.is_cat) {
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
findViewById(R.id.cats_fragment).setVisibility(View.VISIBLE);
refreshCategories();
} else {
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
findViewById(R.id.feeds_fragment).setVisibility(View.VISIBLE);
refreshFeeds();
}
m_activeFeed = null;
initMainMenu();
refreshFeeds();
} else if (m_activeCategory != null) {
if (m_compatMode) {
@ -756,7 +763,6 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
@Override
public void onFeedSelected(Feed feed) {
Log.d(TAG, "Selected feed: " + feed.toString());
viewFeed(feed, false);
}
@ -788,19 +794,34 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
}
}
public void viewCategory(FeedCategory cat) {
m_activeCategory = cat;
public void viewCategory(FeedCategory cat, boolean openAsFeed) {
if (!openAsFeed) {
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
findViewById(R.id.feeds_fragment).setVisibility(View.VISIBLE);
m_activeCategory = cat;
FeedsFragment frag = new FeedsFragment();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.feeds_fragment, frag);
ft.commit();
} else {
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
findViewById(R.id.headlines_fragment).setVisibility(View.VISIBLE);
m_activeFeed = new Feed(cat.id, cat.title, true);
HeadlinesFragment frag = new HeadlinesFragment();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.headlines_fragment, frag);
ft.commit();
}
initMainMenu();
findViewById(R.id.cats_fragment).setVisibility(View.GONE);
findViewById(R.id.feeds_fragment).setVisibility(View.VISIBLE);
FeedsFragment frag = new FeedsFragment();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.feeds_fragment, frag);
ft.commit();
}
public void openArticle(Article article, int compatAnimation) {
@ -934,7 +955,7 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
@Override
public void onCatSelected(FeedCategory cat) {
m_activeCategory = cat;
viewCategory(cat);
Log.d(TAG, "onCatSelected");
viewCategory(cat, m_prefs.getBoolean("browse_cats_like_feeds", false));
}
}