Browse Source

Complete RestaurantActivity

master
Apostolos Fanakis 6 years ago
parent
commit
8ab61c0b7f
  1. 2
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/AndroidManifest.xml
  2. 3
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddRestaurantActivity.java
  3. 24
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainActivity.java
  4. 122
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/RestaurantActivity.java
  5. 67
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantDrinksFragment.java
  6. 66
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantFoodsFragment.java
  7. 49
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantInfoFragment.java
  8. 69
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantItemAdapter.java
  9. 42
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantListFragment.java
  10. 28
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantRatingsAdapter.java
  11. 67
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantRatingsFragment.java
  12. 53
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/base/BaseFragment.java
  13. 23
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/ItemSummary.java
  14. 51
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_restaurant.xml
  15. 42
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/fragment_restaurant_info.xml
  16. 8
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/fragment_restaurant_items.xml
  17. 5
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/fragment_restaurant_map.xml
  18. 20
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/restaurant_item_row.xml
  19. 4
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/dimens.xml
  20. 6
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/strings.xml
  21. 5
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/styles.xml

2
UI/AndroidApp/flavoursWithoutBorders/app/src/main/AndroidManifest.xml

@ -46,7 +46,7 @@
android:name=".activities.main.MainActivity" android:name=".activities.main.MainActivity"
android:label="@string/main_activity_title" /> android:label="@string/main_activity_title" />
<activity android:name=".activities.restaurant.RestaurantActivity" /> <activity android:name=".activities.restaurant.RestaurantActivity" />
<activity android:name=".activities.restaurant.AddRestaurantActivity" /> <activity android:name=".activities.AddRestaurantActivity" />
</application> </application>
</manifest> </manifest>

3
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/AddRestaurantActivity.java → UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddRestaurantActivity.java

@ -1,8 +1,7 @@
package gr.auth.databases.flavours.activities.restaurant; package gr.auth.databases.flavours.activities;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;

24
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainActivity.java

@ -6,6 +6,8 @@ import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
@ -15,7 +17,7 @@ import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager; import androidx.viewpager.widget.ViewPager;
import gr.auth.databases.flavours.R; import gr.auth.databases.flavours.R;
import gr.auth.databases.flavours.activities.restaurant.AddRestaurantActivity; import gr.auth.databases.flavours.activities.AddRestaurantActivity;
import gr.auth.databases.flavours.activities.main.fragments.MainListFragment; import gr.auth.databases.flavours.activities.main.fragments.MainListFragment;
import gr.auth.databases.flavours.activities.main.fragments.MainMapFragment; import gr.auth.databases.flavours.activities.main.fragments.MainMapFragment;
import gr.auth.databases.flavours.base.BaseActivity; import gr.auth.databases.flavours.base.BaseActivity;
@ -25,6 +27,7 @@ public class MainActivity extends BaseActivity {
private ViewPager viewPager; private ViewPager viewPager;
private MenuItem menuMapItem; private MenuItem menuMapItem;
private FloatingActionButton FAB;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -42,6 +45,15 @@ public class MainActivity extends BaseActivity {
createDrawer(); createDrawer();
FAB = findViewById(R.id.main_fab);
FAB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(view.getContext(), AddRestaurantActivity.class);
startActivity(intent);
}
});
viewPager = findViewById(R.id.main_pager); viewPager = findViewById(R.id.main_pager);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
public void onPageScrollStateChanged(int state) { public void onPageScrollStateChanged(int state) {
@ -57,20 +69,14 @@ public class MainActivity extends BaseActivity {
if (position == 0) { if (position == 0) {
menuMapItem.setIcon(R.drawable.ic_map_black_24dp); menuMapItem.setIcon(R.drawable.ic_map_black_24dp);
FAB.show();
} else { } else {
menuMapItem.setIcon(R.drawable.ic_list_black_24dp); menuMapItem.setIcon(R.drawable.ic_list_black_24dp);
FAB.hide();
} }
} }
}); });
findViewById(R.id.main_fab).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(view.getContext(), AddRestaurantActivity.class);
startActivity(intent);
}
});
PagerAdapter pagerAdapter = new MainPagerAdapter(getSupportFragmentManager()); PagerAdapter pagerAdapter = new MainPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(pagerAdapter); viewPager.setAdapter(pagerAdapter);
} }

