diff --git a/.gitignore b/.gitignore index aa724b7..5bd175f 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ .externalNativeBuild .cxx local.properties +.idea diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 10c50fe..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -Localazy-Card \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index fb7f4a8..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index cf73b8d..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml deleted file mode 100644 index 958a5be..0000000 --- a/.idea/jarRepositories.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 6199cc2..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 797acea..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/LocalazyCard/build.gradle b/LocalazyCard/build.gradle index e6af98c..e592d0a 100644 --- a/LocalazyCard/build.gradle +++ b/LocalazyCard/build.gradle @@ -1,6 +1,7 @@ plugins { id 'com.android.library' } +apply plugin: 'kotlin-android' android { compileSdkVersion 30 @@ -8,8 +9,8 @@ android { defaultConfig { minSdkVersion 22 targetSdkVersion 30 - versionCode 4 - versionName "v1.0.4" + versionCode 6 + versionName "v1.2" consumerProguardFiles "consumer-rules.pro" } @@ -27,8 +28,16 @@ android { } dependencies { + implementation "com.localazy.android:core:[1.1.0,)" + implementation 'de.hdodenhof:circleimageview:3.1.0' + implementation "androidx.preference:preference-ktx:1.1.1" // Support libs implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.3.0' + implementation "androidx.core:core-ktx:+" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" +} +repositories { + mavenCentral() } \ No newline at end of file diff --git a/LocalazyCard/src/main/java/com/paget96/localazycard/LocalazyCard.java b/LocalazyCard/src/main/java/com/paget96/localazycard/LocalazyCard.java deleted file mode 100644 index 2aceeea..0000000 --- a/LocalazyCard/src/main/java/com/paget96/localazycard/LocalazyCard.java +++ /dev/null @@ -1,192 +0,0 @@ -package com.paget96.localazycard; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.content.res.TypedArray; -import android.graphics.Canvas; -import android.util.AttributeSet; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.appcompat.app.AlertDialog; -import androidx.core.content.ContextCompat; - -import com.google.android.material.button.MaterialButton; -import com.google.android.material.card.MaterialCardView; -import com.paget96.localazycard.utils.LocaleUtils; -import com.paget96.localazycard.utils.UiUtils; - -import java.util.AbstractMap; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class LocalazyCard extends MaterialCardView { - - // Variables - private Context context; - private LayoutInflater inflater; - private View rootView; - private TextView titleTextView, summaryTextView; - private ImageView iconImageView; - private MaterialButton inviteButton, translateButton; - private TextView language; - private ImageView arrowDown; - private LinearLayout selectLanguageLayout; - private MaterialCardView selectLanguage; - private Activity activity; - private Map languages; - - public void setActivity(Activity activity) { - this.activity = activity; - } - - public void setLanguages(String language, String languageCountry) { - languages.put(language, languageCountry); - } - - public LocalazyCard(final Context context) { - this(context, null); - } - - public LocalazyCard(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - public LocalazyCard(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - languages = new HashMap<>(); - - initializeViews(context, attrs, defStyleAttr); - } - - private void initializeViews(Context context, AttributeSet attrs, int defStyleAttr) { - - // Load the styled attributes and set their properties - TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.LocalazyCard, defStyleAttr, 0); - this.context = context; - - inflater = LayoutInflater.from(context); - rootView = inflater.inflate(R.layout.localazy_card_style1, this); - - titleTextView = rootView.findViewById(R.id.title_text); - summaryTextView = rootView.findViewById(R.id.summary_text); - iconImageView = rootView.findViewById(R.id.icon); - inviteButton = rootView.findViewById(R.id.invite); - translateButton = rootView.findViewById(R.id.translate); - - setIcon(attributes.getResourceId(R.styleable.LocalazyCard_localazy_icon, R.drawable.ic_localazy)); - - // Set title - setTitle(checkIsStringEmpty(attributes.getString(R.styleable.LocalazyCard_localazy_title), context.getString(R.string.localazy_default_title))); - - // Set summary - setSummaryText(checkIsStringEmpty(attributes.getString(R.styleable.LocalazyCard_localazy_summary), context.getString(R.string.localazy_default_summary))); - - // Open link on a button press - setTranslateButton(checkIsStringEmpty(attributes.getString(R.styleable.LocalazyCard_localazy_app_translation_link), "https://localazy.com")); - - attributes.recycle(); - } - - @Override - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - setLanguageInitialization(); - } - - private void setLanguageInitialization() { - selectLanguageLayout = rootView.findViewById(R.id.select_language_layout); - selectLanguage = rootView.findViewById(R.id.select_language); - language = rootView.findViewById(R.id.language); - arrowDown = rootView.findViewById(R.id.expand_arrow); - - language.setText(LocaleUtils.getLanguage(context)); - - if (languages != null) { - if (languages.size() > 1) { - rootView.setOnClickListener(v -> UiUtils.expandCollapseView(selectLanguageLayout, arrowDown)); - - selectLanguage.setOnClickListener(v -> { - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(context.getString(R.string.localazy_set_language_dialog_title)); - - String[] langArray, langCountryArray; - langArray = languages.keySet().toArray(new String[0]); - langCountryArray = languages.values().toArray(new String[0]); - // for (Map.Entry pair : languages.entrySet()) { - - builder.setItems(langArray, (dialog, which) -> { - language.setText(langArray[which]); - LocaleUtils.setLocale(context, langArray[which], langCountryArray[which]); - activity.recreate(); - }); - - AlertDialog dialog = builder.create(); - dialog.show(); - }); - } else - arrowDown.setVisibility(GONE); - - } else - arrowDown.setVisibility(GONE); - - } - - private String checkIsStringEmpty(String string, String defaultString) { - if (string == null) - return defaultString; - else if (string.isEmpty()) - return defaultString; - else return string; - } - - public void setTitle(String title) { - titleTextView.setText(title); - } - - public void setTitleTextSize(float textSize) { - titleTextView.setTextSize(textSize); - } - - public void setTitleTextStyle(int typeface) { - titleTextView.setTypeface(titleTextView.getTypeface(), typeface); - } - - public void setSummaryText(String summaryText) { - summaryTextView.setText(summaryText); - } - - public void setSummaryTextStyle(int typeface) { - summaryTextView.setTypeface(summaryTextView.getTypeface(), typeface); - } - - public void setSummaryTextSize(float textSize) { - summaryTextView.setTextSize(textSize); - } - - public void setIcon(int icon) { - iconImageView.setImageDrawable(ContextCompat.getDrawable(context, icon)); - } - - public void setTranslateButton(String url) { - translateButton.setOnClickListener(v -> UiUtils.openLink(context, url)); - } - - public void setInviteButton(Context context, String textMessage, String url) { - inviteButton.setVisibility(VISIBLE); - inviteButton.setOnClickListener(v -> { - Intent sendIntent = new Intent(); - sendIntent.setAction(Intent.ACTION_SEND); - sendIntent.putExtra(Intent.EXTRA_TEXT, textMessage + " " + url); - sendIntent.setType("text/plain"); - context.startActivity(sendIntent); - }); - } -} diff --git a/LocalazyCard/src/main/java/com/paget96/localazycard/LocalazyCard.kt b/LocalazyCard/src/main/java/com/paget96/localazycard/LocalazyCard.kt new file mode 100644 index 0000000..dcde318 --- /dev/null +++ b/LocalazyCard/src/main/java/com/paget96/localazycard/LocalazyCard.kt @@ -0,0 +1,188 @@ +package com.paget96.localazycard + +import android.app.Activity +import android.content.Context +import android.content.DialogInterface +import android.content.Intent +import android.content.SharedPreferences +import android.content.res.ColorStateList +import android.graphics.Canvas +import android.net.Uri +import android.util.AttributeSet +import android.view.LayoutInflater +import android.view.View +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.appcompat.app.AlertDialog +import androidx.core.content.ContextCompat +import androidx.preference.PreferenceManager +import com.google.android.material.card.MaterialCardView +import com.localazy.android.Localazy +import com.localazy.android.LocalazyLocale +import com.paget96.localazycard.utils.UiUtils.openLink +import java.util.* + +class LocalazyCard @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : MaterialCardView(context, attrs, defStyleAttr) { + // Variables + private val preferences: SharedPreferences + private var titleTextView: TextView? = null + private var summaryTextView: TextView? = null + private var iconImageView: ImageView? = null + private var languageDownArrow: ImageView? = null + var selectLanguage: LinearLayout? = null + var inviteButton: LinearLayout? = null + var translateButton: LinearLayout? = null + private var language: TextView? = null + private val localazyTranslationLink: Uri + private var activity: Activity? = null + private val languagesInternal: MutableMap + private val languagesLocalazy: MutableMap? + + fun setActivity(activity: Activity?) { + this.activity = activity + } + + fun setLanguages(language: String, languageCountry: String) { + languagesInternal[language] = languageCountry + } + + private fun setLanguages(language: LocalazyLocale, localeName: String) { + languagesLocalazy!![language] = localeName + } + + private fun initializeViews(context: Context, attrs: AttributeSet?, defStyleAttr: Int) { + + // Load the styled attributes and set their properties + val attributes = context.obtainStyledAttributes(attrs, R.styleable.LocalazyCard, defStyleAttr, 0) + + val cardRootView: View? = LayoutInflater.from(context).inflate(R.layout.localazy_card_style1, this) + + titleTextView = cardRootView?.findViewById(R.id.title_text) + summaryTextView = cardRootView?.findViewById(R.id.summary_text) + iconImageView = cardRootView?.findViewById(R.id.icon) + selectLanguage = cardRootView?.findViewById(R.id.select_language) + language = cardRootView?.findViewById(R.id.language) + languageDownArrow = cardRootView?.findViewById(R.id.language_down_arrow) + inviteButton = cardRootView?.findViewById(R.id.invite) + translateButton = cardRootView?.findViewById(R.id.translate) + + if (!preferences.getBoolean("language_selected", false)) { + selectLanguage?.setBackgroundColor(ContextCompat.getColor(context, R.color.design_default_color_background)) + language?.setText(context.getText(R.string.localazy_select_app_language)) + language?.setTextColor(ContextCompat.getColor(context, R.color.no_language_selected_text_color)) + languageDownArrow?.setImageTintList(ColorStateList.valueOf(ContextCompat.getColor(context, R.color.no_language_selected_text_color))) + + } else { + val currentLocale = Localazy.getCurrentLocalazyLocale() + language?.setText(currentLocale.getLocalizedName()) + } + + setIcon(attributes.getResourceId(R.styleable.LocalazyCard_localazy_icon, R.drawable.ic_localazy)) + + // Set title + setTitle(checkIsStringEmpty(attributes.getString(R.styleable.LocalazyCard_localazy_title), context.getString(R.string.localazy_default_title))) + + // Set summary + setSummaryText(checkIsStringEmpty(attributes.getString(R.styleable.LocalazyCard_localazy_summary), context.getString(R.string.localazy_default_summary))) + attributes.recycle() + } + + override fun onDraw(canvas: Canvas) { + super.onDraw(canvas) + setLanguageInitialization() + } + + private fun setLanguageInitialization() { + val locales = Localazy.getLocales() + + for (locale in locales) { + // Returns display name for the locale in its own language - eq. "Čeština (Česko)" for "cs_CZ". + val localizedName = locale.getLocalizedName() + setLanguages(locale, localizedName) + } + + if (languagesLocalazy != null) { + if (languagesLocalazy.size > 1) { + selectLanguage!!.setOnClickListener { + + val builder = AlertDialog.Builder(context!!) + builder.setTitle(context!!.getString(R.string.localazy_set_language_dialog_title)) + val langArray: Array + val langNameArray: Array + langArray = languagesLocalazy.keys.toTypedArray() + langNameArray = languagesLocalazy.values.toTypedArray() + + val languageName = arrayOfNulls(langArray.size) + for (i in langArray.indices) { + languageName[i] = langArray[i].getLocalizedName() + } + + builder.setItems(languageName) { dialog: DialogInterface?, which: Int -> + preferences.edit().putBoolean("language_selected", true).apply() + Localazy.forceLocale(langArray[which].locale, true) + activity!!.recreate() + } + + val dialog = builder.create() + dialog.show() + } + } + } + } + + private fun checkIsStringEmpty(string: String?, defaultString: String): String { + return if (string == null) defaultString else if (string.isEmpty()) defaultString else string + } + + fun setTitle(title: String?) { + titleTextView!!.text = title + } + + fun setTitleTextSize(textSize: Float) { + titleTextView!!.textSize = textSize + } + + fun setTitleTextStyle(typeface: Int) { + titleTextView!!.setTypeface(titleTextView!!.typeface, typeface) + } + + fun setSummaryText(summaryText: String?) { + summaryTextView!!.text = summaryText + } + + fun setSummaryTextStyle(typeface: Int) { + summaryTextView!!.setTypeface(summaryTextView!!.typeface, typeface) + } + + fun setSummaryTextSize(textSize: Float) { + summaryTextView!!.textSize = textSize + } + + fun setIcon(icon: Int) { + iconImageView!!.setImageDrawable(ContextCompat.getDrawable(context!!, icon)) + } + + fun setTranslateButton() { + translateButton!!.setOnClickListener { v: View? -> openLink(context!!, localazyTranslationLink.toString()) } + } + + fun setInviteButton(textMessage: String) { + inviteButton!!.visibility = VISIBLE + inviteButton!!.setOnClickListener { v: View? -> + val sendIntent = Intent() + sendIntent.action = Intent.ACTION_SEND + sendIntent.putExtra(Intent.EXTRA_TEXT, "$textMessage $localazyTranslationLink") + sendIntent.type = "text/plain" + activity!!.startActivity(sendIntent) + } + } + + init { + languagesInternal = HashMap() + languagesLocalazy = HashMap() + localazyTranslationLink = Localazy.getProjectUri() + preferences = PreferenceManager.getDefaultSharedPreferences(context) + initializeViews(context, attrs, defStyleAttr) + } +} \ No newline at end of file diff --git a/LocalazyCard/src/main/java/com/paget96/localazycard/utils/LocaleUtils.java b/LocalazyCard/src/main/java/com/paget96/localazycard/utils/LocaleUtils.java deleted file mode 100644 index 0c5a664..0000000 --- a/LocalazyCard/src/main/java/com/paget96/localazycard/utils/LocaleUtils.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.paget96.localazycard.utils; - -import android.annotation.TargetApi; -import android.content.Context; -import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.content.res.Resources; -import android.os.Build; -import android.preference.PreferenceManager; -import android.util.Log; - -import java.util.Locale; - -public class LocaleUtils { - - private static final String TAG = "localazy_locale"; - private static final String SELECTED_LANGUAGE = "en"; - private static final String SELECTED_LANGUAGE_COUNTRY = "US"; - - - public static Context onAttach(Context context) { - Log.d(TAG, "onAttach:"); - String lang = getPersistedData(context, Locale.getDefault().getLanguage()); - String langCountry = getPersistedCountryData(context, Locale.getDefault().getCountry()); - return setLocale(context, lang, langCountry); - } - - public static String getLanguage(Context context) { - return getPersistedData(context, Locale.getDefault().getLanguage()); - } - - public static String getLanguageCountry(Context context) { - return getPersistedCountryData(context, Locale.getDefault().getCountry()); - } - - public static Context setLocale(Context context, String language, String langCountry) { - Log.d(TAG, "setLocale: "); - persist(context, language, langCountry); - - return updateResources(context, language, langCountry); - - - } - - private static String getPersistedData(Context context, String defaultLanguage) { - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); - return preferences.getString(SELECTED_LANGUAGE, defaultLanguage); - } - - private static String getPersistedCountryData(Context context, String defaultLangCountry) { - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); - return preferences.getString(SELECTED_LANGUAGE_COUNTRY, defaultLangCountry); - } - - private static void persist(Context context, String language, String langCountry) { - Log.d(TAG, "persist: "); - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); - SharedPreferences.Editor editor = preferences.edit(); - - editor.putString(SELECTED_LANGUAGE, language); - editor.putString(SELECTED_LANGUAGE_COUNTRY, langCountry); - editor.apply(); - } - - - @TargetApi(Build.VERSION_CODES.N) - private static Context updateResources(Context context, String language, String langCountry) { - Log.d(TAG, "updateResources: "); - Locale locale = new Locale(language, langCountry); - Locale.setDefault(locale); - - Configuration configuration = context.getResources().getConfiguration(); - configuration.setLocale(locale); - configuration.setLayoutDirection(locale); - - return context.createConfigurationContext(configuration); - } -} diff --git a/LocalazyCard/src/main/java/com/paget96/localazycard/utils/LocaleUtils.kt b/LocalazyCard/src/main/java/com/paget96/localazycard/utils/LocaleUtils.kt new file mode 100644 index 0000000..5fbdd65 --- /dev/null +++ b/LocalazyCard/src/main/java/com/paget96/localazycard/utils/LocaleUtils.kt @@ -0,0 +1,65 @@ +package com.paget96.localazycard.utils + +import android.annotation.TargetApi +import android.content.Context +import android.os.Build +import android.util.Log +import androidx.preference.PreferenceManager +import java.util.* + +object LocaleUtils { + private const val TAG = "localazy_locale" + private const val SELECTED_LANGUAGE = "en" + private const val SELECTED_LANGUAGE_COUNTRY = "US" + @JvmStatic + fun onAttach(context: Context): Context { + Log.d(TAG, "onAttach:") + val lang = getPersistedData(context, Locale.getDefault().language) + val langCountry = getPersistedCountryData(context, Locale.getDefault().country) + return setLocale(context, lang, langCountry) + } + + fun getLanguage(context: Context): String? { + return getPersistedData(context, Locale.getDefault().language) + } + + fun getLanguageCountry(context: Context): String? { + return getPersistedCountryData(context, Locale.getDefault().country) + } + + fun setLocale(context: Context, language: String?, langCountry: String?): Context { + Log.d(TAG, "setLocale: ") + persist(context, language, langCountry) + return updateResources(context, language, langCountry) + } + + private fun getPersistedData(context: Context, defaultLanguage: String): String? { + val preferences = PreferenceManager.getDefaultSharedPreferences(context) + return preferences.getString(SELECTED_LANGUAGE, defaultLanguage) + } + + private fun getPersistedCountryData(context: Context, defaultLangCountry: String): String? { + val preferences = PreferenceManager.getDefaultSharedPreferences(context) + return preferences.getString(SELECTED_LANGUAGE_COUNTRY, defaultLangCountry) + } + + private fun persist(context: Context, language: String?, langCountry: String?) { + Log.d(TAG, "persist: ") + val preferences = PreferenceManager.getDefaultSharedPreferences(context) + val editor = preferences.edit() + editor.putString(SELECTED_LANGUAGE, language) + editor.putString(SELECTED_LANGUAGE_COUNTRY, langCountry) + editor.apply() + } + + @TargetApi(Build.VERSION_CODES.N) + private fun updateResources(context: Context, language: String?, langCountry: String?): Context { + Log.d(TAG, "updateResources: ") + val locale = Locale(language, langCountry) + Locale.setDefault(locale) + val configuration = context.resources.configuration + configuration.setLocale(locale) + configuration.setLayoutDirection(locale) + return context.createConfigurationContext(configuration) + } +} \ No newline at end of file diff --git a/LocalazyCard/src/main/java/com/paget96/localazycard/utils/UiUtils.java b/LocalazyCard/src/main/java/com/paget96/localazycard/utils/UiUtils.java deleted file mode 100644 index 87411a7..0000000 --- a/LocalazyCard/src/main/java/com/paget96/localazycard/utils/UiUtils.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.paget96.localazycard.utils; - -import android.content.ActivityNotFoundException; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.util.AndroidRuntimeException; -import android.view.View; - -public class UiUtils { - - // Parses and open links. - public static void openLink(Context context, String link) { - Uri uri = Uri.parse(link); - Intent intent = new Intent(Intent.ACTION_VIEW, uri); - try { - context.startActivity(intent); - } catch (ActivityNotFoundException e) { - e.printStackTrace(); - } - } - - public static void expandView(View expandedLayout, View animateArrow) { - try { - animateArrow.animate().rotation(180).setDuration(500).start(); - } catch (AndroidRuntimeException are) { - are.printStackTrace(); - } - expandedLayout.setVisibility(View.VISIBLE); - } - - public static void collapseView(View expandedLayout, View animateArrow) { - try { - animateArrow.animate().rotation(0).setDuration(500).start(); - } catch (AndroidRuntimeException are) { - are.printStackTrace(); - } - expandedLayout.setVisibility(View.GONE); - } - - public static void expandCollapseView(View expandedLayout, View animateArrow) { - if (expandedLayout.isShown()) { - collapseView(expandedLayout, animateArrow); - } else { - expandView(expandedLayout, animateArrow); - } - } - -} diff --git a/LocalazyCard/src/main/java/com/paget96/localazycard/utils/UiUtils.kt b/LocalazyCard/src/main/java/com/paget96/localazycard/utils/UiUtils.kt new file mode 100644 index 0000000..6bc7e92 --- /dev/null +++ b/LocalazyCard/src/main/java/com/paget96/localazycard/utils/UiUtils.kt @@ -0,0 +1,20 @@ +package com.paget96.localazycard.utils + +import android.content.ActivityNotFoundException +import android.content.Context +import android.content.Intent +import android.net.Uri + +object UiUtils { + // Parses and open links. + @JvmStatic + fun openLink(context: Context, link: String?) { + val uri = Uri.parse(link) + val intent = Intent(Intent.ACTION_VIEW, uri) + try { + context.startActivity(intent) + } catch (e: ActivityNotFoundException) { + e.printStackTrace() + } + } +} \ No newline at end of file diff --git a/LocalazyCard/src/main/res/drawable/ic_arrow_down.xml b/LocalazyCard/src/main/res/drawable/ic_arrow_down.xml index 101d078..f89e1c9 100644 --- a/LocalazyCard/src/main/res/drawable/ic_arrow_down.xml +++ b/LocalazyCard/src/main/res/drawable/ic_arrow_down.xml @@ -4,6 +4,6 @@ android:viewportWidth="24.0" android:viewportHeight="24.0"> diff --git a/LocalazyCard/src/main/res/drawable/ic_invite.xml b/LocalazyCard/src/main/res/drawable/ic_invite.xml new file mode 100644 index 0000000..622411f --- /dev/null +++ b/LocalazyCard/src/main/res/drawable/ic_invite.xml @@ -0,0 +1,9 @@ + + + diff --git a/LocalazyCard/src/main/res/drawable/ic_localazy_no_bgd.xml b/LocalazyCard/src/main/res/drawable/ic_localazy_no_bgd.xml new file mode 100644 index 0000000..a9389e2 --- /dev/null +++ b/LocalazyCard/src/main/res/drawable/ic_localazy_no_bgd.xml @@ -0,0 +1,12 @@ + + + + diff --git a/LocalazyCard/src/main/res/drawable/ic_translate.xml b/LocalazyCard/src/main/res/drawable/ic_translate.xml new file mode 100644 index 0000000..85403ea --- /dev/null +++ b/LocalazyCard/src/main/res/drawable/ic_translate.xml @@ -0,0 +1,9 @@ + + + diff --git a/LocalazyCard/src/main/res/layout/localazy_card_style1.xml b/LocalazyCard/src/main/res/layout/localazy_card_style1.xml index 6ab7940..788f3e4 100644 --- a/LocalazyCard/src/main/res/layout/localazy_card_style1.xml +++ b/LocalazyCard/src/main/res/layout/localazy_card_style1.xml @@ -1,138 +1,147 @@ + android:layout_height="wrap_content"> + android:background="#066FEF" + android:orientation="vertical"> + android:orientation="vertical" + android:padding="32dp"> + + + + + + + + + - + + + android:layout_marginTop="16dp" + android:text="@string/localazy_default_summary" + android:textColor="@color/cardview_light_background" /> - + - - - + - + + + - + - + - - - - + android:orientation="horizontal"> + android:layout_height="48dp" + android:layout_weight="1" + android:background="?attr/selectableItemBackground" + android:gravity="center"> + + - + - - - + - + + + - - - \ No newline at end of file diff --git a/LocalazyCard/src/main/res/values/attrs.xml b/LocalazyCard/src/main/res/values/attrs.xml index d88d153..070c027 100644 --- a/LocalazyCard/src/main/res/values/attrs.xml +++ b/LocalazyCard/src/main/res/values/attrs.xml @@ -6,7 +6,6 @@ - \ No newline at end of file diff --git a/LocalazyCard/src/main/res/values/colors.xml b/LocalazyCard/src/main/res/values/colors.xml new file mode 100644 index 0000000..c6be26a --- /dev/null +++ b/LocalazyCard/src/main/res/values/colors.xml @@ -0,0 +1,7 @@ + + + + #64707B + + + \ No newline at end of file diff --git a/LocalazyCard/src/main/res/values/strings.xml b/LocalazyCard/src/main/res/values/strings.xml index a8ea027..c5fc4bd 100644 --- a/LocalazyCard/src/main/res/values/strings.xml +++ b/LocalazyCard/src/main/res/values/strings.xml @@ -2,13 +2,13 @@ Translate + With Localazy Help us make this app multilingual, translate to 50+ languages I\'m inviting to help me translating this app using Localazy Translate Invite - Powered by Localazy Set language - Select app language: + Select app language \ No newline at end of file diff --git a/LocalazyCard/src/main/res/values/styles.xml b/LocalazyCard/src/main/res/values/styles.xml new file mode 100644 index 0000000..d260284 --- /dev/null +++ b/LocalazyCard/src/main/res/values/styles.xml @@ -0,0 +1,16 @@ + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 6fdd336..c76aa08 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,33 @@ This is a small library to help the developers who already using Localazy to localize their apps, aside that library support app language changing directly from it - + + +In order to use this library, you need to setup Localazy Gradle Plugin. Guide can be found on official website +Localazy Gradle Plugin + +**IMPORTANT THING** +Do not apply this configuration to the Localazy Gradle Plugin, because injection and download is important to retrieve your Language pack +``` +localazy { + injection { + enabledForRelease false + enabledForDebug false + library "none" + } + + download { + enabledForRelease false + enabledForDebug false + } + } +``` + +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. + +``` + +``` Add it in your root build.gradle at the end of repositories: @@ -26,7 +52,7 @@ allprojects { Include the library as a local library project or add the dependency in your build.gradle. ``` dependencies { - implementation 'com.github.Paget96:Localazy-Card:1.0.4' + implementation 'com.github.Paget96:Localazy-Card:1.2' } ``` @@ -41,7 +67,6 @@ Include the view defined as below in your layout. And you can customize it like android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="16dp" - app:localazy_app_translation_link="https://localazy.com" app:localazy_icon="@drawable/ic_localazy" app:localazy_invitation_message="@string/localazy_default_invitation_text" app:localazy_summary="@string/localazy_default_summary" @@ -51,41 +76,39 @@ Include the view defined as below in your layout. And you can customize it like ### Step 2 ##### (Optional) Add this to your activity if you want language changer feature ``` -@Override -protected void attachBaseContext(Context base) { - super.attachBaseContext(LocaleUtils.onAttach(base)); +override fun attachBaseContext(base: Context) { + super.attachBaseContext(onAttach(base)) } ``` #### Add this to the class which own the xml you set in Step 1 ``` -LocalazyCard localazyCard = findViewById(R.id.localazyCard); +val localazyCard = findViewById(R.id.localazyCard) -// Optional - define what languages your app have -// this will be used for language changer // IMPORTANT, define activity for language changing -localazyCard.setActivity(this); -localazyCard.setLanguages("en", ""); -localazyCard.setLanguages("de", ""); -localazyCard.setLanguages("fr", ""); +localazyCard.setActivity(this) // Set card icon -localazyCard.setIcon(R.drawable.ic_localazy); +localazyCard.setIcon(R.drawable.ic_localazy_no_bgd) // Title text -localazyCard.setTitle(getString(R.string.translate) + " " + getString(R.string.app_name)); -localazyCard.setTitleTextSize(18f); -localazyCard.setTitleTextStyle(Typeface.BOLD); +localazyCard.setTitle(getString(R.string.translate) + " " + getString(R.string.app_name)) +localazyCard.setTitleTextSize(18f) +localazyCard.setTitleTextStyle(Typeface.BOLD) // Summary text -localazyCard.setSummaryText(getString(R.string.summary_text, getString(R.string.app_name))); -localazyCard.setSummaryTextSize(14f); -localazyCard.setSummaryTextStyle(Typeface.NORMAL); +localazyCard.setSummaryText(getString(R.string.summary_text, getString(R.string.app_name))) +localazyCard.setSummaryTextSize(14f) +localazyCard.setSummaryTextStyle(Typeface.NORMAL) // Open translation link -localazyCard.setTranslateButton("https://localazy.com"); +localazyCard.setTranslateButton() // Invite to translate -localazyCard.setInviteButton(this, getString(R.string.invitation_text, getString(R.string.app_name)) , "https://localazy.com"); +localazyCard.setInviteButton(getString(R.string.invitation_text, getString(R.string.app_name))) +localazyCard.radius = 24f +localazyCard.strokeColor = ContextCompat.getColor(this, R.color.design_default_color_primary) +localazyCard.strokeWidth = 2 +localazyCard.elevation = 0f ``` ### Step 3 (Strings) @@ -105,14 +128,29 @@ Add this to your strings file (those are default strings if you use configuratio ### Step 4 (style) Since this library is basically an extended view of a MaterialCardView, you can use pretty much the same features as the default material card have ``` -localazyCard.setRadius(24); // Set card corner radius -localazyCard.setStrokeColor(ContextCompat.getColor(this, R.color.design_default_color_primary)); // Set stroke color -localazyCard.setStrokeWidth(2); // Set stroke width -localazyCard.setElevation(0f); // Set card elevation +localazyCard.radius = 24f // Set card corner radius +localazyCard.setStrokeColor(ContextCompat.getColor(this, R.color.design_default_color_primary)) // Set stroke color +localazyCard.strokeWidth = 2 // Set stroke width +localazyCard.elevation = 0f // Set card elevation // And much more ``` + # Changelog +### 1.2 (4-May-2021) +- Converted code to Kotlin + +### 1.1.1 (4-May-2021) +- Design overhaul + +### 1.1 (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.0.4 (20-Mar-2021) - Added feature to change app language directly from the app - Updated library code diff --git a/app/.localazy b/app/.localazy new file mode 100644 index 0000000..53219e8 --- /dev/null +++ b/app/.localazy @@ -0,0 +1,3 @@ +[packages] +com.paget96.localazy_card = raa + diff --git a/app/build.gradle b/app/build.gradle index 3abd586..4a04454 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ plugins { id 'com.android.application' + id 'com.localazy.gradle' + id 'kotlin-android' } android { @@ -25,20 +27,38 @@ android { } } } + compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 + + kotlinOptions { + jvmTarget = '1.8' + } + } +} + +localazy { + readKey "put your read key" + writeKey "put your write key" + + upload { + showUploadAll true } } dependencies { + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + implementation project(":LocalazyCard") implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.3.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //implementation 'com.github.Paget96:Localazy-Card:1.0' - testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.2' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + + implementation "androidx.core:core-ktx:1.3.2" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0d47ffb..450216a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,8 @@ + + (R.id.localazyCard) + + // IMPORTANT, define activity for language changing + localazyCard.setActivity(this) + + // Set card icon + localazyCard.setIcon(R.drawable.ic_localazy_no_bgd) + + // Title text + localazyCard.setTitle(getString(R.string.translate) + " " + getString(R.string.app_name)) + localazyCard.setTitleTextSize(18f) + localazyCard.setTitleTextStyle(Typeface.BOLD) + + // Summary text + localazyCard.setSummaryText(getString(R.string.summary_text, getString(R.string.app_name))) + localazyCard.setSummaryTextSize(14f) + localazyCard.setSummaryTextStyle(Typeface.NORMAL) + + // Open translation link + localazyCard.setTranslateButton() + + // Invite to translate + localazyCard.setInviteButton(getString(R.string.invitation_text, getString(R.string.app_name))) + localazyCard.radius = 24f + localazyCard.strokeColor = ContextCompat.getColor(this, R.color.design_default_color_primary) + localazyCard.strokeWidth = 2 + localazyCard.elevation = 0f + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index b965f25..3c2b9db 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -12,7 +12,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="16dp" - app:localazy_app_translation_link="https://localazy.com" app:localazy_icon="@drawable/ic_localazy" app:localazy_invitation_message="@string/localazy_default_invitation_text" app:localazy_summary="@string/localazy_default_summary" diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 9333725..42582e4 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -1,5 +1,5 @@ - Localazy-Card-Deutch + Localazy-Card Übersetzen Helfen Sie uns %1$s App mehrsprachig zu machen und in mehr als 50 Sprachen zu übersetzen Ich lade Sie ein, beim Übersetzen zu helfen %1$s diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 71f1fbf..af27d77 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -1,5 +1,5 @@ - Localazy-Card-France + Localazy-Card Traduire Aidez-nous à rendre l\'application %1$s multilingue, traduisez-la dans plus de 50 langues Je vous invite à aider à traduire %1$s diff --git a/build.gradle b/build.gradle index 4e2646f..a5aa2a6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,16 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + ext.kotlin_version = '1.4.32' repositories { google() mavenCentral() + maven { url "https://maven.localazy.com/repository/release/" } } + dependencies { - classpath 'com.android.tools.build:gradle:4.2.0-rc01' + classpath 'com.android.tools.build:gradle:4.2.0' + classpath "com.localazy:gradle:1.5.2" + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5b92423..aa17f53 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri Mar 19 12:43:15 CET 2021 +#Tue May 04 08:43:54 GMT 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip distributionPath=wrapper/dists -zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip diff --git a/resources/screenshot1.png b/resources/screenshot1.png new file mode 100644 index 0000000..19202f0 Binary files /dev/null and b/resources/screenshot1.png differ diff --git a/resources/screenshot_1.png b/resources/screenshot_1.png deleted file mode 100644 index e6e9d02..0000000 Binary files a/resources/screenshot_1.png and /dev/null differ