From 9b1c5442fade1af4ab7dbce289734e3094cf968d Mon Sep 17 00:00:00 2001 From: Bartosz J Date: Wed, 7 Dec 2016 14:20:03 +0100 Subject: [PATCH 1/3] Bump plugins versions --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 346c96b..7a0d4b5 100644 --- a/build.gradle +++ b/build.gradle @@ -5,9 +5,9 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.0' + classpath 'com.android.tools.build:gradle:2.2.2' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4' - classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' + classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } From 85a2030713099e919ed05692319a2c5e18ad2686 Mon Sep 17 00:00:00 2001 From: Bartosz J Date: Wed, 7 Dec 2016 14:21:41 +0100 Subject: [PATCH 2/3] Remove LocaleController dependency --- .../Actionbar/ActionBarMenuItem.java | 7 +- .../Components/PhotoPickerSearchCell.java | 7 +- .../Components/PickerBottomLayout.java | 5 +- .../PhotoAlbumPickerActivity.java | 25 +- .../telegramgallery/PhotoPickerActivity.java | 30 +- .../telegramgallery/PhotoViewer.java | 30 +- .../Utils/AndroidUtilities.java | 28 +- .../Utils/LocaleController.java | 854 ------------------ .../Utils/MediaController.java | 9 +- 9 files changed, 60 insertions(+), 935 deletions(-) delete mode 100644 telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Utils/LocaleController.java diff --git a/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Actionbar/ActionBarMenuItem.java b/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Actionbar/ActionBarMenuItem.java index 048c077..edfa426 100644 --- a/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Actionbar/ActionBarMenuItem.java +++ b/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Actionbar/ActionBarMenuItem.java @@ -26,7 +26,6 @@ import com.tangxiaolv.telegramgallery.Theme; import com.tangxiaolv.telegramgallery.Utils.AndroidUtilities; import com.tangxiaolv.telegramgallery.Utils.LayoutHelper; -import com.tangxiaolv.telegramgallery.Utils.LocaleController; import java.lang.reflect.Field; @@ -215,7 +214,7 @@ public void onDispatchKeyEvent(KeyEvent keyEvent) { TextView textView = new TextView(getContext()); textView.setTextColor(0xff212121); textView.setBackgroundResource(R.drawable.list_selector); - if (!LocaleController.isRTL) { + if (!AndroidUtilities.isRTL()) { textView.setGravity(Gravity.CENTER_VERTICAL); } else { textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT); @@ -227,7 +226,7 @@ public void onDispatchKeyEvent(KeyEvent keyEvent) { textView.setText(text); if (icon != 0) { textView.setCompoundDrawablePadding(AndroidUtilities.dp(12)); - if (!LocaleController.isRTL) { + if (!AndroidUtilities.isRTL()) { textView.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(icon), null, null, null); } else { textView.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(icon), null); @@ -236,7 +235,7 @@ public void onDispatchKeyEvent(KeyEvent keyEvent) { popupLayout.setShowedFromBotton(showFromBottom); popupLayout.addView(textView); LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams(); - if (LocaleController.isRTL) { + if (AndroidUtilities.isRTL()) { layoutParams.gravity = Gravity.RIGHT; } layoutParams.width = LayoutHelper.MATCH_PARENT; diff --git a/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Components/PhotoPickerSearchCell.java b/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Components/PhotoPickerSearchCell.java index 8eeb4fb..48c6ffe 100644 --- a/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Components/PhotoPickerSearchCell.java +++ b/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Components/PhotoPickerSearchCell.java @@ -14,7 +14,6 @@ import com.tangxiaolv.telegramgallery.Utils.AndroidUtilities; import com.tangxiaolv.telegramgallery.Utils.LayoutHelper; -import com.tangxiaolv.telegramgallery.Utils.LocaleController; import com.tangxiaolv.telegramgallery.R; public class PhotoPickerSearchCell extends LinearLayout { @@ -78,8 +77,8 @@ public PhotoPickerSearchCell(Context context, boolean allowGifs) { setOrientation(HORIZONTAL); SearchButton searchButton = new SearchButton(context); - searchButton.textView1.setText(LocaleController.getString("SearchImages", R.string.SearchImages)); - searchButton.textView2.setText(LocaleController.getString("SearchImagesInfo", R.string.SearchImagesInfo)); + searchButton.textView1.setText(R.string.SearchImages); + searchButton.textView2.setText(R.string.SearchImagesInfo); searchButton.imageView.setImageResource(R.drawable.search_web); addView(searchButton); LayoutParams layoutParams = (LayoutParams) searchButton.getLayoutParams(); @@ -107,7 +106,7 @@ public void onClick(View v) { frameLayout.setLayoutParams(layoutParams); searchButton = new SearchButton(context); - searchButton.textView1.setText(LocaleController.getString("SearchGifs", R.string.SearchGifs)); + searchButton.textView1.setText(R.string.SearchGifs); searchButton.textView2.setText("GIPHY"); searchButton.imageView.setImageResource(R.drawable.search_gif); addView(searchButton); diff --git a/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Components/PickerBottomLayout.java b/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Components/PickerBottomLayout.java index 1c82056..d0d5ec3 100644 --- a/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Components/PickerBottomLayout.java +++ b/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Components/PickerBottomLayout.java @@ -14,7 +14,6 @@ import com.tangxiaolv.telegramgallery.Theme; import com.tangxiaolv.telegramgallery.Utils.AndroidUtilities; import com.tangxiaolv.telegramgallery.Utils.LayoutHelper; -import com.tangxiaolv.telegramgallery.Utils.LocaleController; public class PickerBottomLayout extends FrameLayout { @@ -43,7 +42,7 @@ public PickerBottomLayout(Context context, boolean darkTheme) { Theme.createBarSelectorDrawable(isDarkTheme ? Theme.ACTION_BAR_PICKER_SELECTOR_COLOR : Theme.ACTION_BAR_AUDIO_SELECTOR_COLOR, false)); cancelButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0); - cancelButton.setText(LocaleController.getString("Preview", R.string.Preview).toUpperCase()); + cancelButton.setText(R.string.Preview); // cancelButton.getPaint().setFakeBoldText(true); addView(cancelButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); @@ -74,7 +73,7 @@ public PickerBottomLayout(Context context, boolean darkTheme) { doneButtonTextView.setTextColor(isDarkTheme ? 0xffffffff : 0xff007aff); doneButtonTextView.setGravity(Gravity.CENTER); doneButtonTextView.setCompoundDrawablePadding(AndroidUtilities.dp(8)); - doneButtonTextView.setText(LocaleController.getString("Send", R.string.Send).toUpperCase()); + doneButtonTextView.setText(R.string.Send); // doneButtonTextView.getPaint().setFakeBoldText(true); doneButton.addView(doneButtonTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL)); diff --git a/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/PhotoAlbumPickerActivity.java b/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/PhotoAlbumPickerActivity.java index 22fcd39..77789b6 100644 --- a/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/PhotoAlbumPickerActivity.java +++ b/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/PhotoAlbumPickerActivity.java @@ -27,7 +27,6 @@ import com.tangxiaolv.telegramgallery.Components.PhotoPickerSearchCell; import com.tangxiaolv.telegramgallery.Utils.AndroidUtilities; import com.tangxiaolv.telegramgallery.Utils.LayoutHelper; -import com.tangxiaolv.telegramgallery.Utils.LocaleController; import com.tangxiaolv.telegramgallery.Utils.MediaController; import com.tangxiaolv.telegramgallery.Utils.NotificationCenter; @@ -114,7 +113,7 @@ public View createView(Context context) { actionBar.setBackgroundColor(Theme.ACTION_BAR_MEDIA_PICKER_COLOR); actionBar.setItemsBackgroundColor(Theme.ACTION_BAR_PICKER_SELECTOR_COLOR); // actionBar.setBackButtonImage(R.drawable.ic_ab_back); - actionBar.setBackText(LocaleController.getString("Cancel", R.string.Cancel)); + actionBar.setBackText(context.getString(R.string.Cancel)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { @@ -131,8 +130,8 @@ public void onItemClick(int id) { } selectedMode = 0; dropDown.setText( - LocaleController.getString("PickerPhotos", R.string.PickerPhotos)); - emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos)); + R.string.PickerPhotos); + emptyView.setText(R.string.NoPhotos); listAdapter.notifyDataSetChanged(); } else if (id == item_video) { if (selectedMode == 1) { @@ -140,8 +139,8 @@ public void onItemClick(int id) { } selectedMode = 1; dropDown.setText( - LocaleController.getString("PickerVideo", R.string.PickerVideo)); - emptyView.setText(LocaleController.getString("NoVideo", R.string.NoVideo)); + R.string.PickerVideo); + emptyView.setText(R.string.NoVideo); listAdapter.notifyDataSetChanged(); } } @@ -159,10 +158,10 @@ public void onItemClick(int id) { ActionBarMenu menu = actionBar.createMenu(); dropDownContainer = new ActionBarMenuItem(context, menu, 0); dropDownContainer.setSubMenuOpenSide(1); - dropDownContainer.addSubItem(item_photos, - LocaleController.getString("PickerPhotos", R.string.PickerPhotos), 0); - dropDownContainer.addSubItem(item_video, - LocaleController.getString("PickerVideo", R.string.PickerVideo), 0); + dropDownContainer.addSubItem(item_photos,context.getString( + R.string.PickerPhotos), 0); + dropDownContainer.addSubItem(item_video,context.getString( + R.string.PickerVideo), 0); actionBar.addView(dropDownContainer); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) dropDownContainer .getLayoutParams(); @@ -191,7 +190,7 @@ public void onClick(View view) { 0); dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4)); // dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0); - dropDown.setText(LocaleController.getString("PickerPhotos", R.string.PickerPhotos)); + dropDown.setText(R.string.PickerPhotos); dropDownContainer.addView(dropDown); layoutParams = (FrameLayout.LayoutParams) dropDown.getLayoutParams(); layoutParams.width = LayoutHelper.WRAP_CONTENT; @@ -200,7 +199,7 @@ public void onClick(View view) { layoutParams.gravity = Gravity.CENTER_VERTICAL; dropDown.setLayoutParams(layoutParams); } else { - actionBar.setTitle(LocaleController.getString("Album", R.string.Album)); + actionBar.setTitle(context.getString(R.string.Album)); } listView = new ListView(context); @@ -229,7 +228,7 @@ public void onClick(View view) { emptyView.setTextSize(20); emptyView.setGravity(Gravity.CENTER); emptyView.setVisibility(View.GONE); - emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos)); + emptyView.setText(R.string.NoPhotos); frameLayout.addView(emptyView); layoutParams = (FrameLayout.LayoutParams) emptyView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; diff --git a/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/PhotoPickerActivity.java b/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/PhotoPickerActivity.java index 53f91e1..08d4b6d 100644 --- a/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/PhotoPickerActivity.java +++ b/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/PhotoPickerActivity.java @@ -34,7 +34,6 @@ import com.tangxiaolv.telegramgallery.Utils.AndroidUtilities; import com.tangxiaolv.telegramgallery.Utils.FileLoader; import com.tangxiaolv.telegramgallery.Utils.LayoutHelper; -import com.tangxiaolv.telegramgallery.Utils.LocaleController; import com.tangxiaolv.telegramgallery.Utils.MediaController; import com.tangxiaolv.telegramgallery.Utils.NotificationCenter; @@ -147,7 +146,7 @@ public void onItemClick(int id) { LinearLayout.LayoutParams cancelParams = LayoutHelper .createLinear(LayoutHelper.WRAP_CONTENT, -1); cancel.setTextSize(18); - cancel.setText(LocaleController.getString("Cancel", R.string.Cancel)); + cancel.setText(R.string.Cancel); cancel.setTextColor(0xffffffff); cancel.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL); cancelParams.setMargins(0, 0, AndroidUtilities.dp(8), 0); @@ -163,11 +162,10 @@ public void onClick(View v) { if (selectedAlbum == null) { if (type == 0) { - searchItem.getSearchField().setHint(LocaleController.getString("SearchImagesTitle", - R.string.SearchImagesTitle)); + searchItem.getSearchField().setHint(R.string.SearchImagesTitle); } else if (type == 1) { searchItem.getSearchField().setHint( - LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle)); + R.string.SearchGifsTitle); } } @@ -240,11 +238,11 @@ public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { if (searchResult.isEmpty() && lastSearchString == null) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); - builder.setTitle(LocaleController.getString("AppName", R.string.app_name)); - builder.setMessage( - LocaleController.getString("ClearSearch", R.string.ClearSearch)); - builder.setPositiveButton(LocaleController - .getString("ClearButton", R.string.ClearButton).toUpperCase(), + builder.setTitle(R.string.app_name) + .setMessage( + R.string.ClearSearch) + .setPositiveButton( + R.string.ClearButton, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { @@ -253,9 +251,9 @@ public void onClick(DialogInterface dialogInterface, int i) { listAdapter.notifyDataSetChanged(); } } - }); - builder.setNegativeButton( - LocaleController.getString("Cancel", R.string.Cancel), null); + }) + .setNegativeButton( + R.string.Cancel, null); showDialog(builder.create()); return true; } @@ -270,14 +268,14 @@ public void onClick(DialogInterface dialogInterface, int i) { emptyView.setGravity(Gravity.CENTER); emptyView.setVisibility(View.GONE); if (selectedAlbum != null) { - emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos)); + emptyView.setText(R.string.NoPhotos); } else { if (type == 0) { emptyView.setText( - LocaleController.getString("NoRecentPhotos", R.string.NoRecentPhotos)); + R.string.NoRecentPhotos); } else if (type == 1) { emptyView - .setText(LocaleController.getString("NoRecentGIFs", R.string.NoRecentGIFs)); + .setText(R.string.NoRecentGIFs); } } frameLayout.addView(emptyView); diff --git a/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/PhotoViewer.java b/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/PhotoViewer.java index bda6668..1432d21 100644 --- a/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/PhotoViewer.java +++ b/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/PhotoViewer.java @@ -23,7 +23,6 @@ import com.tangxiaolv.telegramgallery.Utils.FileLoader; import com.tangxiaolv.telegramgallery.Utils.ImageLoader; import com.tangxiaolv.telegramgallery.Utils.LayoutHelper; -import com.tangxiaolv.telegramgallery.Utils.LocaleController; import com.tangxiaolv.telegramgallery.Utils.MediaController; import com.tangxiaolv.telegramgallery.Utils.NotificationCenter; import com.tangxiaolv.telegramgallery.Utils.Utilities; @@ -49,7 +48,6 @@ import android.net.Uri; import android.os.Build; import android.text.TextUtils; -import android.view.ActionMode; import android.view.ContextThemeWrapper; import android.view.GestureDetector; import android.view.Gravity; @@ -79,7 +77,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat private boolean isVisible; private Activity parentActivity; - private Context actvityContext; + private Context activityContext; private ActionBar actionBar; private boolean isActionBarVisible = true; @@ -731,7 +729,7 @@ public void setParentActivity(final Activity activity) { return; } parentActivity = activity; - actvityContext = new ContextThemeWrapper(parentActivity, R.style.Theme_TMessages); + activityContext = new ContextThemeWrapper(parentActivity, R.style.Theme_TMessages); scroller = new Scroller(activity); @@ -775,7 +773,7 @@ public boolean dispatchKeyEventPreIme(KeyEvent event) { actionBar.setOccupyStatusBar(false); actionBar.setItemsBackgroundColor(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR); actionBar.setBackButtonImage(R.drawable.ic_ab_back); - actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, 1, 1)); + actionBar.setTitle(activityContext.getString(R.string.Of, 1, 1)); containerView.addView(actionBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); @@ -842,7 +840,7 @@ public boolean canOpenMenu() { checkImageView.setLayoutParams(params); indexItem = menu.addItem(gallery_menu_index, checkImageView); - bottomLayout = new FrameLayout(actvityContext); + bottomLayout = new FrameLayout(activityContext); bottomLayout.setBackgroundColor(0x7f000000); containerView.addView(bottomLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT)); @@ -854,7 +852,7 @@ public boolean canOpenMenu() { radialProgressViews[2] = new RadialProgressView(containerView.getContext(), containerView); radialProgressViews[2].setBackgroundState(0, false); - pickerView = new PickerBottomLayout(actvityContext); + pickerView = new PickerBottomLayout(activityContext); pickerView.setBackgroundColor(0x7f000000); containerView.addView(pickerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT)); @@ -880,7 +878,7 @@ public void onClick(View view) { } }); - editorDoneLayout = new PickerBottomLayout(actvityContext); + editorDoneLayout = new PickerBottomLayout(activityContext); editorDoneLayout.setBackgroundColor(0x7f000000); editorDoneLayout.updateSelectedCount(0, false); editorDoneLayout.setVisibility(View.GONE); @@ -910,7 +908,7 @@ public void onClick(View view) { } }); - ImageView rotateButton = new ImageView(actvityContext); + ImageView rotateButton = new ImageView(activityContext); rotateButton.setScaleType(ImageView.ScaleType.CENTER); rotateButton.setImageResource(R.drawable.tool_rotate); rotateButton.setBackgroundDrawable( @@ -1137,7 +1135,7 @@ public void onAnimationStart(Animator animation) { imageMoveAnimation.start(); } else if (mode == 1) { if (photoCropView == null) { - photoCropView = new PhotoCropView(actvityContext); + photoCropView = new PhotoCropView(activityContext); photoCropView.setVisibility(View.GONE); containerView.addView(photoCropView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, @@ -1164,7 +1162,7 @@ public Bitmap getBitmap() { } editorDoneLayout.doneButtonTextView - .setText(LocaleController.getString("Crop", R.string.Crop)); + .setText(R.string.Crop); changeModeAnimation = new AnimatorSet(); ArrayList arrayList = new ArrayList<>(); arrayList.add( @@ -1462,7 +1460,7 @@ private void setImageIndex(int index, boolean init) { && old.volume_id == currentFileLocation.volume_id) { sameImage = true; } - actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, currentIndex + 1, + actionBar.setTitle(activityContext.getString(R.string.Of, currentIndex + 1, imagesArrLocations.size())); } else if (!imagesArrLocals.isEmpty()) { Object object = imagesArrLocals.get(index); @@ -1486,9 +1484,9 @@ private void setImageIndex(int index, boolean init) { } } if (fromCamera) { - actionBar.setTitle(LocaleController.getString("AttachPhoto", R.string.AttachPhoto)); + actionBar.setTitle(activityContext.getString(R.string.AttachPhoto)); } else { - actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, + actionBar.setTitle(activityContext.getString(R.string.Of, currentIndex + 1, imagesArrLocals.size())); } if (sendPhotoType == 0) { @@ -1738,7 +1736,7 @@ public void openPhotoForSelect(final List photos, boolean selectPreview, sendPhotoType = type; if (pickerView != null) { pickerView.doneButtonTextView - .setText(LocaleController.getString("Send", R.string.Send).toUpperCase()); + .setText(R.string.Send); } openPhoto(null, photos, index, provider, 0, 0); } @@ -1790,7 +1788,7 @@ public void openPhoto(final FileLocation fileLocation, final List photos return; } - actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, 1, 1)); + actionBar.setTitle(activityContext.getString(R.string.Of, 1, 1)); NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailedLoad); NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidLoaded); NotificationCenter.getInstance().addObserver(this, diff --git a/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Utils/AndroidUtilities.java b/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Utils/AndroidUtilities.java index 5f68e05..8f68952 100644 --- a/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Utils/AndroidUtilities.java +++ b/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Utils/AndroidUtilities.java @@ -40,6 +40,7 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Hashtable; +import java.util.Locale; import java.util.regex.Pattern; public class AndroidUtilities { @@ -319,27 +320,6 @@ public static int getPhotoSize() { return photoSize; } - public static String formatTTLString(int ttl) { - if (ttl < 60) { - return LocaleController.formatPluralString("Seconds", ttl); - } else if (ttl < 60 * 60) { - return LocaleController.formatPluralString("Minutes", ttl / 60); - } else if (ttl < 60 * 60 * 24) { - return LocaleController.formatPluralString("Hours", ttl / 60 / 60); - } else if (ttl < 60 * 60 * 24 * 7) { - return LocaleController.formatPluralString("Days", ttl / 60 / 60 / 24); - } else { - int days = ttl / 60 / 60 / 24; - if (ttl % 7 == 0) { - return LocaleController.formatPluralString("Weeks", days / 7); - } else { - return String.format("%s %s", - LocaleController.formatPluralString("Weeks", days / 7), - LocaleController.formatPluralString("Days", days % 7)); - } - } - } - public static int getViewInset(View view) { if (view == null || Build.VERSION.SDK_INT < 21 || view.getHeight() == AndroidUtilities.displaySize.y @@ -629,4 +609,10 @@ public static boolean isDownloadsDocument(Uri uri) { public static boolean isMediaDocument(Uri uri) { return "com.android.providers.media.documents".equals(uri.getAuthority()); } + + public static boolean isRTL() { + final int directionality = Character.getDirectionality(Locale.getDefault().getDisplayName().charAt(0)); + return directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT || + directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC; + } } diff --git a/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Utils/LocaleController.java b/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Utils/LocaleController.java deleted file mode 100644 index 10162a9..0000000 --- a/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Utils/LocaleController.java +++ /dev/null @@ -1,854 +0,0 @@ - -package com.tangxiaolv.telegramgallery.Utils; - -import android.app.Activity; -import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.text.TextUtils; -import android.text.format.DateFormat; -import android.util.Xml; - -import com.tangxiaolv.telegramgallery.Gallery; - -import org.xmlpull.v1.XmlPullParser; - -import java.io.File; -import java.io.FileInputStream; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Locale; - -public class LocaleController { - - static final int QUANTITY_OTHER = 0x0000; - static final int QUANTITY_ZERO = 0x0001; - static final int QUANTITY_ONE = 0x0002; - static final int QUANTITY_TWO = 0x0004; - static final int QUANTITY_FEW = 0x0008; - static final int QUANTITY_MANY = 0x0010; - - public static boolean isRTL = false; - public static int nameDisplayOrder = 1; - private static boolean is24HourFormat = false; - - private HashMap allRules = new HashMap<>(); - - private Locale currentLocale; - private Locale systemDefaultLocale; - private PluralRules currentPluralRules; - private LocaleInfo currentLocaleInfo; - private LocaleInfo defaultLocalInfo; - private HashMap localeValues = new HashMap<>(); - private String languageOverride; - private boolean changingConfiguration = false; - - private HashMap translitChars; - - public static class LocaleInfo { - public String name; - public String nameEnglish; - public String shortName; - public String pathToFile; - - public String getSaveString() { - return name + "|" + nameEnglish + "|" + shortName + "|" + pathToFile; - } - - public static LocaleInfo createWithString(String string) { - if (string == null || string.length() == 0) { - return null; - } - String[] args = string.split("\\|"); - if (args.length != 4) { - return null; - } - LocaleInfo localeInfo = new LocaleInfo(); - localeInfo.name = args[0]; - localeInfo.nameEnglish = args[1]; - localeInfo.shortName = args[2]; - localeInfo.pathToFile = args[3]; - return localeInfo; - } - } - - public ArrayList sortedLanguages = new ArrayList<>(); - public HashMap languagesDict = new HashMap<>(); - - private ArrayList otherLanguages = new ArrayList<>(); - - private static volatile LocaleController Instance = null; - - public static LocaleController getInstance() { - LocaleController localInstance = Instance; - if (localInstance == null) { - synchronized (LocaleController.class) { - localInstance = Instance; - if (localInstance == null) { - Instance = localInstance = new LocaleController(); - } - } - } - return localInstance; - } - - public LocaleController() { - addRules(new String[] { - "bem", "brx", "da", "de", "el", "en", "eo", "es", "et", "fi", "fo", "gl", "he", - "iw", "it", "nb", "nl", "nn", "no", "sv", "af", "bg", "bn", "ca", "eu", "fur", "fy", - "gu", "ha", "is", "ku", "lb", "ml", "mr", "nah", "ne", "om", "or", "pa", "pap", - "ps", "so", "sq", "sw", "ta", "te", "tk", "ur", "zu", "mn", "gsw", "chr", "rm", - "pt", "an", "ast" - }, new PluralRules_One()); - addRules(new String[] { - "cs", "sk" - }, new PluralRules_Czech()); - addRules(new String[] { - "ff", "fr", "kab" - }, new PluralRules_French()); - addRules(new String[] { - "hr", "ru", "sr", "uk", "be", "bs", "sh" - }, new PluralRules_Balkan()); - addRules(new String[] { - "lv" - }, new PluralRules_Latvian()); - addRules(new String[] { - "lt" - }, new PluralRules_Lithuanian()); - addRules(new String[] { - "pl" - }, new PluralRules_Polish()); - addRules(new String[] { - "ro", "mo" - }, new PluralRules_Romanian()); - addRules(new String[] { - "sl" - }, new PluralRules_Slovenian()); - addRules(new String[] { - "ar" - }, new PluralRules_Arabic()); - addRules(new String[] { - "mk" - }, new PluralRules_Macedonian()); - addRules(new String[] { - "cy" - }, new PluralRules_Welsh()); - addRules(new String[] { - "br" - }, new PluralRules_Breton()); - addRules(new String[] { - "lag" - }, new PluralRules_Langi()); - addRules(new String[] { - "shi" - }, new PluralRules_Tachelhit()); - addRules(new String[] { - "mt" - }, new PluralRules_Maltese()); - addRules(new String[] { - "ga", "se", "sma", "smi", "smj", "smn", "sms" - }, new PluralRules_Two()); - addRules(new String[] { - "ak", "am", "bh", "fil", "tl", "guw", "hi", "ln", "mg", "nso", "ti", "wa" - }, new PluralRules_Zero()); - addRules(new String[] { - "az", "bm", "fa", "ig", "hu", "ja", "kde", "kea", "ko", "my", "ses", "sg", "to", - "tr", "vi", "wo", "yo", "zh", "bo", "dz", "id", "jv", "ka", "km", "kn", "ms", "th" - }, new PluralRules_None()); - - LocaleInfo localeInfo = new LocaleInfo(); - localeInfo.name = "English"; - localeInfo.nameEnglish = "English"; - localeInfo.shortName = "en"; - localeInfo.pathToFile = null; - sortedLanguages.add(localeInfo); - languagesDict.put(localeInfo.shortName, localeInfo); - - localeInfo = new LocaleInfo(); - localeInfo.name = "Italiano"; - localeInfo.nameEnglish = "Italian"; - localeInfo.shortName = "it"; - localeInfo.pathToFile = null; - sortedLanguages.add(localeInfo); - languagesDict.put(localeInfo.shortName, localeInfo); - - localeInfo = new LocaleInfo(); - localeInfo.name = "Español"; - localeInfo.nameEnglish = "Spanish"; - localeInfo.shortName = "es"; - sortedLanguages.add(localeInfo); - languagesDict.put(localeInfo.shortName, localeInfo); - - localeInfo = new LocaleInfo(); - localeInfo.name = "Deutsch"; - localeInfo.nameEnglish = "German"; - localeInfo.shortName = "de"; - localeInfo.pathToFile = null; - sortedLanguages.add(localeInfo); - languagesDict.put(localeInfo.shortName, localeInfo); - - localeInfo = new LocaleInfo(); - localeInfo.name = "Nederlands"; - localeInfo.nameEnglish = "Dutch"; - localeInfo.shortName = "nl"; - localeInfo.pathToFile = null; - sortedLanguages.add(localeInfo); - languagesDict.put(localeInfo.shortName, localeInfo); - - localeInfo = new LocaleInfo(); - localeInfo.name = "العربية"; - localeInfo.nameEnglish = "Arabic"; - localeInfo.shortName = "ar"; - localeInfo.pathToFile = null; - sortedLanguages.add(localeInfo); - languagesDict.put(localeInfo.shortName, localeInfo); - - localeInfo = new LocaleInfo(); - localeInfo.name = "Português (Brasil)"; - localeInfo.nameEnglish = "Portuguese (Brazil)"; - localeInfo.shortName = "pt_BR"; - localeInfo.pathToFile = null; - sortedLanguages.add(localeInfo); - languagesDict.put(localeInfo.shortName, localeInfo); - - localeInfo = new LocaleInfo(); - localeInfo.name = "Português (Portugal)"; - localeInfo.nameEnglish = "Portuguese (Portugal)"; - localeInfo.shortName = "pt_PT"; - localeInfo.pathToFile = null; - sortedLanguages.add(localeInfo); - languagesDict.put(localeInfo.shortName, localeInfo); - - localeInfo = new LocaleInfo(); - localeInfo.name = "한국어"; - localeInfo.nameEnglish = "Korean"; - localeInfo.shortName = "ko"; - localeInfo.pathToFile = null; - sortedLanguages.add(localeInfo); - languagesDict.put(localeInfo.shortName, localeInfo); - - loadOtherLanguages(); - - for (LocaleInfo locale : otherLanguages) { - sortedLanguages.add(locale); - languagesDict.put(locale.shortName, locale); - } - - Collections.sort(sortedLanguages, new Comparator() { - @Override - public int compare(LocaleInfo o, LocaleInfo o2) { - return o.name.compareTo(o2.name); - } - }); - - defaultLocalInfo = localeInfo = new LocaleInfo(); - localeInfo.name = "System default"; - localeInfo.nameEnglish = "System default"; - localeInfo.shortName = null; - localeInfo.pathToFile = null; - sortedLanguages.add(0, localeInfo); - - systemDefaultLocale = Locale.getDefault(); - is24HourFormat = DateFormat.is24HourFormat(Gallery.applicationContext); - LocaleInfo currentInfo = null; - boolean override = false; - - try { - SharedPreferences preferences = Gallery.applicationContext - .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); - String lang = preferences.getString("language", null); - if (lang != null) { - currentInfo = languagesDict.get(lang); - if (currentInfo != null) { - override = true; - } - } - - if (currentInfo == null && systemDefaultLocale.getLanguage() != null) { - currentInfo = languagesDict.get(systemDefaultLocale.getLanguage()); - } - if (currentInfo == null) { - currentInfo = languagesDict.get(getLocaleString(systemDefaultLocale)); - } - if (currentInfo == null) { - currentInfo = languagesDict.get("en"); - } - applyLanguage(currentInfo, override); - } catch (Exception e) { - e.printStackTrace(); - } - } - - private void addRules(String[] languages, PluralRules rules) { - for (String language : languages) { - allRules.put(language, rules); - } - } - - private String stringForQuantity(int quantity) { - switch (quantity) { - case QUANTITY_ZERO: - return "zero"; - case QUANTITY_ONE: - return "one"; - case QUANTITY_TWO: - return "two"; - case QUANTITY_FEW: - return "few"; - case QUANTITY_MANY: - return "many"; - default: - return "other"; - } - } - - public Locale getSystemDefaultLocale() { - return systemDefaultLocale; - } - - private String getLocaleString(Locale locale) { - if (locale == null) { - return "en"; - } - String languageCode = locale.getLanguage(); - String countryCode = locale.getCountry(); - String variantCode = locale.getVariant(); - if (languageCode.length() == 0 && countryCode.length() == 0) { - return "en"; - } - StringBuilder result = new StringBuilder(11); - result.append(languageCode); - if (countryCode.length() > 0 || variantCode.length() > 0) { - result.append('_'); - } - result.append(countryCode); - if (variantCode.length() > 0) { - result.append('_'); - } - result.append(variantCode); - return result.toString(); - } - - public static String getLocaleStringIso639() { - Locale locale = getInstance().getSystemDefaultLocale(); - if (locale == null) { - return "en"; - } - String languageCode = locale.getLanguage(); - String countryCode = locale.getCountry(); - String variantCode = locale.getVariant(); - if (languageCode.length() == 0 && countryCode.length() == 0) { - return "en"; - } - StringBuilder result = new StringBuilder(11); - result.append(languageCode); - if (countryCode.length() > 0 || variantCode.length() > 0) { - result.append('-'); - } - result.append(countryCode); - if (variantCode.length() > 0) { - result.append('_'); - } - result.append(variantCode); - return result.toString(); - } - - private void saveOtherLanguages() { - SharedPreferences preferences = Gallery.applicationContext - .getSharedPreferences("langconfig", Activity.MODE_PRIVATE); - SharedPreferences.Editor editor = preferences.edit(); - String locales = ""; - for (LocaleInfo localeInfo : otherLanguages) { - String loc = localeInfo.getSaveString(); - if (loc != null) { - if (locales.length() != 0) { - locales += "&"; - } - locales += loc; - } - } - editor.putString("locales", locales); - editor.commit(); - } - - public boolean deleteLanguage(LocaleInfo localeInfo) { - if (localeInfo.pathToFile == null) { - return false; - } - if (currentLocaleInfo == localeInfo) { - applyLanguage(defaultLocalInfo, true); - } - - otherLanguages.remove(localeInfo); - sortedLanguages.remove(localeInfo); - languagesDict.remove(localeInfo.shortName); - File file = new File(localeInfo.pathToFile); - file.delete(); - saveOtherLanguages(); - return true; - } - - private void loadOtherLanguages() { - SharedPreferences preferences = Gallery.applicationContext - .getSharedPreferences("langconfig", Activity.MODE_PRIVATE); - String locales = preferences.getString("locales", null); - if (locales == null || locales.length() == 0) { - return; - } - String[] localesArr = locales.split("&"); - for (String locale : localesArr) { - LocaleInfo localeInfo = LocaleInfo.createWithString(locale); - if (localeInfo != null) { - otherLanguages.add(localeInfo); - } - } - } - - private HashMap getLocaleFileStrings(File file) { - FileInputStream stream = null; - try { - HashMap stringMap = new HashMap<>(); - XmlPullParser parser = Xml.newPullParser(); - stream = new FileInputStream(file); - parser.setInput(stream, "UTF-8"); - int eventType = parser.getEventType(); - String name = null; - String value = null; - String attrName = null; - while (eventType != XmlPullParser.END_DOCUMENT) { - if (eventType == XmlPullParser.START_TAG) { - name = parser.getName(); - int c = parser.getAttributeCount(); - if (c > 0) { - attrName = parser.getAttributeValue(0); - } - } else if (eventType == XmlPullParser.TEXT) { - if (attrName != null) { - value = parser.getText(); - if (value != null) { - value = value.trim(); - value = value.replace("\\n", "\n"); - value = value.replace("\\", ""); - } - } - } else if (eventType == XmlPullParser.END_TAG) { - value = null; - attrName = null; - name = null; - } - if (name != null && name.equals("string") && value != null && attrName != null - && value.length() != 0 && attrName.length() != 0) { - stringMap.put(attrName, value); - name = null; - value = null; - attrName = null; - } - eventType = parser.next(); - } - return stringMap; - } catch (Exception e) { - } finally { - try { - if (stream != null) { - stream.close(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - return new HashMap<>(); - } - - public void applyLanguage(LocaleInfo localeInfo, boolean override) { - applyLanguage(localeInfo, override, false); - } - - public void applyLanguage(LocaleInfo localeInfo, boolean override, boolean fromFile) { - if (localeInfo == null) { - return; - } - try { - Locale newLocale; - if (localeInfo.shortName != null) { - String[] args = localeInfo.shortName.split("_"); - if (args.length == 1) { - newLocale = new Locale(localeInfo.shortName); - } else { - newLocale = new Locale(args[0], args[1]); - } - if (newLocale != null) { - if (override) { - languageOverride = localeInfo.shortName; - - SharedPreferences preferences = Gallery.applicationContext - .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); - SharedPreferences.Editor editor = preferences.edit(); - editor.putString("language", localeInfo.shortName); - editor.commit(); - } - } - } else { - newLocale = systemDefaultLocale; - languageOverride = null; - SharedPreferences preferences = Gallery.applicationContext - .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); - SharedPreferences.Editor editor = preferences.edit(); - editor.remove("language"); - editor.commit(); - - if (newLocale != null) { - LocaleInfo info = null; - if (newLocale.getLanguage() != null) { - info = languagesDict.get(newLocale.getLanguage()); - } - if (info == null) { - info = languagesDict.get(getLocaleString(newLocale)); - } - if (info == null) { - newLocale = Locale.US; - } - } - } - if (newLocale != null) { - if (localeInfo.pathToFile == null) { - localeValues.clear(); - } else if (!fromFile) { - localeValues = getLocaleFileStrings(new File(localeInfo.pathToFile)); - } - currentLocale = newLocale; - currentLocaleInfo = localeInfo; - currentPluralRules = allRules.get(currentLocale.getLanguage()); - if (currentPluralRules == null) { - currentPluralRules = allRules.get("en"); - } - changingConfiguration = true; - Locale locale = Gallery.applicationContext.getResources().getConfiguration().locale; - if (TextUtils.equals(locale.getLanguage(), "zh")) { - currentLocale = locale; - } - Locale.setDefault(currentLocale); - Configuration config = new Configuration(); - config.locale = currentLocale; - Gallery.applicationContext.getResources().updateConfiguration(config, - Gallery.applicationContext.getResources().getDisplayMetrics()); - changingConfiguration = false; - } - } catch (Exception e) { - e.printStackTrace(); - changingConfiguration = false; - } - } - - private String getStringInternal(String key, int res) { - String value = localeValues.get(key); - if (value == null) { - try { - value = Gallery.applicationContext.getString(res); - } catch (Exception e) { - e.printStackTrace(); - } - } - if (value == null) { - value = "LOC_ERR:" + key; - } - return value; - } - - public static String getString(String key, int res) { - return getInstance().getStringInternal(key, res); - } - - public static String formatPluralString(String key, int plural) { - if (key == null || key.length() == 0 || getInstance().currentPluralRules == null) { - return "LOC_ERR:" + key; - } - String param = getInstance() - .stringForQuantity(getInstance().currentPluralRules.quantityForNumber(plural)); - param = key + "_" + param; - int resourceId = Gallery.applicationContext.getResources().getIdentifier(param, - "string", Gallery.applicationContext.getPackageName()); - return formatString(param, resourceId, plural); - } - - public static String formatString(String key, int res, Object... args) { - try { - String value = getInstance().localeValues.get(key); - if (value == null) { - value = Gallery.applicationContext.getString(res); - } - - if (getInstance().currentLocale != null) { - return String.format(getInstance().currentLocale, value, args); - } else { - return String.format(value, args); - } - } catch (Exception e) { - e.printStackTrace(); - return "LOC_ERR: " + key; - } - } - - public static String formatStringSimple(String string, Object... args) { - try { - if (getInstance().currentLocale != null) { - return String.format(getInstance().currentLocale, string, args); - } else { - return String.format(string, args); - } - } catch (Exception e) { - e.printStackTrace(); - return "LOC_ERR: " + string; - } - } - - abstract public static class PluralRules { - abstract int quantityForNumber(int n); - } - - public static class PluralRules_Zero extends PluralRules { - public int quantityForNumber(int count) { - if (count == 0 || count == 1) { - return QUANTITY_ONE; - } else { - return QUANTITY_OTHER; - } - } - } - - public static class PluralRules_Welsh extends PluralRules { - public int quantityForNumber(int count) { - if (count == 0) { - return QUANTITY_ZERO; - } else if (count == 1) { - return QUANTITY_ONE; - } else if (count == 2) { - return QUANTITY_TWO; - } else if (count == 3) { - return QUANTITY_FEW; - } else if (count == 6) { - return QUANTITY_MANY; - } else { - return QUANTITY_OTHER; - } - } - } - - public static class PluralRules_Two extends PluralRules { - public int quantityForNumber(int count) { - if (count == 1) { - return QUANTITY_ONE; - } else if (count == 2) { - return QUANTITY_TWO; - } else { - return QUANTITY_OTHER; - } - } - } - - public static class PluralRules_Tachelhit extends PluralRules { - public int quantityForNumber(int count) { - if (count >= 0 && count <= 1) { - return QUANTITY_ONE; - } else if (count >= 2 && count <= 10) { - return QUANTITY_FEW; - } else { - return QUANTITY_OTHER; - } - } - } - - public static class PluralRules_Slovenian extends PluralRules { - public int quantityForNumber(int count) { - int rem100 = count % 100; - if (rem100 == 1) { - return QUANTITY_ONE; - } else if (rem100 == 2) { - return QUANTITY_TWO; - } else if (rem100 >= 3 && rem100 <= 4) { - return QUANTITY_FEW; - } else { - return QUANTITY_OTHER; - } - } - } - - public static class PluralRules_Romanian extends PluralRules { - public int quantityForNumber(int count) { - int rem100 = count % 100; - if (count == 1) { - return QUANTITY_ONE; - } else if ((count == 0 || (rem100 >= 1 && rem100 <= 19))) { - return QUANTITY_FEW; - } else { - return QUANTITY_OTHER; - } - } - } - - public static class PluralRules_Polish extends PluralRules { - public int quantityForNumber(int count) { - int rem100 = count % 100; - int rem10 = count % 10; - if (count == 1) { - return QUANTITY_ONE; - } else if (rem10 >= 2 && rem10 <= 4 && !(rem100 >= 12 && rem100 <= 14) - && !(rem100 >= 22 && rem100 <= 24)) { - return QUANTITY_FEW; - } else { - return QUANTITY_OTHER; - } - } - } - - public static class PluralRules_One extends PluralRules { - public int quantityForNumber(int count) { - return count == 1 ? QUANTITY_ONE : QUANTITY_OTHER; - } - } - - public static class PluralRules_None extends PluralRules { - public int quantityForNumber(int count) { - return QUANTITY_OTHER; - } - } - - public static class PluralRules_Maltese extends PluralRules { - public int quantityForNumber(int count) { - int rem100 = count % 100; - if (count == 1) { - return QUANTITY_ONE; - } else if (count == 0 || (rem100 >= 2 && rem100 <= 10)) { - return QUANTITY_FEW; - } else if (rem100 >= 11 && rem100 <= 19) { - return QUANTITY_MANY; - } else { - return QUANTITY_OTHER; - } - } - } - - public static class PluralRules_Macedonian extends PluralRules { - public int quantityForNumber(int count) { - if (count % 10 == 1 && count != 11) { - return QUANTITY_ONE; - } else { - return QUANTITY_OTHER; - } - } - } - - public static class PluralRules_Lithuanian extends PluralRules { - public int quantityForNumber(int count) { - int rem100 = count % 100; - int rem10 = count % 10; - if (rem10 == 1 && !(rem100 >= 11 && rem100 <= 19)) { - return QUANTITY_ONE; - } else if (rem10 >= 2 && rem10 <= 9 && !(rem100 >= 11 && rem100 <= 19)) { - return QUANTITY_FEW; - } else { - return QUANTITY_OTHER; - } - } - } - - public static class PluralRules_Latvian extends PluralRules { - public int quantityForNumber(int count) { - if (count == 0) { - return QUANTITY_ZERO; - } else if (count % 10 == 1 && count % 100 != 11) { - return QUANTITY_ONE; - } else { - return QUANTITY_OTHER; - } - } - } - - public static class PluralRules_Langi extends PluralRules { - public int quantityForNumber(int count) { - if (count == 0) { - return QUANTITY_ZERO; - } else if (count > 0 && count < 2) { - return QUANTITY_ONE; - } else { - return QUANTITY_OTHER; - } - } - } - - public static class PluralRules_French extends PluralRules { - public int quantityForNumber(int count) { - if (count >= 0 && count < 2) { - return QUANTITY_ONE; - } else { - return QUANTITY_OTHER; - } - } - } - - public static class PluralRules_Czech extends PluralRules { - public int quantityForNumber(int count) { - if (count == 1) { - return QUANTITY_ONE; - } else if (count >= 2 && count <= 4) { - return QUANTITY_FEW; - } else { - return QUANTITY_OTHER; - } - } - } - - public static class PluralRules_Breton extends PluralRules { - public int quantityForNumber(int count) { - if (count == 0) { - return QUANTITY_ZERO; - } else if (count == 1) { - return QUANTITY_ONE; - } else if (count == 2) { - return QUANTITY_TWO; - } else if (count == 3) { - return QUANTITY_FEW; - } else if (count == 6) { - return QUANTITY_MANY; - } else { - return QUANTITY_OTHER; - } - } - } - - public static class PluralRules_Balkan extends PluralRules { - public int quantityForNumber(int count) { - int rem100 = count % 100; - int rem10 = count % 10; - if (rem10 == 1 && rem100 != 11) { - return QUANTITY_ONE; - } else if (rem10 >= 2 && rem10 <= 4 && !(rem100 >= 12 && rem100 <= 14)) { - return QUANTITY_FEW; - } else if ((rem10 == 0 || (rem10 >= 5 && rem10 <= 9) - || (rem100 >= 11 && rem100 <= 14))) { - return QUANTITY_MANY; - } else { - return QUANTITY_OTHER; - } - } - } - - public static class PluralRules_Arabic extends PluralRules { - public int quantityForNumber(int count) { - int rem100 = count % 100; - if (count == 0) { - return QUANTITY_ZERO; - } else if (count == 1) { - return QUANTITY_ONE; - } else if (count == 2) { - return QUANTITY_TWO; - } else if (rem100 >= 3 && rem100 <= 10) { - return QUANTITY_FEW; - } else if (rem100 >= 11 && rem100 <= 99) { - return QUANTITY_MANY; - } else { - return QUANTITY_OTHER; - } - } - } -} diff --git a/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Utils/MediaController.java b/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Utils/MediaController.java index 31ddf2b..1663502 100644 --- a/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Utils/MediaController.java +++ b/telegramgallery/src/main/java/com/tangxiaolv/telegramgallery/Utils/MediaController.java @@ -592,8 +592,8 @@ public void run() { path, orientation, false); if (allPhotosAlbum == null) { - allPhotosAlbum = new AlbumEntry(0, LocaleController.getString( - "AllPhotos", R.string.AllPhotos), photoEntry, false); + allPhotosAlbum = new AlbumEntry(0, Gallery.applicationContext.getString( + R.string.AllPhotos), photoEntry, false); albumsSorted.add(0, allPhotosAlbum); } if (allPhotosAlbum != null) { @@ -668,8 +668,9 @@ public void run() { path, 0, true); if (allVideosAlbum == null) { - allVideosAlbum = new AlbumEntry(0, LocaleController.getString( - "AllVideo", R.string.AllVideo), photoEntry, true); + + allVideosAlbum = new AlbumEntry(0, Gallery.applicationContext.getString + (R.string.AllVideo), photoEntry, true); videoAlbumsSorted.add(0, allVideosAlbum); } if (allVideosAlbum != null) { From 67ef7861443b10a22c6965b84aed24ef8fe8bab9 Mon Sep 17 00:00:00 2001 From: Bartosz J Date: Wed, 7 Dec 2016 14:32:26 +0100 Subject: [PATCH 3/3] Set English strings as a default language Add Polish Language --- .../src/main/res/values-en/strings.xml | 33 --------------- .../src/main/res/values-pl/strings.xml | 33 +++++++++++++++ .../src/main/res/values-zh/strings.xml | 21 ++++++++++ .../src/main/res/values/strings.xml | 40 ++++++++++--------- 4 files changed, 76 insertions(+), 51 deletions(-) delete mode 100644 telegramgallery/src/main/res/values-en/strings.xml create mode 100644 telegramgallery/src/main/res/values-pl/strings.xml create mode 100644 telegramgallery/src/main/res/values-zh/strings.xml diff --git a/telegramgallery/src/main/res/values-en/strings.xml b/telegramgallery/src/main/res/values-en/strings.xml deleted file mode 100644 index 51a34fb..0000000 --- a/telegramgallery/src/main/res/values-en/strings.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - Photos - Video - All Photos - All Videos - No photos yet - No videos yet - FIND IMAGES - FIND GIFS - No recent photos - No recent GIFs - No results - CROP - Photo - %1$d of %2$d - Set - Album - - Clear search history? - Clear - - Search web - Search GIFs - - WEB SEARCH - You can select up to %d pictures - - finish - Cancel - Preview - album read fail,please check permission - \ No newline at end of file diff --git a/telegramgallery/src/main/res/values-pl/strings.xml b/telegramgallery/src/main/res/values-pl/strings.xml new file mode 100644 index 0000000..576eca3 --- /dev/null +++ b/telegramgallery/src/main/res/values-pl/strings.xml @@ -0,0 +1,33 @@ + + + Zdjęcia + Filmy + Wszystkie zdjęcia + Wszystkie filmy + Brak zdjęć + Brak filmów + ZNAJDŹ ZDJĘCIA + ZNAJDŹ GIFY + Brak ostatnich zdjęć + Brak osatnich GIFów + Brak wyników + PRZYTNIJ + Zdjęcie + %1$d z %2$d + Zbiór + Album + + Wyczyścić historię wyszukiwania? + Wyczyść + + Przeszukaj sieć + Szukaj GIFów + + SZUKAJ W SIECI + Możesz wybrać do %d zdjęć + + Akceptuj + Anuluj + Podgląd + Bład odczytu, sprawdź uprawnienia + \ No newline at end of file diff --git a/telegramgallery/src/main/res/values-zh/strings.xml b/telegramgallery/src/main/res/values-zh/strings.xml new file mode 100644 index 0000000..3342390 --- /dev/null +++ b/telegramgallery/src/main/res/values-zh/strings.xml @@ -0,0 +1,21 @@ + + + 图片 + 视频 + 所有图片 + 所有视频 + 还没有图片 + 还没有视频 + 剪切 + 图片 + %1$d / %2$d + 设置 + 相册 + + 你最多只能选择%d张图片 + + 完成 + 取消 + 预览 + 相册读取失败,请检查权限 + diff --git a/telegramgallery/src/main/res/values/strings.xml b/telegramgallery/src/main/res/values/strings.xml index a00c90a..554db60 100644 --- a/telegramgallery/src/main/res/values/strings.xml +++ b/telegramgallery/src/main/res/values/strings.xml @@ -1,31 +1,35 @@ + - TelegramGallery + TelegramGallery - 图片 - 视频 - 所有图片 - 所有视频 - 还没有图片 - 还没有视频 + Photos + Video + All Photos + All Videos + No photos yet + No videos yet FIND IMAGES FIND GIFS No recent photos No recent GIFs No results - 剪切 - 图片 - %1$d / %2$d - 设置 - 相册 + CROP + Photo + %1$d of %2$d + Set + Album Clear search history? Clear + Search web + Search GIFs + WEB SEARCH - 你最多只能选择%d张图片 + You can select up to %d pictures - 完成 - 取消 - 预览 - 相册读取失败,请检查权限 - + Accept + Cancel + Preview + Failed to read an album, please check permissions + \ No newline at end of file