79 lines
2.5 KiB
Kotlin
79 lines
2.5 KiB
Kotlin
|
package pl.edu.amu.wmi.socialaggregator.socialplatforms
|
||
|
|
||
|
import android.content.Context
|
||
|
import android.content.Intent
|
||
|
import android.graphics.Bitmap
|
||
|
import android.util.Log
|
||
|
import com.snapchat.kit.sdk.SnapCreative
|
||
|
import com.snapchat.kit.sdk.creative.api.SnapCreativeKitCompletionCallback
|
||
|
import com.snapchat.kit.sdk.creative.api.SnapCreativeKitSendError
|
||
|
import com.snapchat.kit.sdk.creative.exceptions.SnapMediaSizeException
|
||
|
import com.snapchat.kit.sdk.creative.models.SnapPhotoContent
|
||
|
import io.reactivex.Single
|
||
|
import io.reactivex.subjects.PublishSubject
|
||
|
import pl.edu.amu.wmi.socialaggregator.R
|
||
|
import pl.edu.amu.wmi.socialaggregator.viewholders.SocialWithButtonRecycler
|
||
|
import java.io.File
|
||
|
import java.lang.Exception
|
||
|
|
||
|
class Snapchat : SocialPlatform {
|
||
|
override fun getName(): String = "Snapchat"
|
||
|
|
||
|
override fun login(context: Context) {
|
||
|
}
|
||
|
|
||
|
override fun logout(context: Context) {
|
||
|
}
|
||
|
|
||
|
override fun isLoggedIn(context: Context): Boolean = true
|
||
|
|
||
|
override fun addPost(
|
||
|
publishSubject: PublishSubject<Any>,
|
||
|
context: Context,
|
||
|
text: String,
|
||
|
images: List<Bitmap>,
|
||
|
imagePaths: List<String>
|
||
|
) {
|
||
|
val snapCreativeKitApi = SnapCreative.getApi(context)
|
||
|
|
||
|
val content = imagePaths.map {
|
||
|
val snapMediaFactory = SnapCreative.getMediaFactory(context)
|
||
|
val photoFile = try {
|
||
|
snapMediaFactory.getSnapPhotoFromFile(File(it))
|
||
|
} catch (e: SnapMediaSizeException) {
|
||
|
Log.e(getName(), e.toString())
|
||
|
null
|
||
|
}
|
||
|
SnapPhotoContent(photoFile!!)
|
||
|
}.first()
|
||
|
|
||
|
snapCreativeKitApi.sendWithCompletionHandler(
|
||
|
content,
|
||
|
object : SnapCreativeKitCompletionCallback {
|
||
|
override fun onSendSuccess() {
|
||
|
publishSubject.onNext(Any())
|
||
|
}
|
||
|
|
||
|
override fun onSendFailed(p0: SnapCreativeKitSendError?) {
|
||
|
publishSubject.onError(Exception("Snapchat error"))
|
||
|
}
|
||
|
|
||
|
})
|
||
|
}
|
||
|
|
||
|
override fun getPosts(context: Context): Single<List<Post>> {
|
||
|
return Single.just(emptyList())
|
||
|
}
|
||
|
|
||
|
override fun getLogo(): Int = R.drawable.ic_icon_snapchat
|
||
|
|
||
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||
|
super.onActivityResult(requestCode, resultCode, data)
|
||
|
}
|
||
|
|
||
|
override fun handleButtonView(context: Context): (SocialWithButtonRecycler.ViewHolder) -> Unit =
|
||
|
{
|
||
|
it.image.setImageResource(getLogo())
|
||
|
it.textView.text = getName()
|
||
|
}
|
||
|
}
|