From 6b2025bb58240e8fd8f913c9769fd7178b771129 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 30 Nov 2011 09:30:19 +0300 Subject: [PATCH] use compact portrait vertical headlines layout for small screen devices --- res/layout-port/headlines_row_small.xml | 95 +++++++++++++++++++ .../headlines_row_small_selected.xml | 95 +++++++++++++++++++ .../headlines_row_small_unread.xml | 95 +++++++++++++++++++ src/org/fox/ttrss/FeedsFragment.java | 7 +- src/org/fox/ttrss/HeadlinesFragment.java | 13 ++- src/org/fox/ttrss/MainActivity.java | 4 + 6 files changed, 305 insertions(+), 4 deletions(-) create mode 100644 res/layout-port/headlines_row_small.xml create mode 100644 res/layout-port/headlines_row_small_selected.xml create mode 100644 res/layout-port/headlines_row_small_unread.xml diff --git a/res/layout-port/headlines_row_small.xml b/res/layout-port/headlines_row_small.xml new file mode 100644 index 00000000..772184dd --- /dev/null +++ b/res/layout-port/headlines_row_small.xml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout-port/headlines_row_small_selected.xml b/res/layout-port/headlines_row_small_selected.xml new file mode 100644 index 00000000..59658b01 --- /dev/null +++ b/res/layout-port/headlines_row_small_selected.xml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout-port/headlines_row_small_unread.xml b/res/layout-port/headlines_row_small_unread.xml new file mode 100644 index 00000000..196ee8e2 --- /dev/null +++ b/res/layout-port/headlines_row_small_unread.xml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/org/fox/ttrss/FeedsFragment.java b/src/org/fox/ttrss/FeedsFragment.java index f3ace4fa..c82010d9 100644 --- a/src/org/fox/ttrss/FeedsFragment.java +++ b/src/org/fox/ttrss/FeedsFragment.java @@ -66,6 +66,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh private int m_selectedFeedId; private static final String ICON_PATH = "/org.fox.ttrss/icons/"; private boolean m_enableFeedIcons; + private boolean m_feedIconsChecked = false; public interface OnFeedSelectedListener { public void onFeedSelected(Feed feed); @@ -118,6 +119,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh if (savedInstanceState != null) { m_selectedFeedId = savedInstanceState.getInt("selectedFeedId"); m_feeds = savedInstanceState.getParcelable("feeds"); + m_feedIconsChecked = savedInstanceState.getBoolean("feedIconsChecked"); } View view = inflater.inflate(R.layout.feeds_fragment, container, false); @@ -165,6 +167,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh out.putInt("selectedFeedId", m_selectedFeedId); out.putParcelable("feeds", m_feeds); + out.putBoolean("feedIconsChecked", m_feedIconsChecked); } @Override @@ -255,6 +258,8 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh GetIconsTask git = new GetIconsTask(baseUrl); git.execute(m_feeds); + + m_feedIconsChecked = true; } } catch (Exception e) { Log.d(TAG, "Error receiving icons configuration"); @@ -307,7 +312,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh else setLoadingStatus(R.string.blank, false); - if (m_enableFeedIcons) getFeedIcons(); + if (m_enableFeedIcons && !m_feedIconsChecked) getFeedIcons(); return; } diff --git a/src/org/fox/ttrss/HeadlinesFragment.java b/src/org/fox/ttrss/HeadlinesFragment.java index 59c0e5f1..79ce8dd6 100644 --- a/src/org/fox/ttrss/HeadlinesFragment.java +++ b/src/org/fox/ttrss/HeadlinesFragment.java @@ -50,6 +50,8 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { private ArticleList m_selectedArticles = new ArticleList(); private ArticleOps m_articleOps; + private boolean m_smallScreenMode = false; + private boolean m_portraitMode = false; public ArticleList getSelectedArticles() { return m_selectedArticles; @@ -73,12 +75,15 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + + m_portraitMode = getActivity().getWindowManager().getDefaultDisplay().getOrientation() % 2 == 0; if (savedInstanceState != null) { m_feed = savedInstanceState.getParcelable("feed"); m_articles = savedInstanceState.getParcelable("articles"); m_activeArticleId = savedInstanceState.getInt("activeArticleId"); m_selectedArticles = savedInstanceState.getParcelable("selectedArticles"); + m_smallScreenMode = savedInstanceState.getBoolean("smallScreenMode"); } View view = inflater.inflate(R.layout.headlines_fragment, container, false); @@ -103,6 +108,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { public void onAttach(Activity activity) { super.onAttach(activity); m_feed = ((MainActivity)activity).getActiveFeed(); + m_smallScreenMode = ((MainActivity)activity).getSmallScreenMode(); m_articleOps = (ArticleOps) activity; } @@ -168,6 +174,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { out.putParcelable("articles", m_articles); out.putInt("activeArticleId", m_activeArticleId); out.putParcelable("selectedArticles", m_selectedArticles); + out.putBoolean("smallScreenMode", m_smallScreenMode); } public void setLoadingStatus(int status, boolean showProgress) { @@ -286,14 +293,14 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { final Article article = items.get(position); if (v == null) { - int layoutId = R.layout.headlines_row; + int layoutId = (m_smallScreenMode && m_portraitMode) ? R.layout.headlines_row_small : R.layout.headlines_row; switch (getItemViewType(position)) { case VIEW_UNREAD: - layoutId = R.layout.headlines_row_unread; + layoutId = (m_smallScreenMode && m_portraitMode) ? R.layout.headlines_row_small_unread : R.layout.headlines_row_unread; break; case VIEW_SELECTED: - layoutId = R.layout.headlines_row_selected; + layoutId = (m_smallScreenMode && m_portraitMode) ? R.layout.headlines_row_small_selected : R.layout.headlines_row_selected; break; } diff --git a/src/org/fox/ttrss/MainActivity.java b/src/org/fox/ttrss/MainActivity.java index 50313072..e772611d 100644 --- a/src/org/fox/ttrss/MainActivity.java +++ b/src/org/fox/ttrss/MainActivity.java @@ -1235,4 +1235,8 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe Log.d(TAG, "onCatSelected"); viewCategory(cat, m_prefs.getBoolean("browse_cats_like_feeds", false)); } + + public boolean getSmallScreenMode() { + return m_smallScreenMode; + } } \ No newline at end of file