Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

445: Stores spoken keyboard prompts to Recents #530

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/src/main/java/com/willowtree/vocable/PhrasesUseCase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,15 @@ class PhrasesUseCase(
sortOrder = legacyPhrasesRepository.getPhrasesForCategory(parentCategoryId).size
))
}

suspend fun addPhraseSpokenNow(localizedUtterance: LocalesWithText, parentCategoryId: String) {
storedPhrasesRepository.addPhrase(PhraseDto(
phraseId = uuidProvider.randomUUIDString(),
parentCategoryId = parentCategoryId,
creationDate = dateProvider.currentTimeMillis(),
lastSpokenDate = dateProvider.currentTimeMillis(),
localizedUtterance = localizedUtterance,
sortOrder = legacyPhrasesRepository.getPhrasesForCategory(parentCategoryId).size
))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.core.view.children
import androidx.core.view.isVisible
import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.GridLayoutManager
Expand All @@ -14,12 +15,15 @@ import com.willowtree.vocable.R
import com.willowtree.vocable.customviews.PointerListener
import com.willowtree.vocable.databinding.FragmentKeyboardBinding
import com.willowtree.vocable.keyboard.adapter.KeyboardAdapter
import com.willowtree.vocable.presets.PresetCategories
import com.willowtree.vocable.utils.ItemOffsetDecoration
import com.willowtree.vocable.utils.VocableTextToSpeech
import java.util.Locale

class KeyboardFragment : BaseFragment<FragmentKeyboardBinding>() {

private val viewModel: KeyboardFragmentViewModel by viewModels()

override val bindingInflater: BindingInflater<FragmentKeyboardBinding> =
FragmentKeyboardBinding::inflate
private lateinit var keys: Array<String>
Expand Down Expand Up @@ -104,10 +108,12 @@ class KeyboardFragment : BaseFragment<FragmentKeyboardBinding>() {

binding.keyboardSpeakButton.action = {
if (!isDefaultTextVisible()) {
val text = binding.keyboardInput.text?.toString() ?: ""
VocableTextToSpeech.speak(
Locale.getDefault(),
binding.keyboardInput.text?.toString() ?: ""
text
)
viewModel.addNewPhrase(text, PresetCategories.RECENTS.id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You exposed a flaw in how our categories are set up, nice! We don't actually want to be storing phrases under the "RECENTS" category, instead we determine RECENTS by just looking at the most recently used phrases PhrasesUseCase#getPhrasesForCategory().

Totally understand how you got here, and we should clean up the API to not allow creating a phrase with "Recent" as the category, could you create a ticket on the board to track that? Up to you whether or not you tackle that, but we should get it written down.

As far as the defect at hand, I don't think we actually want just anything spoken from the keyboard to be saved, and this is corroborated by how the iOS app works. Instead, Android is currently missing functionality where a user can save a phrase directly from the keyboard. Download the Vocable iOS app to your Mac and poke around to see what I mean. Once you feel comfortable, I think we should discard the current bug as "won't-fix" and write up an enhancement to match iOS's functionality here.

Copy link
Contributor Author

@cinadia cinadia May 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a new issue for the API cleanup: #534

As for saving phrases directly from the keyboard, on iOS they're stored under the "My Sayings" category, but on Android the "My Sayings" category is depricated. Would you like to bring it back?

image

Copy link
Contributor Author

@cinadia cinadia May 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated #445 to reflect adding the My Sayings enhancement. Can probably close this PR

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cinadia Agreed!

}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.willowtree.vocable.keyboard
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.willowtree.vocable.PhrasesUseCase
import com.willowtree.vocable.utils.locale.LocalesWithText
import kotlinx.coroutines.launch
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import java.util.Locale

class KeyboardFragmentViewModel : ViewModel(), KoinComponent {

private val phrasesUseCase: PhrasesUseCase by inject()

fun addNewPhrase(phraseStr: String, categoryId: String) {
viewModelScope.launch {
phrasesUseCase.addPhraseSpokenNow(
LocalesWithText(mapOf(Pair(Locale.getDefault().toString(), phraseStr))),
categoryId
)
}
}
}


Loading