Food Recipe App Project PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 42

Main Activity:

JAVA CODE:
package com.example.pakfoodrecipe;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.core.view.GravityCompat;
import androidx.appcompat.app.ActionBarDrawerToggle;
import android.view.MenuItem;
import com.google.android.material.navigation.NavigationView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.Menu;
import android.widget.EditText;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {

private RecyclerView m_recyclerView;


private List<RecipeData> myRecipeList;
private DatabaseReference databaseReference;
private ProgressDialog progressDialog;
private MyAdapter myAdapter;
private EditText txt_Search;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
m_recyclerView = findViewById(R.id.recyclerview);
txt_Search = findViewById(R.id.edt_search);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
View headerView = navigationView.getHeaderView(0);
TextView navEmail = headerView.findViewById(R.id.textViewEmail);
TextView navUsername = headerView.findViewById(R.id.textviewhead);
String email = FirebaseAuth.getInstance().getCurrentUser().getEmail();
String name = FirebaseAuth.getInstance().getCurrentUser().getDisplayName();
navEmail.setText(email);
navUsername.setText(name);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open,
R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
navigationView.setNavigationItemSelectedListener(this);
GridLayoutManager gridLayoutManager= new GridLayoutManager(MainActivity.this,2);
m_recyclerView.setLayoutManager((gridLayoutManager));
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Loading Recipes...");
myRecipeList = new ArrayList<>();
myAdapter= new MyAdapter(MainActivity.this,myRecipeList);
m_recyclerView.setAdapter(myAdapter);
databaseReference = FirebaseDatabase.getInstance().getReference("Recipe");
progressDialog.show();
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
myRecipeList.clear();
for(DataSnapshot recipeSnapshot: dataSnapshot.getChildren()){
//recipeDatas.add(recipeSnapshot.getValue(RecipeData.class));
RecipeData recipeData = recipeSnapshot.getValue(RecipeData.class);
myRecipeList.add(recipeData);
}
myAdapter.notifyDataSetChanged();
progressDialog.dismiss();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
progressDialog.dismiss();
}
});
}
@Override
public void onBackPressed() {
DrawerLayout drawer = findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit application")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(@SuppressWarnings("unused") final DialogInterface dialog,
@SuppressWarnings("unused") final int id) {
moveTaskToBack(true);
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, @SuppressWarnings("unused")
final int id) {
dialog.cancel();
}
});
final AlertDialog alert = builder.create();
alert.show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
//getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();

if (id == R.id.signout) {
FirebaseAuth.getInstance().signOut();
startActivity(new Intent(this, Login_Form.class));
finish();
}

DrawerLayout drawer = findViewById(R.id.drawer_layout);


drawer.closeDrawer(GravityCompat.START);
return true;
}

public void btn_uploading(View view) {


startActivity(new Intent(this,Upload_Recipe.class));
}
public void btnSearching(View view) {
HashSet unique=new HashSet();
List<RecipeData> datas = new ArrayList<>();
for (RecipeData data : myRecipeList) {
if (data.getRecipeDescription().contains(txt_Search.getText().toString())) {
if(unique.add(data.getRecipeName())) {
datas.add(data);
}
}
}
myAdapter= new MyAdapter(MainActivity.this,datas);
m_recyclerView.setAdapter(myAdapter);
myAdapter.notifyDataSetChanged();
}
}

XML CODE:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
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"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>

Login Form:

