Rev 19 | AutorÃa | Comparar con el anterior | Ultima modificación | Ver Log |
//
// MyCapsuleListingView.swift
// twogetskills
//
// Created by Efrain Yanez Recanatini on 7/27/22.
//
import Foundation
import SwiftUI
import HTMLEntities
struct MyCapsuleListItemView: View {
@EnvironmentObject var appNavigation : AppNavigation
private var viewModel : MyCapsulesListingItemView = MyCapsulesListingItemView()
private let capsuleName : String
private let capsuleDescription : String
private var appData = Environment(\.appData).wrappedValue
init (capsuleUuid : String) {
self.viewModel.fetch(capsuleUuid: capsuleUuid, userUuid: appData.userUuid)
if self.viewModel.capsule.name.count > Constants.MYCAPSULE_TITLE_MAX_LENGTH {
self.capsuleName = String(Array(self.viewModel.capsule.name)[0...Constants.MYCAPSULE_TITLE_MAX_LENGTH]) + "..."
} else {
self.capsuleName = self.viewModel.capsule.name
}
let textHtml = self.viewModel.capsule.description.htmlUnescape()
let regex = "<.*?>"
let repl = ""
let s = textHtml.replacingOccurrences(of: regex, with: repl, options: [.regularExpression])
if s.count > Constants.MYCAPSULE_DESCRIPTION_MAX_LENGTH {
self.capsuleDescription = String(Array(s)[0...Constants.MYCAPSULE_DESCRIPTION_MAX_LENGTH]) + "..."
} else {
self.capsuleDescription = s
}
}
var body: some View {
VStack(spacing: 0 ) {
Group {
HStack {
Group {
if self.viewModel.capsule.image.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
Image(uiImage: UIImage(named: "logo") ?? UIImage())
.resizable()
.resizable()
.aspectRatio(contentMode: .fit)
} else {
CustomAsyncImage(
url: URL(string: self.viewModel.capsule.image.trimmingCharacters(in: .whitespacesAndNewlines))!,
placeholder: { Text(Config.LANG_COMMON_LOADING).font(.footnote).foregroundColor(.black)},
image: {
Image(uiImage: $0).resizable()
}
)
}
} .frame(width: 64, height:97, alignment: .center)
.cornerRadius(5)
.padding(.horizontal, 5)
.padding(5)
VStack(spacing: 0)
{
HStack {
Text(self.capsuleName)
.font(Font.custom(Config.FONT_NAME_BOLD, size: 14))
.foregroundColor(Color("color_capsule_list_item_title_foreground"))
Spacer()
/*
Button(action: {
appData.topicUuidActive = self.viewModel.capsule.topicUuid
appData.capsuleUuidActive = self.viewModel.capsule.uuid
appData.slideUuidActive = ""
appData.save()
appNavigation.subPageSource = .mycapsules
withAnimation {
appNavigation.subpageActive = .slides
}
}, label: {
Image(systemName: "arrowtriangle.right.fill")
.resizable()
.aspectRatio(contentMode: /*@START_MENU_TOKEN@*/.fill/*@END_MENU_TOKEN@*/)
.frame(width: 16, height: 16, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
}).padding(.trailing, 10)
.foregroundColor(Color("color_capsule_list_item_title_foreground"))
*/
}.padding(.top, 10)
HStack {
Text(self.capsuleDescription)
.font(Font.custom(Config.FONT_NAME_REGULAR, size: 14))
.foregroundColor(Color("color_capsule_list_item_description_foreground"))
Spacer()
}.padding(.top, 5)
Spacer()
HStack {
//Spacer()
Text("\(self.viewModel.capsule.viewSlides)/\(self.viewModel.capsule.totalSlides) \(Config.LANG_COMMON_SLIDES)")
.font(Font.custom(Config.FONT_NAME_REGULAR, size: 12))
.foregroundColor(Color("color_capsule_list_item_description_foreground"))
Spacer();
}.padding(.top, 3)
.padding(.trailing, 5)
HStack {
//Spacer()
FiveStarView(rating: self.viewModel.capsule.totalRating, color: Color("color_capsule_list_item_star_foreground"), backgroundColor: Color("color_capsule_list_item_star_background"))
.frame(width: /*@START_MENU_TOKEN@*/100/*@END_MENU_TOKEN@*/, height: 16, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
Spacer()
}
.padding(.top, 3)
.padding(.bottom, 5)
.padding(.leading, 5)
.padding(.trailing, 10)
/*
Button(action: {
appData.topicUuidActive = self.viewModel.capsule.topicUuid
appData.capsuleUuidActive = self.viewModel.capsule.uuid
appData.slideUuidActive = ""
appData.save()
appNavigation.subPageSource = .mycapsules
appNavigation.subpageActive = .commentsandrating
}, label: {
HStack {
FiveStarView(rating: self.viewModel.capsule.totalRating, color: Color("color_capsule_list_item_star_foreground"), backgroundColor: Color("color_capsule_list_item_star_background")) .frame(width: /*@START_MENU_TOKEN@*/100/*@END_MENU_TOKEN@*/, height: 16, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
.padding(.leading, 8)
Spacer()
Text("\(self.viewModel.capsule.totalComments)")
.font(Font.custom(Config.FONT_NAME_REGULAR, size: 16))
.foregroundColor(Color("color_capsule_list_item_description_foreground"))
Image(systemName: "message")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 16, height: 16, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
.padding(.trailing, 16)
.foregroundColor(Color("color_capsule_list_item_description_foreground"))
}
}).padding(.top, 3)*/
//Spacer()
}
}
}
Divider()
} .background(Color("color_capsule_list_item_background"))
.padding(.leading, 5)
.padding(.trailing, 5)
}
}
struct MyCapsuleListItemView_Previews: PreviewProvider {
static var previews: some View {
MyCapsuleListItemView(capsuleUuid : "C123")
}
}