Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expandable second home section #6848

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,21 @@
package de.danoeh.antennapod.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

public class EpisodesFragementInHome extends AllEpisodesFragment {
public static final String TAG = "EpisodesInHome";

@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View root = super.onCreateView(inflater, container, savedInstanceState);
toolbar.setVisibility(View.GONE);
swipeRefreshLayout.setEnabled(false);
return root;
}
}
@@ -0,0 +1,21 @@
package de.danoeh.antennapod.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

public class InboxFragmentInHome extends InboxFragment {
public static final String TAG = "InboxInHome";

@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View root = super.onCreateView(inflater, container, savedInstanceState);
toolbar.setVisibility(View.GONE);
swipeRefreshLayout.setEnabled(false);
return root;
}
}
@@ -0,0 +1,26 @@
package de.danoeh.antennapod.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import de.danoeh.antennapod.R;

/**
* Shows all items in the queue.
*/
public class QueueFragmentInHome extends QueueFragment {
public static final String TAG = "QueueInHome";

@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View root = super.onCreateView(inflater, container, savedInstanceState);
root.findViewById(R.id.toolbar).setVisibility(View.GONE);
root.findViewById(R.id.swipeRefresh).setEnabled(false);
return root;
}
}
41 changes: 32 additions & 9 deletions app/src/main/java/de/danoeh/antennapod/ui/home/HomeFragment.java
Expand Up @@ -12,13 +12,15 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentContainerView;