JAVA CODE:
package com.example.pakfoodrecipe;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
public class Login_Form extends AppCompatActivity {
EditText txtEmail,txtPass;
Button btn_login;
ProgressBar lpbar;
TextView forgot_password;
private FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login__form);
getSupportActionBar().setTitle("Login");
txtEmail=(EditText) findViewById(R.id.tx_mail);
txtPass=(EditText) findViewById(R.id.tx_lpass);
btn_login=(Button) findViewById(R.id.login);
lpbar=(ProgressBar) findViewById(R.id.lpgb);
forgot_password=(android.widget.TextView) findViewById(R.id.tx_fp);
firebaseAuth=FirebaseAuth.getInstance();
btn_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String lmail=txtEmail.getText().toString().trim();
String lpass=txtPass.getText().toString().trim();
if(TextUtils.isEmpty(lmail)){
Toast.makeText(Login_Form.this, "Please enter Email",
Toast.LENGTH_LONG).show();
return;
}
if(TextUtils.isEmpty(lpass)){
Toast.makeText(Login_Form.this, "Please enter Password",
Toast.LENGTH_LONG).show();
return;
}
if(lpass.length()<6){
Toast.makeText(Login_Form.this, "Password too short",
Toast.LENGTH_LONG).show();
return;
}
lpbar.setVisibility(View.VISIBLE);
firebaseAuth.signInWithEmailAndPassword(lmail, lpass)
.addOnCompleteListener(Login_Form.this, new
OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
lpbar.setVisibility(View.GONE);
if (task.isSuccessful()) {
startActivity(new Intent(getApplicationContext(), MainActivity.class));
finish();
} else {
Toast.makeText(Login_Form.this, "Login Failed",
Toast.LENGTH_SHORT).show();
}
}
});
}
});
}
public void btn_SignupForm(View view) {
startActivity(new Intent (getApplicationContext(),Signup_Form.class));
}
public void btn_fpass(View view) {
startActivity(new Intent (getApplicationContext(),Forgot_password.class));
}
}
XML CODE:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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=".Login_Form"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ProgressBar
android:id="@+id/lpgb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:visibility="gone"/>

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingRight="30dp"
android:paddingLeft="30dp">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:textColorHint="#000000">

<EditText
android:id="@+id/tx_mail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/username"
android:drawablePadding="30dp"
android:hint="Email"
android:ems="10"
android:inputType="text"
android:textSize="22sp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="5dp"
android:textColorHint="#000000"
app:passwordToggleEnabled="true">

<EditText
android:id="@+id/tx_lpass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/password"
android:drawablePadding="30dp"
android:hint="Password"
android:ems="10"
android:inputType="text"
android:textSize="22sp" />

</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/tx_fp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forgot password?"
android:textSize="20sp"
android:gravity="left"
android:layout_gravity="right"
android:onClick="btn_fpass" />
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="40dp"
android:text="Login"
android:textSize="22sp"
android:textColor="#ffffff"
android:background="@drawable/rounded_button"/>
<TextView
android:layout_width="match_parent"
android:layout_height="63dp"
android:layout_marginTop="7dp"
android:text="Not a member? Register now"
android:gravity="center"
android:textColor="#000000"
android:textSize="22sp"
android:onClick="btn_SignupForm"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Forget Form:

JAVA CODE:
package com.example.pakfoodrecipe;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;
import android.widget.Toolbar;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
public class Forgot_password extends AppCompatActivity {
Toolbar ftba;
EditText fm;
Button fb;
ProgressBar fopgb;
FirebaseAuth firebaseAuth;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_forgot_password);

// ftba = (Toolbar) findViewById(R.id.toolbar);


fm = (EditText) findViewById(R.id.editText);
fb = (Button) findViewById(R.id.forgotbutton);
fopgb = (ProgressBar) findViewById(R.id.fpgb);
// ftba.setTitle("FORGOT PASSWORD");
firebaseAuth=FirebaseAuth.getInstance();
fb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

firebaseAuth.sendPasswordResetEmail(fm.getText().toString()).addOnCompleteListener(new
OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
Toast.makeText(Forgot_password.this, "Password sent
successfully",Toast.LENGTH_LONG).show();
finish();
startActivity(new Intent(Forgot_password.this,Login_Form.class));
}
else
{
Toast.makeText(Forgot_password.this,
task.getException().toString(),Toast.LENGTH_LONG).show();
}
}
});
}
});
}
}
XML CODE:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".Forgot_password">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#50C878"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="FORGOT PASSWORD"
android:textStyle="bold"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="30sp"/>
<ProgressBar
android:id="@+id/fpgb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:visibility="gone"/>
</androidx.appcompat.widget.Toolbar>

<EditText
android:layout_marginTop="20dp"
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter your Email to change password"
android:inputType="textEmailAddress" />

<Button
android:layout_marginTop="10dp"
android:id="@+id/forgotbutton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="DONE"
android:background="@drawable/rounded_button"/>
</LinearLayout>
Signup Form:

