-
Notifications
You must be signed in to change notification settings - Fork 1
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
68 respective gaps #69
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4ddfac3
Added LocalFarmCycle: Data class
30d5961
Added some recycler view adapter
f6665af
Attach data, and fix some bugs
69cee2d
Some fixes
b9ae5ce
Filtering locally saved crop cycles working!
7e3ca32
Debugging done, another release and update
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
app/src/main/java/com/steve_md/smartmkulima/adapter/others/LocalFarmCycleAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.steve_md.smartmkulima.adapter.others | ||
|
||
import android.annotation.SuppressLint | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.DiffUtil | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.steve_md.smartmkulima.databinding.CropCycleTaskRowBinding | ||
import com.steve_md.smartmkulima.model.LocalFarmCycle | ||
|
||
/** | ||
* Attach data to locally created Farm cycles to Room DB | ||
*/ | ||
class LocalFarmCycleAdapter(private val onClickListener: OnClickListener) : | ||
ListAdapter<LocalFarmCycle, LocalFarmCycleAdapter.MyViewHolder>(TaskDiffUtil) { | ||
|
||
object TaskDiffUtil : DiffUtil.ItemCallback<LocalFarmCycle>() { | ||
override fun areItemsTheSame(oldItem: LocalFarmCycle, newItem: LocalFarmCycle): Boolean { | ||
return oldItem == newItem | ||
} | ||
|
||
override fun areContentsTheSame(oldItem: LocalFarmCycle, newItem: LocalFarmCycle): Boolean { | ||
return oldItem.cropName == newItem.cropName | ||
} | ||
} | ||
|
||
inner class MyViewHolder(private var binding: CropCycleTaskRowBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
|
||
@SuppressLint("SetTextI18n") | ||
fun bind(cycle: LocalFarmCycle?) { | ||
binding.farmID.text = cycle?.farmName | ||
binding.cycleData.text = cycle?.cropName | ||
binding.dateForCycle.text = cycle?.startDate | ||
binding.textView85.text = "Crop cycle" | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { | ||
return MyViewHolder( | ||
CropCycleTaskRowBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
) | ||
} | ||
|
||
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { | ||
val cycle = getItem(position) | ||
holder.bind(cycle) | ||
|
||
holder.itemView.setOnClickListener { | ||
onClickListener.onClick(cycle = cycle) | ||
} | ||
} | ||
|
||
class OnClickListener(val clickListener: (cycle: LocalFarmCycle) -> Unit) { | ||
fun onClick(cycle: LocalFarmCycle) = clickListener(cycle) | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
app/src/main/java/com/steve_md/smartmkulima/adapter/others/LocalFarmCycleTasksAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.steve_md.smartmkulima.adapter.others | ||
|
||
import android.annotation.SuppressLint | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.steve_md.smartmkulima.databinding.DetailCycleRowBinding | ||
import com.steve_md.smartmkulima.model.LocalTasks | ||
|
||
/** | ||
* Able to view actual tasks for cycle - respective tasks | ||
*/ | ||
class LocalFarmCycleTasksAdapter : RecyclerView.Adapter<LocalFarmCycleTasksAdapter.TaskViewHolder>() { | ||
|
||
private var tasks: List<LocalTasks> = ArrayList() | ||
|
||
inner class TaskViewHolder(private val binding: DetailCycleRowBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
|
||
fun bind(task: LocalTasks) { | ||
binding.textView75.text = task.taskName | ||
binding.textView76.text = task.startDate | ||
binding.textView77.text = task.endDate | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TaskViewHolder { | ||
val binding = | ||
DetailCycleRowBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
return TaskViewHolder(binding) | ||
} | ||
|
||
override fun onBindViewHolder(holder: TaskViewHolder, position: Int) { | ||
val task = tasks[position] | ||
holder.bind(task) | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return tasks.size | ||
} | ||
|
||
@SuppressLint("NotifyDataSetChanged") | ||
fun submitList(taskList: List<LocalTasks>) { | ||
tasks = taskList | ||
notifyDataSetChanged() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
app/src/main/java/com/steve_md/smartmkulima/data/repositories/FarmCycleRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.steve_md.smartmkulima.data.repositories | ||
|
||
import androidx.lifecycle.LiveData | ||
import com.steve_md.smartmkulima.data.room.AppDatabase | ||
import com.steve_md.smartmkulima.data.room.GAPDao | ||
import com.steve_md.smartmkulima.data.room.LocalFarmCycleDao | ||
import com.steve_md.smartmkulima.model.Cycle | ||
import com.steve_md.smartmkulima.model.GAP | ||
import com.steve_md.smartmkulima.model.LocalFarmCycle | ||
import com.steve_md.smartmkulima.utils.apiRequestByResource | ||
import com.steve_md.smartmkulima.utils.safeCall | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
import javax.inject.Inject | ||
|
||
/** | ||
* Farm cycles repository | ||
* Manual creating of repositories | ||
*/ | ||
class FarmCycleRepository @Inject constructor( | ||
database: AppDatabase | ||
) { | ||
private val gapDao: GAPDao = database.gapDao() | ||
|
||
private val localCycleDao: LocalFarmCycleDao = database.localFarmCycleDao() | ||
|
||
suspend fun insertCycle(cycle: LocalFarmCycle) = apiRequestByResource { | ||
localCycleDao.insertLocalFarmCycle(cycle) | ||
} | ||
|
||
val allCycles : Flow<List<Cycle>> = gapDao.getAllCycle() | ||
|
||
|
||
|
||
|
||
fun getAllCycles(): LiveData<List<LocalFarmCycle>> { | ||
return localCycleDao.getAllFarmCycle() | ||
} | ||
|
||
suspend fun updateTaskStatus(status: String) { | ||
localCycleDao.updateTaskStatus(status) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/steve_md/smartmkulima/data/room/GAPDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.steve_md.smartmkulima.data.room | ||
|
||
import androidx.room.* | ||
import com.steve_md.smartmkulima.model.Cycle | ||
import com.steve_md.smartmkulima.model.GAP | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
@Dao | ||
interface GAPDao { | ||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun insertGAP(cycle: Cycle) | ||
|
||
@Query("SELECT * FROM cycle") | ||
fun getAllCycle(): Flow<List<Cycle>> | ||
|
||
@Delete | ||
suspend fun deleteGAP(cycle: Cycle) | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/steve_md/smartmkulima/data/room/LocalFarmCycleDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.steve_md.smartmkulima.data.room | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.Query | ||
import androidx.room.Update | ||
import com.steve_md.smartmkulima.model.LocalFarmCycle | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
|
||
@Dao | ||
interface LocalFarmCycleDao { | ||
|
||
@Insert | ||
suspend fun insertLocalFarmCycle(localFarmCycle: LocalFarmCycle) | ||
|
||
@Update | ||
suspend fun updateLocalFarmCycle(localFarmCycle: LocalFarmCycle) | ||
|
||
@Query("SELECT * FROM localcycle WHERE cropName = :cropName") | ||
suspend fun getFarmCycleBYName(cropName: String): LocalFarmCycle? | ||
|
||
@Query("SELECT * FROM localcycle") | ||
fun getAllFarmCycle(): LiveData<List<LocalFarmCycle>> | ||
|
||
@Query("UPDATE localcycle SET status = :status") | ||
suspend fun updateTaskStatus(status: String) | ||
} |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/com/steve_md/smartmkulima/data/room/converters/GAPConverters.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.steve_md.smartmkulima.data.room.converters | ||
|
||
import androidx.room.TypeConverter | ||
import com.google.gson.Gson | ||
import com.google.gson.reflect.TypeToken | ||
import com.steve_md.smartmkulima.model.Cycle | ||
import com.steve_md.smartmkulima.model.GAPtask | ||
import com.steve_md.smartmkulima.model.Tasks | ||
|
||
class Converters { | ||
@TypeConverter | ||
fun fromTasksList(tasks: List<Tasks>?): String? { | ||
return Gson().toJson(tasks) | ||
} | ||
|
||
@TypeConverter | ||
fun toTasksList(tasksString: String?): List<Tasks>? { | ||
val listType = object : TypeToken<List<Tasks>>() {}.type | ||
return Gson().fromJson(tasksString, listType) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/steve_md/smartmkulima/data/room/converters/LocalFarmCycleConverter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.steve_md.smartmkulima.data.room.converters | ||
|
||
import androidx.room.TypeConverter | ||
import com.google.gson.Gson | ||
import com.google.gson.reflect.TypeToken | ||
import com.steve_md.smartmkulima.model.LocalTasks | ||
|
||
class LocalFarmCycleConverter { | ||
@TypeConverter | ||
fun fromLocalTasksList(value: List<LocalTasks>?): String { | ||
val gson = Gson() | ||
val type = object : TypeToken<List<LocalTasks>>() {}.type | ||
return gson.toJson(value, type) | ||
} | ||
|
||
@TypeConverter | ||
fun toLocalTasksList(value: String): List<LocalTasks>? { | ||
val gson = Gson() | ||
val type = object : TypeToken<List<LocalTasks>>() {}.type | ||
return gson.fromJson(value, type) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome ; @converters in Room DB