Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed MakedObject #103

Draft
wants to merge 18 commits into
base: Open-Testing
Choose a base branch
from
Draft
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
8 changes: 1 addition & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
Expand All @@ -15,4 +9,4 @@
app/src/debug/res/values/google_maps_api.xml
app/release/app-release.aab
app/src/release/res/values/google_maps_api.xml
.idea/dictionaries/stephenogden.xml
/.idea/
5 changes: 2 additions & 3 deletions .idea/gradle.xml

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

33 changes: 18 additions & 15 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'

android {
compileSdk 34
buildToolsVersion '34.0.0'
compileSdk 35
defaultConfig {
applicationId "fnsb.macstransit"
minSdkVersion 21
targetSdk 34
targetSdk 35
versionCode 30
versionName 'Release 1.3.9'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -38,6 +37,7 @@ android {
buildFeatures {
viewBinding true
dataBinding true
buildConfig true
}
compileOptions {
sourceCompatibility = 17
Expand All @@ -51,24 +51,27 @@ android {
includeInBundle true
}
namespace 'fnsb.macstransit'
buildToolsVersion '35.0.0'
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.gms:play-services-maps:18.2.0'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'com.google.android.gms:play-services-maps:19.0.0'
implementation 'org.jetbrains:annotations:24.1.0'
implementation 'com.android.volley:volley:1.2.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'
implementation 'com.google.maps.android:maps-ktx:5.0.0'
implementation 'com.google.maps.android:maps-utils-ktx:5.0.0'
implementation 'com.google.maps.android:android-maps-utils:3.8.0'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.json:json:20231013'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.4'
implementation 'com.google.maps.android:maps-ktx:5.1.1'
implementation 'com.google.maps.android:maps-utils-ktx:5.1.1'
implementation 'com.google.maps.android:android-maps-utils:3.8.2'
implementation 'androidx.annotation:annotation-jvm:1.8.2'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.12'
implementation 'com.orhanobut:dialogplus:1.11@aar'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.json:json:20240303'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.14'
}
11 changes: 11 additions & 0 deletions app/src/main/java/fnsb/macstransit/activities/LoadedRoutes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package fnsb.macstransit.activities

import fnsb.macstransit.routematch.Route

object LoadedRoutes {

/**
* All of the routes that can be tracked by the app. This will be determined by the master schedule.
*/
val routes: HashMap<String, Route> = HashMap() // todo Preload this from default_routes.json?
}
21 changes: 2 additions & 19 deletions app/src/main/java/fnsb/macstransit/activities/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,9 @@ class SettingsActivity : AppCompatActivity() {
// The cancel button should just finish the class and return.
binding.cancel.setOnClickListener { finish() }

// Get the routes from the intent extra.
val extraBundle: Bundle = intent.extras ?: return

if (VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {

@Suppress("DEPRECATION") // Suppressed because the new function does not exist in earlier APIs
val routesParcelable: Array<Parcelable> = extraBundle.getParcelableArray("Routes") ?: return
for (parcelableRoute in routesParcelable) {
if (parcelableRoute is Route) {
addRouteToCheckbox(parcelableRoute)
}
}
} else {

val routes: Array<Route> = extraBundle.getParcelableArray("Routes", Route::class.java) ?: return
for (route in routes) {
addRouteToCheckbox(route)
}
for (route in LoadedRoutes.routes.values) {
addRouteToCheckbox(route)
}

}

private fun addRouteToCheckbox(route: Route) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ class LoadingActivity : AppCompatActivity() {
// Get the intent to start the MapsActivity.
val mapsIntent = Intent(this, MapsActivity::class.java)

// Get the routes as parcelables.
mapsIntent.putExtra("Routes", binding.viewmodel!!.routes.values.toTypedArray())

// Start the MapsActivity, and close this splash activity.
Log.d("launchMapsActivity", "Starting maps activity")
startActivity(mapsIntent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import fnsb.macstransit.R
import fnsb.macstransit.activities.LoadedRoutes
import fnsb.macstransit.activities.loadingactivity.loadingscreenrunnables.DownloadBusStops
import fnsb.macstransit.activities.loadingactivity.loadingscreenrunnables.DownloadMasterSchedule
import fnsb.macstransit.activities.loadingactivity.loadingscreenrunnables.DownloadRouteObjects
Expand All @@ -40,17 +41,11 @@ import kotlin.math.max
*/
class LoadingViewModel(application: Application) : AndroidViewModel(application) {


/**
* The RouteMatch object used to retrieve data from the RouteMatch servers.
*/
val routeMatch: RouteMatch = RouteMatch(getApplication<Application>().getString(R.string.routematch_url), getApplication())

/**
* All of the routes that can be tracked by the app. This will be determined by the master schedule.
*/
val routes: HashMap<String, Route> = HashMap()

/**
* The current (adjustable) progress.
* This is private as we only want to adjust it the values in the view model.
Expand Down Expand Up @@ -187,8 +182,6 @@ class LoadingViewModel(application: Application) : AndroidViewModel(application)
}
}



/**
* Changes the splash screen display when there is no internet.
* This method involves making the progress bar invisible,
Expand Down Expand Up @@ -244,7 +237,7 @@ class LoadingViewModel(application: Application) : AndroidViewModel(application)
if (!passedInit) { return@launch }

// Check if there are routes available for the day.
if (routes.isEmpty()) {
if (LoadedRoutes.routes.isEmpty()) {
setMessage(R.string.its_sunday)
activity.allowForRetry()
return@launch
Expand All @@ -271,7 +264,7 @@ class LoadingViewModel(application: Application) : AndroidViewModel(application)

// Iterate though all the routes and recreate the stops for each route.
// Purge the stops that have shared stops.
for (route in routes.values) { route.purgeStops() }
for (route in LoadedRoutes.routes.values) { route.purgeStops() }


// Update the progress bar to the maximum value since we've reached the end.
Expand Down Expand Up @@ -300,13 +293,13 @@ class LoadingViewModel(application: Application) : AndroidViewModel(application)
var downloadQueue = 0

// Get the progress step.
val step: Double = loadProgress / routes.size
val step: Double = loadProgress / LoadedRoutes.routes.size

// Get the current progress.
val progress: Double = progressSoFar + downloadProgress

// Iterate though all the indices of all the routes that can be tracked.
for ((i, route) in routes.values.withIndex()) {
for ((i, route) in LoadedRoutes.routes.values.withIndex()) {

// Decrease the download queue (as we are queueing a new downloadable).
downloadQueue--
Expand All @@ -318,7 +311,7 @@ class LoadingViewModel(application: Application) : AndroidViewModel(application)
runnable.download(route, downloadProgress, progressSoFar, i)

// Update the current progress.
setProgressBar(progress + step + downloadQueue + routes.size)
setProgressBar(progress + step + downloadQueue + LoadedRoutes.routes.size)

// Increase the downloaded queue as our downloadable has finished downloading.
downloadQueue++
Expand Down Expand Up @@ -384,12 +377,12 @@ class LoadingViewModel(application: Application) : AndroidViewModel(application)
setMessage(R.string.shared_bus_stop_check)

// Set the current progress.
val step = LoadingActivity.LOAD_SHARED_STOPS.toDouble() / routes.size
val step = LoadingActivity.LOAD_SHARED_STOPS.toDouble() / LoadedRoutes.routes.size
var currentProgress = (LoadingActivity.DOWNLOAD_MASTER_SCHEDULE_PROGRESS + LoadingActivity.
PARSE_MASTER_SCHEDULE + LoadingActivity.DOWNLOAD_BUS_STOPS + LoadingActivity.LOAD_BUS_STOPS).toDouble()

// Iterate though each route in all our trackable routes.
for (route in routes.values) {
for (route in LoadedRoutes.routes.values) {

// If there are no stops to iterate over in our route just continue with the next iteration.
if (route.stops.isEmpty()) { continue }
Expand All @@ -402,7 +395,7 @@ class LoadingViewModel(application: Application) : AndroidViewModel(application)
if (route.sharedStops[name] != null) { continue }

// Get an array of shared routes.
val sharedRoutes: Array<Route> = SharedStop.getSharedRoutes(route, stop, routes)
val sharedRoutes: Array<Route> = SharedStop.getSharedRoutes(route, stop, LoadedRoutes.routes)

// If the shared routes array has more than one entry, create a new shared stop object.
if (sharedRoutes.size > 1) {
Expand All @@ -411,8 +404,8 @@ class LoadingViewModel(application: Application) : AndroidViewModel(application)
// Iterate though all the routes in the shared route,
// and add our newly created shared stop.
for (sharedStopRoute: Route in sharedRoutes) {
Log.d("mapSharedStops", "Adding shared stop to route: ${routes[sharedStopRoute.name]!!.name}")
routes[sharedStopRoute.name]!!.sharedStops[name] = sharedStop
Log.d("mapSharedStops", "Adding shared stop to route: ${LoadedRoutes.routes[sharedStopRoute.name]!!.name}")
LoadedRoutes.routes[sharedStopRoute.name]!!.sharedStops[name] = sharedStop
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fnsb.macstransit.activities.loadingactivity.loadingscreenrunnables

import android.util.Log
import fnsb.macstransit.R
import fnsb.macstransit.activities.LoadedRoutes
import fnsb.macstransit.activities.loadingactivity.LoadingViewModel
import fnsb.macstransit.routematch.Route
import fnsb.macstransit.routematch.Stop
Expand Down Expand Up @@ -30,7 +31,7 @@ class DownloadBusStops(viewModel: LoadingViewModel): DownloadRouteObjects<Unit>(
})

// Get the progress step.
val step: Double = downloadProgress / this.viewModel.routes.size
val step: Double = downloadProgress /LoadedRoutes.routes.size

// Update the progress bar.
this.viewModel.setProgressBar(progressSoFar + step + index)
Expand All @@ -50,7 +51,7 @@ class DownloadBusStops(viewModel: LoadingViewModel): DownloadRouteObjects<Unit>(

// Try to create a new stop object using the information in the json array.
val stop: Stop = try {
Stop(jsonArray.getJSONObject(i), this.route)
Stop(jsonArray.getJSONObject(i), route)
} catch (e: org.json.JSONException) {

// If unsuccessful simply log the exception and continue iterating.
Expand All @@ -60,7 +61,7 @@ class DownloadBusStops(viewModel: LoadingViewModel): DownloadRouteObjects<Unit>(

// Try to add the stop the route's stop hashmap in the view model.
try {
this.viewModel.routes[this.route.name]!!.stops[stop.name] = stop
LoadedRoutes.routes[this.route.name]!!.stops[stop.name] = stop
} catch (NullPointerException : NullPointerException) {

// If the route of the stop is not in the routes hashmap then log it as an error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class DownloadMasterSchedule(private val loadingActivity: LoadingActivity):
val route = Route.generateRoute(routeData)

// Add the route to the hashmap in the view model.
loadingActivity.binding.viewmodel!!.routes[route.name] = route
fnsb.macstransit.activities.LoadedRoutes.routes[route.name] = route
} catch (exception: Exception) {

// If there was a route exception thrown simply log it.
Expand Down
Loading
Loading