move offline/online prompts to the sidebar

This commit is contained in:
Andrew Dolgov 2015-06-04 20:57:32 +03:00
parent c9398d0fe1
commit 8c6d767190
19 changed files with 90 additions and 47 deletions

View File

@ -20,7 +20,8 @@ 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 rootView, boolean isOffline) {
if (true /*m_activity.findViewById(R.id.headlines_drawer) != null*/) { if (true /*m_activity.findViewById(R.id.headlines_drawer) != null*/) {
try { try {
@ -87,6 +88,22 @@ public abstract class BaseFeedlistFragment extends Fragment {
} }
}); });
if (rootView) {
// offline
footer = inflater.inflate(R.layout.feeds_row, list, false);
list.addFooterView(footer);
text = (TextView) footer.findViewById(R.id.title);
text.setText(isOffline ? R.string.go_online : R.string.go_offline);
icon = (ImageView) 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);
counter.setText(R.string.blank);
}
// settings // settings
footer = inflater.inflate(R.layout.feeds_row, list, false); footer = inflater.inflate(R.layout.feeds_row, list, false);
list.addFooterView(footer); list.addFooterView(footer);

View File

@ -217,7 +217,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); initDrawerHeader(inflater, view, m_list, m_activity, m_prefs, true, false);
m_list.setAdapter(m_adapter); m_list.setAdapter(m_adapter);
m_list.setOnItemClickListener(this); m_list.setOnItemClickListener(this);
@ -511,14 +511,6 @@ public class FeedCategoriesFragment extends BaseFeedlistFragment implements OnIt
if (list != null) { if (list != null) {
if (position == list.getCount() - 1) {
Intent intent = new Intent(m_activity,
PreferencesActivity.class);
startActivityForResult(intent, 0);
return;
}
FeedCategory cat = (FeedCategory)list.getItemAtPosition(position); FeedCategory cat = (FeedCategory)list.getItemAtPosition(position);
if (cat != null) { if (cat != null) {
@ -531,6 +523,19 @@ 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

@ -283,7 +283,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); initDrawerHeader(inflater, view, m_list, m_activity, m_prefs, !m_enableParentBtn, false);
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);
@ -358,14 +358,6 @@ public class FeedsFragment extends BaseFeedlistFragment implements OnItemClickLi
ListView list = (ListView)av; ListView list = (ListView)av;
if (list != null) { if (list != null) {
if (position == list.getCount() - 1) {
Intent intent = new Intent(m_activity,
PreferencesActivity.class);
startActivityForResult(intent, 0);
return;
}
Feed feed = (Feed)list.getItemAtPosition(position); Feed feed = (Feed)list.getItemAtPosition(position);
if (feed != null) { if (feed != null) {
@ -378,6 +370,19 @@ 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 (position == list.getCount() - 2) {
m_activity.switchOffline();
return;
}
} }
m_selectedFeed = feed; m_selectedFeed = feed;

View File

@ -200,7 +200,7 @@ public class OnlineActivity extends CommonActivity {
return GlobalState.getInstance().m_canUseProgress; return GlobalState.getInstance().m_canUseProgress;
} }
private void switchOffline() { protected void switchOffline() {
if (m_offlineModeStatus == 2) { if (m_offlineModeStatus == 2) {
AlertDialog.Builder builder = new AlertDialog.Builder( AlertDialog.Builder builder = new AlertDialog.Builder(
@ -729,9 +729,9 @@ public class OnlineActivity extends CommonActivity {
case R.id.login: case R.id.login:
login(); login();
return true; return true;
case R.id.go_offline: /*case R.id.go_offline:
switchOffline(); switchOffline();
return true; return true;*/
case R.id.article_set_note: case R.id.article_set_note:
if (ap != null && ap.getSelectedArticle() != null) { if (ap != null && ap.getSelectedArticle() != null) {
editArticleNote(ap.getSelectedArticle()); editArticleNote(ap.getSelectedArticle());

View File

@ -271,9 +271,9 @@ public class OfflineActivity extends CommonActivity {
} }
} }
return true; */ return true; */
case R.id.go_online: /*case R.id.go_online:
switchOnline(); switchOnline();
return true; return true;*/
case R.id.search: case R.id.search:
if (ohf != null) { if (ohf != null) {
Dialog dialog = new Dialog(this); Dialog dialog = new Dialog(this);
@ -602,7 +602,7 @@ public class OfflineActivity extends CommonActivity {
} }
} }
private void switchOnline() { protected 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

@ -148,7 +148,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); initDrawerHeader(inflater, view, m_list, m_activity, m_prefs, true, true);
m_list.setAdapter(m_adapter); m_list.setAdapter(m_adapter);
m_list.setOnItemClickListener(this); m_list.setOnItemClickListener(this);
@ -188,14 +188,6 @@ public class OfflineFeedCategoriesFragment extends BaseFeedlistFragment implemen
ListView list = (ListView)getActivity().findViewById(R.id.feeds); ListView list = (ListView)getActivity().findViewById(R.id.feeds);
if (list != null) { if (list != null) {
if (position == list.getCount() - 1) {
Intent intent = new Intent(m_activity,
PreferencesActivity.class);
startActivityForResult(intent, 0);
return;
}
Cursor cursor = (Cursor) list.getItemAtPosition(position); Cursor cursor = (Cursor) list.getItemAtPosition(position);
if (cursor != null) { if (cursor != null) {
@ -207,6 +199,19 @@ 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

@ -150,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); initDrawerHeader(inflater, view, m_list, m_activity, m_prefs, !m_enableParentBtn, true);
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);
@ -215,14 +215,6 @@ public class OfflineFeedsFragment extends BaseFeedlistFragment implements OnItem
ListView list = (ListView)getActivity().findViewById(R.id.feeds); ListView list = (ListView)getActivity().findViewById(R.id.feeds);
if (list != null) { if (list != null) {
if (position == list.getCount() - 1) {
Intent intent = new Intent(m_activity,
PreferencesActivity.class);
startActivityForResult(intent, 0);
return;
}
Cursor cursor = (Cursor) list.getItemAtPosition(position); Cursor cursor = (Cursor) list.getItemAtPosition(position);
if (cursor != null) { if (cursor != null) {
@ -234,6 +226,19 @@ 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 (position == list.getCount() - 2) {
m_activity.switchOnline();
return;
}
} }
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 976 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 971 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -14,12 +14,12 @@
android:icon="@drawable/ic_filter_remove" android:icon="@drawable/ic_filter_remove"
app:showAsAction="" app:showAsAction=""
android:title="@string/menu_all_feeds"/> --> android:title="@string/menu_all_feeds"/> -->
<item <!-- <item
android:id="@+id/go_offline" android:id="@+id/go_offline"
android:icon="@drawable/ic_cloud_download" android:icon="@drawable/ic_cloud_download"
android:orderInCategory="800" android:orderInCategory="800"
app:showAsAction="" app:showAsAction=""
android:title="@string/go_offline"/> <!-- iRroom --> android:title="@string/go_offline"/> --><!-- iRroom -->
<!-- <item <!-- <item
android:id="@+id/update_feeds" android:id="@+id/update_feeds"
android:icon="@drawable/ic_refresh" android:icon="@drawable/ic_refresh"

View File

@ -1,12 +1,12 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" > <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" >
<group android:id="@+id/menu_group_feeds" > <group android:id="@+id/menu_group_feeds" >
<item <!-- <item
android:id="@+id/go_online" android:id="@+id/go_online"
android:icon="@drawable/ic_cloud_upload" android:icon="@drawable/ic_cloud_upload"
app:showAsAction="" app:showAsAction=""
android:title="@string/go_online" android:title="@string/go_online"
android:visible="false"/> <!-- ifRoom|withText --> android:visible="false"/> --> <!-- ifRoom|withText -->
<!-- <item <!-- <item
android:id="@+id/show_feeds" android:id="@+id/show_feeds"
android:icon="@drawable/ic_filter_remove" android:icon="@drawable/ic_filter_remove"

View File

@ -38,6 +38,8 @@
<attr name="ic_keyboard_backspace" format="reference" /> <attr name="ic_keyboard_backspace" format="reference" />
<attr name="ic_settings" format="reference" /> <attr name="ic_settings" format="reference" />
<attr name="ic_filter_variant" format="reference" /> <attr name="ic_filter_variant" format="reference" />
<attr name="ic_cloud_download" format="reference" />
<attr name="ic_cloud_upload" format="reference" />
<declare-styleable name="ScrimInsetsView"> <declare-styleable name="ScrimInsetsView">
<attr format="reference|color" name="insetForeground"> <attr format="reference|color" name="insetForeground">
</attr></declare-styleable> </attr></declare-styleable>

View File

@ -51,6 +51,8 @@
<item name="ic_keyboard_backspace">@drawable/ic_keyboard_backspace_dark</item> <item name="ic_keyboard_backspace">@drawable/ic_keyboard_backspace_dark</item>
<item name="ic_settings">@drawable/ic_settings_dark</item> <item name="ic_settings">@drawable/ic_settings_dark</item>
<item name="ic_filter_variant">@drawable/ic_filter_variant_dark</item> <item name="ic_filter_variant">@drawable/ic_filter_variant_dark</item>
<item name="ic_cloud_download">@drawable/ic_cloud_download_dark</item>
<item name="ic_cloud_upload">@drawable/ic_cloud_upload_dark</item>
</style> </style>
<style name="DarkTheme.Base" parent="Theme.AppCompat.NoActionBar"> <style name="DarkTheme.Base" parent="Theme.AppCompat.NoActionBar">
@ -103,6 +105,8 @@
<item name="ic_keyboard_backspace">@drawable/ic_keyboard_backspace</item> <item name="ic_keyboard_backspace">@drawable/ic_keyboard_backspace</item>
<item name="ic_settings">@drawable/ic_settings</item> <item name="ic_settings">@drawable/ic_settings</item>
<item name="ic_filter_variant">@drawable/ic_filter_variant</item> <item name="ic_filter_variant">@drawable/ic_filter_variant</item>
<item name="ic_cloud_download">@drawable/ic_cloud_download</item>
<item name="ic_cloud_upload">@drawable/ic_cloud_upload</item>
</style> </style>
<style name="DarkDialogTheme" parent="android:Theme"></style> <style name="DarkDialogTheme" parent="android:Theme"></style>