Display file size and entry count in dictionary list
CHANGELOG.md
1 | 1 | Changelog | |
2 | 2 | ========= | |
3 | 3 | ||
4 | + | Changes In 0.2.2.1 | |
5 | + | ------------------ | |
6 | + | ||
7 | + | ### Features | |
8 | + | ||
9 | + | * Display expected file size and entry count in dictionary list. | |
10 | + | ||
4 | 11 | Changes In 0.2.2 | |
5 | 12 | ------------------- | |
6 | 13 |
app/src/main/java/eu/lepiller/nani/dictionary/DictionariesAdapter.java
9 | 9 | import android.widget.ImageView; | |
10 | 10 | import android.widget.TextView; | |
11 | 11 | ||
12 | + | import java.text.NumberFormat; | |
12 | 13 | import java.util.ArrayList; | |
13 | 14 | ||
14 | 15 | import eu.lepiller.nani.R; | |
… | |||
38 | 39 | ImageView icon_view = convertView.findViewById(R.id.icon_view); | |
39 | 40 | TextView name_view = convertView.findViewById(R.id.name_view); | |
40 | 41 | TextView description_view = convertView.findViewById(R.id.additional_info_view); | |
42 | + | TextView size_view = convertView.findViewById(R.id.file_size_view); | |
43 | + | TextView entry_count_view = convertView.findViewById(R.id.entries_view); | |
41 | 44 | ||
42 | 45 | // Populate the data into the template view using the data object | |
43 | 46 | Drawable icon = dictionary.getDrawable(context); | |
… | |||
57 | 60 | else | |
58 | 61 | convertView.setBackgroundColor(0); | |
59 | 62 | ||
63 | + | int size = dictionary.getExpectedFileSize(); | |
64 | + | if(size < 1500) | |
65 | + | size_view.setText(String.format(context.getString(R.string.dictionary_size_b), size)); | |
66 | + | else if(size < 1500000) | |
67 | + | size_view.setText(String.format(context.getString(R.string.dictionary_size_kb), size/1000)); | |
68 | + | else | |
69 | + | size_view.setText(String.format(context.getString(R.string.dictionary_size_mb), size/1000000)); | |
70 | + | ||
71 | + | int entries = dictionary.getExpectedEntries(); | |
72 | + | NumberFormat nf = NumberFormat.getInstance(); | |
73 | + | String formated = nf.format(entries); | |
74 | + | entry_count_view.setText(context.getResources().getQuantityString(R.plurals.dico_entry_count, entries, formated)); | |
75 | + | ||
60 | 76 | // Return the completed view to render on screen | |
61 | 77 | return convertView; | |
62 | 78 | } |
app/src/main/res/layout/layout_dictionary.xml
43 | 43 | android:layout_marginEnd="8dp" | |
44 | 44 | android:layout_marginRight="8dp" | |
45 | 45 | android:text="Description" /> | |
46 | + | ||
47 | + | <LinearLayout | |
48 | + | android:layout_width="match_parent" | |
49 | + | android:layout_height="wrap_content" | |
50 | + | android:orientation="horizontal"> | |
51 | + | <TextView | |
52 | + | android:id="@+id/file_size_view" | |
53 | + | android:layout_width="0dp" | |
54 | + | android:layout_height="wrap_content" | |
55 | + | android:layout_weight="50"/> | |
56 | + | <TextView | |
57 | + | android:id="@+id/entries_view" | |
58 | + | android:layout_width="0dp" | |
59 | + | android:layout_height="wrap_content" | |
60 | + | android:layout_weight="50"/> | |
61 | + | </LinearLayout> | |
46 | 62 | </LinearLayout> | |
47 | 63 | ||
48 | 64 | </LinearLayout> | |
48 | 64 | = | |
49 | 65 | = | \ No newline at end of file |
app/src/main/res/values/strings.xml
45 | 45 | <string name="error_dico_not_found">Error fetching dictionary list: cannot find it on server.</string> | |
46 | 46 | <string name="no_dico_list">Dictionary list not yet downloaded, updating???</string> | |
47 | 47 | <string name="error_dico_checksum_fail">Hash mismatch when verifying checksum: file is corrupted; deleting.</string> | |
48 | + | <plurals name="dico_entry_count"> | |
49 | + | <item quantity="one">%s entry</item> | |
50 | + | <item quantity="other">%s entries</item> | |
51 | + | </plurals> | |
52 | + | <string name="dictionary_expected_size_b">File size: %dB</string> | |
53 | + | <string name="dictionary_expected_size_kb">File size: %dKB</string> | |
54 | + | <string name="dictionary_expected_size_mb">File size: %dMB</string> | |
48 | 55 | ||
49 | 56 | <!-- Result view --> | |
50 | 57 | <string name="sense_number">%d.</string> |