From 4505a404edd59e28bc92d6528865db2de1533fd8 Mon Sep 17 00:00:00 2001 From: 0xd9a <0xd9a@noreply.codeberg.org> Date: Sun, 5 Oct 2025 14:54:15 +0530 Subject: [PATCH] Add option to change profile image shape in profile page (#711) --- .../mastodon/activities/ProfileActivity.java | 16 +++++++++++ .../settings/FragmentInterfaceSettings.java | 20 ++++++++++++++ .../drawable/profile_image_shape_circle.xml | 9 +++++++ .../drawable/profile_image_shape_diamond.xml | 9 +++++++ .../drawable/profile_image_shape_octagon.xml | 9 +++++++ .../profile_image_shape_rounded_square.xml | 9 +++++++ .../drawable/profile_image_shape_square.xml | 9 +++++++ .../mastodon/layout/activity_profile.xml | 27 +++++++------------ app/src/main/res/values/strings.xml | 18 +++++++++++++ app/src/main/res/values/themes.xml | 24 +++++++++++++++++ app/src/main/res/xml/pref_interface.xml | 7 +++++ 11 files changed, 140 insertions(+), 17 deletions(-) create mode 100644 app/src/main/res/layouts/mastodon/drawable/profile_image_shape_circle.xml create mode 100644 app/src/main/res/layouts/mastodon/drawable/profile_image_shape_diamond.xml create mode 100644 app/src/main/res/layouts/mastodon/drawable/profile_image_shape_octagon.xml create mode 100644 app/src/main/res/layouts/mastodon/drawable/profile_image_shape_rounded_square.xml create mode 100644 app/src/main/res/layouts/mastodon/drawable/profile_image_shape_square.xml diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/ProfileActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/ProfileActivity.java index 27aaf7dc..a971824f 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/ProfileActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/ProfileActivity.java @@ -72,6 +72,7 @@ import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.transition.Transition; import com.google.android.material.chip.Chip; import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import com.google.android.material.shape.ShapeAppearanceModel; import com.google.android.material.tabs.TabLayout; import java.io.File; @@ -456,6 +457,21 @@ public class ProfileActivity extends BaseActivity { boolean disableGif = sharedpreferences.getBoolean(getString(R.string.SET_DISABLE_GIF), false); String targetedUrl = disableGif ? account.avatar_static : account.avatar; // MastodonHelper.loadPPMastodon(binding.accountPp, account); + String profileImageShapePref = sharedpreferences.getString(getString(R.string.SET_PROFILE_IMAGE_SHAPE), "rounded_square"); + binding.accountPp.setShapeAppearanceModel( + ShapeAppearanceModel + .builder( + this, + R.style.ShapeAppearance_MaterialComponents, + switch (profileImageShapePref) { + case "circle" -> R.style.ShapeAppearanceOverlay_Fedilab_ProfileImage_Circle; + case "diamond" -> R.style.ShapeAppearanceOverlay_Fedilab_ProfileImage_Diamond; + case "octagon" -> R.style.ShapeAppearanceOverlay_Fedilab_ProfileImage_Octagon; + case "square" -> R.style.ShapeAppearanceOverlay_Fedilab_ProfileImage_Square; + default -> R.style.ShapeAppearanceOverlay_Fedilab_ProfileImage_RoundedSquare; + }) + .build() + ); Glide.with(ProfileActivity.this) .asDrawable() .dontTransform() diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentInterfaceSettings.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentInterfaceSettings.java index 92132e10..8ab5b6fb 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentInterfaceSettings.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentInterfaceSettings.java @@ -56,6 +56,10 @@ public class FragmentInterfaceSettings extends PreferenceFragmentCompat implemen return; } + ListPreference SET_PROFILE_IMAGE_SHAPE = findPreference(getString(R.string.SET_PROFILE_IMAGE_SHAPE)); + if (SET_PROFILE_IMAGE_SHAPE != null) + SET_PROFILE_IMAGE_SHAPE.setIcon(getProfileImageShapeDrawable(SET_PROFILE_IMAGE_SHAPE.getValue())); + //Theme for dialogs ImageListPreference SET_LOGO_LAUNCHER = findPreference(getString(R.string.SET_LOGO_LAUNCHER)); if (SET_LOGO_LAUNCHER != null) { @@ -84,6 +88,17 @@ public class FragmentInterfaceSettings extends PreferenceFragmentCompat implemen recreate = false; } + private int getProfileImageShapeDrawable(String profileImageShapePrefValue) { + return switch (profileImageShapePrefValue) { + case "circle" -> R.drawable.profile_image_shape_circle; + case "diamond" -> R.drawable.profile_image_shape_diamond; + case "octagon" -> R.drawable.profile_image_shape_octagon; + case "rounded_square" -> R.drawable.profile_image_shape_rounded_square; + case "square" -> R.drawable.profile_image_shape_square; + default -> 0; + }; + } + @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (getActivity() != null) { @@ -116,6 +131,11 @@ public class FragmentInterfaceSettings extends PreferenceFragmentCompat implemen } recreate = true; } + if (key.compareToIgnoreCase(getString(R.string.SET_PROFILE_IMAGE_SHAPE)) == 0) { + ListPreference SET_PROFILE_IMAGE_SHAPE = findPreference(getString(R.string.SET_PROFILE_IMAGE_SHAPE)); + if (SET_PROFILE_IMAGE_SHAPE != null) + SET_PROFILE_IMAGE_SHAPE.setIcon(getProfileImageShapeDrawable(SET_PROFILE_IMAGE_SHAPE.getValue())); + } if (key.compareToIgnoreCase(getString(R.string.SET_LOGO_LAUNCHER)) == 0) { ListPreference SET_LOGO_LAUNCHER = findPreference(getString(R.string.SET_LOGO_LAUNCHER)); String newLauncher = sharedpreferences.getString(getString(R.string.SET_LOGO_LAUNCHER), "Bubbles"); diff --git a/app/src/main/res/layouts/mastodon/drawable/profile_image_shape_circle.xml b/app/src/main/res/layouts/mastodon/drawable/profile_image_shape_circle.xml new file mode 100644 index 00000000..189ae03e --- /dev/null +++ b/app/src/main/res/layouts/mastodon/drawable/profile_image_shape_circle.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layouts/mastodon/drawable/profile_image_shape_diamond.xml b/app/src/main/res/layouts/mastodon/drawable/profile_image_shape_diamond.xml new file mode 100644 index 00000000..5969a4d2 --- /dev/null +++ b/app/src/main/res/layouts/mastodon/drawable/profile_image_shape_diamond.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layouts/mastodon/drawable/profile_image_shape_octagon.xml b/app/src/main/res/layouts/mastodon/drawable/profile_image_shape_octagon.xml new file mode 100644 index 00000000..8447da7e --- /dev/null +++ b/app/src/main/res/layouts/mastodon/drawable/profile_image_shape_octagon.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layouts/mastodon/drawable/profile_image_shape_rounded_square.xml b/app/src/main/res/layouts/mastodon/drawable/profile_image_shape_rounded_square.xml new file mode 100644 index 00000000..5a5e009e --- /dev/null +++ b/app/src/main/res/layouts/mastodon/drawable/profile_image_shape_rounded_square.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layouts/mastodon/drawable/profile_image_shape_square.xml b/app/src/main/res/layouts/mastodon/drawable/profile_image_shape_square.xml new file mode 100644 index 00000000..e5cce4b1 --- /dev/null +++ b/app/src/main/res/layouts/mastodon/drawable/profile_image_shape_square.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layouts/mastodon/layout/activity_profile.xml b/app/src/main/res/layouts/mastodon/layout/activity_profile.xml index f4e43217..2c857f74 100644 --- a/app/src/main/res/layouts/mastodon/layout/activity_profile.xml +++ b/app/src/main/res/layouts/mastodon/layout/activity_profile.xml @@ -82,27 +82,20 @@ - - - - - + app:layout_constraintTop_toBottomOf="@id/banner_container" + app:layout_scrollFlags="scroll" + tools:src="@tools:sample/avatars" /> Fetch at fixed times No notifications + + + Circle + Diamond + Octagon + Rounded Square + Square + + + circle + diamond + octagon + rounded_square + square + + Fedilab Fedilab UA @@ -1304,6 +1320,7 @@ SET_DISPLAY_RELATIVE_DATE SET_REMOVE_LEFT_MARGIN + SET_PROFILE_IMAGE_SHAPE SET_PROFILE_REMOTELY SET_CONVERSATION_REMOTELY SET_EXTAND_EXTRA_FEATURES @@ -2101,6 +2118,7 @@ Remote conversations The app will display publicly profiles to get all messages. Interactions will need an extra step to federate messages. The app will display publicly conversations to get all messages. Interactions will need an extra step to federate messages. + Profile image shape Local only Display \"Local only\" button Pixelfed presentation for media diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 3b3e558f..b59ed315 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -285,4 +285,28 @@ + + + + + + + + + + + diff --git a/app/src/main/res/xml/pref_interface.xml b/app/src/main/res/xml/pref_interface.xml index 1347e720..b169ffc3 100644 --- a/app/src/main/res/xml/pref_interface.xml +++ b/app/src/main/res/xml/pref_interface.xml @@ -59,6 +59,13 @@ app:summary="@string/set_remote_profile" app:title="@string/set_remote_profile_title" /> +