Search in sources :

Example 6 with Comment

use of forpdateam.ru.forpda.api.news.models.Comment in project ForPDA by RadiationX.

the class ArticleCommentsFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.article_comments, container, false);
    refreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_list);
    recyclerView = (RecyclerView) view.findViewById(R.id.base_list);
    writePanel = (RelativeLayout) view.findViewById(R.id.comment_write_panel);
    messageField = (EditText) view.findViewById(R.id.message_field);
    sendContainer = (FrameLayout) view.findViewById(R.id.send_container);
    buttonSend = (AppCompatImageButton) view.findViewById(R.id.button_send);
    progressBarSend = (ProgressBar) view.findViewById(R.id.send_progress);
    additionalContent = (ViewGroup) view.findViewById(R.id.additional_content);
    refreshLayout.setProgressBackgroundColorSchemeColor(App.getColorFromAttr(getContext(), R.attr.colorPrimary));
    refreshLayout.setColorSchemeColors(App.getColorFromAttr(getContext(), R.attr.colorAccent));
    refreshLayout.setOnRefreshListener(() -> {
        refreshLayout.setRefreshing(true);
        RxApi.NewsList().getDetails(article.getId()).map(page -> {
            Comment commentTree = Api.NewsApi().updateComments(article, page);
            article.setCommentTree(commentTree);
            return Api.NewsApi().commentsToList(article.getCommentTree());
        }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(comments -> {
            refreshLayout.setRefreshing(false);
            createFunny(comments);
            adapter.addAll(comments);
        });
    });
    recyclerView.setBackgroundColor(App.getColorFromAttr(getContext(), R.attr.background_for_lists));
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    recyclerView.setHasFixedSize(true);
    recyclerView.addItemDecoration(new BrandFragment.SpacingItemDecoration(App.px12, false));
    adapter = new ArticleCommentsAdapter();
    adapter.setClickListener(this);
    Observable.fromCallable(() -> {
        if (article.getCommentTree() == null) {
            Comment commentTree = Api.NewsApi().parseComments(article.getKarmaMap(), article.getCommentsSource());
            article.setCommentTree(commentTree);
        }
        return Api.NewsApi().commentsToList(article.getCommentTree());
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(comments -> {
        createFunny(comments);
        adapter.addAll(comments);
        if (article.getCommentId() > 0) {
            for (int i = 0; i < comments.size(); i++) {
                if (comments.get(i).getId() == article.getCommentId()) {
                    recyclerView.scrollToPosition(i);
                    break;
                }
            }
        }
    });
    recyclerView.setAdapter(adapter);
    messageField.addTextChangedListener(new SimpleTextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            if (s.length() == 0) {
                currentReplyComment = null;
            }
            buttonSend.setClickable(s.length() > 0);
        }
    });
    buttonSend.setOnClickListener(v -> sendComment());
    if (ClientHelper.getAuthState()) {
        writePanel.setVisibility(View.VISIBLE);
    } else {
        writePanel.setVisibility(View.GONE);
    }
    ClientHelper.get().addLoginObserver(loginObserver);
    contentController = new ContentController(null, additionalContent, refreshLayout);
    return view;
}
Also used : Observer(java.util.Observer) ContentController(forpdateam.ru.forpda.ui.views.ContentController) Context(android.content.Context) Bundle(android.os.Bundle) SimpleTextWatcher(forpdateam.ru.forpda.common.simple.SimpleTextWatcher) ProgressBar(android.widget.ProgressBar) FrameLayout(android.widget.FrameLayout) Comment(forpdateam.ru.forpda.api.news.models.Comment) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) Editable(android.text.Editable) InputMethodManager(android.view.inputmethod.InputMethodManager) ArrayList(java.util.ArrayList) RxApi(forpdateam.ru.forpda.apirx.RxApi) View(android.view.View) FunnyContent(forpdateam.ru.forpda.ui.views.FunnyContent) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) Api(forpdateam.ru.forpda.api.Api) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) BrandFragment(forpdateam.ru.forpda.ui.fragments.devdb.BrandFragment) LayoutInflater(android.view.LayoutInflater) ClientHelper(forpdateam.ru.forpda.client.ClientHelper) Fragment(android.support.v4.app.Fragment) AppCompatImageButton(android.support.v7.widget.AppCompatImageButton) IntentHandler(forpdateam.ru.forpda.common.IntentHandler) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ViewGroup(android.view.ViewGroup) RecyclerView(android.support.v7.widget.RecyclerView) AlertDialog(android.support.v7.app.AlertDialog) DetailsPage(forpdateam.ru.forpda.api.news.models.DetailsPage) RelativeLayout(android.widget.RelativeLayout) App(forpdateam.ru.forpda.App) Nullable(android.support.annotation.Nullable) R(forpdateam.ru.forpda.R) EditText(android.widget.EditText) Comment(forpdateam.ru.forpda.api.news.models.Comment) SimpleTextWatcher(forpdateam.ru.forpda.common.simple.SimpleTextWatcher) BrandFragment(forpdateam.ru.forpda.ui.fragments.devdb.BrandFragment) ContentController(forpdateam.ru.forpda.ui.views.ContentController) Editable(android.text.Editable) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) Nullable(android.support.annotation.Nullable)

Aggregations

Comment (forpdateam.ru.forpda.api.news.models.Comment)6 Context (android.content.Context)1 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 Fragment (android.support.v4.app.Fragment)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 AlertDialog (android.support.v7.app.AlertDialog)1 AppCompatImageButton (android.support.v7.widget.AppCompatImageButton)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Editable (android.text.Editable)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 EditText (android.widget.EditText)1 FrameLayout (android.widget.FrameLayout)1 ProgressBar (android.widget.ProgressBar)1 RelativeLayout (android.widget.RelativeLayout)1 App (forpdateam.ru.forpda.App)1