-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
344 additions
and
29 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
app/src/main/java/com/nqmgaming/shoseshop/adapter/viewpagger2/OrderAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} | ||
} | ||
|
||
} |
21 changes: 0 additions & 21 deletions
21
app/src/main/java/com/nqmgaming/shoseshop/ui/fragments/OrderFragment.kt
This file was deleted.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
app/src/main/java/com/nqmgaming/shoseshop/ui/fragments/order/OrderFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
app/src/main/java/com/nqmgaming/shoseshop/ui/fragments/order/OrderViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
app/src/main/java/com/nqmgaming/shoseshop/ui/fragments/order/fragments/CancelFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
app/src/main/java/com/nqmgaming/shoseshop/ui/fragments/order/fragments/ProgressFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
app/src/main/java/com/nqmgaming/shoseshop/ui/fragments/order/fragments/ShipFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.