Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified ListyCity/.gradle/8.13/checksums/checksums.lock
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified ListyCity/.gradle/8.13/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified ListyCity/.gradle/8.13/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified ListyCity/.gradle/8.13/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified ListyCity/.gradle/8.13/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified ListyCity/.gradle/8.13/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified ListyCity/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified ListyCity/.gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions ListyCity/.gradle/config.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Tue Oct 07 08:20:18 MDT 2025
java.home=/Applications/Android Studio.app/Contents/jbr/Contents/Home
#Thu Feb 26 10:57:48 PKT 2026
java.home=C\:\\Program Files\\Android\\Android Studio\\jbr
Binary file modified ListyCity/.gradle/file-system.probe
Binary file not shown.
9 changes: 9 additions & 0 deletions ListyCity/.idea/ListyCity.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

603 changes: 580 additions & 23 deletions ListyCity/.idea/caches/deviceStreaming.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ListyCity/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion ListyCity/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions ListyCity/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
alias(libs.plugins.android.application)
id("com.google.gms.google-services")

}

Expand Down Expand Up @@ -38,6 +39,8 @@ dependencies {
implementation(libs.material)
implementation(libs.activity)
implementation(libs.constraintlayout)
implementation(platform("com.google.firebase:firebase-bom:34.3.0"))
implementation("com.google.firebase:firebase-firestore")
testImplementation(libs.junit)
androidTestImplementation(libs.ext.junit)
androidTestImplementation(libs.espresso.core)
Expand Down
29 changes: 29 additions & 0 deletions ListyCity/app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"project_info": {
"project_number": "820681107984",
"project_id": "test-lab-05-b0acc",
"storage_bucket": "test-lab-05-b0acc.firebasestorage.app"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:820681107984:android:26f9b5b4b874959f097895",
"android_client_info": {
"package_name": "com.example.lab5_starter"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyAZAwySbE1ivY3pMkSIF_Y0_p89yKhvXzo"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class CityDialogFragment extends DialogFragment {
interface CityDialogListener {
void updateCity(City city, String title, String year);
void addCity(City city);
void deleteCity(City city);
}
private CityDialogListener listener;

Expand Down Expand Up @@ -49,7 +50,8 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {

String tag = getTag();
Bundle bundle = getArguments();
City city;
// City city;
final City city;

if (Objects.equals(tag, "City Details") && bundle != null){
city = (City) bundle.getSerializable("City");
Expand All @@ -61,7 +63,7 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
city = null;}

AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
return builder
builder
.setView(view)
.setTitle("City Details")
.setNegativeButton("Cancel", null)
Expand All @@ -73,7 +75,15 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
} else {
listener.addCity(new City(title, year));
}
})
.create();
});
// .create();

if (Objects.equals(tag, "City Details") && city != null) {
builder.setNeutralButton("Delete", (dialog, which) -> {
listener.deleteCity(city);
});
}

return builder.create();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.lab5_starter;

import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
Expand All @@ -11,6 +12,11 @@
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.QueryDocumentSnapshot;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity implements CityDialogFragment.CityDialogListener {
Expand All @@ -20,6 +26,8 @@ public class MainActivity extends AppCompatActivity implements CityDialogFragmen

private ArrayList<City> cityArrayList;
private ArrayAdapter<City> cityArrayAdapter;
private FirebaseFirestore db;
private CollectionReference citiesRef;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -32,6 +40,9 @@ protected void onCreate(Bundle savedInstanceState) {
return insets;
});

db = FirebaseFirestore.getInstance();
citiesRef = db.collection("cities");

