diff options
author | ByteHamster <info@bytehamster.com> | 2020-03-16 17:24:52 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2020-03-16 17:24:57 +0100 |
commit | be22ad1682ae4369a27fa3a1557cfe8e716df5d2 (patch) | |
tree | 74dd46b09d81fd68eee11bd0eade80282bf17fee | |
parent | 78b26fefb58ed5b7406909dcc8e8e5113e502424 (diff) | |
download | AntennaPod-be22ad1682ae4369a27fa3a1557cfe8e716df5d2.zip |
Added toolbar to online search fragments
8 files changed, 49 insertions, 50 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/CombinedSearchFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/CombinedSearchFragment.java index 47d7a0b86..256438c2b 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/CombinedSearchFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/CombinedSearchFragment.java @@ -2,6 +2,7 @@ package de.danoeh.antennapod.fragment; import android.content.Intent; import android.os.Bundle; +import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import androidx.core.view.MenuItemCompat; import androidx.appcompat.widget.SearchView; @@ -66,6 +67,7 @@ public class CombinedSearchFragment extends Fragment { Bundle savedInstanceState) { // Inflate the layout for this fragment View root = inflater.inflate(R.layout.fragment_itunes_search, container, false); + ((AppCompatActivity) getActivity()).setSupportActionBar(root.findViewById(R.id.toolbar)); gridView = root.findViewById(R.id.gridView); adapter = new ItunesAdapter(getActivity(), new ArrayList<>()); gridView.setAdapter(adapter); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FyydSearchFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FyydSearchFragment.java index aa26610aa..547bd6b24 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FyydSearchFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FyydSearchFragment.java @@ -2,6 +2,7 @@ package de.danoeh.antennapod.fragment; import android.content.Intent; import android.os.Bundle; +import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import androidx.core.view.MenuItemCompat; import androidx.appcompat.widget.SearchView; @@ -65,6 +66,7 @@ public class FyydSearchFragment extends Fragment { Bundle savedInstanceState) { // Inflate the layout for this fragment View root = inflater.inflate(R.layout.fragment_itunes_search, container, false); + ((AppCompatActivity) getActivity()).setSupportActionBar(root.findViewById(R.id.toolbar)); gridView = root.findViewById(R.id.gridView); adapter = new ItunesAdapter(getActivity(), new ArrayList<>()); gridView.setAdapter(adapter); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItunesSearchFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItunesSearchFragment.java index 4b1544e47..0e3caf2fe 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItunesSearchFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItunesSearchFragment.java @@ -3,6 +3,7 @@ package de.danoeh.antennapod.fragment; import android.content.Intent; import android.os.Bundle; import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import androidx.core.view.MenuItemCompat; import androidx.appcompat.widget.SearchView; @@ -93,6 +94,7 @@ public class ItunesSearchFragment extends Fragment { Bundle savedInstanceState) { // Inflate the layout for this fragment View root = inflater.inflate(R.layout.fragment_itunes_search, container, false); + ((AppCompatActivity) getActivity()).setSupportActionBar(root.findViewById(R.id.toolbar)); gridView = root.findViewById(R.id.gridView); adapter = new ItunesAdapter(getActivity(), new ArrayList<>()); gridView.setAdapter(adapter); @@ -172,7 +174,7 @@ public class ItunesSearchFragment extends Fragment { @Override public boolean onMenuItemActionCollapse(MenuItem item) { - if(searchResults != null) { + if (searchResults != null) { searchResults = null; updateData(topList); } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/GpodnetMainFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/GpodnetMainFragment.java index 380f6741a..e34f1ea1c 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/GpodnetMainFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/GpodnetMainFragment.java @@ -1,18 +1,17 @@ package de.danoeh.antennapod.fragment.gpodnet; -import android.content.Context; -import android.content.SharedPreferences; import android.content.res.Resources; import android.os.Bundle; -import com.google.android.material.tabs.TabLayout; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentPagerAdapter; import androidx.viewpager.widget.ViewPager; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - +import com.google.android.material.tabs.TabLayout; import de.danoeh.antennapod.R; /** @@ -20,49 +19,25 @@ import de.danoeh.antennapod.R; */ public class GpodnetMainFragment extends Fragment { - private static final String TAG = "GpodnetMainFragment"; - - private static final String PREF_LAST_TAB_POSITION = "tab_position"; - private TabLayout tabLayout; - private ViewPager viewPager; - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); View root = inflater.inflate(R.layout.pager_fragment, container, false); + Toolbar toolbar = root.findViewById(R.id.toolbar); + toolbar.setTitle(R.string.gpodnet_main_label); + ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar); - viewPager = root.findViewById(R.id.viewpager); + ViewPager viewPager = root.findViewById(R.id.viewpager); GpodnetPagerAdapter pagerAdapter = new GpodnetPagerAdapter(getChildFragmentManager(), getResources()); viewPager.setAdapter(pagerAdapter); // Give the TabLayout the ViewPager - tabLayout = root.findViewById(R.id.sliding_tabs); + TabLayout tabLayout = root.findViewById(R.id.sliding_tabs); tabLayout.setupWithViewPager(viewPager); return root; } - - @Override - public void onPause() { - super.onPause(); - // save our tab selection - SharedPreferences prefs = getActivity().getSharedPreferences(TAG, Context.MODE_PRIVATE); - SharedPreferences.Editor editor = prefs.edit(); - editor.putInt(PREF_LAST_TAB_POSITION, tabLayout.getSelectedTabPosition()); - editor.apply(); - } - - @Override - public void onStart() { - super.onStart(); - - // restore our last position - SharedPreferences prefs = getActivity().getSharedPreferences(TAG, Context.MODE_PRIVATE); - int lastPosition = prefs.getInt(PREF_LAST_TAB_POSITION, 0); - viewPager.setCurrentItem(lastPosition); - } - public class GpodnetPagerAdapter extends FragmentPagerAdapter { @@ -80,13 +55,19 @@ public class GpodnetMainFragment extends Fragment { @Override public Fragment getItem(int i) { + Bundle arguments = new Bundle(); + arguments.putBoolean(PodcastListFragment.ARGUMENT_HIDE_TOOLBAR, true); switch (i) { case POS_TAGS: return new TagListFragment(); case POS_TOPLIST: - return new PodcastTopListFragment(); + PodcastListFragment topListFragment = new PodcastTopListFragment(); + topListFragment.setArguments(arguments); + return topListFragment; case POS_SUGGESTIONS: - return new SuggestionListFragment(); + PodcastListFragment suggestionsFragment = new SuggestionListFragment(); + suggestionsFragment.setArguments(arguments); + return suggestionsFragment; default: return null; } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/PodcastListFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/PodcastListFragment.java index 4baa74df6..3fca43938 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/PodcastListFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/PodcastListFragment.java @@ -4,6 +4,8 @@ import android.content.Context; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; import androidx.core.view.MenuItemCompat; import androidx.appcompat.widget.SearchView; @@ -34,7 +36,7 @@ import de.danoeh.antennapod.menuhandler.MenuItemUtils; * Displays a list of GPodnetPodcast-Objects in a GridView */ public abstract class PodcastListFragment extends Fragment { - + public static final String ARGUMENT_HIDE_TOOLBAR = "hideToolbar"; private static final String TAG = "PodcastListFragment"; private GridView gridView; @@ -76,6 +78,13 @@ public abstract class PodcastListFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.gpodnet_podcast_list, container, false); + Toolbar toolbar = root.findViewById(R.id.toolbar); + if (getArguments() == null || !getArguments().getBoolean(ARGUMENT_HIDE_TOOLBAR, false)) { + toolbar.setTitle(R.string.gpodnet_main_label); + ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar); + } else { + toolbar.setVisibility(View.GONE); + } gridView = root.findViewById(R.id.gridView); progressBar = root.findViewById(R.id.progressBar); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagListFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagListFragment.java index cde8fb3df..a8b6c2976 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagListFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagListFragment.java @@ -24,8 +24,6 @@ import de.danoeh.antennapod.core.gpoddernet.model.GpodnetTag; import de.danoeh.antennapod.menuhandler.MenuItemUtils; public class TagListFragment extends ListFragment { - - private static final String TAG = "TagListFragment"; private static final int COUNT = 50; @Override @@ -73,12 +71,6 @@ public class TagListFragment extends ListFragment { } @Override - public void onResume() { - super.onResume(); - ((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.add_feed_label); - } - - @Override public void onDestroyView() { super.onDestroyView(); cancelLoadTask(); diff --git a/app/src/main/res/layout/gpodnet_podcast_list.xml b/app/src/main/res/layout/gpodnet_podcast_list.xml index d8b06e4f7..ae0a400f1 100644 --- a/app/src/main/res/layout/gpodnet_podcast_list.xml +++ b/app/src/main/res/layout/gpodnet_podcast_list.xml @@ -1,10 +1,19 @@ <?xml version="1.0" encoding="utf-8"?> - -<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" +<RelativeLayout + xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" + xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> + <androidx.appcompat.widget.Toolbar + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:minHeight="?attr/actionBarSize" + android:theme="?attr/actionBarTheme" + app:navigationIcon="?homeAsUpIndicator" + android:id="@+id/toolbar"/> + <GridView android:id="@+id/gridView" android:layout_width="match_parent" @@ -18,6 +27,7 @@ android:paddingTop="@dimen/list_vertical_padding" android:stretchMode="columnWidth" android:verticalSpacing="8dp" + android:layout_below="@id/toolbar" tools:listitem="@layout/gpodnet_podcast_listitem" /> <ProgressBar diff --git a/app/src/main/res/layout/pager_fragment.xml b/app/src/main/res/layout/pager_fragment.xml index 03ae023d2..6a642caae 100644 --- a/app/src/main/res/layout/pager_fragment.xml +++ b/app/src/main/res/layout/pager_fragment.xml @@ -11,6 +11,7 @@ android:layout_height="wrap_content" android:minHeight="?attr/actionBarSize" android:theme="?attr/actionBarTheme" + app:navigationIcon="?homeAsUpIndicator" android:id="@+id/toolbar"/> <com.google.android.material.tabs.TabLayout |