rework fragment interaction through listeners
articlefragment now works
This commit is contained in:
parent
acd2786961
commit
d391312d04
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
<LinearLayout android:id="@+id/article_fragment" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical">
|
<LinearLayout android:id="@+id/article_fragment" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical">
|
||||||
<LinearLayout android:layout_gravity="center_vertical" android:padding="6dip" android:background="#e0e0e0" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:id="@+id/article_header">
|
<LinearLayout android:layout_gravity="center_vertical" android:padding="3dip" android:background="#e0e0e0" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:id="@+id/article_header">
|
||||||
<TextView android:layout_weight="1" android:text="TextView" android:layout_height="wrap_content" android:textColor="#909090" android:layout_width="match_parent" android:id="@+id/title"></TextView>
|
<TextView android:singleLine="true" android:layout_weight="1" android:text="TextView" android:layout_height="wrap_content" android:textColor="#909090" android:ellipsize="end" android:layout_width="match_parent" android:id="@+id/title"></TextView>
|
||||||
<Button android:text="Close" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/close_button"></Button>
|
<Button android:text="Close" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/close_button"></Button>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
<WebView android:padding="3dip" android:layout_width="match_parent" android:id="@+id/content" android:layout_height="match_parent"></WebView>
|
<WebView android:padding="3dip" android:layout_width="match_parent" android:id="@+id/content" android:layout_height="match_parent"></WebView>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_height="fill_parent" android:id="@+id/feeds_container" android:layout_width="match_parent">
|
android:layout_height="fill_parent" android:layout_width="match_parent" android:id="@+id/feeds_fragment">
|
||||||
<LinearLayout android:id="@+id/loading_container" android:gravity="center" android:layout_height="match_parent" android:layout_width="match_parent">
|
<LinearLayout android:id="@+id/loading_container" android:gravity="center" android:layout_height="match_parent" android:layout_width="match_parent">
|
||||||
<ProgressBar android:layout_width="wrap_content" style="?android:attr/progressBarStyleLarge" android:id="@+id/loading_progress" android:layout_height="wrap_content"></ProgressBar>
|
<ProgressBar android:layout_width="wrap_content" style="?android:attr/progressBarStyleLarge" android:id="@+id/loading_progress" android:layout_height="wrap_content"></ProgressBar>
|
||||||
<TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:id="@+id/loading_message" android:layout_height="wrap_content" ></TextView>
|
<TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:id="@+id/loading_message" android:layout_height="wrap_content" ></TextView>
|
||||||
|
@ -1,22 +1,16 @@
|
|||||||
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
|
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent" android:id="@+id/main_flipper">
|
android:layout_height="fill_parent" android:id="@+id/main_flipper">
|
||||||
<FrameLayout android:layout_height="match_parent" android:layout_width="match_parent" android:layout_gravity="center_vertical" android:id="@+id/sync_splash">
|
<FrameLayout android:layout_height="match_parent" android:id="@+id/sync_splash" android:layout_width="match_parent" android:layout_gravity="center_vertical">
|
||||||
<LinearLayout android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/linearLayout1" android:gravity="center">
|
<LinearLayout android:layout_height="match_parent" android:id="@+id/linearLayout1" android:gravity="center" android:layout_width="match_parent">
|
||||||
<ProgressBar android:id="@+id/loading_progress" style="?android:attr/progressBarStyleLarge" android:layout_height="wrap_content" android:layout_width="wrap_content"></ProgressBar>
|
<ProgressBar style="?android:attr/progressBarStyleLarge" android:id="@+id/loading_progress" android:layout_height="wrap_content" android:layout_width="wrap_content"></ProgressBar>
|
||||||
<TextView android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_width="wrap_content" android:text="@string/loading_message" android:id="@+id/loading_message"></TextView>
|
<TextView android:id="@+id/loading_message" android:text="@string/loading_message" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge"></TextView>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
<LinearLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="@+id/main" android:orientation="horizontal">
|
<LinearLayout android:layout_height="fill_parent" android:id="@+id/main" android:layout_width="fill_parent" android:orientation="horizontal">
|
||||||
<fragment android:layout_weight="0" android:id="@+id/feeds_fragment" android:layout_height="match_parent" android:layout_width="300dp" android:name="org.fox.ttrss.FeedsFragment">
|
<LinearLayout android:id="@+id/feeds_fragment" android:layout_weight="0" android:layout_height="match_parent" android:orientation="vertical" android:layout_width="300dp"></LinearLayout>
|
||||||
<!-- Preview: layout=@layout/feeds_fragment -->
|
<LinearLayout android:layout_height="match_parent" android:layout_weight="1" android:id="@+id/headlines_fragment" android:orientation="vertical" android:layout_width="match_parent"></LinearLayout>
|
||||||
</fragment>
|
<LinearLayout android:id="@+id/article_fragment" android:layout_weight="0" android:layout_height="match_parent" android:orientation="vertical" android:layout_width="500dp"></LinearLayout>
|
||||||
<fragment android:layout_weight="1" android:id="@+id/headlines_fragment" android:layout_height="match_parent" android:layout_width="wrap_content" android:name="org.fox.ttrss.HeadlinesFragment">
|
|
||||||
<!-- Preview: layout=@layout/headlines_fragment -->
|
|
||||||
</fragment>
|
|
||||||
<fragment android:layout_weight="0" android:id="@+id/article_fragment" android:layout_height="match_parent" android:name="org.fox.ttrss.ArticleFragment" android:layout_width="500dp">
|
|
||||||
<!-- Preview: layout=@layout/article_fragment -->
|
|
||||||
</fragment>
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
package org.fox.ttrss;
|
package org.fox.ttrss;
|
||||||
|
|
||||||
import java.sql.SQLData;
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
|
import org.jsoup.Jsoup;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.Cursor;
|
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.provider.BaseColumns;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -22,30 +20,42 @@ public class ArticleFragment extends Fragment {
|
|||||||
|
|
||||||
protected SharedPreferences m_prefs;
|
protected SharedPreferences m_prefs;
|
||||||
|
|
||||||
private int m_articleId;
|
//private int m_articleId;
|
||||||
private String m_sessionId;
|
private String m_sessionId;
|
||||||
|
private Article m_article;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
m_sessionId = savedInstanceState.getString("sessionId");
|
m_sessionId = savedInstanceState.getString("sessionId");
|
||||||
m_articleId = savedInstanceState.getInt("articleId");
|
//m_articleId = savedInstanceState.getInt("articleId");
|
||||||
}
|
}
|
||||||
|
|
||||||
View view = inflater.inflate(R.layout.article_fragment, container, false);
|
View view = inflater.inflate(R.layout.article_fragment, container, false);
|
||||||
|
|
||||||
|
if (m_article != null) {
|
||||||
|
|
||||||
|
TextView title = (TextView)view.findViewById(R.id.title);
|
||||||
|
|
||||||
|
if (title != null) {
|
||||||
|
title.setText(m_article.title);
|
||||||
|
}
|
||||||
|
|
||||||
|
WebView web = (WebView)view.findViewById(R.id.content);
|
||||||
|
|
||||||
|
if (web != null) {
|
||||||
|
|
||||||
|
// this is ridiculous
|
||||||
|
String content = "<html><body>" + URLEncoder.encode(m_article.content).replace('+', ' ') + "</body></html>";
|
||||||
|
|
||||||
|
web.loadData(content, "text/html", "utf-8");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize(String sessionId, int articleId, SharedPreferences prefs) {
|
|
||||||
m_articleId = articleId;
|
|
||||||
m_prefs = prefs;
|
|
||||||
m_sessionId = sessionId;
|
|
||||||
|
|
||||||
Log.d(TAG, "Article: " + articleId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
@ -56,13 +66,18 @@ public class ArticleFragment extends Fragment {
|
|||||||
super.onSaveInstanceState(out);
|
super.onSaveInstanceState(out);
|
||||||
|
|
||||||
out.putString("sessionId", m_sessionId);
|
out.putString("sessionId", m_sessionId);
|
||||||
out.putInt("articleId", m_articleId);
|
//out.putInt("articleId", m_articleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
m_prefs = PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext());
|
|
||||||
|
m_sessionId = ((MainActivity)activity).getSessionId();
|
||||||
|
m_article = ((MainActivity)activity).getSelectedArticle();
|
||||||
|
|
||||||
|
//m_prefs = PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,11 @@ import java.util.List;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.app.FragmentTransaction;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -32,16 +32,32 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
|
|||||||
private final String TAG = this.getClass().getSimpleName();
|
private final String TAG = this.getClass().getSimpleName();
|
||||||
private SharedPreferences m_prefs;
|
private SharedPreferences m_prefs;
|
||||||
private String m_sessionId;
|
private String m_sessionId;
|
||||||
private int m_activeFeedId;
|
//private int m_activeFeedId;
|
||||||
private FeedListAdapter m_adapter;
|
private FeedListAdapter m_adapter;
|
||||||
private List<Feed> m_feeds = new ArrayList<Feed>();
|
private List<Feed> m_feeds = new ArrayList<Feed>();
|
||||||
|
private OnFeedSelectedListener m_feedSelectedListener;
|
||||||
|
|
||||||
|
public interface OnFeedSelectedListener {
|
||||||
|
public void onFeedSelected(Feed feed);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showLoading(boolean show) {
|
||||||
|
View v = getView();
|
||||||
|
|
||||||
|
if (v != null) {
|
||||||
|
v = v.findViewById(R.id.loading_container);
|
||||||
|
|
||||||
|
if (v != null)
|
||||||
|
v.setVisibility(show ? View.VISIBLE : View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
m_sessionId = savedInstanceState.getString("sessionId");
|
//m_sessionId = savedInstanceState.getString("sessionId");
|
||||||
m_activeFeedId = savedInstanceState.getInt("activeFeedId");
|
//m_activeFeedId = savedInstanceState.getInt("activeFeedId");
|
||||||
}
|
}
|
||||||
|
|
||||||
View view = inflater.inflate(R.layout.feeds_fragment, container, false);
|
View view = inflater.inflate(R.layout.feeds_fragment, container, false);
|
||||||
@ -52,6 +68,9 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
|
|||||||
list.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
|
list.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
|
||||||
list.setOnItemClickListener(this);
|
list.setOnItemClickListener(this);
|
||||||
|
|
||||||
|
if (m_sessionId != null)
|
||||||
|
refresh();
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +82,12 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
|
|
||||||
m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
|
m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
|
||||||
|
m_feedSelectedListener = (OnFeedSelectedListener) activity;
|
||||||
|
|
||||||
|
m_sessionId = ((MainActivity)activity).getSessionId();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -71,29 +95,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
|
|||||||
super.onSaveInstanceState(out);
|
super.onSaveInstanceState(out);
|
||||||
|
|
||||||
out.putString("sessionId", m_sessionId);
|
out.putString("sessionId", m_sessionId);
|
||||||
out.putInt("activeFeedId", m_activeFeedId);
|
//out.putInt("activeFeedId", m_activeFeedId);
|
||||||
}
|
|
||||||
|
|
||||||
public void setActiveFeedId(int feedId) {
|
|
||||||
m_activeFeedId = feedId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void viewFeed(int feedId) {
|
|
||||||
//FragmentManager fm = getFragmentManager();
|
|
||||||
//HeadlinesFragment hf = (HeadlinesFragment) fm.findFragmentById(R.id.headlines_fragment);
|
|
||||||
|
|
||||||
HeadlinesFragment hf = new HeadlinesFragment();
|
|
||||||
hf.initialize(m_sessionId, feedId, m_prefs);
|
|
||||||
|
|
||||||
if (hf != null) {
|
|
||||||
setActiveFeedId(feedId);
|
|
||||||
|
|
||||||
FragmentTransaction ft = getFragmentManager().beginTransaction();
|
|
||||||
ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
|
|
||||||
ft.show(getFragmentManager().findFragmentById(R.id.headlines_fragment));
|
|
||||||
ft.replace(R.id.headlines_fragment, hf);
|
|
||||||
ft.commit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -102,17 +104,10 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
|
|||||||
|
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
Feed feed = (Feed)list.getItemAtPosition(position);
|
Feed feed = (Feed)list.getItemAtPosition(position);
|
||||||
|
m_feedSelectedListener.onFeedSelected(feed);
|
||||||
viewFeed(feed.id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize(String sessionId) {
|
|
||||||
m_sessionId = sessionId;
|
|
||||||
|
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
FeedsRequest fr = new FeedsRequest();
|
FeedsRequest fr = new FeedsRequest();
|
||||||
|
|
||||||
@ -170,8 +165,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
|
|||||||
|
|
||||||
m_adapter.notifyDataSetInvalidated();
|
m_adapter.notifyDataSetInvalidated();
|
||||||
|
|
||||||
View v = getView().findViewById(R.id.loading_container);
|
showLoading(false);
|
||||||
v.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -221,6 +215,8 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
|
|||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
|
||||||
|
Feed active_feed = ((MainActivity)getActivity()).getActiveFeed();
|
||||||
|
|
||||||
View v = convertView;
|
View v = convertView;
|
||||||
|
|
||||||
Feed feed = items.get(position);
|
Feed feed = items.get(position);
|
||||||
@ -235,7 +231,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
|
|||||||
if (tt != null) {
|
if (tt != null) {
|
||||||
tt.setText(feed.title);
|
tt.setText(feed.title);
|
||||||
|
|
||||||
if (feed.id == m_activeFeedId)
|
if (active_feed != null && feed.id == active_feed.id)
|
||||||
tt.setTextAppearance(getContext(), R.style.SelectedFeed);
|
tt.setTextAppearance(getContext(), R.style.SelectedFeed);
|
||||||
else
|
else
|
||||||
tt.setTextAppearance(getContext(), R.style.Feed);
|
tt.setTextAppearance(getContext(), R.style.Feed);
|
||||||
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.fox.ttrss.FeedsFragment.OnFeedSelectedListener;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@ -34,19 +35,23 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
|
|||||||
protected SharedPreferences m_prefs;
|
protected SharedPreferences m_prefs;
|
||||||
|
|
||||||
private String m_sessionId;
|
private String m_sessionId;
|
||||||
private int m_feedId;
|
private Feed m_feed;
|
||||||
private int m_activeArticleId;
|
//private int m_activeArticleId;
|
||||||
|
|
||||||
private ArticleListAdapter m_adapter;
|
private ArticleListAdapter m_adapter;
|
||||||
private List<Article> m_articles = new ArrayList<Article>();
|
private List<Article> m_articles = new ArrayList<Article>();
|
||||||
|
private OnArticleSelectedListener m_articleSelectedListener;
|
||||||
|
|
||||||
|
public interface OnArticleSelectedListener {
|
||||||
|
public void onArticleSelected(Article article);
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
m_sessionId = savedInstanceState.getString("sessionId");
|
m_sessionId = savedInstanceState.getString("sessionId");
|
||||||
m_feedId = savedInstanceState.getInt("feedId");
|
//m_feedId = savedInstanceState.getInt("feedId");
|
||||||
m_activeArticleId = savedInstanceState.getInt("activeArticleId");
|
//m_activeArticleId = savedInstanceState.getInt("activeArticleId");
|
||||||
}
|
}
|
||||||
|
|
||||||
View view = inflater.inflate(R.layout.headlines_fragment, container, false);
|
View view = inflater.inflate(R.layout.headlines_fragment, container, false);
|
||||||
@ -56,6 +61,8 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
|
|||||||
list.setAdapter(m_adapter);
|
list.setAdapter(m_adapter);
|
||||||
list.setOnItemClickListener(this);
|
list.setOnItemClickListener(this);
|
||||||
|
|
||||||
|
if (m_feed != null) refresh();
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,8 +80,12 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
|
|
||||||
m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
|
m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
|
||||||
|
|
||||||
|
m_sessionId = ((MainActivity)activity).getSessionId();
|
||||||
|
m_feed = ((MainActivity)activity).getActiveFeed();
|
||||||
|
|
||||||
|
m_articleSelectedListener = (OnArticleSelectedListener) activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -83,35 +94,10 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
|
|||||||
|
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
Article article = (Article)list.getItemAtPosition(position);
|
Article article = (Article)list.getItemAtPosition(position);
|
||||||
|
m_articleSelectedListener.onArticleSelected(article);
|
||||||
viewArticle(article.id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void viewArticle(int articleId) {
|
|
||||||
ArticleFragment frag = new ArticleFragment();
|
|
||||||
frag.initialize(m_sessionId, articleId, m_prefs);
|
|
||||||
|
|
||||||
if (frag != null) {
|
|
||||||
m_activeArticleId = articleId;
|
|
||||||
|
|
||||||
FragmentTransaction ft = getFragmentManager().beginTransaction();
|
|
||||||
ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
|
|
||||||
ft.show(getFragmentManager().findFragmentById(R.id.article_fragment));
|
|
||||||
//ft.hide(getFragmentManager().findFragmentById(R.id.feeds_fragment));
|
|
||||||
ft.replace(R.id.article_fragment, frag);
|
|
||||||
ft.commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initialize(String sessionId, int feedId, SharedPreferences prefs) {
|
|
||||||
m_sessionId = sessionId;
|
|
||||||
m_feedId = feedId;
|
|
||||||
m_prefs = prefs;
|
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
HeadlinesRequest req = new HeadlinesRequest();
|
HeadlinesRequest req = new HeadlinesRequest();
|
||||||
|
|
||||||
@ -121,7 +107,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
|
|||||||
{
|
{
|
||||||
put("op", "getHeadlines");
|
put("op", "getHeadlines");
|
||||||
put("sid", m_sessionId);
|
put("sid", m_sessionId);
|
||||||
put("feed_id", String.valueOf(m_feedId));
|
put("feed_id", String.valueOf(m_feed.id));
|
||||||
put("show_content", "true");
|
put("show_content", "true");
|
||||||
put("limit", String.valueOf(30));
|
put("limit", String.valueOf(30));
|
||||||
put("offset", String.valueOf(0));
|
put("offset", String.valueOf(0));
|
||||||
@ -137,8 +123,8 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener {
|
|||||||
super.onSaveInstanceState(out);
|
super.onSaveInstanceState(out);
|
||||||
|
|
||||||
out.putString("sessionId", m_sessionId);
|
out.putString("sessionId", m_sessionId);
|
||||||
out.putInt("feedId", m_feedId);
|
//out.putInt("feedId", m_feedId);
|
||||||
out.putInt("activeArticleId", m_activeArticleId);
|
//out.putInt("activeArticleId", m_activeArticleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class HeadlinesRequest extends ApiRequest {
|
private class HeadlinesRequest extends ApiRequest {
|
||||||
|
@ -21,12 +21,14 @@ import android.widget.ViewFlipper;
|
|||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
public class MainActivity extends Activity {
|
public class MainActivity extends Activity implements FeedsFragment.OnFeedSelectedListener, HeadlinesFragment.OnArticleSelectedListener {
|
||||||
private final String TAG = this.getClass().getSimpleName();
|
private final String TAG = this.getClass().getSimpleName();
|
||||||
|
|
||||||
private SharedPreferences m_prefs;
|
private SharedPreferences m_prefs;
|
||||||
private String m_themeName = "";
|
private String m_themeName = "";
|
||||||
protected String m_sessionId;
|
private String m_sessionId;
|
||||||
|
private Article m_selectedArticle;
|
||||||
|
private Feed m_activeFeed;
|
||||||
|
|
||||||
protected MenuItem m_syncStatus;
|
protected MenuItem m_syncStatus;
|
||||||
|
|
||||||
@ -61,22 +63,15 @@ public class MainActivity extends Activity {
|
|||||||
|
|
||||||
setContentView(R.layout.main);
|
setContentView(R.layout.main);
|
||||||
|
|
||||||
/* HeadlinesFragment hf = new HeadlinesFragment();
|
HeadlinesFragment hf = new HeadlinesFragment();
|
||||||
FeedsFragment ff = new FeedsFragment();
|
|
||||||
ArticleFragment af = new ArticleFragment();
|
ArticleFragment af = new ArticleFragment();
|
||||||
|
|
||||||
FragmentTransaction ft = getFragmentManager().beginTransaction();
|
FragmentTransaction ft = getFragmentManager().beginTransaction();
|
||||||
|
ft.replace(R.id.feeds_fragment, new FeedsFragment());
|
||||||
ft.add(R.id.main, ff);
|
ft.replace(R.id.headlines_fragment, hf);
|
||||||
ft.add(R.id.main, hf);
|
ft.replace(R.id.article_fragment, af);
|
||||||
ft.add(R.id.main, af);
|
|
||||||
ft.hide(hf);
|
|
||||||
ft.hide(af);
|
ft.hide(af);
|
||||||
ft.commit(); */
|
ft.hide(hf);
|
||||||
|
|
||||||
FragmentTransaction ft = getFragmentManager().beginTransaction();
|
|
||||||
ft.hide(getFragmentManager().findFragmentById(R.id.headlines_fragment));
|
|
||||||
ft.hide(getFragmentManager().findFragmentById(R.id.article_fragment));
|
|
||||||
ft.commit();
|
ft.commit();
|
||||||
|
|
||||||
LoginRequest ar = new LoginRequest();
|
LoginRequest ar = new LoginRequest();
|
||||||
@ -94,12 +89,6 @@ public class MainActivity extends Activity {
|
|||||||
|
|
||||||
setLoadingStatus(R.string.login_in_progress, true);
|
setLoadingStatus(R.string.login_in_progress, true);
|
||||||
|
|
||||||
/* ViewFlipper vf = (ViewFlipper) findViewById(R.id.main_flipper);
|
|
||||||
|
|
||||||
if (vf != null) {
|
|
||||||
vf.showNext();
|
|
||||||
} */
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoadingStatus(int status, boolean showProgress) {
|
public void setLoadingStatus(int status, boolean showProgress) {
|
||||||
@ -176,18 +165,20 @@ public class MainActivity extends Activity {
|
|||||||
|
|
||||||
setLoadingStatus(R.string.loading_message, true);
|
setLoadingStatus(R.string.loading_message, true);
|
||||||
|
|
||||||
FragmentManager fm = getFragmentManager();
|
//FragmentManager fm = getFragmentManager();
|
||||||
FeedsFragment ff = (FeedsFragment) fm.findFragmentById(R.id.feeds_fragment);
|
//FeedsFragment ff = (FeedsFragment) fm.findFragmentById(R.id.feeds_fragment);
|
||||||
|
|
||||||
if (ff != null) {
|
|
||||||
ff.initialize(m_sessionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
ViewFlipper vf = (ViewFlipper) findViewById(R.id.main_flipper);
|
ViewFlipper vf = (ViewFlipper) findViewById(R.id.main_flipper);
|
||||||
|
|
||||||
if (vf != null) {
|
if (vf != null) {
|
||||||
vf.showNext();
|
vf.showNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FeedsFragment frag = new FeedsFragment();
|
||||||
|
|
||||||
|
FragmentTransaction ft = getFragmentManager().beginTransaction();
|
||||||
|
ft.replace(R.id.feeds_fragment, frag);
|
||||||
|
ft.commit();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
JsonObject content = rv.get("content").getAsJsonObject();
|
JsonObject content = rv.get("content").getAsJsonObject();
|
||||||
@ -212,4 +203,47 @@ public class MainActivity extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFeedSelected(Feed feed) {
|
||||||
|
Log.d(TAG, "Selected feed: " + feed.toString());
|
||||||
|
|
||||||
|
m_activeFeed = feed;
|
||||||
|
|
||||||
|
HeadlinesFragment hf = new HeadlinesFragment();
|
||||||
|
//hf.initialize(m_sessionId, feed.id, m_prefs);
|
||||||
|
|
||||||
|
FragmentTransaction ft = getFragmentManager().beginTransaction();
|
||||||
|
ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
|
||||||
|
ft.show(getFragmentManager().findFragmentById(R.id.headlines_fragment));
|
||||||
|
ft.replace(R.id.headlines_fragment, hf);
|
||||||
|
ft.addToBackStack(null);
|
||||||
|
ft.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Article getSelectedArticle() {
|
||||||
|
return m_selectedArticle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onArticleSelected(Article article) {
|
||||||
|
Log.d(TAG, "Selected article: " + article.toString());
|
||||||
|
|
||||||
|
m_selectedArticle = article;
|
||||||
|
|
||||||
|
ArticleFragment frag = new ArticleFragment();
|
||||||
|
|
||||||
|
FragmentTransaction ft = getFragmentManager().beginTransaction();
|
||||||
|
ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
|
||||||
|
ft.show(getFragmentManager().findFragmentById(R.id.article_fragment));
|
||||||
|
//ft.hide(getFragmentManager().findFragmentById(R.id.feeds_fragment));
|
||||||
|
ft.replace(R.id.article_fragment, frag);
|
||||||
|
ft.addToBackStack(null);
|
||||||
|
ft.commit();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Feed getActiveFeed() {
|
||||||
|
return m_activeFeed;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user