Android代码12月4日提交
This commit is contained in:
parent
d6d0ca5573
commit
ebf09cae36
|
@ -2,15 +2,27 @@ package com.c202101020117.Action;
|
|||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.c202101020117.AppConctroller;
|
||||
import com.c202101020117.Login;
|
||||
import com.c202101020117.R;
|
||||
import com.c202101020117.package1.DrugInfo;
|
||||
import com.c202101020117.package1.RYApi;
|
||||
import com.c202101020117.package1.Result;
|
||||
import com.gyf.immersionbar.ImmersionBar;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
|
||||
public class Action3 extends AppCompatActivity {
|
||||
|
||||
|
@ -27,6 +39,9 @@ public class Action3 extends AppCompatActivity {
|
|||
setContentView(R.layout.activity_action3);
|
||||
ImmersionBar.with(this).init();
|
||||
|
||||
//添加Activity到容器中
|
||||
AppConctroller.addActivity(this);
|
||||
|
||||
back = findViewById(R.id.textView33);
|
||||
text1 = findViewById(R.id.editTextText30);
|
||||
text2 = findViewById(R.id.editTextText32);
|
||||
|
@ -55,8 +70,63 @@ public class Action3 extends AppCompatActivity {
|
|||
confirm.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
DrugInfo drugInfo = new DrugInfo();
|
||||
int id = sharedPreferences.getInt("id", 0);
|
||||
String dno = text1.getText() + "";
|
||||
String MFD = text2.getText() + "";
|
||||
String EXP = text3.getText() + "";
|
||||
int Quantity = Integer.parseInt(text4.getText() + "");
|
||||
|
||||
drugInfo.id = id;
|
||||
drugInfo.dno = dno;
|
||||
drugInfo.MFD = MFD;
|
||||
drugInfo.EXP = EXP;
|
||||
drugInfo.quantity = Quantity;
|
||||
|
||||
SharedPreferences sharedPreferences = getSharedPreferences("user", Activity.MODE_PRIVATE);
|
||||
String token = sharedPreferences.getString("token", null);
|
||||
|
||||
//获取数据
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl("http://10.138.63.204:8080/")
|
||||
.addConverterFactory(GsonConverterFactory.create()) //返回结果用Gson解析
|
||||
.build();
|
||||
RYApi api = retrofit.create(RYApi.class);
|
||||
|
||||
Call<Result> updateDrugCall = api.updateDrug("Bearer " + token, drugInfo);
|
||||
updateDrugCall.enqueue(new retrofit2.Callback<Result>() {
|
||||
@Override
|
||||
public void onResponse(Call<Result> call, retrofit2.Response<Result> response) {
|
||||
Result result = response.body();
|
||||
if (result.code == 200) {
|
||||
Toast.makeText(Action3.this, "修改成功", Toast.LENGTH_LONG).show();
|
||||
Intent intent = new Intent(Action3.this, Action6.class);
|
||||
startActivity(intent);
|
||||
}else{
|
||||
Toast.makeText(Action3.this, "修改失败", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
if (result.code == 401){
|
||||
Toast.makeText(Action3.this, "请重新登录", Toast.LENGTH_LONG).show();
|
||||
Intent intent = new Intent(Action3.this, Login.class);
|
||||
startActivity(intent);
|
||||
AppConctroller.exit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Result> call, Throwable t) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
back.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
AppConctroller.removeActivity(Action3.this);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -11,7 +11,9 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.c202101020117.AppConctroller;
|
||||
import com.c202101020117.Login;
|
||||
import com.c202101020117.R;
|
||||
import com.c202101020117.package1.RYApi;
|
||||
|
@ -56,6 +58,12 @@ public class HomeFragment extends Fragment {
|
|||
nickNameTV.setText("用户名:" + userInfoResult.user.nickName);
|
||||
phonenumberTv.setText("手机号:" + userInfoResult.user.phonenumber);
|
||||
}
|
||||
if(userInfoResult.code == 401){
|
||||
Toast.makeText(getActivity(), "登录过期,请重新登录", Toast.LENGTH_SHORT).show();
|
||||
Intent intent = new Intent(getActivity(), Login.class);
|
||||
startActivity(intent);
|
||||
getActivity().finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.c202101020117.package1;
|
|||
import retrofit2.Call;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.PUT;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
//定义网络请求的方法
|
||||
|
|
|
@ -45,6 +45,10 @@ public interface RYApi {
|
|||
@GET("/system/adrug/expiringlist")
|
||||
Call<Drug2ListResult> getExpiringDrugList(@Header("Authorization") String token);
|
||||
|
||||
//http://127.0.0.1:8080/system/quantity
|
||||
@PUT("/system/quantity")
|
||||
Call<Result> updateDrug(@Header("Authorization") String token, @Body DrugInfo drugInfo);
|
||||
|
||||
//http://127.0.0.1:8080/system/quantity
|
||||
@POST("/system/quantity")
|
||||
Call<Result> addDrug(@Header("Authorization") String token, @Body DrugInfo drugInfo);
|
||||
|
|
Loading…
Reference in New Issue