122
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/RestaurantActivity.java

@ -5,24 +5,31 @@ import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter; import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager; import androidx.viewpager.widget.ViewPager;
import gr.auth.databases.flavours.R; import gr.auth.databases.flavours.R;
import gr.auth.databases.flavours.activities.restaurant.fragments.RestaurantListFragment; import gr.auth.databases.flavours.activities.restaurant.fragments.RestaurantDrinksFragment;
import gr.auth.databases.flavours.activities.restaurant.fragments.RestaurantMapFragment; import gr.auth.databases.flavours.activities.restaurant.fragments.RestaurantFoodsFragment;
import gr.auth.databases.flavours.activities.restaurant.fragments.RestaurantInfoFragment;
import gr.auth.databases.flavours.activities.restaurant.fragments.RestaurantRatingsFragment;
import gr.auth.databases.flavours.base.BaseActivity; import gr.auth.databases.flavours.base.BaseActivity;
import gr.auth.databases.flavours.model.ItemSummary;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View; import android.view.View;
public class RestaurantActivity extends BaseActivity { import com.google.android.material.floatingactionbutton.FloatingActionButton;
private static final int NUM_PAGES = 2; import com.google.android.material.tabs.TabLayout;
import java.util.ArrayList;
import java.util.List;
public class RestaurantActivity extends BaseActivity
implements RestaurantFoodsFragment.RestaurantFoodsFragmentInteractionListener,
RestaurantDrinksFragment.RestaurantDrinksFragmentInteractionListener {
private ViewPager viewPager; private ViewPager viewPager;
private MenuItem menuMapItem; private FloatingActionButton FAB;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -41,6 +48,16 @@ public class RestaurantActivity extends BaseActivity {
createDrawer(); createDrawer();
drawer.setSelection(-1); drawer.setSelection(-1);
FAB = findViewById(R.id.restaurant_fab);
FAB.hide();
FAB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
/*Intent intent = new Intent(view.getContext(), AddRestaurantActivity.class);
startActivity(intent);*/
}
});
viewPager = findViewById(R.id.restaurant_pager); viewPager = findViewById(R.id.restaurant_pager);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
public void onPageScrollStateChanged(int state) { public void onPageScrollStateChanged(int state) {
@ -50,85 +67,86 @@ public class RestaurantActivity extends BaseActivity {
} }
public void onPageSelected(int position) { public void onPageSelected(int position) {
if (menuMapItem == null) {
return;
}
if (position == 0) { if (position == 0) {
menuMapItem.setIcon(R.drawable.ic_map_black_24dp); FAB.hide();
} else { } else {
menuMapItem.setIcon(R.drawable.ic_list_black_24dp); FAB.show();
} }
} }
}); });
findViewById(R.id.restaurant_fab).setOnClickListener(new View.OnClickListener() { setupViewPager(viewPager);
@Override TabLayout tabLayout = findViewById(R.id.restaurant_tabs);
public void onClick(View view) { tabLayout.setupWithViewPager(viewPager);
/*Intent intent = new Intent(view.getContext(), AddRestaurantActivity.class);
startActivity(intent);*/
} }
});
PagerAdapter pagerAdapter = new RestaurantPagerAdapter(getSupportFragmentManager()); /*@Override
viewPager.setAdapter(pagerAdapter); public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
drawer.openDrawer();
return true;
} }
return super.onOptionsItemSelected(item);
}*/
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if (drawer.isDrawerOpen()) { if (drawer.isDrawerOpen()) {
drawer.closeDrawer(); drawer.closeDrawer();
} else if (viewPager.getCurrentItem() == 1) {
viewPager.setCurrentItem(0);
} else { } else {
super.onBackPressed(); super.onBackPressed();
} }
} }
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public void onRestaurantFoodsFragmentInteraction(ItemSummary item) {
getMenuInflater().inflate(R.menu.restaurant_toolbar_menu, menu); // todo
menuMapItem = menu.findItem(R.id.restaurant_toolbar_menu_map);
return true;
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public void onRestaurantDrinksFragmentInteraction(ItemSummary item) {
int id = item.getItemId(); // todo
if (id == R.id.main_toolbar_menu_map) {
if (viewPager.getCurrentItem() == 0) {
viewPager.setCurrentItem(1);
} else if (viewPager.getCurrentItem() == 1) {
viewPager.setCurrentItem(0);
}
return true;
} else if (id == android.R.id.home) {
drawer.openDrawer();
return true;
} }
return super.onOptionsItemSelected(item); private void setupViewPager(ViewPager viewPager) {
RestaurantPagerAdapter adapter = new RestaurantPagerAdapter(getSupportFragmentManager());
adapter.addFrag(RestaurantInfoFragment.newInstance(64), "INFO");
adapter.addFrag(RestaurantFoodsFragment.newInstance(64), "FOOD");
adapter.addFrag(RestaurantDrinksFragment.newInstance(64), "DRINKS");
adapter.addFrag(RestaurantRatingsFragment.newInstance(64), "RATINGS");
viewPager.setAdapter(adapter);
} }
private class RestaurantPagerAdapter extends FragmentStatePagerAdapter { private class RestaurantPagerAdapter extends FragmentPagerAdapter {
RestaurantPagerAdapter(FragmentManager fm) { private final List<Fragment> mFragmentList = new ArrayList<>();
super(fm); private final List<String> mFragmentTitleList = new ArrayList<>();
RestaurantPagerAdapter(FragmentManager manager) {
super(manager);
} }
@NonNull @NonNull
@Override @Override
public Fragment getItem(int position) { public Fragment getItem(int position) {
if (position == 0) { return mFragmentList.get(position);
return new RestaurantListFragment();
} else {
return new RestaurantMapFragment();
}
} }
@Override @Override
public int getCount() { public int getCount() {
return NUM_PAGES; return mFragmentList.size();
}
void addFrag(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
@Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
} }
} }
} }

