Convert to use MGSwipeTableCell to provide better swipe capabilities.

This commit is contained in:
Mark Jerde 2017-08-14 23:18:50 -05:00
parent 4fd18601e4
commit aa83f93754
3 changed files with 73 additions and 32 deletions

View file

@ -4,4 +4,5 @@
#import <Foundation/Foundation.h>
#import "FlycutOperator.h"
#import "MGSwipeTableCell/MGSwipeTableCell/MGSwipeTableCell.h"
#import "MGSwipeTableCell/MGSwipeTableCell/MGSwipeButton.h"

View file

@ -93,43 +93,53 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
//let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell", for: indexPath)
let item = UITableViewCell();
let item = MGSwipeTableCell();
item.textLabel?.text = flycut.previousDisplayStrings(indexPath.row + 1, containing: nil).last as! String?
//cell.textLabel?.text = item.textLabel?.text
//cell.detailTextLabel?.text=item.detailTextLabel?.text
let content = flycut.clippingString(withCount: Int32(indexPath.row) )
//configure left buttons
if let url = URL(string: content!) {
if (content?.lowercased().hasPrefix("http"))! {
item.leftButtons = [MGSwipeButton(title: "Open", backgroundColor: .blue, callback: { (cell) -> Bool in
let indexPath = tableView.indexPath(for: cell)
if ( nil != indexPath ) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
tableView.reloadRows(at: [indexPath!], with: UITableViewRowAnimation.none)
}
return true;
})]
item.leftSwipeSettings.transition = .border
item.leftExpansion.buttonIndex=0
}
}
//configure right buttons
item.rightButtons = [MGSwipeButton(title: "Delete", backgroundColor: .red, callback: { (cell) -> Bool in
let indexPath = tableView.indexPath(for: cell)
if ( nil != indexPath ) {
self.flycut.setStackPositionTo( Int32((indexPath?.row)! ))
self.flycut.clearItemAtStackPosition()
tableView.beginUpdates()
tableView.deleteRows(at: [indexPath!], with: .left) // Use .left to look better with swiping left to delete.
tableView.endUpdates()
}
return true;
})]
item.rightSwipeSettings.transition = .border
item.rightExpansion.buttonIndex = 0
return item
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let content = flycut.clippingString(withCount: Int32(indexPath.row) )
print("Select: \(indexPath.row) \(content) OK")
tableView.deselectRow(at: indexPath, animated: true)
UIPasteboard.general.string = content
}
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let deleteAction:UITableViewRowAction = UITableViewRowAction(style: .destructive, title: "Delete") { (rowAction, indexPath) in
self.flycut.setStackPositionTo( Int32(indexPath.row ))
self.flycut.clearItemAtStackPosition()
tableView.deleteRows(at: [indexPath], with: .none)
if ( MGSwipeState.none == (tableView.cellForRow(at: indexPath) as! MGSwipeTableCell).swipeState ) {
let content = flycut.clippingString(withCount: Int32(indexPath.row) )
print("Select: \(indexPath.row) \(content) OK")
tableView.deselectRow(at: indexPath, animated: true)
UIPasteboard.general.string = content
}
var results = [deleteAction]
let content = self.flycut.clippingString(withCount: Int32(indexPath.row) )
if let url = URL(string: content!) {
if (content?.lowercased().hasPrefix("http"))!
{
let openWebAction:UITableViewRowAction = UITableViewRowAction(style: .normal, title: "Open") { (rowAction, indexPath) in
UIApplication.shared.open(url, options: [:], completionHandler: nil)
tableView.reloadRows(at: [indexPath], with: UITableViewRowAnimation.none)
}
openWebAction.backgroundColor = UIColor.blue
results.append(openWebAction)
}
}
return results
}
}

View file

@ -75,6 +75,8 @@
8D2E28871B0669F500AE62C8 /* com.generalarcade.flycut.black.32.png in Resources */ = {isa = PBXBuildFile; fileRef = 8D2E28831B0669F500AE62C8 /* com.generalarcade.flycut.black.32.png */; };
8D2E28881B0669F500AE62C8 /* com.generalarcade.flycut.xout.16.png in Resources */ = {isa = PBXBuildFile; fileRef = 8D2E28841B0669F500AE62C8 /* com.generalarcade.flycut.xout.16.png */; };
8D2E28891B0669F500AE62C8 /* com.generalarcade.flycut.xout.32.png in Resources */ = {isa = PBXBuildFile; fileRef = 8D2E28851B0669F500AE62C8 /* com.generalarcade.flycut.xout.32.png */; };
8DCE82681F4550AA00124117 /* MGSwipeTableCell.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8D0DC8571F3D682800A2A8AF /* MGSwipeTableCell.framework */; };
8DCE82691F4550AA00124117 /* MGSwipeTableCell.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8D0DC8571F3D682800A2A8AF /* MGSwipeTableCell.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
AABE497C09FF9CD000A6A239 /* AppController.m in Sources */ = {isa = PBXBuildFile; fileRef = AABE497B09FF9CD000A6A239 /* AppController.m */; };
AAFAC85F0A1BD9DD00DC6025 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AAFAC84A0A1BD9DD00DC6025 /* Carbon.framework */; };
DBEB0C9C1442F2AE0080D24E /* NSWindow+ULIZoomEffect.h in Headers */ = {isa = PBXBuildFile; fileRef = DBEB0C9A1442F2AE0080D24E /* NSWindow+ULIZoomEffect.h */; };
@ -110,8 +112,29 @@
remoteGlobalIDString = C63EE56A1BBA07ED008F46BB;
remoteInfo = MGSwipeTableCell;
};
8DCE826A1F4550AA00124117 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 8D0DC8391F3D4B6A00A2A8AF /* MGSwipeTableCell.xcodeproj */;
proxyType = 1;
remoteGlobalIDString = C63EE56A1BBA07ED008F46BB;
remoteInfo = MGSwipeTableCell;
};
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
8DCE826C1F4550AA00124117 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
8DCE82691F4550AA00124117 /* MGSwipeTableCell.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
13E42FB307B3F0F600E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
@ -206,6 +229,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
8DCE82681F4550AA00124117 /* MGSwipeTableCell.framework in Frameworks */,
8D0DC85A1F3D697000A2A8AF /* MGSwipeTableCell.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -505,12 +529,13 @@
8D0C11A11F171B140046FAA0 /* Sources */,
8D0C11A21F171B140046FAA0 /* Frameworks */,
8D0C11A31F171B140046FAA0 /* Resources */,
8D5D88001F2063720050D4BD /* Embed App Extensions */,
8DCE826C1F4550AA00124117 /* Embed Frameworks */,
);
buildRules = (
);
dependencies = (
8D0DC8591F3D696B00A2A8AF /* PBXTargetDependency */,
8DCE826B1F4550AA00124117 /* PBXTargetDependency */,
);
name = "Flycut-iOS";
productName = "Flycut-iOS";
@ -811,6 +836,11 @@
name = MGSwipeTableCell;
targetProxy = 8D0DC8581F3D696B00A2A8AF /* PBXContainerItemProxy */;
};
8DCE826B1F4550AA00124117 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
name = MGSwipeTableCell;
targetProxy = 8DCE826A1F4550AA00124117 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin PBXVariantGroup section */