mirror of
https://github.com/hmalik144/Farmr.git
synced 2025-12-10 02:25:19 +00:00
- lint checks completed
This commit is contained in:
6
.idea/kotlinc.xml
generated
Normal file
6
.idea/kotlinc.xml
generated
Normal 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>
|
||||
@@ -19,22 +19,24 @@ class ShiftProvider : ContentProvider() {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun query(uri: Uri, projection: Array<String>?, selection: String?, selectionArgs: Array<String>?,
|
||||
sortOrder: String?): Cursor? {
|
||||
var selection = selection
|
||||
var selectionArgs = selectionArgs
|
||||
override fun query(
|
||||
uri: Uri, projection: Array<String>?, selection: String?, selectionArgs: Array<String>?,
|
||||
sortOrder: String?
|
||||
): Cursor {
|
||||
val database = mDbHelper!!.readableDatabase
|
||||
val cursor: Cursor
|
||||
val match = sUriMatcher.match(uri)
|
||||
when (match) {
|
||||
SHIFTS -> cursor = database.query(ShiftsEntry.TABLE_NAME, projection, selection, selectionArgs,
|
||||
null, null, sortOrder)
|
||||
val cursor: Cursor = when (sUriMatcher.match(uri)) {
|
||||
SHIFTS -> database.query(
|
||||
ShiftsEntry.TABLE_NAME, projection, selection, selectionArgs,
|
||||
null, null, sortOrder
|
||||
)
|
||||
|
||||
SHIFT_ID -> {
|
||||
selection = ShiftsEntry._ID + "=?"
|
||||
selectionArgs = arrayOf(ContentUris.parseId(uri).toString())
|
||||
cursor = database.query(ShiftsEntry.TABLE_NAME, projection, selection, selectionArgs,
|
||||
null, null, sortOrder)
|
||||
val mSelection = ShiftsEntry._ID + "=?"
|
||||
val mSelectionArgs = arrayOf(ContentUris.parseId(uri).toString())
|
||||
database.query(
|
||||
ShiftsEntry.TABLE_NAME, projection, mSelection, mSelectionArgs,
|
||||
null, null, sortOrder
|
||||
)
|
||||
}
|
||||
|
||||
else -> throw IllegalArgumentException("Cannot query $uri")
|
||||
@@ -44,26 +46,25 @@ class ShiftProvider : ContentProvider() {
|
||||
}
|
||||
|
||||
override fun insert(uri: Uri, contentValues: ContentValues?): Uri? {
|
||||
val match = sUriMatcher.match(uri)
|
||||
return when (match) {
|
||||
return when (sUriMatcher.match(uri)) {
|
||||
SHIFTS -> insertShift(uri, contentValues)
|
||||
else -> throw IllegalArgumentException("Insertion is not supported for $uri")
|
||||
}
|
||||
}
|
||||
|
||||
private fun insertShift(uri: Uri, values: ContentValues?): Uri? {
|
||||
val description = values!!.getAsString(ShiftsEntry.COLUMN_SHIFT_DESCRIPTION)
|
||||
?: throw IllegalArgumentException("Description required")
|
||||
val date = values.getAsString(ShiftsEntry.COLUMN_SHIFT_DATE)
|
||||
?: throw IllegalArgumentException("Date required")
|
||||
val timeIn = values.getAsString(ShiftsEntry.COLUMN_SHIFT_TIME_IN)
|
||||
?: throw IllegalArgumentException("Time In required")
|
||||
val timeOut = values.getAsString(ShiftsEntry.COLUMN_SHIFT_TIME_OUT)
|
||||
?: throw IllegalArgumentException("Time Out required")
|
||||
values!!.getAsString(ShiftsEntry.COLUMN_SHIFT_DESCRIPTION)
|
||||
?: throw IllegalArgumentException("Description required")
|
||||
values.getAsString(ShiftsEntry.COLUMN_SHIFT_DATE)
|
||||
?: throw IllegalArgumentException("Date required")
|
||||
values.getAsString(ShiftsEntry.COLUMN_SHIFT_TIME_IN)
|
||||
?: throw IllegalArgumentException("Time In required")
|
||||
values.getAsString(ShiftsEntry.COLUMN_SHIFT_TIME_OUT)
|
||||
?: throw IllegalArgumentException("Time Out required")
|
||||
val duration = values.getAsFloat(ShiftsEntry.COLUMN_SHIFT_DURATION)
|
||||
require(duration >= 0) { "Duration cannot be negative" }
|
||||
val shiftType = values.getAsString(ShiftsEntry.COLUMN_SHIFT_TYPE)
|
||||
?: throw IllegalArgumentException("Shift type required")
|
||||
values.getAsString(ShiftsEntry.COLUMN_SHIFT_TYPE)
|
||||
?: throw IllegalArgumentException("Shift type required")
|
||||
val shiftUnits = values.getAsFloat(ShiftsEntry.COLUMN_SHIFT_UNIT)
|
||||
require(shiftUnits >= 0) { "Units cannot be negative" }
|
||||
val payRate = values.getAsFloat(ShiftsEntry.COLUMN_SHIFT_PAYRATE)
|
||||
@@ -82,43 +83,47 @@ class ShiftProvider : ContentProvider() {
|
||||
return ContentUris.withAppendedId(uri, id)
|
||||
}
|
||||
|
||||
override fun update(uri: Uri, contentValues: ContentValues?, selection: String?,
|
||||
selectionArgs: Array<String>?): Int {
|
||||
var selection = selection
|
||||
var selectionArgs = selectionArgs
|
||||
val match = sUriMatcher.match(uri)
|
||||
return when (match) {
|
||||
override fun update(
|
||||
uri: Uri, contentValues: ContentValues?, selection: String?,
|
||||
selectionArgs: Array<String>?
|
||||
): Int {
|
||||
return when (sUriMatcher.match(uri)) {
|
||||
SHIFTS -> updateShift(uri, contentValues, selection, selectionArgs)
|
||||
SHIFT_ID -> {
|
||||
selection = ShiftsEntry._ID + "=?"
|
||||
selectionArgs = arrayOf(ContentUris.parseId(uri).toString())
|
||||
updateShift(uri, contentValues, selection, selectionArgs)
|
||||
val mSelection = ShiftsEntry._ID + "=?"
|
||||
val mSelectionArgs = arrayOf(ContentUris.parseId(uri).toString())
|
||||
updateShift(uri, contentValues, mSelection, mSelectionArgs)
|
||||
}
|
||||
|
||||
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)) {
|
||||
val description = values.getAsString(ShiftsEntry.COLUMN_SHIFT_DESCRIPTION)
|
||||
?: throw IllegalArgumentException("description required")
|
||||
values.getAsString(ShiftsEntry.COLUMN_SHIFT_DESCRIPTION)
|
||||
?: throw IllegalArgumentException("description required")
|
||||
}
|
||||
if (values.containsKey(ShiftsEntry.COLUMN_SHIFT_DATE)) {
|
||||
val date = values.getAsString(ShiftsEntry.COLUMN_SHIFT_DATE)
|
||||
?: throw IllegalArgumentException("date required")
|
||||
values.getAsString(ShiftsEntry.COLUMN_SHIFT_DATE)
|
||||
?: throw IllegalArgumentException("date required")
|
||||
}
|
||||
if (values.containsKey(ShiftsEntry.COLUMN_SHIFT_TIME_IN)) {
|
||||
val timeIn = values.getAsString(ShiftsEntry.COLUMN_SHIFT_TIME_IN)
|
||||
?: throw IllegalArgumentException("time in required")
|
||||
values.getAsString(ShiftsEntry.COLUMN_SHIFT_TIME_IN)
|
||||
?: throw IllegalArgumentException("time in required")
|
||||
}
|
||||
if (values.containsKey(ShiftsEntry.COLUMN_SHIFT_TIME_OUT)) {
|
||||
val timeOut = values.getAsString(ShiftsEntry.COLUMN_SHIFT_TIME_OUT)
|
||||
?: throw IllegalArgumentException("time out required")
|
||||
values.getAsString(ShiftsEntry.COLUMN_SHIFT_TIME_OUT)
|
||||
?: throw IllegalArgumentException("time out required")
|
||||
}
|
||||
if (values.containsKey(ShiftsEntry.COLUMN_SHIFT_BREAK)) {
|
||||
val breaks = values.getAsString(ShiftsEntry.COLUMN_SHIFT_BREAK)
|
||||
?: throw IllegalArgumentException("break required")
|
||||
values.getAsString(ShiftsEntry.COLUMN_SHIFT_BREAK)
|
||||
?: throw IllegalArgumentException("break required")
|
||||
}
|
||||
if (values.size() == 0) {
|
||||
return 0
|
||||
@@ -132,17 +137,15 @@ class ShiftProvider : ContentProvider() {
|
||||
}
|
||||
|
||||
override fun delete(uri: Uri, selection: String?, selectionArgs: Array<String>?): Int {
|
||||
var selection = selection
|
||||
var selectionArgs = selectionArgs
|
||||
val database = mDbHelper!!.writableDatabase
|
||||
val rowsDeleted: Int
|
||||
val match = sUriMatcher.match(uri)
|
||||
when (match) {
|
||||
SHIFTS -> rowsDeleted = database.delete(ShiftsEntry.TABLE_NAME, selection, selectionArgs)
|
||||
val rowsDeleted: Int = when (sUriMatcher.match(uri)) {
|
||||
SHIFTS -> database.delete(ShiftsEntry.TABLE_NAME, selection, selectionArgs)
|
||||
|
||||
SHIFT_ID -> {
|
||||
selection = ShiftsEntry._ID + "=?"
|
||||
selectionArgs = arrayOf(ContentUris.parseId(uri).toString())
|
||||
rowsDeleted = database.delete(ShiftsEntry.TABLE_NAME, selection, selectionArgs)
|
||||
val mSelection = ShiftsEntry._ID + "=?"
|
||||
val mSelectionArgs = arrayOf(ContentUris.parseId(uri).toString())
|
||||
|
||||
database.delete(ShiftsEntry.TABLE_NAME, mSelection, mSelectionArgs)
|
||||
}
|
||||
|
||||
else -> throw IllegalArgumentException("Deletion is not supported for $uri")
|
||||
@@ -169,7 +172,11 @@ class ShiftProvider : ContentProvider() {
|
||||
|
||||
init {
|
||||
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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,6 @@ enum class Sortable(val label: String) {
|
||||
TOTALPAY("Total Pay");
|
||||
|
||||
companion object {
|
||||
val entries = Sortable.values()
|
||||
|
||||
fun getEnumByType(label: String): Sortable {
|
||||
return Sortable.values().first { it.label == label }
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ class FragmentMain : BaseFragment<MainViewModel>(R.layout.fragment_main), BackPr
|
||||
AlertDialog.Builder(context)
|
||||
.setTitle("Help & Support:")
|
||||
.setView(R.layout.dialog_layout)
|
||||
.setPositiveButton(android.R.string.yes) { arg0, arg1 -> arg0.dismiss() }
|
||||
.setPositiveButton(android.R.string.ok) { arg0, _ -> arg0.dismiss() }
|
||||
.create().show()
|
||||
return true
|
||||
}
|
||||
@@ -120,12 +120,11 @@ class FragmentMain : BaseFragment<MainViewModel>(R.layout.fragment_main), BackPr
|
||||
AlertDialog.Builder(context)
|
||||
.setTitle("Export?")
|
||||
.setMessage("Exporting current filtered data. Continue?")
|
||||
.setNegativeButton(android.R.string.no, null)
|
||||
.setPositiveButton(android.R.string.yes) { arg0, arg1 -> exportData() }
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ -> exportData() }
|
||||
.create().show()
|
||||
} else {
|
||||
Toast.makeText(context, "Storage permissions required", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
displayToast("Storage permissions required")
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -134,7 +133,7 @@ class FragmentMain : BaseFragment<MainViewModel>(R.layout.fragment_main), BackPr
|
||||
AlertDialog.Builder(context)
|
||||
.setTitle("Info:")
|
||||
.setMessage(viewModel.getInformation())
|
||||
.setPositiveButton(android.R.string.yes) { arg0, arg1 ->
|
||||
.setPositiveButton(android.R.string.ok) { arg0, _ ->
|
||||
arg0.dismiss()
|
||||
}.create().show()
|
||||
return true
|
||||
@@ -144,7 +143,7 @@ class FragmentMain : BaseFragment<MainViewModel>(R.layout.fragment_main), BackPr
|
||||
}
|
||||
|
||||
private fun sortData() {
|
||||
val groupName = Sortable.entries.map { it.label }.toTypedArray()
|
||||
val groupName = Sortable.values().map { it.label }.toTypedArray()
|
||||
var sort = Sortable.ID
|
||||
|
||||
val sortAndOrder = viewModel.getSortAndOrder()
|
||||
@@ -155,11 +154,11 @@ class FragmentMain : BaseFragment<MainViewModel>(R.layout.fragment_main), BackPr
|
||||
.setSingleChoiceItems(
|
||||
groupName,
|
||||
checkedItem
|
||||
) { p0, p1 -> sort = Sortable.getEnumByType(groupName[p1]) }
|
||||
.setPositiveButton("Ascending") { dialog, id ->
|
||||
) { _, p1 -> sort = Sortable.getEnumByType(groupName[p1]) }
|
||||
.setPositiveButton("Ascending") { dialog, _ ->
|
||||
viewModel.setSortAndOrder(sort)
|
||||
dialog.dismiss()
|
||||
}.setNegativeButton("Descending") { dialog, id ->
|
||||
}.setNegativeButton("Descending") { dialog, _ ->
|
||||
viewModel.setSortAndOrder(sort, Order.DESCENDING)
|
||||
dialog.dismiss()
|
||||
}
|
||||
@@ -210,25 +209,25 @@ class FragmentMain : BaseFragment<MainViewModel>(R.layout.fragment_main), BackPr
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
println("request code$requestCode")
|
||||
if (requestCode == MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE) {
|
||||
if (grantResults.size > 0
|
||||
if (grantResults.isNotEmpty()
|
||||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
exportDialog()
|
||||
} else {
|
||||
Toast.makeText(context, "Storage Permissions denied", Toast.LENGTH_SHORT).show()
|
||||
displayToast("Storage Permissions denied")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun exportDialog() {
|
||||
private fun exportDialog() {
|
||||
AlertDialog.Builder(context)
|
||||
.setTitle("Export?")
|
||||
.setMessage("Exporting current filtered data. Continue?")
|
||||
.setNegativeButton(android.R.string.no, null)
|
||||
.setPositiveButton(android.R.string.yes) { arg0, arg1 -> exportData() }.create().show()
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ -> exportData() }.create().show()
|
||||
}
|
||||
|
||||
fun checkStoragePermissions(activity: Activity?): Boolean {
|
||||
private fun checkStoragePermissions(activity: Activity?): Boolean {
|
||||
var status = false
|
||||
val permission = ActivityCompat.checkSelfPermission(
|
||||
activity!!,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.appttude.h_mal.farmr.ui
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.AlertDialog
|
||||
import android.os.Bundle
|
||||
import android.view.ViewGroup
|
||||
@@ -28,6 +29,7 @@ class ShiftListAdapter(
|
||||
return BaseRecyclerAdapter.CurrentViewHolder(currentViewHolder)
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun onBindViewHolder(holder: BaseRecyclerAdapter.CurrentViewHolder, position: Int) {
|
||||
val view = holder.itemView
|
||||
val data = getItem(position)
|
||||
@@ -90,8 +92,8 @@ class ShiftListAdapter(
|
||||
view.setOnLongClickListener {
|
||||
AlertDialog.Builder(it.context)
|
||||
.setMessage("Are you sure you want to delete")
|
||||
.setPositiveButton("delete") { dialog, id -> longPressCallback.invoke(data.id) }
|
||||
.setNegativeButton("cancel") { dialog, id ->
|
||||
.setPositiveButton("delete") { _, _ -> longPressCallback.invoke(data.id) }
|
||||
.setNegativeButton("cancel") { dialog, _ ->
|
||||
dialog?.dismiss()
|
||||
}
|
||||
.create().show()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.appttude.h_mal.farmr.ui
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
@@ -13,6 +14,7 @@ import com.appttude.h_mal.farmr.R
|
||||
/**
|
||||
* Created by h_mal on 27/06/2017.
|
||||
*/
|
||||
@SuppressLint("CustomSplashScreen")
|
||||
class SplashScreen : Activity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -20,13 +22,9 @@ class SplashScreen : Activity() {
|
||||
|
||||
val i = Intent(this@SplashScreen, MainActivity::class.java)
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||
Handler().postDelayed({
|
||||
// This method will be executed once the timer is over
|
||||
// Start your app main activity
|
||||
// startActivity(i,bundle);
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
startActivity(i)
|
||||
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out)
|
||||
// finish();
|
||||
}, SPLASH_TIME_OUT)
|
||||
}
|
||||
|
||||
|
||||
@@ -161,12 +161,12 @@ fun EditText.setDatePicker(onSelected: (String) -> Unit) {
|
||||
}
|
||||
val mDatePicker = DatePickerDialog(
|
||||
(this.context),
|
||||
{ datepicker, selectedyear, selectedmonth, selectedday ->
|
||||
var currentMonth = selectedmonth
|
||||
val dateString = StringBuilder().append(selectedyear).append("-")
|
||||
{ _, selectedYear, selectedMonth, selectedDay ->
|
||||
var currentMonth = selectedMonth
|
||||
val dateString = StringBuilder().append(selectedYear).append("-")
|
||||
.append(String.format("%02d", (currentMonth + 1.also { currentMonth = it })))
|
||||
.append("-")
|
||||
.append(String.format("%02d", selectedday))
|
||||
.append(String.format("%02d", selectedDay))
|
||||
.toString()
|
||||
setText(dateString)
|
||||
onSelected.invoke(dateString)
|
||||
|
||||
@@ -239,7 +239,7 @@ class MainViewModel(
|
||||
val data = shiftLiveData.value!!.applyFilters()
|
||||
.sortList(sortAndOrder.first, sortAndOrder.second)
|
||||
var currentRow = 0
|
||||
val cells = data.mapIndexed { index, shift ->
|
||||
val cells = data.map { shift ->
|
||||
currentRow += 1
|
||||
listOf(
|
||||
Label(0, currentRow, shift.id.toString()),
|
||||
|
||||
Reference in New Issue
Block a user