mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 13:38:41 +00:00
Fix progress bar on home fragment crash the app
This commit is contained in:
@@ -5,6 +5,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@@ -45,7 +46,7 @@ public class HomeFragment extends Fragment {
|
||||
private RecyclerView rcvMenu, recyclerView_restaurant;
|
||||
private MenuAdapter menuAdapter;
|
||||
private ShopAdapter shopAdapter;
|
||||
private PopupDialog popupDialog;
|
||||
private ConstraintLayout progressLayout;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -59,8 +60,7 @@ public class HomeFragment extends Fragment {
|
||||
menuAdapter = new MenuAdapter(getContext());
|
||||
recyclerView_restaurant = view.findViewById(R.id.recycler_view_restaurant);
|
||||
shopAdapter = new ShopAdapter(getContext());
|
||||
|
||||
popupDialog = PopupDialog.getInstance(getContext());
|
||||
progressLayout = view.findViewById(R.id.progress_layout);
|
||||
|
||||
|
||||
if(listFood.isEmpty() || recentFood.isEmpty()){
|
||||
@@ -91,10 +91,6 @@ public class HomeFragment extends Fragment {
|
||||
|
||||
private void showSlider(){
|
||||
|
||||
//Show progress bar
|
||||
popupDialog.setStyle(Styles.PROGRESS).setProgressDialogTint(getResources().getColor(R.color.primaryColor, null))
|
||||
.setCancelable(false).showDialog();
|
||||
|
||||
FoodApi.apiService.listSlider().enqueue(new Callback<List<Slider>>() {
|
||||
@Override
|
||||
public void onResponse(Call<List<Slider>> call, Response<List<Slider>> response) {
|
||||
@@ -107,13 +103,17 @@ public class HomeFragment extends Fragment {
|
||||
|
||||
imageSlider.setImageList(slideModels, ScaleTypes.FIT);
|
||||
|
||||
popupDialog.dismissDialog();
|
||||
//Dismiss progress bar
|
||||
progressLayout.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<List<Slider>> call, Throwable t) {
|
||||
popupDialog.dismissDialog();
|
||||
Common.showNotificationError(getContext(), getActivity());
|
||||
//Dismiss progress bar
|
||||
progressLayout.setVisibility(View.GONE);
|
||||
|
||||
if(getActivity() != null)
|
||||
Common.showNotificationError(getContext(), getActivity());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -144,7 +144,8 @@ public class HomeFragment extends Fragment {
|
||||
@Override
|
||||
public void onFailure(Call<Foods> call, Throwable t) {
|
||||
//Check internet connection
|
||||
Common.showNotificationError(getContext(), getActivity());
|
||||
if(getActivity() != null)
|
||||
Common.showNotificationError(getContext(), getActivity());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -191,7 +192,8 @@ public class HomeFragment extends Fragment {
|
||||
@Override
|
||||
public void onFailure(Call<Shops> call, Throwable t) {
|
||||
//Check internet connection
|
||||
Common.showNotificationError(getContext(), getActivity());
|
||||
if(getActivity() != null)
|
||||
Common.showNotificationError(getContext(), getActivity());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -31,16 +31,19 @@
|
||||
|
||||
<TextView
|
||||
android:id="@+id/forgot_Password_description"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/confirm_code_description"
|
||||
android:fontFamily="@font/opensans"
|
||||
android:textColor="@color/gray"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_marginStart="20dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
/>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
|
||||
@@ -1,118 +1,151 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".Fragment.HomeFragment">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_height="match_parent"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/header_title"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_marginTop="40dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/welcome_text"
|
||||
android:text="@string/hello_guest"
|
||||
android:textSize="22sp"
|
||||
android:fontFamily="@font/opensans"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/black"
|
||||
android:layout_weight="0.7"
|
||||
android:layout_width="0dp"
|
||||
<LinearLayout
|
||||
android:id="@+id/header_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_marginTop="40dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/welcome_text"
|
||||
android:text="@string/hello_guest"
|
||||
android:textSize="22sp"
|
||||
android:fontFamily="@font/opensans"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/black"
|
||||
android:layout_weight="0.7"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_address"
|
||||
android:text="@string/home"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/secondary"
|
||||
android:textAlignment="center"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
<ImageView
|
||||
android:src="@drawable/location"
|
||||
android:layout_weight="0.1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="30dp"
|
||||
android:contentDescription="@string/location_icon"
|
||||
app:tint="@color/secondary"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.denzcoskun.imageslider.ImageSlider
|
||||
android:id="@+id/slider"
|
||||
app:iss_auto_cycle="true"
|
||||
app:iss_delay="0"
|
||||
app:iss_period="3000"
|
||||
android:layout_marginTop="20dp"
|
||||
app:iss_corner_radius="40"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="180dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/header_title"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_address"
|
||||
android:text="@string/home"
|
||||
android:id="@+id/restaurant_text"
|
||||
android:text="Shop"
|
||||
android:layout_marginTop="5dp"
|
||||
android:textSize="18sp"
|
||||
android:fontFamily="@font/opensans"
|
||||
android:textColor="@color/black"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/secondary"
|
||||
android:textAlignment="center"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@id/slider"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
/>
|
||||
<ImageView
|
||||
android:src="@drawable/location"
|
||||
android:layout_weight="0.1"
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view_restaurant"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="30dp"
|
||||
android:contentDescription="@string/location_icon"
|
||||
app:tint="@color/secondary"
|
||||
android:layout_height="wrap_content"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
android:orientation="horizontal"
|
||||
android:contentDescription="@string/description"
|
||||
tools:listitem="@layout/item_shop"
|
||||
app:layout_constraintTop_toBottomOf="@id/restaurant_text"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view_menu"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
android:orientation="horizontal"
|
||||
tools:listitem="@layout/item_food"
|
||||
android:layout_marginTop="10dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/recycler_view_restaurant"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
/>
|
||||
|
||||
<com.denzcoskun.imageslider.ImageSlider
|
||||
android:id="@+id/slider"
|
||||
app:iss_auto_cycle="true"
|
||||
app:iss_delay="0"
|
||||
app:iss_period="3000"
|
||||
android:layout_marginTop="20dp"
|
||||
app:iss_corner_radius="40"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="180dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/header_title"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/restaurant_text"
|
||||
android:text="Shop"
|
||||
android:layout_marginTop="5dp"
|
||||
android:textSize="18sp"
|
||||
android:fontFamily="@font/opensans"
|
||||
android:textColor="@color/black"
|
||||
android:textStyle="bold"
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:background="#80000000"
|
||||
android:id="@+id/progress_layout"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBarLoadData"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@id/slider"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view_restaurant"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
android:orientation="horizontal"
|
||||
android:contentDescription="@string/description"
|
||||
tools:listitem="@layout/item_shop"
|
||||
app:layout_constraintTop_toBottomOf="@id/restaurant_text"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view_menu"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
android:orientation="horizontal"
|
||||
tools:listitem="@layout/item_food"
|
||||
android:layout_marginTop="10dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/recycler_view_restaurant"
|
||||
android:indeterminateTint="@color/primaryColor"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Reference in New Issue
Block a user