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
fun <T> Call<T>.asLiveData(): LiveData<Resource<T>> { | |
val result = MutableLiveData<Resource<T>>() | |
enqueue(object : Callback<T> { | |
override fun onFailure(call: Call<T>, t: Throwable) { | |
result.postValue(Resource.error(AppException(t))) | |
} | |
override fun onResponse(call: Call<T>, response: Response<T>) { |
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
class FetchDetailsRepo(private val fetchDetailsAPI: FetchDetailsAPI) { | |
fun fetchDetails(): LiveData<Resource<DogBreed>> { | |
return fetchDetailsAPI.fetchBreedList().asLiveData() | |
} | |
fun fetchBreedDetails(id: Int): LiveData<Resource<BreedDetail>> { | |
return fetchDetailsAPI.fetchBreedDetails(id).asLiveData() | |
} | |
} | |
interface FetchDetailsAPI { |
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
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
// Apply default transition on app launch | |
motion_layout.setTransition(motion_layout.currentState, R.id.home_expand) | |
motion_layout.transitionToEnd() |
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
<ConstraintSet android:id="@+id/home_expand" | |
app:deriveConstraintsFrom="@id/base"> | |
<Constraint | |
android:id="@+id/iv_home" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintEnd_toStartOf="@id/tv_home" | |
app:layout_constraintHorizontal_chainStyle="spread" | |
app:layout_constraintStart_toStartOf="parent" |
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
<ConstraintSet android:id="@+id/base"> | |
<Constraint | |
android:id="@+id/iv_home" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintEnd_toStartOf="@id/tv_home" | |
app:layout_constraintHorizontal_chainStyle="spread" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toTopOf="parent"> |
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
<?xml version="1.0" encoding="utf-8"?> | |
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto"> | |
<ConstraintSet android:id="@+id/base"> | |
<Constraint | |
android:id="@+id/iv_home" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
app:layout_constraintBottom_toBottomOf="parent" |
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
<?xml version="1.0" encoding="utf-8"?> | |
<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" | |
android:background="@color/colorBackground" | |
tools:context=".MainActivity"> | |
<androidx.constraintlayout.motion.widget.MotionLayout |
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
fun checkForGeoFenceEntry(userLocation: Location, geofenceLat: Double, geofenceLong: Double, radius: Double) { | |
val startLatLng = LatLng(userLocation.latitude, userLocation.longitude) // User Location | |
val geofenceLatLng = LatLng(geofenceLat, geofenceLong) // Center of geofence | |
val distanceInMeters = SphericalUtil.computeDistanceBetween(startLatLng, geofenceLatLng) | |
if (distanceInMeters < radius) { | |
// User is inside the Geo-fence | |
showNotificationEvent.call() | |
} |
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
private fun requestMyGpsLocation(callback: (location: Location) -> Unit) { | |
val client = LocationServices.getFusedLocationProviderClient(this) | |
client.requestLocationUpdates(locationRequest, object : LocationCallback() { | |
override fun onLocationResult(locationResult: LocationResult?) { | |
val location = locationResult?.lastLocation | |
if (location != null) { | |
callback.invoke(location) | |
mainVM.checkForGeoFenceEntry( | |
location, |
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
private val GEOFENCE_LAT = 19.139941 | |
private val GEOFENCE_LONG = 72.872936 | |
private val GEOFENCE_RADIUS = 10000.00 | |
private fun setupMap(googleMap: GoogleMap?) { | |
googleMap?.addCircle( | |
CircleOptions() | |
.center(LatLng(GEOFENCE_LAT, GEOFENCE_LONG)) | |
.radius(GEOFENCE_RADIUS) | |
.strokeColor(ContextCompat.getColor(this, R.color.colorRed)) |