@@ -3,22 +3,22 @@ package ai.pai.lensman.db; |
||
3 | 3 |
import android.content.Context; |
4 | 4 |
import android.content.SharedPreferences; |
5 | 5 |
|
6 |
+import ai.pai.lensman.App; |
|
7 |
+ |
|
6 | 8 |
public class Preferences { |
7 | 9 |
|
8 |
- private Context context; |
|
9 | 10 |
private SharedPreferences mPrefs; |
10 | 11 |
private static Preferences instance; |
11 | 12 |
private static final String NullStr = ""; |
12 | 13 |
|
13 |
- private Preferences(Context context) { |
|
14 |
- this.context = context.getApplicationContext(); |
|
15 |
- mPrefs = this.context.getSharedPreferences("prefs", Context.MODE_PRIVATE); |
|
14 |
+ private Preferences() { |
|
15 |
+ mPrefs = App.getAppContext().getSharedPreferences("prefs", Context.MODE_PRIVATE); |
|
16 | 16 |
} |
17 | 17 |
|
18 |
- public static synchronized Preferences getInstance(Context context) { |
|
18 |
+ public static synchronized Preferences getInstance() { |
|
19 | 19 |
|
20 | 20 |
if (instance == null) { |
21 |
- instance = new Preferences(context); |
|
21 |
+ instance = new Preferences(); |
|
22 | 22 |
} |
23 | 23 |
return instance; |
24 | 24 |
} |
@@ -9,6 +9,7 @@ import org.json.JSONObject; |
||
9 | 9 |
import java.util.HashMap; |
10 | 10 |
|
11 | 11 |
import ai.pai.lensman.base.BaseInteractor; |
12 |
+import ai.pai.lensman.db.Preferences; |
|
12 | 13 |
import ai.pai.lensman.utils.HttpPostTask; |
13 | 14 |
import ai.pai.lensman.utils.UrlContainer; |
14 | 15 |
|
@@ -177,6 +178,7 @@ public class LoginInteractor implements BaseInteractor { |
||
177 | 178 |
loginTask = new HttpPostTask(params) { |
178 | 179 |
|
179 | 180 |
String lensmanId; |
181 |
+ String userName; |
|
180 | 182 |
String message; |
181 | 183 |
|
182 | 184 |
@Override |
@@ -187,6 +189,7 @@ public class LoginInteractor implements BaseInteractor { |
||
187 | 189 |
if (status == 200) { |
188 | 190 |
JSONObject info = json.getJSONObject("data"); |
189 | 191 |
lensmanId = info.getString("user_id"); |
192 |
+ userName = info.getString("username"); |
|
190 | 193 |
return true; |
191 | 194 |
} else { |
192 | 195 |
message = json.getString("message"); |
@@ -207,6 +210,8 @@ public class LoginInteractor implements BaseInteractor { |
||
207 | 210 |
protected void onPostSuccess() { |
208 | 211 |
super.onPostSuccess(); |
209 | 212 |
listener.onInteractSuccess(lensmanId); |
213 |
+ Preferences.getInstance().setLensManId(lensmanId); |
|
214 |
+ Preferences.getInstance().setUserName(userName); |
|
210 | 215 |
} |
211 | 216 |
}; |
212 | 217 |
loginTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), UrlContainer.WX_LOGIN_URL); |
@@ -37,7 +37,7 @@ public class LoginPresenter implements LoginContract.Presenter,BaseInteractor.In |
||
37 | 37 |
|
38 | 38 |
@Override |
39 | 39 |
public void start() { |
40 |
- String wxCode = Preferences.getInstance(context).getWXCode(); |
|
40 |
+ String wxCode = Preferences.getInstance().getWXCode(); |
|
41 | 41 |
if(!TextUtils.isEmpty(wxCode)){ |
42 | 42 |
view.showProgressView(); |
43 | 43 |
interactor = new LoginInteractor(wxCode,this); |
@@ -56,7 +56,7 @@ public class LoginPresenter implements LoginContract.Presenter,BaseInteractor.In |
||
56 | 56 |
@Override |
57 | 57 |
public void onInteractSuccess(String result) { |
58 | 58 |
view.hideProgressView(); |
59 |
- Preferences.getInstance(context).setLensManId(result); |
|
59 |
+ Preferences.getInstance().setLensManId(result); |
|
60 | 60 |
view.jumpMain(); |
61 | 61 |
} |
62 | 62 |
|
@@ -39,9 +39,9 @@ public class UploadTask extends AsyncTask<String,Integer,Boolean> { |
||
39 | 39 |
if(photo.exists() &&photo.isFile()){ |
40 | 40 |
PhotoUploadUtils photoUploadUtils = new PhotoUploadUtils(UrlContainer.PHOTO_UPLOAD_URL+"?timestamp="+System.currentTimeMillis()); |
41 | 41 |
photoUploadUtils.addFileParameter("photo", photo); |
42 |
- photoUploadUtils.addTextParameter("user_id", Preferences.getInstance(context).getLensManId()); |
|
42 |
+ photoUploadUtils.addTextParameter("user_id", Preferences.getInstance().getLensManId()); |
|
43 | 43 |
photoUploadUtils.addTextParameter("group_id", groupId); |
44 |
- photoUploadUtils.addTextParameter("nickname", Preferences.getInstance(context).getUserName()); |
|
44 |
+ photoUploadUtils.addTextParameter("nickname", Preferences.getInstance().getUserName()); |
|
45 | 45 |
String result=new String(photoUploadUtils.send(),"UTF-8"); |
46 | 46 |
JSONObject resultObj = new JSONObject(result); |
47 | 47 |
if(resultObj.getInt("status")==200){ |
@@ -31,7 +31,7 @@ public class SplashPresenter implements SplashContract.Presenter { |
||
31 | 31 |
|
32 | 32 |
@Override |
33 | 33 |
public void start() { |
34 |
- if(TextUtils.isEmpty(Preferences.getInstance(context).getLensManId())){ |
|
34 |
+ if(TextUtils.isEmpty(Preferences.getInstance().getLensManId())){ |
|
35 | 35 |
mHandler.postDelayed(new Runnable() { |
36 | 36 |
@Override |
37 | 37 |
public void run() { |
@@ -47,11 +47,11 @@ public class SplashPresenter implements SplashContract.Presenter { |
||
47 | 47 |
} |
48 | 48 |
}, NORMAL_DELAY_TIME); |
49 | 49 |
String curDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); |
50 |
- if(Preferences.getInstance(context).getLastRunDate().equals(curDate)){ |
|
50 |
+ if(Preferences.getInstance().getLastRunDate().equals(curDate)){ |
|
51 | 51 |
return; |
52 | 52 |
} |
53 | 53 |
// checkUpdate(); |
54 |
- Preferences.getInstance(context).setLastRunDate(curDate); |
|
54 |
+ Preferences.getInstance().setLastRunDate(curDate); |
|
55 | 55 |
} |
56 | 56 |
|
57 | 57 |
@Override |
@@ -36,7 +36,7 @@ public class UploadActivity extends BaseActivity implements UploadContract.View |
||
36 | 36 |
setContentView(R.layout.activity_upload); |
37 | 37 |
ButterKnife.bind(this); |
38 | 38 |
|
39 |
- presenter = new UploadPresenter(this,Preferences.getInstance(this).getLensManId()); |
|
39 |
+ presenter = new UploadPresenter(this,Preferences.getInstance().getLensManId()); |
|
40 | 40 |
adapter = new SessionRecyclerAdapter(this); |
41 | 41 |
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(this,2,LinearLayoutManager.VERTICAL,false); |
42 | 42 |
sessionsRecyclerView.setLayoutManager(layoutManager); |
@@ -44,7 +44,7 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler { |
||
44 | 44 |
if(resp instanceof SendAuth.Resp){ |
45 | 45 |
SendAuth.Resp newResp = (SendAuth.Resp) resp; |
46 | 46 |
String code = newResp.code; |
47 |
- Preferences.getInstance(this).setWXCode(code); |
|
47 |
+ Preferences.getInstance().setWXCode(code); |
|
48 | 48 |
} |
49 | 49 |
} |
50 | 50 |
|