Qr #11
|
@ -12,6 +12,7 @@ import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.core.content.res.ResourcesCompat;
|
import androidx.core.content.res.ResourcesCompat;
|
||||||
|
@ -91,19 +92,24 @@ public class HomeFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
//初回起動かを保存する変数
|
//初回起動かを保存する変数
|
||||||
int i = Integer.parseInt(preferences.getString("kidoukaisuu", "1"));
|
// int i = Integer.parseInt(preferences.getString("kidoukaisuu", "1"));
|
||||||
|
boolean alreadySaved = preferences.getBoolean("alreadySaved", false);
|
||||||
//ボタン変数の宣言
|
//ボタン変数の宣言
|
||||||
Button parent = view.findViewById(R.id.QRprinting);
|
Button parent = view.findViewById(R.id.QRprinting);
|
||||||
Button born = view.findViewById(R.id.QRprinting);
|
Button born = view.findViewById(R.id.QRprinting);
|
||||||
if (i == 1) {//QRコード印刷を初めて押したときにFireBaseへの登録を行う
|
if (alreadySaved) {
|
||||||
String QRYomitorisya = parent.getText().toString();//変数に文字列を代入
|
Log.d("HomeFragment", "already printed");
|
||||||
|
return;
|
||||||
|
} else Log.d("HomeFragment", "not printed yet"); // debug
|
||||||
|
|
||||||
|
String valueParent = parent.getText().toString();//変数に文字列を代入
|
||||||
String valueBorn = born.getText().toString();//変数に文字列を代入
|
String valueBorn = born.getText().toString();//変数に文字列を代入
|
||||||
Map<String, String> user = new HashMap<>();//mapの宣言
|
Map<String, String> user = new HashMap<>();//mapの宣言
|
||||||
|
|
||||||
Log.d("HomeFragment", "onClick is called");
|
Log.d("HomeFragment", "onClick is called");
|
||||||
|
|
||||||
//mapに入れる
|
//mapに入れる
|
||||||
user.put("parent", QRYomitorisya);
|
user.put("parent", valueParent);
|
||||||
user.put("born", valueBorn);
|
user.put("born", valueBorn);
|
||||||
//新しいドキュメントにIDを作って追加
|
//新しいドキュメントにIDを作って追加
|
||||||
db.collection("users")
|
db.collection("users")
|
||||||
|
@ -111,21 +117,27 @@ public class HomeFragment extends Fragment {
|
||||||
.addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
|
.addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(DocumentReference documentReference) {
|
public void onSuccess(DocumentReference documentReference) {
|
||||||
|
//成功したら
|
||||||
Log.d(TAG, "DocumentSnapshot added with ID: " + documentReference.getId());
|
Log.d(TAG, "DocumentSnapshot added with ID: " + documentReference.getId());
|
||||||
|
SharedPreferences.Editor e = preferences.edit();
|
||||||
|
e.putBoolean("alreadySaved", true);
|
||||||
|
e.apply();
|
||||||
|
//画面遷移
|
||||||
|
replaceFragment(new QrPrintFragment());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.addOnFailureListener(new OnFailureListener() {
|
.addOnFailureListener(new OnFailureListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Exception e) {//エラー処理
|
public void onFailure(@NonNull Exception e) {
|
||||||
|
//失敗したら
|
||||||
Log.w(TAG, "Error adding document", e);
|
Log.w(TAG, "Error adding document", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
//
|
||||||
SharedPreferences.Editor e = preferences.edit();
|
// SharedPreferences.Editor e = preferences.edit();
|
||||||
e.putString("kidoukiroku", "2");
|
// e.putString("kidoukiroku", "2");
|
||||||
e.apply();
|
// e.apply();
|
||||||
replaceFragment(new QrPrintFragment());
|
replaceFragment(new QrPrintFragment());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user