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
/** | |
* Set this on a textview and then you can potentially open links locally if applicable | |
*/ | |
public class DefaultLinkMovementMethod extends LinkMovementMethod { | |
private OnLinkClickedListener mOnLinkClickedListener; | |
public DefaultLinkMovementMethod(OnLinkClickedListener onLinkClickedListener) { | |
mOnLinkClickedListener = onLinkClickedListener; | |
} |
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
//If you want to use a Compose in your XML file, you can add this to your layout file: | |
<androidx.compose.ui.platform.ComposeView | |
android:id="@+id/my_composable" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" /> | |
//and then, set the content: |
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
export NVM_DIR=~/.nvm | |
export PATH=~/Library/Android/sdk/tools:$PATH | |
export PATH=~/Library/Android/sdk/platform-tools:$PATH | |
export PATH=/Library/flutter/bin:$PATH | |
source $(brew --prefix nvm)/nvm.sh |
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
RewriteBase / | |
RewriteCond %{REQUEST_URI} !^/(assets/?|$) | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteRule . /index.html [L] |
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 String.getSha256(): String { | |
val digest = MessageDigest.getInstance("SHA-256").apply { reset() } | |
val byteData: ByteArray = digest.digest(toByteArray()) | |
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
Base64.getEncoder().encodeToString(byteData) | |
} else { | |
String( | |
android.util.Base64.encode(byteData, android.util.Base64.DEFAULT), | |
StandardCharsets.UTF_8 | |
) |
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 path = ContextCompat.getExternalFilesDirs(requireContext(), null).first() | |
val bytesAvailable = path.freeSpace | |
val bytesSize = path.totalSpace | |
fun formatSize(size: Long): String? { | |
var size = size | |
var suffix: String? = null | |
if (size >= 1024) { | |
suffix = " KB" | |
size /= 1024 |
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.content.Context | |
import android.net.Uri | |
import androidx.hilt.work.HiltWorker | |
import androidx.work.* | |
import com.google.gson.Gson | |
import com.google.gson.stream.JsonReader | |
import dagger.assisted.Assisted | |
import dagger.assisted.AssistedInject | |
import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.withContext |
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
inline fun <reified T> String.jsonToObject(): T { | |
val gson = GsonBuilder().create() | |
return gson.fromJson(this, object: TypeToken<T>(){}.type) | |
} |
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
inline fun <reified T : Any> Response<*>.bodyOrThrow(): T { | |
if (isSuccessful && (code() == 200 || code() == 201)) return body() as T | |
else throw Exception() //or with custom exception | |
} |
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 NetworkMonitor(context: Context) : ConnectivityManager.NetworkCallback() { | |
private val weakContext = WeakReference(context) | |
private val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | |
private val networkRequest = NetworkRequest.Builder() | |
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR) | |
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI) | |
.addTransportType(NetworkCapabilities.TRANSPORT_ETHERNET) | |
.build() |
NewerOlder