Report what was searched when there is no result
CHANGELOG.md
| 9 | 9 | * Clicking the back button when the radical panel is open will now close the panel | |
| 10 | 10 | instead of exiting the app. No change the behavior when the panel is already | |
| 11 | 11 | closed. | |
| 12 | + | * Report what was tried when there is no result. | |
| 12 | 13 | ||
| 13 | 14 | ### Translations | |
| 14 | 15 |
app/src/main/java/eu/lepiller/nani/MainActivity.java
| 27 | 27 | import eu.lepiller.nani.dictionary.DictionaryFactory; | |
| 28 | 28 | import eu.lepiller.nani.dictionary.IncompatibleFormatException; | |
| 29 | 29 | import eu.lepiller.nani.dictionary.NoDictionaryException; | |
| 30 | + | import eu.lepiller.nani.dictionary.NoResultDictionaryException; | |
| 30 | 31 | import eu.lepiller.nani.result.Result; | |
| 31 | 32 | import se.fekete.furiganatextview.furiganaview.FuriganaTextView; | |
| 32 | 33 | ||
… | |||
| 156 | 157 | @Override | |
| 157 | 158 | protected SearchResult doInBackground(String... sInput) { | |
| 158 | 159 | String text = sInput[0]; | |
| 160 | + | ArrayList<String> tried = new ArrayList<>(); | |
| 161 | + | tried.add(text); | |
| 159 | 162 | ||
| 160 | 163 | ArrayList<Result> searchResult; | |
| 161 | 164 | try { | |
… | |||
| 168 | 171 | if(searchResult.size() == 0) { | |
| 169 | 172 | MojiConverter converter = new MojiConverter(); | |
| 170 | 173 | try { | |
| 174 | + | tried.add(converter.convertRomajiToHiragana(text)); | |
| 171 | 175 | searchResult = DictionaryFactory.search(converter.convertRomajiToHiragana(text)); | |
| 172 | 176 | searchResult.addAll(DictionaryFactory.search(converter.convertRomajiToKatakana(text))); | |
| 173 | 177 | } catch (DictionaryException e) { | |
| 174 | 178 | return new SearchResult(e); | |
| 175 | 179 | } | |
| 176 | 180 | ||
| 181 | + | if(searchResult.size() == 0) { | |
| 182 | + | return new SearchResult(new NoResultDictionaryException(tried)); | |
| 183 | + | } | |
| 184 | + | ||
| 177 | 185 | return new SearchResult(searchResult, text, true); | |
| 178 | 186 | } else { | |
| 179 | 187 | return new SearchResult(searchResult, text, false); | |
… | |||
| 197 | 205 | } else if(e instanceof IncompatibleFormatException) { | |
| 198 | 206 | Snackbar.make(findViewById(R.id.search_form), String.format(getString(R.string.incompatible_format), | |
| 199 | 207 | ((IncompatibleFormatException) e).getName()), Snackbar.LENGTH_LONG).show(); | |
| 208 | + | } else if(e instanceof NoResultDictionaryException) { | |
| 209 | + | StringBuilder sb = new StringBuilder(); | |
| 210 | + | boolean first = true; | |
| 211 | + | for(String s: ((NoResultDictionaryException) e).getTried()) { | |
| 212 | + | if(first) { | |
| 213 | + | first = false; | |
| 214 | + | } else { | |
| 215 | + | sb.append(getText(R.string.sense_separator)); | |
| 216 | + | } | |
| 217 | + | sb.append(s); | |
| 218 | + | } | |
| 219 | + | feedback_text.setText(String.format(getString(R.string.feedback_no_result_tried), sb.toString())); | |
| 200 | 220 | } | |
| 201 | 221 | return; | |
| 202 | 222 | } | |
app/src/main/java/eu/lepiller/nani/dictionary/NoResultDictionaryException.java unknown status 1
| 1 | + | package eu.lepiller.nani.dictionary; | |
| 2 | + | ||
| 3 | + | import java.util.ArrayList; | |
| 4 | + | import java.util.List; | |
| 5 | + | ||
| 6 | + | public class NoResultDictionaryException extends DictionaryException { | |
| 7 | + | private ArrayList<String> tried; | |
| 8 | + | ||
| 9 | + | public NoResultDictionaryException(ArrayList<String> tried) { | |
| 10 | + | this.tried = tried; | |
| 11 | + | } | |
| 12 | + | ||
| 13 | + | public List<String> getTried() { | |
| 14 | + | return tried; | |
| 15 | + | } | |
| 16 | + | } |
app/src/main/res/layout/content_main.xml
| 50 | 50 | android:id="@+id/result_layout" | |
| 51 | 51 | android:layout_width="match_parent" | |
| 52 | 52 | android:layout_height="match_parent" | |
| 53 | - | android:orientation="vertical"> | |
| 53 | + | android:orientation="vertical" | |
| 54 | + | android:layout_margin="8dp"> | |
| 54 | 55 | ||
| 55 | 56 | <TextView | |
| 56 | 57 | android:id="@+id/feedback" |
app/src/main/res/values-fr/strings.xml
| 29 | 29 | <string name="dictionary_size_b">Taille r??elle : %d???o</string> | |
| 30 | 30 | <string name="downloading">T??l??chargement d\'un dictionnaire???</string> | |
| 31 | 31 | <string name="feedback_no_result">Pas de r??sultat</string> | |
| 32 | + | <string name="feedback_no_result_tried">Pas de r??sultat pour %s</string> | |
| 32 | 33 | <string name="feedback_progress">Recherche???</string> | |
| 33 | 34 | <string name="feedback_didyoumean">Vouliez-vous dire ?? %s ?? ?</string> | |
| 34 | 35 | <string name="alt_text_icon">Ic??ne</string> |
app/src/main/res/values/strings.xml
| 28 | 28 | <string name="dictionary_size_b">Actual size: %dB</string> | |
| 29 | 29 | <string name="downloading">Downloading a dictionary???</string> | |
| 30 | 30 | <string name="feedback_no_result">No result</string> | |
| 31 | + | <string name="feedback_no_result_tried">No result, search for %s</string> | |
| 31 | 32 | <string name="feedback_progress">Searching???</string> | |
| 32 | 33 | <string name="feedback_didyoumean">Did you mean "%s"?</string> | |
| 33 | 34 |