JAVA CODE:
package com.example.pakfoodrecipe
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth
public class Signup_Form extends AppCompatActivity {
EditText txt_name,txt_contact,txt_email,txt_password,txt_c_pas ;
RadioGroup btn_male_female;
RadioButton btn_male, btn_female;
Button btn_reg;
TextView txt_head, txt_gnd;
ProgressBar pgrbar;
private FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup__form);
getSupportActionBar().setTitle("Signup");
txt_name = (EditText) findViewById(R.id.tx_name);
txt_contact = (EditText) findViewById(R.id.tx_contact);
txt_email=(EditText) findViewById(R.id.tx_email);
txt_password = (EditText) findViewById(R.id.tx_password);
txt_c_pas = (EditText) findViewById(R.id.tx_c_password);
btn_male_female = (RadioGroup) findViewById(R.id.tx_mf);
btn_reg = (Button) findViewById(R.id.tx_submit);
txt_head= (TextView) findViewById(R.id.head);
txt_gnd= (TextView) findViewById(R.id.tx_gender);
btn_male= (RadioButton) findViewById(R.id.tx_male);
btn_female= (RadioButton) findViewById(R.id.tx_female);
pgrbar= (ProgressBar) findViewById(R.id.pgb)
firebaseAuth=FirebaseAuth.getInstance();
btn_reg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String name=txt_name.getText().toString().trim();
String contact=txt_contact.getText().toString().trim();
String email=txt_email.getText().toString().trim();
String password=txt_password.getText().toString().trim();
String cpassword=txt_c_pas.getText().toString().trim();
String gender=txt_gnd.getText().toString().trim();
if(TextUtils.isEmpty(name)){
Toast.makeText(Signup_Form.this, "Please enter name",
Toast.LENGTH_LONG).show();
return;
}
if(TextUtils.isEmpty(contact)){
Toast.makeText(Signup_Form.this, "Please enter contact",
Toast.LENGTH_LONG).show();
return;
}
if(TextUtils.isEmpty(email)){
Toast.makeText(Signup_Form.this, "Please enter email",
Toast.LENGTH_LONG).show();
return;
}
if(TextUtils.isEmpty(password)){
Toast.makeText(Signup_Form.this, "Please enter password",
Toast.LENGTH_LONG).show();
return;
}
if(TextUtils.isEmpty(cpassword)){
Toast.makeText(Signup_Form.this, "Please enter Confirm password",
Toast.LENGTH_LONG).show();
return;
}
if(TextUtils.isEmpty(gender)){
Toast.makeText(Signup_Form.this, "Please select gender",
Toast.LENGTH_LONG).show();
return;
}
if(password.length()<6){
Toast.makeText(Signup_Form.this, "Password too short",
Toast.LENGTH_LONG).show();
return;
}
pgrbar.setVisibility(View.VISIBLE);
if(password.equals(cpassword)){
firebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(Signup_Form.this, new
OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
pgrbar.setVisibility(View.GONE);
if (task.isSuccessful()) {
startActivity(new Intent(getApplicationContext(),Login_Form.class));
Toast.makeText(Signup_Form.this, "Registration successful",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(Signup_Form.this, "Authentication failed",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
});
}
}
XML CODE:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
tools:context=".Signup_Form"
android:orientation="vertical"
android:padding="30dp">
<ProgressBar
android:id="@+id/pgb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:visibility="gone"/>
<TextView
android:id="@+id/head"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Creat account"
android:textSize="24sp"
android:textColor="@color/colorAccent"
android:textStyle="italic"
android:layout_gravity="center" />

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="5dp"
android:textColorHint="#000000">

<EditText
android:id="@+id/tx_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your name"
android:ems="10"
android:inputType="text"
android:textSize="22sp"
/>

</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="5dp"
android:textColorHint="#000000">

<EditText
android:id="@+id/tx_contact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="10dp"
android:drawableLeft="@drawable/icon_pak_code"
android:drawableRight="@drawable/flag"
android:hint="Contact"
android:ems="10"
android:inputType="phone"
android:textSize="22sp" />

</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="5dp"
android:textColorHint="#000000">

<EditText
android:id="@+id/tx_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your email"
android:ems="10"
android:inputType="textEmailAddress"
android:textSize="22sp" />

</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="5dp"
android:textColorHint="#000000">

<EditText
android:id="@+id/tx_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter password"
android:ems="10"
android:inputType="textPassword"
android:textSize="22sp" />

</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="5dp"
android:textColorHint="#000000">

<EditText
android:id="@+id/tx_c_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Re-enter password"
android:ems="10"
android:inputType="textPassword"
android:textSize="22sp" />

</com.google.android.material.textfield.TextInputLayout>
<RadioGroup
android:id="@+id/tx_mf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp">

<TextView
android:id="@+id/tx_gender"
android:layout_width="wrap_content"
android:layout_height="14dp"
android:text="Gender: "
android:textSize="20sp" />
<RadioButton
android:id="@+id/tx_male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Male "
android:textSize="20sp"/>

<RadioButton
android:id="@+id/tx_female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:text="Female"
android:textSize="20sp" />
</RadioGroup>
<Button
android:id="@+id/tx_submit"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="60dp"
android:text="Submit"
android:textSize="22sp"
android:textColor="#ffffff"
android:background="@drawable/rounded_button"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
Detail Form:

JAVA CODE:
package com.example.pakfoodrecipe;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView
import com.bumptech.glide.Glide;
public class DetailActivity extends AppCompatActivity {
TextView recipeDescription,recipeTitle;
ImageView recipeImage;
RatingBar ratingBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
recipeTitle=(TextView)findViewById(R.id.adTitle);
recipeDescription=(TextView)findViewById(R.id.adDescription);
recipeDescription.setMovementMethod(new ScrollingMovementMethod());
recipeImage=(ImageView) findViewById(R.id.adimage);
ratingBar=(RatingBar) findViewById(R.id.ratingbar);
Bundle mBundle = getIntent().getExtras();
if(mBundle!=null){
recipeTitle.setText(mBundle.getString("Title"));
recipeDescription.setText(mBundle.getString("Description"));
// recipeImage.setImageResource(mBundle.getInt("Image"));
Glide.with(this).load(mBundle.getString("Image")).into(recipeImage);
}
}
}
XML CODE:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:scrollbars="vertical"
tools:context=".DetailActivity">

