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 compress(userInput: String): String { | |
| val charactersMap = HashMap<Char, Int>() | |
| val indexWithCharacter = StringBuilder() | |
| for (i in userInput.indices) { | |
| if ((i + 1) != userInput.length && userInput[i] == userInput[i + 1]) { | |
| if (!charactersMap.containsKey(userInput[i])) { | |
| indexWithCharacter.append("$i${userInput[i]}") | |
| charactersMap[userInput[i]] = i | |
| } | |
| } else { // in case character appears only one time in string |
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
| characterAdapter.onItemClicked = { character -> | |
| character.let { | |
| if (!character.id.isNullOrBlank()) { | |
| findNavController().navigate( | |
| CharactersListFragmentDirections.navigateToCharacterDetailsFragment( | |
| id = character.id | |
| ) | |
| ) | |
| } | |
| } |
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
| private fun observeLiveData() { | |
| viewModel.character.observe(viewLifecycleOwner) { response -> | |
| when (response) { | |
| is ViewState.Loading -> { | |
| binding.characterDetailsFetchProgress.visibility = View.VISIBLE | |
| binding.characterDetailsNotFound.visibility = View.GONE | |
| } | |
| is ViewState.Success -> { | |
| if (response.value?.data?.character == null) { | |
| binding.characterDetailsFetchProgress.visibility = View.GONE |
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"?> | |
| <layout xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:app="http://schemas.android.com/apk/res-auto" | |
| xmlns:tools="http://schemas.android.com/tools"> | |
| <data> | |
| <variable | |
| name="query" | |
| type="com.example.apollographqltutorial.CharacterQuery.Data" /> |
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 queryCharacter(id: String) = viewModelScope.launch { | |
| _character.postValue(ViewState.Loading()) | |
| try { | |
| val response = repository.queryCharacter(id) | |
| _character.postValue(ViewState.Success(response)) | |
| } catch (ae: ApolloException) { | |
| Log.d("ApolloException", "Failure", ae) | |
| _character.postValue(ViewState.Error("Error fetching characters")) | |
| } | |
| } |
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
| override suspend fun queryCharacter(id: String): Response<CharacterQuery.Data> { | |
| return webService.getApolloClient().query(CharacterQuery(id)).await() | |
| } |
NewerOlder