Implement parts of #462

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2019-02-14 07:28:51 +01:00
parent 2080b8099d
commit 8fd1ef031d
6 changed files with 55 additions and 6 deletions

View File

@ -24,6 +24,7 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.security.KeyChain;
import android.text.TextUtils;
@ -234,6 +235,10 @@ public class SettingsController extends BaseController {
shouldVibrateSwitchPreference.setVisibility(View.GONE);
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
incognitoKeyboardSwitchPreference.setVisibility(View.GONE);
}
if (!TextUtils.isEmpty(getResources().getString(R.string.nc_privacy_url))) {
privacyButton.addPreferenceClickListener(view12 -> {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().
@ -342,7 +347,9 @@ public class SettingsController extends BaseController {
}
((Checkable)screenSecuritySwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getIsScreenSecured());
((Checkable)incognitoKeyboardSwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getIsKeyboardIncognito());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
((Checkable) incognitoKeyboardSwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getIsKeyboardIncognito());
}
((Checkable)linkPreviewsSwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getAreLinkPreviewsAllowed());

View File

@ -19,12 +19,17 @@
package com.nextcloud.talk.controllers.base;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import androidx.annotation.RequiresApi;
import com.bluelinelabs.conductor.Controller;
import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.controllers.AccountVerificationController;
@ -90,6 +95,10 @@ public abstract class BaseController extends ButterKnifeController {
@Override
protected void onViewBound(@NonNull View view) {
super.onViewBound(view);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && appPreferences.getIsKeyboardIncognito()) {
disableKeyboardPersonalisedLearning((ViewGroup) view);
}
}
// Note: This is just a quick demo of how an ActionBar *can* be accessed, not necessarily how it *should*
@ -106,11 +115,12 @@ public abstract class BaseController extends ButterKnifeController {
@Override
protected void onAttach(@NonNull View view) {
super.onAttach(view);
setTitle();
if (getActionBar() != null) {
getActionBar().setDisplayHomeAsUpEnabled(getParentController() != null || getRouter().getBackstackSize() > 1);
}
super.onAttach(view);
}
@Override
@ -141,4 +151,20 @@ public abstract class BaseController extends ButterKnifeController {
protected String getTitle() {
return null;
}
@RequiresApi(api = Build.VERSION_CODES.O)
private void disableKeyboardPersonalisedLearning(final ViewGroup viewGroup) {
View view;
EditText editText;
for(int i = 0; i < viewGroup.getChildCount(); i++) {
view = viewGroup.getChildAt(i);
if (view instanceof EditText) {
editText = (EditText) view;
editText.setImeOptions(editText.getImeOptions() | EditorInfo.IME_FLAG_NO_PERSONALIZED_LEARNING);
} else if (view instanceof ViewGroup) {
disableKeyboardPersonalisedLearning((ViewGroup) view);
}
}
}
}

View File

@ -223,7 +223,7 @@ public interface AppPreferences {
void removeScreenLock();
@KeyByString("incognito_keyboard")
@DefaultValue(R.bool.value_false)
@DefaultValue(R.bool.value_true)
boolean getIsKeyboardIncognito();
@KeyByString("incognito_keyboard")

View File

@ -22,12 +22,16 @@ package com.nextcloud.talk.utils.preferences;
import android.app.Dialog;
import android.content.Context;
import android.os.Build;
import android.text.InputType;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import autodagger.AutoInjector;
import com.nextcloud.talk.R;
import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.yarolegovich.mp.io.StandardUserInputModule;
import java.util.ArrayList;
@ -35,16 +39,24 @@ import java.util.List;
import androidx.appcompat.app.AlertDialog;
import javax.inject.Inject;
@AutoInjector(NextcloudTalkApplication.class)
public class MagicUserInputModule extends StandardUserInputModule {
@Inject
AppPreferences appPreferences;
private List<String> keysWithIntegerInput = new ArrayList<>();
public MagicUserInputModule(Context context) {
super(context);
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
}
public MagicUserInputModule(Context context, List<String> keysWithIntegerInput) {
super(context);
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
this.keysWithIntegerInput = keysWithIntegerInput;
}
@ -55,7 +67,11 @@ public class MagicUserInputModule extends StandardUserInputModule {
CharSequence defaultValue,
final Listener<String> listener) {
final View view = LayoutInflater.from(context).inflate(R.layout.dialog_edittext, null);
final EditText inputField = (EditText) view.findViewById(R.id.mp_text_input);
final EditText inputField = view.findViewById(R.id.mp_text_input);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && appPreferences.getIsKeyboardIncognito()) {
inputField.setImeOptions(inputField.getImeOptions() | EditorInfo.IME_FLAG_NO_PERSONALIZED_LEARNING);
}
if (defaultValue != null) {
inputField.setText(defaultValue);

View File

@ -162,7 +162,7 @@
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_default_value="@bool/value_true"
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" />

View File

@ -96,7 +96,7 @@
<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_title">Incognito keyboard</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>