-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLazyFragment.java
42 lines (32 loc) · 1.02 KB
/
LazyFragment.java
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
package cz.martinforejt.slider.viewpager;
import android.support.annotation.CallSuper;
import android.support.v4.app.Fragment;
/**
* Created by Martin Forejt on 30.10.2016.
* forejt.martin97@gmail.com
*/
public abstract class LazyFragment extends Fragment {
private boolean _wasVisible = false;
@CallSuper
protected void onFirstVisible(){
_wasVisible = true;
}
protected void onVisibilityChange(boolean isVisible) {
throw new UnsupportedOperationException("method not overridden");
}
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
// is full initialized
if (LazyFragment.this.getActivity() == null) return;
// is first show - lazy load data
if (!_wasVisible) {
onFirstVisible();
}
// call visibility change
try {
onVisibilityChange(isVisibleToUser);
} catch (UnsupportedOperationException e){
// child not override 'onVisibilityChange' method
}
}
}