OpenLotteryBoxDialog.java
7.92 KB
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package com.chudiangameplay.android.dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.chudiangameplay.android.R;
import com.chudiangameplay.android.adapter.LotteryResultListAdapter;
import com.chudiangameplay.android.bean.GiftInfo;
import com.chudiangameplay.android.bean.LotteryInfo;
import com.chudiangameplay.android.event.EventOneMore;
import com.chudiangameplay.android.interface_.CommCallBack;
import com.chudiangameplay.android.interface_.OkHttpCallBack;
import com.chudiangameplay.android.manager.API_RoomManager;
import com.chudiangameplay.android.module_im.ui.view.IM_EmojiGridViewV2;
import com.chudiangameplay.android.responce.BaseResponce;
import com.chudiangameplay.android.responce.LotteryResultRespson;
import com.chudiangameplay.android.tool.CommToast;
import com.chudiangameplay.android.ui.view.GridSpacingItemDecoration;
import com.chudiangameplay.android.util.Util;
import com.opensource.svgaplayer.SVGACallback;
import com.opensource.svgaplayer.SVGADrawable;
import com.opensource.svgaplayer.SVGAImageView;
import com.opensource.svgaplayer.SVGAParser;
import com.opensource.svgaplayer.SVGAVideoEntity;
import org.greenrobot.eventbus.EventBus;
import org.jetbrains.annotations.NotNull;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
/**
* Created by 0 on 2019/8/22.
*/
public class OpenLotteryBoxDialog extends DialogFragment implements View.OnClickListener {
RecyclerView recyclerview;
SVGAImageView svga_iv;
List<LotteryResultRespson.LotteryResult> lotteryResults;
View fl_result;
static LotteryResultRespson lotteryResultRespson;
static String roomNo, number;
static LotteryInfo info;
static CommCallBack callBack;
public static void open(final FragmentActivity context, String roomNo, LotteryInfo info, String number, final CommCallBack callBack) {
OpenLotteryBoxDialog.roomNo = roomNo;
OpenLotteryBoxDialog.info = info;
OpenLotteryBoxDialog.number = number;
OpenLotteryBoxDialog.callBack = callBack;
API_RoomManager.lottery_activity(context, roomNo, info.id, number, new OkHttpCallBack() {
@Override
public void onSuccess(BaseResponce baseResponce) {
if (BaseResponce.Status_Success.equals(baseResponce.status)) {
OpenLotteryBoxDialog.lotteryResultRespson = (LotteryResultRespson) baseResponce;
Bundle args = new Bundle();
args.putSerializable("lotteryResults", (Serializable) lotteryResultRespson.data);
OpenLotteryBoxDialog fragment = new OpenLotteryBoxDialog();
fragment.setArguments(args);
fragment.show(context.getSupportFragmentManager(), null);
} else {
CommToast.showToast(context, baseResponce.msg);
}
}
@Override
public void onFailure(BaseResponce baseResponce) {
}
});
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_FRAME, R.style.myDialog);
lotteryResults = (List<LotteryResultRespson.LotteryResult>) getArguments().getSerializable("lotteryResults");
}
@Override
public void onStart() {
super.onStart();
Window win = getDialog().getWindow();
// 一定要设置Background,如果不设置,window属性设置无效
win.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
DisplayMetrics dm = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
WindowManager.LayoutParams params = win.getAttributes();
// 使用ViewGroup.LayoutParams,以便Dialog 宽度充满整个屏幕
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
win.setAttributes(params);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.dialog_open_lottery, container, false);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
initView(view);
}
private void initView(View view) {
recyclerview = view.findViewById(R.id.recyclerview);
svga_iv = view.findViewById(R.id.svga_iv);
fl_result = view.findViewById(R.id.fl_result);
view.findViewById(R.id.view_bg).setOnClickListener(this);
view.findViewById(R.id.tv_ok).setOnClickListener(this);
TextView tv_one_more = view.findViewById(R.id.tv_one_more);
tv_one_more.setOnClickListener(this);
tv_one_more.setText("再开" + number + "个");
GridLayoutManager manager = new GridLayoutManager(getContext(), lotteryResults.size() > 1 ? 5 : 1);
recyclerview.setLayoutManager(manager);
recyclerview.addItemDecoration(new GridSpacingItemDecoration(5, Util.dip2px(getContext(), 8), false));
if (lotteryResults.size()>10){
recyclerview.getLayoutParams().height = Util.dip2px(getActivity(),168);
}
LotteryResultListAdapter adapter = new LotteryResultListAdapter(getActivity(), null);
recyclerview.setAdapter(adapter);
adapter.setData(lotteryResults);
if (info != null) {
try {
loadSvga(info.objectGifUrl);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
private void loadSvga(String objectGifUrl) throws MalformedURLException {
new SVGAParser(getActivity()).decodeFromURL(new URL(objectGifUrl), new SVGAParser.ParseCompletion() {
@Override
public void onComplete(@NotNull SVGAVideoEntity svgaVideoEntity) {
SVGADrawable drawable = new SVGADrawable(svgaVideoEntity);
svga_iv.setImageDrawable(drawable);
svga_iv.setCallback(new SVGACallback() {
@Override
public void onPause() {
}
@Override
public void onFinished() {
fl_result.setVisibility(View.VISIBLE);
if (callBack != null) {
callBack.onResult(lotteryResultRespson.data);
}
}
@Override
public void onRepeat() {
}
@Override
public void onStep(int i, double v) {
}
});
svga_iv.startAnimation();
}
@Override
public void onError() {
fl_result.setVisibility(View.VISIBLE);
}
});
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.tv_ok:
case R.id.fl_result:
dismiss();
break;
case R.id.tv_one_more:
open(getActivity(), roomNo, info, number, callBack);
dismiss();
break;
}
}
}