tt-rss-android/src/org/fox/ttrss/HeadlinesFragment.java

118 lines
3.4 KiB
Java
Raw Normal View History

package org.fox.ttrss;
import android.app.Activity;
import android.app.Fragment;
2011-09-09 11:58:11 +00:00
import android.app.FragmentTransaction;
import android.content.SharedPreferences;
2011-09-09 09:50:15 +00:00
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.preference.PreferenceManager;
2011-09-09 11:58:11 +00:00
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
2011-09-09 09:50:15 +00:00
import android.widget.AbsListView;
2011-09-09 11:58:11 +00:00
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
2011-09-09 09:50:15 +00:00
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
2011-09-09 11:58:11 +00:00
public class HeadlinesFragment extends Fragment implements OnItemClickListener {
private final String TAG = this.getClass().getSimpleName();
protected int m_feedId;
protected SharedPreferences m_prefs;
2011-09-09 09:50:15 +00:00
protected SQLiteDatabase m_db;
protected Cursor m_cursor;
protected SimpleCursorAdapter m_adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.headlines_fragment, container, false);
2011-09-09 09:50:15 +00:00
DatabaseHelper helper = new DatabaseHelper(getActivity());
m_db = helper.getReadableDatabase();
m_cursor = m_db.query("articles", null, "feed_id = ?", new String[] { String.valueOf(m_feedId) }, null, null, "updated DESC");
m_adapter = new SimpleCursorAdapter(getActivity(), R.layout.headlines_row, m_cursor,
new String[] { "title", "excerpt" }, new int[] { R.id.title, R.id.excerpt }, 0);
ListView list = (ListView) view.findViewById(R.id.headlines);
if (list != null) {
list.setAdapter(m_adapter);
2011-09-09 11:58:11 +00:00
list.setOnItemClickListener(this);
2011-09-09 09:50:15 +00:00
list.setEmptyView(view.findViewById(R.id.no_headlines));
2011-09-09 11:58:11 +00:00
list.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
2011-09-09 09:50:15 +00:00
}
2011-09-09 16:36:09 +00:00
return view;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
}
2011-09-09 09:50:15 +00:00
@Override
public void onDestroy() {
super.onDestroy();
m_cursor.close();
m_db.close();
}
public void initialize(int feedId) {
m_feedId = feedId;
}
2011-09-09 11:58:11 +00:00
@Override
public void onItemClick(AdapterView<?> av, View view, int position, long id) {
ListView list = (ListView)getActivity().findViewById(R.id.headlines);
if (list != null) {
Cursor cursor = (Cursor) list.getItemAtPosition(position);
if (cursor != null) {
int articleId = (int) cursor.getLong(0);
Log.d(TAG, "clicked on article " + articleId);
viewArticle(articleId);
}
}
}
private void viewArticle(int articleId) {
FragmentTransaction ft = getFragmentManager().beginTransaction();
ArticleFragment frag = new ArticleFragment();
2011-09-09 16:36:09 +00:00
frag.initialize(articleId);
2011-09-09 11:58:11 +00:00
2011-09-09 16:36:09 +00:00
/* LinearLayout v = (LinearLayout) getActivity().findViewById(R.id.headlines_container);
2011-09-09 11:58:11 +00:00
2011-09-09 16:36:09 +00:00
if (v != null) {
ObjectAnimator anim = ObjectAnimator.ofFloat(v, "weightSum", 0f, 0.5f);
anim.setDuration(1000);
anim.start();
} */
2011-09-09 11:58:11 +00:00
ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
ft.replace(R.id.article_container, frag);
ft.commit();
2011-09-09 16:36:09 +00:00
getActivity().findViewById(R.id.article_container).setVisibility(View.VISIBLE);
2011-09-09 11:58:11 +00:00
//m_adapter.notifyDataSetChanged();
}
}