-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add capability to change name of Masjid and class via a settings module. #55
Comments
Potential solutionThe task involves adding the capability to change the name of the Masjid and class via a settings module. The solution requires updating the How to implementQuizPreferences.swiftAdd new properties for Masjid and class names to the struct QuizPreferences {
struct QuizHeader {
var topRightText: String
var topLeftText: String
var masjidName: String
var className: String
}
var quizHeader: QuizHeader
var quizDate = Date.now
init(topRightText: String = "Default Top Right",
topLeftText: String = "Default Top Left",
masjidName: String = "Default Masjid",
className: String = "Default Class") {
self.quizHeader = QuizHeader(topRightText: topRightText,
topLeftText: topLeftText,
masjidName: masjidName,
className: className)
}
} PDFPreviewView.swiftUpdate the PDFKitView(
documentData: PDFGenerator(
verses: viewModel.quizVerses,
words: viewModel.wordsForWordsMeaning,
preferences: viewModel.preferences
).generateQuiz()
) QuizSettingsView.swiftAdd TextField("Enter Masjid Name", text: $masjidName)
TextField("Enter Class Name", text: $className)
Button("Save Changes", action: saveSettings) QuizViewModel.swiftAdd properties for Masjid and class names and methods to update and save these settings. @Published var masjidName: String = ""
@Published var className: String = ""
func updateMasjidName(to newName: String) {
masjidName = newName
saveSettings()
}
func updateClassName(to newName: String) {
className = newName
saveSettings()
}
private func saveSettings() {
// Save the settings using the Datastore implementation
} FileDatastore.swiftEnsure that the let preferencesDatastore = FileDatastore<QuizPreferences>(purpose: "QuizSettings")
preferencesDatastore.save(preferences, forKey: "QuizPreferences") Datastore.swiftVerify that the concrete implementations of the protocol Datastore {
// Existing methods...
func saveMasjidName(_ name: String)
func loadMasjidName() -> String?
func saveClassName(_ name: String)
func loadClassName() -> String?
} Ensure that the concrete classes or structs that conform to the Testing and DocumentationTest the changes to ensure that the Masjid and class names are correctly saved, loaded, and displayed. Update documentation to reflect the new functionality. Click here to create a Pull Request with the proposed solution Files used for this task: Changes on QuranMajeed/Foundation/Datastore.swiftThe Since the However, it is important to ensure that the concrete classes or structs that conform to the The tasks for the concrete implementations, such as In summary, the Changes on QuranMajeed/Info.plistFor the However, if the new settings involve accessing sensitive user data or integrating with other services that require permissions (e.g., cloud storage for syncing settings), then appropriate keys and strings would need to be added to the Since the task description does not specify such requirements, the Changes on QuranMajeed/Quiz/Main/View/Quiz/PDFPreviewView.swiftTo address the task of binding the Masjid and class names to the appropriate Text views in the Here's a practical proposal to solve the task:
Here's an example of how you might modify the struct PDFPreviewView: View {
@ObservedObject var viewModel: QuizView.ViewModel
var body: some View {
NavigationLink {
VStack {
// ... (other code remains unchanged)
// Update the PDFKitView initializer to use the updated QuizPreferences
PDFKitView(
documentData: PDFGenerator(
verses: viewModel.quizVerses,
words: viewModel.wordsForWordsMeaning,
preferences: QuizPreferences(
quizHeader: QuizPreferences.QuizHeader(
topRightText: viewModel.preferences.className, // Updated to use viewModel
topLeftText: viewModel.preferences.masjidName // Updated to use viewModel
)
)
)
.generateQuiz()
)
// ... (other code remains unchanged)
}
} label: {
// ... (label code remains unchanged)
}
}
} In the above code, Remember to test the changes to ensure that the Masjid and class names are correctly displayed in the PDF preview and that the PDF document is generated as expected with the new settings. Changes on QuranMajeed/Quiz/QuizSettings/QuizPreferences.swiftTo solve the task for the //
// QuizPreferences.swift
// Al-Tanzeel
//
// Created by Takasur Azeem on 16/02/2024.
// Copyright © 2024 Islam. All rights reserved.
//
import Foundation
struct QuizPreferences {
struct QuizHeader {
var topRightText: String
var topLeftText: String
var masjidName: String // New property for Masjid name
var className: String // New property for class name
}
var quizHeader: QuizHeader
var quizDate = Date.now
// Initializer to set default values or load existing settings
init(topRightText: String = "Default Top Right",
topLeftText: String = "Default Top Left",
masjidName: String = "Default Masjid",
className: String = "Default Class") {
self.quizHeader = QuizHeader(topRightText: topRightText,
topLeftText: topLeftText,
masjidName: masjidName,
className: className)
}
} With these changes, the Changes on QuranMajeed/Quiz/QuizSettings/QuizSettingsView.swiftTo solve the task of adding the capability to change the name of the Masjid and class via a settings module, we need to modify the
Here's the updated code for import SwiftUI
struct QuizSettingsView: View {
@AppStorage("MasjidName") private var masjidName: String = ""
@AppStorage("ClassName") private var className: String = ""
private let masjidNameLabel: String = "Masjid Name"
private let classNameLabel: String = "Class Name"
var body: some View {
List {
Section(header: Text("Settings")) {
VStack(alignment: .leading) {
Text(masjidNameLabel)
.font(.headline)
TextField("Enter Masjid Name", text: $masjidName)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding(.bottom)
Text(classNameLabel)
.font(.headline)
TextField("Enter Class Name", text: $className)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding(.bottom)
Button(action: saveSettings) {
Text("Save Changes")
.bold()
.frame(maxWidth: .infinity)
}
.buttonStyle(RoundedRectangleButtonStyle())
}
.padding()
}
}
.navigationTitle("Quiz Settings")
}
private func saveSettings() {
// Code to save the settings will be implemented here.
// This could involve updating the ViewModel or directly saving to AppStorage if that's the chosen approach.
}
}
struct RoundedRectangleButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.padding()
.background(Color.blue)
.foregroundColor(.white)
.clipShape(RoundedRectangle(cornerRadius: 8))
.scaleEffect(configuration.isPressed ? 0.95 : 1)
}
}
struct QuizSettingsView_Previews: PreviewProvider {
static var previews: some View {
NavigationStack {
QuizSettingsView()
}
}
} In this updated code, we have:
The Changes on QuranMajeed/Quiz/Main/ViewModel/QuizViewModel.swiftTo implement the capability to change the name of the Masjid and class via a settings module in the
@Published var masjidName: String = ""
@Published var className: String = ""
func updateMasjidName(to newName: String) {
masjidName = newName
saveSettings()
}
func updateClassName(to newName: String) {
className = newName
saveSettings()
}
private func saveSettings() {
// Assuming Datastore has methods to save settings
Datastore.shared.saveMasjidName(masjidName)
Datastore.shared.saveClassName(className)
}
init(
theQuranRepository: QuranRepository
) {
self.theQuranRepository = theQuranRepository
// ... existing code ...
loadSettings()
}
private func loadSettings() {
masjidName = Datastore.shared.loadMasjidName() ?? "Default Masjid"
className = Datastore.shared.loadClassName() ?? "Default Class"
}
private func saveSettings() {
do {
try Datastore.shared.saveMasjidName(masjidName)
try Datastore.shared.saveClassName(className)
} catch {
// Handle the error, possibly by showing an alert to the user
}
}
Remember to also update the Changes on QuranMajeed/Foundation/FileDatastore.swiftTo update the Here's a practical proposal for updating the
Here is an example of how the settings structure might look in struct QuizPreferences: Codable {
var masjidName: String
var className: String
// ... other properties
} And here is how you might use the let preferencesDatastore = FileDatastore<QuizPreferences>(purpose: "QuizSettings")
// To save the settings
let preferences = QuizPreferences(masjidName: "New Masjid", className: "New Class")
preferencesDatastore.save(preferences, forKey: "QuizPreferences")
// To load the settings
if let loadedPreferences = preferencesDatastore.load(forKey: "QuizPreferences") {
print("Loaded Masjid Name: \(loadedPreferences.masjidName)")
print("Loaded Class Name: \(loadedPreferences.className)")
} Remember to handle the possibility of the settings not existing yet when the app is first launched or after a flush. You may want to provide default values or prompt the user to enter these details if they are not found. Disclaimer: This comment was entirely generated using AI. Be aware that the information provided may be incorrect. Current plan usage: 21.08% Have feedback or need help? |
No description provided.
The text was updated successfully, but these errors were encountered: