mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 13:38:41 +00:00
Change url api to mockapi
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
package com.capstone.foodify.API;
|
||||
|
||||
import com.capstone.foodify.Model.DistrictWard.DisctrictWardResponse;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
|
||||
public interface DistrictWardApi {
|
||||
|
||||
Gson gson = new GsonBuilder().setDateFormat("HH:mm:ss dd-MM-yyyy").create();
|
||||
|
||||
DistrictWardApi apiService = new Retrofit.Builder()
|
||||
.baseUrl("https://vn-public-apis.fpo.vn/").addConverterFactory(GsonConverterFactory.create(gson))
|
||||
.build()
|
||||
.create(DistrictWardApi.class);
|
||||
|
||||
@GET("wards/getByDistrict")
|
||||
Call<DisctrictWardResponse> wardResponse(@Query("districtCode") int districtCode, @Query("limit") int limit);
|
||||
|
||||
@GET("districts/getByProvince")
|
||||
Call<DisctrictWardResponse> districtResponse(@Query("provinceCode") int provinceCode, @Query("limit") int limit);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.capstone.foodify.API;
|
||||
|
||||
import com.capstone.foodify.Model.Category.Category;
|
||||
import com.capstone.foodify.Model.DistrictWard.DistrictWardResponse;
|
||||
import com.capstone.foodify.Model.Food.Food;
|
||||
import com.capstone.foodify.Model.Food.ImageFood;
|
||||
import com.google.gson.Gson;
|
||||
@@ -48,4 +49,10 @@ public interface FoodApi {
|
||||
|
||||
@GET("detail/{id}/image")
|
||||
Call<List<ImageFood>> getImageFoodById(@Path("id") String id);
|
||||
|
||||
@GET("district/{districtId}/ward")
|
||||
Call<List<DistrictWardResponse>> wardResponse(@Path("districtId") int district_id);
|
||||
|
||||
@GET("district")
|
||||
Call<List<DistrictWardResponse>> districtResponse();
|
||||
}
|
||||
|
||||
@@ -18,9 +18,8 @@ import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.capstone.foodify.API.DistrictWardApi;
|
||||
import com.capstone.foodify.Model.DistrictWard.Datas;
|
||||
import com.capstone.foodify.Model.DistrictWard.DisctrictWardResponse;
|
||||
import com.capstone.foodify.API.FoodApi;
|
||||
import com.capstone.foodify.Model.DistrictWard.DistrictWardResponse;
|
||||
import com.capstone.foodify.R;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
|
||||
@@ -36,9 +35,6 @@ import retrofit2.Response;
|
||||
|
||||
public class SignUpActivity extends AppCompatActivity {
|
||||
|
||||
private static final int PROVINCE_CODE = 48;
|
||||
private static final int LIMIT = -1;
|
||||
|
||||
TextInputLayout textInput_email, textInput_password, textInput_phone,
|
||||
textInput_address, textInput_repeatPassword, textInput_firstName, textInput_lastName, textInput_birthDay;
|
||||
final Calendar myCalendar= Calendar.getInstance();
|
||||
@@ -49,8 +45,6 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
|
||||
private static final ArrayList<String> wardList = new ArrayList<>();
|
||||
private static final ArrayList<String> districtList = new ArrayList<>();
|
||||
private static List<Datas> districtListData = new ArrayList<>();
|
||||
private static List<Datas> wardListData = new ArrayList<>();
|
||||
|
||||
String selectedDistrict = "";
|
||||
|
||||
@@ -65,7 +59,7 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
setFontUI();
|
||||
chooseDateOfBirth();
|
||||
|
||||
if(districtListData.size() == 0){
|
||||
if(districtList.size() == 0){
|
||||
getListDistrict();
|
||||
} else {
|
||||
setAdapter(districtList, "---Quận", districtSpinner);
|
||||
@@ -88,18 +82,7 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
districtSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
|
||||
int districtCode = 0;
|
||||
|
||||
selectedDistrict = districtSpinner.getSelectedItem().toString();
|
||||
|
||||
//Get id district from selected item district;
|
||||
for(Datas dataTemp: districtListData){
|
||||
if(selectedDistrict.equals(dataTemp.getName_with_type())){
|
||||
districtCode = Integer.parseInt(dataTemp.getCode());
|
||||
break;
|
||||
}
|
||||
}
|
||||
getListWard(districtCode);
|
||||
getListWard(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -134,23 +117,21 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
|
||||
districtList.add("---Quận");
|
||||
|
||||
DistrictWardApi.apiService.districtResponse(PROVINCE_CODE, LIMIT).enqueue(new Callback<DisctrictWardResponse>() {
|
||||
FoodApi.apiService.districtResponse().enqueue(new Callback<List<DistrictWardResponse>>() {
|
||||
@Override
|
||||
public void onResponse(Call<DisctrictWardResponse> call, Response<DisctrictWardResponse> response) {
|
||||
DisctrictWardResponse districtResponse = response.body();
|
||||
if(districtResponse != null && districtResponse.getExitcode() == 1){
|
||||
|
||||
districtListData = districtResponse.getData().getData();
|
||||
for(Datas tempData: districtListData){
|
||||
districtList.add(tempData.getName_with_type());
|
||||
public void onResponse(Call<List<DistrictWardResponse>> call, Response<List<DistrictWardResponse>> response) {
|
||||
List<DistrictWardResponse> districtResponse = response.body();
|
||||
if(districtResponse != null){
|
||||
for(DistrictWardResponse tempDistrict: districtResponse){
|
||||
districtList.add(tempDistrict.getName());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
setAdapter(districtList, "---Quận", districtSpinner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<DisctrictWardResponse> call, Throwable t) {
|
||||
public void onFailure(Call<List<DistrictWardResponse>> call, Throwable t) {
|
||||
Toast.makeText(SignUpActivity.this, "Đã xảy ra lỗi hệ thống. Vui lòng thử lại sau!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
@@ -164,25 +145,31 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
if(wardList.size() == 0)
|
||||
wardList.add("---Phường");
|
||||
|
||||
wardSpinner.setEnabled(false);
|
||||
|
||||
if(districtCode != 0){
|
||||
DistrictWardApi.apiService.wardResponse(districtCode, LIMIT).enqueue(new Callback<DisctrictWardResponse>() {
|
||||
FoodApi.apiService.wardResponse(districtCode).enqueue(new Callback<List<DistrictWardResponse>>() {
|
||||
@Override
|
||||
public void onResponse(Call<DisctrictWardResponse> call, Response<DisctrictWardResponse> response) {
|
||||
public void onResponse(Call<List<DistrictWardResponse>> call, Response<List<DistrictWardResponse>> response) {
|
||||
List<DistrictWardResponse> wardData = response.body();
|
||||
|
||||
DisctrictWardResponse wardResponse = response.body();
|
||||
if(wardResponse != null && wardResponse.getExitcode() == 1){
|
||||
|
||||
wardListData = wardResponse.getData().getData();
|
||||
for(Datas tempData: wardListData){
|
||||
wardList.add(tempData.getName_with_type());
|
||||
if(wardData != null){
|
||||
for(DistrictWardResponse tempWard: wardData){
|
||||
wardList.add(tempWard.getName());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if(wardList.size() <= 1){
|
||||
wardSpinner.setEnabled(false);
|
||||
} else {
|
||||
wardSpinner.setEnabled(true);
|
||||
}
|
||||
|
||||
setAdapter(wardList, "---Phường", wardSpinner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<DisctrictWardResponse> call, Throwable t) {
|
||||
public void onFailure(Call<List<DistrictWardResponse>> call, Throwable t) {
|
||||
Toast.makeText(SignUpActivity.this, "Đã xảy ra lỗi hệ thống. Vui lòng thử lại sau!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.capstone.foodify.Model.DistrictWard;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Data {
|
||||
private int nItems;
|
||||
private int nPages;
|
||||
private List<Datas> data;
|
||||
|
||||
public int getnItems() {
|
||||
return nItems;
|
||||
}
|
||||
|
||||
public void setnItems(int nItems) {
|
||||
this.nItems = nItems;
|
||||
}
|
||||
|
||||
public int getnPages() {
|
||||
return nPages;
|
||||
}
|
||||
|
||||
public void setnPages(int nPages) {
|
||||
this.nPages = nPages;
|
||||
}
|
||||
|
||||
public List<Datas> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(List<Datas> data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
package com.capstone.foodify.Model.DistrictWard;
|
||||
|
||||
public class Datas {
|
||||
private String _id;
|
||||
private String name;
|
||||
private String type;
|
||||
private String slug;
|
||||
private String name_with_type;
|
||||
private String path;
|
||||
private String path_with_type;
|
||||
private String code;
|
||||
private String parent_code;
|
||||
private String isDeleted;
|
||||
|
||||
public String get_id() {
|
||||
return _id;
|
||||
}
|
||||
|
||||
public void set_id(String _id) {
|
||||
this._id = _id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getSlug() {
|
||||
return slug;
|
||||
}
|
||||
|
||||
public void setSlug(String slug) {
|
||||
this.slug = slug;
|
||||
}
|
||||
|
||||
public String getName_with_type() {
|
||||
return name_with_type;
|
||||
}
|
||||
|
||||
public void setName_with_type(String name_with_type) {
|
||||
this.name_with_type = name_with_type;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public String getPath_with_type() {
|
||||
return path_with_type;
|
||||
}
|
||||
|
||||
public void setPath_with_type(String paht_with_type) {
|
||||
this.path_with_type = paht_with_type;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getParent_code() {
|
||||
return parent_code;
|
||||
}
|
||||
|
||||
public void setParent_code(String parent_code) {
|
||||
this.parent_code = parent_code;
|
||||
}
|
||||
|
||||
public String getIsDeleted() {
|
||||
return isDeleted;
|
||||
}
|
||||
|
||||
public void setIsDeleted(String isDeleted) {
|
||||
this.isDeleted = isDeleted;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.capstone.foodify.Model.DistrictWard;
|
||||
|
||||
public class DisctrictWardResponse {
|
||||
private int exitcode;
|
||||
private Data data;
|
||||
private String message;
|
||||
|
||||
public int getExitcode() {
|
||||
return exitcode;
|
||||
}
|
||||
|
||||
public void setExitcode(int exitcode) {
|
||||
this.exitcode = exitcode;
|
||||
}
|
||||
|
||||
public Data getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Data data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.capstone.foodify.Model.DistrictWard;
|
||||
|
||||
public class DistrictWardResponse {
|
||||
private String id;
|
||||
private String name;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -188,22 +188,24 @@
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/district"
|
||||
android:layout_width="150dp"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:textAlignment="viewEnd"
|
||||
android:gravity="end"
|
||||
android:paddingEnd="25dp"
|
||||
android:contentDescription="district"
|
||||
android:layout_weight="0.4"
|
||||
/>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/ward"
|
||||
android:textAlignment="viewEnd"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="end"
|
||||
android:paddingEnd="25dp"
|
||||
android:contentDescription="ward"
|
||||
android:layout_weight="0.6"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
Reference in New Issue
Block a user