Skip to content

Instantly share code, notes, and snippets.

View labibmuhajir's full-sized avatar

Labib Muhajir labibmuhajir

View GitHub Profile
@labibmuhajir
labibmuhajir / Example.kt
Created December 13, 2019 15:52
example
/**
* You can edit, run, and share this code.
* play.kotlinlang.org
*/
fun main() {
val siswa1 = Siswa(Modules.nama)
val siswa2 = Siswa(Modules.module.get("nama"), Modules.module.get("kelas"))
println("siswa 1 nama: " + siswa1.nama)
@labibmuhajir
labibmuhajir / TabDivider.kt
Created April 21, 2020 10:18
android tab divider
with(tabCatalog) {
setupWithViewPager(vpCatalog)
val linearLayout = getChildAt(0) as LinearLayout
linearLayout.showDividers = LinearLayout.SHOW_DIVIDER_MIDDLE
val drawable = GradientDrawable()
drawable.setColor(ResourcesCompat.getColor(resources, R.color.black16, null))
drawable.setSize(1, 1)
linearLayout.dividerPadding = 40
linearLayout.dividerDrawable = drawable
requestLayout()
@labibmuhajir
labibmuhajir / collapsing_toolbar.xml
Last active April 7, 2021 20:38
toolbar collapsing
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toTopOf="@id/view_separator"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
@labibmuhajir
labibmuhajir / bottom_sheet_rounded_top_theme.xml
Last active April 7, 2021 20:37
Android Bottomsheet Rounded Top
<!-- android style -->
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="bottomSheetDialogTheme">@style/BottomSheetTheme</item>
</style>
<style name="BottomSheetTheme" parent="Theme.MaterialComponents.Light.BottomSheetDialog">
<item name="bottomSheetStyle">@style/BottomSheetModalStyle</item>
</style>
@labibmuhajir
labibmuhajir / network_security_config.xml
Created April 12, 2021 01:40
Network Security Config Http Android
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">yoururl</domain>
</domain-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
@labibmuhajir
labibmuhajir / flavor.kts
Created April 19, 2021 08:44
build flavor
android{
.....
fun getString(key: String): String {
val items = mutableMapOf<String, String>()
val fl = rootProject.file("./kmm/kmm.properties")
(fl.exists())?.let {
fl.forEachLine {
@labibmuhajir
labibmuhajir / NetworkBounceResource.kt
Last active April 30, 2021 01:52
Network Bounce Resource
class UserRepository @Inject constructor(
private val webservice: Webservice,
private val userDao: UserDao
) {
fun getUser(userId: String) =
object : NetworkBoundResource<User, User>() {
override suspend fun saveCallResult(item: User) {
userDao.save(item)
}
@labibmuhajir
labibmuhajir / DeleteFile.kt
Created April 30, 2021 02:02
Delete cache image
val outputDirectory = File(applicationContext.filesDir, OUTPUT_PATH)
if (outputDirectory.exists()) {
val entries = outputDirectory.listFiles()
if (entries != null) {
for (entry in entries) {
val name = entry.name
if (name.isNotEmpty() && name.endsWith(".png")) {
val deleted = entry.delete()
Timber.i("Deleted $name - $deleted")
}
@labibmuhajir
labibmuhajir / NetworkDownload.swift
Last active June 3, 2021 09:26
alamofire download file
class NetworkDownload {
static let shared = NetworkDownload()
func download(url: String, result: @escaping (URL) -> Void, onProgress: ((Double) -> Void)? = nil) {
let fileName = url.components(separatedBy: "/").last ?? "File \(Date.currentDateTime())"
let destination: DownloadRequest.DownloadFileDestination = { _, _ in
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let fileURL: URL = documentsURL.appendingPathComponent(fileName)
return (fileURL, [.removePreviousFile, .createIntermediateDirectories])
}
@labibmuhajir
labibmuhajir / DownloadManager.kt
Created June 3, 2021 08:11
Android Download Manager
class DownloadManager(private val context: Context) {
fun download(url: String, fileName: String) {
try {
val uri = Uri.parse(url)
val downloadRequest = DownloadManager.Request(uri).apply {
val extension = MimeTypeMap.getFileExtensionFromUrl(url)
val name = "$fileName.$extension"
setTitle(name)
setAllowedOverMetered(true)
setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)