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
47 changes: 14 additions & 33 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,34 +1,15 @@
# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Log/OS Files
*.log
.DS_Store

# Android Studio generated files and folders
captures/
.externalNativeBuild/
.cxx/
*.apk
output.json

# IntelliJ
*.iml
.idea/
misc.xml
deploymentTargetDropDown.xml
render.experimental.xml

# Keystore files
*.jks
*.keystore

# Google Services (e.g. APIs or Firebase)
google-services.json

# Android Profiling
*.hprof
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
3 changes: 3 additions & 0 deletions .idea/.gitignore

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

1 change: 1 addition & 0 deletions .idea/.name

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

6 changes: 6 additions & 0 deletions .idea/AndroidProjectSystem.xml

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

6 changes: 6 additions & 0 deletions .idea/compiler.xml

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

10 changes: 10 additions & 0 deletions .idea/deploymentTargetSelector.xml

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

19 changes: 19 additions & 0 deletions .idea/gradle.xml

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

10 changes: 10 additions & 0 deletions .idea/migrations.xml

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

9 changes: 9 additions & 0 deletions .idea/misc.xml

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

17 changes: 17 additions & 0 deletions .idea/runConfigurations.xml

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

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CMPUT 301 Student Submission License
Version 2.0

Copyright 2025 `<student name>`
Copyright 2025 `Aalpesh Dayal`

Unauthorized redistribution is forbidden under all circumstances. Use of this
software without explicit authorization from the author **and** the CMPUT 301
Expand Down
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@

## Student Details

- **Full Name:** `<Enter name>`
- **CCID:** `<Enter ccid>`
- **Full Name:** `Aalpesh Dayal`
- **CCID:** `aalpesh`

## References and Resources

List any resources used here, or simply put `N/A` if not applicable.

`N/A`
## Verbal Collaboration

| Student Name | CCID |
| ------------ | --------- |
| `student` | `student` |
| `<Add more>` | `<CCID>` |
`N/A`
File renamed without changes.
23 changes: 11 additions & 12 deletions code/app/build.gradle.kts → app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
plugins {
alias(libs.plugins.android.application)
id("com.android.application")
}

android {
namespace = "com.example.listycitylab3"
compileSdk = 35
compileSdk = 34

defaultConfig {
applicationId = "com.example.listycitylab3"
minSdk = 24
targetSdk = 35
targetSdk = 33
versionCode = 1
versionName = "1.0"

Expand All @@ -26,18 +26,17 @@ android {
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}

dependencies {

implementation(libs.appcompat)
implementation(libs.material)
implementation(libs.activity)
implementation(libs.constraintlayout)
testImplementation(libs.junit)
androidTestImplementation(libs.ext.junit)
androidTestImplementation(libs.espresso.core)
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("com.google.android.material:material:1.12.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
}
File renamed without changes.
File renamed without changes.
99 changes: 99 additions & 0 deletions app/src/main/java/com/example/listycitylab3/AddCityFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.example.listycitylab3;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

// extended the dialog fragment class
public class AddCityFragment extends DialogFragment {
interface AddCityDialogListener {
void addCity(City city);
// extended listener interface to distinguish between adding and editing a city so that the fragment can call editCity() when editing
void editCity(City oldCity, City editedCity);
}

// defined the AddCityDialogListener interface inside the class and then added a private AddCityDialogListener attribute named listener
private AddCityDialogListener listener;

// override onAttach method
// listener provides the reusability of the fragment
@Override
public void onAttach(@NonNull Context context) {

super.onAttach(context);
if (context instanceof AddCityDialogListener) {
listener = (AddCityDialogListener) context;
} else {
throw new RuntimeException(context + " must implement AddCityDialogListener");
}
}

// TODO: we need to add functionality to allow editing an existing city

// pass the city object that is clicked in the Activity into the Fragment
// add a "newInstance" method in the Fragment, and use this method to create a new Fragment when editing a City

// we have to take in a city and store it in the fragment's bundle object (storing data in a Bundle is similar to storing data in an Intent using key-value pairs
static AddCityFragment newInstance(City city){
Bundle args = new Bundle();
args.putSerializable("city", city);
AddCityFragment fragment = new AddCityFragment();
fragment.setArguments(args);
return fragment;
}

// override onCreateDialog method
// we customize the dialog and bind the views
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {

View view =
LayoutInflater.from(getContext()).inflate(R.layout.fragment_add_city, null);
EditText editCityName = view.findViewById(R.id.edit_text_city_text);
EditText editProvinceName = view.findViewById(R.id.edit_text_province_text);
// (for editing a city/province) access the bundle using GetArguments() and retrieve the City object there
// need to check whether a City was passed in arguments, if yes -> editing mode, otherwise -> adding mode
City cityToEdit = null;
if (getArguments() != null){
// this means i have a city to edit
cityToEdit = (City) getArguments().getSerializable("city");
if(cityToEdit != null){
editCityName.setText(cityToEdit.getName());
editProvinceName.setText(cityToEdit.getProvince());
}
}

City finalCityToEdit = cityToEdit; // effectively final for lambda

AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
return builder
.setView(view)
// modified the line below to work for both adding and editing modes
.setTitle(cityToEdit == null ? "Add New City" : "Edit City")
.setNegativeButton("Cancel", null)
// modified the lines below to work for both adding and editing modes
.setPositiveButton(cityToEdit == null ? "Add" : "Save", (dialog, which) -> {
String cityName = editCityName.getText().toString();
String provinceName = editProvinceName.getText().toString();

if (finalCityToEdit == null) {
// Adding a new city
listener.addCity(new City(cityName, provinceName));
} else {
// Editing existing city
City updated = new City(cityName, provinceName);
listener.editCity(finalCityToEdit, updated);
}
})
.create();
}
}
36 changes: 36 additions & 0 deletions app/src/main/java/com/example/listycitylab3/City.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.example.listycitylab3;

import java.io.Serializable;

// created a new class for cities to provide more features than a string literal
// city class should implement the "Serializable" interface, so that it can be saved into the Bundle
public class City implements Serializable {

// added two private attributes, name and province
private String name;
private String province;

// added a constructor with two parameters and initialized the class attributes we just declared inside it
public City(String name, String province) {
this.name = name;
this.province = province;
}

// added getters for the attributes
public String getName() {
return name;
}
public String getProvince() {
return province;
}

// added setters to the City class so that I can modify its name and province
public void setName(String newName){
this.name = newName;
}

public void setProvince(String newProvince){
this.province = newProvince;
}

}
Loading