Skip to content

Commit 9b78e49

Browse files
authored
Merge pull request #11725 from Profpatsch/lwj.compose_migrate_empty_state_view
Migrate empty_state_view xml/view to Jetpack Compose
2 parents 295f719 + cff3834 commit 9b78e49

32 files changed

+364
-269
lines changed

app/src/main/java/org/schabi/newpipe/fragments/EmptyFragment.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
import android.view.ViewGroup;
77

88
import androidx.annotation.Nullable;
9+
import androidx.compose.ui.platform.ComposeView;
910

1011
import org.schabi.newpipe.BaseFragment;
1112
import org.schabi.newpipe.R;
13+
import org.schabi.newpipe.ui.emptystate.EmptyStateUtil;
1214

1315
public class EmptyFragment extends BaseFragment {
1416
private static final String SHOW_MESSAGE = "SHOW_MESSAGE";
@@ -26,8 +28,10 @@ public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGrou
2628
final Bundle savedInstanceState) {
2729
final boolean showMessage = getArguments().getBoolean(SHOW_MESSAGE);
2830
final View view = inflater.inflate(R.layout.fragment_empty, container, false);
29-
view.findViewById(R.id.empty_state_view).setVisibility(
30-
showMessage ? View.VISIBLE : View.GONE);
31+
32+
final ComposeView composeView = view.findViewById(R.id.empty_state_view);
33+
EmptyStateUtil.setEmptyStateComposable(composeView);
34+
composeView.setVisibility(showMessage ? View.VISIBLE : View.GONE);
3135
return view;
3236
}
3337
}

app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import android.os.Bundle;
1111
import android.text.TextUtils;
1212
import android.util.Log;
13-
import android.util.TypedValue;
1413
import android.view.LayoutInflater;
1514
import android.view.Menu;
1615
import android.view.MenuInflater;
@@ -45,6 +44,8 @@
4544
import org.schabi.newpipe.ktx.AnimationType;
4645
import org.schabi.newpipe.local.feed.notifications.NotificationHelper;
4746
import org.schabi.newpipe.local.subscription.SubscriptionManager;
47+
import org.schabi.newpipe.ui.emptystate.EmptyStateSpec;
48+
import org.schabi.newpipe.ui.emptystate.EmptyStateUtil;
4849
import org.schabi.newpipe.util.ChannelTabHelper;
4950
import org.schabi.newpipe.util.Constants;
5051
import org.schabi.newpipe.util.ExtractorHelper;
@@ -199,6 +200,11 @@ public View onCreateView(@NonNull final LayoutInflater inflater,
199200
protected void initViews(final View rootView, final Bundle savedInstanceState) {
200201
super.initViews(rootView, savedInstanceState);
201202

203+
EmptyStateUtil.setEmptyStateComposable(
204+
binding.emptyStateView,
205+
EmptyStateSpec.Companion.getContentNotSupported()
206+
);
207+
202208
tabAdapter = new TabAdapter(getChildFragmentManager());
203209
binding.viewPager.setAdapter(tabAdapter);
204210
binding.tabLayout.setupWithViewPager(binding.viewPager);
@@ -645,8 +651,6 @@ private void showContentNotSupportedIfNeeded() {
645651
return;
646652
}
647653

648-
binding.errorContentNotSupported.setVisibility(View.VISIBLE);
649-
binding.channelKaomoji.setText("(︶︹︺)");
650-
binding.channelKaomoji.setTextSize(TypedValue.COMPLEX_UNIT_SP, 45f);
654+
binding.emptyStateView.setVisibility(View.VISIBLE);
651655
}
652656
}

app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelTabFragment.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.schabi.newpipe.fragments.list.playlist.PlaylistControlViewHolder;
2727
import org.schabi.newpipe.player.playqueue.ChannelTabPlayQueue;
2828
import org.schabi.newpipe.player.playqueue.PlayQueue;
29+
import org.schabi.newpipe.ui.emptystate.EmptyStateUtil;
2930
import org.schabi.newpipe.util.ChannelTabHelper;
3031
import org.schabi.newpipe.util.ExtractorHelper;
3132
import org.schabi.newpipe.util.PlayButtonHelper;
@@ -79,6 +80,12 @@ public View onCreateView(@NonNull final LayoutInflater inflater,
7980
return inflater.inflate(R.layout.fragment_channel_tab, container, false);
8081
}
8182

