Skip to content

Commit

Permalink
Add HA cloud badge to servers (#2829)
Browse files Browse the repository at this point in the history
<!-- Thank you for submitting a Pull Request and helping to improve Home
Assistant. Please complete the following sections to help the processing
and review of your changes. Please do not delete anything from this
template. -->

## Summary
<!-- Provide a brief summary of the changes you have made and most
importantly what they aim to achieve -->

## Screenshots
<!-- If this is a user-facing change not in the frontend, please include
screenshots in light and dark mode. -->
<img width="698" alt="Screenshot 2024-06-27 at 16 40 54"
src="https://github.com/home-assistant/iOS/assets/5808343/011587c6-9aa1-475c-bcbd-2b769e2d2f76">

## Link to pull request in Documentation repository
<!-- Pull requests that add, change or remove functionality must have a
corresponding pull request in the Companion App Documentation repository
(https://github.com/home-assistant/companion.home-assistant). Please add
the number of this pull request after the "#" -->
Documentation: home-assistant/companion.home-assistant#

## Any other notes
<!-- If there is any other information of note, like if this Pull
Request is part of a bigger change, please include it here. -->
  • Loading branch information
bgoncal committed Jul 2, 2024
1 parent 8f2362e commit a10c49a
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 1 deletion.
6 changes: 6 additions & 0 deletions HomeAssistant.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,8 @@
42A818E32BBEA9780083D045 /* MockAudioRecorder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42A818E22BBEA9780083D045 /* MockAudioRecorder.swift */; };
42A818E52BBEAA3A0083D045 /* MockAudioPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42A818E42BBEAA3A0083D045 /* MockAudioPlayer.swift */; };
42A818E72BBEAAE80083D045 /* MockAssistService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42A818E62BBEAAE80083D045 /* MockAssistService.swift */; };
42AA4C822C2DA56100EA2E99 /* SharedAssets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 420B10032B1CF6D800D383D8 /* SharedAssets.xcassets */; };
42AA4C842C2DACAD00EA2E99 /* UIImage+Circle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42AA4C832C2DACAD00EA2E99 /* UIImage+Circle.swift */; };
42B94BDD2B9606CD00DEE060 /* AssistChatItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42B94BDA2B9606CD00DEE060 /* AssistChatItem.swift */; };
42B94BDE2B9606CD00DEE060 /* AssistViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42B94BDB2B9606CD00DEE060 /* AssistViewModel.swift */; };
42B94BDF2B9606CD00DEE060 /* AssistView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42B94BDC2B9606CD00DEE060 /* AssistView.swift */; };
Expand Down Expand Up @@ -1753,6 +1755,7 @@
42A818E22BBEA9780083D045 /* MockAudioRecorder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockAudioRecorder.swift; sourceTree = "<group>"; };
42A818E42BBEAA3A0083D045 /* MockAudioPlayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockAudioPlayer.swift; sourceTree = "<group>"; };
42A818E62BBEAAE80083D045 /* MockAssistService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockAssistService.swift; sourceTree = "<group>"; };
42AA4C832C2DACAD00EA2E99 /* UIImage+Circle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+Circle.swift"; sourceTree = "<group>"; };
42B94BDA2B9606CD00DEE060 /* AssistChatItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssistChatItem.swift; sourceTree = "<group>"; };
42B94BDB2B9606CD00DEE060 /* AssistViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssistViewModel.swift; sourceTree = "<group>"; };
42B94BDC2B9606CD00DEE060 /* AssistView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssistView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3167,6 +3170,7 @@
B6617EEC1CFE79AD004DEE6D /* NSURL+QueryDictionary.swift */,
11B62DBF24F2F06100E5CB55 /* UIApplication+OpenSettings.swift */,
39A32EE12C0E384E00985722 /* UIImage+scaledToSize.swift */,
42AA4C832C2DACAD00EA2E99 /* UIImage+Circle.swift */,
117D8A0724A9347F00580913 /* UIColor+CSSRGB.swift */,
);
path = Extensions;
Expand Down Expand Up @@ -5328,6 +5332,7 @@
4278DFD32B45C7AE0087C9D7 /* Core.strings in Resources */,
1165705B2702A3BA003906A7 /* Frontend.strings in Resources */,
11F855D724DF6C7A0018013E /* MaterialDesignIcons.ttf in Resources */,
42AA4C822C2DA56100EA2E99 /* SharedAssets.xcassets in Resources */,
113E72ED251842BE004006D8 /* Localizable.strings in Resources */,
84F7755EFB03C3F463292ABF /* Pods-watchOS-Shared-watchOS-metadata.plist in Resources */,
);
Expand Down Expand Up @@ -6095,6 +6100,7 @@
1185DF96271FBB9800ED7D9A /* OnboardingAuthLogin.swift in Sources */,
425573E62B5838B600145217 /* MaterialDesignIcons+CarPlay.swift in Sources */,
421B1C1A2BD65255001ED18C /* WidgetsSettingsView+build.swift in Sources */,
42AA4C842C2DACAD00EA2E99 /* UIImage+Circle.swift in Sources */,
42F1DA612B4D4F31002729BC /* CarPlayNoServerAlert.swift in Sources */,
11C590ED24A832CA0066085D /* YamlSection.swift in Sources */,
4296C36D2B90DB640051B63C /* IntentActionAppEntity.swift in Sources */,
Expand Down
17 changes: 16 additions & 1 deletion Sources/App/Settings/Eureka/AccountRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class AccountCell: Cell<AccountRowValue>, CellType {
let userName = accountRow?.cachedUserName
let locationName = server.info.name
let size = AccountInitialsImage.defaultSize
let showHACloudBadge = server.info.connection.canUseCloud

if let imageView {
if let image = accountRow?.cachedImage {
Expand All @@ -80,7 +81,21 @@ class AccountCell: Cell<AccountRowValue>, CellType {
imageView.image = AccountInitialsImage.image(for: userName ?? "?")
}

imageView.layer.cornerRadius = ceil(size.height / 2.0)
// Cropping image instead of image view to avoid cropping HA cloud badge too
imageView.image = imageView.image?.croppedToCircle()

if showHACloudBadge {
let badgeImage = Asset.SharedAssets.haCloudLogo.image
let haCloudBadge = UIImageView(image: badgeImage)
imageView.addSubview(haCloudBadge)
imageView.contentMode = .scaleAspectFit
haCloudBadge.translatesAutoresizingMaskIntoConstraints = false
haCloudBadge.clipsToBounds = false
NSLayoutConstraint.activate([
haCloudBadge.bottomAnchor.constraint(equalTo: imageView.bottomAnchor),
haCloudBadge.trailingAnchor.constraint(equalTo: imageView.trailingAnchor),
])
}
}

accessoryType = .disclosureIndicator
Expand Down
25 changes: 25 additions & 0 deletions Sources/App/Utilities/Extensions/UIImage+Circle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import CoreGraphics
import Foundation
import UIKit

extension UIImage {
func croppedToCircle() -> UIImage {
UIGraphicsBeginImageContextWithOptions(size, false, scale)

let circleWidth = size.width
let radius = circleWidth / 2

let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
UIBezierPath(roundedRect: rect, cornerRadius: radius).addClip()
draw(in: rect)

let newImage: UIImage? = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

if let newImage {
return newImage
} else {
return self
}
}
}
1 change: 1 addition & 0 deletions Sources/Shared/Assets/Assets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public enum Asset {
}
public enum SharedAssets {
public static let logo = ImageAsset(name: "Logo")
public static let haCloudLogo = ImageAsset(name: "ha-cloud-logo")
public static let statusItemIcon = ImageAsset(name: "statusItemIcon")
public static let thread = ImageAsset(name: "thread")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "ha-cloud-logo.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.

0 comments on commit a10c49a

Please sign in to comment.