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
Intent i = new Intent(); | |
String packageName = getPackageName(); | |
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); | |
if (pm.isIgnoringBatteryOptimizations(packageName){ | |
i.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); | |
} else { | |
i.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); | |
i.setData(Uri.parse("package:" + packageName)); |
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
dependencies{ | |
kapt "android.arch.lifecycle:compiler:1.1.1" | |
implementation "android.arch.lifecycle:extensions:1.1.1" | |
} |
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 AppApplication : Application() { | |
override fun onCreate() { | |
super.onCreate() | |
ProcessLifecycleOwner.get().lifecycle | |
.addObserver(AppLifecycleObserver()) | |
} | |
} |
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 AppLifecycleObserver : LifecycleObserver { | |
@OnLifecycleEvent(Lifecycle.Event.ON_START) | |
fun onForeground() { | |
//foreground | |
} | |
@OnLifecycleEvent(Lifecycle.Event.ON_STOP) | |
fun onBackground() { | |
//background |
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 LoginRepository @Inject constructor(private val apiService: APIService, private val sharedPreferences: SharedPreferences) { | |
fun getOTPForNumber(phoneNumber: String): LiveData<OTPResult> { | |
val loginResult = MutableLiveData<OTPResult>() | |
launch { | |
try { | |
val request = apiService.getOTPForNumber(phoneNumber) | |
val response = request.await() |
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 lateinit var job2: Job | |
fun toDoWorkConcurrent() { | |
job2 = launch { | |
try { | |
val work1 = async { getThingsDone(43) } | |
val work2 = async { getThingsDoneAgain(123) } |
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 lateinit var job1: Job | |
suspend fun getThingsDone(myThings: Int): Int { | |
// Heavy computation going on here :D | |
return myThings + 99 | |
} | |
suspend fun getThingsDoneAgain(myThings: Int): Int { | |
// Heavy computation going on here :D | |
return myThings + 50 |
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
public actual fun launch( | |
context: CoroutineContext = DefaultDispatcher, | |
start: CoroutineStart = CoroutineStart.DEFAULT, | |
parent: Job? = null, | |
block: suspend CoroutineScope.() -> Unit | |
): Job { | |
val newContext = newCoroutineContext(context, parent) | |
val coroutine = if (start.isLazy) | |
LazyStandaloneCoroutine(newContext, block) else | |
StandaloneCoroutine(newContext, active = true) |
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
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
sharedElementEnterTransition = ChangeBounds() | |
} |
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
postponeEnterTransition() | |
recyclerView.doOnPreDraw { | |
startPostponedEnterTransition() | |
} |
NewerOlder