Browse Source

Add DietsActivity

master
Apostolos Fanakis 6 years ago
parent
commit
9253375b2f
  1. 1
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/AndroidManifest.xml
  2. 88
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/diets/DietsActivity.java
  3. 56
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/diets/DietsAdapter.java
  4. 28
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/base/BaseActivity.java
  5. 30
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Diet.java
  6. BIN
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-hdpi/ic_add_black_18dp.png
  7. BIN
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-mdpi/ic_add_black_18dp.png
  8. BIN
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xhdpi/ic_add_black_18dp.png
  9. BIN
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xxhdpi/ic_add_black_18dp.png
  10. BIN
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xxxhdpi/ic_add_black_18dp.png
  11. 39
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_diets.xml
  12. 49
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/diets_row.xml
  13. 6
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/strings.xml

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

@ -55,6 +55,7 @@
<activity android:name=".activities.profile.ProfileActivity" /> <activity android:name=".activities.profile.ProfileActivity" />
<activity android:name=".activities.RateRestaurantActivity" /> <activity android:name=".activities.RateRestaurantActivity" />
<activity android:name=".activities.RateItemActivity" /> <activity android:name=".activities.RateItemActivity" />
<activity android:name=".activities.diets.DietsActivity" />
</application> </application>
</manifest> </manifest>

88
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/diets/DietsActivity.java

@ -0,0 +1,88 @@
package gr.auth.databases.flavours.activities.diets;
import android.os.Bundle;
import android.view.View;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.ArrayList;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import gr.auth.databases.flavours.R;
import gr.auth.databases.flavours.base.BaseActivity;
import gr.auth.databases.flavours.model.Diet;
public class DietsActivity extends BaseActivity {
private FloatingActionButton FAB;
private ArrayList<Diet> diets = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_diets);
Toolbar toolbar = findViewById(R.id.diets_toolbar);
toolbar.setTitle(getString(R.string.diets_toolbar_title));
setSupportActionBar(toolbar);
ActionBar actionbar = getSupportActionBar();
if (actionbar != null) {
actionbar.setDisplayHomeAsUpEnabled(true);
actionbar.setHomeAsUpIndicator(R.drawable.ic_menu_black_24dp);
}
createDrawer();
FAB = findViewById(R.id.diets_fab);
FAB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
/*Intent intent = new Intent(view.getContext(), AddRestaurantActivity.class);
startActivity(intent);*/
}
});
RecyclerView recyclerView = findViewById(R.id.diets_list);
recyclerView.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
diets.add(new Diet(1, "Μόνο κρέας", "Τρώς πολύ κρέας.", false));
diets.add(new Diet(2, "Σχεδόν μόνο κρέας", "Τρώς αρκετό κρέας.", true));
DietsAdapter dietsAdapter = new DietsAdapter(diets);
recyclerView.setAdapter(dietsAdapter);
}
@Override
public void onBackPressed() {
if (drawer.isDrawerOpen()) {
drawer.closeDrawer();
} else {
super.onBackPressed();
}
}
/*@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) {
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);
}*/
}

56
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/diets/DietsAdapter.java

@ -0,0 +1,56 @@
package gr.auth.databases.flavours.activities.diets;
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.appcompat.widget.AppCompatImageButton;
import androidx.recyclerview.widget.RecyclerView;
import gr.auth.databases.flavours.R;
import gr.auth.databases.flavours.model.Diet;
public class DietsAdapter extends RecyclerView.Adapter<DietsAdapter.DietViewHolder> {
private ArrayList<Diet> diets;
DietsAdapter(ArrayList<Diet> diets) {
this.diets = diets;
}
@NonNull
@Override
public DietsAdapter.DietViewHolder onCreateViewHolder(@NonNull ViewGroup parent,
int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.diets_row, parent, false);
return new DietViewHolder(v);
}
@Override
public void onBindViewHolder(@NonNull DietViewHolder holder, int position) {
holder.name.setText(diets.get(position).getName());
holder.description.setText(diets.get(position).getDescription());
if (diets.get(position).isFollowedByUser()) {
holder.addDietButton.setImageResource(R.drawable.ic_delete_black_18dp);
}
}
@Override
public int getItemCount() {
return diets.size();
}
static class DietViewHolder extends RecyclerView.ViewHolder {
TextView name, description;
AppCompatImageButton addDietButton;
DietViewHolder(View v) {
super(v);
name = v.findViewById(R.id.diets_diet_name);
description = v.findViewById(R.id.diets_diet_description);
addDietButton = v.findViewById(R.id.diets_diet_subscribe);
}
}
}

