Search in sources :

Example 1 with Diary

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);
    }
}
Also used : Context(android.content.Context) Diary(me.zhanghai.android.douya.network.api.info.frodo.Diary) ImageView(android.widget.ImageView) BindView(butterknife.BindView) TextView(android.widget.TextView) View(android.view.View) FriendlyCardView(me.zhanghai.android.douya.ui.FriendlyCardView)

Example 2 with Diary

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);
    }
}
Also used : DiaryUpdatedEvent(me.zhanghai.android.douya.eventbus.DiaryUpdatedEvent) Diary(me.zhanghai.android.douya.network.api.info.frodo.Diary)

Example 3 with Diary

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));
        }
    }
}
Also used : Diary(me.zhanghai.android.douya.network.api.info.frodo.Diary) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 4 with Diary

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);
    }
}
Also used : DiaryUpdatedEvent(me.zhanghai.android.douya.eventbus.DiaryUpdatedEvent) Diary(me.zhanghai.android.douya.network.api.info.frodo.Diary)

Example 5 with Diary

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;
        }
    }
}
Also used : Diary(me.zhanghai.android.douya.network.api.info.frodo.Diary) Subscribe(org.greenrobot.eventbus.Subscribe)

Aggregations

Diary (me.zhanghai.android.douya.network.api.info.frodo.Diary)5 DiaryUpdatedEvent (me.zhanghai.android.douya.eventbus.DiaryUpdatedEvent)2 Subscribe (org.greenrobot.eventbus.Subscribe)2 Context (android.content.Context)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 FriendlyCardView (me.zhanghai.android.douya.ui.FriendlyCardView)1