Skip to content

Instantly share code, notes, and snippets.

Avatar
🎸

Alperen Babagil alperenbabagil

🎸
View GitHub Profile
View ProfileDetailDataSource.kt
class ProfileDetailDataSource(
private val profileService: ProfileService,
private val apiCallAdapter: ApiCallAdapter
) : BaseDataSource<ResponseTemplate<ProfileDetailDataTemplate>, ProfileDetailNetworkDTO>() {
override suspend fun getDataSourceResult(request: BaseRequest<ResponseTemplate<ProfileDetailDataTemplate>>):
DataHolder<ProfileDetailNetworkDTO> = apiCallAdapter.adapt {
profileService.getProfileDetail(request)
}
}
@alperenbabagil
alperenbabagil / Interactor.kt
Last active Sep 25, 2020
Example Interactor
View Interactor.kt
class ChangePasswordInteractor(private val repository: ProfileRepository) :
BaseInteractor(), Interactor.SingleInteractor<ChangePasswordInteractor.Params, Any> {
class Params(val oldPassword:String,val newPassword:String) : Interactor.Params()
override suspend fun execute(params: Params): DataHolder<Any> =
repository.changePassword(ChangePasswordRequest(params.oldPassword,params.newPassword))
}
View DataHolder.kt
sealed class DataHolder<out T: Any> {
data class Success<out T : Any>(val data:T) : DataHolder<T>()
data class Fail(val error: BaseError?=null) : DataHolder<Nothing>()
data class Loading() : DataHolder<Nothing>()
}
View NotificationHelper.kt
val builder = NotificationCompat.Builder(context, AppNavigator.NOTF_CHANNEL_ID)
.setSmallIcon(android.R.drawable.arrow_up_float)
.setContentTitle(context.getString(R.string.app_name))
.setContentText(context.getString(R.string.channel_description))
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_CALL)
.setAutoCancel(true)
val pendingIntent = PendingIntent.getActivity(context,
0,
Intent(context, RingActivity::class.java),
View HMSPushService.kt
override fun onMessageReceived(remoteMessage: RemoteMessage?) {
super.onMessageReceived(remoteMessage)
remoteMessage?.let {
if(it.data.isNotEmpty()){
//data message
try {
val pushDataModel= Gson().fromJson(it.data,PushDataModel::class.java)
handleNotification(pushDataMceodel)
}
catch (e:Exception){
@alperenbabagil
alperenbabagil / DataMessageModel
Last active Aug 17, 2020
Data message structure
View DataMessageModel
{
"validate_only": false,
"message": {
"data": "{'param1':'value1','param2':'value2'}",
"token": ["pushtoken1","pushtoken2"]
}
}