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
<!DOCTYPE html> | |
<html> | |
<head>Demo site firebase</head> | |
<body> | |
<br> | |
<br> | |
<br> | |
Hello world! This is demo firebase site. From GitHub. |
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
{ | |
"database": { | |
"rules": "database.rules.json" | |
}, | |
"hosting": { | |
"public": "public", | |
"rewrites": [ | |
{ | |
"source": "**", | |
"destination": "/index.html" |
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
{ | |
"rules": { | |
".read": "auth != null", | |
".write": "auth != null" | |
} | |
} |
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
{ | |
"projects": { | |
"default": "fir-signinproject-d8d84" | |
} | |
} |
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
private void subscribeToDbChanges() { | |
// как преобразовать LiveData | |
// входная сигнатура - List<LoanWithUserAndBook> | |
// выходная - String | |
LiveData<List<LoanWithUserAndBook>> loans | |
= mDb.loanModel().findLoansByNameAfter("Alexander", getYesterdayDate()); | |
// Instead of exposing the list of Loans, we can apply a transformation and expose Strings. | |
mLoansResult = Transformations.map(loans, | |
new Function<List<LoanWithUserAndBook>, String>() { |
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
... | |
private User selectedUser; //hold selected user | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
... |
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
private void deleteUser(User selectedUser) { | |
mDatabaseReference.child("users") | |
.child(selectedUser.getUid()) | |
.removeValue(); | |
clearEditText(); | |
} |
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
private void updateUser(User user) { | |
//по полученному начению UUID меняем имя | |
mDatabaseReference.child("users") | |
.child(user.getUid()) | |
.child("name") | |
.setValue(user.getName()); | |
//меняем email | |
mDatabaseReference.child("users") | |
.child(user.getUid()) | |
.child("email") |
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
private void createUser() { | |
//создаем элемент класса User | |
User user = new User(UUID.randomUUID().toString(), | |
input_name.getText().toString(), //берем данные имени и email из полей ввода | |
input_email.getText().toString()); | |
//сохраняем данные в базе данных Firebase по пути users -> UUID_User | |
mDatabaseReference.child("users").child(user.getUid()).setValue(user); | |
//очищаем поля ввода | |
clearEditText(); | |
} |
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
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
//нажато "добавить" | |
if (item.getItemId() == R.id.menu_add) { | |
createUser(); | |
} | |
//нажато "сохранить изменения" | |
else if (item.getItemId() == R.id.menu_save) { | |
//создаем экземпляр записи и заносим туда измененные данные | |
//которые берем из полей ввода |