mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 20:00:50 +00:00
Refactor Code
This commit is contained in:
@@ -37,7 +37,9 @@
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".Activity.FoodDetailActivity"
|
||||
android:exported="false" />
|
||||
android:exported="false"
|
||||
android:noHistory="true"
|
||||
/>
|
||||
<activity
|
||||
android:name=".Activity.ResetPasswordActivity"
|
||||
android:exported="false"
|
||||
|
||||
@@ -266,7 +266,7 @@ public class FoodDetailActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Food> call, Throwable t) {
|
||||
Toast.makeText(FoodDetailActivity.this, "Lỗi Food" + t, Toast.LENGTH_SHORT).show();
|
||||
Common.showNotificationError(t, getBaseContext(), FoodDetailActivity.this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Build;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
@@ -63,13 +64,23 @@ public class Common {
|
||||
.setOnClickListener(new OnDialogClickListener() {
|
||||
@Override
|
||||
public void onClick(@NonNull AestheticDialog.Builder builder) {
|
||||
activity.finish();
|
||||
activity.finishAffinity();
|
||||
System.exit(0);
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void showNotificationError(Throwable t, Context context, Activity activity) {
|
||||
if(checkInternetConnection(context)){
|
||||
//Has internet connection
|
||||
Toast.makeText(context, "Error: " + t, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
//No internet, show notification
|
||||
showErrorInternetConnectionNotification(activity);
|
||||
}
|
||||
}
|
||||
|
||||
public static Basket getFoodExistInBasket(String foodId) {
|
||||
return Common.LIST_BASKET_FOOD.stream().filter(food -> foodId.equals(food.getId())).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
@@ -113,13 +113,7 @@ public class HomeFragment extends Fragment {
|
||||
@Override
|
||||
public void onFailure(Call<Foods> call, Throwable t) {
|
||||
//Check internet connection
|
||||
if(Common.checkInternetConnection(getContext())){
|
||||
//Has internet connection
|
||||
Toast.makeText(getContext(), "Error: " + t, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
//No internet, show notification
|
||||
Common.showErrorInternetConnectionNotification(getActivity());
|
||||
}
|
||||
Common.showNotificationError(t, getContext(), getActivity());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -143,13 +137,7 @@ public class HomeFragment extends Fragment {
|
||||
@Override
|
||||
public void onFailure(Call<Foods> call, Throwable t) {
|
||||
//Check internet connection
|
||||
if(Common.checkInternetConnection(getContext())){
|
||||
//Has internet connection
|
||||
Toast.makeText(getContext(), "Error: " + t, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
//No internet, show notification
|
||||
Common.showErrorInternetConnectionNotification(getActivity());
|
||||
}
|
||||
Common.showNotificationError(t,getContext(), getActivity());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -172,13 +160,7 @@ public class HomeFragment extends Fragment {
|
||||
@Override
|
||||
public void onFailure(Call<Shops> call, Throwable t) {
|
||||
//Check internet connection
|
||||
if(Common.checkInternetConnection(getContext())){
|
||||
//Has internet connection
|
||||
Toast.makeText(getContext(), "Error: " + t, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
//No internet, show notification
|
||||
Common.showErrorInternetConnectionNotification(getActivity());
|
||||
}
|
||||
Common.showNotificationError(t, getContext(), getActivity());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user