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
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) |
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
private val postViewModel: PostViewModel by fragmentViewModel() |
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 PostState( | |
val post: Async<List<Post>> = Uninitialized | |
) : MavericksState |
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 PostViewModel( | |
initialState: PostState | |
) : MavericksViewModel<PostState>(initialState), KoinComponent { | |
private val repository: PostRepository by inject() | |
init { | |
getData() | |
} | |
private fun getData() { |
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 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? { |
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
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) |
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
private val postViewModel: PostViewModel by fragmentViewModel() |
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
val instanceName = if (BuildConfig.DEBUG) "beserved-development" else "beserved-production" | |
FirebaseApp.getInstance(instanceName) |
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 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") |
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
val options = FirebaseOptions.Builder() | |
.setProjectId("my-firebase-project") | |
.setApplicationId("1:27992087142:android:ce3b6448250083d1") | |
.setApiKey("AIzaSyADUe90ULnQDuGShD9W23RDP0xmeDc6Mvw") | |
.build() |
OlderNewer