Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2019-02-14 06:50:02 +01:00
parent b1356ff0d1
commit 2080b8099d
8 changed files with 164 additions and 9 deletions

View File

@ -23,11 +23,13 @@ package com.nextcloud.talk.activities;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;
import android.webkit.SslErrorHandler;
import com.nextcloud.talk.R;
import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.events.CertificateEvent;
import com.nextcloud.talk.utils.preferences.AppPreferences;
import com.nextcloud.talk.utils.ssl.MagicTrustManager;
import com.yarolegovich.lovelydialog.LovelyStandardDialog;
@ -53,10 +55,16 @@ public class BaseActivity extends AppCompatActivity {
@Inject
EventBus eventBus;
@Inject
AppPreferences appPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
super.onCreate(savedInstanceState);
if (appPreferences.getIsScreenSecured()) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
}
}
public void showCertificateDialog(X509Certificate cert, MagicTrustManager magicTrustManager,

View File

@ -73,6 +73,7 @@ import com.nextcloud.talk.presenters.MentionAutocompletePresenter;
import com.nextcloud.talk.utils.*;
import com.nextcloud.talk.utils.bundle.BundleKeys;
import com.nextcloud.talk.utils.database.user.UserUtils;
import com.nextcloud.talk.utils.preferences.AppPreferences;
import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder;
import com.otaliastudios.autocomplete.Autocomplete;
import com.otaliastudios.autocomplete.AutocompleteCallback;
@ -113,6 +114,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
NcApi ncApi;
@Inject
UserUtils userUtils;
@Inject
AppPreferences appPreferences;
@BindView(R.id.messagesListView)
MessagesList messagesListView;
@BindView(R.id.messageInputView)
@ -152,6 +155,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
private boolean isHelloClicked;
private boolean isLeavingForConversation;
private boolean isLinkPreviewAllowed;
private static final byte CONTENT_TYPE_SYSTEM_MESSAGE = 1;
private boolean wasDetached;
@ -443,6 +448,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
ApplicationWideCurrentRoomHolder.getInstance().setInCall(false);
ApplicationWideCurrentRoomHolder.getInstance().setUserInRoom(conversationUser);
isLinkPreviewAllowed = appPreferences.getAreLinkPreviewsAllowed();
emojiPopup = EmojiPopup.Builder.fromRootView(view).setOnEmojiPopupShownListener(new OnEmojiPopupShownListener() {
@Override
@ -856,8 +862,11 @@ public class ChatController extends BaseController implements MessagesListAdapte
countGroupedMessages = 0;
}
}
chatMessageList.get(i).setBaseUrl(conversationUser.getBaseUrl());
chatMessageList.get(i).setActiveUserId(conversationUser.getUserId());
ChatMessage chatMessage = chatMessageList.get(i);
chatMessage.setLinkPreviewAllowed(isLinkPreviewAllowed);
chatMessage.setBaseUrl(conversationUser.getBaseUrl());
chatMessage.setActiveUserId(conversationUser.getUserId());
if (globalLastKnownPastMessageId == -1 || chatMessageList.get(i).getJsonMessageId() <
globalLastKnownPastMessageId) {
globalLastKnownPastMessageId = chatMessageList.get(i).getJsonMessageId();
@ -882,7 +891,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
chatMessage = chatMessageList.get(i);
chatMessage.setBaseUrl(conversationUser.getBaseUrl());
chatMessageList.get(i).setActiveUserId(conversationUser.getUserId());
chatMessage.setActiveUserId(conversationUser.getUserId());
chatMessage.setLinkPreviewAllowed(isLinkPreviewAllowed);
// if credentials are empty, we're acting as a guest
if (TextUtils.isEmpty(credentials) && !TextUtils.isEmpty(myFirstMessage.toString())) {

View File

@ -31,6 +31,7 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Checkable;
import android.widget.ImageView;
import android.widget.TextView;
@ -153,6 +154,15 @@ public class SettingsController extends BaseController {
@BindView(R.id.settings_always_vibrate)
MaterialSwitchPreference shouldVibrateSwitchPreference;
@BindView(R.id.settings_incognito_keyboard)
MaterialSwitchPreference incognitoKeyboardSwitchPreference;
@BindView(R.id.settings_screen_security)
MaterialSwitchPreference screenSecuritySwitchPreference;
@BindView(R.id.settings_link_previews)
MaterialSwitchPreference linkPreviewsSwitchPreference;
@BindView(R.id.message_text)
TextView messageText;
@ -173,6 +183,7 @@ public class SettingsController extends BaseController {
private OnPreferenceValueChangedListener<String> proxyTypeChangeListener;
private OnPreferenceValueChangedListener<Boolean> proxyCredentialsChangeListener;
private OnPreferenceValueChangedListener<Boolean> screenSecurityChangeListener;
private Disposable profileQueryDisposable;
private Disposable dbQueryDisposable;
@ -198,8 +209,8 @@ public class SettingsController extends BaseController {
getCurrentUser();
appPreferences.registerProxyTypeListener(proxyTypeChangeListener = new ProxyTypeChangeListener());
appPreferences.registerProxyCredentialsListener(proxyCredentialsChangeListener = new
ProxyCredentialsChangeListener());
appPreferences.registerProxyCredentialsListener(proxyCredentialsChangeListener = new ProxyCredentialsChangeListener());
appPreferences.registerScreenSecurityListener(screenSecurityChangeListener = new ScreenSecurityChangeListener());
List<String> listWithIntFields = new ArrayList<>();
listWithIntFields.add("proxy_port");
@ -330,6 +341,11 @@ public class SettingsController extends BaseController {
((Checkable)shouldVibrateSwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getShouldVibrateSetting());
}
((Checkable)screenSecuritySwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getIsScreenSecured());
((Checkable)incognitoKeyboardSwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getIsKeyboardIncognito());
((Checkable)linkPreviewsSwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getAreLinkPreviewsAllowed());
String ringtoneName = "";
RingtoneSettings ringtoneSettings;
if (!TextUtils.isEmpty(appPreferences.getCallRingtoneUri())) {
@ -532,6 +548,7 @@ public class SettingsController extends BaseController {
if (appPreferences != null) {
appPreferences.unregisterProxyTypeListener(proxyTypeChangeListener);
appPreferences.unregisterProxyCredentialsListener(proxyCredentialsChangeListener);
appPreferences.unregisterScreenSecurityListener(screenSecurityChangeListener);
}
super.onDestroy();
}
@ -594,6 +611,21 @@ public class SettingsController extends BaseController {
return getResources().getString(R.string.nc_app_name);
}
private class ScreenSecurityChangeListener implements OnPreferenceValueChangedListener<Boolean> {
@Override
public void onChanged(Boolean newValue) {
if (newValue) {
if (getActivity() != null) {
getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
}
} else {
if (getActivity() != null) {
getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
}
}
}
private class ProxyCredentialsChangeListener implements OnPreferenceValueChangedListener<Boolean> {
@Override

View File

@ -82,7 +82,7 @@ public class ChatMessage implements IMessage, MessageContentType, MessageContent
}
}
if (!messageTypesToIgnore.contains(getMessageType())) {
if (!messageTypesToIgnore.contains(getMessageType()) && isLinkPreviewAllowed) {
return getMessage().trim();
}
@ -163,6 +163,8 @@ public class ChatMessage implements IMessage, MessageContentType, MessageContent
public String activeUserId;
@JsonIgnore
public Map<String, String> selectedIndividualHashMap;
@JsonIgnore
public boolean isLinkPreviewAllowed;
public Map<String, String> getSelectedIndividualHashMap() {

View File

@ -192,6 +192,58 @@ public interface AppPreferences {
@RemoveMethod
void removeVibrateSetting();
@KeyByString("screen_security")
@DefaultValue(R.bool.value_false)
boolean getIsScreenSecured();
@KeyByString("screen_security")
void setScreenSecurity(boolean value);
@KeyByString("screen_security")
@RemoveMethod
void removeScreenSecurity();
@KeyByString("screen_security")
@RegisterChangeListenerMethod
void registerScreenSecurityListener(OnPreferenceValueChangedListener<Boolean> listener);
@KeyByString("screen_security")
@UnregisterChangeListenerMethod
void unregisterScreenSecurityListener(OnPreferenceValueChangedListener<Boolean> listener);
@KeyByString("screen_lock")
@DefaultValue(R.bool.value_false)
boolean getIsScreenLocked();
@KeyByString("screen_lock")
void setScreenLock(boolean value);
@KeyByString("screen_lock")
@RemoveMethod
void removeScreenLock();
@KeyByString("incognito_keyboard")
@DefaultValue(R.bool.value_false)
boolean getIsKeyboardIncognito();
@KeyByString("incognito_keyboard")
void setIncognitoKeyboard(boolean value);
@KeyByString("incognito_keyboard")
@RemoveMethod
void removeIncognitoKeyboard();
@KeyByString("link_previews")
@DefaultValue(R.bool.value_true)
boolean getAreLinkPreviewsAllowed();
@KeyByString("link_previews")
void setLinkPreviewsAllowed(boolean value);
@KeyByString("link_previews")
@RemoveMethod
void removeLinkPreviews();
@ClearMethod
void clear();
}

View File

@ -142,6 +142,40 @@
</com.yarolegovich.mp.MaterialPreferenceCategory>
<com.yarolegovich.mp.MaterialPreferenceCategory
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
apc:mpc_title="@string/nc_settings_privacy"
apc:mpc_title_color="@color/colorPrimary">
<com.yarolegovich.mp.MaterialSwitchPreference
android:id="@+id/settings_screen_security"
android:layout_width="match_parent"
android:layout_height="wrap_content"
apc:mp_default_value="@bool/value_false"
apc:mp_key="@string/nc_settings_screen_security_key"
apc:mp_summary="@string/nc_settings_screen_security_desc"
apc:mp_title="@string/nc_settings_screen_security_title" />
<com.yarolegovich.mp.MaterialSwitchPreference
android:id="@+id/settings_incognito_keyboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
apc:mp_default_value="@bool/value_false"
apc:mp_key="@string/nc_settings_incognito_keyboard_key"
apc:mp_summary="@string/nc_settings_incognito_keyboard_desc"
apc:mp_title="@string/nc_settings_incognito_keyboard_title" />
<com.yarolegovich.mp.MaterialSwitchPreference
android:id="@+id/settings_link_previews"
android:layout_width="match_parent"
android:layout_height="wrap_content"
apc:mp_default_value="@bool/value_true"
apc:mp_key="@string/nc_settings_link_previews_key"
apc:mp_summary="@string/nc_settings_link_previews_desc"
apc:mp_title="@string/nc_settings_link_previews_title" />
</com.yarolegovich.mp.MaterialPreferenceCategory>
<com.yarolegovich.mp.MaterialPreferenceCategory
android:layout_width="match_parent"
@ -202,7 +236,6 @@
apc:mp_key="@string/nc_settings_proxy_password_key"
apc:mp_show_value="onRight"
apc:mp_title="@string/nc_password" />
</com.yarolegovich.mp.MaterialPreferenceCategory>
<com.yarolegovich.mp.MaterialPreferenceCategory

View File

@ -21,4 +21,5 @@
<resources>
<bool name="value_true">true</bool>
</resources>
<bool name="value_false">false</bool>
</resources>

View File

@ -83,9 +83,26 @@
<string name="nc_settings_default_ringtone" translatable="false">Librem by feandesign</string>
<string name="nc_settings_no_ringtone">No sound</string>
<string name="nc_settings_vibrate">Vibrate</string>
<string name="nc_settings_vibrate_desc">Your phone will vibrate unless it\'s silenced</string>
<string name="nc_settings_vibrate_desc">Phone will unless it\'s silenced</string>
<string name="nc_settings_vibrate_key" translatable="false">notifications_vibrate</string>
<string name="nc_settings_privacy">Privacy</string>
<string name="nc_settings_screen_lock_title">Screen lock</string>
<string name="nc_settings_screen_lock_desc">Lock %1$s with Android screen lock or fingerprint</string>
<string name="nc_settings_screen_lock_key" translatable="false">screen_lock</string>
<string name="nc_settings_screen_lock_timeout_title">Screen lock inactivity timeout</string>
<string name="nc_none">None</string>
<string name="nc_settings_screen_lock_timeout_key" translatable="false">screen_lock_timeout</string>
<string name="nc_settings_screen_security_title">Screen security</string>
<string name="nc_settings_screen_security_desc">Prevents screenshots in the recents list and inside the app</string>
<string name="nc_settings_screen_security_key" translatable="false">screen_security</string>
<string name="nc_settings_incognito_keyboard_title">Screen security</string>
<string name="nc_settings_incognito_keyboard_desc">Instructs keyboard to disable personalized learning (without guarantees)</string>
<string name="nc_settings_incognito_keyboard_key" translatable="false">incognito_keyboard</string>
<string name="nc_settings_link_previews_title">Show link previews</string>
<string name="nc_settings_link_previews_desc">Allows previews of content from received links for supported services</string>
<string name="nc_settings_link_previews_key" translatable="false">link_previews</string>
<string name="nc_no_proxy">No proxy</string>
<string name="nc_username">Username</string>