Skip to content

Commit

Permalink
Version -- 0.1 Alpha
Browse files Browse the repository at this point in the history
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
  • Loading branch information
FlapjackStaxx committed Feb 12, 2022
1 parent 53a776d commit 0cbf23d
Show file tree
Hide file tree
Showing 60 changed files with 489 additions and 447 deletions.
8 changes: 8 additions & 0 deletions .idea/misc.xml

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

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {

defaultConfig {
applicationId "com.staxxproducts.vehicleservicetracker"
minSdk 21
minSdk 26
targetSdk 31
versionCode 1
versionName "1.0"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<activity android:name=".About"/>
<activity android:name=".AddRecord"/>
<activity android:name=".ViewServices"/>
<activity android:name=".AdminActivities"/>
</application>

</manifest>
Binary file added app/src/main/ic_launcher-playstore.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 15 additions & 5 deletions app/src/main/java/com/staxxproducts/vehicleservicetracker/About.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@ class About: MainActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.about_screen)

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

backButton.setOnClickListener {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
}
// Initialize buttons
val backButton = findViewById<Button>(R.id.goBackBtn)
val adminButton = findViewById<Button>(R.id.adminBtn)

// Returns user to first screen
backButton.setOnClickListener {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
}

// Sends user to Admin Activities
adminButton.setOnClickListener {
val intent = Intent(this, AdminActivities::class.java)
startActivity(intent)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class AddRecord: MainActivity() {
private var vMk: String = ""
private var vMd: String = ""
private var vId: Int = 0
private val TAG: String = "Vehicle Info: "
private var svcDate: String = ""
private var svcMile: String = ""
private var svcType: String = ""
Expand All @@ -38,10 +37,10 @@ class AddRecord: MainActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.add_record)

// Runs loadData to populate the list of services
loadData()

val TAG = "MyActivity"

// Initializes Button and TextView
val svcAddBtn = findViewById<Button>(R.id.addSvcBtn)
val vehInfo = findViewById<TextView>(R.id.vehicleInfoTv)

Expand All @@ -50,23 +49,21 @@ class AddRecord: MainActivity() {
vYr = intent.getStringExtra("Year").toString()
vMk = intent.getStringExtra("Make").toString()
vMd = intent.getStringExtra("Model").toString()
listLength= intent.getIntExtra("ServiceLength",0)
listLength= intent.getIntExtra("ServiceLength",0)

// Returns the number of service records for vehicleID (vId)
checkRecordLength(vId)

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


// Runs processes to add a new record when Add Button is clicked then sends user back to list of vehicles when done
svcAddBtn.setOnClickListener {


addRecord()
val intent = Intent(this, ExistingVehicle::class.java)

val intent = Intent(this, ExistingVehicle::class.java)
intent.putExtra("ServiceID",listLength)

startActivity(intent)
}
}
Expand All @@ -87,16 +84,19 @@ class AddRecord: MainActivity() {
svcMile = mileageEt.text.toString()
svcType = svcTypeEt.text.toString()
svcNotes = svcNotesEt.text.toString()

// If the list of services is empty it sets the first record rather than adds to the list
if (mServiceList!!.isEmpty()) {
mServiceList!!.set(recLength-1,Service(svcDate, svcMile, svcNotes, svcType))
mServiceList!![recLength-1] = Service(svcDate, svcMile, svcNotes, svcType)
}
else {
mServiceList!!.add(recLength, Service(svcDate, svcMile, svcNotes, svcType))
}

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

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




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


// Populates the list of vehicles and their services for display
private fun loadData() {
val sharedPreferences = getSharedPreferences("shared preferences", MODE_PRIVATE)
val json = sharedPreferences.getString("vehicle list", null)
val jsonArray = JSONArray(json)
val jsonServices = jsonArray.getJSONObject(vId).getJSONArray("Services").toString()

val gson = Gson()

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

mServiceList = gson.fromJson(jsonServices, type1)
mVehicleList1 = gson.fromJson(json, type)

if (mVehicleList1 == null) {
mVehicleList1 = ArrayList()
}
Expand All @@ -138,14 +138,11 @@ class AddRecord: MainActivity() {

private fun checkRecordLength(position: Int) {
val sharedPreferences = getSharedPreferences("shared preferences", MODE_PRIVATE)
val gson = Gson()
val json = sharedPreferences.getString("vehicle list", null)
val jsonArray = JSONArray(json)
val jsonServices = jsonArray.getJSONObject(position).getJSONArray("Services")
recLength = jsonServices.length()


Log.i("Service Record # ",recLength.toString())

}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.staxxproducts.vehicleservicetracker

import android.app.AlertDialog
import android.content.Intent
import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.Button
import android.widget.EditText
import android.widget.Spinner
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import java.lang.reflect.Type
import java.text.SimpleDateFormat
import java.util.*
import kotlin.collections.ArrayList


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

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


// Runs loadData to populate the list of vehicles
loadData()


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

//Get range of years for spinner
// Get range of years for spinner
listYear = getYearRange(fromYear, toYear)
yearSpin.adapter = adapterSpin

//Executes saveData to add vehicle inputs to Gson
buttonSave.setOnClickListener { saveData() }
// Upon clicking Save getMoreInfo gets the newly added vehicle's mileage
buttonSave.setOnClickListener { getMoreInfo() }
}

//Adds data for a new vehicle
private fun saveData() {

val year = findViewById<Spinner>(R.id.yearSpin)
val make = findViewById<EditText>(R.id.makeEt)
val model = findViewById<EditText>(R.id.modelEt)

val date = ""
val mileage = ""
val servicenotes = ""
val typeofservice = ""
mServiceList!!.add(Service(date,mileage,servicenotes,typeofservice))
// Sets the current date and time as first entry
val timestamp = Date()
val dateString = timestamp.dateToString("MM-dd-yyyy")
val serviceNotes = ""
val typeOfService = ""

mServiceList!!.add(Service(dateString, currentMileage, serviceNotes, typeOfService))

// insertItem creates strings of the year make and model along with default / current service info and adds it to the vehicles data
insertItem(year.selectedItem.toString(), make.text.toString(), model.text.toString(), mServiceList!!)

val sharedPreferences = getSharedPreferences("shared preferences", MODE_PRIVATE)
Expand All @@ -64,11 +71,34 @@ class AddVehicle: AppCompatActivity() {
val json: String = gson.toJson(mVehicleList1)
editor.putString("vehicle list", json)
editor.apply()

// Sends user back to Existing Vehicle screen
val intent = Intent(this, ExistingVehicle::class.java)
startActivity(intent)

}

// Creates a dialog box to enter vehicles current mileage then executes saveData to push data to the list
private fun getMoreInfo() {
val builder = AlertDialog.Builder(this)
val inflater = layoutInflater
builder.setTitle("Enter Current Info")
val dialogLayout = inflater.inflate(R.layout.more_info_popup, null)
val currentMiles = dialogLayout.findViewById<EditText>(R.id.currentMilesEt)
val btnOkay = dialogLayout.findViewById<Button>(R.id.btnok)
builder.setView(dialogLayout)
btnOkay.setOnClickListener { currentMileage = currentMiles.text.toString()

//Executes saveData to add vehicle inputs to Gson
saveData()
}

builder.show()


}

// Populates the list of vehicles and their services for display
private fun loadData() {

val sharedPreferences = getSharedPreferences("shared preferences", MODE_PRIVATE)
Expand Down Expand Up @@ -100,4 +130,14 @@ class AddVehicle: AppCompatActivity() {
}
return listYear
}


// Returns the current date
private fun Date.dateToString(format: String): String {
//simple date formatter
val dateFormatter = SimpleDateFormat(format, Locale.getDefault())

//return the formatted date string
return dateFormatter.format(this)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.staxxproducts.vehicleservicetracker

import android.app.AlertDialog
import android.content.Intent
import android.os.Bundle
import android.widget.Button


class AdminActivities: MainActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.admin_screen)

// Initializes buttons
val backButton = findViewById<Button>(R.id.goBackBtn)
val eraseList = findViewById<Button>(R.id.eraseListBtn)

// Sends user back to the main screen
backButton.setOnClickListener {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
}
// Executes sureOrNot which asks user if they're sure they want to delete the entire list
eraseList.setOnClickListener {
sureOrNotEntire()
}



}


// Creates a dialog box giving the user the option to proceed with list deletion or to back out to the main screen
private fun sureOrNotEntire() {

val builder = AlertDialog.Builder(this)
val inflater = layoutInflater
val dialogLayout = inflater.inflate(R.layout.are_you_sure_popup, null)
val yesImSure = dialogLayout.findViewById<Button>(R.id.yesSureBtn)
val goBack = dialogLayout.findViewById<Button>(R.id.sureGoBack)
builder.setView(dialogLayout)
goBack.setOnClickListener {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
}
yesImSure.setOnClickListener {
val intent = Intent(this, ExistingVehicle::class.java)
val preferences = getSharedPreferences("shared preferences", MODE_PRIVATE)
preferences.edit().clear().apply()
startActivity(intent)
}

builder.show()


}
}

0 comments on commit 0cbf23d

Please sign in to comment.