Add saving information about account change.
This commit is contained in:
parent
ea2eb0a972
commit
3638d36d78
|
@ -32,6 +32,12 @@ class ApplicationSettingsHandler {
|
|||
}
|
||||
}
|
||||
|
||||
func setAccountAsDefault(accountData: AccountData) {
|
||||
let defaultSettings = self.getDefaultSettings()
|
||||
defaultSettings.currentAccount = accountData.id
|
||||
CoreDataHandler.shared.save()
|
||||
}
|
||||
|
||||
private func createApplicationSettingsEntity() -> ApplicationSettings {
|
||||
let context = CoreDataHandler.shared.container.viewContext
|
||||
return ApplicationSettings(context: context)
|
||||
|
|
|
@ -33,7 +33,7 @@ struct HomeFeedView: View {
|
|||
imageWidth: item.attachments().first?.metaImageWidth,
|
||||
imageHeight: item.attachments().first?.metaImageHeight)
|
||||
.environmentObject(applicationState)) {
|
||||
ImageRow(status: item)
|
||||
ImageRow(statusData: item)
|
||||
}
|
||||
.buttonStyle(EmptyButtonStyle())
|
||||
}
|
||||
|
|
|
@ -135,6 +135,7 @@ struct MainView: View {
|
|||
ForEach(self.dbAccounts) { account in
|
||||
Button {
|
||||
self.applicationState.accountData = account
|
||||
ApplicationSettingsHandler.shared.setAccountAsDefault(accountData: account)
|
||||
} label: {
|
||||
if self.applicationState.accountData?.id == account.id {
|
||||
Label(account.displayName ?? account.acct, systemImage: "checkmark")
|
||||
|
|
|
@ -9,16 +9,38 @@ import SwiftUI
|
|||
struct ImageRow: View {
|
||||
@State public var status: StatusData
|
||||
|
||||
@State private var imageHeight = UIScreen.main.bounds.width
|
||||
@State private var imageWidth = UIScreen.main.bounds.width
|
||||
@State private var imageHeight: Double
|
||||
@State private var imageWidth: Double
|
||||
|
||||
private let uiImage:UIImage?
|
||||
private let attachmentData: AttachmentData?
|
||||
|
||||
init(statusData: StatusData) {
|
||||
self.status = statusData
|
||||
self.attachmentData = statusData.attachments().first
|
||||
|
||||
if let attachmenData = self.attachmentData, let uiImage = UIImage(data: attachmenData.data) {
|
||||
self.uiImage = uiImage
|
||||
|
||||
let imgHeight = uiImage.size.height
|
||||
let imgWidth = uiImage.size.width
|
||||
let divider = imgWidth / UIScreen.main.bounds.size.width
|
||||
let calculatedHeight = imgHeight / divider
|
||||
|
||||
self.imageWidth = imgWidth
|
||||
self.imageHeight = (calculatedHeight > 0 && calculatedHeight < .infinity) ? calculatedHeight : UIScreen.main.bounds.width
|
||||
} else {
|
||||
self.uiImage = nil
|
||||
self.imageHeight = UIScreen.main.bounds.width
|
||||
self.imageWidth = UIScreen.main.bounds.width
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
if let attachmenData = self.status.attachments().first,
|
||||
let uiImage = UIImage(data: attachmenData.data) {
|
||||
|
||||
if let uiImage, let attachmentData {
|
||||
ZStack {
|
||||
if self.status.sensitive {
|
||||
ContentWarning(blurhash: attachmenData.blurhash, spoilerText: self.status.spoilerText) {
|
||||
ContentWarning(blurhash: attachmentData.blurhash, spoilerText: self.status.spoilerText) {
|
||||
Image(uiImage: uiImage)
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
|
@ -42,25 +64,10 @@ struct ImageRow: View {
|
|||
}
|
||||
}
|
||||
.frame(width: self.imageWidth, height: self.imageHeight)
|
||||
.onAppear {
|
||||
self.recalculateSizeOfDownloadedImage(uiImage: uiImage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func recalculateSizeOfDownloadedImage(uiImage: UIImage) {
|
||||
let imgHeight = uiImage.size.height
|
||||
let imgWidth = uiImage.size.width
|
||||
let calculatedHeight = self.calculateHeight(width: imgWidth, height: imgHeight)
|
||||
self.imageHeight = (calculatedHeight > 0 && calculatedHeight < .infinity) ? calculatedHeight : UIScreen.main.bounds.width
|
||||
}
|
||||
|
||||
private func calculateHeight(width: Double, height: Double) -> CGFloat {
|
||||
let divider = width / UIScreen.main.bounds.size.width
|
||||
return height / divider
|
||||
}
|
||||
}
|
||||
|
||||
struct ImageRow_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
Text("")
|
||||
|
|
Loading…
Reference in New Issue