use of me.zhanghai.android.douya.network.api.info.frodo.Diary in project Douya by DreaminginCodeZH.
the class ProfileDiariesLayout method bind.
public void bind(final User user, List<Diary> diaryList) {
final Context context = getContext();
OnClickListener viewMoreListener = new OnClickListener() {
@Override
public void onClick(View view) {
// TODO
UriHandler.open(StringUtils.formatUs("https://www.douban.com/people/%s/notes", user.getIdOrUid()), context);
// context.startActivity(DiaryListActivity.makeIntent(mUser, context));
}
};
mTitleText.setOnClickListener(viewMoreListener);
mViewMoreText.setOnClickListener(viewMoreListener);
int i = 0;
for (final Diary diary : diaryList) {
if (i >= DIARY_COUNT_MAX) {
break;
}
if (i >= mDiaryList.getChildCount()) {
LayoutInflater.from(context).inflate(R.layout.profile_diary_item, mDiaryList);
}
View diaryLayout = mDiaryList.getChildAt(i);
DiaryLayoutHolder holder = (DiaryLayoutHolder) diaryLayout.getTag();
if (holder == null) {
holder = new DiaryLayoutHolder(diaryLayout);
diaryLayout.setTag(holder);
ViewUtils.setTextViewLinkClickable(holder.titleText);
}
if (!TextUtils.isEmpty(diary.cover)) {
holder.coverImage.setVisibility(VISIBLE);
ImageUtils.loadImage(holder.coverImage, diary.cover);
} else {
holder.coverImage.setVisibility(GONE);
}
holder.titleText.setText(diary.title);
holder.abstractText.setText(diary.abstract_);
diaryLayout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
// TODO
UriHandler.open(StringUtils.formatUs("https://www.douban.com/note/%d", diary.id), context);
// context.startActivity(DiaryActivity.makeIntent(diary, context));
}
});
++i;
}
ViewUtils.setVisibleOrGone(mDiaryList, i != 0);
ViewUtils.setVisibleOrGone(mEmptyView, i == 0);
if (user.diaryCount > i) {
mViewMoreText.setText(context.getString(R.string.view_more_with_count_format, user.diaryCount));
} else {
mViewMoreText.setVisibility(GONE);
}
for (int count = mDiaryList.getChildCount(); i < count; ++i) {
ViewUtils.setVisibleOrGone(mDiaryList.getChildAt(i), false);
}
}
use of me.zhanghai.android.douya.network.api.info.frodo.Diary in project Douya by DreaminginCodeZH.
the class UserDiaryListResource method onLoadFinished.
@Override
protected void onLoadFinished(boolean more, int count, boolean successful, List<Diary> response, ApiError error) {
if (successful) {
if (more) {
append(response);
getListener().onLoadDiaryListFinished(getRequestCode());
getListener().onDiaryListAppended(getRequestCode(), Collections.unmodifiableList(response));
} else {
set(response);
getListener().onLoadDiaryListFinished(getRequestCode());
getListener().onDiaryListChanged(getRequestCode(), Collections.unmodifiableList(get()));
}
for (Diary diary : response) {
EventBusUtils.postAsync(new DiaryUpdatedEvent(diary, this));
}
} else {
getListener().onLoadDiaryListFinished(getRequestCode());
getListener().onLoadDiaryListError(getRequestCode(), error);
}
}
use of me.zhanghai.android.douya.network.api.info.frodo.Diary in project Douya by DreaminginCodeZH.
the class UserDiaryListResource method onDiaryUpdated.
@Subscribe(threadMode = ThreadMode.POSTING)
public void onDiaryUpdated(DiaryUpdatedEvent event) {
if (event.isFromMyself(this) || isEmpty()) {
return;
}
List<Diary> diaryList = get();
for (int i = 0, size = diaryList.size(); i < size; ++i) {
Diary diary = diaryList.get(i);
if (diary.id == event.diary.id) {
diaryList.set(i, event.diary);
getListener().onDiaryChanged(getRequestCode(), i, diaryList.get(i));
}
}
}
use of me.zhanghai.android.douya.network.api.info.frodo.Diary in project Douya by DreaminginCodeZH.
the class UserDiaryListResource method onLoadFinished.
private void onLoadFinished(boolean more, int count, boolean successful, List<Diary> response, VolleyError error) {
getListener().onLoadDiaryListFinished(getRequestCode());
if (successful) {
if (more) {
append(response);
getListener().onDiaryListAppended(getRequestCode(), Collections.unmodifiableList(response));
} else {
set(response);
getListener().onDiaryListChanged(getRequestCode(), Collections.unmodifiableList(get()));
}
for (Diary diary : response) {
EventBusUtils.postAsync(new DiaryUpdatedEvent(diary, this));
}
} else {
getListener().onLoadDiaryListError(getRequestCode(), error);
}
}
use of me.zhanghai.android.douya.network.api.info.frodo.Diary in project Douya by DreaminginCodeZH.
the class UserDiaryListResource method onDiaryDeleted.
@Subscribe(threadMode = ThreadMode.POSTING)
public void onDiaryDeleted(DiaryDeletedEvent event) {
if (event.isFromMyself(this) || isEmpty()) {
return;
}
List<Diary> diaryList = get();
for (int i = 0, size = diaryList.size(); i < size; ) {
Diary diary = diaryList.get(i);
if (diary.id == event.diaryId) {
diaryList.remove(i);
getListener().onDiaryRemoved(getRequestCode(), i);
--size;
} else {
++i;
}
}
}
Aggregations