67
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantDrinksFragment.java

@ -0,0 +1,67 @@
package gr.auth.databases.flavours.activities.restaurant.fragments;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import gr.auth.databases.flavours.R;
import gr.auth.databases.flavours.base.BaseFragment;
import gr.auth.databases.flavours.model.ItemSummary;
public class RestaurantDrinksFragment extends BaseFragment {
public RestaurantDrinksFragment() {
// Required empty public constructor
}
private static final String RESTAURANT_ID = "RESTAURANT_ID";
private int restaurantId;
public static RestaurantDrinksFragment newInstance(int restaurantId) {
RestaurantDrinksFragment fragment = new RestaurantDrinksFragment();
Bundle args = new Bundle();
args.putInt(RESTAURANT_ID, restaurantId);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
assert getArguments() != null;
restaurantId = getArguments().getInt(RESTAURANT_ID);
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_restaurant_items, container, false);
ArrayList<ItemSummary> drinks = new ArrayList<>();
drinks.add(new ItemSummary("White russian", ItemSummary.ItemType.DRINK));
drinks.add(new ItemSummary("Τσίπουρο Τσάπουρας", ItemSummary.ItemType.DRINK));
RestaurantItemAdapter itemAdapter = new RestaurantItemAdapter(fragmentInteractionListener, drinks);
RecyclerView mainContent = rootView.findViewById(R.id.restaurant_list);
mainContent.setAdapter(itemAdapter);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
mainContent.setLayoutManager(layoutManager);
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mainContent.getContext(),
layoutManager.getOrientation());
mainContent.addItemDecoration(dividerItemDecoration);
return rootView;
}
public interface RestaurantDrinksFragmentInteractionListener extends FragmentInteractionListener {
void onRestaurantDrinksFragmentInteraction(ItemSummary foodSummary);
}
}