28
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/base/BaseActivity.java

@ -26,6 +26,7 @@ import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import gr.auth.databases.flavours.R; import gr.auth.databases.flavours.R;
import gr.auth.databases.flavours.activities.diets.DietsActivity;
import gr.auth.databases.flavours.activities.LoginActivity; import gr.auth.databases.flavours.activities.LoginActivity;
import gr.auth.databases.flavours.activities.main.MainActivity; import gr.auth.databases.flavours.activities.main.MainActivity;
import gr.auth.databases.flavours.activities.profile.ProfileActivity; import gr.auth.databases.flavours.activities.profile.ProfileActivity;
@ -93,6 +94,7 @@ public abstract class BaseActivity extends AppCompatActivity {
//------------------------------------------DRAWER STUFF---------------------------------------- //------------------------------------------DRAWER STUFF----------------------------------------
protected static final int HOME_ID = 0; protected static final int HOME_ID = 0;
protected static final int DIETS_ID = 1;
protected static final int LOG_ID = 4; protected static final int LOG_ID = 4;
private AccountHeader accountHeader; private AccountHeader accountHeader;
@ -104,8 +106,8 @@ public abstract class BaseActivity extends AppCompatActivity {
final int selectedPrimaryColor = ContextCompat.getColor(this, R.color.primary_dark); final int selectedPrimaryColor = ContextCompat.getColor(this, R.color.primary_dark);
final int selectedSecondaryColor = ContextCompat.getColor(this, R.color.iron); final int selectedSecondaryColor = ContextCompat.getColor(this, R.color.iron);
PrimaryDrawerItem homeItem; PrimaryDrawerItem homeItem, dietsItem;
IconicsDrawable homeIcon, homeIconSelected; IconicsDrawable homeIcon, homeIconSelected, dietsIcon, dietsIconSelected;
//Drawer Icons //Drawer Icons
homeIcon = new IconicsDrawable(this) homeIcon = new IconicsDrawable(this)
@ -116,6 +118,14 @@ public abstract class BaseActivity extends AppCompatActivity {
.icon(GoogleMaterial.Icon.gmd_home) .icon(GoogleMaterial.Icon.gmd_home)
.color(selectedSecondaryColor); .color(selectedSecondaryColor);
dietsIcon = new IconicsDrawable(this)
.icon(GoogleMaterial.Icon.gmd_donut_small)
.color(primaryColor);
dietsIconSelected = new IconicsDrawable(this)
.icon(GoogleMaterial.Icon.gmd_donut_small)
.color(selectedSecondaryColor);
IconicsDrawable loginIcon = new IconicsDrawable(this) IconicsDrawable loginIcon = new IconicsDrawable(this)
.icon(FontAwesome.Icon.faw_sign_in) .icon(FontAwesome.Icon.faw_sign_in)
.color(primaryColor); .color(primaryColor);
@ -134,6 +144,15 @@ public abstract class BaseActivity extends AppCompatActivity {
.withIcon(homeIcon) .withIcon(homeIcon)
.withSelectedIcon(homeIconSelected); .withSelectedIcon(homeIconSelected);
dietsItem = new PrimaryDrawerItem()
.withTextColor(primaryColor)
.withSelectedColor(selectedPrimaryColor)
.withSelectedTextColor(selectedSecondaryColor)
.withIdentifier(DIETS_ID)
.withName(R.string.drawer_diets)
.withIcon(dietsIcon)
.withSelectedIcon(dietsIconSelected);
if (sessionManager.isLoggedIn()) { if (sessionManager.isLoggedIn()) {
loginLogoutItem = new PrimaryDrawerItem() loginLogoutItem = new PrimaryDrawerItem()
.withTextColor(primaryColor) .withTextColor(primaryColor)
@ -195,6 +214,9 @@ public abstract class BaseActivity extends AppCompatActivity {
Intent intent = new Intent(BaseActivity.this, MainActivity.class); Intent intent = new Intent(BaseActivity.this, MainActivity.class);
startActivity(intent); startActivity(intent);
} }
} else if (drawerItem.equals(DIETS_ID)) {
Intent intent = new Intent(BaseActivity.this, DietsActivity.class);
startActivity(intent);
} else if (drawerItem.equals(LOG_ID)) { } else if (drawerItem.equals(LOG_ID)) {
if (!sessionManager.isLoggedIn()) //When logged out or if user is guest if (!sessionManager.isLoggedIn()) //When logged out or if user is guest
startLoginActivity(); startLoginActivity();
@ -207,7 +229,7 @@ public abstract class BaseActivity extends AppCompatActivity {
} }
}); });
drawerBuilder.addDrawerItems(homeItem, loginLogoutItem); drawerBuilder.addDrawerItems(homeItem, dietsItem, loginLogoutItem);
drawer = drawerBuilder.build(); drawer = drawerBuilder.build();
/*if (!isMainActivity) /*if (!isMainActivity)

30
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Diet.java

@ -0,0 +1,30 @@
package gr.auth.databases.flavours.model;
public class Diet {
private int id;
private String name, description;
private boolean isFollowedByUser;
public Diet(int id, String name, String description, boolean isFollowedByUser) {
this.id = id;
this.name = name;
this.description = description;
this.isFollowedByUser = isFollowedByUser;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public boolean isFollowedByUser() {
return isFollowedByUser;
}
}

BIN
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-hdpi/ic_add_black_18dp.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 B

BIN
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-mdpi/ic_add_black_18dp.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 B

BIN
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xhdpi/ic_add_black_18dp.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B

BIN
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xxhdpi/ic_add_black_18dp.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 B

BIN
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xxxhdpi/ic_add_black_18dp.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B

39
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_diets.xml

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/diets_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Theme.AppCompat.Light">
<androidx.appcompat.widget.Toolbar
android:id="@+id/diets_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/Theme.AppCompat.Light"
app:title="@string/diets_toolbar_title" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/diets_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/diets_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:src="@drawable/ic_add_white_24dp"
app:fabSize="normal"
app:layout_behavior="gr.auth.databases.flavours.utils.ScrollAwareFABBehavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

49
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/diets_row.xml

@ -0,0 +1,49 @@
<?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/diets_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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="4dp"
android:paddingTop="6dp"
android:paddingEnd="4dp"
android:paddingBottom="6dp">
<TextView
android:id="@+id/diets_diet_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:text="@string/diet_name"
android:textStyle="bold" />
<TextView
android:id="@+id/diets_diet_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:text="@string/diet_description" />
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/diets_diet_subscribe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:src="@drawable/ic_add_black_18dp" />
</LinearLayout>
</androidx.cardview.widget.CardView>

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

@ -20,6 +20,7 @@
<!-- Drawer --> <!-- Drawer -->
<string name="drawer_home">Home</string> <string name="drawer_home">Home</string>
<string name="drawer_diets">Diets</string>
<string name="drawer_logout">Logout</string> <string name="drawer_logout">Logout</string>
<string name="drawer_login">Login</string> <string name="drawer_login">Login</string>
@ -86,6 +87,11 @@
<string name="profile_owns_restaurant_placeholder">Owns the restaurant: %1$s</string> <string name="profile_owns_restaurant_placeholder">Owns the restaurant: %1$s</string>
<string name="profile_diet_list_title">Diets:</string> <string name="profile_diet_list_title">Diets:</string>
<!-- Diets -->
<string name="diets_toolbar_title">Diets</string>
<string name="diet_name">Diet name</string>
<string name="diet_description">Diet description</string>
<!-- Ingredient --> <!-- Ingredient -->
<string name="ingredient_name">Ingredient name</string> <string name="ingredient_name">Ingredient name</string>
<string name="ingredient_has_alcohol">Ingredient contains alcohol</string> <string name="ingredient_has_alcohol">Ingredient contains alcohol</string>

Loading…
Cancel
Save