Refactor code, check internet connection

This commit is contained in:
Nezumi
2023-04-14 11:47:56 +07:00
parent 8462156b5d
commit f91ca323b5
31 changed files with 1181 additions and 353 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ android {
minSdk 26
targetSdk 32
versionCode 1
versionName "0.1.1"
versionName "0.1.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
signingConfig signingConfigs.release
Binary file not shown.
+1 -1
View File
@@ -12,7 +12,7 @@
"filters": [],
"attributes": [],
"versionCode": 1,
"versionName": "0.1.1",
"versionName": "0.1.2",
"outputFile": "app-release.apk"
}
],
@@ -63,9 +63,6 @@ public interface FoodApi {
@GET("products/{id}")
Call<Food> detailFood(@Path("id") String id);
@GET("shops/{id}")
Call<Shop> detailShop(@Path("id") int id);
@GET("products/shops/{id}")
Call<Foods> listFoodByShopId(@Path("id") int id, @Query("pageNo") int pageNo, @Query("pageSize") int pageSize, @Query("sortBy") String sortBy, @Query("sortDir") String sortDir);
@@ -3,10 +3,14 @@ package com.capstone.foodify.Activity;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.net.Uri;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.View;
import android.webkit.MimeTypeMap;
import android.widget.Button;
@@ -21,6 +25,7 @@ import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
@@ -42,11 +47,8 @@ import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;
import com.makeramen.roundedimageview.RoundedImageView;
import com.squareup.picasso.Picasso;
import com.thecode.aestheticdialogs.AestheticDialog;
import com.thecode.aestheticdialogs.DialogAnimation;
import com.thecode.aestheticdialogs.DialogStyle;
import com.thecode.aestheticdialogs.DialogType;
import com.thecode.aestheticdialogs.OnDialogClickListener;
import java.text.SimpleDateFormat;
import java.util.Calendar;
@@ -59,21 +61,22 @@ import retrofit2.Response;
public class AccountAndProfileActivity extends AppCompatActivity {
private static final String TAG = "AccountAndProfileActivity";
private static final String FOLDER_DIRECTORY = "UserImages/";
TextInputLayout textInput_email, textInput_phone, textInput_fullName, textInput_birthDay;
TextView txt_countdown, txt_resend_code, txt_verify_email;
EditText edt_birthday, edt_email, edt_phone, edt_fullName;
final Calendar myCalendar= Calendar.getInstance();
LinearLayout change_password, countdown_layout;
Button update_button, update_image_button;
ImageView back_image;
RoundedImageView profile_avatar;
private TextInputLayout textInput_email, textInput_phone, textInput_fullName, textInput_birthDay;
private TextView txt_countdown, txt_resend_code, txt_verify_email;
private EditText edt_birthday, edt_email, edt_phone, edt_fullName;
private final Calendar myCalendar= Calendar.getInstance();
private LinearLayout change_password, countdown_layout;
private Button update_button, update_image_button;
private ImageView back_image;
private RoundedImageView profile_avatar;
private Uri imageUri;
final private StorageReference storageReference = FirebaseStorage.getInstance().getReference();
ConstraintLayout progressLayout;
FirebaseAuth mAuth;
FirebaseUser firebaseUser;
CountDownTimer count = new CountDownTimer(60000, 1000) {
private final StorageReference storageReference = FirebaseStorage.getInstance().getReference();
private ConstraintLayout progressLayout;
private FirebaseAuth mAuth;
private FirebaseUser firebaseUser;
private final CountDownTimer count = new CountDownTimer(60000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
txt_countdown.setText(millisUntilFinished / 1000 + " giây");
@@ -95,6 +98,10 @@ public class AccountAndProfileActivity extends AppCompatActivity {
initComponent();
setFontUI();
if(getConnectionType() == 0){
Common.showErrorInternetConnectionNotification(this);
}
//Init data
initData();
@@ -206,7 +213,7 @@ public class AccountAndProfileActivity extends AppCompatActivity {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(AccountAndProfileActivity.this, "Failed", Toast.LENGTH_SHORT).show();
Toast.makeText(AccountAndProfileActivity.this, "Tải ảnh thất bại!", Toast.LENGTH_SHORT).show();
}
});
}
@@ -319,7 +326,7 @@ public class AccountAndProfileActivity extends AppCompatActivity {
@Override
public void onFailure(Call<User> call, Throwable t) {
Common.showErrorServerNotification(AccountAndProfileActivity.this, "Không thể cập nhật thông tin, vui lòng thử lại sau!");
Log.e(TAG, t.toString());
progressLayout.setVisibility(View.GONE);
}
});
@@ -387,4 +394,23 @@ public class AccountAndProfileActivity extends AppCompatActivity {
SimpleDateFormat dateFormat=new SimpleDateFormat(Common.FORMAT_DATE, Locale.US);
edt_birthday.setText(dateFormat.format(myCalendar.getTime()));
}
@IntRange(from = 0, to = 3)
public int getConnectionType() {
int result = 0; // Returns connection type. 0: none; 1: mobile data; 2: wifi
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm != null) {
NetworkCapabilities capabilities = cm.getNetworkCapabilities(cm.getActiveNetwork());
if (capabilities != null) {
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
result = 2;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
result = 1;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
result = 3;
}
}
}
return result;
}
}
@@ -2,7 +2,10 @@ package com.capstone.foodify.Activity;
import android.content.Context;
import android.graphics.Typeface;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -16,6 +19,7 @@ import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.IntRange;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
@@ -47,6 +51,7 @@ import retrofit2.Response;
public class AddressManagerActivity extends AppCompatActivity {
private static final String TAG = "AddressManagerActivity";
private Address defaultAddress = null;
private RecyclerView recycler_view_address;
private AddressAdapter adapter;
@@ -55,14 +60,33 @@ public class AddressManagerActivity extends AppCompatActivity {
private ImageView back_image, edit_btn;
private TextView txt_Address, errorTextDistrictWard;
private List<Address> listAddress = new ArrayList<>();
Spinner wardSpinner, districtSpinner;
EditText edt_address;
ConstraintLayout progressLayout, progressLayoutDialog;
CheckBox default_address_checkbox;
private Spinner wardSpinner, districtSpinner;
private EditText edt_address;
private ConstraintLayout progressLayout, progressLayoutDialog;
private CheckBox default_address_checkbox;
private static final ArrayList<String> wardList = new ArrayList<>();
private static final ArrayList<String> districtList = new ArrayList<>();
String address, ward, district;
@IntRange(from = 0, to = 3)
public int getConnectionType() {
int result = 0; // Returns connection type. 0: none; 1: mobile data; 2: wifi
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm != null) {
NetworkCapabilities capabilities = cm.getNetworkCapabilities(cm.getActiveNetwork());
if (capabilities != null) {
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
result = 2;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
result = 1;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
result = 3;
}
}
}
return result;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -76,6 +100,10 @@ public class AddressManagerActivity extends AppCompatActivity {
progressLayout = findViewById(R.id.progress_layout);
edit_btn = findViewById(R.id.edit_button);
if(getConnectionType() == 0){
Common.showErrorInternetConnectionNotification(this);
}
//Set layout recyclerview
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
recycler_view_address.setLayoutManager(linearLayoutManager);
@@ -184,7 +212,7 @@ public class AddressManagerActivity extends AppCompatActivity {
@Override
public void onFailure(Call<CustomResponse> call, Throwable t) {
Toast.makeText(AddressManagerActivity.this, "Đã có lỗi từ hệ thống, vui lòng thử lại sau!", Toast.LENGTH_SHORT).show();
Log.e(TAG, t.toString());
}
});
}
@@ -201,7 +229,7 @@ public class AddressManagerActivity extends AppCompatActivity {
@Override
public void onFailure(Call<CustomResponse> call, Throwable t) {
Toast.makeText(AddressManagerActivity.this, "Đã có lỗi từ hệ thống! Vui lòng thử lại sau!", Toast.LENGTH_SHORT).show();
Log.e(TAG, t.toString());
}
});
}
@@ -221,7 +249,7 @@ public class AddressManagerActivity extends AppCompatActivity {
@Override
public void onFailure(Call<User> call, Throwable t) {
Toast.makeText(AddressManagerActivity.this, "Đã có lỗi khi thay đổi địa chỉ mặc định, vui lòng thử lại sau!", Toast.LENGTH_SHORT).show();
Log.e(TAG, t.toString());
}
});
}
@@ -249,6 +277,7 @@ public class AddressManagerActivity extends AppCompatActivity {
@Override
public void onFailure(Call<User> call, Throwable t) {
Log.e(TAG, t.toString());
}
});
}
@@ -318,7 +347,7 @@ public class AddressManagerActivity extends AppCompatActivity {
@Override
public void onFailure(Call<CustomResponse> call, Throwable t) {
Log.e(TAG, t.toString());
}
});
}
@@ -327,14 +356,7 @@ public class AddressManagerActivity extends AppCompatActivity {
View view = LayoutInflater.from(this).inflate(R.layout.add_address_dialog,null);
//Init component
textInput_address = view.findViewById(R.id.textInput_address);
wardSpinner = view.findViewById(R.id.ward);
districtSpinner = view.findViewById(R.id.district);
edt_address = view.findViewById(R.id.edt_address);
errorTextDistrictWard = view.findViewById(R.id.errorTextDistrictWard);
progressLayoutDialog = view.findViewById(R.id.progress_layout);
default_address_checkbox = view.findViewById(R.id.checkbox_default_address);
initComponent(view);
//Set font
textInput_address.setTypeface(Common.setFontOpenSans(getAssets()));
@@ -463,6 +485,16 @@ public class AddressManagerActivity extends AppCompatActivity {
customViewDialog.show();
}
private void initComponent(View view) {
textInput_address = view.findViewById(R.id.textInput_address);
wardSpinner = view.findViewById(R.id.ward);
districtSpinner = view.findViewById(R.id.district);
edt_address = view.findViewById(R.id.edt_address);
errorTextDistrictWard = view.findViewById(R.id.errorTextDistrictWard);
progressLayoutDialog = view.findViewById(R.id.progress_layout);
default_address_checkbox = view.findViewById(R.id.checkbox_default_address);
}
private boolean validData(String address, String ward, String district){
//Valid data
boolean dataHasValidate = true;
@@ -511,7 +543,7 @@ public class AddressManagerActivity extends AppCompatActivity {
@Override
public void onFailure(Call<List<DistrictWardResponse>> call, Throwable t) {
Toast.makeText(AddressManagerActivity.this, "Đã xảy ra lỗi hệ thống. Vui lòng thử lại sau!", Toast.LENGTH_SHORT).show();
Log.e(TAG, t.toString());
}
});
}
@@ -548,7 +580,7 @@ public class AddressManagerActivity extends AppCompatActivity {
@Override
public void onFailure(Call<List<DistrictWardResponse>> call, Throwable t) {
Toast.makeText(AddressManagerActivity.this, "Đã xảy ra lỗi hệ thống. Vui lòng thử lại sau!", Toast.LENGTH_SHORT).show();
Log.e(TAG, t.toString());
}
});
} else {
@@ -1,10 +1,14 @@
package com.capstone.foodify.Activity;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import android.content.Context;
import android.graphics.Typeface;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
@@ -33,13 +37,32 @@ import java.util.regex.Pattern;
public class ChangePasswordActivity extends AppCompatActivity {
TextInputLayout textInput_old_password, textInput_password, textInput_password_confirm;
EditText edtOldPassword, edtPassword, edtPasswordConfirm;
ImageView back_image;
ConstraintLayout progressLayout;
private TextInputLayout textInput_old_password, textInput_password, textInput_password_confirm;
private EditText edtOldPassword, edtPassword, edtPasswordConfirm;
private ImageView back_image;
private ConstraintLayout progressLayout;
Button changePasswordButton;
@IntRange(from = 0, to = 3)
public int getConnectionType() {
int result = 0; // Returns connection type. 0: none; 1: mobile data; 2: wifi
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm != null) {
NetworkCapabilities capabilities = cm.getNetworkCapabilities(cm.getActiveNetwork());
if (capabilities != null) {
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
result = 2;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
result = 1;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
result = 3;
}
}
}
return result;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -48,6 +71,10 @@ public class ChangePasswordActivity extends AppCompatActivity {
initComponent();
setFontUI();
if(getConnectionType() == 0){
Common.showErrorInternetConnectionNotification(this);
}
//Handle event when back image on click
back_image.setOnClickListener(new View.OnClickListener() {
@Override
@@ -1,8 +1,12 @@
package com.capstone.foodify.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
@@ -10,6 +14,7 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
@@ -38,6 +43,7 @@ import retrofit2.Callback;
import retrofit2.Response;
public class FavoriteFoodActivity extends AppCompatActivity implements ItemTouchHelperListener {
private static final String TAG = "FavoriteFoodActivity";
private static int CURRENT_PAGE = 0;
private static final int PAGE_SIZE = 8;
private static final String SORT_BY = "name";
@@ -52,18 +58,37 @@ public class FavoriteFoodActivity extends AppCompatActivity implements ItemTouch
private ProgressBar progressBar;
private TextView endOfListText;
private LinearLayout no_food_favorite_layout;
@IntRange(from = 0, to = 3)
public int getConnectionType() {
int result = 0; // Returns connection type. 0: none; 1: mobile data; 2: wifi
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm != null) {
NetworkCapabilities capabilities = cm.getNetworkCapabilities(cm.getActiveNetwork());
if (capabilities != null) {
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
result = 2;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
result = 1;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
result = 3;
}
}
}
return result;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_favorite_food);
//Init component
back_image = findViewById(R.id.back_image);
nestedScrollView = findViewById(R.id.nestedScrollView);
progressBar = findViewById(R.id.progress_bar);
endOfListText = findViewById(R.id.end_of_list_text);
no_food_favorite_layout = findViewById(R.id.no_food_favorite_layout);
listFavoriteFoodLayout = findViewById(R.id.list_favorite_food_layout);
initComponent();
//Check internet connection
if(getConnectionType() == 0){
Common.showErrorInternetConnectionNotification(this);
}
//Set event when user scroll down
if (nestedScrollView != null) {
@@ -109,6 +134,15 @@ public class FavoriteFoodActivity extends AppCompatActivity implements ItemTouch
new ItemTouchHelper(simpleCallback).attachToRecyclerView(recyclerView_favorite_food);
}
private void initComponent() {
back_image = findViewById(R.id.back_image);
nestedScrollView = findViewById(R.id.nestedScrollView);
progressBar = findViewById(R.id.progress_bar);
endOfListText = findViewById(R.id.end_of_list_text);
no_food_favorite_layout = findViewById(R.id.no_food_favorite_layout);
listFavoriteFoodLayout = findViewById(R.id.list_favorite_food_layout);
}
private void dataLoadMore() {
if(!LAST_PAGE){
getListFavoriteFood(++CURRENT_PAGE);
@@ -153,7 +187,7 @@ public class FavoriteFoodActivity extends AppCompatActivity implements ItemTouch
@Override
public void onFailure(Call<Foods> call, Throwable t) {
Toast.makeText(FavoriteFoodActivity.this, "Đã có lỗi từ hệ thống! Vui lòng thử lại sau!", Toast.LENGTH_SHORT).show();
Log.e(TAG, t.toString());
}
});
@@ -3,10 +3,14 @@ package com.capstone.foodify.Activity;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
@@ -19,6 +23,7 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
@@ -66,6 +71,7 @@ import retrofit2.Callback;
import retrofit2.Response;
public class FoodDetailActivity extends AppCompatActivity {
private static final String TAG = "FoodDetailActivity";
ArrayList<Comment> listComment = new ArrayList<>();
private static final int CREATE_COMMENT = 1;
private static final int EDIT_COMMENT = 2;
@@ -96,6 +102,25 @@ public class FoodDetailActivity extends AppCompatActivity {
private ChipGroup list_category;
private SwipeRefreshLayout swipeRefreshLayout;
@IntRange(from = 0, to = 3)
public int getConnectionType() {
int result = 0; // Returns connection type. 0: none; 1: mobile data; 2: wifi
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm != null) {
NetworkCapabilities capabilities = cm.getNetworkCapabilities(cm.getActiveNetwork());
if (capabilities != null) {
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
result = 2;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
result = 1;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
result = 3;
}
}
}
return result;
}
private void initComponent() {
horizontalQuantitizer = findViewById(R.id.quantity_option);
imageSlider = findViewById(R.id.slider);
@@ -136,6 +161,11 @@ public class FoodDetailActivity extends AppCompatActivity {
initComponent();
//Check internet connection
if(getConnectionType() == 0){
Common.showErrorInternetConnectionNotification(this);
}
commentAdapter = new CommentAdapter(this);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, RecyclerView.VERTICAL, false);
@@ -308,7 +338,7 @@ public class FoodDetailActivity extends AppCompatActivity {
@Override
public void onFailure(Call<CustomResponse> call, Throwable t) {
Toast.makeText(FoodDetailActivity.this, "Đã xảy ra lỗi kết nối đến hệ thống!", Toast.LENGTH_SHORT).show();
Log.e(TAG, t.toString());
}
});
}
@@ -334,7 +364,7 @@ public class FoodDetailActivity extends AppCompatActivity {
@Override
public void onFailure(Call<Food> call, Throwable t) {
Toast.makeText(FoodDetailActivity.this, "Oops! Đã có lỗi, vui lòng thử lại sau!", Toast.LENGTH_SHORT).show();
Log.e(TAG, t.toString());
}
});
}
@@ -349,7 +379,7 @@ public class FoodDetailActivity extends AppCompatActivity {
@Override
public void onFailure(Call<Food> call, Throwable t) {
Toast.makeText(FoodDetailActivity.this, "Oops! Đã có lỗi, vui lòng thử lại sau!", Toast.LENGTH_SHORT).show();
Log.e(TAG, t.toString());
}
});
}
@@ -440,7 +470,7 @@ public class FoodDetailActivity extends AppCompatActivity {
@Override
public void onFailure(Call<Comment> call, Throwable t) {
showUI();
Common.showErrorServerNotification(FoodDetailActivity.this, "Lỗi kết nối!");
Log.e(TAG, t.toString());
}
});
}
@@ -487,7 +517,7 @@ public class FoodDetailActivity extends AppCompatActivity {
@Override
public void onFailure(Call<Comments> call, Throwable t) {
Toast.makeText(FoodDetailActivity.this, "Đã có lỗi từ hệ thống!", Toast.LENGTH_SHORT).show();
Log.e(TAG, t.toString());
}
});
@@ -586,7 +616,7 @@ public class FoodDetailActivity extends AppCompatActivity {
@Override
public void onFailure(Call<CustomResponse> call, Throwable t) {
Toast.makeText(FoodDetailActivity.this, "Oops, đã có lỗi xảy ra! Vui lòng thử lại sau!", Toast.LENGTH_SHORT).show();
Log.e(TAG, t.toString());
}
});
}
@@ -610,7 +640,7 @@ public class FoodDetailActivity extends AppCompatActivity {
@Override
public void onFailure(Call<Food> call, Throwable t) {
Common.showNotificationError(getBaseContext(), FoodDetailActivity.this);
Log.e(TAG, t.toString());
}
});
}
@@ -719,7 +749,7 @@ public class FoodDetailActivity extends AppCompatActivity {
@Override
public void onFailure(Call<CustomResponse> call, Throwable t) {
Toast.makeText(FoodDetailActivity.this, "Đã có lỗi kết nối đến hệ thống!", Toast.LENGTH_SHORT).show();
Log.e(TAG, t.toString());
}
});
}
@@ -750,7 +780,7 @@ public class FoodDetailActivity extends AppCompatActivity {
@Override
public void onFailure(Call<Comment> call, Throwable t) {
Toast.makeText(FoodDetailActivity.this, "Đã xuất hiện lỗi hệ thống!", Toast.LENGTH_SHORT).show();
Log.e(TAG, t.toString());
}
});
}
@@ -783,7 +813,7 @@ public class FoodDetailActivity extends AppCompatActivity {
@Override
public void onFailure(Call<CustomResponse> call, Throwable t) {
Toast.makeText(FoodDetailActivity.this, "Đã có lỗi kết nối tới hệ thống!", Toast.LENGTH_SHORT).show();
Log.e(TAG, t.toString());
}
});
}
@@ -1,10 +1,14 @@
package com.capstone.foodify.Activity;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
@@ -41,11 +45,30 @@ import retrofit2.Response;
public class ForgotPasswordActivity extends AppCompatActivity {
private FirebaseAuth mAuth;
TextInputLayout textInput_email;
EditText edt_email;
MaterialButton send_code_button;
ConstraintLayout progress_layout;
ImageView back_image;
private TextInputLayout textInput_email;
private EditText edt_email;
private MaterialButton send_code_button;
private ConstraintLayout progress_layout;
private ImageView back_image;
@IntRange(from = 0, to = 3)
public int getConnectionType() {
int result = 0; // Returns connection type. 0: none; 1: mobile data; 2: wifi
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm != null) {
NetworkCapabilities capabilities = cm.getNetworkCapabilities(cm.getActiveNetwork());
if (capabilities != null) {
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
result = 2;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
result = 1;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
result = 3;
}
}
}
return result;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -53,6 +76,11 @@ public class ForgotPasswordActivity extends AppCompatActivity {
initComponent();
//Check internet connection
if(getConnectionType() == 0){
Common.showErrorInternetConnectionNotification(this);
}
mAuth = FirebaseAuth.getInstance();
//Back button
@@ -78,13 +78,13 @@ import retrofit2.Response;
public class MainActivity extends AppCompatActivity {
FirebaseAppDistribution firebaseAppDistribution = FirebaseAppDistribution.getInstance();
ViewPager2 viewPager2;
ViewPagerAdapter viewPagerAdapter;
BottomNavigationView bottomNavigationView;
public static boolean slider, shop, recommendFood, recentFood, loadUser;
private final FirebaseAppDistribution firebaseAppDistribution = FirebaseAppDistribution.getInstance();
private ViewPager2 viewPager2;
private BottomNavigationView bottomNavigationView;
private FirebaseAuth mAuth;
private FirebaseUser user;
private ConstraintLayout progressLayout;
private static ConstraintLayout progressLayout;
//Location
private static final int REQUEST_CHECK_SETTINGS = 100;
@@ -112,6 +112,7 @@ public class MainActivity extends AppCompatActivity {
user = mAuth.getCurrentUser();
if (user != null && Common.CURRENT_USER == null) {
progressLayout.setVisibility(View.VISIBLE);
user.getIdToken(true)
.addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
@@ -130,6 +131,9 @@ public class MainActivity extends AppCompatActivity {
HomeFragment.setNameUser();
getTokenFCM();
loadUser = true;
hideProgressbar();
}
}
@@ -142,6 +146,16 @@ public class MainActivity extends AppCompatActivity {
}
}
});
} else {
//No account login
loadUser = true;
hideProgressbar();
}
}
public static void hideProgressbar(){
if(slider && shop && recentFood && recommendFood && loadUser){
progressLayout.setVisibility(View.GONE);
}
}
@@ -210,7 +224,6 @@ public class MainActivity extends AppCompatActivity {
stopLocationUpdates();
}
progressLayout.setVisibility(View.GONE);
}
}, 4000);
@@ -237,7 +250,6 @@ public class MainActivity extends AppCompatActivity {
if(response.code() != 200)
Toast.makeText(MainActivity.this, "Không thể cập nhật FCM Token. Mã lỗi: " + response.code(), Toast.LENGTH_SHORT).show();
progressLayout.setVisibility(View.GONE);
}
@Override
@@ -257,7 +269,7 @@ public class MainActivity extends AppCompatActivity {
}
private void bottomNavigation() {
viewPagerAdapter = new ViewPagerAdapter(this);
ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(this);
viewPager2.setAdapter(viewPagerAdapter);
viewPager2.setUserInputEnabled(false);
@@ -1,26 +1,50 @@
package com.capstone.foodify.Activity;
import androidx.annotation.IntRange;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager2.widget.ViewPager2;
import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import com.capstone.foodify.Common;
import com.capstone.foodify.Fragment.Order.ViewPagerAdapter;
import com.capstone.foodify.R;
import com.google.android.material.tabs.TabLayout;
public class OrderActivity extends AppCompatActivity {
TabLayout tabLayout;
ViewPager2 viewPager2;
ViewPagerAdapter viewPagerAdapter;
ImageView back_image;
private TabLayout tabLayout;
private ViewPager2 viewPager2;
private ViewPagerAdapter viewPagerAdapter;
private ImageView back_image;
public static Activity orderActivity;
@IntRange(from = 0, to = 3)
public int getConnectionType() {
int result = 0; // Returns connection type. 0: none; 1: mobile data; 2: wifi
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm != null) {
NetworkCapabilities capabilities = cm.getNetworkCapabilities(cm.getActiveNetwork());
if (capabilities != null) {
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
result = 2;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
result = 1;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
result = 3;
}
}
}
return result;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -31,6 +55,11 @@ public class OrderActivity extends AppCompatActivity {
viewPager2 = findViewById(R.id.view_pager);
back_image = findViewById(R.id.back_image);
//Check internet connection
if(getConnectionType() == 0){
Common.showErrorInternetConnectionNotification(this);
}
viewPagerAdapter = new ViewPagerAdapter(this);
viewPager2.setAdapter(viewPagerAdapter);
@@ -39,7 +68,7 @@ public class OrderActivity extends AppCompatActivity {
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager2.setCurrentItem(tab.getPosition());
viewPager2.setCurrentItem(tab.getPosition(), false);
}
@Override
@@ -6,9 +6,12 @@ import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.location.Geocoder;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
@@ -22,6 +25,7 @@ import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
@@ -71,6 +75,7 @@ import vn.zalopay.sdk.ZaloPaySDK;
import vn.zalopay.sdk.listeners.PayOrderListener;
public class OrderCheckOutActivity extends AppCompatActivity {
private static final String TAG = "OrderCheckOutActivity";
private static final String TAKE_FOOD_FROM_SHOP = "Đến shop lấy";
private static final String ZALO_PAYMENT_METHOD = "Zalo Pay";
private static final String CASH_PAYMENT = "CASH";
@@ -78,19 +83,19 @@ public class OrderCheckOutActivity extends AppCompatActivity {
private static Double LNG_SHOP = 0.0;
private static String finalAddress, tempAddress = null;
private static double finalLat, finalLng = 0;
ImageView back_image;
OrderDetailAdapter adapter;
RecyclerView recyclerView;
TextView txt_userName, txt_phone, edt_address_detect, errorTextDistrictWard, txt_total, txt_distance, txt_ship_cost;
TextInputLayout textInput_address;
EditText edt_address;
Spinner spn_list_address, spn_district, spn_ward;
ConstraintLayout manual_input_address_layout;
Button change_address_button, confirm_address_button, btn_ZaloPay, btn_Pay;
RadioButton list_address_input, auto_detect_location, manual_input_address, radio_button_selected, take_food_from_shop;
RadioGroup address_option;
ConstraintLayout progress_layout;
float total, totalProduct, shipCost;
private ImageView back_image;
private OrderDetailAdapter adapter;
private RecyclerView recyclerView;
private TextView txt_userName, txt_phone, edt_address_detect, errorTextDistrictWard, txt_total, txt_distance, txt_ship_cost;
private TextInputLayout textInput_address;
private EditText edt_address;
private Spinner spn_list_address, spn_district, spn_ward;
private ConstraintLayout manual_input_address_layout;
private Button change_address_button, confirm_address_button, btn_ZaloPay, btn_Pay;
private RadioButton list_address_input, auto_detect_location, manual_input_address, radio_button_selected, take_food_from_shop;
private RadioGroup address_option;
private ConstraintLayout progress_layout;
private float total, totalProduct, shipCost;
private static final ArrayList<String> wardList = new ArrayList<>();
private static final ArrayList<String> districtList = new ArrayList<>();
@@ -123,6 +128,25 @@ public class OrderCheckOutActivity extends AppCompatActivity {
btn_Pay = findViewById(R.id.btnPay);
}
@IntRange(from = 0, to = 3)
public int getConnectionType() {
int result = 0; // Returns connection type. 0: none; 1: mobile data; 2: wifi
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm != null) {
NetworkCapabilities capabilities = cm.getNetworkCapabilities(cm.getActiveNetwork());
if (capabilities != null) {
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
result = 2;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
result = 1;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
result = 3;
}
}
}
return result;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -132,7 +156,10 @@ public class OrderCheckOutActivity extends AppCompatActivity {
if(Common.CURRENT_USER == null)
startActivity(new Intent(this, SignInActivity.class));
//Check internet connection
if(getConnectionType() == 0){
Common.showErrorInternetConnectionNotification(this);
}
//Init Component
@@ -337,7 +364,7 @@ public class OrderCheckOutActivity extends AppCompatActivity {
@Override
public void onFailure(Call<GoogleMapResponse> call, Throwable t) {
Toast.makeText(OrderCheckOutActivity.this, "Lỗi kết nối!", Toast.LENGTH_SHORT).show();
Log.e(TAG, t.toString());
}
});
} else {
@@ -471,7 +498,7 @@ public class OrderCheckOutActivity extends AppCompatActivity {
@Override
public void onFailure(Call<Order> call, Throwable t) {
Toast.makeText(OrderCheckOutActivity.this, "Đã xảy ra lỗi kết nối hệ thống!", Toast.LENGTH_SHORT).show();
Log.e(TAG, t.toString());
}
});
}
@@ -501,7 +528,7 @@ public class OrderCheckOutActivity extends AppCompatActivity {
//Calculate ship cost
if(distance <= 3){
shipCost = 15000;
} else if(distance > 3 && distance <= 10){
} else if(distance <= 10){
shipCost = 5000 * (float) distance;
} else {
shipCost = 3000 * (float) distance;
@@ -518,7 +545,7 @@ public class OrderCheckOutActivity extends AppCompatActivity {
@Override
public void onFailure(Call<GoogleMapResponse> call, Throwable t) {
Toast.makeText(OrderCheckOutActivity.this, "Error: " + t, Toast.LENGTH_SHORT).show();
Log.e(TAG, t.toString());
}
});
} else {
@@ -543,7 +570,7 @@ public class OrderCheckOutActivity extends AppCompatActivity {
@Override
public void onFailure(Call<Shop> call, Throwable t) {
Toast.makeText(OrderCheckOutActivity.this, "Đã có lỗi kết nối đến hệ thống!", Toast.LENGTH_SHORT).show();
Log.e(TAG, t.toString());
}
});
@@ -563,10 +590,9 @@ public class OrderCheckOutActivity extends AppCompatActivity {
* Math.sin(dLon / 2);
double c = 2 * Math.asin(Math.sqrt(a));
double valueResult = Radius * c;
double km = valueResult / 1;
DecimalFormat newFormat = new DecimalFormat("####");
return Integer.valueOf(newFormat.format(km));
return Integer.valueOf(newFormat.format(valueResult));
}
private boolean validForm(){
@@ -759,7 +785,7 @@ public class OrderCheckOutActivity extends AppCompatActivity {
@Override
public void onFailure(Call<List<DistrictWardResponse>> call, Throwable t) {
Toast.makeText(OrderCheckOutActivity.this, "Đã xảy ra lỗi hệ thống. Vui lòng thử lại sau!", Toast.LENGTH_SHORT).show();
Log.e(TAG, t.toString());
}
});
}
@@ -797,7 +823,7 @@ public class OrderCheckOutActivity extends AppCompatActivity {
@Override
public void onFailure(Call<List<DistrictWardResponse>> call, Throwable t) {
Toast.makeText(OrderCheckOutActivity.this, "Đã xảy ra lỗi hệ thống. Vui lòng thử lại sau!", Toast.LENGTH_SHORT).show();
Log.e(TAG, t.toString());
}
});
} else {
@@ -1,12 +1,17 @@
package com.capstone.foodify.Activity;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
@@ -39,17 +44,36 @@ import retrofit2.Callback;
import retrofit2.Response;
public class OrderDetailActivity extends AppCompatActivity {
private static final String TAG = "OrderDetailActivity";
private static final String AWAITING = "AWAITING";
private static final String SHIPPING = "SHIPPING";
private TextView order_tracking_number, user_name, phone, address, orderTime, total, status;
private ImageView back_image;
private List<Basket> listOrderDetails = new ArrayList<>();
OrderDetailAdapter adapter;
RecyclerView recyclerView;
private OrderDetailAdapter adapter;
private RecyclerView recyclerView;
private Order order;
private Button btn_cancel_order, btn_tracking_location_shipper;
private View line_cancel_order, line_tracking_order;
@IntRange(from = 0, to = 3)
public int getConnectionType() {
int result = 0; // Returns connection type. 0: none; 1: mobile data; 2: wifi
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm != null) {
NetworkCapabilities capabilities = cm.getNetworkCapabilities(cm.getActiveNetwork());
if (capabilities != null) {
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
result = 2;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
result = 1;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
result = 3;
}
}
}
return result;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -58,6 +82,11 @@ public class OrderDetailActivity extends AppCompatActivity {
//Init Component
initComponent();
//Check internet connection
if(getConnectionType() == 0){
Common.showErrorInternetConnectionNotification(this);
}
//Get data from previous fragment
if(getIntent() != null)
order = (Order) getIntent().getSerializableExtra("order");
@@ -179,7 +208,7 @@ public class OrderDetailActivity extends AppCompatActivity {
@Override
public void onFailure(Call<CustomResponse> call, Throwable t) {
Toast.makeText(OrderDetailActivity.this, "Đã có lỗi kết nối đến hệ thống! Vui lòng thử lại sau!", Toast.LENGTH_SHORT).show();
Log.e(TAG, t.toString());
}
});
}
@@ -1,11 +1,17 @@
package com.capstone.foodify.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
@@ -13,6 +19,7 @@ import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.capstone.foodify.API.FoodApi;
import com.capstone.foodify.Adapter.FoodShopAdapter;
@@ -32,7 +39,7 @@ import retrofit2.Callback;
import retrofit2.Response;
public class ShopDetailActivity extends AppCompatActivity {
private static final String TAG = "ShopDetailActivity";
private static int CURRENT_PAGE;
private static int PAGE_SIZE = 8;
private static String SORT_BY = "name";
@@ -40,14 +47,35 @@ public class ShopDetailActivity extends AppCompatActivity {
private static boolean LAST_PAGE = false;
private int shopId;
private List<Food> listFood = new ArrayList<>();
TextView content_description_text_view, student_shop_text_view, end_of_list_text_view, txt_shop_name;
ImageView imageShop, back_image;
RecyclerView recycler_view_food_shop;
FoodShopAdapter adapter;
private TextView content_description_text_view, student_shop_text_view, end_of_list_text_view, txt_shop_name;
private ImageView imageShop, back_image;
private RecyclerView recycler_view_food_shop;
private FoodShopAdapter adapter;
private LinearLayout empty_layout;
private NestedScrollView nestedScrollView;
private ProgressBar progressBar;
private Shop shop;
private ConstraintLayout progressLayout;
private SwipeRefreshLayout swipeRefreshLayout;
@IntRange(from = 0, to = 3)
public int getConnectionType() {
int result = 0; // Returns connection type. 0: none; 1: mobile data; 2: wifi
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm != null) {
NetworkCapabilities capabilities = cm.getNetworkCapabilities(cm.getActiveNetwork());
if (capabilities != null) {
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
result = 2;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
result = 1;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
result = 3;
}
}
}
return result;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -55,17 +83,12 @@ public class ShopDetailActivity extends AppCompatActivity {
setContentView(R.layout.activity_shop_detail);
//Init Component
imageShop = findViewById(R.id.image_shop);
recycler_view_food_shop = findViewById(R.id.recycler_view_food_shop);
back_image = findViewById(R.id.back_image);
adapter = new FoodShopAdapter(this);
content_description_text_view = findViewById(R.id.content_description_text_view);
student_shop_text_view = findViewById(R.id.student_shop_text_view);
nestedScrollView = findViewById(R.id.food_detail);
progressBar = findViewById(R.id.progress_bar);
end_of_list_text_view = findViewById(R.id.end_of_list_text);
progressLayout = findViewById(R.id.progress_layout);
txt_shop_name = findViewById(R.id.txt_shop_name);
initComponent();
//Check internet connection
if(getConnectionType() == 0){
Common.showErrorInternetConnectionNotification(this);
}
//Get data
if (getIntent() != null)
@@ -101,6 +124,42 @@ public class ShopDetailActivity extends AppCompatActivity {
});
}
swipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.primaryColor, null));
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
CURRENT_PAGE = 0;
getDetailShop(shopId);
nestedScrollView.setVisibility(View.GONE);
progressLayout.setVisibility(View.VISIBLE);
recycler_view_food_shop.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.VISIBLE);
end_of_list_text_view.setVisibility(View.GONE);
empty_layout.setVisibility(View.GONE);
swipeRefreshLayout.setRefreshing(false);
}
});
}
private void initComponent() {
imageShop = findViewById(R.id.image_shop);
recycler_view_food_shop = findViewById(R.id.recycler_view_food_shop);
back_image = findViewById(R.id.back_image);
adapter = new FoodShopAdapter(this);
content_description_text_view = findViewById(R.id.content_description_text_view);
student_shop_text_view = findViewById(R.id.student_shop_text_view);
nestedScrollView = findViewById(R.id.food_detail);
progressBar = findViewById(R.id.progress_bar);
end_of_list_text_view = findViewById(R.id.end_of_list_text);
progressLayout = findViewById(R.id.progress_layout);
txt_shop_name = findViewById(R.id.txt_shop_name);
empty_layout = findViewById(R.id.empty_layout);
swipeRefreshLayout = findViewById(R.id.swipe_refresh);
}
private void getListFood(int shopId){
@@ -122,21 +181,33 @@ public class ShopDetailActivity extends AppCompatActivity {
recycler_view_food_shop.setAdapter(adapter);
initData(shop);
progressLayout.setVisibility(View.GONE);
if(listFood.size() == 0){
progressBar.setVisibility(View.GONE);
end_of_list_text_view.setVisibility(View.GONE);
empty_layout.setVisibility(View.VISIBLE);
return;
}
if(LAST_PAGE){
progressBar.setVisibility(View.GONE);
end_of_list_text_view.setVisibility(View.VISIBLE);
}
}
@Override
public void onFailure(Call<Foods> call, Throwable t) {
//Check internet connection
Common.showNotificationError(getBaseContext(), ShopDetailActivity.this);
Log.e(TAG, t.toString());
progressLayout.setVisibility(View.GONE);
}
});
}
private void getDetailShop(int shopId) {
FoodApi.apiService.detailShop(shopId).enqueue(new Callback<Shop>() {
FoodApi.apiService.getShopById(shopId).enqueue(new Callback<Shop>() {
@Override
public void onResponse(Call<Shop> call, Response<Shop> response) {
Shop tempShop = response.body();
@@ -150,7 +221,7 @@ public class ShopDetailActivity extends AppCompatActivity {
@Override
public void onFailure(Call<Shop> call, Throwable t) {
Common.showNotificationError(getBaseContext(), ShopDetailActivity.this);
Log.e(TAG, t.toString());
}
});
}
@@ -1,25 +1,28 @@
package com.capstone.foodify.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.capstone.foodify.API.FoodApiToken;
import com.capstone.foodify.Common;
import com.capstone.foodify.Fragment.HomeFragment;
import com.capstone.foodify.Model.User;
import com.capstone.foodify.R;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.textfield.TextInputEditText;
@@ -40,19 +43,43 @@ import retrofit2.Callback;
import retrofit2.Response;
public class SignInActivity extends AppCompatActivity {
private static final String TAG = "SignInActivity";
private FirebaseAuth mAuth;
TextView signUp_textView, forgotPassword_textView;
TextInputLayout textInput_email, textInput_password;
TextInputEditText edt_email, edt_password;
MaterialButton signInButton;
ImageView back_image;
ConstraintLayout progressLayout;
String email, password = null;
private TextView signUp_textView, forgotPassword_textView;
private TextInputLayout textInput_email, textInput_password;
private TextInputEditText edt_email, edt_password;
private MaterialButton signInButton;
private ImageView back_image;
private ConstraintLayout progressLayout;
private String email, password = null;
@IntRange(from = 0, to = 3)
public int getConnectionType() {
int result = 0; // Returns connection type. 0: none; 1: mobile data; 2: wifi
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm != null) {
NetworkCapabilities capabilities = cm.getNetworkCapabilities(cm.getActiveNetwork());
if (capabilities != null) {
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
result = 2;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
result = 1;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
result = 3;
}
}
}
return result;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Check internet connection
if(getConnectionType() == 0){
Common.showErrorInternetConnectionNotification(this);
}
//Init firebase app
FirebaseApp.initializeApp(SignInActivity.this);
setContentView(R.layout.activity_sign_in);
@@ -247,8 +274,7 @@ public class SignInActivity extends AppCompatActivity {
@Override
public void onFailure(Call<User> call, Throwable t) {
System.out.println("ERROR: " + t);
Common.showErrorServerNotification(SignInActivity.this, "Không thể đăng nhập tài khoản! Vui lòng thử lại sau!");
Log.e(TAG, t.toString());
}
});
} else {
@@ -1,5 +1,6 @@
package com.capstone.foodify.Activity;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
@@ -8,9 +9,12 @@ import android.app.DatePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
@@ -58,6 +62,7 @@ import retrofit2.Callback;
import retrofit2.Response;
public class SignUpActivity extends AppCompatActivity {
private static final String TAG = "SignUpActivity";
TextInputLayout textInput_password, textInput_phone, textInput_email, textInput_id_card,
textInput_address, textInput_confirmPassword, textInput_fullName, textInput_birthDay;
final Calendar myCalendar= Calendar.getInstance();
@@ -106,6 +111,24 @@ public class SignUpActivity extends AppCompatActivity {
}
@IntRange(from = 0, to = 3)
public int getConnectionType() {
int result = 0; // Returns connection type. 0: none; 1: mobile data; 2: wifi
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm != null) {
NetworkCapabilities capabilities = cm.getNetworkCapabilities(cm.getActiveNetwork());
if (capabilities != null) {
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
result = 2;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
result = 1;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
result = 3;
}
}
}
return result;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -113,9 +136,15 @@ public class SignUpActivity extends AppCompatActivity {
initComponent();
//Check internet connection
if(getConnectionType() == 0){
Common.showErrorInternetConnectionNotification(this);
}
setFontUI();
chooseDateOfBirth();
//Get list district
if(districtList.size() == 0){
getListDistrict();
@@ -248,7 +277,7 @@ public class SignUpActivity extends AppCompatActivity {
@Override
public void onFailure(Call<CustomResponse> call, Throwable t) {
Log.e(TAG, t.toString());
}
});
}
@@ -276,7 +305,7 @@ public class SignUpActivity extends AppCompatActivity {
@Override
public void onFailure(Call<CustomResponse> call, Throwable t) {
Log.e(TAG, t.toString());
}
});
}
@@ -485,7 +514,7 @@ public class SignUpActivity extends AppCompatActivity {
@Override
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();
Log.e(TAG, t.toString());
}
});
}
@@ -523,7 +552,7 @@ public class SignUpActivity extends AppCompatActivity {
@Override
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();
Log.e(TAG, t.toString());
}
});
} else {
@@ -7,12 +7,16 @@ import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity;
@@ -53,7 +57,7 @@ import retrofit2.Callback;
import retrofit2.Response;
public class TrackingOrderActivity extends FragmentActivity implements OnMapReadyCallback, ValueEventListener {
private static final String TAG = "TrackingOrderActivity";
private GoogleMap mMap;
private ActivityTrackingOrderBinding binding;
private String trackingOrderNumber, latOrder, lngOrder = null;
@@ -62,12 +66,35 @@ public class TrackingOrderActivity extends FragmentActivity implements OnMapRead
private DatabaseReference orderDatabase;
private Marker shippingMarker;
private Polyline polyline;
private static final String TAG = "TrackingOrderActivity";
@IntRange(from = 0, to = 3)
public int getConnectionType() {
int result = 0; // Returns connection type. 0: none; 1: mobile data; 2: wifi
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm != null) {
NetworkCapabilities capabilities = cm.getNetworkCapabilities(cm.getActiveNetwork());
if (capabilities != null) {
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
result = 2;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
result = 1;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
result = 3;
}
}
}
return result;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Check internet connection
if(getConnectionType() == 0){
Common.showErrorInternetConnectionNotification(this);
}
//Get tracking number order
if(getIntent() != null){
trackingOrderNumber = getIntent().getStringExtra("trackingOrderNumber");
@@ -175,7 +202,7 @@ public class TrackingOrderActivity extends FragmentActivity implements OnMapRead
@Override
public void onFailure(Call<String> call, Throwable t) {
Toast.makeText(TrackingOrderActivity.this, "Có lỗi kết nối!", Toast.LENGTH_SHORT).show();
Log.e(TAG, t.toString());
}
});
}
@@ -2,13 +2,17 @@ package com.capstone.foodify.Activity;
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
@@ -20,6 +24,7 @@ import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
@@ -52,17 +57,37 @@ import retrofit2.Callback;
import retrofit2.Response;
public class VerifyAccountActivity extends AppCompatActivity {
private static final String TAG = "VerifyAccountActivity";
private static final String PHONE_CODE = "+84";
ActivityResultLauncher<Intent> activityResultLauncher;
SmsBroadcastReceiver smsBroadcastReceiver;
private ActivityResultLauncher<Intent> activityResultLauncher;
private SmsBroadcastReceiver smsBroadcastReceiver;
private EditText inputCode1, inputCode2, inputCode3, inputCode4, inputCode5, inputCode6;
ImageView close_image;
MaterialButton confirm_code;
String verificationId, phone, password = null;
ConstraintLayout progressLayout;
TextView resendCodeText, resendCodeTextButton, countDown, errorText;
User user;
FirebaseAuth mAuth;
private ImageView close_image;
private MaterialButton confirm_code;
private String verificationId, phone, password = null;
private ConstraintLayout progressLayout;
private TextView resendCodeText, resendCodeTextButton, countDown, errorText;
private User user;
private FirebaseAuth mAuth;
@IntRange(from = 0, to = 3)
public int getConnectionType() {
int result = 0; // Returns connection type. 0: none; 1: mobile data; 2: wifi
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm != null) {
NetworkCapabilities capabilities = cm.getNetworkCapabilities(cm.getActiveNetwork());
if (capabilities != null) {
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
result = 2;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
result = 1;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
result = 3;
}
}
}
return result;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -71,6 +96,11 @@ public class VerifyAccountActivity extends AppCompatActivity {
initComponent();
//Check internet connection
if(getConnectionType() == 0){
Common.showErrorInternetConnectionNotification(this);
}
//Auto fill OTP Code
requestSMSPermission();
startSmartUserContent();
@@ -263,7 +293,7 @@ public class VerifyAccountActivity extends AppCompatActivity {
public void onFailure(Call<User> call, Throwable t) {
progressLayout.setVisibility(View.GONE);
showErrorText(t.toString());
Common.showErrorServerNotification(VerifyAccountActivity.this, "Không thể tạo tài khoản! Vui lòng thử lại sau!");
Log.e(TAG, t.toString());
}
});
} else {
@@ -429,7 +459,6 @@ public class VerifyAccountActivity extends AppCompatActivity {
@Override
public void onFailure() {
}
};
@@ -41,7 +41,7 @@ import retrofit2.Response;
public class Common {
//https://foodify-backend-production.up.railway.app/
public static final String BASE_URL = "https://foodify-backend-production.up.railway.app/api/";
public static final String BASE_URL = "http://192.168.1.183:8080/api/";
public static String FCM_TOKEN = null;
public static Location CURRENT_LOCATION = null;
public static final String MAP_API = "AIzaSyAY14Ic32UP26Hg6GILznOfbBihiY5BUxw";
@@ -94,31 +94,15 @@ public class Common {
public static int getConnectionType(Context context) {
int result = 0; // Returns connection type. 0: none; 1: mobile data; 2: wifi
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (cm != null) {
NetworkCapabilities capabilities = cm.getNetworkCapabilities(cm.getActiveNetwork());
if (capabilities != null) {
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
result = 2;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
result = 1;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
result = 3;
}
}
}
} else {
if (cm != null) {
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
if (activeNetwork != null) {
// connected to the internet
if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) {
result = 2;
} else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
result = 1;
} else if (activeNetwork.getType() == ConnectivityManager.TYPE_VPN) {
result = 3;
}
if (cm != null) {
NetworkCapabilities capabilities = cm.getNetworkCapabilities(cm.getActiveNetwork());
if (capabilities != null) {
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
result = 2;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
result = 1;
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
result = 3;
}
}
}
@@ -61,6 +61,11 @@ public class BasketFragment extends Fragment implements ItemTouchHelperListener
btnCheckOut = view.findViewById(R.id.btnCheckOut);
listBasketFoodLayout = view.findViewById(R.id.list_basket_food_layout);
//Check status internet
if(Common.getConnectionType(requireContext()) == 0){
Common.showErrorInternetConnectionNotification(getActivity());
}
//Check list basket is null or not!
checkListBasket();
@@ -1,17 +1,19 @@
package com.capstone.foodify.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.capstone.foodify.API.FoodApi;
import com.capstone.foodify.Activity.MainActivity;
import com.capstone.foodify.Adapter.MenuAdapter;
import com.capstone.foodify.Adapter.ShopAdapter;
import com.capstone.foodify.Common;
@@ -28,6 +30,7 @@ import com.denzcoskun.imageslider.models.SlideModel;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import retrofit2.Call;
import retrofit2.Callback;
@@ -35,6 +38,7 @@ import retrofit2.Response;
public class HomeFragment extends Fragment {
private static final String TAG = "HomeFragment";
public static List<Food> listFood = new ArrayList<>();
private static List<Food> recentFood = new ArrayList<>();
@@ -61,9 +65,16 @@ public class HomeFragment extends Fragment {
shopAdapter = new ShopAdapter(getContext());
welcomeText = view.findViewById(R.id.welcome_text);
//Check status internet
if(Common.getConnectionType(requireContext()) == 0){
Common.showErrorInternetConnectionNotification(getActivity());
}
if(listFood.isEmpty() || recentFood.isEmpty()){
//Get food
getListFood();
recentFood();
} else {
menuAdapter.setData(getListMenu());
rcvMenu.setAdapter(menuAdapter);
@@ -75,7 +86,8 @@ public class HomeFragment extends Fragment {
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false);
rcvMenu.setLayoutManager(linearLayoutManager);
showSlider();
//Get slider
getSlider();
//Get list shop
getListShop();
@@ -100,7 +112,7 @@ public class HomeFragment extends Fragment {
welcomeText.setText("Xin chào, khách!");
}
private void showSlider(){
private void getSlider(){
FoodApi.apiService.listSlider().enqueue(new Callback<List<Slider>>() {
@Override
@@ -114,10 +126,13 @@ public class HomeFragment extends Fragment {
imageSlider.setImageList(slideModels, ScaleTypes.FIT);
MainActivity.slider = true;
MainActivity.hideProgressbar();
}
@Override
public void onFailure(Call<List<Slider>> call, Throwable t) {
Log.e(TAG, t.toString());
}
});
}
@@ -140,17 +155,17 @@ public class HomeFragment extends Fragment {
//Check null data
if(foodResponse == null)
return;
listFood = foodResponse.getProducts();
recentFood();
menuAdapter.setData(getListMenu());
MainActivity.recommendFood = true;
MainActivity.hideProgressbar();
}
@Override
public void onFailure(Call<Foods> call, Throwable t) {
//Check internet connection
if(getActivity() != null)
Common.showNotificationError(getContext(), getActivity());
Log.e(TAG, t.toString());
}
});
}
@@ -169,10 +184,14 @@ public class HomeFragment extends Fragment {
menuAdapter.setData(getListMenu());
rcvMenu.setAdapter(menuAdapter);
MainActivity.recentFood = true;
MainActivity.hideProgressbar();
}
@Override
public void onFailure(Call<Foods> call, Throwable t) {
Log.e(TAG, t.toString());
}
});
}
@@ -190,10 +209,14 @@ public class HomeFragment extends Fragment {
shopAdapter.setData(shopList);
recyclerView_restaurant.setAdapter(shopAdapter);
MainActivity.shop = true;
MainActivity.hideProgressbar();
}
@Override
public void onFailure(Call<Shops> call, Throwable t) {
Log.e(TAG, t.toString());
}
});
}
@@ -52,6 +52,11 @@ public class CancelOrderFragment extends Fragment {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_cancel_order, container, false);
//Check status internet
if(Common.getConnectionType(requireContext()) == 0){
Common.showErrorInternetConnectionNotification(getActivity());
}
//Init Component
initComponent(view);
@@ -28,6 +28,7 @@ import com.squareup.picasso.Picasso;
import io.paperdb.Paper;
public class ProfileFragment extends Fragment {
private static final String TAG = "ProfileFragment";
LinearLayout account_and_profile, manage_address, favorite_food, order_history, log_out;
PopupDialog popupDialog;
TextView user_name;
@@ -49,6 +50,11 @@ public class ProfileFragment extends Fragment {
popupDialog = PopupDialog.getInstance(getContext());
//Check status internet
if(Common.getConnectionType(requireContext()) == 0){
Common.showErrorInternetConnectionNotification(getActivity());
}
//Set image for user
if(Common.CURRENT_USER.getImageUrl().isEmpty()){
profile_avatar.setImageResource(R.drawable.profile_avatar);
@@ -1,6 +1,7 @@
package com.capstone.foodify.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -38,6 +39,7 @@ import retrofit2.http.GET;
public class SearchFragment extends Fragment {
private static final String TAG = "SearchFragment";
private static int CURRENT_PAGE = 0;
private static final int LIMIT = 8;
private static boolean LAST_PAGE;
@@ -73,6 +75,11 @@ public class SearchFragment extends Fragment {
end_of_list_text_view = view.findViewById(R.id.end_of_list_text);
searchNotFound = view.findViewById(R.id.search_not_found);
//Check status internet
if(Common.getConnectionType(requireContext()) == 0){
Common.showErrorInternetConnectionNotification(getActivity());
}
getListCategory();
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
@@ -161,8 +168,7 @@ public class SearchFragment extends Fragment {
@Override
public void onFailure(Call<Foods> call, Throwable t) {
//Check internet connection
Common.showNotificationError(getContext(), getActivity());
Log.e(TAG, t.toString());
}
});
}
@@ -262,8 +268,7 @@ public class SearchFragment extends Fragment {
@Override
public void onFailure(Call<Categories> call, Throwable t) {
//Check internet connection
Common.showNotificationError(getContext(), getActivity());
Log.e(TAG, t.toString());
}
});
}
@@ -283,7 +288,7 @@ public class SearchFragment extends Fragment {
@Override
public void onFailure(Call<Foods> call, Throwable t) {
Log.e(TAG, t.toString());
}
});
}
@@ -303,8 +308,7 @@ public class SearchFragment extends Fragment {
@Override
public void onFailure(Call<Foods> call, Throwable t) {
//Check internet connection
Common.showNotificationError(getContext(), getActivity());
Log.e(TAG, t.toString());
}
});
}
@@ -319,8 +323,7 @@ public class SearchFragment extends Fragment {
@Override
public void onFailure(Call<Foods> call, Throwable t) {
//Check internet connection
Common.showNotificationError(getContext(), getActivity());
Log.e(TAG, t.toString());
}
});
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