66
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantFoodsFragment.java

@ -0,0 +1,66 @@
package gr.auth.databases.flavours.activities.restaurant.fragments;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import gr.auth.databases.flavours.R;
import gr.auth.databases.flavours.base.BaseFragment;
import gr.auth.databases.flavours.model.ItemSummary;
public class RestaurantFoodsFragment extends BaseFragment {
public RestaurantFoodsFragment() {
// Required empty public constructor
}
private static final String RESTAURANT_ID = "RESTAURANT_ID";
private int restaurantId;
public static RestaurantFoodsFragment newInstance(int restaurantId) {
RestaurantFoodsFragment fragment = new RestaurantFoodsFragment();
Bundle args = new Bundle();
args.putInt(RESTAURANT_ID, restaurantId);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
assert getArguments() != null;
restaurantId = getArguments().getInt(RESTAURANT_ID);
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_restaurant_items, container, false);
ArrayList<ItemSummary> foods = new ArrayList<>();
foods.add(new ItemSummary("Γιουβαρλάκια", ItemSummary.ItemType.FOOD));
foods.add(new ItemSummary("Γεμιστά", ItemSummary.ItemType.FOOD));
RestaurantItemAdapter itemAdapter = new RestaurantItemAdapter(fragmentInteractionListener, foods);
RecyclerView mainContent = rootView.findViewById(R.id.restaurant_list);
mainContent.setAdapter(itemAdapter);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
mainContent.setLayoutManager(layoutManager);
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mainContent.getContext(),
layoutManager.getOrientation());
mainContent.addItemDecoration(dividerItemDecoration);
return rootView;
}
public interface RestaurantFoodsFragmentInteractionListener extends FragmentInteractionListener {
void onRestaurantFoodsFragmentInteraction(ItemSummary foodSummary);
}
}

49
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantMapFragment.java → UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantInfoFragment.java

@ -1,30 +1,69 @@
package gr.auth.databases.flavours.activities.restaurant.fragments; package gr.auth.databases.flavours.activities.restaurant.fragments;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView; import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.OnMapReadyCallback;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import gr.auth.databases.flavours.R; import gr.auth.databases.flavours.R;
import gr.auth.databases.flavours.base.BaseFragment;
public class RestaurantMapFragment extends Fragment implements OnMapReadyCallback { public class RestaurantInfoFragment extends BaseFragment implements OnMapReadyCallback {
private MapView gMapView = null; private MapView gMapView = null;
public RestaurantInfoFragment() {
// Required empty public constructor
}
private static final String RESTAURANT_ID = "RESTAURANT_ID";
private int restaurantId;
public static RestaurantInfoFragment newInstance(int restaurantId) {
RestaurantInfoFragment fragment = new RestaurantInfoFragment();
Bundle args = new Bundle();
args.putInt(RESTAURANT_ID, restaurantId);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
assert getArguments() != null;
restaurantId = getArguments().getInt(RESTAURANT_ID);
}
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_restaurant_map, container, false); final View rootView = inflater.inflate(R.layout.fragment_restaurant_info, container, false);
TextView workingHours = rootView.findViewById(R.id.restaurant_working_hours);
workingHours.setText(getString(R.string.restaurant_working_hours,
"12:00", "01:30"));
TextView type = rootView.findViewById(R.id.restaurant_type);
type.setText(getString(R.string.restaurant_type, "Bar"));
TextView averageRatings = rootView.findViewById(R.id.restaurant_average_rating);
averageRatings.setText(getString(R.string.restaurant_average_rating, 4.78));
LinearLayout averageRatingPerDiet = rootView.findViewById(R.id.restaurant_average_rating_per_diet);
TextView dietRatingView = new TextView(getContext());
dietRatingView.setText(getString(R.string.restaurant_diet_average_rating, "όγκος", 4.65));
averageRatingPerDiet.addView(dietRatingView);
dietRatingView = new TextView(getContext());
dietRatingView.setText(getString(R.string.restaurant_diet_average_rating, "vegan", 2.23));
averageRatingPerDiet.addView(dietRatingView);
gMapView = rootView.findViewById(R.id.restaurant_map); gMapView = rootView.findViewById(R.id.restaurant_map);
gMapView.getMapAsync(this); gMapView.getMapAsync(this);
gMapView.onCreate(getArguments()); gMapView.onCreate(getArguments());
return rootView; return rootView;
} }

