Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View alperenbabagil's full-sized avatar
🎸

Alperen Babagil alperenbabagil

🎸
View GitHub Profile
@alperenbabagil
alperenbabagil / ProfileDetailDataSource.kt
Last active September 25, 2020 23:11
Data Source Example
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 September 25, 2020 22:18
Example Interactor
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))
}
@alperenbabagil
alperenbabagil / DataHolder.kt
Created September 25, 2020 22:10
Example DataHolder
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>()
}
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),
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 August 17, 2020 06:45
Data message structure
{
"validate_only": false,
"message": {
"data": "{'param1':'value1','param2':'value2'}",
"token": ["pushtoken1","pushtoken2"]
}
}