Skip to content

Commit

Permalink
Organise code and removed not used class
Browse files Browse the repository at this point in the history
  • Loading branch information
jigar-f committed Sep 12, 2023
1 parent 3b62b0a commit 76a627c
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 138 deletions.
8 changes: 8 additions & 0 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
03A1AB3A2AA890AB00FB41B2 /* Tunnel.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 03A1AB302AA890AB00FB41B2 /* Tunnel.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
03A1AB422AA8930A00FB41B2 /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03A1AB412AA8930A00FB41B2 /* Result.swift */; };
03A1AB442AA8946400FB41B2 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03A1AB432AA8946400FB41B2 /* Constants.swift */; };
03F00B5D2AB07B3800E991E2 /* NavigationModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03F00B5C2AB07B3800E991E2 /* NavigationModel.swift */; };
03F00B5F2AB07C8000E991E2 /* LoadingIndicatorManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03F00B5E2AB07C8000E991E2 /* LoadingIndicatorManager.swift */; };
03F2FE342A6949EF0082B34C /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03F2FE332A6949EF0082B34C /* Logger.swift */; };
03F4CD822A77E43C00F7BDD8 /* BaseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03F4CD812A77E43C00F7BDD8 /* BaseModel.swift */; };
03FAF1B22AA1C7940063580C /* RunningEnv.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03FAF1B12AA1C7940063580C /* RunningEnv.swift */; };
Expand Down Expand Up @@ -120,6 +122,8 @@
03A1AB372AA890AB00FB41B2 /* Tunnel.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Tunnel.entitlements; sourceTree = "<group>"; };
03A1AB412AA8930A00FB41B2 /* Result.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Result.swift; sourceTree = "<group>"; };
03A1AB432AA8946400FB41B2 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
03F00B5C2AB07B3800E991E2 /* NavigationModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = NavigationModel.swift; path = Models/NavigationModel.swift; sourceTree = "<group>"; };
03F00B5E2AB07C8000E991E2 /* LoadingIndicatorManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingIndicatorManager.swift; sourceTree = "<group>"; };
03F2FE332A6949EF0082B34C /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
03F4CD812A77E43C00F7BDD8 /* BaseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = BaseModel.swift; path = Models/BaseModel.swift; sourceTree = "<group>"; };
03FAF1B12AA1C7940063580C /* RunningEnv.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunningEnv.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -252,6 +256,7 @@
03F4CD812A77E43C00F7BDD8 /* BaseModel.swift */,
0369DF782A93803D000EBE43 /* MessagingModel.swift */,
03FAF1B32AA1E9F40063580C /* VpnModel.swift */,
03F00B5C2AB07B3800E991E2 /* NavigationModel.swift */,
);
name = Models;
sourceTree = "<group>";
Expand All @@ -269,6 +274,7 @@
03FAF1B12AA1C7940063580C /* RunningEnv.swift */,
03A1AB432AA8946400FB41B2 /* Constants.swift */,
03567DBF2AA9F47200A233EA /* FileUtils.swift */,
03F00B5E2AB07C8000E991E2 /* LoadingIndicatorManager.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -582,6 +588,7 @@
0321C3F92AA9D8DF00D462C1 /* FlashlightManager.swift in Sources */,
035BE7062A7122BC0084059A /* SessionModel.swift in Sources */,
036663D92A9E0C0E00595971 /* JsonUtils.swift in Sources */,
03F00B5D2AB07B3800E991E2 /* NavigationModel.swift in Sources */,
0308A1302AAEF3AA0086157A /* Event.swift in Sources */,
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */,
03A1AB142AA88BDA00FB41B2 /* VPNManager.swift in Sources */,
Expand All @@ -592,6 +599,7 @@
03A1AB422AA8930A00FB41B2 /* Result.swift in Sources */,
035BE7052A7122BC0084059A /* LanternModel.swift in Sources */,
0308A1282AAEED7E0086157A /* VpnHelper.swift in Sources */,
03F00B5F2AB07C8000E991E2 /* LoadingIndicatorManager.swift in Sources */,
03026EA32A77D67A001D5507 /* ValueUtil.swift in Sources */,
03026EA12A77D654001D5507 /* Database.swift in Sources */,
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */,
Expand Down
105 changes: 46 additions & 59 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,47 @@ import Toast_Swift

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
// List of channel and event method names
let NAVIGATION_METHOED_CHANNEL="lantern_method_channel"

var sessionModel:SessionModel!
var messagingModel:MessagingModel!
var lanternModel:LanternModel!
var vpnModel:VpnModel!
var flutterbinaryMessenger:FlutterBinaryMessenger!
var lanternMethodChannel:FlutterMethodChannel!
var navigationChannel:FlutterMethodChannel!
var flutterViewController:FlutterViewController!
var loadingIndicator: UIActivityIndicatorView!



// Flutter Properties
var flutterViewController: FlutterViewController!
var flutterbinaryMessenger: FlutterBinaryMessenger!

// Model Properties
var sessionModel: SessionModel!
var messagingModel: MessagingModel!
var lanternModel: LanternModel!
var vpnModel: VpnModel!
var navigationModel: NavigationModel!

//IOS
var loadingManager: LoadingIndicatorManager?

override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
flutterViewController = window?.rootViewController as! FlutterViewController
flutterbinaryMessenger=flutterViewController.binaryMessenger
setupModels()
prepareChannel()
setupLocal()
createUser()
initializeFlutterComponents()
setupAppComponents()
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

