Skip to content

Commit

Permalink
Merge pull request #2 from MenuFinder/development
Browse files Browse the repository at this point in the history
Sprint 1
  • Loading branch information
sanchezfauste authored Nov 14, 2016
2 parents b7e6183 + 9cbb329 commit 94b52b1
Show file tree
Hide file tree
Showing 64 changed files with 1,695 additions and 126 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ android {
minSdkVersion 16
targetSdkVersion 25
versionCode 1
multiDexEnabled true
versionName "1.0"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -28,5 +29,6 @@ dependencies {
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.0.0'
compile 'com.android.support:cardview-v7:25.0.0'
compile 'com.google.android.gms:play-services:9.8.0'
testCompile 'junit:junit:4.12'
}
3 changes: 3 additions & 0 deletions app/src/debug/res/values/google_maps_api.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AIzaSyCT3geBi-P4CbjxQv0BxhXVoBy2GIbJ8rY</string>
</resources>
19 changes: 18 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cat.udl.menufinder">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
android:name=".application.MasterApplication"
android:allowBackup="true"
Expand All @@ -16,19 +18,34 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".activities.LoginActivity"
android:label="@string/title_activity_login" />

<activity
android:name=".activities.HomeActivity"
android:label="@string/title_activity_home"
android:parentActivityName=".application.MasterActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="cat.udl.menufinder.application.MasterActivity" />
</activity>

<activity android:name=".activities.RegisterActivity" />

<activity
android:name=".activities.DetailRestaurantActivity"
android:theme="@style/AppTheme.NoActionBar" />

<activity android:name=".activities.DetailMenuActivity" />

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />

<activity android:name=".activities.ReviewActivity" />

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cat.udl.menufinder.activities;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;

import cat.udl.menufinder.R;
import cat.udl.menufinder.application.MasterActivity;
import cat.udl.menufinder.fragments.DetailMenuFragment;
import cat.udl.menufinder.models.Menu;

import static cat.udl.menufinder.utils.Constants.KEY_MENU;

public class DetailMenuActivity extends MasterActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail_menu);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Intent intent = getIntent();
Menu menu = (Menu) intent.getSerializableExtra(KEY_MENU);
DetailMenuFragment fragment = (DetailMenuFragment) getFragmentManager().findFragmentById(R.id.detail_fragment);
fragment.update(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
break;
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cat.udl.menufinder.activities;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;

import cat.udl.menufinder.R;
import cat.udl.menufinder.application.MasterActivity;
import cat.udl.menufinder.fragments.DetailRestaurantFragment;
import cat.udl.menufinder.models.Restaurant;

import static cat.udl.menufinder.utils.Constants.KEY_RESTAURANT;

public class DetailRestaurantActivity extends MasterActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail_restaurant);
Intent intent = getIntent();
Restaurant restaurant = (Restaurant) intent.getSerializableExtra(KEY_RESTAURANT);
DetailRestaurantFragment fragment = (DetailRestaurantFragment) getFragmentManager().findFragmentById(R.id.detail_fragment);
fragment.update(restaurant);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
break;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,28 @@
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.TextView;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import cat.udl.menufinder.R;
import cat.udl.menufinder.application.MasterActivity;
import cat.udl.menufinder.fragments.ManageItemsFragment;
import cat.udl.menufinder.fragments.ManageMenusFragment;
import cat.udl.menufinder.fragments.PreferencesFragment;
import cat.udl.menufinder.fragments.RestaurantsFragment;

import static cat.udl.menufinder.enums.UserType.CLIENT;
import static cat.udl.menufinder.enums.UserType.GUEST;
import static cat.udl.menufinder.enums.UserType.RESTAURANT;

public class HomeActivity extends MasterActivity
implements NavigationView.OnNavigationItemSelectedListener {
implements NavigationView.OnNavigationItemSelectedListener, OnMapReadyCallback {
Toolbar toolbar;

@Override
Expand All @@ -46,6 +55,11 @@ else if (getMasterApplication().getUserType() == GUEST)
navigationView.inflateMenu(R.menu.activity_home_drawer_guest);
navigationView.setNavigationItemSelectedListener(this);

if (getMasterApplication().getUserType() != GUEST) {
TextView view = (TextView)navigationView.getHeaderView(0).findViewById(R.id.nav_username);
view.setText(getMasterApplication().getUsername());
}

navigate(navigationView.getMenu().getItem(0).getItemId());
}

Expand Down Expand Up @@ -78,6 +92,14 @@ private void navigate(int id) {
} else if (id == R.id.view_restaurants) {
toolbar.setTitle(R.string.action_view_restaurants);
loadFragment(itemId, new RestaurantsFragment());
} else if (id == R.id.view_map) {
toolbar.setTitle(R.string.view_on_map);
MapFragment mapFragment = MapFragment.newInstance();
mapFragment.getMapAsync(this);
loadFragment(itemId, mapFragment);
} else if (id == R.id.settings) {
toolbar.setTitle(R.string.action_settings);
loadFragment(itemId, new PreferencesFragment());
} else if (id == R.id.logout) {
getMasterApplication().logout();
startActivity(new Intent(HomeActivity.this, SplashActivity.class));
Expand All @@ -90,4 +112,11 @@ private void navigate(int id) {
finish();
}
}

@Override
public void onMapReady(GoogleMap googleMap) {
LatLng lleida = new LatLng(41.6175899, 0.6200145999999904);
googleMap.addMarker(new MarkerOptions().position(lleida).title("Marker in Lleida"));
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(lleida, 15));
}
}
103 changes: 103 additions & 0 deletions app/src/main/java/cat/udl/menufinder/activities/ReviewActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package cat.udl.menufinder.activities;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import java.util.List;

