-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Rafael Chagas <[email protected]>
- Loading branch information
Showing
9 changed files
with
150 additions
and
105 deletions.
There are no files selected for viewing
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
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
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
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
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
35 changes: 35 additions & 0 deletions
35
library/src/main/java/com/rtchagas/pingplacepicker/ui/activity/BaseActivity.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,35 @@ | ||
package com.rtchagas.pingplacepicker.ui.activity | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.viewbinding.ViewBinding | ||
|
||
typealias ActivityInflater<T> = (LayoutInflater) -> T | ||
|
||
abstract class BaseActivity<T : ViewBinding>( | ||
private val inflate: ActivityInflater<T> | ||
) : AppCompatActivity() { | ||
|
||
private var _binding: T? = null | ||
|
||
/** | ||
* The view binding for this fragment. | ||
* | ||
* [https://developer.android.com/topic/libraries/view-binding] | ||
* | ||
* This property is only valid between [onCreate] and [onDestroy]. | ||
*/ | ||
val binding: T get() = _binding!! | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
_binding = inflate(layoutInflater) | ||
setContentView(binding.root) | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
_binding = null | ||
} | ||
} |
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
28 changes: 12 additions & 16 deletions
28
.../pingplacepicker/ui/PlacePickerAdapter.kt → ...cepicker/ui/adapter/PlacePickerAdapter.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 |
---|---|---|
@@ -1,50 +1,46 @@ | ||
package com.rtchagas.pingplacepicker.ui | ||
package com.rtchagas.pingplacepicker.ui.adapter | ||
|
||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.google.android.libraries.places.api.model.Place | ||
import com.rtchagas.pingplacepicker.R | ||
import kotlinx.android.synthetic.main.item_place.view.* | ||
import com.rtchagas.pingplacepicker.databinding.ItemPlaceBinding | ||
import com.rtchagas.pingplacepicker.ui.UiUtils | ||
|
||
internal class PlacePickerAdapter( | ||
private var placeList: List<Place>, | ||
private val clickListener: (Place) -> Unit | ||
) : RecyclerView.Adapter<PlacePickerAdapter.PlaceViewHolder>() { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlaceViewHolder { | ||
|
||
val view = LayoutInflater.from(parent.context) | ||
.inflate(R.layout.item_place, parent, false) | ||
|
||
return PlaceViewHolder(view) | ||
val inflater = LayoutInflater.from(parent.context) | ||
val binding = ItemPlaceBinding.inflate(inflater, parent, false) | ||
return PlaceViewHolder(binding) | ||
} | ||
|
||
override fun onBindViewHolder(holder: PlaceViewHolder, position: Int) { | ||
holder.bind(placeList[position], clickListener) | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return placeList.size | ||
} | ||
override fun getItemCount(): Int = | ||
placeList.size | ||
|
||
fun swapData(newPlaceList: List<Place>) { | ||
placeList = newPlaceList | ||
notifyDataSetChanged() | ||
} | ||
|
||
inner class PlaceViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | ||
inner class PlaceViewHolder(private val binding: ItemPlaceBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
|
||
fun bind(place: Place, listener: (Place) -> Unit) { | ||
|
||
with(itemView) { | ||
setOnClickListener { listener(place) } | ||
with(binding) { | ||
root.setOnClickListener { listener(place) } | ||
ivPlaceType.setImageResource(UiUtils.getPlaceDrawableRes(itemView.context, place)) | ||
tvPlaceName.text = place.name | ||
tvPlaceAddress.text = place.address | ||
} | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.