<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/adimage"
android:src="@drawable/halem"
android:scaleType="centerCrop"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:textColor="#000000"
android:padding="20dp"
android:text="Title"
android:textStyle="bold"
android:textSize="22sp"
android:id="@+id/adTitle"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textColor="#000000"
android:padding="20dp"
android:text="Description"
android:textSize="19sp"
android:scrollbars="vertical"
android:id="@+id/adDescription"/>
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:numStars="5"
android:stepSize="0.5"
android:id="@+id/ratingbar"
android:layout_below="@id/adTitle"
/>

</LinearLayout>
Recipe Data Form:

JAVA CODE:
package com.example.pakfoodrecipe
public class RecipeData {
private String recipeName;
private String recipeDescription;
private String recipeCookingTime;
private String recipeImage;
public RecipeData(){}
public RecipeData(String recipeName, String recipeDescription, String recipeCookingTime,
String recipeImage) {
this.recipeName = recipeName;
this.recipeDescription = recipeDescription;
this.recipeCookingTime = recipeCookingTime;
this.recipeImage = recipeImage;
}

public String getRecipeName() {


return recipeName;
}
public String getRecipeDescription() {
return recipeDescription;
}
public String getRecipeCookingTime() {
return recipeCookingTime;
}
public String getRecipeImage() {
return recipeImage;
}
}
XML CODE:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="@layout/app_bar_main">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/viewBrr"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_margin="10dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:padding="5dp"
android:background="@drawable/rounded_bg"
android:id="@+id/viewBr">
<ImageView
android:layout_width="20dp"
android:layout_height="match_parent"
android:src="@drawable/search_icon"
android:layout_margin="5dp"/>
<EditText
android:id="@+id/edt_search"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:textSize="18sp"
android:background="@null"
android:layout_marginLeft="5dp"
android:hint="Search your recipe here"/>

