diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java index 62fd4b515..e49fc8db7 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -1,7 +1,6 @@ package de.danoeh.antennapod.activity; import android.annotation.TargetApi; -import android.app.ProgressDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -11,18 +10,7 @@ import android.database.DataSetObserver; import android.os.Build; import android.os.Bundle; import android.os.Handler; -import androidx.annotation.NonNull; -import androidx.annotation.VisibleForTesting; -import com.google.android.material.snackbar.Snackbar; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentManager; -import androidx.fragment.app.FragmentTransaction; -import androidx.drawerlayout.widget.DrawerLayout; -import androidx.appcompat.app.ActionBarDrawerToggle; -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.widget.Toolbar; import android.util.Log; -import android.util.TypedValue; import android.view.ContextMenu; import android.view.Menu; import android.view.MenuInflater; @@ -31,25 +19,23 @@ import android.view.View; import android.widget.AdapterView; import android.widget.ListView; import android.widget.Toast; - +import androidx.annotation.NonNull; +import androidx.appcompat.app.ActionBarDrawerToggle; +import androidx.appcompat.app.AlertDialog; +import androidx.drawerlayout.widget.DrawerLayout; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentTransaction; import com.bumptech.glide.Glide; - -import de.danoeh.antennapod.core.event.FeedListUpdateEvent; -import de.danoeh.antennapod.core.event.UnreadItemsUpdateEvent; -import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.Validate; -import org.greenrobot.eventbus.EventBus; -import org.greenrobot.eventbus.Subscribe; -import org.greenrobot.eventbus.ThreadMode; - -import java.util.List; - +import com.google.android.material.snackbar.Snackbar; import de.danoeh.antennapod.R; import de.danoeh.antennapod.adapter.NavListAdapter; import de.danoeh.antennapod.core.asynctask.FeedRemover; import de.danoeh.antennapod.core.dialog.ConfirmationDialog; +import de.danoeh.antennapod.core.event.FeedListUpdateEvent; import de.danoeh.antennapod.core.event.MessageEvent; import de.danoeh.antennapod.core.event.QueueEvent; +import de.danoeh.antennapod.core.event.UnreadItemsUpdateEvent; import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.preferences.PlaybackPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences; @@ -77,6 +63,13 @@ import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.Validate; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +import java.util.List; /** * The activity that is shown when the user launches the app. @@ -96,7 +89,6 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi private static final String EXTRA_FEED_ID = "fragment_feed_id"; private static final String SAVE_BACKSTACK_COUNT = "backstackCount"; - private static final String SAVE_TITLE = "title"; public static final String[] NAV_DRAWER_TAGS = { QueueFragment.TAG, @@ -108,15 +100,11 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi NavListAdapter.SUBSCRIPTION_LIST_TAG }; - private Toolbar toolbar; - private ExternalPlayerFragment externalPlayerFragment; private DrawerLayout drawerLayout; private View navDrawer; - private ListView navList; private NavListAdapter navAdapter; private int mPosition = -1; private ActionBarDrawerToggle drawerToggle; - private CharSequence currentTitle; private Disposable disposable; private long lastBackButtonPressTime = 0; @@ -135,20 +123,8 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi StorageUtils.checkStorageAvailability(this); setContentView(R.layout.main); - toolbar = findViewById(R.id.toolbar); - setSupportActionBar(toolbar); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - findViewById(R.id.shadow).setVisibility(View.GONE); - int elevation = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, - getResources().getDisplayMetrics()); - getSupportActionBar().setElevation(elevation); - } - - currentTitle = getTitle(); - drawerLayout = findViewById(R.id.drawer_layout); - navList = findViewById(R.id.nav_list); + ListView navList = findViewById(R.id.nav_list); navDrawer = findViewById(R.id.nav_layout); drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close); @@ -162,9 +138,6 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi fm.addOnBackStackChangedListener(() -> drawerToggle.setDrawerIndicatorEnabled(fm.getBackStackEntryCount() == 0)); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setHomeButtonEnabled(true); - navAdapter = new NavListAdapter(itemAccess, this); navList.setAdapter(navAdapter); navList.setOnItemClickListener(navListClickListener); @@ -203,7 +176,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi } } } - externalPlayerFragment = new ExternalPlayerFragment(); + ExternalPlayerFragment externalPlayerFragment = new ExternalPlayerFragment(); transaction.replace(R.id.playerFragment, externalPlayerFragment, ExternalPlayerFragment.TAG); transaction.commit(); @@ -315,8 +288,6 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi args = null; break; } - currentTitle = navAdapter.getLabel(tag); - getSupportActionBar().setTitle(currentTitle); saveLastNavFragment(tag); if (args != null) { fragment.setArguments(args); @@ -338,8 +309,6 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi fragment.setArguments(args); } saveLastNavFragment(String.valueOf(feedId)); - currentTitle = ""; - getSupportActionBar().setTitle(currentTitle); loadFragment(fragment); } @@ -452,10 +421,6 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi super.onPostCreate(savedInstanceState); drawerToggle.syncState(); if (savedInstanceState != null) { - currentTitle = savedInstanceState.getString(SAVE_TITLE); - if (!drawerLayout.isDrawerOpen(navDrawer)) { - getSupportActionBar().setTitle(currentTitle); - } selectedNavListIndex = getSelectedNavListIndex(); } } @@ -469,7 +434,6 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - outState.putString(SAVE_TITLE, getSupportActionBar().getTitle().toString()); outState.putInt(SAVE_BACKSTACK_COUNT, getSupportFragmentManager().getBackStackEntryCount()); } diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/EpisodesApplyActionFragment.java b/app/src/main/java/de/danoeh/antennapod/dialog/EpisodesApplyActionFragment.java index cbba1637f..9514ea5eb 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/EpisodesApplyActionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/EpisodesApplyActionFragment.java @@ -13,26 +13,17 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ListView; - import androidx.annotation.IdRes; import androidx.annotation.NonNull; import androidx.annotation.PluralsRes; import androidx.annotation.StringRes; -import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import androidx.collection.ArrayMap; import androidx.core.app.ActivityCompat; import androidx.fragment.app.Fragment; - import com.google.android.material.snackbar.Snackbar; import com.leinardi.android.speeddial.SpeedDialView; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; - import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator; import de.danoeh.antennapod.core.feed.FeedItem; @@ -43,6 +34,12 @@ import de.danoeh.antennapod.core.util.FeedItemPermutors; import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.core.util.SortOrder; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; + public class EpisodesApplyActionFragment extends Fragment { public static final String TAG = "EpisodeActionFragment"; @@ -55,6 +52,7 @@ public class EpisodesApplyActionFragment extends Fragment { public static final int ACTION_DELETE = 32; private static final int ACTION_ALL = ACTION_ADD_TO_QUEUE | ACTION_REMOVE_FROM_QUEUE | ACTION_MARK_PLAYED | ACTION_MARK_UNPLAYED | ACTION_DOWNLOAD | ACTION_DELETE; + private Toolbar toolbar; /** * Specify an action (defined by #flag) 's UI bindings. @@ -76,20 +74,15 @@ public class EpisodesApplyActionFragment extends Fragment { } private final List actionBindings; - - private ListView mListView; - private ArrayAdapter mAdapter; - - private SpeedDialView mSpeedDialView; - @NonNull - private CharSequence actionBarTitleOriginal = ""; - - private final Map idMap = new ArrayMap<>(); + private final Map idMap = new ArrayMap<>(); private final List episodes = new ArrayList<>(); private int actions; private final List titles = new ArrayList<>(); private final LongList checkedIds = new LongList(); + private ListView mListView; + private ArrayAdapter mAdapter; + private SpeedDialView mSpeedDialView; private MenuItem mSelectToggle; public EpisodesApplyActionFragment() { @@ -137,7 +130,7 @@ public class EpisodesApplyActionFragment extends Fragment { mListView = view.findViewById(android.R.id.list); mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); - mListView.setOnItemClickListener((ListView, view1, position, rowId) -> { + mListView.setOnItemClickListener((listView, view1, position, rowId) -> { long id = episodes.get(position).getId(); if (checkedIds.contains(id)) { checkedIds.remove(id); @@ -177,8 +170,8 @@ public class EpisodesApplyActionFragment extends Fragment { mAdapter = new ArrayAdapter<>(getActivity(), R.layout.simple_list_item_multiple_choice_on_start, titles); mListView.setAdapter(mAdapter); - - saveActionBarTitle(); // needed when we dynamically change the title based on selection + toolbar = view.findViewById(R.id.toolbar); + ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar); // Init action UI (via a FAB Speed Dial) mSpeedDialView = view.findViewById(R.id.fabSD); @@ -206,18 +199,10 @@ public class EpisodesApplyActionFragment extends Fragment { } return true; }); - - showSpeedDialIfAnyChecked(); - + refreshCheckboxes(); return view; } - @Override - public void onStop() { - restoreActionBarTitle(); // it might have been changed to "N selected". Restore original. - super.onStop(); - } - private void showSpeedDialIfAnyChecked() { if (checkedIds.size() > 0) { if (!mSpeedDialView.isShown()) { @@ -327,7 +312,7 @@ public class EpisodesApplyActionFragment extends Fragment { return true; } } - if(resId != 0) { + if (resId != 0) { Snackbar.make(getActivity().findViewById(R.id.content), resId, Snackbar.LENGTH_SHORT) .show(); return true; @@ -345,7 +330,7 @@ public class EpisodesApplyActionFragment extends Fragment { private void checkAll() { for (FeedItem episode : episodes) { - if(!checkedIds.contains(episode.getId())) { + if (!checkedIds.contains(episode.getId())) { checkedIds.add(episode.getId()); } } @@ -359,12 +344,12 @@ public class EpisodesApplyActionFragment extends Fragment { private void checkPlayed(boolean isPlayed) { for (FeedItem episode : episodes) { - if(episode.isPlayed() == isPlayed) { - if(!checkedIds.contains(episode.getId())) { + if (episode.isPlayed() == isPlayed) { + if (!checkedIds.contains(episode.getId())) { checkedIds.add(episode.getId()); } } else { - if(checkedIds.contains(episode.getId())) { + if (checkedIds.contains(episode.getId())) { checkedIds.remove(episode.getId()); } } @@ -374,12 +359,12 @@ public class EpisodesApplyActionFragment extends Fragment { private void checkDownloaded(boolean isDownloaded) { for (FeedItem episode : episodes) { - if(episode.hasMedia() && episode.getMedia().isDownloaded() == isDownloaded) { - if(!checkedIds.contains(episode.getId())) { + if (episode.hasMedia() && episode.getMedia().isDownloaded() == isDownloaded) { + if (!checkedIds.contains(episode.getId())) { checkedIds.add(episode.getId()); } } else { - if(checkedIds.contains(episode.getId())) { + if (checkedIds.contains(episode.getId())) { checkedIds.remove(episode.getId()); } } @@ -389,7 +374,7 @@ public class EpisodesApplyActionFragment extends Fragment { private void checkQueued(boolean isQueued) { for (FeedItem episode : episodes) { - if(episode.isTagged(FeedItem.TAG_QUEUE) == isQueued) { + if (episode.isTagged(FeedItem.TAG_QUEUE) == isQueued) { checkedIds.add(episode.getId()); } else { checkedIds.remove(episode.getId()); @@ -400,7 +385,7 @@ public class EpisodesApplyActionFragment extends Fragment { private void checkWithMedia() { for (FeedItem episode : episodes) { - if(episode.hasMedia()) { + if (episode.hasMedia()) { checkedIds.add(episode.getId()); } else { checkedIds.remove(episode.getId()); @@ -425,35 +410,7 @@ public class EpisodesApplyActionFragment extends Fragment { } ActivityCompat.invalidateOptionsMenu(EpisodesApplyActionFragment.this.getActivity()); showSpeedDialIfAnyChecked(); - updateActionBarTitle(); - } - - private void saveActionBarTitle() { - ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); - if (actionBar != null) { - CharSequence title = actionBar.getTitle(); - if (title == null) { - title = ""; - } - actionBarTitleOriginal = title; - } - } - - private void restoreActionBarTitle() { - ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); - if (actionBar != null) { - actionBar.setTitle(actionBarTitleOriginal); - } - } - - private void updateActionBarTitle() { - ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); - if (actionBar != null) { - CharSequence title = checkedIds.size() > 0 ? - getString(R.string.num_selected_label, checkedIds.size()) : - actionBarTitleOriginal; - actionBar.setTitle(title); - } + toolbar.setTitle(getString(R.string.num_selected_label, checkedIds.size())); } private void queueChecked() { @@ -487,7 +444,7 @@ public class EpisodesApplyActionFragment extends Fragment { // download the check episodes in the same order as they are currently displayed List toDownload = new ArrayList<>(checkedIds.size()); for (FeedItem episode : episodes) { - if(checkedIds.contains(episode.getId()) && episode.hasMedia()) { + if (checkedIds.contains(episode.getId()) && episode.hasMedia()) { toDownload.add(episode); } } @@ -503,7 +460,7 @@ public class EpisodesApplyActionFragment extends Fragment { private void deleteChecked() { for (long id : checkedIds.toArray()) { FeedItem episode = idMap.get(id); - if(episode.hasMedia()) { + if (episode.hasMedia()) { DBWriter.deleteFeedMediaOfItem(getActivity(), episode.getMedia().getId()); } } @@ -516,7 +473,7 @@ public class EpisodesApplyActionFragment extends Fragment { getResources().getQuantityString(msgId, numItems, numItems), Snackbar.LENGTH_LONG ) - .setAction(android.R.string.ok, v -> {}) + .setAction(android.R.string.ok, v -> { }) .show(); } getActivity().getSupportFragmentManager().popBackStack(); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java index 343cf76ab..7cdcce36f 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java @@ -6,6 +6,7 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.util.Log; +import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import android.view.ContextMenu; import android.view.LayoutInflater; @@ -41,9 +42,8 @@ public class AddFeedFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); View root = inflater.inflate(R.layout.addfeed, container, false); - activity = (MainActivity) getActivity(); - activity.getSupportActionBar().setTitle(R.string.add_feed_label); + ((AppCompatActivity) getActivity()).setSupportActionBar(root.findViewById(R.id.toolbar)); setupAdvancedSearchButtons(root); setupSeachBox(root); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/DownloadsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/DownloadsFragment.java index b1bcdf404..6f537be96 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/DownloadsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/DownloadsFragment.java @@ -4,6 +4,8 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; import android.os.Bundle; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import com.google.android.material.tabs.TabLayout; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -37,6 +39,9 @@ public class DownloadsFragment extends Fragment { 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.downloads_label); + ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar); viewPager = root.findViewById(R.id.viewpager); DownloadsPagerAdapter pagerAdapter = new DownloadsPagerAdapter(getChildFragmentManager(), getResources()); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java index 49398d104..275496f24 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java @@ -2,20 +2,18 @@ package de.danoeh.antennapod.fragment; import android.content.Context; import android.content.SharedPreferences; -import android.content.res.Resources; import android.os.Bundle; -import androidx.annotation.NonNull; -import com.google.android.material.tabs.TabLayout; -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 androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentPagerAdapter; +import androidx.viewpager.widget.ViewPager; +import com.google.android.material.tabs.TabLayout; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.activity.MainActivity; public class EpisodesFragment extends Fragment { @@ -38,22 +36,21 @@ public class EpisodesFragment extends Fragment { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); + setHasOptionsMenu(true); } - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); - setHasOptionsMenu(true); - ((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.episodes_label); - View rootView = inflater.inflate(R.layout.pager_fragment, container, false); + Toolbar toolbar = rootView.findViewById(R.id.toolbar); + toolbar.setTitle(R.string.episodes_label); + ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar); viewPager = rootView.findViewById(R.id.viewpager); viewPager.setAdapter(new EpisodesPagerAdapter()); // Give the TabLayout the ViewPager tabLayout = rootView.findViewById(R.id.sliding_tabs); tabLayout.setupWithViewPager(viewPager); - return rootView; } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedInfoFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedInfoFragment.java index 3949172bb..af3c5d303 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedInfoFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedInfoFragment.java @@ -8,6 +8,8 @@ import android.net.Uri; import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; import android.text.TextUtils; import android.util.Log; @@ -22,6 +24,9 @@ import android.widget.TextView; import android.widget.Toast; import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; +import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; +import com.google.android.material.snackbar.Snackbar; import com.joanzapata.iconify.Iconify; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; @@ -33,8 +38,10 @@ import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DownloadRequestException; import de.danoeh.antennapod.core.util.IntentUtils; import de.danoeh.antennapod.core.util.LangUtils; +import de.danoeh.antennapod.core.util.ThemeUtils; import de.danoeh.antennapod.core.util.syndication.HtmlToPlainText; import de.danoeh.antennapod.menuhandler.FeedMenuHandler; +import de.danoeh.antennapod.view.ToolbarIconTintManager; import io.reactivex.Maybe; import io.reactivex.MaybeOnSubscribe; import io.reactivex.android.schedulers.AndroidSchedulers; @@ -64,6 +71,8 @@ public class FeedInfoFragment extends Fragment { private TextView txtvUrl; private TextView txtvAuthorHeader; private ImageView imgvBackground; + private Menu optionsMenu; + private ToolbarIconTintManager iconTintManager; public static FeedInfoFragment newInstance(Feed feed) { FeedInfoFragment fragment = new FeedInfoFragment(); @@ -82,23 +91,33 @@ public class FeedInfoFragment extends Fragment { android.content.ClipboardManager cm = (android.content.ClipboardManager) getContext() .getSystemService(Context.CLIPBOARD_SERVICE); cm.setPrimaryClip(clipData); - Toast t = Toast.makeText(getContext(), R.string.copied_url_msg, Toast.LENGTH_SHORT); - t.show(); + Snackbar.make(getView(), R.string.copied_url_msg, Snackbar.LENGTH_SHORT).show(); } } }; - @Override - public void onResume() { - super.onResume(); - ((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.feed_info_label); - } - @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View root = inflater.inflate(R.layout.feedinfo, null); + Toolbar toolbar = root.findViewById(R.id.toolbar); + toolbar.setTitle(""); + ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar); + AppBarLayout appBar = root.findViewById(R.id.appBar); + CollapsingToolbarLayout collapsingToolbar = root.findViewById(R.id.collapsing_toolbar); + iconTintManager = new ToolbarIconTintManager(getContext(), toolbar, collapsingToolbar) { + @Override + protected void doTint(Context themedContext) { + if (optionsMenu == null) { + return; + } + optionsMenu.findItem(R.id.visit_website_item) + .setIcon(ThemeUtils.getDrawableFromAttr(themedContext, R.attr.location_web_site)); + } + }; + appBar.addOnOffsetChangedListener(iconTintManager); + setHasOptionsMenu(true); imgvCover = root.findViewById(R.id.imgvCover); @@ -110,7 +129,6 @@ public class FeedInfoFragment extends Fragment { // https://github.com/bumptech/glide/issues/529 imgvBackground.setColorFilter(new LightingColorFilter(0xff828282, 0x000000)); - txtvDescription = root.findViewById(R.id.txtvDescription); lblLanguage = root.findViewById(R.id.lblLanguage); txtvLanguage = root.findViewById(R.id.txtvLanguage); @@ -201,6 +219,8 @@ public class FeedInfoFragment extends Fragment { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.feedinfo, menu); + optionsMenu = menu; + iconTintManager.updateTint(); } @Override diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java index b9afa6d57..dd9fe7bc4 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java @@ -1,6 +1,5 @@ package de.danoeh.antennapod.fragment; -import android.annotation.SuppressLint; import android.content.Context; import android.content.DialogInterface; import android.graphics.LightingColorFilter; @@ -12,31 +11,26 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.ListView; +import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.TextView; - import android.widget.Toast; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.SearchView; +import androidx.appcompat.widget.Toolbar; import androidx.core.view.MenuItemCompat; -import androidx.fragment.app.ListFragment; - +import androidx.fragment.app.Fragment; import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; import com.joanzapata.iconify.Iconify; import com.joanzapata.iconify.widget.IconTextView; - -import org.apache.commons.lang3.Validate; -import org.greenrobot.eventbus.EventBus; -import org.greenrobot.eventbus.Subscribe; -import org.greenrobot.eventbus.ThreadMode; - -import java.util.List; - import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.adapter.FeedItemlistAdapter; @@ -46,28 +40,23 @@ import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator; import de.danoeh.antennapod.core.event.DownloadEvent; import de.danoeh.antennapod.core.event.DownloaderUpdate; import de.danoeh.antennapod.core.event.FeedItemEvent; - import de.danoeh.antennapod.core.event.FeedListUpdateEvent; import de.danoeh.antennapod.core.event.PlaybackPositionEvent; import de.danoeh.antennapod.core.event.PlayerStatusEvent; import de.danoeh.antennapod.core.event.UnreadItemsUpdateEvent; - import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedEvent; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedItemFilter; -import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.glide.FastBlurTransformation; import de.danoeh.antennapod.core.service.download.DownloadService; -import de.danoeh.antennapod.core.service.download.Downloader; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.DownloadRequestException; import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.util.FeedItemPermutors; import de.danoeh.antennapod.core.util.FeedItemUtil; -import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.core.util.Optional; import de.danoeh.antennapod.core.util.gui.MoreContentListFooterUtil; import de.danoeh.antennapod.dialog.EpisodesApplyActionFragment; @@ -79,12 +68,17 @@ import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; +import org.apache.commons.lang3.Validate; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +import java.util.List; /** * Displays a list of FeedItems. */ -@SuppressLint("ValidFragment") -public class FeedItemlistFragment extends ListFragment { +public class FeedItemlistFragment extends Fragment implements AdapterView.OnItemClickListener { private static final String TAG = "ItemlistFragment"; private static final String ARGUMENT_FEED_ID = "argument.de.danoeh.antennapod.feed_id"; @@ -102,6 +96,8 @@ public class FeedItemlistFragment extends ListFragment { private ImageView imgvBackground; private ImageView imgvCover; private TextView txtvInformation; + private ListView listView; + private ProgressBar progressBar; private Disposable disposable; @@ -131,22 +127,23 @@ public class FeedItemlistFragment extends ListFragment { feedID = args.getLong(ARGUMENT_FEED_ID); } + @Nullable @Override - public void onHiddenChanged(boolean hidden) { - super.onHiddenChanged(hidden); - if (!hidden && getActivity() != null) { - ((MainActivity) getActivity()).getSupportActionBar().setTitle(""); - } - } + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { + View root = inflater.inflate(R.layout.feed_item_list_fragment, container, false); + Toolbar toolbar = root.findViewById(R.id.toolbar); + toolbar.setTitle(""); + ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar); - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - registerForContextMenu(getListView()); + listView = root.findViewById(android.R.id.list); + listView.setOnItemClickListener(this); + registerForContextMenu(listView); + progressBar = root.findViewById(R.id.progLoading); EventBus.getDefault().register(this); loadItems(); + return root; } @Override @@ -320,21 +317,20 @@ public class FeedItemlistFragment extends ListFragment { } @Override - public void onListItemClick(ListView l, View v, int position, long id) { - if(adapter == null) { + public void onItemClick(AdapterView parent, View view, int position, long id) { + if (adapter == null) { return; } - position -= l.getHeaderViewsCount(); + position -= listView.getHeaderViewsCount(); MainActivity activity = (MainActivity) getActivity(); long[] ids = FeedItemUtil.getIds(feed.getItems()); activity.loadChildFragment(ItemPagerFragment.newInstance(ids, position)); - activity.getSupportActionBar().setTitle(feed.getTitle()); } @Subscribe public void onEvent(FeedEvent event) { Log.d(TAG, "onEvent() called with: " + "event = [" + event + "]"); - if(event.feedId == feedID) { + if (event.feedId == feedID) { loadItems(); } } @@ -342,12 +338,12 @@ public class FeedItemlistFragment extends ListFragment { @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(FeedItemEvent event) { Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]"); - if(feed == null || feed.getItems() == null || adapter == null) { + if (feed == null || feed.getItems() == null || adapter == null) { return; } - for(FeedItem item : event.items) { + for (FeedItem item : event.items) { int pos = FeedItemUtil.indexOfItemWithId(feed.getItems(), item.getId()); - if(pos >= 0) { + if (pos >= 0) { loadItems(); return; } @@ -369,7 +365,7 @@ public class FeedItemlistFragment extends ListFragment { @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(PlaybackPositionEvent event) { if (adapter != null) { - adapter.notifyCurrentlyPlayingItemChanged(event, getListView()); + adapter.notifyCurrentlyPlayingItemChanged(event, listView); } } @@ -412,39 +408,40 @@ public class FeedItemlistFragment extends ListFragment { return; } if (adapter == null) { - setListAdapter(null); + listView.setAdapter(null); setupHeaderView(); setupFooterView(); adapter = new FeedItemlistAdapter((MainActivity) getActivity(), itemAccess, false, true); - setListAdapter(adapter); + listView.setAdapter(adapter); } refreshHeaderView(); - setListShown(true); + listView.setVisibility(View.VISIBLE); + progressBar.setVisibility(View.GONE); adapter.notifyDataSetChanged(); getActivity().supportInvalidateOptionsMenu(); if (feed != null && feed.getNextPageLink() == null && listFooter != null) { - getListView().removeFooterView(listFooter.getRoot()); + listView.removeFooterView(listFooter.getRoot()); } } private void refreshHeaderView() { - if (getListView() == null || feed == null || !headerCreated) { + if (listView == null || feed == null || !headerCreated) { Log.e(TAG, "Unable to refresh header view"); return; } loadFeedImage(); - if(feed.hasLastUpdateFailed()) { + if (feed.hasLastUpdateFailed()) { txtvFailure.setVisibility(View.VISIBLE); } else { txtvFailure.setVisibility(View.GONE); } txtvTitle.setText(feed.getTitle()); - if(feed.getItemFilter() != null) { + if (feed.getItemFilter() != null) { FeedItemFilter filter = feed.getItemFilter(); - if(filter.getValues().length > 0) { - if(feed.hasLastUpdateFailed()) { + if (filter.getValues().length > 0) { + if (feed.hasLastUpdateFailed()) { RelativeLayout.LayoutParams p = (RelativeLayout.LayoutParams) txtvInformation.getLayoutParams(); p.addRule(RelativeLayout.BELOW, R.id.txtvFailure); } @@ -460,15 +457,14 @@ public class FeedItemlistFragment extends ListFragment { } private void setupHeaderView() { - if (getListView() == null || feed == null) { + if (listView == null || feed == null) { Log.e(TAG, "Unable to setup listview: recyclerView = null or feed = null"); return; } - ListView lv = getListView(); LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); - View header = inflater.inflate(R.layout.feeditemlist_header, lv, false); - lv.addHeaderView(header); + View header = inflater.inflate(R.layout.feeditemlist_header, listView, false); + listView.addHeaderView(header); txtvTitle = header.findViewById(R.id.txtvTitle); TextView txtvAuthor = header.findViewById(R.id.txtvAuthor); @@ -482,7 +478,6 @@ public class FeedItemlistFragment extends ListFragment { txtvTitle.setText(feed.getTitle()); txtvAuthor.setText(feed.getAuthor()); - // https://github.com/bumptech/glide/issues/529 imgvBackground.setColorFilter(new LightingColorFilter(0xff828282, 0x000000)); @@ -530,16 +525,15 @@ public class FeedItemlistFragment extends ListFragment { private void setupFooterView() { - if (getListView() == null || feed == null) { + if (listView == null || feed == null) { Log.e(TAG, "Unable to setup listview: recyclerView = null or feed = null"); return; } if (feed.isPaged() && feed.getNextPageLink() != null) { - ListView lv = getListView(); LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); - View header = inflater.inflate(R.layout.more_content_list_footer, lv, false); - lv.addFooterView(header); + View header = inflater.inflate(R.layout.more_content_list_footer, listView, false); + listView.addFooterView(header); listFooter = new MoreContentListFooterUtil(header); listFooter.setClickListener(() -> { if (feed != null) { @@ -573,7 +567,7 @@ public class FeedItemlistFragment extends ListFragment { }; private void loadItems() { - if(disposable != null) { + if (disposable != null) { disposable.dispose(); } disposable = Observable.fromCallable(this::loadData) @@ -600,5 +594,4 @@ public class FeedItemlistFragment extends ListFragment { } return Optional.ofNullable(feed); } - } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java index 8ff71e114..cf09c5b26 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java @@ -4,11 +4,18 @@ import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; import androidx.preference.ListPreference; import androidx.preference.PreferenceFragmentCompat; import androidx.preference.SwitchPreference; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.core.dialog.ConfirmationDialog; import de.danoeh.antennapod.core.event.settings.SpeedPresetChangedEvent; import de.danoeh.antennapod.core.event.settings.VolumeAdaptionChangedEvent; @@ -34,17 +41,11 @@ import java.util.Locale; import static de.danoeh.antennapod.core.feed.FeedPreferences.SPEED_USE_GLOBAL; -public class FeedSettingsFragment extends PreferenceFragmentCompat { - private static final CharSequence PREF_EPISODE_FILTER = "episodeFilter"; - private static final String PREF_FEED_PLAYBACK_SPEED = "feedPlaybackSpeed"; - private static final DecimalFormat SPEED_FORMAT = - new DecimalFormat("0.00", DecimalFormatSymbols.getInstance(Locale.US)); - private static final String EXTRA_FEED_ID = "de.danoeh.antennapod.extra.feedId"; +public class FeedSettingsFragment extends Fragment { private static final String TAG = "FeedSettingsFragment"; + private static final String EXTRA_FEED_ID = "de.danoeh.antennapod.extra.feedId"; - private Feed feed; private Disposable disposable; - private FeedPreferences feedPreferences; public static FeedSettingsFragment newInstance(Feed feed) { FeedSettingsFragment fragment = new FeedSettingsFragment(); @@ -54,13 +55,20 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat { return fragment; } + @Nullable @Override - public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { - addPreferencesFromResource(R.xml.feed_settings); - - setupAutoDownloadGlobalPreference(); // To prevent transition animation because of summary update - + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View root = inflater.inflate(R.layout.feedsettings, container, false); long feedId = getArguments().getLong(EXTRA_FEED_ID); + + Toolbar toolbar = root.findViewById(R.id.toolbar); + ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar); + + getFragmentManager().beginTransaction() + .replace(R.id.settings_fragment_container, + FeedSettingsPreferenceFragment.newInstance(feedId), "settings_fragment") + .commitAllowingStateLoss(); + disposable = Maybe.create((MaybeOnSubscribe) emitter -> { Feed feed = DBReader.getFeed(feedId); if (feed != null) { @@ -71,39 +79,12 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat { }) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(result -> { - feed = result; - feedPreferences = feed.getPreferences(); - ((MainActivity) getActivity()).getSupportActionBar().setSubtitle(feed.getTitle()); + .subscribe(result -> toolbar.setSubtitle(result.getTitle()), + error -> Log.d(TAG, Log.getStackTraceString(error)), + () -> { }); - setupAutoDownloadPreference(); - setupKeepUpdatedPreference(); - setupAutoDeletePreference(); - setupVolumeReductionPreferences(); - setupAuthentificationPreference(); - setupEpisodeFilterPreference(); - setupPlaybackSpeedPreference(); - updateAutoDeleteSummary(); - updateVolumeReductionValue(); - updateAutoDownloadEnabled(); - updatePlaybackSpeedPreference(); - }, error -> Log.d(TAG, Log.getStackTraceString(error)), () -> { }); - } - - @Override - public void onResume() { - super.onResume(); - ((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.feed_settings_label); - if (feed != null) { - ((MainActivity) getActivity()).getSupportActionBar().setSubtitle(feed.getTitle()); - } - } - - @Override - public void onStop() { - super.onStop(); - ((MainActivity) getActivity()).getSupportActionBar().setSubtitle(null); + return root; } @Override @@ -114,212 +95,275 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat { } } - private void setupPlaybackSpeedPreference() { - ListPreference feedPlaybackSpeedPreference = findPreference(PREF_FEED_PLAYBACK_SPEED); + public static class FeedSettingsPreferenceFragment extends PreferenceFragmentCompat { + private static final CharSequence PREF_EPISODE_FILTER = "episodeFilter"; + private static final String PREF_FEED_PLAYBACK_SPEED = "feedPlaybackSpeed"; + private static final DecimalFormat SPEED_FORMAT = + new DecimalFormat("0.00", DecimalFormatSymbols.getInstance(Locale.US)); - final String[] speeds = getResources().getStringArray(R.array.playback_speed_values); - String[] values = new String[speeds.length + 1]; - values[0] = SPEED_FORMAT.format(SPEED_USE_GLOBAL); + private Feed feed; + private Disposable disposable; + private FeedPreferences feedPreferences; - String[] entries = new String[speeds.length + 1]; - entries[0] = getString(R.string.feed_auto_download_global); - - System.arraycopy(speeds, 0, values, 1, speeds.length); - System.arraycopy(speeds, 0, entries, 1, speeds.length); - - feedPlaybackSpeedPreference.setEntryValues(values); - feedPlaybackSpeedPreference.setEntries(entries); - feedPlaybackSpeedPreference.setOnPreferenceChangeListener((preference, newValue) -> { - feedPreferences.setFeedPlaybackSpeed(Float.parseFloat((String) newValue)); - feed.savePreferences(); - updatePlaybackSpeedPreference(); - EventBus.getDefault().post( - new SpeedPresetChangedEvent(feedPreferences.getFeedPlaybackSpeed(), feed.getId())); - return false; - }); - } - - private void setupEpisodeFilterPreference() { - findPreference(PREF_EPISODE_FILTER).setOnPreferenceClickListener(preference -> { - new EpisodeFilterDialog(getContext(), feedPreferences.getFilter()) { - @Override - protected void onConfirmed(FeedFilter filter) { - feedPreferences.setFilter(filter); - feed.savePreferences(); - } - }.show(); - return false; - }); - } - - private void setupAuthentificationPreference() { - findPreference("authentication").setOnPreferenceClickListener(preference -> { - new AuthenticationDialog(getContext(), - R.string.authentication_label, true, false, - feedPreferences.getUsername(), feedPreferences.getPassword()) { - @Override - protected void onConfirmed(String username, String password, boolean saveUsernamePassword) { - feedPreferences.setUsername(username); - feedPreferences.setPassword(password); - feed.savePreferences(); - } - }.show(); - return false; - }); - } - - private void setupAutoDeletePreference() { - ListPreference autoDeletePreference = (ListPreference) findPreference("autoDelete"); - autoDeletePreference.setOnPreferenceChangeListener((preference, newValue) -> { - switch ((String) newValue) { - case "global": - feedPreferences.setAutoDeleteAction(FeedPreferences.AutoDeleteAction.GLOBAL); - break; - case "always": - feedPreferences.setAutoDeleteAction(FeedPreferences.AutoDeleteAction.YES); - break; - case "never": - feedPreferences.setAutoDeleteAction(FeedPreferences.AutoDeleteAction.NO); - break; - } - feed.savePreferences(); - updateAutoDeleteSummary(); - return false; - }); - } - - private void updatePlaybackSpeedPreference() { - ListPreference feedPlaybackSpeedPreference = findPreference(PREF_FEED_PLAYBACK_SPEED); - - float speedValue = feedPreferences.getFeedPlaybackSpeed(); - feedPlaybackSpeedPreference.setValue(SPEED_FORMAT.format(speedValue)); - } - - private void updateAutoDeleteSummary() { - ListPreference autoDeletePreference = findPreference("autoDelete"); - - switch (feedPreferences.getAutoDeleteAction()) { - case GLOBAL: - autoDeletePreference.setSummary(R.string.feed_auto_download_global); - autoDeletePreference.setValue("global"); - break; - case YES: - autoDeletePreference.setSummary(R.string.feed_auto_download_always); - autoDeletePreference.setValue("always"); - break; - case NO: - autoDeletePreference.setSummary(R.string.feed_auto_download_never); - autoDeletePreference.setValue("never"); - break; - } - } - - private void setupVolumeReductionPreferences() { - ListPreference volumeReductionPreference = (ListPreference) findPreference("volumeReduction"); - volumeReductionPreference.setOnPreferenceChangeListener((preference, newValue) -> { - switch ((String) newValue) { - case "off": - feedPreferences.setVolumeAdaptionSetting(VolumeAdaptionSetting.OFF); - break; - case "light": - feedPreferences.setVolumeAdaptionSetting(VolumeAdaptionSetting.LIGHT_REDUCTION); - break; - case "heavy": - feedPreferences.setVolumeAdaptionSetting(VolumeAdaptionSetting.HEAVY_REDUCTION); - break; - } - feed.savePreferences(); - updateVolumeReductionValue(); - EventBus.getDefault().post( - new VolumeAdaptionChangedEvent(feedPreferences.getVolumeAdaptionSetting(), feed.getId())); - return false; - }); - } - - private void updateVolumeReductionValue() { - ListPreference volumeReductionPreference = (ListPreference) findPreference("volumeReduction"); - - switch (feedPreferences.getVolumeAdaptionSetting()) { - case OFF: - volumeReductionPreference.setValue("off"); - break; - case LIGHT_REDUCTION: - volumeReductionPreference.setValue("light"); - break; - case HEAVY_REDUCTION: - volumeReductionPreference.setValue("heavy"); - break; - } - } - - private void setupKeepUpdatedPreference() { - SwitchPreference pref = (SwitchPreference) findPreference("keepUpdated"); - - pref.setChecked(feedPreferences.getKeepUpdated()); - pref.setOnPreferenceChangeListener((preference, newValue) -> { - boolean checked = newValue == Boolean.TRUE; - feedPreferences.setKeepUpdated(checked); - feed.savePreferences(); - pref.setChecked(checked); - return false; - }); - } - - private void setupAutoDownloadGlobalPreference() { - if (!UserPreferences.isEnableAutodownload()) { - SwitchPreference autodl = findPreference("autoDownload"); - autodl.setChecked(false); - autodl.setEnabled(false); - autodl.setSummary(R.string.auto_download_disabled_globally); - findPreference(PREF_EPISODE_FILTER).setEnabled(false); - } - } - - private void setupAutoDownloadPreference() { - SwitchPreference pref = (SwitchPreference) findPreference("autoDownload"); - - pref.setEnabled(UserPreferences.isEnableAutodownload()); - if (UserPreferences.isEnableAutodownload()) { - pref.setChecked(feedPreferences.getAutoDownload()); - } else { - pref.setChecked(false); - pref.setSummary(R.string.auto_download_disabled_globally); - } - - pref.setOnPreferenceChangeListener((preference, newValue) -> { - boolean checked = newValue == Boolean.TRUE; - - feedPreferences.setAutoDownload(checked); - feed.savePreferences(); - updateAutoDownloadEnabled(); - ApplyToEpisodesDialog dialog = new ApplyToEpisodesDialog(getActivity(), checked); - dialog.createNewDialog().show(); - pref.setChecked(checked); - return false; - }); - } - - private void updateAutoDownloadEnabled() { - if (feed != null && feed.getPreferences() != null) { - boolean enabled = feed.getPreferences().getAutoDownload() && UserPreferences.isEnableAutodownload(); - findPreference(PREF_EPISODE_FILTER).setEnabled(enabled); - } - } - - private class ApplyToEpisodesDialog extends ConfirmationDialog { - private final boolean autoDownload; - - ApplyToEpisodesDialog(Context context, boolean autoDownload) { - super(context, R.string.auto_download_apply_to_items_title, - R.string.auto_download_apply_to_items_message); - this.autoDownload = autoDownload; - setPositiveText(R.string.yes); - setNegativeText(R.string.no); + public static FeedSettingsPreferenceFragment newInstance(long feedId) { + FeedSettingsPreferenceFragment fragment = new FeedSettingsPreferenceFragment(); + Bundle arguments = new Bundle(); + arguments.putLong(EXTRA_FEED_ID, feedId); + fragment.setArguments(arguments); + return fragment; } @Override - public void onConfirmButtonPressed(DialogInterface dialog) { - DBWriter.setFeedsItemsAutoDownload(feed, autoDownload); + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + addPreferencesFromResource(R.xml.feed_settings); + + setupAutoDownloadGlobalPreference(); // To prevent transition animation because of summary update + + long feedId = getArguments().getLong(EXTRA_FEED_ID); + disposable = Maybe.create((MaybeOnSubscribe) emitter -> { + Feed feed = DBReader.getFeed(feedId); + if (feed != null) { + emitter.onSuccess(feed); + } else { + emitter.onComplete(); + } + }) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(result -> { + feed = result; + feedPreferences = feed.getPreferences(); + + setupAutoDownloadPreference(); + setupKeepUpdatedPreference(); + setupAutoDeletePreference(); + setupVolumeReductionPreferences(); + setupAuthentificationPreference(); + setupEpisodeFilterPreference(); + setupPlaybackSpeedPreference(); + + updateAutoDeleteSummary(); + updateVolumeReductionValue(); + updateAutoDownloadEnabled(); + updatePlaybackSpeedPreference(); + }, error -> Log.d(TAG, Log.getStackTraceString(error)), () -> { }); + } + + @Override + public void onDestroy() { + super.onDestroy(); + if (disposable != null) { + disposable.dispose(); + } + } + + private void setupPlaybackSpeedPreference() { + ListPreference feedPlaybackSpeedPreference = findPreference(PREF_FEED_PLAYBACK_SPEED); + + final String[] speeds = getResources().getStringArray(R.array.playback_speed_values); + String[] values = new String[speeds.length + 1]; + values[0] = SPEED_FORMAT.format(SPEED_USE_GLOBAL); + + String[] entries = new String[speeds.length + 1]; + entries[0] = getString(R.string.feed_auto_download_global); + + System.arraycopy(speeds, 0, values, 1, speeds.length); + System.arraycopy(speeds, 0, entries, 1, speeds.length); + + feedPlaybackSpeedPreference.setEntryValues(values); + feedPlaybackSpeedPreference.setEntries(entries); + feedPlaybackSpeedPreference.setOnPreferenceChangeListener((preference, newValue) -> { + feedPreferences.setFeedPlaybackSpeed(Float.parseFloat((String) newValue)); + feed.savePreferences(); + updatePlaybackSpeedPreference(); + EventBus.getDefault().post( + new SpeedPresetChangedEvent(feedPreferences.getFeedPlaybackSpeed(), feed.getId())); + return false; + }); + } + + private void setupEpisodeFilterPreference() { + findPreference(PREF_EPISODE_FILTER).setOnPreferenceClickListener(preference -> { + new EpisodeFilterDialog(getContext(), feedPreferences.getFilter()) { + @Override + protected void onConfirmed(FeedFilter filter) { + feedPreferences.setFilter(filter); + feed.savePreferences(); + } + }.show(); + return false; + }); + } + + private void setupAuthentificationPreference() { + findPreference("authentication").setOnPreferenceClickListener(preference -> { + new AuthenticationDialog(getContext(), + R.string.authentication_label, true, false, + feedPreferences.getUsername(), feedPreferences.getPassword()) { + @Override + protected void onConfirmed(String username, String password, boolean saveUsernamePassword) { + feedPreferences.setUsername(username); + feedPreferences.setPassword(password); + feed.savePreferences(); + } + }.show(); + return false; + }); + } + + private void setupAutoDeletePreference() { + ListPreference autoDeletePreference = findPreference("autoDelete"); + autoDeletePreference.setOnPreferenceChangeListener((preference, newValue) -> { + switch ((String) newValue) { + case "global": + feedPreferences.setAutoDeleteAction(FeedPreferences.AutoDeleteAction.GLOBAL); + break; + case "always": + feedPreferences.setAutoDeleteAction(FeedPreferences.AutoDeleteAction.YES); + break; + case "never": + feedPreferences.setAutoDeleteAction(FeedPreferences.AutoDeleteAction.NO); + break; + } + feed.savePreferences(); + updateAutoDeleteSummary(); + return false; + }); + } + + private void updatePlaybackSpeedPreference() { + ListPreference feedPlaybackSpeedPreference = findPreference(PREF_FEED_PLAYBACK_SPEED); + + float speedValue = feedPreferences.getFeedPlaybackSpeed(); + feedPlaybackSpeedPreference.setValue(SPEED_FORMAT.format(speedValue)); + } + + private void updateAutoDeleteSummary() { + ListPreference autoDeletePreference = findPreference("autoDelete"); + + switch (feedPreferences.getAutoDeleteAction()) { + case GLOBAL: + autoDeletePreference.setSummary(R.string.feed_auto_download_global); + autoDeletePreference.setValue("global"); + break; + case YES: + autoDeletePreference.setSummary(R.string.feed_auto_download_always); + autoDeletePreference.setValue("always"); + break; + case NO: + autoDeletePreference.setSummary(R.string.feed_auto_download_never); + autoDeletePreference.setValue("never"); + break; + } + } + + private void setupVolumeReductionPreferences() { + ListPreference volumeReductionPreference = findPreference("volumeReduction"); + volumeReductionPreference.setOnPreferenceChangeListener((preference, newValue) -> { + switch ((String) newValue) { + case "off": + feedPreferences.setVolumeAdaptionSetting(VolumeAdaptionSetting.OFF); + break; + case "light": + feedPreferences.setVolumeAdaptionSetting(VolumeAdaptionSetting.LIGHT_REDUCTION); + break; + case "heavy": + feedPreferences.setVolumeAdaptionSetting(VolumeAdaptionSetting.HEAVY_REDUCTION); + break; + } + feed.savePreferences(); + updateVolumeReductionValue(); + EventBus.getDefault().post( + new VolumeAdaptionChangedEvent(feedPreferences.getVolumeAdaptionSetting(), feed.getId())); + return false; + }); + } + + private void updateVolumeReductionValue() { + ListPreference volumeReductionPreference = findPreference("volumeReduction"); + + switch (feedPreferences.getVolumeAdaptionSetting()) { + case OFF: + volumeReductionPreference.setValue("off"); + break; + case LIGHT_REDUCTION: + volumeReductionPreference.setValue("light"); + break; + case HEAVY_REDUCTION: + volumeReductionPreference.setValue("heavy"); + break; + } + } + + private void setupKeepUpdatedPreference() { + SwitchPreference pref = findPreference("keepUpdated"); + + pref.setChecked(feedPreferences.getKeepUpdated()); + pref.setOnPreferenceChangeListener((preference, newValue) -> { + boolean checked = newValue == Boolean.TRUE; + feedPreferences.setKeepUpdated(checked); + feed.savePreferences(); + pref.setChecked(checked); + return false; + }); + } + + private void setupAutoDownloadGlobalPreference() { + if (!UserPreferences.isEnableAutodownload()) { + SwitchPreference autodl = findPreference("autoDownload"); + autodl.setChecked(false); + autodl.setEnabled(false); + autodl.setSummary(R.string.auto_download_disabled_globally); + findPreference(PREF_EPISODE_FILTER).setEnabled(false); + } + } + + private void setupAutoDownloadPreference() { + SwitchPreference pref = findPreference("autoDownload"); + + pref.setEnabled(UserPreferences.isEnableAutodownload()); + if (UserPreferences.isEnableAutodownload()) { + pref.setChecked(feedPreferences.getAutoDownload()); + } else { + pref.setChecked(false); + pref.setSummary(R.string.auto_download_disabled_globally); + } + + pref.setOnPreferenceChangeListener((preference, newValue) -> { + boolean checked = newValue == Boolean.TRUE; + + feedPreferences.setAutoDownload(checked); + feed.savePreferences(); + updateAutoDownloadEnabled(); + ApplyToEpisodesDialog dialog = new ApplyToEpisodesDialog(getActivity(), checked); + dialog.createNewDialog().show(); + pref.setChecked(checked); + return false; + }); + } + + private void updateAutoDownloadEnabled() { + if (feed != null && feed.getPreferences() != null) { + boolean enabled = feed.getPreferences().getAutoDownload() && UserPreferences.isEnableAutodownload(); + findPreference(PREF_EPISODE_FILTER).setEnabled(enabled); + } + } + + private class ApplyToEpisodesDialog extends ConfirmationDialog { + private final boolean autoDownload; + + ApplyToEpisodesDialog(Context context, boolean autoDownload) { + super(context, R.string.auto_download_apply_to_items_title, + R.string.auto_download_apply_to_items_message); + this.autoDownload = autoDownload; + setPositiveText(R.string.yes); + setNegativeText(R.string.no); + } + + @Override + public void onConfirmButtonPressed(DialogInterface dialog) { + DBWriter.setFeedsItemsAutoDownload(feed, autoDownload); + } } } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemPagerFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemPagerFragment.java index 51d1c7ba9..f251de5ec 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemPagerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemPagerFragment.java @@ -9,6 +9,8 @@ import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import androidx.core.view.ViewCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentStatePagerAdapter; @@ -77,6 +79,9 @@ public class ItemPagerFragment extends Fragment { @Nullable Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); View layout = inflater.inflate(R.layout.feeditem_pager_fragment, container, false); + Toolbar toolbar = layout.findViewById(R.id.toolbar); + toolbar.setTitle(""); + ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar); feedItems = getArguments().getLongArray(ARG_FEEDITEMS); int feedItemPos = getArguments().getInt(ARG_FEEDITEM_POS); @@ -145,15 +150,12 @@ public class ItemPagerFragment extends Fragment { ((CastEnabledActivity) getActivity()).requestCastButton(MenuItem.SHOW_AS_ACTION_ALWAYS); } inflater.inflate(R.menu.feeditem_options, menu); - - if (menu != null && item != null) { - if (item.hasMedia()) { - FeedItemMenuHandler.onPrepareMenu(menu, item); - } else { - // these are already available via button1 and button2 - FeedItemMenuHandler.onPrepareMenu(menu, item, - R.id.mark_read_item, R.id.visit_website_item); - } + if (item.hasMedia()) { + FeedItemMenuHandler.onPrepareMenu(menu, item); + } else { + // these are already available via button1 and button2 + FeedItemMenuHandler.onPrepareMenu(menu, item, + R.id.mark_read_item, R.id.visit_website_item); } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java index 923a6325c..f57b83bb8 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java @@ -2,50 +2,50 @@ package de.danoeh.antennapod.fragment; import android.content.res.TypedArray; import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.fragment.app.ListFragment; -import androidx.core.view.MenuItemCompat; import android.util.Log; +import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.ListView; - +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.view.MenuItemCompat; +import androidx.fragment.app.Fragment; +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.activity.MainActivity; +import de.danoeh.antennapod.adapter.FeedItemlistAdapter; +import de.danoeh.antennapod.core.event.DownloadEvent; +import de.danoeh.antennapod.core.event.FeedItemEvent; import de.danoeh.antennapod.core.event.PlaybackHistoryEvent; import de.danoeh.antennapod.core.event.PlayerStatusEvent; +import de.danoeh.antennapod.core.feed.FeedItem; +import de.danoeh.antennapod.core.storage.DBReader; +import de.danoeh.antennapod.core.storage.DBWriter; +import de.danoeh.antennapod.core.util.FeedItemUtil; +import de.danoeh.antennapod.view.EmptyViewHandler; +import io.reactivex.Observable; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.Disposable; +import io.reactivex.schedulers.Schedulers; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import java.util.List; -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.activity.MainActivity; -import de.danoeh.antennapod.adapter.FeedItemlistAdapter; -import de.danoeh.antennapod.core.event.DownloadEvent; -import de.danoeh.antennapod.core.event.DownloaderUpdate; -import de.danoeh.antennapod.core.event.FeedItemEvent; -import de.danoeh.antennapod.core.feed.FeedItem; -import de.danoeh.antennapod.core.feed.FeedMedia; -import de.danoeh.antennapod.core.service.download.Downloader; -import de.danoeh.antennapod.core.storage.DBReader; -import de.danoeh.antennapod.core.storage.DBWriter; -import de.danoeh.antennapod.core.util.FeedItemUtil; -import de.danoeh.antennapod.core.util.LongList; -import de.danoeh.antennapod.view.EmptyViewHandler; -import io.reactivex.Observable; -import io.reactivex.android.schedulers.AndroidSchedulers; -import io.reactivex.disposables.Disposable; -import io.reactivex.schedulers.Schedulers; - -public class PlaybackHistoryFragment extends ListFragment { +public class PlaybackHistoryFragment extends Fragment implements AdapterView.OnItemClickListener { public static final String TAG = "PlaybackHistoryFragment"; private List playbackHistory; private FeedItemlistAdapter adapter; - private List downloaderList; private Disposable disposable; + private ListView listView; @Override public void onCreate(Bundle savedInstanceState) { @@ -55,26 +55,26 @@ public class PlaybackHistoryFragment extends ListFragment { } @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - // add padding - final ListView lv = getListView(); - lv.setClipToPadding(false); - final int vertPadding = getResources().getDimensionPixelSize(R.dimen.list_vertical_padding); - lv.setPadding(0, vertPadding, 0, vertPadding); + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { + View root = inflater.inflate(R.layout.simple_list_fragment, container, false); + Toolbar toolbar = root.findViewById(R.id.toolbar); + toolbar.setTitle(R.string.playback_history_label); + ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar); + listView = root.findViewById(android.R.id.list); EmptyViewHandler emptyView = new EmptyViewHandler(getActivity()); emptyView.setIcon(R.attr.ic_history); emptyView.setTitle(R.string.no_history_head_label); emptyView.setMessage(R.string.no_history_label); - emptyView.attachToListView(getListView()); + emptyView.attachToListView(listView); // played items shoudln't be transparent for this fragment since, *all* items // in this fragment will, by definition, be played. So it serves no purpose and can make // it harder to read. adapter = new FeedItemlistAdapter((MainActivity) getActivity(), itemAccess, true, false); - setListAdapter(adapter); + listView.setAdapter(adapter); + return root; } @Override @@ -96,15 +96,12 @@ public class PlaybackHistoryFragment extends ListFragment { @Subscribe(sticky = true, threadMode = ThreadMode.MAIN) public void onEvent(DownloadEvent event) { Log.d(TAG, "onEvent() called with: " + "event = [" + event + "]"); - DownloaderUpdate update = event.update; - downloaderList = update.downloaders; adapter.notifyDataSetChanged(); } @Override - public void onListItemClick(ListView l, View v, int position, long id) { - super.onListItemClick(l, v, position, id); - position -= l.getHeaderViewsCount(); + public void onItemClick(AdapterView parent, View view, int position, long id) { + position -= listView.getHeaderViewsCount(); long[] ids = FeedItemUtil.getIds(playbackHistory); ((MainActivity) getActivity()).loadChildFragment(ItemPagerFragment.newInstance(ids, position)); } @@ -149,12 +146,12 @@ public class PlaybackHistoryFragment extends ListFragment { @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(FeedItemEvent event) { Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]"); - if(playbackHistory == null) { + if (playbackHistory == null) { return; } - for(FeedItem item : event.items) { + for (FeedItem item : event.items) { int pos = FeedItemUtil.indexOfItemWithId(playbackHistory, item.getId()); - if(pos >= 0) { + if (pos >= 0) { loadItems(); return; } @@ -196,7 +193,7 @@ public class PlaybackHistoryFragment extends ListFragment { }; private void loadItems() { - if(disposable != null) { + if (disposable != null) { disposable.dispose(); } disposable = Observable.fromCallable(this::loadData) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java index 36c837a25..27b105ee8 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -16,6 +16,7 @@ import android.widget.ProgressBar; import android.widget.TextView; import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.SearchView; import androidx.core.view.MenuItemCompat; import androidx.fragment.app.Fragment; @@ -495,9 +496,8 @@ public class QueueFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); - ((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.queue_label); - View root = inflater.inflate(R.layout.queue_fragment, container, false); + ((AppCompatActivity) getActivity()).setSupportActionBar(root.findViewById(R.id.toolbar)); infoBar = root.findViewById(R.id.info_bar); recyclerView = root.findViewById(R.id.recyclerView); RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator(); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java index 7d284835d..f4a5ed299 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java @@ -103,9 +103,8 @@ public class SearchFragment extends Fragment implements AdapterView.OnItemClickL @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(R.string.search_label); - View layout = inflater.inflate(R.layout.search_fragment, container, false); + ((AppCompatActivity) getActivity()).setSupportActionBar(layout.findViewById(R.id.toolbar)); ListView listView = layout.findViewById(R.id.listview); progressBar = layout.findViewById(R.id.progressBar); searchAdapter = new FeedItemlistAdapter((MainActivity) getActivity(), itemAccess, true, true); @@ -141,7 +140,7 @@ public class SearchFragment extends Fragment implements AdapterView.OnItemClickL public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); MenuItem item = menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label); - MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); + item.setShowAsAction(MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); final SearchView sv = new SearchView(getActivity()); sv.setQueryHint(getString(R.string.search_label)); sv.setQuery(getArguments().getString(ARG_QUERY), false); @@ -159,7 +158,8 @@ public class SearchFragment extends Fragment implements AdapterView.OnItemClickL return false; } }); - MenuItemCompat.setActionView(item, sv); + sv.setIconifiedByDefault(false); + item.setActionView(sv); } @Subscribe diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java index d0f6772ea..83c2ea440 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java @@ -6,6 +6,7 @@ import android.content.DialogInterface; import android.content.SharedPreferences; import android.os.Bundle; import androidx.annotation.StringRes; +import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import android.util.Log; import android.view.ContextMenu; @@ -85,6 +86,7 @@ public class SubscriptionFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.fragment_subscriptions, container, false); + ((AppCompatActivity) getActivity()).setSupportActionBar(root.findViewById(R.id.toolbar)); subscriptionGridLayout = root.findViewById(R.id.subscriptions_grid); subscriptionGridLayout.setNumColumns(prefs.getInt(PREF_NUM_COLUMNS, 3)); registerForContextMenu(subscriptionGridLayout); @@ -160,10 +162,6 @@ public class SubscriptionFragment extends Fragment { ((MainActivity) getActivity()).loadChildFragment(new AddFeedFragment()); } }); - - if (getActivity() instanceof MainActivity) { - ((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.subscriptions_label); - } } @Override diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/StatisticsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/StatisticsFragment.java index 668549d53..4b8cf1e1c 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/StatisticsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/StatisticsFragment.java @@ -49,6 +49,8 @@ public class StatisticsFragment extends Fragment { tabLayout = rootView.findViewById(R.id.sliding_tabs); tabLayout.setupWithViewPager(viewPager); + rootView.findViewById(R.id.toolbar).setVisibility(View.GONE); + return rootView; } diff --git a/app/src/main/res/layout/addfeed.xml b/app/src/main/res/layout/addfeed.xml index 9e57e0743..8b26332ed 100644 --- a/app/src/main/res/layout/addfeed.xml +++ b/app/src/main/res/layout/addfeed.xml @@ -1,182 +1,193 @@ - + android:layout_height="match_parent" android:layout_width="match_parent" + android:orientation="vertical"> - + android:minHeight="?attr/actionBarSize" + android:theme="?attr/actionBarTheme" + app:title="@string/add_feed_label" + android:id="@+id/toolbar"/> - + + + android:orientation="vertical" + android:focusableInTouchMode="true" + android:padding="8dp"> - + app:cardCornerRadius="4dp" + android:elevation="16dp" + android:layout_margin="8dp"> - - - + android:orientation="horizontal"> - + - + - + - + - + android:layout_margin="8dp"/> - + + + android:padding="16dp" + android:orientation="vertical"> - + -