-
Notifications
You must be signed in to change notification settings - Fork 66
/
ListSupportFragment.java
172 lines (148 loc) · 5.98 KB
/
ListSupportFragment.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package com.brucetoo.listvideoplay.demo;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.brucetoo.listvideoplay.MainActivity;
import com.brucetoo.listvideoplay.R;
import com.brucetoo.videoplayer.tracker.IViewTracker;
import com.brucetoo.videoplayer.tracker.Tracker;
import com.brucetoo.videoplayer.tracker.VisibleChangeListener;
import com.brucetoo.videoplayer.scrolldetector.ListScrollDetector;
import com.brucetoo.videoplayer.videomanage.controller.DefaultControllerView;
import com.brucetoo.videoplayer.videomanage.interfaces.PlayerItemChangeListener;
import com.brucetoo.videoplayer.videomanage.interfaces.VideoPlayerListener;
import com.brucetoo.videoplayer.videomanage.meta.DefaultMetaData;
import com.brucetoo.videoplayer.videomanage.player.RatioImageView;
import com.joanzapata.android.BaseAdapterHelper;
import com.joanzapata.android.QuickAdapter;
import com.squareup.picasso.Picasso;
/**
* Created by Bruce Too
* On 05/04/2017.
* At 09:28
*/
public class ListSupportFragment extends Fragment implements View.OnClickListener, VisibleChangeListener, PlayerItemChangeListener, VideoPlayerListener {
public static final String TAG = "ListSupportFragment";
private ListView mListView;
private ImageView mImageTop;
private TextView mTextCalculator;
private static final float VISIBLE_THRESHOLD = 0.5f;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_video_support, container, false);
}
@Override
public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mListView = (ListView) view.findViewById(R.id.list_view);
QuickAdapter<VideoModel> adapter = new QuickAdapter<VideoModel>(getActivity(), R.layout.item_list_view_new, ListDataGenerater.datas) {
@Override
protected void convert(BaseAdapterHelper helper, VideoModel item) {
RatioImageView imageCover = (RatioImageView) helper.getView(R.id.view_tracker);
Picasso.with(getActivity())
.load(item.coverImage)
.into(imageCover);
imageCover.setRatio(16,9);
//bind meta data
imageCover.setTag(R.id.tag_tracker_view,new DefaultMetaData(item.videoUrl));
imageCover.setOnClickListener(ListSupportFragment.this);
}
};
mListView.setAdapter(adapter);
mListView.setRecyclerListener(new AbsListView.RecyclerListener() {
@Override
public void onMovedToScrapHeap(View view) {
//the tracker view is moved to scrap,and be re-used,so we need detach view in decor
IViewTracker tracker = Tracker.getViewTracker(getActivity());
if(tracker != null) {
View trackerView = tracker.getTrackerView();
if (trackerView != null && trackerView.equals(view.findViewById(tracker.getTrackerViewId()))) {
//TODO Configuration Changed may cause problem
Log.e(TAG, "onMovedToScrapHeap -> " + view.findViewById(R.id.view_tracker));
// Tracker.detach(getActivity());
}
}
}
});
Tracker.addPlayerItemChangeListener(this);
Tracker.addVideoPlayerListener(this);
}
@Override
public void onClick(View v) {
Log.e(TAG, "onMovedToScrapHeap onClick -> " + v);
if(!Tracker.isSameTrackerView(getActivity(),v)) {
Tracker.attach(getActivity())
.trackView(v)
.into(new ListScrollDetector(mListView))
.controller(new DefaultControllerView())
.visibleListener(this);
}
((MainActivity) getActivity()).addDetailFragment();
}
@Override
public void onVisibleChange(float visibleRatio, IViewTracker tracker) {
Log.e(TAG, "onVisibleChange : edge -> " + tracker.getEdgeString());
if(!tracker.getFloatLayerView().getVideoPlayerView().isComplete()) {
if (visibleRatio <= 0.5) {
tracker.hide();
} else {
tracker.show();
}
}
}
@Override
public void onPlayerItemChanged(IViewTracker viewTracker) {
Log.i(TAG, "onPlayerItemChanged ");
}
@Override
public void onVideoSizeChanged(IViewTracker viewTracker, int width, int height) {
Log.e(TAG, "onVideoSizeChanged");
}
@Override
public void onVideoPrepared(IViewTracker viewTracker) {
Log.e(TAG, "onVideoPrepared");
}
@Override
public void onVideoCompletion(IViewTracker viewTracker) {
Log.e(TAG, "onVideoCompletion");
}
@Override
public void onError(IViewTracker viewTracker, int what, int extra) {
Log.e(TAG, "onError");
}
@Override
public void onBufferingUpdate(IViewTracker viewTracker, int percent) {
Log.e(TAG, "onBufferingUpdate");
}
@Override
public void onVideoStopped(IViewTracker viewTracker) {
Log.e(TAG, "onVideoStopped");
}
@Override
public void onVideoReset(IViewTracker viewTracker) {
}
@Override
public void onVideoReleased(IViewTracker viewTracker) {
}
@Override
public void onInfo(IViewTracker viewTracker, int what) {
Log.e(TAG, "onInfo");
}
@Override
public void onVideoStarted(IViewTracker viewTracker) {
Log.e(TAG, "onVideoStarted");
}
@Override
public void onVideoPaused(IViewTracker viewTracker) {
Log.e(TAG, "onVideoPaused");
}
}