Skip to content

Commit 2c17133

Browse files
committed
Build 34
1 parent 61d0ad2 commit 2c17133

14 files changed

Lines changed: 298 additions & 59 deletions

File tree

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ android {
3636
applicationId "uk.openvk.android.refresh"
3737
minSdk 21
3838
targetSdk 33
39-
versionCode 33
40-
versionName "0.9.33.alpha"
39+
versionCode 34
40+
versionName "0.9.34.alpha"
4141
}
4242

4343
buildTypes {

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
android:supportsRtl="true"
2525
android:usesCleartextTraffic="true"
2626
android:theme="@style/ApplicationTheme.SplashTheme"
27-
tools:targetApi="m"
28-
android:requestLegacyExternalStorage="true">
27+
tools:targetApi="tiramisu"
28+
android:requestLegacyExternalStorage="true"
29+
android:localeConfig="@xml/locales">
2930
<receiver android:name=".longpoll_api.receivers.LongPollReceiver"
3031
android:exported="true"
3132
android:permission="GET_LONGPOLL_NOTIFICATIONS">

app/src/main/java/uk/openvk/android/refresh/Global.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package uk.openvk.android.refresh;
22

3+
import android.app.LocaleManager;
34
import android.content.Context;
45
import android.content.Intent;
56
import android.content.SharedPreferences;
@@ -14,8 +15,10 @@
1415

1516
import androidx.annotation.ColorInt;
1617
import androidx.appcompat.app.AppCompatActivity;
18+
import androidx.appcompat.app.AppCompatDelegate;
1719
import androidx.core.content.res.ResourcesCompat;
1820
import androidx.core.graphics.TypefaceCompat;
21+
import androidx.core.os.LocaleListCompat;
1922
import androidx.core.view.WindowInsetsControllerCompat;
2023
import androidx.preference.PreferenceManager;
2124

@@ -34,6 +37,7 @@
3437
import uk.openvk.android.refresh.api.Account;
3538
import uk.openvk.android.refresh.api.models.OvkLink;
3639
import uk.openvk.android.refresh.api.models.WallPost;
40+
import uk.openvk.android.refresh.ui.core.activities.AppActivity;
3741
import uk.openvk.android.refresh.ui.core.activities.WallPostActivity;
3842

3943
public class Global {
@@ -361,4 +365,12 @@ public static ColorStateList getMonetRippleColorList(
361365
}
362366
return new ColorStateList(states, colors);
363367
}
368+
369+
public static void setPerAppLanguage(Context ctx) {
370+
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
371+
LocaleManager localeManager =
372+
(LocaleManager) ctx.getSystemService(Context.LOCALE_SERVICE);
373+
AppCompatDelegate.setApplicationLocales(OvkApplication.getLocaleList(ctx));
374+
}
375+
}
364376
}

app/src/main/java/uk/openvk/android/refresh/OvkApplication.java

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package uk.openvk.android.refresh;
22

33
import android.app.Application;
4+
import android.app.LocaleManager;
45
import android.content.Context;
56
import android.content.SharedPreferences;
67
import android.content.res.Configuration;
78
import android.os.Build;
9+
import android.os.LocaleList;
810
import android.preference.PreferenceManager;
9-
import android.util.Log;
1011

12+
import androidx.annotation.RequiresApi;
1113
import androidx.appcompat.app.AppCompatDelegate;
14+
import androidx.core.os.LocaleListCompat;
1215

1316
import com.kieronquinn.monetcompat.core.MonetCompat;
1417

@@ -91,22 +94,53 @@ public static Locale getLocale(Context ctx) {
9194
SharedPreferences global_prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
9295
String language = global_prefs.getString("ui_language", "System");
9396
String language_code = "en";
94-
if(language.equals("English")) {
95-
language_code = "en";
96-
} else if(language.equals("Русский")) {
97-
language_code = "ru";
98-
// } else if(language.equals("Украïнська")) {
99-
// language_code = "uk"; (later)
100-
} else {
101-
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
102-
language_code = ctx.getResources().getConfiguration().getLocales().get(0).getLanguage();
103-
} else {
104-
language_code = ctx.getResources().getConfiguration().locale.getLanguage();
105-
}
97+
switch (language) {
98+
case "English":
99+
language_code = "en";
100+
break;
101+
case "Русский":
102+
language_code = "ru";
103+
break;
104+
case "Украïнська":
105+
language_code = "uk";
106+
break;
107+
default:
108+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
109+
language_code = ctx.getResources().getConfiguration().getLocales().get(0).getLanguage();
110+
} else {
111+
language_code = ctx.getResources().getConfiguration().locale.getLanguage();
112+
}
113+
break;
106114
}
107115

108116

109117
return new Locale(language_code);
110118
}
111119

