Browse Source

1.增加图生图历史记录示例
2.修改图生图历史记录 cell 大小

100Years 1 month ago
parent
commit
74909fc238

+ 2 - 2
AIEmoji.xcodeproj/project.pbxproj

@@ -1808,7 +1808,7 @@
 				ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
 				CLANG_ENABLE_MODULES = YES;
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 1;
+				CURRENT_PROJECT_VERSION = 2;
 				DEVELOPMENT_TEAM = 65UD255J84;
 				ENABLE_USER_SCRIPT_SANDBOXING = NO;
 				GENERATE_INFOPLIST_FILE = YES;
@@ -1847,7 +1847,7 @@
 				ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
 				CLANG_ENABLE_MODULES = YES;
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 1;
+				CURRENT_PROJECT_VERSION = 2;
 				DEVELOPMENT_TEAM = 65UD255J84;
 				ENABLE_USER_SCRIPT_SANDBOXING = NO;
 				GENERATE_INFOPLIST_FILE = YES;

+ 21 - 0
AIEmoji/Assets.xcassets/PTP/ptp_example_image0.imageset/Contents.json

@@ -0,0 +1,21 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "filename" : "ptp_example_image0.png",
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

BIN
AIEmoji/Assets.xcassets/PTP/ptp_example_image0.imageset/ptp_example_image0.png


+ 21 - 0
AIEmoji/Assets.xcassets/PTP/ptp_example_image1.imageset/Contents.json

@@ -0,0 +1,21 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "filename" : "ptp_example_image1.png",
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

BIN
AIEmoji/Assets.xcassets/PTP/ptp_example_image1.imageset/ptp_example_image1.png


+ 7 - 1
AIEmoji/Business/TSGenmojiVC/TSGenmojiVC/Model/TSGenmojiModel.swift

