Apostolos Fanakis
6 years ago
23 changed files with 829 additions and 34 deletions
@ -1,15 +1,134 @@ |
|||||
package gr.auth.databases.flavours.activities.restaurant; |
package gr.auth.databases.flavours.activities.restaurant; |
||||
|
|
||||
|
import androidx.annotation.NonNull; |
||||
|
import androidx.appcompat.app.ActionBar; |
||||
|
import androidx.appcompat.widget.Toolbar; |
||||
|
import androidx.fragment.app.Fragment; |
||||
|
import androidx.fragment.app.FragmentManager; |
||||
|
import androidx.fragment.app.FragmentStatePagerAdapter; |
||||
|
import androidx.viewpager.widget.PagerAdapter; |
||||
|
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.RestaurantMapFragment; |
||||
import gr.auth.databases.flavours.base.BaseActivity; |
import gr.auth.databases.flavours.base.BaseActivity; |
||||
|
|
||||
import android.os.Bundle; |
import android.os.Bundle; |
||||
|
import android.view.Menu; |
||||
|
import android.view.MenuItem; |
||||
|
import android.view.View; |
||||
|
|
||||
public class RestaurantActivity extends BaseActivity { |
public class RestaurantActivity extends BaseActivity { |
||||
|
private static final int NUM_PAGES = 2; |
||||
|
|
||||
|
private ViewPager viewPager; |
||||
|
private MenuItem menuMapItem; |
||||
|
|
||||
@Override |
@Override |
||||
protected void onCreate(Bundle savedInstanceState) { |
protected void onCreate(Bundle savedInstanceState) { |
||||
super.onCreate(savedInstanceState); |
super.onCreate(savedInstanceState); |
||||
setContentView(R.layout.activity_restaurant); |
setContentView(R.layout.activity_restaurant); |
||||
|
|
||||
|
Toolbar toolbar = findViewById(R.id.restaurant_toolbar); |
||||
|
toolbar.setTitle(getString(R.string.restaurant_toolbar_title)); |
||||
|
setSupportActionBar(toolbar); |
||||
|
ActionBar actionbar = getSupportActionBar(); |
||||
|
if (actionbar != null) { |
||||
|
actionbar.setDisplayHomeAsUpEnabled(true); |
||||
|
actionbar.setHomeAsUpIndicator(R.drawable.ic_menu_black_24dp); |
||||
|
} |
||||
|
|
||||
|
createDrawer(); |
||||
|
drawer.setSelection(-1); |
||||
|
|
||||
|
viewPager = findViewById(R.id.restaurant_pager); |
||||
|
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { |
||||
|
public void onPageScrollStateChanged(int state) { |
||||
|
} |
||||
|
|
||||
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { |
||||
|
} |
||||
|
|
||||
|
public void onPageSelected(int position) { |
||||
|
if (menuMapItem == null) { |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
if (position == 0) { |
||||
|
menuMapItem.setIcon(R.drawable.ic_map_black_24dp); |
||||
|
} else { |
||||
|
menuMapItem.setIcon(R.drawable.ic_list_black_24dp); |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
findViewById(R.id.restaurant_fab).setOnClickListener(new View.OnClickListener() { |
||||
|
@Override |
||||
|
public void onClick(View view) { |
||||
|
/*Intent intent = new Intent(view.getContext(), AddRestaurantActivity.class); |
||||
|
startActivity(intent);*/ |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
PagerAdapter pagerAdapter = new RestaurantPagerAdapter(getSupportFragmentManager()); |
||||
|
viewPager.setAdapter(pagerAdapter); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onBackPressed() { |
||||
|
if (drawer.isDrawerOpen()) { |
||||
|
drawer.closeDrawer(); |
||||
|
} else if (viewPager.getCurrentItem() == 1) { |
||||
|
viewPager.setCurrentItem(0); |
||||
|
} else { |
||||
|
super.onBackPressed(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean onCreateOptionsMenu(Menu menu) { |
||||
|
getMenuInflater().inflate(R.menu.restaurant_toolbar_menu, menu); |
||||
|
menuMapItem = menu.findItem(R.id.restaurant_toolbar_menu_map); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean onOptionsItemSelected(MenuItem item) { |
||||
|
int id = item.getItemId(); |
||||
|
|
||||
|
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 class RestaurantPagerAdapter extends FragmentStatePagerAdapter { |
||||
|
RestaurantPagerAdapter(FragmentManager fm) { |
||||
|
super(fm); |
||||
|
} |
||||
|
|
||||
|
@NonNull |
||||
|
@Override |
||||
|
public Fragment getItem(int position) { |
||||
|
if (position == 0) { |
||||
|
return new RestaurantListFragment(); |
||||
|
} else { |
||||
|
return new RestaurantMapFragment(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public int getCount() { |
||||
|
return NUM_PAGES; |
||||
|
} |
||||
} |
} |
||||
} |
} |
||||
|
@ -0,0 +1,70 @@ |
|||||
|
package gr.auth.databases.flavours.activities.restaurant; |
||||
|
|
||||
|
import android.content.Context; |
||||
|
import android.util.Log; |
||||
|
import android.view.LayoutInflater; |
||||
|
import android.view.View; |
||||
|
import android.view.ViewGroup; |
||||
|
import android.widget.TextView; |
||||
|
|
||||
|
import androidx.annotation.NonNull; |
||||
|
import androidx.recyclerview.widget.RecyclerView; |
||||
|
import gr.auth.databases.flavours.R; |
||||
|
import gr.auth.databases.flavours.model.Rating; |
||||
|
|
||||
|
public class RestaurantAdapter extends RecyclerView.Adapter<RestaurantAdapter.RatingViewHolder> { |
||||
|
private Context context; |
||||
|
private Rating[] ratings; |
||||
|
|
||||
|
public RestaurantAdapter(Context context, Rating[] ratings) { |
||||
|
this.context = context; |
||||
|
this.ratings = ratings; |
||||
|
} |
||||
|
|
||||
|
@NonNull |
||||
|
@Override |
||||
|
public RestaurantAdapter.RatingViewHolder onCreateViewHolder(@NonNull ViewGroup parent, |
||||
|
int viewType) { |
||||
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_restaurant_list_row, |
||||
|
parent, false); |
||||
|
return new RatingViewHolder(v); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onBindViewHolder(@NonNull RatingViewHolder holder, int position) { |
||||
|
Log.d("THISSSS", "" + position + ratings[position].getUsername()); |
||||
|
holder.username.setText(ratings[position].getUsername()); |
||||
|
holder.date.setText(ratings[position].getDate()); |
||||
|
|
||||
|
holder.grade.setText(context.getString(R.string.restaurant_row_grade_placeholder, |
||||
|
ratings[position].getGrade())); |
||||
|
|
||||
|
if (ratings[position].getAccessibility() != null) { |
||||
|
holder.accessibility.setVisibility(View.VISIBLE); |
||||
|
holder.accessibility.setText(context.getString(R.string.restaurant_row_accessibility_placeholder, |
||||
|
ratings[position].getAccessibility().toString())); |
||||
|
} else { |
||||
|
holder.accessibility.setVisibility(View.GONE); |
||||
|
} |
||||
|
|
||||
|
holder.text.setText(ratings[position].getText()); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public int getItemCount() { |
||||
|
return ratings.length; |
||||
|
} |
||||
|
|
||||
|
static class RatingViewHolder extends RecyclerView.ViewHolder { |
||||
|
TextView username, date, grade, accessibility, text; |
||||
|
|
||||
|
RatingViewHolder(View v) { |
||||
|
super(v); |
||||
|
username = v.findViewById(R.id.restaurant_row_username); |
||||
|
date = v.findViewById(R.id.restaurant_row_date); |
||||
|
grade = v.findViewById(R.id.restaurant_row_grade); |
||||
|
accessibility = v.findViewById(R.id.restaurant_row_accessibility); |
||||
|
text = v.findViewById(R.id.restaurant_row_text); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,42 @@ |
|||||
|
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; |
||||
|
} |
||||
|
} |
@ -0,0 +1,90 @@ |
|||||
|
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 com.google.android.gms.maps.GoogleMap; |
||||
|
import com.google.android.gms.maps.MapView; |
||||
|
import com.google.android.gms.maps.OnMapReadyCallback; |
||||
|
|
||||
|
import androidx.annotation.NonNull; |
||||
|
import androidx.fragment.app.Fragment; |
||||
|
import gr.auth.databases.flavours.R; |
||||
|
|
||||
|
public class RestaurantMapFragment extends Fragment implements OnMapReadyCallback { |
||||
|
private MapView gMapView = null; |
||||
|
|
||||
|
@Override |
||||
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
||||
|
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_restaurant_map, container, false); |
||||
|
|
||||
|
gMapView = rootView.findViewById(R.id.restaurant_map); |
||||
|
gMapView.getMapAsync(this); |
||||
|
gMapView.onCreate(getArguments()); |
||||
|
|
||||
|
return rootView; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onResume() { |
||||
|
super.onResume(); |
||||
|
|
||||
|
if (gMapView != null) { |
||||
|
gMapView.onResume(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onDestroy() { |
||||
|
super.onDestroy(); |
||||
|
|
||||
|
if (gMapView != null) { |
||||
|
gMapView.onDestroy(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onStart() { |
||||
|
super.onStart(); |
||||
|
|
||||
|
if (gMapView != null) { |
||||
|
gMapView.onStart(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onStop() { |
||||
|
super.onStop(); |
||||
|
|
||||
|
if (gMapView != null) { |
||||
|
gMapView.onStop(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onSaveInstanceState(@NonNull Bundle outState) { |
||||
|
super.onSaveInstanceState(outState); |
||||
|
|
||||
|
if (gMapView != null) { |
||||
|
gMapView.onSaveInstanceState(outState); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Manipulates the map once available. |
||||
|
* This callback is triggered when the map is ready to be used. |
||||
|
* This is where we can add markers or lines, add listeners or move the camera. In this case, |
||||
|
* we just add a marker near Sydney, Australia. |
||||
|
* If Google Play services is not installed on the device, the user will be prompted to install |
||||
|
* it inside the SupportMapFragment. This method will only be triggered once the user has |
||||
|
* installed Google Play services and returned to the app. |
||||
|
*/ |
||||
|
@Override |
||||
|
public void onMapReady(GoogleMap googleMap) { |
||||
|
//googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(grill15, 12.0f));
|
||||
|
} |
||||
|
} |
@ -0,0 +1,39 @@ |
|||||
|
package gr.auth.databases.flavours.model; |
||||
|
|
||||
|
public class Rating { |
||||
|
public enum Accessibility { |
||||
|
EASY, MODERATE, HARD |
||||
|
} |
||||
|
|
||||
|
private int grade; |
||||
|
private String username, text, date; |
||||
|
private Accessibility accessibility; |
||||
|
|
||||
|
public Rating(int grade, String username, String text, String date, Accessibility accessibility) { |
||||
|
this.grade = grade; |
||||
|
this.username = username; |
||||
|
this.text = text; |
||||
|
this.date = date; |
||||
|
this.accessibility = accessibility; |
||||
|
} |
||||
|
|
||||
|
public int getGrade() { |
||||
|
return grade; |
||||
|
} |
||||
|
|
||||
|
public String getUsername() { |
||||
|
return username; |
||||
|
} |
||||
|
|
||||
|
public String getText() { |
||||
|
return text; |
||||
|
} |
||||
|
|
||||
|
public String getDate() { |
||||
|
return date; |
||||
|
} |
||||
|
|
||||
|
public Accessibility getAccessibility() { |
||||
|
return accessibility; |
||||
|
} |
||||
|
} |
@ -0,0 +1,37 @@ |
|||||
|
<?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="wrap_content" |
||||
|
android:layout_marginStart="8dp" |
||||
|
android:layout_marginEnd="8dp" |
||||
|
android:layout_marginBottom="6dp" |
||||
|
android:orientation="vertical"> |
||||
|
|
||||
|
<TextView |
||||
|
android:id="@+id/restaurant_row_username" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_marginBottom="4dp" |
||||
|
android:textStyle="bold" /> |
||||
|
|
||||
|
<TextView |
||||
|
android:id="@+id/restaurant_row_date" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_marginBottom="4dp" /> |
||||
|
|
||||
|
<TextView |
||||
|
android:id="@+id/restaurant_row_grade" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" /> |
||||
|
|
||||
|
<TextView |
||||
|
android:id="@+id/restaurant_row_accessibility" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" /> |
||||
|
|
||||
|
<TextView |
||||
|
android:id="@+id/restaurant_row_text" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" /> |
||||
|
</LinearLayout> |
@ -0,0 +1,10 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<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_recycler" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_marginStart="12dp" |
||||
|
android:layout_marginEnd="12dp" |
||||
|
android:orientation="vertical" |
||||
|
app:layout_behavior="@string/appbar_scrolling_view_behavior" /> |
@ -0,0 +1,5 @@ |
|||||
|
<?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" /> |
@ -1,8 +0,0 @@ |
|||||
<?xml version="1.0" encoding="utf-8"?> |
|
||||
<fragment xmlns:android="http://schemas.android.com/apk/res/android" |
|
||||
xmlns:tools="http://schemas.android.com/tools" |
|
||||
android:id="@+id/map" |
|
||||
android:name="com.google.android.gms.maps.SupportMapFragment" |
|
||||
android:layout_width="match_parent" |
|
||||
android:layout_height="match_parent" |
|
||||
tools:context=".activities.main.MainActivity" /> |
|
@ -0,0 +1,12 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<menu 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" |
||||
|
tools:context=".activities.main.MainActivity"> |
||||
|
<item |
||||
|
android:id="@+id/restaurant_toolbar_menu_map" |
||||
|
android:icon="@drawable/ic_map_black_24dp" |
||||
|
android:orderInCategory="200" |
||||
|
android:title="@string/main_toolbar_menu_map" |
||||
|
app:showAsAction="ifRoom" /> |
||||
|
</menu> |
@ -0,0 +1,11 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<resources> |
||||
|
<string-array name="restaurant_type"> |
||||
|
<item>Cafeteria</item> |
||||
|
<item>Pub</item> |
||||
|
<item>Bar</item> |
||||
|
<item>Restaurant</item> |
||||
|
<item>Fast Food</item> |
||||
|
<item>Ethnic</item> |
||||
|
</string-array> |
||||
|
</resources> |
Loading…
Reference in new issue