-
-
Notifications
You must be signed in to change notification settings - Fork 78
User profile screen UX/UI redesign #890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
roihershberg
wants to merge
15
commits into
evilcorpltd:master
Choose a base branch
from
roihershberg:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
560a7c2
Created AvatarMaker for handling avatar images
roihershberg 88bf795
Redesigned profile view screen + Related code cleanup
roihershberg 8220a02
Added edit profile screen + related code cleanup
roihershberg d230af7
Merge pull request #1 from roihershberg/profile_settings_ux_redesign
roihershberg 6e1893a
Merge branch 'master' of https://github.com/evilcorpltd/aTox into evi…
roihershberg 409602b
Resolve rebase conflicts
roihershberg b809d2f
Resolve rebase conflicts
roihershberg 82517e4
Removed no longer used status dialog
roihershberg 6e9834c
Fixed status icon color on API < 23
roihershberg 44f5b21
Resolve ktlint errors
roihershberg f3da907
Added migration of the database with avatarUri field
roihershberg 5430aac
Reverted unnecessary and unrelated changes
roihershberg c432393
Cleaned the code of toolbar icon and color methods
roihershberg 39f41d3
Resolved ktlint errors
roihershberg 65df88f
Maybe resolve displaying of QR in smaller displays
roihershberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| // SPDX-FileCopyrightText: 2019-2021 aTox contributors | ||
| // | ||
| // SPDX-License-Identifier: GPL-3.0-only | ||
|
|
||
| package ltd.evilcorp.atox.ui | ||
|
|
||
| import android.graphics.Bitmap | ||
| import android.graphics.Canvas | ||
| import android.graphics.Color | ||
| import android.graphics.Paint | ||
| import android.graphics.Rect | ||
| import android.graphics.RectF | ||
| import android.graphics.Typeface | ||
| import android.net.Uri | ||
| import android.widget.ImageView | ||
| import ltd.evilcorp.atox.R | ||
| import ltd.evilcorp.core.vo.Contact | ||
| import ltd.evilcorp.core.vo.User | ||
| import kotlin.math.abs | ||
|
|
||
| internal enum class SizeUnit { | ||
| DP, | ||
| PX, | ||
| } | ||
|
|
||
| /** | ||
| * Class for creating an avatar for user or contact and setting it in the ImageView | ||
| */ | ||
| internal class AvatarMaker { | ||
|
|
||
| companion object { | ||
| private const val DEFAULT_AVATAR_SIZE_DP = 50 | ||
| } | ||
|
|
||
| private var name: String = "" | ||
| private var publicKey: String = "" | ||
| private var avatarUri: String = "" | ||
| private var initials: String = "" | ||
|
|
||
| constructor(contact: Contact) { | ||
| name = contact.name | ||
| publicKey = contact.publicKey | ||
| avatarUri = contact.avatarUri | ||
| initials = getInitials() | ||
| } | ||
| constructor(user: User) { | ||
| name = user.name | ||
| publicKey = user.publicKey | ||
| avatarUri = user.avatarUri | ||
| initials = getInitials() | ||
| } | ||
|
|
||
| /** | ||
| * Method will get the initial characters of the name | ||
| * @return The initial characters of the name. | ||
| */ | ||
| private fun getInitials(): String { | ||
| val segments = name.split(" ") | ||
| if (segments.size == 1) return segments.first().take(1) | ||
| return segments.first().take(1) + segments[1][0] | ||
| } | ||
|
|
||
| /** | ||
| * Method will set an avatar to an image view. If avatar image exists then it will be set to the image view, | ||
| * otherwise a new avatar image will be created based on the initials of the name | ||
| * and the public key for the background color. | ||
| * @param imageView The image view for whom to set the avatar image. | ||
| * @param size The size of the avatar image in the units specified in sizeUnit (default: DP units). | ||
| * @param sizeUnit The size unit of size parameter. | ||
| */ | ||
| fun setAvatar(imageView: ImageView, size: Int = DEFAULT_AVATAR_SIZE_DP, sizeUnit: SizeUnit = SizeUnit.DP) = | ||
| if (avatarUri.isNotEmpty()) { | ||
| imageView.setImageURI(Uri.parse(avatarUri)) | ||
| } else { | ||
| val side: Int | ||
| val textScale: Float | ||
|
|
||
| if (sizeUnit == SizeUnit.DP) { | ||
| side = (size * imageView.resources.displayMetrics.density).toInt() | ||
| textScale = size.toFloat() / DEFAULT_AVATAR_SIZE_DP | ||
| } else { | ||
| side = size | ||
| textScale = size.toFloat() / dpToPx(DEFAULT_AVATAR_SIZE_DP.toFloat(), imageView.resources) | ||
| } | ||
|
|
||
| val bitmap = Bitmap.createBitmap(side, side, Bitmap.Config.ARGB_8888) | ||
| val canvas = Canvas(bitmap) | ||
| val rect = RectF(0f, 0f, bitmap.width.toFloat(), bitmap.height.toFloat()) | ||
| val colors = imageView.resources.getIntArray(R.array.contactBackgrounds) | ||
| val backgroundPaint = Paint().apply { color = colors[abs(publicKey.hashCode()).rem(colors.size)] } | ||
|
|
||
| val textPaint = Paint().apply { | ||
| color = Color.WHITE | ||
| textSize = imageView.resources.getDimension(R.dimen.contact_avatar_placeholder_text) * textScale | ||
| textAlign = Paint.Align.CENTER | ||
| isAntiAlias = true | ||
| typeface = Typeface.create("sans-serif-light", Typeface.NORMAL) | ||
| } | ||
|
|
||
| val textBounds = Rect() | ||
| textPaint.getTextBounds(initials, 0, initials.length, textBounds) | ||
| canvas.drawRoundRect(rect, rect.bottom, rect.right, backgroundPaint) | ||
| canvas.drawText(initials, rect.centerX(), rect.centerY() - textBounds.exactCenterY(), textPaint) | ||
| imageView.setImageBitmap(bitmap) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.