如何在另一个垂直recyclerview中实现垂直recyclerview

时间:2018-09-17 11:27:43

标签: android android-recyclerview kotlin

我是android开发的新手。我正在开发一个需要在另一个垂直RecyclerView中使用垂直RecyclerView的应用程序。我创建了它,但是问题是我想根据外部RecyclerView元素对内部RecyclerView元素进行分组。

我已附上代码以供参考!

private fun ResponsibilityExpListFun() {

        CommonFunctions.hideSoftKeyboard(this@DailyTasksPage)
        builder = AlertDialog.Builder(this@DailyTasksPage)
        inflater = layoutInflater
        dialogView = inflater!!.inflate(R.layout.expandable_list_dialog, null)
        dialog = builder!!.create()
        expandableListView = dialogView!!.findViewById(R.id.expandablelistview) as ExpandableListView
        dialog!!.setView(dialogView)
        expandableListView?.setAdapter(TaskResponsibiltyExpandableAdapter(this, expandableListView!!, header, body))
        dialog!!.show()
        dialog!!.setCancelable(true)
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_daily_tasks)
        setSupportActionBar(daily_task_toolbar)

        daily_task_toolbar.navigationIcon = resources.getDrawable(R.drawable.back_icon)
        daily_task_toolbar.setNavigationOnClickListener { finish() }

        /* daily_Task_Refresh.setOnRefreshListener {
             try {
                 onStart()
             } catch (e: Exception) {
                 e.printStackTrace()
             }
         }*/
        daily_Task_Refresh.isEnabled = false
        val sharedPreferences = getSharedPreferences("App_Details", Context.MODE_PRIVATE)
        strMobileIdentifier = sharedPreferences.getString("IMEI_NUMBER", null)
        strTokenSecret = sharedPreferences.getString("TOKEN_SECRET", null)

        var linearLayoutManager = LinearLayoutManager(this)

        Daily_Tasks_recyclerview?.layoutManager = linearLayoutManager
        ahowalltaskadapter = AllTaskAdapter(slotIDarrayList)
        Daily_Tasks_recyclerview.adapter = ahowalltaskadapter
        cayyoverslotadapter = CarryOverSlotAdapter(previousSlotarrayList)


        //ahowalltaskadapter = ahowalltaskadapter(slotIDarrayList)


        /* preplan_Image_Toggle.setOnClickListener {
             preplan_Image_ToggleUp.visibility = View.VISIBLE
             preplan_Image_Toggle.visibility = View.GONE
             PrePlanTaskRecyclerView.visibility = View.VISIBLE
         }

         preplan_Image_ToggleUp.setOnClickListener {
             preplan_Image_Toggle.visibility = View.VISIBLE
             preplan_Image_ToggleUp.visibility = View.GONE
             PrePlanTaskRecyclerView.visibility = View.GONE
         }*/

        fab_btn_DailyTask.setOnClickListener { it ->
            builder = AlertDialog.Builder(this)
            inflater = layoutInflater
            dialogView = inflater!!.inflate(R.layout.edit_curremt_slot, null)
            dialog = builder!!.create()
            layout = dialogView!!.findViewById(R.id.edit_current_slot_cardview) as CardView
            taskName = dialogView!!.findViewById(R.id.edit_content) as TextInputEditText
            taskResp = dialogView!!.findViewById(R.id.edit_resp_content) as TextView
            taskPackage = dialogView!!.findViewById(R.id.edit_prod_content) as TextView
            taskPriority = dialogView!!.findViewById(R.id.edit_priority_content) as TextView
            SaveBtn = dialogView!!.findViewById(R.id.SaveEditSlot) as Button
            CancelBtn = dialogView!!.findViewById(R.id.cancelEditSlot) as Button
            layout!!.setOnClickListener {
                CommonFunctions.hideSoftKeyboard(activity = this@DailyTasksPage)
            }

            CancelBtn!!.setOnClickListener {
                dialog!!.dismiss()
            }
            // expandableListView = dialogView!!.findViewById(R.id.expandablelistview) as ExpandableListView

            dialog!!.show()
            taskResp!!.setOnClickListener {
                count = 1
                ResponsibilityExpListFun()
            }
            taskPackage!!.setOnClickListener {
                count = 2
                PackageExpListFun()
            }
            taskPriority!!.setOnClickListener {
                PriorityFun()
            }

            SaveBtn!!.setOnClickListener {
                strTaskName = taskName!!.text.toString()
                if (strTaskName.isNullOrEmpty()) {
                    Snackbar.make(dialogView!!, "Task Name field is empty", Snackbar.LENGTH_LONG).show()
                    return@setOnClickListener
                }
                if (taskResp!!.text.isNullOrEmpty()) {
                    Snackbar.make(dialogView!!, "Task Responsibility field is empty", Snackbar.LENGTH_LONG).show()
                    return@setOnClickListener
                }

                if (taskPriority!!.text.isNullOrEmpty()) {
                    Snackbar.make(dialogView!!, "Task Priority field is empty", Snackbar.LENGTH_LONG).show()
                    return@setOnClickListener
                }
                AddTaskFunction()
                dialog!!.dismiss()
            }

            // expandableListView?.setAdapter(TaskResponsibiltyExpandableAdapter(this, expandableListView!!, header, body))
            dialog!!.setView(dialogView)
            dialog!!.show()
            //  dialog!!.setCancelable(false)


        }
    }
    inner class AllTaskAdapter(val alltaskList: ArrayList<SlotIDClass>) : RecyclerView.Adapter<AllTaskAdapter.ViewHolderAdapter>() {
        var slotName: String? = null

        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AllTaskAdapter.ViewHolderAdapter {
            val View = LayoutInflater.from(parent.context).inflate(R.layout.previous_slot_format, parent, false)
            val sharedPreferences = View.context.getSharedPreferences("App_Details", Context.MODE_PRIVATE)
            slotName = sharedPreferences.getString("SlotName", null)
            return ViewHolderAdapter(View)
        }

        override fun getItemCount(): Int {
            return alltaskList.size
        }

        override fun onBindViewHolder(holder: AllTaskAdapter.ViewHolderAdapter, position: Int) {

            val layoutManager = CustomLinearLayoutManager(holder.itemView.context)
            taskinnerAdapter = RunningTaskAdapter(currTaskarrayList)
            holder.DailyTasks_Recyclerview!!.setLayoutManager(layoutManager)
            holder.DailyTasks_Recyclerview!!.addItemDecoration(DividerItemDecoration(holder.DailyTasks_Recyclerview!!.context, DividerItemDecoration.VERTICAL))

            holder.DailyTasks_Recyclerview!!.adapter = taskinnerAdapter
            println("Running tASK aDaPtEr------------------------------" + ahowalltaskadapter.toString())
            holder.SlotName!!.text = alltaskList.get(position).SlotName

            if (holder.SlotName!!.text.equals(slotName)) {
                holder.title_prev_slot!!.setBackgroundColor(holder.itemView.resources.getColor(R.color.dark_orange))
                holder.strShowime!!.visibility = View.VISIBLE

                var SlotTime = (ToMilliseconds!! - CurrentMilliseconds!!).toLong()
                object : CountDownTimer(SlotTime.toLong(), 1000) {

                    override fun onTick(millisUntilFinished: Long) {
                        strShowime = String.format(Locale.getDefault(), "Time Remaining %02d hour %02d min %02d sec",
                                TimeUnit.MILLISECONDS.toHours(millisUntilFinished),
                                TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) % 60,
                                TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) % 60)
                        holder.strShowime!!.setText(strShowime)
                    }

                    override fun onFinish() {
                        onStart()
                        GetCurrentSlot()
                    }
                }.start()


                Toast.makeText(holder.itemView.context.applicationContext, strShowime, Toast.LENGTH_LONG).show()
            }

        }

        inner class ViewHolderAdapter(view: View) : RecyclerView.ViewHolder(view), View.OnClickListener {
            override fun onClick(v: View?) {
                TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
            }

            var DailyTasks_Recyclerview: RecyclerView? = null
            var SlotName: TextView? = null
            var title_prev_slot: RelativeLayout? = null
            var strShowime: TextView? = null

            init {
                this.DailyTasks_Recyclerview = view.findViewById(R.id.Daily_Tasks_recyclerview) as RecyclerView
                this.SlotName = view.findViewById(R.id.prev_SlotName) as TextView
                this.title_prev_slot = view.findViewById(R.id.title_prev_slot) as RelativeLayout
                this.strShowime = view.findViewById(R.id.strShowime) as TextView
            }
        }

    }

    inner class RunningTaskAdapter(val runningtaskList: ArrayList<TaskDetailsDataClass>) : RecyclerView.Adapter<RunningTaskAdapter.RunningTaskViewHolder>() {
        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RunningTaskAdapter.RunningTaskViewHolder {
            val view = LayoutInflater.from(parent.context).inflate(R.layout.runningtasks_format, parent, false)
            return RunningTaskViewHolder(view)
        }

        override fun getItemCount(): Int {
            return runningtaskList.size
        }

        override fun onBindViewHolder(holder: RunningTaskAdapter.RunningTaskViewHolder, position: Int) {
            holder.tasknameText?.text = runningtaskList.get(position).strTaskName
            holder.respnameText?.text = runningtaskList.get(position).strRespName
            holder.priorityIDText?.text = runningtaskList.get(position).intPriorityID.toString()
            holder.TaskStatusText?.text = runningtaskList.get(position).intTaskStatusID.toString()
            holder.PackageText?.text = runningtaskList.get(position).PackageName
            holder.intTaskID?.text = runningtaskList.get(position).intTaskID.toString()
            holder.intTimeElapsed?.text = runningtaskList.get(position).intTimeElapsed.toString()
            holder.intinitial_time_elapsed?.text = runningtaskList.get(position).intinitial_time_elapsed.toString()
            holder.strRemarks?.text = runningtaskList.get(position).strRemarks
            //  holder.ResumeTime?.text = runningtaskList.get(position).ResumeTime

            if (holder.TaskStatusText!!.text.equals("1")) {
                holder.running_task_Image!!.visibility = View.VISIBLE
            } else {
                holder.running_task_Image!!.visibility = View.INVISIBLE
            }
            holder.RunningTaskCardView!!.setOnClickListener {

                holder.itemView.context.startActivity(Intent(holder.itemView.context, CurrentTaskDetails::class.java)
                        .putExtra("Task_Name", holder.tasknameText?.text.toString())
                        .putExtra("Responsibility_Name", holder.respnameText?.text.toString())
                        .putExtra("Package_Name", holder.PackageText?.text.toString())
                        .putExtra("TaskStatusID", holder.TaskStatusText?.text.toString())
                        .putExtra("Task_ID", holder.intTaskID?.text.toString())
                        .putExtra("Time_Elapsed", holder.intTimeElapsed?.text.toString())
                        .putExtra("Initial_Time_Elapsed", holder.intinitial_time_elapsed?.text.toString())
                        .putExtra("PriorityID", holder.priorityIDText?.text.toString())
                        .putExtra("Remarks", holder.strRemarks?.text.toString()))

                // val activity = holder.itemView.getContext() as AppCompatActivity
                // val fragment = CurrentTaskDetails()
                // val arguments = Bundle()
                // arguments.putString("Task_Name", holder.tasknameText?.text.toString())
                // arguments.putString("Responsibility_Name", holder.respnameText?.text.toString())
                // fragment.setArguments(arguments)
                // activity.supportFragmentManager.beginTransaction().replace(R.id.daily_task_layout, fragment).addToBackStack(null).commit()

            }

        }

        inner class RunningTaskViewHolder(v: View) : RecyclerView.ViewHolder(v), View.OnClickListener {
            override fun onClick(v: View?) {
                TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
            }

            var running_task_Image: ImageView? = null
            var tasknameText: TextView? = null
            var respnameText: TextView? = null
            var priorityIDText: TextView? = null
            var TaskStatusText: TextView? = null
            var RunningTaskCardView: CardView? = null
            var PackageText: TextView? = null
            var intTaskID: TextView? = null
            var intTimeElapsed: TextView? = null
            var intinitial_time_elapsed: TextView? = null
            var strRemarks: TextView? = null


            init {
                this.tasknameText = v.findViewById(R.id.task_name_rt_format) as TextView
                this.respnameText = v.findViewById(R.id.task_responsibilty_rt_format) as TextView
                this.running_task_Image = v.findViewById(R.id.running_task_Image) as ImageView
                this.priorityIDText = v.findViewById(R.id.priority_id_rt_format) as TextView
                this.TaskStatusText = v.findViewById(R.id.task_status_rt) as TextView
                this.PackageText = v.findViewById(R.id.task_package_rt_format) as TextView
                this.RunningTaskCardView = v.findViewById(R.id.running_task_cardview) as CardView
                this.intTaskID = v.findViewById(R.id.intTaskID) as TextView
                this.intTimeElapsed = v.findViewById(R.id.intTimeElapsed) as TextView
                this.intinitial_time_elapsed = v.findViewById(R.id.intinitial_time_elapsed) as TextView
                this.strRemarks = v.findViewById(R.id.strRemarks) as TextView


            }

        }
    }

0 个答案:

没有答案