Skip to content

Instantly share code, notes, and snippets.

private val compositeDisposable = CompositeDisposable()
private val photoChangeState: Subject<Boolean> = PublishSubject.create()
private var isPhotoChanged: Boolean = false
set(value) {
field = value
photoChangeState.onNext(value)
}
//---------
@AndSky90
AndSky90 / ImageProcessor
Created November 4, 2019 12:00
Image compress and rotate
object ImageProcessor {
private const val MAX_IMAGE_DIMENSION = 1920
private const val COMPRESS_QUALITY = 100
@Throws(IOException::class)
fun saveImageWithFixFromUri(context: Context, uri: Uri, filePath: String) {
val bitmap = getFixedImageFromUri(context, uri)
saveBitmapToFile(bitmap, filePath)
}
val b = BitmapFactory.decodeFile(filePath)
val stream = ByteArrayOutputStream()
b.compress(Bitmap.CompressFormat.JPEG, 100, stream)
val ba = stream.toByteArray()
photoPart = RequestBody.create(MediaType.parse("image/jpeg"), ba)
body = MultipartBody.Part.createFormData("Photo", "Photo.jpg", photoPart!!)
val part = RequestBody.create(MediaType.parse("text/plain"), text)
@Multipart
@AndSky90
AndSky90 / gist:578a222be0864a06aaab91343e6be646
Created November 4, 2019 14:07
observable from callable rx
fun loadPdf(url: String) = Observable.fromCallable {
val request = Request.Builder().url(url).build()
val call = coreNetwork.getOkHttp().newCall(request)
call.execute().body()!!.source().inputStream()
}
@AndSky90
AndSky90 / ImageViewerActivity.kt
Created November 4, 2019 14:16
PhotoView ImageGallery Custom
import android.os.Bundle
import android.view.Menu
import android.view.View
import androidx.core.view.isVisible
import com.arellomobile.mvp.presenter.InjectPresenter
import com.arellomobile.mvp.presenter.ProvidePresenter
import kotlinx.android.synthetic.main.image_viewer.*
import javax.inject.Inject
import kotlin.math.abs
@AndSky90
AndSky90 / CustomWebViewClient.kt
Created November 4, 2019 14:20
WebView client handle clicks image/mail/link
import android.webkit.WebView
import android.webkit.WebResourceRequest
import android.os.Build
import android.annotation.TargetApi
import android.content.ActivityNotFoundException
import android.content.Context
import android.webkit.WebViewClient
import android.content.Intent
import android.net.Uri
var text: String
get() = editText.text.toString()
set(value) {
editText.setText(value, TextView.BufferType.EDITABLE)
}
@AndSky90
AndSky90 / AvatarIcon.kt
Created November 4, 2019 14:35
Avatar Icon
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import kotlinx.android.synthetic.main.avatar_icon.view.*
class AvatarIcon(context: Context, attrs: AttributeSet?) : ConstraintLayout(context, attrs) {
private var mask: Int? = null
@AndSky90
AndSky90 / AndroidManifest.xml
Last active December 27, 2019 07:28
Firebase push handling
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="...">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="..."
@AndSky90
AndSky90 / AccessTokenAuthenticator.kt
Last active November 16, 2019 13:13
Okhttp config
class AccessTokenAuthenticator : Authenticator {
@Throws(IOException::class)
override fun authenticate(route: Route?, response: Response): Request? {
val token = AuthProvider.getTokenInfoFromCache()?.refreshToken?.token
val coreNetworkComponent = CoreNetworkComponent.get()
synchronized(this) {
if (token != null) {