Commit 032e6d86 by lihuaikun

feat:接口联调完毕 done

parent 70683b4e
apply plugin: 'com.android.application'
android {
signingConfigs {
debug {
storeFile file('./release.jks')
storePassword 'dankal'
keyAlias 'dk'
keyPassword 'dankal'
}
release {
storeFile file('./release.jks')
storePassword 'dankal'
keyAlias 'dk'
keyPassword 'dankal'
}
}
compileSdkVersion build_versions.compile_sdk
defaultConfig {
......@@ -14,7 +29,9 @@ android {
buildTypes {
release {
debuggable false
minifyEnabled false
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
......
File added
{
"version": 1,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "cn.dankal.yunlaboratory",
"variantName": "release",
"elements": [
{
"type": "SINGLE",
"filters": [],
"properties": [],
"versionCode": 1,
"versionName": "1",
"enabled": true,
"outputFile": "app-release.apk"
}
]
}
\ No newline at end of file
......@@ -11,7 +11,8 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:name="cn.dankal.basiclib.DankalApplication"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:networkSecurityConfig="@xml/network_config">
<activity android:name=".ui.activity.LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......
......@@ -6,6 +6,8 @@ import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.HashMap;
import api.UserServiceFactory;
import butterknife.BindView;
import butterknife.OnClick;
......@@ -17,10 +19,13 @@ import cn.dankal.basiclib.eventbus.AppBus;
import cn.dankal.basiclib.model.BaseModel;
import cn.dankal.basiclib.model.UserInfoBody;
import cn.dankal.basiclib.model.UserModel;
import cn.dankal.basiclib.rx.MapFunc;
import cn.dankal.basiclib.rx.NormalSubscriber;
import cn.dankal.yunlaboratory.R;
import cn.dankal.yunlaboratory.ui.widget.MainButton;
import io.reactivex.disposables.Disposable;
import okhttp3.MediaType;
import okhttp3.RequestBody;
public class ChangeNicknameActivity extends BaseActivity {
@BindView(R.id.iv_onback)
......@@ -69,23 +74,29 @@ public class ChangeNicknameActivity extends BaseActivity {
UserInfoBody userInfoBody = new UserInfoBody();
userInfoBody.setUpdate_type("name");
userInfoBody.setName(name);
UserServiceFactory.updateInfo(userInfoBody, null).subscribe(new NormalSubscriber<BaseModel<UserModel>>() {
HashMap<String,RequestBody> map=new HashMap<>();
RequestBody body=RequestBody.create(MediaType.parse("multipart/form-data"),name);
map.put("name",body);
RequestBody updateTypeBody=RequestBody.create(MediaType.parse("multipart/form-data"),"name");
map.put("update_type",updateTypeBody);
UserServiceFactory.updateName("name", name).map(new MapFunc<>()).subscribe(new NormalSubscriber<BaseModel>() {
@Override
public void onSubscribe(Disposable d) {
showLoadingDialog();
}
@Override
public void onNext(BaseModel<UserModel> stringBaseModel) {
public void onNext(BaseModel stringBaseModel) {
if (stringBaseModel.getData() != null) {
UserModel userModel = DKUserManager.getUserInfo();
UserModel userModel = DKUserManager.getUserInfo();
userModel.setName(stringBaseModel.getData().getName());
DKUserManager.updateUserInfo(userModel);
userModel.setName(name);
DKUserManager.updateUserInfo(userModel);
AppBus.getInstance().post(new InfoChange());
}
AppBus.getInstance().post(new InfoChange());
finish();
}
......
......@@ -13,6 +13,7 @@ import api.UserServiceFactory;
import butterknife.BindView;
import butterknife.OnClick;
import cn.dankal.basiclib.DKUserManager;
import cn.dankal.basiclib.DankalApplication;
import cn.dankal.basiclib.base.activity.BaseActivity;
import cn.dankal.basiclib.base.mvp.BasePresenter;
import cn.dankal.basiclib.model.BaseModel;
......@@ -76,6 +77,12 @@ public class LoginActivity extends BaseActivity {
etAccount.addTextChangedListener(textWatcher);
etPwd.addTextChangedListener(textWatcher);
if (DankalApplication.isLogin()){
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
}
......
......@@ -15,6 +15,7 @@ import cn.dankal.basiclib.model.BaseModel;
import cn.dankal.basiclib.model.ProjectModel;
import cn.dankal.basiclib.model.SubmitRecordModel;
import cn.dankal.basiclib.model.SubmitResultBody;
import cn.dankal.basiclib.rx.MapFunc;
import cn.dankal.basiclib.rx.NormalSubscriber;
import cn.dankal.yunlaboratory.R;
import cn.dankal.yunlaboratory.ui.dialog.ChooseItemDialog;
......@@ -69,6 +70,7 @@ public class StartTestActivity extends BaseActivity {
chooseProjectDialog.setViewClick(R.id.tv_positive, new View.OnClickListener() {
@Override
public void onClick(View v) {
chooseProjectDialog.dismiss();
int pos = chooseProjectDialog.getCurrentItem();
if (projectModels!=null&&pos<projectModels.size()){
......@@ -81,6 +83,7 @@ public class StartTestActivity extends BaseActivity {
chooseDeviceDialog.setViewClick(R.id.tv_positive, new View.OnClickListener() {
@Override
public void onClick(View v) {
chooseDeviceDialog.dismiss();
int pos = chooseDeviceDialog.getCurrentItem();
if (deviceModels!=null&&pos<deviceModels.size()){
......@@ -124,7 +127,7 @@ public class StartTestActivity extends BaseActivity {
}
public void getProjectList() {
UserServiceFactory.getProjectList().subscribe(new NormalSubscriber<BaseModel<List<ProjectModel>>>() {
UserServiceFactory.getProjectList(recordModel.getId()).map(new MapFunc<>()).subscribe(new NormalSubscriber<BaseModel<List<ProjectModel>>>() {
@Override
public void onSubscribe(Disposable d) {
......@@ -150,7 +153,7 @@ public class StartTestActivity extends BaseActivity {
}
public void getDeviceList() {
UserServiceFactory.getProjectList().subscribe(new NormalSubscriber<BaseModel<List<ProjectModel>>>() {
UserServiceFactory.getDeviceList(recordModel.getId()).map(new MapFunc<>()).subscribe(new NormalSubscriber<BaseModel<List<ProjectModel>>>() {
@Override
public void onSubscribe(Disposable d) {
......
......@@ -58,15 +58,21 @@ public class UploadResultActivity extends BaseActivity {
if (!TextUtils.isEmpty(report)){
body.setContent(report);
UserServiceFactory.submitReport(body).map(new MapFunc<>()).subscribe(new NormalSubscriber<BaseModel<String>>() {
UserServiceFactory.submitReport(body).map(new MapFunc<>()).subscribe(new NormalSubscriber<BaseModel>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(BaseModel<String> stringBaseModel) {
public void onNext(BaseModel stringBaseModel) {
showToast("上传成功");
view.postDelayed(new Runnable() {
@Override
public void run() {
finish();
}
},1000);
}
});
}else {
......
......@@ -23,6 +23,7 @@ import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import api.UserServiceFactory;
......@@ -36,6 +37,7 @@ import cn.dankal.basiclib.eventbus.Subscribe;
import cn.dankal.basiclib.model.BaseModel;
import cn.dankal.basiclib.model.UserInfoBody;
import cn.dankal.basiclib.model.UserModel;
import cn.dankal.basiclib.rx.MapFunc;
import cn.dankal.basiclib.rx.NormalSubscriber;
import cn.dankal.basiclib.util.FileUtil;
import cn.dankal.basiclib.util.GlideUtils;
......@@ -100,6 +102,9 @@ public class PersonFragment extends BaseFragment implements View.OnClickListener
renderDialog = new RenderDialog(getContext());
btnExit.setEnabled(true);
tvTitle.setText("个人中心");
if (DKUserManager.getUserInfo() != null) {
UserModel userModel = DKUserManager.getUserInfo();
......@@ -274,26 +279,23 @@ public class PersonFragment extends BaseFragment implements View.OnClickListener
}
public void updateSex(int sex) {
UserInfoBody userInfoBody = new UserInfoBody();
userInfoBody.setUpdate_type("sex");
userInfoBody.setSex(sex);
UserServiceFactory.updateInfo(userInfoBody, null).subscribe(new NormalSubscriber<BaseModel<UserModel>>() {
UserServiceFactory.updateSex("sex", sex).map(new MapFunc<>()).subscribe(new NormalSubscriber<BaseModel>() {
@Override
public void onSubscribe(Disposable d) {
showLoadingDialog();
}
@Override
public void onNext(BaseModel<UserModel> stringBaseModel) {
public void onNext(BaseModel stringBaseModel) {
if (stringBaseModel.getData()!=null){
UserModel userModel = DKUserManager.getUserInfo();
UserModel userModel = DKUserManager.getUserInfo();
userModel.setSex(stringBaseModel.getData().getSex());
DKUserManager.updateUserInfo(userModel);
userModel.setSex(sex);
DKUserManager.updateUserInfo(userModel);
tvSex.setText(userModel.getRealSex());
}
tvSex.setText(userModel.getRealSex());
}
......@@ -313,16 +315,21 @@ public class PersonFragment extends BaseFragment implements View.OnClickListener
*/
private void updateAvatar(Uri uri) {
if (!TextUtils.isEmpty(uri.toString())) {
UserInfoBody userInfoBody = new UserInfoBody();
userInfoBody.setUpdate_type("avatar");
HashMap<String,RequestBody> map=new HashMap<>();
RequestBody updateTypeBody=RequestBody.create(MediaType.parse("application/json"),"avatar");
map.put("update_type",updateTypeBody);
File file = new File(FileUtil.getRealFilePath(getContext(), uri));
RequestBody fileRQ = RequestBody.create(MediaType.parse("image/*"), file);
MultipartBody.Part part = MultipartBody.Part.createFormData("picture", file.getName(), fileRQ);
RequestBody fileRQ = RequestBody.create(MediaType.parse("image/png"), file);
MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), fileRQ);
// map.put("file",fileRQ);
UserServiceFactory.updateInfo(userInfoBody, part).subscribe(new NormalSubscriber<BaseModel<UserModel>>() {
UserServiceFactory.updateInfo(map,part).map(new MapFunc<>()).subscribe(new NormalSubscriber<BaseModel<UserModel>>() {
@Override
public void onSubscribe(Disposable d) {
showLoadingDialog();
......
......@@ -58,32 +58,7 @@ public class ScanFragment extends BaseFragment {
getBackSampleDialog.setViewClick(R.id.tv_positive, new View.OnClickListener() {
@Override
public void onClick(View v) {
getBackSampleDialog.dismiss();
UserServiceFactory.sample(codeResult).map(new MapFunc<BaseModel<SampleModel>>()).subscribe(new NormalSubscriber<BaseModel<SampleModel>>() {
@Override
public void onSubscribe(Disposable d) {
showLoadingDialog();
}
@Override
public void onNext(BaseModel<SampleModel> sampleModelBaseModel) {
SampleModel sampleModel = sampleModelBaseModel.getData();
if (sampleModel.getType() == 1) {
inputPersonNoDialog.show();
} else {
Intent intent = new Intent(getContext(), GetSampleActivity.class);
intent.putExtra("data", sampleModel.getUpload_list());
getContext().startActivity(intent);
}
}
@Override
public void onComplete() {
super.onComplete();
dismissLoadingDialog();
}
}
);
inputPersonNoDialog.dismiss();
}
});
......@@ -94,7 +69,7 @@ public class ScanFragment extends BaseFragment {
String nameStr = inputPersonNoDialog.getInputName();
if (!TextUtils.isEmpty(nameStr)) {
inputPersonNoDialog.dismiss();
UserServiceFactory.sampleNext(nameStr).subscribe(new NormalSubscriber<BaseModel<SubmitRecordModel>>() {
UserServiceFactory.sampleNext(nameStr).map(new MapFunc<>()).subscribe(new NormalSubscriber<BaseModel<SubmitRecordModel>>() {
@Override
public void onSubscribe(Disposable d) {
showLoadingDialog();
......@@ -141,8 +116,38 @@ public class ScanFragment extends BaseFragment {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK && requestCode == RC_SCAN) {
codeResult = data.getStringExtra("data");
requestData();
getBackSampleDialog.show();
}
}
/**
* 判断是否是第一次取样
*/
public void requestData(){
UserServiceFactory.sample(codeResult).map(new MapFunc<BaseModel<SampleModel>>()).subscribe(new NormalSubscriber<BaseModel<SampleModel>>() {
@Override
public void onSubscribe(Disposable d) {
showLoadingDialog();
}
@Override
public void onNext(BaseModel<SampleModel> sampleModelBaseModel) {
SampleModel sampleModel = sampleModelBaseModel.getData();
if (sampleModel.getType() == 1) {
getBackSampleDialog.show();
} else {
Intent intent = new Intent(getContext(), GetSampleActivity.class);
intent.putExtra("data", sampleModel.getUpload_list());
getContext().startActivity(intent);
}
}
@Override
public void onComplete() {
super.onComplete();
dismissLoadingDialog();
}
});
}
}
......@@ -2,7 +2,7 @@
<resources>
<color name="colorPrimary">#fff</color>
<color name="colorPrimaryDark">#fff</color>
<color name="colorAccent">#fff</color>
<color name="colorAccent">#6fc3ff</color>
<color name="color14">#141414</color>
<color name="color33">#333333</color>
<color name="colorcf">#CFCFCF</color>
......
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
\ No newline at end of file
......@@ -8,8 +8,6 @@ import cn.dankal.basiclib.common.qiniu.QiniuConfigResponse;
import cn.dankal.basiclib.model.LoginModel;
import cn.dankal.basiclib.model.TokenModel;
import cn.dankal.basiclib.model.UserModel;
import cn.dankal.basiclib.pojo.UserInfoBean;
import cn.dankal.basiclib.pojo.UserResponseBody;
import cn.dankal.basiclib.util.PreferenceUtil;
......@@ -41,8 +39,8 @@ public class DKUserManager {
* 如登录后可更新当前的UserInfo和本地的缓存
*/
public static void saveUserInfo(LoginModel userResponseBody) {
UserModel userInfo = userResponseBody.getUser();
TokenModel token = userResponseBody.getToken();
UserModel userInfo = userResponseBody.getInfo();
TokenModel token = userResponseBody.getMeta();
if (userInfo != null) {
PreferenceUtil.updateBean(mSpUserInfo, getUserInfo(), userInfo);
}
......@@ -69,7 +67,7 @@ public class DKUserManager {
* mUserInfo是否等于null,防止UserManager.getUserInfo出现空指针
*/
private static void readUserInfo() {
userInfo = (UserModel) PreferenceUtil.getBeanValue(mSpUserInfo, UserInfoBean.class);
userInfo = (UserModel) PreferenceUtil.getBeanValue(mSpUserInfo, UserModel.class);
if (userInfo == null) {
userInfo = new UserModel();
}
......@@ -77,7 +75,7 @@ public class DKUserManager {
private static void readUserToken() {
userToken = (TokenModel) PreferenceUtil.getBeanValue(mSpToken,
UserResponseBody.TokenBean.class);
TokenModel.class);
if (userToken == null) {
userToken = new TokenModel();
}
......
......@@ -25,8 +25,8 @@ import static cn.dankal.basiclib.DankalApplication.isDev;
*/
public class BaseApi {
public static final String BASE_URL = isDev ? "https://www.baidu.com"
: "https://www.google.com";
public static final String BASE_URL = isDev ? "http://tp.lzdu.com/api/"
: "http://tp.lzdu.com/api/";
private static LinkedHashMap<String, Retrofit> linkedHashMap = new LinkedHashMap<>(3);
......@@ -72,7 +72,7 @@ public class BaseApi {
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
@Override
public void log(String message) {
Logger.d(message);
Logger.e(message);
}
});
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
......
package cn.dankal.basiclib.api;
import java.util.List;
import java.util.Map;
import cn.dankal.annotations.ApiFactory;
import cn.dankal.basiclib.model.BaseModel;
......@@ -13,6 +14,7 @@ import cn.dankal.basiclib.model.UserInfoBody;
import cn.dankal.basiclib.model.UserModel;
import io.reactivex.Observable;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.http.Body;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
......@@ -21,6 +23,7 @@ import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Part;
import retrofit2.http.PartMap;
import retrofit2.http.Query;
/**
......@@ -62,14 +65,14 @@ public interface UserService {
* 获取项目
*/
@GET("project")
Observable<BaseModel<List<ProjectModel>>> getProjectList();
Observable<BaseModel<List<ProjectModel>>> getProjectList(@Query("sample_id")int sample_id);
/**
* 获取设备
*/
@GET("device")
Observable<BaseModel<List<ProjectModel>>> getDeviceList();
Observable<BaseModel<List<ProjectModel>>> getDeviceList(@Query("sample_id")int sample_id);
/**
......@@ -96,8 +99,36 @@ public interface UserService {
* @return
*/
@Multipart
@POST("update/info")
Observable<BaseModel<UserModel>> updateInfo(@PartMap Map<String, RequestBody> body, @Part MultipartBody.Part file);
/**
* 更新昵称
* update_type avatar: 更新头像name:更新昵称sex:性别
* name 昵称
* sex 性别 1男2女
* file 头像图片
*
* @return
*/
@FormUrlEncoded
@PUT("update/info")
Observable<BaseModel<UserModel>> updateInfo(@Part("body") UserInfoBody body, @Part MultipartBody.Part file);
Observable<BaseModel> updateName(@Field("update_type")String type,@Field("name")String name);
/**
* 更新昵称
* update_type avatar: 更新头像name:更新昵称sex:性别
* name 昵称
* sex 性别 1男2女
* file 头像图片
*
* @return
*/
@PUT("update/info")
@FormUrlEncoded
Observable<BaseModel> updateSex(@Field("update_type")String type,@Field("sex")int sex);
/**
......
......@@ -23,7 +23,7 @@ public class TokenInterceptor implements Interceptor {
String accessToken = DKUserManager.getUserToken().getAccess_token();
if (accessToken != null) {
Request requestAuthorised = originalRequest.newBuilder()
.header("X-Access-Token", accessToken)
.header("authorization", accessToken)
.build();
return chain.proceed(requestAuthorised);
}
......
package cn.dankal.basiclib.model;
public class LoginModel {
private UserModel user;
private TokenModel token;
private UserModel info;
private TokenModel meta;
public UserModel getUser() {
return user;
public UserModel getInfo() {
return info;
}
public void setUser(UserModel user) {
this.user = user;
public void setInfo(UserModel info) {
this.info = info;
}
public TokenModel getToken() {
return token;
public TokenModel getMeta() {
return meta;
}
public void setToken(TokenModel token) {
this.token = token;
public void setMeta(TokenModel meta) {
this.meta = meta;
}
}
......@@ -6,6 +6,7 @@ public class UserInfoBody {
private String name;
private int sex;
public String getUpdate_type() {
return update_type;
}
......
......@@ -24,6 +24,7 @@ public abstract class NormalSubscriber<T> implements Observer<T> {
public void onError(Throwable e) {
ToastUtils.showLong(e.getLocalizedMessage());
onComplete();
}
......
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