- lint checks completed

This commit is contained in:
2023-08-29 19:13:01 +01:00
parent a0f3af3990
commit e6e3a72adf
8 changed files with 95 additions and 85 deletions

6
.idea/kotlinc.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="KotlinJpsPluginSettings">
<option name="version" value="1.7.10" />
</component>
</project>

View File

@@ -19,22 +19,24 @@ class ShiftProvider : ContentProvider() {
return true return true
} }
override fun query(uri: Uri, projection: Array<String>?, selection: String?, selectionArgs: Array<String>?, override fun query(
sortOrder: String?): Cursor? { uri: Uri, projection: Array<String>?, selection: String?, selectionArgs: Array<String>?,
var selection = selection sortOrder: String?
var selectionArgs = selectionArgs ): Cursor {
val database = mDbHelper!!.readableDatabase val database = mDbHelper!!.readableDatabase
val cursor: Cursor val cursor: Cursor = when (sUriMatcher.match(uri)) {
val match = sUriMatcher.match(uri) SHIFTS -> database.query(
when (match) { ShiftsEntry.TABLE_NAME, projection, selection, selectionArgs,
SHIFTS -> cursor = database.query(ShiftsEntry.TABLE_NAME, projection, selection, selectionArgs, null, null, sortOrder
null, null, sortOrder) )
SHIFT_ID -> { SHIFT_ID -> {
selection = ShiftsEntry._ID + "=?" val mSelection = ShiftsEntry._ID + "=?"
selectionArgs = arrayOf(ContentUris.parseId(uri).toString()) val mSelectionArgs = arrayOf(ContentUris.parseId(uri).toString())
cursor = database.query(ShiftsEntry.TABLE_NAME, projection, selection, selectionArgs, database.query(
null, null, sortOrder) ShiftsEntry.TABLE_NAME, projection, mSelection, mSelectionArgs,
null, null, sortOrder
)
} }
else -> throw IllegalArgumentException("Cannot query $uri") else -> throw IllegalArgumentException("Cannot query $uri")
@@ -44,26 +46,25 @@ class ShiftProvider : ContentProvider() {
} }
override fun insert(uri: Uri, contentValues: ContentValues?): Uri? { override fun insert(uri: Uri, contentValues: ContentValues?): Uri? {
val match = sUriMatcher.match(uri) return when (sUriMatcher.match(uri)) {
return when (match) {
SHIFTS -> insertShift(uri, contentValues) SHIFTS -> insertShift(uri, contentValues)
else -> throw IllegalArgumentException("Insertion is not supported for $uri") else -> throw IllegalArgumentException("Insertion is not supported for $uri")
} }
} }
private fun insertShift(uri: Uri, values: ContentValues?): Uri? { private fun insertShift(uri: Uri, values: ContentValues?): Uri? {
val description = values!!.getAsString(ShiftsEntry.COLUMN_SHIFT_DESCRIPTION) values!!.getAsString(ShiftsEntry.COLUMN_SHIFT_DESCRIPTION)
?: throw IllegalArgumentException("Description required") ?: throw IllegalArgumentException("Description required")
val date = values.getAsString(ShiftsEntry.COLUMN_SHIFT_DATE) values.getAsString(ShiftsEntry.COLUMN_SHIFT_DATE)
?: throw IllegalArgumentException("Date required") ?: throw IllegalArgumentException("Date required")
val timeIn = values.getAsString(ShiftsEntry.COLUMN_SHIFT_TIME_IN) values.getAsString(ShiftsEntry.COLUMN_SHIFT_TIME_IN)
?: throw IllegalArgumentException("Time In required") ?: throw IllegalArgumentException("Time In required")
val timeOut = values.getAsString(ShiftsEntry.COLUMN_SHIFT_TIME_OUT) values.getAsString(ShiftsEntry.COLUMN_SHIFT_TIME_OUT)
?: throw IllegalArgumentException("Time Out required") ?: throw IllegalArgumentException("Time Out required")
val duration = values.getAsFloat(ShiftsEntry.COLUMN_SHIFT_DURATION) val duration = values.getAsFloat(ShiftsEntry.COLUMN_SHIFT_DURATION)
require(duration >= 0) { "Duration cannot be negative" } require(duration >= 0) { "Duration cannot be negative" }
val shiftType = values.getAsString(ShiftsEntry.COLUMN_SHIFT_TYPE) values.getAsString(ShiftsEntry.COLUMN_SHIFT_TYPE)
?: throw IllegalArgumentException("Shift type required") ?: throw IllegalArgumentException("Shift type required")
val shiftUnits = values.getAsFloat(ShiftsEntry.COLUMN_SHIFT_UNIT) val shiftUnits = values.getAsFloat(ShiftsEntry.COLUMN_SHIFT_UNIT)
require(shiftUnits >= 0) { "Units cannot be negative" } require(shiftUnits >= 0) { "Units cannot be negative" }
val payRate = values.getAsFloat(ShiftsEntry.COLUMN_SHIFT_PAYRATE) val payRate = values.getAsFloat(ShiftsEntry.COLUMN_SHIFT_PAYRATE)
@@ -82,43 +83,47 @@ class ShiftProvider : ContentProvider() {
return ContentUris.withAppendedId(uri, id) return ContentUris.withAppendedId(uri, id)
} }
override fun update(uri: Uri, contentValues: ContentValues?, selection: String?, override fun update(
selectionArgs: Array<String>?): Int { uri: Uri, contentValues: ContentValues?, selection: String?,
var selection = selection selectionArgs: Array<String>?
var selectionArgs = selectionArgs ): Int {
val match = sUriMatcher.match(uri) return when (sUriMatcher.match(uri)) {
return when (match) {
SHIFTS -> updateShift(uri, contentValues, selection, selectionArgs) SHIFTS -> updateShift(uri, contentValues, selection, selectionArgs)
SHIFT_ID -> { SHIFT_ID -> {
selection = ShiftsEntry._ID + "=?" val mSelection = ShiftsEntry._ID + "=?"
selectionArgs = arrayOf(ContentUris.parseId(uri).toString()) val mSelectionArgs = arrayOf(ContentUris.parseId(uri).toString())
updateShift(uri, contentValues, selection, selectionArgs) updateShift(uri, contentValues, mSelection, mSelectionArgs)
} }
else -> throw IllegalArgumentException("Update is not supported for $uri") else -> throw IllegalArgumentException("Update is not supported for $uri")
} }
} }
private fun updateShift(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<String>?): Int { private fun updateShift(
uri: Uri,
values: ContentValues?,
selection: String?,
selectionArgs: Array<String>?
): Int {
if (values!!.containsKey(ShiftsEntry.COLUMN_SHIFT_DESCRIPTION)) { if (values!!.containsKey(ShiftsEntry.COLUMN_SHIFT_DESCRIPTION)) {
val description = values.getAsString(ShiftsEntry.COLUMN_SHIFT_DESCRIPTION) values.getAsString(ShiftsEntry.COLUMN_SHIFT_DESCRIPTION)
?: throw IllegalArgumentException("description required") ?: throw IllegalArgumentException("description required")
} }
if (values.containsKey(ShiftsEntry.COLUMN_SHIFT_DATE)) { if (values.containsKey(ShiftsEntry.COLUMN_SHIFT_DATE)) {
val date = values.getAsString(ShiftsEntry.COLUMN_SHIFT_DATE) values.getAsString(ShiftsEntry.COLUMN_SHIFT_DATE)
?: throw IllegalArgumentException("date required") ?: throw IllegalArgumentException("date required")
} }
if (values.containsKey(ShiftsEntry.COLUMN_SHIFT_TIME_IN)) { if (values.containsKey(ShiftsEntry.COLUMN_SHIFT_TIME_IN)) {
val timeIn = values.getAsString(ShiftsEntry.COLUMN_SHIFT_TIME_IN) values.getAsString(ShiftsEntry.COLUMN_SHIFT_TIME_IN)
?: throw IllegalArgumentException("time in required") ?: throw IllegalArgumentException("time in required")
} }
if (values.containsKey(ShiftsEntry.COLUMN_SHIFT_TIME_OUT)) { if (values.containsKey(ShiftsEntry.COLUMN_SHIFT_TIME_OUT)) {
val timeOut = values.getAsString(ShiftsEntry.COLUMN_SHIFT_TIME_OUT) values.getAsString(ShiftsEntry.COLUMN_SHIFT_TIME_OUT)
?: throw IllegalArgumentException("time out required") ?: throw IllegalArgumentException("time out required")
} }
if (values.containsKey(ShiftsEntry.COLUMN_SHIFT_BREAK)) { if (values.containsKey(ShiftsEntry.COLUMN_SHIFT_BREAK)) {
val breaks = values.getAsString(ShiftsEntry.COLUMN_SHIFT_BREAK) values.getAsString(ShiftsEntry.COLUMN_SHIFT_BREAK)
?: throw IllegalArgumentException("break required") ?: throw IllegalArgumentException("break required")
} }
if (values.size() == 0) { if (values.size() == 0) {
return 0 return 0
@@ -132,17 +137,15 @@ class ShiftProvider : ContentProvider() {
} }
override fun delete(uri: Uri, selection: String?, selectionArgs: Array<String>?): Int { override fun delete(uri: Uri, selection: String?, selectionArgs: Array<String>?): Int {
var selection = selection
var selectionArgs = selectionArgs
val database = mDbHelper!!.writableDatabase val database = mDbHelper!!.writableDatabase
val rowsDeleted: Int val rowsDeleted: Int = when (sUriMatcher.match(uri)) {
val match = sUriMatcher.match(uri) SHIFTS -> database.delete(ShiftsEntry.TABLE_NAME, selection, selectionArgs)
when (match) {
SHIFTS -> rowsDeleted = database.delete(ShiftsEntry.TABLE_NAME, selection, selectionArgs)
SHIFT_ID -> { SHIFT_ID -> {
selection = ShiftsEntry._ID + "=?" val mSelection = ShiftsEntry._ID + "=?"
selectionArgs = arrayOf(ContentUris.parseId(uri).toString()) val mSelectionArgs = arrayOf(ContentUris.parseId(uri).toString())
rowsDeleted = database.delete(ShiftsEntry.TABLE_NAME, selection, selectionArgs)
database.delete(ShiftsEntry.TABLE_NAME, mSelection, mSelectionArgs)
} }
else -> throw IllegalArgumentException("Deletion is not supported for $uri") else -> throw IllegalArgumentException("Deletion is not supported for $uri")
@@ -169,7 +172,11 @@ class ShiftProvider : ContentProvider() {
init { init {
sUriMatcher.addURI(ShiftsContract.CONTENT_AUTHORITY, ShiftsContract.PATH_SHIFTS, SHIFTS) sUriMatcher.addURI(ShiftsContract.CONTENT_AUTHORITY, ShiftsContract.PATH_SHIFTS, SHIFTS)
sUriMatcher.addURI(ShiftsContract.CONTENT_AUTHORITY, ShiftsContract.PATH_SHIFTS + "/#", SHIFT_ID) sUriMatcher.addURI(
ShiftsContract.CONTENT_AUTHORITY,
ShiftsContract.PATH_SHIFTS + "/#",
SHIFT_ID
)
} }
} }

View File

@@ -10,8 +10,6 @@ enum class Sortable(val label: String) {
TOTALPAY("Total Pay"); TOTALPAY("Total Pay");
companion object { companion object {
val entries = Sortable.values()
fun getEnumByType(label: String): Sortable { fun getEnumByType(label: String): Sortable {
return Sortable.values().first { it.label == label } return Sortable.values().first { it.label == label }
} }

View File

@@ -95,7 +95,7 @@ class FragmentMain : BaseFragment<MainViewModel>(R.layout.fragment_main), BackPr
AlertDialog.Builder(context) AlertDialog.Builder(context)
.setTitle("Help & Support:") .setTitle("Help & Support:")
.setView(R.layout.dialog_layout) .setView(R.layout.dialog_layout)
.setPositiveButton(android.R.string.yes) { arg0, arg1 -> arg0.dismiss() } .setPositiveButton(android.R.string.ok) { arg0, _ -> arg0.dismiss() }
.create().show() .create().show()
return true return true
} }
@@ -120,12 +120,11 @@ class FragmentMain : BaseFragment<MainViewModel>(R.layout.fragment_main), BackPr
AlertDialog.Builder(context) AlertDialog.Builder(context)
.setTitle("Export?") .setTitle("Export?")
.setMessage("Exporting current filtered data. Continue?") .setMessage("Exporting current filtered data. Continue?")
.setNegativeButton(android.R.string.no, null) .setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.yes) { arg0, arg1 -> exportData() } .setPositiveButton(android.R.string.ok) { _, _ -> exportData() }
.create().show() .create().show()
} else { } else {
Toast.makeText(context, "Storage permissions required", Toast.LENGTH_SHORT) displayToast("Storage permissions required")
.show()
} }
return true return true
} }
@@ -134,7 +133,7 @@ class FragmentMain : BaseFragment<MainViewModel>(R.layout.fragment_main), BackPr
AlertDialog.Builder(context) AlertDialog.Builder(context)
.setTitle("Info:") .setTitle("Info:")
.setMessage(viewModel.getInformation()) .setMessage(viewModel.getInformation())
.setPositiveButton(android.R.string.yes) { arg0, arg1 -> .setPositiveButton(android.R.string.ok) { arg0, _ ->
arg0.dismiss() arg0.dismiss()
}.create().show() }.create().show()
return true return true
@@ -144,7 +143,7 @@ class FragmentMain : BaseFragment<MainViewModel>(R.layout.fragment_main), BackPr
} }
private fun sortData() { private fun sortData() {
val groupName = Sortable.entries.map { it.label }.toTypedArray() val groupName = Sortable.values().map { it.label }.toTypedArray()
var sort = Sortable.ID var sort = Sortable.ID
val sortAndOrder = viewModel.getSortAndOrder() val sortAndOrder = viewModel.getSortAndOrder()
@@ -155,11 +154,11 @@ class FragmentMain : BaseFragment<MainViewModel>(R.layout.fragment_main), BackPr
.setSingleChoiceItems( .setSingleChoiceItems(
groupName, groupName,
checkedItem checkedItem
) { p0, p1 -> sort = Sortable.getEnumByType(groupName[p1]) } ) { _, p1 -> sort = Sortable.getEnumByType(groupName[p1]) }
.setPositiveButton("Ascending") { dialog, id -> .setPositiveButton("Ascending") { dialog, _ ->
viewModel.setSortAndOrder(sort) viewModel.setSortAndOrder(sort)
dialog.dismiss() dialog.dismiss()
}.setNegativeButton("Descending") { dialog, id -> }.setNegativeButton("Descending") { dialog, _ ->
viewModel.setSortAndOrder(sort, Order.DESCENDING) viewModel.setSortAndOrder(sort, Order.DESCENDING)
dialog.dismiss() dialog.dismiss()
} }
@@ -210,25 +209,25 @@ class FragmentMain : BaseFragment<MainViewModel>(R.layout.fragment_main), BackPr
super.onRequestPermissionsResult(requestCode, permissions, grantResults) super.onRequestPermissionsResult(requestCode, permissions, grantResults)
println("request code$requestCode") println("request code$requestCode")
if (requestCode == MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE) { if (requestCode == MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE) {
if (grantResults.size > 0 if (grantResults.isNotEmpty()
&& grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[0] == PackageManager.PERMISSION_GRANTED
) { ) {
exportDialog() exportDialog()
} else { } else {
Toast.makeText(context, "Storage Permissions denied", Toast.LENGTH_SHORT).show() displayToast("Storage Permissions denied")
} }
} }
} }
fun exportDialog() { private fun exportDialog() {
AlertDialog.Builder(context) AlertDialog.Builder(context)
.setTitle("Export?") .setTitle("Export?")
.setMessage("Exporting current filtered data. Continue?") .setMessage("Exporting current filtered data. Continue?")
.setNegativeButton(android.R.string.no, null) .setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.yes) { arg0, arg1 -> exportData() }.create().show() .setPositiveButton(android.R.string.ok) { _, _ -> exportData() }.create().show()
} }
fun checkStoragePermissions(activity: Activity?): Boolean { private fun checkStoragePermissions(activity: Activity?): Boolean {
var status = false var status = false
val permission = ActivityCompat.checkSelfPermission( val permission = ActivityCompat.checkSelfPermission(
activity!!, activity!!,

View File

@@ -1,5 +1,6 @@
package com.appttude.h_mal.farmr.ui package com.appttude.h_mal.farmr.ui
import android.annotation.SuppressLint
import android.app.AlertDialog import android.app.AlertDialog
import android.os.Bundle import android.os.Bundle
import android.view.ViewGroup import android.view.ViewGroup
@@ -28,6 +29,7 @@ class ShiftListAdapter(
return BaseRecyclerAdapter.CurrentViewHolder(currentViewHolder) return BaseRecyclerAdapter.CurrentViewHolder(currentViewHolder)
} }
@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: BaseRecyclerAdapter.CurrentViewHolder, position: Int) { override fun onBindViewHolder(holder: BaseRecyclerAdapter.CurrentViewHolder, position: Int) {
val view = holder.itemView val view = holder.itemView
val data = getItem(position) val data = getItem(position)
@@ -90,8 +92,8 @@ class ShiftListAdapter(
view.setOnLongClickListener { view.setOnLongClickListener {
AlertDialog.Builder(it.context) AlertDialog.Builder(it.context)
.setMessage("Are you sure you want to delete") .setMessage("Are you sure you want to delete")
.setPositiveButton("delete") { dialog, id -> longPressCallback.invoke(data.id) } .setPositiveButton("delete") { _, _ -> longPressCallback.invoke(data.id) }
.setNegativeButton("cancel") { dialog, id -> .setNegativeButton("cancel") { dialog, _ ->
dialog?.dismiss() dialog?.dismiss()
} }
.create().show() .create().show()

View File

@@ -1,5 +1,6 @@
package com.appttude.h_mal.farmr.ui package com.appttude.h_mal.farmr.ui
import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
@@ -13,6 +14,7 @@ import com.appttude.h_mal.farmr.R
/** /**
* Created by h_mal on 27/06/2017. * Created by h_mal on 27/06/2017.
*/ */
@SuppressLint("CustomSplashScreen")
class SplashScreen : Activity() { class SplashScreen : Activity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@@ -20,13 +22,9 @@ class SplashScreen : Activity() {
val i = Intent(this@SplashScreen, MainActivity::class.java) val i = Intent(this@SplashScreen, MainActivity::class.java)
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_CLEAR_TASK) i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_CLEAR_TASK)
Handler().postDelayed({ Handler(Looper.getMainLooper()).postDelayed({
// This method will be executed once the timer is over
// Start your app main activity
// startActivity(i,bundle);
startActivity(i) startActivity(i)
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out) overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out)
// finish();
}, SPLASH_TIME_OUT) }, SPLASH_TIME_OUT)
} }

View File

@@ -161,12 +161,12 @@ fun EditText.setDatePicker(onSelected: (String) -> Unit) {
} }
val mDatePicker = DatePickerDialog( val mDatePicker = DatePickerDialog(
(this.context), (this.context),
{ datepicker, selectedyear, selectedmonth, selectedday -> { _, selectedYear, selectedMonth, selectedDay ->
var currentMonth = selectedmonth var currentMonth = selectedMonth
val dateString = StringBuilder().append(selectedyear).append("-") val dateString = StringBuilder().append(selectedYear).append("-")
.append(String.format("%02d", (currentMonth + 1.also { currentMonth = it }))) .append(String.format("%02d", (currentMonth + 1.also { currentMonth = it })))
.append("-") .append("-")
.append(String.format("%02d", selectedday)) .append(String.format("%02d", selectedDay))
.toString() .toString()
setText(dateString) setText(dateString)
onSelected.invoke(dateString) onSelected.invoke(dateString)

View File

@@ -239,7 +239,7 @@ class MainViewModel(
val data = shiftLiveData.value!!.applyFilters() val data = shiftLiveData.value!!.applyFilters()
.sortList(sortAndOrder.first, sortAndOrder.second) .sortList(sortAndOrder.first, sortAndOrder.second)
var currentRow = 0 var currentRow = 0
val cells = data.mapIndexed { index, shift -> val cells = data.map { shift ->
currentRow += 1 currentRow += 1
listOf( listOf(
Label(0, currentRow, shift.id.toString()), Label(0, currentRow, shift.id.toString()),