SettingPresenter.java
10.6 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/*
* Copyright (c) 2016 wugian
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.xgimi.gimicinema.presenter;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import com.gimi.common.cinema.db.NewDBManager;
import com.gimi.common.cinema.model.Constant;
import com.gimi.common.cinema.model.LocalMovieMessage;
import com.gimi.common.cinema.model.SambaMsg;
import com.gimi.common.cinema.model.WrongMsg;
import com.gimi.common.cinema.utils.SambaFileCharge;
import com.gimi.common.cinema.utils.ShellUtils;
import com.gimi.common.cinema.utils.SystemUtils;
import com.gimi.common.cinema.utils.Utils;
import com.xgimi.gimicinema.BuildConfig;
import com.xgimi.gimicinema.activity.AddCActivity;
import com.xgimi.gimicinema.activity.ChoseSourceActivity;
import com.xgimi.gimicinema.activity.CinemaConfig;
import com.xgimi.gimicinema.cctvsix.model.DataListEntity;
import com.xgimi.gimicinema.model.DBUpdateModelImpl;
import com.xgimi.gimicinema.model.IDBUpdateModel;
import com.xgimi.gimicinema.model.IM1905MovieModel;
import com.xgimi.gimicinema.model.IMovieScanModel;
import com.xgimi.gimicinema.model.IOtherModel;
import com.xgimi.gimicinema.model.ISambaModel;
import com.xgimi.gimicinema.model.IUpdateModel;
import com.xgimi.gimicinema.model.M1905ModelImpl;
import com.xgimi.gimicinema.model.MovieScanModelImpl;
import com.xgimi.gimicinema.model.OtherModelImpl;
import com.xgimi.gimicinema.model.SambaModelImpl;
import com.xgimi.gimicinema.model.UpdateModelImpl;
import com.xgimi.gimicinema.mview.ISettingView;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* Created by wugian on 2016/9/27
*/
public class SettingPresenter extends BasePresenter
implements MovieScanModelImpl.OnMovieScanListener,
DBUpdateModelImpl.OnInsertDbListener,
SambaModelImpl.OnSambaMountListener, UpdateModelImpl.OnCopyDbListener,
M1905ModelImpl.OnGetM1905MovieListener, OtherModelImpl.OnGetApkList {
private Context context;
private ISettingView view;
private IMovieScanModel scanModel;
private IDBUpdateModel dbModel;
private IUpdateModel updateModel;
private ISambaModel sambaModel;
private IM1905MovieModel m1905Model;
private IOtherModel otherModel;
private boolean copyIn = true;
public SettingPresenter(Context context, ISettingView view) {
this.context = context;
this.view = view;
this.scanModel = new MovieScanModelImpl();
this.dbModel = new DBUpdateModelImpl();
this.updateModel = new UpdateModelImpl();
this.sambaModel = new SambaModelImpl();
this.m1905Model = new M1905ModelImpl();
this.otherModel = new OtherModelImpl();
}
public void initBasic() {
SambaMsg sambaMsg = Utils.getSambaMsg(context);
String pid = SystemUtils.getPid(context, BuildConfig.MACHINE_TYPE);
boolean startOpen = Utils.getBool(context, "start_open");
boolean openAp = Utils.getBool(context, "open_ap");
String apName = Utils.getString(context, "ssid");
String apPwd = Utils.getString(context, "ssid_pwd");
view.initUi(sambaMsg);
view.setOtherMsg(pid, apName, apPwd, openAp, startOpen);
if (SambaFileCharge.fileExist(sambaMsg.getLocalPath() + "/TJ")) {
String s = sambaMsg.getLocalPath() + "/apks";
File file = new File(s);
if (!SambaFileCharge.fileExist(s)) {
boolean mkdirs = file.mkdirs();
if (mkdirs) {
ShellUtils.execCommand(new String[]{"chmod 0777 " + s}, false);
}
}
String s1 = sambaMsg.getLocalPath() + "/fl";
File files = new File(s1);
if (!SambaFileCharge.fileExist(s1)) {
files.mkdirs();
}
}
loadApkFiles();
}
public void scanMovie() {
view.enableCopy(false);
scanModel.scanMovie(context, this);
}
//scan local interface start
@Override
public void onSuccess(ArrayList<LocalMovieMessage> list) {
view.updateCurrentName("已扫描:" + list.size());
dbModel.insertAll(context, list, this);
}
@Override
public void onMessage(String msg) {
view.updateCurrentName(msg);
}
@Override
public void onFailure() {
view.enableCopy(true);
view.updateCurrentName("扫描失败");
}//scan local interface end
//insert db start
@Override
public void insertSuccess(int size) {
view.enableCopy(true);
view.updateCurrentName("成功更新 " + size);
}
@Override
public void insertFailure() {
view.enableCopy(true);
view.updateCurrentName("插入数据库失败");
}//insert db end
public void checkAppUpdate() {
updateModel.updateAppVersion(context, true);
}
public void choseSource() {
Intent intent = new Intent(context, ChoseSourceActivity.class);
context.startActivity(intent);
}
public void addNewClassification() {
Intent intent = new Intent(context, AddCActivity.class);
context.startActivity(intent);
}
public void mountSamba() {
SambaMsg sambaMsg = view.getSambaMsg();
sambaModel.mountSamba(context, sambaMsg, this);
}
//mount samba start
@Override
public void onSambaMountSuccess() {
view.showMessage("挂载成功");
SambaMsg sambaMsg = view.getSambaMsg();
if (BuildConfig.MACHINE_TYPE.equals("himedia")) {
if (!new File(CinemaConfig.BASIC_ROOT).exists()) {
view.showMessage("账号密码正确,文件夹或者相对路径不正确,请重新配置");
}
} else {
if (!new File(sambaMsg.getLocalPath()).exists()) {
view.showMessage("账号密码正确,文件夹或者相对路径不正确,请重新配置");
}
}
Utils.saveSambaMsg(context, sambaMsg);
}
@Override
public void onSambaMountFailure(int code, String wrongMsg) {
view.showMessage(wrongMsg);
}//mount samba end
public void saveBoolean(String name, boolean isChecked) {
Utils.saveBool(context, name, isChecked);
}
public void saveString(String name, String isChecked) {
Utils.saveString(context, name, isChecked);
}
public void saveInt(String name, int pos) {
Utils.saveInt(context, name, pos);
}
public int getInt(String name, int pos) {
return Utils.getString(context, name, pos);
}
//update server&local db start
public void updateServerDb() {
view.enableCopy(false);
copyIn = false;
updateModel.updateServerDb(context, this);
}
public void updateLocalDb() {
view.enableCopy(false);
copyIn = true;
updateModel.updateLocalDb(context, this);
}
@Override
public void onCopyDbSuccess() {
view.enableCopy(true);
if (copyIn) {
view.showMessage("更新本地数据库成功");
NewDBManager.getInstance().closeDB();
} else {
view.showMessage("数据库已考出");
}
}
@Override
public void onCopyDbFailure() {
view.enableCopy(true);
if (copyIn) {
view.showMessage("更新本地数据库失败");
} else {
view.showMessage("数据库已考出失败");
}
}//update local&server db end
//update 1905 movie start
public void updateM1905Movies() {
String ip = Utils.getString(context, "ip", Constant.DEFAULT_IP);
m1905Model.getAllM1905Movies(ip, this);
}
@Override
public void onGetM1905Success(List<DataListEntity> list) {
ArrayList<LocalMovieMessage> localMovieMessages = convertType(list);
dbModel.insertAll(context, localMovieMessages, this);
}
@Override
public void onGetM1905Failure(WrongMsg wrongMsg) {
view.showMessage(wrongMsg.getMsg());
view.showMessage("检测是否配置相关服务器");
}//update 1905 movie end
private ArrayList<LocalMovieMessage> convertType(List<DataListEntity> test) {
ArrayList<LocalMovieMessage> localMovieMessages = new ArrayList<>();
for (DataListEntity dataListEntity : test) {
LocalMovieMessage localMovieMessage = new LocalMovieMessage();
localMovieMessage.setMovieName(dataListEntity.getFile_name());
localMovieMessage.setDoubanId((dataListEntity.getId()));
localMovieMessage.setPlayPath(dataListEntity.getSave_name());
localMovieMessage.setType(dataListEntity.getFile_name());
localMovieMessage.setPosterPath(dataListEntity.getPic());
localMovieMessage.setScreenTime(dataListEntity.getRelease_date());
localMovieMessage.setDoubanRating(Double.parseDouble(dataListEntity.getScore()));
localMovieMessage.setNamePinyin(dataListEntity.getInitial());
localMovieMessage.setClassDescribe(dataListEntity.getFilm_type_text());
localMovieMessage.setMd5("qnyb_abc_test");
localMovieMessages.add(localMovieMessage);
}
return localMovieMessages;
}
private void loadApkFiles() {
String path = Utils.getSambaMsg(context).getLocalPath() + "/apks";
if (BuildConfig.MACHINE_TYPE.equals("himedia")) {
path = CinemaConfig.BASIC_ROOT + "/apks";
}
otherModel.getAllApk(path, this);
}
//get samba apk files
@Override
public void onGetApkListSuccess(ArrayList<HashMap<String, Object>> result) {
view.updateApkLists(result);
}
public void installApk(String fileName) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
String localPath = Utils.getSambaMsg(context).getLocalPath();
if (BuildConfig.MACHINE_TYPE.equals("himedia")) {
localPath = CinemaConfig.BASIC_ROOT + "/";
}
intent.setDataAndType(Uri.parse("file://" + localPath + "apks/"
+ fileName), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}