Created
November 2, 2016 02:46
-
-
Save alvareztech/b743bdfea1e3045b5e54cd66bca63799 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
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 java.util.List; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
FirebaseDatabase database = FirebaseDatabase.getInstance(); | |
DatabaseReference ref = database.getReference("daniel"); | |
ref.addValueEventListener(new ValueEventListener() { | |
@Override | |
public void onDataChange(DataSnapshot dataSnapshot) { | |
Usuario u = dataSnapshot.getValue(Usuario.class); | |
System.out.println("Usuario" + u.getNombre() + " " + dataSnapshot.getKey()); | |
System.out.println(" Niveles: " + u.getNiveles().size()); | |
for (Nivel n : u.getNiveles()) { | |
System.out.println(" > " + n.getNota() + " " + n.isHabilitado()); | |
} | |
actualizarBotones(u.getNiveles()); | |
} | |
@Override | |
public void onCancelled(DatabaseError error) { | |
System.out.println("Error: " + error.getMessage()); | |
} | |
}); | |
} | |
private void actualizarBotones(List<Nivel> niveles) { | |
// aqui se recorre los niveles y se pregunta si estan habilitados los niveles | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"daniel" : { | |
"niveles" : [ { | |
"habilitado" : true, | |
"nota" : 23 | |
}, { | |
"habilitado" : true, | |
"nota" : 4 | |
}, { | |
"habilitado" : false, | |
"nota" : 432 | |
}, { | |
"habilitado" : false, | |
"nota" : 312 | |
} ], | |
"nombre" : "Daniel Alvarez" | |
}, | |
"jose" : { | |
"niveles" : [ null, { | |
"habilitado" : true, | |
"nota" : 100 | |
} ], | |
"nombre" : "Jose" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Nivel { | |
private boolean habilitado; | |
private int nota; | |
public Nivel() { | |
this.habilitado = false; | |
this.nota = 0; | |
} | |
public boolean isHabilitado() { | |
return habilitado; | |
} | |
public void setHabilitado(boolean habilitado) { | |
this.habilitado = habilitado; | |
} | |
public int getNota() { | |
return nota; | |
} | |
public void setNota(int nota) { | |
this.nota = nota; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Usuario { | |
private String nombre; | |
private List<Nivel> niveles; | |
public List<Nivel> getNiveles() { | |
return niveles; | |
} | |
public void setNiveles(List<Nivel> niveles) { | |
this.niveles = niveles; | |
} | |
public String getNombre() { | |
return nombre; | |
} | |
public void setNombre(String nombre) { | |
this.nombre = nombre; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment