From 31dfb0c7048b6841b1633a544823fca53b661648 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 19 Apr 2020 08:04:36 +0200 Subject: [PATCH] cache useTor information in activity --- .../siacs/conversations/ui/ConversationFragment.java | 4 ++-- .../conversations/ui/ConversationsActivity.java | 1 - .../java/eu/siacs/conversations/ui/XmppActivity.java | 12 +++++++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 8d1a0f1ab..e5c1925f7 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -1252,7 +1252,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } private void checkPermissionAndTriggerAudioCall() { - if (activity.xmppConnectionService.useTorToConnect() || conversation.getAccount().isOnion()) { + if (activity.mUseTor || conversation.getAccount().isOnion()) { Toast.makeText(activity, R.string.disable_tor_to_make_call, Toast.LENGTH_SHORT).show(); return; } @@ -1262,7 +1262,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } private void checkPermissionAndTriggerVideoCall() { - if (activity.xmppConnectionService.useTorToConnect() || conversation.getAccount().isOnion()) { + if (activity.mUseTor || conversation.getAccount().isOnion()) { Toast.makeText(activity, R.string.disable_tor_to_make_call, Toast.LENGTH_SHORT).show(); return; } diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java index bc9d78f71..cd6a1d8e6 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java @@ -383,7 +383,6 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio if (isCameraFeatureAvailable()) { Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment); boolean visible = getResources().getBoolean(R.bool.show_qr_code_scan) - && fragment != null && fragment instanceof ConversationsOverviewFragment; qrCodeScanMenuItem.setVisible(visible); } else { diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index 9ed35190b..b2fee69f9 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -67,6 +67,7 @@ import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Presences; import eu.siacs.conversations.services.AvatarService; import eu.siacs.conversations.services.BarcodeProvider; +import eu.siacs.conversations.services.QuickConversationsService; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder; import eu.siacs.conversations.ui.service.EmojiService; @@ -96,6 +97,7 @@ public abstract class XmppActivity extends ActionBarActivity { protected int mTheme; protected boolean mUsingEnterKey = false; + protected boolean mUseTor = false; protected Toast mToast; public Runnable onOpenPGPKeyPublished = () -> Toast.makeText(XmppActivity.this, R.string.openpgp_has_been_published, Toast.LENGTH_SHORT).show(); protected ConferenceInvite mPendingConferenceInvite = null; @@ -211,6 +213,8 @@ public abstract class XmppActivity extends ActionBarActivity { this.registerListeners(); this.onBackendConnected(); } + this.mUsingEnterKey = usingEnterKey(); + this.mUseTor = useTor(); } public void connectToBackend() { @@ -408,8 +412,6 @@ public abstract class XmppActivity extends ActionBarActivity { } this.mTheme = findTheme(); setTheme(this.mTheme); - - this.mUsingEnterKey = usingEnterKey(); } protected boolean isCameraFeatureAvailable() { @@ -451,10 +453,14 @@ public abstract class XmppActivity extends ActionBarActivity { } } - protected boolean usingEnterKey() { + private boolean usingEnterKey() { return getBooleanPreference("display_enter_key", R.bool.display_enter_key); } + private boolean useTor() { + return QuickConversationsService.isConversations() && getBooleanPreference("use_tor", R.bool.use_tor); + } + protected SharedPreferences getPreferences() { return PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); }