Skip to content

Commit 6d59374

Browse files
committed
Homepage now updates recent project last modified date
1 parent 7ec0af2 commit 6d59374

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

lib/homepage.dart

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ import 'package:corecoder_develop/util/modules_manager.dart'
1515
show Module, ModulesManager, Template;
1616
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
1717

18+
/// Updates the file last modified
19+
void touchFile(File file, CCSolution solution) {
20+
var newTime = DateTime.now();
21+
solution.dateModified = newTime;
22+
file.setLastModifiedSync(newTime);
23+
}
1824
void loadSolution(
1925
CCSolution solution, BuildContext context, ModulesManager modulesManager) {
20-
/// Load the project
21-
// var template = modulesManager.getTemplateByIdentifier(solution.identifier);
2226
Navigator.pushNamed(context, EditorPage.routeName, arguments: solution);
2327
}
2428

@@ -59,6 +63,7 @@ class _HomePageState extends State<HomePage> {
5963
final Future<SharedPreferences> _pref = SharedPreferences.getInstance();
6064
var projectsWidgets = <Widget>[];
6165

66+
6267
void showSettings() {
6368
Navigator.pushNamed(context, SettingsPage.routeName);
6469
}
@@ -226,6 +231,7 @@ class _HomePageState extends State<HomePage> {
226231
void initState() {
227232
super.initState();
228233
loadPrefs();
234+
refreshRecentProjects();
229235
}
230236

231237
@override
@@ -248,15 +254,21 @@ class _HomePageState extends State<HomePage> {
248254
}
249255
}
250256

257+
251258
void refreshRecentProjects() {
252259
setState(() {
253260
projectsWidgets.clear();
261+
rpm.projects.sort((CCSolution a,CCSolution b){
262+
return b.dateModified.compareTo(a.dateModified);
263+
});
254264
for (CCSolution p in rpm.projects) {
255265
if (p.name == "")
256266
continue; // TODO: add better way to check if project is corrupt
257267
debugPrint(p.name);
258268
projectsWidgets.add(ListTile(
259269
onTap: () {
270+
touchFile(File(p.slnPath),p);
271+
refreshRecentProjects();
260272
loadSolution(p, context, mm);
261273
},
262274
leading: p.image != null
@@ -295,6 +307,11 @@ class _HomePageState extends State<HomePage> {
295307
),
296308
),
297309
const Spacer(flex: 1),
310+
TextButton(
311+
onPressed: () {refreshRecentProjects();},
312+
child: const Text("Refresh"),
313+
style: ElevatedButton.styleFrom(primary: Colors.black12),
314+
),
298315
TextButton(
299316
onPressed: () {},
300317
child: const Text("Add"),

lib/util/cc_project_structure.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ class CCSolution {
3131
var stat = await file.stat();
3232
if (await file.exists()) {
3333
String input = await file.readAsString();
34-
var obj = decoder.convert(input);
3534
try {
36-
35+
var obj = decoder.convert(input);
3736
var result = CCSolution(obj["name"], obj["description"] ?? "",
3837
obj["author"], obj["identifier"], filepath, file.parent.path, stat.modified);
3938

0 commit comments

Comments
 (0)