From ba12f1bba2d91509e2bafe52f4d019cba543257e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 4 Jun 2017 06:56:04 +0300 Subject: [PATCH] headlines fragment: assorted fixes, mostly related to footer placement video related fix if surface was destroyed while player was initializing --- .../org/fox/ttrss/GalleryVideoFragment.java | 12 ++-- .../java/org/fox/ttrss/HeadlinesFragment.java | 64 ++++++++----------- .../java/org/fox/ttrss/MasterActivity.java | 2 +- .../org/fox/ttrss/util/HeadlinesRequest.java | 6 +- .../src/main/res/layout/headlines_footer.xml | 3 +- 5 files changed, 40 insertions(+), 47 deletions(-) diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/GalleryVideoFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/GalleryVideoFragment.java index 387781f5..8b7bb024 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/GalleryVideoFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/GalleryVideoFragment.java @@ -215,11 +215,15 @@ public class GalleryVideoFragment extends GalleryBaseFragment { getView().findViewById(R.id.flavor_image).setVisibility(View.GONE); getView().findViewById(R.id.flavor_image_progress).setVisibility(View.GONE); - resizeSurface(textureView); - mp.setLooping(true); + try { + resizeSurface(textureView); + mp.setLooping(true); - if (m_userVisibleHint) { - mp.start(); + if (m_userVisibleHint) { + mp.start(); + } + } catch (IllegalStateException e) { + e.printStackTrace(); } } }); 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 2f30272b..373e8d49 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java @@ -93,7 +93,7 @@ public class HeadlinesFragment extends Fragment { public static final int THUMB_IMG_MIN_SIZE = 32; public static final int HEADLINES_REQUEST_SIZE = 30; - public static final int HEADLINES_BUFFER_MAX = 500; + public static final int HEADLINES_BUFFER_MAX = 1000; private final String TAG = this.getClass().getSimpleName(); @@ -118,10 +118,6 @@ public class HeadlinesFragment extends Fragment { private RecyclerView m_list; private LinearLayoutManager m_layoutManager; - /*private View m_listLoadingView; - private View m_topChangedView; - private View m_amrFooterView;*/ - private MediaPlayer m_mediaPlayer; private TextureView m_activeTexture; @@ -289,7 +285,8 @@ public class HeadlinesFragment extends Fragment { if (isAdded() || m_activity != null) { View view = getActivity().getLayoutInflater().inflate(layoutId, m_list, false); - if (layoutId == R.layout.headlines_footer) { + // only resize footer if auto mark as read is enabled + if (layoutId == R.layout.headlines_footer && m_prefs.getBoolean("headlines_mark_read_scroll", false)) { WindowManager wm = (WindowManager) m_activity.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); int screenHeight = display.getHeight(); @@ -448,27 +445,13 @@ public class HeadlinesFragment extends Fragment { fab.setVisibility(View.GONE); } - /*m_listLoadingView = inflater.inflate(R.layout.headlines_row_loadmore, m_list, false); - m_topChangedView = inflater.inflate(R.layout.headlines_row_top_changed, m_list, false);*/ - - if (m_prefs.getBoolean("headlines_mark_read_scroll", false)) { - /*WindowManager wm = (WindowManager) m_activity.getSystemService(Context.WINDOW_SERVICE); - Display display = wm.getDefaultDisplay(); - int screenHeight = display.getHeight();*/ - - /*m_amrFooterView = inflater.inflate(R.layout.headlines_footer, container, false); - m_amrFooterView.setLayoutParams(new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT, screenHeight)); - - m_adapter.addFooterView(m_amrFooterView);*/ - } - if (m_activity.isSmallScreen()) { View layout = inflater.inflate(R.layout.headlines_heading_spacer, m_list, false); m_adapter.addHeaderView(layout); m_swipeLayout.setProgressViewOffset(false, 0, m_activity.getResources().getDimensionPixelSize(R.dimen.abc_action_bar_default_height_material) + - m_activity.getResources().getDimensionPixelSize(R.dimen.abc_action_bar_default_padding_end_material) + 5); + m_activity.getResources().getDimensionPixelSize(R.dimen.abc_action_bar_default_padding_end_material) + 15); } m_list.setOnScrollListener(new RecyclerView.OnScrollListener() { @@ -538,6 +521,8 @@ public class HeadlinesFragment extends Fragment { m_listPreviousVisibleItem = firstVisibleItem; } + //Log.d(TAG, "onScrolled: " + m_refreshInProgress + " " + m_lazyLoadDisabled + " " + lastVisibleItem + " " + m_articles.size()); + if (!m_refreshInProgress && !m_lazyLoadDisabled && lastVisibleItem >= m_articles.size() - 5) { refresh(true); } @@ -585,21 +570,23 @@ public class HeadlinesFragment extends Fragment { @SuppressWarnings({ "serial" }) public void refresh(final boolean append, boolean userInitiated) { - /*m_adapter.removeFooterView(m_listLoadingView); - m_adapter.removeFooterView(m_topChangedView); - m_adapter.removeFooterView(m_amrFooterView);*/ - m_adapter.removeAllFooterViews(); if (!append) m_lazyLoadDisabled = false; - if (m_activity != null && m_feed != null) { + if (m_activity != null && isAdded() && m_feed != null) { m_refreshInProgress = true; if (m_swipeLayout != null) m_swipeLayout.setRefreshing(true); if (!append) { - m_list.scrollToPosition(0); + m_articles.clear(); + m_adapter.notifyDataSetChanged(); + } else { + // TODO: should check footer presence by id? + if (m_adapter.getFooterCount() == 0) { + m_adapter.addFooterView(createListFooter(R.layout.headlines_row_loadmore)); + } } final String sessionId = m_activity.getSessionId(); @@ -616,12 +603,10 @@ public class HeadlinesFragment extends Fragment { if (isDetached() || !isAdded()) return; super.onPostExecute(result); + m_adapter.notifyDataSetChanged(); if (m_swipeLayout != null) m_swipeLayout.setRefreshing(false); - /*m_adapter.removeFooterView(m_listLoadingView); - m_adapter.removeFooterView(m_topChangedView); - m_adapter.removeFooterView(m_amrFooterView);*/ m_adapter.removeAllFooterViews(); if (result != null) { @@ -634,10 +619,12 @@ public class HeadlinesFragment extends Fragment { if (m_firstIdChanged) { m_lazyLoadDisabled = true; + //Log.d(TAG, "first id changed, disabling lazy load"); m_adapter.addFooterView(createListFooter(R.layout.headlines_row_top_changed)); } if (m_amountLoaded < HEADLINES_REQUEST_SIZE) { + //Log.d(TAG, "amount loaded < request size, disabling lazy load"); m_lazyLoadDisabled = true; } @@ -659,11 +646,11 @@ public class HeadlinesFragment extends Fragment { } } - if (m_prefs.getBoolean("headlines_mark_read_scroll", false)) - m_adapter.addFooterView(createListFooter(R.layout.headlines_footer)); + //if (m_prefs.getBoolean("headlines_mark_read_scroll", false)) + m_adapter.addFooterView(createListFooter(R.layout.headlines_footer)); } }; - + int skip = 0; if (append) { @@ -1297,10 +1284,13 @@ public class HeadlinesFragment extends Fragment { @Override public void onPrepared(MediaPlayer mp) { - bar.setVisibility(View.GONE); - //resizeSurface(); - mp.setLooping(true); - mp.start(); + try { + bar.setVisibility(View.GONE); + mp.setLooping(true); + mp.start(); + } catch (IllegalStateException e) { + e.printStackTrace(); + } } }); diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/MasterActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/MasterActivity.java index ee9cd729..7c4c6a56 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/MasterActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/MasterActivity.java @@ -539,7 +539,7 @@ public class MasterActivity extends OnlineActivity implements HeadlinesEventList if (hf != null) { hf.setArticles(articles); - hf.setActiveArticle(article); + //hf.setActiveArticle(article); disable HL scrolling on resume for now } } diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/util/HeadlinesRequest.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/util/HeadlinesRequest.java index 8cb1a3c1..f87a4d2b 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/util/HeadlinesRequest.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/util/HeadlinesRequest.java @@ -11,6 +11,7 @@ import com.google.gson.reflect.TypeToken; import org.fox.ttrss.ApiCommon; import org.fox.ttrss.ApiRequest; +import org.fox.ttrss.HeadlinesFragment; import org.fox.ttrss.OnlineActivity; import org.fox.ttrss.types.Article; import org.fox.ttrss.types.ArticleList; @@ -20,9 +21,6 @@ import java.lang.reflect.Type; import java.util.List; public class HeadlinesRequest extends ApiRequest { - public static final int HEADLINES_REQUEST_SIZE = 30; - public static final int HEADLINES_BUFFER_MAX = 1500; - private final String TAG = this.getClass().getSimpleName(); private int m_offset = 0; @@ -83,7 +81,7 @@ public class HeadlinesRequest extends ApiRequest { if (m_offset == 0) { m_articles.clear(); } else { - while (m_articles.size() > HEADLINES_BUFFER_MAX) { + while (m_articles.size() > HeadlinesFragment.HEADLINES_BUFFER_MAX) { m_articles.remove(0); } diff --git a/org.fox.ttrss/src/main/res/layout/headlines_footer.xml b/org.fox.ttrss/src/main/res/layout/headlines_footer.xml index ca5c6546..a734a294 100644 --- a/org.fox.ttrss/src/main/res/layout/headlines_footer.xml +++ b/org.fox.ttrss/src/main/res/layout/headlines_footer.xml @@ -3,11 +3,12 @@ + android:layout_height="wrap_content">