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 onClickLikeButton() { | |
| if (viewModel.liked) { | |
| //First we update the local model so the user feels the action is instantaneous | |
| viewModel.liked = false | |
| viewModel.count-- | |
| //Then we call the API to update it on the server | |
| apiService.removeLike.enqueue({ response -> | |
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 onClickLikeButton() { | |
| if (viewModel.liked) { | |
| removeLike() | |
| } else { | |
| addLike() | |
| } | |
| } | |
| private fun addLike() { | |
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
| class ViewModel { | |
| //... here comes the attributes and the model | |
| //we are changing (irrelevant for the example) | |
| fun addLikeLocally() { | |
| liked = true | |
| count++ | |
| } | |
| fun removeLikeLocally() { |
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 onClickLikeButton() { | |
| if (viewModel.liked) { | |
| removeLike() | |
| } else { | |
| addLike() | |
| } | |
| } | |
| private fun showError(errorMessage: String) { | |
| Toast.makeToast(activity, errorMessage, LENGTH_LONG).show() |
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
| dependencies { | |
| ... | |
| } | |
| //This step below fixes the issues | |
| afterEvaluate { | |
| android.applicationVariants.all { | |
| def name = it.name.capitalize() | |
| tasks["kapt${name}Kotlin"].dependsOn("transformDataBindingWithDataBindingMergeArtifactsFor${name}") | |
| } |
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
| object BindingAdapters { | |
| @BindingAdapter(values = ["selected", "options"], requireAll = false) | |
| @JvmStatic | |
| fun setOptionsAndSelected(view: MyCustomView, selected: Option?, options: List<Option>?) { | |
| options?.let { | |
| view.setOptions(it) | |
| } | |
| selected?.let { |
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
| class SectionPagerAdapter( | |
| fragmentManager: FragmentManager, | |
| private val sections: List<Section> | |
| ): FragmentStatePagerAdapter(fragmentManager) { | |
| var currentFormSection: FormSection? = null | |
| override fun getItem(position: Int): Fragment { | |
| return when (sections[position].type) { | |
| SectionType.MAP -> MapFragment.newInstance(sections[position]) |
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
| class MainActivity : AppCompatActivity() { | |
| private val viewPager by lazy { findViewById<ViewPager>(R.id.viewPager) } | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| setContentView(R.layout.activity_main) | |
| //getSections somehow from API/local storage |
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
| class FormFragment : Fragment() { | |
| private val section by lazy { arguments!!.getParcelable<Section>(SECTION) } | |
| private val fieldInputs = mutableListOf<FieldInput>() | |
| override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | |
| val view = inflater.inflate(R.layout.form_section_fragment, container, false) | |
| return view | |
| } |
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
| interface FieldInput { | |
| var key: String | |
| fun getValue(): String | |
| fun setHint(hint: String) | |
| } |