Skip to content

Commit

Permalink
collections
Browse files Browse the repository at this point in the history
take flags
retrofit add images to hashmap
  • Loading branch information
CraZyLegenD committed Jun 6, 2019
1 parent 39b8bdd commit f887afd
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion kotlinextensions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ dependencies {
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.14.1'
implementation 'com.squareup.okhttp3:logging-interceptor:4.0.0-alpha02'
implementation 'io.reactivex.rxjava2:rxkotlin:2.3.0'
implementation 'com.jakewharton.rxbinding2:rxbinding-kotlin:2.2.0'
implementation 'androidx.core:core-ktx:1.2.0-alpha01'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,4 +899,9 @@ inline fun <T, R : Any> Iterable<T>.mapNotNullToSet(transform: (T) -> R?) =

fun <T> Comparator<T>.sort(list: MutableList<T>) {
list.sortWith(this)
}
}


fun <T> listEqualsIgnoreOrder(list1: List<T>, list2: List<T>): Boolean {
return HashSet(list1) == HashSet(list2)
}
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,5 @@ fun Context.dialPhoneNumber(phoneNumber: String) {
}
}

val Intent.takeFlags: Int get() = flags and
(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.crazylegend.kotlinextensions.retrofit

import com.crazylegend.kotlinextensions.exhaustive
import okhttp3.MediaType
import okhttp3.RequestBody
import okhttp3.ResponseBody
import retrofit2.Retrofit
import java.io.File
import okhttp3.RequestBody.Companion.toRequestBody


/**
Expand Down Expand Up @@ -78,3 +82,34 @@ fun <T> RetrofitResult<T>.handle(
}.exhaustive
}

const val multiPartContentType = "multipart/form-data"

fun HashMap<String,RequestBody>.addImagesToRetrofit(pathList:List<String>){
if (pathList.isNotEmpty()){
pathList.forEachIndexed { index, s ->
val key = String.format("%1\$s\"; filename=\"%1\$s", "photo_" + "${index+1}")
this[key] = File(s).toRequestBody(MediaType.parse(multiPartContentType))
}
}
}


/**
*
* val hashMap: HashMap<String, RequestBody> = HashMap()
if (pathList.isNotEmpty()){
hashMap.addImages(pathList.map {
it.pathToImage
})
}
*/
/**
*
@Multipart
@POST()
fun postNewWaterMeterMeasurementWithImages(@Header("Authorization") token: String,
@PartMap images: Map<String,@JvmSuppressWildcards RequestBody>): Single<Response<ResponseBody>>
*
*/

0 comments on commit f887afd

Please sign in to comment.