Inital commit
31
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Device (please complete the following information):**
|
||||
- Device: [e.g. Pixel 3]
|
||||
- Android version: [e.g. 11]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
16
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: github-actions
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: daily
|
||||
time: "04:00"
|
||||
timezone: Europe/Berlin
|
||||
open-pull-requests-limit: 99
|
||||
- package-ecosystem: gradle
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: daily
|
||||
time: "04:00"
|
||||
timezone: Europe/Berlin
|
||||
open-pull-requests-limit: 99
|
22
.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
name: Build App
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: 'adopt'
|
||||
java-version: 8
|
||||
|
||||
- name: Validate Gradle Wrapper
|
||||
uses: gradle/wrapper-validation-action@v1
|
||||
|
||||
- name: Build
|
||||
run: bash gradlew build
|
15
.gitignore
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/caches
|
||||
/.idea/libraries
|
||||
/.idea/modules.xml
|
||||
/.idea/workspace.xml
|
||||
/.idea/navEditor.xml
|
||||
/.idea/assetWizardSettings.xml
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
.cxx
|
||||
local.properties
|
3
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
1
.idea/.name
Normal file
@ -0,0 +1 @@
|
||||
Prepaid Balance
|
123
.idea/codeStyles/Project.xml
Normal file
@ -0,0 +1,123 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<JetCodeStyleSettings>
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</JetCodeStyleSettings>
|
||||
<codeStyleSettings language="XML">
|
||||
<option name="FORCE_REARRANGE_MODE" value="1" />
|
||||
<indentOptions>
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
</indentOptions>
|
||||
<arrangement>
|
||||
<rules>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:android</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:id</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>style</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>ANDROID_ATTRIBUTE_ORDER</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>.*</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
</rules>
|
||||
</arrangement>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="kotlin">
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
</state>
|
||||
</component>
|
6
.idea/compiler.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="11" />
|
||||
</component>
|
||||
</project>
|
22
.idea/gradle.xml
Normal file
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="testRunner" value="PLATFORM" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="1.8" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
<option name="useQualifiedModuleNames" value="true" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
35
.idea/jarRepositories.xml
Normal file
@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="BintrayJCenter" />
|
||||
<option name="name" value="BintrayJCenter" />
|
||||
<option name="url" value="https://jcenter.bintray.com/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="Google" />
|
||||
<option name="name" value="Google" />
|
||||
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="maven" />
|
||||
<option name="name" value="maven" />
|
||||
<option name="url" value="https://jitpack.io" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="MavenRepo" />
|
||||
<option name="name" value="MavenRepo" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
9
.idea/misc.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
</project>
|
10
.idea/runConfigurations.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
201
LICENSE
Normal file
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
23
README.md
Normal file
@ -0,0 +1,23 @@
|
||||
# Prepaid balance
|
||||
|
||||
This app keeps track of your prepaid balance. It can automatically record it and post a notification if your balance drops under a configurable threshold.
|
||||
It does so by parsing the response of a USSD code, that can be set in the settings.
|
||||
|
||||
[<img src="https://f-droid.org/badge/get-it-on.png" alt="Get it on F-Droid" height="80">](https://f-droid.org/de/packages/com.github.muellerma.prepaidbalance/)
|
||||
|
||||
## Translations
|
||||
|
||||
You can help translating this app by coping the file `app/src/main/res/values/strings.xml` to `app/src/main/res/values-xx/strings.xml` (`xx` stands for your language code), removing all entries marked with `translatable="false"` and translating the remaining entries. This file contains all strings used in the app.
|
||||
|
||||
The app store description can also be translated: Copy `fastlane/metadata/android/en-US/full_description.txt` and `fastlane/metadata/android/en-US/short_description.txt` to `fastlane/metadata/android/xx-YY/full_description.txt` (`xx` is the language code, `YY` is the country code) and translate the file.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
You might run into on of these issues with the app:
|
||||
* The USSD code is different than the default (`*100#`). In this case please configure the correct one and open an issue, so I can change the default code for your provider.
|
||||
* Your provider doesn't provide a USSD code to query your prepaid balance. In this case you cannot use this app.
|
||||
* Depending on the response pattern the parsing might fail. In this case please open an issue.
|
||||
|
||||
## Credits
|
||||
|
||||
* Feature graphic by https://unsplash.com/@joshappel
|
9
SECURITY.md
Normal file
@ -0,0 +1,9 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
Since this is an Android app, only the latest version is supported.
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Please open an issue on GitHub to report a vulnerability.
|
1
app/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/build
|
65
app/build.gradle
Normal file
@ -0,0 +1,65 @@
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'kotlin-android'
|
||||
id 'kotlin-kapt'
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 30
|
||||
buildToolsVersion "30.0.3"
|
||||
|
||||
repositories {
|
||||
maven { url 'https://jitpack.io' }
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.github.muellerma.prepaidbalance"
|
||||
minSdkVersion 26
|
||||
targetSdkVersion 30
|
||||
versionCode 2
|
||||
versionName "0.1"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = '1.8'
|
||||
}
|
||||
buildFeatures {
|
||||
viewBinding true
|
||||
}
|
||||
testOptions {
|
||||
unitTests.returnDefaultValues = true
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
implementation "androidx.core:core-ktx:1.3.2"
|
||||
implementation "androidx.fragment:fragment-ktx:1.3.3"
|
||||
implementation "androidx.appcompat:appcompat:1.2.0"
|
||||
implementation "androidx.preference:preference-ktx:1.1.1"
|
||||
implementation "com.google.android.material:material:1.3.0"
|
||||
implementation "androidx.constraintlayout:constraintlayout:2.0.4"
|
||||
implementation "androidx.room:room-runtime:$room_version"
|
||||
implementation "androidx.room:room-ktx:$room_version"
|
||||
kapt "androidx.room:room-compiler:$room_version"
|
||||
implementation "androidx.work:work-runtime-ktx:$workmanager_version"
|
||||
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
|
||||
testImplementation "junit:junit:4.13.2"
|
||||
androidTestImplementation "androidx.test.ext:junit:1.1.2"
|
||||
androidTestImplementation "androidx.test.espresso:espresso-core:3.3.0"
|
||||
|
||||
|
||||
}
|
21
app/proguard-rules.pro
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
# 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
|
@ -0,0 +1,52 @@
|
||||
package com.github.muellerma.prepaidbalance
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.github.muellerma.prepaidbalance.room.AppDatabase
|
||||
import com.github.muellerma.prepaidbalance.room.BalanceEntry
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class DatabaseTest {
|
||||
@Before
|
||||
fun setupDatabase() {
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
val now = System.currentTimeMillis()
|
||||
AppDatabase.get(appContext)
|
||||
.balanceDao().apply {
|
||||
deleteAll()
|
||||
insert(BalanceEntry(timestamp = now, balance = 10.15))
|
||||
insert(BalanceEntry(timestamp = now - 5 * 60 * 1000, balance = 0.15))
|
||||
insert(BalanceEntry(timestamp = now - 60 * 60 * 1000, balance = 5.12))
|
||||
insert(BalanceEntry(timestamp = now - 30 * 60 * 60 * 1000, balance = 7.12))
|
||||
insert(BalanceEntry(timestamp = 12, balance = 7.12)) // quite old
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getAllTest() {
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals(5, AppDatabase.get(appContext).balanceDao().getAll().size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getLatestTest() {
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
val latest = AppDatabase.get(appContext).balanceDao().getLatest()
|
||||
assertNotNull(latest)
|
||||
assertEquals(10.15, latest!!.balance, 0.01)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun deleteOldTest() {
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
val database = AppDatabase.get(appContext).balanceDao()
|
||||
database.deleteBefore(100000)
|
||||
assertEquals(4, database.getAll().size)
|
||||
}
|
||||
}
|
25
app/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.github.muellerma.prepaidbalance">
|
||||
|
||||
<uses-permission android:name="android.permission.CALL_PHONE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.App">
|
||||
<activity android:name="com.github.muellerma.prepaidbalance.ui.MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name="com.github.muellerma.prepaidbalance.ui.PreferenceActivity" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -0,0 +1,27 @@
|
||||
package com.github.muellerma.prepaidbalance.room
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
|
||||
@Dao
|
||||
interface BalanceDao {
|
||||
@Query("SELECT * FROM BalanceEntry ORDER BY timestamp DESC")
|
||||
fun getAll(): List<BalanceEntry>
|
||||
|
||||
@Insert
|
||||
fun insert(balance: BalanceEntry)
|
||||
|
||||
@Delete
|
||||
fun delete(balance: BalanceEntry)
|
||||
|
||||
@Query("DELETE FROM BalanceEntry")
|
||||
fun deleteAll()
|
||||
|
||||
@Query("SELECT * FROM BalanceEntry ORDER BY timestamp DESC LIMIT 1")
|
||||
fun getLatest(): BalanceEntry?
|
||||
|
||||
@Query("DELETE FROM BalanceEntry WHERE timestamp < :before")
|
||||
fun deleteBefore(before: Long)
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.github.muellerma.prepaidbalance.room
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
|
||||
@Database(entities = [BalanceEntry::class], version = 1)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
abstract fun balanceDao(): BalanceDao
|
||||
|
||||
companion object {
|
||||
private var instance: AppDatabase? = null
|
||||
|
||||
fun get(context: Context): AppDatabase {
|
||||
if (instance == null) {
|
||||
instance = Room.databaseBuilder(
|
||||
context,
|
||||
AppDatabase::class.java,
|
||||
"balance-history"
|
||||
).build()
|
||||
}
|
||||
|
||||
// TODO better solution?
|
||||
return instance!!
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.github.muellerma.prepaidbalance.room
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import kotlin.math.abs
|
||||
|
||||
@Entity
|
||||
data class BalanceEntry(
|
||||
@PrimaryKey(autoGenerate = true) val id: Int? = null,
|
||||
val timestamp: Long,
|
||||
@ColumnInfo(name = "balance") val balance: Double
|
||||
) {
|
||||
fun nearlyEquals(other: BalanceEntry): Boolean {
|
||||
if (balance != other.balance) {
|
||||
return false
|
||||
}
|
||||
|
||||
return abs(timestamp - other.timestamp) < 15 * 60 * 1000
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.github.muellerma.prepaidbalance.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.muellerma.prepaidbalance.R
|
||||
import com.github.muellerma.prepaidbalance.room.BalanceEntry
|
||||
import com.github.muellerma.prepaidbalance.utils.formatAsCurrency
|
||||
import com.github.muellerma.prepaidbalance.utils.timestampForUi
|
||||
|
||||
class BalanceListAdapter(private val context: Context) :
|
||||
RecyclerView.Adapter<BalanceListViewHolder>() {
|
||||
var balances = emptyList<BalanceEntry>()
|
||||
set(value) {
|
||||
field = value
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
private val inflater = LayoutInflater.from(context)
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BalanceListViewHolder {
|
||||
return BalanceListViewHolder(inflater, parent)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: BalanceListViewHolder, position: Int) {
|
||||
holder.itemView.findViewById<TextView>(R.id.balance).apply {
|
||||
text = balances[position].balance.formatAsCurrency()
|
||||
}
|
||||
|
||||
holder.itemView.findViewById<TextView>(R.id.date).apply {
|
||||
text = balances[position].timestamp.timestampForUi(context)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount() = balances.size
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.github.muellerma.prepaidbalance.ui
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.muellerma.prepaidbalance.R
|
||||
|
||||
class BalanceListViewHolder internal constructor(
|
||||
inflater: LayoutInflater,
|
||||
parent: ViewGroup
|
||||
) : RecyclerView.ViewHolder(inflater.inflate(R.layout.list_balance, parent, false))
|
@ -0,0 +1,143 @@
|
||||
package com.github.muellerma.prepaidbalance.ui
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import com.github.muellerma.prepaidbalance.R
|
||||
import com.github.muellerma.prepaidbalance.databinding.ActivityMainBinding
|
||||
import com.github.muellerma.prepaidbalance.room.AppDatabase
|
||||
import com.github.muellerma.prepaidbalance.work.CheckBalanceWorker
|
||||
import com.github.muellerma.prepaidbalance.work.CheckBalanceWorker.Companion.CheckResult
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
|
||||
class MainActivity : AppCompatActivity(), CoroutineScope, SwipeRefreshLayout.OnRefreshListener {
|
||||
override val coroutineContext: CoroutineContext get() = Dispatchers.IO + Job()
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
private lateinit var database: AppDatabase
|
||||
private val requestPermissionLauncher = registerForActivityResult(
|
||||
ActivityResultContracts.RequestPermission()
|
||||
) { isGranted: Boolean ->
|
||||
if (isGranted) {
|
||||
onRefresh()
|
||||
} else {
|
||||
showSnackbar(R.string.permissions_required)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
database = AppDatabase.get(this)
|
||||
|
||||
binding.swiperefresh.setOnRefreshListener(this)
|
||||
|
||||
binding.list.layoutManager = LinearLayoutManager(this)
|
||||
binding.list.adapter = BalanceListAdapter(this)
|
||||
|
||||
PreferenceManager.setDefaultValues(this, R.xml.pref_main, false)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
updateBalanceList()
|
||||
super.onResume()
|
||||
}
|
||||
|
||||
private fun updateBalanceList() {
|
||||
launch {
|
||||
val entries = database.balanceDao().getAll()
|
||||
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
(binding.list.adapter as BalanceListAdapter).balances = entries
|
||||
binding.list.isVisible = entries.isNotEmpty()
|
||||
binding.hint.isVisible = entries.isEmpty()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
val inflater = menuInflater
|
||||
inflater.inflate(R.menu.main_menu, menu)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when(item.itemId) {
|
||||
R.id.preferences -> {
|
||||
Intent(this, PreferenceActivity::class.java).apply {
|
||||
startActivity(this)
|
||||
}
|
||||
true
|
||||
}
|
||||
android.R.id.home -> {
|
||||
onBackPressed()
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showSnackbar(@StringRes message: Int) {
|
||||
showSnackbar(getString(message))
|
||||
}
|
||||
|
||||
private fun showSnackbar(message: String) {
|
||||
Snackbar.make(findViewById(android.R.id.content), message, Snackbar.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
override fun onRefresh() {
|
||||
CheckBalanceWorker.checkBalance(this@MainActivity) { result ->
|
||||
Log.d(TAG, "Got result $result")
|
||||
binding.swiperefresh.isRefreshing = false
|
||||
|
||||
when (result) {
|
||||
CheckResult.OK -> {
|
||||
launch {
|
||||
val latestEntry = database.balanceDao().getLatest()
|
||||
?: throw IllegalStateException("No balance in db")
|
||||
showSnackbar(getString(R.string.current_balance, latestEntry.balance))
|
||||
updateBalanceList()
|
||||
}
|
||||
}
|
||||
CheckResult.PARSER_FAILED -> {
|
||||
showSnackbar(R.string.unable_get_balance)
|
||||
}
|
||||
CheckResult.USSD_FAILED -> {
|
||||
showSnackbar(R.string.ussd_failed)
|
||||
}
|
||||
CheckResult.MISSING_PERMISSIONS -> {
|
||||
requestPermissionLauncher.launch(Manifest.permission.CALL_PHONE)
|
||||
}
|
||||
CheckResult.USSD_INVALID -> {
|
||||
showSnackbar(R.string.invalid_ussd_code)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = MainActivity::class.java.simpleName
|
||||
private const val REQUEST_CODE_PHONE = 1
|
||||
}
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
package com.github.muellerma.prepaidbalance.ui
|
||||
|
||||
import android.os.Bundle
|
||||
import android.text.InputType
|
||||
import android.view.MenuItem
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.commit
|
||||
import androidx.preference.EditTextPreference
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import androidx.work.Constraints
|
||||
import androidx.work.ExistingPeriodicWorkPolicy
|
||||
import androidx.work.PeriodicWorkRequest
|
||||
import androidx.work.WorkManager
|
||||
import com.github.muellerma.prepaidbalance.R
|
||||
import com.github.muellerma.prepaidbalance.databinding.ActivityPreferenceBinding
|
||||
import com.github.muellerma.prepaidbalance.room.AppDatabase
|
||||
import com.github.muellerma.prepaidbalance.utils.isValidUssdCode
|
||||
import com.github.muellerma.prepaidbalance.work.CheckBalanceWorker
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import java.time.Duration
|
||||
|
||||
|
||||
class PreferenceActivity : AppCompatActivity() {
|
||||
private lateinit var binding: ActivityPreferenceBinding
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityPreferenceBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
|
||||
supportFragmentManager.commit {
|
||||
add(binding.activityContent.id, MainSettingsFragment())
|
||||
}
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
onBackPressed()
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class MainSettingsFragment : PreferenceFragmentCompat() {
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
addPreferencesFromResource(R.xml.pref_main)
|
||||
|
||||
val thresholdValuePref = getPreference("notify_balance_under_threshold_value") as EditTextPreference
|
||||
thresholdValuePref.setOnBindEditTextListener { editText ->
|
||||
editText.inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL
|
||||
}
|
||||
|
||||
val ussdCodePreference = getPreference("ussd_code")
|
||||
ussdCodePreference.setSummaryProvider { pref ->
|
||||
val currentValue = preferenceManager.sharedPreferences.getString(pref.key, "").orEmpty()
|
||||
if (!currentValue.isValidUssdCode()) {
|
||||
getString(R.string.invalid_ussd_code)
|
||||
} else {
|
||||
getString(R.string.ussd_code_summary, currentValue)
|
||||
}
|
||||
}
|
||||
|
||||
val workPref = getPreference("periodic_checks")
|
||||
workPref.setOnPreferenceChangeListener { _, newValue ->
|
||||
WorkManager.getInstance(preferenceManager.context).apply {
|
||||
if (newValue as Boolean) {
|
||||
val request = PeriodicWorkRequest.Builder(
|
||||
CheckBalanceWorker::class.java,
|
||||
Duration.ofHours(12)
|
||||
)
|
||||
.setConstraints(Constraints.NONE)
|
||||
.build()
|
||||
|
||||
enqueueUniquePeriodicWork(
|
||||
"work",
|
||||
ExistingPeriodicWorkPolicy.REPLACE,
|
||||
request
|
||||
)
|
||||
} else {
|
||||
cancelAllWork()
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
val clearDataPref = getPreference("clear_data")
|
||||
clearDataPref.setOnPreferenceClickListener {
|
||||
AlertDialog.Builder(it.context)
|
||||
.setMessage(R.string.clear_current_data)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
AppDatabase.get(it.context)
|
||||
.balanceDao()
|
||||
.deleteAll()
|
||||
}
|
||||
}
|
||||
.show()
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun PreferenceFragmentCompat.getPreference(key: String) =
|
||||
preferenceManager.findPreference<Preference>(key)!!
|
@ -0,0 +1,19 @@
|
||||
package com.github.muellerma.prepaidbalance.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.text.format.DateFormat
|
||||
|
||||
private const val TAG = "ExtensionFunctions"
|
||||
|
||||
fun Double.formatAsCurrency(): String {
|
||||
return "%1\$,.2f".format(this)
|
||||
}
|
||||
|
||||
fun Long.timestampForUi(context: Context): String {
|
||||
return DateFormat.getTimeFormat(context).format(this) + " " +
|
||||
DateFormat.getDateFormat(context).format(this)
|
||||
}
|
||||
|
||||
fun String.isValidUssdCode(): Boolean {
|
||||
return matches("^\\*(\\d)+#$".toRegex())
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.github.muellerma.prepaidbalance.utils
|
||||
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import androidx.core.app.NotificationCompat
|
||||
import com.github.muellerma.prepaidbalance.R
|
||||
|
||||
class NotificationUtils {
|
||||
companion object {
|
||||
private val TAG = NotificationUtils::class.java.simpleName
|
||||
const val CHANNEL_ID_BALANCE_INCREASED = "balance_increased"
|
||||
const val CHANNEL_ID_THRESHOLD_REACHED = "threshold"
|
||||
const val CHANNEL_ID_ERROR = "error"
|
||||
|
||||
const val NOTIFICATION_ID_BALANCE_INCREASED = 0
|
||||
const val NOTIFICATION_ID_THRESHOLD_REACHED = 1
|
||||
const val NOTIFICATION_ID_ERROR = 2
|
||||
|
||||
fun getBaseNotification(context: Context, channel: String): NotificationCompat.Builder {
|
||||
return NotificationCompat.Builder(context, channel)
|
||||
.setSmallIcon(R.drawable.ic_circle_multiple_outline)
|
||||
.setColor(context.getColor(R.color.golden))
|
||||
.setLights(context.getColor(R.color.golden), 500, 500)
|
||||
}
|
||||
|
||||
fun createChannels(context: Context) {
|
||||
Log.d(TAG, "createChannels()")
|
||||
val manager = manager(context)
|
||||
|
||||
manager.createNotificationChannel(
|
||||
NotificationChannel(
|
||||
CHANNEL_ID_BALANCE_INCREASED,
|
||||
context.getString(R.string.channel_name_balance_increased),
|
||||
NotificationManager.IMPORTANCE_DEFAULT
|
||||
)
|
||||
)
|
||||
|
||||
manager.createNotificationChannel(
|
||||
NotificationChannel(
|
||||
CHANNEL_ID_THRESHOLD_REACHED,
|
||||
context.getString(R.string.channel_name_threshold_reached),
|
||||
NotificationManager.IMPORTANCE_DEFAULT
|
||||
)
|
||||
)
|
||||
|
||||
manager.createNotificationChannel(
|
||||
NotificationChannel(
|
||||
CHANNEL_ID_ERROR,
|
||||
context.getString(R.string.channel_name_error),
|
||||
NotificationManager.IMPORTANCE_DEFAULT
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun manager(context: Context) =
|
||||
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.github.muellerma.prepaidbalance.utils
|
||||
|
||||
class ResponseParser {
|
||||
companion object {
|
||||
private val TAG = ResponseParser::class.java.simpleName
|
||||
|
||||
private val MATCHERS = listOf(
|
||||
MATCHER("^(.*?)((\\d)+\\.?(\\d)?(\\d)?)(.*) EUR (.*)".toRegex(), 2),
|
||||
MATCHER("^(.*?)((\\d)+\\.?(\\d)?(\\d)?)(.*)\$".toRegex(), 2)
|
||||
)
|
||||
|
||||
fun getBalance(response: String?): Double? {
|
||||
if (response == null || response.trim().isEmpty()) {
|
||||
return null
|
||||
}
|
||||
val withDots = response.replace(',', '.')
|
||||
|
||||
MATCHERS.forEach { matcher ->
|
||||
println("Check matcher $matcher") // TODO Log.d()
|
||||
if (withDots.matches(matcher.regex)) {
|
||||
return matcher
|
||||
.regex
|
||||
.matchEntire(withDots)
|
||||
?.groups
|
||||
?.get(matcher.groupContainsBalance)
|
||||
?.value
|
||||
?.toDouble()
|
||||
.also { println("Found balance $it") }
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
private data class MATCHER(val regex: Regex, val groupContainsBalance: Int)
|
||||
}
|
||||
}
|
@ -0,0 +1,184 @@
|
||||
package com.github.muellerma.prepaidbalance.work
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.telephony.TelephonyManager
|
||||
import android.util.Log
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.app.NotificationBuilderWithBuilderAccessor
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.work.Worker
|
||||
import androidx.work.WorkerParameters
|
||||
import com.github.muellerma.prepaidbalance.R
|
||||
import com.github.muellerma.prepaidbalance.room.AppDatabase
|
||||
import com.github.muellerma.prepaidbalance.room.BalanceEntry
|
||||
import com.github.muellerma.prepaidbalance.utils.NotificationUtils
|
||||
import com.github.muellerma.prepaidbalance.utils.NotificationUtils.Companion.CHANNEL_ID_BALANCE_INCREASED
|
||||
import com.github.muellerma.prepaidbalance.utils.NotificationUtils.Companion.CHANNEL_ID_ERROR
|
||||
import com.github.muellerma.prepaidbalance.utils.NotificationUtils.Companion.CHANNEL_ID_THRESHOLD_REACHED
|
||||
import com.github.muellerma.prepaidbalance.utils.NotificationUtils.Companion.NOTIFICATION_ID_BALANCE_INCREASED
|
||||
import com.github.muellerma.prepaidbalance.utils.NotificationUtils.Companion.NOTIFICATION_ID_THRESHOLD_REACHED
|
||||
import com.github.muellerma.prepaidbalance.utils.NotificationUtils.Companion.getBaseNotification
|
||||
import com.github.muellerma.prepaidbalance.utils.ResponseParser
|
||||
import com.github.muellerma.prepaidbalance.utils.formatAsCurrency
|
||||
import com.github.muellerma.prepaidbalance.utils.isValidUssdCode
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
class CheckBalanceWorker(
|
||||
val context: Context,
|
||||
workerParams: WorkerParameters
|
||||
) :
|
||||
Worker(context, workerParams)
|
||||
{
|
||||
override fun doWork(): Result {
|
||||
checkBalance(applicationContext) { result ->
|
||||
@StringRes val errorMessage = when (result) {
|
||||
CheckResult.USSD_FAILED -> R.string.ussd_failed
|
||||
CheckResult.MISSING_PERMISSIONS -> R.string.permissions_required
|
||||
CheckResult.PARSER_FAILED -> R.string.unable_get_balance
|
||||
CheckResult.USSD_INVALID -> R.string.invalid_ussd_code
|
||||
CheckResult.OK -> null
|
||||
}
|
||||
|
||||
errorMessage?.let {
|
||||
val notification = getBaseNotification(context, CHANNEL_ID_ERROR)
|
||||
.setContentTitle(context.getString(errorMessage))
|
||||
|
||||
NotificationUtils
|
||||
.manager(context)
|
||||
.notify(NotificationUtils.NOTIFICATION_ID_ERROR, notification.build())
|
||||
}
|
||||
}
|
||||
|
||||
return Result.success()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = CheckBalanceWorker::class.java.simpleName
|
||||
|
||||
fun checkBalance(context: Context, callback: (CheckResult)->Unit) {
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
AppDatabase
|
||||
.get(context)
|
||||
.balanceDao()
|
||||
.deleteBefore(System.currentTimeMillis() - 6L * 30 * 24 * 60 * 60 * 1000) // 6 months
|
||||
}
|
||||
|
||||
if (ActivityCompat.checkSelfPermission(
|
||||
context,
|
||||
Manifest.permission.CALL_PHONE
|
||||
) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
return callback(CheckResult.MISSING_PERMISSIONS)
|
||||
}
|
||||
|
||||
val ussdResponseCallback = object : TelephonyManager.UssdResponseCallback() {
|
||||
override fun onReceiveUssdResponse(
|
||||
telephonyManager: TelephonyManager?,
|
||||
request: String?,
|
||||
response: CharSequence?
|
||||
) {
|
||||
Log.d(TAG, "onReceiveUssdResponse($response)")
|
||||
val balance = ResponseParser.getBalance(response as String?)
|
||||
?: return callback(CheckResult.PARSER_FAILED)
|
||||
|
||||
handleNewBalance(context, balance, callback)
|
||||
}
|
||||
|
||||
override fun onReceiveUssdResponseFailed(
|
||||
telephonyManager: TelephonyManager?,
|
||||
request: String?,
|
||||
failureCode: Int
|
||||
) {
|
||||
Log.d(TAG, "onReceiveUssdResponseFailed($failureCode)")
|
||||
return callback(CheckResult.USSD_FAILED)
|
||||
}
|
||||
}
|
||||
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
val ussdCode = prefs.getString("ussd_code", "").orEmpty()
|
||||
if (!ussdCode.isValidUssdCode()) {
|
||||
return callback(CheckResult.USSD_INVALID)
|
||||
}
|
||||
|
||||
context.getSystemService(TelephonyManager::class.java)
|
||||
.sendUssdRequest(
|
||||
ussdCode,
|
||||
ussdResponseCallback,
|
||||
Handler(Looper.getMainLooper())
|
||||
)
|
||||
}
|
||||
|
||||
private fun handleNewBalance(context: Context, balance: Double, callback: (CheckResult) -> Unit) =
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
val database = AppDatabase.get(context)
|
||||
|
||||
val latestInDb = database.balanceDao().getLatest()
|
||||
val new = BalanceEntry(timestamp = System.currentTimeMillis(), balance = balance)
|
||||
|
||||
database
|
||||
.balanceDao()
|
||||
.insert(new)
|
||||
|
||||
if (latestInDb?.nearlyEquals(new) == true) {
|
||||
Log.d(TAG, "Remove $latestInDb from db")
|
||||
database.balanceDao().delete(latestInDb)
|
||||
}
|
||||
|
||||
callback(CheckResult.OK)
|
||||
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
if (prefs.getBoolean("notify_balance_increased", false) &&
|
||||
latestInDb != null &&
|
||||
new.balance > latestInDb.balance
|
||||
) {
|
||||
val diff = new.balance - latestInDb.balance
|
||||
Log.d(TAG, "New balance is larger: $diff")
|
||||
|
||||
NotificationUtils.createChannels(context)
|
||||
|
||||
val notification = getBaseNotification(context, CHANNEL_ID_BALANCE_INCREASED)
|
||||
.setContentTitle(context.getString(R.string.balance_increased, diff.formatAsCurrency()))
|
||||
|
||||
NotificationUtils
|
||||
.manager(context)
|
||||
.notify(NOTIFICATION_ID_BALANCE_INCREASED, notification.build())
|
||||
}
|
||||
|
||||
val threshold = try {
|
||||
prefs
|
||||
.getString("notify_balance_under_threshold_value", "")
|
||||
?.replace(',', '.')
|
||||
?.toDouble() ?: Double.MAX_VALUE
|
||||
} catch (e: Exception) {
|
||||
Double.MAX_VALUE
|
||||
}
|
||||
if (
|
||||
prefs.getBoolean("notify_balance_under_threshold", false) &&
|
||||
new.balance < threshold
|
||||
) {
|
||||
NotificationUtils.createChannels(context)
|
||||
|
||||
val notification = getBaseNotification(context, CHANNEL_ID_THRESHOLD_REACHED)
|
||||
.setContentTitle(context.getString(R.string.threshold_reached, new.balance.formatAsCurrency()))
|
||||
|
||||
NotificationUtils
|
||||
.manager(context)
|
||||
.notify(NOTIFICATION_ID_THRESHOLD_REACHED, notification.build())
|
||||
}
|
||||
}
|
||||
|
||||
enum class CheckResult {
|
||||
OK,
|
||||
MISSING_PERMISSIONS,
|
||||
PARSER_FAILED,
|
||||
USSD_FAILED,
|
||||
USSD_INVALID
|
||||
}
|
||||
}
|
||||
}
|
9
app/src/main/res/drawable/ic_circle_multiple_outline.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:pathData="M15,4A8,8 0,0 1,23 12A8,8 0,0 1,15 20A8,8 0,0 1,7 12A8,8 0,0 1,15 4M15,18A6,6 0,0 0,21 12A6,6 0,0 0,15 6A6,6 0,0 0,9 12A6,6 0,0 0,15 18M3,12C3,14.61 4.67,16.83 7,17.65V19.74C3.55,18.85 1,15.73 1,12C1,8.27 3.55,5.15 7,4.26V6.35C4.67,7.17 3,9.39 3,12Z"
|
||||
android:fillColor="#000"/>
|
||||
</vector>
|
14
app/src/main/res/drawable/ic_launcher_foreground.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<group android:scaleX="1.9899"
|
||||
android:scaleY="1.9899"
|
||||
android:translateX="30.1212"
|
||||
android:translateY="30.1212">
|
||||
<path
|
||||
android:pathData="M15,4A8,8 0,0 1,23 12A8,8 0,0 1,15 20A8,8 0,0 1,7 12A8,8 0,0 1,15 4M15,18A6,6 0,0 0,21 12A6,6 0,0 0,15 6A6,6 0,0 0,9 12A6,6 0,0 0,15 18M3,12C3,14.61 4.67,16.83 7,17.65V19.74C3.55,18.85 1,15.73 1,12C1,8.27 3.55,5.15 7,4.26V6.35C4.67,7.17 3,9.39 3,12Z"
|
||||
android:fillColor="#D7BF2A"/>
|
||||
</group>
|
||||
</vector>
|
37
app/src/main/res/layout/activity_main.xml
Normal file
@ -0,0 +1,37 @@
|
||||
<?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"
|
||||
tools:context=".ui.MainActivity">
|
||||
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
android:id="@+id/swiperefresh"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="4dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/hint"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center"
|
||||
android:padding="16dp"
|
||||
android:text="@string/no_data_hint" />
|
||||
</FrameLayout>
|
||||
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
13
app/src/main/res/layout/activity_preference.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<?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="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/activity_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</LinearLayout>
|
43
app/src/main/res/layout/list_balance.xml
Normal file
@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.cardview.widget.CardView
|
||||
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:cardElevation="4dp"
|
||||
app:cardCornerRadius="4dp"
|
||||
android:layout_marginHorizontal="8dp"
|
||||
android:layout_marginVertical="4dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_margin="8dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/balance"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="12.34" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/date"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:gravity="end"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/balance"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="Now" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
8
app/src/main/res/menu/main_menu.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/preferences"
|
||||
android:title="@string/preferences"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
5
app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background"/>
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
||||
</adaptive-icon>
|
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 4.9 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 8.6 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 12 KiB |
7
app/src/main/res/values-night/themes.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<style name="Theme.App" parent="Theme.App.Base">
|
||||
<item name="android:windowLightStatusBar">false</item>
|
||||
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">false</item>
|
||||
</style>
|
||||
</resources>
|
6
app/src/main/res/values/colors.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
<color name="golden">#D7BF2A</color>
|
||||
</resources>
|
4
app/src/main/res/values/ic_launcher_background.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="ic_launcher_background">#FFFFFF</color>
|
||||
</resources>
|
26
app/src/main/res/values/strings.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<resources>
|
||||
<string name="app_name">Prepaid Balance</string>
|
||||
<string name="ussd_failed">Failed to request USSD code</string>
|
||||
<string name="current_balance">Current balance: %1$,.2f</string>
|
||||
<string name="unable_get_balance">Unable to get balance from response</string>
|
||||
<string name="check_now">Check now</string>
|
||||
<string name="permissions_required">Phone permissions required</string>
|
||||
<string name="preferences">Settings</string>
|
||||
<string name="periodic_checks_title">Periodically check balance</string>
|
||||
<string name="notify_balance_increased_title">Balance increased</string>
|
||||
<string name="notify_balance_under_threshold_title">Balance under threshold</string>
|
||||
<string name="notify_balance_under_threshold_value_title">Threshold</string>
|
||||
<string name="notifications">Notifications</string>
|
||||
<string name="balance_increased">Balance has been increased by %s</string>
|
||||
<string name="threshold_reached">Balance is under threshold: %s</string>
|
||||
<string name="channel_name_balance_increased">Balance increased</string>
|
||||
<string name="channel_name_threshold_reached">Threshold reached</string>
|
||||
<string name="invalid_ussd_code">Invalid USSD code entered. It must start with \'*\' and end with \'#\'.</string>
|
||||
<string name="ussd_code">USSD code</string>
|
||||
<string name="ussd_code_summary">The app queries the USSD code %s to get the current balance</string>
|
||||
<string name="general">General</string>
|
||||
<string name="clear_current_data">Clear all current data</string>
|
||||
<string name="no_data_hint">Swipe down to get your latest prepaid balance. You might want to check the configured USSD code in the settings first.</string>
|
||||
<string name="clear_current_data_summary">Data older than 6 months is deleted automatically</string>
|
||||
<string name="channel_name_error">Error</string>
|
||||
</resources>
|
20
app/src/main/res/values/themes.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<style name="Theme.App.Base" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<item name="colorPrimary">@color/golden</item>
|
||||
<item name="colorPrimaryVariant">@color/golden</item>
|
||||
<item name="colorOnPrimary">@color/white</item>
|
||||
|
||||
<item name="colorSecondary">@color/golden</item>
|
||||
<item name="colorSecondaryVariant">@color/golden</item>
|
||||
<item name="colorOnSecondary">@color/white</item>
|
||||
|
||||
<!--<item name="android:statusBarColor">?android:windowBackground</item>
|
||||
<item name="android:navigationBarColor">?android:windowBackground</item>-->
|
||||
</style>
|
||||
|
||||
<style name="Theme.App" parent="Theme.App.Base">
|
||||
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
|
||||
<item name="android:windowLightStatusBar">true</item>
|
||||
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">true</item>
|
||||
</style>
|
||||
</resources>
|
39
app/src/main/res/xml/pref_main.xml
Normal file
@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<PreferenceCategory
|
||||
android:title="@string/general">
|
||||
<EditTextPreference
|
||||
android:key="ussd_code"
|
||||
android:defaultValue="*100#"
|
||||
android:title="@string/ussd_code" />
|
||||
<SwitchPreferenceCompat
|
||||
android:key="periodic_checks"
|
||||
android:defaultValue="false"
|
||||
android:title="@string/periodic_checks_title" />
|
||||
<Preference
|
||||
android:key="clear_data"
|
||||
android:title="@string/clear_current_data"
|
||||
android:summary="@string/clear_current_data_summary" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/notifications">
|
||||
<SwitchPreferenceCompat
|
||||
android:key="notify_balance_increased"
|
||||
android:defaultValue="false"
|
||||
android:title="@string/notify_balance_increased_title" />
|
||||
<SwitchPreferenceCompat
|
||||
android:key="notify_balance_under_threshold"
|
||||
android:defaultValue="true"
|
||||
android:title="@string/notify_balance_under_threshold_title" />
|
||||
<EditTextPreference
|
||||
android:key="notify_balance_under_threshold_value"
|
||||
android:dependency="notify_balance_under_threshold"
|
||||
android:title="@string/notify_balance_under_threshold_value_title"
|
||||
app:useSimpleSummaryProvider="true"
|
||||
android:inputType="number"
|
||||
android:defaultValue="1.00" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
@ -0,0 +1,34 @@
|
||||
package com.github.muellerma.prepaidbalance
|
||||
|
||||
import com.github.muellerma.prepaidbalance.utils.formatAsCurrency
|
||||
import com.github.muellerma.prepaidbalance.utils.isValidUssdCode
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
class ExtensionFunctionsTest {
|
||||
@Test
|
||||
fun testIsValidUssdCode() {
|
||||
assertFalse("".isValidUssdCode())
|
||||
assertFalse("abc".isValidUssdCode())
|
||||
assertFalse("123".isValidUssdCode())
|
||||
assertFalse("*123".isValidUssdCode())
|
||||
assertFalse("*#".isValidUssdCode())
|
||||
assertFalse("1*123#".isValidUssdCode())
|
||||
assertFalse("*123#1".isValidUssdCode())
|
||||
|
||||
assertTrue("*123#".isValidUssdCode())
|
||||
assertTrue("*1#".isValidUssdCode())
|
||||
assertTrue("*0#".isValidUssdCode())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFormatAsCurrency() {
|
||||
//val dfs = DecimalFormatSymbols(Locale.getDefault()).decimalSeparator
|
||||
val dfs = "," // TODO
|
||||
assertEquals("0${dfs}00", 0.0.formatAsCurrency())
|
||||
assertEquals("42${dfs}00", 42.0.formatAsCurrency())
|
||||
assertEquals("42${dfs}10", 42.1.formatAsCurrency())
|
||||
assertEquals("42${dfs}12", 42.12.formatAsCurrency())
|
||||
assertEquals("42${dfs}12", 42.123.formatAsCurrency())
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.github.muellerma.prepaidbalance
|
||||
|
||||
import com.github.muellerma.prepaidbalance.utils.ResponseParser
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
class ResponseParserTest {
|
||||
@Test
|
||||
fun testGetBalance() {
|
||||
assertEquals(null, ResponseParser.getBalance(null))
|
||||
assertEquals(null, ResponseParser.getBalance(""))
|
||||
assertEquals(null, ResponseParser.getBalance("foobar"))
|
||||
assertEquals(2.42, ResponseParser.getBalance("2.42"))
|
||||
assertEquals(2.42, ResponseParser.getBalance("2,42"))
|
||||
assertEquals(2.42, ResponseParser.getBalance("02,42"))
|
||||
assertEquals(1202.42, ResponseParser.getBalance("1202,42"))
|
||||
assertEquals(1202.0, ResponseParser.getBalance("1202"))
|
||||
assertEquals(1202.0, ResponseParser.getBalance("1202.0"))
|
||||
assertEquals(1202.0, ResponseParser.getBalance("1202.00"))
|
||||
|
||||
assertEquals(5.12, ResponseParser.getBalance("5.12 EUR"))
|
||||
assertEquals(5.12, ResponseParser.getBalance("Current balance is 5.12 EUR"))
|
||||
assertEquals(5.12, ResponseParser.getBalance("Current balance: 5.12 EUR."))
|
||||
assertEquals(5.12, ResponseParser.getBalance("5.12 EUR is the current balance"))
|
||||
assertEquals(5.12, ResponseParser.getBalance("Some ads; 5.12 EUR is the current balance"))
|
||||
assertEquals(5.12, ResponseParser.getBalance("Some ads. 5.12 EUR is the current balance"))
|
||||
assertEquals(5.12, ResponseParser.getBalance("Current balance is 5,12 EUR"))
|
||||
assertEquals(5.12, ResponseParser.getBalance("Current balance is 5.12 EURO"))
|
||||
assertEquals(5.12, ResponseParser.getBalance("Current balance is 5.12 €"))
|
||||
assertEquals(5.12, ResponseParser.getBalance("Current balance is € 5.12"))
|
||||
assertEquals(5.12, ResponseParser.getBalance("Current balance is 5.12 USD"))
|
||||
assertEquals(5.12, ResponseParser.getBalance("Current balance is $ 5.12"))
|
||||
assertEquals(5.12, ResponseParser.getBalance("Current balance is 5.12"))
|
||||
}
|
||||
}
|
30
build.gradle
Normal file
@ -0,0 +1,30 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
buildscript {
|
||||
ext.kotlin_version = "1.4.32"
|
||||
ext.room_version = "2.3.0"
|
||||
ext.workmanager_version = "2.5.0"
|
||||
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
maven { url 'https://jitpack.io' }
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.2.0'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
1
fastlane/metadata/android/en-US/changelogs/2.txt
Normal file
@ -0,0 +1 @@
|
||||
Pre-release
|
2
fastlane/metadata/android/en-US/full_description.txt
Normal file
@ -0,0 +1,2 @@
|
||||
This app keeps track of your prepaid balance. It can automatically record it and post a notification if your balance drops under a configurable threshold.
|
||||
It does so by parsing the response of a USSD code, that can be set in the settings.
|
BIN
fastlane/metadata/android/en-US/images/featureGraphic.png
Normal file
After Width: | Height: | Size: 831 KiB |
BIN
fastlane/metadata/android/en-US/images/icon.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
fastlane/metadata/android/en-US/images/phoneScreenshots/1.png
Normal file
After Width: | Height: | Size: 54 KiB |
1
fastlane/metadata/android/en-US/short_description.txt
Normal file
@ -0,0 +1 @@
|
||||
Keep track your prepaid balance
|
21
gradle.properties
Normal file
@ -0,0 +1,21 @@
|
||||
# Project-wide Gradle settings.
|
||||
# IDE (e.g. Android Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
# AndroidX package structure to make it clearer which packages are bundled with the
|
||||
# Android operating system, and which are packaged with your app"s APK
|
||||
# https://developer.android.com/topic/libraries/support-library/androidx-rn
|
||||
android.useAndroidX=true
|
||||
# Automatically convert third-party libraries to use AndroidX
|
||||
android.enableJetifier=true
|
||||
# Kotlin code style for this project: "official" or "obsolete":
|
||||
kotlin.code.style=official
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
#Fri Apr 30 15:01:23 CEST 2021
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
|
172
gradlew
vendored
Normal file
@ -0,0 +1,172 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
84
gradlew.bat
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
2
settings.gradle
Normal file
@ -0,0 +1,2 @@
|
||||
include ':app'
|
||||
rootProject.name = "Prepaid Balance"
|