Report what was searched when there is no result

Julien LepillerSat Jun 20 00:53:28+0200 2020

440df4e

Report what was searched when there is no result

CHANGELOG.md

99
* Clicking the back button when the radical panel is open will now close the panel
1010
  instead of exiting the app. No change the behavior when the panel is already
1111
  closed.
12+
* Report what was tried when there is no result.
1213
1314
### Translations
1415

app/src/main/java/eu/lepiller/nani/MainActivity.java

2727
import eu.lepiller.nani.dictionary.DictionaryFactory;
2828
import eu.lepiller.nani.dictionary.IncompatibleFormatException;
2929
import eu.lepiller.nani.dictionary.NoDictionaryException;
30+
import eu.lepiller.nani.dictionary.NoResultDictionaryException;
3031
import eu.lepiller.nani.result.Result;
3132
import se.fekete.furiganatextview.furiganaview.FuriganaTextView;
3233

156157
        @Override
157158
        protected SearchResult doInBackground(String... sInput) {
158159
            String text = sInput[0];
160+
            ArrayList<String> tried = new ArrayList<>();
161+
            tried.add(text);
159162
160163
            ArrayList<Result> searchResult;
161164
            try {

168171
            if(searchResult.size() == 0) {
169172
                MojiConverter converter = new MojiConverter();
170173
                try {
174+
                    tried.add(converter.convertRomajiToHiragana(text));
171175
                    searchResult = DictionaryFactory.search(converter.convertRomajiToHiragana(text));
172176
                    searchResult.addAll(DictionaryFactory.search(converter.convertRomajiToKatakana(text)));
173177
                } catch (DictionaryException e) {
174178
                    return new SearchResult(e);
175179
                }
176180
181+
                if(searchResult.size() == 0) {
182+
                    return new SearchResult(new NoResultDictionaryException(tried));
183+
                }
184+
177185
                return new SearchResult(searchResult, text, true);
178186
            } else {
179187
                return new SearchResult(searchResult, text, false);

197205
            } else if(e instanceof IncompatibleFormatException) {
198206
                Snackbar.make(findViewById(R.id.search_form), String.format(getString(R.string.incompatible_format),
199207
                        ((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()));
200220
            }
201221
            return;
202222
        }

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

5050
            android:id="@+id/result_layout"
5151
            android:layout_width="match_parent"
5252
            android:layout_height="match_parent"
53-
            android:orientation="vertical">
53+
            android:orientation="vertical"
54+
            android:layout_margin="8dp">
5455
5556
            <TextView
5657
                android:id="@+id/feedback"

app/src/main/res/values-fr/strings.xml

2929
    <string name="dictionary_size_b">Taille r??elle : %d???o</string>
3030
    <string name="downloading">T??l??chargement d\'un dictionnaire???</string>
3131
    <string name="feedback_no_result">Pas de r??sultat</string>
32+
    <string name="feedback_no_result_tried">Pas de r??sultat pour %s</string>
3233
    <string name="feedback_progress">Recherche???</string>
3334
    <string name="feedback_didyoumean">Vouliez-vous dire ?? %s ?? ?</string>
3435
    <string name="alt_text_icon">Ic??ne</string>

app/src/main/res/values/strings.xml

2828
    <string name="dictionary_size_b">Actual size: %dB</string>
2929
    <string name="downloading">Downloading a dictionary???</string>
3030
    <string name="feedback_no_result">No result</string>
31+
    <string name="feedback_no_result_tried">No result, search for %s</string>
3132
    <string name="feedback_progress">Searching???</string>
3233
    <string name="feedback_didyoumean">Did you mean "%s"?</string>
3334