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
# Commands installed | |
# tldr - better man | |
# scc - code counter | |
# duf - disk usage | |
# ctop - top for containers | |
# lazygit - git client | |
# fx - json viewer | |
# mc - midnight commander | |
# autojump (j) - jump to directories |
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
LazyStaggeredGrid(columnCount = 2) { | |
(0..100).forEach { _ -> | |
item { | |
Box(modifier = Modifier | |
.fillMaxWidth() | |
.aspectRatio(ratio = random.nextDouble(0.2, 1.8).toFloat()) | |
.background(Color(random.nextInt(255), random.nextInt(255), random.nextInt(255))) | |
) | |
} | |
} |
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
// This requires NO permissions (camera, storage etc) | |
fun askForPhoto(activity: Activity, imageRequest: Int) { | |
val dir = getExternalFilesDir(Environment.DIRECTORY_PICTURES) | |
val picture = File(dir, UUID.randomUUID().toString()) | |
// keep this. Will be used later in the onActivityResult method | |
photoUri = FileProvider.getUriForFile(this, "com.savvasdalkitsis.fileprovider", picture) | |
val photoIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE) | |
photoIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri) | |
startActivityForResult(photoIntent, imageRequest) | |
} |
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 getLocation(photoUri: Uri): Pair<Double, Double> { | |
contentResolver.openInputStream(photoUri).use { stream -> | |
val latLon = ExifInterface(stream).latLong | |
return Pair(latLon[0], latLon[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
val frescoOkHttpClient = OkHttpClient.Builder() | |
.connectTimeout(DEFAULT_REQUEST_TIMEOUT, TimeUnit.SECONDS) | |
.readTimeout(DEFAULT_REQUEST_TIMEOUT, TimeUnit.SECONDS) | |
.writeTimeout(DEFAULT_REQUEST_TIMEOUT, TimeUnit.SECONDS) | |
.addInterceptor(StaleIfErrorInterceptor()) | |
.cache(newCache("fresco_cache", 100, ByteConstants.MB)) | |
.build() |
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 StaleIfErrorInterceptor: Interceptor { | |
override fun intercept(chain: Interceptor.Chain): Response { | |
val request = chain.request().newBuilder() | |
return try { | |
chain.proceed(request.build()) | |
} catch (e: IOException) { | |
Log.w(TAG, "Error on network call. Fallback to cache if present.", e) | |
chain.proceed(request | |
.cacheControl(CacheControl.FORCE_CACHE) |
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 frescoOkHttpClient = OkHttpClient.Builder() | |
.connectTimeout(DEFAULT_REQUEST_TIMEOUT, TimeUnit.SECONDS) | |
.readTimeout(DEFAULT_REQUEST_TIMEOUT, TimeUnit.SECONDS) | |
.writeTimeout(DEFAULT_REQUEST_TIMEOUT, TimeUnit.SECONDS) | |
.cache(newCache("fresco_cache", 100, ByteConstants.MB)) | |
.build() | |
fun newCache(name: String, mb: Long, unit: Int): Cache = | |
Cache(File(applicationContext.cacheDir, name), mb * 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
val imagePipelineConfig = ImagePipelineConfig.newBuilder(context) | |
.setNetworkFetcher(OkHttpNetworkFetcherWithCache(frescoOkHttpClient)) | |
// no way to disable the disk cache globally, setting everything | |
// no to max 0 bytes | |
.setMainDiskCacheConfig(DiskCacheConfig.newBuilder(this) | |
.setMaxCacheSize(0) | |
.setMaxCacheSizeOnLowDiskSpace(0) | |
.setMaxCacheSizeOnVeryLowDiskSpace(0) | |
.build()) | |
.build() |
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
/** | |
* The default [OkHttpNetworkFetcher] injects a ‘Cache-Control: no-store’ | |
* header in the requests, preventing the response cache to work for images loaded | |
* via Fresco. This is done because Fresco has its own disk cache which, | |
* unfortunately, ignores the response cache headers. <br><br> | |
* | |
* We decided to disable that disk cache and rely on the http one, so we need to | |
* remove the ‘no-store header from the request | |
**/ | |
class OkHttpNetworkFetcherWithCache : OkHttpNetworkFetcher { |
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 imagePipelineConfig = OkHttpImagePipelineConfigFactory | |
.newBuilder(context, okHttpClient) | |
// no way to disable the disk cache globally, setting everything | |
// no to max 0 bytes | |
.setMainDiskCacheConfig(DiskCacheConfig.newBuilder(context) | |
.setMaxCacheSize(0) | |
.setMaxCacheSizeOnLowDiskSpace(0) | |
.setMaxCacheSizeOnVeryLowDiskSpace(0) | |
.build()) | |
.build() |
NewerOlder