1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-06-05 16:14:05 +00:00

Remove unneeded empty state changes in ChannelFragment

This commit is contained in:
Stypox 2024-11-21 11:53:01 +01:00
parent ad72b2cb31
commit 46b9243661
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
3 changed files with 11 additions and 29 deletions

View File

@ -19,7 +19,6 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.compose.runtime.MutableState;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.core.graphics.ColorUtils; import androidx.core.graphics.ColorUtils;
import androidx.core.view.MenuProvider; import androidx.core.view.MenuProvider;
@ -46,7 +45,6 @@ import org.schabi.newpipe.ktx.AnimationType;
import org.schabi.newpipe.local.feed.notifications.NotificationHelper; import org.schabi.newpipe.local.feed.notifications.NotificationHelper;
import org.schabi.newpipe.local.subscription.SubscriptionManager; import org.schabi.newpipe.local.subscription.SubscriptionManager;
import org.schabi.newpipe.ui.emptystate.EmptyStateSpec; import org.schabi.newpipe.ui.emptystate.EmptyStateSpec;
import org.schabi.newpipe.ui.emptystate.EmptyStateSpecBuilder;
import org.schabi.newpipe.ui.emptystate.EmptyStateUtil; import org.schabi.newpipe.ui.emptystate.EmptyStateUtil;
import org.schabi.newpipe.util.ChannelTabHelper; import org.schabi.newpipe.util.ChannelTabHelper;
import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.Constants;
@ -105,8 +103,6 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo>
private SubscriptionEntity channelSubscription; private SubscriptionEntity channelSubscription;
private MenuProvider menuProvider; private MenuProvider menuProvider;
private MutableState<EmptyStateSpec> emptyStateSpec;
public static ChannelFragment getInstance(final int serviceId, final String url, public static ChannelFragment getInstance(final int serviceId, final String url,
final String name) { final String name) {
final ChannelFragment instance = new ChannelFragment(); final ChannelFragment instance = new ChannelFragment();
@ -204,9 +200,10 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo>
protected void initViews(final View rootView, final Bundle savedInstanceState) { protected void initViews(final View rootView, final Bundle savedInstanceState) {
super.initViews(rootView, savedInstanceState); super.initViews(rootView, savedInstanceState);
emptyStateSpec = EmptyStateUtil.mutableStateOf( EmptyStateUtil.setEmptyStateComposable(
EmptyStateSpec.Companion.getContentNotSupported()); binding.emptyStateView,
EmptyStateUtil.setEmptyStateComposable(binding.emptyStateView, emptyStateSpec); EmptyStateSpec.Companion.getContentNotSupported()
);
tabAdapter = new TabAdapter(getChildFragmentManager()); tabAdapter = new TabAdapter(getChildFragmentManager());
binding.viewPager.setAdapter(tabAdapter); binding.viewPager.setAdapter(tabAdapter);
@ -654,10 +651,6 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo>
return; return;
} }
emptyStateSpec.setValue( binding.emptyStateView.setVisibility(View.VISIBLE);
new EmptyStateSpecBuilder(emptyStateSpec.getValue())
.descriptionVisibility(true)
.build()
);
} }
} }

View File

@ -37,7 +37,6 @@ fun EmptyStateComposable(
descriptionModifier = spec.descriptionModifier(), descriptionModifier = spec.descriptionModifier(),
descriptionText = spec.descriptionText(), descriptionText = spec.descriptionText(),
descriptionTextStyle = spec.descriptionTextStyle(), descriptionTextStyle = spec.descriptionTextStyle(),
descriptionTextVisibility = spec.descriptionVisibility(),
) )
@Composable @Composable
@ -49,7 +48,6 @@ private fun EmptyStateComposable(
descriptionModifier: Modifier, descriptionModifier: Modifier,
descriptionText: String, descriptionText: String,
descriptionTextStyle: TextStyle, descriptionTextStyle: TextStyle,
descriptionTextVisibility: Boolean,
) { ) {
CompositionLocalProvider( CompositionLocalProvider(
LocalContentColor provides MaterialTheme.colorScheme.errorHint LocalContentColor provides MaterialTheme.colorScheme.errorHint
@ -65,13 +63,11 @@ private fun EmptyStateComposable(
style = emojiTextStyle, style = emojiTextStyle,
) )
if (descriptionTextVisibility) { Text(
Text( modifier = descriptionModifier,
modifier = descriptionModifier, text = descriptionText,
text = descriptionText, style = descriptionTextStyle,
style = descriptionTextStyle, )
)
}
} }
} }
} }
@ -100,9 +96,7 @@ data class EmptyStateSpec(
val descriptionText: @Composable () -> String, val descriptionText: @Composable () -> String,
val descriptionModifier: () -> Modifier, val descriptionModifier: () -> Modifier,
val descriptionTextStyle: @Composable () -> TextStyle, val descriptionTextStyle: @Composable () -> TextStyle,
val descriptionVisibility: () -> Boolean = { true },
) { ) {
companion object { companion object {
val GenericError = val GenericError =
@ -162,7 +156,6 @@ data class EmptyStateSpec(
descriptionModifier = { Modifier.padding(top = 20.dp) }, descriptionModifier = { Modifier.padding(top = 20.dp) },
descriptionText = { stringResource(id = R.string.content_not_supported) }, descriptionText = { stringResource(id = R.string.content_not_supported) },
descriptionTextStyle = { LocalTextStyle.current.merge(fontSize = 15.sp) }, descriptionTextStyle = { LocalTextStyle.current.merge(fontSize = 15.sp) },
descriptionVisibility = { false },
) )
} }
} }

View File

@ -71,7 +71,7 @@ fun <T> mutableStateOf(param: T): MutableState<T> {
* Used in Java land to modify [EmptyStateSpec] properties. * Used in Java land to modify [EmptyStateSpec] properties.
* TODO: remove after Kotlin migration * TODO: remove after Kotlin migration
*/ */
class EmptyStateSpecBuilder(var spec: EmptyStateSpec) { class EmptyStateSpecBuilder(private var spec: EmptyStateSpec) {
fun descriptionText(@StringRes stringRes: Int) = apply { fun descriptionText(@StringRes stringRes: Int) = apply {
spec = spec.copy( spec = spec.copy(
@ -79,9 +79,5 @@ class EmptyStateSpecBuilder(var spec: EmptyStateSpec) {
) )
} }
fun descriptionVisibility(descriptionTextVisibility: Boolean) = apply {
spec = spec.copy(descriptionVisibility = { descriptionTextVisibility })
}
fun build() = spec fun build() = spec
} }