Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor improvements #63

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: "androidx.navigation.safeargs"

android {
compileSdkVersion 30
Expand Down
7 changes: 0 additions & 7 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,10 @@
android:name=".view.activity.MainActivity"
android:windowSoftInputMode="adjustPan" />

<activity
android:name=".view.activity.RestaurantDetails"
android:theme="@style/AppTheme" />

<activity
android:name=".view.activity.MenuActivity"
android:theme="@style/AppTheme" />

<activity
android:name=".view.activity.CollectionDetails" />

</application>

</manifest>

This file was deleted.

12 changes: 12 additions & 0 deletions app/src/main/java/com/tip/lunchbox/view/activity/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.tip.lunchbox.view.activity;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.NavDestination;
import androidx.navigation.Navigation;
import androidx.navigation.ui.NavigationUI;

Expand All @@ -24,6 +28,14 @@ protected void onCreate(Bundle savedInstanceState) {
//Setting navController
NavController navController = Navigation.findNavController(this,
R.id.navigation_host_fragment);
navController.addOnDestinationChangedListener((controller, destination, arguments) -> {
if (destination.getId() == R.id.restaurantDetails
|| destination.getId() == R.id.collectionDetails) {
mainBinding.mainActivityBn.setVisibility(View.GONE);
} else {
mainBinding.mainActivityBn.setVisibility(View.VISIBLE);
}
});
NavigationUI.setupWithNavController(mainBinding.mainActivityBn, navController);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public void addData(RestaurantContainer restaurantContainer) {
restaurantItemBinding.itemTvRestaurantName.setText(restaurant.getName());
Glide.with(restaurantItemBinding.getRoot())
.load(restaurant.getThumb())
.error(R.drawable.ic_image_not_found)
.centerCrop()
.into(restaurantItemBinding.itemIvRestaurant);
restaurantItemBinding.itemTvRating.setText(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.tip.lunchbox.view.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.fragment.NavHostFragment;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.tip.lunchbox.databinding.FragmentCollectionDetailsBinding;
import com.tip.lunchbox.view.adapter.RestaurantAdapter;
import com.tip.lunchbox.view.listeners.RecyclerTouchListener;
import com.tip.lunchbox.viewmodel.CollectionDetailsViewModel;

import org.jetbrains.annotations.NotNull;

public class CollectionDetails extends Fragment {
private FragmentCollectionDetailsBinding binding;
private CollectionDetailsViewModel viewModel;
private RestaurantAdapter adapter;

@Override
public View onCreateView(@NotNull LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = FragmentCollectionDetailsBinding.inflate(inflater, container, false);
setupRecyclerView();

viewModel = new ViewModelProvider(this).get(CollectionDetailsViewModel.class);
assert getArguments() != null;
int collectionId = CollectionDetailsArgs.fromBundle(getArguments()).getCollectionID();
String collectionName = CollectionDetailsArgs
.fromBundle(getArguments()).getCollectionName();
binding.appBarTvLocation.setText(collectionName);
viewModel.getSearchResponseLiveData(collectionId)
.observe(getViewLifecycleOwner(), searchResponse ->
adapter.setData(searchResponse.getRestaurantContainers()));
return binding.getRoot();
}

private void setupRecyclerView() {
adapter = new RestaurantAdapter(requireContext());
binding.rvCollectionsDetails.setAdapter(adapter);
binding.rvCollectionsDetails.setLayoutManager(new LinearLayoutManager(requireContext()));

new RecyclerTouchListener(requireContext(),
binding.rvCollectionsDetails, (view, position) -> {
CollectionDetailsDirections.ActionCollectionDetailsToRestaurantDetails action =
CollectionDetailsDirections.actionCollectionDetailsToRestaurantDetails(
Integer.parseInt(adapter.getData().get(position)
.getRestaurant().getId()));

NavHostFragment.findNavController(this).navigate(action);
});
}
}
32 changes: 20 additions & 12 deletions app/src/main/java/com/tip/lunchbox/view/fragment/HomeFragment.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.tip.lunchbox.view.fragment;

import android.animation.Animator;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -28,8 +27,6 @@
import com.tip.lunchbox.model.CategoryContainer;
import com.tip.lunchbox.model.Restaurant;
import com.tip.lunchbox.model.RestaurantContainer;
import com.tip.lunchbox.utilities.Constants;
import com.tip.lunchbox.view.activity.RestaurantDetails;
import com.tip.lunchbox.view.listeners.CategoryChangeListener;
import com.tip.lunchbox.view.adapter.RestaurantAdapter;
import com.tip.lunchbox.view.listeners.RecyclerTouchListener;
Expand All @@ -39,7 +36,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
Expand Down Expand Up @@ -74,12 +70,14 @@ public View onCreateView(@NotNull LayoutInflater inflater,
adapter = new RestaurantAdapter(getActivity());

new RecyclerTouchListener(getActivity(), homeBinding.rvRestaurant, (view, position) -> {
Intent intent = new Intent(getContext(), RestaurantDetails.class);
intent.putExtra(Constants.INTENT_RES_ID, adapter.getData().get(position)
.getRestaurant().getId());
requireActivity().startActivity(intent);
});
HomeFragmentDirections.ActionHomeFragmentToRestaurantDetails action =
HomeFragmentDirections.actionHomeFragmentToRestaurantDetails(
Integer.parseInt(adapter.getData().get(position)
.getRestaurant().getId()));

NavHostFragment.findNavController(this).navigate(action);
});
onError();
BottomSheetBehavior.from(homeBinding.nsvRestaurantList);
homeBinding.rvRestaurant.setLayoutManager(new LinearLayoutManager(getActivity()));
homeBinding.rvRestaurant.setAdapter(adapter);
Expand Down Expand Up @@ -109,13 +107,23 @@ private void showData() {
homeBinding.rvRestaurant.setVisibility(View.VISIBLE);
}

private void onError() {
viewModel.getIsErrorLiveData().observe(getViewLifecycleOwner(), aBoolean -> {
if (aBoolean) {
showErrorView();
} else {
showData();
}
});
}

private void loadData() {
showLoadingView();
viewModel.getCategoriesLiveData().observe(getViewLifecycleOwner(), categoryResponse -> {
if (categoryResponse != null) {
List<CategoryContainer> categories = categoryResponse.getCategories();
for (CategoryContainer categoryContainer : categories) {
Chip categoryChip = (Chip)(getLayoutInflater()
Chip categoryChip = (Chip) (getLayoutInflater()
.inflate(R.layout.item_chip_category, homeBinding.filterChipGroup,
false));
categoryChip.setText(categoryContainer.getCategories().getName());
Expand Down Expand Up @@ -171,8 +179,8 @@ public void onAnimationRepeat(Animator animation) {
showData();

homeBinding.appBarTvLocation.setText(geoCodeResponse.getLocality().getTitle()
+ ", "
+ geoCodeResponse.getLocality().getCityName());
+ ", "
+ geoCodeResponse.getLocality().getCityName());
setMapMarkers(geoCodeResponse.getNearbyRestaurantContainers());
} else {
showErrorView();
Expand Down
Loading