├── .github ├── PULL_REQUEST_TEMPLATE.md ├── release.yml └── workflows │ ├── manual_release.yml │ ├── release.yml │ ├── snapshot.yml │ └── tests.yml ├── .gitignore ├── LICENSE ├── README.md ├── app ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── telefonica │ │ └── tweaks │ │ └── demo │ │ ├── MainActivity.kt │ │ ├── TweakDemoApplication.kt │ │ └── theme │ │ ├── Color.kt │ │ └── Theme.kt │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-mdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-xhdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-xxhdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-xxxhdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ └── values │ ├── colors.xml │ ├── strings.xml │ └── themes.xml ├── build.gradle ├── detekt.yml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── build.gradle ├── consumer-rules.pro ├── proguard-rules.pro └── src │ ├── enabled │ ├── java │ │ └── com │ │ │ └── telefonica │ │ │ └── tweaks │ │ │ ├── Tweaks.kt │ │ │ ├── TweaksTheme.kt │ │ │ ├── data │ │ │ ├── TweaksDataStore.kt │ │ │ └── TweaksRepository.kt │ │ │ ├── di │ │ │ ├── TweaksComponent.kt │ │ │ └── TweaksModule.kt │ │ │ ├── domain │ │ │ └── TweaksBusinessLogic.kt │ │ │ └── ui │ │ │ ├── EditableTweakEntryViewModel.kt │ │ │ ├── ReadOnlyTweakEntryViewModel.kt │ │ │ ├── TweakComponents.kt │ │ │ ├── TweakGroupViewModel.kt │ │ │ └── theme │ │ │ ├── Color.kt │ │ │ └── Type.kt │ └── res │ │ └── font │ │ ├── eczar_regular.ttf │ │ ├── eczar_semibold.ttf │ │ ├── robotocondensed_bold.ttf │ │ ├── robotocondensed_light.ttf │ │ └── robotocondensed_regular.ttf │ ├── main │ ├── AndroidManifest.xml │ └── java │ │ └── com │ │ └── telefonica │ │ └── tweaks │ │ ├── TweaksContract.kt │ │ └── domain │ │ └── tweakModels.kt │ ├── noop │ └── java │ │ └── com │ │ └── telefonica │ │ └── tweaks │ │ ├── Tweaks.kt │ │ └── ui │ │ └── theme │ │ └── Theme.kt │ └── testEnabled │ └── java │ └── com │ └── telefonica │ └── tweaks │ └── domain │ └── TweaksBusinessLogicTest.kt ├── mavencentral.gradle ├── objects ├── publish_maven_central.gradle └── settings.gradle /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### :goal_net: What's the goal? 2 | _Provide a description of the overall goal. The description in the Jira ticket may help._ 3 | 4 | ### :construction: How do we do it? 5 | _Provide a description of the implementation. A list of steps would be ideal._ 6 | * _Step 1_ 7 | * _Step 2_ 8 | * _Step 3_ 9 | 10 | ### :blue_book: Documentation changes? 11 | - [ ] No docs to update nor create 12 | 13 | ### :test_tube: How can I test this? 14 | _If it cannot be tested explain why._ 15 | - [ ] 🖼️ Screenshots/Videos 16 | - [ ] ... 17 | -------------------------------------------------------------------------------- /.github/release.yml: -------------------------------------------------------------------------------- 1 | changelog: 2 | exclude: 3 | labels: 4 | - ignore-for-release 5 | authors: 6 | - tuentisre 7 | categories: 8 | - title: Breaking Changes 🛠 9 | labels: 10 | - breaking-change 11 | - title: New Features 🎉 12 | labels: 13 | - enhancement 14 | - new-feature 15 | - title: Other Changes 16 | labels: 17 | - "*" 18 | -------------------------------------------------------------------------------- /.github/workflows/manual_release.yml: -------------------------------------------------------------------------------- 1 | name: "Release manually" 2 | on: 3 | workflow_dispatch: 4 | inputs: 5 | libraryVersion: 6 | description: "Library version" 7 | required: true 8 | jobs: 9 | manual-release: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout repo 13 | uses: actions/checkout@v2 14 | 15 | - name: Set up JDK 17 16 | uses: actions/setup-java@v3 17 | with: 18 | distribution: 'temurin' 19 | java-version: '17' 20 | 21 | - name: Build library 22 | run: 'bash ./gradlew clean :library:assembleRelease' 23 | 24 | - name: Release library manually 25 | env: 26 | MOBILE_MAVENCENTRAL_USER: ${{ secrets.MOBILE_MAVENCENTRAL_USER }} 27 | MOBILE_MAVENCENTRAL_PASSWORD: ${{ secrets.MOBILE_MAVENCENTRAL_PASSWORD }} 28 | ORG_GRADLE_PROJECT_signingKey: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEY }} 29 | ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGPASSWORD }} 30 | ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEYID }} 31 | run: "bash ./gradlew publishReleasePublicationToSonatypeRepository -DLIBRARY_VERSION=${{ github.event.inputs.libraryVersion }} publishNoopPublicationToSonatypeRepository -DLIBRARY_VERSION=${{ github.event.inputs.libraryVersion }}" 32 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: "Create release" 2 | on: 3 | release: 4 | types: [published] 5 | jobs: 6 | release: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: Checkout repo 10 | uses: actions/checkout@v2 11 | 12 | - name: Set up JDK 17 13 | uses: actions/setup-java@v3 14 | with: 15 | distribution: 'temurin' 16 | java-version: '17' 17 | 18 | - name: Build library 19 | run: 'bash ./gradlew clean :library:assembleRelease' 20 | 21 | - name: Release library 22 | env: 23 | MOBILE_MAVENCENTRAL_USER: ${{ secrets.MOBILE_MAVENCENTRAL_USER }} 24 | MOBILE_MAVENCENTRAL_PASSWORD: ${{ secrets.MOBILE_MAVENCENTRAL_PASSWORD }} 25 | ORG_GRADLE_PROJECT_signingKey: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEY }} 26 | ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGPASSWORD }} 27 | ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEYID }} 28 | run: "bash ./gradlew publishReleasePublicationToSonatypeRepository -DLIBRARY_VERSION=${{ github.event.release.tag_name }} publishNoopPublicationToSonatypeRepository -DLIBRARY_VERSION=${{ github.event.release.tag_name }} --max-workers 1 closeAndReleaseStagingRepository" 29 | 30 | - name: Prepare release notes 31 | run: | 32 | RELEASE_BODY=$(jq -Rs . <<'EOF' 33 | ${{ github.event.release.body }} 34 | EOF 35 | ) 36 | echo "FORMATTED_BODY=${RELEASE_BODY}" >> $GITHUB_ENV 37 | 38 | - name: Send Teams notification 39 | uses: fjogeleit/http-request-action@v1.16.4 40 | with: 41 | url: ${{ secrets.ANDROID_LIBRARIES_TEAMS_WEBHOOK }} 42 | method: 'POST' 43 | data: | 44 | { 45 | "type": "message", 46 | "attachments": [ 47 | { 48 | "contentType": "application/vnd.microsoft.card.adaptive", 49 | "content": { 50 | "type": "AdaptiveCard", 51 | "version": "1.5", 52 | "body": [ 53 | { 54 | "type": "ColumnSet", 55 | "columns": [ 56 | { 57 | "type": "Column", 58 | "width": "auto", 59 | "items": [ 60 | { 61 | "type": "Image", 62 | "url": "https://raw.githubusercontent.com/Skitionek/notify-microsoft-teams/master/icons/success.png", 63 | "width": "56px", 64 | "height": "56px", 65 | "style": "RoundedCorners" 66 | } 67 | ] 68 | }, 69 | { 70 | "type": "Column", 71 | "width": "stretch", 72 | "items": [ 73 | { 74 | "type": "TextBlock", 75 | "text": "New Tweaks version published ${{ github.event.release.tag_name }}", 76 | "wrap": true, 77 | "weight": "Bolder", 78 | "style": "heading" 79 | } 80 | ] 81 | } 82 | ] 83 | }, 84 | { 85 | "type": "TextBlock", 86 | "text": ${{ env.FORMATTED_BODY }}, 87 | "wrap": true 88 | }, 89 | { 90 | "type": "ActionSet", 91 | "actions": [ 92 | { 93 | "type": "Action.OpenUrl", 94 | "title": "Open release", 95 | "url": "${{ github.event.release.html_url }}" 96 | } 97 | ] 98 | } 99 | ], 100 | "$schema": "https://adaptivecards.io/schemas/adaptive-card.json" 101 | } 102 | } 103 | ] 104 | } -------------------------------------------------------------------------------- /.github/workflows/snapshot.yml: -------------------------------------------------------------------------------- 1 | name: "Snapshot" 2 | on: 3 | workflow_dispatch: 4 | inputs: 5 | snapshotVersion: 6 | description: "Snapshot version" 7 | required: true 8 | jobs: 9 | snapshot: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout repo 13 | uses: actions/checkout@v2 14 | 15 | - name: Set up JDK 17 16 | uses: actions/setup-java@v3 17 | with: 18 | distribution: 'temurin' 19 | java-version: '17' 20 | 21 | - name: Build library 22 | run: 'bash ./gradlew clean :library:assembleRelease' 23 | 24 | - name: Release snapshot 25 | env: 26 | MOBILE_MAVENCENTRAL_USER: ${{ secrets.MOBILE_MAVENCENTRAL_USER }} 27 | MOBILE_MAVENCENTRAL_PASSWORD: ${{ secrets.MOBILE_MAVENCENTRAL_PASSWORD }} 28 | ORG_GRADLE_PROJECT_signingKey: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEY }} 29 | ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGPASSWORD }} 30 | ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEYID }} 31 | run: "bash ./gradlew publishReleasePublicationToSonatypeRepository -DSNAPSHOT_VERSION=${{ github.event.inputs.snapshotVersion }} publishNoopPublicationToSonatypeRepository -DSNAPSHOT_VERSION=${{ github.event.inputs.snapshotVersion }}" 32 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | on: pull_request 3 | jobs: 4 | test: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - name: Checkout 8 | uses: actions/checkout@v3 9 | 10 | - name: Set up JDK 17 11 | uses: actions/setup-java@v3 12 | with: 13 | distribution: 'temurin' 14 | java-version: '17' 15 | 16 | - name: Setup Gradle 17 | uses: gradle/gradle-build-action@v2 18 | 19 | - name: Assemble release 20 | run: ./gradlew assembleRelease 21 | 22 | - name: Run checks 23 | if: success() || failure() 24 | run: ./gradlew check 25 | 26 | - name: Run Detekt 27 | if: success() || failure() 28 | run: ./gradlew detekt 29 | 30 | - name: Run Lint 31 | if: success() || failure() 32 | run: ./gradlew lint 33 | 34 | - name: Upload Detekt results 35 | uses: github/codeql-action/upload-sarif@v2 36 | if: success() || failure() 37 | with: 38 | sarif_file: build/reports/detekt/detekt-report.sarif 39 | category: detekt 40 | 41 | - name: Upload Lint results 42 | uses: github/codeql-action/upload-sarif@v2 43 | if: success() || failure() 44 | with: 45 | sarif_file: app/build/reports/lint-results-debug.sarif 46 | category: lint -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | syntax: glob 2 | 3 | local.properties 4 | .idea/* 5 | !.idea/codeStyles 6 | .DS_Store 7 | bin/ 8 | gen/ 9 | .gradle/ 10 | build/ 11 | */.idea 12 | *.iml -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | 4 | 5 |

6 | 7 |

8 | 9 |

10 | 11 | A customizable debug screen to view and edit flags that can be used for development in **Jetpack Compose** applications 12 | 13 | 14 | 15 |

16 | 17 |

