Advertisement
Guest User

inbox detail

a guest
Dec 17th, 2019
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  InboxDetailController.m
  3. //  IphoneMobileBanking
  4. //
  5. //  Created by Yonas P Syamsuddin on 5/7/12.
  6. //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9. #import "InboxDetailController.h"
  10.  
  11. //share sms
  12. #import <AddressBook/AddressBook.h>
  13. #import <AddressBook/ABAddressBook.h>
  14. #import <AddressBook/ABPerson.h>
  15. #import "ContactMenuController.h"
  16.  
  17. @interface InboxDetailController ()
  18.  
  19. @end
  20.  
  21. @implementation InboxDetailController
  22. @synthesize tabBar;
  23. @synthesize rowTitle,rowValue,keterangan, noRef, idInbox;
  24. @synthesize _loadingScreen;
  25.  
  26. BOOL alreadyInitialized;
  27.  
  28. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  29. {
  30.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  31.     if (self) {
  32.         // Custom initialization
  33.         alreadyInitialized = YES;
  34.     }
  35.     return self;
  36. }
  37.  
  38. - (void)didReceiveMemoryWarning
  39. {
  40.     // Releases the view if it doesn't have a superview.
  41.     [super didReceiveMemoryWarning];
  42.    
  43.     // Release any cached data, images, etc that aren't in use.
  44. }
  45.  
  46. - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
  47.     NSLog(@"selected : %d", [item tag]);
  48.     if  ([item tag] == 1){
  49.         [ViewLoadingUtil loadMainMenuFrom:self];
  50.     }
  51.     if ([item tag] == 2) {
  52.         /*LokasiController *controller = [[LokasiController alloc] initWithNibName:@"LokasiController" bundle:nil];
  53.         [ViewLoadingUtil animateToNextView:controller from:self :@""];*/
  54.        
  55.         [ViewLoadingUtil loadInfoFrom:self];
  56.     }
  57.     else if ([item tag] == 3) {
  58.         [ViewLoadingUtil loadAdminMenuFrom:self];
  59.     }
  60.     else if ([item tag] == 4) {
  61.         UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Informasi" message:@"Apakah anda yakin?" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ya", @"Tidak", nil];
  62.         [alert show];
  63.         [alert setTag:ALERT_TAG_LOGOUT];
  64.     }
  65. }
  66.  
  67. #pragma mark - View lifecycle
  68.  
  69. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  70. - (void)viewDidLoad
  71. {
  72.     NSLog(@"Menu %@", self.title);
  73.     if (alreadyInitialized) {
  74.         if (keterangan.length == 0) {
  75.             labelKeterangan.hidden = YES;
  76.         //    footerView.hidden = YES;
  77.             buttonView.frame = CGRectMake( 5, 5, buttonView.frame.size.width, buttonView.frame.size.height );
  78.             footerView.frame = CGRectMake( footerView.frame.origin.x, footerView.frame.origin.y, footerView.frame.size.width, 90);
  79.         }else {
  80.             labelKeterangan.text = keterangan;
  81.         }
  82.        
  83.         secondView = [[DSICellView alloc]initWithView:secondTable];
  84.         [secondView setDelegate:self];
  85.         [secondView setTinggiBaris:50];
  86.        
  87.         [ViewLoadingUtil rightButtonForController:self withTitle:@"Share" withAction:@selector(shareButtonSelected:)];
  88.        
  89.         [super viewDidLoad];
  90.     }
  91.     alreadyInitialized = NO;
  92.    
  93.     self.title = @"Detail Inbox";
  94.    
  95.     // change the back button and add an event handler
  96.     self.navigationItem.hidesBackButton = YES;
  97.     //set custom image to button if needed
  98.     UIImage *backButtonImage = [UIImage imageNamed:@"btn_back.png"];
  99.     UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  100.     [button setImage:backButtonImage forState:UIControlStateNormal];
  101.     button.frame = CGRectMake(-12, 2, backButtonImage.size.width, backButtonImage.size.height);
  102.     [button addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  103.    
  104.     UIView *backButtonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, backButtonImage.size.width-15, backButtonImage.size.height)];
  105.     [backButtonView addSubview:button];
  106.    
  107.     UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:backButtonView];
  108.     self.navigationItem.leftBarButtonItem = customBarItem;
  109. }
  110.  
  111. - (void) backAction {
  112.     [self.navigationController popViewControllerAnimated:YES];
  113. }
  114.  
  115. - (void)viewDidUnload
  116. {
  117.     [super viewDidUnload];
  118.     // Release any retained subviews of the main view.
  119.     // e.g. self.myOutlet = nil;
  120. }
  121. - (void)viewWillDisappear:(BOOL)animated{
  122.     //[rowTitle removeAllObjects];
  123.     //[rowValue removeAllObjects];
  124. }
  125. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  126. {
  127.     // Return YES for supported orientations
  128.     return (interfaceOrientation == UIInterfaceOrientationPortrait);
  129. }
  130. #pragma  mark -
  131. #pragma  mark Table View Data Source Methods
  132. -(NSInteger)numberOfRowsInSection:(NSInteger)section{
  133.     return 1;
  134. }
  135. -(NSInteger)numberOfSection{
  136.     return 1;
  137. }
  138. - (NSInteger)numberOfRowsInSection2:(NSInteger)section{
  139.     return [rowTitle count];
  140. }
  141. -(NSString *)isWithDisclosureButton{
  142.     return @"NO";
  143. }
  144. -(NSString *)isWithDisclosureButton2{
  145.     return @"NO";
  146. }
  147. -(NSString *)menuStyle{
  148.     NSString *tableStyle = @"Style1";
  149.     return tableStyle;
  150. }
  151. -(NSString *)cellBgStyle{
  152.     return @"oddonly";
  153. }
  154.  
  155. - (NSString *) title5ForRowAtIndexPath:(NSIndexPath *) indexPath {
  156.     NSString *title;
  157.     title = [rowTitle objectAtIndex:indexPath.row];
  158.     return title;
  159. }
  160. - (NSString *) title6ForRowAtIndexPath:(NSIndexPath *) indexPath {
  161.     NSString *title;
  162.     title = [rowValue objectAtIndex:indexPath.row];
  163.     return title;
  164. }
  165.  
  166. -(void)didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  167.    
  168. }
  169. -(IBAction)shareButtonSelected:(id)sender{
  170. //    UIActionSheet *actionSheet;
  171. //    actionSheet = [[UIActionSheet alloc]initWithTitle:@"Pilih Media"delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Email" otherButtonTitles:@"SMS", nil];
  172. //    [actionSheet showInView:self.view];
  173.     NSString *message = @"";
  174.     for (int i = 0; i < [rowTitle count]; i++){
  175.         message = [message stringByAppendingFormat:@"%@:\n    %@\n",[rowTitle objectAtIndex:i], [rowValue objectAtIndex:i]];
  176.     }
  177.    
  178.     NSArray *activityItems = @[message];
  179.     UIActivityViewController *activityViewControntroller = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
  180.     activityViewControntroller.excludedActivityTypes = @[];
  181.     activityViewControntroller.popoverPresentationController.sourceView = self.view;
  182.     activityViewControntroller.popoverPresentationController.sourceRect = CGRectMake(self.view.bounds.size.width/2, self.view.bounds.size.height/4, 0, 0);
  183.    
  184.     [self presentViewController:activityViewControntroller animated:true completion:nil];
  185. }
  186. - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
  187. {
  188.     if (buttonIndex != [actionSheet cancelButtonIndex])
  189.     {
  190.         NSLog(@"index button %d", buttonIndex);
  191.         if (buttonIndex == 0) {
  192.             /*shareMail = [[MessageCustomController alloc]init];
  193.             [shareMail composeMail:[self composeEmailBody] :@"Histori Transaksi"];
  194.             [self presentModalViewController:shareMail animated:YES];*/
  195.            
  196.             [self composeMail:[self composeEmailBody] :@"Histori Transaksi"];
  197.         }else {
  198.             /*shareSms = [[MessageCustomController alloc]init];
  199.             [shareSms composeSms:[self composeSmsBody]];
  200.             [self presentModalViewController:shareSms animated:YES]; */
  201.            
  202.             [self loadPhoneContacts];
  203.         }
  204.     }
  205. }
  206. -(NSString *)composeSmsBody{
  207.     NSString *message = @"";
  208.     for (int i = 0; i < [rowTitle count]; i++){
  209.         message = [message stringByAppendingFormat:@"%@:\n\t\b\t    %@\n",[rowTitle objectAtIndex:i], [rowValue objectAtIndex:i]];
  210.     }
  211.     return message;
  212. }
  213. -(NSString *)composeEmailBody{
  214.     NSString *message = @"";
  215.     for (int i = 0; i < [rowTitle count]; i++){
  216.         message = [message stringByAppendingFormat:@"%@:\n    %@\n",[rowTitle objectAtIndex:i], [rowValue objectAtIndex:i]];
  217.     }
  218.     return message;
  219. }
  220.  
  221. - (void) loadingScreen:(BOOL) visibility {
  222.     if (visibility) {
  223.         self._loadingScreen = [[DSILoadingScreenController alloc] initWithNibName:@"DSILoadingScreenController" bundle:nil];
  224.         self._loadingScreen.view.frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);
  225.         [self.view addSubview:_loadingScreen.view];
  226.     }
  227.     else {
  228.         [_loadingScreen.view removeFromSuperview];
  229.         self._loadingScreen = nil;
  230.     }
  231. }
  232.  
  233. -(void)loadPhoneContacts{
  234.     [self loadingScreen:YES];
  235.    
  236.     ABAuthorizationStatus status = ABAddressBookGetAuthorizationStatus();
  237.    
  238.     if (status == kABAuthorizationStatusDenied) {
  239.         // if you got here, user had previously denied/revoked permission for your
  240.         // app to access the contacts, and all you can do is handle this gracefully,
  241.         // perhaps telling the user that they have to go to settings to grant access
  242.         // to contacts
  243.         [self loadingScreen:NO];
  244.        
  245.         [[[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];
  246.         return;
  247.     }
  248.    
  249.     CFErrorRef error = NULL;
  250.     ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error);
  251.    
  252.     if (error) {
  253.         NSLog(@"ABAddressBookCreateWithOptions error: %@", CFBridgingRelease(error));
  254.         if (addressBook) CFRelease(addressBook);
  255.         return;
  256.     }
  257.    
  258.     if (status == kABAuthorizationStatusNotDetermined) {
  259.        
  260.         // present the user the UI that requests permission to contacts ...
  261.        
  262.         ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
  263.             if (error) {
  264.                 NSLog(@"ABAddressBookRequestAccessWithCompletion error: %@", CFBridgingRelease(error));
  265.             }
  266.            
  267.             if (granted) {
  268.                 // if they gave you permission, then just carry on
  269.                
  270.                 [self listPeopleInAddressBook:addressBook];
  271.             } else {
  272.                 // however, if they didn't give you permission, handle it gracefully, for example...
  273.                 [self loadingScreen:NO];
  274.                
  275.                 dispatch_async(dispatch_get_main_queue(), ^{
  276.                     // BTW, this is not on the main thread, so dispatch UI updates back to the main queue
  277.                    
  278.                     [[[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];
  279.                 });
  280.             }
  281.            
  282.             if (addressBook) CFRelease(addressBook);
  283.         });
  284.        
  285.     } else if (status == kABAuthorizationStatusAuthorized) {
  286.         [self listPeopleInAddressBook:addressBook];
  287.         if (addressBook) CFRelease(addressBook);
  288.     }
  289. }
  290.  
  291. - (void)listPeopleInAddressBook:(ABAddressBookRef)addressBook
  292. {
  293.     NSInteger numberOfPeople = ABAddressBookGetPersonCount(addressBook);
  294.     NSArray *allPeople = CFBridgingRelease(ABAddressBookCopyArrayOfAllPeople(addressBook));
  295.    
  296.     namePeople = [[NSMutableArray alloc] init];
  297.     //NSMutableArray *phonePeople = [[NSMutableArray alloc] init];
  298.    
  299.     for (NSInteger i = 0; i < numberOfPeople; i++) {
  300.         ABRecordRef person = (__bridge ABRecordRef)allPeople[i];
  301.        
  302.         NSString *firstName = CFBridgingRelease(ABRecordCopyValue(person, kABPersonFirstNameProperty));
  303.         NSString *lastName  = CFBridgingRelease(ABRecordCopyValue(person, kABPersonLastNameProperty));
  304.         //if(SHOW_LOG) NSLog(@"Name:%@ %@", firstName, lastName);
  305.        
  306.         ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
  307.        
  308.         CFIndex numberOfPhoneNumbers = ABMultiValueGetCount(phoneNumbers);
  309.         for (CFIndex i = 0; i < numberOfPhoneNumbers; i++) {
  310.             NSString *phoneNumber = CFBridgingRelease(ABMultiValueCopyValueAtIndex(phoneNumbers, i));
  311.             //if(SHOW_LOG) NSLog(@"  phone:%@", phoneNumber);
  312.             if(firstName == nil && lastName != nil) {
  313.                 [namePeople addObject:[NSString stringWithFormat:@"%@, %@", lastName, phoneNumber]];
  314.             } else if(lastName == nil && firstName !=nil) {
  315.                 [namePeople addObject:[NSString stringWithFormat:@"%@, %@", firstName, phoneNumber]];
  316.             } else if(lastName != nil && firstName !=nil) {
  317.                 [namePeople addObject:[NSString stringWithFormat:@"%@ %@, %@", firstName, lastName, phoneNumber]];
  318.             } else  {
  319.                 [namePeople addObject:[NSString stringWithFormat:@"%@, %@", @"Kontak", phoneNumber]];
  320.             }
  321.            
  322.         }
  323.        
  324.         CFRelease(phoneNumbers);
  325.        
  326.         NSLog(@"=============================================");
  327.     }
  328.    
  329.     /*UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"AdminStoryboard" bundle:nil];
  330.      ContactMenuController *myVC = (ContactMenuController *) [storyboard instantiateViewControllerWithIdentifier:@"contactView"];
  331.      myVC.nameP = namePeople;
  332.      myVC.composeBody = [self composeSmsBody];
  333.      [self.navigationController pushViewController:myVC animated:YES];*/
  334.    
  335.     [self loadingScreen:NO];
  336.    
  337.     if(namePeople.count > 0) {
  338.         ContactMenuController *controller = [[ContactMenuController alloc]initWithNibName:@"ContactMenuController" bundle:nil];
  339.         /*controller.firstTitle = firstTitle;
  340.         controller.secondTitle = secondTitle;
  341.         controller.nameTitle = nameTitle;
  342.         controller.valueTitle = valueTitle;
  343.         controller.menuImage = menuImage;
  344.         controller.menuHighlightedImage = menuHighlightedImage;
  345.         controller.folioModel = folioModel;*/
  346.         controller.nameP = namePeople;
  347.         controller.composeBody = [self composeSmsBody];
  348.        
  349.         [ViewLoadingUtil animateToNextView:controller from:self :@"Pilih Kontak"];
  350.     } else {
  351.         UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Informasi" message:@"Tidak ada data" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
  352.         [alert show];
  353.     }
  354. }
  355.  
  356.  
  357. -(void) composeMail:(NSString *)body :(NSString *)subject{
  358.     // Do any additional setup after loading the view from its nib.
  359.     if([MFMailComposeViewController canSendMail]){
  360.         mail = [[MFMailComposeViewController alloc]init];
  361.         mail.mailComposeDelegate = self;
  362.         //[mail setToRecipients:[NSArray arrayWithObjects:@"",nil]];
  363.         [mail setSubject:subject];
  364.         [mail setMessageBody:body isHTML:NO];
  365.         //mail.delegate = self;
  366.        
  367.         [self presentViewController:mail animated:YES completion:nil];
  368.     }else {
  369.         NSLog(@"Device is unable to send email in its current state.");
  370.         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];
  371.         [alert setTag:1];
  372.         [alert show];
  373.     }
  374. }
  375.  
  376. - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
  377. {
  378.     switch (result) {
  379.         case MFMailComposeResultCancelled:{
  380.             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Informasi" message:@"Pengiriman Email dibatalkan." delegate:self cancelButtonTitle:[NSString stringWithFormat:@"Tutup"] otherButtonTitles:nil];
  381.             [alert show];
  382.             break;
  383.         }
  384.         case MFMailComposeResultSaved:{
  385.             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Informasi" message:@"Draft Email disimpan." delegate:self cancelButtonTitle:[NSString stringWithFormat:@"Tutup"] otherButtonTitles:nil];
  386.             [alert show];
  387.             break;
  388.         }
  389.         case MFMailComposeResultFailed:{
  390.             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Informasi" message:@"Pengiriman Email gagal. Mohon cek konfigurasi email anda." delegate:self cancelButtonTitle:[NSString stringWithFormat:@"Tutup"] otherButtonTitles:nil];
  391.             [alert show];
  392.             break;
  393.         }
  394.         case MFMailComposeResultSent:{
  395.             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Informasi" message:@"Email dikirim." delegate:self cancelButtonTitle:[NSString stringWithFormat:@"Tutup"] otherButtonTitles:nil];
  396.             [alert show];
  397.             break;
  398.         }
  399.         default:
  400.             break;
  401.     }
  402.    
  403.     [self dismissViewControllerAnimated:YES completion:nil];
  404. }
  405.  
  406. -(IBAction) resendClicked:(id)sender {
  407.     [self loadingScreen:YES];
  408.     NSLog(@"=========== resend click");
  409.     NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
  410.    
  411.     if ([CommunicationUtil checkNetworkConnection]){
  412.         NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
  413.         [params setObject:[DeviceUtil decryptUserDefaults:[prefs objectForKey:nsuser_customer_id]] forKey:@"customerId"];
  414.         [params setObject:[DeviceUtil getDeviceId] forKey:@"deviceId"];
  415.         [params setObject:[prefs objectForKey:nsuser_session_id] forKey:@"sessionId"];
  416.         [params setObject:idInbox forKey:@"transactionId"];
  417.        
  418.         // perform webservice call
  419.         NSDictionary *response = [CommunicationUtil webServiceRequestUri:uriInboxResend withParameters:params withMethod:HTTP_METHOD_POST];
  420.         [self loadingScreen:NO];
  421.        
  422.         if ([CommunicationUtil validateJsonObject:response]) {
  423.             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Informasi" message:[NSString stringWithFormat:@"Email sudah dikirim ke %@", [response objectForKey:@"email"]] delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
  424.             [alert show];
  425.            
  426.             self.navigationController.navigationBar.userInteractionEnabled = YES;
  427.         }
  428.     }
  429. }
  430.  
  431. -(IBAction) deleteClicked:(id)sender {
  432.     UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Informasi" message:[NSString stringWithFormat:@"Hapus '%@' dari inbox?", noRef] delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ya", @"Tidak", nil];
  433.     [alert show];
  434.     [alert setTag:123];
  435. }
  436.  
  437.  
  438. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
  439.     if([alertView tag] == ALERT_TAG_LOGOUT && buttonIndex == 0){
  440.         [DeviceUtil logoutSession];
  441.         LoginController *controller =  [[LoginController alloc]initWithNibName:@"Login" bundle:nil];
  442.         [ViewLoadingUtil animateToNextView:controller from:self :@""];
  443.     } else if([alertView tag] == 123 && buttonIndex == 0){
  444.         NSLog(@"=========== delete click");
  445.        
  446.         [self loadingScreen:YES];
  447.         NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
  448.        
  449.         if ([CommunicationUtil checkNetworkConnection]){
  450.             NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
  451.             [params setObject:[DeviceUtil decryptUserDefaults:[prefs objectForKey:nsuser_customer_id]] forKey:@"customerId"];
  452.             [params setObject:[DeviceUtil getDeviceId] forKey:@"deviceId"];
  453.             [params setObject:[prefs objectForKey:nsuser_session_id] forKey:@"sessionId"];
  454.             [params setObject:idInbox forKey:@"transactionId"];
  455.            
  456.             // perform webservice call
  457.             NSDictionary *response = [CommunicationUtil webServiceRequestUri:uriInboxDelete withParameters:params withMethod:HTTP_METHOD_POST];
  458.             [self loadingScreen:NO];
  459.            
  460.             if ([CommunicationUtil validateJsonObject:response]) {
  461.                 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Informasi" message:@"Data berhasil dihapus" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
  462.                 [alert show];
  463.                
  464.                 [ViewLoadingUtil loadInfoFrom:self];
  465.             }
  466.         }
  467.     }
  468. }
  469. -(NSString *)hideHeader {
  470.     return @"NO";
  471. }
  472. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement