Skip to content

Commit

Permalink
create layout for order
Browse files Browse the repository at this point in the history
  • Loading branch information
nqmgaming committed May 29, 2024
1 parent cb34540 commit a383d6d
Show file tree
Hide file tree
Showing 12 changed files with 344 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.nqmgaming.shoseshop.adapter.viewpagger2

import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.nqmgaming.shoseshop.ui.fragments.order.fragments.CancelFragment
import com.nqmgaming.shoseshop.ui.fragments.order.fragments.ProgressFragment
import com.nqmgaming.shoseshop.ui.fragments.order.fragments.ShipFragment

class OrderAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {

override fun getItemCount(): Int {
return 3
}

override fun createFragment(position: Int): Fragment {
return when (position) {
0 -> {
ShipFragment.newInstance("Shipped")
}

1 -> {
ProgressFragment.newInstance("On Process")
}
2 -> {
CancelFragment.newInstance("Cancel")
}
else -> {
CancelFragment.newInstance("Cancel")
}
}
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.nqmgaming.shoseshop.ui.fragments.order

import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.viewModels
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayoutMediator
import com.nqmgaming.shoseshop.R
import com.nqmgaming.shoseshop.adapter.viewpagger2.OrderAdapter
import com.nqmgaming.shoseshop.databinding.FragmentOrderBinding
import com.nqmgaming.shoseshop.util.SharedPrefUtils
import dagger.hilt.android.AndroidEntryPoint


@AndroidEntryPoint
class OrderFragment : Fragment() {
private var _binding: FragmentOrderBinding? = null
private val binding get() = _binding!!
private val viewModel by viewModels<OrderViewModel>()

private lateinit var orderAdapter: OrderAdapter

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = FragmentOrderBinding.inflate(inflater, container, false)
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

val token = SharedPrefUtils.getString(requireContext(), "accessToken", "") ?: ""
val bearerToken = "Bearer $token"
val userId = SharedPrefUtils.getString(requireContext(), "id", "") ?: ""

orderAdapter = OrderAdapter(this)
binding.viewpager.adapter = orderAdapter

TabLayoutMediator(binding.tabLayout, binding.viewpager) { tab, position ->
when (position) {
0 -> {
tab.text = "Shipped"
}

1 -> {
tab.text = "On Progress"
}

2 -> {
tab.text = "Cancel"
}
}
}.attach()
}

override fun onDestroy() {
super.onDestroy()
_binding = null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.nqmgaming.shoseshop.ui.fragments.order

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.nqmgaming.shoseshop.data.model.order.Order
import com.nqmgaming.shoseshop.data.repository.ShoesRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class OrderViewModel @Inject constructor(
private val shoesRepository: ShoesRepository
) : ViewModel() {
private suspend fun getOrders(token: String, userId: String) =
shoesRepository.getOrders(token, userId)

fun getOrdersOrder(token: String, userId: String, callback: (List<Order>?) -> Unit) {
viewModelScope.launch {
try {
val orders = getOrders(token, userId)
callback(orders)
} catch (e: Exception) {
Log.e("OrderViewModel", "Error getting orders: ${e.message}")
callback(null)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.nqmgaming.shoseshop.ui.fragments.order.fragments

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.nqmgaming.shoseshop.R
import com.nqmgaming.shoseshop.databinding.FragmentCancelBinding

private const val ARG_PARAM1 = "param1"

class CancelFragment : Fragment() {
private var param1: String? = null
private var _binding: FragmentCancelBinding? = null
private val binding get() = _binding!!
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
param1 = it.getString(ARG_PARAM1)
}
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = FragmentCancelBinding.inflate(inflater, container, false)
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.cancel.text = param1
}

companion object {
@JvmStatic
fun newInstance(param1: String) =
CancelFragment().apply {
arguments = Bundle().apply {
putString(ARG_PARAM1, param1)

}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.nqmgaming.shoseshop.ui.fragments.order.fragments

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.nqmgaming.shoseshop.R
import com.nqmgaming.shoseshop.databinding.FragmentProgressBinding

private const val ARG_PARAM1 = "param1"

class ProgressFragment : Fragment() {
private var param1: String? = null
private var _binding: FragmentProgressBinding? = null
private val binding get() = _binding!!

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
param1 = it.getString(ARG_PARAM1)
}
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = FragmentProgressBinding.inflate(inflater, container, false)
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.progress.text = param1
}
companion object {
@JvmStatic
fun newInstance(param1: String) =
ProgressFragment().apply {
arguments = Bundle().apply {
putString(ARG_PARAM1, param1)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.nqmgaming.shoseshop.ui.fragments.order.fragments

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.nqmgaming.shoseshop.R
import com.nqmgaming.shoseshop.databinding.FragmentShipBinding

private const val ARG_PARAM1 = "param1"


class ShipFragment : Fragment() {

private var param1: String? = null
private var _binding: FragmentShipBinding? = null
private val binding get() = _binding!!

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
param1 = it.getString(ARG_PARAM1)
}
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = FragmentShipBinding.inflate(inflater, container, false)
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.ship.text = param1
}

companion object {

@JvmStatic
fun newInstance(param1: String) =
ShipFragment().apply {
arguments = Bundle().apply {
putString(ARG_PARAM1, param1)
}
}
}
}
15 changes: 15 additions & 0 deletions app/src/main/res/layout/fragment_cancel.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".ui.fragments.order.fragments.CancelFragment">

<!-- TODO: Update blank fragment layout -->
<TextView
android:id="@+id/cancel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />

</FrameLayout>
33 changes: 26 additions & 7 deletions app/src/main/res/layout/fragment_order.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.fragments.OrderFragment">
tools:context=".ui.fragments.order.OrderFragment">

<!-- TODO: Update blank fragment layout -->
<TextView
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
android:layout_height="50dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tabIndicator="@color/colorGrey"
app:tabIndicatorAnimationMode="elastic"
app:tabIndicatorColor="@color/colorOrange"
app:tabIndicatorGravity="center"
app:tabMode="fixed"
app:tabSelectedTextColor="@color/colorOrange" />

</FrameLayout>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tabLayout" />


</androidx.constraintlayout.widget.ConstraintLayout>
15 changes: 15 additions & 0 deletions app/src/main/res/layout/fragment_progress.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".ui.fragments.order.fragments.ProgressFragment">

<!-- TODO: Update blank fragment layout -->
<TextView
android:id="@+id/progress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />

</FrameLayout>
Loading

0 comments on commit a383d6d

Please sign in to comment.