Make switching language working again
This commit is contained in:
parent
e4a5616298
commit
95d3551931
|
@ -37,7 +37,6 @@ import com.joanzapata.iconify.fonts.FontAwesomeModule;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.activities.AgreementActivity;
|
||||
import info.nightscout.androidaps.activities.HistoryBrowseActivity;
|
||||
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
|
||||
import info.nightscout.androidaps.activities.PreferencesActivity;
|
||||
|
@ -141,8 +140,6 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
|||
if (!SP.getBoolean(R.string.key_setupwizard_processed, false) || !SP.contains(R.string.key_units)) {
|
||||
Intent intent = new Intent(this, SetupWizardActivity.class);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
checkEula();
|
||||
}
|
||||
|
||||
AndroidPermission.notifyForStoragePermission(this);
|
||||
|
@ -234,16 +231,6 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
|||
}
|
||||
}
|
||||
|
||||
private void checkEula() {
|
||||
//SP.removeBoolean(R.string.key_i_understand);
|
||||
boolean IUnderstand = SP.getBoolean(R.string.key_i_understand, false);
|
||||
if (!IUnderstand) {
|
||||
Intent intent = new Intent(getApplicationContext(), AgreementActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
private void doMigrations() {
|
||||
|
||||
// guarantee that the unreachable threshold is at least 30 and of type String
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
package info.nightscout.androidaps.activities;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
|
||||
import info.nightscout.androidaps.MainActivity;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
public class AgreementActivity extends NoSplashActivity {
|
||||
boolean IUnderstand;
|
||||
CheckBox agreeCheckBox;
|
||||
Button saveButton;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_agreement);
|
||||
IUnderstand = SP.getBoolean(R.string.key_i_understand, false);
|
||||
setContentView(R.layout.activity_agreement);
|
||||
agreeCheckBox = (CheckBox)findViewById(R.id.agreementCheckBox);
|
||||
agreeCheckBox.setChecked(IUnderstand);
|
||||
saveButton = (Button)findViewById(R.id.agreementSaveButton);
|
||||
addListenerOnButton();
|
||||
}
|
||||
|
||||
public void addListenerOnButton() {
|
||||
saveButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
|
||||
SP.putBoolean(R.string.key_i_understand, agreeCheckBox.isChecked());
|
||||
|
||||
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package info.nightscout.androidaps.activities
|
||||
|
||||
import android.app.Activity
|
||||
import android.os.Bundle
|
||||
|
||||
import info.nightscout.androidaps.R
|
||||
|
||||
open class NoSplashActivity : Activity() {
|
||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||
setTheme(R.style.AppTheme_NoActionBar)
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
}
|
|
@ -1,12 +1,18 @@
|
|||
package info.nightscout.androidaps.activities
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.utils.LocaleHelper
|
||||
|
||||
open class NoSplashAppCompatActivity : AppCompatActivity() {
|
||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||
setTheme(R.style.AppTheme_NoActionBar)
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
public override fun attachBaseContext(newBase: Context) {
|
||||
super.attachBaseContext(LocaleHelper.wrap(newBase))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package info.nightscout.androidaps.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.EditTextPreference;
|
||||
|
@ -47,6 +48,7 @@ import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref0Plugin;
|
|||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin;
|
||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin;
|
||||
import info.nightscout.androidaps.plugins.source.SourceDexcomPlugin;
|
||||
import info.nightscout.androidaps.utils.LocaleHelper;
|
||||
import info.nightscout.androidaps.utils.OKDialog;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import info.nightscout.androidaps.utils.SafeParse;
|
||||
|
@ -66,6 +68,11 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
|||
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachBaseContext(Context newBase) {
|
||||
super.attachBaseContext(LocaleHelper.INSTANCE.wrap(newBase));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
RxBus.INSTANCE.send(new EventPreferenceChange(key));
|
||||
|
|
|
@ -54,7 +54,7 @@ import info.nightscout.androidaps.utils.SafeParse;
|
|||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
|
||||
public class TDDStatsActivity extends NoSplashActivity {
|
||||
public class TDDStatsActivity extends NoSplashAppCompatActivity {
|
||||
private static Logger log = LoggerFactory.getLogger(TDDStatsActivity.class);
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
|
|
|
@ -6,11 +6,11 @@ import android.widget.CheckBox
|
|||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.activities.NoSplashActivity
|
||||
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
|
||||
import info.nightscout.androidaps.logging.L
|
||||
import kotlinx.android.synthetic.main.activity_logsetting.*
|
||||
|
||||
class LogSettingActivity : NoSplashActivity() {
|
||||
class LogSettingActivity : NoSplashAppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
|
|
@ -3,9 +3,9 @@ package info.nightscout.androidaps.plugins.general.tidepool.events
|
|||
import info.nightscout.androidaps.events.Event
|
||||
import info.nightscout.androidaps.logging.L
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.LocaleHelper
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
class EventTidepoolStatus(val status: String) : Event() {
|
||||
private val log = LoggerFactory.getLogger(L.TIDEPOOL)
|
||||
|
@ -17,7 +17,7 @@ class EventTidepoolStatus(val status: String) : Event() {
|
|||
log.debug("New status: $status")
|
||||
}
|
||||
|
||||
private var timeFormat = SimpleDateFormat("HH:mm:ss", LocaleHelper.currentLocale())
|
||||
private var timeFormat = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
|
||||
|
||||
fun toPreparedHtml(): StringBuilder {
|
||||
val stringBuilder = StringBuilder()
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.List;
|
|||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.activities.NoSplashActivity;
|
||||
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||
|
@ -44,7 +44,7 @@ import info.nightscout.androidaps.utils.FabricPrivacy;
|
|||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
|
||||
public class DanaRHistoryActivity extends NoSplashActivity {
|
||||
public class DanaRHistoryActivity extends NoSplashAppCompatActivity {
|
||||
private static Logger log = LoggerFactory.getLogger(L.PUMP);
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
|
|
|
@ -12,9 +12,8 @@ import org.slf4j.LoggerFactory;
|
|||
import java.text.DecimalFormat;
|
||||
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.activities.NoSplashActivity;
|
||||
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
|
||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
|
@ -33,7 +32,7 @@ import io.reactivex.disposables.CompositeDisposable;
|
|||
* Created by Rumen Georgiev on 5/31/2018.
|
||||
*/
|
||||
|
||||
public class DanaRUserOptionsActivity extends NoSplashActivity {
|
||||
public class DanaRUserOptionsActivity extends NoSplashAppCompatActivity {
|
||||
private static Logger log = LoggerFactory.getLogger(L.PUMP);
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
|
|
|
@ -20,13 +20,13 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.activities.NoSplashActivity;
|
||||
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntryGroup;
|
||||
|
||||
public class MedtronicHistoryActivity extends NoSplashActivity {
|
||||
public class MedtronicHistoryActivity extends NoSplashAppCompatActivity {
|
||||
|
||||
private static Logger LOG = LoggerFactory.getLogger(L.PUMP);
|
||||
|
||||
|
|
|
@ -1,21 +1,19 @@
|
|||
package info.nightscout.androidaps.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.os.Build
|
||||
import android.os.LocaleList
|
||||
import info.nightscout.androidaps.R
|
||||
import java.util.*
|
||||
|
||||
object LocaleHelper {
|
||||
fun update(context: Context) =
|
||||
updateResources(context, currentLanguage())
|
||||
|
||||
object LocaleHelper {
|
||||
fun currentLanguage(): String =
|
||||
SP.getString(R.string.key_language, Locale.getDefault().language)
|
||||
|
||||
fun currentLocale(): Locale =
|
||||
Locale(SP.getString(R.string.key_language, Locale.getDefault().language))
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
private fun updateResources(context: Context, language: String) {
|
||||
private fun currentLocale(): Locale {
|
||||
val language = currentLanguage()
|
||||
var locale = Locale(language)
|
||||
if (language.contains("_")) {
|
||||
// language with country like pt_BR defined in arrays.xml
|
||||
|
@ -23,10 +21,35 @@ object LocaleHelper {
|
|||
val country = language.substring(3, 5)
|
||||
locale = Locale(lang, country)
|
||||
}
|
||||
return locale
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
fun update(context: Context) {
|
||||
val locale = currentLocale()
|
||||
Locale.setDefault(locale)
|
||||
val resources = context.resources
|
||||
resources.configuration.setLocale(locale)
|
||||
resources.updateConfiguration(resources.configuration, resources.displayMetrics)
|
||||
val configuration = resources.configuration
|
||||
context.createConfigurationContext(configuration)
|
||||
configuration.setLocale(locale)
|
||||
configuration.locale = locale
|
||||
resources.updateConfiguration(configuration, resources.displayMetrics)
|
||||
}
|
||||
|
||||
fun wrap(ctx: Context): ContextWrapper {
|
||||
val res = ctx.resources
|
||||
val configuration = res.configuration
|
||||
val newLocale = currentLocale()
|
||||
val context = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
configuration.setLocale(newLocale)
|
||||
val localeList = LocaleList(newLocale)
|
||||
LocaleList.setDefault(localeList)
|
||||
configuration.locales = localeList
|
||||
ctx.createConfigurationContext(configuration)
|
||||
} else {
|
||||
configuration.setLocale(newLocale)
|
||||
ctx.createConfigurationContext(configuration)
|
||||
}
|
||||
return ContextWrapper(context)
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
tools:context="info.nightscout.androidaps.activities.AgreementActivity">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="fill_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
|
||||
<TextView
|
||||
android:text="@string/end_user_license_agreement"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:text="@string/app_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dp"
|
||||
android:textSize="11sp" />
|
||||
|
||||
<TextView
|
||||
android:text="@string/end_user_license_agreement_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dp"
|
||||
android:textSize="11sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
<CheckBox
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/end_user_license_agreement_i_understand"
|
||||
android:id="@+id/agreementCheckBox"
|
||||
android:checked="false" />
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/save"
|
||||
android:id="@+id/agreementSaveButton"
|
||||
android:layout_marginTop="20dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
</RelativeLayout>
|
Loading…
Reference in a new issue