package com.bysoftware.cookbook.android;

/**
 * Created by sbozturk on 6.5.2017.
 */

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;

public class AddRecipeActivity extends AppCompatActivity {

    public EditText editTextRecipeName, editTextIngredients, editTextDirections, editTextPreparationTime;
    private PrefUtil prefUtil;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.add_recipe);

        prefUtil = new PrefUtil(this);

        editTextRecipeName = (EditText) findViewById(R.id.editTextRecipeName);
        editTextIngredients = (EditText) findViewById(R.id.editTextIngredients);
        editTextDirections = (EditText) findViewById(R.id.editTextDirections);
        editTextPreparationTime = (EditText) findViewById(R.id.editTextPreparationTime);
        showSavedPreferences();

    }

    @Override
    protected void onPause() {
        super.onPause();
        prefUtil.saveBio(editTextRecipeName.getText().toString(), editTextIngredients.getText().toString(), editTextDirections.getText().toString(), editTextPreparationTime.getText().toString());

    }

    public void showSavedPreferences() {
        editTextRecipeName.setText(prefUtil.getRecipeName());
        editTextIngredients.setText(prefUtil.getRecipeIngredients());
        editTextDirections.setText(prefUtil.getRecipeDirections());
        editTextPreparationTime.setText(prefUtil.getRecipePreparationTime());

    }

    public void addRecipe(View view) {
        editTextRecipeName.setText("");
        editTextIngredients.setText("");
        editTextDirections.setText("");
        editTextPreparationTime.setText("");

        finish();
    }
}

@@ -277,16 +277,127 @@
 tText;%0A%0A
+import com.google.firebase.database.DatabaseReference;%0Aimport com.google.firebase.database.FirebaseDatabase;%0A%0A%0A
 public c
@@ -584,16 +584,84 @@
 refUtil;
+%0A    public DatabaseReference mDatabase;%0A    public String recipeID;
 %0A%0A    @O
@@ -2032,24 +2032,48 @@
 iew view) %7B%0A
+        saveFirebase();%0A
         edit
@@ -2251,10 +2251,646 @@
 ;%0A    %7D%0A
+%0A    public void saveFirebase() %7B%0A        mDatabase = FirebaseDatabase.getInstance().getReference(%22users%22);%0A%0A        //id d%C3%BCzenlenecek%0A        recipeID = %22123%22;%0A        String recipeName = editTextRecipeName.getText().toString();%0A        String recipeIngredients = editTextIngredients.getText().toString();%0A        String recipeDirections = editTextDirections.getText().toString();%0A        String recipePreparationTime = editTextPreparationTime.getText().toString();%0A%0A        Recipe recipe = new Recipe(recipeName, recipeIngredients, recipeDirections, recipePreparationTime);%0A%0A        mDatabase.child(recipeID).setValue(recipe);%0A    %7D%0A%0A
 %7D%0A

write to firebase