69
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantItemAdapter.java

@ -0,0 +1,69 @@
package gr.auth.databases.flavours.activities.restaurant.fragments;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.ArrayList;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;
import gr.auth.databases.flavours.R;
import gr.auth.databases.flavours.base.BaseFragment;
import gr.auth.databases.flavours.model.ItemSummary;
public class RestaurantItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final RestaurantFoodsFragment.RestaurantFoodsFragmentInteractionListener interactionListener;
private final ArrayList<ItemSummary> items;
RestaurantItemAdapter(BaseFragment.FragmentInteractionListener interactionListener,
ArrayList<ItemSummary> items) {
this.interactionListener = (RestaurantFoodsFragment.RestaurantFoodsFragmentInteractionListener) interactionListener;
this.items = items;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).
inflate(R.layout.restaurant_item_row, parent, false);
return new ItemViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
ItemSummary item = items.get(position);
ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
itemViewHolder.card.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (interactionListener != null) {
// Notify the active callbacks interface (the activity, if the
// fragment is attached to one) that an item has been selected.
interactionListener.onRestaurantFoodsFragmentInteraction(items.get(holder.getAdapterPosition()));
}
}
});
itemViewHolder.item.setText(item.getItem());
}
@Override
public int getItemCount() {
return items == null ? 0 : items.size();
}
private static class ItemViewHolder extends RecyclerView.ViewHolder {
CardView card;
TextView item;
ItemViewHolder(View itemView) {
super(itemView);
card = itemView.findViewById(R.id.restaurant_item_row_card);
item = itemView.findViewById(R.id.restaurant_item_row_item);
}
}
}

42
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantListFragment.java

@ -1,42 +0,0 @@
package gr.auth.databases.flavours.activities.restaurant.fragments;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import gr.auth.databases.flavours.R;
import gr.auth.databases.flavours.activities.restaurant.RestaurantAdapter;
import gr.auth.databases.flavours.model.Rating;
public class RestaurantListFragment extends Fragment {
private Rating[] ratings = new Rating[7];
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_restaurant_list, container, false);
RecyclerView recyclerView = rootView.findViewById(R.id.restaurant_recycler);
recyclerView.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(layoutManager);
ratings[0] = new Rating(5, "Ανώνυμος", "Πάρα πολύ καλό!", "2018-01-04", Rating.Accessibility.MODERATE);
ratings[1] = new Rating(5, "Ανύπαρκτος", "Εξαιρετικό service.\nΘα ξαναπάω!", "2018-06-08", Rating.Accessibility.EASY);
ratings[2] = new Rating(4, "Γαρδένιος ο Stoner", "-", "2018-06-08", Rating.Accessibility.EASY);
ratings[3] = new Rating(4, "Μαγκούστα", "Μου άρεσε.", "2018-06-08", Rating.Accessibility.MODERATE);
ratings[4] = new Rating(5, "Νταλίκας", "Τέλειο.", "2018-06-08", Rating.Accessibility.EASY);
ratings[5] = new Rating(2, "Ms Godzila", "Το φαϊ άργησε πάρα πολύ!", "2018-06-08", null);
ratings[6] = new Rating(4, "eddie lives inside you", "-", "2018-06-08", Rating.Accessibility.MODERATE);
RestaurantAdapter restaurantAdapter = new RestaurantAdapter(getContext(), ratings);
recyclerView.setAdapter(restaurantAdapter);
return rootView;
}
}

