Food Recipe App Project PDF
Food Recipe App Project PDF
Food Recipe App Project PDF
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 {
if (id == R.id.signout) {
FirebaseAuth.getInstance().signOut();
startActivity(new Intent(this, Login_Form.class));
finish();
}
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);
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:
<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;
}
<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>
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;
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());
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;
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> {
@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);
}
}
<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>
<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>
</LinearLayout>
<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>
<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>