mirror of
https://github.com/gezimos/inkOS.git
synced 2025-12-23 22:17:55 -05:00
Initial commit
This commit is contained in:
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
13
.gitignore
vendored
Normal file
13
.gitignore
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
.gradle
|
||||
.kotlin
|
||||
.idea
|
||||
git-cliff*
|
||||
bin/*
|
||||
local.properties
|
||||
build
|
||||
pages
|
||||
wiki
|
||||
app/release
|
||||
app/build
|
||||
app/debug
|
||||
diff.*
|
||||
5
CHANGELOG.md
Normal file
5
CHANGELOG.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.
|
||||
|
||||
190
DOCUMENTATION.md
Normal file
190
DOCUMENTATION.md
Normal file
@@ -0,0 +1,190 @@
|
||||
# 📱 App Documentation
|
||||
|
||||
---
|
||||
|
||||
## 🔧 Features
|
||||
|
||||
**Padding Size**
|
||||
Controls the gap between home app items. Font family and size can affect this spacing, so it’s
|
||||
recommended to adjust it for better visibility.
|
||||
|
||||
**Re-order Apps**
|
||||
Easily drag and drop apps to rearrange their order in the home menu.
|
||||
|
||||
**Extend Clickable Area**
|
||||
Makes the full horizontal area of app names clickable.
|
||||
E.g., `[Calendar] → [ Calendar ]`
|
||||
|
||||
**Number of Home Apps**
|
||||
Sets how many apps in total are featured on the home screen.
|
||||
|
||||
**Number of Pages**
|
||||
Determines the total number of pages. Apps will be auto-divided across pages.
|
||||
|
||||
**Enable Page Indicator**
|
||||
Displays dots on the right side to indicate the current page.
|
||||
|
||||
**Show Clock**
|
||||
Enables the clock widget at the top of the home screen.
|
||||
|
||||
**Show Battery**
|
||||
Enables the battery widget at the bottom of the home screen.
|
||||
|
||||
---
|
||||
|
||||
## 🅰 Fonts
|
||||
|
||||
**Universal Font**
|
||||
Sets a single font family for all font-selectable items. When enabled, only text size can be
|
||||
modified.
|
||||
*Tip: Set a universal font, then disable it to customize specific fonts (e.g., a display font for
|
||||
the clock).*
|
||||
|
||||
**Settings Font/Text Size**
|
||||
Controls font family and text size for all settings menus.
|
||||
|
||||
**App Font/Text Size**
|
||||
Controls font and size for home menu apps, app drawer, and hidden apps.
|
||||
|
||||
**Clock Font/Text Size**
|
||||
Controls font and size for the Clock widget.
|
||||
|
||||
**Battery Font/Text Size**
|
||||
Controls font and size for the Battery widget.
|
||||
|
||||
**Label Notifications**
|
||||
Controls font and size for notification previews under app names.
|
||||
E.g.,
|
||||
`Whatsapp`
|
||||
`John: Message goes here`
|
||||
*Character limit adjustable in* **Settings > Notifications**.
|
||||
|
||||
**Window Title/Font/Size**
|
||||
Sets the title string and its font/size for the notification window (opened by swiping left).
|
||||
|
||||
**Body Font**
|
||||
Controls the body text in the notification window.
|
||||
|
||||
---
|
||||
|
||||
## 🎨 Look & Feel
|
||||
|
||||
**Theme Mode**
|
||||
Switch between light and dark themes.
|
||||
|
||||
**E-Ink Auto Refresh**
|
||||
Optimized for e-ink devices (e.g., Mudita Kompakt). Flashes the screen after exiting apps to clean
|
||||
ghosting artifacts.
|
||||
*Note: Doesn't apply to overlays like quick settings; press the home button to exit.*
|
||||
|
||||
**Show Status Bar**
|
||||
Displays the top status bar (carrier, clock, battery, Wi-Fi, Bluetooth).
|
||||
|
||||
**Element Colors**
|
||||
Allows setting custom UI colors.
|
||||
*Recommended only for AMOLED displays. Not suitable for e-ink screens.*
|
||||
|
||||
---
|
||||
|
||||
## ✋ Gestures
|
||||
|
||||
**Volume Keys Swipe**
|
||||
Navigate between pages using the volume keys.
|
||||
|
||||
**Double Tap**
|
||||
Customize double tap to:
|
||||
|
||||
- Restart launcher
|
||||
- Open notifications window
|
||||
- Disable the gesture
|
||||
|
||||
**Click on Clock**
|
||||
Customize clock tap to:
|
||||
|
||||
- Open clock (alarm app)
|
||||
- Restart launcher
|
||||
- Open notifications window
|
||||
|
||||
**Swipe Left / Swipe Right**
|
||||
Default actions:
|
||||
|
||||
- Swipe left: Open notifications
|
||||
- Swipe right: Open phone app
|
||||
*You can also assign these to page navigation.*
|
||||
|
||||
---
|
||||
|
||||
## 🔔 Notifications
|
||||
|
||||
**Push Notifications**
|
||||
Enable or disable notifications system-wide.
|
||||
*System permission dialog will guide you.*
|
||||
|
||||
**Asterisk**
|
||||
Adds a `*` next to app names with pending notifications.
|
||||
|
||||
**Label Notifications**
|
||||
Shows actual notification content below app names.
|
||||
*Great for chat/media apps.*
|
||||
|
||||
**Media Playing Asterisk**
|
||||
Displays a music note `♪` beside apps currently playing media.
|
||||
|
||||
**Media Playing Name**
|
||||
Displays the name of currently playing media (e.g., song, podcast, audio file).
|
||||
|
||||
**Home Notifications Allowlist**
|
||||
Choose which apps can show label notifications on the home screen.
|
||||
*Highly recommended for focus and clarity.*
|
||||
|
||||
**Chat Notifications**
|
||||
Controls for:
|
||||
|
||||
- Sender/group name
|
||||
- Message preview
|
||||
- Character limits
|
||||
*Important for layout stability—depends on font and size.*
|
||||
|
||||
**Notification Window**
|
||||
Enables a dedicated window to read full messages.
|
||||
|
||||
- Has a separate allowlist
|
||||
- Some limitations apply based on app permissions
|
||||
|
||||
---
|
||||
|
||||
## ⚙️ Advanced
|
||||
|
||||
**Hidden Apps**
|
||||
Hide apps from the App Drawer (e.g., system apps).
|
||||
|
||||
**Lock Home Apps**
|
||||
Prevents app changes on the home screen via long press.
|
||||
|
||||
**Long Press for App Info**
|
||||
Opens the system dialog to uninstall or force stop apps.
|
||||
*Especially useful for phones with no recents menu.*
|
||||
|
||||
**Lock Settings**
|
||||
Lock the Settings menu with fingerprint or PIN to avoid accidental changes.
|
||||
|
||||
**Backup / Restore**
|
||||
|
||||
- **Backup:** Save current settings for future restoration (e.g., factory reset or new device).
|
||||
- **Restore:** Load saved settings.
|
||||
*Note: Custom fonts are not backed up.*
|
||||
- **Clear All Data:** Reset everything to default.
|
||||
|
||||
---
|
||||
|
||||
## 🗂️ Open App Drawer
|
||||
|
||||
Displays a scrollable list of all installed apps.
|
||||
|
||||
**Long Press Options:**
|
||||
|
||||
1. **Delete:** Uninstalls the app
|
||||
2. **Rename:** Change app name/alias (affects home too)
|
||||
3. **Hide:** Moves the app to the hidden apps list
|
||||
4. **Lock:** Requires fingerprint/PIN to open
|
||||
5. **Info:** Opens the system info dialog
|
||||
217
Gemfile.lock
Normal file
217
Gemfile.lock
Normal file
@@ -0,0 +1,217 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
CFPropertyList (3.0.5)
|
||||
rexml
|
||||
addressable (2.8.0)
|
||||
public_suffix (>= 2.0.2, < 5.0)
|
||||
artifactory (3.0.15)
|
||||
atomos (0.1.3)
|
||||
aws-eventstream (1.2.0)
|
||||
aws-partitions (1.578.0)
|
||||
aws-sdk-core (3.130.1)
|
||||
aws-eventstream (~> 1, >= 1.0.2)
|
||||
aws-partitions (~> 1, >= 1.525.0)
|
||||
aws-sigv4 (~> 1.1)
|
||||
jmespath (~> 1.0)
|
||||
aws-sdk-kms (1.56.0)
|
||||
aws-sdk-core (~> 3, >= 3.127.0)
|
||||
aws-sigv4 (~> 1.1)
|
||||
aws-sdk-s3 (1.113.0)
|
||||
aws-sdk-core (~> 3, >= 3.127.0)
|
||||
aws-sdk-kms (~> 1)
|
||||
aws-sigv4 (~> 1.4)
|
||||
aws-sigv4 (1.4.0)
|
||||
aws-eventstream (~> 1, >= 1.0.2)
|
||||
babosa (1.0.4)
|
||||
claide (1.1.0)
|
||||
colored (1.2)
|
||||
colored2 (3.1.2)
|
||||
commander (4.6.0)
|
||||
highline (~> 2.0.0)
|
||||
declarative (0.0.20)
|
||||
digest-crc (0.6.4)
|
||||
rake (>= 12.0.0, < 14.0.0)
|
||||
domain_name (0.5.20190701)
|
||||
unf (>= 0.0.5, < 1.0.0)
|
||||
dotenv (2.7.6)
|
||||
emoji_regex (3.2.3)
|
||||
excon (0.92.2)
|
||||
faraday (1.10.0)
|
||||
faraday-em_http (~> 1.0)
|
||||
faraday-em_synchrony (~> 1.0)
|
||||
faraday-excon (~> 1.1)
|
||||
faraday-httpclient (~> 1.0)
|
||||
faraday-multipart (~> 1.0)
|
||||
faraday-net_http (~> 1.0)
|
||||
faraday-net_http_persistent (~> 1.0)
|
||||
faraday-patron (~> 1.0)
|
||||
faraday-rack (~> 1.0)
|
||||
faraday-retry (~> 1.0)
|
||||
ruby2_keywords (>= 0.0.4)
|
||||
faraday-cookie_jar (0.0.7)
|
||||
faraday (>= 0.8.0)
|
||||
http-cookie (~> 1.0.0)
|
||||
faraday-em_http (1.0.0)
|
||||
faraday-em_synchrony (1.0.0)
|
||||
faraday-excon (1.1.0)
|
||||
faraday-httpclient (1.0.1)
|
||||
faraday-multipart (1.0.3)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
faraday-net_http (1.0.1)
|
||||
faraday-net_http_persistent (1.2.0)
|
||||
faraday-patron (1.0.0)
|
||||
faraday-rack (1.0.0)
|
||||
faraday-retry (1.0.3)
|
||||
faraday_middleware (1.2.0)
|
||||
faraday (~> 1.0)
|
||||
fastimage (2.2.6)
|
||||
fastlane (2.214.0)
|
||||
CFPropertyList (>= 2.3, < 4.0.0)
|
||||
addressable (>= 2.8, < 3.0.0)
|
||||
artifactory (~> 3.0)
|
||||
aws-sdk-s3 (~> 1.0)
|
||||
babosa (>= 1.0.3, < 2.0.0)
|
||||
bundler (>= 1.12.0, < 3.0.0)
|
||||
colored
|
||||
commander (~> 4.6)
|
||||
dotenv (>= 2.1.1, < 3.0.0)
|
||||
emoji_regex (>= 0.1, < 4.0)
|
||||
excon (>= 0.71.0, < 1.0.0)
|
||||
faraday (~> 1.0)
|
||||
faraday-cookie_jar (~> 0.0.6)
|
||||
faraday_middleware (~> 1.0)
|
||||
fastimage (>= 2.1.0, < 3.0.0)
|
||||
gh_inspector (>= 1.1.2, < 2.0.0)
|
||||
google-apis-androidpublisher_v3 (~> 0.3)
|
||||
google-apis-playcustomapp_v1 (~> 0.1)
|
||||
google-cloud-storage (~> 1.31)
|
||||
highline (~> 2.0)
|
||||
json (< 3.0.0)
|
||||
jwt (>= 2.1.0, < 3)
|
||||
mini_magick (>= 4.9.4, < 5.0.0)
|
||||
multipart-post (>= 2.0.0, < 3.0.0)
|
||||
naturally (~> 2.2)
|
||||
optparse (~> 0.1.1)
|
||||
plist (>= 3.1.0, < 4.0.0)
|
||||
rubyzip (>= 2.0.0, < 3.0.0)
|
||||
security (= 0.1.3)
|
||||
simctl (~> 1.6.3)
|
||||
terminal-notifier (>= 2.0.0, < 3.0.0)
|
||||
terminal-table (>= 1.4.5, < 2.0.0)
|
||||
tty-screen (>= 0.6.3, < 1.0.0)
|
||||
tty-spinner (>= 0.8.0, < 1.0.0)
|
||||
word_wrap (~> 1.0.0)
|
||||
xcodeproj (>= 1.13.0, < 2.0.0)
|
||||
xcpretty (~> 0.3.0)
|
||||
xcpretty-travis-formatter (>= 0.0.3)
|
||||
gh_inspector (1.1.3)
|
||||
google-apis-androidpublisher_v3 (0.19.0)
|
||||
google-apis-core (>= 0.4, < 2.a)
|
||||
google-apis-core (0.4.2)
|
||||
addressable (~> 2.5, >= 2.5.1)
|
||||
googleauth (>= 0.16.2, < 2.a)
|
||||
httpclient (>= 2.8.1, < 3.a)
|
||||
mini_mime (~> 1.0)
|
||||
representable (~> 3.0)
|
||||
retriable (>= 2.0, < 4.a)
|
||||
rexml
|
||||
webrick
|
||||
google-apis-iamcredentials_v1 (0.10.0)
|
||||
google-apis-core (>= 0.4, < 2.a)
|
||||
google-apis-playcustomapp_v1 (0.7.0)
|
||||
google-apis-core (>= 0.4, < 2.a)
|
||||
google-apis-storage_v1 (0.13.0)
|
||||
google-apis-core (>= 0.4, < 2.a)
|
||||
google-cloud-core (1.6.0)
|
||||
google-cloud-env (~> 1.0)
|
||||
google-cloud-errors (~> 1.0)
|
||||
google-cloud-env (1.6.0)
|
||||
faraday (>= 0.17.3, < 3.0)
|
||||
google-cloud-errors (1.2.0)
|
||||
google-cloud-storage (1.36.2)
|
||||
addressable (~> 2.8)
|
||||
digest-crc (~> 0.4)
|
||||
google-apis-iamcredentials_v1 (~> 0.1)
|
||||
google-apis-storage_v1 (~> 0.1)
|
||||
google-cloud-core (~> 1.6)
|
||||
googleauth (>= 0.16.2, < 2.a)
|
||||
mini_mime (~> 1.0)
|
||||
googleauth (1.1.2)
|
||||
faraday (>= 0.17.3, < 3.a)
|
||||
jwt (>= 1.4, < 3.0)
|
||||
memoist (~> 0.16)
|
||||
multi_json (~> 1.11)
|
||||
os (>= 0.9, < 2.0)
|
||||
signet (>= 0.16, < 2.a)
|
||||
highline (2.0.3)
|
||||
http-cookie (1.0.4)
|
||||
domain_name (~> 0.5)
|
||||
httpclient (2.8.3)
|
||||
jmespath (1.6.1)
|
||||
json (2.6.1)
|
||||
jwt (2.3.0)
|
||||
memoist (0.16.2)
|
||||
mini_magick (4.11.0)
|
||||
mini_mime (1.1.2)
|
||||
multi_json (1.15.0)
|
||||
multipart-post (2.0.0)
|
||||
nanaimo (0.3.0)
|
||||
naturally (2.2.1)
|
||||
optparse (0.1.1)
|
||||
os (1.1.4)
|
||||
plist (3.6.0)
|
||||
public_suffix (4.0.7)
|
||||
rake (13.0.6)
|
||||
representable (3.1.1)
|
||||
declarative (< 0.1.0)
|
||||
trailblazer-option (>= 0.1.1, < 0.2.0)
|
||||
uber (< 0.2.0)
|
||||
retriable (3.1.2)
|
||||
rexml (3.3.9)
|
||||
rouge (2.0.7)
|
||||
ruby2_keywords (0.0.5)
|
||||
rubyzip (2.3.2)
|
||||
security (0.1.3)
|
||||
signet (0.16.1)
|
||||
addressable (~> 2.8)
|
||||
faraday (>= 0.17.5, < 3.0)
|
||||
jwt (>= 1.5, < 3.0)
|
||||
multi_json (~> 1.10)
|
||||
simctl (1.6.8)
|
||||
CFPropertyList
|
||||
naturally
|
||||
terminal-notifier (2.0.0)
|
||||
terminal-table (1.8.0)
|
||||
unicode-display_width (~> 1.1, >= 1.1.1)
|
||||
trailblazer-option (0.1.2)
|
||||
tty-cursor (0.7.1)
|
||||
tty-screen (0.8.1)
|
||||
tty-spinner (0.9.3)
|
||||
tty-cursor (~> 0.7)
|
||||
uber (0.1.0)
|
||||
unf (0.1.4)
|
||||
unf_ext
|
||||
unf_ext (0.0.8.1)
|
||||
unicode-display_width (1.8.0)
|
||||
webrick (1.8.2)
|
||||
word_wrap (1.0.0)
|
||||
xcodeproj (1.19.0)
|
||||
CFPropertyList (>= 2.3.3, < 4.0)
|
||||
atomos (~> 0.1.3)
|
||||
claide (>= 1.0.2, < 2.0)
|
||||
colored2 (~> 3.1)
|
||||
nanaimo (~> 0.3.0)
|
||||
xcpretty (0.3.0)
|
||||
rouge (~> 2.0.7)
|
||||
xcpretty-travis-formatter (1.0.1)
|
||||
xcpretty (~> 0.2, >= 0.0.7)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
fastlane
|
||||
|
||||
BUNDLED WITH
|
||||
2.1.4
|
||||
674
LICENSE
Normal file
674
LICENSE
Normal file
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
101
README.md
Normal file
101
README.md
Normal file
@@ -0,0 +1,101 @@
|
||||
<div style="text-align: center;">
|
||||
<h2>inkOS - Text based & E-ink friendly Android Launcher </h2>
|
||||
<table>
|
||||
<tr>
|
||||
<td><img src='fastlane/metadata/android/en-US/images/phoneScreenshots/0.png' height='300' alt=""></td>
|
||||
<td><img src='fastlane/metadata/android/en-US/images/phoneScreenshots/1.png' height='300' alt=""></td>
|
||||
<td><img src='fastlane/metadata/android/en-US/images/phoneScreenshots/2.png' height='300' alt=""></td>
|
||||
<td><img src='fastlane/metadata/android/en-US/images/phoneScreenshots/3.png' height='300' alt=""></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
Click on any image to enlarge it. To know more, read [documentation](DOCUMENTATION.md).
|
||||
|
||||
# Tested on Android 10 to 16.
|
||||
|
||||
It works well with these minimal/dumbphone devices:
|
||||
|
||||
- Mudita Kompakt
|
||||
- LightPhone 3 (tested on emulator)
|
||||
- QIN F22
|
||||
- Cat S22 flip
|
||||
|
||||
# Forked with extra features
|
||||
|
||||
<details><summary>List of features (click to expand)</summary>
|
||||
|
||||
- No ads, trackers, or unnecessary permissions (no internet permission).
|
||||
- Reorder apps on the home screen by drag & drop.
|
||||
- Rename, hide, lock, or uninstall apps from the app drawer.
|
||||
- Customize font size and style for:
|
||||
- Home screen apps
|
||||
- Clock
|
||||
- Battery widget
|
||||
- Notifications
|
||||
- Settings
|
||||
- Set a universal font or individually customize each text section.
|
||||
- Fine-tune padding (spacing) between home screen apps.
|
||||
- Set how many apps appear on the home screen and how many pages exist.
|
||||
- Page indicators (dots) show your current page on the right side.
|
||||
- Optionally show clock and battery widgets on the home screen.
|
||||
- Gesture support:
|
||||
- Swiping left/right
|
||||
- Clicking the clock
|
||||
- Double-tap
|
||||
- Volume key page navigation
|
||||
- (Actions: open app, open notifications, restart launcher, disable gesture, more)
|
||||
- Full notification control:
|
||||
- Show message previews under app names
|
||||
- Show media playing info (title, music note icon)
|
||||
- Use app allowlist for chat/media apps
|
||||
- Optional full-screen notification reader window
|
||||
- E-ink mode auto-refresh to clean up ghosting (for e-ink devices).
|
||||
- Theme mode (light/dark), with color options for AMOLED (not recommended for e-ink).
|
||||
- Show or hide the status bar (carrier, clock, battery, etc.).
|
||||
- Lock settings or individual apps with PIN/fingerprint.
|
||||
- Long-press apps for quick access to system info or force-stop.
|
||||
- Backup and restore your setup across devices (excludes custom fonts).
|
||||
- Clean “Reset All” option to return to default.
|
||||
|
||||
</details>
|
||||
|
||||
## Permissions
|
||||
|
||||
inkOS uses the following permissions:
|
||||
|
||||
- `android.permission.EXPAND_STATUS_BAR`
|
||||
- Allows the launcher to expand or collapse the status bar (for gestures and quick access).
|
||||
- `android.permission.QUERY_ALL_PACKAGES`
|
||||
- Allows the launcher to list all installed apps, so you can see and manage them.
|
||||
- `android.permission.REQUEST_DELETE_PACKAGES`
|
||||
- Allows the launcher to request the uninstallation of apps (user confirmation required).
|
||||
- `android.permission.USE_BIOMETRIC`
|
||||
- Enables PIN or fingerprint lock for apps or settings.
|
||||
- `android.permission.SYSTEM_ALERT_WINDOW`
|
||||
- Required for overlay features, such as showing notifications or dialogs over other apps.
|
||||
- `android.permission.FOREGROUND_SERVICE`
|
||||
- Allows the launcher to run foreground services for persistent features (e.g., notification
|
||||
listener).
|
||||
- `android.permission.VIBRATE`
|
||||
- Enables vibration feedback for certain actions.
|
||||
|
||||
> **Note:** inkOS does not request internet access and does not collect or transmit any data.
|
||||
|
||||
## License
|
||||
|
||||
inkOS is open source under the GPLv3 license, giving you the freedom to use, study, modify, and
|
||||
distribute it. The Copyleft provision ensures these freedoms remain intact, so inkOS will always be
|
||||
fully open source and customizable by anyone.
|
||||
|
||||
- inkOS does not have network access.
|
||||
- inkOS does not collect or transmit any data in any way whatsoever.
|
||||
|
||||
## Credits
|
||||
|
||||
- [https://github.com/DroidWorksStudio/mLauncher](https://github.com/DroidWorksStudio/mLauncher)
|
||||
- [https://github.com/tanujnotes/Olauncher](https://github.com/tanujnotes/Olauncher)
|
||||
- [https://github.com/OlauncherCF/OlauncherCF](https://github.com/OlauncherCF/OlauncherCF)
|
||||
|
||||
## Donation
|
||||
BIN
app/.DS_Store
vendored
Normal file
BIN
app/.DS_Store
vendored
Normal file
Binary file not shown.
1
app/.gitignore
vendored
Normal file
1
app/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
||||
161
app/build.gradle.kts
Normal file
161
app/build.gradle.kts
Normal file
@@ -0,0 +1,161 @@
|
||||
@file:Suppress("UnstableApiUsage")
|
||||
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("org.jetbrains.kotlin.android")
|
||||
id("org.jetbrains.kotlin.plugin.compose")
|
||||
id("kotlin-android")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "com.github.gezimos.inkos"
|
||||
compileSdk = 36
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "app.inkos"
|
||||
minSdk = 26
|
||||
targetSdk = 36
|
||||
versionCode = 101001
|
||||
versionName = "0.1"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
getByName("debug") {
|
||||
isMinifyEnabled = false
|
||||
isShrinkResources = false
|
||||
isDebuggable = true
|
||||
applicationIdSuffix = ".debug"
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
resValue("string", "app_name", "inkOS Debug")
|
||||
}
|
||||
|
||||
getByName("release") {
|
||||
isMinifyEnabled = true
|
||||
isShrinkResources = true
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
resValue("string", "app_name", "inkOS")
|
||||
}
|
||||
}
|
||||
|
||||
applicationVariants.all {
|
||||
if (buildType.name == "release") {
|
||||
outputs.all {
|
||||
val output = this as? com.android.build.gradle.internal.api.BaseVariantOutputImpl
|
||||
if (output?.outputFileName?.endsWith(".apk") == true) {
|
||||
output.outputFileName =
|
||||
"${defaultConfig.applicationId}_v${defaultConfig.versionName}-Signed.apk"
|
||||
}
|
||||
}
|
||||
}
|
||||
if (buildType.name == "debug") {
|
||||
outputs.all {
|
||||
val output = this as? com.android.build.gradle.internal.api.BaseVariantOutputImpl
|
||||
if (output?.outputFileName?.endsWith(".apk") == true) {
|
||||
output.outputFileName =
|
||||
"${defaultConfig.applicationId}_v${defaultConfig.versionName}-Debug.apk"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
compose = true
|
||||
viewBinding = true
|
||||
buildConfig = true
|
||||
}
|
||||
|
||||
composeOptions {
|
||||
kotlinCompilerExtensionVersion = "1.6.0"
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_17.toString()
|
||||
}
|
||||
|
||||
lint {
|
||||
abortOnError = false
|
||||
}
|
||||
|
||||
packaging {
|
||||
// Keep debug symbols for specific native libraries
|
||||
// found in /app/build/intermediates/merged_native_libs/release/mergeReleaseNativeLibs/out/lib
|
||||
jniLibs {
|
||||
keepDebugSymbols.add("libandroidx.graphics.path.so") // Ensure debug symbols are kept
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
|
||||
// Core libraries
|
||||
implementation(libs.core.ktx)
|
||||
implementation(libs.appcompat)
|
||||
implementation(libs.recyclerview)
|
||||
implementation(libs.palette.ktx)
|
||||
|
||||
// Android Lifecycle
|
||||
implementation(libs.lifecycle.extensions)
|
||||
implementation(libs.lifecycle.viewmodel.ktx)
|
||||
|
||||
// Navigation
|
||||
implementation(libs.navigation.fragment.ktx)
|
||||
implementation(libs.navigation.ui.ktx)
|
||||
|
||||
// Work Manager
|
||||
implementation(libs.work.runtime.ktx)
|
||||
|
||||
// UI Components
|
||||
implementation(libs.constraintlayout)
|
||||
implementation(libs.constraintlayout.compose)
|
||||
implementation(libs.activity.compose)
|
||||
|
||||
// Jetpack Compose
|
||||
implementation(libs.compose.material) // Compose Material Design
|
||||
implementation(libs.compose.android) // Android
|
||||
implementation(libs.compose.animation) // Animations
|
||||
implementation(libs.compose.ui) // Core UI library
|
||||
implementation("androidx.compose.foundation:foundation:1.6.0") // Foundation library (stickyHeader)
|
||||
implementation(libs.compose.ui.tooling) // UI tooling for previews
|
||||
implementation("androidx.compose.foundation:foundation:1.6.0") // For VerticalPager
|
||||
implementation("com.google.accompanist:accompanist-pager:0.34.0")
|
||||
implementation("com.google.accompanist:accompanist-pager-indicators:0.34.0")
|
||||
implementation("androidx.compose.runtime:runtime-livedata:1.6.0") // <-- Add this line for observeAsState with LiveData
|
||||
|
||||
// Text similarity and JSON handling
|
||||
implementation(libs.commons.text)
|
||||
implementation(libs.gson)
|
||||
|
||||
// Biometric support
|
||||
implementation(libs.biometric.ktx)
|
||||
|
||||
// AndroidX Test - Espresso
|
||||
androidTestImplementation(libs.espresso.core)
|
||||
androidTestImplementation(libs.espresso.contrib)
|
||||
implementation(libs.espresso.idling.resource) // Idling resources for Espresso tests
|
||||
|
||||
// Test rules and other testing dependencies
|
||||
androidTestImplementation(libs.test.runner)
|
||||
androidTestImplementation(libs.test.rules)
|
||||
implementation(libs.test.core.ktx) // Test core utilities
|
||||
|
||||
// Jetpack Compose Testing
|
||||
androidTestImplementation(libs.ui.test.junit4) // For createComposeRule
|
||||
debugImplementation(libs.ui.test.manifest) // Debug-only dependencies for Compose testing
|
||||
|
||||
// Fragment testing
|
||||
debugImplementation(libs.fragment.testing)
|
||||
|
||||
// Navigation testing
|
||||
androidTestImplementation(libs.navigation.testing)
|
||||
}
|
||||
25
app/proguard-rules.pro
vendored
Normal file
25
app/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
|
||||
-dontwarn javax.annotation.processing.Processor
|
||||
-dontwarn javax.annotation.processing.AbstractProcessor
|
||||
-dontwarn javax.annotation.processing.SupportedOptions
|
||||
103
app/src/main/AndroidManifest.xml
Normal file
103
app/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,103 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:dist="http://schemas.android.com/apk/distribution"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<dist:module dist:instant="true" />
|
||||
|
||||
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
|
||||
<uses-permission
|
||||
android:name="android.permission.QUERY_ALL_PACKAGES"
|
||||
tools:ignore="QueryAllPackagesPermission" />
|
||||
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
|
||||
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
|
||||
<application
|
||||
android:name="com.github.gezimos.inkos.inkOS"
|
||||
android:allowBackup="true"
|
||||
android:clearTaskOnLaunch="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:enableOnBackInvokedCallback="true"
|
||||
android:excludeFromRecents="true"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@drawable/app_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
tools:targetApi="tiramisu">
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.fileprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths" />
|
||||
</provider>
|
||||
|
||||
<activity
|
||||
android:name="com.github.gezimos.inkos.MainActivity"
|
||||
android:configChanges="uiMode"
|
||||
android:excludeFromRecents="true"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTask"
|
||||
android:taskAffinity=""
|
||||
android:windowSoftInputMode="stateHidden">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.HOME" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="com.github.gezimos.inkos.FakeHomeActivity"
|
||||
android:enabled="false"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTask"
|
||||
android:windowSoftInputMode="stateHidden">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.HOME" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="com.github.gezimos.inkos.CrashReportActivity"
|
||||
android:enabled="true"
|
||||
android:exported="true" />
|
||||
|
||||
<service
|
||||
android:name="com.github.gezimos.inkos.services.ActionService"
|
||||
android:enabled="true"
|
||||
android:exported="false"
|
||||
android:label="@string/accessibility_service_name"
|
||||
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
|
||||
<meta-data
|
||||
android:name="android.accessibilityservice"
|
||||
android:resource="@xml/accessibility_service_config" />
|
||||
<intent-filter>
|
||||
<action android:name="android.accessibilityservice.AccessibilityService" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<service
|
||||
android:name=".services.NotificationService"
|
||||
android:exported="false"
|
||||
android:label="@string/app_name"
|
||||
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
|
||||
<intent-filter>
|
||||
<action android:name="android.service.notification.NotificationListenerService" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
</application>
|
||||
</manifest>
|
||||
203
app/src/main/java/com/github/gezimos/common/ContextExtensions.kt
Normal file
203
app/src/main/java/com/github/gezimos/common/ContextExtensions.kt
Normal file
@@ -0,0 +1,203 @@
|
||||
package com.github.gezimos.common
|
||||
|
||||
import android.Manifest
|
||||
import android.app.SearchManager
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.LauncherApps
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.Configuration
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.UserHandle
|
||||
import android.provider.AlarmClock
|
||||
import android.provider.CalendarContract
|
||||
import android.provider.MediaStore
|
||||
import android.provider.Settings
|
||||
import android.util.Log.d
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.Toast
|
||||
import androidx.biometric.BiometricManager
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.net.toUri
|
||||
import com.github.gezimos.inkos.services.ActionService
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
|
||||
fun Context.inflate(resource: Int, root: ViewGroup? = null, attachToRoot: Boolean = false): View {
|
||||
return LayoutInflater.from(this).inflate(resource, root, attachToRoot)
|
||||
}
|
||||
|
||||
fun Context.showLongToast(message: String) {
|
||||
Toast.makeText(this, message, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
fun Context.showShortToast(message: String) {
|
||||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
fun Context.hasSoftKeyboard(): Boolean {
|
||||
val config = resources.configuration
|
||||
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
|
||||
// True if the device does not have physical keys AND at least one soft input method is installed
|
||||
return config.keyboard == Configuration.KEYBOARD_NOKEYS && imm.inputMethodList.isNotEmpty()
|
||||
}
|
||||
|
||||
fun Context.openSearch(query: String? = null) {
|
||||
val intent = Intent(Intent.ACTION_WEB_SEARCH)
|
||||
intent.putExtra(SearchManager.QUERY, query ?: "")
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
|
||||
fun Context.openUrl(url: String) {
|
||||
if (url.isEmpty()) return
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
intent.data = url.toUri()
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
fun isGestureNavigationEnabled(context: Context): Boolean {
|
||||
return try {
|
||||
val navigationMode = Settings.Secure.getInt(
|
||||
context.contentResolver,
|
||||
"navigation_mode" // This is the key to check the current navigation mode
|
||||
)
|
||||
// 2 corresponds to gesture navigation mode
|
||||
navigationMode == 2
|
||||
} catch (_: Settings.SettingNotFoundException) {
|
||||
// Handle the case where the setting isn't found, assume not enabled
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.launchCalendar() {
|
||||
try {
|
||||
val cal: Calendar = Calendar.getInstance()
|
||||
cal.time = Date()
|
||||
val time = cal.time.time
|
||||
val builder: Uri.Builder = CalendarContract.CONTENT_URI.buildUpon()
|
||||
builder.appendPath("time")
|
||||
builder.appendPath(time.toString())
|
||||
this.startActivity(Intent(Intent.ACTION_VIEW, builder.build()))
|
||||
} catch (_: Exception) {
|
||||
try {
|
||||
val intent = Intent(Intent.ACTION_MAIN)
|
||||
intent.addCategory(Intent.CATEGORY_APP_CALENDAR)
|
||||
this.startActivity(intent)
|
||||
} catch (e: Exception) {
|
||||
d("openCalendar", e.toString())
|
||||
}
|
||||
}
|
||||
CrashHandler.logUserAction("Calendar App Launched")
|
||||
}
|
||||
|
||||
fun Context.openDialerApp() {
|
||||
try {
|
||||
val sendIntent = Intent(Intent.ACTION_DIAL)
|
||||
this.startActivity(sendIntent)
|
||||
} catch (e: java.lang.Exception) {
|
||||
d("openDialerApp", e.toString())
|
||||
}
|
||||
CrashHandler.logUserAction("Dialer App Launched")
|
||||
}
|
||||
|
||||
fun Context.openAlarmApp() {
|
||||
try {
|
||||
val intent = Intent(AlarmClock.ACTION_SHOW_ALARMS)
|
||||
this.startActivity(intent)
|
||||
} catch (e: java.lang.Exception) {
|
||||
d("openAlarmApp", e.toString())
|
||||
}
|
||||
CrashHandler.logUserAction("Alarm App Launched")
|
||||
}
|
||||
|
||||
fun Context.openCameraApp() {
|
||||
try {
|
||||
val sendIntent = Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA)
|
||||
this.startActivity(sendIntent)
|
||||
} catch (e: java.lang.Exception) {
|
||||
d("openCameraApp", e.toString())
|
||||
}
|
||||
CrashHandler.logUserAction("Camera App Launched")
|
||||
}
|
||||
|
||||
fun Context.openBatteryManager() {
|
||||
try {
|
||||
val intent = Intent(Intent.ACTION_POWER_USAGE_SUMMARY)
|
||||
this.startActivity(intent)
|
||||
} catch (_: ActivityNotFoundException) {
|
||||
showLongToast("Battery manager settings are not available on this device.")
|
||||
}
|
||||
CrashHandler.logUserAction("Battery Manager Launched")
|
||||
}
|
||||
|
||||
|
||||
fun Context.hasInternetPermission(): Boolean {
|
||||
val permission = Manifest.permission.INTERNET
|
||||
val result = ContextCompat.checkSelfPermission(this, permission)
|
||||
return result == PackageManager.PERMISSION_GRANTED
|
||||
}
|
||||
|
||||
fun Context.isPackageInstalled(
|
||||
packageName: String,
|
||||
userHandle: UserHandle = android.os.Process.myUserHandle()
|
||||
): Boolean {
|
||||
val launcher = getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
|
||||
val activityInfo = launcher.getActivityList(packageName, userHandle)
|
||||
return activityInfo.isNotEmpty()
|
||||
}
|
||||
|
||||
fun Context.getAppNameFromPackageName(packageName: String): String? {
|
||||
val packageManager = this.packageManager
|
||||
return try {
|
||||
val appInfo = packageManager.getApplicationInfo(packageName, 0)
|
||||
packageManager.getApplicationLabel(appInfo) as String
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
e.printStackTrace()
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.isSystemApp(packageName: String): Boolean {
|
||||
if (packageName.isBlank()) return true
|
||||
return try {
|
||||
val applicationInfo = packageManager.getApplicationInfo(packageName, 0)
|
||||
((applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM != 0)
|
||||
|| (applicationInfo.flags and ApplicationInfo.FLAG_UPDATED_SYSTEM_APP != 0))
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.isBiometricEnabled(): Boolean {
|
||||
val biometricManager = BiometricManager.from(this)
|
||||
|
||||
return when (biometricManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_STRONG or BiometricManager.Authenticators.DEVICE_CREDENTIAL)) {
|
||||
BiometricManager.BIOMETRIC_SUCCESS -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun Context.openAccessibilitySettings() {
|
||||
val intent = Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)
|
||||
val cs = ComponentName(this.packageName, ActionService::class.java.name).flattenToString()
|
||||
val bundle = Bundle()
|
||||
bundle.putString(":settings:fragment_args_key", cs)
|
||||
intent.apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
putExtra(":settings:fragment_args_key", cs)
|
||||
putExtra(":settings:show_fragment_args", bundle)
|
||||
}
|
||||
this.startActivity(intent)
|
||||
CrashHandler.logUserAction("Accessibility Settings Opened")
|
||||
}
|
||||
167
app/src/main/java/com/github/gezimos/common/CrashHandler.kt
Normal file
167
app/src/main/java/com/github/gezimos/common/CrashHandler.kt
Normal file
@@ -0,0 +1,167 @@
|
||||
package com.github.gezimos.common
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.content.FileProvider
|
||||
import com.github.gezimos.inkos.CrashReportActivity
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileWriter
|
||||
import java.io.InputStreamReader
|
||||
import java.io.PrintWriter
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.LinkedBlockingQueue
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
class CrashHandler(private val context: Context) : Thread.UncaughtExceptionHandler {
|
||||
|
||||
companion object {
|
||||
private val userActions = LinkedBlockingQueue<String>(50) // Stores last 50 user actions
|
||||
|
||||
fun logUserAction(action: String) {
|
||||
val timeStamp = SimpleDateFormat("HH:mm:ss", Locale.getDefault()).format(Date())
|
||||
userActions.offer("$timeStamp - $action")
|
||||
if (userActions.size > 50) userActions.poll() // Remove oldest if over limit
|
||||
}
|
||||
|
||||
fun customReportSender(context: Context): Uri? {
|
||||
val logFile: File = try {
|
||||
val packageManager = context.packageManager
|
||||
val packageInfo = packageManager.getPackageInfo(context.packageName, 0)
|
||||
|
||||
// Use internal storage for saving the crash log
|
||||
val crashDir = File(context.filesDir, "crash_logs") // Internal storage
|
||||
if (!crashDir.exists()) crashDir.mkdirs()
|
||||
|
||||
val crashFile = File(crashDir, "${packageInfo.packageName}-crash-report.txt")
|
||||
|
||||
// Check if the file exists before attempting to read
|
||||
if (crashFile.exists()) {
|
||||
// Read the content of the file
|
||||
val fileInputStream = FileInputStream(crashFile)
|
||||
val inputStreamReader = InputStreamReader(fileInputStream)
|
||||
val stringBuilder = StringBuilder()
|
||||
|
||||
// Read the file line by line
|
||||
inputStreamReader.forEachLine { stringBuilder.append(it).append("\n") }
|
||||
|
||||
// Log the content of the crash report file
|
||||
Log.d("CrashHandler", "Crash Report Content:\n${stringBuilder}")
|
||||
} else {
|
||||
Log.e("CrashHandler", "Crash report file does not exist.")
|
||||
}
|
||||
|
||||
File(crashDir, "${packageInfo.packageName}-crash-report.txt")
|
||||
} catch (e: Exception) {
|
||||
Log.e("CrashHandler", "Error determining crash log file location: ${e.message}")
|
||||
return null // Return null if something goes wrong
|
||||
}
|
||||
|
||||
// Ensure the file exists
|
||||
if (!logFile.exists()) {
|
||||
return null
|
||||
}
|
||||
|
||||
// Use FileProvider to get a content Uri for the file
|
||||
return FileProvider.getUriForFile(
|
||||
context,
|
||||
"${context.packageName}.fileprovider",
|
||||
logFile
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
override fun uncaughtException(thread: Thread, exception: Throwable) {
|
||||
Log.e("CrashHandler", "Caught exception: ${exception.message}", exception)
|
||||
|
||||
// Step 1: Save custom crash log
|
||||
saveCrashLog(exception)
|
||||
|
||||
// Step 2: Start CrashReportActivity with the crash details
|
||||
val intent = Intent(context, CrashReportActivity::class.java).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||
}
|
||||
context.startActivity(intent)
|
||||
|
||||
// Kill the process
|
||||
android.os.Process.killProcess(android.os.Process.myPid())
|
||||
exitProcess(1)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
private fun saveCrashLog(exception: Throwable): File {
|
||||
val logFile: File = try {
|
||||
val packageManager = context.packageManager
|
||||
val packageInfo: PackageInfo = packageManager.getPackageInfo(context.packageName, 0)
|
||||
|
||||
// Use internal storage for saving the crash log
|
||||
val crashDir = File(context.filesDir, "crash_logs") // This is internal storage
|
||||
if (!crashDir.exists()) crashDir.mkdirs()
|
||||
|
||||
File(crashDir, "${packageInfo.packageName}-crash-report.txt")
|
||||
} catch (e: Exception) {
|
||||
Log.e("CrashHandler", "Error determining crash log file location: ${e.message}")
|
||||
// In case of error, use a default file name
|
||||
File(context.filesDir, "default-crash-report.txt")
|
||||
}
|
||||
|
||||
try {
|
||||
FileWriter(logFile).use { writer ->
|
||||
PrintWriter(writer).use { printWriter ->
|
||||
printWriter.println("Crash Report - ${Date()}")
|
||||
printWriter.println("Thread: ${Thread.currentThread().name}")
|
||||
printWriter.println("\n=== Device Info ===")
|
||||
printWriter.println(getDeviceInfo())
|
||||
printWriter.println("\n=== Recent User Actions ===")
|
||||
userActions.forEach { printWriter.println(it) }
|
||||
printWriter.println("\n=== Crash Stack Trace ===")
|
||||
exception.printStackTrace(printWriter)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("CrashHandler", "Error writing crash log: ${e.message}")
|
||||
}
|
||||
return logFile
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
private fun getDeviceInfo(): String {
|
||||
return try {
|
||||
val packageManager = context.packageManager
|
||||
val packageInfo: PackageInfo = packageManager.getPackageInfo(context.packageName, 0)
|
||||
val installSource = getInstallSource(packageManager, context.packageName)
|
||||
|
||||
"""
|
||||
App Version: ${packageInfo.versionName} (${packageInfo.longVersionCode})
|
||||
Installed From: $installSource
|
||||
Device: ${Build.MANUFACTURER} ${Build.MODEL}
|
||||
Android Version: ${Build.VERSION.RELEASE} (API ${Build.VERSION.SDK_INT})
|
||||
CPU: ${Build.SUPPORTED_ABIS.joinToString()}
|
||||
""".trimIndent()
|
||||
} catch (e: Exception) {
|
||||
"Device Info Unavailable: ${e.message}"
|
||||
}
|
||||
}
|
||||
|
||||
private fun getInstallSource(packageManager: PackageManager, packageName: String): String {
|
||||
return try {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
packageManager.getInstallSourceInfo(packageName).installingPackageName ?: "Unknown"
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
packageManager.getInstallerPackageName(packageName) ?: "Unknown"
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
"Unknown"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.github.gezimos.common
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
|
||||
fun Fragment.showLongToast(message: String) {
|
||||
Toast.makeText(requireContext(), message, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
fun Fragment.showShortToast(message: String) {
|
||||
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
@SuppressLint("ServiceCast")
|
||||
fun Fragment.hideKeyboard() {
|
||||
val inputMethodManager =
|
||||
requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
val view = activity?.currentFocus ?: View(requireContext()) // Use current focus or a new view
|
||||
if (inputMethodManager.isActive) { // Check if IME is active before hiding
|
||||
inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.github.gezimos.common
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
|
||||
|
||||
fun View.showKeyboard() {
|
||||
if (this.requestFocus()) {
|
||||
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
@Suppress("DEPRECATION")
|
||||
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY)
|
||||
}
|
||||
}
|
||||
|
||||
fun View.hideKeyboard() {
|
||||
val imm: InputMethodManager? =
|
||||
context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?
|
||||
imm?.hideSoftInputFromWindow(windowToken, 0)
|
||||
this.clearFocus()
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.github.gezimos.inkos
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.github.gezimos.common.CrashHandler
|
||||
import com.github.gezimos.inkos.helper.utils.SimpleEmailSender
|
||||
|
||||
class CrashReportActivity : AppCompatActivity() {
|
||||
private var pkgName: String = ""
|
||||
private var pkgVersion: String = ""
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
pkgName = getString(R.string.app_name)
|
||||
pkgVersion = this.packageManager.getPackageInfo(
|
||||
this.packageName,
|
||||
0
|
||||
).versionName.toString()
|
||||
|
||||
// Show a dialog to ask if the user wants to report the crash
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(getString(R.string.acra_crash))
|
||||
.setMessage(getString(R.string.acra_dialog_text).format(pkgName))
|
||||
.setPositiveButton(getString(R.string.acra_send_report)) { _, _ ->
|
||||
sendCrashReport(this)
|
||||
}
|
||||
.setNegativeButton(getString(R.string.acra_dont_send)) { _, _ ->
|
||||
restartApp()
|
||||
}
|
||||
.setCancelable(false)
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun sendCrashReport(context: Context) {
|
||||
val crashFileUri: Uri? = CrashHandler.customReportSender(applicationContext)
|
||||
val crashFileUris: List<Uri> = crashFileUri?.let { listOf(it) } ?: emptyList()
|
||||
|
||||
val emailSender = SimpleEmailSender() // Create an instance
|
||||
val crashReportContent = getString(R.string.acra_mail_body)
|
||||
val subject = String.format("Crash Report %s - %s", pkgName, pkgVersion)
|
||||
val recipient = getString(R.string.acra_email) // Replace with your email
|
||||
|
||||
emailSender.sendCrashReport(context, crashReportContent, crashFileUris, subject, recipient)
|
||||
}
|
||||
|
||||
|
||||
private fun restartApp() {
|
||||
val intent = Intent(this, MainActivity::class.java).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
startActivity(intent)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.github.gezimos.inkos
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
||||
class FakeHomeActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_fake_home)
|
||||
}
|
||||
}
|
||||
349
app/src/main/java/com/github/gezimos/inkos/MainActivity.kt
Normal file
349
app/src/main/java/com/github/gezimos/inkos/MainActivity.kt
Normal file
@@ -0,0 +1,349 @@
|
||||
package com.github.gezimos.inkos
|
||||
|
||||
// import android.content.pm.PackageManager
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.content.res.Configuration
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.view.KeyEvent
|
||||
import android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.findNavController
|
||||
import com.github.gezimos.common.CrashHandler
|
||||
import com.github.gezimos.inkos.data.Constants
|
||||
import com.github.gezimos.inkos.data.Migration
|
||||
import com.github.gezimos.inkos.data.Prefs
|
||||
import com.github.gezimos.inkos.databinding.ActivityMainBinding
|
||||
import com.github.gezimos.inkos.helper.isTablet
|
||||
import com.github.gezimos.inkos.helper.isinkosDefault
|
||||
import com.github.gezimos.inkos.ui.dialogs.DialogManager
|
||||
import java.io.BufferedReader
|
||||
import java.io.FileOutputStream
|
||||
import java.io.InputStreamReader
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
|
||||
private lateinit var prefs: Prefs
|
||||
private lateinit var migration: Migration
|
||||
private lateinit var navController: NavController
|
||||
private lateinit var viewModel: MainViewModel
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
private var isOnboarding = false
|
||||
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun onBackPressed() {
|
||||
if (isOnboarding) {
|
||||
// Block back during onboarding
|
||||
return
|
||||
}
|
||||
@Suppress("DEPRECATION")
|
||||
if (navController.currentDestination?.id != R.id.mainFragment)
|
||||
super.onBackPressed()
|
||||
}
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
if (isOnboarding) {
|
||||
// Block all key events during onboarding
|
||||
return true
|
||||
}
|
||||
return when (keyCode) {
|
||||
KeyEvent.KEYCODE_MENU -> {
|
||||
when (navController.currentDestination?.id) {
|
||||
R.id.mainFragment -> {
|
||||
this.findNavController(R.id.nav_host_fragment)
|
||||
.navigate(R.id.action_mainFragment_to_appListFragment)
|
||||
true
|
||||
}
|
||||
|
||||
else -> {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
KeyEvent.KEYCODE_A, KeyEvent.KEYCODE_B, KeyEvent.KEYCODE_C, KeyEvent.KEYCODE_D,
|
||||
KeyEvent.KEYCODE_E, KeyEvent.KEYCODE_F, KeyEvent.KEYCODE_G, KeyEvent.KEYCODE_H,
|
||||
KeyEvent.KEYCODE_I, KeyEvent.KEYCODE_J, KeyEvent.KEYCODE_K, KeyEvent.KEYCODE_L,
|
||||
KeyEvent.KEYCODE_M, KeyEvent.KEYCODE_N, KeyEvent.KEYCODE_O, KeyEvent.KEYCODE_P,
|
||||
KeyEvent.KEYCODE_Q, KeyEvent.KEYCODE_R, KeyEvent.KEYCODE_S, KeyEvent.KEYCODE_T,
|
||||
KeyEvent.KEYCODE_U, KeyEvent.KEYCODE_V, KeyEvent.KEYCODE_W, KeyEvent.KEYCODE_X,
|
||||
KeyEvent.KEYCODE_Y, KeyEvent.KEYCODE_Z -> {
|
||||
when (navController.currentDestination?.id) {
|
||||
R.id.mainFragment -> {
|
||||
val bundle = Bundle()
|
||||
bundle.putInt("letterKeyCode", keyCode) // Pass the letter key code
|
||||
this.findNavController(R.id.nav_host_fragment)
|
||||
.navigate(R.id.action_mainFragment_to_appListFragment, bundle)
|
||||
true
|
||||
}
|
||||
|
||||
else -> {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
KeyEvent.KEYCODE_ESCAPE -> {
|
||||
backToHomeScreen()
|
||||
true
|
||||
}
|
||||
|
||||
KeyEvent.KEYCODE_HOME -> {
|
||||
// Only send signal and navigate home, do not use shouldResetHomePage
|
||||
com.github.gezimos.inkos.ui.HomeFragment.sendGoToFirstPageSignal()
|
||||
backToHomeScreen()
|
||||
true
|
||||
}
|
||||
|
||||
KeyEvent.KEYCODE_VOLUME_UP, KeyEvent.KEYCODE_VOLUME_DOWN -> {
|
||||
// Handle volume keys for page navigation if enabled and on home
|
||||
if (navController.currentDestination?.id == R.id.mainFragment && prefs.useVolumeKeysForPages) {
|
||||
val fragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment)
|
||||
val homeFragment =
|
||||
fragment?.childFragmentManager?.fragments?.find { it is com.github.gezimos.inkos.ui.HomeFragment } as? com.github.gezimos.inkos.ui.HomeFragment
|
||||
if (homeFragment != null && com.github.gezimos.inkos.ui.HomeFragment.isHomeVisible) {
|
||||
if (homeFragment.handleVolumeKeyNavigation(keyCode)) return true
|
||||
}
|
||||
}
|
||||
return super.onKeyDown(keyCode, event)
|
||||
}
|
||||
|
||||
else -> {
|
||||
super.onKeyDown(keyCode, event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
if (isOnboarding) {
|
||||
// Ignore new intents during onboarding to prevent navController crash
|
||||
return
|
||||
}
|
||||
super.onNewIntent(intent)
|
||||
if (intent.action == Intent.ACTION_MAIN) {
|
||||
// Only bring home to front, do not reset page
|
||||
backToHomeScreen()
|
||||
}
|
||||
}
|
||||
|
||||
private fun backToHomeScreen() {
|
||||
if (!::navController.isInitialized) return // Prevent crash if navController not ready
|
||||
// Pop all fragments and return to home
|
||||
navController.popBackStack(R.id.mainFragment, false)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
prefs = Prefs(this)
|
||||
migration = Migration(this)
|
||||
|
||||
// Initialize com.github.gezimos.common.CrashHandler to catch uncaught exceptions
|
||||
Thread.setDefaultUncaughtExceptionHandler(CrashHandler(applicationContext))
|
||||
|
||||
if (prefs.firstOpen) {
|
||||
isOnboarding = true
|
||||
// Show onboarding screen using ComposeView
|
||||
val composeView = androidx.compose.ui.platform.ComposeView(this)
|
||||
setContentView(composeView)
|
||||
composeView.setContent {
|
||||
com.github.gezimos.inkos.ui.compose.OnboardingScreen.Show(
|
||||
onFinish = {
|
||||
prefs.firstOpen = false
|
||||
isOnboarding = false
|
||||
recreate() // Restart activity to show main UI
|
||||
},
|
||||
onRequestNotificationPermission = {
|
||||
if (Build.VERSION.SDK_INT >= 33) {
|
||||
if (checkSelfPermission(android.Manifest.permission.POST_NOTIFICATIONS) != android.content.pm.PackageManager.PERMISSION_GRANTED) {
|
||||
requestPermissions(
|
||||
arrayOf(android.Manifest.permission.POST_NOTIFICATIONS),
|
||||
1001
|
||||
)
|
||||
}
|
||||
} else {
|
||||
val areEnabled =
|
||||
NotificationManagerCompat.from(this).areNotificationsEnabled()
|
||||
if (!areEnabled) {
|
||||
val intent =
|
||||
Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS).apply {
|
||||
putExtra(Settings.EXTRA_APP_PACKAGE, packageName)
|
||||
}
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
val themeMode = when (prefs.appTheme) {
|
||||
Constants.Theme.Light -> AppCompatDelegate.MODE_NIGHT_NO
|
||||
Constants.Theme.Dark -> AppCompatDelegate.MODE_NIGHT_YES
|
||||
Constants.Theme.System -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
}
|
||||
AppCompatDelegate.setDefaultNightMode(themeMode)
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
val view = binding.root
|
||||
setContentView(view)
|
||||
migration.migratePreferencesOnVersionUpdate(prefs)
|
||||
|
||||
// Set window background color dynamically from prefs
|
||||
window.setBackgroundDrawable(android.graphics.drawable.ColorDrawable(prefs.backgroundColor))
|
||||
|
||||
navController = this.findNavController(R.id.nav_host_fragment)
|
||||
viewModel = ViewModelProvider(this)[MainViewModel::class.java]
|
||||
// Remove firstOpen logic here, handled above
|
||||
viewModel.getAppList(includeHiddenApps = true)
|
||||
setupOrientation()
|
||||
|
||||
window.addFlags(FLAG_LAYOUT_NO_LIMITS)
|
||||
|
||||
// Request notification access if not granted
|
||||
if (!isNotificationServiceEnabled()) {
|
||||
val intent = Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
// Add bottom padding if navigation bar/gestures are present
|
||||
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { v, insets ->
|
||||
val navBarInset = insets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom
|
||||
v.setPadding(
|
||||
v.paddingLeft,
|
||||
v.paddingTop,
|
||||
v.paddingRight,
|
||||
navBarInset
|
||||
)
|
||||
insets
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
// Post a delayed hide to ensure it runs after window focus changes
|
||||
window.decorView.postDelayed({
|
||||
// Request focus on decorView to steal it from any EditText
|
||||
window.decorView.requestFocus()
|
||||
val imm =
|
||||
getSystemService(INPUT_METHOD_SERVICE) as? android.view.inputmethod.InputMethodManager
|
||||
imm?.hideSoftInputFromWindow(window.decorView.windowToken, 0)
|
||||
currentFocus?.let { view ->
|
||||
imm?.hideSoftInputFromWindow(view.windowToken, 0)
|
||||
}
|
||||
}, 100)
|
||||
}
|
||||
|
||||
private fun isNotificationServiceEnabled(): Boolean {
|
||||
return NotificationManagerCompat.getEnabledListenerPackages(this)
|
||||
.contains(packageName)
|
||||
}
|
||||
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
when (requestCode) {
|
||||
|
||||
Constants.REQUEST_SET_DEFAULT_HOME -> {
|
||||
val isDefault = isinkosDefault(this) // Check again if the app is now default
|
||||
|
||||
if (isDefault) {
|
||||
viewModel.setDefaultLauncher(false)
|
||||
} else {
|
||||
viewModel.setDefaultLauncher(true)
|
||||
}
|
||||
}
|
||||
|
||||
Constants.BACKUP_READ -> {
|
||||
data?.data?.also { uri ->
|
||||
// Try to get file name from content resolver if lastPathSegment is not reliable
|
||||
val fileName = uri.lastPathSegment ?: ""
|
||||
val isJsonExtension = fileName.endsWith(".json", ignoreCase = true) ||
|
||||
applicationContext.contentResolver.getType(uri)?.contains("json") == true
|
||||
if (!isJsonExtension) {
|
||||
DialogManager(this, this).showErrorDialog(
|
||||
this,
|
||||
getString(R.string.error_invalid_file_title),
|
||||
getString(R.string.error_invalid_file_message)
|
||||
)
|
||||
return
|
||||
}
|
||||
applicationContext.contentResolver.openInputStream(uri).use { inputStream ->
|
||||
val stringBuilder = StringBuilder()
|
||||
BufferedReader(InputStreamReader(inputStream)).use { reader ->
|
||||
var line: String? = reader.readLine()
|
||||
while (line != null) {
|
||||
stringBuilder.append(line)
|
||||
line = reader.readLine()
|
||||
}
|
||||
}
|
||||
val string = stringBuilder.toString()
|
||||
// Try to parse as JSON
|
||||
try {
|
||||
org.json.JSONObject(string) // Throws if not valid JSON
|
||||
} catch (e: Exception) {
|
||||
DialogManager(this, this).showErrorDialog(
|
||||
this,
|
||||
getString(R.string.error_invalid_file_title),
|
||||
getString(R.string.error_invalid_file_message)
|
||||
)
|
||||
return
|
||||
}
|
||||
val prefs = Prefs(applicationContext)
|
||||
prefs.clear()
|
||||
prefs.loadFromString(string)
|
||||
}
|
||||
}
|
||||
startActivity(Intent.makeRestartActivityTask(this.intent?.component))
|
||||
}
|
||||
|
||||
Constants.BACKUP_WRITE -> {
|
||||
data?.data?.also { uri ->
|
||||
applicationContext.contentResolver.openFileDescriptor(uri, "w")?.use { file ->
|
||||
FileOutputStream(file.fileDescriptor).use { stream ->
|
||||
val prefs = Prefs(applicationContext).saveToString()
|
||||
stream.channel.truncate(0)
|
||||
stream.write(prefs.toByteArray())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
recreate()
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("SourceLockedOrientationActivity")
|
||||
private fun setupOrientation() {
|
||||
if (isTablet(this)) return
|
||||
// In Android 8.0, windowIsTranslucent cannot be used with screenOrientation=portrait
|
||||
if (Build.VERSION.SDK_INT != Build.VERSION_CODES.O)
|
||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||
}
|
||||
|
||||
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||
super.onWindowFocusChanged(hasFocus)
|
||||
// Forward window focus changes to HomeFragment
|
||||
if (hasFocus) {
|
||||
val fragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment)
|
||||
val homeFragment = fragment?.childFragmentManager?.fragments?.find { it is com.github.gezimos.inkos.ui.HomeFragment } as? com.github.gezimos.inkos.ui.HomeFragment
|
||||
if (homeFragment != null && com.github.gezimos.inkos.ui.HomeFragment.isHomeVisible) {
|
||||
homeFragment.onWindowFocusGained()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
391
app/src/main/java/com/github/gezimos/inkos/MainViewModel.kt
Normal file
391
app/src/main/java/com/github/gezimos/inkos/MainViewModel.kt
Normal file
@@ -0,0 +1,391 @@
|
||||
package com.github.gezimos.inkos
|
||||
|
||||
import android.app.Application
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.content.pm.LauncherApps
|
||||
import android.os.Process
|
||||
import android.os.UserHandle
|
||||
import android.util.Log
|
||||
import androidx.biometric.BiometricPrompt
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.navigation.fragment.NavHostFragment.Companion.findNavController
|
||||
import com.github.gezimos.common.CrashHandler
|
||||
import com.github.gezimos.common.hideKeyboard
|
||||
import com.github.gezimos.common.showShortToast
|
||||
import com.github.gezimos.inkos.data.AppListItem
|
||||
import com.github.gezimos.inkos.data.Constants.AppDrawerFlag
|
||||
import com.github.gezimos.inkos.data.HomeAppUiState
|
||||
import com.github.gezimos.inkos.data.Prefs
|
||||
import com.github.gezimos.inkos.helper.getAppsList
|
||||
import com.github.gezimos.inkos.helper.isinkosDefault
|
||||
import com.github.gezimos.inkos.helper.setDefaultHomeScreen
|
||||
import com.github.gezimos.inkos.helper.utils.BiometricHelper
|
||||
import com.github.gezimos.inkos.services.NotificationManager
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
private lateinit var biometricHelper: BiometricHelper
|
||||
|
||||
private val appContext by lazy { application.applicationContext }
|
||||
private val prefs = Prefs(appContext)
|
||||
|
||||
// setup variables with initial values
|
||||
val firstOpen = MutableLiveData<Boolean>()
|
||||
|
||||
val appList = MutableLiveData<List<AppListItem>?>()
|
||||
val hiddenApps = MutableLiveData<List<AppListItem>?>()
|
||||
val homeAppsOrder = MutableLiveData<List<AppListItem>>() // Store actual app items
|
||||
val launcherDefault = MutableLiveData<Boolean>()
|
||||
|
||||
val showClock = MutableLiveData(prefs.showClock)
|
||||
val homeAppsNum = MutableLiveData(prefs.homeAppsNum)
|
||||
val homePagesNum = MutableLiveData(prefs.homePagesNum)
|
||||
|
||||
val appTheme = MutableLiveData(prefs.appTheme)
|
||||
val appColor = MutableLiveData(prefs.appColor)
|
||||
val backgroundColor = MutableLiveData(prefs.backgroundColor)
|
||||
val clockColor = MutableLiveData(prefs.clockColor)
|
||||
val batteryColor = MutableLiveData(prefs.batteryColor)
|
||||
val appsFont = MutableLiveData(prefs.appsFont)
|
||||
val clockFont = MutableLiveData(prefs.clockFont)
|
||||
val batteryFont = MutableLiveData(prefs.batteryFont)
|
||||
val notificationsFont = MutableLiveData(prefs.notificationsFont)
|
||||
val notificationFont = MutableLiveData(prefs.labelnotificationsFont)
|
||||
val statusFont = MutableLiveData(prefs.statusFont)
|
||||
val lettersFont = MutableLiveData(prefs.lettersFont)
|
||||
val lettersTitleFont = MutableLiveData(prefs.lettersTitleFont)
|
||||
val textPaddingSize = MutableLiveData(prefs.textPaddingSize)
|
||||
val appSize = MutableLiveData(prefs.appSize)
|
||||
val clockSize = MutableLiveData(prefs.clockSize)
|
||||
val batterySize = MutableLiveData(prefs.batterySize)
|
||||
|
||||
// --- Home screen UI state ---
|
||||
private val _homeAppsUiState = MutableLiveData<List<HomeAppUiState>>()
|
||||
val homeAppsUiState: LiveData<List<HomeAppUiState>> = _homeAppsUiState
|
||||
|
||||
fun updateMediaPlaybackInfo(info: NotificationManager.NotificationInfo?) {
|
||||
// _mediaPlaybackInfo.postValue(info)
|
||||
}
|
||||
|
||||
// Listen for preference changes and update LiveData
|
||||
private val prefsListener = SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
|
||||
when (key) {
|
||||
"APP_THEME" -> appTheme.postValue(prefs.appTheme)
|
||||
"APP_COLOR" -> appColor.postValue(prefs.appColor)
|
||||
"BACKGROUND_COLOR" -> backgroundColor.postValue(prefs.backgroundColor)
|
||||
"CLOCK_COLOR" -> clockColor.postValue(prefs.clockColor)
|
||||
"BATTERY_COLOR" -> batteryColor.postValue(prefs.batteryColor)
|
||||
"APPS_FONT" -> appsFont.postValue(prefs.appsFont)
|
||||
"CLOCK_FONT" -> clockFont.postValue(prefs.clockFont)
|
||||
"BATTERY_FONT" -> batteryFont.postValue(prefs.batteryFont)
|
||||
"NOTIFICATIONS_FONT" -> notificationsFont.postValue(prefs.notificationsFont)
|
||||
"NOTIFICATION_FONT" -> notificationFont.postValue(prefs.labelnotificationsFont)
|
||||
"STATUS_FONT" -> statusFont.postValue(prefs.statusFont)
|
||||
"LETTERS_FONT" -> lettersFont.postValue(prefs.lettersFont)
|
||||
"LETTERS_TITLE_FONT" -> lettersTitleFont.postValue(prefs.lettersTitleFont)
|
||||
"TEXT_PADDING_SIZE" -> textPaddingSize.postValue(prefs.textPaddingSize)
|
||||
"APP_SIZE_TEXT" -> appSize.postValue(prefs.appSize)
|
||||
"CLOCK_SIZE_TEXT" -> clockSize.postValue(prefs.clockSize)
|
||||
"BATTERY_SIZE_TEXT" -> batterySize.postValue(prefs.batterySize)
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
prefs.sharedPrefs.registerOnSharedPreferenceChangeListener(prefsListener)
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
prefs.sharedPrefs.unregisterOnSharedPreferenceChangeListener(prefsListener)
|
||||
super.onCleared()
|
||||
}
|
||||
|
||||
// Call this to refresh home app UI state (labels, fonts, colors, badges)
|
||||
fun refreshHomeAppsUiState(context: Context) {
|
||||
val notifications =
|
||||
NotificationManager.getInstance(context).notificationInfoLiveData.value ?: emptyMap()
|
||||
val appColor = prefs.appColor
|
||||
val appFont = prefs.getFontForContext("apps")
|
||||
.getFont(context, prefs.getCustomFontPathForContext("apps"))
|
||||
val homeApps = (0 until prefs.homeAppsNum).map { i ->
|
||||
val appModel = prefs.getHomeAppModel(i)
|
||||
val customLabel = prefs.getAppAlias("app_alias_${appModel.activityPackage}")
|
||||
val label = if (customLabel.isNotEmpty()) customLabel else appModel.activityLabel
|
||||
val notificationInfo = notifications[appModel.activityPackage]
|
||||
HomeAppUiState(
|
||||
id = i,
|
||||
label = label,
|
||||
font = appFont,
|
||||
color = appColor,
|
||||
notificationInfo = notificationInfo,
|
||||
activityPackage = appModel.activityPackage // Pass unique identifier
|
||||
)
|
||||
}
|
||||
_homeAppsUiState.postValue(homeApps)
|
||||
}
|
||||
|
||||
fun selectedApp(fragment: Fragment, app: AppListItem, flag: AppDrawerFlag, n: Int = 0) {
|
||||
when (flag) {
|
||||
AppDrawerFlag.LaunchApp,
|
||||
AppDrawerFlag.HiddenApps,
|
||||
AppDrawerFlag.PrivateApps -> {
|
||||
launchApp(app, fragment)
|
||||
}
|
||||
|
||||
AppDrawerFlag.SetHomeApp -> {
|
||||
prefs.setHomeAppModel(n, app)
|
||||
findNavController(fragment).popBackStack()
|
||||
}
|
||||
|
||||
AppDrawerFlag.SetSwipeLeft -> prefs.appSwipeLeft = app
|
||||
AppDrawerFlag.SetSwipeRight -> prefs.appSwipeRight = app
|
||||
AppDrawerFlag.SetDoubleTap -> prefs.appDoubleTap = app
|
||||
AppDrawerFlag.SetClickClock -> { /* no-op or implement if needed */
|
||||
}
|
||||
|
||||
AppDrawerFlag.SetSwipeUp, AppDrawerFlag.SetSwipeDown -> { /* no-op, removed */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun firstOpen(value: Boolean) {
|
||||
firstOpen.postValue(value)
|
||||
}
|
||||
|
||||
|
||||
fun setShowClock(visibility: Boolean) {
|
||||
showClock.value = visibility
|
||||
}
|
||||
|
||||
fun setDefaultLauncher(visibility: Boolean) {
|
||||
launcherDefault.value = visibility
|
||||
}
|
||||
|
||||
fun launchApp(appListItem: AppListItem, fragment: Fragment) {
|
||||
biometricHelper = BiometricHelper(fragment)
|
||||
|
||||
val packageName = appListItem.activityPackage
|
||||
val currentLockedApps = prefs.lockedApps
|
||||
|
||||
if (currentLockedApps.contains(packageName)) {
|
||||
fragment.hideKeyboard()
|
||||
biometricHelper.startBiometricAuth(appListItem, object : BiometricHelper.CallbackApp {
|
||||
override fun onAuthenticationSucceeded(appListItem: AppListItem) {
|
||||
launchUnlockedApp(appListItem)
|
||||
}
|
||||
|
||||
override fun onAuthenticationFailed() {
|
||||
Log.e(
|
||||
"Authentication",
|
||||
appContext.getString(R.string.text_authentication_failed)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onAuthenticationError(errorCode: Int, errorMessage: CharSequence?) {
|
||||
when (errorCode) {
|
||||
BiometricPrompt.ERROR_USER_CANCELED -> Log.e(
|
||||
"Authentication",
|
||||
appContext.getString(R.string.text_authentication_cancel)
|
||||
)
|
||||
|
||||
else -> Log.e(
|
||||
"Authentication",
|
||||
appContext.getString(R.string.text_authentication_error).format(
|
||||
errorMessage,
|
||||
errorCode
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
launchUnlockedApp(appListItem)
|
||||
}
|
||||
}
|
||||
|
||||
private fun launchUnlockedApp(appListItem: AppListItem) {
|
||||
val packageName = appListItem.activityPackage
|
||||
val userHandle = appListItem.user
|
||||
val launcher = appContext.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
|
||||
val activityInfo = launcher.getActivityList(packageName, userHandle)
|
||||
|
||||
if (activityInfo.isNotEmpty()) {
|
||||
val component = ComponentName(packageName, activityInfo.first().name)
|
||||
launchAppWithPermissionCheck(component, packageName, userHandle, launcher)
|
||||
} else {
|
||||
appContext.showShortToast("App not found")
|
||||
}
|
||||
}
|
||||
|
||||
private fun launchAppWithPermissionCheck(
|
||||
component: ComponentName,
|
||||
packageName: String,
|
||||
userHandle: UserHandle,
|
||||
launcher: LauncherApps
|
||||
) {
|
||||
try {
|
||||
launcher.startMainActivity(component, userHandle, null, null)
|
||||
CrashHandler.logUserAction("${component.packageName} App Launched")
|
||||
} catch (_: SecurityException) {
|
||||
try {
|
||||
launcher.startMainActivity(component, Process.myUserHandle(), null, null)
|
||||
CrashHandler.logUserAction("${component.packageName} App Launched")
|
||||
} catch (_: Exception) {
|
||||
appContext.showShortToast("Unable to launch app")
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
appContext.showShortToast("Unable to launch app")
|
||||
}
|
||||
}
|
||||
|
||||
fun getAppList(includeHiddenApps: Boolean = true) {
|
||||
viewModelScope.launch {
|
||||
val apps = getAppsList(
|
||||
appContext,
|
||||
includeRegularApps = true,
|
||||
includeHiddenApps = includeHiddenApps
|
||||
)
|
||||
// Load custom labels for each app
|
||||
apps.forEach { app ->
|
||||
val customLabel = prefs.getAppAlias("app_alias_${app.activityPackage}")
|
||||
if (customLabel.isNotEmpty()) {
|
||||
app.customLabel = customLabel
|
||||
}
|
||||
}
|
||||
|
||||
// Filter out hidden apps if not including them
|
||||
val filteredApps = if (!includeHiddenApps) {
|
||||
val hiddenApps = prefs.hiddenApps
|
||||
apps.filter { app ->
|
||||
!hiddenApps.contains("${app.activityPackage}|${app.user}")
|
||||
}
|
||||
} else {
|
||||
apps
|
||||
}
|
||||
|
||||
appList.value = filteredApps
|
||||
}
|
||||
}
|
||||
|
||||
fun getHiddenApps() {
|
||||
viewModelScope.launch {
|
||||
val hiddenSet = prefs.hiddenApps
|
||||
val hiddenAppsList = mutableListOf<AppListItem>()
|
||||
|
||||
// Get all installed apps
|
||||
val allApps =
|
||||
getAppsList(appContext, includeRegularApps = true, includeHiddenApps = true)
|
||||
|
||||
// For each hidden app package+user combination
|
||||
for (hiddenApp in hiddenSet) {
|
||||
try {
|
||||
// Split the stored string into package name and user handle
|
||||
val parts = hiddenApp.split("|")
|
||||
val packageName = parts[0]
|
||||
|
||||
// Find matching app
|
||||
val app = if (parts.size > 1) {
|
||||
allApps.find { app ->
|
||||
app.activityPackage == packageName &&
|
||||
app.user.toString() == parts[1]
|
||||
}
|
||||
} else {
|
||||
allApps.find { app ->
|
||||
app.activityPackage == packageName
|
||||
}
|
||||
}
|
||||
|
||||
// Load custom label if it exists
|
||||
app?.let {
|
||||
val customLabel = prefs.getAppAlias("app_alias_${it.activityPackage}")
|
||||
if (customLabel.isNotEmpty()) {
|
||||
it.customLabel = customLabel
|
||||
}
|
||||
hiddenAppsList.add(it)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("MainViewModel", "Error processing hidden app: $hiddenApp", e)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
hiddenApps.postValue(hiddenAppsList)
|
||||
}
|
||||
}
|
||||
|
||||
fun isinkosDefault() {
|
||||
val isDefault = isinkosDefault(appContext)
|
||||
launcherDefault.value = !isDefault
|
||||
}
|
||||
|
||||
fun resetDefaultLauncherApp(context: Context) {
|
||||
setDefaultHomeScreen(context)
|
||||
}
|
||||
|
||||
fun updateAppOrder(fromPosition: Int, toPosition: Int) {
|
||||
val currentOrder = homeAppsOrder.value?.toMutableList() ?: return
|
||||
|
||||
// Move the actual app object in the list
|
||||
val app = currentOrder.removeAt(fromPosition)
|
||||
currentOrder.add(toPosition, app)
|
||||
|
||||
homeAppsOrder.postValue(currentOrder)
|
||||
saveAppOrder(currentOrder) // Save new order in preferences
|
||||
}
|
||||
|
||||
private fun saveAppOrder(order: List<AppListItem>) {
|
||||
order.forEachIndexed { index, app ->
|
||||
prefs.setHomeAppModel(index, app) // Save app in its new order
|
||||
}
|
||||
}
|
||||
|
||||
fun loadAppOrder() {
|
||||
val savedOrder = (0 until prefs.homeAppsNum)
|
||||
.mapNotNull { i ->
|
||||
prefs.getHomeAppModel(i).let { app ->
|
||||
// Check for custom label
|
||||
val customLabel = prefs.getAppAlias("app_alias_${app.activityPackage}")
|
||||
if (customLabel.isNotEmpty()) {
|
||||
app.customLabel = customLabel
|
||||
}
|
||||
app
|
||||
}
|
||||
}
|
||||
homeAppsOrder.postValue(savedOrder)
|
||||
}
|
||||
|
||||
// --- App Drawer actions ---
|
||||
fun refreshAppListAfterUninstall(includeHiddenApps: Boolean = false) {
|
||||
getAppList(includeHiddenApps)
|
||||
}
|
||||
|
||||
fun renameApp(packageName: String, newName: String) {
|
||||
if (newName.isEmpty()) {
|
||||
prefs.removeAppAlias(packageName)
|
||||
} else {
|
||||
prefs.setAppAlias(packageName, newName)
|
||||
}
|
||||
// Refresh app list to update labels
|
||||
getAppList(includeHiddenApps = false)
|
||||
getHiddenApps()
|
||||
}
|
||||
|
||||
fun hideOrShowApp(flag: AppDrawerFlag, appModel: AppListItem) {
|
||||
val newSet = mutableSetOf<String>()
|
||||
newSet.addAll(prefs.hiddenApps)
|
||||
if (flag == AppDrawerFlag.HiddenApps) {
|
||||
newSet.remove(appModel.activityPackage)
|
||||
newSet.remove(appModel.activityPackage + "|" + appModel.user.toString())
|
||||
} else {
|
||||
newSet.add(appModel.activityPackage + "|" + appModel.user.toString())
|
||||
}
|
||||
prefs.hiddenApps = newSet
|
||||
getAppList(includeHiddenApps = (flag == AppDrawerFlag.HiddenApps))
|
||||
getHiddenApps()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.github.gezimos.inkos.data
|
||||
|
||||
import android.os.UserHandle
|
||||
import java.text.Collator
|
||||
|
||||
val collator: Collator = Collator.getInstance()
|
||||
|
||||
/**
|
||||
* We create instances in 3 different places:
|
||||
* 1. app drawer
|
||||
* 2. recent apps
|
||||
* 3. home screen (for the list and for swipes/taps)
|
||||
*
|
||||
* @property activityLabel
|
||||
* label of the activity (`LauncherActivityInfo.label`)
|
||||
*
|
||||
* @property activityPackage
|
||||
* Package name of the activity (`LauncherActivityInfo.applicationInfo.packageName`)
|
||||
*
|
||||
* @property activityClass
|
||||
* (`LauncherActivityInfo.componentName.className`)
|
||||
*
|
||||
* @property user
|
||||
* userHandle is needed to resolve and start an activity.
|
||||
* And also we mark with a special icon the apps which belong to a managed user.
|
||||
*
|
||||
* @property customLabel
|
||||
* When user renames an app, we store the rename in Preferences.
|
||||
*
|
||||
* @property label
|
||||
* Use this property to render the list item.
|
||||
* It's either the original activity label (`activityLabel`) or a user-defined label (`definedLabel`).
|
||||
*/
|
||||
|
||||
data class AppListItem(
|
||||
val activityLabel: String,
|
||||
val activityPackage: String,
|
||||
val activityClass: String,
|
||||
val user: UserHandle,
|
||||
var customLabel: String, // TODO make immutable by refining data flow
|
||||
) : Comparable<AppListItem> {
|
||||
val label = customLabel.ifEmpty { activityLabel }
|
||||
|
||||
/** Speed up sort and search */
|
||||
private val collationKey = collator.getCollationKey(label)
|
||||
|
||||
override fun compareTo(other: AppListItem): Int =
|
||||
collationKey.compareTo(other.collationKey)
|
||||
}
|
||||
231
app/src/main/java/com/github/gezimos/inkos/data/Constants.kt
Normal file
231
app/src/main/java/com/github/gezimos/inkos/data/Constants.kt
Normal file
@@ -0,0 +1,231 @@
|
||||
package com.github.gezimos.inkos.data
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Typeface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import com.github.gezimos.inkos.R
|
||||
import com.github.gezimos.inkos.helper.getTrueSystemFont
|
||||
|
||||
interface EnumOption {
|
||||
@Composable
|
||||
fun string(): String
|
||||
}
|
||||
|
||||
|
||||
object Constants {
|
||||
|
||||
const val REQUEST_SET_DEFAULT_HOME = 777
|
||||
|
||||
const val TRIPLE_TAP_DELAY_MS = 300
|
||||
const val LONG_PRESS_DELAY_MS = 500
|
||||
|
||||
const val MIN_HOME_APPS = 0
|
||||
const val MAX_HOME_APPS = 30
|
||||
|
||||
const val MIN_HOME_PAGES = 1
|
||||
|
||||
// These are for the App Text Size (home screen app labels)
|
||||
const val MIN_APP_SIZE = 10
|
||||
const val MAX_APP_SIZE = 50
|
||||
|
||||
// Add for settings text size
|
||||
const val MIN_SETTINGS_TEXT_SIZE = 8
|
||||
const val MAX_SETTINGS_TEXT_SIZE = 27
|
||||
|
||||
// Add for notification text size
|
||||
const val MIN_LABEL_NOTIFICATION_TEXT_SIZE = 10
|
||||
const val MAX_LABEL_NOTIFICATION_TEXT_SIZE = 40
|
||||
|
||||
const val BACKUP_WRITE = 1
|
||||
const val BACKUP_READ = 2
|
||||
|
||||
const val THEME_BACKUP_WRITE = 11
|
||||
const val THEME_BACKUP_READ = 12
|
||||
|
||||
const val MIN_BATTERY_SIZE = 10
|
||||
const val MAX_BATTERY_SIZE = 40
|
||||
|
||||
const val MIN_TEXT_PADDING = 0
|
||||
const val MAX_TEXT_PADDING = 80
|
||||
|
||||
// Restore for clock_date_size (not gap)
|
||||
const val MIN_CLOCK_SIZE = 12
|
||||
const val MAX_CLOCK_SIZE = 80
|
||||
|
||||
// Update SWIPE_DISTANCE_THRESHOLD dynamically based on screen dimensions
|
||||
var SWIPE_DISTANCE_THRESHOLD = 0f
|
||||
|
||||
// Update MAX_HOME_PAGES dynamically based on MAX_HOME_APPS
|
||||
var MAX_HOME_PAGES = 10
|
||||
|
||||
fun updateMaxHomePages(context: Context) {
|
||||
val prefs = Prefs(context)
|
||||
|
||||
MAX_HOME_PAGES = if (prefs.homeAppsNum < MAX_HOME_PAGES) {
|
||||
prefs.homeAppsNum
|
||||
} else {
|
||||
MAX_HOME_PAGES
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
enum class BackupType {
|
||||
FullSystem,
|
||||
Theme
|
||||
}
|
||||
|
||||
enum class AppDrawerFlag {
|
||||
LaunchApp,
|
||||
HiddenApps,
|
||||
PrivateApps,
|
||||
SetHomeApp,
|
||||
SetSwipeUp,
|
||||
SetSwipeDown,
|
||||
SetSwipeLeft,
|
||||
SetSwipeRight,
|
||||
SetClickClock,
|
||||
SetDoubleTap,
|
||||
|
||||
}
|
||||
|
||||
enum class Action : EnumOption {
|
||||
OpenApp,
|
||||
TogglePrivateSpace,
|
||||
NextPage,
|
||||
PreviousPage,
|
||||
RestartApp,
|
||||
OpenNotificationsScreen,
|
||||
OpenNotificationsScreenAlt, // Renamed from OpenLettersScreen
|
||||
Disabled;
|
||||
|
||||
fun getString(context: Context): String {
|
||||
return when (this) {
|
||||
OpenApp -> context.getString(R.string.open_app)
|
||||
TogglePrivateSpace -> context.getString(R.string.private_space)
|
||||
NextPage -> context.getString(R.string.next_page)
|
||||
PreviousPage -> context.getString(R.string.previous_page)
|
||||
RestartApp -> context.getString(R.string.restart_launcher)
|
||||
OpenNotificationsScreen -> context.getString(R.string.notifications_screen_title)
|
||||
OpenNotificationsScreenAlt -> context.getString(R.string.notifications_screen_title) // Use same string for alt
|
||||
Disabled -> context.getString(R.string.disabled)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
override fun string(): String {
|
||||
return when (this) {
|
||||
OpenApp -> stringResource(R.string.open_app)
|
||||
TogglePrivateSpace -> stringResource(R.string.private_space)
|
||||
NextPage -> stringResource(R.string.next_page)
|
||||
PreviousPage -> stringResource(R.string.previous_page)
|
||||
RestartApp -> stringResource(R.string.restart_launcher)
|
||||
OpenNotificationsScreen -> stringResource(R.string.notifications_screen_title)
|
||||
OpenNotificationsScreenAlt -> stringResource(R.string.notifications_screen_title)
|
||||
Disabled -> stringResource(R.string.disabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class Theme : EnumOption {
|
||||
System,
|
||||
Dark,
|
||||
Light;
|
||||
|
||||
// Function to get a string from a context (for non-Composable use)
|
||||
fun getString(context: Context): String {
|
||||
return when (this) {
|
||||
System -> context.getString(R.string.system_default)
|
||||
Dark -> context.getString(R.string.dark)
|
||||
Light -> context.getString(R.string.light)
|
||||
}
|
||||
}
|
||||
|
||||
// Keep this for Composable usage
|
||||
@Composable
|
||||
override fun string(): String {
|
||||
return when (this) {
|
||||
System -> stringResource(R.string.system_default)
|
||||
Dark -> stringResource(R.string.dark)
|
||||
Light -> stringResource(R.string.light)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class FontFamily : EnumOption {
|
||||
System,
|
||||
Hoog,
|
||||
Merriweather,
|
||||
Osdmono,
|
||||
Manrope,
|
||||
Custom; // Add Custom for user-uploaded font
|
||||
|
||||
fun getFont(context: Context, customPath: String? = null): Typeface? {
|
||||
val prefs = Prefs(context)
|
||||
return when (this) {
|
||||
System -> getTrueSystemFont()
|
||||
Custom -> {
|
||||
val path = customPath ?: prefs.customFontPath
|
||||
if (!path.isNullOrBlank()) {
|
||||
val file = java.io.File(path)
|
||||
if (file.exists()) {
|
||||
try {
|
||||
Typeface.createFromFile(path)
|
||||
} catch (e: Exception) {
|
||||
getTrueSystemFont()
|
||||
}
|
||||
} else {
|
||||
getTrueSystemFont()
|
||||
}
|
||||
} else getTrueSystemFont()
|
||||
}
|
||||
|
||||
Hoog -> ResourcesCompat.getFont(context, R.font.hoog)
|
||||
Merriweather -> ResourcesCompat.getFont(context, R.font.merriweather)
|
||||
Osdmono -> ResourcesCompat.getFont(context, R.font.osdmono)
|
||||
Manrope -> ResourcesCompat.getFont(context, R.font.manropemedium)
|
||||
}
|
||||
}
|
||||
|
||||
fun getString(context: Context): String {
|
||||
return when (this) {
|
||||
System -> context.getString(R.string.system_default)
|
||||
Custom -> "Custom Font"
|
||||
Hoog -> context.getString(R.string.settings_font_hoog)
|
||||
Merriweather -> context.getString(R.string.settings_font_merriweather)
|
||||
Osdmono -> context.getString(R.string.settings_font_osdmono)
|
||||
Manrope -> "Manrope Medium"
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
// Helper to get all custom font display names and paths
|
||||
fun getAllCustomFonts(context: Context): List<Pair<String, String>> {
|
||||
val prefs = Prefs(context)
|
||||
return prefs.customFontPaths.map { path ->
|
||||
// Remove "Custom:" and limit to 24 chars
|
||||
path.substringAfterLast('/').take(24) to path
|
||||
}
|
||||
}
|
||||
|
||||
// Centralized: get the correct custom font path for each widget/context
|
||||
fun getCustomFontPathForWidget(context: Context, widget: String): String? {
|
||||
val prefs = Prefs(context)
|
||||
return prefs.getCustomFontPath(widget)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
override fun string(): String {
|
||||
return when (this) {
|
||||
System -> stringResource(R.string.system_default)
|
||||
Custom -> "Custom Font"
|
||||
Hoog -> stringResource(R.string.settings_font_hoog)
|
||||
Merriweather -> stringResource(R.string.settings_font_merriweather)
|
||||
Osdmono -> stringResource(R.string.settings_font_osdmono)
|
||||
Manrope -> "Manrope Medium"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.github.gezimos.inkos.data
|
||||
|
||||
import android.graphics.Typeface
|
||||
import androidx.annotation.ColorInt
|
||||
import com.github.gezimos.inkos.services.NotificationManager
|
||||
|
||||
/**
|
||||
* UI state for a home screen app button, including label, font, color, and notification badge info.
|
||||
*/
|
||||
data class HomeAppUiState(
|
||||
val id: Int, // position on home screen
|
||||
val label: String,
|
||||
val font: Typeface?,
|
||||
@ColorInt val color: Int,
|
||||
val notificationInfo: NotificationManager.NotificationInfo? = null,
|
||||
val activityPackage: String // Add unique identifier for the app
|
||||
)
|
||||
|
||||
49
app/src/main/java/com/github/gezimos/inkos/data/Migration.kt
Normal file
49
app/src/main/java/com/github/gezimos/inkos/data/Migration.kt
Normal file
@@ -0,0 +1,49 @@
|
||||
package com.github.gezimos.inkos.data
|
||||
|
||||
import android.content.Context
|
||||
import com.github.gezimos.inkos.BuildConfig
|
||||
|
||||
class Migration(val context: Context) {
|
||||
fun migratePreferencesOnVersionUpdate(prefs: Prefs) {
|
||||
val currentVersionCode = BuildConfig.VERSION_CODE
|
||||
val savedVersionCode = prefs.appVersion
|
||||
|
||||
// Define a map of version code -> preferences to clear
|
||||
val versionCleanupMap = mapOf(
|
||||
171 to listOf(
|
||||
"APP_DARK_COLORS",
|
||||
"APP_LIGHT_COLORS",
|
||||
"HOME_FOLLOW_ACCENT",
|
||||
"ALL_APPS_TEXT"
|
||||
),
|
||||
172 to listOf(
|
||||
"TIME_ALIGNMENT",
|
||||
"SHOW_TIME",
|
||||
"SHOW_TIME_FORMAT",
|
||||
"TIME_COLOR"
|
||||
),
|
||||
175 to listOf(
|
||||
"CLICK_APP_USAGE"
|
||||
),
|
||||
10803 to listOf(
|
||||
"SHOW_EDGE_PANEL",
|
||||
"EDGE_APPS_NUM"
|
||||
),
|
||||
// Add more versions and preferences to remove here
|
||||
)
|
||||
|
||||
// Iterate over the versions and clear the relevant preferences
|
||||
for ((version, keys) in versionCleanupMap) {
|
||||
// Only clear preferences for versions between savedVersionCode and currentVersionCode
|
||||
if (version in (savedVersionCode + 1)..currentVersionCode) {
|
||||
// Remove the preferences for this version
|
||||
keys.forEach { key ->
|
||||
prefs.remove(key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the stored version code after cleanup
|
||||
prefs.appVersion = currentVersionCode
|
||||
}
|
||||
}
|
||||
830
app/src/main/java/com/github/gezimos/inkos/data/Prefs.kt
Normal file
830
app/src/main/java/com/github/gezimos/inkos/data/Prefs.kt
Normal file
@@ -0,0 +1,830 @@
|
||||
package com.github.gezimos.inkos.data
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.os.UserHandle
|
||||
import android.util.Log
|
||||
import androidx.core.content.ContextCompat.getColor
|
||||
import androidx.core.content.edit
|
||||
import com.github.gezimos.inkos.R
|
||||
import com.github.gezimos.inkos.helper.getUserHandleFromString
|
||||
import com.github.gezimos.inkos.helper.isSystemInDarkMode
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
private const val PREFS_FILENAME = "com.github.gezimos.inkos"
|
||||
|
||||
private const val APP_VERSION = "APP_VERSION"
|
||||
private const val FIRST_OPEN = "FIRST_OPEN"
|
||||
private const val FIRST_SETTINGS_OPEN = "FIRST_SETTINGS_OPEN"
|
||||
private const val LOCK_MODE = "LOCK_MODE"
|
||||
private const val HOME_APPS_NUM = "HOME_APPS_NUM"
|
||||
private const val HOME_PAGES_NUM = "HOME_PAGES_NUM"
|
||||
private const val HOME_PAGES_PAGER = "HOME_PAGES_PAGER"
|
||||
private const val HOME_CLICK_AREA = "HOME_CLICK_AREA"
|
||||
private const val STATUS_BAR = "STATUS_BAR"
|
||||
private const val SHOW_BATTERY = "SHOW_BATTERY"
|
||||
private const val HOME_LOCKED = "HOME_LOCKED"
|
||||
private const val SETTINGS_LOCKED = "SETTINGS_LOCKED"
|
||||
private const val SHOW_CLOCK = "SHOW_CLOCK"
|
||||
private const val SWIPE_RIGHT_ACTION = "SWIPE_RIGHT_ACTION"
|
||||
private const val SWIPE_LEFT_ACTION = "SWIPE_LEFT_ACTION"
|
||||
private const val CLICK_CLOCK_ACTION = "CLICK_CLOCK_ACTION"
|
||||
private const val DOUBLE_TAP_ACTION = "DOUBLE_TAP_ACTION"
|
||||
private const val HIDDEN_APPS = "HIDDEN_APPS"
|
||||
private const val LOCKED_APPS = "LOCKED_APPS"
|
||||
private const val LAUNCHER_FONT = "LAUNCHER_FONT"
|
||||
private const val APP_NAME = "APP_NAME"
|
||||
private const val APP_PACKAGE = "APP_PACKAGE"
|
||||
private const val APP_USER = "APP_USER"
|
||||
private const val APP_ALIAS = "APP_ALIAS"
|
||||
private const val APP_ACTIVITY = "APP_ACTIVITY"
|
||||
private const val APP_THEME = "APP_THEME"
|
||||
private const val SWIPE_LEFT = "SWIPE_LEFT"
|
||||
private const val SWIPE_RIGHT = "SWIPE_RIGHT"
|
||||
private const val CLICK_CLOCK = "CLICK_CLOCK"
|
||||
private const val DOUBLE_TAP = "DOUBLE_TAP"
|
||||
private const val APP_SIZE_TEXT = "APP_SIZE_TEXT"
|
||||
private const val CLOCK_SIZE_TEXT = "CLOCK_SIZE_TEXT"
|
||||
private const val BATTERY_SIZE_TEXT = "BATTERY_SIZE_TEXT"
|
||||
private const val TEXT_SIZE_SETTINGS = "TEXT_SIZE_SETTINGS"
|
||||
private const val TEXT_PADDING_SIZE = "TEXT_PADDING_SIZE"
|
||||
private const val SHOW_NOTIFICATION_BADGE = "show_notification_badge"
|
||||
private const val ONBOARDING_PAGE = "ONBOARDING_PAGE"
|
||||
|
||||
private const val BACKGROUND_COLOR = "BACKGROUND_COLOR"
|
||||
private const val APP_COLOR = "APP_COLOR"
|
||||
private const val CLOCK_COLOR = "CLOCK_COLOR"
|
||||
private const val BATTERY_COLOR = "BATTERY_COLOR"
|
||||
|
||||
private const val APPS_FONT = "APPS_FONT"
|
||||
private const val CLOCK_FONT = "CLOCK_FONT"
|
||||
private const val STATUS_FONT = "STATUS_FONT" // For Calendar, Alarm, Battery
|
||||
private const val NOTIFICATION_FONT = "NOTIFICATION_FONT"
|
||||
|
||||
private const val EINK_REFRESH_ENABLED = "EINK_REFRESH_ENABLED"
|
||||
|
||||
class Prefs(val context: Context) {
|
||||
|
||||
private val prefs: SharedPreferences = context.getSharedPreferences(PREFS_FILENAME, 0)
|
||||
|
||||
val sharedPrefs: SharedPreferences
|
||||
get() = prefs
|
||||
|
||||
private val CUSTOM_FONT_PATH_MAP_KEY = "custom_font_path_map"
|
||||
private val gson = Gson()
|
||||
|
||||
var customFontPathMap: MutableMap<String, String>
|
||||
get() {
|
||||
val json = prefs.getString(CUSTOM_FONT_PATH_MAP_KEY, "{}") ?: "{}"
|
||||
return gson.fromJson(json, object : TypeToken<MutableMap<String, String>>() {}.type)
|
||||
?: mutableMapOf()
|
||||
}
|
||||
set(value) {
|
||||
prefs.edit { putString(CUSTOM_FONT_PATH_MAP_KEY, gson.toJson(value)) }
|
||||
}
|
||||
|
||||
fun setCustomFontPath(context: String, path: String) {
|
||||
val map = customFontPathMap
|
||||
map[context] = path
|
||||
customFontPathMap = map
|
||||
}
|
||||
|
||||
fun getCustomFontPath(context: String): String? {
|
||||
return customFontPathMap[context]
|
||||
}
|
||||
|
||||
// Remove a custom font path from the context map
|
||||
fun removeCustomFontPath(context: String) {
|
||||
val map = customFontPathMap
|
||||
map.remove(context)
|
||||
customFontPathMap = map
|
||||
}
|
||||
|
||||
// Remove a custom font path from the set of paths
|
||||
fun removeCustomFontPathByPath(path: String) {
|
||||
val set = customFontPaths
|
||||
set.remove(path)
|
||||
customFontPaths = set
|
||||
}
|
||||
|
||||
var universalFontEnabled: Boolean
|
||||
get() = prefs.getBoolean("universal_font_enabled", true)
|
||||
set(value) {
|
||||
prefs.edit {
|
||||
putBoolean("universal_font_enabled", value)
|
||||
}
|
||||
if (value) {
|
||||
// Apply universal font to all elements when enabled
|
||||
val font = universalFont
|
||||
appsFont = font
|
||||
clockFont = font
|
||||
statusFont = font
|
||||
labelnotificationsFont = font
|
||||
batteryFont = font
|
||||
lettersFont = font
|
||||
lettersTitleFont = font
|
||||
notificationsFont = font
|
||||
}
|
||||
}
|
||||
|
||||
var universalFont: Constants.FontFamily
|
||||
get() = try {
|
||||
Constants.FontFamily.valueOf(
|
||||
prefs.getString("universal_font", Constants.FontFamily.System.name)!!
|
||||
)
|
||||
} catch (_: Exception) {
|
||||
Constants.FontFamily.System
|
||||
}
|
||||
set(value) {
|
||||
prefs.edit {
|
||||
putString("universal_font", value.name)
|
||||
}
|
||||
if (universalFontEnabled) {
|
||||
// When universal font is enabled and changed, update all relevant preferences
|
||||
appsFont = value
|
||||
clockFont = value
|
||||
statusFont = value
|
||||
labelnotificationsFont = value
|
||||
batteryFont = value
|
||||
lettersFont = value
|
||||
lettersTitleFont = value
|
||||
notificationsFont = value
|
||||
}
|
||||
}
|
||||
|
||||
var fontFamily: Constants.FontFamily
|
||||
get() = try {
|
||||
Constants.FontFamily.valueOf(
|
||||
prefs.getString(
|
||||
LAUNCHER_FONT,
|
||||
Constants.FontFamily.System.name
|
||||
).toString()
|
||||
)
|
||||
} catch (_: Exception) {
|
||||
Constants.FontFamily.System
|
||||
}
|
||||
set(value) = prefs.edit { putString(LAUNCHER_FONT, value.name) }
|
||||
|
||||
var customFontPath: String?
|
||||
get() = prefs.getString("custom_font_path", null)
|
||||
set(value) = prefs.edit { putString("custom_font_path", value) }
|
||||
|
||||
// Store a set of custom font paths
|
||||
var customFontPaths: MutableSet<String>
|
||||
get() = prefs.getStringSet("custom_font_paths", mutableSetOf()) ?: mutableSetOf()
|
||||
set(value) = prefs.edit { putStringSet("custom_font_paths", value) }
|
||||
|
||||
// Add a new custom font path
|
||||
fun addCustomFontPath(path: String) {
|
||||
val set = customFontPaths
|
||||
set.add(path)
|
||||
customFontPaths = set
|
||||
}
|
||||
|
||||
var notificationsEnabled: Boolean
|
||||
get() = prefs.getBoolean(NOTIFICATIONS_ENABLED, true)
|
||||
set(value) = prefs.edit { putBoolean(NOTIFICATIONS_ENABLED, value) }
|
||||
|
||||
var notificationsFont: Constants.FontFamily
|
||||
get() = try {
|
||||
Constants.FontFamily.valueOf(
|
||||
prefs.getString(NOTIFICATIONS_FONT, Constants.FontFamily.System.name)!!
|
||||
)
|
||||
} catch (_: Exception) {
|
||||
Constants.FontFamily.System
|
||||
}
|
||||
set(value) = prefs.edit { putString(NOTIFICATIONS_FONT, value.name) }
|
||||
|
||||
var notificationsTextSize: Int
|
||||
get() = prefs.getInt(NOTIFICATIONS_TEXT_SIZE, 18)
|
||||
set(value) = prefs.edit { putInt(NOTIFICATIONS_TEXT_SIZE, value) }
|
||||
|
||||
var showNotificationSenderFullName: Boolean
|
||||
get() = prefs.getBoolean("show_notification_sender_full_name", false)
|
||||
set(value) = prefs.edit { putBoolean("show_notification_sender_full_name", value) }
|
||||
|
||||
var einkRefreshEnabled: Boolean
|
||||
get() = prefs.getBoolean(EINK_REFRESH_ENABLED, false)
|
||||
set(value) = prefs.edit { putBoolean(EINK_REFRESH_ENABLED, value) }
|
||||
|
||||
// --- Push Notifications Master Switch ---
|
||||
private val _pushNotificationsEnabledFlow = MutableStateFlow(pushNotificationsEnabled)
|
||||
val pushNotificationsEnabledFlow: StateFlow<Boolean> get() = _pushNotificationsEnabledFlow
|
||||
|
||||
var pushNotificationsEnabled: Boolean
|
||||
get() = prefs.getBoolean("push_notifications_enabled", false)
|
||||
set(value) {
|
||||
prefs.edit { putBoolean("push_notifications_enabled", value) }
|
||||
_pushNotificationsEnabledFlow.value = value
|
||||
}
|
||||
|
||||
// Save/restore notification-related switches' state
|
||||
private val NOTIFICATION_SWITCHES_STATE_KEY = "notification_switches_state"
|
||||
|
||||
fun saveNotificationSwitchesState() {
|
||||
val state = mapOf(
|
||||
"showNotificationBadge" to showNotificationBadge,
|
||||
"showNotificationText" to showNotificationText,
|
||||
"showNotificationSenderName" to showNotificationSenderName,
|
||||
"showNotificationGroupName" to showNotificationGroupName,
|
||||
"showNotificationMessage" to showNotificationMessage,
|
||||
"showMediaIndicator" to showMediaIndicator,
|
||||
"showMediaName" to showMediaName,
|
||||
"notificationsEnabled" to notificationsEnabled,
|
||||
"showNotificationSenderFullName" to showNotificationSenderFullName
|
||||
)
|
||||
prefs.edit { putString(NOTIFICATION_SWITCHES_STATE_KEY, gson.toJson(state)) }
|
||||
}
|
||||
|
||||
fun restoreNotificationSwitchesState() {
|
||||
val json = prefs.getString(NOTIFICATION_SWITCHES_STATE_KEY, null) ?: return
|
||||
val type = object : TypeToken<Map<String, Boolean>>() {}.type
|
||||
val state: Map<String, Boolean> = gson.fromJson(json, type) ?: return
|
||||
state["showNotificationBadge"]?.let { showNotificationBadge = it }
|
||||
state["showNotificationText"]?.let { showNotificationText = it }
|
||||
state["showNotificationSenderName"]?.let { showNotificationSenderName = it }
|
||||
state["showNotificationGroupName"]?.let { showNotificationGroupName = it }
|
||||
state["showNotificationMessage"]?.let { showNotificationMessage = it }
|
||||
state["showMediaIndicator"]?.let { showMediaIndicator = it }
|
||||
state["showMediaName"]?.let { showMediaName = it }
|
||||
state["notificationsEnabled"]?.let { notificationsEnabled = it }
|
||||
state["showNotificationSenderFullName"]?.let { showNotificationSenderFullName = it }
|
||||
}
|
||||
|
||||
fun disableAllNotificationSwitches() {
|
||||
showNotificationBadge = false
|
||||
showNotificationText = false
|
||||
showNotificationSenderName = false
|
||||
showNotificationGroupName = false
|
||||
showNotificationMessage = false
|
||||
showMediaIndicator = false
|
||||
showMediaName = false
|
||||
notificationsEnabled = false
|
||||
showNotificationSenderFullName = false
|
||||
}
|
||||
|
||||
fun saveToString(): String {
|
||||
val all: HashMap<String, Any?> = HashMap(prefs.all)
|
||||
return Gson().toJson(all)
|
||||
}
|
||||
|
||||
fun loadFromString(json: String) {
|
||||
prefs.edit {
|
||||
val all: HashMap<String, Any?> =
|
||||
Gson().fromJson(json, object : TypeToken<HashMap<String, Any?>>() {}.type)
|
||||
val pm = context.packageManager
|
||||
for ((key, value) in all) {
|
||||
// Explicitly handle allowlists as sets of strings, and filter out non-existent apps
|
||||
if (key == "allowed_notification_apps" || key == "allowed_badge_notification_apps") {
|
||||
val set = when (value) {
|
||||
is Collection<*> -> value.filterIsInstance<String>().toMutableSet()
|
||||
is String -> mutableSetOf(value)
|
||||
else -> mutableSetOf<String>()
|
||||
}
|
||||
// Filter out packages that are not installed
|
||||
val filteredSet = set.filter { pkg ->
|
||||
try {
|
||||
pm.getPackageInfo(pkg, 0)
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
}.toMutableSet()
|
||||
putStringSet(key, filteredSet)
|
||||
continue
|
||||
}
|
||||
when (value) {
|
||||
is String -> putString(key, value)
|
||||
is Boolean -> putBoolean(key, value)
|
||||
is Number -> {
|
||||
if (value.toDouble() == value.toInt().toDouble()) {
|
||||
putInt(key, value.toInt())
|
||||
} else {
|
||||
putFloat(key, value.toFloat())
|
||||
}
|
||||
}
|
||||
|
||||
is MutableSet<*> -> {
|
||||
val list = value.filterIsInstance<String>().toSet()
|
||||
putStringSet(key, list)
|
||||
}
|
||||
|
||||
else -> {
|
||||
Log.d("backup error", "$value")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getAppAlias(key: String): String {
|
||||
return prefs.getString(key, "").toString()
|
||||
}
|
||||
|
||||
fun setAppAlias(packageName: String, appAlias: String) {
|
||||
prefs.edit { putString("app_alias_$packageName", appAlias) }
|
||||
}
|
||||
|
||||
fun removeAppAlias(packageName: String) {
|
||||
prefs.edit { remove("app_alias_$packageName") }
|
||||
}
|
||||
|
||||
var appVersion: Int
|
||||
get() = prefs.getInt(APP_VERSION, -1)
|
||||
set(value) = prefs.edit { putInt(APP_VERSION, value) }
|
||||
|
||||
var firstOpen: Boolean
|
||||
get() = prefs.getBoolean(FIRST_OPEN, true)
|
||||
set(value) = prefs.edit { putBoolean(FIRST_OPEN, value) }
|
||||
|
||||
var firstSettingsOpen: Boolean
|
||||
get() = prefs.getBoolean(FIRST_SETTINGS_OPEN, true)
|
||||
set(value) = prefs.edit { putBoolean(FIRST_SETTINGS_OPEN, value) }
|
||||
|
||||
var lockModeOn: Boolean
|
||||
get() = prefs.getBoolean(LOCK_MODE, false)
|
||||
set(value) = prefs.edit { putBoolean(LOCK_MODE, value) }
|
||||
|
||||
var homePager: Boolean
|
||||
get() = prefs.getBoolean(HOME_PAGES_PAGER, true)
|
||||
set(value) = prefs.edit { putBoolean(HOME_PAGES_PAGER, value) }
|
||||
|
||||
var homeAppsNum: Int
|
||||
get() = prefs.getInt(HOME_APPS_NUM, 15)
|
||||
set(value) = prefs.edit { putInt(HOME_APPS_NUM, value) }
|
||||
|
||||
var homePagesNum: Int
|
||||
get() = prefs.getInt(HOME_PAGES_NUM, 3)
|
||||
set(value) = prefs.edit { putInt(HOME_PAGES_NUM, value) }
|
||||
|
||||
var backgroundColor: Int
|
||||
get() = prefs.getInt(BACKGROUND_COLOR, getColor(context, getColorInt("bg")))
|
||||
set(value) = prefs.edit { putInt(BACKGROUND_COLOR, value) }
|
||||
|
||||
var appColor: Int
|
||||
get() = prefs.getInt(APP_COLOR, getColor(context, getColorInt("txt")))
|
||||
set(value) = prefs.edit { putInt(APP_COLOR, value) }
|
||||
|
||||
var clockColor: Int
|
||||
get() = prefs.getInt(CLOCK_COLOR, getColor(context, getColorInt("txt")))
|
||||
set(value) = prefs.edit { putInt(CLOCK_COLOR, value) }
|
||||
|
||||
var batteryColor: Int
|
||||
get() = prefs.getInt(BATTERY_COLOR, getColor(context, getColorInt("txt")))
|
||||
set(value) = prefs.edit { putInt(BATTERY_COLOR, value) }
|
||||
|
||||
var extendHomeAppsArea: Boolean
|
||||
get() = prefs.getBoolean(HOME_CLICK_AREA, false)
|
||||
set(value) = prefs.edit { putBoolean(HOME_CLICK_AREA, value) }
|
||||
|
||||
var showStatusBar: Boolean
|
||||
get() = prefs.getBoolean(STATUS_BAR, false)
|
||||
set(value) = prefs.edit { putBoolean(STATUS_BAR, value) }
|
||||
|
||||
var showClock: Boolean
|
||||
get() = prefs.getBoolean(SHOW_CLOCK, false)
|
||||
set(value) = prefs.edit { putBoolean(SHOW_CLOCK, value) }
|
||||
|
||||
var showBattery: Boolean
|
||||
get() = prefs.getBoolean(SHOW_BATTERY, false)
|
||||
set(value) = prefs.edit { putBoolean(SHOW_BATTERY, value) }
|
||||
|
||||
var showNotificationBadge: Boolean
|
||||
get() = prefs.getBoolean(SHOW_NOTIFICATION_BADGE, true)
|
||||
set(value) = prefs.edit { putBoolean(SHOW_NOTIFICATION_BADGE, value) }
|
||||
|
||||
var showNotificationText: Boolean
|
||||
get() = prefs.getBoolean("showNotificationText", true)
|
||||
set(value) = prefs.edit { putBoolean("showNotificationText", value) }
|
||||
|
||||
var labelnotificationsTextSize: Int
|
||||
get() = prefs.getInt("notificationTextSize", 16)
|
||||
set(value) = prefs.edit { putInt("notificationTextSize", value) }
|
||||
|
||||
var showNotificationSenderName: Boolean
|
||||
get() = prefs.getBoolean("show_notification_sender_name", true)
|
||||
set(value) = prefs.edit { putBoolean("show_notification_sender_name", value) }
|
||||
|
||||
var showNotificationGroupName: Boolean
|
||||
get() = prefs.getBoolean("show_notification_group_name", true)
|
||||
set(value) = prefs.edit { putBoolean("show_notification_group_name", value) }
|
||||
|
||||
var showNotificationMessage: Boolean
|
||||
get() = prefs.getBoolean("show_notification_message", true)
|
||||
set(value) = prefs.edit { putBoolean("show_notification_message", value) }
|
||||
|
||||
// Media indicator and media name toggles
|
||||
var showMediaIndicator: Boolean
|
||||
get() = prefs.getBoolean("show_media_indicator", true)
|
||||
set(value) = prefs.edit { putBoolean("show_media_indicator", value) }
|
||||
|
||||
var showMediaName: Boolean
|
||||
get() = prefs.getBoolean("show_media_name", true)
|
||||
set(value) = prefs.edit { putBoolean("show_media_name", value) }
|
||||
|
||||
var homeLocked: Boolean
|
||||
get() = prefs.getBoolean(HOME_LOCKED, false)
|
||||
set(value) = prefs.edit { putBoolean(HOME_LOCKED, value) }
|
||||
|
||||
var settingsLocked: Boolean
|
||||
get() = prefs.getBoolean(SETTINGS_LOCKED, false)
|
||||
set(value) = prefs.edit { putBoolean(SETTINGS_LOCKED, value) }
|
||||
|
||||
var swipeLeftAction: Constants.Action
|
||||
get() {
|
||||
return try {
|
||||
Constants.Action.valueOf(
|
||||
prefs.getString(
|
||||
SWIPE_LEFT_ACTION,
|
||||
Constants.Action.OpenNotificationsScreen.name // changed default
|
||||
).toString()
|
||||
)
|
||||
} catch (_: Exception) {
|
||||
Constants.Action.OpenNotificationsScreen // changed default
|
||||
}
|
||||
}
|
||||
set(value) = prefs.edit { putString(SWIPE_LEFT_ACTION, value.name) }
|
||||
|
||||
var swipeRightAction: Constants.Action
|
||||
get() {
|
||||
return try {
|
||||
Constants.Action.valueOf(
|
||||
prefs.getString(
|
||||
SWIPE_RIGHT_ACTION,
|
||||
Constants.Action.OpenApp.name
|
||||
).toString()
|
||||
)
|
||||
} catch (_: Exception) {
|
||||
Constants.Action.OpenApp
|
||||
}
|
||||
}
|
||||
set(value) = prefs.edit { putString(SWIPE_RIGHT_ACTION, value.name) }
|
||||
|
||||
var clickClockAction: Constants.Action
|
||||
get() {
|
||||
return try {
|
||||
Constants.Action.valueOf(
|
||||
prefs.getString(
|
||||
CLICK_CLOCK_ACTION,
|
||||
Constants.Action.OpenApp.name
|
||||
).toString()
|
||||
)
|
||||
} catch (_: Exception) {
|
||||
Constants.Action.OpenApp
|
||||
}
|
||||
}
|
||||
set(value) = prefs.edit { putString(CLICK_CLOCK_ACTION, value.name) }
|
||||
|
||||
var doubleTapAction: Constants.Action
|
||||
get() {
|
||||
return try {
|
||||
Constants.Action.valueOf(
|
||||
prefs.getString(
|
||||
DOUBLE_TAP_ACTION,
|
||||
Constants.Action.RestartApp.name
|
||||
).toString()
|
||||
)
|
||||
} catch (_: Exception) {
|
||||
Constants.Action.RestartApp
|
||||
}
|
||||
}
|
||||
set(value) = prefs.edit { putString(DOUBLE_TAP_ACTION, value.name) }
|
||||
|
||||
var appTheme: Constants.Theme
|
||||
get() {
|
||||
return try {
|
||||
Constants.Theme.valueOf(
|
||||
prefs.getString(APP_THEME, Constants.Theme.System.name).toString()
|
||||
)
|
||||
} catch (_: Exception) {
|
||||
Constants.Theme.System
|
||||
}
|
||||
}
|
||||
set(value) = prefs.edit { putString(APP_THEME, value.name) }
|
||||
|
||||
|
||||
var appsFont: Constants.FontFamily
|
||||
get() = try {
|
||||
Constants.FontFamily.valueOf(
|
||||
prefs.getString(APPS_FONT, Constants.FontFamily.System.name).toString()
|
||||
)
|
||||
} catch (_: Exception) {
|
||||
Constants.FontFamily.System
|
||||
}
|
||||
set(value) = prefs.edit { putString(APPS_FONT, value.name) }
|
||||
|
||||
var clockFont: Constants.FontFamily
|
||||
get() = try {
|
||||
Constants.FontFamily.valueOf(
|
||||
prefs.getString(CLOCK_FONT, Constants.FontFamily.System.name).toString()
|
||||
)
|
||||
} catch (_: Exception) {
|
||||
Constants.FontFamily.System
|
||||
}
|
||||
set(value) = prefs.edit { putString(CLOCK_FONT, value.name) }
|
||||
|
||||
var statusFont: Constants.FontFamily
|
||||
get() = try {
|
||||
Constants.FontFamily.valueOf(
|
||||
prefs.getString(STATUS_FONT, Constants.FontFamily.System.name).toString()
|
||||
)
|
||||
} catch (_: Exception) {
|
||||
Constants.FontFamily.System
|
||||
}
|
||||
set(value) = prefs.edit { putString(STATUS_FONT, value.name) }
|
||||
|
||||
var labelnotificationsFont: Constants.FontFamily
|
||||
get() = try {
|
||||
Constants.FontFamily.valueOf(
|
||||
prefs.getString(NOTIFICATION_FONT, Constants.FontFamily.System.name).toString()
|
||||
)
|
||||
} catch (_: Exception) {
|
||||
Constants.FontFamily.System
|
||||
}
|
||||
set(value) = prefs.edit { putString(NOTIFICATION_FONT, value.name) }
|
||||
|
||||
var batteryFont: Constants.FontFamily
|
||||
get() = try {
|
||||
Constants.FontFamily.valueOf(
|
||||
prefs.getString(BATTERY_FONT, Constants.FontFamily.System.name)!!
|
||||
)
|
||||
} catch (_: Exception) {
|
||||
Constants.FontFamily.System
|
||||
}
|
||||
set(value) = prefs.edit { putString(BATTERY_FONT, value.name) }
|
||||
|
||||
var lettersFont: Constants.FontFamily
|
||||
get() = try {
|
||||
Constants.FontFamily.valueOf(
|
||||
prefs.getString(LETTERS_FONT, Constants.FontFamily.System.name)!!
|
||||
)
|
||||
} catch (_: Exception) {
|
||||
Constants.FontFamily.System
|
||||
}
|
||||
set(value) = prefs.edit { putString(LETTERS_FONT, value.name) }
|
||||
|
||||
var lettersTextSize: Int
|
||||
get() = prefs.getInt(LETTERS_TEXT_SIZE, 18)
|
||||
set(value) = prefs.edit { putInt(LETTERS_TEXT_SIZE, value) }
|
||||
|
||||
var lettersTitle: String
|
||||
get() = prefs.getString(LETTERS_TITLE, "Letters") ?: "Letters"
|
||||
set(value) = prefs.edit { putString(LETTERS_TITLE, value) }
|
||||
|
||||
var lettersTitleFont: Constants.FontFamily
|
||||
get() = try {
|
||||
Constants.FontFamily.valueOf(
|
||||
prefs.getString(LETTERS_TITLE_FONT, Constants.FontFamily.System.name)!!
|
||||
)
|
||||
} catch (_: Exception) {
|
||||
Constants.FontFamily.System
|
||||
}
|
||||
set(value) = prefs.edit { putString(LETTERS_TITLE_FONT, value.name) }
|
||||
|
||||
var lettersTitleSize: Int
|
||||
get() = prefs.getInt(LETTERS_TITLE_SIZE, 36)
|
||||
set(value) = prefs.edit { putInt(LETTERS_TITLE_SIZE, value) }
|
||||
|
||||
var hiddenApps: MutableSet<String>
|
||||
get() = prefs.getStringSet(HIDDEN_APPS, mutableSetOf()) as MutableSet<String>
|
||||
set(value) = prefs.edit { putStringSet(HIDDEN_APPS, value) }
|
||||
|
||||
var lockedApps: MutableSet<String>
|
||||
get() = prefs.getStringSet(LOCKED_APPS, mutableSetOf()) as MutableSet<String>
|
||||
set(value) = prefs.edit { putStringSet(LOCKED_APPS, value) }
|
||||
|
||||
/**
|
||||
* By the number in home app list, get the list item.
|
||||
* TODO why not just save it as a list?
|
||||
*/
|
||||
fun getHomeAppModel(i: Int): AppListItem {
|
||||
return loadApp("$i")
|
||||
}
|
||||
|
||||
fun setHomeAppModel(i: Int, appListItem: AppListItem) {
|
||||
storeApp("$i", appListItem)
|
||||
}
|
||||
|
||||
var appSwipeLeft: AppListItem
|
||||
get() = loadApp(SWIPE_LEFT)
|
||||
set(appModel) = storeApp(SWIPE_LEFT, appModel)
|
||||
|
||||
var appSwipeRight: AppListItem
|
||||
get() = loadApp(SWIPE_RIGHT)
|
||||
set(appModel) = storeApp(SWIPE_RIGHT, appModel)
|
||||
|
||||
var appClickClock: AppListItem
|
||||
get() = loadApp(CLICK_CLOCK)
|
||||
set(appModel) = storeApp(CLICK_CLOCK, appModel)
|
||||
|
||||
|
||||
var appDoubleTap: AppListItem
|
||||
get() = loadApp(DOUBLE_TAP)
|
||||
set(appModel) = storeApp(DOUBLE_TAP, appModel)
|
||||
|
||||
/**
|
||||
* Restore an `AppListItem` from preferences.
|
||||
*
|
||||
* We store not only application name, but everything needed to start the item.
|
||||
* Because thus we save time to query the system about it?
|
||||
*
|
||||
* TODO store with protobuf instead of serializing manually.
|
||||
*/
|
||||
private fun loadApp(id: String): AppListItem {
|
||||
val appName = prefs.getString("${APP_NAME}_$id", "").toString()
|
||||
val appPackage = prefs.getString("${APP_PACKAGE}_$id", "").toString()
|
||||
val appActivityName = prefs.getString("${APP_ACTIVITY}_$id", "").toString()
|
||||
val customLabel = getAppAlias("app_alias_$appPackage")
|
||||
|
||||
val userHandleString = try {
|
||||
prefs.getString("${APP_USER}_$id", "").toString()
|
||||
} catch (_: Exception) {
|
||||
""
|
||||
}
|
||||
val userHandle: UserHandle = getUserHandleFromString(context, userHandleString)
|
||||
|
||||
return AppListItem(
|
||||
activityLabel = appName,
|
||||
activityPackage = appPackage,
|
||||
customLabel = customLabel, // Set the custom label when loading the app
|
||||
activityClass = appActivityName,
|
||||
user = userHandle,
|
||||
)
|
||||
}
|
||||
|
||||
private fun storeApp(id: String, app: AppListItem) {
|
||||
prefs.edit {
|
||||
|
||||
putString("${APP_NAME}_$id", app.label)
|
||||
putString("${APP_PACKAGE}_$id", app.activityPackage)
|
||||
putString("${APP_ACTIVITY}_$id", app.activityClass)
|
||||
putString("${APP_ALIAS}_$id", app.customLabel)
|
||||
putString("${APP_USER}_$id", app.user.toString())
|
||||
}
|
||||
}
|
||||
|
||||
var appSize: Int
|
||||
get() {
|
||||
return try {
|
||||
prefs.getInt(APP_SIZE_TEXT, 32)
|
||||
} catch (_: Exception) {
|
||||
18
|
||||
}
|
||||
}
|
||||
set(value) = prefs.edit { putInt(APP_SIZE_TEXT, value) }
|
||||
|
||||
var clockSize: Int
|
||||
get() {
|
||||
return try {
|
||||
prefs.getInt(CLOCK_SIZE_TEXT, 64)
|
||||
} catch (_: Exception) {
|
||||
64
|
||||
}
|
||||
}
|
||||
set(value) = prefs.edit { putInt(CLOCK_SIZE_TEXT, value) }
|
||||
|
||||
var batterySize: Int
|
||||
get() {
|
||||
return try {
|
||||
prefs.getInt(BATTERY_SIZE_TEXT, 18)
|
||||
} catch (_: Exception) {
|
||||
18
|
||||
}
|
||||
}
|
||||
set(value) = prefs.edit { putInt(BATTERY_SIZE_TEXT, value) }
|
||||
|
||||
var settingsSize: Int
|
||||
get() {
|
||||
return try {
|
||||
prefs.getInt(TEXT_SIZE_SETTINGS, 16)
|
||||
} catch (_: Exception) {
|
||||
17
|
||||
}
|
||||
}
|
||||
set(value) = prefs.edit { putInt(TEXT_SIZE_SETTINGS, value) }
|
||||
|
||||
var textPaddingSize: Int
|
||||
get() {
|
||||
return try {
|
||||
prefs.getInt(TEXT_PADDING_SIZE, 12)
|
||||
} catch (_: Exception) {
|
||||
12
|
||||
}
|
||||
}
|
||||
set(value) = prefs.edit { putInt(TEXT_PADDING_SIZE, value) }
|
||||
|
||||
// Number of characters to show in Home App Name Notifications
|
||||
// Remove unused property
|
||||
// var homeNotificationCharLimit: Int
|
||||
// get() = prefs.getInt("home_notification_char_limit", 30)
|
||||
// set(value) = prefs.edit { putInt("home_notification_char_limit", value) }
|
||||
|
||||
// Character limit for Home App labels
|
||||
var homeAppCharLimit: Int
|
||||
get() = prefs.getInt("home_app_char_limit", 20) // default to 20
|
||||
set(value) = prefs.edit { putInt("home_app_char_limit", value) }
|
||||
|
||||
private fun getColorInt(type: String): Int {
|
||||
when (appTheme) {
|
||||
Constants.Theme.System -> {
|
||||
return if (isSystemInDarkMode(context)) {
|
||||
if (type == "bg") R.color.black
|
||||
else R.color.white
|
||||
} else {
|
||||
if (type == "bg") R.color.white
|
||||
else R.color.black
|
||||
}
|
||||
}
|
||||
|
||||
Constants.Theme.Dark -> {
|
||||
return if (type == "bg") R.color.black
|
||||
else R.color.white
|
||||
}
|
||||
|
||||
Constants.Theme.Light -> {
|
||||
return if (type == "bg") R.color.white // #FFFFFF for background
|
||||
else R.color.black // #000000 for app, date, clock, alarm, battery
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// return app label
|
||||
fun getAppName(location: Int): String {
|
||||
return getHomeAppModel(location).activityLabel
|
||||
}
|
||||
|
||||
fun remove(prefName: String) {
|
||||
prefs.edit { remove(prefName) }
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
prefs.edit { clear() }
|
||||
}
|
||||
|
||||
fun getFontForContext(context: String): Constants.FontFamily {
|
||||
return if (universalFontEnabled) universalFont else when (context) {
|
||||
"settings" -> fontFamily
|
||||
"apps" -> appsFont
|
||||
"clock" -> clockFont
|
||||
"status" -> statusFont
|
||||
"notification" -> labelnotificationsFont
|
||||
"battery" -> batteryFont
|
||||
"letters" -> lettersFont
|
||||
"lettersTitle" -> lettersTitleFont
|
||||
"notifications" -> notificationsFont
|
||||
else -> Constants.FontFamily.System
|
||||
}
|
||||
}
|
||||
|
||||
fun getCustomFontPathForContext(context: String): String? {
|
||||
return if (universalFontEnabled && universalFont == Constants.FontFamily.Custom) {
|
||||
getCustomFontPath("universal")
|
||||
} else {
|
||||
getCustomFontPath(context)
|
||||
}
|
||||
}
|
||||
|
||||
// Per-app allowlist (was blocklist)
|
||||
var allowedNotificationApps: MutableSet<String>
|
||||
get() = prefs.getStringSet("allowed_notification_apps", mutableSetOf()) ?: mutableSetOf()
|
||||
set(value) = prefs.edit { putStringSet("allowed_notification_apps", value) }
|
||||
|
||||
// Per-app allowlist for badge notifications
|
||||
var allowedBadgeNotificationApps: MutableSet<String>
|
||||
get() = prefs.getStringSet("allowed_badge_notification_apps", mutableSetOf())
|
||||
?: mutableSetOf()
|
||||
set(value) = prefs.edit { putStringSet("allowed_badge_notification_apps", value) }
|
||||
|
||||
// --- Volume keys for page navigation ---
|
||||
var useVolumeKeysForPages: Boolean
|
||||
get() = prefs.getBoolean("use_volume_keys_for_pages", false)
|
||||
set(value) = prefs.edit { putBoolean("use_volume_keys_for_pages", value) }
|
||||
|
||||
var longPressAppInfoEnabled: Boolean
|
||||
get() = prefs.getBoolean("long_press_app_info_enabled", false)
|
||||
set(value) = prefs.edit { putBoolean("long_press_app_info_enabled", value) }
|
||||
|
||||
// --- Vibration for paging ---
|
||||
var useVibrationForPaging: Boolean
|
||||
get() = prefs.getBoolean("use_vibration_for_paging", false)
|
||||
set(value) = prefs.edit { putBoolean("use_vibration_for_paging", value) }
|
||||
|
||||
var onboardingPage: Int
|
||||
get() = prefs.getInt(ONBOARDING_PAGE, 0)
|
||||
set(value) = prefs.edit { putInt(ONBOARDING_PAGE, value) }
|
||||
|
||||
companion object {
|
||||
private const val BATTERY_FONT = "battery_font"
|
||||
private const val LETTERS_FONT = "letters_font"
|
||||
private const val LETTERS_TEXT_SIZE = "letters_text_size"
|
||||
private const val LETTERS_TITLE = "letters_title"
|
||||
private const val LETTERS_TITLE_FONT = "letters_title_font"
|
||||
private const val LETTERS_TITLE_SIZE = "letters_title_size"
|
||||
private const val NOTIFICATIONS_ENABLED = "notifications_enabled"
|
||||
private const val NOTIFICATIONS_FONT = "notifications_font"
|
||||
private const val NOTIFICATIONS_TEXT_SIZE = "notifications_text_size"
|
||||
}
|
||||
}
|
||||
441
app/src/main/java/com/github/gezimos/inkos/helper/SystemUtils.kt
Normal file
441
app/src/main/java/com/github/gezimos/inkos/helper/SystemUtils.kt
Normal file
@@ -0,0 +1,441 @@
|
||||
package com.github.gezimos.inkos.helper
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.UiModeManager
|
||||
import android.app.role.RoleManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.LauncherApps
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Typeface
|
||||
import android.os.Build
|
||||
import android.os.Process
|
||||
import android.os.UserHandle
|
||||
import android.os.UserManager
|
||||
import android.provider.Settings
|
||||
import android.util.DisplayMetrics
|
||||
import android.util.Log
|
||||
import android.util.TypedValue
|
||||
import android.view.View
|
||||
import android.view.WindowInsets
|
||||
import android.view.WindowManager
|
||||
import com.github.gezimos.common.openAccessibilitySettings
|
||||
import com.github.gezimos.common.showLongToast
|
||||
import com.github.gezimos.inkos.R
|
||||
import com.github.gezimos.inkos.data.AppListItem
|
||||
import com.github.gezimos.inkos.data.Constants
|
||||
import com.github.gezimos.inkos.data.Prefs
|
||||
import com.github.gezimos.inkos.services.ActionService
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.xmlpull.v1.XmlPullParser
|
||||
import java.io.File
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import kotlin.math.pow
|
||||
import kotlin.math.sqrt
|
||||
|
||||
suspend fun getAppsList(
|
||||
context: Context,
|
||||
includeRegularApps: Boolean = true,
|
||||
includeHiddenApps: Boolean = false,
|
||||
): MutableList<AppListItem> {
|
||||
return withContext(Dispatchers.Main) {
|
||||
val appList: MutableList<AppListItem> = mutableListOf()
|
||||
val combinedList: MutableList<AppListItem> = mutableListOf()
|
||||
|
||||
try {
|
||||
val hiddenApps = Prefs(context).hiddenApps
|
||||
val userManager = context.getSystemService(Context.USER_SERVICE) as UserManager
|
||||
val launcherApps =
|
||||
context.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
|
||||
|
||||
for (profile in userManager.userProfiles) {
|
||||
for (launcherActivityInfo in launcherApps.getActivityList(null, profile)) {
|
||||
val activityName = launcherActivityInfo.name
|
||||
val appPackage = launcherActivityInfo.applicationInfo.packageName
|
||||
val label = launcherActivityInfo.label.toString()
|
||||
|
||||
if (includeHiddenApps && hiddenApps.contains(appPackage) ||
|
||||
includeRegularApps && !hiddenApps.contains(appPackage)
|
||||
) {
|
||||
appList.add(
|
||||
AppListItem(
|
||||
activityLabel = label,
|
||||
activityPackage = appPackage,
|
||||
activityClass = activityName,
|
||||
user = profile,
|
||||
customLabel = "" // Add empty string as default custom label
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
appList.sort()
|
||||
combinedList.addAll(appList)
|
||||
} catch (e: Exception) {
|
||||
Log.d("appList", e.toString())
|
||||
}
|
||||
|
||||
combinedList
|
||||
}
|
||||
}
|
||||
|
||||
fun getUserHandleFromString(context: Context, userHandleString: String): UserHandle {
|
||||
val userManager = context.getSystemService(Context.USER_SERVICE) as UserManager
|
||||
for (userHandle in userManager.userProfiles) {
|
||||
if (userHandle.toString() == userHandleString) {
|
||||
return userHandle
|
||||
}
|
||||
}
|
||||
return Process.myUserHandle()
|
||||
}
|
||||
|
||||
fun isinkosDefault(context: Context): Boolean {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
val roleManager = context.getSystemService(RoleManager::class.java)
|
||||
return roleManager.isRoleHeld(RoleManager.ROLE_HOME)
|
||||
} else {
|
||||
val testIntent = Intent(Intent.ACTION_MAIN)
|
||||
testIntent.addCategory(Intent.CATEGORY_HOME)
|
||||
val defaultHome = testIntent.resolveActivity(context.packageManager)?.packageName
|
||||
return defaultHome == context.packageName
|
||||
}
|
||||
}
|
||||
|
||||
fun setDefaultHomeScreen(context: Context, checkDefault: Boolean = false) {
|
||||
val isDefault = isinkosDefault(context)
|
||||
if (checkDefault && isDefault) {
|
||||
// Launcher is already the default home app
|
||||
return
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
|
||||
&& context is Activity
|
||||
&& !isDefault // using role manager only works when µLauncher is not already the default.
|
||||
) {
|
||||
val roleManager = context.getSystemService(RoleManager::class.java)
|
||||
context.startActivityForResult(
|
||||
roleManager.createRequestRoleIntent(RoleManager.ROLE_HOME),
|
||||
Constants.REQUEST_SET_DEFAULT_HOME
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
val intent = Intent(Settings.ACTION_HOME_SETTINGS)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
fun checkWhoInstalled(context: Context): String {
|
||||
val appName = context.getString(R.string.app_name)
|
||||
val descriptionTemplate =
|
||||
context.getString(R.string.advanced_settings_share_application_description)
|
||||
val descriptionTemplate2 =
|
||||
context.getString(R.string.advanced_settings_share_application_description_addon)
|
||||
|
||||
// Get the installer package name
|
||||
val installer: String? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
// For Android 11 (API 30) and above
|
||||
val installSourceInfo = context.packageManager.getInstallSourceInfo(context.packageName)
|
||||
installSourceInfo.installingPackageName
|
||||
} else {
|
||||
// For older versions
|
||||
context.packageManager.getInstallerPackageName(context.packageName)
|
||||
}
|
||||
|
||||
// Handle null installer package name
|
||||
val installSource = when (installer) {
|
||||
"com.android.vending" -> "Google Play Store"
|
||||
"org.fdroid.fdroid" -> "F-Droid"
|
||||
null -> "GitHub" // In case installer is null
|
||||
else -> installer // Default to the installer package name
|
||||
}
|
||||
|
||||
val installURL = when (installer) {
|
||||
"com.android.vending" -> "https://play.google.com/store/apps/details?id=app.mlauncher"
|
||||
"org.fdroid.fdroid" -> "https://f-droid.org/packages/app.mlauncher"
|
||||
null -> "https://github.com/DroidWorksStudio/mLauncher" // In case installer is null
|
||||
else -> "https://play.google.com/store/apps/details?id=app.mlauncher" // Default to the Google Play Store
|
||||
}
|
||||
|
||||
// Format the description with the app name and install source
|
||||
return String.format(
|
||||
"%s %s",
|
||||
String.format(descriptionTemplate, appName),
|
||||
String.format(descriptionTemplate2, installSource, installURL)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
fun openAppInfo(context: Context, userHandle: UserHandle, packageName: String) {
|
||||
val launcher = context.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
|
||||
val intent: Intent? = context.packageManager.getLaunchIntentForPackage(packageName)
|
||||
intent?.let {
|
||||
launcher.startAppDetailsActivity(intent.component, userHandle, null, null)
|
||||
} ?: context.showLongToast("Unable to to open app info")
|
||||
}
|
||||
|
||||
|
||||
fun isTablet(context: Context): Boolean {
|
||||
val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||
val metrics = DisplayMetrics()
|
||||
@Suppress("DEPRECATION")
|
||||
windowManager.defaultDisplay.getMetrics(metrics)
|
||||
val widthInches = metrics.widthPixels / metrics.xdpi
|
||||
val heightInches = metrics.heightPixels / metrics.ydpi
|
||||
val diagonalInches = sqrt(widthInches.toDouble().pow(2.0) + heightInches.toDouble().pow(2.0))
|
||||
if (diagonalInches >= 7.0) return true
|
||||
return false
|
||||
}
|
||||
|
||||
fun initActionService(context: Context): ActionService? {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
val actionService = ActionService.instance()
|
||||
if (actionService != null) {
|
||||
return actionService
|
||||
} else {
|
||||
context.openAccessibilitySettings()
|
||||
}
|
||||
} else {
|
||||
context.showLongToast("This action requires Android P (9) or higher")
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
fun showStatusBar(activity: Activity) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
|
||||
activity.window.insetsController?.show(WindowInsets.Type.statusBars())
|
||||
else
|
||||
@Suppress("DEPRECATION", "InlinedApi")
|
||||
activity.window.decorView.apply {
|
||||
systemUiVisibility =
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
}
|
||||
}
|
||||
|
||||
fun hideStatusBar(activity: Activity) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
|
||||
activity.window.insetsController?.hide(WindowInsets.Type.statusBars())
|
||||
else {
|
||||
@Suppress("DEPRECATION")
|
||||
activity.window.decorView.apply {
|
||||
systemUiVisibility = View.SYSTEM_UI_FLAG_IMMERSIVE or View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun dp2px(resources: Resources, dp: Int): Int {
|
||||
return TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP,
|
||||
dp.toFloat(),
|
||||
resources.displayMetrics
|
||||
).toInt()
|
||||
}
|
||||
|
||||
fun storeFile(activity: Activity, backupType: Constants.BackupType) {
|
||||
// Generate a unique filename with a timestamp
|
||||
when (backupType) {
|
||||
Constants.BackupType.FullSystem -> {
|
||||
val timeStamp = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(Date())
|
||||
val fileName = "backup_$timeStamp.json"
|
||||
|
||||
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
type = "application/json"
|
||||
putExtra(Intent.EXTRA_TITLE, fileName)
|
||||
}
|
||||
activity.startActivityForResult(intent, Constants.BACKUP_WRITE, null)
|
||||
}
|
||||
|
||||
Constants.BackupType.Theme -> {
|
||||
val timeStamp = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date())
|
||||
val fileName = "theme_$timeStamp.mtheme"
|
||||
|
||||
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
type = "application/octet-stream"
|
||||
putExtra(Intent.EXTRA_TITLE, fileName)
|
||||
}
|
||||
activity.startActivityForResult(intent, Constants.THEME_BACKUP_WRITE, null)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun loadFile(activity: Activity, backupType: Constants.BackupType) {
|
||||
when (backupType) {
|
||||
Constants.BackupType.FullSystem -> {
|
||||
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
type = "*/*" // Use generic type for compatibility
|
||||
}
|
||||
if (intent.resolveActivity(activity.packageManager) == null) {
|
||||
// Show error dialog if no file picker is available
|
||||
try {
|
||||
val dialogManagerClass =
|
||||
Class.forName("com.github.gezimos.inkos.ui.dialogs.DialogManager")
|
||||
val constructor =
|
||||
dialogManagerClass.getConstructor(Context::class.java, Activity::class.java)
|
||||
val dialogManager = constructor.newInstance(activity, activity)
|
||||
val showErrorDialog = dialogManagerClass.getMethod(
|
||||
"showErrorDialog",
|
||||
Context::class.java,
|
||||
String::class.java,
|
||||
String::class.java
|
||||
)
|
||||
showErrorDialog.invoke(
|
||||
dialogManager,
|
||||
activity,
|
||||
activity.getString(R.string.error_no_file_picker_title),
|
||||
activity.getString(R.string.error_no_file_picker_message)
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
// fallback: show toast
|
||||
android.widget.Toast.makeText(
|
||||
activity,
|
||||
activity.getString(R.string.error_no_file_picker_message),
|
||||
android.widget.Toast.LENGTH_LONG
|
||||
).show()
|
||||
}
|
||||
return
|
||||
}
|
||||
activity.startActivityForResult(intent, Constants.BACKUP_READ, null)
|
||||
}
|
||||
|
||||
Constants.BackupType.Theme -> {
|
||||
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
type = "application/octet-stream"
|
||||
}
|
||||
if (intent.resolveActivity(activity.packageManager) == null) {
|
||||
try {
|
||||
val dialogManagerClass =
|
||||
Class.forName("com.github.gezimos.inkos.ui.dialogs.DialogManager")
|
||||
val constructor =
|
||||
dialogManagerClass.getConstructor(Context::class.java, Activity::class.java)
|
||||
val dialogManager = constructor.newInstance(activity, activity)
|
||||
val showErrorDialog = dialogManagerClass.getMethod(
|
||||
"showErrorDialog",
|
||||
Context::class.java,
|
||||
String::class.java,
|
||||
String::class.java
|
||||
)
|
||||
showErrorDialog.invoke(
|
||||
dialogManager,
|
||||
activity,
|
||||
activity.getString(R.string.error_no_file_picker_title),
|
||||
activity.getString(R.string.error_no_file_picker_message)
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
android.widget.Toast.makeText(
|
||||
activity,
|
||||
activity.getString(R.string.error_no_file_picker_message),
|
||||
android.widget.Toast.LENGTH_LONG
|
||||
).show()
|
||||
}
|
||||
return
|
||||
}
|
||||
activity.startActivityForResult(intent, Constants.THEME_BACKUP_READ, null)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun getHexForOpacity(prefs: Prefs): Int {
|
||||
val backgroundColor = prefs.backgroundColor
|
||||
return backgroundColor // Just return the background color without opacity modification
|
||||
}
|
||||
|
||||
fun isSystemInDarkMode(context: Context): Boolean {
|
||||
val uiModeManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager
|
||||
return uiModeManager.nightMode == UiModeManager.MODE_NIGHT_YES
|
||||
}
|
||||
|
||||
fun setThemeMode(context: Context, isDark: Boolean, view: View) {
|
||||
// Retrieve background color based on the theme
|
||||
val backgroundAttr = if (isDark) R.attr.backgroundDark else R.attr.backgroundLight
|
||||
|
||||
val typedValue = TypedValue()
|
||||
val theme: Resources.Theme = context.theme
|
||||
theme.resolveAttribute(backgroundAttr, typedValue, true)
|
||||
|
||||
// Apply the background color from styles.xml
|
||||
view.setBackgroundResource(typedValue.resourceId)
|
||||
}
|
||||
|
||||
fun parseBlacklistXML(context: Context): List<String> {
|
||||
val packageNames = mutableListOf<String>()
|
||||
|
||||
// Obtain an XmlPullParser for the blacklist.xml file
|
||||
context.resources.getXml(R.xml.blacklist).use { parser ->
|
||||
while (parser.eventType != XmlPullParser.END_DOCUMENT) {
|
||||
if (parser.eventType == XmlPullParser.START_TAG && parser.name == "app") {
|
||||
val packageName = parser.getAttributeValue(null, "packageName")
|
||||
packageNames.add(packageName)
|
||||
}
|
||||
parser.next()
|
||||
}
|
||||
}
|
||||
|
||||
return packageNames
|
||||
}
|
||||
|
||||
fun getTrueSystemFont(): Typeface {
|
||||
val possibleSystemFonts = listOf(
|
||||
"/system/fonts/Roboto-Regular.ttf", // Stock Android (Pixel, AOSP)
|
||||
"/system/fonts/NotoSans-Regular.ttf", // Some Android One devices
|
||||
"/system/fonts/SamsungOne-Regular.ttf", // Samsung
|
||||
"/system/fonts/MiSans-Regular.ttf", // Xiaomi MIUI
|
||||
"/system/fonts/OPSans-Regular.ttf" // OnePlus
|
||||
)
|
||||
|
||||
for (fontPath in possibleSystemFonts) {
|
||||
val fontFile = File(fontPath)
|
||||
if (fontFile.exists()) {
|
||||
return Typeface.createFromFile(fontFile)
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to Roboto as a default if no system font is found
|
||||
return Typeface.DEFAULT
|
||||
}
|
||||
|
||||
fun formatLongToCalendar(longTimestamp: Long): String {
|
||||
// Create a Calendar instance and set its time to the given timestamp (in milliseconds)
|
||||
val calendar = Calendar.getInstance().apply {
|
||||
timeInMillis = longTimestamp
|
||||
}
|
||||
|
||||
// Format the calendar object to a readable string
|
||||
val dateFormat = SimpleDateFormat(
|
||||
"MMMM dd, yyyy, HH:mm:ss",
|
||||
Locale.getDefault()
|
||||
) // You can modify the format
|
||||
return dateFormat.format(calendar.time) // Return the formatted date string
|
||||
}
|
||||
|
||||
fun formatMillisToHMS(millis: Long, showSeconds: Boolean): String {
|
||||
val hours = millis / (1000 * 60 * 60)
|
||||
val minutes = (millis % (1000 * 60 * 60)) / (1000 * 60)
|
||||
val seconds = (millis % (1000 * 60)) / 1000
|
||||
|
||||
val formattedString = StringBuilder()
|
||||
if (hours > 0) {
|
||||
formattedString.append("$hours h ")
|
||||
}
|
||||
if (minutes > 0 || hours > 0) {
|
||||
formattedString.append("$minutes m ")
|
||||
}
|
||||
// Only append seconds if showSeconds is true
|
||||
if (showSeconds) {
|
||||
formattedString.append("$seconds s")
|
||||
}
|
||||
|
||||
return formattedString.toString().trim()
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.github.gezimos.inkos.helper.receivers
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.BatteryManager
|
||||
import androidx.appcompat.widget.AppCompatTextView
|
||||
import com.github.gezimos.inkos.R
|
||||
import com.github.gezimos.inkos.data.Prefs
|
||||
|
||||
class BatteryReceiver : BroadcastReceiver() {
|
||||
|
||||
private lateinit var prefs: Prefs
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
prefs = Prefs(context)
|
||||
val level: Int = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)
|
||||
val scale: Int = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1)
|
||||
|
||||
val contextBattery = context as? Activity
|
||||
val batteryTextView = (contextBattery)?.findViewById<AppCompatTextView>(R.id.battery)
|
||||
|
||||
val batteryLevel = level * 100 / scale.toFloat()
|
||||
|
||||
val batteryLevelInt = batteryLevel.toInt()
|
||||
batteryTextView?.text = buildString {
|
||||
append(batteryLevelInt)
|
||||
append("%")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.github.gezimos.inkos.helper.utils
|
||||
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import com.github.gezimos.inkos.data.AppListItem
|
||||
|
||||
// DiffUtil for efficiently handling list updates
|
||||
class AppDiffCallback(
|
||||
private val oldList: List<AppListItem>,
|
||||
private val newList: List<AppListItem>
|
||||
) : DiffUtil.Callback() {
|
||||
|
||||
override fun getOldListSize(): Int = oldList.size
|
||||
|
||||
override fun getNewListSize(): Int = newList.size
|
||||
|
||||
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
|
||||
return oldList[oldItemPosition].activityPackage == newList[newItemPosition].activityPackage
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
|
||||
return oldList[oldItemPosition] == newList[newItemPosition]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.github.gezimos.inkos.helper.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
object AppReloader {
|
||||
// GlobalScope: "fire and forget", no lifecycle management
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
fun restartApp(context: Context) {
|
||||
val packageManager = context.packageManager
|
||||
val intent = packageManager.getLaunchIntentForPackage(context.packageName)
|
||||
val componentName = intent?.component
|
||||
val mainIntent = Intent.makeRestartActivityTask(componentName)
|
||||
|
||||
// Delay the restart slightly to ensure all current activities are finished
|
||||
GlobalScope.launch(Dispatchers.Main) {
|
||||
delay(500) // Suspend function, avoids `Handler`
|
||||
context.startActivity(mainIntent)
|
||||
Runtime.getRuntime().exit(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.github.gezimos.inkos.helper.utils
|
||||
|
||||
import androidx.biometric.BiometricManager
|
||||
import androidx.biometric.BiometricPrompt
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.github.gezimos.inkos.R
|
||||
import com.github.gezimos.inkos.data.AppListItem
|
||||
|
||||
class BiometricHelper(private val fragment: Fragment) {
|
||||
private lateinit var callbackApp: CallbackApp
|
||||
private lateinit var callbackSettings: CallbackSettings
|
||||
|
||||
interface CallbackApp {
|
||||
fun onAuthenticationSucceeded(appListItem: AppListItem)
|
||||
fun onAuthenticationFailed()
|
||||
fun onAuthenticationError(errorCode: Int, errorMessage: CharSequence?)
|
||||
}
|
||||
|
||||
interface CallbackSettings {
|
||||
fun onAuthenticationSucceeded()
|
||||
fun onAuthenticationFailed()
|
||||
fun onAuthenticationError(errorCode: Int, errorMessage: CharSequence?)
|
||||
}
|
||||
|
||||
fun startBiometricAuth(appListItem: AppListItem, callbackApp: CallbackApp) {
|
||||
this.callbackApp = callbackApp
|
||||
|
||||
val authenticationCallback = object : BiometricPrompt.AuthenticationCallback() {
|
||||
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
|
||||
callbackApp.onAuthenticationSucceeded(appListItem)
|
||||
}
|
||||
|
||||
override fun onAuthenticationFailed() {
|
||||
callbackApp.onAuthenticationFailed()
|
||||
}
|
||||
|
||||
override fun onAuthenticationError(errorCode: Int, errorMessage: CharSequence) {
|
||||
callbackApp.onAuthenticationError(errorCode, errorMessage)
|
||||
}
|
||||
}
|
||||
|
||||
val executor = ContextCompat.getMainExecutor(fragment.requireContext())
|
||||
val biometricPrompt = BiometricPrompt(fragment, executor, authenticationCallback)
|
||||
|
||||
val authenticators =
|
||||
BiometricManager.Authenticators.BIOMETRIC_STRONG or BiometricManager.Authenticators.DEVICE_CREDENTIAL
|
||||
val canAuthenticate =
|
||||
BiometricManager.from(fragment.requireContext()).canAuthenticate(authenticators)
|
||||
|
||||
val promptInfo = BiometricPrompt.PromptInfo.Builder()
|
||||
.setTitle(fragment.getString(R.string.text_biometric_login))
|
||||
.setSubtitle(
|
||||
fragment.getString(
|
||||
R.string.text_biometric_login_app,
|
||||
appListItem.activityLabel
|
||||
)
|
||||
)
|
||||
.setAllowedAuthenticators(authenticators)
|
||||
.setConfirmationRequired(false)
|
||||
.build()
|
||||
|
||||
if (canAuthenticate == BiometricManager.BIOMETRIC_SUCCESS) {
|
||||
biometricPrompt.authenticate(promptInfo)
|
||||
}
|
||||
}
|
||||
|
||||
fun startBiometricSettingsAuth(callbackApp: CallbackSettings) {
|
||||
this.callbackSettings = callbackApp
|
||||
|
||||
val authenticationCallback = object : BiometricPrompt.AuthenticationCallback() {
|
||||
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
|
||||
callbackSettings.onAuthenticationSucceeded()
|
||||
}
|
||||
|
||||
override fun onAuthenticationFailed() {
|
||||
callbackSettings.onAuthenticationFailed()
|
||||
}
|
||||
|
||||
override fun onAuthenticationError(errorCode: Int, errorMessage: CharSequence) {
|
||||
callbackSettings.onAuthenticationError(errorCode, errorMessage)
|
||||
}
|
||||
}
|
||||
|
||||
val executor = ContextCompat.getMainExecutor(fragment.requireContext())
|
||||
val biometricPrompt = BiometricPrompt(fragment, executor, authenticationCallback)
|
||||
|
||||
val authenticators =
|
||||
BiometricManager.Authenticators.BIOMETRIC_STRONG or BiometricManager.Authenticators.DEVICE_CREDENTIAL
|
||||
val canAuthenticate =
|
||||
BiometricManager.from(fragment.requireContext()).canAuthenticate(authenticators)
|
||||
|
||||
val promptInfo = BiometricPrompt.PromptInfo.Builder()
|
||||
.setTitle(fragment.getString(R.string.text_biometric_login))
|
||||
.setSubtitle(fragment.getString(R.string.text_biometric_login_sub))
|
||||
.setAllowedAuthenticators(authenticators)
|
||||
.setConfirmationRequired(false)
|
||||
.build()
|
||||
|
||||
if (canAuthenticate == BiometricManager.BIOMETRIC_SUCCESS) {
|
||||
biometricPrompt.authenticate(promptInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.github.gezimos.inkos.helper.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.github.gezimos.inkos.data.Prefs
|
||||
import com.github.gezimos.inkos.data.Constants
|
||||
import com.github.gezimos.inkos.helper.isSystemInDarkMode
|
||||
|
||||
object EinkRefreshHelper {
|
||||
/**
|
||||
* Triggers an E-Ink refresh by flashing an overlay on the given ViewGroup.
|
||||
* @param context Context for theme and color resolution
|
||||
* @param prefs Prefs instance for theme and refresh settings
|
||||
* @param rootView The ViewGroup to add the overlay to
|
||||
* @param delayMs How long the overlay should be visible (ms)
|
||||
* @param useActivityRoot If true, will try to add overlay to activity decorView (for fragments with Compose root)
|
||||
*/
|
||||
fun refreshEink(
|
||||
context: Context,
|
||||
prefs: Prefs,
|
||||
rootView: ViewGroup?,
|
||||
delayMs: Long = 120,
|
||||
useActivityRoot: Boolean = false
|
||||
) {
|
||||
if (!prefs.einkRefreshEnabled) return
|
||||
val isDark = when (prefs.appTheme) {
|
||||
Constants.Theme.Light -> false
|
||||
Constants.Theme.Dark -> true
|
||||
Constants.Theme.System -> isSystemInDarkMode(context)
|
||||
}
|
||||
val overlayColor = if (isDark) android.graphics.Color.WHITE else android.graphics.Color.BLACK
|
||||
val overlay = View(context)
|
||||
overlay.setBackgroundColor(overlayColor)
|
||||
overlay.layoutParams = ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
val parent = if (useActivityRoot) {
|
||||
(context as? android.app.Activity)?.window?.decorView as? ViewGroup
|
||||
} else {
|
||||
rootView
|
||||
}
|
||||
parent?.addView(overlay)
|
||||
overlay.bringToFront()
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
parent?.removeView(overlay)
|
||||
}, delayMs)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package com.github.gezimos.inkos.helper.utils
|
||||
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.os.VibrationEffect
|
||||
import android.os.Vibrator
|
||||
import android.os.VibratorManager
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.widget.ScrollView
|
||||
import androidx.core.widget.NestedScrollView
|
||||
import com.github.gezimos.inkos.data.Prefs
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
class EinkScrollBehavior(
|
||||
private val context: Context,
|
||||
private var touchThreshold: Float = 50f, // Threshold to detect significant movement
|
||||
// Scroll by full page height by default
|
||||
private var timeThresholdMs: Long = 300, // Minimum time between page turns (milliseconds)
|
||||
private val prefs: Prefs = Prefs(context) // Add Prefs for vibration preference
|
||||
) {
|
||||
private var lastY: Float = 0f
|
||||
private var startY: Float = 0f
|
||||
private var lastScrollTime: Long = 0 // Track time of last scroll action
|
||||
private var contentHeight: Int = 0
|
||||
private var viewportHeight: Int = 0
|
||||
private var hasScrolled: Boolean = false // Track if scroll has occurred in this gesture
|
||||
|
||||
// Fixed vibrator initialization
|
||||
private val vibrator = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val vibratorManager =
|
||||
context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
|
||||
vibratorManager.defaultVibrator
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
||||
}
|
||||
|
||||
fun attachToScrollView(scrollView: View) {
|
||||
when (scrollView) {
|
||||
is ScrollView -> attachToRegularScrollView(scrollView)
|
||||
is NestedScrollView -> attachToNestedScrollView(scrollView)
|
||||
}
|
||||
}
|
||||
|
||||
private fun attachToRegularScrollView(scrollView: ScrollView) {
|
||||
scrollView.isSmoothScrollingEnabled = false
|
||||
setupScrollView(scrollView)
|
||||
}
|
||||
|
||||
private fun attachToNestedScrollView(scrollView: NestedScrollView) {
|
||||
scrollView.isSmoothScrollingEnabled = false
|
||||
setupScrollView(scrollView)
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
private fun setupScrollView(view: View) {
|
||||
// Wait for layout to calculate dimensions
|
||||
view.post {
|
||||
updateDimensions(view)
|
||||
}
|
||||
|
||||
view.setOnTouchListener { v, event ->
|
||||
when (event.action) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
startY = event.y
|
||||
lastY = startY
|
||||
hasScrolled = false // Reset scroll state for new gesture
|
||||
// Update dimensions in case content has changed
|
||||
updateDimensions(view)
|
||||
true
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
if (hasScrolled) return@setOnTouchListener true // Only allow one scroll per gesture
|
||||
val deltaY = lastY - event.y
|
||||
val currentTime = System.currentTimeMillis()
|
||||
|
||||
// Only handle significant movements and respect time threshold
|
||||
if (abs(deltaY) > touchThreshold && (currentTime - lastScrollTime > timeThresholdMs)) {
|
||||
// Get current scroll position
|
||||
val currentScroll = view.scrollY
|
||||
|
||||
// Calculate overlap (20% of viewport height)
|
||||
val overlap = (viewportHeight * 0.2).toInt()
|
||||
|
||||
val maxScroll = contentHeight - viewportHeight
|
||||
|
||||
if (deltaY > 0) {
|
||||
// Scroll down
|
||||
if (currentScroll < maxScroll) {
|
||||
val nextScroll = min(
|
||||
maxScroll,
|
||||
currentScroll + viewportHeight - overlap
|
||||
)
|
||||
scrollToPosition(view, nextScroll)
|
||||
performHapticFeedback()
|
||||
lastScrollTime = currentTime
|
||||
hasScrolled = true // Mark as scrolled for this gesture
|
||||
}
|
||||
} else if (deltaY < 0) {
|
||||
// Scroll up
|
||||
if (currentScroll > 0) {
|
||||
val prevScroll = max(
|
||||
0,
|
||||
currentScroll - (viewportHeight - overlap)
|
||||
)
|
||||
// Prevent jumping to last page if already at top
|
||||
scrollToPosition(view, prevScroll)
|
||||
performHapticFeedback()
|
||||
lastScrollTime = currentTime
|
||||
hasScrolled = true // Mark as scrolled for this gesture
|
||||
}
|
||||
}
|
||||
lastY = event.y
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_UP -> {
|
||||
hasScrolled = false // Reset for next gesture
|
||||
true
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateDimensions(view: View) {
|
||||
contentHeight = when (view) {
|
||||
is ScrollView -> view.getChildAt(0)?.height ?: 0
|
||||
is NestedScrollView -> view.getChildAt(0)?.height ?: 0
|
||||
else -> 0
|
||||
}
|
||||
viewportHeight = view.height
|
||||
}
|
||||
|
||||
private fun scrollToPosition(view: View, targetY: Int) {
|
||||
// Ensure we don't scroll outside content bounds
|
||||
val boundedTargetY = when (view) {
|
||||
is ScrollView -> {
|
||||
val maxScroll = getMaxScrollY(view)
|
||||
targetY.coerceIn(0, maxScroll)
|
||||
}
|
||||
|
||||
is NestedScrollView -> {
|
||||
val maxScroll = getMaxScrollY(view)
|
||||
targetY.coerceIn(0, maxScroll)
|
||||
}
|
||||
|
||||
else -> targetY
|
||||
}
|
||||
|
||||
// Apply the scroll without any animation
|
||||
when (view) {
|
||||
is ScrollView -> view.scrollTo(0, boundedTargetY)
|
||||
is NestedScrollView -> view.scrollTo(0, boundedTargetY)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getMaxScrollY(view: View): Int {
|
||||
updateDimensions(view)
|
||||
return max(0, contentHeight - viewportHeight)
|
||||
}
|
||||
|
||||
private fun performHapticFeedback() {
|
||||
if (!prefs.useVibrationForPaging) return
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
if (context.checkSelfPermission(Manifest.permission.VIBRATE) == PackageManager.PERMISSION_GRANTED) {
|
||||
vibrator.vibrate(VibrationEffect.createOneShot(30, VibrationEffect.DEFAULT_AMPLITUDE))
|
||||
}
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
vibrator.vibrate(30)
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
// Silently handle any vibration-related errors
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
package com.github.gezimos.inkos.helper.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
import android.text.SpannableStringBuilder
|
||||
import android.text.style.AbsoluteSizeSpan
|
||||
import android.text.style.SuperscriptSpan
|
||||
import android.widget.TextView
|
||||
import com.github.gezimos.inkos.data.Prefs
|
||||
import com.github.gezimos.inkos.services.NotificationManager
|
||||
|
||||
object NotificationBadgeUtil {
|
||||
fun updateNotificationForView(
|
||||
context: Context,
|
||||
prefs: Prefs,
|
||||
textView: TextView,
|
||||
notifications: Map<String, NotificationManager.NotificationInfo>
|
||||
) {
|
||||
val appModel = prefs.getHomeAppModel(textView.id)
|
||||
val packageName = appModel.activityPackage
|
||||
val notificationInfo = notifications[packageName]
|
||||
// Filtering is now handled in NotificationManager, so no need to filter here
|
||||
val customLabel = prefs.getAppAlias("app_alias_$packageName")
|
||||
val displayName = if (customLabel.isNotEmpty()) customLabel else appModel.activityLabel
|
||||
|
||||
// Filter out unwanted Signal (or similar) system messages
|
||||
val unwantedMessages =
|
||||
listOf("background connection established", "background connection enabled")
|
||||
val isUnwanted = notificationInfo != null && (
|
||||
(notificationInfo.title?.trim()?.let {
|
||||
unwantedMessages.any { msg ->
|
||||
it.equals(
|
||||
msg,
|
||||
ignoreCase = true
|
||||
)
|
||||
}
|
||||
} == true) ||
|
||||
(notificationInfo.text?.trim()?.let {
|
||||
unwantedMessages.any { msg ->
|
||||
it.equals(
|
||||
msg,
|
||||
ignoreCase = true
|
||||
)
|
||||
}
|
||||
} == true)
|
||||
)
|
||||
|
||||
if (notificationInfo != null && prefs.showNotificationBadge && !isUnwanted) {
|
||||
val spanBuilder = SpannableStringBuilder()
|
||||
|
||||
// Add app name with apps font - use universal font logic
|
||||
val appFont = prefs.getFontForContext("apps")
|
||||
.getFont(context, prefs.getCustomFontPathForContext("apps"))
|
||||
val appNameSpan = SpannableString(displayName)
|
||||
if (appFont != null) {
|
||||
appNameSpan.setSpan(
|
||||
CustomTypefaceSpan(appFont),
|
||||
0,
|
||||
displayName.length,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
)
|
||||
}
|
||||
spanBuilder.append(appNameSpan)
|
||||
|
||||
val title = notificationInfo.title
|
||||
val text = notificationInfo.text
|
||||
val isMedia = notificationInfo.category == android.app.Notification.CATEGORY_TRANSPORT
|
||||
val isMediaPlaying = isMedia && (!title.isNullOrBlank() || !text.isNullOrBlank())
|
||||
|
||||
// Only show asterisk or music note if not media, or if media is actually playing
|
||||
if (isMedia && isMediaPlaying && prefs.showMediaIndicator) {
|
||||
// Music note as superscript (exponent)
|
||||
val musicNote = SpannableString("\u266A")
|
||||
musicNote.setSpan(
|
||||
SuperscriptSpan(),
|
||||
0,
|
||||
musicNote.length,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
)
|
||||
musicNote.setSpan(
|
||||
AbsoluteSizeSpan((textView.textSize * 0.8).toInt()),
|
||||
0,
|
||||
musicNote.length,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
)
|
||||
spanBuilder.append(musicNote)
|
||||
} else if (!isMedia && notificationInfo.count > 0) {
|
||||
// Asterisk as superscript (already styled)
|
||||
spanBuilder.append(" *")
|
||||
}
|
||||
|
||||
// Notification text logic
|
||||
if (isMedia && isMediaPlaying && prefs.showMediaName) {
|
||||
// For media, show only the first part (title or artist), not the full name
|
||||
spanBuilder.append("\n")
|
||||
val charLimit = prefs.homeAppCharLimit
|
||||
// Split by common separators and take the first part
|
||||
val firstPart = title?.split(" - ", ":", "|")?.firstOrNull()?.trim() ?: ""
|
||||
val notifText =
|
||||
if (!firstPart.isNullOrBlank() && firstPart.lowercase() != "transport") firstPart.take(
|
||||
charLimit
|
||||
) else ""
|
||||
val notifSpan = SpannableString(notifText)
|
||||
notifSpan.setSpan(
|
||||
AbsoluteSizeSpan(prefs.labelnotificationsTextSize, true),
|
||||
0,
|
||||
notifText.length,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
)
|
||||
val notificationFont = prefs.getFontForContext("notification")
|
||||
.getFont(context, prefs.getCustomFontPathForContext("notification"))
|
||||
if (notificationFont != null) {
|
||||
notifSpan.setSpan(
|
||||
CustomTypefaceSpan(notificationFont),
|
||||
0,
|
||||
notifText.length,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
)
|
||||
}
|
||||
spanBuilder.append(notifSpan)
|
||||
} else if (!isMedia && prefs.showNotificationText && (!title.isNullOrBlank() || !text.isNullOrBlank())) {
|
||||
// For messaging/other notifications, apply toggles
|
||||
spanBuilder.append("\n")
|
||||
val charLimit = prefs.homeAppCharLimit
|
||||
val showName = prefs.showNotificationSenderName
|
||||
val showGroup = prefs.showNotificationGroupName
|
||||
val showMessage = prefs.showNotificationMessage
|
||||
|
||||
// Parse sender and group from title, avoid duplication
|
||||
var sender = ""
|
||||
var group = ""
|
||||
if (!title.isNullOrBlank()) {
|
||||
val parts = title.split(": ", limit = 2)
|
||||
if (packageName == "org.thoughtcrime.securesms") { // Signal
|
||||
if (parts.size == 1) {
|
||||
// Single-person conversation: treat as sender
|
||||
sender = parts[0]
|
||||
group = ""
|
||||
} else {
|
||||
group = parts.getOrNull(0) ?: ""
|
||||
sender = parts.getOrNull(1) ?: ""
|
||||
// If group is empty or same as sender, treat as single-person
|
||||
if (group.isBlank() || group == sender) {
|
||||
sender = group
|
||||
group = ""
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sender = parts.getOrNull(0) ?: ""
|
||||
group = parts.getOrNull(1) ?: ""
|
||||
}
|
||||
}
|
||||
// If group is same as sender, don't show group
|
||||
if (group == sender) group = ""
|
||||
|
||||
val message = if (showMessage) text ?: "" else ""
|
||||
val notifText = buildString {
|
||||
if (showName && sender.isNotBlank()) append(sender)
|
||||
if (showGroup && group.isNotBlank()) {
|
||||
if (isNotEmpty()) append(": ")
|
||||
append(group)
|
||||
}
|
||||
if (showMessage && message.isNotBlank()) {
|
||||
if (isNotEmpty()) append(": ")
|
||||
append(message)
|
||||
}
|
||||
}.take(charLimit)
|
||||
val notifSpan = SpannableString(notifText)
|
||||
notifSpan.setSpan(
|
||||
AbsoluteSizeSpan(prefs.labelnotificationsTextSize, true),
|
||||
0,
|
||||
notifText.length,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
)
|
||||
val notificationFont = prefs.getFontForContext("notification")
|
||||
.getFont(context, prefs.getCustomFontPathForContext("notification"))
|
||||
if (notificationFont != null) {
|
||||
notifSpan.setSpan(
|
||||
CustomTypefaceSpan(notificationFont),
|
||||
0,
|
||||
notifText.length,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
)
|
||||
}
|
||||
spanBuilder.append(notifSpan)
|
||||
}
|
||||
|
||||
textView.text = spanBuilder
|
||||
} else {
|
||||
textView.text = displayName
|
||||
textView.typeface = prefs.getFontForContext("apps")
|
||||
.getFont(context, prefs.getCustomFontPathForContext("apps"))
|
||||
}
|
||||
}
|
||||
|
||||
// CustomTypefaceSpan copied from HomeFragment for reuse
|
||||
private class CustomTypefaceSpan(private val typeface: android.graphics.Typeface) :
|
||||
android.text.style.TypefaceSpan("") {
|
||||
override fun updateDrawState(ds: android.text.TextPaint) {
|
||||
ds.typeface = typeface
|
||||
}
|
||||
|
||||
override fun updateMeasureState(paint: android.text.TextPaint) {
|
||||
paint.typeface = typeface
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
package com.github.gezimos.inkos.helper.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.pm.LauncherApps
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.UserHandle
|
||||
import android.os.UserManager
|
||||
import android.util.Log
|
||||
import com.github.gezimos.common.showLongToast
|
||||
import com.github.gezimos.inkos.R
|
||||
import com.github.gezimos.inkos.helper.isinkosDefault
|
||||
import com.github.gezimos.inkos.helper.setDefaultHomeScreen
|
||||
|
||||
class PrivateSpaceManager(private val context: Context) {
|
||||
|
||||
/**
|
||||
* Checks whether the device supports private space.
|
||||
*/
|
||||
fun isPrivateSpaceSupported(): Boolean {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the private space user if available.
|
||||
*/
|
||||
private fun getPrivateSpaceUser(): UserHandle? {
|
||||
if (!isPrivateSpaceSupported()) {
|
||||
return null
|
||||
}
|
||||
val userManager = context.getSystemService(Context.USER_SERVICE) as UserManager
|
||||
val launcherApps = context.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
|
||||
return userManager.userProfiles.firstOrNull { u ->
|
||||
launcherApps.getLauncherUserInfo(u)?.userType == UserManager.USER_TYPE_PROFILE_PRIVATE
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given user profile is the private space.
|
||||
*/
|
||||
fun isPrivateSpaceProfile(userHandle: UserHandle): Boolean {
|
||||
if (!isPrivateSpaceSupported()) {
|
||||
return false
|
||||
}
|
||||
|
||||
val launcherApps = context.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
|
||||
try {
|
||||
val userType = launcherApps.getLauncherUserInfo(userHandle)?.userType
|
||||
return userType == UserManager.USER_TYPE_PROFILE_PRIVATE
|
||||
} catch (e: Exception) {
|
||||
Log.e("PrivateSpace", "Failed to retrieve launcher user info", e)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the user has created a private space and whether mLauncher can access it.
|
||||
*/
|
||||
fun isPrivateSpaceSetUp(
|
||||
showToast: Boolean = false,
|
||||
launchSettings: Boolean = false
|
||||
): Boolean {
|
||||
if (!isPrivateSpaceSupported()) {
|
||||
if (showToast) {
|
||||
context.showLongToast(context.getString(R.string.alert_requires_android_v))
|
||||
}
|
||||
return false
|
||||
}
|
||||
val privateSpaceUser = getPrivateSpaceUser()
|
||||
if (privateSpaceUser != null) {
|
||||
return true
|
||||
}
|
||||
if (!isinkosDefault(context)) {
|
||||
if (showToast) {
|
||||
context.showLongToast(context.getString(R.string.toast_private_space_default_home_screen))
|
||||
}
|
||||
if (launchSettings) {
|
||||
setDefaultHomeScreen(context)
|
||||
}
|
||||
} else {
|
||||
if (showToast) {
|
||||
context.showLongToast(context.getString(R.string.toast_private_space_not_available))
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the private space is locked.
|
||||
*/
|
||||
fun isPrivateSpaceLocked(): Boolean {
|
||||
if (!isPrivateSpaceSupported()) {
|
||||
return false
|
||||
}
|
||||
val userManager = context.getSystemService(Context.USER_SERVICE) as UserManager
|
||||
val privateSpaceUser = getPrivateSpaceUser() ?: return false
|
||||
return userManager.isQuietModeEnabled(privateSpaceUser)
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock or unlock the private space.
|
||||
*/
|
||||
private fun lockPrivateSpace(lock: Boolean) {
|
||||
if (!isPrivateSpaceSupported()) {
|
||||
return
|
||||
}
|
||||
val userManager = context.getSystemService(Context.USER_SERVICE) as UserManager
|
||||
val privateSpaceUser = getPrivateSpaceUser() ?: return
|
||||
userManager.requestQuietModeEnabled(lock, privateSpaceUser)
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the lock state of the private space.
|
||||
*/
|
||||
fun togglePrivateSpaceLock(showToast: Boolean, launchSettings: Boolean) {
|
||||
if (!isPrivateSpaceSetUp(showToast, launchSettings)) {
|
||||
return
|
||||
}
|
||||
if (!isinkosDefault(context)) {
|
||||
context.showLongToast(context.getString(R.string.toast_private_space_default_home_screen))
|
||||
return
|
||||
}
|
||||
|
||||
val lock = isPrivateSpaceLocked()
|
||||
lockPrivateSpace(!lock)
|
||||
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
if (isPrivateSpaceLocked() == !lock) {
|
||||
context.showLongToast(context.getString(R.string.toast_private_space_locked))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
package com.github.gezimos.inkos.helper.utils
|
||||
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import androidx.core.net.toUri
|
||||
|
||||
class SimpleEmailSender {
|
||||
|
||||
fun sendCrashReport(
|
||||
context: Context,
|
||||
crashReportContent: String,
|
||||
crashReportAttachments: List<Uri>,
|
||||
subject: String,
|
||||
emailRecipient: String
|
||||
) {
|
||||
sendWithSelector(
|
||||
subject,
|
||||
crashReportContent,
|
||||
crashReportAttachments,
|
||||
context,
|
||||
emailRecipient
|
||||
)
|
||||
}
|
||||
|
||||
private fun resolveAndSend(
|
||||
subject: String,
|
||||
body: String,
|
||||
attachments: List<Uri>,
|
||||
context: Context,
|
||||
emailRecipient: String
|
||||
) {
|
||||
val pm = context.packageManager
|
||||
val resolveIntent = buildResolveIntent()
|
||||
val resolveActivity = resolveIntent.resolveActivity(pm)
|
||||
|
||||
if (resolveActivity != null) {
|
||||
if (attachments.isEmpty()) {
|
||||
// No attachments, send directly
|
||||
context.startActivity(buildFallbackIntent(subject, body, emailRecipient))
|
||||
} else {
|
||||
val attachmentIntent =
|
||||
buildAttachmentIntent(subject, body, attachments, emailRecipient)
|
||||
val altAttachmentIntent = Intent(attachmentIntent).apply {
|
||||
type = "*/*"
|
||||
} // To match Gmail's attachment expectations
|
||||
val initialIntents = buildInitialIntents(pm, resolveIntent, attachmentIntent)
|
||||
val packageName = getPackageName(resolveActivity, initialIntents)
|
||||
|
||||
attachmentIntent.setPackage(packageName)
|
||||
altAttachmentIntent.setPackage(packageName)
|
||||
|
||||
when {
|
||||
packageName == null -> {
|
||||
// Let user choose email client
|
||||
showChooser(context, initialIntents)
|
||||
}
|
||||
|
||||
attachmentIntent.resolveActivity(pm) != null -> {
|
||||
// Use default email client
|
||||
context.startActivity(attachmentIntent)
|
||||
}
|
||||
|
||||
altAttachmentIntent.resolveActivity(pm) != null -> {
|
||||
// Use default email client with alternative attachment type
|
||||
context.startActivity(altAttachmentIntent)
|
||||
}
|
||||
|
||||
else -> {
|
||||
// No email client found, fallback
|
||||
context.startActivity(buildFallbackIntent(subject, body, emailRecipient))
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw ActivityNotFoundException("No email client found")
|
||||
}
|
||||
}
|
||||
|
||||
private fun sendWithSelector(
|
||||
subject: String,
|
||||
body: String,
|
||||
attachments: List<Uri>,
|
||||
context: Context,
|
||||
emailRecipient: String
|
||||
) {
|
||||
val intent = if (attachments.size == 1) {
|
||||
buildSingleAttachmentIntent(subject, body, attachments.first(), emailRecipient)
|
||||
} else {
|
||||
buildAttachmentIntent(subject, body, attachments, emailRecipient)
|
||||
}
|
||||
intent.selector = buildResolveIntent()
|
||||
try {
|
||||
context.startActivity(intent)
|
||||
} catch (_: ActivityNotFoundException) {
|
||||
resolveAndSend(subject, body, attachments, context, emailRecipient)
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildAttachmentIntent(
|
||||
subject: String,
|
||||
body: String,
|
||||
attachments: List<Uri>,
|
||||
emailRecipient: String
|
||||
): Intent {
|
||||
val intent = Intent(Intent.ACTION_SEND_MULTIPLE)
|
||||
intent.putExtra(Intent.EXTRA_EMAIL, arrayOf(emailRecipient))
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, subject)
|
||||
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, ArrayList(attachments))
|
||||
intent.putExtra(Intent.EXTRA_TEXT, body)
|
||||
return intent
|
||||
}
|
||||
|
||||
private fun buildSingleAttachmentIntent(
|
||||
subject: String,
|
||||
body: String,
|
||||
attachment: Uri,
|
||||
emailRecipient: String
|
||||
): Intent {
|
||||
val intent = Intent(Intent.ACTION_SEND)
|
||||
intent.putExtra(Intent.EXTRA_EMAIL, arrayOf(emailRecipient))
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, subject)
|
||||
intent.putExtra(Intent.EXTRA_STREAM, attachment)
|
||||
intent.putExtra(Intent.EXTRA_TEXT, body)
|
||||
return intent
|
||||
}
|
||||
|
||||
private fun buildResolveIntent(): Intent {
|
||||
val intent = Intent(Intent.ACTION_SENDTO)
|
||||
intent.data = "mailto:".toUri()
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
return intent
|
||||
}
|
||||
|
||||
private fun buildFallbackIntent(subject: String, body: String, emailRecipient: String): Intent {
|
||||
val intent = Intent(Intent.ACTION_SENDTO)
|
||||
intent.data =
|
||||
"mailto:${emailRecipient}?subject=${Uri.encode(subject)}&body=${Uri.encode(body)}".toUri()
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, subject)
|
||||
intent.putExtra(Intent.EXTRA_TEXT, body)
|
||||
return intent
|
||||
}
|
||||
|
||||
private fun buildInitialIntents(
|
||||
pm: PackageManager,
|
||||
resolveIntent: Intent,
|
||||
emailIntent: Intent
|
||||
): List<Intent> {
|
||||
val resolveInfoList =
|
||||
pm.queryIntentActivities(resolveIntent, PackageManager.MATCH_DEFAULT_ONLY)
|
||||
val initialIntents = mutableListOf<Intent>()
|
||||
for (info in resolveInfoList) {
|
||||
val packageSpecificIntent = Intent(emailIntent)
|
||||
packageSpecificIntent.setPackage(info.activityInfo.packageName)
|
||||
if (packageSpecificIntent.resolveActivity(pm) != null) {
|
||||
initialIntents.add(packageSpecificIntent)
|
||||
continue
|
||||
}
|
||||
packageSpecificIntent.setClassName(
|
||||
info.activityInfo.packageName,
|
||||
info.activityInfo.name
|
||||
)
|
||||
if (packageSpecificIntent.resolveActivity(pm) != null) {
|
||||
initialIntents.add(packageSpecificIntent)
|
||||
}
|
||||
}
|
||||
return initialIntents
|
||||
}
|
||||
|
||||
private fun showChooser(context: Context, initialIntents: List<Intent>) {
|
||||
val chooser = Intent(Intent.ACTION_CHOOSER)
|
||||
chooser.putExtra(Intent.EXTRA_INTENT, initialIntents.first())
|
||||
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, initialIntents.toTypedArray())
|
||||
chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
context.startActivity(chooser)
|
||||
}
|
||||
|
||||
private fun getPackageName(
|
||||
resolveActivity: ComponentName,
|
||||
initialIntents: List<Intent>
|
||||
): String? {
|
||||
var packageName: String? = resolveActivity.packageName
|
||||
if (packageName == "android") {
|
||||
if (initialIntents.size > 1) {
|
||||
packageName = null
|
||||
} else if (initialIntents.size == 1) {
|
||||
packageName = initialIntents[0].`package`
|
||||
}
|
||||
}
|
||||
return packageName
|
||||
}
|
||||
}
|
||||
55
app/src/main/java/com/github/gezimos/inkos/inkOS.kt
Normal file
55
app/src/main/java/com/github/gezimos/inkos/inkOS.kt
Normal file
@@ -0,0 +1,55 @@
|
||||
package com.github.gezimos.inkos
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.graphics.Typeface
|
||||
import android.util.Log
|
||||
import com.github.gezimos.common.CrashHandler
|
||||
import com.github.gezimos.inkos.data.Prefs
|
||||
|
||||
class inkOS : Application() {
|
||||
private lateinit var prefs: Prefs
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
// Initialize com.github.gezimos.common.CrashHandler to catch uncaught exceptions
|
||||
Thread.setDefaultUncaughtExceptionHandler(CrashHandler(applicationContext))
|
||||
|
||||
// Initialize prefs here
|
||||
prefs = Prefs(applicationContext)
|
||||
|
||||
setCustomFont(applicationContext)
|
||||
|
||||
// Log app launch
|
||||
CrashHandler.logUserAction("App Launched")
|
||||
}
|
||||
|
||||
|
||||
private fun setCustomFont(context: Context) {
|
||||
// Load the custom font from resources
|
||||
val customFont = prefs.fontFamily.getFont(context)
|
||||
|
||||
// Apply the custom font to different font families
|
||||
if (customFont != null) {
|
||||
TypefaceUtil.setDefaultFont("DEFAULT", customFont)
|
||||
TypefaceUtil.setDefaultFont("MONOSPACE", customFont)
|
||||
TypefaceUtil.setDefaultFont("SERIF", customFont)
|
||||
TypefaceUtil.setDefaultFont("SANS_SERIF", customFont)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object TypefaceUtil {
|
||||
|
||||
fun setDefaultFont(staticTypefaceFieldName: String, fontAssetName: Typeface) {
|
||||
Log.e("setDefaultFont", "$staticTypefaceFieldName | $fontAssetName")
|
||||
try {
|
||||
val staticField = Typeface::class.java.getDeclaredField(staticTypefaceFieldName)
|
||||
staticField.isAccessible = true
|
||||
staticField.set(null, fontAssetName)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.github.gezimos.inkos.listener
|
||||
|
||||
import android.app.admin.DeviceAdminReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.widget.Toast
|
||||
import com.github.gezimos.inkos.R
|
||||
|
||||
|
||||
class DeviceAdmin : DeviceAdminReceiver() {
|
||||
override fun onEnabled(context: Context, intent: Intent) {
|
||||
super.onEnabled(context, intent)
|
||||
Toast.makeText(context, context.getString(R.string.enabled), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
override fun onDisabled(context: Context, intent: Intent) {
|
||||
super.onDisabled(context, intent)
|
||||
Toast.makeText(context, context.getString(R.string.disabled), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.github.gezimos.inkos.listener
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.view.GestureDetector
|
||||
import android.view.GestureDetector.SimpleOnGestureListener
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.View.OnTouchListener
|
||||
import com.github.gezimos.inkos.data.Constants
|
||||
import java.util.Timer
|
||||
import kotlin.concurrent.schedule
|
||||
import kotlin.math.abs
|
||||
|
||||
/*
|
||||
Swipe, double tap and long press touch listener for a view
|
||||
Source: https://www.tutorialspoint.com/how-to-handle-swipe-gestures-in-kotlin
|
||||
*/
|
||||
|
||||
internal open class OnSwipeTouchListener(c: Context?) : OnTouchListener {
|
||||
private var longPressOn = false
|
||||
private var doubleTapOn = false
|
||||
private val gestureDetector: GestureDetector
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onTouch(view: View, motionEvent: MotionEvent): Boolean {
|
||||
if (motionEvent.action == MotionEvent.ACTION_UP)
|
||||
longPressOn = false
|
||||
return gestureDetector.onTouchEvent(motionEvent)
|
||||
}
|
||||
|
||||
private inner class GestureListener : SimpleOnGestureListener() {
|
||||
private val swipeThreshold: Int = 100
|
||||
private val swipeVelocityThreshold: Int = 100
|
||||
|
||||
override fun onDown(e: MotionEvent): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onSingleTapUp(e: MotionEvent): Boolean {
|
||||
if (doubleTapOn) {
|
||||
doubleTapOn = false
|
||||
onTripleClick()
|
||||
}
|
||||
return super.onSingleTapUp(e)
|
||||
}
|
||||
|
||||
override fun onDoubleTap(e: MotionEvent): Boolean {
|
||||
doubleTapOn = true
|
||||
Timer().schedule(Constants.TRIPLE_TAP_DELAY_MS.toLong()) {
|
||||
if (doubleTapOn) {
|
||||
doubleTapOn = false
|
||||
onDoubleClick()
|
||||
}
|
||||
}
|
||||
return super.onDoubleTap(e)
|
||||
}
|
||||
|
||||
override fun onLongPress(e: MotionEvent) {
|
||||
longPressOn = true
|
||||
Timer().schedule(Constants.LONG_PRESS_DELAY_MS.toLong()) {
|
||||
if (longPressOn) onLongClick()
|
||||
}
|
||||
super.onLongPress(e)
|
||||
}
|
||||
|
||||
override fun onFling(
|
||||
event1: MotionEvent?,
|
||||
event2: MotionEvent,
|
||||
velocityX: Float,
|
||||
velocityY: Float
|
||||
): Boolean {
|
||||
try {
|
||||
val diffY = event2.y - event1!!.y
|
||||
val diffX = event2.x - event1.x
|
||||
if (abs(diffX) > abs(diffY)) {
|
||||
if (abs(diffX) > swipeThreshold && abs(velocityX) > swipeVelocityThreshold) {
|
||||
if (diffX > 0) onSwipeRight() else onSwipeLeft()
|
||||
}
|
||||
} else {
|
||||
if (abs(diffY) > swipeThreshold && abs(velocityY) > swipeVelocityThreshold) {
|
||||
if (diffY < 0) onSwipeUp() else onSwipeDown()
|
||||
}
|
||||
}
|
||||
} catch (exception: Exception) {
|
||||
exception.printStackTrace()
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
open fun onSwipeRight() {}
|
||||
open fun onSwipeLeft() {}
|
||||
open fun onSwipeUp() {}
|
||||
open fun onSwipeDown() {}
|
||||
open fun onLongClick() {}
|
||||
open fun onDoubleClick() {}
|
||||
open fun onTripleClick() {}
|
||||
open fun onLongSwipe(direction: String) {}
|
||||
|
||||
init {
|
||||
gestureDetector = GestureDetector(c, GestureListener())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.github.gezimos.inkos.listener
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.view.GestureDetector
|
||||
import android.view.GestureDetector.SimpleOnGestureListener
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.View.OnTouchListener
|
||||
import kotlin.math.abs
|
||||
|
||||
internal open class ViewSwipeTouchListener(c: Context?, v: View) : OnTouchListener {
|
||||
private val gestureDetector: GestureDetector = GestureDetector(c, GestureListener(v))
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onTouch(view: View, motionEvent: MotionEvent): Boolean {
|
||||
when (motionEvent.action) {
|
||||
MotionEvent.ACTION_DOWN -> view.isPressed = true
|
||||
MotionEvent.ACTION_UP -> view.isPressed = false
|
||||
}
|
||||
return gestureDetector.onTouchEvent(motionEvent)
|
||||
}
|
||||
|
||||
private inner class GestureListener(private val view: View) : SimpleOnGestureListener() {
|
||||
private val swipeThreshold: Int = 100
|
||||
private val swipeVelocityThreshold: Int = 100
|
||||
|
||||
override fun onDown(e: MotionEvent): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onSingleTapUp(e: MotionEvent): Boolean {
|
||||
onClick(view)
|
||||
return super.onSingleTapUp(e)
|
||||
}
|
||||
|
||||
override fun onDoubleTap(e: MotionEvent): Boolean {
|
||||
onDoubleClick()
|
||||
return super.onDoubleTap(e)
|
||||
}
|
||||
|
||||
override fun onLongPress(e: MotionEvent) {
|
||||
onLongClick(view)
|
||||
super.onLongPress(e)
|
||||
}
|
||||
|
||||
override fun onFling(
|
||||
event1: MotionEvent?,
|
||||
event2: MotionEvent,
|
||||
velocityX: Float,
|
||||
velocityY: Float
|
||||
): Boolean {
|
||||
try {
|
||||
val diffY = event2.y - event1!!.y
|
||||
val diffX = event2.x - event1.x
|
||||
if (abs(diffX) > abs(diffY)) {
|
||||
if (abs(diffX) > swipeThreshold && abs(velocityX) > swipeVelocityThreshold) {
|
||||
if (diffX > 0) onSwipeRight() else onSwipeLeft()
|
||||
}
|
||||
} else {
|
||||
if (abs(diffY) > swipeThreshold && abs(velocityY) > swipeVelocityThreshold) {
|
||||
if (diffY < 0) onSwipeUp() else onSwipeDown()
|
||||
}
|
||||
}
|
||||
} catch (exception: Exception) {
|
||||
exception.printStackTrace()
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
open fun onSwipeRight() {}
|
||||
open fun onSwipeLeft() {}
|
||||
open fun onSwipeUp() {}
|
||||
open fun onSwipeDown() {}
|
||||
open fun onLongClick(view: View) {}
|
||||
open fun onDoubleClick() {}
|
||||
open fun onClick(view: View) {}
|
||||
open fun onLongSwipe(direction: String) {}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.github.gezimos.inkos.services
|
||||
|
||||
import android.accessibilityservice.AccessibilityService
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.view.accessibility.AccessibilityEvent
|
||||
import androidx.annotation.RequiresApi
|
||||
import com.github.gezimos.common.CrashHandler
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
class ActionService : AccessibilityService() {
|
||||
|
||||
override fun onServiceConnected() {
|
||||
instance = WeakReference(this)
|
||||
}
|
||||
|
||||
override fun onUnbind(intent: Intent?): Boolean {
|
||||
instance = WeakReference(null)
|
||||
return super.onUnbind(intent)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
fun lockScreen(): Boolean {
|
||||
CrashHandler.logUserAction("Lock Screen")
|
||||
return performGlobalAction(GLOBAL_ACTION_LOCK_SCREEN)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
fun showRecents(): Boolean {
|
||||
CrashHandler.logUserAction("Show Recents")
|
||||
return performGlobalAction(GLOBAL_ACTION_RECENTS)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
fun openNotifications(): Boolean {
|
||||
CrashHandler.logUserAction("Open Notifications")
|
||||
return performGlobalAction(GLOBAL_ACTION_NOTIFICATIONS)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
fun openQuickSettings(): Boolean {
|
||||
CrashHandler.logUserAction("Open Quick Settings")
|
||||
return performGlobalAction(GLOBAL_ACTION_QUICK_SETTINGS)
|
||||
}
|
||||
|
||||
fun openPowerDialog(): Boolean {
|
||||
CrashHandler.logUserAction("Open Power Dialog")
|
||||
return performGlobalAction(GLOBAL_ACTION_POWER_DIALOG)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
fun takeScreenShot(): Boolean {
|
||||
CrashHandler.logUserAction("Take Screen Shot")
|
||||
return performGlobalAction(GLOBAL_ACTION_TAKE_SCREENSHOT)
|
||||
}
|
||||
|
||||
override fun onAccessibilityEvent(event: AccessibilityEvent?) {}
|
||||
override fun onInterrupt() {}
|
||||
|
||||
companion object {
|
||||
private var instance: WeakReference<ActionService> = WeakReference(null)
|
||||
|
||||
fun instance(): ActionService? {
|
||||
return instance.get()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
package com.github.gezimos.inkos.services
|
||||
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import java.io.File
|
||||
|
||||
class NotificationManager private constructor(private val context: Context) {
|
||||
data class NotificationInfo(
|
||||
val count: Int,
|
||||
val title: String?,
|
||||
val text: String?,
|
||||
val category: String?
|
||||
)
|
||||
|
||||
data class ConversationNotification(
|
||||
val conversationId: String,
|
||||
val conversationTitle: String?,
|
||||
val sender: String?,
|
||||
val message: String?,
|
||||
val timestamp: Long,
|
||||
val category: String? = null
|
||||
)
|
||||
|
||||
private val notificationInfo = mutableMapOf<String, NotificationInfo>()
|
||||
private val _notificationInfoLiveData = MutableLiveData<Map<String, NotificationInfo>>()
|
||||
val notificationInfoLiveData: LiveData<Map<String, NotificationInfo>> =
|
||||
_notificationInfoLiveData
|
||||
|
||||
private val conversationNotifications =
|
||||
mutableMapOf<String, MutableMap<String, ConversationNotification>>()
|
||||
private val _conversationNotificationsLiveData =
|
||||
MutableLiveData<Map<String, List<ConversationNotification>>>()
|
||||
val conversationNotificationsLiveData: LiveData<Map<String, List<ConversationNotification>>> =
|
||||
_conversationNotificationsLiveData
|
||||
|
||||
private val NOTIF_SAVE_FILE = "mlauncher_notifications.json"
|
||||
|
||||
companion object {
|
||||
@Volatile
|
||||
private var INSTANCE: NotificationManager? = null
|
||||
fun getInstance(context: Context): NotificationManager {
|
||||
return INSTANCE ?: synchronized(this) {
|
||||
INSTANCE ?: NotificationManager(context.applicationContext).also { INSTANCE = it }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getBadgeNotifications(): Map<String, NotificationInfo> {
|
||||
// Only filter by badge allowlist
|
||||
val prefs = com.github.gezimos.inkos.data.Prefs(context)
|
||||
val allowed = prefs.allowedBadgeNotificationApps
|
||||
return if (allowed.isEmpty()) {
|
||||
notificationInfo.toMap()
|
||||
} else {
|
||||
notificationInfo.filter { (pkg, _) -> pkg in allowed }
|
||||
}
|
||||
}
|
||||
|
||||
fun updateBadgeNotification(packageName: String, info: NotificationInfo?) {
|
||||
if (info == null) {
|
||||
notificationInfo.remove(packageName)
|
||||
} else {
|
||||
notificationInfo[packageName] = info
|
||||
}
|
||||
// Only filter by badge allowlist
|
||||
val prefs = com.github.gezimos.inkos.data.Prefs(context)
|
||||
val allowed = prefs.allowedBadgeNotificationApps
|
||||
val filtered = if (allowed.isEmpty()) {
|
||||
notificationInfo.toMap()
|
||||
} else {
|
||||
notificationInfo.filter { (pkg, _) -> pkg in allowed }
|
||||
}
|
||||
_notificationInfoLiveData.postValue(filtered)
|
||||
}
|
||||
|
||||
fun getConversationNotifications(): Map<String, List<ConversationNotification>> {
|
||||
// Only filter by allowlist
|
||||
val prefs = com.github.gezimos.inkos.data.Prefs(context)
|
||||
val allowed = prefs.allowedNotificationApps
|
||||
return conversationNotifications
|
||||
.filter { (pkg, _) -> allowed.isEmpty() || pkg in allowed }
|
||||
.mapValues { entry ->
|
||||
entry.value.values.sortedByDescending { n -> n.timestamp }
|
||||
}
|
||||
}
|
||||
|
||||
fun updateConversationNotification(
|
||||
packageName: String,
|
||||
conversation: ConversationNotification
|
||||
) {
|
||||
val appMap = conversationNotifications.getOrPut(packageName) { mutableMapOf() }
|
||||
appMap[conversation.conversationId] = conversation
|
||||
_conversationNotificationsLiveData.postValue(getConversationNotifications())
|
||||
saveConversationNotifications()
|
||||
}
|
||||
|
||||
fun removeConversationNotification(packageName: String, conversationId: String) {
|
||||
val appMap = conversationNotifications[packageName]
|
||||
if (appMap != null) {
|
||||
appMap.remove(conversationId)
|
||||
if (appMap.isEmpty()) {
|
||||
conversationNotifications.remove(packageName)
|
||||
}
|
||||
_conversationNotificationsLiveData.postValue(getConversationNotifications())
|
||||
saveConversationNotifications()
|
||||
}
|
||||
}
|
||||
|
||||
fun saveConversationNotifications() {
|
||||
try {
|
||||
val file = File(context.filesDir, NOTIF_SAVE_FILE)
|
||||
val mapToSave = conversationNotifications.mapValues { it.value.values.toList() }
|
||||
val json = Gson().toJson(mapToSave)
|
||||
file.writeText(json)
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
}
|
||||
|
||||
fun restoreConversationNotifications() {
|
||||
try {
|
||||
val file = File(context.filesDir, NOTIF_SAVE_FILE)
|
||||
if (!file.exists()) return
|
||||
val json = file.readText()
|
||||
val type = object : TypeToken<Map<String, List<ConversationNotification>>>() {}.type
|
||||
val restored: Map<String, List<ConversationNotification>> = Gson().fromJson(json, type)
|
||||
conversationNotifications.clear()
|
||||
restored.forEach { (pkg, list) ->
|
||||
conversationNotifications[pkg] =
|
||||
list.associateBy { it.conversationId }.toMutableMap()
|
||||
}
|
||||
_conversationNotificationsLiveData.postValue(getConversationNotifications())
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
}
|
||||
|
||||
fun buildNotificationInfo(
|
||||
sbn: android.service.notification.StatusBarNotification,
|
||||
prefs: com.github.gezimos.inkos.data.Prefs,
|
||||
activeNotifications: Array<android.service.notification.StatusBarNotification>
|
||||
): NotificationInfo? {
|
||||
val packageNotifications = activeNotifications.filter { it.packageName == sbn.packageName }
|
||||
if (packageNotifications.isNotEmpty()) {
|
||||
val latestNotification = packageNotifications.maxByOrNull { it.postTime }
|
||||
val extras = latestNotification?.notification?.extras
|
||||
|
||||
val showSender = prefs.showNotificationSenderName
|
||||
val showGroup = prefs.showNotificationGroupName
|
||||
val showMessage = prefs.showNotificationMessage
|
||||
|
||||
// Sender name logic: use full sender name if enabled
|
||||
val sender: String? = if (showSender) {
|
||||
extras?.getCharSequence("android.title")?.toString()?.trim()
|
||||
} else null
|
||||
|
||||
// Group name (conversation title)
|
||||
val group = if (showGroup) {
|
||||
extras?.getCharSequence("android.conversationTitle")?.toString()?.trim()
|
||||
} else null
|
||||
|
||||
// Message text
|
||||
val text = if (showMessage) {
|
||||
when {
|
||||
extras?.getCharSequence("android.bigText") != null ->
|
||||
extras.getCharSequence("android.bigText")?.toString()?.take(30)
|
||||
|
||||
extras?.getCharSequence("android.text") != null ->
|
||||
extras.getCharSequence("android.text")?.toString()?.take(30)
|
||||
|
||||
extras?.getCharSequenceArray("android.textLines") != null -> {
|
||||
val lines = extras.getCharSequenceArray("android.textLines")
|
||||
lines?.lastOrNull()?.toString()?.take(30)
|
||||
}
|
||||
|
||||
else -> null
|
||||
}
|
||||
} else null
|
||||
|
||||
var category = latestNotification?.notification?.category
|
||||
var showMedia = true
|
||||
if (category == android.app.Notification.CATEGORY_TRANSPORT) {
|
||||
showMedia = false
|
||||
val token =
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) {
|
||||
extras?.getParcelable(
|
||||
"android.mediaSession",
|
||||
android.media.session.MediaSession.Token::class.java
|
||||
)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
extras?.getParcelable<android.media.session.MediaSession.Token>("android.mediaSession")
|
||||
}
|
||||
if (token != null) {
|
||||
try {
|
||||
val controller = android.media.session.MediaController(context, token)
|
||||
val playbackState = controller.playbackState
|
||||
if (playbackState != null && playbackState.state == android.media.session.PlaybackState.STATE_PLAYING) {
|
||||
showMedia = true
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
}
|
||||
if (!showMedia) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
// Compose title and text based on toggles
|
||||
val notifTitle = buildString {
|
||||
if (!sender.isNullOrBlank()) append(sender)
|
||||
if (!group.isNullOrBlank()) {
|
||||
if (isNotEmpty()) append(": ")
|
||||
append(group)
|
||||
}
|
||||
}.ifBlank { null }
|
||||
|
||||
val notifText = text
|
||||
|
||||
return NotificationInfo(
|
||||
count = packageNotifications.size,
|
||||
title = notifTitle,
|
||||
text = if ((showMedia || category != android.app.Notification.CATEGORY_TRANSPORT) && showMessage) notifText else null,
|
||||
category = if (showMedia) category else null
|
||||
)
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
package com.github.gezimos.inkos.services
|
||||
|
||||
import android.content.Context
|
||||
import android.media.session.MediaSession
|
||||
import android.service.notification.NotificationListenerService
|
||||
import android.service.notification.StatusBarNotification
|
||||
|
||||
class NotificationService : NotificationListenerService() {
|
||||
private lateinit var notificationManager: NotificationManager
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
notificationManager = NotificationManager.getInstance(applicationContext)
|
||||
notificationManager.restoreConversationNotifications()
|
||||
}
|
||||
|
||||
override fun onListenerConnected() {
|
||||
super.onListenerConnected()
|
||||
// Only restore active media playback notifications after service (re)start
|
||||
activeNotifications?.filter {
|
||||
it.notification.category == android.app.Notification.CATEGORY_TRANSPORT
|
||||
}?.forEach { sbn ->
|
||||
updateBadgeNotification(sbn)
|
||||
if (shouldShowNotification(sbn.packageName)) {
|
||||
updateConversationNotifications(sbn)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun shouldShowNotification(packageName: String): Boolean {
|
||||
val prefs = com.github.gezimos.inkos.data.Prefs(this)
|
||||
val allowed = prefs.allowedNotificationApps
|
||||
// If allowlist is empty, allow all. Otherwise, only allow if in allowlist.
|
||||
return allowed.isEmpty() || allowed.contains(packageName)
|
||||
}
|
||||
|
||||
private fun shouldShowBadgeNotification(packageName: String): Boolean {
|
||||
val prefs = com.github.gezimos.inkos.data.Prefs(this)
|
||||
val allowed = prefs.allowedBadgeNotificationApps
|
||||
// If allowlist is empty, allow all. Otherwise, only allow if in allowlist.
|
||||
return allowed.isEmpty() || allowed.contains(packageName)
|
||||
}
|
||||
|
||||
override fun onNotificationPosted(sbn: StatusBarNotification) {
|
||||
// Always update badge notification, let NotificationManager filter by allowlist
|
||||
updateBadgeNotification(sbn)
|
||||
// Only update conversation notifications if allowed in notification allowlist
|
||||
if (shouldShowNotification(sbn.packageName)) {
|
||||
updateConversationNotifications(sbn)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNotificationRemoved(sbn: StatusBarNotification) {
|
||||
// Always update badge notification, let NotificationManager filter by allowlist
|
||||
updateBadgeNotification(sbn)
|
||||
}
|
||||
|
||||
private fun updateBadgeNotification(sbn: StatusBarNotification) {
|
||||
val activeNotifications = getActiveNotifications()
|
||||
val packageNotifications = activeNotifications.filter { it.packageName == sbn.packageName }
|
||||
val prefs = com.github.gezimos.inkos.data.Prefs(applicationContext)
|
||||
if (packageNotifications.isNotEmpty()) {
|
||||
val latestNotification = packageNotifications.maxByOrNull { it.postTime }
|
||||
val extras = latestNotification?.notification?.extras
|
||||
val title = extras?.getCharSequence("android.title")?.toString()
|
||||
val text = when {
|
||||
extras?.getCharSequence("android.bigText") != null ->
|
||||
extras.getCharSequence("android.bigText")?.toString()?.take(30)
|
||||
|
||||
extras?.getCharSequence("android.text") != null ->
|
||||
extras.getCharSequence("android.text")?.toString()?.take(30)
|
||||
|
||||
extras?.getCharSequenceArray("android.textLines") != null -> {
|
||||
val lines = extras.getCharSequenceArray("android.textLines")
|
||||
lines?.lastOrNull()?.toString()?.take(30)
|
||||
}
|
||||
|
||||
else -> null
|
||||
}
|
||||
var category = latestNotification?.notification?.category
|
||||
var showMedia = true
|
||||
if (category == android.app.Notification.CATEGORY_TRANSPORT) {
|
||||
showMedia = false
|
||||
val token =
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) {
|
||||
extras?.getParcelable(
|
||||
"android.mediaSession",
|
||||
MediaSession.Token::class.java
|
||||
)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
extras?.getParcelable<MediaSession.Token>("android.mediaSession")
|
||||
}
|
||||
if (token != null) {
|
||||
try {
|
||||
val controller = android.media.session.MediaController(this, token)
|
||||
val playbackState = controller.playbackState
|
||||
if (playbackState != null && playbackState.state == android.media.session.PlaybackState.STATE_PLAYING) {
|
||||
showMedia = true
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
}
|
||||
if (!showMedia) {
|
||||
notificationManager.updateBadgeNotification(sbn.packageName, null)
|
||||
return
|
||||
}
|
||||
}
|
||||
val showSender = prefs.showNotificationSenderName
|
||||
val showGroup = prefs.showNotificationGroupName
|
||||
val showMessage = prefs.showNotificationMessage
|
||||
notificationManager.updateBadgeNotification(
|
||||
sbn.packageName,
|
||||
NotificationManager.NotificationInfo(
|
||||
count = packageNotifications.size,
|
||||
title = when {
|
||||
showSender && showGroup && !title.isNullOrBlank() -> title
|
||||
showSender && !showGroup && !title.isNullOrBlank() -> title
|
||||
!showSender && showGroup -> null
|
||||
else -> null
|
||||
},
|
||||
text = if ((showMedia || category != android.app.Notification.CATEGORY_TRANSPORT) && showMessage) text else null,
|
||||
category = if (showMedia) category else null
|
||||
)
|
||||
)
|
||||
} else {
|
||||
notificationManager.updateBadgeNotification(sbn.packageName, null)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateConversationNotifications(sbn: StatusBarNotification) {
|
||||
val packageName = sbn.packageName
|
||||
val extras = sbn.notification.extras
|
||||
val conversationId = extras.getString("android.conversationTitle")
|
||||
?: extras.getString("android.title")
|
||||
?: "default"
|
||||
val conversationTitle = extras.getString("android.conversationTitle")
|
||||
val sender = extras.getString("android.title")
|
||||
val message = when {
|
||||
extras.getCharSequence("android.bigText") != null ->
|
||||
extras.getCharSequence("android.bigText")?.toString()
|
||||
|
||||
extras.getCharSequence("android.text") != null ->
|
||||
extras.getCharSequence("android.text")?.toString()
|
||||
|
||||
extras.getCharSequenceArray("android.textLines") != null -> {
|
||||
val lines = extras.getCharSequenceArray("android.textLines")
|
||||
lines?.lastOrNull()?.toString()
|
||||
}
|
||||
|
||||
else -> null
|
||||
}
|
||||
val timestamp = sbn.postTime
|
||||
notificationManager.updateConversationNotification(
|
||||
packageName,
|
||||
NotificationManager.ConversationNotification(
|
||||
conversationId = conversationId,
|
||||
conversationTitle = conversationTitle,
|
||||
sender = sender,
|
||||
message = message,
|
||||
timestamp = timestamp,
|
||||
category = sbn.notification.category
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun attachBaseContext(base: Context?) {
|
||||
super.attachBaseContext(base)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.github.gezimos.inkos.style
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
val textLightHeader = Color(0xFFFFFFFF)
|
||||
val textLight = Color(0xFFFFFFFF)
|
||||
val textDarkHeader = Color(0xFF000000)
|
||||
val textDark = Color(0xFF000000)
|
||||
val textGray = Color(0xFF000000)
|
||||
@@ -0,0 +1,127 @@
|
||||
package com.github.gezimos.inkos.style
|
||||
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.github.gezimos.inkos.data.Constants
|
||||
import com.github.gezimos.inkos.data.Prefs
|
||||
import com.github.gezimos.inkos.helper.getTrueSystemFont
|
||||
|
||||
@Immutable
|
||||
data class ReplacementTypography(
|
||||
val header: TextStyle,
|
||||
val title: TextStyle,
|
||||
val body: TextStyle,
|
||||
val item: TextStyle,
|
||||
val button: TextStyle,
|
||||
val buttonDisabled: TextStyle,
|
||||
)
|
||||
|
||||
@Immutable
|
||||
data class ReplacementColor(
|
||||
val settings: Color,
|
||||
val image: Color,
|
||||
val selector: Color,
|
||||
val border: Color,
|
||||
val horizontalPadding: Dp,
|
||||
)
|
||||
|
||||
val LocalReplacementTypography = staticCompositionLocalOf {
|
||||
ReplacementTypography(
|
||||
header = TextStyle.Default,
|
||||
title = TextStyle.Default,
|
||||
body = TextStyle.Default,
|
||||
item = TextStyle.Default,
|
||||
button = TextStyle.Default,
|
||||
buttonDisabled = TextStyle.Default,
|
||||
)
|
||||
}
|
||||
val LocalReplacementColor = staticCompositionLocalOf {
|
||||
ReplacementColor(
|
||||
settings = Color.Unspecified,
|
||||
image = Color.Unspecified,
|
||||
selector = Color.Unspecified,
|
||||
border = Color.Unspecified,
|
||||
horizontalPadding = 0.dp,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SettingsTheme(
|
||||
isDark: Boolean,
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
val context = androidx.compose.ui.platform.LocalContext.current
|
||||
val prefs = Prefs(context)
|
||||
|
||||
// Get current font from preferences
|
||||
val customPath = if (prefs.fontFamily == Constants.FontFamily.Custom) {
|
||||
prefs.getCustomFontPath("settings")
|
||||
} else null
|
||||
val currentFont = prefs.fontFamily.getFont(context, customPath) ?: getTrueSystemFont()
|
||||
|
||||
val replacementTypography = ReplacementTypography(
|
||||
header = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = if (isDark) textLightHeader else textDarkHeader,
|
||||
fontFamily = androidx.compose.ui.text.font.FontFamily(currentFont)
|
||||
),
|
||||
title = TextStyle(
|
||||
fontSize = 32.sp,
|
||||
color = if (isDark) textLight else textDark,
|
||||
fontFamily = androidx.compose.ui.text.font.FontFamily(currentFont)
|
||||
),
|
||||
body = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = if (isDark) textLight else textDark,
|
||||
fontFamily = androidx.compose.ui.text.font.FontFamily(currentFont)
|
||||
),
|
||||
item = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = if (isDark) textLight else textDark,
|
||||
fontFamily = androidx.compose.ui.text.font.FontFamily(currentFont)
|
||||
),
|
||||
button = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = if (isDark) textLight else textDark,
|
||||
fontFamily = androidx.compose.ui.text.font.FontFamily(currentFont)
|
||||
),
|
||||
buttonDisabled = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = textGray,
|
||||
fontFamily = androidx.compose.ui.text.font.FontFamily(currentFont)
|
||||
),
|
||||
)
|
||||
val replacementColor = ReplacementColor(
|
||||
settings = if (isDark) Color.White else Color.Black,
|
||||
image = if (isDark) Color.White else Color.Black,
|
||||
selector = if (isDark) Color.White else Color.Black,
|
||||
border = if (isDark) Color.White else Color.Black,
|
||||
horizontalPadding = 24.dp
|
||||
)
|
||||
CompositionLocalProvider(
|
||||
LocalReplacementTypography provides replacementTypography,
|
||||
LocalReplacementColor provides replacementColor,
|
||||
) {
|
||||
MaterialTheme(
|
||||
content = content
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
object SettingsTheme {
|
||||
val typography: ReplacementTypography
|
||||
@Composable
|
||||
get() = LocalReplacementTypography.current
|
||||
|
||||
val color: ReplacementColor
|
||||
@Composable
|
||||
get() = LocalReplacementColor.current
|
||||
}
|
||||
@@ -0,0 +1,381 @@
|
||||
/**
|
||||
* Prepare the data for the app drawer, which is the list of all the installed applications.
|
||||
*/
|
||||
|
||||
package com.github.gezimos.inkos.ui
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.util.Log
|
||||
import android.view.KeyEvent
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.widget.EditText
|
||||
import android.widget.Filter
|
||||
import android.widget.Filterable
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.gezimos.common.isSystemApp
|
||||
import com.github.gezimos.common.showKeyboard
|
||||
import com.github.gezimos.inkos.R
|
||||
import com.github.gezimos.inkos.data.AppListItem
|
||||
import com.github.gezimos.inkos.data.Constants.AppDrawerFlag
|
||||
import com.github.gezimos.inkos.data.Prefs
|
||||
import com.github.gezimos.inkos.databinding.AdapterAppDrawerBinding
|
||||
import com.github.gezimos.inkos.helper.dp2px
|
||||
|
||||
class AppDrawerAdapter(
|
||||
val context: Context,
|
||||
private val flag: AppDrawerFlag,
|
||||
private val drawerGravity: Int,
|
||||
private val clickListener: (AppListItem) -> Unit,
|
||||
private val deleteListener: (AppListItem) -> Unit,
|
||||
private val renameListener: (String, String) -> Unit,
|
||||
private val showHideListener: (AppDrawerFlag, AppListItem) -> Unit,
|
||||
private val infoListener: (AppListItem) -> Unit,
|
||||
) : RecyclerView.Adapter<AppDrawerAdapter.ViewHolder>(), Filterable {
|
||||
|
||||
private lateinit var prefs: Prefs
|
||||
private var appFilter = createAppFilter()
|
||||
var appsList: MutableList<AppListItem> = mutableListOf()
|
||||
var appFilteredList: MutableList<AppListItem> = mutableListOf()
|
||||
private lateinit var binding: AdapterAppDrawerBinding
|
||||
|
||||
private var lastQuery: String = ""
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
binding =
|
||||
AdapterAppDrawerBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
prefs = Prefs(parent.context)
|
||||
val fontColor = prefs.appColor
|
||||
binding.appTitle.setTextColor(fontColor)
|
||||
|
||||
binding.appTitle.textSize = prefs.appSize.toFloat()
|
||||
val padding: Int = prefs.textPaddingSize
|
||||
binding.appTitle.setPadding(0, padding, 0, padding)
|
||||
return ViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
if (appFilteredList.isEmpty()) return
|
||||
val appModel = appFilteredList[holder.absoluteAdapterPosition]
|
||||
holder.bind(
|
||||
flag,
|
||||
drawerGravity,
|
||||
appModel,
|
||||
clickListener,
|
||||
infoListener,
|
||||
deleteListener,
|
||||
renameListener,
|
||||
showHideListener
|
||||
)
|
||||
|
||||
holder.textView.apply {
|
||||
// Always use customLabel if available, otherwise fall back to original label
|
||||
text = if (appModel.customLabel.isNotEmpty()) appModel.customLabel else appModel.label
|
||||
gravity = drawerGravity
|
||||
textSize = Prefs(context).appSize.toFloat()
|
||||
// Use universal font logic for app names
|
||||
typeface = Prefs(context).getFontForContext("apps")
|
||||
.getFont(context, Prefs(context).getCustomFontPathForContext("apps"))
|
||||
setTextColor(Prefs(context).appColor)
|
||||
}
|
||||
|
||||
holder.appHide.setOnClickListener {
|
||||
appFilteredList.removeAt(holder.absoluteAdapterPosition)
|
||||
appsList.remove(appModel)
|
||||
notifyItemRemoved(holder.absoluteAdapterPosition)
|
||||
showHideListener(flag, appModel)
|
||||
}
|
||||
|
||||
holder.appLock.setOnClickListener {
|
||||
val appName = appModel.activityPackage
|
||||
// Access the current locked apps set
|
||||
val currentLockedApps = prefs.lockedApps
|
||||
|
||||
if (currentLockedApps.contains(appName)) {
|
||||
holder.appLock.setCompoundDrawablesWithIntrinsicBounds(
|
||||
0,
|
||||
R.drawable.padlock_off,
|
||||
0,
|
||||
0
|
||||
)
|
||||
holder.appLock.text = context.getString(R.string.lock)
|
||||
// If appName is already in the set, remove it
|
||||
currentLockedApps.remove(appName)
|
||||
} else {
|
||||
holder.appLock.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.padlock, 0, 0)
|
||||
holder.appLock.text = context.getString(R.string.unlock)
|
||||
// If appName is not in the set, add it
|
||||
currentLockedApps.add(appName)
|
||||
}
|
||||
|
||||
// Update the lockedApps value (save the updated set back to prefs)
|
||||
prefs.lockedApps = currentLockedApps
|
||||
Log.d("lockedApps", prefs.lockedApps.toString())
|
||||
}
|
||||
|
||||
holder.appSaveRename.setOnClickListener {
|
||||
val name = holder.appRenameEdit.text.toString().trim()
|
||||
appModel.customLabel = name
|
||||
// Re-sort the list after renaming
|
||||
sortAppList()
|
||||
notifyDataSetChanged()
|
||||
renameListener(appModel.activityPackage, appModel.customLabel)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = appFilteredList.size
|
||||
|
||||
override fun getFilter(): Filter = this.appFilter
|
||||
|
||||
private fun createAppFilter(): Filter {
|
||||
return object : Filter() {
|
||||
override fun performFiltering(charSearch: CharSequence?): FilterResults {
|
||||
lastQuery = charSearch?.toString() ?: ""
|
||||
val filterResults = FilterResults()
|
||||
filterResults.values = appsList // Return all apps since we're removing search
|
||||
return filterResults
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun publishResults(constraint: CharSequence?, results: FilterResults?) {
|
||||
if (results?.values is MutableList<*>) {
|
||||
appFilteredList = results.values as MutableList<AppListItem>
|
||||
notifyDataSetChanged()
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun setAppList(appsList: MutableList<AppListItem>) {
|
||||
this.appsList = appsList
|
||||
this.appFilteredList = appsList
|
||||
sortAppList()
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
private fun sortAppList() {
|
||||
val comparator = compareBy<AppListItem> { it.customLabel.ifEmpty { it.label }.lowercase() }
|
||||
appsList.sortWith(comparator)
|
||||
appFilteredList.sortWith(comparator)
|
||||
}
|
||||
|
||||
fun launchFirstInList() {
|
||||
if (appFilteredList.isNotEmpty())
|
||||
clickListener(appFilteredList[0])
|
||||
}
|
||||
|
||||
class ViewHolder(itemView: AdapterAppDrawerBinding) : RecyclerView.ViewHolder(itemView.root) {
|
||||
val appHide: TextView = itemView.appHide
|
||||
val appLock: TextView = itemView.appLock
|
||||
val appRenameEdit: EditText = itemView.appRenameEdit
|
||||
val appSaveRename: TextView = itemView.appSaveRename
|
||||
val textView: TextView = itemView.appTitle
|
||||
|
||||
private val appHideLayout: LinearLayout = itemView.appHideLayout
|
||||
private val appRenameLayout: LinearLayout = itemView.appRenameLayout
|
||||
private val appRename: TextView = itemView.appRename
|
||||
private val appTitleFrame: FrameLayout = itemView.appTitleFrame
|
||||
private val appClose: TextView = itemView.appClose
|
||||
private val appInfo: TextView = itemView.appInfo
|
||||
private val appDelete: TextView = itemView.appDelete
|
||||
|
||||
@SuppressLint("RtlHardcoded", "NewApi")
|
||||
fun bind(
|
||||
flag: AppDrawerFlag,
|
||||
appLabelGravity: Int,
|
||||
appListItem: AppListItem,
|
||||
appClickListener: (AppListItem) -> Unit,
|
||||
appInfoListener: (AppListItem) -> Unit,
|
||||
appDeleteListener: (AppListItem) -> Unit,
|
||||
renameListener: (String, String) -> Unit,
|
||||
showHideListener: (AppDrawerFlag, AppListItem) -> Unit
|
||||
) =
|
||||
with(itemView) {
|
||||
val prefs = Prefs(context)
|
||||
appHideLayout.visibility = View.GONE
|
||||
appRenameLayout.visibility = View.GONE
|
||||
|
||||
// set show/hide icon
|
||||
if (flag == AppDrawerFlag.HiddenApps) {
|
||||
appHide.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.visibility, 0, 0)
|
||||
appHide.text = context.getString(R.string.show)
|
||||
} else {
|
||||
appHide.setCompoundDrawablesWithIntrinsicBounds(
|
||||
0,
|
||||
R.drawable.visibility_off,
|
||||
0,
|
||||
0
|
||||
)
|
||||
appHide.text = context.getString(R.string.hide)
|
||||
}
|
||||
|
||||
val appName = appListItem.activityPackage
|
||||
// Access the current locked apps set
|
||||
val currentLockedApps = prefs.lockedApps
|
||||
|
||||
if (currentLockedApps.contains(appName)) {
|
||||
appLock.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.padlock, 0, 0)
|
||||
appLock.text = context.getString(R.string.unlock)
|
||||
} else {
|
||||
appLock.setCompoundDrawablesWithIntrinsicBounds(
|
||||
0,
|
||||
R.drawable.padlock_off,
|
||||
0,
|
||||
0
|
||||
)
|
||||
appLock.text = context.getString(R.string.lock)
|
||||
}
|
||||
|
||||
appRename.apply {
|
||||
setOnClickListener {
|
||||
if (appListItem.activityPackage.isNotEmpty()) {
|
||||
appRenameEdit.setText(appListItem.customLabel.ifEmpty { appListItem.label })
|
||||
appRenameLayout.visibility = View.VISIBLE
|
||||
appHideLayout.visibility = View.GONE
|
||||
appRenameEdit.showKeyboard()
|
||||
appRenameEdit.setSelection(appRenameEdit.text.length)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
appRenameEdit.apply {
|
||||
addTextChangedListener(object : TextWatcher {
|
||||
override fun afterTextChanged(s: Editable) {}
|
||||
|
||||
override fun beforeTextChanged(
|
||||
s: CharSequence, start: Int,
|
||||
count: Int, after: Int
|
||||
) {
|
||||
}
|
||||
|
||||
override fun onTextChanged(
|
||||
s: CharSequence, start: Int,
|
||||
before: Int, count: Int
|
||||
) {
|
||||
if (appRenameEdit.text.isEmpty()) {
|
||||
appSaveRename.text = context.getString(R.string.reset)
|
||||
} else if (appRenameEdit.text.toString() == appListItem.customLabel) {
|
||||
appSaveRename.text = context.getString(R.string.cancel)
|
||||
} else {
|
||||
appSaveRename.text = context.getString(R.string.rename)
|
||||
}
|
||||
}
|
||||
})
|
||||
text = Editable.Factory.getInstance().newEditable(appListItem.label)
|
||||
setOnEditorActionListener { v, actionId, event ->
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE || (event != null && event.keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_DOWN)) {
|
||||
val name = appRenameEdit.text.toString().trim()
|
||||
appListItem.customLabel = name
|
||||
(bindingAdapter as AppDrawerAdapter).notifyItemChanged(
|
||||
absoluteAdapterPosition
|
||||
)
|
||||
renameListener(appListItem.activityPackage, name)
|
||||
appRenameLayout.visibility = View.GONE
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
appSaveRename.setOnClickListener {
|
||||
val name = appRenameEdit.text.toString().trim()
|
||||
appListItem.customLabel = name
|
||||
(bindingAdapter as AppDrawerAdapter).notifyItemChanged(absoluteAdapterPosition)
|
||||
renameListener(appListItem.activityPackage, name)
|
||||
appRenameLayout.visibility = View.GONE
|
||||
}
|
||||
|
||||
textView.apply {
|
||||
val customLabel =
|
||||
Prefs(context).getAppAlias("app_alias_${appListItem.activityPackage}")
|
||||
text = if (customLabel.isNotEmpty()) customLabel else appListItem.label
|
||||
gravity = appLabelGravity
|
||||
textSize = Prefs(context).appSize.toFloat()
|
||||
// Use universal font logic for app names
|
||||
typeface = Prefs(context).getFontForContext("apps")
|
||||
.getFont(context, Prefs(context).getCustomFontPathForContext("apps"))
|
||||
setTextColor(Prefs(context).appColor)
|
||||
}
|
||||
|
||||
// set text gravity
|
||||
val params = textView.layoutParams as FrameLayout.LayoutParams
|
||||
params.gravity = appLabelGravity
|
||||
textView.layoutParams = params
|
||||
|
||||
textView.setCompoundDrawables(null, null, null, null)
|
||||
|
||||
val padding = dp2px(resources, 24)
|
||||
textView.updatePadding(left = padding, right = padding)
|
||||
|
||||
appHide.setOnClickListener {
|
||||
(bindingAdapter as AppDrawerAdapter).let { adapter ->
|
||||
// Remove from current visible list
|
||||
adapter.appFilteredList.removeAt(absoluteAdapterPosition)
|
||||
adapter.notifyItemRemoved(absoluteAdapterPosition)
|
||||
// Remove from full list as well
|
||||
adapter.appsList.remove(appListItem)
|
||||
showHideListener(flag, appListItem)
|
||||
appHideLayout.visibility = View.GONE
|
||||
|
||||
// Reapply current filter to refresh the list
|
||||
adapter.filter.filter(adapter.lastQuery)
|
||||
}
|
||||
}
|
||||
|
||||
appTitleFrame.apply {
|
||||
setOnClickListener {
|
||||
appClickListener(appListItem)
|
||||
}
|
||||
setOnLongClickListener {
|
||||
val openApp =
|
||||
flag == AppDrawerFlag.LaunchApp || flag == AppDrawerFlag.HiddenApps
|
||||
if (openApp) {
|
||||
try {
|
||||
appDelete.alpha =
|
||||
if (context.isSystemApp(appListItem.activityPackage)) 0.3f else 1.0f
|
||||
appHideLayout.visibility = View.VISIBLE
|
||||
appRenameLayout.visibility =
|
||||
View.GONE // Make sure rename layout is hidden
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
appInfo.apply {
|
||||
setOnClickListener {
|
||||
appInfoListener(appListItem)
|
||||
}
|
||||
}
|
||||
|
||||
appDelete.apply {
|
||||
setOnClickListener {
|
||||
appDeleteListener(appListItem)
|
||||
}
|
||||
}
|
||||
|
||||
appClose.apply {
|
||||
setOnClickListener {
|
||||
appHideLayout.visibility = View.GONE
|
||||
appRenameLayout.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,327 @@
|
||||
/**
|
||||
* The view for the list of all the installed applications.
|
||||
*/
|
||||
|
||||
package com.github.gezimos.inkos.ui
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.view.Gravity
|
||||
import android.view.KeyEvent
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.animation.AnimationUtils
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import androidx.core.net.toUri
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.gezimos.common.isSystemApp
|
||||
import com.github.gezimos.common.showShortToast
|
||||
import com.github.gezimos.inkos.MainViewModel
|
||||
import com.github.gezimos.inkos.R
|
||||
import com.github.gezimos.inkos.data.AppListItem
|
||||
import com.github.gezimos.inkos.data.Constants.AppDrawerFlag
|
||||
import com.github.gezimos.inkos.data.Prefs
|
||||
import com.github.gezimos.inkos.databinding.FragmentAppDrawerBinding
|
||||
import com.github.gezimos.inkos.helper.getHexForOpacity
|
||||
import com.github.gezimos.inkos.helper.openAppInfo
|
||||
|
||||
class AppDrawerFragment : Fragment() {
|
||||
|
||||
private lateinit var prefs: Prefs
|
||||
private lateinit var adapter: AppDrawerAdapter
|
||||
private lateinit var viewModel: MainViewModel // Add viewModel property
|
||||
|
||||
// --- Add uninstall launcher and package tracking ---
|
||||
private var pendingUninstallPackage: String? = null
|
||||
private val uninstallLauncher =
|
||||
registerForActivityResult(androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (pendingUninstallPackage != null) {
|
||||
viewModel.refreshAppListAfterUninstall(includeHiddenApps = false)
|
||||
pendingUninstallPackage = null
|
||||
}
|
||||
}
|
||||
|
||||
private var _binding: FragmentAppDrawerBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = FragmentAppDrawerBinding.inflate(inflater, container, false)
|
||||
prefs = Prefs(requireContext())
|
||||
|
||||
// Initialize viewModel
|
||||
viewModel = ViewModelProvider(requireActivity())[MainViewModel::class.java]
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
@SuppressLint("RtlHardcoded")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
if (prefs.firstSettingsOpen) {
|
||||
prefs.firstSettingsOpen = false
|
||||
}
|
||||
|
||||
arguments?.getInt("letterKeyCode", -1)
|
||||
|
||||
val backgroundColor = getHexForOpacity(prefs)
|
||||
binding.mainLayout.setBackgroundColor(backgroundColor)
|
||||
|
||||
val flagString = arguments?.getString("flag", AppDrawerFlag.LaunchApp.toString())
|
||||
?: AppDrawerFlag.LaunchApp.toString()
|
||||
val flag = AppDrawerFlag.valueOf(flagString)
|
||||
val n = arguments?.getInt("n", 0) ?: 0
|
||||
|
||||
// Include hidden apps only for SetHomeApp flag or HiddenApps flag
|
||||
val includeHidden = flag == AppDrawerFlag.SetHomeApp || flag == AppDrawerFlag.HiddenApps
|
||||
viewModel.getAppList(includeHiddenApps = includeHidden)
|
||||
|
||||
when (flag) {
|
||||
AppDrawerFlag.SetHomeApp,
|
||||
AppDrawerFlag.SetSwipeUp,
|
||||
AppDrawerFlag.SetSwipeDown,
|
||||
AppDrawerFlag.SetSwipeLeft,
|
||||
AppDrawerFlag.SetSwipeRight,
|
||||
AppDrawerFlag.SetClickClock -> {
|
||||
binding.drawerButton.setOnClickListener {
|
||||
findNavController().popBackStack()
|
||||
}
|
||||
}
|
||||
|
||||
AppDrawerFlag.HiddenApps,
|
||||
AppDrawerFlag.LaunchApp,
|
||||
AppDrawerFlag.PrivateApps,
|
||||
AppDrawerFlag.SetDoubleTap -> {
|
||||
// No action needed
|
||||
}
|
||||
}
|
||||
|
||||
// Always use center gravity for consistency
|
||||
val gravity = Gravity.CENTER
|
||||
|
||||
val appAdapter = context?.let {
|
||||
AppDrawerAdapter(
|
||||
it,
|
||||
flag,
|
||||
gravity,
|
||||
appClickListener(viewModel, flag, n),
|
||||
appDeleteListener(),
|
||||
this.appRenameListener(),
|
||||
appShowHideListener(),
|
||||
appInfoListener()
|
||||
)
|
||||
}
|
||||
|
||||
if (appAdapter != null) {
|
||||
adapter = appAdapter
|
||||
}
|
||||
|
||||
// Hide the search view completely
|
||||
binding.search.visibility = View.GONE
|
||||
|
||||
// Apply apps font to listEmptyHint text
|
||||
binding.listEmptyHint.typeface = prefs.appsFont.getFont(requireContext())
|
||||
|
||||
if (appAdapter != null) {
|
||||
initViewModel(flag, viewModel, appAdapter)
|
||||
}
|
||||
|
||||
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
|
||||
binding.recyclerView.adapter = appAdapter
|
||||
binding.recyclerView.addOnScrollListener(getRecyclerViewOnScrollListener())
|
||||
|
||||
binding.listEmptyHint.text =
|
||||
applyTextColor(getString(R.string.drawer_list_empty_hint), prefs.appColor)
|
||||
}
|
||||
|
||||
private fun applyTextColor(text: String, color: Int): SpannableString {
|
||||
val spannableString = SpannableString(text)
|
||||
spannableString.setSpan(
|
||||
ForegroundColorSpan(color),
|
||||
0,
|
||||
text.length,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
)
|
||||
return spannableString
|
||||
}
|
||||
|
||||
private fun convertKeyCodeToLetter(keyCode: Int): Char {
|
||||
return when (keyCode) {
|
||||
KeyEvent.KEYCODE_A -> 'A'
|
||||
KeyEvent.KEYCODE_B -> 'B'
|
||||
KeyEvent.KEYCODE_C -> 'C'
|
||||
KeyEvent.KEYCODE_D -> 'D'
|
||||
KeyEvent.KEYCODE_E -> 'E'
|
||||
KeyEvent.KEYCODE_F -> 'F'
|
||||
KeyEvent.KEYCODE_G -> 'G'
|
||||
KeyEvent.KEYCODE_H -> 'H'
|
||||
KeyEvent.KEYCODE_I -> 'I'
|
||||
KeyEvent.KEYCODE_J -> 'J'
|
||||
KeyEvent.KEYCODE_K -> 'K'
|
||||
KeyEvent.KEYCODE_L -> 'L'
|
||||
KeyEvent.KEYCODE_M -> 'M'
|
||||
KeyEvent.KEYCODE_N -> 'N'
|
||||
KeyEvent.KEYCODE_O -> 'O'
|
||||
KeyEvent.KEYCODE_P -> 'P'
|
||||
KeyEvent.KEYCODE_Q -> 'Q'
|
||||
KeyEvent.KEYCODE_R -> 'R'
|
||||
KeyEvent.KEYCODE_S -> 'S'
|
||||
KeyEvent.KEYCODE_T -> 'T'
|
||||
KeyEvent.KEYCODE_U -> 'U'
|
||||
KeyEvent.KEYCODE_V -> 'V'
|
||||
KeyEvent.KEYCODE_W -> 'W'
|
||||
KeyEvent.KEYCODE_X -> 'X'
|
||||
KeyEvent.KEYCODE_Y -> 'Y'
|
||||
KeyEvent.KEYCODE_Z -> 'Z'
|
||||
else -> throw IllegalArgumentException("Invalid key code: $keyCode")
|
||||
}
|
||||
}
|
||||
|
||||
private fun initViewModel(
|
||||
flag: AppDrawerFlag,
|
||||
viewModel: MainViewModel,
|
||||
appAdapter: AppDrawerAdapter
|
||||
) {
|
||||
viewModel.hiddenApps.observe(viewLifecycleOwner, Observer {
|
||||
if (flag != AppDrawerFlag.HiddenApps) return@Observer
|
||||
it?.let { appList ->
|
||||
binding.listEmptyHint.visibility =
|
||||
if (appList.isEmpty()) View.VISIBLE else View.GONE
|
||||
populateAppList(appList, appAdapter)
|
||||
}
|
||||
})
|
||||
|
||||
viewModel.appList.observe(viewLifecycleOwner, Observer {
|
||||
if (flag == AppDrawerFlag.HiddenApps) return@Observer
|
||||
if (it == appAdapter.appsList) return@Observer
|
||||
it?.let { appList ->
|
||||
binding.listEmptyHint.visibility =
|
||||
if (appList.isEmpty()) View.VISIBLE else View.GONE
|
||||
populateAppList(appList, appAdapter)
|
||||
}
|
||||
})
|
||||
|
||||
viewModel.firstOpen.observe(viewLifecycleOwner) {
|
||||
if (it) binding.appDrawerTip.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
// No need to show keyboard since search is hidden
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
// No need to hide keyboard since search is hidden
|
||||
}
|
||||
|
||||
private fun View.hideKeyboard() {
|
||||
val imm: InputMethodManager? =
|
||||
context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?
|
||||
imm?.hideSoftInputFromWindow(windowToken, 0)
|
||||
this.clearFocus()
|
||||
}
|
||||
|
||||
private fun populateAppList(apps: List<AppListItem>, appAdapter: AppDrawerAdapter) {
|
||||
val animation =
|
||||
AnimationUtils.loadLayoutAnimation(requireContext(), R.anim.layout_anim_from_bottom)
|
||||
binding.recyclerView.layoutAnimation = animation
|
||||
appAdapter.setAppList(apps.toMutableList())
|
||||
}
|
||||
|
||||
private fun appClickListener(
|
||||
viewModel: MainViewModel,
|
||||
flag: AppDrawerFlag,
|
||||
n: Int = 0
|
||||
): (appListItem: AppListItem) -> Unit =
|
||||
{ appModel ->
|
||||
viewModel.selectedApp(this, appModel, flag, n)
|
||||
}
|
||||
|
||||
private fun appDeleteListener(): (appListItem: AppListItem) -> Unit =
|
||||
{ appModel ->
|
||||
if (requireContext().isSystemApp(appModel.activityPackage))
|
||||
showShortToast(getString(R.string.can_not_delete_system_apps))
|
||||
else {
|
||||
val appPackage = appModel.activityPackage
|
||||
val intent = Intent(Intent.ACTION_DELETE)
|
||||
intent.data = "package:$appPackage".toUri()
|
||||
pendingUninstallPackage = appPackage
|
||||
uninstallLauncher.launch(intent)
|
||||
// Do NOT refresh here; refresh will happen in the result callback
|
||||
}
|
||||
}
|
||||
|
||||
private fun appRenameListener(): (String, String) -> Unit = { packageName, newName ->
|
||||
viewModel.renameApp(packageName, newName)
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
private fun renameListener(flag: AppDrawerFlag, i: Int) {
|
||||
// No search functionality, so no longer needed
|
||||
}
|
||||
|
||||
private fun appShowHideListener(): (flag: AppDrawerFlag, appListItem: AppListItem) -> Unit =
|
||||
{ flag, appModel ->
|
||||
viewModel.hideOrShowApp(flag, appModel)
|
||||
if (flag == AppDrawerFlag.HiddenApps && Prefs(requireContext()).hiddenApps.isEmpty()) {
|
||||
findNavController().popBackStack()
|
||||
}
|
||||
}
|
||||
|
||||
private fun appInfoListener(): (appListItem: AppListItem) -> Unit =
|
||||
{ appModel ->
|
||||
openAppInfo(
|
||||
requireContext(),
|
||||
appModel.user,
|
||||
appModel.activityPackage
|
||||
)
|
||||
findNavController().popBackStack(R.id.mainFragment, false)
|
||||
}
|
||||
|
||||
private fun getRecyclerViewOnScrollListener(): RecyclerView.OnScrollListener {
|
||||
return object : RecyclerView.OnScrollListener() {
|
||||
|
||||
var onTop = false
|
||||
|
||||
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
|
||||
super.onScrollStateChanged(recyclerView, newState)
|
||||
when (newState) {
|
||||
|
||||
RecyclerView.SCROLL_STATE_DRAGGING -> {
|
||||
onTop = !recyclerView.canScrollVertically(-1)
|
||||
if (onTop && !recyclerView.canScrollVertically(1)) {
|
||||
findNavController().popBackStack()
|
||||
}
|
||||
}
|
||||
|
||||
RecyclerView.SCROLL_STATE_IDLE -> {
|
||||
if (!recyclerView.canScrollVertically(1)) {
|
||||
// No need to hide keyboard since search is removed
|
||||
} else if (!recyclerView.canScrollVertically(-1)) {
|
||||
if (onTop) {
|
||||
findNavController().popBackStack()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.github.gezimos.inkos.ui
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.gezimos.inkos.R
|
||||
import com.github.gezimos.inkos.data.AppListItem
|
||||
import com.github.gezimos.inkos.data.Prefs
|
||||
import com.github.gezimos.inkos.helper.utils.AppDiffCallback
|
||||
|
||||
// Adapter to display Home Apps
|
||||
class FavoriteAdapter(
|
||||
private val apps: MutableList<AppListItem>, // List of AppListItem objects
|
||||
private val onItemMoved: (fromPosition: Int, toPosition: Int) -> Unit,
|
||||
private val prefs: Prefs
|
||||
) : RecyclerView.Adapter<FavoriteAdapter.AppViewHolder>() {
|
||||
|
||||
inner class AppViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
val appTextView: TextView = itemView.findViewById(R.id.homeAppLabel)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AppViewHolder {
|
||||
val view =
|
||||
LayoutInflater.from(parent.context).inflate(R.layout.home_app_button, parent, false)
|
||||
return AppViewHolder(view)
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onBindViewHolder(holder: AppViewHolder, position: Int) {
|
||||
val appItem = apps[position]
|
||||
|
||||
// Set the label text from the app item
|
||||
holder.appTextView.text = appItem.label
|
||||
|
||||
// Set the text size and color dynamically using prefs
|
||||
holder.appTextView.setTextColor(prefs.appColor) // Get color from prefs
|
||||
holder.appTextView.textSize = prefs.appSize.toFloat() // Get text size from prefs
|
||||
|
||||
// Set the font from prefs.appsFont
|
||||
val font = prefs.appsFont.getFont(
|
||||
holder.itemView.context,
|
||||
prefs.getCustomFontPathForContext("apps")
|
||||
)
|
||||
if (font != null) {
|
||||
holder.appTextView.typeface = font
|
||||
}
|
||||
|
||||
// Set the gravity to align text to the left and ensure it's centered vertically
|
||||
holder.appTextView.gravity = Gravity.START or Gravity.CENTER_VERTICAL
|
||||
|
||||
// Set drawable to the right side of the text
|
||||
val prefixDrawable: Drawable? =
|
||||
ContextCompat.getDrawable(holder.itemView.context, R.drawable.ic_order_apps)
|
||||
holder.appTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, prefixDrawable, null)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = apps.size
|
||||
|
||||
// Notify when an item is moved
|
||||
fun moveItem(fromPosition: Int, toPosition: Int) {
|
||||
val temp = apps[fromPosition]
|
||||
apps[fromPosition] = apps[toPosition]
|
||||
apps[toPosition] = temp
|
||||
notifyItemMoved(fromPosition, toPosition)
|
||||
onItemMoved(fromPosition, toPosition) // Notify the view model of the change
|
||||
}
|
||||
|
||||
// Update the list when the data changes
|
||||
fun updateList(newList: List<AppListItem>) {
|
||||
val diffCallback = AppDiffCallback(apps, newList)
|
||||
val diffResult = DiffUtil.calculateDiff(diffCallback)
|
||||
apps.clear()
|
||||
apps.addAll(newList)
|
||||
diffResult.dispatchUpdatesTo(this)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
package com.github.gezimos.inkos.ui
|
||||
|
||||
import android.app.admin.DevicePolicyManager
|
||||
import android.content.Context
|
||||
import android.content.Context.VIBRATOR_SERVICE
|
||||
import android.os.Bundle
|
||||
import android.os.Vibrator
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.gezimos.inkos.MainViewModel
|
||||
import com.github.gezimos.inkos.R
|
||||
import com.github.gezimos.inkos.data.Prefs
|
||||
import com.github.gezimos.inkos.databinding.FragmentFavoriteBinding
|
||||
import com.github.gezimos.inkos.helper.getHexForOpacity
|
||||
import com.github.gezimos.inkos.helper.hideStatusBar
|
||||
import com.github.gezimos.inkos.helper.showStatusBar
|
||||
|
||||
class FavoriteFragment : Fragment() {
|
||||
|
||||
private lateinit var prefs: Prefs
|
||||
private lateinit var viewModel: MainViewModel
|
||||
private lateinit var deviceManager: DevicePolicyManager
|
||||
private lateinit var vibrator: Vibrator
|
||||
|
||||
private var _binding: FragmentFavoriteBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = FragmentFavoriteBinding.inflate(inflater, container, false)
|
||||
|
||||
val view = binding.root
|
||||
prefs = Prefs(requireContext())
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
val backgroundColor = getHexForOpacity(prefs)
|
||||
binding.mainLayout.setBackgroundColor(backgroundColor)
|
||||
|
||||
viewModel = activity?.run {
|
||||
ViewModelProvider(this)[MainViewModel::class.java]
|
||||
} ?: throw Exception("Invalid Activity")
|
||||
|
||||
deviceManager =
|
||||
context?.getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
|
||||
@Suppress("DEPRECATION")
|
||||
vibrator = context?.getSystemService(VIBRATOR_SERVICE) as Vibrator
|
||||
|
||||
// Initialize the adapter and pass prefs to it
|
||||
val adapter = FavoriteAdapter(mutableListOf(), { from, to ->
|
||||
viewModel.updateAppOrder(from, to)
|
||||
}, prefs) // Pass prefs to the adapter
|
||||
|
||||
binding.homeAppsRecyclerview.layoutManager =
|
||||
LinearLayoutManager(requireContext()) // Set LayoutManager
|
||||
binding.homeAppsRecyclerview.adapter = adapter
|
||||
|
||||
// Initialize the ItemTouchHelper to enable drag-and-drop
|
||||
val callback = object : ItemTouchHelper.Callback() {
|
||||
override fun getMovementFlags(
|
||||
recyclerView: RecyclerView,
|
||||
viewHolder: RecyclerView.ViewHolder
|
||||
): Int {
|
||||
val dragFlags = ItemTouchHelper.UP or ItemTouchHelper.DOWN
|
||||
return makeMovementFlags(dragFlags, 0)
|
||||
}
|
||||
|
||||
override fun onMove(
|
||||
recyclerView: RecyclerView,
|
||||
source: RecyclerView.ViewHolder,
|
||||
target: RecyclerView.ViewHolder
|
||||
): Boolean {
|
||||
val fromPosition = source.bindingAdapterPosition // Use bindingAdapterPosition here
|
||||
val toPosition = target.bindingAdapterPosition // Use bindingAdapterPosition here
|
||||
|
||||
// Change the background color when the item is being dragged
|
||||
source.itemView.setBackgroundColor(
|
||||
ContextCompat.getColor(
|
||||
source.itemView.context,
|
||||
R.color.hover_effect
|
||||
)
|
||||
)
|
||||
|
||||
// Check if the positions are valid
|
||||
if (fromPosition != RecyclerView.NO_POSITION && toPosition != RecyclerView.NO_POSITION) {
|
||||
// Update the order of the items in the adapter
|
||||
(recyclerView.adapter as FavoriteAdapter).moveItem(fromPosition, toPosition)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
|
||||
// Not handling swipe-to-dismiss here
|
||||
}
|
||||
|
||||
override fun onSelectedChanged(
|
||||
viewHolder: RecyclerView.ViewHolder?,
|
||||
actionState: Int
|
||||
) {
|
||||
super.onSelectedChanged(viewHolder, actionState)
|
||||
|
||||
viewHolder?.itemView?.setBackgroundColor(
|
||||
ContextCompat.getColor(viewHolder.itemView.context, R.color.hover_effect)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
override fun clearView(
|
||||
recyclerView: RecyclerView,
|
||||
viewHolder: RecyclerView.ViewHolder
|
||||
) {
|
||||
// Reset the background color after dragging is finished
|
||||
super.clearView(recyclerView, viewHolder)
|
||||
viewHolder.itemView.setBackgroundColor(
|
||||
ContextCompat.getColor(
|
||||
viewHolder.itemView.context,
|
||||
R.color.transparent
|
||||
)
|
||||
) // Set the background to transparent
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
val itemTouchHelper = ItemTouchHelper(callback)
|
||||
itemTouchHelper.attachToRecyclerView(binding.homeAppsRecyclerview)
|
||||
|
||||
// Load the saved order when the fragment starts
|
||||
viewModel.loadAppOrder() // Load the app order
|
||||
|
||||
// Observe LiveData and update RecyclerView when order changes
|
||||
viewModel.homeAppsOrder.observe(viewLifecycleOwner) { order ->
|
||||
if (order.isNotEmpty()) {
|
||||
adapter.updateList(order) // Update the adapter with the new order
|
||||
}
|
||||
}
|
||||
|
||||
initObservers()
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
if (prefs.showStatusBar) showStatusBar(requireActivity()) else hideStatusBar(requireActivity())
|
||||
|
||||
val backgroundColor = getHexForOpacity(prefs)
|
||||
binding.mainLayout.setBackgroundColor(backgroundColor)
|
||||
}
|
||||
|
||||
private fun initObservers() {
|
||||
binding.pageName.apply {
|
||||
text = getString(R.string.favorite_apps)
|
||||
textSize = prefs.appSize * 1.1f
|
||||
setTextColor(prefs.appColor)
|
||||
// Set the font from prefs.appsFont
|
||||
val font = prefs.appsFont.getFont(context, prefs.getCustomFontPathForContext("apps"))
|
||||
if (font != null) {
|
||||
typeface = font
|
||||
}
|
||||
}
|
||||
|
||||
with(viewModel) {
|
||||
homeAppsNum.observe(viewLifecycleOwner) { newAppsNum ->
|
||||
updateRecyclerView(newAppsNum)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateRecyclerView(newAppsNum: Int) {
|
||||
val currentList = viewModel.homeAppsOrder.value ?: emptyList()
|
||||
|
||||
// If the number of apps has changed, update the RecyclerView's list
|
||||
if (currentList.size != newAppsNum) {
|
||||
val newList = (0 until newAppsNum).map { index ->
|
||||
prefs.getHomeAppModel(index) // Retrieve app info from Prefs
|
||||
}
|
||||
viewModel.homeAppsOrder.postValue(newList) // Update LiveData to trigger RecyclerView refresh
|
||||
}
|
||||
}
|
||||
}
|
||||
1112
app/src/main/java/com/github/gezimos/inkos/ui/HomeFragment.kt
Normal file
1112
app/src/main/java/com/github/gezimos/inkos/ui/HomeFragment.kt
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,404 @@
|
||||
package com.github.gezimos.inkos.ui
|
||||
|
||||
import android.app.admin.DevicePolicyManager
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.TextUnit
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.isSpecified
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.github.gezimos.inkos.MainViewModel
|
||||
import com.github.gezimos.inkos.R
|
||||
import com.github.gezimos.inkos.data.Constants.AppDrawerFlag
|
||||
import com.github.gezimos.inkos.data.Constants.Theme.Dark
|
||||
import com.github.gezimos.inkos.data.Constants.Theme.Light
|
||||
import com.github.gezimos.inkos.data.Constants.Theme.System
|
||||
import com.github.gezimos.inkos.data.Prefs
|
||||
import com.github.gezimos.inkos.helper.getHexForOpacity
|
||||
import com.github.gezimos.inkos.helper.isSystemInDarkMode
|
||||
import com.github.gezimos.inkos.helper.utils.EinkScrollBehavior
|
||||
import com.github.gezimos.inkos.helper.utils.PrivateSpaceManager
|
||||
import com.github.gezimos.inkos.listener.DeviceAdmin
|
||||
import com.github.gezimos.inkos.style.SettingsTheme
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.DashedSeparator
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.FullLineSeparator
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.PageHeader
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.PageIndicator
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.SettingsHomeItem
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.SolidSeparator
|
||||
|
||||
|
||||
class SettingsFragment : Fragment() {
|
||||
|
||||
private lateinit var prefs: Prefs
|
||||
private lateinit var viewModel: MainViewModel
|
||||
private lateinit var deviceManager: DevicePolicyManager
|
||||
private lateinit var componentName: ComponentName
|
||||
private var rootLayout: android.widget.LinearLayout? = null
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
prefs = Prefs(requireContext())
|
||||
val isDark = when (prefs.appTheme) {
|
||||
Light -> false
|
||||
Dark -> true
|
||||
System -> isSystemInDarkMode(requireContext())
|
||||
}
|
||||
val settingsSize = (prefs.settingsSize - 3)
|
||||
val backgroundColor = getHexForOpacity(prefs)
|
||||
val context = requireContext()
|
||||
val currentPage = intArrayOf(0)
|
||||
val pageCount = intArrayOf(1)
|
||||
|
||||
val root = android.widget.LinearLayout(context).apply {
|
||||
orientation = android.widget.LinearLayout.VERTICAL
|
||||
setBackgroundColor(backgroundColor)
|
||||
layoutParams = ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
}
|
||||
rootLayout = root
|
||||
|
||||
var bottomInsetPx = 0
|
||||
androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener(root) { _, insets ->
|
||||
val navBarInset =
|
||||
insets.getInsets(androidx.core.view.WindowInsetsCompat.Type.navigationBars()).bottom
|
||||
bottomInsetPx = navBarInset
|
||||
insets
|
||||
}
|
||||
|
||||
// Helper to update header
|
||||
fun updateHeader(headerView: androidx.compose.ui.platform.ComposeView) {
|
||||
headerView.setContent {
|
||||
LocalDensity.current
|
||||
// Remove bottomInsetDp from header
|
||||
SettingsTheme(isDark) {
|
||||
Column(Modifier.fillMaxWidth()) {
|
||||
PageHeader(
|
||||
iconRes = R.drawable.ic_home,
|
||||
title = stringResource(R.string.settings_name),
|
||||
onClick = { findNavController().popBackStack() },
|
||||
showStatusBar = prefs.showStatusBar,
|
||||
pageIndicator = {
|
||||
PageIndicator(
|
||||
currentPage = currentPage[0],
|
||||
pageCount = pageCount[0],
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else TextUnit.Unspecified
|
||||
)
|
||||
},
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else TextUnit.Unspecified
|
||||
)
|
||||
SolidSeparator(isDark = isDark)
|
||||
Spacer(modifier = Modifier.height(SettingsTheme.color.horizontalPadding))
|
||||
// (No bottomInsetDp here)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add sticky header ComposeView
|
||||
val headerView = androidx.compose.ui.platform.ComposeView(context)
|
||||
updateHeader(headerView)
|
||||
root.addView(headerView)
|
||||
|
||||
// Add scrollable settings content
|
||||
val nestedScrollView = androidx.core.widget.NestedScrollView(context).apply {
|
||||
isFillViewport = true
|
||||
setBackgroundColor(backgroundColor)
|
||||
addView(
|
||||
androidx.compose.ui.platform.ComposeView(context).apply {
|
||||
setContent {
|
||||
val density = LocalDensity.current
|
||||
val bottomInsetDp = with(density) { bottomInsetPx.toDp() }
|
||||
SettingsTheme(isDark) {
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
Column {
|
||||
SettingsAllInOne(settingsSize.sp)
|
||||
if (bottomInsetDp > 0.dp) {
|
||||
Spacer(modifier = Modifier.height(bottomInsetDp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
)
|
||||
}
|
||||
EinkScrollBehavior(context).attachToScrollView(nestedScrollView)
|
||||
root.addView(
|
||||
nestedScrollView,
|
||||
ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
)
|
||||
|
||||
// --- Calculate pages and listen for scroll changes ---
|
||||
fun getCurrentPageIndex(
|
||||
scrollY: Int,
|
||||
viewportHeight: Int,
|
||||
contentHeight: Int,
|
||||
pageCount: Int
|
||||
): Int {
|
||||
if (contentHeight <= viewportHeight) return 0
|
||||
val overlap = (viewportHeight * 0.2).toInt()
|
||||
val scrollStep = viewportHeight - overlap
|
||||
val maxScroll = (contentHeight - viewportHeight).coerceAtLeast(1)
|
||||
val clampedScrollY = scrollY.coerceIn(0, maxScroll)
|
||||
val page = Math.round(clampedScrollY.toFloat() / scrollStep)
|
||||
return page.coerceIn(0, pageCount - 1)
|
||||
}
|
||||
nestedScrollView.viewTreeObserver.addOnGlobalLayoutListener {
|
||||
val contentHeight = nestedScrollView.getChildAt(0)?.height ?: 1
|
||||
val viewportHeight = nestedScrollView.height.takeIf { it > 0 } ?: 1
|
||||
val overlap = (viewportHeight * 0.2).toInt()
|
||||
val scrollStep = viewportHeight - overlap
|
||||
val pages =
|
||||
Math.ceil(((contentHeight - viewportHeight).toDouble() / scrollStep.toDouble()))
|
||||
.toInt() + 1
|
||||
pageCount[0] = pages
|
||||
val scrollY = nestedScrollView.scrollY
|
||||
currentPage[0] = getCurrentPageIndex(scrollY, viewportHeight, contentHeight, pages)
|
||||
updateHeader(headerView)
|
||||
}
|
||||
nestedScrollView.setOnScrollChangeListener { _, _, scrollY, _, _ ->
|
||||
val contentHeight = nestedScrollView.getChildAt(0)?.height ?: 1
|
||||
val viewportHeight = nestedScrollView.height.takeIf { it > 0 } ?: 1
|
||||
val overlap = (viewportHeight * 0.2).toInt()
|
||||
val scrollStep = viewportHeight - overlap
|
||||
val pages =
|
||||
Math.ceil(((contentHeight - viewportHeight).toDouble() / scrollStep.toDouble()))
|
||||
.toInt() + 1
|
||||
pageCount[0] = pages
|
||||
currentPage[0] = getCurrentPageIndex(scrollY, viewportHeight, contentHeight, pages)
|
||||
updateHeader(headerView)
|
||||
}
|
||||
return root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
// Eink refresh: flash overlay if enabled
|
||||
com.github.gezimos.inkos.helper.utils.EinkRefreshHelper.refreshEink(
|
||||
requireContext(), prefs, null, useActivityRoot = true
|
||||
)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
// Eink refresh: flash overlay if enabled
|
||||
com.github.gezimos.inkos.helper.utils.EinkRefreshHelper.refreshEink(
|
||||
requireContext(), prefs, null, useActivityRoot = true
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SettingsAllInOne(fontSize: TextUnit = TextUnit.Unspecified) {
|
||||
val navController = findNavController()
|
||||
val isDark = isSystemInDarkMode(requireContext())
|
||||
val titleFontSize = if (fontSize.isSpecified) (fontSize.value * 1.5).sp else fontSize
|
||||
val iconSize = if (fontSize.isSpecified) tuToDp((fontSize * 0.8)) else tuToDp(fontSize)
|
||||
val privateSpaceManager = PrivateSpaceManager(requireContext())
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
FullLineSeparator(isDark = isDark)
|
||||
SettingsHomeItem(
|
||||
title = stringResource(R.string.settings_features_title),
|
||||
titleFontSize = titleFontSize,
|
||||
iconSize = iconSize,
|
||||
onClick = { showFeaturesSettings() },
|
||||
)
|
||||
DashedSeparator(isDark = isDark)
|
||||
SettingsHomeItem(
|
||||
title = stringResource(R.string.fonts_settings_title),
|
||||
titleFontSize = titleFontSize,
|
||||
iconSize = iconSize,
|
||||
onClick = { showFontsSettings() },
|
||||
)
|
||||
DashedSeparator(isDark = isDark)
|
||||
SettingsHomeItem(
|
||||
title = stringResource(R.string.settings_look_feel_title),
|
||||
titleFontSize = titleFontSize,
|
||||
iconSize = iconSize,
|
||||
onClick = { showLookFeelSettings() },
|
||||
)
|
||||
DashedSeparator(isDark = isDark)
|
||||
SettingsHomeItem(
|
||||
title = stringResource(R.string.settings_gestures_title),
|
||||
titleFontSize = titleFontSize,
|
||||
iconSize = iconSize,
|
||||
onClick = { showGesturesSettings() },
|
||||
)
|
||||
DashedSeparator(isDark = isDark)
|
||||
SettingsHomeItem(
|
||||
title = stringResource(R.string.notification_section),
|
||||
titleFontSize = titleFontSize,
|
||||
iconSize = iconSize,
|
||||
onClick = { showNotificationSettings() },
|
||||
)
|
||||
DashedSeparator(isDark = isDark)
|
||||
if (privateSpaceManager.isPrivateSpaceSupported() &&
|
||||
privateSpaceManager.isPrivateSpaceSetUp(showToast = false, launchSettings = false)
|
||||
) {
|
||||
SettingsHomeItem(
|
||||
title = stringResource(R.string.private_space),
|
||||
titleFontSize = titleFontSize,
|
||||
iconSize = iconSize,
|
||||
onClick = {
|
||||
privateSpaceManager.togglePrivateSpaceLock(
|
||||
showToast = true,
|
||||
launchSettings = true
|
||||
)
|
||||
}
|
||||
)
|
||||
DashedSeparator(isDark = isDark)
|
||||
}
|
||||
SettingsHomeItem(
|
||||
title = stringResource(R.string.settings_advanced_title),
|
||||
titleFontSize = titleFontSize,
|
||||
iconSize = iconSize,
|
||||
onClick = { showAdvancedSettings() },
|
||||
)
|
||||
DashedSeparator(isDark = isDark)
|
||||
SettingsHomeItem(
|
||||
title = "Open App Drawer",
|
||||
titleFontSize = titleFontSize,
|
||||
iconSize = iconSize,
|
||||
onClick = {
|
||||
navController.navigate(
|
||||
R.id.appDrawerListFragment,
|
||||
bundleOf("flag" to AppDrawerFlag.LaunchApp.toString())
|
||||
)
|
||||
},
|
||||
)
|
||||
DashedSeparator(isDark = isDark)
|
||||
SettingsHomeItem(
|
||||
title = stringResource(R.string.settings_exit_inkos_title),
|
||||
titleFontSize = titleFontSize,
|
||||
iconSize = iconSize,
|
||||
onClick = { exitLauncher() },
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun tuToDp(textUnit: TextUnit): Dp {
|
||||
val density = LocalDensity.current.density
|
||||
val scaledDensity = LocalDensity.current.fontScale
|
||||
val dpValue = textUnit.value * (density / scaledDensity)
|
||||
return dpValue.dp
|
||||
}
|
||||
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
@Suppress("DEPRECATION")
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
prefs = Prefs(requireContext())
|
||||
viewModel = activity?.run {
|
||||
ViewModelProvider(this)[MainViewModel::class.java]
|
||||
} ?: throw Exception("Invalid Activity")
|
||||
|
||||
viewModel.isinkosDefault()
|
||||
|
||||
deviceManager =
|
||||
context?.getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
|
||||
componentName = ComponentName(requireContext(), DeviceAdmin::class.java)
|
||||
checkAdminPermission()
|
||||
}
|
||||
|
||||
private fun checkAdminPermission() {
|
||||
val isAdmin: Boolean = deviceManager.isAdminActive(componentName)
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P)
|
||||
prefs.lockModeOn = isAdmin
|
||||
}
|
||||
|
||||
private fun showFeaturesSettings() {
|
||||
findNavController().navigate(
|
||||
R.id.action_settingsFragment_to_settingsFeaturesFragment,
|
||||
)
|
||||
}
|
||||
|
||||
private fun showFontsSettings() {
|
||||
findNavController().navigate(
|
||||
R.id.action_settingsFragment_to_fontsFragment
|
||||
)
|
||||
}
|
||||
|
||||
private fun showLookFeelSettings() {
|
||||
findNavController().navigate(
|
||||
R.id.action_settingsFragment_to_settingsLookFeelFragment,
|
||||
)
|
||||
}
|
||||
|
||||
private fun showGesturesSettings() {
|
||||
findNavController().navigate(
|
||||
R.id.action_settingsFragment_to_settingsGesturesFragment,
|
||||
)
|
||||
}
|
||||
|
||||
private fun showHiddenApps() {
|
||||
viewModel.getHiddenApps()
|
||||
findNavController().navigate(
|
||||
R.id.action_settingsFragment_to_appListFragment,
|
||||
bundleOf("flag" to AppDrawerFlag.HiddenApps.toString())
|
||||
)
|
||||
}
|
||||
|
||||
private fun showFavoriteApps() {
|
||||
findNavController().navigate(
|
||||
R.id.action_settingsFragment_to_appFavoriteFragment,
|
||||
bundleOf("flag" to AppDrawerFlag.SetHomeApp.toString())
|
||||
)
|
||||
}
|
||||
|
||||
private fun showAdvancedSettings() {
|
||||
findNavController().navigate(
|
||||
R.id.action_settingsFragment_to_settingsAdvancedFragment,
|
||||
)
|
||||
}
|
||||
|
||||
private fun showNotificationSettings() {
|
||||
findNavController().navigate(
|
||||
R.id.action_settingsFragment_to_notificationSettingsFragment
|
||||
)
|
||||
}
|
||||
|
||||
private fun exitLauncher() {
|
||||
val intent = Intent(Intent.ACTION_MAIN).apply {
|
||||
addCategory(Intent.CATEGORY_HOME)
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
}
|
||||
startActivity(Intent.createChooser(intent, "Choose your launcher"))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,388 @@
|
||||
package com.github.gezimos.inkos.ui.compose
|
||||
|
||||
import android.content.Intent
|
||||
import android.provider.Settings
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.interaction.collectIsFocusedAsState
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.asPaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.navigationBars
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.ColorFilter
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.github.gezimos.inkos.R
|
||||
import com.github.gezimos.inkos.data.Constants
|
||||
import com.github.gezimos.inkos.data.Prefs
|
||||
import com.github.gezimos.inkos.style.SettingsTheme
|
||||
|
||||
object OnboardingScreen {
|
||||
|
||||
@Composable
|
||||
fun Show(
|
||||
onFinish: () -> Unit = {},
|
||||
onRequestNotificationPermission: (() -> Unit)? = null
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val prefs = remember { Prefs(context) }
|
||||
var pushNotificationsEnabled by remember { mutableStateOf(prefs.pushNotificationsEnabled) }
|
||||
var showClock by remember { mutableStateOf(prefs.showClock) }
|
||||
var showBattery by remember { mutableStateOf(prefs.showBattery) }
|
||||
var showStatusBar by remember { mutableStateOf(prefs.showStatusBar) }
|
||||
|
||||
// State for onboarding page
|
||||
var page by remember { mutableStateOf(prefs.onboardingPage) }
|
||||
val totalPages = 3
|
||||
val settingsSize = (prefs.settingsSize - 3)
|
||||
val titleFontSize = (settingsSize * 1.5).sp
|
||||
|
||||
// Persist onboarding page index when it changes
|
||||
LaunchedEffect(page) {
|
||||
prefs.onboardingPage = page
|
||||
}
|
||||
|
||||
// Determine background color using the same logic as HomeFragment/Prefs
|
||||
val isDark = when (prefs.appTheme) {
|
||||
Constants.Theme.Light -> false
|
||||
Constants.Theme.Dark -> true
|
||||
Constants.Theme.System -> com.github.gezimos.inkos.helper.isSystemInDarkMode(
|
||||
context
|
||||
)
|
||||
}
|
||||
val backgroundColor = when (prefs.appTheme) {
|
||||
Constants.Theme.System ->
|
||||
if (com.github.gezimos.inkos.helper.isSystemInDarkMode(context)) Color.Black else Color.White
|
||||
|
||||
Constants.Theme.Dark -> Color.Black
|
||||
Constants.Theme.Light -> Color.White
|
||||
}
|
||||
val topPadding = if (prefs.showStatusBar) 48.dp else 48.dp
|
||||
// Calculate bottom padding for nav bar/gestures
|
||||
val bottomPadding = WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding()
|
||||
SettingsTheme(isDark = isDark) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.fillMaxHeight()
|
||||
.background(backgroundColor)
|
||||
) {
|
||||
// Top-aligned welcome and description
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = topPadding),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Top
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.ic_ink),
|
||||
contentDescription = "InkOS Logo",
|
||||
colorFilter = ColorFilter.tint(SettingsTheme.typography.title.color ?: Color.Unspecified),
|
||||
modifier = Modifier
|
||||
.width(24.dp)
|
||||
.padding(bottom = 8.dp)
|
||||
.align(Alignment.CenterHorizontally)
|
||||
)
|
||||
Text(
|
||||
text = "inkOS",
|
||||
style = SettingsTheme.typography.title,
|
||||
fontSize = 32.sp,
|
||||
modifier = Modifier.padding(bottom = 8.dp)
|
||||
)
|
||||
Text(
|
||||
text = "A text based launcher.",
|
||||
style = SettingsTheme.typography.body,
|
||||
fontSize = 18.sp,
|
||||
modifier = Modifier
|
||||
.padding(start = 36.dp, end = 36.dp)
|
||||
.fillMaxWidth()
|
||||
.align(Alignment.CenterHorizontally),
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
}
|
||||
// Vertically centered switches, 3 per page
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.align(Alignment.Center)
|
||||
.padding(top = 64.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
// FocusRequesters for first item on each page
|
||||
val focusRequesterPage0 = remember { FocusRequester() }
|
||||
val focusRequesterPage1 = remember { FocusRequester() }
|
||||
val focusRequesterPage2 = remember { FocusRequester() }
|
||||
// Move focus to first item on page change
|
||||
var einkRefreshEnabled by remember { mutableStateOf(prefs.einkRefreshEnabled) }
|
||||
var vibrationFeedback by remember { mutableStateOf(prefs.useVibrationForPaging) }
|
||||
var volumeKeyNavigation by remember { mutableStateOf(prefs.useVolumeKeysForPages) }
|
||||
var lastToggledSwitch by remember { mutableStateOf<String?>(null) }
|
||||
when (page) {
|
||||
0 -> {
|
||||
// Page 1: Status Bar, Clock, Battery
|
||||
SettingsComposable.SettingsSwitch(
|
||||
text = "Show Status Bar",
|
||||
fontSize = titleFontSize,
|
||||
defaultState = showStatusBar,
|
||||
modifier = Modifier.focusRequester(focusRequesterPage0),
|
||||
onCheckedChange = {
|
||||
showStatusBar = it
|
||||
prefs.showStatusBar = it
|
||||
}
|
||||
)
|
||||
LaunchedEffect(page) {
|
||||
focusRequesterPage0.requestFocus()
|
||||
}
|
||||
SettingsComposable.FullLineSeparator(isDark = false)
|
||||
SettingsComposable.SettingsSwitch(
|
||||
text = "Show Clock",
|
||||
fontSize = titleFontSize,
|
||||
defaultState = showClock,
|
||||
onCheckedChange = {
|
||||
showClock = it
|
||||
prefs.showClock = it
|
||||
}
|
||||
)
|
||||
SettingsComposable.FullLineSeparator(isDark = false)
|
||||
SettingsComposable.SettingsSwitch(
|
||||
text = "Show Battery",
|
||||
fontSize = titleFontSize,
|
||||
defaultState = showBattery,
|
||||
onCheckedChange = {
|
||||
showBattery = it
|
||||
prefs.showBattery = it
|
||||
}
|
||||
)
|
||||
}
|
||||
1 -> {
|
||||
// Page 2: Einkrefresh, Vibration feedback, Volume key navigation
|
||||
SettingsComposable.SettingsSwitch(
|
||||
text = "Eink Refresh",
|
||||
fontSize = titleFontSize,
|
||||
defaultState = einkRefreshEnabled,
|
||||
modifier = Modifier.focusRequester(focusRequesterPage1),
|
||||
onCheckedChange = {
|
||||
einkRefreshEnabled = it
|
||||
prefs.einkRefreshEnabled = it
|
||||
if (it) lastToggledSwitch = "eink" else if (lastToggledSwitch == "eink") lastToggledSwitch = null
|
||||
}
|
||||
)
|
||||
LaunchedEffect(page) {
|
||||
focusRequesterPage1.requestFocus()
|
||||
}
|
||||
SettingsComposable.FullLineSeparator(isDark = false)
|
||||
SettingsComposable.SettingsSwitch(
|
||||
text = "Vibration Feedback",
|
||||
fontSize = titleFontSize,
|
||||
defaultState = vibrationFeedback,
|
||||
onCheckedChange = {
|
||||
vibrationFeedback = it
|
||||
prefs.useVibrationForPaging = it
|
||||
if (it) lastToggledSwitch = "vibration" else if (lastToggledSwitch == "vibration") lastToggledSwitch = null
|
||||
}
|
||||
)
|
||||
SettingsComposable.FullLineSeparator(isDark = false)
|
||||
SettingsComposable.SettingsSwitch(
|
||||
text = "Volume Key Navigation",
|
||||
fontSize = titleFontSize,
|
||||
defaultState = volumeKeyNavigation,
|
||||
onCheckedChange = {
|
||||
volumeKeyNavigation = it
|
||||
prefs.useVolumeKeysForPages = it
|
||||
if (it) lastToggledSwitch = "volume" else if (lastToggledSwitch == "volume") lastToggledSwitch = null
|
||||
}
|
||||
)
|
||||
}
|
||||
2 -> {
|
||||
// Page 3: Notifications first, then theme mode
|
||||
SettingsComposable.SettingsSwitch(
|
||||
text = "Enable Notifications",
|
||||
fontSize = titleFontSize,
|
||||
defaultState = pushNotificationsEnabled,
|
||||
modifier = Modifier.focusRequester(focusRequesterPage2),
|
||||
onCheckedChange = {
|
||||
pushNotificationsEnabled = it
|
||||
prefs.pushNotificationsEnabled = it
|
||||
if (it) {
|
||||
val intent = Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
context.startActivity(intent)
|
||||
onRequestNotificationPermission?.invoke()
|
||||
}
|
||||
}
|
||||
)
|
||||
LaunchedEffect(page) {
|
||||
focusRequesterPage2.requestFocus()
|
||||
}
|
||||
SettingsComposable.FullLineSeparator(isDark = false)
|
||||
// Theme Mode selector (cycles through System, Light, Dark)
|
||||
var themeMode by remember { mutableStateOf(prefs.appTheme) }
|
||||
SettingsComposable.SettingsSelect(
|
||||
title = "Theme Mode",
|
||||
option = themeMode.name,
|
||||
fontSize = titleFontSize,
|
||||
onClick = {
|
||||
// Cycle through System -> Light -> Dark -> System
|
||||
val next = when (themeMode) {
|
||||
Constants.Theme.System -> Constants.Theme.Light
|
||||
Constants.Theme.Light -> Constants.Theme.Dark
|
||||
Constants.Theme.Dark -> Constants.Theme.System
|
||||
}
|
||||
themeMode = next
|
||||
prefs.appTheme = next
|
||||
}
|
||||
)
|
||||
SettingsComposable.FullLineSeparator(isDark = false)
|
||||
SettingsComposable.SettingsHomeItem(
|
||||
title = "Set as Default Launcher",
|
||||
onClick = {
|
||||
val intent = Intent(Settings.ACTION_HOME_SETTINGS)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
context.startActivity(intent)
|
||||
},
|
||||
titleFontSize = titleFontSize
|
||||
)
|
||||
}
|
||||
}
|
||||
SettingsComposable.FullLineSeparator(isDark = false)
|
||||
// Dynamic tip based on enabled switches
|
||||
val tipText = when {
|
||||
page == 0 && showBattery -> "Shows the battery % at the bottom."
|
||||
page == 0 && showClock -> "Clock widget appears above apps."
|
||||
page == 0 && showStatusBar -> "This will show the status bar."
|
||||
page == 1 && lastToggledSwitch == "eink" && einkRefreshEnabled -> "To clear ghosting in Mudita Komapkt"
|
||||
page == 1 && lastToggledSwitch == "vibration" && vibrationFeedback -> "Vibration feedback on swipes"
|
||||
page == 1 && lastToggledSwitch == "volume" && volumeKeyNavigation -> "Use vol. keys to change pages/values."
|
||||
page == 1 && einkRefreshEnabled -> "Screen refresh to clear ghosting"
|
||||
page == 1 && vibrationFeedback -> "Vibration feedback on swipes"
|
||||
page == 1 && volumeKeyNavigation -> "Use vol. keys to change pages/values."
|
||||
else -> null
|
||||
}
|
||||
val defaultTip = if (page == 2) "Tip: Longpress 9 in home for settings" else "Tip: Longpress in home for settings"
|
||||
if (tipText != null) {
|
||||
Text(
|
||||
text = tipText,
|
||||
style = SettingsTheme.typography.body,
|
||||
fontSize = 14.sp,
|
||||
modifier = Modifier
|
||||
.padding(start = 36.dp, end = 36.dp, top = 24.dp)
|
||||
.fillMaxWidth()
|
||||
.align(Alignment.CenterHorizontally),
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
} else {
|
||||
Text(
|
||||
text = defaultTip,
|
||||
style = SettingsTheme.typography.body,
|
||||
fontSize = 14.sp,
|
||||
modifier = Modifier
|
||||
.padding(start = 36.dp, end = 36.dp, top = 24.dp)
|
||||
.fillMaxWidth()
|
||||
.align(Alignment.CenterHorizontally),
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
}
|
||||
}
|
||||
// Bottom-aligned navigation buttons
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomCenter)
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = bottomPadding),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
// Back button
|
||||
val backInteractionSource = remember { MutableInteractionSource() }
|
||||
val backIsFocused = backInteractionSource.collectIsFocusedAsState().value
|
||||
val focusColor = if (isDark) Color(0x33FFFFFF) else Color(0x22000000)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.heightIn(min = 56.dp)
|
||||
.then(if (backIsFocused) Modifier.background(focusColor) else Modifier)
|
||||
.clickable(
|
||||
enabled = page > 0,
|
||||
interactionSource = backInteractionSource,
|
||||
indication = null
|
||||
) {
|
||||
if (page > 0) page--
|
||||
},
|
||||
contentAlignment = Alignment.CenterStart
|
||||
) {
|
||||
if (page > 0) {
|
||||
Text(
|
||||
text = "Back",
|
||||
style = SettingsTheme.typography.title,
|
||||
fontSize = titleFontSize,
|
||||
modifier = Modifier.padding(start = 24.dp, end = 24.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
// Page indicator in the center
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.heightIn(min = 56.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
SettingsComposable.PageIndicator(
|
||||
currentPage = page,
|
||||
pageCount = totalPages
|
||||
)
|
||||
}
|
||||
// Next/Finish button
|
||||
val nextInteractionSource = remember { MutableInteractionSource() }
|
||||
val nextIsFocused = nextInteractionSource.collectIsFocusedAsState().value
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.heightIn(min = 56.dp)
|
||||
.then(if (nextIsFocused) Modifier.background(focusColor) else Modifier)
|
||||
.clickable(
|
||||
interactionSource = nextInteractionSource,
|
||||
indication = null
|
||||
) {
|
||||
if (page < totalPages - 1) page++ else onFinish()
|
||||
},
|
||||
contentAlignment = Alignment.CenterEnd
|
||||
) {
|
||||
Text(
|
||||
text = if (page < totalPages - 1) "Next" else "Finish",
|
||||
style = SettingsTheme.typography.title,
|
||||
fontSize = titleFontSize,
|
||||
modifier = Modifier.padding(start = 24.dp, end = 24.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,443 @@
|
||||
package com.github.gezimos.inkos.ui.compose
|
||||
|
||||
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.interaction.collectIsFocusedAsState
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material.Switch
|
||||
import androidx.compose.material.SwitchDefaults
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.ColorFilter
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.TextUnit
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.isSpecified
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.github.gezimos.inkos.style.SettingsTheme
|
||||
|
||||
object SettingsComposable {
|
||||
|
||||
@Composable
|
||||
fun PageIndicator(
|
||||
currentPage: Int,
|
||||
pageCount: Int,
|
||||
modifier: Modifier = Modifier,
|
||||
titleFontSize: TextUnit = TextUnit.Unspecified
|
||||
) {
|
||||
// Use the current theme to determine dark mode
|
||||
val isDark = androidx.compose.foundation.isSystemInDarkTheme()
|
||||
val activeRes = com.github.gezimos.inkos.R.drawable.ic_current_page
|
||||
val inactiveRes = com.github.gezimos.inkos.R.drawable.ic_new_page
|
||||
val tintColor = if (isDark) Color.White else Color.Black
|
||||
Row(
|
||||
modifier = modifier,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.End
|
||||
) {
|
||||
for (i in 0 until pageCount) {
|
||||
Image(
|
||||
painter = painterResource(id = if (i == currentPage) activeRes else inactiveRes),
|
||||
contentDescription = null,
|
||||
colorFilter = ColorFilter.tint(tintColor),
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 2.dp)
|
||||
.size(if (i == currentPage) 12.dp else 10.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun PageHeader(
|
||||
@DrawableRes iconRes: Int,
|
||||
title: String,
|
||||
iconSize: Dp = 24.dp,
|
||||
onClick: () -> Unit = {},
|
||||
showStatusBar: Boolean = false,
|
||||
modifier: Modifier = Modifier,
|
||||
pageIndicator: (@Composable () -> Unit)? = null,
|
||||
titleFontSize: TextUnit = TextUnit.Unspecified // Use titleFontSize
|
||||
) {
|
||||
Row(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = if (showStatusBar) 36.dp else 12.dp)
|
||||
.padding(bottom = 12.dp)
|
||||
.padding(horizontal = SettingsTheme.color.horizontalPadding),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
// Back icon
|
||||
Image(
|
||||
painter = painterResource(id = iconRes),
|
||||
contentDescription = title,
|
||||
colorFilter = ColorFilter.tint(SettingsTheme.color.image),
|
||||
modifier = Modifier
|
||||
.clickable(onClick = onClick)
|
||||
.size(iconSize)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
|
||||
// Title centered
|
||||
Box(
|
||||
modifier = Modifier.weight(1f),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
SettingsTitle(
|
||||
text = title,
|
||||
fontSize = titleFontSize,
|
||||
)
|
||||
}
|
||||
|
||||
// Page indicator right-aligned, no extra padding
|
||||
if (pageIndicator != null) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(start = 8.dp)
|
||||
.align(Alignment.CenterVertically)
|
||||
) {
|
||||
pageIndicator()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun TopMainHeader(
|
||||
@DrawableRes iconRes: Int,
|
||||
title: String,
|
||||
iconSize: Dp = 96.dp, // Default size for the icon
|
||||
fontSize: TextUnit = 24.sp, // Default font size for the title
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = SettingsTheme.color.horizontalPadding),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
// Image Icon
|
||||
Image(
|
||||
painter = painterResource(id = iconRes),
|
||||
contentDescription = title,
|
||||
modifier = Modifier
|
||||
.size(iconSize)
|
||||
.padding(bottom = 16.dp) // Bottom margin like in XML
|
||||
)
|
||||
|
||||
// Title Text
|
||||
Text(
|
||||
text = title,
|
||||
style = SettingsTheme.typography.title,
|
||||
fontSize = fontSize,
|
||||
modifier = Modifier
|
||||
.padding(bottom = 24.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SettingsHomeItem(
|
||||
title: String,
|
||||
imageVector: ImageVector? = null,
|
||||
onClick: () -> Unit = {},
|
||||
titleFontSize: TextUnit = TextUnit.Unspecified,
|
||||
iconSize: Dp = 18.dp,
|
||||
) {
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
val isFocused = interactionSource.collectIsFocusedAsState().value
|
||||
val isDark = androidx.compose.foundation.isSystemInDarkTheme()
|
||||
val focusColor = if (isDark) Color(0x33FFFFFF) else Color(0x22000000)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.then(
|
||||
if (isFocused) Modifier.background(focusColor) else Modifier
|
||||
)
|
||||
.clickable(onClick = onClick, interactionSource = interactionSource, indication = null)
|
||||
.padding(horizontal = SettingsTheme.color.horizontalPadding)
|
||||
.padding(vertical = 16.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
if (imageVector != null) {
|
||||
Image(
|
||||
imageVector,
|
||||
contentDescription = title,
|
||||
colorFilter = ColorFilter.tint(SettingsTheme.color.image),
|
||||
modifier = Modifier
|
||||
.size(24.dp)
|
||||
)
|
||||
Spacer(
|
||||
modifier = Modifier
|
||||
.width(16.dp)
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = title,
|
||||
style = SettingsTheme.typography.title,
|
||||
fontSize = titleFontSize,
|
||||
fontWeight = FontWeight.Bold,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
// Chevron right icon
|
||||
Image(
|
||||
painter = painterResource(id = com.github.gezimos.inkos.R.drawable.ic_chevron_right),
|
||||
contentDescription = null,
|
||||
colorFilter = ColorFilter.tint(SettingsTheme.color.image),
|
||||
modifier = Modifier.size(16.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SettingsTitle(
|
||||
text: String,
|
||||
modifier: Modifier = Modifier,
|
||||
fontSize: TextUnit = TextUnit.Unspecified
|
||||
) {
|
||||
// Make SettingsTitle same height as SettingsSwitch/Select and capitalize text
|
||||
val effectiveFontSize = if (fontSize.isSpecified) {
|
||||
(fontSize.value * 0.8).sp
|
||||
} else {
|
||||
14.sp // fallback to a small size
|
||||
}
|
||||
Row(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 16.dp), // changed from 24.dp to 16.dp
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = text.uppercase(),
|
||||
style = SettingsTheme.typography.header,
|
||||
fontSize = effectiveFontSize,
|
||||
fontWeight = FontWeight.Bold,
|
||||
modifier = Modifier.padding(start = SettingsTheme.color.horizontalPadding)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SettingsSwitch(
|
||||
text: String,
|
||||
fontSize: TextUnit = TextUnit.Unspecified,
|
||||
defaultState: Boolean = false,
|
||||
enabled: Boolean = true,
|
||||
modifier: Modifier = Modifier,
|
||||
onCheckedChange: (Boolean) -> Unit
|
||||
) {
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
val isFocused = interactionSource.collectIsFocusedAsState().value
|
||||
val isDark = androidx.compose.foundation.isSystemInDarkTheme()
|
||||
val focusColor = if (isDark) Color(0x33FFFFFF) else Color(0x22000000)
|
||||
Row(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.then(
|
||||
if (isFocused) Modifier.background(focusColor) else Modifier
|
||||
)
|
||||
.clickable(enabled = enabled, onClick = { onCheckedChange(!defaultState) }, interactionSource = interactionSource, indication = null)
|
||||
.padding(horizontal = SettingsTheme.color.horizontalPadding),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = text,
|
||||
style = if (fontSize.isSpecified) {
|
||||
SettingsTheme.typography.title.copy(fontSize = fontSize)
|
||||
} else SettingsTheme.typography.title,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(vertical = 16.dp), // vertical padding only on text
|
||||
color = if (enabled) {
|
||||
SettingsTheme.typography.title.color
|
||||
} else Color.Gray
|
||||
)
|
||||
Switch(
|
||||
checked = defaultState,
|
||||
onCheckedChange = { onCheckedChange(it) },
|
||||
enabled = enabled,
|
||||
colors = SwitchDefaults.colors(
|
||||
checkedThumbColor = SettingsTheme.color.settings,
|
||||
checkedTrackColor = SettingsTheme.color.settings.copy(alpha = 0.5f),
|
||||
uncheckedThumbColor = SettingsTheme.color.settings,
|
||||
uncheckedTrackColor = Color.Gray
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SettingsSelect(
|
||||
title: String,
|
||||
option: String,
|
||||
fontSize: TextUnit = 24.sp, // Default font size for the title
|
||||
fontColor: Color = SettingsTheme.typography.title.color,
|
||||
enabled: Boolean = true,
|
||||
onClick: () -> Unit = {},
|
||||
) {
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
val isFocused = interactionSource.collectIsFocusedAsState().value
|
||||
val isDark = androidx.compose.foundation.isSystemInDarkTheme()
|
||||
val focusColor = if (isDark) Color(0x33FFFFFF) else Color(0x22000000)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.then(
|
||||
if (isFocused) Modifier.background(focusColor) else Modifier
|
||||
)
|
||||
.clickable(enabled = enabled, onClick = onClick, interactionSource = interactionSource, indication = null)
|
||||
.padding(vertical = 16.dp)
|
||||
.padding(horizontal = SettingsTheme.color.horizontalPadding),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = title,
|
||||
style = SettingsTheme.typography.title,
|
||||
fontSize = fontSize,
|
||||
modifier = Modifier.weight(1f),
|
||||
color = if (enabled) SettingsTheme.typography.title.color else Color.Gray
|
||||
)
|
||||
|
||||
Text(
|
||||
text = option,
|
||||
style = SettingsTheme.typography.title,
|
||||
fontSize = fontSize,
|
||||
color = if (enabled) fontColor else Color.Gray
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SettingsSelectWithColorPreview(
|
||||
title: String,
|
||||
hexColor: String,
|
||||
previewColor: Color,
|
||||
fontSize: TextUnit = 24.sp,
|
||||
enabled: Boolean = true,
|
||||
onClick: () -> Unit = {},
|
||||
) {
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
val isFocused = interactionSource.collectIsFocusedAsState().value
|
||||
val isDark = androidx.compose.foundation.isSystemInDarkTheme()
|
||||
val focusColor = if (isDark) Color(0x33FFFFFF) else Color(0x22000000)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.then(
|
||||
if (isFocused) Modifier.background(focusColor) else Modifier
|
||||
)
|
||||
.clickable(enabled = enabled, onClick = onClick, interactionSource = interactionSource, indication = null)
|
||||
.padding(vertical = 12.dp)
|
||||
.padding(horizontal = SettingsTheme.color.horizontalPadding),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = title,
|
||||
style = SettingsTheme.typography.title,
|
||||
fontSize = fontSize,
|
||||
modifier = Modifier.weight(1f),
|
||||
color = if (enabled) SettingsTheme.typography.title.color else Color.Gray
|
||||
)
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
modifier = Modifier.clickable(enabled = enabled, onClick = onClick)
|
||||
) {
|
||||
Text(
|
||||
text = hexColor,
|
||||
style = SettingsTheme.typography.title,
|
||||
fontSize = fontSize,
|
||||
color = if (enabled) SettingsTheme.typography.title.color else Color.Gray
|
||||
)
|
||||
|
||||
Canvas(
|
||||
modifier = Modifier
|
||||
.size(24.dp)
|
||||
.border(
|
||||
width = 1.dp,
|
||||
color = SettingsTheme.color.border,
|
||||
shape = CircleShape
|
||||
)
|
||||
) {
|
||||
drawCircle(color = previewColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun FullLineSeparator(isDark: Boolean) {
|
||||
val borderColor = SettingsTheme.color.border
|
||||
androidx.compose.material.Divider(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = SettingsTheme.color.horizontalPadding), // changed
|
||||
color = borderColor,
|
||||
thickness = 2.dp
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SolidSeparator(isDark: Boolean) {
|
||||
val borderColor = SettingsTheme.color.border
|
||||
androidx.compose.material.Divider(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth(),
|
||||
color = borderColor,
|
||||
thickness = 3.dp
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun DashedSeparator(isDark: Boolean) {
|
||||
val borderColor = SettingsTheme.color.border
|
||||
Canvas(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(1.dp)
|
||||
.alpha(0.85f)
|
||||
.padding(horizontal = SettingsTheme.color.horizontalPadding) // already present
|
||||
) {
|
||||
val dashWidth = 4f
|
||||
val gapWidth = 4f
|
||||
var x = 0f
|
||||
val y = size.height / 2
|
||||
while (x < size.width) {
|
||||
drawLine(
|
||||
color = borderColor,
|
||||
start = Offset(x, y),
|
||||
end = Offset((x + dashWidth).coerceAtMost(size.width), y),
|
||||
strokeWidth = size.height
|
||||
)
|
||||
x += dashWidth + gapWidth
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,598 @@
|
||||
package com.github.gezimos.inkos.ui.dialogs
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.Typeface
|
||||
import android.text.Editable
|
||||
import android.text.InputType
|
||||
import android.text.TextWatcher
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.EditText
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.ListView
|
||||
import android.widget.SeekBar
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.graphics.toColorInt
|
||||
import com.github.gezimos.inkos.R
|
||||
import com.github.gezimos.inkos.data.Constants
|
||||
import com.github.gezimos.inkos.data.Prefs
|
||||
import com.github.gezimos.inkos.helper.getTrueSystemFont
|
||||
import com.github.gezimos.inkos.helper.loadFile
|
||||
import com.github.gezimos.inkos.helper.storeFile
|
||||
import com.github.gezimos.inkos.helper.utils.AppReloader
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
||||
class DialogManager(val context: Context, val activity: Activity) {
|
||||
|
||||
private lateinit var prefs: Prefs
|
||||
|
||||
var backupRestoreDialog: AlertDialog? = null
|
||||
|
||||
fun showBackupRestoreDialog() {
|
||||
// Dismiss any existing dialog to prevent multiple dialogs open simultaneously
|
||||
backupRestoreDialog?.dismiss()
|
||||
|
||||
// Define the items for the dialog (Backup, Restore, Clear Data)
|
||||
val items = arrayOf(
|
||||
context.getString(R.string.advanced_settings_backup_restore_backup),
|
||||
context.getString(R.string.advanced_settings_backup_restore_restore),
|
||||
context.getString(R.string.advanced_settings_backup_restore_clear)
|
||||
)
|
||||
|
||||
val dialogBuilder = MaterialAlertDialogBuilder(context)
|
||||
dialogBuilder.setTitle(context.getString(R.string.advanced_settings_backup_restore_title))
|
||||
dialogBuilder.setItems(items) { _, which ->
|
||||
when (which) {
|
||||
0 -> storeFile(activity, Constants.BackupType.FullSystem)
|
||||
1 -> loadFile(activity, Constants.BackupType.FullSystem)
|
||||
2 -> confirmClearData()
|
||||
}
|
||||
}
|
||||
|
||||
// Assign the created dialog to backupRestoreDialog
|
||||
backupRestoreDialog = dialogBuilder.create()
|
||||
backupRestoreDialog?.show()
|
||||
setDialogFontForAllButtonsAndText(backupRestoreDialog, context, "settings")
|
||||
}
|
||||
|
||||
// Function to handle the Clear Data action, with a confirmation dialog
|
||||
private fun confirmClearData() {
|
||||
MaterialAlertDialogBuilder(context)
|
||||
.setTitle(context.getString(R.string.advanced_settings_backup_restore_clear_title))
|
||||
.setMessage(context.getString(R.string.advanced_settings_backup_restore_clear_description))
|
||||
.setPositiveButton(context.getString(R.string.advanced_settings_backup_restore_clear_yes)) { _, _ ->
|
||||
clearData()
|
||||
}
|
||||
.setNegativeButton(
|
||||
context.getString(R.string.advanced_settings_backup_restore_clear_no),
|
||||
null
|
||||
)
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun clearData() {
|
||||
prefs = Prefs(context)
|
||||
prefs.clear()
|
||||
|
||||
AppReloader.restartApp(context)
|
||||
}
|
||||
|
||||
var sliderDialog: AlertDialog? = null
|
||||
|
||||
fun showSliderDialog(
|
||||
context: Context,
|
||||
title: String,
|
||||
minValue: Int,
|
||||
maxValue: Int,
|
||||
currentValue: Int,
|
||||
onValueSelected: (Int) -> Unit // Callback for when the user selects a value
|
||||
) {
|
||||
// Dismiss any existing dialog to prevent multiple dialogs from being open simultaneously
|
||||
sliderDialog?.dismiss()
|
||||
|
||||
var seekBar: SeekBar
|
||||
lateinit var valueText: TextView
|
||||
|
||||
// Create a layout to hold the SeekBar and the value display
|
||||
val seekBarLayout = LinearLayout(context).apply {
|
||||
orientation = LinearLayout.VERTICAL
|
||||
gravity = Gravity.CENTER
|
||||
setPadding(16, 16, 16, 16)
|
||||
|
||||
// TextView to display the current value
|
||||
valueText = TextView(context).apply {
|
||||
text = "$currentValue"
|
||||
textSize = 16f
|
||||
gravity = Gravity.CENTER
|
||||
}
|
||||
|
||||
// Declare the seekBar outside the layout block so we can access it later
|
||||
seekBar = SeekBar(context).apply {
|
||||
min = minValue // Minimum value
|
||||
max = maxValue // Maximum value
|
||||
progress = currentValue // Default value
|
||||
setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
||||
override fun onProgressChanged(
|
||||
seekBar: SeekBar,
|
||||
progress: Int,
|
||||
fromUser: Boolean
|
||||
) {
|
||||
valueText.text = "$progress"
|
||||
}
|
||||
|
||||
override fun onStartTrackingTouch(seekBar: SeekBar) {}
|
||||
override fun onStopTrackingTouch(seekBar: SeekBar) {}
|
||||
})
|
||||
}
|
||||
|
||||
// Add TextView and SeekBar to the layout
|
||||
addView(valueText)
|
||||
addView(seekBar)
|
||||
}
|
||||
|
||||
// Set valueText font and size before showing dialog
|
||||
val prefs = Prefs(context)
|
||||
val fontFamily = prefs.getFontForContext("settings")
|
||||
val customFontPath = prefs.getCustomFontPathForContext("settings")
|
||||
val typeface = fontFamily.getFont(context, customFontPath) ?: getTrueSystemFont()
|
||||
val textSize = prefs.settingsSize.toFloat()
|
||||
valueText.typeface = typeface
|
||||
valueText.textSize = textSize
|
||||
|
||||
// Create the dialog
|
||||
val dialogBuilder = MaterialAlertDialogBuilder(context).apply {
|
||||
setTitle(title)
|
||||
setView(seekBarLayout) // Add the slider directly to the dialog
|
||||
setPositiveButton(context.getString(R.string.okay)) { _, _ ->
|
||||
// Get the progress from the seekBar now that it's accessible
|
||||
val finalValue = seekBar.progress
|
||||
onValueSelected(finalValue) // Trigger the callback with the selected value
|
||||
}
|
||||
setNegativeButton(context.getString(R.string.cancel), null)
|
||||
}
|
||||
|
||||
// Assign the created dialog to sliderDialog and show it
|
||||
sliderDialog = dialogBuilder.create()
|
||||
sliderDialog?.show()
|
||||
setDialogFontForAllButtonsAndText(sliderDialog, context, "settings")
|
||||
|
||||
// --- Volume key support for SeekBar ---
|
||||
if (prefs.useVolumeKeysForPages) {
|
||||
sliderDialog?.window?.decorView?.isFocusableInTouchMode = true
|
||||
sliderDialog?.window?.decorView?.requestFocus()
|
||||
sliderDialog?.window?.decorView?.setOnKeyListener { _, keyCode, event ->
|
||||
if (event.action == android.view.KeyEvent.ACTION_DOWN) {
|
||||
when (keyCode) {
|
||||
android.view.KeyEvent.KEYCODE_VOLUME_UP -> {
|
||||
if (seekBar.progress < seekBar.max) {
|
||||
seekBar.progress = seekBar.progress + 1
|
||||
return@setOnKeyListener true
|
||||
}
|
||||
}
|
||||
android.view.KeyEvent.KEYCODE_VOLUME_DOWN -> {
|
||||
if (seekBar.progress > seekBar.min) {
|
||||
seekBar.progress = seekBar.progress - 1
|
||||
return@setOnKeyListener true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var singleChoiceDialog: AlertDialog? = null
|
||||
|
||||
fun <T> showSingleChoiceDialog(
|
||||
context: Context,
|
||||
options: Array<T>,
|
||||
titleResId: Int,
|
||||
fonts: List<Typeface>? = null, // Optional fonts
|
||||
fontSize: Float = 18f, // Default font size
|
||||
selectedIndex: Int? = null, // Index of selected font
|
||||
isCustomFont: ((T) -> Boolean)? = null, // Function to check if font is custom
|
||||
onItemSelected: (T) -> Unit,
|
||||
onItemDeleted: ((T) -> Unit)? = null // Callback for delete
|
||||
) {
|
||||
singleChoiceDialog?.dismiss()
|
||||
|
||||
// Move selected font to the top if selectedIndex is provided
|
||||
val reorderedOptions = if (selectedIndex != null && selectedIndex in options.indices) {
|
||||
val list = options.toMutableList()
|
||||
val selected = list.removeAt(selectedIndex)
|
||||
list.add(0, selected)
|
||||
list
|
||||
} else {
|
||||
options.toList()
|
||||
}
|
||||
val reorderedFonts =
|
||||
if (fonts != null && selectedIndex != null && selectedIndex in fonts.indices) {
|
||||
val list = fonts.toMutableList()
|
||||
val selected = list.removeAt(selectedIndex)
|
||||
list.add(0, selected)
|
||||
list
|
||||
} else {
|
||||
fonts
|
||||
}
|
||||
|
||||
val itemStrings = reorderedOptions.map { option ->
|
||||
when (option) {
|
||||
is Enum<*> -> option.name
|
||||
else -> option.toString()
|
||||
}
|
||||
}
|
||||
|
||||
val dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_single_choice, null)
|
||||
val listView = dialogView.findViewById<ListView>(R.id.dialogListView)
|
||||
val titleView = dialogView.findViewById<TextView>(R.id.dialogTitle)
|
||||
val deleteButton = dialogView.findViewById<View>(R.id.dialogDeleteButton)
|
||||
|
||||
val prefs = Prefs(context)
|
||||
val fontFamily = prefs.getFontForContext("settings")
|
||||
val customFontPath = prefs.getCustomFontPathForContext("settings")
|
||||
val typeface = fontFamily.getFont(context, customFontPath) ?: getTrueSystemFont()
|
||||
val textSize = prefs.settingsSize.toFloat()
|
||||
titleView.text = context.getString(titleResId)
|
||||
titleView.typeface = typeface
|
||||
titleView.textSize = textSize
|
||||
|
||||
var selectedListIndex = 0 // Always start with the top item selected
|
||||
|
||||
val adapter =
|
||||
object : ArrayAdapter<String>(context, R.layout.item_single_choice, itemStrings) {
|
||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||
val view = convertView ?: LayoutInflater.from(context)
|
||||
.inflate(R.layout.item_single_choice, parent, false)
|
||||
val textView = view.findViewById<TextView>(R.id.text_item)
|
||||
val deleteIcon = view.findViewById<View>(R.id.delete_icon)
|
||||
|
||||
textView.text = itemStrings[position]
|
||||
textView.typeface = reorderedFonts?.getOrNull(position) ?: getTrueSystemFont()
|
||||
textView.textSize = fontSize
|
||||
|
||||
// Highlight selected item with transparent background and black outline
|
||||
if (position == selectedListIndex) {
|
||||
view.setBackgroundResource(0)
|
||||
view.background = android.graphics.drawable.GradientDrawable().apply {
|
||||
setColor(Color.TRANSPARENT)
|
||||
setStroke(3, Color.BLACK)
|
||||
cornerRadius = 16f
|
||||
}
|
||||
} else {
|
||||
view.setBackgroundResource(0)
|
||||
view.background = null
|
||||
}
|
||||
|
||||
// Show delete icon for custom fonts only
|
||||
if (isCustomFont != null && isCustomFont(reorderedOptions[position])) {
|
||||
deleteIcon.visibility = View.VISIBLE
|
||||
deleteIcon.setOnClickListener {
|
||||
onItemDeleted?.invoke(reorderedOptions[position])
|
||||
singleChoiceDialog?.dismiss()
|
||||
}
|
||||
} else {
|
||||
deleteIcon.visibility = View.GONE
|
||||
deleteIcon.setOnClickListener(null)
|
||||
}
|
||||
|
||||
return view
|
||||
}
|
||||
}
|
||||
listView.adapter = adapter
|
||||
|
||||
// Show delete button if selected is custom
|
||||
fun updateDeleteButton() {
|
||||
if (isCustomFont != null && isCustomFont(reorderedOptions[selectedListIndex])) {
|
||||
deleteButton.visibility = View.VISIBLE
|
||||
} else {
|
||||
deleteButton.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
updateDeleteButton()
|
||||
|
||||
// Handle item selection
|
||||
listView.setOnItemClickListener { parent, view, position, _ ->
|
||||
onItemSelected(reorderedOptions[position])
|
||||
singleChoiceDialog?.dismiss()
|
||||
}
|
||||
|
||||
// Handle delete button click
|
||||
deleteButton.setOnClickListener {
|
||||
onItemDeleted?.invoke(reorderedOptions[selectedListIndex])
|
||||
singleChoiceDialog?.dismiss()
|
||||
}
|
||||
|
||||
val dialogBuilder = MaterialAlertDialogBuilder(context)
|
||||
.setView(dialogView)
|
||||
|
||||
singleChoiceDialog = dialogBuilder.create()
|
||||
singleChoiceDialog?.show()
|
||||
setDialogFontForAllButtonsAndText(singleChoiceDialog, context, "settings")
|
||||
}
|
||||
|
||||
var multiChoiceDialog: AlertDialog? = null
|
||||
|
||||
fun showMultiChoiceDialog(
|
||||
context: Context,
|
||||
title: String,
|
||||
items: Array<String>,
|
||||
initialChecked: BooleanArray,
|
||||
onConfirm: (selectedIndices: List<Int>) -> Unit
|
||||
) {
|
||||
multiChoiceDialog?.dismiss()
|
||||
val checked = initialChecked.copyOf()
|
||||
val dialog = MaterialAlertDialogBuilder(context)
|
||||
.setTitle(title)
|
||||
.setMultiChoiceItems(items, checked) { _, which, isChecked ->
|
||||
checked[which] = isChecked
|
||||
}
|
||||
.setPositiveButton(context.getString(R.string.okay)) { _, _ ->
|
||||
val selected = mutableListOf<Int>()
|
||||
for (idx in checked.indices) {
|
||||
if (checked[idx]) selected.add(idx)
|
||||
}
|
||||
onConfirm(selected)
|
||||
}
|
||||
.setNegativeButton(context.getString(R.string.cancel), null)
|
||||
.create()
|
||||
dialog.show()
|
||||
multiChoiceDialog = dialog
|
||||
setDialogFontForAllButtonsAndText(multiChoiceDialog, context, "settings")
|
||||
}
|
||||
|
||||
var colorPickerDialog: AlertDialog? = null
|
||||
|
||||
fun showColorPickerDialog(
|
||||
context: Context,
|
||||
titleResId: Int,
|
||||
color: Int,
|
||||
onItemSelected: (Int) -> Unit // Callback to handle the selected color
|
||||
) {
|
||||
val red = Color.red(color)
|
||||
val green = Color.green(color)
|
||||
val blue = Color.blue(color)
|
||||
|
||||
var isUpdatingText = false
|
||||
|
||||
val dialogBuilder = MaterialAlertDialogBuilder(context)
|
||||
.setTitle(context.getString(titleResId))
|
||||
|
||||
// Create SeekBars for Red, Green, and Blue
|
||||
val redSeekBar = createColorSeekBar(context, red)
|
||||
val greenSeekBar = createColorSeekBar(context, green)
|
||||
val blueSeekBar = createColorSeekBar(context, blue)
|
||||
|
||||
// Create color preview box and RGB Hex input field
|
||||
val colorPreviewBox = createColorPreviewBox(context, color)
|
||||
val rgbText = createRgbTextField(context, red, green, blue)
|
||||
|
||||
// Layout with SeekBars, Color Preview, and RGB Hex Text Input
|
||||
val layout = LinearLayout(context).apply {
|
||||
orientation = LinearLayout.VERTICAL
|
||||
|
||||
// Create a horizontal layout for the text box and color preview
|
||||
val horizontalLayout = LinearLayout(context).apply {
|
||||
orientation = LinearLayout.HORIZONTAL
|
||||
gravity = Gravity.CENTER_VERTICAL // Vertically center the views
|
||||
|
||||
// RGB Text field
|
||||
val rgbParams =
|
||||
LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f).apply {
|
||||
marginStart = 32 // Optional: Add margin between the text and the color box
|
||||
}
|
||||
rgbText.layoutParams = rgbParams
|
||||
addView(rgbText)
|
||||
|
||||
// Color preview box
|
||||
val colorParams = LinearLayout.LayoutParams(150, 50).apply {
|
||||
marginEnd = 32 // Optional: Add margin between the text and the color box
|
||||
}
|
||||
colorPreviewBox.layoutParams = colorParams
|
||||
addView(colorPreviewBox)
|
||||
}
|
||||
|
||||
addView(redSeekBar)
|
||||
addView(greenSeekBar)
|
||||
addView(blueSeekBar)
|
||||
addView(horizontalLayout)
|
||||
}
|
||||
|
||||
// Update color preview and text input when SeekBars are adjusted
|
||||
val updateColorPreview = {
|
||||
val updatedColor = Color.rgb(
|
||||
redSeekBar.progress, greenSeekBar.progress, blueSeekBar.progress
|
||||
)
|
||||
colorPreviewBox.setBackgroundColor(updatedColor)
|
||||
|
||||
if (!isUpdatingText) {
|
||||
isUpdatingText = true
|
||||
rgbText.setText(
|
||||
String.format(
|
||||
"#%02X%02X%02X",
|
||||
redSeekBar.progress, greenSeekBar.progress, blueSeekBar.progress
|
||||
)
|
||||
)
|
||||
isUpdatingText = false
|
||||
}
|
||||
}
|
||||
|
||||
// Listeners to update color preview when sliders are adjusted
|
||||
redSeekBar.setOnSeekBarChangeListener(createSeekBarChangeListener(updateColorPreview))
|
||||
greenSeekBar.setOnSeekBarChangeListener(createSeekBarChangeListener(updateColorPreview))
|
||||
blueSeekBar.setOnSeekBarChangeListener(createSeekBarChangeListener(updateColorPreview))
|
||||
|
||||
// Listen for text input and update sliders and preview
|
||||
rgbText.addTextChangedListener(object : TextWatcher {
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
s?.toString()?.trim()?.let { colorString ->
|
||||
if (colorString.matches(Regex("^#[0-9A-Fa-f]{6}$"))) {
|
||||
val hexColor = colorString.toColorInt()
|
||||
redSeekBar.progress = Color.red(hexColor)
|
||||
greenSeekBar.progress = Color.green(hexColor)
|
||||
blueSeekBar.progress = Color.blue(hexColor)
|
||||
updateColorPreview()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
|
||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
|
||||
})
|
||||
|
||||
// Set up the dialog view and buttons
|
||||
dialogBuilder.setView(layout)
|
||||
dialogBuilder.setPositiveButton("OK") { _, _ ->
|
||||
val pickedColor = Color.rgb(
|
||||
redSeekBar.progress, greenSeekBar.progress, blueSeekBar.progress
|
||||
)
|
||||
onItemSelected(pickedColor)
|
||||
}
|
||||
dialogBuilder.setNegativeButton("Cancel", null)
|
||||
|
||||
// Show the dialog
|
||||
dialogBuilder.create().show()
|
||||
}
|
||||
|
||||
fun showInputDialog(
|
||||
context: Context,
|
||||
title: String,
|
||||
initialValue: String,
|
||||
onValueEntered: (String) -> Unit
|
||||
) {
|
||||
val builder = MaterialAlertDialogBuilder(context)
|
||||
val input = EditText(context)
|
||||
input.setText(initialValue)
|
||||
// Make input single line and set IME action to DONE
|
||||
input.maxLines = 1
|
||||
input.isSingleLine = true
|
||||
input.imeOptions = android.view.inputmethod.EditorInfo.IME_ACTION_DONE
|
||||
input.setOnEditorActionListener { v, actionId, event ->
|
||||
if (actionId == android.view.inputmethod.EditorInfo.IME_ACTION_DONE || (event != null && event.keyCode == android.view.KeyEvent.KEYCODE_ENTER && event.action == android.view.KeyEvent.ACTION_DOWN)) {
|
||||
onValueEntered(input.text.toString())
|
||||
// Dismiss the dialog
|
||||
(v.parent as? View)?.let { parentView ->
|
||||
var parent = parentView.parent
|
||||
while (parent != null && parent !is AlertDialog) {
|
||||
parent = (parent as? View)?.parent
|
||||
}
|
||||
(parent as? AlertDialog)?.dismiss()
|
||||
}
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
// Wrap the EditText in a FrameLayout with standard Material dialog padding
|
||||
val container = android.widget.FrameLayout(context).apply {
|
||||
val padding = (24 * context.resources.displayMetrics.density).toInt() // 24dp
|
||||
setPadding(padding, padding, padding, 0)
|
||||
// Fix: Remove input from previous parent if needed
|
||||
(input.parent as? ViewGroup)?.removeView(input)
|
||||
addView(input)
|
||||
}
|
||||
|
||||
builder.setTitle(title)
|
||||
.setView(container)
|
||||
.setPositiveButton("OK") { _, _ ->
|
||||
onValueEntered(input.text.toString())
|
||||
}
|
||||
.setNegativeButton("Cancel") { dialog, _ ->
|
||||
dialog.cancel()
|
||||
}
|
||||
// Only call show() once and use the returned dialog
|
||||
val dialog = builder.show()
|
||||
setDialogFontForAllButtonsAndText(dialog, context, "settings")
|
||||
}
|
||||
|
||||
fun showErrorDialog(context: Context, title: String, message: String) {
|
||||
val dialog = MaterialAlertDialogBuilder(context)
|
||||
.setTitle(title)
|
||||
.setMessage(message)
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.create()
|
||||
dialog.show()
|
||||
setDialogFontForAllButtonsAndText(dialog, context, "settings")
|
||||
}
|
||||
|
||||
private fun createColorSeekBar(context: Context, initialValue: Int): SeekBar {
|
||||
return SeekBar(context).apply {
|
||||
max = 255
|
||||
progress = initialValue
|
||||
}
|
||||
}
|
||||
|
||||
private fun createColorPreviewBox(context: Context, color: Int): View {
|
||||
return View(context).apply {
|
||||
setBackgroundColor(color)
|
||||
}
|
||||
}
|
||||
|
||||
private fun createRgbTextField(context: Context, red: Int, green: Int, blue: Int): EditText {
|
||||
return EditText(context).apply {
|
||||
setText(String.format("#%02X%02X%02X", red, green, blue))
|
||||
inputType = InputType.TYPE_CLASS_TEXT
|
||||
|
||||
// Remove the bottom line (underline) from the EditText
|
||||
background = null
|
||||
}
|
||||
}
|
||||
|
||||
private fun createSeekBarChangeListener(updateColorPreview: () -> Unit): SeekBar.OnSeekBarChangeListener {
|
||||
return object : SeekBar.OnSeekBarChangeListener {
|
||||
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
||||
updateColorPreview()
|
||||
}
|
||||
|
||||
override fun onStartTrackingTouch(seekBar: SeekBar?) {}
|
||||
override fun onStopTrackingTouch(seekBar: SeekBar?) {}
|
||||
}
|
||||
}
|
||||
|
||||
fun setDialogFontForAllButtonsAndText(
|
||||
dialog: AlertDialog?,
|
||||
context: Context,
|
||||
contextKey: String = "settings"
|
||||
) {
|
||||
val prefs = Prefs(context)
|
||||
val fontFamily = prefs.getFontForContext(contextKey)
|
||||
val customFontPath = prefs.getCustomFontPathForContext(contextKey)
|
||||
val typeface = fontFamily.getFont(context, customFontPath) ?: getTrueSystemFont()
|
||||
val textSize = prefs.settingsSize.toFloat()
|
||||
// Set for all buttons
|
||||
dialog?.getButton(AlertDialog.BUTTON_POSITIVE)?.let {
|
||||
it.typeface = typeface
|
||||
it.textSize = textSize
|
||||
}
|
||||
dialog?.getButton(AlertDialog.BUTTON_NEGATIVE)?.let {
|
||||
it.typeface = typeface
|
||||
it.textSize = textSize
|
||||
}
|
||||
dialog?.getButton(AlertDialog.BUTTON_NEUTRAL)?.let {
|
||||
it.typeface = typeface
|
||||
it.textSize = textSize
|
||||
}
|
||||
// Set for all TextViews in the dialog view
|
||||
(dialog?.window?.decorView as? ViewGroup)?.let { root ->
|
||||
fun applyToAllTextViews(view: View) {
|
||||
if (view is TextView) {
|
||||
view.typeface = typeface
|
||||
view.textSize = textSize
|
||||
} else if (view is ViewGroup) {
|
||||
for (i in 0 until view.childCount) {
|
||||
applyToAllTextViews(view.getChildAt(i))
|
||||
}
|
||||
}
|
||||
}
|
||||
applyToAllTextViews(root)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,633 @@
|
||||
package com.github.gezimos.inkos.ui.notifications
|
||||
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Vibrator
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.gestures.detectVerticalDragGestures
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.pager.VerticalPager
|
||||
import androidx.compose.foundation.pager.rememberPagerState
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.TextUnit
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.github.gezimos.inkos.data.Prefs
|
||||
import com.github.gezimos.inkos.services.NotificationManager
|
||||
import com.github.gezimos.inkos.style.SettingsTheme
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.FullLineSeparator
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class NotificationsFragment : Fragment() {
|
||||
private lateinit var prefs: Prefs
|
||||
private lateinit var vibrator: Vibrator
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
prefs = Prefs(requireContext())
|
||||
vibrator = requireContext().getSystemService(Vibrator::class.java)
|
||||
val composeView = ComposeView(requireContext())
|
||||
composeView.setContent {
|
||||
val isDark = when (prefs.appTheme) {
|
||||
com.github.gezimos.inkos.data.Constants.Theme.Dark -> true
|
||||
com.github.gezimos.inkos.data.Constants.Theme.Light -> false
|
||||
com.github.gezimos.inkos.data.Constants.Theme.System -> com.github.gezimos.inkos.helper.isSystemInDarkMode(requireContext())
|
||||
}
|
||||
val backgroundColor = Color(prefs.backgroundColor)
|
||||
SettingsTheme(isDark = isDark) {
|
||||
NotificationsScreen(backgroundColor, composeView)
|
||||
}
|
||||
}
|
||||
return composeView
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
// Eink refresh: flash overlay if enabled
|
||||
com.github.gezimos.inkos.helper.utils.EinkRefreshHelper.refreshEink(
|
||||
requireContext(), prefs, null, useActivityRoot = true
|
||||
)
|
||||
// Add DPAD up/down navigation for notifications
|
||||
view.isFocusable = true
|
||||
view.isFocusableInTouchMode = true
|
||||
view.requestFocus()
|
||||
view.setOnKeyListener { v, keyCode, event ->
|
||||
if (event.action == android.view.KeyEvent.ACTION_DOWN) {
|
||||
android.util.Log.d("NotificationsFragment", "Key event: $keyCode")
|
||||
val composeView = v as? ComposeView
|
||||
val pagerState = composeView?.getTag(0xdeadbeef.toInt()) as? androidx.compose.foundation.pager.PagerState
|
||||
val coroutineScope = composeView?.getTag(0xcafebabe.toInt()) as? kotlinx.coroutines.CoroutineScope
|
||||
// Store the last validNotifications in a tag for key actions
|
||||
val validNotifications = (composeView?.getTag(0xabcdef01.toInt()) as? List<*>)
|
||||
?.filterIsInstance<Pair<String, NotificationManager.ConversationNotification>>()
|
||||
if (pagerState != null && coroutineScope != null && validNotifications != null) {
|
||||
when (keyCode) {
|
||||
android.view.KeyEvent.KEYCODE_DPAD_DOWN -> {
|
||||
coroutineScope.launch {
|
||||
if (pagerState.currentPage < pagerState.pageCount - 1) {
|
||||
pagerState.scrollToPage(pagerState.currentPage + 1)
|
||||
vibratePaging()
|
||||
} else if (pagerState.pageCount > 0) {
|
||||
pagerState.scrollToPage(0)
|
||||
vibratePaging()
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
android.view.KeyEvent.KEYCODE_DPAD_UP -> {
|
||||
coroutineScope.launch {
|
||||
if (pagerState.currentPage > 0) {
|
||||
pagerState.scrollToPage(pagerState.currentPage - 1)
|
||||
vibratePaging()
|
||||
} else if (pagerState.pageCount > 0) {
|
||||
pagerState.scrollToPage(pagerState.pageCount - 1)
|
||||
vibratePaging()
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
android.view.KeyEvent.KEYCODE_VOLUME_UP -> {
|
||||
if (prefs.useVolumeKeysForPages) {
|
||||
coroutineScope.launch {
|
||||
if (pagerState.currentPage > 0) {
|
||||
pagerState.scrollToPage(pagerState.currentPage - 1)
|
||||
vibratePaging()
|
||||
} else if (pagerState.pageCount > 0) {
|
||||
pagerState.scrollToPage(pagerState.pageCount - 1)
|
||||
vibratePaging()
|
||||
}
|
||||
}
|
||||
true
|
||||
} else false
|
||||
}
|
||||
android.view.KeyEvent.KEYCODE_VOLUME_DOWN -> {
|
||||
if (prefs.useVolumeKeysForPages) {
|
||||
coroutineScope.launch {
|
||||
if (pagerState.currentPage < pagerState.pageCount - 1) {
|
||||
pagerState.scrollToPage(pagerState.currentPage + 1)
|
||||
vibratePaging()
|
||||
} else if (pagerState.pageCount > 0) {
|
||||
pagerState.scrollToPage(0)
|
||||
vibratePaging()
|
||||
}
|
||||
}
|
||||
true
|
||||
} else false
|
||||
}
|
||||
android.view.KeyEvent.KEYCODE_DEL, 82 /* KEYCODE_MENU for QIN phones */ -> {
|
||||
// Dismiss notification
|
||||
val (pkg, notif) = validNotifications.getOrNull(pagerState.currentPage) ?: return@setOnKeyListener true
|
||||
NotificationManager.getInstance(requireContext())
|
||||
.removeConversationNotification(pkg, notif.conversationId)
|
||||
coroutineScope.launch {
|
||||
val nextPage = when {
|
||||
pagerState.currentPage == validNotifications.lastIndex && pagerState.currentPage > 0 -> pagerState.currentPage - 1
|
||||
pagerState.currentPage < validNotifications.lastIndex -> pagerState.currentPage
|
||||
else -> 0
|
||||
}
|
||||
kotlinx.coroutines.delay(150)
|
||||
if (validNotifications.size > 1) {
|
||||
pagerState.scrollToPage(nextPage)
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
android.view.KeyEvent.KEYCODE_DPAD_CENTER, android.view.KeyEvent.KEYCODE_ENTER -> {
|
||||
// Open notification
|
||||
val (pkg, notif) = validNotifications.getOrNull(pagerState.currentPage) ?: return@setOnKeyListener true
|
||||
try {
|
||||
val context = requireContext()
|
||||
val launchIntent = context.packageManager.getLaunchIntentForPackage(pkg)
|
||||
if (launchIntent != null) {
|
||||
context.startActivity(launchIntent)
|
||||
}
|
||||
} catch (_: Exception) {}
|
||||
NotificationManager.getInstance(requireContext())
|
||||
.removeConversationNotification(pkg, notif.conversationId)
|
||||
coroutineScope.launch {
|
||||
if (pagerState.currentPage == validNotifications.lastIndex && pagerState.currentPage > 0) {
|
||||
pagerState.scrollToPage(pagerState.currentPage - 1)
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
} else {
|
||||
android.util.Log.d("NotificationsFragment", "pagerState, coroutineScope, or validNotifications is null")
|
||||
false
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun NotificationsScreen(backgroundColor: Color, composeView: ComposeView) {
|
||||
val notificationsMap by rememberNotifications()
|
||||
// Use notification-specific font and size settings
|
||||
val notifFont = prefs.getFontForContext("notifications")
|
||||
.getFont(requireContext(), prefs.getCustomFontPathForContext("notifications"))
|
||||
val notifFontFamily = notifFont?.let { FontFamily(it) } ?: FontFamily.Default
|
||||
val notifTextSize = prefs.notificationsTextSize.sp
|
||||
val notifTitle = prefs.lettersTitle
|
||||
val notifTitleFont = prefs.lettersTitleFont.getFont(
|
||||
requireContext(),
|
||||
prefs.getCustomFontPath("lettersTitle")
|
||||
)
|
||||
val notifTitleFontFamily = notifTitleFont?.let { FontFamily(it) } ?: FontFamily.Default
|
||||
val notifTitleSize = prefs.lettersTitleSize.sp
|
||||
val isDark = when (prefs.appTheme) {
|
||||
com.github.gezimos.inkos.data.Constants.Theme.Dark -> true
|
||||
com.github.gezimos.inkos.data.Constants.Theme.Light -> false
|
||||
com.github.gezimos.inkos.data.Constants.Theme.System -> com.github.gezimos.inkos.helper.isSystemInDarkMode(requireContext())
|
||||
}
|
||||
|
||||
// Check if notifications are enabled
|
||||
if (!prefs.notificationsEnabled) {
|
||||
findNavController().popBackStack()
|
||||
return
|
||||
}
|
||||
|
||||
// Flatten all notifications into a single list (one per notification)
|
||||
val validNotifications = remember(notificationsMap) {
|
||||
notificationsMap.flatMap { (packageName, conversations) ->
|
||||
conversations.map { notif -> packageName to notif }
|
||||
}
|
||||
}
|
||||
val pagerState = rememberPagerState(
|
||||
initialPage = 0,
|
||||
pageCount = { validNotifications.size }
|
||||
)
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
// Attach pagerState and coroutineScope to the correct ComposeView instance
|
||||
DisposableEffect(pagerState, coroutineScope, composeView) {
|
||||
composeView.setTag(0xdeadbeef.toInt(), pagerState)
|
||||
composeView.setTag(0xcafebabe.toInt(), coroutineScope)
|
||||
onDispose {
|
||||
composeView.setTag(0xdeadbeef.toInt(), null)
|
||||
composeView.setTag(0xcafebabe.toInt(), null)
|
||||
}
|
||||
}
|
||||
|
||||
// Store validNotifications in ComposeView tag for key actions
|
||||
DisposableEffect(validNotifications, composeView) {
|
||||
composeView.setTag(0xabcdef01.toInt(), validNotifications)
|
||||
onDispose { composeView.setTag(0xabcdef01.toInt(), null) }
|
||||
}
|
||||
|
||||
// Custom swipe handling for instant page change
|
||||
val pagerModifier = Modifier
|
||||
.fillMaxSize()
|
||||
.pointerInput(validNotifications.size) {
|
||||
var totalDrag = 0f
|
||||
detectVerticalDragGestures(
|
||||
onDragEnd = {
|
||||
if (totalDrag < -30) { // Swipe up
|
||||
coroutineScope.launch {
|
||||
if (pagerState.currentPage < validNotifications.lastIndex) {
|
||||
pagerState.scrollToPage(pagerState.currentPage + 1)
|
||||
vibratePaging()
|
||||
} else if (validNotifications.isNotEmpty()) {
|
||||
pagerState.scrollToPage(0) // Loop to first notification
|
||||
vibratePaging()
|
||||
}
|
||||
}
|
||||
} else if (totalDrag > 30) { // Swipe down
|
||||
coroutineScope.launch {
|
||||
if (pagerState.currentPage > 0) {
|
||||
pagerState.scrollToPage(pagerState.currentPage - 1)
|
||||
vibratePaging()
|
||||
} else if (validNotifications.isNotEmpty()) {
|
||||
pagerState.scrollToPage(validNotifications.lastIndex) // Loop to last notification
|
||||
vibratePaging()
|
||||
}
|
||||
}
|
||||
}
|
||||
totalDrag = 0f
|
||||
},
|
||||
onVerticalDrag = { change, dragAmount ->
|
||||
change.consume() // Use consume() as recommended by Compose deprecation warning
|
||||
totalDrag += dragAmount
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// Detect navigation bar height for padding
|
||||
val view = LocalView.current
|
||||
val density = LocalDensity.current
|
||||
var navBarPadding by remember { mutableStateOf(0.dp) }
|
||||
var statusBarPadding by remember { mutableStateOf(0.dp) }
|
||||
LaunchedEffect(view) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
view.rootWindowInsets?.let { insets ->
|
||||
val navBar = insets.getInsets(android.view.WindowInsets.Type.navigationBars())
|
||||
navBarPadding = with(density) { navBar.bottom.toDp() }
|
||||
val statusBar = insets.getInsets(android.view.WindowInsets.Type.statusBars())
|
||||
statusBarPadding = with(density) { statusBar.top.toDp() }
|
||||
}
|
||||
} else {
|
||||
ViewCompat.setOnApplyWindowInsetsListener(view) { v: View, insets: WindowInsetsCompat ->
|
||||
val navBar = insets.getInsets(WindowInsetsCompat.Type.navigationBars())
|
||||
navBarPadding = with(density) { navBar.bottom.toDp() }
|
||||
val statusBar = insets.getInsets(WindowInsetsCompat.Type.statusBars())
|
||||
statusBarPadding = with(density) { statusBar.top.toDp() }
|
||||
insets
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove all bottom padding
|
||||
val contentBottomPadding = 0.dp
|
||||
val actionBarBottomPadding = 0.dp
|
||||
val contentTopPadding = statusBarPadding
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(backgroundColor)
|
||||
) {
|
||||
if (validNotifications.isEmpty()) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(top = contentTopPadding, bottom = contentBottomPadding),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(
|
||||
text = "No notifications",
|
||||
fontSize = notifTextSize,
|
||||
fontFamily = notifFontFamily,
|
||||
color = SettingsTheme.typography.title.color
|
||||
)
|
||||
}
|
||||
} else {
|
||||
VerticalPager(
|
||||
state = pagerState,
|
||||
modifier = pagerModifier,
|
||||
userScrollEnabled = false,
|
||||
pageSpacing = 0.dp
|
||||
) { page ->
|
||||
val (packageName, notif) = validNotifications[page]
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(top = contentTopPadding, bottom = contentBottomPadding),
|
||||
verticalArrangement = Arrangement.Top
|
||||
) {
|
||||
// Title row at the top of the content
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 24.dp, vertical = 24.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = notifTitle,
|
||||
style = SettingsTheme.typography.title,
|
||||
fontSize = notifTitleSize,
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontFamily = notifTitleFontFamily,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth(),
|
||||
textAlign = androidx.compose.ui.text.style.TextAlign.Start
|
||||
)
|
||||
}
|
||||
ConversationNotificationItem(
|
||||
packageName = packageName,
|
||||
notif = notif,
|
||||
notifFontFamily = notifFontFamily,
|
||||
titleFontSize = notifTextSize, // Use body font size for sender/group name
|
||||
descriptionFontSize = notifTextSize,
|
||||
isDark = isDark
|
||||
)
|
||||
}
|
||||
}
|
||||
// Sticky bottom action bar
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomCenter)
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = actionBarBottomPadding),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
val canDismiss = validNotifications.isNotEmpty()
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
// Dismiss button with matching hitbox
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.heightIn(min = 56.dp)
|
||||
.clickable(enabled = canDismiss) {
|
||||
val (pkg, notif) = validNotifications.getOrNull(pagerState.currentPage)
|
||||
?: return@clickable
|
||||
NotificationManager.getInstance(requireContext())
|
||||
.removeConversationNotification(pkg, notif.conversationId)
|
||||
coroutineScope.launch {
|
||||
val nextPage = when {
|
||||
pagerState.currentPage == validNotifications.lastIndex && pagerState.currentPage > 0 -> pagerState.currentPage - 1
|
||||
pagerState.currentPage < validNotifications.lastIndex -> pagerState.currentPage
|
||||
else -> 0
|
||||
}
|
||||
kotlinx.coroutines.delay(150)
|
||||
if (validNotifications.size > 1) {
|
||||
pagerState.scrollToPage(nextPage)
|
||||
}
|
||||
}
|
||||
vibratePaging() // vibrate on dismiss tap if enabled
|
||||
},
|
||||
contentAlignment = Alignment.CenterStart
|
||||
) {
|
||||
Text(
|
||||
text = "DISMISS",
|
||||
style = SettingsTheme.typography.title,
|
||||
fontSize = notifTextSize,
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontFamily = notifFontFamily,
|
||||
color = if (canDismiss) SettingsTheme.typography.title.color else Color.Gray,
|
||||
modifier = Modifier.padding(start = 24.dp, end = 24.dp)
|
||||
)
|
||||
}
|
||||
// Open button with matching hitbox
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.heightIn(min = 56.dp)
|
||||
.clickable {
|
||||
val (pkg, notif) = validNotifications.getOrNull(pagerState.currentPage)
|
||||
?: return@clickable
|
||||
try {
|
||||
val context = requireContext()
|
||||
val launchIntent =
|
||||
context.packageManager.getLaunchIntentForPackage(pkg)
|
||||
if (launchIntent != null) {
|
||||
context.startActivity(launchIntent)
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
NotificationManager.getInstance(requireContext())
|
||||
.removeConversationNotification(pkg, notif.conversationId)
|
||||
coroutineScope.launch {
|
||||
if (pagerState.currentPage == validNotifications.lastIndex && pagerState.currentPage > 0) {
|
||||
pagerState.scrollToPage(pagerState.currentPage - 1)
|
||||
}
|
||||
}
|
||||
vibratePaging() // vibrate on open tap if enabled
|
||||
},
|
||||
contentAlignment = Alignment.CenterEnd
|
||||
) {
|
||||
Text(
|
||||
text = "OPEN",
|
||||
style = SettingsTheme.typography.title,
|
||||
fontSize = notifTextSize,
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontFamily = notifFontFamily,
|
||||
color = SettingsTheme.typography.title.color,
|
||||
modifier = Modifier.padding(start = 24.dp, end = 24.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun vibratePaging() {
|
||||
if (prefs.useVibrationForPaging) {
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
vibrator.vibrate(android.os.VibrationEffect.createOneShot(30, android.os.VibrationEffect.DEFAULT_AMPLITUDE))
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
vibrator.vibrate(30)
|
||||
}
|
||||
} catch (_: Exception) {}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun rememberNotifications(): State<Map<String, List<NotificationManager.ConversationNotification>>> {
|
||||
val state =
|
||||
remember { mutableStateOf(emptyMap<String, List<NotificationManager.ConversationNotification>>()) }
|
||||
DisposableEffect(Unit) {
|
||||
val observer =
|
||||
Observer<Map<String, List<NotificationManager.ConversationNotification>>> {
|
||||
state.value = it
|
||||
}
|
||||
NotificationManager.getInstance(requireContext()).conversationNotificationsLiveData.observe(
|
||||
viewLifecycleOwner,
|
||||
observer
|
||||
)
|
||||
onDispose {
|
||||
NotificationManager.getInstance(requireContext()).conversationNotificationsLiveData.removeObserver(
|
||||
observer
|
||||
)
|
||||
}
|
||||
}
|
||||
return state
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ConversationNotificationItem(
|
||||
packageName: String,
|
||||
notif: NotificationManager.ConversationNotification,
|
||||
notifFontFamily: FontFamily,
|
||||
titleFontSize: TextUnit,
|
||||
descriptionFontSize: TextUnit,
|
||||
isDark: Boolean
|
||||
) {
|
||||
val context = requireContext()
|
||||
// Improved title logic for group conversations:
|
||||
val title = when {
|
||||
!notif.conversationTitle.isNullOrBlank() && !notif.sender.isNullOrBlank() && notif.conversationTitle != notif.sender ->
|
||||
notif.sender
|
||||
!notif.conversationTitle.isNullOrBlank() -> notif.conversationTitle
|
||||
!notif.sender.isNullOrBlank() -> notif.sender
|
||||
else -> {
|
||||
// Fallback to app label if no title or sender
|
||||
val alias = Prefs(context).getAppAlias("app_alias_${packageName}")
|
||||
if (alias.isNotEmpty()) {
|
||||
alias
|
||||
} else {
|
||||
try {
|
||||
context.packageManager.getApplicationLabel(
|
||||
context.packageManager.getApplicationInfo(packageName, 0)
|
||||
).toString()
|
||||
} catch (_: Exception) {
|
||||
packageName
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
val timeFormat = java.text.SimpleDateFormat("h:mm a", java.util.Locale.getDefault())
|
||||
val timeString = timeFormat.format(notif.timestamp)
|
||||
|
||||
// Only use the single message field, since ConversationNotification does not have a messages list
|
||||
val message = notif.message ?: ""
|
||||
if (message.isBlank()) return
|
||||
|
||||
// Get app label, using renamed alias if available (like AppDrawer)
|
||||
val alias = Prefs(context).getAppAlias("app_alias_${packageName}")
|
||||
val appLabel = if (alias.isNotEmpty()) {
|
||||
alias
|
||||
} else {
|
||||
try {
|
||||
context.packageManager.getApplicationLabel(
|
||||
context.packageManager.getApplicationInfo(packageName, 0)
|
||||
).toString()
|
||||
} catch (_: Exception) {
|
||||
packageName
|
||||
}
|
||||
}
|
||||
FullLineSeparator(isDark = isDark)
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 24.dp, vertical = 16.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = title,
|
||||
style = SettingsTheme.typography.title,
|
||||
fontSize = titleFontSize * 1.2f, // Increased name size to 1.2x
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontFamily = notifFontFamily,
|
||||
)
|
||||
}
|
||||
|
||||
FullLineSeparator(isDark = isDark)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 24.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = appLabel,
|
||||
style = SettingsTheme.typography.title,
|
||||
fontSize = descriptionFontSize * 0.8f, // Reduced app alias size
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontFamily = notifFontFamily,
|
||||
color = SettingsTheme.typography.title.color
|
||||
)
|
||||
Text(
|
||||
text = timeString,
|
||||
style = SettingsTheme.typography.title,
|
||||
fontSize = descriptionFontSize * 0.8f, // Reduced time size
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontFamily = notifFontFamily,
|
||||
color = SettingsTheme.typography.title.color
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
// Separator: no extra padding, already handled in FullLineSeparator
|
||||
FullLineSeparator(isDark = isDark)
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
|
||||
Text(
|
||||
text = message,
|
||||
style = SettingsTheme.typography.title,
|
||||
fontSize = descriptionFontSize,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontFamily = notifFontFamily,
|
||||
lineHeight = descriptionFontSize * 1.3, // Increased line height
|
||||
modifier = Modifier
|
||||
.padding(start = 24.dp, end = 24.dp, bottom = 8.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,419 @@
|
||||
package com.github.gezimos.inkos.ui.settings
|
||||
|
||||
import android.app.admin.DevicePolicyManager
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.TextUnit
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.isSpecified
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.github.gezimos.common.isBiometricEnabled
|
||||
import com.github.gezimos.common.isGestureNavigationEnabled
|
||||
import com.github.gezimos.inkos.BuildConfig
|
||||
import com.github.gezimos.inkos.MainViewModel
|
||||
import com.github.gezimos.inkos.R
|
||||
import com.github.gezimos.inkos.data.Constants.Theme.Dark
|
||||
import com.github.gezimos.inkos.data.Constants.Theme.Light
|
||||
import com.github.gezimos.inkos.data.Constants.Theme.System
|
||||
import com.github.gezimos.inkos.data.Prefs
|
||||
import com.github.gezimos.inkos.helper.getHexForOpacity
|
||||
import com.github.gezimos.inkos.helper.isSystemInDarkMode
|
||||
import com.github.gezimos.inkos.helper.isinkosDefault
|
||||
import com.github.gezimos.inkos.helper.openAppInfo
|
||||
import com.github.gezimos.inkos.helper.utils.AppReloader
|
||||
import com.github.gezimos.inkos.listener.DeviceAdmin
|
||||
import com.github.gezimos.inkos.style.SettingsTheme
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.DashedSeparator
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.FullLineSeparator
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.PageHeader
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.SettingsHomeItem
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.SettingsSelect
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.SettingsSwitch
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.SolidSeparator
|
||||
import com.github.gezimos.inkos.ui.dialogs.DialogManager
|
||||
|
||||
class AdvancedFragment : Fragment() {
|
||||
|
||||
private lateinit var prefs: Prefs
|
||||
private lateinit var viewModel: MainViewModel
|
||||
private lateinit var deviceManager: DevicePolicyManager
|
||||
private lateinit var componentName: ComponentName
|
||||
private lateinit var dialogBuilder: DialogManager
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
prefs = Prefs(requireContext())
|
||||
dialogBuilder = DialogManager(requireContext(), requireActivity())
|
||||
val backgroundColor = getHexForOpacity(prefs)
|
||||
val isDark = when (prefs.appTheme) {
|
||||
Light -> false
|
||||
Dark -> true
|
||||
System -> isSystemInDarkMode(requireContext())
|
||||
}
|
||||
val settingsSize = (prefs.settingsSize - 3)
|
||||
val context = requireContext()
|
||||
// --- Dot indicator state ---
|
||||
val currentPage = intArrayOf(0)
|
||||
val pageCount = intArrayOf(1)
|
||||
|
||||
// Create a vertical LinearLayout to hold sticky header and scrollable content
|
||||
val rootLayout = android.widget.LinearLayout(context).apply {
|
||||
orientation = android.widget.LinearLayout.VERTICAL
|
||||
setBackgroundColor(backgroundColor)
|
||||
layoutParams = ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
}
|
||||
|
||||
var bottomInsetPx = 0
|
||||
androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener(rootLayout) { v, insets ->
|
||||
val navBarInset =
|
||||
insets.getInsets(androidx.core.view.WindowInsetsCompat.Type.navigationBars()).bottom
|
||||
bottomInsetPx = navBarInset
|
||||
insets
|
||||
}
|
||||
|
||||
// Add sticky header ComposeView
|
||||
val headerView = androidx.compose.ui.platform.ComposeView(context).apply {
|
||||
setContent {
|
||||
val density = LocalDensity.current
|
||||
val bottomInsetDp = with(density) { bottomInsetPx.toDp() }
|
||||
SettingsTheme(isDark) {
|
||||
Column(Modifier.fillMaxWidth()) {
|
||||
PageHeader(
|
||||
iconRes = R.drawable.ic_back,
|
||||
title = stringResource(R.string.advanced_settings_title),
|
||||
onClick = { findNavController().popBackStack() },
|
||||
showStatusBar = prefs.showStatusBar,
|
||||
pageIndicator = {
|
||||
com.github.gezimos.inkos.ui.compose.SettingsComposable.PageIndicator(
|
||||
currentPage = currentPage[0],
|
||||
pageCount = pageCount[0],
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else TextUnit.Unspecified
|
||||
)
|
||||
},
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else TextUnit.Unspecified
|
||||
)
|
||||
SolidSeparator(isDark = isDark)
|
||||
Spacer(modifier = Modifier.height(SettingsTheme.color.horizontalPadding))
|
||||
if (bottomInsetDp > 0.dp) {
|
||||
Spacer(modifier = Modifier.height(bottomInsetDp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
rootLayout.addView(headerView)
|
||||
|
||||
// Add scrollable settings content
|
||||
val nestedScrollView = androidx.core.widget.NestedScrollView(context).apply {
|
||||
isFillViewport = true
|
||||
setBackgroundColor(backgroundColor)
|
||||
addView(
|
||||
androidx.compose.ui.platform.ComposeView(context).apply {
|
||||
setContent {
|
||||
val density = LocalDensity.current
|
||||
val bottomInsetDp = with(density) { bottomInsetPx.toDp() }
|
||||
SettingsTheme(isDark) {
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
Column {
|
||||
AdvancedSettingsAllInOne(settingsSize.sp)
|
||||
if (bottomInsetDp > 0.dp) {
|
||||
Spacer(modifier = Modifier.height(bottomInsetDp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
)
|
||||
}
|
||||
com.github.gezimos.inkos.helper.utils.EinkScrollBehavior(context)
|
||||
.attachToScrollView(nestedScrollView)
|
||||
rootLayout.addView(
|
||||
nestedScrollView,
|
||||
ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
)
|
||||
|
||||
// --- Calculate pages and listen for scroll changes ---
|
||||
fun getCurrentPageIndex(
|
||||
scrollY: Int,
|
||||
viewportHeight: Int,
|
||||
contentHeight: Int,
|
||||
pageCount: Int
|
||||
): Int {
|
||||
if (contentHeight <= viewportHeight) return 0
|
||||
val overlap = (viewportHeight * 0.2).toInt()
|
||||
val scrollStep = viewportHeight - overlap
|
||||
val maxScroll = (contentHeight - viewportHeight).coerceAtLeast(1)
|
||||
val clampedScrollY = scrollY.coerceIn(0, maxScroll)
|
||||
val page = Math.round(clampedScrollY.toFloat() / scrollStep)
|
||||
return page.coerceIn(0, pageCount - 1)
|
||||
}
|
||||
nestedScrollView.viewTreeObserver.addOnGlobalLayoutListener {
|
||||
val contentHeight = nestedScrollView.getChildAt(0)?.height ?: 1
|
||||
val viewportHeight = nestedScrollView.height.takeIf { it > 0 } ?: 1
|
||||
val overlap = (viewportHeight * 0.2).toInt()
|
||||
val scrollStep = viewportHeight - overlap
|
||||
val pages =
|
||||
Math.ceil(((contentHeight - viewportHeight).toDouble() / scrollStep.toDouble()))
|
||||
.toInt() + 1
|
||||
pageCount[0] = pages
|
||||
val scrollY = nestedScrollView.scrollY
|
||||
currentPage[0] = getCurrentPageIndex(scrollY, viewportHeight, contentHeight, pages)
|
||||
headerView.setContent {
|
||||
SettingsTheme(isDark) {
|
||||
Column(Modifier.fillMaxWidth()) {
|
||||
PageHeader(
|
||||
iconRes = R.drawable.ic_back,
|
||||
title = stringResource(R.string.advanced_settings_title),
|
||||
onClick = { findNavController().popBackStack() },
|
||||
showStatusBar = prefs.showStatusBar,
|
||||
pageIndicator = {
|
||||
com.github.gezimos.inkos.ui.compose.SettingsComposable.PageIndicator(
|
||||
currentPage = currentPage[0],
|
||||
pageCount = pageCount[0],
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else TextUnit.Unspecified
|
||||
)
|
||||
},
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else TextUnit.Unspecified
|
||||
)
|
||||
SolidSeparator(isDark = isDark)
|
||||
Spacer(modifier = Modifier.height(SettingsTheme.color.horizontalPadding))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
nestedScrollView.setOnScrollChangeListener { _, _, scrollY, _, _ ->
|
||||
val contentHeight = nestedScrollView.getChildAt(0)?.height ?: 1
|
||||
val viewportHeight = nestedScrollView.height.takeIf { it > 0 } ?: 1
|
||||
val overlap = (viewportHeight * 0.2).toInt()
|
||||
val scrollStep = viewportHeight - overlap
|
||||
val pages =
|
||||
Math.ceil(((contentHeight - viewportHeight).toDouble() / scrollStep.toDouble()))
|
||||
.toInt() + 1
|
||||
pageCount[0] = pages
|
||||
currentPage[0] = getCurrentPageIndex(scrollY, viewportHeight, contentHeight, pages)
|
||||
headerView.setContent {
|
||||
SettingsTheme(isDark) {
|
||||
Column(Modifier.fillMaxWidth()) {
|
||||
PageHeader(
|
||||
iconRes = R.drawable.ic_back,
|
||||
title = stringResource(R.string.advanced_settings_title),
|
||||
onClick = { findNavController().popBackStack() },
|
||||
showStatusBar = prefs.showStatusBar,
|
||||
pageIndicator = {
|
||||
com.github.gezimos.inkos.ui.compose.SettingsComposable.PageIndicator(
|
||||
currentPage = currentPage[0],
|
||||
pageCount = pageCount[0],
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else TextUnit.Unspecified
|
||||
)
|
||||
},
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else TextUnit.Unspecified
|
||||
)
|
||||
SolidSeparator(isDark = isDark)
|
||||
Spacer(modifier = Modifier.height(SettingsTheme.color.horizontalPadding))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rootLayout
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun AdvancedSettingsAllInOne(fontSize: TextUnit = TextUnit.Unspecified) {
|
||||
findNavController()
|
||||
val isDark = isSystemInDarkMode(requireContext())
|
||||
val titleFontSize = if (fontSize.isSpecified) (fontSize.value * 1.5).sp else fontSize
|
||||
val iconSize = if (fontSize.isSpecified) tuToDp((fontSize * 0.8)) else tuToDp(fontSize)
|
||||
val changeLauncherText = if (isinkosDefault(requireContext())) {
|
||||
R.string.advanced_settings_set_as_default_launcher
|
||||
} else {
|
||||
R.string.advanced_settings_change_default_launcher
|
||||
}
|
||||
val navController = findNavController()
|
||||
// Remove verticalScroll and header, handled by parent ComposeView
|
||||
Column(modifier = Modifier.fillMaxWidth()) {
|
||||
// --- Home App Management section moved from FeaturesFragment ---
|
||||
var toggledAppsLocked by remember { mutableStateOf(prefs.homeLocked) }
|
||||
var toggledSettingsLocked by remember { mutableStateOf(prefs.settingsLocked) }
|
||||
var toggledLongPressAppInfo by remember { mutableStateOf(prefs.longPressAppInfoEnabled) }
|
||||
FullLineSeparator(isDark = isDark)
|
||||
// --- Insert Hidden Apps here ---
|
||||
SettingsHomeItem(
|
||||
title = stringResource(R.string.settings_hidden_apps_title),
|
||||
titleFontSize = titleFontSize,
|
||||
iconSize = iconSize,
|
||||
onClick = {
|
||||
// Copied from SettingsFragment
|
||||
viewModel.getHiddenApps()
|
||||
navController.navigate(
|
||||
R.id.action_settingsAdvancedFragment_to_appListFragment,
|
||||
androidx.core.os.bundleOf("flag" to com.github.gezimos.inkos.data.Constants.AppDrawerFlag.HiddenApps.toString())
|
||||
)
|
||||
}
|
||||
)
|
||||
DashedSeparator(isDark = isDark)
|
||||
SettingsSwitch(
|
||||
text = stringResource(R.string.lock_home_apps),
|
||||
fontSize = titleFontSize,
|
||||
defaultState = toggledAppsLocked,
|
||||
onCheckedChange = { checked ->
|
||||
toggledAppsLocked = checked
|
||||
prefs.homeLocked = checked
|
||||
if (!checked) {
|
||||
toggledLongPressAppInfo = false
|
||||
prefs.longPressAppInfoEnabled = false
|
||||
}
|
||||
}
|
||||
)
|
||||
DashedSeparator(isDark = isDark)
|
||||
SettingsSwitch(
|
||||
text = stringResource(R.string.longpress_app_info),
|
||||
fontSize = titleFontSize,
|
||||
defaultState = toggledLongPressAppInfo,
|
||||
enabled = toggledAppsLocked,
|
||||
onCheckedChange = { checked ->
|
||||
toggledLongPressAppInfo = checked
|
||||
prefs.longPressAppInfoEnabled = checked
|
||||
}
|
||||
)
|
||||
if (requireContext().isBiometricEnabled()) {
|
||||
DashedSeparator(isDark = isDark)
|
||||
SettingsSwitch(
|
||||
text = stringResource(R.string.lock_settings),
|
||||
fontSize = titleFontSize,
|
||||
defaultState = toggledSettingsLocked,
|
||||
onCheckedChange = { checked ->
|
||||
toggledSettingsLocked = checked
|
||||
prefs.settingsLocked = checked
|
||||
}
|
||||
)
|
||||
}
|
||||
DashedSeparator(isDark = isDark)
|
||||
// App Info item with version text (opens app info dialog on click)
|
||||
SettingsSelect(
|
||||
title = stringResource(R.string.app_version),
|
||||
option = "v0.1",
|
||||
fontSize = titleFontSize,
|
||||
enabled = true,
|
||||
onClick = {
|
||||
openAppInfo(
|
||||
requireContext(),
|
||||
android.os.Process.myUserHandle(),
|
||||
BuildConfig.APPLICATION_ID
|
||||
)
|
||||
}
|
||||
)
|
||||
DashedSeparator(isDark)
|
||||
SettingsHomeItem(
|
||||
title = stringResource(R.string.advanced_settings_backup_restore_title),
|
||||
titleFontSize = titleFontSize,
|
||||
iconSize = iconSize,
|
||||
onClick = {
|
||||
dialogBuilder.showBackupRestoreDialog()
|
||||
}
|
||||
)
|
||||
DashedSeparator(isDark)
|
||||
SettingsHomeItem(
|
||||
title = stringResource(changeLauncherText),
|
||||
titleFontSize = titleFontSize,
|
||||
iconSize = iconSize,
|
||||
onClick = {
|
||||
// Open system Default Home App settings for proper launcher selection UI
|
||||
val intent =
|
||||
android.content.Intent(android.provider.Settings.ACTION_HOME_SETTINGS)
|
||||
requireContext().startActivity(intent)
|
||||
}
|
||||
)
|
||||
DashedSeparator(isDark)
|
||||
SettingsHomeItem(
|
||||
title = stringResource(R.string.advanced_settings_restart_title),
|
||||
titleFontSize = titleFontSize,
|
||||
iconSize = iconSize,
|
||||
onClick = {
|
||||
AppReloader.restartApp(requireContext())
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
if (!isGestureNavigationEnabled(requireContext())) {
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun tuToDp(textUnit: TextUnit): Dp {
|
||||
val density = LocalDensity.current.density
|
||||
val scaledDensity = LocalDensity.current.fontScale
|
||||
val dpValue = textUnit.value * (density / scaledDensity)
|
||||
return dpValue.dp // Convert to Dp using the 'dp' extension
|
||||
}
|
||||
|
||||
|
||||
private fun dismissDialogs() {
|
||||
dialogBuilder.backupRestoreDialog?.dismiss()
|
||||
// dialogBuilder.saveLoadThemeDialog?.dismiss() // Remove theme dialog dismiss
|
||||
}
|
||||
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
@Suppress("DEPRECATION")
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
dialogBuilder = DialogManager(requireContext(), requireActivity())
|
||||
prefs = Prefs(requireContext())
|
||||
viewModel = activity?.run {
|
||||
ViewModelProvider(this)[MainViewModel::class.java]
|
||||
} ?: throw Exception("Invalid Activity")
|
||||
|
||||
viewModel.isinkosDefault()
|
||||
|
||||
deviceManager =
|
||||
context?.getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
|
||||
componentName = ComponentName(requireContext(), DeviceAdmin::class.java)
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
dismissDialogs()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,445 @@
|
||||
package com.github.gezimos.inkos.ui.settings
|
||||
|
||||
import android.app.admin.DevicePolicyManager
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.TextUnit
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.isSpecified
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.github.gezimos.common.isGestureNavigationEnabled
|
||||
import com.github.gezimos.inkos.MainViewModel
|
||||
import com.github.gezimos.inkos.R
|
||||
import com.github.gezimos.inkos.data.Constants
|
||||
import com.github.gezimos.inkos.data.Constants.Theme.Dark
|
||||
import com.github.gezimos.inkos.data.Constants.Theme.Light
|
||||
import com.github.gezimos.inkos.data.Constants.Theme.System
|
||||
import com.github.gezimos.inkos.data.Prefs
|
||||
import com.github.gezimos.inkos.helper.getHexForOpacity
|
||||
import com.github.gezimos.inkos.helper.isSystemInDarkMode
|
||||
import com.github.gezimos.inkos.listener.DeviceAdmin
|
||||
import com.github.gezimos.inkos.style.SettingsTheme
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.DashedSeparator
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.FullLineSeparator
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.PageHeader
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.SettingsSelect
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.SettingsSwitch
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.SettingsTitle
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.SolidSeparator
|
||||
import com.github.gezimos.inkos.ui.dialogs.DialogManager
|
||||
|
||||
class FeaturesFragment : Fragment() {
|
||||
|
||||
private lateinit var prefs: Prefs
|
||||
private lateinit var viewModel: MainViewModel
|
||||
private lateinit var deviceManager: DevicePolicyManager
|
||||
private lateinit var componentName: ComponentName
|
||||
private lateinit var dialogBuilder: DialogManager
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
prefs = Prefs(requireContext())
|
||||
dialogBuilder = DialogManager(requireContext(), requireActivity())
|
||||
val backgroundColor = getHexForOpacity(prefs)
|
||||
val isDark = when (prefs.appTheme) {
|
||||
Light -> false
|
||||
Dark -> true
|
||||
System -> isSystemInDarkMode(requireContext())
|
||||
}
|
||||
val settingsSize = (prefs.settingsSize - 3)
|
||||
val context = requireContext()
|
||||
// --- Dot indicator state ---
|
||||
val currentPage = intArrayOf(0)
|
||||
val pageCount = intArrayOf(1)
|
||||
|
||||
// Create a vertical LinearLayout to hold sticky header and scrollable content
|
||||
val rootLayout = android.widget.LinearLayout(context).apply {
|
||||
orientation = android.widget.LinearLayout.VERTICAL
|
||||
setBackgroundColor(backgroundColor)
|
||||
layoutParams = ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
}
|
||||
|
||||
var bottomInsetPx = 0
|
||||
androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener(rootLayout) { v, insets ->
|
||||
val navBarInset =
|
||||
insets.getInsets(androidx.core.view.WindowInsetsCompat.Type.navigationBars()).bottom
|
||||
bottomInsetPx = navBarInset
|
||||
insets
|
||||
}
|
||||
|
||||
// Add sticky header ComposeView
|
||||
val headerView = androidx.compose.ui.platform.ComposeView(context).apply {
|
||||
setContent {
|
||||
val density = androidx.compose.ui.platform.LocalDensity.current
|
||||
val bottomInsetDp = with(density) { bottomInsetPx.toDp() }
|
||||
SettingsTheme(isDark) {
|
||||
Column(Modifier.fillMaxWidth()) {
|
||||
PageHeader(
|
||||
iconRes = R.drawable.ic_back,
|
||||
title = stringResource(R.string.features_settings_title),
|
||||
onClick = { findNavController().popBackStack() },
|
||||
showStatusBar = prefs.showStatusBar,
|
||||
pageIndicator = {
|
||||
com.github.gezimos.inkos.ui.compose.SettingsComposable.PageIndicator(
|
||||
currentPage = currentPage[0],
|
||||
pageCount = pageCount[0],
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else TextUnit.Unspecified
|
||||
)
|
||||
},
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else TextUnit.Unspecified
|
||||
)
|
||||
SolidSeparator(isDark = isDark)
|
||||
Spacer(modifier = Modifier.height(SettingsTheme.color.horizontalPadding))
|
||||
if (bottomInsetDp > 0.dp) {
|
||||
Spacer(modifier = Modifier.height(bottomInsetDp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
rootLayout.addView(headerView)
|
||||
|
||||
// Add scrollable settings content
|
||||
val nestedScrollView = androidx.core.widget.NestedScrollView(context).apply {
|
||||
isFillViewport = true
|
||||
setBackgroundColor(backgroundColor)
|
||||
addView(
|
||||
androidx.compose.ui.platform.ComposeView(context).apply {
|
||||
setContent {
|
||||
val density = androidx.compose.ui.platform.LocalDensity.current
|
||||
val bottomInsetDp = with(density) { bottomInsetPx.toDp() }
|
||||
SettingsTheme(isDark) {
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
Column {
|
||||
FeaturesSettingsAllInOne(settingsSize.sp, isDark)
|
||||
if (bottomInsetDp > 0.dp) {
|
||||
Spacer(modifier = Modifier.height(bottomInsetDp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
)
|
||||
}
|
||||
com.github.gezimos.inkos.helper.utils.EinkScrollBehavior(context)
|
||||
.attachToScrollView(nestedScrollView)
|
||||
rootLayout.addView(
|
||||
nestedScrollView,
|
||||
ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
)
|
||||
|
||||
// --- Calculate pages and listen for scroll changes ---
|
||||
fun getCurrentPageIndex(
|
||||
scrollY: Int,
|
||||
viewportHeight: Int,
|
||||
contentHeight: Int,
|
||||
pageCount: Int
|
||||
): Int {
|
||||
if (contentHeight <= viewportHeight) return 0
|
||||
val overlap = (viewportHeight * 0.2).toInt()
|
||||
val scrollStep = viewportHeight - overlap
|
||||
val maxScroll = (contentHeight - viewportHeight).coerceAtLeast(1)
|
||||
val clampedScrollY = scrollY.coerceIn(0, maxScroll)
|
||||
val page = Math.round(clampedScrollY.toFloat() / scrollStep)
|
||||
return page.coerceIn(0, pageCount - 1)
|
||||
}
|
||||
nestedScrollView.viewTreeObserver.addOnGlobalLayoutListener {
|
||||
val contentHeight = nestedScrollView.getChildAt(0)?.height ?: 1
|
||||
val viewportHeight = nestedScrollView.height.takeIf { it > 0 } ?: 1
|
||||
val overlap = (viewportHeight * 0.2).toInt()
|
||||
val scrollStep = viewportHeight - overlap
|
||||
val pages =
|
||||
Math.ceil(((contentHeight - viewportHeight).toDouble() / scrollStep.toDouble()))
|
||||
.toInt() + 1
|
||||
pageCount[0] = pages
|
||||
val scrollY = nestedScrollView.scrollY
|
||||
currentPage[0] = getCurrentPageIndex(scrollY, viewportHeight, contentHeight, pages)
|
||||
headerView.setContent {
|
||||
SettingsTheme(isDark) {
|
||||
Column(Modifier.fillMaxWidth()) {
|
||||
PageHeader(
|
||||
iconRes = R.drawable.ic_back,
|
||||
title = stringResource(R.string.features_settings_title),
|
||||
onClick = { findNavController().popBackStack() },
|
||||
showStatusBar = prefs.showStatusBar,
|
||||
pageIndicator = {
|
||||
com.github.gezimos.inkos.ui.compose.SettingsComposable.PageIndicator(
|
||||
currentPage = currentPage[0],
|
||||
pageCount = pageCount[0],
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else TextUnit.Unspecified
|
||||
)
|
||||
},
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else TextUnit.Unspecified
|
||||
)
|
||||
SolidSeparator(isDark = isDark)
|
||||
Spacer(modifier = Modifier.height(SettingsTheme.color.horizontalPadding))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
nestedScrollView.setOnScrollChangeListener { _, _, scrollY, _, _ ->
|
||||
val contentHeight = nestedScrollView.getChildAt(0)?.height ?: 1
|
||||
val viewportHeight = nestedScrollView.height.takeIf { it > 0 } ?: 1
|
||||
val overlap = (viewportHeight * 0.2).toInt()
|
||||
val scrollStep = viewportHeight - overlap
|
||||
val pages =
|
||||
Math.ceil(((contentHeight - viewportHeight).toDouble() / scrollStep.toDouble()))
|
||||
.toInt() + 1
|
||||
pageCount[0] = pages
|
||||
currentPage[0] = getCurrentPageIndex(scrollY, viewportHeight, contentHeight, pages)
|
||||
headerView.setContent {
|
||||
SettingsTheme(isDark) {
|
||||
Column(Modifier.fillMaxWidth()) {
|
||||
PageHeader(
|
||||
iconRes = R.drawable.ic_back,
|
||||
title = stringResource(R.string.features_settings_title),
|
||||
onClick = { findNavController().popBackStack() },
|
||||
showStatusBar = prefs.showStatusBar,
|
||||
pageIndicator = {
|
||||
com.github.gezimos.inkos.ui.compose.SettingsComposable.PageIndicator(
|
||||
currentPage = currentPage[0],
|
||||
pageCount = pageCount[0],
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else TextUnit.Unspecified
|
||||
)
|
||||
},
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else TextUnit.Unspecified
|
||||
)
|
||||
SolidSeparator(isDark = isDark)
|
||||
Spacer(modifier = Modifier.height(SettingsTheme.color.horizontalPadding))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rootLayout
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun FeaturesSettingsAllInOne(fontSize: TextUnit = TextUnit.Unspecified, isDark: Boolean) {
|
||||
findNavController()
|
||||
val titleFontSize = if (fontSize.isSpecified) (fontSize.value * 1.5).sp else fontSize
|
||||
var selectedHomeAppsNum by remember { mutableIntStateOf(prefs.homeAppsNum) }
|
||||
var selectedHomePagesNum by remember { mutableIntStateOf(prefs.homePagesNum) }
|
||||
var toggledHomePager by remember { mutableStateOf(prefs.homePager) }
|
||||
var toggledShowClock by remember { mutableStateOf(prefs.showClock) }
|
||||
var toggledShowBattery by remember { mutableStateOf(prefs.showBattery) }
|
||||
// Layout & Positioning section (moved from LookFeelFragment)
|
||||
var toggledExtendHomeAppsArea = remember { mutableStateOf(prefs.extendHomeAppsArea) }
|
||||
var selectedPaddingSize = remember { mutableStateOf(prefs.textPaddingSize) }
|
||||
// Remove verticalScroll and isDark param, handled by parent ComposeView
|
||||
Column(modifier = Modifier.fillMaxWidth()) {
|
||||
FullLineSeparator(isDark)
|
||||
// --- Layout & Positioning (moved) ---
|
||||
SettingsTitle(
|
||||
text = stringResource(R.string.layout_positioning),
|
||||
fontSize = titleFontSize,
|
||||
)
|
||||
FullLineSeparator(isDark)
|
||||
SettingsSelect(
|
||||
title = stringResource(R.string.app_padding_size),
|
||||
option = selectedPaddingSize.value.toString(),
|
||||
fontSize = titleFontSize,
|
||||
onClick = {
|
||||
dialogBuilder.showSliderDialog(
|
||||
context = requireContext(),
|
||||
title = getString(R.string.app_padding_size),
|
||||
minValue = Constants.MIN_TEXT_PADDING,
|
||||
maxValue = Constants.MAX_TEXT_PADDING,
|
||||
currentValue = selectedPaddingSize.value,
|
||||
onValueSelected = { newPaddingSize ->
|
||||
selectedPaddingSize.value = newPaddingSize
|
||||
prefs.textPaddingSize = newPaddingSize
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
DashedSeparator(isDark)
|
||||
com.github.gezimos.inkos.ui.compose.SettingsComposable.SettingsHomeItem(
|
||||
title = stringResource(R.string.reorder_apps),
|
||||
onClick = {
|
||||
findNavController().navigate(
|
||||
R.id.action_settingsFeaturesFragment_to_appFavoriteFragment,
|
||||
bundleOf("flag" to Constants.AppDrawerFlag.SetHomeApp.toString())
|
||||
)
|
||||
},
|
||||
titleFontSize = titleFontSize
|
||||
)
|
||||
DashedSeparator(isDark)
|
||||
SettingsSwitch(
|
||||
text = stringResource(R.string.extend_home_apps_area),
|
||||
fontSize = titleFontSize,
|
||||
defaultState = toggledExtendHomeAppsArea.value,
|
||||
onCheckedChange = {
|
||||
toggledExtendHomeAppsArea.value = !prefs.extendHomeAppsArea
|
||||
prefs.extendHomeAppsArea = toggledExtendHomeAppsArea.value
|
||||
}
|
||||
)
|
||||
FullLineSeparator(isDark)
|
||||
// --- End Layout & Positioning (moved) ---
|
||||
// Home Apps Section
|
||||
SettingsTitle(
|
||||
text = stringResource(R.string.apps_on_home_screen),
|
||||
fontSize = titleFontSize,
|
||||
)
|
||||
FullLineSeparator(isDark)
|
||||
SettingsSelect(
|
||||
title = stringResource(R.string.apps_on_home_screen),
|
||||
option = selectedHomeAppsNum.toString(),
|
||||
fontSize = titleFontSize,
|
||||
onClick = {
|
||||
dialogBuilder.showSliderDialog(
|
||||
context = requireContext(),
|
||||
title = getString(R.string.apps_on_home_screen),
|
||||
minValue = Constants.MIN_HOME_APPS,
|
||||
maxValue = Constants.MAX_HOME_APPS,
|
||||
currentValue = prefs.homeAppsNum,
|
||||
onValueSelected = { newHomeAppsNum ->
|
||||
selectedHomeAppsNum = newHomeAppsNum
|
||||
prefs.homeAppsNum = newHomeAppsNum
|
||||
viewModel.homeAppsNum.value = newHomeAppsNum
|
||||
if (newHomeAppsNum in 1..<selectedHomePagesNum) {
|
||||
selectedHomePagesNum = newHomeAppsNum
|
||||
prefs.homePagesNum = newHomeAppsNum
|
||||
viewModel.homePagesNum.value = newHomeAppsNum
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
DashedSeparator(isDark)
|
||||
SettingsSelect(
|
||||
title = stringResource(R.string.pages_on_home_screen),
|
||||
option = selectedHomePagesNum.toString(),
|
||||
fontSize = titleFontSize,
|
||||
onClick = {
|
||||
Constants.updateMaxHomePages(requireContext())
|
||||
dialogBuilder.showSliderDialog(
|
||||
context = requireContext(),
|
||||
title = getString(R.string.pages_on_home_screen),
|
||||
minValue = Constants.MIN_HOME_PAGES,
|
||||
maxValue = Constants.MAX_HOME_PAGES,
|
||||
currentValue = prefs.homePagesNum,
|
||||
onValueSelected = { newHomePagesNum ->
|
||||
selectedHomePagesNum = newHomePagesNum
|
||||
prefs.homePagesNum = newHomePagesNum
|
||||
viewModel.homePagesNum.value = newHomePagesNum
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
DashedSeparator(isDark)
|
||||
SettingsSwitch(
|
||||
text = stringResource(R.string.enable_home_pager),
|
||||
fontSize = titleFontSize,
|
||||
defaultState = toggledHomePager,
|
||||
onCheckedChange = {
|
||||
toggledHomePager = !prefs.homePager
|
||||
prefs.homePager = toggledHomePager
|
||||
}
|
||||
)
|
||||
// Battery, Date, Time Section
|
||||
FullLineSeparator(isDark = isDark)
|
||||
SettingsTitle(
|
||||
text = stringResource(R.string.home_widgets),
|
||||
fontSize = titleFontSize,
|
||||
)
|
||||
FullLineSeparator(isDark)
|
||||
SettingsSwitch(
|
||||
text = stringResource(R.string.show_clock),
|
||||
fontSize = titleFontSize,
|
||||
defaultState = toggledShowClock,
|
||||
onCheckedChange = {
|
||||
toggledShowClock = !prefs.showClock
|
||||
prefs.showClock = toggledShowClock
|
||||
viewModel.setShowClock(prefs.showClock)
|
||||
}
|
||||
)
|
||||
DashedSeparator(isDark)
|
||||
SettingsSwitch(
|
||||
text = stringResource(R.string.show_battery),
|
||||
fontSize = titleFontSize,
|
||||
defaultState = toggledShowBattery,
|
||||
onCheckedChange = {
|
||||
toggledShowBattery = !prefs.showBattery
|
||||
prefs.showBattery = toggledShowBattery
|
||||
}
|
||||
)
|
||||
FullLineSeparator(isDark)
|
||||
Spacer(modifier = Modifier.height(100.dp))
|
||||
if (!isGestureNavigationEnabled(requireContext())) {
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun goBackToLastFragment() {
|
||||
findNavController().popBackStack()
|
||||
}
|
||||
|
||||
private fun dismissDialogs() {
|
||||
dialogBuilder.singleChoiceDialog?.dismiss()
|
||||
dialogBuilder.sliderDialog?.dismiss()
|
||||
}
|
||||
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
@Suppress("DEPRECATION")
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
dialogBuilder = DialogManager(requireContext(), requireActivity())
|
||||
prefs = Prefs(requireContext())
|
||||
viewModel = activity?.run {
|
||||
ViewModelProvider(this)[MainViewModel::class.java]
|
||||
} ?: throw Exception("Invalid Activity")
|
||||
|
||||
viewModel.isinkosDefault()
|
||||
|
||||
deviceManager =
|
||||
context?.getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
|
||||
componentName = ComponentName(requireContext(), DeviceAdmin::class.java)
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
dismissDialogs()
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,454 @@
|
||||
package com.github.gezimos.inkos.ui.settings
|
||||
|
||||
import android.app.admin.DevicePolicyManager
|
||||
import android.content.ComponentName
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.TextUnit
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.isSpecified
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.widget.NestedScrollView
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.github.gezimos.inkos.MainViewModel
|
||||
import com.github.gezimos.inkos.R
|
||||
import com.github.gezimos.inkos.data.Constants.Action
|
||||
import com.github.gezimos.inkos.data.Constants.AppDrawerFlag
|
||||
import com.github.gezimos.inkos.data.Constants.Theme.Dark
|
||||
import com.github.gezimos.inkos.data.Constants.Theme.Light
|
||||
import com.github.gezimos.inkos.data.Constants.Theme.System
|
||||
import com.github.gezimos.inkos.data.Prefs
|
||||
import com.github.gezimos.inkos.helper.getHexForOpacity
|
||||
import com.github.gezimos.inkos.helper.isSystemInDarkMode
|
||||
import com.github.gezimos.inkos.helper.utils.EinkScrollBehavior
|
||||
import com.github.gezimos.inkos.helper.utils.PrivateSpaceManager
|
||||
import com.github.gezimos.inkos.style.SettingsTheme
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.DashedSeparator
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.FullLineSeparator
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.PageHeader
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.PageIndicator
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.SettingsSelect
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.SettingsSwitch
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.SettingsTitle
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.SolidSeparator
|
||||
import com.github.gezimos.inkos.ui.dialogs.DialogManager
|
||||
|
||||
class GesturesFragment : Fragment() {
|
||||
|
||||
private lateinit var prefs: Prefs
|
||||
private lateinit var viewModel: MainViewModel
|
||||
private lateinit var deviceManager: DevicePolicyManager
|
||||
private lateinit var componentName: ComponentName
|
||||
private lateinit var dialogBuilder: DialogManager
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
prefs = Prefs(requireContext())
|
||||
dialogBuilder = DialogManager(requireContext(), requireActivity())
|
||||
val isDark = when (prefs.appTheme) {
|
||||
Light -> false
|
||||
Dark -> true
|
||||
System -> isSystemInDarkMode(requireContext())
|
||||
}
|
||||
val settingsSize = (prefs.settingsSize - 3)
|
||||
val backgroundColor = getHexForOpacity(prefs)
|
||||
val context = requireContext()
|
||||
// --- Dot indicator state ---
|
||||
val currentPage = intArrayOf(0)
|
||||
val pageCount = intArrayOf(1)
|
||||
|
||||
// Create a vertical LinearLayout to hold sticky header and scrollable content
|
||||
val rootLayout = android.widget.LinearLayout(context).apply {
|
||||
orientation = android.widget.LinearLayout.VERTICAL
|
||||
setBackgroundColor(backgroundColor)
|
||||
layoutParams = ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
}
|
||||
|
||||
var bottomInsetPx = 0
|
||||
ViewCompat.setOnApplyWindowInsetsListener(rootLayout) { v, insets ->
|
||||
val navBarInset = insets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom
|
||||
bottomInsetPx = navBarInset
|
||||
insets
|
||||
}
|
||||
|
||||
// Add sticky header ComposeView
|
||||
val headerView = ComposeView(context).apply {
|
||||
setContent {
|
||||
val density = LocalDensity.current
|
||||
val bottomInsetDp = with(density) { bottomInsetPx.toDp() }
|
||||
SettingsTheme(isDark) {
|
||||
Column(Modifier.fillMaxWidth()) {
|
||||
PageHeader(
|
||||
iconRes = R.drawable.ic_back,
|
||||
title = stringResource(R.string.gestures_settings_title),
|
||||
onClick = { findNavController().popBackStack() },
|
||||
showStatusBar = prefs.showStatusBar,
|
||||
pageIndicator = {
|
||||
PageIndicator(
|
||||
currentPage = currentPage[0],
|
||||
pageCount = pageCount[0],
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else TextUnit.Unspecified
|
||||
)
|
||||
},
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else TextUnit.Unspecified
|
||||
)
|
||||
SolidSeparator(isDark = isDark)
|
||||
Spacer(modifier = Modifier.height(SettingsTheme.color.horizontalPadding))
|
||||
if (bottomInsetDp > 0.dp) {
|
||||
Spacer(modifier = Modifier.height(bottomInsetDp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
rootLayout.addView(headerView)
|
||||
|
||||
// Add scrollable settings content
|
||||
val nestedScrollView = NestedScrollView(context).apply {
|
||||
isFillViewport = true
|
||||
setBackgroundColor(backgroundColor)
|
||||
addView(
|
||||
ComposeView(context).apply {
|
||||
setContent {
|
||||
val density = LocalDensity.current
|
||||
val bottomInsetDp = with(density) { bottomInsetPx.toDp() }
|
||||
SettingsTheme(isDark) {
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
Column {
|
||||
GesturesSettingsAllInOne(settingsSize.sp)
|
||||
if (bottomInsetDp > 0.dp) {
|
||||
Spacer(modifier = Modifier.height(bottomInsetDp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
)
|
||||
}
|
||||
EinkScrollBehavior(context).attachToScrollView(nestedScrollView)
|
||||
rootLayout.addView(
|
||||
nestedScrollView,
|
||||
ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
)
|
||||
|
||||
// --- Calculate pages and listen for scroll changes ---
|
||||
fun getCurrentPageIndex(
|
||||
scrollY: Int,
|
||||
viewportHeight: Int,
|
||||
contentHeight: Int,
|
||||
pageCount: Int
|
||||
): Int {
|
||||
if (contentHeight <= viewportHeight) return 0
|
||||
val overlap = (viewportHeight * 0.2).toInt()
|
||||
val scrollStep = viewportHeight - overlap
|
||||
val maxScroll = (contentHeight - viewportHeight).coerceAtLeast(1)
|
||||
val clampedScrollY = scrollY.coerceIn(0, maxScroll)
|
||||
val page = Math.round(clampedScrollY.toFloat() / scrollStep)
|
||||
return page.coerceIn(0, pageCount - 1)
|
||||
}
|
||||
nestedScrollView.viewTreeObserver.addOnGlobalLayoutListener {
|
||||
val contentHeight = nestedScrollView.getChildAt(0)?.height ?: 1
|
||||
val viewportHeight = nestedScrollView.height.takeIf { it > 0 } ?: 1
|
||||
val overlap = (viewportHeight * 0.2).toInt()
|
||||
val scrollStep = viewportHeight - overlap
|
||||
val pages =
|
||||
Math.ceil(((contentHeight - viewportHeight).toDouble() / scrollStep.toDouble()))
|
||||
.toInt() + 1
|
||||
pageCount[0] = pages
|
||||
val scrollY = nestedScrollView.scrollY
|
||||
currentPage[0] = getCurrentPageIndex(scrollY, viewportHeight, contentHeight, pages)
|
||||
headerView.setContent {
|
||||
SettingsTheme(isDark) {
|
||||
Column(Modifier.fillMaxWidth()) {
|
||||
PageHeader(
|
||||
iconRes = R.drawable.ic_back,
|
||||
title = stringResource(R.string.gestures_settings_title),
|
||||
onClick = { findNavController().popBackStack() },
|
||||
showStatusBar = prefs.showStatusBar,
|
||||
pageIndicator = {
|
||||
PageIndicator(
|
||||
currentPage = currentPage[0],
|
||||
pageCount = pageCount[0],
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else TextUnit.Unspecified
|
||||
)
|
||||
},
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else TextUnit.Unspecified
|
||||
)
|
||||
SolidSeparator(isDark = isDark)
|
||||
Spacer(modifier = Modifier.height(SettingsTheme.color.horizontalPadding))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
nestedScrollView.setOnScrollChangeListener { _, _, scrollY, _, _ ->
|
||||
val contentHeight = nestedScrollView.getChildAt(0)?.height ?: 1
|
||||
val viewportHeight = nestedScrollView.height.takeIf { it > 0 } ?: 1
|
||||
val overlap = (viewportHeight * 0.2).toInt()
|
||||
val scrollStep = viewportHeight - overlap
|
||||
val pages =
|
||||
Math.ceil(((contentHeight - viewportHeight).toDouble() / scrollStep.toDouble()))
|
||||
.toInt() + 1
|
||||
pageCount[0] = pages
|
||||
currentPage[0] = getCurrentPageIndex(scrollY, viewportHeight, contentHeight, pages)
|
||||
headerView.setContent {
|
||||
SettingsTheme(isDark) {
|
||||
Column(Modifier.fillMaxWidth()) {
|
||||
PageHeader(
|
||||
iconRes = R.drawable.ic_back,
|
||||
title = stringResource(R.string.gestures_settings_title),
|
||||
onClick = { findNavController().popBackStack() },
|
||||
showStatusBar = prefs.showStatusBar,
|
||||
pageIndicator = {
|
||||
PageIndicator(
|
||||
currentPage = currentPage[0],
|
||||
pageCount = pageCount[0],
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else TextUnit.Unspecified
|
||||
)
|
||||
},
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else TextUnit.Unspecified
|
||||
)
|
||||
SolidSeparator(isDark = isDark)
|
||||
Spacer(modifier = Modifier.height(SettingsTheme.color.horizontalPadding))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rootLayout
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun GesturesSettingsAllInOne(fontSize: TextUnit = TextUnit.Unspecified) {
|
||||
findNavController()
|
||||
val isDark = isSystemInDarkMode(requireContext())
|
||||
val titleFontSize = if (fontSize.isSpecified) (fontSize.value * 1.5).sp else fontSize
|
||||
var useVolumeKeys by remember { mutableStateOf(prefs.useVolumeKeysForPages) }
|
||||
var selectedDoubleTapAction by remember { mutableStateOf(prefs.doubleTapAction) }
|
||||
var selectedClickClockAction by remember { mutableStateOf(prefs.clickClockAction) }
|
||||
var selectedSwipeLeftAction by remember { mutableStateOf(prefs.swipeLeftAction) }
|
||||
var selectedSwipeRightAction by remember { mutableStateOf(prefs.swipeRightAction) }
|
||||
val actions = Action.entries
|
||||
val filteredActions =
|
||||
if (!PrivateSpaceManager(requireContext()).isPrivateSpaceSupported()) {
|
||||
actions.filter { it != Action.TogglePrivateSpace }
|
||||
} else actions
|
||||
// Remove OpenApp, NextPage, and PreviousPage from double tap gesture actions only
|
||||
val doubleTapGestureActions = filteredActions.filter { action ->
|
||||
action != Action.OpenApp &&
|
||||
action != Action.NextPage &&
|
||||
action != Action.PreviousPage &&
|
||||
when (action) {
|
||||
Action.OpenNotificationsScreen -> prefs.notificationsEnabled
|
||||
Action.OpenNotificationsScreenAlt -> false
|
||||
else -> true
|
||||
}
|
||||
}.toMutableList()
|
||||
// Only remove NextPage and PreviousPage from click clock gesture actions
|
||||
val clickClockGestureActions = filteredActions.filter { action ->
|
||||
action != Action.NextPage &&
|
||||
action != Action.PreviousPage &&
|
||||
when (action) {
|
||||
Action.OpenNotificationsScreen -> prefs.notificationsEnabled
|
||||
Action.OpenNotificationsScreenAlt -> false
|
||||
else -> true
|
||||
}
|
||||
}.toMutableList()
|
||||
// For swipe left/right, do not filter out NextPage or PreviousPage
|
||||
val gestureActions = filteredActions.filter { action ->
|
||||
when (action) {
|
||||
Action.OpenNotificationsScreen -> prefs.notificationsEnabled
|
||||
Action.OpenNotificationsScreenAlt -> false
|
||||
else -> true
|
||||
}
|
||||
}.toMutableList()
|
||||
val doubleTapActionStrings =
|
||||
doubleTapGestureActions.map { it.getString(requireContext()) }.toTypedArray()
|
||||
val clickClockActionStrings =
|
||||
clickClockGestureActions.map { it.getString(requireContext()) }.toTypedArray()
|
||||
val actionStrings = gestureActions.map { it.getString(requireContext()) }.toTypedArray()
|
||||
val appLabelDoubleTapAction = prefs.appDoubleTap.activityLabel
|
||||
prefs.appClickClock.activityLabel.ifEmpty { "Clock" }
|
||||
val appLabelSwipeLeftAction = prefs.appSwipeLeft.activityLabel.ifEmpty { "Camera" }
|
||||
val appLabelSwipeRightAction = prefs.appSwipeRight.activityLabel.ifEmpty { "Phone" }
|
||||
Column(modifier = Modifier.fillMaxSize()) {
|
||||
FullLineSeparator(isDark)
|
||||
SettingsSwitch(
|
||||
text = stringResource(R.string.use_volume_keys_for_pages),
|
||||
fontSize = titleFontSize,
|
||||
defaultState = useVolumeKeys,
|
||||
onCheckedChange = {
|
||||
useVolumeKeys = it
|
||||
prefs.useVolumeKeysForPages = it
|
||||
}
|
||||
)
|
||||
// Tap/Click Actions Section
|
||||
FullLineSeparator(isDark)
|
||||
SettingsTitle(
|
||||
text = stringResource(R.string.tap_click_actions),
|
||||
fontSize = titleFontSize,
|
||||
)
|
||||
FullLineSeparator(isDark)
|
||||
SettingsSelect(
|
||||
title = stringResource(R.string.double_tap),
|
||||
option = if (selectedDoubleTapAction == Action.OpenApp) {
|
||||
// fallback, but OpenApp should not be selectable
|
||||
"${stringResource(R.string.open)} $appLabelDoubleTapAction"
|
||||
} else {
|
||||
selectedDoubleTapAction.string()
|
||||
},
|
||||
fontSize = titleFontSize,
|
||||
onClick = {
|
||||
dialogBuilder.showSingleChoiceDialog(
|
||||
context = requireContext(),
|
||||
options = doubleTapActionStrings,
|
||||
titleResId = R.string.double_tap,
|
||||
onItemSelected = { newDoubleTapAction: String ->
|
||||
val selectedAction =
|
||||
doubleTapGestureActions.firstOrNull { it.getString(requireContext()) == newDoubleTapAction }
|
||||
if (selectedAction != null) {
|
||||
selectedDoubleTapAction = selectedAction
|
||||
setGesture(AppDrawerFlag.SetDoubleTap, selectedAction)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
DashedSeparator(isDark)
|
||||
SettingsSelect(
|
||||
title = stringResource(R.string.clock_click_app),
|
||||
option = if (selectedClickClockAction == Action.OpenApp) {
|
||||
stringResource(R.string.open_clock)
|
||||
} else {
|
||||
selectedClickClockAction.string()
|
||||
},
|
||||
fontSize = titleFontSize,
|
||||
onClick = {
|
||||
dialogBuilder.showSingleChoiceDialog(
|
||||
context = requireContext(),
|
||||
options = clickClockActionStrings,
|
||||
titleResId = R.string.clock_click_app,
|
||||
onItemSelected = { newClickClock: String ->
|
||||
val selectedAction =
|
||||
clickClockGestureActions.firstOrNull { it.getString(requireContext()) == newClickClock }
|
||||
if (selectedAction != null) {
|
||||
selectedClickClockAction = selectedAction
|
||||
setGesture(AppDrawerFlag.SetClickClock, selectedAction)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
// Swipe Actions Section
|
||||
FullLineSeparator(isDark)
|
||||
SettingsTitle(
|
||||
text = stringResource(R.string.swipe_movement),
|
||||
fontSize = titleFontSize,
|
||||
)
|
||||
FullLineSeparator(isDark)
|
||||
// Swipe Up/Down removed from UI
|
||||
SettingsSelect(
|
||||
title = stringResource(R.string.swipe_left_app),
|
||||
option = if (selectedSwipeLeftAction == Action.OpenApp) {
|
||||
"${stringResource(R.string.open)} $appLabelSwipeLeftAction"
|
||||
} else {
|
||||
selectedSwipeLeftAction.string()
|
||||
},
|
||||
fontSize = titleFontSize,
|
||||
onClick = {
|
||||
dialogBuilder.showSingleChoiceDialog(
|
||||
context = requireContext(),
|
||||
options = actionStrings,
|
||||
titleResId = R.string.swipe_left_app,
|
||||
onItemSelected = { newAction: String ->
|
||||
val selectedAction =
|
||||
gestureActions.firstOrNull { it.getString(requireContext()) == newAction }
|
||||
if (selectedAction != null) {
|
||||
selectedSwipeLeftAction = selectedAction
|
||||
setGesture(AppDrawerFlag.SetSwipeLeft, selectedAction)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
DashedSeparator(isDark)
|
||||
SettingsSelect(
|
||||
title = stringResource(R.string.swipe_right_app),
|
||||
option = if (selectedSwipeRightAction == Action.OpenApp) {
|
||||
"${stringResource(R.string.open)} $appLabelSwipeRightAction"
|
||||
} else {
|
||||
selectedSwipeRightAction.string()
|
||||
},
|
||||
fontSize = titleFontSize,
|
||||
onClick = {
|
||||
dialogBuilder.showSingleChoiceDialog(
|
||||
context = requireContext(),
|
||||
options = actionStrings,
|
||||
titleResId = R.string.swipe_right_app,
|
||||
onItemSelected = { newAction: String ->
|
||||
val selectedAction =
|
||||
gestureActions.firstOrNull { it.getString(requireContext()) == newAction }
|
||||
if (selectedAction != null) {
|
||||
selectedSwipeRightAction = selectedAction
|
||||
setGesture(AppDrawerFlag.SetSwipeRight, selectedAction)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
DashedSeparator(isDark)
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
}
|
||||
}
|
||||
|
||||
private fun setGesture(flag: AppDrawerFlag, action: Action) {
|
||||
when (flag) {
|
||||
AppDrawerFlag.SetDoubleTap -> prefs.doubleTapAction = action
|
||||
AppDrawerFlag.SetClickClock -> prefs.clickClockAction = action
|
||||
AppDrawerFlag.SetSwipeLeft -> prefs.swipeLeftAction = action
|
||||
AppDrawerFlag.SetSwipeRight -> prefs.swipeRightAction = action
|
||||
AppDrawerFlag.LaunchApp,
|
||||
AppDrawerFlag.HiddenApps,
|
||||
AppDrawerFlag.PrivateApps,
|
||||
AppDrawerFlag.SetHomeApp -> {
|
||||
// No-op for these flags in this context
|
||||
}
|
||||
|
||||
else -> {
|
||||
// No-op for unused/removed flags (SetSwipeUp, SetSwipeDown, SetAppUsage, SetFloating)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,447 @@
|
||||
package com.github.gezimos.inkos.ui.settings
|
||||
|
||||
import android.app.admin.DevicePolicyManager
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.TextUnit
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.isSpecified
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.github.gezimos.inkos.MainViewModel
|
||||
import com.github.gezimos.inkos.R
|
||||
import com.github.gezimos.inkos.data.Constants
|
||||
import com.github.gezimos.inkos.data.Constants.Theme.Dark
|
||||
import com.github.gezimos.inkos.data.Constants.Theme.Light
|
||||
import com.github.gezimos.inkos.data.Constants.Theme.System
|
||||
import com.github.gezimos.inkos.data.Prefs
|
||||
import com.github.gezimos.inkos.helper.getHexForOpacity
|
||||
import com.github.gezimos.inkos.helper.hideStatusBar
|
||||
import com.github.gezimos.inkos.helper.isSystemInDarkMode
|
||||
import com.github.gezimos.inkos.helper.setThemeMode
|
||||
import com.github.gezimos.inkos.helper.showStatusBar
|
||||
import com.github.gezimos.inkos.listener.DeviceAdmin
|
||||
import com.github.gezimos.inkos.style.SettingsTheme
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.DashedSeparator
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.FullLineSeparator
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.PageHeader
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.SettingsSelect
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.SettingsSelectWithColorPreview
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.SettingsSwitch
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.SettingsTitle
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable.SolidSeparator
|
||||
import com.github.gezimos.inkos.ui.dialogs.DialogManager
|
||||
|
||||
class LookFeelFragment : Fragment() {
|
||||
|
||||
private lateinit var prefs: Prefs
|
||||
private lateinit var viewModel: MainViewModel
|
||||
private lateinit var deviceManager: DevicePolicyManager
|
||||
private lateinit var componentName: ComponentName
|
||||
private lateinit var dialogBuilder: DialogManager
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
prefs = Prefs(requireContext())
|
||||
dialogBuilder = DialogManager(requireContext(), requireActivity())
|
||||
val backgroundColor = getHexForOpacity(prefs)
|
||||
val isDark = when (prefs.appTheme) {
|
||||
Light -> false
|
||||
Dark -> true
|
||||
System -> isSystemInDarkMode(requireContext())
|
||||
}
|
||||
val settingsSize = (prefs.settingsSize - 3)
|
||||
val context = requireContext()
|
||||
val currentPage = intArrayOf(0)
|
||||
val pageCount = intArrayOf(1)
|
||||
|
||||
val rootLayout = android.widget.LinearLayout(context).apply {
|
||||
orientation = android.widget.LinearLayout.VERTICAL
|
||||
setBackgroundColor(backgroundColor)
|
||||
layoutParams = ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
}
|
||||
|
||||
var bottomInsetPx = 0
|
||||
androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener(rootLayout) { v, insets ->
|
||||
val navBarInset =
|
||||
insets.getInsets(androidx.core.view.WindowInsetsCompat.Type.navigationBars()).bottom
|
||||
bottomInsetPx = navBarInset
|
||||
insets
|
||||
}
|
||||
|
||||
// Marked as @Composable for Compose usage
|
||||
@Composable
|
||||
fun HeaderContent() {
|
||||
androidx.compose.ui.platform.LocalDensity.current
|
||||
// Remove bottomInsetDp from header
|
||||
SettingsTheme(isDark) {
|
||||
Column(Modifier.fillMaxWidth()) {
|
||||
PageHeader(
|
||||
iconRes = R.drawable.ic_back,
|
||||
title = stringResource(R.string.look_feel_settings_title),
|
||||
onClick = { findNavController().popBackStack() },
|
||||
showStatusBar = prefs.showStatusBar,
|
||||
pageIndicator = {
|
||||
com.github.gezimos.inkos.ui.compose.SettingsComposable.PageIndicator(
|
||||
currentPage = currentPage[0],
|
||||
pageCount = pageCount[0],
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else TextUnit.Unspecified
|
||||
)
|
||||
},
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else TextUnit.Unspecified
|
||||
)
|
||||
SolidSeparator(isDark = isDark)
|
||||
Spacer(modifier = Modifier.height(SettingsTheme.color.horizontalPadding))
|
||||
// (No bottomInsetDp here)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val headerView = androidx.compose.ui.platform.ComposeView(context).apply {
|
||||
setContent { HeaderContent() }
|
||||
}
|
||||
rootLayout.addView(headerView)
|
||||
|
||||
val nestedScrollView = androidx.core.widget.NestedScrollView(context).apply {
|
||||
isFillViewport = true
|
||||
setBackgroundColor(backgroundColor)
|
||||
addView(
|
||||
androidx.compose.ui.platform.ComposeView(context).apply {
|
||||
setContent {
|
||||
val density = androidx.compose.ui.platform.LocalDensity.current
|
||||
val bottomInsetDp = with(density) { bottomInsetPx.toDp() }
|
||||
SettingsTheme(isDark) {
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
Column {
|
||||
LookFeelSettingsAllInOne(settingsSize.sp, isDark)
|
||||
if (bottomInsetDp > 0.dp) {
|
||||
Spacer(modifier = Modifier.height(bottomInsetDp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
)
|
||||
}
|
||||
com.github.gezimos.inkos.helper.utils.EinkScrollBehavior(context)
|
||||
.attachToScrollView(nestedScrollView)
|
||||
rootLayout.addView(
|
||||
nestedScrollView,
|
||||
ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
)
|
||||
|
||||
fun getCurrentPageIndex(
|
||||
scrollY: Int,
|
||||
viewportHeight: Int,
|
||||
contentHeight: Int,
|
||||
pageCount: Int
|
||||
): Int {
|
||||
if (contentHeight <= viewportHeight) return 0
|
||||
val overlap = (viewportHeight * 0.2).toInt()
|
||||
val scrollStep = viewportHeight - overlap
|
||||
val maxScroll = (contentHeight - viewportHeight).coerceAtLeast(1)
|
||||
val clampedScrollY = scrollY.coerceIn(0, maxScroll)
|
||||
val page = Math.round(clampedScrollY.toFloat() / scrollStep)
|
||||
return page.coerceIn(0, pageCount - 1)
|
||||
}
|
||||
|
||||
fun updateHeaderAndPages(scrollY: Int = nestedScrollView.scrollY) {
|
||||
val contentHeight = nestedScrollView.getChildAt(0)?.height ?: 1
|
||||
val viewportHeight = nestedScrollView.height.takeIf { it > 0 } ?: 1
|
||||
val overlap = (viewportHeight * 0.2).toInt()
|
||||
val scrollStep = viewportHeight - overlap
|
||||
val pages =
|
||||
Math.ceil(((contentHeight - viewportHeight).toDouble() / scrollStep.toDouble()))
|
||||
.toInt() + 1
|
||||
pageCount[0] = pages
|
||||
currentPage[0] = getCurrentPageIndex(scrollY, viewportHeight, contentHeight, pages)
|
||||
headerView.setContent { HeaderContent() }
|
||||
}
|
||||
nestedScrollView.viewTreeObserver.addOnGlobalLayoutListener {
|
||||
updateHeaderAndPages()
|
||||
}
|
||||
nestedScrollView.setOnScrollChangeListener { _, _, scrollY, _, _ ->
|
||||
updateHeaderAndPages(scrollY)
|
||||
}
|
||||
return rootLayout
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun LookFeelSettingsAllInOne(fontSize: TextUnit = TextUnit.Unspecified, isDark: Boolean) {
|
||||
findNavController()
|
||||
val titleFontSize = if (fontSize.isSpecified) (fontSize.value * 1.5).sp else fontSize
|
||||
var toggledShowStatusBar = remember { mutableStateOf(prefs.showStatusBar) }
|
||||
var selectedTheme = remember { mutableStateOf(prefs.appTheme) }
|
||||
var selectedBackgroundColor = remember { mutableStateOf(prefs.backgroundColor) }
|
||||
var selectedAppColor = remember { mutableStateOf(prefs.appColor) }
|
||||
var selectedClockColor = remember { mutableStateOf(prefs.clockColor) }
|
||||
var selectedBatteryColor = remember { mutableStateOf(prefs.batteryColor) }
|
||||
var einkRefreshEnabled = remember { mutableStateOf(prefs.einkRefreshEnabled) }
|
||||
var vibrationForPaging = remember { mutableStateOf(prefs.useVibrationForPaging) }
|
||||
Constants.updateMaxHomePages(requireContext())
|
||||
Column(modifier = Modifier.fillMaxSize()) {
|
||||
// Theme Mode
|
||||
FullLineSeparator(isDark = isDark)
|
||||
|
||||
// Visibility & Display
|
||||
SettingsTitle(
|
||||
text = stringResource(R.string.visibility_display),
|
||||
fontSize = titleFontSize,
|
||||
)
|
||||
FullLineSeparator(isDark)
|
||||
SettingsSelect(
|
||||
title = stringResource(R.string.theme_mode),
|
||||
option = selectedTheme.value.string(),
|
||||
fontSize = titleFontSize,
|
||||
onClick = {
|
||||
dialogBuilder.showSingleChoiceDialog(
|
||||
context = requireContext(),
|
||||
options = Constants.Theme.entries.toTypedArray(),
|
||||
titleResId = R.string.theme_mode,
|
||||
onItemSelected = { newTheme ->
|
||||
selectedTheme.value = newTheme
|
||||
prefs.appTheme = newTheme
|
||||
val isDark = when (newTheme) {
|
||||
Light -> false
|
||||
Dark -> true
|
||||
System -> isSystemInDarkMode(requireContext())
|
||||
}
|
||||
prefs.backgroundColor =
|
||||
if (isDark) Color.Black.toArgb() else Color.White.toArgb()
|
||||
prefs.appColor =
|
||||
if (isDark) Color.White.toArgb() else Color.Black.toArgb()
|
||||
prefs.clockColor =
|
||||
if (isDark) Color.White.toArgb() else Color.Black.toArgb()
|
||||
prefs.batteryColor =
|
||||
if (isDark) Color.White.toArgb() else Color.Black.toArgb()
|
||||
setThemeMode(
|
||||
requireContext(),
|
||||
isDark,
|
||||
requireActivity().window.decorView
|
||||
)
|
||||
requireActivity().recreate()
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
// --- Eink Refresh Switch inserted here ---
|
||||
DashedSeparator(isDark)
|
||||
SettingsSwitch(
|
||||
text = "E-Ink Refresh",
|
||||
fontSize = titleFontSize,
|
||||
defaultState = einkRefreshEnabled.value,
|
||||
onCheckedChange = {
|
||||
einkRefreshEnabled.value = it
|
||||
prefs.einkRefreshEnabled = it
|
||||
}
|
||||
)
|
||||
DashedSeparator(isDark)
|
||||
SettingsSwitch(
|
||||
text = "Vibration for Paging",
|
||||
fontSize = titleFontSize,
|
||||
defaultState = vibrationForPaging.value,
|
||||
onCheckedChange = {
|
||||
vibrationForPaging.value = it
|
||||
prefs.useVibrationForPaging = it
|
||||
}
|
||||
)
|
||||
DashedSeparator(isDark)
|
||||
SettingsSwitch(
|
||||
text = stringResource(R.string.show_status_bar),
|
||||
fontSize = titleFontSize,
|
||||
defaultState = toggledShowStatusBar.value,
|
||||
onCheckedChange = {
|
||||
toggledShowStatusBar.value = !prefs.showStatusBar
|
||||
prefs.showStatusBar = toggledShowStatusBar.value
|
||||
if (toggledShowStatusBar.value) showStatusBar(requireActivity()) else hideStatusBar(
|
||||
requireActivity()
|
||||
)
|
||||
}
|
||||
)
|
||||
// Element Colors
|
||||
FullLineSeparator(isDark)
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
SettingsTitle(
|
||||
text = stringResource(R.string.element_colors),
|
||||
fontSize = titleFontSize,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
Text(
|
||||
text = stringResource(R.string.reset),
|
||||
style = SettingsTheme.typography.button,
|
||||
fontSize = if (titleFontSize.isSpecified) (titleFontSize.value * 0.7).sp else 14.sp,
|
||||
modifier = Modifier
|
||||
.padding(end = SettingsTheme.color.horizontalPadding)
|
||||
.clickable {
|
||||
val isDarkMode = when (prefs.appTheme) {
|
||||
Dark -> true
|
||||
Light -> false
|
||||
System -> isSystemInDarkMode(requireContext())
|
||||
}
|
||||
selectedBackgroundColor.value =
|
||||
if (isDarkMode) Color.Black.toArgb() else Color.White.toArgb()
|
||||
selectedAppColor.value =
|
||||
if (isDarkMode) Color.White.toArgb() else Color.Black.toArgb()
|
||||
selectedClockColor.value =
|
||||
if (isDarkMode) Color.White.toArgb() else Color.Black.toArgb()
|
||||
selectedBatteryColor.value =
|
||||
if (isDarkMode) Color.White.toArgb() else Color.Black.toArgb()
|
||||
prefs.backgroundColor = selectedBackgroundColor.value
|
||||
prefs.appColor = selectedAppColor.value
|
||||
prefs.clockColor = selectedClockColor.value
|
||||
prefs.batteryColor = selectedBatteryColor.value
|
||||
}
|
||||
)
|
||||
}
|
||||
FullLineSeparator(isDark)
|
||||
val hexBackgroundColor =
|
||||
String.format("#%06X", (0xFFFFFF and selectedBackgroundColor.value))
|
||||
SettingsSelectWithColorPreview(
|
||||
title = stringResource(R.string.background_color),
|
||||
hexColor = hexBackgroundColor,
|
||||
previewColor = Color(selectedBackgroundColor.value),
|
||||
fontSize = titleFontSize,
|
||||
onClick = {
|
||||
dialogBuilder.showColorPickerDialog(
|
||||
context = requireContext(),
|
||||
color = selectedBackgroundColor.value,
|
||||
titleResId = R.string.background_color,
|
||||
onItemSelected = { selectedColor ->
|
||||
selectedBackgroundColor.value = selectedColor
|
||||
prefs.backgroundColor = selectedColor
|
||||
})
|
||||
}
|
||||
)
|
||||
DashedSeparator(isDark)
|
||||
val hexAppColor = String.format("#%06X", (0xFFFFFF and selectedAppColor.value))
|
||||
SettingsSelectWithColorPreview(
|
||||
title = stringResource(R.string.app_color),
|
||||
hexColor = hexAppColor,
|
||||
previewColor = Color(selectedAppColor.value),
|
||||
fontSize = titleFontSize,
|
||||
onClick = {
|
||||
dialogBuilder.showColorPickerDialog(
|
||||
context = requireContext(),
|
||||
color = selectedAppColor.value,
|
||||
titleResId = R.string.app_color,
|
||||
onItemSelected = { selectedColor ->
|
||||
selectedAppColor.value = selectedColor
|
||||
prefs.appColor = selectedColor
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
DashedSeparator(isDark)
|
||||
val hexClockColor = String.format("#%06X", (0xFFFFFF and selectedClockColor.value))
|
||||
SettingsSelectWithColorPreview(
|
||||
title = stringResource(R.string.clock_color),
|
||||
hexColor = hexClockColor,
|
||||
previewColor = Color(selectedClockColor.value),
|
||||
fontSize = titleFontSize,
|
||||
onClick = {
|
||||
dialogBuilder.showColorPickerDialog(
|
||||
context = requireContext(),
|
||||
color = selectedClockColor.value,
|
||||
titleResId = R.string.clock_color,
|
||||
onItemSelected = { selectedColor ->
|
||||
selectedClockColor.value = selectedColor
|
||||
prefs.clockColor = selectedColor
|
||||
})
|
||||
}
|
||||
)
|
||||
DashedSeparator(isDark)
|
||||
val hexBatteryColor = String.format("#%06X", (0xFFFFFF and selectedBatteryColor.value))
|
||||
SettingsSelectWithColorPreview(
|
||||
title = stringResource(R.string.battery_color),
|
||||
hexColor = hexBatteryColor,
|
||||
previewColor = Color(selectedBatteryColor.value),
|
||||
fontSize = titleFontSize,
|
||||
onClick = {
|
||||
dialogBuilder.showColorPickerDialog(
|
||||
context = requireContext(),
|
||||
color = selectedBatteryColor.value,
|
||||
titleResId = R.string.battery_color,
|
||||
onItemSelected = { selectedColor ->
|
||||
selectedBatteryColor.value = selectedColor
|
||||
prefs.batteryColor = selectedColor
|
||||
})
|
||||
}
|
||||
)
|
||||
FullLineSeparator(isDark)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private fun goBackToLastFragment() {
|
||||
findNavController().popBackStack()
|
||||
}
|
||||
|
||||
private fun dismissDialogs() {
|
||||
dialogBuilder.colorPickerDialog?.dismiss()
|
||||
dialogBuilder.singleChoiceDialog?.dismiss()
|
||||
dialogBuilder.sliderDialog?.dismiss()
|
||||
}
|
||||
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
@Suppress("DEPRECATION")
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
dialogBuilder = DialogManager(requireContext(), requireActivity())
|
||||
prefs = Prefs(requireContext())
|
||||
viewModel = activity?.run {
|
||||
ViewModelProvider(this)[MainViewModel::class.java]
|
||||
} ?: throw Exception("Invalid Activity")
|
||||
|
||||
viewModel.isinkosDefault()
|
||||
|
||||
deviceManager =
|
||||
context?.getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
|
||||
componentName = ComponentName(requireContext(), DeviceAdmin::class.java)
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
dismissDialogs()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,719 @@
|
||||
package com.github.gezimos.inkos.ui.settings
|
||||
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.github.gezimos.inkos.R
|
||||
import com.github.gezimos.inkos.data.Prefs
|
||||
import com.github.gezimos.inkos.helper.isSystemInDarkMode
|
||||
import com.github.gezimos.inkos.style.SettingsTheme
|
||||
import com.github.gezimos.inkos.ui.compose.SettingsComposable
|
||||
import com.github.gezimos.inkos.ui.dialogs.DialogManager
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class NotificationSettingsFragment : Fragment() {
|
||||
private lateinit var prefs: Prefs
|
||||
private lateinit var dialogManager: DialogManager
|
||||
|
||||
private var onCustomFontSelected: ((com.github.gezimos.inkos.data.Constants.FontFamily) -> Unit)? =
|
||||
null
|
||||
|
||||
// Helper data class for app info
|
||||
data class AppInfo(val label: String, val packageName: String)
|
||||
|
||||
@Suppress("unused")
|
||||
private fun getInstalledApps(): List<AppInfo> {
|
||||
val pm = requireContext().packageManager
|
||||
val apps = pm.getInstalledApplications(0)
|
||||
return apps.map {
|
||||
val label = pm.getApplicationLabel(it).toString()
|
||||
AppInfo(label, it.packageName)
|
||||
}.sortedBy { it.label.lowercase() }
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
prefs = Prefs(requireContext())
|
||||
dialogManager = DialogManager(requireContext(), requireActivity())
|
||||
val isDark = when (prefs.appTheme) {
|
||||
com.github.gezimos.inkos.data.Constants.Theme.Light -> false
|
||||
com.github.gezimos.inkos.data.Constants.Theme.Dark -> true
|
||||
com.github.gezimos.inkos.data.Constants.Theme.System -> isSystemInDarkMode(
|
||||
requireContext()
|
||||
)
|
||||
}
|
||||
val settingsSize = (prefs.settingsSize - 3)
|
||||
val backgroundColor = com.github.gezimos.inkos.helper.getHexForOpacity(prefs)
|
||||
val context = requireContext()
|
||||
// --- Dot indicator state ---
|
||||
val currentPage = intArrayOf(0)
|
||||
val pageCount = intArrayOf(1)
|
||||
|
||||
// Create a vertical LinearLayout to hold sticky header and scrollable content
|
||||
val rootLayout = android.widget.LinearLayout(context).apply {
|
||||
orientation = android.widget.LinearLayout.VERTICAL
|
||||
setBackgroundColor(backgroundColor)
|
||||
layoutParams = ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
}
|
||||
|
||||
var bottomInsetPx = 0
|
||||
ViewCompat.setOnApplyWindowInsetsListener(rootLayout) { v, insets ->
|
||||
val navBarInset =
|
||||
insets.getInsets(androidx.core.view.WindowInsetsCompat.Type.navigationBars()).bottom
|
||||
bottomInsetPx = navBarInset
|
||||
insets
|
||||
}
|
||||
|
||||
// Add sticky header ComposeView
|
||||
val headerView = androidx.compose.ui.platform.ComposeView(context).apply {
|
||||
setContent {
|
||||
val density = androidx.compose.ui.platform.LocalDensity.current
|
||||
val bottomInsetDp = with(density) { bottomInsetPx.toDp() }
|
||||
SettingsTheme(isDark) {
|
||||
Column(Modifier.fillMaxWidth()) {
|
||||
SettingsComposable.PageHeader(
|
||||
iconRes = R.drawable.ic_back,
|
||||
title = stringResource(R.string.notification_section),
|
||||
onClick = { findNavController().popBackStack() },
|
||||
showStatusBar = prefs.showStatusBar,
|
||||
pageIndicator = {
|
||||
SettingsComposable.PageIndicator(
|
||||
currentPage = currentPage[0],
|
||||
pageCount = pageCount[0],
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else androidx.compose.ui.unit.TextUnit.Unspecified
|
||||
)
|
||||
},
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else androidx.compose.ui.unit.TextUnit.Unspecified
|
||||
)
|
||||
SettingsComposable.SolidSeparator(isDark = isDark)
|
||||
Spacer(modifier = Modifier.height(SettingsTheme.color.horizontalPadding))
|
||||
if (bottomInsetDp > 0.dp) {
|
||||
Spacer(modifier = Modifier.height(bottomInsetDp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
rootLayout.addView(headerView)
|
||||
|
||||
// Add scrollable settings content
|
||||
val nestedScrollView = androidx.core.widget.NestedScrollView(context).apply {
|
||||
isFillViewport = true
|
||||
setBackgroundColor(backgroundColor)
|
||||
addView(
|
||||
androidx.compose.ui.platform.ComposeView(context).apply {
|
||||
setContent {
|
||||
val density = androidx.compose.ui.platform.LocalDensity.current
|
||||
val bottomInsetDp = with(density) { bottomInsetPx.toDp() }
|
||||
SettingsTheme(isDark) {
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
Column {
|
||||
NotificationSettingsAllInOne(settingsSize.sp)
|
||||
if (bottomInsetDp > 0.dp) {
|
||||
Spacer(modifier = Modifier.height(bottomInsetDp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
)
|
||||
}
|
||||
com.github.gezimos.inkos.helper.utils.EinkScrollBehavior(context)
|
||||
.attachToScrollView(nestedScrollView)
|
||||
rootLayout.addView(
|
||||
nestedScrollView,
|
||||
ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
)
|
||||
|
||||
// --- Calculate pages and listen for scroll changes ---
|
||||
fun getCurrentPageIndex(
|
||||
scrollY: Int,
|
||||
viewportHeight: Int,
|
||||
contentHeight: Int,
|
||||
pageCount: Int
|
||||
): Int {
|
||||
if (contentHeight <= viewportHeight) return 0
|
||||
val overlap = (viewportHeight * 0.2).toInt()
|
||||
val scrollStep = viewportHeight - overlap
|
||||
val maxScroll = (contentHeight - viewportHeight).coerceAtLeast(1)
|
||||
val clampedScrollY = scrollY.coerceIn(0, maxScroll)
|
||||
val page = Math.round(clampedScrollY.toFloat() / scrollStep)
|
||||
return page.coerceIn(0, pageCount - 1)
|
||||
}
|
||||
nestedScrollView.viewTreeObserver.addOnGlobalLayoutListener {
|
||||
val contentHeight = nestedScrollView.getChildAt(0)?.height ?: 1
|
||||
val viewportHeight = nestedScrollView.height.takeIf { it > 0 } ?: 1
|
||||
val overlap = (viewportHeight * 0.2).toInt()
|
||||
val scrollStep = viewportHeight - overlap
|
||||
val pages =
|
||||
Math.ceil(((contentHeight - viewportHeight).toDouble() / scrollStep.toDouble()))
|
||||
.toInt() + 1
|
||||
pageCount[0] = pages
|
||||
val scrollY = nestedScrollView.scrollY
|
||||
currentPage[0] = getCurrentPageIndex(scrollY, viewportHeight, contentHeight, pages)
|
||||
headerView.setContent {
|
||||
SettingsTheme(isDark) {
|
||||
Column(Modifier.fillMaxWidth()) {
|
||||
SettingsComposable.PageHeader(
|
||||
iconRes = R.drawable.ic_back,
|
||||
title = stringResource(R.string.notification_section),
|
||||
onClick = { findNavController().popBackStack() },
|
||||
showStatusBar = prefs.showStatusBar,
|
||||
pageIndicator = {
|
||||
SettingsComposable.PageIndicator(
|
||||
currentPage = currentPage[0],
|
||||
pageCount = pageCount[0],
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else androidx.compose.ui.unit.TextUnit.Unspecified
|
||||
)
|
||||
},
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else androidx.compose.ui.unit.TextUnit.Unspecified
|
||||
)
|
||||
SettingsComposable.SolidSeparator(isDark = isDark)
|
||||
Spacer(modifier = Modifier.height(SettingsTheme.color.horizontalPadding))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
nestedScrollView.setOnScrollChangeListener { _, _, scrollY, _, _ ->
|
||||
val contentHeight = nestedScrollView.getChildAt(0)?.height ?: 1
|
||||
val viewportHeight = nestedScrollView.height.takeIf { it > 0 } ?: 1
|
||||
val overlap = (viewportHeight * 0.2).toInt()
|
||||
val scrollStep = viewportHeight - overlap
|
||||
val pages =
|
||||
Math.ceil(((contentHeight - viewportHeight).toDouble() / scrollStep.toDouble()))
|
||||
.toInt() + 1
|
||||
pageCount[0] = pages
|
||||
currentPage[0] = getCurrentPageIndex(scrollY, viewportHeight, contentHeight, pages)
|
||||
headerView.setContent {
|
||||
SettingsTheme(isDark) {
|
||||
Column(Modifier.fillMaxWidth()) {
|
||||
SettingsComposable.PageHeader(
|
||||
iconRes = R.drawable.ic_back,
|
||||
title = stringResource(R.string.notification_section),
|
||||
onClick = { findNavController().popBackStack() },
|
||||
showStatusBar = prefs.showStatusBar,
|
||||
pageIndicator = {
|
||||
SettingsComposable.PageIndicator(
|
||||
currentPage = currentPage[0],
|
||||
pageCount = pageCount[0],
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else androidx.compose.ui.unit.TextUnit.Unspecified
|
||||
)
|
||||
},
|
||||
titleFontSize = if (settingsSize > 0) (settingsSize * 1.5).sp else androidx.compose.ui.unit.TextUnit.Unspecified
|
||||
)
|
||||
SettingsComposable.SolidSeparator(isDark = isDark)
|
||||
Spacer(modifier = Modifier.height(SettingsTheme.color.horizontalPadding))
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rootLayout
|
||||
}
|
||||
|
||||
@Deprecated("Deprecated in Java")
|
||||
@Suppress("DEPRECATION")
|
||||
override fun onActivityResult(
|
||||
requestCode: Int,
|
||||
resultCode: Int,
|
||||
data: android.content.Intent?
|
||||
) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (requestCode == 1002 && resultCode == android.app.Activity.RESULT_OK) {
|
||||
data?.data?.let { uri ->
|
||||
val fileName = getFileName(uri) ?: "custom_font.ttf"
|
||||
val file = java.io.File(requireContext().filesDir, fileName)
|
||||
try {
|
||||
val inputStream: java.io.InputStream? =
|
||||
requireContext().contentResolver.openInputStream(uri)
|
||||
val outputStream = java.io.FileOutputStream(file)
|
||||
inputStream?.copyTo(outputStream)
|
||||
inputStream?.close()
|
||||
outputStream.close()
|
||||
// Save path and call callback
|
||||
val prefs = Prefs(requireContext())
|
||||
prefs.customFontPath = file.absolutePath
|
||||
// Add to custom font set
|
||||
prefs.addCustomFontPath(file.absolutePath)
|
||||
onCustomFontSelected?.invoke(com.github.gezimos.inkos.data.Constants.FontFamily.Custom)
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getFileName(uri: android.net.Uri): String? {
|
||||
var name: String? = null
|
||||
val cursor = requireContext().contentResolver.query(uri, null, null, null, null)
|
||||
cursor?.use {
|
||||
if (it.moveToFirst()) {
|
||||
val index = it.getColumnIndex(android.provider.OpenableColumns.DISPLAY_NAME)
|
||||
if (index >= 0) name = it.getString(index)
|
||||
}
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
// Helper to display a short, user-friendly font name for custom fonts
|
||||
@Suppress("unused")
|
||||
private fun getShortFontDisplayName(fontPath: String?, maxLen: Int = 24): String {
|
||||
if (fontPath.isNullOrBlank()) return "Custom Font"
|
||||
val fileName = fontPath.substringAfterLast('/')
|
||||
return if (fileName.length > maxLen) {
|
||||
fileName.take(maxLen - 3) + "..."
|
||||
} else fileName
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun NotificationSettingsAllInOne(fontSize: androidx.compose.ui.unit.TextUnit = androidx.compose.ui.unit.TextUnit.Unspecified) {
|
||||
val context = requireContext()
|
||||
val isDark = isSystemInDarkMode(context)
|
||||
val titleFontSize =
|
||||
if (fontSize != androidx.compose.ui.unit.TextUnit.Unspecified) (fontSize.value * 1.5).sp else fontSize
|
||||
val prefs = remember { Prefs(context) }
|
||||
var pushNotificationsEnabled by remember { mutableStateOf(prefs.pushNotificationsEnabled) }
|
||||
|
||||
// Observe pushNotificationsEnabledFlow for real-time updates
|
||||
val lifecycleOwner = androidx.lifecycle.compose.LocalLifecycleOwner.current
|
||||
LaunchedEffect(prefs) {
|
||||
lifecycleOwner.lifecycleScope.launch {
|
||||
prefs.pushNotificationsEnabledFlow.collectLatest { enabled ->
|
||||
pushNotificationsEnabled = enabled
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Compose state for all notification switches ---
|
||||
var showNotificationBadge by rememberSaveable { mutableStateOf(prefs.showNotificationBadge) }
|
||||
var showNotificationText by rememberSaveable { mutableStateOf(prefs.showNotificationText) }
|
||||
var showMediaIndicator by rememberSaveable { mutableStateOf(prefs.showMediaIndicator) }
|
||||
var showMediaName by rememberSaveable { mutableStateOf(prefs.showMediaName) }
|
||||
var showSenderName by rememberSaveable { mutableStateOf(prefs.showNotificationSenderName) }
|
||||
var showGroupName by rememberSaveable { mutableStateOf(prefs.showNotificationGroupName) }
|
||||
var showMessage by rememberSaveable { mutableStateOf(prefs.showNotificationMessage) }
|
||||
var notificationsEnabled by rememberSaveable { mutableStateOf(prefs.notificationsEnabled) }
|
||||
var charLimit by rememberSaveable { mutableStateOf(prefs.homeAppCharLimit) }
|
||||
|
||||
// --- Add state for allowlists to trigger recomposition ---
|
||||
var badgeAllowlist by remember { mutableStateOf(prefs.allowedBadgeNotificationApps.toSet()) }
|
||||
var allowlist by remember { mutableStateOf(prefs.allowedNotificationApps.toSet()) }
|
||||
|
||||
// When toggling master switch, update all states
|
||||
fun onPushNotificationsToggle(newValue: Boolean) {
|
||||
// Always launch Notification Listener Settings when toggling
|
||||
val intent =
|
||||
android.content.Intent(android.provider.Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)
|
||||
try {
|
||||
context.startActivity(intent)
|
||||
} catch (_: Exception) {
|
||||
// fallback: open app details if notification listener settings not available
|
||||
val fallbackIntent =
|
||||
android.content.Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
||||
.apply {
|
||||
data = android.net.Uri.fromParts("package", context.packageName, null)
|
||||
}
|
||||
context.startActivity(fallbackIntent)
|
||||
}
|
||||
if (!newValue) {
|
||||
prefs.saveNotificationSwitchesState()
|
||||
prefs.disableAllNotificationSwitches()
|
||||
showNotificationBadge = false
|
||||
showNotificationText = false
|
||||
showMediaIndicator = false
|
||||
showMediaName = false
|
||||
showSenderName = false
|
||||
showGroupName = false
|
||||
showMessage = false
|
||||
notificationsEnabled = false
|
||||
} else {
|
||||
prefs.restoreNotificationSwitchesState()
|
||||
showNotificationBadge = prefs.showNotificationBadge
|
||||
showNotificationText = prefs.showNotificationText
|
||||
showMediaIndicator = prefs.showMediaIndicator
|
||||
showMediaName = prefs.showMediaName
|
||||
showSenderName = prefs.showNotificationSenderName
|
||||
showGroupName = prefs.showNotificationGroupName
|
||||
showMessage = prefs.showNotificationMessage
|
||||
notificationsEnabled = prefs.notificationsEnabled
|
||||
}
|
||||
prefs.pushNotificationsEnabled = newValue
|
||||
pushNotificationsEnabled = newValue
|
||||
}
|
||||
|
||||
Column(modifier = Modifier.fillMaxWidth()) {
|
||||
SettingsComposable.FullLineSeparator(isDark = isDark)
|
||||
// Push Notifications master switch
|
||||
SettingsComposable.SettingsSwitch(
|
||||
text = stringResource(R.string.push_notifications),
|
||||
fontSize = titleFontSize,
|
||||
defaultState = pushNotificationsEnabled,
|
||||
onCheckedChange = { onPushNotificationsToggle(!pushNotificationsEnabled) }
|
||||
)
|
||||
SettingsComposable.FullLineSeparator(isDark = isDark)
|
||||
SettingsComposable.SettingsTitle(
|
||||
text = stringResource(R.string.notification_home),
|
||||
fontSize = titleFontSize
|
||||
)
|
||||
SettingsComposable.FullLineSeparator(isDark = isDark)
|
||||
// Notification Badge
|
||||
SettingsComposable.SettingsSwitch(
|
||||
text = stringResource(R.string.show_notification_badge),
|
||||
fontSize = titleFontSize,
|
||||
defaultState = showNotificationBadge,
|
||||
enabled = pushNotificationsEnabled,
|
||||
onCheckedChange = {
|
||||
showNotificationBadge = !showNotificationBadge
|
||||
prefs.showNotificationBadge = showNotificationBadge
|
||||
}
|
||||
)
|
||||
SettingsComposable.DashedSeparator(isDark = isDark)
|
||||
// Notification Text
|
||||
SettingsComposable.SettingsSwitch(
|
||||
text = stringResource(R.string.show_notification_text),
|
||||
fontSize = titleFontSize,
|
||||
defaultState = showNotificationText,
|
||||
enabled = pushNotificationsEnabled,
|
||||
onCheckedChange = {
|
||||
showNotificationText = !showNotificationText
|
||||
prefs.showNotificationText = showNotificationText
|
||||
}
|
||||
)
|
||||
SettingsComposable.DashedSeparator(isDark = isDark)
|
||||
// Media Playing Indicator
|
||||
SettingsComposable.SettingsSwitch(
|
||||
text = stringResource(R.string.show_media_playing_indicator),
|
||||
fontSize = titleFontSize,
|
||||
defaultState = showMediaIndicator,
|
||||
enabled = pushNotificationsEnabled,
|
||||
onCheckedChange = {
|
||||
showMediaIndicator = !showMediaIndicator
|
||||
prefs.showMediaIndicator = showMediaIndicator
|
||||
}
|
||||
)
|
||||
SettingsComposable.DashedSeparator(isDark = isDark)
|
||||
// Media Playing Name
|
||||
SettingsComposable.SettingsSwitch(
|
||||
text = stringResource(R.string.show_media_playing_name),
|
||||
fontSize = titleFontSize,
|
||||
defaultState = showMediaName,
|
||||
enabled = pushNotificationsEnabled,
|
||||
onCheckedChange = {
|
||||
showMediaName = !showMediaName
|
||||
prefs.showMediaName = showMediaName
|
||||
}
|
||||
)
|
||||
SettingsComposable.DashedSeparator(isDark = isDark)
|
||||
val badgeAllowlistState = badgeAllowlist // for recomposition
|
||||
var showBadgeDialog by remember { mutableStateOf(false) }
|
||||
SettingsComposable.SettingsSelect(
|
||||
title = stringResource(R.string.home_notifications_allowlist),
|
||||
option = badgeAllowlistState.size.toString(),
|
||||
fontSize = titleFontSize,
|
||||
onClick = { showBadgeDialog = true },
|
||||
enabled = pushNotificationsEnabled
|
||||
)
|
||||
if (showBadgeDialog) {
|
||||
LaunchedEffect(Unit) {
|
||||
showBadgeDialog = false
|
||||
showAppAllowlistDialog(
|
||||
title = "Label Notification Apps",
|
||||
initialSelected = badgeAllowlistState,
|
||||
onConfirm = { selected ->
|
||||
prefs.allowedBadgeNotificationApps = selected.toMutableSet()
|
||||
badgeAllowlist = selected.toMutableSet() // update state to refresh UI
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
SettingsComposable.FullLineSeparator(isDark = isDark)
|
||||
// Chat section
|
||||
SettingsComposable.SettingsTitle(
|
||||
text = stringResource(R.string.chat_notifications_section),
|
||||
fontSize = titleFontSize
|
||||
)
|
||||
SettingsComposable.FullLineSeparator(isDark = isDark)
|
||||
SettingsComposable.SettingsSwitch(
|
||||
text = stringResource(R.string.show_sender_name),
|
||||
fontSize = titleFontSize,
|
||||
defaultState = showSenderName,
|
||||
onCheckedChange = {
|
||||
showSenderName = !showSenderName
|
||||
prefs.showNotificationSenderName = showSenderName
|
||||
},
|
||||
enabled = pushNotificationsEnabled
|
||||
)
|
||||
SettingsComposable.DashedSeparator(isDark = isDark)
|
||||
SettingsComposable.SettingsSwitch(
|
||||
text = stringResource(R.string.show_conversation_group_name),
|
||||
fontSize = titleFontSize,
|
||||
defaultState = showGroupName,
|
||||
onCheckedChange = {
|
||||
showGroupName = !showGroupName
|
||||
prefs.showNotificationGroupName = showGroupName
|
||||
},
|
||||
enabled = pushNotificationsEnabled
|
||||
)
|
||||
SettingsComposable.DashedSeparator(isDark = isDark)
|
||||
SettingsComposable.SettingsSwitch(
|
||||
text = stringResource(R.string.show_message),
|
||||
fontSize = titleFontSize,
|
||||
defaultState = showMessage,
|
||||
onCheckedChange = {
|
||||
showMessage = !showMessage
|
||||
prefs.showNotificationMessage = showMessage
|
||||
},
|
||||
enabled = pushNotificationsEnabled
|
||||
)
|
||||
SettingsComposable.DashedSeparator(isDark = isDark)
|
||||
SettingsComposable.SettingsSelect(
|
||||
title = stringResource(R.string.badge_character_limit),
|
||||
option = charLimit.toString(),
|
||||
fontSize = titleFontSize,
|
||||
onClick = {
|
||||
DialogManager(requireContext(), requireActivity()).showSliderDialog(
|
||||
context = requireContext(),
|
||||
title = getString(R.string.badge_character_limit),
|
||||
minValue = 5,
|
||||
maxValue = 50,
|
||||
currentValue = charLimit,
|
||||
onValueSelected = { newValue ->
|
||||
prefs.homeAppCharLimit = newValue
|
||||
charLimit = newValue
|
||||
}
|
||||
)
|
||||
},
|
||||
enabled = pushNotificationsEnabled
|
||||
)
|
||||
SettingsComposable.FullLineSeparator(isDark = isDark)
|
||||
// Filter section
|
||||
SettingsComposable.SettingsTitle(
|
||||
text = stringResource(R.string.notifications_window_title),
|
||||
fontSize = titleFontSize
|
||||
)
|
||||
SettingsComposable.FullLineSeparator(isDark = isDark)
|
||||
var notificationsEnabled by remember { mutableStateOf(prefs.notificationsEnabled) }
|
||||
val allowlistState = allowlist // for recomposition
|
||||
var showAllowlistDialog by remember { mutableStateOf(false) }
|
||||
SettingsComposable.SettingsSwitch(
|
||||
text = stringResource(R.string.enable_notifications),
|
||||
fontSize = titleFontSize,
|
||||
defaultState = notificationsEnabled,
|
||||
onCheckedChange = {
|
||||
notificationsEnabled = !notificationsEnabled
|
||||
prefs.notificationsEnabled = notificationsEnabled
|
||||
},
|
||||
enabled = pushNotificationsEnabled
|
||||
)
|
||||
SettingsComposable.DashedSeparator(isDark = isDark)
|
||||
SettingsComposable.SettingsSelect(
|
||||
title = "Notification Allowlist",
|
||||
option = allowlistState.size.toString(),
|
||||
fontSize = titleFontSize,
|
||||
onClick = { showAllowlistDialog = true },
|
||||
enabled = pushNotificationsEnabled
|
||||
)
|
||||
if (showAllowlistDialog) {
|
||||
LaunchedEffect(Unit) {
|
||||
showAllowlistDialog = false
|
||||
showAppAllowlistDialog(
|
||||
title = "Notification Window Apps",
|
||||
initialSelected = allowlistState,
|
||||
onConfirm = { selected ->
|
||||
prefs.allowedNotificationApps = selected.toMutableSet()
|
||||
allowlist = selected.toMutableSet() // update state to refresh UI
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
SettingsComposable.FullLineSeparator(isDark = isDark)
|
||||
}
|
||||
}
|
||||
|
||||
// Font selection dialog helper (copied from FontsFragment, but simplified for notification fonts)
|
||||
@Suppress("unused")
|
||||
private fun showFontSelectionDialogWithCustoms(
|
||||
titleResId: Int,
|
||||
onFontSelected: (com.github.gezimos.inkos.data.Constants.FontFamily, String?) -> Unit
|
||||
) {
|
||||
val fontFamilyEntries =
|
||||
com.github.gezimos.inkos.data.Constants.FontFamily.entries
|
||||
.filter { it != com.github.gezimos.inkos.data.Constants.FontFamily.Custom }
|
||||
val context = requireContext()
|
||||
val prefs = Prefs(context)
|
||||
|
||||
val builtInFontOptions = fontFamilyEntries.map { it.getString(context) }
|
||||
val builtInFonts = fontFamilyEntries.map {
|
||||
it.getFont(context) ?: com.github.gezimos.inkos.helper.getTrueSystemFont()
|
||||
}
|
||||
|
||||
val customFonts =
|
||||
com.github.gezimos.inkos.data.Constants.FontFamily.getAllCustomFonts(
|
||||
context
|
||||
)
|
||||
val customFontOptions = customFonts.map { it.first }
|
||||
val customFontPaths = customFonts.map { it.second }
|
||||
val customFontTypefaces = customFontPaths.map { path ->
|
||||
com.github.gezimos.inkos.data.Constants.FontFamily.Custom.getFont(
|
||||
context,
|
||||
path
|
||||
) ?: com.github.gezimos.inkos.helper.getTrueSystemFont()
|
||||
}
|
||||
|
||||
val addCustomFontOption = "Add Custom Font..."
|
||||
|
||||
val options = builtInFontOptions + customFontOptions + addCustomFontOption
|
||||
val fonts =
|
||||
builtInFonts + customFontTypefaces + com.github.gezimos.inkos.helper.getTrueSystemFont()
|
||||
|
||||
dialogManager.showSingleChoiceDialog(
|
||||
context = context,
|
||||
options = options.toTypedArray(),
|
||||
fonts = fonts,
|
||||
titleResId = titleResId,
|
||||
onItemSelected = { selectedName ->
|
||||
when (selectedName) {
|
||||
addCustomFontOption -> {
|
||||
pickCustomFontFile { _, path ->
|
||||
prefs.setCustomFontPath("custom", path)
|
||||
prefs.addCustomFontPath(path)
|
||||
onFontSelected(
|
||||
com.github.gezimos.inkos.data.Constants.FontFamily.Custom,
|
||||
path
|
||||
)
|
||||
activity?.recreate()
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
val builtInIndex = builtInFontOptions.indexOf(selectedName)
|
||||
if (builtInIndex != -1) {
|
||||
onFontSelected(fontFamilyEntries[builtInIndex], null)
|
||||
return@showSingleChoiceDialog
|
||||
}
|
||||
val customIndex = customFontOptions.indexOf(selectedName)
|
||||
if (customIndex != -1) {
|
||||
val path = customFontPaths[customIndex]
|
||||
onFontSelected(
|
||||
com.github.gezimos.inkos.data.Constants.FontFamily.Custom,
|
||||
path
|
||||
)
|
||||
return@showSingleChoiceDialog
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// Font file picker for custom fonts (copied from FontsFragment, but only path is needed)
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
private fun pickCustomFontFile(onFontPicked: (android.graphics.Typeface, String) -> Unit) {
|
||||
onCustomFontSelected = { _ ->
|
||||
// Not used here, but required for interface
|
||||
}
|
||||
val intent = android.content.Intent(android.content.Intent.ACTION_OPEN_DOCUMENT).apply {
|
||||
addCategory(android.content.Intent.CATEGORY_OPENABLE)
|
||||
type = "font/*"
|
||||
putExtra(
|
||||
android.content.Intent.EXTRA_MIME_TYPES,
|
||||
arrayOf(
|
||||
"font/ttf",
|
||||
"font/otf",
|
||||
"application/x-font-ttf",
|
||||
"application/x-font-opentype",
|
||||
"application/octet-stream"
|
||||
)
|
||||
)
|
||||
}
|
||||
startActivityForResult(intent, 1002)
|
||||
}
|
||||
|
||||
// Helper to show app allowlist dialog using DialogManager (imperative, not Compose)
|
||||
private fun showAppAllowlistDialog(
|
||||
title: String,
|
||||
initialSelected: Set<String>,
|
||||
onConfirm: (Set<String>) -> Unit,
|
||||
includeHidden: Boolean = true // Add this param to control hidden apps
|
||||
) {
|
||||
// Use MainViewModel's appList instead of getInstalledApps
|
||||
val activity = requireActivity()
|
||||
val viewModel =
|
||||
androidx.lifecycle.ViewModelProvider(activity)[com.github.gezimos.inkos.MainViewModel::class.java]
|
||||
viewModel.getAppList(includeHiddenApps = includeHidden)
|
||||
val appListLiveData = viewModel.appList
|
||||
// Observe once and show dialog when data is available
|
||||
appListLiveData.observe(viewLifecycleOwner) { appListItems ->
|
||||
if (appListItems == null) return@observe
|
||||
// Map AppListItem to AppInfo
|
||||
val allApps = appListItems.map {
|
||||
AppInfo(label = it.customLabel.takeIf { l -> !l.isNullOrEmpty() }
|
||||
?: it.activityLabel, packageName = it.activityPackage)
|
||||
}
|
||||
// Sort: selected apps first, then unselected, both alphabetically
|
||||
val sortedApps = allApps.sortedWith(
|
||||
compareByDescending<AppInfo> { initialSelected.contains(it.packageName) }
|
||||
.thenBy { it.label.lowercase() }
|
||||
)
|
||||
val appLabels = sortedApps.map { it.label }
|
||||
val appPackages = sortedApps.map { it.packageName }
|
||||
val checkedItems = appPackages.map { initialSelected.contains(it) }.toBooleanArray()
|
||||
|
||||
dialogManager.showMultiChoiceDialog(
|
||||
context = requireContext(),
|
||||
title = title,
|
||||
items = appLabels.toTypedArray(),
|
||||
initialChecked = checkedItems,
|
||||
onConfirm = { selectedIndices ->
|
||||
val selectedPkgs = selectedIndices.map { appPackages[it] }.toSet()
|
||||
onConfirm(selectedPkgs)
|
||||
}
|
||||
)
|
||||
// Remove observer after first use
|
||||
appListLiveData.removeObservers(viewLifecycleOwner)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
}
|
||||
}
|
||||
BIN
app/src/main/play_store.png
Normal file
BIN
app/src/main/play_store.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
BIN
app/src/main/play_store_features.png
Normal file
BIN
app/src/main/play_store_features.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 176 KiB |
23
app/src/main/res/anim/item_anim_from_bottom.xml
Normal file
23
app/src/main/res/anim/item_anim_from_bottom.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:duration="200">
|
||||
|
||||
<translate
|
||||
android:fromYDelta="20%"
|
||||
android:interpolator="@android:anim/decelerate_interpolator"
|
||||
android:toYDelta="0" />
|
||||
|
||||
<alpha
|
||||
android:fromAlpha="0"
|
||||
android:interpolator="@android:anim/decelerate_interpolator"
|
||||
android:toAlpha="1" />
|
||||
|
||||
<scale
|
||||
android:fromXScale="100%"
|
||||
android:fromYScale="110%"
|
||||
android:interpolator="@android:anim/decelerate_interpolator"
|
||||
android:pivotX="50%"
|
||||
android:pivotY="50%"
|
||||
android:toXScale="100%"
|
||||
android:toYScale="100%" />
|
||||
|
||||
</set>
|
||||
5
app/src/main/res/anim/layout_anim_from_bottom.xml
Normal file
5
app/src/main/res/anim/layout_anim_from_bottom.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:animation="@anim/item_anim_from_bottom"
|
||||
android:animationOrder="normal"
|
||||
android:delay="6%" />
|
||||
15
app/src/main/res/drawable/app_launcher.xml
Normal file
15
app/src/main/res/drawable/app_launcher.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="64dp"
|
||||
android:height="64dp"
|
||||
android:viewportWidth="1024"
|
||||
android:viewportHeight="1024">
|
||||
<path
|
||||
android:pathData="M802,80H222c-37.9,0 -73.6,14.8 -100.4,41.6 -26.8,26.8 -41.6,62.5 -41.6,100.4v580c0,37.9 14.8,73.6 41.6,100.4 26.8,26.8 62.5,41.6 100.4,41.6h580c37.9,0 73.6,-14.8 100.4,-41.6 26.8,-26.8 41.6,-62.5 41.6,-100.4V222c0,-37.9 -14.8,-73.6 -41.6,-100.4 -26.8,-26.8 -62.5,-41.6 -100.4,-41.6Z"
|
||||
android:fillColor="#fff"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M802,0H222C99.4,0 0,99.4 0,222v580c0,122.6 99.4,222 222,222h580c122.6,0 222,-99.4 222,-222V222c0,-122.6 -99.4,-222 -222,-222ZM944,802c0,37.9 -14.8,73.6 -41.6,100.4 -26.8,26.8 -62.5,41.6 -100.4,41.6H222c-37.9,0 -73.6,-14.8 -100.4,-41.6 -26.8,-26.8 -41.6,-62.5 -41.6,-100.4V222c0,-37.9 14.8,-73.6 41.6,-100.4 26.8,-26.8 62.5,-41.6 100.4,-41.6h580c37.9,0 73.6,14.8 100.4,41.6 26.8,26.8 41.6,62.5 41.6,100.4v580Z"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M737.3,514.8c-25.3,-61 -62,-121.7 -98,-176.9 -39.3,-60.3 -81.7,-118.7 -126.2,-175.2l-1.1,-1.3 -1.1,1.3c-44.5,56.6 -86.8,114.9 -126.2,175.2 -36,55.2 -72.7,115.9 -98,176.9 -26.7,64.4 -34.4,115.8 -9.9,183.2 38.1,104.8 135.2,164.6 235.2,164.8 99.9,-0.1 197.1,-60 235.2,-164.8 24.5,-67.4 16.8,-118.8 -9.9,-183.2Z"/>
|
||||
</vector>
|
||||
20
app/src/main/res/drawable/fab_background.xml
Normal file
20
app/src/main/res/drawable/fab_background.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- Border -->
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<stroke
|
||||
android:width="8dp"
|
||||
android:color="@color/fab_background" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<!-- ImageView Background -->
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:color="@color/fab_border" />
|
||||
</shape>
|
||||
</item>
|
||||
</layer-list>
|
||||
10
app/src/main/res/drawable/ic_back.xml
Normal file
10
app/src/main/res/drawable/ic_back.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:autoMirrored="true"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="?attr/primaryColor"
|
||||
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z" />
|
||||
</vector>
|
||||
11
app/src/main/res/drawable/ic_chevron_right.xml
Normal file
11
app/src/main/res/drawable/ic_chevron_right.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="64"
|
||||
android:viewportHeight="64">
|
||||
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M21.21,4.76l26.18,26.18c0.59,0.59 0.59,1.54 0,2.12l-26.18,26.18c-0.59,0.59 -1.54,0.59 -2.12,0l-2.48,-2.47c-0.59,-0.59 -0.59,-1.54 0,-2.12l22.59,-22.64L16.61,9.36c-0.59,-0.59 -0.59,-1.54 0,-2.12l2.48,-2.47c0.58,-0.59 1.54,-0.59 2.12,0Z" />
|
||||
|
||||
</vector>
|
||||
9
app/src/main/res/drawable/ic_close.xml
Normal file
9
app/src/main/res/drawable/ic_close.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="?attr/primaryColor"
|
||||
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z" />
|
||||
</vector>
|
||||
9
app/src/main/res/drawable/ic_current_page.xml
Normal file
9
app/src/main/res/drawable/ic_current_page.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="18dp"
|
||||
android:height="18dp"
|
||||
android:viewportWidth="12"
|
||||
android:viewportHeight="12">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M6,1a5,5 0 1,0 0,10a5,5 0 1,0 0,-10z"/>
|
||||
</vector>
|
||||
9
app/src/main/res/drawable/ic_delete.xml
Normal file
9
app/src/main/res/drawable/ic_delete.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="?attr/primaryColor"
|
||||
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2L18,7L6,7v12zM8,9h8v10L8,19L8,9zM15.5,4l-1,-1h-5l-1,1L5,4v2h14L19,4z" />
|
||||
</vector>
|
||||
11
app/src/main/res/drawable/ic_home.xml
Normal file
11
app/src/main/res/drawable/ic_home.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="64dp"
|
||||
android:height="49.77dp"
|
||||
android:viewportWidth="64"
|
||||
android:viewportHeight="49.77">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M64,25.3c0,.43-.16.83-.41,1.14l-1.14,1.37c-.33.39-.82.64-1.36.64-.43,0-.83-.16-1.14-.41l-3.06-2.51v20.73c-.02,1.95-1.6,3.52-3.56,3.53h-14.22c-1.96,0-3.55-1.6-3.56-3.56v-11.56h-7.11v11.56c0,1.96-1.6,3.55-3.56,3.56h-14.22c-1.96,0-3.55-1.6-3.56-3.56v-20.7l-3.05,2.51c-.31.26-.71.41-1.14.41-.55,0-1.04-.25-1.36-.64l-1.14-1.37c-.26-.31-.41-.71-.41-1.14,0-.55.25-1.04.64-1.36L28.01,1.44c1.08-.9,2.48-1.44,3.99-1.44s2.9.54,3.98,1.44l15.58,12.79v-6.25c0-.48.4-.87.88-.88h3.56c.49,0,.89.4.89.89v10.61l6.47,5.32c.39.33.64.82.64,1.37ZM51.55,21.13L32,5.07,12.44,21.14v23.3h10.67v-11.56c0-1.96,1.6-3.55,3.56-3.56h10.67c1.96,0,3.55,1.6,3.56,3.56v11.56h10.65l.02-23.31Z" />
|
||||
</vector>
|
||||
|
||||
9
app/src/main/res/drawable/ic_info.xml
Normal file
9
app/src/main/res/drawable/ic_info.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="?attr/primaryColor"
|
||||
android:pathData="M11,7h2v2h-2zM11,11h2v6h-2zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z" />
|
||||
</vector>
|
||||
9
app/src/main/res/drawable/ic_ink.xml
Normal file
9
app/src/main/res/drawable/ic_ink.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="500dp"
|
||||
android:height="701.41dp"
|
||||
android:viewportWidth="500"
|
||||
android:viewportHeight="701.41">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M475.27,353.47c-25.3,-60.97 -61.98,-121.69 -98.02,-176.92C337.91,116.27 295.56,57.9 251.08,1.34l-1.08,-1.34 -1.08,1.34c-44.47,56.56 -86.82,114.93 -126.17,175.21 -36.04,55.23 -72.72,115.95 -98.02,176.92 -26.72,64.4 -34.43,115.79 -9.91,183.16 38.12,104.76 135.24,164.65 235.18,164.78 99.94,-0.13 197.07,-60.02 235.18,-164.78 24.51,-67.37 16.81,-118.76 -9.91,-183.16Z"/>
|
||||
</vector>
|
||||
11
app/src/main/res/drawable/ic_new_page.xml
Normal file
11
app/src/main/res/drawable/ic_new_page.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="18dp"
|
||||
android:height="18dp"
|
||||
android:viewportWidth="12"
|
||||
android:viewportHeight="12">
|
||||
<path
|
||||
android:fillColor="@android:color/transparent"
|
||||
android:strokeColor="#000000"
|
||||
android:strokeWidth="2"
|
||||
android:pathData="M6,6m-4.5,0a4.5,4.5 0 1,0 9,0a4.5,4.5 0 1,0 -9,0"/>
|
||||
</vector>
|
||||
13
app/src/main/res/drawable/ic_order_apps.xml
Normal file
13
app/src/main/res/drawable/ic_order_apps.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M5,10H19M14,19L12,21L10,19M14,5L12,3L10,5M5,14H19"
|
||||
android:strokeWidth="1.5"
|
||||
android:strokeColor="?attr/primaryColor"
|
||||
android:strokeLineCap="square"
|
||||
android:strokeLineJoin="miter" />
|
||||
</vector>
|
||||
9
app/src/main/res/drawable/ic_rename.xml
Normal file
9
app/src/main/res/drawable/ic_rename.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="?attr/primaryColor"
|
||||
android:pathData="M18.41,5.8L17.2,4.59c-0.78,-0.78 -2.05,-0.78 -2.83,0l-2.68,2.68L3,15.96V20h4.04l8.74,-8.74 2.63,-2.63c0.79,-0.78 0.79,-2.05 0,-2.83zM6.21,18H5v-1.21l8.66,-8.66 1.21,1.21L6.21,18zM11,20l4,-4h6v4H11z" />
|
||||
</vector>
|
||||
21
app/src/main/res/drawable/ic_unlock.xml
Normal file
21
app/src/main/res/drawable/ic_unlock.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="?attr/primaryColor"
|
||||
android:pathData="m6.1,11.4v7.9c0,1.3 1,2.4 2.3,2.4h7.2c1.3,0 2.3,-1.1 2.3,-2.4v-7.9zM12,18.1c-1,0 -1.9,-0.9 -1.9,-1.9 0,-1.1 0.9,-1.9 1.9,-1.9 1.1,0 1.9,0.8 1.9,1.9 0,1 -0.8,1.9 -1.9,1.9z" />
|
||||
<path
|
||||
android:fillColor="?attr/primaryColor"
|
||||
android:pathData="m15.6,22.2h-7.2c-1.6,0 -2.9,-1.3 -2.9,-2.9v-7.9c0,-0.3 0.3,-0.5 0.6,-0.5h11.8c0.3,0 0.6,0.2 0.6,0.5v7.9c0,1.6 -1.3,2.9 -2.9,2.9zM6.7,12v7.3c0,1 0.8,1.8 1.7,1.8h7.2c0.9,0 1.7,-0.8 1.7,-1.8v-7.3zM12.1,18.6c-1.4,0 -2.5,-1.1 -2.5,-2.4 0,-1.4 1.1,-2.5 2.5,-2.5 1.3,0 2.5,1.1 2.5,2.5 0,1.3 -1.2,2.4 -2.5,2.4zM12.1,14.8c-0.8,0 -1.4,0.6 -1.4,1.4 0,0.7 0.6,1.3 1.4,1.3 0.7,0 1.3,-0.6 1.3,-1.3 0,-0.8 -0.6,-1.4 -1.3,-1.4z" />
|
||||
<path
|
||||
android:fillColor="?attr/primaryColor"
|
||||
android:pathData="m7.3,12c-0.3,0 -0.5,-0.3 -0.5,-0.6v-4.7c0,-2.7 2.2,-4.9 4.9,-4.9h0.6c2.7,0 4.9,2.2 4.9,4.9 0,0.3 -0.2,0.6 -0.5,0.6 -0.3,0 -0.6,-0.3 -0.6,-0.6 0,-2.1 -1.7,-3.8 -3.8,-3.8h-0.6c-2.1,0 -3.8,1.7 -3.8,3.8v4.7c0,0.3 -0.3,0.6 -0.6,0.6z" />
|
||||
<path
|
||||
android:fillColor="?attr/primaryColor"
|
||||
android:pathData="m8.3,11.1h-2c-0.3,0 -0.5,-0.2 -0.5,-0.5 0,-0.3 0.2,-0.6 0.5,-0.6h2c0.3,0 0.5,0.3 0.5,0.6 0,0.3 -0.2,0.5 -0.5,0.5z" />
|
||||
<path
|
||||
android:fillColor="?attr/primaryColor"
|
||||
android:pathData="m17.7,11.1h-2c-0.3,0 -0.5,-0.2 -0.5,-0.5 0,-0.3 0.2,-0.6 0.5,-0.6h2c0.3,0 0.5,0.3 0.5,0.6 0,0.3 -0.2,0.5 -0.5,0.5z" />
|
||||
</vector>
|
||||
21
app/src/main/res/drawable/padlock.xml
Normal file
21
app/src/main/res/drawable/padlock.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="?attr/primaryColor"
|
||||
android:pathData="m6.1,11.4v7.9c0,1.3 1,2.4 2.3,2.4h7.2c1.3,0 2.3,-1.1 2.3,-2.4v-7.9zM12,18.1c-1,0 -1.9,-0.9 -1.9,-1.9 0,-1.1 0.9,-1.9 1.9,-1.9 1.1,0 1.9,0.8 1.9,1.9 0,1 -0.8,1.9 -1.9,1.9z" />
|
||||
<path
|
||||
android:fillColor="?attr/primaryColor"
|
||||
android:pathData="m15.6,22.2h-7.2c-1.6,0 -2.9,-1.3 -2.9,-2.9v-7.9c0,-0.3 0.3,-0.5 0.6,-0.5h11.8c0.3,0 0.6,0.2 0.6,0.5v7.9c0,1.6 -1.3,2.9 -2.9,2.9zM6.7,12v7.3c0,1 0.8,1.8 1.7,1.8h7.2c0.9,0 1.7,-0.8 1.7,-1.8v-7.3zM12.1,18.6c-1.4,0 -2.5,-1.1 -2.5,-2.4 0,-1.4 1.1,-2.5 2.5,-2.5 1.3,0 2.5,1.1 2.5,2.5 0,1.3 -1.2,2.4 -2.5,2.4zM12.1,14.8c-0.8,0 -1.4,0.6 -1.4,1.4 0,0.7 0.6,1.3 1.4,1.3 0.7,0 1.3,-0.6 1.3,-1.3 0,-0.8 -0.6,-1.4 -1.3,-1.4z" />
|
||||
<path
|
||||
android:fillColor="?attr/primaryColor"
|
||||
android:pathData="m8.3,11.1h-2c-0.3,0 -0.5,-0.2 -0.5,-0.5 0,-0.3 0.2,-0.6 0.5,-0.6h2c0.3,0 0.5,0.3 0.5,0.6 0,0.3 -0.2,0.5 -0.5,0.5z" />
|
||||
<path
|
||||
android:fillColor="?attr/primaryColor"
|
||||
android:pathData="m17.7,11.1h-2c-0.3,0 -0.5,-0.2 -0.5,-0.5 0,-0.3 0.2,-0.6 0.5,-0.6h2c0.3,0 0.5,0.3 0.5,0.6 0,0.3 -0.2,0.5 -0.5,0.5z" />
|
||||
<path
|
||||
android:fillColor="?attr/primaryColor"
|
||||
android:pathData="m7.3,12c-0.3,0 -0.5,-0.3 -0.5,-0.6v-4.7c0,-2.7 2.2,-4.9 4.9,-4.9h0.6c2.7,0 4.9,2.2 4.9,4.9v4.1c0,0.3 -0.2,0.5 -0.5,0.5 -0.3,0 -0.6,-0.2 -0.6,-0.5v-4.1c0,-2.1 -1.7,-3.8 -3.8,-3.8h-0.6c-2.1,0 -3.8,1.7 -3.8,3.8v4.7c0,0.3 -0.3,0.6 -0.6,0.6z" />
|
||||
</vector>
|
||||
21
app/src/main/res/drawable/padlock_off.xml
Normal file
21
app/src/main/res/drawable/padlock_off.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="?attr/primaryColor"
|
||||
android:pathData="m6.1,11.4v7.9c0,1.3 1,2.4 2.3,2.4h7.2c1.3,0 2.3,-1.1 2.3,-2.4v-7.9zM12,18.1c-1,0 -1.9,-0.9 -1.9,-1.9 0,-1.1 0.9,-1.9 1.9,-1.9 1.1,0 1.9,0.8 1.9,1.9 0,1 -0.8,1.9 -1.9,1.9z" />
|
||||
<path
|
||||
android:fillColor="?attr/primaryColor"
|
||||
android:pathData="m15.6,22.2h-7.2c-1.6,0 -2.9,-1.3 -2.9,-2.9v-7.9c0,-0.3 0.3,-0.5 0.6,-0.5h11.8c0.3,0 0.6,0.2 0.6,0.5v7.9c0,1.6 -1.3,2.9 -2.9,2.9zM6.7,12v7.3c0,1 0.8,1.8 1.7,1.8h7.2c0.9,0 1.7,-0.8 1.7,-1.8v-7.3zM12.1,18.6c-1.4,0 -2.5,-1.1 -2.5,-2.4 0,-1.4 1.1,-2.5 2.5,-2.5 1.3,0 2.5,1.1 2.5,2.5 0,1.3 -1.2,2.4 -2.5,2.4zM12.1,14.8c-0.8,0 -1.4,0.6 -1.4,1.4 0,0.7 0.6,1.3 1.4,1.3 0.7,0 1.3,-0.6 1.3,-1.3 0,-0.8 -0.6,-1.4 -1.3,-1.4z" />
|
||||
<path
|
||||
android:fillColor="?attr/primaryColor"
|
||||
android:pathData="m7.3,12c-0.3,0 -0.5,-0.3 -0.5,-0.6v-4.7c0,-2.7 2.2,-4.9 4.9,-4.9h0.6c2.7,0 4.9,2.2 4.9,4.9 0,0.3 -0.2,0.6 -0.5,0.6 -0.3,0 -0.6,-0.3 -0.6,-0.6 0,-2.1 -1.7,-3.8 -3.8,-3.8h-0.6c-2.1,0 -3.8,1.7 -3.8,3.8v4.7c0,0.3 -0.3,0.6 -0.6,0.6z" />
|
||||
<path
|
||||
android:fillColor="?attr/primaryColor"
|
||||
android:pathData="m8.3,11.1h-2c-0.3,0 -0.5,-0.2 -0.5,-0.5 0,-0.3 0.2,-0.6 0.5,-0.6h2c0.3,0 0.5,0.3 0.5,0.6 0,0.3 -0.2,0.5 -0.5,0.5z" />
|
||||
<path
|
||||
android:fillColor="?attr/primaryColor"
|
||||
android:pathData="m17.7,11.1h-2c-0.3,0 -0.5,-0.2 -0.5,-0.5 0,-0.3 0.2,-0.6 0.5,-0.6h2c0.3,0 0.5,0.3 0.5,0.6 0,0.3 -0.2,0.5 -0.5,0.5z" />
|
||||
</vector>
|
||||
7
app/src/main/res/drawable/text_colors_default.xml
Normal file
7
app/src/main/res/drawable/text_colors_default.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:color="?attr/primaryColorTrans80" android:state_pressed="true" />
|
||||
<item android:color="?attr/primaryColor" android:state_selected="true" />
|
||||
<item android:color="?attr/primaryColor" android:state_focused="true" />
|
||||
<item android:color="?attr/primaryColor" />
|
||||
</selector>
|
||||
9
app/src/main/res/drawable/visibility.xml
Normal file
9
app/src/main/res/drawable/visibility.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24sp"
|
||||
android:height="24sp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="?attr/primaryColor"
|
||||
android:pathData="M12,16Q13.875,16 15.188,14.688Q16.5,13.375 16.5,11.5Q16.5,9.625 15.188,8.312Q13.875,7 12,7Q10.125,7 8.812,8.312Q7.5,9.625 7.5,11.5Q7.5,13.375 8.812,14.688Q10.125,16 12,16ZM12,14.2Q10.875,14.2 10.088,13.412Q9.3,12.625 9.3,11.5Q9.3,10.375 10.088,9.587Q10.875,8.8 12,8.8Q13.125,8.8 13.913,9.587Q14.7,10.375 14.7,11.5Q14.7,12.625 13.913,13.412Q13.125,14.2 12,14.2ZM12,19Q8.35,19 5.35,16.962Q2.35,14.925 1,11.5Q2.35,8.075 5.35,6.037Q8.35,4 12,4Q15.65,4 18.65,6.037Q21.65,8.075 23,11.5Q21.65,14.925 18.65,16.962Q15.65,19 12,19ZM12,11.5Q12,11.5 12,11.5Q12,11.5 12,11.5Q12,11.5 12,11.5Q12,11.5 12,11.5Q12,11.5 12,11.5Q12,11.5 12,11.5Q12,11.5 12,11.5Q12,11.5 12,11.5ZM12,17Q14.825,17 17.188,15.512Q19.55,14.025 20.8,11.5Q19.55,8.975 17.188,7.487Q14.825,6 12,6Q9.175,6 6.812,7.487Q4.45,8.975 3.2,11.5Q4.45,14.025 6.812,15.512Q9.175,17 12,17Z" />
|
||||
</vector>
|
||||
9
app/src/main/res/drawable/visibility_off.xml
Normal file
9
app/src/main/res/drawable/visibility_off.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24sp"
|
||||
android:height="24sp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="?attr/primaryColor"
|
||||
android:pathData="M16.1,13.3 L14.65,11.85Q14.875,10.675 13.975,9.65Q13.075,8.625 11.65,8.85L10.2,7.4Q10.625,7.2 11.062,7.1Q11.5,7 12,7Q13.875,7 15.188,8.312Q16.5,9.625 16.5,11.5Q16.5,12 16.4,12.438Q16.3,12.875 16.1,13.3ZM19.3,16.45 L17.85,15.05Q18.8,14.325 19.538,13.462Q20.275,12.6 20.8,11.5Q19.55,8.975 17.212,7.487Q14.875,6 12,6Q11.275,6 10.575,6.1Q9.875,6.2 9.2,6.4L7.65,4.85Q8.675,4.425 9.75,4.212Q10.825,4 12,4Q15.775,4 18.725,6.087Q21.675,8.175 23,11.5Q22.425,12.975 21.488,14.238Q20.55,15.5 19.3,16.45ZM19.8,22.6 L15.6,18.45Q14.725,18.725 13.838,18.863Q12.95,19 12,19Q8.225,19 5.275,16.913Q2.325,14.825 1,11.5Q1.525,10.175 2.325,9.037Q3.125,7.9 4.15,7L1.4,4.2L2.8,2.8L21.2,21.2ZM5.55,8.4Q4.825,9.05 4.225,9.825Q3.625,10.6 3.2,11.5Q4.45,14.025 6.787,15.512Q9.125,17 12,17Q12.5,17 12.975,16.938Q13.45,16.875 13.95,16.8L13.05,15.85Q12.775,15.925 12.525,15.962Q12.275,16 12,16Q10.125,16 8.812,14.688Q7.5,13.375 7.5,11.5Q7.5,11.225 7.537,10.975Q7.575,10.725 7.65,10.45ZM13.525,10.725Q13.525,10.725 13.525,10.725Q13.525,10.725 13.525,10.725Q13.525,10.725 13.525,10.725Q13.525,10.725 13.525,10.725Q13.525,10.725 13.525,10.725Q13.525,10.725 13.525,10.725ZM9.75,12.6Q9.75,12.6 9.75,12.6Q9.75,12.6 9.75,12.6Q9.75,12.6 9.75,12.6Q9.75,12.6 9.75,12.6Q9.75,12.6 9.75,12.6Q9.75,12.6 9.75,12.6Z" />
|
||||
</vector>
|
||||
BIN
app/src/main/res/font/hoog.ttf
Normal file
BIN
app/src/main/res/font/hoog.ttf
Normal file
Binary file not shown.
BIN
app/src/main/res/font/manropemedium.ttf
Normal file
BIN
app/src/main/res/font/manropemedium.ttf
Normal file
Binary file not shown.
BIN
app/src/main/res/font/merriweather.ttf
Normal file
BIN
app/src/main/res/font/merriweather.ttf
Normal file
Binary file not shown.
BIN
app/src/main/res/font/osdmono.ttf
Normal file
BIN
app/src/main/res/font/osdmono.ttf
Normal file
Binary file not shown.
BIN
app/src/main/res/font/unifrakturcookbold.ttf
Normal file
BIN
app/src/main/res/font/unifrakturcookbold.ttf
Normal file
Binary file not shown.
8
app/src/main/res/layout/activity_fake_home.xml
Normal file
8
app/src/main/res/layout/activity_fake_home.xml
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".FakeHomeActivity">
|
||||
|
||||
</merge>
|
||||
19
app/src/main/res/layout/activity_main.xml
Normal file
19
app/src/main/res/layout/activity_main.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:animateLayoutChanges="true">
|
||||
|
||||
<!-- Remove the EditText search view if it exists -->
|
||||
|
||||
<fragment
|
||||
android:id="@+id/nav_host_fragment"
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:defaultNavHost="true"
|
||||
app:navGraph="@navigation/nav_graph"
|
||||
tools:ignore="FragmentTagUsage" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
173
app/src/main/res/layout/adapter_app_drawer.xml
Normal file
173
app/src/main/res/layout/adapter_app_drawer.xml
Normal file
@@ -0,0 +1,173 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:animateLayoutChanges="true">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/appTitleFrame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/appTitle"
|
||||
style="@style/TextLarge"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
android:paddingHorizontal="24dp"
|
||||
android:paddingVertical="@dimen/app_padding_vertical"
|
||||
android:text="@string/select_app" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/appHideLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:animateLayoutChanges="true"
|
||||
android:background="?attr/primaryColorInverseTrans80"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:gravity="end|center_vertical"
|
||||
android:paddingVertical="@dimen/app_padding_vertical"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/appDelete"
|
||||
style="@style/TextSmall"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:drawablePadding="2dp"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center"
|
||||
android:maxLines="1"
|
||||
android:paddingHorizontal="8dp"
|
||||
android:text="@string/delete"
|
||||
android:textSize="12sp"
|
||||
app:drawableTopCompat="@drawable/ic_delete" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/appRename"
|
||||
style="@style/TextSmall"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:drawablePadding="2dp"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center"
|
||||
android:maxLines="1"
|
||||
android:paddingHorizontal="8dp"
|
||||
android:text="@string/rename"
|
||||
android:textSize="12sp"
|
||||
app:drawableTopCompat="@drawable/ic_rename" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/appHide"
|
||||
style="@style/TextSmall"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:drawablePadding="2dp"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center"
|
||||
android:maxLines="1"
|
||||
android:paddingHorizontal="8dp"
|
||||
android:text="@string/hide"
|
||||
android:textSize="12sp"
|
||||
app:drawableTopCompat="@drawable/visibility_off" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/appLock"
|
||||
style="@style/TextSmall"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:drawablePadding="2dp"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center"
|
||||
android:maxLines="1"
|
||||
android:paddingHorizontal="8dp"
|
||||
android:text="@string/lock"
|
||||
android:textSize="12sp"
|
||||
app:drawableTopCompat="@drawable/padlock_off" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/appInfo"
|
||||
style="@style/TextSmall"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:drawablePadding="2dp"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center"
|
||||
android:maxLines="1"
|
||||
android:paddingHorizontal="8dp"
|
||||
android:text="@string/info"
|
||||
android:textSize="12sp"
|
||||
app:drawableTopCompat="@drawable/ic_info" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/appClose"
|
||||
style="@style/TextSmall"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:drawablePadding="2dp"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center"
|
||||
android:maxLines="1"
|
||||
android:paddingHorizontal="8dp"
|
||||
android:text="@string/close"
|
||||
android:textSize="12sp"
|
||||
app:drawableTopCompat="@drawable/ic_close" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/appRenameLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:animateLayoutChanges="true"
|
||||
android:background="?attr/primaryColorInverseTrans80"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:gravity="end|center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone"
|
||||
tools:visibility="gone">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/appRenameEdit"
|
||||
style="@style/TextLarge"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_weight="1"
|
||||
android:autofillHints="name"
|
||||
android:background="@null"
|
||||
android:gravity="center_vertical"
|
||||
android:inputType="textCapWords"
|
||||
android:maxLength="30"
|
||||
android:maxLines="1"
|
||||
android:paddingVertical="@dimen/app_padding_vertical"
|
||||
android:textColorHint="?attr/primaryColorTrans50"
|
||||
tools:ignore="LabelFor" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/appSaveRename"
|
||||
style="@style/TextSmallBold"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:paddingHorizontal="20dp"
|
||||
android:text="@string/rename"
|
||||
android:textAllCaps="true" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
36
app/src/main/res/layout/dialog_single_choice.xml
Normal file
36
app/src/main/res/layout/dialog_single_choice.xml
Normal file
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minWidth="320dp"
|
||||
android:orientation="vertical"
|
||||
android:padding="24dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialogTitle"
|
||||
style="@style/DialogTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="start|center_vertical"
|
||||
android:paddingBottom="12dp" />
|
||||
|
||||
<ListView
|
||||
android:id="@+id/dialogListView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:divider="@android:color/transparent"
|
||||
android:dividerHeight="0dp"
|
||||
android:maxHeight="320dp"
|
||||
android:overScrollMode="ifContentScrolls"
|
||||
android:scrollbars="vertical"
|
||||
tools:ignore="NestedScrolling" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/dialogDeleteButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/delete"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
||||
86
app/src/main/res/layout/fragment_app_drawer.xml
Normal file
86
app/src/main/res/layout/fragment_app_drawer.xml
Normal file
@@ -0,0 +1,86 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/mainLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:animateLayoutChanges="true"
|
||||
android:background="?attr/primaryShadeDarkColor">
|
||||
|
||||
<!-- Search Bar positioned at the top -->
|
||||
<LinearLayout
|
||||
android:id="@+id/searchContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_marginTop="32dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<androidx.appcompat.widget.SearchView
|
||||
android:id="@+id/search"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="end"
|
||||
android:imeOptions="actionSearch"
|
||||
android:paddingHorizontal="8dp"
|
||||
android:paddingVertical="0dp"
|
||||
android:textCursorDrawable="@null"
|
||||
app:closeIcon="@null"
|
||||
app:iconifiedByDefault="false"
|
||||
app:queryBackground="@null"
|
||||
app:queryHint="___"
|
||||
app:searchIcon="@null"
|
||||
app:theme="@style/AppSearchText" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Drawer button and tip, positioned below search container -->
|
||||
<TextView
|
||||
android:id="@+id/drawerButton"
|
||||
style="@style/TextSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/searchContainer"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:paddingVertical="@dimen/app_padding_vertical"
|
||||
android:textAllCaps="true"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/appDrawerTip"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/drawerButton"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:text="@string/app_drawer_tips"
|
||||
android:textColor="?attr/primaryColor"
|
||||
android:textSize="16sp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<!-- RecyclerView positioned below the Drawer TextViews -->
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_below="@id/appDrawerTip"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_marginBottom="25dp"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:overScrollMode="never"
|
||||
android:paddingBottom="25dp" />
|
||||
|
||||
<!-- List Empty Hint, center aligned -->
|
||||
<TextView
|
||||
android:id="@+id/listEmptyHint"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:text="@string/drawer_list_empty_hint"
|
||||
android:textSize="20sp" />
|
||||
|
||||
</RelativeLayout>
|
||||
37
app/src/main/res/layout/fragment_favorite.xml
Normal file
37
app/src/main/res/layout/fragment_favorite.xml
Normal file
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/mainLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:animateLayoutChanges="true"
|
||||
android:orientation="vertical"
|
||||
tools:context=".ui.FavoriteFragment">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginHorizontal="22dp"
|
||||
android:layout_marginVertical="24dp"
|
||||
android:orientation="vertical"
|
||||
tools:ignore="UselessParent"
|
||||
tools:visibility="visible">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/pageName"
|
||||
style="@style/TextDefault"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginVertical="24dp"
|
||||
android:textSize="@dimen/date_size" />
|
||||
|
||||
<!-- Home apps-->
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/homeAppsRecyclerview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:listitem="@layout/home_app_button" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
126
app/src/main/res/layout/fragment_home.xml
Normal file
126
app/src/main/res/layout/fragment_home.xml
Normal file
@@ -0,0 +1,126 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/mainLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:animateLayoutChanges="true"
|
||||
android:orientation="vertical"
|
||||
tools:context=".ui.HomeFragment">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/touchArea"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp" />
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginHorizontal="20dp"
|
||||
android:layout_marginVertical="36dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginVertical="1dp"
|
||||
android:orientation="vertical"
|
||||
tools:visibility="visible">
|
||||
|
||||
<TextClock
|
||||
android:id="@+id/clock"
|
||||
style="@style/TextDefaultStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="@dimen/time_size"
|
||||
tools:text="02:34" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/alarm"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="@dimen/alarm_size"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="@dimen/alarm_size"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
|
||||
<!-- Home apps-->
|
||||
<LinearLayout
|
||||
android:id="@+id/homeAppsLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="vertical"
|
||||
android:paddingHorizontal="20dp"
|
||||
android:paddingTop="100dp"
|
||||
android:paddingBottom="30dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/homeScreenPager"
|
||||
style="@style/TextSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:rotation="90"
|
||||
android:translationX="16dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
|
||||
<!-- Set default launcher -->
|
||||
<TextView
|
||||
android:id="@+id/setDefaultLauncher"
|
||||
style="@style/TextSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|center_horizontal"
|
||||
android:layout_marginStart="24dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:text="@string/advanced_settings_set_as_default_launcher"
|
||||
android:visibility="gone" />
|
||||
|
||||
<!-- Battery indicator repositioned to bottom center -->
|
||||
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/battery"
|
||||
style="@style/TextDefaultStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|center_horizontal"
|
||||
android:layout_marginBottom="48dp"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginBottom="64dp"
|
||||
android:background="@drawable/fab_background"
|
||||
android:contentDescription="@string/show"
|
||||
android:elevation="6dp"
|
||||
android:padding="6dp"
|
||||
android:src="@drawable/app_launcher"
|
||||
android:visibility="gone" />
|
||||
|
||||
</FrameLayout>
|
||||
28
app/src/main/res/layout/fragment_settings.xml
Normal file
28
app/src/main/res/layout/fragment_settings.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/scrollView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:animateLayoutChanges="true"
|
||||
android:background="?attr/primaryShadeDarkColor"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:fillViewport="true"
|
||||
android:overScrollMode="never"
|
||||
android:scrollbars="none">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.compose.ui.platform.ComposeView
|
||||
android:id="@+id/settingsView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
12
app/src/main/res/layout/home_app_button.xml
Normal file
12
app/src/main/res/layout/home_app_button.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/homeAppLabel"
|
||||
style="@style/TextLarge"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/select_app"
|
||||
android:lineSpacingExtra="2dp"
|
||||
android:maxLines="3"
|
||||
android:paddingVertical="@dimen/home_app_padding_vertical"
|
||||
android:tag="1"
|
||||
android:textColorHint="?android:textColorPrimary"
|
||||
android:textSize="16sp" />
|
||||
28
app/src/main/res/layout/item_single_choice.xml
Normal file
28
app/src/main/res/layout/item_single_choice.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="12dp"
|
||||
android:paddingVertical="6dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/delete_icon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:contentDescription="@string/delete"
|
||||
android:padding="4dp"
|
||||
android:src="@drawable/ic_delete"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_item"
|
||||
style="@style/DialogTitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="start|center_vertical"
|
||||
android:textColor="?attr/colorOnSurface"
|
||||
android:textSize="18sp" />
|
||||
</LinearLayout>
|
||||
138
app/src/main/res/navigation/nav_graph.xml
Normal file
138
app/src/main/res/navigation/nav_graph.xml
Normal file
@@ -0,0 +1,138 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
app:startDestination="@id/mainFragment">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/mainFragment"
|
||||
android:name="com.github.gezimos.inkos.ui.HomeFragment"
|
||||
android:label="mainFragment"
|
||||
tools:layout="@layout/fragment_home">
|
||||
<action
|
||||
android:id="@+id/action_mainFragment_to_appListFragment"
|
||||
app:destination="@id/appListFragment" />
|
||||
|
||||
<action
|
||||
android:id="@+id/action_mainFragment_to_notificationsFragment"
|
||||
app:destination="@id/notificationsFragment" />
|
||||
<action
|
||||
android:id="@+id/action_mainFragment_to_settingsFragment"
|
||||
app:destination="@id/settingsFragment" />
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/appListFragment"
|
||||
android:name="com.github.gezimos.inkos.ui.AppDrawerFragment"
|
||||
android:label="appListFragment"
|
||||
tools:layout="@layout/fragment_app_drawer">
|
||||
<action
|
||||
android:id="@+id/action_appListFragment_to_settingsFragment"
|
||||
app:destination="@id/settingsFragment"
|
||||
app:popUpTo="@+id/appListFragment"
|
||||
app:popUpToInclusive="true" />
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/appFavoriteFragment"
|
||||
android:name="com.github.gezimos.inkos.ui.FavoriteFragment"
|
||||
android:label="appFavoriteFragment"
|
||||
tools:layout="@layout/fragment_favorite" />
|
||||
|
||||
<fragment
|
||||
android:id="@+id/appDrawerListFragment"
|
||||
android:name="com.github.gezimos.inkos.ui.AppDrawerFragment"
|
||||
android:label="AppDrawerFragment" />
|
||||
|
||||
<fragment
|
||||
android:id="@+id/notificationsFragment"
|
||||
android:name="com.github.gezimos.inkos.ui.notifications.NotificationsFragment"
|
||||
android:label="NotificationsFragment"
|
||||
tools:layout="@layout/fragment_settings" />
|
||||
|
||||
<fragment
|
||||
android:id="@+id/settingsFragment"
|
||||
android:name="com.github.gezimos.inkos.ui.SettingsFragment"
|
||||
android:label="SettingsFragment"
|
||||
android:layout="@layout/fragment_settings">
|
||||
<action
|
||||
android:id="@+id/action_settingsFragment_to_appListFragment"
|
||||
app:destination="@id/appListFragment" />
|
||||
|
||||
<action
|
||||
android:id="@+id/action_settingsFragment_to_appFavoriteFragment"
|
||||
app:destination="@id/appFavoriteFragment" />
|
||||
|
||||
<action
|
||||
android:id="@+id/action_settingsFragment_to_settingsFeaturesFragment"
|
||||
app:destination="@id/settingsFeaturesFragment" />
|
||||
|
||||
<action
|
||||
android:id="@+id/action_settingsFragment_to_settingsLookFeelFragment"
|
||||
app:destination="@id/settingsLookFeelFragment" />
|
||||
|
||||
<action
|
||||
android:id="@+id/action_settingsFragment_to_settingsGesturesFragment"
|
||||
app:destination="@id/settingsGesturesFragment" />
|
||||
|
||||
<action
|
||||
android:id="@+id/action_settingsFragment_to_settingsAdvancedFragment"
|
||||
app:destination="@id/settingsAdvancedFragment" />
|
||||
|
||||
<action
|
||||
android:id="@+id/action_settingsFragment_to_fontsFragment"
|
||||
app:destination="@id/fontsFragment" />
|
||||
|
||||
<action
|
||||
android:id="@+id/action_settingsFragment_to_notificationSettingsFragment"
|
||||
app:destination="@id/notificationSettingsFragment" />
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/settingsFeaturesFragment"
|
||||
android:name="com.github.gezimos.inkos.ui.settings.FeaturesFragment"
|
||||
android:label="FeaturesFragment"
|
||||
tools:layout="@layout/fragment_settings">
|
||||
<action
|
||||
android:id="@+id/action_settingsFeaturesFragment_to_appFavoriteFragment"
|
||||
app:destination="@id/appFavoriteFragment" />
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/settingsLookFeelFragment"
|
||||
android:name="com.github.gezimos.inkos.ui.settings.LookFeelFragment"
|
||||
android:label="LookFeelFragment"
|
||||
tools:layout="@layout/fragment_settings" />
|
||||
|
||||
<fragment
|
||||
android:id="@+id/settingsGesturesFragment"
|
||||
android:name="com.github.gezimos.inkos.ui.settings.GesturesFragment"
|
||||
android:label="GesturesFragment"
|
||||
tools:layout="@layout/fragment_settings">
|
||||
|
||||
<action
|
||||
android:id="@+id/action_gesturesFragment_to_appListFragment"
|
||||
app:destination="@id/appListFragment" />
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/settingsAdvancedFragment"
|
||||
android:name="com.github.gezimos.inkos.ui.settings.AdvancedFragment"
|
||||
android:label="settingsAdvancedFragment"
|
||||
tools:layout="@layout/fragment_settings">
|
||||
<action
|
||||
android:id="@+id/action_settingsAdvancedFragment_to_appListFragment"
|
||||
app:destination="@id/appListFragment" />
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/fontsFragment"
|
||||
android:name="com.github.gezimos.inkos.ui.settings.FontsFragment"
|
||||
android:label="FontsFragment" />
|
||||
|
||||
<fragment
|
||||
android:id="@+id/notificationSettingsFragment"
|
||||
android:name="com.github.gezimos.inkos.ui.settings.NotificationSettingsFragment"
|
||||
android:label="NotificationSettingsFragment"
|
||||
tools:layout="@layout/fragment_settings" />
|
||||
</navigation>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user