GimiCinemaBusiness.java
3.74 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
package com.gimi.common.cinema.utils;
import android.content.Context;
import android.text.TextUtils;
import com.gimi.common.cinema.model.AsyncCallback;
import com.gimi.common.cinema.model.MovieMessage;
import com.gimi.common.cinema.model.Urls;
import com.gimi.common.cinema.model.WrongMsg;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* Created by pc on 2014/12/23.
*/
public class GimiCinemaBusiness {
private Context context;
public GimiCinemaBusiness(Context context) {
this.context = context;
}
public void getMovieMessage(final String id, final AsyncCallback<MovieMessage> callback) {
new Thread() {
public void run() {
if (callback != null)
callback.onStart();
WrongMsg wrongMsg = new WrongMsg();
MovieMessage result = null;
try {
Gson gson = new Gson();
String s = "";
s = OkHttpClientManager.getAsString(Urls.BASIC_URL + Urls.MOVIE_MESSAGE + id.trim());
wrongMsg = gson.fromJson(s, new TypeToken<WrongMsg>() {
}.getType());
if (wrongMsg.getCode() != 0) {
if (callback != null)
callback.onFailure(wrongMsg);
} else {
result = gson.fromJson(s, new TypeToken<MovieMessage>() {
}.getType());
if (callback != null)
callback.onSuccess(result);
}
} catch (JsonSyntaxException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (callback != null)
callback.onDone();
}
}.start();
}
public Thread getMovieMessages(final String id, final AsyncCallback<MovieMessage> callback) {
return new Thread() {
public void run() {
if (callback != null)
callback.onStart();
WrongMsg wrongMsg = new WrongMsg();
MovieMessage result = null;
Gson gson = new Gson();
String s = "";
List<String> keys = new ArrayList<String>();
List<String> values = new ArrayList<String>();
try {
s = OkHttpClientManager.getAsString(Urls.BASIC_URL + Urls.MOVIE_MESSAGE + id);
} catch (IOException e) {
e.printStackTrace();
if (callback != null) {
wrongMsg.setMsg(e.getMessage());
callback.onFailure(wrongMsg);
}
}
if (TextUtils.isEmpty(s)) {
if (callback != null) {
wrongMsg.setMsg("json msg is empty");
callback.onFailure(wrongMsg);
}
}
wrongMsg = gson.fromJson(s, new TypeToken<WrongMsg>() {
}.getType());
if (wrongMsg.getCode() != 0) {
if (callback != null)
callback.onFailure(wrongMsg);
} else {
result = gson.fromJson(s, new TypeToken<MovieMessage>() {
}.getType());
if (callback != null)
callback.onSuccess(result);
}
if (callback != null)
callback.onDone();
}
};
}
}