Skip to content

Commit

Permalink
patched autosave behaviour of spamming downloads
Browse files Browse the repository at this point in the history
also we're at 1.2.4 now ffs
  • Loading branch information
OverPoweredDev committed Sep 13, 2021
1 parent 60709c5 commit d030a2a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
30 changes: 28 additions & 2 deletions src/lib/homepage/body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:Junior/homepage/components/title.dart';
import 'package:Junior/model/changelog.dart';
import 'package:Junior/model/novel.dart';
import 'package:Junior/model/preferences.dart';
import 'package:Junior/settings_page/components/export_data.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

Expand Down Expand Up @@ -41,17 +42,19 @@ class _HomePageState extends State<HomePage> {
novelList = await getNovelList();
preferences = await loadPreferences();

if(preferences.exportAutomatically) autoSave();

searchList.addAll(novelList);
sortBy(preferences.sortBy);
}

showChangelog(BuildContext context) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
bool hasSeenChangelog = prefs.getBool('seenChangeLog-1.2.3') ?? false;
bool hasSeenChangelog = prefs.getBool('seenChangeLog-1.2.4') ?? false;

if (!hasSeenChangelog) {
showChangeDialog(context);
prefs.setBool('seenChangeLog-1.2.3', true);
prefs.setBool('seenChangeLog-1.2.4', true);
}
}

Expand Down Expand Up @@ -157,4 +160,27 @@ class _HomePageState extends State<HomePage> {
});
}
}

void autoSave() async {
bool moreThanADay(int milliseconds) {
return DateTime.now().millisecondsSinceEpoch - milliseconds > 86400000;
}

SharedPreferences prefs = await SharedPreferences.getInstance();
int milliseconds = prefs.getInt('lastSaved') ?? DateTime.now().millisecondsSinceEpoch - 86500000;
if(moreThanADay(milliseconds)) {
await exportData('autosaves/novelList-autosave-' + getRandomNumbers() + '.txt');
showDialog(
context: context,
builder: (BuildContext context) => AlertDialog(
content: Text(
'Autosaved Data to Download/Junior/autosaves/',
style: TextStyle(color: textColor),
),
backgroundColor: tileColor.withAlpha(255),
),
);
prefs.setInt('lastSaved', DateTime.now().millisecondsSinceEpoch);
}
}
}
4 changes: 2 additions & 2 deletions src/lib/model/changelog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ showChangeDialog(BuildContext context) {
context: context,
builder: (BuildContext context) => AlertDialog(
title: Text(
'Version 1.2.3',
'Version 1.2.4',
style: TextStyle(color: textColor),
),
content: Text(
'The previous update caused a lot of savefiles in Downloads. A fix for now is storing it all in a dedicated folder',
'Along with it\'s dedicated folder, AutoSaves are now only saved once a day',
style: TextStyle(color: textColor),
),
backgroundColor: tileColor.withAlpha(255),
Expand Down
6 changes: 0 additions & 6 deletions src/lib/model/novel.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'dart:convert';
import 'dart:io';

import 'package:Junior/model/preferences.dart';
import 'package:Junior/settings_page/components/export_data.dart';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';

Expand Down Expand Up @@ -102,10 +100,6 @@ Future<File> saveNovelList(novelList) async {
final file = await _localFile;
final novelListJSON = jsonEncode(novelList);

final prefs = await loadPreferences();
if (prefs.exportAutomatically)
exportData('autosaves/novelList-autosave-' + getRandomNumbers() + '.txt');

return file.writeAsString(novelListJSON);
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/settings_page/body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class _SettingsPageState extends State<SettingsPage> {
backgroundColor: backgroundColor,
body: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.only(top: 80, bottom: 20),
padding: EdgeInsets.only(top: 80),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expand Down Expand Up @@ -246,7 +246,7 @@ class _SettingsPageState extends State<SettingsPage> {
},
),
],
)
),
],
),
],
Expand Down

0 comments on commit d030a2a

Please sign in to comment.