Browse Source

- replaced the navigation drawer filter with an ugly spinner

- filters work again
pull/526/head
Twig N 5 years ago
parent
commit
ff3a289914
  1. 70
      app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java
  2. 42
      app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java
  3. 16
      app/src/main/res/layout/fragment_remoterss.xml

70
app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java

@ -18,32 +18,23 @@ package org.transdroid.core.gui.remoterss; @@ -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 { @@ -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 { @@ -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 { @@ -120,44 +100,22 @@ public class RemoteRssFragment extends Fragment {
}
}
public void updateChannelFilters(List<RemoteRssChannel> 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);
}
}

42
app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java

@ -21,6 +21,7 @@ import android.content.Intent; @@ -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 { @@ -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 { @@ -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 { @@ -387,4 +384,21 @@ public class RssfeedsActivity extends AppCompatActivity {
.type(SnackbarType.MULTI_LINE)
);
}
private void showRemoteChannelFilters() {
List<RemoteRssChannel> 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);
}
}

16
app/src/main/res/layout/fragment_remoterss.xml

@ -15,10 +15,18 @@ @@ -15,10 +15,18 @@
You should have received a copy of the GNU General Public License
along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">
<Spinner
android:id="@+id/remoterss_filter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dialog" />
<TextView
android:layout_width="match_parent"
@ -33,5 +41,5 @@ @@ -33,5 +41,5 @@
android:layout_height="match_parent"
android:clipToPadding="false"
tools:listitem="@layout/list_item_remoterssitem"
tools:visibility="visible"/>
</FrameLayout>
tools:visibility="visible" />
</LinearLayout>

Loading…
Cancel
Save