@@ -57,6 +57,10 @@ class TaskActivity : AppCompatActivity(), FolderSelectorCallback{
5757 private lateinit var switchDeleteExcluded: Switch
5858
5959
60+ private lateinit var onFailDropdown: Spinner
61+ private lateinit var onSuccessDropdown: Spinner
62+
63+
6064 private lateinit var filterOptionsButton: ImageButton
6165
6266
@@ -125,6 +129,8 @@ class TaskActivity : AppCompatActivity(), FolderSelectorCallback{
125129 syncDescription = findViewById(R .id.descriptionSyncDirection)
126130 filterDropdown = findViewById(R .id.task_filter_spinner)
127131 switchDeleteExcluded = findViewById(R .id.task_exclude_delete_toggle)
132+ onFailDropdown = findViewById(R .id.task_onFail_spinner)
133+ onSuccessDropdown = findViewById(R .id.task_onSuccess_spinner)
128134 fab = findViewById(R .id.saveButton)
129135 switchWifi = findViewById(R .id.task_wifionly)
130136 switchMD5sum = findViewById(R .id.task_md5sum)
@@ -161,7 +167,7 @@ class TaskActivity : AppCompatActivity(), FolderSelectorCallback{
161167 val filter = if (filterDropdown.selectedItemPosition > 0 && filterDropdown.selectedItemPosition < filterDropdown.count) filterItems[filterDropdown.selectedItemPosition - 1 ] else null
162168 showFilterMenu(filterOptionsButton, filter)
163169 }
164- createNewFilterButton = findViewById< Button > (R .id.task_edit_filter_add_button)
170+ createNewFilterButton = findViewById(R .id.task_edit_filter_add_button)
165171 createNewFilterButton.setOnClickListener {
166172 openFilterActivity()
167173 }
@@ -174,16 +180,32 @@ class TaskActivity : AppCompatActivity(), FolderSelectorCallback{
174180 prepareLocal()
175181 prepareRemote()
176182 prepareFilterDropdown()
183+ prepareOnFailDropdown()
184+ prepareOnSuccessDropdown()
177185 }
178186
179187 private val remoteItems: Array <String ?>
180- private get() {
188+ get() {
181189 val remotes = arrayOfNulls<String >(rcloneInstance.remotes.size)
182190 for (i in rcloneInstance.remotes.indices) {
183191 remotes[i] = rcloneInstance.remotes[i].name
184192 }
185193 return remotes
186194 }
195+
196+ private val taskListWithNone: ArrayList <TaskNameIdPair >
197+ get() {
198+ val tasks = dbHandler.allTasks
199+ val list = ArrayList <TaskNameIdPair >()
200+ list.add(TaskNameIdPair (- 1 , " None" ))
201+ tasks.forEach{
202+ list.add(TaskNameIdPair (it.id, it.title))
203+ }
204+ return list
205+ }
206+
207+
208+
187209 private val filterItems: List <Filter >
188210 get() {
189211 return dbHandler.allFilters
@@ -229,7 +251,9 @@ class TaskActivity : AppCompatActivity(), FolderSelectorCallback{
229251 taskToPopulate.wifionly = switchWifi.isChecked
230252 taskToPopulate.md5sum = switchMD5sum.isChecked
231253 taskToPopulate.deleteExcluded = switchDeleteExcluded.isChecked
232- taskToPopulate.filterId = if (filterDropdown.selectedItemPosition == 0 ) null else filterItems[filterDropdown.selectedItemPosition - 1 ].id
254+ taskToPopulate.filterId = if (filterDropdown.selectedItemPosition == 0 || filterDropdown.selectedItemPosition == - 1 ) null else filterItems[filterDropdown.selectedItemPosition - 1 ].id
255+ taskToPopulate.onFailFollowup = (onFailDropdown.selectedItem as TaskNameIdPair ).id
256+ taskToPopulate.onSuccessFollowup = (onSuccessDropdown.selectedItem as TaskNameIdPair ).id
233257
234258 // Verify if data is completed
235259 if (localPath.text.toString() == " " ) {
@@ -267,6 +291,7 @@ class TaskActivity : AppCompatActivity(), FolderSelectorCallback{
267291 remotePath.setText(remotePathHolder)
268292 fab.visibility = View .VISIBLE
269293 }
294+
270295 private fun selectFilter (filterId : Long ) {
271296 prepareFilterDropdown()
272297
@@ -290,6 +315,7 @@ class TaskActivity : AppCompatActivity(), FolderSelectorCallback{
290315 }
291316 }
292317 }
318+
293319 private fun prepareRemote () {
294320
295321 remotePathHolder = existingTask?.remotePath.toString()
@@ -327,6 +353,54 @@ class TaskActivity : AppCompatActivity(), FolderSelectorCallback{
327353 }
328354 }
329355 }
356+
357+ private fun prepareOnFailDropdown () {
358+ onFailDropdown.adapter = ArrayAdapter (this , android.R .layout.simple_spinner_dropdown_item, taskListWithNone)
359+ var i = 0
360+ var found = 0
361+ taskListWithNone.forEach{
362+ if (it.id == (existingTask?.onFailFollowup ? : - 1 )) {
363+ found = i
364+ }
365+ i++
366+ }
367+ onFailDropdown.setSelection(found)
368+
369+ onFailDropdown.onItemSelectedListener = object : AdapterView .OnItemSelectedListener {
370+ override fun onItemSelected (parentView : AdapterView <* >? , selectedItemView : View , position : Int , id : Long ) {
371+ val pair = parentView?.selectedItem as TaskNameIdPair
372+ existingTask?.onFailFollowup = pair.id
373+ }
374+
375+ override fun onNothingSelected (parentView : AdapterView <* >? ) {}
376+ }
377+ }
378+
379+ private fun prepareOnSuccessDropdown () {
380+ onSuccessDropdown.adapter = ArrayAdapter (this , android.R .layout.simple_spinner_dropdown_item, taskListWithNone)
381+ var i = 0
382+ var found = 0
383+ taskListWithNone.forEach{
384+ if (it.id == (existingTask?.onSuccessFollowup ? : - 1 )) {
385+ found = i
386+ }
387+ i++
388+ }
389+ onSuccessDropdown.setSelection(found)
390+
391+
392+ onSuccessDropdown.onItemSelectedListener = object : AdapterView .OnItemSelectedListener {
393+ override fun onItemSelected (parentView : AdapterView <* >? , selectedItemView : View , position : Int , id : Long ) {
394+ val pair = parentView?.selectedItem as TaskNameIdPair
395+ existingTask?.onSuccessFollowup = pair.id
396+ }
397+
398+ override fun onNothingSelected (parentView : AdapterView <* >? ) {}
399+ }
400+ }
401+
402+
403+
330404 private fun prepareFilterDropdown () {
331405 val filterList = filterItems.toMutableList()
332406
@@ -444,4 +518,10 @@ class TaskActivity : AppCompatActivity(), FolderSelectorCallback{
444518 const val REQUEST_CODE_FILTER = 333
445519
446520 }
521+
522+ inner class TaskNameIdPair (var id : Long , private var name : String ) {
523+ override fun toString (): String {
524+ return name
525+ }
526+ }
447527}
0 commit comments