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 FragmentA : Fragment() { | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
//Observe the result to be set by Fragment B in the stateHandle of the currentBackStackEntry | |
val currentBackStackEntry = findNavController().currentBackStackEntry | |
val savedStateHandle = currentBackStackEntry?.savedStateHandle | |
savedStateHandle?.getLiveData<String>(RESULT_FROM_FRAGMENT_B) | |
?.observe(currentBackStackEntry, Observer { result -> | |
print(result) |
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 getPermissionState(activity: Activity, result: Map<String, Boolean>): PermissionState { | |
val deniedPermissions = result.filterValues { !it }.keys | |
return when { | |
deniedPermissions.isEmpty() -> PermissionState.Granted | |
deniedPermissions.any { permission -> | |
!shouldShowRequestPermissionRationale( | |
/* activity = */ | |
activity, | |
/* permission = */ |
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
import android.os.Bundle | |
import android.widget.ProgressBar | |
import android.widget.TextView | |
import androidx.activity.viewModels | |
import androidx.appcompat.app.AppCompatActivity | |
import androidx.core.view.isVisible | |
class MainActivity : AppCompatActivity() { | |
private val mainViewModel: MainViewModel by viewModels() |
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
val user = User() | |
val userValidator = Validator(user).apply { | |
addRule("Name Cannot be empty") { it?.name.isNullOrEmpty() } | |
addRule("Username lenght min 5 character") { it?.name?.length < 5 } | |
addRule("Email cannot be empty") { it?.email.isNullOrEmpty() } | |
addRule("Email format is wrong") { it?.email.isValidEmail() } | |
addRule("Age min 18") { it?.age < 18 } | |
} |
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
package com.hamurcuabi.myapplication | |
import android.content.Context | |
import android.graphics.Typeface | |
import android.util.AttributeSet | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.widget.FrameLayout | |
import androidx.core.view.isVisible | |
import com.hamurcuabi.myapplication.databinding.ViewCustomToolbarBinding |
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 OnBackPressedDelegationImpl : OnBackPressedDelegation, DefaultLifecycleObserver { | |
private val onBackPressedCallback = object : OnBackPressedCallback(true) { | |
override fun handleOnBackPressed() { | |
onBackPressed.invoke() | |
} | |
} | |
private var fragmentActivity: FragmentActivity? = 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
class HomeFragment : Fragment(), | |
OnBackPressedDelegation by OnBackPressedDelegationImpl() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
registerOnBackPressedDelegation(activity, this.lifecycle) { | |
// OnBackPressed fired!!! | |
} | |
} | |
} |
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
interface OnBackPressedDelegation { | |
fun registerOnBackPressedDelegation( | |
fragmentActivity: FragmentActivity?, | |
lifecycle: Lifecycle, | |
onBackPressed: () -> Unit | |
) | |
} |
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 HomeFragment : Fragment() { | |
private val onBackPressedCallback = object : OnBackPressedCallback(true) { | |
override fun handleOnBackPressed() { | |
// On back pressed | |
} | |
} | |
override fun onResume() { | |
super.onResume() |
NewerOlder