</LinearLayout>
<Button
android:id="@+id/btn_searching"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Search"
android:onClick="btnSearching"
android:background="@drawable/rounded_button"
android:layout_marginLeft="5dp"/>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recyclerview"
android:scrollbars="vertical"
android:layout_below="@id/viewBrr">
</androidx.recyclerview.widget.RecyclerView>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Recipe Upload Form:

JAVA CODE:
package com.example.pakfoodrecipe;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;
import java.text.DateFormat;
import java.util.Calendar;

public class Upload_Recipe extends AppCompatActivity {


ImageView recipeImage;
Uri uri;
EditText TxtName,TxtDescription,TxtCT;
String imageUrl;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload__recipe);
recipeImage=(ImageView)findViewById(R.id.up_recipeImage);
TxtName=(EditText) findViewById(R.id.txt_recName);
TxtDescription=(EditText) findViewById(R.id.txt_recDescription);
TxtCT=(EditText) findViewById(R.id.txt_recCookingTime);
}
public void btnSelectImage(View view) {
Intent photoPiker=new Intent(Intent.ACTION_PICK);
photoPiker.setType("image/*");
startActivityForResult(photoPiker,1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if(resultCode == RESULT_OK){
uri= data.getData();
recipeImage.setImageURI(uri);
}
else Toast.makeText(this,"You have not select the image",Toast.LENGTH_SHORT);
}
public void uploadImage(){
StorageReference storageReference= FirebaseStorage.getInstance().
getReference().child("RecipeImages").child(uri.getLastPathSegment());

final ProgressDialog progressDialog= new ProgressDialog(this);


progressDialog.setMessage("Recipe Uploading....");
progressDialog.show();
storageReference.putFile(uri).addOnSuccessListener(new
OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Task<Uri>uriTask=taskSnapshot.getStorage().getDownloadUrl();
while(!uriTask.isComplete());
Uri urIImage=uriTask.getResult();
imageUrl=urIImage.toString();
uploadRecipe();
progressDialog.dismiss();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
progressDialog.dismiss();
}
});
}
public void btnUploadRecipe(View view) {
uploadImage();
}
public void uploadRecipe(){
RecipeData recipeData=new RecipeData(
TxtName.getText().toString(),
TxtDescription.getText().toString(),
TxtCT.getText().toString(),
imageUrl
);
String myCurrentDateTime=
DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());
FirebaseDatabase.getInstance().getReference("Recipe")
.child(myCurrentDateTime).setValue(recipeData).addOnCompleteListener(new
OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
Toast.makeText(Upload_Recipe.this, "Recipe Uploaded",
Toast.LENGTH_SHORT).show();
finish();
}
}
});
}
}

XML CODE:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Upload_Recipe">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="30dp"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:id="@+id/up_recipeImage"
android:src="@drawable/ic_image_black_24dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Recipe Name"
android:textSize="19sp"
android:layout_marginTop="10dp"
android:id="@+id/txt_recName"/>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Recipe Description"
android:textSize="19sp"
android:layout_marginTop="10dp"
android:id="@+id/txt_recDescription"/>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Recipe Cooking Time"
android:textSize="19sp"
android:layout_marginTop="10dp"
android:id="@+id/txt_recCookingTime"/>
<Button
android:id="@+id/btnSelectImage"
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Select Image"
android:textSize="22sp"
android:backgroundTint="@color/colorPrimary"
android:textColor="#ffffff"
android:onClick="btnSelectImage"/>
<Button
android:id="@+id/btnUploadRecipe"
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Upload Recipe"
android:textSize="22sp"
android:backgroundTint="@color/colorPrimary"
android:textColor="#ffffff"
android:onClick="btnUploadRecipe"
/>
</LinearLayout>
</ScrollView>

Connection Helper:
JAVA CODE:

package com.example.pakfoodrecipe;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class ConnectionHelper {


public static boolean haveNetworkConnection(Context c) {
boolean haveConnectedWifi = false;
boolean haveConnectedMobile = false;
ConnectivityManager cm = (ConnectivityManager)
c.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] netInfo = cm.getAllNetworkInfo();
for (NetworkInfo ni : netInfo) {
if (ni.getTypeName().equalsIgnoreCase("WIFI"))
if (ni.isConnected())
haveConnectedWifi = true;
if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
if (ni.isConnected())
haveConnectedMobile = true;
}
return haveConnectedWifi || haveConnectedMobile;
}
}