//Flutter related stuff
private func initializeFlutterComponents() {
flutterViewController = window?.rootViewController as! FlutterViewController
flutterbinaryMessenger = flutterViewController.binaryMessenger
}


//Intlize this GO model and callback
private func setupAppComponents() {
setupModels()
startUpSequency()
setupLoadingBar()
}


//Init all the models
private func setupModels(){
logger.log("setupModels method called")
//Init Session Model
Expand All @@ -45,10 +57,17 @@ import Toast_Swift
lanternModel=LanternModel(flutterBinary: flutterbinaryMessenger)
//Init VPN Model
vpnModel=VpnModel(flutterBinary: flutterbinaryMessenger,vpnBase: VPNManager.appDefault)
//Init Navigation Model
navigationModel=NavigationModel(flutterBinary: flutterbinaryMessenger)
}

// Post start up
// Init all method needed for user
func startUpSequency() {
askNotificationPermssion()
setupLocal()
createUser()
askNotificationPermssion()

}

func askNotificationPermssion() {
Expand All @@ -61,14 +80,12 @@ import Toast_Swift
}
}


private func prepareChannel (){
logger.log("prepareChannel method called")
//Navigation Channel
navigationChannel=FlutterMethodChannel(name: NAVIGATION_METHOED_CHANNEL, binaryMessenger: flutterbinaryMessenger)
navigationChannel.setMethodCallHandler(handleNavigationethodCall)
func setupLoadingBar() {
loadingManager = LoadingIndicatorManager(parentView: flutterViewController.view)

}


private func setupLocal(){
let langStr = Locale.current.identifier
if langStr != nil{
Expand All @@ -82,13 +99,13 @@ import Toast_Swift
// Calling create API
func createUser(){
DispatchQueue.main.async {
self.showLoadingDialog()
self.loadingManager?.show()
}
DispatchQueue.global().async {
let success = self.sessionModel.createUser(local: Locale.current.identifier)
// After the API call is done, move back to the main thread to update UI
DispatchQueue.main.async {
self.hideLoadingDialog()
self.loadingManager?.hide()
if success {
self.flutterViewController.view.makeToast("User Created")
} else {
Expand All @@ -99,34 +116,4 @@ import Toast_Swift

}


func handleNavigationethodCall(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
// Handle your method calls here
// The 'call' contains the method name and arguments
// The 'result' can be used to send back the data to Flutter
switch call.method {
case "yourMethod":
// handle yourMethod
break
default:
result(FlutterMethodNotImplemented)
}
}


//Todo-:Sprate this Loading indicator to new class for reuse
private func showLoadingDialog(){
loadingIndicator = UIActivityIndicatorView(style: UIActivityIndicatorView.Style.gray)
loadingIndicator.center = flutterViewController.view.center
loadingIndicator.hidesWhenStopped = false
loadingIndicator.startAnimating()
flutterViewController.view.addSubview(loadingIndicator)
}

private func hideLoadingDialog() {
loadingIndicator?.stopAnimating()
loadingIndicator?.removeFromSuperview()
}


}
79 changes: 0 additions & 79 deletions ios/Runner/Lantern/EventManager.swift

This file was deleted.

43 changes: 43 additions & 0 deletions ios/Runner/Lantern/Models/NavigationModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// NavigationModel.swift
// Runner
//
// Created by jigar fumakiya on 12/09/23.
//

import Foundation
import Flutter

class NavigationModel{
let navigationMethodChannel = "lantern_method_channel"

var flutterbinaryMessenger:FlutterBinaryMessenger

init(flutterBinary:FlutterBinaryMessenger) {
self.flutterbinaryMessenger=flutterBinary
prepareNavigationChannel()
}


private func prepareNavigationChannel (){

//Navigation Channel
let navigationChannel=FlutterMethodChannel(name: navigationMethodChannel, binaryMessenger: flutterbinaryMessenger)
navigationChannel.setMethodCallHandler(handleNavigationethodCall)
}


func handleNavigationethodCall(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
// Handle your method calls here
// The 'call' contains the method name and arguments
// The 'result' can be used to send back the data to Flutter
switch call.method {
case "yourMethod":
// handle yourMethod
break
default:
result(FlutterMethodNotImplemented)
}
}

}
39 changes: 39 additions & 0 deletions ios/Runner/Lantern/Utils/LoadingIndicatorManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// LoadingIndicatorManager.swift
// Runner
//
// Created by jigar fumakiya on 12/09/23.
//

import Foundation
import UIKit

class LoadingIndicatorManager {
private var loadingIndicator: UIActivityIndicatorView?
private weak var parentView: UIView?

init(parentView: UIView) {
self.parentView = parentView
setupLoadingIndicator()
}

private func setupLoadingIndicator() {
loadingIndicator = UIActivityIndicatorView(style: .gray)
guard let loadingIndicator = loadingIndicator, let parentView = parentView else {
return
}
loadingIndicator.center = parentView.center
loadingIndicator.hidesWhenStopped = true
parentView.addSubview(loadingIndicator)
}

func show() {
loadingIndicator?.startAnimating()
}

func hide() {
loadingIndicator?.stopAnimating()
loadingIndicator?.removeFromSuperview()
loadingIndicator = nil
}
}

0 comments on commit 76a627c

Please sign in to comment.