use of com.google.firebase.firestore.QueryDocumentSnapshot in project EZMeal by Jake-Sokol2.
the class CategoryFragmentRepository method retrieveHorizontal.
// returns number of recipes that were actually retrieved
private List<HorizontalRecipe> retrieveHorizontal(RetrievedRecipeLists recipeList, String category, String typeOfRecyclerItem, Task<QuerySnapshot> task) {
// delete all existing featured recipes in SQL
deleteAllRecycler2();
int numRetrieved = 0;
List<HorizontalRecipe> returnList = new ArrayList<>();
for (QueryDocumentSnapshot document : task.getResult()) {
String imageUrl = document.getString("imageUrl");
String title = document.getString("title");
String highRatedRecipeId = document.getId();
Double highRatedRecipeIdDouble = document.getDouble("recipeId");
Integer highRatedRecipeIdInt = highRatedRecipeIdDouble.intValue();
Double countRating = document.getDouble("countRating");
Double avgRating;
if (countRating != null) {
avgRating = document.getDouble("rating") / countRating;
} else {
countRating = 0.0;
avgRating = 0.0;
}
if (Double.isNaN(avgRating)) {
avgRating = 0.0;
}
Integer totalRating = countRating.intValue();
int sizeOfSet = recipeList.getSetOfUniqueHorizontalRecipes().size();
recipeList.addToSetOfUniqueHorizontalRecipes(highRatedRecipeIdInt);
// the current recipe is not a duplicate - it may be added to the recyclerview
if ((sizeOfSet != recipeList.getSetOfUniqueHorizontalRecipes().size())) {
// todo: may need to uncomment and modify class
// numRetrieved = numRetrieved + 1;
// viewModel.incrementNumOfRetrievedHighRatedRecipes(1);
HorizontalRecipe newRecipe = new HorizontalRecipe(title, imageUrl, highRatedRecipeId, avgRating);
// add this recipe to the most recently added vertical item
// horizontalLists.add(newRecipe);
returnList.add(newRecipe);
RecyclerRecipe2 horizontalRecyclerRecipe2 = new RecyclerRecipe2("RecommendedForYou", highRatedRecipeId, title, imageUrl, avgRating, typeOfRecyclerItem, true, totalRating);
roomRepository.insertRecycler2(horizontalRecyclerRecipe2);
// todo: fix this and other inserts to Room
// insertRecycler2(recyclerRecipePopular2);
}
}
return returnList;
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project spacecraft-android by JamesfChen.
the class FirebaseDatabaseActivity method onCreate.
// @AddTrace(name = "FirebaseDatabaseActivity_onCreateTrace", enabled = true /* optional */)
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
database.setPersistenceEnabled(true);
database.setPersistenceCacheSizeBytes(50 * 1024 * 1024);
database.setLogLevel(Logger.Level.DEBUG);
DatabaseReference myRef = database.getReference();
myRef.child("user");
myRef.setValue("Hello, World!");
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
String value = dataSnapshot.getValue(String.class);
Log.d("hawks", "Value is: " + value);
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w("hawks", "Failed to read value.", error.toException());
}
});
FirebaseFirestoreSettings build = new FirebaseFirestoreSettings.Builder().setPersistenceEnabled(true).setCacheSizeBytes(50 * 10241024).build();
databasev2.setFirestoreSettings(build);
// Create a new user with a first and last name
Map<String, Object> user = new HashMap<>();
user.put("first", "Ada");
user.put("last", "Lovelace");
user.put("born", 1815);
// Add a new document with a generated ID
databasev2.collection("users").add(user).addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
@Override
public void onSuccess(DocumentReference documentReference) {
Log.d("hawks", "DocumentSnapshot added with ID: " + documentReference.getId());
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w("hawks", "Error adding document", e);
}
});
// Create a new user with a first, middle, and last name
Map<String, Object> user2 = new HashMap<>();
user.put("first", "Alan");
user.put("middle", "Mathison");
user.put("last", "Turing");
user.put("born", 1912);
// Add a new document with a generated ID
databasev2.collection("users").add(user2).addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
@Override
public void onSuccess(DocumentReference documentReference) {
Log.d("hawks", "DocumentSnapshot added with ID: " + documentReference.getId());
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w("hawks", "Error adding document", e);
}
});
// Log.d("hawks", "enableNetwork : " + databasev2.enableNetwork().isSuccessful());
databasev2.collection("users").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Log.d("hawks", document.getId() + " => " + document.getData());
}
} else {
Log.w("hawks", "Error getting documents.", task.getException());
}
}
});
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project MobileTerm by vivi108.
the class MyHomeFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_my_home, container, false);
setting = (ImageView) rootView.findViewById(R.id.my_home_setting_iv);
listview = (ListView) rootView.findViewById(R.id.my_home_listview);
profile = (ImageView) rootView.findViewById(R.id.my_home_profile_iv);
name = (TextView) rootView.findViewById(R.id.my_home_profile_name_tv);
// DB
// Cloud Firestore초기화
db = FirebaseFirestore.getInstance();
db.collection("Users").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Log.d(TAG, document.getId() + " => " + document.getData());
}
} else {
Log.w(TAG, "Error getting documents.", task.getException());
}
}
});
// 리스트뷰
ArrayAdapter<String> adapter = new ArrayAdapter<>(requireActivity(), android.R.layout.simple_list_item_1, data);
listview.setAdapter(adapter);
// 톱니바퀴, 설정 그림 눌렀을 때
setting.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
requireActivity().getSupportFragmentManager().beginTransaction().replace(R.id.main_frame_layout, new SettingFragment()).commit();
}
});
// 프로필 이미지 눌렀을 때.
profile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
requireActivity().getSupportFragmentManager().beginTransaction().replace(R.id.main_frame_layout, new ProfileSettingFragment()).commit();
}
});
// 이름을 눌렀을 때
name.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
requireActivity().getSupportFragmentManager().beginTransaction().replace(R.id.main_frame_layout, new ProfileSettingFragment()).commit();
}
});
// 리스트뷰 메뉴 선택했을 때
listview.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
return rootView;
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project MobileTerm by vivi108.
the class BoardFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_board_main, container, false);
searchEditText = rootView.findViewById(R.id.searchEditText);
listView = rootView.findViewById(R.id.listView);
db = FirebaseFirestore.getInstance();
db.collection("BulletinBoard").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
if (document.exists()) {
String title = (String) document.getData().get("Title");
String content = (String) document.getData().get("Content");
String tags = (String) document.getData().get("Tags");
String name = (String) document.getData().get("Name");
BoardInfo data = new BoardInfo(title, tags, content, name);
arrayList.add(data);
}
}
adapter = new ListViewAdapter(rootView.getContext(), arrayList);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
MainActivity activity = (MainActivity) getActivity();
Log.d("boardItemClicked", "by setOnItemCLick");
activity.onFragmentChanged(arrayList.get(i));
}
});
}
}
});
rootView.findViewById(R.id.searchButton).setOnClickListener(onClickListener);
rootView.findViewById(R.id.filterButton).setOnClickListener(onClickListener);
rootView.findViewById(R.id.startWriteButton).setOnClickListener(onClickListener);
return rootView;
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project SE_TermProject by IMDongH.
the class UserReservationActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_reservation);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
time.add("예약 시간 선택");
mAuth = FirebaseAuth.getInstance();
db = FirebaseFirestore.getInstance();
user = mAuth.getCurrentUser();
// Date 객체 사용
java.util.Date day = new Date();
Date = simpleDateFormat.format(day);
today = Date;
info.setDate(Date);
ActionBar ac = getSupportActionBar();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
calendarView = findViewById(R.id.calendarView);
complete_Btn = findViewById(R.id.complete_Btn);
Spinner reservationSpinner = (Spinner) findViewById(R.id.reservation);
Spinner contentSpinner = (Spinner) findViewById(R.id.content);
Intent intent = getIntent();
centerName = intent.getStringExtra("centerName");
info.setCenterName(centerName);
centerAddress = intent.getStringExtra("centerAddress");
info.setAddress(centerAddress);
db.collection("enterprises").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
if (document.exists()) {
String name = (String) document.getData().get("centerName");
String address = (String) document.getData().get("roadName_Address");
System.out.println(name + info.getCenterName());
System.out.println(address + info.getAddress());
if (name.equals(info.getCenterName()) && address.equals(info.getAddress())) {
String start = (String) document.getData().get("startTime");
String end = (String) document.getData().get("endTime");
int startH;
int startM;
int endH;
int endM;
int openH;
int openM;
String[] startT = start.split(" ");
if (startT[0].equals("AM")) {
String intStr = startT[1].replaceAll("[^0-9]", "");
startH = Integer.parseInt(intStr);
String intStr2 = startT[2].replaceAll("[^0-9]", "");
startM = Integer.parseInt(intStr2);
if (startM >= 30) {
startM = 30;
} else {
startM = 0;
}
} else {
String intStr = startT[1].replaceAll("[^0-9]", "");
startH = Integer.parseInt(intStr) + 12;
String intStr2 = startT[2].replaceAll("[^0-9]", "");
startM = Integer.parseInt(intStr2);
if (startM >= 30) {
startM = 30;
} else {
startM = 0;
}
}
String[] endT = end.split(" ");
if (endT[0].equals("AM")) {
String intStr = endT[1].replaceAll("[^0-9]", "");
endH = Integer.parseInt(intStr);
String intStr2 = endT[2].replaceAll("[^0-9]", "");
endM = Integer.parseInt(intStr2);
if (endM >= 30) {
endM = 30;
} else {
endM = 0;
}
} else {
String intStr = endT[1].replaceAll("[^0-9]", "");
endH = Integer.parseInt(intStr) + 12;
String intStr2 = endT[2].replaceAll("[^0-9]", "");
endM = Integer.parseInt(intStr2);
if (endM >= 30) {
endM = 30;
} else {
endM = 0;
}
}
openH = (endH - startH) * 2;
openM = endM - startM;
if (openM == 30) {
openH++;
}
ArrayList<Integer>[] test = new ArrayList[openH];
for (int i = 0; i < openH; i++) {
test[i] = new ArrayList<Integer>();
}
for (int i = 0; i < openH; i++) {
if (startM == 30) {
startH++;
startM = 0;
} else {
startM = 30;
}
test[i].add(startH);
test[i].add(startM);
}
for (int i = 0; i < openH; i++) {
time.add(test[i].get(0) + " : " + test[i].get(1));
}
}
} else {
Log.d("Wrong", "No document");
}
}
} else {
Log.d("Wrong", "failed with", task.getException());
}
}
});
TextView carcenterReservationTitle = findViewById(R.id.carcenterReservationTitle);
carcenterReservationTitle.setText(centerName);
ac.setTitle("예약하기");
findViewById(R.id.complete_Btn).setOnClickListener(onClickListener);
calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(@NonNull CalendarView view, int year, int month, int dayOfMonth) {
// complete_Btn.setVisibility(View.VISIBLE);
Date = checkDay(year, month, dayOfMonth);
info.setDate(Date);
}
});
ArrayAdapter<String> adapterReservation = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, time);
reservationSpinner.setAdapter(adapterReservation);
adapterReservation.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
reservationSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Log.d("TESTTEST", time.get(i));
info.setTime(time.get(i));
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
ArrayAdapter<String> adapterContent = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, content);
contentSpinner.setAdapter(adapterContent);
adapterContent.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
contentSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Log.d("TESTTEST", content[i]);
info.setContent(content[i]);
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
}
Aggregations