update iOS app
This commit is contained in:
parent
e0db322995
commit
6011bd7812
@ -7,6 +7,7 @@
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
523F3694298456A200E48AD2 /* ParametersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 523F3693298456A200E48AD2 /* ParametersView.swift */; };
|
||||
52571C6429718D0500FF1027 /* FuzzyApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52571C6329718D0500FF1027 /* FuzzyApp.swift */; };
|
||||
52571C6629718D0500FF1027 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52571C6529718D0500FF1027 /* ContentView.swift */; };
|
||||
52571C6829718D0600FF1027 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 52571C6729718D0600FF1027 /* Assets.xcassets */; };
|
||||
@ -29,6 +30,7 @@
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
523F3693298456A200E48AD2 /* ParametersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParametersView.swift; sourceTree = "<group>"; };
|
||||
52571C6029718D0500FF1027 /* Fuzzy.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Fuzzy.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
52571C6329718D0500FF1027 /* FuzzyApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FuzzyApp.swift; sourceTree = "<group>"; };
|
||||
52571C6529718D0500FF1027 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
|
||||
@ -108,6 +110,7 @@
|
||||
52D2A7402971B51000BCA112 /* SearchBarView.swift */,
|
||||
52571C6529718D0500FF1027 /* ContentView.swift */,
|
||||
52D2A74F2971D61200BCA112 /* MovieView.swift */,
|
||||
523F3693298456A200E48AD2 /* ParametersView.swift */,
|
||||
52D2A7592971F8D200BCA112 /* SuggestionView.swift */,
|
||||
52D2A7692972114400BCA112 /* SuggestionMovieView.swift */,
|
||||
52D2A75D2971FC2D00BCA112 /* LoaderView.swift */,
|
||||
@ -250,6 +253,7 @@
|
||||
52D2A76629720B3600BCA112 /* SuggestionMovieTitleModel.swift in Sources */,
|
||||
52571C6429718D0500FF1027 /* FuzzyApp.swift in Sources */,
|
||||
52D2A7622972001B00BCA112 /* SuggestionsData.swift in Sources */,
|
||||
523F3694298456A200E48AD2 /* ParametersView.swift in Sources */,
|
||||
52D2A76A2972114400BCA112 /* SuggestionMovieView.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
Binary file not shown.
@ -70,8 +70,16 @@ class Api {
|
||||
}
|
||||
}
|
||||
|
||||
func getSuggestions(id_movie: String, completion: @escaping(Bool?) -> Void) {
|
||||
let req = session.request("http://127.0.0.1:8000/recs/\(id_movie)/",method:.get, encoding: JSONEncoding.default).response { response in
|
||||
func getSuggestions(id_movie: String,
|
||||
release_year_param: String,
|
||||
runtime_param: String,
|
||||
seasons_param: String,
|
||||
genres_param: String,
|
||||
emotions_param: String,
|
||||
count: Int,
|
||||
completion: @escaping(Bool?) -> Void) {
|
||||
let url = "http://127.0.0.1:8000/recs/\(id_movie)?release_year_param\(release_year_param.lowercased())&runtime_param=\(runtime_param.lowercased())&seasons_param=\(seasons_param.lowercased())&genres_param=\(genres_param.lowercased())&emotions_param=\(emotions_param.lowercased())&count=\(count)"
|
||||
let req = session.request(url, method:.get, encoding: JSONEncoding.default).response { response in
|
||||
switch response.result {
|
||||
case.success:
|
||||
if response.response?.statusCode == 200 {
|
||||
|
@ -18,7 +18,7 @@ struct MovieView: View {
|
||||
var body: some View {
|
||||
ZStack {
|
||||
VStack{
|
||||
NavigationLink(destination: SuggestionView(), tag: "Success", selection: $selection) { EmptyView() }
|
||||
NavigationLink(destination: ParametersView(), tag: "Success", selection: $selection) { EmptyView() }
|
||||
.navigationTitle(movie.title)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
|
||||
@ -43,23 +43,7 @@ struct MovieView: View {
|
||||
.padding(.horizontal, 20)
|
||||
|
||||
Button {
|
||||
wait.wait = true
|
||||
Api().getSuggestions(id_movie: movie.id) { res in
|
||||
if res == true {
|
||||
suggestionsList.titles.removeAll()
|
||||
for s in suggestion.id {
|
||||
for t in movie.csv {
|
||||
if s == t.id_movie {
|
||||
suggestionsList.titles.append(SuggestonMovieTitle(id_movie: t.id_movie, title: t.title))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
wait.wait = false
|
||||
selection = "Success"
|
||||
// print("show list of movies")
|
||||
}
|
||||
}
|
||||
selection = "Success"
|
||||
} label: {
|
||||
Text("Suggest Similar")
|
||||
}
|
||||
|
133
Fuzzy/Fuzzy/View/ParametersView.swift
Normal file
133
Fuzzy/Fuzzy/View/ParametersView.swift
Normal file
@ -0,0 +1,133 @@
|
||||
//
|
||||
// ParametersView.swift
|
||||
// Fuzzy
|
||||
//
|
||||
// Created by Maciej Czajka on 27/01/2023.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ParametersView: View {
|
||||
|
||||
var releaseYear = ["Newer", "Similar", "Older"]
|
||||
var runtime = ["Shorter", "Similar", "Longer"]
|
||||
var seasons = ["Less", "Similar", "More"]
|
||||
var genres = ["Different", "Similar", "Same"]
|
||||
var emotions = ["Different", "Similar", "Same"]
|
||||
|
||||
@State private var selectedYear = "Similar"
|
||||
@State private var selectedRuntime = "Similar"
|
||||
@State private var selectedSeasons = "Similar"
|
||||
@State private var selectedGenres = "Same"
|
||||
@State private var selectedEmotions = "Same"
|
||||
@State private var selectedResults = 5
|
||||
|
||||
@Environment(\.colorScheme) var colorScheme
|
||||
@ObservedObject var movie = MovieData.shared
|
||||
@ObservedObject var suggestion = SuggestionData.shared
|
||||
@ObservedObject var suggestionsList = SuggestionsMoviesListData.shared
|
||||
@ObservedObject var wait = Wait.shared
|
||||
@State private var selection: String? = nil
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
NavigationLink(destination: SuggestionView(), tag: "Success", selection: $selection) { EmptyView() }
|
||||
.navigationTitle(movie.title)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
Form {
|
||||
Section(header: Text("Choose parameters")) {
|
||||
Picker("Release year", selection: $selectedYear) {
|
||||
ForEach(releaseYear, id: \.self) {
|
||||
Text($0)
|
||||
}
|
||||
}
|
||||
.foregroundColor(Color(colorScheme == .dark ? .white : .black))
|
||||
|
||||
Picker("Runtime", selection: $selectedRuntime) {
|
||||
ForEach(runtime, id: \.self) {
|
||||
Text($0)
|
||||
}
|
||||
}
|
||||
.foregroundColor(Color(colorScheme == .dark ? .white : .black))
|
||||
|
||||
Picker("Seasons", selection: $selectedSeasons) {
|
||||
ForEach(seasons, id: \.self) {
|
||||
Text($0)
|
||||
}
|
||||
}
|
||||
.foregroundColor(Color(colorScheme == .dark ? .white : .black))
|
||||
|
||||
Picker("Genres", selection: $selectedGenres) {
|
||||
ForEach(genres, id: \.self) {
|
||||
Text($0)
|
||||
}
|
||||
}
|
||||
.foregroundColor(Color(colorScheme == .dark ? .white : .black))
|
||||
|
||||
Picker("Emotions", selection: $selectedEmotions) {
|
||||
ForEach(emotions, id: \.self) {
|
||||
Text($0)
|
||||
}
|
||||
}
|
||||
.foregroundColor(Color(colorScheme == .dark ? .white : .black))
|
||||
}
|
||||
.foregroundColor(Color("netflixRed"))
|
||||
|
||||
|
||||
Section(header: Text("Choose the number of results")) {
|
||||
Stepper("\(selectedResults)", value: $selectedResults, in: 5...100, step: Int.Stride(5))
|
||||
.foregroundColor(Color(colorScheme == .dark ? .white : .black))
|
||||
}
|
||||
.foregroundColor(Color("netflixRed"))
|
||||
|
||||
Section {
|
||||
Button {
|
||||
wait.wait = true
|
||||
Api().getSuggestions(id_movie: movie.id,
|
||||
release_year_param: selectedYear,
|
||||
runtime_param: selectedRuntime,
|
||||
seasons_param: selectedSeasons,
|
||||
genres_param: selectedGenres,
|
||||
emotions_param: selectedEmotions,
|
||||
count: selectedResults ) { res in
|
||||
if res == true {
|
||||
suggestionsList.titles.removeAll()
|
||||
for s in suggestion.id {
|
||||
for t in movie.csv {
|
||||
if s == t.id_movie {
|
||||
suggestionsList.titles.append(SuggestonMovieTitle(id_movie: t.id_movie, title: t.title))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
wait.wait = false
|
||||
selection = "Success"
|
||||
} else {
|
||||
wait.wait = false
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
Text("Suggest Similar")
|
||||
}
|
||||
.frame(width: UIScreen.main.bounds.width - 80)
|
||||
.foregroundColor(Color("netflixRed"))
|
||||
}
|
||||
|
||||
}
|
||||
if wait.wait {
|
||||
GeometryReader { _ in
|
||||
LoaderView().frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
|
||||
}
|
||||
.background(Color.black.opacity(0.45))
|
||||
.edgesIgnoringSafeArea(.all)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
struct ParametersView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ParametersView()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user