-
-
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000000..f288702d2f
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ 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.
+
+
+ Copyright (C)
+
+ 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 .
+
+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:
+
+ Copyright (C)
+ 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
+.
+
+ 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
+.
diff --git a/PRIVACY b/PRIVACY
new file mode 100644
index 0000000000..644cc22a49
--- /dev/null
+++ b/PRIVACY
@@ -0,0 +1,4 @@
+Findroid does not collection any personal data.
+
+Findroid connects to a provided Jellyfin server which may collect some personal data such as IP address and device name.
+This provided Jellyfin server is in most cases owned by the user themselves.
diff --git a/README.md b/README.md
index 622c966688..fc290cd044 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,40 @@
-Jellyfin
+![Findroid banner](images/banner.svg)
+
+# Findroid
+
+Findroid is third-party Android application for Jellyfin that provides a native user interface to browse and play movies and series.
+
+I am developing this application in my spare time.
+
+**This project is in its early stages so expect bugs.**
+
+## Screenshots
+Home | Library | Movie | Season | Episode
+-----|---------|-------|--------|--------
+![Home](images/home-light-dark.png) | ![Library](images/library-dark.png) | ![Movie](images/movie-dark.png) | ![Season](images/season-dark.png) | ![Episode](images/episode-dark.png)
+
+## Features
+- Completely native interface
+- Supported media items: movies, series, seasons, episodes
+ - Direct play only, (no transcoding)
+- Video codes: H.263, H.264, H.265, VP8, VP9, AV1
+ - Support depends on Android device
+- Audio codes: Vorbis, Opus, FLAC, ALAC, PCM µ-law, PCM A-law, MP1, MP2, MP3, AMR-NB, AMR-WB, AAC, AC-3, E-AC-3, DTS, DTS-HD, TrueHD
+ - Support provided by ExoPlayer FFmpeg extension
+- Subtitle codecs: SRT, VTT, SSA/ASS, PGSSUB
+ - SSA/ASS has limited styling support see [this issue](https://github.com/google/ExoPlayer/issues/8435)
+
+## Planned features
+- Websocket connection (Syncplay)
+- Caching
+- Offline playback / downloads
+- Picture in picture mode
+- Chromecast support
+
+This project is licensed under [GPLv3](LICENSE).
+
+The logo is a combination of the Jellyfin logo and the Android robot.
+
+The Android robot is reproduced or modified from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.
+
+Android is a trademark of Google LLC.
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 0bd55296de..fa04e1602d 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,45 +1,111 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
+ id 'kotlin-parcelize'
+ id 'kotlin-kapt'
+ id 'androidx.navigation.safeargs.kotlin'
+ id 'dagger.hilt.android.plugin'
+ id 'com.google.android.gms.oss-licenses-plugin'
}
android {
- compileSdkVersion 30
- buildToolsVersion "30.0.3"
+ compileSdkVersion 31
+ buildToolsVersion "31.0.0"
defaultConfig {
applicationId "dev.jdtech.jellyfin"
minSdkVersion 24
- targetSdkVersion 30
+ targetSdkVersion 31
versionCode 1
- versionName "1.0"
+ versionName "0.1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
- minifyEnabled false
+ minifyEnabled true
+ shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
+
compileOptions {
+ coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
+
kotlinOptions {
jvmTarget = '1.8'
}
+
+ buildFeatures {
+ dataBinding true
+ }
}
dependencies {
+ implementation 'androidx.core:core-ktx:1.6.0'
+ implementation 'androidx.core:core-splashscreen:1.0.0-alpha01'
+ implementation 'androidx.appcompat:appcompat:1.3.1'
+
+ // Material
+ implementation 'com.google.android.material:material:1.4.0'
+
+ // ConstraintLayout
+ implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
+
+ // Navigation
+ def navigation_version = "2.3.5"
+ implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
+ implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"
+
+ // RecyclerView
+ implementation "androidx.recyclerview:recyclerview:1.2.1"
+ implementation "androidx.recyclerview:recyclerview-selection:1.1.0"
+
+ // Room
+ def room_version = "2.3.0"
+ implementation "androidx.room:room-runtime:$room_version"
+ kapt "androidx.room:room-compiler:$room_version"
+ implementation "androidx.room:room-ktx:$room_version"
+
+ // Preference
+ def preference_version = "1.1.1"
+ implementation "androidx.preference:preference-ktx:$preference_version"
+
+ // Jellyfin
+ def jellyfin_version = "1.0.2"
+ implementation "org.jellyfin.sdk:jellyfin-platform-android:$jellyfin_version"
+
+ // Glide
+ def glide_version = "4.12.0"
+ implementation "com.github.bumptech.glide:glide:$glide_version"
+ kapt "com.github.bumptech.glide:compiler:$glide_version"
+
+ // Hilt
+ def hilt_version = "2.38.1"
+ implementation "com.google.dagger:hilt-android:$hilt_version"
+ kapt "com.google.dagger:hilt-compiler:$hilt_version"
+
+ // ExoPlayer
+ def exoplayer_version = "2.15.0"
+ implementation "com.google.android.exoplayer:exoplayer-core:$exoplayer_version"
+ implementation "com.google.android.exoplayer:exoplayer-ui:$exoplayer_version"
+ implementation files('libs/extension-ffmpeg-release.aar')
+
+ // Timber
+ def timber_version = "5.0.0"
+ implementation "com.jakewharton.timber:timber:$timber_version"
+
+ def oss_licenses_version = "17.0.0"
+ implementation "com.google.android.gms:play-services-oss-licenses:$oss_licenses_version"
+
+ // Testing
+ testImplementation 'junit:junit:4.13.2'
+ androidTestImplementation 'androidx.test.ext:junit:1.1.3'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
- implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
- implementation 'androidx.core:core-ktx:1.5.0'
- implementation 'androidx.appcompat:appcompat:1.3.0'
- implementation 'com.google.android.material:material:1.3.0'
- implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
- testImplementation 'junit:junit:4.+'
- androidTestImplementation 'androidx.test.ext:junit:1.1.2'
- androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
+ coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
}
\ No newline at end of file
diff --git a/app/libs/extension-ffmpeg-release.aar b/app/libs/extension-ffmpeg-release.aar
new file mode 100644
index 0000000000..c563cae6b3
Binary files /dev/null and b/app/libs/extension-ffmpeg-release.aar differ
diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro
index 481bb43481..39fc3b6c4b 100644
--- a/app/proguard-rules.pro
+++ b/app/proguard-rules.pro
@@ -18,4 +18,6 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
-#-renamesourcefileattribute SourceFile
\ No newline at end of file
+#-renamesourcefileattribute SourceFile
+
+-keep public class dev.jdtech.jellyfin.models.PlayerItem
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index b8e16895cd..75b71ba443 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -2,20 +2,37 @@
+
+
-
+ android:theme="@style/Theme.Jellyfin"
+ android:usesCleartextTraffic="true">
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/ic_launcher-playstore.png b/app/src/main/ic_launcher-playstore.png
new file mode 100644
index 0000000000..edd0aa1ff6
Binary files /dev/null and b/app/src/main/ic_launcher-playstore.png differ
diff --git a/app/src/main/java/dev/jdtech/jellyfin/BaseApplication.kt b/app/src/main/java/dev/jdtech/jellyfin/BaseApplication.kt
new file mode 100644
index 0000000000..1fbd0f5d4f
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/BaseApplication.kt
@@ -0,0 +1,25 @@
+package dev.jdtech.jellyfin
+
+import android.app.Application
+import androidx.appcompat.app.AppCompatDelegate
+import androidx.preference.PreferenceManager
+import dagger.hilt.android.HiltAndroidApp
+import timber.log.Timber
+
+@HiltAndroidApp
+class BaseApplication : Application() {
+ override fun onCreate() {
+ val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
+
+ when (sharedPreferences.getString("theme", null)) {
+ "system" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
+ "light" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
+ "dark" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
+ }
+
+ super.onCreate()
+ if (BuildConfig.DEBUG) {
+ Timber.plant(Timber.DebugTree())
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/BindingAdapters.kt b/app/src/main/java/dev/jdtech/jellyfin/BindingAdapters.kt
new file mode 100644
index 0000000000..40315453a4
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/BindingAdapters.kt
@@ -0,0 +1,176 @@
+package dev.jdtech.jellyfin
+
+import android.widget.ImageView
+import androidx.databinding.BindingAdapter
+import androidx.recyclerview.widget.RecyclerView
+import com.bumptech.glide.Glide
+import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
+import dev.jdtech.jellyfin.adapters.*
+import dev.jdtech.jellyfin.api.JellyfinApi
+import dev.jdtech.jellyfin.database.Server
+import dev.jdtech.jellyfin.models.FavoriteSection
+import org.jellyfin.sdk.model.api.BaseItemDto
+import org.jellyfin.sdk.model.api.BaseItemPerson
+import java.util.*
+
+@BindingAdapter("servers")
+fun bindServers(recyclerView: RecyclerView, data: List?) {
+ val adapter = recyclerView.adapter as ServerGridAdapter
+ adapter.submitList(data)
+}
+
+@BindingAdapter("views")
+fun bindViews(recyclerView: RecyclerView, data: List?) {
+ val adapter = recyclerView.adapter as ViewListAdapter
+ adapter.submitList(data)
+}
+
+@BindingAdapter("items")
+fun bindItems(recyclerView: RecyclerView, data: List?) {
+ val adapter = recyclerView.adapter as ViewItemListAdapter
+ adapter.submitList(data)
+}
+
+@BindingAdapter("itemImage")
+fun bindItemImage(imageView: ImageView, item: BaseItemDto) {
+ val jellyfinApi = JellyfinApi.getInstance(imageView.context.applicationContext, "")
+
+ val itemId = if (item.type == "Episode") item.seriesId else item.id
+
+ Glide
+ .with(imageView.context)
+ .load(jellyfinApi.api.baseUrl.plus("/items/${itemId}/Images/Primary"))
+ .transition(DrawableTransitionOptions.withCrossFade())
+ .placeholder(R.color.neutral_800)
+ .into(imageView)
+
+ imageView.contentDescription = "${item.name} poster"
+}
+
+@BindingAdapter("itemBackdropImage")
+fun bindItemBackdropImage(imageView: ImageView, item: BaseItemDto?) {
+ if (item != null) {
+ val jellyfinApi = JellyfinApi.getInstance(imageView.context.applicationContext, "")
+
+ Glide
+ .with(imageView.context)
+ .load(jellyfinApi.api.baseUrl.plus("/items/${item.id}/Images/Backdrop"))
+ .transition(DrawableTransitionOptions.withCrossFade())
+ .into(imageView)
+
+ imageView.contentDescription = "${item.name} backdrop"
+ }
+}
+
+@BindingAdapter("itemBackdropById")
+fun bindItemBackdropById(imageView: ImageView, itemId: UUID) {
+ val jellyfinApi = JellyfinApi.getInstance(imageView.context.applicationContext, "")
+
+ Glide
+ .with(imageView.context)
+ .load(jellyfinApi.api.baseUrl.plus("/items/${itemId}/Images/Backdrop"))
+ .transition(DrawableTransitionOptions.withCrossFade())
+ .into(imageView)
+}
+
+@BindingAdapter("collections")
+fun bindCollections(recyclerView: RecyclerView, data: List?) {
+ val adapter = recyclerView.adapter as CollectionListAdapter
+ adapter.submitList(data)
+}
+
+@BindingAdapter("collectionImage")
+fun bindCollectionImage(imageView: ImageView, item: BaseItemDto) {
+ val jellyfinApi = JellyfinApi.getInstance(imageView.context.applicationContext, "")
+
+ Glide
+ .with(imageView.context)
+ .load(jellyfinApi.api.baseUrl.plus("/items/${item.id}/Images/Primary"))
+ .transition(DrawableTransitionOptions.withCrossFade())
+ .placeholder(R.color.neutral_800)
+ .into(imageView)
+
+ imageView.contentDescription = "${item.name} image"
+}
+
+@BindingAdapter("people")
+fun bindPeople(recyclerView: RecyclerView, data: List?) {
+ val adapter = recyclerView.adapter as PersonListAdapter
+ adapter.submitList(data)
+}
+
+@BindingAdapter("personImage")
+fun bindPersonImage(imageView: ImageView, person: BaseItemPerson) {
+ val jellyfinApi = JellyfinApi.getInstance(imageView.context.applicationContext, "")
+
+ Glide
+ .with(imageView.context)
+ .load(jellyfinApi.api.baseUrl.plus("/items/${person.id}/Images/Primary"))
+ .transition(DrawableTransitionOptions.withCrossFade())
+ .placeholder(R.color.neutral_800)
+ .into(imageView)
+
+ imageView.contentDescription = "${person.name} poster"
+}
+
+@BindingAdapter("episodes")
+fun bindEpisodes(recyclerView: RecyclerView, data: List?) {
+ val adapter = recyclerView.adapter as EpisodeListAdapter
+ adapter.submitList(data)
+}
+
+@BindingAdapter("homeEpisodes")
+fun bindHomeEpisodes(recyclerView: RecyclerView, data: List?) {
+ val adapter = recyclerView.adapter as HomeEpisodeListAdapter
+ adapter.submitList(data)
+}
+
+@BindingAdapter("episodeImage")
+fun bindEpisodeImage(imageView: ImageView, episode: BaseItemDto) {
+ val jellyfinApi = JellyfinApi.getInstance(imageView.context.applicationContext, "")
+
+ val imageType = if (episode.type == "Movie") "Backdrop" else "Primary"
+
+ Glide
+ .with(imageView.context)
+ .load(jellyfinApi.api.baseUrl.plus("/items/${episode.id}/Images/$imageType"))
+ .transition(DrawableTransitionOptions.withCrossFade())
+ .placeholder(R.color.neutral_800)
+ .into(imageView)
+
+ imageView.contentDescription = "${episode.name} poster"
+}
+
+@BindingAdapter("seasonPoster")
+fun bindSeasonPoster(imageView: ImageView, seasonId: UUID) {
+ val jellyfinApi = JellyfinApi.getInstance(imageView.context.applicationContext, "")
+
+ Glide
+ .with(imageView.context)
+ .load(jellyfinApi.api.baseUrl.plus("/items/${seasonId}/Images/Primary"))
+ .transition(DrawableTransitionOptions.withCrossFade())
+ .placeholder(R.color.neutral_800)
+ .into(imageView)
+}
+
+@BindingAdapter("itemPrimaryImage")
+fun bindItemPrimaryImage(imageView: ImageView, item: BaseItemDto?) {
+ if (item != null) {
+ val jellyfinApi = JellyfinApi.getInstance(imageView.context.applicationContext, "")
+
+ Glide
+ .with(imageView.context)
+ .load(jellyfinApi.api.baseUrl.plus("/items/${item.id}/Images/Primary"))
+ .transition(DrawableTransitionOptions.withCrossFade())
+ .placeholder(R.color.neutral_800)
+ .into(imageView)
+
+ imageView.contentDescription = "${item.name} poster"
+ }
+}
+
+@BindingAdapter("favoriteSections")
+fun bindFavoriteSections(recyclerView: RecyclerView, data: List?) {
+ val adapter = recyclerView.adapter as FavoritesListAdapter
+ adapter.submitList(data)
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/MainActivity.kt b/app/src/main/java/dev/jdtech/jellyfin/MainActivity.kt
index d138eee5b0..1d74d1154f 100644
--- a/app/src/main/java/dev/jdtech/jellyfin/MainActivity.kt
+++ b/app/src/main/java/dev/jdtech/jellyfin/MainActivity.kt
@@ -1,11 +1,79 @@
package dev.jdtech.jellyfin
-import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
+import android.view.View
+import androidx.activity.viewModels
+import com.google.android.material.bottomnavigation.BottomNavigationView
+import androidx.appcompat.app.AppCompatActivity
+import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
+import androidx.navigation.fragment.NavHostFragment
+import androidx.navigation.ui.AppBarConfiguration
+import androidx.navigation.ui.setupActionBarWithNavController
+import androidx.navigation.ui.setupWithNavController
+import dagger.hilt.android.AndroidEntryPoint
+import dev.jdtech.jellyfin.databinding.ActivityMainBinding
+import dev.jdtech.jellyfin.fragments.InitializingFragmentDirections
+import dev.jdtech.jellyfin.viewmodels.MainViewModel
+@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
+
+ private lateinit var binding: ActivityMainBinding
+ private val viewModel: MainViewModel by viewModels()
+
override fun onCreate(savedInstanceState: Bundle?) {
+ installSplashScreen()
super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_main)
+
+ binding = ActivityMainBinding.inflate(layoutInflater)
+
+ setContentView(binding.root)
+
+ val navView: BottomNavigationView = binding.navView
+
+ val navHostFragment =
+ supportFragmentManager.findFragmentById(R.id.nav_host_fragment_activity_main) as NavHostFragment
+
+ setSupportActionBar(binding.mainToolbar)
+
+ val navController = navHostFragment.navController
+
+ // Passing each menu ID as a set of Ids because each
+ // menu should be considered as top level destinations.
+ val appBarConfiguration = AppBarConfiguration(
+ setOf(
+ R.id.homeFragment, R.id.mediaFragment, R.id.favoriteFragment
+ )
+ )
+
+ setupActionBarWithNavController(navController, appBarConfiguration)
+ navView.setupWithNavController(navController)
+
+ navController.addOnDestinationChangedListener { _, destination, _ ->
+ binding.navView.visibility = when (destination.id) {
+ R.id.settingsFragment, R.id.serverSelectFragment, R.id.addServerFragment, R.id.loginFragment -> View.GONE
+ else -> View.VISIBLE
+ }
+ }
+
+ viewModel.navigateToAddServer.observe(this, {
+ if (it) {
+ navController.navigate(InitializingFragmentDirections.actionInitializingFragmentToAddServerFragment3())
+ viewModel.doneNavigateToAddServer()
+ }
+ })
+
+ viewModel.doneLoading.observe(this, {
+ if (it) {
+ if (navController.currentDestination!!.id == R.id.initializingFragment) {
+ navController.navigate(InitializingFragmentDirections.actionInitializingFragmentToNavigationHome())
+ }
+ }
+ })
+ }
+
+ override fun onSupportNavigateUp(): Boolean {
+ onBackPressed()
+ return true
}
}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/PlayerActivity.kt b/app/src/main/java/dev/jdtech/jellyfin/PlayerActivity.kt
new file mode 100644
index 0000000000..f4ad3546e2
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/PlayerActivity.kt
@@ -0,0 +1,68 @@
+package dev.jdtech.jellyfin
+
+import androidx.appcompat.app.AppCompatActivity
+import android.os.Bundle
+import android.view.View
+import android.view.WindowManager
+import androidx.activity.viewModels
+import androidx.navigation.navArgs
+import com.google.android.exoplayer2.ui.StyledPlayerView
+import dagger.hilt.android.AndroidEntryPoint
+import dev.jdtech.jellyfin.viewmodels.PlayerActivityViewModel
+import timber.log.Timber
+
+@AndroidEntryPoint
+class PlayerActivity : AppCompatActivity() {
+ private val viewModel: PlayerActivityViewModel by viewModels()
+
+ private val args: PlayerActivityArgs by navArgs()
+
+ private lateinit var playerView: StyledPlayerView
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ Timber.d("Creating player activity")
+ setContentView(R.layout.activity_player)
+ window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
+
+ playerView = findViewById(R.id.video_view)
+
+ viewModel.player.observe(this, {
+ playerView.player = it
+ })
+
+ viewModel.navigateBack.observe(this, {
+ if (it) {
+ onBackPressed()
+ }
+ })
+
+ if (viewModel.player.value == null) {
+ viewModel.initializePlayer(args.items, args.playbackPosition)
+ }
+ hideSystemUI()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ viewModel.playWhenReady = viewModel.player.value?.playWhenReady == true
+ playerView.player?.playWhenReady = false
+ }
+
+ override fun onResume() {
+ super.onResume()
+ viewModel.player.value?.playWhenReady = viewModel.playWhenReady
+ hideSystemUI()
+ }
+
+ @Suppress("DEPRECATION")
+ private fun hideSystemUI() {
+ // These methods are deprecated but we still use them because the new WindowInsetsControllerCompat has a bug which makes the action bar reappear
+ window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
+ View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
+ View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
+
+ window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
+ }
+}
+
diff --git a/app/src/main/java/dev/jdtech/jellyfin/adapters/CollectionListAdapter.kt b/app/src/main/java/dev/jdtech/jellyfin/adapters/CollectionListAdapter.kt
new file mode 100644
index 0000000000..13fd7e84c6
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/adapters/CollectionListAdapter.kt
@@ -0,0 +1,53 @@
+package dev.jdtech.jellyfin.adapters
+
+import android.view.LayoutInflater
+import android.view.ViewGroup
+import androidx.recyclerview.widget.DiffUtil
+import androidx.recyclerview.widget.ListAdapter
+import androidx.recyclerview.widget.RecyclerView
+import dev.jdtech.jellyfin.databinding.CollectionItemBinding
+import org.jellyfin.sdk.model.api.BaseItemDto
+
+class CollectionListAdapter(
+ private val onClickListener: OnClickListener
+) : ListAdapter(DiffCallback) {
+ class CollectionViewHolder(private var binding: CollectionItemBinding) :
+ RecyclerView.ViewHolder(binding.root) {
+ fun bind(collection: BaseItemDto) {
+ binding.collection = collection
+ binding.executePendingBindings()
+ }
+ }
+
+ companion object DiffCallback : DiffUtil.ItemCallback() {
+ override fun areItemsTheSame(oldItem: BaseItemDto, newItem: BaseItemDto): Boolean {
+ return oldItem.id == newItem.id
+ }
+
+ override fun areContentsTheSame(oldItem: BaseItemDto, newItem: BaseItemDto): Boolean {
+ return oldItem == newItem
+ }
+ }
+
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CollectionViewHolder {
+ return CollectionViewHolder(
+ CollectionItemBinding.inflate(
+ LayoutInflater.from(parent.context),
+ parent,
+ false
+ )
+ )
+ }
+
+ override fun onBindViewHolder(holder: CollectionViewHolder, position: Int) {
+ val collection = getItem(position)
+ holder.itemView.setOnClickListener {
+ onClickListener.onClick(collection)
+ }
+ holder.bind(collection)
+ }
+
+ class OnClickListener(val clickListener: (collection: BaseItemDto) -> Unit) {
+ fun onClick(collection: BaseItemDto) = clickListener(collection)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/adapters/EpisodeListAdapter.kt b/app/src/main/java/dev/jdtech/jellyfin/adapters/EpisodeListAdapter.kt
new file mode 100644
index 0000000000..f25e50a84e
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/adapters/EpisodeListAdapter.kt
@@ -0,0 +1,132 @@
+package dev.jdtech.jellyfin.adapters
+
+import android.util.TypedValue
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.recyclerview.widget.DiffUtil
+import androidx.recyclerview.widget.ListAdapter
+import androidx.recyclerview.widget.RecyclerView
+import dev.jdtech.jellyfin.databinding.EpisodeItemBinding
+import dev.jdtech.jellyfin.databinding.SeasonHeaderBinding
+import org.jellyfin.sdk.model.api.BaseItemDto
+import java.util.*
+
+private const val ITEM_VIEW_TYPE_HEADER = 0
+private const val ITEM_VIEW_TYPE_EPISODE = 1
+
+class EpisodeListAdapter(
+ private val onClickListener: OnClickListener,
+ private val seriesId: UUID,
+ private val seriesName: String?,
+ private val seasonId: UUID,
+ private val seasonName: String?
+) :
+ ListAdapter(DiffCallback) {
+
+ class HeaderViewHolder(private var binding: SeasonHeaderBinding) :
+ RecyclerView.ViewHolder(binding.root) {
+ fun bind(
+ seriesId: UUID,
+ seriesName: String?,
+ seasonId: UUID,
+ seasonName: String?
+ ) {
+ binding.seriesId = seriesId
+ binding.seasonId = seasonId
+ binding.seasonName.text = seasonName
+ binding.seriesName.text = seriesName
+ binding.executePendingBindings()
+ }
+ }
+
+ class EpisodeViewHolder(private var binding: EpisodeItemBinding) :
+ RecyclerView.ViewHolder(binding.root) {
+ fun bind(episode: BaseItemDto) {
+ binding.episode = episode
+ if (episode.userData?.playedPercentage != null) {
+ binding.progressBar.layoutParams.width = TypedValue.applyDimension(
+ TypedValue.COMPLEX_UNIT_DIP,
+ (episode.userData?.playedPercentage?.times(.84))!!.toFloat(),
+ binding.progressBar.context.resources.displayMetrics
+ ).toInt()
+ binding.progressBar.visibility = View.VISIBLE
+ } else {
+ binding.progressBar.visibility = View.GONE
+ }
+ binding.executePendingBindings()
+ }
+ }
+
+ companion object DiffCallback : DiffUtil.ItemCallback() {
+ override fun areItemsTheSame(oldItem: EpisodeItem, newItem: EpisodeItem): Boolean {
+ return oldItem.id == newItem.id
+ }
+
+ override fun areContentsTheSame(oldItem: EpisodeItem, newItem: EpisodeItem): Boolean {
+ return oldItem == newItem
+ }
+ }
+
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
+ return when (viewType) {
+ ITEM_VIEW_TYPE_HEADER -> {
+ HeaderViewHolder(
+ SeasonHeaderBinding.inflate(
+ LayoutInflater.from(parent.context),
+ parent,
+ false
+ )
+ )
+ }
+ ITEM_VIEW_TYPE_EPISODE -> {
+ EpisodeViewHolder(
+ EpisodeItemBinding.inflate(
+ LayoutInflater.from(parent.context),
+ parent,
+ false
+ )
+ )
+ }
+ else -> throw ClassCastException("Unknown viewType $viewType")
+ }
+ }
+
+ override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
+ when (holder.itemViewType) {
+ ITEM_VIEW_TYPE_HEADER -> {
+ (holder as HeaderViewHolder).bind(seriesId, seriesName, seasonId, seasonName)
+ }
+ ITEM_VIEW_TYPE_EPISODE -> {
+ val item = getItem(position) as EpisodeItem.Episode
+ holder.itemView.setOnClickListener {
+ onClickListener.onClick(item.episode)
+ }
+ (holder as EpisodeViewHolder).bind(item.episode)
+ }
+ }
+ }
+
+ override fun getItemViewType(position: Int): Int {
+ return when (getItem(position)) {
+ is EpisodeItem.Header -> ITEM_VIEW_TYPE_HEADER
+ is EpisodeItem.Episode -> ITEM_VIEW_TYPE_EPISODE
+ }
+ }
+
+ class OnClickListener(val clickListener: (item: BaseItemDto) -> Unit) {
+ fun onClick(item: BaseItemDto) = clickListener(item)
+ }
+}
+
+sealed class EpisodeItem {
+ abstract val id: UUID
+
+ object Header : EpisodeItem() {
+ override val id: UUID = UUID.randomUUID()
+ }
+
+ data class Episode(val episode: BaseItemDto) : EpisodeItem() {
+ override val id = episode.id
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/adapters/FavoritesListAdapter.kt b/app/src/main/java/dev/jdtech/jellyfin/adapters/FavoritesListAdapter.kt
new file mode 100644
index 0000000000..e69f3ec367
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/adapters/FavoritesListAdapter.kt
@@ -0,0 +1,63 @@
+package dev.jdtech.jellyfin.adapters
+
+import android.view.LayoutInflater
+import android.view.ViewGroup
+import androidx.recyclerview.widget.DiffUtil
+import androidx.recyclerview.widget.ListAdapter
+import androidx.recyclerview.widget.RecyclerView
+import dev.jdtech.jellyfin.databinding.FavoriteSectionBinding
+import dev.jdtech.jellyfin.models.FavoriteSection
+
+class FavoritesListAdapter(
+ private val onClickListener: ViewItemListAdapter.OnClickListener,
+ private val onEpisodeClickListener: HomeEpisodeListAdapter.OnClickListener
+) : ListAdapter(DiffCallback) {
+ class SectionViewHolder(private var binding: FavoriteSectionBinding) :
+ RecyclerView.ViewHolder(binding.root) {
+ fun bind(
+ section: FavoriteSection,
+ onClickListener: ViewItemListAdapter.OnClickListener,
+ onEpisodeClickListener: HomeEpisodeListAdapter.OnClickListener
+ ) {
+ binding.section = section
+ if (section.name == "Movies" || section.name == "Shows") {
+ binding.itemsRecyclerView.adapter =
+ ViewItemListAdapter(onClickListener, fixedWidth = true)
+ (binding.itemsRecyclerView.adapter as ViewItemListAdapter).submitList(section.items)
+ } else if (section.name == "Episodes") {
+ binding.itemsRecyclerView.adapter =
+ HomeEpisodeListAdapter(onEpisodeClickListener)
+ (binding.itemsRecyclerView.adapter as HomeEpisodeListAdapter).submitList(section.items)
+ }
+ binding.executePendingBindings()
+ }
+ }
+
+ companion object DiffCallback : DiffUtil.ItemCallback() {
+ override fun areItemsTheSame(oldItem: FavoriteSection, newItem: FavoriteSection): Boolean {
+ return oldItem.id == newItem.id
+ }
+
+ override fun areContentsTheSame(
+ oldItem: FavoriteSection,
+ newItem: FavoriteSection
+ ): Boolean {
+ return oldItem == newItem
+ }
+ }
+
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SectionViewHolder {
+ return SectionViewHolder(
+ FavoriteSectionBinding.inflate(
+ LayoutInflater.from(parent.context),
+ parent,
+ false
+ )
+ )
+ }
+
+ override fun onBindViewHolder(holder: SectionViewHolder, position: Int) {
+ val collection = getItem(position)
+ holder.bind(collection, onClickListener, onEpisodeClickListener)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/adapters/HomeEpisodeListAdapter.kt b/app/src/main/java/dev/jdtech/jellyfin/adapters/HomeEpisodeListAdapter.kt
new file mode 100644
index 0000000000..a56e4f0baa
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/adapters/HomeEpisodeListAdapter.kt
@@ -0,0 +1,66 @@
+package dev.jdtech.jellyfin.adapters
+
+import android.util.TypedValue
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.recyclerview.widget.DiffUtil
+import androidx.recyclerview.widget.ListAdapter
+import androidx.recyclerview.widget.RecyclerView
+import dev.jdtech.jellyfin.databinding.HomeEpisodeItemBinding
+import org.jellyfin.sdk.model.api.BaseItemDto
+
+class HomeEpisodeListAdapter(private val onClickListener: OnClickListener) : ListAdapter(DiffCallback) {
+ class EpisodeViewHolder(private var binding: HomeEpisodeItemBinding) :
+ RecyclerView.ViewHolder(binding.root) {
+ fun bind(episode: BaseItemDto) {
+ binding.episode = episode
+ if (episode.userData?.playedPercentage != null) {
+ binding.progressBar.layoutParams.width = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
+ (episode.userData?.playedPercentage?.times(2.24))!!.toFloat(), binding.progressBar.context.resources.displayMetrics).toInt()
+ binding.progressBar.visibility = View.VISIBLE
+ }
+
+ if (episode.type == "Movie") {
+ binding.primaryName.text = episode.name
+ binding.secondaryName.visibility = View.GONE
+ } else if (episode.type == "Episode") {
+ binding.primaryName.text = episode.seriesName
+ }
+
+ binding.executePendingBindings()
+ }
+ }
+
+ companion object DiffCallback : DiffUtil.ItemCallback() {
+ override fun areItemsTheSame(oldItem: BaseItemDto, newItem: BaseItemDto): Boolean {
+ return oldItem.id == newItem.id
+ }
+
+ override fun areContentsTheSame(oldItem: BaseItemDto, newItem: BaseItemDto): Boolean {
+ return oldItem == newItem
+ }
+ }
+
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EpisodeViewHolder {
+ return EpisodeViewHolder(
+ HomeEpisodeItemBinding.inflate(
+ LayoutInflater.from(parent.context),
+ parent,
+ false
+ )
+ )
+ }
+
+ override fun onBindViewHolder(holder: EpisodeViewHolder, position: Int) {
+ val item = getItem(position)
+ holder.itemView.setOnClickListener {
+ onClickListener.onClick(item)
+ }
+ holder.bind(item)
+ }
+
+ class OnClickListener(val clickListener: (item: BaseItemDto) -> Unit) {
+ fun onClick(item: BaseItemDto) = clickListener(item)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/adapters/PersonListAdapter.kt b/app/src/main/java/dev/jdtech/jellyfin/adapters/PersonListAdapter.kt
new file mode 100644
index 0000000000..b1654b537c
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/adapters/PersonListAdapter.kt
@@ -0,0 +1,44 @@
+package dev.jdtech.jellyfin.adapters
+
+import android.view.LayoutInflater
+import android.view.ViewGroup
+import androidx.recyclerview.widget.DiffUtil
+import androidx.recyclerview.widget.ListAdapter
+import androidx.recyclerview.widget.RecyclerView
+import dev.jdtech.jellyfin.databinding.PersonItemBinding
+import org.jellyfin.sdk.model.api.BaseItemPerson
+
+class PersonListAdapter :ListAdapter(DiffCallback) {
+ class PersonViewHolder(private var binding: PersonItemBinding) :
+ RecyclerView.ViewHolder(binding.root) {
+ fun bind(person: BaseItemPerson) {
+ binding.person = person
+ binding.executePendingBindings()
+ }
+ }
+
+ companion object DiffCallback : DiffUtil.ItemCallback() {
+ override fun areItemsTheSame(oldItem: BaseItemPerson, newItem: BaseItemPerson): Boolean {
+ return oldItem.id == newItem.id
+ }
+
+ override fun areContentsTheSame(oldItem: BaseItemPerson, newItem: BaseItemPerson): Boolean {
+ return oldItem == newItem
+ }
+ }
+
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PersonViewHolder {
+ return PersonViewHolder(
+ PersonItemBinding.inflate(
+ LayoutInflater.from(parent.context),
+ parent,
+ false
+ )
+ )
+ }
+
+ override fun onBindViewHolder(holder: PersonViewHolder, position: Int) {
+ val item = getItem(position)
+ holder.bind(item)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/adapters/ServerGridAdapter.kt b/app/src/main/java/dev/jdtech/jellyfin/adapters/ServerGridAdapter.kt
new file mode 100644
index 0000000000..7b7e849e7d
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/adapters/ServerGridAdapter.kt
@@ -0,0 +1,58 @@
+package dev.jdtech.jellyfin.adapters
+
+import android.view.LayoutInflater
+import android.view.ViewGroup
+import androidx.recyclerview.widget.DiffUtil
+import androidx.recyclerview.widget.ListAdapter
+import androidx.recyclerview.widget.RecyclerView
+import dev.jdtech.jellyfin.database.Server
+import dev.jdtech.jellyfin.databinding.ServerItemBinding
+
+class ServerGridAdapter(
+ private val onClickListener: OnClickListener,
+ private val onLongClickListener: OnLongClickListener
+ ) : ListAdapter(DiffCallback) {
+ class ServerViewHolder(private var binding: ServerItemBinding) :
+ RecyclerView.ViewHolder(binding.root) {
+ fun bind(server: Server) {
+ binding.server = server
+ binding.executePendingBindings()
+ }
+ }
+
+ companion object DiffCallback : DiffUtil.ItemCallback() {
+ override fun areItemsTheSame(oldItem: Server, newItem: Server): Boolean {
+ return oldItem.id == newItem.id
+ }
+
+ override fun areContentsTheSame(oldItem: Server, newItem: Server): Boolean {
+ return oldItem == newItem
+ }
+ }
+
+ override fun onCreateViewHolder(
+ parent: ViewGroup,
+ viewType: Int
+ ): ServerViewHolder {
+ return ServerViewHolder(ServerItemBinding.inflate(LayoutInflater.from(parent.context)))
+ }
+
+ override fun onBindViewHolder(holder: ServerViewHolder, position: Int) {
+ val server = getItem(position)
+ holder.itemView.setOnClickListener {
+ onClickListener.onClick(server)
+ }
+ holder.itemView.setOnLongClickListener {
+ onLongClickListener.onLongClick(server)
+ }
+ holder.bind(server)
+ }
+
+ class OnClickListener(val clickListener: (server: Server) -> Unit) {
+ fun onClick(server: Server) = clickListener(server)
+ }
+
+ class OnLongClickListener(val clickListener: (server: Server) -> Boolean) {
+ fun onLongClick(server: Server) = clickListener(server)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/adapters/ViewItemListAdapter.kt b/app/src/main/java/dev/jdtech/jellyfin/adapters/ViewItemListAdapter.kt
new file mode 100644
index 0000000000..77e503bdbd
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/adapters/ViewItemListAdapter.kt
@@ -0,0 +1,66 @@
+package dev.jdtech.jellyfin.adapters
+
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.recyclerview.widget.DiffUtil
+import androidx.recyclerview.widget.ListAdapter
+import androidx.recyclerview.widget.RecyclerView
+import dev.jdtech.jellyfin.R
+import dev.jdtech.jellyfin.databinding.BaseItemBinding
+import org.jellyfin.sdk.model.api.BaseItemDto
+
+class ViewItemListAdapter(
+ private val onClickListener: OnClickListener,
+ private val fixedWidth: Boolean = false,
+ ) :
+ ListAdapter(DiffCallback) {
+
+ class ItemViewHolder(private var binding: BaseItemBinding, private val parent: ViewGroup) :
+ RecyclerView.ViewHolder(binding.root) {
+ fun bind(item: BaseItemDto, fixedWidth: Boolean) {
+ binding.item = item
+ binding.itemName.text = if (item.type == "Episode") item.seriesName else item.name
+ binding.itemCount.visibility =
+ if (item.userData?.unplayedItemCount != null && item.userData?.unplayedItemCount!! > 0) View.VISIBLE else View.GONE
+ if (fixedWidth) {
+ binding.itemLayout.layoutParams.width =
+ parent.resources.getDimension(R.dimen.overview_media_width).toInt()
+ (binding.itemLayout.layoutParams as ViewGroup.MarginLayoutParams).bottomMargin = 0
+ }
+ binding.executePendingBindings()
+ }
+ }
+
+ companion object DiffCallback : DiffUtil.ItemCallback() {
+ override fun areItemsTheSame(oldItem: BaseItemDto, newItem: BaseItemDto): Boolean {
+ return oldItem.id == newItem.id
+ }
+
+ override fun areContentsTheSame(oldItem: BaseItemDto, newItem: BaseItemDto): Boolean {
+ return oldItem == newItem
+ }
+ }
+
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
+ return ItemViewHolder(
+ BaseItemBinding.inflate(
+ LayoutInflater.from(parent.context),
+ parent,
+ false
+ ), parent
+ )
+ }
+
+ override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
+ val item = getItem(position)
+ holder.itemView.setOnClickListener {
+ onClickListener.onClick(item)
+ }
+ holder.bind(item, fixedWidth)
+ }
+
+ class OnClickListener(val clickListener: (item: BaseItemDto) -> Unit) {
+ fun onClick(item: BaseItemDto) = clickListener(item)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/adapters/ViewListAdapter.kt b/app/src/main/java/dev/jdtech/jellyfin/adapters/ViewListAdapter.kt
new file mode 100644
index 0000000000..2cd14a15ce
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/adapters/ViewListAdapter.kt
@@ -0,0 +1,116 @@
+package dev.jdtech.jellyfin.adapters
+
+import android.view.LayoutInflater
+import android.view.ViewGroup
+import androidx.recyclerview.widget.DiffUtil
+import androidx.recyclerview.widget.ListAdapter
+import androidx.recyclerview.widget.RecyclerView
+import dev.jdtech.jellyfin.R
+import dev.jdtech.jellyfin.databinding.NextUpSectionBinding
+import dev.jdtech.jellyfin.databinding.ViewItemBinding
+import dev.jdtech.jellyfin.models.HomeSection
+import dev.jdtech.jellyfin.models.View
+import java.util.*
+
+private const val ITEM_VIEW_TYPE_NEXT_UP = 0
+private const val ITEM_VIEW_TYPE_VIEW = 1
+
+class ViewListAdapter(
+ private val onClickListener: OnClickListener,
+ private val onItemClickListener: ViewItemListAdapter.OnClickListener,
+ private val onNextUpClickListener: HomeEpisodeListAdapter.OnClickListener
+) : ListAdapter(DiffCallback) {
+ class ViewViewHolder(private var binding: ViewItemBinding) :
+ RecyclerView.ViewHolder(binding.root) {
+ fun bind(
+ dataItem: HomeItem.ViewItem,
+ onClickListener: OnClickListener,
+ onItemClickListener: ViewItemListAdapter.OnClickListener
+ ) {
+ val view = dataItem.view
+ binding.view = view
+ binding.viewName.text = String.format(binding.viewName.context.resources.getString(R.string.latest_library), view.name)
+ binding.itemsRecyclerView.adapter =
+ ViewItemListAdapter(onItemClickListener, fixedWidth = true)
+ binding.viewAll.setOnClickListener {
+ onClickListener.onClick(view)
+ }
+ binding.executePendingBindings()
+ }
+ }
+
+ class NextUpViewHolder(private var binding: NextUpSectionBinding) :
+ RecyclerView.ViewHolder(binding.root) {
+ fun bind(section: HomeItem.Section, onClickListener: HomeEpisodeListAdapter.OnClickListener) {
+ binding.section = section.homeSection
+ binding.itemsRecyclerView.adapter = HomeEpisodeListAdapter(onClickListener)
+ binding.executePendingBindings()
+ }
+ }
+
+ companion object DiffCallback : DiffUtil.ItemCallback() {
+ override fun areItemsTheSame(oldItem: HomeItem, newItem: HomeItem): Boolean {
+ return oldItem.id == newItem.id
+ }
+
+ override fun areContentsTheSame(oldItem: HomeItem, newItem: HomeItem): Boolean {
+ return oldItem == newItem
+ }
+ }
+
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
+ return when (viewType) {
+ ITEM_VIEW_TYPE_NEXT_UP -> NextUpViewHolder(
+ NextUpSectionBinding.inflate(
+ LayoutInflater.from(
+ parent.context
+ ), parent, false
+ )
+ )
+ ITEM_VIEW_TYPE_VIEW -> ViewViewHolder(
+ ViewItemBinding.inflate(
+ LayoutInflater.from(parent.context),
+ parent,
+ false
+ )
+ )
+ else -> throw ClassCastException("Unknown viewType $viewType")
+ }
+ }
+
+ override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
+ when (holder.itemViewType) {
+ ITEM_VIEW_TYPE_NEXT_UP -> {
+ val view = getItem(position) as HomeItem.Section
+ (holder as NextUpViewHolder).bind(view, onNextUpClickListener)
+ }
+ ITEM_VIEW_TYPE_VIEW -> {
+ val view = getItem(position) as HomeItem.ViewItem
+ (holder as ViewViewHolder).bind(view, onClickListener, onItemClickListener)
+ }
+ }
+ }
+
+ override fun getItemViewType(position: Int): Int {
+ return when (getItem(position)) {
+ is HomeItem.Section -> ITEM_VIEW_TYPE_NEXT_UP
+ is HomeItem.ViewItem -> ITEM_VIEW_TYPE_VIEW
+ }
+ }
+
+ class OnClickListener(val clickListener: (view: View) -> Unit) {
+ fun onClick(view: View) = clickListener(view)
+ }
+}
+
+sealed class HomeItem {
+ data class Section(val homeSection: HomeSection) : HomeItem() {
+ override val id = homeSection.id
+ }
+
+ data class ViewItem(val view: View) : HomeItem() {
+ override val id = view.id
+ }
+
+ abstract val id: UUID
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/api/JellyfinApi.kt b/app/src/main/java/dev/jdtech/jellyfin/api/JellyfinApi.kt
new file mode 100644
index 0000000000..31df12b281
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/api/JellyfinApi.kt
@@ -0,0 +1,76 @@
+package dev.jdtech.jellyfin.api
+
+import android.content.Context
+import dev.jdtech.jellyfin.BuildConfig
+import org.jellyfin.sdk.Jellyfin
+import org.jellyfin.sdk.android
+import org.jellyfin.sdk.api.operations.*
+import org.jellyfin.sdk.model.ClientInfo
+import java.util.*
+
+
+/**
+ * Jellyfin API class using org.jellyfin.sdk:jellyfin-platform-android
+ *
+ * @param context The context
+ * @param baseUrl The url of the server
+ * @constructor Creates a new [JellyfinApi] instance
+ */
+class JellyfinApi(context: Context, baseUrl: String) {
+ val jellyfin = Jellyfin {
+ clientInfo =
+ ClientInfo(name = context.applicationInfo.loadLabel(context.packageManager).toString(), version = BuildConfig.VERSION_NAME)
+ android(context)
+ }
+ val api = jellyfin.createApi(baseUrl = baseUrl)
+ var userId: UUID? = null
+
+ val systemApi = SystemApi(api)
+ val userApi = UserApi(api)
+ val viewsApi = UserViewsApi(api)
+ val itemsApi = ItemsApi(api)
+ val userLibraryApi = UserLibraryApi(api)
+ val showsApi = TvShowsApi(api)
+ val sessionApi = SessionApi(api)
+ val videosApi = VideosApi(api)
+ val mediaInfoApi = MediaInfoApi(api)
+ val playStateApi = PlayStateApi(api)
+
+ companion object {
+ @Volatile
+ private var INSTANCE: JellyfinApi? = null
+
+ /**
+ * Creates or gets a new instance of [JellyfinApi]
+ *
+ * If there already is an instance, it will return that instance and ignore the [baseUrl] parameter
+ *
+ * @param context The context
+ * @param baseUrl The url of the server
+ */
+ fun getInstance(context: Context, baseUrl: String): JellyfinApi {
+ synchronized(this) {
+ var instance = INSTANCE
+ if (instance == null) {
+ instance = JellyfinApi(context.applicationContext, baseUrl)
+ INSTANCE = instance
+ }
+ return instance
+ }
+ }
+
+ /**
+ * Create a new [JellyfinApi] instance
+ *
+ * @param context The context
+ * @param baseUrl The url of the server
+ */
+ fun newInstance(context: Context, baseUrl: String): JellyfinApi {
+ synchronized(this) {
+ val instance = JellyfinApi(context.applicationContext, baseUrl)
+ INSTANCE = instance
+ return instance
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/database/Server.kt b/app/src/main/java/dev/jdtech/jellyfin/database/Server.kt
new file mode 100644
index 0000000000..268c44cc49
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/database/Server.kt
@@ -0,0 +1,15 @@
+package dev.jdtech.jellyfin.database
+
+import androidx.room.Entity
+import androidx.room.PrimaryKey
+
+@Entity(tableName = "servers")
+data class Server(
+ @PrimaryKey
+ val id: String,
+ val name: String,
+ val address: String,
+ val userId: String,
+ val userName: String,
+ val accessToken: String,
+)
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/database/ServerDatabase.kt b/app/src/main/java/dev/jdtech/jellyfin/database/ServerDatabase.kt
new file mode 100644
index 0000000000..4a1b8f0294
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/database/ServerDatabase.kt
@@ -0,0 +1,9 @@
+package dev.jdtech.jellyfin.database
+
+import androidx.room.Database
+import androidx.room.RoomDatabase
+
+@Database(entities = [Server::class], version = 1, exportSchema = false)
+abstract class ServerDatabase : RoomDatabase() {
+ abstract val serverDatabaseDao: ServerDatabaseDao
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/database/ServerDatabaseDao.kt b/app/src/main/java/dev/jdtech/jellyfin/database/ServerDatabaseDao.kt
new file mode 100644
index 0000000000..7363f12187
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/database/ServerDatabaseDao.kt
@@ -0,0 +1,31 @@
+package dev.jdtech.jellyfin.database
+
+import androidx.lifecycle.LiveData
+import androidx.room.Dao
+import androidx.room.Insert
+import androidx.room.Query
+import androidx.room.Update
+
+@Dao
+interface ServerDatabaseDao {
+ @Insert
+ fun insert(server: Server)
+
+ @Update
+ fun update(server: Server)
+
+ @Query("select * from servers where id = :id")
+ fun get(id: String): Server
+
+ @Query("delete from servers")
+ fun clear()
+
+ @Query("select * from servers")
+ fun getAllServers(): LiveData>
+
+ @Query("select * from servers")
+ fun getAllServersSync(): List
+
+ @Query("delete from servers where id = :id")
+ fun delete(id: String)
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/di/ApiModule.kt b/app/src/main/java/dev/jdtech/jellyfin/di/ApiModule.kt
new file mode 100644
index 0000000000..944b0fe687
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/di/ApiModule.kt
@@ -0,0 +1,20 @@
+package dev.jdtech.jellyfin.di
+
+import android.content.Context
+import dagger.Module
+import dagger.Provides
+import dagger.hilt.InstallIn
+import dagger.hilt.android.qualifiers.ApplicationContext
+import dagger.hilt.components.SingletonComponent
+import dev.jdtech.jellyfin.api.JellyfinApi
+import javax.inject.Singleton
+
+@Module
+@InstallIn(SingletonComponent::class)
+object ApiModule {
+ @Singleton
+ @Provides
+ fun provideJellyfinApi(@ApplicationContext application: Context): JellyfinApi {
+ return JellyfinApi.getInstance(application, "")
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/di/AppModule.kt b/app/src/main/java/dev/jdtech/jellyfin/di/AppModule.kt
new file mode 100644
index 0000000000..323c078eb9
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/di/AppModule.kt
@@ -0,0 +1,20 @@
+package dev.jdtech.jellyfin.di
+
+import android.content.Context
+import dagger.Module
+import dagger.Provides
+import dagger.hilt.InstallIn
+import dagger.hilt.android.qualifiers.ApplicationContext
+import dagger.hilt.components.SingletonComponent
+import dev.jdtech.jellyfin.BaseApplication
+import javax.inject.Singleton
+
+@Module
+@InstallIn(SingletonComponent::class)
+object AppModule {
+ @Singleton
+ @Provides
+ fun provideApplication(@ApplicationContext app: Context): BaseApplication {
+ return app as BaseApplication
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/di/DatabaseModule.kt b/app/src/main/java/dev/jdtech/jellyfin/di/DatabaseModule.kt
new file mode 100644
index 0000000000..8932892fdd
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/di/DatabaseModule.kt
@@ -0,0 +1,29 @@
+package dev.jdtech.jellyfin.di
+
+import android.content.Context
+import androidx.room.Room
+import dagger.Module
+import dagger.Provides
+import dagger.hilt.InstallIn
+import dagger.hilt.android.qualifiers.ApplicationContext
+import dagger.hilt.components.SingletonComponent
+import dev.jdtech.jellyfin.database.ServerDatabase
+import dev.jdtech.jellyfin.database.ServerDatabaseDao
+import javax.inject.Singleton
+
+@Module
+@InstallIn(SingletonComponent::class)
+object DatabaseModule {
+ @Singleton
+ @Provides
+ fun provideServerDatabaseDao(@ApplicationContext app: Context): ServerDatabaseDao {
+ return Room.databaseBuilder(
+ app.applicationContext,
+ ServerDatabase::class.java,
+ "servers"
+ )
+ .fallbackToDestructiveMigration()
+ .build()
+ .serverDatabaseDao
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/di/RepositoryModule.kt b/app/src/main/java/dev/jdtech/jellyfin/di/RepositoryModule.kt
new file mode 100644
index 0000000000..e3865bb7b8
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/di/RepositoryModule.kt
@@ -0,0 +1,22 @@
+package dev.jdtech.jellyfin.di
+
+import dagger.Module
+import dagger.Provides
+import dagger.hilt.InstallIn
+import dagger.hilt.components.SingletonComponent
+import dev.jdtech.jellyfin.api.JellyfinApi
+import dev.jdtech.jellyfin.repository.JellyfinRepository
+import dev.jdtech.jellyfin.repository.JellyfinRepositoryImpl
+import javax.inject.Singleton
+
+@Module
+@InstallIn(SingletonComponent::class)
+object RepositoryModule {
+ @Singleton
+ @Provides
+ fun provideJellyfinRepository(
+ jellyfinApi: JellyfinApi
+ ): JellyfinRepository {
+ return JellyfinRepositoryImpl(jellyfinApi)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/di/SharedPreferencesModule.kt b/app/src/main/java/dev/jdtech/jellyfin/di/SharedPreferencesModule.kt
new file mode 100644
index 0000000000..d3f6de1936
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/di/SharedPreferencesModule.kt
@@ -0,0 +1,22 @@
+package dev.jdtech.jellyfin.di
+
+import android.content.Context
+import android.content.SharedPreferences
+import androidx.preference.PreferenceManager
+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 SharedPreferencesModule {
+ @Singleton
+ @Provides
+ fun provideSharedPreferences(@ApplicationContext application: Context): SharedPreferences {
+ return PreferenceManager.getDefaultSharedPreferences(application)
+ }
+}
diff --git a/app/src/main/java/dev/jdtech/jellyfin/dialogs/DeleteServerDialogFragment.kt b/app/src/main/java/dev/jdtech/jellyfin/dialogs/DeleteServerDialogFragment.kt
new file mode 100644
index 0000000000..53bedbd5dc
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/dialogs/DeleteServerDialogFragment.kt
@@ -0,0 +1,27 @@
+package dev.jdtech.jellyfin.dialogs
+
+import android.app.AlertDialog
+import android.app.Dialog
+import android.os.Bundle
+import androidx.fragment.app.DialogFragment
+import dev.jdtech.jellyfin.R
+import dev.jdtech.jellyfin.database.Server
+import dev.jdtech.jellyfin.viewmodels.ServerSelectViewModel
+import java.lang.IllegalStateException
+
+class DeleteServerDialogFragment(private val viewModel: ServerSelectViewModel, val server: Server) : DialogFragment() {
+ override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
+ return activity?.let {
+ val builder = AlertDialog.Builder(it)
+ builder.setTitle(getString(R.string.remove_server))
+ .setMessage(getString(R.string.remove_server_dialog_text, server.name))
+ .setPositiveButton(getString(R.string.remove)) { _, _ ->
+ viewModel.deleteServer(server)
+ }
+ .setNegativeButton(getString(R.string.cancel)) { _, _ ->
+
+ }
+ builder.create()
+ } ?: throw IllegalStateException("Activity cannot be null")
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/dialogs/VideoVersionDialogFragment.kt b/app/src/main/java/dev/jdtech/jellyfin/dialogs/VideoVersionDialogFragment.kt
new file mode 100644
index 0000000000..912d40748f
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/dialogs/VideoVersionDialogFragment.kt
@@ -0,0 +1,24 @@
+package dev.jdtech.jellyfin.dialogs
+
+import android.app.AlertDialog
+import android.app.Dialog
+import android.os.Bundle
+import androidx.fragment.app.DialogFragment
+import dev.jdtech.jellyfin.viewmodels.MediaInfoViewModel
+import java.lang.IllegalStateException
+
+class VideoVersionDialogFragment(
+ private val viewModel: MediaInfoViewModel
+) : DialogFragment() {
+ override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
+ val items = viewModel.mediaSources.value!!.map { it.name }
+ return activity?.let {
+ val builder = AlertDialog.Builder(it)
+ builder.setTitle("Select a version")
+ .setItems(items.toTypedArray()) { _, which ->
+ viewModel.navigateToPlayer(viewModel.mediaSources.value!![which])
+ }
+ builder.create()
+ } ?: throw IllegalStateException("Activity cannot be null")
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/fragments/AddServerFragment.kt b/app/src/main/java/dev/jdtech/jellyfin/fragments/AddServerFragment.kt
new file mode 100644
index 0000000000..10fbcddc3b
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/fragments/AddServerFragment.kt
@@ -0,0 +1,57 @@
+package dev.jdtech.jellyfin.fragments
+
+import android.os.Bundle
+import androidx.fragment.app.Fragment
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.fragment.app.viewModels
+import androidx.navigation.fragment.findNavController
+import dagger.hilt.android.AndroidEntryPoint
+import dev.jdtech.jellyfin.databinding.FragmentAddServerBinding
+import dev.jdtech.jellyfin.viewmodels.AddServerViewModel
+
+@AndroidEntryPoint
+class AddServerFragment : Fragment() {
+
+ private lateinit var binding: FragmentAddServerBinding
+ private val viewModel: AddServerViewModel by viewModels()
+
+ override fun onCreateView(
+ inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View {
+ binding = FragmentAddServerBinding.inflate(inflater)
+
+ binding.lifecycleOwner = viewLifecycleOwner
+ binding.viewModel = viewModel
+
+ binding.buttonConnect.setOnClickListener {
+ val serverAddress = binding.editTextServerAddress.text.toString()
+ if (serverAddress.isNotBlank()) {
+ viewModel.checkServer(serverAddress)
+ binding.progressCircular.visibility = View.VISIBLE
+ } else {
+ binding.editTextServerAddressLayout.error = "Empty server address"
+ }
+ }
+
+ viewModel.navigateToLogin.observe(viewLifecycleOwner, {
+ if (it) {
+ navigateToLoginFragment()
+ }
+ binding.progressCircular.visibility = View.GONE
+ })
+
+ viewModel.error.observe(viewLifecycleOwner, {
+ binding.editTextServerAddressLayout.error = it
+ })
+
+ return binding.root
+ }
+
+ private fun navigateToLoginFragment() {
+ findNavController().navigate(AddServerFragmentDirections.actionAddServerFragment3ToLoginFragment2())
+ viewModel.onNavigateToLoginDone()
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/fragments/EpisodeBottomSheetFragment.kt b/app/src/main/java/dev/jdtech/jellyfin/fragments/EpisodeBottomSheetFragment.kt
new file mode 100644
index 0000000000..eb4a83a780
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/fragments/EpisodeBottomSheetFragment.kt
@@ -0,0 +1,128 @@
+package dev.jdtech.jellyfin.fragments
+
+import android.os.Bundle
+import android.util.TypedValue
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.core.content.ContextCompat
+import androidx.fragment.app.viewModels
+import androidx.navigation.fragment.findNavController
+import androidx.navigation.fragment.navArgs
+import com.google.android.material.bottomsheet.BottomSheetDialogFragment
+import dagger.hilt.android.AndroidEntryPoint
+import dev.jdtech.jellyfin.R
+import dev.jdtech.jellyfin.databinding.EpisodeBottomSheetBinding
+import dev.jdtech.jellyfin.models.PlayerItem
+import dev.jdtech.jellyfin.viewmodels.EpisodeBottomSheetViewModel
+
+@AndroidEntryPoint
+class EpisodeBottomSheetFragment : BottomSheetDialogFragment() {
+ private val args: EpisodeBottomSheetFragmentArgs by navArgs()
+
+ private lateinit var binding: EpisodeBottomSheetBinding
+ private val viewModel: EpisodeBottomSheetViewModel by viewModels()
+
+ override fun onCreateView(
+ inflater: LayoutInflater,
+ container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View {
+ binding = EpisodeBottomSheetBinding.inflate(inflater, container, false)
+
+ binding.lifecycleOwner = viewLifecycleOwner
+ binding.viewModel = viewModel
+
+ binding.playButton.setOnClickListener {
+ binding.playButton.setImageResource(android.R.color.transparent)
+ binding.progressCircular.visibility = View.VISIBLE
+ viewModel.preparePlayer()
+ }
+
+ binding.checkButton.setOnClickListener {
+ when (viewModel.played.value) {
+ true -> viewModel.markAsUnplayed(args.episodeId)
+ false -> viewModel.markAsPlayed(args.episodeId)
+ }
+ }
+
+ binding.favoriteButton.setOnClickListener {
+ when (viewModel.favorite.value) {
+ true -> viewModel.unmarkAsFavorite(args.episodeId)
+ false -> viewModel.markAsFavorite(args.episodeId)
+ }
+ }
+
+ viewModel.item.observe(viewLifecycleOwner, { episode ->
+ if (episode.userData?.playedPercentage != null) {
+ binding.progressBar.layoutParams.width = TypedValue.applyDimension(
+ TypedValue.COMPLEX_UNIT_DIP,
+ (episode.userData?.playedPercentage?.times(1.26))!!.toFloat(),
+ context?.resources?.displayMetrics
+ ).toInt()
+ binding.progressBar.visibility = View.VISIBLE
+ }
+ binding.communityRating.visibility = when (episode.communityRating != null) {
+ false -> View.GONE
+ true -> View.VISIBLE
+ }
+ })
+
+ viewModel.played.observe(viewLifecycleOwner, {
+ val drawable = when (it) {
+ true -> R.drawable.ic_check_filled
+ false -> R.drawable.ic_check
+ }
+
+ binding.checkButton.setImageResource(drawable)
+ })
+
+ viewModel.favorite.observe(viewLifecycleOwner, {
+ val drawable = when (it) {
+ true -> R.drawable.ic_heart_filled
+ false -> R.drawable.ic_heart
+ }
+
+ binding.favoriteButton.setImageResource(drawable)
+ })
+
+ viewModel.navigateToPlayer.observe(viewLifecycleOwner, {
+ if (it) {
+ navigateToPlayerActivity(
+ viewModel.playerItems.toTypedArray(),
+ viewModel.item.value!!.userData!!.playbackPositionTicks.div(10000)
+ )
+ viewModel.doneNavigateToPlayer()
+ binding.playButton.setImageDrawable(ContextCompat.getDrawable(requireActivity(), R.drawable.ic_play))
+ binding.progressCircular.visibility = View.INVISIBLE
+ }
+ })
+
+ viewModel.playerItemsError.observe(viewLifecycleOwner, {
+ when (it) {
+ true -> {
+ binding.playerItemsError.visibility = View.VISIBLE
+ binding.playButton.setImageDrawable(ContextCompat.getDrawable(requireActivity(), R.drawable.ic_play))
+ binding.progressCircular.visibility = View.INVISIBLE
+ }
+ false -> binding.playerItemsError.visibility = View.GONE
+ }
+ })
+
+ viewModel.loadEpisode(args.episodeId)
+
+ return binding.root
+ }
+
+ private fun navigateToPlayerActivity(
+ playerItems: Array,
+ playbackPosition: Long
+ ) {
+ findNavController().navigate(
+ EpisodeBottomSheetFragmentDirections.actionEpisodeBottomSheetFragmentToPlayerActivity(
+ playerItems,
+ playbackPosition
+ )
+ )
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/fragments/FavoriteFragment.kt b/app/src/main/java/dev/jdtech/jellyfin/fragments/FavoriteFragment.kt
new file mode 100644
index 0000000000..d66f701168
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/fragments/FavoriteFragment.kt
@@ -0,0 +1,89 @@
+package dev.jdtech.jellyfin.fragments
+
+import android.os.Bundle
+import androidx.fragment.app.Fragment
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.fragment.app.viewModels
+import androidx.navigation.fragment.findNavController
+import com.google.android.material.snackbar.Snackbar
+import dagger.hilt.android.AndroidEntryPoint
+import dev.jdtech.jellyfin.R
+import dev.jdtech.jellyfin.adapters.FavoritesListAdapter
+import dev.jdtech.jellyfin.adapters.HomeEpisodeListAdapter
+import dev.jdtech.jellyfin.adapters.ViewItemListAdapter
+import dev.jdtech.jellyfin.databinding.FragmentFavoriteBinding
+import dev.jdtech.jellyfin.viewmodels.FavoriteViewModel
+import org.jellyfin.sdk.model.api.BaseItemDto
+
+@AndroidEntryPoint
+class FavoriteFragment : Fragment() {
+
+ private lateinit var binding: FragmentFavoriteBinding
+ private val viewModel: FavoriteViewModel by viewModels()
+
+ override fun onCreateView(
+ inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View {
+ binding = FragmentFavoriteBinding.inflate(inflater, container, false)
+
+ val snackbar =
+ Snackbar.make(
+ binding.mainLayout,
+ getString(R.string.error_loading_data),
+ Snackbar.LENGTH_INDEFINITE
+ )
+ snackbar.setAction(getString(R.string.retry)) {
+ viewModel.loadData()
+ }
+
+ binding.lifecycleOwner = viewLifecycleOwner
+ binding.viewModel = viewModel
+ binding.favoritesRecyclerView.adapter = FavoritesListAdapter(
+ ViewItemListAdapter.OnClickListener { item ->
+ navigateToMediaInfoFragment(item)
+ }, HomeEpisodeListAdapter.OnClickListener { item ->
+ navigateToEpisodeBottomSheetFragment(item)
+ })
+
+ viewModel.finishedLoading.observe(viewLifecycleOwner, { isFinished ->
+ binding.loadingIndicator.visibility = if (isFinished) View.GONE else View.VISIBLE
+ })
+
+ viewModel.error.observe(viewLifecycleOwner, { error ->
+ if (error) {
+ snackbar.show()
+ }
+ })
+
+ viewModel.favoriteSections.observe(viewLifecycleOwner, { sections ->
+ if (sections.isEmpty()) {
+ binding.noFavoritesText.visibility = View.VISIBLE
+ } else {
+ binding.noFavoritesText.visibility = View.GONE
+ }
+ })
+
+ return binding.root
+ }
+
+ private fun navigateToMediaInfoFragment(item: BaseItemDto) {
+ findNavController().navigate(
+ FavoriteFragmentDirections.actionFavoriteFragmentToMediaInfoFragment(
+ item.id,
+ item.name,
+ item.type ?: "Unknown"
+ )
+ )
+ }
+
+ private fun navigateToEpisodeBottomSheetFragment(episode: BaseItemDto) {
+ findNavController().navigate(
+ FavoriteFragmentDirections.actionFavoriteFragmentToEpisodeBottomSheetFragment(
+ episode.id
+ )
+ )
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/fragments/HomeFragment.kt b/app/src/main/java/dev/jdtech/jellyfin/fragments/HomeFragment.kt
new file mode 100644
index 0000000000..f2bc3b745e
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/fragments/HomeFragment.kt
@@ -0,0 +1,131 @@
+package dev.jdtech.jellyfin.fragments
+
+import android.os.Bundle
+import android.view.*
+import androidx.fragment.app.Fragment
+import androidx.fragment.app.viewModels
+import androidx.navigation.fragment.findNavController
+import com.google.android.material.snackbar.Snackbar
+import dagger.hilt.android.AndroidEntryPoint
+import dev.jdtech.jellyfin.R
+import dev.jdtech.jellyfin.adapters.HomeEpisodeListAdapter
+import dev.jdtech.jellyfin.adapters.ViewItemListAdapter
+import dev.jdtech.jellyfin.adapters.ViewListAdapter
+import dev.jdtech.jellyfin.databinding.FragmentHomeBinding
+import dev.jdtech.jellyfin.viewmodels.HomeViewModel
+import org.jellyfin.sdk.model.api.BaseItemDto
+
+@AndroidEntryPoint
+class HomeFragment : Fragment() {
+
+ private lateinit var binding: FragmentHomeBinding
+ private val viewModel: HomeViewModel by viewModels()
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setHasOptionsMenu(true)
+
+ findNavController().graph.startDestination = R.id.homeFragment
+ }
+
+ override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
+ inflater.inflate(R.menu.home_menu, menu)
+ }
+
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
+ return when (item.itemId) {
+ R.id.action_settings -> {
+ navigateToSettingsFragment()
+ true
+ }
+ else -> super.onOptionsItemSelected(item)
+ }
+ }
+
+ override fun onCreateView(
+ inflater: LayoutInflater,
+ container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View {
+ binding = FragmentHomeBinding.inflate(inflater, container, false)
+
+ val snackbar =
+ Snackbar.make(binding.mainLayout, getString(R.string.error_loading_data), Snackbar.LENGTH_INDEFINITE)
+ snackbar.setAction(getString(R.string.retry)) {
+ viewModel.loadData()
+ }
+
+ binding.lifecycleOwner = viewLifecycleOwner
+ binding.viewModel = viewModel
+ binding.viewsRecyclerView.adapter = ViewListAdapter(ViewListAdapter.OnClickListener {
+ navigateToLibraryFragment(it)
+ }, ViewItemListAdapter.OnClickListener {
+ navigateToMediaInfoFragment(it)
+ }, HomeEpisodeListAdapter.OnClickListener { item ->
+ when (item.type) {
+ "Episode" -> {
+ navigateToEpisodeBottomSheetFragment(item)
+ }
+ "Movie" -> {
+ navigateToMediaInfoFragment(item)
+ }
+ }
+
+ })
+
+ viewModel.finishedLoading.observe(viewLifecycleOwner, {
+ binding.loadingIndicator.visibility = if (it) View.GONE else View.VISIBLE
+ })
+
+ viewModel.error.observe(viewLifecycleOwner, { error ->
+ if (error) {
+ snackbar.show()
+ }
+ })
+
+ return binding.root
+ }
+
+ private fun navigateToLibraryFragment(view: dev.jdtech.jellyfin.models.View) {
+ findNavController().navigate(
+ HomeFragmentDirections.actionNavigationHomeToLibraryFragment(
+ view.id,
+ view.name
+ )
+ )
+ }
+
+ private fun navigateToMediaInfoFragment(item: BaseItemDto) {
+ if (item.type == "Episode") {
+ findNavController().navigate(
+ HomeFragmentDirections.actionNavigationHomeToMediaInfoFragment(
+ item.seriesId!!,
+ item.seriesName,
+ "Series"
+ )
+ )
+ } else {
+ findNavController().navigate(
+ HomeFragmentDirections.actionNavigationHomeToMediaInfoFragment(
+ item.id,
+ item.name,
+ item.type ?: "Unknown"
+ )
+ )
+ }
+ }
+
+ private fun navigateToEpisodeBottomSheetFragment(episode: BaseItemDto) {
+ findNavController().navigate(
+ HomeFragmentDirections.actionNavigationHomeToEpisodeBottomSheetFragment(
+ episode.id
+ )
+ )
+ }
+
+ private fun navigateToSettingsFragment() {
+ findNavController().navigate(
+ HomeFragmentDirections.actionNavigationHomeToNavigationSettings()
+ )
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/fragments/InitializingFragment.kt b/app/src/main/java/dev/jdtech/jellyfin/fragments/InitializingFragment.kt
new file mode 100644
index 0000000000..e30ba4805e
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/fragments/InitializingFragment.kt
@@ -0,0 +1,24 @@
+package dev.jdtech.jellyfin.fragments
+
+import android.os.Bundle
+import androidx.fragment.app.Fragment
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import dev.jdtech.jellyfin.R
+
+
+class InitializingFragment : Fragment() {
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ }
+
+ override fun onCreateView(
+ inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View? {
+ // Inflate the layout for this fragment
+ return inflater.inflate(R.layout.fragment_initializing, container, false)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/fragments/LibraryFragment.kt b/app/src/main/java/dev/jdtech/jellyfin/fragments/LibraryFragment.kt
new file mode 100644
index 0000000000..5858ca0637
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/fragments/LibraryFragment.kt
@@ -0,0 +1,78 @@
+package dev.jdtech.jellyfin.fragments
+
+import android.os.Bundle
+import androidx.fragment.app.Fragment
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.fragment.app.viewModels
+import androidx.navigation.fragment.findNavController
+import androidx.navigation.fragment.navArgs
+import com.google.android.material.snackbar.Snackbar
+import dagger.hilt.android.AndroidEntryPoint
+import dev.jdtech.jellyfin.R
+import dev.jdtech.jellyfin.viewmodels.LibraryViewModel
+import dev.jdtech.jellyfin.adapters.ViewItemListAdapter
+import dev.jdtech.jellyfin.databinding.FragmentLibraryBinding
+import org.jellyfin.sdk.model.api.BaseItemDto
+
+@AndroidEntryPoint
+class LibraryFragment : Fragment() {
+
+ private lateinit var binding: FragmentLibraryBinding
+ private val viewModel: LibraryViewModel by viewModels()
+
+ private val args: LibraryFragmentArgs by navArgs()
+
+ override fun onCreateView(
+ inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View {
+ binding = FragmentLibraryBinding.inflate(inflater, container, false)
+
+ binding.lifecycleOwner = viewLifecycleOwner
+
+ return binding.root
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+ binding.viewModel = viewModel
+
+ val snackbar =
+ Snackbar.make(
+ binding.mainLayout,
+ getString(R.string.error_loading_data),
+ Snackbar.LENGTH_INDEFINITE
+ )
+ snackbar.setAction(getString(R.string.retry)) {
+ viewModel.loadItems(args.libraryId)
+ }
+
+ viewModel.error.observe(viewLifecycleOwner, { error ->
+ if (error) {
+ snackbar.show()
+ }
+ })
+
+ viewModel.finishedLoading.observe(viewLifecycleOwner, {
+ binding.loadingIndicator.visibility = if (it) View.GONE else View.VISIBLE
+ })
+
+ binding.itemsRecyclerView.adapter =
+ ViewItemListAdapter(ViewItemListAdapter.OnClickListener { item ->
+ navigateToMediaInfoFragment(item)
+ })
+ viewModel.loadItems(args.libraryId)
+ }
+
+ private fun navigateToMediaInfoFragment(item: BaseItemDto) {
+ findNavController().navigate(
+ LibraryFragmentDirections.actionLibraryFragmentToMediaInfoFragment(
+ item.id,
+ item.name,
+ item.type ?: "Unknown"
+ )
+ )
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/fragments/LoginFragment.kt b/app/src/main/java/dev/jdtech/jellyfin/fragments/LoginFragment.kt
new file mode 100644
index 0000000000..61d9e6aa4d
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/fragments/LoginFragment.kt
@@ -0,0 +1,53 @@
+package dev.jdtech.jellyfin.fragments
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.fragment.app.Fragment
+import androidx.fragment.app.viewModels
+import androidx.navigation.fragment.findNavController
+import dagger.hilt.android.AndroidEntryPoint
+import dev.jdtech.jellyfin.databinding.FragmentLoginBinding
+import dev.jdtech.jellyfin.viewmodels.LoginViewModel
+
+@AndroidEntryPoint
+class LoginFragment : Fragment() {
+
+ private val viewModel: LoginViewModel by viewModels()
+
+ override fun onCreateView(
+ inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View {
+ val binding = FragmentLoginBinding.inflate(inflater)
+ binding.lifecycleOwner = viewLifecycleOwner
+ binding.viewModel = viewModel
+
+ binding.buttonLogin.setOnClickListener {
+ val username = binding.editTextUsername.text.toString()
+ val password = binding.editTextPassword.text.toString()
+
+ binding.progressCircular.visibility = View.VISIBLE
+ viewModel.login(username, password)
+ }
+
+ viewModel.error.observe(viewLifecycleOwner, {
+ binding.progressCircular.visibility = View.GONE
+ binding.editTextUsernameLayout.error = it
+ })
+
+ viewModel.navigateToMain.observe(viewLifecycleOwner, {
+ if (it) {
+ navigateToMainActivity()
+ }
+ })
+
+ return binding.root
+ }
+
+ private fun navigateToMainActivity() {
+ findNavController().navigate(LoginFragmentDirections.actionLoginFragment2ToNavigationHome())
+ viewModel.doneNavigatingToMain()
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/fragments/MediaFragment.kt b/app/src/main/java/dev/jdtech/jellyfin/fragments/MediaFragment.kt
new file mode 100644
index 0000000000..94a185eee4
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/fragments/MediaFragment.kt
@@ -0,0 +1,100 @@
+package dev.jdtech.jellyfin.fragments
+
+import android.os.Bundle
+import android.view.*
+import androidx.appcompat.widget.SearchView
+import androidx.fragment.app.Fragment
+import androidx.fragment.app.viewModels
+import androidx.navigation.fragment.findNavController
+import com.google.android.material.snackbar.Snackbar
+import dagger.hilt.android.AndroidEntryPoint
+import dev.jdtech.jellyfin.R
+import dev.jdtech.jellyfin.adapters.CollectionListAdapter
+import dev.jdtech.jellyfin.databinding.FragmentMediaBinding
+import dev.jdtech.jellyfin.viewmodels.MediaViewModel
+import org.jellyfin.sdk.model.api.BaseItemDto
+
+@AndroidEntryPoint
+class MediaFragment : Fragment() {
+
+ private lateinit var binding: FragmentMediaBinding
+ private val viewModel: MediaViewModel by viewModels()
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setHasOptionsMenu(true)
+ }
+
+ override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
+ inflater.inflate(R.menu.media_menu, menu)
+
+ val search = menu.findItem(R.id.action_search)
+ val searchView = search.actionView as SearchView
+ searchView.queryHint = "Search movies, shows, episodes..."
+
+ searchView.setOnQueryTextListener(object: SearchView.OnQueryTextListener {
+ override fun onQueryTextSubmit(p0: String?): Boolean {
+ if (p0 != null) {
+ navigateToSearchResultFragment(p0)
+ }
+ return true
+ }
+
+ override fun onQueryTextChange(p0: String?): Boolean {
+ return false
+ }
+ })
+ }
+
+ override fun onCreateView(
+ inflater: LayoutInflater,
+ container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View {
+ binding = FragmentMediaBinding.inflate(inflater, container, false)
+
+ val snackbar =
+ Snackbar.make(
+ binding.mainLayout,
+ getString(R.string.error_loading_data),
+ Snackbar.LENGTH_INDEFINITE
+ )
+ snackbar.setAction(getString(R.string.retry)) {
+ viewModel.loadData()
+ }
+
+ binding.lifecycleOwner = viewLifecycleOwner
+ binding.viewModel = viewModel
+ binding.viewsRecyclerView.adapter =
+ CollectionListAdapter(CollectionListAdapter.OnClickListener { library ->
+ navigateToLibraryFragment(library)
+ })
+
+ viewModel.finishedLoading.observe(viewLifecycleOwner, {
+ binding.loadingIndicator.visibility = if (it) View.GONE else View.VISIBLE
+ })
+
+ viewModel.error.observe(viewLifecycleOwner, { error ->
+ if (error) {
+ snackbar.show()
+ }
+ })
+
+ return binding.root
+ }
+
+ private fun navigateToLibraryFragment(library: BaseItemDto) {
+ findNavController().navigate(
+ MediaFragmentDirections.actionNavigationMediaToLibraryFragment(
+ library.id,
+ library.name
+ )
+ )
+ }
+
+ private fun navigateToSearchResultFragment(query: String) {
+ findNavController().navigate(
+ MediaFragmentDirections.actionNavigationMediaToSearchResultFragment(query)
+ )
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/fragments/MediaInfoFragment.kt b/app/src/main/java/dev/jdtech/jellyfin/fragments/MediaInfoFragment.kt
new file mode 100644
index 0000000000..6e6ac67306
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/fragments/MediaInfoFragment.kt
@@ -0,0 +1,217 @@
+package dev.jdtech.jellyfin.fragments
+
+import android.content.Intent
+import android.net.Uri
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.core.content.ContextCompat
+import androidx.fragment.app.Fragment
+import androidx.fragment.app.viewModels
+import androidx.navigation.fragment.findNavController
+import androidx.navigation.fragment.navArgs
+import com.google.android.material.snackbar.Snackbar
+import dagger.hilt.android.AndroidEntryPoint
+import dev.jdtech.jellyfin.R
+import dev.jdtech.jellyfin.adapters.PersonListAdapter
+import dev.jdtech.jellyfin.adapters.ViewItemListAdapter
+import dev.jdtech.jellyfin.databinding.FragmentMediaInfoBinding
+import dev.jdtech.jellyfin.dialogs.VideoVersionDialogFragment
+import dev.jdtech.jellyfin.models.PlayerItem
+import dev.jdtech.jellyfin.viewmodels.MediaInfoViewModel
+import org.jellyfin.sdk.model.api.BaseItemDto
+
+@AndroidEntryPoint
+class MediaInfoFragment : Fragment() {
+
+ private lateinit var binding: FragmentMediaInfoBinding
+ private val viewModel: MediaInfoViewModel by viewModels()
+
+ private val args: MediaInfoFragmentArgs by navArgs()
+
+ override fun onCreateView(
+ inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View {
+ binding = FragmentMediaInfoBinding.inflate(inflater, container, false)
+
+ binding.lifecycleOwner = viewLifecycleOwner
+
+ return binding.root
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+
+ val snackbar =
+ Snackbar.make(
+ binding.mainLayout,
+ getString(R.string.error_loading_data),
+ Snackbar.LENGTH_INDEFINITE
+ )
+ snackbar.setAction(getString(R.string.retry)) {
+ viewModel.loadData(args.itemId, args.itemType)
+ }
+
+ binding.viewModel = viewModel
+
+ viewModel.error.observe(viewLifecycleOwner, { error ->
+ if (error) {
+ snackbar.show()
+ }
+ })
+
+ viewModel.item.observe(viewLifecycleOwner, { item ->
+ if (item.originalTitle != item.name) {
+ binding.originalTitle.visibility = View.VISIBLE
+ } else {
+ binding.originalTitle.visibility = View.GONE
+ }
+ if (item.trailerCount != null && item.trailerCount!! < 1) {
+ binding.trailerButton.visibility = View.GONE
+ }
+ binding.communityRating.visibility = when (item.communityRating != null) {
+ true -> View.VISIBLE
+ false -> View.GONE
+ }
+ })
+
+ viewModel.actors.observe(viewLifecycleOwner, { actors ->
+ when (actors.isNullOrEmpty()) {
+ false -> binding.actors.visibility = View.VISIBLE
+ true -> binding.actors.visibility = View.GONE
+ }
+ })
+
+ viewModel.navigateToPlayer.observe(viewLifecycleOwner, { playerItems ->
+ if (playerItems != null) {
+ navigateToPlayerActivity(
+ playerItems,
+ viewModel.item.value!!.userData!!.playbackPositionTicks.div(10000)
+ )
+ viewModel.doneNavigatingToPlayer()
+ binding.playButton.setImageDrawable(ContextCompat.getDrawable(requireActivity(), R.drawable.ic_play))
+ binding.progressCircular.visibility = View.INVISIBLE
+ }
+ })
+
+ viewModel.played.observe(viewLifecycleOwner, {
+ val drawable = when (it) {
+ true -> R.drawable.ic_check_filled
+ false -> R.drawable.ic_check
+ }
+
+ binding.checkButton.setImageResource(drawable)
+ })
+
+ viewModel.favorite.observe(viewLifecycleOwner, {
+ val drawable = when (it) {
+ true -> R.drawable.ic_heart_filled
+ false -> R.drawable.ic_heart
+ }
+
+ binding.favoriteButton.setImageResource(drawable)
+ })
+
+ viewModel.playerItemsError.observe(viewLifecycleOwner, {
+ when (it) {
+ true -> {
+ binding.playerItemsError.visibility = View.VISIBLE
+ binding.playButton.setImageDrawable(ContextCompat.getDrawable(requireActivity(), R.drawable.ic_play))
+ binding.progressCircular.visibility = View.INVISIBLE
+ }
+ false -> binding.playerItemsError.visibility = View.GONE
+ }
+ })
+
+ binding.trailerButton.setOnClickListener {
+ val intent = Intent(
+ Intent.ACTION_VIEW,
+ Uri.parse(viewModel.item.value?.remoteTrailers?.get(0)?.url)
+ )
+ startActivity(intent)
+ }
+
+ binding.nextUp.setOnClickListener {
+ navigateToEpisodeBottomSheetFragment(viewModel.nextUp.value!!)
+ }
+
+ binding.seasonsRecyclerView.adapter =
+ ViewItemListAdapter(ViewItemListAdapter.OnClickListener { season ->
+ navigateToSeasonFragment(season)
+ }, fixedWidth = true)
+ binding.peopleRecyclerView.adapter = PersonListAdapter()
+
+ binding.playButton.setOnClickListener {
+ binding.playButton.setImageResource(android.R.color.transparent)
+ binding.progressCircular.visibility = View.VISIBLE
+ if (args.itemType == "Movie") {
+ if (!viewModel.mediaSources.value.isNullOrEmpty()) {
+ if (viewModel.mediaSources.value!!.size > 1) {
+ VideoVersionDialogFragment(viewModel).show(
+ parentFragmentManager,
+ "videoversiondialog"
+ )
+ } else {
+ navigateToPlayerActivity(
+ arrayOf(PlayerItem(args.itemId, viewModel.mediaSources.value!![0].id!!)),
+ viewModel.item.value!!.userData!!.playbackPositionTicks.div(10000),
+ )
+ binding.playButton.setImageDrawable(ContextCompat.getDrawable(requireActivity(), R.drawable.ic_play))
+ binding.progressCircular.visibility = View.INVISIBLE
+ }
+ }
+ } else if (args.itemType == "Series") {
+ viewModel.preparePlayer()
+ }
+ }
+
+ binding.checkButton.setOnClickListener {
+ when (viewModel.played.value) {
+ true -> viewModel.markAsUnplayed(args.itemId)
+ false -> viewModel.markAsPlayed(args.itemId)
+ }
+ }
+
+ binding.favoriteButton.setOnClickListener {
+ when (viewModel.favorite.value) {
+ true -> viewModel.unmarkAsFavorite(args.itemId)
+ false -> viewModel.markAsFavorite(args.itemId)
+ }
+ }
+
+ viewModel.loadData(args.itemId, args.itemType)
+ }
+
+ private fun navigateToEpisodeBottomSheetFragment(episode: BaseItemDto) {
+ findNavController().navigate(
+ MediaInfoFragmentDirections.actionMediaInfoFragmentToEpisodeBottomSheetFragment(
+ episode.id
+ )
+ )
+ }
+
+ private fun navigateToSeasonFragment(season: BaseItemDto) {
+ findNavController().navigate(
+ MediaInfoFragmentDirections.actionMediaInfoFragmentToSeasonFragment(
+ season.seriesId!!,
+ season.id,
+ season.seriesName,
+ season.name
+ )
+ )
+ }
+
+ private fun navigateToPlayerActivity(
+ playerItems: Array,
+ playbackPosition: Long,
+ ) {
+ findNavController().navigate(
+ MediaInfoFragmentDirections.actionMediaInfoFragmentToPlayerActivity(
+ playerItems,
+ playbackPosition
+ )
+ )
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/fragments/SearchResultFragment.kt b/app/src/main/java/dev/jdtech/jellyfin/fragments/SearchResultFragment.kt
new file mode 100644
index 0000000000..ca1b637458
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/fragments/SearchResultFragment.kt
@@ -0,0 +1,94 @@
+package dev.jdtech.jellyfin.fragments
+
+import android.os.Bundle
+import androidx.fragment.app.Fragment
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.fragment.app.viewModels
+import androidx.navigation.fragment.findNavController
+import androidx.navigation.fragment.navArgs
+import com.google.android.material.snackbar.Snackbar
+import dagger.hilt.android.AndroidEntryPoint
+import dev.jdtech.jellyfin.R
+import dev.jdtech.jellyfin.adapters.FavoritesListAdapter
+import dev.jdtech.jellyfin.adapters.HomeEpisodeListAdapter
+import dev.jdtech.jellyfin.adapters.ViewItemListAdapter
+import dev.jdtech.jellyfin.databinding.FragmentSearchResultBinding
+import dev.jdtech.jellyfin.viewmodels.SearchResultViewModel
+import org.jellyfin.sdk.model.api.BaseItemDto
+
+@AndroidEntryPoint
+class SearchResultFragment : Fragment() {
+
+ private lateinit var binding: FragmentSearchResultBinding
+ private val viewModel: SearchResultViewModel by viewModels()
+
+ private val args: SearchResultFragmentArgs by navArgs()
+
+ override fun onCreateView(
+ inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View {
+ binding = FragmentSearchResultBinding.inflate(inflater, container, false)
+
+ val snackbar =
+ Snackbar.make(
+ binding.mainLayout,
+ getString(R.string.error_loading_data),
+ Snackbar.LENGTH_INDEFINITE
+ )
+ snackbar.setAction(getString(R.string.retry)) {
+ viewModel.loadData(args.query)
+ }
+
+ binding.lifecycleOwner = viewLifecycleOwner
+ binding.viewModel = viewModel
+ binding.searchResultsRecyclerView.adapter = FavoritesListAdapter(
+ ViewItemListAdapter.OnClickListener { item ->
+ navigateToMediaInfoFragment(item)
+ }, HomeEpisodeListAdapter.OnClickListener { item ->
+ navigateToEpisodeBottomSheetFragment(item)
+ })
+
+ viewModel.finishedLoading.observe(viewLifecycleOwner, { isFinished ->
+ binding.loadingIndicator.visibility = if (isFinished) View.GONE else View.VISIBLE
+ })
+
+ viewModel.error.observe(viewLifecycleOwner, { error ->
+ if (error) {
+ snackbar.show()
+ }
+ })
+
+ viewModel.sections.observe(viewLifecycleOwner, { sections ->
+ if (sections.isEmpty()) {
+ binding.noSearchResultsText.visibility = View.VISIBLE
+ } else {
+ binding.noSearchResultsText.visibility = View.GONE
+ }
+ })
+
+ viewModel.loadData(args.query)
+
+ return binding.root
+ }
+
+ private fun navigateToMediaInfoFragment(item: BaseItemDto) {
+ findNavController().navigate(
+ FavoriteFragmentDirections.actionFavoriteFragmentToMediaInfoFragment(
+ item.id,
+ item.name,
+ item.type ?: "Unknown"
+ )
+ )
+ }
+
+ private fun navigateToEpisodeBottomSheetFragment(episode: BaseItemDto) {
+ findNavController().navigate(
+ FavoriteFragmentDirections.actionFavoriteFragmentToEpisodeBottomSheetFragment(
+ episode.id
+ )
+ )
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/fragments/SeasonFragment.kt b/app/src/main/java/dev/jdtech/jellyfin/fragments/SeasonFragment.kt
new file mode 100644
index 0000000000..325008679a
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/fragments/SeasonFragment.kt
@@ -0,0 +1,75 @@
+package dev.jdtech.jellyfin.fragments
+
+import android.os.Bundle
+import androidx.fragment.app.Fragment
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.fragment.app.viewModels
+import androidx.navigation.fragment.findNavController
+import androidx.navigation.fragment.navArgs
+import com.google.android.material.snackbar.Snackbar
+import dagger.hilt.android.AndroidEntryPoint
+import dev.jdtech.jellyfin.R
+import dev.jdtech.jellyfin.adapters.EpisodeListAdapter
+import dev.jdtech.jellyfin.databinding.FragmentSeasonBinding
+import dev.jdtech.jellyfin.viewmodels.SeasonViewModel
+import org.jellyfin.sdk.model.api.BaseItemDto
+
+@AndroidEntryPoint
+class SeasonFragment : Fragment() {
+
+ private lateinit var binding: FragmentSeasonBinding
+ private val viewModel: SeasonViewModel by viewModels()
+
+ private val args: SeasonFragmentArgs by navArgs()
+
+ override fun onCreateView(
+ inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View {
+ binding = FragmentSeasonBinding.inflate(inflater, container, false)
+ binding.lifecycleOwner = viewLifecycleOwner
+ return binding.root
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+ binding.viewModel = viewModel
+
+ val snackbar =
+ Snackbar.make(
+ binding.mainLayout,
+ getString(R.string.error_loading_data),
+ Snackbar.LENGTH_INDEFINITE
+ )
+ snackbar.setAction(getString(R.string.retry)) {
+ viewModel.loadEpisodes(args.seriesId, args.seasonId)
+ }
+
+ viewModel.error.observe(viewLifecycleOwner, { error ->
+ if (error) {
+ snackbar.show()
+ }
+ })
+
+ viewModel.finishedLoading.observe(viewLifecycleOwner, {
+ binding.loadingIndicator.visibility = if (it) View.GONE else View.VISIBLE
+ })
+
+ binding.episodesRecyclerView.adapter =
+ EpisodeListAdapter(EpisodeListAdapter.OnClickListener { episode ->
+ navigateToEpisodeBottomSheetFragment(episode)
+ }, args.seriesId, args.seriesName, args.seasonId, args.seasonName)
+
+ viewModel.loadEpisodes(args.seriesId, args.seasonId)
+ }
+
+ private fun navigateToEpisodeBottomSheetFragment(episode: BaseItemDto) {
+ findNavController().navigate(
+ SeasonFragmentDirections.actionSeasonFragmentToEpisodeBottomSheetFragment(
+ episode.id
+ )
+ )
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/fragments/ServerSelectFragment.kt b/app/src/main/java/dev/jdtech/jellyfin/fragments/ServerSelectFragment.kt
new file mode 100644
index 0000000000..d082b14503
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/fragments/ServerSelectFragment.kt
@@ -0,0 +1,67 @@
+package dev.jdtech.jellyfin.fragments
+
+import android.os.Bundle
+import androidx.fragment.app.Fragment
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.fragment.app.viewModels
+import androidx.navigation.fragment.findNavController
+import dagger.hilt.android.AndroidEntryPoint
+import dev.jdtech.jellyfin.R
+import dev.jdtech.jellyfin.databinding.FragmentServerSelectBinding
+import dev.jdtech.jellyfin.dialogs.DeleteServerDialogFragment
+import dev.jdtech.jellyfin.adapters.ServerGridAdapter
+import dev.jdtech.jellyfin.viewmodels.ServerSelectViewModel
+
+@AndroidEntryPoint
+class ServerSelectFragment : Fragment() {
+
+ private lateinit var binding: FragmentServerSelectBinding
+ private val viewModel: ServerSelectViewModel by viewModels()
+
+ override fun onCreateView(
+ inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View {
+ binding = FragmentServerSelectBinding.inflate(inflater)
+
+ binding.lifecycleOwner = viewLifecycleOwner
+
+ binding.viewModel = viewModel
+
+ binding.serversRecyclerView.adapter =
+ ServerGridAdapter(ServerGridAdapter.OnClickListener { server ->
+ viewModel.connectToServer(server)
+ }, ServerGridAdapter.OnLongClickListener { server ->
+ DeleteServerDialogFragment(viewModel, server).show(
+ parentFragmentManager,
+ "deleteServer"
+ )
+ true
+ })
+
+ binding.buttonAddServer.setOnClickListener {
+ navigateToAddServerFragment()
+ }
+
+ viewModel.navigateToMain.observe(viewLifecycleOwner, {
+ if (it) {
+ navigateToMainActivity()
+ }
+ })
+
+ return binding.root
+ }
+
+ private fun navigateToAddServerFragment() {
+ findNavController().navigate(
+ ServerSelectFragmentDirections.actionServerSelectFragment2ToAddServerFragment3()
+ )
+ }
+
+ private fun navigateToMainActivity() {
+ findNavController().navigate(ServerSelectFragmentDirections.actionServerSelectFragmentToHomeFragment())
+ viewModel.doneNavigatingToMain()
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/fragments/SettingsFragment.kt b/app/src/main/java/dev/jdtech/jellyfin/fragments/SettingsFragment.kt
new file mode 100644
index 0000000000..9fd43144f1
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/fragments/SettingsFragment.kt
@@ -0,0 +1,46 @@
+package dev.jdtech.jellyfin.fragments
+
+import android.content.Intent
+import android.net.Uri
+import android.os.Bundle
+import androidx.appcompat.app.AppCompatDelegate.*
+import androidx.navigation.fragment.findNavController
+import androidx.preference.ListPreference
+import androidx.preference.Preference
+import androidx.preference.PreferenceFragmentCompat
+import com.google.android.gms.oss.licenses.OssLicensesMenuActivity
+import dev.jdtech.jellyfin.R
+
+class SettingsFragment : PreferenceFragmentCompat() {
+ override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
+ setPreferencesFromResource(R.xml.fragment_settings, rootKey)
+
+ findPreference("switchServer")?.setOnPreferenceClickListener {
+ findNavController().navigate(SettingsFragmentDirections.actionNavigationSettingsToServerSelectFragment2())
+ true
+ }
+
+ findPreference("theme")?.setOnPreferenceChangeListener { _, newValue ->
+ when (newValue) {
+ "system" -> setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM)
+ "light" -> setDefaultNightMode(MODE_NIGHT_NO)
+ "dark" -> setDefaultNightMode(MODE_NIGHT_YES)
+ }
+ true
+ }
+
+ findPreference("privacyPolicy")?.setOnPreferenceClickListener {
+ val intent = Intent(
+ Intent.ACTION_VIEW,
+ Uri.parse("https://github.com/jarnedemeulemeester/findroid/blob/main/PRIVACY")
+ )
+ startActivity(intent)
+ true
+ }
+
+ findPreference("ossLicenses")?.setOnPreferenceClickListener {
+ startActivity(Intent(requireContext(), OssLicensesMenuActivity::class.java))
+ true
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/models/FavoriteSection.kt b/app/src/main/java/dev/jdtech/jellyfin/models/FavoriteSection.kt
new file mode 100644
index 0000000000..57279f9938
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/models/FavoriteSection.kt
@@ -0,0 +1,10 @@
+package dev.jdtech.jellyfin.models
+
+import org.jellyfin.sdk.model.api.BaseItemDto
+import java.util.*
+
+data class FavoriteSection(
+ val id: UUID,
+ val name: String,
+ var items: List
+)
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/models/HomeSection.kt b/app/src/main/java/dev/jdtech/jellyfin/models/HomeSection.kt
new file mode 100644
index 0000000000..dc1d1998f5
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/models/HomeSection.kt
@@ -0,0 +1,10 @@
+package dev.jdtech.jellyfin.models
+
+import org.jellyfin.sdk.model.api.BaseItemDto
+import java.util.*
+
+data class HomeSection(
+ val id: UUID,
+ val name: String?,
+ var items: List? = null
+)
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/models/PlayerItem.kt b/app/src/main/java/dev/jdtech/jellyfin/models/PlayerItem.kt
new file mode 100644
index 0000000000..0f6852d472
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/models/PlayerItem.kt
@@ -0,0 +1,11 @@
+package dev.jdtech.jellyfin.models
+
+import android.os.Parcelable
+import kotlinx.parcelize.Parcelize
+import java.util.*
+
+@Parcelize
+data class PlayerItem(
+ val itemId: UUID,
+ val mediaSourceId: String
+) : Parcelable
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/models/View.kt b/app/src/main/java/dev/jdtech/jellyfin/models/View.kt
new file mode 100644
index 0000000000..7c88dd6b41
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/models/View.kt
@@ -0,0 +1,10 @@
+package dev.jdtech.jellyfin.models
+
+import org.jellyfin.sdk.model.api.BaseItemDto
+import java.util.*
+
+data class View(
+ val id: UUID,
+ val name: String?,
+ var items: List? = null
+)
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/repository/JellyfinRepository.kt b/app/src/main/java/dev/jdtech/jellyfin/repository/JellyfinRepository.kt
new file mode 100644
index 0000000000..84ed47815c
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/repository/JellyfinRepository.kt
@@ -0,0 +1,53 @@
+package dev.jdtech.jellyfin.repository
+
+import org.jellyfin.sdk.model.api.BaseItemDto
+import org.jellyfin.sdk.model.api.ItemFields
+import org.jellyfin.sdk.model.api.MediaSourceInfo
+import java.util.*
+
+interface JellyfinRepository {
+ suspend fun getUserViews(): List
+
+ suspend fun getItem(itemId: UUID): BaseItemDto
+
+ suspend fun getItems(parentId: UUID? = null): List
+
+ suspend fun getFavoriteItems(): List
+
+ suspend fun getSearchItems(searchQuery: String): List
+
+ suspend fun getResumeItems(): List
+
+ suspend fun getLatestMedia(parentId: UUID): List
+
+ suspend fun getSeasons(seriesId: UUID): List
+
+ suspend fun getNextUp(seriesId: UUID? = null): List
+
+ suspend fun getEpisodes(
+ seriesId: UUID,
+ seasonId: UUID,
+ fields: List? = null,
+ startIndex: Int? = null
+ ): List
+
+ suspend fun getMediaSources(itemId: UUID): List
+
+ suspend fun getStreamUrl(itemId: UUID, mediaSourceId: String): String
+
+ suspend fun postCapabilities()
+
+ suspend fun postPlaybackStart(itemId: UUID)
+
+ suspend fun postPlaybackStop(itemId: UUID, positionTicks: Long)
+
+ suspend fun postPlaybackProgress(itemId: UUID, positionTicks: Long, isPaused: Boolean)
+
+ suspend fun markAsFavorite(itemId: UUID)
+
+ suspend fun unmarkAsFavorite(itemId: UUID)
+
+ suspend fun markAsPlayed(itemId: UUID)
+
+ suspend fun markAsUnplayed(itemId: UUID)
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/repository/JellyfinRepositoryImpl.kt b/app/src/main/java/dev/jdtech/jellyfin/repository/JellyfinRepositoryImpl.kt
new file mode 100644
index 0000000000..297def3924
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/repository/JellyfinRepositoryImpl.kt
@@ -0,0 +1,260 @@
+package dev.jdtech.jellyfin.repository
+
+import dev.jdtech.jellyfin.api.JellyfinApi
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.withContext
+import org.jellyfin.sdk.model.api.*
+import timber.log.Timber
+import java.util.*
+
+class JellyfinRepositoryImpl(private val jellyfinApi: JellyfinApi) : JellyfinRepository {
+ override suspend fun getUserViews(): List {
+ val views: List
+ withContext(Dispatchers.IO) {
+ views =
+ jellyfinApi.viewsApi.getUserViews(jellyfinApi.userId!!).content.items ?: listOf()
+ }
+ return views
+ }
+
+ override suspend fun getItem(itemId: UUID): BaseItemDto {
+ val item: BaseItemDto
+ withContext(Dispatchers.IO) {
+ item = jellyfinApi.userLibraryApi.getItem(jellyfinApi.userId!!, itemId).content
+ }
+ return item
+ }
+
+ override suspend fun getItems(parentId: UUID?): List {
+ val items: List
+ withContext(Dispatchers.IO) {
+ items = jellyfinApi.itemsApi.getItems(
+ jellyfinApi.userId!!,
+ parentId = parentId
+ ).content.items ?: listOf()
+ }
+ return items
+ }
+
+ override suspend fun getFavoriteItems(): List {
+ val items: List
+ withContext(Dispatchers.IO) {
+ items = jellyfinApi.itemsApi.getItems(
+ jellyfinApi.userId!!,
+ filters = listOf(ItemFilter.IS_FAVORITE),
+ includeItemTypes = listOf("Movie", "Series", "Episode"),
+ recursive = true
+ ).content.items ?: listOf()
+ }
+ return items
+ }
+
+ override suspend fun getSearchItems(searchQuery: String): List {
+ val items: List
+ withContext(Dispatchers.IO) {
+ items = jellyfinApi.itemsApi.getItems(
+ jellyfinApi.userId!!,
+ searchTerm = searchQuery,
+ includeItemTypes = listOf("Movie", "Series", "Episode"),
+ recursive = true
+ ).content.items ?: listOf()
+ }
+ return items
+ }
+
+ override suspend fun getResumeItems(): List {
+ val items: List
+ withContext(Dispatchers.IO) {
+ items =
+ jellyfinApi.itemsApi.getResumeItems(jellyfinApi.userId!!).content.items ?: listOf()
+ }
+ return items
+ }
+
+ override suspend fun getLatestMedia(parentId: UUID): List {
+ val items: List
+ withContext(Dispatchers.IO) {
+ items = jellyfinApi.userLibraryApi.getLatestMedia(
+ jellyfinApi.userId!!,
+ parentId = parentId
+ ).content
+ }
+ return items
+ }
+
+ override suspend fun getSeasons(seriesId: UUID): List {
+ val seasons: List
+ withContext(Dispatchers.IO) {
+ seasons = jellyfinApi.showsApi.getSeasons(seriesId, jellyfinApi.userId!!).content.items
+ ?: listOf()
+ }
+ return seasons
+ }
+
+ override suspend fun getNextUp(seriesId: UUID?): List {
+ val nextUpItems: List
+ withContext(Dispatchers.IO) {
+ nextUpItems = jellyfinApi.showsApi.getNextUp(
+ jellyfinApi.userId!!,
+ seriesId = seriesId?.toString(),
+ ).content.items ?: listOf()
+ }
+ return nextUpItems
+ }
+
+ override suspend fun getEpisodes(
+ seriesId: UUID,
+ seasonId: UUID,
+ fields: List?,
+ startIndex: Int?
+ ): List {
+ val episodes: List
+ withContext(Dispatchers.IO) {
+ episodes = jellyfinApi.showsApi.getEpisodes(
+ seriesId,
+ jellyfinApi.userId!!,
+ seasonId = seasonId,
+ fields = fields,
+ startIndex = startIndex
+ ).content.items ?: listOf()
+ }
+ return episodes
+ }
+
+ override suspend fun getMediaSources(itemId: UUID): List {
+ val mediaSourceInfoList: List
+ val mediaInfo by jellyfinApi.mediaInfoApi.getPostedPlaybackInfo(
+ itemId, PlaybackInfoDto(
+ userId = jellyfinApi.userId!!,
+ deviceProfile = DeviceProfile(
+ name = "Direct play all",
+ maxStaticBitrate = 1_000_000_000,
+ maxStreamingBitrate = 1_000_000_000,
+ codecProfiles = listOf(),
+ containerProfiles = listOf(),
+ directPlayProfiles = listOf(
+ DirectPlayProfile(
+ type = DlnaProfileType.VIDEO
+ ), DirectPlayProfile(type = DlnaProfileType.AUDIO)
+ ),
+ transcodingProfiles = listOf(),
+ responseProfiles = listOf(),
+ enableAlbumArtInDidl = false,
+ enableMsMediaReceiverRegistrar = false,
+ enableSingleAlbumArtLimit = false,
+ enableSingleSubtitleLimit = false,
+ ignoreTranscodeByteRangeRequests = false,
+ maxAlbumArtHeight = 1_000_000_000,
+ maxAlbumArtWidth = 1_000_000_000,
+ requiresPlainFolders = false,
+ requiresPlainVideoItems = false,
+ timelineOffsetSeconds = 0
+ ),
+ startTimeTicks = null,
+ audioStreamIndex = null,
+ subtitleStreamIndex = null,
+ maxStreamingBitrate = 1_000_000_000,
+ )
+ )
+ mediaSourceInfoList = mediaInfo.mediaSources ?: listOf()
+ return mediaSourceInfoList
+ }
+
+ override suspend fun getStreamUrl(itemId: UUID, mediaSourceId: String): String {
+ var streamUrl = ""
+ withContext(Dispatchers.IO) {
+ try {
+ streamUrl = jellyfinApi.videosApi.getVideoStreamUrl(
+ itemId,
+ static = true,
+ mediaSourceId = mediaSourceId
+ )
+ } catch (e: Exception) {
+ Timber.e(e)
+ }
+ }
+ return streamUrl
+ }
+
+ override suspend fun postCapabilities() {
+ Timber.d("Sending capabilities")
+ withContext(Dispatchers.IO) {
+ jellyfinApi.sessionApi.postCapabilities(
+ playableMediaTypes = listOf("Video"),
+ supportedCommands = listOf(
+ GeneralCommandType.VOLUME_UP,
+ GeneralCommandType.VOLUME_DOWN,
+ GeneralCommandType.TOGGLE_MUTE,
+ GeneralCommandType.SET_AUDIO_STREAM_INDEX,
+ GeneralCommandType.SET_SUBTITLE_STREAM_INDEX,
+ GeneralCommandType.MUTE,
+ GeneralCommandType.UNMUTE,
+ GeneralCommandType.SET_VOLUME,
+ GeneralCommandType.DISPLAY_MESSAGE,
+ GeneralCommandType.PLAY,
+ GeneralCommandType.PLAY_STATE,
+ GeneralCommandType.PLAY_NEXT,
+ GeneralCommandType.PLAY_MEDIA_SOURCE
+ ), supportsMediaControl = true
+ )
+ }
+ }
+
+ override suspend fun postPlaybackStart(itemId: UUID) {
+ Timber.d("Sending start $itemId")
+ withContext(Dispatchers.IO) {
+ jellyfinApi.playStateApi.onPlaybackStart(jellyfinApi.userId!!, itemId)
+ }
+ }
+
+ override suspend fun postPlaybackStop(itemId: UUID, positionTicks: Long) {
+ Timber.d("Sending stop $itemId")
+ withContext(Dispatchers.IO) {
+ jellyfinApi.playStateApi.onPlaybackStopped(
+ jellyfinApi.userId!!,
+ itemId,
+ positionTicks = positionTicks
+ )
+ }
+ }
+
+ override suspend fun postPlaybackProgress(
+ itemId: UUID,
+ positionTicks: Long,
+ isPaused: Boolean
+ ) {
+ Timber.d("Posting progress of $itemId, position: $positionTicks")
+ withContext(Dispatchers.IO) {
+ jellyfinApi.playStateApi.onPlaybackProgress(
+ jellyfinApi.userId!!,
+ itemId,
+ positionTicks = positionTicks,
+ isPaused = isPaused
+ )
+ }
+ }
+
+ override suspend fun markAsFavorite(itemId: UUID) {
+ withContext(Dispatchers.IO) {
+ jellyfinApi.userLibraryApi.markFavoriteItem(jellyfinApi.userId!!, itemId)
+ }
+ }
+
+ override suspend fun unmarkAsFavorite(itemId: UUID) {
+ withContext(Dispatchers.IO) {
+ jellyfinApi.userLibraryApi.unmarkFavoriteItem(jellyfinApi.userId!!, itemId)
+ }
+ }
+
+ override suspend fun markAsPlayed(itemId: UUID) {
+ withContext(Dispatchers.IO) {
+ jellyfinApi.playStateApi.markPlayedItem(jellyfinApi.userId!!, itemId)
+ }
+ }
+
+ override suspend fun markAsUnplayed(itemId: UUID) {
+ withContext(Dispatchers.IO) {
+ jellyfinApi.playStateApi.markUnplayedItem(jellyfinApi.userId!!, itemId)
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/utils/VersionPreference.kt b/app/src/main/java/dev/jdtech/jellyfin/utils/VersionPreference.kt
new file mode 100644
index 0000000000..7ce9e9fcd5
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/utils/VersionPreference.kt
@@ -0,0 +1,14 @@
+package dev.jdtech.jellyfin.utils
+
+import android.content.Context
+import android.util.AttributeSet
+import androidx.preference.Preference
+
+class VersionPreference(context: Context, attrs: AttributeSet): Preference(context, attrs) {
+ init {
+ val packageManager = context.packageManager
+ val packageInfo = packageManager.getPackageInfo(context.packageName, 0)
+ val versionName = packageInfo.versionName
+ summary = versionName
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/utils/extensions.kt b/app/src/main/java/dev/jdtech/jellyfin/utils/extensions.kt
new file mode 100644
index 0000000000..fd2e2892ad
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/utils/extensions.kt
@@ -0,0 +1,11 @@
+package dev.jdtech.jellyfin.utils
+
+import dev.jdtech.jellyfin.models.View
+import org.jellyfin.sdk.model.api.BaseItemDto
+
+fun BaseItemDto.toView(): View {
+ return View(
+ id = id,
+ name = name
+ )
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/viewmodels/AddServerViewModel.kt b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/AddServerViewModel.kt
new file mode 100644
index 0000000000..829d6dc50f
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/AddServerViewModel.kt
@@ -0,0 +1,88 @@
+package dev.jdtech.jellyfin.viewmodels
+
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.MutableLiveData
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import dagger.hilt.android.lifecycle.HiltViewModel
+import dev.jdtech.jellyfin.api.JellyfinApi
+import dev.jdtech.jellyfin.database.Server
+import dev.jdtech.jellyfin.database.ServerDatabaseDao
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
+import timber.log.Timber
+import javax.inject.Inject
+
+@HiltViewModel
+class AddServerViewModel
+@Inject
+constructor(
+ private val jellyfinApi: JellyfinApi,
+ private val database: ServerDatabaseDao
+) : ViewModel() {
+
+ private val _navigateToLogin = MutableLiveData()
+ val navigateToLogin: LiveData = _navigateToLogin
+
+ private val _error = MutableLiveData()
+ val error: LiveData = _error
+
+ /**
+ * Run multiple check on the server before continuing:
+ *
+ * - Connect to server and check if it is a Jellyfin server
+ * - Check if server is not already in Database
+ */
+ fun checkServer(baseUrl: String) {
+ _error.value = null
+
+ viewModelScope.launch {
+ jellyfinApi.apply {
+ api.baseUrl = baseUrl
+ api.accessToken = null
+ }
+ try {
+ val publicSystemInfo by jellyfinApi.systemApi.getPublicSystemInfo()
+ Timber.d("Remote server: ${publicSystemInfo.id}")
+
+ if (serverAlreadyInDatabase(publicSystemInfo.id)) {
+ _error.value = "Server already added"
+ _navigateToLogin.value = false
+ } else {
+ _error.value = null
+ _navigateToLogin.value = true
+ }
+ } catch (e: Exception) {
+ Timber.e(e)
+ _error.value = e.message
+ _navigateToLogin.value = false
+ }
+ }
+ }
+
+ /**
+ * Check if server is already in database using server ID
+ *
+ * @param id Server ID
+ * @return True if server is already in database
+ */
+ private suspend fun serverAlreadyInDatabase(id: String?): Boolean {
+ val servers: List
+ withContext(Dispatchers.IO) {
+ servers = database.getAllServersSync()
+ }
+ for (server in servers) {
+ Timber.d("Database server: ${server.id}")
+ if (server.id == id) {
+ Timber.w("Server already in the database")
+ return true
+ }
+ }
+ return false
+ }
+
+ fun onNavigateToLoginDone() {
+ _navigateToLogin.value = false
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/viewmodels/EpisodeBottomSheetViewModel.kt b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/EpisodeBottomSheetViewModel.kt
new file mode 100644
index 0000000000..51422e83eb
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/EpisodeBottomSheetViewModel.kt
@@ -0,0 +1,130 @@
+package dev.jdtech.jellyfin.viewmodels
+
+import android.os.Build
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.MutableLiveData
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import dagger.hilt.android.lifecycle.HiltViewModel
+import dev.jdtech.jellyfin.models.PlayerItem
+import dev.jdtech.jellyfin.repository.JellyfinRepository
+import kotlinx.coroutines.launch
+import org.jellyfin.sdk.model.api.BaseItemDto
+import timber.log.Timber
+import java.text.DateFormat
+import java.time.ZoneOffset
+import java.util.*
+import javax.inject.Inject
+
+@HiltViewModel
+class EpisodeBottomSheetViewModel
+@Inject
+constructor(
+ private val jellyfinRepository: JellyfinRepository
+) : ViewModel() {
+
+ private val _item = MutableLiveData()
+ val item: LiveData = _item
+
+ private val _runTime = MutableLiveData()
+ val runTime: LiveData = _runTime
+
+ private val _dateString = MutableLiveData()
+ val dateString: LiveData = _dateString
+
+ private val _played = MutableLiveData()
+ val played: LiveData = _played
+
+ private val _favorite = MutableLiveData()
+ val favorite: LiveData = _favorite
+
+ private val _navigateToPlayer = MutableLiveData()
+ val navigateToPlayer: LiveData = _navigateToPlayer
+
+ var playerItems: MutableList = mutableListOf()
+
+ private val _playerItemsError = MutableLiveData()
+ val playerItemsError: LiveData = _playerItemsError
+
+ fun loadEpisode(episodeId: UUID) {
+ viewModelScope.launch {
+ try {
+ val item = jellyfinRepository.getItem(episodeId)
+ _item.value = item
+ _runTime.value = "${item.runTimeTicks?.div(600000000)} min"
+ _dateString.value = getDateString(item)
+ _played.value = item.userData?.played
+ _favorite.value = item.userData?.isFavorite
+ } catch (e: Exception) {
+ Timber.e(e)
+ }
+ }
+ }
+
+ fun preparePlayer() {
+ _playerItemsError.value = false
+ viewModelScope.launch {
+ try {
+ createPlayerItems(_item.value!!)
+ _navigateToPlayer.value = true
+ } catch (e: Exception) {
+ _playerItemsError.value = true
+ }
+ }
+ }
+
+ private suspend fun createPlayerItems(startEpisode: BaseItemDto) {
+ val episodes = jellyfinRepository.getEpisodes(
+ startEpisode.seriesId!!,
+ startEpisode.seasonId!!,
+ startIndex = startEpisode.indexNumber?.minus(1)
+ )
+ for (episode in episodes) {
+ val mediaSources = jellyfinRepository.getMediaSources(episode.id)
+ playerItems.add(PlayerItem(episode.id, mediaSources[0].id!!))
+ }
+ }
+
+ fun markAsPlayed(itemId: UUID) {
+ viewModelScope.launch {
+ jellyfinRepository.markAsPlayed(itemId)
+ }
+ _played.value = true
+ }
+
+ fun markAsUnplayed(itemId: UUID) {
+ viewModelScope.launch {
+ jellyfinRepository.markAsUnplayed(itemId)
+ }
+ _played.value = false
+ }
+
+ fun markAsFavorite(itemId: UUID) {
+ viewModelScope.launch {
+ jellyfinRepository.markAsFavorite(itemId)
+ }
+ _favorite.value = true
+ }
+
+ fun unmarkAsFavorite(itemId: UUID) {
+ viewModelScope.launch {
+ jellyfinRepository.unmarkAsFavorite(itemId)
+ }
+ _favorite.value = false
+ }
+
+ private fun getDateString(item: BaseItemDto): String {
+ return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ val instant = item.premiereDate?.toInstant(ZoneOffset.UTC)
+ val date = Date.from(instant)
+ DateFormat.getDateInstance(DateFormat.SHORT).format(date)
+ } else {
+ // TODO: Implement a way to get the year from LocalDateTime in Android < O
+ item.premiereDate.toString()
+ }
+ }
+
+ fun doneNavigateToPlayer() {
+ _navigateToPlayer.value = false
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/viewmodels/FavoriteViewModel.kt b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/FavoriteViewModel.kt
new file mode 100644
index 0000000000..e9138d0994
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/FavoriteViewModel.kt
@@ -0,0 +1,86 @@
+package dev.jdtech.jellyfin.viewmodels
+
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.MutableLiveData
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import dagger.hilt.android.lifecycle.HiltViewModel
+import dev.jdtech.jellyfin.models.FavoriteSection
+import dev.jdtech.jellyfin.repository.JellyfinRepository
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
+import timber.log.Timber
+import java.util.*
+import javax.inject.Inject
+
+@HiltViewModel
+class FavoriteViewModel
+@Inject
+constructor(
+ private val jellyfinRepository: JellyfinRepository
+) : ViewModel() {
+ private val _favoriteSections = MutableLiveData>()
+ val favoriteSections: LiveData> = _favoriteSections
+
+ private val _finishedLoading = MutableLiveData()
+ val finishedLoading: LiveData = _finishedLoading
+
+ private val _error = MutableLiveData()
+ val error: LiveData = _error
+
+ init {
+ loadData()
+ }
+
+ fun loadData() {
+ _error.value = false
+ _finishedLoading.value = false
+ viewModelScope.launch {
+ try {
+ val items = jellyfinRepository.getFavoriteItems()
+
+ if (items.isEmpty()) {
+ _favoriteSections.value = listOf()
+ _finishedLoading.value = true
+ return@launch
+ }
+
+ val tempFavoriteSections = mutableListOf()
+
+ withContext(Dispatchers.Default) {
+ FavoriteSection(
+ UUID.randomUUID(),
+ "Movies",
+ items.filter { it.type == "Movie" }).let {
+ if (it.items.isNotEmpty()) tempFavoriteSections.add(
+ it
+ )
+ }
+ FavoriteSection(
+ UUID.randomUUID(),
+ "Shows",
+ items.filter { it.type == "Series" }).let {
+ if (it.items.isNotEmpty()) tempFavoriteSections.add(
+ it
+ )
+ }
+ FavoriteSection(
+ UUID.randomUUID(),
+ "Episodes",
+ items.filter { it.type == "Episode" }).let {
+ if (it.items.isNotEmpty()) tempFavoriteSections.add(
+ it
+ )
+ }
+ }
+
+ _favoriteSections.value = tempFavoriteSections
+ } catch (e: Exception) {
+ Timber.e(e)
+ _error.value = true
+ }
+ _finishedLoading.value = true
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/viewmodels/HomeViewModel.kt b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/HomeViewModel.kt
new file mode 100644
index 0000000000..cfba9866ea
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/HomeViewModel.kt
@@ -0,0 +1,97 @@
+package dev.jdtech.jellyfin.viewmodels
+
+import android.app.Application
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.MutableLiveData
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import dagger.hilt.android.lifecycle.HiltViewModel
+import dev.jdtech.jellyfin.R
+import dev.jdtech.jellyfin.adapters.HomeItem
+import dev.jdtech.jellyfin.models.HomeSection
+import dev.jdtech.jellyfin.models.View
+import dev.jdtech.jellyfin.repository.JellyfinRepository
+import dev.jdtech.jellyfin.utils.toView
+import kotlinx.coroutines.launch
+import org.jellyfin.sdk.model.api.BaseItemDto
+import timber.log.Timber
+import java.util.*
+import javax.inject.Inject
+
+@HiltViewModel
+class HomeViewModel
+@Inject
+constructor(
+ application: Application,
+ private val jellyfinRepository: JellyfinRepository
+) : ViewModel() {
+
+ private val continueWatchingString = application.resources.getString(R.string.continue_watching)
+ private val nextUpString = application.resources.getString(R.string.next_up)
+
+ private val _views = MutableLiveData>()
+ val views: LiveData> = _views
+
+ private val _items = MutableLiveData>()
+ val items: LiveData> = _items
+
+ private val _finishedLoading = MutableLiveData()
+ val finishedLoading: LiveData = _finishedLoading
+
+ private val _error = MutableLiveData()
+ val error: LiveData = _error
+
+ init {
+ loadData()
+ }
+
+ fun loadData() {
+ _error.value = false
+ _finishedLoading.value = false
+ viewModelScope.launch {
+ try {
+ jellyfinRepository.postCapabilities()
+ val views: MutableList = mutableListOf()
+ val userViews = jellyfinRepository.getUserViews()
+ for (view in userViews) {
+ Timber.d("Collection type: ${view.collectionType}")
+ if (view.collectionType == "homevideos" ||
+ view.collectionType == "music" ||
+ view.collectionType == "playlists"
+ ) continue
+ val latestItems = jellyfinRepository.getLatestMedia(view.id)
+ if (latestItems.isEmpty()) continue
+ val v = view.toView()
+ v.items = latestItems
+ views.add(v)
+ }
+
+ val items = mutableListOf()
+
+ val resumeItems = jellyfinRepository.getResumeItems()
+ val resumeSection =
+ HomeSection(UUID.randomUUID(), continueWatchingString, resumeItems)
+
+ if (!resumeItems.isNullOrEmpty()) {
+ items.add(HomeItem.Section(resumeSection))
+ }
+
+ val nextUpItems = jellyfinRepository.getNextUp()
+ val nextUpSection = HomeSection(UUID.randomUUID(), nextUpString, nextUpItems)
+
+ if (!nextUpItems.isNullOrEmpty()) {
+ items.add(HomeItem.Section(nextUpSection))
+ }
+
+ _views.value = items + views.map { HomeItem.ViewItem(it) }
+
+ } catch (e: Exception) {
+ Timber.e(e)
+ _error.value = true
+ }
+ _finishedLoading.value = true
+ }
+ }
+}
+
+
diff --git a/app/src/main/java/dev/jdtech/jellyfin/viewmodels/LibraryViewModel.kt b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/LibraryViewModel.kt
new file mode 100644
index 0000000000..04c48f5318
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/LibraryViewModel.kt
@@ -0,0 +1,39 @@
+package dev.jdtech.jellyfin.viewmodels
+
+import androidx.lifecycle.*
+import dagger.hilt.android.lifecycle.HiltViewModel
+import dev.jdtech.jellyfin.repository.JellyfinRepository
+import kotlinx.coroutines.launch
+import org.jellyfin.sdk.model.api.BaseItemDto
+import timber.log.Timber
+import java.util.*
+import javax.inject.Inject
+
+@HiltViewModel
+class LibraryViewModel
+@Inject
+constructor(private val jellyfinRepository: JellyfinRepository) : ViewModel() {
+
+ private val _items = MutableLiveData>()
+ val items: LiveData> = _items
+
+ private val _finishedLoading = MutableLiveData()
+ val finishedLoading: LiveData = _finishedLoading
+
+ private val _error = MutableLiveData()
+ val error: LiveData = _error
+
+ fun loadItems(parentId: UUID) {
+ _error.value = false
+ _finishedLoading.value = false
+ viewModelScope.launch {
+ try {
+ _items.value = jellyfinRepository.getItems(parentId)
+ } catch (e: Exception) {
+ Timber.e(e)
+ _error.value = true
+ }
+ _finishedLoading.value = true
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/viewmodels/LoginViewModel.kt b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/LoginViewModel.kt
new file mode 100644
index 0000000000..7722a3e72e
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/LoginViewModel.kt
@@ -0,0 +1,88 @@
+package dev.jdtech.jellyfin.viewmodels
+
+import android.content.SharedPreferences
+import androidx.lifecycle.*
+import dagger.hilt.android.lifecycle.HiltViewModel
+import dev.jdtech.jellyfin.api.JellyfinApi
+import dev.jdtech.jellyfin.database.Server
+import dev.jdtech.jellyfin.database.ServerDatabaseDao
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
+import org.jellyfin.sdk.model.api.AuthenticateUserByName
+import timber.log.Timber
+import java.lang.Exception
+import javax.inject.Inject
+
+@HiltViewModel
+class LoginViewModel
+@Inject
+constructor(
+ private val sharedPreferences: SharedPreferences,
+ private val jellyfinApi: JellyfinApi,
+ private val database: ServerDatabaseDao
+) : ViewModel() {
+
+ private val _error = MutableLiveData()
+ val error: LiveData = _error
+
+
+ private val _navigateToMain = MutableLiveData()
+ val navigateToMain: LiveData = _navigateToMain
+
+ /**
+ * Send a authentication request to the Jellyfin server
+ *
+ * @param username Username
+ * @param password Password
+ */
+ fun login(username: String, password: String) {
+ viewModelScope.launch {
+ try {
+ val authenticationResult by jellyfinApi.userApi.authenticateUserByName(
+ data = AuthenticateUserByName(
+ username = username,
+ pw = password
+ )
+ )
+ _error.value = null
+ val serverInfo by jellyfinApi.systemApi.getPublicSystemInfo()
+ val server = Server(
+ serverInfo.id!!,
+ serverInfo.serverName!!,
+ jellyfinApi.api.baseUrl!!,
+ authenticationResult.user?.id.toString(),
+ authenticationResult.user?.name!!,
+ authenticationResult.accessToken!!
+ )
+ insert(server)
+ val spEdit = sharedPreferences.edit()
+ spEdit.putString("selectedServer", server.id)
+ spEdit.apply()
+ jellyfinApi.apply {
+ api.accessToken = authenticationResult.accessToken
+ userId = authenticationResult.user?.id
+ }
+ _navigateToMain.value = true
+ } catch (e: Exception) {
+ Timber.e(e)
+ _error.value = e.message
+ }
+ }
+ }
+
+ /**
+ * Add server to the database
+ *
+ * @param server The server
+ */
+ private suspend fun insert(server: Server) {
+ withContext(Dispatchers.IO) {
+ database.insert(server)
+ }
+ }
+
+ fun doneNavigatingToMain() {
+ _navigateToMain.value = false
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/viewmodels/MainViewModel.kt b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/MainViewModel.kt
new file mode 100644
index 0000000000..92cab80bf0
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/MainViewModel.kt
@@ -0,0 +1,65 @@
+package dev.jdtech.jellyfin.viewmodels
+
+import android.app.Application
+import android.content.SharedPreferences
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.MutableLiveData
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import androidx.preference.PreferenceManager
+import dagger.hilt.android.lifecycle.HiltViewModel
+import dev.jdtech.jellyfin.api.JellyfinApi
+import dev.jdtech.jellyfin.database.Server
+import dev.jdtech.jellyfin.database.ServerDatabaseDao
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
+import timber.log.Timber
+import java.util.*
+import javax.inject.Inject
+
+@HiltViewModel
+class MainViewModel
+@Inject
+constructor(
+ private val sharedPreferences: SharedPreferences,
+ private val database: ServerDatabaseDao,
+ private val jellyfinApi: JellyfinApi,
+) : ViewModel() {
+
+ private val _doneLoading = MutableLiveData()
+ val doneLoading: LiveData = _doneLoading
+
+ private val _navigateToAddServer = MutableLiveData()
+ val navigateToAddServer: LiveData = _navigateToAddServer
+
+ init {
+ Timber.d("Start Main")
+ viewModelScope.launch {
+ val servers: List
+ withContext(Dispatchers.IO) {
+ servers = database.getAllServersSync()
+ }
+ if (servers.isEmpty()) {
+ _navigateToAddServer.value = true
+ } else {
+ val serverId = sharedPreferences.getString("selectedServer", null)
+ val selectedServer = servers.find { server -> server.id == serverId }
+ Timber.d("Selected server: $selectedServer")
+ if (selectedServer != null) {
+ jellyfinApi.apply {
+ api.baseUrl = selectedServer.address
+ api.accessToken = selectedServer.accessToken
+ userId = UUID.fromString(selectedServer.userId)
+ }
+ Timber.d("Finish Main")
+ }
+ _doneLoading.value = true
+ }
+ }
+ }
+
+ fun doneNavigateToAddServer() {
+ _navigateToAddServer.value = false
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/viewmodels/MediaInfoViewModel.kt b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/MediaInfoViewModel.kt
new file mode 100644
index 0000000000..6df01cbb9a
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/MediaInfoViewModel.kt
@@ -0,0 +1,225 @@
+package dev.jdtech.jellyfin.viewmodels
+
+import android.os.Build
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.MutableLiveData
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import dagger.hilt.android.lifecycle.HiltViewModel
+import dev.jdtech.jellyfin.models.PlayerItem
+import dev.jdtech.jellyfin.repository.JellyfinRepository
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
+import org.jellyfin.sdk.model.api.BaseItemDto
+import org.jellyfin.sdk.model.api.BaseItemPerson
+import org.jellyfin.sdk.model.api.MediaSourceInfo
+import timber.log.Timber
+import java.util.*
+import javax.inject.Inject
+
+@HiltViewModel
+class MediaInfoViewModel
+@Inject
+constructor(private val jellyfinRepository: JellyfinRepository) : ViewModel() {
+
+ private val _item = MutableLiveData()
+ val item: LiveData = _item
+
+ private val _actors = MutableLiveData>()
+ val actors: LiveData> = _actors
+
+ private val _director = MutableLiveData()
+ val director: LiveData = _director
+
+ private val _writers = MutableLiveData>()
+ val writers: LiveData> = _writers
+ private val _writersString = MutableLiveData()
+ val writersString: LiveData = _writersString
+
+ private val _genresString = MutableLiveData()
+ val genresString: LiveData = _genresString
+
+ private val _runTime = MutableLiveData()
+ val runTime: LiveData = _runTime
+
+ private val _dateString = MutableLiveData()
+ val dateString: LiveData = _dateString
+
+ private val _nextUp = MutableLiveData()
+ val nextUp: LiveData = _nextUp
+
+ private val _seasons = MutableLiveData>()
+ val seasons: LiveData> = _seasons
+
+ private val _mediaSources = MutableLiveData>()
+ val mediaSources: LiveData> = _mediaSources
+
+ private val _navigateToPlayer = MutableLiveData>()
+ val navigateToPlayer: LiveData> = _navigateToPlayer
+
+ private val _played = MutableLiveData()
+ val played: LiveData = _played
+
+ private val _favorite = MutableLiveData()
+ val favorite: LiveData = _favorite
+
+ private val _error = MutableLiveData()
+ val error: LiveData = _error
+
+ var playerItems: MutableList = mutableListOf()
+
+ private val _playerItemsError = MutableLiveData()
+ val playerItemsError: LiveData = _playerItemsError
+
+ fun loadData(itemId: UUID, itemType: String) {
+ _error.value = false
+ viewModelScope.launch {
+ try {
+ _item.value = jellyfinRepository.getItem(itemId)
+ _actors.value = getActors(_item.value!!)
+ _director.value = getDirector(_item.value!!)
+ _writers.value = getWriters(_item.value!!)
+ _writersString.value =
+ _writers.value?.joinToString(separator = ", ") { it.name.toString() }
+ _genresString.value = _item.value?.genres?.joinToString(separator = ", ")
+ _runTime.value = "${_item.value?.runTimeTicks?.div(600000000)} min"
+ _dateString.value = getDateString(_item.value!!)
+ _played.value = _item.value?.userData?.played
+ _favorite.value = _item.value?.userData?.isFavorite
+ if (itemType == "Series") {
+ _nextUp.value = getNextUp(itemId)
+ _seasons.value = jellyfinRepository.getSeasons(itemId)
+ }
+ if (itemType == "Movie") {
+ _mediaSources.value = jellyfinRepository.getMediaSources(itemId)
+ }
+ } catch (e: Exception) {
+ Timber.e(e)
+ _error.value = true
+ }
+ }
+ }
+
+ private suspend fun getActors(item: BaseItemDto): List? {
+ val actors: List?
+ withContext(Dispatchers.Default) {
+ actors = item.people?.filter { it.type == "Actor" }
+ }
+ return actors
+ }
+
+ private suspend fun getDirector(item: BaseItemDto): BaseItemPerson? {
+ val director: BaseItemPerson?
+ withContext(Dispatchers.Default) {
+ director = item.people?.firstOrNull { it.type == "Director" }
+ }
+ return director
+ }
+
+ private suspend fun getWriters(item: BaseItemDto): List? {
+ val writers: List?
+ withContext(Dispatchers.Default) {
+ writers = item.people?.filter { it.type == "Writer" }
+ }
+ return writers
+ }
+
+ private suspend fun getNextUp(seriesId: UUID): BaseItemDto? {
+ val nextUpItems = jellyfinRepository.getNextUp(seriesId)
+ return if (nextUpItems.isNotEmpty()) {
+ nextUpItems[0]
+ } else {
+ null
+ }
+ }
+
+ fun markAsPlayed(itemId: UUID) {
+ viewModelScope.launch {
+ jellyfinRepository.markAsPlayed(itemId)
+ }
+ _played.value = true
+ }
+
+ fun markAsUnplayed(itemId: UUID) {
+ viewModelScope.launch {
+ jellyfinRepository.markAsUnplayed(itemId)
+ }
+ _played.value = false
+ }
+
+ fun markAsFavorite(itemId: UUID) {
+ viewModelScope.launch {
+ jellyfinRepository.markAsFavorite(itemId)
+ }
+ _favorite.value = true
+ }
+
+ fun unmarkAsFavorite(itemId: UUID) {
+ viewModelScope.launch {
+ jellyfinRepository.unmarkAsFavorite(itemId)
+ }
+ _favorite.value = false
+ }
+
+ private fun getDateString(item: BaseItemDto): String {
+ val dateString: String = item.productionYear.toString()
+ return when (item.status) {
+ "Continuing" -> dateString.plus(" - Present")
+ "Ended" -> {
+ return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ return if (item.productionYear == item.endDate?.year) {
+ dateString
+ } else {
+ dateString.plus(" - ${item.endDate?.year}")
+ }
+ } else {
+ // TODO: Implement a way to get the year from LocalDateTime in Android < O
+ dateString
+ }
+
+ }
+ else -> dateString
+ }
+ }
+
+ fun preparePlayer() {
+ _playerItemsError.value = false
+ viewModelScope.launch {
+ try {
+ createPlayerItems(_item.value!!)
+ _navigateToPlayer.value = playerItems.toTypedArray()
+ } catch (e: Exception) {
+ _playerItemsError.value = true
+ }
+ }
+ }
+
+ private suspend fun createPlayerItems(series: BaseItemDto) {
+ if (nextUp.value != null) {
+ val startEpisode = nextUp.value!!
+ val episodes = jellyfinRepository.getEpisodes(startEpisode.seriesId!!, startEpisode.seasonId!!, startIndex = startEpisode.indexNumber?.minus(1))
+ for (episode in episodes) {
+ val mediaSources = jellyfinRepository.getMediaSources(episode.id)
+ playerItems.add(PlayerItem(episode.id, mediaSources[0].id!!))
+ }
+ } else {
+ for (season in seasons.value!!) {
+ if (season.indexNumber == 0) continue
+ val episodes = jellyfinRepository.getEpisodes(series.id, season.id)
+ for (episode in episodes) {
+ val mediaSources = jellyfinRepository.getMediaSources(episode.id)
+ playerItems.add(PlayerItem(episode.id, mediaSources[0].id!!))
+ }
+ }
+ }
+ }
+
+ fun navigateToPlayer(mediaSource: MediaSourceInfo) {
+ _navigateToPlayer.value = arrayOf(PlayerItem(item.value!!.id, mediaSource.id!!))
+ }
+
+ fun doneNavigatingToPlayer() {
+ _navigateToPlayer.value = null
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/viewmodels/MediaViewModel.kt b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/MediaViewModel.kt
new file mode 100644
index 0000000000..a23f9607fd
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/MediaViewModel.kt
@@ -0,0 +1,51 @@
+package dev.jdtech.jellyfin.viewmodels
+
+import androidx.lifecycle.*
+import dagger.hilt.android.lifecycle.HiltViewModel
+import dev.jdtech.jellyfin.repository.JellyfinRepository
+import kotlinx.coroutines.launch
+import org.jellyfin.sdk.model.api.BaseItemDto
+import timber.log.Timber
+import javax.inject.Inject
+
+@HiltViewModel
+class MediaViewModel
+@Inject
+constructor(
+ private val jellyfinRepository: JellyfinRepository
+) : ViewModel() {
+
+ private val _collections = MutableLiveData>()
+ val collections: LiveData> = _collections
+
+ private val _finishedLoading = MutableLiveData()
+ val finishedLoading: LiveData = _finishedLoading
+
+ private val _error = MutableLiveData()
+ val error: LiveData = _error
+
+ init {
+ loadData()
+ }
+
+ fun loadData() {
+ _finishedLoading.value = false
+ _error.value = false
+ viewModelScope.launch {
+ try {
+ val items = jellyfinRepository.getItems()
+ _collections.value =
+ items.filter {
+ it.collectionType != "homevideos" &&
+ it.collectionType != "music" &&
+ it.collectionType != "playlists" &&
+ it.collectionType != "boxsets"
+ }
+ } catch (e: Exception) {
+ Timber.e(e)
+ _error.value = true
+ }
+ _finishedLoading.value = true
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/viewmodels/PlayerActivityViewModel.kt b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/PlayerActivityViewModel.kt
new file mode 100644
index 0000000000..80e30af71f
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/PlayerActivityViewModel.kt
@@ -0,0 +1,155 @@
+package dev.jdtech.jellyfin.viewmodels
+
+import android.app.Application
+import android.os.Handler
+import android.os.Looper
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.MutableLiveData
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import androidx.preference.PreferenceManager
+import com.google.android.exoplayer2.*
+import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
+import dagger.hilt.android.lifecycle.HiltViewModel
+import dev.jdtech.jellyfin.models.PlayerItem
+import dev.jdtech.jellyfin.repository.JellyfinRepository
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.runBlocking
+import timber.log.Timber
+import java.util.*
+import javax.inject.Inject
+
+@HiltViewModel
+class PlayerActivityViewModel
+@Inject
+constructor(
+ private val application: Application,
+ private val jellyfinRepository: JellyfinRepository
+) : ViewModel(), Player.Listener {
+ private var _player = MutableLiveData()
+ var player: LiveData = _player
+
+ private val _navigateBack = MutableLiveData()
+ val navigateBack: LiveData = _navigateBack
+
+ var playWhenReady = true
+ private var currentWindow = 0
+ private var playbackPosition: Long = 0
+
+ private val sp = PreferenceManager.getDefaultSharedPreferences(application)
+
+ fun initializePlayer(
+ items: Array,
+ playbackPosition: Long
+ ) {
+
+ val renderersFactory =
+ DefaultRenderersFactory(application).setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON)
+ val trackSelector = DefaultTrackSelector(application)
+ trackSelector.setParameters(
+ trackSelector.buildUponParameters()
+ .setTunnelingEnabled(true)
+ .setPreferredAudioLanguage(sp.getString("audio_language", null))
+ .setPreferredTextLanguage(sp.getString("subtitle_language", null))
+ )
+ val player = SimpleExoPlayer.Builder(application, renderersFactory)
+ .setTrackSelector(trackSelector)
+ .build()
+
+ player.addListener(this)
+
+ viewModelScope.launch {
+ val mediaItems: MutableList = mutableListOf()
+
+ for (item in items) {
+ val streamUrl = jellyfinRepository.getStreamUrl(item.itemId, item.mediaSourceId)
+ Timber.d("Stream url: $streamUrl")
+ val mediaItem =
+ MediaItem.Builder()
+ .setMediaId(item.itemId.toString())
+ .setUri(streamUrl)
+ .build()
+ mediaItems.add(mediaItem)
+ }
+
+ player.setMediaItems(mediaItems, currentWindow, playbackPosition)
+ player.playWhenReady = playWhenReady
+ player.prepare()
+ _player.value = player
+ }
+
+ pollPosition(player)
+ }
+
+ private fun releasePlayer() {
+ _player.value?.let { player ->
+ runBlocking {
+ jellyfinRepository.postPlaybackStop(
+ UUID.fromString(player.currentMediaItem?.mediaId),
+ player.currentPosition.times(10000)
+ )
+ }
+ }
+
+ if (player.value != null) {
+ playWhenReady = player.value!!.playWhenReady
+ playbackPosition = player.value!!.currentPosition
+ currentWindow = player.value!!.currentWindowIndex
+ player.value!!.removeListener(this)
+ player.value!!.release()
+ _player.value = null
+ }
+ }
+
+ private fun pollPosition(player: SimpleExoPlayer) {
+ val handler = Handler(Looper.getMainLooper())
+ val runnable = object : Runnable {
+ override fun run() {
+ viewModelScope.launch {
+ if (player.currentMediaItem != null) {
+ jellyfinRepository.postPlaybackProgress(
+ UUID.fromString(player.currentMediaItem!!.mediaId),
+ player.currentPosition.times(10000),
+ !player.isPlaying
+ )
+ }
+ }
+ handler.postDelayed(this, 2000)
+ }
+ }
+ handler.post(runnable)
+ }
+
+ override fun onMediaItemTransition(mediaItem: MediaItem?, reason: Int) {
+ Timber.d("Playing MediaItem: ${mediaItem?.mediaId}")
+ viewModelScope.launch {
+ jellyfinRepository.postPlaybackStart(UUID.fromString(mediaItem?.mediaId))
+ }
+ }
+
+ override fun onPlaybackStateChanged(state: Int) {
+ var stateString = "UNKNOWN_STATE -"
+ when (state) {
+ ExoPlayer.STATE_IDLE -> {
+ stateString = "ExoPlayer.STATE_IDLE -"
+ }
+ ExoPlayer.STATE_BUFFERING -> {
+ stateString = "ExoPlayer.STATE_BUFFERING -"
+ }
+ ExoPlayer.STATE_READY -> {
+ stateString = "ExoPlayer.STATE_READY -"
+ }
+ ExoPlayer.STATE_ENDED -> {
+ stateString = "ExoPlayer.STATE_ENDED -"
+ _navigateBack.value = true
+ }
+ }
+ Timber.d("Changed player state to $stateString")
+ }
+
+ override fun onCleared() {
+ super.onCleared()
+ Timber.d("Clearing Player ViewModel")
+ releasePlayer()
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/viewmodels/SearchResultViewModel.kt b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/SearchResultViewModel.kt
new file mode 100644
index 0000000000..f5f8f9251e
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/SearchResultViewModel.kt
@@ -0,0 +1,82 @@
+package dev.jdtech.jellyfin.viewmodels
+
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.MutableLiveData
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import dagger.hilt.android.lifecycle.HiltViewModel
+import dev.jdtech.jellyfin.models.FavoriteSection
+import dev.jdtech.jellyfin.repository.JellyfinRepository
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
+import timber.log.Timber
+import java.util.*
+import javax.inject.Inject
+
+@HiltViewModel
+class SearchResultViewModel
+@Inject
+constructor(
+ private val jellyfinRepository: JellyfinRepository
+) : ViewModel() {
+ private val _sections = MutableLiveData>()
+ val sections: LiveData> = _sections
+
+ private val _finishedLoading = MutableLiveData()
+ val finishedLoading: LiveData = _finishedLoading
+
+ private val _error = MutableLiveData()
+ val error: LiveData = _error
+
+ fun loadData(query: String) {
+ _error.value = false
+ _finishedLoading.value = false
+ viewModelScope.launch {
+ try {
+ val items = jellyfinRepository.getSearchItems(query)
+
+ if (items.isEmpty()) {
+ _sections.value = listOf()
+ _finishedLoading.value = true
+ return@launch
+ }
+
+ val tempSections = mutableListOf()
+
+ withContext(Dispatchers.Default) {
+ FavoriteSection(
+ UUID.randomUUID(),
+ "Movies",
+ items.filter { it.type == "Movie" }).let {
+ if (it.items.isNotEmpty()) tempSections.add(
+ it
+ )
+ }
+ FavoriteSection(
+ UUID.randomUUID(),
+ "Shows",
+ items.filter { it.type == "Series" }).let {
+ if (it.items.isNotEmpty()) tempSections.add(
+ it
+ )
+ }
+ FavoriteSection(
+ UUID.randomUUID(),
+ "Episodes",
+ items.filter { it.type == "Episode" }).let {
+ if (it.items.isNotEmpty()) tempSections.add(
+ it
+ )
+ }
+ }
+
+ _sections.value = tempSections
+ } catch (e: Exception) {
+ Timber.e(e)
+ _error.value = true
+ }
+ _finishedLoading.value = true
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/viewmodels/SeasonViewModel.kt b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/SeasonViewModel.kt
new file mode 100644
index 0000000000..cf15b182fe
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/SeasonViewModel.kt
@@ -0,0 +1,48 @@
+package dev.jdtech.jellyfin.viewmodels
+
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.MutableLiveData
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import dagger.hilt.android.lifecycle.HiltViewModel
+import dev.jdtech.jellyfin.adapters.EpisodeItem
+import dev.jdtech.jellyfin.repository.JellyfinRepository
+import kotlinx.coroutines.launch
+import org.jellyfin.sdk.model.api.ItemFields
+import timber.log.Timber
+import java.util.*
+import javax.inject.Inject
+
+@HiltViewModel
+class SeasonViewModel
+@Inject
+constructor(private val jellyfinRepository: JellyfinRepository) : ViewModel() {
+
+ private val _episodes = MutableLiveData>()
+ val episodes: LiveData> = _episodes
+
+ private val _finishedLoading = MutableLiveData()
+ val finishedLoading: LiveData = _finishedLoading
+
+ private val _error = MutableLiveData()
+ val error: LiveData = _error
+
+ fun loadEpisodes(seriesId: UUID, seasonId: UUID) {
+ _error.value = false
+ _finishedLoading.value = false
+ viewModelScope.launch {
+ try {
+ _episodes.value = getEpisodes(seriesId, seasonId)
+ } catch (e: Exception) {
+ Timber.e(e)
+ _error.value = true
+ }
+ _finishedLoading.value = true
+ }
+ }
+
+ private suspend fun getEpisodes(seriesId: UUID, seasonId: UUID): List {
+ val episodes = jellyfinRepository.getEpisodes(seriesId, seasonId, fields = listOf(ItemFields.OVERVIEW))
+ return listOf(EpisodeItem.Header) + episodes.map { EpisodeItem.Episode(it) }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jdtech/jellyfin/viewmodels/ServerSelectViewModel.kt b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/ServerSelectViewModel.kt
new file mode 100644
index 0000000000..c459f477cb
--- /dev/null
+++ b/app/src/main/java/dev/jdtech/jellyfin/viewmodels/ServerSelectViewModel.kt
@@ -0,0 +1,63 @@
+package dev.jdtech.jellyfin.viewmodels
+
+import android.content.SharedPreferences
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.MutableLiveData
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import dagger.hilt.android.lifecycle.HiltViewModel
+import dev.jdtech.jellyfin.api.JellyfinApi
+import dev.jdtech.jellyfin.database.Server
+import dev.jdtech.jellyfin.database.ServerDatabaseDao
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
+import java.util.*
+import javax.inject.Inject
+
+@HiltViewModel
+class ServerSelectViewModel
+@Inject
+constructor(
+ private val sharedPreferences: SharedPreferences,
+ private val jellyfinApi: JellyfinApi,
+ private val database: ServerDatabaseDao,
+) : ViewModel() {
+
+ private val _servers = database.getAllServers()
+ val servers: LiveData> = _servers
+
+ private val _navigateToMain = MutableLiveData()
+ val navigateToMain: LiveData = _navigateToMain
+
+ /**
+ * Delete server from database
+ *
+ * @param server The server
+ */
+ fun deleteServer(server: Server) {
+ viewModelScope.launch {
+ withContext(Dispatchers.IO) {
+ database.delete(server.id)
+ }
+ }
+ }
+
+ fun connectToServer(server: Server) {
+ val spEdit = sharedPreferences.edit()
+ spEdit.putString("selectedServer", server.id)
+ spEdit.apply()
+
+ jellyfinApi.apply {
+ api.baseUrl = server.address
+ api.accessToken = server.accessToken
+ userId = UUID.fromString(server.userId)
+ }
+
+ _navigateToMain.value = true
+ }
+
+ fun doneNavigatingToMain() {
+ _navigateToMain.value = false
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/res/anim/item_animation_slide_in.xml b/app/src/main/res/anim/item_animation_slide_in.xml
new file mode 100644
index 0000000000..c035240c86
--- /dev/null
+++ b/app/src/main/res/anim/item_animation_slide_in.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/anim/overview_media_animation.xml b/app/src/main/res/anim/overview_media_animation.xml
new file mode 100644
index 0000000000..d197e7e7e9
--- /dev/null
+++ b/app/src/main/res/anim/overview_media_animation.xml
@@ -0,0 +1,5 @@
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable-night/header_gradient.xml b/app/src/main/res/drawable-night/header_gradient.xml
new file mode 100644
index 0000000000..3a87dafcb5
--- /dev/null
+++ b/app/src/main/res/drawable-night/header_gradient.xml
@@ -0,0 +1,5 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable-night/ic_banner.xml b/app/src/main/res/drawable-night/ic_banner.xml
new file mode 100644
index 0000000000..b2adc4c4ee
--- /dev/null
+++ b/app/src/main/res/drawable-night/ic_banner.xml
@@ -0,0 +1,76 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml
deleted file mode 100644
index 2b068d1146..0000000000
--- a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/drawable/button_accent_background.xml b/app/src/main/res/drawable/button_accent_background.xml
new file mode 100644
index 0000000000..6badef84f6
--- /dev/null
+++ b/app/src/main/res/drawable/button_accent_background.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/drawable/button_setup_background.xml b/app/src/main/res/drawable/button_setup_background.xml
new file mode 100644
index 0000000000..561aec7713
--- /dev/null
+++ b/app/src/main/res/drawable/button_setup_background.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/drawable/circle_background.xml b/app/src/main/res/drawable/circle_background.xml
new file mode 100644
index 0000000000..b3f5e5dca8
--- /dev/null
+++ b/app/src/main/res/drawable/circle_background.xml
@@ -0,0 +1,5 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/header_gradient.xml b/app/src/main/res/drawable/header_gradient.xml
new file mode 100644
index 0000000000..f9f0f81289
--- /dev/null
+++ b/app/src/main/res/drawable/header_gradient.xml
@@ -0,0 +1,5 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_banner.xml b/app/src/main/res/drawable/ic_banner.xml
new file mode 100644
index 0000000000..e23843a65b
--- /dev/null
+++ b/app/src/main/res/drawable/ic_banner.xml
@@ -0,0 +1,76 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/drawable/ic_check.xml b/app/src/main/res/drawable/ic_check.xml
new file mode 100644
index 0000000000..95e065d157
--- /dev/null
+++ b/app/src/main/res/drawable/ic_check.xml
@@ -0,0 +1,13 @@
+
+
+
diff --git a/app/src/main/res/drawable/ic_check_filled.xml b/app/src/main/res/drawable/ic_check_filled.xml
new file mode 100644
index 0000000000..6c19c50c9a
--- /dev/null
+++ b/app/src/main/res/drawable/ic_check_filled.xml
@@ -0,0 +1,13 @@
+
+
+
diff --git a/app/src/main/res/drawable/ic_film.xml b/app/src/main/res/drawable/ic_film.xml
new file mode 100644
index 0000000000..13c24410b8
--- /dev/null
+++ b/app/src/main/res/drawable/ic_film.xml
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/drawable/ic_heart.xml b/app/src/main/res/drawable/ic_heart.xml
new file mode 100644
index 0000000000..b388383095
--- /dev/null
+++ b/app/src/main/res/drawable/ic_heart.xml
@@ -0,0 +1,13 @@
+
+
+
diff --git a/app/src/main/res/drawable/ic_heart_filled.xml b/app/src/main/res/drawable/ic_heart_filled.xml
new file mode 100644
index 0000000000..5f1451cb38
--- /dev/null
+++ b/app/src/main/res/drawable/ic_heart_filled.xml
@@ -0,0 +1,13 @@
+
+
+
diff --git a/app/src/main/res/drawable/ic_home.xml b/app/src/main/res/drawable/ic_home.xml
new file mode 100644
index 0000000000..1114de2de6
--- /dev/null
+++ b/app/src/main/res/drawable/ic_home.xml
@@ -0,0 +1,21 @@
+
+
+
+
diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml
deleted file mode 100644
index 07d5da9cbf..0000000000
--- a/app/src/main/res/drawable/ic_launcher_background.xml
+++ /dev/null
@@ -1,170 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml
new file mode 100644
index 0000000000..8d2c57c685
--- /dev/null
+++ b/app/src/main/res/drawable/ic_launcher_foreground.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/drawable/ic_library.xml b/app/src/main/res/drawable/ic_library.xml
new file mode 100644
index 0000000000..003f35182a
--- /dev/null
+++ b/app/src/main/res/drawable/ic_library.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
diff --git a/app/src/main/res/drawable/ic_lock.xml b/app/src/main/res/drawable/ic_lock.xml
new file mode 100644
index 0000000000..3465d69251
--- /dev/null
+++ b/app/src/main/res/drawable/ic_lock.xml
@@ -0,0 +1,20 @@
+
+
+
+
diff --git a/app/src/main/res/drawable/ic_minus_fat.xml b/app/src/main/res/drawable/ic_minus_fat.xml
new file mode 100644
index 0000000000..f8c8bb6515
--- /dev/null
+++ b/app/src/main/res/drawable/ic_minus_fat.xml
@@ -0,0 +1,13 @@
+
+
+
diff --git a/app/src/main/res/drawable/ic_play.xml b/app/src/main/res/drawable/ic_play.xml
new file mode 100644
index 0000000000..17da1f55bb
--- /dev/null
+++ b/app/src/main/res/drawable/ic_play.xml
@@ -0,0 +1,13 @@
+
+
+
diff --git a/app/src/main/res/drawable/ic_search.xml b/app/src/main/res/drawable/ic_search.xml
new file mode 100644
index 0000000000..00b5e5f3f4
--- /dev/null
+++ b/app/src/main/res/drawable/ic_search.xml
@@ -0,0 +1,21 @@
+
+
+
+
diff --git a/app/src/main/res/drawable/ic_server.xml b/app/src/main/res/drawable/ic_server.xml
new file mode 100644
index 0000000000..f472367ad8
--- /dev/null
+++ b/app/src/main/res/drawable/ic_server.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
diff --git a/app/src/main/res/drawable/ic_settings.xml b/app/src/main/res/drawable/ic_settings.xml
new file mode 100644
index 0000000000..f5f25e4755
--- /dev/null
+++ b/app/src/main/res/drawable/ic_settings.xml
@@ -0,0 +1,21 @@
+
+
+
+
diff --git a/app/src/main/res/drawable/ic_star.xml b/app/src/main/res/drawable/ic_star.xml
new file mode 100644
index 0000000000..65e4c71428
--- /dev/null
+++ b/app/src/main/res/drawable/ic_star.xml
@@ -0,0 +1,13 @@
+
+
+
diff --git a/app/src/main/res/drawable/ic_user.xml b/app/src/main/res/drawable/ic_user.xml
new file mode 100644
index 0000000000..8d15214a4c
--- /dev/null
+++ b/app/src/main/res/drawable/ic_user.xml
@@ -0,0 +1,20 @@
+
+
+
+
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 4fc244418b..47d6f80c62 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -1,18 +1,52 @@
-
-
-
-
-
\ No newline at end of file
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_player.xml b/app/src/main/res/layout/activity_player.xml
new file mode 100644
index 0000000000..49020401bf
--- /dev/null
+++ b/app/src/main/res/layout/activity_player.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/base_item.xml b/app/src/main/res/layout/base_item.xml
new file mode 100644
index 0000000000..0bea8d11b9
--- /dev/null
+++ b/app/src/main/res/layout/base_item.xml
@@ -0,0 +1,77 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/collection_item.xml b/app/src/main/res/layout/collection_item.xml
new file mode 100644
index 0000000000..6b78f8f12d
--- /dev/null
+++ b/app/src/main/res/layout/collection_item.xml
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/episode_bottom_sheet.xml b/app/src/main/res/layout/episode_bottom_sheet.xml
new file mode 100644
index 0000000000..99044167e4
--- /dev/null
+++ b/app/src/main/res/layout/episode_bottom_sheet.xml
@@ -0,0 +1,196 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/episode_item.xml b/app/src/main/res/layout/episode_item.xml
new file mode 100644
index 0000000000..7a94f37af2
--- /dev/null
+++ b/app/src/main/res/layout/episode_item.xml
@@ -0,0 +1,86 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/favorite_section.xml b/app/src/main/res/layout/favorite_section.xml
new file mode 100644
index 0000000000..c8a671620d
--- /dev/null
+++ b/app/src/main/res/layout/favorite_section.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_add_server.xml b/app/src/main/res/layout/fragment_add_server.xml
new file mode 100644
index 0000000000..1b38ed9e4d
--- /dev/null
+++ b/app/src/main/res/layout/fragment_add_server.xml
@@ -0,0 +1,97 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/fragment_favorite.xml b/app/src/main/res/layout/fragment_favorite.xml
new file mode 100644
index 0000000000..a4660e90e4
--- /dev/null
+++ b/app/src/main/res/layout/fragment_favorite.xml
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml
new file mode 100644
index 0000000000..c231859c61
--- /dev/null
+++ b/app/src/main/res/layout/fragment_home.xml
@@ -0,0 +1,52 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/fragment_initializing.xml b/app/src/main/res/layout/fragment_initializing.xml
new file mode 100644
index 0000000000..ce89985032
--- /dev/null
+++ b/app/src/main/res/layout/fragment_initializing.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_library.xml b/app/src/main/res/layout/fragment_library.xml
new file mode 100644
index 0000000000..4e02303151
--- /dev/null
+++ b/app/src/main/res/layout/fragment_library.xml
@@ -0,0 +1,56 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/fragment_login.xml b/app/src/main/res/layout/fragment_login.xml
new file mode 100644
index 0000000000..4ceee57c1f
--- /dev/null
+++ b/app/src/main/res/layout/fragment_login.xml
@@ -0,0 +1,112 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/fragment_media.xml b/app/src/main/res/layout/fragment_media.xml
new file mode 100644
index 0000000000..a38dbffd9d
--- /dev/null
+++ b/app/src/main/res/layout/fragment_media.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/fragment_media_info.xml b/app/src/main/res/layout/fragment_media_info.xml
new file mode 100644
index 0000000000..2d08d88117
--- /dev/null
+++ b/app/src/main/res/layout/fragment_media_info.xml
@@ -0,0 +1,421 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/fragment_search_result.xml b/app/src/main/res/layout/fragment_search_result.xml
new file mode 100644
index 0000000000..d250d75e38
--- /dev/null
+++ b/app/src/main/res/layout/fragment_search_result.xml
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_season.xml b/app/src/main/res/layout/fragment_season.xml
new file mode 100644
index 0000000000..bb1f63ae3a
--- /dev/null
+++ b/app/src/main/res/layout/fragment_season.xml
@@ -0,0 +1,52 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_server_select.xml b/app/src/main/res/layout/fragment_server_select.xml
new file mode 100644
index 0000000000..29f61f9028
--- /dev/null
+++ b/app/src/main/res/layout/fragment_server_select.xml
@@ -0,0 +1,81 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/home_episode_item.xml b/app/src/main/res/layout/home_episode_item.xml
new file mode 100644
index 0000000000..06b523507a
--- /dev/null
+++ b/app/src/main/res/layout/home_episode_item.xml
@@ -0,0 +1,70 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/next_up_section.xml b/app/src/main/res/layout/next_up_section.xml
new file mode 100644
index 0000000000..ffe8bfe1f5
--- /dev/null
+++ b/app/src/main/res/layout/next_up_section.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/person_item.xml b/app/src/main/res/layout/person_item.xml
new file mode 100644
index 0000000000..10850ae6dd
--- /dev/null
+++ b/app/src/main/res/layout/person_item.xml
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/season_header.xml b/app/src/main/res/layout/season_header.xml
new file mode 100644
index 0000000000..9fb32ac0b3
--- /dev/null
+++ b/app/src/main/res/layout/season_header.xml
@@ -0,0 +1,86 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/server_item.xml b/app/src/main/res/layout/server_item.xml
new file mode 100644
index 0000000000..752cb452bb
--- /dev/null
+++ b/app/src/main/res/layout/server_item.xml
@@ -0,0 +1,56 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/view_item.xml b/app/src/main/res/layout/view_item.xml
new file mode 100644
index 0000000000..1c0ae16bca
--- /dev/null
+++ b/app/src/main/res/layout/view_item.xml
@@ -0,0 +1,56 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/menu/bottom_nav_menu.xml b/app/src/main/res/menu/bottom_nav_menu.xml
new file mode 100644
index 0000000000..246fe4caaa
--- /dev/null
+++ b/app/src/main/res/menu/bottom_nav_menu.xml
@@ -0,0 +1,19 @@
+
+
\ No newline at end of file
diff --git a/app/src/main/res/menu/home_menu.xml b/app/src/main/res/menu/home_menu.xml
new file mode 100644
index 0000000000..8bf60bd158
--- /dev/null
+++ b/app/src/main/res/menu/home_menu.xml
@@ -0,0 +1,10 @@
+
+
\ No newline at end of file
diff --git a/app/src/main/res/menu/media_menu.xml b/app/src/main/res/menu/media_menu.xml
new file mode 100644
index 0000000000..9195a338a5
--- /dev/null
+++ b/app/src/main/res/menu/media_menu.xml
@@ -0,0 +1,11 @@
+
+
\ No newline at end of file
diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
index eca70cfe52..7353dbd1fd 100644
--- a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
+++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
@@ -1,5 +1,5 @@
-
-
+
+
\ No newline at end of file
diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
index eca70cfe52..7353dbd1fd 100644
--- a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
+++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
@@ -1,5 +1,5 @@
-
-
+
+
\ No newline at end of file
diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png
index a571e60098..99474f0241 100644
Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher.png and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
index 61da551c55..76af6fccf6 100644
Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ
diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png
index c41dd28531..2040940148 100644
Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher.png and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
index db5080a752..4146e6f10f 100644
Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ
diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png
index 6dba46dab1..5ed34e400b 100644
Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
index da31a871c8..2b023e18a8 100644
Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ
diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
index 15ac681720..76ef0633d2 100644
Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
index b216f2d313..02866fd0d3 100644
Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ
diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
index f25a419744..e092ab14c2 100644
Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
index e96783ccce..50cf914934 100644
Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ
diff --git a/app/src/main/res/navigation/main_navigation.xml b/app/src/main/res/navigation/main_navigation.xml
new file mode 100644
index 0000000000..3f64d1d2ea
--- /dev/null
+++ b/app/src/main/res/navigation/main_navigation.xml
@@ -0,0 +1,237 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml
index 4f87ef2329..7c2709e2d8 100644
--- a/app/src/main/res/values-night/themes.xml
+++ b/app/src/main/res/values-night/themes.xml
@@ -1,16 +1,24 @@
-
+
-
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-sw600dp/dimens.xml b/app/src/main/res/values-sw600dp/dimens.xml
new file mode 100644
index 0000000000..c75a466750
--- /dev/null
+++ b/app/src/main/res/values-sw600dp/dimens.xml
@@ -0,0 +1,9 @@
+
+
+ 400dp
+ 6
+ 2
+ 4
+ 450
+ 350dp
+
\ No newline at end of file
diff --git a/app/src/main/res/values-sw720dp/dimens.xml b/app/src/main/res/values-sw720dp/dimens.xml
new file mode 100644
index 0000000000..1d98770c38
--- /dev/null
+++ b/app/src/main/res/values-sw720dp/dimens.xml
@@ -0,0 +1,6 @@
+
+
+ 8
+ 3
+ 6
+
\ No newline at end of file
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index f8c6127d32..f230cfa6e1 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -1,10 +1,18 @@
- #FFBB86FC
- #FF6200EE
- #FF3700B3
- #FF03DAC5
- #FF018786
+ #2B82D9
+ #1B5692
+ #24B364
+ #126839
+ #121A21
+ #243342
+ #374F67
+ #5D82A7
+ #A9BDD1
+ #D7E0E9
+ #EEF2F6#FF000000#FFFFFFFF
+ #EB5757
+ #F2C94C
\ No newline at end of file
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
new file mode 100644
index 0000000000..6ad4fb71a3
--- /dev/null
+++ b/app/src/main/res/values/dimens.xml
@@ -0,0 +1,12 @@
+
+
+ -1
+ -2
+ @dimen/match_parent
+ 150dp
+ 3
+ 1
+ 2
+ 250
+ @dimen/match_parent
+
\ No newline at end of file
diff --git a/app/src/main/res/values/ic_launcher_background.xml b/app/src/main/res/values/ic_launcher_background.xml
new file mode 100644
index 0000000000..beab31f753
--- /dev/null
+++ b/app/src/main/res/values/ic_launcher_background.xml
@@ -0,0 +1,4 @@
+
+
+ #000000
+
\ No newline at end of file
diff --git a/app/src/main/res/values/languages.xml b/app/src/main/res/values/languages.xml
new file mode 100644
index 0000000000..0a4c73bd7f
--- /dev/null
+++ b/app/src/main/res/values/languages.xml
@@ -0,0 +1,378 @@
+
+
+
+ None
+ Abkhazian
+ Afar
+ Afrikaans
+ Akan
+ Albanian
+ Amharic
+ Arabic
+ Aragonese
+ Armenian
+ Assamese
+ Avaric
+ Avestan
+ Aymara
+ Azerbaijani
+ Bambara
+ Bashkir
+ Basque
+ Belarusian
+ Bengali
+ Bihari languages
+ Bislama
+ Bokmål, Norwegian; Norwegian Bokmål
+ Bosnian
+ Breton
+ Bulgarian
+ Burmese
+ Catalan
+ Central Khmer
+ Chamorro
+ Chechen
+ Chichewa
+ Chinese
+ Church Slavic
+ Chuvash
+ Cornish
+ Corsican
+ Cree
+ Croatian
+ Czech
+ Danish
+ Divehi
+ Dutch
+ Dzongkha
+ English
+ Esperanto
+ Estonian
+ Ewe
+ Faroese
+ Fijian
+ Finnish
+ French
+ Fulah
+ Gaelic
+ Galician
+ Ganda
+ Georgian
+ German
+ Greek, Modern (1453-)
+ Guarani
+ Gujarati
+ Haitian
+ Hausa
+ Hebrew
+ Herero
+ Hindi
+ Hiri Motu
+ Hungarian
+ Icelandic
+ Ido
+ Igbo
+ Indonesian
+ Interlingua (International Auxiliary Language Association)
+ Interlingue
+ Inuktitut
+ Inupiaq
+ Irish
+ Italian
+ Japanese
+ Javanese
+ Kalaallisut
+ Kannada
+ Kanuri
+ Kashmiri
+ Kazakh
+ Kikuyu
+ Kinyarwanda
+ Kirghiz
+ Komi
+ Kongo
+ Korean
+ Kuanyama
+ Kurdish
+ Lao
+ Latin
+ Latvian
+ Limburgan
+ Lingala
+ Lithuanian
+ Luba-Katanga
+ Luxembourgish
+ Macedonian
+ Malagasy
+ Malay
+ Malayalam
+ Maltese
+ Manx
+ Maori
+ Marathi
+ Marshallese
+ Mongolian
+ Nauru
+ Navajo
+ Ndebele, North; North Ndebele
+ Ndebele, South; South Ndebele
+ Ndonga
+ Nepali
+ Northern Sami
+ Norwegian
+ Norwegian Nynorsk; Nynorsk, Norwegian
+ Occitan (post 1500)
+ Ojibwa
+ Oriya
+ Oromo
+ Ossetian
+ Pali
+ Panjabi
+ Persian
+ Polish
+ Portuguese
+ Pushto
+ Quechua
+ Romanian
+ Romansh
+ Rundi
+ Russian
+ Samoan
+ Sango
+ Sanskrit
+ Sardinian
+ Serbian
+ Shona
+ Sichuan Yi
+ Sindhi
+ Sinhala
+ Slovak
+ Slovenian
+ Somali
+ Sotho, Southern
+ Spanish
+ Sundanese
+ Swahili
+ Swati
+ Swedish
+ Tagalog
+ Tahitian
+ Tajik
+ Tamil
+ Tatar
+ Telugu
+ Thai
+ Tibetan
+ Tigrinya
+ Tonga (Tonga Islands)
+ Tsonga
+ Tswana
+ Turkish
+ Turkmen
+ Twi
+ Uighur
+ Ukrainian
+ Urdu
+ Uzbek
+ Venda
+ Vietnamese
+ Volapük
+ Walloon
+ Welsh
+ Western Frisian
+ Wolof
+ Xhosa
+ Yiddish
+ Yoruba
+ Zhuang
+ Zulu
+
+
+
+ null
+ ab
+ aa
+ af
+ ak
+ sq
+ am
+ ar
+ an
+ hy
+ as
+ av
+ ae
+ ay
+ az
+ bm
+ ba
+ eu
+ be
+ bn
+ bh
+ bi
+ nb
+ bs
+ br
+ bg
+ my
+ ca
+ km
+ ch
+ ce
+ ny
+ zh
+ cu
+ cv
+ kw
+ co
+ cr
+ hr
+ cs
+ da
+ dv
+ nl
+ dz
+ en
+ eo
+ et
+ ee
+ fo
+ fj
+ fi
+ fr
+ ff
+ gd
+ gl
+ lg
+ ka
+ de
+ el
+ gn
+ gu
+ ht
+ ha
+ he
+ hz
+ hi
+ ho
+ hu
+ is
+ io
+ ig
+ id
+ ia
+ ie
+ iu
+ ik
+ ga
+ it
+ ja
+ jv
+ kl
+ kn
+ kr
+ ks
+ kk
+ ki
+ rw
+ ky
+ kv
+ kg
+ ko
+ kj
+ ku
+ lo
+ la
+ lv
+ li
+ ln
+ lt
+ lu
+ lb
+ mk
+ mg
+ ms
+ ml
+ mt
+ gv
+ mi
+ mr
+ mh
+ mn
+ na
+ nv
+ nd
+ nr
+ ng
+ ne
+ se
+ no
+ nn
+ oc
+ oj
+ or
+ om
+ os
+ pi
+ pa
+ fa
+ pl
+ pt
+ ps
+ qu
+ ro
+ rm
+ rn
+ ru
+ sm
+ sg
+ sa
+ sc
+ sr
+ sn
+ ii
+ sd
+ si
+ sk
+ sl
+ so
+ st
+ es
+ su
+ sw
+ ss
+ sv
+ tl
+ ty
+ tg
+ ta
+ tt
+ te
+ th
+ bo
+ ti
+ to
+ ts
+ tn
+ tr
+ tk
+ tw
+ ug
+ uk
+ ur
+ uz
+ ve
+ vi
+ vo
+ wa
+ cy
+ fy
+ wo
+ xh
+ yi
+ yo
+ za
+ zu
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index f726cef1bd..c1c8aca16e 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,3 +1,57 @@
- Jellyfin
+ Findroid
+ Jellyfin banner
+ Add server
+ Login
+ Select server
+ Server address
+ Username
+ Password
+ Connect
+ Login
+ Server icon
+ Remove server
+ Are you sure you want to remove the server %1$s
+ Remove
+ Cancel
+ MainActivity
+ Home
+ My media
+ Favorites
+ Settings
+ View all
+ Error loading data
+ Retry
+ Genres
+ Director
+ Writers
+
+ Seasons
+ Play the media
+ Watch the trailer
+ Mark as watched or unwatched
+ Favorite
+ Episode watched indicator
+ %1$d. %2$s
+ S%1$d:E%2$d - %3$s
+ Next Up
+ Continue Watching
+ Latest %1$s
+ Series poster
+ You have no favorites
+ Search
+ No search results
+ Language
+ Preferred audio language
+ Preferred subtitle language
+ Initializing…
+ Servers
+ Manage servers
+ Appearance
+ Theme
+ Error preparing player items
+ Version
+ Open source licenses
+ About
+ Privacy policy
\ No newline at end of file
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
new file mode 100644
index 0000000000..4c7729be87
--- /dev/null
+++ b/app/src/main/res/values/styles.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
index d9e1eb68a8..ceb49f5c4b 100644
--- a/app/src/main/res/values/themes.xml
+++ b/app/src/main/res/values/themes.xml
@@ -1,16 +1,37 @@
-
+
-
+
+
+
+
+ Follow system
+ Light
+ Dark
+
+
+
+ system
+ light
+ dark
+
\ No newline at end of file
diff --git a/app/src/main/res/xml/fragment_settings.xml b/app/src/main/res/xml/fragment_settings.xml
new file mode 100644
index 0000000000..dfa140bc1d
--- /dev/null
+++ b/app/src/main/res/xml/fragment_settings.xml
@@ -0,0 +1,56 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 2f3d35bb04..29d39b5e00 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,16 +1,24 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
- ext.kotlin_version = "1.5.10"
+ ext.kotlin_version = "1.5.21"
repositories {
google()
mavenCentral()
}
dependencies {
- classpath "com.android.tools.build:gradle:4.2.1"
+ classpath 'com.android.tools.build:gradle:7.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
+ def nav_version = "2.3.5"
+ classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
+
+ def hilt_version = "2.38.1"
+ classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
+
+ def oss_licenses_version = "0.10.4"
+ classpath "com.google.android.gms:oss-licenses-plugin:$oss_licenses_version"
}
}
@@ -18,7 +26,6 @@ allprojects {
repositories {
google()
mavenCentral()
- jcenter() // Warning: this repository is going to shut down soon
}
}
diff --git a/gradle.properties b/gradle.properties
index 252175276f..2d78535049 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -16,4 +16,5 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Kotlin code style for this project: "official" or "obsolete":
-kotlin.code.style=official
\ No newline at end of file
+kotlin.code.style=official
+android.injected.testOnly=false
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 383275ed25..36a2a9a2ce 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
#Sat May 29 10:38:39 CEST 2021
distributionBase=GRADLE_USER_HOME
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
diff --git a/images/banner.svg b/images/banner.svg
new file mode 100644
index 0000000000..a9ee7e30f9
--- /dev/null
+++ b/images/banner.svg
@@ -0,0 +1,45 @@
+
+
diff --git a/images/episode-dark.png b/images/episode-dark.png
new file mode 100755
index 0000000000..2d7c4e1e09
Binary files /dev/null and b/images/episode-dark.png differ
diff --git a/images/home-light-dark.png b/images/home-light-dark.png
new file mode 100644
index 0000000000..262a774cc1
Binary files /dev/null and b/images/home-light-dark.png differ
diff --git a/images/library-dark.png b/images/library-dark.png
new file mode 100755
index 0000000000..1c1a02350e
Binary files /dev/null and b/images/library-dark.png differ
diff --git a/images/movie-dark.png b/images/movie-dark.png
new file mode 100755
index 0000000000..62902c7a2d
Binary files /dev/null and b/images/movie-dark.png differ
diff --git a/images/season-dark.png b/images/season-dark.png
new file mode 100755
index 0000000000..64f5e54c3f
Binary files /dev/null and b/images/season-dark.png differ