diff options
author | Andrew Dolgov <[email protected]> | 2015-06-05 12:15:57 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2015-06-05 12:15:57 +0300 |
commit | 0b8abdf07a56b77f7642e86f9588ff978c9676de (patch) | |
tree | 35f431f69cfc0dd3f9528550d51eec8fb9208dfd /org.fox.ttrss/src/main/java | |
parent | 8e5a8fb8eb3897ca494e232a224f51c0a74fa9b4 (diff) |
move sidebar footer item handling to onclick listeners
Diffstat (limited to 'org.fox.ttrss/src/main/java')
6 files changed, 38 insertions, 66 deletions
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 731b2432..4bab1f19 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 @@ -14,14 +14,17 @@ import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; +import org.fox.ttrss.offline.OfflineActivity; + import java.net.MalformedURLException; import java.net.URL; public abstract class BaseFeedlistFragment extends Fragment { abstract public void refresh(boolean background); - public void initDrawerHeader(LayoutInflater inflater, View view, ListView list, final CommonActivity activity, final SharedPreferences prefs, - boolean rootView, boolean isOffline) { + public void initDrawerHeader(LayoutInflater inflater, View view, ListView list, final CommonActivity activity, final SharedPreferences prefs, boolean isRoot) { + + boolean isOffline = activity instanceof OfflineActivity; if (true /*m_activity.findViewById(R.id.headlines_drawer) != null*/) { try { @@ -57,6 +60,12 @@ public abstract class BaseFeedlistFragment extends Fragment { // divider View footer = inflater.inflate(R.layout.headlines_divider, list, false); + footer.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + // + } + }); list.addFooterView(footer); // unread only checkbox @@ -88,9 +97,21 @@ public abstract class BaseFeedlistFragment extends Fragment { } }); - if (rootView) { + if (isRoot) { // offline footer = inflater.inflate(R.layout.feeds_row, list, false); + footer.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (activity instanceof OnlineActivity) { + ((OnlineActivity)activity).switchOffline(); + + } else if (activity instanceof OfflineActivity) { + ((OfflineActivity)activity).switchOnline(); + } + } + }); + list.addFooterView(footer); text = (TextView) footer.findViewById(R.id.title); text.setText(isOffline ? R.string.go_online : R.string.go_offline); @@ -106,6 +127,15 @@ public abstract class BaseFeedlistFragment extends Fragment { // settings footer = inflater.inflate(R.layout.feeds_row, list, false); + footer.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(activity, + PreferencesActivity.class); + startActivityForResult(intent, 0); + } + }); + list.addFooterView(footer); text = (TextView) footer.findViewById(R.id.title); text.setText(R.string.preferences); 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 89bffbd7..ef6dce88 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 @@ -6,7 +6,6 @@ import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; -import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.os.Bundle; @@ -219,7 +218,7 @@ 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); - initDrawerHeader(inflater, view, m_list, m_activity, m_prefs, true, false); + initDrawerHeader(inflater, view, m_list, m_activity, m_prefs, true); m_list.setAdapter(m_adapter); m_list.setOnItemClickListener(this); @@ -535,19 +534,6 @@ public class FeedCategoriesFragment extends BaseFeedlistFragment implements OnIt m_selectedCat = cat; m_adapter.notifyDataSetChanged(); - } else { - if (position == list.getCount() - 1) { - Intent intent = new Intent(m_activity, - PreferencesActivity.class); - startActivityForResult(intent, 0); - - return; - } - - if (position == list.getCount() - 2) { - m_activity.switchOffline(); - return; - } } } } 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 37c89573..5a17f9f5 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 @@ -6,7 +6,6 @@ import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; -import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.graphics.Typeface; @@ -285,7 +284,7 @@ public class FeedsFragment extends BaseFeedlistFragment implements OnItemClickLi m_list = (ListView)view.findViewById(R.id.feeds); - initDrawerHeader(inflater, view, m_list, m_activity, m_prefs, !m_enableParentBtn, false); + initDrawerHeader(inflater, view, m_list, m_activity, m_prefs, !m_enableParentBtn); if (m_enableParentBtn) { View layout = inflater.inflate(R.layout.feeds_goback, m_list, false); @@ -372,19 +371,6 @@ public class FeedsFragment extends BaseFeedlistFragment implements OnItemClickLi } else { m_activity.onFeedSelected(feed); } - } else { - if (position == list.getCount() - 1) { - Intent intent = new Intent(m_activity, - PreferencesActivity.class); - startActivityForResult(intent, 0); - - return; - } - - if (!m_enableParentBtn && position == list.getCount() - 2) { - m_activity.switchOffline(); - return; - } } m_selectedFeed = feed; diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineActivity.java index 5041fd3a..2f59e2e9 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineActivity.java @@ -602,7 +602,7 @@ public class OfflineActivity extends CommonActivity { } } - protected void switchOnline() { + public void switchOnline() { SharedPreferences localPrefs = getSharedPreferences("localprefs", Context.MODE_PRIVATE); SharedPreferences.Editor editor = localPrefs.edit(); editor.putBoolean("offline_mode_active", false); diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineFeedCategoriesFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineFeedCategoriesFragment.java index a6087411..79d56775 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineFeedCategoriesFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineFeedCategoriesFragment.java @@ -2,7 +2,6 @@ package org.fox.ttrss.offline; import android.app.Activity; import android.content.Context; -import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.database.Cursor; @@ -29,7 +28,6 @@ import android.widget.ListView; import android.widget.TextView; import org.fox.ttrss.BaseFeedlistFragment; -import org.fox.ttrss.PreferencesActivity; import org.fox.ttrss.R; public class OfflineFeedCategoriesFragment extends BaseFeedlistFragment implements OnItemClickListener, OnSharedPreferenceChangeListener { @@ -152,7 +150,7 @@ public class OfflineFeedCategoriesFragment extends BaseFeedlistFragment implemen m_adapter = new FeedCategoryListAdapter(getActivity(), R.layout.feeds_row, m_cursor, new String[] { "title", "unread" }, new int[] { R.id.title, R.id.unread_counter }, 0); - initDrawerHeader(inflater, view, m_list, m_activity, m_prefs, true, true); + initDrawerHeader(inflater, view, m_list, m_activity, m_prefs, true); m_list.setAdapter(m_adapter); m_list.setOnItemClickListener(this); @@ -203,19 +201,6 @@ public class OfflineFeedCategoriesFragment extends BaseFeedlistFragment implemen m_selectedCatId = feedId; m_adapter.notifyDataSetChanged(); - } else { - if (position == list.getCount() - 1) { - Intent intent = new Intent(m_activity, - PreferencesActivity.class); - startActivityForResult(intent, 0); - - return; - } - - if (position == list.getCount() - 2) { - m_activity.switchOnline(); - return; - } } } } diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineFeedsFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineFeedsFragment.java index 90c7b7f1..a64076c8 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineFeedsFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineFeedsFragment.java @@ -2,7 +2,6 @@ package org.fox.ttrss.offline; import android.app.Activity; import android.content.Context; -import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.database.Cursor; @@ -26,7 +25,6 @@ import android.widget.ListView; import android.widget.TextView; import org.fox.ttrss.BaseFeedlistFragment; -import org.fox.ttrss.PreferencesActivity; import org.fox.ttrss.R; public class OfflineFeedsFragment extends BaseFeedlistFragment implements OnItemClickListener, OnSharedPreferenceChangeListener { @@ -152,7 +150,7 @@ public class OfflineFeedsFragment extends BaseFeedlistFragment implements OnItem m_list = (ListView)view.findViewById(R.id.feeds); - initDrawerHeader(inflater, view, m_list, m_activity, m_prefs, !m_enableParentBtn, true); + initDrawerHeader(inflater, view, m_list, m_activity, m_prefs, !m_enableParentBtn); if (m_enableParentBtn) { View layout = inflater.inflate(R.layout.feeds_goback, container, false); @@ -228,19 +226,6 @@ public class OfflineFeedsFragment extends BaseFeedlistFragment implements OnItem m_selectedFeedId = feedId; m_adapter.notifyDataSetChanged(); - } else { - if (position == list.getCount() - 1) { - Intent intent = new Intent(m_activity, - PreferencesActivity.class); - startActivityForResult(intent, 0); - - return; - } - - if (!m_enableParentBtn && position == list.getCount() - 2) { - m_activity.switchOnline(); - return; - } } } } |