From 436b307a230f6cc859dd8d9d69fc86b15d10c409 Mon Sep 17 00:00:00 2001 From: Twig N Date: Sun, 5 Jan 2020 21:15:25 +1100 Subject: [PATCH 01/17] - added tabs for local rss feeds - changed the way rss feeds refreshes a bit (RssfeedsFragment calls refresh during onResume() rather than activity) - RssfeedsFragment and RssitemsFragment now extends android.support.v4.app.Fragment - (WIP) it's gonna crash because tab2 currently returns null --- app/build.gradle | 2 + .../core/gui/rss/RssfeedsActivity.java | 66 +++++++++++++++++-- .../core/gui/rss/RssfeedsFragment.java | 8 ++- .../core/gui/rss/RssitemsFragment.java | 2 +- app/src/main/res/layout/activity_rssfeeds.xml | 22 +++++-- app/src/main/res/values/strings.xml | 4 +- 6 files changed, 90 insertions(+), 14 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7f564591..ad4305d9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -73,6 +73,8 @@ dependencies { implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support:recyclerview-v7:28.0.0' implementation 'com.android.support:support-annotations:28.0.0' + implementation 'com.android.support:design:28.0.0' + implementation 'com.android.support:support-v4:28.0.0' implementation 'com.getbase:floatingactionbutton:1.10.1' implementation 'com.nispok:snackbar:2.11.0' implementation 'com.github.aegnor:rencode-java:cb628e824e' diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java index 88b180c7..8925d937 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java @@ -21,6 +21,12 @@ import android.content.Intent; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.design.widget.TabLayout; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.text.TextUtils; @@ -61,12 +67,56 @@ public class RssfeedsActivity extends AppCompatActivity { protected List loaders; // Contained feeds and items fragments - @FragmentById(R.id.rssfeeds_fragment) protected RssfeedsFragment fragmentFeeds; @FragmentById(R.id.rssitems_fragment) protected RssitemsFragment fragmentItems; @ViewById protected Toolbar rssfeedsToolbar; + @ViewById(R.id.rssfeeds_tabs) + protected TabLayout tabLayout; + @ViewById(R.id.rssfeeds_pager) + protected ViewPager viewPager; + + protected static final int RSS_FEEDS_LOCAL = 0; + protected static final int RSS_FEEDS_REMOTE = 1; + + class PagerAdapter extends FragmentPagerAdapter { + public PagerAdapter(FragmentManager fm) { + super(fm); + } + + @Override + public Fragment getItem(int position) { + Fragment fragment = null; + + if (position == RSS_FEEDS_LOCAL) { + fragment = fragmentFeeds; + } + else if (position == RSS_FEEDS_REMOTE) { + fragment = null; + } + + return fragment; + } + + @Override + public int getCount() { + return 2; + } + + @Nullable + @Override + public CharSequence getPageTitle(int position) { + switch (position) { + case RSS_FEEDS_LOCAL: + return getString(R.string.navigation_rss_tabs_local); + case RSS_FEEDS_REMOTE: + return getString(R.string.navigation_rss_tabs_remote); + } + + return super.getPageTitle(position); + } + } @Override public void onCreate(Bundle savedInstanceState) { @@ -82,6 +132,14 @@ public class RssfeedsActivity extends AppCompatActivity { setSupportActionBar(rssfeedsToolbar); getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(getString(R.string.rss_feeds))); getSupportActionBar().setDisplayHomeAsUpEnabled(true); + + fragmentFeeds = RssfeedsFragment_.builder().build(); + fragmentItems = RssitemsFragment_.builder().build(); + + PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager()); + viewPager.setAdapter(pagerAdapter); + tabLayout.setupWithViewPager(viewPager); + viewPager.setCurrentItem(0); } @TargetApi(Build.VERSION_CODES.HONEYCOMB) @@ -90,12 +148,6 @@ public class RssfeedsActivity extends AppCompatActivity { TorrentsActivity_.intent(this).flags(Intent.FLAG_ACTIVITY_CLEAR_TOP).start(); } - @Override - protected void onResume() { - super.onResume(); - refreshFeeds(); - } - /** * Reload the RSS feed settings and start loading all the feeds. To be called from contained fragments. */ diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsFragment.java b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsFragment.java index df227b4b..d7025ec7 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsFragment.java @@ -16,7 +16,7 @@ */ package org.transdroid.core.gui.rss; -import android.app.Fragment; +import android.support.v4.app.Fragment; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -77,6 +77,12 @@ public class RssfeedsFragment extends Fragment { MainSettingsActivity_.intent(getActivity()).start(); } + @Override + public void onResume() { + super.onResume(); + this.refreshScreen(); + } + @OptionsItem(R.id.action_refresh) protected void refreshScreen() { ((RssfeedsActivity) getActivity()).refreshFeeds(); diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssitemsFragment.java b/app/src/main/java/org/transdroid/core/gui/rss/RssitemsFragment.java index 869baf68..31c5d7f1 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssitemsFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssitemsFragment.java @@ -17,13 +17,13 @@ package org.transdroid.core.gui.rss; import android.app.AlertDialog; -import android.app.Fragment; import android.app.SearchManager; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.net.Uri; +import android.support.v4.app.Fragment; import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.view.ActionMode; diff --git a/app/src/main/res/layout/activity_rssfeeds.xml b/app/src/main/res/layout/activity_rssfeeds.xml index 6fb3f0e4..0d4fe9dd 100644 --- a/app/src/main/res/layout/activity_rssfeeds.xml +++ b/app/src/main/res/layout/activity_rssfeeds.xml @@ -32,12 +32,26 @@ style="@style/DefaultToolbarShadow" android:layout_below="@id/rssfeeds_toolbar" /> - + android:layout_marginTop="-2dp"> + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7eb5dc56..694d8e8d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -99,7 +99,9 @@ Invert selection Add torrent to… http://… - + RSS feeds + Remote feeds + STATUS: %1$s Waiting to check… Verifying local data… From f92dd04a314bdbd32a4c824b3bc80021eb3c5026 Mon Sep 17 00:00:00 2001 From: Twig N Date: Mon, 6 Jan 2020 21:47:47 +1100 Subject: [PATCH 02/17] - moved most of remoterss/RemoteRssActivity code into RssfeedsActivity - RemoteRssFragment now extends android.support.v4.app.Fragment - removed swipeRefreshLayout --- .../core/gui/remoterss/RemoteRssActivity.java | 230 +++++++++--------- .../core/gui/remoterss/RemoteRssFragment.java | 85 +++---- .../core/gui/rss/RssfeedsActivity.java | 140 ++++++++++- .../main/res/layout/fragment_remoterss.xml | 17 +- 4 files changed, 296 insertions(+), 176 deletions(-) diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java index 56445861..15eca9a2 100644 --- a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java @@ -72,24 +72,24 @@ import java.util.List; * @author Twig Nguyen */ @EActivity(R.layout.activity_remoterss) -public class RemoteRssActivity extends AppCompatActivity implements RefreshableActivity { - @NonConfigurationInstance - protected ArrayList feeds; +public class RemoteRssActivity extends AppCompatActivity { +// @NonConfigurationInstance +// protected ArrayList feeds; - @InstanceState - protected int selectedFilter; +// @InstanceState +// protected int selectedFilter; - @NonConfigurationInstance - protected ArrayList recentItems; +// @NonConfigurationInstance +// protected ArrayList recentItems; // Server connection @Bean protected ApplicationSettings applicationSettings; @Bean protected Log log; - @Bean - protected ConnectivityHelper connectivityHelper; - private IDaemonAdapter currentConnection; +// @Bean +// protected ConnectivityHelper connectivityHelper; +// private IDaemonAdapter currentConnection; // Details view components @ViewById @@ -122,71 +122,71 @@ public class RemoteRssActivity extends AppCompatActivity implements RefreshableA setSupportActionBar(torrentsToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - // Connect to the last used server - ServerSetting lastUsed = applicationSettings.getLastUsedServer(); - currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this); - - if (feeds != null) { - // Called from a configuration change. No need to load anything from server - showChannelFilters(); - fragmentRemoteRss.updateRemoteItems( - selectedFilter == 0 ? recentItems : feeds.get(selectedFilter - 1).getItems(), - false /* allow android to restore scroll position */ ); - } else { - loadFeeds(); - } - - } - - @Background - protected void loadFeeds() { - try { - fragmentRemoteRss.setRefreshing(true); - feeds = ((RemoteRssSupplier) (currentConnection)).getRemoteRssChannels(log); - fragmentRemoteRss.setRefreshing(false); - } catch (DaemonException e) { - onCommunicationError(e); - } - - recentItems = new ArrayList<>(); - Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.MONTH, -1); - Date oneMonthAgo = calendar.getTime(); - - for (RemoteRssChannel feed : feeds) { - for (RemoteRssItem item : feed.getItems()) { - if (item.getTimestamp().after(oneMonthAgo)) { - recentItems.add(item); - } - } - } - // Sort by -newest - Collections.sort(recentItems, new Comparator() { - @Override - public int compare(RemoteRssItem lhs, RemoteRssItem rhs) { - return rhs.getTimestamp().compareTo(lhs.getTimestamp()); - } - }); +// // Connect to the last used server +// ServerSetting lastUsed = applicationSettings.getLastUsedServer(); +// currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this); +// +// if (feeds != null) { +// // Called from a configuration change. No need to load anything from server +// showChannelFilters(); +// fragmentRemoteRss.updateRemoteItems( +// selectedFilter == 0 ? recentItems : feeds.get(selectedFilter - 1).getItems(), +// false /* allow android to restore scroll position */ ); +// } else { +// loadFeeds(); +// } - afterLoadFeeds(); } - @UiThread - protected void afterLoadFeeds() { - // We need to wrap these calls in a @UiThread rather than make them each a @UiThread themselves - // because they need to run sequentially in a configuration change scenario in order for Android - // to maintain scroll position on the fragment adapter. - showChannelFilters(); - onFeedSelected(selectedFilter); - } - - @UiThread - protected void onCommunicationError(DaemonException daemonException) { - //noinspection ThrowableResultOfMethodCallIgnored - log.i(this, daemonException.toString()); - String error = getString(LocalTorrent.getResourceForDaemonException(daemonException)); - SnackbarManager.show(Snackbar.with(this).text(error).colorResource(R.color.red).type(SnackbarType.MULTI_LINE)); - } +// @Background +// protected void loadFeeds() { +// try { +// fragmentRemoteRss.setRefreshing(true); +// feeds = ((RemoteRssSupplier) (currentConnection)).getRemoteRssChannels(log); +// fragmentRemoteRss.setRefreshing(false); +// } catch (DaemonException e) { +// onCommunicationError(e); +// } +// +// recentItems = new ArrayList<>(); +// Calendar calendar = Calendar.getInstance(); +// calendar.add(Calendar.MONTH, -1); +// Date oneMonthAgo = calendar.getTime(); +// +// for (RemoteRssChannel feed : feeds) { +// for (RemoteRssItem item : feed.getItems()) { +// if (item.getTimestamp().after(oneMonthAgo)) { +// recentItems.add(item); +// } +// } +// } +// // Sort by -newest +// Collections.sort(recentItems, new Comparator() { +// @Override +// public int compare(RemoteRssItem lhs, RemoteRssItem rhs) { +// return rhs.getTimestamp().compareTo(lhs.getTimestamp()); +// } +// }); +// +// afterLoadFeeds(); +// } + +// @UiThread +// protected void afterLoadFeeds() { +// // We need to wrap these calls in a @UiThread rather than make them each a @UiThread themselves +// // because they need to run sequentially in a configuration change scenario in order for Android +// // to maintain scroll position on the fragment adapter. +// showChannelFilters(); +// onFeedSelected(selectedFilter); +// } + +// @UiThread +// protected void onCommunicationError(DaemonException daemonException) { +// //noinspection ThrowableResultOfMethodCallIgnored +// log.i(this, daemonException.toString()); +// String error = getString(LocalTorrent.getResourceForDaemonException(daemonException)); +// SnackbarManager.show(Snackbar.with(this).text(error).colorResource(R.color.red).type(SnackbarType.MULTI_LINE)); +// } @TargetApi(Build.VERSION_CODES.HONEYCOMB) @@ -208,49 +208,49 @@ public class RemoteRssActivity extends AppCompatActivity implements RefreshableA } } - private void showChannelFilters() { - List feedLabels = new ArrayList<>(feeds.size() +1); - feedLabels.add(new RemoteRssChannel() { - @Override - public String getName() { - return getString(R.string.remoterss_filter_allrecent); - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - } - }); - feedLabels.addAll(feeds); - - drawerList.setAdapter(new SimpleListItemAdapter(this, feedLabels)); + private void showChannelFilters() { +// List feedLabels = new ArrayList<>(feeds.size() +1); +// feedLabels.add(new RemoteRssChannel() { +// @Override +// public String getName() { +// return getString(R.string.remoterss_filter_allrecent); +// } +// +// @Override +// public void writeToParcel(Parcel dest, int flags) { +// } +// }); +// feedLabels.addAll(feeds); +// +// drawerList.setAdapter(new SimpleListItemAdapter(this, feedLabels)); } - @ItemClick(R.id.drawer_list) - protected void onFeedSelected(int position) { - selectedFilter = position; - fragmentRemoteRss.updateRemoteItems(position == 0 ? recentItems : feeds.get(position - 1).getItems(), true); - - RemoteRssChannel channel = (RemoteRssChannel) drawerList.getAdapter().getItem(position); - getSupportActionBar().setSubtitle(channel.getName()); - - drawerLayout.closeDrawers(); - } - - public IDaemonAdapter getCurrentConnection() { - return currentConnection; - } - - public RemoteRssChannel getChannel(String name) { - for (RemoteRssChannel feed : feeds) { - if (feed.getName().equals(name)) { - return feed; - } - } - return null; - } - - @Override - public void refreshScreen() { - loadFeeds(); - } +// @ItemClick(R.id.drawer_list) +// protected void onFeedSelected(int position) { +// selectedFilter = position; +// fragmentRemoteRss.updateRemoteItems(position == 0 ? recentItems : feeds.get(position - 1).getItems(), true); +// +// RemoteRssChannel channel = (RemoteRssChannel) drawerList.getAdapter().getItem(position); +// getSupportActionBar().setSubtitle(channel.getName()); +// +// drawerLayout.closeDrawers(); +// } + +// public IDaemonAdapter getCurrentConnection() { +// return currentConnection; +// } + +// public RemoteRssChannel getChannel(String name) { +// for (RemoteRssChannel feed : feeds) { +// if (feed.getName().equals(name)) { +// return feed; +// } +// } +// return null; +// } + +// @Override +// public void refreshScreen() { +// loadFeeds(); +// } } diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java index fe51e925..9560bc48 100644 --- a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java @@ -17,7 +17,7 @@ package org.transdroid.core.gui.remoterss; -import android.app.Fragment; +import android.support.v4.app.Fragment; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.ActionMenuView; import android.view.View; @@ -41,6 +41,7 @@ import org.transdroid.core.gui.log.Log; import org.transdroid.core.gui.navigation.RefreshableActivity; import org.transdroid.core.gui.remoterss.data.RemoteRssItem; import org.transdroid.core.gui.remoterss.data.RemoteRssSupplier; +import org.transdroid.core.gui.rss.RssfeedsActivity; import org.transdroid.daemon.DaemonException; import org.transdroid.daemon.task.DaemonTaskSuccessResult; @@ -66,8 +67,6 @@ public class RemoteRssFragment extends Fragment { @ViewById(R.id.contextual_menu) protected ActionMenuView contextualMenu; @ViewById - protected SwipeRefreshLayout swipeRefreshLayout; - @ViewById protected ListView torrentsList; @ViewById protected TextView remoterssStatusMessage; @@ -94,16 +93,12 @@ public class RemoteRssFragment extends Fragment { adapter = new RemoteRssItemsAdapter(getActivity()); torrentsList.setAdapter(adapter); torrentsList.setFastScrollEnabled(true); + } - // Allow pulls on the list view to refresh the torrents - if (getActivity() != null && getActivity() instanceof RefreshableActivity) { - swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { - @Override - public void onRefresh() { - ((RefreshableActivity) getActivity()).refreshScreen(); - } - }); - } + @Override + public void onResume() { + super.onResume(); + ((RssfeedsActivity) getActivity()).refreshRemoteFeeds(); } /** @@ -123,12 +118,6 @@ public class RemoteRssFragment extends Fragment { remoterssStatusMessage.setVisibility(View.VISIBLE); remoterssStatusMessage.setText(R.string.remoterss_no_files); } - swipeRefreshLayout.setRefreshing(false); - } - - @UiThread - public void setRefreshing(boolean refreshing) { - swipeRefreshLayout.setRefreshing(refreshing); } /** @@ -137,36 +126,38 @@ public class RemoteRssFragment extends Fragment { @ItemClick(resName = "torrents_list") protected void detailsListClicked(int position) { RemoteRssItem item = (RemoteRssItem) adapter.getItem(position); - downloadRemoteRssItem(item); - } +// downloadRemoteRssItem(item); - /** - * Download the item in a background thread and display success/fail accordingly. - */ - @Background - protected void downloadRemoteRssItem(RemoteRssItem item) { - final RemoteRssActivity activity = (RemoteRssActivity) getActivity(); - final RemoteRssSupplier supplier = (RemoteRssSupplier) activity.getCurrentConnection(); - - try { - supplier.downloadRemoteRssItem(log, item, activity.getChannel(item.getSourceName())); - onTaskSucceeded(null, getString(R.string.result_added, item.getTitle())); - } catch (DaemonException e) { - onTaskFailed(getString(LocalTorrent.getResourceForDaemonException(e))); - } - } - - @UiThread - protected void onTaskSucceeded(DaemonTaskSuccessResult result, String successMessage) { - SnackbarManager.show(Snackbar.with(getActivity()).text(successMessage)); + ((RssfeedsActivity) getActivity()).downloadRemoteRssItem(item); } - @UiThread - protected void onTaskFailed(String message) { - SnackbarManager.show(Snackbar.with(getActivity()) - .text(message) - .colorResource(R.color.red) - .type(SnackbarType.MULTI_LINE) - ); - } +// /** +// * Download the item in a background thread and display success/fail accordingly. +// */ +// @Background +// protected void downloadRemoteRssItem(RemoteRssItem item) { +// final RemoteRssActivity activity = (RemoteRssActivity) getActivity(); +// final RemoteRssSupplier supplier = (RemoteRssSupplier) activity.getCurrentConnection(); +// +// try { +// supplier.downloadRemoteRssItem(log, item, activity.getChannel(item.getSourceName())); +// onTaskSucceeded(null, getString(R.string.result_added, item.getTitle())); +// } catch (DaemonException e) { +// onTaskFailed(getString(LocalTorrent.getResourceForDaemonException(e))); +// } +// } +// +// @UiThread +// protected void onTaskSucceeded(DaemonTaskSuccessResult result, String successMessage) { +// SnackbarManager.show(Snackbar.with(getActivity()).text(successMessage)); +// } +// +// @UiThread +// protected void onTaskFailed(String message) { +// SnackbarManager.show(Snackbar.with(getActivity()) +// .text(message) +// .colorResource(R.color.red) +// .type(SnackbarType.MULTI_LINE) +// ); +// } } diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java index 8925d937..257c855d 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java @@ -33,26 +33,43 @@ import android.text.TextUtils; import com.nispok.snackbar.Snackbar; import com.nispok.snackbar.SnackbarManager; +import com.nispok.snackbar.enums.SnackbarType; import org.androidannotations.annotations.AfterViews; import org.androidannotations.annotations.Background; import org.androidannotations.annotations.Bean; import org.androidannotations.annotations.EActivity; import org.androidannotations.annotations.FragmentById; +import org.androidannotations.annotations.InstanceState; +import org.androidannotations.annotations.NonConfigurationInstance; import org.androidannotations.annotations.OptionsItem; import org.androidannotations.annotations.UiThread; import org.androidannotations.annotations.ViewById; import org.transdroid.R; import org.transdroid.core.app.settings.ApplicationSettings; import org.transdroid.core.app.settings.RssfeedSetting; +import org.transdroid.core.app.settings.ServerSetting; import org.transdroid.core.app.settings.SystemSettings_; import org.transdroid.core.gui.TorrentsActivity_; +import org.transdroid.core.gui.lists.LocalTorrent; import org.transdroid.core.gui.log.Log; import org.transdroid.core.gui.navigation.NavigationHelper; +import org.transdroid.core.gui.remoterss.RemoteRssFragment; +import org.transdroid.core.gui.remoterss.RemoteRssFragment_; +import org.transdroid.core.gui.remoterss.data.RemoteRssChannel; +import org.transdroid.core.gui.remoterss.data.RemoteRssItem; +import org.transdroid.core.gui.remoterss.data.RemoteRssSupplier; import org.transdroid.core.rssparser.Channel; import org.transdroid.core.rssparser.RssParser; +import org.transdroid.core.service.ConnectivityHelper; +import org.transdroid.daemon.DaemonException; +import org.transdroid.daemon.IDaemonAdapter; +import org.transdroid.daemon.task.DaemonTaskSuccessResult; import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.Comparator; import java.util.Date; import java.util.List; @@ -64,10 +81,12 @@ public class RssfeedsActivity extends AppCompatActivity { protected Log log; @Bean protected ApplicationSettings applicationSettings; + protected List loaders; // Contained feeds and items fragments protected RssfeedsFragment fragmentFeeds; + protected RemoteRssFragment fragmentRemoteFeeds; @FragmentById(R.id.rssitems_fragment) protected RssitemsFragment fragmentItems; @ViewById @@ -80,6 +99,17 @@ public class RssfeedsActivity extends AppCompatActivity { protected static final int RSS_FEEDS_LOCAL = 0; protected static final int RSS_FEEDS_REMOTE = 1; + // remote RSS stuff + @NonConfigurationInstance + protected ArrayList feeds; + @InstanceState + protected int selectedFilter; + @NonConfigurationInstance + protected ArrayList recentItems; + @Bean + protected ConnectivityHelper connectivityHelper; + + class PagerAdapter extends FragmentPagerAdapter { public PagerAdapter(FragmentManager fm) { super(fm); @@ -93,7 +123,7 @@ public class RssfeedsActivity extends AppCompatActivity { fragment = fragmentFeeds; } else if (position == RSS_FEEDS_REMOTE) { - fragment = null; + fragment = fragmentRemoteFeeds; } return fragment; @@ -134,7 +164,7 @@ public class RssfeedsActivity extends AppCompatActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); fragmentFeeds = RssfeedsFragment_.builder().build(); - fragmentItems = RssitemsFragment_.builder().build(); + fragmentRemoteFeeds = RemoteRssFragment_.builder().build(); PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(pagerAdapter); @@ -180,7 +210,6 @@ public class RssfeedsActivity extends AppCompatActivity { handleRssfeedResult(loader, null, true); log.i(this, "RSS feed " + loader.getSetting().getUrl() + " error: " + e.toString()); } - } /** @@ -250,7 +279,112 @@ public class RssfeedsActivity extends AppCompatActivity { .requiresExternalAuthentication(loader.getSetting().requiresExternalAuthentication()).start(); } + } + + protected IDaemonAdapter getCurrentConnection() { + ServerSetting lastUsed = applicationSettings.getLastUsedServer(); + return lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this); + } + + public void refreshRemoteFeeds() { + // Connect to the last used server + IDaemonAdapter currentConnection = this.getCurrentConnection(); + + // remote rss not supported for this connection type + if (currentConnection instanceof RemoteRssSupplier == false) { + return; + } + + try { + feeds = ((RemoteRssSupplier) (currentConnection)).getRemoteRssChannels(log); + + // loadFeeds() in background + recentItems = new ArrayList<>(); + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.MONTH, -1); + Date oneMonthAgo = calendar.getTime(); + + for (RemoteRssChannel feed : feeds) { + for (RemoteRssItem item : feed.getItems()) { + if (item.getTimestamp().after(oneMonthAgo)) { + recentItems.add(item); + } + } + } + + // Sort by -newest + Collections.sort(recentItems, new Comparator() { + @Override + public int compare(RemoteRssItem lhs, RemoteRssItem rhs) { + return rhs.getTimestamp().compareTo(lhs.getTimestamp()); + } + }); + } catch (DaemonException e) { + onCommunicationError(e); + return; + } + +// if (feeds != null) { + // Called from a configuration change. No need to load anything from server +// showChannelFilters(); + fragmentRemoteFeeds.updateRemoteItems( +// selectedFilter == 0 ? recentItems : feeds.get(selectedFilter).getItems(), + recentItems, + false /* allow android to restore scroll position */ ); +// } else { +// loadFeeds(); +// } + } + + @UiThread + protected void onCommunicationError(DaemonException daemonException) { + //noinspection ThrowableResultOfMethodCallIgnored + log.i(this, daemonException.toString()); + String error = getString(LocalTorrent.getResourceForDaemonException(daemonException)); + SnackbarManager.show(Snackbar.with(this).text(error).colorResource(R.color.red).type(SnackbarType.MULTI_LINE)); + } + + +// @ItemClick(R.id.drawer_list) + protected void onFeedSelected(int position) { + selectedFilter = position; + RemoteRssChannel channel = feeds.get(position); + + fragmentRemoteFeeds.updateRemoteItems(position == 0 ? recentItems : channel.getItems(), true); + +// RemoteRssChannel channel = (RemoteRssChannel) drawerList.getAdapter().getItem(position); +// getSupportActionBar().setSubtitle(channel.getName()); + +// drawerLayout.closeDrawers(); + } + + /** + * Download the item in a background thread and display success/fail accordingly. + */ + @Background + public void downloadRemoteRssItem(RemoteRssItem item) { + final RemoteRssSupplier supplier = (RemoteRssSupplier) this.getCurrentConnection(); + + try { + RemoteRssChannel channel = feeds.get(selectedFilter); + supplier.downloadRemoteRssItem(log, item, channel); + onTaskSucceeded(null, getString(R.string.result_added, item.getTitle())); + } catch (DaemonException e) { + onTaskFailed(getString(LocalTorrent.getResourceForDaemonException(e))); + } + } + @UiThread + protected void onTaskSucceeded(DaemonTaskSuccessResult result, String successMessage) { + SnackbarManager.show(Snackbar.with(this).text(successMessage)); } + @UiThread + protected void onTaskFailed(String message) { + SnackbarManager.show(Snackbar.with(this) + .text(message) + .colorResource(R.color.red) + .type(SnackbarType.MULTI_LINE) + ); + } } diff --git a/app/src/main/res/layout/fragment_remoterss.xml b/app/src/main/res/layout/fragment_remoterss.xml index c3811430..fe10b7c6 100644 --- a/app/src/main/res/layout/fragment_remoterss.xml +++ b/app/src/main/res/layout/fragment_remoterss.xml @@ -27,16 +27,11 @@ android:gravity="center" android:id="@+id/remoterss_status_message"/> - - - + android:layout_height="match_parent" + android:clipToPadding="false" + tools:listitem="@layout/list_item_remoterssitem" + tools:visibility="visible"/> From ff3a289914a9a5f7839bb2f305b85cd404dd4394 Mon Sep 17 00:00:00 2001 From: Twig N Date: Tue, 7 Jan 2020 22:38:40 +1100 Subject: [PATCH 03/17] - replaced the navigation drawer filter with an ugly spinner - filters work again --- .../core/gui/remoterss/RemoteRssFragment.java | 70 ++++--------------- .../core/gui/rss/RssfeedsActivity.java | 42 +++++++---- .../main/res/layout/fragment_remoterss.xml | 20 ++++-- 3 files changed, 56 insertions(+), 76 deletions(-) diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java index 9560bc48..34b9b259 100644 --- a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java @@ -18,32 +18,23 @@ package org.transdroid.core.gui.remoterss; import android.support.v4.app.Fragment; -import android.support.v4.widget.SwipeRefreshLayout; -import android.support.v7.widget.ActionMenuView; import android.view.View; import android.widget.ListView; +import android.widget.Spinner; import android.widget.TextView; -import com.nispok.snackbar.Snackbar; -import com.nispok.snackbar.SnackbarManager; -import com.nispok.snackbar.enums.SnackbarType; - import org.androidannotations.annotations.AfterViews; -import org.androidannotations.annotations.Background; import org.androidannotations.annotations.Bean; import org.androidannotations.annotations.EFragment; import org.androidannotations.annotations.ItemClick; -import org.androidannotations.annotations.UiThread; +import org.androidannotations.annotations.ItemSelect; import org.androidannotations.annotations.ViewById; import org.transdroid.R; -import org.transdroid.core.gui.lists.LocalTorrent; +import org.transdroid.core.gui.lists.SimpleListItemAdapter; import org.transdroid.core.gui.log.Log; -import org.transdroid.core.gui.navigation.RefreshableActivity; +import org.transdroid.core.gui.remoterss.data.RemoteRssChannel; import org.transdroid.core.gui.remoterss.data.RemoteRssItem; -import org.transdroid.core.gui.remoterss.data.RemoteRssSupplier; import org.transdroid.core.gui.rss.RssfeedsActivity; -import org.transdroid.daemon.DaemonException; -import org.transdroid.daemon.task.DaemonTaskSuccessResult; import java.util.ArrayList; import java.util.List; @@ -64,8 +55,8 @@ public class RemoteRssFragment extends Fragment { // Views @ViewById protected View detailsContainer; - @ViewById(R.id.contextual_menu) - protected ActionMenuView contextualMenu; + @ViewById + protected Spinner remoterssFilter; @ViewById protected ListView torrentsList; @ViewById @@ -75,20 +66,9 @@ public class RemoteRssFragment extends Fragment { @AfterViews protected void init() { - // Inject menu options in the actions toolbar setHasOptionsMenu(true); -// // On large screens where this fragment is shown next to the torrents list, we show a continues grey vertical -// // line to separate the lists visually -// if (!NavigationHelper_.getInstance_(getActivity()).isSmallScreen()) { -// if (SystemSettings_.getInstance_(getActivity()).useDarkTheme()) { -// detailsContainer.setBackgroundResource(R.drawable.details_list_background_dark); -// } else { -// detailsContainer.setBackgroundResource(R.drawable.details_list_background_light); -// } -// } - // Set up details adapter adapter = new RemoteRssItemsAdapter(getActivity()); torrentsList.setAdapter(adapter); @@ -120,44 +100,22 @@ public class RemoteRssFragment extends Fragment { } } + public void updateChannelFilters(List feedLabels) { + remoterssFilter.setAdapter(new SimpleListItemAdapter(this.getContext(), feedLabels)); + } + /** * When the user clicks on an item, prepare to download it. */ @ItemClick(resName = "torrents_list") protected void detailsListClicked(int position) { RemoteRssItem item = (RemoteRssItem) adapter.getItem(position); -// downloadRemoteRssItem(item); ((RssfeedsActivity) getActivity()).downloadRemoteRssItem(item); } -// /** -// * Download the item in a background thread and display success/fail accordingly. -// */ -// @Background -// protected void downloadRemoteRssItem(RemoteRssItem item) { -// final RemoteRssActivity activity = (RemoteRssActivity) getActivity(); -// final RemoteRssSupplier supplier = (RemoteRssSupplier) activity.getCurrentConnection(); -// -// try { -// supplier.downloadRemoteRssItem(log, item, activity.getChannel(item.getSourceName())); -// onTaskSucceeded(null, getString(R.string.result_added, item.getTitle())); -// } catch (DaemonException e) { -// onTaskFailed(getString(LocalTorrent.getResourceForDaemonException(e))); -// } -// } -// -// @UiThread -// protected void onTaskSucceeded(DaemonTaskSuccessResult result, String successMessage) { -// SnackbarManager.show(Snackbar.with(getActivity()).text(successMessage)); -// } -// -// @UiThread -// protected void onTaskFailed(String message) { -// SnackbarManager.show(Snackbar.with(getActivity()) -// .text(message) -// .colorResource(R.color.red) -// .type(SnackbarType.MULTI_LINE) -// ); -// } + @ItemSelect(R.id.remoterss_filter) + protected void onFeedSelected(boolean selected, int position) { + ((RssfeedsActivity) getActivity()).onFeedSelected(position); + } } diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java index 257c855d..c2d0e494 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java @@ -21,6 +21,7 @@ import android.content.Intent; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.os.Parcel; import android.support.annotation.Nullable; import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; @@ -324,16 +325,10 @@ public class RssfeedsActivity extends AppCompatActivity { return; } -// if (feeds != null) { - // Called from a configuration change. No need to load anything from server -// showChannelFilters(); fragmentRemoteFeeds.updateRemoteItems( -// selectedFilter == 0 ? recentItems : feeds.get(selectedFilter).getItems(), - recentItems, + selectedFilter == 0 ? recentItems : feeds.get(selectedFilter -1).getItems(), false /* allow android to restore scroll position */ ); -// } else { -// loadFeeds(); -// } + showRemoteChannelFilters(); } @UiThread @@ -345,17 +340,19 @@ public class RssfeedsActivity extends AppCompatActivity { } -// @ItemClick(R.id.drawer_list) - protected void onFeedSelected(int position) { + public void onFeedSelected(int position) { selectedFilter = position; - RemoteRssChannel channel = feeds.get(position); - fragmentRemoteFeeds.updateRemoteItems(position == 0 ? recentItems : channel.getItems(), true); + if (position == 0) { + fragmentRemoteFeeds.updateRemoteItems(recentItems, true); + } + else { + RemoteRssChannel channel = feeds.get(selectedFilter -1); + fragmentRemoteFeeds.updateRemoteItems(channel.getItems(), true); + } // RemoteRssChannel channel = (RemoteRssChannel) drawerList.getAdapter().getItem(position); // getSupportActionBar().setSubtitle(channel.getName()); - -// drawerLayout.closeDrawers(); } /** @@ -387,4 +384,21 @@ public class RssfeedsActivity extends AppCompatActivity { .type(SnackbarType.MULTI_LINE) ); } + + private void showRemoteChannelFilters() { + List feedLabels = new ArrayList<>(feeds.size() +1); + feedLabels.add(new RemoteRssChannel() { + @Override + public String getName() { + return getString(R.string.remoterss_filter_allrecent); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + } + }); + feedLabels.addAll(feeds); + + fragmentRemoteFeeds.updateChannelFilters(feedLabels); + } } diff --git a/app/src/main/res/layout/fragment_remoterss.xml b/app/src/main/res/layout/fragment_remoterss.xml index fe10b7c6..88648efb 100644 --- a/app/src/main/res/layout/fragment_remoterss.xml +++ b/app/src/main/res/layout/fragment_remoterss.xml @@ -15,10 +15,18 @@ You should have received a copy of the GNU General Public License along with Transdroid. If not, see . --> - + + + - + tools:visibility="visible" /> + From e30dfc13b33491dcfb1e0575f56e1566b449f337 Mon Sep 17 00:00:00 2001 From: Twig N Date: Wed, 8 Jan 2020 00:36:08 +1100 Subject: [PATCH 04/17] Dont store loaders and adapters in class variables if we dont need to --- .../transdroid/core/gui/remoterss/RemoteRssFragment.java | 8 ++++++-- .../org/transdroid/core/gui/rss/RssfeedsActivity.java | 5 ++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java index 34b9b259..e73de91c 100644 --- a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java @@ -62,7 +62,7 @@ public class RemoteRssFragment extends Fragment { @ViewById protected TextView remoterssStatusMessage; - protected RemoteRssItemsAdapter adapter; +// protected RemoteRssItemsAdapter adapter; @AfterViews protected void init() { @@ -70,7 +70,7 @@ public class RemoteRssFragment extends Fragment { setHasOptionsMenu(true); // Set up details adapter - adapter = new RemoteRssItemsAdapter(getActivity()); + RemoteRssItemsAdapter adapter = new RemoteRssItemsAdapter(getActivity()); torrentsList.setAdapter(adapter); torrentsList.setFastScrollEnabled(true); } @@ -85,8 +85,11 @@ public class RemoteRssFragment extends Fragment { * Updates the UI with a new list of RSS items. */ public void updateRemoteItems(List remoteItems, boolean scrollToTop) { + RemoteRssItemsAdapter adapter = (RemoteRssItemsAdapter) torrentsList.getAdapter(); + remoteRssItems = new ArrayList<>(remoteItems); adapter.updateItems(remoteRssItems); + if (scrollToTop) { torrentsList.smoothScrollToPosition(0); } @@ -109,6 +112,7 @@ public class RemoteRssFragment extends Fragment { */ @ItemClick(resName = "torrents_list") protected void detailsListClicked(int position) { + RemoteRssItemsAdapter adapter = (RemoteRssItemsAdapter) torrentsList.getAdapter(); RemoteRssItem item = (RemoteRssItem) adapter.getItem(position); ((RssfeedsActivity) getActivity()).downloadRemoteRssItem(item); diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java index c2d0e494..e5671ded 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java @@ -83,11 +83,10 @@ public class RssfeedsActivity extends AppCompatActivity { @Bean protected ApplicationSettings applicationSettings; - protected List loaders; - // Contained feeds and items fragments protected RssfeedsFragment fragmentFeeds; protected RemoteRssFragment fragmentRemoteFeeds; + @FragmentById(R.id.rssitems_fragment) protected RssitemsFragment fragmentItems; @ViewById @@ -183,7 +182,7 @@ public class RssfeedsActivity extends AppCompatActivity { * Reload the RSS feed settings and start loading all the feeds. To be called from contained fragments. */ public void refreshFeeds() { - loaders = new ArrayList<>(); + List loaders = new ArrayList<>(); // For each RSS feed setting the user created, start a loader that retrieved the RSS feed (via a background // thread) and, on success, determines the new items in the feed for (RssfeedSetting setting : applicationSettings.getRssfeedSettings()) { From 10c1bf76b674872966693c80416c5f02ebb5a466 Mon Sep 17 00:00:00 2001 From: Twig N Date: Sat, 18 Jan 2020 20:45:20 +1100 Subject: [PATCH 05/17] - fix crashes on activity recreation because android is just awful --- .../core/gui/remoterss/RemoteRssFragment.java | 15 ++++++- .../core/gui/rss/RssfeedsActivity.java | 45 ++++++++++++++----- .../core/gui/rss/RssfeedsFragment.java | 16 ++++++- 3 files changed, 63 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java index e73de91c..022a72e6 100644 --- a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java @@ -75,10 +75,23 @@ public class RemoteRssFragment extends Fragment { torrentsList.setFastScrollEnabled(true); } + protected RssfeedsActivity getRssActivity() { + return (RssfeedsActivity) getActivity(); + } + @Override public void onResume() { super.onResume(); - ((RssfeedsActivity) getActivity()).refreshRemoteFeeds(); + + getRssActivity().onFragmentReady(this); + getRssActivity().refreshRemoteFeeds(); + } + + @Override + public void onDestroy() { + super.onDestroy(); + + getRssActivity().onFragmentDestroy(this); } /** diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java index e5671ded..7cd4ac34 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java @@ -84,7 +84,7 @@ public class RssfeedsActivity extends AppCompatActivity { protected ApplicationSettings applicationSettings; // Contained feeds and items fragments - protected RssfeedsFragment fragmentFeeds; + protected RssfeedsFragment fragmentLocalFeeds; protected RemoteRssFragment fragmentRemoteFeeds; @FragmentById(R.id.rssitems_fragment) @@ -120,10 +120,10 @@ public class RssfeedsActivity extends AppCompatActivity { Fragment fragment = null; if (position == RSS_FEEDS_LOCAL) { - fragment = fragmentFeeds; + fragment = RssfeedsFragment_.builder().build(); } else if (position == RSS_FEEDS_REMOTE) { - fragment = fragmentRemoteFeeds; + fragment = RemoteRssFragment_.builder().build(); } return fragment; @@ -163,15 +163,30 @@ public class RssfeedsActivity extends AppCompatActivity { getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(getString(R.string.rss_feeds))); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - fragmentFeeds = RssfeedsFragment_.builder().build(); - fragmentRemoteFeeds = RemoteRssFragment_.builder().build(); - PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(pagerAdapter); tabLayout.setupWithViewPager(viewPager); viewPager.setCurrentItem(0); } + public void onFragmentReady(Fragment fragment) { + if (fragment instanceof RssfeedsFragment) { + fragmentLocalFeeds = (RssfeedsFragment) fragment; + } + else if (fragment instanceof RemoteRssFragment) { + fragmentRemoteFeeds = (RemoteRssFragment) fragment; + } + } + + public void onFragmentDestroy(Fragment fragment) { + if (fragment instanceof RssfeedsFragment) { + fragmentLocalFeeds = null; + } + else if (fragment instanceof RemoteRssFragment) { + fragmentRemoteFeeds = null; + } + } + @TargetApi(Build.VERSION_CODES.HONEYCOMB) @OptionsItem(android.R.id.home) protected void navigateUp() { @@ -190,7 +205,10 @@ public class RssfeedsActivity extends AppCompatActivity { loaders.add(loader); loadRssfeed(loader); } - fragmentFeeds.update(loaders); + + if (fragmentLocalFeeds != null) { + fragmentLocalFeeds.update(loaders); + } } /** @@ -221,7 +239,10 @@ public class RssfeedsActivity extends AppCompatActivity { @UiThread protected void handleRssfeedResult(RssfeedLoader loader, Channel channel, boolean hasError) { loader.update(channel, hasError); - fragmentFeeds.notifyDataSetChanged(); + + if (fragmentLocalFeeds != null) { + fragmentLocalFeeds.notifyDataSetChanged(); + } } /** @@ -324,9 +345,11 @@ public class RssfeedsActivity extends AppCompatActivity { return; } - fragmentRemoteFeeds.updateRemoteItems( + if (fragmentRemoteFeeds != null) { + fragmentRemoteFeeds.updateRemoteItems( selectedFilter == 0 ? recentItems : feeds.get(selectedFilter -1).getItems(), false /* allow android to restore scroll position */ ); + } showRemoteChannelFilters(); } @@ -398,6 +421,8 @@ public class RssfeedsActivity extends AppCompatActivity { }); feedLabels.addAll(feeds); - fragmentRemoteFeeds.updateChannelFilters(feedLabels); + if (fragmentRemoteFeeds != null) { + fragmentRemoteFeeds.updateChannelFilters(feedLabels); + } } } diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsFragment.java b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsFragment.java index d7025ec7..2ad23339 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsFragment.java @@ -77,20 +77,32 @@ public class RssfeedsFragment extends Fragment { MainSettingsActivity_.intent(getActivity()).start(); } + protected RssfeedsActivity getRssActivity() { + return (RssfeedsActivity) getActivity(); + } + @Override public void onResume() { super.onResume(); + getRssActivity().onFragmentReady(this); this.refreshScreen(); } + @Override + public void onDestroy() { + super.onDestroy(); + + getRssActivity().onFragmentDestroy(this); + } + @OptionsItem(R.id.action_refresh) protected void refreshScreen() { - ((RssfeedsActivity) getActivity()).refreshFeeds(); + getRssActivity().refreshFeeds(); } @ItemClick(R.id.rssfeeds_list) protected void onFeedClicked(RssfeedLoader loader) { - ((RssfeedsActivity) getActivity()).openRssfeed(loader, true); + getRssActivity().openRssfeed(loader, true); } /** From 226a9795b7ec4621b7b80ff0cec7c3040455c4b4 Mon Sep 17 00:00:00 2001 From: Twig N Date: Sat, 18 Jan 2020 21:10:31 +1100 Subject: [PATCH 06/17] - removed remoterss/RemoteRssActivity.java - removed activity_remoterss.xml - removed menu item to RemoteRssActivity.java --- .../transdroid/core/gui/TorrentsActivity.java | 12 - .../core/gui/remoterss/RemoteRssActivity.java | 256 ------------------ .../main/res/layout/activity_remoterss.xml | 79 ------ .../main/res/menu/activity_torrents_main.xml | 5 - 4 files changed, 352 deletions(-) delete mode 100644 app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java delete mode 100644 app/src/main/res/layout/activity_remoterss.xml diff --git a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java index a0d259e2..3a2d8f82 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java @@ -82,7 +82,6 @@ import org.transdroid.core.gui.navigation.NavigationFilter; import org.transdroid.core.gui.navigation.NavigationHelper; import org.transdroid.core.gui.navigation.RefreshableActivity; import org.transdroid.core.gui.navigation.StatusType; -import org.transdroid.core.gui.remoterss.RemoteRssActivity_; import org.transdroid.core.gui.rss.RssfeedsActivity_; import org.transdroid.core.gui.search.FilePickerHelper; import org.transdroid.core.gui.search.UrlEntryDialog; @@ -469,7 +468,6 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE filterSearch.setVisibility(View.GONE); torrentsToolbar.getMenu().findItem(R.id.action_search).setVisible(false); torrentsToolbar.getMenu().findItem(R.id.action_rss).setVisible(false); - torrentsToolbar.getMenu().findItem(R.id.action_remoterss).setVisible(false); torrentsToolbar.getMenu().findItem(R.id.action_settings).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); torrentsToolbar.getMenu().findItem(R.id.action_help).setVisible(true); actionsToolbar.getMenu().findItem(R.id.action_enableturtle).setVisible(false); @@ -493,12 +491,10 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE filtersList.setVisibility(View.VISIBLE); filterSearch.setVisibility(View.VISIBLE); boolean addByFile = Daemon.supportsAddByFile(currentConnection.getType()); - boolean hasRemoteRss = Daemon.supportsRemoteRssManagement(currentConnection.getType()); addmenuFileButton.setVisibility(addByFile ? View.VISIBLE : View.GONE); // Primary toolbar menu torrentsToolbar.getMenu().findItem(R.id.action_search).setVisible(navigationHelper.enableSearchUi()); torrentsToolbar.getMenu().findItem(R.id.action_rss).setVisible(navigationHelper.enableRssUi()); - torrentsToolbar.getMenu().findItem(R.id.action_remoterss).setVisible(hasRemoteRss); torrentsToolbar.getMenu().findItem(R.id.action_settings).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); torrentsToolbar.getMenu().findItem(R.id.action_help).setVisible(false); // Secondary toolbar menu @@ -821,14 +817,6 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE MainSettingsActivity_.intent(this).start(); } - @OptionsItem(R.id.action_remoterss) - @Background - protected void openRemoteRss() { - // Passing the items over as a feed can overload the Intent size limit and crash without a stack trace. - // Loading the items can take a while so we don't want to load them here and again in the RemoteRssActivity. - RemoteRssActivity_.intent(this).start(); - } - @OptionsItem(R.id.action_help) protected void openHelp() { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.transdroid.org/download/"))); diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java deleted file mode 100644 index 15eca9a2..00000000 --- a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright 2010-2018 Eric Kok et al. - * - * Transdroid is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Transdroid is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Transdroid. If not, see . - */ -package org.transdroid.core.gui.remoterss; - -import android.annotation.TargetApi; -import android.os.Build; -import android.os.Bundle; -import android.os.Parcel; -import android.support.v4.widget.DrawerLayout; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import android.widget.LinearLayout; -import android.widget.ListView; - -import com.nispok.snackbar.Snackbar; -import com.nispok.snackbar.SnackbarManager; -import com.nispok.snackbar.enums.SnackbarType; - -import org.androidannotations.annotations.AfterViews; -import org.androidannotations.annotations.Background; -import org.androidannotations.annotations.Bean; -import org.androidannotations.annotations.EActivity; -import org.androidannotations.annotations.FragmentById; -import org.androidannotations.annotations.InstanceState; -import org.androidannotations.annotations.ItemClick; -import org.androidannotations.annotations.NonConfigurationInstance; -import org.androidannotations.annotations.OptionsItem; -import org.androidannotations.annotations.UiThread; -import org.androidannotations.annotations.ViewById; -import org.transdroid.R; -import org.transdroid.core.app.settings.ApplicationSettings; -import org.transdroid.core.app.settings.ServerSetting; -import org.transdroid.core.app.settings.SystemSettings_; -import org.transdroid.core.gui.lists.LocalTorrent; -import org.transdroid.core.gui.lists.SimpleListItemAdapter; -import org.transdroid.core.gui.log.Log; -import org.transdroid.core.gui.navigation.RefreshableActivity; -import org.transdroid.core.gui.remoterss.data.RemoteRssChannel; -import org.transdroid.core.gui.remoterss.data.RemoteRssItem; -import org.transdroid.core.gui.remoterss.data.RemoteRssSupplier; -import org.transdroid.core.service.ConnectivityHelper; -import org.transdroid.daemon.DaemonException; -import org.transdroid.daemon.IDaemonAdapter; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.Comparator; -import java.util.Date; -import java.util.List; - -/** - * An activity that displays a list of {@link RemoteRssItem}s via an instance of {@link RemoteRssFragment}. - * The activity manages the drawer to filter items by the feed they came through. - * - * By default it displays the latest items within the last month. - * - * @author Twig Nguyen - */ -@EActivity(R.layout.activity_remoterss) -public class RemoteRssActivity extends AppCompatActivity { -// @NonConfigurationInstance -// protected ArrayList feeds; - -// @InstanceState -// protected int selectedFilter; - -// @NonConfigurationInstance -// protected ArrayList recentItems; - - // Server connection - @Bean - protected ApplicationSettings applicationSettings; - @Bean - protected Log log; -// @Bean -// protected ConnectivityHelper connectivityHelper; -// private IDaemonAdapter currentConnection; - - // Details view components - @ViewById - protected DrawerLayout drawerLayout; - @ViewById - protected LinearLayout drawerContainer; - - @ViewById - protected Toolbar torrentsToolbar; - - @ViewById - protected ListView drawerList; - - @FragmentById(R.id.remoterss_fragment) - protected RemoteRssFragment fragmentRemoteRss; - - @Override - public void onCreate(Bundle savedInstanceState) { - // Set the theme according to the user preference - if (SystemSettings_.getInstance_(this).useDarkTheme()) { - setTheme(R.style.TransdroidTheme_Dark); - } - super.onCreate(savedInstanceState); - } - - @AfterViews - protected void init() { - // Simple action bar with up, torrent name as title and refresh button - torrentsToolbar.setNavigationIcon(R.drawable.ic_action_drawer); - setSupportActionBar(torrentsToolbar); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - -// // Connect to the last used server -// ServerSetting lastUsed = applicationSettings.getLastUsedServer(); -// currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this); -// -// if (feeds != null) { -// // Called from a configuration change. No need to load anything from server -// showChannelFilters(); -// fragmentRemoteRss.updateRemoteItems( -// selectedFilter == 0 ? recentItems : feeds.get(selectedFilter - 1).getItems(), -// false /* allow android to restore scroll position */ ); -// } else { -// loadFeeds(); -// } - - } - -// @Background -// protected void loadFeeds() { -// try { -// fragmentRemoteRss.setRefreshing(true); -// feeds = ((RemoteRssSupplier) (currentConnection)).getRemoteRssChannels(log); -// fragmentRemoteRss.setRefreshing(false); -// } catch (DaemonException e) { -// onCommunicationError(e); -// } -// -// recentItems = new ArrayList<>(); -// Calendar calendar = Calendar.getInstance(); -// calendar.add(Calendar.MONTH, -1); -// Date oneMonthAgo = calendar.getTime(); -// -// for (RemoteRssChannel feed : feeds) { -// for (RemoteRssItem item : feed.getItems()) { -// if (item.getTimestamp().after(oneMonthAgo)) { -// recentItems.add(item); -// } -// } -// } -// // Sort by -newest -// Collections.sort(recentItems, new Comparator() { -// @Override -// public int compare(RemoteRssItem lhs, RemoteRssItem rhs) { -// return rhs.getTimestamp().compareTo(lhs.getTimestamp()); -// } -// }); -// -// afterLoadFeeds(); -// } - -// @UiThread -// protected void afterLoadFeeds() { -// // We need to wrap these calls in a @UiThread rather than make them each a @UiThread themselves -// // because they need to run sequentially in a configuration change scenario in order for Android -// // to maintain scroll position on the fragment adapter. -// showChannelFilters(); -// onFeedSelected(selectedFilter); -// } - -// @UiThread -// protected void onCommunicationError(DaemonException daemonException) { -// //noinspection ThrowableResultOfMethodCallIgnored -// log.i(this, daemonException.toString()); -// String error = getString(LocalTorrent.getResourceForDaemonException(daemonException)); -// SnackbarManager.show(Snackbar.with(this).text(error).colorResource(R.color.red).type(SnackbarType.MULTI_LINE)); -// } - - - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - @OptionsItem(android.R.id.home) - protected void navigateUp() { - if (drawerLayout.isDrawerOpen(drawerContainer)) { - drawerLayout.closeDrawers(); - } else { - drawerLayout.openDrawer(drawerContainer); - } - } - - @Override - public void onBackPressed() { - if (drawerLayout.isDrawerOpen(drawerContainer)) { - drawerLayout.closeDrawers(); - } else { - finish(); - } - } - - private void showChannelFilters() { -// List feedLabels = new ArrayList<>(feeds.size() +1); -// feedLabels.add(new RemoteRssChannel() { -// @Override -// public String getName() { -// return getString(R.string.remoterss_filter_allrecent); -// } -// -// @Override -// public void writeToParcel(Parcel dest, int flags) { -// } -// }); -// feedLabels.addAll(feeds); -// -// drawerList.setAdapter(new SimpleListItemAdapter(this, feedLabels)); - } - -// @ItemClick(R.id.drawer_list) -// protected void onFeedSelected(int position) { -// selectedFilter = position; -// fragmentRemoteRss.updateRemoteItems(position == 0 ? recentItems : feeds.get(position - 1).getItems(), true); -// -// RemoteRssChannel channel = (RemoteRssChannel) drawerList.getAdapter().getItem(position); -// getSupportActionBar().setSubtitle(channel.getName()); -// -// drawerLayout.closeDrawers(); -// } - -// public IDaemonAdapter getCurrentConnection() { -// return currentConnection; -// } - -// public RemoteRssChannel getChannel(String name) { -// for (RemoteRssChannel feed : feeds) { -// if (feed.getName().equals(name)) { -// return feed; -// } -// } -// return null; -// } - -// @Override -// public void refreshScreen() { -// loadFeeds(); -// } -} diff --git a/app/src/main/res/layout/activity_remoterss.xml b/app/src/main/res/layout/activity_remoterss.xml deleted file mode 100644 index 0d28fa6b..00000000 --- a/app/src/main/res/layout/activity_remoterss.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/menu/activity_torrents_main.xml b/app/src/main/res/menu/activity_torrents_main.xml index ba8b6e5c..01fc6115 100644 --- a/app/src/main/res/menu/activity_torrents_main.xml +++ b/app/src/main/res/menu/activity_torrents_main.xml @@ -28,11 +28,6 @@ android:icon="@drawable/ic_action_rss" android:title="@string/action_rss" app:showAsAction="ifRoom" /> - Date: Sat, 18 Jan 2020 21:12:28 +1100 Subject: [PATCH 07/17] - updated tab labels - updated comments in RssfeedsActivity.java - show/hide remote rss feeds tab depending on server support - show/hide tab depending on server support --- .../core/gui/rss/RssfeedsActivity.java | 25 ++++++++++++++++--- app/src/main/res/values/strings.xml | 4 +-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java index 7cd4ac34..90204014 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java @@ -31,6 +31,7 @@ import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.text.TextUtils; +import android.view.View; import com.nispok.snackbar.Snackbar; import com.nispok.snackbar.SnackbarManager; @@ -63,6 +64,7 @@ import org.transdroid.core.gui.remoterss.data.RemoteRssSupplier; import org.transdroid.core.rssparser.Channel; import org.transdroid.core.rssparser.RssParser; import org.transdroid.core.service.ConnectivityHelper; +import org.transdroid.daemon.Daemon; import org.transdroid.daemon.DaemonException; import org.transdroid.daemon.IDaemonAdapter; import org.transdroid.daemon.task.DaemonTaskSuccessResult; @@ -111,8 +113,12 @@ public class RssfeedsActivity extends AppCompatActivity { class PagerAdapter extends FragmentPagerAdapter { - public PagerAdapter(FragmentManager fm) { + boolean hasRemoteRss = false; + + public PagerAdapter(FragmentManager fm, boolean hasRemoteRss) { super(fm); + + this.hasRemoteRss = hasRemoteRss; } @Override @@ -131,7 +137,11 @@ public class RssfeedsActivity extends AppCompatActivity { @Override public int getCount() { - return 2; + if (this.hasRemoteRss) { + return 2; + } + + return 1; } @Nullable @@ -163,10 +173,15 @@ public class RssfeedsActivity extends AppCompatActivity { getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(getString(R.string.rss_feeds))); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager()); + boolean hasRemoteRss = Daemon.supportsRemoteRssManagement(this.getCurrentConnection().getType()); + PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager(), hasRemoteRss); viewPager.setAdapter(pagerAdapter); tabLayout.setupWithViewPager(viewPager); viewPager.setCurrentItem(0); + + if (!hasRemoteRss) { + tabLayout.setVisibility(View.GONE); + } } public void onFragmentReady(Fragment fragment) { @@ -307,6 +322,7 @@ public class RssfeedsActivity extends AppCompatActivity { return lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this); } +// @Background public void refreshRemoteFeeds() { // Connect to the last used server IDaemonAdapter currentConnection = this.getCurrentConnection(); @@ -319,7 +335,7 @@ public class RssfeedsActivity extends AppCompatActivity { try { feeds = ((RemoteRssSupplier) (currentConnection)).getRemoteRssChannels(log); - // loadFeeds() in background + // By default it displays the latest items within the last month. recentItems = new ArrayList<>(); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.MONTH, -1); @@ -345,6 +361,7 @@ public class RssfeedsActivity extends AppCompatActivity { return; } +// @UIThread if (fragmentRemoteFeeds != null) { fragmentRemoteFeeds.updateRemoteItems( selectedFilter == 0 ? recentItems : feeds.get(selectedFilter -1).getItems(), diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c90457ce..e8c4d2e7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -102,8 +102,8 @@ Invert selection Add torrent to… http://… - RSS feeds - Remote feeds + Transdroid + Server STATUS: %1$s Waiting to check… From 3fc82d4cc5f3fc53d4e6481f69e4fbeaf7d67d0d Mon Sep 17 00:00:00 2001 From: Twig N Date: Sun, 19 Jan 2020 20:39:59 +1100 Subject: [PATCH 08/17] - use actual server name rather than "Server" in remote rss tab --- .../transdroid/core/gui/rss/RssfeedsActivity.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java index 90204014..0f6ca231 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java @@ -114,11 +114,13 @@ public class RssfeedsActivity extends AppCompatActivity { class PagerAdapter extends FragmentPagerAdapter { boolean hasRemoteRss = false; + String serverName = ""; - public PagerAdapter(FragmentManager fm, boolean hasRemoteRss) { + public PagerAdapter(FragmentManager fm, boolean hasRemoteRss, String name) { super(fm); this.hasRemoteRss = hasRemoteRss; + this.serverName = (name.length() > 0 ? name : getString(R.string.navigation_rss_tabs_remote)); } @Override @@ -151,7 +153,7 @@ public class RssfeedsActivity extends AppCompatActivity { case RSS_FEEDS_LOCAL: return getString(R.string.navigation_rss_tabs_local); case RSS_FEEDS_REMOTE: - return getString(R.string.navigation_rss_tabs_remote); + return this.serverName; } return super.getPageTitle(position); @@ -173,8 +175,10 @@ public class RssfeedsActivity extends AppCompatActivity { getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(getString(R.string.rss_feeds))); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - boolean hasRemoteRss = Daemon.supportsRemoteRssManagement(this.getCurrentConnection().getType()); - PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager(), hasRemoteRss); + IDaemonAdapter currentConnection = this.getCurrentConnection(); + boolean hasRemoteRss = Daemon.supportsRemoteRssManagement(currentConnection.getType()); + + PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager(), hasRemoteRss, currentConnection.getSettings().getName()); viewPager.setAdapter(pagerAdapter); tabLayout.setupWithViewPager(viewPager); viewPager.setCurrentItem(0); From a1d471a78b78a41cacea40d27116ca2a7499c38a Mon Sep 17 00:00:00 2001 From: Twig N Date: Sun, 19 Jan 2020 21:01:36 +1100 Subject: [PATCH 09/17] - improve styling of remote rss channels filter --- .../core/gui/remoterss/RemoteRssFragment.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java index 022a72e6..04102760 100644 --- a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java @@ -19,6 +19,7 @@ package org.transdroid.core.gui.remoterss; import android.support.v4.app.Fragment; import android.view.View; +import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Spinner; import android.widget.TextView; @@ -30,7 +31,6 @@ import org.androidannotations.annotations.ItemClick; import org.androidannotations.annotations.ItemSelect; import org.androidannotations.annotations.ViewById; import org.transdroid.R; -import org.transdroid.core.gui.lists.SimpleListItemAdapter; import org.transdroid.core.gui.log.Log; import org.transdroid.core.gui.remoterss.data.RemoteRssChannel; import org.transdroid.core.gui.remoterss.data.RemoteRssItem; @@ -117,7 +117,15 @@ public class RemoteRssFragment extends Fragment { } public void updateChannelFilters(List feedLabels) { - remoterssFilter.setAdapter(new SimpleListItemAdapter(this.getContext(), feedLabels)); + List labels = new ArrayList<>(); + + for (RemoteRssChannel feedLabel : feedLabels) { + labels.add(feedLabel.getName()); + } + + ArrayAdapter adapter = new ArrayAdapter<>(this.getContext(), android.R.layout.simple_spinner_dropdown_item, labels); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + remoterssFilter.setAdapter(adapter); } /** From 151f8570ca82dee9de8f3da97ca80b13de66644a Mon Sep 17 00:00:00 2001 From: Twig N Date: Mon, 20 Jan 2020 21:06:32 +1100 Subject: [PATCH 10/17] - minor cleanup --- app/src/main/AndroidManifest.xml | 4 ---- .../java/org/transdroid/core/gui/rss/RssfeedsActivity.java | 3 --- 2 files changed, 7 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 31d29570..d25018f8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -256,10 +256,6 @@ android:name="org.transdroid.core.gui.rss.RssitemsActivity_" android:label="@string/rss_feeds" android:theme="@style/TransdroidTheme" /> - diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java index 0f6ca231..abeb976d 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java @@ -393,9 +393,6 @@ public class RssfeedsActivity extends AppCompatActivity { RemoteRssChannel channel = feeds.get(selectedFilter -1); fragmentRemoteFeeds.updateRemoteItems(channel.getItems(), true); } - -// RemoteRssChannel channel = (RemoteRssChannel) drawerList.getAdapter().getItem(position); -// getSupportActionBar().setSubtitle(channel.getName()); } /** From 521159c92868159afceb41921a4e306933bd6d93 Mon Sep 17 00:00:00 2001 From: Twig N Date: Mon, 20 Jan 2020 21:07:24 +1100 Subject: [PATCH 11/17] - added @OptionsMenu for RemoteRssFragment --- .../core/gui/remoterss/RemoteRssFragment.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java index 04102760..36dbc5c9 100644 --- a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java @@ -29,12 +29,15 @@ import org.androidannotations.annotations.Bean; import org.androidannotations.annotations.EFragment; import org.androidannotations.annotations.ItemClick; import org.androidannotations.annotations.ItemSelect; +import org.androidannotations.annotations.OptionsItem; +import org.androidannotations.annotations.OptionsMenu; import org.androidannotations.annotations.ViewById; import org.transdroid.R; import org.transdroid.core.gui.log.Log; import org.transdroid.core.gui.remoterss.data.RemoteRssChannel; import org.transdroid.core.gui.remoterss.data.RemoteRssItem; import org.transdroid.core.gui.rss.RssfeedsActivity; +import org.transdroid.core.gui.settings.MainSettingsActivity_; import java.util.ArrayList; import java.util.List; @@ -45,6 +48,7 @@ import java.util.List; * @author Twig */ @EFragment(R.layout.fragment_remoterss) +@OptionsMenu(R.menu.fragment_rssfeeds) public class RemoteRssFragment extends Fragment { @Bean protected Log log; @@ -62,7 +66,6 @@ public class RemoteRssFragment extends Fragment { @ViewById protected TextView remoterssStatusMessage; -// protected RemoteRssItemsAdapter adapter; @AfterViews protected void init() { @@ -84,9 +87,19 @@ public class RemoteRssFragment extends Fragment { super.onResume(); getRssActivity().onFragmentReady(this); + this.refreshScreen(); + } + + @OptionsItem(R.id.action_refresh) + protected void refreshScreen() { getRssActivity().refreshRemoteFeeds(); } + @OptionsItem(R.id.action_settings) + protected void openSettings() { + MainSettingsActivity_.intent(getActivity()).start(); + } + @Override public void onDestroy() { super.onDestroy(); From 4aca5e68063f813cd226900eb8ef9459e7480e54 Mon Sep 17 00:00:00 2001 From: Twig N Date: Wed, 22 Jan 2020 21:24:24 +1100 Subject: [PATCH 12/17] - made fragments work with inflated layouts to maintain w900 fragments layout - simplified PagerAdapter --- .../core/gui/rss/RssfeedsActivity.java | 43 +++++++------ .../res/layout-w900dp/activity_rssfeeds.xml | 61 +++++++++++++------ app/src/main/res/layout/activity_rssfeeds.xml | 35 ++++++++--- 3 files changed, 96 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java index abeb976d..6718e89f 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java @@ -22,16 +22,17 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Parcel; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.text.TextUtils; import android.view.View; +import android.view.ViewGroup; import com.nispok.snackbar.Snackbar; import com.nispok.snackbar.SnackbarManager; @@ -57,7 +58,6 @@ import org.transdroid.core.gui.lists.LocalTorrent; import org.transdroid.core.gui.log.Log; import org.transdroid.core.gui.navigation.NavigationHelper; import org.transdroid.core.gui.remoterss.RemoteRssFragment; -import org.transdroid.core.gui.remoterss.RemoteRssFragment_; import org.transdroid.core.gui.remoterss.data.RemoteRssChannel; import org.transdroid.core.gui.remoterss.data.RemoteRssItem; import org.transdroid.core.gui.remoterss.data.RemoteRssSupplier; @@ -112,38 +112,45 @@ public class RssfeedsActivity extends AppCompatActivity { protected ConnectivityHelper connectivityHelper; - class PagerAdapter extends FragmentPagerAdapter { - boolean hasRemoteRss = false; - String serverName = ""; + protected class LayoutPagerAdapter extends PagerAdapter { + boolean hasRemoteRss; + String serverName; - public PagerAdapter(FragmentManager fm, boolean hasRemoteRss, String name) { - super(fm); + public LayoutPagerAdapter(boolean hasRemoteRss, String name) { + super(); this.hasRemoteRss = hasRemoteRss; this.serverName = (name.length() > 0 ? name : getString(R.string.navigation_rss_tabs_remote)); } + @NonNull @Override - public Fragment getItem(int position) { - Fragment fragment = null; + public Object instantiateItem(@NonNull ViewGroup container, int position) { + int resId = 0; if (position == RSS_FEEDS_LOCAL) { - fragment = RssfeedsFragment_.builder().build(); + resId = R.id.layout_rssfeeds_local; } else if (position == RSS_FEEDS_REMOTE) { - fragment = RemoteRssFragment_.builder().build(); + resId = R.id.layout_rss_feeds_remote; } - return fragment; + return findViewById(resId); } @Override public int getCount() { - if (this.hasRemoteRss) { - return 2; - } + return (this.hasRemoteRss ? 2 : 1); + } + + @Override + public boolean isViewFromObject(@NonNull View view, @NonNull Object o) { + return (view == o); + } - return 1; + @Override + public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) { + container.removeView((View) object); } @Nullable @@ -178,7 +185,7 @@ public class RssfeedsActivity extends AppCompatActivity { IDaemonAdapter currentConnection = this.getCurrentConnection(); boolean hasRemoteRss = Daemon.supportsRemoteRssManagement(currentConnection.getType()); - PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager(), hasRemoteRss, currentConnection.getSettings().getName()); + PagerAdapter pagerAdapter = new LayoutPagerAdapter(hasRemoteRss, currentConnection.getSettings().getName()); viewPager.setAdapter(pagerAdapter); tabLayout.setupWithViewPager(viewPager); viewPager.setCurrentItem(0); diff --git a/app/src/main/res/layout-w900dp/activity_rssfeeds.xml b/app/src/main/res/layout-w900dp/activity_rssfeeds.xml index bd4390d3..f6a95675 100644 --- a/app/src/main/res/layout-w900dp/activity_rssfeeds.xml +++ b/app/src/main/res/layout-w900dp/activity_rssfeeds.xml @@ -32,28 +32,53 @@ style="@style/DefaultToolbarShadow" android:layout_below="@id/rssfeeds_toolbar" /> - - - + + + + + android:baselineAligned="false" + android:orientation="horizontal"> + + + + - - + android:baselineAligned="false" + android:orientation="horizontal"> + + + diff --git a/app/src/main/res/layout/activity_rssfeeds.xml b/app/src/main/res/layout/activity_rssfeeds.xml index 0d4fe9dd..0532da34 100644 --- a/app/src/main/res/layout/activity_rssfeeds.xml +++ b/app/src/main/res/layout/activity_rssfeeds.xml @@ -44,13 +44,34 @@ android:layout_width="match_parent" android:layout_height="wrap_content"/> - - - - - - - + + + + + + + From 0fc366ecc6d8895f7e02475139f3710a652856dc Mon Sep 17 00:00:00 2001 From: Twig N Date: Thu, 23 Jan 2020 20:38:45 +1100 Subject: [PATCH 13/17] - removed OptionsMenu from RemoteRssFragment since it duplicate them - restored use of @FragmentById - removed onFragmentReady() - removed onFragmentDestroy() --- .../core/gui/remoterss/RemoteRssFragment.java | 11 ---- .../core/gui/rss/RssfeedsActivity.java | 52 +++++-------------- .../core/gui/rss/RssfeedsFragment.java | 8 --- 3 files changed, 13 insertions(+), 58 deletions(-) diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java index 36dbc5c9..d742aa24 100644 --- a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java @@ -30,7 +30,6 @@ import org.androidannotations.annotations.EFragment; import org.androidannotations.annotations.ItemClick; import org.androidannotations.annotations.ItemSelect; import org.androidannotations.annotations.OptionsItem; -import org.androidannotations.annotations.OptionsMenu; import org.androidannotations.annotations.ViewById; import org.transdroid.R; import org.transdroid.core.gui.log.Log; @@ -48,7 +47,6 @@ import java.util.List; * @author Twig */ @EFragment(R.layout.fragment_remoterss) -@OptionsMenu(R.menu.fragment_rssfeeds) public class RemoteRssFragment extends Fragment { @Bean protected Log log; @@ -85,8 +83,6 @@ public class RemoteRssFragment extends Fragment { @Override public void onResume() { super.onResume(); - - getRssActivity().onFragmentReady(this); this.refreshScreen(); } @@ -100,13 +96,6 @@ public class RemoteRssFragment extends Fragment { MainSettingsActivity_.intent(getActivity()).start(); } - @Override - public void onDestroy() { - super.onDestroy(); - - getRssActivity().onFragmentDestroy(this); - } - /** * Updates the UI with a new list of RSS items. */ diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java index 6718e89f..9070f2e6 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java @@ -25,7 +25,6 @@ import android.os.Parcel; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.design.widget.TabLayout; -import android.support.v4.app.Fragment; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; @@ -85,12 +84,16 @@ public class RssfeedsActivity extends AppCompatActivity { @Bean protected ApplicationSettings applicationSettings; - // Contained feeds and items fragments - protected RssfeedsFragment fragmentLocalFeeds; - protected RemoteRssFragment fragmentRemoteFeeds; + protected static final int RSS_FEEDS_LOCAL = 0; + protected static final int RSS_FEEDS_REMOTE = 1; + @FragmentById(R.id.remoterss_fragment) + protected RemoteRssFragment fragmentRemoteFeeds; @FragmentById(R.id.rssitems_fragment) protected RssitemsFragment fragmentItems; + @FragmentById(R.id.rssfeeds_fragment) + protected RssfeedsFragment fragmentLocalFeeds; + @ViewById protected Toolbar rssfeedsToolbar; @ViewById(R.id.rssfeeds_tabs) @@ -98,9 +101,6 @@ public class RssfeedsActivity extends AppCompatActivity { @ViewById(R.id.rssfeeds_pager) protected ViewPager viewPager; - protected static final int RSS_FEEDS_LOCAL = 0; - protected static final int RSS_FEEDS_REMOTE = 1; - // remote RSS stuff @NonConfigurationInstance protected ArrayList feeds; @@ -195,24 +195,6 @@ public class RssfeedsActivity extends AppCompatActivity { } } - public void onFragmentReady(Fragment fragment) { - if (fragment instanceof RssfeedsFragment) { - fragmentLocalFeeds = (RssfeedsFragment) fragment; - } - else if (fragment instanceof RemoteRssFragment) { - fragmentRemoteFeeds = (RemoteRssFragment) fragment; - } - } - - public void onFragmentDestroy(Fragment fragment) { - if (fragment instanceof RssfeedsFragment) { - fragmentLocalFeeds = null; - } - else if (fragment instanceof RemoteRssFragment) { - fragmentRemoteFeeds = null; - } - } - @TargetApi(Build.VERSION_CODES.HONEYCOMB) @OptionsItem(android.R.id.home) protected void navigateUp() { @@ -232,9 +214,7 @@ public class RssfeedsActivity extends AppCompatActivity { loadRssfeed(loader); } - if (fragmentLocalFeeds != null) { - fragmentLocalFeeds.update(loaders); - } + fragmentLocalFeeds.update(loaders); } /** @@ -266,9 +246,7 @@ public class RssfeedsActivity extends AppCompatActivity { protected void handleRssfeedResult(RssfeedLoader loader, Channel channel, boolean hasError) { loader.update(channel, hasError); - if (fragmentLocalFeeds != null) { - fragmentLocalFeeds.notifyDataSetChanged(); - } + fragmentLocalFeeds.notifyDataSetChanged(); } /** @@ -373,11 +351,9 @@ public class RssfeedsActivity extends AppCompatActivity { } // @UIThread - if (fragmentRemoteFeeds != null) { - fragmentRemoteFeeds.updateRemoteItems( - selectedFilter == 0 ? recentItems : feeds.get(selectedFilter -1).getItems(), - false /* allow android to restore scroll position */ ); - } + fragmentRemoteFeeds.updateRemoteItems( + selectedFilter == 0 ? recentItems : feeds.get(selectedFilter -1).getItems(), + false /* allow android to restore scroll position */ ); showRemoteChannelFilters(); } @@ -446,8 +422,6 @@ public class RssfeedsActivity extends AppCompatActivity { }); feedLabels.addAll(feeds); - if (fragmentRemoteFeeds != null) { - fragmentRemoteFeeds.updateChannelFilters(feedLabels); - } + fragmentRemoteFeeds.updateChannelFilters(feedLabels); } } diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsFragment.java b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsFragment.java index 2ad23339..670059e9 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsFragment.java @@ -84,17 +84,9 @@ public class RssfeedsFragment extends Fragment { @Override public void onResume() { super.onResume(); - getRssActivity().onFragmentReady(this); this.refreshScreen(); } - @Override - public void onDestroy() { - super.onDestroy(); - - getRssActivity().onFragmentDestroy(this); - } - @OptionsItem(R.id.action_refresh) protected void refreshScreen() { getRssActivity().refreshFeeds(); From b6dea1cf58cceaa20b5dbde6df69991b50f68ede Mon Sep 17 00:00:00 2001 From: Twig N Date: Thu, 23 Jan 2020 20:56:18 +1100 Subject: [PATCH 14/17] - revert some stuff closer to master branch - adjust some comments - removed RemoteRssFragment.getRssActivity() --- .../core/gui/remoterss/RemoteRssFragment.java | 7 ++----- .../transdroid/core/gui/rss/RssfeedsActivity.java | 12 ++++++------ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java index d742aa24..6c14f567 100644 --- a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java @@ -76,10 +76,6 @@ public class RemoteRssFragment extends Fragment { torrentsList.setFastScrollEnabled(true); } - protected RssfeedsActivity getRssActivity() { - return (RssfeedsActivity) getActivity(); - } - @Override public void onResume() { super.onResume(); @@ -88,7 +84,8 @@ public class RemoteRssFragment extends Fragment { @OptionsItem(R.id.action_refresh) protected void refreshScreen() { - getRssActivity().refreshRemoteFeeds(); + RssfeedsActivity rssActivity = (RssfeedsActivity) getActivity(); + rssActivity.refreshRemoteFeeds(); } @OptionsItem(R.id.action_settings) diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java index 9070f2e6..6c6dda99 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java @@ -87,12 +87,12 @@ public class RssfeedsActivity extends AppCompatActivity { protected static final int RSS_FEEDS_LOCAL = 0; protected static final int RSS_FEEDS_REMOTE = 1; - @FragmentById(R.id.remoterss_fragment) - protected RemoteRssFragment fragmentRemoteFeeds; - @FragmentById(R.id.rssitems_fragment) - protected RssitemsFragment fragmentItems; @FragmentById(R.id.rssfeeds_fragment) protected RssfeedsFragment fragmentLocalFeeds; + @FragmentById(R.id.rssitems_fragment) + protected RssitemsFragment fragmentItems; + @FragmentById(R.id.remoterss_fragment) + protected RemoteRssFragment fragmentRemoteFeeds; @ViewById protected Toolbar rssfeedsToolbar; @@ -311,7 +311,7 @@ public class RssfeedsActivity extends AppCompatActivity { return lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this); } -// @Background + // @Background public void refreshRemoteFeeds() { // Connect to the last used server IDaemonAdapter currentConnection = this.getCurrentConnection(); @@ -350,7 +350,7 @@ public class RssfeedsActivity extends AppCompatActivity { return; } -// @UIThread + // @UIThread fragmentRemoteFeeds.updateRemoteItems( selectedFilter == 0 ? recentItems : feeds.get(selectedFilter -1).getItems(), false /* allow android to restore scroll position */ ); From 882a647370efa7e5b30c275c3e5d90f8587b89bf Mon Sep 17 00:00:00 2001 From: Twig N Date: Thu, 23 Jan 2020 21:17:32 +1100 Subject: [PATCH 15/17] - renamed classes and variables because of annoying squiggly green lines --- app/src/main/AndroidManifest.xml | 2 +- .../transdroid/core/gui/TorrentsActivity.java | 4 ++-- .../core/gui/remoterss/RemoteRssFragment.java | 24 +++++++++---------- ...edsActivity.java => RssFeedsActivity.java} | 12 +++++----- ...edsFragment.java => RssFeedsFragment.java} | 6 ++--- ...emsFragment.java => RssItemsFragment.java} | 24 +++++++++---------- .../core/gui/rss/RssitemsActivity.java | 2 +- .../core/service/RssCheckerJobRunner.java | 4 ++-- .../res/layout-w900dp/activity_rssfeeds.xml | 6 ++--- app/src/main/res/layout/activity_rssfeeds.xml | 4 ++-- 10 files changed, 44 insertions(+), 44 deletions(-) rename app/src/main/java/org/transdroid/core/gui/rss/{RssfeedsActivity.java => RssFeedsActivity.java} (98%) rename app/src/main/java/org/transdroid/core/gui/rss/{RssfeedsFragment.java => RssFeedsFragment.java} (95%) rename app/src/main/java/org/transdroid/core/gui/rss/{RssitemsFragment.java => RssItemsFragment.java} (93%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d25018f8..70016539 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -248,7 +248,7 @@ diff --git a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java index 3a2d8f82..147e81ea 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java @@ -82,7 +82,7 @@ import org.transdroid.core.gui.navigation.NavigationFilter; import org.transdroid.core.gui.navigation.NavigationHelper; import org.transdroid.core.gui.navigation.RefreshableActivity; import org.transdroid.core.gui.navigation.StatusType; -import org.transdroid.core.gui.rss.RssfeedsActivity_; +import org.transdroid.core.gui.rss.RssFeedsActivity_; import org.transdroid.core.gui.search.FilePickerHelper; import org.transdroid.core.gui.search.UrlEntryDialog; import org.transdroid.core.gui.settings.MainSettingsActivity_; @@ -809,7 +809,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @OptionsItem(R.id.action_rss) protected void openRss() { - RssfeedsActivity_.intent(this).start(); + RssFeedsActivity_.intent(this).start(); } @OptionsItem(R.id.action_settings) diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java index 6c14f567..43cb2e87 100644 --- a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java @@ -35,7 +35,7 @@ import org.transdroid.R; import org.transdroid.core.gui.log.Log; import org.transdroid.core.gui.remoterss.data.RemoteRssChannel; import org.transdroid.core.gui.remoterss.data.RemoteRssItem; -import org.transdroid.core.gui.rss.RssfeedsActivity; +import org.transdroid.core.gui.rss.RssFeedsActivity; import org.transdroid.core.gui.settings.MainSettingsActivity_; import java.util.ArrayList; @@ -57,12 +57,12 @@ public class RemoteRssFragment extends Fragment { // Views @ViewById protected View detailsContainer; - @ViewById - protected Spinner remoterssFilter; + @ViewById(R.id.remoterss_filter) + protected Spinner remoteRssFilter; @ViewById protected ListView torrentsList; - @ViewById - protected TextView remoterssStatusMessage; + @ViewById(R.id.remoterss_status_message) + protected TextView remoteRssStatusMessage; @AfterViews @@ -84,7 +84,7 @@ public class RemoteRssFragment extends Fragment { @OptionsItem(R.id.action_refresh) protected void refreshScreen() { - RssfeedsActivity rssActivity = (RssfeedsActivity) getActivity(); + RssFeedsActivity rssActivity = (RssFeedsActivity) getActivity(); rssActivity.refreshRemoteFeeds(); } @@ -107,11 +107,11 @@ public class RemoteRssFragment extends Fragment { } // Show/hide a nice message if there are no items to show if (remoteRssItems.size() > 0) { - remoterssStatusMessage.setVisibility(View.GONE); + remoteRssStatusMessage.setVisibility(View.GONE); } else { - remoterssStatusMessage.setVisibility(View.VISIBLE); - remoterssStatusMessage.setText(R.string.remoterss_no_files); + remoteRssStatusMessage.setVisibility(View.VISIBLE); + remoteRssStatusMessage.setText(R.string.remoterss_no_files); } } @@ -124,7 +124,7 @@ public class RemoteRssFragment extends Fragment { ArrayAdapter adapter = new ArrayAdapter<>(this.getContext(), android.R.layout.simple_spinner_dropdown_item, labels); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - remoterssFilter.setAdapter(adapter); + remoteRssFilter.setAdapter(adapter); } /** @@ -135,11 +135,11 @@ public class RemoteRssFragment extends Fragment { RemoteRssItemsAdapter adapter = (RemoteRssItemsAdapter) torrentsList.getAdapter(); RemoteRssItem item = (RemoteRssItem) adapter.getItem(position); - ((RssfeedsActivity) getActivity()).downloadRemoteRssItem(item); + ((RssFeedsActivity) getActivity()).downloadRemoteRssItem(item); } @ItemSelect(R.id.remoterss_filter) protected void onFeedSelected(boolean selected, int position) { - ((RssfeedsActivity) getActivity()).onFeedSelected(position); + ((RssFeedsActivity) getActivity()).onFeedSelected(position); } } diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java b/app/src/main/java/org/transdroid/core/gui/rss/RssFeedsActivity.java similarity index 98% rename from app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java rename to app/src/main/java/org/transdroid/core/gui/rss/RssFeedsActivity.java index 6c6dda99..5ef17616 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssFeedsActivity.java @@ -76,7 +76,7 @@ import java.util.Date; import java.util.List; @EActivity(R.layout.activity_rssfeeds) -public class RssfeedsActivity extends AppCompatActivity { +public class RssFeedsActivity extends AppCompatActivity { // Settings and local data @Bean @@ -88,14 +88,14 @@ public class RssfeedsActivity extends AppCompatActivity { protected static final int RSS_FEEDS_REMOTE = 1; @FragmentById(R.id.rssfeeds_fragment) - protected RssfeedsFragment fragmentLocalFeeds; + protected RssFeedsFragment fragmentLocalFeeds; @FragmentById(R.id.rssitems_fragment) - protected RssitemsFragment fragmentItems; + protected RssItemsFragment fragmentItems; @FragmentById(R.id.remoterss_fragment) protected RemoteRssFragment fragmentRemoteFeeds; - @ViewById - protected Toolbar rssfeedsToolbar; + @ViewById(R.id.rssfeeds_toolbar) + protected Toolbar rssFeedsToolbar; @ViewById(R.id.rssfeeds_tabs) protected TabLayout tabLayout; @ViewById(R.id.rssfeeds_pager) @@ -178,7 +178,7 @@ public class RssfeedsActivity extends AppCompatActivity { @AfterViews protected void init() { - setSupportActionBar(rssfeedsToolbar); + setSupportActionBar(rssFeedsToolbar); getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(getString(R.string.rss_feeds))); getSupportActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsFragment.java b/app/src/main/java/org/transdroid/core/gui/rss/RssFeedsFragment.java similarity index 95% rename from app/src/main/java/org/transdroid/core/gui/rss/RssfeedsFragment.java rename to app/src/main/java/org/transdroid/core/gui/rss/RssFeedsFragment.java index 670059e9..894bf4f0 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssFeedsFragment.java @@ -41,7 +41,7 @@ import java.util.List; */ @EFragment(R.layout.fragment_rssfeeds) @OptionsMenu(R.menu.fragment_rssfeeds) -public class RssfeedsFragment extends Fragment { +public class RssFeedsFragment extends Fragment { // Views @ViewById(R.id.rssfeeds_list) @@ -77,8 +77,8 @@ public class RssfeedsFragment extends Fragment { MainSettingsActivity_.intent(getActivity()).start(); } - protected RssfeedsActivity getRssActivity() { - return (RssfeedsActivity) getActivity(); + protected RssFeedsActivity getRssActivity() { + return (RssFeedsActivity) getActivity(); } @Override diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssitemsFragment.java b/app/src/main/java/org/transdroid/core/gui/rss/RssItemsFragment.java similarity index 93% rename from app/src/main/java/org/transdroid/core/gui/rss/RssitemsFragment.java rename to app/src/main/java/org/transdroid/core/gui/rss/RssItemsFragment.java index 31c5d7f1..e14c42cf 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssitemsFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssItemsFragment.java @@ -60,10 +60,10 @@ import java.util.List; * @author Eric Kok */ @EFragment(R.layout.fragment_rssitems) -public class RssitemsFragment extends Fragment { +public class RssItemsFragment extends Fragment { @InstanceState - protected Channel rssfeed = null; + protected Channel rssFeed = null; @InstanceState protected boolean hasError = false; @InstanceState @@ -74,7 +74,7 @@ public class RssitemsFragment extends Fragment { // Views @ViewById(R.id.rssitems_list) - protected ListView rssitemsList; + protected ListView rssItemsList; private MultiChoiceModeListener onItemsSelected = new MultiChoiceModeListener() { SelectionManagerMode selectionManagerMode; @@ -84,7 +84,7 @@ public class RssitemsFragment extends Fragment { // Show contextual action bar to add items in batch mode mode.getMenuInflater().inflate(R.menu.fragment_rssitems_cab, menu); Context themedContext = ((AppCompatActivity) getActivity()).getSupportActionBar().getThemedContext(); - selectionManagerMode = new SelectionManagerMode(themedContext, rssitemsList, R.plurals.rss_itemsselected); + selectionManagerMode = new SelectionManagerMode(themedContext, rssItemsList, R.plurals.rss_itemsselected); selectionManagerMode.onCreateActionMode(mode, menu); return true; } @@ -98,9 +98,9 @@ public class RssitemsFragment extends Fragment { // Get checked torrents List checked = new ArrayList<>(); - for (int i = 0; i < rssitemsList.getCheckedItemPositions().size(); i++) { - if (rssitemsList.getCheckedItemPositions().valueAt(i)) { - checked.add(rssitemsAdapter.getItem(rssitemsList.getCheckedItemPositions().keyAt(i))); + for (int i = 0; i < rssItemsList.getCheckedItemPositions().size(); i++) { + if (rssItemsList.getCheckedItemPositions().valueAt(i)) { + checked.add(rssitemsAdapter.getItem(rssItemsList.getCheckedItemPositions().keyAt(i))); } } @@ -189,9 +189,9 @@ public class RssitemsFragment extends Fragment { protected void init() { // Set up the list adapter, which allows multi-select - rssitemsList.setAdapter(rssitemsAdapter); - rssitemsList.setMultiChoiceModeListener(onItemsSelected); - update(rssfeed, hasError, requiresExternalAuthentication); + rssItemsList.setAdapter(rssitemsAdapter); + rssItemsList.setMultiChoiceModeListener(onItemsSelected); + update(rssFeed, hasError, requiresExternalAuthentication); } @@ -204,7 +204,7 @@ public class RssitemsFragment extends Fragment { public void update(Channel channel, boolean hasError, boolean requiresExternalAuthentication) { this.requiresExternalAuthentication = requiresExternalAuthentication; rssitemsAdapter.update(channel); - rssitemsList.setVisibility(View.GONE); + rssItemsList.setVisibility(View.GONE); emptyText.setVisibility(View.VISIBLE); if (hasError) { emptyText.setText(R.string.rss_error); @@ -218,7 +218,7 @@ public class RssitemsFragment extends Fragment { emptyText.setText(R.string.rss_empty); return; } - rssitemsList.setVisibility(View.VISIBLE); + rssItemsList.setVisibility(View.VISIBLE); emptyText.setVisibility(View.INVISIBLE); } diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssitemsActivity.java b/app/src/main/java/org/transdroid/core/gui/rss/RssitemsActivity.java index 742687fb..2211a9fa 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssitemsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssitemsActivity.java @@ -46,7 +46,7 @@ public class RssitemsActivity extends AppCompatActivity { protected boolean requiresExternalAuthentication; @FragmentById(R.id.rssitems_fragment) - protected RssitemsFragment fragmentItems; + protected RssItemsFragment fragmentItems; @ViewById protected Toolbar rssfeedsToolbar; diff --git a/app/src/main/java/org/transdroid/core/service/RssCheckerJobRunner.java b/app/src/main/java/org/transdroid/core/service/RssCheckerJobRunner.java index 1ecbea54..910c90da 100644 --- a/app/src/main/java/org/transdroid/core/service/RssCheckerJobRunner.java +++ b/app/src/main/java/org/transdroid/core/service/RssCheckerJobRunner.java @@ -33,7 +33,7 @@ import org.transdroid.core.app.settings.ApplicationSettings; import org.transdroid.core.app.settings.NotificationSettings; import org.transdroid.core.app.settings.RssfeedSetting; import org.transdroid.core.gui.log.Log; -import org.transdroid.core.gui.rss.RssfeedsActivity_; +import org.transdroid.core.gui.rss.RssFeedsActivity_; import org.transdroid.core.rssparser.Item; import org.transdroid.core.rssparser.RssParser; import org.transdroid.daemon.util.Collections2; @@ -121,7 +121,7 @@ public class RssCheckerJobRunner { // Provide a notification, since there are new RSS items PendingIntent pi = PendingIntent - .getActivity(context, 80000, new Intent(context, RssfeedsActivity_.class), PendingIntent.FLAG_UPDATE_CURRENT); + .getActivity(context, 80000, new Intent(context, RssFeedsActivity_.class), PendingIntent.FLAG_UPDATE_CURRENT); String title = context.getResources().getQuantityString(R.plurals.rss_service_new, unread, Integer.toString(unread)); String forString = Collections2.joinString(hasUnread, ", "); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context, NotificationChannels.CHANNEL_RSS_CHECKER) diff --git a/app/src/main/res/layout-w900dp/activity_rssfeeds.xml b/app/src/main/res/layout-w900dp/activity_rssfeeds.xml index f6a95675..997ccd2e 100644 --- a/app/src/main/res/layout-w900dp/activity_rssfeeds.xml +++ b/app/src/main/res/layout-w900dp/activity_rssfeeds.xml @@ -19,7 +19,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".core.gui.rss.RssfeedsActivity_"> + tools:context=".core.gui.rss.RssFeedsActivity_"> + tools:context=".core.gui.rss.RssFeedsActivity_"> Date: Thu, 23 Jan 2020 21:25:00 +1100 Subject: [PATCH 16/17] - forgot RssItemsFragment - renamed RssItemsActivity --- app/src/main/AndroidManifest.xml | 2 +- .../java/org/transdroid/core/gui/rss/RssFeedsActivity.java | 4 ++-- .../gui/rss/{RssitemsActivity.java => RssItemsActivity.java} | 2 +- app/src/main/res/layout/activity_rssitems.xml | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) rename app/src/main/java/org/transdroid/core/gui/rss/{RssitemsActivity.java => RssItemsActivity.java} (97%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 70016539..b1ec99be 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -253,7 +253,7 @@ android:launchMode="singleTop" android:theme="@style/TransdroidTheme" /> diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssFeedsActivity.java b/app/src/main/java/org/transdroid/core/gui/rss/RssFeedsActivity.java index 5ef17616..f37cb3b7 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssFeedsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssFeedsActivity.java @@ -250,7 +250,7 @@ public class RssFeedsActivity extends AppCompatActivity { } /** - * Opens an RSS feed in the dedicated fragment (if there was space in the UI) or a new {@link RssitemsActivity}. Optionally this also registers in + * Opens an RSS feed in the dedicated fragment (if there was space in the UI) or a new {@link RssItemsActivity}. Optionally this also registers in * the user preferences that the feed was now viewed, so that in the future the new items can be properly marked. * @param loader The RSS feed loader (with settings and the loaded content channel) to show * @param markAsViewedNow True if the user settings should be updated to reflect this feed's last viewed date; false otherwise @@ -300,7 +300,7 @@ public class RssFeedsActivity extends AppCompatActivity { if (TextUtils.isEmpty(name) && !TextUtils.isEmpty(loader.getSetting().getUrl())) { name = Uri.parse(loader.getSetting().getUrl()).getHost(); } - RssitemsActivity_.intent(this).rssfeed(loader.getChannel()).rssfeedName(name) + RssItemsActivity_.intent(this).rssfeed(loader.getChannel()).rssfeedName(name) .requiresExternalAuthentication(loader.getSetting().requiresExternalAuthentication()).start(); } diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssitemsActivity.java b/app/src/main/java/org/transdroid/core/gui/rss/RssItemsActivity.java similarity index 97% rename from app/src/main/java/org/transdroid/core/gui/rss/RssitemsActivity.java rename to app/src/main/java/org/transdroid/core/gui/rss/RssItemsActivity.java index 2211a9fa..ccbc673b 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssitemsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssItemsActivity.java @@ -36,7 +36,7 @@ import org.transdroid.core.gui.navigation.NavigationHelper; import org.transdroid.core.rssparser.Channel; @EActivity(R.layout.activity_rssitems) -public class RssitemsActivity extends AppCompatActivity { +public class RssItemsActivity extends AppCompatActivity { @Extra protected Channel rssfeed = null; diff --git a/app/src/main/res/layout/activity_rssitems.xml b/app/src/main/res/layout/activity_rssitems.xml index 15e62d88..1350234e 100644 --- a/app/src/main/res/layout/activity_rssitems.xml +++ b/app/src/main/res/layout/activity_rssitems.xml @@ -19,7 +19,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".core.gui.rss.RssitemsActivity_"> + tools:context=".core.gui.rss.RssItemsActivity_"> Date: Sun, 22 Mar 2020 20:07:55 +1100 Subject: [PATCH 17/17] - deleted RemoteRssActivity.java that was restored during conflict --- .../core/gui/remoterss/RemoteRssActivity.java | 253 ------------------ 1 file changed, 253 deletions(-) delete mode 100644 app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java deleted file mode 100644 index 7b390c15..00000000 --- a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright 2010-2018 Eric Kok et al. - * - * Transdroid is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Transdroid is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Transdroid. If not, see . - */ -package org.transdroid.core.gui.remoterss; - -import android.annotation.TargetApi; -import android.os.Build; -import android.os.Bundle; -import android.os.Parcel; -import android.support.v4.widget.DrawerLayout; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import android.widget.LinearLayout; -import android.widget.ListView; - -import com.nispok.snackbar.Snackbar; -import com.nispok.snackbar.SnackbarManager; -import com.nispok.snackbar.enums.SnackbarType; - -import org.androidannotations.annotations.AfterViews; -import org.androidannotations.annotations.Background; -import org.androidannotations.annotations.Bean; -import org.androidannotations.annotations.EActivity; -import org.androidannotations.annotations.FragmentById; -import org.androidannotations.annotations.InstanceState; -import org.androidannotations.annotations.ItemClick; -import org.androidannotations.annotations.NonConfigurationInstance; -import org.androidannotations.annotations.OptionsItem; -import org.androidannotations.annotations.UiThread; -import org.androidannotations.annotations.ViewById; -import org.transdroid.R; -import org.transdroid.core.app.settings.ApplicationSettings; -import org.transdroid.core.app.settings.ServerSetting; -import org.transdroid.core.app.settings.SettingsUtils; -import org.transdroid.core.gui.lists.LocalTorrent; -import org.transdroid.core.gui.lists.SimpleListItemAdapter; -import org.transdroid.core.gui.log.Log; -import org.transdroid.core.gui.navigation.RefreshableActivity; -import org.transdroid.core.gui.remoterss.data.RemoteRssChannel; -import org.transdroid.core.gui.remoterss.data.RemoteRssItem; -import org.transdroid.core.gui.remoterss.data.RemoteRssSupplier; -import org.transdroid.core.service.ConnectivityHelper; -import org.transdroid.daemon.DaemonException; -import org.transdroid.daemon.IDaemonAdapter; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.Comparator; -import java.util.Date; -import java.util.List; - -/** - * An activity that displays a list of {@link RemoteRssItem}s via an instance of {@link RemoteRssFragment}. - * The activity manages the drawer to filter items by the feed they came through. - * - * By default it displays the latest items within the last month. - * - * @author Twig Nguyen - */ -@EActivity(R.layout.activity_remoterss) -public class RemoteRssActivity extends AppCompatActivity implements RefreshableActivity { - @NonConfigurationInstance - protected ArrayList feeds; - - @InstanceState - protected int selectedFilter; - - @NonConfigurationInstance - protected ArrayList recentItems; - - // Server connection - @Bean - protected ApplicationSettings applicationSettings; - @Bean - protected Log log; - @Bean - protected ConnectivityHelper connectivityHelper; - private IDaemonAdapter currentConnection; - - // Details view components - @ViewById - protected DrawerLayout drawerLayout; - @ViewById - protected LinearLayout drawerContainer; - - @ViewById - protected Toolbar torrentsToolbar; - - @ViewById - protected ListView drawerList; - - @FragmentById(R.id.remoterss_fragment) - protected RemoteRssFragment fragmentRemoteRss; - - @Override - public void onCreate(Bundle savedInstanceState) { - SettingsUtils.applyDayNightTheme(this); - super.onCreate(savedInstanceState); - } - - @AfterViews - protected void init() { - // Simple action bar with up, torrent name as title and refresh button - torrentsToolbar.setNavigationIcon(R.drawable.ic_action_drawer); - setSupportActionBar(torrentsToolbar); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - - // Connect to the last used server - ServerSetting lastUsed = applicationSettings.getLastUsedServer(); - currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this); - - if (feeds != null) { - // Called from a configuration change. No need to load anything from server - showChannelFilters(); - fragmentRemoteRss.updateRemoteItems( - selectedFilter == 0 ? recentItems : feeds.get(selectedFilter - 1).getItems(), - false /* allow android to restore scroll position */ ); - } else { - loadFeeds(); - } - - } - - @Background - protected void loadFeeds() { - try { - fragmentRemoteRss.setRefreshing(true); - feeds = ((RemoteRssSupplier) (currentConnection)).getRemoteRssChannels(log); - fragmentRemoteRss.setRefreshing(false); - } catch (DaemonException e) { - onCommunicationError(e); - } - - recentItems = new ArrayList<>(); - Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.MONTH, -1); - Date oneMonthAgo = calendar.getTime(); - - for (RemoteRssChannel feed : feeds) { - for (RemoteRssItem item : feed.getItems()) { - if (item.getTimestamp().after(oneMonthAgo)) { - recentItems.add(item); - } - } - } - // Sort by -newest - Collections.sort(recentItems, new Comparator() { - @Override - public int compare(RemoteRssItem lhs, RemoteRssItem rhs) { - return rhs.getTimestamp().compareTo(lhs.getTimestamp()); - } - }); - - afterLoadFeeds(); - } - - @UiThread - protected void afterLoadFeeds() { - // We need to wrap these calls in a @UiThread rather than make them each a @UiThread themselves - // because they need to run sequentially in a configuration change scenario in order for Android - // to maintain scroll position on the fragment adapter. - showChannelFilters(); - onFeedSelected(selectedFilter); - } - - @UiThread - protected void onCommunicationError(DaemonException daemonException) { - //noinspection ThrowableResultOfMethodCallIgnored - log.i(this, daemonException.toString()); - String error = getString(LocalTorrent.getResourceForDaemonException(daemonException)); - SnackbarManager.show(Snackbar.with(this).text(error).colorResource(R.color.red).type(SnackbarType.MULTI_LINE)); - } - - - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - @OptionsItem(android.R.id.home) - protected void navigateUp() { - if (drawerLayout.isDrawerOpen(drawerContainer)) { - drawerLayout.closeDrawers(); - } else { - drawerLayout.openDrawer(drawerContainer); - } - } - - @Override - public void onBackPressed() { - if (drawerLayout.isDrawerOpen(drawerContainer)) { - drawerLayout.closeDrawers(); - } else { - finish(); - } - } - - private void showChannelFilters() { - List feedLabels = new ArrayList<>(feeds.size() +1); - feedLabels.add(new RemoteRssChannel() { - @Override - public String getName() { - return getString(R.string.remoterss_filter_allrecent); - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - } - }); - feedLabels.addAll(feeds); - - drawerList.setAdapter(new SimpleListItemAdapter(this, feedLabels)); - } - - @ItemClick(R.id.drawer_list) - protected void onFeedSelected(int position) { - selectedFilter = position; - fragmentRemoteRss.updateRemoteItems(position == 0 ? recentItems : feeds.get(position - 1).getItems(), true); - - RemoteRssChannel channel = (RemoteRssChannel) drawerList.getAdapter().getItem(position); - getSupportActionBar().setSubtitle(channel.getName()); - - drawerLayout.closeDrawers(); - } - - public IDaemonAdapter getCurrentConnection() { - return currentConnection; - } - - public RemoteRssChannel getChannel(String name) { - for (RemoteRssChannel feed : feeds) { - if (feed.getName().equals(name)) { - return feed; - } - } - return null; - } - - @Override - public void refreshScreen() { - loadFeeds(); - } -}