Skip to content

Instantly share code, notes, and snippets.

@jafar260698
Last active August 23, 2020 11:26
Show Gist options
  • Save jafar260698/421e3152406b7723074e5efa604043dd to your computer and use it in GitHub Desktop.
Save jafar260698/421e3152406b7723074e5efa604043dd to your computer and use it in GitHub Desktop.
class HozirgiZakazlar :Fragment() {
lateinit var viewModel: RestaurantsViewModel
lateinit var preference: LocationPreference
lateinit var adapterhozir:HozirgiZakazAdapter
lateinit var recyclerView: RecyclerView
private var layoutManager: RecyclerView.LayoutManager? = null
var progressbar:ProgressBar?=null
var user_id:Int?=null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
viewModel=(activity as MainActivity).viewModel
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view: View = inflater.inflate(R.layout.fragment_hozirgi_zakazlar, container, false)
progressbar=view.findViewById(R.id.hozir_progressBar)
recyclerView=view.findViewById(R.id.recyclerview_hozirzakaz)
layoutManager= LinearLayoutManager(activity)
recyclerView.layoutManager = layoutManager
recyclerView.apply {
itemAnimator= DefaultItemAnimator()
isNestedScrollingEnabled=false
setHasFixedSize(true)
}
preference= LocationPreference(requireActivity())
user_id=preference.getUserId(com.example.edmodo.util.Constants.USER_ID)
viewModel.getUnconfirmed(user_id!!,1)
viewModel.orders.observe(viewLifecycleOwner, Observer {response->
when(response){
is Resource.Success->{
hideProgressbar()
response.data?.let {
Log.d(TAG, it.toString())
initRecyclerview(it)
}
}
is Resource.Error->{
hideProgressbar()
response.message?.let { message->
Log.d(TAG,"Error : $message")
Toast.makeText(activity,"An error occured: $message", Toast.LENGTH_LONG).show()
}
}
is Resource.Loading->{
showProgressbar()
}
}
})
return view
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment