Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
Improvement
Browse files Browse the repository at this point in the history
delete avatar - need change later
  • Loading branch information
saeedmozaffariGithub committed Dec 27, 2017
1 parent 41a47af commit c95b109
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,12 @@ class IGChannelInfoTableViewController: UITableViewController , UIGestureRecogni
}
}
})

let deleteAction = UIAlertAction(title: "Delete Main Avatar", style: .destructive, handler: {
(alert: UIAlertAction!) -> Void in
self.deleteAvatar()
})

let ChoosePhoto = UIAlertAction(title: "Choose Photo", style: .default, handler: {
(alert: UIAlertAction!) -> Void in
print("Choose Photo")
Expand All @@ -446,6 +452,9 @@ class IGChannelInfoTableViewController: UITableViewController , UIGestureRecogni
(alert: UIAlertAction!) -> Void in
print("Cancelled")
})
if myRole == .owner || myRole == .admin {
optionMenu.addAction(deleteAction)
}
optionMenu.addAction(ChoosePhoto)
optionMenu.addAction(cancelAction)
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) == true {
Expand All @@ -458,6 +467,37 @@ class IGChannelInfoTableViewController: UITableViewController , UIGestureRecogni
self.present(optionMenu, animated: true, completion: nil)
}

/*
* this method will be deleted main(latest) avatar
*/
func deleteAvatar(){
let avatar = self.avatars[0]
IGChannelAvatarDeleteRequest.Generator.generate(avatarId: avatar.id, roomId: (room?.id)!).success({ (protoResponse) in
DispatchQueue.main.async {
switch protoResponse {
case let channelAvatarDeleteResponse as IGPChannelAvatarDeleteResponse :
IGChannelAvatarDeleteRequest.Handler.interpret(response: channelAvatarDeleteResponse)
self.avatarPhotos?.remove(at: 0)
self.avatars.remove(at: 0)
default:
break
}
}
}).error ({ (errorCode, waitTime) in
switch errorCode {
case .timeout:
DispatchQueue.main.async {
let alert = UIAlertController(title: "Timeout", message: "Please try again later", preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alert.addAction(okAction)
self.present(alert, animated: true, completion: nil)
}
default:
break
}

}).send()
}

// MARK: - Table view data source

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ class IGGroupInfoTableViewController: UITableViewController , UIGestureRecognize
}
}
})

let deleteAction = UIAlertAction(title: "Delete Main Avatar", style: .destructive, handler: {
(alert: UIAlertAction!) -> Void in
self.deleteAvatar()
})

let ChoosePhoto = UIAlertAction(title: "Choose Photo", style: .default, handler: {
(alert: UIAlertAction!) -> Void in
print("Choose Photo")
Expand All @@ -198,6 +204,10 @@ class IGGroupInfoTableViewController: UITableViewController , UIGestureRecognize
(alert: UIAlertAction!) -> Void in
print("Cancelled")
})

if myRole == .owner || myRole == .admin {
optionMenu.addAction(deleteAction)
}
optionMenu.addAction(ChoosePhoto)
optionMenu.addAction(cancelAction)
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) == true {
Expand All @@ -210,6 +220,35 @@ class IGGroupInfoTableViewController: UITableViewController , UIGestureRecognize
self.present(optionMenu, animated: true, completion: nil)

}

func deleteAvatar(){
let avatar = self.avatars[0]
IGGroupAvatarDeleteRequest.Generator.generate(avatarId: avatar.id, roomId: (room?.id)!).success({ (protoResponse) in
DispatchQueue.main.async {
switch protoResponse {
case let groupAvatarDeleteResponse as IGPGroupAvatarDeleteResponse :
IGGroupAvatarDeleteRequest.Handler.interpret(response: groupAvatarDeleteResponse)
self.avatarPhotos?.remove(at: 0)
self.avatars.remove(at: 0)
default:
break
}
}
}).error ({ (errorCode, waitTime) in
switch errorCode {
case .timeout:
DispatchQueue.main.async {
let alert = UIAlertController(title: "Timeout", message: "Please try again later", preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alert.addAction(okAction)
self.present(alert, animated: true, completion: nil)
}
default:
break
}

}).send()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
Expand Down
2 changes: 1 addition & 1 deletion iGap/Supporting FIles/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundleShortVersionString</key>
<string>0.1.1</string>
<key>CFBundleVersion</key>
<string>436</string>
<string>437</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>
Expand Down

0 comments on commit c95b109

Please sign in to comment.