creation
commit
53820a6811
|
@ -0,0 +1,18 @@
|
||||||
|
*.iml
|
||||||
|
.gradle
|
||||||
|
/local.properties
|
||||||
|
/.idea/caches
|
||||||
|
/.idea/libraries
|
||||||
|
/.idea/modules.xml
|
||||||
|
/.idea/misc.xml
|
||||||
|
/.idea/vcs.xml
|
||||||
|
/.idea/workspace.xml
|
||||||
|
/.idea/navEditor.xml
|
||||||
|
/.idea/assetWizardSettings.xml
|
||||||
|
/.idea/deploymentTargetDropDown.xml
|
||||||
|
.DS_Store
|
||||||
|
/build
|
||||||
|
/captures
|
||||||
|
.externalNativeBuild
|
||||||
|
.cxx
|
||||||
|
local.properties
|
|
@ -0,0 +1,16 @@
|
||||||
|
# Contributing to My Brain
|
||||||
|
|
||||||
|
### To contribute :
|
||||||
|
|
||||||
|
- Report bugs/glitches.
|
||||||
|
- Create new issues to give us ideas and feedback.
|
||||||
|
- Ask questions or suggest ideas in the comments section of any issue.
|
||||||
|
- You can also help us clean up the [issue section](https://github.com/mhss1/MyBrain/issues) by identifying duplicate issues.
|
||||||
|
|
||||||
|
### Or if you are a developer:
|
||||||
|
|
||||||
|
- Pick an issue or create a new one.
|
||||||
|
- Fork the repo.
|
||||||
|
- Create a feature branch in your fork and make your changes.
|
||||||
|
- Keep it simple and make sure the app runs on an actual Android device and everything works as expected
|
||||||
|
- Submit a pull request to the `dev` branch of the official [My Brain repo](https://github.com/mhss1/MyBrain/pulls) (PR to master will be rejected).
|
|
@ -0,0 +1,674 @@
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
@ -0,0 +1,62 @@
|
||||||
|
![Stars](https://img.shields.io/github/stars/mhss1/mybrain?style=social)
|
||||||
|
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
|
||||||
|
|
||||||
|
<img align="left" width="80" height="80" src="https://user-images.githubusercontent.com/58703865/169863670-eee3c8f1-1308-4eb2-9aea-f7c0a47e6a31.png" alt="app icon">
|
||||||
|
|
||||||
|
# My Brain
|
||||||
|
|
||||||
|
|
||||||
|
### Open-source, All-in-one productivity app for Tasks, Notes, Calendar, Diary and Bookmarks.
|
||||||
|
|
||||||
|
<div align="left">
|
||||||
|
<img src = "https://user-images.githubusercontent.com/58703865/169859205-54c0b8f3-7423-4c2a-9a9b-9e43861814c0.png" width ="160" />
|
||||||
|
<img src = "https://user-images.githubusercontent.com/58703865/169859229-04fbad81-80f8-4b47-8d8a-0242a16a1f8b.png" width ="160" />
|
||||||
|
<img src = "https://user-images.githubusercontent.com/58703865/169859305-7127fcf4-12fe-4f52-a605-c8b4c77917df.png" width ="160" />
|
||||||
|
<img src = "https://user-images.githubusercontent.com/58703865/169859328-1abddd5a-d88c-4877-9078-9e12e311c465.png" width ="160" />
|
||||||
|
<img src = "https://user-images.githubusercontent.com/58703865/169859351-5608acc9-b99e-41c4-8048-6d036e8c189b.png" width ="160" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
[screenshots made by previewed](https://previewed.app/template/00CBF3F6)
|
||||||
|
|
||||||
|
[<img src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png"
|
||||||
|
alt="Get it on F-Droid"
|
||||||
|
height="80">](https://f-droid.org/packages/com.mhss.app.mybrain)
|
||||||
|
[<img src="https://camo.githubusercontent.com/70bffd8873ab81e1bb0bccc44e488c3a989e3bd5/68747470733a2f2f692e6962622e636f2f71306d6463345a2f6765742d69742d6f6e2d6769746875622e706e67"
|
||||||
|
alt="Get it on GitHub"
|
||||||
|
height="80">](https://github.com/mhss1/MyBrain/releases/latest)
|
||||||
|
|
||||||
|
## Features
|
||||||
|
- Private with no data collection and no internet permission at all.
|
||||||
|
- Create tasks with priority, sub-tasks, description and due date and reminders.
|
||||||
|
- Create Notes that supports markdown which enables you to use Headers, lists, links etc..
|
||||||
|
- Record your mood daily and view your mood summary with beautiful graphs.
|
||||||
|
- Save bookmarks for later by using the share menu from any other app.
|
||||||
|
- View your calendar events in a modern view and also with a beautiful home screen widget.
|
||||||
|
- Dashboard screen to see your tasks, calendar events, and more to see your day at a glance.
|
||||||
|
|
||||||
|
## Technologies
|
||||||
|
- 100% Kotlin.
|
||||||
|
- Made Using Jetpack Compose.
|
||||||
|
- Widgets made with Compose Glance.
|
||||||
|
- Following Clean Architecture approach.
|
||||||
|
- Following MVVM Architectural Design Pattern.
|
||||||
|
### Used in the app :
|
||||||
|
- Room DB
|
||||||
|
- Hilt
|
||||||
|
- Preferences DataStore
|
||||||
|
- Kotlin coroutines
|
||||||
|
- Kotlin Flows
|
||||||
|
- Alarm Manager
|
||||||
|
- Jetpack Compose
|
||||||
|
- Compose Glance
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
To get started, take a look at [CONTRIBUTING.md](CONTRIBUTING.md).
|
||||||
|
|
||||||
|
---
|
||||||
|
Icons Attribution
|
||||||
|
<a href="https://www.flaticon.com/free-icons/paper" title="paper icons">Paper icons created by Freepik - Flaticon</a>
|
||||||
|
<a href="https://www.flaticon.com/free-icons/list" title="list icons">List icons created by Freepik - Flaticon</a>
|
||||||
|
<a href="https://www.flaticon.com/free-icons/calendar" title="calendar icons">Calendar icons created by Freepik - Flaticon</a>
|
||||||
|
<a href="https://www.flaticon.com/free-icons/bookmark" title="bookmark icons">Bookmark icons created by Freepik - Flaticon</a>
|
||||||
|
<a href="https://www.flaticon.com/free-icons/book" title="book icons">Book icons created by Freepik - Flaticon</a>
|
|
@ -0,0 +1 @@
|
||||||
|
/build
|
|
@ -0,0 +1,136 @@
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id("com.android.application")
|
||||||
|
id("org.jetbrains.kotlin.android")
|
||||||
|
id ("com.google.dagger.hilt.android")
|
||||||
|
id ("com.google.devtools.ksp")
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
namespace = "com.mhss.app.mybrain"
|
||||||
|
compileSdk = 34
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
applicationId = "com.mhss.app.mybrain"
|
||||||
|
minSdk = 26
|
||||||
|
targetSdk = 34
|
||||||
|
versionCode = 7
|
||||||
|
versionName = "1.0.6"
|
||||||
|
|
||||||
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
vectorDrawables {
|
||||||
|
useSupportLibrary = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buildTypes {
|
||||||
|
release {
|
||||||
|
isMinifyEnabled = true
|
||||||
|
proguardFiles(
|
||||||
|
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||||
|
"proguard-rules.pro"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
debug {
|
||||||
|
isMinifyEnabled = false
|
||||||
|
applicationIdSuffix = ".debug"
|
||||||
|
resValue("string", "app_name", "MyBrain Debug")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
|
}
|
||||||
|
kotlinOptions {
|
||||||
|
jvmTarget = "17"
|
||||||
|
|
||||||
|
}
|
||||||
|
buildFeatures {
|
||||||
|
compose = true
|
||||||
|
buildConfig = true
|
||||||
|
}
|
||||||
|
composeOptions {
|
||||||
|
kotlinCompilerExtensionVersion = "1.5.2"
|
||||||
|
}
|
||||||
|
packaging {
|
||||||
|
resources {
|
||||||
|
excludes += "/META-INF/{AL2.0,LGPL2.1}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
androidResources {
|
||||||
|
generateLocaleConfig = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
val roomVersion = "2.6.0"
|
||||||
|
val coroutinesVersion = "1.7.3"
|
||||||
|
val lifecycleVersion = "2.6.2"
|
||||||
|
val workVersion = "2.8.1"
|
||||||
|
implementation(platform("androidx.compose:compose-bom:2023.09.01"))
|
||||||
|
|
||||||
|
implementation("androidx.core:core-ktx:1.12.0")
|
||||||
|
implementation("androidx.compose.ui:ui")
|
||||||
|
implementation("androidx.compose.material:material")
|
||||||
|
implementation("androidx.compose.ui:ui-tooling-preview")
|
||||||
|
implementation("androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion")
|
||||||
|
implementation("androidx.activity:activity-compose:1.8.0")
|
||||||
|
testImplementation("junit:junit:4.13.2")
|
||||||
|
androidTestImplementation("androidx.test.ext:junit:1.1.5")
|
||||||
|
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
|
||||||
|
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
|
||||||
|
debugImplementation("androidx.compose.ui:ui-tooling")
|
||||||
|
|
||||||
|
// Compose navigation
|
||||||
|
implementation("androidx.navigation:navigation-compose:2.7.4")
|
||||||
|
implementation("androidx.hilt:hilt-navigation-compose:1.0.0")
|
||||||
|
|
||||||
|
// Room
|
||||||
|
implementation("androidx.room:room-runtime:$roomVersion")
|
||||||
|
ksp("androidx.room:room-compiler:$roomVersion")
|
||||||
|
implementation("androidx.room:room-ktx:$roomVersion")
|
||||||
|
|
||||||
|
//Dagger - Hilt
|
||||||
|
implementation("com.google.dagger:hilt-android:2.48")
|
||||||
|
ksp("com.google.dagger:hilt-android-compiler:2.48")
|
||||||
|
ksp("androidx.hilt:hilt-compiler:1.0.0")
|
||||||
|
implementation("androidx.hilt:hilt-work:1.0.0")
|
||||||
|
|
||||||
|
// Coroutines
|
||||||
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
|
||||||
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion")
|
||||||
|
|
||||||
|
// Gson
|
||||||
|
implementation("com.google.code.gson:gson:2.10")
|
||||||
|
|
||||||
|
// Preferences DataStore
|
||||||
|
implementation("androidx.datastore:datastore-preferences:1.0.0")
|
||||||
|
|
||||||
|
// Accompanist libraries
|
||||||
|
implementation("com.google.accompanist:accompanist-flowlayout:0.23.1")
|
||||||
|
implementation("com.google.accompanist:accompanist-systemuicontroller:0.23.1")
|
||||||
|
implementation("com.google.accompanist:accompanist-permissions:0.23.1")
|
||||||
|
|
||||||
|
// Compose MarkDown
|
||||||
|
implementation("com.github.jeziellago:compose-markdown:0.3.4")
|
||||||
|
|
||||||
|
// Compose Glance (Widgets)
|
||||||
|
implementation("androidx.glance:glance-appwidget:1.0.0")
|
||||||
|
implementation("androidx.glance:glance-material:1.0.0")
|
||||||
|
|
||||||
|
//Moshi
|
||||||
|
implementation("com.squareup.moshi:moshi-kotlin:1.14.0")
|
||||||
|
|
||||||
|
// WorkManager
|
||||||
|
implementation("androidx.work:work-runtime-ktx:$workVersion")
|
||||||
|
|
||||||
|
// Compose live data
|
||||||
|
implementation("androidx.compose.runtime:runtime-livedata")
|
||||||
|
|
||||||
|
// DocumentFile
|
||||||
|
implementation("androidx.documentfile:documentfile:1.0.1")
|
||||||
|
}
|
||||||
|
|
||||||
|
ksp {
|
||||||
|
arg("room.schemaLocation", "$projectDir/schemas")
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
# Add project specific ProGuard rules here.
|
||||||
|
# You can control the set of applied configuration files using the
|
||||||
|
# proguardFiles setting in build.gradle.kts.
|
||||||
|
#
|
||||||
|
# For more details, see
|
||||||
|
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||||
|
|
||||||
|
# If your project uses WebView with JS, uncomment the following
|
||||||
|
# and specify the fully qualified class name to the JavaScript interface
|
||||||
|
# class:
|
||||||
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
|
# public *;
|
||||||
|
#}
|
||||||
|
|
||||||
|
# Uncomment this to preserve the line number information for
|
||||||
|
# debugging stack traces.
|
||||||
|
#-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
||||||
|
# If you keep the line number information, uncomment this to
|
||||||
|
# hide the original source file name.
|
||||||
|
#-renamesourcefileattribute SourceFile
|
||||||
|
-dontobfuscate
|
||||||
|
|
||||||
|
-dontwarn org.bouncycastle.jsse.BCSSLParameters
|
||||||
|
-dontwarn org.bouncycastle.jsse.BCSSLSocket
|
||||||
|
-dontwarn org.bouncycastle.jsse.provider.BouncyCastleJsseProvider
|
||||||
|
-dontwarn org.conscrypt.Conscrypt$Version
|
||||||
|
-dontwarn org.conscrypt.Conscrypt
|
||||||
|
-dontwarn org.conscrypt.ConscryptHostnameVerifier
|
||||||
|
-dontwarn org.openjsse.javax.net.ssl.SSLParameters
|
||||||
|
-dontwarn org.openjsse.javax.net.ssl.SSLSocket
|
||||||
|
-dontwarn org.openjsse.net.ssl.OpenJSSE
|
|
@ -0,0 +1,258 @@
|
||||||
|
{
|
||||||
|
"formatVersion": 1,
|
||||||
|
"database": {
|
||||||
|
"version": 1,
|
||||||
|
"identityHash": "1e2bd9b0955419648a3c83b7027f8433",
|
||||||
|
"entities": [
|
||||||
|
{
|
||||||
|
"tableName": "notes",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `content` TEXT NOT NULL, `created_date` INTEGER NOT NULL, `updated_date` INTEGER NOT NULL, `pinned` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "title",
|
||||||
|
"columnName": "title",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "content",
|
||||||
|
"columnName": "content",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "createdDate",
|
||||||
|
"columnName": "created_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "updatedDate",
|
||||||
|
"columnName": "updated_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "pinned",
|
||||||
|
"columnName": "pinned",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
],
|
||||||
|
"autoGenerate": true
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "tasks",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `description` TEXT NOT NULL, `is_completed` INTEGER NOT NULL, `priority` INTEGER NOT NULL, `created_date` INTEGER NOT NULL, `updated_date` INTEGER NOT NULL, `sub_tasks` TEXT NOT NULL, `dueDate` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "title",
|
||||||
|
"columnName": "title",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "description",
|
||||||
|
"columnName": "description",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isCompleted",
|
||||||
|
"columnName": "is_completed",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "priority",
|
||||||
|
"columnName": "priority",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "createdDate",
|
||||||
|
"columnName": "created_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "updatedDate",
|
||||||
|
"columnName": "updated_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "subTasks",
|
||||||
|
"columnName": "sub_tasks",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "dueDate",
|
||||||
|
"columnName": "dueDate",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
],
|
||||||
|
"autoGenerate": true
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "diary",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `content` TEXT NOT NULL, `created_date` INTEGER NOT NULL, `updated_date` INTEGER NOT NULL, `mood` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "title",
|
||||||
|
"columnName": "title",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "content",
|
||||||
|
"columnName": "content",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "createdDate",
|
||||||
|
"columnName": "created_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "updatedDate",
|
||||||
|
"columnName": "updated_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "mood",
|
||||||
|
"columnName": "mood",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
],
|
||||||
|
"autoGenerate": true
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "bookmarks",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`url` TEXT NOT NULL, `title` TEXT NOT NULL, `description` TEXT NOT NULL, `created_date` INTEGER NOT NULL, `updated_date` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "url",
|
||||||
|
"columnName": "url",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "title",
|
||||||
|
"columnName": "title",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "description",
|
||||||
|
"columnName": "description",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "createdDate",
|
||||||
|
"columnName": "created_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "updatedDate",
|
||||||
|
"columnName": "updated_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
],
|
||||||
|
"autoGenerate": true
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "alarms",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `time` INTEGER NOT NULL, PRIMARY KEY(`id`))",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "time",
|
||||||
|
"columnName": "time",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
],
|
||||||
|
"autoGenerate": false
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"views": [],
|
||||||
|
"setupQueries": [
|
||||||
|
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||||
|
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '1e2bd9b0955419648a3c83b7027f8433')"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,302 @@
|
||||||
|
{
|
||||||
|
"formatVersion": 1,
|
||||||
|
"database": {
|
||||||
|
"version": 2,
|
||||||
|
"identityHash": "fad6f140a4272bf79b901ad86cd27d66",
|
||||||
|
"entities": [
|
||||||
|
{
|
||||||
|
"tableName": "notes",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `content` TEXT NOT NULL, `created_date` INTEGER NOT NULL, `updated_date` INTEGER NOT NULL, `pinned` INTEGER NOT NULL, `folder_id` INTEGER, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, FOREIGN KEY(`folder_id`) REFERENCES `note_folders`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "title",
|
||||||
|
"columnName": "title",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "content",
|
||||||
|
"columnName": "content",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "createdDate",
|
||||||
|
"columnName": "created_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "updatedDate",
|
||||||
|
"columnName": "updated_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "pinned",
|
||||||
|
"columnName": "pinned",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "folderId",
|
||||||
|
"columnName": "folder_id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
],
|
||||||
|
"autoGenerate": true
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": [
|
||||||
|
{
|
||||||
|
"table": "note_folders",
|
||||||
|
"onDelete": "CASCADE",
|
||||||
|
"onUpdate": "NO ACTION",
|
||||||
|
"columns": [
|
||||||
|
"folder_id"
|
||||||
|
],
|
||||||
|
"referencedColumns": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "tasks",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `description` TEXT NOT NULL, `is_completed` INTEGER NOT NULL, `priority` INTEGER NOT NULL, `created_date` INTEGER NOT NULL, `updated_date` INTEGER NOT NULL, `sub_tasks` TEXT NOT NULL, `dueDate` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "title",
|
||||||
|
"columnName": "title",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "description",
|
||||||
|
"columnName": "description",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isCompleted",
|
||||||
|
"columnName": "is_completed",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "priority",
|
||||||
|
"columnName": "priority",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "createdDate",
|
||||||
|
"columnName": "created_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "updatedDate",
|
||||||
|
"columnName": "updated_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "subTasks",
|
||||||
|
"columnName": "sub_tasks",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "dueDate",
|
||||||
|
"columnName": "dueDate",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
],
|
||||||
|
"autoGenerate": true
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "diary",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `content` TEXT NOT NULL, `created_date` INTEGER NOT NULL, `updated_date` INTEGER NOT NULL, `mood` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "title",
|
||||||
|
"columnName": "title",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "content",
|
||||||
|
"columnName": "content",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "createdDate",
|
||||||
|
"columnName": "created_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "updatedDate",
|
||||||
|
"columnName": "updated_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "mood",
|
||||||
|
"columnName": "mood",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
],
|
||||||
|
"autoGenerate": true
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "bookmarks",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`url` TEXT NOT NULL, `title` TEXT NOT NULL, `description` TEXT NOT NULL, `created_date` INTEGER NOT NULL, `updated_date` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "url",
|
||||||
|
"columnName": "url",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "title",
|
||||||
|
"columnName": "title",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "description",
|
||||||
|
"columnName": "description",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "createdDate",
|
||||||
|
"columnName": "created_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "updatedDate",
|
||||||
|
"columnName": "updated_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
],
|
||||||
|
"autoGenerate": true
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "alarms",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `time` INTEGER NOT NULL, PRIMARY KEY(`id`))",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "time",
|
||||||
|
"columnName": "time",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
],
|
||||||
|
"autoGenerate": false
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "note_folders",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "name",
|
||||||
|
"columnName": "name",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
],
|
||||||
|
"autoGenerate": true
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"views": [],
|
||||||
|
"setupQueries": [
|
||||||
|
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||||
|
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'fad6f140a4272bf79b901ad86cd27d66')"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,314 @@
|
||||||
|
{
|
||||||
|
"formatVersion": 1,
|
||||||
|
"database": {
|
||||||
|
"version": 3,
|
||||||
|
"identityHash": "4cddc67715bf274c83c6f671b9ec8e5c",
|
||||||
|
"entities": [
|
||||||
|
{
|
||||||
|
"tableName": "notes",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `content` TEXT NOT NULL, `created_date` INTEGER NOT NULL, `updated_date` INTEGER NOT NULL, `pinned` INTEGER NOT NULL, `folder_id` INTEGER, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, FOREIGN KEY(`folder_id`) REFERENCES `note_folders`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "title",
|
||||||
|
"columnName": "title",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "content",
|
||||||
|
"columnName": "content",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "createdDate",
|
||||||
|
"columnName": "created_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "updatedDate",
|
||||||
|
"columnName": "updated_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "pinned",
|
||||||
|
"columnName": "pinned",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "folderId",
|
||||||
|
"columnName": "folder_id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": [
|
||||||
|
{
|
||||||
|
"table": "note_folders",
|
||||||
|
"onDelete": "CASCADE",
|
||||||
|
"onUpdate": "NO ACTION",
|
||||||
|
"columns": [
|
||||||
|
"folder_id"
|
||||||
|
],
|
||||||
|
"referencedColumns": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "tasks",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `description` TEXT NOT NULL, `is_completed` INTEGER NOT NULL, `priority` INTEGER NOT NULL, `created_date` INTEGER NOT NULL, `updated_date` INTEGER NOT NULL, `sub_tasks` TEXT NOT NULL, `dueDate` INTEGER NOT NULL, `recurring` INTEGER NOT NULL, `frequency` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "title",
|
||||||
|
"columnName": "title",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "description",
|
||||||
|
"columnName": "description",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isCompleted",
|
||||||
|
"columnName": "is_completed",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "priority",
|
||||||
|
"columnName": "priority",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "createdDate",
|
||||||
|
"columnName": "created_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "updatedDate",
|
||||||
|
"columnName": "updated_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "subTasks",
|
||||||
|
"columnName": "sub_tasks",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "dueDate",
|
||||||
|
"columnName": "dueDate",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "recurring",
|
||||||
|
"columnName": "recurring",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "frequency",
|
||||||
|
"columnName": "frequency",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "diary",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `content` TEXT NOT NULL, `created_date` INTEGER NOT NULL, `updated_date` INTEGER NOT NULL, `mood` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "title",
|
||||||
|
"columnName": "title",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "content",
|
||||||
|
"columnName": "content",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "createdDate",
|
||||||
|
"columnName": "created_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "updatedDate",
|
||||||
|
"columnName": "updated_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "mood",
|
||||||
|
"columnName": "mood",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "bookmarks",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`url` TEXT NOT NULL, `title` TEXT NOT NULL, `description` TEXT NOT NULL, `created_date` INTEGER NOT NULL, `updated_date` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "url",
|
||||||
|
"columnName": "url",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "title",
|
||||||
|
"columnName": "title",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "description",
|
||||||
|
"columnName": "description",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "createdDate",
|
||||||
|
"columnName": "created_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "updatedDate",
|
||||||
|
"columnName": "updated_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "alarms",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `time` INTEGER NOT NULL, PRIMARY KEY(`id`))",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "time",
|
||||||
|
"columnName": "time",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": false,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "note_folders",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "name",
|
||||||
|
"columnName": "name",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"views": [],
|
||||||
|
"setupQueries": [
|
||||||
|
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||||
|
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '4cddc67715bf274c83c6f671b9ec8e5c')"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,320 @@
|
||||||
|
{
|
||||||
|
"formatVersion": 1,
|
||||||
|
"database": {
|
||||||
|
"version": 4,
|
||||||
|
"identityHash": "0bf1c1b48ba41e376dcea76097a3724c",
|
||||||
|
"entities": [
|
||||||
|
{
|
||||||
|
"tableName": "notes",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `content` TEXT NOT NULL, `created_date` INTEGER NOT NULL, `updated_date` INTEGER NOT NULL, `pinned` INTEGER NOT NULL, `folder_id` INTEGER, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, FOREIGN KEY(`folder_id`) REFERENCES `note_folders`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "title",
|
||||||
|
"columnName": "title",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "content",
|
||||||
|
"columnName": "content",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "createdDate",
|
||||||
|
"columnName": "created_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "updatedDate",
|
||||||
|
"columnName": "updated_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "pinned",
|
||||||
|
"columnName": "pinned",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "folderId",
|
||||||
|
"columnName": "folder_id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": [
|
||||||
|
{
|
||||||
|
"table": "note_folders",
|
||||||
|
"onDelete": "CASCADE",
|
||||||
|
"onUpdate": "NO ACTION",
|
||||||
|
"columns": [
|
||||||
|
"folder_id"
|
||||||
|
],
|
||||||
|
"referencedColumns": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "tasks",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `description` TEXT NOT NULL, `is_completed` INTEGER NOT NULL, `priority` INTEGER NOT NULL, `created_date` INTEGER NOT NULL, `updated_date` INTEGER NOT NULL, `sub_tasks` TEXT NOT NULL, `dueDate` INTEGER NOT NULL, `recurring` INTEGER NOT NULL, `frequency` INTEGER NOT NULL, `frequency_amount` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "title",
|
||||||
|
"columnName": "title",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "description",
|
||||||
|
"columnName": "description",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isCompleted",
|
||||||
|
"columnName": "is_completed",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "priority",
|
||||||
|
"columnName": "priority",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "createdDate",
|
||||||
|
"columnName": "created_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "updatedDate",
|
||||||
|
"columnName": "updated_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "subTasks",
|
||||||
|
"columnName": "sub_tasks",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "dueDate",
|
||||||
|
"columnName": "dueDate",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "recurring",
|
||||||
|
"columnName": "recurring",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "frequency",
|
||||||
|
"columnName": "frequency",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "frequencyAmount",
|
||||||
|
"columnName": "frequency_amount",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "diary",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `content` TEXT NOT NULL, `created_date` INTEGER NOT NULL, `updated_date` INTEGER NOT NULL, `mood` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "title",
|
||||||
|
"columnName": "title",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "content",
|
||||||
|
"columnName": "content",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "createdDate",
|
||||||
|
"columnName": "created_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "updatedDate",
|
||||||
|
"columnName": "updated_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "mood",
|
||||||
|
"columnName": "mood",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "bookmarks",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`url` TEXT NOT NULL, `title` TEXT NOT NULL, `description` TEXT NOT NULL, `created_date` INTEGER NOT NULL, `updated_date` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "url",
|
||||||
|
"columnName": "url",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "title",
|
||||||
|
"columnName": "title",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "description",
|
||||||
|
"columnName": "description",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "createdDate",
|
||||||
|
"columnName": "created_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "updatedDate",
|
||||||
|
"columnName": "updated_date",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "alarms",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `time` INTEGER NOT NULL, PRIMARY KEY(`id`))",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "time",
|
||||||
|
"columnName": "time",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": false,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "note_folders",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "name",
|
||||||
|
"columnName": "name",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"indices": [],
|
||||||
|
"foreignKeys": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"views": [],
|
||||||
|
"setupQueries": [
|
||||||
|
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||||
|
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '0bf1c1b48ba41e376dcea76097a3724c')"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.mhss.app.mybrain
|
||||||
|
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
|
||||||
|
import org.junit.Assert.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instrumented test, which will execute on an Android device.
|
||||||
|
*
|
||||||
|
* See [testing documentation](http://d.android.com/tools/testing).
|
||||||
|
*/
|
||||||
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
class ExampleInstrumentedTest {
|
||||||
|
@Test
|
||||||
|
fun useAppContext() {
|
||||||
|
// Context of the app under test.
|
||||||
|
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||||
|
assertEquals("com.mhss.app.mybrain", appContext.packageName)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,146 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
|
<!-- For the Calendar events features -->
|
||||||
|
<uses-permission android:name="android.permission.READ_CALENDAR" />
|
||||||
|
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
|
||||||
|
<!-- For reminders -->
|
||||||
|
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" /> <!-- to start the alarms after restart. (By default, all alarms are canceled when a device shuts down) -->
|
||||||
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
|
||||||
|
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:name=".app.MyBrainApplication"
|
||||||
|
android:allowBackup="true"
|
||||||
|
android:icon="@mipmap/ic_launcher"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
|
android:supportsRtl="true"
|
||||||
|
android:theme="@style/Theme.MyBrain"
|
||||||
|
tools:targetApi="33">
|
||||||
|
<activity
|
||||||
|
android:name=".presentation.main.MainActivity"
|
||||||
|
android:exported="true"
|
||||||
|
android:theme="@style/Theme.MyBrain"
|
||||||
|
android:windowSoftInputMode="adjustResize">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
<receiver
|
||||||
|
android:name=".util.alarms.BootBroadcastReceiver"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
<receiver
|
||||||
|
android:name=".util.alarms.AlarmReceiver"
|
||||||
|
android:enabled="true" />
|
||||||
|
<receiver
|
||||||
|
android:name=".util.alarms.TaskActionButtonBroadcastReceiver"
|
||||||
|
android:enabled="true" />
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".presentation.bookmarks.SaveBookmarkActivity"
|
||||||
|
android:autoRemoveFromRecents="true"
|
||||||
|
android:excludeFromRecents="true"
|
||||||
|
android:exported="true"
|
||||||
|
android:noHistory="true"
|
||||||
|
android:theme="@android:style/Theme.NoDisplay">
|
||||||
|
<intent-filter android:label="@string/save_bookmark">
|
||||||
|
<action android:name="android.intent.action.SEND" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
|
||||||
|
<data android:mimeType="text/plain" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
<activity
|
||||||
|
android:name=".domain.use_case.tasks.AddTaskFromShareActivity"
|
||||||
|
android:autoRemoveFromRecents="true"
|
||||||
|
android:excludeFromRecents="true"
|
||||||
|
android:exported="true"
|
||||||
|
android:noHistory="true"
|
||||||
|
android:theme="@android:style/Theme.NoDisplay">
|
||||||
|
<intent-filter android:label="@string/add_to_tasks">
|
||||||
|
<action android:name="android.intent.action.SEND" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
|
||||||
|
<data android:mimeType="text/plain" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
<!-- The Add task tile in the quick settings -->
|
||||||
|
<service
|
||||||
|
android:name=".presentation.tasks.AddTaskTileService"
|
||||||
|
android:exported="true"
|
||||||
|
android:icon="@drawable/ic_check"
|
||||||
|
android:label="@string/add_task_to_my_brain"
|
||||||
|
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.service.quicksettings.action.QS_TILE" />
|
||||||
|
</intent-filter>
|
||||||
|
</service>
|
||||||
|
|
||||||
|
<!-- Calendar widget-->
|
||||||
|
<receiver
|
||||||
|
android:name=".presentation.glance_widgets.CalendarWidgetReceiver"
|
||||||
|
android:enabled="@bool/glance_appwidget_available"
|
||||||
|
android:exported="true"
|
||||||
|
android:label="@string/calendar">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||||
|
</intent-filter>
|
||||||
|
<meta-data
|
||||||
|
android:name="android.appwidget.provider"
|
||||||
|
android:resource="@xml/calendar_widget_info" />
|
||||||
|
</receiver>
|
||||||
|
|
||||||
|
<!-- For updating the events in the calendar widget when there are changes-->
|
||||||
|
<receiver
|
||||||
|
android:name=".presentation.glance_widgets.RefreshCalendarWidgetReceiver"
|
||||||
|
android:enabled="@bool/glance_appwidget_available"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.PROVIDER_CHANGED" />
|
||||||
|
<data android:scheme="content" />
|
||||||
|
<data android:host="com.android.calendar" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
|
<!-- Tasks widget-->
|
||||||
|
<receiver
|
||||||
|
android:name=".presentation.glance_widgets.TasksWidgetReceiver"
|
||||||
|
android:enabled="@bool/glance_appwidget_available"
|
||||||
|
android:exported="false"
|
||||||
|
android:label="@string/tasks">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||||
|
</intent-filter>
|
||||||
|
<meta-data
|
||||||
|
android:name="android.appwidget.provider"
|
||||||
|
android:resource="@xml/tasks_widget_info" />
|
||||||
|
</receiver>
|
||||||
|
|
||||||
|
<receiver
|
||||||
|
android:name=".presentation.glance_widgets.CompleteTaskWidgetReceiver"
|
||||||
|
android:enabled="@bool/glance_appwidget_available"
|
||||||
|
android:exported="false" />
|
||||||
|
|
||||||
|
<provider
|
||||||
|
android:name="androidx.startup.InitializationProvider"
|
||||||
|
android:authorities="${applicationId}.androidx-startup"
|
||||||
|
tools:node="remove" />
|
||||||
|
|
||||||
|
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</manifest>
|
|
@ -0,0 +1,59 @@
|
||||||
|
package com.mhss.app.mybrain.app
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import android.app.NotificationChannel
|
||||||
|
import android.app.NotificationManager
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
import androidx.datastore.core.DataStore
|
||||||
|
import androidx.datastore.preferences.core.Preferences
|
||||||
|
import androidx.datastore.preferences.preferencesDataStore
|
||||||
|
import androidx.hilt.work.HiltWorkerFactory
|
||||||
|
import androidx.work.Configuration
|
||||||
|
import com.mhss.app.mybrain.R
|
||||||
|
import com.mhss.app.mybrain.util.Constants
|
||||||
|
import dagger.hilt.android.HiltAndroidApp
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = Constants.SETTINGS_PREFERENCES)
|
||||||
|
|
||||||
|
@HiltAndroidApp
|
||||||
|
class MyBrainApplication : Application(), Configuration.Provider {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
lateinit var appContext: Context
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var workerFactory: HiltWorkerFactory
|
||||||
|
|
||||||
|
override fun getWorkManagerConfiguration() =
|
||||||
|
Configuration.Builder()
|
||||||
|
.setWorkerFactory(workerFactory)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
override fun onCreate() {
|
||||||
|
super.onCreate()
|
||||||
|
appContext = this
|
||||||
|
createRemindersNotificationChannel()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createRemindersNotificationChannel() {
|
||||||
|
val channel = NotificationChannel(
|
||||||
|
Constants.REMINDERS_CHANNEL_ID,
|
||||||
|
getString(R.string.reminders_channel_name),
|
||||||
|
NotificationManager.IMPORTANCE_DEFAULT
|
||||||
|
)
|
||||||
|
channel.description = getString(R.string.reminders_channel_description)
|
||||||
|
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||||
|
notificationManager.createNotificationChannel(channel)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// for string resources where context is not available
|
||||||
|
fun getString(
|
||||||
|
@StringRes
|
||||||
|
resId: Int,
|
||||||
|
vararg args: String
|
||||||
|
) = MyBrainApplication.appContext.getString(resId, *args)
|
|
@ -0,0 +1,64 @@
|
||||||
|
package com.mhss.app.mybrain.data.backup
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.net.Uri
|
||||||
|
import androidx.documentfile.provider.DocumentFile
|
||||||
|
import com.mhss.app.mybrain.data.local.MyBrainDatabase
|
||||||
|
import com.mhss.app.mybrain.domain.repository.RoomBackupRepository
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import java.io.File
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class RoomBackupRepositoryImpl @Inject constructor(
|
||||||
|
private val database: MyBrainDatabase,
|
||||||
|
private val context: Context,
|
||||||
|
) : RoomBackupRepository {
|
||||||
|
|
||||||
|
private val dbPath = File(context.getDatabasePath(database.openHelper.databaseName).toURI())
|
||||||
|
|
||||||
|
override suspend fun exportDatabase(
|
||||||
|
directoryUri: Uri,
|
||||||
|
encrypted: Boolean, // To be added in a future version
|
||||||
|
password: String // To be added in a future version
|
||||||
|
): Boolean {
|
||||||
|
return withContext(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
|
val fileName = "MyBrain_Backup_${System.currentTimeMillis()}.sqlite3"
|
||||||
|
val pickedDir = DocumentFile.fromTreeUri(context, directoryUri)
|
||||||
|
val destination = pickedDir!!.createFile("application/sqlite3", fileName)
|
||||||
|
|
||||||
|
|
||||||
|
val outputStream =
|
||||||
|
destination?.let { context.contentResolver.openOutputStream(it.uri) }
|
||||||
|
?: return@withContext false
|
||||||
|
|
||||||
|
dbPath.inputStream().copyTo(outputStream)
|
||||||
|
|
||||||
|
true
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun importDatabase(
|
||||||
|
fileUri: Uri,
|
||||||
|
encrypted: Boolean, // To be added in a future version
|
||||||
|
password: String // To be added in a future version
|
||||||
|
): Boolean {
|
||||||
|
return withContext(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
|
database.close()
|
||||||
|
context.contentResolver.openInputStream(fileUri)?.use {
|
||||||
|
it.copyTo(dbPath.outputStream())
|
||||||
|
} ?: return@withContext false
|
||||||
|
true
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.mhss.app.mybrain.data.local
|
||||||
|
|
||||||
|
import androidx.room.Database
|
||||||
|
import androidx.room.RoomDatabase
|
||||||
|
import androidx.room.TypeConverters
|
||||||
|
import com.mhss.app.mybrain.data.local.converters.DBConverters
|
||||||
|
import com.mhss.app.mybrain.data.local.dao.*
|
||||||
|
import com.mhss.app.mybrain.domain.model.*
|
||||||
|
|
||||||
|
@Database(
|
||||||
|
entities = [Note::class, Task::class, DiaryEntry::class, Bookmark::class, Alarm::class, NoteFolder::class],
|
||||||
|
version = 4
|
||||||
|
)
|
||||||
|
@TypeConverters(DBConverters::class)
|
||||||
|
abstract class MyBrainDatabase: RoomDatabase() {
|
||||||
|
|
||||||
|
abstract fun noteDao(): NoteDao
|
||||||
|
abstract fun taskDao(): TaskDao
|
||||||
|
abstract fun diaryDao(): DiaryDao
|
||||||
|
abstract fun bookmarkDao(): BookmarkDao
|
||||||
|
abstract fun alarmDao(): AlarmDao
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val DATABASE_NAME = "by_brain_db"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.mhss.app.mybrain.data.local.converters
|
||||||
|
|
||||||
|
import androidx.room.TypeConverter
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import com.google.gson.reflect.TypeToken
|
||||||
|
import com.mhss.app.mybrain.domain.model.SubTask
|
||||||
|
import com.mhss.app.mybrain.util.diary.Mood
|
||||||
|
|
||||||
|
class DBConverters {
|
||||||
|
|
||||||
|
@TypeConverter
|
||||||
|
fun fromSubTasksList(value: List<SubTask>): String {
|
||||||
|
val gson = Gson()
|
||||||
|
val type = TypeToken.getParameterized(List::class.java, SubTask::class.java).type
|
||||||
|
return gson.toJson(value, type)
|
||||||
|
}
|
||||||
|
|
||||||
|
@TypeConverter
|
||||||
|
fun toSubTasksList(value: String): List<SubTask> {
|
||||||
|
val gson = Gson()
|
||||||
|
val type = TypeToken.getParameterized(List::class.java, SubTask::class.java).type
|
||||||
|
return gson.fromJson(value, type)
|
||||||
|
}
|
||||||
|
|
||||||
|
@TypeConverter
|
||||||
|
fun toMood(value: Int) = enumValues<Mood>()[value]
|
||||||
|
|
||||||
|
@TypeConverter
|
||||||
|
fun fromMood(value: Mood) = value.ordinal
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.mhss.app.mybrain.data.local.dao
|
||||||
|
|
||||||
|
import androidx.room.*
|
||||||
|
import com.mhss.app.mybrain.domain.model.Alarm
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface AlarmDao {
|
||||||
|
|
||||||
|
@Query("SELECT * FROM alarms")
|
||||||
|
suspend fun getAll(): List<Alarm>
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
suspend fun insert(alarm: Alarm)
|
||||||
|
|
||||||
|
@Delete
|
||||||
|
suspend fun delete(alarm: Alarm)
|
||||||
|
|
||||||
|
@Query("DELETE FROM alarms WHERE id = :id")
|
||||||
|
suspend fun delete(id: Int)
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.mhss.app.mybrain.data.local.dao
|
||||||
|
|
||||||
|
import androidx.room.*
|
||||||
|
import com.mhss.app.mybrain.domain.model.Bookmark
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface BookmarkDao {
|
||||||
|
|
||||||
|
@Query("SELECT * FROM bookmarks")
|
||||||
|
fun getAllBookmarks(): Flow<List<Bookmark>>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM bookmarks WHERE id = :id")
|
||||||
|
suspend fun getBookmark(id: Int): Bookmark
|
||||||
|
|
||||||
|
@Query("SELECT * FROM bookmarks WHERE title LIKE '%' || :query || '%' OR description LIKE '%' || :query || '%' OR url LIKE '%' || :query || '%'")
|
||||||
|
suspend fun getBookmark(query: String): List<Bookmark>
|
||||||
|
|
||||||
|
@Insert
|
||||||
|
suspend fun insertBookmark(bookmark: Bookmark)
|
||||||
|
|
||||||
|
@Update
|
||||||
|
suspend fun updateBookmark(bookmark: Bookmark)
|
||||||
|
|
||||||
|
@Delete
|
||||||
|
suspend fun deleteBookmark(bookmark: Bookmark)
|
||||||
|
|
||||||
|
@Insert
|
||||||
|
suspend fun insertBookmarks(bookmarks: List<Bookmark>)
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.mhss.app.mybrain.data.local.dao
|
||||||
|
|
||||||
|
import androidx.room.*
|
||||||
|
import com.mhss.app.mybrain.domain.model.DiaryEntry
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface DiaryDao {
|
||||||
|
|
||||||
|
@Query("SELECT * FROM diary")
|
||||||
|
fun getAllEntries(): Flow<List<DiaryEntry>>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM diary WHERE id = :id")
|
||||||
|
suspend fun getEntry(id: Int): DiaryEntry
|
||||||
|
|
||||||
|
@Query("SELECT * FROM diary WHERE title LIKE '%' || :query || '%' OR content LIKE '%' || :query || '%'")
|
||||||
|
suspend fun getEntriesByTitle(query: String): List<DiaryEntry>
|
||||||
|
|
||||||
|
@Insert
|
||||||
|
suspend fun insertEntry(diary: DiaryEntry)
|
||||||
|
|
||||||
|
@Insert
|
||||||
|
suspend fun insertEntries(diary: List<DiaryEntry>)
|
||||||
|
|
||||||
|
@Update
|
||||||
|
suspend fun updateEntry(diary: DiaryEntry)
|
||||||
|
|
||||||
|
@Delete
|
||||||
|
suspend fun deleteEntry(diary: DiaryEntry)
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.mhss.app.mybrain.data.local.dao
|
||||||
|
|
||||||
|
import androidx.room.*
|
||||||
|
import com.mhss.app.mybrain.domain.model.Note
|
||||||
|
import com.mhss.app.mybrain.domain.model.NoteFolder
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface NoteDao {
|
||||||
|
|
||||||
|
@Query("SELECT * FROM notes")
|
||||||
|
fun getAllNotes(): Flow<List<Note>>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM notes WHERE id = :id")
|
||||||
|
suspend fun getNote(id: Int): Note
|
||||||
|
|
||||||
|
@Query("SELECT * FROM notes WHERE title LIKE '%' || :query || '%' OR content LIKE '%' || :query || '%'")
|
||||||
|
suspend fun getNotesByTitle(query: String): List<Note>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM notes WHERE folder_id = :folderId")
|
||||||
|
fun getNotesByFolder(folderId: Int): Flow<List<Note>>
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
suspend fun insertNote(note: Note)
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
|
suspend fun insertNotes(notes: List<Note>)
|
||||||
|
|
||||||
|
@Update
|
||||||
|
suspend fun updateNote(note: Note)
|
||||||
|
|
||||||
|
@Delete
|
||||||
|
suspend fun deleteNote(note: Note)
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
|
suspend fun insertNoteFolder(folder: NoteFolder)
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
|
suspend fun insertNoteFolders(folders: List<NoteFolder>)
|
||||||
|
|
||||||
|
@Update
|
||||||
|
suspend fun updateNoteFolder(folder: NoteFolder)
|
||||||
|
|
||||||
|
@Delete
|
||||||
|
suspend fun deleteNoteFolder(folder: NoteFolder)
|
||||||
|
|
||||||
|
@Query("SELECT * FROM note_folders")
|
||||||
|
fun getAllNoteFolders(): Flow<List<NoteFolder>>
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.mhss.app.mybrain.data.local.dao
|
||||||
|
|
||||||
|
import androidx.room.*
|
||||||
|
import com.mhss.app.mybrain.domain.model.Task
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface TaskDao {
|
||||||
|
|
||||||
|
@Query("SELECT * FROM tasks")
|
||||||
|
fun getAllTasks(): Flow<List<Task>>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM tasks WHERE id = :id")
|
||||||
|
suspend fun getTask(id: Int): Task
|
||||||
|
|
||||||
|
@Query("SELECT * FROM tasks WHERE title LIKE '%' || :title || '%'")
|
||||||
|
fun getTasksByTitle(title: String): Flow<List<Task>>
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
suspend fun insertTask(task: Task): Long
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
|
suspend fun insertTasks(tasks: List<Task>)
|
||||||
|
|
||||||
|
@Update
|
||||||
|
suspend fun updateTask(task: Task)
|
||||||
|
|
||||||
|
@Delete
|
||||||
|
suspend fun deleteTask(task: Task)
|
||||||
|
|
||||||
|
@Query("UPDATE tasks SET is_completed = :completed WHERE id = :id")
|
||||||
|
suspend fun updateCompleted(id: Int, completed: Boolean)
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.mhss.app.mybrain.data.local.migrations
|
||||||
|
|
||||||
|
import androidx.room.migration.Migration
|
||||||
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
|
|
||||||
|
// Added note folders
|
||||||
|
val MIGRATION_1_2 = object : Migration(1, 2) {
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
database.execSQL("CREATE TABLE note_folders (name TEXT NOT NULL, id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)")
|
||||||
|
|
||||||
|
database.execSQL("CREATE TABLE IF NOT EXISTS `notes_new` (`title` TEXT NOT NULL, `content` TEXT NOT NULL, `created_date` INTEGER NOT NULL, `updated_date` INTEGER NOT NULL, `pinned` INTEGER NOT NULL, `folder_id` INTEGER, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, FOREIGN KEY (folder_id) REFERENCES note_folders (id) ON UPDATE NO ACTION ON DELETE CASCADE)")
|
||||||
|
database.execSQL("INSERT INTO notes_new (title, content, created_date, updated_date, pinned, id) SELECT title, content, created_date, updated_date, pinned, id FROM notes")
|
||||||
|
database.execSQL("DROP TABLE notes")
|
||||||
|
database.execSQL("ALTER TABLE notes_new RENAME TO notes")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val MIGRATION_2_3 = object : Migration(2, 3) {
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
database.execSQL("ALTER TABLE tasks ADD COLUMN recurring INTEGER NOT NULL DEFAULT 0")
|
||||||
|
database.execSQL("ALTER TABLE tasks ADD COLUMN frequency INTEGER NOT NULL DEFAULT 0")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val MIGRATION_3_4 = object : Migration(3, 4) {
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
database.execSQL("ALTER TABLE tasks ADD COLUMN frequency_amount INTEGER NOT NULL DEFAULT 1")
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.mhss.app.mybrain.data.repository
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.data.local.dao.AlarmDao
|
||||||
|
import com.mhss.app.mybrain.domain.model.Alarm
|
||||||
|
import com.mhss.app.mybrain.domain.repository.AlarmRepository
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class AlarmRepositoryImpl @Inject constructor(
|
||||||
|
private val alarmDao: AlarmDao,
|
||||||
|
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
|
||||||
|
) : AlarmRepository {
|
||||||
|
|
||||||
|
override suspend fun getAlarms(): List<Alarm> {
|
||||||
|
return withContext(ioDispatcher) {
|
||||||
|
alarmDao.getAll()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun insertAlarm(alarm: Alarm) {
|
||||||
|
withContext(ioDispatcher) {
|
||||||
|
alarmDao.insert(alarm)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun deleteAlarm(alarm: Alarm) {
|
||||||
|
withContext(ioDispatcher) {
|
||||||
|
alarmDao.delete(alarm)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun deleteAlarm(id: Int) {
|
||||||
|
withContext(ioDispatcher) {
|
||||||
|
alarmDao.delete(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.mhss.app.mybrain.data.repository
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.data.local.dao.BookmarkDao
|
||||||
|
import com.mhss.app.mybrain.domain.model.Bookmark
|
||||||
|
import com.mhss.app.mybrain.domain.repository.BookmarkRepository
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
|
class BookmarkRepositoryImpl(
|
||||||
|
private val bookmarkDao: BookmarkDao,
|
||||||
|
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
|
||||||
|
) : BookmarkRepository {
|
||||||
|
|
||||||
|
override fun getAllBookmarks(): Flow<List<Bookmark>> {
|
||||||
|
return bookmarkDao.getAllBookmarks()
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getBookmark(id: Int): Bookmark {
|
||||||
|
return withContext(ioDispatcher) {
|
||||||
|
bookmarkDao.getBookmark(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun searchBookmarks(query: String): List<Bookmark> {
|
||||||
|
return withContext(ioDispatcher) {
|
||||||
|
bookmarkDao.getBookmark(query)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun addBookmark(bookmark: Bookmark) {
|
||||||
|
withContext(ioDispatcher) {
|
||||||
|
bookmarkDao.insertBookmark(bookmark)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun deleteBookmark(bookmark: Bookmark) {
|
||||||
|
withContext(ioDispatcher) {
|
||||||
|
bookmarkDao.deleteBookmark(bookmark)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun updateBookmark(bookmark: Bookmark) {
|
||||||
|
withContext(ioDispatcher) {
|
||||||
|
bookmarkDao.updateBookmark(bookmark)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,285 @@
|
||||||
|
package com.mhss.app.mybrain.data.repository
|
||||||
|
|
||||||
|
import android.content.ContentUris
|
||||||
|
import android.content.ContentValues
|
||||||
|
import android.content.Context
|
||||||
|
import android.database.Cursor
|
||||||
|
import android.net.Uri
|
||||||
|
import android.provider.CalendarContract
|
||||||
|
import com.mhss.app.mybrain.R
|
||||||
|
import com.mhss.app.mybrain.domain.model.Calendar
|
||||||
|
import com.mhss.app.mybrain.domain.model.CalendarEvent
|
||||||
|
import com.mhss.app.mybrain.domain.repository.CalendarRepository
|
||||||
|
import com.mhss.app.mybrain.util.calendar.*
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class CalendarRepositoryImpl(private val context: Context) : CalendarRepository {
|
||||||
|
|
||||||
|
override suspend fun getEvents(): List<CalendarEvent> {
|
||||||
|
return withContext(Dispatchers.IO) {
|
||||||
|
val projection: Array<String> = arrayOf(
|
||||||
|
CalendarContract.Events._ID,
|
||||||
|
CalendarContract.Events.TITLE,
|
||||||
|
CalendarContract.Events.DESCRIPTION,
|
||||||
|
CalendarContract.Events.DTSTART,
|
||||||
|
CalendarContract.Events.DTEND,
|
||||||
|
CalendarContract.Events.EVENT_LOCATION,
|
||||||
|
CalendarContract.Events.ALL_DAY,
|
||||||
|
CalendarContract.Events.EVENT_COLOR,
|
||||||
|
CalendarContract.Events.CALENDAR_ID,
|
||||||
|
CalendarContract.Events.RRULE,
|
||||||
|
CalendarContract.Events.DURATION,
|
||||||
|
CalendarContract.Events.CALENDAR_COLOR
|
||||||
|
)
|
||||||
|
val instancesProjection = arrayOf(
|
||||||
|
CalendarContract.Instances.EVENT_ID,
|
||||||
|
CalendarContract.Instances.TITLE,
|
||||||
|
CalendarContract.Instances.DESCRIPTION,
|
||||||
|
CalendarContract.Instances.BEGIN,
|
||||||
|
CalendarContract.Instances.END,
|
||||||
|
CalendarContract.Instances.EVENT_LOCATION,
|
||||||
|
CalendarContract.Instances.ALL_DAY,
|
||||||
|
CalendarContract.Instances.EVENT_COLOR,
|
||||||
|
CalendarContract.Instances.CALENDAR_ID,
|
||||||
|
CalendarContract.Instances.RRULE,
|
||||||
|
CalendarContract.Instances.DURATION,
|
||||||
|
CalendarContract.Instances.CALENDAR_COLOR
|
||||||
|
)
|
||||||
|
val contentResolver = context.contentResolver
|
||||||
|
val events = mutableListOf<CalendarEvent>()
|
||||||
|
|
||||||
|
val uri: Uri = CalendarContract.Events.CONTENT_URI
|
||||||
|
val cur: Cursor? = contentResolver.query(
|
||||||
|
uri,
|
||||||
|
projection,
|
||||||
|
"${CalendarContract.Events.DTSTART} > ? AND ${CalendarContract.Events.DELETED} = 0",
|
||||||
|
// events today or in the future only
|
||||||
|
arrayOf(System.currentTimeMillis().toString()),
|
||||||
|
null
|
||||||
|
)
|
||||||
|
|
||||||
|
if (cur != null) {
|
||||||
|
while (cur.moveToNext()) {
|
||||||
|
val eventId: Long = cur.getLong(ID_INDEX)
|
||||||
|
val title: String = cur.getString(TITLE_INDEX) ?: continue
|
||||||
|
val description: String? = cur.getString(DESC_INDEX)
|
||||||
|
val start: Long = cur.getLong(START_INDEX)
|
||||||
|
val duration: String = cur.getString(EVENT_DURATION_INDEX) ?: ""
|
||||||
|
val end: Long = if (duration.isNotBlank()) duration.extractEndFromDuration(start) else cur.getLong(END_INDEX)
|
||||||
|
val location: String? = cur.getString(LOCATION_INDEX)
|
||||||
|
val allDay: Boolean = cur.getInt(ALL_DAY_INDEX) == 1
|
||||||
|
val color: Int = cur.getInt(COlOR_INDEX)
|
||||||
|
val calendarColor: Int = cur.getInt(CALENDAR_COLOR_INDEX)
|
||||||
|
val calendarId: Long = cur.getLong(EVENT_CALENDAR_ID_INDEX)
|
||||||
|
val rrule: String = cur.getString(EVENT_RRULE_INDEX) ?: ""
|
||||||
|
val recurring: Boolean = rrule.isNotBlank()
|
||||||
|
// val frequency: String = rrule.extractFrequency()
|
||||||
|
|
||||||
|
if (!recurring)
|
||||||
|
events.add(CalendarEvent(
|
||||||
|
id = eventId ,
|
||||||
|
title = title,
|
||||||
|
description = description,
|
||||||
|
start = start,
|
||||||
|
end = end,
|
||||||
|
location = location,
|
||||||
|
allDay = allDay,
|
||||||
|
color = if (color != 0) color else calendarColor,
|
||||||
|
calendarId = calendarId,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
cur.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// get recurring events
|
||||||
|
val startM = java.util.Calendar.getInstance().timeInMillis
|
||||||
|
val endM = startM + 6 * 30 * 24 * 60 * 60 * 1000L
|
||||||
|
val builder = CalendarContract.Instances.CONTENT_URI.buildUpon()
|
||||||
|
ContentUris.appendId(builder, startM)
|
||||||
|
ContentUris.appendId(builder, endM)
|
||||||
|
val curI = contentResolver.query(
|
||||||
|
builder.build(),
|
||||||
|
instancesProjection,
|
||||||
|
null, null, null
|
||||||
|
)
|
||||||
|
if (curI != null){
|
||||||
|
while (curI.moveToNext()){
|
||||||
|
val eventId: Long = curI.getLong(ID_INDEX)
|
||||||
|
val title: String = curI.getString(TITLE_INDEX) ?: continue
|
||||||
|
val description: String? = curI.getString(DESC_INDEX)
|
||||||
|
val start: Long = curI.getLong(START_INDEX)
|
||||||
|
val duration: String = curI.getString(EVENT_DURATION_INDEX) ?: ""
|
||||||
|
val end: Long = if (duration.isNotBlank()) duration.extractEndFromDuration(start) else curI.getLong(END_INDEX)
|
||||||
|
val location: String? = curI.getString(LOCATION_INDEX)
|
||||||
|
val allDay: Boolean = curI.getInt(ALL_DAY_INDEX) == 1
|
||||||
|
val color: Int = curI.getInt(COlOR_INDEX)
|
||||||
|
val calendarColor: Int = curI.getInt(CALENDAR_COLOR_INDEX)
|
||||||
|
val calendarId: Long = curI.getLong(EVENT_CALENDAR_ID_INDEX)
|
||||||
|
val rrule: String = curI.getString(EVENT_RRULE_INDEX) ?: ""
|
||||||
|
val recurring: Boolean = rrule.isNotBlank()
|
||||||
|
val frequency: String = rrule.extractFrequency()
|
||||||
|
if (recurring) events.add(CalendarEvent(
|
||||||
|
id = eventId,
|
||||||
|
title = title,
|
||||||
|
description = description,
|
||||||
|
start = start,
|
||||||
|
end = end,
|
||||||
|
location = location,
|
||||||
|
allDay = allDay,
|
||||||
|
color = if (color != 0) color else calendarColor,
|
||||||
|
calendarId = calendarId,
|
||||||
|
frequency = frequency,
|
||||||
|
recurring = true,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
curI.close()
|
||||||
|
}
|
||||||
|
events.sortedBy { it.start }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getCalendars() : List<Calendar>{
|
||||||
|
return withContext(Dispatchers.IO){
|
||||||
|
val projection = arrayOf(
|
||||||
|
CalendarContract.Calendars._ID, // 0
|
||||||
|
CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, // 1
|
||||||
|
CalendarContract.Calendars.ACCOUNT_NAME, // 2
|
||||||
|
CalendarContract.Calendars.ACCOUNT_TYPE, // 3
|
||||||
|
CalendarContract.Calendars.CALENDAR_COLOR// 4
|
||||||
|
|
||||||
|
)
|
||||||
|
val uri = CalendarContract.Calendars.CONTENT_URI
|
||||||
|
val contentResolver = context.contentResolver
|
||||||
|
val cur = contentResolver.query(
|
||||||
|
uri,
|
||||||
|
projection,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
)
|
||||||
|
val calendars: MutableList<Calendar> = mutableListOf()
|
||||||
|
if (cur != null) {
|
||||||
|
while (cur.moveToNext()) {
|
||||||
|
|
||||||
|
val calID: Long = cur.getLong(CALENDAR_ID_INDEX)
|
||||||
|
val calendarName: String = cur.getString(CALENDAR_NAME_INDEX)
|
||||||
|
val accountName: String = cur.getString(ACCOUNT_NAME_INDEX)
|
||||||
|
val color: Int = cur.getInt(CALENDAR_CALENDAR_COLOR_INDEX)
|
||||||
|
|
||||||
|
calendars.add(
|
||||||
|
Calendar(
|
||||||
|
calID,
|
||||||
|
calendarName,
|
||||||
|
accountName,
|
||||||
|
color
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
cur.close()
|
||||||
|
calendars
|
||||||
|
}else
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun addEvent(event: CalendarEvent) {
|
||||||
|
withContext(Dispatchers.IO){
|
||||||
|
val values = ContentValues().apply {
|
||||||
|
put(CalendarContract.Events.CALENDAR_ID, event.calendarId)
|
||||||
|
put(CalendarContract.Events.TITLE, event.title)
|
||||||
|
put(CalendarContract.Events.DESCRIPTION, event.description)
|
||||||
|
put(CalendarContract.Events.DTSTART, event.start)
|
||||||
|
put(CalendarContract.Events.ALL_DAY, event.allDay)
|
||||||
|
put(CalendarContract.Events.EVENT_LOCATION, event.location)
|
||||||
|
if (event.recurring){
|
||||||
|
put(CalendarContract.Events.RRULE, event.getEventRRule())
|
||||||
|
put(CalendarContract.Events.DURATION, event.getEventDuration())
|
||||||
|
} else {
|
||||||
|
put(CalendarContract.Events.DTEND, event.end)
|
||||||
|
}
|
||||||
|
put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().id)
|
||||||
|
}
|
||||||
|
context.contentResolver.insert(CalendarContract.Events.CONTENT_URI, values)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun updateEvent(event: CalendarEvent) {
|
||||||
|
withContext(Dispatchers.IO){
|
||||||
|
val values = ContentValues().apply {
|
||||||
|
put(CalendarContract.Events.CALENDAR_ID, event.calendarId)
|
||||||
|
put(CalendarContract.Events.TITLE, event.title)
|
||||||
|
put(CalendarContract.Events.DESCRIPTION, event.description)
|
||||||
|
put(CalendarContract.Events.DTSTART, event.start)
|
||||||
|
if (event.recurring && event.frequency.isNotBlank()){
|
||||||
|
val end: Long? = null
|
||||||
|
put(CalendarContract.Events.RRULE, event.getEventRRule())
|
||||||
|
put(CalendarContract.Events.DURATION, event.getEventDuration())
|
||||||
|
put(CalendarContract.Events.DTEND, end)
|
||||||
|
}else {
|
||||||
|
val rule: String? = null
|
||||||
|
put(CalendarContract.Events.RRULE, rule)
|
||||||
|
put(CalendarContract.Events.DURATION, rule)
|
||||||
|
put(CalendarContract.Events.DTEND, event.end)
|
||||||
|
}
|
||||||
|
put(CalendarContract.Events.ALL_DAY, event.allDay)
|
||||||
|
put(CalendarContract.Events.EVENT_LOCATION, event.location)
|
||||||
|
}
|
||||||
|
val updateUri: Uri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, event.id)
|
||||||
|
context.contentResolver.update(updateUri, values, null, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun createCalendar() {
|
||||||
|
withContext(Dispatchers.IO){
|
||||||
|
val uri = CalendarContract.Calendars.CONTENT_URI.asSyncAdapter(context.getString(R.string.app_name), CalendarContract.ACCOUNT_TYPE_LOCAL)
|
||||||
|
val values = ContentValues().apply {
|
||||||
|
put(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL)
|
||||||
|
put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, context.getString(R.string.app_name))
|
||||||
|
put(CalendarContract.Calendars.NAME, context.getString(R.string.app_name))
|
||||||
|
put(CalendarContract.Calendars.ACCOUNT_NAME, context.getString(R.string.app_name))
|
||||||
|
put(CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL, CalendarContract.Calendars.CAL_ACCESS_OWNER)
|
||||||
|
put(CalendarContract.Calendars.CALENDAR_COLOR, 0x03DAC5)
|
||||||
|
put(CalendarContract.Calendars.VISIBLE, 1)
|
||||||
|
put(CalendarContract.Calendars.SYNC_EVENTS, 1)
|
||||||
|
}
|
||||||
|
context.contentResolver.insert(uri, values)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Uri.asSyncAdapter(account: String, accountType: String): Uri {
|
||||||
|
return buildUpon()
|
||||||
|
.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
|
||||||
|
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, account)
|
||||||
|
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, accountType).build()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
override suspend fun deleteEvent(event: CalendarEvent) {
|
||||||
|
withContext(Dispatchers.IO){
|
||||||
|
val updateUri: Uri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, event.id)
|
||||||
|
context.contentResolver.delete(updateUri, null, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val ID_INDEX = 0
|
||||||
|
private const val TITLE_INDEX = 1
|
||||||
|
private const val DESC_INDEX = 2
|
||||||
|
private const val START_INDEX = 3
|
||||||
|
private const val END_INDEX = 4
|
||||||
|
private const val LOCATION_INDEX = 5
|
||||||
|
private const val ALL_DAY_INDEX = 6
|
||||||
|
private const val COlOR_INDEX = 7
|
||||||
|
private const val EVENT_CALENDAR_ID_INDEX = 8
|
||||||
|
private const val EVENT_RRULE_INDEX = 9
|
||||||
|
private const val EVENT_DURATION_INDEX = 10
|
||||||
|
private const val CALENDAR_COLOR_INDEX = 11
|
||||||
|
|
||||||
|
private const val CALENDAR_ID_INDEX: Int = 0
|
||||||
|
private const val CALENDAR_NAME_INDEX: Int = 1
|
||||||
|
private const val ACCOUNT_NAME_INDEX: Int = 2
|
||||||
|
private const val CALENDAR_CALENDAR_COLOR_INDEX: Int = 4
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.mhss.app.mybrain.data.repository
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.data.local.dao.DiaryDao
|
||||||
|
import com.mhss.app.mybrain.domain.model.DiaryEntry
|
||||||
|
import com.mhss.app.mybrain.domain.repository.DiaryRepository
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
|
class DiaryRepositoryImpl(
|
||||||
|
private val diaryDao: DiaryDao,
|
||||||
|
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
|
||||||
|
) : DiaryRepository {
|
||||||
|
|
||||||
|
override fun getAllEntries(): Flow<List<DiaryEntry>> {
|
||||||
|
return diaryDao.getAllEntries()
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getEntry(id: Int): DiaryEntry {
|
||||||
|
return withContext(ioDispatcher) {
|
||||||
|
diaryDao.getEntry(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun searchEntries(title: String): List<DiaryEntry> {
|
||||||
|
return withContext(ioDispatcher) {
|
||||||
|
diaryDao.getEntriesByTitle(title)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun addEntry(diary: DiaryEntry) {
|
||||||
|
withContext(ioDispatcher) {
|
||||||
|
diaryDao.insertEntry(diary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun updateEntry(diary: DiaryEntry) {
|
||||||
|
withContext(ioDispatcher) {
|
||||||
|
diaryDao.updateEntry(diary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun deleteEntry(diary: DiaryEntry) {
|
||||||
|
withContext(ioDispatcher) {
|
||||||
|
diaryDao.deleteEntry(diary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
package com.mhss.app.mybrain.data.repository
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.data.local.dao.NoteDao
|
||||||
|
import com.mhss.app.mybrain.domain.model.Note
|
||||||
|
import com.mhss.app.mybrain.domain.model.NoteFolder
|
||||||
|
import com.mhss.app.mybrain.domain.repository.NoteRepository
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
|
class NoteRepositoryImpl(
|
||||||
|
private val noteDao: NoteDao,
|
||||||
|
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
|
||||||
|
) : NoteRepository {
|
||||||
|
|
||||||
|
override fun getAllNotes(): Flow<List<Note>> {
|
||||||
|
return noteDao.getAllNotes()
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getNote(id: Int): Note {
|
||||||
|
return withContext(ioDispatcher) {
|
||||||
|
noteDao.getNote(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun searchNotes(query: String): List<Note> {
|
||||||
|
return withContext(ioDispatcher) {
|
||||||
|
noteDao.getNotesByTitle(query)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getNotesByFolder(folderId: Int): Flow<List<Note>> {
|
||||||
|
return noteDao.getNotesByFolder(folderId)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun addNote(note: Note) {
|
||||||
|
withContext(ioDispatcher) {
|
||||||
|
noteDao.insertNote(note)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun updateNote(note: Note) {
|
||||||
|
withContext(ioDispatcher) {
|
||||||
|
noteDao.updateNote(note)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun deleteNote(note: Note) {
|
||||||
|
withContext(ioDispatcher) {
|
||||||
|
noteDao.deleteNote(note)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun insertNoteFolder(folder: NoteFolder) {
|
||||||
|
withContext(ioDispatcher) {
|
||||||
|
noteDao.insertNoteFolder(folder)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun updateNoteFolder(folder: NoteFolder) {
|
||||||
|
withContext(ioDispatcher) {
|
||||||
|
noteDao.updateNoteFolder(folder)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun deleteNoteFolder(folder: NoteFolder) {
|
||||||
|
withContext(ioDispatcher) {
|
||||||
|
noteDao.deleteNoteFolder(folder)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getAllNoteFolders(): Flow<List<NoteFolder>> {
|
||||||
|
return noteDao.getAllNoteFolders()
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.mhss.app.mybrain.data.repository
|
||||||
|
|
||||||
|
import androidx.datastore.core.DataStore
|
||||||
|
import androidx.datastore.preferences.core.Preferences
|
||||||
|
import androidx.datastore.preferences.core.edit
|
||||||
|
import com.mhss.app.mybrain.domain.repository.SettingsRepository
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
|
class SettingsRepositoryImpl(
|
||||||
|
private val preferences: DataStore<Preferences>,
|
||||||
|
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
|
||||||
|
) : SettingsRepository {
|
||||||
|
|
||||||
|
override suspend fun <T> saveSettings(key: Preferences.Key<T>, value: T) {
|
||||||
|
withContext(ioDispatcher) {
|
||||||
|
preferences.edit { settings ->
|
||||||
|
if (settings[key] != value)
|
||||||
|
settings[key] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun <T> getSettings(key: Preferences.Key<T>, defaultValue: T): Flow<T> {
|
||||||
|
return preferences.data.map { preferences -> preferences[key] ?: defaultValue }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
package com.mhss.app.mybrain.data.repository
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.data.local.dao.TaskDao
|
||||||
|
import com.mhss.app.mybrain.domain.model.Task
|
||||||
|
import com.mhss.app.mybrain.domain.repository.TaskRepository
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class TaskRepositoryImpl(
|
||||||
|
private val taskDao: TaskDao,
|
||||||
|
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
|
||||||
|
) : TaskRepository {
|
||||||
|
|
||||||
|
override fun getAllTasks(): Flow<List<Task>> {
|
||||||
|
return taskDao.getAllTasks()
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getTaskById(id: Int): Task {
|
||||||
|
return withContext(ioDispatcher) {
|
||||||
|
taskDao.getTask(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun searchTasks(title: String): Flow<List<Task>> {
|
||||||
|
return taskDao.getTasksByTitle(title)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun insertTask(task: Task): Long {
|
||||||
|
return withContext(ioDispatcher) {
|
||||||
|
taskDao.insertTask(task)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun updateTask(task: Task) {
|
||||||
|
withContext(ioDispatcher) {
|
||||||
|
taskDao.updateTask(task)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun completeTask(id: Int, completed: Boolean) {
|
||||||
|
withContext(ioDispatcher) {
|
||||||
|
taskDao.updateCompleted(id, completed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun deleteTask(task: Task) {
|
||||||
|
withContext(ioDispatcher) {
|
||||||
|
taskDao.deleteTask(task)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
package com.mhss.app.mybrain.di
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.room.Room
|
||||||
|
import com.mhss.app.mybrain.app.dataStore
|
||||||
|
import com.mhss.app.mybrain.data.backup.RoomBackupRepositoryImpl
|
||||||
|
import com.mhss.app.mybrain.data.local.MyBrainDatabase
|
||||||
|
import com.mhss.app.mybrain.data.local.dao.*
|
||||||
|
import com.mhss.app.mybrain.data.local.migrations.MIGRATION_1_2
|
||||||
|
import com.mhss.app.mybrain.data.local.migrations.MIGRATION_2_3
|
||||||
|
import com.mhss.app.mybrain.data.local.migrations.MIGRATION_3_4
|
||||||
|
import com.mhss.app.mybrain.data.repository.*
|
||||||
|
import com.mhss.app.mybrain.domain.repository.*
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Module
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
object AppModule {
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
fun provideMyBrainDataBase(
|
||||||
|
@ApplicationContext context: Context
|
||||||
|
) = Room.databaseBuilder(
|
||||||
|
context,
|
||||||
|
MyBrainDatabase::class.java,
|
||||||
|
MyBrainDatabase.DATABASE_NAME
|
||||||
|
).addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
fun provideNoteDao(myBrainDatabase: MyBrainDatabase) = myBrainDatabase.noteDao()
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
fun provideNoteRepository(noteDao: NoteDao): NoteRepository = NoteRepositoryImpl(noteDao)
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
fun provideTaskDao(myBrainDatabase: MyBrainDatabase) = myBrainDatabase.taskDao()
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
fun provideTaskRepository(taskDao: TaskDao): TaskRepository = TaskRepositoryImpl(taskDao)
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
fun provideBookmarkDao(myBrainDatabase: MyBrainDatabase) = myBrainDatabase.bookmarkDao()
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
fun provideBookmarkRepository(bookmarkDao: BookmarkDao): BookmarkRepository =
|
||||||
|
BookmarkRepositoryImpl(bookmarkDao)
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
fun provideDiaryDao(myBrainDatabase: MyBrainDatabase) = myBrainDatabase.diaryDao()
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
fun provideDiaryRepository(diaryDao: DiaryDao): DiaryRepository = DiaryRepositoryImpl(diaryDao)
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
fun provideCalendarRepository(@ApplicationContext context: Context): CalendarRepository =
|
||||||
|
CalendarRepositoryImpl(context)
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
fun provideAlarmDao(myBrainDatabase: MyBrainDatabase) = myBrainDatabase.alarmDao()
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
fun provideAlarmRepository(alarmDao: AlarmDao): AlarmRepository = AlarmRepositoryImpl(alarmDao)
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
fun provideSettingsRepository(@ApplicationContext context: Context): SettingsRepository =
|
||||||
|
SettingsRepositoryImpl(context.dataStore)
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
fun provideAppContext(@ApplicationContext context: Context) = context
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
fun provideBackupRepository(
|
||||||
|
myBrainDatabase: MyBrainDatabase,
|
||||||
|
@ApplicationContext context: Context
|
||||||
|
): RoomBackupRepository = RoomBackupRepositoryImpl(myBrainDatabase ,context)
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.mhss.app.mybrain.di
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.use_case.calendar.GetAllEventsUseCase
|
||||||
|
import com.mhss.app.mybrain.domain.use_case.settings.GetSettingsUseCase
|
||||||
|
import dagger.hilt.EntryPoint
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
|
||||||
|
|
||||||
|
@EntryPoint
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
interface CalendarWidgetEntryPoint {
|
||||||
|
|
||||||
|
fun getSettingsUseCase(): GetSettingsUseCase
|
||||||
|
|
||||||
|
fun getAllEventsUseCase(): GetAllEventsUseCase
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.mhss.app.mybrain.di
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.use_case.settings.GetSettingsUseCase
|
||||||
|
import com.mhss.app.mybrain.domain.use_case.tasks.GetAllTasksUseCase
|
||||||
|
import dagger.hilt.EntryPoint
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
|
||||||
|
@EntryPoint
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
interface TasksWidgetEntryPoint {
|
||||||
|
fun getSettingsUseCase(): GetSettingsUseCase
|
||||||
|
|
||||||
|
fun getAllTasksUseCase(): GetAllTasksUseCase
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.mhss.app.mybrain.domain.model
|
||||||
|
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
@Entity(tableName = "alarms")
|
||||||
|
data class Alarm(
|
||||||
|
@PrimaryKey(autoGenerate = false)
|
||||||
|
val id: Int,
|
||||||
|
val time: Long,
|
||||||
|
)
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.mhss.app.mybrain.domain.model
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
@Entity(tableName = "bookmarks")
|
||||||
|
data class Bookmark(
|
||||||
|
val url: String,
|
||||||
|
val title: String = "",
|
||||||
|
val description: String = "",
|
||||||
|
@ColumnInfo(name = "created_date")
|
||||||
|
val createdDate: Long = 0L,
|
||||||
|
@ColumnInfo(name = "updated_date")
|
||||||
|
val updatedDate: Long = 0L,
|
||||||
|
@PrimaryKey(autoGenerate = true)
|
||||||
|
val id: Int = 0
|
||||||
|
)
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.mhss.app.mybrain.domain.model
|
||||||
|
|
||||||
|
data class Calendar(
|
||||||
|
val id: Long,
|
||||||
|
val name: String,
|
||||||
|
val account: String,
|
||||||
|
val color: Int,
|
||||||
|
val included: Boolean = true
|
||||||
|
)
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.mhss.app.mybrain.domain.model
|
||||||
|
|
||||||
|
data class CalendarEvent(
|
||||||
|
val id: Long,
|
||||||
|
val title: String,
|
||||||
|
val description: String?,
|
||||||
|
val start: Long,
|
||||||
|
val end: Long,
|
||||||
|
val location: String?,
|
||||||
|
val allDay: Boolean = false,
|
||||||
|
val color: Int = 0,
|
||||||
|
val calendarId: Long,
|
||||||
|
val recurring: Boolean = false,
|
||||||
|
val frequency: String = "",
|
||||||
|
)
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.mhss.app.mybrain.domain.model
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
import com.mhss.app.mybrain.util.diary.Mood
|
||||||
|
|
||||||
|
@Entity(tableName = "diary")
|
||||||
|
data class DiaryEntry(
|
||||||
|
val title: String = "",
|
||||||
|
val content: String = "",
|
||||||
|
@ColumnInfo(name = "created_date")
|
||||||
|
val createdDate: Long = 0L,
|
||||||
|
@ColumnInfo(name = "updated_date")
|
||||||
|
val updatedDate: Long = 0L,
|
||||||
|
val mood: Mood,
|
||||||
|
@PrimaryKey(autoGenerate = true)
|
||||||
|
val id: Int = 0
|
||||||
|
)
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.mhss.app.mybrain.domain.model
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.ForeignKey
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
@Entity(
|
||||||
|
tableName = "notes",
|
||||||
|
foreignKeys = [
|
||||||
|
ForeignKey(
|
||||||
|
entity = NoteFolder::class,
|
||||||
|
parentColumns = ["id"],
|
||||||
|
childColumns = ["folder_id"],
|
||||||
|
onDelete = ForeignKey.CASCADE,
|
||||||
|
onUpdate = ForeignKey.NO_ACTION
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
data class Note(
|
||||||
|
val title: String = "",
|
||||||
|
val content: String = "",
|
||||||
|
@ColumnInfo(name = "created_date")
|
||||||
|
val createdDate: Long = 0L,
|
||||||
|
@ColumnInfo(name = "updated_date")
|
||||||
|
val updatedDate: Long = 0L,
|
||||||
|
val pinned: Boolean = false,
|
||||||
|
@ColumnInfo(name = "folder_id")
|
||||||
|
val folderId: Int? = null,
|
||||||
|
@PrimaryKey(autoGenerate = true)
|
||||||
|
val id: Int = 0,
|
||||||
|
)
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.mhss.app.mybrain.domain.model
|
||||||
|
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
@Entity(
|
||||||
|
tableName = "note_folders",
|
||||||
|
)
|
||||||
|
data class NoteFolder(
|
||||||
|
val name: String,
|
||||||
|
@PrimaryKey(autoGenerate = true)
|
||||||
|
val id: Int = 0
|
||||||
|
)
|
|
@ -0,0 +1,6 @@
|
||||||
|
package com.mhss.app.mybrain.domain.model
|
||||||
|
|
||||||
|
data class NotesBackUp(
|
||||||
|
val notes: List<Note>,
|
||||||
|
val folders: List<NoteFolder>
|
||||||
|
)
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.mhss.app.mybrain.domain.model
|
||||||
|
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
data class SubTask(
|
||||||
|
val title: String,
|
||||||
|
val isCompleted: Boolean,
|
||||||
|
val id: UUID = UUID.randomUUID()
|
||||||
|
)
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.mhss.app.mybrain.domain.model
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
@Entity(tableName = "tasks")
|
||||||
|
data class Task(
|
||||||
|
val title: String,
|
||||||
|
val description: String = "",
|
||||||
|
@ColumnInfo(name = "is_completed")
|
||||||
|
val isCompleted: Boolean = false,
|
||||||
|
val priority: Int = 0,
|
||||||
|
@ColumnInfo(name = "created_date")
|
||||||
|
val createdDate: Long = 0L,
|
||||||
|
@ColumnInfo(name = "updated_date")
|
||||||
|
val updatedDate: Long = 0L,
|
||||||
|
@ColumnInfo(name = "sub_tasks")
|
||||||
|
val subTasks: List<SubTask> = emptyList(),
|
||||||
|
val dueDate: Long = 0L,
|
||||||
|
val recurring: Boolean = false,
|
||||||
|
val frequency: Int = 0,
|
||||||
|
@ColumnInfo(name = "frequency_amount")
|
||||||
|
val frequencyAmount: Int = 1,
|
||||||
|
@PrimaryKey(autoGenerate = true)
|
||||||
|
val id: Int = 0
|
||||||
|
)
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.mhss.app.mybrain.domain.repository
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.Alarm
|
||||||
|
|
||||||
|
interface AlarmRepository {
|
||||||
|
|
||||||
|
suspend fun getAlarms(): List<Alarm>
|
||||||
|
|
||||||
|
suspend fun insertAlarm(alarm: Alarm)
|
||||||
|
|
||||||
|
suspend fun deleteAlarm(alarm: Alarm)
|
||||||
|
|
||||||
|
suspend fun deleteAlarm(id: Int)
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.mhss.app.mybrain.domain.repository
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.Bookmark
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
interface BookmarkRepository {
|
||||||
|
|
||||||
|
fun getAllBookmarks(): Flow<List<Bookmark>>
|
||||||
|
|
||||||
|
suspend fun getBookmark(id: Int): Bookmark
|
||||||
|
|
||||||
|
suspend fun searchBookmarks(query: String): List<Bookmark>
|
||||||
|
|
||||||
|
suspend fun addBookmark(bookmark: Bookmark)
|
||||||
|
|
||||||
|
suspend fun deleteBookmark(bookmark: Bookmark)
|
||||||
|
|
||||||
|
suspend fun updateBookmark(bookmark: Bookmark)
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.mhss.app.mybrain.domain.repository
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.Calendar
|
||||||
|
import com.mhss.app.mybrain.domain.model.CalendarEvent
|
||||||
|
|
||||||
|
interface CalendarRepository {
|
||||||
|
|
||||||
|
suspend fun getEvents(): List<CalendarEvent>
|
||||||
|
|
||||||
|
suspend fun getCalendars(): List<Calendar>
|
||||||
|
|
||||||
|
suspend fun addEvent(event: CalendarEvent)
|
||||||
|
|
||||||
|
suspend fun deleteEvent(event: CalendarEvent)
|
||||||
|
|
||||||
|
suspend fun updateEvent(event: CalendarEvent)
|
||||||
|
|
||||||
|
suspend fun createCalendar()
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.mhss.app.mybrain.domain.repository
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.DiaryEntry
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
interface DiaryRepository {
|
||||||
|
|
||||||
|
fun getAllEntries(): Flow<List<DiaryEntry>>
|
||||||
|
|
||||||
|
suspend fun getEntry(id: Int): DiaryEntry
|
||||||
|
|
||||||
|
suspend fun searchEntries(title: String): List<DiaryEntry>
|
||||||
|
|
||||||
|
suspend fun addEntry(diary: DiaryEntry)
|
||||||
|
|
||||||
|
suspend fun updateEntry(diary: DiaryEntry)
|
||||||
|
|
||||||
|
suspend fun deleteEntry(diary: DiaryEntry)
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.mhss.app.mybrain.domain.repository
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.Note
|
||||||
|
import com.mhss.app.mybrain.domain.model.NoteFolder
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
interface NoteRepository {
|
||||||
|
|
||||||
|
fun getAllNotes(): Flow<List<Note>>
|
||||||
|
|
||||||
|
suspend fun getNote(id: Int): Note
|
||||||
|
|
||||||
|
suspend fun searchNotes(query: String): List<Note>
|
||||||
|
|
||||||
|
fun getNotesByFolder(folderId: Int): Flow<List<Note>>
|
||||||
|
|
||||||
|
suspend fun addNote(note: Note)
|
||||||
|
|
||||||
|
suspend fun updateNote(note: Note)
|
||||||
|
|
||||||
|
suspend fun deleteNote(note: Note)
|
||||||
|
|
||||||
|
suspend fun insertNoteFolder(folder: NoteFolder)
|
||||||
|
|
||||||
|
suspend fun updateNoteFolder(folder: NoteFolder)
|
||||||
|
|
||||||
|
suspend fun deleteNoteFolder(folder: NoteFolder)
|
||||||
|
|
||||||
|
fun getAllNoteFolders(): Flow<List<NoteFolder>>
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.mhss.app.mybrain.domain.repository
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
|
|
||||||
|
interface RoomBackupRepository {
|
||||||
|
|
||||||
|
suspend fun exportDatabase(directoryUri: Uri, encrypted: Boolean, password: String): Boolean
|
||||||
|
|
||||||
|
suspend fun importDatabase(fileUri: Uri, encrypted: Boolean, password: String): Boolean
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.mhss.app.mybrain.domain.repository
|
||||||
|
|
||||||
|
import androidx.datastore.preferences.core.Preferences
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
interface SettingsRepository {
|
||||||
|
|
||||||
|
suspend fun <T> saveSettings(key: Preferences.Key<T>, value: T)
|
||||||
|
|
||||||
|
fun <T> getSettings(key: Preferences.Key<T>, defaultValue: T): Flow<T>
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.mhss.app.mybrain.domain.repository
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.Task
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
interface TaskRepository {
|
||||||
|
|
||||||
|
fun getAllTasks(): Flow<List<Task>>
|
||||||
|
|
||||||
|
suspend fun getTaskById(id: Int): Task
|
||||||
|
|
||||||
|
fun searchTasks(title: String): Flow<List<Task>>
|
||||||
|
|
||||||
|
suspend fun insertTask(task: Task): Long
|
||||||
|
|
||||||
|
suspend fun updateTask(task: Task)
|
||||||
|
|
||||||
|
suspend fun completeTask(id: Int, completed: Boolean)
|
||||||
|
|
||||||
|
suspend fun deleteTask(task: Task)
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.alarm
|
||||||
|
|
||||||
|
import android.app.AlarmManager
|
||||||
|
import android.content.Context
|
||||||
|
import com.mhss.app.mybrain.domain.model.Alarm
|
||||||
|
import com.mhss.app.mybrain.domain.repository.AlarmRepository
|
||||||
|
import com.mhss.app.mybrain.util.alarms.scheduleAlarm
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class AddAlarmUseCase @Inject constructor(
|
||||||
|
private val alarmRepository: AlarmRepository,
|
||||||
|
private val context: Context
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(alarm: Alarm) {
|
||||||
|
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||||
|
alarmManager.scheduleAlarm(alarm, context)
|
||||||
|
alarmRepository.insertAlarm(alarm)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.alarm
|
||||||
|
|
||||||
|
import android.app.AlarmManager
|
||||||
|
import android.content.Context
|
||||||
|
import com.mhss.app.mybrain.domain.repository.AlarmRepository
|
||||||
|
import com.mhss.app.mybrain.util.alarms.cancelAlarm
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class DeleteAlarmUseCase @Inject constructor(
|
||||||
|
private val alarmRepository: AlarmRepository,
|
||||||
|
private val context: Context
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(alarmId: Int) {
|
||||||
|
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||||
|
alarmManager.cancelAlarm(alarmId, context)
|
||||||
|
alarmRepository.deleteAlarm(alarmId)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.alarm
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.repository.AlarmRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class GetAllAlarmsUseCase @Inject constructor(
|
||||||
|
private val alarmRepository: AlarmRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke() = alarmRepository.getAlarms()
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.bookmarks
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.Bookmark
|
||||||
|
import com.mhss.app.mybrain.domain.repository.BookmarkRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class AddBookmarkUseCase @Inject constructor(
|
||||||
|
private val bookmarkRepository: BookmarkRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(bookmark: Bookmark) = bookmarkRepository.addBookmark(bookmark)
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.bookmarks
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.Bookmark
|
||||||
|
import com.mhss.app.mybrain.domain.repository.BookmarkRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class DeleteBookmarkUseCase @Inject constructor(
|
||||||
|
private val bookmarkRepository: BookmarkRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(bookmark: Bookmark) = bookmarkRepository.deleteBookmark(bookmark)
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.bookmarks
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.Bookmark
|
||||||
|
import com.mhss.app.mybrain.domain.repository.BookmarkRepository
|
||||||
|
import com.mhss.app.mybrain.util.settings.Order
|
||||||
|
import com.mhss.app.mybrain.util.settings.OrderType
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class GetAllBookmarksUseCase @Inject constructor(
|
||||||
|
private val bookmarksRepository: BookmarkRepository
|
||||||
|
) {
|
||||||
|
operator fun invoke(order: Order) : Flow<List<Bookmark>>{
|
||||||
|
return bookmarksRepository.getAllBookmarks().map { bookmarks ->
|
||||||
|
when (order.orderType) {
|
||||||
|
is OrderType.ASC -> {
|
||||||
|
when (order) {
|
||||||
|
is Order.Alphabetical -> bookmarks.sortedBy { it.title }
|
||||||
|
is Order.DateCreated -> bookmarks.sortedBy { it.createdDate }
|
||||||
|
is Order.DateModified -> bookmarks.sortedBy { it.updatedDate }
|
||||||
|
else -> bookmarks.sortedBy { it.updatedDate }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is OrderType.DESC -> {
|
||||||
|
when (order) {
|
||||||
|
is Order.Alphabetical -> bookmarks.sortedByDescending { it.title }
|
||||||
|
is Order.DateCreated -> bookmarks.sortedByDescending { it.createdDate }
|
||||||
|
is Order.DateModified -> bookmarks.sortedByDescending { it.updatedDate }
|
||||||
|
else -> bookmarks.sortedByDescending { it.updatedDate }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.bookmarks
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.repository.BookmarkRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class GetBookmarkUseCase @Inject constructor(
|
||||||
|
private val bookmarkRepository: BookmarkRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(id: Int) = bookmarkRepository.getBookmark(id)
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.bookmarks
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.repository.BookmarkRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class SearchBookmarksUseCase @Inject constructor(
|
||||||
|
private val bookmarksRepository: BookmarkRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(query: String) = bookmarksRepository.searchBookmarks(query)
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.bookmarks
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.Bookmark
|
||||||
|
import com.mhss.app.mybrain.domain.repository.BookmarkRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class UpdateBookmarkUseCase @Inject constructor(
|
||||||
|
private val bookmarkRepository: BookmarkRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(bookmark: Bookmark) = bookmarkRepository.updateBookmark(bookmark)
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.calendar
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.glance.appwidget.updateAll
|
||||||
|
import com.mhss.app.mybrain.domain.model.CalendarEvent
|
||||||
|
import com.mhss.app.mybrain.domain.repository.CalendarRepository
|
||||||
|
import com.mhss.app.mybrain.presentation.glance_widgets.CalendarHomeWidget
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class AddCalendarEventUseCase @Inject constructor(
|
||||||
|
private val calendarEventRepository: CalendarRepository,
|
||||||
|
private val context: Context
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(calendarEvent: CalendarEvent) {
|
||||||
|
val calendars = calendarEventRepository.getCalendars()
|
||||||
|
if (calendars.isNotEmpty()) {
|
||||||
|
calendarEventRepository.addEvent(calendarEvent)
|
||||||
|
} else {
|
||||||
|
calendarEventRepository.createCalendar()
|
||||||
|
val calendar = calendarEventRepository.getCalendars().first()
|
||||||
|
calendarEventRepository.addEvent(calendarEvent.copy(calendarId = calendar.id))
|
||||||
|
}
|
||||||
|
CalendarHomeWidget().updateAll(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.calendar
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.glance.appwidget.updateAll
|
||||||
|
import com.mhss.app.mybrain.domain.model.CalendarEvent
|
||||||
|
import com.mhss.app.mybrain.domain.repository.CalendarRepository
|
||||||
|
import com.mhss.app.mybrain.presentation.glance_widgets.CalendarHomeWidget
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class DeleteCalendarEventUseCase @Inject constructor(
|
||||||
|
private val calendarRepository: CalendarRepository,
|
||||||
|
private val context: Context
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(event: CalendarEvent) {
|
||||||
|
calendarRepository.deleteEvent(event)
|
||||||
|
CalendarHomeWidget().updateAll(context)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.calendar
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.Calendar
|
||||||
|
import com.mhss.app.mybrain.domain.repository.CalendarRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class GetAllCalendarsUseCase @Inject constructor(
|
||||||
|
private val calendarRepository: CalendarRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(excluded: List<Int>): Map<String, List<Calendar>> {
|
||||||
|
return calendarRepository.getCalendars().map { it.copy(included = (it.id.toInt() !in excluded)) }.groupBy { it.account }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.calendar
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.CalendarEvent
|
||||||
|
import com.mhss.app.mybrain.domain.repository.CalendarRepository
|
||||||
|
import com.mhss.app.mybrain.util.date.formatDateForMapping
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class GetAllEventsUseCase @Inject constructor(
|
||||||
|
private val calendarRepository: CalendarRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(excluded: List<Int>, fromWidget: Boolean = false): Map<String, List<CalendarEvent>> {
|
||||||
|
val events = try {
|
||||||
|
calendarRepository.getEvents()
|
||||||
|
.filter { it.calendarId.toInt() !in excluded }
|
||||||
|
} catch (e: Exception) {
|
||||||
|
return emptyMap()
|
||||||
|
}
|
||||||
|
return if (fromWidget)
|
||||||
|
events.take(30).groupBy { event ->
|
||||||
|
event.start.formatDateForMapping()
|
||||||
|
}
|
||||||
|
else
|
||||||
|
events.groupBy { event ->
|
||||||
|
event.start.formatDateForMapping()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.calendar
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.glance.appwidget.updateAll
|
||||||
|
import com.mhss.app.mybrain.domain.model.CalendarEvent
|
||||||
|
import com.mhss.app.mybrain.domain.repository.CalendarRepository
|
||||||
|
import com.mhss.app.mybrain.presentation.glance_widgets.CalendarHomeWidget
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class UpdateCalendarEventUseCase @Inject constructor(
|
||||||
|
private val calendarRepository: CalendarRepository,
|
||||||
|
private val context: Context
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(event: CalendarEvent) {
|
||||||
|
calendarRepository.updateEvent(event)
|
||||||
|
CalendarHomeWidget().updateAll(context)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.diary
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.DiaryEntry
|
||||||
|
import com.mhss.app.mybrain.domain.repository.DiaryRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class AddDiaryEntryUseCase @Inject constructor(
|
||||||
|
private val diaryRepository: DiaryRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(entry: DiaryEntry) = diaryRepository.addEntry(entry)
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.diary
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.DiaryEntry
|
||||||
|
import com.mhss.app.mybrain.domain.repository.DiaryRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class DeleteDiaryEntryUseCase @Inject constructor(
|
||||||
|
private val diaryRepository: DiaryRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(entry: DiaryEntry) = diaryRepository.deleteEntry(entry)
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.diary
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.DiaryEntry
|
||||||
|
import com.mhss.app.mybrain.domain.repository.DiaryRepository
|
||||||
|
import com.mhss.app.mybrain.util.settings.Order
|
||||||
|
import com.mhss.app.mybrain.util.settings.OrderType
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class GetAllEntriesUseCase @Inject constructor(
|
||||||
|
private val diaryRepository: DiaryRepository
|
||||||
|
) {
|
||||||
|
operator fun invoke(order: Order) : Flow<List<DiaryEntry>> {
|
||||||
|
return diaryRepository.getAllEntries().map { entries ->
|
||||||
|
when (order.orderType) {
|
||||||
|
is OrderType.ASC -> {
|
||||||
|
when (order) {
|
||||||
|
is Order.Alphabetical -> entries.sortedBy { it.title }
|
||||||
|
is Order.DateCreated -> entries.sortedBy { it.createdDate }
|
||||||
|
is Order.DateModified -> entries.sortedBy { it.updatedDate }
|
||||||
|
else -> entries.sortedBy { it.updatedDate }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is OrderType.DESC -> {
|
||||||
|
when (order) {
|
||||||
|
is Order.Alphabetical -> entries.sortedByDescending { it.title }
|
||||||
|
is Order.DateCreated -> entries.sortedByDescending { it.createdDate }
|
||||||
|
is Order.DateModified -> entries.sortedByDescending { it.updatedDate }
|
||||||
|
else -> entries.sortedByDescending { it.updatedDate }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.diary
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.repository.DiaryRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class GetDiaryEntryUseCase @Inject constructor(
|
||||||
|
private val diaryRepository: DiaryRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(id: Int) = diaryRepository.getEntry(id)
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.diary
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.DiaryEntry
|
||||||
|
import com.mhss.app.mybrain.domain.repository.DiaryRepository
|
||||||
|
import com.mhss.app.mybrain.util.date.inTheLast30Days
|
||||||
|
import com.mhss.app.mybrain.util.date.inTheLastYear
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class GetDiaryForChartUseCase @Inject constructor(
|
||||||
|
private val diaryRepository: DiaryRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(monthly: Boolean) : List<DiaryEntry>{
|
||||||
|
return diaryRepository
|
||||||
|
.getAllEntries()
|
||||||
|
.first()
|
||||||
|
.filter {
|
||||||
|
if (monthly) it.createdDate.inTheLast30Days()
|
||||||
|
else it.createdDate.inTheLastYear()
|
||||||
|
}
|
||||||
|
.sortedBy { it.createdDate }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.diary
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.repository.DiaryRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class SearchEntriesUseCase @Inject constructor(
|
||||||
|
private val repository: DiaryRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(query: String) = repository.searchEntries(query)
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.diary
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.DiaryEntry
|
||||||
|
import com.mhss.app.mybrain.domain.repository.DiaryRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class UpdateDiaryEntryUseCase @Inject constructor(
|
||||||
|
private val diaryRepository: DiaryRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(entry: DiaryEntry) = diaryRepository.updateEntry(entry)
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.notes
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.NoteFolder
|
||||||
|
import com.mhss.app.mybrain.domain.repository.NoteRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class AddNoteFolderUseCass @Inject constructor(
|
||||||
|
private val noteRepository: NoteRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(folder: NoteFolder) = noteRepository.insertNoteFolder(folder)
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.notes
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.Note
|
||||||
|
import com.mhss.app.mybrain.domain.repository.NoteRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class AddNoteUseCase @Inject constructor(
|
||||||
|
private val notesRepository: NoteRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(note: Note) = notesRepository.addNote(note)
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.notes
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.NoteFolder
|
||||||
|
import com.mhss.app.mybrain.domain.repository.NoteRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class DeleteNoteFolderUseCass @Inject constructor(
|
||||||
|
private val noteRepository: NoteRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(folder: NoteFolder) = noteRepository.deleteNoteFolder(folder)
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.notes
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.Note
|
||||||
|
import com.mhss.app.mybrain.domain.repository.NoteRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class DeleteNoteUseCase @Inject constructor(
|
||||||
|
private val repository: NoteRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(note: Note) = repository.deleteNote(note)
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.notes
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.repository.NoteRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class GetAllNoteFoldersUseCase @Inject constructor(
|
||||||
|
private val repository: NoteRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke() = repository.getAllNoteFolders()
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.notes
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.Note
|
||||||
|
import com.mhss.app.mybrain.domain.repository.NoteRepository
|
||||||
|
import com.mhss.app.mybrain.util.settings.Order
|
||||||
|
import com.mhss.app.mybrain.util.settings.OrderType
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class GetAllNotesUseCase @Inject constructor(
|
||||||
|
private val notesRepository: NoteRepository
|
||||||
|
) {
|
||||||
|
operator fun invoke(order: Order) : Flow<List<Note>> {
|
||||||
|
return notesRepository.getAllNotes().map { list ->
|
||||||
|
when (order.orderType) {
|
||||||
|
is OrderType.ASC -> {
|
||||||
|
when (order) {
|
||||||
|
is Order.Alphabetical -> list.sortedWith(compareBy({!it.pinned}, { it.title }))
|
||||||
|
is Order.DateCreated -> list.sortedWith(compareBy({!it.pinned}, { it.createdDate }))
|
||||||
|
is Order.DateModified -> list.sortedWith(compareBy({!it.pinned}, { it.updatedDate }))
|
||||||
|
else -> list.sortedWith(compareBy({!it.pinned}, { it.updatedDate }))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is OrderType.DESC -> {
|
||||||
|
when (order) {
|
||||||
|
is Order.Alphabetical -> list.sortedWith(compareBy({it.pinned}, { it.title })).reversed()
|
||||||
|
is Order.DateCreated -> list.sortedWith(compareBy({it.pinned}, { it.createdDate })).reversed()
|
||||||
|
is Order.DateModified -> list.sortedWith(compareBy({it.pinned}, { it.updatedDate })).reversed()
|
||||||
|
else -> list.sortedWith(compareBy({it.pinned}, { it.updatedDate })).reversed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.notes
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.repository.NoteRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class GetNoteUseCase @Inject constructor(
|
||||||
|
private val notesRepository: NoteRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(id: Int) = notesRepository.getNote(id)
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.notes
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.repository.NoteRepository
|
||||||
|
import com.mhss.app.mybrain.util.settings.Order
|
||||||
|
import com.mhss.app.mybrain.util.settings.OrderType
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class GetNotesByFolderUseCase @Inject constructor(
|
||||||
|
private val notesRepository: NoteRepository
|
||||||
|
) {
|
||||||
|
operator fun invoke(folderId: Int, order: Order) = notesRepository.getNotesByFolder(folderId).map { list ->
|
||||||
|
when (order.orderType) {
|
||||||
|
is OrderType.ASC -> {
|
||||||
|
when (order) {
|
||||||
|
is Order.Alphabetical -> list.sortedWith(compareBy({!it.pinned}, { it.title }))
|
||||||
|
is Order.DateCreated -> list.sortedWith(compareBy({!it.pinned}, { it.createdDate }))
|
||||||
|
is Order.DateModified -> list.sortedWith(compareBy({!it.pinned}, { it.updatedDate }))
|
||||||
|
else -> list.sortedWith(compareBy({!it.pinned}, { it.updatedDate }))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is OrderType.DESC -> {
|
||||||
|
when (order) {
|
||||||
|
is Order.Alphabetical -> list.sortedWith(compareBy({it.pinned}, { it.title })).reversed()
|
||||||
|
is Order.DateCreated -> list.sortedWith(compareBy({it.pinned}, { it.createdDate })).reversed()
|
||||||
|
is Order.DateModified -> list.sortedWith(compareBy({it.pinned}, { it.updatedDate })).reversed()
|
||||||
|
else -> list.sortedWith(compareBy({it.pinned}, { it.updatedDate })).reversed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,245 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.notes
|
||||||
|
|
||||||
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.grid.GridCells
|
||||||
|
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||||
|
import androidx.compose.foundation.lazy.grid.items
|
||||||
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material.*
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.Delete
|
||||||
|
import androidx.compose.material.icons.filled.Edit
|
||||||
|
import androidx.compose.runtime.*
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
|
import androidx.navigation.NavHostController
|
||||||
|
import com.mhss.app.mybrain.R
|
||||||
|
import com.mhss.app.mybrain.presentation.notes.NoteEvent
|
||||||
|
import com.mhss.app.mybrain.presentation.notes.NoteItem
|
||||||
|
import com.mhss.app.mybrain.presentation.notes.NotesViewModel
|
||||||
|
import com.mhss.app.mybrain.presentation.util.Screen
|
||||||
|
import com.mhss.app.mybrain.util.Constants
|
||||||
|
import com.mhss.app.mybrain.util.settings.ItemView
|
||||||
|
|
||||||
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
|
@Composable
|
||||||
|
fun NoteFolderDetailsScreen(
|
||||||
|
navController: NavHostController,
|
||||||
|
id: Int,
|
||||||
|
viewModel: NotesViewModel = hiltViewModel()
|
||||||
|
) {
|
||||||
|
val uiState = viewModel.notesUiState
|
||||||
|
val folder = uiState.folder
|
||||||
|
|
||||||
|
var openDeleteDialog by remember { mutableStateOf(false) }
|
||||||
|
var openEditDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
val scaffoldState = rememberScaffoldState()
|
||||||
|
LaunchedEffect(true) {viewModel.onEvent(NoteEvent.GetFolderNotes(id)) }
|
||||||
|
LaunchedEffect(uiState) {
|
||||||
|
if (viewModel.notesUiState.navigateUp) {
|
||||||
|
navController.popBackStack(route = Screen.NotesScreen.route, inclusive = false)
|
||||||
|
}
|
||||||
|
if (uiState.error != null) {
|
||||||
|
scaffoldState.snackbarHostState.showSnackbar(
|
||||||
|
uiState.error
|
||||||
|
)
|
||||||
|
viewModel.onEvent(NoteEvent.ErrorDisplayed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Scaffold(
|
||||||
|
scaffoldState = scaffoldState,
|
||||||
|
topBar = {
|
||||||
|
TopAppBar(
|
||||||
|
title = {
|
||||||
|
Text(
|
||||||
|
text = folder?.name ?: "",
|
||||||
|
style = MaterialTheme.typography.h5.copy(fontWeight = FontWeight.Bold)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
backgroundColor = MaterialTheme.colors.background,
|
||||||
|
elevation = 0.dp,
|
||||||
|
actions = {
|
||||||
|
IconButton(onClick = { openDeleteDialog = true }) {
|
||||||
|
Icon(Icons.Default.Delete, stringResource(R.string.delete_folder))
|
||||||
|
}
|
||||||
|
IconButton(onClick = { openEditDialog = true }) {
|
||||||
|
Icon(Icons.Default.Edit, stringResource(R.string.delete_folder))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
floatingActionButton = {
|
||||||
|
FloatingActionButton(
|
||||||
|
onClick = {
|
||||||
|
navController.navigate(
|
||||||
|
Screen.NoteDetailsScreen.route.replace(
|
||||||
|
"{${Constants.NOTE_ID_ARG}}",
|
||||||
|
"${-1}"
|
||||||
|
).replace(
|
||||||
|
"{${Constants.FOLDER_ID}}",
|
||||||
|
"$id"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
backgroundColor = MaterialTheme.colors.primary,
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
modifier = Modifier.size(25.dp),
|
||||||
|
painter = painterResource(R.drawable.ic_add),
|
||||||
|
contentDescription = stringResource(R.string.add_note),
|
||||||
|
tint = Color.White
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) { _ ->
|
||||||
|
if (uiState.noteView == ItemView.LIST) {
|
||||||
|
LazyColumn(
|
||||||
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
contentPadding = PaddingValues(
|
||||||
|
top = 12.dp,
|
||||||
|
bottom = 24.dp,
|
||||||
|
start = 12.dp,
|
||||||
|
end = 12.dp
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
items(uiState.folderNotes, key = { it.id }) { note ->
|
||||||
|
NoteItem(
|
||||||
|
note = note,
|
||||||
|
onClick = {
|
||||||
|
navController.navigate(
|
||||||
|
Screen.NoteDetailsScreen.route.replace(
|
||||||
|
"{${Constants.NOTE_ID_ARG}}",
|
||||||
|
"${note.id}"
|
||||||
|
).replace(
|
||||||
|
"{${Constants.FOLDER_ID}}",
|
||||||
|
"-1"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LazyVerticalGrid(
|
||||||
|
columns = GridCells.Adaptive(150.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
contentPadding = PaddingValues(
|
||||||
|
top = 12.dp,
|
||||||
|
bottom = 24.dp,
|
||||||
|
start = 12.dp,
|
||||||
|
end = 12.dp
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
items(uiState.folderNotes) { note ->
|
||||||
|
key(note.id) {
|
||||||
|
NoteItem(
|
||||||
|
note = note,
|
||||||
|
onClick = {
|
||||||
|
navController.navigate(
|
||||||
|
Screen.NoteDetailsScreen.route.replace(
|
||||||
|
"{${Constants.NOTE_ID_ARG}}",
|
||||||
|
"${note.id}"
|
||||||
|
).replace(
|
||||||
|
"{${Constants.FOLDER_ID}}",
|
||||||
|
"-1"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = Modifier.animateItemPlacement().height(220.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (openDeleteDialog)
|
||||||
|
AlertDialog(
|
||||||
|
shape = RoundedCornerShape(25.dp),
|
||||||
|
onDismissRequest = { openDeleteDialog = false },
|
||||||
|
title = { Text(stringResource(R.string.delete_note_confirmation_title)) },
|
||||||
|
text = {
|
||||||
|
Text(
|
||||||
|
stringResource(
|
||||||
|
R.string.delete_folder_confirmation_message,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
Button(
|
||||||
|
colors = ButtonDefaults.buttonColors(backgroundColor = Color.Red),
|
||||||
|
shape = RoundedCornerShape(25.dp),
|
||||||
|
onClick = {
|
||||||
|
viewModel.onEvent(NoteEvent.DeleteFolder(folder!!))
|
||||||
|
openDeleteDialog = false
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
Text(stringResource(R.string.delete_folder), color = Color.White)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
Button(
|
||||||
|
shape = RoundedCornerShape(25.dp),
|
||||||
|
onClick = {
|
||||||
|
openDeleteDialog = false
|
||||||
|
}) {
|
||||||
|
Text(stringResource(R.string.cancel), color = Color.White)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if (openEditDialog){
|
||||||
|
var name by remember { mutableStateOf(folder?.name ?: "") }
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = { openEditDialog = false },
|
||||||
|
title = {
|
||||||
|
Text(
|
||||||
|
text = stringResource(id = R.string.edit_folder),
|
||||||
|
style = MaterialTheme.typography.h6
|
||||||
|
)
|
||||||
|
},
|
||||||
|
text = {
|
||||||
|
TextField(
|
||||||
|
value = name,
|
||||||
|
onValueChange = { name = it },
|
||||||
|
label = {
|
||||||
|
Text(
|
||||||
|
text = stringResource(id = R.string.name),
|
||||||
|
style = MaterialTheme.typography.body1
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
Button(
|
||||||
|
shape = RoundedCornerShape(25.dp),
|
||||||
|
onClick = {
|
||||||
|
viewModel.onEvent(NoteEvent.UpdateFolder(folder?.copy(name = name)!!))
|
||||||
|
openEditDialog = false
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
Text(stringResource(R.string.save), color = Color.White)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(
|
||||||
|
shape = RoundedCornerShape(25.dp),
|
||||||
|
onClick = { openEditDialog = false },
|
||||||
|
) {
|
||||||
|
Text(stringResource(R.string.cancel), color = Color.White)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.notes
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.repository.NoteRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class SearchNotesUseCase @Inject constructor(
|
||||||
|
private val notesRepository: NoteRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(query: String) = notesRepository.searchNotes(query)
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.notes
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.NoteFolder
|
||||||
|
import com.mhss.app.mybrain.domain.repository.NoteRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class UpdateNoteFolderUseCass @Inject constructor(
|
||||||
|
private val noteRepository: NoteRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(folder: NoteFolder) = noteRepository.updateNoteFolder(folder)
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.notes
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.Note
|
||||||
|
import com.mhss.app.mybrain.domain.repository.NoteRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class UpdateNoteUseCase @Inject constructor(
|
||||||
|
private val notesRepository: NoteRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(note: Note) = notesRepository.updateNote(note)
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.settings
|
||||||
|
|
||||||
|
import androidx.datastore.preferences.core.Preferences
|
||||||
|
import com.mhss.app.mybrain.domain.repository.SettingsRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class GetSettingsUseCase @Inject constructor(
|
||||||
|
private val settingsRepository: SettingsRepository
|
||||||
|
) {
|
||||||
|
operator fun <T> invoke(key: Preferences.Key<T>, defaultValue: T) = settingsRepository.getSettings(key, defaultValue)
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.settings
|
||||||
|
|
||||||
|
import androidx.datastore.preferences.core.Preferences
|
||||||
|
import com.mhss.app.mybrain.domain.repository.SettingsRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class SaveSettingsUseCase @Inject constructor(
|
||||||
|
private val settingsRepository: SettingsRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun <T> invoke(key: Preferences.Key<T>, value: T) = settingsRepository.saveSettings(key, value)
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.tasks
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.activity.ComponentActivity
|
||||||
|
import androidx.activity.viewModels
|
||||||
|
import com.mhss.app.mybrain.R
|
||||||
|
import com.mhss.app.mybrain.domain.model.Task
|
||||||
|
import com.mhss.app.mybrain.presentation.tasks.TaskEvent
|
||||||
|
import com.mhss.app.mybrain.presentation.tasks.TasksViewModel
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
|
||||||
|
@AndroidEntryPoint
|
||||||
|
class AddTaskFromShareActivity : ComponentActivity() {
|
||||||
|
|
||||||
|
private val viewModel: TasksViewModel by viewModels()
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
if (intent != null) {
|
||||||
|
if (intent.action == Intent.ACTION_SEND && intent.type == "text/plain") {
|
||||||
|
val title = intent.getStringExtra(Intent.EXTRA_TEXT)
|
||||||
|
if (!title.isNullOrBlank()) {
|
||||||
|
viewModel.onEvent(
|
||||||
|
TaskEvent.AddTask(
|
||||||
|
Task(
|
||||||
|
title = title,
|
||||||
|
createdDate = System.currentTimeMillis(),
|
||||||
|
updatedDate = System.currentTimeMillis()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
Toast.makeText(this, getString(R.string.added_task), Toast.LENGTH_SHORT)
|
||||||
|
.show()
|
||||||
|
} else
|
||||||
|
Toast.makeText(this, getString(R.string.error_empty_title), Toast.LENGTH_SHORT)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.tasks
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.Task
|
||||||
|
import com.mhss.app.mybrain.domain.repository.TaskRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class AddTaskUseCase @Inject constructor(
|
||||||
|
private val tasksRepository: TaskRepository,
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(task: Task): Long {
|
||||||
|
return tasksRepository.insertTask(task)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.tasks
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.Task
|
||||||
|
import com.mhss.app.mybrain.domain.repository.TaskRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class DeleteTaskUseCase @Inject constructor(
|
||||||
|
private val taskRepository: TaskRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(task: Task) {
|
||||||
|
taskRepository.deleteTask(task)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.tasks
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.Task
|
||||||
|
import com.mhss.app.mybrain.domain.repository.TaskRepository
|
||||||
|
import com.mhss.app.mybrain.util.settings.Order
|
||||||
|
import com.mhss.app.mybrain.util.settings.OrderType
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class GetAllTasksUseCase @Inject constructor(
|
||||||
|
private val tasksRepository: TaskRepository
|
||||||
|
) {
|
||||||
|
operator fun invoke(order: Order, showCompleted: Boolean = true): Flow<List<Task>> {
|
||||||
|
return tasksRepository.getAllTasks().map { tasks ->
|
||||||
|
when (order.orderType) {
|
||||||
|
is OrderType.ASC -> {
|
||||||
|
when (order) {
|
||||||
|
is Order.Alphabetical -> tasks.sortedBy { it.title }
|
||||||
|
is Order.DateCreated -> tasks.sortedBy { it.createdDate }
|
||||||
|
is Order.DateModified -> tasks.sortedBy { it.updatedDate }
|
||||||
|
is Order.Priority -> tasks.sortedBy { it.priority }
|
||||||
|
is Order.DueDate -> tasks.sortedWith(compareBy({ it.dueDate == 0L }, { it.dueDate }))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is OrderType.DESC -> {
|
||||||
|
when (order) {
|
||||||
|
is Order.Alphabetical -> tasks.sortedByDescending { it.title }
|
||||||
|
is Order.DateCreated -> tasks.sortedByDescending { it.createdDate }
|
||||||
|
is Order.DateModified -> tasks.sortedByDescending { it.updatedDate }
|
||||||
|
is Order.Priority -> tasks.sortedByDescending { it.priority }
|
||||||
|
is Order.DueDate -> tasks.sortedWith(compareBy({ it.dueDate == 0L }, { it.dueDate })).reversed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.map { list ->
|
||||||
|
if (showCompleted)
|
||||||
|
list
|
||||||
|
else
|
||||||
|
list.filter { !it.isCompleted }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.tasks
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.repository.TaskRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class GetTaskByIdUseCase @Inject constructor(
|
||||||
|
private val tasksRepository: TaskRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(id: Int) = tasksRepository.getTaskById(id)
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.tasks
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.Task
|
||||||
|
import com.mhss.app.mybrain.domain.repository.TaskRepository
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class SearchTasksUseCase @Inject constructor(
|
||||||
|
private val tasksRepository: TaskRepository
|
||||||
|
) {
|
||||||
|
operator fun invoke(query: String): Flow<List<Task>> {
|
||||||
|
return tasksRepository.searchTasks(query)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.tasks
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.repository.TaskRepository
|
||||||
|
import com.mhss.app.mybrain.domain.use_case.alarm.DeleteAlarmUseCase
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class UpdateTaskCompletedUseCase @Inject constructor(
|
||||||
|
private val tasksRepository: TaskRepository,
|
||||||
|
private val deleteAlarm: DeleteAlarmUseCase,
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(taskId: Int, completed: Boolean) {
|
||||||
|
tasksRepository.completeTask(taskId, completed)
|
||||||
|
if (completed) {
|
||||||
|
deleteAlarm(taskId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.mhss.app.mybrain.domain.use_case.tasks
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.Task
|
||||||
|
import com.mhss.app.mybrain.domain.repository.TaskRepository
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class UpdateTaskUseCase @Inject constructor(
|
||||||
|
private val tasksRepository: TaskRepository
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(task: Task) {
|
||||||
|
tasksRepository.updateTask(task)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,239 @@
|
||||||
|
package com.mhss.app.mybrain.presentation.bookmarks
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import androidx.activity.compose.BackHandler
|
||||||
|
import androidx.compose.foundation.layout.*
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material.*
|
||||||
|
import androidx.compose.runtime.*
|
||||||
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
|
import androidx.navigation.NavHostController
|
||||||
|
import com.mhss.app.mybrain.R
|
||||||
|
import com.mhss.app.mybrain.domain.model.Bookmark
|
||||||
|
import com.mhss.app.mybrain.presentation.util.Screen
|
||||||
|
import com.mhss.app.mybrain.util.bookmarks.isValidUrl
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun BookmarkDetailsScreen(
|
||||||
|
navController: NavHostController,
|
||||||
|
bookmarkId: Int,
|
||||||
|
viewModel: BookmarksViewModel = hiltViewModel()
|
||||||
|
) {
|
||||||
|
LaunchedEffect(true) {
|
||||||
|
if (bookmarkId != -1) {
|
||||||
|
viewModel.onEvent(BookmarkEvent.GetBookmark(bookmarkId))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val state = viewModel.uiState
|
||||||
|
val scaffoldState = rememberScaffoldState()
|
||||||
|
var openDialog by rememberSaveable { mutableStateOf(false) }
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
var title by rememberSaveable { mutableStateOf(state.bookmark?.title ?: "") }
|
||||||
|
var description by rememberSaveable { mutableStateOf(state.bookmark?.description ?: "") }
|
||||||
|
var url by rememberSaveable { mutableStateOf(state.bookmark?.url ?: "") }
|
||||||
|
|
||||||
|
LaunchedEffect(state.bookmark) {
|
||||||
|
if (state.bookmark != null) {
|
||||||
|
title = state.bookmark.title
|
||||||
|
description = state.bookmark.description
|
||||||
|
url = state.bookmark.url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LaunchedEffect(state) {
|
||||||
|
if (state.navigateUp) {
|
||||||
|
openDialog = false
|
||||||
|
navController.popBackStack(route = Screen.BookmarksScreen.route, inclusive = false)
|
||||||
|
}
|
||||||
|
if (state.error != null) {
|
||||||
|
scaffoldState.snackbarHostState.showSnackbar(
|
||||||
|
state.error
|
||||||
|
)
|
||||||
|
viewModel.onEvent(BookmarkEvent.ErrorDisplayed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BackHandler {
|
||||||
|
addOrUpdateBookmark(
|
||||||
|
Bookmark(
|
||||||
|
title = title,
|
||||||
|
description = description,
|
||||||
|
url = url
|
||||||
|
),
|
||||||
|
state.bookmark,
|
||||||
|
onNotChanged = {
|
||||||
|
navController.popBackStack(
|
||||||
|
route = Screen.BookmarksScreen.route,
|
||||||
|
inclusive = false
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onUpdate = {
|
||||||
|
if (state.bookmark != null) {
|
||||||
|
viewModel.onEvent(
|
||||||
|
BookmarkEvent.UpdateBookmark(
|
||||||
|
state.bookmark.copy(
|
||||||
|
title = title,
|
||||||
|
description = description,
|
||||||
|
url = url
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
viewModel.onEvent(
|
||||||
|
BookmarkEvent.AddBookmark(
|
||||||
|
Bookmark(
|
||||||
|
title = title,
|
||||||
|
description = description,
|
||||||
|
url = url
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Scaffold(
|
||||||
|
scaffoldState = scaffoldState,
|
||||||
|
topBar = {
|
||||||
|
TopAppBar(
|
||||||
|
title = {},
|
||||||
|
actions = {
|
||||||
|
if (state.bookmark != null) IconButton(onClick = { openDialog = true }) {
|
||||||
|
Icon(
|
||||||
|
painter = painterResource(id = R.drawable.ic_delete),
|
||||||
|
contentDescription = stringResource(R.string.delete_bookmark)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (url.isValidUrl())
|
||||||
|
IconButton(onClick = {
|
||||||
|
val intent = Intent(Intent.ACTION_VIEW)
|
||||||
|
intent.data = Uri.parse(if (!url.startsWith("http://") && !url.startsWith("https://")) "http://$url" else url)
|
||||||
|
context.startActivity(intent)
|
||||||
|
}) {
|
||||||
|
Icon(
|
||||||
|
painter = painterResource(id = R.drawable.ic_open_link),
|
||||||
|
contentDescription = stringResource(R.string.open_link),
|
||||||
|
modifier = Modifier.size(24.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
backgroundColor = MaterialTheme.colors.background,
|
||||||
|
elevation = 0.dp,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(12.dp)
|
||||||
|
) {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = url,
|
||||||
|
onValueChange = { url = it },
|
||||||
|
label = { Text(text = stringResource(R.string.url)) },
|
||||||
|
shape = RoundedCornerShape(15.dp),
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
)
|
||||||
|
Spacer(Modifier.height(8.dp))
|
||||||
|
OutlinedTextField(
|
||||||
|
value = title,
|
||||||
|
onValueChange = { title = it },
|
||||||
|
label = { Text(text = stringResource(R.string.title)) },
|
||||||
|
shape = RoundedCornerShape(15.dp),
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
)
|
||||||
|
Spacer(Modifier.height(8.dp))
|
||||||
|
OutlinedTextField(
|
||||||
|
value = description,
|
||||||
|
onValueChange = { description = it },
|
||||||
|
label = { Text(text = stringResource(R.string.description)) },
|
||||||
|
shape = RoundedCornerShape(15.dp),
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
)
|
||||||
|
Spacer(Modifier.height(8.dp))
|
||||||
|
TextButton(
|
||||||
|
onClick = {
|
||||||
|
if (state.bookmark != null)
|
||||||
|
url = state.bookmark.url
|
||||||
|
else navController.popBackStack(
|
||||||
|
route = Screen.BookmarksScreen.route,
|
||||||
|
inclusive = false
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = Modifier.align(Alignment.End)
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = if (state.bookmark != null) stringResource(R.string.cancel_changes)
|
||||||
|
else stringResource(R.string.cancel)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (openDialog)
|
||||||
|
AlertDialog(
|
||||||
|
shape = RoundedCornerShape(25.dp),
|
||||||
|
onDismissRequest = { openDialog = false },
|
||||||
|
title = { Text(stringResource(R.string.delete_bookmark_confirmation_title)) },
|
||||||
|
text = {
|
||||||
|
Text(
|
||||||
|
stringResource(
|
||||||
|
R.string.delete_bookmark_confirmation_message
|
||||||
|
)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
Button(
|
||||||
|
colors = ButtonDefaults.buttonColors(backgroundColor = Color.Red),
|
||||||
|
shape = RoundedCornerShape(25.dp),
|
||||||
|
onClick = {
|
||||||
|
viewModel.onEvent(BookmarkEvent.DeleteBookmark(state.bookmark!!))
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
Text(stringResource(R.string.delete_bookmark), color = Color.White)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
Button(
|
||||||
|
shape = RoundedCornerShape(25.dp),
|
||||||
|
onClick = {
|
||||||
|
openDialog = false
|
||||||
|
}) {
|
||||||
|
Text(stringResource(R.string.cancel), color = Color.White)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addOrUpdateBookmark(
|
||||||
|
newBookmark: Bookmark,
|
||||||
|
bookmark: Bookmark? = null,
|
||||||
|
onNotChanged: () -> Unit = {},
|
||||||
|
onUpdate: (Bookmark) -> Unit,
|
||||||
|
) {
|
||||||
|
if (bookmark != null) {
|
||||||
|
if (bookmarkChanged(newBookmark, bookmark))
|
||||||
|
onUpdate(bookmark)
|
||||||
|
else
|
||||||
|
onNotChanged()
|
||||||
|
} else {
|
||||||
|
onUpdate(newBookmark)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun bookmarkChanged(
|
||||||
|
bookmark: Bookmark,
|
||||||
|
newBookmark: Bookmark
|
||||||
|
): Boolean {
|
||||||
|
return bookmark.title != newBookmark.title ||
|
||||||
|
bookmark.description != newBookmark.description ||
|
||||||
|
bookmark.url != newBookmark.url
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.mhss.app.mybrain.presentation.bookmarks
|
||||||
|
|
||||||
|
import com.mhss.app.mybrain.domain.model.Bookmark
|
||||||
|
import com.mhss.app.mybrain.util.settings.ItemView
|
||||||
|
import com.mhss.app.mybrain.util.settings.Order
|
||||||
|
|
||||||
|
sealed class BookmarkEvent {
|
||||||
|
data class AddBookmark(val bookmark: Bookmark) : BookmarkEvent()
|
||||||
|
data class GetBookmark(val bookmarkId: Int) : BookmarkEvent()
|
||||||
|
data class SearchBookmarks(val query: String) : BookmarkEvent()
|
||||||
|
data class UpdateOrder(val order: Order) : BookmarkEvent()
|
||||||
|
data class UpdateView(val view: ItemView) : BookmarkEvent()
|
||||||
|
data class UpdateBookmark(val bookmark: Bookmark) : BookmarkEvent()
|
||||||
|
data class DeleteBookmark(val bookmark: Bookmark) : BookmarkEvent()
|
||||||
|
object ErrorDisplayed: BookmarkEvent()
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
package com.mhss.app.mybrain.presentation.bookmarks
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.*
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material.*
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.mhss.app.mybrain.R
|
||||||
|
import com.mhss.app.mybrain.domain.model.Bookmark
|
||||||
|
import com.mhss.app.mybrain.util.bookmarks.isValidUrl
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun BookmarkItem(
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
bookmark: Bookmark,
|
||||||
|
onClick: (Bookmark) -> Unit,
|
||||||
|
onInvalidUrl: () -> Unit
|
||||||
|
) {
|
||||||
|
Card(
|
||||||
|
modifier = modifier,
|
||||||
|
shape = RoundedCornerShape(20.dp),
|
||||||
|
elevation = 8.dp
|
||||||
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.clickable { onClick(bookmark) }
|
||||||
|
.padding(12.dp)
|
||||||
|
.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
if (bookmark.title.isNotBlank()){
|
||||||
|
Text(
|
||||||
|
bookmark.title,
|
||||||
|
style = MaterialTheme.typography.body1.copy(fontWeight = FontWeight.Bold),
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis
|
||||||
|
)
|
||||||
|
Spacer(Modifier.height(8.dp))
|
||||||
|
}
|
||||||
|
Row {
|
||||||
|
|
||||||
|
}
|
||||||
|
Text(
|
||||||
|
bookmark.url,
|
||||||
|
style = MaterialTheme.typography.body1.copy(fontWeight = FontWeight.Bold),
|
||||||
|
color = Color.Gray
|
||||||
|
)
|
||||||
|
IconButton(
|
||||||
|
onClick = {
|
||||||
|
if (bookmark.url.isValidUrl()){
|
||||||
|
val intent = Intent(Intent.ACTION_VIEW)
|
||||||
|
intent.data = Uri.parse(if (!bookmark.url.startsWith("http://") && !bookmark.url.startsWith("https://")) "http://${bookmark.url}" else bookmark.url)
|
||||||
|
context.startActivity(intent)
|
||||||
|
} else
|
||||||
|
onInvalidUrl()
|
||||||
|
},
|
||||||
|
modifier = Modifier.align(Alignment.End)
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
painterResource(id = R.drawable.ic_open_link),
|
||||||
|
stringResource(id = R.string.open_link)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,120 @@
|
||||||
|
package com.mhss.app.mybrain.presentation.bookmarks
|
||||||
|
|
||||||
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
|
import androidx.compose.foundation.layout.*
|
||||||
|
import androidx.compose.foundation.lazy.grid.GridCells
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||||
|
import androidx.compose.foundation.lazy.grid.items
|
||||||
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material.OutlinedTextField
|
||||||
|
import androidx.compose.material.Scaffold
|
||||||
|
import androidx.compose.material.Text
|
||||||
|
import androidx.compose.material.rememberScaffoldState
|
||||||
|
import androidx.compose.runtime.*
|
||||||
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
|
import androidx.compose.ui.focus.focusRequester
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
|
import androidx.navigation.NavHostController
|
||||||
|
import com.mhss.app.mybrain.R
|
||||||
|
import com.mhss.app.mybrain.app.getString
|
||||||
|
import com.mhss.app.mybrain.presentation.util.Screen
|
||||||
|
import com.mhss.app.mybrain.util.Constants
|
||||||
|
import com.mhss.app.mybrain.util.settings.ItemView
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
|
@Composable
|
||||||
|
fun BookmarkSearchScreen(
|
||||||
|
navController: NavHostController,
|
||||||
|
viewModel: BookmarksViewModel = hiltViewModel()
|
||||||
|
) {
|
||||||
|
val state = viewModel.uiState
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
|
val scaffoldState = rememberScaffoldState()
|
||||||
|
Scaffold(scaffoldState = scaffoldState) { paddingValues ->
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.fillMaxSize().padding(paddingValues),
|
||||||
|
) {
|
||||||
|
var query by rememberSaveable {
|
||||||
|
mutableStateOf("")
|
||||||
|
}
|
||||||
|
LaunchedEffect(query){viewModel.onEvent(BookmarkEvent.SearchBookmarks(query))}
|
||||||
|
val focusRequester = remember { FocusRequester() }
|
||||||
|
LaunchedEffect(true){focusRequester.requestFocus()}
|
||||||
|
OutlinedTextField(
|
||||||
|
value = query,
|
||||||
|
onValueChange = {query = it},
|
||||||
|
label = { Text(stringResource(R.string.search_bookmarks)) },
|
||||||
|
shape = RoundedCornerShape(15.dp),
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp)
|
||||||
|
.focusRequester(focusRequester)
|
||||||
|
)
|
||||||
|
if (state.bookmarksView == ItemView.LIST){
|
||||||
|
LazyColumn(
|
||||||
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
contentPadding = PaddingValues(12.dp)
|
||||||
|
) {
|
||||||
|
items(state.searchBookmarks, key = {it.id}) { bookmark ->
|
||||||
|
BookmarkItem(
|
||||||
|
bookmark = bookmark,
|
||||||
|
onClick = {
|
||||||
|
navController.navigate(
|
||||||
|
Screen.BookmarkDetailScreen.route.replace(
|
||||||
|
"{${Constants.BOOKMARK_ID_ARG}}",
|
||||||
|
"${bookmark.id}"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onInvalidUrl = {
|
||||||
|
scope.launch {
|
||||||
|
scaffoldState.snackbarHostState.showSnackbar(
|
||||||
|
getString(R.string.invalid_url)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LazyVerticalGrid(
|
||||||
|
columns = GridCells.Adaptive(150.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
contentPadding = PaddingValues(12.dp)
|
||||||
|
){
|
||||||
|
items(state.searchBookmarks){ bookmark ->
|
||||||
|
key(bookmark.id) {
|
||||||
|
BookmarkItem(
|
||||||
|
bookmark = bookmark,
|
||||||
|
onClick = {
|
||||||
|
navController.navigate(
|
||||||
|
Screen.BookmarkDetailScreen.route.replace(
|
||||||
|
"{${Constants.BOOKMARK_ID_ARG}}",
|
||||||
|
"${bookmark.id}"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onInvalidUrl = {
|
||||||
|
scope.launch {
|
||||||
|
scaffoldState.snackbarHostState.showSnackbar(
|
||||||
|
getString(R.string.invalid_url)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modifier = Modifier.animateItemPlacement()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,292 @@
|
||||||
|
package com.mhss.app.mybrain.presentation.bookmarks
|
||||||
|
|
||||||
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
|
import androidx.compose.foundation.Image
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.layout.*
|
||||||
|
import androidx.compose.foundation.lazy.grid.GridCells
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||||
|
import androidx.compose.foundation.lazy.grid.items
|
||||||
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.material.*
|
||||||
|
import androidx.compose.runtime.*
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
|
import androidx.navigation.NavHostController
|
||||||
|
import com.google.accompanist.flowlayout.FlowRow
|
||||||
|
import com.mhss.app.mybrain.R
|
||||||
|
import com.mhss.app.mybrain.presentation.util.Screen
|
||||||
|
import com.mhss.app.mybrain.util.Constants
|
||||||
|
import com.mhss.app.mybrain.util.settings.ItemView
|
||||||
|
import com.mhss.app.mybrain.util.settings.Order
|
||||||
|
import com.mhss.app.mybrain.util.settings.OrderType
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import com.mhss.app.mybrain.app.getString
|
||||||
|
|
||||||
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
|
@Composable
|
||||||
|
fun BookmarksScreen(
|
||||||
|
navController: NavHostController,
|
||||||
|
viewModel: BookmarksViewModel = hiltViewModel()
|
||||||
|
) {
|
||||||
|
val uiState = viewModel.uiState
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
|
val scaffoldState = rememberScaffoldState()
|
||||||
|
var orderSettingsVisible by remember { mutableStateOf(false) }
|
||||||
|
Scaffold(
|
||||||
|
scaffoldState = scaffoldState,
|
||||||
|
topBar = {
|
||||||
|
TopAppBar(
|
||||||
|
title = {
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.bookmarks),
|
||||||
|
style = MaterialTheme.typography.h5.copy(fontWeight = FontWeight.Bold)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
backgroundColor = MaterialTheme.colors.background,
|
||||||
|
elevation = 0.dp,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
floatingActionButton = {
|
||||||
|
FloatingActionButton(
|
||||||
|
onClick = {
|
||||||
|
navController.navigate(
|
||||||
|
Screen.BookmarkDetailScreen.route.replace(
|
||||||
|
"{${Constants.BOOKMARK_ID_ARG}}",
|
||||||
|
"${-1}"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
backgroundColor = MaterialTheme.colors.primary,
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
modifier = Modifier.size(25.dp),
|
||||||
|
painter = painterResource(R.drawable.ic_add),
|
||||||
|
contentDescription = stringResource(R.string.add_bookmark),
|
||||||
|
tint = Color.White
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
) { paddingValues ->
|
||||||
|
if (uiState.bookmarks.isEmpty())
|
||||||
|
NoBookmarksMessage()
|
||||||
|
Column {
|
||||||
|
Row(
|
||||||
|
Modifier.fillMaxWidth().padding(paddingValues),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween
|
||||||
|
) {
|
||||||
|
IconButton(onClick = { orderSettingsVisible = !orderSettingsVisible }) {
|
||||||
|
Icon(
|
||||||
|
modifier = Modifier.size(25.dp),
|
||||||
|
painter = painterResource(R.drawable.ic_settings_sliders),
|
||||||
|
contentDescription = stringResource(R.string.order_by)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
IconButton(onClick = {
|
||||||
|
navController.navigate(Screen.BookmarkSearchScreen.route)
|
||||||
|
}) {
|
||||||
|
Icon(
|
||||||
|
modifier = Modifier.size(25.dp),
|
||||||
|
painter = painterResource(id = R.drawable.ic_search),
|
||||||
|
contentDescription = stringResource(R.string.search)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AnimatedVisibility(visible = orderSettingsVisible) {
|
||||||
|
BookmarksSettingsSection(
|
||||||
|
uiState.bookmarksOrder,
|
||||||
|
uiState.bookmarksView,
|
||||||
|
onOrderChange = {
|
||||||
|
viewModel.onEvent(BookmarkEvent.UpdateOrder(it))
|
||||||
|
},
|
||||||
|
onViewChange = {
|
||||||
|
viewModel.onEvent(BookmarkEvent.UpdateView(it))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (uiState.bookmarksView == ItemView.LIST) {
|
||||||
|
LazyColumn(
|
||||||
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
contentPadding = PaddingValues(12.dp)
|
||||||
|
) {
|
||||||
|
items(uiState.bookmarks, key = { it.id }) { bookmark ->
|
||||||
|
BookmarkItem(
|
||||||
|
bookmark = bookmark,
|
||||||
|
onClick = {
|
||||||
|
navController.navigate(
|
||||||
|
Screen.BookmarkDetailScreen.route.replace(
|
||||||
|
"{${Constants.BOOKMARK_ID_ARG}}",
|
||||||
|
"${bookmark.id}"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onInvalidUrl = {
|
||||||
|
scope.launch {
|
||||||
|
scaffoldState.snackbarHostState.showSnackbar(
|
||||||
|
getString(R.string.invalid_url)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modifier = Modifier.animateItemPlacement()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LazyVerticalGrid(
|
||||||
|
columns = GridCells.Adaptive(150.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
contentPadding = PaddingValues(12.dp)
|
||||||
|
) {
|
||||||
|
items(uiState.bookmarks) { bookmark ->
|
||||||
|
key(bookmark.id) {
|
||||||
|
BookmarkItem(
|
||||||
|
bookmark = bookmark,
|
||||||
|
onClick = {
|
||||||
|
navController.navigate(
|
||||||
|
Screen.BookmarkDetailScreen.route.replace(
|
||||||
|
"{${Constants.BOOKMARK_ID_ARG}}",
|
||||||
|
"${bookmark.id}"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onInvalidUrl = {
|
||||||
|
scope.launch {
|
||||||
|
scaffoldState.snackbarHostState.showSnackbar(
|
||||||
|
getString(R.string.invalid_url)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modifier = Modifier.animateItemPlacement().height(220.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun BookmarksSettingsSection(
|
||||||
|
order: Order,
|
||||||
|
view: ItemView,
|
||||||
|
onOrderChange: (Order) -> Unit,
|
||||||
|
onViewChange: (ItemView) -> Unit
|
||||||
|
) {
|
||||||
|
val orders = listOf(
|
||||||
|
Order.DateModified(),
|
||||||
|
Order.DateCreated(),
|
||||||
|
Order.Alphabetical()
|
||||||
|
)
|
||||||
|
val orderTypes = listOf(
|
||||||
|
OrderType.ASC(),
|
||||||
|
OrderType.DESC()
|
||||||
|
)
|
||||||
|
val views = listOf(
|
||||||
|
ItemView.LIST,
|
||||||
|
ItemView.GRID
|
||||||
|
)
|
||||||
|
Column(
|
||||||
|
Modifier.background(color = MaterialTheme.colors.background)
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.order_by),
|
||||||
|
style = MaterialTheme.typography.body1,
|
||||||
|
modifier = Modifier.padding(start = 8.dp)
|
||||||
|
)
|
||||||
|
FlowRow(
|
||||||
|
modifier = Modifier.padding(end = 8.dp)
|
||||||
|
) {
|
||||||
|
orders.forEach {
|
||||||
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
|
RadioButton(
|
||||||
|
selected = order.orderTitle == it.orderTitle,
|
||||||
|
onClick = {
|
||||||
|
if (order.orderTitle != it.orderTitle)
|
||||||
|
onOrderChange(
|
||||||
|
it.copy(orderType = order.orderType)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
Text(text = it.orderTitle, style = MaterialTheme.typography.body1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Divider()
|
||||||
|
FlowRow {
|
||||||
|
orderTypes.forEach {
|
||||||
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
|
RadioButton(
|
||||||
|
selected = order.orderType.orderTitle == it.orderTitle,
|
||||||
|
onClick = {
|
||||||
|
if (order.orderTitle != it.orderTitle)
|
||||||
|
onOrderChange(
|
||||||
|
order.copy(it)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.width(4.dp))
|
||||||
|
Text(text = it.orderTitle, style = MaterialTheme.typography.body1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Divider()
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.view_as),
|
||||||
|
style = MaterialTheme.typography.body1,
|
||||||
|
modifier = Modifier.padding(start = 8.dp, top = 8.dp)
|
||||||
|
)
|
||||||
|
FlowRow {
|
||||||
|
views.forEach {
|
||||||
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
|
RadioButton(
|
||||||
|
selected = view.title == it.title,
|
||||||
|
onClick = {
|
||||||
|
if (view.title != it.title)
|
||||||
|
onViewChange(
|
||||||
|
it
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.width(4.dp))
|
||||||
|
Text(text = stringResource(it.title), style = MaterialTheme.typography.body1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Spacer(Modifier.height(8.dp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun NoBookmarksMessage() {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.Center
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.no_bookmarks_message),
|
||||||
|
style = MaterialTheme.typography.body1.copy(fontWeight = FontWeight.Bold),
|
||||||
|
color = Color.Gray,
|
||||||
|
textAlign = TextAlign.Center
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
|
Image(
|
||||||
|
modifier = Modifier.size(125.dp),
|
||||||
|
painter = painterResource(id = R.drawable.bookmarks_img),
|
||||||
|
contentDescription = stringResource(R.string.no_bookmarks_message),
|
||||||
|
alpha = 0.7f
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,139 @@
|
||||||
|
package com.mhss.app.mybrain.presentation.bookmarks
|
||||||
|
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.datastore.preferences.core.intPreferencesKey
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import com.mhss.app.mybrain.R
|
||||||
|
import com.mhss.app.mybrain.app.getString
|
||||||
|
import com.mhss.app.mybrain.domain.model.Bookmark
|
||||||
|
import com.mhss.app.mybrain.domain.use_case.bookmarks.*
|
||||||
|
import com.mhss.app.mybrain.domain.use_case.settings.GetSettingsUseCase
|
||||||
|
import com.mhss.app.mybrain.domain.use_case.settings.SaveSettingsUseCase
|
||||||
|
import com.mhss.app.mybrain.util.Constants
|
||||||
|
import com.mhss.app.mybrain.util.bookmarks.isValidUrl
|
||||||
|
import com.mhss.app.mybrain.util.settings.*
|
||||||
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.flow.collect
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import kotlinx.coroutines.flow.launchIn
|
||||||
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@HiltViewModel
|
||||||
|
class BookmarksViewModel @Inject constructor(
|
||||||
|
private val addBookmark: AddBookmarkUseCase,
|
||||||
|
private val updateBookmark: UpdateBookmarkUseCase,
|
||||||
|
private val deleteBookmark: DeleteBookmarkUseCase,
|
||||||
|
private val getAlBookmarks: GetAllBookmarksUseCase,
|
||||||
|
private val searchBookmarks: SearchBookmarksUseCase,
|
||||||
|
private val getBookmark: GetBookmarkUseCase,
|
||||||
|
getSettings: GetSettingsUseCase,
|
||||||
|
private val saveSettings: SaveSettingsUseCase
|
||||||
|
) : ViewModel() {
|
||||||
|
|
||||||
|
|
||||||
|
var uiState by mutableStateOf(UiState())
|
||||||
|
private set
|
||||||
|
|
||||||
|
private var getBookmarksJob: Job? = null
|
||||||
|
|
||||||
|
init {
|
||||||
|
viewModelScope.launch {
|
||||||
|
combine(
|
||||||
|
getSettings(
|
||||||
|
intPreferencesKey(Constants.BOOKMARK_ORDER_KEY),
|
||||||
|
Order.DateModified(OrderType.ASC()).toInt()
|
||||||
|
),
|
||||||
|
getSettings(
|
||||||
|
intPreferencesKey(Constants.BOOKMARK_VIEW_KEY),
|
||||||
|
ItemView.LIST.value
|
||||||
|
)
|
||||||
|
) { order, view ->
|
||||||
|
uiState = uiState.copy(bookmarksOrder = order.toOrder())
|
||||||
|
getBookmarks(order.toOrder())
|
||||||
|
if (uiState.bookmarksView.value != view) {
|
||||||
|
uiState = uiState.copy(bookmarksView = view.toNotesView())
|
||||||
|
}
|
||||||
|
}.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onEvent(event: BookmarkEvent) {
|
||||||
|
when (event) {
|
||||||
|
is BookmarkEvent.AddBookmark -> viewModelScope.launch {
|
||||||
|
uiState = if (
|
||||||
|
event.bookmark.url.isBlank()
|
||||||
|
&& event.bookmark.title.isBlank()
|
||||||
|
&& event.bookmark.description.isBlank()
|
||||||
|
)
|
||||||
|
uiState.copy(navigateUp = true)
|
||||||
|
else {
|
||||||
|
if (event.bookmark.url.isValidUrl()) {
|
||||||
|
addBookmark(event.bookmark)
|
||||||
|
uiState.copy(navigateUp = true)
|
||||||
|
} else
|
||||||
|
uiState.copy(error = getString(R.string.invalid_url))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is BookmarkEvent.DeleteBookmark -> viewModelScope.launch {
|
||||||
|
deleteBookmark(event.bookmark)
|
||||||
|
uiState = uiState.copy(navigateUp = true)
|
||||||
|
}
|
||||||
|
is BookmarkEvent.GetBookmark -> viewModelScope.launch {
|
||||||
|
val bookmark = getBookmark(event.bookmarkId)
|
||||||
|
uiState = uiState.copy(bookmark = bookmark)
|
||||||
|
}
|
||||||
|
is BookmarkEvent.SearchBookmarks -> viewModelScope.launch {
|
||||||
|
val bookmarks = searchBookmarks(event.query)
|
||||||
|
uiState = uiState.copy(searchBookmarks = bookmarks)
|
||||||
|
}
|
||||||
|
is BookmarkEvent.UpdateBookmark -> viewModelScope.launch {
|
||||||
|
uiState = if (!event.bookmark.url.isValidUrl()) {
|
||||||
|
uiState.copy(error = getString(R.string.invalid_url))
|
||||||
|
} else {
|
||||||
|
updateBookmark(event.bookmark.copy(updatedDate = System.currentTimeMillis()))
|
||||||
|
uiState.copy(navigateUp = true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is BookmarkEvent.UpdateOrder -> viewModelScope.launch {
|
||||||
|
saveSettings(
|
||||||
|
intPreferencesKey(Constants.BOOKMARK_ORDER_KEY),
|
||||||
|
event.order.toInt()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
is BookmarkEvent.UpdateView -> viewModelScope.launch {
|
||||||
|
saveSettings(
|
||||||
|
intPreferencesKey(Constants.BOOKMARK_VIEW_KEY),
|
||||||
|
event.view.value
|
||||||
|
)
|
||||||
|
}
|
||||||
|
BookmarkEvent.ErrorDisplayed -> uiState = uiState.copy(error = null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class UiState(
|
||||||
|
val bookmarks: List<Bookmark> = emptyList(),
|
||||||
|
val bookmarksOrder: Order = Order.DateModified(OrderType.ASC()),
|
||||||
|
val bookmarksView: ItemView = ItemView.LIST,
|
||||||
|
val bookmark: Bookmark? = null,
|
||||||
|
val error: String? = null,
|
||||||
|
val searchBookmarks: List<Bookmark> = emptyList(),
|
||||||
|
val navigateUp: Boolean = false
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun getBookmarks(order: Order) {
|
||||||
|
getBookmarksJob?.cancel()
|
||||||
|
getBookmarksJob = getAlBookmarks(order)
|
||||||
|
.onEach { bookmarks ->
|
||||||
|
uiState = uiState.copy(
|
||||||
|
bookmarks = bookmarks,
|
||||||
|
bookmarksOrder = order
|
||||||
|
)
|
||||||
|
}.launchIn(viewModelScope)
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue