package com.bwie.topnewsnormal.utils;
import android.content.Context;
import com.bwie.topnewsnormal.app.MyApplication;
/**
* Created by Shadow on 2017/8/10.
*/
public class NetUtils {
public static final String SP_NAME = “SP_NAME”;
public static final String PICTURE_LOAD_MODE_KEY = “PICTURE_LOAD_MODE_KEY”;
private boolean isMobileConnectivity = true;
private static final String BASE_URL_BIG_PICTURE = "http://www.big.picture";
private static final String BASE_URL_SMALL_PICTURE = "http://www.small.picture";
private static final String BASE_URL_NO_PICTURE = "http://www.no.picture";
private String BASE_URL = BASE_URL_BIG_PICTURE;
private NetUtils() {
}
//單例模式
private static NetUtils mNetutils;
public static NetUtils getinstance() {
if (mNetutils == null) {
synchronized (NetUtils.class) {
if (mNetutils == null) {
mNetutils = new NetUtils();
}
}
}
return mNetutils;
}
public String getBaseUrl() {
if (isMobileConnectivity) {
int mode = MyApplication.getApp().getSharedPreferences(SP_NAME, Context.MODE_PRIVATE).getInt(PICTURE_LOAD_MODE_KEY, 0);
switch (mode) {
case 0:
BASE_URL = BASE_URL_BIG_PICTURE;
break;
case 1:
BASE_URL = BASE_URL_SMALL_PICTURE;
break;
case 2:
BASE_URL = BASE_URL_NO_PICTURE;
break;
}
} else {
BASE_URL = BASE_URL_BIG_PICTURE;
}
return BASE_URL;
}
public void changNetState(boolean isMobileConnectivity) {
this.isMobileConnectivity = isMobileConnectivity;
}
}