Compare commits

..

15 Commits

Author SHA1 Message Date
Torsten Grote
5e7b4b762e WIP: Lock down NavDrawerActivity 2021-02-18 15:33:04 -03:00
Sebastian Kürten
2397b7f5a2 Remove SIGN_OUT_URI 2021-02-18 14:09:35 +01:00
Sebastian Kürten
5ec80adfe8 Implement signout after language change via view model event 2021-02-18 14:07:29 +01:00
Sebastian Kürten
a56935bc3d Move simulation of slowness into LifecycleManager 2021-02-18 13:27:39 +01:00
Sebastian Kürten
edd76266a9 Simulate slow device, sleep 5 sec after shutdown 2021-02-18 13:27:38 +01:00
akwizgran
f36f1cf3d4 Merge branch '1764-fix-change-app-language-does-not-work' into 'master'
Resolve "Change app language does not work"

Closes #1764

See merge request briar/briar!1367
2021-02-17 16:59:59 +00:00
Torsten Grote
7d6a63d866 Merge branch '1934-upgrade-obfs4proxy' into 'master'
Upgrade obfs4proxy to 0.0.12-dev

Closes #1934

See merge request briar/briar!1372
2021-02-17 16:58:22 +00:00
akwizgran
15ebdf8dd5 Upgrade obfs4proxy to 0.0.12-dev. 2021-02-17 16:41:49 +00:00
akwizgran
db2c235283 Merge branch 'private-group-disabled' into 'master'
Fix disabled groups after screen rotation

See merge request briar/briar!1371
2021-02-17 14:09:57 +00:00
Sebastian Kürten
e5bd43469e Add Javados to Localizer#setLocale() 2021-02-15 14:54:20 +01:00
Torsten Grote
9366c184d8 Fix disabled groups after screen rotation
isDissolved was reverted to LiveData that only shows a dialog when the activity was first opened
2021-02-15 09:55:59 -03:00
Sebastian Kürten
73d2c964d4 Make language switching for robust 2021-02-15 12:31:51 +01:00
Torsten Grote
a04b512497 Merge branch 'tor-0.3.5.13' into 'master'
Upgrade Tor to 0.3.5.13

Closes #1922

See merge request briar/briar!1363
2021-02-09 12:15:45 +00:00
akwizgran
3d9515e308 Also upgrade obfs4proxy and bramble-java's Tor. 2021-02-09 12:05:54 +00:00
Torsten Grote
cb859e998d Upgrade Tor to 0.3.5.13 2021-02-08 15:44:35 -03:00
23 changed files with 152 additions and 190 deletions

View File

