AskService.java
2.93 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
package com.xgimi.gimicinema.service;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.IBinder;
import android.widget.Toast;
import com.gimi.common.cinema.db.NewDBManager;
import com.gimi.common.cinema.model.Constant;
import com.gimi.common.cinema.model.SambaMsg;
import com.gimi.common.cinema.utils.LocalDataUtils;
import com.gimi.common.cinema.utils.OpenMMUtils;
import com.gimi.common.cinema.utils.SystemUtils;
import com.gimi.common.cinema.utils.Utils;
import com.xgimi.gimicinema.mview.IAskView;
import com.xgimi.gimicinema.presenter.AskPresenter;
import java.util.List;
/**
* Created by pc on 2015/1/6
*/
public class AskService extends Service implements IAskView {
public static final String TAG = "AskService";
private Handler handler = new Handler();
private Context context;
private SystemUtils systemUtils;
private SharedPreferences sharedPreferences;
private NewDBManager dbManager;
private LocalDataUtils localDataUtils;
private AskPresenter askPresenter;
private String ip = "";
private String folder = "";
private SambaMsg sambaMsg;
@Override
public void onCreate() {
super.onCreate();
context = this;
askPresenter = new AskPresenter(this);
localDataUtils = new LocalDataUtils(context);
dbManager = new NewDBManager(this);
systemUtils = new SystemUtils();
sharedPreferences = Utils.getSp(context);
agentType = Utils.getInt(sharedPreferences, "agent-type", 0);
updateMsg();
askPresenter.load(context);
handler.postDelayed(updateRunnable, 5 * 1000);
}
private void updateMsg() {
sambaMsg = Utils.getSambaMsg(sharedPreferences);
ip = sambaMsg.getIp();
folder = sambaMsg.getFolder();
}
int agentType;
private String currentPath = "";
private Runnable updateRunnable = new Runnable() {
@Override
public void run() {
Constant.gimiAuth = sharedPreferences.getBoolean(Constant.GIMI_AUTHENTICATION, true);
if (Constant.gimiAuth) {
localDataUtils.updateDb();
}
}
};
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
throw new NullPointerException();
}
@Override
public void onDestroy() {
askPresenter.umountSamba();
super.onDestroy();
}
@Override
public void playPath() {
OpenMMUtils.openMM(context, currentPath, null);
}
@Override
public void playPath(List<String> result, int position) {
OpenMMUtils.openMM(context, null, result, null, position);
}
@Override
public void showMsg(String msg) {
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
}
}