diff --git a/app/lint-baseline.xml b/app/lint-baseline.xml index f96b9e7f5..d755763ca 100644 --- a/app/lint-baseline.xml +++ b/app/lint-baseline.xml @@ -1748,7 +1748,7 @@ errorLine2=" ~~~~~~~~"> diff --git a/app/src/main/java/app/pachli/components/compose/ComposeActivity.kt b/app/src/main/java/app/pachli/components/compose/ComposeActivity.kt index 2b16f3050..6cd008a16 100644 --- a/app/src/main/java/app/pachli/components/compose/ComposeActivity.kt +++ b/app/src/main/java/app/pachli/components/compose/ComposeActivity.kt @@ -99,6 +99,8 @@ import app.pachli.util.getInitialLanguages import app.pachli.util.getLocaleList import app.pachli.util.getMediaSize import app.pachli.util.highlightSpans +import app.pachli.util.iconRes +import app.pachli.util.makeIcon import app.pachli.util.modernLanguageCode import app.pachli.util.setDrawableTint import com.canhub.cropper.CropImage @@ -108,8 +110,8 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.color.MaterialColors import com.google.android.material.snackbar.Snackbar import com.mikepenz.iconics.IconicsDrawable +import com.mikepenz.iconics.IconicsSize import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial -import com.mikepenz.iconics.utils.colorInt import com.mikepenz.iconics.utils.sizeDp import dagger.hilt.android.AndroidEntryPoint import java.io.File @@ -515,24 +517,13 @@ class ComposeActivity : displayTransientMessage(R.string.hint_media_description_missing) } - val textColor = MaterialColors.getColor(binding.root, android.R.attr.textColorTertiary) - - val cameraIcon = IconicsDrawable(this, GoogleMaterial.Icon.gmd_camera_alt).apply { - colorInt = textColor - sizeDp = 18 - } + val cameraIcon = makeIcon(this, GoogleMaterial.Icon.gmd_camera_alt, IconicsSize.dp(18)) binding.actionPhotoTake.setCompoundDrawablesRelativeWithIntrinsicBounds(cameraIcon, null, null, null) - val imageIcon = IconicsDrawable(this, GoogleMaterial.Icon.gmd_image).apply { - colorInt = textColor - sizeDp = 18 - } + val imageIcon = makeIcon(this, GoogleMaterial.Icon.gmd_image, IconicsSize.dp(18)) binding.actionPhotoPick.setCompoundDrawablesRelativeWithIntrinsicBounds(imageIcon, null, null, null) - val pollIcon = IconicsDrawable(this, GoogleMaterial.Icon.gmd_poll).apply { - colorInt = textColor - sizeDp = 18 - } + val pollIcon = makeIcon(this, GoogleMaterial.Icon.gmd_poll, IconicsSize.dp(18)) binding.addPollTextActionTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(pollIcon, null, null, null) binding.actionPhotoTake.visible(Intent(MediaStore.ACTION_IMAGE_CAPTURE).resolveActivity(packageManager) != null) @@ -754,15 +745,9 @@ class ComposeActivity : private fun setStatusVisibility(visibility: Status.Visibility) { binding.composeOptionsBottomSheet.setStatusVisibility(visibility) - binding.composeTootButton.setStatusVisibility(visibility) + binding.composeTootButton.setStatusVisibility(binding.composeTootButton, visibility) - val iconRes = when (visibility) { - Status.Visibility.PUBLIC -> R.drawable.ic_public_24dp - Status.Visibility.PRIVATE -> R.drawable.ic_lock_outline_24dp - Status.Visibility.DIRECT -> R.drawable.ic_email_24dp - Status.Visibility.UNLISTED -> R.drawable.ic_lock_open_24dp - else -> R.drawable.ic_lock_open_24dp - } + val iconRes = visibility.iconRes() ?: R.drawable.ic_lock_open_24dp binding.composeToggleVisibilityButton.setImageResource(iconRes) if (viewModel.editing) { // Can't update visibility on published status diff --git a/app/src/main/java/app/pachli/components/compose/view/TootButton.kt b/app/src/main/java/app/pachli/components/compose/view/TootButton.kt index f679e841c..d4dac542f 100644 --- a/app/src/main/java/app/pachli/components/compose/view/TootButton.kt +++ b/app/src/main/java/app/pachli/components/compose/view/TootButton.kt @@ -17,16 +17,13 @@ package app.pachli.components.compose.view import android.content.Context -import android.graphics.Color import android.util.AttributeSet +import android.view.View import app.pachli.R import app.pachli.core.designsystem.R as DR import app.pachli.core.network.model.Status +import app.pachli.util.iconDrawable import com.google.android.material.button.MaterialButton -import com.mikepenz.iconics.IconicsDrawable -import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial -import com.mikepenz.iconics.utils.colorInt -import com.mikepenz.iconics.utils.sizeDp class TootButton @JvmOverloads constructor( @@ -48,29 +45,16 @@ class TootButton setPadding(padding, 0, padding, 0) } - fun setStatusVisibility(visibility: Status.Visibility) { + fun setStatusVisibility(view: View, visibility: Status.Visibility) { if (!smallStyle) { - icon = when (visibility) { - Status.Visibility.PUBLIC -> { - setText(R.string.action_send_public) - null - } - Status.Visibility.UNLISTED -> { - setText(R.string.action_send) - null - } - Status.Visibility.PRIVATE, - Status.Visibility.DIRECT, - -> { - setText(R.string.action_send) - IconicsDrawable(context, GoogleMaterial.Icon.gmd_lock).apply { - sizeDp = 18 - colorInt = Color.WHITE - } - } - else -> { - null - } + icon = visibility.iconDrawable(view) + + when (visibility) { + Status.Visibility.UNKNOWN -> { /* do nothing */ } + Status.Visibility.PUBLIC -> setText(R.string.action_send_public) + Status.Visibility.UNLISTED -> setText(R.string.action_send) + Status.Visibility.PRIVATE -> setText(R.string.action_send) + Status.Visibility.DIRECT -> setText(R.string.action_send) } } } diff --git a/app/src/main/java/app/pachli/components/preference/AccountPreferencesFragment.kt b/app/src/main/java/app/pachli/components/preference/AccountPreferencesFragment.kt index 8b00bf285..1ceadc2ad 100644 --- a/app/src/main/java/app/pachli/components/preference/AccountPreferencesFragment.kt +++ b/app/src/main/java/app/pachli/components/preference/AccountPreferencesFragment.kt @@ -54,6 +54,7 @@ import app.pachli.settings.switchPreference import app.pachli.util.getInitialLanguages import app.pachli.util.getLocaleList import app.pachli.util.getPachliDisplayName +import app.pachli.util.iconRes import app.pachli.util.makeIcon import com.github.michaelbull.result.getOrElse import com.google.android.material.snackbar.Snackbar @@ -207,9 +208,9 @@ class AccountPreferencesFragment : PreferenceFragmentCompat() { setSummaryProvider { entry } val visibility = accountManager.activeAccount?.defaultPostPrivacy ?: Status.Visibility.PUBLIC value = visibility.serverString() - setIcon(getIconForVisibility(visibility)) + visibility.iconRes()?.let { setIcon(it) } setOnPreferenceChangeListener { _, newValue -> - setIcon(getIconForVisibility(Status.Visibility.byString(newValue as String))) + Status.Visibility.byString(newValue as String).iconRes()?.let { setIcon(it) } syncWithServer(visibility = newValue) true } @@ -344,17 +345,6 @@ class AccountPreferencesFragment : PreferenceFragmentCompat() { } } - @DrawableRes - private fun getIconForVisibility(visibility: Status.Visibility): Int { - return when (visibility) { - Status.Visibility.PRIVATE -> R.drawable.ic_lock_outline_24dp - - Status.Visibility.UNLISTED -> R.drawable.ic_lock_open_24dp - - else -> R.drawable.ic_public_24dp - } - } - @DrawableRes private fun getIconForSensitivity(sensitive: Boolean): Int { return if (sensitive) { diff --git a/app/src/main/java/app/pachli/util/IconUtils.kt b/app/src/main/java/app/pachli/util/IconUtils.kt index f99a7eaf4..ebd09e1b6 100644 --- a/app/src/main/java/app/pachli/util/IconUtils.kt +++ b/app/src/main/java/app/pachli/util/IconUtils.kt @@ -21,8 +21,10 @@ import android.graphics.Color import androidx.annotation.Px import com.google.android.material.color.MaterialColors import com.mikepenz.iconics.IconicsDrawable +import com.mikepenz.iconics.IconicsSize import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import com.mikepenz.iconics.utils.colorInt +import com.mikepenz.iconics.utils.size import com.mikepenz.iconics.utils.sizePx fun makeIcon(context: Context, icon: GoogleMaterial.Icon, @Px iconSize: Int): IconicsDrawable { @@ -31,3 +33,10 @@ fun makeIcon(context: Context, icon: GoogleMaterial.Icon, @Px iconSize: Int): Ic colorInt = MaterialColors.getColor(context, androidx.appcompat.R.attr.colorControlNormal, Color.BLACK) } } + +fun makeIcon(context: Context, icon: GoogleMaterial.Icon, iconSize: IconicsSize): IconicsDrawable { + return IconicsDrawable(context, icon).apply { + size = iconSize + colorInt = MaterialColors.getColor(context, androidx.appcompat.R.attr.colorControlNormal, Color.BLACK) + } +} diff --git a/app/src/main/java/app/pachli/util/StatusExtensions.kt b/app/src/main/java/app/pachli/util/StatusExtensions.kt index 0618a2abc..b8a5e49c6 100644 --- a/app/src/main/java/app/pachli/util/StatusExtensions.kt +++ b/app/src/main/java/app/pachli/util/StatusExtensions.kt @@ -19,7 +19,9 @@ package app.pachli.util import android.content.Context import android.graphics.drawable.Drawable +import android.view.View import android.widget.TextView +import androidx.annotation.DrawableRes import androidx.appcompat.content.res.AppCompatResources import app.pachli.R import app.pachli.core.network.model.Status @@ -43,6 +45,24 @@ fun Status.Visibility?.description(context: Context): CharSequence { return context.getString(resource) } +@DrawableRes +fun Status.Visibility?.iconRes(): Int? { + this ?: return null + + return when (this) { + Status.Visibility.PUBLIC -> R.drawable.ic_public_24dp + Status.Visibility.UNLISTED -> R.drawable.ic_lock_open_24dp + Status.Visibility.PRIVATE -> R.drawable.ic_lock_24dp + Status.Visibility.DIRECT -> R.drawable.ic_email_24dp + Status.Visibility.UNKNOWN -> return null + } +} + +fun Status.Visibility?.iconDrawable(view: View): Drawable? { + val resource = iconRes() ?: return null + return AppCompatResources.getDrawable(view.context, resource) +} + /** * @return An icon for this visibility scaled and coloured to match the text on [textView]. * Returns null if visibility is [Status.Visibility.UNKNOWN]. @@ -50,19 +70,9 @@ fun Status.Visibility?.description(context: Context): CharSequence { fun Status.Visibility?.icon(textView: TextView): Drawable? { this ?: return null - val resource: Int = when (this) { - Status.Visibility.PUBLIC -> R.drawable.ic_public_24dp - Status.Visibility.UNLISTED -> R.drawable.ic_lock_open_24dp - Status.Visibility.PRIVATE -> R.drawable.ic_lock_outline_24dp - Status.Visibility.DIRECT -> R.drawable.ic_email_24dp - Status.Visibility.UNKNOWN -> return null - } - val visibilityDrawable = AppCompatResources.getDrawable( - textView.context, - resource, - ) ?: return null + val drawable = iconDrawable(textView) ?: return null val size = textView.textSize.toInt() - visibilityDrawable.setBounds(0, 0, size, size) - visibilityDrawable.setTint(textView.currentTextColor) - return visibilityDrawable + drawable.setBounds(0, 0, size, size) + drawable.setTint(textView.currentTextColor) + return drawable } diff --git a/app/src/main/res/drawable/ic_email_24dp.xml b/app/src/main/res/drawable/ic_email_24dp.xml index 1bcee1be0..a3335d40f 100644 --- a/app/src/main/res/drawable/ic_email_24dp.xml +++ b/app/src/main/res/drawable/ic_email_24dp.xml @@ -1,7 +1,5 @@ - - - \ No newline at end of file + + + + + diff --git a/app/src/main/res/drawable/ic_lock_24dp.xml b/app/src/main/res/drawable/ic_lock_24dp.xml new file mode 100644 index 000000000..18135499e --- /dev/null +++ b/app/src/main/res/drawable/ic_lock_24dp.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_lock_outline_24dp.xml b/app/src/main/res/drawable/ic_lock_outline_24dp.xml deleted file mode 100644 index 3354b0a91..000000000 --- a/app/src/main/res/drawable/ic_lock_outline_24dp.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/app/src/main/res/layout/activity_compose.xml b/app/src/main/res/layout/activity_compose.xml index 33a0cffe5..afad12f19 100644 --- a/app/src/main/res/layout/activity_compose.xml +++ b/app/src/main/res/layout/activity_compose.xml @@ -198,7 +198,7 @@ android:background="?attr/colorSurface" android:elevation="12dp" android:orientation="vertical" - android:paddingStart="16dp" + android:paddingStart="24dp" android:paddingTop="8dp" android:paddingEnd="16dp" android:paddingBottom="52dp" @@ -210,28 +210,31 @@ android:id="@+id/actionPhotoTake" android:layout_width="match_parent" android:layout_height="wrap_content" + android:gravity="center_vertical" + android:minHeight="48dp" android:drawablePadding="8dp" - android:padding="8dp" android:text="@string/action_photo_take" - android:textSize="?attr/status_text_medium" /> + android:textColor="?android:textColorTertiary" /> + android:textColor="?android:textColorTertiary" /> + android:textColor="?android:textColorTertiary" /> diff --git a/app/src/main/res/layout/view_compose_options.xml b/app/src/main/res/layout/view_compose_options.xml index ee8c70e87..1bec522cc 100644 --- a/app/src/main/res/layout/view_compose_options.xml +++ b/app/src/main/res/layout/view_compose_options.xml @@ -9,8 +9,7 @@ android:id="@+id/publicRadioButton" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginBottom="4dp" - android:layout_weight="1" + android:minHeight="48dp" android:button="@drawable/ic_public_24dp" android:paddingStart="10dp" android:paddingEnd="0dp" @@ -22,9 +21,7 @@ android:id="@+id/unlistedRadioButton" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="4dp" - android:layout_marginBottom="4dp" - android:layout_weight="1" + android:minHeight="48dp" android:button="@drawable/ic_lock_open_24dp" android:paddingStart="10dp" android:paddingEnd="0dp" @@ -36,10 +33,8 @@ android:id="@+id/privateRadioButton" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="4dp" - android:layout_marginBottom="4dp" - android:layout_weight="1" - android:button="@drawable/ic_lock_outline_24dp" + android:minHeight="48dp" + android:button="@drawable/ic_lock_24dp" android:paddingStart="10dp" android:paddingEnd="0dp" android:text="@string/visibility_private" @@ -50,8 +45,7 @@ android:id="@+id/directRadioButton" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="4dp" - android:layout_weight="1" + android:minHeight="48dp" android:button="@drawable/ic_email_24dp" android:paddingStart="10dp" android:paddingEnd="0dp" @@ -59,4 +53,4 @@ android:textColor="?android:textColorTertiary" app:buttonTint="@color/compound_button_color" /> - \ No newline at end of file +