import org.apache.commons.lang3.ArrayUtils;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
Expand All @@ -41,8 +43,11 @@
import de.danoeh.antennapod.ui.home.sections.AllowNotificationsSection;
import de.danoeh.antennapod.ui.home.sections.DownloadsSection;
import de.danoeh.antennapod.ui.home.sections.EchoSection;
import de.danoeh.antennapod.ui.home.sections.EpisodesExpanableSection;
import de.danoeh.antennapod.ui.home.sections.EpisodesSurpriseSection;
import de.danoeh.antennapod.ui.home.sections.InboxExpanableSection;
import de.danoeh.antennapod.ui.home.sections.InboxSection;
import de.danoeh.antennapod.ui.home.sections.QueueExpanableSection;
import de.danoeh.antennapod.ui.home.sections.QueueSection;
import de.danoeh.antennapod.ui.home.sections.SubscriptionsSection;
import de.danoeh.antennapod.view.LiftOnScrollListener;
Expand Down Expand Up @@ -95,34 +100,45 @@ private void populateSectionList() {
if (Build.VERSION.SDK_INT >= 33 && ContextCompat.checkSelfPermission(getContext(),
Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
if (!prefs.getBoolean(HomeFragment.PREF_DISABLE_NOTIFICATION_PERMISSION_NAG, false)) {
addSection(new AllowNotificationsSection());
addSection(new AllowNotificationsSection(), false);
}
}
if (Calendar.getInstance().get(Calendar.YEAR) == EchoActivity.RELEASE_YEAR
&& Calendar.getInstance().get(Calendar.MONTH) == Calendar.DECEMBER
&& Calendar.getInstance().get(Calendar.DAY_OF_MONTH) >= 10
&& prefs.getInt(PREF_HIDE_ECHO, 0) != EchoActivity.RELEASE_YEAR) {
addSection(new EchoSection());
addSection(new EchoSection(), false);
}

List<String> hiddenSections = getHiddenSections(getContext());
String[] sectionTags = getResources().getStringArray(R.array.home_section_tags);
String[] sectionTags = ArrayUtils.addAll(
getResources().getStringArray(R.array.home_section_tags),
getResources().getStringArray(R.array.home_bottomhalf_tags));
for (String sectionTag : sectionTags) {
if (hiddenSections.contains(sectionTag)) {
continue;
}
addSection(getSection(sectionTag));
HomeSection section = getSection(sectionTag);
addSection(section, section.isExpandable());
}
}

private void addSection(Fragment section) {
FragmentContainerView containerView = new FragmentContainerView(getContext());
private void addSection(Fragment section, boolean expandable) {
FragmentContainerView containerView = new FragmentContainerView(requireContext());
containerView.setId(View.generateViewId());
if (expandable) {
containerView.setLayoutParams(
new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT,
2f));
viewBinding.homeContainer.setPadding(0, 0, 0, 0);
}
viewBinding.homeContainer.addView(containerView);
getChildFragmentManager().beginTransaction().add(containerView.getId(), section).commit();
}

private Fragment getSection(String tag) {
private HomeSection getSection(String tag) {
switch (tag) {
case QueueSection.TAG:
return new QueueSection();
Expand All @@ -134,14 +150,21 @@ private Fragment getSection(String tag) {
return new SubscriptionsSection();
case DownloadsSection.TAG:
return new DownloadsSection();
case EpisodesExpanableSection.TAG:
return new EpisodesExpanableSection();
case InboxExpanableSection.TAG:
return new InboxExpanableSection();
case QueueExpanableSection.TAG:
return new QueueExpanableSection();
default:
return null;
}
}

public static List<String> getHiddenSections(Context context) {
SharedPreferences prefs = context.getSharedPreferences(HomeFragment.PREF_NAME, Context.MODE_PRIVATE);
String hiddenSectionsString = prefs.getString(HomeFragment.PREF_HIDDEN_SECTIONS, "");
String hiddenSectionsString = prefs.getString(HomeFragment.PREF_HIDDEN_SECTIONS,
EpisodesExpanableSection.TAG + "," + InboxExpanableSection.TAG + "," + QueueExpanableSection.TAG);
return new ArrayList<>(Arrays.asList(TextUtils.split(hiddenSectionsString, ",")));
}

Expand All @@ -153,7 +176,7 @@ public void onEventMainThread(FeedUpdateRunningEvent event) {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.homesettings_items) {
HomeSectionsSettingsDialog.open(getContext(), (dialogInterface, i) -> populateSectionList());
HomeSectionsSettingsDialog.open(getActivity(), (dialogInterface, i) -> populateSectionList());
return true;
} else if (item.getItemId() == R.id.refresh_item) {
FeedUpdateManager.runOnceOrAsk(requireContext());
Expand Down
52 changes: 41 additions & 11 deletions app/src/main/java/de/danoeh/antennapod/ui/home/HomeSection.java
Expand Up @@ -7,10 +7,16 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DefaultItemAnimator;

import org.greenrobot.eventbus.EventBus;

import java.util.Locale;

import de.danoeh.antennapod.adapter.EpisodeItemListAdapter;
import de.danoeh.antennapod.adapter.HorizontalFeedListAdapter;
import de.danoeh.antennapod.adapter.HorizontalItemListAdapter;
Expand All @@ -19,9 +25,6 @@
import de.danoeh.antennapod.menuhandler.FeedMenuHandler;
import de.danoeh.antennapod.model.feed.Feed;
import de.danoeh.antennapod.model.feed.FeedItem;
import org.greenrobot.eventbus.EventBus;

import java.util.Locale;

/**
* Section on the HomeFragment
Expand All @@ -45,10 +48,25 @@ public View onCreateView(@NonNull LayoutInflater inflater,
if (TextUtils.isEmpty(getMoreLinkTitle())) {
viewBinding.moreButton.setVisibility(View.INVISIBLE);
}
// Dummies are necessary to ensure height, but do not animate them
viewBinding.recyclerView.setItemAnimator(null);
viewBinding.recyclerView.postDelayed(
() -> viewBinding.recyclerView.setItemAnimator(new DefaultItemAnimator()), 500);
Fragment expand = getExpandable();
if (expand != null) {
viewBinding.recyclerView.setVisibility(View.GONE);
viewBinding.homeExpandableContainer.setVisibility(View.VISIBLE);
viewBinding.parent.setLayoutParams(
new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
viewBinding.parent.setPadding(0, 0, 0, 0);
getChildFragmentManager()
.beginTransaction()
.add(viewBinding.homeExpandableContainer.getId(), expand)
.commit();
} else {
// Dummies are necessary to ensure height, but do not animate them
viewBinding.recyclerView.setItemAnimator(null);
viewBinding.recyclerView.postDelayed(
() -> viewBinding.recyclerView.setItemAnimator(new DefaultItemAnimator()), 500);
}
return viewBinding.getRoot();
}

Expand Down Expand Up @@ -86,19 +104,31 @@ public boolean onContextItemSelected(@NonNull MenuItem item) {
@Override
public void onStart() {
super.onStart();
EventBus.getDefault().register(this);
registerForContextMenu(viewBinding.recyclerView);
if (!isExpandable()) {
EventBus.getDefault().register(this);
registerForContextMenu(viewBinding.recyclerView);
}
}

@Override
public void onStop() {
super.onStop();
EventBus.getDefault().unregister(this);
unregisterForContextMenu(viewBinding.recyclerView);
if (!isExpandable()) {
EventBus.getDefault().unregister(this);
unregisterForContextMenu(viewBinding.recyclerView);
}
}

protected abstract String getSectionTitle();

protected Fragment getExpandable() {
return null;
}

protected boolean isExpandable() {
return false;
}

protected abstract String getMoreLinkTitle();

protected abstract void handleMoreClick();
Expand Down