This file contains hidden or 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
<Button | |
android:id="@+id/register" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Register" | |
android:layout_gravity="center" | |
android:layout_marginTop="5dp" | |
android:onClick="@{() -> RegisterViewModel.onCLicked()}" | |
bind:toastMessageAction="@{RegisterViewModel.toastMessage}"/> |
This file contains hidden or 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
<Button | |
android:id="@+id/register" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Register" | |
android:layout_gravity="center" | |
android:layout_marginTop="5dp" | |
android:onClick="@{() -> RegisterViewModel.onCLicked()}" | |
bind:toastMessageAction="@{RegisterViewModel.toastMessage}"/> |
This file contains hidden or 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
<EditText | |
android:id="@+id/username" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:hint="Username" | |
android:maxLines="1" | |
android:inputType="text" | |
android:text="@={RegisterViewModel.username}"/> |
This file contains hidden or 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
<data> | |
<variable | |
name="RegisterViewModel" | |
type="com.example.mvvm_example.viewmodels.RegisterViewModel"> | |
</variable> | |
</data> |
This file contains hidden or 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"?> | |
<layout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:bind="http://schemas.android.com/tools"> | |
<data> | |
<variable | |
name="RegisterViewModel" | |
type="com.example.mvvm_example.viewmodels.RegisterViewModel"> | |
</variable> | |
</data> |
This file contains hidden or 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
companion object { | |
@BindingAdapter("toastMessageAction") | |
@JvmStatic | |
fun runMe(view: View, message: String?) { | |
message?.let { | |
Toast.makeText(view.context, it, Toast.LENGTH_SHORT).show() | |
} | |
} | |
} | |
} |
This file contains hidden or 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 RegisterViewModel : BaseObservable() { | |
private var register = RegisterDataModel("", "", "") | |
@Bindable | |
private var toastMessage: String? = null | |
private fun isValid(): Boolean { | |
return getUsername().isNotEmpty() && getPassword().isNotEmpty() && getCountry().isNotEmpty() | |
} |
This file contains hidden or 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
data class RegisterDataModel(var username: String, var password: String, var country: String) |
This file contains hidden or 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
package com.indieteam.android_permission_simple | |
import android.Manifest | |
import android.content.Context | |
import android.content.pm.PackageManager | |
import android.location.LocationManager | |
import androidx.appcompat.app.AppCompatActivity | |
import android.os.Bundle | |
import android.widget.Toast | |
import androidx.core.app.ActivityCompat |
This file contains hidden or 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 getCurrentLocation() { | |
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { | |
val locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager | |
val location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER) | |
location?.let { | |
it.apply { | |
val lat = latitude | |
val lon = longitude | |
texview.text = "Lat: $lat \n Lon: $lon" |