mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-25 17:17:43 +00:00
Migrate KeyboardInfoViewController to Swift
This commit is contained in:
parent
5a47149161
commit
fe3952bfeb
5 changed files with 181 additions and 321 deletions
|
|
@ -61,17 +61,12 @@
|
|||
9878F77E1B8BF07E00360B8D /* UIView+Helpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 9878F7701B8BF00F00360B8D /* UIView+Helpers.m */; };
|
||||
987F00071AB8FD0A00998116 /* KMKeyboardMenuView.m in Sources */ = {isa = PBXBuildFile; fileRef = 987F00061AB8FD0A00998116 /* KMKeyboardMenuView.m */; };
|
||||
987F3E9F1941AAB700209D4F /* KMKeyPreviewView.m in Sources */ = {isa = PBXBuildFile; fileRef = 989FDF91193C1C7100EECAF9 /* KMKeyPreviewView.m */; };
|
||||
987F3EA01941AAC900209D4F /* KeyboardInfoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 989BDF31193D8CEC00278BBC /* KeyboardInfoViewController.m */; };
|
||||
987F3EA11941AAE900209D4F /* KMKeyPreviewView.m in Sources */ = {isa = PBXBuildFile; fileRef = 989FDF91193C1C7100EECAF9 /* KMKeyPreviewView.m */; };
|
||||
987F3EA21941AAF800209D4F /* KeyboardInfoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 989BDF31193D8CEC00278BBC /* KeyboardInfoViewController.m */; };
|
||||
987F3EA31941ABF600209D4F /* KMKeyPreviewView.h in Headers */ = {isa = PBXBuildFile; fileRef = 989FDF90193C1C7100EECAF9 /* KMKeyPreviewView.h */; };
|
||||
987F3EA41941AC0800209D4F /* KeyboardInfoViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 989BDF30193D8CEC00278BBC /* KeyboardInfoViewController.h */; };
|
||||
987F3EA51941AC2700209D4F /* KMKeyPreviewView.h in Headers */ = {isa = PBXBuildFile; fileRef = 989FDF90193C1C7100EECAF9 /* KMKeyPreviewView.h */; };
|
||||
987F3EA61941AC3400209D4F /* KeyboardInfoViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 989BDF30193D8CEC00278BBC /* KeyboardInfoViewController.h */; };
|
||||
988B36B61ADF67290008752C /* inuktitut_pirurvik-1.0.js in Resources */ = {isa = PBXBuildFile; fileRef = 988B36B51ADF67290008752C /* inuktitut_pirurvik-1.0.js */; };
|
||||
988B36B91ADF728A0008752C /* inuktitut_latin-1.0.js in Resources */ = {isa = PBXBuildFile; fileRef = 988B36B71ADF728A0008752C /* inuktitut_latin-1.0.js */; };
|
||||
988B36BA1ADF728A0008752C /* inuktitut_naqittaut-1.0.js in Resources */ = {isa = PBXBuildFile; fileRef = 988B36B81ADF728A0008752C /* inuktitut_naqittaut-1.0.js */; };
|
||||
989BDF32193D8CEC00278BBC /* KeyboardInfoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 989BDF31193D8CEC00278BBC /* KeyboardInfoViewController.m */; };
|
||||
989FDF92193C1C7100EECAF9 /* KMKeyPreviewView.m in Sources */ = {isa = PBXBuildFile; fileRef = 989FDF91193C1C7100EECAF9 /* KMKeyPreviewView.m */; };
|
||||
98ACCE0817A9EEEB00B7C780 /* KeyboardPickerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 98C2648717A0F59900940E4F /* KeyboardPickerViewController.m */; };
|
||||
98ACCE0917A9EF0700B7C780 /* LanguageDetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 98C0B11617A204BF007ECAFC /* LanguageDetailViewController.m */; };
|
||||
|
|
@ -114,6 +109,7 @@
|
|||
C08C620C1F6792A200268D03 /* KeyboardPickerBarButtonItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = C08C620B1F6792A200268D03 /* KeyboardPickerBarButtonItem.swift */; };
|
||||
C08C62101F67BD4500268D03 /* KeyboardPickerButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = C08C620F1F67BD4500268D03 /* KeyboardPickerButton.swift */; };
|
||||
C08C62131F67C31100268D03 /* KeyboardNameTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C08C62121F67C31100268D03 /* KeyboardNameTableViewCell.swift */; };
|
||||
C08C62151F67C8D500268D03 /* KeyboardInfoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C08C62141F67C8D500268D03 /* KeyboardInfoViewController.swift */; };
|
||||
C0A5FF371F6682EB00BE740C /* PopoverView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0A5FF361F6682EB00BE740C /* PopoverView.swift */; };
|
||||
CE25CCBD1F1DA7BB005AA2BC /* KMHTTPDownloader.m in Sources */ = {isa = PBXBuildFile; fileRef = CE25CCBC1F1DA7BB005AA2BC /* KMHTTPDownloader.m */; };
|
||||
CE25CCBE1F1DA7BB005AA2BC /* KMHTTPDownloader.m in Sources */ = {isa = PBXBuildFile; fileRef = CE25CCBC1F1DA7BB005AA2BC /* KMHTTPDownloader.m */; };
|
||||
|
|
@ -232,8 +228,6 @@
|
|||
988B36B51ADF67290008752C /* inuktitut_pirurvik-1.0.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = "inuktitut_pirurvik-1.0.js"; path = "Keyboards/inuktitut_pirurvik-1.0.js"; sourceTree = SOURCE_ROOT; };
|
||||
988B36B71ADF728A0008752C /* inuktitut_latin-1.0.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = "inuktitut_latin-1.0.js"; path = "Keyboards/inuktitut_latin-1.0.js"; sourceTree = SOURCE_ROOT; };
|
||||
988B36B81ADF728A0008752C /* inuktitut_naqittaut-1.0.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = "inuktitut_naqittaut-1.0.js"; path = "Keyboards/inuktitut_naqittaut-1.0.js"; sourceTree = SOURCE_ROOT; };
|
||||
989BDF30193D8CEC00278BBC /* KeyboardInfoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeyboardInfoViewController.h; sourceTree = "<group>"; };
|
||||
989BDF31193D8CEC00278BBC /* KeyboardInfoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KeyboardInfoViewController.m; sourceTree = "<group>"; };
|
||||
989FDF90193C1C7100EECAF9 /* KMKeyPreviewView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KMKeyPreviewView.h; sourceTree = "<group>"; };
|
||||
989FDF91193C1C7100EECAF9 /* KMKeyPreviewView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KMKeyPreviewView.m; sourceTree = "<group>"; };
|
||||
98B34AB817F3B82000DF079E /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
|
||||
|
|
@ -255,6 +249,7 @@
|
|||
C08C620B1F6792A200268D03 /* KeyboardPickerBarButtonItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardPickerBarButtonItem.swift; sourceTree = "<group>"; };
|
||||
C08C620F1F67BD4500268D03 /* KeyboardPickerButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardPickerButton.swift; sourceTree = "<group>"; };
|
||||
C08C62121F67C31100268D03 /* KeyboardNameTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardNameTableViewCell.swift; sourceTree = "<group>"; };
|
||||
C08C62141F67C8D500268D03 /* KeyboardInfoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardInfoViewController.swift; sourceTree = "<group>"; };
|
||||
C0A5FF351F6682EA00BE740C /* KMEI-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "KMEI-Bridging-Header.h"; sourceTree = "<group>"; };
|
||||
C0A5FF361F6682EB00BE740C /* PopoverView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PopoverView.swift; sourceTree = "<group>"; };
|
||||
CE25CCBC1F1DA7BB005AA2BC /* KMHTTPDownloader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KMHTTPDownloader.m; sourceTree = "<group>"; };
|
||||
|
|
@ -595,8 +590,7 @@
|
|||
F2607212158FBCB500F37184 /* KeyboardPicker */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
989BDF30193D8CEC00278BBC /* KeyboardInfoViewController.h */,
|
||||
989BDF31193D8CEC00278BBC /* KeyboardInfoViewController.m */,
|
||||
C08C62141F67C8D500268D03 /* KeyboardInfoViewController.swift */,
|
||||
98C2648617A0F59900940E4F /* KeyboardPickerViewController.h */,
|
||||
98C2648717A0F59900940E4F /* KeyboardPickerViewController.m */,
|
||||
98C0B11517A204BF007ECAFC /* LanguageDetailViewController.h */,
|
||||
|
|
@ -739,7 +733,6 @@
|
|||
CE25CCC61F1F2325005AA2BC /* KMHTTPDownloader.h in Headers */,
|
||||
98EF3BA719A5B05000A1365F /* KMSubKeysView.h in Headers */,
|
||||
980CC8E519D522060089BB57 /* KMURLProtocol.h in Headers */,
|
||||
987F3EA41941AC0800209D4F /* KeyboardInfoViewController.h in Headers */,
|
||||
987F3EA31941ABF600209D4F /* KMKeyPreviewView.h in Headers */,
|
||||
98ACCE0F17A9EFA500B7C780 /* KeyboardPickerViewController.h in Headers */,
|
||||
98ACCE0E17A9EF9700B7C780 /* LanguageViewController.h in Headers */,
|
||||
|
|
@ -763,7 +756,6 @@
|
|||
98EF3BA819A5B06100A1365F /* KMSubKeysView.h in Headers */,
|
||||
CE25CCC41F1F2310005AA2BC /* KMHTTPDownloader.h in Headers */,
|
||||
CE25CCC51F1F2314005AA2BC /* KMHTTPDownloadRequest.h in Headers */,
|
||||
987F3EA61941AC3400209D4F /* KeyboardInfoViewController.h in Headers */,
|
||||
987F3EA51941AC2700209D4F /* KMKeyPreviewView.h in Headers */,
|
||||
98ACCE1717A9F03000B7C780 /* KeyboardPickerViewController.h in Headers */,
|
||||
98ACCE1617A9F02300B7C780 /* LanguageViewController.h in Headers */,
|
||||
|
|
@ -1004,6 +996,7 @@
|
|||
C08C62131F67C31100268D03 /* KeyboardNameTableViewCell.swift in Sources */,
|
||||
987F00071AB8FD0A00998116 /* KMKeyboardMenuView.m in Sources */,
|
||||
980CC8E419D51F3C0089BB57 /* KMURLProtocol.m in Sources */,
|
||||
C08C62151F67C8D500268D03 /* KeyboardInfoViewController.swift in Sources */,
|
||||
CE25CCC31F1DBF6F005AA2BC /* KMHTTPDownloadRequest.m in Sources */,
|
||||
F273AB9915641EC500A47CEE /* KMManager.m in Sources */,
|
||||
CECB38951F2199BC0098882F /* Reachability.m in Sources */,
|
||||
|
|
@ -1012,7 +1005,6 @@
|
|||
9878F7731B8BF00F00360B8D /* UIView+Helpers.m in Sources */,
|
||||
C0A5FF371F6682EB00BE740C /* PopoverView.swift in Sources */,
|
||||
98F9D6F019545AB60087AA43 /* KMInputViewController.m in Sources */,
|
||||
989BDF32193D8CEC00278BBC /* KeyboardInfoViewController.m in Sources */,
|
||||
989FDF92193C1C7100EECAF9 /* KMKeyPreviewView.m in Sources */,
|
||||
CE25CCBD1F1DA7BB005AA2BC /* KMHTTPDownloader.m in Sources */,
|
||||
9878F7711B8BF00F00360B8D /* NSString+Helpers.m in Sources */,
|
||||
|
|
@ -1032,7 +1024,6 @@
|
|||
98EF3BA619A5B03800A1365F /* KMSubKeysView.m in Sources */,
|
||||
98F9D6F7195463390087AA43 /* KMInputViewController.m in Sources */,
|
||||
9878F7741B8BF01F00360B8D /* NSString+Helpers.m in Sources */,
|
||||
987F3EA01941AAC900209D4F /* KeyboardInfoViewController.m in Sources */,
|
||||
987F3E9F1941AAB700209D4F /* KMKeyPreviewView.m in Sources */,
|
||||
98ACCE0817A9EEEB00B7C780 /* KeyboardPickerViewController.m in Sources */,
|
||||
98F9D692195402F90087AA43 /* KMTextView.m in Sources */,
|
||||
|
|
@ -1059,7 +1050,6 @@
|
|||
98EF3BA919A5B07100A1365F /* KMSubKeysView.m in Sources */,
|
||||
98F9D6F61954632A0087AA43 /* KMInputViewController.m in Sources */,
|
||||
9878F7751B8BF01F00360B8D /* NSString+Helpers.m in Sources */,
|
||||
987F3EA21941AAF800209D4F /* KeyboardInfoViewController.m in Sources */,
|
||||
987F3EA11941AAE900209D4F /* KMKeyPreviewView.m in Sources */,
|
||||
98ACCE1317A9EFED00B7C780 /* KeyboardPickerViewController.m in Sources */,
|
||||
98ACCE1217A9EFE100B7C780 /* LanguageViewController.m in Sources */,
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
//
|
||||
// KeyboardInfoViewController.h
|
||||
// KeymanEngine
|
||||
//
|
||||
// Created by Serkan Kurt on 3/06/2014.
|
||||
// Copyright (c) 2017 SIL International. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface KeyboardInfoViewController : UITableViewController <UIAlertViewDelegate>
|
||||
|
||||
@property (nonatomic, assign) NSUInteger keyboardCount;
|
||||
@property (nonatomic, assign) NSInteger keyboardIndex;
|
||||
@property (nonatomic, strong) NSString *keyboardID;
|
||||
@property (nonatomic, strong) NSString *languageID;
|
||||
@property (nonatomic, strong) NSString *keyboardVersion;
|
||||
@property (nonatomic, strong) NSString *keyboardCopyright;
|
||||
@property (assign) BOOL isCustomKeyboard;
|
||||
|
||||
@end
|
||||
|
|
@ -1,285 +0,0 @@
|
|||
//
|
||||
// KeyboardInfoViewController.m
|
||||
// KeymanEngine
|
||||
//
|
||||
// Created by Serkan Kurt on 3/06/2014.
|
||||
// Copyright (c) 2017 SIL International. All rights reserved.
|
||||
//
|
||||
|
||||
#import "KeyboardInfoViewController.h"
|
||||
#import "KMManager+Internal.h"
|
||||
|
||||
#define KMBackgroundQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
|
||||
|
||||
@interface KeyboardInfoViewController ()
|
||||
@property (nonatomic, strong) NSMutableArray *infoArray;
|
||||
@property (nonatomic, strong) NSDictionary *kbDict;
|
||||
@end
|
||||
|
||||
@implementation KeyboardInfoViewController
|
||||
@synthesize keyboardCount, keyboardIndex;
|
||||
@synthesize keyboardID, languageID, keyboardVersion, keyboardCopyright;
|
||||
@synthesize infoArray, isCustomKeyboard;
|
||||
|
||||
- (id)initWithStyle:(UITableViewStyle)style
|
||||
{
|
||||
self = [super initWithStyle:style];
|
||||
if (self) {
|
||||
// Custom initialization
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
// Copyright info is disabled
|
||||
/*
|
||||
NSString *kbCopyright;
|
||||
NSString *deviceType = ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)?@"iphone":@"ipad";
|
||||
NSString *urlStr = [NSString stringWithFormat:@"%@languages/%@/%@?device=%@", kKeymanApiBaseURL, languageID, keyboardID, deviceType];
|
||||
|
||||
if (keyboardCopyright == nil || ![keyboardCopyright length]) {
|
||||
kbCopyright = @"Unknown";
|
||||
dispatch_async(KMBackgroundQueue, ^{
|
||||
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlStr]];
|
||||
[self performSelectorOnMainThread:@selector(fetchedKeyboardData:)
|
||||
withObject:data waitUntilDone:YES];
|
||||
});
|
||||
}
|
||||
else
|
||||
kbCopyright = keyboardCopyright;
|
||||
*/
|
||||
|
||||
infoArray = [[NSMutableArray alloc] initWithCapacity:3];
|
||||
[infoArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"Keyboard version", @"title", keyboardVersion, @"subtitle", nil]];
|
||||
//[infoArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"Copyright", @"title", kbCopyright, @"subtitle", nil]];
|
||||
if (!isCustomKeyboard) {
|
||||
[infoArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"Help link", @"title", @"", @"subtitle", nil]];
|
||||
}
|
||||
[infoArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"Delete", @"title", @"", @"subtitle", nil]];
|
||||
|
||||
// Uncomment the following line to preserve selection between presentations.
|
||||
// self.clearsSelectionOnViewWillAppear = NO;
|
||||
|
||||
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
|
||||
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
|
||||
}
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated {
|
||||
[super viewDidAppear:animated];
|
||||
[self.navigationController setToolbarHidden:YES animated:YES];
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning
|
||||
{
|
||||
[super didReceiveMemoryWarning];
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
#pragma mark - Table view data source
|
||||
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||||
{
|
||||
if (isCustomKeyboard)
|
||||
return 2;
|
||||
else
|
||||
return 3;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
static NSString *cellIdentifier = @"Cell";
|
||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
|
||||
if (!cell) {
|
||||
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
if (!isCustomKeyboard) {
|
||||
if( indexPath.row == 1) {
|
||||
NSString *helpUrlStr = [NSString stringWithFormat:@"http://help.keyman.com/keyboard/%@/%@/", keyboardID, keyboardVersion];
|
||||
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:helpUrlStr]];
|
||||
}
|
||||
else if (indexPath.row == 2) {
|
||||
[self showDeleteKeyboard];
|
||||
}
|
||||
}
|
||||
else if (indexPath.row == 1) {
|
||||
[self showDeleteKeyboard];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// Override to support conditional editing of the table view.
|
||||
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
// Return NO if you do not want the specified item to be editable.
|
||||
return YES;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// Override to support editing the table view.
|
||||
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
if (editingStyle == UITableViewCellEditingStyleDelete) {
|
||||
// Delete the row from the data source
|
||||
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
|
||||
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
|
||||
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// Override to support rearranging the table view.
|
||||
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
|
||||
{
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// Override to support conditional rearranging of the table view.
|
||||
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
// Return NO if you do not want the item to be re-orderable.
|
||||
return YES;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
#pragma mark - Navigation
|
||||
|
||||
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
||||
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
|
||||
{
|
||||
// Get the new view controller using [segue destinationViewController].
|
||||
// Pass the selected object to the new view controller.
|
||||
}
|
||||
*/
|
||||
|
||||
- (void)fetchedKeyboardData:(NSData *)data {
|
||||
NSError *error;
|
||||
NSDictionary *json = [NSJSONSerialization
|
||||
JSONObjectWithData:data
|
||||
options:0
|
||||
error:&error];
|
||||
if (error == nil) {
|
||||
NSArray *keyboards = [[json objectForKey:kKeymanLanguageKey] objectForKey:kKeymanLanguageKeyboardsKey];
|
||||
NSDictionary *kbDict = [keyboards objectAtIndex:0];
|
||||
NSMutableDictionary *info = [infoArray objectAtIndex:1];
|
||||
NSString *copyright = [kbDict objectForKey:kKeymanKeyboardCopyrightKey];
|
||||
if (copyright == nil)
|
||||
copyright = @"Unknown";
|
||||
|
||||
[info setObject:copyright forKey:@"subtitle"];
|
||||
[infoArray replaceObjectAtIndex:1 withObject:info];
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Table view delegate
|
||||
|
||||
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
|
||||
[cell setAccessoryType:UITableViewCellAccessoryNone];
|
||||
cell.textLabel.text = [[infoArray objectAtIndex:indexPath.row] objectForKey:@"title"];
|
||||
cell.detailTextLabel.text = [[infoArray objectAtIndex:indexPath.row] objectForKey:@"subtitle"];
|
||||
cell.tag = indexPath.row;
|
||||
if (!isCustomKeyboard) {
|
||||
if (indexPath.row == 1)
|
||||
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
|
||||
else if (indexPath.row == 2 && ![self canDeleteKeyboard]) {
|
||||
cell.userInteractionEnabled = NO;
|
||||
cell.textLabel.enabled = NO;
|
||||
cell.detailTextLabel.enabled = NO;
|
||||
}
|
||||
}
|
||||
else if (indexPath.row == 1 && ![self canDeleteKeyboard]) {
|
||||
cell.userInteractionEnabled = NO;
|
||||
cell.textLabel.enabled = NO;
|
||||
cell.detailTextLabel.enabled = NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)isCurrentKeyboard {
|
||||
if ([[KMManager sharedInstance].keyboardID isEqualToString:keyboardID] && [[KMManager sharedInstance].languageID isEqualToString:languageID]) {
|
||||
return YES;
|
||||
}
|
||||
else {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)canDeleteKeyboard {
|
||||
if (![[KMManager sharedInstance] canRemoveKeyboards])
|
||||
return NO;
|
||||
|
||||
if (![[KMManager sharedInstance] canRemoveDefaultKeyboard]) {
|
||||
if (keyboardIndex == 0)
|
||||
return NO;
|
||||
else
|
||||
return YES;
|
||||
}
|
||||
else {
|
||||
if (keyboardIndex > 0)
|
||||
return YES;
|
||||
else if (keyboardCount > 1)
|
||||
return YES;
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)showDeleteKeyboard {
|
||||
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:self.title
|
||||
message:@"Would you like to delete this keyboard?"
|
||||
delegate:self
|
||||
cancelButtonTitle:@"Cancel"
|
||||
otherButtonTitles:@"Delete", nil];
|
||||
alert.tag = 1;
|
||||
[alert show];
|
||||
}
|
||||
|
||||
#pragma mark - Alert view delegate
|
||||
|
||||
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
|
||||
if (buttonIndex == alertView.cancelButtonIndex)
|
||||
return;
|
||||
|
||||
if (alertView.tag == 1) {
|
||||
NSUserDefaults *userData = [[KMManager sharedInstance] activeUserDefaults];
|
||||
NSArray *userKeyboards = [userData arrayForKey:kKeymanUserKeyboardsListKey];
|
||||
NSDictionary *kbDict = [NSDictionary dictionaryWithDictionary:[userKeyboards objectAtIndex:keyboardIndex]];
|
||||
|
||||
if ([[KMManager sharedInstance] removeKeyboardAtIndex:keyboardIndex]) {
|
||||
if ([self isCurrentKeyboard]) {
|
||||
NSString *kbID = [[userKeyboards objectAtIndex:0] objectForKey:kKeymanKeyboardIdKey];
|
||||
NSString *langID = [[userKeyboards objectAtIndex:0] objectForKey:kKeymanLanguageIdKey];
|
||||
NSString *kbName = [[userKeyboards objectAtIndex:0] objectForKey:kKeymanKeyboardNameKey];
|
||||
NSString *langName = [[userKeyboards objectAtIndex:0] objectForKey:kKeymanLanguageNameKey];
|
||||
NSString *font = [[userKeyboards objectAtIndex:0] objectForKey:kKeymanFontKey];
|
||||
NSString *oskFont = [[userKeyboards objectAtIndex:0] objectForKey:kKeymanOskFontKey];
|
||||
[[KMManager sharedInstance] setKeyboardWithID:kbID languageID:langID keyboardName:kbName languageName:langName font:font oskFont:oskFont];
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kKeymanKeyboardRemovedNotification
|
||||
object:self
|
||||
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:kbDict, kKeymanKeyboardInfoKey, nil]];
|
||||
[self.navigationController popToRootViewControllerAnimated:YES];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -0,0 +1,176 @@
|
|||
//
|
||||
// KeyboardInfoViewController.swift
|
||||
// KeymanEngine
|
||||
//
|
||||
// Created by Gabriel Wong on 2017-09-12.
|
||||
// Copyright © 2017 SIL International. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class KeyboardInfoViewController: UITableViewController, UIAlertViewDelegate {
|
||||
var keyboardCount: Int = 0
|
||||
var keyboardIndex: Int = 0
|
||||
var keyboardID: String = ""
|
||||
var languageID: String = ""
|
||||
var keyboardVersion: String = ""
|
||||
var keyboardCopyright: String = ""
|
||||
var isCustomKeyboard: Bool = false
|
||||
var infoArray = [[String: String]]()
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
infoArray = [[String: String]]()
|
||||
infoArray.append([
|
||||
"title": "Keyboard version",
|
||||
"subtitle": keyboardVersion
|
||||
])
|
||||
|
||||
if !isCustomKeyboard {
|
||||
infoArray.append([
|
||||
"title": "Help link",
|
||||
"subtitle": ""
|
||||
])
|
||||
}
|
||||
infoArray.append([
|
||||
"title": "Delete",
|
||||
"subtitle": ""
|
||||
])
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
navigationController?.setToolbarHidden(true, animated: true)
|
||||
}
|
||||
|
||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||
return 1
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
if isCustomKeyboard {
|
||||
return 2
|
||||
} else {
|
||||
return 3
|
||||
}
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
let cellIdentifier = "Cell"
|
||||
if let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) {
|
||||
return cell
|
||||
}
|
||||
return UITableViewCell(style: .subtitle, reuseIdentifier: cellIdentifier)
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
if !isCustomKeyboard {
|
||||
if indexPath.row == 1 {
|
||||
let helpUrlStr = "http://help.keyman.com/keyboard/\(keyboardID)/\(keyboardVersion)/"
|
||||
UIApplication.shared.openURL(URL(string: helpUrlStr)!)
|
||||
} else if indexPath.row == 2 {
|
||||
showDeleteKeyboard()
|
||||
}
|
||||
} else if indexPath.row == 1 {
|
||||
showDeleteKeyboard()
|
||||
}
|
||||
}
|
||||
|
||||
func fetchedKeyboardData(_ data: Data) {
|
||||
guard let json = (try? JSONSerialization.jsonObject(with: data, options: [])) as? [AnyHashable: Any] else {
|
||||
return
|
||||
}
|
||||
let keyboards = json[kKeymanLanguageKey] as? [Any]
|
||||
let kbDict = keyboards?[0] as? [AnyHashable: Any]
|
||||
var info = infoArray[1]
|
||||
let copyright = kbDict?[kKeymanKeyboardCopyrightKey] as? String ?? "Unknown"
|
||||
|
||||
info["subtitle"] = copyright
|
||||
infoArray[1] = info
|
||||
tableView.reloadData()
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
|
||||
cell.selectionStyle = .none
|
||||
cell.accessoryType = .none
|
||||
cell.textLabel?.text = infoArray[indexPath.row]["title"]
|
||||
cell.detailTextLabel?.text = infoArray[indexPath.row]["subtitle"]
|
||||
cell.tag = indexPath.row
|
||||
|
||||
if !isCustomKeyboard {
|
||||
if indexPath.row == 1 {
|
||||
cell.accessoryType = .disclosureIndicator
|
||||
} else if indexPath.row == 2 && !canDeleteKeyboard() {
|
||||
cell.isUserInteractionEnabled = false
|
||||
cell.textLabel?.isEnabled = false
|
||||
cell.detailTextLabel?.isEnabled = false
|
||||
}
|
||||
} else if indexPath.row == 1 && !canDeleteKeyboard() {
|
||||
cell.isUserInteractionEnabled = false
|
||||
cell.textLabel?.isEnabled = false
|
||||
cell.detailTextLabel?.isEnabled = false
|
||||
}
|
||||
}
|
||||
|
||||
func isCurrentKeyboard() -> Bool {
|
||||
return KMManager.sharedInstance().keyboardID == keyboardID &&
|
||||
KMManager.sharedInstance().languageID == languageID
|
||||
}
|
||||
|
||||
func canDeleteKeyboard() -> Bool {
|
||||
if !KMManager.sharedInstance().canRemoveKeyboards {
|
||||
return false
|
||||
}
|
||||
|
||||
if !KMManager.sharedInstance().canRemoveDefaultKeyboard {
|
||||
return keyboardIndex != 0
|
||||
}
|
||||
|
||||
if keyboardIndex > 0 {
|
||||
return true
|
||||
}
|
||||
return keyboardCount > 1
|
||||
}
|
||||
|
||||
func showDeleteKeyboard() {
|
||||
let alert = UIAlertView(title: title ?? "",
|
||||
message: "Would you like to delete this keyboard?",
|
||||
delegate: self,
|
||||
cancelButtonTitle: "Cancel",
|
||||
otherButtonTitles: "Delete")
|
||||
alert.tag = 1
|
||||
alert.show()
|
||||
}
|
||||
|
||||
func alertView(_ alertView: UIAlertView, clickedButtonAt buttonIndex: Int) {
|
||||
if buttonIndex == alertView.cancelButtonIndex {
|
||||
return
|
||||
}
|
||||
|
||||
if alertView.tag == 1 {
|
||||
let userData = KMManager.sharedInstance().activeUserDefaults()
|
||||
let userKeyboards = userData!.array(forKey: kKeymanUserKeyboardsListKey) as! [[String: String]]
|
||||
let kbDict = userKeyboards[keyboardIndex]
|
||||
|
||||
if KMManager.sharedInstance().removeKeyboard(at: UInt(keyboardIndex)) {
|
||||
if isCurrentKeyboard() {
|
||||
// Select default keyboard
|
||||
|
||||
let kbID = userKeyboards[0][kKeymanKeyboardIdKey]
|
||||
let langID = userKeyboards[0][kKeymanLanguageIdKey]
|
||||
let kbName = userKeyboards[0][kKeymanKeyboardNameKey]
|
||||
let langName = userKeyboards[0][kKeymanLanguageNameKey]
|
||||
let font = userKeyboards[0][kKeymanFontKey]
|
||||
let oskFont = userKeyboards[0][kKeymanOskFontKey]
|
||||
KMManager.sharedInstance().setKeyboardWithID(kbID, languageID: langID,
|
||||
keyboardName: kbName, languageName: langName, font: font, oskFont: oskFont)
|
||||
}
|
||||
NotificationCenter.default.post(name: NSNotification.Name.keymanKeyboardRemoved,
|
||||
object: self, userInfo: [ kKeymanKeyboardInfoKey: kbDict ]
|
||||
)
|
||||
navigationController?.popToRootViewController(animated: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,8 +8,8 @@
|
|||
|
||||
#import "KeyboardPickerViewController.h"
|
||||
#import "LanguageViewController.h"
|
||||
#import "KeyboardInfoViewController.h"
|
||||
#import "KMManager+Internal.h"
|
||||
#import <KMEI-Swift.h>
|
||||
|
||||
static const NSInteger kmErrorAlertTag = -1;
|
||||
static const NSInteger kmToolbarButtonTag = 100;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue