Skip to content

Instantly share code, notes, and snippets.

View eyeahs's full-sized avatar

박현우(HyunwooPark) eyeahs

  • Hyundai
  • South Korea
View GitHub Profile
@eyeahs
eyeahs / Base64.kt
Created January 2, 2019 07:07 — forked from hrules6872/Base64.kt
Base64.kt for Kotlin
fun String.encodeBase64ToString(): String = String(this.toByteArray().encodeBase64())
fun String.encodeBase64ToByteArray(): ByteArray = this.toByteArray().encodeBase64()
fun ByteArray.encodeBase64ToString(): String = String(this.encodeBase64())
fun String.decodeBase64(): String = String(this.toByteArray().decodeBase64())
fun String.decodeBase64ToByteArray(): ByteArray = this.toByteArray().decodeBase64()
fun ByteArray.decodeBase64ToString(): String = String(this.decodeBase64())
fun ByteArray.encodeBase64(): ByteArray {
val table = (CharRange('A', 'Z') + CharRange('a', 'z') + CharRange('0', '9') + '+' + '/').toCharArray()
@eyeahs
eyeahs / EventObserver.kt
Created November 1, 2018 13:51 — forked from JoseAlcerreca/EventObserver.kt
An Observer for Events, simplifying the pattern of checking if the Event's content has already been handled.
/**
* An [Observer] for [Event]s, simplifying the pattern of checking if the [Event]'s content has
* already been handled.
*
* [onEventUnhandledContent] is *only* called if the [Event]'s contents has not been handled.
*/
class EventObserver<T>(private val onEventUnhandledContent: (T) -> Unit) : Observer<Event<T>> {
override fun onChanged(event: Event<T>?) {
event?.getContentIfNotHandled()?.let { value ->
onEventUnhandledContent(value)
@eyeahs
eyeahs / MyTest.java
Created May 10, 2016 08:28 — forked from romainpiel/MyTest.java
Source for https://medium.com/p/3f6f4179652e - "RecyclerView and espresso, a complicated story"
RecyclerViewInteraction.<Item>onRecyclerView(withId(R.id.recyclerview))
.withItems(items)
.check(new ItemViewAssertion<Item>() {
@Override
public void check(Item item, View view, NoMatchingViewException e) {
matches(hasDescendant(withText(item.getDisplayName())))
.check(view, e);
}
});

##Getting results from DialogFragments to another Fragment.

When setting up the DialogFragment make a call to Fragment.setTargetFragment()
Then from DialogFragment you can access the main fragment with Fragment.getTargetFragment()
Use interfaces to provide the required actions to the calling Fragment.

##Example code.

###AddFriendDialogFragment - Calls back to calling fragment.