|
@@ -18,6 +18,7 @@ class TSPTPGeneratorVM {
|
|
|
var imageUrl:String?
|
|
|
var upLoadImage:UIImage
|
|
|
|
|
|
+ var generatingProgress = 0
|
|
|
init(prompt:String,upLoadImage:UIImage) {
|
|
|
self.prompt = prompt
|
|
|
self.upLoadImage = upLoadImage
|
|
@@ -25,9 +26,8 @@ class TSPTPGeneratorVM {
|
|
|
|
|
|
|
|
|
func creatImage() {
|
|
|
-
|
|
|
guard let imageUrl = imageUrl else { return }
|
|
|
-
|
|
|
+ generatingProgress = 0
|
|
|
stopNetwork = false
|
|
|
stateDatauPblished = (.start,nil)
|
|
|
stateDatauPblished = (.progressString(generating(progress: 0.0)),nil)
|
|
@@ -55,8 +55,10 @@ class TSPTPGeneratorVM {
|
|
|
case .success:
|
|
|
TSToastShared.hideLoading()
|
|
|
self.stateDatauPblished = (.success(nil),genmojiModel)
|
|
|
+ generatingProgress = 0
|
|
|
case .failed:
|
|
|
self.stateDatauPblished = (.failed(kNetWorkMessage(data: data) ?? ""),nil)
|
|
|
+ generatingProgress = 0
|
|
|
default:
|
|
|
stateDatauPblished = (.progressString(generating(progress: genmojiModel.percent)),nil)
|
|
|
if stopNetwork == false {
|
|
@@ -93,7 +95,9 @@ class TSPTPGeneratorVM {
|
|
|
stateDatauPblished = (.progressString(uploadingPhoto(progress: 0.0)),nil)
|
|
|
uploadImage { [weak self] progress in
|
|
|
guard let self = self else { return }
|
|
|
- stateDatauPblished = (.progressString(uploadingPhoto(progress: progress)),nil)
|
|
|
+ if generatingProgress == 0 {
|
|
|
+ stateDatauPblished = (.progressString(uploadingPhoto(progress: progress)),nil)
|
|
|
+ }
|
|
|
} completion: { [weak self] data, error in
|
|
|
guard let self = self else { return }
|
|
|
if let error = error {
|
|
@@ -110,13 +114,27 @@ class TSPTPGeneratorVM {
|
|
|
|
|
|
func uploadingPhoto(progress:Float) -> String {
|
|
|
//Uploading Photo 0%-100%
|
|
|
- let progressInt = Int(progress*100)
|
|
|
+ var progressInt = Int(progress*100)
|
|
|
+ if progressInt > 99 {
|
|
|
+ progressInt = 99
|
|
|
+ }
|
|
|
return "Uploading Photo \(progressInt)%"
|
|
|
}
|
|
|
|
|
|
func generating(progress:Float) -> String {
|
|
|
+
|
|
|
//Generating 0%-100%
|
|
|
- let progressInt = Int(progress*100)
|
|
|
+ var progressInt = Int(progress*100)
|
|
|
+
|
|
|
+ if generatingProgress >= progressInt{
|
|
|
+ return "Generating \(generatingProgress)%"
|
|
|
+ }
|
|
|
+
|
|
|
+ if progressInt > 99 {
|
|
|
+ progressInt = 99
|
|
|
+ }
|
|
|
+
|
|
|
+ generatingProgress = progressInt
|
|
|
return "Generating \(progressInt)%"
|
|
|
}
|
|
|
}
|