@@ -38,8 +38,8 @@ configurations {
dependencies {
implementation project(path: ':bramble-core', configuration: 'default')
tor 'org.briarproject:tor-android:0.3.5.12@zip'
tor 'org.briarproject:obfs4proxy-android:0.0.11-2@zip'
tor 'org.briarproject:tor-android:0.3.5.13@zip'
tor 'org.briarproject:obfs4proxy-android:0.0.12-dev-40245c4a@zip'
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'

View File

@@ -75,8 +75,8 @@ dependencyVerification {
'org.beanshell:bsh:1.3.0:bsh-1.3.0.jar:9b04edc75d19db54f1b4e8b5355e9364384c6cf71eb0a1b9724c159d779879f8',
'org.bouncycastle:bcpkix-jdk15on:1.56:bcpkix-jdk15on-1.56.jar:7043dee4e9e7175e93e0b36f45b1ec1ecb893c5f755667e8b916eb8dd201c6ca',
'org.bouncycastle:bcprov-jdk15on:1.56:bcprov-jdk15on-1.56.jar:963e1ee14f808ffb99897d848ddcdb28fa91ddda867eb18d303e82728f878349',
'org.briarproject:obfs4proxy-android:0.0.11-2:obfs4proxy-android-0.0.11-2.zip:57e55cbe87aa2aac210fdbb6cd8cdeafe15f825406a08ebf77a8b787aa2c6a8a',
'org.briarproject:tor-android:0.3.5.12:tor-android-0.3.5.12.zip:db71fb3290acff79d572af0752570eaf6aad7c4d88c9b9aa0b4d5afe2b9ead9c',
'org.briarproject:obfs4proxy-android:0.0.12-dev-40245c4a:obfs4proxy-android-0.0.12-dev-40245c4a.zip:8ab05a8f8391be2cb5ab2b665c281a06d9e3a756bd0f95a40a36ca927866ea82',
'org.briarproject:tor-android:0.3.5.13:tor-android-0.3.5.13.zip:e0978db136731dae07774b722970cdae1e462fb5adc82845dd80a7e2d87f356c',
'org.checkerframework:checker-compat-qual:2.5.3:checker-compat-qual-2.5.3.jar:d76b9afea61c7c082908023f0cbc1427fab9abd2df915c8b8a3e7a509bccbc6d',
'org.checkerframework:checker-qual:2.5.2:checker-qual-2.5.2.jar:64b02691c8b9d4e7700f8ee2e742dce7ea2c6e81e662b7522c9ee3bf568c040a',
'org.checkerframework:checker-qual:2.8.1:checker-qual-2.8.1.jar:9103499008bcecd4e948da29b17864abb64304e15706444ae209d17ebe0575df',

View File

@@ -179,6 +179,13 @@ class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
LOG.info("Stopping services");
state = STOPPING;
eventBus.broadcast(new LifecycleEvent(STOPPING));
LOG.info("Sleeping a bit to simulate slowness");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
LOG.info("Done simulating slowness");
for (Service s : services) {
long start = now();
s.stopService();

View File

@@ -16,8 +16,8 @@ dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')
implementation 'net.java.dev.jna:jna:4.5.2'
implementation 'net.java.dev.jna:jna-platform:4.5.2'
tor 'org.briarproject:tor:0.3.5.12@zip'
tor 'org.briarproject:obfs4proxy:0.0.7@zip'
tor 'org.briarproject:tor:0.3.5.13@zip'
tor 'org.briarproject:obfs4proxy:0.0.12-dev-40245c4a@zip'
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'

View File

@@ -23,8 +23,8 @@ dependencyVerification {
'org.apache.ant:ant-launcher:1.9.4:ant-launcher-1.9.4.jar:7bccea20b41801ca17bcbc909a78c835d0f443f12d639c77bd6ae3d05861608d',
'org.apache.ant:ant:1.9.4:ant-1.9.4.jar:649ae0730251de07b8913f49286d46bba7b92d47c5f332610aa426c4f02161d8',
'org.beanshell:bsh:1.3.0:bsh-1.3.0.jar:9b04edc75d19db54f1b4e8b5355e9364384c6cf71eb0a1b9724c159d779879f8',
'org.briarproject:obfs4proxy:0.0.7:obfs4proxy-0.0.7.zip:5b2f693262ce43a7e130f7cc7d5d1617925330640a2eb6d71085e95df8ee0642',
'org.briarproject:tor:0.3.5.12:tor-0.3.5.12.zip:2f542c4befd216f2226bf7c76e3b8b2d99af6f146a8cb28bf727f42014587006',
'org.briarproject:obfs4proxy:0.0.12-dev-40245c4a:obfs4proxy-0.0.12-dev-40245c4a.zip:172029e7058b3a83ac93ac4991a44bf76e16ce8d46f558f5836d57da3cb3a766',
'org.briarproject:tor:0.3.5.13:tor-0.3.5.13.zip:1c5f0b821ee2aadb0ea04aa96caab3ca0a08370cce8de81c2dfe04d172f8a2a0',
'org.checkerframework:checker-compat-qual:2.5.3:checker-compat-qual-2.5.3.jar:d76b9afea61c7c082908023f0cbc1427fab9abd2df915c8b8a3e7a509bccbc6d',
'org.checkerframework:checker-qual:2.5.2:checker-qual-2.5.2.jar:64b02691c8b9d4e7700f8ee2e742dce7ea2c6e81e662b7522c9ee3bf568c040a',
'org.codehaus.mojo:animal-sniffer-annotations:1.17:animal-sniffer-annotations-1.17.jar:92654f493ecfec52082e76354f0ebf87648dc3d5cec2e3c3cdb947c016747a53',

View File

@@ -117,22 +117,9 @@
<activity
android:name="org.briarproject.briar.android.navdrawer.NavDrawerActivity"
android:exported="false"
android:launchMode="singleTask"
android:theme="@style/BriarTheme.NoActionBar">
<intent-filter android:label="@string/add_contact_remotely_title_case">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="briar" />
</intent-filter>
<intent-filter android:label="@string/add_contact_remotely_title_case">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
android:theme="@style/BriarTheme.NoActionBar" />
<activity
android:name="org.briarproject.briar.android.conversation.ConversationActivity"
@@ -440,8 +427,27 @@
<activity
android:name=".android.contact.add.remote.AddContactActivity"
android:label="@string/add_contact_remotely_title_case"
android:parentActivityName="org.briarproject.briar.android.navdrawer.NavDrawerActivity"
android:theme="@style/BriarTheme"
android:windowSoftInputMode="adjustResize|stateHidden" />
android:windowSoftInputMode="adjustResize|stateHidden">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="org.briarproject.briar.android.navdrawer.NavDrawerActivity" />
<intent-filter android:label="@string/add_contact_remotely_title_case">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="briar" />
</intent-filter>
<intent-filter android:label="@string/add_contact_remotely_title_case">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<activity
android:name=".android.contact.add.remote.PendingContactListActivity"

View File

@@ -25,7 +25,7 @@ class BriarAccountManager extends AndroidAccountManager {
public void deleteAccount() {
synchronized (stateChangeLock) {
super.deleteAccount();
Localizer.reinitialize(appContext);
Localizer.reinitialize();
UiUtils.setTheme(appContext,
appContext.getString(R.string.pref_theme_light_value));
}

View File

@@ -579,7 +579,6 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
@UiThread
private void updateContactAddedNotification() {
if (contactAddedTotal == 0) return;
BriarNotificationBuilder b =
new BriarNotificationBuilder(appContext, CONTACT_CHANNEL_ID);
b.setSmallIcon(R.drawable.notification_contact_added);
@@ -714,16 +713,4 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
public void unblockAllBlogPostNotifications() {
androidExecutor.runOnUiThread((Runnable) () -> blockBlogs = false);
}
@Override
public void restartNotifications(boolean locked, boolean mayAlertAgain) {
androidExecutor.runOnUiThread(() -> {
updateForegroundNotification(locked);
updateContactNotification(mayAlertAgain);
updateBlogPostNotification(mayAlertAgain);
updateForumPostNotification(mayAlertAgain);
updateGroupMessageNotification(mayAlertAgain);
updateContactAddedNotification();
});
}
}

View File

@@ -51,6 +51,7 @@ public class BriarApplicationImpl extends Application
Localizer.initialize(prefs);
super.attachBaseContext(
Localizer.getInstance().setLocale(base));
Localizer.getInstance().setLocale(this);
setTheme(base, prefs);
}
@@ -81,7 +82,6 @@ public class BriarApplicationImpl extends Application
rootLogger.setLevel(IS_DEBUG_BUILD ? FINE : INFO);
LOG.info("Created");
Localizer.getInstance().setLocaleLegacy(this);
EmojiManager.install(new GoogleEmojiProvider());
}
@@ -105,9 +105,7 @@ public class BriarApplicationImpl extends Application
@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Localizer.getInstance().applicationConfigurationChanged(this, newConfig,
applicationComponent.androidNotificationManager(),
applicationComponent.lockManager().isLocked());
Localizer.getInstance().setLocale(this);
}
private void setTheme(Context ctx, SharedPreferences prefs) {

View File

@@ -170,6 +170,7 @@ public class BriarService extends Service {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(Localizer.getInstance().setLocale(base));
Localizer.getInstance().setLocale(this);
}
private void showStartupFailureNotification(StartResult result) {

View File

@@ -6,16 +6,12 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.briar.api.android.AndroidNotificationManager;
import java.util.Locale;
import javax.annotation.Nullable;
import androidx.core.text.TextUtilsCompat;
import static android.os.Build.VERSION.SDK_INT;
import static androidx.core.view.ViewCompat.LAYOUT_DIRECTION_LTR;
import static org.briarproject.briar.android.settings.SettingsFragment.LANGUAGE;
@NotNullByDefault
@@ -25,7 +21,6 @@ public class Localizer {
@Nullable
private static Localizer INSTANCE;
private final Locale systemLocale;
@Nullable
private final Locale locale;
private Localizer(SharedPreferences sharedPreferences) {
@@ -35,17 +30,10 @@ public class Localizer {
private Localizer(Locale systemLocale, @Nullable Locale userLocale) {
this.systemLocale = systemLocale;
locale = userLocale;
setLocaleAndSystemConfiguration(locale);
if (userLocale == null) locale = systemLocale;
else locale = userLocale;
}
private Localizer(Locale systemLocale) {
this.systemLocale = systemLocale;
locale = null;
setLocaleAndSystemConfiguration(systemLocale);
}
// Instantiate the Localizer.
public static synchronized void initialize(SharedPreferences prefs) {
if (INSTANCE == null)
@@ -53,11 +41,9 @@ public class Localizer {
}
// Reinstantiate the Localizer with the system locale
public static synchronized void reinitialize(Context appContext) {
if (INSTANCE != null && INSTANCE.locale != null) {
INSTANCE = new Localizer(INSTANCE.systemLocale);
INSTANCE.forceLocale(appContext, INSTANCE.systemLocale);
}
public static synchronized void reinitialize() {
if (INSTANCE != null)
INSTANCE = new Localizer(INSTANCE.systemLocale, null);
}
// Get the current instance.
@@ -78,98 +64,43 @@ public class Localizer {
if (tag.contains("-")) {
String[] langArray = tag.split("-");
return new Locale(langArray[0], langArray[1]);
} else {
} else
return new Locale(tag);
}
}
// Returns the localized version of context
/*
* Apply localization to the specified context.
*
* It updates the configuration of the context's resources object but can
* also return a new context derived from the context parameter. Hence
* make sure to work with the return value of this method instead of
* the context you passed as a parameter.
*
* This method also has side-effects as it calls Locale#setDefault().
*
* When using this in attachBaseContext() of Application, Service or
* Activity subclasses, it is important to not only apply this method to the
* base Context parameter received in that method, but also apply it on the
* class itself which also extends Context.
*/
public Context setLocale(Context context) {
if (locale == null || SDK_INT < 17) return context;
Resources res = context.getResources();
Configuration conf = res.getConfiguration();
updateConfiguration(conf, locale);
return context.createConfigurationContext(conf);
}
// For API < 17 only.
public void setLocaleLegacy(Context appContext) {
if (SDK_INT >= 17 || locale == null) return;
forceLocale(appContext, locale);
}
// Forces the update of the resources through the deprecated API.
private void forceLocale(Context context, Locale locale) {
Resources res = context.getResources();
Configuration conf = res.getConfiguration();
updateConfiguration(conf, locale);
res.updateConfiguration(conf, res.getDisplayMetrics());
}
private void updateConfiguration(Configuration conf, Locale locale) {
Locale currentLocale;
if (SDK_INT >= 24) {
currentLocale = conf.getLocales().get(0);
} else
currentLocale = conf.locale;
if (locale.equals(currentLocale))
return context;
Locale.setDefault(locale);
if (SDK_INT >= 17) {
conf.setLocale(locale);
} else {
context = context.createConfigurationContext(conf);
} else
conf.locale = locale;
}
}
private void setLocaleAndSystemConfiguration(@Nullable Locale locale) {
if (locale == null) return;
Locale.setDefault(locale);
if (SDK_INT >= 23) return;
Resources systemResources = Resources.getSystem();
Configuration systemConfiguration = systemResources.getConfiguration();
updateConfiguration(systemConfiguration, locale);
// DateUtils uses the system resources, so we need to update them too.
//noinspection deprecation
systemResources.updateConfiguration(systemConfiguration,
systemResources.getDisplayMetrics());
res.updateConfiguration(conf, res.getDisplayMetrics());
return context;
}
private Locale getLocaleFromConfig(Configuration config) {
if (SDK_INT >= 24) {
return config.getLocales().get(0);
} else {
//noinspection deprecation
return config.locale;
}
}
public void applicationConfigurationChanged(Context appContext,
Configuration newConfig,
AndroidNotificationManager androidNotificationManager,
boolean locked) {
Locale newLocale = getLocaleFromConfig(newConfig);
if (locale == null && newLocale != systemLocale) {
androidNotificationManager.restartNotifications(locked, false);
}
if (newLocale == locale) return;
setLocaleAndSystemConfiguration(locale);
if (SDK_INT < 17) setLocaleLegacy(appContext);
}
/**
* Indicates whether the language represented by locale
* should be offered to the user on this device.
* * Android doesn't pick up Asturian on API < 21
* * RTL languages are supported since API >= 17
*/
public static boolean isLocaleSupported(Locale locale) {
if (SDK_INT >= 21) return true;
if (locale.getLanguage().equals("ast")) return false;
if (SDK_INT >= 17) return true;
return isLeftToRight(locale);
}
// Exclude RTL locales on API < 17, they won't be laid out correctly
private static boolean isLeftToRight(Locale locale) {
// TextUtilsCompat returns the wrong direction for Hebrew on some phones
String language = locale.getLanguage();
if (language.equals("iw") || language.equals("he")) return false;
int direction =
TextUtilsCompat.getLayoutDirectionFromLocale(locale);
return direction == LAYOUT_DIRECTION_LTR;
}
}

View File

@@ -109,6 +109,7 @@ public abstract class BaseActivity extends AppCompatActivity
protected void attachBaseContext(Context base) {
super.attachBaseContext(
Localizer.getInstance().setLocale(base));
Localizer.getInstance().setLocale(this);
}
public ActivityComponent getActivityComponent() {

View File

@@ -11,6 +11,7 @@ import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.activity.BriarActivity;
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
import javax.annotation.Nullable;
import javax.inject.Inject;
@@ -102,4 +103,11 @@ public class AddContactActivity extends BriarActivity implements
return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed() {
Intent i = new Intent(this, NavDrawerActivity.class);
startActivity(i);
finish();
}
}

View File

@@ -14,6 +14,7 @@ import static org.briarproject.bramble.api.contact.HandshakeLinkConstants.LINK_R
class IntentRouter {
// TODO
static void handleExternalIntent(Context ctx, Intent i) {
String action = i.getAction();
// add remote contact with clicked briar:// link

View File

@@ -101,8 +101,6 @@ public class NavDrawerActivity extends BriarActivity implements
Uri.parse("briar-content://org.briarproject.briar/blog");
public static Uri CONTACT_ADDED_URI =
Uri.parse("briar-content://org.briarproject.briar/contact/added");
public static Uri SIGN_OUT_URI =
Uri.parse("briar-content://org.briarproject.briar/sign-out");
private final List<Transport> transports = new ArrayList<>(3);
private final MutableLiveData<ImageView> torIcon = new MutableLiveData<>();
@@ -236,8 +234,6 @@ public class NavDrawerActivity extends BriarActivity implements
startFragment(ForumListFragment.newInstance(), R.id.nav_btn_forums);
} else if (BLOG_URI.equals(uri)) {
startFragment(FeedFragment.newInstance(), R.id.nav_btn_blogs);
} else if (SIGN_OUT_URI.equals(uri)) {
signOut(false, false);
}
}

View File

@@ -79,9 +79,10 @@ public class GroupActivity extends
// start with group disabled and enable when not dissolved
setGroupEnabled(false);
viewModel.isDissolved().observeEvent(this, dissolved -> {
viewModel.isDissolved().observe(this, dissolved -> {
setGroupEnabled(!dissolved);
if (dissolved) onGroupDissolved();
// only show dialog when no prior state
if (dissolved && state == null) onGroupDissolved();
});
}
@@ -153,7 +154,7 @@ public class GroupActivity extends
@Override
public void onReplyClick(GroupMessageItem item) {
Boolean isDissolved = viewModel.isDissolved().getLastValue();
Boolean isDissolved = viewModel.isDissolved().getValue();
if (isDissolved != null && !isDissolved) super.onReplyClick(item);
}

View File

@@ -22,8 +22,6 @@ import org.briarproject.bramble.api.system.AndroidExecutor;
import org.briarproject.bramble.api.system.Clock;
import org.briarproject.briar.android.sharing.SharingController;
import org.briarproject.briar.android.threaded.ThreadListViewModel;
import org.briarproject.briar.android.viewmodel.LiveEvent;
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
import org.briarproject.briar.api.android.AndroidNotificationManager;
import org.briarproject.briar.api.client.MessageTracker;
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
@@ -71,8 +69,8 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
private final MutableLiveData<PrivateGroup> privateGroup =
new MutableLiveData<>();
private final MutableLiveData<Boolean> isCreator = new MutableLiveData<>();
private final MutableLiveEvent<Boolean> isDissolved =
new MutableLiveEvent<>();
private final MutableLiveData<Boolean> isDissolved =
new MutableLiveData<>();
@Inject
GroupViewModel(Application application,
@@ -129,7 +127,7 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
} else if (e instanceof GroupDissolvedEvent) {
GroupDissolvedEvent g = (GroupDissolvedEvent) e;
if (g.getGroupId().equals(groupId)) {
isDissolved.setEvent(true);
isDissolved.setValue(true);
}
} else {
super.eventOccurred(e);
@@ -164,7 +162,7 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
loadList(txn -> {
// check first if group is dissolved
isDissolved
.postEvent(privateGroupManager.isDissolved(txn, groupId));
.postValue(privateGroupManager.isDissolved(txn, groupId));
// now continue to load the items
long start = now();
List<GroupMessageHeader> headers =
@@ -282,7 +280,7 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
return isCreator;
}
LiveEvent<Boolean> isDissolved() {
LiveData<Boolean> isDissolved() {
return isDissolved;
}

View File

@@ -46,11 +46,16 @@ public class SettingsActivity extends BriarActivity {
setContentView(R.layout.activity_settings);
if (featureFlags.shouldEnableProfilePictures()) {
ViewModelProvider provider =
new ViewModelProvider(this, viewModelFactory);
settingsViewModel = provider.get(SettingsViewModel.class);
ViewModelProvider provider =
new ViewModelProvider(this, viewModelFactory);
settingsViewModel = provider.get(SettingsViewModel.class);
settingsViewModel.getLanguageChange().observeEvent(this, b -> {
signOut(false, false);
finishAffinity();
});
if (featureFlags.shouldEnableProfilePictures()) {
TextView textViewUserName = findViewById(R.id.username);
CircleImageView imageViewAvatar =
findViewById(R.id.avatarImage);

View File

@@ -44,6 +44,8 @@ import javax.inject.Inject;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.core.content.ContextCompat;
import androidx.core.text.TextUtilsCompat;
import androidx.lifecycle.ViewModelProvider;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.Preference.OnPreferenceChangeListener;
@@ -53,7 +55,6 @@ import androidx.preference.SwitchPreference;
import static android.app.Activity.RESULT_OK;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.media.RingtoneManager.ACTION_RINGTONE_PICKER;
import static android.media.RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI;
@@ -69,6 +70,7 @@ import static android.provider.Settings.EXTRA_APP_PACKAGE;
import static android.provider.Settings.EXTRA_CHANNEL_ID;
import static android.provider.Settings.System.DEFAULT_NOTIFICATION_URI;
import static android.widget.Toast.LENGTH_SHORT;
import static androidx.core.view.ViewCompat.LAYOUT_DIRECTION_LTR;
import static java.util.Objects.requireNonNull;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
@@ -87,7 +89,6 @@ import static org.briarproject.bramble.util.LogUtils.now;
import static org.briarproject.briar.android.BriarApplication.ENTRY_ACTIVITY;
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_RINGTONE;
import static org.briarproject.briar.android.navdrawer.NavDrawerActivity.SIGN_OUT_URI;
import static org.briarproject.briar.android.util.UiUtils.getCountryDisplayName;
import static org.briarproject.briar.android.util.UiUtils.hasScreenLock;
import static org.briarproject.briar.android.util.UiUtils.triggerFeedback;
@@ -163,12 +164,19 @@ public class SettingsFragment extends PreferenceFragmentCompat
LocationUtils locationUtils;
@Inject
CircumventionProvider circumventionProvider;
@Inject
ViewModelProvider.Factory viewModelFactory;
private SettingsViewModel viewModel;
@Override
public void onAttach(Context context) {
super.onAttach(context);
listener = (SettingsActivity) context;
listener.getActivityComponent().inject(this);
viewModel = new ViewModelProvider(requireActivity(), viewModelFactory)
.get(SettingsViewModel.class);
}
@Override
@@ -294,27 +302,19 @@ public class SettingsFragment extends PreferenceFragmentCompat
Locale locale = Localizer.getLocaleFromTag(tag);
if (locale == null)
throw new IllegalStateException();
// Check if the locale is supported on this device
if (!Localizer.isLocaleSupported(locale)) {
// Exclude RTL locales on API < 17, they won't be laid out correctly
if (SDK_INT < 17 && !isLeftToRight(locale)) {
if (LOG.isLoggable(INFO))
LOG.info("Skipping unsupported locale " + tag);
LOG.info("Skipping RTL locale " + tag);
continue;
}
String nativeName;
// Unknown languages won't be translated to their native name.
if (locale.getLanguage().equals("ast")) {
nativeName = "Asturianu";
} else if (locale.getLanguage().equals("oc")) {
nativeName = "Occitan";
} else {
nativeName = locale.getDisplayName(locale);
// Fallback to English if the name is unknown in both native and
// current locale.
if (nativeName.equals(tag)) {
String tmp = locale.getDisplayLanguage(Locale.ENGLISH);
if (!tmp.isEmpty() && !tmp.equals(nativeName))
nativeName = tmp;
}
String nativeName = locale.getDisplayName(locale);
// Fallback to English if the name is unknown in both native and
// current locale.
if (nativeName.equals(tag)) {
String tmp = locale.getDisplayLanguage(Locale.ENGLISH);
if (!tmp.isEmpty() && !tmp.equals(nativeName))
nativeName = tmp;
}
// Prefix with LRM marker to prevent any RTL direction
entries.add("\u200E" + nativeName.substring(0, 1).toUpperCase()
@@ -325,6 +325,13 @@ public class SettingsFragment extends PreferenceFragmentCompat
language.setEntryValues(entryValues.toArray(new CharSequence[0]));
}
private boolean isLeftToRight(Locale locale) {
// TextUtilsCompat returns the wrong direction for Hebrew on some phones
String language = locale.getLanguage();
if (language.equals("iw") || language.equals("he")) return false;
int direction = TextUtilsCompat.getLayoutDirectionFromLocale(locale);
return direction == LAYOUT_DIRECTION_LTR;
}
private void setTorNetworkSummary(int torNetworkSetting) {
if (torNetworkSetting != PREF_TOR_NETWORK_AUTOMATIC) {
@@ -637,11 +644,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
builder.setPositiveButton(R.string.sign_out_button,
(dialogInterface, i) -> {
language.setValue(newValue);
Intent intent = new Intent(getContext(), ENTRY_ACTIVITY);
intent.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
intent.setData(SIGN_OUT_URI);
requireActivity().startActivity(intent);
requireActivity().finish();
viewModel.languageChanged();
});
builder.setNegativeButton(R.string.cancel, null);
builder.setCancelable(false);

View File

@@ -56,6 +56,9 @@ class SettingsViewModel extends AndroidViewModel {
private final MutableLiveEvent<Boolean> setAvatarFailed =
new MutableLiveEvent<>();
private final MutableLiveEvent<Boolean> languageChanged =
new MutableLiveEvent<>();
@Inject
SettingsViewModel(Application application,
IdentityManager identityManager,
@@ -83,6 +86,10 @@ class SettingsViewModel extends AndroidViewModel {
return setAvatarFailed;
}
LiveEvent<Boolean> getLanguageChange() {
return languageChanged;
}
private void loadOwnIdentityInfo() {
dbExecutor.execute(() -> {
try {
@@ -131,4 +138,8 @@ class SettingsViewModel extends AndroidViewModel {
});
}
void languageChanged() {
languageChanged.setEvent(true);
}
}

View File

@@ -1,5 +1,6 @@
package org.briarproject.briar.android.splash;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
@@ -7,6 +8,7 @@ import android.view.View;
import android.view.View.OnClickListener;
import org.briarproject.briar.R;
import org.briarproject.briar.android.Localizer;
import androidx.appcompat.app.AppCompatActivity;
@@ -27,6 +29,13 @@ public class ExpiredActivity extends AppCompatActivity
findViewById(R.id.download_briar_button).setOnClickListener(this);
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(
Localizer.getInstance().setLocale(base));
Localizer.getInstance().setLocale(this);
}
@Override
public void onClick(View v) {
Uri uri = Uri.parse("https://briarproject.org/download.html");

View File

@@ -93,7 +93,4 @@ public interface AndroidNotificationManager {
void blockAllBlogPostNotifications();
void unblockAllBlogPostNotifications();
void restartNotifications(boolean locked, boolean mayAlertAgain);
}

View File

@@ -1,8 +1,10 @@
dependencyVerification {
verify = [
'junit:junit:4.13.1:junit-4.13.1.jar:c30719db974d6452793fe191b3638a5777005485bae145924044530ffa5f6122',
'org.codehaus.mojo.signature:java16:1.1:java16-1.1.signature:53799223a2c98dba2d0add810bed76315460df285c69e4f397ae6098f87dd619',
'org.codehaus.mojo:animal-sniffer-ant-tasks:1.16:animal-sniffer-ant-tasks-1.16.jar:890040976fbe2d584619a6a61b1fd2e925b3b5eb342a85eb2762c467c0d64e90',
'org.codehaus.mojo:animal-sniffer:1.16:animal-sniffer-1.16.jar:72be8bcc226ba43b937c722a08a07852bfa1b11400089265d5df0ee7b38b1d52',
'org.hamcrest:hamcrest-core:1.3:hamcrest-core-1.3.jar:66fdef91e9739348df7a096aa384a5685f4e875584cce89386a7a47251c4d8e9',
'org.ow2.asm:asm-all:5.2:asm-all-5.2.jar:7fbffbc1db3422e2101689fd88df8384b15817b52b9b2b267b9f6d2511dc198d',
]
}