Skip to content

Commit 8109520

Browse files
committed
### 1.0.5 (4-May-2021)
- Updated implementation - Changed base functionality - Added Localazy library to get and set languages - Removed useless parts of the code - Set buttons to public, manipulation on them "enabled" - Updated card design
1 parent d7ba09d commit 8109520

File tree

14 files changed

+132
-46
lines changed

14 files changed

+132
-46
lines changed

.idea/jarRepositories.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LocalazyCard/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
defaultConfig {
99
minSdkVersion 22
1010
targetSdkVersion 30
11-
versionCode 4
12-
versionName "v1.0.4"
11+
versionCode 5
12+
versionName "v1.1"
1313

1414
consumerProguardFiles "consumer-rules.pro"
1515
}
@@ -27,6 +27,8 @@ android {
2727
}
2828

2929
dependencies {
30+
implementation "com.localazy.android:core:[1.1.0,)"
31+
implementation 'de.hdodenhof:circleimageview:3.1.0'
3032

3133
// Support libs
3234
implementation 'androidx.appcompat:appcompat:1.2.0'

LocalazyCard/src/main/java/com/paget96/localazycard/LocalazyCard.java

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.content.Intent;
66
import android.content.res.TypedArray;
77
import android.graphics.Canvas;
8+
import android.net.Uri;
89
import android.util.AttributeSet;
910
import android.util.Log;
1011
import android.view.LayoutInflater;
@@ -19,12 +20,16 @@
1920

2021
import com.google.android.material.button.MaterialButton;
2122
import com.google.android.material.card.MaterialCardView;
23+
import com.localazy.android.Localazy;
24+
import com.localazy.android.LocalazyLocale;
2225
import com.paget96.localazycard.utils.LocaleUtils;
2326
import com.paget96.localazycard.utils.UiUtils;
2427

2528
import java.util.AbstractMap;
29+
import java.util.Arrays;
2630
import java.util.HashMap;
2731
import java.util.List;
32+
import java.util.Locale;
2833
import java.util.Map;
2934

3035
public class LocalazyCard extends MaterialCardView {
@@ -35,20 +40,26 @@ public class LocalazyCard extends MaterialCardView {
3540
private View rootView;
3641
private TextView titleTextView, summaryTextView;
3742
private ImageView iconImageView;
38-
private MaterialButton inviteButton, translateButton;
43+
public MaterialButton inviteButton, translateButton;
3944
private TextView language;
4045
private ImageView arrowDown;
4146
private LinearLayout selectLanguageLayout;
4247
private MaterialCardView selectLanguage;
48+
private Uri localazyTranslationLink;
4349
private Activity activity;
44-
private Map<String, String> languages;
50+
private Map<String, String> languagesInternal;
51+
private Map<LocalazyLocale, String> languagesLocalazy;
4552

4653
public void setActivity(Activity activity) {
4754
this.activity = activity;
4855
}
4956

5057
public void setLanguages(String language, String languageCountry) {
51-
languages.put(language, languageCountry);
58+
languagesInternal.put(language, languageCountry);
59+
}
60+
61+
private void setLanguages(LocalazyLocale language, String localeName) {
62+
languagesLocalazy.put(language, localeName);
5263
}
5364

5465
public LocalazyCard(final Context context) {
@@ -61,7 +72,9 @@ public LocalazyCard(Context context, AttributeSet attrs) {
6172

6273
public LocalazyCard(Context context, AttributeSet attrs, int defStyleAttr) {
6374
super(context, attrs, defStyleAttr);
64-
languages = new HashMap<>();
75+
languagesInternal = new HashMap<>();
76+
languagesLocalazy = new HashMap<>();
77+
localazyTranslationLink = Localazy.getProjectUri();
6578

6679
initializeViews(context, attrs, defStyleAttr);
6780
}
@@ -89,9 +102,6 @@ private void initializeViews(Context context, AttributeSet attrs, int defStyleAt
89102
// Set summary
90103
setSummaryText(checkIsStringEmpty(attributes.getString(R.styleable.LocalazyCard_localazy_summary), context.getString(R.string.localazy_default_summary)));
91104

92-
// Open link on a button press
93-
setTranslateButton(checkIsStringEmpty(attributes.getString(R.styleable.LocalazyCard_localazy_app_translation_link), "https://localazy.com"));
94-
95105
attributes.recycle();
96106
}
97107

@@ -107,24 +117,40 @@ private void setLanguageInitialization() {
107117
language = rootView.findViewById(R.id.language);
108118
arrowDown = rootView.findViewById(R.id.expand_arrow);
109119

110-
language.setText(LocaleUtils.getLanguage(context));
120+
LocalazyLocale currentLocale = Localazy.getCurrentLocalazyLocale();
121+
language.setText(currentLocale.getLocalizedName());
122+
123+
List<LocalazyLocale> locales = Localazy.getLocales();
111124

112-
if (languages != null) {
113-
if (languages.size() > 1) {
125+
for (LocalazyLocale locale : locales) {
126+
// Returns display name for the locale in its own language - eq. "Čeština (Česko)" for "cs_CZ".
127+
String localizedName = locale.getLocalizedName();
128+
129+
setLanguages(locale, localizedName);
130+
}
131+
132+
if (languagesLocalazy != null) {
133+
if (languagesLocalazy.size() > 1) {
114134
rootView.setOnClickListener(v -> UiUtils.expandCollapseView(selectLanguageLayout, arrowDown));
115135

116136
selectLanguage.setOnClickListener(v -> {
117137
AlertDialog.Builder builder = new AlertDialog.Builder(context);
118138
builder.setTitle(context.getString(R.string.localazy_set_language_dialog_title));
119139

120-
String[] langArray, langCountryArray;
121-
langArray = languages.keySet().toArray(new String[0]);
122-
langCountryArray = languages.values().toArray(new String[0]);
123-
// for (Map.Entry<String, String> pair : languages.entrySet()) {
140+
LocalazyLocale[] langArray;
141+
String[] langNameArray;
142+
langArray = languagesLocalazy.keySet().toArray(new LocalazyLocale[0]);
143+
langNameArray = languagesLocalazy.values().toArray(new String[0]);
144+
145+
String[] languageName = new String[langArray.length];
146+
for (int i = 0; i < langArray.length; i++) {
147+
languageName[i] = langArray[i].getLocalizedName();
148+
}
149+
150+
builder.setItems(languageName, (dialog, which) -> {
151+
language.setText(langArray[which].getLocalizedName());
124152

125-
builder.setItems(langArray, (dialog, which) -> {
126-
language.setText(langArray[which]);
127-
LocaleUtils.setLocale(context, langArray[which], langCountryArray[which]);
153+
Localazy.forceLocale(langArray[which].getLocale(), true);
128154
activity.recreate();
129155
});
130156

@@ -175,18 +201,18 @@ public void setIcon(int icon) {
175201
iconImageView.setImageDrawable(ContextCompat.getDrawable(context, icon));
176202
}
177203

178-
public void setTranslateButton(String url) {
179-
translateButton.setOnClickListener(v -> UiUtils.openLink(context, url));
204+
public void setTranslateButton() {
205+
translateButton.setOnClickListener(v -> UiUtils.openLink(context, localazyTranslationLink.toString()));
180206
}
181207

182-
public void setInviteButton(Context context, String textMessage, String url) {
208+
public void setInviteButton(String textMessage) {
183209
inviteButton.setVisibility(VISIBLE);
184210
inviteButton.setOnClickListener(v -> {
185211
Intent sendIntent = new Intent();
186212
sendIntent.setAction(Intent.ACTION_SEND);
187-
sendIntent.putExtra(Intent.EXTRA_TEXT, textMessage + " " + url);
213+
sendIntent.putExtra(Intent.EXTRA_TEXT, textMessage + " " + localazyTranslationLink.toString());
188214
sendIntent.setType("text/plain");
189-
context.startActivity(sendIntent);
215+
activity.startActivity(sendIntent);
190216
});
191217
}
192218
}

LocalazyCard/src/main/res/drawable/ic_arrow_down.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
android:viewportWidth="24.0"
55
android:viewportHeight="24.0">
66
<path
7-
android:fillColor="#757575"
7+
android:fillColor="#FFFFFFFF"
88
android:pathData="M7.41,7.84L12,12.42l4.59,-4.58L18,9.25l-6,6 -6,-6z" />
99
</vector>

LocalazyCard/src/main/res/layout/localazy_card_style1.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
android:layout_width="match_parent"
99
android:layout_height="match_parent"
1010
android:orientation="vertical"
11+
android:background="#FF0558BD"
1112
android:padding="8dp">
1213

1314
<LinearLayout
@@ -16,7 +17,7 @@
1617
android:gravity="center_vertical"
1718
android:orientation="horizontal">
1819

19-
<ImageView
20+
<de.hdodenhof.circleimageview.CircleImageView
2021
android:id="@+id/icon"
2122
android:layout_width="72dp"
2223
android:layout_height="72dp"
@@ -29,6 +30,7 @@
2930
android:layout_height="wrap_content"
3031
android:padding="12dp"
3132
android:text="@string/localazy_default_title"
33+
android:textColor="@color/cardview_light_background"
3234
android:textSize="24sp"
3335
android:textStyle="bold" />
3436
</LinearLayout>
@@ -38,7 +40,8 @@
3840
android:layout_width="match_parent"
3941
android:layout_height="wrap_content"
4042
android:padding="12dp"
41-
android:text="@string/localazy_default_summary" />
43+
android:text="@string/localazy_default_summary"
44+
android:textColor="@color/cardview_light_background" />
4245

4346
<LinearLayout
4447
android:layout_width="match_parent"
@@ -83,6 +86,7 @@
8386
android:layout_height="wrap_content"
8487
android:layout_marginStart="8dp"
8588
android:gravity="center_vertical"
89+
android:textColor="@color/cardview_light_background"
8690
android:text="@string/localazy_select_app_language" />
8791

8892
<com.google.android.material.card.MaterialCardView
@@ -112,7 +116,7 @@
112116
android:layout_marginStart="8dp"
113117
android:layout_weight="1"
114118
android:gravity="center_vertical"
115-
android:text="en" />
119+
android:text="English" />
116120

117121
<ImageView
118122
android:layout_width="wrap_content"
@@ -131,6 +135,7 @@
131135
android:layout_height="wrap_content"
132136
android:layout_gravity="end"
133137
android:text="@string/localazy_powered_by_localazy"
138+
android:textColor="@color/cardview_light_background"
134139
android:textSize="10sp"
135140
android:textStyle="italic" />
136141
</LinearLayout>

LocalazyCard/src/main/res/values/attrs.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<attr name="localazy_title" format="string"/>
77
<attr name="localazy_summary" format="string"/>
88
<attr name="localazy_invitation_message" format="string"/>
9-
<attr name="localazy_app_translation_link" format="string"/>
109

1110
</declare-styleable>
1211
</resources>

README.md

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,32 @@ aside that library support app language changing directly from it
1212

1313
<img src="resources/screenshot_1.png" width="30%"/>
1414

15+
In order to use this library, you need to setup Localazy Gradle Plugin. Guide can be found on official website
16+
<a href="https://localazy.com/docs/android/localazy-gradle-plugin</a>
17+
18+
**IMPORTANT THING**
19+
Do not apply this configuration to the Localazy Gradle Plugin, because injection and download is important to retrieve your Language pack
20+
```
21+
localazy {
22+
injection {
23+
enabledForRelease false
24+
enabledForDebug false
25+
library "none"
26+
}
27+
28+
download {
29+
enabledForRelease false
30+
enabledForDebug false
31+
}
32+
}
33+
```
34+
35+
Since Localazy Card rely on Localazys OTA app needs INTERNET permission in order to work, add this code snippet to your Android Manifest, if you already done Localazy Gradle Plugin setup from the link above, you have done this step.
36+
37+
```
38+
<uses-permission android:name="android.permission.INTERNET" />
39+
```
40+
1541
Add it in your root build.gradle at the end of repositories:
1642

1743
```
@@ -26,7 +52,7 @@ allprojects {
2652
Include the library as a local library project or add the dependency in your build.gradle.
2753
```
2854
dependencies {
29-
implementation 'com.github.Paget96:Localazy-Card:1.0.4'
55+
implementation 'com.github.Paget96:Localazy-Card:1.1'
3056
}
3157
```
3258

@@ -41,7 +67,6 @@ Include the view defined as below in your layout. And you can customize it like
4167
android:layout_width="match_parent"
4268
android:layout_height="wrap_content"
4369
android:layout_margin="16dp"
44-
app:localazy_app_translation_link="https://localazy.com"
4570
app:localazy_icon="@drawable/ic_localazy"
4671
app:localazy_invitation_message="@string/localazy_default_invitation_text"
4772
app:localazy_summary="@string/localazy_default_summary"
@@ -60,13 +85,8 @@ protected void attachBaseContext(Context base) {
6085
```
6186
LocalazyCard localazyCard = findViewById(R.id.localazyCard);
6287
63-
// Optional - define what languages your app have
64-
// this will be used for language changer
6588
// IMPORTANT, define activity for language changing
6689
localazyCard.setActivity(this);
67-
localazyCard.setLanguages("en", "");
68-
localazyCard.setLanguages("de", "");
69-
localazyCard.setLanguages("fr", "");
7090
7191
// Set card icon
7292
localazyCard.setIcon(R.drawable.ic_localazy);
@@ -82,10 +102,14 @@ localazyCard.setSummaryTextSize(14f);
82102
localazyCard.setSummaryTextStyle(Typeface.NORMAL);
83103
84104
// Open translation link
85-
localazyCard.setTranslateButton("https://localazy.com");
105+
localazyCard.setTranslateButton();
106+
localazyCard.translateButton.setTextColor(ContextCompat.getColor(this, R.color.white));
107+
localazyCard.translateButton.setStrokeColor(ColorStateList.valueOf(ContextCompat.getColor(this, R.color.white)));
86108
87109
// Invite to translate
88-
localazyCard.setInviteButton(this, getString(R.string.invitation_text, getString(R.string.app_name)) , "https://localazy.com");
110+
localazyCard.setInviteButton(getString(R.string.invitation_text, getString(R.string.app_name)));
111+
localazyCard.inviteButton.setTextColor(ContextCompat.getColor(this, R.color.white));
112+
localazyCard.inviteButton.setStrokeColor(ColorStateList.valueOf(ContextCompat.getColor(this, R.color.white)));
89113
```
90114

91115
### Step 3 (Strings)
@@ -112,7 +136,17 @@ localazyCard.setElevation(0f); // Set card elevation
112136
// And much more
113137
```
114138

139+
140+
115141
# Changelog
142+
### 1.0.5 (4-May-2021)
143+
- Updated implementation
144+
- Changed base functionality
145+
- Added Localazy library to get and set languages
146+
- Removed useless parts of the code
147+
- Set buttons to public, manipulation on them "enabled"
148+
- Updated card design
149+
116150
### 1.0.4 (20-Mar-2021)
117151
- Added feature to change app language directly from the app
118152
- Updated library code

app/build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
id 'com.android.application'
3+
id 'com.localazy.gradle'
34
}
45

56
android {
@@ -31,6 +32,15 @@ android {
3132
}
3233
}
3334

35+
localazy {
36+
readKey "put your read key"
37+
writeKey "put your write key"
38+
39+
upload {
40+
showUploadAll true
41+
}
42+
}
43+
3444
dependencies {
3545
implementation project(":LocalazyCard")
3646

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.paget96.localazy_card">
44

5+
<uses-permission android:name="android.permission.INTERNET" />
6+
57
<application
68
android:allowBackup="true"
79
android:icon="@mipmap/ic_launcher"

0 commit comments

Comments
 (0)