Skip to content
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

[303] Add rich text notes class and migration #345

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ analyzer:
plugins:
- custom_lint
language:
strict-inference: true # Force to specify generic types
strict-inference: true # Force to specify generic rich_text

linter:
rules:
Expand Down
5 changes: 3 additions & 2 deletions lib/common/actions/notes/add.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'select.dart';

import '../../../models/note/note.dart';
import '../../../navigation/navigator_utils.dart';
import '../../../providers/notes/notes_provider.dart';
import '../../../providers/notifiers/notifiers.dart';
import 'select.dart';

/// Adds a note.
///
Expand All @@ -14,7 +15,7 @@ Future<void> addNote(BuildContext context, WidgetRef ref, {String? content}) asy
exitNotesSelectionMode(context, ref);
}

final note = content == null ? Note.empty() : Note.content(content);
final note = content == null ? RichTextNote.empty() : RichTextNote.content(content);

// If some content was provided, immediately save the note without waiting for changes in the editor
if (content != null) {
Expand Down
22 changes: 11 additions & 11 deletions lib/common/constants/notes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import '../../models/note/note.dart';
import '../../utils/localizations_utils.dart';

/// Note displayed on the very first run of the application to welcome the user.
final welcomeNote = Note(
final welcomeNote = RichTextNote(
deleted: false,
pinned: true,
createdTime: DateTime.now(),
Expand All @@ -14,7 +14,7 @@ final welcomeNote = Note(
/// Notes used when running integration tests.
final integrationTestNotes = List.generate(
100,
(index) => Note(
(index) => RichTextNote(
deleted: false,
pinned: false,
createdTime: DateTime(2000, 01, 01, 12).subtract(Duration(minutes: index)),
Expand All @@ -25,7 +25,7 @@ final integrationTestNotes = List.generate(
)..addAll(
List.generate(
100,
(index) => Note(
(index) => RichTextNote(
deleted: true,
pinned: false,
createdTime: DateTime(2000, 01, 01, 12).subtract(Duration(minutes: index)),
Expand All @@ -38,7 +38,7 @@ final integrationTestNotes = List.generate(

/// Notes used when taking screenshots of the application for the stores.
final screenshotNotes = [
Note(
RichTextNote(
deleted: false,
pinned: true,
createdTime: DateTime(2000, 01, 01, 12),
Expand All @@ -47,7 +47,7 @@ final screenshotNotes = [
content:
'[{"insert":"Simple","attributes":{"b":true}},{"insert":", "},{"insert":"local","attributes":{"i":true}},{"insert":", "},{"insert":"material design","attributes":{"u":true}},{"insert":" notes\\n"}]',
),
Note(
RichTextNote(
deleted: false,
pinned: false,
createdTime: DateTime(2000, 01, 01, 11, 55),
Expand All @@ -56,23 +56,23 @@ final screenshotNotes = [
content:
'[{"insert":"Write text notes"},{"insert":"\\n","attributes":{"block":"cl","checked":true}},{"insert":"Use formatting options and undo/redo"},{"insert":"\\n","attributes":{"block":"cl","checked":true}},{"insert":"Use quick action to add from your homescreen"},{"insert":"\\n","attributes":{"block":"cl","checked":true}}]',
),
Note(
RichTextNote(
deleted: false,
pinned: false,
createdTime: DateTime(2000, 01, 01, 11, 50),
editedTime: DateTime(2000, 01, 01, 11, 50),
title: "Organize",
content: '[{"insert":"Search, sort and display in a list or a grid\\nPin and recover from the bin\\n"}]',
),
Note(
RichTextNote(
deleted: false,
pinned: false,
createdTime: DateTime(2000, 01, 01, 11, 50),
editedTime: DateTime(2000, 01, 01, 11, 50),
title: "Categorize",
content: '[{"insert":"Categorize notes with labels\\nPin, hide and colorize labels\\n"}]',
),
Note(
RichTextNote(
deleted: false,
pinned: false,
createdTime: DateTime(2000, 01, 01, 11, 45),
Expand All @@ -81,7 +81,7 @@ final screenshotNotes = [
content:
'[{"insert":"Create a note from shared text\\nShare notes as text and export as Markdown\\nBackup notes as JSON\\n"}]',
),
Note(
RichTextNote(
deleted: false,
pinned: false,
createdTime: DateTime(2000, 01, 01, 11, 40),
Expand All @@ -90,15 +90,15 @@ final screenshotNotes = [
content:
"[{\"insert\":\"Choose your language\\nChoose your theme (including black and dynamic)\\nHide features you don't need\\n\"}]",
),
Note(
RichTextNote(
deleted: false,
pinned: false,
createdTime: DateTime(2000, 01, 01, 11, 35),
editedTime: DateTime(2000, 01, 01, 11, 35),
title: "Protect",
content: '[{"insert":"Your data never leaves your device\\nEncrypt your exports\\n"}]',
),
Note(
RichTextNote(
deleted: true,
pinned: false,
createdTime: DateTime(2000, 01, 01, 12),
Expand Down
16 changes: 8 additions & 8 deletions lib/common/logs/app_logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../constants/constants.dart';
import '../enums/mime_type.dart';
import '../extensions/date_time_extensions.dart';
import '../extensions/string_extension.dart';
import '../../l10n/app_localizations/app_localizations.g.dart';
import '../../utils/files_utils.dart';
import '../../utils/snack_bar_utils.dart';
import 'package:logger/logger.dart' hide FileOutput;
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';

import '../../l10n/app_localizations/app_localizations.g.dart';
import '../../utils/files_utils.dart';
import '../../utils/snack_bar_utils.dart';
import '../constants/constants.dart';
import '../enums/mime_type.dart';
import '../extensions/date_time_extensions.dart';
import '../extensions/string_extension.dart';
import 'filters/debug_filter.dart';
import 'filters/release_filter.dart';

Expand Down Expand Up @@ -71,7 +71,7 @@ class AppLogger {
_fileLogger.e(details.exceptionAsString().firstLine, error: details.exception, stackTrace: details.stack);
};
PlatformDispatcher.instance.onError = (exception, stackTrace) {
_fileLogger.e(exception.toString().firstLine, error: exception, stackTrace: stackTrace);
e(exception.toString().firstLine ?? 'Unknown exception', exception, stackTrace);

return true;
};
Expand Down
3 changes: 3 additions & 0 deletions lib/common/preferences/preference_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ enum PreferenceKey<T> {
sortMethod<String>('editedDate', backup: false),
sortAscending<bool>(false, backup: false),
layout<String>('list', backup: false),

// Database
databaseVersion(1),
;

/// Default value of this preference.
Expand Down
47 changes: 47 additions & 0 deletions lib/models/legacy/note.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'package:isar/isar.dart';
import 'package:json_annotation/json_annotation.dart';

import '../label/label.dart';

part 'note.g.dart';

// ignore_for_file: must_be_immutable, public_member_api_docs

List<String> _labelToJson(IsarLinks<Label> labels) => labels.map((label) => label.name).toList();

/// Legacy model of the rich text note.
@JsonSerializable()
@Collection()
@Deprecated('Legacy model of the rich text note')
class Note {
@JsonKey(includeFromJson: false, includeToJson: false)
Id id = Isar.autoIncrement;

@JsonKey(includeFromJson: false, includeToJson: false)
@ignore
bool selected = false;

bool deleted;

bool pinned;

DateTime createdTime;

DateTime editedTime;

String title;

String content;

@JsonKey(includeFromJson: false, includeToJson: true, toJson: _labelToJson)
IsarLinks<Label> labels = IsarLinks<Label>();

Note({
required this.deleted,
required this.pinned,
required this.createdTime,
required this.editedTime,
required this.title,
required this.content,
});
}
Loading
Loading