Apostolos Fanakis
6 years ago
13 changed files with 302 additions and 11 deletions
@ -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); |
|||
}*/ |
|||
} |
@ -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); |
|||
} |
|||
} |
|||
} |
@ -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; |
|||
} |
|||
} |
After Width: | Height: | Size: 130 B |
After Width: | Height: | Size: 99 B |
After Width: | Height: | Size: 145 B |
After Width: | Height: | Size: 171 B |
After Width: | Height: | Size: 156 B |
@ -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> |
@ -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> |
Loading…
Reference in new issue