18 | 19 | 20 | To include the library add to your app's `build.gradle`: 21 | 22 | ```gradle 23 | implementation 'com.telefonica:tweaks:{version}' 24 | ``` 25 | 26 | Or, in case you want to don't add the library in release builds: 27 | ```gradle 28 | debugImplementation 'com.telefonica:tweaks:{version}' 29 | releaseImplementation 'com.telefonica:tweaks-no-op:{version}' 30 | ``` 31 | 32 | Then initialize the library in your app's `onCreate`: 33 | ```kotlin 34 | override fun onCreate() { 35 | super.onCreate() 36 | Tweaks.init(context, demoTweakGraph()) 37 | } 38 | ``` 39 | 40 | where `demoTweakGraph` is the structure you want to be rendered: 41 | ```kotlin 42 | private fun demoTweakGraph() = tweaksGraph { 43 | cover("Tweaks") { 44 | label("Current user ID:") { flowOf("80057182") } 45 | label("Current IP:") { flowOf("192.168.1.127") } 46 | label("Current IP (public):") { flowOf("80.68.1.92") } 47 | label("Timestamp:") { timestampState } 48 | dropDownMenu( 49 | key = "spinner1", 50 | name = "Spinner example", 51 | values = listOf("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"), 52 | defaultValue = flowOf("Monday") 53 | ) 54 | } 55 | category("Statistics") { 56 | group("Group 1") { 57 | label( 58 | name = "Current timestamp", 59 | ) { 60 | timestampState 61 | } 62 | editableString( 63 | key = "value1", 64 | name = "Value 1", 65 | ) 66 | editableBoolean( 67 | key = "value2", 68 | name = "Value 2", 69 | defaultValue = true, 70 | ) 71 | editableLong( 72 | key = "value4", 73 | name = "Value 4", 74 | defaultValue = 42L, 75 | ) 76 | 77 | button( 78 | name = "Demo button" 79 | ) { 80 | Toast.makeText(this@TweakDemoApplication, "Demo button", Toast.LENGTH_LONG) 81 | .show() 82 | } 83 | routeButton( 84 | name = "Custom screen button", 85 | route = "custom-screen" 86 | ) 87 | customNavigationButton( 88 | name = "Another custom screen button", 89 | navigation = { navController -> 90 | navController.navigate("custom-screen") 91 | } 92 | ) 93 | } 94 | } 95 | } 96 | ``` 97 | 98 | And then, in your NavHost setup, use the extension function `NavGraphBuilder.addTweakGraph` to fill the navigation graph with the tweak components: 99 | ```kotlin 100 | @Composable 101 | private fun DemoNavHost( 102 | navController: NavHostController, 103 | initialScreen: String, 104 | modifier: Modifier = Modifier, 105 | ) { 106 | NavHost( 107 | navController = navController, 108 | startDestination = initialScreen, 109 | modifier = modifier, 110 | ) { 111 | addTweakGraph( 112 | navController = navController, 113 | ) 114 | } 115 | } 116 | ``` 117 | 118 | ## How to build the TweaksGraph 119 | You can use the DSL to create your own graph. Please note that a graph is composed by: 120 | * A main group of tweaks (*Optional*) 121 | * A list of categories 122 | 123 | The categories are separate screens and are composed of groups of tweaks. You can use each category to separate debug elements of your app by feature or key components, for example: (chat, webviews, login, stats, etc...) 124 | 125 | The group of tweaks are a shown inside each category screen, they are composed of tweaks and can represent configuration settings that can be grouped together, for example: endpoints of your API. 126 | 127 | And finally, the tweaks are the configurable elements. Currently we support these ones: 128 | 129 | ```kotlin 130 | button( 131 | name: String, 132 | action: () -> Unit 133 | ) 134 | ``` 135 | Used to display a button that performs an action 136 | 137 | ```kotlin 138 | fun routeButton( 139 | name: String, 140 | route: String, 141 | ) 142 | ``` 143 | Similar, but this button navigates directly to a route of the NavHost, check [custom screens section](#custom-screens) for more info 144 | 145 | ```kotlin 146 | customNavigationButton( 147 | name = "Another custom screen button", 148 | navigation = { navController -> 149 | navController.navigate("custom-screen") { 150 | popUpTo("another-custom-screen") { 151 | inclusive = true 152 | } 153 | } 154 | } 155 | ) 156 | ``` 157 | Just like `routeButton`, but it allows to pass a lambda which receives a `NavController` so more complex navigations can be performed. 158 | 159 | ```kotlin 160 | fun label( 161 | name: String, 162 | value: () -> Flow, 163 | ) 164 | ``` 165 | A non editable text 166 | 167 | ```kotlin 168 | fun editableString( 169 | key: String, 170 | name: String, 171 | defaultValue: Flow? = null, 172 | ) 173 | ``` 174 | 175 | ```kotlin 176 | fun editableString( 177 | key: String, 178 | name: String, 179 | defaultValue: String, 180 | ) 181 | ``` 182 | 183 | An editable text 184 | 185 | ```kotlin 186 | fun editableBoolean( 187 | key: String, 188 | name: String, 189 | defaultValue: Flow? = null, 190 | ) 191 | ``` 192 | 193 | ```kotlin 194 | fun editableBoolean( 195 | key: String, 196 | name: String, 197 | defaultValue: Boolean, 198 | ) 199 | ``` 200 | An editable boolean 201 | ```kotlin 202 | fun editableInt( 203 | key: String, 204 | name: String, 205 | defaultValue: Flow? = null, 206 | ) 207 | ``` 208 | 209 | ```kotlin 210 | fun editableInt( 211 | key: String, 212 | name: String, 213 | defaultValue: Int, 214 | ) 215 | ``` 216 | An editable Int 217 | ```kotlin 218 | fun editableLong( 219 | key: String, 220 | name: String, 221 | defaultValue: Flow? = null, 222 | ) 223 | ``` 224 | 225 | ```kotlin 226 | fun editableLong( 227 | key: String, 228 | name: String, 229 | defaultValue: Long, 230 | ) 231 | ``` 232 | An editable Long 233 | 234 | ```kotlin 235 | fun dropDownMenu( 236 | key: String, 237 | name: String, 238 | values: List, 239 | defaultValue: Flow, 240 | ) 241 | ``` 242 | A DropDownMenu 243 | Please review the app module for configuration examples. 244 | 245 | ## Reset Button 246 | When a group of tweaks is created, only if there is at least one editable tweak, a reset button will be automatically added. 247 | If you do not want the reset button to be added automatically, there is a parameter in group node `withClearButton` that can be set. 248 | ```kotlin 249 | group( 250 | title = "Group Title", 251 | withClearButton = true 252 | ) { 253 | // Your tweaks 254 | } 255 | ``` 256 | 257 | ## Custom screens: 258 | You can add your custom screens to the TweaksGraph by using the `customComposableScreens` parameter of `addTweakGraph` function, for example: 259 | ```kotlin 260 | addTweakGraph( 261 | navController = navController, 262 | ) { 263 | composable(route = "custom-screen") { 264 | Column( 265 | modifier = Modifier 266 | .fillMaxSize() 267 | .padding(16.dp), 268 | verticalArrangement = Arrangement.Center, 269 | horizontalAlignment = Alignment.CenterHorizontally, 270 | ) { 271 | Text("Custom screen") 272 | } 273 | } 274 | } 275 | ``` 276 | 277 | ## Shake gesture support: 278 | 279 | The tweaks can be opened when the user shakes the device. To achieve this, you can either add the following to your navigation controller: 280 | ```kotlin 281 | navController.navigateToTweaksOnShake() 282 | ``` 283 | or call: 284 | ```kotlin 285 | NavigateToTweaksOnShake(onOpenTweaks: () -> Unit) 286 | ``` 287 | and handle the navigation action yourself. 288 | 289 | And also, optionally 290 | ```xml 291 | 292 | ``` 293 | to your `AndroidManifest.xml` 294 | 295 | ## Special thanks to contributors: 296 | * [Yamal Al Mahamid](https://github.com/yamal-coding) 297 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | } 5 | 6 | android { 7 | namespace "com.telefonica.tweaks.demo" 8 | compileSdk 34 9 | 10 | defaultConfig { 11 | applicationId "com.telefonica.tweaks.demo" 12 | minSdk 21 13 | targetSdk 34 14 | versionCode 1 15 | versionName "1.0" 16 | 17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 18 | vectorDrawables { 19 | useSupportLibrary true 20 | } 21 | 22 | missingDimensionStrategy 'tweaksMode', 'enabled' 23 | } 24 | 25 | buildTypes { 26 | release { 27 | minifyEnabled false 28 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 29 | } 30 | } 31 | compileOptions { 32 | sourceCompatibility JavaVersion.VERSION_17 33 | targetCompatibility JavaVersion.VERSION_17 34 | } 35 | kotlinOptions { 36 | jvmTarget = '17' 37 | } 38 | buildFeatures { 39 | compose true 40 | } 41 | composeOptions { 42 | kotlinCompilerExtensionVersion compose_compiler_version 43 | } 44 | packagingOptions { 45 | resources { 46 | excludes += '/META-INF/{AL2.0,LGPL2.1}' 47 | } 48 | } 49 | 50 | lint { 51 | sarifReport true 52 | } 53 | namespace 'com.telefonica.tweaks.demo' 54 | } 55 | 56 | dependencies { 57 | 58 | implementation project(':library') 59 | implementation 'androidx.core:core-ktx:1.13.0' 60 | implementation 'androidx.appcompat:appcompat:1.6.1' 61 | implementation 'com.google.android.material:material:1.11.0' 62 | 63 | implementation "androidx.compose.ui:ui:$compose_version" 64 | implementation "androidx.compose.material3:material3:$compose_material3_version" 65 | implementation "androidx.compose.ui:ui-tooling-preview:$compose_version" 66 | implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.7.0' 67 | implementation 'androidx.activity:activity-compose:1.9.0' 68 | 69 | implementation("androidx.navigation:navigation-compose:2.7.7") 70 | 71 | testImplementation 'junit:junit:4.13.2' 72 | androidTestImplementation 'androidx.test.ext:junit:1.1.5' 73 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' 74 | androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version" 75 | debugImplementation "androidx.compose.ui:ui-tooling:$compose_version" 76 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/telefonica/tweaks/demo/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.telefonica.tweaks.demo 2 | 3 | import android.os.Bundle 4 | import androidx.activity.ComponentActivity 5 | import androidx.activity.SystemBarStyle 6 | import androidx.activity.compose.setContent 7 | import androidx.activity.enableEdgeToEdge 8 | import androidx.compose.foundation.background 9 | import androidx.compose.foundation.layout.Arrangement 10 | import androidx.compose.foundation.layout.Column 11 | import androidx.compose.foundation.layout.fillMaxSize 12 | import androidx.compose.foundation.layout.padding 13 | import androidx.compose.material3.Button 14 | import androidx.compose.material3.MaterialTheme 15 | import androidx.compose.material3.Surface 16 | import androidx.compose.material3.Text 17 | import androidx.compose.runtime.Composable 18 | import androidx.compose.ui.Alignment 19 | import androidx.compose.ui.Modifier 20 | import androidx.compose.ui.graphics.Color 21 | import androidx.compose.ui.unit.dp 22 | import androidx.navigation.NavHostController 23 | import androidx.navigation.compose.NavHost 24 | import androidx.navigation.compose.composable 25 | import androidx.navigation.compose.rememberNavController 26 | import com.telefonica.tweaks.Tweaks.Companion.TWEAKS_NAVIGATION_ENTRYPOINT 27 | import com.telefonica.tweaks.addTweakGraph 28 | import com.telefonica.tweaks.demo.theme.DebugTweaksTheme 29 | import com.telefonica.tweaks.navigateToTweaksOnShake 30 | 31 | class MainActivity : ComponentActivity() { 32 | 33 | override fun onCreate(savedInstanceState: Bundle?) { 34 | enableEdgeToEdge( 35 | statusBarStyle = SystemBarStyle.dark(android.graphics.Color.TRANSPARENT), 36 | navigationBarStyle = SystemBarStyle.dark(android.graphics.Color.TRANSPARENT) 37 | ) 38 | 39 | super.onCreate(savedInstanceState) 40 | 41 | setContent { 42 | DebugTweaksTheme { 43 | val navController = rememberNavController() 44 | navController.navigateToTweaksOnShake() 45 | Surface(color = MaterialTheme.colorScheme.background) { 46 | DemoNavHost( 47 | navController = navController, 48 | initialScreen = "main-screen", 49 | ) 50 | } 51 | } 52 | } 53 | } 54 | 55 | @Composable 56 | private fun DemoNavHost( 57 | navController: NavHostController, 58 | initialScreen: String, 59 | modifier: Modifier = Modifier, 60 | ) { 61 | NavHost( 62 | navController = navController, 63 | startDestination = initialScreen, 64 | modifier = modifier, 65 | ) { 66 | composable( 67 | route = "main-screen", 68 | ) { 69 | Column( 70 | modifier = Modifier 71 | .fillMaxSize() 72 | .background(Color.White) 73 | .padding(16.dp), 74 | verticalArrangement = Arrangement.Center, 75 | horizontalAlignment = Alignment.CenterHorizontally, 76 | ) { 77 | Button( 78 | onClick = { navController.navigate(TWEAKS_NAVIGATION_ENTRYPOINT) } 79 | ) { 80 | Text( 81 | text = "Tweaks", 82 | color = Color.White 83 | ) 84 | } 85 | } 86 | } 87 | addTweakGraph( 88 | navController = navController, 89 | ) { 90 | composable(route = "custom-screen") { 91 | Column( 92 | modifier = Modifier 93 | .fillMaxSize() 94 | .padding(16.dp), 95 | verticalArrangement = Arrangement.Center, 96 | horizontalAlignment = Alignment.CenterHorizontally, 97 | ) { 98 | Text("Custom screen") 99 | } 100 | } 101 | } 102 | } 103 | } 104 | } -------------------------------------------------------------------------------- /app/src/main/java/com/telefonica/tweaks/demo/TweakDemoApplication.kt: -------------------------------------------------------------------------------- 1 | package com.telefonica.tweaks.demo 2 | 3 | import android.app.Application 4 | import android.widget.Toast 5 | import com.telefonica.tweaks.Tweaks 6 | import com.telefonica.tweaks.domain.tweaksGraph 7 | import kotlinx.coroutines.delay 8 | import kotlinx.coroutines.flow.flow 9 | import kotlinx.coroutines.flow.flowOf 10 | 11 | class TweakDemoApplication : Application() { 12 | override fun onCreate() { 13 | super.onCreate() 14 | Tweaks.init(this, demoTweakGraph()) 15 | } 16 | 17 | var timestampState = flow { 18 | while (true) { 19 | emit("${System.currentTimeMillis() / 1000}") 20 | delay(1000) 21 | } 22 | } 23 | 24 | private fun demoTweakGraph() = tweaksGraph { 25 | cover("Tweaks") { 26 | label("Current user ID:") { flowOf("80057182") } 27 | label("Current IP:") { flowOf("192.168.1.127") } 28 | label("Current IP (public):") { flowOf("80.68.1.92") } 29 | label("Timestamp:") { timestampState } 30 | dropDownMenu( 31 | key = "spinner1", 32 | name = "Spinner example", 33 | values = listOf("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"), 34 | defaultValue = flowOf("Monday") 35 | ) 36 | } 37 | category("Statistics") { 38 | group("Group 1") { 39 | label( 40 | name = "Current timestamp", 41 | ) { 42 | timestampState 43 | } 44 | editableString( 45 | key = "value1", 46 | name = "RSSI value returned by the operating system", 47 | ) 48 | editableBoolean( 49 | key = "value2", 50 | name = "Value 2", 51 | defaultValue = true, 52 | ) 53 | editableLong( 54 | key = "value4", 55 | name = "Value 4", 56 | defaultValue = 42L, 57 | ) 58 | 59 | button( 60 | name = "Demo button" 61 | ) { 62 | Toast.makeText(this@TweakDemoApplication, "Demo button", Toast.LENGTH_LONG) 63 | .show() 64 | } 65 | routeButton( 66 | name = "Custom screen button", 67 | route = "custom-screen" 68 | ) 69 | customNavigationButton( 70 | name = "Another custom screen button", 71 | navigation = { navController -> 72 | navController.navigate("custom-screen") 73 | } 74 | ) 75 | } 76 | } 77 | category("API") {} 78 | category("Chat") {} 79 | category("Crash reporting") {} 80 | } 81 | } -------------------------------------------------------------------------------- /app/src/main/java/com/telefonica/tweaks/demo/theme/Color.kt: -------------------------------------------------------------------------------- 1 | package com.telefonica.tweaks.demo.theme 2 | 3 | import androidx.compose.ui.graphics.Color 4 | import androidx.compose.material3.darkColorScheme 5 | 6 | val TweaksColorPalette = darkColorScheme( 7 | primary = Color.Blue, 8 | inversePrimary = Color.Blue, 9 | surface = Color.Black, 10 | onSurface = Color.Black, 11 | background = Color.Black, 12 | onBackground = Color.Black 13 | ) 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/telefonica/tweaks/demo/theme/Theme.kt: -------------------------------------------------------------------------------- 1 | package com.telefonica.tweaks.demo.theme 2 | 3 | import androidx.compose.material3.MaterialTheme 4 | import androidx.compose.runtime.Composable 5 | import com.telefonica.tweaks.ui.theme.TweaksTypography 6 | 7 | @Composable 8 | fun DebugTweaksTheme( 9 | content: @Composable () -> Unit 10 | ) { 11 | MaterialTheme(colorScheme = TweaksColorPalette, typography = TweaksTypography, content = content) 12 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telefonica/tweaks/93082eece7221fc50f3cf9d02a05a2e27d618186/app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telefonica/tweaks/93082eece7221fc50f3cf9d02a05a2e27d618186/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telefonica/tweaks/93082eece7221fc50f3cf9d02a05a2e27d618186/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telefonica/tweaks/93082eece7221fc50f3cf9d02a05a2e27d618186/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telefonica/tweaks/93082eece7221fc50f3cf9d02a05a2e27d618186/app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telefonica/tweaks/93082eece7221fc50f3cf9d02a05a2e27d618186/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telefonica/tweaks/93082eece7221fc50f3cf9d02a05a2e27d618186/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telefonica/tweaks/93082eece7221fc50f3cf9d02a05a2e27d618186/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telefonica/tweaks/93082eece7221fc50f3cf9d02a05a2e27d618186/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telefonica/tweaks/93082eece7221fc50f3cf9d02a05a2e27d618186/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FF1EB980 4 | #FF000000 5 | #FFFFFFFF 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Tweaks Demo 3 | -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | 17 | 21 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | buildscript { 3 | ext { 4 | compose_compiler_version = '1.5.12' 5 | compose_version = '1.6.6' 6 | compose_material3_version = '1.3.1' 7 | 8 | kotlin_version = '1.9.23' 9 | dagger_version = "2.51.1" 10 | } 11 | repositories { 12 | google() 13 | mavenCentral() 14 | maven { 15 | url "https://plugins.gradle.org/m2/" 16 | } 17 | } 18 | dependencies { 19 | classpath 'com.android.tools.build:gradle:8.2.2' 20 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 21 | classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.30.0" 22 | } 23 | } 24 | 25 | plugins { 26 | id("io.gitlab.arturbosch.detekt").version("1.18.1") 27 | id 'io.github.gradle-nexus.publish-plugin' version '1.3.0' apply false 28 | } 29 | 30 | detekt { 31 | input = files(rootProject.rootDir) 32 | config = files("$projectDir/detekt.yml") 33 | failFast = true 34 | buildUponDefaultConfig = true 35 | basePath = projectDir 36 | 37 | reports { 38 | html.enabled = true 39 | xml.enabled = true 40 | sarif.enabled = true 41 | xml.destination = file("$buildDir/reports/detekt/detekt-checkstyle.xml") 42 | html.destination = file("$buildDir/reports/detekt/detekt-report.html") 43 | sarif.destination = file("$buildDir/reports/detekt/detekt-report.sarif") 44 | } 45 | } 46 | 47 | task clean(type: Delete) { 48 | delete rootProject.buildDir 49 | } 50 | 51 | allprojects { 52 | group = 'com.telefonica.tweaks' 53 | if (System.getProperty("SNAPSHOT_VERSION") != null) { 54 | version = System.getProperty("SNAPSHOT_VERSION")+"-SNAPSHOT" 55 | } else { 56 | version = System.getProperty("LIBRARY_VERSION") ?: "undefined" 57 | } 58 | } 59 | 60 | apply from: "${rootProject.projectDir}/publish_maven_central.gradle" 61 | -------------------------------------------------------------------------------- /detekt.yml: -------------------------------------------------------------------------------- 1 | build: 2 | maxIssues: 0 3 | weights: 4 | complexity: 2 5 | formatting: 1 6 | LongParameterList: 1 7 | comments: 1 8 | 9 | complexity: 10 | TooManyFunctions: 11 | active: false 12 | LongMethod: 13 | active: false 14 | LongParameterList: 15 | active: false 16 | 17 | empty-blocks: 18 | EmptyFunctionBlock: 19 | active: false 20 | style: 21 | MagicNumber: 22 | active: false 23 | NewLineAtEndOfFile: 24 | active: false 25 | UnusedPrivateMember: 26 | active: false 27 | WildcardImport: 28 | active: false 29 | UnusedImports: 30 | active: true 31 | 32 | exceptions: 33 | TooGenericExceptionThrown: 34 | active: false 35 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx6656m -Dfile.encoding=UTF-8 10 | 11 | # When configured, Gradle will run in incubating parallel mode. 12 | # This option should only be used with decoupled projects. More details, visit 13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 14 | org.gradle.parallel=true 15 | 16 | android.useAndroidX=true 17 | 18 | kapt.incremental.apt=true 19 | # It's going to be deleted in Kotlin 1.8 20 | kapt.use.worker.api=true 21 | 22 | # This will be default on AGP 8.0 23 | android.r8.failOnMissingClasses=true 24 | 25 | ###### Project settings ###### 26 | kotlin.code.style=official 27 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telefonica/tweaks/93082eece7221fc50f3cf9d02a05a2e27d618186/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Apr 23 11:46:57 CEST 2024 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' 3 | id 'kotlin-android' 4 | id 'kotlin-kapt' 5 | } 6 | 7 | android { 8 | namespace "com.telefonica.tweaks" 9 | compileSdk 34 10 | 11 | defaultConfig { 12 | minSdk 21 13 | targetSdk 34 14 | 15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 16 | consumerProguardFiles "consumer-rules.pro" 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | } 23 | } 24 | compileOptions { 25 | sourceCompatibility JavaVersion.VERSION_17 26 | targetCompatibility JavaVersion.VERSION_17 27 | } 28 | kotlinOptions { 29 | jvmTarget = '17' 30 | } 31 | buildFeatures { 32 | compose true 33 | } 34 | composeOptions { 35 | kotlinCompilerExtensionVersion compose_compiler_version 36 | } 37 | 38 | flavorDimensions "tweaksMode" 39 | productFlavors { 40 | enabled { 41 | dimension "tweaksMode" 42 | } 43 | noop { 44 | dimension "tweaksMode" 45 | } 46 | } 47 | lint { 48 | sarifReport true 49 | checkDependencies true 50 | } 51 | namespace 'com.telefonica.tweaks' 52 | } 53 | 54 | dependencies { 55 | 56 | enabledImplementation 'androidx.core:core-ktx:1.13.0' 57 | enabledImplementation 'androidx.appcompat:appcompat:1.6.1' 58 | enabledImplementation 'com.google.android.material:material:1.11.0' 59 | 60 | enabledImplementation "androidx.compose.material3:material3:$compose_material3_version" 61 | enabledImplementation "androidx.compose.ui:ui-tooling-preview:$compose_version" 62 | enabledImplementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.7.0' 63 | enabledImplementation 'androidx.activity:activity-compose:1.9.0' 64 | enabledImplementation 'com.squareup:seismic:1.0.3' 65 | enabledImplementation "androidx.datastore:datastore-preferences:1.1.0" 66 | implementation "androidx.compose.ui:ui:$compose_version" 67 | implementation "androidx.navigation:navigation-compose:2.7.7" 68 | 69 | //Dagger 70 | enabledImplementation "com.google.dagger:dagger-android-support:$dagger_version" 71 | kapt "com.google.dagger:dagger-compiler:$dagger_version" 72 | kapt "com.google.dagger:dagger-android-processor:$dagger_version" 73 | 74 | 75 | testImplementation 'junit:junit:4.13.2' 76 | testImplementation "org.mockito.kotlin:mockito-kotlin:5.2.1" 77 | 78 | androidTestImplementation 'androidx.test.ext:junit:1.1.5' 79 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' 80 | androidTestImplementation "androidx.compose.ui:ui-test-junit4" 81 | debugImplementation "androidx.compose.ui:ui-tooling:$compose_version" 82 | } 83 | 84 | apply from: "${rootProject.projectDir}/mavencentral.gradle" -------------------------------------------------------------------------------- /library/consumer-rules.pro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telefonica/tweaks/93082eece7221fc50f3cf9d02a05a2e27d618186/library/consumer-rules.pro -------------------------------------------------------------------------------- /library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /library/src/enabled/java/com/telefonica/tweaks/Tweaks.kt: -------------------------------------------------------------------------------- 1 | package com.telefonica.tweaks 2 | 3 | import android.Manifest 4 | import android.annotation.SuppressLint 5 | import android.content.Context 6 | import android.content.pm.PackageManager 7 | import android.hardware.SensorManager 8 | import android.os.Build 9 | import android.os.VibrationEffect 10 | import android.os.Vibrator 11 | import androidx.compose.runtime.Composable 12 | import androidx.compose.runtime.LaunchedEffect 13 | import androidx.compose.runtime.getValue 14 | import androidx.compose.runtime.mutableStateOf 15 | import androidx.compose.runtime.saveable.rememberSaveable 16 | import androidx.compose.runtime.setValue 17 | import androidx.compose.ui.platform.LocalContext 18 | import androidx.core.content.ContextCompat 19 | import androidx.navigation.NavController 20 | import androidx.navigation.NavGraphBuilder 21 | import androidx.navigation.compose.composable 22 | import androidx.navigation.navigation 23 | import com.squareup.seismic.ShakeDetector 24 | import com.telefonica.tweaks.Tweaks.Companion.TWEAKS_NAVIGATION_ENTRYPOINT 25 | import com.telefonica.tweaks.di.DaggerTweaksComponent 26 | import com.telefonica.tweaks.di.TweaksComponent 27 | import com.telefonica.tweaks.di.TweaksModule 28 | import com.telefonica.tweaks.domain.Constants.TWEAK_MAIN_SCREEN 29 | import com.telefonica.tweaks.domain.TweakCategory 30 | import com.telefonica.tweaks.domain.TweaksBusinessLogic 31 | import com.telefonica.tweaks.domain.TweaksGraph 32 | import com.telefonica.tweaks.ui.TweaksCategoryScreen 33 | import com.telefonica.tweaks.ui.TweaksScreen 34 | import kotlinx.coroutines.flow.Flow 35 | import kotlinx.coroutines.flow.firstOrNull 36 | import kotlinx.coroutines.flow.map 37 | import javax.inject.Inject 38 | 39 | 40 | open class Tweaks : TweaksContract { 41 | 42 | @Inject 43 | internal lateinit var tweaksBusinessLogic: TweaksBusinessLogic 44 | 45 | override fun getTweakValue(key: String): Flow = tweaksBusinessLogic.getValue(key) 46 | 47 | override fun getTweakValue(key: String, defaultValue: T): Flow = 48 | getTweakValue(key).map { it ?: defaultValue } 49 | 50 | override suspend fun getTweak(key: String): T? = getTweakValue(key).firstOrNull() 51 | 52 | override suspend fun getTweak(key: String, defaultValue: T): T = 53 | getTweak(key) ?: defaultValue 54 | 55 | override suspend fun setTweakValue(key: String, value: T) { 56 | tweaksBusinessLogic.setValue(key, value) 57 | } 58 | 59 | override suspend fun clearValue(key: String) { 60 | tweaksBusinessLogic.clearValue(key) 61 | } 62 | 63 | private fun initializeGraph(tweaksGraph: TweaksGraph) { 64 | tweaksBusinessLogic.initialize(tweaksGraph) 65 | } 66 | 67 | companion object { 68 | const val TWEAKS_NAVIGATION_ENTRYPOINT = "tweaks" 69 | private var reference: Tweaks = Tweaks() 70 | private lateinit var component: TweaksComponent 71 | 72 | fun init( 73 | context: Context, 74 | tweaksGraph: TweaksGraph, 75 | ) { 76 | inject(context) 77 | 78 | reference.initializeGraph(tweaksGraph) 79 | } 80 | 81 | @JvmStatic 82 | fun getReference(): Tweaks = reference 83 | 84 | private fun inject(context: Context) { 85 | component = DaggerTweaksComponent 86 | .builder() 87 | .tweaksModule(TweaksModule(context)) 88 | .build() 89 | 90 | component.inject(reference) 91 | } 92 | } 93 | } 94 | 95 | @Composable 96 | fun NavController.navigateToTweaksOnShake() { 97 | DetectShakeAndNavigate { 98 | navigate(TWEAKS_NAVIGATION_ENTRYPOINT) { 99 | launchSingleTop = true 100 | } 101 | } 102 | } 103 | 104 | @Composable 105 | fun NavigateToTweaksOnShake(onOpenTweaks: () -> Unit) { 106 | DetectShakeAndNavigate { 107 | onOpenTweaks() 108 | } 109 | } 110 | 111 | @Composable 112 | private fun DetectShakeAndNavigate(onShakeDetected: () -> Unit) { 113 | val context = LocalContext.current 114 | val sensorManager: SensorManager = 115 | context.getSystemService(Context.SENSOR_SERVICE) as SensorManager 116 | 117 | var shouldNavigate by rememberSaveable { mutableStateOf(false) } 118 | 119 | LaunchedEffect(true) { 120 | val shakeDetector = ShakeDetector { 121 | vibrateIfAble(context) 122 | shouldNavigate = true 123 | } 124 | shakeDetector.start(sensorManager, SensorManager.SENSOR_DELAY_UI) 125 | } 126 | 127 | LaunchedEffect(shouldNavigate) { 128 | if (shouldNavigate) { 129 | onShakeDetected() 130 | shouldNavigate = false 131 | } 132 | } 133 | } 134 | 135 | 136 | @SuppressLint("MissingPermission") 137 | private fun vibrateIfAble(context: Context) { 138 | if (ContextCompat.checkSelfPermission( 139 | context, 140 | Manifest.permission.VIBRATE 141 | ) == PackageManager.PERMISSION_GRANTED 142 | ) { 143 | val vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator 144 | if (vibrator.hasVibrator()) { 145 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 146 | vibrator.vibrate(VibrationEffect.createOneShot(200, 100)) 147 | } else { 148 | vibrator.vibrate(200) 149 | } 150 | } 151 | } 152 | } 153 | 154 | fun NavGraphBuilder.addTweakGraph( 155 | navController: NavController, 156 | tweaksCustomTheme: @Composable (block: @Composable () -> Unit) -> Unit = { 157 | DefaultTweaksTheme(content = it) 158 | }, 159 | customComposableScreens: NavGraphBuilder.() -> Unit = {}, 160 | ) { 161 | val tweaksGraph = Tweaks.getReference().tweaksBusinessLogic.tweaksGraph 162 | 163 | val onNavigationEvent: (String) -> Unit = { route -> 164 | navController.navigate(route) 165 | } 166 | 167 | val onCustomNavigation: ((NavController) -> Unit) -> Unit = { navigation -> 168 | navigation.invoke(navController) 169 | } 170 | 171 | navigation( 172 | startDestination = TWEAK_MAIN_SCREEN, 173 | route = TWEAKS_NAVIGATION_ENTRYPOINT, 174 | ) { 175 | 176 | composable(TWEAK_MAIN_SCREEN) { 177 | tweaksCustomTheme { 178 | TweaksScreen( 179 | tweaksGraph = tweaksGraph, 180 | onCategoryButtonClicked = { navController.navigate(it.navigationRoute()) }, 181 | onNavigationEvent = onNavigationEvent, 182 | onCustomNavigation = onCustomNavigation 183 | ) 184 | } 185 | } 186 | 187 | tweaksGraph.categories.iterator().forEach { category -> 188 | composable(category.navigationRoute()) { 189 | tweaksCustomTheme { 190 | TweaksCategoryScreen( 191 | tweakCategory = category, 192 | onNavigationEvent = onNavigationEvent, 193 | onCustomNavigation = onCustomNavigation 194 | ) 195 | } 196 | } 197 | } 198 | customComposableScreens() 199 | } 200 | } 201 | 202 | private fun TweakCategory.navigationRoute(): String = "${this.title.replace(" ", "")}-tweak-screen" 203 | -------------------------------------------------------------------------------- /library/src/enabled/java/com/telefonica/tweaks/TweaksTheme.kt: -------------------------------------------------------------------------------- 1 | package com.telefonica.tweaks 2 | 3 | import androidx.compose.runtime.Composable 4 | import androidx.compose.runtime.CompositionLocalProvider 5 | import androidx.compose.runtime.Immutable 6 | import androidx.compose.runtime.staticCompositionLocalOf 7 | import androidx.compose.ui.graphics.Color 8 | import com.telefonica.tweaks.ui.theme.TweaksDarkBlue 9 | import com.telefonica.tweaks.ui.theme.TweaksDarkBlueBackground 10 | import com.telefonica.tweaks.ui.theme.TweaksGreen 11 | 12 | @Immutable 13 | data class TweaksColors( 14 | val tweaksPrimary: Color, 15 | val tweaksOnPrimary: Color, 16 | val tweaksPrimaryVariant: Color, 17 | val tweaksSurface: Color, 18 | val tweaksOnSurface: Color, 19 | val tweaksBackground: Color, 20 | val tweaksOnBackground: Color, 21 | val tweaksGroupBackground: Color, 22 | val tweaksDropdownItemBackground: Color, 23 | val tweaksColorModified: Color, 24 | ) 25 | 26 | val LocalTweaksColors = staticCompositionLocalOf { 27 | TweaksColors( 28 | tweaksPrimary = Color.Unspecified, 29 | tweaksOnPrimary = Color.Unspecified, 30 | tweaksPrimaryVariant = Color.Unspecified, 31 | tweaksSurface = Color.Unspecified, 32 | tweaksOnSurface = Color.Unspecified, 33 | tweaksBackground = Color.Unspecified, 34 | tweaksOnBackground = Color.Unspecified, 35 | tweaksGroupBackground = Color.Unspecified, 36 | tweaksDropdownItemBackground = Color.Unspecified, 37 | tweaksColorModified = Color.Unspecified, 38 | ) 39 | } 40 | 41 | @Composable 42 | fun DefaultTweaksTheme( 43 | content: @Composable () -> Unit, 44 | ) { 45 | val tweaksColors = TweaksColors( 46 | tweaksPrimary = TweaksGreen, 47 | tweaksOnPrimary = Color.White, 48 | tweaksPrimaryVariant = TweaksGreen, 49 | tweaksSurface = TweaksDarkBlue, 50 | tweaksOnSurface = Color.White, 51 | tweaksBackground = TweaksDarkBlue, 52 | tweaksOnBackground = Color.White, 53 | tweaksGroupBackground = TweaksDarkBlueBackground, 54 | tweaksDropdownItemBackground = TweaksDarkBlue, 55 | tweaksColorModified = TweaksGreen, 56 | ) 57 | CompositionLocalProvider(LocalTweaksColors provides tweaksColors) { 58 | content() 59 | } 60 | } 61 | 62 | object TweaksTheme { 63 | val colors: TweaksColors 64 | @Composable 65 | get() = LocalTweaksColors.current 66 | } -------------------------------------------------------------------------------- /library/src/enabled/java/com/telefonica/tweaks/data/TweaksDataStore.kt: -------------------------------------------------------------------------------- 1 | package com.telefonica.tweaks.data 2 | 3 | import android.content.Context 4 | import androidx.datastore.core.DataStore 5 | import androidx.datastore.preferences.core.Preferences 6 | import androidx.datastore.preferences.preferencesDataStore 7 | import javax.inject.Inject 8 | import javax.inject.Singleton 9 | 10 | internal val Context.tweaksDataStore: DataStore by preferencesDataStore(name = "debug_tweaks") 11 | 12 | @Singleton 13 | open class TweaksDataStore @Inject constructor( 14 | context: Context, 15 | ): DataStore by context.tweaksDataStore 16 | -------------------------------------------------------------------------------- /library/src/enabled/java/com/telefonica/tweaks/data/TweaksRepository.kt: -------------------------------------------------------------------------------- 1 | package com.telefonica.tweaks.data 2 | 3 | import androidx.datastore.preferences.core.Preferences 4 | import androidx.datastore.preferences.core.booleanPreferencesKey 5 | import androidx.datastore.preferences.core.edit 6 | import androidx.datastore.preferences.core.intPreferencesKey 7 | import androidx.datastore.preferences.core.longPreferencesKey 8 | import androidx.datastore.preferences.core.stringPreferencesKey 9 | import com.telefonica.tweaks.domain.DropDownMenuTweakEntry 10 | import com.telefonica.tweaks.domain.Editable 11 | import com.telefonica.tweaks.domain.EditableBooleanTweakEntry 12 | import com.telefonica.tweaks.domain.EditableIntTweakEntry 13 | import com.telefonica.tweaks.domain.EditableLongTweakEntry 14 | import com.telefonica.tweaks.domain.EditableStringTweakEntry 15 | import kotlinx.coroutines.flow.Flow 16 | import kotlinx.coroutines.flow.map 17 | import javax.inject.Inject 18 | 19 | 20 | interface TweaksRepository { 21 | fun isOverriden(entry: Editable<*>): Flow 22 | fun get(entry: Editable): Flow 23 | 24 | suspend fun clearValue(entry: Editable<*>) 25 | 26 | suspend fun setValue(entry: Editable, value: T?) 27 | } 28 | 29 | class TweaksRepositoryImpl @Inject constructor( 30 | private val tweaksDataStore: TweaksDataStore, 31 | ) : TweaksRepository { 32 | 33 | override fun isOverriden(entry: Editable<*>): Flow = tweaksDataStore.data 34 | .map { preferences -> preferences[buildIsOverridenKey(entry)] } 35 | 36 | override fun get(entry: Editable): Flow = tweaksDataStore.data 37 | .map { preferences -> preferences[buildKey(entry)] } 38 | 39 | override suspend fun clearValue(entry: Editable<*>) { 40 | tweaksDataStore.edit { 41 | it.remove(buildKey(entry)) 42 | it.remove(buildIsOverridenKey(entry)) 43 | } 44 | } 45 | 46 | override suspend fun setValue(entry: Editable, value: T?) { 47 | val key = buildKey(entry) 48 | val overridenKey = buildIsOverridenKey(entry) 49 | tweaksDataStore.edit { preferences -> 50 | if (value != null) { 51 | preferences[key] = value 52 | preferences[overridenKey] = true 53 | } else { 54 | preferences.remove(key) 55 | preferences[overridenKey] = false 56 | } 57 | } 58 | } 59 | 60 | @Suppress("UNCHECKED_CAST") 61 | private fun buildKey(entry: Editable): Preferences.Key = when (entry) { 62 | is EditableStringTweakEntry -> stringPreferencesKey(entry.key) as Preferences.Key 63 | is EditableBooleanTweakEntry -> booleanPreferencesKey(entry.key) as Preferences.Key 64 | is EditableIntTweakEntry -> intPreferencesKey(entry.key) as Preferences.Key 65 | is EditableLongTweakEntry -> longPreferencesKey(entry.key) as Preferences.Key 66 | is DropDownMenuTweakEntry -> stringPreferencesKey(entry.key) as Preferences.Key 67 | else -> throw java.lang.IllegalStateException("Unknown tweak entry") 68 | } 69 | 70 | private fun buildIsOverridenKey(entry: Editable<*>): Preferences.Key = 71 | booleanPreferencesKey("${entry.key}.TweakOverriden") 72 | } -------------------------------------------------------------------------------- /library/src/enabled/java/com/telefonica/tweaks/di/TweaksComponent.kt: -------------------------------------------------------------------------------- 1 | package com.telefonica.tweaks.di 2 | 3 | import com.telefonica.tweaks.Tweaks 4 | import dagger.Component 5 | import javax.inject.Singleton 6 | 7 | @Singleton 8 | @Component( 9 | modules = [TweaksModule::class] 10 | ) 11 | internal interface TweaksComponent { 12 | fun inject(tweaks: Tweaks) 13 | } -------------------------------------------------------------------------------- /library/src/enabled/java/com/telefonica/tweaks/di/TweaksModule.kt: -------------------------------------------------------------------------------- 1 | package com.telefonica.tweaks.di 2 | 3 | import android.content.Context 4 | import com.telefonica.tweaks.data.TweaksRepository 5 | import com.telefonica.tweaks.data.TweaksRepositoryImpl 6 | import dagger.Module 7 | import dagger.Provides 8 | 9 | @Module 10 | class TweaksModule(private val context: Context) { 11 | 12 | @Provides 13 | fun provideContext() = context 14 | 15 | @Provides 16 | fun provideTweaksRepository(impl: TweaksRepositoryImpl): TweaksRepository = impl 17 | 18 | } -------------------------------------------------------------------------------- /library/src/enabled/java/com/telefonica/tweaks/domain/TweaksBusinessLogic.kt: -------------------------------------------------------------------------------- 1 | package com.telefonica.tweaks.domain 2 | 3 | import com.telefonica.tweaks.data.TweaksRepository 4 | import kotlinx.coroutines.flow.Flow 5 | import kotlinx.coroutines.flow.emptyFlow 6 | import kotlinx.coroutines.flow.flatMapMerge 7 | import kotlinx.coroutines.flow.flowOf 8 | import kotlinx.coroutines.flow.map 9 | import javax.inject.Inject 10 | import javax.inject.Singleton 11 | 12 | @Suppress("UNCHECKED_CAST") 13 | @Singleton 14 | class TweaksBusinessLogic @Inject constructor( 15 | private val tweaksRepository: TweaksRepository 16 | ) { 17 | 18 | internal lateinit var tweaksGraph: TweaksGraph 19 | private val keyToEntryValueMap: MutableMap> = mutableMapOf() 20 | 21 | internal fun initialize(tweaksGraph: TweaksGraph) { 22 | this.tweaksGraph = tweaksGraph 23 | val alreadyIntroducedKeys = mutableSetOf() 24 | val allEntries: MutableList = tweaksGraph.categories 25 | .flatMap { category -> 26 | category.groups.flatMap { group -> 27 | group.entries 28 | } 29 | }.toMutableList() 30 | if (tweaksGraph.cover != null) { 31 | allEntries.addAll(tweaksGraph.cover.entries) 32 | } 33 | 34 | allEntries 35 | .filterIsInstance>() 36 | .forEach { entry -> 37 | checkIfRepeatedKey(alreadyIntroducedKeys, entry) 38 | keyToEntryValueMap[entry.key] = entry 39 | } 40 | } 41 | 42 | private fun checkIfRepeatedKey( 43 | alreadyIntroducedKeys: MutableSet, 44 | entry: Editable<*>, 45 | ) { 46 | if (alreadyIntroducedKeys.contains(entry.key)) { 47 | throw IllegalStateException("There is a repeated key in the tweaks: ${entry.key}, review your graph") 48 | } 49 | 50 | alreadyIntroducedKeys.add(entry.key) 51 | } 52 | 53 | fun getValue(key: String): Flow { 54 | val tweakEntry = keyToEntryValueMap[key] as TweakEntry 55 | return getValue(tweakEntry) 56 | } 57 | 58 | internal fun getValue(entry: TweakEntry): Flow = when (entry) { 59 | is ReadOnly<*> -> (entry as ReadOnly).value 60 | is Editable<*> -> getMutableValue(entry as Editable) 61 | else -> emptyFlow() 62 | } 63 | 64 | private fun getMutableValue(entry: Editable): Flow { 65 | val defaultValue: Flow = entry.defaultValue ?: flowOf() 66 | 67 | return isOverridden(entry) 68 | .flatMapMerge { overriden -> 69 | when (overriden) { 70 | true -> getFromStorage(entry) 71 | else -> defaultValue 72 | } 73 | } 74 | } 75 | 76 | fun isOverridden(entry: Editable<*>): Flow = 77 | tweaksRepository.isOverriden(entry).map { it ?: OVERRIDEN_DEFAULT_VALUE } 78 | 79 | private fun getFromStorage(entry: Editable) = tweaksRepository.get(entry) 80 | 81 | internal suspend fun clearValue(entry: Editable<*>) { 82 | tweaksRepository.clearValue(entry) 83 | } 84 | 85 | suspend fun setValue(entry: Editable, value: T?) { 86 | tweaksRepository.setValue(entry, value) 87 | } 88 | 89 | suspend fun setValue(key: String, value: T?) { 90 | val tweakEntry = keyToEntryValueMap[key] as Editable 91 | setValue(tweakEntry, value) 92 | } 93 | 94 | suspend fun clearValue(key: String) { 95 | val tweakEntry = keyToEntryValueMap[key] as Editable<*> 96 | clearValue(tweakEntry) 97 | } 98 | 99 | companion object { 100 | private const val OVERRIDEN_DEFAULT_VALUE = false 101 | } 102 | } -------------------------------------------------------------------------------- /library/src/enabled/java/com/telefonica/tweaks/ui/EditableTweakEntryViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.telefonica.tweaks.ui 2 | 3 | import androidx.compose.runtime.getValue 4 | import androidx.compose.runtime.mutableStateOf 5 | import androidx.compose.runtime.setValue 6 | import androidx.lifecycle.ViewModel 7 | import androidx.lifecycle.viewModelScope 8 | import com.telefonica.tweaks.Tweaks 9 | import com.telefonica.tweaks.domain.Editable 10 | import com.telefonica.tweaks.domain.TweakEntry 11 | import com.telefonica.tweaks.domain.TweaksBusinessLogic 12 | import kotlinx.coroutines.flow.Flow 13 | import kotlinx.coroutines.launch 14 | 15 | class EditableTweakEntryViewModel( 16 | private val tweakEntry: Editable, 17 | private val tweaksBusinessLogic: TweaksBusinessLogic = Tweaks.getReference().tweaksBusinessLogic 18 | ) : ViewModel() { 19 | 20 | var value: T? by mutableStateOf(null) 21 | val entry = (tweakEntry as TweakEntry) 22 | init { 23 | viewModelScope.launch { 24 | tweaksBusinessLogic.getValue(tweakEntry as TweakEntry).collect { 25 | value = it 26 | } 27 | } 28 | } 29 | 30 | fun updateValue(value: T) { 31 | this.value = value 32 | viewModelScope.launch { 33 | tweaksBusinessLogic.setValue(tweakEntry, value) 34 | } 35 | } 36 | 37 | fun isOverridden(): Flow = 38 | tweaksBusinessLogic.isOverridden(tweakEntry) 39 | 40 | fun clearValue() { 41 | this.value = null 42 | viewModelScope.launch { 43 | tweaksBusinessLogic.clearValue(tweakEntry) 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /library/src/enabled/java/com/telefonica/tweaks/ui/ReadOnlyTweakEntryViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.telefonica.tweaks.ui 2 | 3 | import androidx.lifecycle.ViewModel 4 | import com.telefonica.tweaks.Tweaks 5 | import com.telefonica.tweaks.domain.TweakEntry 6 | import com.telefonica.tweaks.domain.TweaksBusinessLogic 7 | import kotlinx.coroutines.flow.Flow 8 | 9 | class ReadOnlyTweakEntryViewModel( 10 | private val tweaksBusinessLogic: TweaksBusinessLogic = Tweaks.getReference().tweaksBusinessLogic 11 | ) : ViewModel() { 12 | 13 | fun getValue(entry: TweakEntry): Flow = tweaksBusinessLogic.getValue(entry) 14 | } -------------------------------------------------------------------------------- /library/src/enabled/java/com/telefonica/tweaks/ui/TweakComponents.kt: -------------------------------------------------------------------------------- 1 | package com.telefonica.tweaks.ui 2 | 3 | import android.widget.Toast 4 | import androidx.compose.foundation.ExperimentalFoundationApi 5 | import androidx.compose.foundation.background 6 | import androidx.compose.foundation.combinedClickable 7 | import androidx.compose.foundation.layout.Arrangement 8 | import androidx.compose.foundation.layout.Column 9 | import androidx.compose.foundation.layout.ColumnScope 10 | import androidx.compose.foundation.layout.Row 11 | import androidx.compose.foundation.layout.Spacer 12 | import androidx.compose.foundation.layout.WindowInsets 13 | import androidx.compose.foundation.layout.fillMaxSize 14 | import androidx.compose.foundation.layout.fillMaxWidth 15 | import androidx.compose.foundation.layout.navigationBars 16 | import androidx.compose.foundation.layout.padding 17 | import androidx.compose.foundation.layout.size 18 | import androidx.compose.foundation.layout.statusBars 19 | import androidx.compose.foundation.layout.windowInsetsBottomHeight 20 | import androidx.compose.foundation.layout.windowInsetsTopHeight 21 | import androidx.compose.foundation.rememberScrollState 22 | import androidx.compose.foundation.text.KeyboardActions 23 | import androidx.compose.foundation.text.KeyboardOptions 24 | import androidx.compose.foundation.verticalScroll 25 | import androidx.compose.material.icons.Icons 26 | import androidx.compose.material.icons.filled.Delete 27 | import androidx.compose.material3.Button 28 | import androidx.compose.material3.ButtonColors 29 | import androidx.compose.material3.ButtonDefaults 30 | import androidx.compose.material3.Card 31 | import androidx.compose.material3.CardDefaults.cardElevation 32 | import androidx.compose.material3.Checkbox 33 | import androidx.compose.material3.CheckboxColors 34 | import androidx.compose.material3.CheckboxDefaults 35 | import androidx.compose.material3.DropdownMenu 36 | import androidx.compose.material3.DropdownMenuItem 37 | import androidx.compose.material3.HorizontalDivider 38 | import androidx.compose.material3.Icon 39 | import androidx.compose.material3.IconButton 40 | import androidx.compose.material3.MaterialTheme 41 | import androidx.compose.material3.Text 42 | import androidx.compose.material3.TextField 43 | import androidx.compose.material3.TextFieldColors 44 | import androidx.compose.material3.TextFieldDefaults 45 | import androidx.compose.material3.contentColorFor 46 | import androidx.compose.runtime.Composable 47 | import androidx.compose.runtime.LaunchedEffect 48 | import androidx.compose.runtime.collectAsState 49 | import androidx.compose.runtime.getValue 50 | import androidx.compose.runtime.mutableIntStateOf 51 | import androidx.compose.runtime.mutableStateOf 52 | import androidx.compose.runtime.remember 53 | import androidx.compose.runtime.setValue 54 | import androidx.compose.ui.Alignment 55 | import androidx.compose.ui.Modifier 56 | import androidx.compose.ui.focus.FocusRequester 57 | import androidx.compose.ui.focus.focusRequester 58 | import androidx.compose.ui.graphics.compositeOver 59 | import androidx.compose.ui.platform.LocalClipboardManager 60 | import androidx.compose.ui.platform.LocalContext 61 | import androidx.compose.ui.platform.LocalSoftwareKeyboardController 62 | import androidx.compose.ui.platform.SoftwareKeyboardController 63 | import androidx.compose.ui.text.AnnotatedString 64 | import androidx.compose.ui.text.font.FontFamily 65 | import androidx.compose.ui.text.font.FontWeight 66 | import androidx.compose.ui.text.input.ImeAction 67 | import androidx.compose.ui.text.style.TextAlign 68 | import androidx.compose.ui.unit.dp 69 | import androidx.lifecycle.viewmodel.compose.viewModel 70 | import androidx.navigation.NavController 71 | import com.telefonica.tweaks.TweaksTheme 72 | import com.telefonica.tweaks.domain.ButtonTweakEntry 73 | import com.telefonica.tweaks.domain.CustomNavigationButtonTweakEntry 74 | import com.telefonica.tweaks.domain.DropDownMenuTweakEntry 75 | import com.telefonica.tweaks.domain.Editable 76 | import com.telefonica.tweaks.domain.EditableBooleanTweakEntry 77 | import com.telefonica.tweaks.domain.EditableIntTweakEntry 78 | import com.telefonica.tweaks.domain.EditableLongTweakEntry 79 | import com.telefonica.tweaks.domain.EditableStringTweakEntry 80 | import com.telefonica.tweaks.domain.ReadOnlyStringTweakEntry 81 | import com.telefonica.tweaks.domain.RouteButtonTweakEntry 82 | import com.telefonica.tweaks.domain.TweakCategory 83 | import com.telefonica.tweaks.domain.TweakEntry 84 | import com.telefonica.tweaks.domain.TweakGroup 85 | import com.telefonica.tweaks.domain.TweaksGraph 86 | import kotlin.math.max 87 | 88 | 89 | @Composable 90 | fun TweaksScreen( 91 | tweaksGraph: TweaksGraph, 92 | onCategoryButtonClicked: (TweakCategory) -> Unit, 93 | onNavigationEvent: (String) -> Unit, 94 | onCustomNavigation: ((NavController) -> Unit) -> Unit, 95 | ) { 96 | val scrollState = rememberScrollState() 97 | Column( 98 | modifier = Modifier 99 | .fillMaxSize() 100 | .background(TweaksTheme.colors.tweaksBackground) 101 | .padding(horizontal = 16.dp) 102 | .verticalScroll(scrollState), 103 | verticalArrangement = Arrangement.spacedBy(8.dp), 104 | horizontalAlignment = Alignment.CenterHorizontally, 105 | ) { 106 | Spacer(modifier = Modifier.windowInsetsTopHeight(WindowInsets.statusBars)) 107 | 108 | tweaksGraph.cover?.let { 109 | TweakGroupBody( 110 | tweakGroup = it, 111 | onNavigationEvent = onNavigationEvent, 112 | onCustomNavigation = onCustomNavigation, 113 | ) 114 | } 115 | tweaksGraph.categories.iterator().forEach { category -> 116 | TweakButton( 117 | onClick = { onCategoryButtonClicked(category) }, 118 | text = category.title, 119 | ) 120 | } 121 | Spacer(modifier = Modifier.windowInsetsBottomHeight(WindowInsets.navigationBars)) 122 | } 123 | } 124 | 125 | @Composable 126 | fun TweaksCategoryScreen( 127 | tweakCategory: TweakCategory, 128 | onNavigationEvent: (String) -> Unit, 129 | onCustomNavigation: ((NavController) -> Unit) -> Unit, 130 | ) { 131 | val scrollState = rememberScrollState() 132 | Column( 133 | modifier = Modifier 134 | .fillMaxSize() 135 | .background(TweaksTheme.colors.tweaksBackground) 136 | .padding(horizontal = 16.dp) 137 | .verticalScroll(scrollState), 138 | verticalArrangement = Arrangement.spacedBy(8.dp), 139 | horizontalAlignment = Alignment.CenterHorizontally, 140 | ) { 141 | Spacer(modifier = Modifier.windowInsetsTopHeight(WindowInsets.statusBars)) 142 | 143 | Text( 144 | text = tweakCategory.title, 145 | style = MaterialTheme.typography.headlineLarge, 146 | color = TweaksTheme.colors.tweaksOnBackground, 147 | ) 148 | 149 | tweakCategory.groups.iterator().forEach { group -> 150 | TweakGroupBody( 151 | tweakGroup = group, 152 | onNavigationEvent = onNavigationEvent, 153 | onCustomNavigation = onCustomNavigation 154 | ) 155 | } 156 | 157 | Spacer(modifier = Modifier.windowInsetsBottomHeight(WindowInsets.navigationBars)) 158 | } 159 | } 160 | 161 | @Composable 162 | fun TweakGroupBody( 163 | tweakGroupViewModel: TweakGroupViewModel = viewModel(), 164 | tweakGroup: TweakGroup, 165 | onNavigationEvent: (String) -> Unit, 166 | onCustomNavigation: ((NavController) -> Unit) -> Unit, 167 | ) { 168 | Card(elevation = cardElevation(3.dp)) { 169 | Column( 170 | modifier = Modifier 171 | .background(TweaksTheme.colors.tweaksGroupBackground) 172 | .padding(8.dp), 173 | verticalArrangement = Arrangement.spacedBy(8.dp) 174 | ) { 175 | Text( 176 | tweakGroup.title, 177 | style = MaterialTheme.typography.headlineMedium, 178 | color = TweaksTheme.colors.tweaksOnBackground, 179 | ) 180 | HorizontalDivider(thickness = 2.dp) 181 | tweakGroup.entries.iterator().forEach { entry -> 182 | when (entry) { 183 | is EditableStringTweakEntry -> EditableStringTweakEntryBody( 184 | EditableTweakEntryViewModel(entry) 185 | ) 186 | 187 | is EditableBooleanTweakEntry -> EditableBooleanTweakEntryBody( 188 | EditableTweakEntryViewModel(entry) 189 | ) 190 | 191 | is EditableIntTweakEntry -> EditableIntTweakEntryBody( 192 | EditableTweakEntryViewModel(entry) 193 | ) 194 | 195 | is EditableLongTweakEntry -> EditableLongTweakEntryBody( 196 | EditableTweakEntryViewModel(entry) 197 | ) 198 | 199 | is DropDownMenuTweakEntry -> DropDownMenuTweakEntryBody( 200 | items = entry.values, 201 | EditableTweakEntryViewModel(entry) 202 | ) 203 | 204 | is ReadOnlyStringTweakEntry -> ReadOnlyStringTweakEntryBody( 205 | entry, 206 | ReadOnlyTweakEntryViewModel() 207 | ) 208 | 209 | is ButtonTweakEntry -> TweakButton(entry) 210 | is RouteButtonTweakEntry -> TweakNavigableButton(entry, onNavigationEvent) 211 | is CustomNavigationButtonTweakEntry -> TweakNavigableButton( 212 | entry, 213 | onCustomNavigation 214 | ) 215 | } 216 | } 217 | 218 | if (tweakGroup.entries.any { it is Editable<*> } && tweakGroup.withClearButton) { 219 | HorizontalDivider(thickness = 2.dp) 220 | ResetButton(onResetClicked = { tweakGroupViewModel.reset(tweakGroup) }) 221 | } 222 | } 223 | } 224 | } 225 | 226 | @Composable 227 | private fun ResetButton( 228 | onResetClicked: () -> Unit = {}, 229 | ) { 230 | TweakButton( 231 | onClick = onResetClicked, 232 | text = "⚠️ Reset ⚠️", 233 | ) 234 | } 235 | 236 | @Composable 237 | fun TweakButton(entry: ButtonTweakEntry) { 238 | TweakButton( 239 | onClick = entry.action, 240 | text = entry.name, 241 | ) 242 | } 243 | 244 | @Composable 245 | fun TweakNavigableButton( 246 | entry: RouteButtonTweakEntry, 247 | onClick: (String) -> Unit, 248 | ) { 249 | TweakButton( 250 | onClick = { onClick(entry.route) }, 251 | text = entry.name, 252 | ) 253 | } 254 | 255 | @Composable 256 | fun TweakNavigableButton( 257 | entry: CustomNavigationButtonTweakEntry, 258 | customNavigation: ((NavController) -> Unit) -> Unit, 259 | ) { 260 | TweakButton( 261 | onClick = { customNavigation(entry.navigation) }, 262 | text = entry.name, 263 | ) 264 | } 265 | 266 | @Composable 267 | fun ReadOnlyStringTweakEntryBody( 268 | entry: ReadOnlyStringTweakEntry, 269 | tweakRowViewModel: ReadOnlyTweakEntryViewModel = ReadOnlyTweakEntryViewModel(), 270 | ) { 271 | val context = LocalContext.current 272 | val clipboardManager = LocalClipboardManager.current 273 | val value by remember { 274 | tweakRowViewModel.getValue(entry) 275 | }.collectAsState(initial = null) 276 | TweakRow( 277 | tweakEntry = entry, 278 | onClick = { 279 | Toast 280 | .makeText(context, "${entry.name} = $value", Toast.LENGTH_LONG) 281 | .show() 282 | }, 283 | onLongClick = { 284 | clipboardManager.setText(AnnotatedString(value.orEmpty())) 285 | Toast 286 | .makeText(context, "'$value' copied to clipboard", Toast.LENGTH_LONG) 287 | .show() 288 | }) { 289 | Text( 290 | text = "$value", 291 | fontFamily = FontFamily.Monospace, 292 | color = TweaksTheme.colors.tweaksOnBackground, 293 | textAlign = TextAlign.End, 294 | ) 295 | } 296 | } 297 | 298 | @Composable 299 | fun EditableStringTweakEntryBody( 300 | tweakRowViewModel: EditableTweakEntryViewModel, 301 | ) { 302 | val keyboardController = LocalSoftwareKeyboardController.current 303 | 304 | val isOverridden by remember { tweakRowViewModel.isOverridden() }.collectAsState(initial = false) 305 | 306 | TweakRowWithEditableTextField( 307 | value = tweakRowViewModel.value, 308 | tweakRowViewModel = tweakRowViewModel, 309 | keyboardController = keyboardController, 310 | onTextFieldValueChanged = { tweakRowViewModel.updateValue(it) }, 311 | shouldShowOverriddenLabel = isOverridden 312 | ) 313 | } 314 | 315 | @Composable 316 | fun EditableBooleanTweakEntryBody( 317 | tweakRowViewModel: EditableTweakEntryViewModel, 318 | ) { 319 | val context = LocalContext.current 320 | 321 | val isOverridden by remember { tweakRowViewModel.isOverridden() }.collectAsState(initial = false) 322 | 323 | TweakRow( 324 | tweakEntry = tweakRowViewModel.entry, 325 | onClick = { 326 | Toast 327 | .makeText(context, "Current value is ${tweakRowViewModel.value}", Toast.LENGTH_LONG) 328 | .show() 329 | }, 330 | shouldShowOverriddenLabel = isOverridden 331 | ) { 332 | Checkbox( 333 | modifier = Modifier.size(48.dp), 334 | checked = tweakRowViewModel.value ?: false, 335 | onCheckedChange = { 336 | tweakRowViewModel.updateValue(it) 337 | }, 338 | colors = tweaksCheckboxColors(), 339 | ) 340 | 341 | } 342 | } 343 | 344 | @Composable 345 | fun EditableIntTweakEntryBody( 346 | tweakRowViewModel: EditableTweakEntryViewModel, 347 | ) { 348 | val keyboardController = LocalSoftwareKeyboardController.current 349 | 350 | val isOverridden by remember { tweakRowViewModel.isOverridden() }.collectAsState(initial = false) 351 | 352 | TweakRowWithEditableTextField( 353 | value = tweakRowViewModel.value, 354 | tweakRowViewModel = tweakRowViewModel, 355 | keyboardController = keyboardController, 356 | onTextFieldValueChanged = { 357 | val newValue = it.toIntOrNull() ?: 0 358 | tweakRowViewModel.updateValue(newValue) 359 | }, 360 | shouldShowOverriddenLabel = isOverridden 361 | ) 362 | } 363 | 364 | @Composable 365 | fun EditableLongTweakEntryBody( 366 | tweakRowViewModel: EditableTweakEntryViewModel, 367 | ) { 368 | val keyboardController = LocalSoftwareKeyboardController.current 369 | 370 | val isOverridden by remember { tweakRowViewModel.isOverridden() }.collectAsState(initial = false) 371 | 372 | TweakRowWithEditableTextField( 373 | value = tweakRowViewModel.value, 374 | tweakRowViewModel = tweakRowViewModel, 375 | keyboardController = keyboardController, 376 | onTextFieldValueChanged = { 377 | val newValue = it.toLongOrNull() ?: 0 378 | tweakRowViewModel.updateValue(newValue) 379 | }, 380 | shouldShowOverriddenLabel = isOverridden 381 | ) 382 | } 383 | 384 | @Composable 385 | fun DropDownMenuTweakEntryBody( 386 | items: List, 387 | tweakRowViewModel: EditableTweakEntryViewModel, 388 | ) { 389 | var expanded by remember { mutableStateOf(false) } 390 | 391 | var selectedIndex by remember { 392 | mutableIntStateOf(max(items.indexOf(tweakRowViewModel.value), 0)) 393 | } 394 | 395 | val isOverridden by remember { tweakRowViewModel.isOverridden() }.collectAsState(initial = false) 396 | 397 | TweakRow( 398 | tweakEntry = tweakRowViewModel.entry, 399 | onClick = { 400 | expanded = true 401 | }, 402 | onLongClick = { 403 | expanded = true 404 | }, 405 | shouldShowOverriddenLabel = isOverridden, 406 | ) { 407 | Text( 408 | text = tweakRowViewModel.value ?: "", 409 | fontFamily = FontFamily.Monospace, 410 | color = TweaksTheme.colors.tweaksOnBackground, 411 | ) 412 | } 413 | DropdownMenu( 414 | expanded = expanded, 415 | onDismissRequest = { expanded = false }, 416 | modifier = Modifier 417 | .fillMaxWidth() 418 | .background(color = TweaksTheme.colors.tweaksDropdownItemBackground) 419 | ) { 420 | items.forEachIndexed { index, value -> 421 | DropdownMenuItem( 422 | text = { 423 | Text( 424 | text = value, 425 | color = TweaksTheme.colors.tweaksOnSurface 426 | ) 427 | }, 428 | onClick = { 429 | selectedIndex = index 430 | expanded = false 431 | tweakRowViewModel.updateValue(items[selectedIndex]) 432 | } 433 | ) 434 | } 435 | } 436 | } 437 | 438 | 439 | @OptIn(ExperimentalFoundationApi::class) 440 | @Composable 441 | private fun TweakRow( 442 | tweakEntry: TweakEntry, 443 | onClick: (() -> Unit), 444 | onLongClick: (() -> Unit)? = null, 445 | shouldShowOverriddenLabel: Boolean = false, 446 | content: @Composable ColumnScope.() -> Unit, 447 | ) { 448 | Column( 449 | modifier = Modifier 450 | .fillMaxWidth() 451 | .padding(4.dp) 452 | .combinedClickable( 453 | onClick = onClick, 454 | onLongClick = onLongClick 455 | ) 456 | ) { 457 | TweakNameText(entry = tweakEntry, shouldShowOverriddenLabel = shouldShowOverriddenLabel) 458 | Spacer(modifier = Modifier.padding(horizontal = 8.dp)) 459 | content() 460 | } 461 | } 462 | 463 | @Composable 464 | private fun TweakRowWithEditableTextField( 465 | value: T?, 466 | tweakRowViewModel: EditableTweakEntryViewModel, 467 | keyboardController: SoftwareKeyboardController?, 468 | keyboardOptions: KeyboardOptions = KeyboardOptions.Default, 469 | onTextFieldValueChanged: (String) -> Unit, 470 | shouldShowOverriddenLabel: Boolean = false, 471 | ) { 472 | val context = LocalContext.current 473 | var inEditionMode by remember { mutableStateOf(false) } 474 | val focusRequester = remember { FocusRequester() } 475 | 476 | if (inEditionMode) { 477 | Row { 478 | TextField( 479 | modifier = Modifier 480 | .weight(100F, true) 481 | .focusRequester(focusRequester), 482 | value = if (value == null) "" else "$value", 483 | onValueChange = onTextFieldValueChanged, 484 | maxLines = 1, 485 | label = { Text(tweakRowViewModel.entry.name) }, 486 | keyboardOptions = keyboardOptions.copy(imeAction = ImeAction.Done), 487 | keyboardActions = KeyboardActions(onDone = { 488 | inEditionMode = false 489 | keyboardController?.hide() 490 | }), 491 | colors = tweaksTextFieldColors(), 492 | ) 493 | IconButton(onClick = { 494 | tweakRowViewModel.clearValue() 495 | inEditionMode = false 496 | keyboardController?.hide() 497 | }) { 498 | Icon( 499 | imageVector = Icons.Default.Delete, 500 | contentDescription = "delete", 501 | tint = TweaksTheme.colors.tweaksOnBackground 502 | ) 503 | } 504 | } 505 | 506 | LaunchedEffect(Unit) { 507 | focusRequester.requestFocus() 508 | } 509 | } else { 510 | TweakRow( 511 | tweakEntry = tweakRowViewModel.entry, 512 | onClick = { 513 | Toast 514 | .makeText(context, "Current value is $value", Toast.LENGTH_LONG) 515 | .show() 516 | }, 517 | onLongClick = { 518 | inEditionMode = true 519 | }, 520 | shouldShowOverriddenLabel = shouldShowOverriddenLabel 521 | ) { 522 | Text( 523 | text = if (value == null) "" else "$value", 524 | fontFamily = FontFamily.Monospace, 525 | color = TweaksTheme.colors.tweaksOnBackground, 526 | ) 527 | } 528 | } 529 | } 530 | 531 | @Composable 532 | private fun TweakNameText( 533 | entry: TweakEntry, 534 | shouldShowOverriddenLabel: Boolean = false, 535 | ) { 536 | Row( 537 | horizontalArrangement = Arrangement.SpaceBetween, 538 | modifier = Modifier.fillMaxWidth() 539 | ) { 540 | Text( 541 | text = entry.name, 542 | style = MaterialTheme.typography.headlineSmall, 543 | color = TweaksTheme.colors.tweaksOnBackground, 544 | fontWeight = FontWeight.Bold, 545 | modifier = Modifier.weight(1f, false) 546 | ) 547 | if (shouldShowOverriddenLabel) { 548 | Text( 549 | " (Modified)", 550 | style = MaterialTheme.typography.labelMedium, 551 | color = TweaksTheme.colors.tweaksColorModified, 552 | ) 553 | } 554 | } 555 | } 556 | 557 | @Composable 558 | private fun tweaksButtonColors(): ButtonColors = ButtonDefaults.buttonColors( 559 | containerColor = TweaksTheme.colors.tweaksPrimary, 560 | contentColor = contentColorFor(backgroundColor = TweaksTheme.colors.tweaksBackground), 561 | disabledContainerColor = TweaksTheme.colors.tweaksOnSurface.copy(alpha = 0.12f) 562 | .compositeOver(TweaksTheme.colors.tweaksSurface), 563 | disabledContentColor = TweaksTheme.colors.tweaksOnSurface.copy(alpha = 0.38f) 564 | .compositeOver(TweaksTheme.colors.tweaksSurface), 565 | ) 566 | 567 | @Composable 568 | private fun tweaksCheckboxColors(): CheckboxColors = CheckboxDefaults.colors( 569 | checkedColor = TweaksTheme.colors.tweaksPrimary, 570 | checkmarkColor = TweaksTheme.colors.tweaksOnPrimary, 571 | uncheckedColor = TweaksTheme.colors.tweaksPrimary, 572 | ) 573 | 574 | @Composable 575 | private fun tweaksTextFieldColors(): TextFieldColors = 576 | TextFieldDefaults.colors( 577 | focusedTextColor = TweaksTheme.colors.tweaksOnBackground, 578 | disabledTextColor = TweaksTheme.colors.tweaksOnBackground.copy(alpha = 0.8F), 579 | cursorColor = TweaksTheme.colors.tweaksPrimary, 580 | focusedLabelColor = TweaksTheme.colors.tweaksPrimary, 581 | focusedIndicatorColor = TweaksTheme.colors.tweaksPrimary, 582 | unfocusedIndicatorColor = TweaksTheme.colors.tweaksPrimary, 583 | unfocusedLabelColor = TweaksTheme.colors.tweaksPrimary, 584 | disabledLabelColor = TweaksTheme.colors.tweaksPrimary 585 | ) 586 | 587 | @Composable 588 | internal fun TweakButton( 589 | onClick: () -> Unit, 590 | modifier: Modifier = Modifier, 591 | text: String, 592 | ) { 593 | Button( 594 | onClick = onClick, 595 | modifier = modifier.fillMaxWidth(), 596 | colors = tweaksButtonColors() 597 | ) { 598 | Text( 599 | text = text, 600 | color = TweaksTheme.colors.tweaksOnPrimary, 601 | ) 602 | } 603 | } -------------------------------------------------------------------------------- /library/src/enabled/java/com/telefonica/tweaks/ui/TweakGroupViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.telefonica.tweaks.ui 2 | 3 | import androidx.lifecycle.ViewModel 4 | import androidx.lifecycle.viewModelScope 5 | import com.telefonica.tweaks.Tweaks 6 | import com.telefonica.tweaks.domain.Editable 7 | import com.telefonica.tweaks.domain.TweakGroup 8 | import com.telefonica.tweaks.domain.TweaksBusinessLogic 9 | import kotlinx.coroutines.launch 10 | 11 | class TweakGroupViewModel( 12 | private val tweaksBusinessLogic: TweaksBusinessLogic = Tweaks.getReference().tweaksBusinessLogic, 13 | ) : ViewModel() { 14 | fun reset(tweakGroup: TweakGroup) { 15 | viewModelScope.launch { 16 | tweakGroup.entries 17 | .filterIsInstance>() 18 | .forEach { 19 | tweaksBusinessLogic.clearValue(it) 20 | } 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /library/src/enabled/java/com/telefonica/tweaks/ui/theme/Color.kt: -------------------------------------------------------------------------------- 1 | package com.telefonica.tweaks.ui.theme 2 | 3 | import androidx.compose.ui.graphics.Color 4 | 5 | 6 | val TweaksGreen = Color(0xFF1EB980) 7 | val TweaksDarkBlue = Color(0xFF26282F) 8 | val TweaksDarkBlueBackground = Color(0xEE26282F) 9 | val TweaksWarningRed = Color(0xFFFF4444) -------------------------------------------------------------------------------- /library/src/enabled/java/com/telefonica/tweaks/ui/theme/Type.kt: -------------------------------------------------------------------------------- 1 | package com.telefonica.tweaks.ui.theme 2 | 3 | import androidx.compose.material3.Typography 4 | import androidx.compose.ui.text.TextStyle 5 | import androidx.compose.ui.text.font.Font 6 | import androidx.compose.ui.text.font.FontFamily 7 | import androidx.compose.ui.text.font.FontWeight 8 | import androidx.compose.ui.unit.em 9 | import androidx.compose.ui.unit.sp 10 | import com.telefonica.tweaks.R 11 | 12 | 13 | private val EczarFontFamily = FontFamily( 14 | Font(R.font.eczar_regular), 15 | Font(R.font.eczar_semibold, FontWeight.SemiBold) 16 | ) 17 | private val RobotoCondensed = FontFamily( 18 | Font(R.font.robotocondensed_regular), 19 | Font(R.font.robotocondensed_light, FontWeight.Light), 20 | Font(R.font.robotocondensed_bold, FontWeight.Bold) 21 | ) 22 | 23 | val TweaksTypography = Typography( 24 | displayLarge = TextStyle( 25 | fontWeight = FontWeight.W100, 26 | fontSize = 96.sp, 27 | fontFamily = RobotoCondensed 28 | ), 29 | displayMedium = TextStyle( 30 | fontWeight = FontWeight.SemiBold, 31 | fontSize = 44.sp, 32 | fontFamily = EczarFontFamily, 33 | letterSpacing = 1.5.sp 34 | ), 35 | displaySmall = TextStyle( 36 | fontWeight = FontWeight.W400, 37 | fontSize = 14.sp, 38 | fontFamily = RobotoCondensed 39 | ), 40 | headlineLarge = TextStyle( 41 | fontWeight = FontWeight.W700, 42 | fontSize = 34.sp, 43 | fontFamily = RobotoCondensed 44 | ), 45 | headlineMedium = TextStyle( 46 | fontWeight = FontWeight.W700, 47 | fontSize = 24.sp, 48 | fontFamily = RobotoCondensed 49 | ), 50 | headlineSmall = TextStyle( 51 | fontWeight = FontWeight.Normal, 52 | fontSize = 18.sp, 53 | lineHeight = 20.sp, 54 | fontFamily = EczarFontFamily, 55 | letterSpacing = 3.sp 56 | ), 57 | titleLarge = TextStyle( 58 | fontWeight = FontWeight.Light, 59 | fontSize = 14.sp, 60 | lineHeight = 20.sp, 61 | letterSpacing = 3.sp, 62 | fontFamily = RobotoCondensed 63 | ), 64 | titleMedium = TextStyle( 65 | fontWeight = FontWeight.Normal, 66 | fontSize = 14.sp, 67 | letterSpacing = 0.1.em, 68 | fontFamily = RobotoCondensed 69 | ), 70 | bodyLarge = TextStyle( 71 | fontWeight = FontWeight.Normal, 72 | fontSize = 16.sp, 73 | letterSpacing = 0.1.em, 74 | fontFamily = RobotoCondensed 75 | ), 76 | bodyMedium = TextStyle( 77 | fontWeight = FontWeight.Normal, 78 | fontSize = 14.sp, 79 | lineHeight = 20.sp, 80 | letterSpacing = 0.1.em, 81 | fontFamily = RobotoCondensed 82 | ), 83 | labelLarge = TextStyle( 84 | fontWeight = FontWeight.Bold, 85 | fontSize = 14.sp, 86 | lineHeight = 16.sp, 87 | letterSpacing = 0.2.em, 88 | fontFamily = RobotoCondensed 89 | ), 90 | labelMedium = TextStyle( 91 | fontWeight = FontWeight.W500, 92 | fontSize = 12.sp, 93 | fontFamily = RobotoCondensed 94 | ), 95 | labelSmall = TextStyle( 96 | fontWeight = FontWeight.W500, 97 | fontSize = 10.sp, 98 | fontFamily = RobotoCondensed 99 | ) 100 | ) -------------------------------------------------------------------------------- /library/src/enabled/res/font/eczar_regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telefonica/tweaks/93082eece7221fc50f3cf9d02a05a2e27d618186/library/src/enabled/res/font/eczar_regular.ttf -------------------------------------------------------------------------------- /library/src/enabled/res/font/eczar_semibold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telefonica/tweaks/93082eece7221fc50f3cf9d02a05a2e27d618186/library/src/enabled/res/font/eczar_semibold.ttf -------------------------------------------------------------------------------- /library/src/enabled/res/font/robotocondensed_bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telefonica/tweaks/93082eece7221fc50f3cf9d02a05a2e27d618186/library/src/enabled/res/font/robotocondensed_bold.ttf -------------------------------------------------------------------------------- /library/src/enabled/res/font/robotocondensed_light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telefonica/tweaks/93082eece7221fc50f3cf9d02a05a2e27d618186/library/src/enabled/res/font/robotocondensed_light.ttf -------------------------------------------------------------------------------- /library/src/enabled/res/font/robotocondensed_regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telefonica/tweaks/93082eece7221fc50f3cf9d02a05a2e27d618186/library/src/enabled/res/font/robotocondensed_regular.ttf -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /library/src/main/java/com/telefonica/tweaks/TweaksContract.kt: -------------------------------------------------------------------------------- 1 | package com.telefonica.tweaks 2 | 3 | import kotlinx.coroutines.flow.Flow 4 | 5 | 6 | interface TweaksContract { 7 | 8 | fun getTweakValue(key: String): Flow 9 | 10 | fun getTweakValue(key: String, defaultValue: T): Flow 11 | 12 | suspend fun getTweak(key: String): T? 13 | 14 | suspend fun getTweak(key: String, defaultValue: T): T 15 | 16 | suspend fun setTweakValue(key: String, value: T) 17 | 18 | suspend fun clearValue(key: String) 19 | 20 | 21 | } -------------------------------------------------------------------------------- /library/src/main/java/com/telefonica/tweaks/domain/tweakModels.kt: -------------------------------------------------------------------------------- 1 | package com.telefonica.tweaks.domain 2 | 3 | import androidx.navigation.NavController 4 | import kotlinx.coroutines.flow.Flow 5 | import kotlinx.coroutines.flow.flowOf 6 | 7 | fun tweaksGraph(block: TweaksGraph.Builder.() -> Unit): TweaksGraph { 8 | val builder = TweaksGraph.Builder() 9 | builder.block() 10 | return builder.build() 11 | } 12 | 13 | /** The top level node of the tweak graphs. It contains a list of categories (screens)*/ 14 | data class TweaksGraph(val cover: TweakGroup?, val categories: List) { 15 | class Builder { 16 | private val categories = mutableListOf() 17 | private var cover: TweakGroup? = null 18 | 19 | fun cover(title: String, withClearButton: Boolean = true, block: TweakGroup.Builder.() -> Unit) { 20 | val builder = TweakGroup.Builder(title, withClearButton) 21 | builder.block() 22 | cover = builder.build() 23 | } 24 | 25 | fun category(title: String, block: TweakCategory.Builder.() -> Unit) { 26 | val builder = TweakCategory.Builder(title) 27 | builder.block() 28 | categories.add(builder.build()) 29 | } 30 | 31 | internal fun build(): TweaksGraph = TweaksGraph(cover, categories) 32 | } 33 | } 34 | 35 | /** A tweak category is a screen, for example your app tweaks can be splitted by features 36 | * (chat, video, login...) each one of those can be a category 37 | * */ 38 | data class TweakCategory(val title: String, val groups: List) { 39 | class Builder(private val title: String) { 40 | private val groups = mutableListOf() 41 | 42 | fun group( 43 | title: String, 44 | withClearButton: Boolean = true, 45 | block: TweakGroup.Builder.() -> Unit, 46 | ) { 47 | val builder = TweakGroup.Builder(title, withClearButton) 48 | builder.block() 49 | groups.add(builder.build()) 50 | } 51 | 52 | internal fun build(): TweakCategory = TweakCategory(title, groups) 53 | } 54 | } 55 | 56 | /** A bunch of tweaks that are related to each other, for example: domain & port for the backend server configurations*/ 57 | data class TweakGroup(val title: String, val withClearButton: Boolean = true, val entries: List) { 58 | class Builder( 59 | private val title: String, 60 | private val withClearButton: Boolean = true, 61 | ) { 62 | private val entries = mutableListOf() 63 | 64 | fun tweak(entry: TweakEntry) { 65 | entries.add(entry) 66 | } 67 | 68 | fun button( 69 | name: String, 70 | action: () -> Unit, 71 | ) { 72 | tweak(ButtonTweakEntry(name, action)) 73 | } 74 | 75 | fun routeButton( 76 | name: String, 77 | route: String, 78 | ) { 79 | tweak(RouteButtonTweakEntry(name, route)) 80 | } 81 | 82 | fun customNavigationButton( 83 | name: String, 84 | navigation: (NavController) -> Unit, 85 | ) { 86 | tweak(CustomNavigationButtonTweakEntry(name, navigation)) 87 | } 88 | 89 | fun label( 90 | name: String, 91 | value: () -> Flow, 92 | ) { 93 | tweak(ReadOnlyStringTweakEntry(name, value())) 94 | } 95 | 96 | fun editableString( 97 | key: String, 98 | name: String, 99 | defaultValue: Flow? = null, 100 | ) { 101 | tweak(EditableStringTweakEntry(key, name, defaultValue)) 102 | } 103 | 104 | fun editableString( 105 | key: String, 106 | name: String, 107 | defaultValue: String, 108 | ) { 109 | tweak(EditableStringTweakEntry(key, name, defaultValue)) 110 | } 111 | 112 | fun editableBoolean( 113 | key: String, 114 | name: String, 115 | defaultValue: Flow? = null, 116 | ) { 117 | tweak(EditableBooleanTweakEntry(key, name, defaultValue)) 118 | } 119 | 120 | fun editableBoolean( 121 | key: String, 122 | name: String, 123 | defaultValue: Boolean, 124 | ) { 125 | tweak(EditableBooleanTweakEntry(key, name, defaultValue)) 126 | } 127 | 128 | fun editableInt( 129 | key: String, 130 | name: String, 131 | defaultValue: Flow? = null, 132 | ) { 133 | tweak(EditableIntTweakEntry(key, name, defaultValue)) 134 | } 135 | 136 | fun editableInt( 137 | key: String, 138 | name: String, 139 | defaultValue: Int, 140 | ) { 141 | tweak(EditableIntTweakEntry(key, name, defaultValue)) 142 | } 143 | 144 | fun editableLong( 145 | key: String, 146 | name: String, 147 | defaultValue: Flow? = null, 148 | ) { 149 | tweak(EditableLongTweakEntry(key, name, defaultValue)) 150 | } 151 | 152 | fun editableLong( 153 | key: String, 154 | name: String, 155 | defaultValue: Long, 156 | ) { 157 | tweak(EditableLongTweakEntry(key, name, defaultValue)) 158 | } 159 | 160 | fun dropDownMenu( 161 | key: String, 162 | name: String, 163 | values: List, 164 | defaultValue: Flow, 165 | ) { 166 | tweak(DropDownMenuTweakEntry(key, name, values, defaultValue)) 167 | } 168 | 169 | internal fun build(): TweakGroup = TweakGroup(title, withClearButton, entries) 170 | } 171 | } 172 | 173 | sealed class TweakEntry( 174 | val name: String, 175 | ) : Modifiable 176 | 177 | sealed interface Modifiable 178 | interface Editable : Modifiable { 179 | val key: String 180 | val defaultValue: Flow? 181 | } 182 | 183 | interface ReadOnly : Modifiable { 184 | val value: Flow 185 | } 186 | 187 | /** A button, with a customizable action*/ 188 | class ButtonTweakEntry(name: String, val action: () -> Unit) : 189 | TweakEntry(name = name) 190 | 191 | /** A button, that when tapped navigates to a route*/ 192 | class RouteButtonTweakEntry(name: String, val route: String) : 193 | TweakEntry(name = name) 194 | 195 | /** 196 | * A button, that when tapped will execute the navigation specified 197 | * using the NavController it receives as param 198 | */ 199 | class CustomNavigationButtonTweakEntry( 200 | name: String, 201 | val navigation: (NavController) -> Unit, 202 | ) : TweakEntry(name = name) 203 | 204 | /** A non editable entry */ 205 | class ReadOnlyStringTweakEntry( 206 | name: String, 207 | override val value: Flow, 208 | ) : TweakEntry(name), ReadOnly 209 | 210 | /** An editable entry. It can be modified by using long-press*/ 211 | class EditableStringTweakEntry( 212 | override val key: String, 213 | name: String, 214 | override val defaultValue: Flow? = null, 215 | ) : TweakEntry(name = name), Editable { 216 | constructor( 217 | key: String, 218 | name: String, 219 | defaultUniqueValue: String, 220 | ) : this(key, name, flowOf(defaultUniqueValue)) 221 | } 222 | 223 | /** An editable entry. It can be modified by using long-press*/ 224 | class EditableBooleanTweakEntry( 225 | override val key: String, 226 | name: String, 227 | override val defaultValue: Flow? = null, 228 | ) : TweakEntry(name = name), Editable { 229 | constructor( 230 | key: String, 231 | name: String, 232 | defaultUniqueValue: Boolean, 233 | ) : this(key, name, flowOf(defaultUniqueValue)) 234 | } 235 | 236 | /** An editable entry. It can be modified by using long-press*/ 237 | class EditableIntTweakEntry( 238 | override val key: String, 239 | name: String, 240 | override val defaultValue: Flow? = null, 241 | ) : TweakEntry(name), Editable { 242 | constructor( 243 | key: String, 244 | name: String, 245 | defaultUniqueValue: Int, 246 | ) : this(key, name, flowOf(defaultUniqueValue)) 247 | } 248 | 249 | /** An editable entry. It can be modified by using long-press*/ 250 | class EditableLongTweakEntry( 251 | override val key: String, 252 | name: String, 253 | override val defaultValue: Flow? = null, 254 | ) : TweakEntry(name = name), Editable { 255 | constructor( 256 | key: String, 257 | name: String, 258 | defaultUniqueValue: Long, 259 | ) : this(key, name, flowOf(defaultUniqueValue)) 260 | } 261 | 262 | class DropDownMenuTweakEntry( 263 | override val key: String, 264 | name: String, 265 | val values: List, 266 | override val defaultValue: Flow, 267 | ) : TweakEntry(name = name), Editable { 268 | constructor( 269 | key: String, 270 | name: String, 271 | values: List, 272 | defaultValue: String, 273 | ) : this(key, name, values, flowOf(defaultValue)) 274 | } 275 | 276 | internal object Constants { 277 | const val TWEAK_MAIN_SCREEN = "tweaks-main-screen" 278 | } -------------------------------------------------------------------------------- /library/src/noop/java/com/telefonica/tweaks/Tweaks.kt: -------------------------------------------------------------------------------- 1 | package com.telefonica.tweaks 2 | 3 | import android.content.Context 4 | import androidx.compose.runtime.Composable 5 | import androidx.navigation.NavController 6 | import androidx.navigation.NavGraphBuilder 7 | import com.telefonica.tweaks.domain.* 8 | import kotlinx.coroutines.flow.Flow 9 | import kotlinx.coroutines.flow.firstOrNull 10 | import kotlinx.coroutines.flow.flowOf 11 | import kotlinx.coroutines.flow.map 12 | 13 | open class Tweaks : TweaksContract { 14 | 15 | private val keyToEntryValueMap: MutableMap> = mutableMapOf() 16 | 17 | @Suppress("UNCHECKED_CAST") 18 | override fun getTweakValue(key: String): Flow { 19 | val entry= keyToEntryValueMap[key] as TweakEntry 20 | return getTweakValue(entry) 21 | } 22 | 23 | override fun getTweakValue(key: String, defaultValue: T): Flow = 24 | getTweakValue(key).map { it ?: defaultValue } 25 | 26 | override suspend fun getTweak(key: String): T? = 27 | getTweakValue(key).firstOrNull() 28 | 29 | override suspend fun getTweak(key: String, defaultValue: T): T = 30 | getTweak(key) ?: defaultValue 31 | 32 | @Suppress("UNCHECKED_CAST") 33 | private fun getTweakValue(entry: TweakEntry): Flow = when (entry) { 34 | is ReadOnly<*> -> (entry as ReadOnly).value 35 | is Editable<*> -> (entry as Editable).defaultValue ?: flowOf() 36 | else -> flowOf() 37 | } 38 | 39 | override suspend fun setTweakValue(key: String, value: T) {} 40 | 41 | override suspend fun clearValue(key: String) {} 42 | 43 | private fun initialize(tweaksGraph: TweaksGraph) { 44 | val allEntries: List> = tweaksGraph.categories 45 | .flatMap { category -> 46 | category.groups.flatMap { group -> 47 | group.entries 48 | } 49 | }.filterIsInstance>() 50 | allEntries.forEach { entry -> 51 | keyToEntryValueMap[entry.key] = entry 52 | } 53 | } 54 | 55 | companion object { 56 | const val TWEAKS_NAVIGATION_ENTRYPOINT = "tweaks" 57 | private var reference: Tweaks = Tweaks() 58 | 59 | @JvmStatic 60 | fun init( 61 | context: Context, 62 | tweaksGraph: TweaksGraph, 63 | ) { 64 | reference.initialize(tweaksGraph) 65 | } 66 | 67 | @JvmStatic 68 | fun getReference(): Tweaks = reference 69 | } 70 | 71 | 72 | } 73 | 74 | fun NavGraphBuilder.addTweakGraph( 75 | navController: NavController, 76 | tweaksCustomTheme: @Composable (block: @Composable () -> Unit) -> Unit = { it() }, 77 | customComposableScreens: NavGraphBuilder.() -> Unit = {}, 78 | ) {} 79 | 80 | @Composable 81 | fun NavController.navigateToTweaksOnShake() {} 82 | 83 | @Composable 84 | fun NavigateToTweaksOnShake(onOpenTweaks: () -> Unit) {} 85 | -------------------------------------------------------------------------------- /library/src/noop/java/com/telefonica/tweaks/ui/theme/Theme.kt: -------------------------------------------------------------------------------- 1 | package com.telefonica.tweaks.ui.theme 2 | 3 | import androidx.compose.runtime.Composable 4 | 5 | @Composable 6 | fun DebugTweaksTheme( 7 | content: @Composable () -> Unit 8 | ) { 9 | content() 10 | } -------------------------------------------------------------------------------- /library/src/testEnabled/java/com/telefonica/tweaks/domain/TweaksBusinessLogicTest.kt: -------------------------------------------------------------------------------- 1 | package com.telefonica.tweaks.domain 2 | 3 | import com.telefonica.tweaks.data.TweaksRepository 4 | import junit.framework.Assert.assertEquals 5 | import kotlinx.coroutines.flow.first 6 | import kotlinx.coroutines.flow.flowOf 7 | import kotlinx.coroutines.runBlocking 8 | import org.junit.Test 9 | import org.mockito.kotlin.any 10 | import org.mockito.kotlin.mock 11 | import org.mockito.kotlin.whenever 12 | 13 | class TweaksBusinessLogicTest { 14 | 15 | private val tweaksRepository: TweaksRepository = mock() 16 | private val sut: TweaksBusinessLogic = TweaksBusinessLogic(tweaksRepository) 17 | 18 | @Test 19 | fun `a tweak added as a cover is in the graph`() = runBlocking { 20 | val graph = givenATweaksGraphThatHasACover() 21 | 22 | sut.initialize(graph) 23 | 24 | val result = sut.getValue(A_COVER_ENTRY_KEY).first() 25 | assertEquals(A_COVER_ENTRY_VALUE, result) 26 | } 27 | 28 | private fun givenATweaksGraphThatHasACover(): TweaksGraph = tweaksGraph { 29 | cover(COVER_TITLE) { 30 | editableString(key = A_COVER_ENTRY_KEY, name = A_COVER_ENTRY_NAME, defaultValue = A_COVER_ENTRY_VALUE) 31 | } 32 | 33 | whenever(tweaksRepository.isOverriden(any())).thenReturn(flowOf(false)) 34 | } 35 | 36 | companion object { 37 | private const val A_COVER_ENTRY_KEY = "cover-entry-key" 38 | private const val A_COVER_ENTRY_NAME = "Cover entry name" 39 | private const val A_COVER_ENTRY_VALUE = "Cover entry value" 40 | private const val COVER_TITLE = "Cover" 41 | } 42 | } -------------------------------------------------------------------------------- /mavencentral.gradle: -------------------------------------------------------------------------------- 1 | task enabledSourcesJar(type: Jar) { 2 | archiveClassifier.set('sources') 3 | from android.sourceSets.main.java.srcDirs 4 | from android.sourceSets.enabled.java.srcDirs 5 | } 6 | 7 | artifacts { 8 | archives enabledSourcesJar 9 | } 10 | 11 | apply plugin: 'maven-publish' 12 | apply plugin: 'signing' 13 | 14 | ext { 15 | PUBLISH_GROUP_ID = 'com.telefonica' 16 | PUBLISH_ARTIFACT_ID = 'tweaks' 17 | PUBLISH_VERSION = version 18 | 19 | PUBLISH_RELEASE_NAME = 'Tweaks for Android' 20 | PUBLISH_DESCRIPTION = 'A customizable debug screen to view and edit flags that can be used for development in Jetpack Compose applications' 21 | PUBLISH_REPO_URL = 'https://github.com/Telefonica/tweaks' 22 | } 23 | 24 | publishing { 25 | publications { 26 | release(MavenPublication) { 27 | groupId PUBLISH_GROUP_ID 28 | artifactId PUBLISH_ARTIFACT_ID 29 | version PUBLISH_VERSION 30 | 31 | artifact("$buildDir/outputs/aar/${project.getName()}-enabled-release.aar") 32 | artifact enabledSourcesJar 33 | 34 | pom { 35 | name = PUBLISH_RELEASE_NAME 36 | description = PUBLISH_DESCRIPTION 37 | url = PUBLISH_REPO_URL 38 | licenses { 39 | license { 40 | name = 'The Apache License, Version 2.0' 41 | url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 42 | } 43 | } 44 | developers { 45 | developer { 46 | id = 'android-team-telefonica' 47 | name = 'Android Team' 48 | email = 'cto-android@telefonica.com' 49 | } 50 | } 51 | scm { 52 | connection = 'scm:git:https://github.com/Telefonica/tweaks.git' 53 | developerConnection = 'scm:git:ssh://https://github.com/Telefonica/tweaks.git' 54 | url = 'https://github.com/Telefonica/tweaks/tree/main' 55 | } 56 | withXml { 57 | def dependenciesNode = asNode().appendNode('dependencies') 58 | 59 | project.configurations.getByName("implementation").allDependencies.each { 60 | def dependencyNode = dependenciesNode.appendNode('dependency') 61 | dependencyNode.appendNode('groupId', it.group) 62 | dependencyNode.appendNode('artifactId', it.name) 63 | dependencyNode.appendNode('version', it.version) 64 | } 65 | project.configurations.getByName("enabledImplementation").allDependencies.each { 66 | def dependencyNode = dependenciesNode.appendNode('dependency') 67 | dependencyNode.appendNode('groupId', it.group) 68 | dependencyNode.appendNode('artifactId', it.name) 69 | dependencyNode.appendNode('version', it.version) 70 | } 71 | } 72 | } 73 | } 74 | noop(MavenPublication) { 75 | groupId PUBLISH_GROUP_ID 76 | artifactId "$PUBLISH_ARTIFACT_ID-no-op" 77 | version PUBLISH_VERSION 78 | 79 | artifact("$buildDir/outputs/aar/${project.getName()}-noop-release.aar") 80 | 81 | pom { 82 | name = "$PUBLISH_RELEASE_NAME-no-op" 83 | description = PUBLISH_DESCRIPTION 84 | url = PUBLISH_REPO_URL 85 | licenses { 86 | license { 87 | name = 'The Apache License, Version 2.0' 88 | url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 89 | } 90 | } 91 | developers { 92 | developer { 93 | id = 'android-team-telefonica' 94 | name = 'Android Team' 95 | email = 'cto-android@telefonica.com' 96 | } 97 | } 98 | scm { 99 | connection = 'scm:git:https://github.com/Telefonica/tweaks.git' 100 | developerConnection = 'scm:git:ssh://https://github.com/Telefonica/tweaks.git' 101 | url = 'https://github.com/Telefonica/tweaks/tree/main' 102 | } 103 | withXml { 104 | def dependenciesNode = asNode().appendNode('dependencies') 105 | 106 | project.configurations.getByName("implementation").allDependencies.each { 107 | def dependencyNode = dependenciesNode.appendNode('dependency') 108 | dependencyNode.appendNode('groupId', it.group) 109 | dependencyNode.appendNode('artifactId', it.name) 110 | dependencyNode.appendNode('version', it.version) 111 | } 112 | } 113 | } 114 | } 115 | } 116 | 117 | } 118 | 119 | signing { 120 | def signingKeyId = findProperty("signingKeyId") 121 | def signingKey = findProperty("signingKey") 122 | def signingPassword = findProperty("signingPassword") 123 | useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword) 124 | sign publishing.publications 125 | } 126 | -------------------------------------------------------------------------------- /objects: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Telefonica/tweaks/93082eece7221fc50f3cf9d02a05a2e27d618186/objects -------------------------------------------------------------------------------- /publish_maven_central.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'io.github.gradle-nexus.publish-plugin' 2 | 3 | nexusPublishing { 4 | repositories { 5 | sonatype { 6 | stagingProfileId = "f7fe7699e57a" 7 | username = System.getenv("MOBILE_MAVENCENTRAL_USER") 8 | password = System.getenv("MOBILE_MAVENCENTRAL_PASSWORD") 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | dependencyResolutionManagement { 2 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 3 | repositories { 4 | gradlePluginPortal() 5 | google() 6 | mavenCentral() 7 | } 8 | } 9 | rootProject.name = "tweaks" 10 | include ':app' 11 | include ':library' 12 | --------------------------------------------------------------------------------