article fragment & article pager: move some stuff into runnables to increase perceived performance

This commit is contained in:
Andrew Dolgov 2017-05-29 14:34:50 +03:00
parent e83d4ca2ab
commit ef097f79af
2 changed files with 35 additions and 21 deletions

View File

@ -7,6 +7,7 @@ import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
@ -57,7 +58,6 @@ public class ArticleFragment extends Fragment {
protected int m_articleFontSize;
protected int m_articleSmallFontSize;
protected boolean m_acceleratedWebview = true;
private boolean m_isVisible;
public void initialize(Article article) {
m_article = article;
@ -154,15 +154,6 @@ public class ArticleFragment extends Fragment {
}
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
m_isVisible = isVisibleToUser;
renderContent(null);
}
@SuppressLint("NewApi")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) {
@ -398,9 +389,16 @@ public class ArticleFragment extends Fragment {
m_web.setVisibility(View.VISIBLE);
if (savedInstanceState != null || m_isVisible) renderContent(savedInstanceState);
//renderContent(savedInstanceState);
return view;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
renderContent(savedInstanceState);
}
}, 250);
return view;
}
protected void renderContent(Bundle savedInstanceState) {

View File

@ -6,6 +6,7 @@ import android.content.SharedPreferences;
import android.net.Uri;
import android.os.BadParcelableException;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.ClassloaderWorkaroundFragmentStatePagerAdapter;
import android.support.v4.app.Fragment;
@ -45,6 +46,8 @@ public class ArticlePager extends Fragment {
super(fm);
}
private ArticleFragment m_currentFragment;
@Override
public Fragment getItem(int position) {
Article article = m_articles.get(position);
@ -62,7 +65,18 @@ public class ArticlePager extends Fragment {
public int getCount() {
return m_articles.size();
}
public ArticleFragment getCurrentFragment() {
return m_currentFragment;
}
@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
m_currentFragment = ((ArticleFragment) object);
super.setPrimaryItem(container, position, object);
}
}
public void initialize(Article article, Feed feed, ArticleList articles) {
@ -119,18 +133,20 @@ public class ArticlePager extends Fragment {
@Override
public void onPageSelected(int position) {
Article article = m_articles.get(position);
Log.d(TAG, "onPageSelected: " + position);
final Article article = m_articles.get(position);
if (article != null) {
m_article = article;
/* if (article.unread) {
article.unread = false;
m_activity.saveArticleUnread(article);
} */
m_listener.onArticleSelected(article, false);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
m_listener.onArticleSelected(article, false);
}
}, 250);
//Log.d(TAG, "Page #" + position + "/" + m_adapter.getCount());
if ((m_activity.isSmallScreen() || m_activity.isPortrait()) && position == m_adapter.getCount() - 15) {