120+
@RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
121+
public static LocaleListCompat getLocaleList(Context ctx) {
122+
SharedPreferences global_prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
123+
LocaleList currentAppLocales =
124+
ctx.getSystemService(LocaleManager.class).getApplicationLocales();
125+
SharedPreferences.Editor editor = global_prefs.edit();
126+
if(currentAppLocales.toLanguageTags().startsWith("en")) {
127+
editor.putString("ui_language", "English");
128+
} else if(currentAppLocales.toLanguageTags().startsWith("ru")) {
129+
editor.putString("ui_language", "Russian");
130+
} else if(currentAppLocales.toLanguageTags().startsWith("uk")) {
131+
editor.putString("ui_language", "Украïнська");
132+
} else if(currentAppLocales.toLanguageTags().startsWith("und")) {
133+
editor.putString("ui_language", "System");
134+
}
135+
136+
editor.apply();
137+
if(!currentAppLocales.toLanguageTags().startsWith("und")) {
138+
return LocaleListCompat.wrap(
139+
new LocaleList(Locale.forLanguageTag(currentAppLocales.toLanguageTags())));
140+
} else {
141+
return LocaleListCompat.wrap(
142+
new LocaleList(ctx.getResources().getConfiguration().locale));
143+
}
144+
}
145+
112146
}

