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
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 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
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
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() |
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.app.Activity | |
import androidx.activity.result.ActivityResultLauncher | |
import androidx.activity.result.contract.ActivityResultContracts | |
import androidx.appcompat.app.AppCompatActivity | |
import androidx.core.app.ActivityCompat.shouldShowRequestPermissionRationale | |
import androidx.fragment.app.Fragment | |
object PermissionUtil { |
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
// register permission on top of Fragment or Activity like below | |
private val cameraPermission = registerPermission { | |
onCameraPermissionResult(it) | |
} | |
private val storagePermission = registerPermission { | |
onStoragePermissionResult(it) | |
} |
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 Permission.launchSinglePermission(permission: String) { | |
this.result.launch(arrayOf(permission)) | |
} | |
fun Permission.launchMultiplePermission(permissionList: Array<String>) { | |
this.result.launch(permissionList) | |
} |
NewerOlder