123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805 |
- /*
- * Nextcloud Talk application
- *
- * @author Mario Danic
- * Copyright (C) 2017 Mario Danic (mario@lovelyhq.com)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package com.nextcloud.talk.controllers;
- import android.animation.Animator;
- import android.animation.AnimatorListenerAdapter;
- import android.app.KeyguardManager;
- import android.content.Context;
- import android.content.Intent;
- import android.net.Uri;
- import android.os.Build;
- import android.os.Bundle;
- import android.security.KeyChain;
- import android.text.TextUtils;
- 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;
- import androidx.annotation.NonNull;
- import androidx.annotation.Nullable;
- import androidx.core.view.ViewCompat;
- import androidx.work.OneTimeWorkRequest;
- import androidx.work.WorkManager;
- import autodagger.AutoInjector;
- import butterknife.BindView;
- import com.bluelinelabs.conductor.RouterTransaction;
- import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
- import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler;
- import com.bluelinelabs.logansquare.LoganSquare;
- import com.bumptech.glide.load.model.GlideUrl;
- import com.bumptech.glide.load.model.LazyHeaders;
- import com.bumptech.glide.load.resource.bitmap.CircleCrop;
- import com.bumptech.glide.request.RequestOptions;
- import com.nextcloud.talk.BuildConfig;
- import com.nextcloud.talk.R;
- import com.nextcloud.talk.api.NcApi;
- import com.nextcloud.talk.application.NextcloudTalkApplication;
- import com.nextcloud.talk.controllers.base.BaseController;
- import com.nextcloud.talk.jobs.AccountRemovalWorker;
- import com.nextcloud.talk.models.RingtoneSettings;
- import com.nextcloud.talk.models.database.UserEntity;
- import com.nextcloud.talk.utils.ApiUtils;
- import com.nextcloud.talk.utils.DisplayUtils;
- import com.nextcloud.talk.utils.DoNotDisturbUtils;
- import com.nextcloud.talk.utils.SecurityUtils;
- import com.nextcloud.talk.utils.bundle.BundleKeys;
- import com.nextcloud.talk.utils.database.user.UserUtils;
- import com.nextcloud.talk.utils.glide.GlideApp;
- import com.nextcloud.talk.utils.preferences.AppPreferences;
- import com.nextcloud.talk.utils.preferences.MagicUserInputModule;
- import com.nextcloud.talk.utils.singletons.ApplicationWideMessageHolder;
- import com.yarolegovich.lovelydialog.LovelySaveStateHandler;
- import com.yarolegovich.lovelydialog.LovelyStandardDialog;
- import com.yarolegovich.mp.*;
- import io.reactivex.android.schedulers.AndroidSchedulers;
- import io.reactivex.disposables.Disposable;
- import io.reactivex.schedulers.Schedulers;
- import net.orange_box.storebox.listeners.OnPreferenceValueChangedListener;
- import org.greenrobot.eventbus.EventBus;
- import javax.inject.Inject;
- import java.io.IOException;
- import java.net.URI;
- import java.net.URISyntaxException;
- import java.util.*;
- @AutoInjector(NextcloudTalkApplication.class)
- public class SettingsController extends BaseController {
- public static final String TAG = "SettingsController";
- @BindView(R.id.settings_screen)
- MaterialPreferenceScreen settingsScreen;
- @BindView(R.id.settings_proxy_choice)
- MaterialChoicePreference proxyChoice;
- @BindView(R.id.settings_proxy_port_edit)
- MaterialEditTextPreference proxyPortEditText;
- @BindView(R.id.settings_licence)
- MaterialStandardPreference licenceButton;
- @BindView(R.id.settings_privacy)
- MaterialStandardPreference privacyButton;
- @BindView(R.id.settings_source_code)
- MaterialStandardPreference sourceCodeButton;
- @BindView(R.id.settings_version)
- MaterialStandardPreference versionInfo;
- @BindView(R.id.avatar_image)
- ImageView avatarImageView;
- @BindView(R.id.display_name_text)
- TextView displayNameTextView;
- @BindView(R.id.base_url_text)
- TextView baseUrlTextView;
- @BindView(R.id.settings_call_sound)
- MaterialStandardPreference settingsCallSound;
- @BindView(R.id.settings_message_sound)
- MaterialStandardPreference settingsMessageSound;
- @BindView(R.id.settings_remove_account)
- MaterialStandardPreference removeAccountButton;
- @BindView(R.id.settings_switch)
- MaterialStandardPreference switchAccountButton;
- @BindView(R.id.settings_reauthorize)
- MaterialStandardPreference reauthorizeButton;
- @BindView(R.id.settings_add_account)
- MaterialStandardPreference addAccountButton;
- @BindView(R.id.message_view)
- MaterialPreferenceCategory messageView;
- @BindView(R.id.settings_client_cert)
- MaterialStandardPreference certificateSetup;
- @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.settings_screen_lock)
- MaterialSwitchPreference screenLockSwitchPreference;
- @BindView(R.id.settings_screen_lock_timeout)
- MaterialChoicePreference screenLockTimeoutChoicePreference;
- @BindView(R.id.message_text)
- TextView messageText;
- @Inject
- EventBus eventBus;
- @Inject
- AppPreferences appPreferences;
- @Inject
- NcApi ncApi;
- @Inject
- UserUtils userUtils;
- @Inject
- Context context;
- private LovelySaveStateHandler saveStateHandler;
- private UserEntity currentUser;
- private String credentials;
- private OnPreferenceValueChangedListener<String> proxyTypeChangeListener;
- private OnPreferenceValueChangedListener<Boolean> proxyCredentialsChangeListener;
- private OnPreferenceValueChangedListener<Boolean> screenSecurityChangeListener;
- private OnPreferenceValueChangedListener<Boolean> screenLockChangeListener;
- private OnPreferenceValueChangedListener<String> screenLockTimeoutChangeListener;
- private Disposable profileQueryDisposable;
- private Disposable dbQueryDisposable;
- private static final int ID_REMOVE_ACCOUNT_WARNING_DIALOG = 0;
- @Override
- protected View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
- return inflater.inflate(R.layout.controller_settings, container, false);
- }
- private void getCurrentUser() {
- currentUser = userUtils.getCurrentUser();
- credentials = ApiUtils.getCredentials(currentUser.getUsername(), currentUser.getToken());
- }
- @Override
- protected void onViewBound(@NonNull View view) {
- super.onViewBound(view);
- setHasOptionsMenu(true);
- ViewCompat.setTransitionName(avatarImageView, "userAvatar.transitionTag");
- NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
- getCurrentUser();
- if (saveStateHandler == null) {
- saveStateHandler = new LovelySaveStateHandler();
- }
- appPreferences.registerProxyTypeListener(proxyTypeChangeListener = new ProxyTypeChangeListener());
- appPreferences.registerProxyCredentialsListener(proxyCredentialsChangeListener = new ProxyCredentialsChangeListener());
- appPreferences.registerScreenSecurityListener(screenSecurityChangeListener = new ScreenSecurityChangeListener());
- appPreferences.registerScreenLockListener(screenLockChangeListener = new ScreenLockListener());
- appPreferences.registerScreenLockTimeoutListener(screenLockTimeoutChangeListener = new ScreenLockTimeoutListener());
- List<String> listWithIntFields = new ArrayList<>();
- listWithIntFields.add("proxy_port");
- settingsScreen.setUserInputModule(new MagicUserInputModule(getActivity(), listWithIntFields));
- settingsScreen.setVisibilityController(R.id.settings_proxy_use_credentials,
- Arrays.asList(R.id.settings_proxy_username_edit, R.id.settings_proxy_password_edit),
- true);
- if (!TextUtils.isEmpty(getResources().getString(R.string.nc_gpl3_url))) {
- licenceButton.addPreferenceClickListener(view1 -> {
- Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().
- getString(R.string.nc_gpl3_url)));
- startActivity(browserIntent);
- });
- } else {
- licenceButton.setVisibility(View.GONE);
- }
- if (!DoNotDisturbUtils.hasVibrator()) {
- shouldVibrateSwitchPreference.setVisibility(View.GONE);
- }
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
- incognitoKeyboardSwitchPreference.setVisibility(View.GONE);
- }
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
- screenLockSwitchPreference.setVisibility(View.GONE);
- screenLockTimeoutChoicePreference.setVisibility(View.GONE);
- } else {
- screenLockSwitchPreference.setSummary(String.format(Locale.getDefault(),
- getResources().getString(R.string.nc_settings_screen_lock_desc),
- getResources().getString(R.string.nc_app_name)));
- }
- if (!TextUtils.isEmpty(getResources().getString(R.string.nc_privacy_url))) {
- privacyButton.addPreferenceClickListener(view12 -> {
- Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().
- getString(R.string.nc_privacy_url)));
- startActivity(browserIntent);
- });
- } else {
- privacyButton.setVisibility(View.GONE);
- }
- if (!TextUtils.isEmpty(getResources().getString(R.string.nc_source_code_url))) {
- sourceCodeButton.addPreferenceClickListener(view13 -> {
- Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().
- getString(R.string.nc_source_code_url)));
- startActivity(browserIntent);
- });
- } else {
- sourceCodeButton.setVisibility(View.GONE);
- }
- versionInfo.setSummary("v" + BuildConfig.VERSION_NAME);
- settingsCallSound.setOnClickListener(v -> {
- Bundle bundle = new Bundle();
- bundle.putBoolean(BundleKeys.KEY_ARE_CALL_SOUNDS, true);
- getRouter().pushController(RouterTransaction.with(new RingtoneSelectionController(bundle))
- .pushChangeHandler(new HorizontalChangeHandler())
- .popChangeHandler(new HorizontalChangeHandler()));
- });
- settingsMessageSound.setOnClickListener(v -> {
- Bundle bundle = new Bundle();
- bundle.putBoolean(BundleKeys.KEY_ARE_CALL_SOUNDS, false);
- getRouter().pushController(RouterTransaction.with(new RingtoneSelectionController(bundle))
- .pushChangeHandler(new HorizontalChangeHandler())
- .popChangeHandler(new HorizontalChangeHandler()));
- });
- addAccountButton.addPreferenceClickListener(view15 -> {
- getRouter().pushController(RouterTransaction.with(new
- ServerSelectionController()).pushChangeHandler(new VerticalChangeHandler())
- .popChangeHandler(new VerticalChangeHandler()));
- });
- switchAccountButton.addPreferenceClickListener(view16 -> {
- getRouter().pushController(RouterTransaction.with(new
- SwitchAccountController()).pushChangeHandler(new VerticalChangeHandler())
- .popChangeHandler(new VerticalChangeHandler()));
- });
- String host = null;
- int port = -1;
- URI uri;
- try {
- uri = new URI(currentUser.getBaseUrl());
- host = uri.getHost();
- port = uri.getPort();
- } catch (URISyntaxException e) {
- Log.e(TAG, "Failed to create uri");
- }
- String finalHost = host;
- int finalPort = port;
- certificateSetup.addPreferenceClickListener(v -> KeyChain.choosePrivateKeyAlias(Objects.requireNonNull(getActivity()), alias -> {
- String finalAlias = alias;
- getActivity().runOnUiThread(() -> {
- if (finalAlias != null) {
- certificateSetup.setTitle(R.string.nc_client_cert_change);
- } else {
- certificateSetup.setTitle(R.string.nc_client_cert_setup);
- }
- });
- if (alias == null) {
- alias = "";
- }
- userUtils.createOrUpdateUser(null, null, null, null, null, null, null, currentUser.getId(),
- null, alias, null);
- }, new String[]{"RSA", "EC"}, null, finalHost, finalPort, currentUser.getClientCertificate
- ()));
- }
- private void showLovelyDialog(int dialogId, Bundle savedInstanceState) {
- switch (dialogId) {
- case ID_REMOVE_ACCOUNT_WARNING_DIALOG:
- showRemoveAccountWarning(savedInstanceState);
- break;
- default:
- break;
- }
- }
- @Override
- protected void onSaveViewState(@NonNull View view, @NonNull Bundle outState) {
- saveStateHandler.saveInstanceState(outState);
- super.onSaveViewState(view, outState);
- }
- @Override
- protected void onRestoreViewState(@NonNull View view, @NonNull Bundle savedViewState) {
- super.onRestoreViewState(view, savedViewState);
- if (LovelySaveStateHandler.wasDialogOnScreen(savedViewState)) {
- //Dialog won't be restarted automatically, so we need to call this method.
- //Each dialog knows how to restore its state
- showLovelyDialog(LovelySaveStateHandler.getSavedDialogId(savedViewState), savedViewState);
- }
- }
- private void showRemoveAccountWarning(Bundle savedInstanceState) {
- if (getActivity() != null) {
- new LovelyStandardDialog(getActivity(), LovelyStandardDialog.ButtonLayout.HORIZONTAL)
- .setTopColorRes(R.color.nc_darkRed)
- .setIcon(DisplayUtils.getTintedDrawable(getResources(),
- R.drawable.ic_delete_black_24dp, R.color.white))
- .setPositiveButtonColor(context.getResources().getColor(R.color.nc_darkRed))
- .setTitle(R.string.nc_settings_remove_account)
- .setMessage(R.string.nc_settings_remove_confirmation)
- .setPositiveButton(R.string.nc_settings_remove, new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- removeCurrentAccount();
- }
- })
- .setNegativeButton(R.string.nc_cancel, null)
- .setInstanceStateHandler(ID_REMOVE_ACCOUNT_WARNING_DIALOG, saveStateHandler)
- .setSavedInstanceState(savedInstanceState)
- .show();
- }
- }
- private void removeCurrentAccount() {
- boolean otherUserExists = userUtils.scheduleUserForDeletionWithId(currentUser.getId());
- OneTimeWorkRequest accountRemovalWork = new OneTimeWorkRequest.Builder(AccountRemovalWorker.class).build();
- WorkManager.getInstance().enqueue(accountRemovalWork);
- if (otherUserExists && getView() != null) {
- onViewBound(getView());
- onAttach(getView());
- } else if (!otherUserExists) {
- getRouter().setRoot(RouterTransaction.with(
- new ServerSelectionController())
- .pushChangeHandler(new VerticalChangeHandler())
- .popChangeHandler(new VerticalChangeHandler()));
- }
- }
- @Override
- protected void onAttach(@NonNull View view) {
- super.onAttach(view);
- if (getActionBar() != null) {
- getActionBar().show();
- }
- dispose(null);
- getCurrentUser();
- if (!TextUtils.isEmpty(currentUser.getClientCertificate())) {
- certificateSetup.setTitle(R.string.nc_client_cert_change);
- } else {
- certificateSetup.setTitle(R.string.nc_client_cert_setup);
- }
- if (shouldVibrateSwitchPreference.getVisibility() == View.VISIBLE) {
- ((Checkable) shouldVibrateSwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getShouldVibrateSetting());
- }
- ((Checkable) screenSecuritySwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getIsScreenSecured());
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- ((Checkable) incognitoKeyboardSwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getIsKeyboardIncognito());
- }
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- ((Checkable) incognitoKeyboardSwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getIsKeyboardIncognito());
- }
- ((Checkable) linkPreviewsSwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getAreLinkPreviewsAllowed());
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
- if (keyguardManager.isKeyguardSecure()) {
- screenLockSwitchPreference.setEnabled(true);
- screenLockTimeoutChoicePreference.setEnabled(true);
- ((Checkable) screenLockSwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getIsScreenLocked());
- screenLockTimeoutChoicePreference.setEnabled(appPreferences.getIsScreenLocked());
- if (appPreferences.getIsScreenLocked()) {
- screenLockTimeoutChoicePreference.setAlpha(1.0f);
- } else {
- screenLockTimeoutChoicePreference.setAlpha(0.38f);
- }
- screenLockSwitchPreference.setAlpha(1.0f);
- } else {
- screenLockSwitchPreference.setEnabled(false);
- screenLockTimeoutChoicePreference.setEnabled(false);
- appPreferences.removeScreenLock();
- appPreferences.removeScreenLockTimeout();
- ((Checkable) screenLockSwitchPreference.findViewById(R.id.mp_checkable)).setChecked(false);
- screenLockSwitchPreference.setAlpha(0.38f);
- screenLockTimeoutChoicePreference.setAlpha(0.38f);
- }
- }
- String ringtoneName = "";
- RingtoneSettings ringtoneSettings;
- if (!TextUtils.isEmpty(appPreferences.getCallRingtoneUri())) {
- try {
- ringtoneSettings = LoganSquare.parse(appPreferences.getCallRingtoneUri(), RingtoneSettings.class);
- ringtoneName = ringtoneSettings.getRingtoneName();
- } catch (IOException e) {
- Log.e(TAG, "Failed to parse ringtone name");
- }
- settingsCallSound.setSummary(ringtoneName);
- } else {
- settingsCallSound.setSummary(R.string.nc_settings_default_ringtone);
- }
- ringtoneName = "";
- if (!TextUtils.isEmpty(appPreferences.getMessageRingtoneUri())) {
- try {
- ringtoneSettings = LoganSquare.parse(appPreferences.getMessageRingtoneUri(), RingtoneSettings.class);
- ringtoneName = ringtoneSettings.getRingtoneName();
- } catch (IOException e) {
- Log.e(TAG, "Failed to parse ringtone name");
- }
- settingsMessageSound.setSummary(ringtoneName);
- } else {
- settingsMessageSound.setSummary(R.string.nc_settings_default_ringtone);
- }
- if ("No proxy".equals(appPreferences.getProxyType()) || appPreferences.getProxyType() == null) {
- hideProxySettings();
- } else {
- showProxySettings();
- }
- if (appPreferences.getProxyCredentials()) {
- showProxyCredentials();
- } else {
- hideProxyCredentials();
- }
- if (currentUser != null) {
- baseUrlTextView.setText(Uri.parse(currentUser.getBaseUrl()).getHost());
- reauthorizeButton.addPreferenceClickListener(view14 -> {
- getRouter().pushController(RouterTransaction.with(
- new WebViewLoginController(currentUser.getBaseUrl(), true))
- .pushChangeHandler(new VerticalChangeHandler())
- .popChangeHandler(new VerticalChangeHandler()));
- });
- if (currentUser.getDisplayName() != null) {
- displayNameTextView.setText(currentUser.getDisplayName());
- }
- loadAvatarImage();
- profileQueryDisposable = ncApi.getUserProfile(credentials,
- ApiUtils.getUrlForUserProfile(currentUser.getBaseUrl()))
- .subscribeOn(Schedulers.newThread())
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe(userProfileOverall -> {
- String displayName = null;
- if (!TextUtils.isEmpty(userProfileOverall.getOcs().getData()
- .getDisplayName())) {
- displayName = userProfileOverall.getOcs().getData()
- .getDisplayName();
- } else if (!TextUtils.isEmpty(userProfileOverall.getOcs().getData()
- .getDisplayNameAlt())) {
- displayName = userProfileOverall.getOcs().getData()
- .getDisplayNameAlt();
- }
- if ((!TextUtils.isEmpty(displayName) && !displayName.equals(currentUser.getDisplayName()))) {
- dbQueryDisposable = userUtils.createOrUpdateUser(null,
- null,
- null, displayName, null, null,
- null, currentUser.getId(), null, null, null)
- .subscribeOn(Schedulers.newThread())
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe(userEntityResult -> {
- displayNameTextView.setText(userEntityResult.getDisplayName());
- },
- throwable -> {
- dispose(dbQueryDisposable);
- }, () -> dispose(dbQueryDisposable));
- }
- }, throwable -> {
- dispose(profileQueryDisposable);
- }, () -> dispose(profileQueryDisposable));
- removeAccountButton.addPreferenceClickListener(view1 -> {
- showLovelyDialog(ID_REMOVE_ACCOUNT_WARNING_DIALOG, null);
- });
- }
- if (userUtils.getUsers().size() <= 1) {
- switchAccountButton.setVisibility(View.GONE);
- }
- if (ApplicationWideMessageHolder.getInstance().getMessageType() != null) {
- switch (ApplicationWideMessageHolder.getInstance().getMessageType()) {
- case ACCOUNT_UPDATED_NOT_ADDED:
- messageText.setTextColor(getResources().getColor(R.color.colorPrimary));
- messageText.setText(getResources().getString(R.string.nc_settings_account_updated));
- messageView.setVisibility(View.VISIBLE);
- break;
- case SERVER_WITHOUT_TALK:
- messageText.setTextColor(getResources().getColor(R.color.nc_darkRed));
- messageText.setText(getResources().getString(R.string.nc_settings_wrong_account));
- messageView.setVisibility(View.VISIBLE);
- case ACCOUNT_WAS_IMPORTED:
- messageText.setTextColor(getResources().getColor(R.color.colorPrimary));
- messageText.setText(getResources().getString(R.string.nc_Server_account_imported));
- messageView.setVisibility(View.VISIBLE);
- break;
- case FAILED_TO_IMPORT_ACCOUNT:
- messageText.setTextColor(getResources().getColor(R.color.nc_darkRed));
- messageText.setText(getResources().getString(R.string.nc_server_failed_to_import_account));
- messageView.setVisibility(View.VISIBLE);
- break;
- default:
- messageView.setVisibility(View.GONE);
- break;
- }
- ApplicationWideMessageHolder.getInstance().setMessageType(null);
- messageView.animate()
- .translationY(0)
- .alpha(0.0f)
- .setDuration(2500)
- .setStartDelay(5000)
- .setListener(new AnimatorListenerAdapter() {
- @Override
- public void onAnimationEnd(Animator animation) {
- super.onAnimationEnd(animation);
- if (messageView != null) {
- messageView.setVisibility(View.GONE);
- }
- }
- });
- } else {
- if (messageView != null) {
- messageView.setVisibility(View.GONE);
- }
- }
- }
- private void loadAvatarImage() {
- String avatarId;
- if (!TextUtils.isEmpty(currentUser.getUserId())) {
- avatarId = currentUser.getUserId();
- } else {
- avatarId = currentUser.getUsername();
- }
- GlideUrl glideUrl = new GlideUrl(ApiUtils.getUrlForAvatarWithName(currentUser.getBaseUrl(),
- avatarId, R.dimen.avatar_size_big), new LazyHeaders.Builder()
- .setHeader("Accept", "image/*")
- .setHeader("User-Agent", ApiUtils.getUserAgent())
- .build());
- GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())
- .load(glideUrl)
- .centerInside()
- .apply(RequestOptions.bitmapTransform(new CircleCrop()))
- .into(avatarImageView);
- }
- @Override
- public void onDestroy() {
- if (appPreferences != null) {
- appPreferences.unregisterProxyTypeListener(proxyTypeChangeListener);
- appPreferences.unregisterProxyCredentialsListener(proxyCredentialsChangeListener);
- appPreferences.unregisterScreenSecurityListener(screenSecurityChangeListener);
- appPreferences.unregisterScreenLockListener(screenLockChangeListener);
- appPreferences.unregisterScreenLockTimeoutListener(screenLockTimeoutChangeListener);
- }
- super.onDestroy();
- }
- private void hideProxySettings() {
- appPreferences.removeProxyHost();
- appPreferences.removeProxyPort();
- appPreferences.removeProxyCredentials();
- appPreferences.removeProxyUsername();
- appPreferences.removeProxyPassword();
- settingsScreen.findViewById(R.id.settings_proxy_host_edit).setVisibility(View.GONE);
- settingsScreen.findViewById(R.id.settings_proxy_port_edit).setVisibility(View.GONE);
- settingsScreen.findViewById(R.id.settings_proxy_use_credentials).setVisibility(View.GONE);
- settingsScreen.findViewById(R.id.settings_proxy_username_edit).setVisibility(View.GONE);
- settingsScreen.findViewById(R.id.settings_proxy_password_edit).setVisibility(View.GONE);
- }
- private void showProxySettings() {
- settingsScreen.findViewById(R.id.settings_proxy_host_edit).setVisibility(View.VISIBLE);
- settingsScreen.findViewById(R.id.settings_proxy_port_edit).setVisibility(View.VISIBLE);
- settingsScreen.findViewById(R.id.settings_proxy_use_credentials).setVisibility(View.VISIBLE);
- }
- private void showProxyCredentials() {
- settingsScreen.findViewById(R.id.settings_proxy_username_edit).setVisibility(View.VISIBLE);
- settingsScreen.findViewById(R.id.settings_proxy_password_edit).setVisibility(View.VISIBLE);
- }
- private void hideProxyCredentials() {
- appPreferences.removeProxyUsername();
- appPreferences.removeProxyPassword();
- settingsScreen.findViewById(R.id.settings_proxy_username_edit).setVisibility(View.GONE);
- settingsScreen.findViewById(R.id.settings_proxy_password_edit).setVisibility(View.GONE);
- }
- private void dispose(@Nullable Disposable disposable) {
- if (disposable != null && !disposable.isDisposed()) {
- disposable.dispose();
- } else if (disposable == null) {
- if (profileQueryDisposable != null && !profileQueryDisposable.isDisposed()) {
- profileQueryDisposable.dispose();
- profileQueryDisposable = null;
- } else if (profileQueryDisposable != null) {
- profileQueryDisposable = null;
- }
- if (dbQueryDisposable != null && !dbQueryDisposable.isDisposed()) {
- dbQueryDisposable.dispose();
- dbQueryDisposable = null;
- } else if (dbQueryDisposable != null) {
- dbQueryDisposable = null;
- }
- }
- }
- @Override
- protected String getTitle() {
- return getResources().getString(R.string.nc_settings);
- }
- private class ScreenLockTimeoutListener implements OnPreferenceValueChangedListener<String> {
- @Override
- public void onChanged(String newValue) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- SecurityUtils.createKey(appPreferences.getScreenLockTimeout());
- }
- }
- }
- private class ScreenLockListener implements OnPreferenceValueChangedListener<Boolean> {
- @Override
- public void onChanged(Boolean newValue) {
- screenLockTimeoutChoicePreference.setEnabled(newValue);
- if (newValue) {
- screenLockTimeoutChoicePreference.setAlpha(1.0f);
- } else {
- screenLockTimeoutChoicePreference.setAlpha(0.38f);
- }
- }
- }
- private class ScreenSecurityChangeListener implements OnPreferenceValueChangedListener<Boolean> {
- @Override
- public void onChanged(Boolean newValue) {
- if (newValue) {
- if (getActivity() != null) {
- getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
- }
- } else {
- if (getActivity() != null) {
- getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
- }
- }
- }
- }
- private class ProxyCredentialsChangeListener implements OnPreferenceValueChangedListener<Boolean> {
- @Override
- public void onChanged(Boolean newValue) {
- if (newValue) {
- showProxyCredentials();
- } else {
- hideProxyCredentials();
- }
- }
- }
- private class ProxyTypeChangeListener implements OnPreferenceValueChangedListener<String> {
- @Override
- public void onChanged(String newValue) {
- if ("No proxy".equals(newValue)) {
- hideProxySettings();
- } else {
- switch (newValue) {
- case "HTTP":
- if (proxyPortEditText != null) {
- proxyPortEditText.setValue("3128");
- }
- break;
- case "DIRECT":
- if (proxyPortEditText != null) {
- proxyPortEditText.setValue("8080");
- }
- break;
- case "SOCKS":
- if (proxyPortEditText != null) {
- proxyPortEditText.setValue("1080");
- }
- break;
- default:
- break;
- }
- showProxySettings();
- }
- }
- }
- }
|