@Override public void updateListView(ArrayList<Comment> commentlist) { mRecyclerView.addOnScrollListener(mOnScrollListener); mDatas = commentlist; mAdapter.setData(commentlist); mHeaderAndFooterRecyclerViewAdapter.notifyDataSetChanged(); }
private void fixCommentCount() { Broadcast broadcast = mBroadcastAdapter.getBroadcast(); if (broadcast != null) { int commentCount = mCommentAdapter.getItemCount(); if (broadcast.commentCount < commentCount) { broadcast.commentCount = commentCount; EventBus.getDefault().post(new BroadcastUpdatedEvent(broadcast)); } } }
@Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); mRetainDataFragment.put(RETAIN_DATA_KEY_BROADCAST, mBroadcastAdapter.getBroadcast()); mRetainDataFragment.put(RETAIN_DATA_KEY_COMMENT_LIST, mCommentAdapter.getList()); mRetainDataFragment.put(RETAIN_DATA_KEY_CAN_LOAD_MORE_COMMENTS, mCanLoadMoreComments); mRetainDataFragment.put( RETAIN_DATA_KEY_LOADING_BROADCAST_OR_COMMENT_LIST, mLoadingBroadcastOrCommentList); mRetainDataFragment.put(RETAIN_DATA_KEY_SENDING_COMMENT, mSendingComment); mRetainDataFragment.put(RETAIN_DATA_KEY_VIEW_STATE, onSaveViewState()); }
private void onLoadCommentListResponse( boolean successful, CommentList result, VolleyError error, LoadCommentListState state) { if (successful) { List<Comment> commentList = result.comments; mCanLoadMoreComments = commentList.size() == state.count; if (state.loadMore) { mCommentAdapter.addAll(commentList); } else { mCommentAdapter.replace(commentList); } } else { LogUtils.e(error.toString()); ToastUtils.show(ApiError.getErrorString(error, this), this); } setCommentsRefreshing(false, state.loadMore); mLoadingBroadcastOrCommentList = false; if (successful) { fixCommentCount(); } }
@Override public void onStart() { super.onStart(); // Only auto-load when initially empty, not loaded but empty. boolean autoLoadComments = mCommentAdapter.getItemCount() == 0 && mCanLoadMoreComments; if (mBroadcastAdapter.getItemCount() == 0) { loadBroadcast(autoLoadComments); } else if (autoLoadComments) { loadCommentList(false); } EventBus.getDefault().register(this); }
private void loadCommentList(boolean loadMore) { if (mLoadingBroadcastOrCommentList || (loadMore && !mCanLoadMoreComments)) { return; } Integer start = loadMore ? mCommentAdapter.getItemCount() : null; final int count = COMMENT_COUNT_PER_LOAD; ApiRequest<CommentList> request = ApiRequests.newBroadcastCommentListRequest(mBroadcastId, start, count, this); LoadCommentListState state = new LoadCommentListState(loadMore, count); RequestFragment.startRequest(REQUEST_CODE_LOAD_COMMENT_LIST, request, state, this); mLoadingBroadcastOrCommentList = true; setCommentsRefreshing(true, loadMore); }
private void onSendCommentResponse(boolean successful, Comment result, VolleyError error) { if (successful) { if (!mCanLoadMoreComments) { mCommentAdapter.add(result); fixCommentCount(); } else { ToastUtils.show(R.string.broadcast_send_comment_successful, this); } mBroadcastCommentList.scrollToPosition(mAdapter.getItemCount() - 1); mCommentEdit.setText(null); } else { LogUtils.e(error.toString()); ToastUtils.show( getString( R.string.broadcast_send_comment_failed_format, ApiError.getErrorString(error, this)), this); } setSendingComment(false); }
@Keep public void onEventMainThread(BroadcastCommentDeletedEvent event) { if (event.broadcastId == mBroadcastId) { mCommentAdapter.removeById(event.commentId); } }
private void setCommentsRefreshing(boolean refreshing, boolean loadMore) { mAdapter.setProgressVisible(refreshing && (mCommentAdapter.getItemCount() == 0 || loadMore)); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // IPPからコメント読み込むメソッド public void showCommentList(int target_year, int target_month, long until, int near) { // オンラインなら外部DBから他人のデータ読み出し// try { waitBar.setVisibility(View.VISIBLE); listView.setVisibility(View.GONE); } catch (NullPointerException e) { Log.d(TAG, e.toString()); } if (NetworkManager.isConnected(getActivity().getApplicationContext())) { adapter.clear(); // 読みだすデータの日時の範囲を指定 int year = 0; int month = 0; long mUntil = 0; this.until = until; if (target_month == 0 && target_year == 0) { // 今月1日のUNIXタイムスタンプ(ミリ秒)を取得 year = calendar.get(Calendar.YEAR); month = calendar.get(Calendar.MONTH); calendar.set(year, month, 1, 0, 0, 0); since = calendar.getTimeInMillis(); // 今月頭から if (until == 0) { mUntil = System.currentTimeMillis(); // 現在まで } else { mUntil = until; } } else { // 月と日を指定されたら year = target_year; calendar.set(year, target_month, 1, 0, 0, 0); // 指定月の1日から since = calendar.getTimeInMillis(); if (until == 0) { calendar.add(Calendar.MONTH, 1); mUntil = calendar.getTimeInMillis(); // 次の月の1日まで calendar.add(Calendar.MONTH, -1); // 戻しとく } else { mUntil = until; } } IPPGeoResourceClient client = new IPPGeoResourceClient(getSherlockActivity().getApplicationContext()); client.setAuthKey(ipp_auth_key); jp.innovationplus.ipp.client.IPPGeoResourceClient.QueryCondition condition = new jp.innovationplus.ipp.client.IPPGeoResourceClient.QueryCondition(); condition.setSince(since); condition.setUntil(mUntil); condition.setCount(10); condition.eq("pair_common_id", pair_common_id); if (near == 1) { condition.setBoundByRadiusSquare( mNowLocation.getLatitude(), mNowLocation.getLongitude(), radiusSquare); } condition.build(); client.query(CommentGeoResource.class, condition, new CommentGeoGetCallback()); } else { Toast.makeText( getSherlockActivity(), res.getString(R.string.message_network_disabled), Toast.LENGTH_SHORT) .show(); } }
@Override public void addAtUser(int position) { String content = FormatHelper.formatCommentAtUser(mAdapter.getUsername(position)); etContent.setText(content); etContent.setSelection(content.length()); }
@Override public void bindComment(Comment[] comments) { mAdapter.updateData(comments); }