app/src/main/java/uk/openvk/android/refresh/ui/core/activities/AppActivity.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.annotation.SuppressLint;
44
import android.app.AlarmManager;
5+
import android.app.LocaleManager;
56
import android.app.Notification;
67
import android.app.PendingIntent;
78
import android.content.ComponentName;
@@ -34,6 +35,7 @@
3435
import androidx.appcompat.app.AppCompatDelegate;
3536
import androidx.appcompat.widget.AppCompatSpinner;
3637
import androidx.constraintlayout.widget.ConstraintLayout;
38+
import androidx.core.os.LocaleListCompat;
3739
import androidx.drawerlayout.widget.DrawerLayout;
3840
import androidx.fragment.app.Fragment;
3941
import androidx.fragment.app.FragmentManager;
@@ -158,6 +160,7 @@ protected void onCreate(Bundle savedInstanceState) {
158160
Global.setColorTheme(this, global_prefs.getString("theme_color", "blue"), getWindow());
159161
Global.setInterfaceFont(this);
160162
isDarkTheme = global_prefs.getBoolean("dark_theme", false);
163+
161164
notifMan = new NotificationManager(this, true, true, true, "");
162165
if (savedInstanceState == null) {
163166
Bundle extras = getIntent().getExtras();
@@ -176,6 +179,7 @@ protected void onCreate(Bundle savedInstanceState) {
176179
protected void attachBaseContext(Context newBase) {
177180
Locale languageType = OvkApplication.getLocale(newBase);
178181
super.attachBaseContext(LocaleContextWrapper.wrap(newBase, languageType));
182+
Global.setPerAppLanguage(this);
179183
}
180184

181185
private void createFragments() {
@@ -839,13 +843,15 @@ private void receiveState(int message, Bundle data) {
839843
|| message == HandlerMessages.WALL_AVATARS
840844
|| message == HandlerMessages.WALL_ATTACHMENTS) {
841845
if(selectedFragment == newsfeedFragment) {
842-
if(message == HandlerMessages.NEWSFEED_AVATARS) {
843-
newsfeedFragment.newsfeedAdapter.setAvatarLoadState(true);
844-
} else {
845-
newsfeedFragment.newsfeedAdapter.setPhotoLoadState(true);
846-
newsfeedFragment.disableLoadState();
846+
if(newsfeedFragment.newsfeedAdapter != null) {
847+
if (message == HandlerMessages.NEWSFEED_AVATARS) {
848+
newsfeedFragment.newsfeedAdapter.setAvatarLoadState(true);
849+
} else {
850+
newsfeedFragment.newsfeedAdapter.setPhotoLoadState(true);
851+
newsfeedFragment.disableLoadState();
852+
}
853+
newsfeedFragment.refreshAdapter();
847854
}
848-
newsfeedFragment.refreshAdapter();
849855
} else if(selectedFragment == profileFragment) {
850856
if(profileFragment.getWallAdapter() == null) {
851857
profileFragment.createWallAdapter(this, wall.getWallItems());
@@ -1163,7 +1169,7 @@ public void openCommunityPage(int position) {
11631169
}
11641170
}
11651171

1166-
private ServiceConnection lpConnection = new ServiceConnection() {
1172+
private final ServiceConnection lpConnection = new ServiceConnection() {
11671173
public void onServiceConnected(ComponentName className, IBinder service) {
11681174
LongPollService.LongPollBinder binder = (LongPollService.LongPollBinder) service;
11691175
longPollService = binder.getService();

app/src/main/java/uk/openvk/android/refresh/ui/core/fragments/app/MessagesFragment.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,26 +90,28 @@ public void onRefresh() {
9090

9191
@SuppressLint("NotifyDataSetChanged")
9292
public void createAdapter(Context ctx, ArrayList<Conversation> conversations, Account account) {
93-
this.conversations = conversations;
94-
conversationsView = (RecyclerView) view.findViewById(R.id.conversations_rv);
95-
if(conversationsAdapter == null) {
96-
conversationsAdapter = new ConversationsAdapter(requireActivity(), this.conversations,
97-
account);
98-
llm = new LinearLayoutManager(ctx);
99-
llm.setOrientation(LinearLayoutManager.VERTICAL);
100-
if(OvkApplication.isTablet) {
101-
glm = new GridLayoutManager(getContext(), 2);
102-
conversationsView.setLayoutManager(glm);
93+
if(view != null) {
94+
this.conversations = conversations;
95+
conversationsView = (RecyclerView) view.findViewById(R.id.conversations_rv);
96+
if (conversationsAdapter == null) {
97+
conversationsAdapter = new ConversationsAdapter(requireActivity(), this.conversations,
98+
account);
99+
llm = new LinearLayoutManager(ctx);
100+
llm.setOrientation(LinearLayoutManager.VERTICAL);
101+
if (OvkApplication.isTablet) {
102+
glm = new GridLayoutManager(getContext(), 2);
103+
conversationsView.setLayoutManager(glm);
104+
} else {
105+
conversationsView.setLayoutManager(llm);
106+
}
107+
conversationsView.setAdapter(conversationsAdapter);
103108
} else {
104-
conversationsView.setLayoutManager(llm);
109+
//conversationsAdapter.setArray(wallPosts);
110+
conversationsAdapter.notifyDataSetChanged();
105111
}
106-
conversationsView.setAdapter(conversationsAdapter);
107-
} else {
108-
//conversationsAdapter.setArray(wallPosts);
109-
conversationsAdapter.notifyDataSetChanged();
112+
((ProgressLayout) view.findViewById(R.id.progress_layout)).setVisibility(View.GONE);
113+
((SwipeRefreshLayout) view.findViewById(R.id.messages_swipe_layout)).setVisibility(View.VISIBLE);
110114
}
111-
((ProgressLayout) view.findViewById(R.id.progress_layout)).setVisibility(View.GONE);
112-
((SwipeRefreshLayout) view.findViewById(R.id.messages_swipe_layout)).setVisibility(View.VISIBLE);
113115
}
114116

115117
public void disableUpdateState() {
@@ -118,8 +120,10 @@ public void disableUpdateState() {
118120

119121
@SuppressLint("NotifyDataSetChanged")
120122
public void loadAvatars(ArrayList<Conversation> conversations) {
121-
Context ctx = requireContext();
122-
conversationsAdapter.notifyDataSetChanged();
123+
if(view != null) {
124+
Context ctx = requireContext();
125+
conversationsAdapter.notifyDataSetChanged();
126+
}
123127
}
124128

125129
@SuppressLint("NotifyDataSetChanged")

app/src/main/java/uk/openvk/android/refresh/ui/core/fragments/app/ProfileFragment.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ public void onRefresh() {
101101
}
102102

103103
public void setFriendsCount(int count) {
104-
((Button) header.findViewById(R.id.show_friends_btn))
105-
.setText(String.format(getResources().getStringArray(R.array.friends_count)[2], count));
104+
if(view != null) {
105+
((Button) header.findViewById(R.id.show_friends_btn))
106+
.setText(String.format(getResources().getStringArray(R.array.friends_count)[2], count));
107+
}
106108
}
107109

108110
// Setting ViewPagers with embedded fragments: WallFragment and AboutFragment

app/src/main/java/uk/openvk/android/refresh/ui/core/fragments/app/settings/MainSettingsFragment.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.os.Build;
99
import android.os.Bundle;
1010
import android.os.Handler;
11+
import android.provider.Settings;
1112
import android.text.Html;
1213
import android.text.method.LinkMovementMethod;
1314
import android.view.View;
@@ -87,8 +88,15 @@ public boolean onPreferenceClick(Preference preference) {
8788
assert ui_language != null;
8889
ui_language.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
8990
@Override
90-
public boolean onPreferenceClick(Preference preference) {
91-
showUiLanguageSelectionDialog();
91+
public boolean onPreferenceClick(@NonNull Preference preference) {
92+
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
93+
Intent intent = new Intent(Settings.ACTION_APP_LOCALE_SETTINGS);
94+
Uri uri = Uri.fromParts("package", requireContext().getPackageName(), null);
95+
intent.setData(uri);
96+
startActivity(intent);
97+
} else {
98+
showUiLanguageSelectionDialog();
99+
}
92100
return false;
93101
}
94102
});
@@ -140,7 +148,7 @@ private void showUiLanguageSelectionDialog() {
140148
case "Русский":
141149
valuePos = 2;
142150
break;
143-
case "Українська":
151+
case "Украïнська":
144152
valuePos = 3;
145153
break;
146154
}
@@ -167,7 +175,7 @@ public void onMenuItemClicked(String[] list, int which) {
167175
} else if(which == 2) {
168176
editor.putString("ui_language", "Русский");
169177
} else if(which == 3) {
170-
editor.putString("ui_language", "Українська");
178+
editor.putString("ui_language", "Украïнська");
171179
}
172180
editor.apply();
173181
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<string name="date_at">в</string>
4343

4444
<string name="online">Онлайн</string>
45-
<string name="offline">Оффлайн</string>
45+
<string name="offline">Не в сети</string>
4646
<string name="last_seen_profile_m">был в сети %s</string>
4747
<string name="last_seen_profile_f">была в сети %s</string>
4848
<string name="date_just_now">только что</string>

0 commit comments

Comments
 (0)