doum
6 天以前 2b287056e2f59518888d05a1bbc7e5a55fbd84d5
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
package com.doumee.lib_coremodel.base.livedata;
 
 
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.Observer;
 
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
 
/**
 * 提供观察状态事件
 * @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
 */
public class StatusEvent extends SingleLiveEvent<Integer> {
 
 
    public void observe(LifecycleOwner owner, final StatusObserver observer) {
        super.observe(owner, new Observer<Integer>() {
            @Override
            public void onChanged(@Nullable Integer t) {
            if (t != null) {
                observer.onStatusChanged(t);
            }
            }
        });
    }
 
    public interface StatusObserver{
        void onStatusChanged(@Status int status);
    }
 
    /**
     * 状态
     */
    @IntDef({Status.LOADING, Status.SUCCESS, Status.FAILURE, Status.ERROR})
    @Retention(RetentionPolicy.SOURCE)
    public @interface Status {
        int LOADING = 0;
        int SUCCESS = 1;
        int FAILURE = 2;
        int ERROR = 3;
    }
}