Skip to content

Commit

Permalink
Fixed Minor Changes
Browse files Browse the repository at this point in the history
Signed-off-by: Jeevan Surendran <jvns67@gmail.com>
  • Loading branch information
jeevansurendran committed Mar 15, 2020
1 parent 8666a5c commit 5a803fc
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 55 deletions.
Expand Up @@ -6,28 +6,26 @@ import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import com.airbnb.epoxy.EpoxyModelWithHolder
import com.checkin.app.checkin.R
import com.checkin.app.checkin.home.listeners.LocationSelectedListener
import com.checkin.app.checkin.home.model.CityLocationModel
import com.checkin.app.checkin.menu.listeners.LocationSelectedListener
import com.checkin.app.checkin.misc.epoxy.BaseEpoxyHolder

@EpoxyModelClass(layout = R.layout.item_user_location_city)
abstract class CityLocationModelHolder : EpoxyModelWithHolder<CityLocationModelHolder.Holder>() {

@EpoxyAttribute
internal lateinit var data: CityLocationModel

@EpoxyAttribute
internal lateinit var locationSelected: LocationSelectedListener
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
internal lateinit var locationSelectedListener: LocationSelectedListener

override fun createNewHolder() = Holder(locationSelectedListener)

override fun bind(holder: Holder) {
holder.bindData(data)
holder.itemView.setOnClickListener {
locationSelected.onSelectedLocation()
}

}

class Holder : BaseEpoxyHolder<CityLocationModel>() {
class Holder(val locationSelectedListener: LocationSelectedListener) : BaseEpoxyHolder<CityLocationModel>() {

@BindView(R.id.tv_user_location_city)
internal lateinit var tvCityLocation: TextView
Expand All @@ -39,6 +37,11 @@ abstract class CityLocationModelHolder : EpoxyModelWithHolder<CityLocationModelH
override fun bindData(data: CityLocationModel) {
tvCityLocation.text = data.name
tvStateLocation.text = "${data.state} ${data.country}"

itemView.setOnClickListener {
locationSelectedListener.onLocationSelected(data)
}

}
}
}
Expand Up @@ -4,24 +4,24 @@ import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import com.airbnb.epoxy.EpoxyModelWithHolder
import com.checkin.app.checkin.R
import com.checkin.app.checkin.menu.listeners.LocationSelectedListener
import com.checkin.app.checkin.home.listeners.LocationSelectedListener
import com.checkin.app.checkin.misc.epoxy.BaseEpoxyHolder

@EpoxyModelClass(layout = R.layout.item_user_location_current)
abstract class CurrentLocationModelHolder : EpoxyModelWithHolder<CurrentLocationModelHolder.Holder>() {

@EpoxyAttribute
internal lateinit var locationSelected: LocationSelectedListener
internal lateinit var locationSelectedListener: LocationSelectedListener

override fun createNewHolder() = Holder(locationSelectedListener)

override fun bind(holder: Holder) {
if (::locationSelected.isInitialized)
holder.itemView.setOnClickListener {
locationSelected.onSelectedLocation()
}
holder.bindData("Current Location")
}

class Holder : BaseEpoxyHolder<String>() {
class Holder(val locationSelectedListener: LocationSelectedListener) : BaseEpoxyHolder<String>() {

override fun bindData(data: String) {
locationSelectedListener.onLocationSelected(null)

}
}
Expand Down
Expand Up @@ -17,15 +17,16 @@ import com.checkin.app.checkin.R
import com.checkin.app.checkin.data.resource.Resource
import com.checkin.app.checkin.home.epoxy.cityLocationModelHolder
import com.checkin.app.checkin.home.epoxy.currentLocationModelHolder
import com.checkin.app.checkin.home.listeners.LocationSelectedListener
import com.checkin.app.checkin.home.model.CityLocationModel
import com.checkin.app.checkin.home.viewmodels.HomeViewModel
import com.checkin.app.checkin.home.viewmodels.UserLocationViewModel
import com.checkin.app.checkin.misc.fragments.BaseFragment
import com.checkin.app.checkin.utility.Constants

class UserLocationFragment : BaseFragment() {
class UserLocationFragment : BaseFragment(), LocationSelectedListener {
override val rootLayout = R.layout.fragment_user_location_switch
val viewModel: UserLocationViewModel by viewModels()
val homeViewModel: HomeViewModel by activityViewModels()

@BindView(R.id.et_user_location)
internal lateinit var etUserLocation: EditText

Expand All @@ -35,23 +36,15 @@ class UserLocationFragment : BaseFragment() {
@BindView(R.id.im_user_location_cross)
internal lateinit var imUserCross: ImageView

val viewModel: UserLocationViewModel by viewModels()
val homeViewModel: HomeViewModel by activityViewModels()


@OnTextChanged(R.id.et_user_location, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
fun onTextChanged(et: Editable?) {
if (et.toString().isEmpty()) {
imUserCross.visibility = View.INVISIBLE
} else {
imUserCross.visibility = View.VISIBLE
}
viewModel.searchCities(et.toString())
}


@OnClick(R.id.im_user_location_cross)
fun onTextCrossed() {
etUserLocation.text.clear()
}

@OnClick(R.id.im_user_location_back)
fun onBack() {
requireActivity().supportFragmentManager.popBackStack()
Expand All @@ -62,16 +55,7 @@ class UserLocationFragment : BaseFragment() {
if (etUserLocation.text.isEmpty() || viewModel.locationData.value?.inError == true) {
currentLocationModelHolder {
id("present.location")
locationSelected {
val preferences = requireActivity().getSharedPreferences(Constants.LOCATION_CITY_FILE, Context.MODE_PRIVATE)
with(preferences.edit()) {
putInt(Constants.LOCATION_CITY_ID, 0)
putString(Constants.LOCATION_CITY_NAME, "Current Location")
commit()
}
homeViewModel.setCityId(0)
requireActivity().supportFragmentManager.popBackStack()
}
locationSelectedListener(this@UserLocationFragment)
}
}

Expand All @@ -80,16 +64,7 @@ class UserLocationFragment : BaseFragment() {
cityLocationModelHolder {
id(model.id)
data(model)
locationSelected {
val preferences = requireActivity().getSharedPreferences(Constants.LOCATION_CITY_FILE, Context.MODE_PRIVATE)
with(preferences.edit()) {
putInt(Constants.LOCATION_CITY_ID, model.id)
putString(Constants.LOCATION_CITY_NAME, model.name)
commit()
}
homeViewModel.setCityId(model.id)
requireActivity().supportFragmentManager.popBackStack()
}
locationSelectedListener(this@UserLocationFragment)
}
}
}
Expand All @@ -111,4 +86,24 @@ class UserLocationFragment : BaseFragment() {
val TAG = UserLocationFragment::class.simpleName
}

override fun onLocationSelected(data: CityLocationModel?) {
var id = 0
var name = "Current Location"

if (data != null) {
id = data.id
name = data.name
}

val preferences = requireContext().getSharedPreferences(Constants.LOCATION_CITY_FILE, Context.MODE_PRIVATE)
with(preferences.edit()) {
putInt(Constants.LOCATION_CITY_ID, id)
putString(Constants.LOCATION_CITY_NAME, name)
commit()
}

homeViewModel.setCityId(id)
requireActivity().supportFragmentManager.popBackStack()
}

}
@@ -0,0 +1,7 @@
package com.checkin.app.checkin.home.listeners

import com.checkin.app.checkin.home.model.CityLocationModel

interface LocationSelectedListener {
fun onLocationSelected(data: CityLocationModel?)
}

This file was deleted.

0 comments on commit 5a803fc

Please sign in to comment.