diff options
author | Andrew Dolgov <[email protected]> | 2018-03-08 14:18:05 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2018-03-08 14:18:05 +0300 |
commit | 05ff147fe669ca41600e3419519118d7621feff0 (patch) | |
tree | 12f07f096b4265c7eb3b4daa8da30eb9f6778bde /org.fox.ttrss/src/main | |
parent | c8072f4df8d31c4e4bc4bdfd7e16ddd81b0bfa08 (diff) |
common fragments: use icepick/bridge
Diffstat (limited to 'org.fox.ttrss/src/main')
-rwxr-xr-x | org.fox.ttrss/src/main/AndroidManifest.xml | 4 | ||||
-rwxr-xr-x | org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleFragment.java | 38 | ||||
-rwxr-xr-x | org.fox.ttrss/src/main/java/org/fox/ttrss/BaseFeedlistFragment.java | 25 | ||||
-rwxr-xr-x | org.fox.ttrss/src/main/java/org/fox/ttrss/FeedCategoriesFragment.java | 31 | ||||
-rwxr-xr-x | org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsFragment.java | 36 | ||||
-rwxr-xr-x[-rw-r--r--] | org.fox.ttrss/src/main/java/org/fox/ttrss/GalleryBaseFragment.java | 6 | ||||
-rwxr-xr-x[-rw-r--r--] | org.fox.ttrss/src/main/java/org/fox/ttrss/GalleryImageFragment.java | 23 | ||||
-rwxr-xr-x[-rw-r--r--] | org.fox.ttrss/src/main/java/org/fox/ttrss/GalleryVideoFragment.java | 34 | ||||
-rwxr-xr-x | org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java | 98 |
9 files changed, 93 insertions, 202 deletions
diff --git a/org.fox.ttrss/src/main/AndroidManifest.xml b/org.fox.ttrss/src/main/AndroidManifest.xml index 711b5faa..5bd95214 100755 --- a/org.fox.ttrss/src/main/AndroidManifest.xml +++ b/org.fox.ttrss/src/main/AndroidManifest.xml @@ -1,8 +1,8 @@ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.fox.ttrss" - android:versionCode="465" - android:versionName="1.231"> + android:versionCode="466" + android:versionName="1.232"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleFragment.java index 170b0f8e..abff7edd 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleFragment.java @@ -9,7 +9,6 @@ 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; import android.text.Html; import android.util.Log; @@ -43,11 +42,13 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; -public class ArticleFragment extends Fragment { +import icepick.State; + +public class ArticleFragment extends StateSavedFragment { private final String TAG = this.getClass().getSimpleName(); private SharedPreferences m_prefs; - private Article m_article; + @State protected Article m_article; private DetailActivity m_activity; private WebView m_web; protected View m_customView; @@ -158,11 +159,6 @@ public class ArticleFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) { - if (savedInstanceState != null) { - m_article = savedInstanceState.getParcelable("article"); - //m_fsviewShown = savedInstanceState.getBoolean("fsviewShown"); - } - final View view = inflater.inflate(R.layout.fragment_article, container, false); /* if (m_fsviewShown) { @@ -171,7 +167,7 @@ public class ArticleFragment extends Fragment { } */ m_contentView = view.findViewById(R.id.article_scrollview); - m_customViewContainer = (FrameLayout) view.findViewById(R.id.article_fullscreen_video); + m_customViewContainer = view.findViewById(R.id.article_fullscreen_video); /* if (m_article.id == HeadlinesFragment.ARTICLE_SPECIAL_TOP_CHANGED) { TextView statusMessage = (TextView) view.findViewById(R.id.article_status_message); @@ -184,7 +180,7 @@ public class ArticleFragment extends Fragment { return view; } */ - NotifyingScrollView scrollView = (NotifyingScrollView) view.findViewById(R.id.article_scrollview); + NotifyingScrollView scrollView = view.findViewById(R.id.article_scrollview); m_fab = view.findViewById(R.id.article_fab); if (scrollView != null && m_activity.isSmallScreen()) { @@ -228,7 +224,7 @@ public class ArticleFragment extends Fragment { m_articleFontSize = Integer.parseInt(m_prefs.getString("article_font_size_sp", "16")); m_articleSmallFontSize = Math.max(10, Math.min(18, m_articleFontSize - 2)); - TextView title = (TextView)view.findViewById(R.id.title); + TextView title = view.findViewById(R.id.title); if (title != null) { @@ -257,7 +253,7 @@ public class ArticleFragment extends Fragment { } - ImageView share = (ImageView)view.findViewById(R.id.share); + ImageView share = view.findViewById(R.id.share); if (share != null) { share.setOnClickListener(new OnClickListener() { @@ -268,7 +264,7 @@ public class ArticleFragment extends Fragment { }); } - TextView comments = (TextView)view.findViewById(R.id.comments); + TextView comments = view.findViewById(R.id.comments); if (comments != null) { if (m_activity.getApiLevel() >= 4 && m_article.comments_count > 0) { @@ -297,7 +293,7 @@ public class ArticleFragment extends Fragment { } } - TextView note = (TextView)view.findViewById(R.id.note); + TextView note = view.findViewById(R.id.note); if (note != null) { if (m_article.note != null && !"".equals(m_article.note)) { @@ -309,7 +305,7 @@ public class ArticleFragment extends Fragment { } - TextView dv = (TextView)view.findViewById(R.id.date); + TextView dv = view.findViewById(R.id.date); if (dv != null) { dv.setTextSize(TypedValue.COMPLEX_UNIT_SP, m_articleSmallFontSize); @@ -319,7 +315,7 @@ public class ArticleFragment extends Fragment { dv.setText(df.format(d)); } - TextView tagv = (TextView)view.findViewById(R.id.tags); + TextView tagv = view.findViewById(R.id.tags); if (tagv != null) { tagv.setTextSize(TypedValue.COMPLEX_UNIT_SP, m_articleSmallFontSize); @@ -346,7 +342,7 @@ public class ArticleFragment extends Fragment { } } - m_web = (WebView)view.findViewById(R.id.article_content); + m_web = view.findViewById(R.id.article_content); m_web.setWebViewClient(new WebViewClient() { @Override @@ -564,14 +560,6 @@ public class ArticleFragment extends Fragment { } @Override - public void onSaveInstanceState (Bundle out) { - super.onSaveInstanceState(out); - - out.setClassLoader(getClass().getClassLoader()); - out.putParcelable("article", m_article); - } - - @Override public void onAttach(Activity activity) { super.onAttach(activity); diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/BaseFeedlistFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/BaseFeedlistFragment.java index 4220450d..ec4e4a7a 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/BaseFeedlistFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/BaseFeedlistFragment.java @@ -4,7 +4,6 @@ import android.content.Intent; import android.content.SharedPreferences; import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityOptionsCompat; -import android.support.v4.app.Fragment; import android.support.v7.widget.SwitchCompat; import android.util.TypedValue; import android.view.InflateException; @@ -20,7 +19,7 @@ import org.fox.ttrss.offline.OfflineActivity; import java.net.MalformedURLException; import java.net.URL; -public abstract class BaseFeedlistFragment extends Fragment { +public abstract class BaseFeedlistFragment extends StateSavedFragment { abstract public void refresh(); public void initDrawerHeader(LayoutInflater inflater, View view, ListView list, final CommonActivity activity, final SharedPreferences prefs, boolean isRoot) { @@ -36,8 +35,8 @@ public abstract class BaseFeedlistFragment extends Fragment { View layout = inflater.inflate(R.layout.drawer_header, list, false); list.addHeaderView(layout, null, false); - TextView login = (TextView) view.findViewById(R.id.drawer_header_login); - TextView server = (TextView) view.findViewById(R.id.drawer_header_server); + TextView login = view.findViewById(R.id.drawer_header_login); + TextView server = view.findViewById(R.id.drawer_header_server); login.setText(prefs.getString("login", "")); try { @@ -84,15 +83,15 @@ public abstract class BaseFeedlistFragment extends Fragment { // unread only checkbox footer = inflater.inflate(R.layout.feeds_row_toggle, list, false); list.addFooterView(footer); - TextView text = (TextView) footer.findViewById(R.id.title); + TextView text = footer.findViewById(R.id.title); text.setText(R.string.unread_only); - ImageView icon = (ImageView) footer.findViewById(R.id.icon); + ImageView icon = footer.findViewById(R.id.icon); TypedValue tv = new TypedValue(); getActivity().getTheme().resolveAttribute(R.attr.ic_filter_variant, tv, true); icon.setImageResource(tv.resourceId); - final SwitchCompat rowSwitch = (SwitchCompat) footer.findViewById(R.id.row_switch); + final SwitchCompat rowSwitch = footer.findViewById(R.id.row_switch); rowSwitch.setChecked(activity.getUnreadOnly()); rowSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @@ -134,15 +133,15 @@ public abstract class BaseFeedlistFragment extends Fragment { }); list.addFooterView(footer); - text = (TextView) footer.findViewById(R.id.title); + text = footer.findViewById(R.id.title); text.setText(R.string.action_settings); - icon = (ImageView) footer.findViewById(R.id.icon); + icon = footer.findViewById(R.id.icon); tv = new TypedValue(); getActivity().getTheme().resolveAttribute(R.attr.ic_settings, tv, true); icon.setImageResource(tv.resourceId); - TextView counter = (TextView) footer.findViewById(R.id.unread_counter); + TextView counter = footer.findViewById(R.id.unread_counter); counter.setText(R.string.blank); } @@ -161,15 +160,15 @@ public abstract class BaseFeedlistFragment extends Fragment { }); list.addFooterView(footer); - text = (TextView) footer.findViewById(R.id.title); + text = footer.findViewById(R.id.title); text.setText(isOffline ? R.string.go_online : R.string.go_offline); - icon = (ImageView) footer.findViewById(R.id.icon); + icon = footer.findViewById(R.id.icon); tv = new TypedValue(); getActivity().getTheme().resolveAttribute(isOffline ? R.attr.ic_cloud_upload : R.attr.ic_cloud_download, tv, true); icon.setImageResource(tv.resourceId); - TextView counter = (TextView) footer.findViewById(R.id.unread_counter); + TextView counter = footer.findViewById(R.id.unread_counter); counter.setText(R.string.blank); } diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedCategoriesFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedCategoriesFragment.java index d9131958..ead5e74f 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedCategoriesFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedCategoriesFragment.java @@ -45,12 +45,14 @@ import java.util.Comparator; import java.util.HashMap; import java.util.List; +import icepick.State; + public class FeedCategoriesFragment extends BaseFeedlistFragment implements OnItemClickListener, OnSharedPreferenceChangeListener, LoaderManager.LoaderCallbacks<JsonElement> { private final String TAG = this.getClass().getSimpleName(); private FeedCategoryListAdapter m_adapter; private FeedCategoryList m_cats = new FeedCategoryList(); - private FeedCategory m_selectedCat; + @State FeedCategory m_selectedCat; private MasterActivity m_activity; private SwipeRefreshLayout m_swipeLayout; private ListView m_list; @@ -318,14 +320,10 @@ public class FeedCategoriesFragment extends BaseFeedlistFragment implements OnIt @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - if (savedInstanceState != null) { - m_selectedCat = savedInstanceState.getParcelable("selectedCat"); - //m_cats = savedInstanceState.getParcelable("cats"); - } - + View view = inflater.inflate(R.layout.fragment_cats, container, false); - m_swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.feeds_swipe_container); + m_swipeLayout = view.findViewById(R.id.feeds_swipe_container); m_swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override @@ -334,8 +332,8 @@ public class FeedCategoriesFragment extends BaseFeedlistFragment implements OnIt } }); - m_list = (ListView)view.findViewById(R.id.feeds); - m_adapter = new FeedCategoryListAdapter(getActivity(), R.layout.feeds_row, (ArrayList<FeedCategory>)m_cats); + m_list = view.findViewById(R.id.feeds); + m_adapter = new FeedCategoryListAdapter(getActivity(), R.layout.feeds_row, m_cats); initDrawerHeader(inflater, view, m_list, m_activity, m_prefs, true); @@ -366,15 +364,6 @@ public class FeedCategoriesFragment extends BaseFeedlistFragment implements OnIt m_activity.invalidateOptionsMenu(); } - @Override - public void onSaveInstanceState (Bundle out) { - super.onSaveInstanceState(out); - - out.setClassLoader(getClass().getClassLoader()); - out.putParcelable("selectedCat", m_selectedCat); - //out.putParcelable("cats", m_cats); - } - public void refresh() { if (!isAdded()) return; @@ -433,7 +422,7 @@ public class FeedCategoriesFragment extends BaseFeedlistFragment implements OnIt } - ImageView icon = (ImageView) v.findViewById(R.id.icon); + ImageView icon = v.findViewById(R.id.icon); if (icon != null) { TypedValue tv = new TypedValue(); @@ -443,13 +432,13 @@ public class FeedCategoriesFragment extends BaseFeedlistFragment implements OnIt } - TextView tt = (TextView) v.findViewById(R.id.title); + TextView tt = v.findViewById(R.id.title); if (tt != null) { tt.setText(cat.title); } - TextView tu = (TextView) v.findViewById(R.id.unread_counter); + TextView tu = v.findViewById(R.id.unread_counter); if (tu != null) { tu.setText(String.valueOf(cat.unread)); diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsFragment.java index 02f98a4d..bd69958f 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsFragment.java @@ -47,6 +47,8 @@ import java.util.Comparator; import java.util.HashMap; import java.util.List; +import icepick.State; + public class FeedsFragment extends BaseFeedlistFragment implements OnItemClickListener, OnSharedPreferenceChangeListener, LoaderManager.LoaderCallbacks<JsonElement> { private final String TAG = this.getClass().getSimpleName(); @@ -54,10 +56,10 @@ public class FeedsFragment extends BaseFeedlistFragment implements OnItemClickLi private FeedListAdapter m_adapter; private FeedList m_feeds = new FeedList(); private MasterActivity m_activity; - private Feed m_selectedFeed; - private FeedCategory m_activeCategory; + @State Feed m_selectedFeed; + @State FeedCategory m_activeCategory; private SwipeRefreshLayout m_swipeLayout; - private boolean m_enableParentBtn = false; + @State boolean m_enableParentBtn = false; private ListView m_list; public void initialize(FeedCategory cat, boolean enableParentBtn) { @@ -353,15 +355,9 @@ public class FeedsFragment extends BaseFeedlistFragment implements OnItemClickLi @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - if (savedInstanceState != null) { - m_selectedFeed = savedInstanceState.getParcelable("selectedFeed"); - m_activeCategory = savedInstanceState.getParcelable("activeCat"); - m_enableParentBtn = savedInstanceState.getBoolean("enableParentBtn"); - } - View view = inflater.inflate(R.layout.fragment_feeds, container, false); - m_swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.feeds_swipe_container); + m_swipeLayout = view.findViewById(R.id.feeds_swipe_container); m_swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override @@ -370,7 +366,7 @@ public class FeedsFragment extends BaseFeedlistFragment implements OnItemClickLi } }); - m_list = (ListView)view.findViewById(R.id.feeds); + m_list = view.findViewById(R.id.feeds); initDrawerHeader(inflater, view, m_list, m_activity, m_prefs, !m_enableParentBtn); @@ -422,16 +418,6 @@ public class FeedsFragment extends BaseFeedlistFragment implements OnItemClickLi } @Override - public void onSaveInstanceState (Bundle out) { - super.onSaveInstanceState(out); - - out.setClassLoader(getClass().getClassLoader()); - out.putParcelable("selectedFeed", m_selectedFeed); - out.putParcelable("activeCat", m_activeCategory); - out.putBoolean("enableParentBtn", m_enableParentBtn); - } - - @Override public void onItemClick(AdapterView<?> av, View view, int position, long id) { ListView list = (ListView)av; @@ -483,7 +469,7 @@ public class FeedsFragment extends BaseFeedlistFragment implements OnItemClickLi @Override public boolean isEmpty() { - return m_enableParentBtn ? false : super.isEmpty(); + return !m_enableParentBtn && super.isEmpty(); } @Override @@ -522,7 +508,7 @@ public class FeedsFragment extends BaseFeedlistFragment implements OnItemClickLi } - ImageView icon = (ImageView) v.findViewById(R.id.icon); + ImageView icon = v.findViewById(R.id.icon); if (icon != null) { TypedValue tv = new TypedValue(); @@ -552,7 +538,7 @@ public class FeedsFragment extends BaseFeedlistFragment implements OnItemClickLi } - TextView tt = (TextView) v.findViewById(R.id.title); + TextView tt = v.findViewById(R.id.title); if (tt != null) { tt.setText(feed.display_title != null ? feed.display_title : feed.title); @@ -565,7 +551,7 @@ public class FeedsFragment extends BaseFeedlistFragment implements OnItemClickLi } - TextView tu = (TextView) v.findViewById(R.id.unread_counter); + TextView tu = v.findViewById(R.id.unread_counter); if (tu != null) { tu.setText(String.valueOf(feed.unread)); diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/GalleryBaseFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/GalleryBaseFragment.java index 1b2cbed3..338845a2 100644..100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/GalleryBaseFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/GalleryBaseFragment.java @@ -1,15 +1,11 @@ package org.fox.ttrss; import android.app.Activity; -import android.net.Uri; import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.util.Log; import android.view.ContextMenu; -import android.view.MenuItem; import android.view.View; -public class GalleryBaseFragment extends Fragment { +public class GalleryBaseFragment extends StateSavedFragment { private final String TAG = this.getClass().getSimpleName(); protected GalleryActivity m_activity; diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/GalleryImageFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/GalleryImageFragment.java index 075b97c4..92402501 100644..100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/GalleryImageFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/GalleryImageFragment.java @@ -5,12 +5,9 @@ import android.support.v4.app.ActivityCompat; import android.support.v4.view.ViewCompat; import android.util.Log; import android.view.LayoutInflater; -import android.view.MenuInflater; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; -import android.widget.PopupMenu; import android.widget.ProgressBar; import com.bogdwellers.pinchtozoom.ImageMatrixTouchHandler; @@ -21,22 +18,20 @@ import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.target.GlideDrawableImageViewTarget; import com.bumptech.glide.request.target.Target; +import icepick.State; + public class GalleryImageFragment extends GalleryBaseFragment { private final String TAG = this.getClass().getSimpleName(); - String m_url; + @State String m_url; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_gallery_entry, container, false); - if (savedInstanceState != null) { - m_url = savedInstanceState.getString("url"); - } - Log.d(TAG, "called for URL: " + m_url); - ImageView imgView = (ImageView) view.findViewById(R.id.flavor_image); + ImageView imgView = view.findViewById(R.id.flavor_image); // TODO: ImageMatrixTouchHandler doesn't like context menus ImageMatrixTouchHandler touchHandler = new ImageMatrixTouchHandler(view.getContext()); @@ -50,7 +45,7 @@ public class GalleryImageFragment extends GalleryBaseFragment { registerForContextMenu(imgView); - final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.flavor_image_progress); + final ProgressBar progressBar = view.findViewById(R.id.flavor_image_progress); final View errorMessage = view.findViewById(R.id.flavor_image_error); final GlideDrawableImageViewTarget glideImage = new GlideDrawableImageViewTarget(imgView); @@ -99,12 +94,4 @@ public class GalleryImageFragment extends GalleryBaseFragment { return true; }*/ - @Override - public void onSaveInstanceState (Bundle out) { - super.onSaveInstanceState(out); - - out.setClassLoader(getClass().getClassLoader()); - out.putString("url", m_url); - } - } 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 5bcd0e62..31d16fbb 100644..100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/GalleryVideoFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/GalleryVideoFragment.java @@ -10,30 +10,22 @@ import android.support.v4.view.ViewCompat; import android.util.Log; import android.view.Display; import android.view.LayoutInflater; -import android.view.MenuInflater; -import android.view.MenuItem; import android.view.Surface; import android.view.TextureView; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.MediaController; -import android.widget.PopupMenu; - -import com.bumptech.glide.Glide; -import com.bumptech.glide.load.engine.DiskCacheStrategy; -import com.bumptech.glide.load.resource.drawable.GlideDrawable; -import com.bumptech.glide.request.RequestListener; -import com.bumptech.glide.request.target.GlideDrawableImageViewTarget; -import com.bumptech.glide.request.target.Target; import java.io.IOException; +import icepick.State; + public class GalleryVideoFragment extends GalleryBaseFragment { private final String TAG = this.getClass().getSimpleName(); - String m_url; - String m_coverUrl; + @State String m_url; + @State String m_coverUrl; MediaPlayer m_mediaPlayer; private boolean m_userVisibleHint = false; @@ -41,14 +33,9 @@ public class GalleryVideoFragment extends GalleryBaseFragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.fragment_gallery_entry, container, false); - if (savedInstanceState != null) { - m_url = savedInstanceState.getString("url"); - m_coverUrl = savedInstanceState.getString("coverUrl"); - } - Log.d(TAG, "called for URL: " + m_url + " Cover: " + m_coverUrl); - ImageView imgView = (ImageView) view.findViewById(R.id.flavor_image); + ImageView imgView = view.findViewById(R.id.flavor_image); ViewCompat.setTransitionName(imgView, "gallery:" + m_url); @@ -119,7 +106,7 @@ public class GalleryVideoFragment extends GalleryBaseFragment { final MediaController m_mediaController = new MediaController(m_activity); - final TextureView textureView = (TextureView) view.findViewById(R.id.flavor_video); + final TextureView textureView = view.findViewById(R.id.flavor_video); registerForContextMenu(textureView); @@ -262,15 +249,6 @@ public class GalleryVideoFragment extends GalleryBaseFragment { m_coverUrl = coverUrl; } - @Override - public void onSaveInstanceState (Bundle out) { - super.onSaveInstanceState(out); - - out.setClassLoader(getClass().getClassLoader()); - out.putString("url", m_url); - out.putString("coverUrl", m_coverUrl); - } - protected void resizeSurface(View surfaceView) { // get the dimensions of the video (only valid when surfaceView is set) float videoWidth = m_mediaPlayer.getVideoWidth(); 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 287d9051..1899350b 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 @@ -22,7 +22,6 @@ import android.preference.PreferenceManager; import android.support.design.widget.Snackbar; import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityOptionsCompat; -import android.support.v4.app.Fragment; import android.support.v4.view.ViewCompat; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.ActionBar; @@ -50,8 +49,6 @@ import android.view.View.OnClickListener; import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.WindowManager; -import android.view.animation.Animation; -import android.view.animation.AnimationUtils; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.CheckBox; import android.widget.ImageView; @@ -73,12 +70,12 @@ import com.google.gson.JsonElement; import com.shamanland.fab.FloatingActionButton; import com.shamanland.fab.ShowHideOnScroll; +import org.fox.ttrss.glide.ProgressTarget; import org.fox.ttrss.types.Article; import org.fox.ttrss.types.ArticleList; import org.fox.ttrss.types.Feed; import org.fox.ttrss.util.HeaderViewRecyclerAdapter; import org.fox.ttrss.util.HeadlinesRequest; -import org.fox.ttrss.glide.ProgressTarget; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -88,9 +85,10 @@ import java.util.HashMap; import java.util.List; import java.util.TimeZone; +import icepick.State; import jp.wasabeef.glide.transformations.CropCircleTransformation; -public class HeadlinesFragment extends Fragment { +public class HeadlinesFragment extends StateSavedFragment { public enum ArticlesSelection { ALL, NONE, UNREAD } @@ -102,25 +100,25 @@ public class HeadlinesFragment extends Fragment { private final String TAG = this.getClass().getSimpleName(); - private Feed m_feed; - private Article m_activeArticle; - private String m_searchQuery = ""; + @State Feed m_feed; + @State Article m_activeArticle; + @State String m_searchQuery = ""; private boolean m_refreshInProgress = false; - private int m_firstId = 0; - private boolean m_lazyLoadDisabled = false; + @State int m_firstId = 0; + @State boolean m_lazyLoadDisabled = false; private int m_amountScrolled; private int m_scrollToToggleBar; private SharedPreferences m_prefs; private HeaderViewRecyclerAdapter m_adapter; - private ArticleList m_articles = new ArticleList(); + @State ArticleList m_articles = new ArticleList(); private ArticleList m_readArticles = new ArticleList(); private HeadlinesEventListener m_listener; private OnlineActivity m_activity; private SwipeRefreshLayout m_swipeLayout; private int m_maxImageSize = 0; - private boolean m_compactLayoutMode = false; + @State boolean m_compactLayoutMode = false; private RecyclerView m_list; private LinearLayoutManager m_layoutManager; @@ -296,20 +294,9 @@ public class HeadlinesFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (savedInstanceState != null) { - m_feed = savedInstanceState.getParcelable("feed"); - - if (! (m_activity instanceof DetailActivity)) { - m_articles = savedInstanceState.getParcelable("articles"); - } else { + if (m_activity instanceof DetailActivity) { m_articles = ((DetailActivity)m_activity).m_articles; } - - m_activeArticle = savedInstanceState.getParcelable("activeArticle"); - //m_selectedArticles = savedInstanceState.getParcelable("selectedArticles"); - m_searchQuery = (String) savedInstanceState.getCharSequence("searchQuery"); - m_compactLayoutMode = savedInstanceState.getBoolean("compactLayoutMode"); - m_firstId = savedInstanceState.getInt("firstId"); - m_lazyLoadDisabled = savedInstanceState.getBoolean("lazyLoadDisabled"); } String headlineMode = m_prefs.getString("headline_mode", "HL_DEFAULT"); @@ -327,7 +314,7 @@ public class HeadlinesFragment extends Fragment { View view = inflater.inflate(R.layout.fragment_headlines, container, false); - m_swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.headlines_swipe_container); + m_swipeLayout = view.findViewById(R.id.headlines_swipe_container); m_swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override @@ -336,7 +323,7 @@ public class HeadlinesFragment extends Fragment { } }); - m_list = (RecyclerView) view.findViewById(R.id.headlines_list); + m_list = view.findViewById(R.id.headlines_list); registerForContextMenu(m_list); m_layoutManager = new LinearLayoutManager(m_activity.getApplicationContext()); @@ -350,7 +337,7 @@ public class HeadlinesFragment extends Fragment { m_list.setAdapter(m_adapter); - FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.headlines_fab); + FloatingActionButton fab = view.findViewById(R.id.headlines_fab); if (m_prefs.getBoolean("headlines_swipe_to_dismiss", true) && !m_prefs.getBoolean("headlines_mark_read_scroll", false) ) { @@ -423,7 +410,7 @@ public class HeadlinesFragment extends Fragment { swipeHelper.attachToRecyclerView(m_list); - }; + } if (! (getActivity() instanceof DetailActivity)) { @@ -750,21 +737,6 @@ public class HeadlinesFragment extends Fragment { } } - @Override - public void onSaveInstanceState (Bundle out) { - super.onSaveInstanceState(out); - - out.setClassLoader(getClass().getClassLoader()); - out.putParcelable("feed", m_feed); - out.putParcelable("articles", m_articles); - out.putParcelable("activeArticle", m_activeArticle); - //out.putParcelable("selectedArticles", m_selectedArticles); - out.putCharSequence("searchQuery", m_searchQuery); - out.putBoolean("compactLayoutMode", m_compactLayoutMode); - out.putInt("firstId", m_firstId); - out.putBoolean("lazyLoadDisabled", m_lazyLoadDisabled); - } - static class ArticleViewHolder extends RecyclerView.ViewHolder { public View view; public Article article; @@ -810,26 +782,26 @@ public class HeadlinesFragment extends Fragment { } }); - titleView = (TextView)v.findViewById(R.id.title); - - feedTitleView = (TextView)v.findViewById(R.id.feed_title); - markedView = (ImageView)v.findViewById(R.id.marked); - publishedView = (ImageView)v.findViewById(R.id.published); - excerptView = (TextView)v.findViewById(R.id.excerpt); - flavorImageView = (ImageView) v.findViewById(R.id.flavor_image); - flavorVideoKindView = (ImageView) v.findViewById(R.id.flavor_video_kind); - authorView = (TextView)v.findViewById(R.id.author); - dateView = (TextView) v.findViewById(R.id.date); - selectionBoxView = (CheckBox) v.findViewById(R.id.selected); - menuButtonView = (ImageView) v.findViewById(R.id.article_menu_button); - flavorImageHolder = (ViewGroup) v.findViewById(R.id.flavorImageHolder); - flavorImageLoadingBar = (ProgressBar) v.findViewById(R.id.flavorImageLoadingBar); + titleView = v.findViewById(R.id.title); + + feedTitleView = v.findViewById(R.id.feed_title); + markedView = v.findViewById(R.id.marked); + publishedView = v.findViewById(R.id.published); + excerptView = v.findViewById(R.id.excerpt); + flavorImageView = v.findViewById(R.id.flavor_image); + flavorVideoKindView = v.findViewById(R.id.flavor_video_kind); + authorView = v.findViewById(R.id.author); + dateView = v.findViewById(R.id.date); + selectionBoxView = v.findViewById(R.id.selected); + menuButtonView = v.findViewById(R.id.article_menu_button); + flavorImageHolder = v.findViewById(R.id.flavorImageHolder); + flavorImageLoadingBar = v.findViewById(R.id.flavorImageLoadingBar); headlineFooter = v.findViewById(R.id.headline_footer); - textImage = (ImageView) v.findViewById(R.id.text_image); - textChecked = (ImageView) v.findViewById(R.id.text_checked); + textImage = v.findViewById(R.id.text_image); + textChecked = v.findViewById(R.id.text_checked); headlineHeader = v.findViewById(R.id.headline_header); flavorImageOverflow = v.findViewById(R.id.gallery_overflow); - flavorVideoView = (TextureView) v.findViewById(R.id.flavor_video); + flavorVideoView = v.findViewById(R.id.flavor_video); if (flavorImageView != null && flavorImageLoadingBar != null) { flavorProgressTarget = new FlavorProgressTarget<>(new GlideDrawableImageViewTarget(flavorImageView), flavorImageLoadingBar); @@ -1550,11 +1522,7 @@ public class HeadlinesFragment extends Fragment { @Override public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { - if (resource.getIntrinsicWidth() < THUMB_IMG_MIN_SIZE || resource.getIntrinsicHeight() < THUMB_IMG_MIN_SIZE) { - return true; - } else { - return false; - } + return resource.getIntrinsicWidth() < THUMB_IMG_MIN_SIZE || resource.getIntrinsicHeight() < THUMB_IMG_MIN_SIZE; } }) .into(holder.textImage); |