28
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/RestaurantAdapter.java → UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantRatingsAdapter.java

@ -1,29 +1,30 @@
package gr.auth.databases.flavours.activities.restaurant; package gr.auth.databases.flavours.activities.restaurant.fragments;
import android.content.Context; import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import java.util.ArrayList;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import gr.auth.databases.flavours.R; import gr.auth.databases.flavours.R;
import gr.auth.databases.flavours.model.Rating; import gr.auth.databases.flavours.model.Rating;
public class RestaurantAdapter extends RecyclerView.Adapter<RestaurantAdapter.RatingViewHolder> { public class RestaurantRatingsAdapter extends RecyclerView.Adapter<RestaurantRatingsAdapter.RatingViewHolder> {
private Context context; private Context context;
private Rating[] ratings; private ArrayList<Rating> ratings;
public RestaurantAdapter(Context context, Rating[] ratings) { RestaurantRatingsAdapter(Context context, ArrayList<Rating> ratings) {
this.context = context; this.context = context;
this.ratings = ratings; this.ratings = ratings;
} }
@NonNull @NonNull
@Override @Override
public RestaurantAdapter.RatingViewHolder onCreateViewHolder(@NonNull ViewGroup parent, public RestaurantRatingsAdapter.RatingViewHolder onCreateViewHolder(@NonNull ViewGroup parent,
int viewType) { int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_restaurant_list_row, View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_restaurant_list_row,
parent, false); parent, false);
@ -32,27 +33,26 @@ public class RestaurantAdapter extends RecyclerView.Adapter<RestaurantAdapter.Ra
@Override @Override
public void onBindViewHolder(@NonNull RatingViewHolder holder, int position) { public void onBindViewHolder(@NonNull RatingViewHolder holder, int position) {
Log.d("THISSSS", "" + position + ratings[position].getUsername()); holder.username.setText(ratings.get(position).getUsername());
holder.username.setText(ratings[position].getUsername()); holder.date.setText(ratings.get(position).getDate());
holder.date.setText(ratings[position].getDate());
holder.grade.setText(context.getString(R.string.restaurant_row_grade_placeholder, holder.grade.setText(context.getString(R.string.restaurant_row_grade_placeholder,
ratings[position].getGrade())); ratings.get(position).getGrade()));
if (ratings[position].getAccessibility() != null) { if (ratings.get(position).getAccessibility() != null) {
holder.accessibility.setVisibility(View.VISIBLE); holder.accessibility.setVisibility(View.VISIBLE);
holder.accessibility.setText(context.getString(R.string.restaurant_row_accessibility_placeholder, holder.accessibility.setText(context.getString(R.string.restaurant_row_accessibility_placeholder,
ratings[position].getAccessibility().toString())); ratings.get(position).getAccessibility().toString()));
} else { } else {
holder.accessibility.setVisibility(View.GONE); holder.accessibility.setVisibility(View.GONE);
} }
holder.text.setText(ratings[position].getText()); holder.text.setText(ratings.get(position).getText());
} }
@Override @Override
public int getItemCount() { public int getItemCount() {
return ratings.length; return ratings == null ? 0 : ratings.size();
} }
static class RatingViewHolder extends RecyclerView.ViewHolder { static class RatingViewHolder extends RecyclerView.ViewHolder {

67
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/fragments/RestaurantRatingsFragment.java

@ -0,0 +1,67 @@
package gr.auth.databases.flavours.activities.restaurant.fragments;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import gr.auth.databases.flavours.R;
import gr.auth.databases.flavours.model.Rating;
public class RestaurantRatingsFragment extends Fragment {
public RestaurantRatingsFragment() {
// Required empty public constructor
}
private static final String RESTAURANT_ID = "RESTAURANT_ID";
private int restaurantId;
public static RestaurantRatingsFragment newInstance(int restaurantId) {
RestaurantRatingsFragment fragment = new RestaurantRatingsFragment();
Bundle args = new Bundle();
args.putInt(RESTAURANT_ID, restaurantId);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
assert getArguments() != null;
restaurantId = getArguments().getInt(RESTAURANT_ID);
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_restaurant_items, container, false);
ArrayList<Rating> ratings = new ArrayList<>();
ratings.add(new Rating(5, "Ανώνυμος", "Πάρα πολύ καλό!", "2018-01-04", Rating.Accessibility.MODERATE));
ratings.add(new Rating(5, "Ανύπαρκτος", "Εξαιρετικό service.\nΘα ξαναπάω!", "2018-06-08", Rating.Accessibility.EASY));
ratings.add(new Rating(4, "Γαρδένιος ο Stoner", "-", "2018-06-08", Rating.Accessibility.EASY));
ratings.add(new Rating(4, "Μαγκούστα", "Μου άρεσε.", "2018-06-08", Rating.Accessibility.MODERATE));
ratings.add(new Rating(5, "Νταλίκας", "Τέλειο.", "2018-06-08", Rating.Accessibility.EASY));
ratings.add(new Rating(2, "Ms Godzila", "Το φαϊ άργησε πάρα πολύ!", "2018-06-08", null));
ratings.add(new Rating(4, "eddie lives inside you", "-", "2018-06-08", Rating.Accessibility.MODERATE));
RestaurantRatingsAdapter itemAdapter = new RestaurantRatingsAdapter(getContext(), ratings);
RecyclerView mainContent = rootView.findViewById(R.id.restaurant_list);
mainContent.setAdapter(itemAdapter);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
mainContent.setLayoutManager(layoutManager);
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mainContent.getContext(),
layoutManager.getOrientation());
mainContent.addItemDecoration(dividerItemDecoration);
return rootView;
}
}

53
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/base/BaseFragment.java

@ -0,0 +1,53 @@
package gr.auth.databases.flavours.base;
import android.content.Context;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import okhttp3.OkHttpClient;
public abstract class BaseFragment extends Fragment {
protected static final String ARG_SECTION_NUMBER = "SectionNumber";
protected static final String ARG_TAG = "FragmentTAG";
protected FragmentInteractionListener fragmentInteractionListener;
protected static OkHttpClient client;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//int sectionNumber = getArguments().getInt(ARG_SECTION_NUMBER);
if (client == null)
client = BaseApplication.getInstance().getClient(); //must check every time - e.g.
// becomes null when app restarts after crash
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
/*if (context instanceof FragmentInteractionListener) {
fragmentInteractionListener = (FragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}*/
}
@Override
public void onDetach() {
super.onDetach();
fragmentInteractionListener = null;
}
/**
* This interface MUST be extended by the fragment subclass AND implemented by
* the activity that contains it, to allow communication upon interaction,
* between the fragment and the activity/ other fragments
*/
public interface FragmentInteractionListener {
}
}

23
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/ItemSummary.java

@ -0,0 +1,23 @@
package gr.auth.databases.flavours.model;
public class ItemSummary {
public enum ItemType {
FOOD, DRINK
}
private String item;
private ItemType type;
public ItemSummary(String item, ItemType type) {
this.item = item;
this.type = type;
}
public String getItem() {
return item;
}
public ItemType getType() {
return type;
}
}

51
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_restaurant.xml

@ -10,55 +10,26 @@
android:id="@+id/restaurant_appbar" android:id="@+id/restaurant_appbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:theme="@style/Theme.AppCompat.Light"> android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/ToolbarTheme">
<androidx.appcompat.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/restaurant_toolbar" android:id="@+id/restaurant_toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" android:background="?attr/colorPrimary"
app:popupTheme="@style/Theme.AppCompat.Light" android:gravity="center"
app:title="@string/restaurant_toolbar_title" /> app:popupTheme="@style/ToolbarTheme"/>
<!--<android.support.design.widget.CollapsingToolbarLayout <com.google.android.material.tabs.TabLayout
android:id="@+id/restaurant_collapsing" android:id="@+id/restaurant_tabs"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:orientation="horizontal"
app:layout_collapseMode="parallax">
<TextView
android:id="@+id/add_restaurant_working_hours"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/restaurant_working_hours"
android:textColor="@color/colorAccent"
app:layout_scrollFlags="enterAlways" />
<TextView
android:id="@+id/add_restaurant_type"
android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end" android:gravity="center"
android:layout_weight="1" app:tabGravity="fill"
android:gravity="end" app:tabMode="fixed"
android:text="@string/restaurant_type" app:tabSelectedTextColor="@color/accent"
android:textColor="@color/colorAccent" app:tabTextColor="@color/iron" />
app:layout_scrollFlags="enterAlways" />
</LinearLayout>
<!--</android.support.design.widget.CollapsingToolbarLayout>-->
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager <androidx.viewpager.widget.ViewPager

42
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/fragment_restaurant_info.xml

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/restaurant_working_hours"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/restaurant_working_hours" />
<TextView
android:id="@+id/restaurant_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="@string/restaurant_type" />
<TextView
android:id="@+id/restaurant_average_rating"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="@string/restaurant_average_rating" />
<LinearLayout
android:id="@+id/restaurant_average_rating_per_diet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:orientation="vertical"
android:visibility="gone" />
<com.google.android.gms.maps.MapView
android:id="@+id/restaurant_map"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="6dp"
android:layout_marginBottom="12dp"
android:layout_weight="1" />
</LinearLayout>

8
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/fragment_restaurant_list.xml → UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/fragment_restaurant_items.xml

@ -1,10 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" <androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/restaurant_list"
android:id="@+id/restaurant_recycler"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_marginStart="12dp" android:layout_marginStart="12dp"
android:layout_marginEnd="12dp" android:layout_marginEnd="12dp"
android:orientation="vertical" android:orientation="vertical" />
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

5
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/fragment_restaurant_map.xml

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/restaurant_map"
android:layout_width="match_parent"
android:layout_height="match_parent" />

20
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/restaurant_item_row.xml

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/restaurant_item_row_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:foreground="?android:attr/selectableItemBackground"
card_view:cardCornerRadius="5dp"
card_view:cardElevation="2dp"
card_view:cardPreventCornerOverlap="false"
card_view:cardUseCompatPadding="true">
<TextView
android:id="@+id/restaurant_item_row_item"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.cardview.widget.CardView>

4
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/dimens.xml

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="appbar_padding_top">8dp</dimen>
</resources>

6
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/strings.xml

@ -44,8 +44,10 @@
<!-- Restaurant --> <!-- Restaurant -->
<string name="restaurant_toolbar_title">Restaurant Name</string> <string name="restaurant_toolbar_title">Restaurant Name</string>
<string name="restaurant_working_hours">Working hours</string> <string name="restaurant_working_hours">Working hours: %1$s - %2$s</string>
<string name="restaurant_type">Restaurant type</string> <string name="restaurant_type">Restaurant type: %1$s</string>
<string name="restaurant_average_rating">Restaurant average rating: %1$f</string>
<string name="restaurant_diet_average_rating">Restaurant average rating for diet %1$s: %2$f</string>
<string name="restaurant_row_grade_placeholder">Grade = %1$d/5</string> <string name="restaurant_row_grade_placeholder">Grade = %1$d/5</string>
<string name="restaurant_row_accessibility_placeholder">Accessibility = %1$s</string> <string name="restaurant_row_accessibility_placeholder">Accessibility = %1$s</string>

5
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/styles.xml

@ -7,4 +7,9 @@
<item name="colorAccent">@color/colorAccent</item> <item name="colorAccent">@color/colorAccent</item>
</style> </style>
<style name="ToolbarTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:colorBackground">@color/colorPrimary</item>
<item name="colorControlNormal">@android:color/white</item>
</style>
</resources> </resources>
Loading…
Cancel
Save