Apostolos Fanakis
6 years ago
21 changed files with 546 additions and 36 deletions
@ -0,0 +1,156 @@ |
|||||
|
package gr.auth.databases.flavours.main; |
||||
|
|
||||
|
import android.os.Bundle; |
||||
|
import android.view.Menu; |
||||
|
import android.view.MenuItem; |
||||
|
import android.view.View; |
||||
|
import android.view.animation.AccelerateInterpolator; |
||||
|
import android.view.animation.AlphaAnimation; |
||||
|
import android.view.animation.Animation; |
||||
|
import android.view.animation.DecelerateInterpolator; |
||||
|
|
||||
|
|
||||
|
import androidx.annotation.NonNull; |
||||
|
import androidx.appcompat.app.AppCompatActivity; |
||||
|
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.main.fragments.MainListFragment; |
||||
|
import gr.auth.databases.flavours.main.fragments.MainMapFragment; |
||||
|
|
||||
|
public class MainActivity extends AppCompatActivity { |
||||
|
private static final int NUM_PAGES = 2; |
||||
|
private ViewPager viewPager; |
||||
|
private MenuItem menuMapItem; |
||||
|
|
||||
|
@Override |
||||
|
protected void onCreate(Bundle savedInstanceState) { |
||||
|
super.onCreate(savedInstanceState); |
||||
|
setContentView(R.layout.activity_main); |
||||
|
|
||||
|
Toolbar toolbar = findViewById(R.id.main_toolbar); |
||||
|
toolbar.setTitle("Restaurants"); |
||||
|
setSupportActionBar(toolbar); |
||||
|
|
||||
|
final Animation fadeIn = new AlphaAnimation(0, 1); |
||||
|
fadeIn.setInterpolator(new DecelerateInterpolator()); |
||||
|
fadeIn.setDuration(700); |
||||
|
fadeIn.setAnimationListener(new Animation.AnimationListener() { |
||||
|
@Override |
||||
|
public void onAnimationStart(Animation animation) { |
||||
|
menuMapItem.setVisible(true); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onAnimationRepeat(Animation animation) { |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onAnimationEnd(Animation animation) { |
||||
|
menuMapItem.setVisible(true); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
final Animation fadeOut = new AlphaAnimation(1, 0); |
||||
|
fadeOut.setInterpolator(new AccelerateInterpolator()); |
||||
|
fadeOut.setStartOffset(100); |
||||
|
fadeOut.setDuration(700); |
||||
|
fadeOut.setAnimationListener(new Animation.AnimationListener() { |
||||
|
@Override |
||||
|
public void onAnimationStart(Animation animation) { |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onAnimationRepeat(Animation animation) { |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onAnimationEnd(Animation animation) { |
||||
|
menuMapItem.setVisible(false); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
viewPager = findViewById(R.id.main_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.setVisible(true); |
||||
|
menuMapItem.getActionView().startAnimation(fadeIn); |
||||
|
} else { |
||||
|
menuMapItem.getActionView().startAnimation(fadeOut); |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
PagerAdapter pagerAdapter = new MainPagerAdapter(getSupportFragmentManager()); |
||||
|
viewPager.setAdapter(pagerAdapter); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onBackPressed() { |
||||
|
if (viewPager.getCurrentItem() == 0) { |
||||
|
super.onBackPressed(); |
||||
|
} else { |
||||
|
viewPager.setCurrentItem(0); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean onCreateOptionsMenu(Menu menu) { |
||||
|
getMenuInflater().inflate(R.menu.main_tollbar_menu, menu); |
||||
|
menuMapItem = menu.findItem(R.id.main_toolbar_menu_map); |
||||
|
|
||||
|
View view = getLayoutInflater().inflate(R.layout.menu_item_main_map, null); |
||||
|
menuMapItem.setActionView(view); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean onOptionsItemSelected(MenuItem item) { |
||||
|
int id = item.getItemId(); |
||||
|
|
||||
|
if (id == R.id.main_toolbar_menu_filter) { |
||||
|
return true; |
||||
|
} else if (id == R.id.main_toolbar_menu_map) { |
||||
|
viewPager.setCurrentItem(1); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
return super.onOptionsItemSelected(item); |
||||
|
} |
||||
|
|
||||
|
private class MainPagerAdapter extends FragmentStatePagerAdapter { |
||||
|
MainPagerAdapter(FragmentManager fm) { |
||||
|
super(fm); |
||||
|
} |
||||
|
|
||||
|
@NonNull |
||||
|
@Override |
||||
|
public Fragment getItem(int position) { |
||||
|
if (position == 0) { |
||||
|
return new MainListFragment(); |
||||
|
} else { |
||||
|
return new MainMapFragment(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public int getCount() { |
||||
|
return NUM_PAGES; |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,83 @@ |
|||||
|
package gr.auth.databases.flavours.main; |
||||
|
|
||||
|
import android.content.Context; |
||||
|
import android.view.LayoutInflater; |
||||
|
import android.view.View; |
||||
|
import android.view.ViewGroup; |
||||
|
import android.widget.ImageView; |
||||
|
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.Restaurant; |
||||
|
|
||||
|
public class MainAdapter extends RecyclerView.Adapter<MainAdapter.RestaurantViewHolder> { |
||||
|
private Context context; |
||||
|
private Restaurant[] restaurants; |
||||
|
|
||||
|
public MainAdapter(Context context, Restaurant[] restaurants) { |
||||
|
this.context = context; |
||||
|
this.restaurants = restaurants; |
||||
|
} |
||||
|
|
||||
|
@NonNull |
||||
|
@Override |
||||
|
public MainAdapter.RestaurantViewHolder onCreateViewHolder(@NonNull ViewGroup parent, |
||||
|
int viewType) { |
||||
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_main_list_row, |
||||
|
parent, false); |
||||
|
return new RestaurantViewHolder(v); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onBindViewHolder(@NonNull RestaurantViewHolder holder, int position) { |
||||
|
holder.name.setText(restaurants[position].getName()); |
||||
|
holder.workingHours.setText(context.getString(R.string.main_row_working_hours_placeholder, |
||||
|
restaurants[position].getOpeningTime().substring(0,5), |
||||
|
restaurants[position].getClosingTime().substring(0,5))); |
||||
|
|
||||
|
if (restaurants[position].getType().equals("restaurant")) { |
||||
|
holder.typeImage.setImageResource(R.drawable.restaurant_marker); |
||||
|
holder.typeText.setText(context.getResources().getString(R.string.main_restaurant_type)); |
||||
|
} |
||||
|
if (restaurants[position].getType().equals("bar")) { |
||||
|
holder.typeImage.setImageResource(R.drawable.bar_marker); |
||||
|
holder.typeText.setText(context.getResources().getString(R.string.main_bar_type)); |
||||
|
} |
||||
|
if (restaurants[position].getType().equals("cafeteria")) { |
||||
|
holder.typeImage.setImageResource(R.drawable.cafeteria_marker); |
||||
|
holder.typeText.setText(context.getResources().getString(R.string.main_cafeteria_type)); |
||||
|
} |
||||
|
if (restaurants[position].getType().equals("pub")) { |
||||
|
holder.typeImage.setImageResource(R.drawable.pub_marker); |
||||
|
holder.typeText.setText(context.getResources().getString(R.string.main_pub_type)); |
||||
|
} |
||||
|
if (restaurants[position].getType().equals("fast_food")) { |
||||
|
holder.typeImage.setImageResource(R.drawable.fast_food_marker); |
||||
|
holder.typeText.setText(context.getResources().getString(R.string.main_fast_food_type)); |
||||
|
} |
||||
|
if (restaurants[position].getType().equals("ethnic")) { |
||||
|
holder.typeImage.setImageResource(R.drawable.restaurant_marker); |
||||
|
holder.typeText.setText(context.getResources().getString(R.string.main_ethnic_type)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public int getItemCount() { |
||||
|
return restaurants.length; |
||||
|
} |
||||
|
|
||||
|
static class RestaurantViewHolder extends RecyclerView.ViewHolder { |
||||
|
TextView name, typeText, workingHours; |
||||
|
ImageView typeImage; |
||||
|
|
||||
|
RestaurantViewHolder(View v) { |
||||
|
super(v); |
||||
|
name = v.findViewById(R.id.main_row_name); |
||||
|
typeText = v.findViewById(R.id.main_row_type_txt); |
||||
|
workingHours = v.findViewById(R.id.main_row_working_hours); |
||||
|
typeImage = v.findViewById(R.id.main_row_type_img); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,47 @@ |
|||||
|
package gr.auth.databases.flavours.main.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.main.MainAdapter; |
||||
|
import gr.auth.databases.flavours.model.Restaurant; |
||||
|
|
||||
|
public class MainListFragment extends Fragment { |
||||
|
private Restaurant[] restaurants = new Restaurant[13]; |
||||
|
|
||||
|
@Override |
||||
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
||||
|
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_main_list, container, false); |
||||
|
|
||||
|
RecyclerView recyclerView = rootView.findViewById(R.id.main_recycler); |
||||
|
recyclerView.setHasFixedSize(true); |
||||
|
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); |
||||
|
recyclerView.setLayoutManager(layoutManager); |
||||
|
|
||||
|
restaurants[0] = new Restaurant("U Fleků", "pub", "18:00:00", "04:00:00"); |
||||
|
restaurants[1] = new Restaurant("Σ σύγχρονα εστιατόρια", "restaurant", "12:00:00", "22:00:00"); |
||||
|
restaurants[2] = new Restaurant("U Fleků Garden", "pub", "18:00:00", "02:00:00"); |
||||
|
restaurants[3] = new Restaurant("McDonald\'s", "fast_food", "12:00:00", "23:59:00"); |
||||
|
restaurants[4] = new Restaurant("Grill 15", "fast_food", "12:00:00", "01:30:00"); |
||||
|
restaurants[5] = new Restaurant("Butterflies and Hurricanes", "cafeteria", "08:00:00", "20:00:00"); |
||||
|
restaurants[6] = new Restaurant("The Hoppy Pub", "pub", "17:30:00", "01:30:00"); |
||||
|
restaurants[7] = new Restaurant("Belleville sin patron", "bar", "12:00:00", "02:00:00"); |
||||
|
restaurants[8] = new Restaurant("Αιθερόπλοο", "pub", "08:00:00", "02:00:00"); |
||||
|
restaurants[9] = new Restaurant("Οδυσσέας", "restaurant", "12:30:00", "18:00:00"); |
||||
|
restaurants[10] = new Restaurant("Pulp", "bar", "09:00:00", "23:59:00"); |
||||
|
restaurants[11] = new Restaurant("McDonald\'s", "fast_food", "12:00:00", "23:59:00"); |
||||
|
restaurants[12] = new Restaurant("Γιαννούλα", "restaurant", "13:30:00", "01:00:00"); |
||||
|
|
||||
|
MainAdapter mainAdapter = new MainAdapter(getContext(), restaurants); |
||||
|
recyclerView.setAdapter(mainAdapter); |
||||
|
|
||||
|
return rootView; |
||||
|
} |
||||
|
} |
@ -0,0 +1,28 @@ |
|||||
|
package gr.auth.databases.flavours.model; |
||||
|
|
||||
|
public class Restaurant { |
||||
|
private final String name, type, openingTime, closingTime; |
||||
|
|
||||
|
public Restaurant(String name, String type, String openingTime, String closingTime) { |
||||
|
this.name = name; |
||||
|
this.type= type; |
||||
|
this.openingTime = openingTime; |
||||
|
this.closingTime = closingTime; |
||||
|
} |
||||
|
|
||||
|
public String getName() { |
||||
|
return name; |
||||
|
} |
||||
|
|
||||
|
public String getType() { |
||||
|
return type; |
||||
|
} |
||||
|
|
||||
|
public String getOpeningTime() { |
||||
|
return openingTime; |
||||
|
} |
||||
|
|
||||
|
public String getClosingTime() { |
||||
|
return closingTime; |
||||
|
} |
||||
|
} |
After Width: | Height: | Size: 118 B |
After Width: | Height: | Size: 97 B |
After Width: | Height: | Size: 115 B |
After Width: | Height: | Size: 134 B |
After Width: | Height: | Size: 163 B |
@ -1,9 +1,36 @@ |
|||||
<?xml version="1.0" encoding="utf-8"?> |
<?xml version="1.0" encoding="utf-8"?> |
||||
<fragment xmlns:android="http://schemas.android.com/apk/res/android" |
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:map="http://schemas.android.com/apk/res-auto" |
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
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_width="match_parent" |
||||
android:layout_height="match_parent" |
android:layout_height="match_parent" |
||||
tools:context=".MainActivity" /> |
android:background="@android:color/background_light" |
||||
|
android:fitsSystemWindows="true"> |
||||
|
|
||||
|
<com.google.android.material.appbar.AppBarLayout |
||||
|
android:id="@+id/main_appbar" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:theme="@style/Theme.AppCompat.Light"> |
||||
|
|
||||
|
<androidx.appcompat.widget.Toolbar |
||||
|
android:id="@+id/main_toolbar" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="?attr/actionBarSize" |
||||
|
android:background="?attr/colorPrimary" |
||||
|
app:popupTheme="@style/Theme.AppCompat.Light" /> |
||||
|
</com.google.android.material.appbar.AppBarLayout> |
||||
|
|
||||
|
<androidx.viewpager.widget.ViewPager |
||||
|
android:id="@+id/main_pager" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="match_parent" |
||||
|
app:layout_anchor="@id/main_appbar" |
||||
|
app:layout_anchorGravity="bottom|start" |
||||
|
app:layout_behavior="@string/appbar_scrolling_view_behavior" /> |
||||
|
|
||||
|
<com.google.android.material.floatingactionbutton.FloatingActionButton |
||||
|
android:layout_width="wrap_content" |
||||
|
android:layout_height="wrap_content" |
||||
|
app:layout_anchor="@id/main_appbar" |
||||
|
app:layout_anchorGravity="bottom|right|end" /> |
||||
|
</androidx.coordinatorlayout.widget.CoordinatorLayout> |
@ -0,0 +1,57 @@ |
|||||
|
<?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:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_gravity="center" |
||||
|
android:foreground="?android:attr/selectableItemBackground" |
||||
|
card_view:cardCornerRadius="5dp" |
||||
|
card_view:cardElevation="1dp" |
||||
|
card_view:cardPreventCornerOverlap="false" |
||||
|
card_view:cardUseCompatPadding="true"> |
||||
|
|
||||
|
<LinearLayout |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:orientation="horizontal" |
||||
|
android:paddingStart="2dp" |
||||
|
android:paddingTop="6dp" |
||||
|
android:paddingEnd="4dp" |
||||
|
android:paddingBottom="6dp"> |
||||
|
|
||||
|
<ImageView |
||||
|
android:id="@+id/main_row_type_img" |
||||
|
android:layout_width="wrap_content" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:contentDescription="@string/main_row_type" /> |
||||
|
|
||||
|
<LinearLayout |
||||
|
android:layout_width="0dp" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_marginStart="4dp" |
||||
|
android:layout_weight="0.5" |
||||
|
android:orientation="vertical"> |
||||
|
|
||||
|
<TextView |
||||
|
android:id="@+id/main_row_name" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:ellipsize="end" |
||||
|
android:text="@string/main_row_name" |
||||
|
android:textStyle="bold" /> |
||||
|
|
||||
|
<TextView |
||||
|
android:id="@+id/main_row_working_hours" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:text="@string/main_row_working_hours" /> |
||||
|
</LinearLayout> |
||||
|
|
||||
|
<TextView |
||||
|
android:id="@+id/main_row_type_txt" |
||||
|
android:layout_width="wrap_content" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:contentDescription="@string/main_row_type" |
||||
|
android:textColor="@color/colorAccent" /> |
||||
|
</LinearLayout> |
||||
|
</androidx.cardview.widget.CardView> |
@ -0,0 +1,8 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" |
||||
|
android:id="@+id/main_recycler" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_marginStart="12dp" |
||||
|
android:layout_marginEnd="12dp" |
||||
|
android:orientation="vertical" /> |
@ -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/main_map" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="match_parent" /> |
@ -0,0 +1,8 @@ |
|||||
|
<?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=".main.MainActivity" /> |
@ -0,0 +1,6 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<androidx.appcompat.widget.AppCompatImageButton xmlns:android="http://schemas.android.com/apk/res/android" |
||||
|
android:layout_width="wrap_content" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:contentDescription="@string/main_toolbar_menu_map" |
||||
|
android:src="@drawable/ic_map_black_24dp" /> |
@ -0,0 +1,19 @@ |
|||||
|
<?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=".main.MainActivity"> |
||||
|
<item |
||||
|
android:id="@+id/main_toolbar_menu_filter" |
||||
|
android:icon="@drawable/ic_filter_list_black_24dp" |
||||
|
android:orderInCategory="100" |
||||
|
android:title="@string/main_toolbar_menu_filter" |
||||
|
app:showAsAction="ifRoom" /> |
||||
|
<item |
||||
|
android:id="@+id/main_toolbar_menu_map" |
||||
|
android:icon="@drawable/ic_map_black_24dp" |
||||
|
android:orderInCategory="200" |
||||
|
android:title="@string/main_toolbar_menu_map" |
||||
|
app:actionViewClass="androidx.appcompat.widget.AppCompatImageButton" |
||||
|
app:showAsAction="ifRoom" /> |
||||
|
</menu> |
Loading…
Reference in new issue