move sidebar footer item handling to onclick listeners

This commit is contained in:
Andrew Dolgov 2015-06-05 12:15:57 +03:00
parent 8e5a8fb8eb
commit 0b8abdf07a
6 changed files with 38 additions and 66 deletions

View File

@ -14,14 +14,17 @@ import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import org.fox.ttrss.offline.OfflineActivity;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
public abstract class BaseFeedlistFragment extends Fragment { public abstract class BaseFeedlistFragment extends Fragment {
abstract public void refresh(boolean background); abstract public void refresh(boolean background);
public void initDrawerHeader(LayoutInflater inflater, View view, ListView list, final CommonActivity activity, final SharedPreferences prefs, public void initDrawerHeader(LayoutInflater inflater, View view, ListView list, final CommonActivity activity, final SharedPreferences prefs, boolean isRoot) {
boolean rootView, boolean isOffline) {
boolean isOffline = activity instanceof OfflineActivity;
if (true /*m_activity.findViewById(R.id.headlines_drawer) != null*/) { if (true /*m_activity.findViewById(R.id.headlines_drawer) != null*/) {
try { try {
@ -57,6 +60,12 @@ public abstract class BaseFeedlistFragment extends Fragment {
// divider // divider
View footer = inflater.inflate(R.layout.headlines_divider, list, false); View footer = inflater.inflate(R.layout.headlines_divider, list, false);
footer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//
}
});
list.addFooterView(footer); list.addFooterView(footer);
// unread only checkbox // unread only checkbox
@ -88,9 +97,21 @@ public abstract class BaseFeedlistFragment extends Fragment {
} }
}); });
if (rootView) { if (isRoot) {
// offline // offline
footer = inflater.inflate(R.layout.feeds_row, list, false); 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); list.addFooterView(footer);
text = (TextView) footer.findViewById(R.id.title); text = (TextView) footer.findViewById(R.id.title);
text.setText(isOffline ? R.string.go_online : R.string.go_offline); text.setText(isOffline ? R.string.go_online : R.string.go_offline);
@ -106,6 +127,15 @@ public abstract class BaseFeedlistFragment extends Fragment {
// settings // settings
footer = inflater.inflate(R.layout.feeds_row, list, false); 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); list.addFooterView(footer);
text = (TextView) footer.findViewById(R.id.title); text = (TextView) footer.findViewById(R.id.title);
text.setText(R.string.preferences); text.setText(R.string.preferences);

View File

@ -6,7 +6,6 @@ import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle; import android.os.Bundle;
@ -219,7 +218,7 @@ public class FeedCategoriesFragment extends BaseFeedlistFragment implements OnIt
m_list = (ListView)view.findViewById(R.id.feeds); m_list = (ListView)view.findViewById(R.id.feeds);
m_adapter = new FeedCategoryListAdapter(getActivity(), R.layout.feeds_row, (ArrayList<FeedCategory>)m_cats); 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.setAdapter(m_adapter);
m_list.setOnItemClickListener(this); m_list.setOnItemClickListener(this);
@ -535,19 +534,6 @@ public class FeedCategoriesFragment extends BaseFeedlistFragment implements OnIt
m_selectedCat = cat; m_selectedCat = cat;
m_adapter.notifyDataSetChanged(); 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;
}
} }
} }
} }

View File

@ -6,7 +6,6 @@ import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.graphics.Typeface; import android.graphics.Typeface;
@ -285,7 +284,7 @@ public class FeedsFragment extends BaseFeedlistFragment implements OnItemClickLi
m_list = (ListView)view.findViewById(R.id.feeds); 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) { if (m_enableParentBtn) {
View layout = inflater.inflate(R.layout.feeds_goback, m_list, false); View layout = inflater.inflate(R.layout.feeds_goback, m_list, false);
@ -372,19 +371,6 @@ public class FeedsFragment extends BaseFeedlistFragment implements OnItemClickLi
} else { } else {
m_activity.onFeedSelected(feed); 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; m_selectedFeed = feed;

View File

@ -602,7 +602,7 @@ public class OfflineActivity extends CommonActivity {
} }
} }
protected void switchOnline() { public void switchOnline() {
SharedPreferences localPrefs = getSharedPreferences("localprefs", Context.MODE_PRIVATE); SharedPreferences localPrefs = getSharedPreferences("localprefs", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = localPrefs.edit(); SharedPreferences.Editor editor = localPrefs.edit();
editor.putBoolean("offline_mode_active", false); editor.putBoolean("offline_mode_active", false);

View File

@ -2,7 +2,6 @@ package org.fox.ttrss.offline;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.database.Cursor; import android.database.Cursor;
@ -29,7 +28,6 @@ import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import org.fox.ttrss.BaseFeedlistFragment; import org.fox.ttrss.BaseFeedlistFragment;
import org.fox.ttrss.PreferencesActivity;
import org.fox.ttrss.R; import org.fox.ttrss.R;
public class OfflineFeedCategoriesFragment extends BaseFeedlistFragment implements OnItemClickListener, OnSharedPreferenceChangeListener { 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, 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); 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.setAdapter(m_adapter);
m_list.setOnItemClickListener(this); m_list.setOnItemClickListener(this);
@ -203,19 +201,6 @@ public class OfflineFeedCategoriesFragment extends BaseFeedlistFragment implemen
m_selectedCatId = feedId; m_selectedCatId = feedId;
m_adapter.notifyDataSetChanged(); 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;
}
} }
} }
} }

View File

@ -2,7 +2,6 @@ package org.fox.ttrss.offline;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.database.Cursor; import android.database.Cursor;
@ -26,7 +25,6 @@ import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import org.fox.ttrss.BaseFeedlistFragment; import org.fox.ttrss.BaseFeedlistFragment;
import org.fox.ttrss.PreferencesActivity;
import org.fox.ttrss.R; import org.fox.ttrss.R;
public class OfflineFeedsFragment extends BaseFeedlistFragment implements OnItemClickListener, OnSharedPreferenceChangeListener { 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); 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) { if (m_enableParentBtn) {
View layout = inflater.inflate(R.layout.feeds_goback, container, false); 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_selectedFeedId = feedId;
m_adapter.notifyDataSetChanged(); 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;
}
} }
} }
} }