experimental: remove globalstate article list object
This commit is contained in:
parent
222c3988e3
commit
4913d9ce53
2
.idea/gradle.xml
generated
2
.idea/gradle.xml
generated
@ -5,7 +5,7 @@
|
||||
<GradleProjectSettings>
|
||||
<option name="distributionType" value="LOCAL" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleHome" value="C:\Users\Andrew\AppData\Local\Android\android-studio1\gradle\gradle-2.2.1" />
|
||||
<option name="gradleHome" value="C:\Users\fox\android-studio\gradle\gradle-2.2.1" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
|
@ -32,7 +32,7 @@ public class ArticlePager extends Fragment {
|
||||
private PagerAdapter m_adapter;
|
||||
private HeadlinesEventListener m_listener;
|
||||
private Article m_article;
|
||||
private ArticleList m_articles = GlobalState.getInstance().m_loadedArticles;
|
||||
private ArticleList m_articles = new ArticleList(); //m_articles = GlobalState.getInstance().m_loadedArticles;
|
||||
private OnlineActivity m_activity;
|
||||
private String m_searchQuery = "";
|
||||
private Feed m_feed;
|
||||
@ -64,9 +64,10 @@ public class ArticlePager extends Fragment {
|
||||
|
||||
}
|
||||
|
||||
public void initialize(Article article, Feed feed) {
|
||||
public void initialize(Article article, Feed feed, ArticleList articles) {
|
||||
m_article = article;
|
||||
m_feed = feed;
|
||||
m_articles = articles;
|
||||
}
|
||||
|
||||
public void setSearchQuery(String searchQuery) {
|
||||
@ -141,7 +142,7 @@ public class ArticlePager extends Fragment {
|
||||
append = false;
|
||||
}
|
||||
|
||||
HeadlinesRequest req = new HeadlinesRequest(getActivity().getApplicationContext(), m_activity, m_feed) {
|
||||
HeadlinesRequest req = new HeadlinesRequest(getActivity().getApplicationContext(), m_activity, m_feed, m_articles) {
|
||||
@Override
|
||||
protected void onProgressUpdate(Integer... progress) {
|
||||
m_activity.setProgress(progress[0] / progress[1] * 10000);
|
||||
|
@ -26,6 +26,7 @@ import org.fox.ttrss.types.ArticleList;
|
||||
import org.fox.ttrss.types.Feed;
|
||||
import org.fox.ttrss.types.FeedCategory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
@ -221,7 +222,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
|
||||
}
|
||||
|
||||
public void onFeedSelected(Feed feed, final boolean selectedByUser) {
|
||||
GlobalState.getInstance().m_loadedArticles.clear();
|
||||
//GlobalState.getInstance().m_loadedArticles.clear();
|
||||
//m_pullToRefreshAttacher.setRefreshing(true);
|
||||
|
||||
FragmentTransaction ft = getSupportFragmentManager()
|
||||
@ -423,17 +424,17 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
public void openFeedArticles(Feed feed) {
|
||||
GlobalState.getInstance().m_loadedArticles.clear();
|
||||
/* public void openFeedArticles(Feed feed) {
|
||||
//GlobalState.getInstance().m_loadedArticles.clear();
|
||||
|
||||
Intent intent = new Intent(FeedsActivity.this, HeadlinesActivity.class);
|
||||
intent.putExtra("feed", feed);
|
||||
intent.putExtra("article", (Article)null);
|
||||
intent.putExtra("searchQuery", (String)null);
|
||||
|
||||
|
||||
startActivityForResult(intent, HEADLINES_REQUEST);
|
||||
overridePendingTransition(R.anim.right_slide_in, 0);
|
||||
}
|
||||
} */
|
||||
|
||||
public void onArticleSelected(Article article, boolean open) {
|
||||
if (article.unread) {
|
||||
@ -448,6 +449,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
|
||||
intent.putExtra("feed", hf.getFeed());
|
||||
intent.putExtra("article", article);
|
||||
intent.putExtra("searchQuery", hf.getSearchQuery());
|
||||
intent.putParcelableArrayListExtra("articles", hf.getArticles());
|
||||
|
||||
startActivityForResult(intent, HEADLINES_REQUEST);
|
||||
overridePendingTransition(R.anim.right_slide_in, 0);
|
||||
@ -476,7 +478,18 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == HEADLINES_REQUEST) {
|
||||
GlobalState.getInstance().m_activeArticle = null;
|
||||
GlobalState.getInstance().m_activeArticle = null;
|
||||
|
||||
ArrayList<Article> tmp = data.getParcelableArrayListExtra("articles");
|
||||
|
||||
if (tmp != null) {
|
||||
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
|
||||
if (hf != null) {
|
||||
hf.setArticles(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,23 +2,19 @@ package org.fox.ttrss;
|
||||
|
||||
import android.app.Application;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.acra.ACRA;
|
||||
import org.acra.ReportingInteractionMode;
|
||||
import org.acra.annotation.ReportsCrashes;
|
||||
import org.fox.ttrss.types.Article;
|
||||
import org.fox.ttrss.types.ArticleList;
|
||||
import org.fox.ttrss.types.Feed;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ReportsCrashes(formKey = "", mode = ReportingInteractionMode.DIALOG,
|
||||
resDialogText = R.string.crash_dialog_text,
|
||||
formUri = "http://tt-rss.org/acra/submit/")
|
||||
public class GlobalState extends Application {
|
||||
private static GlobalState m_singleton;
|
||||
|
||||
public ArticleList m_loadedArticles = new ArticleList();
|
||||
//public ArticleList m_loadedArticles = new ArticleList();
|
||||
public Feed m_activeFeed;
|
||||
public Article m_activeArticle;
|
||||
public int m_selectedArticleId;
|
||||
@ -41,7 +37,7 @@ public class GlobalState extends Application {
|
||||
public void save(Bundle out) {
|
||||
|
||||
out.setClassLoader(getClass().getClassLoader());
|
||||
out.putParcelableArrayList("gs:loadedArticles", m_loadedArticles);
|
||||
//out.putParcelableArrayList("gs:loadedArticles", m_loadedArticles);
|
||||
out.putParcelable("gs:activeFeed", m_activeFeed);
|
||||
out.putParcelable("gs:activeArticle", m_activeArticle);
|
||||
out.putString("gs:sessionId", m_sessionId);
|
||||
@ -51,12 +47,12 @@ public class GlobalState extends Application {
|
||||
}
|
||||
|
||||
public void load(Bundle in) {
|
||||
if (m_loadedArticles.size() == 0 && in != null) {
|
||||
ArrayList<Parcelable> list = in.getParcelableArrayList("gs:loadedArticles");
|
||||
if (/* m_loadedArticles.size() == 0 && */ in != null) {
|
||||
/* ArrayList<Parcelable> list = in.getParcelableArrayList("gs:loadedArticles");
|
||||
|
||||
for (Parcelable p : list) {
|
||||
m_loadedArticles.add((Article)p);
|
||||
}
|
||||
} */
|
||||
|
||||
m_activeFeed = (Feed) in.getParcelable("gs:activeFeed");
|
||||
m_activeArticle = (Article) in.getParcelable("gs:activeArticle");
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.fox.ttrss;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
@ -16,9 +17,12 @@ import org.fox.ttrss.types.Article;
|
||||
import org.fox.ttrss.types.ArticleList;
|
||||
import org.fox.ttrss.types.Feed;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventListener {
|
||||
private final String TAG = this.getClass().getSimpleName();
|
||||
|
||||
private ArticleList m_articles = new ArticleList();
|
||||
|
||||
protected SharedPreferences m_prefs;
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@ -60,8 +64,8 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
|
||||
String feedTitle = i.getStringExtra("feed_title");
|
||||
|
||||
tmpFeed = new Feed(feedId, feedTitle, isCat);
|
||||
|
||||
GlobalState.getInstance().m_loadedArticles.clear();
|
||||
|
||||
//GlobalState.getInstance().m_loadedArticles.clear();
|
||||
} else {
|
||||
tmpFeed = i.getParcelableExtra("feed");
|
||||
}
|
||||
@ -70,7 +74,13 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
|
||||
|
||||
final Article article = i.getParcelableExtra("article");
|
||||
final String searchQuery = i.getStringExtra("searchQuery");
|
||||
|
||||
|
||||
ArrayList<Article> tmp = i.getParcelableArrayListExtra("articles");
|
||||
|
||||
if (tmp != null) {
|
||||
m_articles.addAll(tmp);
|
||||
}
|
||||
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
|
||||
ft.replace(R.id.headlines_fragment, new LoadingFragment(), null);
|
||||
@ -86,11 +96,11 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
|
||||
HeadlinesFragment hf = new HeadlinesFragment();
|
||||
hf.initialize(feed, article, true);
|
||||
hf.initialize(feed, article, true, m_articles);
|
||||
hf.setSearchQuery(searchQuery);
|
||||
|
||||
ArticlePager af = new ArticlePager();
|
||||
af.initialize(article != null ? hf.getArticleById(article.id) : new Article(), feed);
|
||||
af.initialize(article != null ? hf.getArticleById(article.id) : new Article(), feed, m_articles);
|
||||
af.setSearchQuery(searchQuery);
|
||||
|
||||
ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES);
|
||||
@ -140,6 +150,11 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
|
||||
Intent resultIntent = new Intent();
|
||||
resultIntent.putParcelableArrayListExtra("articles", m_articles);
|
||||
setResult(Activity.RESULT_OK, resultIntent);
|
||||
|
||||
finish();
|
||||
overridePendingTransition(0, R.anim.right_slide_out);
|
||||
return true;
|
||||
@ -277,7 +292,7 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
|
||||
.beginTransaction();
|
||||
|
||||
ArticlePager af = new ArticlePager();
|
||||
af.initialize(fArticle, fFeed);
|
||||
af.initialize(fArticle, fFeed, m_articles);
|
||||
|
||||
ft.replace(R.id.article_fragment, af, FRAG_ARTICLE);
|
||||
ft.commitAllowingStateLoss();
|
||||
@ -291,5 +306,10 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
|
||||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
overridePendingTransition(0, R.anim.right_slide_out);
|
||||
}
|
||||
|
||||
Intent resultIntent = new Intent();
|
||||
resultIntent.putParcelableArrayListExtra("articles", m_articles);
|
||||
setResult(Activity.RESULT_OK, resultIntent);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
||||
private SharedPreferences m_prefs;
|
||||
|
||||
private ArticleListAdapter m_adapter;
|
||||
private ArticleList m_articles = GlobalState.getInstance().m_loadedArticles;
|
||||
private ArticleList m_articles = new ArticleList(); //GlobalState.getInstance().m_loadedArticles;
|
||||
private ArticleList m_selectedArticles = new ArticleList();
|
||||
private ArticleList m_readArticles = new ArticleList();
|
||||
private HeadlinesEventListener m_listener;
|
||||
@ -106,15 +106,19 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
||||
m_feed = feed;
|
||||
}
|
||||
|
||||
public void initialize(Feed feed, Article activeArticle, boolean compactMode) {
|
||||
public void initialize(Feed feed, Article activeArticle, boolean compactMode, ArticleList articles) {
|
||||
m_feed = feed;
|
||||
m_compactLayoutMode = compactMode;
|
||||
|
||||
if (activeArticle != null) {
|
||||
m_activeArticle = getArticleById(activeArticle.id);
|
||||
}
|
||||
|
||||
if (articles != null) {
|
||||
m_articles = articles;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item) {
|
||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
|
||||
@ -449,7 +453,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
||||
final String sessionId = m_activity.getSessionId();
|
||||
final boolean isCat = m_feed.is_cat;
|
||||
|
||||
HeadlinesRequest req = new HeadlinesRequest(getActivity().getApplicationContext(), m_activity, m_feed) {
|
||||
HeadlinesRequest req = new HeadlinesRequest(getActivity().getApplicationContext(), m_activity, m_feed, m_articles) {
|
||||
@Override
|
||||
protected void onProgressUpdate(Integer... progress) {
|
||||
m_activity.setProgress(Math.round((((float)progress[0] / (float)progress[1]) * 10000)));
|
||||
@ -1182,4 +1186,14 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
||||
public Feed getFeed() {
|
||||
return m_feed;
|
||||
}
|
||||
|
||||
public ArticleList getArticles() {
|
||||
return m_articles;
|
||||
}
|
||||
|
||||
public void setArticles(ArrayList<Article> articles) {
|
||||
m_articles.clear();
|
||||
m_articles.addAll(articles);
|
||||
m_adapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
@ -26,12 +26,13 @@ public class HeadlinesRequest extends ApiRequest {
|
||||
|
||||
private int m_offset = 0;
|
||||
private OnlineActivity m_activity;
|
||||
private ArticleList m_articles = GlobalState.getInstance().m_loadedArticles;
|
||||
private ArticleList m_articles; // = new ArticleList(); //GlobalState.getInstance().m_loadedArticles;
|
||||
private Feed m_feed;
|
||||
|
||||
public HeadlinesRequest(Context context, OnlineActivity activity, final Feed feed) {
|
||||
public HeadlinesRequest(Context context, OnlineActivity activity, final Feed feed, ArticleList articles) {
|
||||
super(context);
|
||||
|
||||
|
||||
m_articles = articles;
|
||||
m_activity = activity;
|
||||
m_feed = feed;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user