2018-09-23 03:32:19 +02:00
|
|
|
package org.schabi.newpipe.fragments.list.comments;
|
|
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2021-06-13 21:35:34 +02:00
|
|
|
import android.widget.TextView;
|
2018-09-23 03:32:19 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
2018-09-23 03:32:19 +02:00
|
|
|
import org.schabi.newpipe.R;
|
2020-12-11 14:55:47 +01:00
|
|
|
import org.schabi.newpipe.error.UserAction;
|
2018-09-23 03:32:19 +02:00
|
|
|
import org.schabi.newpipe.extractor.ListExtractor;
|
|
|
|
import org.schabi.newpipe.extractor.comments.CommentsInfo;
|
|
|
|
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
|
2021-01-16 04:32:01 +01:00
|
|
|
import org.schabi.newpipe.ktx.ViewUtils;
|
2018-09-23 03:32:19 +02:00
|
|
|
import org.schabi.newpipe.util.ExtractorHelper;
|
|
|
|
|
2020-10-31 21:55:45 +01:00
|
|
|
import io.reactivex.rxjava3.core.Single;
|
|
|
|
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
2018-09-23 03:32:19 +02:00
|
|
|
|
|
|
|
public class CommentsFragment extends BaseListInfoFragment<CommentsInfo> {
|
2020-11-18 23:50:00 +01:00
|
|
|
private final CompositeDisposable disposables = new CompositeDisposable();
|
2018-09-23 03:32:19 +02:00
|
|
|
|
2021-06-19 15:03:20 +02:00
|
|
|
private TextView emptyStateDesc;
|
2021-06-13 21:35:34 +02:00
|
|
|
|
2020-12-11 14:55:47 +01:00
|
|
|
public static CommentsFragment getInstance(final int serviceId, final String url,
|
2020-03-31 19:20:15 +02:00
|
|
|
final String name) {
|
2020-08-16 10:24:58 +02:00
|
|
|
final CommentsFragment instance = new CommentsFragment();
|
2018-09-23 03:32:19 +02:00
|
|
|
instance.setInitialData(serviceId, url, name);
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2020-12-11 14:55:47 +01:00
|
|
|
public CommentsFragment() {
|
|
|
|
super(UserAction.REQUESTED_COMMENTS);
|
|
|
|
}
|
|
|
|
|
2021-06-13 21:35:34 +02:00
|
|
|
@Override
|
|
|
|
protected void initViews(final View rootView, final Bundle savedInstanceState) {
|
|
|
|
super.initViews(rootView, savedInstanceState);
|
|
|
|
|
2021-06-19 15:03:20 +02:00
|
|
|
emptyStateDesc = rootView.findViewById(R.id.empty_state_desc);
|
2021-06-13 21:35:34 +02:00
|
|
|
}
|
|
|
|
|
2018-09-23 03:32:19 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// LifeCycle
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public View onCreateView(@NonNull final LayoutInflater inflater,
|
|
|
|
@Nullable final ViewGroup container,
|
|
|
|
@Nullable final Bundle savedInstanceState) {
|
2018-09-23 03:32:19 +02:00
|
|
|
return inflater.inflate(R.layout.fragment_comments, container, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
2020-11-01 13:55:20 +01:00
|
|
|
disposables.clear();
|
2018-09-23 03:32:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Load and handle
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() {
|
2020-04-15 15:31:53 +02:00
|
|
|
return ExtractorHelper.getMoreCommentItems(serviceId, currentInfo, currentNextPage);
|
2018-09-23 03:32:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
protected Single<CommentsInfo> loadResult(final boolean forceLoad) {
|
2018-09-23 03:32:19 +02:00
|
|
|
return ExtractorHelper.getCommentsInfo(serviceId, url, forceLoad);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Contract
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public void handleResult(@NonNull final CommentsInfo result) {
|
2018-09-23 03:32:19 +02:00
|
|
|
super.handleResult(result);
|
2021-06-13 21:35:34 +02:00
|
|
|
|
2021-06-19 15:03:20 +02:00
|
|
|
emptyStateDesc.setText(
|
|
|
|
result.isCommentsDisabled()
|
|
|
|
? R.string.comments_are_disabled
|
|
|
|
: R.string.no_comments);
|
2021-06-13 21:35:34 +02:00
|
|
|
|
2021-01-16 04:32:01 +01:00
|
|
|
ViewUtils.slideUp(requireView(), 120, 150, 0.06f);
|
|
|
|
disposables.clear();
|
2018-09-23 03:32:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Utils
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public void setTitle(final String title) { }
|
2018-10-02 17:09:16 +02:00
|
|
|
|
|
|
|
@Override
|
2021-06-20 00:29:18 +02:00
|
|
|
public void onCreateOptionsMenu(@NonNull final Menu menu,
|
|
|
|
@NonNull final MenuInflater inflater) { }
|
2018-12-08 22:51:55 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean isGridLayout() {
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-23 03:32:19 +02:00
|
|
|
}
|