Search in sources :

Example 86 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout in project Slide by ccrama.

the class ContributionsView method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false);
    final RecyclerView rv = ((RecyclerView) v.findViewById(R.id.vertical_content));
    final PreCachingLayoutManager mLayoutManager;
    mLayoutManager = new PreCachingLayoutManager(getContext());
    rv.setLayoutManager(mLayoutManager);
    rv.setItemViewCacheSize(2);
    v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);
    final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout);
    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(id, getActivity()));
    // If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    // So, we estimate the height of the header in dp
    mSwipeRefreshLayout.setProgressViewOffset(false, Constants.TAB_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP, Constants.TAB_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);
    mSwipeRefreshLayout.post(new Runnable() {

        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });
    if (where.equals("saved") && getActivity() instanceof Profile)
        posts = new ContributionPostsSaved(id, where, ((Profile) getActivity()).category);
    else
        posts = new ContributionPosts(id, where);
    // noinspection StringEquality
    if (where == "hidden")
        adapter = new ContributionAdapter(getActivity(), posts, rv, true);
    else
        adapter = new ContributionAdapter(getActivity(), posts, rv);
    rv.setAdapter(adapter);
    posts.bindAdapter(adapter, mSwipeRefreshLayout);
    // TODO catch errors
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            posts.loadMore(adapter, id, true);
        // TODO catch errors
        }
    });
    rv.addOnScrollListener(new ToolbarScrollHideHandler((Toolbar) getActivity().findViewById(R.id.toolbar), getActivity().findViewById(R.id.header)) {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            visibleItemCount = rv.getLayoutManager().getChildCount();
            totalItemCount = rv.getLayoutManager().getItemCount();
            if (rv.getLayoutManager() instanceof PreCachingLayoutManager) {
                pastVisiblesItems = ((PreCachingLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition();
            } else {
                int[] firstVisibleItems = null;
                firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(firstVisibleItems);
                if (firstVisibleItems != null && firstVisibleItems.length > 0) {
                    pastVisiblesItems = firstVisibleItems[0];
                }
            }
            if (!posts.loading) {
                if ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount && !posts.nomore) {
                    posts.loading = true;
                    posts.loadMore(adapter, id, false);
                }
            }
        }
    });
    return v;
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) PreCachingLayoutManager(me.ccrama.redditslide.Views.PreCachingLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) Profile(me.ccrama.redditslide.Activities.Profile) ContributionPosts(me.ccrama.redditslide.Adapters.ContributionPosts) ContributionPostsSaved(me.ccrama.redditslide.Adapters.ContributionPostsSaved) ContributionAdapter(me.ccrama.redditslide.Adapters.ContributionAdapter) RecyclerView(android.support.v7.widget.RecyclerView) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler) Toolbar(android.support.v7.widget.Toolbar)

Example 87 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout 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)

Example 88 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout in project CCIP-Android by CCIP-App.

the class MainFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    View view = inflater.inflate(R.layout.fragment_main, container, false);
    notCOSCUPWifiView = view.findViewById(R.id.not_conf_wifi);
    invalidTokenMsg = (TextView) view.findViewById(R.id.invalid_token_msg);
    invalidTokenMsg.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            IntentIntegrator integrator = new IntentIntegrator(mActivity);
            integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
            integrator.setPrompt(getString(R.string.scan_kktix_qrcode));
            integrator.setCameraId(0);
            integrator.setBeepEnabled(false);
            integrator.setBarcodeImageEnabled(false);
            integrator.initiateScan();
        }
    });
    scenarioView = (RecyclerView) view.findViewById(R.id.scenarios);
    swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipeContainer);
    mActivity = getActivity();
    scenarioView.setLayoutManager(new LinearLayoutManager(mActivity));
    scenarioView.setItemAnimator(new DefaultItemAnimator());
    if (mActivity.getIntent().getAction().equals(Intent.ACTION_VIEW)) {
        String token = mActivity.getIntent().getData().getQueryParameter("token");
        if (token != null) {
            PreferenceUtil.setIsNewToken(mActivity, true);
            PreferenceUtil.setToken(mActivity, token);
        }
    }
    if (PreferenceUtil.getToken(mActivity) == null) {
        invalidTokenMsg.setVisibility(View.VISIBLE);
    }
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            updateStatus();
        }
    });
    return view;
}
Also used : IntentIntegrator(com.google.zxing.integration.android.IntentIntegrator) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Nullable(android.support.annotation.Nullable)

Example 89 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout in project BaseRecyclerViewAdapter by donghan0912.

