diff options
4 files changed, 36 insertions, 14 deletions
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsActivity.java index c882ed1c..669bef08 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsActivity.java @@ -478,14 +478,17 @@ 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"); + Article article = data.getParcelableExtra("activeArticle"); if (tmp != null) { HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES); + if (hf != null) { hf.setArticles(tmp); + hf.setActiveArticle(article); } } diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/GlobalState.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/GlobalState.java index da5bbd90..be9b8fd2 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/GlobalState.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/GlobalState.java @@ -6,7 +6,6 @@ import android.os.Bundle; import org.acra.ACRA; import org.acra.ReportingInteractionMode; import org.acra.annotation.ReportsCrashes; -import org.fox.ttrss.types.Article; import org.fox.ttrss.types.Feed; @ReportsCrashes(formKey = "", mode = ReportingInteractionMode.DIALOG, resDialogText = R.string.crash_dialog_text, @@ -16,7 +15,7 @@ public class GlobalState extends Application { //public ArticleList m_loadedArticles = new ArticleList(); public Feed m_activeFeed; - public Article m_activeArticle; + //public Article m_activeArticle; public int m_selectedArticleId; public String m_sessionId; public int m_apiLevel; @@ -39,7 +38,7 @@ public class GlobalState extends Application { out.setClassLoader(getClass().getClassLoader()); //out.putParcelableArrayList("gs:loadedArticles", m_loadedArticles); out.putParcelable("gs:activeFeed", m_activeFeed); - out.putParcelable("gs:activeArticle", m_activeArticle); + //out.putParcelable("gs:activeArticle", m_activeArticle); out.putString("gs:sessionId", m_sessionId); out.putInt("gs:apiLevel", m_apiLevel); out.putBoolean("gs:canUseProgress", m_canUseProgress); @@ -55,7 +54,7 @@ public class GlobalState extends Application { } */ m_activeFeed = (Feed) in.getParcelable("gs:activeFeed"); - m_activeArticle = (Article) in.getParcelable("gs:activeArticle"); + //m_activeArticle = (Article) in.getParcelable("gs:activeArticle"); m_sessionId = in.getString("gs:sessionId"); m_apiLevel = in.getInt("gs:apiLevel"); m_canUseProgress = in.getBoolean("gs:canUseProgress"); diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesActivity.java index 86be7e43..cc7cc82f 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesActivity.java @@ -24,8 +24,9 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL private ArticleList m_articles = new ArticleList(); protected SharedPreferences m_prefs; + private Article m_activeArticle; - @SuppressLint("NewApi") + @SuppressLint("NewApi") @Override public void onCreate(Bundle savedInstanceState) { m_prefs = PreferenceManager @@ -153,6 +154,8 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL Intent resultIntent = new Intent(); resultIntent.putParcelableArrayListExtra("articles", m_articles); + resultIntent.putExtra("activeArticle", m_activeArticle); + setResult(Activity.RESULT_OK, resultIntent); finish(); @@ -245,7 +248,9 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL } } - GlobalState.getInstance().m_activeArticle = article; + m_activeArticle = article; + + //GlobalState.getInstance().m_activeArticle = article; invalidateOptionsMenu(); @@ -309,6 +314,8 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL Intent resultIntent = new Intent(); resultIntent.putParcelableArrayListExtra("articles", m_articles); + resultIntent.putExtra("activeArticle", m_activeArticle); + setResult(Activity.RESULT_OK, resultIntent); } diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java index 6bfe64c0..43fbb163 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java @@ -368,10 +368,10 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, public void onResume() { super.onResume(); - if (GlobalState.getInstance().m_activeArticle != null) { + /* if (GlobalState.getInstance().m_activeArticle != null) { m_activeArticle = GlobalState.getInstance().m_activeArticle; GlobalState.getInstance().m_activeArticle = null; - } + } */ if (m_activeArticle != null) { setActiveArticle(m_activeArticle); @@ -1079,15 +1079,18 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, } public void setActiveArticle(Article article) { - if (article != m_activeArticle) { + if (article != m_activeArticle && article != null) { m_activeArticle = article; m_adapter.notifyDataSetChanged(); ListView list = (ListView)getView().findViewById(R.id.headlines_list); - - if (list != null && article != null) { - int position = m_adapter.getPosition(article); - list.setSelection(position); + + if (list != null) { + int position = getArticlePositionById(article.id); + + if (position != -1) { + list.smoothScrollToPosition(position); + } } } } @@ -1164,6 +1167,16 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, return m_activeArticle; } + public int getArticlePositionById(int id) { + for (Article a : m_adapter.items) { + if (a.id == id) { + return m_adapter.getPosition(a); + } + } + + return -1; + } + public int getArticlePosition(Article article) { try { return m_adapter.getPosition(article); |