import cat.udl.menufinder.R;
import cat.udl.menufinder.adapters.ReviewAdapter;
import cat.udl.menufinder.application.MasterActivity;
import cat.udl.menufinder.models.Item;
import cat.udl.menufinder.models.Review;

import static cat.udl.menufinder.utils.Constants.KEY_ITEM;

public class ReviewActivity extends MasterActivity {

ReviewAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_review);
Item item = (Item) getIntent().getSerializableExtra(KEY_ITEM);
((TextView) findViewById(R.id.name)).setText(item.getName());
((TextView) findViewById(R.id.description)).setText(item.getDescription());
configList(item.getReviews());
configFAB(item);
}

private void configList(List<Review> reviews) {
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
RecyclerView.ItemDecoration itemDecoration = new DividerItemDecoration(
ReviewActivity.this, DividerItemDecoration.VERTICAL);
recyclerView.addItemDecoration(itemDecoration);
adapter = new ReviewAdapter(ReviewActivity.this, reviews);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(ReviewActivity.this));
}

private void configFAB(final Item item) {
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.add_item_button);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showAddDialog(item);
}
});
}

private void showAddDialog(Item item) {
LayoutInflater inflater = getLayoutInflater();
final View dialogView = inflater.inflate(R.layout.view_review, null);
final AlertDialog alertDialog = new AlertDialog.Builder(ReviewActivity.this)
.setTitle(item.getName())
.setIcon(R.drawable.menu_finder_logo)
.setView(dialogView)
.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
})
.create();

alertDialog.show();
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean closeDialog = true;
String review = ((EditText) dialogView.findViewById(R.id.review)).getText().toString();
if (TextUtils.isEmpty(review)) {
closeDialog = false;
}

if (closeDialog) {
alertDialog.dismiss();
saveToDB(new Review(review));
}
}
});
}

private void saveToDB(Review review) {
adapter.addReview(review);
showToast(getString(R.string.review_added));
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cat.udl.menufinder.activities;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.ActivityOptionsCompat;
Expand Down Expand Up @@ -32,8 +33,13 @@ public void run() {
break;
}
} else {
ActivityOptionsCompat activityOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(SplashActivity.this, logo, getString(R.string.shared_logo));
startActivity(new Intent(SplashActivity.this, LoginActivity.class), activityOptionsCompat.toBundle());
Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
if (Build.VERSION.SDK_INT >= 21) {
ActivityOptionsCompat activityOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(SplashActivity.this, logo, getString(R.string.shared_logo));
startActivity(intent, activityOptionsCompat.toBundle());
} else {
startActivity(intent);
}
finish();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,25 @@
import java.util.List;

import cat.udl.menufinder.R;
import cat.udl.menufinder.enums.UserType;
import cat.udl.menufinder.fragments.ManageMenusFragment;
import cat.udl.menufinder.models.Menu;

import static android.view.View.GONE;
import static cat.udl.menufinder.enums.UserType.RESTAURANT;

public class MenusAdapter extends RecyclerView.Adapter<MenusAdapter.ViewHolder> {

private final UserType userType;
private Context context;
private List<Menu> menus;
private ManageMenusFragment.OnMenuClickListener listener;

public MenusAdapter(Context context, List<Menu> menus, ManageMenusFragment.OnMenuClickListener listener) {
public MenusAdapter(Context context, List<Menu> menus, ManageMenusFragment.OnMenuClickListener listener, UserType userType) {
this.context = context;
this.menus = menus;
this.listener = listener;
this.userType = userType;
}

@Override
Expand All @@ -39,6 +45,7 @@ public void onBindViewHolder(MenusAdapter.ViewHolder holder, final int position)
Menu menu = getMenu(position);
holder.name.setText(menu.getName());
holder.price.setText(String.valueOf(menu.getPrice()));
if (userType != RESTAURANT) holder.is_visible.setVisibility(GONE);
holder.is_visible.setChecked(menu.isVisible());
holder.is_visible.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
Expand Down
Loading

0 comments on commit 94b52b1

Please sign in to comment.