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;
}
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;
}
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;
}
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);
}
});
}
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);
}
Aggregations