-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Migrate empty_state_view xml/view to Jetpack Compose #11463
base: refactor
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,11 @@ | |
import android.view.MenuInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.annotation.StringRes; | ||
import androidx.compose.runtime.MutableState; | ||
|
||
import org.schabi.newpipe.R; | ||
import org.schabi.newpipe.error.UserAction; | ||
|
@@ -19,6 +20,9 @@ | |
import org.schabi.newpipe.fragments.list.BaseListInfoFragment; | ||
import org.schabi.newpipe.info_list.ItemViewMode; | ||
import org.schabi.newpipe.ktx.ViewUtils; | ||
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.util.ExtractorHelper; | ||
|
||
import io.reactivex.rxjava3.core.Single; | ||
|
@@ -27,7 +31,7 @@ | |
public class CommentsFragment extends BaseListInfoFragment<CommentsInfoItem, CommentsInfo> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've already migrated this fragment to Compose in a separate PR, so I don't think this particular change will be needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good to know. This can wait for your PR. |
||
private final CompositeDisposable disposables = new CompositeDisposable(); | ||
|
||
private TextView emptyStateDesc; | ||
private MutableState<EmptyStateSpec> emptyStateSpec; | ||
|
||
public static CommentsFragment getInstance(final int serviceId, final String url, | ||
final String name) { | ||
|
@@ -44,7 +48,10 @@ public CommentsFragment() { | |
protected void initViews(final View rootView, final Bundle savedInstanceState) { | ||
super.initViews(rootView, savedInstanceState); | ||
|
||
emptyStateDesc = rootView.findViewById(R.id.empty_state_desc); | ||
emptyStateSpec = EmptyStateUtil.mutableStateOf(EmptyStateSpec.Companion.getNoComment()); | ||
EmptyStateUtil.setEmptyStateComposable( | ||
rootView.findViewById(R.id.empty_state_view), | ||
emptyStateSpec); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
|
@@ -86,15 +93,23 @@ protected Single<CommentsInfo> loadResult(final boolean forceLoad) { | |
public void handleResult(@NonNull final CommentsInfo result) { | ||
super.handleResult(result); | ||
|
||
emptyStateDesc.setText( | ||
result.isCommentsDisabled() | ||
? R.string.comments_are_disabled | ||
: R.string.no_comments); | ||
if (result.isCommentsDisabled()) { | ||
updateEmptyState(R.string.comments_are_disabled); | ||
} else { | ||
updateEmptyState(R.string.no_comments); | ||
} | ||
|
||
ViewUtils.slideUp(requireView(), 120, 150, 0.06f); | ||
disposables.clear(); | ||
} | ||
|
||
private void updateEmptyState(final @StringRes int descriptionRes) { | ||
final EmptyStateSpec style = new EmptyStateSpecBuilder(emptyStateSpec.getValue()) | ||
.descriptionText(descriptionRes) | ||
.build(); | ||
emptyStateSpec.setValue(style); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
// Utils | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The entire fragment could be implemented using Compose directly, see https://developer.android.com/reference/kotlin/androidx/fragment/compose/package-summary#(androidx.fragment.app.Fragment).content(kotlin.Function0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. This PR is to have a single purpose. Since applying this API requires firstly migrating EmptyFragment to kotlin, I can start another PR purely for the migration without mixing it into one.