Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // InboxDetailController.m
- // IphoneMobileBanking
- //
- // Created by Yonas P Syamsuddin on 5/7/12.
- // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
- //
- #import "InboxDetailController.h"
- //share sms
- #import <AddressBook/AddressBook.h>
- #import <AddressBook/ABAddressBook.h>
- #import <AddressBook/ABPerson.h>
- #import "ContactMenuController.h"
- @interface InboxDetailController ()
- @end
- @implementation InboxDetailController
- @synthesize tabBar;
- @synthesize rowTitle,rowValue,keterangan, noRef, idInbox;
- @synthesize _loadingScreen;
- BOOL alreadyInitialized;
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- alreadyInitialized = YES;
- }
- return self;
- }
- - (void)didReceiveMemoryWarning
- {
- // Releases the view if it doesn't have a superview.
- [super didReceiveMemoryWarning];
- // Release any cached data, images, etc that aren't in use.
- }
- - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
- NSLog(@"selected : %d", [item tag]);
- if ([item tag] == 1){
- [ViewLoadingUtil loadMainMenuFrom:self];
- }
- if ([item tag] == 2) {
- /*LokasiController *controller = [[LokasiController alloc] initWithNibName:@"LokasiController" bundle:nil];
- [ViewLoadingUtil animateToNextView:controller from:self :@""];*/
- [ViewLoadingUtil loadInfoFrom:self];
- }
- else if ([item tag] == 3) {
- [ViewLoadingUtil loadAdminMenuFrom:self];
- }
- else if ([item tag] == 4) {
- UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Informasi" message:@"Apakah anda yakin?" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ya", @"Tidak", nil];
- [alert show];
- [alert setTag:ALERT_TAG_LOGOUT];
- }
- }
- #pragma mark - View lifecycle
- // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- - (void)viewDidLoad
- {
- NSLog(@"Menu %@", self.title);
- if (alreadyInitialized) {
- if (keterangan.length == 0) {
- labelKeterangan.hidden = YES;
- // footerView.hidden = YES;
- buttonView.frame = CGRectMake( 5, 5, buttonView.frame.size.width, buttonView.frame.size.height );
- footerView.frame = CGRectMake( footerView.frame.origin.x, footerView.frame.origin.y, footerView.frame.size.width, 90);
- }else {
- labelKeterangan.text = keterangan;
- }
- secondView = [[DSICellView alloc]initWithView:secondTable];
- [secondView setDelegate:self];
- [secondView setTinggiBaris:50];
- [ViewLoadingUtil rightButtonForController:self withTitle:@"Share" withAction:@selector(shareButtonSelected:)];
- [super viewDidLoad];
- }
- alreadyInitialized = NO;
- self.title = @"Detail Inbox";
- // change the back button and add an event handler
- self.navigationItem.hidesBackButton = YES;
- //set custom image to button if needed
- UIImage *backButtonImage = [UIImage imageNamed:@"btn_back.png"];
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button setImage:backButtonImage forState:UIControlStateNormal];
- button.frame = CGRectMake(-12, 2, backButtonImage.size.width, backButtonImage.size.height);
- [button addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
- UIView *backButtonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, backButtonImage.size.width-15, backButtonImage.size.height)];
- [backButtonView addSubview:button];
- UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:backButtonView];
- self.navigationItem.leftBarButtonItem = customBarItem;
- }
- - (void) backAction {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)viewDidUnload
- {
- [super viewDidUnload];
- // Release any retained subviews of the main view.
- // e.g. self.myOutlet = nil;
- }
- - (void)viewWillDisappear:(BOOL)animated{
- //[rowTitle removeAllObjects];
- //[rowValue removeAllObjects];
- }
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- // Return YES for supported orientations
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
- }
- #pragma mark -
- #pragma mark Table View Data Source Methods
- -(NSInteger)numberOfRowsInSection:(NSInteger)section{
- return 1;
- }
- -(NSInteger)numberOfSection{
- return 1;
- }
- - (NSInteger)numberOfRowsInSection2:(NSInteger)section{
- return [rowTitle count];
- }
- -(NSString *)isWithDisclosureButton{
- return @"NO";
- }
- -(NSString *)isWithDisclosureButton2{
- return @"NO";
- }
- -(NSString *)menuStyle{
- NSString *tableStyle = @"Style1";
- return tableStyle;
- }
- -(NSString *)cellBgStyle{
- return @"oddonly";
- }
- - (NSString *) title5ForRowAtIndexPath:(NSIndexPath *) indexPath {
- NSString *title;
- title = [rowTitle objectAtIndex:indexPath.row];
- return title;
- }
- - (NSString *) title6ForRowAtIndexPath:(NSIndexPath *) indexPath {
- NSString *title;
- title = [rowValue objectAtIndex:indexPath.row];
- return title;
- }
- -(void)didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- }
- -(IBAction)shareButtonSelected:(id)sender{
- // UIActionSheet *actionSheet;
- // actionSheet = [[UIActionSheet alloc]initWithTitle:@"Pilih Media"delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Email" otherButtonTitles:@"SMS", nil];
- // [actionSheet showInView:self.view];
- NSString *message = @"";
- for (int i = 0; i < [rowTitle count]; i++){
- message = [message stringByAppendingFormat:@"%@:\n %@\n",[rowTitle objectAtIndex:i], [rowValue objectAtIndex:i]];
- }
- NSArray *activityItems = @[message];
- UIActivityViewController *activityViewControntroller = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
- activityViewControntroller.excludedActivityTypes = @[];
- activityViewControntroller.popoverPresentationController.sourceView = self.view;
- activityViewControntroller.popoverPresentationController.sourceRect = CGRectMake(self.view.bounds.size.width/2, self.view.bounds.size.height/4, 0, 0);
- [self presentViewController:activityViewControntroller animated:true completion:nil];
- }
- - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
- {
- if (buttonIndex != [actionSheet cancelButtonIndex])
- {
- NSLog(@"index button %d", buttonIndex);
- if (buttonIndex == 0) {
- /*shareMail = [[MessageCustomController alloc]init];
- [shareMail composeMail:[self composeEmailBody] :@"Histori Transaksi"];
- [self presentModalViewController:shareMail animated:YES];*/
- [self composeMail:[self composeEmailBody] :@"Histori Transaksi"];
- }else {
- /*shareSms = [[MessageCustomController alloc]init];
- [shareSms composeSms:[self composeSmsBody]];
- [self presentModalViewController:shareSms animated:YES]; */
- [self loadPhoneContacts];
- }
- }
- }
- -(NSString *)composeSmsBody{
- NSString *message = @"";
- for (int i = 0; i < [rowTitle count]; i++){
- message = [message stringByAppendingFormat:@"%@:\n\t\b\t %@\n",[rowTitle objectAtIndex:i], [rowValue objectAtIndex:i]];
- }
- return message;
- }
- -(NSString *)composeEmailBody{
- NSString *message = @"";
- for (int i = 0; i < [rowTitle count]; i++){
- message = [message stringByAppendingFormat:@"%@:\n %@\n",[rowTitle objectAtIndex:i], [rowValue objectAtIndex:i]];
- }
- return message;
- }
- - (void) loadingScreen:(BOOL) visibility {
- if (visibility) {
- self._loadingScreen = [[DSILoadingScreenController alloc] initWithNibName:@"DSILoadingScreenController" bundle:nil];
- self._loadingScreen.view.frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);
- [self.view addSubview:_loadingScreen.view];
- }
- else {
- [_loadingScreen.view removeFromSuperview];
- self._loadingScreen = nil;
- }
- }
- -(void)loadPhoneContacts{
- [self loadingScreen:YES];
- ABAuthorizationStatus status = ABAddressBookGetAuthorizationStatus();
- if (status == kABAuthorizationStatusDenied) {
- // if you got here, user had previously denied/revoked permission for your
- // app to access the contacts, and all you can do is handle this gracefully,
- // perhaps telling the user that they have to go to settings to grant access
- // to contacts
- [self loadingScreen:NO];
- [[[UIAlertView alloc] initWithTitle:nil message:@"This app requires access to your contacts to function properly. Please visit to the \"Privacy\" section in the iPhone Settings app." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
- return;
- }
- CFErrorRef error = NULL;
- ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error);
- if (error) {
- NSLog(@"ABAddressBookCreateWithOptions error: %@", CFBridgingRelease(error));
- if (addressBook) CFRelease(addressBook);
- return;
- }
- if (status == kABAuthorizationStatusNotDetermined) {
- // present the user the UI that requests permission to contacts ...
- ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
- if (error) {
- NSLog(@"ABAddressBookRequestAccessWithCompletion error: %@", CFBridgingRelease(error));
- }
- if (granted) {
- // if they gave you permission, then just carry on
- [self listPeopleInAddressBook:addressBook];
- } else {
- // however, if they didn't give you permission, handle it gracefully, for example...
- [self loadingScreen:NO];
- dispatch_async(dispatch_get_main_queue(), ^{
- // BTW, this is not on the main thread, so dispatch UI updates back to the main queue
- [[[UIAlertView alloc] initWithTitle:nil message:@"Aplikasi ini membutuhkan akses ke kontak Anda agar berfungsi dengan baik. Silahkan kunjungi ke \" Privacy\" di iPhone app Settings." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
- });
- }
- if (addressBook) CFRelease(addressBook);
- });
- } else if (status == kABAuthorizationStatusAuthorized) {
- [self listPeopleInAddressBook:addressBook];
- if (addressBook) CFRelease(addressBook);
- }
- }
- - (void)listPeopleInAddressBook:(ABAddressBookRef)addressBook
- {
- NSInteger numberOfPeople = ABAddressBookGetPersonCount(addressBook);
- NSArray *allPeople = CFBridgingRelease(ABAddressBookCopyArrayOfAllPeople(addressBook));
- namePeople = [[NSMutableArray alloc] init];
- //NSMutableArray *phonePeople = [[NSMutableArray alloc] init];
- for (NSInteger i = 0; i < numberOfPeople; i++) {
- ABRecordRef person = (__bridge ABRecordRef)allPeople[i];
- NSString *firstName = CFBridgingRelease(ABRecordCopyValue(person, kABPersonFirstNameProperty));
- NSString *lastName = CFBridgingRelease(ABRecordCopyValue(person, kABPersonLastNameProperty));
- //if(SHOW_LOG) NSLog(@"Name:%@ %@", firstName, lastName);
- ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
- CFIndex numberOfPhoneNumbers = ABMultiValueGetCount(phoneNumbers);
- for (CFIndex i = 0; i < numberOfPhoneNumbers; i++) {
- NSString *phoneNumber = CFBridgingRelease(ABMultiValueCopyValueAtIndex(phoneNumbers, i));
- //if(SHOW_LOG) NSLog(@" phone:%@", phoneNumber);
- if(firstName == nil && lastName != nil) {
- [namePeople addObject:[NSString stringWithFormat:@"%@, %@", lastName, phoneNumber]];
- } else if(lastName == nil && firstName !=nil) {
- [namePeople addObject:[NSString stringWithFormat:@"%@, %@", firstName, phoneNumber]];
- } else if(lastName != nil && firstName !=nil) {
- [namePeople addObject:[NSString stringWithFormat:@"%@ %@, %@", firstName, lastName, phoneNumber]];
- } else {
- [namePeople addObject:[NSString stringWithFormat:@"%@, %@", @"Kontak", phoneNumber]];
- }
- }
- CFRelease(phoneNumbers);
- NSLog(@"=============================================");
- }
- /*UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"AdminStoryboard" bundle:nil];
- ContactMenuController *myVC = (ContactMenuController *) [storyboard instantiateViewControllerWithIdentifier:@"contactView"];
- myVC.nameP = namePeople;
- myVC.composeBody = [self composeSmsBody];
- [self.navigationController pushViewController:myVC animated:YES];*/
- [self loadingScreen:NO];
- if(namePeople.count > 0) {
- ContactMenuController *controller = [[ContactMenuController alloc]initWithNibName:@"ContactMenuController" bundle:nil];
- /*controller.firstTitle = firstTitle;
- controller.secondTitle = secondTitle;
- controller.nameTitle = nameTitle;
- controller.valueTitle = valueTitle;
- controller.menuImage = menuImage;
- controller.menuHighlightedImage = menuHighlightedImage;
- controller.folioModel = folioModel;*/
- controller.nameP = namePeople;
- controller.composeBody = [self composeSmsBody];
- [ViewLoadingUtil animateToNextView:controller from:self :@"Pilih Kontak"];
- } else {
- UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Informasi" message:@"Tidak ada data" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
- [alert show];
- }
- }
- -(void) composeMail:(NSString *)body :(NSString *)subject{
- // Do any additional setup after loading the view from its nib.
- if([MFMailComposeViewController canSendMail]){
- mail = [[MFMailComposeViewController alloc]init];
- mail.mailComposeDelegate = self;
- //[mail setToRecipients:[NSArray arrayWithObjects:@"",nil]];
- [mail setSubject:subject];
- [mail setMessageBody:body isHTML:NO];
- //mail.delegate = self;
- [self presentViewController:mail animated:YES completion:nil];
- }else {
- NSLog(@"Device is unable to send email in its current state.");
- UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Informasi" message:@"Perangkat tidak dapat mengirimkan email. Mohon cek konfigurasi account email anda." delegate:self cancelButtonTitle:[NSString stringWithFormat:@"Tutup"] otherButtonTitles:nil];
- [alert setTag:1];
- [alert show];
- }
- }
- - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
- {
- switch (result) {
- case MFMailComposeResultCancelled:{
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Informasi" message:@"Pengiriman Email dibatalkan." delegate:self cancelButtonTitle:[NSString stringWithFormat:@"Tutup"] otherButtonTitles:nil];
- [alert show];
- break;
- }
- case MFMailComposeResultSaved:{
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Informasi" message:@"Draft Email disimpan." delegate:self cancelButtonTitle:[NSString stringWithFormat:@"Tutup"] otherButtonTitles:nil];
- [alert show];
- break;
- }
- case MFMailComposeResultFailed:{
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Informasi" message:@"Pengiriman Email gagal. Mohon cek konfigurasi email anda." delegate:self cancelButtonTitle:[NSString stringWithFormat:@"Tutup"] otherButtonTitles:nil];
- [alert show];
- break;
- }
- case MFMailComposeResultSent:{
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Informasi" message:@"Email dikirim." delegate:self cancelButtonTitle:[NSString stringWithFormat:@"Tutup"] otherButtonTitles:nil];
- [alert show];
- break;
- }
- default:
- break;
- }
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- -(IBAction) resendClicked:(id)sender {
- [self loadingScreen:YES];
- NSLog(@"=========== resend click");
- NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
- if ([CommunicationUtil checkNetworkConnection]){
- NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
- [params setObject:[DeviceUtil decryptUserDefaults:[prefs objectForKey:nsuser_customer_id]] forKey:@"customerId"];
- [params setObject:[DeviceUtil getDeviceId] forKey:@"deviceId"];
- [params setObject:[prefs objectForKey:nsuser_session_id] forKey:@"sessionId"];
- [params setObject:idInbox forKey:@"transactionId"];
- // perform webservice call
- NSDictionary *response = [CommunicationUtil webServiceRequestUri:uriInboxResend withParameters:params withMethod:HTTP_METHOD_POST];
- [self loadingScreen:NO];
- if ([CommunicationUtil validateJsonObject:response]) {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Informasi" message:[NSString stringWithFormat:@"Email sudah dikirim ke %@", [response objectForKey:@"email"]] delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
- [alert show];
- self.navigationController.navigationBar.userInteractionEnabled = YES;
- }
- }
- }
- -(IBAction) deleteClicked:(id)sender {
- UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Informasi" message:[NSString stringWithFormat:@"Hapus '%@' dari inbox?", noRef] delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ya", @"Tidak", nil];
- [alert show];
- [alert setTag:123];
- }
- -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
- if([alertView tag] == ALERT_TAG_LOGOUT && buttonIndex == 0){
- [DeviceUtil logoutSession];
- LoginController *controller = [[LoginController alloc]initWithNibName:@"Login" bundle:nil];
- [ViewLoadingUtil animateToNextView:controller from:self :@""];
- } else if([alertView tag] == 123 && buttonIndex == 0){
- NSLog(@"=========== delete click");
- [self loadingScreen:YES];
- NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
- if ([CommunicationUtil checkNetworkConnection]){
- NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
- [params setObject:[DeviceUtil decryptUserDefaults:[prefs objectForKey:nsuser_customer_id]] forKey:@"customerId"];
- [params setObject:[DeviceUtil getDeviceId] forKey:@"deviceId"];
- [params setObject:[prefs objectForKey:nsuser_session_id] forKey:@"sessionId"];
- [params setObject:idInbox forKey:@"transactionId"];
- // perform webservice call
- NSDictionary *response = [CommunicationUtil webServiceRequestUri:uriInboxDelete withParameters:params withMethod:HTTP_METHOD_POST];
- [self loadingScreen:NO];
- if ([CommunicationUtil validateJsonObject:response]) {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Informasi" message:@"Data berhasil dihapus" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
- [alert show];
- [ViewLoadingUtil loadInfoFrom:self];
- }
- }
- }
- }
- -(NSString *)hideHeader {
- return @"NO";
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement