添加机厅功能
This commit is contained in:
@@ -11,7 +11,7 @@ android {
|
|||||||
minSdk 29
|
minSdk 29
|
||||||
targetSdk 34
|
targetSdk 34
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.6.0 Ultra"
|
versionName "1.6.0 b"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class Place implements Parcelable {
|
|||||||
public void setNumJ(int numJ) {
|
public void setNumJ(int numJ) {
|
||||||
this.numJ = numJ;
|
this.numJ = numJ;
|
||||||
}
|
}
|
||||||
|
public Place() {}
|
||||||
public Place(int id, String name, String province, String city, String area, String address, int isUse, double x, double y, int count, int good, int bad) {
|
public Place(int id, String name, String province, String city, String area, String address, int isUse, double x, double y, int count, int good, int bad) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|||||||
@@ -14,8 +14,9 @@ import android.util.Log;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.widget.Toast;
|
import android.widget.*;
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
import com.google.android.material.navigation.NavigationView;
|
import com.google.android.material.navigation.NavigationView;
|
||||||
import androidx.navigation.NavController;
|
import androidx.navigation.NavController;
|
||||||
@@ -24,12 +25,17 @@ import androidx.navigation.ui.AppBarConfiguration;
|
|||||||
import androidx.navigation.ui.NavigationUI;
|
import androidx.navigation.ui.NavigationUI;
|
||||||
import androidx.drawerlayout.widget.DrawerLayout;
|
import androidx.drawerlayout.widget.DrawerLayout;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import com.google.gson.Gson;
|
||||||
import com.yalantis.ucrop.UCrop;
|
import com.yalantis.ucrop.UCrop;
|
||||||
|
import okhttp3.*;
|
||||||
import org.astral.findmaimaiultra.R;
|
import org.astral.findmaimaiultra.R;
|
||||||
|
import org.astral.findmaimaiultra.been.Place;
|
||||||
import org.astral.findmaimaiultra.databinding.ActivityMainBinding;
|
import org.astral.findmaimaiultra.databinding.ActivityMainBinding;
|
||||||
|
import org.astral.findmaimaiultra.ui.home.HomeFragment;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static android.app.Activity.RESULT_OK;
|
import static android.app.Activity.RESULT_OK;
|
||||||
|
|
||||||
@@ -81,9 +87,160 @@ public class MainActivity extends AppCompatActivity implements ImagePickerListen
|
|||||||
startActivity(update);
|
startActivity(update);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
menu.findItem(R.id.action_updatePlace).setOnMenuItemClickListener(item -> {
|
||||||
|
updatePlace();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
private void updatePlace() {
|
||||||
|
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this);
|
||||||
|
LinearLayout layout = new LinearLayout(this);
|
||||||
|
layout.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
layout.setPadding(16, 16, 16, 16);
|
||||||
|
|
||||||
|
// 创建一个 ScrollView 并将 LinearLayout 添加到其中
|
||||||
|
ScrollView scrollView = new ScrollView(this);
|
||||||
|
scrollView.addView(layout);
|
||||||
|
|
||||||
|
// 创建店铺名称输入框及其标签
|
||||||
|
TextView textNameLabel = new TextView(this);
|
||||||
|
textNameLabel.setText("店铺名称:");
|
||||||
|
EditText textName = new EditText(this);
|
||||||
|
textName.setHint("请输入店铺名称");
|
||||||
|
layout.addView(textNameLabel);
|
||||||
|
layout.addView(textName);
|
||||||
|
|
||||||
|
// 创建省份输入框及其标签
|
||||||
|
TextView textProvinceLabel = new TextView(this);
|
||||||
|
textProvinceLabel.setText("省份:");
|
||||||
|
EditText textProvince = new EditText(this);
|
||||||
|
textProvince.setHint("请输入省份");
|
||||||
|
layout.addView(textProvinceLabel);
|
||||||
|
layout.addView(textProvince);
|
||||||
|
|
||||||
|
// 创建城市输入框及其标签
|
||||||
|
TextView textCityLabel = new TextView(this);
|
||||||
|
textCityLabel.setText("城市:");
|
||||||
|
EditText textCity = new EditText(this);
|
||||||
|
textCity.setHint("请输入城市");
|
||||||
|
layout.addView(textCityLabel);
|
||||||
|
layout.addView(textCity);
|
||||||
|
|
||||||
|
// 创建地区输入框及其标签
|
||||||
|
TextView textAreaLabel = new TextView(this);
|
||||||
|
textAreaLabel.setText("地区:");
|
||||||
|
EditText textArea = new EditText(this);
|
||||||
|
textArea.setHint("请输入地区");
|
||||||
|
layout.addView(textAreaLabel);
|
||||||
|
layout.addView(textArea);
|
||||||
|
|
||||||
|
// 创建地址输入框及其标签
|
||||||
|
TextView textAddressLabel = new TextView(this);
|
||||||
|
textAddressLabel.setText("地址:");
|
||||||
|
EditText textAddress = new EditText(this);
|
||||||
|
textAddress.setHint("请输入地址");
|
||||||
|
layout.addView(textAddressLabel);
|
||||||
|
layout.addView(textAddress);
|
||||||
|
|
||||||
|
// 创建经度输入框及其标签
|
||||||
|
TextView textXLabel = new TextView(this);
|
||||||
|
textXLabel.setText("经度:");
|
||||||
|
EditText textX = new EditText(this);
|
||||||
|
textX.setHint("请输入经度");
|
||||||
|
layout.addView(textXLabel);
|
||||||
|
layout.addView(textX);
|
||||||
|
|
||||||
|
// 创建纬度输入框及其标签
|
||||||
|
TextView textYLabel = new TextView(this);
|
||||||
|
textYLabel.setText("纬度:");
|
||||||
|
EditText textY = new EditText(this);
|
||||||
|
textY.setHint("请输入纬度");
|
||||||
|
layout.addView(textYLabel);
|
||||||
|
layout.addView(textY);
|
||||||
|
|
||||||
|
// 创建国机数量输入框及其标签
|
||||||
|
TextView textNumLabel = new TextView(this);
|
||||||
|
textNumLabel.setText("国机数量:");
|
||||||
|
EditText textNum = new EditText(this);
|
||||||
|
textNum.setHint("请输入国机数量");
|
||||||
|
textNum.setText("1");
|
||||||
|
layout.addView(textNumLabel);
|
||||||
|
layout.addView(textNum);
|
||||||
|
|
||||||
|
// 创建币数量输入框及其标签
|
||||||
|
TextView textNumJLabel = new TextView(this);
|
||||||
|
textNumJLabel.setText("日机数量:");
|
||||||
|
EditText textNumJ = new EditText(this);
|
||||||
|
textNumJ.setHint("请输入日机数量");
|
||||||
|
textNumJ.setText(String.valueOf(0));
|
||||||
|
layout.addView(textNumJLabel);
|
||||||
|
layout.addView(textNumJ);
|
||||||
|
|
||||||
|
// 创建是否使用输入框及其标签
|
||||||
|
TextView textIsUseLabel = new TextView(this);
|
||||||
|
textIsUseLabel.setText("是否使用:");
|
||||||
|
EditText textIsUse = new EditText(this);
|
||||||
|
textIsUse.setHint("请输入是否使用");
|
||||||
|
textIsUse.setText(String.valueOf(1));
|
||||||
|
layout.addView(textIsUseLabel);
|
||||||
|
layout.addView(textIsUse);
|
||||||
|
Place place = new Place();
|
||||||
|
builder.setTitle("编辑店铺信息")
|
||||||
|
.setView(scrollView) // 设置 ScrollView 作为对话框的内容视图
|
||||||
|
.setPositiveButton("确定", (dialog, which) -> {
|
||||||
|
// 获取输入框的值并更新 place 对象
|
||||||
|
place.setName(textName.getText().toString());
|
||||||
|
place.setProvince(textProvince.getText().toString());
|
||||||
|
place.setCity(textCity.getText().toString());
|
||||||
|
place.setArea(textArea.getText().toString());
|
||||||
|
place.setAddress(textAddress.getText().toString());
|
||||||
|
place.setX(Double.parseDouble(textX.getText().toString()));
|
||||||
|
place.setY(Double.parseDouble(textY.getText().toString()));
|
||||||
|
place.setNum(Integer.parseInt(textNum.getText().toString()));
|
||||||
|
int num2 = 0;
|
||||||
|
try {
|
||||||
|
num2 = Integer.parseInt(textNumJ.getText().toString());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
place.setNumJ(num2);
|
||||||
|
place.setIsUse(Integer.parseInt(textIsUse.getText().toString()));
|
||||||
|
// 调用 sendUpdateNum 方法上传更新
|
||||||
|
addPlace(place);
|
||||||
|
})
|
||||||
|
.setNegativeButton("取消", null)
|
||||||
|
.show();
|
||||||
|
|
||||||
|
}
|
||||||
|
private void addPlace(Place place) {
|
||||||
|
String url = "http://mai.godserver.cn:11451/api/mai/v1/place";
|
||||||
|
String body = new Gson().toJson(place,Place.class);
|
||||||
|
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), body);
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.put(requestBody)
|
||||||
|
.build();
|
||||||
|
OkHttpClient client = new OkHttpClient();
|
||||||
|
client.newCall(request).enqueue(new Callback() {
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call call, IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call call, Response response) throws IOException {
|
||||||
|
if (response.isSuccessful()) {
|
||||||
|
final String responseData = response.body().string();
|
||||||
|
runOnUiThread(() -> {
|
||||||
|
Toast.makeText(MainActivity.this, "添加成功", Toast.LENGTH_SHORT).show();
|
||||||
|
});
|
||||||
|
}else {
|
||||||
|
Toast.makeText(MainActivity.this, "添加失败", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
|||||||
@@ -5,6 +5,10 @@
|
|||||||
android:title="@string/action_settings"
|
android:title="@string/action_settings"
|
||||||
android:orderInCategory="100"
|
android:orderInCategory="100"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never"/>
|
||||||
|
<item android:id="@+id/action_updatePlace"
|
||||||
|
android:title="新增机厅"
|
||||||
|
android:orderInCategory="100"
|
||||||
|
app:showAsAction="never"/>
|
||||||
<item android:id="@+id/action_paika"
|
<item android:id="@+id/action_paika"
|
||||||
android:title="排卡"
|
android:title="排卡"
|
||||||
android:orderInCategory="100"
|
android:orderInCategory="100"
|
||||||
@@ -13,4 +17,5 @@
|
|||||||
android:title="上传成绩"
|
android:title="上传成绩"
|
||||||
android:orderInCategory="100"
|
android:orderInCategory="100"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
Reference in New Issue
Block a user