@@ -8,6 +8,11 @@
 import ObjectMapper
 class TSGenmojiModel: TSBaseModel {
     
+    enum ModelType:Int {
+        case normal
+        case example
+    }
+    
     enum ActionStatus:String ,Equatable {
         case success = "success"//成功
         case pending = "pending"//等待
@@ -18,7 +23,7 @@ class TSGenmojiModel: TSBaseModel {
             return ActionStatus(rawValue: string) ?? .failed
         }
     }
-    
+    var modelType:ModelType = .normal
     var id:Int = 0
     var actionType:String = ""
     var comments:String = ""
@@ -32,6 +37,7 @@ class TSGenmojiModel: TSBaseModel {
     
     
     override func mapping(map: ObjectMapper.Map) {
+        modelType           <- map["modelType"]
         id           <- map["id"]
         actionType   <- map["actionType"]
         comments     <- map["comments"]

+ 31 - 3
AIEmoji/Business/TSGenmojiVC/TSGenmojiVC/View/TSGenmojiItemCell.swift

@@ -7,9 +7,26 @@
 
 class TSGenmojiItemCell: TSBaseCollectionCell {
     
+    lazy var exampleView: UIView = {
+        let exampleView = UIView()
+        exampleView.backgroundColor = "#232323".uiColor.withAlphaComponent(0.3)
+        
+        let textLabel = UILabel.createLabel(
+            text: "Example".localized,
+            font: .font(size: 12),
+            textColor: .white
+        )
+        
+        exampleView.addSubview(textLabel)
+        textLabel.snp.makeConstraints { make in
+            make.top.edges.equalTo(UIEdgeInsets(top: 4, left: 6, bottom: 4, right: 6))
+        }
+        exampleView.isHidden = true
+        return exampleView
+    }()
     
     lazy var showImageView: UIImageView = {
-        let showImageView = UIImageView.createImageView(imageName:"")
+        let showImageView = UIImageView.createImageView(imageName:"",contentMode: .scaleAspectFill)
         showImageView.backgroundColor = .gray
         showImageView.layer.cornerRadius = 18
         return showImageView
@@ -22,14 +39,25 @@ class TSGenmojiItemCell: TSBaseCollectionCell {
             make.leading.equalTo(0)
             make.trailing.bottom.equalTo(0)
         }
+        
+        contentView.addSubview(exampleView)
+        exampleView.snp.makeConstraints { make in
+            make.top.equalTo(8)
+            make.leading.equalTo(8)
+        }
     }
     
     
     override func renderView(with object: Any?, component: TSCollectionViewComponent, attributes: [String : Any]?) {
         super.renderView(with: object, component: component, attributes: attributes)
-        
         if let itemModel = object as? TSGenmojiCoLItemModel{
-            showImageView.setAsyncImage(urlString: itemModel.dataModel.response.resultUrl,contentMode: .scaleAspectFill)
+            if itemModel.dataModel.modelType == .example {
+                exampleView.isHidden = false
+                showImageView.image = UIImage(named: itemModel.dataModel.response.resultUrl)
+            }else{
+                exampleView.isHidden = true
+                showImageView.setAsyncImage(urlString: itemModel.dataModel.response.resultUrl,contentMode: .scaleAspectFill)
+            }
         }
     }
     

+ 15 - 7
AIEmoji/Business/TSGenmojiVC/TSGenmojiVC/ViewModel/TSGenmojiCollectionViewModel.swift

@@ -11,6 +11,13 @@ import ObjectMapper
 private let kTextPicHistoryW = (k_ScreenWidth-32.0-14.0)/2.0
 private let kTextPicHistoryH = kTextPicHistoryW/kTextWHScale
 
+
+let kPTPHistoryDesignW = 165.0
+let kPTPHistoryDesignH = 220.0
+let kPTPHistoryDesignScale = kPTPHistoryDesignW/kPTPHistoryDesignH
+private let kPTPHistoryW = (k_ScreenWidth-32.0-14.0)/2.0
+private let kPTPHistoryH = kPTPHistoryW/kPTPHistoryDesignScale
+
 class TSGenmojiColViewModel: TSBaseModel {
     
     lazy var generateSectionModel: TSGenmojiCoLSectionModel = {
@@ -33,16 +40,15 @@ enum TSGenmojiCoLStyple : Int {
     case ptpEntrance    //图生图入口
     case ptpUpload      //图生图上传
     case ptpSelectStyle //图生图选择样式
-    
+    case ptpPicHistory  //图生图后的历史记录
     
     var sectionInset: UIEdgeInsets {
         switch self {
-            
         case .generate,.textPicGenerate:
             return UIEdgeInsets(top: 17, left: 17, bottom: 20, right: 15)
         case .history:
             return UIEdgeInsets(top: 0, left: 24, bottom: 10, right: 24)
-        case .textPicHistory:
+        case .textPicHistory,.ptpPicHistory:
             return UIEdgeInsets(top: 0, left: 16, bottom: 10, right: 16)
         case .ptpEntrance:
             return UIEdgeInsets(top: 17, left: 17, bottom: 0, right: 15)
@@ -57,7 +63,7 @@ enum TSGenmojiCoLStyple : Int {
             return 0
         case .history:
             return 16
-        case .textPicHistory:
+        case .textPicHistory,.ptpPicHistory:
             return 13
         case .ptpEntrance,.ptpUpload,.ptpSelectStyle:
             return 0
@@ -70,7 +76,7 @@ enum TSGenmojiCoLStyple : Int {
             return 0
         case .history:
             return 16
-        case .textPicHistory:
+        case .textPicHistory,.ptpPicHistory:
             return 13
         case .ptpEntrance,.ptpUpload,.ptpSelectStyle:
             return 0
@@ -92,6 +98,8 @@ enum TSGenmojiCoLStyple : Int {
             return CGSize(width: k_ScreenWidth, height: 248)
         case .ptpSelectStyle:
             return CGSize(width: k_ScreenWidth, height: 110)
+        case .ptpPicHistory:
+            return CGSize(width: kPTPHistoryW, height: kPTPHistoryH)
         }
     }
     
@@ -99,7 +107,7 @@ enum TSGenmojiCoLStyple : Int {
         switch self {
         case .generate,.textPicGenerate:
             return TSGenmojiGennerateCell.self
-        case .history,.textPicHistory:
+        case .history,.textPicHistory,.ptpPicHistory:
             return TSGenmojiItemCell.self
         case .ptpEntrance:
             return TSPTPGeneratorCell.self
@@ -114,7 +122,7 @@ enum TSGenmojiCoLStyple : Int {
         switch self {
         case .generate,.textPicGenerate,.ptpEntrance,.ptpUpload:
             return CGSize.zero
-        case .history,.textPicHistory,.ptpSelectStyle:
+        case .history,.textPicHistory,.ptpPicHistory,.ptpSelectStyle:
             return CGSizeMake(k_ScreenWidth, 60)
         }
     }

+ 34 - 2
AIEmoji/Business/TSPTPGeneratorVC/TSPTPBrowseVC/TSPTPBrowseVC.swift

@@ -185,7 +185,15 @@ extension TSPTPBrowseVC:UICollectionViewDataSource,UICollectionViewDelegate {
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! TSPTPBrowseCell
         if let model = dataModelArray.safeObj(At: indexPath.item){
-            cell.netWorkImageView.setAsyncImage(urlString: model.response.resultUrl,placeholder: kPlaceholderImage,contentMode: .scaleAspectFit)
+
+            if model.modelType == .example {
+//                cell.exampleView.isHidden = false
+                cell.netWorkImageView.image = UIImage(named:model.response.resultUrl)
+            }else{
+//                cell.exampleView.isHidden = true
+                cell.netWorkImageView.setAsyncImage(urlString: model.response.resultUrl,placeholder: kPlaceholderImage,contentMode: .scaleAspectFit)
+            }
+
             cell.vipImageView.isHidden = !model.response.vip
             cell.textLabel.text = model.request.promptSort
         }
@@ -197,8 +205,26 @@ extension TSPTPBrowseVC:UICollectionViewDataSource,UICollectionViewDelegate {
 
 class TSPTPBrowseCell : TSBaseCollectionCell{
 
+    lazy var exampleView: UIView = {
+        let exampleView = UIView()
+        exampleView.backgroundColor = "#232323".uiColor.withAlphaComponent(0.3)
+        
+        let textLabel = UILabel.createLabel(
+            text: "Example".localized,
+            font: .font(size: 12),
+            textColor: .white
+        )
+        
+        exampleView.addSubview(textLabel)
+        textLabel.snp.makeConstraints { make in
+            make.top.edges.equalTo(UIEdgeInsets(top: 4, left: 6, bottom: 4, right: 6))
+        }
+        exampleView.isHidden = true
+        return exampleView
+    }()
+    
     lazy var netWorkImageView : UIImageView = {
-        let netWorkImageView = UIImageView.createImageView(imageName: "",corner: 24.0)
+        let netWorkImageView = UIImageView.createImageView(imageName: "",contentMode: .scaleAspectFit,corner: 24.0)
         return netWorkImageView
     }()
 
@@ -255,5 +281,11 @@ class TSPTPBrowseCell : TSBaseCollectionCell{
             make.trailing.equalTo(5)
         }
         
+        contentView.addSubview(exampleView)
+        exampleView.snp.makeConstraints { make in
+            make.top.equalTo(8)
+            make.leading.equalTo(8)
+        }
+        
     }
 }

+ 0 - 2
AIEmoji/Business/TSPTPGeneratorVC/TSPhotoToPhotoVC/Cell/TSPTPUploadCell.swift

@@ -57,8 +57,6 @@ class TSPTPUploadCell : TSBaseCollectionCell{
     lazy var bgView: UIView = {
         
         let bgView = UIView()
-        bgView.backgroundColor = .white.withAlphaComponent(0.1)
-        bgView.cornerRadius = 16
         bgView.addGestureRecognizer(UITapGestureRecognizer(target: self, action:#selector(clickBgView)))
         let bgImageView = UIImageView.createImageView(imageName: "ptp_upload_bg")
         bgImageView.contentMode = .scaleToFill

+ 27 - 5
AIEmoji/Business/TSPTPGeneratorVC/TSPhotoToPhotoVC/VM/TSPhotoToPhotoVM.swift

@@ -89,7 +89,7 @@ class TSPhotoToPhotoVM {
     
     lazy var historySeciton: TSGenmojiCoLSectionModel = {
         let sectionModel = TSGenmojiCoLSectionModel()
-        sectionModel.style = .textPicHistory
+        sectionModel.style = .ptpPicHistory
         sectionModel.name = "History".localized
         for model in listModelArray {
             let itemModel = TSGenmojiCoLItemModel()
@@ -110,9 +110,35 @@ class TSPhotoToPhotoVM {
     
     var isCanGennerateBlock:((Bool)->Void)?
     init() {
+        if UserDefaults.standard.string(forKey: "insertPTPExampleData") == nil {
+            insertExampleData()
+            UserDefaults.standard.set("1", forKey: "insertPTPExampleData")
+            UserDefaults.standard.synchronize()
+        }
         combinedData()
     }
     
+    func insertExampleData(){
+        let array = [
+            createExampleModel(imageName: "ptp_example_image0"),
+            createExampleModel(imageName: "ptp_example_image1")
+        ]
+        if let jsonString = array.toJSONString() {
+            historyListString = jsonString
+        }
+    }
+    
+    func createExampleModel(imageName:String)->TSGenmojiModel{
+        let model = TSGenmojiModel()
+        model.modelType = .example
+        model.request.prompt = "Example"
+        model.request.promptSort = "Example"
+        model.request.width = 330
+        model.request.height = 440
+        model.response.resultUrl = imageName
+        return model
+    }
+    
     func combinedData(){
         colDataArray.removeAll()
         colDataArray.append(uploadSectionModel)
@@ -129,10 +155,6 @@ extension TSPhotoToPhotoVM {
     //历史记录
     var modelArray:[TSGenmojiModel]{
         get{
-            let sectionModel = TSGenmojiCoLSectionModel()
-            sectionModel.style = .textPicHistory
-            sectionModel.name = "History".localized
-        
             if let modelArray = Mapper<TSGenmojiModel>().mapArray(JSONString: historyListString){
                 return modelArray
             }