Add option to change profile image shape in profile page (#711)

This commit is contained in:
0xd9a 2025-10-05 14:54:15 +05:30
parent e98ce2e9cc
commit 4505a404ed
11 changed files with 140 additions and 17 deletions

View file

@ -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()

View file

@ -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");

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?colorOnSurface"
android:pathData="m24,12a12,12 0,0 1,-12 12,12 12,0 0,1 -12,-12 12,12 0,0 1,12 -12,12 12,0 0,1 12,12z" />
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?colorOnSurface"
android:pathData="m12,0 l12,12 -12,12 -12,-12z" />
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?colorOnSurface"
android:pathData="m16.971,0 l7.029,7.029v9.941l-7.029,7.029 -9.941,-0 -7.029,-7.029 -0,-9.941 7.029,-7.029z" />
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?colorOnSurface"
android:pathData="m3,0h18c1.662,0 3,1.338 3,3v18c0,1.662 -1.338,3 -3,3h-18c-1.662,0 -3,-1.338 -3,-3v-18c0,-1.662 1.338,-3 3,-3z" />
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?colorOnSurface"
android:pathData="m0,0h24v24h-24z" />
</vector>

View file

@ -82,27 +82,20 @@
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="@+id/avatar_container"
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/account_pp"
android:layout_width="108dp"
android:layout_height="108dp"
app:cardElevation="6dp"
android:contentDescription="@string/profile_picture"
android:elevation="6dp"
android:scaleType="centerCrop"
android:transitionName="@string/activity_porfile_pp"
app:layout_constraintBottom_toBottomOf="@id/banner_container"
app:layout_constraintEnd_toEndOf="@id/banner_container"
app:layout_constraintStart_toStartOf="@id/banner_container"
app:layout_constraintTop_toBottomOf="@id/banner_container">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/account_pp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/profile_picture"
android:scaleType="centerCrop"
android:transitionName="@string/activity_porfile_pp"
app:layout_scrollFlags="scroll"
tools:src="@tools:sample/avatars" />
</com.google.android.material.card.MaterialCardView>
app:layout_constraintTop_toBottomOf="@id/banner_container"
app:layout_scrollFlags="scroll"
tools:src="@tools:sample/avatars" />
<com.google.android.material.button.MaterialButton
android:id="@+id/account_follow"
@ -155,7 +148,7 @@
android:singleLine="true"
app:layout_constraintEnd_toEndOf="@id/banner_container"
app:layout_constraintStart_toStartOf="@id/banner_container"
app:layout_constraintTop_toBottomOf="@id/avatar_container"
app:layout_constraintTop_toBottomOf="@id/account_pp"
tools:text="@tools:sample/first_names" />
<androidx.appcompat.widget.LinearLayoutCompat

View file

@ -849,6 +849,22 @@
<item>Fetch at fixed times</item>
<item>No notifications</item>
</string-array>
<string-array name="set_profile_image_shape_entries">
<item>Circle</item>
<item>Diamond</item>
<item>Octagon</item>
<item>Rounded Square</item>
<item>Square</item>
</string-array>
<string-array name="set_profile_image_shape_entry_values" translatable="false">
<item>circle</item>
<item>diamond</item>
<item>octagon</item>
<item>rounded_square</item>
<item>square</item>
</string-array>
<string-array name="set_logo_type_value" translatable="false">
<item>Fedilab</item>
<item>Fedilab UA</item>
@ -1304,6 +1320,7 @@
<string name="SET_DISPLAY_RELATIVE_DATE" translatable="false">SET_DISPLAY_RELATIVE_DATE</string>
<string name="SET_REMOVE_LEFT_MARGIN" translatable="false">SET_REMOVE_LEFT_MARGIN</string>
<string name="SET_PROFILE_IMAGE_SHAPE" translatable="false">SET_PROFILE_IMAGE_SHAPE</string>
<string name="SET_PROFILE_REMOTELY" translatable="false">SET_PROFILE_REMOTELY</string>
<string name="SET_CONVERSATION_REMOTELY" translatable="false">SET_CONVERSATION_REMOTELY</string>
<string name="SET_EXTAND_EXTRA_FEATURES" translatable="false">SET_EXTAND_EXTRA_FEATURES</string>
@ -2101,6 +2118,7 @@
<string name="set_remote_conversation_title">Remote conversations</string>
<string name="set_remote_profile">The app will display publicly profiles to get all messages. Interactions will need an extra step to federate messages.</string>
<string name="set_remote_conversation">The app will display publicly conversations to get all messages. Interactions will need an extra step to federate messages.</string>
<string name="set_profile_image_shape">Profile image shape</string>
<string name="local_only">Local only</string>
<string name="set_display_local_only">Display \"Local only\" button</string>
<string name="set_pixelfed_presentation">Pixelfed presentation for media</string>

View file

@ -285,4 +285,28 @@
<style name="AppSwitchPreferenceCompatStyle" parent="@style/Preference.SwitchPreferenceCompat.Material">
<item name="widgetLayout">@layout/preference_switch_material</item>
</style>
<!-- Profile image shapes -->
<style name="ShapeAppearanceOverlay.Fedilab.ProfileImage.Circle" parent="">
<item name="cornerSize">50%</item>
</style>
<style name="ShapeAppearanceOverlay.Fedilab.ProfileImage.Diamond" parent="">
<item name="cornerSize">50%</item>
<item name="cornerFamily">cut</item>
</style>
<style name="ShapeAppearanceOverlay.Fedilab.ProfileImage.Octagon" parent="">
<item name="cornerSize">29%</item>
<item name="cornerFamily">cut</item>
</style>
<style name="ShapeAppearanceOverlay.Fedilab.ProfileImage.RoundedSquare" parent="">
<item name="cornerSize">12%</item>
<item name="cornerFamily">rounded</item>
</style>
<style name="ShapeAppearanceOverlay.Fedilab.ProfileImage.Square" parent="">
<item name="cornerSize">0dp</item>
</style>
</resources>

View file

@ -59,6 +59,13 @@
app:summary="@string/set_remote_profile"
app:title="@string/set_remote_profile_title" />
<ListPreference
android:entries="@array/set_profile_image_shape_entries"
android:entryValues="@array/set_profile_image_shape_entry_values"
android:title="@string/set_profile_image_shape"
android:defaultValue="rounded_square"
app:key="@string/SET_PROFILE_IMAGE_SHAPE"
app:useSimpleSummaryProvider="true" />
<SwitchPreferenceCompat
app:defaultValue="true"