// Set views
addCityButton = findViewById(R.id.buttonAddCity);
cityListView = findViewById(R.id.listviewCities);
Expand All @@ -41,7 +52,24 @@ protected void onCreate(Bundle savedInstanceState) {
cityArrayAdapter = new CityArrayAdapter(this, cityArrayList);
cityListView.setAdapter(cityArrayAdapter);

addDummyData();
// addDummyData();

citiesRef.addSnapshotListener((value, error) -> {
if (error != null){
Log.e("Firestore", error.toString());
return;
}
if (value != null && !value.isEmpty()){
cityArrayList.clear();
for (QueryDocumentSnapshot snapshot : value){
String cityName = snapshot.getString("name");
String provinceName = snapshot.getString("province");

cityArrayList.add(new City(cityName, provinceName));
}
cityArrayAdapter.notifyDataSetChanged();
}
});

// set listeners
addCityButton.setOnClickListener(view -> {
Expand Down Expand Up @@ -71,13 +99,27 @@ public void addCity(City city){
cityArrayList.add(city);
cityArrayAdapter.notifyDataSetChanged();

DocumentReference docRef = citiesRef.document(city.getName());
docRef.set(city);

}

public void addDummyData(){
City m1 = new City("Edmonton", "AB");
City m2 = new City("Vancouver", "BC");
cityArrayList.add(m1);
cityArrayList.add(m2);
@Override
public void deleteCity(City city) {
cityArrayList.remove(city);
cityArrayAdapter.notifyDataSetChanged();

citiesRef.document(city.getName())
.delete()
.addOnSuccessListener(aVoid -> Log.d("Firestore", "Document successfully deleted!"))
.addOnFailureListener(e -> Log.w("Firestore", "Error deleting document", e));
}

// public void addDummyData(){
// City m1 = new City("Edmonton", "AB");
// City m2 = new City("Vancouver", "BC");
// cityArrayList.add(m1);
// cityArrayList.add(m2);
// cityArrayAdapter.notifyDataSetChanged();
// }
}
1 change: 1 addition & 0 deletions ListyCity/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
alias(libs.plugins.android.application) apply false
id("com.google.gms.google-services") version "4.4.3" apply false

}
2 changes: 1 addition & 1 deletion ListyCity/build/reports/problems/problems-report.html
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@
<script type="text/javascript">
function configurationCacheProblems() { return (
// begin-report-data
{"diagnostics":[{"locations":[{"path":"/Users/re/Documents/Uni/CMPUT301/Lab05/ListyCity/app/src/main/java/com/example/lab5_starter/CityDialogFragment.java"},{"taskPath":":app:compileDebugJavaWithJavac"}],"problem":[{"text":"Java compilation note"}],"severity":"ADVICE","problemDetails":[{"text":"Note: /Users/re/Documents/Uni/CMPUT301/Lab05/ListyCity/app/src/main/java/com/example/lab5_starter/CityDialogFragment.java uses or overrides a deprecated API."}],"contextualLabel":"/Users/re/Documents/Uni/CMPUT301/Lab05/ListyCity/app/src/main/java/com/example/lab5_starter/CityDialogFragment.java uses or overrides a deprecated API.","problemId":[{"name":"java","displayName":"Java compilation"},{"name":"compilation","displayName":"Compilation"},{"name":"compiler-note-deprecated-filename","displayName":"Java compilation note"}]},{"locations":[{"path":"/Users/re/Documents/Uni/CMPUT301/Lab05/ListyCity/app/src/main/java/com/example/lab5_starter/CityDialogFragment.java"},{"taskPath":":app:compileDebugJavaWithJavac"}],"problem":[{"text":"Java compilation note"}],"severity":"ADVICE","problemDetails":[{"text":"Note: Recompile with -Xlint:deprecation for details."}],"contextualLabel":"Recompile with -Xlint:deprecation for details.","problemId":[{"name":"java","displayName":"Java compilation"},{"name":"compilation","displayName":"Compilation"},{"name":"compiler-note-deprecated-recompile","displayName":"Java compilation note"}]}],"problemsReport":{"totalProblemCount":2,"buildName":"Lab5-starter","requestedTasks":":app:assembleDebug","documentationLink":"https://docs.gradle.org/8.13/userguide/reporting_problems.html","documentationLinkCaption":"Problem report","summaries":[]}}
{"diagnostics":[{"locations":[{"path":"C:\\Users\\HP\\AndroidStudioProjects\\lab-05\\ListyCity\\app\\src\\main\\java\\com\\example\\lab5_starter\\CityDialogFragment.java"},{"taskPath":":app:compileDebugJavaWithJavac"}],"problem":[{"text":"Java compilation note"}],"severity":"ADVICE","problemDetails":[{"text":"Note: C:\\Users\\HP\\AndroidStudioProjects\\lab-05\\ListyCity\\app\\src\\main\\java\\com\\example\\lab5_starter\\CityDialogFragment.java uses or overrides a deprecated API."}],"contextualLabel":"C:\\Users\\HP\\AndroidStudioProjects\\lab-05\\ListyCity\\app\\src\\main\\java\\com\\example\\lab5_starter\\CityDialogFragment.java uses or overrides a deprecated API.","problemId":[{"name":"java","displayName":"Java compilation"},{"name":"compilation","displayName":"Compilation"},{"name":"compiler-note-deprecated-filename","displayName":"Java compilation note"}]},{"locations":[{"path":"C:\\Users\\HP\\AndroidStudioProjects\\lab-05\\ListyCity\\app\\src\\main\\java\\com\\example\\lab5_starter\\CityDialogFragment.java"},{"taskPath":":app:compileDebugJavaWithJavac"}],"problem":[{"text":"Java compilation note"}],"severity":"ADVICE","problemDetails":[{"text":"Note: Recompile with -Xlint:deprecation for details."}],"contextualLabel":"Recompile with -Xlint:deprecation for details.","problemId":[{"name":"java","displayName":"Java compilation"},{"name":"compilation","displayName":"Compilation"},{"name":"compiler-note-deprecated-recompile","displayName":"Java compilation note"}]}],"problemsReport":{"totalProblemCount":2,"buildName":"Lab5-starter","requestedTasks":":app:assembleDebug","documentationLink":"https://docs.gradle.org/8.13/userguide/reporting_problems.html","documentationLinkCaption":"Problem report","summaries":[]}}
// end-report-data
);}
</script>
Expand Down
4 changes: 2 additions & 2 deletions ListyCity/local.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Tue Oct 07 02:55:15 MDT 2025
sdk.dir=/Users/re/Library/Android/sdk
#Thu Feb 26 11:05:37 PKT 2026
sdk.dir=C\:\\Users\\HP\\AppData\\Local\\Android\\Sdk