SHARE
TWEET

Untitled

a guest Jun 26th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.altervista.thebrunix.fondocassa;
  2.  
  3. import android.content.Intent;
  4. import android.support.annotation.NonNull;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.util.Log;
  8. import android.view.View;
  9. import android.widget.CalendarView;
  10. import android.widget.CheckBox;
  11. import android.widget.EditText;
  12. import android.widget.Toast;
  13.  
  14. import com.google.firebase.database.DataSnapshot;
  15. import com.google.firebase.database.DatabaseError;
  16. import com.google.firebase.database.DatabaseReference;
  17. import com.google.firebase.database.FirebaseDatabase;
  18. import com.google.firebase.database.ValueEventListener;
  19.  
  20. import org.altervista.thebrunix.fondocassa.Modelli.MovimentoModel;
  21.  
  22. import java.text.SimpleDateFormat;
  23. import java.time.LocalDate;
  24. import java.util.Date;
  25.  
  26. public class InserisciMovimento extends AppCompatActivity {
  27.  
  28.     private CalendarView mCalendario;
  29.     private EditText mImportoMov;
  30.     private CheckBox mConferimento;
  31.     private EditText mDescrizioneMov;
  32.  
  33.     private String mDataDaInserire;
  34.     private Double mImpDaInserire;
  35.     private String mDescrDaInserire;
  36.     private SimpleDateFormat sdf;
  37.  
  38.     private Double totalone;
  39.  
  40.     FirebaseDatabase mDatabase;
  41.     private DatabaseReference mtotaleReference;
  42.  
  43.     @Override
  44.     protected void onCreate(Bundle savedInstanceState) {
  45.         super.onCreate(savedInstanceState);
  46.         setContentView(R.layout.insert_movimento);
  47.         inizializzaFirebase();
  48.         inizializzaUI();
  49.         leggiTotale();
  50.  
  51.     }
  52.  
  53.     private void leggiTotale() {
  54.         mtotaleReference = FirebaseDatabase.getInstance().getReference("totale");
  55.         mtotaleReference.addValueEventListener(new ValueEventListener() {
  56.             @Override
  57.             public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
  58.                 totalone = dataSnapshot.getValue(Double.class);
  59.             }
  60.  
  61.             @Override
  62.             public void onCancelled(@NonNull DatabaseError databaseError) {
  63.  
  64.             }
  65.         });
  66.     }
  67.  
  68.     private void inizializzaUI() {
  69.         mCalendario = (CalendarView) findViewById(R.id.cvCalendario);
  70.         sdf = new SimpleDateFormat("dd/MM/yyyy");
  71.         mDataDaInserire = sdf.format(new Date(mCalendario.getDate()));
  72.         mCalendario.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
  73.             @Override
  74.             public void onSelectedDayChange(@NonNull CalendarView view, int year, int month, int dayOfMonth) {
  75.                 month = month + 1;
  76.                 String mese = "0";
  77.                 if (month<10) mese = "0" + String.valueOf(month);
  78.                 else {
  79.                     mese = String.valueOf(month);
  80.                 }
  81.                 String giorno = "0";
  82.                 if (dayOfMonth<10) giorno = "0" + String.valueOf(dayOfMonth);
  83.                 else {
  84.                     giorno = String.valueOf(dayOfMonth);
  85.                 }
  86.                 mDataDaInserire = giorno+"/"+mese+"/"+String.valueOf(year);
  87.             }
  88.         });
  89.         mImportoMov = (EditText)findViewById(R.id.etImportoMovimento);
  90.         mConferimento = (CheckBox)findViewById(R.id.cbConferimento);
  91.         mDescrizioneMov = (EditText)findViewById(R.id.etDescrizioneMovimento);
  92.  
  93.     }
  94.  
  95.     private void inizializzaFirebase() {
  96.         mDatabase = FirebaseDatabase.getInstance();
  97.  
  98.     }
  99.  
  100.     public void bnChiudi(View view) {
  101.         Intent intento = new Intent(this, MainActivity.class);
  102.         startActivity(intento);
  103.     }
  104.  
  105.  
  106.  
  107.     public void InserisciMov(View view) {
  108.         DatabaseReference myRef = mDatabase.getReference();
  109.  
  110.         mImpDaInserire = -(Double.parseDouble(mImportoMov.getText().toString()));
  111.         if (mConferimento.isChecked()){
  112.             mImpDaInserire = -mImpDaInserire;
  113.         }
  114.         mDescrDaInserire = mDescrizioneMov.getText().toString();
  115.  
  116.  
  117.         MovimentoModel movimento = new MovimentoModel(mDataDaInserire,mImpDaInserire, mDescrDaInserire);
  118.         myRef.child("movimenti").push().setValue(movimento);
  119.  
  120.         totalone = totalone + mImpDaInserire;
  121.         myRef.child("totale").setValue(totalone);
  122.  
  123.         //myRef.setValue("Hello, World!");
  124.         Toast.makeText( this,"Inserito movimento di € " + mImpDaInserire.toString() +
  125.                 " in data " + mDataDaInserire, Toast.LENGTH_SHORT).show();
  126.         mDescrizioneMov.setText("");
  127.         mImportoMov.setText("");
  128.     }
  129. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top