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 | |
@Provides | |
fun provideOkhttpClient(authInterceptor: AuthInterceptor, | |
certificateHelper: CertificateHelper | |
) :OkHttpClient{ | |
val trustManagers = certificateHelper.createTrustManagers() | |
val sslContext = SSLContext.getInstance("TLS") | |
sslContext.init(null, trustManagers, null) | |
return OkHttpClient().newBuilder() | |
.readTimeout(2, TimeUnit.MINUTES) |
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
class CertificateHelper @Inject constructor(@ApplicationContext context: Context) { | |
private val applicationContext = context | |
fun createTrustManagers(): Array<TrustManager> { | |
val certificateInputStream = applicationContext.resources.openRawResource( | |
R.raw.test) | |
val certificateFactory = CertificateFactory.getInstance("X.509") | |
val certificate = certificateFactory.generateCertificate(certificateInputStream) | |
val trustManagerFactory = TrustManagerFactory.getInstance( | |
TrustManagerFactory.getDefaultAlgorithm()) | |
val keyStore = KeyStore.getInstance(KeyStore.getDefaultType()) |
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 filename = "myFile.txt" | |
val content = "Hello, World!" | |
val documentsDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) | |
val file = File(documentsDir, filename) | |
file.outputStream().use { outputStream -> | |
outputStream.write(content.toByteArray()) | |
} |
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 contentResolver = this.contentResolver | |
val contentValues = ContentValues().apply { | |
put(MediaStore.MediaColumns.DISPLAY_NAME, "applounge") | |
put(MediaStore.MediaColumns.MIME_TYPE, "text/plain") | |
put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DOCUMENTS) | |
} | |
val uri = contentResolver.insert(MediaStore.Files.getContentUri("external"), contentValues) | |
uri?.let { | |
contentResolver.openOutputStream(it)?.use { outputStream -> |
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
@Composable | |
fun AnimatedBorderCard( | |
modifier: Modifier = Modifier, | |
shape: Shape = RoundedCornerShape(size = 0.dp), | |
borderWidth: Dp = 2.dp, | |
gradient: Brush = Brush.sweepGradient(listOf(Color.Gray, Color.White)), | |
animationDuration: Int = 10000, | |
onCardClick: () -> Unit = {}, | |
content: @Composable () -> Unit | |
) { |
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
@Composable | |
fun CircleMap() { | |
// Define the coordinates for circle centers and their associated information | |
val circleData = listOf( | |
CircleInfo("Park A", LatLng(37.7749, -122.4194), "This is Park A"), | |
CircleInfo("Park B", LatLng(36.7783, -119.4179), "This is Park B"), | |
CircleInfo("Park C", LatLng(34.0522, -118.2437), "This is Park C") | |
) | |
// Create a mutable state to track the selected circle |
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 url = Uri.parse("https://www.asos.com/") | |
val browserSelectorIntent = Intent() | |
.setAction(Intent.ACTION_VIEW) | |
.addCategory(Intent.CATEGORY_BROWSABLE) | |
.setData(Uri.parse("http:")) | |
val targetIntent = Intent() | |
.setAction(Intent.ACTION_VIEW) | |
.addCategory(Intent.CATEGORY_BROWSABLE) |
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
#!/bin/zsh | |
function get_devices() { | |
all_devices=$(command adb devices) | |
all_devices=${all_devices#"List of devices attached"} | |
# Find how many devices we have | |
num_matches=$(echo $all_devices | egrep -o "([[:alnum:]-]+[[:space:]]+device$)" | wc -l) | |
# If there are multiple, ask for which device to send the command to |
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
import kotlin.random.Random | |
import kotlin.reflect.KClass | |
import kotlin.reflect.KFunction | |
import kotlin.reflect.KType | |
/** | |
* You can find the method explanation here on this post: | |
* https://zaqueusantos.medium.com/an-easy-way-to-create-fixture-or-dummy-classes-for-your-android-tests-with-kotlin-9d6c619237d4 | |
*/ |
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
class LocationService { | |
@SuppressLint("MissingPermission") | |
suspend fun getCurrentLocation(context: Context): Location { | |
if (!context.hasPermissions( | |
Manifest.permission.ACCESS_FINE_LOCATION, | |
Manifest.permission.ACCESS_COARSE_LOCATION | |
) | |
) { |