Skip to content

Commit 1e5829f

Browse files
committed
Show the size of remote dictionaries
This is an important information that users might want to know before clicking download.
1 parent 91523d6 commit 1e5829f

File tree

5 files changed

+29
-14
lines changed

5 files changed

+29
-14
lines changed

res/layout/dictionaries_activity.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true" android:fitsSystemWindows="true">
33
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical">
44
<TextView style="@style/paragraph" android:text="@string/dictionaries_from_internet"/>
5-
<juloo.keyboard2.dict.DictionaryListView style="@style/dictionaryListView"/>
5+
<juloo.keyboard2.dict.DictionaryListView style="@style/dictionary_list_view"/>
66
</LinearLayout>
77
</ScrollView>
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" style="@style/dictionaryDownloadItem">
3-
<TextView android:id="@+id/dictionary_download_locale" style="@style/dictionaryDownloadText"/>
4-
<View android:id="@+id/dictionary_download_button" style="@style/dictionaryDownloadButton"/>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" style="@style/dictionary_download_item">
3+
<TextView android:id="@+id/dictionary_download_locale" style="@style/dictionary_download_locale"/>
4+
<TextView android:id="@+id/dictionary_download_size" style="@style/dictionary_download_size"/>
5+
<View android:id="@+id/dictionary_download_button" style="@style/dictionary_download_button" android:background="@drawable/ic_download"/>
56
</LinearLayout>

res/values/styles.xml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,28 +93,37 @@
9393
<item name="android:orientation">horizontal</item>
9494
</style>
9595
<!-- Dictionaries activity -->
96-
<style name="dictionaryListView">
96+
<style name="dictionary_list_view">
9797
<item name="android:layout_width">fill_parent</item>
9898
<item name="android:layout_height">wrap_content</item>
9999
<item name="android:layout_marginVertical">24dp</item>
100100
</style>
101-
<style name="dictionaryDownloadItem">
101+
<style name="dictionary_download_item">
102102
<item name="android:orientation">horizontal</item>
103103
<item name="android:layout_width">fill_parent</item>
104104
<item name="android:layout_height">wrap_content</item>
105105
<item name="android:layout_marginVertical">8dp</item>
106-
<item name="android:layout_gravity">center_vertical</item>
106+
<item name="android:gravity">center</item>
107+
<item name="android:paddingHorizontal">48dp</item>
107108
</style>
108-
<style name="dictionaryDownloadText">
109+
<style name="dictionary_download_locale">
109110
<item name="android:layout_weight">1</item>
110111
<item name="android:layout_width">fill_parent</item>
111112
<item name="android:layout_height">wrap_content</item>
112-
<item name="android:layout_marginHorizontal">48dp</item>
113+
<item name="android:textSize">16sp</item>
114+
</style>
115+
<style name="dictionary_download_size">
116+
<item name="android:layout_weight">0</item>
117+
<item name="android:layout_width">wrap_content</item>
118+
<item name="android:layout_height">wrap_content</item>
119+
<item name="android:layout_marginRight">8dp</item>
120+
<item name="android:textSize">12sp</item>
113121
</style>
114-
<style name="dictionaryDownloadButton">
122+
<style name="dictionary_download_button">
115123
<item name="android:layout_width">24dp</item>
116124
<item name="android:layout_height">24dp</item>
117-
<item name="android:layout_marginHorizontal">48dp</item>
125+
<item name="android:backgroundTint">@android:color/primary_text_dark</item>
126+
<item name="android:backgroundTintMode">src_in</item>
118127
</style>
119128
<style name="appTheme" parent="@android:style/Theme.DeviceDefault.DayNight"/>
120129
<style name="settingsTheme" parent="appTheme">

srcs/juloo.keyboard2/dict/DictionaryListView.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.net.MalformedURLException;
1111
import java.net.URL;
1212
import java.net.URLConnection;
13+
import java.text.NumberFormat;
1314
import java.util.ArrayList;
1415
import java.util.HashSet;
1516
import java.util.List;
@@ -120,8 +121,11 @@ public DictView(Context ctx, SupportedDictionaries d, DownloadBtnListener on_cli
120121
{
121122
view = View.inflate(ctx, R.layout.dictionary_download_item, null);
122123
desc = d;
124+
float size_mb = d.size / 1048576.f;
123125
((TextView)view.findViewById(R.id.dictionary_download_locale))
124126
.setText(ctx.getString(d.name_resource));
127+
((TextView)view.findViewById(R.id.dictionary_download_size))
128+
.setText(NumberFormat.getInstance().format(size_mb) + "MB");
125129
download_button = view.findViewById(R.id.dictionary_download_button);
126130
download_button.setOnClickListener(on_click);
127131
}

srcs/juloo.keyboard2/dict/SupportedDictionaries.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ public enum SupportedDictionaries
66
{
77
/** Enumeration of the supported dictionaries. */
88

9-
FR("fr", R.string.dict_name_fr);
9+
FR("fr", R.string.dict_name_fr, 1168721);
1010

1111
/** Associated information. */
1212

1313
public final String locale; /** Locale that matches this dictionary. */
1414
public final int name_resource; /** Display name. */
15+
public final int size; /** Size in bytes of the dictionary file. */
1516

16-
SupportedDictionaries(String l, int r)
17-
{ locale = l; name_resource = r; }
17+
SupportedDictionaries(String l, int r, int s)
18+
{ locale = l; name_resource = r; size = s; }
1819

1920
/** Name used in preferences, URLs and file names. */
2021
public String internal_name() { return locale; }

0 commit comments

Comments
 (0)