Initial Upload
19
TrackCovid19.iml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id="TrackCovid19" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="java-gradle" name="Java-Gradle">
|
||||
<configuration>
|
||||
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
|
||||
<option name="BUILDABLE" value="false" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
BIN
app/.DS_Store
vendored
Normal file
1
app/.gitignore
vendored
Executable file
@@ -0,0 +1 @@
|
||||
/build
|
175
app/app.iml
Normal file
@@ -0,0 +1,175 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="android-gradle" name="Android-Gradle">
|
||||
<configuration>
|
||||
<option name="GRADLE_PROJECT_PATH" value=":app" />
|
||||
<option name="LAST_SUCCESSFUL_SYNC_AGP_VERSION" value="3.6.3" />
|
||||
<option name="LAST_KNOWN_AGP_VERSION" value="3.6.3" />
|
||||
</configuration>
|
||||
</facet>
|
||||
<facet type="android" name="Android">
|
||||
<configuration>
|
||||
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
||||
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
||||
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
|
||||
<afterSyncTasks>
|
||||
<task>generateDebugSources</task>
|
||||
</afterSyncTasks>
|
||||
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
||||
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
||||
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
||||
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
|
||||
<option name="TEST_RES_FOLDERS_RELATIVE_PATH" value="" />
|
||||
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/build/intermediates/javac/debug/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/build/intermediates/javac/debugUnitTest/classes" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/ap_generated_sources/debug/out" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/aidl_source_output_dir/debug/out" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/renderscript_source_output_dir/debug/out" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/ap_generated_sources/debugAndroidTest/out" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/aidl_source_output_dir/debugAndroidTest/out" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/renderscript_source_output_dir/debugAndroidTest/out" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/ap_generated_sources/debugUnitTest/out" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Android API 29 Platform" jdkType="Android SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" scope="TEST" name="Gradle: junit:junit:4.12@jar" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Gradle: org.hamcrest:hamcrest-integration:1.3@jar" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Gradle: org.hamcrest:hamcrest-library:1.3@jar" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Gradle: org.hamcrest:hamcrest-core:1.3@jar" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Gradle: net.sf.kxml:kxml2:2.3.0@jar" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Gradle: com.squareup:javawriter:2.1.1@jar" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Gradle: javax.inject:javax.inject:1@jar" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Gradle: com.google.code.findbugs:jsr305:2.0.1@jar" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Gradle: androidx.test.ext:junit:1.1.1@aar" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Gradle: androidx.test.espresso:espresso-core:3.2.0@aar" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Gradle: androidx.test:rules:1.2.0@aar" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Gradle: androidx.test:runner:1.2.0@aar" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Gradle: androidx.test:core:1.2.0@aar" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Gradle: androidx.test:monitor:1.2.0@aar" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Gradle: androidx.test.espresso:espresso-idling-resource:3.2.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.collection:collection:1.1.0@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.arch.core:core-common:2.1.0-rc01@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-common:2.1.0-rc01@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.room:room-common:2.0.0@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.annotation:annotation:1.1.0@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.squareup.retrofit2:converter-gson:2.3.0@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.squareup.retrofit2:adapter-rxjava2:2.3.0@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.squareup.retrofit2:retrofit:2.3.0@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.squareup.okhttp3:okhttp:3.10.0@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.squareup.okio:okio:1.14.0@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.constraintlayout:constraintlayout-solver:1.1.3@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.google.code.gson:gson:2.8.2@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: io.reactivex.rxjava2:rxjava:2.1.6@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.reactivestreams:reactive-streams:1.0.1@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.fasterxml.jackson.core:jackson-databind:2.9.8@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.fasterxml.jackson.core:jackson-core:2.9.8@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.fasterxml.jackson.core:jackson-annotations:2.9.8@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.navigation:navigation-ui:2.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.google.android.material:material:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.preference:preference:1.1.0-rc01@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.appcompat:appcompat:1.1.0-rc01@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.squareup.picasso:picasso:2.71828@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-extensions:2.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.legacy:legacy-support-v4:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.navigation:navigation-fragment:2.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.fragment:fragment:1.1.0-rc01@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.appcompat:appcompat-resources:1.1.0-rc01@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.recyclerview:recyclerview:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.legacy:legacy-support-core-ui:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.drawerlayout:drawerlayout:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.media:media:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.room:room-runtime:2.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.navigation:navigation-runtime:2.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.legacy:legacy-support-core-utils:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.transition:transition:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.viewpager:viewpager:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.loader:loader:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.activity:activity:1.0.0-rc01@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.vectordrawable:vectordrawable-animated:1.1.0-rc01@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.vectordrawable:vectordrawable:1.1.0-rc01@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.coordinatorlayout:coordinatorlayout:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.slidingpanelayout:slidingpanelayout:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.customview:customview:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.swiperefreshlayout:swiperefreshlayout:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.asynclayoutinflater:asynclayoutinflater:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.navigation:navigation-common:2.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.core:core:1.1.0-rc01@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-process:2.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-service:2.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-runtime:2.1.0-rc01@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.cursoradapter:cursoradapter:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.versionedparcelable:versionedparcelable:1.1.0-rc01@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.exifinterface:exifinterface:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.cardview:cardview:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-livedata:2.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-livedata-core:2.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.arch.core:core-runtime:2.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.savedstate:savedstate:1.0.0-rc01@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-viewmodel:2.1.0-rc01@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.sqlite:sqlite-framework:2.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.sqlite:sqlite:2.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.documentfile:documentfile:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.localbroadcastmanager:localbroadcastmanager:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.print:print:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.interpolator:interpolator:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.constraintlayout:constraintlayout:1.1.3@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: io.reactivex.rxjava2:rxandroid:2.0.1@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.evrencoskun.library:tableview:0.8.8@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.fabiomsr:moneytextview:1.1.0@aar" level="project" />
|
||||
</component>
|
||||
</module>
|
89
app/build.gradle
Executable file
@@ -0,0 +1,89 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
buildToolsVersion "29.0.3"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.josh.trackcovid19v2"
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 29
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
implementation 'androidx.appcompat:appcompat:1.0.2'
|
||||
implementation 'com.squareup.picasso:picasso:2.71828'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'com.google.android.material:material:1.0.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation 'androidx.navigation:navigation-fragment:2.0.0'
|
||||
implementation 'androidx.navigation:navigation-ui:2.0.0'
|
||||
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
|
||||
implementation 'androidx.preference:preference:1.1.0-rc01'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
|
||||
implementation "androidx.appcompat:appcompat:$support_version"
|
||||
implementation "androidx.legacy:legacy-support-v4:$legacy_support_version"
|
||||
implementation "com.google.android.material:material:$legacy_support_version"
|
||||
|
||||
// Lifecycle
|
||||
implementation "androidx.lifecycle:lifecycle-runtime:$room_version"
|
||||
implementation "androidx.lifecycle:lifecycle-extensions:$room_version"
|
||||
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$room_version"
|
||||
|
||||
// Room
|
||||
implementation "androidx.room:room-runtime:$room_version"
|
||||
annotationProcessor "androidx.room:room-compiler:$room_version"
|
||||
|
||||
// Retrofit2
|
||||
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
|
||||
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
|
||||
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"
|
||||
|
||||
// RxJava
|
||||
implementation "io.reactivex.rxjava2:rxjava:$rxjava_version"
|
||||
implementation "io.reactivex.rxjava2:rxandroid:$rxandroid_version"
|
||||
|
||||
implementation 'com.fasterxml.jackson.core:jackson-core:2.9.8'
|
||||
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.8'
|
||||
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.8'
|
||||
|
||||
// Gson
|
||||
implementation "com.google.code.gson:gson:$gson_version"
|
||||
|
||||
// TableView
|
||||
implementation "com.evrencoskun.library:tableview:$tableview_version"
|
||||
|
||||
// MoneyView
|
||||
implementation "org.fabiomsr:moneytextview:$moneyview_version"
|
||||
|
||||
// Instrumentation dependencies use androidTestCompile"
|
||||
// (as opposed to testCompile for local unit tests run in the JVM"
|
||||
androidTestImplementation "junit:junit:$junit_version"
|
||||
androidTestImplementation "androidx.annotation:annotation:$support_test_version"
|
||||
androidTestImplementation "androidx.test:runner:$support_test_runner_version"
|
||||
androidTestImplementation "androidx.test:rules:$support_test_runner_version"
|
||||
androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_test_version"
|
||||
}
|
21
app/proguard-rules.pro
vendored
Executable file
@@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
BIN
app/release/app-release.aab
Normal file
BIN
app/src/.DS_Store
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.josh.trackcovid19v2;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
|
||||
assertEquals("com.example.trackcovid19", appContext.getPackageName());
|
||||
}
|
||||
}
|
BIN
app/src/main/.DS_Store
vendored
Normal file
41
app/src/main/AndroidManifest.xml
Executable file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.josh.trackcovid19v2"
|
||||
android:versionCode="2">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
android:usesCleartextTraffic="true">
|
||||
<activity android:name="com.josh.trackcovid19v2.HomeActivity"
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="portrait">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.josh.trackcovid19v2.SettingsActivity"
|
||||
android:label="@string/title_activity_settings" />
|
||||
<activity
|
||||
android:name="com.josh.trackcovid19v2.MainActivity"
|
||||
android:configChanges="orientation|keyboardHidden"
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
</activity>
|
||||
<meta-data
|
||||
android:name="preloaded_fonts"
|
||||
android:resource="@array/preloaded_fonts" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
BIN
app/src/main/ic_launcher-playstore.png
Normal file
After Width: | Height: | Size: 512 KiB |
BIN
app/src/main/java/.DS_Store
vendored
Normal file
64
app/src/main/java/com/josh/trackcovid19v2/AppExecutors.java
Executable file
@@ -0,0 +1,64 @@
|
||||
package com.josh.trackcovid19v2;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* Global executor pools for the whole application.
|
||||
* <p>
|
||||
* Grouping tasks like this avoids the effects of task starvation (e.g. disk reads don't wait behind
|
||||
* webservice requests).
|
||||
* <p>
|
||||
* Creating a class like this is a way for android apps to handle non-trivial threading.
|
||||
*/
|
||||
public class AppExecutors {
|
||||
|
||||
// For Singleton instantiation
|
||||
private static final Object LOCK = new Object();
|
||||
private static AppExecutors sInstance;
|
||||
private final Executor diskIO;
|
||||
private final Executor mainThread;
|
||||
private final Executor networkIO;
|
||||
|
||||
private AppExecutors(Executor diskIO, Executor networkIO, Executor mainThread) {
|
||||
this.diskIO = diskIO;
|
||||
this.networkIO = networkIO;
|
||||
this.mainThread = mainThread;
|
||||
}
|
||||
|
||||
public static AppExecutors getInstance() {
|
||||
if (sInstance == null) {
|
||||
synchronized (LOCK) {
|
||||
sInstance = new AppExecutors(Executors.newSingleThreadExecutor(), Executors
|
||||
.newFixedThreadPool(3), new MainThreadExecutor());
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public Executor diskIO() {
|
||||
return diskIO;
|
||||
}
|
||||
|
||||
public Executor mainThread() {
|
||||
return mainThread;
|
||||
}
|
||||
|
||||
public Executor networkIO() {
|
||||
return networkIO;
|
||||
}
|
||||
|
||||
private static class MainThreadExecutor implements Executor {
|
||||
private Handler mainThreadHandler = new Handler(Looper.getMainLooper());
|
||||
|
||||
@Override
|
||||
public void execute(@NonNull Runnable command) {
|
||||
mainThreadHandler.post(command);
|
||||
}
|
||||
}
|
||||
}
|
199
app/src/main/java/com/josh/trackcovid19v2/HomeActivity.java
Normal file
@@ -0,0 +1,199 @@
|
||||
package com.josh.trackcovid19v2;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class HomeActivity extends AppCompatActivity {
|
||||
private int SPLASH_SCREEN_TIME_OUT = 30000;
|
||||
private Button button;
|
||||
private Handler handler;
|
||||
private int STORAGE_PERMISSION_CODE = 1;
|
||||
private int INTERNET_PERMISSION_CODE = 1;
|
||||
private Runnable myRunnable;
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_home);
|
||||
if(ContextCompat.checkSelfPermission(HomeActivity.this,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
|
||||
}
|
||||
else{
|
||||
requestStoragePermission();
|
||||
}
|
||||
if(ContextCompat.checkSelfPermission(HomeActivity.this,
|
||||
Manifest.permission.INTERNET) == PackageManager.PERMISSION_GRANTED) {
|
||||
}
|
||||
else{
|
||||
requestInternetPermission();
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
button = findViewById(R.id.magicbtn);
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@SuppressLint("LongLogTag")
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Log.d("foasdfaosdfoasdfoasdfoasdfoasdofaosdfoasdfoasdf", "button thingy");
|
||||
skipSplashScreen();
|
||||
}
|
||||
});
|
||||
handler = new Handler();
|
||||
Runnable myRunnable = new Runnable() {
|
||||
public void run() {
|
||||
Intent i= new Intent(HomeActivity.this,
|
||||
MainActivity.class);
|
||||
//Intent is used to switch from one activity to another.
|
||||
|
||||
startActivity(i);
|
||||
//invoke the SecondActivity.
|
||||
|
||||
finish();
|
||||
}
|
||||
};
|
||||
handler.postDelayed(myRunnable, SPLASH_SCREEN_TIME_OUT);
|
||||
}
|
||||
public void startNextActivity(){
|
||||
startActivity(new Intent(getApplicationContext(), MainActivity.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
skipSplashScreen();
|
||||
}
|
||||
|
||||
public void skipSplashScreen(){
|
||||
if (handler != null)
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
|
||||
startNextActivity();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
// clear handler on stop
|
||||
if (handler != null)
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
private void requestInternetPermission() {
|
||||
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.INTERNET)){
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("Permission needed")
|
||||
.setMessage("This permission is needed to store COVID data on your phone for offline usage")
|
||||
.setPositiveButton("ok", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
ActivityCompat.requestPermissions(HomeActivity.this, new String [] {Manifest.permission.INTERNET}, INTERNET_PERMISSION_CODE);
|
||||
}
|
||||
})
|
||||
.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.create().show();
|
||||
} else{
|
||||
ActivityCompat.requestPermissions(this, new String [] {Manifest.permission.INTERNET}, INTERNET_PERMISSION_CODE);
|
||||
}
|
||||
}
|
||||
|
||||
private void requestStoragePermission() {
|
||||
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)){
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("Permission needed")
|
||||
.setMessage("This permission is needed to access data")
|
||||
.setPositiveButton("ok", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
ActivityCompat.requestPermissions(HomeActivity.this, new String [] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, STORAGE_PERMISSION_CODE);
|
||||
}
|
||||
})
|
||||
.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.create().show();
|
||||
} else{
|
||||
ActivityCompat.requestPermissions(this, new String [] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, STORAGE_PERMISSION_CODE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
if (requestCode == STORAGE_PERMISSION_CODE) {
|
||||
if(grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){
|
||||
}
|
||||
else{
|
||||
Toast.makeText(this, "Permission denied", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
if (requestCode == INTERNET_PERMISSION_CODE) {
|
||||
if(grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){
|
||||
}
|
||||
else{
|
||||
Toast.makeText(this, "Permission denied", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
protected void onDestroy() {
|
||||
// TODO Auto-generated method stub
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
public void clearApplicationData() {
|
||||
File cache = getCacheDir();
|
||||
File appDir = new File(cache.getParent());
|
||||
if (appDir.exists()) {
|
||||
String[] children = appDir.list();
|
||||
for (String s : children) {
|
||||
if (!s.equals("lib")) {
|
||||
deleteDir(new File(appDir, s));
|
||||
Log.i("EEEEEERRRRRROOOOOOORRRR", "**************** File /data/data/APP_PACKAGE/" + s + " DELETED *******************");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean deleteDir(File dir) {
|
||||
if (dir != null && dir.isDirectory()) {
|
||||
String[] children = dir.list();
|
||||
int i = 0;
|
||||
while (i < children.length) {
|
||||
boolean success = deleteDir(new File(dir, children[i]));
|
||||
if (!success) {
|
||||
return false;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
assert dir != null;
|
||||
return dir.delete();
|
||||
}
|
||||
}
|
55
app/src/main/java/com/josh/trackcovid19v2/MainActivity.java
Executable file
@@ -0,0 +1,55 @@
|
||||
package com.josh.trackcovid19v2;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.navigation.ui.AppBarConfiguration;
|
||||
import androidx.navigation.ui.NavigationUI;
|
||||
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
private static int SPLASH_SCREEN_TIME_OUT=2000;
|
||||
private AppBarConfiguration mAppBarConfiguration;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||
NavigationView navigationView = findViewById(R.id.nav_view);
|
||||
// Passing each menu ID as a set of Ids because each
|
||||
// menu should be considered as top level destinations.
|
||||
mAppBarConfiguration = new AppBarConfiguration.Builder(
|
||||
R.id.nav_yourworld, R.id.nav_yourcountry,R.id.nav_yourrealcountry, R.id.nav_yourstate)
|
||||
.setDrawerLayout(drawer)
|
||||
.build();
|
||||
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
|
||||
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
|
||||
NavigationUI.setupWithNavController(navigationView, navController);
|
||||
|
||||
Toast.makeText(getApplicationContext(), "Data Imported Successfully",Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSupportNavigateUp() {
|
||||
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
|
||||
return NavigationUI.navigateUp(navController, mAppBarConfiguration)
|
||||
|| super.onSupportNavigateUp();
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package com.josh.trackcovid19v2;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.settings_activity);
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(R.id.settings, new SettingsFragment())
|
||||
.commit();
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SettingsFragment extends PreferenceFragmentCompat {
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
setPreferencesFromResource(R.xml.root_preferences, rootKey);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
package com.josh.trackcovid19v2;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link SettingsFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class SettingsFragment extends Fragment {
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private static final String ARG_PARAM1 = "param1";
|
||||
private static final String ARG_PARAM2 = "param2";
|
||||
|
||||
// TODO: Rename and change types of parameters
|
||||
private String mParam1;
|
||||
private String mParam2;
|
||||
|
||||
public SettingsFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
*
|
||||
* @param param1 Parameter 1.
|
||||
* @param param2 Parameter 2.
|
||||
* @return A new instance of fragment SettingsFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
public static SettingsFragment newInstance(String param1, String param2) {
|
||||
SettingsFragment fragment = new SettingsFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_PARAM1, param1);
|
||||
args.putString(ARG_PARAM2, param2);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
mParam1 = getArguments().getString(ARG_PARAM1);
|
||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_settings, container, false);
|
||||
}
|
||||
}
|
95
app/src/main/java/com/josh/trackcovid19v2/data/CountriesRepository.java
Executable file
@@ -0,0 +1,95 @@
|
||||
package com.josh.trackcovid19v2.data;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
import com.josh.trackcovid19v2.AppExecutors;
|
||||
import com.josh.trackcovid19v2.data.database.CountriesDao;
|
||||
import com.josh.trackcovid19v2.data.database.YesCountriesDao;
|
||||
import com.josh.trackcovid19v2.data.database.entity.Countries;
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesCountries;
|
||||
import com.josh.trackcovid19v2.data.network.UserNetworkDataSource;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class responsible for handling data operations. This is the mediator between different
|
||||
* data sources (persistent model, web service, cache, etc.)
|
||||
*/
|
||||
public class CountriesRepository {
|
||||
private static final String LOG_TAG = CountriesRepository.class.getSimpleName();
|
||||
|
||||
private CountriesDao mCountriesDao;
|
||||
private YesCountriesDao mYesCountriesDao;
|
||||
private UserNetworkDataSource mNetworkDataSource;
|
||||
|
||||
// For Singleton instantiationz
|
||||
private static final Object LOCK = new Object();
|
||||
private static CountriesRepository sInstance;
|
||||
|
||||
public CountriesRepository(CountriesDao countriesDao,
|
||||
YesCountriesDao yescountriesDao,
|
||||
UserNetworkDataSource networkDataSource, AppExecutors
|
||||
executors) {
|
||||
this.mCountriesDao = countriesDao;
|
||||
this.mYesCountriesDao = yescountriesDao;
|
||||
this.mNetworkDataSource = networkDataSource;
|
||||
|
||||
// As long as the repository exists, observe the network LiveData.
|
||||
// If that LiveData changes, update the database.
|
||||
mNetworkDataSource.getCountriesList().observeForever(countries -> {
|
||||
executors.diskIO().execute(() -> {
|
||||
|
||||
Log.d(LOG_TAG, "countries table is updating");
|
||||
mCountriesDao.updateAll(countries);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
mNetworkDataSource.getYesCountriesList().observeForever(yescountries -> {
|
||||
executors.diskIO().execute(() -> {
|
||||
|
||||
Log.d(LOG_TAG, "yes countries table is updating");
|
||||
mYesCountriesDao.updateAll(yescountries);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static CountriesRepository getInstance(CountriesDao countriesDao,
|
||||
YesCountriesDao yesCountriesDao,
|
||||
UserNetworkDataSource
|
||||
networkDataSource, AppExecutors executors) {
|
||||
Log.d(LOG_TAG, "Getting the yes countries repository");
|
||||
if (sInstance == null) {
|
||||
synchronized (LOCK) {
|
||||
sInstance = new CountriesRepository(countriesDao,
|
||||
yesCountriesDao,
|
||||
networkDataSource, executors);
|
||||
Log.d(LOG_TAG, "Made new countries repository");
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public LiveData<List<Countries>> getCountriesList() {
|
||||
LiveData<List<Countries>> foo = mCountriesDao.getCountriesList();
|
||||
return foo;
|
||||
}
|
||||
|
||||
public void postServiceRequest(ServiceRequest serviceRequest) {
|
||||
mNetworkDataSource.fetchCountriesData(serviceRequest);
|
||||
}
|
||||
|
||||
public LiveData<List<YesCountries>> getYesCountriesList() {
|
||||
LiveData<List<YesCountries>> fie = mYesCountriesDao.getYesCountriesList();
|
||||
return fie;
|
||||
}
|
||||
|
||||
public void postServiceRequest1(ServiceRequest serviceRequest) {
|
||||
mNetworkDataSource.fetchYesCountriesData(serviceRequest);
|
||||
}
|
||||
}
|
95
app/src/main/java/com/josh/trackcovid19v2/data/StateRepository.java
Executable file
@@ -0,0 +1,95 @@
|
||||
package com.josh.trackcovid19v2.data;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
import com.josh.trackcovid19v2.AppExecutors;
|
||||
import com.josh.trackcovid19v2.data.database.StateDao;
|
||||
import com.josh.trackcovid19v2.data.database.YesStateDao;
|
||||
import com.josh.trackcovid19v2.data.database.entity.States;
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesStates;
|
||||
import com.josh.trackcovid19v2.data.network.UserNetworkDataSource;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class responsible for handling data operations. This is the mediator between different
|
||||
* data sources (persistent model, web service, cache, etc.)
|
||||
*/
|
||||
public class StateRepository {
|
||||
private static final String LOG_TAG = StateRepository.class.getSimpleName();
|
||||
|
||||
private StateDao mStatesDao;
|
||||
private YesStateDao mYesStatesDao;
|
||||
private UserNetworkDataSource mNetworkDataSource;
|
||||
|
||||
// For Singleton instantiationz
|
||||
private static final Object LOCK = new Object();
|
||||
private static StateRepository sInstance;
|
||||
|
||||
public StateRepository(StateDao stateDao,
|
||||
YesStateDao yesstatesDao,
|
||||
UserNetworkDataSource networkDataSource, AppExecutors
|
||||
executors) {
|
||||
this.mStatesDao = stateDao;
|
||||
this.mYesStatesDao = yesstatesDao;
|
||||
this.mNetworkDataSource = networkDataSource;
|
||||
|
||||
// As long as the repository exists, observe the network LiveData.
|
||||
// If that LiveData changes, update the database.
|
||||
mNetworkDataSource.getStatesList().observeForever(states -> {
|
||||
executors.diskIO().execute(() -> {
|
||||
|
||||
Log.d(LOG_TAG, "states table is updating");
|
||||
mStatesDao.updateAll(states);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
mNetworkDataSource.getYesStatesList().observeForever(yesstates -> {
|
||||
executors.diskIO().execute(() -> {
|
||||
|
||||
Log.d(LOG_TAG, "yes states table is updating");
|
||||
mYesStatesDao.updateAll(yesstates);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static StateRepository getInstance(StateDao stateDao,
|
||||
YesStateDao yesStateDao,
|
||||
UserNetworkDataSource
|
||||
networkDataSource, AppExecutors executors) {
|
||||
Log.d(LOG_TAG, "Getting the yes states repository");
|
||||
if (sInstance == null) {
|
||||
synchronized (LOCK) {
|
||||
sInstance = new StateRepository(stateDao,
|
||||
yesStateDao,
|
||||
networkDataSource, executors);
|
||||
Log.d(LOG_TAG, "Made new states repository");
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public LiveData<List<States>> getStatesList() {
|
||||
LiveData<List<States>> foo = mStatesDao.getStatesList();
|
||||
return foo;
|
||||
}
|
||||
|
||||
public void postServiceRequest(ServiceRequest serviceRequest) {
|
||||
mNetworkDataSource.fetchStatesData(serviceRequest);
|
||||
}
|
||||
|
||||
public LiveData<List<YesStates>> getYesStatesList() {
|
||||
LiveData<List<YesStates>> fie = mYesStatesDao.getYesStatesList();
|
||||
return fie;
|
||||
}
|
||||
|
||||
public void postServiceRequest1(ServiceRequest serviceRequest) {
|
||||
mNetworkDataSource.fetchYesStatesData(serviceRequest);
|
||||
}
|
||||
}
|
85
app/src/main/java/com/josh/trackcovid19v2/data/WorldRepository.java
Executable file
@@ -0,0 +1,85 @@
|
||||
package com.josh.trackcovid19v2.data;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
import com.josh.trackcovid19v2.AppExecutors;
|
||||
import com.josh.trackcovid19v2.data.database.WorldDao;
|
||||
import com.josh.trackcovid19v2.data.database.YesWorldDao;
|
||||
import com.josh.trackcovid19v2.data.database.entity.World;
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesWorld;
|
||||
import com.josh.trackcovid19v2.data.network.UserNetworkDataSource;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
|
||||
/**
|
||||
* This class responsible for handling data operations. This is the mediator between different
|
||||
* data sources (persistent model, web service, cache, etc.)
|
||||
*/
|
||||
public class WorldRepository {
|
||||
private static final String LOG_TAG = WorldRepository.class.getSimpleName();
|
||||
|
||||
private WorldDao mWorldDao;
|
||||
private YesWorldDao mYesWorldDao;
|
||||
private UserNetworkDataSource mNetworkDataSource;
|
||||
|
||||
// For Singleton instantiation
|
||||
private static final Object LOCK = new Object();
|
||||
private static WorldRepository sInstance;
|
||||
|
||||
public WorldRepository(WorldDao worldDao, YesWorldDao yesworldDao, UserNetworkDataSource networkDataSource, AppExecutors
|
||||
executors) {
|
||||
this.mWorldDao = worldDao;
|
||||
this.mYesWorldDao = yesworldDao;
|
||||
this.mNetworkDataSource = networkDataSource;
|
||||
|
||||
// As long as the repository exists, observe the network LiveData.
|
||||
// If that LiveData changes, update the database.
|
||||
mNetworkDataSource.getWorld().observeForever(world -> {
|
||||
executors.diskIO().execute(() -> {
|
||||
|
||||
Log.d(LOG_TAG, "world table is updating");
|
||||
mWorldDao.updateAll(world);
|
||||
});
|
||||
});
|
||||
|
||||
mNetworkDataSource.getYesWorld().observeForever(yesworld -> {
|
||||
executors.diskIO().execute(() -> {
|
||||
|
||||
Log.d(LOG_TAG, "yes world table is updating");
|
||||
mYesWorldDao.updateAll(yesworld);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static WorldRepository getInstance(WorldDao worldDao, YesWorldDao yesworldDao, UserNetworkDataSource
|
||||
networkDataSource, AppExecutors executors) {
|
||||
Log.d(LOG_TAG, "Getting the repository");
|
||||
if (sInstance == null) {
|
||||
synchronized (LOCK) {
|
||||
sInstance = new WorldRepository(worldDao, yesworldDao, networkDataSource, executors);
|
||||
Log.d(LOG_TAG, "Made new world repository");
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public LiveData<World> getWorld() {
|
||||
LiveData<World> foo = mWorldDao.getWorld();
|
||||
return foo;
|
||||
}
|
||||
|
||||
public LiveData<YesWorld> getYesWorld() {
|
||||
LiveData<YesWorld> foo = mYesWorldDao.getYesWorld();
|
||||
return foo;
|
||||
}
|
||||
|
||||
public void postServiceRequest(ServiceRequest serviceRequest) {
|
||||
mNetworkDataSource.fetchWorldData(serviceRequest);
|
||||
}
|
||||
|
||||
public void postServiceRequest1(ServiceRequest serviceRequest) {
|
||||
mNetworkDataSource.fetchYesWorldData(serviceRequest);
|
||||
}
|
||||
|
||||
}
|
33
app/src/main/java/com/josh/trackcovid19v2/data/database/CountriesDao.java
Executable file
@@ -0,0 +1,33 @@
|
||||
package com.josh.trackcovid19v2.data.database;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Transaction;
|
||||
|
||||
import com.josh.trackcovid19v2.data.database.entity.Countries;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Dao
|
||||
public abstract class CountriesDao {
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
abstract void bulkInsert(List<Countries> countries);
|
||||
|
||||
@Query("DELETE FROM countries")
|
||||
abstract void deleteAll();
|
||||
|
||||
@Query("Select * FROM countries ORDER BY country ASC")
|
||||
public abstract LiveData<List<Countries>> getCountriesList();
|
||||
|
||||
@Transaction
|
||||
public void updateAll(List<Countries> countries) {
|
||||
deleteAll();
|
||||
bulkInsert(countries);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
package com.josh.trackcovid19v2.data.database;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.room.Database;
|
||||
import androidx.room.Room;
|
||||
import androidx.room.RoomDatabase;
|
||||
|
||||
import com.josh.trackcovid19v2.data.database.entity.Countries;
|
||||
|
||||
//@Database(entities = { YourEntity.class }, version = 1, exportSchema = false)
|
||||
@Database(entities = {Countries.class}, version = 1, exportSchema = false)
|
||||
public abstract class CountriesDatabase extends RoomDatabase {
|
||||
|
||||
private static final String LOG_TAG = CountriesDatabase.class.getSimpleName();
|
||||
private static final String DATABASE_NAME = "countries";
|
||||
|
||||
// For Singleton instantiation
|
||||
private static final Object LOCK = new Object();
|
||||
private static CountriesDatabase mInstance;
|
||||
|
||||
public static CountriesDatabase getInstance(Context context) {
|
||||
Log.d(LOG_TAG, "Getting " + DATABASE_NAME + " database");
|
||||
|
||||
if (mInstance == null) {
|
||||
synchronized (LOCK) {
|
||||
mInstance = Room.databaseBuilder(context, CountriesDatabase.class, DATABASE_NAME).build();
|
||||
Log.d(LOG_TAG, DATABASE_NAME + " database has been created.");
|
||||
}
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
// The associated DAOs for the database
|
||||
public abstract CountriesDao countriesDao();
|
||||
|
||||
}
|
31
app/src/main/java/com/josh/trackcovid19v2/data/database/StateDao.java
Executable file
@@ -0,0 +1,31 @@
|
||||
package com.josh.trackcovid19v2.data.database;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Transaction;
|
||||
|
||||
import com.josh.trackcovid19v2.data.database.entity.States;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public abstract class StateDao {
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
abstract void bulkInsert(List<States> states);
|
||||
|
||||
@Query("DELETE FROM states")
|
||||
abstract void deleteAll();
|
||||
|
||||
@Query("Select * FROM states ORDER BY state ASC")
|
||||
public abstract LiveData<List<States>> getStatesList();
|
||||
|
||||
@Transaction
|
||||
public void updateAll(List<States> states) {
|
||||
deleteAll();
|
||||
bulkInsert(states);
|
||||
}
|
||||
}
|
40
app/src/main/java/com/josh/trackcovid19v2/data/database/StatesDatabase.java
Executable file
@@ -0,0 +1,40 @@
|
||||
package com.josh.trackcovid19v2.data.database;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.room.Database;
|
||||
import androidx.room.Room;
|
||||
import androidx.room.RoomDatabase;
|
||||
|
||||
import com.josh.trackcovid19v2.data.database.entity.States;
|
||||
|
||||
//@Database(entities = { YourEntity.class }, version = 1, exportSchema = false)
|
||||
@Database(entities = {States.class}, version = 1, exportSchema = false)
|
||||
public abstract class StatesDatabase extends RoomDatabase {
|
||||
|
||||
//public abstract class StatesDatabase {
|
||||
|
||||
private static final String LOG_TAG = StatesDatabase.class.getSimpleName();
|
||||
private static final String DATABASE_NAME = "states";
|
||||
|
||||
// For Singleton instantiation
|
||||
private static final Object LOCK = new Object();
|
||||
private static StatesDatabase mInstance;
|
||||
|
||||
public static StatesDatabase getInstance(Context context) {
|
||||
Log.d(LOG_TAG, "Getting " + DATABASE_NAME + " database");
|
||||
|
||||
if (mInstance == null) {
|
||||
synchronized (LOCK) {
|
||||
mInstance = Room.databaseBuilder(context, StatesDatabase.class, DATABASE_NAME).build();
|
||||
Log.d(LOG_TAG, DATABASE_NAME + " database has been created.");
|
||||
}
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
// The associated DAOs for the database
|
||||
public abstract StateDao stateDao();
|
||||
|
||||
}
|
30
app/src/main/java/com/josh/trackcovid19v2/data/database/WorldDao.java
Executable file
@@ -0,0 +1,30 @@
|
||||
package com.josh.trackcovid19v2.data.database;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Transaction;
|
||||
|
||||
import com.josh.trackcovid19v2.data.database.entity.World;
|
||||
|
||||
|
||||
@Dao
|
||||
public abstract class WorldDao {
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
abstract void bulkInsert(World all);
|
||||
|
||||
@Query("DELETE FROM world")
|
||||
abstract void deleteAll();
|
||||
|
||||
@Query("Select * FROM world")
|
||||
public abstract LiveData<World> getWorld();
|
||||
|
||||
@Transaction
|
||||
public void updateAll(World world) {
|
||||
deleteAll();
|
||||
bulkInsert(world);
|
||||
}
|
||||
}
|
39
app/src/main/java/com/josh/trackcovid19v2/data/database/WorldDatabase.java
Executable file
@@ -0,0 +1,39 @@
|
||||
package com.josh.trackcovid19v2.data.database;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.room.Database;
|
||||
import androidx.room.Room;
|
||||
import androidx.room.RoomDatabase;
|
||||
|
||||
import com.josh.trackcovid19v2.data.database.entity.World;
|
||||
|
||||
//@Database(entities = { YourEntity.class }, version = 1, exportSchema = false)
|
||||
@Database(entities = {World.class}, version = 1, exportSchema = false)
|
||||
public abstract class WorldDatabase extends RoomDatabase {
|
||||
|
||||
|
||||
private static final String LOG_TAG = WorldDatabase.class.getSimpleName();
|
||||
private static final String DATABASE_NAME = "all";
|
||||
|
||||
// For Singleton instantiation
|
||||
private static final Object LOCK = new Object();
|
||||
private static WorldDatabase mInstance;
|
||||
|
||||
public static WorldDatabase getInstance(Context context) {
|
||||
Log.d(LOG_TAG, "Getting " + DATABASE_NAME + " database");
|
||||
|
||||
if (mInstance == null) {
|
||||
synchronized (LOCK) {
|
||||
mInstance = Room.databaseBuilder(context, WorldDatabase.class, DATABASE_NAME).build();
|
||||
Log.d(LOG_TAG, DATABASE_NAME + " database has been created.");
|
||||
}
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
// The associated DAOs for the database
|
||||
public abstract WorldDao worldDao();
|
||||
|
||||
}
|
32
app/src/main/java/com/josh/trackcovid19v2/data/database/YesCountriesDao.java
Executable file
@@ -0,0 +1,32 @@
|
||||
package com.josh.trackcovid19v2.data.database;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Transaction;
|
||||
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesCountries;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Dao
|
||||
public abstract class YesCountriesDao {
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
abstract void bulkInsert(List<YesCountries> yescountries);
|
||||
|
||||
@Query("DELETE FROM yescountries")
|
||||
abstract void deleteAll();
|
||||
|
||||
@Query("Select * FROM yescountries ORDER BY country ASC")
|
||||
public abstract LiveData<List<YesCountries>> getYesCountriesList();
|
||||
|
||||
@Transaction
|
||||
public void updateAll(List<YesCountries> yescountries) {
|
||||
deleteAll();
|
||||
bulkInsert(yescountries);
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
package com.josh.trackcovid19v2.data.database;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.room.Database;
|
||||
import androidx.room.Room;
|
||||
import androidx.room.RoomDatabase;
|
||||
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesCountries;
|
||||
|
||||
//@Database(entities = { YourEntity.class }, version = 1, exportSchema = false)
|
||||
@Database(entities = {YesCountries.class}, version = 1, exportSchema = false)
|
||||
public abstract class YesCountriesDatabase extends RoomDatabase {
|
||||
|
||||
private static final String LOG_TAG = YesCountriesDatabase.class.getSimpleName();
|
||||
private static final String DATABASE_NAME = "yescountries";
|
||||
|
||||
// For Singleton instantiation
|
||||
private static final Object LOCK = new Object();
|
||||
private static YesCountriesDatabase mInstance;
|
||||
|
||||
public static YesCountriesDatabase getInstance(Context context) {
|
||||
Log.d(LOG_TAG, "Getting " + DATABASE_NAME + " database");
|
||||
|
||||
if (mInstance == null) {
|
||||
synchronized (LOCK) {
|
||||
mInstance = Room.databaseBuilder(context, YesCountriesDatabase.class, DATABASE_NAME).build();
|
||||
Log.d(LOG_TAG, DATABASE_NAME + " database has been created.");
|
||||
}
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
// The associated DAOs for the database
|
||||
public abstract YesCountriesDao yescountriesDao();
|
||||
|
||||
}
|
31
app/src/main/java/com/josh/trackcovid19v2/data/database/YesStateDao.java
Executable file
@@ -0,0 +1,31 @@
|
||||
package com.josh.trackcovid19v2.data.database;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Transaction;
|
||||
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesStates;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public abstract class YesStateDao {
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
abstract void bulkInsert(List<YesStates> yesstates);
|
||||
|
||||
@Query("DELETE FROM yesstates")
|
||||
abstract void deleteAll();
|
||||
|
||||
@Query("Select * FROM yesstates ORDER BY state ASC")
|
||||
public abstract LiveData<List<YesStates>> getYesStatesList();
|
||||
|
||||
@Transaction
|
||||
public void updateAll(List<YesStates> yesstates) {
|
||||
deleteAll();
|
||||
bulkInsert(yesstates);
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package com.josh.trackcovid19v2.data.database;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.room.Database;
|
||||
import androidx.room.Room;
|
||||
import androidx.room.RoomDatabase;
|
||||
|
||||
import com.josh.trackcovid19v2.data.database.entity.States;
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesStates;
|
||||
|
||||
//@Database(entities = { YourEntity.class }, version = 1, exportSchema = false)
|
||||
@Database(entities = {YesStates.class}, version = 1, exportSchema = false)
|
||||
public abstract class YesStatesDatabase extends RoomDatabase {
|
||||
|
||||
//public abstract class StatesDatabase {
|
||||
|
||||
private static final String LOG_TAG = YesStatesDatabase.class.getSimpleName();
|
||||
private static final String DATABASE_NAME = "yesstates";
|
||||
|
||||
// For Singleton instantiation
|
||||
private static final Object LOCK = new Object();
|
||||
private static YesStatesDatabase mInstance;
|
||||
|
||||
public static YesStatesDatabase getInstance(Context context) {
|
||||
Log.d(LOG_TAG, "Getting " + DATABASE_NAME + " database");
|
||||
|
||||
if (mInstance == null) {
|
||||
synchronized (LOCK) {
|
||||
mInstance = Room.databaseBuilder(context, YesStatesDatabase.class, DATABASE_NAME).build();
|
||||
Log.d(LOG_TAG, DATABASE_NAME + " database has been created.");
|
||||
}
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
// The associated DAOs for the database
|
||||
public abstract YesStateDao yesstateDao();
|
||||
|
||||
}
|
30
app/src/main/java/com/josh/trackcovid19v2/data/database/YesWorldDao.java
Executable file
@@ -0,0 +1,30 @@
|
||||
package com.josh.trackcovid19v2.data.database;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Transaction;
|
||||
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesWorld;
|
||||
|
||||
|
||||
@Dao
|
||||
public abstract class YesWorldDao {
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
abstract void bulkInsert(YesWorld all);
|
||||
|
||||
@Query("DELETE FROM yesworld")
|
||||
abstract void deleteAll();
|
||||
|
||||
@Query("Select * FROM yesworld")
|
||||
public abstract LiveData<YesWorld> getYesWorld();
|
||||
|
||||
@Transaction
|
||||
public void updateAll(YesWorld yesworld) {
|
||||
deleteAll();
|
||||
bulkInsert(yesworld);
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package com.josh.trackcovid19v2.data.database;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.room.Database;
|
||||
import androidx.room.Room;
|
||||
import androidx.room.RoomDatabase;
|
||||
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesWorld;
|
||||
|
||||
//@Database(entities = { YourEntity.class }, version = 1, exportSchema = false)
|
||||
@Database(entities = {YesWorld.class}, version = 1, exportSchema = false)
|
||||
public abstract class YesWorldDatabase extends RoomDatabase {
|
||||
|
||||
|
||||
private static final String LOG_TAG = YesWorldDatabase.class.getSimpleName();
|
||||
private static final String DATABASE_NAME = "yesall";
|
||||
|
||||
// For Singleton instantiation
|
||||
private static final Object LOCK = new Object();
|
||||
private static YesWorldDatabase mInstance;
|
||||
|
||||
public static YesWorldDatabase getInstance(Context context) {
|
||||
Log.d(LOG_TAG, "Getting " + DATABASE_NAME + " database");
|
||||
|
||||
if (mInstance == null) {
|
||||
synchronized (LOCK) {
|
||||
mInstance = Room.databaseBuilder(context, YesWorldDatabase.class, DATABASE_NAME).build();
|
||||
Log.d(LOG_TAG, DATABASE_NAME + " database has been created.");
|
||||
}
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
// The associated DAOs for the database
|
||||
public abstract YesWorldDao yesworldDao();
|
||||
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.josh.trackcovid19v2.data.database.entity;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 1.12.2017.
|
||||
*/
|
||||
@Entity(tableName = "countries")
|
||||
public class Countries {
|
||||
@PrimaryKey
|
||||
@NonNull
|
||||
public String country;
|
||||
public int cases;
|
||||
public int active;
|
||||
public int todayCases;
|
||||
public int deaths;
|
||||
public int todayDeaths;
|
||||
public int recovered;
|
||||
public int tests;
|
||||
public int testsPerMillion;
|
||||
public String flag;
|
||||
public int critical;
|
||||
public long updated;
|
||||
//@TypeConverters(CountryInfo.class)
|
||||
//public List<CountryInfo> countryinfo;
|
||||
}
|
||||
|
22
app/src/main/java/com/josh/trackcovid19v2/data/database/entity/States.java
Executable file
@@ -0,0 +1,22 @@
|
||||
package com.josh.trackcovid19v2.data.database.entity;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 1.12.2017.
|
||||
*/
|
||||
@Entity(tableName = "states")
|
||||
public class States {
|
||||
@PrimaryKey
|
||||
@NonNull
|
||||
public String state;
|
||||
public int cases;
|
||||
public int todayCases;
|
||||
public int deaths;
|
||||
public int todayDeaths;
|
||||
public int active;
|
||||
public int tests;
|
||||
public int testsPerMillion;
|
||||
}
|
21
app/src/main/java/com/josh/trackcovid19v2/data/database/entity/World.java
Executable file
@@ -0,0 +1,21 @@
|
||||
package com.josh.trackcovid19v2.data.database.entity;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 1.12.2017.
|
||||
*/
|
||||
@Entity(tableName = "world")
|
||||
public class World {
|
||||
@PrimaryKey
|
||||
@NonNull
|
||||
public int cases;
|
||||
public int deaths;
|
||||
public int recovered;
|
||||
public long updated;
|
||||
public int active;
|
||||
public int affectedCountries;
|
||||
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
package com.josh.trackcovid19v2.data.database.entity;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 1.12.2017.
|
||||
*/
|
||||
@Entity(tableName = "yescountries")
|
||||
public class YesCountries {
|
||||
@PrimaryKey
|
||||
@NonNull
|
||||
public String country;
|
||||
public int cases;
|
||||
public int active;
|
||||
public int todayCases;
|
||||
public int deaths;
|
||||
public int todayDeaths;
|
||||
public int recovered;
|
||||
public int tests;
|
||||
public int testsPerMillion;
|
||||
public String flag;
|
||||
public int critical;
|
||||
public long updated;
|
||||
|
||||
//@TypeConverters(CountryInfo.class)
|
||||
//public List<CountryInfo> countryinfo;
|
||||
}
|
||||
|
@@ -0,0 +1,22 @@
|
||||
package com.josh.trackcovid19v2.data.database.entity;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 1.12.2017.
|
||||
*/
|
||||
@Entity(tableName = "yesstates")
|
||||
public class YesStates {
|
||||
@PrimaryKey
|
||||
@NonNull
|
||||
public String state;
|
||||
public int cases;
|
||||
public int todayCases;
|
||||
public int deaths;
|
||||
public int todayDeaths;
|
||||
public int active;
|
||||
public int tests;
|
||||
public int testsPerMillion;
|
||||
}
|
21
app/src/main/java/com/josh/trackcovid19v2/data/database/entity/YesWorld.java
Executable file
@@ -0,0 +1,21 @@
|
||||
package com.josh.trackcovid19v2.data.database.entity;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 1.12.2017.
|
||||
*/
|
||||
@Entity(tableName = "yesworld")
|
||||
public class YesWorld {
|
||||
@PrimaryKey
|
||||
@NonNull
|
||||
public int cases;
|
||||
public int deaths;
|
||||
public int recovered;
|
||||
public long updated;
|
||||
public int active;
|
||||
public int affectedCountries;
|
||||
|
||||
}
|
322
app/src/main/java/com/josh/trackcovid19v2/data/network/NetworkUtils.java
Executable file
@@ -0,0 +1,322 @@
|
||||
package com.josh.trackcovid19v2.data.network;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.josh.trackcovid19v2.data.database.entity.Countries;
|
||||
import com.josh.trackcovid19v2.data.database.entity.States;
|
||||
import com.josh.trackcovid19v2.data.database.entity.World;
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesCountries;
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesStates;
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesWorld;
|
||||
import com.josh.trackcovid19v2.data.network.pojo.CountriesPojo;
|
||||
import com.josh.trackcovid19v2.data.network.pojo.StatesPojo;
|
||||
import com.josh.trackcovid19v2.data.network.pojo.YesCountriesPojo;
|
||||
import com.josh.trackcovid19v2.data.network.pojo.YesStatesPojo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
public class NetworkUtils {
|
||||
|
||||
private static final String LOG_TAG = NetworkUtils.class.getSimpleName();
|
||||
private static final String BASE_URL = "https://corona.lmao.ninja/";
|
||||
|
||||
private static Retrofit getRetrofit() {
|
||||
return new Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory
|
||||
.create()).build();
|
||||
}
|
||||
|
||||
// For getting states data -- create similar for countries
|
||||
/*
|
||||
public static Call<List<States>> getDataFromService() {
|
||||
Log.d(LOG_TAG, "Getting data from the server");
|
||||
List<States> foo = null;
|
||||
|
||||
RestApi service = getRetrofit().create(RestApi.class);
|
||||
|
||||
Call<List<States>> call = service.getStates();
|
||||
|
||||
|
||||
return call;
|
||||
}
|
||||
*/
|
||||
public static Call<List<StatesPojo>> getStatesDataFromService() {
|
||||
Log.d(LOG_TAG, "Getting states data from the server");
|
||||
|
||||
RestApi service = getRetrofit().create(RestApi.class);
|
||||
|
||||
Call<List<StatesPojo>> call = service.getStates(0);
|
||||
|
||||
return call;
|
||||
}
|
||||
|
||||
public static Call<List<YesStatesPojo>> getYesStatesDataFromService() {
|
||||
Log.d(LOG_TAG, "Getting yes states data from the server");
|
||||
|
||||
RestApi service = getRetrofit().create(RestApi.class);
|
||||
|
||||
Call<List<YesStatesPojo>> call = service.getYesStates(1);
|
||||
|
||||
return call;
|
||||
}
|
||||
|
||||
// For getting countries data
|
||||
public static Call<List<CountriesPojo>> getCountriesDataFromService() {
|
||||
Log.d(LOG_TAG, "Getting countries data from the server");
|
||||
//List<Countries> foo = null;
|
||||
|
||||
RestApi service = getRetrofit().create(RestApi.class);
|
||||
|
||||
Call<List<CountriesPojo>> call = service.getCountries(0);
|
||||
|
||||
|
||||
return call;
|
||||
}
|
||||
|
||||
public static Call<List<YesCountriesPojo>> getYesCountriesDataFromService() {
|
||||
Log.d(LOG_TAG, "Getting yesterdays countries data from the server");
|
||||
//List<Countries> foo = null;
|
||||
|
||||
RestApi service = getRetrofit().create(RestApi.class);
|
||||
|
||||
Call<List<YesCountriesPojo>> call = service.getYesCountries(1);
|
||||
|
||||
|
||||
return call;
|
||||
}
|
||||
|
||||
public static List<Countries> convertToCountriesList(List<CountriesPojo> data) {
|
||||
List<Countries> countries = new ArrayList<>();
|
||||
Log.d(LOG_TAG, "Converting the response.");
|
||||
|
||||
try {
|
||||
|
||||
|
||||
for (CountriesPojo ddd : data) {
|
||||
Countries country_data = new Countries();
|
||||
country_data.country = ddd.getCountry();
|
||||
country_data.cases = Integer.parseInt(ddd.getCases());
|
||||
country_data.active = Integer.parseInt(ddd.getActive());
|
||||
country_data.deaths = Integer.parseInt(ddd.getDeaths());
|
||||
country_data.todayCases = Integer.parseInt(ddd.getTodayCases());
|
||||
country_data.todayDeaths = Integer.parseInt(ddd.getTodayDeaths());
|
||||
country_data.recovered = Integer.parseInt(ddd.getRecovered());
|
||||
//country_data.recovered = 0;
|
||||
country_data.tests = Integer.parseInt(ddd.getTests());
|
||||
country_data.testsPerMillion = Integer.parseInt(ddd.getTestsPerOneMillion());
|
||||
country_data.flag = ddd.getCountryInfoPojo().getFlag();
|
||||
country_data.critical = Integer.parseInt(ddd.getCritical());
|
||||
country_data.updated = Long.parseLong(ddd.getUpdated());
|
||||
|
||||
|
||||
// add
|
||||
countries.add(country_data);
|
||||
}
|
||||
|
||||
|
||||
Log.d(LOG_TAG, "Converting the response process has been success. ");
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.d(LOG_TAG, "Converting the response process has been failed. ", e);
|
||||
}
|
||||
|
||||
return countries;
|
||||
}
|
||||
|
||||
public static List<States> convertToStatesList(List<StatesPojo> data) {
|
||||
List<States> states = new ArrayList<>();
|
||||
Log.d(LOG_TAG, "Converting the response.");
|
||||
|
||||
try {
|
||||
|
||||
|
||||
for (StatesPojo ddd : data) {
|
||||
States state_data = new States();
|
||||
state_data.state = ddd.getState();
|
||||
state_data.cases = Integer.parseInt(ddd.getCases());
|
||||
state_data.active = Integer.parseInt(ddd.getActive());
|
||||
state_data.deaths = Integer.parseInt(ddd.getDeaths());
|
||||
state_data.todayCases = Integer.parseInt(ddd.getTodayCases());
|
||||
state_data.todayDeaths = Integer.parseInt(ddd.getTodayDeaths());
|
||||
state_data.tests = Integer.parseInt(ddd.getTests());
|
||||
state_data.testsPerMillion = Integer.parseInt(ddd.getTestsPerOneMillion());
|
||||
|
||||
|
||||
|
||||
// add
|
||||
states.add(state_data);
|
||||
}
|
||||
|
||||
|
||||
Log.d(LOG_TAG, "Converting the response process has been success. ");
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.d(LOG_TAG, "Converting the response process has been failed. ", e);
|
||||
}
|
||||
|
||||
return states;
|
||||
}
|
||||
|
||||
public static List<YesStates> convertToYesStatesList(List<YesStatesPojo> data) {
|
||||
List<YesStates> yesstates = new ArrayList<>();
|
||||
Log.d(LOG_TAG, "Converting the response.");
|
||||
|
||||
try {
|
||||
|
||||
|
||||
for (YesStatesPojo ddd : data) {
|
||||
YesStates state_data = new YesStates();
|
||||
state_data.state = ddd.getState();
|
||||
state_data.cases = Integer.parseInt(ddd.getCases());
|
||||
state_data.active = Integer.parseInt(ddd.getActive());
|
||||
state_data.deaths = Integer.parseInt(ddd.getDeaths());
|
||||
state_data.todayCases = Integer.parseInt(ddd.getTodayCases());
|
||||
state_data.todayDeaths = Integer.parseInt(ddd.getTodayDeaths());
|
||||
state_data.tests = Integer.parseInt(ddd.getTests());
|
||||
state_data.testsPerMillion = Integer.parseInt(ddd.getTestsPerOneMillion());
|
||||
|
||||
|
||||
|
||||
// add
|
||||
yesstates.add(state_data);
|
||||
}
|
||||
|
||||
|
||||
Log.d(LOG_TAG, "Converting the response process has been success. ");
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.d(LOG_TAG, "Converting the response process has been failed. ", e);
|
||||
}
|
||||
|
||||
return yesstates;
|
||||
}
|
||||
|
||||
///
|
||||
public static List<States> convertToStatesList1(List<States> data) {
|
||||
List<States> states = new ArrayList<>();
|
||||
Log.d(LOG_TAG, "Converting the response.");
|
||||
|
||||
try {
|
||||
|
||||
/*
|
||||
for (States ddd : data) {
|
||||
States state_data = new States();
|
||||
state_data.state = ddd.state;
|
||||
state_data.cases = ddd.cases;
|
||||
state_data.todayCases = ddd.todayCases;
|
||||
state_data.deaths = ddd.deaths;
|
||||
state_data.todayDeaths = ddd.todayDeaths;
|
||||
state_data.active = ddd.active;
|
||||
|
||||
// add
|
||||
states.add(state_data);
|
||||
}
|
||||
*/
|
||||
|
||||
Log.d(LOG_TAG, "Converting the response process has been success. ");
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.d(LOG_TAG, "Converting the response process has been failed. ", e);
|
||||
}
|
||||
|
||||
//return states;
|
||||
return data;
|
||||
}
|
||||
|
||||
//private static Date getDate(String stringData) throws ParseException {
|
||||
// DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.getDefault());
|
||||
// return format.parse(stringData);
|
||||
//}
|
||||
|
||||
|
||||
public static Call<World> getWorldDataFromService() {
|
||||
Log.d(LOG_TAG, "Getting data from the server");
|
||||
|
||||
RestApi service = getRetrofit().create(RestApi.class);
|
||||
|
||||
Call<World> call = service.getWorld();
|
||||
|
||||
return call;
|
||||
}
|
||||
public static Call<YesWorld> getYesWorldDataFromService() {
|
||||
Log.d(LOG_TAG, "Getting yesterdays data from the server");
|
||||
|
||||
RestApi service = getRetrofit().create(RestApi.class);
|
||||
|
||||
Call<YesWorld> call = service.getYesWorld();
|
||||
|
||||
return call;
|
||||
}
|
||||
|
||||
public static List<YesCountries> convertToYesCountriesList(List<YesCountriesPojo> data) {
|
||||
List<YesCountries> yescountries = new ArrayList<>();
|
||||
Log.d(LOG_TAG, "Converting the response.");
|
||||
|
||||
try {
|
||||
|
||||
|
||||
for (YesCountriesPojo ddd : data) {
|
||||
YesCountries country_data = new YesCountries();
|
||||
country_data.country = ddd.getCountry();
|
||||
country_data.cases = Integer.parseInt(ddd.getCases());
|
||||
country_data.active = Integer.parseInt(ddd.getActive());
|
||||
country_data.deaths = Integer.parseInt(ddd.getDeaths());
|
||||
country_data.todayCases = Integer.parseInt(ddd.getTodayCases());
|
||||
country_data.todayDeaths = Integer.parseInt(ddd.getTodayDeaths());
|
||||
country_data.recovered = Integer.parseInt(ddd.getRecovered());
|
||||
//country_data.recovered = 0;
|
||||
country_data.tests = Integer.parseInt(ddd.getTests());
|
||||
country_data.testsPerMillion = Integer.parseInt(ddd.getTestsPerOneMillion());
|
||||
country_data.flag = ddd.getCountryInfoPojo().getFlag();
|
||||
country_data.critical = Integer.parseInt(ddd.getCritical());
|
||||
country_data.updated = Long.parseLong(ddd.getUpdated());
|
||||
// add
|
||||
yescountries.add(country_data);
|
||||
}
|
||||
|
||||
|
||||
Log.d(LOG_TAG, "Converting the response process has been success. ");
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.d(LOG_TAG, "Converting the response process has been failed. ", e);
|
||||
}
|
||||
|
||||
return yescountries;
|
||||
}
|
||||
|
||||
/*
|
||||
public static List<States> convertToStatesList(List<States> data) {
|
||||
List<States> states = new ArrayList<>();
|
||||
Log.d(LOG_TAG, "Converting the response.");
|
||||
|
||||
try {
|
||||
|
||||
|
||||
for (States ddd : data) {
|
||||
States state_data = new States();
|
||||
state_data.state = ddd.state;
|
||||
state_data.cases = ddd.cases;
|
||||
state_data.todayCases = ddd.todayCases;
|
||||
state_data.deaths = ddd.deaths;
|
||||
state_data.todayDeaths = ddd.todayDeaths;
|
||||
state_data.active = ddd.active;
|
||||
|
||||
// add
|
||||
states.add(state_data);
|
||||
}
|
||||
|
||||
//Log.d(LOG_TAG, "Converting the response process has been success. ");
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.d(LOG_TAG, "Converting the response process has been failed. ", e);
|
||||
}
|
||||
|
||||
//return states;
|
||||
return data;
|
||||
}
|
||||
*/
|
||||
}
|
48
app/src/main/java/com/josh/trackcovid19v2/data/network/RestApi.java
Executable file
@@ -0,0 +1,48 @@
|
||||
package com.josh.trackcovid19v2.data.network;
|
||||
|
||||
import com.josh.trackcovid19v2.data.database.entity.States;
|
||||
import com.josh.trackcovid19v2.data.database.entity.World;
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesWorld;
|
||||
import com.josh.trackcovid19v2.data.network.pojo.CountriesPojo;
|
||||
import com.josh.trackcovid19v2.data.network.pojo.StatesPojo;
|
||||
import com.josh.trackcovid19v2.data.network.pojo.YesCountriesPojo;
|
||||
import com.josh.trackcovid19v2.data.network.pojo.YesStatesPojo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Headers;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface RestApi {
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@GET("v2/states")
|
||||
Call<List<States>> getStatess();
|
||||
|
||||
@GET("v2/states")
|
||||
Call<List<StatesPojo>> getStates(@Query("yesterday") int y);
|
||||
|
||||
@GET("v2/states")
|
||||
Call<List<YesStatesPojo>> getYesStates(@Query("yesterday") int y);
|
||||
|
||||
@GET("/v2/countries")
|
||||
Call<List<CountriesPojo>> getCountries(@Query("yesterday") int y);
|
||||
|
||||
@GET("/v2/countries")
|
||||
Call<List<YesCountriesPojo>> getYesCountries(@Query("yesterday") int y);
|
||||
|
||||
@GET("v2/all")
|
||||
Call<World> getWorld();
|
||||
|
||||
@GET("v2/all?yesterday=true")
|
||||
Call<YesWorld> getYesWorld();
|
||||
|
||||
//countries/USA
|
||||
//yesterday/USA
|
||||
|
||||
//
|
||||
|
||||
//Observable<List<ServiceResponse>> getStates();
|
||||
}
|
24
app/src/main/java/com/josh/trackcovid19v2/data/network/StatesWrapper.java
Executable file
@@ -0,0 +1,24 @@
|
||||
package com.josh.trackcovid19v2.data.network;
|
||||
|
||||
import com.josh.trackcovid19v2.data.database.entity.States;
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class StatesWrapper {
|
||||
|
||||
@SerializedName("states")
|
||||
@Expose
|
||||
private List<States> states = null;
|
||||
|
||||
public List<States> getStates() {
|
||||
return states;
|
||||
}
|
||||
|
||||
public void setStates(List<States> states) {
|
||||
this.states = states;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,308 @@
|
||||
package com.josh.trackcovid19v2.data.network;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.josh.trackcovid19v2.AppExecutors;
|
||||
import com.josh.trackcovid19v2.data.database.entity.Countries;
|
||||
import com.josh.trackcovid19v2.data.database.entity.States;
|
||||
import com.josh.trackcovid19v2.data.database.entity.World;
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesCountries;
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesStates;
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesWorld;
|
||||
import com.josh.trackcovid19v2.data.network.pojo.CountriesPojo;
|
||||
import com.josh.trackcovid19v2.data.network.pojo.StatesPojo;
|
||||
import com.josh.trackcovid19v2.data.network.pojo.YesCountriesPojo;
|
||||
import com.josh.trackcovid19v2.data.network.pojo.YesStatesPojo;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class UserNetworkDataSource {
|
||||
|
||||
private static final String LOG_TAG = UserNetworkDataSource.class.getSimpleName();
|
||||
|
||||
// For Singleton instantiation
|
||||
private static UserNetworkDataSource sInstance;
|
||||
private static final Object LOCK = new Object();
|
||||
|
||||
private AppExecutors mAppExecutors;
|
||||
private final MutableLiveData<List<States>> mDownloadedStatesData;
|
||||
private final MutableLiveData<List<YesStates>> mDownloadedYesStatesData;
|
||||
private final MutableLiveData<List<Countries>> mDownloadedCountriesData;
|
||||
private final MutableLiveData<List<YesCountries>> mDownloadedYesCountriesData;
|
||||
private final MutableLiveData<World> mDownloadedWorldData;
|
||||
private final MutableLiveData<YesWorld> mDownloadedYesWorldData;
|
||||
|
||||
public UserNetworkDataSource(AppExecutors mAppExecutors) {
|
||||
this.mAppExecutors = mAppExecutors;
|
||||
this.mDownloadedStatesData = new MutableLiveData<>();
|
||||
this.mDownloadedYesStatesData = new MutableLiveData<>();
|
||||
this.mDownloadedCountriesData = new MutableLiveData<>();
|
||||
this.mDownloadedYesCountriesData = new MutableLiveData<>();
|
||||
this.mDownloadedWorldData = new MutableLiveData<>();
|
||||
this.mDownloadedYesWorldData = new MutableLiveData<>();
|
||||
}
|
||||
|
||||
public static UserNetworkDataSource getInstance(AppExecutors executors) {
|
||||
Log.d(LOG_TAG, "Getting the network data source");
|
||||
if (sInstance == null) {
|
||||
synchronized (LOCK) {
|
||||
sInstance = new UserNetworkDataSource(executors);
|
||||
Log.d(LOG_TAG, "Made new network data source");
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
/*
|
||||
public void fetchData(ServiceRequest serviceRequest) {
|
||||
mAppExecutors.networkIO().execute(() -> {
|
||||
try {
|
||||
Call<List<States>> call = NetworkUtils.getDataFromService();
|
||||
call.enqueue(new Callback<List<States>>() {
|
||||
@Override
|
||||
public void onResponse(Call<List<States>> call, Response<List<States>> response) {
|
||||
//Toast.makeText(MainActivity.this,response.body().toString(),Toast.LENGTH_SHORT).show();
|
||||
Log.e("Info", "got data");
|
||||
//ArrayList<States> foo = new ArrayList<States>();
|
||||
List<States> data = response.body();
|
||||
setStatesList(NetworkUtils.convertToStatesList(data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<List<States>> call, Throwable t) {
|
||||
Log.d(LOG_TAG, "fofofofofofof");
|
||||
Log.d("Error",t.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception ex) {
|
||||
Log.e(LOG_TAG, "Getting data process has been failed.", ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
*/
|
||||
|
||||
public void fetchStatesData(ServiceRequest serviceRequest) {
|
||||
mAppExecutors.networkIO().execute(() -> {
|
||||
try {
|
||||
Call<List<StatesPojo>> call = NetworkUtils.getStatesDataFromService();
|
||||
call.enqueue(new Callback<List<StatesPojo>>() {
|
||||
@Override
|
||||
public void onResponse(Call<List<StatesPojo>> call, Response<List<StatesPojo>> response) {
|
||||
//Toast.makeText(MainActivity.this,response.body().toString(),Toast.LENGTH_SHORT).show();
|
||||
Log.e("Info", "got states data");
|
||||
//ArrayList<States> foo = new ArrayList<States>();
|
||||
List<StatesPojo> data = response.body();
|
||||
setStatesList(NetworkUtils.convertToStatesList(data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<List<StatesPojo>> call, Throwable t) {
|
||||
Log.d(LOG_TAG, "states error");
|
||||
Log.d("Error",t.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception ex) {
|
||||
Log.e(LOG_TAG, "Getting states data process has been failed.", ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void fetchYesStatesData(ServiceRequest serviceRequest) {
|
||||
mAppExecutors.networkIO().execute(() -> {
|
||||
try {
|
||||
Call<List<YesStatesPojo>> call = NetworkUtils.getYesStatesDataFromService();
|
||||
call.enqueue(new Callback<List<YesStatesPojo>>() {
|
||||
@Override
|
||||
public void onResponse(Call<List<YesStatesPojo>> call, Response<List<YesStatesPojo>> response) {
|
||||
//Toast.makeText(MainActivity.this,response.body().toString(),Toast.LENGTH_SHORT).show();
|
||||
Log.e("Info", "got yes states data");
|
||||
//ArrayList<States> foo = new ArrayList<States>();
|
||||
List<YesStatesPojo> data = response.body();
|
||||
setYesStatesList(NetworkUtils.convertToYesStatesList(data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<List<YesStatesPojo>> call, Throwable t) {
|
||||
Log.d(LOG_TAG, "yes states error");
|
||||
Log.d("Error",t.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception ex) {
|
||||
Log.e(LOG_TAG, "Getting states data process has been failed.", ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void fetchCountriesData(ServiceRequest serviceRequest) {
|
||||
mAppExecutors.networkIO().execute(() -> {
|
||||
try {
|
||||
Call<List<CountriesPojo>> call = NetworkUtils.getCountriesDataFromService();
|
||||
call.enqueue(new Callback<List<CountriesPojo>>() {
|
||||
@Override
|
||||
public void onResponse(Call<List<CountriesPojo>> call, Response<List<CountriesPojo>> response) {
|
||||
//Toast.makeText(MainActivity.this,response.body().toString(),Toast.LENGTH_SHORT).show();
|
||||
Log.e("Info", "got countries data");
|
||||
//ArrayList<States> foo = new ArrayList<States>();
|
||||
List<CountriesPojo> data = response.body();
|
||||
setCountriesList(NetworkUtils.convertToCountriesList(data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<List<CountriesPojo>> call, Throwable t) {
|
||||
Log.d(LOG_TAG, "countries error");
|
||||
Log.d("Error",t.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception ex) {
|
||||
Log.e(LOG_TAG, "Getting data process has been failed.", ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void fetchYesCountriesData(ServiceRequest serviceRequest) {
|
||||
mAppExecutors.networkIO().execute(() -> {
|
||||
try {
|
||||
Call<List<YesCountriesPojo>> call = NetworkUtils.getYesCountriesDataFromService();
|
||||
call.enqueue(new Callback<List<YesCountriesPojo>>() {
|
||||
@Override
|
||||
public void onResponse(Call<List<YesCountriesPojo>> call, Response<List<YesCountriesPojo>> response) {
|
||||
//Toast.makeText(MainActivity.this,response.body().toString(),Toast.LENGTH_SHORT).show();
|
||||
Log.e("Info", "got yesterdays countries data");
|
||||
//ArrayList<States> foo = new ArrayList<States>();
|
||||
List<YesCountriesPojo> data = response.body();
|
||||
setYesCountriesList(NetworkUtils.convertToYesCountriesList(data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<List<YesCountriesPojo>> call, Throwable t) {
|
||||
Log.d(LOG_TAG, "yes countries error");
|
||||
Log.d("Error",t.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception ex) {
|
||||
Log.e(LOG_TAG, "Getting data process has been failed.", ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void fetchWorldData(ServiceRequest serviceRequest) {
|
||||
mAppExecutors.networkIO().execute(() -> {
|
||||
try {
|
||||
Call<World> call = NetworkUtils.getWorldDataFromService();
|
||||
call.enqueue(new Callback<World>() {
|
||||
@Override
|
||||
public void onResponse(Call<World> call, Response<World> response) {
|
||||
//Toast.makeText(MainActivity.this,response.body().toString(),Toast.LENGTH_SHORT).show();
|
||||
Log.e("Info", "got world data");
|
||||
//ArrayList<States> foo = new ArrayList<States>();
|
||||
World data = response.body();
|
||||
//setWorld(NetworkUtils.convertToStatesList(data));
|
||||
setWorld(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<World> call, Throwable t) {
|
||||
Log.d(LOG_TAG, "fofofofofofof");
|
||||
Log.d("Error", t.getMessage());
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
Log.e(LOG_TAG, "Getting data process has been failed.", ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void fetchYesWorldData(ServiceRequest serviceRequest) {
|
||||
mAppExecutors.networkIO().execute(() -> {
|
||||
try {
|
||||
Call<YesWorld> call1 = NetworkUtils.getYesWorldDataFromService();
|
||||
call1.enqueue(new Callback<YesWorld>() {
|
||||
@Override
|
||||
public void onResponse(Call<YesWorld> call, Response<YesWorld> response) {
|
||||
//Toast.makeText(MainActivity.this,response.body().toString(),Toast.LENGTH_SHORT).show();
|
||||
Log.e("Info", "got yesterday's world data");
|
||||
//ArrayList<States> foo = new ArrayList<States>();
|
||||
YesWorld data = response.body();
|
||||
//setWorld(NetworkUtils.convertToStatesList(data));
|
||||
setYesWorld(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<YesWorld> call, Throwable t) {
|
||||
Log.d(LOG_TAG, "fofofofofofof");
|
||||
Log.d("Error", t.getMessage());
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
Log.e(LOG_TAG, "Getting data process has been failed.", ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// private void setStatesList(List<States> statesList){
|
||||
// mDownloadedData.postValue(statesList);
|
||||
// }
|
||||
private void setWorld(World world) {
|
||||
mDownloadedWorldData.postValue(world);
|
||||
}
|
||||
|
||||
public LiveData<World> getWorld(){
|
||||
return mDownloadedWorldData;
|
||||
}
|
||||
|
||||
private void setYesWorld(YesWorld yesworld) {
|
||||
mDownloadedYesWorldData.postValue(yesworld);
|
||||
}
|
||||
|
||||
public LiveData<YesWorld> getYesWorld(){
|
||||
return mDownloadedYesWorldData;
|
||||
}
|
||||
|
||||
private void setStatesList(List<States> statesList){
|
||||
mDownloadedStatesData.postValue(statesList);
|
||||
}
|
||||
public LiveData<List<States>> getStatesList(){
|
||||
return mDownloadedStatesData;
|
||||
}
|
||||
|
||||
private void setYesStatesList(List<YesStates> yesstatesList){
|
||||
mDownloadedYesStatesData.postValue(yesstatesList);
|
||||
}
|
||||
public LiveData<List<YesStates>> getYesStatesList(){
|
||||
return mDownloadedYesStatesData;
|
||||
}
|
||||
|
||||
private void setCountriesList(List<Countries> countriesList){
|
||||
mDownloadedCountriesData.postValue(countriesList);
|
||||
}
|
||||
|
||||
public LiveData<List<Countries>> getCountriesList(){
|
||||
return mDownloadedCountriesData;
|
||||
}
|
||||
|
||||
private void setYesCountriesList(List<YesCountries> yescountriesList){
|
||||
mDownloadedYesCountriesData.postValue(yescountriesList);
|
||||
}
|
||||
public LiveData<List<YesCountries>> getYesCountriesList(){
|
||||
return mDownloadedYesCountriesData;
|
||||
}
|
||||
|
||||
|
||||
}
|
166
app/src/main/java/com/josh/trackcovid19v2/data/network/pojo/CountriesPojo.java
Executable file
@@ -0,0 +1,166 @@
|
||||
package com.josh.trackcovid19v2.data.network.pojo;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class CountriesPojo {
|
||||
|
||||
@SerializedName("country")
|
||||
@Expose
|
||||
private String country;
|
||||
@SerializedName("updated")
|
||||
@Expose
|
||||
private String updated;
|
||||
@SerializedName("cases")
|
||||
@Expose
|
||||
private String cases;
|
||||
@SerializedName("todayCases")
|
||||
@Expose
|
||||
private String todayCases;
|
||||
@SerializedName("deaths")
|
||||
@Expose
|
||||
private String deaths;
|
||||
@SerializedName("todayDeaths")
|
||||
@Expose
|
||||
private String todayDeaths;
|
||||
@SerializedName("recovered")
|
||||
@Expose
|
||||
private String recovered;
|
||||
@SerializedName("active")
|
||||
@Expose
|
||||
private String active;
|
||||
@SerializedName("critical")
|
||||
@Expose
|
||||
private String critical;
|
||||
@SerializedName("casesPerOneMillion")
|
||||
@Expose
|
||||
private String casesPerOneMillion;
|
||||
@SerializedName("deathsPerOneMillion")
|
||||
@Expose
|
||||
private String deathsPerOneMillion;
|
||||
@SerializedName("tests")
|
||||
@Expose
|
||||
private String tests;
|
||||
@SerializedName("testsPerOneMillion")
|
||||
@Expose
|
||||
private String testsPerOneMillion;
|
||||
@SerializedName("countryInfo")
|
||||
@Expose
|
||||
private CountryInfoPojo countryInfoPojo = null;
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public String getUpdated() {
|
||||
return updated;
|
||||
}
|
||||
|
||||
public void setUpdated(String updated) {
|
||||
this.updated = updated;
|
||||
}
|
||||
|
||||
public String getCases() {
|
||||
return cases;
|
||||
}
|
||||
|
||||
public void setCases(String cases) {
|
||||
this.cases = cases;
|
||||
}
|
||||
|
||||
public String getTodayCases() {
|
||||
return todayCases;
|
||||
}
|
||||
|
||||
public void setTodayCases(String todayCases) {
|
||||
this.todayCases = todayCases;
|
||||
}
|
||||
|
||||
public String getDeaths() {
|
||||
return deaths;
|
||||
}
|
||||
|
||||
public void setDeaths(String deaths) {
|
||||
this.deaths = deaths;
|
||||
}
|
||||
|
||||
public String getTodayDeaths() {
|
||||
return todayDeaths;
|
||||
}
|
||||
|
||||
public void setTodayDeaths(String todayDeaths) {
|
||||
this.todayDeaths = todayDeaths;
|
||||
}
|
||||
|
||||
public String getRecovered() {
|
||||
return recovered;
|
||||
}
|
||||
|
||||
public void setRecovered(String recovered) {
|
||||
this.recovered = recovered;
|
||||
}
|
||||
|
||||
public String getActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public void setActive(String active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public String getCritical() {
|
||||
return critical;
|
||||
}
|
||||
|
||||
public void setCritical(String critical) {
|
||||
this.critical = critical;
|
||||
}
|
||||
|
||||
public String getCasesPerOneMillion() {
|
||||
return casesPerOneMillion;
|
||||
}
|
||||
|
||||
public void setCasesPerOneMillion(String casesPerOneMillion) {
|
||||
this.casesPerOneMillion = casesPerOneMillion;
|
||||
}
|
||||
|
||||
public String getDeathsPerOneMillion() {
|
||||
return deathsPerOneMillion;
|
||||
}
|
||||
|
||||
public void setDeathsPerOneMillion(String deathsPerOneMillion) {
|
||||
this.deathsPerOneMillion = deathsPerOneMillion;
|
||||
}
|
||||
|
||||
public String getTests() {
|
||||
return tests;
|
||||
}
|
||||
|
||||
public void setTests(String tests) {
|
||||
this.tests = tests;
|
||||
}
|
||||
|
||||
public String getTestsPerOneMillion() {
|
||||
return testsPerOneMillion;
|
||||
}
|
||||
|
||||
public void setTestsPerOneMillion(String testsPerOneMillion) {
|
||||
this.testsPerOneMillion = testsPerOneMillion;
|
||||
}
|
||||
|
||||
public CountryInfoPojo getCountryInfoPojo() {
|
||||
return countryInfoPojo;
|
||||
}
|
||||
|
||||
public void setCountryInfoPojo(CountryInfoPojo countryInfoPojo) {
|
||||
this.countryInfoPojo = countryInfoPojo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -0,0 +1,74 @@
|
||||
package com.josh.trackcovid19v2.data.network.pojo;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class CountryInfoPojo {
|
||||
|
||||
@SerializedName("_id")
|
||||
@Expose
|
||||
private String _id;
|
||||
@SerializedName("iso2")
|
||||
@Expose
|
||||
private String iso2;
|
||||
@SerializedName("iso3")
|
||||
@Expose
|
||||
private String iso3;
|
||||
@SerializedName("lat")
|
||||
@Expose
|
||||
private String lat;
|
||||
@SerializedName("llong")
|
||||
@Expose
|
||||
private String llong;
|
||||
@SerializedName("flag")
|
||||
@Expose
|
||||
private String flag;
|
||||
|
||||
public String get_id() {
|
||||
return _id;
|
||||
}
|
||||
|
||||
public void set_id(String _id) {
|
||||
this._id = _id;
|
||||
}
|
||||
|
||||
public String getIso2() {
|
||||
return iso2;
|
||||
}
|
||||
|
||||
public void setIso2(String iso2) {
|
||||
this.iso2 = iso2;
|
||||
}
|
||||
|
||||
public String getIso3() {
|
||||
return iso3;
|
||||
}
|
||||
|
||||
public void setIso3(String iso3) {
|
||||
this.iso3 = iso3;
|
||||
}
|
||||
|
||||
public String getLat() {
|
||||
return lat;
|
||||
}
|
||||
|
||||
public void setLat(String lat) {
|
||||
this.lat = lat;
|
||||
}
|
||||
|
||||
public String getLlong() {
|
||||
return llong;
|
||||
}
|
||||
|
||||
public void setLlong(String llong) {
|
||||
this.llong = llong;
|
||||
}
|
||||
|
||||
public String getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
public void setFlag(String flag) {
|
||||
this.flag = flag;
|
||||
}
|
||||
}
|
104
app/src/main/java/com/josh/trackcovid19v2/data/network/pojo/StatesPojo.java
Executable file
@@ -0,0 +1,104 @@
|
||||
package com.josh.trackcovid19v2.data.network.pojo;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class StatesPojo {
|
||||
@SerializedName("state")
|
||||
@Expose
|
||||
public String state;
|
||||
@SerializedName("cases")
|
||||
@Expose
|
||||
public String cases;
|
||||
@SerializedName("todayCases")
|
||||
@Expose
|
||||
public String todayCases;
|
||||
@SerializedName("deaths")
|
||||
@Expose
|
||||
public String deaths;
|
||||
@SerializedName("todayDeaths")
|
||||
@Expose
|
||||
public String todayDeaths;
|
||||
@SerializedName("active")
|
||||
@Expose
|
||||
public String active;
|
||||
@SerializedName("tests")
|
||||
private String tests;
|
||||
@SerializedName("testsPerOneMillion")
|
||||
@Expose
|
||||
private String testsPerOneMillion;
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getCases() {
|
||||
return cases;
|
||||
}
|
||||
|
||||
public void setCases(String cases) {
|
||||
this.cases = cases;
|
||||
}
|
||||
|
||||
public String getTodayCases() {
|
||||
return todayCases;
|
||||
}
|
||||
|
||||
public void setTodayCases(String todayCases) {
|
||||
this.todayCases = todayCases;
|
||||
}
|
||||
|
||||
public String getDeaths() {
|
||||
return deaths;
|
||||
}
|
||||
|
||||
public void setDeaths(String deaths) {
|
||||
this.deaths = deaths;
|
||||
}
|
||||
|
||||
public String getTodayDeaths() {
|
||||
return todayDeaths;
|
||||
}
|
||||
|
||||
public void setTodayDeaths(String todayDeaths) {
|
||||
this.todayDeaths = todayDeaths;
|
||||
}
|
||||
|
||||
|
||||
public String getActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public void setActive(String active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
|
||||
public String getTests() {
|
||||
return tests;
|
||||
}
|
||||
|
||||
public void setTests(String tests) {
|
||||
this.tests = tests;
|
||||
}
|
||||
|
||||
public String getTestsPerOneMillion() {
|
||||
return testsPerOneMillion;
|
||||
}
|
||||
|
||||
public void setTestsPerOneMillion(String testsPerOneMillion) {
|
||||
this.testsPerOneMillion = testsPerOneMillion;
|
||||
}
|
||||
//@SerializedName("group")
|
||||
// @Expose
|
||||
//public Group group;
|
||||
//@SerializedName("address")
|
||||
//@Expose
|
||||
//public Address address;
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,166 @@
|
||||
package com.josh.trackcovid19v2.data.network.pojo;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class YesCountriesPojo {
|
||||
|
||||
@SerializedName("country")
|
||||
@Expose
|
||||
private String country;
|
||||
@SerializedName("updated")
|
||||
@Expose
|
||||
private String updated;
|
||||
@SerializedName("cases")
|
||||
@Expose
|
||||
private String cases;
|
||||
@SerializedName("todayCases")
|
||||
@Expose
|
||||
private String todayCases;
|
||||
@SerializedName("deaths")
|
||||
@Expose
|
||||
private String deaths;
|
||||
@SerializedName("todayDeaths")
|
||||
@Expose
|
||||
private String todayDeaths;
|
||||
@SerializedName("recovered")
|
||||
@Expose
|
||||
private String recovered;
|
||||
@SerializedName("active")
|
||||
@Expose
|
||||
private String active;
|
||||
@SerializedName("critical")
|
||||
@Expose
|
||||
private String critical;
|
||||
@SerializedName("casesPerOneMillion")
|
||||
@Expose
|
||||
private String casesPerOneMillion;
|
||||
@SerializedName("deathsPerOneMillion")
|
||||
@Expose
|
||||
private String deathsPerOneMillion;
|
||||
@SerializedName("tests")
|
||||
@Expose
|
||||
private String tests;
|
||||
@SerializedName("testsPerOneMillion")
|
||||
@Expose
|
||||
private String testsPerOneMillion;
|
||||
@SerializedName("countryInfo")
|
||||
@Expose
|
||||
private CountryInfoPojo countryInfoPojo = null;
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public String getUpdated() {
|
||||
return updated;
|
||||
}
|
||||
|
||||
public void setUpdated(String updated) {
|
||||
this.updated = updated;
|
||||
}
|
||||
|
||||
public String getCases() {
|
||||
return cases;
|
||||
}
|
||||
|
||||
public void setCases(String cases) {
|
||||
this.cases = cases;
|
||||
}
|
||||
|
||||
public String getTodayCases() {
|
||||
return todayCases;
|
||||
}
|
||||
|
||||
public void setTodayCases(String todayCases) {
|
||||
this.todayCases = todayCases;
|
||||
}
|
||||
|
||||
public String getDeaths() {
|
||||
return deaths;
|
||||
}
|
||||
|
||||
public void setDeaths(String deaths) {
|
||||
this.deaths = deaths;
|
||||
}
|
||||
|
||||
public String getTodayDeaths() {
|
||||
return todayDeaths;
|
||||
}
|
||||
|
||||
public void setTodayDeaths(String todayDeaths) {
|
||||
this.todayDeaths = todayDeaths;
|
||||
}
|
||||
|
||||
public String getRecovered() {
|
||||
return recovered;
|
||||
}
|
||||
|
||||
public void setRecovered(String recovered) {
|
||||
this.recovered = recovered;
|
||||
}
|
||||
|
||||
public String getActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public void setActive(String active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public String getCritical() {
|
||||
return critical;
|
||||
}
|
||||
|
||||
public void setCritical(String critical) {
|
||||
this.critical = critical;
|
||||
}
|
||||
|
||||
public String getCasesPerOneMillion() {
|
||||
return casesPerOneMillion;
|
||||
}
|
||||
|
||||
public void setCasesPerOneMillion(String casesPerOneMillion) {
|
||||
this.casesPerOneMillion = casesPerOneMillion;
|
||||
}
|
||||
|
||||
public String getDeathsPerOneMillion() {
|
||||
return deathsPerOneMillion;
|
||||
}
|
||||
|
||||
public void setDeathsPerOneMillion(String deathsPerOneMillion) {
|
||||
this.deathsPerOneMillion = deathsPerOneMillion;
|
||||
}
|
||||
|
||||
public String getTests() {
|
||||
return tests;
|
||||
}
|
||||
|
||||
public void setTests(String tests) {
|
||||
this.tests = tests;
|
||||
}
|
||||
|
||||
public String getTestsPerOneMillion() {
|
||||
return testsPerOneMillion;
|
||||
}
|
||||
|
||||
public void setTestsPerOneMillion(String testsPerOneMillion) {
|
||||
this.testsPerOneMillion = testsPerOneMillion;
|
||||
}
|
||||
|
||||
public CountryInfoPojo getCountryInfoPojo() {
|
||||
return countryInfoPojo;
|
||||
}
|
||||
|
||||
public void setCountryInfoPojo(CountryInfoPojo countryInfoPojo) {
|
||||
this.countryInfoPojo = countryInfoPojo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -0,0 +1,74 @@
|
||||
package com.josh.trackcovid19v2.data.network.pojo;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class YesCountryInfoPojo {
|
||||
|
||||
@SerializedName("_id")
|
||||
@Expose
|
||||
private String _id;
|
||||
@SerializedName("iso2")
|
||||
@Expose
|
||||
private String iso2;
|
||||
@SerializedName("iso3")
|
||||
@Expose
|
||||
private String iso3;
|
||||
@SerializedName("lat")
|
||||
@Expose
|
||||
private String lat;
|
||||
@SerializedName("llong")
|
||||
@Expose
|
||||
private String llong;
|
||||
@SerializedName("flag")
|
||||
@Expose
|
||||
private String flag;
|
||||
|
||||
public String get_id() {
|
||||
return _id;
|
||||
}
|
||||
|
||||
public void set_id(String _id) {
|
||||
this._id = _id;
|
||||
}
|
||||
|
||||
public String getIso2() {
|
||||
return iso2;
|
||||
}
|
||||
|
||||
public void setIso2(String iso2) {
|
||||
this.iso2 = iso2;
|
||||
}
|
||||
|
||||
public String getIso3() {
|
||||
return iso3;
|
||||
}
|
||||
|
||||
public void setIso3(String iso3) {
|
||||
this.iso3 = iso3;
|
||||
}
|
||||
|
||||
public String getLat() {
|
||||
return lat;
|
||||
}
|
||||
|
||||
public void setLat(String lat) {
|
||||
this.lat = lat;
|
||||
}
|
||||
|
||||
public String getLlong() {
|
||||
return llong;
|
||||
}
|
||||
|
||||
public void setLlong(String llong) {
|
||||
this.llong = llong;
|
||||
}
|
||||
|
||||
public String getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
public void setFlag(String flag) {
|
||||
this.flag = flag;
|
||||
}
|
||||
}
|
@@ -0,0 +1,98 @@
|
||||
package com.josh.trackcovid19v2.data.network.pojo;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class YesStatesPojo {
|
||||
@SerializedName("state")
|
||||
@Expose
|
||||
public String state;
|
||||
@SerializedName("cases")
|
||||
@Expose
|
||||
public String cases;
|
||||
@SerializedName("todayCases")
|
||||
@Expose
|
||||
public String todayCases;
|
||||
@SerializedName("deaths")
|
||||
@Expose
|
||||
public String deaths;
|
||||
@SerializedName("todayDeaths")
|
||||
@Expose
|
||||
public String todayDeaths;
|
||||
@SerializedName("active")
|
||||
@Expose
|
||||
public String active;
|
||||
@SerializedName("tests")
|
||||
private String tests;
|
||||
@SerializedName("testsPerOneMillion")
|
||||
@Expose
|
||||
private String testsPerOneMillion;
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getCases() {
|
||||
return cases;
|
||||
}
|
||||
|
||||
public void setCases(String cases) {
|
||||
this.cases = cases;
|
||||
}
|
||||
|
||||
public String getTodayCases() {
|
||||
return todayCases;
|
||||
}
|
||||
|
||||
public void setTodayCases(String todayCases) {
|
||||
this.todayCases = todayCases;
|
||||
}
|
||||
|
||||
public String getDeaths() {
|
||||
return deaths;
|
||||
}
|
||||
|
||||
public void setDeaths(String deaths) {
|
||||
this.deaths = deaths;
|
||||
}
|
||||
|
||||
public String getTodayDeaths() {
|
||||
return todayDeaths;
|
||||
}
|
||||
|
||||
public void setTodayDeaths(String todayDeaths) {
|
||||
this.todayDeaths = todayDeaths;
|
||||
}
|
||||
|
||||
|
||||
public String getActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public void setActive(String active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
|
||||
public String getTests() {
|
||||
return tests;
|
||||
}
|
||||
|
||||
public void setTests(String tests) {
|
||||
this.tests = tests;
|
||||
}
|
||||
|
||||
public String getTestsPerOneMillion() {
|
||||
return testsPerOneMillion;
|
||||
}
|
||||
|
||||
public void setTestsPerOneMillion(String testsPerOneMillion) {
|
||||
this.testsPerOneMillion = testsPerOneMillion;
|
||||
}
|
||||
|
||||
|
||||
}
|
11
app/src/main/java/com/josh/trackcovid19v2/model/Countries.java
Executable file
@@ -0,0 +1,11 @@
|
||||
package com.josh.trackcovid19v2.model;
|
||||
import java.util.List;
|
||||
|
||||
public class Countries {
|
||||
|
||||
public String Country;
|
||||
public String flag;
|
||||
public List<CountryData> CountryData;
|
||||
|
||||
|
||||
}
|
9
app/src/main/java/com/josh/trackcovid19v2/model/CountryData.java
Executable file
@@ -0,0 +1,9 @@
|
||||
package com.josh.trackcovid19v2.model;
|
||||
|
||||
public class CountryData {
|
||||
|
||||
public int cases;
|
||||
public int active;
|
||||
|
||||
|
||||
}
|
10
app/src/main/java/com/josh/trackcovid19v2/model/ServiceRequest.java
Executable file
@@ -0,0 +1,10 @@
|
||||
package com.josh.trackcovid19v2.model;
|
||||
|
||||
public class ServiceRequest {
|
||||
|
||||
public ServiceRequest() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
14
app/src/main/java/com/josh/trackcovid19v2/model/ServiceResponse.java
Executable file
@@ -0,0 +1,14 @@
|
||||
package com.josh.trackcovid19v2.model;
|
||||
|
||||
import com.josh.trackcovid19v2.data.network.pojo.StatesPojo;
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ServiceResponse {
|
||||
|
||||
@SerializedName("data")
|
||||
@Expose
|
||||
public List<StatesPojo> data = null;
|
||||
}
|
@@ -0,0 +1,145 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.evrencoskun.tableview.adapter.AbstractTableAdapter;
|
||||
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractSorterViewHolder;
|
||||
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder;
|
||||
import com.josh.trackcovid19v2.R;
|
||||
import com.josh.trackcovid19v2.data.database.entity.Countries;
|
||||
import com.josh.trackcovid19v2.ui.tableview.holder.CellViewHolder;
|
||||
import com.josh.trackcovid19v2.ui.tableview.holder.ColumnHeaderViewHolder;
|
||||
import com.josh.trackcovid19v2.ui.tableview.holder.MoneyCellViewHolder;
|
||||
import com.josh.trackcovid19v2.ui.tableview.holder.RowHeaderViewHolder;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.CellModel;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.ColumnHeaderModel;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.RowHeaderModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 27.11.2017.
|
||||
*/
|
||||
|
||||
public class CountriesTableAdapter extends AbstractTableAdapter<ColumnHeaderModel, RowHeaderModel,
|
||||
CellModel> {
|
||||
|
||||
private CountriesTableViewModel myTableViewModel;
|
||||
|
||||
public CountriesTableAdapter(Context p_jContext) {
|
||||
super(p_jContext);
|
||||
|
||||
this.myTableViewModel = new CountriesTableViewModel();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AbstractViewHolder onCreateCellViewHolder(ViewGroup parent, int viewType) {
|
||||
View layout;
|
||||
|
||||
switch (viewType) {
|
||||
|
||||
default:
|
||||
// Get default Cell xml Layout
|
||||
layout = LayoutInflater.from(mContext).inflate(R.layout.tableview_cell_layout,
|
||||
parent, false);
|
||||
|
||||
// Create a Cell ViewHolder
|
||||
return new CellViewHolder(layout);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindCellViewHolder(AbstractViewHolder holder, Object p_jValue, int
|
||||
p_nXPosition, int p_nYPosition) {
|
||||
CellModel cell = (CellModel) p_jValue;
|
||||
|
||||
if (holder instanceof CellViewHolder) {
|
||||
// Get the holder to update cell item text
|
||||
((CellViewHolder) holder).setCellModel(cell, p_nXPosition);
|
||||
|
||||
} else if (holder instanceof MoneyCellViewHolder) {
|
||||
((MoneyCellViewHolder) holder).setCellModel(cell);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractSorterViewHolder onCreateColumnHeaderViewHolder(ViewGroup parent, int viewType) {
|
||||
View layout = LayoutInflater.from(mContext).inflate(R.layout
|
||||
.tableview_column_header_layout, parent, false);
|
||||
|
||||
return new ColumnHeaderViewHolder(layout, getTableView());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindColumnHeaderViewHolder(AbstractViewHolder holder, Object p_jValue, int
|
||||
p_nXPosition) {
|
||||
ColumnHeaderModel columnHeader = (ColumnHeaderModel) p_jValue;
|
||||
|
||||
// Get the holder to update cell item text
|
||||
ColumnHeaderViewHolder columnHeaderViewHolder = (ColumnHeaderViewHolder) holder;
|
||||
|
||||
columnHeaderViewHolder.setColumnHeaderModel(columnHeader, p_nXPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractViewHolder onCreateRowHeaderViewHolder(ViewGroup parent, int viewType) {
|
||||
|
||||
// Get Row Header xml Layout
|
||||
View layout = LayoutInflater.from(mContext).inflate(R.layout.tableview_row_header_layout,
|
||||
parent, false);
|
||||
|
||||
// Create a Row Header ViewHolder
|
||||
return new RowHeaderViewHolder(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindRowHeaderViewHolder(AbstractViewHolder holder, Object p_jValue, int
|
||||
p_nYPosition) {
|
||||
|
||||
RowHeaderModel rowHeaderModel = (RowHeaderModel) p_jValue;
|
||||
|
||||
RowHeaderViewHolder rowHeaderViewHolder = (RowHeaderViewHolder) holder;
|
||||
rowHeaderViewHolder.row_header_textview.setText(rowHeaderModel.getData());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateCornerView() {
|
||||
return LayoutInflater.from(mContext).inflate(R.layout.tableview_corner_layout, null, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnHeaderItemViewType(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowHeaderItemViewType(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCellItemViewType(int position) {
|
||||
return myTableViewModel.getCellItemViewType(position);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is not a generic Adapter method. It helps to generate lists from single user
|
||||
* list for this adapter.
|
||||
*/
|
||||
public void setCountriesList(List<Countries> countriesList) {
|
||||
// Generate the lists that are used to TableViewAdapter
|
||||
myTableViewModel.generateListForTableView(countriesList);
|
||||
|
||||
// Now we got what we need to show on TableView.
|
||||
setAllItems(myTableViewModel.getColumHeaderModeList(), myTableViewModel
|
||||
.getRowHeaderModelList(), myTableViewModel.getCellModelList());
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,203 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview;
|
||||
|
||||
import android.view.Gravity;
|
||||
|
||||
import com.josh.trackcovid19v2.data.database.entity.Countries;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.CellModel;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.ColumnHeaderModel;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.RowHeaderModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 4.02.2018.
|
||||
*/
|
||||
|
||||
public class CountriesTableViewModel {
|
||||
|
||||
|
||||
private List<ColumnHeaderModel> mColumnHeaderModelList;
|
||||
private List<RowHeaderModel> mRowHeaderModelList;
|
||||
private List<List<CellModel>> mCellModelList;
|
||||
|
||||
public int getCellItemViewType(int column) {
|
||||
|
||||
switch (column) {
|
||||
/*
|
||||
case 5:
|
||||
// 5. column header is gender.
|
||||
return GENDER_TYPE;
|
||||
case 8:
|
||||
// 8. column header is Salary.
|
||||
return MONEY_TYPE;
|
||||
|
||||
*/
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
- Each of Column Header -
|
||||
"Id"
|
||||
"Name"
|
||||
"Nickname"
|
||||
"Email"
|
||||
"Birthday"
|
||||
"Gender"
|
||||
"Age"
|
||||
"Job"
|
||||
"Salary"
|
||||
"CreatedAt"
|
||||
"UpdatedAt"
|
||||
"Address"
|
||||
"Zip Code"
|
||||
"Phone"
|
||||
"Fax"
|
||||
*/
|
||||
|
||||
public int getColumnTextAlign(int column) {
|
||||
switch (column) {
|
||||
// Id
|
||||
case 0:
|
||||
return Gravity.CENTER;
|
||||
// Name
|
||||
case 1:
|
||||
return Gravity.LEFT;
|
||||
// Nickname
|
||||
case 2:
|
||||
return Gravity.LEFT;
|
||||
// Email
|
||||
case 3:
|
||||
return Gravity.LEFT;
|
||||
// BirthDay
|
||||
case 4:
|
||||
return Gravity.CENTER;
|
||||
// Gender (Sex)
|
||||
case 5:
|
||||
return Gravity.CENTER;
|
||||
// Age
|
||||
case 6:
|
||||
return Gravity.CENTER;
|
||||
// Job
|
||||
case 7:
|
||||
return Gravity.LEFT;
|
||||
// Salary
|
||||
case 8:
|
||||
return Gravity.CENTER;
|
||||
// CreatedAt
|
||||
case 9:
|
||||
return Gravity.CENTER;
|
||||
// UpdatedAt
|
||||
case 10:
|
||||
return Gravity.CENTER;
|
||||
// Address
|
||||
case 11:
|
||||
return Gravity.LEFT;
|
||||
// Zip Code
|
||||
case 12:
|
||||
return Gravity.RIGHT;
|
||||
// Phone
|
||||
case 13:
|
||||
return Gravity.RIGHT;
|
||||
// Fax
|
||||
case 14:
|
||||
return Gravity.RIGHT;
|
||||
default:
|
||||
return Gravity.CENTER;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private List<ColumnHeaderModel> createColumnHeaderModelList() {
|
||||
List<ColumnHeaderModel> list = new ArrayList<>();
|
||||
|
||||
// Create Column Headers
|
||||
list.add(new ColumnHeaderModel("Country"));
|
||||
// list.add(new ColumnHeaderModel("Flag"));
|
||||
list.add(new ColumnHeaderModel("Cases"));
|
||||
list.add(new ColumnHeaderModel("Today's Cases"));
|
||||
list.add(new ColumnHeaderModel("Deaths"));
|
||||
list.add(new ColumnHeaderModel("Today's Deaths"));
|
||||
list.add(new ColumnHeaderModel("Active"));
|
||||
|
||||
/*
|
||||
list.add(new ColumnHeaderModel("Cases"));
|
||||
list.add(new ColumnHeaderModel("Today's Cases"));
|
||||
list.add(new ColumnHeaderModel("Deaths"));
|
||||
list.add(new ColumnHeaderModel("Today's Deaths"));
|
||||
list.add(new ColumnHeaderModel("Active Cases"));
|
||||
*/
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<List<CellModel>> createCellModelList(List<Countries> countriesList) {
|
||||
List<List<CellModel>> lists = new ArrayList<>();
|
||||
|
||||
// Creating cell model list from User list for Cell Items
|
||||
// In this example, State list is populated from web service
|
||||
|
||||
for (int i = 0; i < countriesList.size(); i++) {
|
||||
Countries country_data = countriesList.get(i);
|
||||
|
||||
List<CellModel> list = new ArrayList<>();
|
||||
|
||||
// The order should be same with column header list;
|
||||
list.add(new CellModel("1-" + i, country_data.country)); // "Id"
|
||||
// list.add(new CellModel("1-" + i, Html.ImageGetter(country_data.flag);
|
||||
list.add(new CellModel("2-" + i, country_data.cases));
|
||||
list.add(new CellModel("3-" + i, country_data.todayCases));
|
||||
list.add(new CellModel("4-" + i, country_data.deaths));
|
||||
list.add(new CellModel("5-" + i, country_data.todayDeaths));
|
||||
list.add(new CellModel("6-" + i, country_data.active));
|
||||
|
||||
|
||||
/*
|
||||
list.add(new CellModel("2-" + i, country_data.cases)); // "Name"
|
||||
list.add(new CellModel("3-" + i, country_data.todayCases)); // "Nickname"
|
||||
list.add(new CellModel("4-" + i, country_data.deaths)); // "Email"
|
||||
list.add(new CellModel("5-" + i, country_data.todayDeaths)); // "BirthDay"
|
||||
list.add(new CellModel("6-" + i, country_data.active));
|
||||
*/
|
||||
// Add
|
||||
lists.add(list);
|
||||
}
|
||||
|
||||
return lists;
|
||||
}
|
||||
|
||||
private List<RowHeaderModel> createRowHeaderList(int size) {
|
||||
List<RowHeaderModel> list = new ArrayList<>();
|
||||
for (int i = 0; i < size; i++) {
|
||||
// In this example, Row headers just shows the index of the TableView List.
|
||||
list.add(new RowHeaderModel(String.valueOf(i + 1)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public List<ColumnHeaderModel> getColumHeaderModeList() {
|
||||
return mColumnHeaderModelList;
|
||||
}
|
||||
|
||||
public List<RowHeaderModel> getRowHeaderModelList() {
|
||||
return mRowHeaderModelList;
|
||||
}
|
||||
|
||||
public List<List<CellModel>> getCellModelList() {
|
||||
return mCellModelList;
|
||||
}
|
||||
|
||||
|
||||
public void generateListForTableView(List<Countries> countries) {
|
||||
mColumnHeaderModelList = createColumnHeaderModelList();
|
||||
mCellModelList = createCellModelList(countries);
|
||||
mRowHeaderModelList = createRowHeaderList(countries.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
145
app/src/main/java/com/josh/trackcovid19v2/ui/tableview/MyTableAdapter.java
Executable file
@@ -0,0 +1,145 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.evrencoskun.tableview.adapter.AbstractTableAdapter;
|
||||
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractSorterViewHolder;
|
||||
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder;
|
||||
import com.josh.trackcovid19v2.R;
|
||||
import com.josh.trackcovid19v2.data.database.entity.States;
|
||||
import com.josh.trackcovid19v2.ui.tableview.holder.CellViewHolder;
|
||||
import com.josh.trackcovid19v2.ui.tableview.holder.ColumnHeaderViewHolder;
|
||||
import com.josh.trackcovid19v2.ui.tableview.holder.MoneyCellViewHolder;
|
||||
import com.josh.trackcovid19v2.ui.tableview.holder.RowHeaderViewHolder;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.CellModel;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.ColumnHeaderModel;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.RowHeaderModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 27.11.2017.
|
||||
*/
|
||||
|
||||
public class MyTableAdapter extends AbstractTableAdapter<ColumnHeaderModel, RowHeaderModel,
|
||||
CellModel> {
|
||||
|
||||
private MyTableViewModel myTableViewModel;
|
||||
|
||||
public MyTableAdapter(Context p_jContext) {
|
||||
super(p_jContext);
|
||||
|
||||
this.myTableViewModel = new MyTableViewModel();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AbstractViewHolder onCreateCellViewHolder(ViewGroup parent, int viewType) {
|
||||
View layout;
|
||||
|
||||
switch (viewType) {
|
||||
|
||||
default:
|
||||
// Get default Cell xml Layout
|
||||
layout = LayoutInflater.from(mContext).inflate(R.layout.tableview_cell_layout,
|
||||
parent, false);
|
||||
|
||||
// Create a Cell ViewHolder
|
||||
return new CellViewHolder(layout);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindCellViewHolder(AbstractViewHolder holder, Object p_jValue, int
|
||||
p_nXPosition, int p_nYPosition) {
|
||||
CellModel cell = (CellModel) p_jValue;
|
||||
|
||||
if (holder instanceof CellViewHolder) {
|
||||
// Get the holder to update cell item text
|
||||
((CellViewHolder) holder).setCellModel(cell, p_nXPosition);
|
||||
|
||||
} else if (holder instanceof MoneyCellViewHolder) {
|
||||
((MoneyCellViewHolder) holder).setCellModel(cell);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractSorterViewHolder onCreateColumnHeaderViewHolder(ViewGroup parent, int viewType) {
|
||||
View layout = LayoutInflater.from(mContext).inflate(R.layout
|
||||
.tableview_column_header_layout, parent, false);
|
||||
|
||||
return new ColumnHeaderViewHolder(layout, getTableView());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindColumnHeaderViewHolder(AbstractViewHolder holder, Object p_jValue, int
|
||||
p_nXPosition) {
|
||||
ColumnHeaderModel columnHeader = (ColumnHeaderModel) p_jValue;
|
||||
|
||||
// Get the holder to update cell item text
|
||||
ColumnHeaderViewHolder columnHeaderViewHolder = (ColumnHeaderViewHolder) holder;
|
||||
|
||||
columnHeaderViewHolder.setColumnHeaderModel(columnHeader, p_nXPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractViewHolder onCreateRowHeaderViewHolder(ViewGroup parent, int viewType) {
|
||||
|
||||
// Get Row Header xml Layout
|
||||
View layout = LayoutInflater.from(mContext).inflate(R.layout.tableview_row_header_layout,
|
||||
parent, false);
|
||||
|
||||
// Create a Row Header ViewHolder
|
||||
return new RowHeaderViewHolder(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindRowHeaderViewHolder(AbstractViewHolder holder, Object p_jValue, int
|
||||
p_nYPosition) {
|
||||
|
||||
RowHeaderModel rowHeaderModel = (RowHeaderModel) p_jValue;
|
||||
|
||||
RowHeaderViewHolder rowHeaderViewHolder = (RowHeaderViewHolder) holder;
|
||||
rowHeaderViewHolder.row_header_textview.setText(rowHeaderModel.getData());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateCornerView() {
|
||||
return LayoutInflater.from(mContext).inflate(R.layout.tableview_corner_layout, null, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnHeaderItemViewType(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowHeaderItemViewType(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCellItemViewType(int position) {
|
||||
return myTableViewModel.getCellItemViewType(position);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is not a generic Adapter method. It helps to generate lists from single user
|
||||
* list for this adapter.
|
||||
*/
|
||||
public void setStatesList(List<States> statesList) {
|
||||
// Generate the lists that are used to TableViewAdapter
|
||||
myTableViewModel.generateListForTableView(statesList);
|
||||
|
||||
// Now we got what we need to show on TableView.
|
||||
setAllItems(myTableViewModel.getColumHeaderModeList(), myTableViewModel
|
||||
.getRowHeaderModelList(), myTableViewModel.getCellModelList());
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.evrencoskun.tableview.ITableView;
|
||||
import com.evrencoskun.tableview.listener.ITableViewListener;
|
||||
import com.josh.trackcovid19v2.ui.tableview.holder.ColumnHeaderViewHolder;
|
||||
import com.josh.trackcovid19v2.ui.tableview.popup.ColumnHeaderLongPressPopup;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 2.12.2017.
|
||||
*/
|
||||
|
||||
public class MyTableViewListener implements ITableViewListener {
|
||||
private static final String LOG_TAG = MyTableViewListener.class.getSimpleName();
|
||||
|
||||
private ITableView mTableView;
|
||||
|
||||
public MyTableViewListener(ITableView pTableView) {
|
||||
this.mTableView = pTableView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCellClicked(@NonNull RecyclerView.ViewHolder cellView, int column, int row) {
|
||||
Log.d(LOG_TAG, "onCellClicked has been clicked for x= " + column + " y= " + row);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCellLongPressed(@NonNull RecyclerView.ViewHolder cellView, int column, int row) {
|
||||
Log.d(LOG_TAG, "onCellLongPressed has been clicked for " + row);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColumnHeaderClicked(@NonNull RecyclerView.ViewHolder columnHeaderView, int
|
||||
column) {
|
||||
Log.d(LOG_TAG, "onColumnHeaderClicked has been clicked for " + column);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColumnHeaderLongPressed(@NonNull RecyclerView.ViewHolder columnHeaderView, int
|
||||
column) {
|
||||
if (columnHeaderView != null && columnHeaderView instanceof ColumnHeaderViewHolder) {
|
||||
|
||||
// Create Long Press Popup
|
||||
ColumnHeaderLongPressPopup popup = new ColumnHeaderLongPressPopup(
|
||||
(ColumnHeaderViewHolder) columnHeaderView, mTableView);
|
||||
|
||||
// Show
|
||||
popup.show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRowHeaderClicked(@NonNull RecyclerView.ViewHolder rowHeaderView, int row) {
|
||||
Log.d(LOG_TAG, "onRowHeaderClicked has been clicked for " + row);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRowHeaderLongPressed(@NonNull RecyclerView.ViewHolder owHeaderView, int row) {
|
||||
Log.d(LOG_TAG, "onRowHeaderLongPressed has been clicked for " + row);
|
||||
}
|
||||
}
|
188
app/src/main/java/com/josh/trackcovid19v2/ui/tableview/MyTableViewModel.java
Executable file
@@ -0,0 +1,188 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview;
|
||||
|
||||
import android.view.Gravity;
|
||||
|
||||
import com.josh.trackcovid19v2.data.database.entity.States;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.CellModel;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.ColumnHeaderModel;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.RowHeaderModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 4.02.2018.
|
||||
*/
|
||||
|
||||
public class MyTableViewModel {
|
||||
// View Types
|
||||
public static final int GENDER_TYPE = 1;
|
||||
public static final int MONEY_TYPE = 2;
|
||||
|
||||
private List<ColumnHeaderModel> mColumnHeaderModelList;
|
||||
private List<RowHeaderModel> mRowHeaderModelList;
|
||||
private List<List<CellModel>> mCellModelList;
|
||||
|
||||
public int getCellItemViewType(int column) {
|
||||
|
||||
switch (column) {
|
||||
/*
|
||||
case 5:
|
||||
// 5. column header is gender.
|
||||
return GENDER_TYPE;
|
||||
case 8:
|
||||
// 8. column header is Salary.
|
||||
return MONEY_TYPE;
|
||||
|
||||
*/
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
- Each of Column Header -
|
||||
"Id"
|
||||
"Name"
|
||||
"Nickname"
|
||||
"Email"
|
||||
"Birthday"
|
||||
"Gender"
|
||||
"Age"
|
||||
"Job"
|
||||
"Salary"
|
||||
"CreatedAt"
|
||||
"UpdatedAt"
|
||||
"Address"
|
||||
"Zip Code"
|
||||
"Phone"
|
||||
"Fax"
|
||||
*/
|
||||
|
||||
public int getColumnTextAlign(int column) {
|
||||
switch (column) {
|
||||
// Id
|
||||
case 0:
|
||||
return Gravity.CENTER;
|
||||
// Name
|
||||
case 1:
|
||||
return Gravity.LEFT;
|
||||
// Nickname
|
||||
case 2:
|
||||
return Gravity.LEFT;
|
||||
// Email
|
||||
case 3:
|
||||
return Gravity.LEFT;
|
||||
// BirthDay
|
||||
case 4:
|
||||
return Gravity.CENTER;
|
||||
// Gender (Sex)
|
||||
case 5:
|
||||
return Gravity.CENTER;
|
||||
// Age
|
||||
case 6:
|
||||
return Gravity.CENTER;
|
||||
// Job
|
||||
case 7:
|
||||
return Gravity.LEFT;
|
||||
// Salary
|
||||
case 8:
|
||||
return Gravity.CENTER;
|
||||
// CreatedAt
|
||||
case 9:
|
||||
return Gravity.CENTER;
|
||||
// UpdatedAt
|
||||
case 10:
|
||||
return Gravity.CENTER;
|
||||
// Address
|
||||
case 11:
|
||||
return Gravity.LEFT;
|
||||
// Zip Code
|
||||
case 12:
|
||||
return Gravity.RIGHT;
|
||||
// Phone
|
||||
case 13:
|
||||
return Gravity.RIGHT;
|
||||
// Fax
|
||||
case 14:
|
||||
return Gravity.RIGHT;
|
||||
default:
|
||||
return Gravity.CENTER;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private List<ColumnHeaderModel> createColumnHeaderModelList() {
|
||||
List<ColumnHeaderModel> list = new ArrayList<>();
|
||||
|
||||
// Create Column Headers
|
||||
list.add(new ColumnHeaderModel("State"));
|
||||
list.add(new ColumnHeaderModel("Cases"));
|
||||
list.add(new ColumnHeaderModel("Today's Cases"));
|
||||
list.add(new ColumnHeaderModel("Deaths"));
|
||||
list.add(new ColumnHeaderModel("Today's Deaths"));
|
||||
list.add(new ColumnHeaderModel("Active Cases"));
|
||||
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<List<CellModel>> createCellModelList(List<States> stateList) {
|
||||
List<List<CellModel>> lists = new ArrayList<>();
|
||||
|
||||
// Creating cell model list from User list for Cell Items
|
||||
// In this example, State list is populated from web service
|
||||
|
||||
for (int i = 0; i < stateList.size(); i++) {
|
||||
States state_data = stateList.get(i);
|
||||
|
||||
List<CellModel> list = new ArrayList<>();
|
||||
|
||||
// The order should be same with column header list;
|
||||
list.add(new CellModel("1-" + i, state_data.state)); // "Id"
|
||||
list.add(new CellModel("2-" + i, state_data.cases)); // "Name"
|
||||
list.add(new CellModel("3-" + i, state_data.todayCases)); // "Nickname"
|
||||
list.add(new CellModel("4-" + i, state_data.deaths)); // "Email"
|
||||
list.add(new CellModel("5-" + i, state_data.todayDeaths)); // "BirthDay"
|
||||
list.add(new CellModel("6-" + i, state_data.active));
|
||||
|
||||
// Add
|
||||
lists.add(list);
|
||||
}
|
||||
|
||||
return lists;
|
||||
}
|
||||
|
||||
private List<RowHeaderModel> createRowHeaderList(int size) {
|
||||
List<RowHeaderModel> list = new ArrayList<>();
|
||||
for (int i = 0; i < size; i++) {
|
||||
// In this example, Row headers just shows the index of the TableView List.
|
||||
list.add(new RowHeaderModel(String.valueOf(i + 1)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public List<ColumnHeaderModel> getColumHeaderModeList() {
|
||||
return mColumnHeaderModelList;
|
||||
}
|
||||
|
||||
public List<RowHeaderModel> getRowHeaderModelList() {
|
||||
return mRowHeaderModelList;
|
||||
}
|
||||
|
||||
public List<List<CellModel>> getCellModelList() {
|
||||
return mCellModelList;
|
||||
}
|
||||
|
||||
|
||||
public void generateListForTableView(List<States> states) {
|
||||
mColumnHeaderModelList = createColumnHeaderModelList();
|
||||
mCellModelList = createCellModelList(states);
|
||||
mRowHeaderModelList = createRowHeaderList(states.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -0,0 +1,54 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview.holder;
|
||||
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder;
|
||||
import com.josh.trackcovid19v2.R;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.CellModel;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 1.12.2017.
|
||||
*/
|
||||
|
||||
public class CellViewHolder extends AbstractViewHolder {
|
||||
public final TextView cell_textview;
|
||||
public final LinearLayout cell_container;
|
||||
|
||||
public CellViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
cell_textview = itemView.findViewById(R.id.cell_data);
|
||||
cell_container = itemView.findViewById(R.id.cell_container);
|
||||
}
|
||||
|
||||
public void setCellModel(CellModel p_jModel, int pColumnPosition) {
|
||||
|
||||
// Change textView align by column
|
||||
cell_textview.setGravity(ColumnHeaderViewHolder.COLUMN_TEXT_ALIGNS[pColumnPosition] |
|
||||
Gravity.CENTER_VERTICAL);
|
||||
|
||||
// Set text
|
||||
cell_textview.setText(String.valueOf(p_jModel.getData()));
|
||||
|
||||
// It is necessary to remeasure itself.
|
||||
cell_container.getLayoutParams().width = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||
cell_textview.requestLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(SelectionState p_nSelectionState) {
|
||||
super.setSelected(p_nSelectionState);
|
||||
|
||||
if (p_nSelectionState == SelectionState.SELECTED) {
|
||||
cell_textview.setTextColor(ContextCompat.getColor(cell_textview.getContext(), R.color
|
||||
.selected_text_color));
|
||||
} else {
|
||||
cell_textview.setTextColor(ContextCompat.getColor(cell_textview.getContext(), R.color
|
||||
.unselected_text_color));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,154 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview.holder;
|
||||
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.evrencoskun.tableview.ITableView;
|
||||
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractSorterViewHolder;
|
||||
import com.evrencoskun.tableview.sort.SortState;
|
||||
import com.josh.trackcovid19v2.R;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.ColumnHeaderModel;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 1.12.2017.
|
||||
*/
|
||||
|
||||
public class ColumnHeaderViewHolder extends AbstractSorterViewHolder {
|
||||
final LinearLayout column_header_container;
|
||||
final TextView column_header_textview;
|
||||
final ImageButton column_header_sort_button;
|
||||
final ITableView tableView;
|
||||
|
||||
public ColumnHeaderViewHolder(View itemView, ITableView pTableView) {
|
||||
super(itemView);
|
||||
tableView = pTableView;
|
||||
column_header_textview = itemView.findViewById(R.id.column_header_textView);
|
||||
column_header_container = itemView.findViewById(R.id.column_header_container);
|
||||
column_header_sort_button = itemView.findViewById(R.id.column_header_sort_imageButton);
|
||||
|
||||
// Set click listener to the sort button
|
||||
column_header_sort_button.setOnClickListener(mSortButtonClickListener);
|
||||
}
|
||||
|
||||
public void setColumnHeaderModel(ColumnHeaderModel pColumnHeaderModel, int pColumnPosition) {
|
||||
|
||||
// Change alignment of textView
|
||||
column_header_textview.setGravity(COLUMN_TEXT_ALIGNS[pColumnPosition] | Gravity
|
||||
.CENTER_VERTICAL);
|
||||
|
||||
// Set text data
|
||||
column_header_textview.setText(pColumnHeaderModel.getData());
|
||||
|
||||
// It is necessary to remeasure itself.
|
||||
column_header_container.getLayoutParams().width = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||
column_header_textview.requestLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(SelectionState p_nSelectionState) {
|
||||
super.setSelected(p_nSelectionState);
|
||||
|
||||
int nBackgroundColorId;
|
||||
int nForegroundColorId;
|
||||
|
||||
if (p_nSelectionState == SelectionState.SELECTED) {
|
||||
nBackgroundColorId = R.color.selected_background_color;
|
||||
nForegroundColorId = R.color.selected_text_color;
|
||||
|
||||
} else if (p_nSelectionState == SelectionState.UNSELECTED) {
|
||||
nBackgroundColorId = R.color.unselected_header_background_color;
|
||||
nForegroundColorId = R.color.unselected_text_color;
|
||||
|
||||
} else { // SelectionState.SHADOWED
|
||||
|
||||
nBackgroundColorId = R.color.shadow_background_color;
|
||||
nForegroundColorId = R.color.unselected_text_color;
|
||||
}
|
||||
|
||||
column_header_container.setBackgroundColor(ContextCompat.getColor(column_header_container
|
||||
.getContext(), nBackgroundColorId));
|
||||
column_header_textview.setTextColor(ContextCompat.getColor(column_header_container
|
||||
.getContext(), nForegroundColorId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSortingStatusChanged(SortState pSortState) {
|
||||
super.onSortingStatusChanged(pSortState);
|
||||
|
||||
// It is necessary to remeasure itself.
|
||||
column_header_container.getLayoutParams().width = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||
|
||||
controlSortState(pSortState);
|
||||
|
||||
column_header_textview.requestLayout();
|
||||
column_header_sort_button.requestLayout();
|
||||
column_header_container.requestLayout();
|
||||
itemView.requestLayout();
|
||||
}
|
||||
|
||||
private void controlSortState(SortState pSortState) {
|
||||
if (pSortState == SortState.ASCENDING) {
|
||||
column_header_sort_button.setVisibility(View.VISIBLE);
|
||||
column_header_sort_button.setImageResource(R.drawable.ic_down);
|
||||
|
||||
} else if (pSortState == SortState.DESCENDING) {
|
||||
column_header_sort_button.setVisibility(View.VISIBLE);
|
||||
column_header_sort_button.setImageResource(R.drawable.ic_up);
|
||||
} else {
|
||||
column_header_sort_button.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private View.OnClickListener mSortButtonClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (getSortState() == SortState.ASCENDING) {
|
||||
tableView.sortColumn(getAdapterPosition(), SortState.DESCENDING);
|
||||
} else if (getSortState() == SortState.DESCENDING) {
|
||||
tableView.sortColumn(getAdapterPosition(), SortState.ASCENDING);
|
||||
} else {
|
||||
// Default one
|
||||
tableView.sortColumn(getAdapterPosition(), SortState.DESCENDING);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static final int[] COLUMN_TEXT_ALIGNS = {
|
||||
// Id
|
||||
Gravity.CENTER,
|
||||
// Name
|
||||
Gravity.LEFT,
|
||||
// Nickname
|
||||
Gravity.LEFT,
|
||||
// Email
|
||||
Gravity.LEFT,
|
||||
// BirthDay
|
||||
Gravity.CENTER,
|
||||
// Gender (Sex)
|
||||
Gravity.CENTER,
|
||||
// Age
|
||||
Gravity.CENTER,
|
||||
// Job
|
||||
Gravity.LEFT,
|
||||
// Salary
|
||||
Gravity.CENTER,
|
||||
// CreatedAt
|
||||
Gravity.CENTER,
|
||||
// UpdatedAt
|
||||
Gravity.CENTER,
|
||||
// Address
|
||||
Gravity.LEFT,
|
||||
// Zip Code
|
||||
Gravity.RIGHT,
|
||||
// Phone
|
||||
Gravity.RIGHT,
|
||||
// Fax
|
||||
Gravity.RIGHT};
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview.holder;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.ColorRes;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder;
|
||||
import com.josh.trackcovid19v2.R;
|
||||
import com.josh.trackcovid19v2.ui.tableview.model.CellModel;
|
||||
|
||||
import org.fabiomsr.moneytextview.MoneyTextView;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 22.12.2017.
|
||||
*/
|
||||
|
||||
public class MoneyCellViewHolder extends AbstractViewHolder {
|
||||
public final MoneyTextView cell_textview;
|
||||
public final LinearLayout cell_container;
|
||||
|
||||
public MoneyCellViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
cell_textview = itemView.findViewById(R.id.money_cell_data);
|
||||
cell_container = itemView.findViewById(R.id.cell_container);
|
||||
}
|
||||
|
||||
public void setCellModel(CellModel p_jModel) {
|
||||
|
||||
// Set text
|
||||
cell_textview.setAmount(Float.parseFloat((String) p_jModel.getData()));
|
||||
|
||||
// It is necessary to remeasure itself.
|
||||
cell_container.getLayoutParams().width = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||
cell_textview.requestLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(SelectionState p_nSelectionState) {
|
||||
super.setSelected(p_nSelectionState);
|
||||
|
||||
if (p_nSelectionState == SelectionState.SELECTED) {
|
||||
changeColorOfMoneyTextView(R.color.selected_text_color);
|
||||
} else {
|
||||
changeColorOfMoneyTextView(R.color.unselected_text_color);
|
||||
}
|
||||
}
|
||||
|
||||
private void changeColorOfMoneyTextView(@ColorRes int id) {
|
||||
int color = ContextCompat.getColor(cell_textview.getContext(), id);
|
||||
|
||||
cell_textview.setBaseColor(color);
|
||||
cell_textview.setDecimalsColor(color);
|
||||
cell_textview.setSymbolColor(color);
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview.holder;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder;
|
||||
import com.josh.trackcovid19v2.R;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 1.12.2017.
|
||||
*/
|
||||
|
||||
public class RowHeaderViewHolder extends AbstractViewHolder {
|
||||
public final TextView row_header_textview;
|
||||
|
||||
public RowHeaderViewHolder(View p_jItemView) {
|
||||
super(p_jItemView);
|
||||
row_header_textview = p_jItemView.findViewById(R.id.row_header_textview);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(SelectionState p_nSelectionState) {
|
||||
super.setSelected(p_nSelectionState);
|
||||
|
||||
int nBackgroundColorId;
|
||||
int nForegroundColorId;
|
||||
|
||||
if (p_nSelectionState == SelectionState.SELECTED) {
|
||||
nBackgroundColorId = R.color.selected_background_color;
|
||||
nForegroundColorId = R.color.selected_text_color;
|
||||
|
||||
} else if (p_nSelectionState == SelectionState.UNSELECTED) {
|
||||
nBackgroundColorId = R.color.unselected_header_background_color;
|
||||
nForegroundColorId = R.color.unselected_text_color;
|
||||
|
||||
} else { // SelectionState.SHADOWED
|
||||
|
||||
nBackgroundColorId = R.color.shadow_background_color;
|
||||
nForegroundColorId = R.color.unselected_text_color;
|
||||
}
|
||||
|
||||
itemView.setBackgroundColor(ContextCompat.getColor(itemView.getContext(),
|
||||
nBackgroundColorId));
|
||||
row_header_textview.setTextColor(ContextCompat.getColor(row_header_textview.getContext(),
|
||||
nForegroundColorId));
|
||||
}
|
||||
}
|
32
app/src/main/java/com/josh/trackcovid19v2/ui/tableview/model/CellModel.java
Executable file
@@ -0,0 +1,32 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview.model;
|
||||
|
||||
import com.evrencoskun.tableview.sort.ISortableModel;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 27.11.2017.
|
||||
*/
|
||||
|
||||
public class CellModel implements ISortableModel {
|
||||
private String mId;
|
||||
private Object mData;
|
||||
|
||||
public CellModel(String pId, Object mData) {
|
||||
this.mId = pId;
|
||||
this.mData = mData;
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return mData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return mId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getContent() {
|
||||
return mData;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview.model;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 27.11.2017.
|
||||
*/
|
||||
|
||||
public class ColumnHeaderModel {
|
||||
|
||||
private String mData;
|
||||
|
||||
public ColumnHeaderModel(String mData) {
|
||||
this.mData = mData;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return mData;
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview.model;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 27.11.2017.
|
||||
*/
|
||||
|
||||
public class RowHeaderModel {
|
||||
private String mData;
|
||||
|
||||
public RowHeaderModel(String mData) {
|
||||
this.mData = mData;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return mData;
|
||||
}
|
||||
}
|
@@ -0,0 +1,121 @@
|
||||
package com.josh.trackcovid19v2.ui.tableview.popup;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.PopupMenu;
|
||||
|
||||
import com.evrencoskun.tableview.ITableView;
|
||||
import com.evrencoskun.tableview.sort.SortState;
|
||||
import com.josh.trackcovid19v2.R;
|
||||
import com.josh.trackcovid19v2.ui.tableview.holder.ColumnHeaderViewHolder;
|
||||
|
||||
/**
|
||||
* Created by evrencoskun on 26.12.2017.
|
||||
*/
|
||||
|
||||
public class ColumnHeaderLongPressPopup extends PopupMenu implements PopupMenu
|
||||
.OnMenuItemClickListener {
|
||||
private static final String LOG_TAG = ColumnHeaderLongPressPopup.class.getSimpleName();
|
||||
|
||||
// Sort states
|
||||
private static final int ASCENDING = 1;
|
||||
private static final int DESCENDING = 2;
|
||||
private static final int CLEAR = 3;
|
||||
// Test menu items for showing / hiding row
|
||||
private static final int ROW_HIDE = 4;
|
||||
private static final int ROW_SHOW = 3;
|
||||
|
||||
//
|
||||
private static final int TEST_ROW_INDEX = 4;
|
||||
|
||||
|
||||
private ColumnHeaderViewHolder m_iViewHolder;
|
||||
private ITableView m_iTableView;
|
||||
private Context mContext;
|
||||
private int mXPosition;
|
||||
|
||||
public ColumnHeaderLongPressPopup(ColumnHeaderViewHolder p_iViewHolder, ITableView
|
||||
p_jTableView) {
|
||||
super(p_iViewHolder.itemView.getContext(), p_iViewHolder.itemView);
|
||||
this.m_iViewHolder = p_iViewHolder;
|
||||
this.m_iTableView = p_jTableView;
|
||||
this.mContext = p_iViewHolder.itemView.getContext();
|
||||
this.mXPosition = m_iViewHolder.getAdapterPosition();
|
||||
|
||||
// find the view holder
|
||||
m_iViewHolder = (ColumnHeaderViewHolder) m_iTableView.getColumnHeaderRecyclerView()
|
||||
.findViewHolderForAdapterPosition(mXPosition);
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
createMenuItem();
|
||||
changeMenuItemVisibility();
|
||||
|
||||
this.setOnMenuItemClickListener(this);
|
||||
}
|
||||
|
||||
private void createMenuItem() {
|
||||
this.getMenu().add(Menu.NONE, ASCENDING, 0, mContext.getString(R.string.sort_ascending));
|
||||
this.getMenu().add(Menu.NONE, DESCENDING, 1, mContext.getString(R.string.sort_descending));
|
||||
this.getMenu().add(Menu.NONE, ROW_HIDE, 2, mContext.getString(R.string.row_hide));
|
||||
this.getMenu().add(Menu.NONE, ROW_SHOW, 3, mContext.getString(R.string.row_show));
|
||||
// add new one ...
|
||||
|
||||
}
|
||||
|
||||
private void changeMenuItemVisibility() {
|
||||
// Determine which one shouldn't be visible
|
||||
SortState sortState = m_iTableView.getSortingStatus(mXPosition);
|
||||
if (sortState == SortState.UNSORTED) {
|
||||
// Show others
|
||||
} else if (sortState == SortState.DESCENDING) {
|
||||
// Hide DESCENDING menu item
|
||||
getMenu().getItem(1).setVisible(false);
|
||||
} else if (sortState == SortState.ASCENDING) {
|
||||
// Hide ASCENDING menu item
|
||||
getMenu().getItem(0).setVisible(false);
|
||||
}
|
||||
|
||||
// Control whether 5. row is visible or not.
|
||||
if (m_iTableView.isRowVisible(TEST_ROW_INDEX)) {
|
||||
// Show row menu item will be invisible
|
||||
getMenu().getItem(3).setVisible(false);
|
||||
} else {
|
||||
// Hide row menu item will be invisible
|
||||
getMenu().getItem(2).setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem menuItem) {
|
||||
// Note: item id is index of menu item..
|
||||
|
||||
switch (menuItem.getItemId()) {
|
||||
case ASCENDING:
|
||||
m_iTableView.sortColumn(mXPosition, SortState.ASCENDING);
|
||||
break;
|
||||
case DESCENDING:
|
||||
m_iTableView.sortColumn(mXPosition, SortState.DESCENDING);
|
||||
break;
|
||||
case ROW_HIDE:
|
||||
// Hide 5. row for testing process
|
||||
// index starts from 0. That's why TEST_ROW_INDEX is 4.
|
||||
m_iTableView.hideRow(TEST_ROW_INDEX);
|
||||
break;
|
||||
case ROW_SHOW:
|
||||
// Show 5. row for testing process
|
||||
// index starts from 0. That's why TEST_ROW_INDEX is 4.
|
||||
m_iTableView.showRow(TEST_ROW_INDEX);
|
||||
break;
|
||||
}
|
||||
|
||||
// Recalculate of the width values of the columns
|
||||
m_iTableView.remeasureColumnWidth(mXPosition);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
package com.josh.trackcovid19v2.ui.viewmodel;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.josh.trackcovid19v2.data.CountriesRepository;
|
||||
import com.josh.trackcovid19v2.data.database.entity.Countries;
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesCountries;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class YourcountriesViewModel extends ViewModel {
|
||||
|
||||
private final CountriesRepository mRepository;
|
||||
private final LiveData<List<Countries>> mCountriesData;
|
||||
private final LiveData<List<YesCountries>> mYesCountriesData;
|
||||
|
||||
public YourcountriesViewModel(CountriesRepository mRepository) {
|
||||
this.mRepository = mRepository;
|
||||
this.mCountriesData = mRepository.getCountriesList();
|
||||
this.mYesCountriesData = mRepository.getYesCountriesList();
|
||||
|
||||
}
|
||||
|
||||
public LiveData<List<Countries>> getCountriesList() {
|
||||
return mCountriesData;
|
||||
}
|
||||
|
||||
public LiveData<List<YesCountries>> getYesCountriesList() {
|
||||
return mYesCountriesData;
|
||||
}
|
||||
|
||||
public void postRequest(ServiceRequest serviceRequest) {
|
||||
mRepository.postServiceRequest(serviceRequest);
|
||||
mRepository.postServiceRequest1(serviceRequest);
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
package com.josh.trackcovid19v2.ui.viewmodel;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.josh.trackcovid19v2.data.CountriesRepository;
|
||||
import com.josh.trackcovid19v2.data.database.entity.Countries;
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesCountries;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class YourrealcountryViewModel extends ViewModel {
|
||||
|
||||
private final CountriesRepository mRepository;
|
||||
private final LiveData<List<Countries>> mCountriesData;
|
||||
private final LiveData<List<YesCountries>> mYesCountriesData;
|
||||
|
||||
public YourrealcountryViewModel(CountriesRepository mRepository) {
|
||||
this.mRepository = mRepository;
|
||||
this.mCountriesData = mRepository.getCountriesList();
|
||||
this.mYesCountriesData = mRepository.getYesCountriesList();
|
||||
|
||||
}
|
||||
|
||||
public LiveData<List<Countries>> getCountriesList() {
|
||||
return mCountriesData;
|
||||
}
|
||||
|
||||
public LiveData<List<YesCountries>> getYesCountriesList() {
|
||||
return mYesCountriesData;
|
||||
}
|
||||
|
||||
public void postRequest(ServiceRequest serviceRequest) {
|
||||
mRepository.postServiceRequest(serviceRequest);
|
||||
mRepository.postServiceRequest1(serviceRequest);
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package com.josh.trackcovid19v2.ui.viewmodel;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.josh.trackcovid19v2.data.CountriesRepository;
|
||||
import com.josh.trackcovid19v2.data.StateRepository;
|
||||
import com.josh.trackcovid19v2.data.database.entity.Countries;
|
||||
import com.josh.trackcovid19v2.data.database.entity.States;
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesCountries;
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesStates;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class YourstateViewModel extends ViewModel {
|
||||
|
||||
private final StateRepository mRepository;
|
||||
private final LiveData<List<States>> mStatesData;
|
||||
private final LiveData<List<YesStates>> mYesStatesData;
|
||||
|
||||
public YourstateViewModel(StateRepository mRepository) {
|
||||
this.mRepository = mRepository;
|
||||
this.mStatesData = mRepository.getStatesList();
|
||||
this.mYesStatesData = mRepository.getYesStatesList();
|
||||
|
||||
}
|
||||
|
||||
public LiveData<List<States>> getStatesList() {
|
||||
return mStatesData;
|
||||
}
|
||||
|
||||
public LiveData<List<YesStates>> getYesStatesList() {
|
||||
return mYesStatesData;
|
||||
}
|
||||
|
||||
public void postRequest(ServiceRequest serviceRequest) {
|
||||
mRepository.postServiceRequest(serviceRequest);
|
||||
mRepository.postServiceRequest1(serviceRequest);
|
||||
}
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
package com.josh.trackcovid19v2.ui.viewmodel;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.josh.trackcovid19v2.data.WorldRepository;
|
||||
import com.josh.trackcovid19v2.data.database.entity.World;
|
||||
import com.josh.trackcovid19v2.data.database.entity.YesWorld;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
|
||||
public class YourworldViewModel extends ViewModel {
|
||||
|
||||
private final WorldRepository mRepository;
|
||||
private final LiveData<World> mWorldData;
|
||||
private final LiveData<YesWorld> mYesWorldData;
|
||||
|
||||
public YourworldViewModel(WorldRepository mRepository) {
|
||||
this.mRepository = mRepository;
|
||||
this.mWorldData = mRepository.getWorld();
|
||||
this.mYesWorldData = mRepository.getYesWorld();
|
||||
}
|
||||
|
||||
public LiveData<World> getWorld() {
|
||||
return mWorldData;
|
||||
}
|
||||
|
||||
public void postRequest(ServiceRequest serviceRequest) {
|
||||
mRepository.postServiceRequest(serviceRequest);
|
||||
mRepository.postServiceRequest1(serviceRequest);
|
||||
}
|
||||
|
||||
public LiveData<YesWorld> getYesWorld() {
|
||||
return mYesWorldData;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package com.josh.trackcovid19v2.ui.viewmodel;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.josh.trackcovid19v2.data.CountriesRepository;
|
||||
|
||||
/**
|
||||
* Factory method that allows us to create a ViewModel with a constructor that takes a
|
||||
* {@link CountriesRepository}
|
||||
*/
|
||||
public class yourCountriesViewModelFactory extends ViewModelProvider.NewInstanceFactory {
|
||||
private final CountriesRepository countriesRepository;
|
||||
|
||||
public yourCountriesViewModelFactory(CountriesRepository countriesRepository) {
|
||||
this.countriesRepository = countriesRepository;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||
//noinspection unchecked
|
||||
return (T) new YourcountriesViewModel(countriesRepository);
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package com.josh.trackcovid19v2.ui.viewmodel;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.josh.trackcovid19v2.data.StateRepository;
|
||||
|
||||
/**
|
||||
* Factory method that allows us to create a ViewModel with a constructor that takes a
|
||||
* {@link StateRepository}
|
||||
*/
|
||||
public class yourStateViewModelFactory extends ViewModelProvider.NewInstanceFactory {
|
||||
private final StateRepository stateRepository;
|
||||
|
||||
public yourStateViewModelFactory(StateRepository stateRepository) {
|
||||
this.stateRepository = stateRepository;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||
//noinspection unchecked
|
||||
return (T) new YourstateViewModel(stateRepository);
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
package com.josh.trackcovid19v2.ui.viewmodel;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.josh.trackcovid19v2.data.WorldRepository;
|
||||
import com.josh.trackcovid19v2.data.StateRepository;
|
||||
|
||||
/**
|
||||
* Factory method that allows us to create a ViewModel with a constructor that takes a
|
||||
* {@link StateRepository}
|
||||
*/
|
||||
public class yourWorldViewModelFactory extends ViewModelProvider.NewInstanceFactory {
|
||||
private final WorldRepository worldRepository;
|
||||
|
||||
public yourWorldViewModelFactory(WorldRepository worldRepository) {
|
||||
this.worldRepository = worldRepository;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||
//noinspection unchecked
|
||||
return (T) new YourworldViewModel(worldRepository);
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package com.josh.trackcovid19v2.ui.viewmodel;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.josh.trackcovid19v2.data.CountriesRepository;
|
||||
|
||||
/**
|
||||
* Factory method that allows us to create a ViewModel with a constructor that takes a
|
||||
* {@link CountriesRepository}
|
||||
*/
|
||||
public class yourrealcountryViewModelFactory extends ViewModelProvider.NewInstanceFactory {
|
||||
private final CountriesRepository countriesRepository;
|
||||
|
||||
public yourrealcountryViewModelFactory(CountriesRepository countriesRepository) {
|
||||
this.countriesRepository = countriesRepository;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||
//noinspection unchecked
|
||||
return (T) new YourrealcountryViewModel(countriesRepository);
|
||||
}
|
||||
}
|
@@ -0,0 +1,132 @@
|
||||
package com.josh.trackcovid19v2.ui.yourcountries;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import com.evrencoskun.tableview.TableView;
|
||||
import com.josh.trackcovid19v2.R;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
import com.josh.trackcovid19v2.ui.tableview.CountriesTableAdapter;
|
||||
import com.josh.trackcovid19v2.ui.tableview.MyTableViewListener;
|
||||
import com.josh.trackcovid19v2.ui.viewmodel.YourcountriesViewModel;
|
||||
import com.josh.trackcovid19v2.ui.viewmodel.yourCountriesViewModelFactory;
|
||||
import com.josh.trackcovid19v2.utility.InjectorUtils;
|
||||
|
||||
public class YourcountriesFragment extends Fragment {
|
||||
|
||||
|
||||
private YourcountriesViewModel yourcountryViewModel;
|
||||
private TableView mTableView;
|
||||
private CountriesTableAdapter mTableAdapter;
|
||||
private ProgressBar mProgressBar;
|
||||
private YourcountriesViewModel vYourcountriesViewModel;
|
||||
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
/*
|
||||
homeViewModel =
|
||||
ViewModelProviders.of(this).get(HomeViewModel.class);
|
||||
View root = inflater.inflate(R.layout.fragment_yourworld, container, false);
|
||||
final TextView textView = root.findViewById(R.id.text_home);
|
||||
homeViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable String s) {
|
||||
textView.setText(s);
|
||||
}
|
||||
});
|
||||
return root;
|
||||
|
||||
*/
|
||||
// Inflate the layout for this fragment
|
||||
View view = inflater.inflate(R.layout.fragment_yourcountry, container, false);
|
||||
|
||||
mProgressBar = view.findViewById(R.id.countries_progressBar);
|
||||
|
||||
mTableView = view.findViewById(R.id.countries_TableView);
|
||||
|
||||
initializeTableView(mTableView);
|
||||
|
||||
|
||||
// initialize ViewModel
|
||||
yourCountriesViewModelFactory factory = InjectorUtils.getCountriesViewModelFactory(getActivity().getApplicationContext());
|
||||
vYourcountriesViewModel = ViewModelProviders.of(this, factory).get(YourcountriesViewModel.class);
|
||||
|
||||
vYourcountriesViewModel.getCountriesList().observe(this, countries -> {
|
||||
|
||||
if(countries != null && countries.size()>0){
|
||||
// set the list on TableViewModel
|
||||
mTableAdapter.setCountriesList(countries);
|
||||
|
||||
hideProgressBar();
|
||||
}
|
||||
});
|
||||
|
||||
// Let's post a request to get the User data from a web server.
|
||||
postRequest();
|
||||
|
||||
return view;
|
||||
|
||||
}
|
||||
|
||||
private void initializeTableView(TableView tableView){
|
||||
|
||||
// Create TableView Adapter
|
||||
mTableAdapter = new CountriesTableAdapter(getContext());
|
||||
tableView.setAdapter(mTableAdapter);
|
||||
|
||||
// Create listener
|
||||
tableView.setTableViewListener(new MyTableViewListener(tableView));
|
||||
}
|
||||
|
||||
|
||||
private void postRequest(){
|
||||
int size = 100; // this is the count of the data items.
|
||||
int page = 1; // Which page do we want to get from the server.
|
||||
ServiceRequest serviceRequest = new ServiceRequest();
|
||||
vYourcountriesViewModel.postRequest(serviceRequest);
|
||||
|
||||
showProgressBar();
|
||||
}
|
||||
|
||||
|
||||
public void showProgressBar() {
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
mTableView.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
public void hideProgressBar() {
|
||||
mProgressBar.setVisibility(View.INVISIBLE);
|
||||
mTableView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Spanned fromHtml(String html){
|
||||
if(html == null){
|
||||
// return an empty spannable if the html is null
|
||||
return new SpannableString("");
|
||||
}else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
// FROM_HTML_MODE_LEGACY is the behaviour that was used for versions below android N
|
||||
// we are using this flag to give a consistent behaviour
|
||||
return Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
|
||||
} else {
|
||||
return Html.fromHtml(html);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -0,0 +1,29 @@
|
||||
package com.josh.trackcovid19v2.ui.yourcountries;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.josh.trackcovid19v2.data.CountriesRepository;
|
||||
import com.josh.trackcovid19v2.data.database.entity.Countries;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class YourcountriesViewModel extends ViewModel {
|
||||
|
||||
private final CountriesRepository mRepository;
|
||||
private final LiveData<List<Countries>> mCountriesData;
|
||||
|
||||
public YourcountriesViewModel(CountriesRepository mRepository) {
|
||||
this.mRepository = mRepository;
|
||||
this.mCountriesData = mRepository.getCountriesList();
|
||||
}
|
||||
|
||||
public LiveData<List<Countries>> getCountriesList() {
|
||||
return mCountriesData;
|
||||
}
|
||||
|
||||
public void postRequest(ServiceRequest serviceRequest) {
|
||||
mRepository.postServiceRequest(serviceRequest);
|
||||
}
|
||||
}
|
@@ -0,0 +1,262 @@
|
||||
package com.josh.trackcovid19v2.ui.yourrealcountry;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import com.josh.trackcovid19v2.R;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
import com.josh.trackcovid19v2.ui.viewmodel.YourcountriesViewModel;
|
||||
import com.josh.trackcovid19v2.ui.viewmodel.YourrealcountryViewModel;
|
||||
import com.josh.trackcovid19v2.ui.viewmodel.yourCountriesViewModelFactory;
|
||||
import com.josh.trackcovid19v2.ui.viewmodel.yourrealcountryViewModelFactory;
|
||||
import com.josh.trackcovid19v2.utility.InjectorUtils;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
public class YourrealcountryFragment extends Fragment {
|
||||
|
||||
private ProgressBar mProgressBar;
|
||||
private YourrealcountryViewModel vYourrealcountryViewModel;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
@Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
|
||||
View view = inflater.inflate(R.layout.fragment_yourrealcountry, container, false);
|
||||
SwipeRefreshLayout mSwipeRefreshLayout = view.findViewById(R.id.swiperefresh);
|
||||
final int[] rememberLocation = {-1};
|
||||
final int[] j = {0};
|
||||
|
||||
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
Log.v("REFRESHING", "************** APP - SWIPE REFRESH EVENT TRIGGERED!!!!!");
|
||||
|
||||
postRequest();
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override public void run() {
|
||||
// Stop animation (This will be after 3 seconds)
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
}, 1000); // Delay in millis
|
||||
}
|
||||
});
|
||||
|
||||
yourrealcountryViewModelFactory factory = InjectorUtils.getRealCountryViewModelFactory(getActivity().getApplicationContext());
|
||||
vYourrealcountryViewModel = ViewModelProviders.of(this, factory).get(YourrealcountryViewModel.class);
|
||||
|
||||
vYourrealcountryViewModel.getCountriesList().observe(this, countries -> {
|
||||
|
||||
if (countries != null && countries.size() > 0) {
|
||||
// set the list on TableViewModel
|
||||
|
||||
String[] country_list = new String[countries.size()];
|
||||
|
||||
for (int i = 0; i < countries.size(); i++) {
|
||||
country_list[i] = countries.get(i).country;
|
||||
if (countries.get(i).country.equalsIgnoreCase("USA")) {
|
||||
j[0] = i;
|
||||
}
|
||||
}
|
||||
final int[] cases = {0};
|
||||
final int[] ycases = {0};
|
||||
final int[] yACases = {0};
|
||||
final int[] ACases = {0};
|
||||
final int[] yRecovered = {0};
|
||||
final int[] recovered = {0};
|
||||
final int[] yDeaths = {0};
|
||||
final int[] Toddeaths = {0};
|
||||
final int[] critical = {0};
|
||||
final int[] yCritical = {0};
|
||||
final int[] yTests = {0};
|
||||
final int[] tests = {0};
|
||||
|
||||
|
||||
vYourrealcountryViewModel.getYesCountriesList().observe(this, yescountries -> {
|
||||
if (yescountries != null && yescountries.size() > 0) {
|
||||
String[] yescountry_list = new String[yescountries.size()];
|
||||
|
||||
//String[] users = { "Suresh Dasari", "Trishika Dasari", "Rohini Alavala", "Praveen Kumar", "Madhav Sai" };
|
||||
Spinner spin = view.findViewById(R.id.spinner1);
|
||||
final TextView textView = view.findViewById(R.id.text_totalCasesData);
|
||||
final TextView textView1 = view.findViewById(R.id.text_activeCasesData);
|
||||
final TextView textView2 = view.findViewById(R.id.text_RecoveredData);
|
||||
final TextView textView3 = view.findViewById(R.id.text_deathsData);
|
||||
final TextView textView4 = view.findViewById(R.id.text_CriticalData);
|
||||
final TextView textView5 = view.findViewById(R.id.text_CriticalDataIncriment);
|
||||
final TextView textView6 = view.findViewById(R.id.text_deathsDataIncriment);
|
||||
final TextView textView7 = view.findViewById(R.id.text_RealRecoveredDataIncriment);
|
||||
final TextView textView8 = view.findViewById(R.id.text_dailyIncriment);
|
||||
final TextView textView9 = view.findViewById(R.id.text_activeCasesIncriment);
|
||||
final TextView textView10 = view.findViewById(R.id.textView2);
|
||||
final TextView textView11 = view.findViewById(R.id.text_totalTestsData);
|
||||
final TextView textView12 = view.findViewById(R.id.text_testsPerOneMillionData);
|
||||
final TextView textView13 = view.findViewById(R.id.text_updated);
|
||||
final ImageView imageView = view.findViewById(R.id.htmlImageGetter);
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.my_spinner_style, country_list);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
spin.setAdapter(adapter);
|
||||
spin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
Picasso.get().load(countries.get(position).flag).into(imageView);
|
||||
Log.d("foo", country_list[position]);
|
||||
cases[0] = countries.get(position).cases;
|
||||
ycases[0] = yescountries.get(position).cases;
|
||||
ACases[0] = countries.get(position).active;
|
||||
yACases[0] = yescountries.get(position).active;
|
||||
recovered[0] = countries.get(position).recovered;
|
||||
yRecovered[0] = yescountries.get(position).recovered;
|
||||
Toddeaths[0] = countries.get(position).deaths;
|
||||
yDeaths[0] = yescountries.get(position).deaths;
|
||||
recovered[0] = countries.get(position).recovered;
|
||||
yRecovered[0] = yescountries.get(position).recovered;
|
||||
tests[0] = countries.get(position).tests;
|
||||
yTests[0] = yescountries.get(position).tests;
|
||||
critical[0] = countries.get(position).critical;
|
||||
yCritical[0] = yescountries.get(position).critical;
|
||||
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
textView10.setText(Html.fromHtml("<b>Pick a country from the dropdown below</b>"));
|
||||
String totalCasesWithCommas = numberFormat.format(countries.get(position).cases);
|
||||
String activeCasesWithCommas = numberFormat.format(countries.get(position).active);
|
||||
String recoveredWithCommas = numberFormat.format(countries.get(position).recovered);
|
||||
String deathWithCommas = numberFormat.format(countries.get(position).deaths);
|
||||
String criticalWithCommas = numberFormat.format(countries.get(position).critical);
|
||||
String ToddeathsWithCommas = numberFormat.format(countries.get(position).todayDeaths);
|
||||
String TodCasesWithCommas = numberFormat.format(countries.get(position).todayCases);
|
||||
String testsWithCommas = numberFormat.format(countries.get(position).tests);
|
||||
String testsMilWithcommas = numberFormat.format(countries.get(position).testsPerMillion);
|
||||
Date date = new Date(countries.get(position).updated);
|
||||
textView13.setText(Html.fromHtml("Updated on "+ date));
|
||||
textView.setText(Html.fromHtml("<center><b>" + totalCasesWithCommas + "</b></center>"));
|
||||
textView3.setText(Html.fromHtml("<b>" + deathWithCommas + "</b>"));
|
||||
textView2.setText(Html.fromHtml("<b>" + recoveredWithCommas + "</b>"));
|
||||
textView1.setText(Html.fromHtml("<b>" + activeCasesWithCommas + "</b>"));
|
||||
textView4.setText(Html.fromHtml("<b>" + criticalWithCommas + "</b>"));
|
||||
textView6.setText(Html.fromHtml("<b>" + ToddeathsWithCommas + "</b>"));
|
||||
textView8.setText(Html.fromHtml("<b>" + TodCasesWithCommas + "</b>"));
|
||||
textView11.setText(Html.fromHtml("<b>" + testsWithCommas + "</b>"));
|
||||
textView12.setText(Html.fromHtml("<b>" + testsMilWithcommas + "</b>"));
|
||||
String dailyActWithCommas = numberFormat.format(ACases[0] - yACases[0]);
|
||||
String dailyRecoveredWithCommas = numberFormat.format(recovered[0] - yRecovered[0]);
|
||||
String dailyTestWithCommas = numberFormat.format(tests[0] - yTests[0]);
|
||||
String todCritWithCommas = numberFormat.format(critical[0] - yCritical[0]);
|
||||
if ((cases[0] - ycases[0]) >= 0) {
|
||||
Spanned text = Html.fromHtml("<i>Daily Increment: " + "<b>" + "+" + TodCasesWithCommas + "</i></b>");
|
||||
SpannableString ss = new SpannableString(text);
|
||||
ForegroundColorSpan fcsWhite = new ForegroundColorSpan(Color.WHITE);
|
||||
@SuppressLint("ResourceAsColor") ForegroundColorSpan fcsGreen = new ForegroundColorSpan(R.color.just_cuz);
|
||||
ss.setSpan(fcsWhite, 0, 16, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
textView8.setText(ss);
|
||||
} else {
|
||||
Spanned text = Html.fromHtml("<i>Daily Increment: " + "<b>" + "-" + TodCasesWithCommas + "</i></b>");
|
||||
SpannableString ss = new SpannableString(text);
|
||||
ForegroundColorSpan fcsWhite = new ForegroundColorSpan(Color.WHITE);
|
||||
@SuppressLint("ResourceAsColor") ForegroundColorSpan fcsGreen = new ForegroundColorSpan(R.color.just_cuz);
|
||||
ss.setSpan(fcsWhite, 0, 16, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
textView8.setText(ss);
|
||||
}
|
||||
if ((ACases[0] - yACases[0]) >= 0) {
|
||||
textView9.setText(Html.fromHtml("<b><i>" + "+" + dailyActWithCommas + "</i></b>"));
|
||||
} else {
|
||||
textView9.setText(Html.fromHtml("<b><i>" + dailyActWithCommas + "</i></b>"));
|
||||
}
|
||||
if ((recovered[0] - yRecovered[0]) >= 0) {
|
||||
textView7.setText(Html.fromHtml("<b><i>" + "+" + dailyRecoveredWithCommas + "</i></b>"));
|
||||
} else {
|
||||
textView7.setText(Html.fromHtml("<b><i>" + dailyRecoveredWithCommas + "</i></b>"));
|
||||
}
|
||||
if ((Toddeaths[0] - yDeaths[0]) >= 0) {
|
||||
textView6.setText(Html.fromHtml("<b><i>" + "+" + ToddeathsWithCommas + "</i></b>"));
|
||||
} else {
|
||||
textView6.setText(Html.fromHtml("<b><i>" + ToddeathsWithCommas + "</i></b>"));
|
||||
}
|
||||
if ((critical[0] - yCritical[0]) >= 0) {
|
||||
textView5.setText(Html.fromHtml("<b><i>" + "+" + todCritWithCommas + "</i></b>"));
|
||||
} else {
|
||||
textView5.setText(Html.fromHtml("<b><i>" + todCritWithCommas + "</i></b>"));
|
||||
}
|
||||
/*
|
||||
if((Toddeaths[0] - yDeaths[0]) >= 0){
|
||||
textView6.setText(Html.fromHtml("<b><i>" + "+" + ToddeathsWithCommas + "</i></b>"));
|
||||
}
|
||||
else {
|
||||
textView6.setText(Html.fromHtml("<b><i>" + "-" + ToddeathsWithCommas + "</i></b>"));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
else{
|
||||
Log.d("lol", "didn't work something broken inside one." + ", name: "+"not found at all");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
else{
|
||||
Log.d("lol", "didn't work something broken outside one." + ", name: "+"not found at all");
|
||||
}
|
||||
});
|
||||
postRequest();
|
||||
return view;
|
||||
//return inflater.inflate(R.layout.fragment_yourrealcountry,container,false);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Spanned fromHtml(String html) {
|
||||
if (html == null) {
|
||||
// return an empty spannable if the html is null
|
||||
return new SpannableString("");
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
// FROM_HTML_MODE_LEGACY is the behaviour that was used for versions below android N
|
||||
// we are using this flag to give a consistent behaviour
|
||||
return Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
|
||||
} else {
|
||||
return Html.fromHtml(html);
|
||||
}
|
||||
}
|
||||
|
||||
private void postRequest() {
|
||||
int size = 100; // this is the count of the data items.
|
||||
int page = 1; // Which page do we want to get from the server.
|
||||
ServiceRequest serviceRequest = new ServiceRequest();
|
||||
vYourrealcountryViewModel.postRequest(serviceRequest);
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.josh.trackcovid19v2.ui.yourrealcountry;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.josh.trackcovid19v2.data.CountriesRepository;
|
||||
import com.josh.trackcovid19v2.data.database.entity.Countries;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class YourrealcountryViewModel extends ViewModel {
|
||||
|
||||
private final CountriesRepository mRepository;
|
||||
private final LiveData<List<Countries>> mCountriesData;
|
||||
|
||||
public YourrealcountryViewModel(CountriesRepository mRepository) {
|
||||
this.mRepository = mRepository;
|
||||
this.mCountriesData = mRepository.getCountriesList();
|
||||
}
|
||||
|
||||
public LiveData<List<Countries>> getCountriesList() {
|
||||
return mCountriesData;
|
||||
}
|
||||
|
||||
public void postRequest(ServiceRequest serviceRequest) {
|
||||
mRepository.postServiceRequest(serviceRequest);
|
||||
}
|
||||
}
|
@@ -0,0 +1,228 @@
|
||||
package com.josh.trackcovid19v2.ui.yourstate;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import com.josh.trackcovid19v2.R;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
import com.josh.trackcovid19v2.ui.viewmodel.YourstateViewModel;
|
||||
import com.josh.trackcovid19v2.ui.viewmodel.yourStateViewModelFactory;
|
||||
import com.josh.trackcovid19v2.utility.InjectorUtils;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
public class YourstateFragment extends Fragment {
|
||||
|
||||
private ProgressBar mProgressBar;
|
||||
private YourstateViewModel vYourstateViewModel;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Spanned fromHtml(String html) {
|
||||
if (html == null) {
|
||||
// return an empty spannable if the html is null
|
||||
return new SpannableString("");
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
// FROM_HTML_MODE_LEGACY is the behaviour that was used for versions below android N
|
||||
// we are using this flag to give a consistent behaviour
|
||||
return Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
|
||||
} else {
|
||||
return Html.fromHtml(html);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
@Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
|
||||
View view = inflater.inflate(R.layout.fragment_yourstate, container, false);
|
||||
SwipeRefreshLayout mSwipeRefreshLayout = view.findViewById(R.id.swiperefresh);
|
||||
final int[] rememberLocation = {-1};
|
||||
final int[] j = {0};
|
||||
|
||||
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
Log.v("REFRESHING", "************** APP - SWIPE REFRESH EVENT TRIGGERED!!!!!");
|
||||
|
||||
postRequest();
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Stop animation (This will be after 3 seconds)
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
}, 1000); // Delay in millis
|
||||
}
|
||||
});
|
||||
|
||||
yourStateViewModelFactory factory = InjectorUtils.getStateViewModelFactory(getActivity().getApplicationContext());
|
||||
vYourstateViewModel = ViewModelProviders.of(this, factory).get(YourstateViewModel.class);
|
||||
|
||||
vYourstateViewModel.getStatesList().observe(this, states -> {
|
||||
|
||||
if (states != null && states.size() > 0) {
|
||||
// set the list on TableViewModel
|
||||
|
||||
String[] state_list = new String[states.size()];
|
||||
|
||||
for (int i = 0; i < states.size(); i++) {
|
||||
state_list[i] = states.get(i).state;
|
||||
if (states.get(i).state.equalsIgnoreCase("New York")) {
|
||||
j[0] = i;
|
||||
}
|
||||
}
|
||||
final int[] cases = {0};
|
||||
final int[] ycases = {0};
|
||||
final int[] yACases = {0};
|
||||
final int[] ACases = {0};
|
||||
final int[] yDeaths = {0};
|
||||
final int[] Toddeaths = {0};
|
||||
final int[] yTests = {0};
|
||||
final int[] tests = {0};
|
||||
|
||||
|
||||
vYourstateViewModel.getYesStatesList().observe(this, yesstates -> {
|
||||
if (yesstates != null && yesstates.size() > 0) {
|
||||
String[] yesstate_list = new String[yesstates.size()];
|
||||
|
||||
//String[] users = { "Suresh Dasari", "Trishika Dasari", "Rohini Alavala", "Praveen Kumar", "Madhav Sai" };
|
||||
Spinner spin = view.findViewById(R.id.spinner1);
|
||||
final TextView textView = view.findViewById(R.id.text_totalCasesData);
|
||||
final TextView textView1 = view.findViewById(R.id.text_activeCasesData);
|
||||
final TextView textView2 = view.findViewById(R.id.text_RecoveredData);
|
||||
final TextView textView3 = view.findViewById(R.id.text_deathsData);
|
||||
final TextView textView4 = view.findViewById(R.id.text_CriticalData);
|
||||
final TextView textView5 = view.findViewById(R.id.text_CriticalDataIncriment);
|
||||
final TextView textView6 = view.findViewById(R.id.text_deathsDataIncriment);
|
||||
final TextView textView7 = view.findViewById(R.id.text_RealRecoveredDataIncriment);
|
||||
final TextView textView8 = view.findViewById(R.id.text_dailyIncriment);
|
||||
final TextView textView9 = view.findViewById(R.id.text_activeCasesIncriment);
|
||||
final TextView textView10 = view.findViewById(R.id.textView2);
|
||||
final TextView textView11 = view.findViewById(R.id.text_totalTestsData);
|
||||
final TextView textView12 = view.findViewById(R.id.text_testsPerOneMillionData);
|
||||
final TextView textView13 = view.findViewById(R.id.text_updated);
|
||||
final ImageView imageView = view.findViewById(R.id.htmlImageGetter);
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.my_spinner_style, state_list);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
spin.setAdapter(adapter);
|
||||
spin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
Log.d("foo", state_list[position]);
|
||||
cases[0] = states.get(position).cases;
|
||||
ycases[0] = yesstates.get(position).cases;
|
||||
ACases[0] = states.get(position).active;
|
||||
yACases[0] = yesstates.get(position).active;
|
||||
Toddeaths[0] = states.get(position).deaths;
|
||||
yDeaths[0] = yesstates.get(position).deaths;
|
||||
tests[0] = states.get(position).tests;
|
||||
yTests[0] = yesstates.get(position).tests;
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
//setData(vYourworldViewModel,world);
|
||||
textView10.setText(Html.fromHtml("<b>Pick a state from the dropdown below</b>"));
|
||||
String totalCasesWithCommas = numberFormat.format(states.get(position).cases);
|
||||
String activeCasesWithCommas = numberFormat.format(states.get(position).active);
|
||||
String deathWithCommas = numberFormat.format(states.get(position).deaths);
|
||||
String ToddeathsWithCommas = numberFormat.format(states.get(position).todayDeaths);
|
||||
String TodCasesWithCommas = numberFormat.format(states.get(position).todayCases);
|
||||
String testsWithCommas = numberFormat.format(states.get(position).tests);
|
||||
String testsMilWithcommas = numberFormat.format(states.get(position).testsPerMillion);
|
||||
textView.setText(Html.fromHtml("<center><b>" + totalCasesWithCommas + "</b></center>"));
|
||||
textView3.setText(Html.fromHtml("<b>" + deathWithCommas + "</b>"));
|
||||
textView1.setText(Html.fromHtml("<b>" + activeCasesWithCommas + "</b>"));
|
||||
textView6.setText(Html.fromHtml("<b>" + ToddeathsWithCommas + "</b>"));
|
||||
textView8.setText(Html.fromHtml("<b>" + TodCasesWithCommas + "</b>"));
|
||||
textView11.setText(Html.fromHtml("<b>" + testsWithCommas + "</b>"));
|
||||
textView12.setText(Html.fromHtml("<b>" + testsMilWithcommas + "</b>"));
|
||||
String dailyActWithCommas = numberFormat.format(ACases[0] - yACases[0]);
|
||||
String dailyTestWithCommas = numberFormat.format(tests[0] - yTests[0]);
|
||||
if ((cases[0] - ycases[0]) >= 0) {
|
||||
Spanned text = Html.fromHtml("<i>Daily Increment: " + "<b>" + "+" + TodCasesWithCommas + "</i></b>");
|
||||
SpannableString ss = new SpannableString(text);
|
||||
ForegroundColorSpan fcsWhite = new ForegroundColorSpan(Color.WHITE);
|
||||
@SuppressLint("ResourceAsColor") ForegroundColorSpan fcsGreen = new ForegroundColorSpan(R.color.just_cuz);
|
||||
ss.setSpan(fcsWhite, 0, 16, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
textView8.setText(ss);
|
||||
} else {
|
||||
Spanned text = Html.fromHtml("<i>Daily Increment: " + "<b>" + "-" + TodCasesWithCommas + "</i></b>");
|
||||
SpannableString ss = new SpannableString(text);
|
||||
ForegroundColorSpan fcsWhite = new ForegroundColorSpan(Color.WHITE);
|
||||
@SuppressLint("ResourceAsColor") ForegroundColorSpan fcsGreen = new ForegroundColorSpan(R.color.just_cuz);
|
||||
ss.setSpan(fcsWhite, 0, 16, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
textView8.setText(ss);
|
||||
}
|
||||
if ((ACases[0] - yACases[0]) >= 0) {
|
||||
textView9.setText(Html.fromHtml("<b><i>" + "+" + dailyActWithCommas + "</i></b>"));
|
||||
} else {
|
||||
textView9.setText(Html.fromHtml("<b><i>" + dailyActWithCommas + "</i></b>"));
|
||||
}
|
||||
if ((Toddeaths[0] - yDeaths[0]) >= 0) {
|
||||
textView6.setText(Html.fromHtml("<b><i>" + "+" + ToddeathsWithCommas + "</i></b>"));
|
||||
} else {
|
||||
textView6.setText(Html.fromHtml("<b><i>" + ToddeathsWithCommas + "</i></b>"));
|
||||
}
|
||||
/*
|
||||
if((Toddeaths[0] - yDeaths[0]) >= 0){
|
||||
textView6.setText(Html.fromHtml("<b><i>" + "+" + ToddeathsWithCommas + "</i></b>"));
|
||||
}
|
||||
else {
|
||||
textView6.setText(Html.fromHtml("<b><i>" + "-" + ToddeathsWithCommas + "</i></b>"));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
}
|
||||
});
|
||||
}
|
||||
else{
|
||||
Log.d("lol", "didn't work something broken inside one." + ", name: "+"not found at all");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
else{
|
||||
Log.d("lol", "didn't work something broken outside one." + ", name: "+"not found at all");
|
||||
}
|
||||
});
|
||||
postRequest();
|
||||
return view;
|
||||
}
|
||||
|
||||
private void postRequest() {
|
||||
int size = 100; // this is the count of the data items.
|
||||
int page = 1; // Which page do we want to get from the server.
|
||||
ServiceRequest serviceRequest = new ServiceRequest();
|
||||
vYourstateViewModel.postRequest(serviceRequest);
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.josh.trackcovid19v2.ui.yourstate;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.josh.trackcovid19v2.data.StateRepository;
|
||||
import com.josh.trackcovid19v2.data.database.entity.States;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class YourstateViewModel extends ViewModel {
|
||||
|
||||
private final StateRepository mRepository;
|
||||
private final LiveData<List<States>> mStatesData;
|
||||
|
||||
public YourstateViewModel(StateRepository mRepository) {
|
||||
this.mRepository = mRepository;
|
||||
this.mStatesData = mRepository.getStatesList();
|
||||
}
|
||||
|
||||
public LiveData<List<States>> getStatesList() {
|
||||
return mStatesData;
|
||||
}
|
||||
|
||||
public void postRequest(ServiceRequest serviceRequest) {
|
||||
mRepository.postServiceRequest(serviceRequest);
|
||||
}
|
||||
}
|
245
app/src/main/java/com/josh/trackcovid19v2/ui/yourworld/YourworldFragment.java
Executable file
@@ -0,0 +1,245 @@
|
||||
package com.josh.trackcovid19v2.ui.yourworld;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ClipDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import com.josh.trackcovid19v2.R;
|
||||
import com.josh.trackcovid19v2.model.ServiceRequest;
|
||||
import com.josh.trackcovid19v2.ui.viewmodel.yourWorldViewModelFactory;
|
||||
import com.josh.trackcovid19v2.utility.InjectorUtils;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
public class YourworldFragment extends Fragment {
|
||||
|
||||
private static YourworldFragment BdTimeUtils;
|
||||
private YourworldViewModel yourworldViewModel;
|
||||
private com.josh.trackcovid19v2.ui.viewmodel.YourworldViewModel vYourworldViewModel;
|
||||
private static DecimalFormat df = new DecimalFormat("0.00");
|
||||
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
View view = inflater.inflate(R.layout.fragment_yourworld, container, false);
|
||||
SwipeRefreshLayout mSwipeRefreshLayout = view.findViewById(R.id.swiperefresh);
|
||||
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
Log.v("REFRESHING", "************** APP - SWIPE REFRESH EVENT TRIGGERED!!!!!");
|
||||
postRequest();
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override public void run() {
|
||||
// Stop animation (This will be after 3 seconds)
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
}, 1000); // Delay in millis
|
||||
}
|
||||
});
|
||||
yourWorldViewModelFactory factory = InjectorUtils.getWorldViewModelFactory(getActivity().getApplicationContext());
|
||||
vYourworldViewModel = ViewModelProviders.of(this, factory).get(com.josh.trackcovid19v2.ui.viewmodel.YourworldViewModel.class);
|
||||
|
||||
final int[] cases = {0};
|
||||
final int[] ycases = {0};
|
||||
final int[] yACases = {0};
|
||||
final int[] ACases = {0};
|
||||
final int[] yRecovered = {0};
|
||||
final int[] recovered = {0};
|
||||
final int[] yDeaths = {0};
|
||||
final int[] Toddeaths = {0};
|
||||
vYourworldViewModel.getWorld().observe(this, world -> {
|
||||
|
||||
if (world != null) {
|
||||
|
||||
Log.d("foooo", String.valueOf(world.cases));
|
||||
|
||||
|
||||
cases[0] = world.cases;
|
||||
ACases[0] = world.active;
|
||||
recovered[0] = world.recovered;
|
||||
Toddeaths[0] = world.deaths;
|
||||
|
||||
Log.d("foooo", "I am here");
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
//setData(vYourworldViewModel,world);
|
||||
TextView textView = view.findViewById(R.id.text_totalCasesData);
|
||||
TextView textViewa = view.findViewById(R.id.text_totalCasesName);
|
||||
TextView textView2 = view.findViewById(R.id.text_deathsData);
|
||||
TextView textView3 = view.findViewById(R.id.text_recoveredData);
|
||||
//unneeded for now
|
||||
TextView textView4 = view.findViewById(R.id.text_updated);
|
||||
TextView textView5 = view.findViewById(R.id.text_activeCasesData);
|
||||
TextView textView6 = view.findViewById(R.id.text_affectedCountriesData);
|
||||
TextView textView7 = view.findViewById(R.id.textView2);
|
||||
TextView textView123 = view.findViewById(R.id.textView4);
|
||||
|
||||
//commas to large numbers
|
||||
String totalCasesWithCommas = numberFormat.format(world.cases);
|
||||
String activeCasesWithCommas = numberFormat.format(world.active);
|
||||
String recoveredWithCommas = numberFormat.format(world.recovered);
|
||||
String deathWithCommas = numberFormat.format(world.deaths);
|
||||
//yesworld data goes above
|
||||
String affectedCountriesData = Integer.toString(world.affectedCountries);
|
||||
Date date = new Date(world.updated);
|
||||
textView.setText(Html.fromHtml("<center><b>" + totalCasesWithCommas + "</b></center>"));
|
||||
textViewa.setText(Html.fromHtml("Total Confirmed Cases"));
|
||||
textView7.setText(Html.fromHtml("<b>COVID-19 Statistics</b>"));
|
||||
textView2.setText(Html.fromHtml("<b>" + deathWithCommas + "</b>"));
|
||||
textView3.setText(Html.fromHtml("<b>" + recoveredWithCommas + "</b>"));
|
||||
textView5.setText(Html.fromHtml("<b>" + activeCasesWithCommas + "</b>"));
|
||||
textView6.setText(Html.fromHtml("<b><sup>" + affectedCountriesData + "</sup>" + "/<sub>251</sub></b>"));
|
||||
textView4.setText(Html.fromHtml("Updated on "+ date));
|
||||
ImageView img1 = view.findViewById(R.id.image_level);
|
||||
double recov = world.recovered;
|
||||
double tcases = world.cases;
|
||||
double percent = (recov/tcases)*100;
|
||||
String percentlegible = df.format(percent);
|
||||
textView123.setText(Html.fromHtml("<b><i>" + percentlegible + "%</i></b>"));
|
||||
Log.d("dfdF", String.valueOf(world.recovered));
|
||||
Log.d("dfdF", String.valueOf(world.cases));
|
||||
Log.d("dfdF", String.valueOf(percent));
|
||||
int x= (int)percent;
|
||||
ClipDrawable drawable = (ClipDrawable) img1.getDrawable();
|
||||
drawable.setLevel(100 * x);
|
||||
}
|
||||
vYourworldViewModel.getYesWorld().observe(this, yesworld -> {
|
||||
|
||||
if (yesworld != null) {
|
||||
|
||||
Log.d("foooo", String.valueOf(yesworld.cases));
|
||||
ycases[0] = yesworld.cases;
|
||||
yACases[0] = yesworld.active;
|
||||
yRecovered[0] = yesworld.recovered;
|
||||
yDeaths[0] = yesworld.deaths;
|
||||
|
||||
Log.d("foooo", "I am in yesworld here");
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
TextView textView8 = view.findViewById(R.id.text_dailyIncriment);
|
||||
TextView textView9 = view.findViewById(R.id.text_activeCasesIncriment);
|
||||
TextView textView10 = view.findViewById(R.id.text_recoveredDataIncriment);
|
||||
TextView textView11 = view.findViewById(R.id.text_deathsDataIncriment);
|
||||
String dailyIncWithCommas = numberFormat.format(cases[0] - ycases[0]);
|
||||
String dailyActWithCommas = numberFormat.format(ACases[0] - yACases[0]);
|
||||
String dailyDeathWithCommas = numberFormat.format(Toddeaths[0] - yDeaths[0]);
|
||||
String dailyRecoveredWithCommas = numberFormat.format(recovered[0] - yRecovered[0]);
|
||||
Log.d("foo", "I got here");
|
||||
|
||||
if ((cases[0] - ycases[0]) >= 0){
|
||||
Spanned text = Html.fromHtml("<i>Daily Increment: " + "<b>" + "+" + dailyIncWithCommas + "</i></b>");
|
||||
SpannableString ss = new SpannableString(text);
|
||||
ForegroundColorSpan fcsWhite = new ForegroundColorSpan(Color.WHITE);
|
||||
@SuppressLint("ResourceAsColor") ForegroundColorSpan fcsGreen = new ForegroundColorSpan(R.color.just_cuz);
|
||||
ss.setSpan(fcsWhite, 0, 16, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
textView8.setText(ss);
|
||||
}
|
||||
else {
|
||||
Spanned text = Html.fromHtml("<i>Daily Increment: " + "<b>" + "-" + dailyIncWithCommas + "</i></b>"); SpannableString ss = new SpannableString(text);
|
||||
ForegroundColorSpan fcsWhite = new ForegroundColorSpan(Color.WHITE);
|
||||
@SuppressLint("ResourceAsColor") ForegroundColorSpan fcsGreen = new ForegroundColorSpan(R.color.just_cuz);
|
||||
ss.setSpan(fcsWhite, 0, 16, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
textView8.setText(ss);
|
||||
}
|
||||
if((ACases[0] - yACases[0]) >= 0){
|
||||
textView9.setText(Html.fromHtml("<b><i>" + "+" + dailyActWithCommas + "</i></b>"));
|
||||
}
|
||||
else {
|
||||
textView9.setText(Html.fromHtml("<b><i>" + "-" + dailyActWithCommas + "</i></b>"));
|
||||
}
|
||||
if((recovered[0] - yRecovered[0]) >= 0){
|
||||
textView10.setText(Html.fromHtml("<b><i>" + "+" + dailyRecoveredWithCommas + "</i></b>"));
|
||||
}
|
||||
else {
|
||||
textView10.setText(Html.fromHtml("<b><i>" + "-" + dailyRecoveredWithCommas + "</i></b>"));
|
||||
}
|
||||
if((Toddeaths[0] - yDeaths[0]) >= 0){
|
||||
textView11.setText(Html.fromHtml("<b><i>" + "+" + dailyDeathWithCommas + "</i></b>"));
|
||||
}
|
||||
else {
|
||||
textView11.setText(Html.fromHtml("<b><i>" + "-" + dailyDeathWithCommas + "</i></b>"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//setData(vYourworldViewModel,world);
|
||||
|
||||
//final TextView textView5 = view.findViewById(R.id.text_activeCases);
|
||||
|
||||
//String totalCases = Integer.toString(yesworld.cases);
|
||||
|
||||
//textView5.setText(Html.fromHtml("<p><u>Yerterday cases</u></p>"+totalCases));
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
postRequest();
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
private void postRequest() {
|
||||
int size = 100; // this is the count of the data items.
|
||||
int page = 1; // Which page do we want to get from the server.
|
||||
ServiceRequest serviceRequest = new ServiceRequest();
|
||||
vYourworldViewModel.postRequest(serviceRequest);
|
||||
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Spanned fromHtml(String html){
|
||||
if(html == null){
|
||||
// return an empty spannable if the html is null
|
||||
return new SpannableString("");
|
||||
}else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
// FROM_HTML_MODE_LEGACY is the behaviour that was used for versions below android N
|
||||
// we are using this flag to give a consistent behaviour
|
||||
return Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
|
||||
} else {
|
||||
return Html.fromHtml(html);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -0,0 +1,24 @@
|
||||
package com.josh.trackcovid19v2.ui.yourworld;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class YourworldViewModel extends ViewModel {
|
||||
|
||||
private MutableLiveData<String> mText;
|
||||
|
||||
public YourworldViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("World Fragment");
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
return mText;
|
||||
}
|
||||
|
||||
public void setText(String str) {
|
||||
mText.setValue(str);
|
||||
}
|
||||
|
||||
}
|
81
app/src/main/java/com/josh/trackcovid19v2/utility/InjectorUtils.java
Executable file
@@ -0,0 +1,81 @@
|
||||
package com.josh.trackcovid19v2.utility;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.josh.trackcovid19v2.AppExecutors;
|
||||
import com.josh.trackcovid19v2.data.CountriesRepository;
|
||||
import com.josh.trackcovid19v2.data.StateRepository;
|
||||
import com.josh.trackcovid19v2.data.WorldRepository;
|
||||
import com.josh.trackcovid19v2.data.database.CountriesDao;
|
||||
import com.josh.trackcovid19v2.data.database.CountriesDatabase;
|
||||
import com.josh.trackcovid19v2.data.database.StateDao;
|
||||
import com.josh.trackcovid19v2.data.database.StatesDatabase;
|
||||
import com.josh.trackcovid19v2.data.database.WorldDao;
|
||||
import com.josh.trackcovid19v2.data.database.WorldDatabase;
|
||||
import com.josh.trackcovid19v2.data.database.YesCountriesDao;
|
||||
import com.josh.trackcovid19v2.data.database.YesCountriesDatabase;
|
||||
import com.josh.trackcovid19v2.data.database.YesStateDao;
|
||||
import com.josh.trackcovid19v2.data.database.YesStatesDatabase;
|
||||
import com.josh.trackcovid19v2.data.database.YesWorldDao;
|
||||
import com.josh.trackcovid19v2.data.database.YesWorldDatabase;
|
||||
import com.josh.trackcovid19v2.data.network.UserNetworkDataSource;
|
||||
import com.josh.trackcovid19v2.ui.viewmodel.yourCountriesViewModelFactory;
|
||||
import com.josh.trackcovid19v2.ui.viewmodel.yourStateViewModelFactory;
|
||||
import com.josh.trackcovid19v2.ui.viewmodel.yourWorldViewModelFactory;
|
||||
import com.josh.trackcovid19v2.ui.viewmodel.yourrealcountryViewModelFactory;
|
||||
|
||||
public class InjectorUtils {
|
||||
|
||||
public static StateRepository getStateRepository(Context context) {
|
||||
// Get all we need
|
||||
StateDao stateDao = StatesDatabase.getInstance(context).stateDao();
|
||||
YesStateDao yesStateDao = YesStatesDatabase.getInstance(context).yesstateDao();
|
||||
AppExecutors executors = AppExecutors.getInstance();
|
||||
UserNetworkDataSource networkDataSource = UserNetworkDataSource.getInstance(executors);
|
||||
|
||||
return StateRepository.getInstance(stateDao, yesStateDao, networkDataSource, executors);
|
||||
|
||||
}
|
||||
|
||||
public static CountriesRepository getCountriesRepository(Context context) {
|
||||
// Get all we need
|
||||
CountriesDao countriesDao = CountriesDatabase.getInstance(context).countriesDao();
|
||||
YesCountriesDao yescountriesDao = YesCountriesDatabase.getInstance(context).yescountriesDao();
|
||||
AppExecutors executors = AppExecutors.getInstance();
|
||||
UserNetworkDataSource networkDataSource = UserNetworkDataSource.getInstance(executors);
|
||||
|
||||
return CountriesRepository.getInstance(countriesDao,
|
||||
yescountriesDao,
|
||||
networkDataSource, executors);
|
||||
|
||||
}
|
||||
|
||||
public static WorldRepository getWorldRepository(Context context) {
|
||||
// Get all we need
|
||||
WorldDao worldDao = WorldDatabase.getInstance(context).worldDao();
|
||||
YesWorldDao yesworldDao = YesWorldDatabase.getInstance(context).yesworldDao();
|
||||
AppExecutors executors = AppExecutors.getInstance();
|
||||
UserNetworkDataSource networkDataSource = UserNetworkDataSource.getInstance(executors);
|
||||
|
||||
return WorldRepository.getInstance(worldDao, yesworldDao, networkDataSource, executors);
|
||||
|
||||
}
|
||||
|
||||
public static yourWorldViewModelFactory getWorldViewModelFactory(Context context){
|
||||
WorldRepository repository = getWorldRepository(context);
|
||||
return new yourWorldViewModelFactory(repository);
|
||||
}
|
||||
public static yourStateViewModelFactory getStateViewModelFactory(Context context){
|
||||
StateRepository repository = getStateRepository(context);
|
||||
return new yourStateViewModelFactory(repository);
|
||||
}
|
||||
public static yourCountriesViewModelFactory getCountriesViewModelFactory(Context context){
|
||||
CountriesRepository repository = getCountriesRepository(context);
|
||||
return new yourCountriesViewModelFactory(repository);
|
||||
}
|
||||
public static yourrealcountryViewModelFactory getRealCountryViewModelFactory(Context context){
|
||||
CountriesRepository repository = getCountriesRepository(context);
|
||||
return new yourrealcountryViewModelFactory(repository);
|
||||
}
|
||||
|
||||
}
|
BIN
app/src/main/res/.DS_Store
vendored
Normal file
14
app/src/main/res/drawable-anydpi/affcountries.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#FFFFFF"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M10.18,9"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M21,16v-2l-8,-5V3.5c0,-0.83 -0.67,-1.5 -1.5,-1.5S10,2.67 10,3.5V9l-8,5v2l8,-2.5V19l-2,1.5V22l3.5,-1 3.5,1v-1.5L13,19v-5.5l8,2.5z"/>
|
||||
</vector>
|
11
app/src/main/res/drawable-anydpi/crits.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#4CAF50"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M17,5L3,5c-1.1,0 -2,0.89 -2,2v9h2c0,1.65 1.34,3 3,3s3,-1.35 3,-3h5.5c0,1.65 1.34,3 3,3s3,-1.35 3,-3L23,16v-5l-6,-6zM3,11L3,7h4v4L3,11zM6,17.5c-0.83,0 -1.5,-0.67 -1.5,-1.5s0.67,-1.5 1.5,-1.5 1.5,0.67 1.5,1.5 -0.67,1.5 -1.5,1.5zM13,11L9,11L9,7h4v4zM17.5,17.5c-0.83,0 -1.5,-0.67 -1.5,-1.5s0.67,-1.5 1.5,-1.5 1.5,0.67 1.5,1.5 -0.67,1.5 -1.5,1.5zM15,11L15,7h1l4,4h-5z"/>
|
||||
</vector>
|
11
app/src/main/res/drawable-anydpi/ic_action_name.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#FFFFFF"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M19.1,12.9a2.8,2.8 0,0 0,0.1 -0.9,2.8 2.8,0 0,0 -0.1,-0.9l2.1,-1.6a0.7,0.7 0,0 0,0.1 -0.6L19.4,5.5a0.7,0.7 0,0 0,-0.6 -0.2l-2.4,1a6.5,6.5 0,0 0,-1.6 -0.9l-0.4,-2.6a0.5,0.5 0,0 0,-0.5 -0.4H10.1a0.5,0.5 0,0 0,-0.5 0.4L9.3,5.4a5.6,5.6 0,0 0,-1.7 0.9l-2.4,-1a0.4,0.4 0,0 0,-0.5 0.2l-2,3.4c-0.1,0.2 0,0.4 0.2,0.6l2,1.6a2.8,2.8 0,0 0,-0.1 0.9,2.8 2.8,0 0,0 0.1,0.9L2.8,14.5a0.7,0.7 0,0 0,-0.1 0.6l1.9,3.4a0.7,0.7 0,0 0,0.6 0.2l2.4,-1a6.5,6.5 0,0 0,1.6 0.9l0.4,2.6a0.5,0.5 0,0 0,0.5 0.4h3.8a0.5,0.5 0,0 0,0.5 -0.4l0.3,-2.6a5.6,5.6 0,0 0,1.7 -0.9l2.4,1a0.4,0.4 0,0 0,0.5 -0.2l2,-3.4c0.1,-0.2 0,-0.4 -0.2,-0.6ZM12,15.6A3.6,3.6 0,1 1,15.6 12,3.6 3.6,0 0,1 12,15.6Z"/>
|
||||
</vector>
|
11
app/src/main/res/drawable-anydpi/ic_action_name2.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#FFFFFF"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M20,2L4,2c-1.1,0 -1.99,0.9 -1.99,2L2,22l4,-4h14c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM13,14h-2v-2h2v2zM13,10h-2L11,6h2v4z"/>
|
||||
</vector>
|
11
app/src/main/res/drawable-anydpi/ic_hospital.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#FFEB3B"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M19,3L5,3c-1.1,0 -1.99,0.9 -1.99,2L3,19c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM18,14h-4v4h-4v-4L6,14v-4h4L10,6h4v4h4v4z"/>
|
||||
</vector>
|
11
app/src/main/res/drawable-anydpi/recovered.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#1B96F8"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M13.5,5.5c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM9.8,8.9L7,23h2.1l1.8,-8 2.1,2v6h2v-7.5l-2.1,-2 0.6,-3C14.8,12 16.8,13 19,13v-2c-1.9,0 -3.5,-1 -4.3,-2.4l-1,-1.6c-0.4,-0.6 -1,-1 -1.7,-1 -0.3,0 -0.5,0.1 -0.8,0.1L6,8.3V13h2V9.6l1.8,-0.7"/>
|
||||
</vector>
|
11
app/src/main/res/drawable-anydpi/recoveredwhite.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#FFFFFF"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M13.5,5.5c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM9.8,8.9L7,23h2.1l1.8,-8 2.1,2v6h2v-7.5l-2.1,-2 0.6,-3C14.8,12 16.8,13 19,13v-2c-1.9,0 -3.5,-1 -4.3,-2.4l-1,-1.6c-0.4,-0.6 -1,-1 -1.7,-1 -0.3,0 -0.5,0.1 -0.8,0.1L6,8.3V13h2V9.6l1.8,-0.7"/>
|
||||
</vector>
|
BIN
app/src/main/res/drawable-hdpi/affcountries.png
Normal file
After Width: | Height: | Size: 457 B |
BIN
app/src/main/res/drawable-hdpi/crits.png
Normal file
After Width: | Height: | Size: 415 B |
BIN
app/src/main/res/drawable-hdpi/ic_action_name.png
Normal file
After Width: | Height: | Size: 457 B |
BIN
app/src/main/res/drawable-hdpi/ic_action_name2.png
Normal file
After Width: | Height: | Size: 192 B |
BIN
app/src/main/res/drawable-hdpi/ic_hospital.png
Normal file
After Width: | Height: | Size: 224 B |
BIN
app/src/main/res/drawable-hdpi/recovered.png
Normal file
After Width: | Height: | Size: 620 B |
BIN
app/src/main/res/drawable-hdpi/recoveredwhite.png
Normal file
After Width: | Height: | Size: 444 B |
BIN
app/src/main/res/drawable-hdpi/syr.png
Normal file
After Width: | Height: | Size: 728 B |
BIN
app/src/main/res/drawable-hdpi/syryell.png
Normal file
After Width: | Height: | Size: 686 B |