aboutsummaryrefslogtreecommitdiff
path: root/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderGapMarkerView.java
blob: db5a63703b5ddab47c998b04f91ea197566010d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package org.wordpress.android.ui.reader.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import org.wordpress.android.R;
import org.wordpress.android.models.ReaderTag;
import org.wordpress.android.ui.reader.services.ReaderPostService;
import org.wordpress.android.ui.reader.services.ReaderPostService.UpdateAction;
import org.wordpress.android.util.NetworkUtils;

/**
 * marker view between posts indicating a gap in time between them that can be filled in - designed
 * for use inside ReaderPostAdapter
 */
public class ReaderGapMarkerView extends RelativeLayout {
    private TextView mText;
    private ProgressBar mProgress;
    private ReaderTag mCurrentTag;

    public ReaderGapMarkerView(Context context) {
        super(context);
        initView(context);
    }

    public ReaderGapMarkerView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public ReaderGapMarkerView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context) {
        View view = inflate(context, R.layout.reader_gap_marker_view, this);
        mText = (TextView) view.findViewById(R.id.text_gap_marker);
        mProgress = (ProgressBar) view.findViewById(R.id.progress_gap_marker);

        mText.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                fillTheGap();
            }
        });
    }

    public void setCurrentTag(ReaderTag tag) {
        mCurrentTag = tag;
        hideProgress();
    }

    private void fillTheGap() {
        if (mCurrentTag == null
                || !NetworkUtils.checkConnection(getContext())) {
            return;
        }

        // start service to fill the gap - EventBus will notify the owning fragment of new posts,
        // and will take care of hiding this view
        ReaderPostService.startServiceForTag(getContext(), mCurrentTag, UpdateAction.REQUEST_OLDER_THAN_GAP);
        showProgress();
    }

    private void showProgress() {
        mText.setVisibility(View.INVISIBLE);
        mProgress.setVisibility(View.VISIBLE);
    }

    private void hideProgress() {
        mText.setVisibility(View.VISIBLE);
        mProgress.setVisibility(View.GONE);
    }
}