Skip to content

Instantly share code, notes, and snippets.

View yveskalume's full-sized avatar
🌍
Working from Anywhere

Yves Kalume yveskalume

🌍
Working from Anywhere
View GitHub Profile
class PostFragment : Fragment(), OnItemClickListener, MavericksView {
private val binding by lazy { FragmentPostBinding.inflate(layoutInflater) }
private val adapter by lazy { PostAdapter(this) }
private val postViewModel: PostViewModel by fragmentViewModel()
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
class PostViewModel(
initialState: PostState
) : MavericksViewModel<PostState>(initialState), KoinComponent {
private val repository: PostRepository by inject()
init {
getData()
}
private fun getData() {
data class PostState(
val post: Async<List<Post>> = Uninitialized
) : MavericksState
override fun invalidate(): Unit = withState(postViewModel) {
binding.progess.isVisible = it.post is Loading
when (it.post) {
is Success -> {
binding.progess.visibility = View.GONE
adapter.submitList(it.post.invoke())
}
is Fail -> {
Toast.makeText( requireContext(), "An error occured", Toast.LENGTH_SHORT).show()
Log.e("message", it.post.error.localizedMessage)
private val postViewModel: PostViewModel by fragmentViewModel()
override fun invalidate(): Unit = withState(postViewModel) {
binding.progess.isVisible = it.post is Loading
when (it.post) {
is Success -> {
binding.progess.visibility = View.GONE
adapter.submitList(it.post.invoke())
}
is Fail -> {
Toast.makeText( requireContext(), "An error occured", Toast.LENGTH_SHORT).show()
Log.e("message", it.post.error.localizedMessage)
private val postViewModel: PostViewModel by fragmentViewModel()
val options = FirebaseOptions.Builder()
.setProjectId("my-firebase-project")
.setApplicationId("1:27992087142:android:ce3b6448250083d1")
.setApiKey("AIzaSyADUe90ULnQDuGShD9W23RDP0xmeDc6Mvw") 
.build()
class App : Application() {
override fun onCreate() { 
super.onCreate()
val devOptions = FirebaseOptions.Builder()
.setProjectId("beserved-development-project")
.setApplicationId("1:212877806437:android:fee5f52927e2f7a907ed8c")
.setApiKey("AIzaSyADUe90ULnQDuGShD9W23RDP0xmeDc6Mvw")
.build()
val prodOptions = FirebaseOptions.Builder()
.setProjectId("beserved-production-project")
val instanceName = if (BuildConfig.DEBUG) "beserved-development" else "beserved-production"
FirebaseApp.getInstance(instanceName)