when exiting headlines activity, properly select active article in the list
remove globalstate active article object
This commit is contained in:
parent
4913d9ce53
commit
568ab61fad
@ -478,14 +478,17 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
|
|||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (requestCode == HEADLINES_REQUEST) {
|
if (requestCode == HEADLINES_REQUEST) {
|
||||||
GlobalState.getInstance().m_activeArticle = null;
|
//GlobalState.getInstance().m_activeArticle = null;
|
||||||
|
|
||||||
ArrayList<Article> tmp = data.getParcelableArrayListExtra("articles");
|
ArrayList<Article> tmp = data.getParcelableArrayListExtra("articles");
|
||||||
|
Article article = data.getParcelableExtra("activeArticle");
|
||||||
|
|
||||||
if (tmp != null) {
|
if (tmp != null) {
|
||||||
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
|
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
|
||||||
|
|
||||||
if (hf != null) {
|
if (hf != null) {
|
||||||
hf.setArticles(tmp);
|
hf.setArticles(tmp);
|
||||||
|
hf.setActiveArticle(article);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@ import android.os.Bundle;
|
|||||||
import org.acra.ACRA;
|
import org.acra.ACRA;
|
||||||
import org.acra.ReportingInteractionMode;
|
import org.acra.ReportingInteractionMode;
|
||||||
import org.acra.annotation.ReportsCrashes;
|
import org.acra.annotation.ReportsCrashes;
|
||||||
import org.fox.ttrss.types.Article;
|
|
||||||
import org.fox.ttrss.types.Feed;
|
import org.fox.ttrss.types.Feed;
|
||||||
@ReportsCrashes(formKey = "", mode = ReportingInteractionMode.DIALOG,
|
@ReportsCrashes(formKey = "", mode = ReportingInteractionMode.DIALOG,
|
||||||
resDialogText = R.string.crash_dialog_text,
|
resDialogText = R.string.crash_dialog_text,
|
||||||
@ -16,7 +15,7 @@ public class GlobalState extends Application {
|
|||||||
|
|
||||||
//public ArticleList m_loadedArticles = new ArticleList();
|
//public ArticleList m_loadedArticles = new ArticleList();
|
||||||
public Feed m_activeFeed;
|
public Feed m_activeFeed;
|
||||||
public Article m_activeArticle;
|
//public Article m_activeArticle;
|
||||||
public int m_selectedArticleId;
|
public int m_selectedArticleId;
|
||||||
public String m_sessionId;
|
public String m_sessionId;
|
||||||
public int m_apiLevel;
|
public int m_apiLevel;
|
||||||
@ -39,7 +38,7 @@ public class GlobalState extends Application {
|
|||||||
out.setClassLoader(getClass().getClassLoader());
|
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:activeFeed", m_activeFeed);
|
||||||
out.putParcelable("gs:activeArticle", m_activeArticle);
|
//out.putParcelable("gs:activeArticle", m_activeArticle);
|
||||||
out.putString("gs:sessionId", m_sessionId);
|
out.putString("gs:sessionId", m_sessionId);
|
||||||
out.putInt("gs:apiLevel", m_apiLevel);
|
out.putInt("gs:apiLevel", m_apiLevel);
|
||||||
out.putBoolean("gs:canUseProgress", m_canUseProgress);
|
out.putBoolean("gs:canUseProgress", m_canUseProgress);
|
||||||
@ -55,7 +54,7 @@ public class GlobalState extends Application {
|
|||||||
} */
|
} */
|
||||||
|
|
||||||
m_activeFeed = (Feed) in.getParcelable("gs:activeFeed");
|
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_sessionId = in.getString("gs:sessionId");
|
||||||
m_apiLevel = in.getInt("gs:apiLevel");
|
m_apiLevel = in.getInt("gs:apiLevel");
|
||||||
m_canUseProgress = in.getBoolean("gs:canUseProgress");
|
m_canUseProgress = in.getBoolean("gs:canUseProgress");
|
||||||
|
@ -24,6 +24,7 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
|
|||||||
private ArticleList m_articles = new ArticleList();
|
private ArticleList m_articles = new ArticleList();
|
||||||
|
|
||||||
protected SharedPreferences m_prefs;
|
protected SharedPreferences m_prefs;
|
||||||
|
private Article m_activeArticle;
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
@Override
|
@Override
|
||||||
@ -153,6 +154,8 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
|
|||||||
|
|
||||||
Intent resultIntent = new Intent();
|
Intent resultIntent = new Intent();
|
||||||
resultIntent.putParcelableArrayListExtra("articles", m_articles);
|
resultIntent.putParcelableArrayListExtra("articles", m_articles);
|
||||||
|
resultIntent.putExtra("activeArticle", m_activeArticle);
|
||||||
|
|
||||||
setResult(Activity.RESULT_OK, resultIntent);
|
setResult(Activity.RESULT_OK, resultIntent);
|
||||||
|
|
||||||
finish();
|
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();
|
invalidateOptionsMenu();
|
||||||
|
|
||||||
@ -309,6 +314,8 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
|
|||||||
|
|
||||||
Intent resultIntent = new Intent();
|
Intent resultIntent = new Intent();
|
||||||
resultIntent.putParcelableArrayListExtra("articles", m_articles);
|
resultIntent.putParcelableArrayListExtra("articles", m_articles);
|
||||||
|
resultIntent.putExtra("activeArticle", m_activeArticle);
|
||||||
|
|
||||||
setResult(Activity.RESULT_OK, resultIntent);
|
setResult(Activity.RESULT_OK, resultIntent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -368,10 +368,10 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
if (GlobalState.getInstance().m_activeArticle != null) {
|
/* if (GlobalState.getInstance().m_activeArticle != null) {
|
||||||
m_activeArticle = GlobalState.getInstance().m_activeArticle;
|
m_activeArticle = GlobalState.getInstance().m_activeArticle;
|
||||||
GlobalState.getInstance().m_activeArticle = null;
|
GlobalState.getInstance().m_activeArticle = null;
|
||||||
}
|
} */
|
||||||
|
|
||||||
if (m_activeArticle != null) {
|
if (m_activeArticle != null) {
|
||||||
setActiveArticle(m_activeArticle);
|
setActiveArticle(m_activeArticle);
|
||||||
@ -1079,15 +1079,18 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setActiveArticle(Article article) {
|
public void setActiveArticle(Article article) {
|
||||||
if (article != m_activeArticle) {
|
if (article != m_activeArticle && article != null) {
|
||||||
m_activeArticle = article;
|
m_activeArticle = article;
|
||||||
m_adapter.notifyDataSetChanged();
|
m_adapter.notifyDataSetChanged();
|
||||||
|
|
||||||
ListView list = (ListView)getView().findViewById(R.id.headlines_list);
|
ListView list = (ListView)getView().findViewById(R.id.headlines_list);
|
||||||
|
|
||||||
if (list != null && article != null) {
|
if (list != null) {
|
||||||
int position = m_adapter.getPosition(article);
|
int position = getArticlePositionById(article.id);
|
||||||
list.setSelection(position);
|
|
||||||
|
if (position != -1) {
|
||||||
|
list.smoothScrollToPosition(position);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1164,6 +1167,16 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
return m_activeArticle;
|
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) {
|
public int getArticlePosition(Article article) {
|
||||||
try {
|
try {
|
||||||
return m_adapter.getPosition(article);
|
return m_adapter.getPosition(article);
|
||||||
|
Loading…
Reference in New Issue
Block a user