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
/* | |
* Copyright 2020 The Android Open Source Project | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
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
public class MyFragment | |
extends Fragment { | |
public MyFragment() { | |
super(R.layout.my_fragment); | |
} | |
private int selectedIndex = 0; | |
private FirstFragment firstFragment; |
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
import java.io.IOException; | |
import java.lang.annotation.Annotation; | |
import java.lang.reflect.Type; | |
import javax.annotation.Nullable; | |
import okhttp3.MediaType; | |
import okhttp3.RequestBody; | |
import okhttp3.ResponseBody; | |
import retrofit2.Converter; |
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 MainActivity : AppCompatActivity() { | |
private lateinit var swipeFragment: SwipeFragment | |
private lateinit var favoritesFragment: FavoritesFragment | |
private lateinit var newsFragment: NewsFragment | |
private val fragments: Array<out Fragment> get() = arrayOf(swipeFragment, favoritesFragment, newsFragment) | |
private fun selectFragment(selectedFragment: Fragment) { | |
var transaction = supportFragmentManager.beginTransaction() | |
fragments.forEachIndexed { index, fragment -> |
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
inline fun <reified T> Query.asLiveData(noinline onError: ((Throwable) -> Unit) = {}): FirestoreQueryLiveData<T> { | |
return FirestoreQueryLiveData(this, T::class.java, onError) | |
} | |
inline fun <reified T> DocumentReference.asLiveData(noinline onError: ((Throwable) -> Unit) = {}): FirestoreDocumentLiveData<T> { | |
return FirestoreDocumentLiveData(this, T::class.java, onError) | |
} | |
class FirestoreQueryLiveData<T>( | |
private val query: Query, |
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
import android.animation.LayoutTransition; | |
import android.content.Context; | |
import android.graphics.Canvas; | |
import android.os.Build; | |
import android.util.AttributeSet; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.view.WindowInsets; | |
import android.widget.FrameLayout; |
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
fun onLoginClicked() { | |
val username = // ... | |
navigationDispatcher.emit { navController -> | |
navController.navigate( | |
LoggedOutGraphDirections.loggedOutToLoggedIn(username)) | |
} | |
} | |
} |
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 LoginViewModel @ViewModelInject constructor( | |
private val navigationDispatcher: NavigationDispatcher, | |
@Assisted private val savedStateHandle: SavedStateHandle | |
) : ViewModel() { | |
fun onRegisterClicked() { | |
navigationDispatcher.emit { navController -> | |
navController.navigate(R.id.logged_out_to_registration) | |
} | |
} | |
} |
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
@AndroidEntryPoint | |
class MainActivity : AppCompatActivity() { | |
@Inject | |
lateinit var navigationDispatcher: NavigationDispatcher | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
navigationDispatcher.navigationCommands.observe(this) { command -> |
NewerOlder