├── .github
└── ISSUE_TEMPLATE
│ └── custom.md
├── .gitignore
├── CODE_OF_CONDUCT.md
├── LICENSE.md
├── PULL_REQUEST_TEMPLATE.md
├── README.md
├── app
├── .github
│ └── ISSUE_TEMPLATE
│ │ ├── Bug_report.md
│ │ ├── Custom.md
│ │ └── Feature_request.md
├── .gitignore
├── .idea
│ ├── .gitignore
│ ├── gradle.xml
│ ├── misc.xml
│ ├── modules.xml
│ ├── runConfigurations.xml
│ └── vcs.xml
├── build.gradle
├── local.properties
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── madonasyombua
│ │ └── sportsdb
│ │ ├── ExampleInstrumentedTest.kt
│ │ └── uitests
│ │ ├── MainActivityTest.kt
│ │ └── ScreenUnitTests.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── madonasyombua
│ │ │ └── sportsdb
│ │ │ ├── app
│ │ │ ├── App.kt
│ │ │ ├── AppModule.kt
│ │ │ ├── NetworkModule.kt
│ │ │ └── SportsApp.kt
│ │ │ ├── data
│ │ │ ├── Repository.kt
│ │ │ ├── local
│ │ │ │ ├── dao
│ │ │ │ │ ├── MatchDao.kt
│ │ │ │ │ └── TeamDao.kt
│ │ │ │ ├── database
│ │ │ │ │ └── SportDB.kt
│ │ │ │ └── entities
│ │ │ │ │ ├── MatchEntity.kt
│ │ │ │ │ └── TeamEntity.kt
│ │ │ └── remote
│ │ │ │ ├── api
│ │ │ │ └── Api.kt
│ │ │ │ ├── model
│ │ │ │ ├── Equipment.kt
│ │ │ │ ├── Event.kt
│ │ │ │ ├── League.kt
│ │ │ │ ├── LeagueTable.kt
│ │ │ │ └── TeamByLeague.kt
│ │ │ │ └── response
│ │ │ │ ├── EquipmentResponse.kt
│ │ │ │ ├── EventResponse.kt
│ │ │ │ ├── LeagueResponse.kt
│ │ │ │ ├── LeagueTableResponse.kt
│ │ │ │ ├── MatchBaseResponse.kt
│ │ │ │ ├── SportsBaseResponse.kt
│ │ │ │ └── TeamsResponse.kt
│ │ │ └── ui
│ │ │ ├── MainActivity.kt
│ │ │ ├── components
│ │ │ └── AppBar.kt
│ │ │ ├── screen
│ │ │ ├── home
│ │ │ │ ├── HomeScreen.kt
│ │ │ │ ├── HomeViewModel.kt
│ │ │ │ ├── LeagueTabrow.kt
│ │ │ │ └── teams
│ │ │ │ │ ├── TeamsByLeague.kt
│ │ │ │ │ └── TeamsViewModel.kt
│ │ │ └── teamdetails
│ │ │ │ ├── TeamDetails.kt
│ │ │ │ ├── TeamLeagueTable.kt
│ │ │ │ ├── equipment
│ │ │ │ └── TeamEquipments.kt
│ │ │ │ └── event
│ │ │ │ ├── TeamEventViewModel.kt
│ │ │ │ └── TeamLastEvents.kt
│ │ │ └── theme
│ │ │ ├── Color.kt
│ │ │ ├── Shape.kt
│ │ │ ├── Theme.kt
│ │ │ └── Type.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── background_normal.png
│ │ ├── ic_launcher_background.xml
│ │ └── logo.png
│ │ ├── font
│ │ ├── domine_bold.ttf
│ │ ├── domine_regular.ttf
│ │ ├── font.xml
│ │ ├── montserrat_medium.ttf
│ │ ├── montserrat_regular.ttf
│ │ ├── montserrat_semibold.ttf
│ │ └── raleway.ttf
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_icon.png
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_icon.png
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_icon.png
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_icon.png
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_icon.png
│ │ └── ic_launcher.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── madonasyombua
│ └── sportsdb
│ ├── ExampleUnitTest.kt
│ └── tests
│ ├── LiveDataUtilTest.kt
│ ├── MatchDBTests.kt
│ └── TeamDBTests.kt
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── screenshots
├── events.png
├── events_dark.png
├── home.png
├── home_dark.png
└── new_home.png
└── settings.gradle
/.github/ISSUE_TEMPLATE/custom.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Custom issue template
3 | about: Describe this issue template's purpose here.
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /app/*.json
4 | /local.properties
5 | /.idea
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Pledge
4 |
5 | * Using welcoming and inclusive language
6 | * Being respectful of differing viewpoints and experiences
7 | * Gracefully accepting constructive criticism
8 | * Focusing on what is best for the community
9 | * Showing empathy towards other community members
10 |
11 | Examples of unacceptable behavior by participants include:
12 |
13 | * The use of sexualized language or imagery and unwelcome sexual attention or advances
14 | * Trolling, insulting/derogatory comments, and personal or political attacks
15 | * Public or private harassment
16 | * Publishing others' private information, such as a physical or electronic address, without explicit permission
17 | * Other conduct which could reasonably be considered inappropriate in a professional setting
18 |
19 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
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 [2018] [Madonah Syombua]
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 |
--------------------------------------------------------------------------------
/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Please Add Description
2 |
3 | ## Run a test check first to confirm no conflicts before creating a PR
4 |
5 | ## Screenshots (if needed):
6 |
7 | ## Detailed commit.
8 |
9 |
10 | # Checklist:
11 | - My code follows the code style of this project.
12 |
13 | - My change requires a change to the documentation.
14 |
15 | - I have updated the documentation accordingly.
16 |
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | # The Sports DB
9 | Just a personal project playing with the free [SportsDB](https://www.thesportsdb.com/api.php?ref=apilist.fun) using JetpackCompose
10 |
11 | ## Screen 1 & 2:
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | ## Draft User Interface Mock
32 | 
33 |
34 |
35 | ## License
36 |
37 | ```
38 | Copyright [2020] [Madona Syombua]
39 |
40 | Licensed under the Apache License, Version 2.0 (the "License");
41 | you may not use this file except in compliance with the License.
42 | You may obtain a copy of the License at
43 |
44 | http://www.apache.org/licenses/LICENSE-2.0
45 |
46 | Unless required by applicable law or agreed to in writing, software
47 | distributed under the License is distributed on an "AS IS" BASIS,
48 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
49 | See the License for the specific language governing permissions and
50 | limitations under the License.
51 |
52 | ```
53 |
--------------------------------------------------------------------------------
/app/.github/ISSUE_TEMPLATE/Bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 |
5 | ---
6 |
7 | **Describe the bug**
8 | A clear and concise description of what the bug is.
9 |
10 | **To Reproduce**
11 | Steps to reproduce the behavior:
12 | 1. Go to '...'
13 | 2. Click on '....'
14 | 3. Scroll down to '....'
15 | 4. See error
16 |
17 | **Expected behavior**
18 | A clear and concise description of what you expected to happen.
19 |
20 | **Screenshots**
21 | If applicable, add screenshots to help explain your problem.
22 |
23 | **Desktop (please complete the following information):**
24 | - OS: [e.g. iOS]
25 | - Browser [e.g. chrome, safari]
26 | - Version [e.g. 22]
27 |
28 | **Smartphone (please complete the following information):**
29 | - Device: [e.g. iPhone6]
30 | - OS: [e.g. iOS8.1]
31 | - Browser [e.g. stock browser, safari]
32 | - Version [e.g. 22]
33 |
34 | **Additional context**
35 | Add any other context about the problem here.
36 |
--------------------------------------------------------------------------------
/app/.github/ISSUE_TEMPLATE/Custom.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Custom issue template
3 | about: Describe this issue template's purpose here.
4 |
5 | ---
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/.github/ISSUE_TEMPLATE/Feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 |
5 | ---
6 |
7 | **Is your feature request related to a problem? Please describe.**
8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
9 |
10 | **Describe the solution you'd like**
11 | A clear and concise description of what you want to happen.
12 |
13 | **Describe alternatives you've considered**
14 | A clear and concise description of any alternative solutions or features you've considered.
15 |
16 | **Additional context**
17 | Add any other context or screenshots about the feature request here.
18 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/app/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-kapt'
4 | apply plugin: 'dagger.hilt.android.plugin'
5 |
6 | android {
7 | compileSdkVersion 31
8 | defaultConfig {
9 | applicationId "com.madonasyombua.sportsdb"
10 | minSdkVersion 24
11 | targetSdkVersion 31
12 | versionCode 1
13 | versionName "1.0"
14 | multiDexEnabled true
15 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 |
24 | buildFeatures{
25 | compose true
26 | }
27 |
28 | compileOptions {
29 | sourceCompatibility JavaVersion.VERSION_1_8
30 | targetCompatibility JavaVersion.VERSION_1_8
31 | }
32 | kotlinOptions {
33 | jvmTarget = "1.8"
34 | }
35 | composeOptions {
36 | kotlinCompilerExtensionVersion '1.0.0-beta01'
37 | }
38 |
39 | }
40 | def JUnit = "4.13"
41 | def testRule="1.2.0"
42 | def testRunner='1.2.0'
43 | def mockito='3.3.3'
44 | def timber = '4.7.1'
45 | def room_version = '2.2.5'
46 |
47 | ext {
48 | moshiVersionCodeGen = "1.11.0"
49 | moshiVersion = "1.11.0"
50 | retrofit = "2.9.0"
51 |
52 | }
53 | dependencies {
54 | implementation fileTree(dir: "libs", include: ["*.jar"])
55 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
56 | implementation 'androidx.core:core-ktx:1.7.0'
57 | implementation 'androidx.appcompat:appcompat:1.4.0'
58 | implementation 'com.google.android.material:material:1.4.0'
59 | implementation "androidx.activity:activity-compose:1.4.0"
60 | implementation "androidx.compose.ui:ui:$compose_version"
61 | implementation "androidx.compose.material:material:$compose_version"
62 | implementation "androidx.compose.material:material-icons-extended:$compose_version"
63 | implementation "androidx.compose.ui:ui-tooling:$compose_version"
64 | implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.4.0'
65 | implementation "androidx.navigation:navigation-compose:2.4.0-rc01"
66 | implementation "androidx.compose.runtime:runtime:1.1.0-rc01"
67 | implementation "androidx.compose.runtime:runtime-livedata:1.1.0-rc01"
68 |
69 |
70 | implementation 'androidx.multidex:multidex:2.0.1'
71 | implementation 'androidx.hilt:hilt-navigation-compose:1.0.0-rc01'
72 |
73 |
74 | // retrofit
75 | implementation "com.squareup.moshi:moshi:${moshiVersion}"
76 | implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0'
77 | kapt "com.squareup.moshi:moshi-kotlin-codegen:${moshiVersion}"
78 | implementation "com.squareup.retrofit2:retrofit:${retrofit}"
79 | implementation "com.squareup.retrofit2:converter-moshi:${retrofit}"
80 | implementation "com.squareup.okhttp3:logging-interceptor:4.9.0"
81 |
82 | // hilt
83 | implementation "com.google.dagger:hilt-android:2.39.1"
84 | implementation "androidx.hilt:hilt-common:1.0.0"
85 | implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
86 |
87 | kapt 'androidx.hilt:hilt-compiler:1.0.0'
88 | annotationProcessor "androidx.hilt:hilt-compiler:1.0.0"
89 | kapt "com.google.dagger:hilt-android-compiler:2.39.1"
90 |
91 | androidTestImplementation "com.google.dagger:hilt-android-testing:2.39.1"
92 | kaptAndroidTest "com.google.dagger:hilt-compiler:2.39.1"
93 |
94 | implementation "dev.chrisbanes.accompanist:accompanist-coil:0.6.0"
95 | //Room Persistent Library
96 | implementation "androidx.room:room-runtime:$room_version"
97 | implementation 'com.google.firebase:firebase-crashlytics:18.2.6'
98 | implementation 'com.google.firebase:firebase-analytics:20.0.2'
99 | kapt "androidx.room:room-compiler:$room_version"
100 |
101 | // Testing
102 | testImplementation "junit:junit:$JUnit"
103 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
104 | androidTestImplementation 'androidx.arch.core:core-testing:2.1.0'
105 | // RxJava
106 | implementation 'io.reactivex.rxjava2:rxkotlin:2.4.0'
107 | implementation "io.reactivex.rxjava2:rxandroid:2.1.1"
108 | implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'
109 |
110 |
111 | //mockito
112 | androidTestImplementation "org.mockito:mockito-android:$mockito"
113 | testImplementation "org.mockito:mockito-core:$mockito"
114 | testImplementation "org.mockito:mockito-inline:$mockito"
115 | testImplementation "org.robolectric:robolectric:4.4"
116 |
117 |
118 | testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
119 | implementation "com.jakewharton.timber:timber:$timber"
120 | androidTestImplementation "androidx.test:rules:$testRule"
121 | androidTestImplementation "androidx.test:runner:$testRunner"
122 | androidTestImplementation "com.android.support.test.espresso:espresso-core:3.0.2"
123 | androidTestImplementation "com.android.support.test.espresso:espresso-intents:3.0.2"
124 | androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
125 | exclude group: 'com.android.support', module: 'support-annotations'
126 | })
127 | implementation 'org.jetbrains:annotations:16.0.1'
128 | annotationProcessor 'androidx.room:room-compiler:2.2.5'
129 |
130 | }
--------------------------------------------------------------------------------
/app/local.properties:
--------------------------------------------------------------------------------
1 | ## This file must *NOT* be checked into Version Control Systems,
2 | # as it contains information specific to your local configuration.
3 | #
4 | # Location of the SDK. This is only used by Gradle.
5 | # For customization when using a Version Control System, please read the
6 | # header note.
7 | #Fri Mar 26 15:52:24 CDT 2021
8 | sdk.dir=/Users/madona/Library/Android/sdk
9 |
--------------------------------------------------------------------------------
/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
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/madonasyombua/sportsdb/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb
2 |
3 | import androidx.test.ext.junit.runners.AndroidJUnit4
4 | import org.junit.Test
5 | import org.junit.runner.RunWith
6 |
7 | /**
8 | * Instrumented test, which will execute on an Android device.
9 | *
10 | * @see [Testing documentation](http://d.android.com/tools/testing)
11 | */
12 | @RunWith(AndroidJUnit4::class)
13 | class ExampleInstrumentedTest {
14 | @Test
15 | fun useAppContext() {
16 | // Context of the app under test.
17 | }
18 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/madonasyombua/sportsdb/uitests/MainActivityTest.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.uitests
2 |
3 | import androidx.test.ext.junit.runners.AndroidJUnit4
4 | import androidx.test.filters.LargeTest
5 | import com.madonasyombua.sportsdb.ui.MainActivity
6 | import org.junit.Rule
7 | import org.junit.runner.RunWith
8 |
9 | @LargeTest
10 | @RunWith(AndroidJUnit4::class)
11 | class MainActivityTest {
12 |
13 | //Needed rule to start UI
14 | @get:Rule
15 | @JvmField
16 | val activityTestRule = ScreenUnitTests(
17 | activityClass = MainActivity::class.java,
18 | navigateToScreen = {}
19 | )
20 |
21 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/madonasyombua/sportsdb/uitests/ScreenUnitTests.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.uitests
2 |
3 | import android.app.Activity
4 | import android.support.test.InstrumentationRegistry
5 | import androidx.test.rule.ActivityTestRule
6 | import com.madonasyombua.sportsdb.app.App
7 |
8 | class ScreenUnitTests(
9 | activityClass: Class,
10 | private val navigateToScreen: T.() -> Unit,
11 | private val setupMocks: () -> Unit = {}
12 | ) : ActivityTestRule(activityClass) {
13 | @ExperimentalStdlibApi
14 | override fun beforeActivityLaunched() {
15 | val instrumentation = InstrumentationRegistry.getInstrumentation()
16 | (instrumentation.targetContext.applicationContext as App).run {
17 | setupMocks()
18 | }
19 | }
20 |
21 | override fun afterActivityLaunched() {
22 | activity.navigateToScreen()
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
15 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/app/App.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.app
2 |
3 | import android.app.Application
4 | import com.madonasyombua.sportsdb.BuildConfig
5 | import dagger.hilt.android.HiltAndroidApp
6 | import timber.log.Timber
7 |
8 | @HiltAndroidApp
9 | open class App : Application() {
10 |
11 | override fun onCreate() {
12 | super.onCreate()
13 | setTimberConfiguration()
14 | }
15 |
16 | protected open fun setTimberConfiguration() {
17 | if (BuildConfig.DEBUG) {
18 | Timber.plant(Timber.DebugTree())
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/app/AppModule.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.app
2 |
3 | import android.content.Context
4 | import dagger.Module
5 | import dagger.Provides
6 | import dagger.hilt.InstallIn
7 | import dagger.hilt.android.qualifiers.ApplicationContext
8 | import dagger.hilt.components.SingletonComponent
9 | import javax.inject.Singleton
10 |
11 | @Module
12 | @InstallIn(SingletonComponent::class)
13 | object AppModule {
14 |
15 | @Singleton
16 | @Provides
17 | fun provideApplication(@ApplicationContext app: Context):
18 | App {
19 | return app as App
20 | }
21 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/app/NetworkModule.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.app
2 |
3 | import com.madonasyombua.sportsdb.data.remote.api.Api
4 | import dagger.Module
5 | import dagger.Provides
6 | import dagger.hilt.InstallIn
7 | import dagger.hilt.components.SingletonComponent
8 | import okhttp3.OkHttpClient
9 | import okhttp3.logging.HttpLoggingInterceptor
10 | import retrofit2.Retrofit
11 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
12 | import retrofit2.converter.moshi.MoshiConverterFactory
13 | import javax.inject.Singleton
14 |
15 | /**
16 | * Created by Loveth Nwokike
17 | * on 3/15/2021
18 | * */
19 |
20 | @Module
21 | @InstallIn(SingletonComponent::class)
22 | class NetworkModule {
23 | @Provides
24 | @Singleton
25 | fun provideOkHttpClient(): OkHttpClient {
26 | return OkHttpClient.Builder()
27 | .addInterceptor(
28 | HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)
29 | )
30 | .build()
31 | }
32 |
33 |
34 | @Provides
35 | @Singleton
36 | fun provideRetrofit(okHttpClient: OkHttpClient): Retrofit {
37 | return Retrofit.Builder()
38 | .client(okHttpClient)
39 | .baseUrl("https://www.thesportsdb.com/api/v1/json/1/")
40 | .addConverterFactory(MoshiConverterFactory.create())
41 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
42 | .build()
43 | }
44 |
45 | @Provides
46 | @Singleton
47 | fun provideApi(retrofit: Retrofit): Api {
48 | return retrofit.create(Api::class.java)
49 | }
50 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/app/SportsApp.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.app
2 |
3 | import androidx.compose.foundation.ExperimentalFoundationApi
4 | import androidx.compose.runtime.Composable
5 | import androidx.navigation.compose.NavHost
6 | import androidx.navigation.compose.composable
7 | import androidx.navigation.compose.rememberNavController
8 | import com.madonasyombua.sportsdb.ui.screen.home.HomeScreen
9 | import com.madonasyombua.sportsdb.ui.screen.teamdetails.TeamDetailsScreen
10 |
11 | @ExperimentalFoundationApi
12 | @Composable
13 | fun TheSportsApp(toggle: () -> Unit) {
14 | val navController = rememberNavController()
15 | NavHost(navController, startDestination = "home") {
16 | composable("home") { HomeScreen(navController = navController, toggle) }
17 | composable("teamdetails/{id}") { entry ->
18 | entry.arguments?.getString("id")?.let {
19 | TeamDetailsScreen(it)
20 | }
21 | }
22 | }
23 | }
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/data/Repository.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.data
2 |
3 | import com.madonasyombua.sportsdb.data.remote.api.Api
4 | import javax.inject.Inject
5 |
6 | /**
7 | * Created by Loveth Nwokike
8 | * on 3/15/2021
9 | * */
10 | class Repository @Inject constructor(private val api: Api) {
11 |
12 | fun getAllLeagues() = api.getAllLeagues()
13 |
14 | fun getAllTeamsByLeague(league: String) = api.getAllTeamsInALeague(league = league)
15 |
16 | fun getTeamLastFiveEvents(teamId: String) = api.getEventsByTeamID(teamId)
17 |
18 | fun getTeamDetails(teamId: String) = api.getTeamDetailsById(teamId = teamId)
19 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/data/local/dao/MatchDao.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.data.local.dao
2 |
3 | import androidx.room.*
4 | import com.madonasyombua.sportsdb.data.local.entities.MatchEntity
5 |
6 | @Dao
7 | interface MatchDao {
8 | @Query("SELECT * FROM matchentity")
9 | fun getAllMatches(): List
10 |
11 | @Insert(onConflict = OnConflictStrategy.REPLACE)
12 | fun insertMatchData(sportEntity: MatchEntity)
13 |
14 | @Delete
15 | fun deleteMatchData(sportEntity: MatchEntity)
16 |
17 | @Update(onConflict = OnConflictStrategy.REPLACE)
18 | fun updateMatchData(sportEntity: MatchEntity)
19 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/data/local/dao/TeamDao.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.data.local.dao
2 |
3 | import androidx.room.*
4 | import androidx.room.OnConflictStrategy.REPLACE
5 | import com.madonasyombua.sportsdb.data.local.entities.TeamEntity
6 |
7 | /**
8 | * @author madona
9 | * The data accessible object one of room annotations (DAO class). In this case
10 | * the DAO provides an api for reading and writing data.
11 | * We can perform CRUD(create, Read, Update, Delete)
12 | * A class implements an interface thereby inheriting the abstract methods of the interface
13 | *
14 | */
15 | @Dao
16 | interface TeamDao {
17 | @Query("SELECT * FROM teamentity")
18 | fun getAllSports(): List
19 |
20 | @Insert(onConflict = REPLACE)
21 | fun insertSportsData(sportEntity: TeamEntity)
22 |
23 | @Delete
24 | fun deleteSportsData(sportEntity: TeamEntity)
25 |
26 | @Update(onConflict = REPLACE)
27 | fun updateSportsData(sportEntity: TeamEntity)
28 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/data/local/database/SportDB.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.data.local.database
2 |
3 | import androidx.room.Database
4 | import androidx.room.RoomDatabase
5 | import com.madonasyombua.sportsdb.data.local.dao.MatchDao
6 | import com.madonasyombua.sportsdb.data.local.dao.TeamDao
7 | import com.madonasyombua.sportsdb.data.local.entities.MatchEntity
8 | import com.madonasyombua.sportsdb.data.local.entities.TeamEntity
9 |
10 | /**
11 | * This is the database class
12 | */
13 | @Database(entities = [TeamEntity::class, MatchEntity::class], version = 1, exportSchema = false)
14 | abstract class SportDB : RoomDatabase() {
15 | abstract fun getTeamsDao(): TeamDao
16 | abstract fun getMatchDao(): MatchDao
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/data/local/entities/MatchEntity.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.data.local.entities
2 |
3 | import androidx.room.Entity
4 | import androidx.room.PrimaryKey
5 | import com.squareup.moshi.Json
6 | import com.squareup.moshi.JsonClass
7 |
8 | @Entity
9 | @JsonClass(generateAdapter = true)
10 | data class MatchEntity(
11 | @PrimaryKey(autoGenerate = true)
12 | var id: Long = 0,
13 | @Json(name = league) var leagues: String? = null,
14 | @Json(name = eventDate) var date: String? = null,
15 | @Json(name = time) var gameTime: String? = null,
16 | @Json(name = homeTeam) var teamHome: String? = null,
17 | @Json(name = guestTeam) var awayTeam: String? = null,
18 | @Json(name = homeScore) var scoreHome: String? = null,
19 | @Json(name = guestSore) var scoreGuest: String? = null,
20 | @Json(name = homeTeamId) var homeIdTeam: String? = null,
21 | @Json(name = awayTeamId) var awayIdTeam: String? = null
22 |
23 | ) {
24 | companion object {
25 | private const val league = "strLeague"
26 | private const val eventDate = "dateEvent"
27 | private const val time = "strTime"
28 | private const val homeTeam = "strHomeTeam"
29 | private const val guestTeam = "strAwayTeam"
30 | private const val homeScore = "intHomeScore"
31 | private const val guestSore = "intAwayScore"
32 | private const val homeTeamId = "idHomeTeam"
33 | private const val awayTeamId = "idAwayTeam"
34 |
35 | }
36 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/data/local/entities/TeamEntity.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.data.local.entities
2 |
3 | import androidx.room.Entity
4 | import androidx.room.PrimaryKey
5 | import com.squareup.moshi.Json
6 | import com.squareup.moshi.JsonClass
7 |
8 | /**
9 | * This is the team entity
10 | */
11 | @Entity
12 | @JsonClass(generateAdapter = true)
13 | data class TeamEntity(
14 | @PrimaryKey(autoGenerate = true)
15 | var id: Long = 0,
16 | @Json(name = teamId) var idTeam: String? = null,
17 | @Json(name = teamName) var strTeam: String? = null,
18 | @Json(name = league) var strLeague: String? = null,
19 | @Json(name = teamBadge) var strTeamBadge: String? = null
20 | ) {
21 | companion object {
22 | private const val teamId = "idTeam"
23 | private const val teamName = "strTeam"
24 | private const val league = "strLeague"
25 | private const val teamBadge = "strTeamBadge"
26 | }
27 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/data/remote/api/Api.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.data.remote.api
2 |
3 | import com.madonasyombua.sportsdb.data.remote.response.*
4 | import io.reactivex.Observable
5 | import io.reactivex.Single
6 | import retrofit2.http.GET
7 | import retrofit2.http.Query
8 |
9 | /**
10 | * @author madona
11 | * NOTE: The developer key does not include livescores, player lists or YouTube highlight links
12 | * Free users, can use the test API key "1" during development of your app or for educational use(see test links below).
13 | * https://www.thesportsdb.com/api.php
14 | * https://www.thesportsdb.com/api/v1/json/1/searchteams.php?t=Arsenal
15 | */
16 | interface Api {
17 | @GET("searchteams.php")
18 | fun getAllTeams(@Query("t") team: String): Single
19 |
20 | @GET("eventslast.php")
21 | fun getAllLastEvents(@Query("id") teamId: String): Single
22 |
23 | @GET("all_leagues.php")
24 | fun getAllLeagues(): Single
25 |
26 | @GET("search_all_teams.php")
27 | fun getAllTeamsInALeague(@Query("l") league: String): Single
28 |
29 | @GET("eventslast.php")
30 | fun getEventsByTeamID(@Query("id") teamId: String): Observable
31 |
32 | @GET("lookupequipment")
33 | fun getEquipmentsBYTeam(@Query("id") teamId: String): Single
34 |
35 | @GET("lookuptable.php")
36 | fun getLeagueTable(@Query("l") leagueId: String, @Query("s") season: String):
37 | Observable
38 |
39 | @GET("lookupteam.php")
40 | fun getTeamDetailsById(@Query("id") teamId: String): Single
41 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/data/remote/model/Equipment.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.data.remote.model
2 |
3 | import com.squareup.moshi.Json
4 | import com.squareup.moshi.JsonClass
5 |
6 | /**
7 | * Created by Loveth Nwokike
8 | * 3/23/2021
9 | * */
10 | @JsonClass(generateAdapter = true)
11 | data class Equipment(
12 | @Json(name = "idEquipment")
13 | val equipmentId: String,
14 | @Json(name = "idTeam")
15 | val teamId: String,
16 | val date: String,
17 | @Json(name = "strSeason")
18 | val season: String,
19 | @Json(name = "strEquipment")
20 | val equipmentUrl: String
21 | )
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/data/remote/model/Event.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.data.remote.model
2 |
3 | import com.squareup.moshi.Json
4 | import com.squareup.moshi.JsonClass
5 |
6 | /**
7 | * Created by Loveth Nwokike
8 | * 3/23/2021
9 | * */
10 | @JsonClass(generateAdapter = true)
11 | data class Event(
12 | @Json(name = "idEvent")
13 | val eventId: String = "",
14 | @Json(name = "strEvent")
15 | val twoTeamName: String = "",
16 | @Json(name = "idLeague")
17 | val leagueId: String = "",
18 | @Json(name = "strLeague")
19 | val leagueName: String = "",
20 | @Json(name = "strSeason")
21 | val season: String = "",
22 | @Json(name = "strHomeTeam")
23 | val homeTeam: String = "",
24 | @Json(name = "strAwayTeam")
25 | val awayTeam: String = "",
26 | @Json(name = "intHomeScore")
27 | val homeScore: String = "",
28 | @Json(name = "intAwayScore")
29 | val awayScore: String = "",
30 | @Json(name = "idHomeTeam")
31 | val homeTeamId: String = "",
32 | @Json(name = "idAwayTeam")
33 | val awayTeamId: String = "",
34 | @Json(name = "strVideo")
35 | val videoUrl: String = "",
36 | @Json(name = "dateEvent")
37 | val eventDate: String,
38 | var badge: String = ""
39 |
40 | )
41 |
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/data/remote/model/League.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.data.remote.model
2 |
3 | import com.squareup.moshi.Json
4 | import com.squareup.moshi.JsonClass
5 |
6 | /**
7 | * Created by Loveth Nwokike
8 | * on 3/15/2021
9 | * */
10 | @JsonClass(generateAdapter = true)
11 | data class League(
12 | @Json(name = "idLeague")
13 | val id: String,
14 | @Json(name = "strLeague")
15 | val name: String,
16 | @Json(name = "strSport")
17 | val sport: String,
18 | @Json(name = "strLeagueAlternate")
19 | val alternateName: String?
20 | )
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/data/remote/model/LeagueTable.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.data.remote.model
2 |
3 | import com.squareup.moshi.Json
4 | import com.squareup.moshi.JsonClass
5 |
6 | /**
7 | * Created by Loveth Nwokike
8 | * 3/23/2021
9 | * */
10 | @JsonClass(generateAdapter = true)
11 | data class LeagueTable(
12 | @Json(name = "intRank")
13 | val rankNo: String,
14 | @Json(name = "idTeam")
15 | val teamId: String,
16 | @Json(name = "strTeam")
17 | val teamName: String,
18 | @Json(name = "strTeamBadge")
19 | val teamBadgeUrl: String,
20 | @Json(name = "idLeague")
21 | val leagueId: String,
22 | @Json(name = "strLeague")
23 | val leagueName: String,
24 | @Json(name = "strSeason")
25 | val season: String,
26 | @Json(name = "strDescription")
27 | val description: String,
28 | @Json(name = "intPlayed")
29 | val noOfGamesPlayed: String,
30 | @Json(name = "intWin")
31 | val noOfGamesWon: String,
32 | @Json(name = "intLoss")
33 | val noOfGamesLost: String,
34 | @Json(name = "intDraw")
35 | val noOfGamesDrawn: String
36 | )
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/data/remote/model/TeamByLeague.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.data.remote.model
2 |
3 | import com.squareup.moshi.Json
4 | import com.squareup.moshi.JsonClass
5 |
6 | /**
7 | * Created by Loveth Nwokike
8 | * on 3/17/2021
9 | * */
10 | @JsonClass(generateAdapter = true)
11 | data class TeamByLeague(
12 | @Json(name = "idTeam")
13 | val teamId: String,
14 | @Json(name = "strTeam")
15 | val teamName: String,
16 | @Json(name = "strTeamBadge")
17 | val badgeUrl: String
18 | )
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/data/remote/response/EquipmentResponse.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.data.remote.response
2 |
3 | import com.madonasyombua.sportsdb.data.remote.model.Equipment
4 | import com.squareup.moshi.JsonClass
5 |
6 | @JsonClass(generateAdapter = true)
7 | data class EquipmentResponse(
8 | val equipment: List
9 | )
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/data/remote/response/EventResponse.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.data.remote.response
2 |
3 | import com.madonasyombua.sportsdb.data.remote.model.Event
4 | import com.squareup.moshi.JsonClass
5 |
6 | @JsonClass(generateAdapter = true)
7 | data class EventResponse(
8 | val results: List
9 | )
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/data/remote/response/LeagueResponse.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.data.remote.response
2 |
3 | import com.madonasyombua.sportsdb.data.remote.model.League
4 | import com.squareup.moshi.JsonClass
5 |
6 | /**
7 | * Created by Loveth Nwokike
8 | * on 3/15/2021
9 | * */
10 | @JsonClass(generateAdapter = true)
11 | data class LeagueResponse(
12 | val leagues: List
13 | )
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/data/remote/response/LeagueTableResponse.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.data.remote.response
2 |
3 | import com.madonasyombua.sportsdb.data.remote.model.LeagueTable
4 | import com.squareup.moshi.JsonClass
5 |
6 | @JsonClass(generateAdapter = true)
7 | data class LeagueTableResponse(
8 | val table: List
9 | )
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/data/remote/response/MatchBaseResponse.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.data.remote.response
2 |
3 | import com.madonasyombua.sportsdb.data.local.entities.MatchEntity
4 |
5 | data class MatchBaseResponse(val match: List)
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/data/remote/response/SportsBaseResponse.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.data.remote.response
2 |
3 | import com.madonasyombua.sportsdb.data.local.entities.TeamEntity
4 |
5 | data class SportsBaseResponse(val sportList: List) {
6 | //check when empty
7 | fun whenEmpty() = sportList.isEmpty()
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/data/remote/response/TeamsResponse.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.data.remote.response
2 |
3 | import com.madonasyombua.sportsdb.data.remote.model.TeamByLeague
4 | import com.squareup.moshi.JsonClass
5 |
6 | /**
7 | * Created by Loveth Nwokike
8 | * on 3/20/2021
9 | * */
10 | @JsonClass(generateAdapter = true)
11 | data class TeamsResponse(
12 | val teams: List
13 | )
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/ui/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.ui
2 |
3 | import android.os.Bundle
4 | import androidx.activity.compose.setContent
5 | import androidx.appcompat.app.AppCompatActivity
6 | import androidx.compose.foundation.ExperimentalFoundationApi
7 | import androidx.compose.runtime.mutableStateOf
8 | import androidx.compose.runtime.remember
9 | import com.madonasyombua.sportsdb.app.TheSportsApp
10 | import com.madonasyombua.sportsdb.ui.theme.SportsAppTheme
11 | import dagger.hilt.android.AndroidEntryPoint
12 | import timber.log.Timber
13 |
14 | @AndroidEntryPoint
15 | class MainActivity : AppCompatActivity() {
16 |
17 | @ExperimentalFoundationApi
18 | override fun onCreate(savedInstanceState: Bundle?) {
19 | super.onCreate(savedInstanceState)
20 | setContent {
21 | val darkTheme = remember { mutableStateOf(false) }
22 | SportsAppTheme(darkTheme = darkTheme.value) {
23 | TheSportsApp {
24 | darkTheme.value = !darkTheme.value
25 | Timber.d("theme ${darkTheme.value}")
26 | }
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/ui/components/AppBar.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.ui.components
2 |
3 | import androidx.compose.foundation.layout.RowScope
4 | import androidx.compose.material.Text
5 | import androidx.compose.material.TopAppBar
6 | import androidx.compose.runtime.Composable
7 | import androidx.compose.ui.graphics.Color
8 |
9 | /**
10 | * Created by Loveth Nwokike
11 | * 3/22/2021
12 | * */
13 |
14 | @Composable
15 | fun AppBar(title: String, actions: @Composable RowScope.() -> Unit = {}) {
16 | TopAppBar(
17 | title = {
18 | Text(text = title, color = Color.White)
19 | },
20 | actions = actions
21 | )
22 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/ui/screen/home/HomeScreen.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.ui.screen.home
2 |
3 | import androidx.compose.animation.Crossfade
4 | import androidx.compose.foundation.ExperimentalFoundationApi
5 | import androidx.compose.foundation.layout.Column
6 | import androidx.compose.foundation.layout.Spacer
7 | import androidx.compose.foundation.layout.fillMaxWidth
8 | import androidx.compose.foundation.layout.height
9 | import androidx.compose.material.*
10 | import androidx.compose.material.icons.Icons
11 | import androidx.compose.material.icons.outlined.DarkMode
12 | import androidx.compose.runtime.Composable
13 | import androidx.compose.runtime.CompositionLocalProvider
14 | import androidx.compose.runtime.livedata.observeAsState
15 | import androidx.compose.ui.Modifier
16 | import androidx.compose.ui.graphics.Color
17 | import androidx.compose.ui.res.stringResource
18 | import androidx.compose.ui.tooling.preview.Preview
19 | import androidx.compose.ui.unit.dp
20 | import androidx.hilt.navigation.compose.hiltNavGraphViewModel
21 | import androidx.navigation.NavController
22 | import com.madonasyombua.sportsdb.R
23 | import com.madonasyombua.sportsdb.ui.components.AppBar
24 | import com.madonasyombua.sportsdb.ui.screen.home.teams.TeamsDisplayGrid
25 |
26 | /**
27 | * Created by Loveth Nwokike
28 | * on 3/15/2021
29 | * */
30 | @ExperimentalFoundationApi
31 | @Composable
32 | fun HomeScreen(navController: NavController, toogle: () -> Unit) {
33 | val viewModel: HomeViewModel = hiltNavGraphViewModel()
34 | val leaguesState = viewModel.state.observeAsState()
35 | val selected = leaguesState.value?.selectedLeague
36 |
37 |
38 | Scaffold(topBar = {
39 | HomeAppBar(toogle)
40 | }) {
41 | leaguesState.value?.leagues?.let { leagues ->
42 | selected?.let {
43 | Column {
44 | LeagueTab(
45 | leagues = leagues.take(20),
46 | selectedLeague = it,
47 | onLeagueSelected = viewModel::onLeagueSelected
48 | )
49 |
50 | Spacer(modifier = Modifier.height(10.dp))
51 |
52 | Crossfade(
53 | targetState = selected, modifier = Modifier
54 | .fillMaxWidth()
55 | .weight(1f)
56 | ) {
57 | TeamsDisplayGrid(it, navController)
58 | }
59 | }
60 |
61 | }
62 | }
63 | }
64 | }
65 |
66 |
67 | @Composable
68 | fun HomeAppBar(toogle: () -> Unit) {
69 | AppBar(title = "Sports App", actions = {
70 |
71 | CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
72 | IconButton(
73 | onClick = toogle
74 |
75 |
76 | ) {
77 | Icon(
78 | imageVector = Icons.Outlined.DarkMode,
79 | contentDescription = stringResource(R.string.cd_search),
80 | tint = Color.White
81 | )
82 | }
83 | }
84 | })
85 | }
86 |
87 | @ExperimentalFoundationApi
88 | @Preview("Light Theme", widthDp = 360, heightDp = 640)
89 | @Composable
90 | fun LightPreview() {
91 | MaterialTheme() {
92 | //HomeAppBar()
93 | }
94 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/ui/screen/home/HomeViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.ui.screen.home
2 |
3 | import androidx.lifecycle.*
4 | import com.madonasyombua.sportsdb.data.Repository
5 | import com.madonasyombua.sportsdb.data.remote.model.League
6 | import com.madonasyombua.sportsdb.data.remote.response.LeagueResponse
7 | import dagger.hilt.android.lifecycle.HiltViewModel
8 | import io.reactivex.SingleObserver
9 | import io.reactivex.android.schedulers.AndroidSchedulers
10 | import io.reactivex.disposables.CompositeDisposable
11 | import io.reactivex.disposables.Disposable
12 | import io.reactivex.schedulers.Schedulers
13 | import kotlinx.coroutines.flow.collect
14 | import kotlinx.coroutines.flow.combine
15 | import kotlinx.coroutines.flow.onEach
16 | import kotlinx.coroutines.launch
17 | import timber.log.Timber
18 | import javax.inject.Inject
19 |
20 | /**
21 | * Created by Loveth Nwokike
22 | * on 3/15/2021
23 | * */
24 | @HiltViewModel
25 | class HomeViewModel @Inject constructor(private val repository: Repository) : ViewModel() {
26 | private val _leaguesLiveData = MutableLiveData>()
27 | private val disposable = CompositeDisposable()
28 |
29 | private val _selectedLeagueLiveData = MutableLiveData(null)
30 | private val _state = MutableLiveData()
31 | val state: LiveData
32 | get() = _state
33 |
34 | init {
35 | fetchLeagues()
36 | }
37 |
38 | private fun fetchLeagues() {
39 | repository.getAllLeagues().doOnSubscribe {
40 | }.subscribeOn(Schedulers.io())
41 | .observeOn(AndroidSchedulers.mainThread())
42 | .subscribe(object : SingleObserver {
43 | override fun onSubscribe(d: Disposable) {
44 | disposable.add(d)
45 | }
46 |
47 | override fun onSuccess(response: LeagueResponse) {
48 | _leaguesLiveData.value = response.leagues
49 | viewModelScope.launch {
50 | combine(
51 | _leaguesLiveData.asFlow().onEach { leagues ->
52 | if (leagues.isNotEmpty() && _selectedLeagueLiveData.value == null) {
53 | _selectedLeagueLiveData.value = leagues[0]
54 | }
55 | },
56 | _selectedLeagueLiveData.asFlow()
57 | ) { leagues, selectedLeague ->
58 | LeagueViewState(leagues, selectedLeague)
59 | }.collect { _state.value = it }
60 | }
61 | }
62 |
63 | override fun onError(error: Throwable) {
64 | Timber.e(error)
65 | }
66 |
67 | })
68 | }
69 |
70 | override fun onCleared() {
71 | super.onCleared()
72 | disposable.clear()
73 | }
74 |
75 | fun onLeagueSelected(league: League) {
76 | _selectedLeagueLiveData.value = league
77 | }
78 |
79 | data class LeagueViewState(
80 | val leagues: List = emptyList(),
81 | val selectedLeague: League? = null
82 | )
83 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/ui/screen/home/LeagueTabrow.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.ui.screen.home
2 |
3 | import androidx.compose.foundation.layout.padding
4 | import androidx.compose.material.*
5 | import androidx.compose.runtime.Composable
6 | import androidx.compose.ui.Modifier
7 | import androidx.compose.ui.graphics.Color
8 | import androidx.compose.ui.unit.dp
9 | import com.madonasyombua.sportsdb.data.remote.model.League
10 | import com.madonasyombua.sportsdb.ui.theme.Green700
11 |
12 | /**
13 | * Created by Loveth Nwokike
14 | * on 3/17/2021
15 | * */
16 | @Composable
17 | fun LeagueTab(leagues: List, selectedLeague: League, onLeagueSelected: (League) -> Unit) {
18 |
19 | val selectedIndex = leagues.indexOfFirst { it == selectedLeague }
20 | ScrollableTabRow(
21 | divider = {},
22 | selectedTabIndex = selectedIndex,
23 | edgePadding = 8.dp,
24 | backgroundColor = Color.White,
25 | contentColor = Green700
26 | ) {
27 | leagues.forEachIndexed { index, league ->
28 | Tab(
29 | selected = index == selectedIndex,
30 | onClick = { onLeagueSelected(league) },
31 | ) {
32 | LeagueChoice(
33 | text = league.name,
34 | selected = index == selectedIndex,
35 | modifier = Modifier.padding(horizontal = 4.dp, vertical = 16.dp)
36 | )
37 | }
38 | }
39 | }
40 | }
41 |
42 | @Composable
43 | private fun LeagueChoice(
44 | text: String,
45 | selected: Boolean,
46 | modifier: Modifier = Modifier
47 | ) {
48 | Surface(
49 | shape = MaterialTheme.shapes.small,
50 | modifier = modifier,
51 | color = Green700
52 | ) {
53 | Text(
54 | text = text,
55 | style = MaterialTheme.typography.body2,
56 | color = Color.Black,
57 | modifier = Modifier.padding(start = 8.dp, end = 8.dp, top = 8.dp, bottom = 8.dp)
58 | )
59 | }
60 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/ui/screen/home/teams/TeamsByLeague.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.ui.screen.home.teams
2 |
3 | import androidx.compose.foundation.ExperimentalFoundationApi
4 | import androidx.compose.foundation.clickable
5 | import androidx.compose.foundation.layout.Column
6 | import androidx.compose.foundation.layout.fillMaxHeight
7 | import androidx.compose.foundation.layout.fillMaxWidth
8 | import androidx.compose.foundation.layout.padding
9 | import androidx.compose.foundation.lazy.GridCells
10 | import androidx.compose.foundation.lazy.LazyVerticalGrid
11 | import androidx.compose.foundation.lazy.items
12 | import androidx.compose.foundation.lazy.rememberLazyListState
13 | import androidx.compose.foundation.shape.RoundedCornerShape
14 | import androidx.compose.material.Card
15 | import androidx.compose.material.MaterialTheme
16 | import androidx.compose.material.Text
17 | import androidx.compose.runtime.Composable
18 | import androidx.compose.runtime.livedata.observeAsState
19 | import androidx.compose.ui.Alignment
20 | import androidx.compose.ui.Modifier
21 | import androidx.compose.ui.draw.clip
22 | import androidx.compose.ui.unit.dp
23 | import androidx.hilt.navigation.compose.hiltNavGraphViewModel
24 | import androidx.navigation.NavController
25 | import androidx.navigation.compose.navigate
26 | import com.madonasyombua.sportsdb.data.remote.model.League
27 | import com.madonasyombua.sportsdb.data.remote.model.TeamByLeague
28 | import dev.chrisbanes.accompanist.coil.CoilImage
29 |
30 | /**
31 | * Created by Loveth Nwokike
32 | * on 3/20/2021
33 | * */
34 | @ExperimentalFoundationApi
35 | @Composable
36 | fun TeamsDisplayGrid(league: League, navController: NavController) {
37 | val teamsViewModel: TeamsViewModel = hiltNavGraphViewModel()
38 | val teams = teamsViewModel.teamsLiveData.observeAsState()
39 | LazyVerticalGrid(
40 | cells = GridCells.Fixed(3), modifier = Modifier.padding(10.dp),
41 | state = rememberLazyListState()
42 | ) {
43 | teamsViewModel.getTeamsByLeague(league.name)
44 |
45 | items(teams.value ?: emptyList()) { team ->
46 | TeamGridItem(team = team, navController = navController)
47 | }
48 |
49 | }
50 | }
51 |
52 | @Composable
53 | fun TeamGridItem(team: TeamByLeague, navController: NavController) {
54 | Card(
55 | modifier = Modifier
56 | .fillMaxWidth()
57 | .fillMaxHeight()
58 | .clip(shape = RoundedCornerShape(6.dp))
59 | .padding(10.dp)
60 | .clickable(onClick = {
61 | navController.navigate("teamdetails/${team.teamId}")
62 | })
63 | ) {
64 | Column(
65 | modifier = Modifier.padding(8.dp),
66 | horizontalAlignment = Alignment.CenterHorizontally
67 | ) {
68 | CoilImage(data = team.badgeUrl, contentDescription = null)
69 | Text(text = team.teamName, style = MaterialTheme.typography.subtitle1)
70 | }
71 | }
72 |
73 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/ui/screen/home/teams/TeamsViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.ui.screen.home.teams
2 |
3 | import androidx.lifecycle.LiveData
4 | import androidx.lifecycle.MutableLiveData
5 | import androidx.lifecycle.ViewModel
6 | import com.madonasyombua.sportsdb.data.Repository
7 | import com.madonasyombua.sportsdb.data.remote.model.TeamByLeague
8 | import com.madonasyombua.sportsdb.data.remote.response.TeamsResponse
9 | import dagger.hilt.android.lifecycle.HiltViewModel
10 | import io.reactivex.SingleObserver
11 | import io.reactivex.android.schedulers.AndroidSchedulers
12 | import io.reactivex.disposables.CompositeDisposable
13 | import io.reactivex.disposables.Disposable
14 | import io.reactivex.schedulers.Schedulers
15 | import timber.log.Timber
16 | import javax.inject.Inject
17 |
18 | /**
19 | * Created by Loveth Nwokike
20 | * on 3/20/2021
21 | * */
22 | @HiltViewModel
23 | class TeamsViewModel @Inject constructor(private val repository: Repository) : ViewModel() {
24 |
25 | private val _teamsLiveData = MutableLiveData>()
26 | val teamsLiveData: LiveData>
27 | get() = _teamsLiveData
28 |
29 | private val disposable = CompositeDisposable()
30 |
31 | fun getTeamsByLeague(league: String) {
32 | repository.getAllTeamsByLeague(league = league)
33 | .doOnSubscribe { }
34 | .subscribeOn(Schedulers.io())
35 | .observeOn(AndroidSchedulers.mainThread())
36 | .subscribe(object : SingleObserver {
37 | override fun onSubscribe(d: Disposable) {
38 | disposable.add(d)
39 | }
40 |
41 | override fun onSuccess(response: TeamsResponse) {
42 | _teamsLiveData.postValue(response.teams)
43 | }
44 |
45 | override fun onError(error: Throwable) {
46 | Timber.e(error)
47 | }
48 |
49 | })
50 | }
51 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/ui/screen/teamdetails/TeamDetails.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.ui.screen.teamdetails
2 |
3 | import androidx.annotation.StringRes
4 | import androidx.compose.foundation.layout.*
5 | import androidx.compose.material.*
6 | import androidx.compose.material.icons.Icons
7 | import androidx.compose.material.icons.outlined.Event
8 | import androidx.compose.material.icons.outlined.Person
9 | import androidx.compose.material.icons.outlined.TableChart
10 | import androidx.compose.runtime.Composable
11 | import androidx.compose.runtime.getValue
12 | import androidx.compose.runtime.livedata.observeAsState
13 | import androidx.compose.ui.Modifier
14 | import androidx.compose.ui.graphics.Color
15 | import androidx.compose.ui.graphics.vector.ImageVector
16 | import androidx.compose.ui.res.stringResource
17 | import androidx.compose.ui.tooling.preview.Preview
18 | import androidx.hilt.navigation.compose.hiltNavGraphViewModel
19 | import androidx.navigation.NavController
20 | import androidx.navigation.compose.*
21 | import com.madonasyombua.sportsdb.R
22 | import com.madonasyombua.sportsdb.ui.components.AppBar
23 | import com.madonasyombua.sportsdb.ui.screen.teamdetails.event.TeamEventViewModel
24 | import com.madonasyombua.sportsdb.ui.screen.teamdetails.event.TeamEventsScreen
25 | import com.madonasyombua.sportsdb.ui.theme.Green800
26 | import dev.chrisbanes.accompanist.coil.CoilImage
27 |
28 | /**
29 | * created by Loveth Nwokike
30 | * 3/22/2021
31 | * */
32 | sealed class Screen(val route: String, @StringRes val resourceId: Int, val icon: ImageVector) {
33 | object Event : Screen("event", R.string.event, Icons.Outlined.Event)
34 | object Equipment : Screen("equipment", R.string.equip, Icons.Outlined.Person)
35 | object Table : Screen("table", R.string.table, Icons.Outlined.TableChart)
36 | }
37 |
38 |
39 | @Composable
40 | fun TeamDetailsScreen(id: String) {
41 | val viewModel: TeamEventViewModel = hiltNavGraphViewModel()
42 | viewModel.getHomeTeamDetails(id)
43 | val teamDetails = viewModel.teamDetailsLiveData.observeAsState()
44 | val navController = rememberNavController()
45 | Scaffold(topBar = {
46 | AppBar(title = "", actions =
47 | {
48 | Row(
49 | modifier = Modifier.fillMaxWidth(),
50 | horizontalArrangement = Arrangement.Center
51 | ) {
52 | teamDetails.value?.get(0)?.badgeUrl?.let {
53 | CoilImage(
54 | data = it,
55 | contentDescription = "null"
56 | )
57 | }
58 | }
59 |
60 | })
61 | }, bottomBar =
62 | { TeamBottomNavigation(navController) }) {
63 | Box(modifier = Modifier.padding(it)) {
64 | NavHost(navController, startDestination = Screen.Event.route) {
65 | composable(Screen.Event.route) {
66 | TeamEventsScreen(viewModel)
67 | viewModel.getLastTeamEvents(id)
68 | }
69 | composable(Screen.Equipment.route) { }
70 | composable(Screen.Table.route) {}
71 | }
72 | }
73 | }
74 | }
75 |
76 |
77 | @Composable
78 | fun TeamBottomNavigation(navController: NavController) {
79 | val items = listOf(
80 | Screen.Event,
81 | Screen.Equipment,
82 | Screen.Table
83 | )
84 | BottomNavigation(
85 | backgroundColor = Green800
86 | ) {
87 | val navBackStackEntry by navController.currentBackStackEntryAsState()
88 | val currentRoute = navBackStackEntry?.arguments?.getString(KEY_ROUTE)
89 | items.forEach { screen ->
90 | BottomNavigationItem(selected = currentRoute == screen.route,
91 | onClick = {
92 | navController.navigate(screen.route) {
93 | popUpTo = navController.graph.startDestination
94 | launchSingleTop = true
95 | }
96 | },
97 | selectedContentColor = Color.White,
98 | unselectedContentColor = Color.Black,
99 | label = { Text(text = stringResource(id = screen.resourceId)) },
100 | icon = { Icon(imageVector = screen.icon, contentDescription = null) })
101 | }
102 | }
103 | }
104 |
105 | @Preview("Light Theme")
106 | @Composable
107 | fun LightPreview() {
108 | MaterialTheme {
109 | TeamDetailsScreen("")
110 | }
111 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/ui/screen/teamdetails/TeamLeagueTable.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.ui.screen.teamdetails
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/ui/screen/teamdetails/equipment/TeamEquipments.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.ui.screen.teamdetails.equipment
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/ui/screen/teamdetails/event/TeamEventViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.ui.screen.teamdetails.event
2 |
3 | import androidx.lifecycle.LiveData
4 | import androidx.lifecycle.MutableLiveData
5 | import androidx.lifecycle.ViewModel
6 | import com.madonasyombua.sportsdb.data.Repository
7 | import com.madonasyombua.sportsdb.data.remote.model.Event
8 | import com.madonasyombua.sportsdb.data.remote.model.TeamByLeague
9 | import com.madonasyombua.sportsdb.data.remote.response.EventResponse
10 | import com.madonasyombua.sportsdb.data.remote.response.TeamsResponse
11 | import dagger.hilt.android.lifecycle.HiltViewModel
12 | import io.reactivex.Observer
13 | import io.reactivex.SingleObserver
14 | import io.reactivex.android.schedulers.AndroidSchedulers
15 | import io.reactivex.disposables.CompositeDisposable
16 | import io.reactivex.disposables.Disposable
17 | import io.reactivex.schedulers.Schedulers
18 | import timber.log.Timber
19 | import javax.inject.Inject
20 |
21 | /**
22 | * Created by Loveth Nwokike
23 | * 3/23/2021
24 | * */
25 | @HiltViewModel
26 | class TeamEventViewModel @Inject constructor(private val repository: Repository) : ViewModel() {
27 |
28 | private val _eventsLiveData = MutableLiveData>()
29 | private val _teamDetailLiveData = MutableLiveData>()
30 | private val _teamAwayDetailLiveData = MutableLiveData>()
31 |
32 | val eventsLiveData: LiveData>
33 | get() = _eventsLiveData
34 | val teamAwayDetailsLiveData: LiveData>
35 | get() = _teamAwayDetailLiveData
36 | val teamDetailsLiveData: LiveData>
37 | get() = _teamDetailLiveData
38 | private val disposable = CompositeDisposable()
39 |
40 |
41 | fun getLastTeamEvents(teamId: String) {
42 | repository.getTeamLastFiveEvents(teamId).doOnSubscribe {
43 |
44 | }.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
45 | .subscribe(object : Observer {
46 | override fun onSubscribe(d: Disposable) {
47 | disposable.add(d)
48 | }
49 |
50 | override fun onNext(t: EventResponse) {
51 | _eventsLiveData.postValue(t.results)
52 | }
53 |
54 | override fun onError(e: Throwable) {
55 | Timber.e(e)
56 | }
57 |
58 | override fun onComplete() {
59 | }
60 | })
61 | }
62 |
63 | fun getHomeTeamDetails(teamId: String) {
64 | repository.getTeamDetails(teamId).doOnSubscribe {
65 |
66 | }.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
67 | .subscribe(object : SingleObserver {
68 | override fun onSubscribe(d: Disposable) {
69 | disposable.add(d)
70 | }
71 |
72 | override fun onSuccess(t: TeamsResponse) {
73 | _teamDetailLiveData.postValue(t.teams)
74 | }
75 |
76 | override fun onError(e: Throwable) {
77 | Timber.e(e)
78 | }
79 | })
80 | }
81 |
82 | fun getAwayTeamDetails(teamId: String) {
83 | repository.getTeamDetails(teamId).doOnSubscribe {
84 |
85 | }.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
86 | .subscribe(object : SingleObserver {
87 | override fun onSubscribe(d: Disposable) {
88 | disposable.add(d)
89 | }
90 |
91 | override fun onSuccess(t: TeamsResponse) {
92 | _teamAwayDetailLiveData.postValue(t.teams)
93 | }
94 |
95 | override fun onError(e: Throwable) {
96 | Timber.e(e)
97 | }
98 | })
99 | }
100 |
101 | override fun onCleared() {
102 | super.onCleared()
103 | disposable.clear()
104 | }
105 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/ui/screen/teamdetails/event/TeamLastEvents.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.ui.screen.teamdetails.event
2 |
3 | import androidx.compose.foundation.background
4 | import androidx.compose.foundation.layout.*
5 | import androidx.compose.foundation.lazy.LazyColumn
6 | import androidx.compose.material.Card
7 | import androidx.compose.material.MaterialTheme
8 | import androidx.compose.material.Text
9 | import androidx.compose.runtime.Composable
10 | import androidx.compose.runtime.livedata.observeAsState
11 | import androidx.compose.ui.Alignment
12 | import androidx.compose.ui.Modifier
13 | import androidx.compose.ui.graphics.Color
14 | import androidx.compose.ui.layout.ContentScale
15 | import androidx.compose.ui.tooling.preview.Preview
16 | import androidx.compose.ui.unit.dp
17 | import com.madonasyombua.sportsdb.data.remote.model.Event
18 | import com.madonasyombua.sportsdb.ui.theme.Green800
19 | import dev.chrisbanes.accompanist.coil.CoilImage
20 | import timber.log.Timber
21 |
22 | /**
23 | * Created by Loveth Nwokike
24 | * 3/23/2021
25 | * */
26 | @Composable
27 | fun TeamEventsScreen(viewModel: TeamEventViewModel) {
28 | val events = viewModel.eventsLiveData.observeAsState()
29 | LazyColumn(
30 | modifier = Modifier
31 | .background(
32 | color =
33 | Color(0xeeecf1)
34 | )
35 | .fillMaxHeight()
36 | ) {
37 | events.value?.let { events ->
38 | items(events.size) { index ->
39 | EventsCardItem(event = events[index], viewModel)
40 |
41 | }
42 | }
43 | }
44 | }
45 |
46 | @Composable
47 | fun EventsCardItem(event: Event, viewModel: TeamEventViewModel) {
48 |
49 | val teamDetails = viewModel.teamDetailsLiveData.observeAsState()
50 | viewModel.getAwayTeamDetails(event.awayTeamId)
51 | Card(modifier = Modifier.padding(10.dp)) {
52 | Column(
53 | horizontalAlignment = Alignment.CenterHorizontally,
54 | modifier = Modifier
55 | .fillMaxWidth()
56 | .padding(bottom = 16.dp)
57 | ) {
58 | Box(
59 | contentAlignment = Alignment.Center, modifier = Modifier
60 | .background(color = Green800)
61 | .padding(top = 8.dp, bottom = 8.dp)
62 | .fillMaxWidth()
63 | ) {
64 | Text(text = event.leagueName, color = Color.White)
65 | }
66 |
67 |
68 |
69 | Row(
70 | modifier = Modifier
71 | .padding(top = 16.dp, bottom = 20.dp)
72 | .fillMaxWidth(),
73 | horizontalArrangement = Arrangement.Center
74 | ) {
75 |
76 | teamDetails.value?.get(0)?.let {
77 | CoilImage(
78 | data = it.badgeUrl,
79 | contentDescription = null,
80 | modifier = Modifier
81 | .width(40.dp)
82 | .height(40.dp)
83 | .padding(end = 4.dp, bottom = 8.dp), contentScale = ContentScale.Crop
84 | )
85 | }
86 |
87 | Text(
88 | text = event.homeTeam,
89 | style = MaterialTheme.typography.subtitle1,
90 | modifier = Modifier.width(70.dp),
91 | )
92 | Text(
93 | text = " ${event.homeScore} - ",
94 | )
95 | Text(
96 | text = event.awayScore.plus(" ")
97 | )
98 | Text(
99 | text = event.awayTeam, style = MaterialTheme.typography.subtitle1,
100 | modifier = Modifier.width(80.dp)
101 | )
102 |
103 | val awayTeam = viewModel.teamAwayDetailsLiveData.observeAsState()
104 | awayTeam.value?.get(0)?.let {
105 | Timber.e(event.homeTeamId)
106 | if (it.teamId == event.awayTeamId)
107 | event.badge = it.badgeUrl
108 | CoilImage(
109 | data = event.badge, contentDescription = null, modifier = Modifier
110 | .width(40.dp)
111 | .height(40.dp)
112 | .padding(start = 4.dp, bottom = 8.dp), contentScale = ContentScale.Crop
113 | )
114 |
115 |
116 | }
117 | }
118 |
119 | Text(
120 | text = event.eventDate,
121 | color = Color.Gray
122 | )
123 |
124 | }
125 | }
126 | }
127 |
128 | @Preview
129 | @Composable
130 | fun EventPreview() {
131 | //TeamEventsScreen()
132 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/ui/theme/Color.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.ui.theme
2 |
3 | import androidx.compose.ui.graphics.Color
4 |
5 | val Green800 = Color(0xFF00844f)
6 | val Green700 = Color(0xFF06955c)
7 | val Green900 = Color(0xFF00643a)
8 | val Green200 = Color(0xFF9cdbb9)
9 | val Green300 = Color(0xFF70ce9d)
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/ui/theme/Shape.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.ui.theme
2 |
3 | import androidx.compose.foundation.shape.RoundedCornerShape
4 | import androidx.compose.material.Shapes
5 | import androidx.compose.ui.unit.dp
6 |
7 | val shapes = Shapes(
8 | small = RoundedCornerShape(8.dp),
9 | medium = RoundedCornerShape(24.dp),
10 | large = RoundedCornerShape(8.dp)
11 | )
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/ui/theme/Theme.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.ui.theme
2 |
3 | import androidx.compose.foundation.isSystemInDarkTheme
4 | import androidx.compose.material.MaterialTheme
5 | import androidx.compose.material.darkColors
6 | import androidx.compose.material.lightColors
7 | import androidx.compose.runtime.Composable
8 | import androidx.compose.ui.graphics.Color
9 |
10 | val LightColors = lightColors(
11 | primary = Green700,
12 | primaryVariant = Green900,
13 | onPrimary = Color.White,
14 | secondary = Green700,
15 | secondaryVariant = Green900,
16 | onSecondary = Color.White,
17 | error = Green800,
18 | )
19 |
20 | val DarkColors = darkColors(
21 | primary = Green300,
22 | primaryVariant = Green700,
23 | onPrimary = Color.Black,
24 | secondary = Green300,
25 | onSecondary = Color.Black,
26 | error = Green200,
27 | )
28 |
29 |
30 | @Composable
31 | fun SportsAppTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) {
32 | MaterialTheme(
33 | content = content,
34 | colors = if (darkTheme) DarkColors else LightColors,
35 | typography = SportsAppTypography
36 | )
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/java/com/madonasyombua/sportsdb/ui/theme/Type.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.ui.theme
2 |
3 | import androidx.compose.material.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.text.style.TextAlign
9 | import androidx.compose.ui.unit.sp
10 | import com.madonasyombua.sportsdb.R
11 |
12 |
13 | private val Montserrat = FontFamily(
14 | Font(R.font.montserrat_regular),
15 | Font(R.font.montserrat_medium, FontWeight.W500),
16 | Font(R.font.montserrat_semibold, FontWeight.W600)
17 | )
18 |
19 | val SportsAppTypography = Typography(
20 | h4 = TextStyle(
21 | fontFamily = Montserrat,
22 | fontWeight = FontWeight.W600,
23 | fontSize = 30.sp,
24 | textAlign = TextAlign.Center
25 | ),
26 | h5 = TextStyle(
27 | fontFamily = Montserrat,
28 | fontWeight = FontWeight.W600,
29 | textAlign = TextAlign.Center,
30 | fontSize = 24.sp
31 | ),
32 | h6 = TextStyle(
33 | fontFamily = Montserrat,
34 | fontWeight = FontWeight.W600,
35 | textAlign = TextAlign.Center,
36 | fontSize = 20.sp
37 | ),
38 | subtitle1 = TextStyle(
39 | fontFamily = Montserrat,
40 | fontWeight = FontWeight.W600,
41 | textAlign = TextAlign.Center,
42 | fontSize = 16.sp
43 | ),
44 | subtitle2 = TextStyle(
45 | fontFamily = Montserrat,
46 | fontWeight = FontWeight.W500,
47 | textAlign = TextAlign.Center,
48 | fontSize = 14.sp
49 | ),
50 | body2 = TextStyle(
51 | fontFamily = Montserrat,
52 | fontSize = 14.sp
53 | ),
54 | button = TextStyle(
55 | fontFamily = Montserrat,
56 | fontWeight = FontWeight.W500,
57 | fontSize = 14.sp
58 | ),
59 | caption = TextStyle(
60 | fontFamily = Montserrat,
61 | fontWeight = FontWeight.Normal,
62 | fontSize = 12.sp
63 | ),
64 | overline = TextStyle(
65 | fontFamily = Montserrat,
66 | fontWeight = FontWeight.W500,
67 | fontSize = 12.sp
68 | )
69 | )
70 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/background_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/app/src/main/res/drawable/background_normal.png
--------------------------------------------------------------------------------
/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/drawable/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/app/src/main/res/drawable/logo.png
--------------------------------------------------------------------------------
/app/src/main/res/font/domine_bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/app/src/main/res/font/domine_bold.ttf
--------------------------------------------------------------------------------
/app/src/main/res/font/domine_regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/app/src/main/res/font/domine_regular.ttf
--------------------------------------------------------------------------------
/app/src/main/res/font/font.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/font/montserrat_medium.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/app/src/main/res/font/montserrat_medium.ttf
--------------------------------------------------------------------------------
/app/src/main/res/font/montserrat_regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/app/src/main/res/font/montserrat_regular.ttf
--------------------------------------------------------------------------------
/app/src/main/res/font/montserrat_semibold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/app/src/main/res/font/montserrat_semibold.ttf
--------------------------------------------------------------------------------
/app/src/main/res/font/raleway.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/app/src/main/res/font/raleway.ttf
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/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_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/app/src/main/res/mipmap-hdpi/ic_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/app/src/main/res/mipmap-mdpi/ic_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/app/src/main/res/mipmap-xhdpi/ic_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/app/src/main/res/mipmap-xxhdpi/ic_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/app/src/main/res/mipmap-xxxhdpi/ic_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FF3eb57b
4 | #FF00844f
5 | #ff4081
6 | #FFFF
7 |
8 |
9 | #663399
10 | #DB7093
11 | #8B4513
12 | #8B0000
13 | #006400
14 | #FF6347
15 | #A9A9A9
16 | #90EE90
17 | #ADD8E6
18 | #CD5C5C
19 | #9370DB
20 | #9ACD32
21 | #00FF00
22 | #F4A460
23 | #BC8F8F
24 | #AFEEEE
25 | #CD853F
26 | #4169E1
27 | #B0E0E6
28 | #FF1493
29 | #D2691E
30 | #778899
31 | #3CB371
32 | #800000
33 | #FF4500
34 | #483D8B
35 | #FFD700
36 | #4B0082
37 | #F0E68C
38 |
39 |
40 |
41 | #000000
42 | #f2f2f2
43 |
44 | #F44336
45 | #EF9A9A
46 | #4CAF50
47 | #A5D6A7
48 | #FF9800
49 | #FFCC80
50 | #EEEEEE
51 |
52 |
53 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Sports
3 | Search
4 | LastEvents
5 | Equipments
6 | LeagueTable
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/madonasyombua/sportsdb/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb
2 |
3 | import org.junit.Assert
4 | import org.junit.Test
5 |
6 | /**
7 | * Example local unit test, which will execute on the development machine (host).
8 | *
9 | * @see [Testing documentation](http://d.android.com/tools/testing)
10 | */
11 | class ExampleUnitTest {
12 | @Test
13 | fun addition_isCorrect() {
14 | Assert.assertEquals(4, 2 + 2.toLong())
15 | }
16 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/madonasyombua/sportsdb/tests/LiveDataUtilTest.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.tests
2 |
3 | import androidx.lifecycle.LiveData
4 | import androidx.lifecycle.Observer
5 | import java.util.concurrent.CountDownLatch
6 | import java.util.concurrent.TimeUnit
7 |
8 | class LiveDataUtilTest {
9 | @Throws(InterruptedException::class)
10 | fun getValue(tLiveData: LiveData): T? {
11 | val data = arrayOfNulls(1)
12 | val downLatch = CountDownLatch(1)
13 | val tObserver: Observer = object : Observer {
14 | override fun onChanged(t: T) {
15 | data[0] = t
16 | downLatch.countDown()
17 | tLiveData.removeObserver(this)
18 | }
19 | }
20 | tLiveData.observeForever(tObserver)
21 | downLatch.await(2, TimeUnit.SECONDS)
22 | return data[0] as T?
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/madonasyombua/sportsdb/tests/MatchDBTests.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.tests
2 |
3 | import androidx.room.Room
4 | import com.madonasyombua.sportsdb.data.local.dao.MatchDao
5 | import com.madonasyombua.sportsdb.data.local.database.SportDB
6 | import com.madonasyombua.sportsdb.data.local.entities.MatchEntity
7 | import junit.framework.TestCase.assertEquals
8 | import org.junit.After
9 | import org.junit.Before
10 | import org.junit.Test
11 | import org.junit.runner.RunWith
12 | import org.robolectric.RobolectricTestRunner
13 | import org.robolectric.RuntimeEnvironment
14 |
15 |
16 | @RunWith(RobolectricTestRunner::class)
17 | class MatchDBTests {
18 | private var matchDao: MatchDao? = null
19 | private var sportsDataBase: SportDB? = null
20 | private var matchEntity: MatchEntity? = null
21 |
22 | @Before
23 | fun databaseCreated() {
24 | // Using an in-memory database because the information stored here disappears when the
25 | // process is killed.
26 | // Using an in-memory database because the information stored here disappears when the
27 | // process is killed.
28 | sportsDataBase = Room.inMemoryDatabaseBuilder(
29 | RuntimeEnvironment.systemContext,
30 | SportDB::class.java
31 | ) //this is just allowed here for testing
32 | .allowMainThreadQueries()
33 | .build()
34 | matchEntity = MatchEntity(
35 | 1, "PremierLeague", "07:12:2020", "2:11", "Manchester", "Arsenal",
36 | "0", "3", "1111", "2222"
37 | )
38 | }
39 |
40 | @Test
41 | @Throws(Exception::class)
42 | fun insertItemsInTheDB() {
43 | matchEntity?.let { sportsDataBase?.getMatchDao()?.insertMatchData(it) }
44 | assertEquals(
45 | "PremierLeague",
46 | sportsDataBase?.getMatchDao()?.getAllMatches()?.get(0)?.leagues
47 | )
48 | }
49 |
50 | @Test
51 | @Throws(Exception::class)
52 | fun deleteItemsFromTheDB() {
53 | matchEntity?.let { sportsDataBase?.getMatchDao()?.insertMatchData(it) }
54 | matchEntity?.let { sportsDataBase?.getMatchDao()?.deleteMatchData(it) }
55 | assertEquals(0, sportsDataBase?.getMatchDao()?.getAllMatches()?.size)
56 | }
57 |
58 | @Test
59 | @Throws(Exception::class)
60 | fun testOnConflict() {
61 | matchEntity?.let { sportsDataBase?.getMatchDao()?.insertMatchData(it) }
62 | matchEntity?.let { sportsDataBase?.getMatchDao()?.insertMatchData(it) }
63 | assertEquals(1, sportsDataBase?.getMatchDao()?.getAllMatches()?.size)
64 | }
65 |
66 | @Test
67 | @Throws(Exception::class)
68 | fun deleteAllSportsData() {
69 | if (sportsDataBase?.getMatchDao()?.getAllMatches()?.isNotEmpty()!!) {
70 | matchEntity?.let { sportsDataBase?.getMatchDao()?.deleteMatchData(it) }
71 | }
72 | }
73 |
74 | @After
75 | @Throws(Exception::class)
76 | fun closeTheDB() {
77 | sportsDataBase?.close()
78 | }
79 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/madonasyombua/sportsdb/tests/TeamDBTests.kt:
--------------------------------------------------------------------------------
1 | package com.madonasyombua.sportsdb.tests
2 |
3 | import android.os.Build
4 | import androidx.room.Room
5 | import com.madonasyombua.sportsdb.data.local.dao.TeamDao
6 | import com.madonasyombua.sportsdb.data.local.database.SportDB
7 | import com.madonasyombua.sportsdb.data.local.entities.TeamEntity
8 | import junit.framework.Assert.assertEquals
9 | import org.junit.After
10 | import org.junit.Before
11 | import org.junit.Test
12 | import org.junit.runner.RunWith
13 | import org.robolectric.RobolectricTestRunner
14 | import org.robolectric.RuntimeEnvironment
15 | import org.robolectric.annotation.Config
16 |
17 | @RunWith(RobolectricTestRunner::class)
18 | @Config(sdk = [Build.VERSION_CODES.O_MR1])
19 | class TeamDBTests {
20 | private var teamDao: TeamDao? = null
21 | private var sportsDataBase: SportDB? = null
22 | private var teamEntity: TeamEntity? = null
23 |
24 | @Before
25 | fun databaseCreated() {
26 | // Using an in-memory database because the information stored here disappears when the
27 | // process is killed.
28 | // Using an in-memory database because the information stored here disappears when the
29 | // process is killed.
30 | sportsDataBase = Room.inMemoryDatabaseBuilder(
31 | RuntimeEnvironment.systemContext,
32 | SportDB::class.java
33 | ) //this is just allowed here for testing
34 | .allowMainThreadQueries()
35 | .build()
36 | teamEntity = TeamEntity(1, "18888", "Arsenal", "Premier League", "Image")
37 | }
38 |
39 | @Test
40 | @Throws(Exception::class)
41 | fun insertItemsInTheDB() {
42 | teamEntity?.let { sportsDataBase?.getTeamsDao()?.insertSportsData(it) }
43 | assertEquals("Arsenal", sportsDataBase?.getTeamsDao()?.getAllSports()?.get(0)?.strTeam)
44 | }
45 |
46 | @Test
47 | @Throws(Exception::class)
48 | fun deleteItemsFromTheDB() {
49 | teamEntity?.let { sportsDataBase?.getTeamsDao()?.insertSportsData(it) }
50 | teamEntity?.let { sportsDataBase?.getTeamsDao()?.deleteSportsData(it) }
51 | assertEquals(0, sportsDataBase?.getTeamsDao()?.getAllSports()?.size)
52 | }
53 |
54 | @Test
55 | @Throws(Exception::class)
56 | fun testOnConflict() {
57 | teamEntity?.let { sportsDataBase?.getTeamsDao()?.insertSportsData(it) }
58 | teamEntity?.let { sportsDataBase?.getTeamsDao()?.insertSportsData(it) }
59 | assertEquals(1, sportsDataBase?.getTeamsDao()?.getAllSports()?.size)
60 | }
61 |
62 | @Test
63 | @Throws(Exception::class)
64 | fun deleteAllSportsData() {
65 | if (sportsDataBase?.getTeamsDao()?.getAllSports()?.isNotEmpty()!!) {
66 | teamEntity?.let { sportsDataBase?.getTeamsDao()?.deleteSportsData(it) }
67 | }
68 | }
69 |
70 | @After
71 | @Throws(Exception::class)
72 | fun closeTheDB() {
73 | sportsDataBase?.close()
74 | }
75 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext{
5 | kotlin_version = '1.5.31'
6 | compose_version = '1.0.0-beta02'
7 | }
8 |
9 | repositories {
10 | google()
11 | mavenCentral()
12 |
13 | }
14 | dependencies {
15 | classpath 'com.android.tools.build:gradle:7.0.4'
16 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
17 | classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40'
18 |
19 | // NOTE: Do not place your application dependencies here; they belong
20 | // in the individual module build.gradle files
21 | }
22 | }
23 |
24 | allprojects {
25 | repositories {
26 | google()
27 | mavenCentral()
28 |
29 | }
30 | }
31 |
32 | task clean(type: Delete) {
33 | delete rootProject.buildDir
34 | }
35 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | android.enableJetifier=true
13 | android.useAndroidX=true
14 | org.gradle.jvmargs=-Xmx1536m
15 |
16 | # When configured, Gradle will run in incubating parallel mode.
17 | # This option should only be used with decoupled projects. More details, visit
18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
19 | # org.gradle.parallel=true
20 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Jul 19 09:57:26 CDT 2020
2 | distributionBase=GRADLE_USER_HOME
3 | //=
4 | distributionPath=wrapper/dists
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 | distributionUrl=https://services.gradle.org/distributions/gradle-7.0.2-all.zip
8 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | #############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem #########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/screenshots/events.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/screenshots/events.png
--------------------------------------------------------------------------------
/screenshots/events_dark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/screenshots/events_dark.png
--------------------------------------------------------------------------------
/screenshots/home.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/screenshots/home.png
--------------------------------------------------------------------------------
/screenshots/home_dark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/screenshots/home_dark.png
--------------------------------------------------------------------------------
/screenshots/new_home.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madonawambua/The-Sports-DB/52f63ddb4f97b6098fb3be53ceba1de8c4efb947/screenshots/new_home.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------