mirror of
https://github.com/praktimarc/kst4contest.git
synced 2026-11-19 01:52:29 +01:00
Compare commits
61
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9ddc1959d
|
||
|
|
dbd6caa4ea
|
||
|
|
e527ad4198
|
||
|
|
b7950f8a06
|
||
|
|
dc164403be
|
||
|
|
76e086f4c0
|
||
|
|
52508eec71
|
||
|
|
918f84dc8a
|
||
|
|
9e5759adfe
|
||
|
|
68d86ce320
|
||
|
|
383e0f97c9
|
||
|
|
85a2984234
|
||
|
|
0d0b752bed
|
||
|
|
175b6350c2
|
||
|
|
a24534bbb1
|
||
|
|
bde77f3ec1
|
||
|
|
facba2b010
|
||
|
|
0ab9ffc241
|
||
|
|
adcd9da306
|
||
|
|
da1f261684
|
||
|
|
f607b831ca
|
||
|
|
a8cfe94853
|
||
|
|
f871f551f7
|
||
|
|
0821820dd4
|
||
|
|
bd36beccb5
|
||
|
|
8352af911e
|
||
|
|
f1e80c6ed3
|
||
|
|
f5783ade25
|
||
|
|
0a43af66df
|
||
|
|
3575473fa9
|
||
|
|
64a6eab35f
|
||
|
|
78fc5b98fa
|
||
|
|
3ca6ef411f
|
||
|
|
01e56c6639
|
||
|
|
78a1502a1f
|
||
|
|
1615c4dffc
|
||
|
|
6508978da9
|
||
|
|
aff9b6e2ff
|
||
|
|
b0960a3f04 | ||
|
|
f13fe54fde | ||
|
|
19bcdb428d | ||
|
|
9304df3705 | ||
|
|
e5c057378f | ||
|
|
d925c83412 | ||
|
|
4d96822c0c | ||
|
|
c23982c339 | ||
|
|
834f4b131a | ||
|
|
1868f21c06 | ||
|
|
9d433f9ba4 | ||
|
|
f4f046c04f | ||
|
|
8fc3b9f424 | ||
|
|
f165f7d303 | ||
|
|
738ae2125e | ||
|
|
af8affda8c | ||
|
|
a4e10300e7 | ||
|
|
4642d658a3 | ||
|
|
d38b385166 | ||
|
|
a28abe1591 | ||
|
|
a0039cd52e | ||
|
|
8dec00870b | ||
|
|
7ee02fb029 |
No files matched your search
@@ -32,13 +32,16 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
name: Test (Java 21, headless)
|
name: Test (Java 21, headless)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
# A healthy run takes about four minutes. The per-test limit in build.gradle.kts names
|
||||||
|
# a hanging test; this cap covers a hang outside any test, such as in Gradle itself.
|
||||||
|
timeout-minutes: 20
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v7
|
uses: actions/checkout@v7
|
||||||
|
|
||||||
- name: Set up Java 21
|
- name: Set up Java 21
|
||||||
uses: actions/setup-java@v6.0.1
|
uses: actions/setup-java@v6.2.0
|
||||||
with:
|
with:
|
||||||
distribution: temurin
|
distribution: temurin
|
||||||
java-version: "21"
|
java-version: "21"
|
||||||
@@ -108,8 +111,10 @@ jobs:
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Also on cancelled(): the job timeout cancels a hanging run, and the reports of the
|
||||||
|
# classes that did finish carry the timed-out tests' full stacks.
|
||||||
- name: Keep the test reports on a failure
|
- name: Keep the test reports on a failure
|
||||||
if: failure()
|
if: failure() || cancelled()
|
||||||
uses: actions/upload-artifact@v7
|
uses: actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: test-results
|
name: test-results
|
||||||
@@ -138,7 +143,7 @@ jobs:
|
|||||||
Add-Content -Path $env:GITHUB_ENV -Value "ASSET_BASENAME=praktiKST-$version-$shortSha"
|
Add-Content -Path $env:GITHUB_ENV -Value "ASSET_BASENAME=praktiKST-$version-$shortSha"
|
||||||
|
|
||||||
- name: Set up Java 21
|
- name: Set up Java 21
|
||||||
uses: actions/setup-java@v6.0.1
|
uses: actions/setup-java@v6.2.0
|
||||||
with:
|
with:
|
||||||
distribution: temurin
|
distribution: temurin
|
||||||
java-version: "21"
|
java-version: "21"
|
||||||
@@ -188,7 +193,7 @@ jobs:
|
|||||||
echo "ASSET_BASENAME=KST4Contest-${VERSION}-${SHORT_SHA}" >> "$GITHUB_ENV"
|
echo "ASSET_BASENAME=KST4Contest-${VERSION}-${SHORT_SHA}" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
- name: Set up Java 21
|
- name: Set up Java 21
|
||||||
uses: actions/setup-java@v6.0.1
|
uses: actions/setup-java@v6.2.0
|
||||||
with:
|
with:
|
||||||
distribution: temurin
|
distribution: temurin
|
||||||
java-version: "21"
|
java-version: "21"
|
||||||
@@ -262,7 +267,7 @@ jobs:
|
|||||||
echo "ASSET_BASENAME=KST4Contest-${VERSION}-${SHORT_SHA}" >> "$GITHUB_ENV"
|
echo "ASSET_BASENAME=KST4Contest-${VERSION}-${SHORT_SHA}" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
- name: Set up Java 21
|
- name: Set up Java 21
|
||||||
uses: actions/setup-java@v6.0.1
|
uses: actions/setup-java@v6.2.0
|
||||||
with:
|
with:
|
||||||
distribution: temurin
|
distribution: temurin
|
||||||
java-version: "21"
|
java-version: "21"
|
||||||
@@ -308,7 +313,7 @@ jobs:
|
|||||||
echo "ASSET_BASENAME=KST4Contest-${VERSION}-${SHORT_SHA}" >> "$GITHUB_ENV"
|
echo "ASSET_BASENAME=KST4Contest-${VERSION}-${SHORT_SHA}" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
- name: Set up Java 21
|
- name: Set up Java 21
|
||||||
uses: actions/setup-java@v6.0.1
|
uses: actions/setup-java@v6.2.0
|
||||||
with:
|
with:
|
||||||
distribution: temurin
|
distribution: temurin
|
||||||
java-version: "21"
|
java-version: "21"
|
||||||
@@ -356,7 +361,7 @@ jobs:
|
|||||||
echo "ASSET_BASENAME=KST4Contest-${VERSION}-${SHORT_SHA}" >> "$GITHUB_ENV"
|
echo "ASSET_BASENAME=KST4Contest-${VERSION}-${SHORT_SHA}" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
- name: Set up Java 21
|
- name: Set up Java 21
|
||||||
uses: actions/setup-java@v6.0.1
|
uses: actions/setup-java@v6.2.0
|
||||||
with:
|
with:
|
||||||
distribution: temurin
|
distribution: temurin
|
||||||
java-version: "21"
|
java-version: "21"
|
||||||
@@ -468,7 +473,7 @@ jobs:
|
|||||||
echo "ASSET_BASENAME=KST4Contest-${VERSION}-${SHORT_SHA}" >> "$GITHUB_ENV"
|
echo "ASSET_BASENAME=KST4Contest-${VERSION}-${SHORT_SHA}" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
- name: Set up Java 21
|
- name: Set up Java 21
|
||||||
uses: actions/setup-java@v6.0.1
|
uses: actions/setup-java@v6.2.0
|
||||||
with:
|
with:
|
||||||
distribution: temurin
|
distribution: temurin
|
||||||
java-version: "21"
|
java-version: "21"
|
||||||
@@ -481,7 +486,7 @@ jobs:
|
|||||||
sudo apt-get update -qq
|
sudo apt-get update -qq
|
||||||
sudo apt-get install -y --no-install-recommends flatpak flatpak-builder elfutils
|
sudo apt-get install -y --no-install-recommends flatpak flatpak-builder elfutils
|
||||||
flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
|
flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
|
||||||
flatpak --user install -y flathub org.freedesktop.Platform//24.08 org.freedesktop.Sdk//24.08
|
flatpak --user install -y flathub org.freedesktop.Platform//25.08 org.freedesktop.Sdk//25.08
|
||||||
|
|
||||||
- name: Build app-image
|
- name: Build app-image
|
||||||
run: |
|
run: |
|
||||||
@@ -498,7 +503,7 @@ jobs:
|
|||||||
cat > target/de.x08.KST4Contest.yml << 'EOF'
|
cat > target/de.x08.KST4Contest.yml << 'EOF'
|
||||||
app-id: de.x08.KST4Contest
|
app-id: de.x08.KST4Contest
|
||||||
runtime: org.freedesktop.Platform
|
runtime: org.freedesktop.Platform
|
||||||
runtime-version: "24.08"
|
runtime-version: "25.08"
|
||||||
sdk: org.freedesktop.Sdk
|
sdk: org.freedesktop.Sdk
|
||||||
command: KST4Contest
|
command: KST4Contest
|
||||||
finish-args:
|
finish-args:
|
||||||
@@ -549,7 +554,7 @@ jobs:
|
|||||||
- name: Create flatpakref (nightly)
|
- name: Create flatpakref (nightly)
|
||||||
run: |
|
run: |
|
||||||
REPO_NAME="${GITHUB_REPOSITORY#*/}"
|
REPO_NAME="${GITHUB_REPOSITORY#*/}"
|
||||||
PAGES_URL="https://${GITHUB_REPOSITORY_OWNER}.github.io/${REPO_NAME}/"
|
PAGES_URL="https://${GITHUB_REPOSITORY_OWNER,,}.github.io/${REPO_NAME}/"
|
||||||
GPG_KEY_B64=$(gpg --export "$FLATPAK_GPG_KEY_ID" | base64 -w 0)
|
GPG_KEY_B64=$(gpg --export "$FLATPAK_GPG_KEY_ID" | base64 -w 0)
|
||||||
cat > "dist/de.x08.KST4Contest.nightly.flatpakref" << EOF
|
cat > "dist/de.x08.KST4Contest.nightly.flatpakref" << EOF
|
||||||
[Flatpak Ref]
|
[Flatpak Ref]
|
||||||
@@ -616,7 +621,7 @@ jobs:
|
|||||||
flatpak build-update-repo --gpg-sign="$FLATPAK_GPG_KEY_ID" .
|
flatpak build-update-repo --gpg-sign="$FLATPAK_GPG_KEY_ID" .
|
||||||
# Generate .flatpakrepo with embedded GPG key so users can do remote-add without errors
|
# Generate .flatpakrepo with embedded GPG key so users can do remote-add without errors
|
||||||
REPO_NAME="${GITHUB_REPOSITORY#*/}"
|
REPO_NAME="${GITHUB_REPOSITORY#*/}"
|
||||||
PAGES_URL="https://${GITHUB_REPOSITORY_OWNER}.github.io/${REPO_NAME}/"
|
PAGES_URL="https://${GITHUB_REPOSITORY_OWNER,,}.github.io/${REPO_NAME}/"
|
||||||
GPG_KEY_B64=$(gpg --export "$FLATPAK_GPG_KEY_ID" | base64 -w 0)
|
GPG_KEY_B64=$(gpg --export "$FLATPAK_GPG_KEY_ID" | base64 -w 0)
|
||||||
cat > kst4contest.flatpakrepo << EOF
|
cat > kst4contest.flatpakrepo << EOF
|
||||||
[Flatpak Repo]
|
[Flatpak Repo]
|
||||||
@@ -659,7 +664,7 @@ jobs:
|
|||||||
echo "ARCH=$ARCH" >> "$GITHUB_ENV"
|
echo "ARCH=$ARCH" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
- name: Set up Java 21
|
- name: Set up Java 21
|
||||||
uses: actions/setup-java@v6.0.1
|
uses: actions/setup-java@v6.2.0
|
||||||
with:
|
with:
|
||||||
distribution: temurin
|
distribution: temurin
|
||||||
java-version: "21"
|
java-version: "21"
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ on:
|
|||||||
- main
|
- main
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
env:
|
env:
|
||||||
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
|
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
|
||||||
|
|
||||||
@@ -19,7 +22,7 @@ jobs:
|
|||||||
uses: actions/checkout@v7
|
uses: actions/checkout@v7
|
||||||
|
|
||||||
- name: Set up Java 21
|
- name: Set up Java 21
|
||||||
uses: actions/setup-java@v6.0.1
|
uses: actions/setup-java@v6.2.0
|
||||||
with:
|
with:
|
||||||
distribution: temurin
|
distribution: temurin
|
||||||
java-version: "21"
|
java-version: "21"
|
||||||
@@ -155,13 +158,16 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
name: Test (Java 21, headless)
|
name: Test (Java 21, headless)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
# A healthy run takes about four minutes. The per-test limit in build.gradle.kts names
|
||||||
|
# a hanging test; this cap covers a hang outside any test, such as in Gradle itself.
|
||||||
|
timeout-minutes: 20
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v7
|
uses: actions/checkout@v7
|
||||||
|
|
||||||
- name: Set up Java 21
|
- name: Set up Java 21
|
||||||
uses: actions/setup-java@v6.0.1
|
uses: actions/setup-java@v6.2.0
|
||||||
with:
|
with:
|
||||||
distribution: temurin
|
distribution: temurin
|
||||||
java-version: "21"
|
java-version: "21"
|
||||||
@@ -283,8 +289,10 @@ jobs:
|
|||||||
if-no-files-found: ignore
|
if-no-files-found: ignore
|
||||||
retention-days: 14
|
retention-days: 14
|
||||||
|
|
||||||
|
# Also on cancelled(): the job timeout cancels a hanging run, and the reports of the
|
||||||
|
# classes that did finish carry the timed-out tests' full stacks.
|
||||||
- name: Keep the test reports on a failure
|
- name: Keep the test reports on a failure
|
||||||
if: failure()
|
if: failure() || cancelled()
|
||||||
uses: actions/upload-artifact@v7
|
uses: actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: test-results
|
name: test-results
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
name: Test (Java 21, headless)
|
name: Test (Java 21, headless)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
# A healthy run takes about four minutes. The per-test limit in build.gradle.kts names
|
||||||
|
# a hanging test; this cap covers a hang outside any test, such as in Gradle itself.
|
||||||
|
timeout-minutes: 20
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
@@ -57,7 +60,7 @@ jobs:
|
|||||||
echo "Tag $REF_NAME matches composePackageVersion=$PROPERTY_VERSION"
|
echo "Tag $REF_NAME matches composePackageVersion=$PROPERTY_VERSION"
|
||||||
|
|
||||||
- name: Set up Java 21
|
- name: Set up Java 21
|
||||||
uses: actions/setup-java@v6.0.1
|
uses: actions/setup-java@v6.2.0
|
||||||
with:
|
with:
|
||||||
distribution: temurin
|
distribution: temurin
|
||||||
java-version: "21"
|
java-version: "21"
|
||||||
@@ -127,8 +130,10 @@ jobs:
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Also on cancelled(): the job timeout cancels a hanging run, and the reports of the
|
||||||
|
# classes that did finish carry the timed-out tests' full stacks.
|
||||||
- name: Keep the test reports on a failure
|
- name: Keep the test reports on a failure
|
||||||
if: failure()
|
if: failure() || cancelled()
|
||||||
uses: actions/upload-artifact@v7
|
uses: actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: test-results
|
name: test-results
|
||||||
@@ -148,7 +153,7 @@ jobs:
|
|||||||
uses: actions/checkout@v7
|
uses: actions/checkout@v7
|
||||||
|
|
||||||
- name: Set up Java 21
|
- name: Set up Java 21
|
||||||
uses: actions/setup-java@v6.0.1
|
uses: actions/setup-java@v6.2.0
|
||||||
with:
|
with:
|
||||||
distribution: temurin
|
distribution: temurin
|
||||||
java-version: "21"
|
java-version: "21"
|
||||||
@@ -217,7 +222,7 @@ jobs:
|
|||||||
uses: actions/checkout@v7
|
uses: actions/checkout@v7
|
||||||
|
|
||||||
- name: Set up Java 21
|
- name: Set up Java 21
|
||||||
uses: actions/setup-java@v6.0.1
|
uses: actions/setup-java@v6.2.0
|
||||||
with:
|
with:
|
||||||
distribution: temurin
|
distribution: temurin
|
||||||
java-version: "21"
|
java-version: "21"
|
||||||
@@ -284,7 +289,7 @@ jobs:
|
|||||||
uses: actions/checkout@v7
|
uses: actions/checkout@v7
|
||||||
|
|
||||||
- name: Set up Java 21
|
- name: Set up Java 21
|
||||||
uses: actions/setup-java@v6.0.1
|
uses: actions/setup-java@v6.2.0
|
||||||
with:
|
with:
|
||||||
distribution: temurin
|
distribution: temurin
|
||||||
java-version: "21"
|
java-version: "21"
|
||||||
@@ -355,7 +360,7 @@ jobs:
|
|||||||
uses: actions/checkout@v7
|
uses: actions/checkout@v7
|
||||||
|
|
||||||
- name: Set up Java 21
|
- name: Set up Java 21
|
||||||
uses: actions/setup-java@v6.0.1
|
uses: actions/setup-java@v6.2.0
|
||||||
with:
|
with:
|
||||||
distribution: temurin
|
distribution: temurin
|
||||||
java-version: "21"
|
java-version: "21"
|
||||||
@@ -426,7 +431,7 @@ jobs:
|
|||||||
uses: actions/checkout@v7
|
uses: actions/checkout@v7
|
||||||
|
|
||||||
- name: Set up Java 21
|
- name: Set up Java 21
|
||||||
uses: actions/setup-java@v6.0.1
|
uses: actions/setup-java@v6.2.0
|
||||||
with:
|
with:
|
||||||
distribution: temurin
|
distribution: temurin
|
||||||
java-version: "21"
|
java-version: "21"
|
||||||
@@ -529,7 +534,7 @@ jobs:
|
|||||||
uses: actions/checkout@v7
|
uses: actions/checkout@v7
|
||||||
|
|
||||||
- name: Set up Java 21
|
- name: Set up Java 21
|
||||||
uses: actions/setup-java@v6.0.1
|
uses: actions/setup-java@v6.2.0
|
||||||
with:
|
with:
|
||||||
distribution: temurin
|
distribution: temurin
|
||||||
java-version: "21"
|
java-version: "21"
|
||||||
@@ -542,7 +547,7 @@ jobs:
|
|||||||
sudo apt-get update -qq
|
sudo apt-get update -qq
|
||||||
sudo apt-get install -y --no-install-recommends flatpak flatpak-builder elfutils
|
sudo apt-get install -y --no-install-recommends flatpak flatpak-builder elfutils
|
||||||
flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
|
flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
|
||||||
flatpak --user install -y flathub org.freedesktop.Platform//24.08 org.freedesktop.Sdk//24.08
|
flatpak --user install -y flathub org.freedesktop.Platform//25.08 org.freedesktop.Sdk//25.08
|
||||||
|
|
||||||
- name: Build app-image
|
- name: Build app-image
|
||||||
run: |
|
run: |
|
||||||
@@ -559,7 +564,7 @@ jobs:
|
|||||||
cat > target/de.x08.KST4Contest.yml << 'EOF'
|
cat > target/de.x08.KST4Contest.yml << 'EOF'
|
||||||
app-id: de.x08.KST4Contest
|
app-id: de.x08.KST4Contest
|
||||||
runtime: org.freedesktop.Platform
|
runtime: org.freedesktop.Platform
|
||||||
runtime-version: "24.08"
|
runtime-version: "25.08"
|
||||||
sdk: org.freedesktop.Sdk
|
sdk: org.freedesktop.Sdk
|
||||||
command: KST4Contest
|
command: KST4Contest
|
||||||
finish-args:
|
finish-args:
|
||||||
@@ -620,7 +625,7 @@ jobs:
|
|||||||
- name: Create flatpakref
|
- name: Create flatpakref
|
||||||
run: |
|
run: |
|
||||||
REPO_NAME="${GITHUB_REPOSITORY#*/}"
|
REPO_NAME="${GITHUB_REPOSITORY#*/}"
|
||||||
PAGES_URL="https://${GITHUB_REPOSITORY_OWNER}.github.io/${REPO_NAME}/"
|
PAGES_URL="https://${GITHUB_REPOSITORY_OWNER,,}.github.io/${REPO_NAME}/"
|
||||||
GPG_KEY_B64=$(gpg --export "$FLATPAK_GPG_KEY_ID" | base64 -w 0)
|
GPG_KEY_B64=$(gpg --export "$FLATPAK_GPG_KEY_ID" | base64 -w 0)
|
||||||
cat > "dist/${FLATPAKREF_NAME}" << EOF
|
cat > "dist/${FLATPAKREF_NAME}" << EOF
|
||||||
[Flatpak Ref]
|
[Flatpak Ref]
|
||||||
@@ -659,7 +664,7 @@ jobs:
|
|||||||
uses: actions/checkout@v7
|
uses: actions/checkout@v7
|
||||||
|
|
||||||
- name: Set up Java 21
|
- name: Set up Java 21
|
||||||
uses: actions/setup-java@v6.0.1
|
uses: actions/setup-java@v6.2.0
|
||||||
with:
|
with:
|
||||||
distribution: temurin
|
distribution: temurin
|
||||||
java-version: "21"
|
java-version: "21"
|
||||||
@@ -827,7 +832,7 @@ jobs:
|
|||||||
flatpak build-update-repo --gpg-sign="$FLATPAK_GPG_KEY_ID" .
|
flatpak build-update-repo --gpg-sign="$FLATPAK_GPG_KEY_ID" .
|
||||||
# Generate .flatpakrepo with embedded GPG key so users can do remote-add without errors
|
# Generate .flatpakrepo with embedded GPG key so users can do remote-add without errors
|
||||||
REPO_NAME="${GITHUB_REPOSITORY#*/}"
|
REPO_NAME="${GITHUB_REPOSITORY#*/}"
|
||||||
PAGES_URL="https://${GITHUB_REPOSITORY_OWNER}.github.io/${REPO_NAME}/"
|
PAGES_URL="https://${GITHUB_REPOSITORY_OWNER,,}.github.io/${REPO_NAME}/"
|
||||||
GPG_KEY_B64=$(gpg --export "$FLATPAK_GPG_KEY_ID" | base64 -w 0)
|
GPG_KEY_B64=$(gpg --export "$FLATPAK_GPG_KEY_ID" | base64 -w 0)
|
||||||
cat > kst4contest.flatpakrepo << EOF
|
cat > kst4contest.flatpakrepo << EOF
|
||||||
[Flatpak Repo]
|
[Flatpak Repo]
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ name: TEST publish-version-xml (local only)
|
|||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
issues: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish-version-xml:
|
publish-version-xml:
|
||||||
name: Publish Version Info XML via WebDAV
|
name: Publish Version Info XML via WebDAV
|
||||||
@@ -30,7 +34,7 @@ jobs:
|
|||||||
|
|
||||||
import os, urllib.request
|
import os, urllib.request
|
||||||
|
|
||||||
REPO = 'praktimarc/kst4contest'
|
REPO = 'HamRadioOnline/kst4contest'
|
||||||
token = os.environ['GH_TOKEN']
|
token = os.environ['GH_TOKEN']
|
||||||
|
|
||||||
def gh_get(path):
|
def gh_get(path):
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ The application is developed by Marc Fröhlich (DO5AMF) and since 2026 Philipp W
|
|||||||
- [Project website](https://kst4contest.hamradioonline.de/)
|
- [Project website](https://kst4contest.hamradioonline.de/)
|
||||||
- [Download Stable, Beta and Nightly builds](https://kst4contest.hamradioonline.de/download/)
|
- [Download Stable, Beta and Nightly builds](https://kst4contest.hamradioonline.de/download/)
|
||||||
- [Online manual](https://kst4contest.hamradioonline.de/manual/)
|
- [Online manual](https://kst4contest.hamradioonline.de/manual/)
|
||||||
- [GitHub wiki](https://github.com/praktimarc/kst4contest/wiki)
|
- [GitHub wiki](https://github.com/HamRadioOnline/kst4contest/wiki)
|
||||||
- [Issues and bug reports](https://github.com/praktimarc/kst4contest/issues)
|
- [Issues and bug reports](https://github.com/HamRadioOnline/kst4contest/issues)
|
||||||
- [Development roadmap](https://kst4contest.hamradioonline.de/roadmap/)
|
- [Development roadmap](https://kst4contest.hamradioonline.de/roadmap/)
|
||||||
|
|
||||||
## What KST4Contest does
|
## What KST4Contest does
|
||||||
@@ -47,8 +47,8 @@ Use the central download page to select the appropriate build:
|
|||||||
|
|
||||||
The documentation is available in German and English:
|
The documentation is available in German and English:
|
||||||
|
|
||||||
- [German manual](https://github.com/praktimarc/kst4contest/wiki/de-Home)
|
- [German manual](https://github.com/HamRadioOnline/kst4contest/wiki/de-Home)
|
||||||
- [English manual](https://github.com/praktimarc/kst4contest/wiki/en-Home)
|
- [English manual](https://github.com/HamRadioOnline/kst4contest/wiki/en-Home)
|
||||||
- [Online manual](https://kst4contest.hamradioonline.de/manual/)
|
- [Online manual](https://kst4contest.hamradioonline.de/manual/)
|
||||||
|
|
||||||
The Markdown sources used for the wiki and the generated PDF manuals are stored in [`github_docs`](github_docs/).
|
The Markdown sources used for the wiki and the generated PDF manuals are stored in [`github_docs`](github_docs/).
|
||||||
@@ -83,13 +83,13 @@ Windows:
|
|||||||
|
|
||||||
### Documentation
|
### Documentation
|
||||||
|
|
||||||
[](https://github.com/praktimarc/kst4contest/actions/workflows/github-wiki.yml)
|
[](https://github.com/HamRadioOnline/kst4contest/actions/workflows/github-wiki.yml)
|
||||||
|
|
||||||
[](https://github.com/praktimarc/kst4contest/actions/workflows/docs-pdf.yml)
|
[](https://github.com/HamRadioOnline/kst4contest/actions/workflows/docs-pdf.yml)
|
||||||
|
|
||||||
### Builds
|
### Builds
|
||||||
|
|
||||||
[](https://github.com/praktimarc/kst4contest/actions/workflows/nightly-artifacts.yml)
|
[](https://github.com/HamRadioOnline/kst4contest/actions/workflows/nightly-artifacts.yml)
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
@@ -103,3 +103,5 @@ You can sponsor KST4Contest here: [Support on Ko-Fi](https://ko-fi.com/praktimar
|
|||||||
|
|
||||||
The following people are sponsoring KST4Contest:
|
The following people are sponsoring KST4Contest:
|
||||||
- Marco (DJ5KW)
|
- Marco (DJ5KW)
|
||||||
|
- Steve (G1YBB/M1B/MW1B)
|
||||||
|
- Jens (DH1AKY)
|
||||||
@@ -122,6 +122,9 @@ station.password=Passwort
|
|||||||
station.pathSection=Vorgaben für die Streckenanalyse
|
station.pathSection=Vorgaben für die Streckenanalyse
|
||||||
station.qtf=QTF
|
station.qtf=QTF
|
||||||
station.rotatorEnabled=Rotorabgleich aktiv
|
station.rotatorEnabled=Rotorabgleich aktiv
|
||||||
|
station.manualAntennaHeadingSection=Manuelle Antennenrichtung
|
||||||
|
station.manualAntennaHeadingRotatorHint=Nicht verfügbar, solange PSTRotator 1 aktiviert ist
|
||||||
|
station.useQtfFilterDirectionAsAntennaHeading=QTF-Filterrichtung als eigene Antennenrichtung übernehmen
|
||||||
station.rotatorHost=Rotor-Host
|
station.rotatorHost=Rotor-Host
|
||||||
station.rotatorPort=Rotor-Port
|
station.rotatorPort=Rotor-Port
|
||||||
station.rotatorSection=PSTRotator
|
station.rotatorSection=PSTRotator
|
||||||
@@ -256,18 +259,26 @@ filter.onlyNewGrids=Nur neue Felder
|
|||||||
filter.gridColour=Feldfarbe
|
filter.gridColour=Feldfarbe
|
||||||
filter.newBands=Neue Bänder
|
filter.newBands=Neue Bänder
|
||||||
filter.tropo=Tropo >=0dB
|
filter.tropo=Tropo >=0dB
|
||||||
|
filter.hide=Ausblenden
|
||||||
|
filter.show=Anzeigen
|
||||||
|
filter.reachability=Erreichbarkeit
|
||||||
|
filter.calcSelected=Auswahl berechnen
|
||||||
|
table.empty=Keine Einträge
|
||||||
selected.none=Keine Station gewählt.
|
selected.none=Keine Station gewählt.
|
||||||
selected.priority=Priorität:
|
selected.priority=Priorität:
|
||||||
|
selected.newJoined=Neu hinzugekommen:
|
||||||
selected.more=mehr
|
selected.more=mehr
|
||||||
selected.showMessages=Nachrichten zeigen
|
selected.showMessages=Nachrichten zeigen
|
||||||
selected.createSked=Sked anlegen
|
selected.createSked=Sked anlegen
|
||||||
selected.sked=Sked
|
selected.sked=Sked alert
|
||||||
selected.skedInMinutes=Sked in (Min.)
|
selected.skedIn=Sked in
|
||||||
|
selected.skedMinutesAt=Min., auf
|
||||||
|
selected.skedModeLink=, Mode
|
||||||
|
selected.minutes=Min.
|
||||||
selected.skedFail=Sked fehlgeschlagen
|
selected.skedFail=Sked fehlgeschlagen
|
||||||
selected.remindPmIn=Erinnerungs-PM in
|
selected.remindPmIn=Erinnerungs-PM in
|
||||||
selected.reminderOffsets=Erinnerungsabstände
|
|
||||||
selected.resetFail=Zurücksetzen fehlgeschlagen
|
selected.resetFail=Zurücksetzen fehlgeschlagen
|
||||||
selected.tagNotQrv=Als NOT QRV markieren
|
selected.tagNotQrv={0} an folgenden Bändern als NOT QRV markieren:
|
||||||
selected.band=Band
|
selected.band=Band
|
||||||
selected.mode=Mode
|
selected.mode=Mode
|
||||||
selected.lookUpAndShow=Nachschlagen und zeigen
|
selected.lookUpAndShow=Nachschlagen und zeigen
|
||||||
@@ -280,6 +291,12 @@ selected.lastActivity=Letzte Aktivität: {0} (vor {1} Min.)
|
|||||||
candidates.title=Stationen mit höchster Priorität
|
candidates.title=Stationen mit höchster Priorität
|
||||||
candidates.none=Noch keine Kandidaten.
|
candidates.none=Noch keine Kandidaten.
|
||||||
candidates.doubleClick=Doppelklick auf einen Kandidaten wählt ihn aus.
|
candidates.doubleClick=Doppelklick auf einen Kandidaten wählt ihn aus.
|
||||||
|
timeline.inBeam1=Im Strahl 1
|
||||||
|
timeline.inBeam2=Im Strahl 2
|
||||||
|
timeline.priority1=Priorität 1
|
||||||
|
timeline.priority2=Priorität 2
|
||||||
|
timeline.skeds=Skeds
|
||||||
|
timeline.minuteSuffix=min
|
||||||
update.title=Aktualisierungsinformationen
|
update.title=Aktualisierungsinformationen
|
||||||
update.available=Aktualisierung verfügbar!
|
update.available=Aktualisierung verfügbar!
|
||||||
update.installedVersion=Installierte Version:
|
update.installedVersion=Installierte Version:
|
||||||
@@ -294,12 +311,17 @@ update.versions=Versionen
|
|||||||
map.title=Stationskarte
|
map.title=Stationskarte
|
||||||
map.tab=Karte
|
map.tab=Karte
|
||||||
map.resetView=Ansicht zurücksetzen
|
map.resetView=Ansicht zurücksetzen
|
||||||
map.groupNearby=Nahe Stationen gruppieren
|
map.groupNearby=Gruppierung
|
||||||
|
map.groupNearbyTooltip=Nahe beieinanderliegende Stationen auf der Karte gruppieren.
|
||||||
|
map.alwaysOnTop=Immer im Vordergrund
|
||||||
map.triggerClusterSpot=Cluster-Spot auslösen
|
map.triggerClusterSpot=Cluster-Spot auslösen
|
||||||
map.showPathAnalysis=Streckenanalyse zeigen
|
map.showPathAnalysis=Streckenanalyse zeigen
|
||||||
map.hidePathAnalysis=Streckenanalyse ausblenden
|
map.hidePathAnalysis=Streckenanalyse ausblenden
|
||||||
map.pathAnalysisHidden=Die Streckenanalyse ist ausgeblendet.
|
map.pathAnalysisHidden=Die Streckenanalyse ist ausgeblendet.
|
||||||
map.tilesUnavailable=Kartenkacheln nicht verfügbar — die Netzverbindung prüfen.
|
map.tilesUnavailable=Kartenkacheln nicht verfügbar — die Netzverbindung prüfen.
|
||||||
|
map.overlayAntenna=Antenne
|
||||||
|
map.overlayFilters=Aktive Filter
|
||||||
|
map.overlayLegendTooltip=Rot: tatsächliche Antennenrichtung, Öffnungswinkel und maximaler QRB. Blau: aktive QTF- und QRB-Filter.
|
||||||
path.title=Strecken- und Geländeanalyse
|
path.title=Strecken- und Geländeanalyse
|
||||||
path.selectStation=Eine Station wählen, um Strecken- und Geländeanalyse vorzubereiten.
|
path.selectStation=Eine Station wählen, um Strecken- und Geländeanalyse vorzubereiten.
|
||||||
path.fromLocator=Vom Locator:
|
path.fromLocator=Vom Locator:
|
||||||
@@ -419,6 +441,16 @@ dialog.apply=Übernehmen
|
|||||||
chat.clear=leeren
|
chat.clear=leeren
|
||||||
selected.showOnMap=🗺 Auf der Karte zeigen
|
selected.showOnMap=🗺 Auf der Karte zeigen
|
||||||
selected.notQrvAll=alle
|
selected.notQrvAll=alle
|
||||||
|
context.messageSnippets=Textbausteine
|
||||||
|
context.createSked=Sked erstellen…
|
||||||
|
context.tagNotQrv=Als NOT QRV markieren
|
||||||
|
context.markWorked=Als gearbeitet markieren
|
||||||
|
context.calculateReachability=Erreichbarkeit berechnen
|
||||||
|
context.chooseStation=Station auswählen
|
||||||
|
context.back=Zurück
|
||||||
|
context.category=Kategorie {0}
|
||||||
|
context.skedTitle=Sked für {0} erstellen
|
||||||
|
context.cancel=Abbrechen
|
||||||
column.category=Kategorie
|
column.category=Kategorie
|
||||||
column.sender=Absender
|
column.sender=Absender
|
||||||
column.receiver=Empfänger
|
column.receiver=Empfänger
|
||||||
@@ -426,8 +458,9 @@ column.lastQrg=Letzte QRG
|
|||||||
column.airplane=AP [Minuten / Pot%]
|
column.airplane=AP [Minuten / Pot%]
|
||||||
column.score=Wertung
|
column.score=Wertung
|
||||||
monitor.title=Cluster & Fremd-QSOs
|
monitor.title=Cluster & Fremd-QSOs
|
||||||
|
monitor.dxCluster=DX-Cluster
|
||||||
profiles.createFailed=Das Profil konnte nicht angelegt werden. Die Profilliste konnte nicht geschrieben werden.
|
profiles.createFailed=Das Profil konnte nicht angelegt werden. Die Profilliste konnte nicht geschrieben werden.
|
||||||
profiles.createdWithoutCredentials=Das Profil „{0}" wurde ohne Rufzeichen und Passwort angelegt. Nach dem Wechsel zu diesem Profil beides im Reiter „Station" eintragen.
|
profiles.createdWithoutCredentials=Das Profil „{0}" wurde ohne Rufzeichen und Passwort angelegt. Nach dem Wechsel zu diesem Profil fragt der Einrichtungsassistent beides ab.
|
||||||
profiles.duplicateFailed=Das Profil konnte nicht dupliziert werden.
|
profiles.duplicateFailed=Das Profil konnte nicht dupliziert werden.
|
||||||
profiles.rootNotDeletable=Das Standardprofil verwendet die Dateien der Installation selbst und kann nicht gelöscht werden.
|
profiles.rootNotDeletable=Das Standardprofil verwendet die Dateien der Installation selbst und kann nicht gelöscht werden.
|
||||||
profiles.activeNotDeletable=Das gerade benutzte Profil kann nicht gelöscht werden. Zuerst zu einem anderen Profil wechseln.
|
profiles.activeNotDeletable=Das gerade benutzte Profil kann nicht gelöscht werden. Zuerst zu einem anderen Profil wechseln.
|
||||||
@@ -440,7 +473,17 @@ profiles.changeAfterSwitch=Die Änderung wirkt erst nach einem erneuten Wechsel
|
|||||||
profiles.alreadyActive=Dieses Profil ist bereits aktiv.
|
profiles.alreadyActive=Dieses Profil ist bereits aktiv.
|
||||||
profiles.selectFirst=Zuerst ein Profil in der Tabelle wählen.
|
profiles.selectFirst=Zuerst ein Profil in der Tabelle wählen.
|
||||||
beacon.invalidMessage=Der Bakentext ist ungültig: {0}
|
beacon.invalidMessage=Der Bakentext ist ungültig: {0}
|
||||||
beacon.intervalTooShort=Einen ganzzahligen Bakenabstand von mindestens {0} Minute eingeben.
|
beacon.intervalTooShort=Einen ganzzahligen Bakenabstand von mindestens {0} Minuten eingeben.
|
||||||
|
beacon.status.main=Hauptkategorie: {0}
|
||||||
|
beacon.status.second=Zweite Kategorie: {0}
|
||||||
|
beacon.status.enabled=aktiv
|
||||||
|
beacon.status.failed=Versand fehlgeschlagen
|
||||||
|
beacon.status.unavailable=nicht verfügbar
|
||||||
|
beacon.reason.session=in dieser Sitzung noch nicht aktiviert
|
||||||
|
beacon.reason.user=durch den Benutzer ausgeschaltet
|
||||||
|
beacon.reason.primaryQrg=Haupt-QRG fehlt oder ist ungültig
|
||||||
|
beacon.reason.secondaryQrg=zweite QRG fehlt oder ist ungültig
|
||||||
|
beacon.reason.automaticQrg=automatische QRG-Änderung um mehr als 5 kHz
|
||||||
notification.invalidPort=„{0}" ist kein gültiger TCP-Port. Einen Wert von 1 bis 65535 eingeben.
|
notification.invalidPort=„{0}" ist kein gültiger TCP-Port. Einen Wert von 1 bis 65535 eingeben.
|
||||||
notification.invalidSpotter=„{0}" ist kein gültiges Spotter-Rufzeichen.
|
notification.invalidSpotter=„{0}" ist kein gültiges Spotter-Rufzeichen.
|
||||||
notification.invalidCallsign=Bitte ein gültiges Rufzeichen eingeben.
|
notification.invalidCallsign=Bitte ein gültiges Rufzeichen eingeben.
|
||||||
@@ -452,3 +495,95 @@ profiles.unknown=unbekannt
|
|||||||
profiles.copyOf=Kopie von {0}
|
profiles.copyOf=Kopie von {0}
|
||||||
profiles.sharedDatabase=gemeinsame Stationsdatenbank
|
profiles.sharedDatabase=gemeinsame Stationsdatenbank
|
||||||
profiles.ownDatabase=eigene Datenbank
|
profiles.ownDatabase=eigene Datenbank
|
||||||
|
|
||||||
|
wizard.title=Einrichtungsassistent
|
||||||
|
wizard.later=Später
|
||||||
|
wizard.back=Zurück
|
||||||
|
wizard.next=Weiter
|
||||||
|
wizard.finish=Fertig
|
||||||
|
wizard.save=Speichern
|
||||||
|
wizard.saveAndConnect=Speichern und verbinden
|
||||||
|
wizard.change=Ändern
|
||||||
|
wizard.saveFailed=Die Einstellungen konnten nicht geschrieben werden. Es wurde nichts geändert.
|
||||||
|
wizard.missing=Es fehlen noch Pflichtangaben. Über „Ändern" ergänzen.
|
||||||
|
wizard.entry.title=Woher kommen die Angaben?
|
||||||
|
wizard.entry.lead=Für Anmeldung und Station getrennt wählen.
|
||||||
|
wizard.entry.login=Anmeldung (Rufzeichen, Passwort)
|
||||||
|
wizard.entry.station=Station (Locator, Bänder, Chatkategorie)
|
||||||
|
wizard.source.loginNew=Anmeldung neu eingeben
|
||||||
|
wizard.source.loginKeep=Anmeldung unverändert lassen ({0})
|
||||||
|
wizard.source.stationNew=Station neu einrichten
|
||||||
|
wizard.source.stationKeep=Station unverändert lassen (Locator {0})
|
||||||
|
wizard.personal.title=Persönliches
|
||||||
|
wizard.personal.lead=Gehört zum Operator.
|
||||||
|
wizard.personal.name=Anzeigename im Chat
|
||||||
|
wizard.personal.nameInvalid=Der Name darf kein Zeichen | enthalten.
|
||||||
|
wizard.login.title=Anmeldung bei ON4KST
|
||||||
|
wizard.login.lead=Die Zugangsdaten deines ON4KST-Kontos.
|
||||||
|
wizard.login.callsignInvalid=Das sieht nicht nach einem Rufzeichen aus.
|
||||||
|
wizard.login.passwordInvalid=Das Passwort darf nicht mit einem Leerzeichen beginnen oder enden und kein Zeichen | enthalten.
|
||||||
|
wizard.site.title=Standort und Bänder
|
||||||
|
wizard.site.lead=Gehört zur Station, nicht zum Operator.
|
||||||
|
wizard.site.locatorInvalid=Sechsstelliger Maidenhead-Locator, zum Beispiel JO50AA.
|
||||||
|
wizard.site.bands=Aktive Bänder
|
||||||
|
wizard.site.bandsHint=Aus den Bändern wird keine Frequenz abgeleitet.
|
||||||
|
wizard.site.categorySuggestion=Vorschlag aus den Bändern: {0}
|
||||||
|
wizard.site.secondChat=Zweiten Chat öffnen
|
||||||
|
wizard.summary.title=Zusammenfassung
|
||||||
|
wizard.summary.lead=Erst „Speichern" schreibt in die Einstellungsdatei.
|
||||||
|
wizard.summary.personal=Persönliches
|
||||||
|
wizard.summary.login=Anmeldung
|
||||||
|
wizard.summary.station=Station
|
||||||
|
wizard.summary.bands=Bänder
|
||||||
|
wizard.summary.none=keine
|
||||||
|
wizard.summary.passwordSet=gesetzt
|
||||||
|
|
||||||
|
menu.setupWizard=Einrichtungsassistent...
|
||||||
|
alert.setupWizardTitle=Einrichtungsassistent
|
||||||
|
alert.setupWizardQuestion=Sitzung beenden und den Einrichtungsassistenten starten?
|
||||||
|
alert.setupWizardBody=Die ON4KST-Verbindung wird geschlossen, und alle Fenster werden nach dem Assistenten neu aufgebaut. Für einzelne Änderungen im laufenden Betrieb ist das Einstellungsfenster da.
|
||||||
|
dialog.startSetupWizard=Assistent starten
|
||||||
|
wizard.antenna.title=Antenne und Leistung
|
||||||
|
wizard.antenna.lead=Freiwillig. Die Werte speisen die Pfadanalyse und den Antennensektor auf der Karte; für den Chat braucht sie niemand.
|
||||||
|
wizard.antenna.aslHint=Standorthöhe leer lassen, dann entscheidet das Höhenmodell.
|
||||||
|
wizard.log.title=Logprogramm
|
||||||
|
wizard.log.lead=Woher kommen deine gearbeiteten Stationen?
|
||||||
|
wizard.log.none=Keines, kein Abgleich
|
||||||
|
wizard.log.wintest=Win-Test
|
||||||
|
wizard.log.udp=UCXLog, DXLog.net, N1MM+ oder QARTEST
|
||||||
|
wizard.log.file=Eine Logdatei
|
||||||
|
wizard.log.qrgFollow=Eigene Frequenz aus dem Logprogramm übernehmen
|
||||||
|
wizard.log.clusterServer=Spots über den lokalen DX-Cluster-Server an das Logprogramm geben
|
||||||
|
wizard.log.incomplete=Die Angaben zu diesem Logprogramm sind unvollständig oder außerhalb des Bereichs.
|
||||||
|
wizard.gear.title=Rotor und AirScout
|
||||||
|
wizard.gear.lead=Nur was wirklich vorhanden ist.
|
||||||
|
wizard.gear.rotator=PSTRotator wird benutzt
|
||||||
|
wizard.gear.airScout=AirScout wird benutzt
|
||||||
|
wizard.gear.incomplete=Die Angaben auf dieser Seite sind unvollständig oder außerhalb des Bereichs.
|
||||||
|
wizard.switch.secondChat=Zweitchat
|
||||||
|
wizard.switch.logWintest=Win-Test-Abgleich
|
||||||
|
wizard.switch.logUdp=Netzwerk-Logabgleich
|
||||||
|
wizard.switch.logFile=Logdatei-Abgleich
|
||||||
|
wizard.switch.qrgFollow=Frequenz aus dem Logprogramm
|
||||||
|
wizard.switch.clusterServer=DX-Cluster-Server
|
||||||
|
wizard.switch.rotator=PSTRotator
|
||||||
|
wizard.switch.airScout=AirScout
|
||||||
|
wizard.summary.antenna=Antenne und Leistung
|
||||||
|
wizard.summary.log=Logprogramm
|
||||||
|
wizard.summary.gear=Rotor und AirScout
|
||||||
|
wizard.summary.qrgFollow=Eigene Frequenz aus dem Logprogramm
|
||||||
|
wizard.summary.clusterServer=DX-Cluster-Server
|
||||||
|
wizard.summary.yes=ja
|
||||||
|
wizard.summary.no=nein
|
||||||
|
wizard.summary.switchedOff=Wird abgeschaltet: {0}.
|
||||||
|
wizard.summary.logSeveral=In diesem Profil sind mehrere Logquellen eingeschaltet. Im Einstellungsfenster ändern.
|
||||||
|
|
||||||
|
wizard.source.loginTake=Anmeldung von Profil „{0}" übernehmen ({1})
|
||||||
|
wizard.source.loginTakeFrom=Anmeldung von einem anderen Profil übernehmen
|
||||||
|
wizard.source.stationTake=Station von Profil „{0}" übernehmen (Locator {1})
|
||||||
|
wizard.source.stationTakeFrom=Station von einem anderen Profil übernehmen
|
||||||
|
wizard.entry.donor=Profil
|
||||||
|
wizard.summary.takenFrom=Übernommen von Profil „{0}"
|
||||||
|
wizard.switch.so2r=SO2R
|
||||||
|
wizard.switch.rotator2=PSTRotator 2
|
||||||
|
wizard.summary.fallbackBand=Ausweichband für Spots
|
||||||
@@ -131,6 +131,9 @@ station.password=Password
|
|||||||
station.pathSection=Path analysis defaults
|
station.pathSection=Path analysis defaults
|
||||||
station.qtf=QTF
|
station.qtf=QTF
|
||||||
station.rotatorEnabled=Rotator sync enabled
|
station.rotatorEnabled=Rotator sync enabled
|
||||||
|
station.manualAntennaHeadingSection=Manual antenna heading
|
||||||
|
station.manualAntennaHeadingRotatorHint=Unavailable while PSTRotator 1 is enabled
|
||||||
|
station.useQtfFilterDirectionAsAntennaHeading=Use QTF filter direction as antenna heading
|
||||||
station.rotatorHost=Rotator host
|
station.rotatorHost=Rotator host
|
||||||
station.rotatorPort=Rotator port
|
station.rotatorPort=Rotator port
|
||||||
station.rotatorSection=PSTRotator
|
station.rotatorSection=PSTRotator
|
||||||
@@ -265,18 +268,26 @@ filter.onlyNewGrids=Only new grids
|
|||||||
filter.gridColour=Grid color
|
filter.gridColour=Grid color
|
||||||
filter.newBands=New bands
|
filter.newBands=New bands
|
||||||
filter.tropo=Tropo >=0dB
|
filter.tropo=Tropo >=0dB
|
||||||
|
filter.hide=Hide
|
||||||
|
filter.show=Show
|
||||||
|
filter.reachability=Reachability
|
||||||
|
filter.calcSelected=Calc selected
|
||||||
|
table.empty=No entries
|
||||||
selected.none=No station selected.
|
selected.none=No station selected.
|
||||||
selected.priority=Priority:
|
selected.priority=Priority:
|
||||||
|
selected.newJoined=New joined:
|
||||||
selected.more=more
|
selected.more=more
|
||||||
selected.showMessages=Show messages
|
selected.showMessages=Show messages
|
||||||
selected.createSked=Create sked
|
selected.createSked=Create sked
|
||||||
selected.sked=Sked
|
selected.sked=Sked alert
|
||||||
selected.skedInMinutes=Sked in (min)
|
selected.skedIn=Sked in
|
||||||
|
selected.skedMinutesAt=min, at
|
||||||
|
selected.skedModeLink=, mode
|
||||||
|
selected.minutes=min
|
||||||
selected.skedFail=Sked fail
|
selected.skedFail=Sked fail
|
||||||
selected.remindPmIn=Remind-PM in
|
selected.remindPmIn=Remind pm in
|
||||||
selected.reminderOffsets=Reminder offsets
|
|
||||||
selected.resetFail=Reset fail
|
selected.resetFail=Reset fail
|
||||||
selected.tagNotQrv=Tag not QRV
|
selected.tagNotQrv=Tag {0} not QRV at bands:
|
||||||
selected.band=Band
|
selected.band=Band
|
||||||
selected.mode=Mode
|
selected.mode=Mode
|
||||||
selected.lookUpAndShow=Look up and show
|
selected.lookUpAndShow=Look up and show
|
||||||
@@ -289,6 +300,12 @@ selected.lastActivity=Last activity: {0} ({1} min ago)
|
|||||||
candidates.title=Top priority candidates
|
candidates.title=Top priority candidates
|
||||||
candidates.none=No candidates yet.
|
candidates.none=No candidates yet.
|
||||||
candidates.doubleClick=Double-click a candidate to select it.
|
candidates.doubleClick=Double-click a candidate to select it.
|
||||||
|
timeline.inBeam1=In beam 1
|
||||||
|
timeline.inBeam2=In beam 2
|
||||||
|
timeline.priority1=Priority 1
|
||||||
|
timeline.priority2=Priority 2
|
||||||
|
timeline.skeds=Skeds
|
||||||
|
timeline.minuteSuffix=min
|
||||||
update.title=Update information
|
update.title=Update information
|
||||||
update.available=Update available!
|
update.available=Update available!
|
||||||
update.installedVersion=Installed version:
|
update.installedVersion=Installed version:
|
||||||
@@ -303,12 +320,17 @@ update.versions=Versions
|
|||||||
map.title=Station Map
|
map.title=Station Map
|
||||||
map.tab=Map
|
map.tab=Map
|
||||||
map.resetView=Reset view
|
map.resetView=Reset view
|
||||||
map.groupNearby=Group nearby stations
|
map.groupNearby=Grouping
|
||||||
|
map.groupNearbyTooltip=Group stations that are close together on the map.
|
||||||
|
map.alwaysOnTop=Always on top
|
||||||
map.triggerClusterSpot=Trigger cluster spot
|
map.triggerClusterSpot=Trigger cluster spot
|
||||||
map.showPathAnalysis=Show path analysis
|
map.showPathAnalysis=Show path analysis
|
||||||
map.hidePathAnalysis=Hide path analysis
|
map.hidePathAnalysis=Hide path analysis
|
||||||
map.pathAnalysisHidden=Path analysis is hidden.
|
map.pathAnalysisHidden=Path analysis is hidden.
|
||||||
map.tilesUnavailable=Map tiles unavailable — check the network connection.
|
map.tilesUnavailable=Map tiles unavailable — check the network connection.
|
||||||
|
map.overlayAntenna=Antenna
|
||||||
|
map.overlayFilters=Active filters
|
||||||
|
map.overlayLegendTooltip=Red: actual antenna heading, beamwidth and maximum QRB. Blue: active QTF and QRB filters.
|
||||||
path.title=Path / terrain analysis
|
path.title=Path / terrain analysis
|
||||||
path.selectStation=Select a station to prepare path and terrain analysis.
|
path.selectStation=Select a station to prepare path and terrain analysis.
|
||||||
path.fromLocator=From locator:
|
path.fromLocator=From locator:
|
||||||
@@ -428,6 +450,16 @@ dialog.apply=Apply
|
|||||||
chat.clear=clear
|
chat.clear=clear
|
||||||
selected.showOnMap=🗺 Show on map
|
selected.showOnMap=🗺 Show on map
|
||||||
selected.notQrvAll=all
|
selected.notQrvAll=all
|
||||||
|
context.messageSnippets=Message snippets
|
||||||
|
context.createSked=Create sked…
|
||||||
|
context.tagNotQrv=Tag NOT QRV
|
||||||
|
context.markWorked=Mark as worked
|
||||||
|
context.calculateReachability=Calculate reachability
|
||||||
|
context.chooseStation=Choose station
|
||||||
|
context.back=Back
|
||||||
|
context.category=Category {0}
|
||||||
|
context.skedTitle=Create sked for {0}
|
||||||
|
context.cancel=Cancel
|
||||||
column.category=Category
|
column.category=Category
|
||||||
column.sender=Sender
|
column.sender=Sender
|
||||||
column.receiver=Receiver
|
column.receiver=Receiver
|
||||||
@@ -435,8 +467,9 @@ column.lastQrg=Last QRG
|
|||||||
column.airplane=AP [minutes / pot%]
|
column.airplane=AP [minutes / pot%]
|
||||||
column.score=Score
|
column.score=Score
|
||||||
monitor.title=Cluster & QSO of the other
|
monitor.title=Cluster & QSO of the other
|
||||||
|
monitor.dxCluster=DX cluster
|
||||||
profiles.createFailed=The profile could not be created. The profile registry could not be written.
|
profiles.createFailed=The profile could not be created. The profile registry could not be written.
|
||||||
profiles.createdWithoutCredentials=The profile "{0}" was created without callsign and password. Enter them on the Station tab after switching to it.
|
profiles.createdWithoutCredentials=The profile "{0}" was created without callsign and password. After switching to it, the setup assistant asks for both.
|
||||||
profiles.duplicateFailed=The profile could not be duplicated.
|
profiles.duplicateFailed=The profile could not be duplicated.
|
||||||
profiles.rootNotDeletable=The default profile uses the files of the installation itself and cannot be deleted.
|
profiles.rootNotDeletable=The default profile uses the files of the installation itself and cannot be deleted.
|
||||||
profiles.activeNotDeletable=The profile currently in use cannot be deleted. Switch to another profile first.
|
profiles.activeNotDeletable=The profile currently in use cannot be deleted. Switch to another profile first.
|
||||||
@@ -449,7 +482,17 @@ profiles.changeAfterSwitch=The change takes effect after switching to this profi
|
|||||||
profiles.alreadyActive=This profile is already active.
|
profiles.alreadyActive=This profile is already active.
|
||||||
profiles.selectFirst=Select a profile in the table first.
|
profiles.selectFirst=Select a profile in the table first.
|
||||||
beacon.invalidMessage=The beacon message is invalid: {0}
|
beacon.invalidMessage=The beacon message is invalid: {0}
|
||||||
beacon.intervalTooShort=Enter a whole beacon interval of at least {0} minute.
|
beacon.intervalTooShort=Enter a whole beacon interval of at least {0} minutes.
|
||||||
|
beacon.status.main=Main category: {0}
|
||||||
|
beacon.status.second=Second category: {0}
|
||||||
|
beacon.status.enabled=active
|
||||||
|
beacon.status.failed=send failed
|
||||||
|
beacon.status.unavailable=unavailable
|
||||||
|
beacon.reason.session=not activated in this session
|
||||||
|
beacon.reason.user=switched off by the operator
|
||||||
|
beacon.reason.primaryQrg=primary QRG missing or invalid
|
||||||
|
beacon.reason.secondaryQrg=second QRG missing or invalid
|
||||||
|
beacon.reason.automaticQrg=automatic QRG change greater than 5 kHz
|
||||||
notification.invalidPort="{0}" is not a valid TCP port. Enter a value from 1 to 65535.
|
notification.invalidPort="{0}" is not a valid TCP port. Enter a value from 1 to 65535.
|
||||||
notification.invalidSpotter="{0}" is not a valid spotter callsign.
|
notification.invalidSpotter="{0}" is not a valid spotter callsign.
|
||||||
notification.invalidCallsign=Please enter a valid callsign.
|
notification.invalidCallsign=Please enter a valid callsign.
|
||||||
@@ -461,3 +504,95 @@ profiles.unknown=unknown
|
|||||||
profiles.copyOf=Copy of {0}
|
profiles.copyOf=Copy of {0}
|
||||||
profiles.sharedDatabase=common station database
|
profiles.sharedDatabase=common station database
|
||||||
profiles.ownDatabase=own database
|
profiles.ownDatabase=own database
|
||||||
|
|
||||||
|
wizard.title=Setup assistant
|
||||||
|
wizard.later=Later
|
||||||
|
wizard.back=Back
|
||||||
|
wizard.next=Next
|
||||||
|
wizard.finish=Finish
|
||||||
|
wizard.save=Save
|
||||||
|
wizard.saveAndConnect=Save and connect
|
||||||
|
wizard.change=Change
|
||||||
|
wizard.saveFailed=The settings could not be written. Nothing was changed.
|
||||||
|
wizard.missing=Some required entries are still missing. Use Change to complete them.
|
||||||
|
wizard.entry.title=Where do the entries come from?
|
||||||
|
wizard.entry.lead=Choose separately for login and station.
|
||||||
|
wizard.entry.login=Login (callsign, password)
|
||||||
|
wizard.entry.station=Station (locator, bands, chat category)
|
||||||
|
wizard.source.loginNew=Enter a new login
|
||||||
|
wizard.source.loginKeep=Leave the login unchanged ({0})
|
||||||
|
wizard.source.stationNew=Set up a new station
|
||||||
|
wizard.source.stationKeep=Leave the station unchanged (locator {0})
|
||||||
|
wizard.personal.title=Personal
|
||||||
|
wizard.personal.lead=Belongs to the operator.
|
||||||
|
wizard.personal.name=Name shown in the chat
|
||||||
|
wizard.personal.nameInvalid=The name must not contain a | character.
|
||||||
|
wizard.login.title=ON4KST login
|
||||||
|
wizard.login.lead=The credentials of your ON4KST account.
|
||||||
|
wizard.login.callsignInvalid=This does not look like a callsign.
|
||||||
|
wizard.login.passwordInvalid=The password must not begin or end with a blank and must not contain a | character.
|
||||||
|
wizard.site.title=Location and bands
|
||||||
|
wizard.site.lead=Belongs to the station, not to the operator.
|
||||||
|
wizard.site.locatorInvalid=Six-character Maidenhead locator, for example JO50AA.
|
||||||
|
wizard.site.bands=Active bands
|
||||||
|
wizard.site.bandsHint=No frequency is derived from the bands.
|
||||||
|
wizard.site.categorySuggestion=Suggested from the bands: {0}
|
||||||
|
wizard.site.secondChat=Open a second chat
|
||||||
|
wizard.summary.title=Summary
|
||||||
|
wizard.summary.lead=Nothing is written until you save.
|
||||||
|
wizard.summary.personal=Personal
|
||||||
|
wizard.summary.login=Login
|
||||||
|
wizard.summary.station=Station
|
||||||
|
wizard.summary.bands=Bands
|
||||||
|
wizard.summary.none=none
|
||||||
|
wizard.summary.passwordSet=set
|
||||||
|
|
||||||
|
menu.setupWizard=Setup assistant...
|
||||||
|
alert.setupWizardTitle=Setup assistant
|
||||||
|
alert.setupWizardQuestion=End the session and start the setup assistant?
|
||||||
|
alert.setupWizardBody=The ON4KST connection is closed and all windows are rebuilt after the assistant. For single changes during operation use the settings window.
|
||||||
|
dialog.startSetupWizard=Start assistant
|
||||||
|
wizard.antenna.title=Antenna and power
|
||||||
|
wizard.antenna.lead=Optional. These values feed the path analysis and the antenna sector on the map; the chat does not need them.
|
||||||
|
wizard.antenna.aslHint=Leave the site elevation empty to let the elevation model decide.
|
||||||
|
wizard.log.title=Log program
|
||||||
|
wizard.log.lead=Where do your worked stations come from?
|
||||||
|
wizard.log.none=None, no synchronisation
|
||||||
|
wizard.log.wintest=Win-Test
|
||||||
|
wizard.log.udp=UCXLog, DXLog.net, N1MM+ or QARTEST
|
||||||
|
wizard.log.file=A log file
|
||||||
|
wizard.log.qrgFollow=Take my own frequency from the log program
|
||||||
|
wizard.log.clusterServer=Pass spots to the log program through the local DX cluster server
|
||||||
|
wizard.log.incomplete=The entries for this log program are incomplete or out of range.
|
||||||
|
wizard.gear.title=Rotator and AirScout
|
||||||
|
wizard.gear.lead=Only what is really there.
|
||||||
|
wizard.gear.rotator=PSTRotator is in use
|
||||||
|
wizard.gear.airScout=AirScout is in use
|
||||||
|
wizard.gear.incomplete=The entries on this page are incomplete or out of range.
|
||||||
|
wizard.switch.secondChat=second chat
|
||||||
|
wizard.switch.logWintest=Win-Test synchronisation
|
||||||
|
wizard.switch.logUdp=network log synchronisation
|
||||||
|
wizard.switch.logFile=log file polling
|
||||||
|
wizard.switch.qrgFollow=frequency from the log program
|
||||||
|
wizard.switch.clusterServer=DX cluster server
|
||||||
|
wizard.switch.rotator=PSTRotator
|
||||||
|
wizard.switch.airScout=AirScout
|
||||||
|
wizard.summary.antenna=Antenna and power
|
||||||
|
wizard.summary.log=Log program
|
||||||
|
wizard.summary.gear=Rotator and AirScout
|
||||||
|
wizard.summary.qrgFollow=Own frequency from the log program
|
||||||
|
wizard.summary.clusterServer=DX cluster server
|
||||||
|
wizard.summary.yes=yes
|
||||||
|
wizard.summary.no=no
|
||||||
|
wizard.summary.switchedOff=Will be switched off: {0}.
|
||||||
|
wizard.summary.logSeveral=Several log sources are enabled in this profile. Change them in the settings window.
|
||||||
|
|
||||||
|
wizard.source.loginTake=Take the login from profile "{0}" ({1})
|
||||||
|
wizard.source.loginTakeFrom=Take the login from another profile
|
||||||
|
wizard.source.stationTake=Take the station from profile "{0}" (locator {1})
|
||||||
|
wizard.source.stationTakeFrom=Take the station from another profile
|
||||||
|
wizard.entry.donor=Profile
|
||||||
|
wizard.summary.takenFrom=Taken from profile "{0}"
|
||||||
|
wizard.switch.so2r=SO2R
|
||||||
|
wizard.switch.rotator2=PSTRotator 2
|
||||||
|
wizard.summary.fallbackBand=Fallback band for spots
|
||||||
@@ -4,6 +4,7 @@ import kst4contest.controller.ActiveOperatorProfile;
|
|||||||
import kst4contest.controller.OperatorProfilePaths;
|
import kst4contest.controller.OperatorProfilePaths;
|
||||||
import kst4contest.controller.OperatorProfileStore;
|
import kst4contest.controller.OperatorProfileStore;
|
||||||
import kst4contest.model.OperatorProfile;
|
import kst4contest.model.OperatorProfile;
|
||||||
|
import kst4contest.model.OperatorProfileSelection;
|
||||||
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -24,6 +25,20 @@ public final class ApplicationRuntimeLauncher {
|
|||||||
|
|
||||||
private static Kst4ContestApplication currentRuntime;
|
private static Kst4ContestApplication currentRuntime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the next runtime start shows the setup wizard although the profile is set up.
|
||||||
|
* Set by the menu entry and cleared by the start that honours it.
|
||||||
|
*/
|
||||||
|
private static final java.util.concurrent.atomic.AtomicBoolean SETUP_WIZARD_REQUESTED =
|
||||||
|
new java.util.concurrent.atomic.AtomicBoolean(false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Guards {@link #switchProfile(OperatorProfile)} against re-entry while window teardown
|
||||||
|
* inside {@link Kst4ContestApplication#shutdownRuntime()} is still pumping events.
|
||||||
|
*/
|
||||||
|
private static final java.util.concurrent.atomic.AtomicBoolean SWITCH_IN_PROGRESS =
|
||||||
|
new java.util.concurrent.atomic.AtomicBoolean(false);
|
||||||
|
|
||||||
private ApplicationRuntimeLauncher() {
|
private ApplicationRuntimeLauncher() {
|
||||||
// Utility class.
|
// Utility class.
|
||||||
}
|
}
|
||||||
@@ -61,14 +76,100 @@ public final class ApplicationRuntimeLauncher {
|
|||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Asks the next runtime start to show the setup wizard. */
|
||||||
|
static void requestSetupWizard() {
|
||||||
|
SETUP_WIZARD_REQUESTED.set(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells a starting runtime whether the wizard was asked for, and forgets the request.
|
||||||
|
*
|
||||||
|
* @return true exactly once per request
|
||||||
|
*/
|
||||||
|
static boolean consumeSetupWizardRequest() {
|
||||||
|
return SETUP_WIZARD_REQUESTED.getAndSet(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks a profile switch as in progress if none is currently running.
|
||||||
|
*
|
||||||
|
* @return true if this call obtained the mark
|
||||||
|
*/
|
||||||
|
static boolean beginSwitch() {
|
||||||
|
return SWITCH_IN_PROGRESS.compareAndSet(false, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Clears the in-progress mark of a profile switch. */
|
||||||
|
static void endSwitch() {
|
||||||
|
SWITCH_IN_PROGRESS.set(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rebuilds the runtime of the active profile with the setup wizard in front of it.
|
||||||
|
*
|
||||||
|
* <p>The running runtime is torn down first and the wizard shown afterwards, not the
|
||||||
|
* other way round: a runtime shutting down flushes its pending layout write, and that
|
||||||
|
* must not land on the file the wizard has just written.</p>
|
||||||
|
*
|
||||||
|
* <p>The wizard is requested only once this call owns the switch. A call refused
|
||||||
|
* because a switch is already under way therefore leaves that switch's request alone:
|
||||||
|
* clearing it would let the running switch end the session and then start without the
|
||||||
|
* wizard it was made for.</p>
|
||||||
|
*
|
||||||
|
* @return true if the new runtime was built
|
||||||
|
*/
|
||||||
|
public static boolean rerunSetupWizard() {
|
||||||
|
OperatorProfileSelection active = ActiveOperatorProfile.get();
|
||||||
|
|
||||||
|
if (active == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!beginSwitch()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
requestSetupWizard();
|
||||||
|
|
||||||
|
boolean switched = false;
|
||||||
|
try {
|
||||||
|
switched = performSwitch(active.getProfile());
|
||||||
|
} finally {
|
||||||
|
if (!switched) {
|
||||||
|
// The request is this call's own, and no start consumed it.
|
||||||
|
consumeSetupWizardRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return switched;
|
||||||
|
} finally {
|
||||||
|
endSwitch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces the running runtime with one bound to another operator profile.
|
* Replaces the running runtime with one bound to another operator profile.
|
||||||
*
|
*
|
||||||
* @param targetProfile profile to activate
|
* @param targetProfile profile to activate
|
||||||
* @return true if the new runtime was built
|
* @return true if the new runtime was built; false also when another switch is
|
||||||
|
* already under way
|
||||||
*/
|
*/
|
||||||
public static boolean switchProfile(final OperatorProfile targetProfile) {
|
public static boolean switchProfile(final OperatorProfile targetProfile) {
|
||||||
|
|
||||||
|
if (!beginSwitch()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return performSwitch(targetProfile);
|
||||||
|
} finally {
|
||||||
|
endSwitch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The switch itself. The caller holds the switch-in-progress mark. */
|
||||||
|
private static boolean performSwitch(final OperatorProfile targetProfile) {
|
||||||
|
|
||||||
if (targetProfile == null) {
|
if (targetProfile == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package kst4contest.view;
|
package kst4contest.view;
|
||||||
|
|
||||||
|
import kst4contest.controller.RadioSlot;
|
||||||
import kst4contest.model.ChatCategory;
|
import kst4contest.model.ChatCategory;
|
||||||
import kst4contest.model.ChatMember;
|
import kst4contest.model.ChatMember;
|
||||||
import kst4contest.model.ChatMessage;
|
import kst4contest.model.ChatMessage;
|
||||||
@@ -97,4 +98,9 @@ public final class ComposeChatInputActions implements ChatInputActions {
|
|||||||
String value = application.chatcontroller.getChatPreferences().getMYQRGSecondCat().get();
|
String value = application.chatcontroller.getChatPreferences().getMYQRGSecondCat().get();
|
||||||
return value == null ? "" : value;
|
return value == null ? "" : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void applyManualQrg(final RadioSlot slot, final String value) {
|
||||||
|
application.chatcontroller.applyManualQrg(slot, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -54,6 +54,11 @@ public final class ComposeMenuActions implements MainMenuActions {
|
|||||||
application.runOnUi(application::menuActionToggleSettingsWindow);
|
application.runOnUi(application::menuActionToggleSettingsWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void openSetupWizard() {
|
||||||
|
application.runOnUi(application::menuActionOpenSetupWizard);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toggleMonitorWindow() {
|
public void toggleMonitorWindow() {
|
||||||
application.runOnUi(application::menuActionToggleMonitorWindow);
|
application.runOnUi(application::menuActionToggleMonitorWindow);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import kst4contest.view.compose.DataTableState;
|
|||||||
import kst4contest.view.compose.MonitorColumns;
|
import kst4contest.view.compose.MonitorColumns;
|
||||||
import kst4contest.view.compose.MonitorWindow;
|
import kst4contest.view.compose.MonitorWindow;
|
||||||
import kst4contest.view.compose.RowKeys;
|
import kst4contest.view.compose.RowKeys;
|
||||||
|
import kst4contest.view.compose.ReachabilityState;
|
||||||
import kst4contest.view.compose.BlinkingNotice;
|
import kst4contest.view.compose.BlinkingNotice;
|
||||||
import kst4contest.view.compose.ThreadStatusButtons;
|
import kst4contest.view.compose.ThreadStatusButtons;
|
||||||
import kst4contest.view.compose.StationColumns;
|
import kst4contest.view.compose.StationColumns;
|
||||||
@@ -18,9 +19,16 @@ import kst4contest.view.compose.DirectedMessageColumns;
|
|||||||
import kst4contest.view.compose.PublicMessageColumns;
|
import kst4contest.view.compose.PublicMessageColumns;
|
||||||
import kst4contest.view.compose.SelectedMessageFilter;
|
import kst4contest.view.compose.SelectedMessageFilter;
|
||||||
import kst4contest.view.compose.SelectedStationMessageColumns;
|
import kst4contest.view.compose.SelectedStationMessageColumns;
|
||||||
|
import kst4contest.view.compose.SelectedStationMessagePredicate;
|
||||||
import kst4contest.view.compose.SelectedStationState;
|
import kst4contest.view.compose.SelectedStationState;
|
||||||
|
import kst4contest.view.compose.DirectedMessageStationTarget;
|
||||||
|
import kst4contest.view.compose.StationIdentity;
|
||||||
|
import kst4contest.view.compose.StationSelectionSource;
|
||||||
|
import kst4contest.view.compose.StationSelectionState;
|
||||||
import kst4contest.view.compose.TopPriorityCandidatesWindow;
|
import kst4contest.view.compose.TopPriorityCandidatesWindow;
|
||||||
import kst4contest.view.compose.TopPriorityState;
|
import kst4contest.view.compose.TopPriorityState;
|
||||||
|
import kst4contest.view.compose.NewJoinedState;
|
||||||
|
import kst4contest.view.compose.SkedRequest;
|
||||||
import kst4contest.view.compose.TimelineState;
|
import kst4contest.view.compose.TimelineState;
|
||||||
import kst4contest.view.compose.ChatInputState;
|
import kst4contest.view.compose.ChatInputState;
|
||||||
import kst4contest.view.compose.MainMenuState;
|
import kst4contest.view.compose.MainMenuState;
|
||||||
@@ -34,6 +42,8 @@ import kst4contest.view.compose.SettingsWindow;
|
|||||||
import kst4contest.controller.ScoreService;
|
import kst4contest.controller.ScoreService;
|
||||||
import kst4contest.view.compose.SettingsWindow;
|
import kst4contest.view.compose.SettingsWindow;
|
||||||
import kst4contest.controller.On4KstConnectionState;
|
import kst4contest.controller.On4KstConnectionState;
|
||||||
|
import kst4contest.view.compose.wizard.SetupWizardLauncher;
|
||||||
|
import kst4contest.view.compose.wizard.SetupWizardOutcome;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -77,6 +87,9 @@ import kst4contest.controller.OperatorProfilePaths;
|
|||||||
import kst4contest.model.OperatorProfile;
|
import kst4contest.model.OperatorProfile;
|
||||||
import kst4contest.model.OperatorProfileSelection;
|
import kst4contest.model.OperatorProfileSelection;
|
||||||
import kst4contest.view.map.OfflineDemImportService;
|
import kst4contest.view.map.OfflineDemImportService;
|
||||||
|
import kst4contest.view.map.MapCallsignRawSnapshot;
|
||||||
|
import kst4contest.view.map.MapCallsignRawSnapshotBuilder;
|
||||||
|
import kst4contest.view.map.PathAnalysisResult;
|
||||||
import kst4contest.controller.WorkedGrossFieldCache;
|
import kst4contest.controller.WorkedGrossFieldCache;
|
||||||
|
|
||||||
|
|
||||||
@@ -121,8 +134,6 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
private Predicate<ChatMember> lastAppliedChatMemberFilterPredicate = null;
|
private Predicate<ChatMember> lastAppliedChatMemberFilterPredicate = null;
|
||||||
|
|
||||||
|
|
||||||
private Band selectedReachabilityBandOverride = null;
|
|
||||||
|
|
||||||
private kst4contest.view.feed.TimelineFeed timelineFeed;
|
private kst4contest.view.feed.TimelineFeed timelineFeed;
|
||||||
private kst4contest.view.feed.SelectedStationMessagesFeed selectedStationMessagesFeed;
|
private kst4contest.view.feed.SelectedStationMessagesFeed selectedStationMessagesFeed;
|
||||||
private kst4contest.view.feed.ConnectionStateFeed connectionStateFeed;
|
private kst4contest.view.feed.ConnectionStateFeed connectionStateFeed;
|
||||||
@@ -264,6 +275,20 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Applies one radio mode to one exact station identity. */
|
||||||
|
private void applySelectedStationMessageFilter(
|
||||||
|
SelectedMessageFilter filter,
|
||||||
|
ChatMember selectedMember) {
|
||||||
|
if (filter == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
applySelectedCallSignInfoFilter(SelectedStationMessagePredicate.forSelection(
|
||||||
|
filter,
|
||||||
|
selectedMember,
|
||||||
|
chatcontroller.getChatPreferences().getStn_loginCallSign()));
|
||||||
|
}
|
||||||
|
|
||||||
/** Follows the PSTRotator QTF in the text field; replaces a JavaFX string binding. */
|
/** Follows the PSTRotator QTF in the text field; replaces a JavaFX string binding. */
|
||||||
|
|
||||||
|
|
||||||
@@ -2154,6 +2179,17 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The setup wizard, before anything of this profile's runtime exists. It writes
|
||||||
|
* preferences.xml and the ChatController built below reads it like any stored
|
||||||
|
* setting, so there is no running session to bring up to date and no reload.
|
||||||
|
* Blocks until the wizard is closed; see SetupWizardWindow for why that is safe on
|
||||||
|
* either thread this method is called from.
|
||||||
|
*/
|
||||||
|
SetupWizardOutcome setupWizardOutcome = SetupWizardLauncher.runIfNeeded(
|
||||||
|
ActiveOperatorProfile.get().getPreferencesRelativeFileName(),
|
||||||
|
ApplicationRuntimeLauncher.consumeSetupWizardRequest());
|
||||||
|
|
||||||
ApplicationRuntimeLauncher.setCurrent(this);
|
ApplicationRuntimeLauncher.setCurrent(this);
|
||||||
|
|
||||||
ApplicationFileUtils.copyResourceIfRequired(ApplicationConstants.APPLICATION_NAME, STYLE_DEFAULTCSSDAY_RESOURCE, STYLE_DEFAULTCSSDAY_FILE);
|
ApplicationFileUtils.copyResourceIfRequired(ApplicationConstants.APPLICATION_NAME, STYLE_DEFAULTCSSDAY_RESOURCE, STYLE_DEFAULTCSSDAY_FILE);
|
||||||
@@ -2274,6 +2310,15 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
//initialize the timeline
|
//initialize the timeline
|
||||||
uiDispatcher.runOnUi(this::updateTimelineVisuals);
|
uiDispatcher.runOnUi(this::updateTimelineVisuals);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* "Save and connect" in the setup wizard. Here and not earlier: connecting needs the
|
||||||
|
* runtime this method has just finished building. The same path as File -> Connect,
|
||||||
|
* so a refused or failed connection is reported the way it is there.
|
||||||
|
*/
|
||||||
|
if (setupWizardOutcome == SetupWizardOutcome.SAVED_AND_CONNECT) {
|
||||||
|
uiDispatcher.runOnUi(this::menuActionConnect);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Replaces Application.stop(), which only JavaFX ever called. This covers a SIGTERM
|
* Replaces Application.stop(), which only JavaFX ever called. This covers a SIGTERM
|
||||||
* and a closing terminal; the ordinary exit still goes through
|
* and a closing terminal; the ordinary exit still goes through
|
||||||
@@ -2520,7 +2565,7 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Path logFile = Path.of(ApplicationFileUtils.getFilePath(
|
Path logFile = Path.of(ApplicationFileUtils.getDebugFilePath(
|
||||||
ApplicationConstants.APPLICATION_NAME,
|
ApplicationConstants.APPLICATION_NAME,
|
||||||
"kst4contest-errors.log"));
|
"kst4contest-errors.log"));
|
||||||
// Start conservatively until the persisted preference has been loaded.
|
// Start conservatively until the persisted preference has been loaded.
|
||||||
@@ -3005,9 +3050,24 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
*/
|
*/
|
||||||
private kst4contest.view.i18n.LanguageStore languageStore;
|
private kst4contest.view.i18n.LanguageStore languageStore;
|
||||||
private java.util.function.Consumer<java.util.List<ChatMember>> composeMemberListener;
|
private java.util.function.Consumer<java.util.List<ChatMember>> composeMemberListener;
|
||||||
|
private java.util.function.Consumer<java.util.List<RecentChatJoin>> composeRecentJoinListener;
|
||||||
private java.util.function.Consumer<java.util.List<ChatMessage>> composeChatListener;
|
private java.util.function.Consumer<java.util.List<ChatMessage>> composeChatListener;
|
||||||
private java.util.function.Consumer<java.util.List<ClusterMessage>> composeClusterListener;
|
private java.util.function.Consumer<java.util.List<ClusterMessage>> composeClusterListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fills the three global Compose message tables from their filtered
|
||||||
|
* controller views.
|
||||||
|
*/
|
||||||
|
/* package */ static void refreshComposeMessageTables(
|
||||||
|
final ChatController controller,
|
||||||
|
final DataTableState<ChatMessage> directed,
|
||||||
|
final DataTableState<ChatMessage> publicMessages,
|
||||||
|
final DataTableState<ChatMessage> qsoOfTheOther) {
|
||||||
|
directed.replaceRows(controller.toMeMessages());
|
||||||
|
publicMessages.replaceRows(controller.toAllMessages());
|
||||||
|
qsoOfTheOther.replaceRows(controller.toOtherMessages());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens the Compose main window beside the JavaFX one.
|
* Opens the Compose main window beside the JavaFX one.
|
||||||
*
|
*
|
||||||
@@ -3050,20 +3110,45 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
* arrange separately while both windows are on screen; sharing the ids would let a
|
* arrange separately while both windows are on screen; sharing the ids would let a
|
||||||
* drag in one silently rearrange the other.
|
* drag in one silently rearrange the other.
|
||||||
*/
|
*/
|
||||||
|
EnumSet<Band> enabledStationBands =
|
||||||
|
BandOpportunityResolver.getEnabledStationBands(chatcontroller.getChatPreferences());
|
||||||
|
ReachabilityState reachability = new ReachabilityState(
|
||||||
|
enabledStationBands,
|
||||||
|
member -> chatcontroller.getReachabilityService().resolveAutoBand(member),
|
||||||
|
() -> composeMainWindowState == null
|
||||||
|
? null : composeMainWindowState.getSelectedStation().getSelected(),
|
||||||
|
(member, band) -> {
|
||||||
|
chatcontroller.getReachabilityService()
|
||||||
|
.calculateSelectedStationOnDemand(member, band);
|
||||||
|
return kotlin.Unit.INSTANCE;
|
||||||
|
},
|
||||||
|
() -> {
|
||||||
|
forceChatMemberFilterRefresh();
|
||||||
|
if (composeMainWindowState != null) {
|
||||||
|
composeMainWindowState.getStations().forceRedraw();
|
||||||
|
}
|
||||||
|
return kotlin.Unit.INSTANCE;
|
||||||
|
});
|
||||||
|
StationSelectionState stationSelection = new StationSelectionState();
|
||||||
|
|
||||||
DataTableState<ChatMember> stations = new DataTableState<>(
|
DataTableState<ChatMember> stations = new DataTableState<>(
|
||||||
StationColumns.INSTANCE.all(
|
StationColumns.INSTANCE.all(
|
||||||
member -> {
|
member -> {
|
||||||
Band band = resolveReachabilityBandForUi(member);
|
Band band = reachability.resolveBand(member);
|
||||||
chatcontroller.getReachabilityService()
|
chatcontroller.getReachabilityService()
|
||||||
.ensureTropoMarginCalculated(member, band);
|
.ensureTropoMarginCalculated(member, band);
|
||||||
return member.formatTropoSsbMarginForBand(band);
|
return member.formatTropoSsbMarginForBand(band);
|
||||||
},
|
},
|
||||||
member -> parseTableDouble(formatPriorityScore(member)),
|
member -> parseTableDouble(formatPriorityScore(member)),
|
||||||
(member, band, worked) -> formatBandCellStatus(member, band, worked),
|
(member, band, worked) -> formatBandCellStatus(member, band, worked),
|
||||||
BandOpportunityResolver.getEnabledStationBands(chatcontroller.getChatPreferences())),
|
enabledStationBands),
|
||||||
RowKeys.INSTANCE.byValue(StationColumns.INSTANCE::rowKey),
|
RowKeys.INSTANCE.byValue(StationColumns.INSTANCE::rowKey),
|
||||||
"compose-stations",
|
"compose-stations",
|
||||||
widths);
|
widths,
|
||||||
|
"callsign",
|
||||||
|
true,
|
||||||
|
stationSelection,
|
||||||
|
true);
|
||||||
|
|
||||||
DataTableState<ChatMessage> directed = new DataTableState<>(
|
DataTableState<ChatMessage> directed = new DataTableState<>(
|
||||||
DirectedMessageColumns.INSTANCE.all(
|
DirectedMessageColumns.INSTANCE.all(
|
||||||
@@ -3115,44 +3200,7 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
if (filter == null) {
|
if (filter == null) {
|
||||||
return kotlin.Unit.INSTANCE;
|
return kotlin.Unit.INSTANCE;
|
||||||
}
|
}
|
||||||
Predicate<ChatMessage> predicate;
|
applySelectedStationMessageFilter(filter, selectedCallSignInfoStageChatMember);
|
||||||
switch (filter) {
|
|
||||||
case PM_TO_ME:
|
|
||||||
predicate = chatMessage -> {
|
|
||||||
try {
|
|
||||||
if (chatMessage.getReceiver().getCallSign().equals("ALL") && !(chatMessage.getMessageText().toLowerCase().contains(chatcontroller.getChatPreferences().getStn_loginCallSign().toLowerCase()))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return ((chatMessage.getReceiver().getCallSign().equals(chatcontroller.getChatPreferences().getStn_loginCallSign())) || (chatMessage.getSender().getCallSign().equals(chatcontroller.getChatPreferences().getStn_loginCallSign()))) &&
|
|
||||||
((chatMessage.getReceiver().getCallSign().equals(selectedCallSignInfoStageChatMember.getCallSign())) || (chatMessage.getSender().getCallSign().equals(selectedCallSignInfoStageChatMember.getCallSign())));
|
|
||||||
} catch (Exception e) { return false; }
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case PM_TO_OTHER:
|
|
||||||
predicate = chatMessage -> {
|
|
||||||
try {
|
|
||||||
return (chatMessage.getSender().getCallSign().equals(selectedCallSignInfoStageChatMember.getCallSign()) && !chatMessage.getReceiver().getCallSign().equals("ALL") && !chatMessage.getReceiver().getCallSign().equals(chatcontroller.getChatPreferences().getStn_loginCallSign())) ||
|
|
||||||
(chatMessage.getReceiver().getCallSign().equals(selectedCallSignInfoStageChatMember.getCallSign()) && !chatMessage.getReceiver().getCallSign().equals("ALL") && !chatMessage.getReceiver().getCallSign().equals(chatcontroller.getChatPreferences().getStn_loginCallSign()));
|
|
||||||
} catch (Exception e) { return false; }
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case PUBLIC:
|
|
||||||
predicate = chatMessage -> {
|
|
||||||
try {
|
|
||||||
return chatMessage.getSender().getCallSign().equals(selectedCallSignInfoStageChatMember.getCallSign()) && chatMessage.getReceiver().getCallSign().equals("ALL");
|
|
||||||
} catch (Exception e) { return false; }
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case NOTHING:
|
|
||||||
default:
|
|
||||||
predicate = chatMessage -> {
|
|
||||||
try {
|
|
||||||
return chatMessage.getSender().getCallSign().equals(selectedCallSignInfoStageChatMember.getCallSign()) || chatMessage.getReceiver().getCallSign().equals(selectedCallSignInfoStageChatMember.getCallSign());
|
|
||||||
} catch (Exception e) { return false; }
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
applySelectedCallSignInfoFilter(predicate);
|
|
||||||
return kotlin.Unit.INSTANCE;
|
return kotlin.Unit.INSTANCE;
|
||||||
},
|
},
|
||||||
member -> {
|
member -> {
|
||||||
@@ -3174,24 +3222,25 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
chatcontroller.rotateTo(kst4contest.controller.RadioSlot.SECOND, azimuth);
|
chatcontroller.rotateTo(kst4contest.controller.RadioSlot.SECOND, azimuth);
|
||||||
return kotlin.Unit.INSTANCE;
|
return kotlin.Unit.INSTANCE;
|
||||||
},
|
},
|
||||||
surroundings::getSecondAntennaOffered);
|
surroundings::getSecondAntennaOffered,
|
||||||
|
stationSelection);
|
||||||
|
selectedStation.setSkedRequestSubmitter(this::createSkedFromCompose);
|
||||||
|
|
||||||
if (chatcontroller.getChatPreferences().isGuiOptions_defaultFilterPmToMe()) {
|
selectedStation.setMessageFilter(
|
||||||
selectedStation.setMessageFilter(SelectedMessageFilter.PM_TO_ME);
|
SelectedMessageFilter.fromPreferences(chatcontroller.getChatPreferences()));
|
||||||
} else if (chatcontroller.getChatPreferences().isGuiOptions_defaultFilterPmToOther()) {
|
|
||||||
selectedStation.setMessageFilter(SelectedMessageFilter.PM_TO_OTHER);
|
|
||||||
} else {
|
|
||||||
selectedStation.setMessageFilter(SelectedMessageFilter.NOTHING);
|
|
||||||
}
|
|
||||||
|
|
||||||
TopPriorityState topPriority = new TopPriorityState(
|
TopPriorityState topPriority = new TopPriorityState(
|
||||||
this::composeTopStations,
|
this::composeTopStations,
|
||||||
member -> selectStationInCompose(selectedStation, stations, member));
|
member -> selectStationInCompose(selectedStation, member, StationSelectionSource.PRIORITY));
|
||||||
|
NewJoinedState newJoined = new NewJoinedState(
|
||||||
|
System::currentTimeMillis,
|
||||||
|
member -> selectStationInCompose(
|
||||||
|
selectedStation, member, StationSelectionSource.NEW_JOINED));
|
||||||
|
|
||||||
ChatInputState chatInput = new ChatInputState(new ComposeChatInputActions(this));
|
ChatInputState chatInput = new ChatInputState(new ComposeChatInputActions(this));
|
||||||
|
|
||||||
composeMainWindowState = new MainWindowState(
|
composeMainWindowState = new MainWindowState(
|
||||||
BandOpportunityResolver.getEnabledStationBands(chatcontroller.getChatPreferences()),
|
enabledStationBands,
|
||||||
chatcontroller.getChatPreferences(),
|
chatcontroller.getChatPreferences(),
|
||||||
stations,
|
stations,
|
||||||
new StationFilterState(),
|
new StationFilterState(),
|
||||||
@@ -3238,7 +3287,29 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
.setGUImainWindowRightSplitPane_dividerposition(positions);
|
.setGUImainWindowRightSplitPane_dividerposition(positions);
|
||||||
requestLayoutSave();
|
requestLayoutSave();
|
||||||
return kotlin.Unit.INSTANCE;
|
return kotlin.Unit.INSTANCE;
|
||||||
}));
|
}),
|
||||||
|
new SplitterState(
|
||||||
|
MainWindowState.SELECTED_STATION_PANE_COUNT,
|
||||||
|
chatcontroller.getChatPreferences().getGUIselectedCallSignSplitPane_dividerposition(),
|
||||||
|
SplitterState.DEFAULT_MIN_PANE_PX,
|
||||||
|
positions -> {
|
||||||
|
chatcontroller.getChatPreferences()
|
||||||
|
.setGUIselectedCallSignSplitPane_dividerposition(positions);
|
||||||
|
requestLayoutSave();
|
||||||
|
return kotlin.Unit.INSTANCE;
|
||||||
|
}),
|
||||||
|
newJoined,
|
||||||
|
reachability);
|
||||||
|
composeMainWindowState.getThreadButtons().registerAction(
|
||||||
|
ChatController.BEACON_STATUS_SOURCE,
|
||||||
|
() -> {
|
||||||
|
chatcontroller.toggleUsableBeacons();
|
||||||
|
return kotlin.Unit.INSTANCE;
|
||||||
|
});
|
||||||
|
composeMainWindowState.getThreadButtons().registerStatusProvider(
|
||||||
|
ChatController.BEACON_STATUS_SOURCE,
|
||||||
|
chatcontroller::currentBeaconStatus);
|
||||||
|
chatcontroller.refreshBeaconStatus();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The feed, not the window construction, owns the timeline's data from here.
|
* The feed, not the window construction, owns the timeline's data from here.
|
||||||
@@ -3249,6 +3320,14 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
composeMainWindowState.getTimeline(), uiDispatcher);
|
composeMainWindowState.getTimeline(), uiDispatcher);
|
||||||
selectedStationMessagesFeed = new kst4contest.view.feed.SelectedStationMessagesFeed(
|
selectedStationMessagesFeed = new kst4contest.view.feed.SelectedStationMessagesFeed(
|
||||||
composeMainWindowState.getSelectedStationMessages(), uiDispatcher);
|
composeMainWindowState.getSelectedStationMessages(), uiDispatcher);
|
||||||
|
/*
|
||||||
|
* Build the live message mirror before the first Compose selection. The
|
||||||
|
* selection path already records the selected member before its legacy focus
|
||||||
|
* callback runs, so waiting for that callback leaves the mirror null and the
|
||||||
|
* table cannot receive either existing or newly arriving messages.
|
||||||
|
*/
|
||||||
|
rebuildSelectedCallSignInfoMessageBinding();
|
||||||
|
selectedStationMessagesFeed.push(selectedCallSignInfoMessageBinding.list());
|
||||||
connectionStateFeed = new kst4contest.view.feed.ConnectionStateFeed(
|
connectionStateFeed = new kst4contest.view.feed.ConnectionStateFeed(
|
||||||
composeMainWindowState.getSurroundings(), uiDispatcher);
|
composeMainWindowState.getSurroundings(), uiDispatcher);
|
||||||
|
|
||||||
@@ -3258,19 +3337,62 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
* Subscribed first and seeded afterwards, so a message arriving in between is not
|
* Subscribed first and seeded afterwards, so a message arriving in between is not
|
||||||
* missed — the order RosterListBinding uses for the same reason.
|
* missed — the order RosterListBinding uses for the same reason.
|
||||||
*/
|
*/
|
||||||
composeMemberListener = rows -> uiDispatcher.runOnUi(() -> stations.replaceRows(rows));
|
composeMemberListener = rows -> uiDispatcher.runOnUi(() -> {
|
||||||
|
stations.replaceRows(rows);
|
||||||
|
newJoined.updateActiveMembers(rows);
|
||||||
|
});
|
||||||
chatcontroller.getLst_chatMemberList().addListener(composeMemberListener);
|
chatcontroller.getLst_chatMemberList().addListener(composeMemberListener);
|
||||||
|
composeRecentJoinListener = rows -> uiDispatcher.runOnUi(() -> newJoined.updateEvents(rows));
|
||||||
|
chatcontroller.getRecentChatJoins().addListener(composeRecentJoinListener);
|
||||||
|
|
||||||
composeMainWindowState.setStationSelector(member -> {
|
composeMainWindowState.setStationSelector((member, source) -> {
|
||||||
selectStationInCompose(selectedStation, stations, member);
|
selectStationInCompose(selectedStation, member, source);
|
||||||
|
return kotlin.Unit.INSTANCE;
|
||||||
|
});
|
||||||
|
composeMainWindowState.setStationFiltersChanged(() -> {
|
||||||
|
updateComposeFilters();
|
||||||
|
return kotlin.Unit.INSTANCE;
|
||||||
|
});
|
||||||
|
composeMainWindowState.setLayoutSaveRequested(() -> {
|
||||||
|
requestLayoutSave();
|
||||||
|
return kotlin.Unit.INSTANCE;
|
||||||
|
});
|
||||||
|
composeMainWindowState.setMarkStationWorked(
|
||||||
|
(member, band) -> chatcontroller.markStationWorkedOnBand(member, band));
|
||||||
|
composeMainWindowState.setWorkedGrossFieldsProvider(
|
||||||
|
() -> chatcontroller.getWorkedGrossFieldCache().snapshotWorkedGrossFieldsAny());
|
||||||
|
composeMainWindowState.getMapReachability().setRequester((member, band, callback) -> {
|
||||||
|
java.util.List<ChatMember> variants = chatcontroller.getLst_chatMemberList().snapshot()
|
||||||
|
.stream()
|
||||||
|
.filter(candidate -> candidate != null
|
||||||
|
&& java.util.Objects.equals(candidate.getCallSignRaw(), member.getCallSignRaw()))
|
||||||
|
.toList();
|
||||||
|
java.util.EnumSet<Band> bands = java.util.EnumSet.noneOf(Band.class);
|
||||||
|
bands.addAll(enabledStationBands);
|
||||||
|
MapCallsignRawSnapshot snapshot = new MapCallsignRawSnapshotBuilder()
|
||||||
|
.buildSnapshots(variants, member, bands)
|
||||||
|
.stream()
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
if (snapshot == null) {
|
||||||
|
callback.invoke(PathAnalysisResult.waitingForValidTarget(
|
||||||
|
chatcontroller.getChatPreferences().getStn_loginLocatorMainCat(),
|
||||||
|
member.getQra()));
|
||||||
|
return kotlin.Unit.INSTANCE;
|
||||||
|
}
|
||||||
|
chatcontroller.getReachabilityService().requestPathAnalysisForMap(
|
||||||
|
member,
|
||||||
|
snapshot,
|
||||||
|
band,
|
||||||
|
result -> callback.invoke(result));
|
||||||
return kotlin.Unit.INSTANCE;
|
return kotlin.Unit.INSTANCE;
|
||||||
});
|
});
|
||||||
|
|
||||||
composeChatListener = rows -> uiDispatcher.runOnUi(() -> {
|
composeChatListener = rows -> uiDispatcher.runOnUi(() -> refreshComposeMessageTables(
|
||||||
directed.replaceRows(chatcontroller.toMeMessages());
|
chatcontroller,
|
||||||
publicMessages.replaceRows(rows);
|
directed,
|
||||||
qsoOfTheOther.replaceRows(chatcontroller.toOtherMessages());
|
publicMessages,
|
||||||
});
|
qsoOfTheOther));
|
||||||
chatcontroller.getLst_globalChatMessageList().addListener(composeChatListener);
|
chatcontroller.getLst_globalChatMessageList().addListener(composeChatListener);
|
||||||
|
|
||||||
composeClusterListener = rows -> uiDispatcher.runOnUi(() -> cluster.replaceRows(rows));
|
composeClusterListener = rows -> uiDispatcher.runOnUi(() -> cluster.replaceRows(rows));
|
||||||
@@ -3281,11 +3403,12 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
}
|
}
|
||||||
uiDispatcher.runOnUi(() -> topPriority.refresh());
|
uiDispatcher.runOnUi(() -> topPriority.refresh());
|
||||||
|
|
||||||
stations.replaceRows(chatcontroller.getLst_chatMemberList().snapshot());
|
java.util.List<ChatMember> initialMembers = chatcontroller.getLst_chatMemberList().snapshot();
|
||||||
directed.replaceRows(chatcontroller.toMeMessages());
|
stations.replaceRows(initialMembers);
|
||||||
publicMessages.replaceRows(chatcontroller.getLst_globalChatMessageList().snapshot());
|
newJoined.updateActiveMembers(initialMembers);
|
||||||
|
newJoined.updateEvents(chatcontroller.getRecentChatJoins().snapshot());
|
||||||
|
refreshComposeMessageTables(chatcontroller, directed, publicMessages, qsoOfTheOther);
|
||||||
cluster.replaceRows(chatcontroller.getLst_clusterMemberList().snapshot());
|
cluster.replaceRows(chatcontroller.getLst_clusterMemberList().snapshot());
|
||||||
qsoOfTheOther.replaceRows(chatcontroller.toOtherMessages());
|
|
||||||
/*
|
/*
|
||||||
* The only push that does not check the feed for null, and deliberately so: the
|
* The only push that does not check the feed for null, and deliberately so: the
|
||||||
* feed is assigned earlier in this same method, so a guard here could never fire
|
* feed is assigned earlier in this same method, so a guard here could never fire
|
||||||
@@ -3336,7 +3459,6 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
closeWindowEvent();
|
closeWindowEvent();
|
||||||
return kotlin.Unit.INSTANCE;
|
return kotlin.Unit.INSTANCE;
|
||||||
},
|
},
|
||||||
() -> composeSkedBands(selectedStation.getSelected()),
|
|
||||||
address -> runOnUi(() -> ExternalDocuments.open(address)),
|
address -> runOnUi(() -> ExternalDocuments.open(address)),
|
||||||
() -> {
|
() -> {
|
||||||
runOnUi(() -> showSelectedCallsignOnMap());
|
runOnUi(() -> showSelectedCallsignOnMap());
|
||||||
@@ -3348,8 +3470,9 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
}
|
}
|
||||||
return kotlin.Unit.INSTANCE;
|
return kotlin.Unit.INSTANCE;
|
||||||
},
|
},
|
||||||
member -> selectStationInCompose(selectedStation, stations, member),
|
member -> selectStationInCompose(selectedStation, member, StationSelectionSource.STATION_TABLE),
|
||||||
message -> onDirectedMessageClickedInCompose(selectedStation, stations, composeMainWindowState.getChatInput(), message),
|
message -> onDirectedMessageClickedInCompose(selectedStation, composeMainWindowState.getChatInput(), message),
|
||||||
|
(message, source) -> onMessageSenderClickedInCompose(selectedStation, message, source),
|
||||||
this::isOwnChatMessage,
|
this::isOwnChatMessage,
|
||||||
this::chatMessageAgeSeconds,
|
this::chatMessageAgeSeconds,
|
||||||
() -> {
|
() -> {
|
||||||
@@ -3367,7 +3490,7 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
ChatMember resolved = resolveChatMemberForCallRawAndCategory(
|
ChatMember resolved = resolveChatMemberForCallRawAndCategory(
|
||||||
candidate.getCallSignRaw(), candidate.getPreferredChatCategory());
|
candidate.getCallSignRaw(), candidate.getPreferredChatCategory());
|
||||||
if (resolved != null) {
|
if (resolved != null) {
|
||||||
selectStationInCompose(selectedStation, stations, resolved);
|
selectStationInCompose(selectedStation, resolved, StationSelectionSource.TIMELINE);
|
||||||
composeMainWindowState.getChatInput().prepareCq(resolved.getCallSign(), false);
|
composeMainWindowState.getChatInput().prepareCq(resolved.getCallSign(), false);
|
||||||
|
|
||||||
// Sync with JavaFX state just in case
|
// Sync with JavaFX state just in case
|
||||||
@@ -3391,6 +3514,29 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
final int minutes,
|
final int minutes,
|
||||||
final Band band,
|
final Band band,
|
||||||
final String mode) {
|
final String mode) {
|
||||||
|
boolean remindPm = false;
|
||||||
|
String reminderOffsets = SelectedStationState.Companion.getREMINDER_OFFSETS().get(0);
|
||||||
|
if (composeMainWindowState != null) {
|
||||||
|
SelectedStationState state = composeMainWindowState.getSelectedStation();
|
||||||
|
remindPm = state.getRemindPm();
|
||||||
|
reminderOffsets = state.getReminderOffsets();
|
||||||
|
}
|
||||||
|
return createSkedFromCompose(new SkedRequest(
|
||||||
|
selectedMember,
|
||||||
|
minutes,
|
||||||
|
band,
|
||||||
|
mode,
|
||||||
|
remindPm,
|
||||||
|
reminderOffsets));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean createSkedFromCompose(final SkedRequest request) {
|
||||||
|
if (request == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final ChatMember selectedMember = request.getTarget();
|
||||||
|
final int minutes = request.getMinutes();
|
||||||
|
final Band band = request.getBand();
|
||||||
|
|
||||||
if (selectedMember == null || band == null) {
|
if (selectedMember == null || band == null) {
|
||||||
return false;
|
return false;
|
||||||
@@ -3412,17 +3558,14 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
chatcontroller.getScoreService().requestRecompute("sked-created");
|
chatcontroller.getScoreService().requestRecompute("sked-created");
|
||||||
|
|
||||||
// Arm PM reminders, exactly as the JavaFX Create sked handler does
|
// Arm PM reminders, exactly as the JavaFX Create sked handler does
|
||||||
if (composeMainWindowState != null) {
|
if (request.getRemindPm()) {
|
||||||
SelectedStationState ssState = composeMainWindowState.getSelectedStation();
|
List<Integer> offsets = parseMinuteOffsets(request.getReminderOffsets());
|
||||||
if (ssState.getRemindPm()) {
|
|
||||||
List<Integer> offsets = parseMinuteOffsets(ssState.getReminderOffsets());
|
|
||||||
chatcontroller.getSkedReminderService().armReminders(
|
chatcontroller.getSkedReminderService().armReminders(
|
||||||
sked.getTargetChatCallsign(),
|
sked.getTargetChatCallsign(),
|
||||||
sked.getTargetChatCategory(),
|
sked.getTargetChatCategory(),
|
||||||
skedTime,
|
skedTime,
|
||||||
offsets
|
offsets
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -3462,28 +3605,6 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
return activeProfile.getProfile().getDisplayName();
|
return activeProfile.getProfile().getDisplayName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The bands a sked can be arranged on for this station: enabled here, available there. */
|
|
||||||
private java.util.List<Band> composeSkedBands(ChatMember selectedMember) {
|
|
||||||
if (selectedMember == null) {
|
|
||||||
return java.util.List.of();
|
|
||||||
}
|
|
||||||
|
|
||||||
java.util.List<ChatMember> variants =
|
|
||||||
chatcontroller.findActiveChatMembersByRawCall(selectedMember.getCallSignRaw());
|
|
||||||
if (variants.isEmpty()) {
|
|
||||||
variants = java.util.List.of(selectedMember);
|
|
||||||
}
|
|
||||||
|
|
||||||
BandOpportunityResolver.Resolution resolution =
|
|
||||||
BandOpportunityResolver.resolve(variants, System.currentTimeMillis());
|
|
||||||
EnumSet<Band> enabledBands =
|
|
||||||
BandOpportunityResolver.getEnabledStationBands(chatcontroller.getChatPreferences());
|
|
||||||
|
|
||||||
EnumSet<Band> available = EnumSet.copyOf(resolution.getAvailableBands());
|
|
||||||
available.retainAll(enabledBands);
|
|
||||||
return new ArrayList<>(available);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The score service's ranking, as the Compose priority bar wants it. */
|
/** The score service's ranking, as the Compose priority bar wants it. */
|
||||||
private java.util.List<kotlin.Pair<ChatMember, Double>> composeTopStations() {
|
private java.util.List<kotlin.Pair<ChatMember, Double>> composeTopStations() {
|
||||||
java.util.List<kotlin.Pair<ChatMember, Double>> out = new ArrayList<>();
|
java.util.List<kotlin.Pair<ChatMember, Double>> out = new ArrayList<>();
|
||||||
@@ -3515,21 +3636,13 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
*/
|
*/
|
||||||
private kotlin.Unit selectStationInCompose(
|
private kotlin.Unit selectStationInCompose(
|
||||||
SelectedStationState panel,
|
SelectedStationState panel,
|
||||||
DataTableState<ChatMember> table,
|
ChatMember member,
|
||||||
ChatMember member) {
|
StationSelectionSource source) {
|
||||||
|
|
||||||
panel.select(member);
|
panel.select(member, source);
|
||||||
table.select(member);
|
|
||||||
|
|
||||||
selectedCallSignInfoStageChatMember = member;
|
selectedCallSignInfoStageChatMember = member;
|
||||||
if (selectedCallSignInfoMessageBinding != null) {
|
applySelectedStationMessageFilter(panel.getMessageFilter(), member);
|
||||||
selectedCallSignInfoMessageBinding.refresh();
|
|
||||||
uiDispatcher.runOnUi(() -> {
|
|
||||||
if (selectedStationMessagesFeed != null) {
|
|
||||||
selectedStationMessagesFeed.push(selectedCallSignInfoMessageBinding.list());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (member != null && chatcontroller.getScoreService() != null) {
|
if (member != null && chatcontroller.getScoreService() != null) {
|
||||||
chatcontroller.getScoreService().setSelectedChatMember(member);
|
chatcontroller.getScoreService().setSelectedChatMember(member);
|
||||||
@@ -3545,26 +3658,41 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
|
|
||||||
private kotlin.Unit onDirectedMessageClickedInCompose(
|
private kotlin.Unit onDirectedMessageClickedInCompose(
|
||||||
SelectedStationState panel,
|
SelectedStationState panel,
|
||||||
DataTableState<ChatMember> stationsTable,
|
|
||||||
ChatInputState chatInput,
|
ChatInputState chatInput,
|
||||||
ChatMessage message) {
|
ChatMessage message) {
|
||||||
|
|
||||||
|
String ownCall = chatcontroller.getChatPreferences().getStn_loginCallSign();
|
||||||
|
StationIdentity target = DirectedMessageStationTarget.forMessage(message, ownCall);
|
||||||
|
if (target == null) {
|
||||||
|
return kotlin.Unit.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatMember activeTarget = chatcontroller.findActiveChatMember(target.getCallSign(), message.getChatCategory());
|
||||||
|
if (activeTarget != null) {
|
||||||
|
selectStationInCompose(panel, activeTarget, StationSelectionSource.DIRECTED_MESSAGE);
|
||||||
|
} else {
|
||||||
|
chatInput.prepareCq(target.getCallSign(), false);
|
||||||
|
if (message.getSender() != null && message.getSender().getCallSign().equalsIgnoreCase(ownCall)) {
|
||||||
|
rememberAutoPreparedCqTarget(target.getCallSign(), message.getChatCategory());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return kotlin.Unit.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private kotlin.Unit onMessageSenderClickedInCompose(
|
||||||
|
SelectedStationState panel,
|
||||||
|
ChatMessage message,
|
||||||
|
StationSelectionSource source) {
|
||||||
if (message == null || message.getSender() == null) {
|
if (message == null || message.getSender() == null) {
|
||||||
return kotlin.Unit.INSTANCE;
|
return kotlin.Unit.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.getSender().getCallSign().equals(chatcontroller.getChatPreferences().getStn_loginCallSign())) {
|
ChatMember sender = chatcontroller.findActiveChatMember(
|
||||||
String receiverCallsign = message.getMessageText().substring(2, message.getMessageText().indexOf(")"));
|
message.getSender().getCallSign(), message.getChatCategory());
|
||||||
chatInput.prepareCq(receiverCallsign, false);
|
if (sender != null) {
|
||||||
rememberAutoPreparedCqTarget(receiverCallsign, message.getChatCategory());
|
selectStationInCompose(panel, sender, source);
|
||||||
} else {
|
|
||||||
selectStationInCompose(panel, stationsTable, message.getSender());
|
|
||||||
|
|
||||||
chatInput.prepareCq(message.getSender().getCallSign(), false);
|
|
||||||
prepareCqTextForSelectedChatMember(message.getSender(), false);
|
|
||||||
focusChatMemberAndPrepareCq(message.getSender(), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return kotlin.Unit.INSTANCE;
|
return kotlin.Unit.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3620,6 +3748,10 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
chatcontroller.getLst_chatMemberList().removeListener(composeMemberListener);
|
chatcontroller.getLst_chatMemberList().removeListener(composeMemberListener);
|
||||||
composeMemberListener = null;
|
composeMemberListener = null;
|
||||||
}
|
}
|
||||||
|
if (composeRecentJoinListener != null) {
|
||||||
|
chatcontroller.getRecentChatJoins().removeListener(composeRecentJoinListener);
|
||||||
|
composeRecentJoinListener = null;
|
||||||
|
}
|
||||||
if (composeChatListener != null) {
|
if (composeChatListener != null) {
|
||||||
chatcontroller.getLst_globalChatMessageList().removeListener(composeChatListener);
|
chatcontroller.getLst_globalChatMessageList().removeListener(composeChatListener);
|
||||||
composeChatListener = null;
|
composeChatListener = null;
|
||||||
@@ -3706,9 +3838,25 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
clusterTable.replaceRows(chatcontroller.getLst_clusterMemberList().snapshot());
|
clusterTable.replaceRows(chatcontroller.getLst_clusterMemberList().snapshot());
|
||||||
qsoTable.replaceRows(chatcontroller.toOtherMessages());
|
qsoTable.replaceRows(chatcontroller.toOtherMessages());
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The same preference the JavaFX SplitPane wrote, so a profile gets back the
|
||||||
|
* position its operator dragged before the Compose port (#144).
|
||||||
|
*/
|
||||||
|
SplitterState monitorSplitter = new SplitterState(
|
||||||
|
2,
|
||||||
|
chatcontroller.getChatPreferences().getGUIpnl_directedMSGWin_dividerpositionDefault(),
|
||||||
|
SplitterState.DEFAULT_MIN_PANE_PX,
|
||||||
|
positions -> {
|
||||||
|
chatcontroller.getChatPreferences()
|
||||||
|
.setGUIpnl_directedMSGWin_dividerpositionDefault(positions);
|
||||||
|
requestLayoutSave();
|
||||||
|
return kotlin.Unit.INSTANCE;
|
||||||
|
});
|
||||||
|
|
||||||
MonitorWindow.show(
|
MonitorWindow.show(
|
||||||
clusterTable,
|
clusterTable,
|
||||||
qsoTable,
|
qsoTable,
|
||||||
|
monitorSplitter,
|
||||||
chatcontroller.getChatPreferences().isGUI_darkModeActive(),
|
chatcontroller.getChatPreferences().isGUI_darkModeActive(),
|
||||||
SETTINGS_WINDOW_FONT_SIZE_SP,
|
SETTINGS_WINDOW_FONT_SIZE_SP,
|
||||||
paletteStore,
|
paletteStore,
|
||||||
@@ -3809,7 +3957,12 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
requestLayoutSave();
|
requestLayoutSave();
|
||||||
return kotlin.Unit.INSTANCE;
|
return kotlin.Unit.INSTANCE;
|
||||||
},
|
},
|
||||||
SettingsTabsKt.settingsButtons(chatcontroller, this, settingsNotices, draft));
|
SettingsTabsKt.settingsButtons(
|
||||||
|
chatcontroller,
|
||||||
|
this,
|
||||||
|
settingsNotices,
|
||||||
|
draft,
|
||||||
|
this::settingsConnectionState));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -3893,6 +4046,27 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options -> setup assistant. Rebuilds the runtime of the active profile with the wizard
|
||||||
|
* in front of it, which costs the running session; hence the question, and hence the
|
||||||
|
* settings edits are settled first, as before a profile switch.
|
||||||
|
*/
|
||||||
|
void menuActionOpenSetupWizard() {
|
||||||
|
SettingsWindow.settleThen(() -> {
|
||||||
|
boolean confirmed = ComposeAlert.confirm(
|
||||||
|
kst4contest.view.i18n.CurrentStrings.get().getAlertSetupWizardTitle(),
|
||||||
|
kst4contest.view.i18n.CurrentStrings.get().getAlertSetupWizardQuestion(),
|
||||||
|
kst4contest.view.i18n.CurrentStrings.get().getAlertSetupWizardBody(),
|
||||||
|
kst4contest.view.i18n.CurrentStrings.get().getDialogStartSetupWizard(),
|
||||||
|
kst4contest.view.i18n.CurrentStrings.get().getDialogCancel(),
|
||||||
|
chatcontroller.getChatPreferences().isGUI_darkModeActive());
|
||||||
|
|
||||||
|
if (confirmed) {
|
||||||
|
ApplicationRuntimeLauncher.rerunSetupWizard();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/** Windows -> open or close the cluster / stranger-QSO monitor window. */
|
/** Windows -> open or close the cluster / stranger-QSO monitor window. */
|
||||||
void menuActionToggleMonitorWindow() {
|
void menuActionToggleMonitorWindow() {
|
||||||
if (MonitorWindow.isOpen()) {
|
if (MonitorWindow.isOpen()) {
|
||||||
@@ -4015,6 +4189,17 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refreshMapDisplaySettings() {
|
||||||
|
uiDispatcher.runOnUi(() -> {
|
||||||
|
if (composeMainWindowState == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
composeMainWindowState.refreshMapDisplaySettings();
|
||||||
|
forceChatMemberFilterRefresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* No-op since the JavaFX own-QRG text field was removed with the never-shown window.
|
* No-op since the JavaFX own-QRG text field was removed with the never-shown window.
|
||||||
*
|
*
|
||||||
@@ -4206,31 +4391,12 @@ public class Kst4ContestApplication implements StatusUpdateListener, SettingsHos
|
|||||||
* @return manually selected band or automatic band
|
* @return manually selected band or automatic band
|
||||||
*/
|
*/
|
||||||
private Band resolveReachabilityBandForUi(ChatMember member) {
|
private Band resolveReachabilityBandForUi(ChatMember member) {
|
||||||
if (selectedReachabilityBandOverride != null) {
|
if (composeMainWindowState != null) {
|
||||||
return selectedReachabilityBandOverride;
|
return composeMainWindowState.getReachability().resolveBand(member);
|
||||||
}
|
}
|
||||||
return chatcontroller.getReachabilityService().resolveAutoBand(member);
|
return chatcontroller.getReachabilityService().resolveAutoBand(member);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses the reachability ComboBox selection.
|
|
||||||
*
|
|
||||||
* @param selectedLabel selected UI text
|
|
||||||
* @return selected band, or null for Auto
|
|
||||||
*/
|
|
||||||
private Band parseReachabilityBandSelection(String selectedLabel) {
|
|
||||||
if (selectedLabel == null || selectedLabel.isBlank() || "Auto".equalsIgnoreCase(selectedLabel)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Band band : Band.values()) {
|
|
||||||
if (selectedLabel.equalsIgnoreCase(band.getDisplayLabel())) {
|
|
||||||
return band;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats the projected priority score for the station table.
|
* Formats the projected priority score for the station table.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import kst4contest.model.BeaconStatusSnapshot
|
||||||
|
import kst4contest.model.BeaconStatusSnapshot.AggregateState
|
||||||
|
import kst4contest.model.BeaconStatusSnapshot.CategoryStatus
|
||||||
|
import kst4contest.model.BeaconStatusSnapshot.InactiveReason
|
||||||
|
import kst4contest.view.i18n.CurrentStrings
|
||||||
|
import kst4contest.view.i18n.Strings
|
||||||
|
|
||||||
|
enum class ThreadStatusVisualStyle {
|
||||||
|
DEFAULT,
|
||||||
|
BEACON_OFF,
|
||||||
|
BEACON_ACTIVE,
|
||||||
|
BEACON_FAILED,
|
||||||
|
}
|
||||||
|
|
||||||
|
data class BeaconStatusPresentation(
|
||||||
|
val label: String,
|
||||||
|
val tooltip: String,
|
||||||
|
val style: ThreadStatusVisualStyle,
|
||||||
|
) {
|
||||||
|
companion object {
|
||||||
|
fun from(
|
||||||
|
snapshot: BeaconStatusSnapshot,
|
||||||
|
strings: Strings = CurrentStrings.get(),
|
||||||
|
): BeaconStatusPresentation {
|
||||||
|
val label = when (snapshot.aggregateState) {
|
||||||
|
AggregateState.OFF -> "off"
|
||||||
|
AggregateState.PARTIAL -> "1/2"
|
||||||
|
AggregateState.ON -> "on"
|
||||||
|
AggregateState.FAILED -> "FAILED"
|
||||||
|
}
|
||||||
|
val style = when (snapshot.aggregateState) {
|
||||||
|
AggregateState.OFF -> ThreadStatusVisualStyle.BEACON_OFF
|
||||||
|
AggregateState.PARTIAL, AggregateState.ON -> ThreadStatusVisualStyle.BEACON_ACTIVE
|
||||||
|
AggregateState.FAILED -> ThreadStatusVisualStyle.BEACON_FAILED
|
||||||
|
}
|
||||||
|
val tooltip = listOf(
|
||||||
|
strings.beaconStatusMain(describe(snapshot.main, strings)),
|
||||||
|
strings.beaconStatusSecond(describe(snapshot.second, strings)),
|
||||||
|
).joinToString("\n")
|
||||||
|
return BeaconStatusPresentation(label, tooltip, style)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun describe(category: CategoryStatus, strings: Strings): String {
|
||||||
|
if (!category.isAvailable()) return strings.beaconStatusUnavailable
|
||||||
|
if (category.isFailed()) return strings.beaconStatusFailed
|
||||||
|
if (category.isEnabled()) return strings.beaconStatusEnabled
|
||||||
|
return when (category.inactiveReason) {
|
||||||
|
InactiveReason.NOT_ACTIVATED_THIS_SESSION -> strings.beaconReasonSession
|
||||||
|
InactiveReason.USER_DISABLED -> strings.beaconReasonUser
|
||||||
|
InactiveReason.PRIMARY_QRG_UNAVAILABLE -> strings.beaconReasonPrimaryQrg
|
||||||
|
InactiveReason.SECONDARY_QRG_UNAVAILABLE -> strings.beaconReasonSecondaryQrg
|
||||||
|
InactiveReason.AUTOMATIC_QRG_CHANGE -> strings.beaconReasonAutomaticQrg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,6 @@ package kst4contest.view.compose
|
|||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.TooltipArea
|
import androidx.compose.foundation.TooltipArea
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
|
||||||
import androidx.compose.foundation.border
|
import androidx.compose.foundation.border
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
@@ -17,7 +16,6 @@ import androidx.compose.foundation.layout.padding
|
|||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.layout.widthIn
|
import androidx.compose.foundation.layout.widthIn
|
||||||
import androidx.compose.foundation.text.BasicTextField
|
import androidx.compose.foundation.text.BasicTextField
|
||||||
import androidx.compose.material3.LocalTextStyle
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
@@ -37,9 +35,8 @@ import androidx.compose.ui.input.key.KeyEventType
|
|||||||
import androidx.compose.ui.input.key.key
|
import androidx.compose.ui.input.key.key
|
||||||
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
||||||
import androidx.compose.ui.input.key.type
|
import androidx.compose.ui.input.key.type
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.graphics.luminance
|
|
||||||
import androidx.compose.ui.graphics.SolidColor
|
import androidx.compose.ui.graphics.SolidColor
|
||||||
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import kst4contest.model.ChatPreferences
|
import kst4contest.model.ChatPreferences
|
||||||
|
|
||||||
@@ -59,9 +56,13 @@ fun ShortcutButtonRow(
|
|||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
FlowRow(
|
FlowRow(
|
||||||
modifier = modifier.fillMaxWidth().padding(horizontal = 2.dp, vertical = 0.dp),
|
modifier = modifier
|
||||||
horizontalArrangement = Arrangement.spacedBy(0.dp),
|
.fillMaxWidth()
|
||||||
verticalArrangement = Arrangement.spacedBy(0.dp),
|
.background(MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.35f))
|
||||||
|
.border(Density.HAIRLINE, MaterialTheme.colorScheme.outlineVariant)
|
||||||
|
.padding(horizontal = 2.dp, vertical = 1.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(2.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||||
) {
|
) {
|
||||||
shortcuts.forEach { shortcut ->
|
shortcuts.forEach { shortcut ->
|
||||||
when (shortcut) {
|
when (shortcut) {
|
||||||
@@ -109,38 +110,9 @@ private fun ShortcutButton(label: String, accented: Boolean, onClick: () -> Unit
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val palette = LocalJavaFxPalette.current
|
Form.button(text = label, accented = true, onClick = onClick)
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.heightIn(min = Density.BUTTON_MIN_HEIGHT)
|
|
||||||
.background(
|
|
||||||
brush = if (palette.windowBackground.luminance() < 0.5f) {
|
|
||||||
androidx.compose.ui.graphics.Brush.linearGradient(
|
|
||||||
colors = listOf(Color(0xFF008000), Color(0xFF90EE90))
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
androidx.compose.ui.graphics.Brush.linearGradient(
|
|
||||||
colors = listOf(Color(0xFF00FFFF), Color(0xFFFF99FF))
|
|
||||||
)
|
|
||||||
},
|
|
||||||
shape = Density.BUTTON_SHAPE
|
|
||||||
)
|
|
||||||
.clickable { onClick() }
|
|
||||||
.padding(Density.BUTTON_CONTENT_PADDING),
|
|
||||||
contentAlignment = Alignment.Center,
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = label,
|
|
||||||
color = MYQRG_LABEL_COLOR,
|
|
||||||
style = MaterialTheme.typography.labelLarge,
|
|
||||||
maxLines = 1,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** `-fx-text-fill: #395306` from `.buttonMyQrg1`; a dark olive that reads on the green. */
|
|
||||||
private val MYQRG_LABEL_COLOR = Color(0xFF395306)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The send row: the message field, TX, clear, and the three small fields the operator
|
* The send row: the message field, TX, clear, and the three small fields the operator
|
||||||
* keeps their own frequencies and antenna heading in.
|
* keeps their own frequencies and antenna heading in.
|
||||||
@@ -191,12 +163,12 @@ fun ChatInputRow(
|
|||||||
// profile on every keystroke.
|
// profile on every keystroke.
|
||||||
InlineCommittedField(
|
InlineCommittedField(
|
||||||
stored = ownQrgMain.value.orEmpty(),
|
stored = ownQrgMain.value.orEmpty(),
|
||||||
onCommit = { prefs.getMYQRGFirstCat().set(it) },
|
onCommit = { state.commitOwnQrg(mainCategory = true, it) },
|
||||||
tooltip = kst4contest.view.i18n.CurrentStrings.get().chatOwnQrgTooltip,
|
tooltip = kst4contest.view.i18n.CurrentStrings.get().chatOwnQrgTooltip,
|
||||||
)
|
)
|
||||||
InlineCommittedField(
|
InlineCommittedField(
|
||||||
stored = ownQrgSecond.value.orEmpty(),
|
stored = ownQrgSecond.value.orEmpty(),
|
||||||
onCommit = { prefs.getMYQRGSecondCat().set(it) },
|
onCommit = { state.commitOwnQrg(mainCategory = false, it) },
|
||||||
tooltip = if (so2rEnabled) {
|
tooltip = if (so2rEnabled) {
|
||||||
kst4contest.view.i18n.CurrentStrings.get().chatSecondQrgTooltipSo2r
|
kst4contest.view.i18n.CurrentStrings.get().chatSecondQrgTooltipSo2r
|
||||||
} else {
|
} else {
|
||||||
@@ -207,6 +179,7 @@ fun ChatInputRow(
|
|||||||
stored = antennaQtf.value?.toString().orEmpty(),
|
stored = antennaQtf.value?.toString().orEmpty(),
|
||||||
onCommit = { text -> text.toDoubleOrNull()?.let { prefs.getActualQTF().set(it) } },
|
onCommit = { text -> text.toDoubleOrNull()?.let { prefs.getActualQTF().set(it) } },
|
||||||
tooltip = kst4contest.view.i18n.CurrentStrings.get().chatQtfTooltip,
|
tooltip = kst4contest.view.i18n.CurrentStrings.get().chatQtfTooltip,
|
||||||
|
width = QTF_FIELD_WIDTH,
|
||||||
)
|
)
|
||||||
if (so2rEnabled) {
|
if (so2rEnabled) {
|
||||||
// Display only: rotator 2 writes it, the operator does not.
|
// Display only: rotator 2 writes it, the operator does not.
|
||||||
@@ -215,6 +188,7 @@ fun ChatInputRow(
|
|||||||
onCommit = { },
|
onCommit = { },
|
||||||
tooltip = kst4contest.view.i18n.CurrentStrings.get().chatQtf2Tooltip,
|
tooltip = kst4contest.view.i18n.CurrentStrings.get().chatQtf2Tooltip,
|
||||||
editable = false,
|
editable = false,
|
||||||
|
width = QTF_FIELD_WIDTH,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -234,6 +208,7 @@ private fun InlineCommittedField(
|
|||||||
onCommit: (String) -> Unit,
|
onCommit: (String) -> Unit,
|
||||||
tooltip: String,
|
tooltip: String,
|
||||||
editable: Boolean = true,
|
editable: Boolean = true,
|
||||||
|
width: Dp = QRG_FIELD_WIDTH,
|
||||||
) {
|
) {
|
||||||
var draft by remember(stored) { mutableStateOf(stored) }
|
var draft by remember(stored) { mutableStateOf(stored) }
|
||||||
|
|
||||||
@@ -243,7 +218,7 @@ private fun InlineCommittedField(
|
|||||||
onValueChange = { draft = it },
|
onValueChange = { draft = it },
|
||||||
enabled = editable,
|
enabled = editable,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.width(QRG_FIELD_WIDTH)
|
.width(width)
|
||||||
.onFocusChanged { focus ->
|
.onFocusChanged { focus ->
|
||||||
if (!focus.isFocused && draft != stored) onCommit(draft)
|
if (!focus.isFocused && draft != stored) onCommit(draft)
|
||||||
},
|
},
|
||||||
@@ -267,7 +242,8 @@ private fun TooltipChip(text: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val QRG_FIELD_WIDTH = 70.dp
|
private val QRG_FIELD_WIDTH = 96.dp
|
||||||
|
private val QTF_FIELD_WIDTH = 56.dp
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The message field.
|
* The message field.
|
||||||
@@ -276,6 +252,7 @@ private val QRG_FIELD_WIDTH = 70.dp
|
|||||||
* both were on the scene in JavaFX, which means they worked wherever the focus was; here
|
* both were on the scene in JavaFX, which means they worked wherever the focus was; here
|
||||||
* they are on the field, and the window handles them for the rest of the surface.
|
* they are on the field, and the window handles them for the rest of the surface.
|
||||||
*/
|
*/
|
||||||
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
private fun MessageField(
|
private fun MessageField(
|
||||||
state: ChatInputState,
|
state: ChatInputState,
|
||||||
@@ -284,12 +261,21 @@ private fun MessageField(
|
|||||||
) {
|
) {
|
||||||
val scheme = MaterialTheme.colorScheme
|
val scheme = MaterialTheme.colorScheme
|
||||||
|
|
||||||
|
TooltipArea(
|
||||||
|
tooltip = {
|
||||||
|
if (state.value.text.isNotBlank()) {
|
||||||
|
TooltipChip(state.value.text)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modifier = modifier,
|
||||||
|
) {
|
||||||
Box(
|
Box(
|
||||||
modifier = modifier
|
modifier = Modifier
|
||||||
.heightIn(min = Density.FIELD_MIN_HEIGHT)
|
.fillMaxWidth()
|
||||||
|
.heightIn(min = Density.CONTROL_HEIGHT)
|
||||||
.border(1.5.dp, scheme.primary, Density.BUTTON_SHAPE)
|
.border(1.5.dp, scheme.primary, Density.BUTTON_SHAPE)
|
||||||
.background(scheme.surface, Density.BUTTON_SHAPE)
|
.background(scheme.surface, Density.BUTTON_SHAPE)
|
||||||
.padding(horizontal = 6.dp, vertical = 4.dp),
|
.padding(horizontal = 6.dp),
|
||||||
contentAlignment = Alignment.CenterStart,
|
contentAlignment = Alignment.CenterStart,
|
||||||
) {
|
) {
|
||||||
BasicTextField(
|
BasicTextField(
|
||||||
@@ -307,10 +293,11 @@ private fun MessageField(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
textStyle = LocalTextStyle.current.copy(color = scheme.onSurface),
|
textStyle = compactControlTextStyle().copy(color = scheme.onSurface),
|
||||||
cursorBrush = SolidColor(scheme.primary),
|
cursorBrush = SolidColor(scheme.primary),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The vertical separator that sets the frequency fields apart from the send controls. */
|
/** The vertical separator that sets the frequency fields apart from the send controls. */
|
||||||
@@ -319,7 +306,7 @@ private fun VerticalRule() {
|
|||||||
Box(
|
Box(
|
||||||
Modifier
|
Modifier
|
||||||
.width(Density.HAIRLINE)
|
.width(Density.HAIRLINE)
|
||||||
.height(Density.FIELD_MIN_HEIGHT)
|
.height(Density.CONTROL_HEIGHT)
|
||||||
.background(MaterialTheme.colorScheme.outline),
|
.background(MaterialTheme.colorScheme.outline),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ import androidx.compose.runtime.mutableStateOf
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.text.TextRange
|
import androidx.compose.ui.text.TextRange
|
||||||
import androidx.compose.ui.text.input.TextFieldValue
|
import androidx.compose.ui.text.input.TextFieldValue
|
||||||
|
import kst4contest.controller.RadioSlot
|
||||||
import kst4contest.model.ChatCategory
|
import kst4contest.model.ChatCategory
|
||||||
import kst4contest.model.ChatMember
|
import kst4contest.model.ChatMember
|
||||||
import kst4contest.model.ChatMessage
|
import kst4contest.model.ChatMessage
|
||||||
@@ -46,6 +47,8 @@ interface ChatInputActions {
|
|||||||
fun ownQrgMain(): String
|
fun ownQrgMain(): String
|
||||||
|
|
||||||
fun ownQrgSecond(): String
|
fun ownQrgSecond(): String
|
||||||
|
|
||||||
|
fun applyManualQrg(slot: RadioSlot, value: String) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -150,6 +153,10 @@ class ChatInputState(private val actions: ChatInputActions) {
|
|||||||
appendAndFocus("$qrg ")
|
appendAndFocus("$qrg ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun commitOwnQrg(mainCategory: Boolean, value: String) {
|
||||||
|
actions.applyManualQrg(if (mainCategory) RadioSlot.FIRST else RadioSlot.SECOND, value)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces the field with "/cq CALL <snippet>", resolved.
|
* Replaces the field with "/cq CALL <snippet>", resolved.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -7,15 +7,9 @@ import androidx.compose.foundation.layout.Row
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import kst4contest.view.i18n.LocalStrings
|
import kst4contest.view.i18n.LocalStrings
|
||||||
import kst4contest.view.i18n.Strings
|
import kst4contest.view.i18n.Strings
|
||||||
import kst4contest.controller.ChatController
|
import kst4contest.controller.On4KstConnectionState
|
||||||
import kst4contest.model.ChatPreferences
|
import kst4contest.model.ChatPreferences
|
||||||
|
|
||||||
/**
|
|
||||||
* The connection state the button bar shows. Derived from the controller rather than
|
|
||||||
* held, because the session also connects and drops outside this window.
|
|
||||||
*/
|
|
||||||
enum class ConnectionState { DISCONNECTED, CONNECTED_NOT_LOGGED_IN, LOGGED_IN }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The button bar at the bottom of the settings window.
|
* The button bar at the bottom of the settings window.
|
||||||
*
|
*
|
||||||
@@ -26,16 +20,9 @@ enum class ConnectionState { DISCONNECTED, CONNECTED_NOT_LOGGED_IN, LOGGED_IN }
|
|||||||
*/
|
*/
|
||||||
class ConnectionBarState(
|
class ConnectionBarState(
|
||||||
private val prefs: ChatPreferences,
|
private val prefs: ChatPreferences,
|
||||||
private val controller: ChatController,
|
private val connectionState: () -> On4KstConnectionState,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val connectionState: ConnectionState
|
|
||||||
get() = when {
|
|
||||||
controller.isConnectedAndLoggedIn -> ConnectionState.LOGGED_IN
|
|
||||||
controller.isConnectedAndNOTLoggedIn -> ConnectionState.CONNECTED_NOT_LOGGED_IN
|
|
||||||
else -> ConnectionState.DISCONNECTED
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The label of the Connect button, which names the chat the station will land in —
|
* The label of the Connect button, which names the chat the station will land in —
|
||||||
* and both chats when the second one is enabled, so the operator sees before
|
* and both chats when the second one is enabled, so the operator sees before
|
||||||
@@ -62,13 +49,13 @@ class ConnectionBarState(
|
|||||||
return label
|
return label
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Only a disconnected session can connect; the JavaFX button locked itself. */
|
/** A new attempt is safe only after the manager has completed its disconnect. */
|
||||||
val canConnect: Boolean
|
val canConnect: Boolean
|
||||||
get() = connectionState != ConnectionState.LOGGED_IN
|
get() = connectionState() == On4KstConnectionState.DISCONNECTED
|
||||||
|
|
||||||
/** Disconnecting needs a session that is actually logged in. */
|
/** A running attempt, online session or reconnect wait can be stopped by the operator. */
|
||||||
val canDisconnect: Boolean
|
val canDisconnect: Boolean
|
||||||
get() = connectionState == ConnectionState.LOGGED_IN
|
get() = connectionState().isConnectionAttemptActive
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalLayoutApi::class)
|
@OptIn(ExperimentalLayoutApi::class)
|
||||||
|
|||||||
@@ -162,6 +162,28 @@ interface ColumnWidthStore {
|
|||||||
fun requestSave()
|
fun requestSave()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional shared row selection for tables whose selected entity is also displayed by
|
||||||
|
* other components. Ordinary event tables keep their selection inside [DataTableState].
|
||||||
|
*/
|
||||||
|
interface TableSelectionModel<T> {
|
||||||
|
|
||||||
|
val selected: T?
|
||||||
|
|
||||||
|
/** Changes whenever [selected] changes, including a repeated explicit selection. */
|
||||||
|
val selectionRevision: Long
|
||||||
|
|
||||||
|
/** Changes only when the table should scroll to the current selection. */
|
||||||
|
val scrollRequestRevision: Long
|
||||||
|
|
||||||
|
fun select(row: T?)
|
||||||
|
|
||||||
|
/** Replaces the selected instance after a roster refresh without requesting a scroll. */
|
||||||
|
fun reconcile(row: T?)
|
||||||
|
|
||||||
|
fun requestScroll()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The state of a multi-column table: its rows, its sorting and its selection.
|
* The state of a multi-column table: its rows, its sorting and its selection.
|
||||||
*
|
*
|
||||||
@@ -170,12 +192,16 @@ interface ColumnWidthStore {
|
|||||||
* data that shows up as a stale display rather than as an unresponsive one — harder
|
* data that shows up as a stale display rather than as an unresponsive one — harder
|
||||||
* to notice and worse in effect.
|
* to notice and worse in effect.
|
||||||
*/
|
*/
|
||||||
class DataTableState<T>(
|
class DataTableState<T> @JvmOverloads constructor(
|
||||||
val columns: List<DataColumn<T>>,
|
val columns: List<DataColumn<T>>,
|
||||||
private val rowKey: RowKeySource<T>,
|
private val rowKey: RowKeySource<T>,
|
||||||
/** Part of the stored layout: renaming it loses the operator's column sizing. */
|
/** Part of the stored layout: renaming it loses the operator's column sizing. */
|
||||||
private val tableId: String = "",
|
private val tableId: String = "",
|
||||||
private val widths: ColumnWidthStore? = null,
|
private val widths: ColumnWidthStore? = null,
|
||||||
|
initialSortColumnId: String? = null,
|
||||||
|
initialSortAscending: Boolean = true,
|
||||||
|
private val selectionModel: TableSelectionModel<T>? = null,
|
||||||
|
private val keepSelectionVisible: Boolean = false,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -251,19 +277,29 @@ class DataTableState<T>(
|
|||||||
var rows: List<T> by mutableStateOf(emptyList())
|
var rows: List<T> by mutableStateOf(emptyList())
|
||||||
private set
|
private set
|
||||||
|
|
||||||
var sortedColumnId: String? by mutableStateOf(null)
|
var sortedColumnId: String? by mutableStateOf(
|
||||||
|
initialSortColumnId?.takeIf { requested -> columns.any { it.id == requested } },
|
||||||
|
)
|
||||||
private set
|
private set
|
||||||
|
|
||||||
var sortAscending: Boolean by mutableStateOf(true)
|
var sortAscending: Boolean by mutableStateOf(initialSortAscending)
|
||||||
private set
|
private set
|
||||||
|
|
||||||
private var selectedKey: Any? by mutableStateOf(null)
|
private var selectedKey: Any? by mutableStateOf(null)
|
||||||
|
|
||||||
private var sortedCache: List<T>? = null
|
private var internalSelectionRevision: Long by mutableStateOf(0L)
|
||||||
|
|
||||||
|
private var internalScrollRequestRevision: Long by mutableStateOf(0L)
|
||||||
|
|
||||||
|
private var filteredCache: List<T>? = null
|
||||||
|
|
||||||
|
private var visibleCache: List<T>? = null
|
||||||
|
|
||||||
|
private var cachedSelectionRevision: Long = Long.MIN_VALUE
|
||||||
|
|
||||||
private var _rowFilter by mutableStateOf<((T) -> Boolean)?>(null, androidx.compose.runtime.neverEqualPolicy())
|
private var _rowFilter by mutableStateOf<((T) -> Boolean)?>(null, androidx.compose.runtime.neverEqualPolicy())
|
||||||
|
|
||||||
/** Optional filter predicate. If set, [visibleRows] will only include matching rows. */
|
/** Optional filter predicate. If set, [filteredRows] only includes matching rows. */
|
||||||
var rowFilter: ((T) -> Boolean)?
|
var rowFilter: ((T) -> Boolean)?
|
||||||
get() = _rowFilter
|
get() = _rowFilter
|
||||||
set(value) {
|
set(value) {
|
||||||
@@ -294,7 +330,7 @@ class DataTableState<T>(
|
|||||||
* per inbound message on the thread that draws — with a column that has no
|
* per inbound message on the thread that draws — with a column that has no
|
||||||
* comparator calling its value function once per comparison on top.
|
* comparator calling its value function once per comparison on top.
|
||||||
*/
|
*/
|
||||||
val visibleRows: List<T>
|
val filteredRows: List<T>
|
||||||
get() {
|
get() {
|
||||||
/*
|
/*
|
||||||
* Read before the cache is consulted, and that order is the whole point.
|
* Read before the cache is consulted, and that order is the whole point.
|
||||||
@@ -307,45 +343,84 @@ class DataTableState<T>(
|
|||||||
val currentRows = rows
|
val currentRows = rows
|
||||||
val currentFilter = rowFilter
|
val currentFilter = rowFilter
|
||||||
contentRevision // read for the subscription: forceRedraw drops the cache
|
contentRevision // read for the subscription: forceRedraw drops the cache
|
||||||
val currentColumn = sortedColumnId
|
val currentColumnId = sortedColumnId
|
||||||
val ascending = sortAscending
|
val ascending = sortAscending
|
||||||
|
filteredCache?.let { return it }
|
||||||
|
|
||||||
sortedCache?.let { return it }
|
val filtered = if (currentFilter != null) currentRows.filter(currentFilter) else currentRows
|
||||||
|
val sorted = sort(filtered, currentColumnId, ascending)
|
||||||
|
|
||||||
val filteredRows = if (currentFilter != null) currentRows.filter(currentFilter) else currentRows
|
filteredCache = sorted
|
||||||
|
|
||||||
val column = columns.firstOrNull { it.id == currentColumn }
|
|
||||||
val sorted = if (column == null) {
|
|
||||||
filteredRows
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
* The displayed text is read once per row rather than once per
|
|
||||||
* comparison, and sortedBy is stable, so rows that compare equal keep
|
|
||||||
* the order they arrived in. Etappe 2 lost that: the JavaFX SortedList
|
|
||||||
* inserted by binary search and put ties wherever it landed, which made
|
|
||||||
* rows jump.
|
|
||||||
*/
|
|
||||||
val order = column.comparator
|
|
||||||
?: compareBy(filteredRows.associateWith { column.value(it) }::getValue)
|
|
||||||
|
|
||||||
if (ascending) {
|
|
||||||
filteredRows.sortedWith(order)
|
|
||||||
} else {
|
|
||||||
filteredRows.sortedWith(order.reversed())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sortedCache = sorted
|
|
||||||
return sorted
|
return sorted
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rows drawn by this table. A station selected outside the table can optionally be
|
||||||
|
* included even when the active filter rejects it; [filteredRows] remains the exact
|
||||||
|
* shared filter result used by the map.
|
||||||
|
*/
|
||||||
|
val visibleRows: List<T>
|
||||||
|
get() {
|
||||||
|
val currentRows = rows
|
||||||
|
val filtered = filteredRows
|
||||||
|
val revision = selectionRevision
|
||||||
|
|
||||||
|
if (!keepSelectionVisible) {
|
||||||
|
return filtered
|
||||||
|
}
|
||||||
|
|
||||||
|
if (visibleCache != null && cachedSelectionRevision == revision) {
|
||||||
|
return visibleCache.orEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
val selected = selectedRow
|
||||||
|
val visible = if (selected == null || filtered.any { keyOf(it) == keyOf(selected) }) {
|
||||||
|
filtered
|
||||||
|
} else if (currentRows.any { keyOf(it) == keyOf(selected) }) {
|
||||||
|
val filteredKeys = filtered.mapTo(HashSet<Any>()) { row -> keyOf(row) }
|
||||||
|
val selectedKey = keyOf(selected)
|
||||||
|
sort(currentRows.filter { row -> keyOf(row) == selectedKey || keyOf(row) in filteredKeys })
|
||||||
|
} else {
|
||||||
|
filtered
|
||||||
|
}
|
||||||
|
|
||||||
|
cachedSelectionRevision = revision
|
||||||
|
visibleCache = visible
|
||||||
|
return visible
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun sort(
|
||||||
|
source: List<T>,
|
||||||
|
columnId: String? = sortedColumnId,
|
||||||
|
ascending: Boolean = sortAscending,
|
||||||
|
): List<T> {
|
||||||
|
val column = columns.firstOrNull { it.id == columnId } ?: return source
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The displayed text is read once per row rather than once per comparison, and
|
||||||
|
* Kotlin's sort is stable, so equal values keep their source order.
|
||||||
|
*/
|
||||||
|
val order = column.comparator
|
||||||
|
?: compareBy(source.associateWith { column.value(it) }::getValue)
|
||||||
|
|
||||||
|
return if (ascending) source.sortedWith(order) else source.sortedWith(order.reversed())
|
||||||
|
}
|
||||||
|
|
||||||
private fun invalidateOrder() {
|
private fun invalidateOrder() {
|
||||||
sortedCache = null
|
filteredCache = null
|
||||||
|
visibleCache = null
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The selected row, or null when nothing is selected or it has gone. */
|
/** The selected row, or null when nothing is selected or it has gone. */
|
||||||
val selectedRow: T?
|
val selectedRow: T?
|
||||||
get() = selectedKey?.let { key -> rows.firstOrNull { rowKey.keyOf(it) == key } }
|
get() = selectionModel?.selected
|
||||||
|
?: selectedKey?.let { key -> rows.firstOrNull { rowKey.keyOf(it) == key } }
|
||||||
|
|
||||||
|
val selectionRevision: Long
|
||||||
|
get() = selectionModel?.selectionRevision ?: internalSelectionRevision
|
||||||
|
|
||||||
|
val scrollRequestRevision: Long
|
||||||
|
get() = selectionModel?.scrollRequestRevision ?: internalScrollRequestRevision
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces the rows.
|
* Replaces the rows.
|
||||||
@@ -356,18 +431,43 @@ class DataTableState<T>(
|
|||||||
* neighbour, which would silently point the operator at someone else.
|
* neighbour, which would silently point the operator at someone else.
|
||||||
*/
|
*/
|
||||||
fun replaceRows(newRows: List<T>) {
|
fun replaceRows(newRows: List<T>) {
|
||||||
|
val selectedIdentity = selectionModel?.selected?.let(rowKey::keyOf) ?: selectedKey
|
||||||
|
|
||||||
rows = newRows
|
rows = newRows
|
||||||
rowKey.retainOnly(newRows)
|
rowKey.retainOnly(newRows)
|
||||||
invalidateOrder()
|
invalidateOrder()
|
||||||
|
|
||||||
val key = selectedKey
|
val replacement = selectedIdentity?.let { key -> newRows.firstOrNull { rowKey.keyOf(it) == key } }
|
||||||
if (key != null && newRows.none { rowKey.keyOf(it) == key }) {
|
|
||||||
selectedKey = null
|
if (selectionModel != null) {
|
||||||
|
if (selectedIdentity != null) {
|
||||||
|
selectionModel.reconcile(replacement)
|
||||||
|
}
|
||||||
|
} else if (selectedIdentity != null) {
|
||||||
|
selectedKey = replacement?.let(rowKey::keyOf)
|
||||||
|
internalSelectionRevision++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun select(row: T?) {
|
fun select(row: T?) {
|
||||||
selectedKey = row?.let(rowKey::keyOf)
|
if (selectionModel != null) {
|
||||||
|
selectionModel.select(row)
|
||||||
|
} else {
|
||||||
|
selectedKey = row?.let(rowKey::keyOf)
|
||||||
|
internalSelectionRevision++
|
||||||
|
}
|
||||||
|
visibleCache = null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Requests navigation to the current selection without changing it. */
|
||||||
|
fun requestScrollToSelection() {
|
||||||
|
if (selectedRow == null) return
|
||||||
|
|
||||||
|
if (selectionModel != null) {
|
||||||
|
selectionModel.requestScroll()
|
||||||
|
} else {
|
||||||
|
internalScrollRequestRevision++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -377,7 +477,10 @@ class DataTableState<T>(
|
|||||||
*/
|
*/
|
||||||
fun keyOf(row: T): Any = rowKey.keyOf(row)
|
fun keyOf(row: T): Any = rowKey.keyOf(row)
|
||||||
|
|
||||||
fun isSelected(row: T): Boolean = selectedKey != null && rowKey.keyOf(row) == selectedKey
|
fun isSelected(row: T): Boolean {
|
||||||
|
val selected = selectedRow ?: return false
|
||||||
|
return rowKey.keyOf(row) == rowKey.keyOf(selected)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts by a column, cycling ascending, descending, unsorted.
|
* Sorts by a column, cycling ascending, descending, unsorted.
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
package kst4contest.view.compose
|
package kst4contest.view.compose
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.border
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.gestures.detectHorizontalDragGestures
|
import androidx.compose.foundation.gestures.detectHorizontalDragGestures
|
||||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
|
||||||
import androidx.compose.ui.unit.Dp
|
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
@@ -30,6 +29,9 @@ import androidx.compose.foundation.rememberScrollState
|
|||||||
import androidx.compose.foundation.rememberScrollbarAdapter
|
import androidx.compose.foundation.rememberScrollbarAdapter
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.ui.input.pointer.PointerIcon
|
import androidx.compose.ui.input.pointer.PointerIcon
|
||||||
|
import androidx.compose.ui.input.pointer.PointerEventType
|
||||||
|
import androidx.compose.ui.input.pointer.isSecondaryPressed
|
||||||
|
import androidx.compose.ui.input.pointer.onPointerEvent
|
||||||
import androidx.compose.ui.input.pointer.pointerHoverIcon
|
import androidx.compose.ui.input.pointer.pointerHoverIcon
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import java.awt.Cursor
|
import java.awt.Cursor
|
||||||
@@ -44,12 +46,19 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.input.pointer.pointerInput
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
|
import androidx.compose.ui.layout.LayoutCoordinates
|
||||||
|
import androidx.compose.ui.layout.onGloballyPositioned
|
||||||
import androidx.compose.ui.platform.LocalDensity
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.text.rememberTextMeasurer
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.IntOffset
|
||||||
|
import kst4contest.view.i18n.LocalStrings
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A multi-column table.
|
* A multi-column table.
|
||||||
@@ -71,15 +80,19 @@ import androidx.compose.ui.unit.dp
|
|||||||
* the supported way to reach the hover text the JavaFX cells had, and losing that
|
* the supported way to reach the hover text the JavaFX cells had, and losing that
|
||||||
* loses the only way to read a value that does not fit its column.
|
* loses the only way to read a value that does not fit its column.
|
||||||
*/
|
*/
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class, ExperimentalComposeUiApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun <T> DataTableView(
|
fun <T> DataTableView(
|
||||||
state: DataTableState<T>,
|
state: DataTableState<T>,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
rowStyle: ((T) -> CellAccent?)? = null,
|
rowStyle: ((T) -> CellAccent?)? = null,
|
||||||
|
emphasizeCell: ((T, DataColumn<T>) -> Boolean)? = null,
|
||||||
onRowClick: ((T) -> Unit)? = null,
|
onRowClick: ((T) -> Unit)? = null,
|
||||||
|
onRowContextMenu: ((T, IntOffset) -> Unit)? = null,
|
||||||
|
selectOnRowClick: Boolean = true,
|
||||||
) {
|
) {
|
||||||
val density = LocalDensity.current
|
val density = LocalDensity.current
|
||||||
|
val automaticWidths = rememberAutomaticColumnWidths(state)
|
||||||
|
|
||||||
val horizontal = rememberScrollState()
|
val horizontal = rememberScrollState()
|
||||||
val vertical = rememberLazyListState()
|
val vertical = rememberLazyListState()
|
||||||
@@ -113,16 +126,36 @@ fun <T> DataTableView(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var handledScrollRequest by remember(state) { mutableStateOf(0L) }
|
||||||
|
val scrollRequest = state.scrollRequestRevision
|
||||||
|
val displayedRows = state.visibleRows
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Resolve the index only after reading the current filtered and sorted rows. If the
|
||||||
|
* selected row has not arrived yet, leave the request pending and retry when that
|
||||||
|
* list changes. A handled request is never repeated by an ordinary data refresh.
|
||||||
|
*/
|
||||||
|
LaunchedEffect(scrollRequest, displayedRows) {
|
||||||
|
if (scrollRequest <= handledScrollRequest) return@LaunchedEffect
|
||||||
|
|
||||||
|
val index = displayedRows.indexOfFirst(state::isSelected)
|
||||||
|
if (index >= 0) {
|
||||||
|
vertical.scrollToItem(index)
|
||||||
|
handledScrollRequest = scrollRequest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Both directions scroll. The columns of these two tables need about 890dp and
|
* Both directions scroll. The columns of these two tables need about 890dp and
|
||||||
* 1000dp, and the stored window width starts at 700: without this the last columns
|
* 1000dp, and the stored window width starts at 700: without this the last columns
|
||||||
* are simply unreachable, and so are the handles that would narrow them. The JavaFX
|
* are simply unreachable, and so are the handles that would narrow them. The JavaFX
|
||||||
* tables had a horizontal scrollbar.
|
* tables had a horizontal scrollbar.
|
||||||
*/
|
*/
|
||||||
BoxWithConstraints(modifier = modifier.fillMaxSize()) {
|
Box(
|
||||||
val slack = unusedWidth(state, maxWidth)
|
modifier = modifier
|
||||||
val lastColumnId = state.orderedColumns.lastOrNull()?.id
|
.fillMaxSize()
|
||||||
|
.border(Density.HAIRLINE, MaterialTheme.colorScheme.outline),
|
||||||
|
) {
|
||||||
Column(modifier = Modifier.fillMaxSize()) {
|
Column(modifier = Modifier.fillMaxSize()) {
|
||||||
/*
|
/*
|
||||||
* A second header row above the first, spanning the columns that share a
|
* A second header row above the first, spanning the columns that share a
|
||||||
@@ -150,9 +183,8 @@ fun <T> DataTableView(
|
|||||||
|
|
||||||
val width = (index until index + span).sumOf { position ->
|
val width = (index until index + span).sumOf { position ->
|
||||||
val column = state.orderedColumns[position]
|
val column = state.orderedColumns[position]
|
||||||
val stored = state.widthOf(column.id)
|
effectiveColumnWidthDp(state, column, automaticWidths).toDouble() +
|
||||||
val own = stored ?: (DEFAULT_COLUMN_WIDTH * column.weight).value.toDouble()
|
Density.COLUMN_HANDLE_WIDTH.value
|
||||||
own + Density.COLUMN_HANDLE_WIDTH.value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
@@ -202,7 +234,7 @@ fun <T> DataTableView(
|
|||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.columnWidth(state, column, if (column.id == lastColumnId) slack else 0.dp)
|
.columnWidth(state, column, automaticWidths)
|
||||||
.fillMaxHeight()
|
.fillMaxHeight()
|
||||||
.clickable { state.toggleSort(column.id) }
|
.clickable { state.toggleSort(column.id) }
|
||||||
.pointerInput(column.id, index) {
|
.pointerInput(column.id, index) {
|
||||||
@@ -211,7 +243,7 @@ fun <T> DataTableView(
|
|||||||
onDragCancel = { dragged = 0f },
|
onDragCancel = { dragged = 0f },
|
||||||
) { _, dragAmount ->
|
) { _, dragAmount ->
|
||||||
dragged += dragAmount
|
dragged += dragAmount
|
||||||
val step = with(density) { DEFAULT_COLUMN_WIDTH.toPx() } / 2f
|
val step = with(density) { DEFAULT_COLUMN_WIDTH_DP.dp.toPx() } / 2f
|
||||||
|
|
||||||
if (dragged > step) {
|
if (dragged > step) {
|
||||||
state.moveColumn(column.id, index + 1)
|
state.moveColumn(column.id, index + 1)
|
||||||
@@ -258,8 +290,11 @@ fun <T> DataTableView(
|
|||||||
* and writes that into preferences.xml.
|
* and writes that into preferences.xml.
|
||||||
*/
|
*/
|
||||||
val deltaDp = with(density) { dragAmount.toDp().value }
|
val deltaDp = with(density) { dragAmount.toDp().value }
|
||||||
val current = state.widthOf(column.id)
|
val current = effectiveColumnWidthDp(
|
||||||
?: (DEFAULT_COLUMN_WIDTH * column.weight).value.toDouble()
|
state,
|
||||||
|
column,
|
||||||
|
automaticWidths,
|
||||||
|
).toDouble()
|
||||||
|
|
||||||
state.resizeColumn(column.id, current + deltaDp)
|
state.resizeColumn(column.id, current + deltaDp)
|
||||||
}
|
}
|
||||||
@@ -278,7 +313,12 @@ fun <T> DataTableView(
|
|||||||
|
|
||||||
HorizontalDivider(thickness = Density.HAIRLINE)
|
HorizontalDivider(thickness = Density.HAIRLINE)
|
||||||
|
|
||||||
Box(modifier = Modifier.weight(1f).fillMaxWidth()) {
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.weight(1f)
|
||||||
|
.fillMaxWidth()
|
||||||
|
.background(MaterialTheme.colorScheme.surface.copy(alpha = 0.45f)),
|
||||||
|
) {
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
state = vertical,
|
state = vertical,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@@ -291,6 +331,9 @@ fun <T> DataTableView(
|
|||||||
val accent = rowStyle?.invoke(row)
|
val accent = rowStyle?.invoke(row)
|
||||||
val isEven = index % 2 == 0
|
val isEven = index % 2 == 0
|
||||||
val _forceRedraw = state.contentRevision
|
val _forceRedraw = state.contentRevision
|
||||||
|
var rowCoordinates by remember(state.keyOf(row)) {
|
||||||
|
mutableStateOf<LayoutCoordinates?>(null)
|
||||||
|
}
|
||||||
|
|
||||||
Column(modifier = Modifier.fillMaxWidth()) {
|
Column(modifier = Modifier.fillMaxWidth()) {
|
||||||
Row(
|
Row(
|
||||||
@@ -306,9 +349,25 @@ fun <T> DataTableView(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
.clickable {
|
.clickable {
|
||||||
state.select(row)
|
if (selectOnRowClick) {
|
||||||
|
state.select(row)
|
||||||
|
}
|
||||||
onRowClick?.invoke(row)
|
onRowClick?.invoke(row)
|
||||||
}
|
}
|
||||||
|
.onGloballyPositioned { rowCoordinates = it }
|
||||||
|
.onPointerEvent(PointerEventType.Press) { event ->
|
||||||
|
if (event.buttons.isSecondaryPressed) {
|
||||||
|
val local = event.changes.firstOrNull()?.position
|
||||||
|
val window = local?.let { rowCoordinates?.localToWindow(it) }
|
||||||
|
if (window != null) {
|
||||||
|
onRowContextMenu?.invoke(
|
||||||
|
row,
|
||||||
|
IntOffset(window.x.roundToInt(), window.y.roundToInt()),
|
||||||
|
)
|
||||||
|
event.changes.forEach { it.consume() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
.heightIn(min = Density.ROW_MIN_HEIGHT),
|
.heightIn(min = Density.ROW_MIN_HEIGHT),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
@@ -318,7 +377,7 @@ fun <T> DataTableView(
|
|||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.columnWidth(state, column, if (column.id == lastColumnId) slack else 0.dp)
|
.columnWidth(state, column, automaticWidths)
|
||||||
.fillMaxHeight()
|
.fillMaxHeight()
|
||||||
.background(cell?.background ?: Color.Transparent)
|
.background(cell?.background ?: Color.Transparent)
|
||||||
.padding(horizontal = 4.dp, vertical = 2.dp),
|
.padding(horizontal = 4.dp, vertical = 2.dp),
|
||||||
@@ -345,6 +404,11 @@ fun <T> DataTableView(
|
|||||||
Text(
|
Text(
|
||||||
value,
|
value,
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
fontWeight = if (emphasizeCell?.invoke(row, column) == true) {
|
||||||
|
FontWeight.Bold
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
},
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
color = cell?.foreground
|
color = cell?.foreground
|
||||||
@@ -378,6 +442,15 @@ fun <T> DataTableView(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (state.visibleRows.isEmpty()) {
|
||||||
|
Text(
|
||||||
|
text = LocalStrings.current.tableEmpty,
|
||||||
|
modifier = Modifier.align(Alignment.Center).padding(8.dp),
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.outline,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
VerticalScrollbar(
|
VerticalScrollbar(
|
||||||
adapter = rememberScrollbarAdapter(vertical),
|
adapter = rememberScrollbarAdapter(vertical),
|
||||||
modifier = Modifier.align(Alignment.CenterEnd).fillMaxHeight(),
|
modifier = Modifier.align(Alignment.CenterEnd).fillMaxHeight(),
|
||||||
@@ -402,39 +475,71 @@ fun <T> DataTableView(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/** A stored width wins over the measured automatic width, even when it is narrower. */
|
||||||
* A stored width when the operator has sized this column, otherwise the column's own
|
|
||||||
* weight. The stored value wins because it is the operator's decision.
|
|
||||||
*
|
|
||||||
* @param extra added to the last column so the table fills the window instead of
|
|
||||||
* leaving a band of empty background to the right. The JavaFX table did the
|
|
||||||
* same through `flexibleInitialWidth`.
|
|
||||||
*/
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun <T> Modifier.columnWidth(
|
private fun <T> Modifier.columnWidth(
|
||||||
state: DataTableState<T>,
|
state: DataTableState<T>,
|
||||||
column: DataColumn<T>,
|
column: DataColumn<T>,
|
||||||
extra: Dp = 0.dp,
|
automaticWidths: Map<String, Float>,
|
||||||
): Modifier {
|
): Modifier {
|
||||||
val stored = state.widthOf(column.id)
|
return this.width(effectiveColumnWidthDp(state, column, automaticWidths).dp)
|
||||||
val own = if (stored != null) stored.dp else DEFAULT_COLUMN_WIDTH * column.weight
|
|
||||||
|
|
||||||
return this.width(own + extra)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How much is left over once every column has its width. Zero when the columns are
|
* Measures automatic columns once from their headers and once more when the first
|
||||||
* already wider than the window, in which case the table scrolls.
|
* source rows arrive. Later chat events do not resize a live table.
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
private fun <T> unusedWidth(state: DataTableState<T>, available: Dp): Dp {
|
private fun <T> rememberAutomaticColumnWidths(state: DataTableState<T>): Map<String, Float> {
|
||||||
val used = state.orderedColumns.sumOf { column ->
|
val density = LocalDensity.current
|
||||||
val stored = state.widthOf(column.id)
|
val measurer = rememberTextMeasurer()
|
||||||
val own = if (stored != null) stored else (DEFAULT_COLUMN_WIDTH * column.weight).value.toDouble()
|
val headerStyle = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.Bold)
|
||||||
own + Density.COLUMN_HANDLE_WIDTH.value
|
val cellStyle = MaterialTheme.typography.bodyMedium
|
||||||
}
|
val hasSourceRows = state.rows.isNotEmpty()
|
||||||
|
val titles = state.orderedColumns.associate { column -> column.id to column.title() }
|
||||||
|
|
||||||
return (available.value - used).coerceAtLeast(0.0).dp
|
return remember(
|
||||||
|
state,
|
||||||
|
density.density,
|
||||||
|
density.fontScale,
|
||||||
|
headerStyle,
|
||||||
|
cellStyle,
|
||||||
|
titles,
|
||||||
|
hasSourceRows,
|
||||||
|
) {
|
||||||
|
val sample = if (hasSourceRows) state.rows.take(AUTO_WIDTH_SAMPLE_SIZE) else emptyList()
|
||||||
|
|
||||||
|
state.orderedColumns.associate { column ->
|
||||||
|
val title = titles.getValue(column.id) + SORT_INDICATOR_SAMPLE
|
||||||
|
val headerWidthPx = measurer.measure(title, headerStyle).size.width
|
||||||
|
val contentWidthPx = sample.maxOfOrNull { row ->
|
||||||
|
val value = runCatching { column.value(row) }.getOrDefault("")
|
||||||
|
measurer.measure(value, cellStyle).size.width
|
||||||
|
} ?: 0
|
||||||
|
val measuredDp = with(density) {
|
||||||
|
maxOf(headerWidthPx, contentWidthPx).toDp().value + CELL_HORIZONTAL_PADDING_DP
|
||||||
|
}
|
||||||
|
val maximumDp = (AUTO_WIDTH_MAX_BASE_DP * column.weight.coerceAtLeast(0.5f))
|
||||||
|
.coerceIn(AUTO_WIDTH_MIN_MAX_DP, AUTO_WIDTH_ABSOLUTE_MAX_DP)
|
||||||
|
|
||||||
|
column.id to measuredDp.coerceIn(AUTO_WIDTH_MIN_DP, maximumDp)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val DEFAULT_COLUMN_WIDTH = 85.dp
|
internal fun <T> effectiveColumnWidthDp(
|
||||||
|
state: DataTableState<T>,
|
||||||
|
column: DataColumn<T>,
|
||||||
|
automaticWidths: Map<String, Float>,
|
||||||
|
): Float = state.widthOf(column.id)?.toFloat()
|
||||||
|
?: automaticWidths[column.id]
|
||||||
|
?: DEFAULT_COLUMN_WIDTH_DP * column.weight
|
||||||
|
|
||||||
|
private const val AUTO_WIDTH_SAMPLE_SIZE = 160
|
||||||
|
private const val AUTO_WIDTH_MIN_DP = 32f
|
||||||
|
private const val AUTO_WIDTH_MIN_MAX_DP = 90f
|
||||||
|
private const val AUTO_WIDTH_MAX_BASE_DP = 180f
|
||||||
|
private const val AUTO_WIDTH_ABSOLUTE_MAX_DP = 360f
|
||||||
|
private const val CELL_HORIZONTAL_PADDING_DP = 10f
|
||||||
|
private const val DEFAULT_COLUMN_WIDTH_DP = 85f
|
||||||
|
private const val SORT_INDICATOR_SAMPLE = " ▲"
|
||||||
@@ -13,27 +13,36 @@ import androidx.compose.ui.unit.dp
|
|||||||
* over thirty fields, so those defaults turn a settings window into a scrolling
|
* over thirty fields, so those defaults turn a settings window into a scrolling
|
||||||
* exercise and make a desktop application look like a phone.
|
* exercise and make a desktop application look like a phone.
|
||||||
*
|
*
|
||||||
* Every height here is a **minimum**, never a fixed size. The configured base font
|
* Interactive controls share one minimum visible height. Their common font and padding
|
||||||
* size scales all text through Typography.scaledTo, and a fixed height would clip a
|
* keep the standard size exact while still allowing a larger configured font to grow.
|
||||||
* larger font instead of growing with it.
|
|
||||||
*/
|
*/
|
||||||
internal object Density {
|
internal object Density {
|
||||||
|
|
||||||
/** Text fields, pickers and anything else on the field column. */
|
/** Minimum for buttons, text fields, choices and checkbox rows in the desktop UI. */
|
||||||
val FIELD_MIN_HEIGHT = 30.dp
|
val CONTROL_HEIGHT = 26.dp
|
||||||
|
|
||||||
/** Inside a text field. The vertical value is what buys back the 56dp. */
|
/** Text stays vertically centred by the control instead of by extra padding. */
|
||||||
val FIELD_CONTENT_PADDING = PaddingValues(horizontal = 8.dp, vertical = 2.dp)
|
val FIELD_CONTENT_PADDING = PaddingValues(horizontal = 6.dp, vertical = 0.dp)
|
||||||
|
|
||||||
val BUTTON_MIN_HEIGHT = 24.dp
|
val BUTTON_CONTENT_PADDING = PaddingValues(horizontal = 6.dp, vertical = 0.dp)
|
||||||
|
|
||||||
val BUTTON_CONTENT_PADDING = PaddingValues(horizontal = 8.dp, vertical = 1.dp)
|
|
||||||
|
|
||||||
/** Square-ish, not a pill: the pill shape is the strongest mobile tell. */
|
/** Square-ish, not a pill: the pill shape is the strongest mobile tell. */
|
||||||
val BUTTON_SHAPE = RoundedCornerShape(4.dp)
|
val BUTTON_SHAPE = RoundedCornerShape(4.dp)
|
||||||
|
|
||||||
/** One row of a list or table. */
|
/** One row of a list or table. */
|
||||||
val ROW_MIN_HEIGHT = 26.dp
|
val ROW_MIN_HEIGHT = CONTROL_HEIGHT
|
||||||
|
|
||||||
|
/** Equal width for all eight compass-direction filter buttons. */
|
||||||
|
val DIRECTION_BUTTON_WIDTH = 28.dp
|
||||||
|
|
||||||
|
/** Two-letter compass labels need only a small inset inside their fixed width. */
|
||||||
|
val DIRECTION_BUTTON_HORIZONTAL_PADDING = 2.dp
|
||||||
|
|
||||||
|
/** Enough room for the NOT-QRV and sked groups to remain usable side by side. */
|
||||||
|
val SELECTED_ACTION_GROUPS_ROW_MIN_WIDTH = 450.dp
|
||||||
|
|
||||||
|
/** Keeps the station actions usable when a stored splitter position is too low. */
|
||||||
|
val SELECTED_ACTION_AREA_MIN_HEIGHT = 160.dp
|
||||||
|
|
||||||
val TAB_MIN_HEIGHT = 30.dp
|
val TAB_MIN_HEIGHT = 30.dp
|
||||||
|
|
||||||
@@ -55,6 +64,9 @@ internal object Density {
|
|||||||
/** Between buttons in a row. */
|
/** Between buttons in a row. */
|
||||||
val BUTTON_GAP = 6.dp
|
val BUTTON_GAP = 6.dp
|
||||||
|
|
||||||
|
/** Compact inset for a visually grouped settings section. */
|
||||||
|
val GROUP_CONTENT_PADDING = PaddingValues(horizontal = 8.dp, vertical = 6.dp)
|
||||||
|
|
||||||
/** Around a selected row, and the hairline between rows. */
|
/** Around a selected row, and the hairline between rows. */
|
||||||
val SELECTION_BORDER = 1.5.dp
|
val SELECTION_BORDER = 1.5.dp
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.Box
|
|||||||
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
||||||
import androidx.compose.foundation.layout.FlowRow
|
import androidx.compose.foundation.layout.FlowRow
|
||||||
import androidx.compose.foundation.layout.FlowRowScope
|
import androidx.compose.foundation.layout.FlowRowScope
|
||||||
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
@@ -17,7 +18,11 @@ import androidx.compose.foundation.text.BasicTextField
|
|||||||
import androidx.compose.foundation.BorderStroke
|
import androidx.compose.foundation.BorderStroke
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.interaction.collectIsHoveredAsState
|
import androidx.compose.foundation.interaction.collectIsHoveredAsState
|
||||||
|
import androidx.compose.foundation.interaction.collectIsFocusedAsState
|
||||||
import androidx.compose.foundation.interaction.collectIsPressedAsState
|
import androidx.compose.foundation.interaction.collectIsPressedAsState
|
||||||
|
import androidx.compose.foundation.border
|
||||||
|
import androidx.compose.foundation.selection.selectable
|
||||||
|
import androidx.compose.foundation.selection.toggleable
|
||||||
import androidx.compose.ui.graphics.Brush
|
import androidx.compose.ui.graphics.Brush
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.ButtonDefaults
|
import androidx.compose.material3.ButtonDefaults
|
||||||
@@ -43,17 +48,29 @@ import androidx.compose.runtime.setValue
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.focus.onFocusChanged
|
import androidx.compose.ui.focus.onFocusChanged
|
||||||
|
import androidx.compose.ui.draw.drawBehind
|
||||||
|
import androidx.compose.ui.geometry.Offset
|
||||||
|
import androidx.compose.ui.geometry.Size
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.SolidColor
|
import androidx.compose.ui.graphics.SolidColor
|
||||||
|
import androidx.compose.ui.graphics.luminance
|
||||||
import androidx.compose.ui.input.key.Key
|
import androidx.compose.ui.input.key.Key
|
||||||
import androidx.compose.ui.input.key.KeyEventType
|
import androidx.compose.ui.input.key.KeyEventType
|
||||||
import androidx.compose.ui.input.key.key
|
import androidx.compose.ui.input.key.key
|
||||||
import androidx.compose.ui.input.key.onKeyEvent
|
import androidx.compose.ui.input.key.onKeyEvent
|
||||||
import androidx.compose.ui.input.key.type
|
import androidx.compose.ui.input.key.type
|
||||||
|
import androidx.compose.ui.text.TextStyle
|
||||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||||
import androidx.compose.ui.text.input.VisualTransformation
|
import androidx.compose.ui.text.input.VisualTransformation
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
|
import androidx.compose.ui.unit.TextUnit
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.semantics.Role
|
||||||
|
|
||||||
|
/** One font size and natural line box for every compact interactive control. */
|
||||||
|
@Composable
|
||||||
|
internal fun compactControlTextStyle(): TextStyle =
|
||||||
|
MaterialTheme.typography.bodyMedium.copy(lineHeight = TextUnit.Unspecified)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form controls shared by the settings tabs.
|
* Form controls shared by the settings tabs.
|
||||||
@@ -232,6 +249,7 @@ object Form {
|
|||||||
val draft = rememberDraft(selected)
|
val draft = rememberDraft(selected)
|
||||||
|
|
||||||
labelled(label) {
|
labelled(label) {
|
||||||
|
CompositionLocalProvider(LocalMinimumInteractiveComponentSize provides 0.dp) {
|
||||||
Box {
|
Box {
|
||||||
OutlinedButton(
|
OutlinedButton(
|
||||||
onClick = { expanded = true },
|
onClick = { expanded = true },
|
||||||
@@ -240,18 +258,20 @@ object Form {
|
|||||||
contentPadding = Density.FIELD_CONTENT_PADDING,
|
contentPadding = Density.FIELD_CONTENT_PADDING,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.heightIn(min = Density.FIELD_MIN_HEIGHT),
|
.heightIn(min = Density.CONTROL_HEIGHT),
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
draft.value?.let(describe) ?: kst4contest.view.i18n.LocalStrings.current.formNotSelected,
|
draft.value?.let(describe) ?: kst4contest.view.i18n.LocalStrings.current.formNotSelected,
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = compactControlTextStyle(),
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
DropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {
|
DropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {
|
||||||
items.forEach { item ->
|
items.forEach { item ->
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
text = { Text(describe(item), style = MaterialTheme.typography.bodyMedium) },
|
text = { Text(describe(item), style = compactControlTextStyle()) },
|
||||||
|
contentPadding = Density.FIELD_CONTENT_PADDING,
|
||||||
|
modifier = Modifier.heightIn(min = Density.CONTROL_HEIGHT),
|
||||||
onClick = {
|
onClick = {
|
||||||
expanded = false
|
expanded = false
|
||||||
draft.value = item
|
draft.value = item
|
||||||
@@ -261,6 +281,7 @@ object Form {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,30 +292,39 @@ object Form {
|
|||||||
selected: T?,
|
selected: T?,
|
||||||
describe: (T) -> String,
|
describe: (T) -> String,
|
||||||
enabled: Boolean = true,
|
enabled: Boolean = true,
|
||||||
|
trailingText: String = "",
|
||||||
onSelect: (T) -> Unit,
|
onSelect: (T) -> Unit,
|
||||||
) {
|
) {
|
||||||
var expanded by remember { mutableStateOf(false) }
|
var expanded by remember { mutableStateOf(false) }
|
||||||
val draft = rememberDraft(selected)
|
val draft = rememberDraft(selected)
|
||||||
|
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
Row(
|
||||||
Text(label, style = MaterialTheme.typography.bodyMedium, modifier = Modifier.padding(end = 8.dp))
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier.heightIn(min = Density.CONTROL_HEIGHT),
|
||||||
|
) {
|
||||||
|
if (label.isNotBlank()) {
|
||||||
|
Text(label, style = compactControlTextStyle(), modifier = Modifier.padding(end = 4.dp))
|
||||||
|
}
|
||||||
|
CompositionLocalProvider(LocalMinimumInteractiveComponentSize provides 0.dp) {
|
||||||
Box {
|
Box {
|
||||||
OutlinedButton(
|
OutlinedButton(
|
||||||
onClick = { expanded = true },
|
onClick = { expanded = true },
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
shape = Density.BUTTON_SHAPE,
|
shape = Density.BUTTON_SHAPE,
|
||||||
contentPadding = Density.FIELD_CONTENT_PADDING,
|
contentPadding = Density.FIELD_CONTENT_PADDING,
|
||||||
modifier = Modifier.heightIn(min = Density.FIELD_MIN_HEIGHT),
|
modifier = Modifier.heightIn(min = Density.CONTROL_HEIGHT),
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
draft.value?.let(describe) ?: kst4contest.view.i18n.LocalStrings.current.formNotSelected,
|
draft.value?.let(describe) ?: kst4contest.view.i18n.LocalStrings.current.formNotSelected,
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = compactControlTextStyle(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
DropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {
|
DropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {
|
||||||
items.forEach { item ->
|
items.forEach { item ->
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
text = { Text(describe(item), style = MaterialTheme.typography.bodyMedium) },
|
text = { Text(describe(item), style = compactControlTextStyle()) },
|
||||||
|
contentPadding = Density.FIELD_CONTENT_PADDING,
|
||||||
|
modifier = Modifier.heightIn(min = Density.CONTROL_HEIGHT),
|
||||||
onClick = {
|
onClick = {
|
||||||
expanded = false
|
expanded = false
|
||||||
draft.value = item
|
draft.value = item
|
||||||
@@ -304,32 +334,81 @@ object Form {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (trailingText.isNotBlank()) {
|
||||||
|
Text(
|
||||||
|
trailingText,
|
||||||
|
style = compactControlTextStyle(),
|
||||||
|
modifier = Modifier.padding(start = 4.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun check(label: String, value: Boolean, onChange: (Boolean) -> Unit) {
|
fun check(
|
||||||
|
label: String,
|
||||||
|
value: Boolean,
|
||||||
|
enabled: Boolean = true,
|
||||||
|
onChange: (Boolean) -> Unit,
|
||||||
|
) {
|
||||||
val draft = rememberDraft(value)
|
val draft = rememberDraft(value)
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier.heightIn(min = Density.ROW_MIN_HEIGHT),
|
modifier = Modifier.heightIn(min = Density.CONTROL_HEIGHT),
|
||||||
) {
|
) {
|
||||||
CompactCheckbox(draft.value) { ticked ->
|
CompactCheckbox(draft.value, enabled = enabled) { ticked ->
|
||||||
draft.value = ticked
|
draft.value = ticked
|
||||||
onChange(ticked)
|
onChange(ticked)
|
||||||
}
|
}
|
||||||
Text(label, modifier = Modifier.padding(start = 6.dp))
|
Text(
|
||||||
|
label,
|
||||||
|
color = if (enabled) {
|
||||||
|
MaterialTheme.colorScheme.onSurface
|
||||||
|
} else {
|
||||||
|
MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
|
||||||
|
},
|
||||||
|
style = compactControlTextStyle(),
|
||||||
|
modifier = Modifier.padding(start = 4.dp),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A compact two-state button for dense desktop option groups. */
|
||||||
|
@Composable
|
||||||
|
fun toggle(
|
||||||
|
text: String,
|
||||||
|
checked: Boolean,
|
||||||
|
enabled: Boolean = true,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
onCheckedChange: (Boolean) -> Unit,
|
||||||
|
) {
|
||||||
|
CompactToggleButton(
|
||||||
|
text = text,
|
||||||
|
checked = checked,
|
||||||
|
enabled = enabled,
|
||||||
|
modifier = modifier,
|
||||||
|
onCheckedChange = onCheckedChange,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun int(label: String, value: Int, onChange: (Int) -> Unit) =
|
fun int(label: String, value: Int, onChange: (Int) -> Unit) =
|
||||||
number(label, value, { it.trim().toIntOrNull() }, onChange)
|
number(label, value, { it.trim().toIntOrNull() }, onChange)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun decimal(label: String, value: Double, onChange: (Double) -> Unit) =
|
fun decimal(
|
||||||
number(label, value, { it.trim().replace(',', '.').toDoubleOrNull() }, onChange)
|
label: String,
|
||||||
|
value: Double,
|
||||||
|
isValid: (Double) -> Boolean = { true },
|
||||||
|
onChange: (Double) -> Unit,
|
||||||
|
) = number(
|
||||||
|
label,
|
||||||
|
value,
|
||||||
|
{ text -> text.trim().replace(',', '.').toDoubleOrNull()?.takeIf(isValid) },
|
||||||
|
onChange,
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number field behind [int] and [decimal].
|
* The number field behind [int] and [decimal].
|
||||||
@@ -401,6 +480,30 @@ object Form {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A compact settings group that needs stronger separation than a labelled divider. */
|
||||||
|
@Composable
|
||||||
|
fun panelSection(title: String, content: @Composable () -> Unit) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(top = 10.dp)
|
||||||
|
.background(
|
||||||
|
color = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.55f),
|
||||||
|
shape = Density.BUTTON_SHAPE,
|
||||||
|
)
|
||||||
|
.border(
|
||||||
|
width = Density.HAIRLINE,
|
||||||
|
color = MaterialTheme.colorScheme.outlineVariant,
|
||||||
|
shape = Density.BUTTON_SHAPE,
|
||||||
|
)
|
||||||
|
.padding(Density.GROUP_CONTENT_PADDING),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(Density.FIELD_GAP),
|
||||||
|
) {
|
||||||
|
Text(title, style = MaterialTheme.typography.titleSmall)
|
||||||
|
content()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A section whose controls flow across the width instead of stacking.
|
* A section whose controls flow across the width instead of stacking.
|
||||||
*
|
*
|
||||||
@@ -430,26 +533,49 @@ object Form {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The button of the settings windows: square-ish corners and desktop padding.
|
* The shared desktop button used in settings, filter and shortcut areas.
|
||||||
*
|
|
||||||
* Material's own Button is a 40dp pill, which is the single strongest reason the
|
|
||||||
* window looked like a phone application.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* The button of the settings windows.
|
|
||||||
*
|
*
|
||||||
* Material's own Button is a 40dp pill; this one is square-ish and at desktop
|
* Material's own Button is a 40dp pill; this one is square-ish and at desktop
|
||||||
* height. It also carries the two states the JavaFX stylesheets give every button:
|
* height. It also carries the two states the JavaFX stylesheets give every button:
|
||||||
* a gradient while the pointer is over it and a red border while it is held down.
|
* a gradient while the pointer is over it and a red border while it is held down.
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun button(text: String, enabled: Boolean = true, onClick: () -> Unit) {
|
fun button(
|
||||||
|
text: String,
|
||||||
|
enabled: Boolean = true,
|
||||||
|
accented: Boolean = false,
|
||||||
|
selected: Boolean = false,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
horizontalPadding: Dp = 6.dp,
|
||||||
|
onClick: () -> Unit,
|
||||||
|
) {
|
||||||
val palette = LocalJavaFxPalette.current
|
val palette = LocalJavaFxPalette.current
|
||||||
val interactions = remember { MutableInteractionSource() }
|
val interactions = remember { MutableInteractionSource() }
|
||||||
val hovered by interactions.collectIsHoveredAsState()
|
val hovered by interactions.collectIsHoveredAsState()
|
||||||
val pressed by interactions.collectIsPressedAsState()
|
val pressed by interactions.collectIsPressedAsState()
|
||||||
|
|
||||||
val hoverGradient = palette.buttonHoverGradient
|
val hoverGradient = palette.buttonHoverGradient
|
||||||
|
val accentGradient = if (palette.windowBackground.luminance() < 0.5f) {
|
||||||
|
listOf(Color(0xFF008000), Color(0xFF90EE90))
|
||||||
|
} else {
|
||||||
|
listOf(Color(0xFF00FFFF), Color(0xFFFF99FF))
|
||||||
|
}
|
||||||
|
val backgroundGradient = when {
|
||||||
|
!enabled -> emptyList()
|
||||||
|
hovered && hoverGradient.size >= 2 -> hoverGradient
|
||||||
|
accented -> accentGradient
|
||||||
|
else -> emptyList()
|
||||||
|
}
|
||||||
|
val containerColor = when {
|
||||||
|
backgroundGradient.isNotEmpty() -> Color.Transparent
|
||||||
|
selected -> MaterialTheme.colorScheme.primary
|
||||||
|
else -> MaterialTheme.colorScheme.surfaceVariant
|
||||||
|
}
|
||||||
|
val contentColor = when {
|
||||||
|
hovered && enabled && hoverGradient.isNotEmpty() -> Color.Black
|
||||||
|
accented -> Color(0xFF395306)
|
||||||
|
selected -> MaterialTheme.colorScheme.onPrimary
|
||||||
|
else -> MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
}
|
||||||
|
|
||||||
CompositionLocalProvider(
|
CompositionLocalProvider(
|
||||||
LocalMinimumInteractiveComponentSize provides 0.dp
|
LocalMinimumInteractiveComponentSize provides 0.dp
|
||||||
@@ -458,35 +584,28 @@ object Form {
|
|||||||
onClick = onClick,
|
onClick = onClick,
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
shape = Density.BUTTON_SHAPE,
|
shape = Density.BUTTON_SHAPE,
|
||||||
contentPadding = Density.BUTTON_CONTENT_PADDING,
|
contentPadding = PaddingValues(horizontal = horizontalPadding, vertical = 0.dp),
|
||||||
interactionSource = interactions,
|
interactionSource = interactions,
|
||||||
border = if (pressed) {
|
border = when {
|
||||||
BorderStroke(Density.SELECTION_BORDER, palette.buttonPressedBorder)
|
pressed -> BorderStroke(Density.SELECTION_BORDER, palette.buttonPressedBorder)
|
||||||
} else {
|
enabled -> BorderStroke(Density.HAIRLINE, MaterialTheme.colorScheme.outline)
|
||||||
null
|
else -> BorderStroke(
|
||||||
},
|
Density.HAIRLINE,
|
||||||
colors = if (hovered && enabled && hoverGradient.isNotEmpty()) {
|
MaterialTheme.colorScheme.outline.copy(alpha = 0.38f),
|
||||||
/*
|
|
||||||
* Compose paints a solid container, so the gradient is applied as the
|
|
||||||
* background below and the container itself is cleared. The text turns
|
|
||||||
* dark because the gradient the sheets use is a bright lime.
|
|
||||||
*/
|
|
||||||
ButtonDefaults.buttonColors(
|
|
||||||
containerColor = Color.Transparent,
|
|
||||||
contentColor = Color.Black,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
ButtonDefaults.buttonColors(
|
|
||||||
containerColor = MaterialTheme.colorScheme.surfaceVariant,
|
|
||||||
contentColor = MaterialTheme.colorScheme.onSurfaceVariant,
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
modifier = Modifier
|
colors = ButtonDefaults.buttonColors(
|
||||||
.heightIn(min = Density.BUTTON_MIN_HEIGHT)
|
containerColor = containerColor,
|
||||||
|
contentColor = contentColor,
|
||||||
|
disabledContainerColor = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.38f),
|
||||||
|
disabledContentColor = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.38f),
|
||||||
|
),
|
||||||
|
modifier = modifier
|
||||||
|
.heightIn(min = Density.CONTROL_HEIGHT)
|
||||||
.then(
|
.then(
|
||||||
if (hovered && enabled && hoverGradient.size >= 2) {
|
if (backgroundGradient.size >= 2) {
|
||||||
Modifier.background(
|
Modifier.background(
|
||||||
brush = Brush.verticalGradient(hoverGradient),
|
brush = Brush.verticalGradient(backgroundGradient),
|
||||||
shape = Density.BUTTON_SHAPE,
|
shape = Density.BUTTON_SHAPE,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
@@ -499,7 +618,11 @@ object Form {
|
|||||||
* bar instead of simply being too narrow, and that bar then pushes the rest
|
* bar instead of simply being too narrow, and that bar then pushes the rest
|
||||||
* of the window out of view.
|
* of the window out of view.
|
||||||
*/
|
*/
|
||||||
Text(text, style = MaterialTheme.typography.bodyMedium, maxLines = 1)
|
Text(
|
||||||
|
text,
|
||||||
|
style = compactControlTextStyle(),
|
||||||
|
maxLines = 1,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -538,6 +661,138 @@ object Form {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A content-sized toggle with the same typography, height and palette as the shared
|
||||||
|
* desktop buttons. Checkbox semantics keep keyboard and accessibility behaviour while
|
||||||
|
* avoiding the extra symbol and label width of a checkbox row.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
internal fun CompactToggleButton(
|
||||||
|
text: String,
|
||||||
|
checked: Boolean,
|
||||||
|
enabled: Boolean = true,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
onCheckedChange: (Boolean) -> Unit,
|
||||||
|
) {
|
||||||
|
val interactions = remember { MutableInteractionSource() }
|
||||||
|
val hovered by interactions.collectIsHoveredAsState()
|
||||||
|
val focused by interactions.collectIsFocusedAsState()
|
||||||
|
val pressed by interactions.collectIsPressedAsState()
|
||||||
|
val containerColor = when {
|
||||||
|
!enabled -> MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.38f)
|
||||||
|
pressed -> MaterialTheme.colorScheme.primaryContainer
|
||||||
|
hovered && checked -> MaterialTheme.colorScheme.primaryContainer
|
||||||
|
checked -> MaterialTheme.colorScheme.primary
|
||||||
|
hovered || focused -> MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.72f)
|
||||||
|
else -> MaterialTheme.colorScheme.surfaceVariant
|
||||||
|
}
|
||||||
|
|
||||||
|
val contentColor = when {
|
||||||
|
!enabled -> MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.38f)
|
||||||
|
(pressed || hovered) && checked -> MaterialTheme.colorScheme.onPrimaryContainer
|
||||||
|
checked -> MaterialTheme.colorScheme.onPrimary
|
||||||
|
else -> MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
}
|
||||||
|
val outlineColor = when {
|
||||||
|
focused || checked -> MaterialTheme.colorScheme.primary
|
||||||
|
enabled -> MaterialTheme.colorScheme.outline
|
||||||
|
else -> MaterialTheme.colorScheme.outline.copy(alpha = 0.38f)
|
||||||
|
}
|
||||||
|
|
||||||
|
Box(
|
||||||
|
modifier = modifier
|
||||||
|
.heightIn(min = Density.CONTROL_HEIGHT)
|
||||||
|
.background(containerColor, Density.BUTTON_SHAPE)
|
||||||
|
.border(
|
||||||
|
if (focused) Density.SELECTION_BORDER else Density.HAIRLINE,
|
||||||
|
outlineColor,
|
||||||
|
Density.BUTTON_SHAPE,
|
||||||
|
)
|
||||||
|
.toggleable(
|
||||||
|
value = checked,
|
||||||
|
enabled = enabled,
|
||||||
|
role = Role.Checkbox,
|
||||||
|
interactionSource = interactions,
|
||||||
|
indication = null,
|
||||||
|
onValueChange = onCheckedChange,
|
||||||
|
)
|
||||||
|
.padding(horizontal = 6.dp),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = text,
|
||||||
|
style = compactControlTextStyle(),
|
||||||
|
color = contentColor,
|
||||||
|
maxLines = 1,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A compact desktop tab with the same interaction palette as the shared controls.
|
||||||
|
* The selected surface visually continues into the content below it, while the border
|
||||||
|
* keeps inactive entries recognizable as tabs in both palettes.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
internal fun CompactTab(
|
||||||
|
text: String,
|
||||||
|
selected: Boolean,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
onClick: () -> Unit,
|
||||||
|
) {
|
||||||
|
val interactions = remember { MutableInteractionSource() }
|
||||||
|
val hovered by interactions.collectIsHoveredAsState()
|
||||||
|
val focused by interactions.collectIsFocusedAsState()
|
||||||
|
val pressed by interactions.collectIsPressedAsState()
|
||||||
|
val primary = MaterialTheme.colorScheme.primary
|
||||||
|
val background = when {
|
||||||
|
pressed -> MaterialTheme.colorScheme.primaryContainer
|
||||||
|
selected -> MaterialTheme.colorScheme.surface
|
||||||
|
hovered || focused -> MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.72f)
|
||||||
|
else -> MaterialTheme.colorScheme.surfaceVariant
|
||||||
|
}
|
||||||
|
val outline = when {
|
||||||
|
selected || focused -> primary
|
||||||
|
else -> MaterialTheme.colorScheme.outlineVariant
|
||||||
|
}
|
||||||
|
|
||||||
|
Box(
|
||||||
|
modifier = modifier
|
||||||
|
.heightIn(min = Density.TAB_MIN_HEIGHT)
|
||||||
|
.background(background)
|
||||||
|
.border(
|
||||||
|
if (focused) Density.SELECTION_BORDER else Density.HAIRLINE,
|
||||||
|
outline,
|
||||||
|
)
|
||||||
|
.selectable(
|
||||||
|
selected = selected,
|
||||||
|
interactionSource = interactions,
|
||||||
|
indication = null,
|
||||||
|
role = Role.Tab,
|
||||||
|
onClick = onClick,
|
||||||
|
)
|
||||||
|
.drawBehind {
|
||||||
|
if (selected) {
|
||||||
|
val thickness = 2.dp.toPx()
|
||||||
|
drawRect(
|
||||||
|
color = primary,
|
||||||
|
topLeft = Offset(0f, size.height - thickness),
|
||||||
|
size = Size(size.width, thickness),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(horizontal = Density.TAB_HORIZONTAL_PADDING, vertical = 3.dp),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text,
|
||||||
|
style = compactControlTextStyle(),
|
||||||
|
color = if (selected) primary else MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
maxLines = 1,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A text field at desktop density.
|
* A text field at desktop density.
|
||||||
*
|
*
|
||||||
@@ -563,6 +818,7 @@ internal fun CompactTextField(
|
|||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
enabled: Boolean = true,
|
enabled: Boolean = true,
|
||||||
isError: Boolean = false,
|
isError: Boolean = false,
|
||||||
|
placeholder: String = "",
|
||||||
visualTransformation: VisualTransformation = VisualTransformation.None,
|
visualTransformation: VisualTransformation = VisualTransformation.None,
|
||||||
borderColor: Color? = null,
|
borderColor: Color? = null,
|
||||||
borderThickness: Dp? = null,
|
borderThickness: Dp? = null,
|
||||||
@@ -596,11 +852,11 @@ internal fun CompactTextField(
|
|||||||
onValueChange = onValueChange,
|
onValueChange = onValueChange,
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
textStyle = MaterialTheme.typography.bodyMedium.copy(color = textColor),
|
textStyle = compactControlTextStyle().copy(color = textColor),
|
||||||
cursorBrush = SolidColor(MaterialTheme.colorScheme.primary),
|
cursorBrush = SolidColor(MaterialTheme.colorScheme.primary),
|
||||||
visualTransformation = visualTransformation,
|
visualTransformation = visualTransformation,
|
||||||
interactionSource = interactionSource,
|
interactionSource = interactionSource,
|
||||||
modifier = modifier.heightIn(min = Density.FIELD_MIN_HEIGHT),
|
modifier = modifier.heightIn(min = Density.CONTROL_HEIGHT),
|
||||||
) { innerTextField ->
|
) { innerTextField ->
|
||||||
OutlinedTextFieldDefaults.DecorationBox(
|
OutlinedTextFieldDefaults.DecorationBox(
|
||||||
value = value,
|
value = value,
|
||||||
@@ -612,6 +868,19 @@ internal fun CompactTextField(
|
|||||||
isError = isError,
|
isError = isError,
|
||||||
colors = colors,
|
colors = colors,
|
||||||
contentPadding = Density.FIELD_CONTENT_PADDING,
|
contentPadding = Density.FIELD_CONTENT_PADDING,
|
||||||
|
placeholder = if (placeholder.isNotEmpty()) {
|
||||||
|
{
|
||||||
|
Text(
|
||||||
|
placeholder,
|
||||||
|
style = compactControlTextStyle().copy(
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
maxLines = 1,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
},
|
||||||
container = {
|
container = {
|
||||||
OutlinedTextFieldDefaults.Container(
|
OutlinedTextFieldDefaults.Container(
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
@@ -628,16 +897,21 @@ internal fun CompactTextField(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A checkbox without the 48dp touch target Material reserves around it. On a desktop
|
* A checkbox on the shared compact control surface instead of Material's 48dp touch target.
|
||||||
* form that target is dead space between every two rows.
|
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
internal fun CompactCheckbox(checked: Boolean, onCheckedChange: (Boolean) -> Unit) {
|
internal fun CompactCheckbox(
|
||||||
CompositionLocalProvider(LocalMinimumInteractiveComponentSize provides Dp.Unspecified) {
|
checked: Boolean,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
enabled: Boolean = true,
|
||||||
|
onCheckedChange: (Boolean) -> Unit,
|
||||||
|
) {
|
||||||
|
CompositionLocalProvider(LocalMinimumInteractiveComponentSize provides 0.dp) {
|
||||||
Checkbox(
|
Checkbox(
|
||||||
checked = checked,
|
checked = checked,
|
||||||
|
enabled = enabled,
|
||||||
onCheckedChange = onCheckedChange,
|
onCheckedChange = onCheckedChange,
|
||||||
modifier = Modifier.size(Density.CHECK_SIZE),
|
modifier = modifier.size(Density.CONTROL_HEIGHT),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,14 +6,20 @@ import androidx.compose.foundation.hoverable
|
|||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
import androidx.compose.foundation.interaction.collectIsHoveredAsState
|
import androidx.compose.foundation.interaction.collectIsHoveredAsState
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.IntrinsicSize
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.heightIn
|
import androidx.compose.foundation.layout.heightIn
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.DropdownMenu
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material3.DropdownMenuItem
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
import androidx.compose.material3.HorizontalDivider
|
import androidx.compose.material3.HorizontalDivider
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.MenuDefaults
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
@@ -21,8 +27,16 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.unit.IntOffset
|
||||||
|
import androidx.compose.ui.unit.IntRect
|
||||||
|
import androidx.compose.ui.unit.IntSize
|
||||||
|
import androidx.compose.ui.unit.LayoutDirection
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.FrameWindowScope
|
import androidx.compose.ui.window.FrameWindowScope
|
||||||
import androidx.compose.ui.window.MenuBar
|
import androidx.compose.ui.window.MenuBar
|
||||||
|
import androidx.compose.ui.window.Popup
|
||||||
|
import androidx.compose.ui.window.PopupPositionProvider
|
||||||
|
import androidx.compose.ui.window.PopupProperties
|
||||||
import kst4contest.controller.On4KstConnectionState
|
import kst4contest.controller.On4KstConnectionState
|
||||||
import kst4contest.utils.PlatformUtils
|
import kst4contest.utils.PlatformUtils
|
||||||
import kst4contest.view.i18n.LocalStrings
|
import kst4contest.view.i18n.LocalStrings
|
||||||
@@ -41,6 +55,9 @@ interface MainMenuActions {
|
|||||||
fun setQrgAsNameInChat()
|
fun setQrgAsNameInChat()
|
||||||
fun toggleAwayState()
|
fun toggleAwayState()
|
||||||
fun toggleSettingsWindow()
|
fun toggleSettingsWindow()
|
||||||
|
|
||||||
|
/** Ends the session after asking and runs the setup wizard for the active profile. */
|
||||||
|
fun openSetupWizard()
|
||||||
fun toggleMonitorWindow()
|
fun toggleMonitorWindow()
|
||||||
fun toggleStationMap()
|
fun toggleStationMap()
|
||||||
fun useDarkDesign()
|
fun useDarkDesign()
|
||||||
@@ -163,7 +180,14 @@ private fun MenuTitle(menu: MenuSpec, rowState: MainMenuRowState) {
|
|||||||
val hovered by interactions.collectIsHoveredAsState()
|
val hovered by interactions.collectIsHoveredAsState()
|
||||||
val open = rowState.openMenu == menu.title
|
val open = rowState.openMenu == menu.title
|
||||||
|
|
||||||
Box {
|
/*
|
||||||
|
* Full bar height, so the popup anchored to this box starts at the bar's bottom edge
|
||||||
|
* rather than at the centred title text a few pixels above it.
|
||||||
|
*/
|
||||||
|
Box(
|
||||||
|
modifier = Modifier.heightIn(min = Density.TAB_MIN_HEIGHT),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = menu.title,
|
text = menu.title,
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
@@ -195,29 +219,90 @@ private fun MenuTitle(menu: MenuSpec, rowState: MainMenuRowState) {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
DropdownMenu(expanded = open, onDismissRequest = rowState::close) {
|
/*
|
||||||
menu.entries.forEach { entry ->
|
* A hand-rolled stand-in for Material3's DropdownMenu, because that one cannot open
|
||||||
when (entry) {
|
* flush under a menu bar — see MenuRowPopupPositionProvider. Same dismissal (outside
|
||||||
is MenuEntry.Item -> DropdownMenuItem(
|
* click and Escape come with a focusable popup), same MenuDefaults look; only the
|
||||||
text = {
|
* expand animation is gone, which a menu bar does not have anyway.
|
||||||
Text(entry.label, style = MaterialTheme.typography.bodyMedium)
|
*/
|
||||||
},
|
if (open) {
|
||||||
enabled = entry.enabled,
|
Popup(
|
||||||
onClick = { rowState.pick(entry.onClick) },
|
popupPositionProvider = MenuRowPopupPositionProvider,
|
||||||
)
|
onDismissRequest = rowState::close,
|
||||||
|
properties = PopupProperties(focusable = true),
|
||||||
|
) {
|
||||||
|
Surface(
|
||||||
|
shape = MenuDefaults.shape,
|
||||||
|
color = MenuDefaults.containerColor,
|
||||||
|
tonalElevation = MenuDefaults.TonalElevation,
|
||||||
|
shadowElevation = MenuDefaults.ShadowElevation,
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(vertical = MENU_POPUP_VERTICAL_PADDING)
|
||||||
|
.width(IntrinsicSize.Max)
|
||||||
|
.verticalScroll(rememberScrollState()),
|
||||||
|
) {
|
||||||
|
menu.entries.forEach { entry ->
|
||||||
|
when (entry) {
|
||||||
|
is MenuEntry.Item -> DropdownMenuItem(
|
||||||
|
text = {
|
||||||
|
Text(entry.label, style = MaterialTheme.typography.bodyMedium)
|
||||||
|
},
|
||||||
|
enabled = entry.enabled,
|
||||||
|
onClick = { rowState.pick(entry.onClick) },
|
||||||
|
)
|
||||||
|
|
||||||
MenuEntry.Separator ->
|
MenuEntry.Separator ->
|
||||||
HorizontalDivider(
|
HorizontalDivider(
|
||||||
thickness = Density.HAIRLINE,
|
thickness = Density.HAIRLINE,
|
||||||
color = palette.separatorLine,
|
color = palette.separatorLine,
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Places a menu-bar menu: flush under its anchor, leading edges aligned.
|
||||||
|
*
|
||||||
|
* Material3's DropdownMenu cannot be told to do this. Its position provider refuses any
|
||||||
|
* position closer than 48 dp (`MenuVerticalMargin`) to the window's top edge, and a menu
|
||||||
|
* bar sits exactly there, so every menu opened pushed down to that margin — a visible gap
|
||||||
|
* below the bar. The margin is applied after the `offset` parameter and the provider is
|
||||||
|
* not replaceable, hence this one and the hand-rolled popup in [MenuTitle].
|
||||||
|
*/
|
||||||
|
internal object MenuRowPopupPositionProvider : PopupPositionProvider {
|
||||||
|
override fun calculatePosition(
|
||||||
|
anchorBounds: IntRect,
|
||||||
|
windowSize: IntSize,
|
||||||
|
layoutDirection: LayoutDirection,
|
||||||
|
popupContentSize: IntSize,
|
||||||
|
): IntOffset {
|
||||||
|
val preferredX = when (layoutDirection) {
|
||||||
|
LayoutDirection.Ltr -> anchorBounds.left
|
||||||
|
LayoutDirection.Rtl -> anchorBounds.right - popupContentSize.width
|
||||||
|
}
|
||||||
|
val x = preferredX.coerceIn(0, maxOf(0, windowSize.width - popupContentSize.width))
|
||||||
|
val below = anchorBounds.bottom
|
||||||
|
val above = anchorBounds.top - popupContentSize.height
|
||||||
|
val y = when {
|
||||||
|
below + popupContentSize.height <= windowSize.height -> below
|
||||||
|
above >= 0 -> above
|
||||||
|
else -> maxOf(0, windowSize.height - popupContentSize.height)
|
||||||
|
}
|
||||||
|
return IntOffset(x, y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Enough tint to show the pointer is over a title, not enough to read as a selection. */
|
/** Enough tint to show the pointer is over a title, not enough to read as a selection. */
|
||||||
private const val HOVER_ALPHA = 0.35f
|
private const val HOVER_ALPHA = 0.35f
|
||||||
|
|
||||||
private val MENU_TITLE_VERTICAL_PADDING = androidx.compose.ui.unit.Dp(4f)
|
private val MENU_TITLE_VERTICAL_PADDING = androidx.compose.ui.unit.Dp(4f)
|
||||||
|
|
||||||
|
/** Material3's DropdownMenuVerticalPadding, which is internal; keep the menus looking alike. */
|
||||||
|
private val MENU_POPUP_VERTICAL_PADDING = 8.dp
|
||||||
@@ -87,6 +87,11 @@ fun mainMenuModel(
|
|||||||
enabled = true,
|
enabled = true,
|
||||||
actions::toggleSettingsWindow,
|
actions::toggleSettingsWindow,
|
||||||
),
|
),
|
||||||
|
/*
|
||||||
|
* Always usable, like the profile switch: it rebuilds the runtime and asks before
|
||||||
|
* it gives the session up.
|
||||||
|
*/
|
||||||
|
MenuEntry.Item(strings.menuSetupWizard, state.canSwitchProfile, actions::openSetupWizard),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
MenuSpec(
|
MenuSpec(
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.FrameWindowScope
|
import androidx.compose.ui.window.FrameWindowScope
|
||||||
import kst4contest.model.Band
|
|
||||||
import kst4contest.model.ChatMember
|
import kst4contest.model.ChatMember
|
||||||
import kst4contest.model.ChatMessage
|
import kst4contest.model.ChatMessage
|
||||||
import kst4contest.utils.PlatformUtils
|
import kst4contest.utils.PlatformUtils
|
||||||
@@ -31,7 +31,6 @@ import java.util.function.Consumer
|
|||||||
fun FrameWindowScope.MainWindow(
|
fun FrameWindowScope.MainWindow(
|
||||||
state: MainWindowState,
|
state: MainWindowState,
|
||||||
actions: MainMenuActions,
|
actions: MainMenuActions,
|
||||||
skedBands: List<Band>,
|
|
||||||
openInBrowser: Consumer<String>,
|
openInBrowser: Consumer<String>,
|
||||||
onShowOnMap: () -> Unit,
|
onShowOnMap: () -> Unit,
|
||||||
onShowPathInAirScout: () -> Unit,
|
onShowPathInAirScout: () -> Unit,
|
||||||
@@ -42,6 +41,7 @@ fun FrameWindowScope.MainWindow(
|
|||||||
* message aims at whoever it was addressed to rather than at oneself.
|
* message aims at whoever it was addressed to rather than at oneself.
|
||||||
*/
|
*/
|
||||||
onDirectedMessageClicked: (ChatMessage) -> Unit,
|
onDirectedMessageClicked: (ChatMessage) -> Unit,
|
||||||
|
onMessageStationClicked: (ChatMessage, StationSelectionSource) -> Unit,
|
||||||
/** Whether a message came from this station; decides its row colour. */
|
/** Whether a message came from this station; decides its row colour. */
|
||||||
isOwnMessage: (ChatMessage) -> Boolean,
|
isOwnMessage: (ChatMessage) -> Boolean,
|
||||||
/** How old a message is, for the fading highlight. */
|
/** How old a message is, for the fading highlight. */
|
||||||
@@ -133,6 +133,7 @@ fun FrameWindowScope.MainWindow(
|
|||||||
state = state,
|
state = state,
|
||||||
onCandidateClicked = onCandidateClicked,
|
onCandidateClicked = onCandidateClicked,
|
||||||
onDirectedMessageClicked = onDirectedMessageClicked,
|
onDirectedMessageClicked = onDirectedMessageClicked,
|
||||||
|
onMessageStationClicked = onMessageStationClicked,
|
||||||
isOwnMessage = isOwnMessage,
|
isOwnMessage = isOwnMessage,
|
||||||
messageAgeSeconds = messageAgeSeconds,
|
messageAgeSeconds = messageAgeSeconds,
|
||||||
)
|
)
|
||||||
@@ -140,7 +141,6 @@ fun FrameWindowScope.MainWindow(
|
|||||||
{
|
{
|
||||||
StationColumn(
|
StationColumn(
|
||||||
state = state,
|
state = state,
|
||||||
skedBands = skedBands,
|
|
||||||
openInBrowser = openInBrowser,
|
openInBrowser = openInBrowser,
|
||||||
onShowOnMap = onShowOnMap,
|
onShowOnMap = onShowOnMap,
|
||||||
onShowPathInAirScout = onShowPathInAirScout,
|
onShowPathInAirScout = onShowPathInAirScout,
|
||||||
@@ -167,6 +167,7 @@ private fun MessageColumn(
|
|||||||
state: MainWindowState,
|
state: MainWindowState,
|
||||||
onCandidateClicked: (TimelineCandidate) -> Unit,
|
onCandidateClicked: (TimelineCandidate) -> Unit,
|
||||||
onDirectedMessageClicked: (ChatMessage) -> Unit,
|
onDirectedMessageClicked: (ChatMessage) -> Unit,
|
||||||
|
onMessageStationClicked: (ChatMessage, StationSelectionSource) -> Unit,
|
||||||
isOwnMessage: (ChatMessage) -> Boolean,
|
isOwnMessage: (ChatMessage) -> Boolean,
|
||||||
messageAgeSeconds: (ChatMessage) -> Long,
|
messageAgeSeconds: (ChatMessage) -> Long,
|
||||||
) {
|
) {
|
||||||
@@ -174,6 +175,13 @@ private fun MessageColumn(
|
|||||||
state = state.messageSplitter,
|
state = state.messageSplitter,
|
||||||
orientation = SplitterOrientation.VERTICAL,
|
orientation = SplitterOrientation.VERTICAL,
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
minimumPaneSizes = listOf(
|
||||||
|
SplitterState.DEFAULT_MIN_PANE_PX.dp,
|
||||||
|
Density.CONTROL_HEIGHT,
|
||||||
|
TimelineGeometry.HEIGHT.dp,
|
||||||
|
Density.CONTROL_HEIGHT,
|
||||||
|
SplitterState.DEFAULT_MIN_PANE_PX.dp,
|
||||||
|
),
|
||||||
panes = listOf(
|
panes = listOf(
|
||||||
{
|
{
|
||||||
SnippetContextMenu(state.snippets.entries, state.chatInput) {
|
SnippetContextMenu(state.snippets.entries, state.chatInput) {
|
||||||
@@ -216,6 +224,7 @@ private fun MessageColumn(
|
|||||||
publicMessages = state.publicMessages,
|
publicMessages = state.publicMessages,
|
||||||
clusterMessages = state.clusterMessages,
|
clusterMessages = state.clusterMessages,
|
||||||
qsoOfTheOther = state.qsoOfTheOther,
|
qsoOfTheOther = state.qsoOfTheOther,
|
||||||
|
onStationMessageClicked = onMessageStationClicked,
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -230,7 +239,6 @@ private fun MessageColumn(
|
|||||||
@Composable
|
@Composable
|
||||||
private fun StationColumn(
|
private fun StationColumn(
|
||||||
state: MainWindowState,
|
state: MainWindowState,
|
||||||
skedBands: List<Band>,
|
|
||||||
openInBrowser: Consumer<String>,
|
openInBrowser: Consumer<String>,
|
||||||
onShowOnMap: () -> Unit,
|
onShowOnMap: () -> Unit,
|
||||||
onShowPathInAirScout: () -> Unit,
|
onShowPathInAirScout: () -> Unit,
|
||||||
@@ -238,6 +246,10 @@ private fun StationColumn(
|
|||||||
onFiltersChanged: () -> Unit,
|
onFiltersChanged: () -> Unit,
|
||||||
onShowMorePriorities: () -> Unit,
|
onShowMorePriorities: () -> Unit,
|
||||||
) {
|
) {
|
||||||
|
val stationContextMenu = remember(state) {
|
||||||
|
StationContextMenuState(state::selectStation)
|
||||||
|
}
|
||||||
|
|
||||||
SplitterPane(
|
SplitterPane(
|
||||||
state = state.rightSplitter,
|
state = state.rightSplitter,
|
||||||
orientation = SplitterOrientation.VERTICAL,
|
orientation = SplitterOrientation.VERTICAL,
|
||||||
@@ -248,24 +260,37 @@ private fun StationColumn(
|
|||||||
StationFilterBar(
|
StationFilterBar(
|
||||||
filters = state.stationFilter,
|
filters = state.stationFilter,
|
||||||
activeBands = state.activeBands,
|
activeBands = state.activeBands,
|
||||||
|
reachability = state.reachability,
|
||||||
onChanged = {
|
onChanged = {
|
||||||
onFiltersChanged()
|
onFiltersChanged()
|
||||||
},
|
},
|
||||||
|
onQtfDirectionChanged = state::applyExplicitQtfFilterDirection,
|
||||||
|
onReset = state::resetStationFilters,
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
)
|
)
|
||||||
HorizontalDivider(thickness = Density.HAIRLINE)
|
HorizontalDivider(thickness = Density.HAIRLINE)
|
||||||
SnippetContextMenu(state.snippets.entries, state.chatInput) {
|
DataTableView(
|
||||||
DataTableView(
|
state = state.stations,
|
||||||
state = state.stations,
|
modifier = Modifier.fillMaxSize(),
|
||||||
modifier = Modifier.fillMaxSize(),
|
emphasizeCell = { member, column ->
|
||||||
onRowClick = onStationSelected,
|
column.id == "callsign" && state.newJoined.isRecent(member)
|
||||||
)
|
},
|
||||||
}
|
onRowClick = onStationSelected,
|
||||||
|
onRowContextMenu = { member, position ->
|
||||||
|
stationContextMenu.open(
|
||||||
|
listOf(member),
|
||||||
|
StationSelectionSource.STATION_CONTEXT_MENU,
|
||||||
|
position,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
selectOnRowClick = false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
TopPriorityBar(
|
TopPriorityBar(
|
||||||
state = state.topPriority,
|
state = state.topPriority,
|
||||||
|
newJoined = state.newJoined,
|
||||||
onShowMore = onShowMorePriorities,
|
onShowMore = onShowMorePriorities,
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
)
|
)
|
||||||
@@ -274,8 +299,8 @@ private fun StationColumn(
|
|||||||
SelectedStationPanel(
|
SelectedStationPanel(
|
||||||
state = state.selectedStation,
|
state = state.selectedStation,
|
||||||
messages = state.selectedStationMessages,
|
messages = state.selectedStationMessages,
|
||||||
skedBands = skedBands,
|
|
||||||
activeBands = state.activeBands,
|
activeBands = state.activeBands,
|
||||||
|
contentSplitter = state.selectedStationSplitter,
|
||||||
openInBrowser = openInBrowser,
|
openInBrowser = openInBrowser,
|
||||||
onShowOnMap = onShowOnMap,
|
onShowOnMap = onShowOnMap,
|
||||||
onShowPathInAirScout = onShowPathInAirScout,
|
onShowPathInAirScout = onShowPathInAirScout,
|
||||||
@@ -284,4 +309,5 @@ private fun StationColumn(
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
StationContextOverlays(stationContextMenu, state, onShowOnMap)
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package kst4contest.view.compose
|
package kst4contest.view.compose
|
||||||
|
|
||||||
import kst4contest.model.Band
|
|
||||||
import kst4contest.model.ChatMember
|
import kst4contest.model.ChatMember
|
||||||
import kst4contest.model.ChatMessage
|
import kst4contest.model.ChatMessage
|
||||||
import java.util.function.Consumer
|
import java.util.function.Consumer
|
||||||
@@ -34,12 +33,12 @@ object MainWindowHost {
|
|||||||
*/
|
*/
|
||||||
private var currentState by androidx.compose.runtime.mutableStateOf<MainWindowState?>(null)
|
private var currentState by androidx.compose.runtime.mutableStateOf<MainWindowState?>(null)
|
||||||
private var currentActions by androidx.compose.runtime.mutableStateOf<MainMenuActions?>(null)
|
private var currentActions by androidx.compose.runtime.mutableStateOf<MainMenuActions?>(null)
|
||||||
private var currentSkedBands by androidx.compose.runtime.mutableStateOf<(() -> List<Band>)?>(null)
|
|
||||||
private var currentOpenInBrowser by androidx.compose.runtime.mutableStateOf<Consumer<String>?>(null)
|
private var currentOpenInBrowser by androidx.compose.runtime.mutableStateOf<Consumer<String>?>(null)
|
||||||
private var currentOnShowOnMap by androidx.compose.runtime.mutableStateOf<(() -> Unit)?>(null)
|
private var currentOnShowOnMap by androidx.compose.runtime.mutableStateOf<(() -> Unit)?>(null)
|
||||||
private var currentOnShowPathInAirScout by androidx.compose.runtime.mutableStateOf<(() -> Unit)?>(null)
|
private var currentOnShowPathInAirScout by androidx.compose.runtime.mutableStateOf<(() -> Unit)?>(null)
|
||||||
private var currentOnStationSelected by androidx.compose.runtime.mutableStateOf<((ChatMember) -> Unit)?>(null)
|
private var currentOnStationSelected by androidx.compose.runtime.mutableStateOf<((ChatMember) -> Unit)?>(null)
|
||||||
private var currentOnDirectedMessageClicked by androidx.compose.runtime.mutableStateOf<((ChatMessage) -> Unit)?>(null)
|
private var currentOnDirectedMessageClicked by androidx.compose.runtime.mutableStateOf<((ChatMessage) -> Unit)?>(null)
|
||||||
|
private var currentOnMessageStationClicked by androidx.compose.runtime.mutableStateOf<((ChatMessage, StationSelectionSource) -> Unit)?>(null)
|
||||||
private var currentIsOwnMessage by androidx.compose.runtime.mutableStateOf<((ChatMessage) -> Boolean)?>(null)
|
private var currentIsOwnMessage by androidx.compose.runtime.mutableStateOf<((ChatMessage) -> Boolean)?>(null)
|
||||||
private var currentMessageAgeSeconds by androidx.compose.runtime.mutableStateOf<((ChatMessage) -> Long)?>(null)
|
private var currentMessageAgeSeconds by androidx.compose.runtime.mutableStateOf<((ChatMessage) -> Long)?>(null)
|
||||||
private var currentOnFiltersChanged by androidx.compose.runtime.mutableStateOf<(() -> Unit)?>(null)
|
private var currentOnFiltersChanged by androidx.compose.runtime.mutableStateOf<(() -> Unit)?>(null)
|
||||||
@@ -79,12 +78,12 @@ object MainWindowHost {
|
|||||||
* leave the client running with the chat connected and nothing to see it in.
|
* leave the client running with the chat connected and nothing to see it in.
|
||||||
*/
|
*/
|
||||||
onCloseRequest: () -> Unit,
|
onCloseRequest: () -> Unit,
|
||||||
skedBands: () -> List<Band>,
|
|
||||||
openInBrowser: Consumer<String>,
|
openInBrowser: Consumer<String>,
|
||||||
onShowOnMap: () -> Unit,
|
onShowOnMap: () -> Unit,
|
||||||
onShowPathInAirScout: () -> Unit,
|
onShowPathInAirScout: () -> Unit,
|
||||||
onStationSelected: (ChatMember) -> Unit,
|
onStationSelected: (ChatMember) -> Unit,
|
||||||
onDirectedMessageClicked: (ChatMessage) -> Unit,
|
onDirectedMessageClicked: (ChatMessage) -> Unit,
|
||||||
|
onMessageStationClicked: (ChatMessage, StationSelectionSource) -> Unit,
|
||||||
isOwnMessage: (ChatMessage) -> Boolean,
|
isOwnMessage: (ChatMessage) -> Boolean,
|
||||||
messageAgeSeconds: (ChatMessage) -> Long,
|
messageAgeSeconds: (ChatMessage) -> Long,
|
||||||
onFiltersChanged: () -> Unit,
|
onFiltersChanged: () -> Unit,
|
||||||
@@ -93,12 +92,12 @@ object MainWindowHost {
|
|||||||
) {
|
) {
|
||||||
currentState = state
|
currentState = state
|
||||||
currentActions = actions
|
currentActions = actions
|
||||||
currentSkedBands = skedBands
|
|
||||||
currentOpenInBrowser = openInBrowser
|
currentOpenInBrowser = openInBrowser
|
||||||
currentOnShowOnMap = onShowOnMap
|
currentOnShowOnMap = onShowOnMap
|
||||||
currentOnShowPathInAirScout = onShowPathInAirScout
|
currentOnShowPathInAirScout = onShowPathInAirScout
|
||||||
currentOnStationSelected = onStationSelected
|
currentOnStationSelected = onStationSelected
|
||||||
currentOnDirectedMessageClicked = onDirectedMessageClicked
|
currentOnDirectedMessageClicked = onDirectedMessageClicked
|
||||||
|
currentOnMessageStationClicked = onMessageStationClicked
|
||||||
currentIsOwnMessage = isOwnMessage
|
currentIsOwnMessage = isOwnMessage
|
||||||
currentMessageAgeSeconds = messageAgeSeconds
|
currentMessageAgeSeconds = messageAgeSeconds
|
||||||
currentOnFiltersChanged = onFiltersChanged
|
currentOnFiltersChanged = onFiltersChanged
|
||||||
@@ -151,12 +150,12 @@ object MainWindowHost {
|
|||||||
MainWindow(
|
MainWindow(
|
||||||
state = s,
|
state = s,
|
||||||
actions = a,
|
actions = a,
|
||||||
skedBands = currentSkedBands?.invoke() ?: emptyList(),
|
|
||||||
openInBrowser = currentOpenInBrowser ?: Consumer { _ -> },
|
openInBrowser = currentOpenInBrowser ?: Consumer { _ -> },
|
||||||
onShowOnMap = currentOnShowOnMap ?: {},
|
onShowOnMap = currentOnShowOnMap ?: {},
|
||||||
onShowPathInAirScout = currentOnShowPathInAirScout ?: {},
|
onShowPathInAirScout = currentOnShowPathInAirScout ?: {},
|
||||||
onStationSelected = currentOnStationSelected ?: {},
|
onStationSelected = currentOnStationSelected ?: {},
|
||||||
onDirectedMessageClicked = currentOnDirectedMessageClicked ?: {},
|
onDirectedMessageClicked = currentOnDirectedMessageClicked ?: {},
|
||||||
|
onMessageStationClicked = currentOnMessageStationClicked ?: { _, _ -> },
|
||||||
isOwnMessage = currentIsOwnMessage ?: { false },
|
isOwnMessage = currentIsOwnMessage ?: { false },
|
||||||
messageAgeSeconds = currentMessageAgeSeconds ?: { 0L },
|
messageAgeSeconds = currentMessageAgeSeconds ?: { 0L },
|
||||||
onFiltersChanged = currentOnFiltersChanged ?: {},
|
onFiltersChanged = currentOnFiltersChanged ?: {},
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import androidx.compose.runtime.setValue
|
|||||||
import kst4contest.controller.On4KstConnectionState
|
import kst4contest.controller.On4KstConnectionState
|
||||||
import kst4contest.model.ChatPreferences
|
import kst4contest.model.ChatPreferences
|
||||||
import kst4contest.observe.SimpleRoster
|
import kst4contest.observe.SimpleRoster
|
||||||
|
import kst4contest.view.compose.map.MapDisplaySettingsState
|
||||||
|
import kst4contest.view.compose.map.MapNavigationState
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Everything the main window draws, in one object.
|
* Everything the main window draws, in one object.
|
||||||
@@ -55,19 +57,87 @@ class MainWindowState(
|
|||||||
val bandUpgradeNotice: BlinkingNotice,
|
val bandUpgradeNotice: BlinkingNotice,
|
||||||
val threadButtons: ThreadStatusButtons,
|
val threadButtons: ThreadStatusButtons,
|
||||||
|
|
||||||
/** The three splitters, whose positions the operator has arranged and stored. */
|
/** The splitters whose positions the operator has arranged and stored. */
|
||||||
val outerSplitter: SplitterState,
|
val outerSplitter: SplitterState,
|
||||||
val messageSplitter: SplitterState,
|
val messageSplitter: SplitterState,
|
||||||
val rightSplitter: SplitterState,
|
val rightSplitter: SplitterState,
|
||||||
|
val selectedStationSplitter: SplitterState = SplitterState(
|
||||||
|
SELECTED_STATION_PANE_COUNT,
|
||||||
|
doubleArrayOf(0.55),
|
||||||
|
) {},
|
||||||
|
val newJoined: NewJoinedState = NewJoinedState(onSelect = {}),
|
||||||
|
val reachability: ReachabilityState = ReachabilityState(activeBands),
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
internal val mapNavigation = MapNavigationState()
|
||||||
|
|
||||||
|
internal val mapDisplaySettings = MapDisplaySettingsState(prefs)
|
||||||
|
|
||||||
|
init {
|
||||||
|
stationSelection.explicitSelectionListener = { member, source ->
|
||||||
|
when {
|
||||||
|
source == StationSelectionSource.RESET_VIEW -> mapNavigation.resetToHome()
|
||||||
|
member != null -> StationIdentity.of(member)?.let(mapNavigation::fitSelectedPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Explicit map analysis requested from either station context menu. */
|
||||||
|
val mapReachability = MapReachabilityState(prefs.stn_loginLocatorMainCat.orEmpty())
|
||||||
|
|
||||||
/** The shortcut buttons above the send line. */
|
/** The shortcut buttons above the send line. */
|
||||||
/**
|
/**
|
||||||
* The one path that selects a station for the whole application (panel, table, score
|
* The one path that selects a station for the whole application (panel, table, score
|
||||||
* service, send line). Set by the host after construction; other windows, such as the
|
* service, send line). Set by the host after construction; other windows, such as the
|
||||||
* map, go through it instead of touching [selectedStation] alone. Null clears.
|
* map, go through it instead of touching [selectedStation] alone. Null clears.
|
||||||
*/
|
*/
|
||||||
var stationSelector: ((ChatMember?) -> Unit)? = null
|
var stationSelector: ((ChatMember?, StationSelectionSource) -> Unit)? = null
|
||||||
|
|
||||||
|
/** Application callback that rebuilds the controller and Compose station filters. */
|
||||||
|
var stationFiltersChanged: (() -> Unit)? = null
|
||||||
|
|
||||||
|
/** Debounced persistence hook shared by the main and map windows. */
|
||||||
|
var layoutSaveRequested: (() -> Unit)? = null
|
||||||
|
|
||||||
|
/** Contactinfo-equivalent manual Worked action supplied by the controller host. */
|
||||||
|
var markStationWorked: ((ChatMember, kst4contest.model.Band) -> Boolean)? = null
|
||||||
|
|
||||||
|
/** Persistent any-band Worked gross fields used by the optional map overlay. */
|
||||||
|
var workedGrossFieldsProvider: (() -> Set<String>) = { emptySet() }
|
||||||
|
|
||||||
|
val stationSelection: StationSelectionState
|
||||||
|
get() = selectedStation.stationSelection
|
||||||
|
|
||||||
|
/** Routes every explicit station choice through the application-level action. */
|
||||||
|
fun selectStation(member: ChatMember?, source: StationSelectionSource) {
|
||||||
|
mapReachability.selectionChanged(StationIdentity.of(member))
|
||||||
|
val selector = stationSelector
|
||||||
|
if (selector != null) {
|
||||||
|
selector(member, source)
|
||||||
|
} else {
|
||||||
|
selectedStation.select(member, source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun resetStationFilters() {
|
||||||
|
stationFilter.reset()
|
||||||
|
stationFiltersChanged?.invoke()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Applies only a deliberate QTF filter entry, never a restored or reset filter value. */
|
||||||
|
fun applyExplicitQtfFilterDirection(qtf: Double) {
|
||||||
|
mapNavigation.centerOnQtf(qtf)
|
||||||
|
applyExplicitQtfHeading(prefs, qtf)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Refreshes map geometry after the Station settings draft has been applied. */
|
||||||
|
fun refreshMapDisplaySettings() {
|
||||||
|
mapDisplaySettings.refreshFromPreferences()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun requestLayoutSave() {
|
||||||
|
layoutSaveRequested?.invoke()
|
||||||
|
}
|
||||||
|
|
||||||
val shortcuts = RosterMirror(prefs.getLst_txtShortCutBtnList())
|
val shortcuts = RosterMirror(prefs.getLst_txtShortCutBtnList())
|
||||||
|
|
||||||
@@ -103,6 +173,9 @@ class MainWindowState(
|
|||||||
|
|
||||||
/** Station list, top priorities, selected station. */
|
/** Station list, top priorities, selected station. */
|
||||||
const val RIGHT_PANE_COUNT = 3
|
const val RIGHT_PANE_COUNT = 3
|
||||||
|
|
||||||
|
/** Selected-station message table and its scrollable action area. */
|
||||||
|
const val SELECTED_STATION_PANE_COUNT = 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import kst4contest.model.ChatPreferences
|
||||||
|
|
||||||
|
private const val MIN_QTF = 0.0
|
||||||
|
private const val MAX_QTF = 360.0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies a deliberate filter direction to the runtime antenna heading without sending a rotor command.
|
||||||
|
*
|
||||||
|
* @return true when the runtime heading was updated
|
||||||
|
*/
|
||||||
|
internal fun applyExplicitQtfHeading(prefs: ChatPreferences, qtf: Double): Boolean {
|
||||||
|
if (!qtf.isFinite() || qtf !in MIN_QTF..MAX_QTF) return false
|
||||||
|
if (!prefs.isQtfFilterDirectionAsAntennaHeadingEnabled) return false
|
||||||
|
|
||||||
|
prefs.actualQTF.set(qtf)
|
||||||
|
return true
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import kst4contest.model.Band
|
||||||
|
import kst4contest.model.ChatMember
|
||||||
|
import kst4contest.view.map.PathAnalysisResult
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Explicit map reachability request shared by station-list and map context menus.
|
||||||
|
* A monotonically increasing request ID prevents older callbacks from replacing a
|
||||||
|
* result for a newer station or band.
|
||||||
|
*/
|
||||||
|
class MapReachabilityState(
|
||||||
|
private val ownLocator: String,
|
||||||
|
requester: (ChatMember, Band, (PathAnalysisResult) -> Unit) -> Unit = { _, _, _ -> },
|
||||||
|
) {
|
||||||
|
var requester: (ChatMember, Band, (PathAnalysisResult) -> Unit) -> Unit = requester
|
||||||
|
|
||||||
|
var result: PathAnalysisResult? by mutableStateOf(null)
|
||||||
|
private set
|
||||||
|
|
||||||
|
var running: Boolean by mutableStateOf(false)
|
||||||
|
private set
|
||||||
|
|
||||||
|
var requestRevision: Long by mutableStateOf(0L)
|
||||||
|
private set
|
||||||
|
|
||||||
|
var targetIdentity: StationIdentity? by mutableStateOf(null)
|
||||||
|
private set
|
||||||
|
|
||||||
|
var requestedBand: Band? by mutableStateOf(null)
|
||||||
|
private set
|
||||||
|
|
||||||
|
fun calculate(member: ChatMember?, band: Band?): Boolean {
|
||||||
|
if (member == null || band == null) return false
|
||||||
|
val identity = StationIdentity.of(member) ?: return false
|
||||||
|
val requestId = ++requestRevision
|
||||||
|
targetIdentity = identity
|
||||||
|
requestedBand = band
|
||||||
|
running = true
|
||||||
|
result = PathAnalysisResult.loading(ownLocator, member.qra, member.callSignRaw)
|
||||||
|
|
||||||
|
try {
|
||||||
|
requester(member, band) { completed ->
|
||||||
|
if (requestRevision == requestId
|
||||||
|
&& targetIdentity == identity
|
||||||
|
&& requestedBand == band
|
||||||
|
) {
|
||||||
|
result = completed
|
||||||
|
running = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (exception: RuntimeException) {
|
||||||
|
if (requestRevision == requestId) {
|
||||||
|
result = PathAnalysisResult.noProfile(
|
||||||
|
"Failed",
|
||||||
|
ownLocator,
|
||||||
|
member.qra,
|
||||||
|
member.callSignRaw,
|
||||||
|
Double.NaN,
|
||||||
|
member.getQTFdirection() ?: Double.NaN,
|
||||||
|
Double.NaN,
|
||||||
|
Double.NaN,
|
||||||
|
band.defaultAnalysisFrequencyMHz,
|
||||||
|
exception.message ?: "Reachability calculation failed.",
|
||||||
|
)
|
||||||
|
running = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun selectionChanged(identity: StationIdentity?) {
|
||||||
|
if (targetIdentity == null || targetIdentity == identity) return
|
||||||
|
requestRevision++
|
||||||
|
targetIdentity = null
|
||||||
|
requestedBand = null
|
||||||
|
result = null
|
||||||
|
running = false
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,13 +2,11 @@ package kst4contest.view.compose
|
|||||||
|
|
||||||
import kst4contest.view.i18n.LocalStrings
|
import kst4contest.view.i18n.LocalStrings
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.heightIn
|
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.HorizontalDivider
|
import androidx.compose.material3.HorizontalDivider
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
@@ -18,13 +16,8 @@ import androidx.compose.runtime.getValue
|
|||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.drawBehind
|
import androidx.compose.foundation.border
|
||||||
import androidx.compose.ui.geometry.Offset
|
|
||||||
import androidx.compose.ui.geometry.Size
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import kst4contest.model.ChatMessage
|
import kst4contest.model.ChatMessage
|
||||||
import kst4contest.model.ClusterMessage
|
import kst4contest.model.ClusterMessage
|
||||||
|
|
||||||
@@ -40,6 +33,7 @@ fun MessageTabs(
|
|||||||
publicMessages: DataTableState<ChatMessage>,
|
publicMessages: DataTableState<ChatMessage>,
|
||||||
clusterMessages: DataTableState<ClusterMessage>,
|
clusterMessages: DataTableState<ClusterMessage>,
|
||||||
qsoOfTheOther: DataTableState<ChatMessage>,
|
qsoOfTheOther: DataTableState<ChatMessage>,
|
||||||
|
onStationMessageClicked: (ChatMessage, StationSelectionSource) -> Unit = { _, _ -> },
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
var selected by remember { mutableStateOf(0) }
|
var selected by remember { mutableStateOf(0) }
|
||||||
@@ -51,35 +45,20 @@ fun MessageTabs(
|
|||||||
strings.messagesQsoOfTheOther,
|
strings.messagesQsoOfTheOther,
|
||||||
)
|
)
|
||||||
|
|
||||||
Column(modifier = modifier.fillMaxSize()) {
|
Column(
|
||||||
|
modifier = modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.border(Density.HAIRLINE, MaterialTheme.colorScheme.outlineVariant),
|
||||||
|
) {
|
||||||
Row(modifier = Modifier.fillMaxWidth().background(MaterialTheme.colorScheme.surfaceVariant)) {
|
Row(modifier = Modifier.fillMaxWidth().background(MaterialTheme.colorScheme.surfaceVariant)) {
|
||||||
titles.forEachIndexed { index, title ->
|
titles.forEachIndexed { index, title ->
|
||||||
val isSelected = index == selected
|
val isSelected = index == selected
|
||||||
val underline = MaterialTheme.colorScheme.primary
|
|
||||||
|
|
||||||
Box(
|
CompactTab(
|
||||||
modifier = Modifier
|
text = title,
|
||||||
.heightIn(min = Density.TAB_MIN_HEIGHT)
|
selected = isSelected,
|
||||||
.background(
|
onClick = { selected = index },
|
||||||
if (isSelected) MaterialTheme.colorScheme.secondaryContainer
|
)
|
||||||
else Color.Transparent
|
|
||||||
)
|
|
||||||
.clickable { selected = index }
|
|
||||||
.drawBehind {
|
|
||||||
if (isSelected) {
|
|
||||||
val thickness = 2.dp.toPx()
|
|
||||||
drawRect(
|
|
||||||
color = underline,
|
|
||||||
topLeft = Offset(0f, size.height - thickness),
|
|
||||||
size = Size(size.width, thickness),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding(horizontal = Density.TAB_HORIZONTAL_PADDING, vertical = 5.dp),
|
|
||||||
contentAlignment = Alignment.Center,
|
|
||||||
) {
|
|
||||||
Text(title, style = MaterialTheme.typography.bodyMedium, maxLines = 1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,9 +66,21 @@ fun MessageTabs(
|
|||||||
|
|
||||||
Box(modifier = Modifier.fillMaxSize()) {
|
Box(modifier = Modifier.fillMaxSize()) {
|
||||||
when (selected) {
|
when (selected) {
|
||||||
0 -> DataTableView(publicMessages, modifier = Modifier.fillMaxSize())
|
0 -> DataTableView(
|
||||||
|
publicMessages,
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
onRowClick = { message ->
|
||||||
|
onStationMessageClicked(message, StationSelectionSource.PUBLIC_MESSAGE)
|
||||||
|
},
|
||||||
|
)
|
||||||
1 -> DataTableView(clusterMessages, modifier = Modifier.fillMaxSize())
|
1 -> DataTableView(clusterMessages, modifier = Modifier.fillMaxSize())
|
||||||
else -> DataTableView(qsoOfTheOther, modifier = Modifier.fillMaxSize())
|
else -> DataTableView(
|
||||||
|
qsoOfTheOther,
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
onRowClick = { message ->
|
||||||
|
onStationMessageClicked(message, StationSelectionSource.QSO_OF_THE_OTHER)
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import androidx.compose.foundation.layout.Column
|
|||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.HorizontalDivider
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
@@ -17,10 +16,11 @@ import kst4contest.model.ClusterMessage
|
|||||||
/**
|
/**
|
||||||
* The cluster and QSO monitor.
|
* The cluster and QSO monitor.
|
||||||
*
|
*
|
||||||
* Two live tables, one above the other. This is the first window in which the table
|
* Two live tables, one above the other, with a divider the operator can drag. This
|
||||||
* carries data that changes while the operator watches, which is why the row identity
|
* is the first window in which the table carries data that changes while the operator
|
||||||
* rules in DataTableState matter here and not in the settings window: in Etappe 2 the
|
* watches, which is why the row identity rules in DataTableState matter here and not in
|
||||||
* visible defects all came from that coupling, not from the table itself.
|
* the settings window: in Etappe 2 the visible defects all came from that coupling, not
|
||||||
|
* from the table itself.
|
||||||
*/
|
*/
|
||||||
object MonitorWindow {
|
object MonitorWindow {
|
||||||
|
|
||||||
@@ -44,6 +44,8 @@ object MonitorWindow {
|
|||||||
fun show(
|
fun show(
|
||||||
clusterTable: DataTableState<ClusterMessage>,
|
clusterTable: DataTableState<ClusterMessage>,
|
||||||
qsoTable: DataTableState<ChatMessage>,
|
qsoTable: DataTableState<ChatMessage>,
|
||||||
|
/** The divider between the two tables, remembered in the profile (#144). */
|
||||||
|
splitter: SplitterState,
|
||||||
darkMode: Boolean,
|
darkMode: Boolean,
|
||||||
baseFontSizeSp: Float,
|
baseFontSizeSp: Float,
|
||||||
/**
|
/**
|
||||||
@@ -70,7 +72,7 @@ object MonitorWindow {
|
|||||||
heightDp = heightDp,
|
heightDp = heightDp,
|
||||||
onResized = onResized,
|
onResized = onResized,
|
||||||
) { _ ->
|
) { _ ->
|
||||||
MonitorContent(clusterTable, qsoTable)
|
MonitorContent(clusterTable, qsoTable, splitter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,29 +82,31 @@ object MonitorWindow {
|
|||||||
internal fun MonitorContent(
|
internal fun MonitorContent(
|
||||||
clusterTable: DataTableState<ClusterMessage>,
|
clusterTable: DataTableState<ClusterMessage>,
|
||||||
qsoTable: DataTableState<ChatMessage>,
|
qsoTable: DataTableState<ChatMessage>,
|
||||||
|
splitter: SplitterState,
|
||||||
) {
|
) {
|
||||||
|
val strings = kst4contest.view.i18n.LocalStrings.current
|
||||||
|
|
||||||
Surface(modifier = Modifier.fillMaxSize()) {
|
Surface(modifier = Modifier.fillMaxSize()) {
|
||||||
Column(modifier = Modifier.fillMaxSize().padding(4.dp)) {
|
/*
|
||||||
Text("DX cluster", style = MaterialTheme.typography.titleSmall)
|
* Each heading sits in the pane of its table, so dragging the divider moves the
|
||||||
|
* heading with the table it names rather than leaving it stranded above the other.
|
||||||
|
*/
|
||||||
|
SplitterPane(
|
||||||
|
state = splitter,
|
||||||
|
orientation = SplitterOrientation.VERTICAL,
|
||||||
|
modifier = Modifier.fillMaxSize().padding(4.dp),
|
||||||
|
panes = listOf(
|
||||||
|
{ MonitorPane(strings.monitorDxCluster, clusterTable) },
|
||||||
|
{ MonitorPane(strings.messagesQsoOfTheOther, qsoTable) },
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
@Composable
|
||||||
* Half each, fixed. The JavaFX window used a SplitPane whose divider the
|
private fun <T> MonitorPane(heading: String, table: DataTableState<T>) {
|
||||||
* operator could drag, and that position was stored; reproducing the
|
Column(modifier = Modifier.fillMaxSize()) {
|
||||||
* gesture belongs with the station list of Etappe 5, where a split pane is
|
Text(heading, style = MaterialTheme.typography.titleSmall, modifier = Modifier.padding(top = 4.dp))
|
||||||
* unavoidable. Until then an even split is honest rather than a broken
|
DataTableView(table, modifier = Modifier.weight(1f).fillMaxWidth())
|
||||||
* handle.
|
|
||||||
*/
|
|
||||||
DataTableView(clusterTable, modifier = Modifier.weight(1f).fillMaxWidth())
|
|
||||||
|
|
||||||
HorizontalDivider(thickness = Density.HAIRLINE)
|
|
||||||
|
|
||||||
Text(
|
|
||||||
kst4contest.view.i18n.LocalStrings.current.messagesQsoOfTheOther,
|
|
||||||
style = MaterialTheme.typography.titleSmall,
|
|
||||||
modifier = Modifier.padding(top = 4.dp),
|
|
||||||
)
|
|
||||||
|
|
||||||
DataTableView(qsoTable, modifier = Modifier.weight(1f).fillMaxWidth())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import kst4contest.model.ChatMember
|
||||||
|
import kst4contest.model.RecentChatJoin
|
||||||
|
|
||||||
|
/** One selectable station in the transient New joined group. */
|
||||||
|
class NewJoinedEntry internal constructor(
|
||||||
|
val identity: StationIdentity,
|
||||||
|
val label: String,
|
||||||
|
val joinedAtEpochMillis: Long,
|
||||||
|
private val member: ChatMember,
|
||||||
|
private val onSelect: (ChatMember) -> Unit,
|
||||||
|
) {
|
||||||
|
fun select() = onSelect(member)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compose-facing view of live ON4KST join events.
|
||||||
|
*
|
||||||
|
* Initial and resynchronized user lists never reach this state. It receives the core's
|
||||||
|
* live-event roster and intersects it with the currently active station roster, so a
|
||||||
|
* departed station disappears immediately. The clock is injected to make expiry exact
|
||||||
|
* and testable without waiting ten minutes.
|
||||||
|
*/
|
||||||
|
class NewJoinedState(
|
||||||
|
private val clock: () -> Long = System::currentTimeMillis,
|
||||||
|
private val onSelect: (ChatMember) -> Unit,
|
||||||
|
) {
|
||||||
|
|
||||||
|
private var events: List<RecentChatJoin> = emptyList()
|
||||||
|
private var activeMembers: List<ChatMember> = emptyList()
|
||||||
|
private var liveEntries by mutableStateOf<List<NewJoinedEntry>>(emptyList())
|
||||||
|
|
||||||
|
val entries: List<NewJoinedEntry>
|
||||||
|
get() = liveEntries
|
||||||
|
|
||||||
|
val visibleEntries: List<NewJoinedEntry>
|
||||||
|
get() = liveEntries.take(SHOWN)
|
||||||
|
|
||||||
|
val overflowEntries: List<NewJoinedEntry>
|
||||||
|
get() = liveEntries.drop(SHOWN)
|
||||||
|
|
||||||
|
fun updateEvents(newEvents: List<RecentChatJoin>) {
|
||||||
|
events = newEvents.toList()
|
||||||
|
refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateActiveMembers(newMembers: List<ChatMember>) {
|
||||||
|
activeMembers = newMembers.toList()
|
||||||
|
refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Removes expired or departed entries and resolves each event to the latest row instance. */
|
||||||
|
fun refresh() {
|
||||||
|
val now = clock()
|
||||||
|
val activeByIdentity = activeMembers.mapNotNull { member ->
|
||||||
|
StationIdentity.of(member)?.let { identity -> identity to member }
|
||||||
|
}.toMap()
|
||||||
|
|
||||||
|
val firstJoinByIdentity = linkedMapOf<StationIdentity, RecentChatJoin>()
|
||||||
|
events.forEach { event ->
|
||||||
|
val identity = StationIdentity.of(event.callSign, event.categoryNumber)
|
||||||
|
?: return@forEach
|
||||||
|
val existing = firstJoinByIdentity[identity]
|
||||||
|
if (existing == null || event.joinedAtEpochMillis < existing.joinedAtEpochMillis) {
|
||||||
|
firstJoinByIdentity[identity] = event
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
liveEntries = firstJoinByIdentity
|
||||||
|
.mapNotNull { (identity, event) ->
|
||||||
|
val active = activeByIdentity[identity] ?: return@mapNotNull null
|
||||||
|
val ageMillis = now - event.joinedAtEpochMillis
|
||||||
|
if (ageMillis < 0L || ageMillis >= VALIDITY_MILLIS) {
|
||||||
|
return@mapNotNull null
|
||||||
|
}
|
||||||
|
NewJoinedEntry(
|
||||||
|
identity = identity,
|
||||||
|
label = identity.callSign,
|
||||||
|
joinedAtEpochMillis = event.joinedAtEpochMillis,
|
||||||
|
member = active,
|
||||||
|
onSelect = onSelect,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.sortedByDescending(NewJoinedEntry::joinedAtEpochMillis)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isRecent(member: ChatMember): Boolean {
|
||||||
|
val identity = StationIdentity.of(member) ?: return false
|
||||||
|
return liveEntries.any { it.identity == identity }
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val VALIDITY_MILLIS = 10L * 60L * 1000L
|
||||||
|
const val SHOWN = 5
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,11 @@
|
|||||||
package kst4contest.view.compose
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.DisposableEffect
|
||||||
|
import androidx.compose.runtime.State
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import kst4contest.observe.ObservableValue
|
import kst4contest.observe.ObservableValue
|
||||||
import java.util.function.Consumer
|
import java.util.function.Consumer
|
||||||
@@ -35,3 +39,19 @@ class ObservedValue<T>(private val source: ObservableValue<T>) {
|
|||||||
source.removeListener(follower)
|
source.removeListener(follower)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Observes a domain value only for the lifetime of the current composition. */
|
||||||
|
@Composable
|
||||||
|
internal fun <T> ObservableValue<T>.observeAsState(): State<T?> {
|
||||||
|
val state = remember(this) { mutableStateOf(get()) }
|
||||||
|
|
||||||
|
DisposableEffect(this) {
|
||||||
|
val follower = Consumer<T> { updated -> state.value = updated }
|
||||||
|
addListener(follower)
|
||||||
|
// Close the gap between the initial read and listener registration.
|
||||||
|
state.value = get()
|
||||||
|
onDispose { removeListener(follower) }
|
||||||
|
}
|
||||||
|
|
||||||
|
return state
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import kst4contest.model.Band
|
||||||
|
import kst4contest.model.ChatMember
|
||||||
|
|
||||||
|
/** One selectable entry in the reachability-band control. A null band means Auto. */
|
||||||
|
data class ReachabilityBandOption(val band: Band?, val label: String)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Operator-controlled reachability selection and the one explicit calculation action.
|
||||||
|
*
|
||||||
|
* Band selection only invalidates cached table/filter presentation. Online terrain work
|
||||||
|
* stays behind [calculateSelected], so recomposition and sorting cannot consume API calls.
|
||||||
|
*/
|
||||||
|
class ReachabilityState(
|
||||||
|
activeBands: Set<Band>,
|
||||||
|
private val resolveAutoBand: (ChatMember) -> Band? = { null },
|
||||||
|
private val selectedStation: () -> ChatMember? = { null },
|
||||||
|
private val calculate: (ChatMember, Band) -> Unit = { _, _ -> },
|
||||||
|
private val refresh: () -> Unit = { },
|
||||||
|
) {
|
||||||
|
private val supportedBands = activeBands.toSet()
|
||||||
|
|
||||||
|
val options: List<ReachabilityBandOption> =
|
||||||
|
listOf(ReachabilityBandOption(null, "Auto")) +
|
||||||
|
activeBands.sortedBy(Band::ordinal).map { band ->
|
||||||
|
ReachabilityBandOption(band, band.displayLabel)
|
||||||
|
}
|
||||||
|
|
||||||
|
var bandOverride: Band? by mutableStateOf(null)
|
||||||
|
private set
|
||||||
|
|
||||||
|
val selectedOption: ReachabilityBandOption
|
||||||
|
get() = options.first { it.band == bandOverride }
|
||||||
|
|
||||||
|
val canCalculate: Boolean
|
||||||
|
get() = selectedStation()?.let(::resolveBand) != null
|
||||||
|
|
||||||
|
fun selectBand(band: Band?) {
|
||||||
|
val accepted = band?.takeIf(supportedBands::contains)
|
||||||
|
if (bandOverride == accepted) return
|
||||||
|
bandOverride = accepted
|
||||||
|
refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun resolveBand(member: ChatMember): Band? = bandOverride ?: resolveAutoBand(member)
|
||||||
|
|
||||||
|
/** Returns whether a complete station/band request was handed to the service. */
|
||||||
|
fun calculateSelected(): Boolean {
|
||||||
|
val member = selectedStation() ?: return false
|
||||||
|
val band = resolveBand(member) ?: return false
|
||||||
|
calculate(member, band)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
+60
@@ -0,0 +1,60 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import kst4contest.model.ChatMember
|
||||||
|
import kst4contest.model.ChatMessage
|
||||||
|
import java.util.Locale
|
||||||
|
import java.util.function.Predicate
|
||||||
|
|
||||||
|
/** Builds the selected-station message filter without changing the source history. */
|
||||||
|
object SelectedStationMessagePredicate {
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun forSelection(
|
||||||
|
filter: SelectedMessageFilter,
|
||||||
|
selected: ChatMember?,
|
||||||
|
ownCallSign: String?,
|
||||||
|
): Predicate<ChatMessage> {
|
||||||
|
val selectedIdentity = StationIdentity.of(selected)
|
||||||
|
val ownCall = ownCallSign.normalizedCall()
|
||||||
|
|
||||||
|
return Predicate { message ->
|
||||||
|
if (selectedIdentity?.categoryNumber == null) {
|
||||||
|
return@Predicate false
|
||||||
|
}
|
||||||
|
|
||||||
|
val senderCall = message?.sender?.callSign.normalizedCall()
|
||||||
|
val receiverCall = message?.receiver?.callSign.normalizedCall()
|
||||||
|
val messageCategory = message?.chatCategory?.categoryNumber
|
||||||
|
if (senderCall.isBlank() || receiverCall.isBlank() ||
|
||||||
|
messageCategory != selectedIdentity.categoryNumber
|
||||||
|
) {
|
||||||
|
return@Predicate false
|
||||||
|
}
|
||||||
|
|
||||||
|
val selectedIsSender = senderCall == selectedIdentity.callSign
|
||||||
|
val selectedIsReceiver = receiverCall == selectedIdentity.callSign
|
||||||
|
val ownIsSender = senderCall == ownCall
|
||||||
|
val ownIsReceiver = receiverCall == ownCall
|
||||||
|
val isPublic = message.isMessageDirectedToCommunity || receiverCall == PUBLIC_RECEIVER
|
||||||
|
|
||||||
|
when (filter) {
|
||||||
|
SelectedMessageFilter.PM_TO_ME ->
|
||||||
|
ownCall.isNotBlank() && (
|
||||||
|
(!isPublic && ((selectedIsSender && ownIsReceiver) ||
|
||||||
|
(ownIsSender && selectedIsReceiver))) ||
|
||||||
|
(isPublic && selectedIsSender && message.isMessageDirectedToMe)
|
||||||
|
)
|
||||||
|
|
||||||
|
SelectedMessageFilter.PM_TO_OTHER ->
|
||||||
|
ownCall.isNotBlank() && selectedIsSender && !isPublic && !ownIsReceiver
|
||||||
|
|
||||||
|
SelectedMessageFilter.PUBLIC -> selectedIsSender && isPublic
|
||||||
|
SelectedMessageFilter.NOTHING -> selectedIsSender || selectedIsReceiver
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun String?.normalizedCall(): String = this?.trim()?.uppercase(Locale.ROOT).orEmpty()
|
||||||
|
|
||||||
|
private const val PUBLIC_RECEIVER = "ALL"
|
||||||
|
}
|
||||||
@@ -2,15 +2,36 @@ package kst4contest.view.compose
|
|||||||
|
|
||||||
import kst4contest.view.i18n.LocalStrings
|
import kst4contest.view.i18n.LocalStrings
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.border
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
||||||
import androidx.compose.foundation.layout.FlowRow
|
import androidx.compose.foundation.layout.FlowRow
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.heightIn
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.rememberScrollbarAdapter
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.foundation.VerticalScrollbar
|
||||||
|
import androidx.compose.foundation.LocalScrollbarStyle
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.DropdownMenu
|
||||||
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.foundation.selection.selectable
|
import androidx.compose.foundation.selection.selectable
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
@@ -22,8 +43,26 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.platform.testTag
|
||||||
import kst4contest.model.Band
|
import kst4contest.model.Band
|
||||||
import java.util.function.Consumer
|
import java.util.function.Consumer
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
|
||||||
|
internal const val SELECTED_STATION_PANEL_TAG = "selected-station-panel"
|
||||||
|
internal const val SELECTED_MESSAGES_TABLE_TAG = "selected-messages-table"
|
||||||
|
internal const val SELECTED_NOT_QRV_GROUP_TAG = "selected-not-qrv-group"
|
||||||
|
internal const val SELECTED_SKED_GROUP_TAG = "selected-sked-group"
|
||||||
|
internal const val NEW_JOINED_MORE_TAG = "new-joined-more"
|
||||||
|
internal const val NEW_JOINED_GROUP_TAG = "new-joined-group"
|
||||||
|
internal const val PRIORITY_GROUP_TAG = "priority-group"
|
||||||
|
|
||||||
|
internal fun skedBandOptions(activeBands: Set<Band>): List<Band> {
|
||||||
|
val options = ArrayList<Band>(activeBands.size)
|
||||||
|
Band.entries.forEach { band ->
|
||||||
|
if (activeBands.contains(band)) options.add(band)
|
||||||
|
}
|
||||||
|
return options
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The panel below the station list, for whichever station is selected.
|
* The panel below the station list, for whichever station is selected.
|
||||||
@@ -40,10 +79,9 @@ import java.util.function.Consumer
|
|||||||
fun SelectedStationPanel(
|
fun SelectedStationPanel(
|
||||||
state: SelectedStationState,
|
state: SelectedStationState,
|
||||||
messages: DataTableState<kst4contest.model.ChatMessage>,
|
messages: DataTableState<kst4contest.model.ChatMessage>,
|
||||||
/** The bands this station is set up for; BandOpportunityResolver decides them. */
|
/** My own station's enabled bands; used for NOT-QRV and sked controls. */
|
||||||
skedBands: List<Band>,
|
|
||||||
/** My own station's enabled bands; used for the "Tag not QRV" checkboxes. */
|
|
||||||
activeBands: Set<Band>,
|
activeBands: Set<Band>,
|
||||||
|
contentSplitter: SplitterState? = null,
|
||||||
openInBrowser: Consumer<String>,
|
openInBrowser: Consumer<String>,
|
||||||
onShowOnMap: () -> Unit,
|
onShowOnMap: () -> Unit,
|
||||||
onShowPathInAirScout: () -> Unit,
|
onShowPathInAirScout: () -> Unit,
|
||||||
@@ -51,136 +89,183 @@ fun SelectedStationPanel(
|
|||||||
) {
|
) {
|
||||||
val strings = LocalStrings.current
|
val strings = LocalStrings.current
|
||||||
val member = state.selected
|
val member = state.selected
|
||||||
|
val splitter = contentSplitter ?: remember {
|
||||||
|
SplitterState(2, doubleArrayOf(DEFAULT_SELECTED_MESSAGE_FRACTION)) {}
|
||||||
|
}
|
||||||
|
|
||||||
Column(
|
Box(
|
||||||
modifier = modifier.fillMaxWidth().padding(4.dp),
|
modifier = modifier
|
||||||
verticalArrangement = Arrangement.spacedBy(3.dp),
|
.fillMaxWidth()
|
||||||
|
.testTag(SELECTED_STATION_PANEL_TAG)
|
||||||
|
.background(MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.22f))
|
||||||
|
.border(Density.HAIRLINE, MaterialTheme.colorScheme.outlineVariant),
|
||||||
) {
|
) {
|
||||||
|
Column(modifier = Modifier.fillMaxSize()) {
|
||||||
if (member == null) {
|
if (member == null) {
|
||||||
Text(
|
Text(
|
||||||
strings.selectedNone,
|
strings.selectedNone,
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.outline,
|
color = MaterialTheme.colorScheme.outline,
|
||||||
|
modifier = Modifier.padding(4.dp),
|
||||||
)
|
)
|
||||||
return@Column
|
return@Column
|
||||||
}
|
}
|
||||||
|
|
||||||
Text(
|
SelectedStationHeaderAndFilter(state, member)
|
||||||
member.callSign.orEmpty() + " " + member.qra.orEmpty(),
|
|
||||||
style = MaterialTheme.typography.titleSmall,
|
SplitterPane(
|
||||||
fontWeight = FontWeight.Bold,
|
state = splitter,
|
||||||
|
orientation = SplitterOrientation.VERTICAL,
|
||||||
|
modifier = Modifier.fillMaxWidth().weight(1f),
|
||||||
|
minimumPaneSizes = listOf(
|
||||||
|
Density.ROW_MIN_HEIGHT * 2,
|
||||||
|
Density.SELECTED_ACTION_AREA_MIN_HEIGHT,
|
||||||
|
),
|
||||||
|
panes = listOf(
|
||||||
|
{
|
||||||
|
DataTableView(
|
||||||
|
state = messages,
|
||||||
|
modifier = Modifier.fillMaxSize().testTag(SELECTED_MESSAGES_TABLE_TAG),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
SelectedStationFunctions(
|
||||||
|
state = state,
|
||||||
|
activeBands = activeBands,
|
||||||
|
openInBrowser = openInBrowser,
|
||||||
|
onShowOnMap = onShowOnMap,
|
||||||
|
onShowPathInAirScout = onShowPathInAirScout,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FlowRow(
|
@OptIn(ExperimentalLayoutApi::class)
|
||||||
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
@Composable
|
||||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
private fun SelectedStationHeaderAndFilter(
|
||||||
modifier = Modifier.padding(bottom = 8.dp)
|
state: SelectedStationState,
|
||||||
) {
|
member: kst4contest.model.ChatMember,
|
||||||
val category = member.chatCategory?.let { it.getChatCategoryName(it.categoryNumber) }
|
) {
|
||||||
if (category != null) {
|
val strings = LocalStrings.current
|
||||||
Text(category, style = MaterialTheme.typography.bodySmall)
|
Column(
|
||||||
}
|
modifier = Modifier.fillMaxWidth().padding(horizontal = 4.dp, vertical = 2.dp),
|
||||||
if (member.getQTFdirection() != null) {
|
verticalArrangement = Arrangement.spacedBy(1.dp),
|
||||||
Text("QTF: ${member.getQTFdirection()}°", style = MaterialTheme.typography.bodySmall)
|
) {
|
||||||
}
|
val category = member.chatCategory?.let { it.getChatCategoryName(it.categoryNumber) }
|
||||||
if (member.qrb != null) {
|
val detectedBands = state.detectedBands()
|
||||||
Text("QRB: ${member.qrb} km", style = MaterialTheme.typography.bodySmall)
|
val metadata = buildList {
|
||||||
}
|
category?.let(::add)
|
||||||
|
member.getQTFdirection()?.let { add("QTF: $it°") }
|
||||||
|
member.qrb?.let { add("QRB: $it km") }
|
||||||
val lastActSec = member.activityTimeLastInEpoch
|
val lastActSec = member.activityTimeLastInEpoch
|
||||||
if (lastActSec > 0L) {
|
if (lastActSec > 0L) {
|
||||||
val actStr = MessageFormats.clockTime(lastActSec.toString())
|
val actStr = MessageFormats.clockTime(lastActSec.toString())
|
||||||
val minAgo = kst4contest.controller.Utils4KST.time_getSecondsBetweenEpochAndNow(lastActSec.toString()) / 60
|
val minAgo = kst4contest.controller.Utils4KST
|
||||||
Text(strings.selectedLastActivity(actStr, minAgo), style = MaterialTheme.typography.bodySmall)
|
.time_getSecondsBetweenEpochAndNow(lastActSec.toString()) / 60
|
||||||
}
|
add(strings.selectedLastActivity(actStr, minAgo))
|
||||||
|
|
||||||
val detectedBands = state.detectedBands()
|
|
||||||
if (detectedBands.isNotBlank()) {
|
|
||||||
Text(detectedBands, style = MaterialTheme.typography.bodySmall)
|
|
||||||
}
|
}
|
||||||
|
add(detectedBands.ifBlank { strings.tooltipBandsNone })
|
||||||
}
|
}
|
||||||
|
FlowRow(
|
||||||
Form.section(strings.selectedShowMessages) {
|
horizontalArrangement = Arrangement.spacedBy(Density.BUTTON_GAP),
|
||||||
FlowRow(horizontalArrangement = Arrangement.spacedBy(Density.BUTTON_GAP)) {
|
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||||
SelectedMessageFilter.entries.forEach { filter ->
|
modifier = Modifier.fillMaxWidth().padding(bottom = 1.dp),
|
||||||
RadioChoice(
|
) {
|
||||||
label = filter.label,
|
Text(
|
||||||
selected = state.messageFilter == filter,
|
member.callSign.orEmpty(),
|
||||||
onSelect = { state.messageFilter = filter },
|
style = MaterialTheme.typography.titleSmall,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
)
|
||||||
|
metadata.forEach { value ->
|
||||||
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
|
Text(
|
||||||
|
"|",
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.outline,
|
||||||
|
modifier = Modifier.padding(end = Density.BUTTON_GAP),
|
||||||
)
|
)
|
||||||
|
Text(value, style = MaterialTheme.typography.bodySmall)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DataTableView(
|
FlowRow(
|
||||||
state = messages,
|
modifier = Modifier.fillMaxWidth(),
|
||||||
modifier = Modifier.weight(1f).fillMaxWidth(),
|
horizontalArrangement = Arrangement.spacedBy(Density.BUTTON_GAP),
|
||||||
)
|
verticalArrangement = Arrangement.spacedBy(Density.FIELD_GAP),
|
||||||
|
itemVerticalAlignment = Alignment.CenterVertically,
|
||||||
Form.section(strings.selectedTagNotQrv) {
|
) {
|
||||||
FlowRow(horizontalArrangement = Arrangement.spacedBy(Density.BUTTON_GAP)) {
|
Row(
|
||||||
val activeNotQrvBands = NotQrvBand.entries.filter { activeBands.contains(it.band) }
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier.height(Density.CONTROL_HEIGHT),
|
||||||
activeNotQrvBands.forEach { band ->
|
|
||||||
Form.check(band.label, state.isTaggedNotQrv(band)) {
|
|
||||||
state.tagNotQrv(band, it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Form.check(strings.selectedNotQrvAll, activeNotQrvBands.all { state.isTaggedNotQrv(it) }) {
|
|
||||||
state.tagNotQrvAll(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Form.section("Sked") {
|
|
||||||
FlowRow(
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(Density.FIELD_GAP)
|
|
||||||
) {
|
) {
|
||||||
Form.inlineChoice(
|
Text(
|
||||||
label = strings.selectedSkedInMinutes,
|
"${strings.selectedShowMessages}:",
|
||||||
items = SelectedStationState.SKED_MINUTES,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
selected = state.skedMinutes,
|
modifier = Modifier.padding(end = Density.BUTTON_GAP),
|
||||||
describe = { it.toString() },
|
|
||||||
onSelect = { state.skedMinutes = it },
|
|
||||||
)
|
)
|
||||||
Form.inlineChoice(
|
RadioChoice(
|
||||||
label = strings.selectedBand,
|
label = SelectedMessageFilter.PM_TO_ME.label,
|
||||||
items = skedBands,
|
selected = state.messageFilter == SelectedMessageFilter.PM_TO_ME,
|
||||||
selected = state.skedBand,
|
onSelect = { state.messageFilter = SelectedMessageFilter.PM_TO_ME },
|
||||||
describe = { it.prefix + " MHz" },
|
|
||||||
onSelect = { state.skedBand = it },
|
|
||||||
)
|
|
||||||
Form.inlineChoice(
|
|
||||||
label = strings.selectedMode,
|
|
||||||
items = SelectedStationState.SKED_MODES,
|
|
||||||
selected = state.skedMode,
|
|
||||||
describe = { it },
|
|
||||||
onSelect = { state.skedMode = it },
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
SelectedMessageFilter.entries.drop(1).forEach { filter ->
|
||||||
Row(horizontalArrangement = Arrangement.spacedBy(16.dp), verticalAlignment = Alignment.CenterVertically) {
|
RadioChoice(
|
||||||
Form.check(strings.selectedRemindPmIn, state.remindPm) { state.remindPm = it }
|
label = filter.label,
|
||||||
Form.inlineChoice(
|
selected = state.messageFilter == filter,
|
||||||
label = strings.selectedReminderOffsets,
|
onSelect = { state.messageFilter = filter },
|
||||||
items = SelectedStationState.REMINDER_OFFSETS,
|
|
||||||
selected = state.reminderOffsets,
|
|
||||||
describe = { it },
|
|
||||||
enabled = state.remindPm,
|
|
||||||
onSelect = { state.reminderOffsets = it },
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
FlowRow(horizontalArrangement = Arrangement.spacedBy(Density.BUTTON_GAP)) {
|
|
||||||
Form.button(strings.selectedCreateSked, enabled = state.canCreateSked) { state.createSked() }
|
|
||||||
Form.button(strings.selectedSkedFail, enabled = state.canCreateSked) { state.markSkedFail() }
|
|
||||||
Form.button(strings.selectedResetFail, enabled = state.canCreateSked) { state.resetSkedFail() }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Form.section(strings.selectedLookUpAndShow) {
|
@OptIn(ExperimentalLayoutApi::class)
|
||||||
|
@Composable
|
||||||
|
private fun SelectedStationFunctions(
|
||||||
|
state: SelectedStationState,
|
||||||
|
activeBands: Set<Band>,
|
||||||
|
openInBrowser: Consumer<String>,
|
||||||
|
onShowOnMap: () -> Unit,
|
||||||
|
onShowPathInAirScout: () -> Unit,
|
||||||
|
) {
|
||||||
|
val strings = LocalStrings.current
|
||||||
|
val scroll = rememberScrollState()
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.fillMaxSize().padding(start = 4.dp, top = 1.dp, bottom = 2.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(1.dp),
|
||||||
|
) {
|
||||||
|
Box(modifier = Modifier.fillMaxWidth().weight(1f)) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(end = Density.SCROLLBAR_GUTTER)
|
||||||
|
.verticalScroll(scroll),
|
||||||
|
) {
|
||||||
|
SelectedStationActionGroups(
|
||||||
|
state = state,
|
||||||
|
activeBands = activeBands,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
VerticalScrollbar(
|
||||||
|
adapter = rememberScrollbarAdapter(scroll),
|
||||||
|
modifier = Modifier.align(Alignment.CenterEnd).fillMaxHeight(),
|
||||||
|
style = LocalScrollbarStyle.current.copy(
|
||||||
|
unhoverColor = MaterialTheme.colorScheme.outline,
|
||||||
|
hoverColor = MaterialTheme.colorScheme.onSurface,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
CompactFunctionGroup(
|
||||||
|
title = strings.selectedLookUpAndShow,
|
||||||
|
modifier = Modifier.fillMaxWidth().padding(end = Density.SCROLLBAR_GUTTER),
|
||||||
|
) {
|
||||||
FlowRow(horizontalArrangement = Arrangement.spacedBy(Density.BUTTON_GAP)) {
|
FlowRow(horizontalArrangement = Arrangement.spacedBy(Density.BUTTON_GAP)) {
|
||||||
Form.button(strings.selectedShowPathInAs, onClick = onShowPathInAirScout)
|
Form.button(strings.selectedShowPathInAs, onClick = onShowPathInAirScout)
|
||||||
Form.button(strings.selectedShowOnMap, onClick = onShowOnMap)
|
Form.button(strings.selectedShowOnMap, onClick = onShowOnMap)
|
||||||
@@ -202,8 +287,207 @@ fun SelectedStationPanel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private const val DEFAULT_SELECTED_MESSAGE_FRACTION = 0.55
|
||||||
|
|
||||||
|
@OptIn(ExperimentalLayoutApi::class)
|
||||||
|
@Composable
|
||||||
|
private fun SelectedStationActionGroups(
|
||||||
|
state: SelectedStationState,
|
||||||
|
activeBands: Set<Band>,
|
||||||
|
) {
|
||||||
|
val strings = LocalStrings.current
|
||||||
|
val member = state.selected ?: return
|
||||||
|
val activeNotQrvBands = NotQrvBand.entries.filter { activeBands.contains(it.band) }
|
||||||
|
val notQrvContent: @Composable () -> Unit = {
|
||||||
|
FlowRow(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(Density.BUTTON_GAP),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(Density.FIELD_GAP),
|
||||||
|
) {
|
||||||
|
activeNotQrvBands.forEach { band ->
|
||||||
|
Form.toggle(band.label, state.isTaggedNotQrv(band)) {
|
||||||
|
state.tagNotQrv(band, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Form.toggle(
|
||||||
|
strings.selectedNotQrvAll,
|
||||||
|
activeNotQrvBands.all { state.isTaggedNotQrv(it) },
|
||||||
|
) {
|
||||||
|
state.tagNotQrvAll(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val skedContent: @Composable () -> Unit = {
|
||||||
|
SkedAlertControls(state, activeBands)
|
||||||
|
}
|
||||||
|
|
||||||
|
BoxWithConstraints(modifier = Modifier.fillMaxWidth()) {
|
||||||
|
if (maxWidth >= Density.SELECTED_ACTION_GROUPS_ROW_MIN_WIDTH) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(Density.BUTTON_GAP),
|
||||||
|
verticalAlignment = Alignment.Top,
|
||||||
|
) {
|
||||||
|
CompactFunctionGroup(
|
||||||
|
title = strings.selectedTagNotQrv(member.callSign.orEmpty()),
|
||||||
|
modifier = Modifier.weight(0.35f).testTag(SELECTED_NOT_QRV_GROUP_TAG),
|
||||||
|
content = notQrvContent,
|
||||||
|
)
|
||||||
|
CompactFunctionGroup(
|
||||||
|
title = strings.selectedSked,
|
||||||
|
modifier = Modifier.weight(0.65f).testTag(SELECTED_SKED_GROUP_TAG),
|
||||||
|
content = skedContent,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(Density.FIELD_GAP),
|
||||||
|
) {
|
||||||
|
CompactFunctionGroup(
|
||||||
|
title = strings.selectedTagNotQrv(member.callSign.orEmpty()),
|
||||||
|
modifier = Modifier.fillMaxWidth().testTag(SELECTED_NOT_QRV_GROUP_TAG),
|
||||||
|
content = notQrvContent,
|
||||||
|
)
|
||||||
|
CompactFunctionGroup(
|
||||||
|
title = strings.selectedSked,
|
||||||
|
modifier = Modifier.fillMaxWidth().testTag(SELECTED_SKED_GROUP_TAG),
|
||||||
|
content = skedContent,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun CompactFunctionGroup(
|
||||||
|
title: String,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
content: @Composable () -> Unit,
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = modifier
|
||||||
|
.background(MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.48f))
|
||||||
|
.border(Density.HAIRLINE, MaterialTheme.colorScheme.outlineVariant, Density.BUTTON_SHAPE)
|
||||||
|
.padding(3.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(Density.FIELD_GAP),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
title,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
fontWeight = FontWeight.SemiBold,
|
||||||
|
)
|
||||||
|
content()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalLayoutApi::class)
|
||||||
|
@Composable
|
||||||
|
private fun SkedAlertControls(state: SelectedStationState, activeBands: Set<Band>) {
|
||||||
|
val strings = LocalStrings.current
|
||||||
|
SkedEditorControls(
|
||||||
|
activeBands = activeBands,
|
||||||
|
minutes = state.skedMinutes,
|
||||||
|
onMinutesChanged = { state.skedMinutes = it },
|
||||||
|
band = state.skedBand,
|
||||||
|
onBandChanged = { state.skedBand = it },
|
||||||
|
mode = state.skedMode,
|
||||||
|
onModeChanged = { state.skedMode = it },
|
||||||
|
remindPm = state.remindPm,
|
||||||
|
onRemindPmChanged = { state.remindPm = it },
|
||||||
|
reminderOffsets = state.reminderOffsets,
|
||||||
|
onReminderOffsetsChanged = { state.reminderOffsets = it },
|
||||||
|
canCreate = state.canCreateSked,
|
||||||
|
onCreate = { state.createSked() },
|
||||||
|
additionalActions = {
|
||||||
|
Form.button(strings.selectedSkedFail, enabled = state.canCreateSked) { state.markSkedFail() }
|
||||||
|
Form.button(strings.selectedResetFail, enabled = state.canCreateSked) { state.resetSkedFail() }
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Shared compact sked editor used by the station panel and the context popup. */
|
||||||
|
@OptIn(ExperimentalLayoutApi::class)
|
||||||
|
@Composable
|
||||||
|
internal fun SkedEditorControls(
|
||||||
|
activeBands: Set<Band>,
|
||||||
|
minutes: Int,
|
||||||
|
onMinutesChanged: (Int) -> Unit,
|
||||||
|
band: Band?,
|
||||||
|
onBandChanged: (Band) -> Unit,
|
||||||
|
mode: String?,
|
||||||
|
onModeChanged: (String) -> Unit,
|
||||||
|
remindPm: Boolean,
|
||||||
|
onRemindPmChanged: (Boolean) -> Unit,
|
||||||
|
reminderOffsets: String,
|
||||||
|
onReminderOffsetsChanged: (String) -> Unit,
|
||||||
|
canCreate: Boolean,
|
||||||
|
onCreate: () -> Unit,
|
||||||
|
additionalActions: @Composable () -> Unit = {},
|
||||||
|
) {
|
||||||
|
val strings = LocalStrings.current
|
||||||
|
|
||||||
|
FlowRow(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(Density.BUTTON_GAP),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(Density.FIELD_GAP),
|
||||||
|
) {
|
||||||
|
Form.inlineChoice(
|
||||||
|
label = strings.selectedSkedIn,
|
||||||
|
items = SelectedStationState.SKED_MINUTES,
|
||||||
|
selected = minutes,
|
||||||
|
describe = { it.toString() },
|
||||||
|
trailingText = strings.selectedSkedMinutesAt,
|
||||||
|
onSelect = onMinutesChanged,
|
||||||
|
)
|
||||||
|
Form.inlineChoice(
|
||||||
|
label = "",
|
||||||
|
items = skedBandOptions(activeBands),
|
||||||
|
selected = band,
|
||||||
|
describe = { it.prefix + " MHz" },
|
||||||
|
trailingText = strings.selectedSkedModeLink,
|
||||||
|
onSelect = onBandChanged,
|
||||||
|
)
|
||||||
|
Form.inlineChoice(
|
||||||
|
label = "",
|
||||||
|
items = SelectedStationState.SKED_MODES,
|
||||||
|
selected = mode,
|
||||||
|
describe = { it },
|
||||||
|
trailingText = ".",
|
||||||
|
onSelect = onModeChanged,
|
||||||
|
)
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier.height(Density.CONTROL_HEIGHT),
|
||||||
|
) {
|
||||||
|
CompactCheckbox(remindPm, onCheckedChange = onRemindPmChanged)
|
||||||
|
Text(
|
||||||
|
strings.selectedRemindPmIn,
|
||||||
|
style = compactControlTextStyle(),
|
||||||
|
modifier = Modifier.padding(start = 4.dp, end = 4.dp),
|
||||||
|
)
|
||||||
|
Form.inlineChoice(
|
||||||
|
label = "",
|
||||||
|
items = SelectedStationState.REMINDER_OFFSETS,
|
||||||
|
selected = reminderOffsets,
|
||||||
|
describe = { it },
|
||||||
|
enabled = remindPm,
|
||||||
|
trailingText = strings.selectedMinutes,
|
||||||
|
onSelect = onReminderOffsetsChanged,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FlowRow(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(Density.BUTTON_GAP),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(Density.FIELD_GAP),
|
||||||
|
) {
|
||||||
|
Form.button(strings.selectedCreateSked, enabled = canCreate, onClick = onCreate)
|
||||||
|
additionalActions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,26 +498,111 @@ fun SelectedStationPanel(
|
|||||||
@Composable
|
@Composable
|
||||||
fun TopPriorityBar(
|
fun TopPriorityBar(
|
||||||
state: TopPriorityState,
|
state: TopPriorityState,
|
||||||
|
newJoined: NewJoinedState? = null,
|
||||||
onShowMore: () -> Unit,
|
onShowMore: () -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
val strings = LocalStrings.current
|
val strings = LocalStrings.current
|
||||||
|
|
||||||
Row(
|
LaunchedEffect(newJoined) {
|
||||||
modifier = modifier.padding(2.dp),
|
while (newJoined != null) {
|
||||||
horizontalArrangement = Arrangement.spacedBy(Density.BUTTON_GAP),
|
delay(NEW_JOINED_REFRESH_INTERVAL_MILLIS)
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
newJoined.refresh()
|
||||||
) {
|
|
||||||
Text(strings.selectedPriority, style = MaterialTheme.typography.bodySmall)
|
|
||||||
|
|
||||||
state.entries.forEach { entry ->
|
|
||||||
Form.button(entry.label, onClick = entry.select)
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Form.button(strings.selectedMore, onClick = onShowMore)
|
BoxWithConstraints(modifier = modifier) {
|
||||||
|
val allJoinedEntries = newJoined?.entries.orEmpty()
|
||||||
|
val directCount = when {
|
||||||
|
maxWidth >= 520.dp -> NewJoinedState.SHOWN
|
||||||
|
maxWidth >= 450.dp -> 4
|
||||||
|
maxWidth >= 380.dp -> 3
|
||||||
|
maxWidth >= 310.dp -> 2
|
||||||
|
else -> 1
|
||||||
|
}
|
||||||
|
val joinedEntries = allJoinedEntries.take(directCount)
|
||||||
|
val overflow = allJoinedEntries.drop(directCount)
|
||||||
|
|
||||||
|
FlowRow(
|
||||||
|
modifier = Modifier.fillMaxWidth().padding(2.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(Density.BUTTON_GAP),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||||
|
itemVerticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
if (joinedEntries.isNotEmpty()) {
|
||||||
|
CandidateGroup(Modifier.testTag(NEW_JOINED_GROUP_TAG)) {
|
||||||
|
Text(strings.selectedNewJoined, style = MaterialTheme.typography.bodySmall)
|
||||||
|
|
||||||
|
joinedEntries.forEach { entry ->
|
||||||
|
Form.button(entry.label, horizontalPadding = 4.dp, onClick = entry::select)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (overflow.isNotEmpty()) {
|
||||||
|
NewJoinedOverflow(overflow)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CandidateGroup(Modifier.testTag(PRIORITY_GROUP_TAG)) {
|
||||||
|
Text(strings.selectedPriority, style = MaterialTheme.typography.bodySmall)
|
||||||
|
|
||||||
|
state.entries.forEach { entry ->
|
||||||
|
Form.button(entry.label, onClick = entry.select)
|
||||||
|
}
|
||||||
|
|
||||||
|
Form.button(strings.selectedMore, onClick = onShowMore)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun CandidateGroup(modifier: Modifier = Modifier, content: @Composable () -> Unit) {
|
||||||
|
FlowRow(
|
||||||
|
modifier = modifier
|
||||||
|
.background(MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.35f))
|
||||||
|
.border(Density.HAIRLINE, MaterialTheme.colorScheme.outlineVariant, Density.BUTTON_SHAPE)
|
||||||
|
.padding(2.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(Density.BUTTON_GAP),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||||
|
itemVerticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
content()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
private fun NewJoinedOverflow(entries: List<NewJoinedEntry>) {
|
||||||
|
val strings = LocalStrings.current
|
||||||
|
var expanded by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
Box {
|
||||||
|
Form.button(
|
||||||
|
strings.selectedMore,
|
||||||
|
modifier = Modifier.testTag(NEW_JOINED_MORE_TAG),
|
||||||
|
horizontalPadding = 4.dp,
|
||||||
|
) { expanded = true }
|
||||||
|
CompositionLocalProvider(LocalMinimumInteractiveComponentSize provides 0.dp) {
|
||||||
|
DropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {
|
||||||
|
entries.forEach { entry ->
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = { Text(entry.label, style = compactControlTextStyle()) },
|
||||||
|
onClick = {
|
||||||
|
expanded = false
|
||||||
|
entry.select()
|
||||||
|
},
|
||||||
|
contentPadding = PaddingValues(horizontal = 8.dp),
|
||||||
|
modifier = Modifier.heightIn(min = Density.CONTROL_HEIGHT),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private const val NEW_JOINED_REFRESH_INTERVAL_MILLIS = 1_000L
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One of a set of mutually exclusive choices.
|
* One of a set of mutually exclusive choices.
|
||||||
@@ -249,6 +618,7 @@ private fun RadioChoice(label: String, selected: Boolean, onSelect: () -> Unit)
|
|||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.selectable(selected = selected, onClick = onSelect)
|
.selectable(selected = selected, onClick = onSelect)
|
||||||
|
.height(Density.CONTROL_HEIGHT)
|
||||||
.padding(end = Density.BUTTON_GAP),
|
.padding(end = Density.BUTTON_GAP),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import androidx.compose.runtime.mutableStateOf
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import kst4contest.model.Band
|
import kst4contest.model.Band
|
||||||
import kst4contest.model.ChatMember
|
import kst4contest.model.ChatMember
|
||||||
|
import kst4contest.model.ChatPreferences
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The bands a station can be tagged as not being on, under the labels the panel shows.
|
* The bands a station can be tagged as not being on, under the labels the panel shows.
|
||||||
@@ -39,7 +40,17 @@ enum class SelectedMessageFilter(val label: String) {
|
|||||||
PM_TO_ME("pm to me"),
|
PM_TO_ME("pm to me"),
|
||||||
PM_TO_OTHER("pm to other"),
|
PM_TO_OTHER("pm to other"),
|
||||||
PUBLIC("public msgs"),
|
PUBLIC("public msgs"),
|
||||||
NOTHING("nothing"),
|
NOTHING("nothing");
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
fun fromPreferences(prefs: ChatPreferences): SelectedMessageFilter = when {
|
||||||
|
prefs.isGuiOptions_defaultFilterPmToMe -> PM_TO_ME
|
||||||
|
prefs.isGuiOptions_defaultFilterPmToOther -> PM_TO_OTHER
|
||||||
|
prefs.isGuiOptions_defaultFilterPublicMsgs -> PUBLIC
|
||||||
|
else -> NOTHING
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,7 +72,7 @@ enum class SelectedMessageFilter(val label: String) {
|
|||||||
* every draw, so the supplied lambda has to read Compose state for the button to
|
* every draw, so the supplied lambda has to read Compose state for the button to
|
||||||
* follow a settings Apply
|
* follow a settings Apply
|
||||||
*/
|
*/
|
||||||
class SelectedStationState(
|
class SelectedStationState @JvmOverloads constructor(
|
||||||
private val propagateNotQrv: (ChatMember) -> Unit,
|
private val propagateNotQrv: (ChatMember) -> Unit,
|
||||||
private val createSked: (ChatMember, Int, Band?, String?) -> Boolean,
|
private val createSked: (ChatMember, Int, Band?, String?) -> Boolean,
|
||||||
private val markSkedFail: (ChatMember) -> Unit = { },
|
private val markSkedFail: (ChatMember) -> Unit = { },
|
||||||
@@ -72,10 +83,14 @@ class SelectedStationState(
|
|||||||
private val turnAntennaTo: ((Double) -> Unit)? = null,
|
private val turnAntennaTo: ((Double) -> Unit)? = null,
|
||||||
private val turnSecondAntennaTo: ((Double) -> Unit)? = null,
|
private val turnSecondAntennaTo: ((Double) -> Unit)? = null,
|
||||||
private val secondAntennaOffered: () -> Boolean = { false },
|
private val secondAntennaOffered: () -> Boolean = { false },
|
||||||
|
val stationSelection: StationSelectionState = StationSelectionState(),
|
||||||
) {
|
) {
|
||||||
|
|
||||||
var selected: ChatMember? by mutableStateOf(null)
|
/** Shared sked action used by both the panel and isolated context-menu drafts. */
|
||||||
private set
|
var skedRequestSubmitter: ((SkedRequest) -> Boolean)? = null
|
||||||
|
|
||||||
|
val selected: ChatMember?
|
||||||
|
get() = stationSelection.selected
|
||||||
|
|
||||||
/** Bumped on a tag so the panel redraws; the flags live on the station itself. */
|
/** Bumped on a tag so the panel redraws; the flags live on the station itself. */
|
||||||
private var tagRevision: Int by mutableStateOf(0)
|
private var tagRevision: Int by mutableStateOf(0)
|
||||||
@@ -136,25 +151,36 @@ class SelectedStationState(
|
|||||||
if (heading.isFinite() && showsSecondAntenna) turnSecondAntennaTo?.invoke(heading)
|
if (heading.isFinite() && showsSecondAntenna) turnSecondAntennaTo?.invoke(heading)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun select(member: ChatMember?) {
|
@JvmOverloads
|
||||||
if (selected?.callSignRaw != member?.callSignRaw) {
|
fun select(
|
||||||
|
member: ChatMember?,
|
||||||
|
source: StationSelectionSource = StationSelectionSource.PROGRAMMATIC,
|
||||||
|
) {
|
||||||
|
if (StationIdentity.of(selected) != StationIdentity.of(member)) {
|
||||||
skedBand = member?.let { resolveDefaultSkedBand(it) }
|
skedBand = member?.let { resolveDefaultSkedBand(it) }
|
||||||
}
|
}
|
||||||
selected = member
|
stationSelection.select(member, source)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isTaggedNotQrv(band: NotQrvBand): Boolean {
|
fun isTaggedNotQrv(band: NotQrvBand): Boolean {
|
||||||
@Suppress("UNUSED_EXPRESSION") tagRevision
|
@Suppress("UNUSED_EXPRESSION") tagRevision
|
||||||
|
|
||||||
val member = selected ?: return false
|
return selected?.let { isTaggedNotQrv(it, band) } ?: false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isTaggedNotQrv(member: ChatMember, band: NotQrvBand): Boolean {
|
||||||
|
@Suppress("UNUSED_EXPRESSION") tagRevision
|
||||||
return !band.read(member)
|
return !band.read(member)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Tagged means not QRV, so the station's QRV flag goes the other way. */
|
/** Tagged means not QRV, so the station's QRV flag goes the other way. */
|
||||||
fun tagNotQrv(band: NotQrvBand, tagged: Boolean) {
|
fun tagNotQrv(band: NotQrvBand, tagged: Boolean) {
|
||||||
val member = selected ?: return
|
val member = selected ?: return
|
||||||
|
tagNotQrv(member, band, tagged)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Applies a context action to its fixed target instead of the current selection. */
|
||||||
|
fun tagNotQrv(member: ChatMember, band: NotQrvBand, tagged: Boolean) {
|
||||||
band.write(member, !tagged)
|
band.write(member, !tagged)
|
||||||
tagRevision++
|
tagRevision++
|
||||||
propagateNotQrv(member)
|
propagateNotQrv(member)
|
||||||
@@ -162,7 +188,10 @@ class SelectedStationState(
|
|||||||
|
|
||||||
fun tagNotQrvAll(tagged: Boolean) {
|
fun tagNotQrvAll(tagged: Boolean) {
|
||||||
val member = selected ?: return
|
val member = selected ?: return
|
||||||
|
tagNotQrvAll(member, tagged)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun tagNotQrvAll(member: ChatMember, tagged: Boolean) {
|
||||||
NotQrvBand.entries.forEach { it.write(member, !tagged) }
|
NotQrvBand.entries.forEach { it.write(member, !tagged) }
|
||||||
tagRevision++
|
tagRevision++
|
||||||
propagateNotQrv(member)
|
propagateNotQrv(member)
|
||||||
@@ -172,9 +201,33 @@ class SelectedStationState(
|
|||||||
fun createSked(): Boolean {
|
fun createSked(): Boolean {
|
||||||
val member = selected ?: return false
|
val member = selected ?: return false
|
||||||
|
|
||||||
return createSked(member, skedMinutes, skedBand, skedMode)
|
val request = SkedRequest(
|
||||||
|
target = member,
|
||||||
|
minutes = skedMinutes,
|
||||||
|
band = skedBand,
|
||||||
|
mode = skedMode,
|
||||||
|
remindPm = remindPm,
|
||||||
|
reminderOffsets = reminderOffsets,
|
||||||
|
)
|
||||||
|
return submitSked(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Submits a fixed-target request through the shared application action. */
|
||||||
|
fun submitSked(request: SkedRequest): Boolean =
|
||||||
|
skedRequestSubmitter?.invoke(request)
|
||||||
|
?: createSked(request.target, request.minutes, request.band, request.mode)
|
||||||
|
|
||||||
|
/** Copies the panel values into an isolated draft for a fixed target. */
|
||||||
|
fun createSkedDraft(target: ChatMember): SkedEditorState = SkedEditorState(
|
||||||
|
target = target,
|
||||||
|
minutes = skedMinutes,
|
||||||
|
band = skedBand ?: resolveDefaultSkedBand(target),
|
||||||
|
mode = skedMode,
|
||||||
|
remindPm = remindPm,
|
||||||
|
reminderOffsets = reminderOffsets,
|
||||||
|
submitter = ::submitSked,
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the path to this station as failed.
|
* Marks the path to this station as failed.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
package kst4contest.view.compose
|
package kst4contest.view.compose
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import kst4contest.controller.ChatController
|
import kst4contest.controller.ChatController
|
||||||
import kst4contest.controller.ActiveOperatorProfile
|
import kst4contest.controller.ActiveOperatorProfile
|
||||||
import kst4contest.controller.OperatorProfileManagementService
|
import kst4contest.controller.OperatorProfileManagementService
|
||||||
@@ -65,6 +62,9 @@ interface SettingsHost {
|
|||||||
*/
|
*/
|
||||||
fun refreshSo2rState()
|
fun refreshSo2rState()
|
||||||
|
|
||||||
|
/** Pushes applied antenna-beam geometry into the open Compose map. */
|
||||||
|
fun refreshMapDisplaySettings()
|
||||||
|
|
||||||
/** Rebuilds the Ctrl+1..Ctrl+0 context menus from the snippet list. */
|
/** Rebuilds the Ctrl+1..Ctrl+0 context menus from the snippet list. */
|
||||||
fun refreshTextSnippetContextMenusFromSettings()
|
fun refreshTextSnippetContextMenusFromSettings()
|
||||||
|
|
||||||
@@ -151,6 +151,8 @@ fun buildSettingsTabs(
|
|||||||
applySecondCategory = { category -> controller.setChatCategorySecondChat(category) },
|
applySecondCategory = { category -> controller.setChatCategorySecondChat(category) },
|
||||||
connectionState = connectionState,
|
connectionState = connectionState,
|
||||||
applySecondRotator = { controller.reconfigureSecondRotator(); host.refreshSo2rState() },
|
applySecondRotator = { controller.reconfigureSecondRotator(); host.refreshSo2rState() },
|
||||||
|
refreshBeaconStatus = controller::refreshBeaconStatus,
|
||||||
|
applyMapDisplaySettings = host::refreshMapDisplaySettings,
|
||||||
)
|
)
|
||||||
|
|
||||||
val notificationState = NotificationTabState(
|
val notificationState = NotificationTabState(
|
||||||
@@ -188,8 +190,14 @@ fun buildSettingsTabs(
|
|||||||
draft,
|
draft,
|
||||||
validateBeaconTemplate = { template -> controller.validateBeaconTemplate(template) },
|
validateBeaconTemplate = { template -> controller.validateBeaconTemplate(template) },
|
||||||
restartBeaconTimer = { controller.restartBeaconTimer() },
|
restartBeaconTimer = { controller.restartBeaconTimer() },
|
||||||
|
setMainBeaconEnabled = controller::setMainBeaconEnabled,
|
||||||
|
setSecondBeaconEnabled = controller::setSecondBeaconEnabled,
|
||||||
mainCategoryName = categoryName(controller.chatCategoryMain, kst4contest.view.i18n.CurrentStrings.get().settingsCategoryMainFallback),
|
mainCategoryName = categoryName(controller.chatCategoryMain, kst4contest.view.i18n.CurrentStrings.get().settingsCategoryMainFallback),
|
||||||
secondCategoryName = categoryName(controller.chatCategorySecondChat, kst4contest.view.i18n.CurrentStrings.get().settingsCategorySecondFallback),
|
secondCategoryName = categoryName(controller.chatCategorySecondChat, kst4contest.view.i18n.CurrentStrings.get().settingsCategorySecondFallback),
|
||||||
|
onBeaconTemplatesApplied = {
|
||||||
|
controller.onMainBeaconTemplateApplied()
|
||||||
|
controller.onSecondBeaconTemplateApplied()
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
val logSynchState = LogSynchTabState(
|
val logSynchState = LogSynchTabState(
|
||||||
@@ -324,18 +332,11 @@ fun settingsButtons(
|
|||||||
host: SettingsHost,
|
host: SettingsHost,
|
||||||
notices: SettingsNotices,
|
notices: SettingsNotices,
|
||||||
draft: SettingsDraft,
|
draft: SettingsDraft,
|
||||||
|
connectionState: () -> On4KstConnectionState,
|
||||||
): @Composable (close: () -> Unit) -> Unit {
|
): @Composable (close: () -> Unit) -> Unit {
|
||||||
val barState = ConnectionBarState(controller.chatPreferences, controller)
|
val barState = ConnectionBarState(controller.chatPreferences, connectionState)
|
||||||
|
|
||||||
return { close ->
|
return { close ->
|
||||||
/*
|
|
||||||
* The bar is rebuilt after every action so its labels and enabled states follow
|
|
||||||
* the session. The JavaFX bar was told by onConnectionStateChanged instead.
|
|
||||||
*/
|
|
||||||
var revision by remember { mutableStateOf(0) }
|
|
||||||
|
|
||||||
@Suppress("UNUSED_EXPRESSION") revision
|
|
||||||
|
|
||||||
ConnectionBar(
|
ConnectionBar(
|
||||||
state = barState,
|
state = barState,
|
||||||
onConnect = {
|
onConnect = {
|
||||||
@@ -343,14 +344,12 @@ fun settingsButtons(
|
|||||||
val refusal = host.connectFromSettings()
|
val refusal = host.connectFromSettings()
|
||||||
if (refusal != null) notices.problem(refusal)
|
if (refusal != null) notices.problem(refusal)
|
||||||
}
|
}
|
||||||
revision++
|
|
||||||
},
|
},
|
||||||
onSave = { applyAndSave(draft, notices, host::savePreferencesFromSettings) },
|
onSave = { applyAndSave(draft, notices, host::savePreferencesFromSettings) },
|
||||||
onApplyAndClose = { if (applyChecked(draft, notices)) close() },
|
onApplyAndClose = { if (applyChecked(draft, notices)) close() },
|
||||||
onDisconnectAndCloseChat = host::disconnectAndCloseChatFromSettings,
|
onDisconnectAndCloseChat = host::disconnectAndCloseChatFromSettings,
|
||||||
onDisconnectOnly = {
|
onDisconnectOnly = {
|
||||||
host.disconnectOnlyFromSettings()
|
host.disconnectOnlyFromSettings()
|
||||||
revision++
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import kst4contest.model.Band
|
||||||
|
import kst4contest.model.ChatMember
|
||||||
|
|
||||||
|
/** Complete immutable request handed to the shared sked creation action. */
|
||||||
|
data class SkedRequest(
|
||||||
|
val target: ChatMember,
|
||||||
|
val minutes: Int,
|
||||||
|
val band: Band?,
|
||||||
|
val mode: String?,
|
||||||
|
val remindPm: Boolean,
|
||||||
|
val reminderOffsets: String,
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Isolated editor draft used by the station-context popup.
|
||||||
|
*
|
||||||
|
* The target is captured when the popup opens. Later station selections therefore do
|
||||||
|
* not redirect a partially edited sked.
|
||||||
|
*/
|
||||||
|
class SkedEditorState(
|
||||||
|
val target: ChatMember,
|
||||||
|
minutes: Int,
|
||||||
|
band: Band?,
|
||||||
|
mode: String?,
|
||||||
|
remindPm: Boolean,
|
||||||
|
reminderOffsets: String,
|
||||||
|
private val submitter: (SkedRequest) -> Boolean,
|
||||||
|
) {
|
||||||
|
var minutes by mutableStateOf(minutes)
|
||||||
|
var band by mutableStateOf(band)
|
||||||
|
var mode by mutableStateOf(mode)
|
||||||
|
var remindPm by mutableStateOf(remindPm)
|
||||||
|
var reminderOffsets by mutableStateOf(reminderOffsets)
|
||||||
|
|
||||||
|
fun request(): SkedRequest = SkedRequest(
|
||||||
|
target = target,
|
||||||
|
minutes = minutes,
|
||||||
|
band = band,
|
||||||
|
mode = mode,
|
||||||
|
remindPm = remindPm,
|
||||||
|
reminderOffsets = reminderOffsets,
|
||||||
|
)
|
||||||
|
|
||||||
|
fun submit(): Boolean = submitter(request())
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ import androidx.compose.ui.input.pointer.pointerHoverIcon
|
|||||||
import androidx.compose.ui.input.pointer.pointerInput
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.ui.platform.LocalDensity
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import java.awt.Cursor
|
import java.awt.Cursor
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@ fun SplitterPane(
|
|||||||
orientation: SplitterOrientation,
|
orientation: SplitterOrientation,
|
||||||
panes: List<@Composable () -> Unit>,
|
panes: List<@Composable () -> Unit>,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
minimumPaneSizes: List<Dp> = emptyList(),
|
||||||
) {
|
) {
|
||||||
BoxWithConstraints(modifier) {
|
BoxWithConstraints(modifier) {
|
||||||
val density = LocalDensity.current
|
val density = LocalDensity.current
|
||||||
@@ -55,7 +57,10 @@ fun SplitterPane(
|
|||||||
* cursor rather than drifting from it by a handle width per divider.
|
* cursor rather than drifting from it by a handle width per divider.
|
||||||
*/
|
*/
|
||||||
val totalPx = SplitterState.availableFor(fullPx, handlePx, state.paneCount)
|
val totalPx = SplitterState.availableFor(fullPx, handlePx, state.paneCount)
|
||||||
val sizes = state.paneSizes(totalPx)
|
val minimumPaneSizesPx = FloatArray(minimumPaneSizes.size) { index ->
|
||||||
|
with(density) { minimumPaneSizes[index].toPx() }
|
||||||
|
}
|
||||||
|
val sizes = state.paneSizes(totalPx, minimumPaneSizesPx)
|
||||||
|
|
||||||
val body: @Composable () -> Unit = {
|
val body: @Composable () -> Unit = {
|
||||||
panes.forEachIndexed { index, pane ->
|
panes.forEachIndexed { index, pane ->
|
||||||
@@ -77,6 +82,7 @@ fun SplitterPane(
|
|||||||
index = index,
|
index = index,
|
||||||
orientation = orientation,
|
orientation = orientation,
|
||||||
totalPx = totalPx,
|
totalPx = totalPx,
|
||||||
|
minimumPaneSizesPx = minimumPaneSizesPx,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,6 +106,7 @@ private fun SplitterHandle(
|
|||||||
index: Int,
|
index: Int,
|
||||||
orientation: SplitterOrientation,
|
orientation: SplitterOrientation,
|
||||||
totalPx: Float,
|
totalPx: Float,
|
||||||
|
minimumPaneSizesPx: FloatArray,
|
||||||
) {
|
) {
|
||||||
val horizontal = orientation == SplitterOrientation.HORIZONTAL
|
val horizontal = orientation == SplitterOrientation.HORIZONTAL
|
||||||
val cursor = if (horizontal) Cursor.E_RESIZE_CURSOR else Cursor.N_RESIZE_CURSOR
|
val cursor = if (horizontal) Cursor.E_RESIZE_CURSOR else Cursor.N_RESIZE_CURSOR
|
||||||
@@ -111,15 +118,20 @@ private fun SplitterHandle(
|
|||||||
else Modifier.height(Density.COLUMN_HANDLE_WIDTH).fillMaxWidth(),
|
else Modifier.height(Density.COLUMN_HANDLE_WIDTH).fillMaxWidth(),
|
||||||
)
|
)
|
||||||
.pointerHoverIcon(PointerIcon(Cursor(cursor)))
|
.pointerHoverIcon(PointerIcon(Cursor(cursor)))
|
||||||
.pointerInput(index, totalPx) {
|
.pointerInput(index, totalPx, minimumPaneSizesPx.contentHashCode()) {
|
||||||
detectDragGestures(
|
detectDragGestures(
|
||||||
onDragEnd = { state.dragFinished() },
|
onDragEnd = { state.dragFinished() },
|
||||||
onDragCancel = { state.dragFinished() },
|
onDragCancel = { state.dragFinished() },
|
||||||
) { _, dragAmount ->
|
) { _, dragAmount ->
|
||||||
if (totalPx <= 0f) return@detectDragGestures
|
if (totalPx <= 0f) return@detectDragGestures
|
||||||
val delta = if (horizontal) dragAmount.x else dragAmount.y
|
val delta = if (horizontal) dragAmount.x else dragAmount.y
|
||||||
val current = state.positions.getOrElse(index) { 0f }
|
val current = state.dividerPosition(index, totalPx, minimumPaneSizesPx)
|
||||||
state.drag(index, current + delta / totalPx, totalPx)
|
state.drag(
|
||||||
|
index = index,
|
||||||
|
to = current + delta / totalPx,
|
||||||
|
totalPx = totalPx,
|
||||||
|
minimumPaneSizesPx = minimumPaneSizesPx,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
contentAlignment = Alignment.Center,
|
contentAlignment = Alignment.Center,
|
||||||
|
|||||||
@@ -39,9 +39,27 @@ class SplitterState(
|
|||||||
* @param to the wanted position as a fraction of the whole
|
* @param to the wanted position as a fraction of the whole
|
||||||
* @param totalPx the splitter's length, needed to turn the minimum into a fraction
|
* @param totalPx the splitter's length, needed to turn the minimum into a fraction
|
||||||
*/
|
*/
|
||||||
fun drag(index: Int, to: Float, totalPx: Float) {
|
fun drag(
|
||||||
|
index: Int,
|
||||||
|
to: Float,
|
||||||
|
totalPx: Float,
|
||||||
|
minimumPaneSizesPx: FloatArray = EMPTY_MINIMUMS,
|
||||||
|
) {
|
||||||
if (index !in 0 until dividerCount) return
|
if (index !in 0 until dividerCount) return
|
||||||
|
|
||||||
|
if (minimumPaneSizesPx.isNotEmpty()) {
|
||||||
|
val minimums = scaledMinimums(totalPx, minimumPaneSizesPx)
|
||||||
|
val effective = effectiveDividerPositions(totalPx, minimumPaneSizesPx)
|
||||||
|
val lowerBound = (effective.getOrElse(index - 1) { 0f } + minimums[index]) / totalPx
|
||||||
|
val upperBound = (effective.getOrElse(index + 1) { totalPx } - minimums[index + 1]) / totalPx
|
||||||
|
livePositions[index] = if (lowerBound > upperBound) {
|
||||||
|
(lowerBound + upperBound) / 2f
|
||||||
|
} else {
|
||||||
|
to.coerceIn(lowerBound, upperBound)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val minFraction = if (totalPx > 0f) minPanePx / totalPx else 0f
|
val minFraction = if (totalPx > 0f) minPanePx / totalPx else 0f
|
||||||
val lowerBound = (if (index == 0) 0f else livePositions[index - 1]) + minFraction
|
val lowerBound = (if (index == 0) 0f else livePositions[index - 1]) + minFraction
|
||||||
val upperBound = (if (index == dividerCount - 1) 1f else livePositions[index + 1]) - minFraction
|
val upperBound = (if (index == dividerCount - 1) 1f else livePositions[index + 1]) - minFraction
|
||||||
@@ -64,18 +82,71 @@ class SplitterState(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** The pane lengths for a given splitter length; they always add up to the whole. */
|
/** The pane lengths for a given splitter length; they always add up to the whole. */
|
||||||
fun paneSizes(totalPx: Float): List<Float> {
|
fun paneSizes(totalPx: Float, minimumPaneSizesPx: FloatArray = EMPTY_MINIMUMS): List<Float> {
|
||||||
if (paneCount <= 1) return listOf(totalPx)
|
if (paneCount <= 1) return listOf(totalPx)
|
||||||
val edges = buildList {
|
val edges = buildList {
|
||||||
add(0f)
|
add(0f)
|
||||||
livePositions.forEach { add(it * totalPx) }
|
effectiveDividerPositions(totalPx, minimumPaneSizesPx).forEach { add(it) }
|
||||||
add(totalPx)
|
add(totalPx)
|
||||||
}
|
}
|
||||||
return (0 until paneCount).map { edges[it + 1] - edges[it] }
|
return (0 until paneCount).map { edges[it + 1] - edges[it] }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The position the pointer sees after pane-specific minimums have been applied. */
|
||||||
|
internal fun dividerPosition(
|
||||||
|
index: Int,
|
||||||
|
totalPx: Float,
|
||||||
|
minimumPaneSizesPx: FloatArray = EMPTY_MINIMUMS,
|
||||||
|
): Float = effectiveDividerPositions(totalPx, minimumPaneSizesPx)
|
||||||
|
.getOrElse(index) { 0f } / totalPx.coerceAtLeast(1f)
|
||||||
|
|
||||||
|
private fun effectiveDividerPositions(
|
||||||
|
totalPx: Float,
|
||||||
|
minimumPaneSizesPx: FloatArray,
|
||||||
|
): FloatArray {
|
||||||
|
if (minimumPaneSizesPx.isEmpty()) {
|
||||||
|
return FloatArray(dividerCount) { index -> livePositions[index] * totalPx }
|
||||||
|
}
|
||||||
|
|
||||||
|
val minimums = scaledMinimums(totalPx, minimumPaneSizesPx)
|
||||||
|
val effective = FloatArray(dividerCount)
|
||||||
|
var previous = 0f
|
||||||
|
repeat(dividerCount) { index ->
|
||||||
|
val lowerBound = previous + minimums[index]
|
||||||
|
var trailingMinimum = 0f
|
||||||
|
for (remainingIndex in index + 1 until paneCount) {
|
||||||
|
trailingMinimum += minimums[remainingIndex]
|
||||||
|
}
|
||||||
|
val upperBound = totalPx - trailingMinimum
|
||||||
|
val wanted = livePositions[index] * totalPx
|
||||||
|
// Scaling impossible minimums can leave the two bounds a few float ULPs
|
||||||
|
// apart. Treat that rounding-only empty range like drag() does instead of
|
||||||
|
// letting coerceIn throw during layout.
|
||||||
|
val position = if (lowerBound > upperBound) {
|
||||||
|
(lowerBound + upperBound) / 2f
|
||||||
|
} else {
|
||||||
|
wanted.coerceIn(lowerBound, upperBound)
|
||||||
|
}
|
||||||
|
effective[index] = position
|
||||||
|
previous = position
|
||||||
|
}
|
||||||
|
return effective
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun scaledMinimums(totalPx: Float, minimumPaneSizesPx: FloatArray): FloatArray {
|
||||||
|
val minimums = FloatArray(paneCount) { index ->
|
||||||
|
minimumPaneSizesPx.getOrNull(index)?.coerceAtLeast(minPanePx) ?: minPanePx
|
||||||
|
}
|
||||||
|
val sum = minimums.sum()
|
||||||
|
if (sum <= totalPx || sum <= 0f) return minimums
|
||||||
|
val scale = totalPx.coerceAtLeast(0f) / sum
|
||||||
|
return FloatArray(paneCount) { index -> minimums[index] * scale }
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
private val EMPTY_MINIMUMS = FloatArray(0)
|
||||||
|
|
||||||
/** Enough to still see a table header and grab the divider again. */
|
/** Enough to still see a table header and grab the divider again. */
|
||||||
const val DEFAULT_MIN_PANE_PX = 24f
|
const val DEFAULT_MIN_PANE_PX = 24f
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,14 @@ object StationColumns {
|
|||||||
formatBand: (ChatMember, kst4contest.model.Band, Boolean) -> String,
|
formatBand: (ChatMember, kst4contest.model.Band, Boolean) -> String,
|
||||||
activeBands: EnumSet<kst4contest.model.Band> = EnumSet.allOf(kst4contest.model.Band::class.java),
|
activeBands: EnumSet<kst4contest.model.Band> = EnumSet.allOf(kst4contest.model.Band::class.java),
|
||||||
): List<DataColumn<ChatMember>> = buildList {
|
): List<DataColumn<ChatMember>> = buildList {
|
||||||
add(DataColumn(id = "callsign", title = { kst4contest.view.i18n.CurrentStrings.get().columnCallsign }, value = { it.callSign.orEmpty() }))
|
add(DataColumn(
|
||||||
|
id = "callsign",
|
||||||
|
title = { kst4contest.view.i18n.CurrentStrings.get().columnCallsign },
|
||||||
|
value = { it.callSign.orEmpty() },
|
||||||
|
comparator = compareBy(String.CASE_INSENSITIVE_ORDER) { member: ChatMember ->
|
||||||
|
member.callSign?.trim().orEmpty()
|
||||||
|
},
|
||||||
|
))
|
||||||
add(DataColumn(id = "name", title = { kst4contest.view.i18n.CurrentStrings.get().columnName }, value = { it.name.orEmpty() }))
|
add(DataColumn(id = "name", title = { kst4contest.view.i18n.CurrentStrings.get().columnName }, value = { it.name.orEmpty() }))
|
||||||
add(DataColumn(id = "qra", title = "QRA", value = { it.qra.orEmpty() }, weight = 0.8f))
|
add(DataColumn(id = "qra", title = "QRA", value = { it.qra.orEmpty() }, weight = 0.8f))
|
||||||
add(DataColumn(
|
add(DataColumn(
|
||||||
|
|||||||
@@ -0,0 +1,314 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.heightIn
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.widthIn
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.HorizontalDivider
|
||||||
|
import androidx.compose.material3.LocalMinimumInteractiveComponentSize
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.MenuDefaults
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.testTag
|
||||||
|
import androidx.compose.ui.unit.Dp
|
||||||
|
import androidx.compose.ui.unit.IntOffset
|
||||||
|
import androidx.compose.ui.unit.IntRect
|
||||||
|
import androidx.compose.ui.unit.IntSize
|
||||||
|
import androidx.compose.ui.unit.LayoutDirection
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.window.Popup
|
||||||
|
import androidx.compose.ui.window.PopupPositionProvider
|
||||||
|
import androidx.compose.ui.window.PopupProperties
|
||||||
|
import kst4contest.model.Band
|
||||||
|
import kst4contest.model.ChatMember
|
||||||
|
import kst4contest.view.i18n.LocalStrings
|
||||||
|
|
||||||
|
internal const val STATION_CONTEXT_MENU_TAG = "station-context-menu"
|
||||||
|
internal const val STATION_CONTEXT_TARGET_CHOOSER_TAG = "station-context-target-chooser"
|
||||||
|
internal const val STATION_SKED_POPUP_TAG = "station-sked-popup"
|
||||||
|
|
||||||
|
private enum class StationContextPage {
|
||||||
|
ROOT,
|
||||||
|
SNIPPETS,
|
||||||
|
NOT_QRV,
|
||||||
|
WORKED,
|
||||||
|
REACHABILITY,
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Shared station action popup used by the user list and the map. */
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun StationContextOverlays(
|
||||||
|
menuState: StationContextMenuState,
|
||||||
|
mainWindowState: MainWindowState,
|
||||||
|
onShowMap: (() -> Unit)? = null,
|
||||||
|
) {
|
||||||
|
val strings = LocalStrings.current
|
||||||
|
var page by remember { mutableStateOf(StationContextPage.ROOT) }
|
||||||
|
var skedDraft by remember { mutableStateOf<SkedEditorState?>(null) }
|
||||||
|
var skedPosition by remember { mutableStateOf(IntOffset.Zero) }
|
||||||
|
|
||||||
|
LaunchedEffect(menuState.candidates, menuState.target) {
|
||||||
|
page = StationContextPage.ROOT
|
||||||
|
}
|
||||||
|
|
||||||
|
if (menuState.isOpen) {
|
||||||
|
Popup(
|
||||||
|
popupPositionProvider = WindowPointPopupPositionProvider(menuState.position),
|
||||||
|
onDismissRequest = menuState::close,
|
||||||
|
properties = PopupProperties(focusable = true),
|
||||||
|
) {
|
||||||
|
Surface(
|
||||||
|
modifier = Modifier.testTag(STATION_CONTEXT_MENU_TAG),
|
||||||
|
shape = MenuDefaults.shape,
|
||||||
|
color = MenuDefaults.containerColor,
|
||||||
|
tonalElevation = MenuDefaults.TonalElevation,
|
||||||
|
shadowElevation = MenuDefaults.ShadowElevation,
|
||||||
|
) {
|
||||||
|
CompositionLocalProvider(LocalMinimumInteractiveComponentSize provides Dp.Unspecified) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.widthIn(min = 190.dp, max = 360.dp)
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(vertical = 4.dp),
|
||||||
|
) {
|
||||||
|
val target = menuState.target
|
||||||
|
if (target == null) {
|
||||||
|
ContextHeading(
|
||||||
|
strings.contextChooseStation,
|
||||||
|
Modifier.testTag(STATION_CONTEXT_TARGET_CHOOSER_TAG),
|
||||||
|
)
|
||||||
|
menuState.candidates.forEach { candidate ->
|
||||||
|
ContextItem(stationContextTargetLabel(candidate)) {
|
||||||
|
menuState.chooseTarget(candidate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
when (page) {
|
||||||
|
StationContextPage.ROOT -> {
|
||||||
|
ContextSubmenu(strings.contextMessageSnippets) {
|
||||||
|
page = StationContextPage.SNIPPETS
|
||||||
|
}
|
||||||
|
ContextItem(strings.contextCreateSked) {
|
||||||
|
skedPosition = menuState.position
|
||||||
|
skedDraft = mainWindowState.selectedStation.createSkedDraft(target)
|
||||||
|
menuState.close()
|
||||||
|
}
|
||||||
|
ContextSeparator()
|
||||||
|
ContextSubmenu(strings.contextTagNotQrv) {
|
||||||
|
page = StationContextPage.NOT_QRV
|
||||||
|
}
|
||||||
|
ContextSubmenu(strings.contextMarkWorked) {
|
||||||
|
page = StationContextPage.WORKED
|
||||||
|
}
|
||||||
|
ContextSeparator()
|
||||||
|
ContextSubmenu(strings.contextCalculateReachability) {
|
||||||
|
page = StationContextPage.REACHABILITY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StationContextPage.SNIPPETS -> {
|
||||||
|
ContextBack { page = StationContextPage.ROOT }
|
||||||
|
mainWindowState.snippets.entries.forEach { snippet ->
|
||||||
|
ContextItem(snippet) {
|
||||||
|
mainWindowState.chatInput.appendSnippet(snippet)
|
||||||
|
menuState.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StationContextPage.NOT_QRV -> {
|
||||||
|
ContextBack { page = StationContextPage.ROOT }
|
||||||
|
NotQrvBand.entries
|
||||||
|
.filter { it.band in mainWindowState.activeBands }
|
||||||
|
.forEach { band ->
|
||||||
|
val tagged = mainWindowState.selectedStation
|
||||||
|
.isTaggedNotQrv(target, band)
|
||||||
|
ContextCheckItem(band.label, tagged) {
|
||||||
|
mainWindowState.selectedStation
|
||||||
|
.tagNotQrv(target, band, !tagged)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StationContextPage.WORKED -> {
|
||||||
|
ContextBack { page = StationContextPage.ROOT }
|
||||||
|
mainWindowState.activeBands.sortedBy(Band::ordinal).forEach { band ->
|
||||||
|
val worked = target.isWorkedOn(band)
|
||||||
|
ContextCheckItem(band.displayLabel, worked, enabled = !worked) {
|
||||||
|
if (mainWindowState.markStationWorked?.invoke(target, band) == true) {
|
||||||
|
menuState.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StationContextPage.REACHABILITY -> {
|
||||||
|
ContextBack { page = StationContextPage.ROOT }
|
||||||
|
mainWindowState.activeBands.sortedBy(Band::ordinal).forEach { band ->
|
||||||
|
ContextItem(band.displayLabel) {
|
||||||
|
if (mainWindowState.mapReachability.calculate(target, band)) {
|
||||||
|
onShowMap?.invoke()
|
||||||
|
menuState.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
skedDraft?.let { draft ->
|
||||||
|
Popup(
|
||||||
|
popupPositionProvider = WindowPointPopupPositionProvider(skedPosition),
|
||||||
|
onDismissRequest = { skedDraft = null },
|
||||||
|
properties = PopupProperties(focusable = true),
|
||||||
|
) {
|
||||||
|
Surface(
|
||||||
|
modifier = Modifier
|
||||||
|
.widthIn(min = 420.dp, max = 560.dp)
|
||||||
|
.testTag(STATION_SKED_POPUP_TAG),
|
||||||
|
shape = MaterialTheme.shapes.small,
|
||||||
|
color = MaterialTheme.colorScheme.surface,
|
||||||
|
tonalElevation = 4.dp,
|
||||||
|
shadowElevation = 8.dp,
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.padding(8.dp),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
strings.contextSkedTitle(draft.target.callSign.orEmpty()),
|
||||||
|
style = MaterialTheme.typography.titleSmall,
|
||||||
|
modifier = Modifier.padding(bottom = 4.dp),
|
||||||
|
)
|
||||||
|
SkedEditorControls(
|
||||||
|
activeBands = mainWindowState.activeBands,
|
||||||
|
minutes = draft.minutes,
|
||||||
|
onMinutesChanged = { draft.minutes = it },
|
||||||
|
band = draft.band,
|
||||||
|
onBandChanged = { draft.band = it },
|
||||||
|
mode = draft.mode,
|
||||||
|
onModeChanged = { draft.mode = it },
|
||||||
|
remindPm = draft.remindPm,
|
||||||
|
onRemindPmChanged = { draft.remindPm = it },
|
||||||
|
reminderOffsets = draft.reminderOffsets,
|
||||||
|
onReminderOffsetsChanged = { draft.reminderOffsets = it },
|
||||||
|
canCreate = draft.band != null,
|
||||||
|
onCreate = {
|
||||||
|
if (draft.submit()) skedDraft = null
|
||||||
|
},
|
||||||
|
additionalActions = {
|
||||||
|
Form.button(strings.contextCancel) { skedDraft = null }
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun ContextHeading(text: String, modifier: Modifier = Modifier) {
|
||||||
|
Text(
|
||||||
|
text = text,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
modifier = modifier.fillMaxWidth().padding(horizontal = 8.dp, vertical = 4.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun ContextBack(onClick: () -> Unit) {
|
||||||
|
val strings = LocalStrings.current
|
||||||
|
ContextItem("‹ ${strings.contextBack}", onClick = onClick)
|
||||||
|
ContextSeparator()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun ContextSubmenu(text: String, onClick: () -> Unit) {
|
||||||
|
ContextItem("$text ›", onClick = onClick)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun ContextCheckItem(
|
||||||
|
text: String,
|
||||||
|
checked: Boolean,
|
||||||
|
enabled: Boolean = true,
|
||||||
|
onClick: () -> Unit,
|
||||||
|
) {
|
||||||
|
ContextItem((if (checked) "✓ " else " ") + text, enabled, onClick)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun ContextItem(text: String, enabled: Boolean = true, onClick: () -> Unit) {
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = { Text(text, style = compactControlTextStyle(), maxLines = 1) },
|
||||||
|
enabled = enabled,
|
||||||
|
onClick = onClick,
|
||||||
|
contentPadding = PaddingValues(horizontal = 8.dp),
|
||||||
|
modifier = Modifier.heightIn(min = Density.CONTROL_HEIGHT),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun ContextSeparator() {
|
||||||
|
HorizontalDivider(
|
||||||
|
thickness = Density.HAIRLINE,
|
||||||
|
color = MaterialTheme.colorScheme.outlineVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun stationContextTargetLabel(member: ChatMember): String {
|
||||||
|
val category = member.chatCategory
|
||||||
|
val categoryName = category?.getChatCategoryName(category.categoryNumber)
|
||||||
|
?.takeIf { it.isNotBlank() }
|
||||||
|
?: category?.categoryNumber?.toString().orEmpty()
|
||||||
|
return if (categoryName.isBlank()) member.callSign.orEmpty()
|
||||||
|
else "${member.callSign.orEmpty()} | $categoryName"
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun ChatMember.isWorkedOn(band: Band): Boolean = when (band) {
|
||||||
|
Band.B_50 -> isWorked50
|
||||||
|
Band.B_70 -> isWorked70
|
||||||
|
Band.B_144 -> isWorked144
|
||||||
|
Band.B_432 -> isWorked432
|
||||||
|
Band.B_1296 -> isWorked1240
|
||||||
|
Band.B_2320 -> isWorked2300
|
||||||
|
Band.B_3400 -> isWorked3400
|
||||||
|
Band.B_5760 -> isWorked5600
|
||||||
|
Band.B_10G -> isWorked10G
|
||||||
|
Band.B_24G -> isWorked24G
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Window-relative popup position clamped to the visible window on every DPI scale. */
|
||||||
|
internal data class WindowPointPopupPositionProvider(
|
||||||
|
val point: IntOffset,
|
||||||
|
) : PopupPositionProvider {
|
||||||
|
override fun calculatePosition(
|
||||||
|
anchorBounds: IntRect,
|
||||||
|
windowSize: IntSize,
|
||||||
|
layoutDirection: LayoutDirection,
|
||||||
|
popupContentSize: IntSize,
|
||||||
|
): IntOffset = IntOffset(
|
||||||
|
x = point.x.coerceIn(0, maxOf(0, windowSize.width - popupContentSize.width)),
|
||||||
|
y = point.y.coerceIn(0, maxOf(0, windowSize.height - popupContentSize.height)),
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.unit.IntOffset
|
||||||
|
import kst4contest.model.ChatMember
|
||||||
|
|
||||||
|
/** Current target and window-relative anchor of a station context menu. */
|
||||||
|
class StationContextMenuState(
|
||||||
|
private val selectStation: (ChatMember, StationSelectionSource) -> Unit,
|
||||||
|
) {
|
||||||
|
var position: IntOffset by mutableStateOf(IntOffset.Zero)
|
||||||
|
private set
|
||||||
|
|
||||||
|
var candidates: List<ChatMember> by mutableStateOf(emptyList())
|
||||||
|
private set
|
||||||
|
|
||||||
|
var target: ChatMember? by mutableStateOf(null)
|
||||||
|
private set
|
||||||
|
|
||||||
|
var source: StationSelectionSource by mutableStateOf(StationSelectionSource.PROGRAMMATIC)
|
||||||
|
private set
|
||||||
|
|
||||||
|
val isOpen: Boolean
|
||||||
|
get() = candidates.isNotEmpty()
|
||||||
|
|
||||||
|
fun open(
|
||||||
|
members: List<ChatMember>,
|
||||||
|
source: StationSelectionSource,
|
||||||
|
position: IntOffset,
|
||||||
|
) {
|
||||||
|
val unique = members
|
||||||
|
.filter { StationIdentity.of(it) != null }
|
||||||
|
.distinctBy(StationIdentity::of)
|
||||||
|
if (unique.isEmpty()) {
|
||||||
|
close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.position = position
|
||||||
|
this.source = source
|
||||||
|
candidates = unique
|
||||||
|
target = unique.singleOrNull()
|
||||||
|
target?.let { selectStation(it, source) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun chooseTarget(member: ChatMember) {
|
||||||
|
val identity = StationIdentity.of(member) ?: return
|
||||||
|
val resolved = candidates.firstOrNull { StationIdentity.of(it) == identity } ?: return
|
||||||
|
target = resolved
|
||||||
|
selectStation(resolved, source)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun close() {
|
||||||
|
candidates = emptyList()
|
||||||
|
target = null
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,49 +3,53 @@ package kst4contest.view.compose
|
|||||||
import kst4contest.view.i18n.LocalStrings
|
import kst4contest.view.i18n.LocalStrings
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.border
|
import androidx.compose.foundation.border
|
||||||
import androidx.compose.foundation.clickable
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
||||||
import androidx.compose.foundation.layout.FlowRow
|
import androidx.compose.foundation.layout.FlowRow
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxHeight
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.layout.heightIn
|
|
||||||
import androidx.compose.foundation.layout.IntrinsicSize
|
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.text.BasicTextField
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.platform.testTag
|
||||||
import androidx.compose.ui.graphics.luminance
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
|
internal const val FILTER_DISTANCE_GROUP_TAG = "filter-distance-group"
|
||||||
|
internal const val FILTER_DIRECTION_GROUP_TAG = "filter-direction-group"
|
||||||
|
internal const val FILTER_STATION_GROUP_TAG = "filter-station-group"
|
||||||
|
internal const val FILTER_WORKED_GROUP_TAG = "filter-worked-group"
|
||||||
|
internal const val FILTER_PROPAGATION_GROUP_TAG = "filter-propagation-group"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The station filter bar above the station table.
|
* The station filter bar above the station table.
|
||||||
*
|
*
|
||||||
* Laid out to match the JavaFX original: three tight rows of controls separated
|
* Compact surfaces keep related filters together while the outer flow rows still wrap
|
||||||
* by thin vertical rules between logical groups.
|
* against the station panel's actual width.
|
||||||
*/
|
*/
|
||||||
@OptIn(ExperimentalLayoutApi::class)
|
@OptIn(ExperimentalLayoutApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun StationFilterBar(
|
fun StationFilterBar(
|
||||||
filters: StationFilterState,
|
filters: StationFilterState,
|
||||||
activeBands: Set<kst4contest.model.Band>,
|
activeBands: Set<kst4contest.model.Band>,
|
||||||
|
reachability: ReachabilityState,
|
||||||
onChanged: () -> Unit,
|
onChanged: () -> Unit,
|
||||||
|
onQtfDirectionChanged: (Double) -> Unit = {},
|
||||||
|
onReset: (() -> Unit)? = null,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
val strings = LocalStrings.current
|
val strings = LocalStrings.current
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = modifier.fillMaxWidth().padding(horizontal = 2.dp, vertical = 1.dp),
|
modifier = modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.background(MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.18f))
|
||||||
|
.border(Density.HAIRLINE, MaterialTheme.colorScheme.outlineVariant)
|
||||||
|
.padding(horizontal = 2.dp, vertical = 1.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(1.dp),
|
verticalArrangement = Arrangement.spacedBy(1.dp),
|
||||||
) {
|
) {
|
||||||
/*
|
/*
|
||||||
@@ -61,121 +65,6 @@ fun StationFilterBar(
|
|||||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(1.dp),
|
verticalArrangement = Arrangement.spacedBy(1.dp),
|
||||||
itemVerticalAlignment = Alignment.CenterVertically,
|
itemVerticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
|
||||||
// Reset filters
|
|
||||||
FilterButton(strings.filterReset, on = false, isAccent = true) {
|
|
||||||
filters.reset()
|
|
||||||
onChanged()
|
|
||||||
}
|
|
||||||
|
|
||||||
// QRB maximum + minimum (#21): together they make a range, so they stay one group
|
|
||||||
FilterGroup {
|
|
||||||
GroupSeparator()
|
|
||||||
FlowRow(
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(1.dp),
|
|
||||||
itemVerticalAlignment = Alignment.CenterVertically,
|
|
||||||
) {
|
|
||||||
FilterGroup {
|
|
||||||
CompactCheckbox(
|
|
||||||
checked = filters.maxQrbEnabled,
|
|
||||||
onCheckedChange = {
|
|
||||||
filters.maxQrbEnabled = it
|
|
||||||
onChanged()
|
|
||||||
},
|
|
||||||
)
|
|
||||||
Text(strings.filterShowOnlyQrb, style = MaterialTheme.typography.bodySmall)
|
|
||||||
CompactTextField(
|
|
||||||
value = if (filters.maxQrbKm.rem(1) == 0.0) filters.maxQrbKm.toInt().toString() else filters.maxQrbKm.toString(),
|
|
||||||
onValueChange = {
|
|
||||||
val parsed = parseQrbKm(it)
|
|
||||||
if (parsed != null) {
|
|
||||||
filters.maxQrbKm = parsed
|
|
||||||
if (filters.maxQrbEnabled) onChanged()
|
|
||||||
} else if (it.isEmpty()) {
|
|
||||||
filters.maxQrbKm = 0.0
|
|
||||||
if (filters.maxQrbEnabled) onChanged()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modifier = Modifier.width(50.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
FilterGroup {
|
|
||||||
CompactCheckbox(
|
|
||||||
checked = filters.minQrbEnabled,
|
|
||||||
onCheckedChange = {
|
|
||||||
filters.minQrbEnabled = it
|
|
||||||
onChanged()
|
|
||||||
},
|
|
||||||
)
|
|
||||||
Text(strings.filterShowOnlyQrbAbove, style = MaterialTheme.typography.bodySmall)
|
|
||||||
CompactTextField(
|
|
||||||
value = if (filters.minQrbKm.rem(1) == 0.0) filters.minQrbKm.toInt().toString() else filters.minQrbKm.toString(),
|
|
||||||
onValueChange = {
|
|
||||||
val parsed = parseQrbKm(it)
|
|
||||||
if (parsed != null) {
|
|
||||||
filters.minQrbKm = parsed
|
|
||||||
if (filters.minQrbEnabled) onChanged()
|
|
||||||
} else if (it.isEmpty()) {
|
|
||||||
filters.minQrbKm = 0.0
|
|
||||||
if (filters.minQrbEnabled) onChanged()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modifier = Modifier.width(50.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// QTF checkbox + field
|
|
||||||
FilterGroup {
|
|
||||||
GroupSeparator()
|
|
||||||
CompactCheckbox(
|
|
||||||
checked = filters.qtfEnabled,
|
|
||||||
onCheckedChange = {
|
|
||||||
filters.qtfEnabled = it
|
|
||||||
onChanged()
|
|
||||||
},
|
|
||||||
)
|
|
||||||
Text(strings.filterShowOnlyQtf, style = MaterialTheme.typography.bodySmall)
|
|
||||||
CompactTextField(
|
|
||||||
value = if (filters.qtfDegrees.rem(1) == 0.0) filters.qtfDegrees.toInt().toString() else filters.qtfDegrees.toString(),
|
|
||||||
onValueChange = {
|
|
||||||
val parsed = it.toDoubleOrNull()
|
|
||||||
if (parsed != null) {
|
|
||||||
filters.qtfDegrees = parsed
|
|
||||||
filters.bearing = null
|
|
||||||
if (filters.qtfEnabled) onChanged()
|
|
||||||
} else if (it.isEmpty()) {
|
|
||||||
filters.qtfDegrees = 0.0
|
|
||||||
filters.bearing = null
|
|
||||||
if (filters.qtfEnabled) onChanged()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modifier = Modifier.width(50.dp)
|
|
||||||
)
|
|
||||||
Text("± BW/2", style = MaterialTheme.typography.bodySmall)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bearings
|
|
||||||
FlowRow(
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(1.dp),
|
|
||||||
) {
|
|
||||||
Bearing.entries.forEach { bearing ->
|
|
||||||
FilterButton(bearing.name, on = filters.bearing == bearing) {
|
|
||||||
filters.toggleBearing(bearing)
|
|
||||||
onChanged()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ROW 2: Find | Hide worked: wkd 50 70 144 432 | Inactive stations | Only new grids
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth().height(IntrinsicSize.Min),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
) {
|
) {
|
||||||
CompactTextField(
|
CompactTextField(
|
||||||
value = filters.searchText,
|
value = filters.searchText,
|
||||||
@@ -187,100 +76,225 @@ fun StationFilterBar(
|
|||||||
modifier = Modifier.width(90.dp),
|
modifier = Modifier.width(90.dp),
|
||||||
)
|
)
|
||||||
|
|
||||||
VerticalSeparator()
|
// Reset filters
|
||||||
|
FilterButton(strings.filterReset, on = false, isAccent = true) {
|
||||||
Text(strings.filterHideWorked, style = MaterialTheme.typography.bodySmall)
|
if (onReset != null) {
|
||||||
FilterButton("wkdany", on = filters.hideWorkedAny) {
|
onReset()
|
||||||
filters.hideWorkedAny = !filters.hideWorkedAny
|
} else {
|
||||||
onChanged()
|
filters.reset()
|
||||||
|
onChanged()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
WorkedBandFilter.entries.forEach { band ->
|
|
||||||
if (band.modelBand in activeBands) {
|
// Distance and bearing-width controls form one functional surface.
|
||||||
FilterButton(band.label, on = filters.isHideWorkedOn(band)) {
|
FilterGroupSurface(FILTER_DISTANCE_GROUP_TAG) {
|
||||||
filters.setHideWorkedOn(band, !filters.isHideWorkedOn(band))
|
FilterGroup {
|
||||||
onChanged()
|
FlowRow(
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(1.dp),
|
||||||
|
itemVerticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
FilterGroup {
|
||||||
|
CompactCheckbox(
|
||||||
|
checked = filters.maxQrbEnabled,
|
||||||
|
onCheckedChange = {
|
||||||
|
filters.maxQrbEnabled = it
|
||||||
|
onChanged()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
Text(strings.filterShowOnlyQrb, style = compactControlTextStyle())
|
||||||
|
CompactTextField(
|
||||||
|
value = if (filters.maxQrbKm.rem(1) == 0.0) {
|
||||||
|
filters.maxQrbKm.toInt().toString()
|
||||||
|
} else {
|
||||||
|
filters.maxQrbKm.toString()
|
||||||
|
},
|
||||||
|
onValueChange = {
|
||||||
|
val parsed = parseQrbKm(it)
|
||||||
|
if (parsed != null) {
|
||||||
|
filters.maxQrbKm = parsed
|
||||||
|
if (filters.maxQrbEnabled) onChanged()
|
||||||
|
} else if (it.isEmpty()) {
|
||||||
|
filters.maxQrbKm = 0.0
|
||||||
|
if (filters.maxQrbEnabled) onChanged()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modifier = Modifier.width(50.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
FilterGroup {
|
||||||
|
CompactCheckbox(
|
||||||
|
checked = filters.minQrbEnabled,
|
||||||
|
onCheckedChange = {
|
||||||
|
filters.minQrbEnabled = it
|
||||||
|
onChanged()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
Text(strings.filterShowOnlyQrbAbove, style = compactControlTextStyle())
|
||||||
|
CompactTextField(
|
||||||
|
value = if (filters.minQrbKm.rem(1) == 0.0) {
|
||||||
|
filters.minQrbKm.toInt().toString()
|
||||||
|
} else {
|
||||||
|
filters.minQrbKm.toString()
|
||||||
|
},
|
||||||
|
onValueChange = {
|
||||||
|
val parsed = parseQrbKm(it)
|
||||||
|
if (parsed != null) {
|
||||||
|
filters.minQrbKm = parsed
|
||||||
|
if (filters.minQrbEnabled) onChanged()
|
||||||
|
} else if (it.isEmpty()) {
|
||||||
|
filters.minQrbKm = 0.0
|
||||||
|
if (filters.minQrbEnabled) onChanged()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modifier = Modifier.width(50.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VerticalSeparator()
|
FilterGroupSurface(FILTER_DIRECTION_GROUP_TAG) {
|
||||||
|
FilterGroup {
|
||||||
|
CompactCheckbox(
|
||||||
|
checked = filters.qtfEnabled,
|
||||||
|
onCheckedChange = {
|
||||||
|
filters.qtfEnabled = it
|
||||||
|
onChanged()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
Text(strings.filterShowOnlyQtf, style = compactControlTextStyle())
|
||||||
|
CompactTextField(
|
||||||
|
value = if (filters.qtfDegrees.rem(1) == 0.0) {
|
||||||
|
filters.qtfDegrees.toInt().toString()
|
||||||
|
} else {
|
||||||
|
filters.qtfDegrees.toString()
|
||||||
|
},
|
||||||
|
onValueChange = {
|
||||||
|
val parsed = parseQtfDegrees(it)
|
||||||
|
if (parsed != null) {
|
||||||
|
filters.qtfDegrees = parsed
|
||||||
|
filters.bearing = null
|
||||||
|
onQtfDirectionChanged(parsed)
|
||||||
|
if (filters.qtfEnabled) onChanged()
|
||||||
|
} else if (it.isEmpty()) {
|
||||||
|
filters.qtfDegrees = 0.0
|
||||||
|
filters.bearing = null
|
||||||
|
if (filters.qtfEnabled) onChanged()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modifier = Modifier.width(50.dp),
|
||||||
|
)
|
||||||
|
Text("± BW/2", style = compactControlTextStyle())
|
||||||
|
}
|
||||||
|
|
||||||
FilterButton(strings.filterInactiveStations, on = filters.hideInactive) {
|
FlowRow(
|
||||||
filters.hideInactive = !filters.hideInactive
|
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||||
onChanged()
|
verticalArrangement = Arrangement.spacedBy(1.dp),
|
||||||
|
) {
|
||||||
|
Bearing.entries.forEach { bearing ->
|
||||||
|
FilterButton(
|
||||||
|
bearing.name,
|
||||||
|
on = filters.bearing == bearing,
|
||||||
|
modifier = Modifier.width(Density.DIRECTION_BUTTON_WIDTH),
|
||||||
|
horizontalPadding = Density.DIRECTION_BUTTON_HORIZONTAL_PADDING,
|
||||||
|
) {
|
||||||
|
filters.toggleBearing(bearing)
|
||||||
|
if (filters.bearing == bearing) {
|
||||||
|
onQtfDirectionChanged(bearing.degrees)
|
||||||
|
}
|
||||||
|
onChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
FilterButton(strings.filterOnlyNewGrids, on = filters.onlyNewGrids) {
|
|
||||||
filters.onlyNewGrids = !filters.onlyNewGrids
|
|
||||||
onChanged()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ROW 3: Grid color | Tropo | New bands | AS next 5m
|
FilterGroupSurface(FILTER_STATION_GROUP_TAG) {
|
||||||
Row(
|
Text(strings.filterHide, style = compactControlTextStyle())
|
||||||
modifier = Modifier.fillMaxWidth().height(IntrinsicSize.Min),
|
FilterButton("wkdany", on = filters.hideWorkedAny) {
|
||||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
filters.hideWorkedAny = !filters.hideWorkedAny
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
onChanged()
|
||||||
) {
|
}
|
||||||
FilterButton(strings.filterGridColour, on = filters.gridColouring) {
|
WorkedBandFilter.entries.forEach { band ->
|
||||||
filters.gridColouring = !filters.gridColouring
|
if (band.modelBand in activeBands) {
|
||||||
|
FilterButton(band.label, on = filters.isHideWorkedOn(band)) {
|
||||||
|
filters.setHideWorkedOn(band, !filters.isHideWorkedOn(band))
|
||||||
|
onChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FilterButton(strings.filterInactiveStations, on = filters.hideInactive) {
|
||||||
|
filters.hideInactive = !filters.hideInactive
|
||||||
|
onChanged()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
FilterButton(strings.filterTropo, on = filters.tropoReachable) {
|
|
||||||
filters.tropoReachable = !filters.tropoReachable
|
FilterGroupSurface(FILTER_WORKED_GROUP_TAG) {
|
||||||
onChanged()
|
Text(strings.filterShow, style = compactControlTextStyle())
|
||||||
|
FilterButton(strings.filterOnlyNewGrids, on = filters.onlyNewGrids) {
|
||||||
|
filters.onlyNewGrids = !filters.onlyNewGrids
|
||||||
|
onChanged()
|
||||||
|
}
|
||||||
|
FilterButton(strings.filterGridColour, on = filters.gridColouring) {
|
||||||
|
filters.gridColouring = !filters.gridColouring
|
||||||
|
}
|
||||||
|
FilterButton(strings.filterTropo, on = filters.tropoReachable) {
|
||||||
|
filters.tropoReachable = !filters.tropoReachable
|
||||||
|
onChanged()
|
||||||
|
}
|
||||||
|
FilterButton(strings.filterNewBands, on = filters.newBands) {
|
||||||
|
filters.newBands = !filters.newBands
|
||||||
|
onChanged()
|
||||||
|
}
|
||||||
|
FilterButton("AS next 5m", on = filters.airScoutNext5Min) {
|
||||||
|
filters.airScoutNext5Min = !filters.airScoutNext5Min
|
||||||
|
onChanged()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
FilterButton(strings.filterNewBands, on = filters.newBands) {
|
|
||||||
filters.newBands = !filters.newBands
|
FilterGroupSurface(FILTER_PROPAGATION_GROUP_TAG) {
|
||||||
onChanged()
|
FilterGroup {
|
||||||
}
|
Text(strings.filterReachability, style = compactControlTextStyle())
|
||||||
FilterButton("AS next 5m", on = filters.airScoutNext5Min) {
|
Form.inlineChoice(
|
||||||
filters.airScoutNext5Min = !filters.airScoutNext5Min
|
label = "",
|
||||||
onChanged()
|
items = reachability.options,
|
||||||
|
selected = reachability.selectedOption,
|
||||||
|
describe = ReachabilityBandOption::label,
|
||||||
|
onSelect = { reachability.selectBand(it.band) },
|
||||||
|
)
|
||||||
|
Form.button(
|
||||||
|
text = strings.filterCalcSelected,
|
||||||
|
enabled = reachability.canCalculate,
|
||||||
|
onClick = { reachability.calculateSelected() },
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A compact toggle button that does NOT use Material 3 Button (which enforces 40dp).
|
* A compact toggle using the same interaction states as every other desktop button.
|
||||||
* Instead it is a plain clickable Box with border and background, matching the tiny
|
|
||||||
* JavaFX filter buttons.
|
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
private fun FilterButton(label: String, on: Boolean, isAccent: Boolean = false, onClick: () -> Unit) {
|
private fun FilterButton(
|
||||||
val palette = LocalJavaFxPalette.current
|
label: String,
|
||||||
val isDark = palette.windowBackground.luminance() < 0.5f
|
on: Boolean,
|
||||||
|
isAccent: Boolean = false,
|
||||||
val accentBrush = if (isDark) {
|
enabled: Boolean = true,
|
||||||
androidx.compose.ui.graphics.Brush.linearGradient(
|
modifier: Modifier = Modifier,
|
||||||
colors = listOf(Color(0xFF008000), Color(0xFF90EE90))
|
horizontalPadding: androidx.compose.ui.unit.Dp = 6.dp,
|
||||||
)
|
onClick: () -> Unit,
|
||||||
} else {
|
) {
|
||||||
androidx.compose.ui.graphics.Brush.linearGradient(
|
Form.button(
|
||||||
colors = listOf(Color(0xFF00FFFF), Color(0xFFFF99FF))
|
text = label,
|
||||||
)
|
enabled = enabled,
|
||||||
}
|
accented = isAccent,
|
||||||
|
selected = on,
|
||||||
val bgModifier = if (isAccent) {
|
modifier = modifier,
|
||||||
Modifier.background(accentBrush, Density.BUTTON_SHAPE)
|
horizontalPadding = horizontalPadding,
|
||||||
} else {
|
onClick = onClick,
|
||||||
val bg = if (on) MaterialTheme.colorScheme.primary else Color.Transparent
|
)
|
||||||
Modifier.background(bg, Density.BUTTON_SHAPE)
|
|
||||||
}
|
|
||||||
|
|
||||||
val fg = if (isAccent) Color(0xFF395306) else if (on) MaterialTheme.colorScheme.onPrimary else MaterialTheme.colorScheme.onSurface
|
|
||||||
val borderColor = if (isAccent) Color.Transparent else if (on) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.outline
|
|
||||||
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.heightIn(min = 20.dp)
|
|
||||||
.then(if (borderColor != Color.Transparent) Modifier.border(Density.HAIRLINE, borderColor, Density.BUTTON_SHAPE) else Modifier)
|
|
||||||
.then(bgModifier)
|
|
||||||
.clickable { onClick() }
|
|
||||||
.padding(horizontal = 6.dp, vertical = 2.dp),
|
|
||||||
contentAlignment = Alignment.Center,
|
|
||||||
) {
|
|
||||||
Text(label, style = MaterialTheme.typography.bodySmall, color = fg, maxLines = 1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Controls that belong together and move to the next line of a wrapping row as one. */
|
/** Controls that belong together and move to the next line of a wrapping row as one. */
|
||||||
@@ -294,62 +308,20 @@ private fun FilterGroup(content: @Composable () -> Unit) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** A compact surface that keeps related filters visually and spatially together. */
|
||||||
* The group divider for a wrapping row. A fixed height, because [VerticalSeparator] fills
|
@OptIn(ExperimentalLayoutApi::class)
|
||||||
* the row's intrinsic height, which a line of a flow row does not offer.
|
|
||||||
*/
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun GroupSeparator() {
|
private fun FilterGroupSurface(tag: String, content: @Composable () -> Unit) {
|
||||||
Box(
|
FlowRow(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.width(Density.HAIRLINE)
|
.testTag(tag)
|
||||||
.height(18.dp)
|
.background(MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.42f))
|
||||||
.background(MaterialTheme.colorScheme.outline),
|
.border(Density.HAIRLINE, MaterialTheme.colorScheme.outlineVariant, Density.BUTTON_SHAPE)
|
||||||
)
|
.padding(2.dp),
|
||||||
}
|
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||||
/** Thin vertical separator matching JavaFX's group dividers. */
|
itemVerticalAlignment = Alignment.CenterVertically,
|
||||||
@Composable
|
) {
|
||||||
private fun VerticalSeparator() {
|
content()
|
||||||
Box(
|
}
|
||||||
modifier = Modifier
|
|
||||||
.width(Density.HAIRLINE)
|
|
||||||
.fillMaxHeight()
|
|
||||||
.background(MaterialTheme.colorScheme.outline),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun CompactTextField(
|
|
||||||
value: String,
|
|
||||||
onValueChange: (String) -> Unit,
|
|
||||||
placeholder: String = "",
|
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
) {
|
|
||||||
BasicTextField(
|
|
||||||
value = value,
|
|
||||||
onValueChange = onValueChange,
|
|
||||||
singleLine = true,
|
|
||||||
textStyle = MaterialTheme.typography.bodySmall.copy(color = MaterialTheme.colorScheme.onSurface),
|
|
||||||
decorationBox = { innerTextField ->
|
|
||||||
Box(
|
|
||||||
modifier = modifier
|
|
||||||
.background(MaterialTheme.colorScheme.surfaceVariant, Density.BUTTON_SHAPE)
|
|
||||||
.border(1.dp, MaterialTheme.colorScheme.outline, Density.BUTTON_SHAPE)
|
|
||||||
.padding(horizontal = 4.dp, vertical = 2.dp),
|
|
||||||
contentAlignment = Alignment.CenterStart,
|
|
||||||
) {
|
|
||||||
if (value.isEmpty() && placeholder.isNotEmpty()) {
|
|
||||||
Text(
|
|
||||||
placeholder,
|
|
||||||
style = MaterialTheme.typography.bodySmall.copy(
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
innerTextField()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
@@ -45,6 +45,10 @@ enum class StationFilter {
|
|||||||
internal fun parseQrbKm(text: String): Double? =
|
internal fun parseQrbKm(text: String): Double? =
|
||||||
text.toDoubleOrNull()?.takeIf { it.isFinite() && it >= 0.0 }
|
text.toDoubleOrNull()?.takeIf { it.isFinite() && it >= 0.0 }
|
||||||
|
|
||||||
|
/** A deliberate antenna/filter heading in the convention used by the QTF display. */
|
||||||
|
internal fun parseQtfDegrees(text: String): Double? =
|
||||||
|
text.toDoubleOrNull()?.takeIf { it.isFinite() && it in 0.0..360.0 }
|
||||||
|
|
||||||
/** The bands the "hide worked" row offers, under the labels the bar shows. */
|
/** The bands the "hide worked" row offers, under the labels the bar shows. */
|
||||||
enum class WorkedBandFilter(val label: String, val filter: StationFilter, val modelBand: kst4contest.model.Band) {
|
enum class WorkedBandFilter(val label: String, val filter: StationFilter, val modelBand: kst4contest.model.Band) {
|
||||||
B_50("50", StationFilter.HIDE_WORKED_50, kst4contest.model.Band.B_50),
|
B_50("50", StationFilter.HIDE_WORKED_50, kst4contest.model.Band.B_50),
|
||||||
|
|||||||
@@ -0,0 +1,151 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import kst4contest.model.ChatMember
|
||||||
|
import kst4contest.model.ChatMessage
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
|
/** Full ON4KST station identity used across tables, messages and the map. */
|
||||||
|
data class StationIdentity(
|
||||||
|
val callSign: String,
|
||||||
|
val categoryNumber: Int?,
|
||||||
|
) {
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
fun of(member: ChatMember?): StationIdentity? =
|
||||||
|
of(member?.callSign, member?.chatCategory?.categoryNumber)
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun of(callSignValue: String?, categoryNumber: Int?): StationIdentity? {
|
||||||
|
val callSign = callSignValue?.trim()?.uppercase(Locale.ROOT).orEmpty()
|
||||||
|
if (callSign.isBlank()) return null
|
||||||
|
|
||||||
|
return StationIdentity(callSign, categoryNumber)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Resolves the station navigated to by a directed-message row click. */
|
||||||
|
object DirectedMessageStationTarget {
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun forMessage(message: ChatMessage?, ownCallSign: String?): StationIdentity? {
|
||||||
|
val senderCallSign = message?.sender?.callSign ?: return null
|
||||||
|
val ownCall = ownCallSign?.trim()?.uppercase(Locale.ROOT).orEmpty()
|
||||||
|
val senderCall = senderCallSign.trim().uppercase(Locale.ROOT)
|
||||||
|
val targetCall = if (senderCall == ownCall) {
|
||||||
|
message.receiver?.callSign ?: receiverFromPayload(message.messageText)
|
||||||
|
} else {
|
||||||
|
senderCallSign
|
||||||
|
}
|
||||||
|
|
||||||
|
return StationIdentity.of(targetCall, message.chatCategory?.categoryNumber)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun receiverFromPayload(messageText: String?): String? {
|
||||||
|
if (messageText == null || !messageText.startsWith('(')) return null
|
||||||
|
val closing = messageText.indexOf(')')
|
||||||
|
return if (closing > 1) messageText.substring(1, closing).trim() else null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Where an explicit station selection came from. */
|
||||||
|
enum class StationSelectionSource {
|
||||||
|
STATION_TABLE,
|
||||||
|
STATION_CONTEXT_MENU,
|
||||||
|
DIRECTED_MESSAGE,
|
||||||
|
PUBLIC_MESSAGE,
|
||||||
|
QSO_OF_THE_OTHER,
|
||||||
|
MAP,
|
||||||
|
MAP_CONTEXT_MENU,
|
||||||
|
PRIORITY,
|
||||||
|
NEW_JOINED,
|
||||||
|
TIMELINE,
|
||||||
|
RESET_VIEW,
|
||||||
|
PROGRAMMATIC,
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Canonical station selection shared by the station table and detail views.
|
||||||
|
*
|
||||||
|
* Data refreshes reconcile the selected instance without moving the table. Explicit
|
||||||
|
* user navigation increments [scrollRequestRevision], even when the identity is the
|
||||||
|
* same as before.
|
||||||
|
*/
|
||||||
|
class StationSelectionState : TableSelectionModel<ChatMember> {
|
||||||
|
|
||||||
|
private var current: ChatMember? by mutableStateOf(null)
|
||||||
|
|
||||||
|
override val selected: ChatMember?
|
||||||
|
get() = current
|
||||||
|
|
||||||
|
override var selectionRevision: Long by mutableStateOf(0L)
|
||||||
|
private set
|
||||||
|
|
||||||
|
override var scrollRequestRevision: Long by mutableStateOf(0L)
|
||||||
|
private set
|
||||||
|
|
||||||
|
var lastSource: StationSelectionSource by mutableStateOf(StationSelectionSource.PROGRAMMATIC)
|
||||||
|
private set
|
||||||
|
|
||||||
|
/** Changes only for deliberate station choices, including repeated choices. */
|
||||||
|
var explicitSelectionRevision: Long by mutableStateOf(0L)
|
||||||
|
private set
|
||||||
|
|
||||||
|
/** Receives deliberate station choices without observing roster reconciliation. */
|
||||||
|
internal var explicitSelectionListener: ((ChatMember?, StationSelectionSource) -> Unit)? = null
|
||||||
|
|
||||||
|
val identity: StationIdentity?
|
||||||
|
get() = StationIdentity.of(current)
|
||||||
|
|
||||||
|
override fun select(row: ChatMember?) {
|
||||||
|
select(row, StationSelectionSource.STATION_TABLE)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun select(row: ChatMember?, source: StationSelectionSource) {
|
||||||
|
current = row
|
||||||
|
lastSource = source
|
||||||
|
selectionRevision++
|
||||||
|
if (source.isExplicitSelection()) {
|
||||||
|
explicitSelectionRevision++
|
||||||
|
explicitSelectionListener?.invoke(row, source)
|
||||||
|
}
|
||||||
|
if (row != null && source.requestsStationTableScroll()) {
|
||||||
|
scrollRequestRevision++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun reconcile(row: ChatMember?) {
|
||||||
|
current = row
|
||||||
|
selectionRevision++
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun requestScroll() {
|
||||||
|
if (current != null) {
|
||||||
|
scrollRequestRevision++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun StationSelectionSource.isExplicitSelection(): Boolean = when (this) {
|
||||||
|
StationSelectionSource.PROGRAMMATIC -> false
|
||||||
|
else -> true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun StationSelectionSource.requestsStationTableScroll(): Boolean = when (this) {
|
||||||
|
StationSelectionSource.STATION_TABLE,
|
||||||
|
StationSelectionSource.STATION_CONTEXT_MENU,
|
||||||
|
StationSelectionSource.RESET_VIEW,
|
||||||
|
StationSelectionSource.PROGRAMMATIC -> false
|
||||||
|
|
||||||
|
StationSelectionSource.DIRECTED_MESSAGE,
|
||||||
|
StationSelectionSource.PUBLIC_MESSAGE,
|
||||||
|
StationSelectionSource.QSO_OF_THE_OTHER,
|
||||||
|
StationSelectionSource.MAP,
|
||||||
|
StationSelectionSource.MAP_CONTEXT_MENU,
|
||||||
|
StationSelectionSource.PRIORITY,
|
||||||
|
StationSelectionSource.NEW_JOINED,
|
||||||
|
StationSelectionSource.TIMELINE -> true
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import androidx.compose.foundation.ExperimentalFoundationApi
|
|||||||
import androidx.compose.foundation.TooltipArea
|
import androidx.compose.foundation.TooltipArea
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.border
|
import androidx.compose.foundation.border
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
||||||
@@ -25,6 +26,8 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.alpha
|
import androidx.compose.ui.draw.alpha
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.graphics.luminance
|
||||||
|
import androidx.compose.ui.semantics.Role
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
@@ -39,11 +42,9 @@ import kst4contest.controller.On4KstConnectionState
|
|||||||
* only the indicators are left here — which is also what finally makes the bar wrap
|
* only the indicators are left here — which is also what finally makes the bar wrap
|
||||||
* properly on a narrow window instead of pushing the badges out of sight.
|
* properly on a narrow window instead of pushing the badges out of sight.
|
||||||
*
|
*
|
||||||
* Nothing in this bar is clickable. The three indicators were mouse-transparent and
|
* The connection and notice indicators remain non-clickable. A background-thread status is
|
||||||
* non-focusable in JavaFX and stay that way: the operator is typing into the chat, and a
|
* actionable only when the application explicitly registers an action for that source; the
|
||||||
* status badge must never take the keyboard. The background-thread buttons were ordinary
|
* beacon uses this for its quick switch, while every other worker remains a plain label.
|
||||||
* focusable Buttons there, with no action attached — they are drawn as plain labels here,
|
|
||||||
* which is what they always behaved like.
|
|
||||||
*/
|
*/
|
||||||
@OptIn(ExperimentalLayoutApi::class)
|
@OptIn(ExperimentalLayoutApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -202,20 +203,41 @@ private fun ThreadStatusButtonView(button: ThreadStatusButton) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val scheme = MaterialTheme.colorScheme
|
val scheme = MaterialTheme.colorScheme
|
||||||
val background = if (button.highlighted) scheme.primary else scheme.surfaceVariant
|
val colors = if (button.visualStyle == ThreadStatusVisualStyle.DEFAULT) {
|
||||||
val foreground = if (button.highlighted) scheme.onPrimary else scheme.onSurfaceVariant
|
ThreadButtonColors(
|
||||||
|
background = if (button.highlighted) scheme.primary else scheme.surfaceVariant,
|
||||||
|
border = null,
|
||||||
|
text = if (button.highlighted) scheme.onPrimary else scheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
beaconThreadButtonColors(
|
||||||
|
style = button.visualStyle,
|
||||||
|
highlighted = button.highlighted,
|
||||||
|
darkTheme = scheme.surface.luminance() < 0.5f,
|
||||||
|
neutralBackground = scheme.surfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
TooltipArea(tooltip = { TooltipCard(button.tooltip) }) {
|
TooltipArea(tooltip = { TooltipCard(button.tooltip) }) {
|
||||||
Box(
|
val actionModifier = if (button.hasAction) {
|
||||||
modifier = Modifier
|
Modifier.clickable(role = Role.Button) { button.activate() }
|
||||||
|
} else {
|
||||||
|
Modifier
|
||||||
|
}
|
||||||
|
var boxModifier = Modifier
|
||||||
.defaultMinSize(minHeight = 22.dp)
|
.defaultMinSize(minHeight = 22.dp)
|
||||||
.background(background, NOTICE_SHAPE)
|
.background(colors.background, NOTICE_SHAPE)
|
||||||
.padding(NOTICE_PADDING),
|
.then(actionModifier)
|
||||||
|
colors.border?.let { border ->
|
||||||
|
boxModifier = boxModifier.border(1.dp, border, NOTICE_SHAPE)
|
||||||
|
}
|
||||||
|
Box(
|
||||||
|
modifier = boxModifier.padding(NOTICE_PADDING),
|
||||||
contentAlignment = Alignment.Center,
|
contentAlignment = Alignment.Center,
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = button.label,
|
text = button.label,
|
||||||
color = foreground,
|
color = colors.text,
|
||||||
style = MaterialTheme.typography.labelMedium,
|
style = MaterialTheme.typography.labelMedium,
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
)
|
)
|
||||||
@@ -223,6 +245,33 @@ private fun ThreadStatusButtonView(button: ThreadStatusButton) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal data class ThreadButtonColors(
|
||||||
|
val background: Color,
|
||||||
|
val border: Color?,
|
||||||
|
val text: Color,
|
||||||
|
)
|
||||||
|
|
||||||
|
internal fun beaconThreadButtonColors(
|
||||||
|
style: ThreadStatusVisualStyle,
|
||||||
|
highlighted: Boolean,
|
||||||
|
darkTheme: Boolean,
|
||||||
|
neutralBackground: Color,
|
||||||
|
): ThreadButtonColors = when (style) {
|
||||||
|
ThreadStatusVisualStyle.BEACON_ACTIVE -> if (highlighted) {
|
||||||
|
ThreadButtonColors(Color(0xFFFFB300), Color(0xFFFFE082), Color(0xFF1B1B1B))
|
||||||
|
} else {
|
||||||
|
ThreadButtonColors(Color(0xFF238636), Color(0xFF56D364), Color.White)
|
||||||
|
}
|
||||||
|
ThreadStatusVisualStyle.BEACON_FAILED ->
|
||||||
|
ThreadButtonColors(Color(0xFFD50000), Color(0xFFFF6B6B), Color.White)
|
||||||
|
ThreadStatusVisualStyle.BEACON_OFF -> ThreadButtonColors(
|
||||||
|
neutralBackground,
|
||||||
|
null,
|
||||||
|
if (darkTheme) Color(0xFFFF6B6B) else Color(0xFFD50000),
|
||||||
|
)
|
||||||
|
ThreadStatusVisualStyle.DEFAULT -> error("Default worker colours come from the theme")
|
||||||
|
}
|
||||||
|
|
||||||
/** The tooltips in this bar carry the long text the badges had to cut. */
|
/** The tooltips in this bar carry the long text the badges had to cut. */
|
||||||
@Composable
|
@Composable
|
||||||
internal fun TooltipCard(text: String) {
|
internal fun TooltipCard(text: String) {
|
||||||
|
|||||||
@@ -176,20 +176,36 @@ object StatusIndicators {
|
|||||||
class ThreadStatusButtons {
|
class ThreadStatusButtons {
|
||||||
|
|
||||||
private val bySource = LinkedHashMap<String, ThreadStatusButton>()
|
private val bySource = LinkedHashMap<String, ThreadStatusButton>()
|
||||||
|
private val actions = LinkedHashMap<String, () -> Unit>()
|
||||||
|
private val statusProviders = LinkedHashMap<String, () -> ThreadStateMessage>()
|
||||||
private val ordered = mutableStateListOf<ThreadStatusButton>()
|
private val ordered = mutableStateListOf<ThreadStatusButton>()
|
||||||
|
|
||||||
val buttons: List<ThreadStatusButton> get() = ordered
|
val buttons: List<ThreadStatusButton> get() = ordered
|
||||||
|
|
||||||
fun update(sourceName: String, message: ThreadStateMessage) {
|
fun update(sourceName: String, message: ThreadStateMessage) {
|
||||||
|
val effectiveMessage = statusProviders[sourceName]?.invoke() ?: message
|
||||||
val button = bySource.getOrPut(sourceName) {
|
val button = bySource.getOrPut(sourceName) {
|
||||||
ThreadStatusButton(sourceName).also { ordered.add(it) }
|
ThreadStatusButton(sourceName, actions[sourceName]).also { ordered.add(it) }
|
||||||
}
|
}
|
||||||
|
val beacon = effectiveMessage.beaconStatusSnapshot?.let(BeaconStatusPresentation::from)
|
||||||
button.report(
|
button.report(
|
||||||
label = "$sourceName: ${message.runningInformationTextDescription}",
|
label = "$sourceName: ${beacon?.label ?: effectiveMessage.runningInformationTextDescription}",
|
||||||
tooltip = message.runningInformation.orEmpty(),
|
tooltip = beacon?.tooltip ?: effectiveMessage.runningInformation.orEmpty(),
|
||||||
|
style = beacon?.style ?: ThreadStatusVisualStyle.DEFAULT,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Gives one status source an explicit action without changing any other source. */
|
||||||
|
fun registerAction(sourceName: String, action: () -> Unit) {
|
||||||
|
actions[sourceName] = action
|
||||||
|
bySource[sourceName]?.setAction(action)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Resolves a status only when its queued UI update is actually applied. */
|
||||||
|
fun registerStatusProvider(sourceName: String, provider: () -> ThreadStateMessage) {
|
||||||
|
statusProviders[sourceName] = provider
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
/** How long the flash stays on; JavaFX used a 0.2 s PauseTransition. */
|
/** How long the flash stays on; JavaFX used a 0.2 s PauseTransition. */
|
||||||
const val HIGHLIGHT_MILLIS = 200L
|
const val HIGHLIGHT_MILLIS = 200L
|
||||||
@@ -197,7 +213,10 @@ class ThreadStatusButtons {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** One background thread's button. */
|
/** One background thread's button. */
|
||||||
class ThreadStatusButton(val sourceName: String) {
|
class ThreadStatusButton(
|
||||||
|
val sourceName: String,
|
||||||
|
initialAction: (() -> Unit)? = null,
|
||||||
|
) {
|
||||||
|
|
||||||
var label: String by mutableStateOf(sourceName)
|
var label: String by mutableStateOf(sourceName)
|
||||||
private set
|
private set
|
||||||
@@ -209,17 +228,43 @@ class ThreadStatusButton(val sourceName: String) {
|
|||||||
var highlighted: Boolean by mutableStateOf(false)
|
var highlighted: Boolean by mutableStateOf(false)
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
var visualStyle: ThreadStatusVisualStyle by mutableStateOf(ThreadStatusVisualStyle.DEFAULT)
|
||||||
|
private set
|
||||||
|
|
||||||
var revision: Int by mutableStateOf(0)
|
var revision: Int by mutableStateOf(0)
|
||||||
private set
|
private set
|
||||||
|
|
||||||
internal fun report(label: String, tooltip: String) {
|
var action: (() -> Unit)? by mutableStateOf(initialAction)
|
||||||
|
private set
|
||||||
|
|
||||||
|
val hasAction: Boolean
|
||||||
|
get() = action != null
|
||||||
|
|
||||||
|
internal fun report(
|
||||||
|
label: String,
|
||||||
|
tooltip: String,
|
||||||
|
style: ThreadStatusVisualStyle = ThreadStatusVisualStyle.DEFAULT,
|
||||||
|
) {
|
||||||
this.label = label
|
this.label = label
|
||||||
this.tooltip = tooltip
|
this.tooltip = tooltip
|
||||||
highlighted = true
|
visualStyle = style
|
||||||
|
highlighted = style == ThreadStatusVisualStyle.DEFAULT ||
|
||||||
|
style == ThreadStatusVisualStyle.BEACON_ACTIVE
|
||||||
revision++
|
revision++
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clearHighlight() {
|
fun clearHighlight() {
|
||||||
highlighted = false
|
highlighted = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun setAction(action: () -> Unit) {
|
||||||
|
this.action = action
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Runs the registered action and reports whether this status is actionable. */
|
||||||
|
fun activate(): Boolean {
|
||||||
|
val current = action ?: return false
|
||||||
|
current()
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -49,6 +49,23 @@ data class TimelineCandidate(
|
|||||||
val tooltipText: String?,
|
val tooltipText: String?,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/** The four candidate groups produced for every minute bucket, in display order. */
|
||||||
|
enum class TimelineLane(val index: Int) {
|
||||||
|
IN_BEAM_1(0),
|
||||||
|
IN_BEAM_2(1),
|
||||||
|
PRIORITY_1(2),
|
||||||
|
PRIORITY_2(3);
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun forIndex(index: Int): TimelineLane = entries[index.coerceIn(0, entries.lastIndex)]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class TimelineTick(
|
||||||
|
val minutes: Int,
|
||||||
|
val x: Float,
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Where things sit on the strip.
|
* Where things sit on the strip.
|
||||||
*
|
*
|
||||||
@@ -67,27 +84,27 @@ object TimelineGeometry {
|
|||||||
* is why the candidate labels and the sked labels landed on top of each other. The
|
* is why the candidate labels and the sked labels landed on top of each other. The
|
||||||
* lanes below are laid out for the real height.
|
* lanes below are laid out for the real height.
|
||||||
*/
|
*/
|
||||||
const val HEIGHT: Float = 80f
|
const val HEIGHT: Float = 104f
|
||||||
|
|
||||||
/** The time axis, with the candidate lanes above it and the skeds below. */
|
/** The time axis, with the candidate lanes above it and the skeds below. */
|
||||||
const val AXIS_Y: Float = 44f
|
const val AXIS_Y: Float = 70f
|
||||||
|
const val TICK_LABEL_Y: Float = 72f
|
||||||
|
|
||||||
/** Candidates keep further from the edges than skeds do, because their labels are wider. */
|
/** Candidates keep further from the edges than skeds do, because their labels are wider. */
|
||||||
const val CANDIDATE_MARGIN: Float = 30f
|
const val CANDIDATE_MARGIN: Float = 30f
|
||||||
const val SKED_MARGIN: Float = 10f
|
const val SKED_MARGIN: Float = 10f
|
||||||
|
|
||||||
const val LANE_BASE_Y: Float = 2f
|
const val LANE_BASE_Y: Float = 2f
|
||||||
const val LANE_HEIGHT: Float = 20f
|
const val LANE_HEIGHT: Float = 16f
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How many candidate lanes fit above the axis. The producer keeps at most two
|
* How many candidate lanes the producer defines: two in-beam choices followed by
|
||||||
* candidates per minute, so this is a guard rather than a limit in practice: a third
|
* two global priority choices.
|
||||||
* lane shares the second one instead of being drawn across the axis.
|
|
||||||
*/
|
*/
|
||||||
const val LANE_COUNT: Int = 2
|
const val LANE_COUNT: Int = 4
|
||||||
|
|
||||||
/** Skeds get their own lane below the axis, which is what frees the labels. */
|
/** Skeds get their own lane below the axis, which is what frees the labels. */
|
||||||
const val SKED_Y: Float = 52f
|
const val SKED_Y: Float = 86f
|
||||||
|
|
||||||
const val DEFAULT_BEAM_WIDTH_DEG: Double = 50.0
|
const val DEFAULT_BEAM_WIDTH_DEG: Double = 50.0
|
||||||
|
|
||||||
@@ -124,6 +141,23 @@ object TimelineGeometry {
|
|||||||
|
|
||||||
fun laneY(laneIndex: Int): Float =
|
fun laneY(laneIndex: Int): Float =
|
||||||
LANE_BASE_Y + LANE_HEIGHT * laneIndex.coerceIn(0, LANE_COUNT - 1)
|
LANE_BASE_Y + LANE_HEIGHT * laneIndex.coerceIn(0, LANE_COUNT - 1)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relative minute ticks for the current preview window. Five-minute ticks are used
|
||||||
|
* whenever their labels fit; compact layouts increase the interval instead of
|
||||||
|
* drawing overlapping text.
|
||||||
|
*/
|
||||||
|
fun minuteTicks(axisWidth: Float, minimumLabelSpacing: Float): List<TimelineTick> {
|
||||||
|
if (axisWidth <= 0f) return emptyList()
|
||||||
|
|
||||||
|
val previewMinutes = (PREVIEW_MILLIS / 60_000L).toInt()
|
||||||
|
val interval = listOf(5, 10, 15, previewMinutes).first { minutes ->
|
||||||
|
axisWidth * minutes / previewMinutes >= minimumLabelSpacing
|
||||||
|
}
|
||||||
|
return (0..previewMinutes step interval).map { minutes ->
|
||||||
|
TimelineTick(minutes, axisWidth * minutes / previewMinutes)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.height
|
|||||||
import androidx.compose.foundation.layout.offset
|
import androidx.compose.foundation.layout.offset
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
@@ -34,6 +35,7 @@ import androidx.compose.ui.unit.IntOffset
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import kst4contest.model.ContestSked
|
import kst4contest.model.ContestSked
|
||||||
|
import kst4contest.view.i18n.LocalStrings
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
/** The strip is read like a radar screen, so it stays dark in both designs. */
|
/** The strip is read like a radar screen, so it stays dark in both designs. */
|
||||||
@@ -47,6 +49,8 @@ private val MARKER_SIZE = 12.dp
|
|||||||
private val LABEL_GAP = 4.dp
|
private val LABEL_GAP = 4.dp
|
||||||
private val CHIP_SHAPE = RoundedCornerShape(6.dp)
|
private val CHIP_SHAPE = RoundedCornerShape(6.dp)
|
||||||
private val CHIP_BACKGROUND = Color(0xA6000000)
|
private val CHIP_BACKGROUND = Color(0xA6000000)
|
||||||
|
private val LANE_LABEL_WIDTH = 68.dp
|
||||||
|
private val AXIS_LABEL_PADDING = 6.dp
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The strip above the send field: what is coming in the next half hour.
|
* The strip above the send field: what is coming in the next half hour.
|
||||||
@@ -82,6 +86,7 @@ fun TimelineView(
|
|||||||
|
|
||||||
val density = LocalDensity.current
|
val density = LocalDensity.current
|
||||||
val measurer = rememberTextMeasurer()
|
val measurer = rememberTextMeasurer()
|
||||||
|
val strings = LocalStrings.current
|
||||||
|
|
||||||
BoxWithConstraints(
|
BoxWithConstraints(
|
||||||
modifier
|
modifier
|
||||||
@@ -89,17 +94,60 @@ fun TimelineView(
|
|||||||
.background(STRIP_BACKGROUND),
|
.background(STRIP_BACKGROUND),
|
||||||
) {
|
) {
|
||||||
val widthPx = with(density) { maxWidth.toPx() }
|
val widthPx = with(density) { maxWidth.toPx() }
|
||||||
|
val labelGutterPx = with(density) { LANE_LABEL_WIDTH.toPx() }.coerceAtMost(widthPx)
|
||||||
|
val axisWidthPx = (widthPx - labelGutterPx).coerceAtLeast(0f)
|
||||||
val axisY = with(density) { TimelineGeometry.AXIS_Y.dp.toPx() }
|
val axisY = with(density) { TimelineGeometry.AXIS_Y.dp.toPx() }
|
||||||
val candidateMargin = with(density) { TimelineGeometry.CANDIDATE_MARGIN.dp.toPx() }
|
val candidateMargin = with(density) { TimelineGeometry.CANDIDATE_MARGIN.dp.toPx() }
|
||||||
val skedMargin = with(density) { TimelineGeometry.SKED_MARGIN.dp.toPx() }
|
val skedMargin = with(density) { TimelineGeometry.SKED_MARGIN.dp.toPx() }
|
||||||
|
val tickLabels = TimelineGeometry.minuteTicks(
|
||||||
|
axisWidth = axisWidthPx,
|
||||||
|
minimumLabelSpacing = measurer.measure("+30 ${strings.timelineMinuteSuffix}", AXIS_TEXT_STYLE)
|
||||||
|
.size.width.toFloat() + with(density) { AXIS_LABEL_PADDING.toPx() },
|
||||||
|
).map { tick ->
|
||||||
|
tick to if (tick.minutes == 0) {
|
||||||
|
"0 ${strings.timelineMinuteSuffix}"
|
||||||
|
} else {
|
||||||
|
"+${tick.minutes} ${strings.timelineMinuteSuffix}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Canvas(Modifier.fillMaxSize()) {
|
Canvas(Modifier.fillMaxSize()) {
|
||||||
drawLine(AXIS_COLOR, Offset(0f, axisY), Offset(size.width, axisY))
|
drawLine(AXIS_COLOR, Offset(labelGutterPx, axisY), Offset(size.width, axisY))
|
||||||
|
tickLabels.forEach { (tick, _) ->
|
||||||
|
val x = labelGutterPx + tick.x
|
||||||
|
drawLine(AXIS_COLOR, Offset(x, axisY - 2.dp.toPx()), Offset(x, axisY + 3.dp.toPx()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val laneLabels = listOf(
|
||||||
|
strings.timelineInBeam1,
|
||||||
|
strings.timelineInBeam2,
|
||||||
|
strings.timelinePriority1,
|
||||||
|
strings.timelinePriority2,
|
||||||
|
)
|
||||||
|
laneLabels.forEachIndexed { index, label ->
|
||||||
|
TimelineAxisLabel(label, TimelineGeometry.laneY(index).dp)
|
||||||
|
}
|
||||||
|
TimelineAxisLabel(strings.timelineSkeds, TimelineGeometry.SKED_Y.dp)
|
||||||
|
|
||||||
|
tickLabels.forEach { (tick, label) ->
|
||||||
|
val labelWidthPx = measurer.measure(label, AXIS_TEXT_STYLE).size.width.toFloat()
|
||||||
|
val x = (labelGutterPx + tick.x - labelWidthPx / 2f)
|
||||||
|
.coerceIn(labelGutterPx, (widthPx - labelWidthPx).coerceAtLeast(labelGutterPx))
|
||||||
|
Text(
|
||||||
|
text = label,
|
||||||
|
modifier = Modifier.offset {
|
||||||
|
IntOffset(x.roundToInt(), with(density) { TimelineGeometry.TICK_LABEL_Y.dp.toPx() }.roundToInt())
|
||||||
|
},
|
||||||
|
style = AXIS_TEXT_STYLE,
|
||||||
|
maxLines = 1,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The candidate lanes, above the axis.
|
// The candidate lanes, above the axis.
|
||||||
state.candidates.forEach { candidate ->
|
state.candidates.forEach { candidate ->
|
||||||
val x = TimelineGeometry.xFor(candidate.timeUntilMs, widthPx, candidateMargin)
|
val x = TimelineGeometry.xFor(candidate.timeUntilMs, axisWidthPx, candidateMargin)
|
||||||
|
?.plus(labelGutterPx)
|
||||||
?: return@forEach
|
?: return@forEach
|
||||||
|
|
||||||
TimelineMarker(
|
TimelineMarker(
|
||||||
@@ -120,7 +168,8 @@ fun TimelineView(
|
|||||||
// above it, which is why their labels sat on top of the candidates'.
|
// above it, which is why their labels sat on top of the candidates'.
|
||||||
val now = nowMillis.value
|
val now = nowMillis.value
|
||||||
state.skeds.forEach { sked ->
|
state.skeds.forEach { sked ->
|
||||||
val x = TimelineGeometry.xFor(sked.skedTimeEpoch - now, widthPx, skedMargin)
|
val x = TimelineGeometry.xFor(sked.skedTimeEpoch - now, axisWidthPx, skedMargin)
|
||||||
|
?.plus(labelGutterPx)
|
||||||
?: return@forEach
|
?: return@forEach
|
||||||
|
|
||||||
TimelineMarker(
|
TimelineMarker(
|
||||||
@@ -157,6 +206,23 @@ private val CHIP_TEXT_STYLE = TextStyle(
|
|||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private val AXIS_TEXT_STYLE = TextStyle(
|
||||||
|
color = Color(0xFFB8B8B8),
|
||||||
|
fontSize = 8.sp,
|
||||||
|
)
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun TimelineAxisLabel(text: String, top: Dp) {
|
||||||
|
Text(
|
||||||
|
text = text,
|
||||||
|
modifier = Modifier
|
||||||
|
.offset(x = 4.dp, y = top)
|
||||||
|
.width(LANE_LABEL_WIDTH - 8.dp),
|
||||||
|
style = AXIS_TEXT_STYLE,
|
||||||
|
maxLines = 1,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One marker: the symbol on the time axis and its callsign beside it.
|
* One marker: the symbol on the time axis and its callsign beside it.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.runtime.snapshotFlow
|
import androidx.compose.runtime.snapshotFlow
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||||
import androidx.compose.ui.draw.clipToBounds
|
import androidx.compose.ui.draw.clipToBounds
|
||||||
import androidx.compose.ui.layout.onSizeChanged
|
import androidx.compose.ui.layout.onSizeChanged
|
||||||
import androidx.compose.ui.geometry.Offset
|
import androidx.compose.ui.geometry.Offset
|
||||||
@@ -24,7 +25,11 @@ import androidx.compose.ui.graphics.drawscope.Fill
|
|||||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||||
import androidx.compose.ui.graphics.toComposeImageBitmap
|
import androidx.compose.ui.graphics.toComposeImageBitmap
|
||||||
import androidx.compose.ui.input.pointer.PointerEventType
|
import androidx.compose.ui.input.pointer.PointerEventType
|
||||||
|
import androidx.compose.ui.input.pointer.isSecondaryPressed
|
||||||
|
import androidx.compose.ui.input.pointer.onPointerEvent
|
||||||
import androidx.compose.ui.input.pointer.pointerInput
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
|
import androidx.compose.ui.layout.LayoutCoordinates
|
||||||
|
import androidx.compose.ui.layout.onGloballyPositioned
|
||||||
import androidx.compose.ui.text.TextLayoutResult
|
import androidx.compose.ui.text.TextLayoutResult
|
||||||
import androidx.compose.ui.text.TextMeasurer
|
import androidx.compose.ui.text.TextMeasurer
|
||||||
import androidx.compose.ui.text.TextStyle
|
import androidx.compose.ui.text.TextStyle
|
||||||
@@ -50,6 +55,7 @@ import kotlin.math.ceil
|
|||||||
import kotlin.math.floor
|
import kotlin.math.floor
|
||||||
import kotlin.math.log2
|
import kotlin.math.log2
|
||||||
import kotlin.math.sign
|
import kotlin.math.sign
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Where the map is looking. Compose state, so a pan or a zoom reaches the screen.
|
* Where the map is looking. Compose state, so a pan or a zoom reaches the screen.
|
||||||
@@ -94,6 +100,7 @@ class MapState(
|
|||||||
* any zoom with a fraction, the antenna beam did not start where the map said home was.
|
* any zoom with a fraction, the antenna beam did not start where the map said home was.
|
||||||
* Neither failure is possible here, because nothing is scaled.
|
* Neither failure is possible here, because nothing is scaled.
|
||||||
*/
|
*/
|
||||||
|
@OptIn(ExperimentalComposeUiApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun ComposeStationMap(
|
fun ComposeStationMap(
|
||||||
markers: List<MapCallsignRawSnapshot>,
|
markers: List<MapCallsignRawSnapshot>,
|
||||||
@@ -105,8 +112,15 @@ fun ComposeStationMap(
|
|||||||
antennaAzimuthDeg: Double,
|
antennaAzimuthDeg: Double,
|
||||||
antennaBeamWidthDeg: Double,
|
antennaBeamWidthDeg: Double,
|
||||||
maxQrbKm: Double,
|
maxQrbKm: Double,
|
||||||
|
selectedTarget: MapCallsignRawSnapshot? = markers.firstOrNull {
|
||||||
|
it.callSignRaw() == selectedMarkerCallsign
|
||||||
|
},
|
||||||
|
spatialFilterOverlay: SpatialFilterOverlayState? = null,
|
||||||
onMarkerClicked: ((MapCallsignRawSnapshot) -> Unit)?,
|
onMarkerClicked: ((MapCallsignRawSnapshot) -> Unit)?,
|
||||||
|
onMarkerContextRequested: ((List<MapCallsignRawSnapshot>, IntOffset) -> Unit)? = null,
|
||||||
|
workedGrossFields: Set<String> = emptySet(),
|
||||||
darkMode: Boolean = true,
|
darkMode: Boolean = true,
|
||||||
|
onCanvasSizeChanged: (Size) -> Unit = { },
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
val imageCache = remember { TileBitmapCache() }
|
val imageCache = remember { TileBitmapCache() }
|
||||||
@@ -122,6 +136,7 @@ fun ComposeStationMap(
|
|||||||
* wrongly grouped markers whenever the window is resized.
|
* wrongly grouped markers whenever the window is resized.
|
||||||
*/
|
*/
|
||||||
var canvasSize by remember { mutableStateOf(Size.Zero) }
|
var canvasSize by remember { mutableStateOf(Size.Zero) }
|
||||||
|
var canvasCoordinates by remember { mutableStateOf<LayoutCoordinates?>(null) }
|
||||||
|
|
||||||
/* Bumped when a tile arrives, which is what asks for the frame that shows it. */
|
/* Bumped when a tile arrives, which is what asks for the frame that shows it. */
|
||||||
var tileRevision by remember { mutableStateOf(0) }
|
var tileRevision by remember { mutableStateOf(0) }
|
||||||
@@ -137,6 +152,13 @@ fun ComposeStationMap(
|
|||||||
* one linear pass over a few hundred markers.
|
* one linear pass over a few hundred markers.
|
||||||
*/
|
*/
|
||||||
val home = remember(ownLocator6) { homePosition(ownLocator6) }
|
val home = remember(ownLocator6) { homePosition(ownLocator6) }
|
||||||
|
val selectedTargetOutsideMarkers by remember(markers, selectedTarget) {
|
||||||
|
derivedStateOf {
|
||||||
|
selectedTarget?.takeIf { target ->
|
||||||
|
target.hasUsablePosition() && markers.none { it.callSignRaw() == target.callSignRaw() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
val clusterResult by remember(markers, groupingEnabled, canvasSize) {
|
val clusterResult by remember(markers, groupingEnabled, canvasSize) {
|
||||||
derivedStateOf {
|
derivedStateOf {
|
||||||
StationMapClusterer.cluster(
|
StationMapClusterer.cluster(
|
||||||
@@ -195,7 +217,53 @@ fun ComposeStationMap(
|
|||||||
Canvas(
|
Canvas(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.clipToBounds()
|
.clipToBounds()
|
||||||
.onSizeChanged { canvasSize = Size(it.width.toFloat(), it.height.toFloat()) }
|
.onSizeChanged {
|
||||||
|
canvasSize = Size(it.width.toFloat(), it.height.toFloat())
|
||||||
|
onCanvasSizeChanged(canvasSize)
|
||||||
|
}
|
||||||
|
.onGloballyPositioned { canvasCoordinates = it }
|
||||||
|
.onPointerEvent(PointerEventType.Press) { event ->
|
||||||
|
if (event.buttons.isSecondaryPressed) {
|
||||||
|
val local = event.changes.firstOrNull()?.position ?: return@onPointerEvent
|
||||||
|
val viewport = mapState.viewportFor(canvasSize.width, canvasSize.height)
|
||||||
|
val result = StationMapClusterer.cluster(markers, viewport, groupingEnabled)
|
||||||
|
val selectedOutside = selectedTargetOutsideMarkers?.takeIf { marker ->
|
||||||
|
within(
|
||||||
|
local,
|
||||||
|
viewport.screenXWrapped(marker.longitudeDeg()).toFloat(),
|
||||||
|
viewport.screenY(marker.latitudeDeg()).toFloat(),
|
||||||
|
MARKER_HIT_RADIUS_PX,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val cluster = result.clusters().firstOrNull { candidate ->
|
||||||
|
within(
|
||||||
|
local,
|
||||||
|
viewport.screenXWrapped(candidate.centerLon).toFloat(),
|
||||||
|
viewport.screenY(candidate.centerLat).toFloat(),
|
||||||
|
clusterRadiusPx(candidate.size()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val individual = result.individual().firstOrNull { marker ->
|
||||||
|
within(
|
||||||
|
local,
|
||||||
|
viewport.screenXWrapped(marker.longitudeDeg()).toFloat(),
|
||||||
|
viewport.screenY(marker.latitudeDeg()).toFloat(),
|
||||||
|
MARKER_HIT_RADIUS_PX,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val targets = selectedOutside?.let(::listOf)
|
||||||
|
?: cluster?.getMarkers()
|
||||||
|
?: individual?.let(::listOf)
|
||||||
|
val window = canvasCoordinates?.localToWindow(local)
|
||||||
|
if (!targets.isNullOrEmpty() && window != null) {
|
||||||
|
onMarkerContextRequested?.invoke(
|
||||||
|
targets,
|
||||||
|
IntOffset(window.x.roundToInt(), window.y.roundToInt()),
|
||||||
|
)
|
||||||
|
event.changes.forEach { it.consume() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
.pointerInput(Unit) {
|
.pointerInput(Unit) {
|
||||||
detectTransformGestures { centroid, pan, zoomChange, _ ->
|
detectTransformGestures { centroid, pan, zoomChange, _ ->
|
||||||
var viewport = mapState.viewportFor(size.width.toFloat(), size.height.toFloat())
|
var viewport = mapState.viewportFor(size.width.toFloat(), size.height.toFloat())
|
||||||
@@ -238,15 +306,28 @@ fun ComposeStationMap(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.pointerInput(markers, groupingEnabled, onMarkerClicked) {
|
.pointerInput(markers, selectedTargetOutsideMarkers, groupingEnabled, onMarkerClicked) {
|
||||||
detectTapGestures { offset ->
|
detectTapGestures { offset ->
|
||||||
val viewport = mapState.viewportFor(size.width.toFloat(), size.height.toFloat())
|
val viewport = mapState.viewportFor(size.width.toFloat(), size.height.toFloat())
|
||||||
val result = StationMapClusterer.cluster(markers, viewport, groupingEnabled)
|
val result = StationMapClusterer.cluster(markers, viewport, groupingEnabled)
|
||||||
|
|
||||||
|
val selectedOutside = selectedTargetOutsideMarkers?.takeIf { marker ->
|
||||||
|
within(
|
||||||
|
offset,
|
||||||
|
viewport.screenXWrapped(marker.longitudeDeg()).toFloat(),
|
||||||
|
viewport.screenY(marker.latitudeDeg()).toFloat(),
|
||||||
|
MARKER_HIT_RADIUS_PX,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (selectedOutside != null) {
|
||||||
|
onMarkerClicked?.invoke(selectedOutside)
|
||||||
|
return@detectTapGestures
|
||||||
|
}
|
||||||
|
|
||||||
val hitCluster = result.clusters().firstOrNull { cluster ->
|
val hitCluster = result.clusters().firstOrNull { cluster ->
|
||||||
within(
|
within(
|
||||||
offset,
|
offset,
|
||||||
viewport.screenX(cluster.centerLon).toFloat(),
|
viewport.screenXWrapped(cluster.centerLon).toFloat(),
|
||||||
viewport.screenY(cluster.centerLat).toFloat(),
|
viewport.screenY(cluster.centerLat).toFloat(),
|
||||||
clusterRadiusPx(cluster.size()),
|
clusterRadiusPx(cluster.size()),
|
||||||
)
|
)
|
||||||
@@ -269,14 +350,12 @@ fun ComposeStationMap(
|
|||||||
val hit = result.individual().firstOrNull { marker ->
|
val hit = result.individual().firstOrNull { marker ->
|
||||||
within(
|
within(
|
||||||
offset,
|
offset,
|
||||||
viewport.screenX(marker.longitudeDeg()).toFloat(),
|
viewport.screenXWrapped(marker.longitudeDeg()).toFloat(),
|
||||||
viewport.screenY(marker.latitudeDeg()).toFloat(),
|
viewport.screenY(marker.latitudeDeg()).toFloat(),
|
||||||
MARKER_HIT_RADIUS_PX,
|
MARKER_HIT_RADIUS_PX,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (hit != null) {
|
if (hit != null) onMarkerClicked?.invoke(hit)
|
||||||
onMarkerClicked?.invoke(hit)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
@@ -292,10 +371,34 @@ fun ComposeStationMap(
|
|||||||
drawRect(color = if (darkMode) MAP_BACKGROUND_DARK else MAP_BACKGROUND_LIGHT)
|
drawRect(color = if (darkMode) MAP_BACKGROUND_DARK else MAP_BACKGROUND_LIGHT)
|
||||||
|
|
||||||
drawTiles(viewport, imageCache, darkMode)
|
drawTiles(viewport, imageCache, darkMode)
|
||||||
|
if (home != null && spatialFilterOverlay != null) {
|
||||||
|
drawSpatialFilterOverlay(
|
||||||
|
viewport = viewport,
|
||||||
|
homeLatitudeDeg = home.first,
|
||||||
|
homeLongitudeDeg = home.second,
|
||||||
|
state = spatialFilterOverlay,
|
||||||
|
darkMode = darkMode,
|
||||||
|
)
|
||||||
|
}
|
||||||
drawMaidenheadGrid(viewport, textMeasurer, darkMode)
|
drawMaidenheadGrid(viewport, textMeasurer, darkMode)
|
||||||
drawBeamAndPath(viewport, home, antennaAzimuthDeg, antennaBeamWidthDeg, maxQrbKm, markers, selectedMarkerCallsign, darkMode)
|
drawWorkedGrossFields(viewport, workedGrossFields)
|
||||||
|
drawBeamAndPath(
|
||||||
|
viewport,
|
||||||
|
home,
|
||||||
|
antennaAzimuthDeg,
|
||||||
|
antennaBeamWidthDeg,
|
||||||
|
maxQrbKm,
|
||||||
|
selectedTarget,
|
||||||
|
darkMode,
|
||||||
|
)
|
||||||
drawStations(viewport, clusterResult, selectedMarkerCallsign, textMeasurer, darkMode)
|
drawStations(viewport, clusterResult, selectedMarkerCallsign, textMeasurer, darkMode)
|
||||||
drawHover(viewport, hoverPosition, clusterResult, textMeasurer)
|
selectedTargetOutsideMarkers?.let { target ->
|
||||||
|
val x = viewport.screenXWrapped(target.longitudeDeg()).toFloat()
|
||||||
|
val y = viewport.screenY(target.latitudeDeg()).toFloat()
|
||||||
|
drawStationDot(x, y, selected = true, worked = target.worked(), warning = target.warningToMyDirection())
|
||||||
|
drawStationLabel(x, y, target.markerLabel(), target.warningToMyDirection(), textMeasurer, darkMode)
|
||||||
|
}
|
||||||
|
drawHover(viewport, hoverPosition, clusterResult, selectedTargetOutsideMarkers, textMeasurer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -430,8 +533,8 @@ private fun DrawScope.drawMaidenheadGrid(
|
|||||||
val verticals = sortedSetOf<Float>()
|
val verticals = sortedSetOf<Float>()
|
||||||
val horizontals = sortedSetOf<Float>()
|
val horizontals = sortedSetOf<Float>()
|
||||||
for (cell in cells) {
|
for (cell in cells) {
|
||||||
verticals.add(viewport.screenX(cell.westLon()).toFloat())
|
verticals.add(viewport.screenXWrapped(cell.westLon()).toFloat())
|
||||||
verticals.add(viewport.screenX(cell.eastLon()).toFloat())
|
verticals.add(viewport.screenXWrapped(cell.eastLon()).toFloat())
|
||||||
horizontals.add(viewport.screenY(cell.northLat()).toFloat())
|
horizontals.add(viewport.screenY(cell.northLat()).toFloat())
|
||||||
horizontals.add(viewport.screenY(cell.southLat()).toFloat())
|
horizontals.add(viewport.screenY(cell.southLat()).toFloat())
|
||||||
}
|
}
|
||||||
@@ -472,7 +575,7 @@ private fun DrawScope.drawMaidenheadGrid(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Centred in the cell, the way the stylesheet's translate(-50%, -50%) was. */
|
/* Centred in the cell, the way the stylesheet's translate(-50%, -50%) was. */
|
||||||
val centerX = viewport.screenX((cell.westLon() + cell.eastLon()) / 2.0).toFloat()
|
val centerX = viewport.screenXWrapped((cell.westLon() + cell.eastLon()) / 2.0).toFloat()
|
||||||
val centerY = viewport.screenY((cell.southLat() + cell.northLat()) / 2.0).toFloat()
|
val centerY = viewport.screenY((cell.southLat() + cell.northLat()) / 2.0).toFloat()
|
||||||
|
|
||||||
val layout = textMeasurer.measure(cell.locatorLabel(), style = labelStyle)
|
val layout = textMeasurer.measure(cell.locatorLabel(), style = labelStyle)
|
||||||
@@ -496,8 +599,7 @@ private fun DrawScope.drawBeamAndPath(
|
|||||||
antennaAzimuthDeg: Double,
|
antennaAzimuthDeg: Double,
|
||||||
antennaBeamWidthDeg: Double,
|
antennaBeamWidthDeg: Double,
|
||||||
maxQrbKm: Double,
|
maxQrbKm: Double,
|
||||||
markers: List<MapCallsignRawSnapshot>,
|
selectedTarget: MapCallsignRawSnapshot?,
|
||||||
selectedMarkerCallsign: String?,
|
|
||||||
darkMode: Boolean,
|
darkMode: Boolean,
|
||||||
) {
|
) {
|
||||||
if (home == null) {
|
if (home == null) {
|
||||||
@@ -505,32 +607,40 @@ private fun DrawScope.drawBeamAndPath(
|
|||||||
}
|
}
|
||||||
val (homeLat, homeLon) = home
|
val (homeLat, homeLon) = home
|
||||||
|
|
||||||
if (antennaBeamWidthDeg > 0.0 && maxQrbKm > 0.0) {
|
if (isAntennaSectorDrawable(home, antennaAzimuthDeg, antennaBeamWidthDeg, maxQrbKm)) {
|
||||||
val polygon = Path()
|
val polygon = Path()
|
||||||
buildBeamPolygon(homeLat, homeLon, antennaAzimuthDeg, antennaBeamWidthDeg, maxQrbKm)
|
buildBeamPolygon(homeLat, homeLon, antennaAzimuthDeg, antennaBeamWidthDeg, maxQrbKm)
|
||||||
.forEachIndexed { index, point ->
|
.forEachIndexed { index, point ->
|
||||||
val x = viewport.screenX(point.second).toFloat()
|
val x = viewport.screenXWrapped(point.second).toFloat()
|
||||||
val y = viewport.screenY(point.first).toFloat()
|
val y = viewport.screenY(point.first).toFloat()
|
||||||
if (index == 0) polygon.moveTo(x, y) else polygon.lineTo(x, y)
|
if (index == 0) polygon.moveTo(x, y) else polygon.lineTo(x, y)
|
||||||
}
|
}
|
||||||
polygon.close()
|
polygon.close()
|
||||||
|
|
||||||
drawPath(path = polygon, color = BEAM_COLOR, alpha = BEAM_FILL_ALPHA, style = Fill)
|
drawPath(path = polygon, color = ANTENNA_OVERLAY_COLOR, alpha = BEAM_FILL_ALPHA, style = Fill)
|
||||||
drawPath(path = polygon, color = BEAM_COLOR, style = Stroke(width = BEAM_STROKE_WIDTH_PX))
|
drawPath(path = polygon, color = ANTENNA_OVERLAY_COLOR, style = Stroke(width = BEAM_STROKE_WIDTH_PX))
|
||||||
}
|
}
|
||||||
|
|
||||||
val selected = markers.firstOrNull {
|
val selected = selectedTarget?.takeIf(MapCallsignRawSnapshot::hasUsablePosition)
|
||||||
it.callSignRaw() == selectedMarkerCallsign && it.hasUsablePosition()
|
|
||||||
}
|
|
||||||
if (selected != null) {
|
if (selected != null) {
|
||||||
|
val start = Offset(viewport.screenXWrapped(homeLon).toFloat(), viewport.screenY(homeLat).toFloat())
|
||||||
|
val end = Offset(
|
||||||
|
viewport.screenXWrapped(selected.longitudeDeg()).toFloat(),
|
||||||
|
viewport.screenY(selected.latitudeDeg()).toFloat(),
|
||||||
|
)
|
||||||
|
drawLine(
|
||||||
|
color = if (darkMode) CONNECTION_HALO_DARK else CONNECTION_HALO_LIGHT,
|
||||||
|
alpha = CONNECTION_HALO_ALPHA,
|
||||||
|
start = start,
|
||||||
|
end = end,
|
||||||
|
strokeWidth = CONNECTION_HALO_WIDTH_PX,
|
||||||
|
pathEffect = PathEffect.dashPathEffect(CONNECTION_DASH_PX),
|
||||||
|
)
|
||||||
drawLine(
|
drawLine(
|
||||||
color = if (darkMode) CONNECTION_COLOR_DARK else CONNECTION_COLOR_LIGHT,
|
color = if (darkMode) CONNECTION_COLOR_DARK else CONNECTION_COLOR_LIGHT,
|
||||||
alpha = CONNECTION_ALPHA,
|
alpha = CONNECTION_ALPHA,
|
||||||
start = Offset(viewport.screenX(homeLon).toFloat(), viewport.screenY(homeLat).toFloat()),
|
start = start,
|
||||||
end = Offset(
|
end = end,
|
||||||
viewport.screenX(selected.longitudeDeg()).toFloat(),
|
|
||||||
viewport.screenY(selected.latitudeDeg()).toFloat(),
|
|
||||||
),
|
|
||||||
strokeWidth = CONNECTION_STROKE_WIDTH_PX,
|
strokeWidth = CONNECTION_STROKE_WIDTH_PX,
|
||||||
pathEffect = PathEffect.dashPathEffect(CONNECTION_DASH_PX),
|
pathEffect = PathEffect.dashPathEffect(CONNECTION_DASH_PX),
|
||||||
)
|
)
|
||||||
@@ -541,9 +651,9 @@ private fun DrawScope.drawBeamAndPath(
|
|||||||
* home is, and with the beam switched off there was none. A small dot is kept here
|
* home is, and with the beam switched off there was none. A small dot is kept here
|
||||||
* deliberately.
|
* deliberately.
|
||||||
*/
|
*/
|
||||||
val homeX = viewport.screenX(homeLon).toFloat()
|
val homeX = viewport.screenXWrapped(homeLon).toFloat()
|
||||||
val homeY = viewport.screenY(homeLat).toFloat()
|
val homeY = viewport.screenY(homeLat).toFloat()
|
||||||
drawCircle(color = BEAM_COLOR, radius = HOME_RADIUS_PX, center = Offset(homeX, homeY))
|
drawCircle(color = ANTENNA_OVERLAY_COLOR, radius = HOME_RADIUS_PX, center = Offset(homeX, homeY))
|
||||||
drawCircle(color = Color.White, radius = HOME_INNER_RADIUS_PX, center = Offset(homeX, homeY))
|
drawCircle(color = Color.White, radius = HOME_INNER_RADIUS_PX, center = Offset(homeX, homeY))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -558,7 +668,7 @@ private fun DrawScope.drawStations(
|
|||||||
) {
|
) {
|
||||||
for (cluster in clusterResult.clusters()) {
|
for (cluster in clusterResult.clusters()) {
|
||||||
drawClusterBubble(
|
drawClusterBubble(
|
||||||
x = viewport.screenX(cluster.centerLon).toFloat(),
|
x = viewport.screenXWrapped(cluster.centerLon).toFloat(),
|
||||||
y = viewport.screenY(cluster.centerLat).toFloat(),
|
y = viewport.screenY(cluster.centerLat).toFloat(),
|
||||||
count = cluster.size(),
|
count = cluster.size(),
|
||||||
containsWorked = cluster.getMarkers().any { it.worked() },
|
containsWorked = cluster.getMarkers().any { it.worked() },
|
||||||
@@ -567,7 +677,7 @@ private fun DrawScope.drawStations(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (marker in clusterResult.individual()) {
|
for (marker in clusterResult.individual()) {
|
||||||
val x = viewport.screenX(marker.longitudeDeg()).toFloat()
|
val x = viewport.screenXWrapped(marker.longitudeDeg()).toFloat()
|
||||||
val y = viewport.screenY(marker.latitudeDeg()).toFloat()
|
val y = viewport.screenY(marker.latitudeDeg()).toFloat()
|
||||||
val selected = marker.callSignRaw() == selectedMarkerCallsign
|
val selected = marker.callSignRaw() == selectedMarkerCallsign
|
||||||
|
|
||||||
@@ -685,14 +795,23 @@ private fun DrawScope.drawHover(
|
|||||||
viewport: MapViewport,
|
viewport: MapViewport,
|
||||||
hoverPosition: Offset?,
|
hoverPosition: Offset?,
|
||||||
clusterResult: StationMapClusterer.Result,
|
clusterResult: StationMapClusterer.Result,
|
||||||
|
selectedTargetOutsideMarkers: MapCallsignRawSnapshot?,
|
||||||
textMeasurer: TextMeasurer,
|
textMeasurer: TextMeasurer,
|
||||||
) {
|
) {
|
||||||
val position = hoverPosition ?: return
|
val position = hoverPosition ?: return
|
||||||
|
|
||||||
|
val selectedTargetUnderPointer = selectedTargetOutsideMarkers?.takeIf { marker ->
|
||||||
|
within(
|
||||||
|
position,
|
||||||
|
viewport.screenXWrapped(marker.longitudeDeg()).toFloat(),
|
||||||
|
viewport.screenY(marker.latitudeDeg()).toFloat(),
|
||||||
|
MARKER_HIT_RADIUS_PX,
|
||||||
|
)
|
||||||
|
}
|
||||||
val clusterUnderPointer = clusterResult.clusters().firstOrNull { cluster ->
|
val clusterUnderPointer = clusterResult.clusters().firstOrNull { cluster ->
|
||||||
within(
|
within(
|
||||||
position,
|
position,
|
||||||
viewport.screenX(cluster.centerLon).toFloat(),
|
viewport.screenXWrapped(cluster.centerLon).toFloat(),
|
||||||
viewport.screenY(cluster.centerLat).toFloat(),
|
viewport.screenY(cluster.centerLat).toFloat(),
|
||||||
clusterRadiusPx(cluster.size()),
|
clusterRadiusPx(cluster.size()),
|
||||||
)
|
)
|
||||||
@@ -700,19 +819,17 @@ private fun DrawScope.drawHover(
|
|||||||
val markerUnderPointer = clusterResult.individual().firstOrNull { marker ->
|
val markerUnderPointer = clusterResult.individual().firstOrNull { marker ->
|
||||||
within(
|
within(
|
||||||
position,
|
position,
|
||||||
viewport.screenX(marker.longitudeDeg()).toFloat(),
|
viewport.screenXWrapped(marker.longitudeDeg()).toFloat(),
|
||||||
viewport.screenY(marker.latitudeDeg()).toFloat(),
|
viewport.screenY(marker.latitudeDeg()).toFloat(),
|
||||||
MARKER_HIT_RADIUS_PX,
|
MARKER_HIT_RADIUS_PX,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val text = when {
|
val text = when {
|
||||||
|
selectedTargetUnderPointer != null -> selectedTargetUnderPointer.tooltipText()
|
||||||
|
|
||||||
clusterUnderPointer != null -> MapMarkerClusterTooltip.build(clusterUnderPointer)
|
clusterUnderPointer != null -> MapMarkerClusterTooltip.build(clusterUnderPointer)
|
||||||
|
|
||||||
markerUnderPointer != null -> markerUnderPointer.locator6().let { locator ->
|
markerUnderPointer != null -> markerUnderPointer.tooltipText()
|
||||||
if (locator.isBlank()) markerUnderPointer.displayCallSign()
|
|
||||||
else "${markerUnderPointer.displayCallSign()} ($locator)"
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> return
|
else -> return
|
||||||
}
|
}
|
||||||
@@ -758,6 +875,46 @@ private fun DrawScope.drawHover(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun DrawScope.drawWorkedGrossFields(
|
||||||
|
viewport: MapViewport,
|
||||||
|
workedGrossFields: Set<String>,
|
||||||
|
) {
|
||||||
|
visibleWorkedGrossFieldCells(viewport, workedGrossFields).forEach { cell ->
|
||||||
|
val left = viewport.screenXWrapped(cell.westLon()).toFloat()
|
||||||
|
val right = viewport.screenXWrapped(cell.eastLon()).toFloat()
|
||||||
|
val top = viewport.screenY(cell.northLat()).toFloat()
|
||||||
|
val bottom = viewport.screenY(cell.southLat()).toFloat()
|
||||||
|
val topLeft = Offset(minOf(left, right), minOf(top, bottom))
|
||||||
|
val cellSize = Size(kotlin.math.abs(right - left), kotlin.math.abs(bottom - top))
|
||||||
|
drawRect(
|
||||||
|
color = WORKED_GRID_FILL,
|
||||||
|
topLeft = topLeft,
|
||||||
|
size = cellSize,
|
||||||
|
)
|
||||||
|
drawRect(
|
||||||
|
color = WORKED_GRID_BORDER,
|
||||||
|
topLeft = topLeft,
|
||||||
|
size = cellSize,
|
||||||
|
style = Stroke(width = WORKED_GRID_BORDER_WIDTH_PX),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Worked four-character cells visible in the current viewport, independent of markers. */
|
||||||
|
internal fun visibleWorkedGrossFieldCells(
|
||||||
|
viewport: MapViewport,
|
||||||
|
workedGrossFields: Set<String>,
|
||||||
|
): List<MaidenheadGridUtils.GridCell> {
|
||||||
|
if (workedGrossFields.isEmpty()) return emptyList()
|
||||||
|
return MaidenheadGridUtils.buildVisibleCells(
|
||||||
|
viewport.southLat(),
|
||||||
|
viewport.westLon(),
|
||||||
|
viewport.northLat(),
|
||||||
|
viewport.eastLon(),
|
||||||
|
MaidenheadGridUtils.GridPrecision.SQUARE_4,
|
||||||
|
).filter { it.locatorLabel() in workedGrossFields }
|
||||||
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------- helpers */
|
/* ----------------------------------------------------------- helpers */
|
||||||
|
|
||||||
private val MapMarkerCluster.centerLon: Double get() = getCenterLon()
|
private val MapMarkerCluster.centerLon: Double get() = getCenterLon()
|
||||||
@@ -782,7 +939,7 @@ private fun clusterFontSizePx(count: Int): Float = when {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Null rather than a guess when the operator has no usable locator configured. */
|
/** Null rather than a guess when the operator has no usable locator configured. */
|
||||||
private fun homePosition(ownLocator6: String): Pair<Double, Double>? {
|
internal fun homePosition(ownLocator6: String): Pair<Double, Double>? {
|
||||||
if (ownLocator6.length < 4) {
|
if (ownLocator6.length < 4) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -794,6 +951,15 @@ private fun homePosition(ownLocator6: String): Pair<Double, Double>? {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun isAntennaSectorDrawable(
|
||||||
|
home: Pair<Double, Double>?,
|
||||||
|
antennaAzimuthDeg: Double,
|
||||||
|
antennaBeamWidthDeg: Double,
|
||||||
|
maxQrbKm: Double,
|
||||||
|
): Boolean = home != null && antennaAzimuthDeg.isFinite() &&
|
||||||
|
antennaBeamWidthDeg.isFinite() && antennaBeamWidthDeg > 0.0 &&
|
||||||
|
maxQrbKm.isFinite() && maxQrbKm > 0.0
|
||||||
|
|
||||||
fun calculateDestinationPoint(
|
fun calculateDestinationPoint(
|
||||||
startLatDeg: Double,
|
startLatDeg: Double,
|
||||||
startLonDeg: Double,
|
startLonDeg: Double,
|
||||||
@@ -864,6 +1030,9 @@ private const val GRID_LINE_WIDTH_PX = 1.4f
|
|||||||
private val GRID_LABEL_COLOR = Color(0xFF63067A)
|
private val GRID_LABEL_COLOR = Color(0xFF63067A)
|
||||||
private val GRID_LABEL_BACKGROUND_LIGHT = Color.White.copy(alpha = 0.18f)
|
private val GRID_LABEL_BACKGROUND_LIGHT = Color.White.copy(alpha = 0.18f)
|
||||||
private val GRID_LABEL_BACKGROUND_DARK = Color(0xFF22262B).copy(alpha = 0.20f)
|
private val GRID_LABEL_BACKGROUND_DARK = Color(0xFF22262B).copy(alpha = 0.20f)
|
||||||
|
private val WORKED_GRID_FILL = Color.Black.copy(alpha = 0.30f)
|
||||||
|
private val WORKED_GRID_BORDER = Color.Black
|
||||||
|
private const val WORKED_GRID_BORDER_WIDTH_PX = 3f
|
||||||
private const val GRID_LABEL_PADDING_PX = 3f
|
private const val GRID_LABEL_PADDING_PX = 3f
|
||||||
|
|
||||||
private val DOT_FILL = Color(0xFF1D1D1D)
|
private val DOT_FILL = Color(0xFF1D1D1D)
|
||||||
@@ -898,16 +1067,20 @@ private const val CLUSTER_RADIUS_SMALL_PX = 16f
|
|||||||
private const val CLUSTER_RADIUS_MEDIUM_PX = 18f
|
private const val CLUSTER_RADIUS_MEDIUM_PX = 18f
|
||||||
private const val CLUSTER_RADIUS_LARGE_PX = 21f
|
private const val CLUSTER_RADIUS_LARGE_PX = 21f
|
||||||
|
|
||||||
private val BEAM_COLOR = Color(0xFFFF4D4D)
|
internal val ANTENNA_OVERLAY_COLOR = Color(0xFFFF4D4D)
|
||||||
private const val BEAM_FILL_ALPHA = 0.12f
|
private const val BEAM_FILL_ALPHA = 0.12f
|
||||||
private const val BEAM_STROKE_WIDTH_PX = 2f
|
private const val BEAM_STROKE_WIDTH_PX = 2f
|
||||||
private const val HOME_RADIUS_PX = 6f
|
private const val HOME_RADIUS_PX = 6f
|
||||||
private const val HOME_INNER_RADIUS_PX = 2f
|
private const val HOME_INNER_RADIUS_PX = 2f
|
||||||
|
|
||||||
private val CONNECTION_COLOR_DARK = Color(0xFF2FD7FF)
|
private val CONNECTION_COLOR_DARK = Color(0xFF52E7FF)
|
||||||
private val CONNECTION_COLOR_LIGHT = Color(0xFF00A4CF)
|
private val CONNECTION_COLOR_LIGHT = Color(0xFF007A9E)
|
||||||
private const val CONNECTION_ALPHA = 0.85f
|
private val CONNECTION_HALO_DARK = Color.White
|
||||||
private const val CONNECTION_STROKE_WIDTH_PX = 2f
|
private val CONNECTION_HALO_LIGHT = Color.Black
|
||||||
|
private const val CONNECTION_ALPHA = 0.98f
|
||||||
|
private const val CONNECTION_HALO_ALPHA = 0.82f
|
||||||
|
private const val CONNECTION_STROKE_WIDTH_PX = 3f
|
||||||
|
private const val CONNECTION_HALO_WIDTH_PX = 5f
|
||||||
private val CONNECTION_DASH_PX = floatArrayOf(6f, 6f)
|
private val CONNECTION_DASH_PX = floatArrayOf(6f, 6f)
|
||||||
|
|
||||||
private val TOOLTIP_BACKGROUND = Color.White.copy(alpha = 0.92f)
|
private val TOOLTIP_BACKGROUND = Color.White.copy(alpha = 0.92f)
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package kst4contest.view.compose.map
|
||||||
|
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import kst4contest.model.ChatPreferences
|
||||||
|
|
||||||
|
/** Compose-observable map geometry read from the active profile. */
|
||||||
|
internal class MapDisplaySettingsState(private val prefs: ChatPreferences) {
|
||||||
|
|
||||||
|
var antennaBeamWidthDeg: Double by mutableStateOf(prefs.stn_antennaBeamWidthDeg)
|
||||||
|
private set
|
||||||
|
|
||||||
|
var maxQrbKm: Double by mutableStateOf(prefs.stn_maxQRBDefault)
|
||||||
|
private set
|
||||||
|
|
||||||
|
fun refreshFromPreferences() {
|
||||||
|
antennaBeamWidthDeg = prefs.stn_antennaBeamWidthDeg
|
||||||
|
maxQrbKm = prefs.stn_maxQRBDefault
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package kst4contest.view.compose.map
|
||||||
|
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import kst4contest.view.compose.StationIdentity
|
||||||
|
|
||||||
|
/** A deliberate operator action that may move the station-map camera. */
|
||||||
|
internal sealed interface MapNavigationRequest {
|
||||||
|
data class FitSelectedPath(val identity: StationIdentity) : MapNavigationRequest
|
||||||
|
|
||||||
|
data class CenterOnQtf(val qtfDegrees: Double) : MapNavigationRequest
|
||||||
|
|
||||||
|
data object ResetToHome : MapNavigationRequest
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* The latest deliberate map-navigation request.
|
||||||
|
*
|
||||||
|
* Ordinary model refreshes never write this state. Keeping one monotonically increasing
|
||||||
|
* revision makes repeated selections observable and gives the most recent station or QTF
|
||||||
|
* action deterministic precedence when several actions happen before the map draws.
|
||||||
|
*/
|
||||||
|
internal class MapNavigationState {
|
||||||
|
|
||||||
|
var request: MapNavigationRequest? by mutableStateOf(null)
|
||||||
|
private set
|
||||||
|
|
||||||
|
var requestRevision: Long by mutableStateOf(0L)
|
||||||
|
private set
|
||||||
|
|
||||||
|
fun fitSelectedPath(identity: StationIdentity) {
|
||||||
|
publish(MapNavigationRequest.FitSelectedPath(identity))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun centerOnQtf(qtfDegrees: Double) {
|
||||||
|
if (!qtfDegrees.isFinite() || qtfDegrees !in 0.0..360.0) return
|
||||||
|
publish(MapNavigationRequest.CenterOnQtf(qtfDegrees))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun resetToHome() {
|
||||||
|
publish(MapNavigationRequest.ResetToHome)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun publish(next: MapNavigationRequest) {
|
||||||
|
request = next
|
||||||
|
requestRevision++
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package kst4contest.view.compose.map
|
||||||
|
|
||||||
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
|
import androidx.compose.foundation.TooltipArea
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
||||||
|
import androidx.compose.foundation.layout.FlowRow
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.platform.testTag
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import kst4contest.view.compose.TooltipCard
|
||||||
|
import kst4contest.view.i18n.LocalStrings
|
||||||
|
|
||||||
|
@OptIn(ExperimentalFoundationApi::class, ExperimentalLayoutApi::class)
|
||||||
|
@Composable
|
||||||
|
internal fun MapOverlayLegend(
|
||||||
|
showAntenna: Boolean,
|
||||||
|
showSpatialFilters: Boolean,
|
||||||
|
darkMode: Boolean,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
) {
|
||||||
|
if (!showAntenna && !showSpatialFilters) return
|
||||||
|
|
||||||
|
val strings = LocalStrings.current
|
||||||
|
TooltipArea(
|
||||||
|
tooltip = { TooltipCard(strings.mapOverlayLegendTooltip) },
|
||||||
|
modifier = modifier,
|
||||||
|
) {
|
||||||
|
FlowRow(
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||||
|
itemVerticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
if (showAntenna) {
|
||||||
|
LegendItem(
|
||||||
|
color = ANTENNA_OVERLAY_COLOR,
|
||||||
|
label = strings.mapOverlayAntenna,
|
||||||
|
tag = MAP_ANTENNA_LEGEND_TAG,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (showSpatialFilters) {
|
||||||
|
LegendItem(
|
||||||
|
color = spatialFilterOverlayLineColor(darkMode),
|
||||||
|
label = strings.mapOverlayFilters,
|
||||||
|
tag = MAP_FILTER_LEGEND_TAG,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun LegendItem(color: Color, label: String, tag: String) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.testTag(tag),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
androidx.compose.foundation.layout.Box(
|
||||||
|
Modifier
|
||||||
|
.size(9.dp)
|
||||||
|
.clip(androidx.compose.foundation.shape.CircleShape)
|
||||||
|
.background(color),
|
||||||
|
)
|
||||||
|
Text(text = label, style = MaterialTheme.typography.bodySmall)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal const val MAP_ANTENNA_LEGEND_TAG = "station-map-antenna-legend"
|
||||||
|
internal const val MAP_FILTER_LEGEND_TAG = "station-map-filter-legend"
|
||||||
@@ -0,0 +1,273 @@
|
|||||||
|
package kst4contest.view.compose.map
|
||||||
|
|
||||||
|
import androidx.compose.ui.geometry.Offset
|
||||||
|
import androidx.compose.ui.geometry.Rect
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.graphics.Path
|
||||||
|
import androidx.compose.ui.graphics.PathEffect
|
||||||
|
import androidx.compose.ui.graphics.PathFillType
|
||||||
|
import androidx.compose.ui.graphics.drawscope.DrawScope
|
||||||
|
import androidx.compose.ui.graphics.drawscope.Fill
|
||||||
|
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||||
|
import kst4contest.locatorUtils.DirectionUtils
|
||||||
|
import kst4contest.view.map.MapViewport
|
||||||
|
import kst4contest.view.map.PathGeometryUtils
|
||||||
|
import kotlin.math.ceil
|
||||||
|
|
||||||
|
/** Immutable effective QTF/QRB filter values drawn by the station map. */
|
||||||
|
data class SpatialFilterOverlayState(
|
||||||
|
val qtfEnabled: Boolean,
|
||||||
|
val qtfDegrees: Double,
|
||||||
|
val beamWidthDeg: Double,
|
||||||
|
val minQrbEnabled: Boolean,
|
||||||
|
val minQrbKm: Double,
|
||||||
|
val maxQrbEnabled: Boolean,
|
||||||
|
val maxQrbKm: Double,
|
||||||
|
) {
|
||||||
|
val isActive: Boolean
|
||||||
|
get() = qtfEnabled || minQrbEnabled || maxQrbEnabled
|
||||||
|
|
||||||
|
val hasEmptyDistanceRange: Boolean
|
||||||
|
get() = minQrbEnabled && maxQrbEnabled && minQrbKm >= maxQrbKm
|
||||||
|
|
||||||
|
val hasRenderableValues: Boolean
|
||||||
|
get() = (!qtfEnabled || qtfDegrees.isFinite() && beamWidthDeg.isFinite()) &&
|
||||||
|
(!minQrbEnabled || minQrbKm.isFinite()) &&
|
||||||
|
(!maxQrbEnabled || maxQrbKm.isFinite())
|
||||||
|
|
||||||
|
/** True when the current values produce at least one visible fill or boundary. */
|
||||||
|
val hasDrawableGeometry: Boolean
|
||||||
|
get() {
|
||||||
|
if (!isActive || !hasRenderableValues) return false
|
||||||
|
if (minQrbEnabled && !maxQrbEnabled) return true
|
||||||
|
if (minQrbEnabled && minQrbKm > 0.0) return true
|
||||||
|
if (maxQrbEnabled && maxQrbKm > 0.0) return true
|
||||||
|
return qtfEnabled && !maxQrbEnabled
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Mirrors the filter predicate: minimum exclusive, maximum inclusive. */
|
||||||
|
fun accepts(distanceKm: Double, bearingDeg: Double): Boolean {
|
||||||
|
if (!distanceKm.isFinite() || !bearingDeg.isFinite()) return false
|
||||||
|
if (minQrbEnabled && distanceKm <= minQrbKm) return false
|
||||||
|
if (maxQrbEnabled && distanceKm > maxQrbKm) return false
|
||||||
|
if (qtfEnabled && !DirectionUtils.isAngleInRange(bearingDeg, qtfDegrees, beamWidthDeg)) return false
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun DrawScope.drawSpatialFilterOverlay(
|
||||||
|
viewport: MapViewport,
|
||||||
|
homeLatitudeDeg: Double,
|
||||||
|
homeLongitudeDeg: Double,
|
||||||
|
state: SpatialFilterOverlayState,
|
||||||
|
darkMode: Boolean,
|
||||||
|
) {
|
||||||
|
if (!state.hasDrawableGeometry ||
|
||||||
|
!homeLatitudeDeg.isFinite() || !homeLongitudeDeg.isFinite()
|
||||||
|
) return
|
||||||
|
|
||||||
|
val fillColor = if (darkMode) FILTER_FILL_DARK else FILTER_FILL_LIGHT
|
||||||
|
val lineColor = spatialFilterOverlayLineColor(darkMode)
|
||||||
|
val angular = state.qtfEnabled && state.beamWidthDeg.isFinite()
|
||||||
|
val validAngularArea = !angular || state.beamWidthDeg > 0.0 && state.beamWidthDeg < 360.0
|
||||||
|
val visibleRadius = visibleRadiusKm(viewport, homeLatitudeDeg, homeLongitudeDeg)
|
||||||
|
val outerRadius = if (state.maxQrbEnabled) state.maxQrbKm else visibleRadius
|
||||||
|
val innerRadius = if (state.minQrbEnabled) state.minQrbKm else 0.0
|
||||||
|
|
||||||
|
if (!state.hasEmptyDistanceRange && validAngularArea && outerRadius > innerRadius && outerRadius > 0.0) {
|
||||||
|
val fillPath = when {
|
||||||
|
angular -> annularSectorPath(
|
||||||
|
viewport,
|
||||||
|
homeLatitudeDeg,
|
||||||
|
homeLongitudeDeg,
|
||||||
|
state.qtfDegrees,
|
||||||
|
state.beamWidthDeg,
|
||||||
|
innerRadius.coerceAtLeast(0.0),
|
||||||
|
outerRadius,
|
||||||
|
)
|
||||||
|
|
||||||
|
state.minQrbEnabled && !state.maxQrbEnabled -> outsideCirclePath(
|
||||||
|
viewport,
|
||||||
|
homeLatitudeDeg,
|
||||||
|
homeLongitudeDeg,
|
||||||
|
innerRadius.coerceAtLeast(0.0),
|
||||||
|
)
|
||||||
|
|
||||||
|
else -> ringPath(
|
||||||
|
viewport,
|
||||||
|
homeLatitudeDeg,
|
||||||
|
homeLongitudeDeg,
|
||||||
|
innerRadius.coerceAtLeast(0.0),
|
||||||
|
outerRadius,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
drawPath(fillPath, fillColor, style = Fill)
|
||||||
|
}
|
||||||
|
|
||||||
|
val stroke = Stroke(
|
||||||
|
width = FILTER_LINE_WIDTH_PX,
|
||||||
|
pathEffect = PathEffect.dashPathEffect(FILTER_DASH_PX),
|
||||||
|
)
|
||||||
|
if (state.minQrbEnabled && state.minQrbKm > 0.0) {
|
||||||
|
drawPath(circlePath(viewport, homeLatitudeDeg, homeLongitudeDeg, state.minQrbKm), lineColor, style = stroke)
|
||||||
|
}
|
||||||
|
if (state.maxQrbEnabled && state.maxQrbKm > 0.0) {
|
||||||
|
drawPath(circlePath(viewport, homeLatitudeDeg, homeLongitudeDeg, state.maxQrbKm), lineColor, style = stroke)
|
||||||
|
}
|
||||||
|
if (angular) {
|
||||||
|
val boundaryRadius = if (state.maxQrbEnabled) state.maxQrbKm else visibleRadius
|
||||||
|
val halfWidth = state.beamWidthDeg.coerceAtLeast(0.0) / 2.0
|
||||||
|
listOf(state.qtfDegrees - halfWidth, state.qtfDegrees + halfWidth).forEach { bearing ->
|
||||||
|
val endpoint = calculateDestinationPoint(
|
||||||
|
homeLatitudeDeg,
|
||||||
|
homeLongitudeDeg,
|
||||||
|
bearing,
|
||||||
|
boundaryRadius,
|
||||||
|
)
|
||||||
|
drawLine(
|
||||||
|
color = lineColor,
|
||||||
|
start = Offset(
|
||||||
|
viewport.screenXWrapped(homeLongitudeDeg).toFloat(),
|
||||||
|
viewport.screenY(homeLatitudeDeg).toFloat(),
|
||||||
|
),
|
||||||
|
end = Offset(
|
||||||
|
viewport.screenXWrapped(endpoint.second).toFloat(),
|
||||||
|
viewport.screenY(endpoint.first).toFloat(),
|
||||||
|
),
|
||||||
|
strokeWidth = FILTER_LINE_WIDTH_PX,
|
||||||
|
pathEffect = PathEffect.dashPathEffect(FILTER_DASH_PX),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun outsideCirclePath(
|
||||||
|
viewport: MapViewport,
|
||||||
|
homeLatitudeDeg: Double,
|
||||||
|
homeLongitudeDeg: Double,
|
||||||
|
radiusKm: Double,
|
||||||
|
): Path = Path().apply {
|
||||||
|
fillType = PathFillType.EvenOdd
|
||||||
|
addRect(Rect(0f, 0f, viewport.widthPx().toFloat(), viewport.heightPx().toFloat()))
|
||||||
|
addPath(circlePath(viewport, homeLatitudeDeg, homeLongitudeDeg, radiusKm))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun ringPath(
|
||||||
|
viewport: MapViewport,
|
||||||
|
homeLatitudeDeg: Double,
|
||||||
|
homeLongitudeDeg: Double,
|
||||||
|
innerRadiusKm: Double,
|
||||||
|
outerRadiusKm: Double,
|
||||||
|
): Path = Path().apply {
|
||||||
|
fillType = PathFillType.EvenOdd
|
||||||
|
addPath(circlePath(viewport, homeLatitudeDeg, homeLongitudeDeg, outerRadiusKm))
|
||||||
|
if (innerRadiusKm > 0.0) {
|
||||||
|
addPath(circlePath(viewport, homeLatitudeDeg, homeLongitudeDeg, innerRadiusKm))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun annularSectorPath(
|
||||||
|
viewport: MapViewport,
|
||||||
|
homeLatitudeDeg: Double,
|
||||||
|
homeLongitudeDeg: Double,
|
||||||
|
centerBearingDeg: Double,
|
||||||
|
beamWidthDeg: Double,
|
||||||
|
innerRadiusKm: Double,
|
||||||
|
outerRadiusKm: Double,
|
||||||
|
): Path {
|
||||||
|
val halfWidth = beamWidthDeg / 2.0
|
||||||
|
val outer = arcPoints(
|
||||||
|
homeLatitudeDeg,
|
||||||
|
homeLongitudeDeg,
|
||||||
|
centerBearingDeg - halfWidth,
|
||||||
|
beamWidthDeg,
|
||||||
|
outerRadiusKm,
|
||||||
|
)
|
||||||
|
val inner = if (innerRadiusKm > 0.0) {
|
||||||
|
arcPoints(
|
||||||
|
homeLatitudeDeg,
|
||||||
|
homeLongitudeDeg,
|
||||||
|
centerBearingDeg - halfWidth,
|
||||||
|
beamWidthDeg,
|
||||||
|
innerRadiusKm,
|
||||||
|
).asReversed()
|
||||||
|
} else {
|
||||||
|
listOf(homeLatitudeDeg to homeLongitudeDeg)
|
||||||
|
}
|
||||||
|
|
||||||
|
return pathThrough(viewport, outer + inner, close = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun circlePath(
|
||||||
|
viewport: MapViewport,
|
||||||
|
homeLatitudeDeg: Double,
|
||||||
|
homeLongitudeDeg: Double,
|
||||||
|
radiusKm: Double,
|
||||||
|
): Path = pathThrough(
|
||||||
|
viewport,
|
||||||
|
arcPoints(homeLatitudeDeg, homeLongitudeDeg, 0.0, 360.0, radiusKm),
|
||||||
|
close = true,
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun arcPoints(
|
||||||
|
homeLatitudeDeg: Double,
|
||||||
|
homeLongitudeDeg: Double,
|
||||||
|
startBearingDeg: Double,
|
||||||
|
sweepDeg: Double,
|
||||||
|
radiusKm: Double,
|
||||||
|
): List<Pair<Double, Double>> {
|
||||||
|
val segmentCount = maxOf(24, ceil(kotlin.math.abs(sweepDeg) / 3.0).toInt())
|
||||||
|
return (0..segmentCount).map { segment ->
|
||||||
|
calculateDestinationPoint(
|
||||||
|
homeLatitudeDeg,
|
||||||
|
homeLongitudeDeg,
|
||||||
|
startBearingDeg + sweepDeg * segment / segmentCount,
|
||||||
|
radiusKm,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun pathThrough(
|
||||||
|
viewport: MapViewport,
|
||||||
|
points: List<Pair<Double, Double>>,
|
||||||
|
close: Boolean,
|
||||||
|
): Path = Path().apply {
|
||||||
|
points.forEachIndexed { index, point ->
|
||||||
|
val x = viewport.screenXWrapped(point.second).toFloat()
|
||||||
|
val y = viewport.screenY(point.first).toFloat()
|
||||||
|
if (index == 0) moveTo(x, y) else lineTo(x, y)
|
||||||
|
}
|
||||||
|
if (close && points.isNotEmpty()) close()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun visibleRadiusKm(
|
||||||
|
viewport: MapViewport,
|
||||||
|
homeLatitudeDeg: Double,
|
||||||
|
homeLongitudeDeg: Double,
|
||||||
|
): Double {
|
||||||
|
val corners = listOf(
|
||||||
|
viewport.northLat() to viewport.westLon(),
|
||||||
|
viewport.northLat() to viewport.eastLon(),
|
||||||
|
viewport.southLat() to viewport.westLon(),
|
||||||
|
viewport.southLat() to viewport.eastLon(),
|
||||||
|
)
|
||||||
|
val farthestCorner = corners.maxOfOrNull { (latitude, longitude) ->
|
||||||
|
PathGeometryUtils.calculateGreatCircleDistanceKm(
|
||||||
|
homeLatitudeDeg,
|
||||||
|
homeLongitudeDeg,
|
||||||
|
latitude,
|
||||||
|
longitude,
|
||||||
|
)
|
||||||
|
} ?: 0.0
|
||||||
|
return farthestCorner * VIEWPORT_RADIUS_MARGIN
|
||||||
|
}
|
||||||
|
|
||||||
|
private val FILTER_FILL_LIGHT = Color(0xFF5B4BC4).copy(alpha = 0.16f)
|
||||||
|
private val FILTER_FILL_DARK = Color(0xFF78A9FF).copy(alpha = 0.18f)
|
||||||
|
private val FILTER_LINE_LIGHT = Color(0xFF4937B8).copy(alpha = 0.88f)
|
||||||
|
private val FILTER_LINE_DARK = Color(0xFF8CB8FF).copy(alpha = 0.92f)
|
||||||
|
internal fun spatialFilterOverlayLineColor(darkMode: Boolean): Color =
|
||||||
|
if (darkMode) FILTER_LINE_DARK else FILTER_LINE_LIGHT
|
||||||
|
private const val FILTER_LINE_WIDTH_PX = 2f
|
||||||
|
private val FILTER_DASH_PX = floatArrayOf(7f, 5f)
|
||||||
|
private const val VIEWPORT_RADIUS_MARGIN = 1.12
|
||||||
@@ -11,6 +11,8 @@ import androidx.compose.runtime.*
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.alpha
|
import androidx.compose.ui.draw.alpha
|
||||||
|
import androidx.compose.ui.geometry.Size
|
||||||
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.platform.testTag
|
import androidx.compose.ui.platform.testTag
|
||||||
import androidx.compose.ui.text.font.FontStyle
|
import androidx.compose.ui.text.font.FontStyle
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
@@ -20,13 +22,21 @@ import kst4contest.view.ApplicationRuntimeLauncher
|
|||||||
import kst4contest.view.compose.PaletteStore
|
import kst4contest.view.compose.PaletteStore
|
||||||
import kst4contest.view.compose.ComposeWindowHost
|
import kst4contest.view.compose.ComposeWindowHost
|
||||||
import kst4contest.view.compose.MainWindowState
|
import kst4contest.view.compose.MainWindowState
|
||||||
|
import kst4contest.view.compose.StationIdentity
|
||||||
|
import kst4contest.view.compose.StationContextMenuState
|
||||||
|
import kst4contest.view.compose.StationContextOverlays
|
||||||
|
import kst4contest.view.compose.StationSelectionSource
|
||||||
import kst4contest.view.map.MapCallsignRawSnapshotBuilder
|
import kst4contest.view.map.MapCallsignRawSnapshotBuilder
|
||||||
import kst4contest.view.map.PathAnalysisResult
|
import kst4contest.view.map.PathAnalysisResult
|
||||||
|
import kst4contest.view.map.MapViewportNavigation
|
||||||
import kst4contest.view.map.StationMapStatusText
|
import kst4contest.view.map.StationMapStatusText
|
||||||
import kst4contest.view.map.TileFetcher
|
import kst4contest.view.map.TileFetcher
|
||||||
import java.util.EnumSet
|
import java.util.EnumSet
|
||||||
|
|
||||||
@OptIn(androidx.compose.foundation.ExperimentalFoundationApi::class)
|
@OptIn(
|
||||||
|
androidx.compose.foundation.ExperimentalFoundationApi::class,
|
||||||
|
androidx.compose.foundation.layout.ExperimentalLayoutApi::class,
|
||||||
|
)
|
||||||
object StationMapWindow {
|
object StationMapWindow {
|
||||||
|
|
||||||
private val host = ComposeWindowHost("Map")
|
private val host = ComposeWindowHost("Map")
|
||||||
@@ -60,14 +70,16 @@ object StationMapWindow {
|
|||||||
widthDp = widthDp,
|
widthDp = widthDp,
|
||||||
heightDp = heightDp,
|
heightDp = heightDp,
|
||||||
onResized = onResized,
|
onResized = onResized,
|
||||||
|
alwaysOnTop = mainWindowState.prefs.isGUIstationMapAlwaysOnTop,
|
||||||
) { _ ->
|
) { _ ->
|
||||||
val window = this.window
|
val window = this.window
|
||||||
/*
|
/*
|
||||||
* Never larger than the smallest screen: AWT enforces a minimum size even past
|
* Never larger than the smallest screen: AWT enforces a minimum size even past
|
||||||
* the edge, and some operators work on 640x480.
|
* the edge, and some operators work on 640x480.
|
||||||
*/
|
*/
|
||||||
androidx.compose.runtime.LaunchedEffect(window) {
|
androidx.compose.runtime.LaunchedEffect(window, mainWindowState.prefs.isGUIstationMapAlwaysOnTop) {
|
||||||
window?.minimumSize = WindowPlacementOnScreen.minimumSizeOnScreens(900, 600)
|
window?.minimumSize = WindowPlacementOnScreen.minimumSizeOnScreens(900, 600)
|
||||||
|
window?.isAlwaysOnTop = mainWindowState.prefs.isGUIstationMapAlwaysOnTop
|
||||||
}
|
}
|
||||||
val tileFetcher = remember { TileFetcher() }
|
val tileFetcher = remember { TileFetcher() }
|
||||||
|
|
||||||
@@ -80,7 +92,11 @@ object StationMapWindow {
|
|||||||
onDispose { tileFetcher.close() }
|
onDispose { tileFetcher.close() }
|
||||||
}
|
}
|
||||||
|
|
||||||
Content(mainWindowState = mainWindowState, tileFetcher = tileFetcher)
|
Content(
|
||||||
|
mainWindowState = mainWindowState,
|
||||||
|
tileFetcher = tileFetcher,
|
||||||
|
onAlwaysOnTopChanged = { enabled -> window?.isAlwaysOnTop = enabled },
|
||||||
|
)
|
||||||
} // host.show content
|
} // host.show content
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,9 +111,8 @@ object StationMapWindow {
|
|||||||
* @param chatMembers the roster a marker click looks its station up in; a marker stands
|
* @param chatMembers the roster a marker click looks its station up in; a marker stands
|
||||||
* for a raw callsign, and this is where its category variants come from
|
* for a raw callsign, and this is where its category variants come from
|
||||||
* @param mapState where the map is looking
|
* @param mapState where the map is looking
|
||||||
* @param pathAnalysis asked each time the selection changes; null means there is no
|
* @param pathAnalysis asked for an explicit selection; null disables only the terrain
|
||||||
* running application, and then the map neither pans nor analyses, exactly as
|
* analysis while viewport navigation remains available
|
||||||
* when no chat controller existed before the split
|
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
internal fun Content(
|
internal fun Content(
|
||||||
@@ -108,6 +123,7 @@ object StationMapWindow {
|
|||||||
},
|
},
|
||||||
mapState: MapState = remember { MapState() },
|
mapState: MapState = remember { MapState() },
|
||||||
pathAnalysis: () -> MapPathAnalysis? = ::runtimePathAnalysis,
|
pathAnalysis: () -> MapPathAnalysis? = ::runtimePathAnalysis,
|
||||||
|
onAlwaysOnTopChanged: (Boolean) -> Unit = { },
|
||||||
) {
|
) {
|
||||||
val strings = LocalStrings.current
|
val strings = LocalStrings.current
|
||||||
|
|
||||||
@@ -128,13 +144,17 @@ object StationMapWindow {
|
|||||||
|
|
||||||
var groupingEnabled by remember { mutableStateOf(prefs.isGUIstationMapClusteringEnabled) }
|
var groupingEnabled by remember { mutableStateOf(prefs.isGUIstationMapClusteringEnabled) }
|
||||||
var pathAnalysisVisible by remember { mutableStateOf(prefs.isGUIstationMapPathAnalysisVisible) }
|
var pathAnalysisVisible by remember { mutableStateOf(prefs.isGUIstationMapPathAnalysisVisible) }
|
||||||
|
var alwaysOnTop by remember { mutableStateOf(prefs.isGUIstationMapAlwaysOnTop) }
|
||||||
|
val stationContextMenu = remember(mainWindowState) {
|
||||||
|
StationContextMenuState(mainWindowState::selectStation)
|
||||||
|
}
|
||||||
|
|
||||||
val selectedMember = mainWindowState.selectedStation.selected
|
val selectedMember = mainWindowState.selectedStation.selected
|
||||||
|
|
||||||
val ownLocator6 by remember { androidx.compose.runtime.mutableStateOf(mainWindowState.prefs.stn_loginLocatorMainCat) }
|
val ownLocator6 by remember { androidx.compose.runtime.mutableStateOf(mainWindowState.prefs.stn_loginLocatorMainCat) }
|
||||||
val antennaAzimuthDeg = mainWindowState.antennaQtf.value
|
val antennaAzimuthDeg = mainWindowState.antennaQtf.value
|
||||||
val antennaBeamWidthDeg = mainWindowState.prefs.stn_antennaBeamWidthDeg
|
val antennaBeamWidthDeg = mainWindowState.mapDisplaySettings.antennaBeamWidthDeg
|
||||||
val maxQrbKm = mainWindowState.prefs.stn_maxQRBDefault
|
val maxQrbKm = mainWindowState.mapDisplaySettings.maxQrbKm
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The markers are the stations the list shows, not all of them (#21): the
|
* The markers are the stations the list shows, not all of them (#21): the
|
||||||
@@ -159,59 +179,60 @@ object StationMapWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
builder.buildSnapshots(
|
builder.buildSnapshots(
|
||||||
mainWindowState.stations.visibleRows,
|
mainWindowState.stations.filteredRows,
|
||||||
selectedMember,
|
selectedMember,
|
||||||
bandSet
|
bandSet
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Selection is independent of the filtered marker set. A selected station
|
||||||
|
* remains a target even when an active filter removes its normal marker; it is
|
||||||
|
* drawn in a separate selection layer and never enters marker counts or clusters.
|
||||||
|
*/
|
||||||
|
val selectedTarget by remember(
|
||||||
|
selectedMember,
|
||||||
|
mainWindowState.stations.contentRevision,
|
||||||
|
mainWindowState.activeBands,
|
||||||
|
) {
|
||||||
|
derivedStateOf {
|
||||||
|
selectedMember?.let { selected ->
|
||||||
|
val variants = chatMembers().filter { it.callSignRaw == selected.callSignRaw }
|
||||||
|
.ifEmpty { listOf(selected) }
|
||||||
|
val bands = EnumSet.noneOf(Band::class.java).apply {
|
||||||
|
addAll(mainWindowState.activeBands)
|
||||||
|
}
|
||||||
|
MapCallsignRawSnapshotBuilder()
|
||||||
|
.buildSnapshots(variants, selected, bands)
|
||||||
|
.firstOrNull()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var pathAnalysisResult by remember { mutableStateOf<PathAnalysisResult?>(null) }
|
var pathAnalysisResult by remember { mutableStateOf<PathAnalysisResult?>(null) }
|
||||||
|
var automaticAnalysisRevision by remember { mutableStateOf(0L) }
|
||||||
|
|
||||||
// Read through updated state so a caller passing a new lambda is never served a stale one.
|
// Read through updated state so a caller passing a new lambda is never served a stale one.
|
||||||
val currentPathAnalysis by rememberUpdatedState(pathAnalysis)
|
val currentPathAnalysis by rememberUpdatedState(pathAnalysis)
|
||||||
|
|
||||||
/*
|
LaunchedEffect(mainWindowState.stationSelection.explicitSelectionRevision) {
|
||||||
* Whether the selected station has a marker. A filter can hide it (#21), and a
|
val automaticRequest = ++automaticAnalysisRevision
|
||||||
* station without a locator never has one; then there is nothing to analyse.
|
val explicitRevisionAtStart = mainWindowState.mapReachability.requestRevision
|
||||||
*/
|
|
||||||
val selectedHasMarker = selectedMember != null &&
|
|
||||||
markers.any { it.callSignRaw() == selectedMember.callSignRaw }
|
|
||||||
|
|
||||||
LaunchedEffect(selectedMember, selectedHasMarker) {
|
|
||||||
if (selectedMember == null) {
|
if (selectedMember == null) {
|
||||||
pathAnalysisResult = null
|
pathAnalysisResult = null
|
||||||
return@LaunchedEffect
|
return@LaunchedEffect
|
||||||
}
|
}
|
||||||
|
|
||||||
val selectedSnapshot = markers.find { it.callSignRaw() == selectedMember.callSignRaw }
|
val selectedSnapshot = selectedTarget
|
||||||
if (selectedSnapshot == null) {
|
if (selectedSnapshot == null) {
|
||||||
// No marker: no request, and no "Loading" for a station the map does not show.
|
// No valid locator: no request and no misleading loading state.
|
||||||
pathAnalysisResult = null
|
pathAnalysisResult = null
|
||||||
return@LaunchedEffect
|
return@LaunchedEffect
|
||||||
}
|
}
|
||||||
|
|
||||||
val analysis = currentPathAnalysis()
|
val analysis = currentPathAnalysis()
|
||||||
if (analysis != null) {
|
if (analysis != null) {
|
||||||
if (selectedSnapshot.hasUsablePosition()) {
|
|
||||||
/*
|
|
||||||
* Pan to the station and leave the zoom alone. The Leaflet map
|
|
||||||
* did exactly this (focusCallsignRaw) and touched the zoom only
|
|
||||||
* when the station was hidden inside a bubble, and then only far
|
|
||||||
* enough to break the bubble open. An earlier Compose version
|
|
||||||
* recomputed a zoom from a bounding box on every selection and
|
|
||||||
* clamped it into 4..12, which threw an operator working at zoom
|
|
||||||
* 15 out to about 7 every time they picked the next station.
|
|
||||||
* AGENTS.md names zoom first among the things not to change as
|
|
||||||
* an incidental side effect.
|
|
||||||
*/
|
|
||||||
mapState.centerLon = selectedSnapshot.longitudeDeg()
|
|
||||||
mapState.centerLat = selectedSnapshot.latitudeDeg()
|
|
||||||
mapState.zoom = kst4contest.view.map.StationMapClusterer
|
|
||||||
.zoomToRevealStations(mapState.zoom.toDouble(), groupingEnabled)
|
|
||||||
.toFloat()
|
|
||||||
}
|
|
||||||
|
|
||||||
pathAnalysisResult = PathAnalysisResult.loading(
|
pathAnalysisResult = PathAnalysisResult.loading(
|
||||||
prefs.stn_loginLocatorMainCat,
|
prefs.stn_loginLocatorMainCat,
|
||||||
selectedSnapshot.locator6(),
|
selectedSnapshot.locator6(),
|
||||||
@@ -219,11 +240,115 @@ object StationMapWindow {
|
|||||||
)
|
)
|
||||||
|
|
||||||
analysis.request(selectedMember, selectedSnapshot) { result ->
|
analysis.request(selectedMember, selectedSnapshot) { result ->
|
||||||
pathAnalysisResult = result
|
if (automaticAnalysisRevision == automaticRequest &&
|
||||||
|
mainWindowState.mapReachability.requestRevision == explicitRevisionAtStart
|
||||||
|
) {
|
||||||
|
pathAnalysisResult = result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var mapCanvasSize by remember { mutableStateOf(Size.Zero) }
|
||||||
|
var consumedNavigationRevision by remember(mapState) { mutableStateOf(Long.MIN_VALUE) }
|
||||||
|
val navigationRevision = mainWindowState.mapNavigation.requestRevision
|
||||||
|
val navigationRequest = mainWindowState.mapNavigation.request
|
||||||
|
val navigationPaddingPx = with(LocalDensity.current) { 40.dp.toPx().toDouble() }
|
||||||
|
|
||||||
|
LaunchedEffect(
|
||||||
|
navigationRevision,
|
||||||
|
navigationRequest,
|
||||||
|
mapCanvasSize,
|
||||||
|
selectedTarget,
|
||||||
|
ownLocator6,
|
||||||
|
) {
|
||||||
|
if (navigationRevision == consumedNavigationRevision ||
|
||||||
|
mapCanvasSize.width <= 0f || mapCanvasSize.height <= 0f
|
||||||
|
) {
|
||||||
|
return@LaunchedEffect
|
||||||
|
}
|
||||||
|
|
||||||
|
val home = runCatching { kst4contest.locatorUtils.Location(ownLocator6) }.getOrNull()
|
||||||
|
val current = mapState.viewportFor(mapCanvasSize.width, mapCanvasSize.height)
|
||||||
|
val next = when (val request = navigationRequest) {
|
||||||
|
is MapNavigationRequest.FitSelectedPath -> {
|
||||||
|
val target = selectedTarget
|
||||||
|
if (home == null || target == null || !target.hasUsablePosition() ||
|
||||||
|
request.identity != StationIdentity.of(selectedMember)
|
||||||
|
) {
|
||||||
|
null
|
||||||
|
} else {
|
||||||
|
MapViewportNavigation.fitPath(
|
||||||
|
current,
|
||||||
|
home.latitude.toDegrees(),
|
||||||
|
home.longitude.toDegrees(),
|
||||||
|
target.latitudeDeg(),
|
||||||
|
target.longitudeDeg(),
|
||||||
|
navigationPaddingPx,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
is MapNavigationRequest.CenterOnQtf -> {
|
||||||
|
if (home == null) null else MapViewportNavigation.centreOnBearing(
|
||||||
|
current,
|
||||||
|
home.latitude.toDegrees(),
|
||||||
|
home.longitude.toDegrees(),
|
||||||
|
request.qtfDegrees,
|
||||||
|
QTF_FORWARD_CENTRE_FRACTION,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
MapNavigationRequest.ResetToHome -> {
|
||||||
|
if (home == null) null else MapViewportNavigation.centreOnHome(
|
||||||
|
current,
|
||||||
|
home.latitude.toDegrees(),
|
||||||
|
home.longitude.toDegrees(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
null -> null
|
||||||
|
}
|
||||||
|
consumedNavigationRevision = navigationRevision
|
||||||
|
if (next != null) {
|
||||||
|
mapState.applyFrom(next)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val explicitReachabilityResult = mainWindowState.mapReachability.result
|
||||||
|
LaunchedEffect(mainWindowState.mapReachability.requestRevision, explicitReachabilityResult) {
|
||||||
|
if (explicitReachabilityResult != null) {
|
||||||
|
automaticAnalysisRevision++
|
||||||
|
pathAnalysisResult = explicitReachabilityResult
|
||||||
|
pathAnalysisVisible = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val workedGrossFields = if (mainWindowState.stationFilter.gridColouring) {
|
||||||
|
mainWindowState.stations.contentRevision
|
||||||
|
mainWindowState.workedGrossFieldsProvider()
|
||||||
|
} else {
|
||||||
|
emptySet()
|
||||||
|
}
|
||||||
|
val spatialFilterOverlay = SpatialFilterOverlayState(
|
||||||
|
qtfEnabled = mainWindowState.stationFilter.qtfEnabled,
|
||||||
|
qtfDegrees = mainWindowState.stationFilter.qtfDegrees,
|
||||||
|
beamWidthDeg = antennaBeamWidthDeg,
|
||||||
|
minQrbEnabled = mainWindowState.stationFilter.minQrbEnabled,
|
||||||
|
minQrbKm = mainWindowState.stationFilter.minQrbKm,
|
||||||
|
maxQrbEnabled = mainWindowState.stationFilter.maxQrbEnabled,
|
||||||
|
maxQrbKm = mainWindowState.stationFilter.maxQrbKm,
|
||||||
|
)
|
||||||
|
val mapHome = remember(ownLocator6) { homePosition(ownLocator6) }
|
||||||
|
val showAntennaOverlay = isAntennaSectorDrawable(
|
||||||
|
mapHome,
|
||||||
|
antennaAzimuthDeg ?: 0.0,
|
||||||
|
antennaBeamWidthDeg,
|
||||||
|
maxQrbKm,
|
||||||
|
)
|
||||||
|
val showSpatialFilterOverlay = mapHome != null && spatialFilterOverlay.hasDrawableGeometry
|
||||||
|
val isDarkTheme = isDarkThemeState.value
|
||||||
|
|
||||||
androidx.compose.material3.Surface(
|
androidx.compose.material3.Surface(
|
||||||
color = androidx.compose.material3.MaterialTheme.colorScheme.background,
|
color = androidx.compose.material3.MaterialTheme.colorScheme.background,
|
||||||
contentColor = androidx.compose.material3.MaterialTheme.colorScheme.onBackground,
|
contentColor = androidx.compose.material3.MaterialTheme.colorScheme.onBackground,
|
||||||
@@ -237,16 +362,17 @@ object StationMapWindow {
|
|||||||
* the theme's primary colour, which in the evening sheet is a bright
|
* the theme's primary colour, which in the evening sheet is a bright
|
||||||
* green, and the map window was the only one wearing it.
|
* green, and the map window was the only one wearing it.
|
||||||
*/
|
*/
|
||||||
Row(
|
FlowRow(
|
||||||
modifier = Modifier.fillMaxWidth().padding(8.dp),
|
modifier = Modifier.fillMaxWidth().padding(8.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
horizontalArrangement = Arrangement.spacedBy(10.dp),
|
||||||
horizontalArrangement = Arrangement.spacedBy(10.dp)
|
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||||
|
itemVerticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
val statusText = StationMapStatusText.build(
|
val statusText = StationMapStatusText.build(
|
||||||
markers.size,
|
markers.size,
|
||||||
mainWindowState.stationFilter.activeFilters.isNotEmpty() ||
|
mainWindowState.stationFilter.activeFilters.isNotEmpty() ||
|
||||||
mainWindowState.stationFilter.searchText.isNotBlank(),
|
mainWindowState.stationFilter.searchText.isNotBlank(),
|
||||||
markers.firstOrNull { it.callSignRaw() == selectedMember?.callSignRaw },
|
selectedTarget,
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -266,6 +392,12 @@ object StationMapWindow {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MapOverlayLegend(
|
||||||
|
showAntenna = showAntennaOverlay,
|
||||||
|
showSpatialFilters = showSpatialFilterOverlay,
|
||||||
|
darkMode = isDarkTheme,
|
||||||
|
)
|
||||||
|
|
||||||
if (selectedMember != null) {
|
if (selectedMember != null) {
|
||||||
kst4contest.view.compose.Form.button(strings.mapTriggerClusterSpot) {
|
kst4contest.view.compose.Form.button(strings.mapTriggerClusterSpot) {
|
||||||
ApplicationRuntimeLauncher.getCurrent()?.chatController
|
ApplicationRuntimeLauncher.getCurrent()?.chatController
|
||||||
@@ -274,22 +406,41 @@ object StationMapWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
kst4contest.view.compose.Form.button(strings.mapResetView) {
|
kst4contest.view.compose.Form.button(strings.mapResetView) {
|
||||||
mainWindowState.stationSelector?.invoke(null)
|
mainWindowState.selectStation(null, StationSelectionSource.RESET_VIEW)
|
||||||
?: mainWindowState.selectedStation.select(null)
|
}
|
||||||
val home = runCatching {
|
|
||||||
kst4contest.locatorUtils.Location(ownLocator6)
|
kst4contest.view.compose.Form.button(strings.filterReset) {
|
||||||
}.getOrNull()
|
mainWindowState.resetStationFilters()
|
||||||
mapState.centerLon = home?.longitude?.toDegrees() ?: 10.0
|
}
|
||||||
mapState.centerLat = home?.latitude?.toDegrees() ?: 51.0
|
|
||||||
/* The zoom is deliberately left alone; see AGENTS.md, UI behaviour. */
|
androidx.compose.foundation.TooltipArea(
|
||||||
|
tooltip = { kst4contest.view.compose.TooltipCard(strings.mapGroupNearbyTooltip) },
|
||||||
|
) {
|
||||||
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
|
kst4contest.view.compose.CompactCheckbox(
|
||||||
|
checked = groupingEnabled,
|
||||||
|
modifier = Modifier.testTag(GROUPING_TAG),
|
||||||
|
) {
|
||||||
|
groupingEnabled = it
|
||||||
|
prefs.isGUIstationMapClusteringEnabled = it
|
||||||
|
mainWindowState.requestLayoutSave()
|
||||||
|
}
|
||||||
|
Text(strings.mapGroupNearby, modifier = Modifier.padding(start = 4.dp))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
kst4contest.view.compose.CompactCheckbox(groupingEnabled) {
|
kst4contest.view.compose.CompactCheckbox(
|
||||||
groupingEnabled = it
|
checked = alwaysOnTop,
|
||||||
prefs.isGUIstationMapClusteringEnabled = it
|
onCheckedChange = { enabled ->
|
||||||
}
|
alwaysOnTop = enabled
|
||||||
Text(strings.mapGroupNearby, modifier = Modifier.padding(start = 4.dp))
|
prefs.isGUIstationMapAlwaysOnTop = enabled
|
||||||
|
onAlwaysOnTopChanged(enabled)
|
||||||
|
mainWindowState.requestLayoutSave()
|
||||||
|
},
|
||||||
|
modifier = Modifier.testTag(ALWAYS_ON_TOP_TAG),
|
||||||
|
)
|
||||||
|
Text(strings.mapAlwaysOnTop, modifier = Modifier.padding(start = 4.dp))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pathAnalysisVisible) {
|
if (!pathAnalysisVisible) {
|
||||||
@@ -305,6 +456,7 @@ object StationMapWindow {
|
|||||||
) {
|
) {
|
||||||
pathAnalysisVisible = !pathAnalysisVisible
|
pathAnalysisVisible = !pathAnalysisVisible
|
||||||
prefs.isGUIstationMapPathAnalysisVisible = pathAnalysisVisible
|
prefs.isGUIstationMapPathAnalysisVisible = pathAnalysisVisible
|
||||||
|
mainWindowState.requestLayoutSave()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,7 +472,6 @@ object StationMapWindow {
|
|||||||
|
|
||||||
val leftPane: @Composable () -> Unit = {
|
val leftPane: @Composable () -> Unit = {
|
||||||
Column(Modifier.fillMaxHeight()) {
|
Column(Modifier.fillMaxHeight()) {
|
||||||
val isDarkTheme = isDarkThemeState.value
|
|
||||||
androidx.compose.foundation.layout.Box(Modifier.weight(1f).fillMaxWidth()) {
|
androidx.compose.foundation.layout.Box(Modifier.weight(1f).fillMaxWidth()) {
|
||||||
ComposeStationMap(
|
ComposeStationMap(
|
||||||
markers = markers,
|
markers = markers,
|
||||||
@@ -332,7 +483,11 @@ object StationMapWindow {
|
|||||||
antennaAzimuthDeg = antennaAzimuthDeg ?: 0.0,
|
antennaAzimuthDeg = antennaAzimuthDeg ?: 0.0,
|
||||||
antennaBeamWidthDeg = antennaBeamWidthDeg,
|
antennaBeamWidthDeg = antennaBeamWidthDeg,
|
||||||
maxQrbKm = maxQrbKm,
|
maxQrbKm = maxQrbKm,
|
||||||
|
selectedTarget = selectedTarget,
|
||||||
|
spatialFilterOverlay = spatialFilterOverlay,
|
||||||
darkMode = isDarkTheme,
|
darkMode = isDarkTheme,
|
||||||
|
workedGrossFields = workedGrossFields,
|
||||||
|
onCanvasSizeChanged = { mapCanvasSize = it },
|
||||||
onMarkerClicked = { snapshot ->
|
onMarkerClicked = { snapshot ->
|
||||||
val variants = chatMembers()
|
val variants = chatMembers()
|
||||||
.filter { it.callSignRaw == snapshot.callSignRaw() }
|
.filter { it.callSignRaw == snapshot.callSignRaw() }
|
||||||
@@ -340,19 +495,28 @@ object StationMapWindow {
|
|||||||
* A marker stands for a raw callsign, not a category. Keep the
|
* A marker stands for a raw callsign, not a category. Keep the
|
||||||
* category already selected when it is one of the variants.
|
* category already selected when it is one of the variants.
|
||||||
*/
|
*/
|
||||||
val member = variants.firstOrNull { it === mainWindowState.selectedStation.selected }
|
val selectedIdentity = StationIdentity.of(mainWindowState.selectedStation.selected)
|
||||||
?: variants.firstOrNull()
|
val member = variants.firstOrNull {
|
||||||
|
StationIdentity.of(it) == selectedIdentity
|
||||||
|
} ?: variants.firstOrNull {
|
||||||
|
it.chatCategory?.categoryNumber ==
|
||||||
|
prefs.loginChatCategoryMain?.categoryNumber
|
||||||
|
} ?: variants.singleOrNull()
|
||||||
if (member != null) {
|
if (member != null) {
|
||||||
val selector = mainWindowState.stationSelector
|
mainWindowState.selectStation(member, StationSelectionSource.MAP)
|
||||||
if (selector != null) {
|
|
||||||
selector(member)
|
|
||||||
} else {
|
|
||||||
mainWindowState.selectedStation.select(member)
|
|
||||||
}
|
|
||||||
// Mirror old JavaFX handleMapCallsignSelection logic: prefill /cq
|
// Mirror old JavaFX handleMapCallsignSelection logic: prefill /cq
|
||||||
mainWindowState.chatInput.prepareCq(member.callSign ?: "", forceOverwrite = true)
|
mainWindowState.chatInput.prepareCq(member.callSign ?: "", forceOverwrite = true)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onMarkerContextRequested = { snapshots, position ->
|
||||||
|
val callsigns = snapshots.mapTo(linkedSetOf()) { it.callSignRaw() }
|
||||||
|
val candidates = chatMembers().filter { it.callSignRaw in callsigns }
|
||||||
|
stationContextMenu.open(
|
||||||
|
candidates,
|
||||||
|
StationSelectionSource.MAP_CONTEXT_MENU,
|
||||||
|
position,
|
||||||
|
)
|
||||||
|
},
|
||||||
modifier = Modifier.fillMaxSize().testTag(MAP_CANVAS_TAG)
|
modifier = Modifier.fillMaxSize().testTag(MAP_CANVAS_TAG)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -416,10 +580,14 @@ object StationMapWindow {
|
|||||||
} // main layout column
|
} // main layout column
|
||||||
} // window column
|
} // window column
|
||||||
} // Surface
|
} // Surface
|
||||||
|
StationContextOverlays(stationContextMenu, mainWindowState)
|
||||||
} // Content
|
} // Content
|
||||||
|
|
||||||
/** Marks the map canvas so a test can click a marker on it. */
|
/** Marks the map canvas so a test can click a marker on it. */
|
||||||
internal const val MAP_CANVAS_TAG = "station-map-canvas"
|
internal const val MAP_CANVAS_TAG = "station-map-canvas"
|
||||||
|
internal const val GROUPING_TAG = "station-map-grouping"
|
||||||
|
internal const val ALWAYS_ON_TOP_TAG = "station-map-always-on-top"
|
||||||
|
private const val QTF_FORWARD_CENTRE_FRACTION = 0.25
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun applyDarkMode(darkMode: Boolean) {
|
fun applyDarkMode(darkMode: Boolean) {
|
||||||
|
|||||||
@@ -4,9 +4,11 @@ import kst4contest.view.i18n.LocalStrings
|
|||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import kst4contest.view.compose.Form
|
import kst4contest.view.compose.Form
|
||||||
|
import kst4contest.view.compose.observeAsState
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The beacon tab: one CQ template per chat category and the interval they share.
|
* The beacon tab: one CQ template per chat category and the interval they share.
|
||||||
@@ -18,12 +20,14 @@ import kst4contest.view.compose.Form
|
|||||||
@Composable
|
@Composable
|
||||||
fun BeaconTab(state: BeaconTabState, onRefused: (String) -> Unit) {
|
fun BeaconTab(state: BeaconTabState, onRefused: (String) -> Unit) {
|
||||||
val strings = LocalStrings.current
|
val strings = LocalStrings.current
|
||||||
|
val mainEnabled by state.mainBeaconEnabled.observeAsState()
|
||||||
|
val secondEnabled by state.secondBeaconEnabled.observeAsState()
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||||
) {
|
) {
|
||||||
Form.section(strings.beaconSectionFor(state.mainCategoryName)) {
|
Form.section(strings.beaconSectionFor(state.mainCategoryName)) {
|
||||||
Form.check(strings.beaconEnabled, state.bcn_beaconsEnabledMainCat) {
|
Form.check(strings.beaconEnabled, mainEnabled == true) {
|
||||||
state.bcn_beaconsEnabledMainCat = it
|
state.bcn_beaconsEnabledMainCat = it
|
||||||
}
|
}
|
||||||
Form.committed(
|
Form.committed(
|
||||||
@@ -36,7 +40,7 @@ fun BeaconTab(state: BeaconTabState, onRefused: (String) -> Unit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Form.section(strings.beaconSectionFor(state.secondCategoryName)) {
|
Form.section(strings.beaconSectionFor(state.secondCategoryName)) {
|
||||||
Form.check(strings.beaconEnabled, state.bcn_beaconsEnabledSecondCat) {
|
Form.check(strings.beaconEnabled, secondEnabled == true) {
|
||||||
state.bcn_beaconsEnabledSecondCat = it
|
state.bcn_beaconsEnabledSecondCat = it
|
||||||
}
|
}
|
||||||
Form.committed(
|
Form.committed(
|
||||||
|
|||||||
@@ -12,8 +12,9 @@ import kst4contest.view.compose.setting
|
|||||||
* The two commit methods are the ports of `applyBeaconTextSetting` and
|
* The two commit methods are the ports of `applyBeaconTextSetting` and
|
||||||
* `applySharedBeaconInterval`. Both returned nothing and opened an alert; here they
|
* `applySharedBeaconInterval`. Both returned nothing and opened an alert; here they
|
||||||
* return the refusal text instead, so the tab decides how to show it and a test can
|
* return the refusal text instead, so the tab decides how to show it and a test can
|
||||||
* read it. An accepted value is staged in the window's [SettingsDraft] and takes effect
|
* read it. Accepted templates and intervals are staged in the window's [SettingsDraft]
|
||||||
* when the operator applies it; a refused one never gets there.
|
* and take effect when the operator applies them. The two enable switches deliberately
|
||||||
|
* bypass the draft so the running timer sees their values immediately.
|
||||||
*
|
*
|
||||||
* @param validateBeaconTemplate throws IllegalArgumentException with the reason,
|
* @param validateBeaconTemplate throws IllegalArgumentException with the reason,
|
||||||
* the contract of `ChatController.validateBeaconTemplate`.
|
* the contract of `ChatController.validateBeaconTemplate`.
|
||||||
@@ -27,22 +28,32 @@ class BeaconTabState(
|
|||||||
private val restartBeaconTimer: () -> Unit,
|
private val restartBeaconTimer: () -> Unit,
|
||||||
val mainCategoryName: String,
|
val mainCategoryName: String,
|
||||||
val secondCategoryName: String,
|
val secondCategoryName: String,
|
||||||
|
private val setMainBeaconEnabled: (Boolean) -> Unit = prefs::setBcn_beaconsEnabledMainCat,
|
||||||
|
private val setSecondBeaconEnabled: (Boolean) -> Unit = prefs::setBcn_beaconsEnabledSecondCat,
|
||||||
|
private val onBeaconTemplatesApplied: () -> Unit = {},
|
||||||
) {
|
) {
|
||||||
|
|
||||||
var bcn_beaconsEnabledMainCat: Boolean by draft.setting(
|
val mainBeaconEnabled = prefs.bcnBeaconsEnabledMainCatProperty()
|
||||||
{ prefs.isBcn_beaconsEnabledMainCat() },
|
val secondBeaconEnabled = prefs.bcnBeaconsEnabledSecondCatProperty()
|
||||||
) { prefs.setBcn_beaconsEnabledMainCat(it) }
|
|
||||||
|
|
||||||
var bcn_beaconsEnabledSecondCat: Boolean by draft.setting(
|
var bcn_beaconsEnabledMainCat: Boolean
|
||||||
{ prefs.isBcn_beaconsEnabledSecondCat() },
|
get() = prefs.isBcn_beaconsEnabledMainCat()
|
||||||
) { prefs.setBcn_beaconsEnabledSecondCat(it) }
|
set(value) = setMainBeaconEnabled(value)
|
||||||
|
|
||||||
|
var bcn_beaconsEnabledSecondCat: Boolean
|
||||||
|
get() = prefs.isBcn_beaconsEnabledSecondCat()
|
||||||
|
set(value) = setSecondBeaconEnabled(value)
|
||||||
|
|
||||||
private var textMainCat: String by draft.setting(
|
private var textMainCat: String by draft.setting(
|
||||||
{ prefs.getBcn_beaconTextMainCat() },
|
{ prefs.getBcn_beaconTextMainCat() },
|
||||||
|
effectKey = BEACON_TEMPLATE_EFFECT,
|
||||||
|
effect = onBeaconTemplatesApplied,
|
||||||
) { prefs.setBcn_beaconTextMainCat(it) }
|
) { prefs.setBcn_beaconTextMainCat(it) }
|
||||||
|
|
||||||
private var textSecondCat: String by draft.setting(
|
private var textSecondCat: String by draft.setting(
|
||||||
{ prefs.getBcn_beaconTextSecondCat() },
|
{ prefs.getBcn_beaconTextSecondCat() },
|
||||||
|
effectKey = BEACON_TEMPLATE_EFFECT,
|
||||||
|
effect = onBeaconTemplatesApplied,
|
||||||
) { prefs.setBcn_beaconTextSecondCat(it) }
|
) { prefs.setBcn_beaconTextSecondCat(it) }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -69,7 +80,7 @@ class BeaconTabState(
|
|||||||
*
|
*
|
||||||
* The clamp is not cosmetic: a stored zero would otherwise be displayed as a
|
* The clamp is not cosmetic: a stored zero would otherwise be displayed as a
|
||||||
* valid setting while `ChatController` sends at the minimum anyway
|
* valid setting while `ChatController` sends at the minimum anyway
|
||||||
* (ChatController:3425). The JavaFX field applied the same `Math.max` when it
|
* when scheduling the timer. The JavaFX field applied the same `Math.max` when it
|
||||||
* restored the value after a rejected entry.
|
* restored the value after a rejected entry.
|
||||||
*/
|
*/
|
||||||
val beaconIntervalMinutes: Int
|
val beaconIntervalMinutes: Int
|
||||||
@@ -117,4 +128,8 @@ class BeaconTabState(
|
|||||||
interval = minutes
|
interval = minutes
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
const val BEACON_TEMPLATE_EFFECT = "beaconTemplates"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+38
-19
@@ -18,10 +18,12 @@ import androidx.compose.runtime.getValue
|
|||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.runtime.staticCompositionLocalOf
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.AwtWindow
|
import androidx.compose.ui.window.AwtWindow
|
||||||
|
import java.awt.Dialog
|
||||||
import java.awt.FileDialog
|
import java.awt.FileDialog
|
||||||
import java.awt.Frame
|
import java.awt.Frame
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -125,34 +127,51 @@ internal fun FilePathRow(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** The modal owner that keeps the native file chooser accessible when opened from the wizard. */
|
||||||
* The AWT file dialog, opened from Compose. The JavaFX chooser started in the user's
|
val LocalFileDialogOwner = staticCompositionLocalOf<Dialog?> { null }
|
||||||
* home directory and a cancelled choice kept the stored path — both are preserved.
|
|
||||||
*/
|
/** The AWT file dialog, opened from Compose. */
|
||||||
@Composable
|
@Composable
|
||||||
private fun FileChooserDialog(title: String, onResult: (String?) -> Unit) {
|
private fun FileChooserDialog(title: String, onResult: (String?) -> Unit) {
|
||||||
|
val owner = LocalFileDialogOwner.current
|
||||||
AwtWindow(
|
AwtWindow(
|
||||||
create = {
|
create = {
|
||||||
object : FileDialog(null as Frame?, title, LOAD) {
|
if (owner == null) LogFileDialog(title, onResult) else LogFileDialog(owner, title, onResult)
|
||||||
override fun setVisible(visible: Boolean) {
|
|
||||||
if (visible) {
|
|
||||||
directory = System.getProperty("user.home")
|
|
||||||
}
|
|
||||||
super.setVisible(visible)
|
|
||||||
if (visible) {
|
|
||||||
val chosenName = file
|
|
||||||
onResult(
|
|
||||||
if (chosenName == null) null
|
|
||||||
else File(directory ?: "", chosenName).absolutePath
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
dispose = FileDialog::dispose,
|
dispose = FileDialog::dispose,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The JavaFX chooser started in the user's home directory and a cancelled choice kept the
|
||||||
|
* stored path. Both constructors share that behaviour.
|
||||||
|
*/
|
||||||
|
private class LogFileDialog : FileDialog {
|
||||||
|
private val onResult: (String?) -> Unit
|
||||||
|
|
||||||
|
constructor(title: String, onResult: (String?) -> Unit) : super(null as Frame?, title, LOAD) {
|
||||||
|
this.onResult = onResult
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(owner: Dialog, title: String, onResult: (String?) -> Unit) : super(owner, title, LOAD) {
|
||||||
|
this.onResult = onResult
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setVisible(visible: Boolean) {
|
||||||
|
if (visible) {
|
||||||
|
directory = System.getProperty("user.home")
|
||||||
|
}
|
||||||
|
super.setVisible(visible)
|
||||||
|
if (visible) {
|
||||||
|
val chosenName = file
|
||||||
|
onResult(
|
||||||
|
if (chosenName == null) null
|
||||||
|
else File(directory ?: "", chosenName).absolutePath
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** The label column width the shared form controls use, so the tabs line up. */
|
/** The label column width the shared form controls use, so the tabs line up. */
|
||||||
@Composable
|
@Composable
|
||||||
private fun LabelledRow(label: String, field: @Composable () -> Unit) {
|
private fun LabelledRow(label: String, field: @Composable () -> Unit) {
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
package kst4contest.view.compose.tabs
|
package kst4contest.view.compose.tabs
|
||||||
|
|
||||||
import kst4contest.view.i18n.LocalStrings
|
import kst4contest.view.i18n.LocalStrings
|
||||||
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
|
import androidx.compose.foundation.TooltipArea
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import kst4contest.view.compose.Form
|
import kst4contest.view.compose.Form
|
||||||
|
import kst4contest.view.compose.TooltipCard
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Station tab: own station, server, active bands and path-analysis defaults.
|
* The Station tab: own station, server, active bands and path-analysis defaults.
|
||||||
@@ -16,6 +19,7 @@ import kst4contest.view.compose.Form
|
|||||||
*
|
*
|
||||||
* @param onRefused shows why a committed entry was refused (the own ground height)
|
* @param onRefused shows why a committed entry was refused (the own ground height)
|
||||||
*/
|
*/
|
||||||
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun StationTab(state: StationTabState, onRefused: (String) -> Unit = {}) {
|
fun StationTab(state: StationTabState, onRefused: (String) -> Unit = {}) {
|
||||||
val strings = LocalStrings.current
|
val strings = LocalStrings.current
|
||||||
@@ -86,10 +90,32 @@ fun StationTab(state: StationTabState, onRefused: (String) -> Unit = {}) {
|
|||||||
|
|
||||||
Form.section(strings.stationDefaultsSection) {
|
Form.section(strings.stationDefaultsSection) {
|
||||||
Form.decimal(strings.stationMaxQrb, state.stn_maxQRBDefault) { state.stn_maxQRBDefault = it }
|
Form.decimal(strings.stationMaxQrb, state.stn_maxQRBDefault) { state.stn_maxQRBDefault = it }
|
||||||
Form.decimal(strings.stationQtf, state.stn_qtfDefault) { state.stn_qtfDefault = it }
|
Form.decimal(
|
||||||
|
label = strings.stationQtf,
|
||||||
|
value = state.stn_qtfDefault,
|
||||||
|
isValid = { it.isFinite() && it in 0.0..360.0 },
|
||||||
|
) { state.stn_qtfDefault = it }
|
||||||
Form.decimal(strings.stationBeamWidth, state.stn_antennaBeamWidthDeg) { state.stn_antennaBeamWidthDeg = it }
|
Form.decimal(strings.stationBeamWidth, state.stn_antennaBeamWidthDeg) { state.stn_antennaBeamWidthDeg = it }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Form.panelSection(strings.stationManualAntennaHeadingSection) {
|
||||||
|
val headingOption: @Composable () -> Unit = {
|
||||||
|
Form.check(
|
||||||
|
strings.stationUseQtfFilterDirectionAsAntennaHeading,
|
||||||
|
state.stn_useQtfFilterDirectionAsAntennaHeading,
|
||||||
|
enabled = !state.stn_pstRotatorEnabled,
|
||||||
|
) { state.stn_useQtfFilterDirectionAsAntennaHeading = it }
|
||||||
|
}
|
||||||
|
if (state.stn_pstRotatorEnabled) {
|
||||||
|
TooltipArea(
|
||||||
|
tooltip = { TooltipCard(strings.stationManualAntennaHeadingRotatorHint) },
|
||||||
|
content = headingOption,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
headingOption()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Form.section(strings.stationRotatorSection) {
|
Form.section(strings.stationRotatorSection) {
|
||||||
Form.check(strings.stationRotatorEnabled, state.stn_pstRotatorEnabled) { state.stn_pstRotatorEnabled = it }
|
Form.check(strings.stationRotatorEnabled, state.stn_pstRotatorEnabled) { state.stn_pstRotatorEnabled = it }
|
||||||
Form.text(strings.stationRotatorHost, state.stn_pstRotatorHost) { state.stn_pstRotatorHost = it }
|
Form.text(strings.stationRotatorHost, state.stn_pstRotatorHost) { state.stn_pstRotatorHost = it }
|
||||||
|
|||||||
@@ -44,6 +44,10 @@ class StationTabState(
|
|||||||
* TRX synch tab through [SECOND_ROTATOR], so it runs once per apply.
|
* TRX synch tab through [SECOND_ROTATOR], so it runs once per apply.
|
||||||
*/
|
*/
|
||||||
private val applySecondRotator: () -> Unit = {},
|
private val applySecondRotator: () -> Unit = {},
|
||||||
|
/** Recomputes status whose available-count depends on the second-chat switch. */
|
||||||
|
private val refreshBeaconStatus: () -> Unit = {},
|
||||||
|
/** Repaints applied beam geometry and dependent QTF results in the running UI. */
|
||||||
|
private val applyMapDisplaySettings: () -> Unit = {},
|
||||||
) {
|
) {
|
||||||
|
|
||||||
var loginChatCategoryMain: ChatCategory?
|
var loginChatCategoryMain: ChatCategory?
|
||||||
@@ -55,7 +59,11 @@ class StationTabState(
|
|||||||
get() = prefs.getLoginChatCategorySecond()
|
get() = prefs.getLoginChatCategorySecond()
|
||||||
set(value) { prefs.setLoginChatCategorySecond(value) }
|
set(value) { prefs.setLoginChatCategorySecond(value) }
|
||||||
|
|
||||||
var stn_antennaBeamWidthDeg: Double by draft.setting({ prefs.getStn_antennaBeamWidthDeg() }) { prefs.setStn_antennaBeamWidthDeg(it) }
|
var stn_antennaBeamWidthDeg: Double by draft.setting(
|
||||||
|
{ prefs.getStn_antennaBeamWidthDeg() },
|
||||||
|
effectKey = MAP_DISPLAY_SETTINGS,
|
||||||
|
effect = applyMapDisplaySettings,
|
||||||
|
) { prefs.setStn_antennaBeamWidthDeg(it) }
|
||||||
|
|
||||||
var stn_bandActive10G: Boolean by draft.setting({ prefs.isStn_bandActive10G() }) { prefs.setStn_bandActive10G(it) }
|
var stn_bandActive10G: Boolean by draft.setting({ prefs.isStn_bandActive10G() }) { prefs.setStn_bandActive10G(it) }
|
||||||
|
|
||||||
@@ -95,7 +103,11 @@ class StationTabState(
|
|||||||
get() = prefs.getStn_loginPassword()
|
get() = prefs.getStn_loginPassword()
|
||||||
set(value) { prefs.setStn_loginPassword(value) }
|
set(value) { prefs.setStn_loginPassword(value) }
|
||||||
|
|
||||||
var stn_maxQRBDefault: Double by draft.setting({ prefs.getStn_maxQRBDefault() }) { prefs.setStn_maxQRBDefault(it) }
|
var stn_maxQRBDefault: Double by draft.setting(
|
||||||
|
{ prefs.getStn_maxQRBDefault() },
|
||||||
|
effectKey = MAP_DISPLAY_SETTINGS,
|
||||||
|
effect = applyMapDisplaySettings,
|
||||||
|
) { prefs.setStn_maxQRBDefault(it) }
|
||||||
|
|
||||||
var stn_on4kstServersDns: String by draft.setting({ prefs.getStn_on4kstServersDns() }) { prefs.setStn_on4kstServersDns(it) }
|
var stn_on4kstServersDns: String by draft.setting({ prefs.getStn_on4kstServersDns() }) { prefs.setStn_on4kstServersDns(it) }
|
||||||
|
|
||||||
@@ -165,7 +177,13 @@ class StationTabState(
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
var stn_pstRotatorEnabled: Boolean by draft.setting({ prefs.isStn_pstRotatorEnabled() }) { prefs.setStn_pstRotatorEnabled(it) }
|
var stn_pstRotatorEnabled: Boolean by draft.setting(
|
||||||
|
{ prefs.isStn_pstRotatorEnabled() },
|
||||||
|
) { prefs.setStn_pstRotatorEnabled(it) }
|
||||||
|
|
||||||
|
var stn_useQtfFilterDirectionAsAntennaHeading: Boolean by draft.setting(
|
||||||
|
{ prefs.isStn_useQtfFilterDirectionAsAntennaHeading() },
|
||||||
|
) { prefs.setStn_useQtfFilterDirectionAsAntennaHeading(it) }
|
||||||
|
|
||||||
var stn_pstRotatorHost: String by draft.setting({ prefs.getStn_pstRotatorHost() }) { prefs.setStn_pstRotatorHost(it) }
|
var stn_pstRotatorHost: String by draft.setting({ prefs.getStn_pstRotatorHost() }) { prefs.setStn_pstRotatorHost(it) }
|
||||||
|
|
||||||
@@ -228,7 +246,10 @@ class StationTabState(
|
|||||||
* pickers it governs. It decides what the Connect button does, so it belongs with
|
* pickers it governs. It decides what the Connect button does, so it belongs with
|
||||||
* the login settings and not with the display options.
|
* the login settings and not with the display options.
|
||||||
*/
|
*/
|
||||||
var loginToSecondChatEnabled: Boolean by draft.setting({ prefs.isLoginToSecondChatEnabled() }) { prefs.setLoginToSecondChatEnabled(it) }
|
var loginToSecondChatEnabled: Boolean by draft.setting(
|
||||||
|
{ prefs.isLoginToSecondChatEnabled() },
|
||||||
|
effect = { refreshBeaconStatus() },
|
||||||
|
) { prefs.setLoginToSecondChatEnabled(it) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the login fields may be edited. The JavaFX window disabled callsign,
|
* Whether the login fields may be edited. The JavaFX window disabled callsign,
|
||||||
@@ -283,6 +304,9 @@ class StationTabState(
|
|||||||
/** The effect key of everything that restarts rotator 2; shared with the TRX synch tab. */
|
/** The effect key of everything that restarts rotator 2; shared with the TRX synch tab. */
|
||||||
const val SECOND_ROTATOR: String = "secondRotator"
|
const val SECOND_ROTATOR: String = "secondRotator"
|
||||||
|
|
||||||
|
/** Shared effect for the two settings that define the map's antenna sector. */
|
||||||
|
const val MAP_DISPLAY_SETTINGS: String = "mapDisplaySettings"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether two PSTRotator ports collide: the same port, or one apart because
|
* Whether two PSTRotator ports collide: the same port, or one apart because
|
||||||
* PSTRotator answers on port + 1, which would be the other client's local port.
|
* PSTRotator answers on port + 1, which would be the other client's local port.
|
||||||
|
|||||||
@@ -0,0 +1,492 @@
|
|||||||
|
package kst4contest.view.compose.wizard
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.selection.selectable
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.RadioButton
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.semantics.Role
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import kst4contest.model.ChatCategory
|
||||||
|
import kst4contest.view.compose.Density
|
||||||
|
import kst4contest.view.compose.Form
|
||||||
|
import kst4contest.view.compose.LocalSettingsDraft
|
||||||
|
import kst4contest.view.compose.SettingsDraft
|
||||||
|
import kst4contest.view.compose.tabs.FilePathRow
|
||||||
|
import kst4contest.view.i18n.LanguageStore
|
||||||
|
import kst4contest.view.i18n.LocalStrings
|
||||||
|
import kst4contest.view.i18n.SYSTEM_LANGUAGE
|
||||||
|
import kst4contest.view.i18n.Strings
|
||||||
|
import kst4contest.view.i18n.Translations
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A language store for the wizard: a choice takes effect on screen at once and is kept in
|
||||||
|
* the wizard's answers, not in the preferences. "Later" therefore stores no language, and
|
||||||
|
* the runtime built afterwards puts the stored one back in force.
|
||||||
|
*/
|
||||||
|
fun wizardLanguageStore(state: SetupWizardState): LanguageStore =
|
||||||
|
LanguageStore(storedLanguage = { state.language }, storeLanguage = { state.language = it })
|
||||||
|
|
||||||
|
/** The name a chat category carries in the pickers, the one the Station tab shows. */
|
||||||
|
private fun categoryName(number: Int): String = ChatCategory(number).getChatCategoryName(number)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The wizard's pages and its button row.
|
||||||
|
*
|
||||||
|
* All decisions are in [state]; this draws them. The texts are read from [languageStore] in
|
||||||
|
* the composition, so the language picker on the personal page switches the wizard itself.
|
||||||
|
*
|
||||||
|
* @param saveFailed whether the last Save could not write the file
|
||||||
|
* @param onLater the operator does not want to set up now; nothing is written
|
||||||
|
* @param onSave the operator saves; true when the session should be started afterwards
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
fun SetupWizardContent(
|
||||||
|
state: SetupWizardState,
|
||||||
|
languageStore: LanguageStore,
|
||||||
|
saveFailed: Boolean,
|
||||||
|
onLater: () -> Unit,
|
||||||
|
onSave: (connect: Boolean) -> Unit,
|
||||||
|
) {
|
||||||
|
val strings = languageStore.strings
|
||||||
|
// The draft only registers typed entries. Wizard answers are never staged or applied through it.
|
||||||
|
val typedEntries = remember { SettingsDraft() }
|
||||||
|
var typedEntryRefusals by remember { mutableStateOf(emptyList<String>()) }
|
||||||
|
|
||||||
|
fun withAcceptedTypedEntries(action: () -> Unit) {
|
||||||
|
val refusals = typedEntries.commitTypedEntries()
|
||||||
|
typedEntryRefusals = refusals
|
||||||
|
if (refusals.isEmpty()) action()
|
||||||
|
}
|
||||||
|
|
||||||
|
CompositionLocalProvider(LocalStrings provides strings, LocalSettingsDraft provides typedEntries) {
|
||||||
|
Surface(modifier = Modifier.fillMaxSize()) {
|
||||||
|
Column(modifier = Modifier.padding(15.dp)) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.weight(1f).fillMaxWidth().verticalScroll(rememberScrollState()),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(6.dp),
|
||||||
|
) {
|
||||||
|
when (state.page) {
|
||||||
|
WizardPage.ENTRY -> EntryPage(state, strings)
|
||||||
|
WizardPage.PERSONAL -> PersonalPage(state, strings, languageStore)
|
||||||
|
WizardPage.LOGIN -> LoginPage(state, strings)
|
||||||
|
WizardPage.SITE -> SitePage(state, strings)
|
||||||
|
WizardPage.ANTENNA -> AntennaPage(state.antenna, strings)
|
||||||
|
WizardPage.LOG -> LogPage(state.integrations, strings)
|
||||||
|
WizardPage.GEAR -> GearPage(state.integrations, strings)
|
||||||
|
WizardPage.SUMMARY -> SummaryPage(state, strings, saveFailed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typedEntryRefusals.isNotEmpty()) {
|
||||||
|
Refusal(typedEntryRefusals.joinToString("\n"))
|
||||||
|
}
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth().padding(top = 10.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(Density.BUTTON_GAP),
|
||||||
|
) {
|
||||||
|
Form.button(strings.wizardLater, onClick = onLater)
|
||||||
|
Spacer(Modifier.weight(1f))
|
||||||
|
if (state.canGoBack) {
|
||||||
|
Form.button(strings.wizardBack, onClick = state::back)
|
||||||
|
}
|
||||||
|
if (state.page == WizardPage.SUMMARY) {
|
||||||
|
Form.button(strings.wizardSave, enabled = state.mandatoryComplete) {
|
||||||
|
withAcceptedTypedEntries { onSave(false) }
|
||||||
|
}
|
||||||
|
Form.button(
|
||||||
|
strings.wizardSaveAndConnect,
|
||||||
|
enabled = state.mandatoryComplete,
|
||||||
|
accented = true,
|
||||||
|
) { withAcceptedTypedEntries { onSave(true) } }
|
||||||
|
} else {
|
||||||
|
if (state.canFinish) {
|
||||||
|
Form.button(strings.wizardFinish) { withAcceptedTypedEntries(state::finish) }
|
||||||
|
}
|
||||||
|
Form.button(
|
||||||
|
strings.wizardNext,
|
||||||
|
enabled = state.canGoNext,
|
||||||
|
accented = true,
|
||||||
|
) { withAcceptedTypedEntries(state::next) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun Heading(title: String, lead: String) {
|
||||||
|
Text(title, style = MaterialTheme.typography.titleMedium)
|
||||||
|
Text(lead, style = MaterialTheme.typography.bodySmall)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun Refusal(text: String) {
|
||||||
|
Text(text, color = MaterialTheme.colorScheme.error, style = MaterialTheme.typography.bodySmall)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun RadioOption(label: String, selected: Boolean, onSelect: () -> Unit) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.selectable(selected = selected, role = Role.RadioButton, onClick = onSelect)
|
||||||
|
.padding(vertical = 2.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
RadioButton(selected = selected, onClick = null)
|
||||||
|
Text(label, modifier = Modifier.padding(start = 6.dp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun EntryPage(state: SetupWizardState, strings: Strings) {
|
||||||
|
Heading(strings.wizardEntryTitle, strings.wizardEntryLead)
|
||||||
|
val oneDonor = state.donors.singleOrNull()
|
||||||
|
|
||||||
|
/* An axis with a single option is decided already and is not asked about. */
|
||||||
|
if (state.loginSources.size > 1) {
|
||||||
|
Form.section(strings.wizardEntryLogin) {
|
||||||
|
state.loginSources.forEach { source ->
|
||||||
|
RadioOption(
|
||||||
|
label = when (source) {
|
||||||
|
WizardSource.NEW -> strings.wizardSourceLoginNew
|
||||||
|
// One other profile is named in the option; several get a picker below.
|
||||||
|
WizardSource.TAKE ->
|
||||||
|
if (oneDonor != null) strings.wizardSourceLoginTake(oneDonor.displayName, oneDonor.callsign)
|
||||||
|
else strings.wizardSourceLoginTakeFrom
|
||||||
|
WizardSource.KEEP -> strings.wizardSourceLoginKeep(state.storedCallsign)
|
||||||
|
},
|
||||||
|
selected = state.loginSource == source,
|
||||||
|
onSelect = { state.chooseLoginSource(source) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (state.loginSource == WizardSource.TAKE && oneDonor == null) {
|
||||||
|
Form.choice(
|
||||||
|
label = strings.wizardEntryDonor,
|
||||||
|
items = state.donors,
|
||||||
|
selected = state.loginDonor,
|
||||||
|
describe = { "${it.displayName} (${it.callsign})" },
|
||||||
|
onSelect = state::chooseLoginDonor,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.stationSources.size > 1) {
|
||||||
|
Form.section(strings.wizardEntryStation) {
|
||||||
|
state.stationSources.forEach { source ->
|
||||||
|
RadioOption(
|
||||||
|
label = when (source) {
|
||||||
|
WizardSource.NEW -> strings.wizardSourceStationNew
|
||||||
|
WizardSource.TAKE ->
|
||||||
|
if (oneDonor != null) strings.wizardSourceStationTake(oneDonor.displayName, oneDonor.locator)
|
||||||
|
else strings.wizardSourceStationTakeFrom
|
||||||
|
WizardSource.KEEP -> strings.wizardSourceStationKeep(state.storedLocator)
|
||||||
|
},
|
||||||
|
selected = state.stationSource == source,
|
||||||
|
onSelect = { state.chooseStationSource(source) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (state.stationSource == WizardSource.TAKE && oneDonor == null) {
|
||||||
|
Form.choice(
|
||||||
|
label = strings.wizardEntryDonor,
|
||||||
|
items = state.donors,
|
||||||
|
selected = state.stationDonor,
|
||||||
|
describe = { "${it.displayName} (${it.locator})" },
|
||||||
|
onSelect = state::chooseStationDonor,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun PersonalPage(state: SetupWizardState, strings: Strings, languageStore: LanguageStore) {
|
||||||
|
Heading(strings.wizardPersonalTitle, strings.wizardPersonalLead)
|
||||||
|
|
||||||
|
Form.choice(
|
||||||
|
label = strings.guiLanguage,
|
||||||
|
items = listOf(SYSTEM_LANGUAGE) + Translations.BY_LANGUAGE.keys.sorted(),
|
||||||
|
selected = languageStore.stored,
|
||||||
|
// The code in capitals, as the GUI tab shows it.
|
||||||
|
describe = { code -> if (code == SYSTEM_LANGUAGE) strings.guiLanguageSystem else code.uppercase() },
|
||||||
|
onSelect = { languageStore.use(it) },
|
||||||
|
)
|
||||||
|
Form.text(strings.wizardPersonalName, state.name) { state.name = it }
|
||||||
|
if (state.nameRefused) Refusal(strings.wizardPersonalNameInvalid)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun LoginPage(state: SetupWizardState, strings: Strings) {
|
||||||
|
Heading(strings.wizardLoginTitle, strings.wizardLoginLead)
|
||||||
|
|
||||||
|
Form.text(strings.stationCallsign, state.callsign) { state.callsign = it }
|
||||||
|
if (state.callsignRefused) Refusal(strings.wizardLoginCallsignInvalid)
|
||||||
|
Form.password(strings.stationPassword, state.password) { state.password = it }
|
||||||
|
if (state.passwordRefused) Refusal(strings.wizardLoginPasswordInvalid)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun SitePage(state: SetupWizardState, strings: Strings) {
|
||||||
|
Heading(strings.wizardSiteTitle, strings.wizardSiteLead)
|
||||||
|
|
||||||
|
Form.text(strings.stationLocator, state.locator) { state.locator = it }
|
||||||
|
if (state.locatorRefused) Refusal(strings.wizardSiteLocatorInvalid)
|
||||||
|
|
||||||
|
Form.flowingSection(strings.wizardSiteBands) {
|
||||||
|
WizardBand.entries.forEach { band ->
|
||||||
|
Form.check(band.label, band in state.bands) { state.setBand(band, it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Text(strings.wizardSiteBandsHint, style = MaterialTheme.typography.bodySmall)
|
||||||
|
|
||||||
|
Form.choice(
|
||||||
|
label = strings.stationMainCategory,
|
||||||
|
items = SetupWizardState.CATEGORY_NUMBERS,
|
||||||
|
selected = state.category,
|
||||||
|
describe = ::categoryName,
|
||||||
|
onSelect = state::chooseCategory,
|
||||||
|
)
|
||||||
|
state.suggestedCategory?.let { suggested ->
|
||||||
|
Text(
|
||||||
|
strings.wizardSiteCategorySuggestion(categoryName(suggested)),
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Form.check(strings.wizardSiteSecondChat, state.secondChat) { state.chooseSecondChat(it) }
|
||||||
|
if (state.secondChat) {
|
||||||
|
Form.choice(
|
||||||
|
label = strings.stationSecondCategory,
|
||||||
|
items = state.secondCategoryOptions,
|
||||||
|
selected = state.secondCategory,
|
||||||
|
describe = ::categoryName,
|
||||||
|
onSelect = { state.secondCategory = it },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The name a log program carries on its page and in the summary. */
|
||||||
|
private fun logProgramName(program: WizardLogProgram, strings: Strings): String = when (program) {
|
||||||
|
WizardLogProgram.NONE -> strings.wizardLogNone
|
||||||
|
WizardLogProgram.WINTEST -> strings.wizardLogWintest
|
||||||
|
WizardLogProgram.UDP -> strings.wizardLogUdp
|
||||||
|
WizardLogProgram.FILE -> strings.wizardLogFile
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The name of something that will be switched off, for the summary's notice. */
|
||||||
|
private fun switchName(switch: WizardSwitch, strings: Strings): String = when (switch) {
|
||||||
|
WizardSwitch.SECOND_CHAT -> strings.wizardSwitchSecondChat
|
||||||
|
WizardSwitch.LOG_WINTEST -> strings.wizardSwitchLogWintest
|
||||||
|
WizardSwitch.LOG_UDP -> strings.wizardSwitchLogUdp
|
||||||
|
WizardSwitch.LOG_FILE -> strings.wizardSwitchLogFile
|
||||||
|
WizardSwitch.QRG_FOLLOW -> strings.wizardSwitchQrgFollow
|
||||||
|
WizardSwitch.CLUSTER_SERVER -> strings.wizardSwitchClusterServer
|
||||||
|
WizardSwitch.ROTATOR -> strings.wizardSwitchRotator
|
||||||
|
WizardSwitch.AIRSCOUT -> strings.wizardSwitchAirScout
|
||||||
|
WizardSwitch.SO2R -> strings.wizardSwitchSo2r
|
||||||
|
WizardSwitch.ROTATOR_2 -> strings.wizardSwitchRotator2
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun AntennaPage(antenna: WizardAntenna, strings: Strings) {
|
||||||
|
Heading(strings.wizardAntennaTitle, strings.wizardAntennaLead)
|
||||||
|
|
||||||
|
Form.decimal(strings.stationBeamWidth, antenna.beamWidthDeg, isValid = { it.isFinite() }) {
|
||||||
|
antenna.beamWidthDeg = it
|
||||||
|
}
|
||||||
|
Form.decimal(strings.stationOwnAntennaGain, antenna.gainDbi, isValid = { it.isFinite() }) {
|
||||||
|
antenna.gainDbi = it
|
||||||
|
}
|
||||||
|
Form.decimal(strings.stationOwnAntennaHeight, antenna.heightMeters, isValid = { it.isFinite() && it >= 0.0 }) {
|
||||||
|
antenna.heightMeters = it
|
||||||
|
}
|
||||||
|
Form.decimal(strings.stationOwnTxPower, antenna.txPowerWatts, isValid = { it.isFinite() }) {
|
||||||
|
antenna.txPowerWatts = it
|
||||||
|
}
|
||||||
|
|
||||||
|
Form.text(strings.stationOwnHeightAsl, antenna.heightAslText) { antenna.heightAslText = it }
|
||||||
|
if (antenna.heightAslRefused) {
|
||||||
|
Refusal(strings.stationInvalidOwnHeightAsl(antenna.heightAslText.trim()))
|
||||||
|
}
|
||||||
|
Text(strings.wizardAntennaAslHint, style = MaterialTheme.typography.bodySmall)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun LogPage(integrations: WizardIntegrations, strings: Strings) {
|
||||||
|
Heading(strings.wizardLogTitle, strings.wizardLogLead)
|
||||||
|
|
||||||
|
WizardLogProgram.entries.forEach { program ->
|
||||||
|
RadioOption(
|
||||||
|
label = logProgramName(program, strings),
|
||||||
|
selected = integrations.logProgram == program,
|
||||||
|
onSelect = { integrations.chooseLogProgram(program) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The details of a program appear only once it is chosen. */
|
||||||
|
when (integrations.logProgram) {
|
||||||
|
WizardLogProgram.WINTEST -> {
|
||||||
|
Form.int(strings.logSynchWinTestPort, integrations.wintestPort) { integrations.wintestPort = it }
|
||||||
|
Form.text(strings.logSynchWinTestStationName, integrations.wintestStationName) {
|
||||||
|
integrations.wintestStationName = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WizardLogProgram.UDP ->
|
||||||
|
Form.int(strings.logSynchSharedPort, integrations.udpPort) { integrations.udpPort = it }
|
||||||
|
WizardLogProgram.FILE ->
|
||||||
|
FilePathRow(
|
||||||
|
label = strings.logSynchFileLabel,
|
||||||
|
value = integrations.filePath,
|
||||||
|
chooserTitle = strings.logSynchFileChooserTitle,
|
||||||
|
) { integrations.filePath = it }
|
||||||
|
WizardLogProgram.NONE -> Unit
|
||||||
|
}
|
||||||
|
if (!integrations.logComplete) Refusal(strings.wizardLogIncomplete)
|
||||||
|
|
||||||
|
if (integrations.networked) {
|
||||||
|
Form.check(strings.wizardLogQrgFollow, integrations.qrgFollow) { integrations.qrgFollow = it }
|
||||||
|
Form.check(strings.wizardLogClusterServer, integrations.clusterServer) { integrations.clusterServer = it }
|
||||||
|
// The settings tab's own words: an enabled source does not produce a frequency by itself.
|
||||||
|
Text(strings.trxSynchHint, style = MaterialTheme.typography.bodySmall)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun GearPage(integrations: WizardIntegrations, strings: Strings) {
|
||||||
|
Heading(strings.wizardGearTitle, strings.wizardGearLead)
|
||||||
|
|
||||||
|
Form.check(strings.wizardGearRotator, integrations.rotator) { integrations.rotator = it }
|
||||||
|
if (integrations.rotator) {
|
||||||
|
Form.text(strings.stationRotatorHost, integrations.rotatorHost) { integrations.rotatorHost = it }
|
||||||
|
Form.int(strings.stationRotatorPort, integrations.rotatorPort) { integrations.rotatorPort = it }
|
||||||
|
if (integrations.rotatorPortClashes) {
|
||||||
|
Refusal(strings.stationRotator2PortClash(integrations.rotatorPort.toString()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Form.check(strings.wizardGearAirScout, integrations.airScout) { integrations.airScout = it }
|
||||||
|
if (integrations.airScout) {
|
||||||
|
Form.int(strings.airscoutUdpPort, integrations.airScoutPort) { integrations.airScoutPort = it }
|
||||||
|
Form.text(strings.airscoutServerIdentifier, integrations.airScoutServerName) {
|
||||||
|
integrations.airScoutServerName = it
|
||||||
|
}
|
||||||
|
Form.text(strings.airscoutClientIdentifier, integrations.airScoutClientName) {
|
||||||
|
integrations.airScoutClientName = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!integrations.gearComplete) Refusal(strings.wizardGearIncomplete)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun SummaryRow(label: String, value: String) {
|
||||||
|
Form.labelledRow(label) { Text(value) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun SummaryPage(state: SetupWizardState, strings: Strings, saveFailed: Boolean) {
|
||||||
|
Heading(strings.wizardSummaryTitle, strings.wizardSummaryLead)
|
||||||
|
|
||||||
|
if (saveFailed) Refusal(strings.wizardSaveFailed)
|
||||||
|
if (!state.mandatoryComplete) Refusal(strings.wizardMissing)
|
||||||
|
if (state.switchedOff.isNotEmpty()) {
|
||||||
|
Text(strings.wizardSummarySwitchedOff(state.switchedOff.joinToString(", ") { switchName(it, strings) }))
|
||||||
|
}
|
||||||
|
|
||||||
|
Form.section(strings.wizardSummaryPersonal) {
|
||||||
|
SummaryRow(
|
||||||
|
strings.guiLanguage,
|
||||||
|
if (state.language == SYSTEM_LANGUAGE) strings.guiLanguageSystem else state.language.uppercase(),
|
||||||
|
)
|
||||||
|
SummaryRow(strings.wizardPersonalName, state.name.ifBlank { strings.wizardSummaryNone })
|
||||||
|
Form.button(strings.wizardChange) { state.edit(WizardPage.PERSONAL) }
|
||||||
|
}
|
||||||
|
|
||||||
|
Form.section(strings.wizardSummaryLogin) {
|
||||||
|
if (state.loginSource == WizardSource.TAKE) {
|
||||||
|
state.loginDonor?.let { Text(strings.wizardSummaryTakenFrom(it.displayName)) }
|
||||||
|
}
|
||||||
|
SummaryRow(strings.stationCallsign, state.callsign.ifBlank { strings.wizardSummaryNone })
|
||||||
|
// Never the password itself: the summary may be read over a shoulder.
|
||||||
|
SummaryRow(
|
||||||
|
strings.stationPassword,
|
||||||
|
if (state.password.isEmpty()) strings.wizardSummaryNone else strings.wizardSummaryPasswordSet,
|
||||||
|
)
|
||||||
|
Form.button(strings.wizardChange) { state.edit(WizardPage.LOGIN) }
|
||||||
|
}
|
||||||
|
|
||||||
|
Form.section(strings.wizardSummaryStation) {
|
||||||
|
if (state.stationSource == WizardSource.TAKE) {
|
||||||
|
state.stationDonor?.let { Text(strings.wizardSummaryTakenFrom(it.displayName)) }
|
||||||
|
}
|
||||||
|
SummaryRow(strings.stationLocator, state.locator.ifBlank { strings.wizardSummaryNone })
|
||||||
|
SummaryRow(
|
||||||
|
strings.wizardSummaryBands,
|
||||||
|
WizardBand.entries.filter { it in state.bands }.joinToString(", ") { it.label }
|
||||||
|
.ifEmpty { strings.wizardSummaryNone },
|
||||||
|
)
|
||||||
|
SummaryRow(
|
||||||
|
strings.wizardSummaryFallbackBand,
|
||||||
|
if (state.summaryFallbackBand.isBlank()) strings.wizardSummaryNone else "${state.summaryFallbackBand} MHz",
|
||||||
|
)
|
||||||
|
SummaryRow(
|
||||||
|
strings.stationMainCategory,
|
||||||
|
state.category?.let(::categoryName) ?: strings.wizardSummaryNone,
|
||||||
|
)
|
||||||
|
SummaryRow(
|
||||||
|
strings.stationSecondCategory,
|
||||||
|
state.secondCategory?.takeIf { state.secondChat }?.let(::categoryName) ?: strings.wizardSummaryNone,
|
||||||
|
)
|
||||||
|
Form.button(strings.wizardChange) { state.edit(WizardPage.SITE) }
|
||||||
|
}
|
||||||
|
|
||||||
|
val antenna = state.antenna
|
||||||
|
Form.section(strings.wizardSummaryAntenna) {
|
||||||
|
SummaryRow(strings.stationBeamWidth, antenna.beamWidthDeg.toString())
|
||||||
|
SummaryRow(strings.stationOwnAntennaGain, antenna.gainDbi.toString())
|
||||||
|
SummaryRow(strings.stationOwnAntennaHeight, antenna.heightMeters.toString())
|
||||||
|
SummaryRow(strings.stationOwnTxPower, antenna.txPowerWatts.toString())
|
||||||
|
SummaryRow(strings.stationOwnHeightAsl, antenna.heightAslText.trim().ifEmpty { strings.wizardSummaryNone })
|
||||||
|
Form.button(strings.wizardChange) { state.edit(WizardPage.ANTENNA) }
|
||||||
|
}
|
||||||
|
|
||||||
|
val integrations = state.integrations
|
||||||
|
val yesNo = { on: Boolean -> if (on) strings.wizardSummaryYes else strings.wizardSummaryNo }
|
||||||
|
|
||||||
|
Form.section(strings.wizardSummaryLog) {
|
||||||
|
if (state.logPageEditable) {
|
||||||
|
SummaryRow(strings.wizardSummaryLog, logProgramName(integrations.logProgram, strings))
|
||||||
|
SummaryRow(strings.wizardSummaryQrgFollow, yesNo(state.summaryQrgFollow))
|
||||||
|
SummaryRow(strings.wizardSummaryClusterServer, yesNo(state.summaryClusterServer))
|
||||||
|
Form.button(strings.wizardChange) { state.edit(WizardPage.LOG) }
|
||||||
|
} else {
|
||||||
|
/* Several sources are on; the page cannot show that and must not be opened. */
|
||||||
|
Text(strings.wizardSummaryLogSeveral)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Form.section(strings.wizardSummaryGear) {
|
||||||
|
SummaryRow(strings.wizardSwitchRotator, yesNo(integrations.rotator))
|
||||||
|
SummaryRow(strings.wizardSwitchAirScout, yesNo(integrations.airScout))
|
||||||
|
Form.button(strings.wizardChange) { state.edit(WizardPage.GEAR) }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,576 @@
|
|||||||
|
package kst4contest.view.compose.wizard
|
||||||
|
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import kst4contest.controller.LoginConfiguration
|
||||||
|
import kst4contest.model.ChatCategory
|
||||||
|
import kst4contest.model.ChatPreferences
|
||||||
|
|
||||||
|
/** Where the answers of one group come from. */
|
||||||
|
enum class WizardSource {
|
||||||
|
/** Entered in the wizard, starting from the wizard's own empty values. */
|
||||||
|
NEW,
|
||||||
|
|
||||||
|
/** Taken from another, configured profile. */
|
||||||
|
TAKE,
|
||||||
|
|
||||||
|
/** What the profile already holds. */
|
||||||
|
KEEP,
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Another profile the login or the station can be taken from.
|
||||||
|
*
|
||||||
|
* Its preferences are read from its file and never written: taking over fills the wizard's
|
||||||
|
* answers, and Save writes only into the active profile.
|
||||||
|
*
|
||||||
|
* @param prefs the other profile's preferences, already read from its file
|
||||||
|
*/
|
||||||
|
class WizardDonor(val profileId: String, val displayName: String, val prefs: ChatPreferences) {
|
||||||
|
|
||||||
|
/** For the entry page's label. */
|
||||||
|
val callsign: String = prefs.getStn_loginCallSign().orEmpty()
|
||||||
|
|
||||||
|
/** For the entry page's label. */
|
||||||
|
val locator: String = prefs.getStn_loginLocatorMainCat().orEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The pages, in the order they can appear. */
|
||||||
|
enum class WizardPage { ENTRY, PERSONAL, LOGIN, SITE, ANTENNA, LOG, GEAR, SUMMARY }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A band the station can be active on.
|
||||||
|
*
|
||||||
|
* The labels are amateur shorthand and deliberately not in the translation files.
|
||||||
|
*/
|
||||||
|
enum class WizardBand(
|
||||||
|
val label: String,
|
||||||
|
val megahertz: Int,
|
||||||
|
internal val isActive: (ChatPreferences) -> Boolean,
|
||||||
|
internal val setActive: (ChatPreferences, Boolean) -> Unit,
|
||||||
|
) {
|
||||||
|
B50("50 MHz", 50, { it.isStn_bandActive50() }, { p, on -> p.setStn_bandActive50(on) }),
|
||||||
|
B70("70 MHz", 70, { it.isStn_bandActive70() }, { p, on -> p.setStn_bandActive70(on) }),
|
||||||
|
B144("144 MHz", 144, { it.isStn_bandActive144() }, { p, on -> p.setStn_bandActive144(on) }),
|
||||||
|
B432("432 MHz", 432, { it.isStn_bandActive432() }, { p, on -> p.setStn_bandActive432(on) }),
|
||||||
|
B1240("1240 MHz", 1240, { it.isStn_bandActive1240() }, { p, on -> p.setStn_bandActive1240(on) }),
|
||||||
|
B2300("2300 MHz", 2300, { it.isStn_bandActive2300() }, { p, on -> p.setStn_bandActive2300(on) }),
|
||||||
|
B3400("3400 MHz", 3400, { it.isStn_bandActive3400() }, { p, on -> p.setStn_bandActive3400(on) }),
|
||||||
|
B5600("5600 MHz", 5600, { it.isStn_bandActive5600() }, { p, on -> p.setStn_bandActive5600(on) }),
|
||||||
|
B10G("10 GHz", 10000, { it.isStn_bandActive10G() }, { p, on -> p.setStn_bandActive10G(on) }),
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The setup wizard's answers and the rules of its course, free of any window.
|
||||||
|
*
|
||||||
|
* It reads the preferences once, when it is built, and does not touch them again until
|
||||||
|
* [writeTo]: closing the wizard without saving therefore leaves the profile exactly as it
|
||||||
|
* was. The design is in `docs/superpowers/specs/2026-11-18-einrichtungsassistent-design.md`.
|
||||||
|
*
|
||||||
|
* The answers are Compose state, so a composition reading them follows; nothing else here
|
||||||
|
* depends on Compose.
|
||||||
|
*
|
||||||
|
* @param prefs the profile's preferences, already read from its file
|
||||||
|
* @param donors other configured profiles the login or the station can be taken from
|
||||||
|
*/
|
||||||
|
class SetupWizardState(prefs: ChatPreferences, val donors: List<WizardDonor> = emptyList()) {
|
||||||
|
|
||||||
|
/** What the pages of the station group show of one profile's preferences. */
|
||||||
|
private class StationSnapshot(prefs: ChatPreferences) {
|
||||||
|
val locator: String = prefs.getStn_loginLocatorMainCat().orEmpty()
|
||||||
|
val bands: Set<WizardBand> = WizardBand.entries.filter { it.isActive(prefs) }.toSet()
|
||||||
|
val category: Int? = prefs.getLoginChatCategoryMain()?.categoryNumber
|
||||||
|
val secondChat: Boolean = prefs.isLoginToSecondChatEnabled()
|
||||||
|
val secondCategory: Int? = prefs.getLoginChatCategorySecond()?.categoryNumber
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Kept to rebuild the answers of the station group when its source changes. */
|
||||||
|
private val ownPrefs: ChatPreferences = prefs
|
||||||
|
private val ownStation = StationSnapshot(prefs)
|
||||||
|
|
||||||
|
/** What the own profile has on, whatever the answers are built from. */
|
||||||
|
private val ownSwitches: Set<WizardSwitch> = WizardIntegrations(prefs).let {
|
||||||
|
it.storedLogSwitches() + it.storedGearSwitches()
|
||||||
|
}
|
||||||
|
|
||||||
|
private val loginConfigured = !LoginConfiguration.isUnconfigured(prefs)
|
||||||
|
private val templateCredentials = LoginConfiguration.carriesTemplateCredentials(prefs)
|
||||||
|
|
||||||
|
/** The callsign the profile holds, for the label of "leave unchanged". */
|
||||||
|
val storedCallsign: String = prefs.getStn_loginCallSign().orEmpty()
|
||||||
|
private val storedPassword: String = prefs.getStn_loginPassword().orEmpty()
|
||||||
|
private val storedName: String = prefs.getStn_loginNameMainCat().orEmpty()
|
||||||
|
private val storedSecondName: String = prefs.getStn_loginNameSecondCat().orEmpty()
|
||||||
|
|
||||||
|
/** The locator the profile holds, for the label of "leave unchanged". */
|
||||||
|
val storedLocator: String = ownStation.locator
|
||||||
|
|
||||||
|
/** A login can be taken where another profile has one, and kept where an operator entered one. */
|
||||||
|
val loginSources: List<WizardSource> = buildList {
|
||||||
|
add(WizardSource.NEW)
|
||||||
|
if (donors.isNotEmpty()) add(WizardSource.TAKE)
|
||||||
|
if (loginConfigured) add(WizardSource.KEEP)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A station can be kept unless the profile is the untouched template: its locator and
|
||||||
|
* bands are then nobody's.
|
||||||
|
*/
|
||||||
|
val stationSources: List<WizardSource> = buildList {
|
||||||
|
add(WizardSource.NEW)
|
||||||
|
if (donors.isNotEmpty()) add(WizardSource.TAKE)
|
||||||
|
if (!templateCredentials) add(WizardSource.KEEP)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Whether there is anything to choose on the entry page. */
|
||||||
|
val hasEntryPage: Boolean = loginSources.size > 1 || stationSources.size > 1
|
||||||
|
|
||||||
|
var loginSource: WizardSource? by mutableStateOf(loginSources.singleOrNull())
|
||||||
|
private set
|
||||||
|
|
||||||
|
var stationSource: WizardSource? by mutableStateOf(stationSources.singleOrNull())
|
||||||
|
private set
|
||||||
|
|
||||||
|
/** The profile the login is taken from; decided with the source when there is only one. */
|
||||||
|
var loginDonor: WizardDonor? by mutableStateOf(null)
|
||||||
|
private set
|
||||||
|
|
||||||
|
/** The profile the station is taken from; decided with the source when there is only one. */
|
||||||
|
var stationDonor: WizardDonor? by mutableStateOf(null)
|
||||||
|
private set
|
||||||
|
|
||||||
|
/* A group is reloaded when its source or its donor changes, and only then. */
|
||||||
|
private var appliedLogin: Pair<WizardSource?, WizardDonor?> = null to null
|
||||||
|
private var appliedStation: Pair<WizardSource?, WizardDonor?> = null to null
|
||||||
|
|
||||||
|
/** The stored form of the language: a code, or empty for the system language. */
|
||||||
|
var language: String by mutableStateOf(prefs.getGuiOptions_language().orEmpty())
|
||||||
|
|
||||||
|
/** Empty on an unconfigured profile: its stored name is the template's or another operator's. */
|
||||||
|
var name: String by mutableStateOf(if (loginConfigured) storedName else "")
|
||||||
|
|
||||||
|
var callsign: String by mutableStateOf("")
|
||||||
|
var password: String by mutableStateOf("")
|
||||||
|
var locator: String by mutableStateOf("")
|
||||||
|
|
||||||
|
var bands: Set<WizardBand> by mutableStateOf(emptySet())
|
||||||
|
private set
|
||||||
|
|
||||||
|
var category: Int? by mutableStateOf(null)
|
||||||
|
private set
|
||||||
|
|
||||||
|
private var categoryChosenByOperator = false
|
||||||
|
|
||||||
|
var secondChat: Boolean by mutableStateOf(false)
|
||||||
|
private set
|
||||||
|
|
||||||
|
var secondCategory: Int? by mutableStateOf(null)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Antenna and power; always proposals from the profile the station comes from. Replaced
|
||||||
|
* when the station's source changes, so nothing typed under one choice shows under another.
|
||||||
|
*/
|
||||||
|
var antenna: WizardAntenna by mutableStateOf(WizardAntenna(prefs))
|
||||||
|
private set
|
||||||
|
|
||||||
|
/** Log program, rotator and AirScout; replaced like [antenna]. */
|
||||||
|
var integrations: WizardIntegrations by mutableStateOf(WizardIntegrations(prefs))
|
||||||
|
private set
|
||||||
|
|
||||||
|
private var loginShown by mutableStateOf(false)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* One flag per page of the station group. A page that was shown in this run is written;
|
||||||
|
* a page that never was leaves its settings exactly as the profile has them. That is
|
||||||
|
* what keeps "leave the station unchanged" from touching integrations the wizard's
|
||||||
|
* simpler questions could not express.
|
||||||
|
*/
|
||||||
|
private var siteShown by mutableStateOf(false)
|
||||||
|
private var antennaShown by mutableStateOf(false)
|
||||||
|
private var logShown by mutableStateOf(false)
|
||||||
|
private var gearShown by mutableStateOf(false)
|
||||||
|
|
||||||
|
var page: WizardPage by mutableStateOf(if (hasEntryPage) WizardPage.ENTRY else WizardPage.PERSONAL)
|
||||||
|
private set
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (!hasEntryPage) applySources()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun chooseLoginSource(source: WizardSource) {
|
||||||
|
if (source !in loginSources) return
|
||||||
|
loginSource = source
|
||||||
|
if (source == WizardSource.TAKE && loginDonor == null) loginDonor = donors.singleOrNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun chooseStationSource(source: WizardSource) {
|
||||||
|
if (source !in stationSources) return
|
||||||
|
stationSource = source
|
||||||
|
if (source == WizardSource.TAKE && stationDonor == null) stationDonor = donors.singleOrNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun chooseLoginDonor(donor: WizardDonor) {
|
||||||
|
if (donor in donors) loginDonor = donor
|
||||||
|
}
|
||||||
|
|
||||||
|
fun chooseStationDonor(donor: WizardDonor) {
|
||||||
|
if (donor in donors) stationDonor = donor
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A source is decided once it is chosen and, when it takes over, says from whom. */
|
||||||
|
private fun decided(source: WizardSource?, donor: WizardDonor?): Boolean =
|
||||||
|
source != null && (source != WizardSource.TAKE || donor != null)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the answers of a group whose source or donor changed. A group whose choice is the
|
||||||
|
* one already applied is left alone, so going back to the entry page costs nothing typed.
|
||||||
|
*/
|
||||||
|
private fun applySources() {
|
||||||
|
val login = loginSource to loginDonor.takeIf { loginSource == WizardSource.TAKE }
|
||||||
|
if (login != appliedLogin) {
|
||||||
|
when (loginSource) {
|
||||||
|
WizardSource.KEEP -> {
|
||||||
|
callsign = storedCallsign
|
||||||
|
password = storedPassword
|
||||||
|
}
|
||||||
|
WizardSource.TAKE -> {
|
||||||
|
callsign = loginDonor?.prefs?.getStn_loginCallSign().orEmpty()
|
||||||
|
password = loginDonor?.prefs?.getStn_loginPassword().orEmpty()
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
callsign = ""
|
||||||
|
password = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Shown when entered anew, and when what was kept or taken cannot be saved as it is.
|
||||||
|
loginShown = loginSource == WizardSource.NEW || !loginComplete
|
||||||
|
appliedLogin = login
|
||||||
|
}
|
||||||
|
|
||||||
|
val station = stationSource to stationDonor.takeIf { stationSource == WizardSource.TAKE }
|
||||||
|
if (station != appliedStation) {
|
||||||
|
val fresh = stationSource == WizardSource.NEW
|
||||||
|
val base = if (stationSource == WizardSource.TAKE) stationDonor?.prefs ?: ownPrefs else ownPrefs
|
||||||
|
val snapshot = if (base === ownPrefs) ownStation else StationSnapshot(base)
|
||||||
|
|
||||||
|
locator = if (fresh) "" else snapshot.locator
|
||||||
|
bands = if (fresh) emptySet() else snapshot.bands
|
||||||
|
category = if (fresh) null else snapshot.category
|
||||||
|
secondChat = !fresh && snapshot.secondChat
|
||||||
|
secondCategory = if (fresh) null else snapshot.secondCategory
|
||||||
|
// A kept or taken category is an operator's; the suggestion must not replace it.
|
||||||
|
categoryChosenByOperator = !fresh
|
||||||
|
|
||||||
|
siteShown = fresh || !stationComplete
|
||||||
|
antennaShown = fresh
|
||||||
|
logShown = fresh
|
||||||
|
gearShown = fresh
|
||||||
|
|
||||||
|
// Built anew from the profile the station comes from; a new station gets only
|
||||||
|
// what the operator says yes to.
|
||||||
|
antenna = WizardAntenna(base)
|
||||||
|
integrations = WizardIntegrations(base).also { if (fresh) it.loadFresh() }
|
||||||
|
appliedStation = station
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setBand(band: WizardBand, active: Boolean) {
|
||||||
|
bands = if (active) bands + band else bands - band
|
||||||
|
if (!categoryChosenByOperator) updateCategory(suggestCategory(bands))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** What the bands suggest, shown beside the picker whatever is chosen. */
|
||||||
|
val suggestedCategory: Int?
|
||||||
|
get() = suggestCategory(bands)
|
||||||
|
|
||||||
|
fun chooseCategory(number: Int) {
|
||||||
|
categoryChosenByOperator = true
|
||||||
|
updateCategory(number)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateCategory(number: Int?) {
|
||||||
|
category = number
|
||||||
|
if (secondCategory == number) secondCategory = null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun chooseSecondChat(enabled: Boolean) {
|
||||||
|
secondChat = enabled
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The main category is left out, as the Station tab does. */
|
||||||
|
val secondCategoryOptions: List<Int>
|
||||||
|
get() = CATEGORY_NUMBERS.filter { it != category }
|
||||||
|
|
||||||
|
/** The pages of this run, in order. */
|
||||||
|
val pages: List<WizardPage>
|
||||||
|
get() = buildList {
|
||||||
|
if (hasEntryPage) add(WizardPage.ENTRY)
|
||||||
|
add(WizardPage.PERSONAL)
|
||||||
|
if (loginShown) add(WizardPage.LOGIN)
|
||||||
|
if (siteShown) add(WizardPage.SITE)
|
||||||
|
if (antennaShown) add(WizardPage.ANTENNA)
|
||||||
|
if (logShown) add(WizardPage.LOG)
|
||||||
|
if (gearShown) add(WizardPage.GEAR)
|
||||||
|
add(WizardPage.SUMMARY)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val personalComplete: Boolean
|
||||||
|
get() = isStorableName(name)
|
||||||
|
|
||||||
|
private val loginComplete: Boolean
|
||||||
|
get() = isPlausibleCallsign(callsign) && isStorablePassword(password)
|
||||||
|
|
||||||
|
private val stationComplete: Boolean
|
||||||
|
get() = isLocator(locator) && bands.isNotEmpty() && category in CATEGORY_NUMBERS &&
|
||||||
|
(!secondChat || secondCategory in secondCategoryOptions)
|
||||||
|
|
||||||
|
/** The optional pages that are part of this run hold nothing that cannot be stored. */
|
||||||
|
private val shownOptionalPagesComplete: Boolean
|
||||||
|
get() = (!antennaShown || antenna.complete) &&
|
||||||
|
(!logShown || integrations.logComplete) &&
|
||||||
|
(!gearShown || integrations.gearComplete)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the answers can be saved: everything the profile needs to log in is there, and
|
||||||
|
* no page of this run holds a value that cannot be stored. The optional pages need no
|
||||||
|
* answer, but an out-of-range port on one of them still blocks.
|
||||||
|
*/
|
||||||
|
val mandatoryComplete: Boolean
|
||||||
|
get() = personalComplete && loginComplete && stationComplete && shownOptionalPagesComplete
|
||||||
|
|
||||||
|
/** A chat name that was typed and cannot be sent. An empty or blank field is not an error yet. */
|
||||||
|
val nameRefused: Boolean
|
||||||
|
get() = name.isNotBlank() && !isStorableName(name)
|
||||||
|
|
||||||
|
/** A callsign that was typed and does not look like one. An empty field is not an error yet. */
|
||||||
|
val callsignRefused: Boolean
|
||||||
|
get() = callsign.isNotBlank() && !isPlausibleCallsign(callsign)
|
||||||
|
|
||||||
|
/** A password that was typed and cannot be stored or sent. An empty field is not an error yet. */
|
||||||
|
val passwordRefused: Boolean
|
||||||
|
get() = password.isNotEmpty() && !isStorablePassword(password)
|
||||||
|
|
||||||
|
/** A locator that was typed and is not one. An empty field is not an error yet. */
|
||||||
|
val locatorRefused: Boolean
|
||||||
|
get() = locator.isNotBlank() && !isLocator(locator)
|
||||||
|
|
||||||
|
val canGoNext: Boolean
|
||||||
|
get() = when (page) {
|
||||||
|
WizardPage.ENTRY -> decided(loginSource, loginDonor) && decided(stationSource, stationDonor)
|
||||||
|
WizardPage.PERSONAL -> personalComplete
|
||||||
|
WizardPage.LOGIN -> loginComplete
|
||||||
|
WizardPage.SITE -> stationComplete
|
||||||
|
WizardPage.ANTENNA -> antenna.complete
|
||||||
|
WizardPage.LOG -> integrations.logComplete
|
||||||
|
WizardPage.GEAR -> integrations.gearComplete
|
||||||
|
WizardPage.SUMMARY -> false
|
||||||
|
}
|
||||||
|
|
||||||
|
val canGoBack: Boolean
|
||||||
|
get() = pages.indexOf(page) > 0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the remaining steps may be skipped. Only with every mandatory answer, because
|
||||||
|
* a summary that cannot be saved helps nobody.
|
||||||
|
*/
|
||||||
|
val canFinish: Boolean
|
||||||
|
get() = page != WizardPage.ENTRY && page != WizardPage.SUMMARY && mandatoryComplete
|
||||||
|
|
||||||
|
fun next() {
|
||||||
|
if (!canGoNext) return
|
||||||
|
if (page == WizardPage.ENTRY) applySources()
|
||||||
|
page = pages[pages.indexOf(page) + 1]
|
||||||
|
}
|
||||||
|
|
||||||
|
fun back() {
|
||||||
|
if (canGoBack) page = pages[pages.indexOf(page) - 1]
|
||||||
|
}
|
||||||
|
|
||||||
|
fun finish() {
|
||||||
|
if (canFinish) page = WizardPage.SUMMARY
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the log page may be opened: always once it is part of the run, and otherwise
|
||||||
|
* only if the profile has at most one log source on. The page knows one source; opened
|
||||||
|
* over several it would switch the others off.
|
||||||
|
*/
|
||||||
|
val logPageEditable: Boolean
|
||||||
|
get() = logShown || !integrations.severalStoredLogSources
|
||||||
|
|
||||||
|
/** Opens a step from the summary, also one this run skipped. */
|
||||||
|
fun edit(target: WizardPage) {
|
||||||
|
when (target) {
|
||||||
|
WizardPage.LOGIN -> loginShown = true
|
||||||
|
WizardPage.SITE -> siteShown = true
|
||||||
|
WizardPage.ANTENNA -> antennaShown = true
|
||||||
|
WizardPage.LOG -> if (logPageEditable) logShown = true else return
|
||||||
|
WizardPage.GEAR -> gearShown = true
|
||||||
|
WizardPage.PERSONAL -> Unit
|
||||||
|
WizardPage.ENTRY, WizardPage.SUMMARY -> return
|
||||||
|
}
|
||||||
|
page = target
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the frequency is taken from a log program after Save, for the summary: the
|
||||||
|
* page's answer once the log page is part of the run, and what the profile holds before.
|
||||||
|
* The two differ where a frequency source is on without its log source, which the
|
||||||
|
* settings window allows and the page cannot show.
|
||||||
|
*/
|
||||||
|
val summaryQrgFollow: Boolean
|
||||||
|
get() = if (logShown) integrations.qrgFollow else integrations.storedQrgFollow
|
||||||
|
|
||||||
|
/** Whether the DX cluster server runs after Save; see [summaryQrgFollow]. */
|
||||||
|
val summaryClusterServer: Boolean
|
||||||
|
get() = if (logShown) integrations.networked && integrations.clusterServer else integrations.storedClusterServer
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The fallback band prefix the profile has after Save, for the summary: taken with the
|
||||||
|
* donor's station when chosen, otherwise left as the own profile holds it.
|
||||||
|
*/
|
||||||
|
val summaryFallbackBand: String
|
||||||
|
get() {
|
||||||
|
val sourcePrefs = stationDonor?.takeIf { stationSource == WizardSource.TAKE }?.prefs ?: ownPrefs
|
||||||
|
return sourcePrefs.getNotify_optionalFrequencyPrefix()?.get().orEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Rotator 2 only counts while SO2R uses it, as on the Station tab. */
|
||||||
|
private fun so2rSwitches(prefs: ChatPreferences): Set<WizardSwitch> = buildSet {
|
||||||
|
if (prefs.isTrxSynch_so2rEnabled()) {
|
||||||
|
add(WizardSwitch.SO2R)
|
||||||
|
if (prefs.isStn_pstRotator2Enabled()) add(WizardSwitch.ROTATOR_2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What is on in the own profile and will be off after Save, for the summary. Always
|
||||||
|
* against the own profile: with a station taken from another one, that is what the
|
||||||
|
* operator loses, whatever the other profile had.
|
||||||
|
*
|
||||||
|
* A page that is not part of the run contributes what its profile holds -- the own one
|
||||||
|
* for a station left unchanged, the donor's for a station taken over. The wizard never
|
||||||
|
* writes SO2R or rotator 2 itself, so after Save they come from the donor when taking
|
||||||
|
* over a station, otherwise from the own profile.
|
||||||
|
*/
|
||||||
|
val switchedOff: List<WizardSwitch>
|
||||||
|
get() {
|
||||||
|
val neverAskedPrefs = stationDonor?.takeIf { stationSource == WizardSource.TAKE }?.prefs ?: ownPrefs
|
||||||
|
val after = buildSet {
|
||||||
|
if (secondChat) add(WizardSwitch.SECOND_CHAT)
|
||||||
|
addAll(if (logShown) integrations.answeredLogSwitches() else integrations.storedLogSwitches())
|
||||||
|
addAll(if (gearShown) integrations.answeredGearSwitches() else integrations.storedGearSwitches())
|
||||||
|
addAll(so2rSwitches(neverAskedPrefs))
|
||||||
|
}
|
||||||
|
val before = ownSwitches + so2rSwitches(ownPrefs) +
|
||||||
|
if (ownStation.secondChat) setOf(WizardSwitch.SECOND_CHAT) else emptySet()
|
||||||
|
return WizardSwitch.entries.filter { it in before && it !in after }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Puts the answers into [prefs] and writes its file.
|
||||||
|
*
|
||||||
|
* Everything the wizard did not ask about stays as [prefs] read it, because the whole
|
||||||
|
* file is read and written back. The callsign and the locator are stored as typed, the
|
||||||
|
* way the Station tab stores them; only surrounding blanks go.
|
||||||
|
*
|
||||||
|
* The second chat's name follows the first unless the operator had set it apart, and the
|
||||||
|
* second category is left alone while the second chat is off.
|
||||||
|
*
|
||||||
|
* Antenna, log program and equipment are written only for the pages that were part of
|
||||||
|
* this run.
|
||||||
|
*
|
||||||
|
* A station taken from another profile is copied whole before the answers are written.
|
||||||
|
*
|
||||||
|
* @return false when a mandatory answer is missing -- nothing is touched then -- or when
|
||||||
|
* the file could not be written
|
||||||
|
*/
|
||||||
|
fun writeTo(prefs: ChatPreferences): Boolean {
|
||||||
|
if (!mandatoryComplete) return false
|
||||||
|
|
||||||
|
val newName = name.trim()
|
||||||
|
|
||||||
|
prefs.setGuiOptions_language(language)
|
||||||
|
prefs.setStn_loginNameMainCat(newName)
|
||||||
|
if (storedSecondName.isBlank() || storedSecondName == storedName) {
|
||||||
|
prefs.setStn_loginNameSecondCat(newName)
|
||||||
|
}
|
||||||
|
|
||||||
|
prefs.setStn_loginCallSign(callsign.trim())
|
||||||
|
prefs.setStn_loginPassword(password)
|
||||||
|
|
||||||
|
// The whole station of the other profile first, also what no page asks about; the
|
||||||
|
// answers below then lie on top, so a taken value the operator changed wins.
|
||||||
|
if (stationSource == WizardSource.TAKE) {
|
||||||
|
stationDonor?.let { copyStation(it.prefs, prefs) }
|
||||||
|
}
|
||||||
|
|
||||||
|
prefs.setStn_loginLocatorMainCat(locator.trim())
|
||||||
|
WizardBand.entries.forEach { it.setActive(prefs, it in bands) }
|
||||||
|
prefs.setLoginChatCategoryMain(ChatCategory(requireNotNull(category)))
|
||||||
|
prefs.setLoginToSecondChatEnabled(secondChat)
|
||||||
|
if (secondChat) {
|
||||||
|
prefs.setLoginChatCategorySecond(ChatCategory(requireNotNull(secondCategory)))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (antennaShown) antenna.writeTo(prefs)
|
||||||
|
if (logShown) integrations.writeLogTo(prefs)
|
||||||
|
if (gearShown) integrations.writeGearTo(prefs)
|
||||||
|
|
||||||
|
// A write that throws is a write that failed; the wizard must stay open either way.
|
||||||
|
return runCatching { prefs.writePreferencesToXmlFile() }.getOrDefault(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
/** The categories the pickers offer, the way the Station tab builds them. */
|
||||||
|
val CATEGORY_NUMBERS: List<Int> = ChatCategory(0).possibleCategoryNumbers.toList()
|
||||||
|
|
||||||
|
private val CALLSIGN = Regex("[A-Za-z0-9]+([-/][A-Za-z0-9]+)?")
|
||||||
|
private val LOCATOR = Regex("[A-Ra-r]{2}[0-9]{2}[A-Xa-x]{2}")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a text can be a login callsign: letters and digits, at most one "-" or "/"
|
||||||
|
* suffix, and a base of three characters with a letter and a digit. Deliberately
|
||||||
|
* loose -- ON4KST decides what it accepts, this only catches a slip.
|
||||||
|
*/
|
||||||
|
fun isPlausibleCallsign(text: String): Boolean {
|
||||||
|
val trimmed = text.trim()
|
||||||
|
if (!CALLSIGN.matches(trimmed)) return false
|
||||||
|
val base = trimmed.substringBefore('-').substringBefore('/')
|
||||||
|
return base.length >= 3 && base.any(Char::isDigit) && base.any(Char::isLetter)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Whether a text is a six-character Maidenhead locator, in either case. */
|
||||||
|
fun isLocator(text: String): Boolean = LOCATOR.matches(text.trim())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a password can be stored in preferences.xml and sent in an ON4KST login frame:
|
||||||
|
* not blank, free of surrounding whitespace (which the XML reader trims), and free of
|
||||||
|
* frame delimiters.
|
||||||
|
*/
|
||||||
|
fun isStorablePassword(text: String): Boolean =
|
||||||
|
text.isNotBlank() && text == text.trim() && '|' !in text && '\r' !in text && '\n' !in text
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a chat display name can be sent in an ON4KST frame: not blank and free of
|
||||||
|
* frame delimiters.
|
||||||
|
*/
|
||||||
|
fun isStorableName(text: String): Boolean =
|
||||||
|
text.isNotBlank() && '|' !in text && '\r' !in text && '\n' !in text
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The chat category the lowest band belongs to: 1 for 50/70 MHz, 2 for 144/432 MHz,
|
||||||
|
* 3 above. Null without a band. A suggestion only -- the operator confirms it.
|
||||||
|
*/
|
||||||
|
fun suggestCategory(bands: Set<WizardBand>): Int? {
|
||||||
|
val lowest = bands.minOfOrNull { it.megahertz } ?: return null
|
||||||
|
return when {
|
||||||
|
lowest <= 70 -> ChatCategory.FIFTYSEVENTYMHz
|
||||||
|
lowest <= 432 -> ChatCategory.VUHF
|
||||||
|
else -> ChatCategory.MICROWAVE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,243 @@
|
|||||||
|
package kst4contest.view.compose.wizard
|
||||||
|
|
||||||
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.awt.ComposeDialog
|
||||||
|
import kst4contest.ApplicationConstants
|
||||||
|
import kst4contest.controller.LoginConfiguration
|
||||||
|
import kst4contest.controller.OperatorProfilePaths
|
||||||
|
import kst4contest.controller.OperatorProfileStore
|
||||||
|
import kst4contest.model.ChatPreferences
|
||||||
|
import kst4contest.utils.ApplicationFileUtils
|
||||||
|
import kst4contest.view.compose.Kst4ContestTheme
|
||||||
|
import kst4contest.view.compose.WindowPlacementOnScreen
|
||||||
|
import kst4contest.view.compose.openOnEventThread
|
||||||
|
import kst4contest.view.compose.tabs.LocalFileDialogOwner
|
||||||
|
import java.awt.Dialog
|
||||||
|
import java.awt.Dimension
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.nio.file.Path
|
||||||
|
import java.util.concurrent.atomic.AtomicReference
|
||||||
|
import javax.swing.WindowConstants
|
||||||
|
|
||||||
|
/** How a run of the setup wizard ended. */
|
||||||
|
enum class SetupWizardOutcome {
|
||||||
|
/** The profile is set up, or its file could not be read: the wizard did not open. */
|
||||||
|
NOT_SHOWN,
|
||||||
|
|
||||||
|
/** Closed without saving; the file is as it was. */
|
||||||
|
LATER,
|
||||||
|
|
||||||
|
/** The answers are in the file. */
|
||||||
|
SAVED,
|
||||||
|
|
||||||
|
/** The answers are in the file and the operator wants the session started. */
|
||||||
|
SAVED_AND_CONNECT,
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes the answers and says how the wizard ends.
|
||||||
|
*
|
||||||
|
* @return the outcome to close with, or null when the file could not be written -- the
|
||||||
|
* wizard then stays open, because "saved" would be a lie
|
||||||
|
*/
|
||||||
|
internal fun saveFromWizard(
|
||||||
|
state: SetupWizardState,
|
||||||
|
prefs: ChatPreferences,
|
||||||
|
connect: Boolean,
|
||||||
|
): SetupWizardOutcome? =
|
||||||
|
when {
|
||||||
|
!state.writeTo(prefs) -> null
|
||||||
|
connect -> SetupWizardOutcome.SAVED_AND_CONNECT
|
||||||
|
else -> SetupWizardOutcome.SAVED
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The setup wizard's window.
|
||||||
|
*
|
||||||
|
* A modal [ComposeDialog] opened through [openOnEventThread], the construction
|
||||||
|
* OperatorProfilePickerWindow uses and for the reason given there: a wait that does not
|
||||||
|
* pump events deadlocks once the caller is the event thread, and this one is called from
|
||||||
|
* `main` at startup and from the event thread when the menu rebuilds the runtime.
|
||||||
|
*/
|
||||||
|
object SetupWizardWindow {
|
||||||
|
|
||||||
|
/** Runs before a profile's runtime exists, so there is no configured size to read. */
|
||||||
|
private const val DIALOG_FONT_SIZE_SP = 12f
|
||||||
|
|
||||||
|
private val DIALOG_SIZE = Dimension(640, 620)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens the wizard and blocks until it is closed.
|
||||||
|
*
|
||||||
|
* @param prefs the profile's preferences; written only by Save
|
||||||
|
* @return never [SetupWizardOutcome.NOT_SHOWN]
|
||||||
|
*/
|
||||||
|
fun show(state: SetupWizardState, prefs: ChatPreferences): SetupWizardOutcome {
|
||||||
|
/* The window's X leaves this untouched: closing is "later". */
|
||||||
|
val outcome = AtomicReference(SetupWizardOutcome.LATER)
|
||||||
|
|
||||||
|
openOnEventThread { open(state, prefs, outcome) }
|
||||||
|
|
||||||
|
return outcome.get()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun open(
|
||||||
|
state: SetupWizardState,
|
||||||
|
prefs: ChatPreferences,
|
||||||
|
outcome: AtomicReference<SetupWizardOutcome>,
|
||||||
|
) {
|
||||||
|
val languageStore = wizardLanguageStore(state)
|
||||||
|
var saveFailed by mutableStateOf(false)
|
||||||
|
|
||||||
|
val dialog = ComposeDialog(owner = null, modalityType = Dialog.ModalityType.APPLICATION_MODAL)
|
||||||
|
dialog.title = languageStore.strings.wizardTitle
|
||||||
|
dialog.size = DIALOG_SIZE
|
||||||
|
WindowPlacementOnScreen.centreOnMainWindowScreen(dialog)
|
||||||
|
/* Disposed and not hidden: a hidden dialog keeps its window and Skia layer alive. */
|
||||||
|
dialog.defaultCloseOperation = WindowConstants.DISPOSE_ON_CLOSE
|
||||||
|
|
||||||
|
dialog.setContent {
|
||||||
|
Kst4ContestTheme(
|
||||||
|
darkMode = prefs.isGUI_darkModeActiveByDefault(),
|
||||||
|
baseFontSizeSp = DIALOG_FONT_SIZE_SP,
|
||||||
|
) {
|
||||||
|
CompositionLocalProvider(LocalFileDialogOwner provides dialog) {
|
||||||
|
SetupWizardContent(
|
||||||
|
state = state,
|
||||||
|
languageStore = languageStore,
|
||||||
|
saveFailed = saveFailed,
|
||||||
|
onLater = { dialog.dispose() },
|
||||||
|
onSave = { connect ->
|
||||||
|
val saved = saveFromWizard(state, prefs, connect)
|
||||||
|
if (saved == null) {
|
||||||
|
saveFailed = true
|
||||||
|
} else {
|
||||||
|
outcome.set(saved)
|
||||||
|
dialog.dispose()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog.isVisible = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Another profile that might serve as a donor: who it is and where its preferences lie. */
|
||||||
|
internal class DonorCandidate(val profileId: String, val displayName: String, val file: Path)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the candidates that can serve as donors: the file exists, can be read, and holds a
|
||||||
|
* login an operator entered. A candidate whose file is the same file as [activeFile] (for
|
||||||
|
* example through a symbolic link) is skipped so a profile never becomes its own donor.
|
||||||
|
*
|
||||||
|
* A candidate's file is opened through `ChatPreferences(Path)` and never through the
|
||||||
|
* constructor that takes a name below the application directory: that one seeds a missing
|
||||||
|
* file from the bundled template, and looking for a donor must not create a profile's file.
|
||||||
|
* Nothing here writes.
|
||||||
|
*/
|
||||||
|
internal fun loadDonors(
|
||||||
|
candidates: List<DonorCandidate>,
|
||||||
|
activeFile: Path? = null,
|
||||||
|
): List<WizardDonor> =
|
||||||
|
candidates.mapNotNull { candidate ->
|
||||||
|
if (!Files.isRegularFile(candidate.file)) return@mapNotNull null
|
||||||
|
if (activeFile != null && Files.exists(activeFile) &&
|
||||||
|
runCatching { Files.isSameFile(candidate.file, activeFile) }.getOrDefault(false)
|
||||||
|
) {
|
||||||
|
return@mapNotNull null
|
||||||
|
}
|
||||||
|
|
||||||
|
val prefs = ChatPreferences(candidate.file)
|
||||||
|
// A throwing read counts as failed, as for the profile being set up.
|
||||||
|
if (!runCatching { prefs.readPreferencesFromXmlFile() }.getOrDefault(false)) return@mapNotNull null
|
||||||
|
if (LoginConfiguration.isUnconfigured(prefs)) return@mapNotNull null
|
||||||
|
|
||||||
|
WizardDonor(candidate.profileId, candidate.displayName, prefs)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Decides whether the wizard opens for a profile, and opens it. */
|
||||||
|
object SetupWizardLauncher {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens the wizard when the profile needs it, before the profile's runtime is built.
|
||||||
|
*
|
||||||
|
* @param preferencesRelativeFileName the profile's preferences file below the
|
||||||
|
* application directory; a missing one is seeded from the bundled template, as
|
||||||
|
* the runtime itself would do
|
||||||
|
* @param forced the operator asked for the wizard from the menu
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun runIfNeeded(preferencesRelativeFileName: String, forced: Boolean): SetupWizardOutcome =
|
||||||
|
run(
|
||||||
|
ChatPreferences(preferencesRelativeFileName),
|
||||||
|
forced,
|
||||||
|
{
|
||||||
|
loadDonors(
|
||||||
|
otherProfiles(preferencesRelativeFileName),
|
||||||
|
activeFile = Path.of(
|
||||||
|
ApplicationFileUtils.getFilePath(
|
||||||
|
ApplicationConstants.APPLICATION_NAME,
|
||||||
|
preferencesRelativeFileName,
|
||||||
|
)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
SetupWizardWindow::show,
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Every registered profile but the one being set up, with the file its preferences lie
|
||||||
|
* in. Empty on an installation without a profile registry: there is only the root
|
||||||
|
* profile then, and it is the active one.
|
||||||
|
*/
|
||||||
|
private fun otherProfiles(activeRelativeFileName: String): List<DonorCandidate> =
|
||||||
|
OperatorProfileStore().loadProfiles().mapNotNull { profile ->
|
||||||
|
val relativeFileName = OperatorProfilePaths.preferencesRelativeFileName(profile)
|
||||||
|
if (relativeFileName == activeRelativeFileName) return@mapNotNull null
|
||||||
|
|
||||||
|
DonorCandidate(
|
||||||
|
profile.profileId,
|
||||||
|
profile.displayName,
|
||||||
|
Path.of(ApplicationFileUtils.getFilePath(ApplicationConstants.APPLICATION_NAME, relativeFileName)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Without other profiles; for callers and tests that have none. */
|
||||||
|
internal fun run(
|
||||||
|
prefs: ChatPreferences,
|
||||||
|
forced: Boolean,
|
||||||
|
show: (SetupWizardState, ChatPreferences) -> SetupWizardOutcome,
|
||||||
|
): SetupWizardOutcome = run(prefs, forced, { emptyList() }, show)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param prefs bound to the profile's file and not read yet
|
||||||
|
* @param donors reads the other profiles; called only once the wizard is certain to
|
||||||
|
* open, so an ordinary start reads no file but its own
|
||||||
|
* @param show opens the window; replaced in the tests
|
||||||
|
*/
|
||||||
|
internal fun run(
|
||||||
|
prefs: ChatPreferences,
|
||||||
|
forced: Boolean,
|
||||||
|
donors: () -> List<WizardDonor>,
|
||||||
|
show: (SetupWizardState, ChatPreferences) -> SetupWizardOutcome,
|
||||||
|
): SetupWizardOutcome {
|
||||||
|
/*
|
||||||
|
* A file that cannot be read is not a profile to set up: the wizard would start from
|
||||||
|
* compiled-in defaults and Save would write them over whatever the file holds. The
|
||||||
|
* runtime deals with such a file as it always did. A throwing read counts as failed too.
|
||||||
|
*/
|
||||||
|
if (!runCatching { prefs.readPreferencesFromXmlFile() }.getOrDefault(false)) {
|
||||||
|
return SetupWizardOutcome.NOT_SHOWN
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!forced && !LoginConfiguration.isUnconfigured(prefs)) return SetupWizardOutcome.NOT_SHOWN
|
||||||
|
|
||||||
|
return show(SetupWizardState(prefs, donors()), prefs)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package kst4contest.view.compose.wizard
|
||||||
|
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import kst4contest.model.ChatPreferences
|
||||||
|
import kst4contest.view.compose.tabs.StationTabState
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The setup wizard's answers about antenna and power.
|
||||||
|
*
|
||||||
|
* These numbers have no empty state: every answer starts as the stored value and is a
|
||||||
|
* proposal the operator may pass unchanged, also when a station is set up anew. They feed the
|
||||||
|
* path analysis and the antenna sector on the map; the chat does not need them.
|
||||||
|
*
|
||||||
|
* The site elevation is the exception in form, not in rule: it is text, because empty is a
|
||||||
|
* value of its own -- "let the elevation model decide" -- and it is read exactly as the
|
||||||
|
* Station tab reads it.
|
||||||
|
*
|
||||||
|
* @param prefs the profile's preferences, already read from its file
|
||||||
|
*/
|
||||||
|
class WizardAntenna(prefs: ChatPreferences) {
|
||||||
|
|
||||||
|
private val storedBeamWidthDeg = prefs.getStn_antennaBeamWidthDeg()
|
||||||
|
private val storedGainDbi = prefs.getStn_pathAnalysisOwnAntennaGainDbi()
|
||||||
|
// The XML reader assigns the field directly without clamping, whereas the setter and path analysis treat < 0 as 0.
|
||||||
|
private val storedHeightMeters = prefs.getStn_pathAnalysisOwnAntennaHeightMeters().coerceAtLeast(0.0)
|
||||||
|
private val storedTxPowerWatts = prefs.getStn_pathAnalysisOwnTxPowerWatts()
|
||||||
|
private val storedHeightAslText = elevationText(prefs.getStn_pathAnalysisOwnHeightAslMeters())
|
||||||
|
|
||||||
|
var beamWidthDeg: Double by mutableStateOf(storedBeamWidthDeg)
|
||||||
|
var gainDbi: Double by mutableStateOf(storedGainDbi)
|
||||||
|
var heightMeters: Double by mutableStateOf(storedHeightMeters)
|
||||||
|
var txPowerWatts: Double by mutableStateOf(storedTxPowerWatts)
|
||||||
|
|
||||||
|
/** The site elevation above sea level as the operator types it; empty for the model. */
|
||||||
|
var heightAslText: String by mutableStateOf(storedHeightAslText)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Puts every answer back to what the profile holds. For the moment the operator changes
|
||||||
|
* his mind about where the station comes from: what he typed for one choice must not
|
||||||
|
* show in the summary of the other, where it would not be written.
|
||||||
|
*/
|
||||||
|
fun loadStored() {
|
||||||
|
beamWidthDeg = storedBeamWidthDeg
|
||||||
|
gainDbi = storedGainDbi
|
||||||
|
heightMeters = storedHeightMeters
|
||||||
|
txPowerWatts = storedTxPowerWatts
|
||||||
|
heightAslText = storedHeightAslText
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A site elevation that is neither empty nor a number in the accepted range. */
|
||||||
|
val heightAslRefused: Boolean
|
||||||
|
get() = StationTabState.parseOwnHeightAsl(heightAslText) == null
|
||||||
|
|
||||||
|
/** Whether every answer can be stored as it stands. */
|
||||||
|
val complete: Boolean
|
||||||
|
get() = beamWidthDeg.isFinite() && gainDbi.isFinite() && heightMeters.isFinite() &&
|
||||||
|
heightMeters >= 0.0 && txPowerWatts.isFinite() && !heightAslRefused
|
||||||
|
|
||||||
|
/** Puts the answers into [prefs]. Call only while [complete]. */
|
||||||
|
fun writeTo(prefs: ChatPreferences) {
|
||||||
|
prefs.setStn_antennaBeamWidthDeg(beamWidthDeg)
|
||||||
|
prefs.setStn_pathAnalysisOwnAntennaGainDbi(gainDbi)
|
||||||
|
prefs.setStn_pathAnalysisOwnAntennaHeightMeters(heightMeters)
|
||||||
|
prefs.setStn_pathAnalysisOwnTxPowerWatts(txPowerWatts)
|
||||||
|
prefs.setStn_pathAnalysisOwnHeightAslMeters(
|
||||||
|
StationTabState.parseOwnHeightAsl(heightAslText) ?: Double.NaN
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
/** Empty for "unset"; a whole number without ".0", so the field shows what one types. */
|
||||||
|
fun elevationText(meters: Double): String = when {
|
||||||
|
meters.isNaN() -> ""
|
||||||
|
meters == Math.floor(meters) && !meters.isInfinite() -> meters.toLong().toString()
|
||||||
|
else -> meters.toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,289 @@
|
|||||||
|
package kst4contest.view.compose.wizard
|
||||||
|
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import kst4contest.model.ChatPreferences
|
||||||
|
import kst4contest.view.compose.tabs.AirscoutTabState
|
||||||
|
import kst4contest.view.compose.tabs.StationTabState
|
||||||
|
|
||||||
|
/** Where the worked stations come from. The wizard knows one source at a time. */
|
||||||
|
enum class WizardLogProgram {
|
||||||
|
NONE,
|
||||||
|
|
||||||
|
/** The Win-Test network listener. */
|
||||||
|
WINTEST,
|
||||||
|
|
||||||
|
/** UCXLog, DXLog.net, N1MM+ and QARTEST: QSO messages on the shared UDP port. */
|
||||||
|
UDP,
|
||||||
|
|
||||||
|
/** A log file polled for callsigns. */
|
||||||
|
FILE,
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Something that was on in the profile and will be off after Save, for the summary. */
|
||||||
|
enum class WizardSwitch {
|
||||||
|
SECOND_CHAT,
|
||||||
|
LOG_WINTEST,
|
||||||
|
LOG_UDP,
|
||||||
|
LOG_FILE,
|
||||||
|
QRG_FOLLOW,
|
||||||
|
CLUSTER_SERVER,
|
||||||
|
ROTATOR,
|
||||||
|
AIRSCOUT,
|
||||||
|
SO2R,
|
||||||
|
ROTATOR_2,
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The setup wizard's answers about log program, rotator and AirScout.
|
||||||
|
*
|
||||||
|
* Two pages share this class because they share a rule: a station set up anew gets only what
|
||||||
|
* the operator said yes to. [loadFresh] therefore switches everything off -- the bundled
|
||||||
|
* template has several of these on, which a newcomer without a log program does not know --
|
||||||
|
* while ports, names, host and identifiers stay as stored and are proposals.
|
||||||
|
*
|
||||||
|
* The wizard switches things on and off and takes numbers over. It invents none: no port,
|
||||||
|
* no identifier and no default here differs from what the settings tabs accept.
|
||||||
|
*
|
||||||
|
* The settings window allows several log sources at once and the wizard's question does
|
||||||
|
* not. [severalStoredLogSources] says when the stored profile is such a case, so the caller
|
||||||
|
* can keep the log page shut rather than collapse the sources into one.
|
||||||
|
*
|
||||||
|
* @param prefs the profile's preferences, already read from its file
|
||||||
|
*/
|
||||||
|
class WizardIntegrations(prefs: ChatPreferences) {
|
||||||
|
|
||||||
|
private val storedWintest = prefs.isLogsynch_wintestNetworkListenerEnabled()
|
||||||
|
private val storedUdp = prefs.isLogsynch_ucxUDPWkdCallListenerEnabled()
|
||||||
|
private val storedFile = prefs.isLogsynch_fileBasedWkdCallInterpreterEnabled()
|
||||||
|
private val storedUdpQrg = prefs.isTrxSynch_ucxLogUDPListenerEnabled()
|
||||||
|
private val storedWintestQrg = prefs.isLogsynch_wintestQrgSyncEnabled()
|
||||||
|
private val storedCluster = prefs.isNotify_dxClusterServerEnabled()
|
||||||
|
private val storedRotator = prefs.isStn_pstRotatorEnabled()
|
||||||
|
private val storedAirScout = prefs.isAirScout_asUDPListenerEnabled()
|
||||||
|
|
||||||
|
/** Rotator 2 only counts while SO2R uses it, as on the Station tab. */
|
||||||
|
private val rotatorTwoInUse = prefs.isTrxSynch_so2rEnabled() && prefs.isStn_pstRotator2Enabled()
|
||||||
|
private val rotatorTwoPort = prefs.getStn_pstRotator2Port()
|
||||||
|
|
||||||
|
/** More than one log source is on in the profile; the log page cannot show that. */
|
||||||
|
val severalStoredLogSources: Boolean = listOf(storedWintest, storedUdp, storedFile).count { it } > 1
|
||||||
|
|
||||||
|
var logProgram: WizardLogProgram by mutableStateOf(WizardLogProgram.NONE)
|
||||||
|
private set
|
||||||
|
|
||||||
|
private val storedUdpPort = prefs.getLogsynch_ucxUDPWkdCallListenerPort()
|
||||||
|
private val storedWintestPort = prefs.getLogsynch_wintestNetworkPort()
|
||||||
|
private val storedWintestStationName = prefs.getLogsynch_wintestNetworkStationNameOfKST().orEmpty()
|
||||||
|
private val storedFilePath = prefs.getLogsynch_fileBasedWkdCallInterpreterFileNameReadOnly().orEmpty()
|
||||||
|
private val storedRotatorHost = prefs.getStn_pstRotatorHost().orEmpty()
|
||||||
|
private val storedRotatorPort = prefs.getStn_pstRotatorPort()
|
||||||
|
private val storedAirScoutPort = prefs.getAirScout_asCommunicationPort()
|
||||||
|
private val storedAirScoutServerName = prefs.getAirScout_asServerNameString().orEmpty()
|
||||||
|
private val storedAirScoutClientName = prefs.getAirScout_asClientNameString().orEmpty()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the profile takes its own frequency from a log program, whichever one. Known
|
||||||
|
* apart from [qrgFollow] because the settings window allows a frequency source without
|
||||||
|
* the matching log source, which the page's single choice cannot show.
|
||||||
|
*/
|
||||||
|
val storedQrgFollow: Boolean = storedUdpQrg || storedWintestQrg
|
||||||
|
|
||||||
|
/** Whether the profile runs the local DX cluster server, with or without a log source. */
|
||||||
|
val storedClusterServer: Boolean = storedCluster
|
||||||
|
|
||||||
|
var udpPort: Int by mutableStateOf(storedUdpPort)
|
||||||
|
var wintestPort: Int by mutableStateOf(storedWintestPort)
|
||||||
|
var wintestStationName: String by mutableStateOf(storedWintestStationName)
|
||||||
|
var filePath: String by mutableStateOf(storedFilePath)
|
||||||
|
|
||||||
|
/** Take the own frequency from the chosen network program. */
|
||||||
|
var qrgFollow: Boolean by mutableStateOf(false)
|
||||||
|
|
||||||
|
/** Pass spots to the log program through the local DX cluster server. */
|
||||||
|
var clusterServer: Boolean by mutableStateOf(false)
|
||||||
|
|
||||||
|
var rotator: Boolean by mutableStateOf(false)
|
||||||
|
var rotatorHost: String by mutableStateOf(storedRotatorHost)
|
||||||
|
var rotatorPort: Int by mutableStateOf(storedRotatorPort)
|
||||||
|
|
||||||
|
var airScout: Boolean by mutableStateOf(false)
|
||||||
|
var airScoutPort: Int by mutableStateOf(storedAirScoutPort)
|
||||||
|
var airScoutServerName: String by mutableStateOf(storedAirScoutServerName)
|
||||||
|
var airScoutClientName: String by mutableStateOf(storedAirScoutClientName)
|
||||||
|
|
||||||
|
init {
|
||||||
|
loadStored()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The switches as the profile has them. Several sources show as one, the network ones first. */
|
||||||
|
fun loadStored() {
|
||||||
|
logProgram = when {
|
||||||
|
storedWintest -> WizardLogProgram.WINTEST
|
||||||
|
storedUdp -> WizardLogProgram.UDP
|
||||||
|
storedFile -> WizardLogProgram.FILE
|
||||||
|
else -> WizardLogProgram.NONE
|
||||||
|
}
|
||||||
|
qrgFollow = when (logProgram) {
|
||||||
|
WizardLogProgram.WINTEST -> storedWintestQrg
|
||||||
|
WizardLogProgram.UDP -> storedUdpQrg
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
clusterServer = networked && storedCluster
|
||||||
|
rotator = storedRotator
|
||||||
|
airScout = storedAirScout
|
||||||
|
loadStoredDetails()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A station set up anew: every switch off, every number left as a proposal. */
|
||||||
|
fun loadFresh() {
|
||||||
|
logProgram = WizardLogProgram.NONE
|
||||||
|
qrgFollow = false
|
||||||
|
clusterServer = false
|
||||||
|
rotator = false
|
||||||
|
airScout = false
|
||||||
|
loadStoredDetails()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ports, names, host and identifiers back to what the profile holds. Both loads do this:
|
||||||
|
* they run when the operator changes his mind about where the station comes from, and a
|
||||||
|
* number typed under one choice must not turn up under the other.
|
||||||
|
*/
|
||||||
|
private fun loadStoredDetails() {
|
||||||
|
udpPort = storedUdpPort
|
||||||
|
wintestPort = storedWintestPort
|
||||||
|
wintestStationName = storedWintestStationName
|
||||||
|
filePath = storedFilePath
|
||||||
|
rotatorHost = storedRotatorHost
|
||||||
|
rotatorPort = storedRotatorPort
|
||||||
|
airScoutPort = storedAirScoutPort
|
||||||
|
airScoutServerName = storedAirScoutServerName
|
||||||
|
airScoutClientName = storedAirScoutClientName
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Only a network program can deliver a frequency or take spots. */
|
||||||
|
val networked: Boolean
|
||||||
|
get() = logProgram == WizardLogProgram.WINTEST || logProgram == WizardLogProgram.UDP
|
||||||
|
|
||||||
|
fun chooseLogProgram(program: WizardLogProgram) {
|
||||||
|
logProgram = program
|
||||||
|
if (!networked) {
|
||||||
|
qrgFollow = false
|
||||||
|
clusterServer = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Whether what the chosen program needs is there. A program not chosen needs nothing. */
|
||||||
|
val logComplete: Boolean
|
||||||
|
get() = when (logProgram) {
|
||||||
|
WizardLogProgram.NONE -> true
|
||||||
|
WizardLogProgram.WINTEST -> AirscoutTabState.isValidPort(wintestPort) && wintestStationName.isNotBlank()
|
||||||
|
WizardLogProgram.UDP -> AirscoutTabState.isValidPort(udpPort)
|
||||||
|
WizardLogProgram.FILE -> filePath.isNotBlank()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The same or the next port as rotator 2, which answers on its port + 1. */
|
||||||
|
val rotatorPortClashes: Boolean
|
||||||
|
get() = rotator && rotatorTwoInUse && StationTabState.portsClash(rotatorPort, rotatorTwoPort)
|
||||||
|
|
||||||
|
/** Whether what the switched-on equipment needs is there. */
|
||||||
|
val gearComplete: Boolean
|
||||||
|
get() {
|
||||||
|
val rotatorComplete = !rotator ||
|
||||||
|
(rotatorHost.isNotBlank() && rotatorPort in ROTATOR_PORTS && !rotatorPortClashes)
|
||||||
|
val airScoutComplete = !airScout ||
|
||||||
|
(AirscoutTabState.isValidPort(airScoutPort) &&
|
||||||
|
AirscoutTabState.isValidIdentifier(airScoutServerName) &&
|
||||||
|
AirscoutTabState.isValidIdentifier(airScoutClientName))
|
||||||
|
return rotatorComplete && airScoutComplete
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Puts the log page's answers into [prefs]: exactly the chosen source on, its details
|
||||||
|
* stored, and the frequency source and the DX cluster server only with a network program.
|
||||||
|
* Details of a program that is not chosen are left as they are. Call only while
|
||||||
|
* [logComplete].
|
||||||
|
*/
|
||||||
|
fun writeLogTo(prefs: ChatPreferences) {
|
||||||
|
prefs.setLogsynch_wintestNetworkListenerEnabled(logProgram == WizardLogProgram.WINTEST)
|
||||||
|
prefs.setLogsynch_ucxUDPWkdCallListenerEnabled(logProgram == WizardLogProgram.UDP)
|
||||||
|
prefs.setLogsynch_fileBasedWkdCallInterpreterEnabled(logProgram == WizardLogProgram.FILE)
|
||||||
|
|
||||||
|
when (logProgram) {
|
||||||
|
WizardLogProgram.WINTEST -> {
|
||||||
|
prefs.setLogsynch_wintestNetworkPort(wintestPort)
|
||||||
|
prefs.setLogsynch_wintestNetworkStationNameOfKST(wintestStationName.trim())
|
||||||
|
}
|
||||||
|
WizardLogProgram.UDP -> prefs.setLogsynch_ucxUDPWkdCallListenerPort(udpPort)
|
||||||
|
WizardLogProgram.FILE -> prefs.setLogsynch_fileBasedWkdCallInterpreterFileNameReadOnly(filePath)
|
||||||
|
WizardLogProgram.NONE -> Unit
|
||||||
|
}
|
||||||
|
|
||||||
|
prefs.setLogsynch_wintestQrgSyncEnabled(logProgram == WizardLogProgram.WINTEST && qrgFollow)
|
||||||
|
prefs.setTrxSynch_ucxLogUDPListenerEnabled(logProgram == WizardLogProgram.UDP && qrgFollow)
|
||||||
|
prefs.setNotify_dxClusterServerEnabled(networked && clusterServer)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Puts the equipment page's answers into [prefs]. Host, port and identifiers are stored
|
||||||
|
* only for what is switched on. Call only while [gearComplete].
|
||||||
|
*/
|
||||||
|
fun writeGearTo(prefs: ChatPreferences) {
|
||||||
|
prefs.setStn_pstRotatorEnabled(rotator)
|
||||||
|
if (rotator) {
|
||||||
|
prefs.setStn_pstRotatorHost(rotatorHost.trim())
|
||||||
|
prefs.setStn_pstRotatorPort(rotatorPort)
|
||||||
|
}
|
||||||
|
|
||||||
|
prefs.setAirScout_asUDPListenerEnabled(airScout)
|
||||||
|
if (airScout) {
|
||||||
|
prefs.setAirScout_asCommunicationPort(airScoutPort)
|
||||||
|
prefs.setAirScout_asServerNameString(airScoutServerName.trim())
|
||||||
|
prefs.setAirScout_asClientNameString(airScoutClientName.trim())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The log-page switches the profile these answers were built from has on. */
|
||||||
|
fun storedLogSwitches(): Set<WizardSwitch> = buildSet {
|
||||||
|
if (storedWintest) add(WizardSwitch.LOG_WINTEST)
|
||||||
|
if (storedUdp) add(WizardSwitch.LOG_UDP)
|
||||||
|
if (storedFile) add(WizardSwitch.LOG_FILE)
|
||||||
|
if (storedQrgFollow) add(WizardSwitch.QRG_FOLLOW)
|
||||||
|
if (storedCluster) add(WizardSwitch.CLUSTER_SERVER)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The equipment switches the profile these answers were built from has on. */
|
||||||
|
fun storedGearSwitches(): Set<WizardSwitch> = buildSet {
|
||||||
|
if (storedRotator) add(WizardSwitch.ROTATOR)
|
||||||
|
if (storedAirScout) add(WizardSwitch.AIRSCOUT)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The log-page switches that are on once [writeLogTo] has run. */
|
||||||
|
fun answeredLogSwitches(): Set<WizardSwitch> = buildSet {
|
||||||
|
when (logProgram) {
|
||||||
|
WizardLogProgram.WINTEST -> add(WizardSwitch.LOG_WINTEST)
|
||||||
|
WizardLogProgram.UDP -> add(WizardSwitch.LOG_UDP)
|
||||||
|
WizardLogProgram.FILE -> add(WizardSwitch.LOG_FILE)
|
||||||
|
WizardLogProgram.NONE -> Unit
|
||||||
|
}
|
||||||
|
if (networked && qrgFollow) add(WizardSwitch.QRG_FOLLOW)
|
||||||
|
if (networked && clusterServer) add(WizardSwitch.CLUSTER_SERVER)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The equipment switches that are on once [writeGearTo] has run. */
|
||||||
|
fun answeredGearSwitches(): Set<WizardSwitch> = buildSet {
|
||||||
|
if (rotator) add(WizardSwitch.ROTATOR)
|
||||||
|
if (airScout) add(WizardSwitch.AIRSCOUT)
|
||||||
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
/**
|
||||||
|
* The ports setStn_pstRotatorPort stores. One short of the full range, because
|
||||||
|
* PSTRotator answers on port + 1; the setter replaces anything else by its factory
|
||||||
|
* default, which would be the wizard inventing a number.
|
||||||
|
*/
|
||||||
|
val ROTATOR_PORTS = 1..65534
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
package kst4contest.view.compose.wizard
|
||||||
|
|
||||||
|
import kst4contest.model.ChatCategory
|
||||||
|
import kst4contest.model.ChatPreferences
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the station from one profile's preferences to another's.
|
||||||
|
*
|
||||||
|
* "The station" is what hangs on the site and the equipment: locator, bands, chat
|
||||||
|
* categories, antenna and path-analysis values, log program, frequency source, DX cluster
|
||||||
|
* server, rotators, AirScout. It is deliberately more than the setup wizard asks about -- a
|
||||||
|
* further operator at the same station should inherit the second rotator and the Win-Test
|
||||||
|
* station filter too, without ever seeing a question for them.
|
||||||
|
*
|
||||||
|
* It is deliberately not the operator: login, names, language, appearance, layout,
|
||||||
|
* shortcuts, snippets, beacons, automatic answers, sounds, filters. Nor the server address
|
||||||
|
* or the spotter callsign.
|
||||||
|
*
|
||||||
|
* Which setter belongs where is decided line by line in
|
||||||
|
* `src/test/resources/wizard-station-setters.txt` and `wizard-other-setters.txt`; a test
|
||||||
|
* holds this function and those lists together, and fails when ChatPreferences gains a
|
||||||
|
* setter nobody classified.
|
||||||
|
*
|
||||||
|
* Nothing is written to a file here, and [from] is only read.
|
||||||
|
*/
|
||||||
|
internal fun copyStation(from: ChatPreferences, to: ChatPreferences) {
|
||||||
|
// Location, bands and chats. The categories are copied by number: the two profiles
|
||||||
|
// must not share one mutable ChatCategory.
|
||||||
|
to.setStn_loginLocatorMainCat(from.getStn_loginLocatorMainCat())
|
||||||
|
to.setLoginChatCategoryMain(from.getLoginChatCategoryMain()?.let { ChatCategory(it.categoryNumber) })
|
||||||
|
to.setLoginChatCategorySecond(from.getLoginChatCategorySecond()?.let { ChatCategory(it.categoryNumber) })
|
||||||
|
to.setLoginToSecondChatEnabled(from.isLoginToSecondChatEnabled())
|
||||||
|
|
||||||
|
// Bands.
|
||||||
|
to.setStn_bandActive50(from.isStn_bandActive50())
|
||||||
|
to.setStn_bandActive70(from.isStn_bandActive70())
|
||||||
|
to.setStn_bandActive144(from.isStn_bandActive144())
|
||||||
|
to.setStn_bandActive432(from.isStn_bandActive432())
|
||||||
|
to.setStn_bandActive1240(from.isStn_bandActive1240())
|
||||||
|
to.setStn_bandActive2300(from.isStn_bandActive2300())
|
||||||
|
to.setStn_bandActive3400(from.isStn_bandActive3400())
|
||||||
|
to.setStn_bandActive5600(from.isStn_bandActive5600())
|
||||||
|
to.setStn_bandActive10G(from.isStn_bandActive10G())
|
||||||
|
|
||||||
|
// Antenna, defaults and everything the path analysis needs to know about the site.
|
||||||
|
to.setStn_antennaBeamWidthDeg(from.getStn_antennaBeamWidthDeg())
|
||||||
|
to.setStn_qtfDefault(from.getStn_qtfDefault())
|
||||||
|
to.setStn_maxQRBDefault(from.getStn_maxQRBDefault())
|
||||||
|
to.setStn_useQtfFilterDirectionAsAntennaHeading(from.isStn_useQtfFilterDirectionAsAntennaHeading())
|
||||||
|
to.setStn_pathAnalysisOwnAntennaGainDbi(from.getStn_pathAnalysisOwnAntennaGainDbi())
|
||||||
|
to.setStn_pathAnalysisOwnAntennaHeightMeters(from.getStn_pathAnalysisOwnAntennaHeightMeters())
|
||||||
|
to.setStn_pathAnalysisOwnTxPowerWatts(from.getStn_pathAnalysisOwnTxPowerWatts())
|
||||||
|
to.setStn_pathAnalysisOwnHeightAslMeters(from.getStn_pathAnalysisOwnHeightAslMeters())
|
||||||
|
to.setStn_pathAnalysisDefaultTargetAntennaGainDbi(from.getStn_pathAnalysisDefaultTargetAntennaGainDbi())
|
||||||
|
to.setStn_pathAnalysisDefaultTargetAntennaHeightMeters(from.getStn_pathAnalysisDefaultTargetAntennaHeightMeters())
|
||||||
|
to.setStn_pathAnalysisDefaultTargetTxPowerWatts(from.getStn_pathAnalysisDefaultTargetTxPowerWatts())
|
||||||
|
to.setStn_pathAnalysisDxHighestPointInSquare(from.isStn_pathAnalysisDxHighestPointInSquare())
|
||||||
|
to.setStn_pathAnalysisDemRootDirectory(from.getStn_pathAnalysisDemRootDirectory())
|
||||||
|
to.setStn_pathAnalysisDemDatasetId(from.getStn_pathAnalysisDemDatasetId())
|
||||||
|
to.setStn_pathAnalysisVhfFeederLossPerStationDb(from.getStn_pathAnalysisVhfFeederLossPerStationDb())
|
||||||
|
to.setStn_pathAnalysisFeederLossIncreaseDbPer200MHz(from.getStn_pathAnalysisFeederLossIncreaseDbPer200MHz())
|
||||||
|
to.setStn_pathAnalysisMaxEstimatedFeederLossPerStationDb(from.getStn_pathAnalysisMaxEstimatedFeederLossPerStationDb())
|
||||||
|
to.setStn_pathAnalysisRequiredSsbSignalDbm(from.getStn_pathAnalysisRequiredSsbSignalDbm())
|
||||||
|
to.setStn_pathAnalysisRequiredCwSignalDbm(from.getStn_pathAnalysisRequiredCwSignalDbm())
|
||||||
|
to.setStn_pathAnalysisContestMarginDb(from.getStn_pathAnalysisContestMarginDb())
|
||||||
|
|
||||||
|
// Log sources. All of them as they are: a station may run several at once.
|
||||||
|
to.setLogsynch_fileBasedWkdCallInterpreterEnabled(from.isLogsynch_fileBasedWkdCallInterpreterEnabled())
|
||||||
|
to.setLogsynch_fileBasedWkdCallInterpreterFileNameReadOnly(from.getLogsynch_fileBasedWkdCallInterpreterFileNameReadOnly())
|
||||||
|
to.setLogsynch_ucxUDPWkdCallListenerEnabled(from.isLogsynch_ucxUDPWkdCallListenerEnabled())
|
||||||
|
to.setLogsynch_ucxUDPWkdCallListenerPort(from.getLogsynch_ucxUDPWkdCallListenerPort())
|
||||||
|
to.setLogsynch_wintestNetworkListenerEnabled(from.isLogsynch_wintestNetworkListenerEnabled())
|
||||||
|
to.setLogsynch_wintestNetworkPort(from.getLogsynch_wintestNetworkPort())
|
||||||
|
to.setLogsynch_wintestNetworkBroadcastAddress(from.getLogsynch_wintestNetworkBroadcastAddress())
|
||||||
|
to.setLogsynch_wintestNetworkStationNameOfKST(from.getLogsynch_wintestNetworkStationNameOfKST())
|
||||||
|
to.setLogsynch_wintestNetworkStationIDOfKST(from.getLogsynch_wintestNetworkStationIDOfKST())
|
||||||
|
to.setLogsynch_wintestNetworkStationNameOfWintestClient1(from.getLogsynch_wintestNetworkStationNameOfWintestClient1())
|
||||||
|
to.setLogsynch_wintestNetworkStationNameOfWintestClient2(from.getLogsynch_wintestNetworkStationNameOfWintestClient2())
|
||||||
|
to.setLogsynch_wintestNetworkSkedPushEnabled(from.isLogsynch_wintestNetworkSkedPushEnabled())
|
||||||
|
to.setLogsynch_wintestNetworkSimulationEnabled(from.isLogsynch_wintestNetworkSimulationEnabled())
|
||||||
|
to.setLogsynch_wintestSkedMode(from.getLogsynch_wintestSkedMode())
|
||||||
|
|
||||||
|
// Frequency sources, SO2R and the DX cluster server for the log program.
|
||||||
|
to.setLogsynch_wintestQrgSyncEnabled(from.isLogsynch_wintestQrgSyncEnabled())
|
||||||
|
to.setLogsynch_wintestUsePassQrg(from.isLogsynch_wintestUsePassQrg())
|
||||||
|
to.setTrxSynch_ucxLogUDPListenerEnabled(from.isTrxSynch_ucxLogUDPListenerEnabled())
|
||||||
|
to.setTrxSynch_so2rEnabled(from.isTrxSynch_so2rEnabled())
|
||||||
|
to.setNotify_dxClusterServerEnabled(from.isNotify_dxClusterServerEnabled())
|
||||||
|
to.setNotify_dxclusterServerPort(from.getNotify_dxclusterServerPort())
|
||||||
|
// The band a frequency given without one is completed with; it has to fit the bands above.
|
||||||
|
to.setNotify_optionalFrequencyPrefix(from.getNotify_optionalFrequencyPrefix().get())
|
||||||
|
|
||||||
|
// Rotators.
|
||||||
|
to.setStn_pstRotatorEnabled(from.isStn_pstRotatorEnabled())
|
||||||
|
to.setStn_pstRotatorHost(from.getStn_pstRotatorHost())
|
||||||
|
to.setStn_pstRotatorPort(from.getStn_pstRotatorPort())
|
||||||
|
to.setStn_pstRotator2Enabled(from.isStn_pstRotator2Enabled())
|
||||||
|
to.setStn_pstRotator2Host(from.getStn_pstRotator2Host())
|
||||||
|
to.setStn_pstRotator2Port(from.getStn_pstRotator2Port())
|
||||||
|
|
||||||
|
// AirScout.
|
||||||
|
to.setAirScout_asUDPListenerEnabled(from.isAirScout_asUDPListenerEnabled())
|
||||||
|
to.setAirScout_asCommunicationPort(from.getAirScout_asCommunicationPort())
|
||||||
|
to.setAirScout_asServerNameString(from.getAirScout_asServerNameString())
|
||||||
|
to.setAirScout_asClientNameString(from.getAirScout_asClientNameString())
|
||||||
|
to.setAirScout_autoBandSelectionEnabled(from.isAirScout_autoBandSelectionEnabled())
|
||||||
|
to.setAirScout_asBandString(from.getAirScout_asBandString())
|
||||||
|
}
|
||||||
+87
@@ -0,0 +1,87 @@
|
|||||||
|
package kst4contest.view;
|
||||||
|
|
||||||
|
import kst4contest.controller.ActiveOperatorProfile;
|
||||||
|
import kst4contest.model.OperatorProfile;
|
||||||
|
import kst4contest.model.OperatorProfileSelection;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The request to show the setup wizard on the next runtime start is honoured exactly once.
|
||||||
|
* A request that stuck would open the wizard on every later profile switch.
|
||||||
|
*/
|
||||||
|
class ApplicationRuntimeLauncherSetupWizardTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void aRequestIsHonouredOnce() {
|
||||||
|
assertFalse(ApplicationRuntimeLauncher.consumeSetupWizardRequest(), "nothing was requested");
|
||||||
|
|
||||||
|
ApplicationRuntimeLauncher.requestSetupWizard();
|
||||||
|
|
||||||
|
assertTrue(ApplicationRuntimeLauncher.consumeSetupWizardRequest());
|
||||||
|
assertFalse(ApplicationRuntimeLauncher.consumeSetupWizardRequest(), "the request must not stick");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void switchGuardAllowsOnlyOneSwitchAtATime() {
|
||||||
|
try {
|
||||||
|
assertTrue(ApplicationRuntimeLauncher.beginSwitch());
|
||||||
|
assertFalse(ApplicationRuntimeLauncher.beginSwitch(),
|
||||||
|
"a second switch must be refused while one is in progress");
|
||||||
|
} finally {
|
||||||
|
ApplicationRuntimeLauncher.endSwitch();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
assertTrue(ApplicationRuntimeLauncher.beginSwitch(),
|
||||||
|
"ending the first switch must release the guard");
|
||||||
|
} finally {
|
||||||
|
ApplicationRuntimeLauncher.endSwitch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void aRefusedRerunLeavesTheRequestOfTheRunningSwitchAlone() {
|
||||||
|
OperatorProfileSelection previous = ActiveOperatorProfile.get();
|
||||||
|
OperatorProfile profile = new OperatorProfile("wizard-guard-test", "Wizard Guard Test", false, false);
|
||||||
|
ActiveOperatorProfile.set(new OperatorProfileSelection(profile, "preferences.xml", "worked.db", false));
|
||||||
|
|
||||||
|
// A first rerun is under way: it holds the guard and its request waits for startRuntime.
|
||||||
|
assertTrue(ApplicationRuntimeLauncher.beginSwitch());
|
||||||
|
ApplicationRuntimeLauncher.requestSetupWizard();
|
||||||
|
try {
|
||||||
|
// A second one arrives while the first tears its windows down, and is refused.
|
||||||
|
assertFalse(ApplicationRuntimeLauncher.rerunSetupWizard());
|
||||||
|
|
||||||
|
assertTrue(ApplicationRuntimeLauncher.consumeSetupWizardRequest(),
|
||||||
|
"the refused rerun took the running switch's request with it: that switch "
|
||||||
|
+ "would end the session and then start without the wizard");
|
||||||
|
} finally {
|
||||||
|
ApplicationRuntimeLauncher.endSwitch();
|
||||||
|
ApplicationRuntimeLauncher.consumeSetupWizardRequest();
|
||||||
|
ActiveOperatorProfile.set(previous);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void aRefusedRerunLeavesNoRequestOfItsOwn() {
|
||||||
|
OperatorProfileSelection previous = ActiveOperatorProfile.get();
|
||||||
|
OperatorProfile profile = new OperatorProfile("wizard-guard-test", "Wizard Guard Test", false, false);
|
||||||
|
ActiveOperatorProfile.set(new OperatorProfileSelection(profile, "preferences.xml", "worked.db", false));
|
||||||
|
|
||||||
|
// A plain profile switch is under way; nobody asked for the wizard.
|
||||||
|
assertTrue(ApplicationRuntimeLauncher.beginSwitch());
|
||||||
|
try {
|
||||||
|
assertFalse(ApplicationRuntimeLauncher.rerunSetupWizard());
|
||||||
|
|
||||||
|
assertFalse(ApplicationRuntimeLauncher.consumeSetupWizardRequest(),
|
||||||
|
"a refused rerun must not hand its wizard to the switch that refused it");
|
||||||
|
} finally {
|
||||||
|
ApplicationRuntimeLauncher.endSwitch();
|
||||||
|
ApplicationRuntimeLauncher.consumeSetupWizardRequest();
|
||||||
|
ActiveOperatorProfile.set(previous);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,19 @@
|
|||||||
package kst4contest.view;
|
package kst4contest.view;
|
||||||
|
|
||||||
|
import kst4contest.model.ChatCategory;
|
||||||
|
import kst4contest.model.ChatMember;
|
||||||
|
import kst4contest.model.ChatMessage;
|
||||||
import kst4contest.observe.DirectUiDispatcher;
|
import kst4contest.observe.DirectUiDispatcher;
|
||||||
import kst4contest.observe.SimpleRoster;
|
import kst4contest.observe.SimpleRoster;
|
||||||
|
import kst4contest.view.compose.SelectedMessageFilter;
|
||||||
|
import kst4contest.view.compose.SelectedStationMessagePredicate;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
@@ -136,6 +143,39 @@ class RosterListBindingTest {
|
|||||||
"a newly set filter must be visible without waiting for the next roster change");
|
"a newly set filter must be visible without waiting for the next roster change");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void selectedStationMessagesFollowNewMessagesAndSelectionChanges() {
|
||||||
|
ChatMember first = member("DL1FIRST", 2);
|
||||||
|
ChatMember second = member("DL2SECOND", 2);
|
||||||
|
SimpleRoster<ChatMessage> messages = new SimpleRoster<>();
|
||||||
|
AtomicReference<Predicate<ChatMessage>> filter = new AtomicReference<>(
|
||||||
|
SelectedStationMessagePredicate.forSelection(
|
||||||
|
SelectedMessageFilter.PUBLIC, first, "DL0OWN"));
|
||||||
|
|
||||||
|
RosterListBinding<ChatMessage> binding = RosterListBinding.derived(
|
||||||
|
new DirectUiDispatcher(),
|
||||||
|
() -> messages.snapshot().stream().filter(filter.get()).toList(),
|
||||||
|
messages);
|
||||||
|
|
||||||
|
ChatMessage unrelated = publicMessage(second);
|
||||||
|
messages.add(unrelated);
|
||||||
|
assertTrue(binding.list().isEmpty());
|
||||||
|
|
||||||
|
ChatMessage matching = publicMessage(first);
|
||||||
|
messages.add(matching);
|
||||||
|
assertEquals(List.of(matching), List.copyOf(binding.list()));
|
||||||
|
|
||||||
|
filter.set(SelectedStationMessagePredicate.forSelection(
|
||||||
|
SelectedMessageFilter.PUBLIC, second, "DL0OWN"));
|
||||||
|
binding.refresh();
|
||||||
|
assertEquals(List.of(unrelated), List.copyOf(binding.list()),
|
||||||
|
"the former station's messages must disappear immediately");
|
||||||
|
|
||||||
|
ChatMessage next = publicMessage(second);
|
||||||
|
messages.add(next);
|
||||||
|
assertEquals(List.of(unrelated, next), List.copyOf(binding.list()));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void aDisposedDerivedBindingDetachesFromEverySource() {
|
void aDisposedDerivedBindingDetachesFromEverySource() {
|
||||||
SimpleRoster<String> members = new SimpleRoster<>();
|
SimpleRoster<String> members = new SimpleRoster<>();
|
||||||
@@ -150,4 +190,20 @@ class RosterListBindingTest {
|
|||||||
|
|
||||||
assertTrue(binding.list().isEmpty());
|
assertTrue(binding.list().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ChatMember member(String callSign, int category) {
|
||||||
|
ChatMember member = new ChatMember();
|
||||||
|
member.setCallSign(callSign);
|
||||||
|
member.setChatCategory(new ChatCategory(category));
|
||||||
|
return member;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ChatMessage publicMessage(ChatMember sender) {
|
||||||
|
ChatMessage message = new ChatMessage();
|
||||||
|
message.setSender(sender);
|
||||||
|
message.setReceiver(member("ALL", sender.getChatCategory().getCategoryNumber()));
|
||||||
|
message.setChatCategory(sender.getChatCategory());
|
||||||
|
message.setMessageText("test");
|
||||||
|
return message;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,180 @@
|
|||||||
|
package kst4contest.view;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.doAnswer;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.Timeout;
|
||||||
|
|
||||||
|
import kst4contest.ApplicationConstants;
|
||||||
|
import kst4contest.controller.ChatController;
|
||||||
|
import kst4contest.controller.MessageBusManagementThread;
|
||||||
|
import kst4contest.controller.ScoreService;
|
||||||
|
import kst4contest.controller.StationMetricsService;
|
||||||
|
import kst4contest.controller.ThreadStatusCallback;
|
||||||
|
import kst4contest.model.AirPlaneReflectionInfo;
|
||||||
|
import kst4contest.model.ChatCategory;
|
||||||
|
import kst4contest.model.ChatMember;
|
||||||
|
import kst4contest.model.ChatMessage;
|
||||||
|
import kst4contest.model.ChatPreferences;
|
||||||
|
import kst4contest.observe.DirectUiDispatcher;
|
||||||
|
import kst4contest.observe.SimpleRoster;
|
||||||
|
import kst4contest.observe.SimpleValue;
|
||||||
|
import kst4contest.view.compose.DataTableState;
|
||||||
|
import kst4contest.view.compose.RowKeys;
|
||||||
|
import kst4contest.view.compose.SelectedMessageFilter;
|
||||||
|
import kst4contest.view.compose.SelectedStationMessagePredicate;
|
||||||
|
import kst4contest.view.feed.SelectedStationMessagesFeed;
|
||||||
|
|
||||||
|
/** Exercises protocol parsing, selected-station filtering and the displayed table together. */
|
||||||
|
class SelectedStationMessageFlowTest {
|
||||||
|
|
||||||
|
private static final String OWN_CALL = "DL0OWN";
|
||||||
|
private static final String SELECTED_CALL = "DM5M";
|
||||||
|
|
||||||
|
private final LinkedBlockingQueue<ChatMessage> receiveQueue = new LinkedBlockingQueue<>();
|
||||||
|
private final SimpleRoster<ChatMessage> messages = new SimpleRoster<>();
|
||||||
|
private final AtomicReference<Predicate<ChatMessage>> filter = new AtomicReference<>();
|
||||||
|
|
||||||
|
private ChatController controller;
|
||||||
|
private ChatPreferences preferences;
|
||||||
|
private ChatMember selected;
|
||||||
|
private RosterListBinding<ChatMessage> binding;
|
||||||
|
private DataTableState<ChatMessage> displayed;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
preferences = mock(ChatPreferences.class);
|
||||||
|
when(preferences.getStn_loginCallSign()).thenReturn(OWN_CALL);
|
||||||
|
when(preferences.getStn_loginLocatorMainCat()).thenReturn("JO50LL");
|
||||||
|
when(preferences.getMYQRGFirstCat()).thenReturn(new SimpleValue<>("144.300"));
|
||||||
|
when(preferences.getMYQRGSecondCat()).thenReturn(new SimpleValue<>("1296.200"));
|
||||||
|
|
||||||
|
controller = mock(ChatController.class);
|
||||||
|
when(controller.getChatPreferences()).thenReturn(preferences);
|
||||||
|
when(controller.getChatCategoryMain()).thenReturn(new ChatCategory(ChatCategory.VUHF));
|
||||||
|
when(controller.getChatCategorySecondChat()).thenReturn(new ChatCategory(ChatCategory.MICROWAVE));
|
||||||
|
when(controller.getStationMetricsService()).thenReturn(mock(StationMetricsService.class));
|
||||||
|
when(controller.getScoreService()).thenReturn(mock(ScoreService.class));
|
||||||
|
when(controller.findActiveChatMember(any(ChatMember.class)))
|
||||||
|
.thenAnswer(invocation -> activeMember(invocation.getArgument(0)));
|
||||||
|
doAnswer(invocation -> {
|
||||||
|
messages.add(invocation.getArgument(0));
|
||||||
|
return null;
|
||||||
|
}).when(controller).publishChatMessage(any(ChatMessage.class));
|
||||||
|
|
||||||
|
selected = member(SELECTED_CALL, ChatCategory.VUHF);
|
||||||
|
filter.set(SelectedStationMessagePredicate.forSelection(
|
||||||
|
SelectedMessageFilter.PM_TO_ME, selected, OWN_CALL));
|
||||||
|
|
||||||
|
displayed = new DataTableState<>(List.of(), RowKeys.INSTANCE.byReference(), "selected-flow-test");
|
||||||
|
SelectedStationMessagesFeed feed =
|
||||||
|
new SelectedStationMessagesFeed(displayed, new DirectUiDispatcher());
|
||||||
|
binding = RosterListBinding.derived(
|
||||||
|
new DirectUiDispatcher(),
|
||||||
|
() -> messages.snapshot().stream().filter(filter.get()).toList(),
|
||||||
|
messages);
|
||||||
|
binding.onChanged(feed::push);
|
||||||
|
feed.push(binding.list());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Timeout(10)
|
||||||
|
void realisticFramesReachTheDisplayedRowsUnderAllFourModes() throws InterruptedException {
|
||||||
|
runThrough(
|
||||||
|
chatFrame(2, SELECTED_CALL, "private", OWN_CALL),
|
||||||
|
chatFrame(2, SELECTED_CALL, "(" + OWN_CALL + ") public reply", "0"),
|
||||||
|
chatFrame(2, SELECTED_CALL, "general public message", "0"),
|
||||||
|
chatFrame(2, SELECTED_CALL, "private to another station", "DL2OTHER"),
|
||||||
|
chatFrame(2, "DL2OTHER", "other station", "0"),
|
||||||
|
chatFrame(3, SELECTED_CALL, "same call, other category", "0"));
|
||||||
|
|
||||||
|
assertEquals(2, displayed.getRows().size(),
|
||||||
|
"pm to me must contain the genuine PM and the explicitly addressed public line");
|
||||||
|
|
||||||
|
selectMode(SelectedMessageFilter.PUBLIC);
|
||||||
|
assertEquals(2, displayed.getRows().size(),
|
||||||
|
"the two public lines overlap with the addressed-public PM view");
|
||||||
|
|
||||||
|
selectMode(SelectedMessageFilter.PM_TO_OTHER);
|
||||||
|
assertEquals(1, displayed.getRows().size(),
|
||||||
|
"pm to other keeps private traffic sent by the selected station to another station");
|
||||||
|
|
||||||
|
selectMode(SelectedMessageFilter.NOTHING);
|
||||||
|
assertEquals(4, displayed.getRows().size(),
|
||||||
|
"nothing removes only the type/receiver restriction");
|
||||||
|
|
||||||
|
selectStation(member("DL2OTHER", ChatCategory.VUHF));
|
||||||
|
assertEquals(2, displayed.getRows().size(),
|
||||||
|
"changing the selected station must replace the displayed station scope immediately");
|
||||||
|
selectStation(member(SELECTED_CALL, ChatCategory.VUHF));
|
||||||
|
|
||||||
|
runThrough(chatFrame(2, SELECTED_CALL, "new while the panel is open", OWN_CALL));
|
||||||
|
assertEquals(5, displayed.getRows().size(),
|
||||||
|
"a new matching line must reach the already open table");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectMode(SelectedMessageFilter mode) {
|
||||||
|
filter.set(SelectedStationMessagePredicate.forSelection(mode, selected, OWN_CALL));
|
||||||
|
binding.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectStation(ChatMember station) {
|
||||||
|
selected = station;
|
||||||
|
selectMode(SelectedMessageFilter.NOTHING);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runThrough(ChatMessage... frames) throws InterruptedException {
|
||||||
|
MessageBusManagementThread thread = new MessageBusManagementThread(
|
||||||
|
controller,
|
||||||
|
mock(ThreadStatusCallback.class),
|
||||||
|
11L,
|
||||||
|
receiveQueue,
|
||||||
|
ignored -> true);
|
||||||
|
for (ChatMessage frame : frames) {
|
||||||
|
receiveQueue.add(frame);
|
||||||
|
}
|
||||||
|
receiveQueue.add(poisonPill());
|
||||||
|
thread.start();
|
||||||
|
thread.join();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ChatMessage chatFrame(int category, String sender, String text, String receiver) {
|
||||||
|
return wireMessage("CH|" + category + "|1700000000|" + sender
|
||||||
|
+ "|Operator|0|" + text + "|" + receiver + "|");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ChatMessage poisonPill() {
|
||||||
|
ChatMessage message = wireMessage(ApplicationConstants.DISCONNECT_RDR_POISONPILL);
|
||||||
|
message.setMessageSenderName(ApplicationConstants.DISCONNECT_RDR_POISONPILL);
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ChatMessage wireMessage(String text) {
|
||||||
|
ChatMessage message = new ChatMessage();
|
||||||
|
message.setMessageText(text);
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ChatMember activeMember(ChatMember lookup) {
|
||||||
|
return member(lookup.getCallSign(), lookup.getChatCategory().getCategoryNumber());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ChatMember member(String callSign, int category) {
|
||||||
|
ChatMember member = new ChatMember();
|
||||||
|
member.setCallSign(callSign);
|
||||||
|
member.setChatCategory(new ChatCategory(category));
|
||||||
|
member.setQra("JO31AA");
|
||||||
|
member.setAirPlaneReflectInfo(new AirPlaneReflectionInfo());
|
||||||
|
return member;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package kst4contest.view
|
||||||
|
|
||||||
|
import kst4contest.controller.ChatController
|
||||||
|
import kst4contest.model.ChatMessage
|
||||||
|
import kst4contest.view.compose.DataTableState
|
||||||
|
import kst4contest.view.compose.RowKeys
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.mockito.Mockito.mock
|
||||||
|
import org.mockito.Mockito.`when`
|
||||||
|
|
||||||
|
class ComposeMessageTableRefreshTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `refresh keeps public table on the filtered controller view`() {
|
||||||
|
val controller = mock(ChatController::class.java)
|
||||||
|
val privateToMe = message("private to me")
|
||||||
|
val publicInitial = message("public initial")
|
||||||
|
val betweenOthers = message("between others")
|
||||||
|
val directed = table()
|
||||||
|
val publicMessages = table()
|
||||||
|
val qsoOfTheOther = table()
|
||||||
|
|
||||||
|
`when`(controller.toMeMessages()).thenReturn(listOf(privateToMe))
|
||||||
|
`when`(controller.toAllMessages()).thenReturn(listOf(publicInitial))
|
||||||
|
`when`(controller.toOtherMessages()).thenReturn(listOf(betweenOthers))
|
||||||
|
|
||||||
|
Kst4ContestApplication.refreshComposeMessageTables(
|
||||||
|
controller,
|
||||||
|
directed,
|
||||||
|
publicMessages,
|
||||||
|
qsoOfTheOther,
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(listOf(privateToMe), directed.rows)
|
||||||
|
assertEquals(listOf(publicInitial), publicMessages.rows)
|
||||||
|
assertEquals(listOf(betweenOthers), qsoOfTheOther.rows)
|
||||||
|
|
||||||
|
val publicLater = message("public later")
|
||||||
|
`when`(controller.toAllMessages()).thenReturn(listOf(publicLater, publicInitial))
|
||||||
|
|
||||||
|
Kst4ContestApplication.refreshComposeMessageTables(
|
||||||
|
controller,
|
||||||
|
directed,
|
||||||
|
publicMessages,
|
||||||
|
qsoOfTheOther,
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(listOf(publicLater, publicInitial), publicMessages.rows)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun table() = DataTableState(
|
||||||
|
columns = emptyList(),
|
||||||
|
rowKey = RowKeys.byReference<ChatMessage>(),
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun message(text: String) = ChatMessage().apply {
|
||||||
|
messageText = text
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.Assertions.assertFalse
|
||||||
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class BeaconStatusColorsTest {
|
||||||
|
private val neutral = Color(0xFF123456)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `active and activity colours are the approved traffic colours`() {
|
||||||
|
assertEquals(
|
||||||
|
ThreadButtonColors(Color(0xFF238636), Color(0xFF56D364), Color.White),
|
||||||
|
beaconThreadButtonColors(ThreadStatusVisualStyle.BEACON_ACTIVE, false, false, neutral),
|
||||||
|
)
|
||||||
|
assertEquals(
|
||||||
|
ThreadButtonColors(Color(0xFFFFB300), Color(0xFFFFE082), Color(0xFF1B1B1B)),
|
||||||
|
beaconThreadButtonColors(ThreadStatusVisualStyle.BEACON_ACTIVE, true, false, neutral),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `off uses neutral background and theme specific red text`() {
|
||||||
|
assertEquals(Color(0xFFD50000),
|
||||||
|
beaconThreadButtonColors(ThreadStatusVisualStyle.BEACON_OFF, false, false, neutral).text)
|
||||||
|
assertEquals(Color(0xFFFF6B6B),
|
||||||
|
beaconThreadButtonColors(ThreadStatusVisualStyle.BEACON_OFF, false, true, neutral).text)
|
||||||
|
assertEquals(neutral,
|
||||||
|
beaconThreadButtonColors(ThreadStatusVisualStyle.BEACON_OFF, false, true, neutral).background)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `failed stays red even when a highlight is requested`() {
|
||||||
|
val colors = beaconThreadButtonColors(
|
||||||
|
ThreadStatusVisualStyle.BEACON_FAILED,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
neutral,
|
||||||
|
)
|
||||||
|
assertEquals(ThreadButtonColors(Color(0xFFD50000), Color(0xFFFF6B6B), Color.White), colors)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `failed suppresses the flash while active status allows it`() {
|
||||||
|
val button = ThreadStatusButton("MyBeacon")
|
||||||
|
button.report("MyBeacon: on", "active", ThreadStatusVisualStyle.BEACON_ACTIVE)
|
||||||
|
assertTrue(button.highlighted)
|
||||||
|
|
||||||
|
button.report("MyBeacon: FAILED", "failed", ThreadStatusVisualStyle.BEACON_FAILED)
|
||||||
|
assertFalse(button.highlighted)
|
||||||
|
assertEquals(
|
||||||
|
ThreadButtonColors(Color(0xFFD50000), Color(0xFFFF6B6B), Color.White),
|
||||||
|
beaconThreadButtonColors(ThreadStatusVisualStyle.BEACON_FAILED, true, false, neutral),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import kst4contest.model.BeaconStatusSnapshot
|
||||||
|
import kst4contest.model.BeaconStatusSnapshot.AggregateState
|
||||||
|
import kst4contest.model.BeaconStatusSnapshot.CategoryStatus
|
||||||
|
import kst4contest.model.BeaconStatusSnapshot.InactiveReason
|
||||||
|
import kst4contest.view.i18n.LanguageStore
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.Assertions.assertFalse
|
||||||
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
|
class BeaconStatusPresentationTest {
|
||||||
|
@Test
|
||||||
|
fun `partial status keeps the inactive category reason in English`() {
|
||||||
|
val presentation = BeaconStatusPresentation.from(snapshot(AggregateState.PARTIAL))
|
||||||
|
|
||||||
|
assertEquals("1/2", presentation.label)
|
||||||
|
assertTrue(presentation.tooltip.contains("Main category: active"))
|
||||||
|
assertTrue(presentation.tooltip.contains("primary QRG missing or invalid"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `the same category reasons are available in German`() {
|
||||||
|
val language = LanguageStore({ "de" }, {}, Locale.UK)
|
||||||
|
try {
|
||||||
|
val presentation = BeaconStatusPresentation.from(
|
||||||
|
snapshot(AggregateState.PARTIAL),
|
||||||
|
language.strings,
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(presentation.tooltip.contains("Hauptkategorie: aktiv"))
|
||||||
|
assertTrue(presentation.tooltip.contains("Haupt-QRG fehlt oder ist ungültig"))
|
||||||
|
assertFalse(presentation.tooltip.contains("144."))
|
||||||
|
} finally {
|
||||||
|
language.use("en")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `failed style overrides an active category`() {
|
||||||
|
val main = CategoryStatus(true, true, true, InactiveReason.USER_DISABLED)
|
||||||
|
val second = CategoryStatus(false, false, false, InactiveReason.NOT_ACTIVATED_THIS_SESSION)
|
||||||
|
val presentation = BeaconStatusPresentation.from(
|
||||||
|
BeaconStatusSnapshot(AggregateState.FAILED, main, second),
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals("FAILED", presentation.label)
|
||||||
|
assertEquals(ThreadStatusVisualStyle.BEACON_FAILED, presentation.style)
|
||||||
|
assertTrue(presentation.tooltip.contains("send failed"))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun snapshot(state: AggregateState): BeaconStatusSnapshot = BeaconStatusSnapshot(
|
||||||
|
state,
|
||||||
|
CategoryStatus(true, true, false, InactiveReason.USER_DISABLED),
|
||||||
|
CategoryStatus(true, false, false, InactiveReason.PRIMARY_QRG_UNAVAILABLE),
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -3,19 +3,23 @@ package kst4contest.view.compose
|
|||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.text.input.TextFieldValue
|
||||||
import androidx.compose.ui.test.ExperimentalTestApi
|
import androidx.compose.ui.test.ExperimentalTestApi
|
||||||
import androidx.compose.ui.test.assertCountEquals
|
import androidx.compose.ui.test.assertCountEquals
|
||||||
import androidx.compose.ui.test.assertIsNotEnabled
|
import androidx.compose.ui.test.assertIsNotEnabled
|
||||||
import androidx.compose.ui.test.onAllNodesWithText
|
import androidx.compose.ui.test.onAllNodesWithText
|
||||||
import androidx.compose.ui.test.onNodeWithText
|
import androidx.compose.ui.test.onNodeWithText
|
||||||
import androidx.compose.ui.test.runComposeUiTest
|
import androidx.compose.ui.test.runComposeUiTest
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import kst4contest.model.ChatCategory
|
import kst4contest.model.ChatCategory
|
||||||
import kst4contest.model.ChatMember
|
import kst4contest.model.ChatMember
|
||||||
import kst4contest.model.ChatMessage
|
import kst4contest.model.ChatMessage
|
||||||
import kst4contest.model.ChatPreferences
|
import kst4contest.model.ChatPreferences
|
||||||
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.io.TempDir
|
import org.junit.jupiter.api.io.TempDir
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
import kotlin.math.abs
|
||||||
|
|
||||||
/** The send line with SO2R: the display-only QTF2 field appears only while SO2R is on. */
|
/** The send line with SO2R: the display-only QTF2 field appears only while SO2R is on. */
|
||||||
@OptIn(ExperimentalTestApi::class)
|
@OptIn(ExperimentalTestApi::class)
|
||||||
@@ -66,4 +70,53 @@ class ChatInputRowSo2rScreenTest {
|
|||||||
onNodeWithText("270.0").assertExists()
|
onNodeWithText("270.0").assertExists()
|
||||||
onNodeWithText("270.0").assertIsNotEnabled()
|
onNodeWithText("270.0").assertIsNotEnabled()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `send buttons message and station fields share height and preserve realistic values`() = runComposeUiTest {
|
||||||
|
val prefs = prefs().apply {
|
||||||
|
getMYQRGFirstCat().set("1296.123.000")
|
||||||
|
getMYQRGSecondCat().set("144.310.000")
|
||||||
|
getActualQTF().set(360.0)
|
||||||
|
}
|
||||||
|
val state = chatInputStateFor(prefs).apply {
|
||||||
|
value = TextFieldValue("/cq OK1IN test test test aasdasd ggggg asd asd gggg")
|
||||||
|
}
|
||||||
|
setContent {
|
||||||
|
Kst4ContestTheme(darkMode = false, baseFontSizeSp = 12f) {
|
||||||
|
ChatInputRow(
|
||||||
|
state = state,
|
||||||
|
prefs = prefs,
|
||||||
|
ownQrgMain = ObservedValue(prefs.getMYQRGFirstCat()),
|
||||||
|
ownQrgSecond = ObservedValue(prefs.getMYQRGSecondCat()),
|
||||||
|
antennaQtf = ObservedValue(prefs.getActualQTF()),
|
||||||
|
antennaQtf2 = ObservedValue(prefs.getActualQTF2()),
|
||||||
|
so2rEnabled = false,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val values = listOf("1296.123.000", "144.310.000", "360.0")
|
||||||
|
val heights = listOf("TX", "clear")
|
||||||
|
.map { onNodeWithText(it).fetchSemanticsNode().boundsInRoot.height } +
|
||||||
|
values.map { onNodeWithText(it).fetchSemanticsNode().boundsInRoot.height }
|
||||||
|
assertTrue(
|
||||||
|
heights.max() - heights.min() <= 1f,
|
||||||
|
"send-row control heights differ: $heights",
|
||||||
|
)
|
||||||
|
|
||||||
|
val minimumQrgWidth = with(density) { 96.dp.toPx() }
|
||||||
|
values.take(2).forEach { value ->
|
||||||
|
val width = onNodeWithText(value).fetchSemanticsNode().boundsInRoot.width
|
||||||
|
assertTrue(width >= minimumQrgWidth - 1f, "$value has only $width px")
|
||||||
|
}
|
||||||
|
val qtfWidth = onNodeWithText("360.0").fetchSemanticsNode().boundsInRoot.width
|
||||||
|
assertTrue(
|
||||||
|
abs(qtfWidth - with(density) { 56.dp.toPx() }) <= 1f,
|
||||||
|
"360.0 field is $qtfWidth px wide",
|
||||||
|
)
|
||||||
|
assertTrue(
|
||||||
|
abs(onNodeWithText("TX").fetchSemanticsNode().boundsInRoot.height -
|
||||||
|
with(density) { 26.dp.toPx() }) <= 1f,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ import androidx.compose.ui.text.input.TextFieldValue
|
|||||||
import kst4contest.model.ChatCategory
|
import kst4contest.model.ChatCategory
|
||||||
import kst4contest.model.ChatMember
|
import kst4contest.model.ChatMember
|
||||||
import kst4contest.model.ChatMessage
|
import kst4contest.model.ChatMessage
|
||||||
|
import kst4contest.controller.RadioSlot
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
import org.junit.jupiter.api.Assertions.assertNull
|
import org.junit.jupiter.api.Assertions.assertNull
|
||||||
import org.junit.jupiter.api.Assertions.assertSame
|
import org.junit.jupiter.api.Assertions.assertSame
|
||||||
@@ -233,6 +234,20 @@ class ChatInputStateTest {
|
|||||||
assertEquals("432.200 ", state.value.text)
|
assertEquals("432.200 ", state.value.text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `manual QRG commits keep their radio source explicit`() {
|
||||||
|
val actions = FakeActions()
|
||||||
|
val state = ChatInputState(actions)
|
||||||
|
|
||||||
|
state.commitOwnQrg(mainCategory = true, "144.300")
|
||||||
|
state.commitOwnQrg(mainCategory = false, "1296.100")
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
listOf(RadioSlot.FIRST to "144.300", RadioSlot.SECOND to "1296.100"),
|
||||||
|
actions.manualQrgs,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// ---- the snippets ------------------------------------------------------
|
// ---- the snippets ------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -407,6 +422,7 @@ class ChatInputStateTest {
|
|||||||
val resolvedTemplates = mutableListOf<String>()
|
val resolvedTemplates = mutableListOf<String>()
|
||||||
val recordedCqs = mutableListOf<String>()
|
val recordedCqs = mutableListOf<String>()
|
||||||
val recomputeReasons = mutableListOf<String>()
|
val recomputeReasons = mutableListOf<String>()
|
||||||
|
val manualQrgs = mutableListOf<Pair<RadioSlot, String>>()
|
||||||
|
|
||||||
override fun panelSelection(): ChatMember? = panelSelection
|
override fun panelSelection(): ChatMember? = panelSelection
|
||||||
override fun tableSelection(): ChatMember? = tableSelection
|
override fun tableSelection(): ChatMember? = tableSelection
|
||||||
@@ -431,5 +447,6 @@ class ChatInputStateTest {
|
|||||||
override fun queue(message: ChatMessage) { queued += message }
|
override fun queue(message: ChatMessage) { queued += message }
|
||||||
override fun ownQrgMain(): String = ownQrgMain
|
override fun ownQrgMain(): String = ownQrgMain
|
||||||
override fun ownQrgSecond(): String = ownQrgSecond
|
override fun ownQrgSecond(): String = ownQrgSecond
|
||||||
|
override fun applyManualQrg(slot: RadioSlot, value: String) { manualQrgs += slot to value }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
|
import androidx.compose.ui.test.ExperimentalTestApi
|
||||||
|
import androidx.compose.ui.test.onNodeWithText
|
||||||
|
import androidx.compose.ui.test.performClick
|
||||||
|
import androidx.compose.ui.test.runComposeUiTest
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import kotlin.math.abs
|
||||||
|
|
||||||
|
/** Shared fields and choices use the same compact desktop height. */
|
||||||
|
@OptIn(ExperimentalTestApi::class)
|
||||||
|
class CompactControlsScreenTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun fieldsChoicesAndButtonsShareTheDesktopControlHeight() = runComposeUiTest {
|
||||||
|
setContent {
|
||||||
|
Kst4ContestTheme(darkMode = false, baseFontSizeSp = 12f) {
|
||||||
|
Column {
|
||||||
|
CompactTextField(value = "144.310.000", onValueChange = {})
|
||||||
|
Form.inlineChoice(
|
||||||
|
label = "Reachability",
|
||||||
|
items = listOf("Auto"),
|
||||||
|
selected = "Auto",
|
||||||
|
describe = { it },
|
||||||
|
onSelect = {},
|
||||||
|
)
|
||||||
|
Form.button(text = "TX", onClick = {})
|
||||||
|
Form.button(text = "Filter", onClick = {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val heights = listOf("144.310.000", "Auto", "TX", "Filter")
|
||||||
|
.map { onNodeWithText(it).fetchSemanticsNode().boundsInRoot.height }
|
||||||
|
val targetHeight = with(density) { 26.dp.toPx() }
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
heights.all { abs(it - targetHeight) <= 1f },
|
||||||
|
"controls are $heights px tall instead of $targetHeight px",
|
||||||
|
)
|
||||||
|
assertTrue(
|
||||||
|
heights.max() - heights.min() <= 1f,
|
||||||
|
"control heights differ by more than one pixel: $heights",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun accentAndToggleButtonsShareEnabledAndDisabledClickBehaviour() = runComposeUiTest {
|
||||||
|
var accentClicks = 0
|
||||||
|
var disabledClicks = 0
|
||||||
|
setContent {
|
||||||
|
Kst4ContestTheme(darkMode = true, baseFontSizeSp = 12f) {
|
||||||
|
Column {
|
||||||
|
Form.button(
|
||||||
|
text = "Accent",
|
||||||
|
accented = true,
|
||||||
|
onClick = { accentClicks++ },
|
||||||
|
)
|
||||||
|
Form.button(
|
||||||
|
text = "Selected",
|
||||||
|
selected = true,
|
||||||
|
onClick = {},
|
||||||
|
)
|
||||||
|
Form.button(
|
||||||
|
text = "Disabled accent",
|
||||||
|
enabled = false,
|
||||||
|
accented = true,
|
||||||
|
onClick = { disabledClicks++ },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onNodeWithText("Accent").performClick()
|
||||||
|
onNodeWithText("Disabled accent").performClick()
|
||||||
|
|
||||||
|
assertEquals(1, accentClicks)
|
||||||
|
assertEquals(0, disabledClicks)
|
||||||
|
assertTrue(onNodeWithText("Selected").fetchSemanticsNode().boundsInRoot.height < 40f)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun controlsStayAlignedAt125PercentDensityInEveningDesign() = runComposeUiTest {
|
||||||
|
setContent {
|
||||||
|
CompositionLocalProvider(
|
||||||
|
LocalDensity provides androidx.compose.ui.unit.Density(1.25f),
|
||||||
|
) {
|
||||||
|
Kst4ContestTheme(darkMode = true, baseFontSizeSp = 12f) {
|
||||||
|
Column {
|
||||||
|
CompactTextField(value = "10368.000", onValueChange = {})
|
||||||
|
Form.inlineChoice(
|
||||||
|
label = "Reachability",
|
||||||
|
items = listOf("Auto"),
|
||||||
|
selected = "Auto",
|
||||||
|
describe = { it },
|
||||||
|
onSelect = {},
|
||||||
|
)
|
||||||
|
Form.button(text = "TX", onClick = {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val heights = listOf("10368.000", "Auto", "TX")
|
||||||
|
.map { onNodeWithText(it).fetchSemanticsNode().boundsInRoot.height }
|
||||||
|
val expected = 26f * 1.25f
|
||||||
|
assertTrue(
|
||||||
|
heights.all { abs(it - expected) <= 1f },
|
||||||
|
"125% controls are $heights px tall instead of about $expected px",
|
||||||
|
)
|
||||||
|
assertTrue(
|
||||||
|
heights.max() - heights.min() <= 1f,
|
||||||
|
"125% control heights differ by more than one pixel: $heights",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun controlsGrowTogetherInsteadOfClippingALargerConfiguredFont() = runComposeUiTest {
|
||||||
|
setContent {
|
||||||
|
Kst4ContestTheme(darkMode = false, baseFontSizeSp = 24f) {
|
||||||
|
Column {
|
||||||
|
CompactTextField(value = "1296.123.000", onValueChange = {})
|
||||||
|
Form.inlineChoice(
|
||||||
|
label = "Reachability",
|
||||||
|
items = listOf("Auto"),
|
||||||
|
selected = "Auto",
|
||||||
|
describe = { it },
|
||||||
|
onSelect = {},
|
||||||
|
)
|
||||||
|
Form.button(text = "TX", onClick = {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val heights = listOf("1296.123.000", "Auto", "TX")
|
||||||
|
.map { onNodeWithText(it).fetchSemanticsNode().boundsInRoot.height }
|
||||||
|
assertTrue(heights.min() > with(density) { 26.dp.toPx() })
|
||||||
|
assertTrue(
|
||||||
|
heights.max() - heights.min() <= 1f,
|
||||||
|
"large-font controls do not grow together: $heights",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
+116
@@ -0,0 +1,116 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.ui.ImageComposeScene
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.text.input.TextFieldValue
|
||||||
|
import androidx.compose.ui.unit.Density
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import kst4contest.model.Band
|
||||||
|
import kst4contest.model.ChatCategory
|
||||||
|
import kst4contest.model.ChatMember
|
||||||
|
import kst4contest.model.ChatMessage
|
||||||
|
import kst4contest.model.ChatPreferences
|
||||||
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.api.io.TempDir
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.nio.file.Path
|
||||||
|
import java.util.EnumSet
|
||||||
|
|
||||||
|
/** Renders the compact control strips for visual inspection in both supported palettes. */
|
||||||
|
class CompactControlsVisualRenderingTest(@param:TempDir private val tempDir: Path) {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun rendersDayAndEveningControlsAt100And125Percent() {
|
||||||
|
val reportDirectory = Path.of("build", "reports", "compact-controls")
|
||||||
|
Files.createDirectories(reportDirectory)
|
||||||
|
|
||||||
|
listOf(false, true).forEach { darkMode ->
|
||||||
|
listOf(1f, 1.25f).forEach { scale ->
|
||||||
|
val bytes = render(darkMode, scale)
|
||||||
|
val palette = if (darkMode) "evening" else "day"
|
||||||
|
val scaling = if (scale == 1f) "100" else "125"
|
||||||
|
Files.write(reportDirectory.resolve("$palette-$scaling.png"), bytes)
|
||||||
|
assertTrue(bytes.size > 10_000, "$palette at $scaling% did not render")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun render(darkMode: Boolean, scale: Float): ByteArray {
|
||||||
|
val preferences = ChatPreferences(tempDir.resolve("preferences-$darkMode-$scale.xml")).apply {
|
||||||
|
getMYQRGFirstCat().set("1296.123.000")
|
||||||
|
getMYQRGSecondCat().set("144.310.000")
|
||||||
|
getActualQTF().set(360.0)
|
||||||
|
}
|
||||||
|
val chatInputState = ChatInputState(RenderActions(preferences)).apply {
|
||||||
|
value = TextFieldValue("/cq OK1IN test test test aasdasd ggggg asd asd gggg")
|
||||||
|
}
|
||||||
|
val filters = StationFilterState()
|
||||||
|
|
||||||
|
return onEventThread {
|
||||||
|
val scene = ImageComposeScene(width = 1366, height = 380, density = Density(scale)) {
|
||||||
|
Kst4ContestTheme(darkMode = darkMode, baseFontSizeSp = 12f) {
|
||||||
|
Surface(
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
color = MaterialTheme.colorScheme.background,
|
||||||
|
) {
|
||||||
|
Column(Modifier.padding(4.dp)) {
|
||||||
|
TimelineView(
|
||||||
|
state = TimelineState(),
|
||||||
|
onCandidateClicked = {},
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
)
|
||||||
|
Spacer(Modifier.height(8.dp))
|
||||||
|
StationFilterBar(
|
||||||
|
filters = filters,
|
||||||
|
activeBands = EnumSet.of(Band.B_144, Band.B_432, Band.B_1296),
|
||||||
|
reachability = ReachabilityState(
|
||||||
|
EnumSet.of(Band.B_144, Band.B_432, Band.B_1296),
|
||||||
|
),
|
||||||
|
onChanged = {},
|
||||||
|
)
|
||||||
|
Spacer(Modifier.height(12.dp))
|
||||||
|
ChatInputRow(
|
||||||
|
state = chatInputState,
|
||||||
|
prefs = preferences,
|
||||||
|
ownQrgMain = ObservedValue(preferences.getMYQRGFirstCat()),
|
||||||
|
ownQrgSecond = ObservedValue(preferences.getMYQRGSecondCat()),
|
||||||
|
antennaQtf = ObservedValue(preferences.getActualQTF()),
|
||||||
|
antennaQtf2 = ObservedValue(preferences.getActualQTF2()),
|
||||||
|
so2rEnabled = false,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
scene.render().encodeToData()!!.bytes
|
||||||
|
} finally {
|
||||||
|
scene.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class RenderActions(private val preferences: ChatPreferences) : ChatInputActions {
|
||||||
|
override fun panelSelection(): ChatMember? = null
|
||||||
|
override fun tableSelection(): ChatMember? = null
|
||||||
|
override fun scoreSelection(): ChatMember? = null
|
||||||
|
override fun resolveVariables(template: String, member: ChatMember?): String = template
|
||||||
|
override fun isAddressedToOwnCallsign(text: String): Boolean = false
|
||||||
|
override fun resolveCategory(text: String, member: ChatMember?): ChatCategory? = null
|
||||||
|
override fun mainCategory(): ChatCategory? = null
|
||||||
|
override fun recordOutboundCq(text: String) = Unit
|
||||||
|
override fun requestRecompute(reason: String) = Unit
|
||||||
|
override fun queue(message: ChatMessage) = Unit
|
||||||
|
override fun ownQrgMain(): String = preferences.getMYQRGFirstCat().get().orEmpty()
|
||||||
|
override fun ownQrgSecond(): String = preferences.getMYQRGSecondCat().get().orEmpty()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.test.ExperimentalTestApi
|
||||||
|
import androidx.compose.ui.test.assertIsEnabled
|
||||||
|
import androidx.compose.ui.test.assertIsNotEnabled
|
||||||
|
import androidx.compose.ui.test.onNodeWithText
|
||||||
|
import androidx.compose.ui.test.performClick
|
||||||
|
import androidx.compose.ui.test.runComposeUiTest
|
||||||
|
import kst4contest.controller.On4KstConnectionState
|
||||||
|
import kst4contest.model.ChatPreferences
|
||||||
|
import kst4contest.view.compose.tabs.showTab
|
||||||
|
import org.junit.jupiter.api.Assertions.assertFalse
|
||||||
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.api.io.TempDir
|
||||||
|
import java.nio.file.Path
|
||||||
|
|
||||||
|
@OptIn(ExperimentalTestApi::class)
|
||||||
|
class ConnectionBarScreenTest(@param:TempDir private val tempDir: Path) {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `button availability follows every manager lifecycle state`() {
|
||||||
|
var connectionState = On4KstConnectionState.DISCONNECTED
|
||||||
|
val state = ConnectionBarState(preferences()) { connectionState }
|
||||||
|
|
||||||
|
On4KstConnectionState.entries.forEach { lifecycle ->
|
||||||
|
connectionState = lifecycle
|
||||||
|
assertEqualsLifecycleRules(lifecycle, state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `async disconnect redraws the open settings connection bar`() = runComposeUiTest {
|
||||||
|
var connectionState by mutableStateOf(On4KstConnectionState.ONLINE)
|
||||||
|
val state = ConnectionBarState(preferences()) { connectionState }
|
||||||
|
|
||||||
|
showTab {
|
||||||
|
ConnectionBar(
|
||||||
|
state = state,
|
||||||
|
onConnect = { },
|
||||||
|
onSave = { },
|
||||||
|
onApplyAndClose = { },
|
||||||
|
onDisconnectAndCloseChat = { },
|
||||||
|
onDisconnectOnly = { },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
onNodeWithText("Connect", substring = true).assertIsNotEnabled()
|
||||||
|
onNodeWithText("Disconnect").assertIsEnabled()
|
||||||
|
|
||||||
|
runOnIdle { connectionState = On4KstConnectionState.STOPPING }
|
||||||
|
onNodeWithText("Connect", substring = true).assertIsNotEnabled()
|
||||||
|
onNodeWithText("Disconnect").assertIsNotEnabled()
|
||||||
|
|
||||||
|
runOnIdle { connectionState = On4KstConnectionState.DISCONNECTED }
|
||||||
|
onNodeWithText("Connect", substring = true).assertIsEnabled()
|
||||||
|
onNodeWithText("Disconnect").assertIsNotEnabled()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a failed attempt enables one new connection attempt`() = runComposeUiTest {
|
||||||
|
var connectionState by mutableStateOf(On4KstConnectionState.CONNECTING)
|
||||||
|
var attempts = 0
|
||||||
|
val state = ConnectionBarState(preferences()) { connectionState }
|
||||||
|
|
||||||
|
showTab {
|
||||||
|
ConnectionBar(
|
||||||
|
state = state,
|
||||||
|
onConnect = {
|
||||||
|
attempts++
|
||||||
|
connectionState = On4KstConnectionState.CONNECTING
|
||||||
|
},
|
||||||
|
onSave = { },
|
||||||
|
onApplyAndClose = { },
|
||||||
|
onDisconnectAndCloseChat = { },
|
||||||
|
onDisconnectOnly = { },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
runOnIdle { connectionState = On4KstConnectionState.DISCONNECTED }
|
||||||
|
onNodeWithText("Connect", substring = true).performClick()
|
||||||
|
|
||||||
|
assertTrue(attempts == 1)
|
||||||
|
onNodeWithText("Connect", substring = true).assertIsNotEnabled()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertEqualsLifecycleRules(
|
||||||
|
lifecycle: On4KstConnectionState,
|
||||||
|
state: ConnectionBarState,
|
||||||
|
) {
|
||||||
|
assertTrue(state.canConnect == (lifecycle == On4KstConnectionState.DISCONNECTED), lifecycle.name)
|
||||||
|
assertTrue(state.canDisconnect == lifecycle.isConnectionAttemptActive, lifecycle.name)
|
||||||
|
if (lifecycle == On4KstConnectionState.STOPPING) {
|
||||||
|
assertFalse(state.canConnect)
|
||||||
|
assertFalse(state.canDisconnect)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun preferences() = ChatPreferences(tempDir.resolve("preferences.xml"))
|
||||||
|
}
|
||||||
@@ -34,6 +34,97 @@ class DataTableStateTest {
|
|||||||
rowKey = RowKeys.byValue { s: Station -> s.callSign },
|
rowKey = RowKeys.byValue { s: Station -> s.callSign },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `an initial sort is applied once and keeps later rows in order`() {
|
||||||
|
val table = DataTableState(
|
||||||
|
columns = listOf(
|
||||||
|
DataColumn(
|
||||||
|
id = "callsign",
|
||||||
|
title = "Callsign",
|
||||||
|
value = { station: Station -> station.callSign },
|
||||||
|
comparator = compareBy(String.CASE_INSENSITIVE_ORDER) { station: Station ->
|
||||||
|
station.callSign.trim()
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
rowKey = RowKeys.byValue { station: Station -> station.callSign },
|
||||||
|
initialSortColumnId = "callsign",
|
||||||
|
)
|
||||||
|
|
||||||
|
table.replaceRows(listOf(Station("do5amf", 1), Station("DL1ABC", 2)))
|
||||||
|
assertEquals(listOf("DL1ABC", "do5amf"), table.visibleRows.map { it.callSign })
|
||||||
|
|
||||||
|
table.replaceRows(
|
||||||
|
listOf(Station("ZZ9ZZZ", 3), Station("do5amf", 1), Station("AA1AAA", 4), Station("DL1ABC", 2)),
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
listOf("AA1AAA", "DL1ABC", "do5amf", "ZZ9ZZZ"),
|
||||||
|
table.visibleRows.map { it.callSign },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a user sort replaces the initial sort and survives row and filter updates`() {
|
||||||
|
val table = DataTableState(
|
||||||
|
columns = listOf(
|
||||||
|
DataColumn(id = "callsign", title = "Callsign", value = { station: Station -> station.callSign }),
|
||||||
|
DataColumn(
|
||||||
|
id = "qrb",
|
||||||
|
title = "QRB",
|
||||||
|
value = { station: Station -> station.qrb.toString() },
|
||||||
|
comparator = compareBy { station: Station -> station.qrb },
|
||||||
|
),
|
||||||
|
),
|
||||||
|
rowKey = RowKeys.byValue { station: Station -> station.callSign },
|
||||||
|
initialSortColumnId = "callsign",
|
||||||
|
)
|
||||||
|
table.replaceRows(listOf(Station("B", 300), Station("A", 100)))
|
||||||
|
|
||||||
|
table.toggleSort("qrb")
|
||||||
|
table.rowFilter = { it.qrb >= 100 }
|
||||||
|
table.replaceRows(listOf(Station("C", 200), Station("B", 300), Station("A", 100)))
|
||||||
|
|
||||||
|
assertEquals("qrb", table.sortedColumnId)
|
||||||
|
assertEquals(listOf("A", "C", "B"), table.visibleRows.map { it.callSign })
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a selected filtered row can be pinned only in the table view`() {
|
||||||
|
val table = DataTableState(
|
||||||
|
columns = listOf(DataColumn(id = "callsign", title = "Callsign", value = { s: Station -> s.callSign })),
|
||||||
|
rowKey = RowKeys.byValue { station: Station -> station.callSign },
|
||||||
|
keepSelectionVisible = true,
|
||||||
|
)
|
||||||
|
val hidden = Station("DL1HIDE", 100)
|
||||||
|
val shown = Station("DL2SHOW", 500)
|
||||||
|
table.replaceRows(listOf(hidden, shown))
|
||||||
|
table.rowFilter = { it.qrb >= 300 }
|
||||||
|
|
||||||
|
table.select(hidden)
|
||||||
|
|
||||||
|
assertEquals(listOf("DL2SHOW"), table.filteredRows.map { it.callSign }, "the shared map filter changed")
|
||||||
|
assertEquals(
|
||||||
|
listOf("DL1HIDE", "DL2SHOW"),
|
||||||
|
table.visibleRows.map { it.callSign },
|
||||||
|
"the selected station was not made reachable in the table",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `the same selected row can request scrolling more than once`() {
|
||||||
|
val table = stationTable()
|
||||||
|
val selected = Station("DL1ABC", 100)
|
||||||
|
table.replaceRows(listOf(selected))
|
||||||
|
table.select(selected)
|
||||||
|
|
||||||
|
table.requestScrollToSelection()
|
||||||
|
val first = table.scrollRequestRevision
|
||||||
|
table.requestScrollToSelection()
|
||||||
|
|
||||||
|
assertTrue(table.scrollRequestRevision > first)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `the selection follows the row, not its position`() {
|
fun `the selection follows the row, not its position`() {
|
||||||
val table = stationTable()
|
val table = stationTable()
|
||||||
@@ -388,6 +479,24 @@ class DataTableColumnWidthTest {
|
|||||||
assertEquals(140.0, table(store).widthOf("callsign"))
|
assertEquals(140.0, table(store).widthOf("callsign"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a stored narrow width wins over the automatic width`() {
|
||||||
|
val store = RecordingStore()
|
||||||
|
store.stored["dx-cluster-monitor/callsign"] = 36.0
|
||||||
|
val table = table(store)
|
||||||
|
val column = table.columns.first { it.id == "callsign" }
|
||||||
|
|
||||||
|
assertEquals(36f, effectiveColumnWidthDp(table, column, mapOf("callsign" to 140f)))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `the automatic width is used only without a stored width`() {
|
||||||
|
val table = table(RecordingStore())
|
||||||
|
val column = table.columns.first { it.id == "callsign" }
|
||||||
|
|
||||||
|
assertEquals(140f, effectiveColumnWidthDp(table, column, mapOf("callsign" to 140f)))
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `a column never sized yet has no stored width`() {
|
fun `a column never sized yet has no stored width`() {
|
||||||
assertNull(table(RecordingStore()).widthOf("qra"),
|
assertNull(table(RecordingStore()).widthOf("qra"),
|
||||||
|
|||||||
+57
@@ -0,0 +1,57 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import kst4contest.model.ChatPreferences
|
||||||
|
import kst4contest.view.compose.tabs.GuiOptionsTabState
|
||||||
|
import kst4contest.view.i18n.LanguageStore
|
||||||
|
import kst4contest.view.i18n.SYSTEM_LANGUAGE
|
||||||
|
import org.junit.jupiter.api.Assertions.assertFalse
|
||||||
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.api.io.TempDir
|
||||||
|
import java.nio.file.Path
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
|
class GuiStartupDesignPersistenceTest(@param:TempDir private val tempDir: Path) {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `root profile keeps evening startup design across save layout autosave and reload`() {
|
||||||
|
assertStartupDesignSurvives(tempDir.resolve("preferences.xml"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `named profile keeps evening startup design across save layout autosave and reload`() {
|
||||||
|
assertStartupDesignSurvives(tempDir.resolve("profiles/CONTEST/preferences.xml"))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertStartupDesignSurvives(preferencesFile: Path) {
|
||||||
|
val preferences = ChatPreferences(preferencesFile)
|
||||||
|
val draft = SettingsDraft()
|
||||||
|
val notices = SettingsNotices()
|
||||||
|
val state = GuiOptionsTabState(preferences, draft, languageStore())
|
||||||
|
|
||||||
|
state.gUI_darkModeActiveByDefault = true
|
||||||
|
applyAndSave(draft, notices) {
|
||||||
|
preferences.writePreferencesToXmlFile()
|
||||||
|
.takeIf { it }
|
||||||
|
?.let { preferences.storeAndRestorePreferencesFileName }
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue(preferences.isGUI_darkModeActiveByDefault)
|
||||||
|
|
||||||
|
// The menu switch is session-only and must not alter the next startup.
|
||||||
|
preferences.isGUI_darkModeActive = false
|
||||||
|
preferences.getGUIsettingsStageSceneSizeHW()[0] = 777.0
|
||||||
|
assertTrue(preferences.writeLayoutPreferencesToXmlFile())
|
||||||
|
|
||||||
|
val restored = ChatPreferences(preferencesFile)
|
||||||
|
assertTrue(restored.readPreferencesFromXmlFile())
|
||||||
|
assertTrue(restored.isGUI_darkModeActiveByDefault)
|
||||||
|
assertFalse(restored.isGUI_darkModeActive)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun languageStore() = LanguageStore(
|
||||||
|
storedLanguage = { SYSTEM_LANGUAGE },
|
||||||
|
storeLanguage = { },
|
||||||
|
systemDefault = Locale.UK,
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@ class MainMenuModelTest {
|
|||||||
override fun setQrgAsNameInChat() { calls += "setQrgAsNameInChat" }
|
override fun setQrgAsNameInChat() { calls += "setQrgAsNameInChat" }
|
||||||
override fun toggleAwayState() { calls += "toggleAwayState" }
|
override fun toggleAwayState() { calls += "toggleAwayState" }
|
||||||
override fun toggleSettingsWindow() { calls += "toggleSettingsWindow" }
|
override fun toggleSettingsWindow() { calls += "toggleSettingsWindow" }
|
||||||
|
override fun openSetupWizard() { calls += "openSetupWizard" }
|
||||||
override fun toggleMonitorWindow() { calls += "toggleMonitorWindow" }
|
override fun toggleMonitorWindow() { calls += "toggleMonitorWindow" }
|
||||||
override fun toggleStationMap() { calls += "toggleStationMap" }
|
override fun toggleStationMap() { calls += "toggleStationMap" }
|
||||||
override fun useDarkDesign() { calls += "useDarkDesign" }
|
override fun useDarkDesign() { calls += "useDarkDesign" }
|
||||||
@@ -181,4 +182,19 @@ class MainMenuModelTest {
|
|||||||
"every item must reach an action; one of them did nothing",
|
"every item must reach an action; one of them did nothing",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun theSetupAssistantIsReachableFromOptionsWhateverTheConnection() {
|
||||||
|
for (connectionState in On4KstConnectionState.values()) {
|
||||||
|
val actions = RecordingActions()
|
||||||
|
val model = model(connectionState = connectionState, actions = actions)
|
||||||
|
val entry = items(model.single { it.title == "Options" }).single { it.label == "Setup assistant..." }
|
||||||
|
|
||||||
|
// Like the profile switch: it gives the session up itself, after asking.
|
||||||
|
assertTrue(entry.enabled, "the assistant must be reachable while $connectionState")
|
||||||
|
|
||||||
|
entry.onClick()
|
||||||
|
assertEquals("openSetupWizard", actions.calls.last())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -55,6 +55,7 @@ class MainMenuRowScreenTest {
|
|||||||
override fun setQrgAsNameInChat() { calls += "setQrgAsNameInChat" }
|
override fun setQrgAsNameInChat() { calls += "setQrgAsNameInChat" }
|
||||||
override fun toggleAwayState() { calls += "toggleAwayState" }
|
override fun toggleAwayState() { calls += "toggleAwayState" }
|
||||||
override fun toggleSettingsWindow() { calls += "toggleSettingsWindow" }
|
override fun toggleSettingsWindow() { calls += "toggleSettingsWindow" }
|
||||||
|
override fun openSetupWizard() { calls += "openSetupWizard" }
|
||||||
override fun toggleMonitorWindow() { calls += "toggleMonitorWindow" }
|
override fun toggleMonitorWindow() { calls += "toggleMonitorWindow" }
|
||||||
override fun toggleStationMap() { calls += "toggleStationMap" }
|
override fun toggleStationMap() { calls += "toggleStationMap" }
|
||||||
override fun useDarkDesign() { calls += "useDarkDesign" }
|
override fun useDarkDesign() { calls += "useDarkDesign" }
|
||||||
@@ -116,6 +117,7 @@ class MainMenuRowScreenTest {
|
|||||||
Triple("Options", "Set QRG as name in Chat (main category)", "setQrgAsNameInChat"),
|
Triple("Options", "Set QRG as name in Chat (main category)", "setQrgAsNameInChat"),
|
||||||
Triple("Options", "Show me as AWAY FROM chat!", "toggleAwayState"),
|
Triple("Options", "Show me as AWAY FROM chat!", "toggleAwayState"),
|
||||||
Triple("Options", "Show options", "toggleSettingsWindow"),
|
Triple("Options", "Show options", "toggleSettingsWindow"),
|
||||||
|
Triple("Options", "Setup assistant...", "openSetupWizard"),
|
||||||
Triple("Windows", "Show cluster / stranger QSOs", "toggleMonitorWindow"),
|
Triple("Windows", "Show cluster / stranger QSOs", "toggleMonitorWindow"),
|
||||||
Triple("Windows", "Show / hide station map", "toggleStationMap"),
|
Triple("Windows", "Show / hide station map", "toggleStationMap"),
|
||||||
Triple("Windows", "Use dark mode design", "useDarkDesign"),
|
Triple("Windows", "Use dark mode design", "useDarkDesign"),
|
||||||
@@ -219,6 +221,29 @@ class MainMenuRowScreenTest {
|
|||||||
onNodeWithText("Show cluster / stranger QSOs").assertDoesNotExist()
|
onNodeWithText("Show cluster / stranger QSOs").assertDoesNotExist()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The menu starts at the bar's bottom edge, like any menu bar's menu. Material3's
|
||||||
|
* DropdownMenu cannot do this: its position provider refuses any y closer than 48 dp
|
||||||
|
* (MenuVerticalMargin) to the window's top edge, and the bar sits exactly there, so
|
||||||
|
* every menu opened with a visible gap hanging below the bar.
|
||||||
|
*
|
||||||
|
* The popup-semantics node is a scene-filling layout that positions the menu inside
|
||||||
|
* itself, so its own bounds say nothing; the first item is measured instead, which
|
||||||
|
* sits [MENU_POPUP_VERTICAL_PADDING] below the menu's top edge.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun theMenuOpensFlushUnderTheBar() = runComposeUiTest {
|
||||||
|
showRow(onlineState(), RecordingActions())
|
||||||
|
|
||||||
|
onNodeWithText("File").performClick()
|
||||||
|
val firstItem = awaitNode(inPopup("Connect to 144/432 MHz"))
|
||||||
|
|
||||||
|
val rowBottom = onNodeWithTag(rowTag).fetchSemanticsNode().boundsInWindow.bottom
|
||||||
|
val itemTop = firstItem.fetchSemanticsNode().boundsInWindow.top
|
||||||
|
val paddingPx = 8f
|
||||||
|
assertEquals(rowBottom + paddingPx, itemTop, 0.5f, "the menu does not start at the bar's bottom edge")
|
||||||
|
}
|
||||||
|
|
||||||
/** A second click on an open title closes it again, the way a menu bar behaves. */
|
/** A second click on an open title closes it again, the way a menu bar behaves. */
|
||||||
@Test
|
@Test
|
||||||
fun clickingAnOpenTitleClosesIt() = runComposeUiTest {
|
fun clickingAnOpenTitleClosesIt() = runComposeUiTest {
|
||||||
|
|||||||
@@ -120,6 +120,15 @@ class MainWindowSplitterDefaultsTest(@TempDir private val tempDir: Path) {
|
|||||||
val splitter = SplitterState(paneCount = 2, stored = stored) {}
|
val splitter = SplitterState(paneCount = 2, stored = stored) {}
|
||||||
assertEquals(stored.map { it.toFloat() }, splitter.positions)
|
assertEquals(stored.map { it.toFloat() }, splitter.positions)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `the selected station content splitter takes the one stored profile position`() {
|
||||||
|
val stored = prefs.getGUIselectedCallSignSplitPane_dividerposition()
|
||||||
|
assertEquals(1, stored.size)
|
||||||
|
|
||||||
|
val splitter = SplitterState(paneCount = MainWindowState.SELECTED_STATION_PANE_COUNT, stored = stored) {}
|
||||||
|
assertEquals(stored.map { it.toFloat() }, splitter.positions)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import kst4contest.model.ChatPreferences
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.Assertions.assertFalse
|
||||||
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.api.io.TempDir
|
||||||
|
import java.nio.file.Path
|
||||||
|
|
||||||
|
class ManualQtfHeadingSynchronizerTest(@param:TempDir private val directory: Path) {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `valid explicit QTF updates actual heading when synchronization is enabled`() {
|
||||||
|
val prefs = preferences().apply {
|
||||||
|
actualQTF.set(20.0)
|
||||||
|
}
|
||||||
|
assertTrue(applyExplicitQtfHeading(prefs, 315.5))
|
||||||
|
assertEquals(315.5, prefs.actualQTF.get(), 0.0001)
|
||||||
|
assertEquals(135.0, prefs.stn_qtfDefault, 0.0001)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `primary rotator prevents manual QTF synchronization`() {
|
||||||
|
val prefs = preferences().apply {
|
||||||
|
setStn_pstRotatorEnabled(true)
|
||||||
|
actualQTF.set(82.0)
|
||||||
|
}
|
||||||
|
assertFalse(applyExplicitQtfHeading(prefs, 180.0))
|
||||||
|
assertEquals(82.0, prefs.actualQTF.get(), 0.0001)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `disabled option and invalid angles leave actual heading unchanged`() {
|
||||||
|
val prefs = preferences().apply {
|
||||||
|
setStn_useQtfFilterDirectionAsAntennaHeading(false)
|
||||||
|
actualQTF.set(82.0)
|
||||||
|
}
|
||||||
|
listOf(90.0, Double.NaN, Double.POSITIVE_INFINITY, -0.1, 360.1).forEach { qtf ->
|
||||||
|
assertFalse(applyExplicitQtfHeading(prefs, qtf), "unexpectedly accepted $qtf")
|
||||||
|
assertEquals(82.0, prefs.actualQTF.get(), 0.0001)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `zero and 360 follow the existing antenna heading convention`() {
|
||||||
|
val prefs = preferences()
|
||||||
|
assertTrue(applyExplicitQtfHeading(prefs, 0.0))
|
||||||
|
assertEquals(0.0, prefs.actualQTF.get(), 0.0001)
|
||||||
|
assertTrue(applyExplicitQtfHeading(prefs, 360.0))
|
||||||
|
assertEquals(360.0, prefs.actualQTF.get(), 0.0001)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun preferences() = ChatPreferences(directory.resolve("preferences.xml"))
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import kst4contest.model.Band
|
||||||
|
import kst4contest.model.ChatCategory
|
||||||
|
import kst4contest.model.ChatMember
|
||||||
|
import kst4contest.view.map.PathAnalysisResult
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.Assertions.assertFalse
|
||||||
|
import org.junit.jupiter.api.Assertions.assertNull
|
||||||
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class MapReachabilityStateTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `latest station and band request rejects stale results`() {
|
||||||
|
val callbacks = mutableListOf<(PathAnalysisResult) -> Unit>()
|
||||||
|
val state = MapReachabilityState("JO51AA") { _, _, callback -> callbacks += callback }
|
||||||
|
val first = member("DL1ABC", 2, "JN49AA")
|
||||||
|
val second = member("DL2XYZ", 3, "JO60AA")
|
||||||
|
|
||||||
|
assertTrue(state.calculate(first, Band.B_144))
|
||||||
|
assertEquals("Loading", state.result?.analysisMode())
|
||||||
|
assertTrue(state.calculate(second, Band.B_432))
|
||||||
|
|
||||||
|
callbacks[1](result("DL2XYZ", 432.0))
|
||||||
|
callbacks[0](result("DL1ABC", 144.0))
|
||||||
|
|
||||||
|
assertEquals("DL2XYZ", state.result?.toCallsignRaw())
|
||||||
|
assertEquals(432.0, state.result?.analysisFrequencyMHz())
|
||||||
|
assertFalse(state.running)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `selecting another station invalidates an outstanding explicit result`() {
|
||||||
|
lateinit var callback: (PathAnalysisResult) -> Unit
|
||||||
|
val state = MapReachabilityState("JO51AA") { _, _, result -> callback = result }
|
||||||
|
val first = member("DL1ABC", 2, "JN49AA")
|
||||||
|
|
||||||
|
state.calculate(first, Band.B_144)
|
||||||
|
state.selectionChanged(StationIdentity("DL2XYZ", 2))
|
||||||
|
callback(result("DL1ABC", 144.0))
|
||||||
|
|
||||||
|
assertNull(state.result)
|
||||||
|
assertFalse(state.running)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `missing station or band does not start a request`() {
|
||||||
|
val state = MapReachabilityState("JO51AA") { _, _, _ -> error("must not run") }
|
||||||
|
|
||||||
|
assertFalse(state.calculate(null, Band.B_144))
|
||||||
|
assertFalse(state.calculate(member("DL1ABC", 2, "JN49AA"), null))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun member(callSign: String, category: Int, locator: String) = ChatMember().apply {
|
||||||
|
this.callSign = callSign
|
||||||
|
chatCategory = ChatCategory(category)
|
||||||
|
qra = locator
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun result(callSign: String, frequency: Double) = PathAnalysisResult.noProfile(
|
||||||
|
"Calculated", "JO51AA", "JN49AA", callSign,
|
||||||
|
100.0, 180.0, 10.0, 10.0, frequency, "done",
|
||||||
|
)
|
||||||
|
}
|
||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import androidx.compose.ui.unit.IntOffset
|
||||||
|
import androidx.compose.ui.unit.IntRect
|
||||||
|
import androidx.compose.ui.unit.IntSize
|
||||||
|
import androidx.compose.ui.unit.LayoutDirection
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The menu row's own popup placement, as pure arithmetic.
|
||||||
|
*
|
||||||
|
* Material3's DropdownMenuPositionProvider refuses any y closer than 48 dp to the window's
|
||||||
|
* top edge, which pushed every menu of the bar down to that margin. This provider must not:
|
||||||
|
* a menu-bar menu starts flush under its anchor, whatever the distance to the window edge.
|
||||||
|
*/
|
||||||
|
class MenuRowPopupPositionProviderTest {
|
||||||
|
|
||||||
|
private val window = IntSize(800, 600)
|
||||||
|
private val menu = IntSize(200, 150)
|
||||||
|
|
||||||
|
private fun positionOf(
|
||||||
|
anchor: IntRect,
|
||||||
|
window: IntSize = this.window,
|
||||||
|
direction: LayoutDirection = LayoutDirection.Ltr,
|
||||||
|
menu: IntSize = this.menu,
|
||||||
|
) = MenuRowPopupPositionProvider.calculatePosition(
|
||||||
|
anchorBounds = anchor,
|
||||||
|
windowSize = window,
|
||||||
|
layoutDirection = direction,
|
||||||
|
popupContentSize = menu,
|
||||||
|
)
|
||||||
|
|
||||||
|
/** The regression itself: an anchor at the very top gets its menu directly below it. */
|
||||||
|
@Test
|
||||||
|
fun opensFlushUnderAnAnchorAtTheTopOfTheWindow() {
|
||||||
|
val position = positionOf(IntRect(0, 0, 40, 30))
|
||||||
|
assertEquals(IntOffset(0, 30), position)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun staysInsideTheWindowWhenTheAnchorIsNearTheRightEdge() {
|
||||||
|
val position = positionOf(IntRect(760, 0, 800, 30))
|
||||||
|
assertEquals(IntOffset(600, 30), position)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun opensAboveTheAnchorWhenThereIsNoRoomBelow() {
|
||||||
|
val position = positionOf(IntRect(0, 560, 40, 590))
|
||||||
|
assertEquals(IntOffset(0, 410), position)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** No room on either side: pinned to the window's bottom edge rather than clipped. */
|
||||||
|
@Test
|
||||||
|
fun staysInsideAWindowTooSmallForTheMenu() {
|
||||||
|
val position = positionOf(IntRect(0, 40, 40, 70), window = IntSize(800, 100), menu = IntSize(200, 90))
|
||||||
|
assertEquals(IntOffset(0, 10), position)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun alignsTheRightEdgesInRightToLeftLayouts() {
|
||||||
|
val position = positionOf(IntRect(600, 0, 640, 30), direction = LayoutDirection.Rtl)
|
||||||
|
assertEquals(IntOffset(440, 30), position)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import androidx.compose.ui.test.ExperimentalTestApi
|
||||||
|
import androidx.compose.ui.test.assertIsNotSelected
|
||||||
|
import androidx.compose.ui.test.assertIsSelected
|
||||||
|
import androidx.compose.ui.test.onNodeWithText
|
||||||
|
import androidx.compose.ui.test.performClick
|
||||||
|
import androidx.compose.ui.test.runComposeUiTest
|
||||||
|
import kst4contest.model.ChatCategory
|
||||||
|
import kst4contest.model.ChatMember
|
||||||
|
import kst4contest.model.ChatMessage
|
||||||
|
import kst4contest.model.ClusterMessage
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.Assertions.assertSame
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
@OptIn(ExperimentalTestApi::class)
|
||||||
|
class MessageTabsScreenTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `tab semantics distinguish the active tab and follow selection`() = runComposeUiTest {
|
||||||
|
setContent {
|
||||||
|
Kst4ContestTheme(darkMode = true, baseFontSizeSp = 12f) {
|
||||||
|
MessageTabs(
|
||||||
|
publicMessages = messageTable(),
|
||||||
|
clusterMessages = clusterTable(),
|
||||||
|
qsoOfTheOther = messageTable(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onNodeWithText("Public messages").assertIsSelected()
|
||||||
|
onNodeWithText("DXCluster messages").assertIsNotSelected().performClick()
|
||||||
|
waitForIdle()
|
||||||
|
onNodeWithText("Public messages").assertIsNotSelected()
|
||||||
|
onNodeWithText("DXCluster messages").assertIsSelected()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a public message row reports its sender selection source`() = runComposeUiTest {
|
||||||
|
val public = messageTable()
|
||||||
|
val message = messageFrom("DL1PUBLIC")
|
||||||
|
public.replaceRows(listOf(message))
|
||||||
|
val clicks = mutableListOf<Pair<ChatMessage, StationSelectionSource>>()
|
||||||
|
|
||||||
|
setContent {
|
||||||
|
Kst4ContestTheme(darkMode = false, baseFontSizeSp = 12f) {
|
||||||
|
MessageTabs(
|
||||||
|
publicMessages = public,
|
||||||
|
clusterMessages = clusterTable(),
|
||||||
|
qsoOfTheOther = messageTable(),
|
||||||
|
onStationMessageClicked = { clicked, source -> clicks += clicked to source },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
waitForIdle()
|
||||||
|
|
||||||
|
onNodeWithText("DL1PUBLIC").performClick()
|
||||||
|
waitForIdle()
|
||||||
|
|
||||||
|
assertSame(message, clicks.single().first)
|
||||||
|
assertEquals(StationSelectionSource.PUBLIC_MESSAGE, clicks.single().second)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a qso of the other row reports its sender selection source`() = runComposeUiTest {
|
||||||
|
val qso = messageTable()
|
||||||
|
val message = messageFrom("DL2QSO")
|
||||||
|
qso.replaceRows(listOf(message))
|
||||||
|
val clicks = mutableListOf<Pair<ChatMessage, StationSelectionSource>>()
|
||||||
|
|
||||||
|
setContent {
|
||||||
|
Kst4ContestTheme(darkMode = false, baseFontSizeSp = 12f) {
|
||||||
|
MessageTabs(
|
||||||
|
publicMessages = messageTable(),
|
||||||
|
clusterMessages = clusterTable(),
|
||||||
|
qsoOfTheOther = qso,
|
||||||
|
onStationMessageClicked = { clicked, source -> clicks += clicked to source },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
waitForIdle()
|
||||||
|
|
||||||
|
onNodeWithText("QSO of the other").performClick()
|
||||||
|
waitForIdle()
|
||||||
|
onNodeWithText("DL2QSO").performClick()
|
||||||
|
waitForIdle()
|
||||||
|
|
||||||
|
assertSame(message, clicks.single().first)
|
||||||
|
assertEquals(StationSelectionSource.QSO_OF_THE_OTHER, clicks.single().second)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun messageTable() = DataTableState(
|
||||||
|
columns = listOf(
|
||||||
|
DataColumn(
|
||||||
|
id = "sender",
|
||||||
|
title = "Sender",
|
||||||
|
value = { message: ChatMessage -> message.sender?.callSign.orEmpty() },
|
||||||
|
),
|
||||||
|
),
|
||||||
|
rowKey = RowKeys.byReference<ChatMessage>(),
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun clusterTable() = DataTableState(
|
||||||
|
columns = emptyList<DataColumn<ClusterMessage>>(),
|
||||||
|
rowKey = RowKeys.byReference<ClusterMessage>(),
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun messageFrom(callSign: String): ChatMessage = ChatMessage().apply {
|
||||||
|
sender = ChatMember().apply {
|
||||||
|
this.callSign = callSign
|
||||||
|
chatCategory = ChatCategory(2)
|
||||||
|
}
|
||||||
|
receiver = ChatMember().apply { this.callSign = "ALL" }
|
||||||
|
chatCategory = ChatCategory(2)
|
||||||
|
messageText = "test"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,12 @@
|
|||||||
package kst4contest.view.compose
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.test.ComposeUiTest
|
import androidx.compose.ui.test.ComposeUiTest
|
||||||
|
import androidx.compose.ui.test.getBoundsInRoot
|
||||||
|
import androidx.compose.ui.test.onRoot
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.test.ExperimentalTestApi
|
import androidx.compose.ui.test.ExperimentalTestApi
|
||||||
import androidx.compose.ui.test.onAllNodesWithText
|
import androidx.compose.ui.test.onAllNodesWithText
|
||||||
import androidx.compose.ui.test.onNodeWithText
|
import androidx.compose.ui.test.onNodeWithText
|
||||||
@@ -9,6 +15,7 @@ import kst4contest.model.ChatMember
|
|||||||
import kst4contest.model.ChatMessage
|
import kst4contest.model.ChatMessage
|
||||||
import kst4contest.model.ClusterMessage
|
import kst4contest.model.ClusterMessage
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,10 +63,13 @@ class MonitorWindowScreenTest {
|
|||||||
private fun ComposeUiTest.show(
|
private fun ComposeUiTest.show(
|
||||||
cluster: DataTableState<ClusterMessage>,
|
cluster: DataTableState<ClusterMessage>,
|
||||||
qsos: DataTableState<ChatMessage>,
|
qsos: DataTableState<ChatMessage>,
|
||||||
|
splitter: SplitterState = SplitterState(paneCount = 2, stored = doubleArrayOf(0.5)) {},
|
||||||
) {
|
) {
|
||||||
setContent {
|
setContent {
|
||||||
Kst4ContestTheme(darkMode = false, baseFontSizeSp = 12f) {
|
Kst4ContestTheme(darkMode = false, baseFontSizeSp = 12f) {
|
||||||
MonitorContent(cluster, qsos)
|
Box(Modifier.size(600.dp, 400.dp)) {
|
||||||
|
MonitorContent(cluster, qsos, splitter)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
waitForIdle()
|
waitForIdle()
|
||||||
@@ -75,6 +85,22 @@ class MonitorWindowScreenTest {
|
|||||||
onNodeWithText("Call TX").assertExists()
|
onNodeWithText("Call TX").assertExists()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The two tables used to get half the height each, fixed, and the stored position the
|
||||||
|
* JavaFX SplitPane had written was read by nobody (#144). The QSO heading is the top of
|
||||||
|
* the lower pane, so where it sits says where the divider is.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun theStoredDividerPositionSplitsTheWindow() = runComposeUiTest {
|
||||||
|
show(clusterTable(), qsoTable(), SplitterState(paneCount = 2, stored = doubleArrayOf(0.8)) {})
|
||||||
|
|
||||||
|
val window = onRoot().getBoundsInRoot()
|
||||||
|
val qsoHeadingTop = onNodeWithText("QSO of the other").getBoundsInRoot().top
|
||||||
|
val share = (qsoHeadingTop - window.top) / (window.bottom - window.top)
|
||||||
|
|
||||||
|
assertTrue(share in 0.75f..0.85f, "QSO pane starts at $share of the height, expected about 0.8")
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun messagesArrivingWhileTheWindowIsOpenReachBothTables() = runComposeUiTest {
|
fun messagesArrivingWhileTheWindowIsOpenReachBothTables() = runComposeUiTest {
|
||||||
val cluster = clusterTable()
|
val cluster = clusterTable()
|
||||||
|
|||||||
@@ -0,0 +1,126 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import androidx.compose.ui.test.ExperimentalTestApi
|
||||||
|
import androidx.compose.ui.test.assertIsDisplayed
|
||||||
|
import androidx.compose.ui.test.onNodeWithText
|
||||||
|
import androidx.compose.ui.test.onNodeWithTag
|
||||||
|
import androidx.compose.ui.test.performClick
|
||||||
|
import androidx.compose.ui.test.runComposeUiTest
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import kst4contest.model.ChatCategory
|
||||||
|
import kst4contest.model.ChatMember
|
||||||
|
import kst4contest.model.RecentChatJoin
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.Assertions.assertSame
|
||||||
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
@OptIn(ExperimentalTestApi::class)
|
||||||
|
class NewJoinedBarScreenTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun fiveNewestStationsAreDirectAndAdditionalStationsUseTheMoreDropdown() = runComposeUiTest {
|
||||||
|
val selection = StationSelectionState()
|
||||||
|
val members = (1..7).map { member("DL${it}ABC") }
|
||||||
|
val newJoined = NewJoinedState(clock = { 10_000L }) { member ->
|
||||||
|
selection.select(member, StationSelectionSource.NEW_JOINED)
|
||||||
|
}.apply {
|
||||||
|
updateActiveMembers(members)
|
||||||
|
updateEvents(
|
||||||
|
members.mapIndexed { index, member ->
|
||||||
|
RecentChatJoin(member.callSign, 2, 9_000L + index)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val priority = TopPriorityState(topStations = { emptyList() }, onSelect = {})
|
||||||
|
|
||||||
|
setContent {
|
||||||
|
Kst4ContestTheme(darkMode = false, baseFontSizeSp = 12f) {
|
||||||
|
TopPriorityBar(
|
||||||
|
state = priority,
|
||||||
|
newJoined = newJoined,
|
||||||
|
onShowMore = {},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onNodeWithText("New joined:").assertIsDisplayed()
|
||||||
|
listOf("DL7ABC", "DL6ABC", "DL5ABC", "DL4ABC", "DL3ABC").forEach {
|
||||||
|
onNodeWithText(it).assertIsDisplayed()
|
||||||
|
}
|
||||||
|
onNodeWithText("DL2ABC").assertDoesNotExist()
|
||||||
|
|
||||||
|
onNodeWithTag(NEW_JOINED_MORE_TAG).performClick()
|
||||||
|
onNodeWithText("DL2ABC").assertIsDisplayed().performClick()
|
||||||
|
|
||||||
|
assertSame(members[1], selection.selected)
|
||||||
|
assertEquals(StationSelectionSource.NEW_JOINED, selection.lastSource)
|
||||||
|
assertTrue(selection.scrollRequestRevision > 0L)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun emptyNewJoinedStateUsesNoSpaceBesidePriority() = runComposeUiTest {
|
||||||
|
val newJoined = NewJoinedState(onSelect = {})
|
||||||
|
val priorityMember = member("OK1FPR")
|
||||||
|
val priority = TopPriorityState(
|
||||||
|
topStations = { listOf(priorityMember to 767.0) },
|
||||||
|
onSelect = {},
|
||||||
|
).apply { refresh() }
|
||||||
|
|
||||||
|
setContent {
|
||||||
|
Kst4ContestTheme(darkMode = true, baseFontSizeSp = 12f) {
|
||||||
|
TopPriorityBar(
|
||||||
|
state = priority,
|
||||||
|
newJoined = newJoined,
|
||||||
|
onShowMore = {},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onNodeWithText("New joined:").assertDoesNotExist()
|
||||||
|
onNodeWithText("Priority:").assertIsDisplayed()
|
||||||
|
onNodeWithText("1 OK1FPR 767").assertIsDisplayed()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun narrowBarMovesAdditionalDirectEntriesIntoTheSameDropdownWithoutOverflow() = runComposeUiTest {
|
||||||
|
val members = (1..7).map { member("DL${it}ABC") }
|
||||||
|
val newJoined = NewJoinedState(clock = { 10_000L }, onSelect = {}).apply {
|
||||||
|
updateActiveMembers(members)
|
||||||
|
updateEvents(members.mapIndexed { index, member ->
|
||||||
|
RecentChatJoin(member.callSign, 2, 9_000L + index)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
setContent {
|
||||||
|
Kst4ContestTheme(darkMode = true, baseFontSizeSp = 12f) {
|
||||||
|
Box(Modifier.width(300.dp)) {
|
||||||
|
TopPriorityBar(
|
||||||
|
state = TopPriorityState(topStations = { emptyList() }, onSelect = {}),
|
||||||
|
newJoined = newJoined,
|
||||||
|
onShowMore = {},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onNodeWithText("DL7ABC").assertIsDisplayed()
|
||||||
|
onNodeWithText("DL6ABC").assertDoesNotExist()
|
||||||
|
val limit = with(density) { 300.dp.toPx() }
|
||||||
|
listOf(NEW_JOINED_GROUP_TAG, PRIORITY_GROUP_TAG).forEach { tag ->
|
||||||
|
val bounds = onNodeWithTag(tag).assertIsDisplayed().fetchSemanticsNode().boundsInRoot
|
||||||
|
assertTrue(bounds.right <= limit + 0.5f, "$tag crosses the narrow bar")
|
||||||
|
}
|
||||||
|
|
||||||
|
onNodeWithTag(NEW_JOINED_MORE_TAG).performClick()
|
||||||
|
onNodeWithText("DL6ABC").assertIsDisplayed()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun member(callSign: String) = ChatMember().apply {
|
||||||
|
this.callSign = callSign
|
||||||
|
chatCategory = ChatCategory(2)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import kst4contest.model.ChatCategory
|
||||||
|
import kst4contest.model.ChatMember
|
||||||
|
import kst4contest.model.RecentChatJoin
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.Assertions.assertFalse
|
||||||
|
import org.junit.jupiter.api.Assertions.assertSame
|
||||||
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import java.util.concurrent.atomic.AtomicLong
|
||||||
|
|
||||||
|
class NewJoinedStateTest {
|
||||||
|
|
||||||
|
private val now = AtomicLong(1_000_000L)
|
||||||
|
private var selected: ChatMember? = null
|
||||||
|
private val state = NewJoinedState(clock = now::get, onSelect = { selected = it })
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `an initial active roster without live events produces no entries`() {
|
||||||
|
state.updateActiveMembers(listOf(member("HB9SJV", 2)))
|
||||||
|
|
||||||
|
assertTrue(state.entries.isEmpty())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a live join is shown once and duplicate events do not renew it`() {
|
||||||
|
val station = member("HB9SJV", 2)
|
||||||
|
state.updateActiveMembers(listOf(station))
|
||||||
|
state.updateEvents(
|
||||||
|
listOf(
|
||||||
|
event("HB9SJV", 2, now.get() - 2_000L),
|
||||||
|
event("HB9SJV", 2, now.get() - 1_000L),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(listOf("HB9SJV"), state.entries.map { it.label })
|
||||||
|
assertEquals(now.get() - 2_000L, state.entries.single().joinedAtEpochMillis)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `the same full callsign in two categories stays distinguishable`() {
|
||||||
|
val main = member("DL1KDA", 2)
|
||||||
|
val microwave = member("DL1KDA", 3)
|
||||||
|
state.updateActiveMembers(listOf(main, microwave))
|
||||||
|
state.updateEvents(
|
||||||
|
listOf(
|
||||||
|
event("DL1KDA", 3, now.get()),
|
||||||
|
event("DL1KDA", 2, now.get() - 1L),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(listOf(3, 2), state.entries.map { it.identity.categoryNumber })
|
||||||
|
state.entries.first().select()
|
||||||
|
assertSame(microwave, selected)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `an entry expires exactly ten minutes after the join`() {
|
||||||
|
val station = member("OE5SOS", 2)
|
||||||
|
state.updateActiveMembers(listOf(station))
|
||||||
|
state.updateEvents(listOf(event("OE5SOS", 2, now.get())))
|
||||||
|
|
||||||
|
now.addAndGet(NewJoinedState.VALIDITY_MILLIS - 1L)
|
||||||
|
state.refresh()
|
||||||
|
assertTrue(state.isRecent(station))
|
||||||
|
|
||||||
|
now.incrementAndGet()
|
||||||
|
state.refresh()
|
||||||
|
assertFalse(state.isRecent(station))
|
||||||
|
assertTrue(state.entries.isEmpty())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `only five newest entries are direct and the rest remain in the overflow`() {
|
||||||
|
val members = (1..7).map { member("DL${it}ABC", 2) }
|
||||||
|
state.updateActiveMembers(members)
|
||||||
|
state.updateEvents(
|
||||||
|
members.mapIndexed { index, member ->
|
||||||
|
event(member.callSign, 2, now.get() - (members.size - index))
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(listOf("DL7ABC", "DL6ABC", "DL5ABC", "DL4ABC", "DL3ABC"),
|
||||||
|
state.visibleEntries.map { it.label })
|
||||||
|
assertEquals(listOf("DL2ABC", "DL1ABC"), state.overflowEntries.map { it.label })
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `a station leaving disappears and a real rejoin gets the new event`() {
|
||||||
|
val first = member("PA2M", 2)
|
||||||
|
state.updateActiveMembers(listOf(first))
|
||||||
|
state.updateEvents(listOf(event("PA2M", 2, now.get())))
|
||||||
|
|
||||||
|
state.updateActiveMembers(emptyList())
|
||||||
|
assertTrue(state.entries.isEmpty())
|
||||||
|
|
||||||
|
val rejoined = member("PA2M", 2)
|
||||||
|
now.addAndGet(5_000L)
|
||||||
|
state.updateActiveMembers(listOf(rejoined))
|
||||||
|
state.updateEvents(listOf(event("PA2M", 2, now.get())))
|
||||||
|
|
||||||
|
state.entries.single().select()
|
||||||
|
assertSame(rejoined, selected)
|
||||||
|
assertEquals(now.get(), state.entries.single().joinedAtEpochMillis)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun member(callSign: String, categoryNumber: Int) = ChatMember().apply {
|
||||||
|
this.callSign = callSign
|
||||||
|
chatCategory = ChatCategory(categoryNumber)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun event(callSign: String, categoryNumber: Int, joinedAt: Long) =
|
||||||
|
RecentChatJoin(callSign, categoryNumber, joinedAt)
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import java.awt.EventQueue
|
||||||
|
import java.lang.reflect.InvocationTargetException
|
||||||
|
|
||||||
|
/*
|
||||||
|
* An ImageComposeScene must live on the AWT event thread, the thread the application renders
|
||||||
|
* on. Compose Multiplatform 1.8.2 sends the global snapshot notifications there
|
||||||
|
* (GlobalSnapshotManager), and doing so takes two locks in the opposite order from a render
|
||||||
|
* on any other thread:
|
||||||
|
*
|
||||||
|
* - the render holds the scene's FlushCoroutineDispatcher runLock while a task it runs
|
||||||
|
* (here LazyListState.scrollToItem) measures and wants the SnapshotStateObserver's
|
||||||
|
* observedScopeMapsLock;
|
||||||
|
* - the event thread holds observedScopeMapsLock in drainChanges while a derived state it
|
||||||
|
* re-reads wakes a snapshotFlow collector of that scene, whose dispatch wants runLock.
|
||||||
|
*
|
||||||
|
* Both waited forever in CI runs 40252077018, 40252089738 and 40299943329; the thread dump of
|
||||||
|
* the last one shows both stacks. On one thread the two monitors are simply re-entered, which
|
||||||
|
* is why the application never hangs this way.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs [block] on the AWT event thread, waits for it and returns its result. Whatever
|
||||||
|
* [block] throws is rethrown here unwrapped, so a failed assertion still reads as one.
|
||||||
|
*/
|
||||||
|
internal fun <T> onEventThread(block: () -> T): T {
|
||||||
|
if (EventQueue.isDispatchThread()) return block()
|
||||||
|
|
||||||
|
var result: Result<T>? = null
|
||||||
|
try {
|
||||||
|
EventQueue.invokeAndWait { result = runCatching(block) }
|
||||||
|
} catch (wrapped: InvocationTargetException) {
|
||||||
|
throw wrapped.cause ?: wrapped
|
||||||
|
}
|
||||||
|
return result!!.getOrThrow()
|
||||||
|
}
|
||||||
@@ -100,11 +100,11 @@ class PaletteStoreFactoryTest(@TempDir private val tempDir: Path) {
|
|||||||
val files = OperatorProfilePaletteFiles.of(other)
|
val files = OperatorProfilePaletteFiles.of(other)
|
||||||
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
files.dayFile.path.endsWith("profiles/OP2/KST4ContestDefaultDay.css"),
|
files.dayFile.toPath().endsWith(Path.of("profiles", "OP2", "KST4ContestDefaultDay.css")),
|
||||||
"the daylight file is ${files.dayFile.path}",
|
"the daylight file is ${files.dayFile.path}",
|
||||||
)
|
)
|
||||||
assertTrue(
|
assertTrue(
|
||||||
files.eveningFile.path.endsWith("profiles/OP2/KST4ContestDefaultEvening.css"),
|
files.eveningFile.toPath().endsWith(Path.of("profiles", "OP2", "KST4ContestDefaultEvening.css")),
|
||||||
"the evening file is ${files.eveningFile.path}",
|
"the evening file is ${files.eveningFile.path}",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import kst4contest.model.Band
|
||||||
|
import kst4contest.model.ChatMember
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.Assertions.assertFalse
|
||||||
|
import org.junit.jupiter.api.Assertions.assertNull
|
||||||
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import java.util.EnumSet
|
||||||
|
|
||||||
|
class ReachabilityStateTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `auto and only locally active bands are offered`() {
|
||||||
|
val state = ReachabilityState(EnumSet.of(Band.B_144, Band.B_1296))
|
||||||
|
|
||||||
|
assertEquals(listOf(null, Band.B_144, Band.B_1296), state.options.map { it.band })
|
||||||
|
assertNull(state.bandOverride)
|
||||||
|
assertEquals("Auto", state.selectedOption.label)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `band changes redraw but never calculate`() {
|
||||||
|
val station = ChatMember().apply { callSign = "DL1ABC" }
|
||||||
|
val calculated = mutableListOf<Pair<ChatMember, Band>>()
|
||||||
|
var redraws = 0
|
||||||
|
val state = ReachabilityState(
|
||||||
|
activeBands = EnumSet.of(Band.B_144, Band.B_432),
|
||||||
|
resolveAutoBand = { Band.B_144 },
|
||||||
|
selectedStation = { station },
|
||||||
|
calculate = { member, band -> calculated += member to band },
|
||||||
|
refresh = { redraws++ },
|
||||||
|
)
|
||||||
|
|
||||||
|
state.selectBand(Band.B_432)
|
||||||
|
|
||||||
|
assertEquals(Band.B_432, state.resolveBand(station))
|
||||||
|
assertEquals(1, redraws)
|
||||||
|
assertTrue(calculated.isEmpty())
|
||||||
|
|
||||||
|
assertTrue(state.calculateSelected())
|
||||||
|
assertEquals(listOf(station to Band.B_432), calculated)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `auto uses shared resolver and unavailable selections do not calculate`() {
|
||||||
|
var selected: ChatMember? = ChatMember()
|
||||||
|
var calculations = 0
|
||||||
|
val state = ReachabilityState(
|
||||||
|
activeBands = EnumSet.of(Band.B_144),
|
||||||
|
resolveAutoBand = { null },
|
||||||
|
selectedStation = { selected },
|
||||||
|
calculate = { _, _ -> calculations++ },
|
||||||
|
)
|
||||||
|
|
||||||
|
assertFalse(state.canCalculate)
|
||||||
|
assertFalse(state.calculateSelected())
|
||||||
|
selected = null
|
||||||
|
assertFalse(state.calculateSelected())
|
||||||
|
assertEquals(0, calculations)
|
||||||
|
}
|
||||||
|
}
|
||||||
+155
@@ -0,0 +1,155 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import kst4contest.model.ChatCategory
|
||||||
|
import kst4contest.model.ChatMember
|
||||||
|
import kst4contest.model.ChatMessage
|
||||||
|
import org.junit.jupiter.api.Assertions.assertFalse
|
||||||
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class SelectedStationMessagePredicateTest {
|
||||||
|
|
||||||
|
private val ownCall = "DL0OWN"
|
||||||
|
private val selected = member("DL1SEL", 2)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `pm to me contains both private directions with the selected station`() {
|
||||||
|
val predicate = SelectedStationMessagePredicate.forSelection(
|
||||||
|
SelectedMessageFilter.PM_TO_ME,
|
||||||
|
selected,
|
||||||
|
ownCall,
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(predicate.test(message(selected, member(ownCall, 2), 2)))
|
||||||
|
assertTrue(predicate.test(message(member(ownCall, 2), selected, 2)))
|
||||||
|
assertFalse(predicate.test(message(selected, member("DL2OTHER", 2), 2)))
|
||||||
|
assertFalse(predicate.test(publicMessage(selected, 2)))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `pm to me also contains an explicitly addressed public message`() {
|
||||||
|
val predicate = SelectedStationMessagePredicate.forSelection(
|
||||||
|
SelectedMessageFilter.PM_TO_ME,
|
||||||
|
selected,
|
||||||
|
ownCall,
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(predicate.test(publicMessage(selected, 2, addressedToMe = true)))
|
||||||
|
assertFalse(predicate.test(publicMessage(selected, 2, addressedToMe = false)))
|
||||||
|
|
||||||
|
val mentionOnly = publicMessage(selected, 2).apply {
|
||||||
|
messageText = "Please ask $ownCall whether the path is open"
|
||||||
|
}
|
||||||
|
assertFalse(predicate.test(mentionOnly))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `pm to other contains only private messages sent by the selected station to others`() {
|
||||||
|
val other = member("DL2OTHER", 2)
|
||||||
|
val predicate = SelectedStationMessagePredicate.forSelection(
|
||||||
|
SelectedMessageFilter.PM_TO_OTHER,
|
||||||
|
selected,
|
||||||
|
ownCall,
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(predicate.test(message(selected, other, 2)))
|
||||||
|
assertFalse(predicate.test(message(other, selected, 2)))
|
||||||
|
assertFalse(predicate.test(message(selected, member(ownCall, 2), 2)))
|
||||||
|
assertFalse(predicate.test(publicMessage(selected, 2)))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `public contains only public messages sent by the selected station`() {
|
||||||
|
val predicate = SelectedStationMessagePredicate.forSelection(
|
||||||
|
SelectedMessageFilter.PUBLIC,
|
||||||
|
selected,
|
||||||
|
ownCall,
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(predicate.test(publicMessage(selected, 2)))
|
||||||
|
assertTrue(predicate.test(publicMessage(selected, 2, addressedToMe = true)))
|
||||||
|
assertFalse(predicate.test(publicMessage(member("DL2OTHER", 2), 2)))
|
||||||
|
assertFalse(predicate.test(message(selected, member("DL2OTHER", 2), 2)))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `nothing applies no additional message type restriction`() {
|
||||||
|
val predicate = SelectedStationMessagePredicate.forSelection(
|
||||||
|
SelectedMessageFilter.NOTHING,
|
||||||
|
selected,
|
||||||
|
ownCall,
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(predicate.test(message(selected, member(ownCall, 2), 2)))
|
||||||
|
assertTrue(predicate.test(message(member(ownCall, 2), selected, 2)))
|
||||||
|
assertTrue(predicate.test(publicMessage(selected, 2)))
|
||||||
|
assertFalse(predicate.test(publicMessage(member("DL2OTHER", 2), 2)))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `the same callsign in another category does not match`() {
|
||||||
|
val predicate = SelectedStationMessagePredicate.forSelection(
|
||||||
|
SelectedMessageFilter.PUBLIC,
|
||||||
|
selected,
|
||||||
|
ownCall,
|
||||||
|
)
|
||||||
|
|
||||||
|
assertFalse(predicate.test(publicMessage(member("DL1SEL", 3), 3)))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `message category is authoritative when a member snapshot has no category`() {
|
||||||
|
val senderWithoutCategory = member("DL1SEL", 2).apply { chatCategory = null }
|
||||||
|
val predicate = SelectedStationMessagePredicate.forSelection(
|
||||||
|
SelectedMessageFilter.PM_TO_ME,
|
||||||
|
selected,
|
||||||
|
ownCall,
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(predicate.test(message(senderWithoutCategory, member(ownCall, 2), 2)))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `missing selection or incomplete historical data fails closed`() {
|
||||||
|
val withoutSelection = SelectedStationMessagePredicate.forSelection(
|
||||||
|
SelectedMessageFilter.PUBLIC,
|
||||||
|
null,
|
||||||
|
ownCall,
|
||||||
|
)
|
||||||
|
val incomplete = ChatMessage().apply { chatCategory = ChatCategory(2) }
|
||||||
|
|
||||||
|
assertFalse(withoutSelection.test(publicMessage(selected, 2)))
|
||||||
|
assertFalse(
|
||||||
|
SelectedStationMessagePredicate.forSelection(SelectedMessageFilter.PUBLIC, selected, ownCall)
|
||||||
|
.test(incomplete),
|
||||||
|
)
|
||||||
|
assertFalse(
|
||||||
|
SelectedStationMessagePredicate.forSelection(
|
||||||
|
SelectedMessageFilter.PUBLIC,
|
||||||
|
ChatMember().apply { callSign = "DL1SEL" },
|
||||||
|
ownCall,
|
||||||
|
).test(publicMessage(selected, 2)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun message(sender: ChatMember, receiver: ChatMember, category: Int): ChatMessage = ChatMessage().apply {
|
||||||
|
this.sender = sender
|
||||||
|
this.receiver = receiver
|
||||||
|
chatCategory = ChatCategory(category)
|
||||||
|
messageText = "test"
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun publicMessage(
|
||||||
|
sender: ChatMember,
|
||||||
|
category: Int,
|
||||||
|
addressedToMe: Boolean = false,
|
||||||
|
): ChatMessage = message(sender, member("ALL", category), category).apply {
|
||||||
|
isMessageDirectedToCommunity = true
|
||||||
|
isMessageDirectedToMe = addressedToMe
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun member(callSign: String, category: Int): ChatMember = ChatMember().apply {
|
||||||
|
this.callSign = callSign
|
||||||
|
chatCategory = ChatCategory(category)
|
||||||
|
}
|
||||||
|
}
|
||||||
+160
@@ -0,0 +1,160 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.ui.ImageComposeScene
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.Dp
|
||||||
|
import androidx.compose.ui.unit.Density
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import kst4contest.model.Band
|
||||||
|
import kst4contest.model.ChatCategory
|
||||||
|
import kst4contest.model.ChatMember
|
||||||
|
import kst4contest.model.ChatMessage
|
||||||
|
import kst4contest.model.ClusterMessage
|
||||||
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.nio.file.Path
|
||||||
|
import java.time.Instant
|
||||||
|
import java.util.EnumSet
|
||||||
|
import java.util.function.Consumer
|
||||||
|
|
||||||
|
/** Produces review images for the selected-station controls and lower message tabs. */
|
||||||
|
class SelectedStationMessageUiVisualRenderingTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun rendersDayAndEveningAt100And125Percent() {
|
||||||
|
val reportDirectory = Path.of("build", "reports", "selected-station-message-ui")
|
||||||
|
Files.createDirectories(reportDirectory)
|
||||||
|
|
||||||
|
val scenarios = listOf(
|
||||||
|
RenderScenario(prefix = "", panelWidth = 570.dp, windowHeight = 768),
|
||||||
|
RenderScenario(prefix = "narrow-", panelWidth = 360.dp, windowHeight = 768),
|
||||||
|
RenderScenario(prefix = "short-", panelWidth = 570.dp, windowHeight = 480),
|
||||||
|
)
|
||||||
|
scenarios.forEach { scenario ->
|
||||||
|
listOf(false, true).forEach { darkMode ->
|
||||||
|
listOf(1f, 1.25f).forEach { scale ->
|
||||||
|
val bytes = render(darkMode, scale, scenario.panelWidth, scenario.windowHeight)
|
||||||
|
val palette = if (darkMode) "evening" else "day"
|
||||||
|
val scaling = if (scale == 1f) "100" else "125"
|
||||||
|
val name = "${scenario.prefix}$palette-$scaling.png"
|
||||||
|
Files.write(reportDirectory.resolve(name), bytes)
|
||||||
|
assertTrue(bytes.size > 10_000, "$name did not render")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun render(darkMode: Boolean, scale: Float, panelWidth: Dp, windowHeight: Int): ByteArray {
|
||||||
|
val selectedMember = member("DM5M", 2).apply {
|
||||||
|
setQTFdirection(255.54)
|
||||||
|
qrb = 1907.59
|
||||||
|
activityTimeLastInEpoch = Instant.now().epochSecond - 240
|
||||||
|
isQrv144 = false
|
||||||
|
isQrv1240 = false
|
||||||
|
}
|
||||||
|
val selectedState = SelectedStationState(
|
||||||
|
propagateNotQrv = {},
|
||||||
|
createSked = { _, _, _, _ -> true },
|
||||||
|
detectBands = { "Bands: 144/432 MHz" },
|
||||||
|
).apply {
|
||||||
|
select(selectedMember)
|
||||||
|
skedBand = Band.B_144
|
||||||
|
skedMode = "SSB"
|
||||||
|
remindPm = true
|
||||||
|
}
|
||||||
|
val selectedMessages = messageTable().apply {
|
||||||
|
replaceRows(
|
||||||
|
listOf(
|
||||||
|
message(selectedMember, member("DL0OWN", 2), "pse ur qrg"),
|
||||||
|
message(selectedMember, member("ALL", 2), "(DL0OWN) qrv 144.300"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val publicMessages = messageTable().apply {
|
||||||
|
replaceRows(listOf(message(selectedMember, member("ALL", 2), "cq 144.300")))
|
||||||
|
}
|
||||||
|
val qsoMessages = messageTable().apply {
|
||||||
|
replaceRows(listOf(message(member("DL1ABC", 2), member("DL2XYZ", 2), "pse sked")))
|
||||||
|
}
|
||||||
|
|
||||||
|
return onEventThread {
|
||||||
|
val scene = ImageComposeScene(width = 1366, height = windowHeight, density = Density(scale)) {
|
||||||
|
Kst4ContestTheme(darkMode = darkMode, baseFontSizeSp = 12f) {
|
||||||
|
Surface(
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
color = MaterialTheme.colorScheme.background,
|
||||||
|
) {
|
||||||
|
Row(Modifier.fillMaxSize().padding(6.dp)) {
|
||||||
|
MessageTabs(
|
||||||
|
publicMessages = publicMessages,
|
||||||
|
clusterMessages = clusterTable(),
|
||||||
|
qsoOfTheOther = qsoMessages,
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
)
|
||||||
|
SelectedStationPanel(
|
||||||
|
state = selectedState,
|
||||||
|
messages = selectedMessages,
|
||||||
|
activeBands = EnumSet.of(Band.B_144, Band.B_432, Band.B_1296),
|
||||||
|
openInBrowser = Consumer {},
|
||||||
|
onShowOnMap = {},
|
||||||
|
onShowPathInAirScout = {},
|
||||||
|
modifier = Modifier.width(panelWidth).padding(start = 6.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
scene.render().encodeToData()!!.bytes
|
||||||
|
} finally {
|
||||||
|
scene.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun messageTable() = DataTableState(
|
||||||
|
columns = listOf(
|
||||||
|
DataColumn("sender", "Sender", value = { message: ChatMessage -> message.sender.callSign }),
|
||||||
|
DataColumn("message", "Message", value = { message: ChatMessage -> message.messageText.orEmpty() }),
|
||||||
|
),
|
||||||
|
rowKey = RowKeys.byReference<ChatMessage>(),
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun clusterTable() = DataTableState(
|
||||||
|
columns = listOf(
|
||||||
|
DataColumn(
|
||||||
|
"message",
|
||||||
|
"DXCluster",
|
||||||
|
value = { message: ClusterMessage -> message.messageInhibited.orEmpty() },
|
||||||
|
),
|
||||||
|
),
|
||||||
|
rowKey = RowKeys.byReference<ClusterMessage>(),
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun message(sender: ChatMember, receiver: ChatMember, text: String) = ChatMessage().apply {
|
||||||
|
this.sender = sender
|
||||||
|
this.receiver = receiver
|
||||||
|
chatCategory = sender.chatCategory
|
||||||
|
messageText = text
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun member(callSign: String, category: Int) = ChatMember().apply {
|
||||||
|
this.callSign = callSign
|
||||||
|
chatCategory = ChatCategory(category)
|
||||||
|
qra = "JO31AA"
|
||||||
|
}
|
||||||
|
|
||||||
|
private data class RenderScenario(
|
||||||
|
val prefix: String,
|
||||||
|
val panelWidth: Dp,
|
||||||
|
val windowHeight: Int,
|
||||||
|
)
|
||||||
|
}
|
||||||
+431
@@ -0,0 +1,431 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.test.ExperimentalTestApi
|
||||||
|
import androidx.compose.ui.test.assertIsOff
|
||||||
|
import androidx.compose.ui.test.assertIsOn
|
||||||
|
import androidx.compose.ui.test.assertIsDisplayed
|
||||||
|
import androidx.compose.ui.test.onNodeWithTag
|
||||||
|
import androidx.compose.ui.test.onNodeWithText
|
||||||
|
import androidx.compose.ui.test.performClick
|
||||||
|
import androidx.compose.ui.test.performScrollTo
|
||||||
|
import androidx.compose.ui.test.runComposeUiTest
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import kst4contest.model.Band
|
||||||
|
import kst4contest.model.ChatCategory
|
||||||
|
import kst4contest.model.ChatMember
|
||||||
|
import kst4contest.model.ChatMessage
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.Assertions.assertFalse
|
||||||
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import java.time.Instant
|
||||||
|
import java.util.EnumSet
|
||||||
|
import java.util.function.Consumer
|
||||||
|
import kotlin.math.abs
|
||||||
|
|
||||||
|
/** The selected-station controls remain reachable when its splitter pane is short. */
|
||||||
|
@OptIn(ExperimentalTestApi::class)
|
||||||
|
class SelectedStationPanelScreenTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun stationHeaderKeepsAllMetadataOnOneLineWhenWideAndOmitsTheLocator() = runComposeUiTest {
|
||||||
|
val station = member("CT1EKD").apply {
|
||||||
|
qra = "IM59IB"
|
||||||
|
chatCategory = ChatCategory(2)
|
||||||
|
setQTFdirection(255.54)
|
||||||
|
qrb = 1907.59
|
||||||
|
activityTimeLastInEpoch = Instant.now().epochSecond - 240
|
||||||
|
}
|
||||||
|
val selected = selectedState(station, detectedBands = "Bands: 144/432 MHz")
|
||||||
|
|
||||||
|
setPanel(selected, Modifier.width(900.dp).height(420.dp))
|
||||||
|
|
||||||
|
val callsignTop = onNodeWithText("CT1EKD").fetchSemanticsNode().boundsInRoot.top
|
||||||
|
listOf(
|
||||||
|
station.chatCategory.getChatCategoryName(station.chatCategory.categoryNumber),
|
||||||
|
"QTF: 255.54°",
|
||||||
|
"QRB: 1907.59 km",
|
||||||
|
"Bands: 144/432 MHz",
|
||||||
|
).forEach { text ->
|
||||||
|
val top = onNodeWithText(text).assertIsDisplayed().fetchSemanticsNode().boundsInRoot.top
|
||||||
|
assertTrue(abs(top - callsignTop) <= 4f, "$text did not remain in the wide title row")
|
||||||
|
}
|
||||||
|
onNodeWithText("Last activity:", substring = true).assertIsDisplayed()
|
||||||
|
onNodeWithText("Bands: Bands:", substring = true).assertDoesNotExist()
|
||||||
|
onNodeWithText("IM59IB").assertDoesNotExist()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun stationHeaderWrapsMetadataWithoutClippingWhenNarrow() = runComposeUiTest {
|
||||||
|
val station = member("CT1EKD").apply {
|
||||||
|
qra = "IM59IB"
|
||||||
|
chatCategory = ChatCategory(2)
|
||||||
|
setQTFdirection(255.54)
|
||||||
|
qrb = 1907.59
|
||||||
|
activityTimeLastInEpoch = Instant.now().epochSecond - 240
|
||||||
|
}
|
||||||
|
val selected = selectedState(station, detectedBands = "Bands: 144/432 MHz")
|
||||||
|
|
||||||
|
setPanel(selected, Modifier.width(310.dp).height(620.dp))
|
||||||
|
|
||||||
|
val callsign = onNodeWithText("CT1EKD").fetchSemanticsNode().boundsInRoot
|
||||||
|
val bands = onNodeWithText("Bands: 144/432 MHz").assertIsDisplayed()
|
||||||
|
.fetchSemanticsNode().boundsInRoot
|
||||||
|
val panel = onNodeWithTag(SELECTED_STATION_PANEL_TAG).fetchSemanticsNode().boundsInRoot
|
||||||
|
assertTrue(bands.top > callsign.top, "the narrow header did not wrap")
|
||||||
|
assertTrue(bands.right <= panel.right, "wrapped metadata crossed the panel edge")
|
||||||
|
onNodeWithText("IM59IB").assertDoesNotExist()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun stationHeaderKeepsTheAlreadyLabelledEmptyBandsValueExactlyOnce() = runComposeUiTest {
|
||||||
|
val selected = selectedState(member("DM5M"), detectedBands = "Bands: -")
|
||||||
|
|
||||||
|
setPanel(selected, Modifier.width(570.dp).height(420.dp))
|
||||||
|
|
||||||
|
onNodeWithText("Bands: -").assertIsDisplayed()
|
||||||
|
onNodeWithText("Bands: Bands:", substring = true).assertDoesNotExist()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun messageFilterLabelSharesTheFirstFlowItemWithPmToMe() = runComposeUiTest {
|
||||||
|
val selected = selectedState("DM5M")
|
||||||
|
|
||||||
|
setPanel(selected, Modifier.width(250.dp).height(520.dp))
|
||||||
|
|
||||||
|
val label = onNodeWithText("Show messages:").assertIsDisplayed()
|
||||||
|
.fetchSemanticsNode().boundsInRoot
|
||||||
|
val firstChoice = onNodeWithText("pm to me").assertIsDisplayed()
|
||||||
|
.fetchSemanticsNode().boundsInRoot
|
||||||
|
assertTrue(abs(label.center.y - firstChoice.center.y) <= 2f)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun allMessageChoicesShareOneVerticalAxis() = runComposeUiTest {
|
||||||
|
setPanel(selectedState("DM5M"), Modifier.width(570.dp).height(420.dp))
|
||||||
|
|
||||||
|
val centers = listOf("pm to me", "pm to other", "public msgs", "nothing")
|
||||||
|
.map { onNodeWithText(it).fetchSemanticsNode().boundsInRoot.center.y }
|
||||||
|
|
||||||
|
assertTrue(centers.max() - centers.min() <= 1f, "radio labels are misaligned: $centers")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun selectedMessageSplitterChangesTheActualTableHeightInBothDirections() = runComposeUiTest {
|
||||||
|
val selected = selectedState("DM5M")
|
||||||
|
val splitter = SplitterState(2, doubleArrayOf(0.45)) {}
|
||||||
|
|
||||||
|
setContent {
|
||||||
|
Kst4ContestTheme(darkMode = false, baseFontSizeSp = 12f) {
|
||||||
|
SelectedStationPanel(
|
||||||
|
state = selected,
|
||||||
|
messages = messageTable(),
|
||||||
|
activeBands = EnumSet.of(Band.B_144),
|
||||||
|
contentSplitter = splitter,
|
||||||
|
openInBrowser = Consumer {},
|
||||||
|
onShowOnMap = {},
|
||||||
|
onShowPathInAirScout = {},
|
||||||
|
modifier = Modifier.width(570.dp).height(620.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val initial = onNodeWithTag(SELECTED_MESSAGES_TABLE_TAG)
|
||||||
|
.fetchSemanticsNode().boundsInRoot.height
|
||||||
|
runOnIdle { splitter.drag(0, 0.70f, 500f) }
|
||||||
|
waitForIdle()
|
||||||
|
val taller = onNodeWithTag(SELECTED_MESSAGES_TABLE_TAG)
|
||||||
|
.fetchSemanticsNode().boundsInRoot.height
|
||||||
|
assertTrue(taller > initial, "moving the divider down did not enlarge the table")
|
||||||
|
|
||||||
|
runOnIdle { splitter.drag(0, 0.25f, 500f) }
|
||||||
|
waitForIdle()
|
||||||
|
val shorter = onNodeWithTag(SELECTED_MESSAGES_TABLE_TAG)
|
||||||
|
.fetchSemanticsNode().boundsInRoot.height
|
||||||
|
assertTrue(shorter < taller, "moving the divider up did not shrink the table")
|
||||||
|
|
||||||
|
onNodeWithText("Lookup on qrz.com").assertIsDisplayed()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun selectedMessageSplitterSurvivesStationAndMessageUpdates() = runComposeUiTest {
|
||||||
|
val selected = selectedState("DM5M")
|
||||||
|
val messages = messageTable()
|
||||||
|
val splitter = SplitterState(2, doubleArrayOf(0.62)) {}
|
||||||
|
|
||||||
|
setContent {
|
||||||
|
Kst4ContestTheme(darkMode = false, baseFontSizeSp = 12f) {
|
||||||
|
SelectedStationPanel(
|
||||||
|
state = selected,
|
||||||
|
messages = messages,
|
||||||
|
activeBands = EnumSet.of(Band.B_144),
|
||||||
|
contentSplitter = splitter,
|
||||||
|
openInBrowser = Consumer {},
|
||||||
|
onShowOnMap = {},
|
||||||
|
onShowPathInAirScout = {},
|
||||||
|
modifier = Modifier.width(570.dp).height(620.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val expectedPosition = splitter.positions.single()
|
||||||
|
runOnIdle {
|
||||||
|
selected.select(member("DL1ABC"))
|
||||||
|
messages.replaceRows(listOf(ChatMessage().apply { messageText = "new message" }))
|
||||||
|
}
|
||||||
|
waitForIdle()
|
||||||
|
|
||||||
|
assertEquals(expectedPosition, splitter.positions.single())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun notQrvHeadingFollowsTheCurrentStationWithoutKeepingAStaleCallsign() = runComposeUiTest {
|
||||||
|
val selected = selectedState("DM5M")
|
||||||
|
|
||||||
|
setContent {
|
||||||
|
Kst4ContestTheme(darkMode = false, baseFontSizeSp = 12f) {
|
||||||
|
SelectedStationPanel(
|
||||||
|
state = selected,
|
||||||
|
messages = messageTable(),
|
||||||
|
activeBands = EnumSet.of(Band.B_144),
|
||||||
|
openInBrowser = Consumer {},
|
||||||
|
onShowOnMap = {},
|
||||||
|
onShowPathInAirScout = {},
|
||||||
|
modifier = Modifier.height(420.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onNodeWithText("Tag DM5M not QRV at bands:").assertIsDisplayed()
|
||||||
|
|
||||||
|
runOnIdle { selected.select(member("DL1ABC")) }
|
||||||
|
waitForIdle()
|
||||||
|
onNodeWithText("Tag DM5M not QRV at bands:").assertDoesNotExist()
|
||||||
|
onNodeWithText("Tag DL1ABC not QRV at bands:").assertIsDisplayed()
|
||||||
|
|
||||||
|
runOnIdle { selected.select(null) }
|
||||||
|
waitForIdle()
|
||||||
|
onNodeWithText("Tag DL1ABC not QRV at bands:").assertDoesNotExist()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun skedSentenceUsesTheCompactControlsWithoutTheOldOffsetsLabel() = runComposeUiTest {
|
||||||
|
val selected = selectedState("DM5M")
|
||||||
|
|
||||||
|
setContent {
|
||||||
|
Kst4ContestTheme(darkMode = true, baseFontSizeSp = 12f) {
|
||||||
|
SelectedStationPanel(
|
||||||
|
state = selected,
|
||||||
|
messages = messageTable(),
|
||||||
|
activeBands = EnumSet.of(Band.B_144),
|
||||||
|
openInBrowser = Consumer {},
|
||||||
|
onShowOnMap = {},
|
||||||
|
onShowPathInAirScout = {},
|
||||||
|
modifier = Modifier.height(420.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onNodeWithText("Sked alert").assertIsDisplayed()
|
||||||
|
onNodeWithText("Sked in").assertIsDisplayed()
|
||||||
|
onNodeWithText("Remind pm in").assertIsDisplayed()
|
||||||
|
onNodeWithText("Reminder offsets").assertDoesNotExist()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun skedBandChoiceUsesEnabledBandsAndPassesTheSelectionToSkedCreation() = runComposeUiTest {
|
||||||
|
var createdMinutes: Int? = null
|
||||||
|
var createdBand: Band? = null
|
||||||
|
var createdMode: String? = null
|
||||||
|
val selected = SelectedStationState(
|
||||||
|
propagateNotQrv = {},
|
||||||
|
createSked = { _, minutes, band, mode ->
|
||||||
|
createdMinutes = minutes
|
||||||
|
createdBand = band
|
||||||
|
createdMode = mode
|
||||||
|
true
|
||||||
|
},
|
||||||
|
).apply {
|
||||||
|
select(member("DM5M"))
|
||||||
|
skedBand = Band.B_144
|
||||||
|
skedMode = "SSB"
|
||||||
|
}
|
||||||
|
|
||||||
|
setContent {
|
||||||
|
Kst4ContestTheme(darkMode = false, baseFontSizeSp = 12f) {
|
||||||
|
SelectedStationPanel(
|
||||||
|
state = selected,
|
||||||
|
messages = messageTable(),
|
||||||
|
activeBands = EnumSet.of(Band.B_144, Band.B_432),
|
||||||
|
openInBrowser = Consumer {},
|
||||||
|
onShowOnMap = {},
|
||||||
|
onShowPathInAirScout = {},
|
||||||
|
modifier = Modifier.width(570.dp).height(520.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onNodeWithText("144 MHz").performClick()
|
||||||
|
onNodeWithText("1296 MHz").assertDoesNotExist()
|
||||||
|
onNodeWithText("432 MHz").assertIsDisplayed().performClick()
|
||||||
|
assertEquals(Band.B_432, selected.skedBand)
|
||||||
|
|
||||||
|
onNodeWithText("5").performClick()
|
||||||
|
onNodeWithText("8").assertIsDisplayed().performClick()
|
||||||
|
onNodeWithText("SSB").performClick()
|
||||||
|
onNodeWithText("CW").assertIsDisplayed().performClick()
|
||||||
|
|
||||||
|
onNodeWithText("Create sked").performScrollTo().performClick()
|
||||||
|
assertEquals(8, createdMinutes)
|
||||||
|
assertEquals(Band.B_432, createdBand)
|
||||||
|
assertEquals("CW", createdMode)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun notQrvToggleButtonsKeepAllSemanticsAndFollowTheSelectedStation() = runComposeUiTest {
|
||||||
|
val first = member("DM5M").apply {
|
||||||
|
isQrv144 = false
|
||||||
|
isQrv432 = true
|
||||||
|
isQrv1240 = false
|
||||||
|
}
|
||||||
|
val second = member("DL1ABC").apply {
|
||||||
|
isQrv144 = true
|
||||||
|
isQrv432 = false
|
||||||
|
isQrv1240 = true
|
||||||
|
}
|
||||||
|
val propagated = mutableListOf<ChatMember>()
|
||||||
|
val selected = SelectedStationState(
|
||||||
|
propagateNotQrv = { propagated += it },
|
||||||
|
createSked = { _, _, _, _ -> true },
|
||||||
|
).apply { select(first) }
|
||||||
|
|
||||||
|
setPanel(
|
||||||
|
selected,
|
||||||
|
Modifier.width(570.dp).height(520.dp),
|
||||||
|
EnumSet.of(Band.B_144, Band.B_432, Band.B_1296),
|
||||||
|
)
|
||||||
|
|
||||||
|
onNodeWithText("144").assertIsOn()
|
||||||
|
onNodeWithText("432").assertIsOff()
|
||||||
|
onNodeWithText("23cm").assertIsOn()
|
||||||
|
onNodeWithText("all").assertIsOff().performClick().assertIsOn()
|
||||||
|
assertFalse(first.isQrv10G, "all must retain its existing all-supported-bands semantics")
|
||||||
|
assertTrue(propagated.last() === first)
|
||||||
|
|
||||||
|
onNodeWithText("all").performClick().assertIsOff()
|
||||||
|
assertTrue(first.isQrv144)
|
||||||
|
assertTrue(first.isQrv10G)
|
||||||
|
|
||||||
|
runOnIdle { selected.select(second) }
|
||||||
|
waitForIdle()
|
||||||
|
onNodeWithText("144").assertIsOff()
|
||||||
|
onNodeWithText("432").assertIsOn()
|
||||||
|
onNodeWithText("23cm").assertIsOff()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun notQrvAndSkedGroupsFollowTheActualPanelWidth() = runComposeUiTest {
|
||||||
|
val selected = selectedState("DM5M")
|
||||||
|
var panelWidth by mutableStateOf(620.dp)
|
||||||
|
|
||||||
|
setContent {
|
||||||
|
Kst4ContestTheme(darkMode = false, baseFontSizeSp = 12f) {
|
||||||
|
Panel(selected, Modifier.width(panelWidth).height(560.dp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var notQrv = onNodeWithTag(SELECTED_NOT_QRV_GROUP_TAG).fetchSemanticsNode().boundsInRoot
|
||||||
|
var sked = onNodeWithTag(SELECTED_SKED_GROUP_TAG).fetchSemanticsNode().boundsInRoot
|
||||||
|
assertTrue(abs(notQrv.top - sked.top) <= 1f, "wide groups were not arranged horizontally")
|
||||||
|
assertTrue(sked.left >= notQrv.right, "wide groups overlap")
|
||||||
|
|
||||||
|
runOnIdle { panelWidth = 360.dp }
|
||||||
|
waitForIdle()
|
||||||
|
|
||||||
|
notQrv = onNodeWithTag(SELECTED_NOT_QRV_GROUP_TAG).fetchSemanticsNode().boundsInRoot
|
||||||
|
sked = onNodeWithTag(SELECTED_SKED_GROUP_TAG).fetchSemanticsNode().boundsInRoot
|
||||||
|
val panel = onNodeWithTag(SELECTED_STATION_PANEL_TAG).fetchSemanticsNode().boundsInRoot
|
||||||
|
assertTrue(sked.top >= notQrv.bottom, "narrow groups were not stacked vertically")
|
||||||
|
assertTrue(notQrv.right <= panel.right && sked.right <= panel.right, "a group crossed the panel edge")
|
||||||
|
|
||||||
|
listOf("Create sked", "Sked fail", "Reset fail").forEach {
|
||||||
|
onNodeWithText(it).performScrollTo().assertIsDisplayed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun lookupActionsCanBeScrolledIntoViewInAShortPane() = runComposeUiTest {
|
||||||
|
val selected = selectedState("DL1ABC")
|
||||||
|
val messages = messageTable()
|
||||||
|
|
||||||
|
setContent {
|
||||||
|
Kst4ContestTheme(darkMode = false, baseFontSizeSp = 12f) {
|
||||||
|
SelectedStationPanel(
|
||||||
|
state = selected,
|
||||||
|
messages = messages,
|
||||||
|
activeBands = EnumSet.of(Band.B_144),
|
||||||
|
openInBrowser = Consumer {},
|
||||||
|
onShowOnMap = {},
|
||||||
|
onShowPathInAirScout = {},
|
||||||
|
modifier = Modifier.height(220.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onNodeWithText("Lookup on qrz.com").assertIsDisplayed()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun selectedState(callSign: String) = selectedState(member(callSign))
|
||||||
|
|
||||||
|
private fun selectedState(member: ChatMember, detectedBands: String = "") = SelectedStationState(
|
||||||
|
propagateNotQrv = {},
|
||||||
|
createSked = { _, _, _, _ -> true },
|
||||||
|
detectBands = { detectedBands },
|
||||||
|
).apply { select(member) }
|
||||||
|
|
||||||
|
private fun member(callSign: String) = ChatMember().apply {
|
||||||
|
this.callSign = callSign
|
||||||
|
qra = "JO50AA"
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun androidx.compose.ui.test.ComposeUiTest.setPanel(
|
||||||
|
selected: SelectedStationState,
|
||||||
|
modifier: Modifier,
|
||||||
|
activeBands: Set<Band> = EnumSet.of(Band.B_144),
|
||||||
|
) {
|
||||||
|
setContent {
|
||||||
|
Kst4ContestTheme(darkMode = false, baseFontSizeSp = 12f) {
|
||||||
|
Panel(selected, modifier, activeBands)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@androidx.compose.runtime.Composable
|
||||||
|
private fun Panel(
|
||||||
|
selected: SelectedStationState,
|
||||||
|
modifier: Modifier,
|
||||||
|
activeBands: Set<Band> = EnumSet.of(Band.B_144),
|
||||||
|
) {
|
||||||
|
SelectedStationPanel(
|
||||||
|
state = selected,
|
||||||
|
messages = messageTable(),
|
||||||
|
activeBands = activeBands,
|
||||||
|
openInBrowser = Consumer {},
|
||||||
|
onShowOnMap = {},
|
||||||
|
onShowPathInAirScout = {},
|
||||||
|
modifier = modifier,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun messageTable() = DataTableState(
|
||||||
|
SelectedStationMessageColumns.all(),
|
||||||
|
RowKeys.byReference<ChatMessage>(),
|
||||||
|
"selected-station-panel-test",
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,11 +1,14 @@
|
|||||||
package kst4contest.view.compose
|
package kst4contest.view.compose
|
||||||
|
|
||||||
import kst4contest.model.ChatMember
|
import kst4contest.model.ChatMember
|
||||||
|
import kst4contest.model.ChatPreferences
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
import org.junit.jupiter.api.Assertions.assertFalse
|
import org.junit.jupiter.api.Assertions.assertFalse
|
||||||
import org.junit.jupiter.api.Assertions.assertNull
|
import org.junit.jupiter.api.Assertions.assertNull
|
||||||
import org.junit.jupiter.api.Assertions.assertTrue
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
import org.junit.jupiter.api.io.TempDir
|
||||||
|
import java.nio.file.Path
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The panel below the station list, for the station currently selected.
|
* The panel below the station list, for the station currently selected.
|
||||||
@@ -16,6 +19,9 @@ import org.junit.jupiter.api.Assertions.assertTrue
|
|||||||
*/
|
*/
|
||||||
class SelectedStationStateTest {
|
class SelectedStationStateTest {
|
||||||
|
|
||||||
|
@TempDir
|
||||||
|
lateinit var tempDir: Path
|
||||||
|
|
||||||
private class Session {
|
private class Session {
|
||||||
val propagated = mutableListOf<String>()
|
val propagated = mutableListOf<String>()
|
||||||
var skedsCreated = 0
|
var skedsCreated = 0
|
||||||
@@ -178,6 +184,15 @@ class SelectedStationStateTest {
|
|||||||
"the JavaFX radio buttons were one toggle group; two cannot be on")
|
"the JavaFX radio buttons were one toggle group; two cannot be on")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `public messages can be the configured initial radio mode`() {
|
||||||
|
val prefs = ChatPreferences(tempDir.resolve("preferences.xml")).apply {
|
||||||
|
isGuiOptions_defaultFilterPublicMsgs = true
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(SelectedMessageFilter.PUBLIC, SelectedMessageFilter.fromPreferences(prefs))
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* No filter is chosen until the operator chooses one. JavaFX has the
|
* No filter is chosen until the operator chooses one. JavaFX has the
|
||||||
* setSelected(true) on "pm to me" commented out, so the group starts with nothing on,
|
* setSelected(true) on "pm to me" commented out, so the group starts with nothing on,
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ class SettingsFieldCoverageTest {
|
|||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
|
||||||
val missing = expected.filterNot { composeSources.contains("$it(") }
|
val missing = expected.filterNot {
|
||||||
|
composeSources.contains("$it(") || composeSources.contains("::$it")
|
||||||
|
}
|
||||||
|
|
||||||
assertTrue(missing.isEmpty(),
|
assertTrue(missing.isEmpty(),
|
||||||
"settings not written by any Compose source (${missing.size} of ${expected.size}):\n" +
|
"settings not written by any Compose source (${missing.size} of ${expected.size}):\n" +
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import kst4contest.model.Band
|
||||||
|
import kst4contest.model.ChatCategory
|
||||||
|
import kst4contest.model.ChatMember
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.Assertions.assertFalse
|
||||||
|
import org.junit.jupiter.api.Assertions.assertSame
|
||||||
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class SkedEditorStateTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `panel submission includes reminder settings in one request`() {
|
||||||
|
val requests = mutableListOf<SkedRequest>()
|
||||||
|
val member = member("DL1ABC", 2)
|
||||||
|
val state = SelectedStationState(
|
||||||
|
propagateNotQrv = { },
|
||||||
|
createSked = { _, _, _, _ -> false },
|
||||||
|
)
|
||||||
|
state.skedRequestSubmitter = { request -> requests += request; true }
|
||||||
|
state.select(member)
|
||||||
|
state.skedMinutes = 8
|
||||||
|
state.skedBand = Band.B_432
|
||||||
|
state.skedMode = "CW"
|
||||||
|
state.remindPm = true
|
||||||
|
state.reminderOffsets = "5+2+1"
|
||||||
|
|
||||||
|
assertTrue(state.createSked())
|
||||||
|
assertEquals(
|
||||||
|
SkedRequest(member, 8, Band.B_432, "CW", true, "5+2+1"),
|
||||||
|
requests.single(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `popup draft keeps its target when the shared selection changes`() {
|
||||||
|
val requests = mutableListOf<SkedRequest>()
|
||||||
|
val original = member("DL1ABC", 2)
|
||||||
|
val later = member("DL2XYZ", 3)
|
||||||
|
val draft = SkedEditorState(
|
||||||
|
target = original,
|
||||||
|
minutes = 5,
|
||||||
|
band = Band.B_144,
|
||||||
|
mode = "SSB",
|
||||||
|
remindPm = false,
|
||||||
|
reminderOffsets = "2+1",
|
||||||
|
submitter = { request -> requests += request; true },
|
||||||
|
)
|
||||||
|
|
||||||
|
draft.minutes = 10
|
||||||
|
draft.band = Band.B_1296
|
||||||
|
draft.remindPm = true
|
||||||
|
@Suppress("UNUSED_VARIABLE") val unrelatedSelection = later
|
||||||
|
|
||||||
|
assertTrue(draft.submit())
|
||||||
|
assertSame(original, requests.single().target)
|
||||||
|
assertEquals(Band.B_1296, requests.single().band)
|
||||||
|
assertTrue(requests.single().remindPm)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `rejected popup submission reports failure so popup can remain open`() {
|
||||||
|
val draft = SkedEditorState(
|
||||||
|
target = member("DL1ABC", 2),
|
||||||
|
minutes = 5,
|
||||||
|
band = null,
|
||||||
|
mode = "SSB",
|
||||||
|
remindPm = false,
|
||||||
|
reminderOffsets = "2+1",
|
||||||
|
submitter = { false },
|
||||||
|
)
|
||||||
|
|
||||||
|
assertFalse(draft.submit())
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun member(callSign: String, category: Int) = ChatMember().apply {
|
||||||
|
this.callSign = callSign
|
||||||
|
chatCategory = ChatCategory(category)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -219,6 +219,57 @@ class SplitterStateTest {
|
|||||||
assertEquals(777f, state.paneSizes(totalPx = 777f).sum(), 0.01f)
|
assertEquals(777f, state.paneSizes(totalPx = 777f).sum(), 0.01f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `pane-specific minimums keep fixed-height controls visible without replacing stored positions`() {
|
||||||
|
val stored = doubleArrayOf(0.62, 0.7, 0.75, 0.9)
|
||||||
|
val state = SplitterState(paneCount = 5, stored = stored) {}
|
||||||
|
|
||||||
|
val sizes = state.paneSizes(
|
||||||
|
totalPx = 800f,
|
||||||
|
minimumPaneSizesPx = floatArrayOf(24f, 26f, 104f, 26f, 24f),
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(sizes[0] >= 24f)
|
||||||
|
assertTrue(sizes[1] >= 26f)
|
||||||
|
assertTrue(sizes[2] >= 104f)
|
||||||
|
assertTrue(sizes[3] >= 26f)
|
||||||
|
assertTrue(sizes[4] >= 24f)
|
||||||
|
assertEquals(800f, sizes.sum(), 0.01f)
|
||||||
|
stored.forEachIndexed { index, position ->
|
||||||
|
assertEquals(position.toFloat(), state.positions[index], 0.001f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `pane-specific minimums scale down together in an impossibly small splitter`() {
|
||||||
|
val state = SplitterState(paneCount = 3, stored = doubleArrayOf(0.2, 0.8)) {}
|
||||||
|
|
||||||
|
val sizes = state.paneSizes(
|
||||||
|
totalPx = 100f,
|
||||||
|
minimumPaneSizesPx = floatArrayOf(50f, 100f, 50f),
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(listOf(25f, 50f, 25f), sizes)
|
||||||
|
assertEquals(100f, sizes.sum(), 0.01f)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `pane-specific minimum scaling tolerates float rounding`() {
|
||||||
|
val state = SplitterState(
|
||||||
|
paneCount = 2,
|
||||||
|
stored = doubleArrayOf(0.48),
|
||||||
|
minPanePx = 160f,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
val sizes = state.paneSizes(
|
||||||
|
totalPx = 24.405657f,
|
||||||
|
minimumPaneSizesPx = floatArrayOf(52f, 160f),
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(sizes.all { it >= 0f })
|
||||||
|
assertEquals(24.405657f, sizes.sum(), 0.0001f)
|
||||||
|
}
|
||||||
|
|
||||||
private fun assertNull(value: Any?, message: String) {
|
private fun assertNull(value: Any?, message: String) {
|
||||||
assertFalse(value != null, message)
|
assertFalse(value != null, message)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
package kst4contest.view.compose
|
||||||
|
|
||||||
|
import androidx.compose.ui.unit.IntOffset
|
||||||
|
import androidx.compose.ui.unit.IntRect
|
||||||
|
import androidx.compose.ui.unit.IntSize
|
||||||
|
import androidx.compose.ui.unit.LayoutDirection
|
||||||
|
import kst4contest.model.Band
|
||||||
|
import kst4contest.model.ChatCategory
|
||||||
|
import kst4contest.model.ChatMember
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.Assertions.assertNull
|
||||||
|
import org.junit.jupiter.api.Assertions.assertSame
|
||||||
|
import org.junit.jupiter.api.Assertions.assertFalse
|
||||||
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class StationContextMenuStateTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `single row target is selected immediately with its context source`() {
|
||||||
|
val selections = mutableListOf<Pair<ChatMember, StationSelectionSource>>()
|
||||||
|
val state = StationContextMenuState { member, source -> selections += member to source }
|
||||||
|
val member = member("DL1ABC", 2)
|
||||||
|
|
||||||
|
state.open(listOf(member), StationSelectionSource.STATION_CONTEXT_MENU, IntOffset(10, 20))
|
||||||
|
|
||||||
|
assertSame(member, state.target)
|
||||||
|
assertEquals(listOf(member to StationSelectionSource.STATION_CONTEXT_MENU), selections)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `grouped map target requires an explicit full callsign and category choice`() {
|
||||||
|
val selections = mutableListOf<Pair<ChatMember, StationSelectionSource>>()
|
||||||
|
val state = StationContextMenuState { member, source -> selections += member to source }
|
||||||
|
val main = member("DN9APW-2", 2)
|
||||||
|
val second = member("DN9APW-2", 3)
|
||||||
|
|
||||||
|
state.open(
|
||||||
|
listOf(main, second, main),
|
||||||
|
StationSelectionSource.MAP_CONTEXT_MENU,
|
||||||
|
IntOffset(30, 40),
|
||||||
|
)
|
||||||
|
|
||||||
|
assertNull(state.target)
|
||||||
|
assertEquals(2, state.candidates.size)
|
||||||
|
assertEquals(emptyList<Pair<ChatMember, StationSelectionSource>>(), selections)
|
||||||
|
|
||||||
|
state.chooseTarget(second)
|
||||||
|
|
||||||
|
assertSame(second, state.target)
|
||||||
|
assertEquals(listOf(second to StationSelectionSource.MAP_CONTEXT_MENU), selections)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `target label retains the full suffix and category`() {
|
||||||
|
val target = member("DN9APW-70", 3)
|
||||||
|
|
||||||
|
val label = stationContextTargetLabel(target)
|
||||||
|
|
||||||
|
assertTrue(label.startsWith("DN9APW-70 | "))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `worked menu state follows the existing per-band flags`() {
|
||||||
|
val target = member("DL1ABC", 2)
|
||||||
|
target.isWorked144 = true
|
||||||
|
|
||||||
|
assertTrue(target.isWorkedOn(Band.B_144))
|
||||||
|
assertFalse(target.isWorkedOn(Band.B_432))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `popup anchor is clamped at the window edge`() {
|
||||||
|
val provider = WindowPointPopupPositionProvider(IntOffset(990, 790))
|
||||||
|
|
||||||
|
val position = provider.calculatePosition(
|
||||||
|
anchorBounds = IntRect.Zero,
|
||||||
|
windowSize = IntSize(1_000, 800),
|
||||||
|
layoutDirection = LayoutDirection.Ltr,
|
||||||
|
popupContentSize = IntSize(300, 250),
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(IntOffset(700, 550), position)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun member(callSign: String, category: Int) = ChatMember().apply {
|
||||||
|
this.callSign = callSign
|
||||||
|
chatCategory = ChatCategory(category)
|
||||||
|
}
|
||||||
|
}
|
||||||
+190
-2
@@ -10,10 +10,13 @@ import androidx.compose.ui.test.assertIsOff
|
|||||||
import androidx.compose.ui.test.assertIsOn
|
import androidx.compose.ui.test.assertIsOn
|
||||||
import androidx.compose.ui.test.assertTextEquals
|
import androidx.compose.ui.test.assertTextEquals
|
||||||
import androidx.compose.ui.test.onNodeWithText
|
import androidx.compose.ui.test.onNodeWithText
|
||||||
|
import androidx.compose.ui.test.onNodeWithTag
|
||||||
import androidx.compose.ui.test.performClick
|
import androidx.compose.ui.test.performClick
|
||||||
import androidx.compose.ui.test.runComposeUiTest
|
import androidx.compose.ui.test.runComposeUiTest
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import kst4contest.model.Band
|
import kst4contest.model.Band
|
||||||
|
import kst4contest.model.ChatPreferences
|
||||||
|
import kst4contest.view.compose.ObservedValue
|
||||||
import kst4contest.view.compose.tabs.checkBeside
|
import kst4contest.view.compose.tabs.checkBeside
|
||||||
import kst4contest.view.compose.tabs.fieldBeside
|
import kst4contest.view.compose.tabs.fieldBeside
|
||||||
import kst4contest.view.compose.tabs.showTab
|
import kst4contest.view.compose.tabs.showTab
|
||||||
@@ -23,7 +26,10 @@ import org.junit.jupiter.api.Assertions.assertEquals
|
|||||||
import org.junit.jupiter.api.Assertions.assertFalse
|
import org.junit.jupiter.api.Assertions.assertFalse
|
||||||
import org.junit.jupiter.api.Assertions.assertTrue
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.api.io.TempDir
|
||||||
|
import java.nio.file.Path
|
||||||
import java.util.EnumSet
|
import java.util.EnumSet
|
||||||
|
import kotlin.math.abs
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The QRB part of the station filter bar, drawn (#21).
|
* The QRB part of the station filter bar, drawn (#21).
|
||||||
@@ -35,7 +41,7 @@ import java.util.EnumSet
|
|||||||
* Headless: only a composition, no window.
|
* Headless: only a composition, no window.
|
||||||
*/
|
*/
|
||||||
@OptIn(ExperimentalTestApi::class)
|
@OptIn(ExperimentalTestApi::class)
|
||||||
class StationFilterBarScreenTest {
|
class StationFilterBarScreenTest(@param:TempDir private val directory: Path) {
|
||||||
|
|
||||||
private val maxLabel = "Show only QRB [km] <="
|
private val maxLabel = "Show only QRB [km] <="
|
||||||
private val minLabel = "Show only QRB [km] >"
|
private val minLabel = "Show only QRB [km] >"
|
||||||
@@ -43,6 +49,7 @@ class StationFilterBarScreenTest {
|
|||||||
private class Bar {
|
private class Bar {
|
||||||
val filters = StationFilterState()
|
val filters = StationFilterState()
|
||||||
var changes = 0
|
var changes = 0
|
||||||
|
val explicitQtfDirections = mutableListOf<Double>()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ComposeUiTest.showBar(): Bar {
|
private fun ComposeUiTest.showBar(): Bar {
|
||||||
@@ -51,12 +58,127 @@ class StationFilterBarScreenTest {
|
|||||||
StationFilterBar(
|
StationFilterBar(
|
||||||
filters = bar.filters,
|
filters = bar.filters,
|
||||||
activeBands = EnumSet.of(Band.B_144),
|
activeBands = EnumSet.of(Band.B_144),
|
||||||
|
reachability = ReachabilityState(EnumSet.of(Band.B_144)),
|
||||||
onChanged = { bar.changes++ },
|
onChanged = { bar.changes++ },
|
||||||
|
onQtfDirectionChanged = { bar.explicitQtfDirections += it },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return bar
|
return bar
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun aValidManualQtfEntryIsReportedEvenWhileTheFilterIsOff() = runComposeUiTest {
|
||||||
|
val bar = showBar()
|
||||||
|
|
||||||
|
type("Show only QTF:", "127.5")
|
||||||
|
|
||||||
|
assertFalse(bar.filters.qtfEnabled)
|
||||||
|
assertEquals(listOf(127.5), bar.explicitQtfDirections)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun everyBearingButtonReportsItsExplicitDirection() = runComposeUiTest {
|
||||||
|
val bar = showBar()
|
||||||
|
|
||||||
|
Bearing.entries.forEach { bearing ->
|
||||||
|
onNodeWithText(bearing.name).performClick()
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(Bearing.entries.map { it.degrees }, bar.explicitQtfDirections)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun deselectingABearingDoesNotReportAnotherExplicitDirection() = runComposeUiTest {
|
||||||
|
val bar = showBar()
|
||||||
|
|
||||||
|
onNodeWithText("NE").performClick()
|
||||||
|
onNodeWithText("NE").performClick()
|
||||||
|
|
||||||
|
assertFalse(bar.filters.qtfEnabled)
|
||||||
|
assertEquals(listOf(45.0), bar.explicitQtfDirections)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun defaultManualHeadingMakesNorthEastVisibleToTheMapObserverWhileFilterIsOff() = runComposeUiTest {
|
||||||
|
val prefs = ChatPreferences(directory.resolve("preferences.xml"))
|
||||||
|
val filters = StationFilterState()
|
||||||
|
val mapHeading = ObservedValue(prefs.actualQTF)
|
||||||
|
try {
|
||||||
|
showTab {
|
||||||
|
StationFilterBar(
|
||||||
|
filters = filters,
|
||||||
|
activeBands = EnumSet.of(Band.B_144),
|
||||||
|
reachability = ReachabilityState(EnumSet.of(Band.B_144)),
|
||||||
|
onChanged = {},
|
||||||
|
onQtfDirectionChanged = { applyExplicitQtfHeading(prefs, it) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
assertFalse(filters.qtfEnabled)
|
||||||
|
onNodeWithText("NE").performClick()
|
||||||
|
waitForIdle()
|
||||||
|
|
||||||
|
assertEquals(45.0, prefs.actualQTF.get(), 0.0001)
|
||||||
|
assertEquals(45.0, requireNotNull(mapHeading.value), 0.0001)
|
||||||
|
assertEquals(135.0, prefs.stn_qtfDefault, 0.0001)
|
||||||
|
} finally {
|
||||||
|
mapHeading.release()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun resetAndQtfCheckboxChangesDoNotReportAnExplicitDirection() = runComposeUiTest {
|
||||||
|
val bar = showBar()
|
||||||
|
toggle("Show only QTF:")
|
||||||
|
onNodeWithText("Reset filters").performClick()
|
||||||
|
|
||||||
|
assertTrue(bar.explicitQtfDirections.isEmpty())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun invalidManualQtfEntriesAreNotReported() = runComposeUiTest {
|
||||||
|
val bar = showBar()
|
||||||
|
|
||||||
|
listOf("NaN", "Infinity", "-1", "360.1").forEach { type("Show only QTF:", it) }
|
||||||
|
|
||||||
|
assertTrue(bar.explicitQtfDirections.isEmpty())
|
||||||
|
assertEquals(0.0, bar.filters.qtfDegrees, 0.0001)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun reachabilityBandChangesDoNotCalculateUntilTheButtonIsClicked() = runComposeUiTest {
|
||||||
|
val filters = StationFilterState()
|
||||||
|
val station = kst4contest.model.ChatMember()
|
||||||
|
var calculations = 0
|
||||||
|
val reachability = ReachabilityState(
|
||||||
|
activeBands = EnumSet.of(Band.B_144, Band.B_432),
|
||||||
|
resolveAutoBand = { Band.B_144 },
|
||||||
|
selectedStation = { station },
|
||||||
|
calculate = { member, band ->
|
||||||
|
assertEquals(station, member)
|
||||||
|
assertEquals(Band.B_432, band)
|
||||||
|
calculations++
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
showTab {
|
||||||
|
StationFilterBar(
|
||||||
|
filters = filters,
|
||||||
|
activeBands = EnumSet.of(Band.B_144, Band.B_432),
|
||||||
|
reachability = reachability,
|
||||||
|
onChanged = { },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
onNodeWithText("Reachability").assertIsDisplayed()
|
||||||
|
onNodeWithText("Auto").performClick()
|
||||||
|
awaitNode(inPopup("432")).performClick()
|
||||||
|
assertEquals(0, calculations)
|
||||||
|
|
||||||
|
onNodeWithText("Calc selected").performClick()
|
||||||
|
assertEquals(1, calculations)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun theMinimumQrbControlsWriteTheMinimumFilterOnly() = runComposeUiTest {
|
fun theMinimumQrbControlsWriteTheMinimumFilterOnly() = runComposeUiTest {
|
||||||
val bar = showBar()
|
val bar = showBar()
|
||||||
@@ -133,7 +255,12 @@ class StationFilterBarScreenTest {
|
|||||||
setContent {
|
setContent {
|
||||||
Kst4ContestTheme(darkMode = false, baseFontSizeSp = 12f) {
|
Kst4ContestTheme(darkMode = false, baseFontSizeSp = 12f) {
|
||||||
Box(Modifier.width(width)) {
|
Box(Modifier.width(width)) {
|
||||||
StationFilterBar(filters = filters, activeBands = EnumSet.of(Band.B_144), onChanged = {})
|
StationFilterBar(
|
||||||
|
filters = filters,
|
||||||
|
activeBands = EnumSet.of(Band.B_144),
|
||||||
|
reachability = ReachabilityState(EnumSet.of(Band.B_144)),
|
||||||
|
onChanged = {},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,6 +272,10 @@ class StationFilterBarScreenTest {
|
|||||||
onNodeWithText(maxLabel),
|
onNodeWithText(maxLabel),
|
||||||
onNodeWithText(minLabel),
|
onNodeWithText(minLabel),
|
||||||
onNodeWithText("Show only QTF:"),
|
onNodeWithText("Show only QTF:"),
|
||||||
|
onNodeWithText("Inactive stations"),
|
||||||
|
onNodeWithText("Only new grids"),
|
||||||
|
onNodeWithText("AS next 5m"),
|
||||||
|
onNodeWithText("Calc selected"),
|
||||||
fieldBeside(maxLabel),
|
fieldBeside(maxLabel),
|
||||||
fieldBeside(minLabel),
|
fieldBeside(minLabel),
|
||||||
)
|
)
|
||||||
@@ -154,4 +285,61 @@ class StationFilterBarScreenTest {
|
|||||||
assertTrue(right <= limit + 0.5f, "a control ends at $right px, beyond the $limit px wide bar")
|
assertTrue(right <= limit + 0.5f, "a control ends at $right px, beyond the $limit px wide bar")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun filterControlsShareOneHeightAndBearingsShareOneCompactWidth() = runComposeUiTest {
|
||||||
|
showBar()
|
||||||
|
|
||||||
|
val fieldHeight = fieldBeside(maxLabel).fetchSemanticsNode().boundsInRoot.height
|
||||||
|
val checkboxHeight = checkBeside(maxLabel).fetchSemanticsNode().boundsInRoot.height
|
||||||
|
val findFieldHeight = onNodeWithText("Find...").fetchSemanticsNode().boundsInRoot.height
|
||||||
|
val controlHeights = listOf("Reset filters", "N", "Auto", "Calc selected")
|
||||||
|
.map { onNodeWithText(it).fetchSemanticsNode().boundsInRoot.height } +
|
||||||
|
listOf(fieldHeight, checkboxHeight, findFieldHeight)
|
||||||
|
assertTrue(
|
||||||
|
controlHeights.max() - controlHeights.min() <= 1f,
|
||||||
|
"filter control heights differ: $controlHeights",
|
||||||
|
)
|
||||||
|
|
||||||
|
val bearingWidths = Bearing.entries
|
||||||
|
.map { onNodeWithText(it.name).fetchSemanticsNode().boundsInRoot.width }
|
||||||
|
assertTrue(
|
||||||
|
bearingWidths.max() - bearingWidths.min() <= 1f,
|
||||||
|
"bearing widths differ: $bearingWidths",
|
||||||
|
)
|
||||||
|
val expectedWidth = with(density) { Density.DIRECTION_BUTTON_WIDTH.toPx() }
|
||||||
|
assertTrue(
|
||||||
|
bearingWidths.all { abs(it - expectedWidth) <= 1f },
|
||||||
|
"bearing buttons are not $expectedWidth px wide: $bearingWidths",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun functionalFilterGroupsRemainDistinctAndInsideANarrowBar() = runComposeUiTest {
|
||||||
|
val width = 300.dp
|
||||||
|
setContent {
|
||||||
|
Kst4ContestTheme(darkMode = true, baseFontSizeSp = 12f) {
|
||||||
|
Box(Modifier.width(width)) {
|
||||||
|
StationFilterBar(
|
||||||
|
filters = StationFilterState(),
|
||||||
|
activeBands = EnumSet.of(Band.B_144),
|
||||||
|
reachability = ReachabilityState(EnumSet.of(Band.B_144)),
|
||||||
|
onChanged = {},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val limit = with(density) { width.toPx() }
|
||||||
|
listOf(
|
||||||
|
FILTER_DISTANCE_GROUP_TAG,
|
||||||
|
FILTER_DIRECTION_GROUP_TAG,
|
||||||
|
FILTER_STATION_GROUP_TAG,
|
||||||
|
FILTER_WORKED_GROUP_TAG,
|
||||||
|
FILTER_PROPAGATION_GROUP_TAG,
|
||||||
|
).forEach { tag ->
|
||||||
|
val bounds = onNodeWithTag(tag).assertIsDisplayed().fetchSemanticsNode().boundsInRoot
|
||||||
|
assertTrue(bounds.left >= 0f && bounds.right <= limit + 0.5f, "$tag crosses the filter bar")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loaded 100 of 269 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user