Skip to content

Commit 0cbf23d

Browse files
committed
Version -- 0.1 Alpha
Started adding versions Fixed -- Added App Icon -- Fixed Button BG Colors -- About screen had white bar up top -- Field shift hid date when "mileage" was clicked on Add Record screen -- Added alpha version information and version TextViews -- Fixed spacing and text and text background colors -- Now asks current mileage of new vehicle avoiding blank line for first service -- Added Admin Section with option to delete entire list of vehicles -- Added comments to ALL files -- Removed unnecessary files To Do -- Make option to delete certain vehicles -- Create New Existing Vehicles type layout with click bringing up are you sure dialog -- Make option to delete certain services
1 parent 53a776d commit 0cbf23d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+489
-447
lines changed

.idea/misc.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88

99
defaultConfig {
1010
applicationId "com.staxxproducts.vehicleservicetracker"
11-
minSdk 21
11+
minSdk 26
1212
targetSdk 31
1313
versionCode 1
1414
versionName "1.0"

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<activity android:name=".About"/>
2525
<activity android:name=".AddRecord"/>
2626
<activity android:name=".ViewServices"/>
27+
<activity android:name=".AdminActivities"/>
2728
</application>
2829

2930
</manifest>
31.1 KB
Loading

app/src/main/java/com/staxxproducts/vehicleservicetracker/About.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@ class About: MainActivity() {
1010
super.onCreate(savedInstanceState)
1111
setContentView(R.layout.about_screen)
1212

13-
val backButton = findViewById<Button>(R.id.goBackBtn)
1413

15-
backButton.setOnClickListener {
16-
val intent = Intent(this, MainActivity::class.java)
17-
startActivity(intent)
18-
}
14+
// Initialize buttons
15+
val backButton = findViewById<Button>(R.id.goBackBtn)
16+
val adminButton = findViewById<Button>(R.id.adminBtn)
17+
18+
// Returns user to first screen
19+
backButton.setOnClickListener {
20+
val intent = Intent(this, MainActivity::class.java)
21+
startActivity(intent)
22+
}
23+
24+
// Sends user to Admin Activities
25+
adminButton.setOnClickListener {
26+
val intent = Intent(this, AdminActivities::class.java)
27+
startActivity(intent)
28+
}
1929
}
2030
}

