headlines fragment: assorted fixes, mostly related to footer placement

video related fix if surface was destroyed while player was initializing
This commit is contained in:
Andrew Dolgov 2017-06-04 06:56:04 +03:00
parent 4ce672fa8e
commit ba12f1bba2
5 changed files with 40 additions and 47 deletions

View File

@ -215,12 +215,16 @@ public class GalleryVideoFragment extends GalleryBaseFragment {
getView().findViewById(R.id.flavor_image).setVisibility(View.GONE); getView().findViewById(R.id.flavor_image).setVisibility(View.GONE);
getView().findViewById(R.id.flavor_image_progress).setVisibility(View.GONE); getView().findViewById(R.id.flavor_image_progress).setVisibility(View.GONE);
try {
resizeSurface(textureView); resizeSurface(textureView);
mp.setLooping(true); mp.setLooping(true);
if (m_userVisibleHint) { if (m_userVisibleHint) {
mp.start(); mp.start();
} }
} catch (IllegalStateException e) {
e.printStackTrace();
}
} }
}); });

View File

@ -93,7 +93,7 @@ public class HeadlinesFragment extends Fragment {
public static final int THUMB_IMG_MIN_SIZE = 32; public static final int THUMB_IMG_MIN_SIZE = 32;
public static final int HEADLINES_REQUEST_SIZE = 30; 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(); private final String TAG = this.getClass().getSimpleName();
@ -118,10 +118,6 @@ public class HeadlinesFragment extends Fragment {
private RecyclerView m_list; private RecyclerView m_list;
private LinearLayoutManager m_layoutManager; private LinearLayoutManager m_layoutManager;
/*private View m_listLoadingView;
private View m_topChangedView;
private View m_amrFooterView;*/
private MediaPlayer m_mediaPlayer; private MediaPlayer m_mediaPlayer;
private TextureView m_activeTexture; private TextureView m_activeTexture;
@ -289,7 +285,8 @@ public class HeadlinesFragment extends Fragment {
if (isAdded() || m_activity != null) { if (isAdded() || m_activity != null) {
View view = getActivity().getLayoutInflater().inflate(layoutId, m_list, false); 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); WindowManager wm = (WindowManager) m_activity.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay(); Display display = wm.getDefaultDisplay();
int screenHeight = display.getHeight(); int screenHeight = display.getHeight();
@ -448,27 +445,13 @@ public class HeadlinesFragment extends Fragment {
fab.setVisibility(View.GONE); 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()) { if (m_activity.isSmallScreen()) {
View layout = inflater.inflate(R.layout.headlines_heading_spacer, m_list, false); View layout = inflater.inflate(R.layout.headlines_heading_spacer, m_list, false);
m_adapter.addHeaderView(layout); m_adapter.addHeaderView(layout);
m_swipeLayout.setProgressViewOffset(false, 0, 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_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() { m_list.setOnScrollListener(new RecyclerView.OnScrollListener() {
@ -538,6 +521,8 @@ public class HeadlinesFragment extends Fragment {
m_listPreviousVisibleItem = firstVisibleItem; 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) { if (!m_refreshInProgress && !m_lazyLoadDisabled && lastVisibleItem >= m_articles.size() - 5) {
refresh(true); refresh(true);
} }
@ -585,21 +570,23 @@ public class HeadlinesFragment extends Fragment {
@SuppressWarnings({ "serial" }) @SuppressWarnings({ "serial" })
public void refresh(final boolean append, boolean userInitiated) { 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(); m_adapter.removeAllFooterViews();
if (!append) m_lazyLoadDisabled = false; if (!append) m_lazyLoadDisabled = false;
if (m_activity != null && m_feed != null) { if (m_activity != null && isAdded() && m_feed != null) {
m_refreshInProgress = true; m_refreshInProgress = true;
if (m_swipeLayout != null) m_swipeLayout.setRefreshing(true); if (m_swipeLayout != null) m_swipeLayout.setRefreshing(true);
if (!append) { 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(); final String sessionId = m_activity.getSessionId();
@ -616,12 +603,10 @@ public class HeadlinesFragment extends Fragment {
if (isDetached() || !isAdded()) return; if (isDetached() || !isAdded()) return;
super.onPostExecute(result); super.onPostExecute(result);
m_adapter.notifyDataSetChanged();
if (m_swipeLayout != null) m_swipeLayout.setRefreshing(false); 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(); m_adapter.removeAllFooterViews();
if (result != null) { if (result != null) {
@ -634,10 +619,12 @@ public class HeadlinesFragment extends Fragment {
if (m_firstIdChanged) { if (m_firstIdChanged) {
m_lazyLoadDisabled = true; m_lazyLoadDisabled = true;
//Log.d(TAG, "first id changed, disabling lazy load");
m_adapter.addFooterView(createListFooter(R.layout.headlines_row_top_changed)); m_adapter.addFooterView(createListFooter(R.layout.headlines_row_top_changed));
} }
if (m_amountLoaded < HEADLINES_REQUEST_SIZE) { if (m_amountLoaded < HEADLINES_REQUEST_SIZE) {
//Log.d(TAG, "amount loaded < request size, disabling lazy load");
m_lazyLoadDisabled = true; m_lazyLoadDisabled = true;
} }
@ -659,7 +646,7 @@ public class HeadlinesFragment extends Fragment {
} }
} }
if (m_prefs.getBoolean("headlines_mark_read_scroll", false)) //if (m_prefs.getBoolean("headlines_mark_read_scroll", false))
m_adapter.addFooterView(createListFooter(R.layout.headlines_footer)); m_adapter.addFooterView(createListFooter(R.layout.headlines_footer));
} }
}; };
@ -1297,10 +1284,13 @@ public class HeadlinesFragment extends Fragment {
@Override @Override
public void onPrepared(MediaPlayer mp) { public void onPrepared(MediaPlayer mp) {
try {
bar.setVisibility(View.GONE); bar.setVisibility(View.GONE);
//resizeSurface();
mp.setLooping(true); mp.setLooping(true);
mp.start(); mp.start();
} catch (IllegalStateException e) {
e.printStackTrace();
}
} }
}); });

View File

@ -539,7 +539,7 @@ public class MasterActivity extends OnlineActivity implements HeadlinesEventList
if (hf != null) { if (hf != null) {
hf.setArticles(articles); hf.setArticles(articles);
hf.setActiveArticle(article); //hf.setActiveArticle(article); disable HL scrolling on resume for now
} }
} }

View File

@ -11,6 +11,7 @@ import com.google.gson.reflect.TypeToken;
import org.fox.ttrss.ApiCommon; import org.fox.ttrss.ApiCommon;
import org.fox.ttrss.ApiRequest; import org.fox.ttrss.ApiRequest;
import org.fox.ttrss.HeadlinesFragment;
import org.fox.ttrss.OnlineActivity; import org.fox.ttrss.OnlineActivity;
import org.fox.ttrss.types.Article; import org.fox.ttrss.types.Article;
import org.fox.ttrss.types.ArticleList; import org.fox.ttrss.types.ArticleList;
@ -20,9 +21,6 @@ import java.lang.reflect.Type;
import java.util.List; import java.util.List;
public class HeadlinesRequest extends ApiRequest { 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 final String TAG = this.getClass().getSimpleName();
private int m_offset = 0; private int m_offset = 0;
@ -83,7 +81,7 @@ public class HeadlinesRequest extends ApiRequest {
if (m_offset == 0) { if (m_offset == 0) {
m_articles.clear(); m_articles.clear();
} else { } else {
while (m_articles.size() > HEADLINES_BUFFER_MAX) { while (m_articles.size() > HeadlinesFragment.HEADLINES_BUFFER_MAX) {
m_articles.remove(0); m_articles.remove(0);
} }

View File

@ -3,11 +3,12 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/headlines_footer" android:id="@+id/headlines_footer"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent"> android:layout_height="wrap_content">
<View <View
android:layout_gravity="top|center_horizontal" android:layout_gravity="top|center_horizontal"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="128dp" android:layout_width="128dp"
android:layout_height="1dp" android:layout_height="1dp"
android:background="?headlineFooterColor"/> android:background="?headlineFooterColor"/>