This commit is contained in:
Trey t
2022-12-23 09:43:48 -06:00
parent 49e3812659
commit 488832b777
9 changed files with 195 additions and 167 deletions

View File

@@ -25,7 +25,7 @@ struct FeelsApp: App {
}
UIApplication.shared.applicationIconBadgeNumber = 0
// PersistenceController.shared.clearDB()
PersistenceController.shared.populateMemory()
// PersistenceController.shared.populateMemory()
}
var body: some Scene {

View File

@@ -23,6 +23,8 @@ class IAPManager: ObservableObject {
@Published private(set) var subscriptions = [Product: (status: [Product.SubscriptionInfo.Status], renewalInfo: RenewalInfo)?]()
@AppStorage(UserDefaultsStore.Keys.firstLaunchDate.rawValue, store: GroupUserDefaults.groupDefaults) private var firstLaunchDate = Date()
@Published private(set) var isLoadingSubscriptions = false
public var sortedSubscriptionKeysByPriceOptions: [Product] {
subscriptions.keys.sorted(by: {
$0.price < $1.price
@@ -89,7 +91,7 @@ class IAPManager: ObservableObject {
}
private let iapIdentifiers = Set([
"com.88oakapps.ifeel.IAP.subscriptions.weekly",
// "com.88oakapps.ifeel.IAP.subscriptions.weekly",
"com.88oakapps.ifeel.IAP.subscriptions.monthly",
"com.88oakapps.ifeel.IAP.subscriptions.yearly"
])
@@ -97,6 +99,8 @@ class IAPManager: ObservableObject {
var expireOnTimer: Timer?
init() {
isLoadingSubscriptions = true
//Start a transaction listener as close to app launch as possible so you don't miss any transactions.
updateListenerTask = listenForTransactions()
@@ -133,6 +137,9 @@ class IAPManager: ObservableObject {
decideShowIAP()
decideShowIAPWarning()
DispatchQueue.main.async {
self.isLoadingSubscriptions = false
}
}
}

View File

@@ -26,6 +26,7 @@ extension PersistenceController {
}
func populateMemory() {
#if debug
for idx in 1..<255 {
let newItem = MoodEntry(context: viewContext)
newItem.timestamp = Calendar.current.date(byAdding: .day, value: -idx, to: Date())
@@ -48,6 +49,7 @@ extension PersistenceController {
let nsError = error as NSError
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
}
#endif
}
func generateObjectNotInArray(forDate date: Date = Date(), withMood mood: Mood = .placeholder) -> MoodEntry {
@@ -88,10 +90,10 @@ extension PersistenceController {
}
func longestStreak() -> [MoodEntry] {
// let predicate = NSPredicate(format: "forDate == %@", date as NSDate)
// let predicate = NSPredicate(format: "forDate == %@", date as NSDate)
let fetchRequest = NSFetchRequest<MoodEntry>(entityName: "MoodEntry")
// fetchRequest.predicate = predicate
// fetchRequest.predicate = predicate
fetchRequest.sortDescriptors = [NSSortDescriptor(key: "forDate", ascending: true)]
let data = try! viewContext.fetch(fetchRequest)
return data

View File

@@ -17,6 +17,7 @@ struct IAPWarningView: View {
private let height: Float
private let showManageSubClosure: (() -> Void)?
@State private var showSettings = false
public init(height: Float, iapManager: IAPManager, showManageSubClosure: (() -> Void)? = nil, showCountdownTimer: Bool = false) {
@@ -27,11 +28,17 @@ struct IAPWarningView: View {
var body: some View {
VStack {
Text(String(format: String(localized: "iap_warning_view_title"), iapManager.daysLeftBeforeIAP))
if let date = Calendar.current.date(byAdding: .day, value: 30, to: firstLaunchDate) {
Text(String(localized: "iap_warning_view_title"))
.font(.body)
.frame(minWidth: 0, maxWidth: .infinity)
.background(theme.currentTheme.secondaryBGColor)
Text(date, style: .relative)
.font(.body)
.bold()
.foregroundColor(textColor)
Button(action: {
showSettings.toggle()
}, label: {
@@ -45,7 +52,7 @@ struct IAPWarningView: View {
.frame(height: 50)
.background(RoundedRectangle(cornerRadius: 10).fill(DefaultMoodTint.color(forMood: .great)))
}
// .frame(height: CGFloat(height))
}
.frame(minWidth: 0, maxWidth: .infinity)
.padding()
.background(theme.currentTheme.secondaryBGColor)

View File

@@ -116,7 +116,6 @@ struct MonthView: View {
}
}
.onPreferenceChange(ViewOffsetKey.self) { value in
print(value)
iAPWarningViewHidden = value < 0
}
}

View File

@@ -100,6 +100,17 @@ struct PurchaseButtonView: View {
VStack {
ZStack {
theme.currentTheme.secondaryBGColor
if iapManager.isLoadingSubscriptions {
VStack(spacing: 20) {
Text(String(localized: "purchase_view_loading"))
.font(.body)
.bold()
.frame(minWidth: 0, maxWidth: .infinity, alignment: .center)
ProgressView()
}
} else {
VStack(spacing: 20) {
Text(String(localized: "purchase_view_title"))
.font(.body)
@@ -156,9 +167,10 @@ struct PurchaseButtonView: View {
.frame(minWidth: 0, maxWidth: .infinity)
}
}
}
.background(.ultraThinMaterial)
.frame(minWidth: 0, maxWidth: .infinity)
}
.background(.clear)
}

View File

@@ -37,24 +37,25 @@ struct SettingsView: View {
closeButtonView
.padding()
// cloudKitEnable
// cloudKitEnable
subscriptionInfoView
canDelete
showOnboardingButton
specialThanksCell
// specialThanksCell
}
#if DEBUG
Group {
Divider()
Text("Test builds only")
addTestDataCell
clearDB
// randomIcons
// randomIcons
if useCloudKit {
cloudKitStatus
}
// fixWeekday
// fixWeekday
exportData
importData
editFirstLaunchDatePast
@@ -62,7 +63,7 @@ struct SettingsView: View {
Divider()
}
Spacer()
#endif
Text("\(Bundle.main.appName) v \(Bundle.main.versionNumber) (Build \(Bundle.main.buildNumber))")
.font(.body)
}
@@ -126,7 +127,7 @@ struct SettingsView: View {
let localTime = dateFormatter.date(from: columns[3])!
moodEntry.weekDay = Int16(Calendar.current.component(.weekday, from: localTime))
// let _ = print("import info: ", columns[3], dateFormatter.date(from: columns[3]), localTime, Int16(Calendar.current.component(.weekday, from: localTime)))
// let _ = print("import info: ", columns[3], dateFormatter.date(from: columns[3]), localTime, Int16(Calendar.current.component(.weekday, from: localTime)))
try! PersistenceController.shared.viewContext.save()
}
PersistenceController.shared.saveAndRunDataListerners()
@@ -415,16 +416,16 @@ struct SettingsView: View {
Button(action: {
var iconViews = [UIImage]()
// for _ in 0...300 {
// iconViews.append(
// IconView(iconViewModel: IconViewModel(
// backgroundImage: MoodImages.FontAwesome.icon(forMood: .great),
// bgColor: Color.random(),
// bgOverlayColor: Color.random(),
// centerImage: MoodImages.FontAwesome.icon(forMood: .great),
// innerColor: Color.random())
// ).asImage(size: CGSize(width: 1024, height: 1024)))
// }
// for _ in 0...300 {
// iconViews.append(
// IconView(iconViewModel: IconViewModel(
// backgroundImage: MoodImages.FontAwesome.icon(forMood: .great),
// bgColor: Color.random(),
// bgOverlayColor: Color.random(),
// centerImage: MoodImages.FontAwesome.icon(forMood: .great),
// innerColor: Color.random())
// ).asImage(size: CGSize(width: 1024, height: 1024)))
// }
iconViews.append(
IconView(iconViewModel: IconViewModel(
@@ -477,45 +478,45 @@ struct SettingsView: View {
)
// iconViews.append(
// IconView(iconViewModel: IconViewModel(
// backgroundImage: MoodImages.FontAwesome.icon(forMood: .great),
// bgColor: Color(hex: "EF0CF3"),
// bgOverlayColor: Color(hex: "EF0CF3").darker(by: 40),
// centerImage: MoodImages.FontAwesome.icon(forMood: .great),
// innerColor: Color(hex: "EF0CF3"))
// ).asImage(size: CGSize(width: 1024, height: 1024))
// )
//
// iconViews.append(
// IconView(iconViewModel: IconViewModel(
// backgroundImage: MoodImages.FontAwesome.icon(forMood: .great),
// bgColor: Color(hex: "1AE5D6"),
// bgOverlayColor: Color(hex: "1AE5D6").darker(by: 40),
// centerImage: MoodImages.FontAwesome.icon(forMood: .great),
// innerColor: Color(hex: "1AE5D6"))
// ).asImage(size: CGSize(width: 1024, height: 1024))
// )
//
// iconViews.append(
// IconView(iconViewModel: IconViewModel(
// backgroundImage: MoodImages.FontAwesome.icon(forMood: .great),
// bgColor: Color(hex: "633EC1"),
// bgOverlayColor: Color(hex: "633EC1").darker(by: 40),
// centerImage: MoodImages.FontAwesome.icon(forMood: .great),
// innerColor: Color(hex: "633EC1"))
// ).asImage(size: CGSize(width: 1024, height: 1024))
// )
//
// iconViews.append(
// IconView(iconViewModel: IconViewModel(
// backgroundImage: MoodImages.FontAwesome.icon(forMood: .great),
// bgColor: Color(hex: "10F30C"),
// bgOverlayColor: Color(hex: "10F30C").darker(by: 40),
// centerImage: MoodImages.FontAwesome.icon(forMood: .great),
// innerColor: Color(hex: "10F30C"))
// ).asImage(size: CGSize(width: 1024, height: 1024))
// )
// iconViews.append(
// IconView(iconViewModel: IconViewModel(
// backgroundImage: MoodImages.FontAwesome.icon(forMood: .great),
// bgColor: Color(hex: "EF0CF3"),
// bgOverlayColor: Color(hex: "EF0CF3").darker(by: 40),
// centerImage: MoodImages.FontAwesome.icon(forMood: .great),
// innerColor: Color(hex: "EF0CF3"))
// ).asImage(size: CGSize(width: 1024, height: 1024))
// )
//
// iconViews.append(
// IconView(iconViewModel: IconViewModel(
// backgroundImage: MoodImages.FontAwesome.icon(forMood: .great),
// bgColor: Color(hex: "1AE5D6"),
// bgOverlayColor: Color(hex: "1AE5D6").darker(by: 40),
// centerImage: MoodImages.FontAwesome.icon(forMood: .great),
// innerColor: Color(hex: "1AE5D6"))
// ).asImage(size: CGSize(width: 1024, height: 1024))
// )
//
// iconViews.append(
// IconView(iconViewModel: IconViewModel(
// backgroundImage: MoodImages.FontAwesome.icon(forMood: .great),
// bgColor: Color(hex: "633EC1"),
// bgOverlayColor: Color(hex: "633EC1").darker(by: 40),
// centerImage: MoodImages.FontAwesome.icon(forMood: .great),
// innerColor: Color(hex: "633EC1"))
// ).asImage(size: CGSize(width: 1024, height: 1024))
// )
//
// iconViews.append(
// IconView(iconViewModel: IconViewModel(
// backgroundImage: MoodImages.FontAwesome.icon(forMood: .great),
// bgColor: Color(hex: "10F30C"),
// bgOverlayColor: Color(hex: "10F30C").darker(by: 40),
// centerImage: MoodImages.FontAwesome.icon(forMood: .great),
// innerColor: Color(hex: "10F30C"))
// ).asImage(size: CGSize(width: 1024, height: 1024))
// )
for (idx, image) in iconViews.enumerated() {
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
@@ -576,7 +577,7 @@ struct TextFile: FileDocument {
let weekDay = entry.weekDay
let dataString = "\(canDelete),\(canEdit),\(entryType),\(String(describing: forDate)),\(moodValue),\(String(describing:timestamp)),\(weekDay)\n"
// print("DATA: \(dataString)")
// print("DATA: \(dataString)")
csvString = csvString.appending(dataString)
}
text = csvString

View File

@@ -81,7 +81,6 @@ struct YearView: View {
.edgesIgnoringSafeArea(.all)
)
.onPreferenceChange(ViewOffsetKey.self) { value in
print(value)
iAPWarningViewHidden = value < 0
}
}

View File

@@ -114,8 +114,9 @@
"purchase_view_current_subscription" = "Current Subscription";
"purchase_view_current_subscription_expires_in" = "Trial expires in:";
"purchase_view_current_subscription_expired_on" = "Trial expired on:";
"purchase_view_loading" = "Loading subscription options";
"iap_warning_view_title" = "In %d day(s) this view will no longer scroll";
"iap_warning_view_title" = "This view will no longer scroll in ";
"iap_warning_view_buy_button" = "Subscribe Now";
/* not used */
"onboarding_title_title" = "What would you like the reminder to say?";