Display file size and entry count in dictionary list

Julien LepillerSun May 31 18:36:21+0200 2020

87487d5

Display file size and entry count in dictionary list

CHANGELOG.md

11
Changelog
22
=========
33
4+
Changes In 0.2.2.1
5+
------------------
6+
7+
### Features
8+
9+
* Display expected file size and entry count in dictionary list.
10+
411
Changes In 0.2.2
512
-------------------
613

app/src/main/java/eu/lepiller/nani/dictionary/DictionariesAdapter.java

99
import android.widget.ImageView;
1010
import android.widget.TextView;
1111
12+
import java.text.NumberFormat;
1213
import java.util.ArrayList;
1314
1415
import eu.lepiller.nani.R;

3839
        ImageView icon_view = convertView.findViewById(R.id.icon_view);
3940
        TextView name_view = convertView.findViewById(R.id.name_view);
4041
        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);
4144
4245
        // Populate the data into the template view using the data object
4346
        Drawable icon = dictionary.getDrawable(context);

5760
        else
5861
            convertView.setBackgroundColor(0);
5962
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+
6076
        // Return the completed view to render on screen
6177
        return convertView;
6278
    }

app/src/main/res/layout/layout_dictionary.xml

4343
            android:layout_marginEnd="8dp"
4444
            android:layout_marginRight="8dp"
4545
            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>
4662
    </LinearLayout>
4763
4864
</LinearLayout>
4864=
4965=
\ No newline at end of file

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

4545
    <string name="error_dico_not_found">Error fetching dictionary list: cannot find it on server.</string>
4646
    <string name="no_dico_list">Dictionary list not yet downloaded, updating???</string>
4747
    <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>
4855
4956
    <!-- Result view -->
5057
    <string name="sense_number">%d.</string>