Add feedback when no result is found
app/src/main/java/eu/lepiller/nani/MainActivity.java
| 27 | 27 | public class MainActivity extends AppCompatActivity implements OnTaskCompleted<SearchResult> { | |
| 28 | 28 | private LinearLayout result_view; | |
| 29 | 29 | private Button search_button; | |
| 30 | + | private TextView feedback_text; | |
| 30 | 31 | ||
| 31 | 32 | @Override | |
| 32 | 33 | protected void onCreate(Bundle savedInstanceState) { | |
… | |||
| 37 | 38 | ||
| 38 | 39 | search_button = findViewById(R.id.search_button); | |
| 39 | 40 | result_view = findViewById(R.id.results_view); | |
| 41 | + | feedback_text = findViewById(R.id.feedback); | |
| 40 | 42 | final EditText search_form = findViewById(R.id.search_form); | |
| 41 | 43 | ||
| 42 | 44 | search_button.setOnClickListener(new View.OnClickListener() { | |
… | |||
| 50 | 52 | ||
| 51 | 53 | result_view.removeAllViews(); | |
| 52 | 54 | search_button.setEnabled(false); | |
| 55 | + | feedback_text.setText(""); | |
| 53 | 56 | ||
| 54 | 57 | DictionaryFactory.prepare(getApplicationContext()); | |
| 55 | 58 | new SearchTask(MainActivity.this).execute(text); | |
… | |||
| 103 | 106 | } | |
| 104 | 107 | ||
| 105 | 108 | void showResults(ArrayList<Result> searchResult) { | |
| 109 | + | if(searchResult.size() == 0) { | |
| 110 | + | feedback_text.setText(R.string.feedback_no_result); | |
| 111 | + | return; | |
| 112 | + | } | |
| 113 | + | ||
| 106 | 114 | int num = 0; | |
| 107 | 115 | for(Result result: searchResult) { | |
| 108 | 116 | num++; | |
app/src/main/res/layout/content_main.xml
| 39 | 39 | android:layout_marginEnd="16dp" | |
| 40 | 40 | android:layout_marginRight="16dp" | |
| 41 | 41 | android:text="@string/search_button" /> | |
| 42 | + | ||
| 42 | 43 | </LinearLayout> | |
| 43 | 44 | ||
| 45 | + | <TextView | |
| 46 | + | android:id="@+id/feedback" | |
| 47 | + | android:layout_width="match_parent" | |
| 48 | + | android:layout_height="wrap_content" /> | |
| 49 | + | ||
| 44 | 50 | <ScrollView | |
| 45 | 51 | android:layout_weight="1" | |
| 46 | 52 | android:layout_width="match_parent" |
app/src/main/res/values-fr/strings.xml
| 20 | 20 | <string name="kanji_description">??criture</string> | |
| 21 | 21 | ||
| 22 | 22 | <string name="dictionary_size">Taille r??elle : %d???Mo</string> | |
| 23 | + | <string name="feedback_no_result">Pas de r??sultat</string> | |
| 23 | 24 | ||
| 24 | 25 | <!-- Dictionnary descriptions --> | |
| 25 | 26 |
app/src/main/res/values/strings.xml
| 17 | 17 | <string name="kanji_description">Writing</string> | |
| 18 | 18 | ||
| 19 | 19 | <string name="dictionary_size">Actual size: %dMB</string> | |
| 20 | + | <string name="feedback_no_result">No result</string> | |
| 20 | 21 | ||
| 21 | 22 | <!-- Dictionnary descriptions --> | |
| 22 | 23 | <string name="dico_jmdict_e">Japanese/English dictionary from the Electronic Dictionary Research and Development Group.\n~56 MB, ~180,000 entries.</string> |