This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DialogFragmentPresenter(val context: FragmentActivity) : DefaultLifecycleObserver { | |
private val pendingDialogs: MutableList<DialogFragmentPresentation> = mutableListOf() | |
private var canShowDialogs: Boolean = false | |
override fun onResume(owner: LifecycleOwner) { | |
canShowDialogs = true | |
pendingDialogs.forEach { | |
it.dialog.show(context.supportFragmentManager, it.tag) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DialogFragmentPresenter(val context: FragmentActivity) : DefaultLifecycleObserver { | |
private var canShowDialogs: Boolean = false | |
override fun onResume(owner: LifecycleOwner) { | |
canShowDialogs = true | |
} | |
override fun onPause(owner: LifecycleOwner) { | |
canShowDialogs = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RightDrawableOnTouchListener( | |
private val view: TextView, | |
private val listener: (MotionEvent) -> Boolean | |
) : | |
View.OnTouchListener { | |
private val drawable: Drawable? | |
get() { | |
val drawables = view.compoundDrawables | |
return if (drawables.size >= 2) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrganizationListViewModel : ViewModel() { | |
val liveData : RetrofitLiveData<List<Organization>> = DataHandler.INSTANCE.organizationHandler.getOrganizations() | |
override fun onCleared() { | |
liveData.cancel() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrganizationsHandler(val organizationsService: OrganizationsService) { | |
fun getOrganizations() : RetrofitLiveData<List<Organization>> = RetrofitLiveData(organizationsService.getOrganizations()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrganizationsHandler(val organizationsService: OrganizationsService) { | |
fun getOrganizations() : Call<List<Organization>> = organizationsService.getOrganizations() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RetrofitLiveData<T>(private val call: Call<T>) : LiveData<T>(), Callback<T> { | |
override fun onActive() { | |
if (!call.isCanceled && !call.isExecuted) call.enqueue(this) | |
} | |
override fun onFailure(call: Call<T>?, t: Throwable?) { | |
//not implemented | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DataHandler private constructor() { | |
companion object Singleton { | |
val INSTANCE: DataHandler by lazy { DataHandler() } | |
const val BASE_URL = "https://api.github.com" | |
} | |
val organizationHandler: OrganizationsHandler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Organization(val login: String, val id: Int, val avatarUrl: String, val description: String) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface OrganizationsService { | |
@GET("organizations") | |
fun getOrganizations(@Query("since") since : Int? = null) : Call<List<Organization>> | |
} |