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
| val pair: Pair<File, Long> = measureTimeMillisPair(::readAndDecodeFile) | |
| val file = pair.first | |
| Log.d(TAG, "Read and decode took ${pair.last}ms") |
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
| val file: File = readAndDecodeFile() |
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
| inline fun<T> measureTimeMillisPair(function: () -> T): Pair<T, Long> { | |
| val startTime = System.currentTimeMillis() | |
| val result: T = function.invoke() | |
| val endTime = System.currentTimeMillis() | |
| return Pair(result, endTime - startTime) | |
| } |
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
| /** | |
| * An extension of the kotlin stdlib function [measureTimeMillis] that can measure | |
| * the execution time fo functions that return values. | |
| * We want this function to return just one value (the function under measurement's | |
| * return value) but we also need to "return" the timing result somehow. | |
| * In order to avoid returning a [Pair], and since the timing result is usually used | |
| * in a side-effect (logging), we can provide a lambda to be executed with the timing | |
| * result as its input. | |
| * | |
| * @param loggingFunction The function to execute with the timing result (typically |
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
| // 1. Use with a block of code | |
| val executionTime = measureTimeMillis { | |
| // block of code to be measured | |
| } | |
| // 2. Use with a function reference | |
| fun doSth() { | |
| // body of function to be measured | |
| } |
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
| /** | |
| * Executes the given [block] and returns elapsed time in milliseconds. | |
| */ | |
| public inline fun measureTimeMillis(block: () -> Unit): Long { | |
| val start = System.currentTimeMillis() | |
| block() | |
| return System.currentTimeMillis() - start | |
| } |
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
| @Singleton | |
| class NotificationsHelper @Inject constructor(private val context: Context, | |
| private val notificationRepository: NotificationRepository, | |
| private val groupsRepository: GroupsRepository) { | |
| private val notificationManager: NotificationManager = | |
| context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | |
| init { | |
| atLeastApi(Build.VERSION_CODES.O) { createNotificationChannels() } |
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
| fusedLocationProviderClient | |
| .getLastLocation() | |
| .addOnSuccessListener(location -> { | |
| // Do something with the location | |
| } | |
| ) |
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
| public class LocationPresenter implements LocationContract.Presenter { | |
| private static final String TAG = "LOCATION"; | |
| private final WeakReference<LocationContract.View> viewWeakReference; | |
| private final LocationInteractor interactor; | |
| private PermissionRequestHandler permissionRequestHandler; | |
| private final CompositeDisposable disposables = new CompositeDisposable(); | |
| @Inject |
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
| public class LocationActivity extends AppCompatActivity | |
| implements LocationContract.View { | |
| @BindView(R.id.latitudeTextView) | |
| TextView latitudeTextView; | |
| @BindView(R.id.longitudeTextView) | |
| TextView longitudeTextView; | |
| @BindView(R.id.softDenyTextView) | |
| TextView softDeniedWarningTextView; | |
| @BindView(R.id.hardDenyTextView) |