the class GlidFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    SwipeRefreshLayout refreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swip_refresh);
    refreshLayout.setEnabled(false);
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    GridLayoutManager manager = new GridLayoutManager(getActivity(), 2);
    recyclerView.setLayoutManager(manager);
    for (int i = 0; i < 20; i++) {
        list.add(new SingleItem(getAvatar()));
    }
    final BaseRecyclerViewAdapter adapter = new BaseRecyclerViewAdapter(list);
    recyclerView.setAdapter(adapter);
    adapter.addHeader(new SimpleItem(R.layout.layout_head));
    adapter.setExtraItem(new SimpleItem(R.layout.layout_loadmore));
    manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            return adapter.isExtra(position) || adapter.isHeader(position) || adapter.isFooter(position) || adapter.isStatus(position) ? 2 : 1;
        }
    });
    recyclerView.addOnScrollListener(new EndlessRecyclerOnScrollListener() {

        @Override
        public void onLoadMore() {
            if (!loadMore) {
                return;
            }
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    new Handler().postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            List<BaseItem> list2 = new ArrayList<>();
                            for (int i = 0; i < 20; i++) {
                                list2.add(new SingleItem(getAvatar()));
                            }
                            list.addAll(list2);
                            if (list.size() > 40) {
                                adapter.removeExtraItem();
                                loadMore = false;
                            }
                            adapter.addData(list2);
                        }
                    }, 3000);
                }
            }, 3000);
        }
    });
}
Also used : EndlessRecyclerOnScrollListener(com.hpu.baserecyclerviewadapter.EndlessRecyclerOnScrollListener) Handler(android.os.Handler) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) GridLayoutManager(android.support.v7.widget.GridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) SingleItem(com.hpu.baserecyclerviewadapter.sample.item.SingleItem) ArrayList(java.util.ArrayList) List(java.util.List) BaseRecyclerViewAdapter(com.hpu.baserecyclerviewadapter.BaseRecyclerViewAdapter) SimpleItem(com.hpu.baserecyclerviewadapter.SimpleItem)

Example 90 with SwipeRefreshLayout

use of android.support.v4.widget.SwipeRefreshLayout in project BaseRecyclerViewAdapter by donghan0912.

the class MultiTypeFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    SwipeRefreshLayout refreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swip_refresh);
    refreshLayout.setEnabled(false);
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    list = new ArrayList<>();
    for (int i = 0; i < 6; i++) {
        list.add(new FirstItem("第" + i + "条数据"));
        list.add(new SecondItem("第" + i + "条数据"));
        if (i == 0) {
            list.add(new ThirdItem(R.drawable.luoluo_1));
        } else if (i == 1) {
            list.add(new ThirdItem(R.drawable.luoluo_2));
        } else if (i == 2) {
            list.add(new ThirdItem(R.drawable.luoluo_3));
        } else if (i == 3) {
            list.add(new ThirdItem(R.drawable.luoluo_4));
        } else if (i == 4) {
            list.add(new ThirdItem(R.drawable.luoluo_5));
        } else if (i == 5) {
            list.add(new ThirdItem(R.drawable.luoluo_6));
        }
    }
    final BaseRecyclerViewAdapter baseRecyclerViewAdapter = new BaseRecyclerViewAdapter();
    recyclerView.setAdapter(baseRecyclerViewAdapter);
    baseRecyclerViewAdapter.setOnItemClickListener(new BaseRecyclerViewAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(View view, int position) {
            Toast.makeText(getContext(), position + "", Toast.LENGTH_SHORT).show();
        }
    });
    baseRecyclerViewAdapter.setOnItemLongClickListener(new BaseRecyclerViewAdapter.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(View view, int position) {
            Toast.makeText(getContext(), position + "", Toast.LENGTH_SHORT).show();
            return false;
        }
    });
    baseRecyclerViewAdapter.setStatusItem(new SimpleItem(R.layout.layout_loading));
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            baseRecyclerViewAdapter.setStatusItem(new SimpleItem(R.layout.layout_error) {

                @Override
                public void onBindViewHolder(BaseViewHolder holder, int position) {
                    holder.setOnClickListener(R.id.retry, new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            baseRecyclerViewAdapter.setStatusItem(new SimpleItem(R.layout.layout_loading));
                            new Handler().postDelayed(new Runnable() {

                                @Override
                                public void run() {
                                    baseRecyclerViewAdapter.setData(list);
                                }
                            }, 3000);
                        }
                    });
                }
            });
        }
    }, 3000);
}
Also used : BaseViewHolder(com.hpu.baserecyclerviewadapter.BaseViewHolder) Handler(android.os.Handler) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) ThirdItem(com.hpu.baserecyclerviewadapter.sample.multi.ThirdItem) SecondItem(com.hpu.baserecyclerviewadapter.sample.multi.SecondItem) FirstItem(com.hpu.baserecyclerviewadapter.sample.multi.FirstItem) RecyclerView(android.support.v7.widget.RecyclerView) BaseRecyclerViewAdapter(com.hpu.baserecyclerviewadapter.BaseRecyclerViewAdapter) SimpleItem(com.hpu.baserecyclerviewadapter.SimpleItem)

Aggregations

SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)115 View (android.view.View)65 RecyclerView (android.support.v7.widget.RecyclerView)58 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)43 TextView (android.widget.TextView)30 Bundle (android.os.Bundle)21 Intent (android.content.Intent)20 Handler (android.os.Handler)17 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)16 Toolbar (android.support.v7.widget.Toolbar)16 ArrayList (java.util.ArrayList)16 AdapterView (android.widget.AdapterView)14 ListView (android.widget.ListView)12 ImageView (android.widget.ImageView)11 GridLayoutManager (android.support.v7.widget.GridLayoutManager)10 Context (android.content.Context)9 LayoutInflater (android.view.LayoutInflater)9 ViewGroup (android.view.ViewGroup)9 DialogInterface (android.content.DialogInterface)8 FrameLayout (android.widget.FrameLayout)7