This file contains hidden or 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
| package FXBrowser; | |
| public interface DefaultURL { | |
| //The default URL. | |
| public static final String DEFAULT_URL = "http://365programperday.blogspot.in/"; | |
| } |
This file contains hidden or 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
| fun AppCompatActivity.subscribeToBroadcastsOnLifecycle(action: String, fn: (Intent) -> Unit) { | |
| observeBroadcasts(action).subscribeOnLifecycle(lifecycle, fn) | |
| } | |
| fun <T> Observable<T>.subscribeOnLifecycle(lifecycle: Lifecycle, fn: (T) -> Unit) { | |
| val lifecycleObserver: LifecycleObserver = object : LifecycleObserver { | |
| private var subscription: Disposable? = null | |
| @OnLifecycleEvent(Lifecycle.Event.ON_START) | |
| fun onStart() { |
This file contains hidden or 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
| fun <L : LiveData<T>, T : Any> LifecycleOwner.observe(liveData: L, body: (T?) -> Unit) = | |
| liveData.observe(this, Observer(body)) | |
| //Activity view model | |
| @MainThread | |
| inline fun <reified VM : BaseViewModel> Fragment.activityViewModels(body: VM.() -> Unit): VM = | |
| ViewModelProviders.of(this.requireActivity()).get<VM>().apply(body) | |
This file contains hidden or 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
| import android.app.Activity | |
| import android.os.Bundle | |
| class HomeActivity: Activity() { | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| setContentView(R.layout.activity_home) | |
| } | |
| override fun onStart() { |
This file contains hidden or 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
| <manifest ... > | |
| <application ... > | |
| <activity android:name=".HomeActivity" /> | |
| ... | |
| </application ... > | |
| ... | |
| </manifest > |
This file contains hidden or 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
| import android.content.Context | |
| import android.os.Bundle | |
| import android.view.LayoutInflater | |
| import android.view.View | |
| import android.view.ViewGroup | |
| import androidx.fragment.app.Fragment | |
| class HomeFragment: Fragment() { | |
| override fun onAttach(context: Context) { |
This file contains hidden or 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
| <?xml version="1.0" encoding="utf-8"?> | |
| <androidx.fragment.app.FragmentContainerView | |
| xmlns:android="http://schemas.android.com/apk/res/android" | |
| android:id="@+id/fragment_container_view" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| android:name="com.alokomkar.activity.HomeFragment" /> |
This file contains hidden or 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
| fun main() = runBlocking { // this: CoroutineScope | |
| launch { // launch a new coroutine and continue | |
| delay(1000L) // non-blocking delay for 1 second (default time unit is ms) | |
| println("World!") // print after delay | |
| } | |
| println("Hello") // main coroutine continues while a previous one is delayed | |
| } | |
This file contains hidden or 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
| fun main() = runBlocking { // this: CoroutineScope | |
| launch { doWorld() } | |
| println("Hello") | |
| } | |
| // this is your first suspending function | |
| suspend fun doWorld() { | |
| delay(1000L) | |
| println("World!") | |
| } |
This file contains hidden or 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
| // Sequentially executes doWorld followed by "Done" | |
| fun main() = runBlocking { | |
| doWorld() | |
| println("Done") | |
| } | |
| // Concurrently executes both sections | |
| suspend fun doWorld() = coroutineScope { // this: CoroutineScope | |
| launch { // Coroutine 1 |
OlderNewer