This repository has been archived by the owner on Feb 8, 2022. It is now read-only.
/
MaterialViewPagerHelper.java
81 lines (71 loc) · 2.86 KB
/
MaterialViewPagerHelper.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
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
80
81
package com.github.florent37.materialviewpager;
import android.app.Activity;
import android.content.Context;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.RecyclerView;
import java.util.concurrent.ConcurrentHashMap;
/**
* Created by florentchampigny on 25/04/15.
* <p/>
* MaterialViewPagerHelper attach a MaterialViewPagerAnimator to an activity
* You can use MaterialViewPagerHelper to retrieve MaterialViewPagerAnimator from context
* Or register a scrollable to the current activity's MaterialViewPagerAnimator
*/
public class MaterialViewPagerHelper {
private static ConcurrentHashMap<Object, MaterialViewPagerAnimator> hashMap = new ConcurrentHashMap<>();
/**
* Register an MaterialViewPagerAnimator attached to an activity into the ConcurrentHashMap
*
* @param context the context
* @param animator the current MaterialViewPagerAnimator
*/
static void register(Context context, MaterialViewPagerAnimator animator) {
hashMap.put(context, animator);
}
static void unregister(Context context) {
if (context != null) {
hashMap.remove(context);
}
}
/**
* Register a RecyclerView to the current MaterialViewPagerAnimator
* Listen to RecyclerView.OnScrollListener so give to $[onScrollListener] your RecyclerView.OnScrollListener if you already use one
* For loadmore or anything else
*
* @param context current context
* @param recyclerView the scrollable
*/
public static void registerRecyclerView(Context context, RecyclerView recyclerView) {
if (context != null && hashMap.containsKey(context)) {
final MaterialViewPagerAnimator animator = hashMap.get(context);
if (animator != null) {
animator.registerRecyclerView(recyclerView);
}
}
}
/**
* Register a ScrollView to the current MaterialViewPagerAnimator
* Listen to ObservableScrollViewCallbacks so give to $[observableScrollViewCallbacks] your ObservableScrollViewCallbacks if you already use one
* For loadmore or anything else
*
* @param context current context
* @param mScrollView the scrollable
*/
public static void registerScrollView(Context context, NestedScrollView mScrollView) {
if (context != null && hashMap.containsKey(context)) {
final MaterialViewPagerAnimator animator = hashMap.get(context);
if (animator != null) {
animator.registerScrollView(mScrollView);
}
}
}
/**
* Retrieve the current MaterialViewPagerAnimator used in this context (Activity)
*
* @param context the context
* @return current MaterialViewPagerAnimator
*/
public static MaterialViewPagerAnimator getAnimator(Context context) {
return hashMap.get(context);
}
}