83+
@Override
84+
public void onViewCreated(@NonNull final View rootView, final Bundle savedInstanceState) {
85+
super.onViewCreated(rootView, savedInstanceState);
86+
EmptyStateUtil.setEmptyStateComposable(rootView.findViewById(R.id.empty_state_view));
87+
}
88+
8289
@Override
8390
public void onDestroyView() {
8491
super.onDestroyView();

app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
import org.schabi.newpipe.ktx.ExceptionUtils;
6565
import org.schabi.newpipe.local.history.HistoryRecordManager;
6666
import org.schabi.newpipe.settings.NewPipeSettings;
67+
import org.schabi.newpipe.ui.emptystate.EmptyStateSpec;
68+
import org.schabi.newpipe.ui.emptystate.EmptyStateUtil;
6769
import org.schabi.newpipe.util.Constants;
6870
import org.schabi.newpipe.util.DeviceUtils;
6971
import org.schabi.newpipe.util.ExtractorHelper;
@@ -344,6 +346,10 @@ public void onActivityResult(final int requestCode, final int resultCode, final
344346
protected void initViews(final View rootView, final Bundle savedInstanceState) {
345347
super.initViews(rootView, savedInstanceState);
346348

349+
EmptyStateUtil.setEmptyStateComposable(
350+
searchBinding.emptyStateView,
351+
EmptyStateSpec.Companion.getNoSearchResult());
352+
347353
searchBinding.suggestionsList.setAdapter(suggestionListAdapter);
348354
// animations are just strange and useless, since the suggestions keep changing too much
349355
searchBinding.suggestionsList.setItemAnimator(null);

app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import org.schabi.newpipe.local.holder.RemoteBookmarkPlaylistItemHolder;
3939
import org.schabi.newpipe.local.playlist.LocalPlaylistManager;
4040
import org.schabi.newpipe.local.playlist.RemotePlaylistManager;
41+
import org.schabi.newpipe.ui.emptystate.EmptyStateSpec;
42+
import org.schabi.newpipe.ui.emptystate.EmptyStateUtil;
4143
import org.schabi.newpipe.util.NavigationHelper;
4244
import org.schabi.newpipe.util.OnClickGesture;
4345
import org.schabi.newpipe.util.debounce.DebounceSavable;
@@ -123,6 +125,10 @@ protected void initViews(final View rootView, final Bundle savedInstanceState) {
123125
super.initViews(rootView, savedInstanceState);
124126

125127
itemListAdapter.setUseItemHandle(true);
128+
EmptyStateUtil.setEmptyStateComposable(
129+
rootView.findViewById(R.id.empty_state_view),
130+
EmptyStateSpec.Companion.getNoBookmarkedPlaylist()
131+
);
126132
}
127133

128134
@Override

app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import org.schabi.newpipe.ktx.slideUp
7474
import org.schabi.newpipe.local.feed.item.StreamItem
7575
import org.schabi.newpipe.local.feed.service.FeedLoadService
7676
import org.schabi.newpipe.local.subscription.SubscriptionManager
77+
import org.schabi.newpipe.ui.emptystate.setEmptyStateComposable
7778
import org.schabi.newpipe.util.DeviceUtils
7879
import org.schabi.newpipe.util.Localization
7980
import org.schabi.newpipe.util.NavigationHelper
@@ -132,6 +133,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
132133
override fun onViewCreated(rootView: View, savedInstanceState: Bundle?) {
133134
// super.onViewCreated() calls initListeners() which require the binding to be initialized
134135
_feedBinding = FragmentFeedBinding.bind(rootView)
136+
feedBinding.emptyStateView.setEmptyStateComposable()
135137
super.onViewCreated(rootView, savedInstanceState)
136138

137139
val factory = FeedViewModel.getFactory(requireContext(), groupId)

app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import org.schabi.newpipe.local.subscription.services.SubscriptionsImportService
5656
import org.schabi.newpipe.local.subscription.services.SubscriptionsImportService.PREVIOUS_EXPORT_MODE
5757
import org.schabi.newpipe.streams.io.NoFileManagerSafeGuard
5858
import org.schabi.newpipe.streams.io.StoredFileHelper
59+
import org.schabi.newpipe.ui.emptystate.setEmptyStateComposable
5960
import org.schabi.newpipe.util.NavigationHelper
6061
import org.schabi.newpipe.util.OnClickGesture
6162
import org.schabi.newpipe.util.ServiceHelper
@@ -257,6 +258,8 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
257258
binding.itemsList.adapter = groupAdapter
258259
binding.itemsList.itemAnimator = null
259260

261+
binding.emptyStateView.setEmptyStateComposable()
262+
260263
viewModel = ViewModelProvider(this)[SubscriptionViewModel::class.java]
261264
viewModel.stateLiveData.observe(viewLifecycleOwner) { it?.let(this::handleResult) }
262265
viewModel.feedGroupsLiveData.observe(viewLifecycleOwner) {

app/src/main/java/org/schabi/newpipe/local/subscription/item/ImportSubscriptionsHintPlaceholderItem.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ package org.schabi.newpipe.local.subscription.item
33
import android.view.View
44
import com.xwray.groupie.viewbinding.BindableItem
55
import org.schabi.newpipe.R
6-
import org.schabi.newpipe.databinding.ListEmptyViewBinding
6+
import org.schabi.newpipe.databinding.ListEmptyViewSubscriptionsBinding
7+
import org.schabi.newpipe.ui.emptystate.EmptyStateSpec
8+
import org.schabi.newpipe.ui.emptystate.setEmptyStateComposable
79

810
/**
911
* When there are no subscriptions, show a hint to the user about how to import subscriptions
1012
*/
11-
class ImportSubscriptionsHintPlaceholderItem : BindableItem<ListEmptyViewBinding>() {
13+
class ImportSubscriptionsHintPlaceholderItem : BindableItem<ListEmptyViewSubscriptionsBinding>() {
1214
override fun getLayout(): Int = R.layout.list_empty_view_subscriptions
13-
override fun bind(viewBinding: ListEmptyViewBinding, position: Int) {}
15+
override fun bind(viewBinding: ListEmptyViewSubscriptionsBinding, position: Int) {
16+
viewBinding.root.setEmptyStateComposable(EmptyStateSpec.NoSubscriptionsHint)
17+
}
1418
override fun getSpanSize(spanCount: Int, position: Int): Int = spanCount
15-
override fun initializeViewBinding(view: View) = ListEmptyViewBinding.bind(view)
19+
override fun initializeViewBinding(view: View) = ListEmptyViewSubscriptionsBinding.bind(view)
1620
}

app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import androidx.annotation.NonNull;
1313
import androidx.annotation.Nullable;
14+
import androidx.compose.ui.platform.ComposeView;
1415
import androidx.fragment.app.DialogFragment;
1516
import androidx.recyclerview.widget.LinearLayoutManager;
1617
import androidx.recyclerview.widget.RecyclerView;
@@ -19,6 +20,8 @@
1920
import org.schabi.newpipe.database.subscription.SubscriptionEntity;
2021
import org.schabi.newpipe.error.ErrorUtil;
2122
import org.schabi.newpipe.local.subscription.SubscriptionManager;
23+
import org.schabi.newpipe.ui.emptystate.EmptyStateSpec;
24+
import org.schabi.newpipe.ui.emptystate.EmptyStateUtil;
2225
import org.schabi.newpipe.util.ThemeHelper;
2326
import org.schabi.newpipe.util.image.CoilHelper;
2427

@@ -57,7 +60,7 @@ public class SelectChannelFragment extends DialogFragment {
5760
private OnCancelListener onCancelListener = null;
5861

5962
private ProgressBar progressBar;
60-
private TextView emptyView;
63+
private ComposeView emptyView;
6164
private RecyclerView recyclerView;
6265

6366
private List<SubscriptionEntity> subscriptions = new Vector<>();
@@ -91,6 +94,9 @@ public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup
9194

9295
progressBar = v.findViewById(R.id.progressBar);
9396
emptyView = v.findViewById(R.id.empty_state_view);
97+
98+
EmptyStateUtil.setEmptyStateComposable(emptyView,
99+
EmptyStateSpec.Companion.getNoSubscriptions());
94100
progressBar.setVisibility(View.VISIBLE);
95101
recyclerView.setVisibility(View.GONE);
96102
emptyView.setVisibility(View.GONE);

app/src/main/java/org/schabi/newpipe/settings/SelectPlaylistFragment.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import android.widget.TextView;
1212

1313
import androidx.annotation.NonNull;
14+
import androidx.compose.ui.platform.ComposeView;
1415
import androidx.fragment.app.DialogFragment;
1516
import androidx.recyclerview.widget.LinearLayoutManager;
1617
import androidx.recyclerview.widget.RecyclerView;
@@ -27,6 +28,8 @@
2728
import org.schabi.newpipe.error.UserAction;
2829
import org.schabi.newpipe.local.playlist.LocalPlaylistManager;
2930
import org.schabi.newpipe.local.playlist.RemotePlaylistManager;
31+
import org.schabi.newpipe.ui.emptystate.EmptyStateSpec;
32+
import org.schabi.newpipe.ui.emptystate.EmptyStateUtil;
3033
import org.schabi.newpipe.util.image.CoilHelper;
3134

3235
import java.util.List;
@@ -40,7 +43,7 @@ public class SelectPlaylistFragment extends DialogFragment {
4043
private OnSelectedListener onSelectedListener = null;
4144

4245
private ProgressBar progressBar;
43-
private TextView emptyView;
46+
private ComposeView emptyView;
4447
private RecyclerView recyclerView;
4548
private Disposable disposable = null;
4649

@@ -62,6 +65,8 @@ public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup
6265
recyclerView = v.findViewById(R.id.items_list);
6366
emptyView = v.findViewById(R.id.empty_state_view);
6467

68+
EmptyStateUtil.setEmptyStateComposable(emptyView,
69+
EmptyStateSpec.Companion.getNoBookmarkedPlaylist());
6570
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
6671
final SelectPlaylistAdapter playlistAdapter = new SelectPlaylistAdapter();
6772
recyclerView.setAdapter(playlistAdapter);

0 commit comments

Comments
 (0)