+170 -129
View File
@@ -7,160 +7,201 @@
tools:context=".Activity.ShopDetailActivity"
>
<androidx.core.widget.NestedScrollView
android:id="@+id/food_detail"
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_height="match_parent"
android:id="@+id/swipe_refresh"
>
<androidx.constraintlayout.widget.ConstraintLayout
<androidx.core.widget.NestedScrollView
android:id="@+id/food_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
>
<ImageView
android:id="@+id/image_shop"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<ImageView
android:id="@+id/back_image"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/back_button"
android:layout_marginStart="10dp"
android:layout_marginTop="25dp"
android:background="@drawable/circle_button"
android:translationZ="90dp"
android:padding="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="7dp"
android:layout_marginEnd="7dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/image_shop"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/student_shop_text_view"
android:text="Shop sinh viên"
android:fontFamily="@font/bebas"
android:textColor="@color/red"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/txt_shop_name"
app:layout_constraintEnd_toEndOf="parent"
android:visibility="gone"
/>
<TextView
android:id="@+id/txt_shop_name"
android:text="Shop name"
android:fontFamily="@font/bebas"
android:textColor="@color/primaryColor"
android:textSize="35sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<ImageView
android:id="@+id/image_shop"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<TextView
android:id="@+id/description_text_view"
android:text="Mô tả"
android:textSize="18sp"
android:fontFamily="@font/bebas"
android:textColor="@color/black"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/txt_shop_name"
<ImageView
android:id="@+id/back_image"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/back_button"
android:layout_marginStart="10dp"
android:layout_marginTop="25dp"
android:background="@drawable/circle_button"
android:translationZ="90dp"
android:padding="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<TextView
android:id="@+id/content_description_text_view"
android:textColor="@color/gray"
android:fontFamily="@font/opensans"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
app:layout_constraintTop_toBottomOf="@id/description_text_view"
app:layout_constraintStart_toStartOf="parent"
/>
<View
android:id="@+id/line"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#c0c0c0"
android:layout_marginTop="5dp"
app:layout_constraintTop_toBottomOf="@id/content_description_text_view"
/>
<TextView
android:id="@+id/textView"
android:text="Danh sách các món ăn"
android:fontFamily="@font/bebas"
android:textColor="@color/black"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/content_description_text_view"
app:layout_constraintStart_toStartOf="parent"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_food_shop"
tools:listitem="@layout/item_food_shop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/textView"
app:layout_constraintStart_toStartOf="parent"
/>
<ProgressBar
android:id="@+id/progress_bar"
android:indeterminateTint="@color/primaryColor"
app:layout_constraintTop_toBottomOf="@id/recycler_view_food_shop"
android:layout_marginStart="7dp"
android:layout_marginEnd="7dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
app:layout_constraintTop_toBottomOf="@id/image_shop"
android:id="@+id/information_shop"
>
<TextView
android:id="@+id/end_of_list_text"
android:text="Đã hết"
android:fontFamily="@font/opensans"
android:textColor="@color/grayLight"
<TextView
android:id="@+id/student_shop_text_view"
android:text="Shop sinh viên"
android:fontFamily="@font/bebas"
android:textColor="@color/red"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/txt_shop_name"
app:layout_constraintEnd_toEndOf="parent"
android:visibility="gone"
/>
<TextView
android:id="@+id/txt_shop_name"
android:text="Shop name"
android:fontFamily="@font/bebas"
android:textColor="@color/primaryColor"
android:textSize="35sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<TextView
android:id="@+id/description_text_view"
android:text="Mô tả"
android:textSize="18sp"
android:fontFamily="@font/bebas"
android:textColor="@color/black"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/txt_shop_name"
app:layout_constraintStart_toStartOf="parent"
/>
<TextView
android:id="@+id/content_description_text_view"
android:textColor="@color/gray"
android:fontFamily="@font/opensans"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
app:layout_constraintTop_toBottomOf="@id/description_text_view"
app:layout_constraintStart_toStartOf="parent"
/>
<View
android:id="@+id/line"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#c0c0c0"
android:layout_marginTop="5dp"
app:layout_constraintTop_toBottomOf="@id/content_description_text_view"
/>
<TextView
android:id="@+id/textView"
android:text="Danh sách các món ăn"
android:fontFamily="@font/bebas"
android:textColor="@color/black"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/content_description_text_view"
app:layout_constraintStart_toStartOf="parent"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_food_shop"
tools:listitem="@layout/item_food_shop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/textView"
app:layout_constraintStart_toStartOf="parent"
/>
<ProgressBar
android:id="@+id/progress_bar"
android:indeterminateTint="@color/primaryColor"
app:layout_constraintTop_toBottomOf="@id/recycler_view_food_shop"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/end_of_list_text"
android:text="Đã hết"
android:fontFamily="@font/opensans"
android:textColor="@color/grayLight"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@id/progress_bar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
app:layout_constraintTop_toBottomOf="@id/information_shop"
android:gravity="center"
android:orientation="vertical"
android:id="@+id/empty_layout"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@id/progress_bar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
>
<ImageView
android:src="@drawable/no_food"
android:layout_width="110dp"
android:layout_height="110dp"
/>
<TextView
android:gravity="center"
android:fontFamily="@font/opensans"
android:text="Oops! Hiện cửa hàng này chưa có món ăn nào! Vui lòng quay lại sau!"
android:layout_marginTop="10dp"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
+1 -1
View File
@@ -117,7 +117,7 @@
<TextView
android:id="@+id/total_text_view"
android:text="0 đ"
android:text="12500"
android:fontFamily="@font/opensans"
android:textSize="24sp"
android:textColor="@android:color/white"
+7 -5
View File
@@ -10,7 +10,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/red"
android:layout_margin="10dp"
android:layout_margin="7dp"
>
<TextView
@@ -45,7 +45,7 @@
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="@color/white"
android:layout_margin="5dp"
android:layout_margin="7dp"
>
<ImageView
@@ -143,19 +143,20 @@
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:layout_weight="0.4"
>
<TextView
android:id="@+id/txt_increment"
android:text="+"
android:textSize="19sp"
android:padding="5dp"
android:textColor="@color/primaryColor"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:layout_weight="0.2"
android:layout_weight="0.3"
/>
<TextView
@@ -174,12 +175,13 @@
android:id="@+id/txt_decrement"
android:text="-"
android:textSize="25sp"
android:padding="5dp"
android:textColor="@color/primaryColor"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center_vertical"
android:layout_weight="0.2"
android:layout_weight="0.3"
/>
@@ -1,17 +0,0 @@
package com.capstone.foodify;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
@@ -0,0 +1,324 @@
package com.capstone.foodify;
import org.junit.Test;
import static org.junit.Assert.*;
import com.capstone.foodify.API.FoodApi;
import com.capstone.foodify.Model.Address;
import com.capstone.foodify.Model.Comment;
import com.capstone.foodify.Model.DistrictWardResponse;
import com.capstone.foodify.Model.Food;
import com.capstone.foodify.Model.Response.Categories;
import com.capstone.foodify.Model.Response.Comments;
import com.capstone.foodify.Model.Response.CustomResponse;
import com.capstone.foodify.Model.Response.Foods;
import com.capstone.foodify.Model.Response.Shops;
import com.capstone.foodify.Model.Shop;
import com.capstone.foodify.Model.Slider;
import com.capstone.foodify.Model.User;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import retrofit2.Response;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class UnitTest {
@Test
public void testGetDistrict() {
try {
Response<List<DistrictWardResponse>> response = FoodApi.apiService.districtResponse().execute();
List<DistrictWardResponse> listDistrict = response.body();
assertTrue(response.code() == 200 && Objects.requireNonNull(listDistrict).size() > 0);
} catch (IOException e) {
fail();
}
}
@Test
public void testGetWard() {
try {
Response<List<DistrictWardResponse>> response = FoodApi.apiService.wardResponse(1).execute();
List<DistrictWardResponse> listWard = response.body();
assertTrue(response.code() == 200 && Objects.requireNonNull(listWard).size() > 0);
} catch (IOException e) {
fail();
}
}
@Test
public void testGetFoodRecommend() {
try {
Response<Foods> response = FoodApi.apiService.recommendFood().execute();
Foods listFood = response.body();
assertTrue(response.code() == 200 && Objects.requireNonNull(listFood).getProducts().size() > 0);
} catch (IOException e) {
fail();
}
}
@Test
public void testGetFoodRecent() {
try {
Response<Foods> response = FoodApi.apiService.recentFood().execute();
Foods listFood = response.body();
assertTrue(response.code() == 200 && Objects.requireNonNull(listFood).getProducts().size() > 0);
} catch (IOException e) {
fail();
}
}
@Test
public void testGetAllShop() {
try {
Response<Shops> response = FoodApi.apiService.allShops().execute();
Shops listFood = response.body();
assertTrue(response.code() == 200 && Objects.requireNonNull(listFood).getShops().size() > 0);
} catch (IOException e) {
fail();
}
}
@Test
public void testSearchFoodByName() {
try {
Response<Foods> response = FoodApi.apiService.searchFoodByName("a", 0, 8, "id", "asc").execute();
Foods listFood = response.body();
assertTrue(response.code() == 200 && Objects.requireNonNull(listFood).getProducts().size() > 0);
} catch (IOException e) {
fail();
}
}
@Test
public void testGetListFood() {
try {
Response<Foods> response = FoodApi.apiService.listFood(0, 8, "id", "asc").execute();
Foods listFood = response.body();
assertTrue(response.code() == 200 && Objects.requireNonNull(listFood).getProducts().size() > 0);
} catch (IOException e) {
fail();
}
}
@Test
public void testGetListCategory() {
try {
Response<Categories> response = FoodApi.apiService.listCategory().execute();
Categories listFood = response.body();
assertTrue(response.code() == 200 && Objects.requireNonNull(listFood).getCategories().size() > 0);
} catch (IOException e) {
fail();
}
}
@Test
public void testGetListFoodByCategory() {
List<Integer> statusCategoryChecked = new ArrayList<>();
statusCategoryChecked.add(1);
statusCategoryChecked.add(2);
try {
Response<Foods> response = FoodApi.apiService.listFoodByCategory(statusCategoryChecked, 0, 8, "id", "asc").execute();
Foods listFood = response.body();
assertTrue(response.code() == 200 && Objects.requireNonNull(listFood).getProducts().size() > 0);
} catch (IOException e) {
fail();
}
}
@Test
public void testGetListFoodByCategoryAndName() {
List<Integer> statusCategoryChecked = new ArrayList<>();
statusCategoryChecked.add(1);
statusCategoryChecked.add(2);
try {
Response<Foods> response = FoodApi.apiService.listFoodByCategoriesAndName(statusCategoryChecked, "a",0, 8, "id", "asc").execute();
Foods listFood = response.body();
assertTrue(response.code() == 200 && Objects.requireNonNull(listFood).getProducts().size() > 0);
} catch (IOException e) {
fail();
}
}
@Test
public void getDetailFood() {
try {
Response<Food> response = FoodApi.apiService.detailFood("10").execute();
Food food = null;
food = response.body();
assertTrue(response.code() == 200 && food != null);
} catch (IOException e) {
fail();
}
}
@Test
public void getDetailShop() {
try {
Response<Shop> response = FoodApi.apiService.getShopById(1).execute();
Shop shop = null;
shop = response.body();
assertTrue(response.code() == 200 && shop != null);
} catch (IOException e) {
fail();
}
}
@Test
public void testGetListFoodByShopId() {
try {
Response<Foods> response = FoodApi.apiService.listFoodByShopId(1, 0, 8, "name", "asc").execute();
Foods listFood = response.body();
assertTrue(response.code() == 200 && Objects.requireNonNull(listFood).getProducts().size() > 0);
} catch (IOException e) {
fail();
}
}
@Test
public void testGetListSlider() {
try {
Response<List<Slider>> response = FoodApi.apiService.listSlider().execute();
List<Slider> listSlider = response.body();
assertTrue(response.code() == 200 && Objects.requireNonNull(listSlider).size() > 0);
} catch (IOException e) {
fail();
}
}
@Test
public void checkPhoneExist() {
User user = new User(new Address(), "", "", "", "", "0987654321");
try {
Response<CustomResponse> response = FoodApi.apiService.checkEmailOrPhoneExist(user).execute();
CustomResponse customResponse = response.body();
assertTrue(response.code() == 200 && Objects.requireNonNull(customResponse).isTrue());
} catch (IOException e) {
fail();
}
}
@Test
public void getCommentByProductId() {
try {
Response<Comments> response = FoodApi.apiService.getCommentByProductId(13, 0, 8, "id", "asc").execute();
Comments listComment = response.body();
assertTrue(response.code() == 200 && Objects.requireNonNull(listComment).getComments().size() > 0);
} catch (IOException e) {
fail();
}
}
@Test
public void getUserComment() {
try {
Response<Comment> response = FoodApi.apiService.getUserComment(13, 17).execute();
Comment comment = response.body();
assertTrue(response.code() == 200 && comment != null);
} catch (IOException e) {
fail();
}
}
@Test
public void getShopById() {
try {
Response<CustomResponse> response = FoodApi.apiService.checkUserBuyProduct(13, 17).execute();
CustomResponse customResponse = response.body();
assertTrue(response.code() == 200 && Objects.requireNonNull(customResponse).isTrue());
} catch (IOException e) {
fail();
}
}
@Test
public void checkIdentifiedCode() {
try {
Response<CustomResponse> response = FoodApi.apiService.checkIdentifiedCode("0987654321").execute();
CustomResponse customResponse = response.body();
assertTrue(response.code() == 200 && Objects.requireNonNull(customResponse).isTrue());
} catch (IOException e) {
fail();
}
}
}