Commit 2b413d0c by sikang

UPDATE

parent 3c713327
......@@ -31,6 +31,10 @@ android {
dirs 'libs'
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}
dependencies {
......@@ -45,6 +49,13 @@ dependencies {
api "com.android.support:support-v4:$rootProject.ext.supportLibraryVersion"
api "com.android.support:recyclerview-v7:$rootProject.ext.supportLibraryVersion"
//protobuf
api "com.google.protobuf:protobuf-java:3.5.1"
// stream
api 'com.annimon:stream:1.1.4'
// litepal
api 'org.litepal.android:core:2.0.0'
//同盾
api(name: 'android_shujumohe_sdk_beta_20180907_1.0.8.2', ext: 'aar')
api 'com.alibaba:fastjson:1.1.58.android'
......
......@@ -18,9 +18,11 @@ import com.tencent.bugly.crashreport.CrashReport;
import cn.fraudmetrix.octopus.aspirit.main.OctopusManager;
import tech.starwin.database.DataBaseHelper;
import tech.starwin.network.Gateway;
import tech.starwin.utils.FireBaseHelper;
import tech.starwin.utils.PreferencesManager;
import tech.starwin.utils.collection.UploadManager;
import zendesk.core.AnonymousIdentity;
import zendesk.core.Zendesk;
import zendesk.support.Support;
......@@ -63,7 +65,7 @@ public class LibConfig {
public static String ZENDESK_OAUTH_CLIENT_ID;
public static String TONGDUN_PARENT_CODE;
public static String TONGDUN_PARENT_KEY;
public static int HARVESTER_PORT;
public static int HARVESTER_PORT;//
public static int LOADING_ICON;//loading图标
public static int LOADING_BACKGROUND;//loading旋转背景
public static int MAIN_COLOR;//主题色
......@@ -72,7 +74,7 @@ public class LibConfig {
public static Context getContext() {
if (CONTEXT == null)
throw new RuntimeException("context is null ! you must execute LibConfig.initLib(application) in your Appliaction");
throw new RuntimeException("context is null ! you must execute LibConfig.initLib(context) in your Appliaction");
return CONTEXT;
}
......@@ -83,6 +85,9 @@ public class LibConfig {
public static void initLib(Application application) {
if (application != null) {
CONTEXT = application;
//上传工具
UploadManager.init(CONTEXT);
//init FireBase RemoteConfig
//RemoteConfig
FirebaseRemoteConfig.getInstance().setConfigSettings(
......
......@@ -34,6 +34,7 @@ import tech.starwin.mvp.IView;
import tech.starwin.utils.LogUtils;
import tech.starwin.utils.PresenterHoler;
import tech.starwin.utils.context_utils.FragmentLauncher;
import tech.starwin.utils.ui_utils.DialogFactory;
import tech.starwin.widget.ProgressDialog;
/**
......@@ -160,16 +161,23 @@ public abstract class BaseActivity extends AppCompatActivity implements IView {
@Override
public void onHttpStart(String action, boolean isShowLoading) {
if (isShowLoading) {
progressDialog.showLoading();
//500ms后如果还没有收到返回数据,显示loading
progressDialog.setEnable(true);
rootLayout.postDelayed(() -> progressDialog.showLoading(), 500);
}
}
@Override
public void onHttpFinish(String action) {
progressDialog.setEnable(false);
progressDialog.dissmissLoading();
}
@Override
public void onHttpError(String action, String msg) {
DialogFactory.createMessageDialog(this, "Tip", msg, "OK").show();
}
//----------------------------------- Layout ----------------------------------------
......@@ -275,7 +283,6 @@ public abstract class BaseActivity extends AppCompatActivity implements IView {
}
}
//----------------------------------- Presenter ----------------------------------------
/**
......
......@@ -23,6 +23,7 @@ import tech.starwin.LibConfig;
import tech.starwin.R;
import tech.starwin.mvp.IView;
import tech.starwin.utils.PresenterHoler;
import tech.starwin.utils.ui_utils.DialogFactory;
import tech.starwin.widget.ProgressDialog;
import tech.starwin.utils.ui_utils.UIHelper;
......@@ -125,12 +126,20 @@ public abstract class BaseFragment extends Fragment implements IView {
@Override
public void onHttpStart(String action, boolean isShowLoading) {
if (isShowLoading) {
progressDialog.showLoading();
//500ms后如果还没有收到返回数据,显示loading
progressDialog.setEnable(true);
mContentView.postDelayed(() -> progressDialog.showLoading(), 500);
}
}
@Override
public void onHttpError(String action, String msg) {
DialogFactory.createMessageDialog(getActivity(), "Tip", msg, "OK").show();
}
@Override
public void onHttpFinish(String action) {
progressDialog.setEnable(false);
progressDialog.dissmissLoading();
}
......@@ -171,7 +180,7 @@ public abstract class BaseFragment extends Fragment implements IView {
presenterHelper.onDestory();
}
public View findViewById(@IdRes int id){
public View findViewById(@IdRes int id) {
return mContentView.findViewById(id);
}
......
......@@ -35,7 +35,7 @@ public abstract class BaseRecyclerAdapter<T> extends RecyclerView.Adapter<Recycl
throw new RuntimeException("bindItemLayout() invalid");
}
final RecyclerViewHolder holder = new RecyclerViewHolder(view);
initViewHolder(holder);
if (mClickListener != null) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
......@@ -77,6 +77,9 @@ public abstract class BaseRecyclerAdapter<T> extends RecyclerView.Adapter<Recycl
*/
public abstract void bindData(RecyclerViewHolder holder, int position, T item);
public void initViewHolder(RecyclerViewHolder holder) {
}
public T getItem(int pos) {
return mData.get(pos);
}
......
package tech.starwin.database.entity;
/**
* 跟通话记录数据库中的字段直接对应的pojo
* */
public class CallLogEntity {
private String cachedName;
private String number;
private int type;
private long date;
private long duration;
public String getCachedName() {
return cachedName;
}
public void setCachedName(String cachedName) {
this.cachedName = cachedName;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public long getDate() {
return date;
}
public void setDate(long date) {
this.date = date;
}
public long getDuration() {
return duration;
}
public void setDuration(long duration) {
this.duration = duration;
}
@Override
public String toString() {
return "CallLogEntity{" +
"cachedName='" + cachedName + '\'' +
", number='" + number + '\'' +
", type=" + type +
", date=" + date +
", duration=" + duration +
'}';
}
private static String[] callLogType = {
"UNKNOW_TYPE", //placeholder
"INCOMING_TYPE",
"OUTGOING_TYPE",
"MISSED_TYPE",
"VOICEMAIL_TYPE",
"REJECTED_TYPE",
"BLOCKED_TYPE",
"ANSWERED_EXTERNALLY_TYPE"
};
public static String getCallLogTypeDesc(int type){
if(type > 0 && type < callLogType.length){
return callLogType[type];
}else{
return callLogType[0];
}
}
}
package tech.starwin.database.entity;
import org.litepal.crud.LitePalSupport;
public class CollectInfoEntity extends LitePalSupport {
private String type;
private String body;
private long update_time;
public long getUpdate_time() {
return update_time;
}
public void setUpdate_time(long update_time) {
this.update_time = update_time;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
@Override
public boolean equals(Object entity){
return entity != null
&& entity instanceof CollectInfoEntity
&& ((CollectInfoEntity)entity).getType() != null && type.equals(((CollectInfoEntity)entity).getType());
}
@Override
public int hashCode(){
return type.hashCode();
}
@Override
public String toString() {
return "CollectInfoEntity{" +
"type='" + type + '\'' +
", body='" + body + '\'' +
'}';
}
}
package tech.starwin.database.entity;
import java.util.List;
/**
* 跟通讯录数据库中的字段直接对应的pojo
* */
public class ContactEntity {
private String name;
private List<NumberEntity> number;
private long lastUpdate;
private int contact_times;
private long last_contact_time;
private String nickname;
private String relation;
private String status;
public int getContact_times() {
return contact_times;
}
public void setContact_times(int contact_times) {
this.contact_times = contact_times;
}
public long getLast_contact_time() {
return last_contact_time;
}
public void setLast_contact_time(long last_contact_time) {
this.last_contact_time = last_contact_time;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getRelation() {
return relation;
}
public void setRelation(String relation) {
this.relation = relation;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<NumberEntity> getNumber() {
return number;
}
public void setNumber(List<NumberEntity> number) {
this.number = number;
}
public long getLastUpdate() {
return lastUpdate;
}
public void setLastUpdate(long lastUpdate) {
this.lastUpdate = lastUpdate;
}
@Override
public String toString() {
return "ContactEntity{" +
"name='" + name + '\'' +
", number=" + number +
", lastUpdate='" + lastUpdate + '\'' +
", contact_times=" + contact_times +
", last_contact_time='" + last_contact_time + '\'' +
", nickname='" + nickname + '\'' +
", relation='" + relation + '\'' +
", status='" + status + '\'' +
'}';
}
public static class NumberEntity{
private String number;
private String last_time_used;
private int time_used;
private String type_label;
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getLast_time_used() {
return last_time_used;
}
public void setLast_time_used(String last_time_used) {
this.last_time_used = last_time_used;
}
public int getTime_used() {
return time_used;
}
public void setTime_used(int time_used) {
this.time_used = time_used;
}
public String getType_label() {
return type_label;
}
public void setType_label(String type_label) {
this.type_label = type_label;
}
@Override
public String toString() {
return "NumberEntity{" +
"number='" + number + '\'' +
", last_time_used='" + last_time_used + '\'' +
", time_used='" + time_used + '\'' +
", type_label='" + type_label + '\'' +
'}';
}
}
public static class ContactDetail{
private int contact_times;
private long last_contact_time;
private String nickname;
private String relation;
private String status;
public int getContact_times() {
return contact_times;
}
public void setContact_times(int contact_times) {
this.contact_times = contact_times;
}
public long getLast_contact_time() {
return last_contact_time;
}
public void setLast_contact_time(long last_contact_time) {
this.last_contact_time = last_contact_time;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getRelation() {
return relation;
}
public void setRelation(String relation) {
this.relation = relation;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
@Override
public String toString() {
return "ContactDetail{" +
"contact_times='" + contact_times + '\'' +
", last_contact_time='" + last_contact_time + '\'' +
", nickname=" + nickname +
", relation='" + relation + '\'' +
", status='" + status + '\'' +
'}';
}
}
}
package tech.starwin.database.entity;
/**
* 跟短信记录数据库中的字段直接对应的pojo
* */
public class SmsEntity {
private String address;
private int type;
private long date;
private String body;
private String subject;
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public long getDate() {
return date;
}
public void setDate(long date) {
this.date = date;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
@Override
public String toString() {
return "SmsEntity{" +
"type=" + type +
", address='" + address + '\'' +
", date=" + date +
", body='" + body + '\'' +
", subject='" + subject + '\'' +
'}';
}
private static String[] smsType = {
"MESSAGE_TYPE_ALL",
"MESSAGE_TYPE_INBOX",
"MESSAGE_TYPE_SENT",
"MESSAGE_TYPE_DRAFT",
"MESSAGE_TYPE_OUTBOX",
"MESSAGE_TYPE_FAILED",
"MESSAGE_TYPE_QUEUED",
"MESSAGE_UNKNOW_TYPE"
};
public static String getSmsTypeDesc(int type){
if(type > 0 && type < smsType.length){
return smsType[type];
}else{
return smsType[0];
}
}
}
\ No newline at end of file
......@@ -42,15 +42,16 @@ public abstract class HttpObserver<T> implements Observer<T> {
@Override
public void onError(Throwable throwable) {
onFinish();
String msg = throwable.getMessage();
try {
if (throwable != null) {
String msg = throwable.getMessage();
if (isHttpError(msg)) {
onError(Error.HTTP_ERROR, LibConfig.getContext().getString(R.string.text_net_error));
} else if (throwable instanceof HttpException) {
HttpException exception = (HttpException) throwable;
if (!isCanHandle(exception)) {
ResponseErrorBody responseErrorBody = new Gson().fromJson(exception.response().errorBody().string(), ResponseErrorBody.class);
String body = exception.response().errorBody().string();
ResponseErrorBody responseErrorBody = new Gson().fromJson(body, ResponseErrorBody.class);
onError(Error.SERVER_ERROR, responseErrorBody.getMessage());
}
} else if (msg.contains("java.lang.IllegalStateException")) {
......@@ -63,7 +64,7 @@ public abstract class HttpObserver<T> implements Observer<T> {
}
} catch (Throwable e) {
onError(Error.APP_ERROR, LibConfig.getContext().getString(R.string.text_app_error));
onError(Error.APP_ERROR, msg);
}
if (disposable != null)
disposable.dispose();
......
......@@ -273,7 +273,7 @@ public interface UserApi {
@Query("productId") long productId);
/**
* 客户服务热线
* 客户服务热线、公司介绍
*/
@GET("loanapp/display")
Observable<DisplayBean> display();
......
package tech.starwin.mvp.beans;
import android.os.Parcelable;
import java.io.Serializable;
/**
......@@ -11,7 +13,7 @@ import java.io.Serializable;
* @更新描述:${TODO}
*/
public class HistoryLoanAppInfoBean extends LoanAppBeanFather implements Serializable {
public class HistoryLoanAppInfoBean extends LoanAppBeanFather implements Parcelable {
/**
......
package tech.starwin.mvp.beans;
import android.os.Parcelable;
import java.io.Serializable;
/**
* Created by Miaoke on 2017/3/6.
*/
public class LatestLoanAppBean extends LoanAppBeanFather implements Serializable {
public class LatestLoanAppBean extends LoanAppBeanFather implements Parcelable {
/**
* amount ; 0
......
......@@ -14,8 +14,8 @@ import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.functions.Function4;
import io.reactivex.functions.Predicate;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
import retrofit2.http.Query;
import tech.starwin.base.BasePresenter;
import tech.starwin.impl.HttpObserver;
import tech.starwin.mvp.api.LoanApi;
......@@ -49,6 +49,7 @@ public class UserPresenter extends BasePresenter<UserApi> {
@SuppressLint("CheckResult")
public void notifyGateway() {
Observable.fromIterable(Gateway.getGatewayUrl())
.observeOn(Schedulers.io())
.concatMap(new Function<String, ObservableSource<GatewayInfoBean>>() {
@Override
public ObservableSource<GatewayInfoBean> apply(String s) throws Exception {
......@@ -71,7 +72,7 @@ public class UserPresenter extends BasePresenter<UserApi> {
.subscribe(new Consumer<GatewayInfoBean>() {
@Override
public void accept(GatewayInfoBean gatewayInfoBean) throws Exception {
Gateway.notify(gatewayInfoBean);
Gateway.setGatewayInfoBean(gatewayInfoBean);
}
});
}
......@@ -363,6 +364,13 @@ public class UserPresenter extends BasePresenter<UserApi> {
handleRequest(action, apiService.display());
}
/**
* 获取公司介绍
*/
public void getAboutUsMsg(String action) {
handleRequest(action, apiService.display());
}
/**
* 获取用户联系人
......
......@@ -41,6 +41,12 @@ public class RegionActivity extends BaseActivity {
}
@Override
public void overridePendingTransition(int enterAnim, int exitAnim) {
//取消动画,使用系统默认动画
// super.overridePendingTransition(enterAnim, exitAnim);
}
@Override
public void onHttpSuccess(String action, Object result) {
}
......
......@@ -121,6 +121,10 @@ public class RegionFragment extends BaseFragment {
if (action == "action_getRegion") {
//填充数据,更新UI
final RegionBean regionBean = (RegionBean) result;
if(regionBean.getRegions().size()==0){
getActivity().setResult(Activity.RESULT_OK, new ActivityJumper.Builder().put("region_info", regionInfo).toIntent());
getActivity().finish();
}
RegionAdapter regionAdapter = new RegionAdapter(getActivity(), regionBean.getRegions());
UIHelper.bindAdapter(mRegionRv, regionAdapter);
//选中区域 item
......
......@@ -12,7 +12,7 @@ import retrofit2.Retrofit;
* Created by SiKang on 2018/9/14.
* responseBody 为空时,抛出空指针
*/
public class NullOnEmptyConverterFactory extends Converter.Factory {
public class EmptyConverterFactory extends Converter.Factory {
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
......
......@@ -32,7 +32,7 @@ public class Gateway {
/**
* 更新gateway
*/
public static void notify(GatewayInfoBean info) {
public static void setGatewayInfoBean(GatewayInfoBean info) {
gatewayInfo.notifyWith(info);
PreferencesManager.get().saveGatewayInfo(info);
}
......
......@@ -44,7 +44,7 @@ public class ServiceGenerator {
retrofit = new Retrofit.Builder()
.baseUrl(Gateway.getRestUrl())
.client(okHttpClient)
.addConverterFactory(new NullOnEmptyConverterFactory())
.addConverterFactory(new EmptyConverterFactory())
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
......
package tech.starwin.utils;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
/**
* Created by SiKang on 2018/10/19.
* 数据库辅助类,用于涉及数据库查询的业务封装
*/
public class DataBaseHelper {
/**
* 查询联系人信息
*
* @return String[name, number]
*/
public static String[] queryContactInfo(Context context, Uri uri) {
String[] data = null;
if (uri != null) {
Cursor cursor = context.getContentResolver()
.query(uri, new String[]{ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME},
null, null, null);
while (cursor != null && cursor.moveToNext()) {
String number = cursor.getString(0);
String name = cursor.getString(1);
data = new String[]{name, number};
}
cursor.close();
}
return data;
}
}
......@@ -104,7 +104,21 @@ public class LoginManager {
* 获取Token
*/
public String getToken() {
return getTokenInfo() == null ? "" : tokenInfo.getToken();
return getTokenInfo() == null ? "" : getTokenInfo().getToken();
}
/**
* 获取手机号
*/
public String getMobile() {
return getTokenInfo() == null ? "" : getTokenInfo().getMobile();
}
/**
* 获取用户名
*/
public String getUserName() {
return getUserInfo() == null ? "" : getUserInfo().getName();
}
public TokenInfoBean getTokenInfo() {
......@@ -130,6 +144,7 @@ public class LoginManager {
*/
public void logout() {
tokenInfo = null;
userInfo = null;
PreferencesManager.get().clearLoginInfo();
}
......
......@@ -8,11 +8,10 @@ import android.text.TextUtils;
import java.util.Map;
import tech.starwin.mvp.beans.GatewayInfoBean;
import tech.starwin.mvp.beans.LoanInfo;
import tech.starwin.mvp.beans.OcrResultBean;
import tech.starwin.mvp.beans.PersonalInfoServerBean;
import tech.starwin.mvp.beans.TokenInfoBean;
import tech.starwin.mvp.beans.UserBean;
import tech.starwin.utils.format_utils.DataFormat;
/**
* Created by SiKang on 2018/9/18.
......@@ -124,6 +123,20 @@ public class PreferencesManager {
}
/**
* 保存上传用户数据时使用的sessionId
*/
public void saveSessionId(String sessionId) {
saveData("session_id", sessionId);
}
/**
* 取出上传用户数据时使用的sessionId
*/
public String getSessionId() {
return getString("session_id", "");
}
/**
* 是否已同意政策
*/
public boolean hasAgreedPolicy() {
......@@ -135,8 +148,8 @@ public class PreferencesManager {
* 清除登录信息
*/
public void clearLoginInfo() {
saveData("user_info", "");
saveData("token_info", "");
remove("user_info");
remove("token_info");
}
/**
......@@ -164,6 +177,15 @@ public class PreferencesManager {
mEditor.commit();
}
/**
* 删除一条数据
*/
public void remove(String key) {
mEditor.remove(key);
mEditor.commit();
}
/**
* 保存多条数据
*/
......
package tech.starwin.utils;
import java.util.concurrent.TimeUnit;
import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.functions.Function;
public class RetryWithDelay implements
Function<Observable<? extends Throwable>, Observable<?>> {
private final int maxRetries;
private final int retryDelayMillis;
private int retryCount;
public RetryWithDelay(int maxRetries, int retryDelayMillis) {
this.maxRetries = maxRetries;
this.retryDelayMillis = retryDelayMillis;
}
@Override
public Observable<?> apply(Observable<? extends Throwable> observable) throws Exception {
return observable.flatMap(new Function<Throwable, ObservableSource<?>>() {
@Override
public ObservableSource<?> apply(Throwable throwable) throws Exception {
if (++retryCount <= maxRetries) {
// When this Observable calls onNext, the original Observable will be retried (i.e. re-subscribed).
return Observable.timer(retryDelayMillis,
TimeUnit.MILLISECONDS);
}
// Max retries hit. Just pass the error along.
return Observable.error(throwable);
}
});
}
}
package tech.starwin.utils.collection;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Date;
import tech.starwin.utils.LoginManager;
/**
* 异常处理
*/
public class ExceptionHelper {
public static String throwable2String(Throwable ex) {
Writer writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
ex.printStackTrace(printWriter);
Throwable cause = ex.getCause();
while (cause != null) {
cause.printStackTrace(printWriter);
cause = cause.getCause();
}
printWriter.close();
return writer.toString();
}
public static JSONObject getCrashMsgBody(Context context, String crashMsg, String tag) {
JSONObject CrashMsgEntity = new JSONObject();
Long totalNumber = 1L;
Long latestTime = 0L;
Long earliestTime = 0L;
JSONArray crashMsgArray = new JSONArray();
JSONObject crashMsgObject = new JSONObject();
try {
crashMsgObject.put("createTime", new Date().getTime());
crashMsgObject.put("crashMsg", crashMsg);
crashMsgArray.put(crashMsgObject);
//------------------------
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
CrashMsgEntity.put("protocolName", "CRASH_MSG");
CrashMsgEntity.put("protocolVersion", ProtocolVersion.V_1_0.name());
CrashMsgEntity.put("versionName", packageInfo.versionName);
CrashMsgEntity.put("versionCode", packageInfo.versionCode);
CrashMsgEntity.put("totalNumber", totalNumber);
CrashMsgEntity.put("latestTime", latestTime);
CrashMsgEntity.put("earliestTime", earliestTime);
CrashMsgEntity.put("token", LoginManager.get().getToken());
CrashMsgEntity.put("tag", tag);
CrashMsgEntity.put("data", crashMsgArray);
} catch (JSONException e) {
e.printStackTrace();
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return CrashMsgEntity;
}
public static JSONObject getInstallRefererMsgBody(Context context, String msg, String tag) {
JSONObject CrashMsgEntity = new JSONObject();
Long totalNumber = 1L;
Long latestTime = 0L;
Long earliestTime = 0L;
JSONArray crashMsgArray = new JSONArray();
JSONObject crashMsgObject = new JSONObject();
try {
crashMsgObject.put("createTime", new Date().getTime());
crashMsgObject.put("msg", msg);
crashMsgArray.put(crashMsgObject);
//------------------------
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
CrashMsgEntity.put("protocolName", "CRASH_MSG");
CrashMsgEntity.put("protocolVersion", ProtocolVersion.V_1_0.name());
CrashMsgEntity.put("versionName", packageInfo.versionName);
CrashMsgEntity.put("versionCode", packageInfo.versionCode);
CrashMsgEntity.put("totalNumber", totalNumber);
CrashMsgEntity.put("latestTime", latestTime);
CrashMsgEntity.put("earliestTime", earliestTime);
String token = LoginManager.get().getToken();
if (token == null) {
token = "";
}
CrashMsgEntity.put("token", token);
CrashMsgEntity.put("tag", tag);
CrashMsgEntity.put("data", crashMsgArray);
} catch (JSONException e) {
e.printStackTrace();
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return CrashMsgEntity;
}
}
\ No newline at end of file
package tech.starwin.utils.collection;
import android.util.Log;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
/**
* Created by luoliuqing on 17/10/21.
* GZip工具类
*/
public class GZipUtil {
public static final String GZIP_ENCODE_UTF_8 = "UTF-8";
public static final String GZIP_ENCODE_ISO_8859_1 = "ISO-8859-1";
/**
* 字符串压缩为GZIP字节数组
* @param str
* @param encoding
* @return
*/
public static byte[] compress(String str, String encoding) {
if (str == null || str.length() == 0) {
return null;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPOutputStream gzip;
try {
gzip = new GZIPOutputStream(out);
gzip.write(str.getBytes(encoding));
gzip.close();
} catch (IOException e) {
Log.e("gzip compress error.", e.getMessage());
}
return out.toByteArray();
}
/**
* Gzip byte[] 解压成字符串
* @param bytes
* @return
*/
public static String uncompressToString(byte[] bytes) {
return uncompressToString(bytes, GZIP_ENCODE_UTF_8);
}
/**
* Gzip byte[] 解压成字符串
* @param bytes
* @param encoding
* @return
*/
public static String uncompressToString(byte[] bytes, String encoding) {
if (bytes == null || bytes.length == 0) {
return null;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
try {
GZIPInputStream ungzip = new GZIPInputStream(in);
byte[] buffer = new byte[256];
int n;
while ((n = ungzip.read(buffer)) >= 0) {
out.write(buffer, 0, n);
}
return out.toString(encoding);
} catch (IOException e) {
Log.e("gzip compress error.",e.getMessage());
}
return null;
}
/**
* 判断byte[]是否是Gzip格式
* @param data
* @return
*/
public static boolean isGzip(byte[] data) {
int header = (int)((data[0]<<8) | data[1]&0xFF);
return header == 0x1f8b;
}
}
package tech.starwin.utils.collection;
/**
* Created by Miaoke on 13/04/2017.
*/
public enum ProtocolVersion {
V_1_0("1.0"),CURRENT_VERSON("1.0");
private String customName;
private ProtocolVersion(String name){
customName = name;
}
public String getCustomName(){
return customName;
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import java.io.Serializable;
......@@ -111,6 +112,11 @@ public class ActivityJumper {
return this;
}
public Builder put(String key, Parcelable obj) {
intent.putExtra(key, obj);
return this;
}
public ActivityJumper build() {
return new ActivityJumper(fromContext, intent);
}
......
......@@ -7,11 +7,13 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.PermissionChecker;
import com.tbruyelle.rxpermissions2.Permission;
import com.tbruyelle.rxpermissions2.RxPermissions;
......@@ -201,6 +203,16 @@ public class PermissionsHelper {
}
/**
* 是否同意了某个权限
*/
public static boolean permissionGranted(String permission, Context ctx) {
if (permission == null) {
return true;
}
return Build.VERSION.SDK_INT < 23 || PermissionChecker.checkSelfPermission(ctx, permission) == PackageManager.PERMISSION_GRANTED;
}
public interface OnPermissionListener {
/**
* 允许权限
......
package tech.starwin.utils;
package tech.starwin.utils.format_utils;
import android.content.Context;
import android.support.annotation.NonNull;
......@@ -23,6 +23,7 @@ import tech.starwin.R;
/**
* Created by SiKang on 2018/10/16.
* 时间、货币、String、Bean 格式化工具
*/
public class DataFormat {
......
package tech.starwin.utils;
package tech.starwin.utils.format_utils;
import android.content.Context;
import tech.starwin.R;
import tech.starwin.utils.format_utils.StringAdapter;
/**
......
package tech.starwin.utils;
package tech.starwin.utils.format_utils;
import android.text.TextUtils;
......
......@@ -9,7 +9,12 @@ import android.content.Context;
import android.content.ContextWrapper;
import android.content.DialogInterface;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.InputType;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
......@@ -23,6 +28,7 @@ import java.util.concurrent.TimeUnit;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import tech.starwin.base.RecyclerViewHolder;
/**
......@@ -45,16 +51,27 @@ public class DialogFactory {
/**
* 创建一个带有文本提示的对话框
*/
public static void showMessageDialog(Context context, String msg) {
createMessageDialog(context, "Tip", msg, "ok").show();
}
public static Dialog createMessageDialog(Context context, String title, String message, String btnText) {
return new QMUIDialog.MessageDialogBuilder(context)
.setTitle(title)
.setMessage(message)
.addAction(btnText, new QMUIDialogAction.ActionListener() {
return createMessageDialog(context, title, message, btnText, null);
}
public static Dialog createMessageDialog(Context context, String title, String message, String btnText, QMUIDialogAction.ActionListener listener) {
if (listener == null) {
listener = new QMUIDialogAction.ActionListener() {
@Override
public void onClick(QMUIDialog dialog, int index) {
dialog.dismiss();
}
})
};
}
return new QMUIDialog.MessageDialogBuilder(context)
.setTitle(title)
.setMessage(message)
.addAction(btnText, listener)
.create();
}
......@@ -154,13 +171,17 @@ public class DialogFactory {
}
public static Dialog showCustomDialog(View view) {
Dialog dialog = new AlertDialog.Builder(view.getContext()).create();
dialog.show();
dialog.getWindow().setContentView(view);
/**
* 创建一个自定义的View
*/
public static Dialog createCustomDialog(Context context, @LayoutRes int layout, OnViewCreatedListener listener) {
View view = LayoutInflater.from(context).inflate(layout, null);
Dialog dialog = new CustomDialog(context, view);
listener.onCreatedView(dialog, new RecyclerViewHolder(view));
return dialog;
}
/**
* 显示一个对话框,并在计时结束后dismiss
*/
......@@ -191,6 +212,10 @@ public class DialogFactory {
void onClick(Dialog dialog, boolean isAgree);
}
public interface OnViewCreatedListener {
void onCreatedView(Dialog dialog, RecyclerViewHolder viewHolder);
}
public static void dismiss(Dialog dialog) {
if (dialog != null) {
Context context = ((ContextWrapper) dialog.getContext()).getBaseContext();
......@@ -205,4 +230,19 @@ public class DialogFactory {
}
}
public static class CustomDialog extends Dialog {
View view;
public CustomDialog(@NonNull Context context, View view) {
super(context);
this.view = view;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(view);
}
}
}
......@@ -16,6 +16,7 @@ import tech.starwin.utils.ui_utils.DialogFactory;
*/
public class ProgressDialog {
//loading dialog
private boolean enable = true;
private Dialog loadingDialog;
private Context context;
......@@ -31,7 +32,7 @@ public class ProgressDialog {
public void showLoading() {
if (!loadingDialog.isShowing()) {
if (!loadingDialog.isShowing() && enable) {
loadingDialog.show();
}
}
......@@ -44,7 +45,7 @@ public class ProgressDialog {
/**
* 关闭loading 显示错误提示
* */
*/
@SuppressLint("CheckResult")
public void showError(String msg) {
final Dialog errorDialog = DialogFactory.createTipDialog(context, QMUITipDialog.Builder.ICON_TYPE_FAIL, msg);
......@@ -53,5 +54,7 @@ public class ProgressDialog {
DialogFactory.showTiming(errorDialog, 1500);
}
public void setEnable(boolean enable) {
this.enable = enable;
}
}
......@@ -9,14 +9,11 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_horizontal"
android:padding="@dimen/x_30"
android:text="region"
android:textColor="@color/colorBlack" />
android:textColor="@color/black" />
<TextView
android:layout_width="match_parent"
android:layout_height="@dimen/x_2"
android:background="@color/big_rec_line_color" />
<TextView style="@style/gray_line" />
</LinearLayout>
\ No newline at end of file
......@@ -2,70 +2,17 @@
<resources>
<!--蓝色:3e75c8 绿色:6fc4bb 中灰:8e949b 浅灰色:bcc6d1-->
<!--background\shape color-->
<color name="colorPrimary">@color/theme</color>
<color name="colorPrimaryDark">@color/theme_d</color>
<color name="colorAccent">@color/accent</color>
<color name="colorBackground">@color/page_background</color>
<color name="colorBackground_d">#f2f2f2</color>
<color name="red">#ef4e4e</color>
<color name="hover">#0ea26c</color>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<!--背景灰-->
<color name="gray_bg">#F7F7F7</color>
<!--text color-->
<color name="textDeep">#272637</color>
<color name="textNormal">#262536</color>
<color name="textHint">#7b7a89</color>
<color name="textLight">#999999</color>
<color name="textButton">@color/white</color>
<color name="textLink">@color/theme</color>
<color name="textAccent">@color/accent</color>
<color name="textButton_Tab">#ccd2d5</color>
<color name="textButton_Tab_active">@color/theme</color>
<color name="text_progress_circle_dark">#7c87a0</color>
<color name="text_contack_dark">#333333</color>
<color name="text_take_photo_tips">#7fbec9</color>
<color name="text_loan_info">#a9a9a9</color>
<color name="text_theme_dark">@color/theme_d</color>
<color name="text_accent_dark">@color/accent_d</color>
<!--shape/background colors-->
<color name="toolbar_background">@color/color_main_dark</color>
<color name="page_background">#ffffff</color>
<color name="theme">#10b679</color>
<color name="theme_d">#11b780</color>
<color name="theme_light">#00c08c</color>
<color name="accent">#fa5a4e</color>
<color name="accent_d">#fb5b4f</color>
<color name="sys_info_color">#454360</color>
<color name="big_rec_line_color">#d8dee1</color>
<color name="divider_color">#dedede</color>
<color name="divider_color_light">#e6e6e6</color>
<color name="small_rec_active_theme">@color/theme</color>
<color name="small_rec_inactive">#999999</color>
<color name="button_background">@color/theme</color>
<color name="progress_background">#dfe4e6</color>
<color name="select_rec_background">@color/white</color>
<color name="instruction_tips_background">#f5f5f5</color>
<color name="divide_page_background">#f5f5f5</color>
<color name="take_photo_img_background">@color/colorBackground_d</color>
<color name="take_photo_bottom_background">@color/white</color>
<color name="progress_background_loan_info">#d8dee1</color>
<color name="im_edit_background">#e9e9e9</color>
<color name="translateColor">#00000000</color>
<color name="colorBlack">#000</color>
<color name="bottom_tab_normal">@color/sys_info_color</color>
<color name="color_main_dark">#272637</color>
<color name="color_main">#575673</color>
<color name="time_line_big">#a3a1b2</color>
<color name="time_line_small">#4f4c69</color>
<color name="splash_bg">#0dbd6b</color>
<color name="payment_hint">#d0cfde</color>
<color name="theme_t">#80b2a0</color>
<color name="alert_t">#e78b8b</color>
<color name="gray_bg">#F7F7F7</color>
<color name="white">@android:color/white</color>
<color name="black">@android:color/black</color>
<color name="green">#00EE00</color>
<color name="red">#FF0000</color>
<color name="organge">#EEAD0E</color>
</resources>
......@@ -7,6 +7,12 @@
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="noAnimation">
<item name="android:activityOpenEnterAnimation">@null</item>
<item name="android:activityOpenExitAnimation">@null</item>
<item name="android:activityCloseEnterAnimation">@null</item>
<item name="android:activityCloseExitAnimation">@null</item>
</style>
<style name="style_bg_transparent_dialog" parent="Base.Theme.AppCompat.Light.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
......@@ -14,6 +20,7 @@
</style>
<style name="QMTheme" parent="QMUI.Compat.NoActionBar">
<item name="android:windowAnimationStyle">@style/noAnimation</item>
<item name="android:windowIsTranslucent">true</item>
<!-- toolbar(actionbar)颜色 -->
<item name="colorPrimary">@color/main_color</item>
......@@ -134,7 +141,7 @@
<style name="main_color_roundBtn">
<item name="android:textColor">@color/white</item>
<item name="android:background">@drawable/style_mainsolid_round</item>
<item name="android:background">@drawable/shape_mainsolid_round</item>
</style>
<style name="vertical_padding_10dp">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment