Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove in-app language pref #21542

Merged
merged 15 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -949,8 +949,7 @@ class AppInitializer @Inject constructor(
*/
private inner class MemoryAndConfigChangeMonitor : ComponentCallbacks2 {
override fun onConfigurationChanged(newConfig: Configuration) {
// Make sure the in-app locale is correct
perAppLocaleManager.checkAndUpdateOldLanguagePrefKey()
// Do nothing
}

override fun onLowMemory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import org.wordpress.android.localcontentmigration.LocalContentEntityData.UserFl
import org.wordpress.android.ui.prefs.AppPrefs.DeletablePrefKey
import org.wordpress.android.ui.prefs.AppPrefs.UndeletablePrefKey
import org.wordpress.android.ui.prefs.AppPrefsWrapper
import org.wordpress.android.util.LocaleManagerWrapper
import org.wordpress.android.viewmodel.ContextProvider
import javax.inject.Inject

class UserFlagsProviderHelper @Inject constructor(
private val appPrefsWrapper: AppPrefsWrapper,
contextProvider: ContextProvider,
localeManagerWrapper: LocaleManagerWrapper
) : LocalDataProviderHelper {
override fun getData(localEntityId: Int?): LocalContentEntityData =
UserFlagsData(
Expand Down Expand Up @@ -73,6 +71,5 @@ class UserFlagsProviderHelper @Inject constructor(
contextProvider.getContext().getString(R.string.pref_key_app_theme),
contextProvider.getContext().getString(R.string.pref_key_initial_screen),
contextProvider.getContext().getString(R.string.pref_key_send_crash),
localeManagerWrapper.getLocalePrefKeyString()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ private void getNoteFromNoteId(String noteId, RestRequest.Listener listener,
}

HashMap<String, String> params = new HashMap<>();
params.put("locale", LocaleManager.getLanguage(mContext));
params.put("locale", LocaleManager.getLanguage());
WordPress.getRestClientUtils().getNotification(params, noteId, listener, errorListener);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineDispatcher
import org.wordpress.android.modules.BG_THREAD
import org.wordpress.android.ui.mysite.SelectedSiteRepository
import org.wordpress.android.util.LocaleManagerWrapper
import org.wordpress.android.viewmodel.ScopedViewModel
import javax.inject.Inject
import javax.inject.Named
Expand All @@ -20,7 +19,6 @@ class PersonalizationViewModel @Inject constructor(
private val selectedSiteRepository: SelectedSiteRepository,
private val shortcutsPersonalizationViewModelSlice: ShortcutsPersonalizationViewModelSlice,
private val dashboardCardPersonalizationViewModelSlice: DashboardCardPersonalizationViewModelSlice,
private val localeManagerWrapper: LocaleManagerWrapper
) : ScopedViewModel(bgDispatcher) {
val uiState = dashboardCardPersonalizationViewModelSlice.uiState
val shortcutsState = shortcutsPersonalizationViewModelSlice.uiState
Expand All @@ -32,7 +30,6 @@ class PersonalizationViewModel @Inject constructor(
val appLanguage = _appLanguage as LiveData<String>

init {
emitLanguageRefreshIfNeeded(localeManagerWrapper.getLanguage())
shortcutsPersonalizationViewModelSlice.initialize(viewModelScope)
dashboardCardPersonalizationViewModelSlice.initialize(viewModelScope)
}
Expand Down Expand Up @@ -67,13 +64,4 @@ class PersonalizationViewModel @Inject constructor(
val siteId = selectedSiteRepository.getSelectedSite()!!.siteId
shortcutsPersonalizationViewModelSlice.addShortcut(shortcutState,siteId)
}

private fun emitLanguageRefreshIfNeeded(languageCode: String) {
if (languageCode.isNotEmpty()) {
val shouldEmitLanguageRefresh = !localeManagerWrapper.isSameLanguage(languageCode)
if (shouldEmitLanguageRefresh) {
_appLanguage.value = languageCode
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.app.job.JobParameters;
import android.app.job.JobService;
import android.content.Context;

import org.wordpress.android.ui.notifications.NotificationsListFragment;
import org.wordpress.android.util.AppLog;
Expand All @@ -14,11 +13,6 @@ public class NotificationsUpdateJobService extends JobService
implements NotificationsUpdateLogic.ServiceCompletionListener {
private NotificationsUpdateLogic mNotificationsUpdateLogic;

@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(LocaleManager.setLocale(newBase));
}

@Override
public boolean onStartJob(JobParameters params) {
String noteId = null;
Expand All @@ -42,7 +36,7 @@ public boolean onStopJob(JobParameters params) {
public void onCreate() {
super.onCreate();
AppLog.i(AppLog.T.NOTIFS, "notifications update job service > created");
mNotificationsUpdateLogic = new NotificationsUpdateLogic(LocaleManager.getLanguage(this), this);
mNotificationsUpdateLogic = new NotificationsUpdateLogic(LocaleManager.getLanguage(), this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.wordpress.android.ui.notifications.services;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;

Expand All @@ -14,11 +13,6 @@
public class NotificationsUpdateService extends Service implements NotificationsUpdateLogic.ServiceCompletionListener {
private NotificationsUpdateLogic mNotificationsUpdateLogic;

@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(LocaleManager.setLocale(newBase));
}

@Override
public IBinder onBind(Intent intent) {
return null;
Expand All @@ -28,7 +22,7 @@ public IBinder onBind(Intent intent) {
public void onCreate() {
super.onCreate();
AppLog.i(AppLog.T.NOTIFS, "notifications update service > created");
mNotificationsUpdateLogic = new NotificationsUpdateLogic(LocaleManager.getLanguage(this), this);
mNotificationsUpdateLogic = new NotificationsUpdateLogic(LocaleManager.getLanguage(), this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2571,7 +2571,7 @@ class EditPostActivity : AppCompatActivity(), EditorFragmentActivity, EditorImag
get() {
val postType = if (isPage) "page" else "post"
val featuredImageId = editPostRepository.featuredImageId.toInt()
val languageString = LocaleManager.getLanguage(this@EditPostActivity)
val languageString = LocaleManager.getLanguage()
val wpcomLocaleSlug = languageString.replace("_", "-").lowercase()

// this.mIsXPostsCapable may return true for non-WP.com sites, but the app only supports xPosts for P2-based
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ class AppPrefsWrapper @Inject constructor(val buildConfigWrapper: BuildConfigWra
return AppPrefs.prefs().getString(key, defValue)
}

fun setPrefString(key: String, value: String) {
AppPrefs.prefs().edit().putString(key, value).apply()
fun removePref(key: String) {
AppPrefs.prefs().edit().remove(key).apply()
}

fun getDebugBooleanPref(key: String, default: Boolean = false) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
mLanguagePreference = (WPPreference) findPreference(getString(R.string.pref_key_language));
mLanguagePreference.setOnPreferenceChangeListener(this);
mLanguagePreference.setOnPreferenceClickListener(this);
mLanguagePreference.setSummary(mPerAppLocaleManager.getCurrentLocaleDisplayName());
mLanguagePreference.setSummary(PerAppLocaleManager.Companion.getCurrentLocaleDisplayName());

return view;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class ReaderInterestsFragment : Fragment(R.layout.reader_interests_fragment_layo
}

viewModel.start(
LocaleManager.getLanguage(WordPress.getContext()),
LocaleManager.getLanguage(),
parentViewModel,
entryPoint
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.wordpress.android.ui.reader.services.discover

import android.app.job.JobParameters
import android.app.job.JobService
import android.content.Context
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
Expand All @@ -12,7 +11,6 @@ import org.wordpress.android.ui.reader.services.ServiceCompletionListener
import org.wordpress.android.ui.reader.services.discover.ReaderDiscoverLogic.DiscoverTasks
import org.wordpress.android.util.AppLog
import org.wordpress.android.util.AppLog.T.READER
import org.wordpress.android.util.LocaleManager
import javax.inject.Inject
import javax.inject.Named
import kotlin.coroutines.CoroutineContext
Expand All @@ -31,10 +29,6 @@ class ReaderDiscoverJobService : JobService(), ServiceCompletionListener, Corout
override val coroutineContext: CoroutineContext
get() = ioDispatcher + job

override fun attachBaseContext(newBase: Context) {
super.attachBaseContext(LocaleManager.setLocale(newBase))
}

override fun onStartJob(params: JobParameters): Boolean {
AppLog.i(READER, "reader discover job service > started")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.wordpress.android.ui.reader.services.discover

import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.IBinder
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -14,7 +13,6 @@ import org.wordpress.android.ui.reader.services.discover.ReaderDiscoverLogic.Dis
import org.wordpress.android.ui.reader.services.discover.ReaderDiscoverServiceStarter.ARG_DISCOVER_TASK
import org.wordpress.android.util.AppLog
import org.wordpress.android.util.AppLog.T.READER
import org.wordpress.android.util.LocaleManager
import org.wordpress.android.util.extensions.getSerializableExtraCompat
import javax.inject.Inject
import javax.inject.Named
Expand All @@ -41,10 +39,6 @@ class ReaderDiscoverService : Service(), ServiceCompletionListener, CoroutineSco
return null
}

override fun attachBaseContext(newBase: Context) {
super.attachBaseContext(LocaleManager.setLocale(newBase))
}

override fun onCreate() {
super.onCreate()
AppLog.i(READER, "reader discover service > created")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import android.app.job.JobParameters;
import android.app.job.JobService;
import android.content.Context;

import org.wordpress.android.WordPress;
import org.wordpress.android.ui.reader.services.ServiceCompletionListener;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.LocaleManager;

import java.util.EnumSet;

Expand All @@ -16,11 +14,6 @@
public class ReaderUpdateJobService extends JobService implements ServiceCompletionListener {
private ReaderUpdateLogic mReaderUpdateLogic;

@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(LocaleManager.setLocale(newBase));
}

@Override
public boolean onStartJob(JobParameters params) {
AppLog.i(AppLog.T.READER, "reader job service > started");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public enum UpdateTask {
public ReaderUpdateLogic(Context context, WordPress app, ServiceCompletionListener listener) {
mCompletionListener = listener;
app.component().inject(this);
mLanguage = LocaleManager.getLanguage(app);
mLanguage = LocaleManager.getLanguage();
mContext = context;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package org.wordpress.android.ui.reader.services.update;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;

import org.wordpress.android.WordPress;
import org.wordpress.android.ui.reader.services.ServiceCompletionListener;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.LocaleManager;

import java.util.EnumSet;

Expand All @@ -28,11 +26,6 @@ public IBinder onBind(Intent intent) {
return null;
}

@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(LocaleManager.setLocale(newBase));
}

@Override
public void onCreate() {
super.onCreate();
Expand Down
Loading
Loading