Android代码11月30日提交
This commit is contained in:
parent
d2f54506ac
commit
397923fb2a
|
@ -18,8 +18,6 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.c202101020117.package1.Api;
|
||||
import com.c202101020117.package1.DrugList;
|
||||
import com.c202101020117.R;
|
||||
import com.c202101020117.package1.DrugListResult;
|
||||
import com.c202101020117.package1.RYApi;
|
||||
|
|
|
@ -5,6 +5,8 @@ import androidx.appcompat.app.AppCompatActivity;
|
|||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
|
@ -17,6 +19,8 @@ import com.bumptech.glide.Glide;
|
|||
import com.c202101020117.package1.Api;
|
||||
import com.c202101020117.package1.Drug2List;
|
||||
import com.c202101020117.R;
|
||||
import com.c202101020117.package1.Drug2ListResult;
|
||||
import com.c202101020117.package1.RYApi;
|
||||
import com.gyf.immersionbar.ImmersionBar;
|
||||
import com.scwang.smart.refresh.footer.ClassicsFooter;
|
||||
import com.scwang.smart.refresh.header.ClassicsHeader;
|
||||
|
@ -36,7 +40,7 @@ public class Action2 extends AppCompatActivity {
|
|||
TextView back;
|
||||
SmartRefreshLayout smartRefreshLayout;
|
||||
|
||||
Drug2List drugs;
|
||||
Drug2ListResult drugs;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -57,23 +61,27 @@ public class Action2 extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
|
||||
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();
|
||||
Api api = retrofit.create(Api.class);
|
||||
RYApi api = retrofit.create(RYApi.class);
|
||||
|
||||
Call<Drug2ListResult> drug2ListResultCall = api.getExpiringDrugList("Bearer " + token);
|
||||
drug2ListResultCall.enqueue(new Callback<Drug2ListResult>() {
|
||||
|
||||
Call<Drug2List> drugListCall = api.getExpiringDrugList();
|
||||
drugListCall.enqueue(new Callback<Drug2List>() {
|
||||
@Override
|
||||
public void onResponse(Call<Drug2List> call, Response<Drug2List> response) {
|
||||
public void onResponse(Call<Drug2ListResult> call, Response<Drug2ListResult> response) {
|
||||
drugs = response.body();
|
||||
myAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Drug2List> call, Throwable t) {
|
||||
public void onFailure(Call<Drug2ListResult> call, Throwable t) {
|
||||
|
||||
}
|
||||
});
|
||||
|
@ -85,26 +93,21 @@ public class Action2 extends AppCompatActivity {
|
|||
smartRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
|
||||
// Retrofit retrofit = new Retrofit.Builder()
|
||||
// .baseUrl("http://10.138.63.204:8080/")
|
||||
// .addConverterFactory(GsonConverterFactory.create()) //返回结果用Gson解析
|
||||
// .build();
|
||||
// Api api = retrofit.create(Api.class);
|
||||
|
||||
Call<Drug2List> drugListCall = api.getExpiringDrugList();
|
||||
drugListCall.enqueue(new Callback<Drug2List>() {
|
||||
Call<Drug2ListResult> drug2ListResultCall = api.getExpiringDrugList("Bearer " + token);
|
||||
drug2ListResultCall.enqueue(new Callback<Drug2ListResult>() {
|
||||
@Override
|
||||
public void onResponse(Call<Drug2List> call, Response<Drug2List> response) {
|
||||
public void onResponse(Call<Drug2ListResult> call, Response<Drug2ListResult> response) {
|
||||
drugs = response.body();
|
||||
smartRefreshLayout.finishRefresh(500);
|
||||
myAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Drug2List> call, Throwable t) {
|
||||
public void onFailure(Call<Drug2ListResult> call, Throwable t) {
|
||||
|
||||
}
|
||||
});
|
||||
smartRefreshLayout.finishRefresh(500);
|
||||
myAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -124,14 +127,14 @@ public class Action2 extends AppCompatActivity {
|
|||
@Override
|
||||
//每个条目加载一次,该方法就会被调用一次
|
||||
public void onBindViewHolder(@NonNull MyViewHoler holder, int position) {
|
||||
holder.DnoTv.setText(drugs.drugList.get(position).dno);
|
||||
holder.DnameTv.setText(drugs.drugList.get(position).name);
|
||||
holder.SnoTv.setText(drugs.drugList.get(position).sno);
|
||||
holder.MFDTv.setText(drugs.drugList.get(position).mfd);
|
||||
holder.EXPTv.setText(drugs.drugList.get(position).exp);
|
||||
holder.QuantityTv.setText(drugs.drugList.get(position).quantity+"");
|
||||
holder.DatediffTv.setText((int)(drugs.drugList.get(position).datediff)+"");
|
||||
Glide.with(Action2.this).load(drugs.drugList.get(position).picture).into(holder.imageView);
|
||||
holder.DnoTv.setText(drugs.rows.get(position).dno);
|
||||
holder.DnameTv.setText(drugs.rows.get(position).name);
|
||||
holder.SnoTv.setText(drugs.rows.get(position).sno);
|
||||
holder.MFDTv.setText(drugs.rows.get(position).mFD);
|
||||
holder.EXPTv.setText(drugs.rows.get(position).eXP);
|
||||
holder.QuantityTv.setText(drugs.rows.get(position).quantity+"");
|
||||
holder.DatediffTv.setText((int)(drugs.rows.get(position).datediff)+"");
|
||||
Glide.with(Action2.this).load(drugs.rows.get(position).picture).into(holder.imageView);
|
||||
holder.constraintLayout.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
@ -154,7 +157,7 @@ public class Action2 extends AppCompatActivity {
|
|||
//用来控制限制列表条数
|
||||
public int getItemCount() {
|
||||
if(drugs != null)
|
||||
return drugs.drugList.size();
|
||||
return drugs.rows.size();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -2,23 +2,27 @@ package com.c202101020117.Action;
|
|||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.app.Activity;
|
||||
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.R;
|
||||
import com.c202101020117.package1.Api;
|
||||
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.Callback;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
public class Action4 extends AppCompatActivity {
|
||||
public class Action4 extends AppCompatActivity {
|
||||
|
||||
TextView back;
|
||||
EditText text1;
|
||||
|
@ -39,36 +43,48 @@ public class Action4 extends AppCompatActivity {
|
|||
text4 = findViewById(R.id.editTextTextPersonName6);
|
||||
confirm = findViewById(R.id.textView78);
|
||||
|
||||
SharedPreferences sharedPreferences = getSharedPreferences("action1",MODE_PRIVATE);
|
||||
SharedPreferences sharedPreferences = getSharedPreferences("action1", MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
Boolean need = sharedPreferences.getBoolean("need",false);
|
||||
Boolean need = sharedPreferences.getBoolean("need", false);
|
||||
|
||||
if(need){
|
||||
text1.setText(sharedPreferences.getString("dno",""));
|
||||
if (need) {
|
||||
text1.setText(sharedPreferences.getString("dno", ""));
|
||||
editor.clear();
|
||||
editor.commit();
|
||||
}else{
|
||||
} else {
|
||||
text1.setText("");
|
||||
}
|
||||
|
||||
confirm.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
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();
|
||||
Api api = retrofit.create(Api.class);
|
||||
RYApi api = retrofit.create(RYApi.class);
|
||||
|
||||
Call<Result> addDrug = api.addDrug(text1.getText()+"",text3.getText()+"",text2.getText()+"",Integer.parseInt(text4.getText()+""));
|
||||
addDrug.enqueue(new Callback<Result>(){
|
||||
DrugInfo drugInfo = new DrugInfo();
|
||||
drugInfo.dno = text1.getText() + "";
|
||||
drugInfo.EXP = text3.getText() + "";
|
||||
drugInfo.MFD = text2.getText() + "";
|
||||
drugInfo.quantity = Integer.parseInt(text4.getText() + "");
|
||||
|
||||
Call<Result> addDrug = api.addDrug("Bearer " + token, drugInfo);
|
||||
addDrug.enqueue(new Callback<Result>() {
|
||||
@Override
|
||||
public void onResponse(Call<Result> call, Response<Result> response) {
|
||||
Result result = response.body();
|
||||
if(result.code==0){
|
||||
Toast.makeText(Action4.this,"增添成功",Toast.LENGTH_LONG).show();
|
||||
if (result.code == 200) {
|
||||
Toast.makeText(Action4.this, "增添成功", Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
}else{
|
||||
Toast.makeText(Action4.this,"数据输入错误",Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
Toast.makeText(Action4.this, "数据输入错误", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,24 @@
|
|||
package com.c202101020117.Action;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.app.Activity;
|
||||
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.R;
|
||||
import com.c202101020117.package1.Api;
|
||||
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.Callback;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
|
@ -34,17 +41,17 @@ public class Action5 extends AppCompatActivity {
|
|||
text3 = findViewById(R.id.editTextTextPersonName9);
|
||||
confirm = findViewById(R.id.textView86);
|
||||
|
||||
SharedPreferences sharedPreferences = getSharedPreferences("action2",MODE_PRIVATE);
|
||||
SharedPreferences sharedPreferences = getSharedPreferences("action2", MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
Boolean need = sharedPreferences.getBoolean("need",false);
|
||||
Boolean need = sharedPreferences.getBoolean("need", false);
|
||||
|
||||
if(need){
|
||||
text1.setText(sharedPreferences.getString("Dno",""));
|
||||
text2.setText(sharedPreferences.getString("MFD",""));
|
||||
text3.setText(sharedPreferences.getString("EXP",""));
|
||||
if (need) {
|
||||
text1.setText(sharedPreferences.getString("Dno", ""));
|
||||
text2.setText(sharedPreferences.getString("MFD", ""));
|
||||
text3.setText(sharedPreferences.getString("EXP", ""));
|
||||
editor.clear();
|
||||
editor.commit();
|
||||
}else{
|
||||
} else {
|
||||
text1.setText("");
|
||||
text2.setText("");
|
||||
text3.setText("");
|
||||
|
@ -53,24 +60,35 @@ public class Action5 extends AppCompatActivity {
|
|||
confirm.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
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();
|
||||
Api api = retrofit.create(Api.class);
|
||||
RYApi api = retrofit.create(RYApi.class);
|
||||
|
||||
Call<Result> deleteDrug = api.deleteDrug(text1.getText()+"",text3.getText()+"",text2.getText()+"");
|
||||
deleteDrug.enqueue(new retrofit2.Callback<Result>() {
|
||||
DrugInfo drugInfo = new DrugInfo();
|
||||
drugInfo.dno = text1.getText() + "";
|
||||
drugInfo.EXP = text3.getText() + "";
|
||||
drugInfo.MFD = text2.getText() + "";
|
||||
|
||||
Call<Result> deleteDrug = api.deleteDrug("Bearer " + token, drugInfo);
|
||||
deleteDrug.enqueue(new Callback<Result>() {
|
||||
@Override
|
||||
public void onResponse(Call<Result> call, retrofit2.Response<Result> response) {
|
||||
public void onResponse(Call<Result> call, Response<Result> response) {
|
||||
Result result = response.body();
|
||||
if(result.code==0){
|
||||
Toast.makeText(Action5.this,"删除成功",Toast.LENGTH_LONG).show();
|
||||
if (result.code == 200) {
|
||||
Toast.makeText(Action5.this, "删除成功", Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
}else{
|
||||
Toast.makeText(Action5.this,"数据输入错误",Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
Toast.makeText(Action5.this, "数据输入错误", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Result> call, Throwable t) {
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package com.c202101020117;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AppConctroller extends Application {
|
||||
public static List<Activity> lists = new ArrayList<>();
|
||||
|
||||
public static void addActivity(Activity activity) {
|
||||
lists.add(activity);
|
||||
}
|
||||
|
||||
public static void removeActivity(Activity activity) {
|
||||
lists.remove(activity);
|
||||
}
|
||||
|
||||
public static void exit() {
|
||||
for (Activity activity : lists) {
|
||||
activity.finish();
|
||||
}
|
||||
lists.clear();
|
||||
}
|
||||
}
|
|
@ -17,9 +17,11 @@ import android.view.ViewGroup;
|
|||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.c202101020117.Action.DetailedInformation;
|
||||
import com.c202101020117.Login;
|
||||
import com.c202101020117.R;
|
||||
import com.c202101020117.package1.DrugListResult;
|
||||
import com.c202101020117.package1.RYApi;
|
||||
|
|
|
@ -2,8 +2,11 @@ package com.c202101020117;
|
|||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.c202101020117.Fragment.HomeFragment;
|
||||
import com.c202101020117.Fragment.DrugListFragment;
|
||||
import com.c202101020117.Fragment.ScreeningFragment;
|
||||
|
@ -27,14 +30,17 @@ public class Home extends AppCompatActivity {
|
|||
setContentView(R.layout.activity_home);
|
||||
ImmersionBar.with(this).init();
|
||||
|
||||
AppConctroller.addActivity(this);
|
||||
Toast.makeText(this, AppConctroller.lists.size()+"", Toast.LENGTH_LONG).show();
|
||||
|
||||
homeFragment = new HomeFragment();
|
||||
drugListFragment = new DrugListFragment();
|
||||
screeningFragment = new ScreeningFragment();
|
||||
updateFragment = new UpdateFragment();
|
||||
getSupportFragmentManager().beginTransaction().add(R.id.fragment,homeFragment).commit();
|
||||
getSupportFragmentManager().beginTransaction().add(R.id.fragment,drugListFragment).commit();
|
||||
getSupportFragmentManager().beginTransaction().add(R.id.fragment,screeningFragment).commit();
|
||||
getSupportFragmentManager().beginTransaction().add(R.id.fragment,updateFragment).commit();
|
||||
getSupportFragmentManager().beginTransaction().add(R.id.fragment, homeFragment).commit();
|
||||
getSupportFragmentManager().beginTransaction().add(R.id.fragment, drugListFragment).commit();
|
||||
getSupportFragmentManager().beginTransaction().add(R.id.fragment, screeningFragment).commit();
|
||||
getSupportFragmentManager().beginTransaction().add(R.id.fragment, updateFragment).commit();
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.show(homeFragment)
|
||||
.hide(drugListFragment)
|
||||
|
@ -114,6 +120,5 @@ public class Home extends AppCompatActivity {
|
|||
.commit();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.c202101020117.package1;
|
||||
|
||||
public class DrugInfo {
|
||||
public Integer id;
|
||||
public String dno;
|
||||
public String EXP;
|
||||
public String MFD;
|
||||
public Integer quantity;
|
||||
}
|
|
@ -1,12 +1,15 @@
|
|||
package com.c202101020117.package1;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.DELETE;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Header;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.PUT;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface RYApi {
|
||||
|
@ -35,6 +38,14 @@ public interface RYApi {
|
|||
Call<DrugListResult> getUndersupplyDrugList(@Header("Authorization") String token);
|
||||
|
||||
//http://127.0.0.1:8080/system/adrug/expiringlist
|
||||
@GET("/system/adrug/expiringlist")
|
||||
Call<Drug2ListResult> getExpiringDrugList(@Header("Authorization") String token);
|
||||
|
||||
//http://127.0.0.1:8080/system/quantity
|
||||
@POST("/system/quantity")
|
||||
Call<Result> addDrug(@Header("Authorization") String token, @Body DrugInfo drugInfo);
|
||||
|
||||
//http://127.0.0.1:8080/system/adrug/remove
|
||||
@POST("/system/adrug/remove")
|
||||
Call<Result> deleteDrug(@Header("Authorization") String token, @Body DrugInfo drugInfo);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue