проблема с реселлером - PullRequest
0 голосов
/ 09 февраля 2020

Я использую этот код во фрагменте, когда ориентация по вертикали все хорошо и работает, но при изменении на Горизонтально не отображается во фрагменте


 private var progressBar: ProgressBar? = null
    private var linearParent: LinearLayout? = null
    private var txtEmpty: TextView? = null
    private var token : String ?= null
    private var recycler : RecyclerView?= null
    private var txtNewReturn : TextView?= null
    private var txtDate : TextView?= null
    private var recyclerCat : RecyclerView?= null
    private var categoryAdapter: CategoryInShopBasketAdapter? = null
    private var productAdapter: ReturnBasketAdapter? = null
    private var returnBasketViewModel: ReturnBasketViewModel? = null

    @SuppressLint("InflateParams")
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val view = LayoutInflater.from(this.requireContext()).inflate(R.layout.fragment_return_basket, null)
        init(view)
        getAllReturnBasketCategory()
        return view
    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        loadData()
    }

    private fun loadData () {
        token = PrefManager.getToken(this.requireContext())
    }

    private fun init(view: View){
        txtNewReturn = view.findViewById(R.id.txtNewReturn)
        txtDate = view.findViewById(R.id.txtDate)
        progressBar = view.findViewById(R.id.progressBar)
        linearParent = view.findViewById(R.id.linearParent)
        txtEmpty = view.findViewById(R.id.txtEmpty)

        recycler = view.findViewById(R.id.recycler)
        setupRecyclerVertical(recycler, this.requireContext())
        recyclerCat = view.findViewById(R.id.recyclerCat)
        recyclerCat?.layoutManager = LinearLayoutManager(this.requireContext(),LinearLayoutManager.HORIZONTAL,false)
       // recyclerCat?.layoutManager = RTLGridLayoutManager(this.requireContext(),4)
        recyclerCat?.layoutDirection = LayoutDirection.RTL
       // setupRecyclerHorizontal(recyclerCat, this.requireContext(), true)

        txtNewReturn?.setOnClickListener {
            showToast("Toooast",this.requireContext(),2000)
        }
        txtDate?.text = "1398/04/12"

        returnBasketViewModel = ViewModelProvider(this.requireActivity(),ReturnBasketViewModelFactory(this.requireActivity().application))
            .get(ReturnBasketViewModel::class.java)


        recyclerCat?.addOnItemTouchListener(RecyclerTouchListener(this.requireContext(), recyclerCat, object : ClickListener {
            override fun onClick(view: View?, position: Int) {
                val item = categoryAdapter?.getItem(position)
                if (item?.id == "0") {
                    getAllReturnBasket()
                    categoryAdapter?.getAllItems()?.forEach {
                        if (it.id == "0") {
                            it.check = true
                        }
                        categoryAdapter!!.notifyDataSetChanged()
                    }
                } else {
                    getReturnBasketByCategoryName(item!!.name)
                }
                categoryAdapter?.getAllItems()?.forEach {
                    it.check = it.name == item.name
                }
                categoryAdapter?.notifyDataSetChanged()
            }

            override fun onLongClick(view: View?, position: Int) {}
        }))
    } 

, и это функция для получения

 private fun getAllReturnBasketCategory() {
        returnBasketViewModel?.getAll()?.observe(this.requireActivity(), Observer {
            val categoryList: ArrayList<Category> = ArrayList()
            categoryList.add(Category("0", "همه"))
            it.forEach { returnBasket ->
                if (returnBasket.categoryId.isNotEmpty()) {
                    val cat = Category(
                        returnBasket.categoryId,
                        returnBasket.categoryName
                    )
                    categoryList.add(cat)
                }
            }
            categoryAdapter = CategoryInShopBasketAdapter(this.requireContext(), categoryList)
            recyclerCat?.adapter = AlphaInAnimationAdapter(categoryAdapter).apply {
                setDuration(300)
                setFirstOnly(true)
                setInterpolator(OvershootInterpolator(0.3f))
            }

            if (categoryAdapter!!.itemCount != 1) {
                getAllReturnBasket()
                categoryAdapter?.getAllItems()?.forEach { cat ->
                    if (cat.id == "0") {
                        cat.check = true
                    }
                    categoryAdapter!!.notifyDataSetChanged()
                }
                txtNewReturn?.visibility = View.VISIBLE
                linearParent?.visibility = View.VISIBLE
                progressBar?.visibility = View.GONE
                txtEmpty?.visibility = View.GONE
            } else {
                progressBar?.visibility = View.GONE
                txtEmpty?.visibility = View.VISIBLE
                txtNewReturn?.visibility = View.GONE
                linearParent?.visibility = View.GONE
            }
        })
    }

это макет xml фрагмента


<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <LinearLayout
        android:id="@+id/linearParent"
        android:visibility="gone"
        android:layout_marginBottom="8dp"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:orientation="vertical"
        app:layout_constraintBottom_toTopOf="@+id/txtNewReturn"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingEnd="12dp">

            <TextView
                android:id="@+id/textView5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="8dp"
                android:fontFamily="@font/font_is"
                android:gravity="center"
                android:hint="سبد مرجوعی"
                android:textColor="@color/primary_gray"
                android:textColorHint="@color/primary_gray"
                android:textDirection="rtl"
                android:textSize="@dimen/font13"
                android:textStyle="bold"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toStartOf="@+id/imageView"
                app:layout_constraintTop_toTopOf="parent" />

            <ImageView
                android:id="@+id/imageView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_keyboard_return_gray_24dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent" />


        </androidx.constraintlayout.widget.ConstraintLayout>

        <TextView
            android:id="@+id/txtDate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end"`enter code here`
            android:layout_marginRight="12dp"
            android:fontFamily="@font/font_is"
            android:gravity="center"
            android:hint="1398-05-12"
            android:textColor="@color/primary_gray"
            android:textColorHint="@color/primary_gray"
            android:textDirection="rtl"
            android:textSize="@dimen/font12" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerCat"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="8dp" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recycler"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginEnd="8dp"
            android:paddingTop="4dp"
            android:paddingBottom="4dp" />

    </LinearLayout>

    <TextView
        android:id="@+id/txtNewReturn"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:layout_marginStart="60dp"
        android:layout_marginEnd="60dp"
        android:layout_marginBottom="8dp"
        android:background="@drawable/border_basket_green"
        android:fontFamily="@font/font_is"
        android:gravity="center"
        android:text="ثبت مرجوعی"
        android:textAlignment="center"
        android:textColor="@color/white"
        android:clickable="true"
        android:foreground="?attr/selectableItemBackground"
        android:textSize="@dimen/font12"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

    <TextView
        android:visibility="gone"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:text="موردی یافت نشد"
        android:fontFamily="@font/font_is"
        android:textStyle="bold"
        android:textColor="@color/primary_red"
        android:textSize="@dimen/font13"
        android:id="@+id/txtEmpty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <ProgressBar
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_centerInParent="true"
        android:theme="@style/myCircularProgress"
        android:indeterminate="true"
        android:id="@+id/progressBar"
        android:layout_width="30dp"
        android:layout_height="30dp" />

</androidx.constraintlayout.widget.ConstraintLayout>

при загрузке LinearLayoutManager (this.requireContext (), LinearLayoutManager.VERTICAL, false) и правильном слове, но оно меняется на LinearLayoutManager (this.requireContext (), LinearLayoutManager. ГОРИЗОНТАЛЬНО, ложно) переработчик не показывать !!!

1 Ответ

0 голосов
/ 10 февраля 2020

я решил проблему! для высоты ресайклер = содержимое упаковки должно иметь значение c высота!

...