Skip to content

Commit

Permalink
parse data
Browse files Browse the repository at this point in the history
  • Loading branch information
xqsadness committed Sep 15, 2023
1 parent 954d556 commit 286eb9d
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 4 deletions.
8 changes: 4 additions & 4 deletions DefaultProject.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
DDCC6D7D2A8E1C890085D950 /* HistorySubmitNextButtonsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCC6D7C2A8E1C890085D950 /* HistorySubmitNextButtonsView.swift */; };
DDFDD3DE2AB3EAF200585841 /* Localize.strings in Resources */ = {isa = PBXBuildFile; fileRef = DDFDD3DD2AB3EAF200585841 /* Localize.strings */; };
DDFDD3EA2AB4053400585841 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = DDFDD3E92AB4053400585841 /* GoogleService-Info.plist */; };
DDFDD3ED2AB409BA00585841 /* Data.json in Resources */ = {isa = PBXBuildFile; fileRef = DDFDD3EC2AB409BA00585841 /* Data.json */; };
DDFDD3ED2AB409BA00585841 /* data.json in Resources */ = {isa = PBXBuildFile; fileRef = DDFDD3EC2AB409BA00585841 /* data.json */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -286,7 +286,7 @@
DDCC6D7C2A8E1C890085D950 /* HistorySubmitNextButtonsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistorySubmitNextButtonsView.swift; sourceTree = "<group>"; };
DDFDD3DD2AB3EAF200585841 /* Localize.strings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; path = Localize.strings; sourceTree = "<group>"; };
DDFDD3E92AB4053400585841 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
DDFDD3EC2AB409BA00585841 /* Data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = Data.json; sourceTree = "<group>"; };
DDFDD3EC2AB409BA00585841 /* data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = data.json; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -355,7 +355,7 @@
CA2223482A2BB329005164BB /* ContentView.swift */,
CA22234A2A2BB32A005164BB /* Assets.xcassets */,
CA2223E52A2BC1CE005164BB /* loading_default.json */,
DDFDD3EC2AB409BA00585841 /* Data.json */,
DDFDD3EC2AB409BA00585841 /* data.json */,
DD0EA4832A8B26DC007D8C55 /* Localizable */,
DD72E2302A8A1182006AB647 /* ViewModel */,
DDA494562A871A35003814F1 /* Lotties */,
Expand Down Expand Up @@ -756,7 +756,7 @@
CA2223A22A2BB34A005164BB /* NativeAdView.xib in Resources */,
CA2223DE2A2BBADC005164BB /* Launch Screen.storyboard in Resources */,
CA2223B52A2BB34A005164BB /* SF-Pro-Display-Medium.otf in Resources */,
DDFDD3ED2AB409BA00585841 /* Data.json in Resources */,
DDFDD3ED2AB409BA00585841 /* data.json in Resources */,
9ADF75732A84C8F800A42B7B /* SF-Pro-Text-Bold.otf in Resources */,
9ADF75762A84C8F800A42B7B /* SF-Pro-Text-Regular.otf in Resources */,
CA2223B42A2BB34A005164BB /* SF-Pro-Display-Bold.otf in Resources */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,22 @@
uuid = "40680EE2-D096-4625-B9E1-B90CF7A46FFB"
type = "0"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "E096DF4D-BD4E-451A-B118-0A24CA842847"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "DefaultProject/View/Home/HomeView.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "57"
endingLineNumber = "57"
landmarkName = "body"
landmarkType = "24">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
64 changes: 64 additions & 0 deletions DefaultProject/DEFAULT_SOURCE/CONTROLL_APP/CONSTANT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class CONSTANT{

static var USING_MANIFEST = true
static var MANIFEST_URL = "/manifest/test/v1_0"
static var DATA_URL = "/data/ver_1"

var OBSERVER_MANIFEST: Any?

Expand Down Expand Up @@ -49,6 +50,34 @@ class CONSTANT{
}
}

func loadData(_ completion: @escaping (()->Void)){
if CONSTANT.USING_MANIFEST && Network.connectedToNetwork(){
self.OBSERVER_MANIFEST = Database.database().reference().child(CONSTANT.DATA_URL).observe(.value){snapshot in
if !snapshot.exists(){
debugPrint("DATA_URL URL NOT FOULD!")
return
}
let json = JSON(snapshot.value as Any)
self.pareData(json, completion: {
completion()
})
}
}
else {
if let manifestPath = Bundle.main.path(forResource: "data", ofType: "json"){
if let data = NSData(contentsOfFile: manifestPath) {
do {
let json = try JSON(data: data as Data, options: JSONSerialization.ReadingOptions.allowFragments)
self.pareData(json, completion: {
completion()
})
} catch _ {
debugPrint("error")
}
}
}
}
}
//Init
var VERSION_APP = [VERSION_APP_STRUCT]()
var INFO_APP = INFO_APP_STRUCT()
Expand All @@ -61,6 +90,15 @@ class CONSTANT{
var DESIGN = DESIGN_STRUCT()
var URL = URL_STRUCT()
var APP_NAVIGATION = APP_NAVIGATION_STRUCT()

//data
var DATA_COLOR = [QUIZ]()
var DATA_MATH = [QUIZ]()
var DATA_SURROUNDING = [QUIZ]()
var DATA_LISTEN = [QUIZ]()
var DATA_HISTORY = [QUIZ]()
var DATA_LISTENANDREPEAT = [QUIZ]()
var DATA_WRITING = [QUIZ]()
}

struct VERSION_APP_STRUCT{
Expand Down Expand Up @@ -147,6 +185,17 @@ struct APP_NAVIGATION_STRUCT{
var COLOR_BUTTON_TEXT = "ffffff"
}

struct QUIZ {
var id: String = ""
var answer: String = ""
var question: String = ""
var a: String = ""
var b: String = ""
var c: String = ""
var d: String = ""
var img: String = ""
}

extension CONSTANT{
func pareManifest(_ json: JSON, completion: @escaping ()->Void){
//VERSION_APP
Expand Down Expand Up @@ -256,7 +305,22 @@ extension CONSTANT{
self.APP_NAVIGATION.COLOR_BACKGROUND = nav["COLOR_BACKGROUND"].stringValue
self.APP_NAVIGATION.COLOR_BUTTON_TEXT = nav["COLOR_BUTTON_TEXT"].stringValue
self.APP_NAVIGATION.COLOR_BUTTON_BACKGROUND = nav["COLOR_BUTTON_BACKGROUND"].stringValue

}

//data
func pareData(_ json: JSON, completion: @escaping ()->Void){
//DATA_COLOR
let dataColors = json["listQuestionsColor"]

var list: [QUIZ] = []
for (_, json) : (String, JSON) in dataColors{
list.append(QUIZ(id: json["id"].stringValue, answer: json["answer"].stringValue, question: json["question"].stringValue, a: json["a"].stringValue, b: json["b"].stringValue, c: json["c"].stringValue, d: json["d"].stringValue, img: json["img"].stringValue))
}

self.DATA_COLOR = list
}

//Load old
func loadOldVersion(path: String,_ completion: @escaping (()->Void)){
self.OBSERVER_MANIFEST = Database.database().reference().child(path).observe(.value){snapshot in
Expand Down
2 changes: 2 additions & 0 deletions DefaultProject/DefaultProjectApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ struct RootView: View {
}
})
}

CONSTANT.SHARED.loadData{}
})
.onChange(of: appController.INDEX_TABBAR, perform: { b in
if User.isShowInterstitial() == false{
Expand Down
2 changes: 2 additions & 0 deletions DefaultProject/View/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ struct HomeView: View {
.padding(.horizontal)
.background(Color(red: 0.89, green: 0.79, blue: 0.98))
.onAppear{
print(CONSTANT.SHARED.DATA_COLOR)

switch language{
case "en":
selectedLanguage = .english(.us)
Expand Down
File renamed without changes.

0 comments on commit 286eb9d

Please sign in to comment.