From 3057e6c7d7e03421115cb706dc1fe4eb20644bee Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 16 May 2019 20:10:12 +0200 Subject: [PATCH] remove dead code wrt system-avatar/system-name in profile settings --- .../ApplicationPreferencesActivity.java | 3 - .../securesms/CreateProfileActivity.java | 43 +------ .../securesms/profiles/SystemProfileUtil.java | 116 ------------------ 3 files changed, 4 insertions(+), 158 deletions(-) delete mode 100644 src/org/thoughtcrime/securesms/profiles/SystemProfileUtil.java diff --git a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java index 9d9ffaa20..1296dbe5c 100644 --- a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java +++ b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java @@ -280,10 +280,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA @Override public boolean onPreferenceClick(Preference preference) { Intent intent = new Intent(preference.getContext(), CreateProfileActivity.class); - intent.putExtra(CreateProfileActivity.EXCLUDE_SYSTEM, true); - getActivity().startActivity(intent); -// ((BaseActionBarActivity)getActivity()).startActivitySceneTransition(intent, getActivity().findViewById(R.id.avatar), "avatar"); return true; } } diff --git a/src/org/thoughtcrime/securesms/CreateProfileActivity.java b/src/org/thoughtcrime/securesms/CreateProfileActivity.java index fceb39117..f08488ac4 100644 --- a/src/org/thoughtcrime/securesms/CreateProfileActivity.java +++ b/src/org/thoughtcrime/securesms/CreateProfileActivity.java @@ -42,7 +42,6 @@ import org.thoughtcrime.securesms.mms.GlideApp; import org.thoughtcrime.securesms.permissions.Permissions; import org.thoughtcrime.securesms.profiles.AvatarHelper; import org.thoughtcrime.securesms.profiles.ProfileMediaConstraints; -import org.thoughtcrime.securesms.profiles.SystemProfileUtil; import org.thoughtcrime.securesms.util.BitmapDecodingException; import org.thoughtcrime.securesms.util.BitmapUtil; import org.thoughtcrime.securesms.util.DynamicLanguage; @@ -69,7 +68,6 @@ public class CreateProfileActivity extends BaseActionBarActivity { private static final String TAG = CreateProfileActivity.class.getSimpleName(); public static final String NEXT_INTENT = "next_intent"; - public static final String EXCLUDE_SYSTEM = "exclude_system"; private static final int REQUEST_CODE_AVATAR = 1; @@ -104,8 +102,8 @@ public class CreateProfileActivity extends BaseActionBarActivity { initializeResources(); initializeEmojiInput(); - initializeProfileName(getIntent().getBooleanExtra(EXCLUDE_SYSTEM, false)); - initializeProfileAvatar(getIntent().getBooleanExtra(EXCLUDE_SYSTEM, false)); + initializeProfileName(); + initializeProfileAvatar(); initializeStatusText(); } @@ -256,30 +254,15 @@ public class CreateProfileActivity extends BaseActionBarActivity { }); } - private void initializeProfileName(boolean excludeSystem) { + private void initializeProfileName() { String profileName = DcHelper.get(this, DcHelper.CONFIG_DISPLAY_NAME); if (!TextUtils.isEmpty(profileName)) { name.setText(profileName); name.setSelection(profileName.length(), profileName.length()); - } else if (!excludeSystem) { - SystemProfileUtil.getSystemProfileName(this).addListener(new ListenableFuture.Listener() { - @Override - public void onSuccess(String result) { - if (!TextUtils.isEmpty(result)) { - name.setText(result); - name.setSelection(result.length(), result.length()); - } - } - - @Override - public void onFailure(ExecutionException e) { - Log.w(TAG, e); - } - }); } } - private void initializeProfileAvatar(boolean excludeSystem) { + private void initializeProfileAvatar() { String address = DcHelper.get(this, DcHelper.CONFIG_ADDRESS); if (AvatarHelper.getSelfAvatarFile(this, address).exists() && AvatarHelper.getSelfAvatarFile(this, address).length() > 0) { @@ -305,24 +288,6 @@ public class CreateProfileActivity extends BaseActionBarActivity { } } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else if (!excludeSystem) { - SystemProfileUtil.getSystemProfileAvatar(this, new ProfileMediaConstraints()).addListener(new ListenableFuture.Listener() { - @Override - public void onSuccess(byte[] result) { - if (result != null) { - avatarBytes = result; - GlideApp.with(CreateProfileActivity.this) - .load(result) - .circleCrop() - .into(avatar); - } - } - - @Override - public void onFailure(ExecutionException e) { - Log.w(TAG, e); - } - }); } } diff --git a/src/org/thoughtcrime/securesms/profiles/SystemProfileUtil.java b/src/org/thoughtcrime/securesms/profiles/SystemProfileUtil.java deleted file mode 100644 index 781465ee7..000000000 --- a/src/org/thoughtcrime/securesms/profiles/SystemProfileUtil.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.thoughtcrime.securesms.profiles; - - -import android.accounts.Account; -import android.accounts.AccountManager; -import android.annotation.SuppressLint; -import android.content.Context; -import android.database.Cursor; -import android.net.Uri; -import android.os.AsyncTask; -import android.os.Build; -import android.provider.ContactsContract; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.text.TextUtils; -import android.util.Log; - -import org.thoughtcrime.securesms.mms.MediaConstraints; -import org.thoughtcrime.securesms.util.BitmapDecodingException; -import org.thoughtcrime.securesms.util.BitmapUtil; -import org.thoughtcrime.securesms.util.concurrent.ListenableFuture; -import org.thoughtcrime.securesms.util.concurrent.SettableFuture; - -public class SystemProfileUtil { - - private static final String TAG = SystemProfileUtil.class.getSimpleName(); - - @SuppressLint("StaticFieldLeak") - public static ListenableFuture getSystemProfileAvatar(final @NonNull Context context, MediaConstraints mediaConstraints) { - SettableFuture future = new SettableFuture<>(); - - new AsyncTask() { - @Override - protected @Nullable byte[] doInBackground(Void... params) { - if (Build.VERSION.SDK_INT >= 14) { - try (Cursor cursor = context.getContentResolver().query(ContactsContract.Profile.CONTENT_URI, null, null, null, null)) { - while (cursor != null && cursor.moveToNext()) { - String photoUri = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Profile.PHOTO_URI)); - - if (!TextUtils.isEmpty(photoUri)) { - try { - BitmapUtil.ScaleResult result = BitmapUtil.createScaledBytes(context, Uri.parse(photoUri), mediaConstraints); - return result.getBitmap(); - } catch (BitmapDecodingException e) { - Log.w(TAG, e); - } - } - } - } catch (SecurityException se) { - Log.w(TAG, se); - } - } - - return null; - } - - @Override - protected void onPostExecute(@Nullable byte[] result) { - future.set(result); - } - - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - - return future; - } - - @SuppressLint("StaticFieldLeak") - public static ListenableFuture getSystemProfileName(final @NonNull Context context) { - SettableFuture future = new SettableFuture<>(); - - new AsyncTask() { - @Override - protected String doInBackground(Void... params) { - String name = null; - - if (Build.VERSION.SDK_INT >= 14) { - try (Cursor cursor = context.getContentResolver().query(ContactsContract.Profile.CONTENT_URI, null, null, null, null)) { - if (cursor != null && cursor.moveToNext()) { - name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Profile.DISPLAY_NAME)); - } - } catch (SecurityException se) { - Log.w(TAG, se); - } - } - - if (name == null) { - AccountManager accountManager = AccountManager.get(context); - Account[] accounts = accountManager.getAccountsByType("com.google"); - - for (Account account : accounts) { - if (!TextUtils.isEmpty(account.name)) { - if (account.name.contains("@")) { - name = account.name.substring(0, account.name.indexOf("@")).replace('.', ' '); - } else { - name = account.name.replace('.', ' '); - } - - break; - } - } - } - - return name; - } - - @Override - protected void onPostExecute(@Nullable String result) { - future.set(result); - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - - return future; - } - - -}