Untitled

mail@pastecode.io avatar
unknown
kotlin
2 years ago
5.8 kB
2
Indexable
Never
grid.onItemClickListener = OnItemClickListener { parent, view, position, id ->
            val selectedItem = parent.getItemAtPosition(position) as GridElement

             if(falseclickposition == "Before") {
                    if (satisfied < falseclickcount) {
                        if (currentCombinationPosition == 0 && satisfied < falseclickcount) {
                            satisfied++

                            updateBottomSheet(toptext, inputtednum, bottomSheetAdapter)
                            return@OnItemClickListener
                        }
                    }
                }

                if(falseclickposition == "After" && currentCombinationPosition == combination.chunked(5).size){
                    if(satisfied < falseclickcount){
                            satisfied++
                        updateBottomSheet(toptext, inputtednum, bottomSheetAdapter)
                        return@OnItemClickListener
                        }
                }


            if(arrowCombinations.getOrNull(currentCombinationPosition) == null){
                inputtedElements.add(null)
                updateBottomSheet(toptext, inputtednum, bottomSheetAdapter)
                return@OnItemClickListener
            }

             if(foreignfile!!){

                 arrowCombinations = config.getString("$destination+combination").chunked(5).toCollection(ArrayList())
             } else {
                 arrowCombinations = config.getString("PKcombination").chunked(5).toCollection(ArrayList())
             }

             var currentElement: String = arrowCombinations[currentCombinationPosition]

            println("Curr el: $currentElement")
             // TODO: think about this
            if(currentElement == "KeYaR" || currentElement == "FiShA" || currentElement == "AiRaR" || currentElement == "MaNaR"
                || currentElement == "ArrTw" || currentElement == "ColAr" || currentElement == "ImgAr" || currentElement == "LetAr" ) {
                gridElementsArray.forEachIndexed { index, arrayOfGridElements ->
                    arrayOfGridElements.forEachIndexed { sndindex, gridElement ->
                        if(gridElement == selectedItem){

                            if(currentElement == "ColAr" || currentElement == "ImgAr" || currentElement == "LetAr"){
                                var result = checkArrowsSymbol(file, index, sndindex, "ArRoWdOwNbLaCk", currentElement, gridElementsArray[index][sndindex])
                                if(result == "Nthng"){
                                    val combinationEdit = combination.chunked(5).toMutableList()
                                        if(combinationEdit[currentCombinationPosition - 1] == "ImgAr" || combinationEdit[currentCombinationPosition - 1] == "ColAr" || combinationEdit[currentCombinationPosition - 1] == "LetAr" ){
                                            combinationEdit[currentCombinationPosition - 1] = "Nthng"
                                        }
                                    combination = combinationEdit.joinToString("")

                                } else {
                                    val combinationEdit = combination.chunked(5).toMutableList()
                                    if(combinationEdit[currentCombinationPosition - 1] == "Nthng"){
                                        combinationEdit[currentCombinationPosition - 1] = result
                                    }
                                    combination = combinationEdit.joinToString("")
                                }


                            }
                            // TODO: Refactor this too!!
                            if(currentElement == "FiShA") {
                                checkArrows(index, sndindex, "FiShArRoW")
                            } else if(currentElement == "AiRaR"){
                                checkArrows(index, sndindex, "AiRpLaNeArRoW")
                            } else if(currentElement == "MaNaR") {
                                checkArrows(index, sndindex, "MaNaRrOw")
                            }
                            else if(currentElement == "KeYaR"){
                                checkArrows(index, sndindex, "KeYaRrOw")
                            }
                            else if(currentElement == "ArrTw"){
                                val TopArrow = gridElementsArray.getOrNull(index + 1)?.getOrNull(sndindex)
                                if(TopArrow?.whiteNumber?.key == "ArRoWuP"){
                                    inputtedElements.add(TopArrow)
                                    currentCombinationPosition++
                                } else if(TopArrow == null || TopArrow.whiteNumber.key != "ArRoWuP"){
                                    inputtedElements.add(null)
                                    currentCombinationPosition++
                                }
                            }
                        }
                    }
                }
            } else {
                
                        if(selectedItem.whiteNumber.name != selectedItem.whiteNumber.key){
                            inputtedElements.add(GridElement(selectedItem.color, selectedItem.img, WhiteNumbers.valueOf(selectedItem.whiteNumber.key), selectedItem.blackNumber))
                        } else {
                            inputtedElements.add(selectedItem)

                        }

                if(falseclickposition == "Before"){
                    if(satisfied >= falseclickcount){

                        currentCombinationPosition++
                    }
                } else {
                    currentCombinationPosition++
                }

            }




            updateBottomSheet(toptext, inputtednum, bottomSheetAdapter)
        }