app/src/main/java/com/staxxproducts/vehicleservicetracker/AddRecord.kt

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class AddRecord: MainActivity() {
2121
private var vMk: String = ""
2222
private var vMd: String = ""
2323
private var vId: Int = 0
24-
private val TAG: String = "Vehicle Info: "
2524
private var svcDate: String = ""
2625
private var svcMile: String = ""
2726
private var svcType: String = ""
@@ -38,10 +37,10 @@ class AddRecord: MainActivity() {
3837
super.onCreate(savedInstanceState)
3938
setContentView(R.layout.add_record)
4039

40+
// Runs loadData to populate the list of services
4141
loadData()
4242

43-
val TAG = "MyActivity"
44-
43+
// Initializes Button and TextView
4544
val svcAddBtn = findViewById<Button>(R.id.addSvcBtn)
4645
val vehInfo = findViewById<TextView>(R.id.vehicleInfoTv)
4746

@@ -50,23 +49,21 @@ class AddRecord: MainActivity() {
5049
vYr = intent.getStringExtra("Year").toString()
5150
vMk = intent.getStringExtra("Make").toString()
5251
vMd = intent.getStringExtra("Model").toString()
53-
listLength= intent.getIntExtra("ServiceLength",0)
52+
listLength= intent.getIntExtra("ServiceLength",0)
5453

54+
// Returns the number of service records for vehicleID (vId)
5555
checkRecordLength(vId)
5656

57+
// Sets the info TextView to year make and model for the vehicle
5758
val finalStr: String = ("$vYr $vMk $vMd")
58-
Log.i(TAG, " $finalStr")
5959
vehInfo.text = finalStr
6060

61-
61+
// Runs processes to add a new record when Add Button is clicked then sends user back to list of vehicles when done
6262
svcAddBtn.setOnClickListener {
63-
64-
6563
addRecord()
66-
val intent = Intent(this, ExistingVehicle::class.java)
6764

65+
val intent = Intent(this, ExistingVehicle::class.java)
6866
intent.putExtra("ServiceID",listLength)
69-
7067
startActivity(intent)
7168
}
7269
}
@@ -87,16 +84,19 @@ class AddRecord: MainActivity() {
8784
svcMile = mileageEt.text.toString()
8885
svcType = svcTypeEt.text.toString()
8986
svcNotes = svcNotesEt.text.toString()
87+
88+
// If the list of services is empty it sets the first record rather than adds to the list
9089
if (mServiceList!!.isEmpty()) {
91-
mServiceList!!.set(recLength-1,Service(svcDate, svcMile, svcNotes, svcType))
90+
mServiceList!![recLength-1] = Service(svcDate, svcMile, svcNotes, svcType)
9291
}
9392
else {
9493
mServiceList!!.add(recLength, Service(svcDate, svcMile, svcNotes, svcType))
9594
}
9695

97-
// mServiceList!!.add(recLength-1,Service(svcDate, svcMile, svcNotes, svcType))
96+
// mServiceList!!.add(recLength-1,Service(svcDate, svcMile, svcNotes, svcType))
9897
insertItem(vYr,vMk,vMd, mServiceList!!)
9998

99+
// Calls up a fresh instance of shared preferences and adds the record to it
100100
val sharedPreferences = getSharedPreferences("shared preferences", MODE_PRIVATE)
101101
val editor = sharedPreferences.edit()
102102
val gson = Gson()
@@ -107,18 +107,17 @@ class AddRecord: MainActivity() {
107107

108108

109109

110-
110+
// Inserts a new service item to the vehicle list at position vId
111111
private fun insertItem(Year: String, Make: String, Model: String, mServiceList: ArrayList<Service>) {
112112
mVehicleList1!![vId] = (VehicleServiceItem(Year,Make,Model,mServiceList))
113113
}
114114

115-
115+
// Populates the list of vehicles and their services for display
116116
private fun loadData() {
117117
val sharedPreferences = getSharedPreferences("shared preferences", MODE_PRIVATE)
118118
val json = sharedPreferences.getString("vehicle list", null)
119119
val jsonArray = JSONArray(json)
120120
val jsonServices = jsonArray.getJSONObject(vId).getJSONArray("Services").toString()
121-
122121
val gson = Gson()
123122

124123
val type: Type = object : TypeToken<ArrayList<VehicleServiceItem?>?>() {}.type
@@ -127,6 +126,7 @@ class AddRecord: MainActivity() {
127126

128127
mServiceList = gson.fromJson(jsonServices, type1)
129128
mVehicleList1 = gson.fromJson(json, type)
129+
130130
if (mVehicleList1 == null) {
131131
mVehicleList1 = ArrayList()
132132
}
@@ -138,14 +138,11 @@ class AddRecord: MainActivity() {
138138

139139
private fun checkRecordLength(position: Int) {
140140
val sharedPreferences = getSharedPreferences("shared preferences", MODE_PRIVATE)
141-
val gson = Gson()
142141
val json = sharedPreferences.getString("vehicle list", null)
143142
val jsonArray = JSONArray(json)
144143
val jsonServices = jsonArray.getJSONObject(position).getJSONArray("Services")
145144
recLength = jsonServices.length()
146145

147146

148-
Log.i("Service Record # ",recLength.toString())
149-
150147
}
151148
}

app/src/main/java/com/staxxproducts/vehicleservicetracker/AddVehicle.kt

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package com.staxxproducts.vehicleservicetracker
22

3+
import android.app.AlertDialog
34
import android.content.Intent
45
import android.os.Bundle
5-
import android.widget.ArrayAdapter
6-
import android.widget.Button
7-
import android.widget.EditText
8-
import android.widget.Spinner
6+
import android.widget.*
97
import androidx.appcompat.app.AppCompatActivity
108
import com.google.gson.Gson
119
import com.google.gson.reflect.TypeToken
1210
import java.lang.reflect.Type
11+
import java.text.SimpleDateFormat
12+
import java.util.*
13+
import kotlin.collections.ArrayList
1314

1415

1516
class AddVehicle: AppCompatActivity() {
@@ -21,12 +22,13 @@ class AddVehicle: AppCompatActivity() {
2122
private var mServiceList: ArrayList<Service>? = null
2223
private val fromYear: String = "2022"
2324
private val toYear: String = "1900"
25+
private var currentMileage: String = ""
2426

2527
override fun onCreate(savedInstanceState: Bundle?) {
2628
super.onCreate(savedInstanceState)
2729
setContentView(R.layout.add_vehicle)
2830

29-
31+
// Runs loadData to populate the list of vehicles
3032
loadData()
3133

3234

@@ -37,25 +39,30 @@ class AddVehicle: AppCompatActivity() {
3739
android.R.layout.simple_spinner_item, listYear)
3840
val buttonSave = findViewById<Button>(R.id.addButton)
3941

40-
//Get range of years for spinner
42+
// Get range of years for spinner
4143
listYear = getYearRange(fromYear, toYear)
4244
yearSpin.adapter = adapterSpin
4345

44-
//Executes saveData to add vehicle inputs to Gson
45-
buttonSave.setOnClickListener { saveData() }
46+
// Upon clicking Save getMoreInfo gets the newly added vehicle's mileage
47+
buttonSave.setOnClickListener { getMoreInfo() }
4648
}
4749

50+
//Adds data for a new vehicle
4851
private fun saveData() {
52+
4953
val year = findViewById<Spinner>(R.id.yearSpin)
5054
val make = findViewById<EditText>(R.id.makeEt)
5155
val model = findViewById<EditText>(R.id.modelEt)
5256

53-
val date = ""
54-
val mileage = ""
55-
val servicenotes = ""
56-
val typeofservice = ""
57-
mServiceList!!.add(Service(date,mileage,servicenotes,typeofservice))
57+
// Sets the current date and time as first entry
58+
val timestamp = Date()
59+
val dateString = timestamp.dateToString("MM-dd-yyyy")
60+
val serviceNotes = ""
61+
val typeOfService = ""
5862

63+
mServiceList!!.add(Service(dateString, currentMileage, serviceNotes, typeOfService))
64+
65+
// insertItem creates strings of the year make and model along with default / current service info and adds it to the vehicles data
5966
insertItem(year.selectedItem.toString(), make.text.toString(), model.text.toString(), mServiceList!!)
6067

6168
val sharedPreferences = getSharedPreferences("shared preferences", MODE_PRIVATE)
@@ -64,11 +71,34 @@ class AddVehicle: AppCompatActivity() {
6471
val json: String = gson.toJson(mVehicleList1)
6572
editor.putString("vehicle list", json)
6673
editor.apply()
74+
75+
// Sends user back to Existing Vehicle screen
6776
val intent = Intent(this, ExistingVehicle::class.java)
6877
startActivity(intent)
78+
6979
}
7080

81+
// Creates a dialog box to enter vehicles current mileage then executes saveData to push data to the list
82+
private fun getMoreInfo() {
83+
val builder = AlertDialog.Builder(this)
84+
val inflater = layoutInflater
85+
builder.setTitle("Enter Current Info")
86+
val dialogLayout = inflater.inflate(R.layout.more_info_popup, null)
87+
val currentMiles = dialogLayout.findViewById<EditText>(R.id.currentMilesEt)
88+
val btnOkay = dialogLayout.findViewById<Button>(R.id.btnok)
89+
builder.setView(dialogLayout)
90+
btnOkay.setOnClickListener { currentMileage = currentMiles.text.toString()
91+
92+
//Executes saveData to add vehicle inputs to Gson
93+
saveData()
94+
}
95+
96+
builder.show()
7197

98+
99+
}
100+
101+
// Populates the list of vehicles and their services for display
72102
private fun loadData() {
73103

74104
val sharedPreferences = getSharedPreferences("shared preferences", MODE_PRIVATE)
@@ -100,4 +130,14 @@ class AddVehicle: AppCompatActivity() {
100130
}
101131
return listYear
102132
}
133+
134+
135+
// Returns the current date
136+
private fun Date.dateToString(format: String): String {
137+
//simple date formatter
138+
val dateFormatter = SimpleDateFormat(format, Locale.getDefault())
139+
140+
//return the formatted date string
141+
return dateFormatter.format(this)
142+
}
103143
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.staxxproducts.vehicleservicetracker
2+
3+
import android.app.AlertDialog
4+
import android.content.Intent
5+
import android.os.Bundle
6+
import android.widget.Button
7+
8+
9+
class AdminActivities: MainActivity() {
10+
11+
override fun onCreate(savedInstanceState: Bundle?) {
12+
super.onCreate(savedInstanceState)
13+
setContentView(R.layout.admin_screen)
14+
15+
// Initializes buttons
16+
val backButton = findViewById<Button>(R.id.goBackBtn)
17+
val eraseList = findViewById<Button>(R.id.eraseListBtn)
18+
19+
// Sends user back to the main screen
20+
backButton.setOnClickListener {
21+
val intent = Intent(this, MainActivity::class.java)
22+
startActivity(intent)
23+
}
24+
// Executes sureOrNot which asks user if they're sure they want to delete the entire list
25+
eraseList.setOnClickListener {
26+
sureOrNotEntire()
27+
}
28+
29+
30+
31+
}
32+
33+
34+
// Creates a dialog box giving the user the option to proceed with list deletion or to back out to the main screen
35+
private fun sureOrNotEntire() {
36+
37+
val builder = AlertDialog.Builder(this)
38+
val inflater = layoutInflater
39+
val dialogLayout = inflater.inflate(R.layout.are_you_sure_popup, null)
40+
val yesImSure = dialogLayout.findViewById<Button>(R.id.yesSureBtn)
41+
val goBack = dialogLayout.findViewById<Button>(R.id.sureGoBack)
42+
builder.setView(dialogLayout)
43+
goBack.setOnClickListener {
44+
val intent = Intent(this, MainActivity::class.java)
45+
startActivity(intent)
46+
}
47+
yesImSure.setOnClickListener {
48+
val intent = Intent(this, ExistingVehicle::class.java)
49+
val preferences = getSharedPreferences("shared preferences", MODE_PRIVATE)
50+
preferences.edit().clear().apply()
51+
startActivity(intent)
52+
}
53+
54+
builder.show()
55+
56+
57+
}
58+
}

0 commit comments

Comments
 (0)