MyAdpter Helper:
JAVA CODE:

package com.example.pakfoodrecipe;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import java.util.ArrayList;
import java.util.List;
public class MyAdapter extends RecyclerView.Adapter<RecipeViewHolder> {

private Context mContext;


private List<RecipeData> myRecipeList;
private int lastPosition = -1;
public MyAdapter(Context mContext, List<RecipeData> myRecipeList) {
this.mContext = mContext;
this.myRecipeList = myRecipeList;
}

@Override
public RecipeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
View mView=
LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item,parent,false);
return new RecipeViewHolder(mView);
}
@Override
public void onBindViewHolder(@NonNull final RecipeViewHolder holder, int position) {

Glide.with(mContext).load(myRecipeList.get(position).getRecipeImage()).into(holder.imageVie
w);
//holder.imageView.setImageResource(myRecipeList.get(position).getRecipeimage());
holder.mtitle.setText(myRecipeList.get(position).getRecipeName());
holder.mdescription.setText(myRecipeList.get(position).getRecipeDescription());
holder.mcooktime.setText(myRecipeList.get(position).getRecipeCookingTime());
holder.mcardview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(mContext,DetailActivity.class);

intent.putExtra("Image",myRecipeList.get(holder.getAdapterPosition()).getRecipeImage());

intent.putExtra("Title",myRecipeList.get(holder.getAdapterPosition()).getRecipeName());

intent.putExtra("Description",myRecipeList.get(holder.getAdapterPosition()).getRecipeDescripti
on());
mContext.startActivity(intent);
}
});
}

@Override
public int getItemCount() {
return myRecipeList.size();
}
}
class RecipeViewHolder extends RecyclerView.ViewHolder{

ImageView imageView;
TextView mtitle,mdescription,mcooktime;
CardView mcardview;
public RecipeViewHolder( View itemView) {
super(itemView);
imageView=itemView.findViewById(R.id.ivimage);
mtitle=itemView.findViewById(R.id.tTitle);
mdescription=itemView.findViewById(R.id.tDescription);
mcooktime=itemView.findViewById(R.id.ct);
mcardview=itemView.findViewById(R.id.mycardview);
}
}

NAV_HEADER XML CODE:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout 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="@dimen/nav_header_height"
android:background="@drawable/side_nav_bar"
android:gravity="bottom"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark">

<ImageView
android:id="@+id/imageView"
android:layout_width="75dp"
android:layout_height="75dp"
android:contentDescription="@string/nav_header_desc"
android:paddingTop="@dimen/nav_header_vertical_spacing"
app:srcCompat="@drawable/ic_image_black_24dp" />

<TextView
android:id="@+id/textviewhead"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing"
android:text="@string/nav_header_title"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

<TextView
android:id="@+id/textViewEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/nav_header_subtitle" />

</LinearLayout>

RECYCLER VIEW XML CODE:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="250dp"
android:id="@+id/mycardview"
app:cardElevation="3dp"
android:layout_margin="4dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:weightSum="5.5"
android:orientation="vertical"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/ivimage"
android:layout_weight="4"
android:scaleType="centerCrop"
android:src="@drawable/chickenharimirch"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:weightSum="2"
android:layout_weight="1.5">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.3"
android:padding="10dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="18sp"
android:textColor="#000000"
android:maxLines="1"
android:id="@+id/tTitle"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Description"
android:textSize="18sp"
android:textColor="#000000"
android:id="@+id/tDescription"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".7"
android:gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CookingTime"
android:textSize="20sp"
android:textAlignment="center"
android:textColor="#000000"
android:id="@+id/ct"
android:textStyle="bold"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>

</LinearLayout>

TOOLBAR XML CODE:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">

</LinearLayout>

APPBAR XML CODE:

<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />

</com.google.android.material.appbar.AppBarLayout>

<include layout="@layout/content_main" />

<ImageButton
android:id="@+id/btn_upload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_margin="10dp"
android:backgroundTint="@color/colorAccent"
android:onClick="btn_uploading"
android:src="@drawable/ic_file_upload_black_24dp"
android:textSize="10sp" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

You might also like