Search in sources :

Example 1 with ContentController

use of forpdateam.ru.forpda.ui.views.ContentController in project ForPDA by RadiationX.

the class TabFragment method onCreateView.

@CallSuper
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.fragment_base, container, false);
    // Осторожно! Чувствительно к структуре разметки! (по идеи так должно работать чуть быстрее)
    fragmentContainer = (RelativeLayout) findViewById(R.id.fragment_container);
    coordinatorLayout = (CoordinatorLayout) fragmentContainer.findViewById(R.id.coordinator_layout);
    appBarLayout = (AppBarLayout) coordinatorLayout.findViewById(R.id.appbar_layout);
    toolbarLayout = (CollapsingToolbarLayout) appBarLayout.findViewById(R.id.toolbar_layout);
    toolbarBackground = (ImageView) toolbarLayout.findViewById(R.id.toolbar_image_background);
    toolbar = (Toolbar) toolbarLayout.findViewById(R.id.toolbar);
    toolbarImageView = (ImageView) toolbar.findViewById(R.id.toolbar_image_icon);
    toolbarTitleView = (TextView) toolbar.findViewById(R.id.toolbar_title);
    toolbarSubtitleView = (TextView) toolbar.findViewById(R.id.toolbar_subtitle);
    toolbarProgress = (ProgressBar) toolbar.findViewById(R.id.toolbar_progress);
    titlesWrapper = (LinearLayout) toolbar.findViewById(R.id.toolbar_titles_wrapper);
    toolbarSpinner = (Spinner) toolbar.findViewById(R.id.toolbar_spinner);
    notifyDot = findViewById(R.id.notify_dot);
    fragmentContent = (ViewGroup) coordinatorLayout.findViewById(R.id.fragment_content);
    additionalContent = (ViewGroup) coordinatorLayout.findViewById(R.id.additional_content);
    contentProgress = (ProgressBar) additionalContent.findViewById(R.id.content_progress);
    noNetwork = (LinearLayout) coordinatorLayout.findViewById(R.id.no_network);
    // // TODO: 20.03.17 удалить и юзать только там, где нужно
    fab = (FloatingActionButton) coordinatorLayout.findViewById(R.id.fab);
    contentController = new ContentController(contentProgress, additionalContent, fragmentContent);
    return view;
}
Also used : ContentController(forpdateam.ru.forpda.ui.views.ContentController) CallSuper(android.support.annotation.CallSuper) Nullable(android.support.annotation.Nullable)

Example 2 with ContentController

use of forpdateam.ru.forpda.ui.views.ContentController 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

Nullable (android.support.annotation.Nullable)2 ContentController (forpdateam.ru.forpda.ui.views.ContentController)2 Context (android.content.Context)1 Bundle (android.os.Bundle)1 CallSuper (android.support.annotation.CallSuper)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