Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 83c1ab35d5 | |||
| 7a6563736a | |||
| 55c50c1119 | |||
| ba08968600 | |||
| 79459c373e | |||
| 590298bf5b | |||
| 09bf49a9ce | |||
| 38fb37cde2 | |||
| d0b4e3e163 | |||
| 0cce6b30b1 | |||
| bf650a7565 | |||
| b78cd1dd0d | |||
| 6d9ad8c56c | |||
| e7a3f0cffa | |||
| 6aa72caf6c |
2
.github/workflows/publish.yml
vendored
@@ -8,6 +8,8 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: macOS-latest
|
runs-on: macOS-latest
|
||||||
|
env:
|
||||||
|
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
- name: Install GPG
|
- name: Install GPG
|
||||||
|
|||||||
1
.gitignore
vendored
@@ -5,6 +5,7 @@
|
|||||||
*.swp
|
*.swp
|
||||||
*~.nib
|
*~.nib
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
._.DS_Store
|
||||||
.externalNativeBuild
|
.externalNativeBuild
|
||||||
.gradle
|
.gradle
|
||||||
.idea
|
.idea
|
||||||
|
|||||||
13
CHANGELOG.md
@@ -1,5 +1,18 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
### 1.8.9 (Nov 18, 2020)
|
||||||
|
|
||||||
|
* Remove INTERNET permission
|
||||||
|
* Manage exceptions for when activities don't exist to handle intents (#181)
|
||||||
|
* MemoryHabitList: Inherit parent's order (#598)
|
||||||
|
* Remove notification groups; revert to default system behavior
|
||||||
|
* Remove SyncManager and Internet permission
|
||||||
|
|
||||||
|
### 1.8.8 (June 21, 2020)
|
||||||
|
|
||||||
|
* Make small changes to the habit scheduling algorithm, so that "1 time every x days" habits work more predictably.
|
||||||
|
* Fix crash when saving habit
|
||||||
|
|
||||||
### 1.8.0 (Jan 1, 2020)
|
### 1.8.0 (Jan 1, 2020)
|
||||||
|
|
||||||
* New bar chart showing number of repetitions performed in each week, month, quarter or year.
|
* New bar chart showing number of repetitions performed in each week, month, quarter or year.
|
||||||
|
|||||||
@@ -126,4 +126,18 @@ abstract public class BaseActivity extends AppCompatActivity
|
|||||||
super.onResume();
|
super.onResume();
|
||||||
if(screen != null) screen.reattachDialogs();
|
if(screen != null) screen.reattachDialogs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startActivity(Intent intent)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
super.startActivity(intent);
|
||||||
|
}
|
||||||
|
catch (ActivityNotFoundException e)
|
||||||
|
{
|
||||||
|
if (this.screen != null)
|
||||||
|
this.screen.showMessage(R.string.activity_not_found);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
23
android/android-base/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (C) 2016-2020 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
~
|
||||||
|
~ This file is part of Loop Habit Tracker.
|
||||||
|
~
|
||||||
|
~ Loop Habit Tracker 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.
|
||||||
|
~
|
||||||
|
~ Loop Habit Tracker 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 <http://www.gnu.org/licenses/>.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<resources>
|
||||||
|
<string name="activity_not_found">No app was found to support this action</string>
|
||||||
|
</resources>
|
||||||
377
android/build.sh
@@ -25,294 +25,255 @@ OUTPUTS_DIR=uhabits-android/build/outputs
|
|||||||
VERSION=$(cat gradle.properties | grep VERSION_NAME | sed -e 's/.*=//g;s/ //g')
|
VERSION=$(cat gradle.properties | grep VERSION_NAME | sed -e 's/.*=//g;s/ //g')
|
||||||
|
|
||||||
if [ ! -f "${ANDROID_HOME}/platform-tools/adb" ]; then
|
if [ ! -f "${ANDROID_HOME}/platform-tools/adb" ]; then
|
||||||
echo "Error: ANDROID_HOME is not set correctly"
|
echo "Error: ANDROID_HOME is not set correctly"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log_error() {
|
log_error() {
|
||||||
if [ ! -z "$TEAMCITY_VERSION" ]; then
|
if [ ! -z "$TEAMCITY_VERSION" ]; then
|
||||||
echo "###teamcity[progressMessage '$1']"
|
echo "###teamcity[progressMessage '$1']"
|
||||||
else
|
else
|
||||||
local COLOR='\033[1;31m'
|
local COLOR='\033[1;31m'
|
||||||
local NC='\033[0m'
|
local NC='\033[0m'
|
||||||
echo -e "$COLOR>>> $1 $NC"
|
echo -e "$COLOR>>> $1 $NC"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
log_info() {
|
log_info() {
|
||||||
if [ ! -z "$TEAMCITY_VERSION" ]; then
|
if [ ! -z "$TEAMCITY_VERSION" ]; then
|
||||||
echo "###teamcity[progressMessage '$1']"
|
echo "###teamcity[progressMessage '$1']"
|
||||||
else
|
else
|
||||||
local COLOR='\033[1;32m'
|
local COLOR='\033[1;32m'
|
||||||
local NC='\033[0m'
|
local NC='\033[0m'
|
||||||
echo -e "$COLOR>>> $1 $NC"
|
echo -e "$COLOR>>> $1 $NC"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
fail() {
|
fail() {
|
||||||
if [ ! -z ${AVD_NAME} ]; then
|
log_error "BUILD FAILED"
|
||||||
stop_emulator
|
exit 1
|
||||||
stop_gradle_daemon
|
|
||||||
fi
|
|
||||||
log_error "BUILD FAILED"
|
|
||||||
exit 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ ! -z $RELEASE ]; then
|
if [ ! -z $RELEASE ]; then
|
||||||
log_info "Reading secret env variables from ../.secret/env"
|
log_info "Reading secret env variables from ../.secret/env"
|
||||||
source ../.secret/env || fail
|
source ../.secret/env || fail
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
start_emulator() {
|
|
||||||
log_info "Starting emulator ($AVD_NAME)"
|
|
||||||
$EMULATOR -avd ${AVD_NAME} -port ${AVD_SERIAL} -no-audio -no-window &
|
|
||||||
$ADB wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done; input keyevent 82'
|
|
||||||
}
|
|
||||||
|
|
||||||
stop_emulator() {
|
|
||||||
log_info "Stopping emulator"
|
|
||||||
$ADB emu kill
|
|
||||||
}
|
|
||||||
|
|
||||||
stop_gradle_daemon() {
|
|
||||||
log_info "Stopping gradle daemon"
|
|
||||||
$GRADLE --stop
|
|
||||||
}
|
|
||||||
|
|
||||||
run_adb_as_root() {
|
run_adb_as_root() {
|
||||||
log_info "Running adb as root"
|
log_info "Running adb as root"
|
||||||
$ADB root
|
$ADB root
|
||||||
}
|
}
|
||||||
|
|
||||||
build_apk() {
|
build_apk() {
|
||||||
log_info "Removing old APKs..."
|
log_info "Removing old APKs..."
|
||||||
rm -vf build/*.apk
|
rm -vf build/*.apk
|
||||||
|
|
||||||
if [ ! -z $RELEASE ]; then
|
if [ ! -z $RELEASE ]; then
|
||||||
log_info "Building release APK"
|
log_info "Building release APK"
|
||||||
./gradlew assembleRelease
|
./gradlew assembleRelease
|
||||||
cp -v uhabits-android/build/outputs/apk/release/uhabits-android-release.apk build/loop-$VERSION-release.apk
|
cp -v uhabits-android/build/outputs/apk/release/uhabits-android-release.apk build/loop-$VERSION-release.apk
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log_info "Building debug APK"
|
log_info "Building debug APK"
|
||||||
./gradlew assembleDebug || fail
|
./gradlew assembleDebug || fail
|
||||||
cp -v uhabits-android/build/outputs/apk/debug/uhabits-android-debug.apk build/loop-$VERSION-debug.apk
|
cp -v uhabits-android/build/outputs/apk/debug/uhabits-android-debug.apk build/loop-$VERSION-debug.apk
|
||||||
}
|
}
|
||||||
|
|
||||||
build_instrumentation_apk() {
|
build_instrumentation_apk() {
|
||||||
log_info "Building instrumentation APK"
|
log_info "Building instrumentation APK"
|
||||||
if [ ! -z $RELEASE ]; then
|
if [ ! -z $RELEASE ]; then
|
||||||
$GRADLE assembleAndroidTest \
|
$GRADLE assembleAndroidTest \
|
||||||
-Pandroid.injected.signing.store.file=$LOOP_KEY_STORE \
|
-Pandroid.injected.signing.store.file=$LOOP_KEY_STORE \
|
||||||
-Pandroid.injected.signing.store.password=$LOOP_STORE_PASSWORD \
|
-Pandroid.injected.signing.store.password=$LOOP_STORE_PASSWORD \
|
||||||
-Pandroid.injected.signing.key.alias=$LOOP_KEY_ALIAS \
|
-Pandroid.injected.signing.key.alias=$LOOP_KEY_ALIAS \
|
||||||
-Pandroid.injected.signing.key.password=$LOOP_KEY_PASSWORD || fail
|
-Pandroid.injected.signing.key.password=$LOOP_KEY_PASSWORD || fail
|
||||||
else
|
else
|
||||||
$GRADLE assembleAndroidTest || fail
|
$GRADLE assembleAndroidTest || fail
|
||||||
fi
|
fi
|
||||||
}
|
|
||||||
|
|
||||||
clean_output_dir() {
|
|
||||||
log_info "Cleaning output directory"
|
|
||||||
rm -rf ${OUTPUTS_DIR}
|
|
||||||
mkdir -p ${OUTPUTS_DIR}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uninstall_apk() {
|
uninstall_apk() {
|
||||||
log_info "Uninstalling existing APK"
|
log_info "Uninstalling existing APK"
|
||||||
$ADB uninstall ${PACKAGE_NAME}
|
$ADB uninstall ${PACKAGE_NAME}
|
||||||
}
|
}
|
||||||
|
|
||||||
install_test_butler() {
|
install_test_butler() {
|
||||||
log_info "Installing Test Butler"
|
log_info "Installing Test Butler"
|
||||||
$ADB uninstall com.linkedin.android.testbutler
|
$ADB uninstall com.linkedin.android.testbutler
|
||||||
$ADB install tools/test-butler-app-2.0.2.apk
|
$ADB install tools/test-butler-app-2.0.2.apk
|
||||||
}
|
}
|
||||||
|
|
||||||
install_apk() {
|
install_apk() {
|
||||||
log_info "Installing APK"
|
log_info "Installing APK"
|
||||||
if [ ! -z $RELEASE ]; then
|
if [ ! -z $RELEASE ]; then
|
||||||
$ADB install -r ${OUTPUTS_DIR}/apk/release/uhabits-android-release.apk || fail
|
$ADB install -r ${OUTPUTS_DIR}/apk/release/uhabits-android-release.apk || fail
|
||||||
else
|
else
|
||||||
$ADB install -t -r ${OUTPUTS_DIR}/apk/debug/uhabits-android-debug.apk || fail
|
$ADB install -t -r ${OUTPUTS_DIR}/apk/debug/uhabits-android-debug.apk || fail
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
install_test_apk() {
|
install_test_apk() {
|
||||||
log_info "Uninstalling existing test APK"
|
log_info "Uninstalling existing test APK"
|
||||||
$ADB uninstall ${PACKAGE_NAME}.test
|
$ADB uninstall ${PACKAGE_NAME}.test
|
||||||
|
|
||||||
log_info "Installing test APK"
|
log_info "Installing test APK"
|
||||||
$ADB install -r ${OUTPUTS_DIR}/apk/androidTest/debug/uhabits-android-debug-androidTest.apk || fail
|
$ADB install -r ${OUTPUTS_DIR}/apk/androidTest/debug/uhabits-android-debug-androidTest.apk || fail
|
||||||
}
|
}
|
||||||
|
|
||||||
run_instrumented_tests() {
|
run_instrumented_tests() {
|
||||||
SIZE=$1
|
SIZE=$1
|
||||||
log_info "Running instrumented tests"
|
log_info "Running instrumented tests"
|
||||||
$ADB shell am instrument \
|
$ADB shell am instrument \
|
||||||
-r -e coverage true -e size $SIZE \
|
-r -e coverage true -e size $SIZE \
|
||||||
-w ${PACKAGE_NAME}.test/android.support.test.runner.AndroidJUnitRunner \
|
-w ${PACKAGE_NAME}.test/androidx.test.runner.AndroidJUnitRunner \
|
||||||
| tee ${OUTPUTS_DIR}/instrument.txt
|
| tee ${OUTPUTS_DIR}/instrument.txt
|
||||||
|
|
||||||
if grep FAILURES $OUTPUTS_DIR/instrument.txt; then
|
if grep "\(INSTRUMENTATION_STATUS_CODE.*-1\|FAILURES\)" $OUTPUTS_DIR/instrument.txt; then
|
||||||
log_error "Some instrumented tests failed"
|
log_error "Some instrumented tests failed"
|
||||||
fetch_images
|
fetch_images
|
||||||
fetch_logcat
|
fetch_logcat
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#mkdir -p ${OUTPUTS_DIR}/code-coverage/connected/
|
#mkdir -p ${OUTPUTS_DIR}/code-coverage/connected/
|
||||||
#$ADB pull /data/user/0/${PACKAGE_NAME}/files/coverage.ec \
|
#$ADB pull /data/user/0/${PACKAGE_NAME}/files/coverage.ec \
|
||||||
# ${OUTPUTS_DIR}/code-coverage/connected/ \
|
# ${OUTPUTS_DIR}/code-coverage/connected/ \
|
||||||
# || log_error "COVERAGE REPORT NOT AVAILABLE"
|
# || log_error "COVERAGE REPORT NOT AVAILABLE"
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_instrumentation_results() {
|
parse_instrumentation_results() {
|
||||||
log_info "Parsing instrumented test results"
|
log_info "Parsing instrumented test results"
|
||||||
java -jar tools/automator-log-converter-1.5.0.jar ${OUTPUTS_DIR}/instrument.txt || fail
|
java -jar tools/automator-log-converter-1.5.0.jar ${OUTPUTS_DIR}/instrument.txt || fail
|
||||||
}
|
}
|
||||||
|
|
||||||
generate_coverage_badge() {
|
generate_coverage_badge() {
|
||||||
log_info "Generating code coverage badge"
|
log_info "Generating code coverage badge"
|
||||||
CORE_REPORT=uhabits-core/build/reports/jacoco/test/jacocoTestReport.xml
|
CORE_REPORT=uhabits-core/build/reports/jacoco/test/jacocoTestReport.xml
|
||||||
rm -f ${OUTPUTS_DIR}/coverage-badge.svg
|
rm -f ${OUTPUTS_DIR}/coverage-badge.svg
|
||||||
python3 tools/coverage-badge/badge.py -i $CORE_REPORT -o ${OUTPUTS_DIR}/coverage-badge
|
python3 tools/coverage-badge/badge.py -i $CORE_REPORT -o ${OUTPUTS_DIR}/coverage-badge
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch_logcat() {
|
fetch_logcat() {
|
||||||
log_info "Fetching logcat"
|
log_info "Fetching logcat"
|
||||||
$ADB logcat -d > ${OUTPUTS_DIR}/logcat.txt
|
$ADB logcat -d > ${OUTPUTS_DIR}/logcat.txt
|
||||||
}
|
}
|
||||||
|
|
||||||
run_jvm_tests() {
|
run_jvm_tests() {
|
||||||
log_info "Running JVM tests"
|
log_info "Running JVM tests"
|
||||||
if [ ! -z $RELEASE ]; then
|
if [ ! -z $RELEASE ]; then
|
||||||
$GRADLE testReleaseUnitTest :uhabits-core:check || fail
|
$GRADLE testReleaseUnitTest :uhabits-core:check || fail
|
||||||
else
|
else
|
||||||
$GRADLE testDebugUnitTest :uhabits-core:check || fail
|
$GRADLE testDebugUnitTest :uhabits-core:check || fail
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
uninstall_test_apk() {
|
uninstall_test_apk() {
|
||||||
log_info "Uninstalling test APK"
|
log_info "Uninstalling test APK"
|
||||||
$ADB uninstall ${PACKAGE_NAME}.test
|
$ADB uninstall ${PACKAGE_NAME}.test
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch_images() {
|
fetch_images() {
|
||||||
log_info "Fetching images"
|
log_info "Fetching images"
|
||||||
rm -rf $OUTPUTS_DIR/test-screenshots
|
rm -rf $OUTPUTS_DIR/test-screenshots
|
||||||
$ADB pull /sdcard/Android/data/${PACKAGE_NAME}/files/test-screenshots/ $OUTPUTS_DIR
|
$ADB pull /sdcard/Android/data/${PACKAGE_NAME}/files/test-screenshots/ $OUTPUTS_DIR
|
||||||
$ADB shell rm -r /sdcard/Android/data/${PACKAGE_NAME}/files/test-screenshots/
|
$ADB shell rm -r /sdcard/Android/data/${PACKAGE_NAME}/files/test-screenshots/
|
||||||
}
|
}
|
||||||
|
|
||||||
accept_images() {
|
accept_images() {
|
||||||
find tmp/test-screenshots -name '*.expected*' -delete
|
find $OUTPUTS_DIR/test-screenshots -name '*.expected*' -delete
|
||||||
rsync -av tmp/test-screenshots/ uhabits-android/src/androidTest/assets/
|
rsync -av $OUTPUTS_DIR/test-screenshots/ uhabits-android/src/androidTest/assets/
|
||||||
}
|
}
|
||||||
|
|
||||||
run_tests() {
|
run_tests() {
|
||||||
SIZE=$1
|
SIZE=$1
|
||||||
run_adb_as_root
|
run_adb_as_root
|
||||||
install_test_butler
|
install_test_butler
|
||||||
uninstall_apk
|
uninstall_apk
|
||||||
install_apk
|
install_apk
|
||||||
install_test_apk
|
install_test_apk
|
||||||
run_instrumented_tests $SIZE
|
run_instrumented_tests $SIZE
|
||||||
parse_instrumentation_results
|
parse_instrumentation_results
|
||||||
fetch_logcat
|
fetch_logcat
|
||||||
uninstall_test_apk
|
uninstall_test_apk
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_opts() {
|
parse_opts() {
|
||||||
OPTS=`getopt -o ur --long uninstall-first,release -n 'build.sh' -- "$@"`
|
OPTS=`getopt -o r --long release -n 'build.sh' -- "$@"`
|
||||||
if [ $? != 0 ] ; then exit 1; fi
|
if [ $? != 0 ] ; then exit 1; fi
|
||||||
eval set -- "$OPTS"
|
eval set -- "$OPTS"
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-u | --uninstall-first ) UNINSTALL_FIRST=1; shift ;;
|
-r | --release ) RELEASE=1; shift ;;
|
||||||
-r | --release ) RELEASE=1; shift ;;
|
* ) break ;;
|
||||||
* ) break ;;
|
esac
|
||||||
esac
|
done
|
||||||
done
|
}
|
||||||
|
|
||||||
|
remove_build_dir() {
|
||||||
|
rm -rfv build
|
||||||
|
rm -rfv android-base/build
|
||||||
|
rm -rfv android-pickers/build
|
||||||
|
rm -rfv uhabits-android/build
|
||||||
|
rm -rfv uhabits-core/build
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
build)
|
build)
|
||||||
shift; parse_opts $*
|
shift; parse_opts $*
|
||||||
|
|
||||||
build_apk
|
build_apk
|
||||||
build_instrumentation_apk
|
build_instrumentation_apk
|
||||||
run_jvm_tests
|
run_jvm_tests
|
||||||
#generate_coverage_badge
|
#generate_coverage_badge
|
||||||
;;
|
;;
|
||||||
|
|
||||||
ci-tests)
|
medium-tests)
|
||||||
if [ -z $3 ]; then
|
shift; parse_opts $*
|
||||||
cat <<- END
|
run_tests medium
|
||||||
Usage: $0 ci-tests AVD_NAME AVD_SERIAL [options]
|
;;
|
||||||
|
|
||||||
Parameters:
|
large-tests)
|
||||||
AVD_NAME name of the virtual android device to start
|
shift; parse_opts $*
|
||||||
AVD_SERIAL adb port to use (e.g. 5560)
|
run_tests large
|
||||||
|
;;
|
||||||
|
|
||||||
Options:
|
fetch-images)
|
||||||
-u --uninstall-first Uninstall existing APK first
|
fetch_images
|
||||||
-r --release Test release APK, instead of debug
|
;;
|
||||||
END
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
shift; AVD_NAME=$1
|
accept-images)
|
||||||
shift; AVD_SERIAL=$1
|
accept_images
|
||||||
shift; parse_opts $*
|
;;
|
||||||
ADB="${ADB} -s emulator-${AVD_SERIAL}"
|
|
||||||
|
|
||||||
start_emulator
|
install)
|
||||||
run_tests medium
|
shift; parse_opts $*
|
||||||
stop_emulator
|
build_apk
|
||||||
stop_gradle_daemon
|
install_apk
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
clean)
|
||||||
|
remove_build_dir
|
||||||
|
;;
|
||||||
|
|
||||||
medium-tests)
|
*)
|
||||||
shift; parse_opts $*
|
cat <<END
|
||||||
run_tests medium
|
Usage: $0 <command> [options]
|
||||||
;;
|
Builds, installs and tests Loop Habit Tracker
|
||||||
|
|
||||||
large-tests)
|
Commands:
|
||||||
shift; parse_opts $*
|
accept-images Copies fetched images to corresponding assets folder
|
||||||
run_tests large
|
build Build APK and run JVM tests
|
||||||
;;
|
clean Remove build directory
|
||||||
|
fetch-images Fetches failed view test images from device
|
||||||
|
install Install app on connected device
|
||||||
|
large-tests Run large-sized tests on connected device
|
||||||
|
medium-tests Run medium-sized tests on connected device
|
||||||
|
|
||||||
fetch-images)
|
Options:
|
||||||
fetch_images
|
-r --release Build and test release APK, instead of debug
|
||||||
;;
|
END
|
||||||
|
exit 1
|
||||||
accept-images)
|
;;
|
||||||
accept_images
|
|
||||||
;;
|
|
||||||
|
|
||||||
install)
|
|
||||||
shift; parse_opts $*
|
|
||||||
build_apk
|
|
||||||
install_apk
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
cat <<- END
|
|
||||||
Usage: $0 <command> [options]
|
|
||||||
Builds, installs and tests Loop Habit Tracker
|
|
||||||
|
|
||||||
Commands:
|
|
||||||
ci-tests Start emulator silently, run tests then kill emulator
|
|
||||||
local-tests Run all tests on connected device
|
|
||||||
install Install app on connected device
|
|
||||||
fetch-images Fetches failed view test images from device
|
|
||||||
accept-images Copies fetched images to corresponding assets folder
|
|
||||||
|
|
||||||
Options:
|
|
||||||
-r --release Build and test release APK, instead of debug
|
|
||||||
END
|
|
||||||
exit 1
|
|
||||||
esac
|
esac
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
VERSION_CODE = 50
|
VERSION_CODE = 52
|
||||||
VERSION_NAME = 1.8.7
|
VERSION_NAME = 1.8.9
|
||||||
|
|
||||||
MIN_SDK_VERSION = 21
|
MIN_SDK_VERSION = 21
|
||||||
TARGET_SDK_VERSION = 29
|
TARGET_SDK_VERSION = 29
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 61 KiB |
|
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 58 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 31 KiB |
@@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker 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.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.isoron.uhabits.tasks;
|
|
||||||
|
|
||||||
import androidx.test.filters.*;
|
|
||||||
import androidx.test.runner.*;
|
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.*;
|
|
||||||
import org.junit.*;
|
|
||||||
import org.junit.runner.*;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
|
||||||
@MediumTest
|
|
||||||
public class ExportCSVTaskTest extends BaseAndroidTest
|
|
||||||
{
|
|
||||||
@Before
|
|
||||||
@Override
|
|
||||||
public void setUp()
|
|
||||||
{
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
// public void testExportCSV() throws Throwable
|
|
||||||
// {
|
|
||||||
// fixtures.purgeHabits(habitList);
|
|
||||||
// fixtures.createShortHabit();
|
|
||||||
//
|
|
||||||
// List<Habit> selected = new LinkedList<>();
|
|
||||||
// for (Habit h : habitList) selected.add(h);
|
|
||||||
// File outputDir = new AndroidDirFinder(targetContext).getFilesDir("CSV");
|
|
||||||
// assertNotNull(outputDir);
|
|
||||||
//
|
|
||||||
// taskRunner.execute(
|
|
||||||
// new ExportCSVTask(habitList, selected, outputDir, archiveFilename -> {
|
|
||||||
// assertThat(archiveFilename, is(not(nullValue())));
|
|
||||||
// File f = new File(archiveFilename);
|
|
||||||
// assertTrue(f.exists());
|
|
||||||
// assertTrue(f.canRead());
|
|
||||||
// }));
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker 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.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.isoron.uhabits.tasks;
|
|
||||||
|
|
||||||
import androidx.test.filters.*;
|
|
||||||
import androidx.test.runner.*;
|
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.*;
|
|
||||||
import org.junit.*;
|
|
||||||
import org.junit.runner.*;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
|
||||||
@MediumTest
|
|
||||||
public class ExportDBTaskTest extends BaseAndroidTest
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
@Before
|
|
||||||
public void setUp()
|
|
||||||
{
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
// public void testExportCSV() throws Throwable
|
|
||||||
// {
|
|
||||||
// ExportDBTask task =
|
|
||||||
// new ExportDBTask(targetContext, new AndroidDirFinder(targetContext),
|
|
||||||
// filename ->
|
|
||||||
// {
|
|
||||||
// assertNotNull(filename);
|
|
||||||
// File f = new File(filename);
|
|
||||||
// assertTrue(f.exists());
|
|
||||||
// assertTrue(f.canRead());
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// taskRunner.execute(task);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
@@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
@@ -218,12 +216,6 @@
|
|||||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
android:resource="@xml/file_paths"/>
|
android:resource="@xml/file_paths"/>
|
||||||
</provider>
|
</provider>
|
||||||
|
|
||||||
<service
|
|
||||||
android:name=".sync.SyncService"
|
|
||||||
android:enabled="true"
|
|
||||||
android:exported="false">
|
|
||||||
</service>
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -34,7 +34,6 @@ import org.isoron.uhabits.core.ui.screens.habits.list.*;
|
|||||||
import org.isoron.uhabits.core.utils.*;
|
import org.isoron.uhabits.core.utils.*;
|
||||||
import org.isoron.uhabits.intents.*;
|
import org.isoron.uhabits.intents.*;
|
||||||
import org.isoron.uhabits.receivers.*;
|
import org.isoron.uhabits.receivers.*;
|
||||||
import org.isoron.uhabits.sync.*;
|
|
||||||
import org.isoron.uhabits.tasks.*;
|
import org.isoron.uhabits.tasks.*;
|
||||||
import org.isoron.uhabits.widgets.*;
|
import org.isoron.uhabits.widgets.*;
|
||||||
|
|
||||||
@@ -81,8 +80,6 @@ public interface HabitsApplicationComponent
|
|||||||
|
|
||||||
ReminderController getReminderController();
|
ReminderController getReminderController();
|
||||||
|
|
||||||
SyncManager getSyncManager();
|
|
||||||
|
|
||||||
TaskRunner getTaskRunner();
|
TaskRunner getTaskRunner();
|
||||||
|
|
||||||
WidgetPreferences getWidgetPreferences();
|
WidgetPreferences getWidgetPreferences();
|
||||||
|
|||||||
@@ -57,7 +57,13 @@ public class TargetPanel extends FrameLayout
|
|||||||
public double getTargetValue()
|
public double getTargetValue()
|
||||||
{
|
{
|
||||||
String sValue = tvTargetValue.getText().toString();
|
String sValue = tvTargetValue.getText().toString();
|
||||||
return Double.parseDouble(sValue);
|
double value = 0;
|
||||||
|
try {
|
||||||
|
value = Double.parseDouble(sValue);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// NOP
|
||||||
|
}
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTargetValue(double targetValue)
|
public void setTargetValue(double targetValue)
|
||||||
|
|||||||
@@ -155,8 +155,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
// Temporarily disable this; we now always ask
|
// Temporarily disable this; we now always ask
|
||||||
findPreference("reminderSound").setVisible(false);
|
findPreference("reminderSound").setVisible(false);
|
||||||
findPreference("pref_snooze_interval").setVisible(false);
|
findPreference("pref_snooze_interval").setVisible(false);
|
||||||
|
|
||||||
updateSync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateWeekdayPreference()
|
private void updateWeekdayPreference()
|
||||||
@@ -183,7 +181,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
}
|
}
|
||||||
if (key.equals("pref_first_weekday")) updateWeekdayPreference();
|
if (key.equals("pref_first_weekday")) updateWeekdayPreference();
|
||||||
BackupManager.dataChanged("org.isoron.uhabits");
|
BackupManager.dataChanged("org.isoron.uhabits");
|
||||||
updateSync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setResultOnPreferenceClick(String key, final int result)
|
private void setResultOnPreferenceClick(String key, final int result)
|
||||||
@@ -218,24 +215,4 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
Preference ringtonePreference = findPreference("reminderSound");
|
Preference ringtonePreference = findPreference("reminderSound");
|
||||||
ringtonePreference.setSummary(ringtoneName);
|
ringtonePreference.setSummary(ringtoneName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSync()
|
|
||||||
{
|
|
||||||
if (prefs == null) return;
|
|
||||||
boolean enabled = prefs.isSyncEnabled();
|
|
||||||
|
|
||||||
Preference syncKey = findPreference("pref_sync_key");
|
|
||||||
if (syncKey != null)
|
|
||||||
{
|
|
||||||
syncKey.setSummary(prefs.getSyncKey());
|
|
||||||
syncKey.setVisible(enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
Preference syncAddress = findPreference("pref_sync_address");
|
|
||||||
if (syncAddress != null)
|
|
||||||
{
|
|
||||||
syncAddress.setSummary(prefs.getSyncAddress());
|
|
||||||
syncAddress.setVisible(enabled);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,6 @@ class AndroidNotificationTray
|
|||||||
Log.d("AndroidNotificationTray", msg)
|
Log.d("AndroidNotificationTray", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun removeNotification(id: Int) {
|
override fun removeNotification(id: Int) {
|
||||||
val manager = NotificationManagerCompat.from(context)
|
val manager = NotificationManagerCompat.from(context)
|
||||||
manager.cancel(id)
|
manager.cancel(id)
|
||||||
@@ -63,8 +62,6 @@ class AndroidNotificationTray
|
|||||||
timestamp: Timestamp,
|
timestamp: Timestamp,
|
||||||
reminderTime: Long) {
|
reminderTime: Long) {
|
||||||
val notificationManager = NotificationManagerCompat.from(context)
|
val notificationManager = NotificationManagerCompat.from(context)
|
||||||
//val summary = buildSummary(habit, reminderTime)
|
|
||||||
//notificationManager.notify(Int.MAX_VALUE, summary)
|
|
||||||
val notification = buildNotification(habit, reminderTime, timestamp)
|
val notification = buildNotification(habit, reminderTime, timestamp)
|
||||||
createAndroidNotificationChannel(context)
|
createAndroidNotificationChannel(context)
|
||||||
try {
|
try {
|
||||||
@@ -109,7 +106,7 @@ class AndroidNotificationTray
|
|||||||
.addAction(removeRepetitionAction)
|
.addAction(removeRepetitionAction)
|
||||||
|
|
||||||
val defaultText = context.getString(R.string.default_reminder_question)
|
val defaultText = context.getString(R.string.default_reminder_question)
|
||||||
val builder = NotificationCompat.Builder(context, REMINDERS_CHANNEL_ID)
|
val builder = Builder(context, REMINDERS_CHANNEL_ID)
|
||||||
.setSmallIcon(R.drawable.ic_notification)
|
.setSmallIcon(R.drawable.ic_notification)
|
||||||
.setContentTitle(habit.name)
|
.setContentTitle(habit.name)
|
||||||
.setContentText(if(habit.description.isBlank()) defaultText else habit.description)
|
.setContentText(if(habit.description.isBlank()) defaultText else habit.description)
|
||||||
@@ -121,7 +118,6 @@ class AndroidNotificationTray
|
|||||||
.setWhen(reminderTime)
|
.setWhen(reminderTime)
|
||||||
.setShowWhen(true)
|
.setShowWhen(true)
|
||||||
.setOngoing(preferences.shouldMakeNotificationsSticky())
|
.setOngoing(preferences.shouldMakeNotificationsSticky())
|
||||||
.setGroup("group" + habit.getId())
|
|
||||||
|
|
||||||
if (!disableSound)
|
if (!disableSound)
|
||||||
builder.setSound(ringtoneManager.getURI())
|
builder.setSound(ringtoneManager.getURI())
|
||||||
@@ -139,18 +135,6 @@ class AndroidNotificationTray
|
|||||||
return builder.build()
|
return builder.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildSummary(habit: Habit,
|
|
||||||
reminderTime: Long): Notification {
|
|
||||||
return NotificationCompat.Builder(context, REMINDERS_CHANNEL_ID)
|
|
||||||
.setSmallIcon(R.drawable.ic_notification)
|
|
||||||
.setContentTitle(context.getString(R.string.app_name))
|
|
||||||
.setWhen(reminderTime)
|
|
||||||
.setShowWhen(true)
|
|
||||||
.setGroup("group" + habit.getId())
|
|
||||||
.setGroupSummary(true)
|
|
||||||
.build()
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val REMINDERS_CHANNEL_ID = "REMINDERS"
|
private const val REMINDERS_CHANNEL_ID = "REMINDERS"
|
||||||
fun createAndroidNotificationChannel(context: Context) {
|
fun createAndroidNotificationChannel(context: Context) {
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker 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.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.isoron.uhabits.receivers
|
|
||||||
|
|
||||||
import android.content.*
|
|
||||||
import android.content.Context.*
|
|
||||||
import android.net.*
|
|
||||||
import org.isoron.uhabits.*
|
|
||||||
|
|
||||||
class ConnectivityReceiver : BroadcastReceiver() {
|
|
||||||
override fun onReceive(context: Context?, intent: Intent?) {
|
|
||||||
if (context == null || intent == null) return
|
|
||||||
val app = context.applicationContext as HabitsApplication
|
|
||||||
val networkInfo = (context.getSystemService(CONNECTIVITY_SERVICE)
|
|
||||||
as ConnectivityManager).activeNetworkInfo
|
|
||||||
val isConnected = (networkInfo != null) &&
|
|
||||||
networkInfo.isConnectedOrConnecting
|
|
||||||
val syncManager = app.component.syncManager
|
|
||||||
syncManager.onNetworkStatusChanged(isConnected)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -26,7 +26,6 @@ import org.isoron.uhabits.*;
|
|||||||
import org.isoron.uhabits.core.preferences.*;
|
import org.isoron.uhabits.core.preferences.*;
|
||||||
import org.isoron.uhabits.core.ui.widgets.*;
|
import org.isoron.uhabits.core.ui.widgets.*;
|
||||||
import org.isoron.uhabits.intents.*;
|
import org.isoron.uhabits.intents.*;
|
||||||
import org.isoron.uhabits.sync.*;
|
|
||||||
|
|
||||||
import dagger.*;
|
import dagger.*;
|
||||||
|
|
||||||
@@ -68,9 +67,6 @@ public class WidgetReceiver extends BroadcastReceiver
|
|||||||
|
|
||||||
Log.i(TAG, String.format("Received intent: %s", intent.toString()));
|
Log.i(TAG, String.format("Received intent: %s", intent.toString()));
|
||||||
|
|
||||||
if (prefs.isSyncEnabled())
|
|
||||||
context.startService(new Intent(context, SyncService.class));
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IntentParser.CheckmarkIntentData data;
|
IntentParser.CheckmarkIntentData data;
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker 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.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.isoron.uhabits.sync;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.core.database.*;
|
|
||||||
|
|
||||||
@Table(name = "Events")
|
|
||||||
public class Event
|
|
||||||
{
|
|
||||||
@Nullable
|
|
||||||
@Column
|
|
||||||
public Long id;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Column(name = "timestamp")
|
|
||||||
public Long timestamp;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Column(name = "message")
|
|
||||||
public String message;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Column(name = "server_id")
|
|
||||||
public String serverId;
|
|
||||||
|
|
||||||
public Event()
|
|
||||||
{
|
|
||||||
timestamp = 0L;
|
|
||||||
message = "";
|
|
||||||
serverId = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public Event(@NonNull String serverId, long timestamp, @NonNull String message)
|
|
||||||
{
|
|
||||||
this.serverId = serverId;
|
|
||||||
this.timestamp = timestamp;
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,380 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker 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.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.isoron.uhabits.sync;
|
|
||||||
|
|
||||||
import android.util.*;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.isoron.androidbase.*;
|
|
||||||
import org.isoron.uhabits.BuildConfig;
|
|
||||||
import org.isoron.uhabits.core.*;
|
|
||||||
import org.isoron.uhabits.core.commands.*;
|
|
||||||
import org.isoron.uhabits.core.database.*;
|
|
||||||
import org.isoron.uhabits.core.preferences.*;
|
|
||||||
import org.isoron.uhabits.database.*;
|
|
||||||
import org.isoron.uhabits.utils.*;
|
|
||||||
import org.json.*;
|
|
||||||
|
|
||||||
import java.net.*;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import javax.inject.*;
|
|
||||||
|
|
||||||
import io.socket.client.*;
|
|
||||||
import io.socket.client.Socket;
|
|
||||||
import io.socket.emitter.*;
|
|
||||||
|
|
||||||
import static io.socket.client.Socket.EVENT_CONNECT;
|
|
||||||
import static io.socket.client.Socket.EVENT_CONNECTING;
|
|
||||||
import static io.socket.client.Socket.EVENT_CONNECT_ERROR;
|
|
||||||
import static io.socket.client.Socket.EVENT_CONNECT_TIMEOUT;
|
|
||||||
import static io.socket.client.Socket.EVENT_DISCONNECT;
|
|
||||||
import static io.socket.client.Socket.EVENT_PING;
|
|
||||||
import static io.socket.client.Socket.EVENT_PONG;
|
|
||||||
import static io.socket.client.Socket.EVENT_RECONNECT;
|
|
||||||
import static io.socket.client.Socket.EVENT_RECONNECT_ATTEMPT;
|
|
||||||
import static io.socket.client.Socket.EVENT_RECONNECT_ERROR;
|
|
||||||
import static io.socket.client.Socket.EVENT_RECONNECT_FAILED;
|
|
||||||
|
|
||||||
@AppScope
|
|
||||||
public class SyncManager implements CommandRunner.Listener
|
|
||||||
{
|
|
||||||
public static final String EVENT_AUTH = "auth";
|
|
||||||
|
|
||||||
public static final String EVENT_AUTH_OK = "authOK";
|
|
||||||
|
|
||||||
public static final String EVENT_EXECUTE_EVENT = "execute";
|
|
||||||
|
|
||||||
public static final String EVENT_FETCH = "fetch";
|
|
||||||
|
|
||||||
public static final String EVENT_FETCH_OK = "fetchOK";
|
|
||||||
|
|
||||||
public static final String EVENT_POST_EVENT = "postEvent";
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private String clientId;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private String groupKey;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private Socket socket;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private LinkedList<Event> pendingConfirmation;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private LinkedList<Event> pendingEmit;
|
|
||||||
|
|
||||||
private boolean readyToEmit = false;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private final Preferences prefs;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private CommandRunner commandRunner;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private CommandParser commandParser;
|
|
||||||
|
|
||||||
private boolean isListening;
|
|
||||||
|
|
||||||
private SSLContextProvider sslProvider;
|
|
||||||
|
|
||||||
private final Repository<Event> repository;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public SyncManager(@NonNull SSLContextProvider sslProvider,
|
|
||||||
@NonNull Preferences prefs,
|
|
||||||
@NonNull CommandRunner commandRunner,
|
|
||||||
@NonNull CommandParser commandParser)
|
|
||||||
{
|
|
||||||
Log.i("SyncManager", this.toString());
|
|
||||||
|
|
||||||
this.sslProvider = sslProvider;
|
|
||||||
this.prefs = prefs;
|
|
||||||
this.commandRunner = commandRunner;
|
|
||||||
this.commandParser = commandParser;
|
|
||||||
this.isListening = false;
|
|
||||||
|
|
||||||
repository = new Repository<>(Event.class,
|
|
||||||
new AndroidDatabase(DatabaseUtils.openDatabase()));
|
|
||||||
pendingConfirmation = new LinkedList<>();
|
|
||||||
pendingEmit = new LinkedList<>(repository.findAll("order by timestamp"));
|
|
||||||
|
|
||||||
groupKey = prefs.getSyncKey();
|
|
||||||
clientId = prefs.getSyncClientId();
|
|
||||||
String serverURL = prefs.getSyncAddress();
|
|
||||||
|
|
||||||
Log.d("SyncManager", clientId);
|
|
||||||
connect(serverURL);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCommandExecuted(@NonNull Command command,
|
|
||||||
@Nullable Long refreshKey)
|
|
||||||
{
|
|
||||||
if (command.isRemote()) return;
|
|
||||||
|
|
||||||
JSONObject msg = toJSONObject(command.toJson());
|
|
||||||
Long now = new Date().getTime();
|
|
||||||
Event e = new Event(command.getId(), now, msg.toString());
|
|
||||||
repository.save(e);
|
|
||||||
|
|
||||||
Log.i("SyncManager", "Adding to outbox: " + msg.toString());
|
|
||||||
|
|
||||||
pendingEmit.add(e);
|
|
||||||
if (readyToEmit) emitPending();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onNetworkStatusChanged(boolean isConnected)
|
|
||||||
{
|
|
||||||
if (!isListening) return;
|
|
||||||
if (isConnected) socket.connect();
|
|
||||||
else socket.disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startListening()
|
|
||||||
{
|
|
||||||
if (!prefs.isSyncEnabled()) return;
|
|
||||||
if (groupKey.isEmpty()) return;
|
|
||||||
if (isListening) return;
|
|
||||||
|
|
||||||
isListening = true;
|
|
||||||
socket.connect();
|
|
||||||
commandRunner.addListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopListening()
|
|
||||||
{
|
|
||||||
if (!isListening) return;
|
|
||||||
|
|
||||||
commandRunner.removeListener(this);
|
|
||||||
socket.close();
|
|
||||||
isListening = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void connect(String serverURL)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
IO.setDefaultSSLContext(sslProvider.getCACertSSLContext());
|
|
||||||
socket = IO.socket(serverURL);
|
|
||||||
|
|
||||||
logSocketEvent(socket, EVENT_CONNECT, "Connected");
|
|
||||||
logSocketEvent(socket, EVENT_CONNECT_TIMEOUT, "Connect timeout");
|
|
||||||
logSocketEvent(socket, EVENT_CONNECTING, "Connecting...");
|
|
||||||
logSocketEvent(socket, EVENT_CONNECT_ERROR, "Connect error");
|
|
||||||
logSocketEvent(socket, EVENT_DISCONNECT, "Disconnected");
|
|
||||||
logSocketEvent(socket, EVENT_RECONNECT, "Reconnected");
|
|
||||||
logSocketEvent(socket, EVENT_RECONNECT_ATTEMPT, "Reconnecting...");
|
|
||||||
logSocketEvent(socket, EVENT_RECONNECT_ERROR, "Reconnect error");
|
|
||||||
logSocketEvent(socket, EVENT_RECONNECT_FAILED, "Reconnect failed");
|
|
||||||
logSocketEvent(socket, EVENT_DISCONNECT, "Disconnected");
|
|
||||||
logSocketEvent(socket, EVENT_PING, "Ping");
|
|
||||||
logSocketEvent(socket, EVENT_PONG, "Pong");
|
|
||||||
|
|
||||||
socket.on(EVENT_CONNECT, new OnConnectListener());
|
|
||||||
socket.on(EVENT_DISCONNECT, new OnDisconnectListener());
|
|
||||||
socket.on(EVENT_EXECUTE_EVENT, new OnExecuteCommandListener());
|
|
||||||
socket.on(EVENT_AUTH_OK, new OnAuthOKListener());
|
|
||||||
socket.on(EVENT_FETCH_OK, new OnFetchOKListener());
|
|
||||||
}
|
|
||||||
catch (URISyntaxException e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void emitPending()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
for (Event e : pendingEmit)
|
|
||||||
{
|
|
||||||
Log.i("SyncManager", "Emitting: " + e.message);
|
|
||||||
socket.emit(EVENT_POST_EVENT, new JSONObject(e.message));
|
|
||||||
pendingConfirmation.add(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
pendingEmit.clear();
|
|
||||||
}
|
|
||||||
catch (JSONException e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void logSocketEvent(Socket socket, String event, final String msg)
|
|
||||||
{
|
|
||||||
socket.on(event, args ->
|
|
||||||
{
|
|
||||||
Log.i("SyncManager", msg);
|
|
||||||
for (Object o : args)
|
|
||||||
if (o instanceof SocketIOException)
|
|
||||||
((SocketIOException) o).printStackTrace();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private JSONObject toJSONObject(String json)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return new JSONObject(json);
|
|
||||||
}
|
|
||||||
catch (JSONException e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateLastSync(Long timestamp)
|
|
||||||
{
|
|
||||||
prefs.setLastSync(timestamp + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class OnAuthOKListener implements Emitter.Listener
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void call(Object... args)
|
|
||||||
{
|
|
||||||
Log.i("SyncManager", "Auth OK");
|
|
||||||
Log.i("SyncManager", "Requesting commands since last sync");
|
|
||||||
|
|
||||||
Long lastSync = prefs.getLastSync();
|
|
||||||
socket.emit(EVENT_FETCH, buildFetchMessage(lastSync));
|
|
||||||
}
|
|
||||||
|
|
||||||
private JSONObject buildFetchMessage(Long lastSync)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
JSONObject json = new JSONObject();
|
|
||||||
json.put("since", lastSync);
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
catch (JSONException e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class OnConnectListener implements Emitter.Listener
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void call(Object... args)
|
|
||||||
{
|
|
||||||
Log.i("SyncManager", "Sending auth message");
|
|
||||||
socket.emit(EVENT_AUTH, buildAuthMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
private JSONObject buildAuthMessage()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
JSONObject json = new JSONObject();
|
|
||||||
json.put("groupKey", groupKey);
|
|
||||||
json.put("clientId", clientId);
|
|
||||||
json.put("version", BuildConfig.VERSION_NAME);
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
catch (JSONException e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class OnDisconnectListener implements Emitter.Listener
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void call(Object... args)
|
|
||||||
{
|
|
||||||
readyToEmit = false;
|
|
||||||
for (Event e : pendingConfirmation) pendingEmit.add(e);
|
|
||||||
pendingConfirmation.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class OnExecuteCommandListener implements Emitter.Listener
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void call(Object... args)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Log.d("SyncManager",
|
|
||||||
String.format("Received command: %s", args[0].toString()));
|
|
||||||
JSONObject root = new JSONObject(args[0].toString());
|
|
||||||
updateLastSync(root.getLong("timestamp"));
|
|
||||||
executeCommand(root);
|
|
||||||
}
|
|
||||||
catch (JSONException e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void executeCommand(JSONObject root) throws JSONException
|
|
||||||
{
|
|
||||||
Command received = commandParser.parse(root.toString());
|
|
||||||
received.setRemote(true);
|
|
||||||
|
|
||||||
for (Event e : pendingConfirmation)
|
|
||||||
{
|
|
||||||
if (e.serverId.equals(received.getId()))
|
|
||||||
{
|
|
||||||
Log.i("SyncManager", "Pending command confirmed");
|
|
||||||
pendingConfirmation.remove(e);
|
|
||||||
repository.remove(e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.d("SyncManager", "Executing received command");
|
|
||||||
commandRunner.execute(received, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class OnFetchOKListener implements Emitter.Listener
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void call(Object... args)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Log.i("SyncManager", "Fetch OK");
|
|
||||||
|
|
||||||
JSONObject json = (JSONObject) args[0];
|
|
||||||
updateLastSync(json.getLong("timestamp"));
|
|
||||||
|
|
||||||
emitPending();
|
|
||||||
readyToEmit = true;
|
|
||||||
}
|
|
||||||
catch (JSONException e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker 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.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.isoron.uhabits.sync;
|
|
||||||
|
|
||||||
import android.app.*;
|
|
||||||
import android.content.*;
|
|
||||||
import android.net.*;
|
|
||||||
import android.os.*;
|
|
||||||
import androidx.core.app.*;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.*;
|
|
||||||
import org.isoron.uhabits.core.preferences.*;
|
|
||||||
import org.isoron.uhabits.receivers.*;
|
|
||||||
|
|
||||||
public class SyncService extends Service implements Preferences.Listener
|
|
||||||
{
|
|
||||||
private SyncManager syncManager;
|
|
||||||
|
|
||||||
private Preferences prefs;
|
|
||||||
|
|
||||||
private ConnectivityReceiver connectivityReceiver;
|
|
||||||
|
|
||||||
public SyncService()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBinder onBind(Intent intent)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate()
|
|
||||||
{
|
|
||||||
Intent notificationIntent = new Intent(this, SyncService.class);
|
|
||||||
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
|
|
||||||
|
|
||||||
Notification notification = new NotificationCompat.Builder(this)
|
|
||||||
.setContentTitle("Loop Habit Tracker")
|
|
||||||
.setContentText("Sync service running")
|
|
||||||
.setSmallIcon(R.drawable.ic_notification)
|
|
||||||
.setPriority(NotificationCompat.PRIORITY_MIN)
|
|
||||||
.setContentIntent(pendingIntent)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
startForeground(99999, notification);
|
|
||||||
|
|
||||||
connectivityReceiver = new ConnectivityReceiver();
|
|
||||||
IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
|
|
||||||
this.registerReceiver(connectivityReceiver, filter);
|
|
||||||
|
|
||||||
HabitsApplication app = (HabitsApplication) getApplicationContext();
|
|
||||||
syncManager = app.getComponent().getSyncManager();
|
|
||||||
syncManager.startListening();
|
|
||||||
|
|
||||||
prefs = app.getComponent().getPreferences();
|
|
||||||
prefs.addListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSyncFeatureChanged()
|
|
||||||
{
|
|
||||||
if(!prefs.isSyncEnabled()) stopSelf();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy()
|
|
||||||
{
|
|
||||||
unregisterReceiver(connectivityReceiver);
|
|
||||||
syncManager.stopListening();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
1.8.7
|
1.8.9
|
||||||
* Fix notification issues
|
* Remove unused permissions
|
||||||
|
* Notification bundling
|
||||||
1.8:
|
1.8:
|
||||||
* New bar chart showing number of repetitions performed each week, month or year
|
* New bar chart showing number of repetitions performed each week, month or year
|
||||||
* Performing habits on irregular weekdays will no longer break your streak
|
* Performing habits on irregular weekdays will no longer break your streak
|
||||||
* More colors to choose from (now 20 in total)
|
* More colors
|
||||||
* Ability to customize how transparent the widgets are
|
* Customize how transparent the widgets are
|
||||||
* Ability to customize the first day of the week
|
* Customize the first day of the week
|
||||||
* Yes/No buttons on notifications instead of just "Check"
|
* Yes/No buttons on notifications
|
||||||
* Automatic dark theme (Android 10)
|
* Automatic dark theme (Android 10)
|
||||||
* Smaller APK and backup files
|
* Smaller APK and backup files
|
||||||
|
|||||||
@@ -190,22 +190,6 @@
|
|||||||
android:title="Enable widget stacks"
|
android:title="Enable widget stacks"
|
||||||
app:iconSpaceReserved="false" />
|
app:iconSpaceReserved="false" />
|
||||||
|
|
||||||
<CheckBoxPreference
|
|
||||||
android:defaultValue="false"
|
|
||||||
android:key="pref_feature_sync"
|
|
||||||
android:title="Enable cloud sync"
|
|
||||||
app:iconSpaceReserved="false" />
|
|
||||||
|
|
||||||
<EditTextPreference
|
|
||||||
android:key="pref_sync_address"
|
|
||||||
android:title="Sync server address"
|
|
||||||
app:iconSpaceReserved="false" />
|
|
||||||
|
|
||||||
<EditTextPreference
|
|
||||||
android:key="pref_sync_key"
|
|
||||||
android:title="Sync key"
|
|
||||||
app:iconSpaceReserved="false" />
|
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
@@ -122,22 +122,28 @@ public abstract class CheckmarkList
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starting from the oldest interval, this function tries to slide the
|
* Starting from the second newest interval, this function tries to slide the
|
||||||
* intervals backwards into the past, so that gaps are eliminated and
|
* intervals backwards into the past, so that gaps are eliminated and
|
||||||
* streaks are maximized. When it detects that sliding an interval
|
* streaks are maximized.
|
||||||
* would not help fixing any gap, it leaves the interval unchanged.
|
|
||||||
*/
|
*/
|
||||||
static void snapIntervalsTogether(@NonNull ArrayList<Interval> intervals)
|
static void snapIntervalsTogether(@NonNull ArrayList<Interval> intervals)
|
||||||
{
|
{
|
||||||
for (int i = 1; i < intervals.size(); i++)
|
int n = intervals.size();
|
||||||
|
for (int i = n - 2; i >= 0; i--)
|
||||||
{
|
{
|
||||||
Interval curr = intervals.get(i);
|
Interval curr = intervals.get(i);
|
||||||
Interval prev = intervals.get(i - 1);
|
Interval next = intervals.get(i + 1);
|
||||||
|
|
||||||
int gap = prev.end.daysUntil(curr.begin) - 1;
|
int gapNextToCurrent = next.begin.daysUntil(curr.end);
|
||||||
if (gap <= 0 || curr.end.minus(gap).isOlderThan(curr.center)) continue;
|
int gapCenterToEnd = curr.center.daysUntil(curr.end);
|
||||||
intervals.set(i, new Interval(curr.begin.minus(gap), curr.center,
|
|
||||||
curr.end.minus(gap)));
|
if (gapNextToCurrent >= 0)
|
||||||
|
{
|
||||||
|
int shift = Math.min(gapCenterToEnd, gapNextToCurrent + 1);
|
||||||
|
intervals.set(i, new Interval(curr.begin.minus(shift),
|
||||||
|
curr.center,
|
||||||
|
curr.end.minus(shift)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ public class MemoryHabitList extends HabitList
|
|||||||
super(matcher);
|
super(matcher);
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.comparator = comparator;
|
this.comparator = comparator;
|
||||||
|
this.order = parent.order;
|
||||||
parent.getObservable().addListener(this::loadFromParent);
|
parent.getObservable().addListener(this::loadFromParent);
|
||||||
loadFromParent();
|
loadFromParent();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -319,16 +319,31 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
public void test_snapIntervalsTogether_1() throws Exception
|
public void test_snapIntervalsTogether_1() throws Exception
|
||||||
{
|
{
|
||||||
ArrayList<CheckmarkList.Interval> original = new ArrayList<>();
|
ArrayList<CheckmarkList.Interval> original = new ArrayList<>();
|
||||||
original.add(new CheckmarkList.Interval(day(40), day(40), day(34)));
|
original.add(new CheckmarkList.Interval(day(27), day(27), day(21)));
|
||||||
original.add(new CheckmarkList.Interval(day(25), day(25), day(19)));
|
original.add(new CheckmarkList.Interval(day(20), day(20), day(14)));
|
||||||
original.add(new CheckmarkList.Interval(day(16), day(16), day(10)));
|
original.add(new CheckmarkList.Interval(day(12), day(12), day(6)));
|
||||||
original.add(new CheckmarkList.Interval(day(8), day(8), day(2)));
|
original.add(new CheckmarkList.Interval(day(8), day(8), day(2)));
|
||||||
|
|
||||||
ArrayList<CheckmarkList.Interval> expected = new ArrayList<>();
|
ArrayList<CheckmarkList.Interval> expected = new ArrayList<>();
|
||||||
expected.add(new CheckmarkList.Interval(day(40), day(40), day(34)));
|
expected.add(new CheckmarkList.Interval(day(29), day(27), day(23)));
|
||||||
expected.add(new CheckmarkList.Interval(day(25), day(25), day(19)));
|
expected.add(new CheckmarkList.Interval(day(22), day(20), day(16)));
|
||||||
expected.add(new CheckmarkList.Interval(day(18), day(16), day(12)));
|
expected.add(new CheckmarkList.Interval(day(15), day(12), day(9)));
|
||||||
expected.add(new CheckmarkList.Interval(day(11), day(8), day(5)));
|
expected.add(new CheckmarkList.Interval(day(8), day(8), day(2)));
|
||||||
|
|
||||||
|
CheckmarkList.snapIntervalsTogether(original);
|
||||||
|
assertThat(original, equalTo(expected));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_snapIntervalsTogether_2() throws Exception
|
||||||
|
{
|
||||||
|
ArrayList<CheckmarkList.Interval> original = new ArrayList<>();
|
||||||
|
original.add(new CheckmarkList.Interval(day(11), day(8), day(5)));
|
||||||
|
original.add(new CheckmarkList.Interval(day(6), day(4), day(0)));
|
||||||
|
|
||||||
|
ArrayList<CheckmarkList.Interval> expected = new ArrayList<>();
|
||||||
|
expected.add(new CheckmarkList.Interval(day(13), day(8), day(7)));
|
||||||
|
expected.add(new CheckmarkList.Interval(day(6), day(4), day(0)));
|
||||||
|
|
||||||
CheckmarkList.snapIntervalsTogether(original);
|
CheckmarkList.snapIntervalsTogether(original);
|
||||||
assertThat(original, equalTo(expected));
|
assertThat(original, equalTo(expected));
|
||||||
|
|||||||
@@ -31,8 +31,7 @@ import static junit.framework.TestCase.assertFalse;
|
|||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.isoron.uhabits.core.models.HabitList.Order.*;
|
import static org.isoron.uhabits.core.models.HabitList.Order.*;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
|
|
||||||
@SuppressWarnings("JavaDoc")
|
@SuppressWarnings("JavaDoc")
|
||||||
public class HabitListTest extends BaseUnitTest
|
public class HabitListTest extends BaseUnitTest
|
||||||
@@ -211,6 +210,17 @@ public class HabitListTest extends BaseUnitTest
|
|||||||
habitList.reorder(h1, h2);
|
habitList.reorder(h1, h2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOrder_inherit()
|
||||||
|
{
|
||||||
|
habitList.setOrder(BY_COLOR);
|
||||||
|
HabitList filteredList = habitList.getFiltered(new HabitMatcherBuilder()
|
||||||
|
.setArchivedAllowed(false)
|
||||||
|
.setCompletedAllowed(false)
|
||||||
|
.build());
|
||||||
|
assertEquals(filteredList.getOrder(), BY_COLOR);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWriteCSV() throws IOException
|
public void testWriteCSV() throws IOException
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -153,9 +153,9 @@ public class ScoreListTest extends BaseUnitTest
|
|||||||
habit.getScores().groupBy(DateUtils.TruncateField.MONTH, Calendar.SATURDAY);
|
habit.getScores().groupBy(DateUtils.TruncateField.MONTH, Calendar.SATURDAY);
|
||||||
|
|
||||||
assertThat(list.size(), equalTo(5));
|
assertThat(list.size(), equalTo(5));
|
||||||
assertThat(list.get(0).getValue(), closeTo(0.653659, E));
|
assertThat(list.get(0).getValue(), closeTo(0.687724, E));
|
||||||
assertThat(list.get(1).getValue(), closeTo(0.622715, E));
|
assertThat(list.get(1).getValue(), closeTo(0.636747, E));
|
||||||
assertThat(list.get(2).getValue(), closeTo(0.520997, E));
|
assertThat(list.get(2).getValue(), closeTo(0.533860, E));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||