youtu.be/RzNRMPicfC4
VIDEO
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jwlee.covid_tracker">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_covid_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_covid_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".DetailActivity"></activity>
<activity android:name=".AffectedCountries" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.jwlee.covid_tracker"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.github.blackfizz:eazegraph:1.2.5l@aar'
implementation 'com.nineoldandroids:library:2.4.0'
implementation 'com.android.volley:volley:1.1.1'
implementation 'com.leo.simplearcloader:simplearcloader:1.0.+'
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
implementation 'com.google.android.gms:play-services-ads:15.0.1'
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#024265</color>
<color name="colorPrimaryDark">#024265</color>
<color name="colorAccent">#05af9b</color>
<color name="color_one">#fb7268</color>
<color name="color_white">#ededf2</color>
<color name="color_two">#e3e0e0</color>
<color name="cases">#ffa726</color>
<color name="recovered">#66bb6a</color>
<color name="deaths">#ef5350</color>
<color name="active">#29b6f6</color>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_white"
tools:context=".AffectedCountries">
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:id="@+id/edtSearch"
android:layout_margin="10dp"
android:maxLines="1"
android:singleLine="true"
android:paddingLeft="20dp"
android:hint="Search"
android:drawablePadding="15dp"
android:background="@drawable/edittext_shadow"
android:drawableLeft="@drawable/ic_baseline_search_24"
/>
<ListView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="@+id/listView"
android:layout_below="@+id/edtSearch"
android:layout_margin="10dp"/>
<com.leo.simplearcloader.SimpleArcLoader
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/loader"
app:arc_style="simple_arc"
android:visibility="visible"
android:layout_centerInParent="true"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".DetailActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="Country"
android:textSize="18sp" />
<TextView
android:id="@+id/tvCountry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/color_one"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@color/color_two" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="Cases"
android:textSize="18sp" />
<TextView
android:id="@+id/tvCases"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/color_one"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@color/color_two" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="Today Cases"
android:textSize="18sp" />
<TextView
android:id="@+id/tvTodayCases2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/color_one"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@color/color_two" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="Deaths"
android:textSize="18sp" />
<TextView
android:id="@+id/tvDeaths2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/color_one"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@color/color_two" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="Today Deaths"
android:textSize="18sp" />
<TextView
android:id="@+id/tvTodayDeaths"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/color_one"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@color/color_two" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="Recovered"
android:textSize="18sp" />
<TextView
android:id="@+id/tvRecovered"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/color_one"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@color/color_two" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="Active"
android:textSize="18sp" />
<TextView
android:id="@+id/tvActive"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/color_one"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@color/color_two" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="Critical"
android:textSize="18sp" />
<TextView
android:id="@+id/tvCritical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/color_one"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@color/color_two" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="casesPerOneMillion"
android:textSize="18sp" />
<TextView
android:id="@+id/tv_casesPerOneMillion"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/color_one"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@color/color_two" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="deathsPerOneMillion"
android:textSize="18sp" />
<TextView
android:id="@+id/tv_deathsPerOneMillion"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/color_one"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@color/color_two" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="tests"
android:textSize="18sp" />
<TextView
android:id="@+id/tv_tests"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/color_one"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@color/color_two" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="testsPerOneMillion"
android:textSize="18sp" />
<TextView
android:id="@+id/tv_testsPerOneMillion"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/color_one"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@color/color_two" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="population"
android:textSize="18sp" />
<TextView
android:id="@+id/tv_population"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/color_one"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@color/color_two" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="continent"
android:textSize="18sp" />
<TextView
android:id="@+id/tv_continent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:textAlignment="textEnd"
android:textColor="@color/color_one"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_white"
tools:context=".MainActivity">
<androidx.cardview.widget.CardView
android:id="@+id/cardViewGraph"
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
app:cardCornerRadius="5dp"
app:cardElevation="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="2">
<org.eazegraph.lib.charts.PieChart
android:id="@+id/piechart"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:layout_weight="1"
android:padding="6dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="15dp"
android:gravity="center_vertical">
<View
android:layout_width="15dp"
android:layout_height="match_parent"
android:background="@color/cases" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:text="Total Cases" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="15dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical">
<View
android:layout_width="15dp"
android:layout_height="match_parent"
android:background="@color/recovered" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:text="Recovered" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="15dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical">
<View
android:layout_width="15dp"
android:layout_height="match_parent"
android:background="@color/deaths" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:text="Deaths" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="15dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical">
<View
android:layout_width="15dp"
android:layout_height="match_parent"
android:background="@color/active" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:text="Active" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/btnTrack"
android:layout_below="@+id/cardViewGraph"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
app:cardCornerRadius="5dp"
app:cardElevation="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.leo.simplearcloader.SimpleArcLoader
android:id="@+id/loader"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:visibility="visible"
app:arc_style="simple_arc"
>
</com.leo.simplearcloader.SimpleArcLoader>
<ScrollView
android:id="@+id/scrollStats"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="20dp"
android:text="global stats"
android:textAllCaps="true"
android:textSize="28sp"
android:textStyle="bold" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:layout_marginRight="20dp"
android:background="@color/color_two" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="Cases"
android:textSize="18sp" />
<TextView
android:id="@+id/tvCases"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/color_one"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@color/color_two" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="Recovered"
android:textSize="18sp" />
<TextView
android:id="@+id/tvRecovered"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/color_one"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@color/color_two" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="Critical"
android:textSize="18sp" />
<TextView
android:id="@+id/tvCritical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/color_one"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@color/color_two" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="Active"
android:textSize="18sp" />
<TextView
android:id="@+id/tvActive"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/color_one"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@color/color_two" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="Today Casese"
android:textSize="18sp" />
<TextView
android:id="@+id/tvTodayCasese"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/color_one"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@color/color_two" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="Total Deaths"
android:textSize="18sp" />
<TextView
android:id="@+id/tvTotalDeaths"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/color_one"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@color/color_two" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="Today Deaths"
android:textSize="18sp" />
<TextView
android:id="@+id/tvTodayDeaths"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/color_one"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@color/color_two" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="Affected Countries"
android:textSize="18sp" />
<TextView
android:id="@+id/tvAffectedCountries"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/color_one"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<Button
android:id="@+id/btnTrack"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="20dp"
android:background="@color/color_one"
android:onClick="goTrackCountries"
android:padding="5dp"
android:text="Track countries"
android:textColor="@android:color/white"
android:textSize="18sp" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="5dp">
<ImageView
android:layout_width="80dp"
android:layout_height="55dp"
android:id="@+id/imageFlag"
android:padding="5dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tvCountryName"
android:layout_gravity="center_vertical"
android:text="Country Name"
android:textSize="20sp"
android:textStyle="bold"
android:paddingLeft="15dp"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:right="1dp"
android:left="1dp"
android:bottom="2dp"
>
<shape
android:shape="rectangle">
<solid android:color="#ffffff"/>
<stroke android:color="#66000000" android:width="0.5dp"/>
</shape>
</item>
</layer-list>
package com.jwlee.covid_tracker;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.MobileAds;
import com.leo.simplearcloader.SimpleArcLoader;
import org.eazegraph.lib.models.PieModel;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class AffectedCountries extends AppCompatActivity {
EditText editSearch;
ListView listView;
SimpleArcLoader simpleArcLoader;
public static List<CountryModel> countryModelsList = new ArrayList<>();
CountryModel countryModel;
MyCustomAdapter myCustomAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_affected_countries);
editSearch = findViewById(R.id.edtSearch);
listView = findViewById(R.id.listView);
simpleArcLoader = findViewById(R.id.loader);
getSupportActionBar().setTitle("Affected Countries");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
fetchData();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
startActivity(new Intent(getApplicationContext(),DetailActivity.class).putExtra("position",position));
}
});
editSearch.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
myCustomAdapter.getFilter().filter(s);
myCustomAdapter.notifyDataSetChanged();
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if(item.getItemId()==android.R.id.home)
finish();
return super.onOptionsItemSelected(item);
}
private void fetchData() {
String url = "https://corona.lmao.ninja/v2/countries";
simpleArcLoader.start();
StringRequest request = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try{
JSONArray jsonArray = new JSONArray(response);
for(int i=0; i<jsonArray.length();i++){
JSONObject jsonObject = jsonArray.getJSONObject(i);
String countryName = jsonObject.getString("country");
String cases = jsonObject.getString("cases");
String todayCases = jsonObject.getString("todayCases");
String deaths = jsonObject.getString("deaths");
String todayDeaths = jsonObject.getString("todayDeaths");
String recovered = jsonObject.getString("recovered");
String active = jsonObject.getString("active");
String critical = jsonObject.getString("critical");
String casesPerOneMillion = jsonObject.getString("casesPerOneMillion");
String deathsPerOneMillion = jsonObject.getString("deathsPerOneMillion");
String tests = jsonObject.getString("tests");
String testsPerOneMillion = jsonObject.getString("testsPerOneMillion");
String population = jsonObject.getString("population");
String continent = jsonObject.getString("continent");
String oneCasePerPeople = jsonObject.getString("oneCasePerPeople");
String oneDeathPerPeople = jsonObject.getString("oneDeathPerPeople");
String oneTestPerPeople = jsonObject.getString("oneTestPerPeople");
String activePerOneMillion = jsonObject.getString("activePerOneMillion");
String recoveredPerOneMillion = jsonObject.getString("recoveredPerOneMillion");
String criticalPerOneMillion = jsonObject.getString("criticalPerOneMillion");
JSONObject object = jsonObject.getJSONObject("countryInfo");
String flagUrl = object.getString("flag");
countryModel = new CountryModel(flagUrl, countryName, cases, todayCases, deaths, todayDeaths, recovered, active, critical,
casesPerOneMillion,deathsPerOneMillion,tests,testsPerOneMillion,population,continent,oneCasePerPeople,oneDeathPerPeople,
oneTestPerPeople,activePerOneMillion,recoveredPerOneMillion,criticalPerOneMillion);
countryModelsList.add(countryModel);
}
myCustomAdapter = new MyCustomAdapter(AffectedCountries.this, countryModelsList);
listView.setAdapter(myCustomAdapter);
simpleArcLoader.stop();
simpleArcLoader.setVisibility(View.GONE);
}catch (JSONException e){
e.printStackTrace();
simpleArcLoader.stop();
simpleArcLoader.setVisibility(View.GONE);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
simpleArcLoader.stop();
simpleArcLoader.setVisibility(View.GONE);
Toast.makeText(AffectedCountries.this, error.getMessage(),Toast.LENGTH_SHORT).show();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(request);
}
}
package com.jwlee.covid_tracker;
public class CountryModel {
private String flag, country, cases, todayCases, deaths, todayDeaths, recovered, active, critical,
casesPerOneMillion,deathsPerOneMillion,tests,testsPerOneMillion,population,continent,oneCasePerPeople,
oneDeathPerPeople,oneTestPerPeople,activePerOneMillion,recoveredPerOneMillion,criticalPerOneMillion;
public CountryModel(String flag, String country, String cases, String todayCases, String deaths, String todayDeaths, String recovered, String active, String critical, String casesPerOneMillion, String deathsPerOneMillion, String tests, String testsPerOneMillion, String population, String continent, String oneCasePerPeople, String oneDeathPerPeople, String oneTestPerPeople, String activePerOneMillion, String recoveredPerOneMillion, String criticalPerOneMillion) {
this.flag = flag;
this.country = country;
this.cases = cases;
this.todayCases = todayCases;
this.deaths = deaths;
this.todayDeaths = todayDeaths;
this.recovered = recovered;
this.active = active;
this.critical = critical;
this.casesPerOneMillion = casesPerOneMillion;
this.deathsPerOneMillion = deathsPerOneMillion;
this.tests = tests;
this.testsPerOneMillion = testsPerOneMillion;
this.population = population;
this.continent = continent;
this.oneCasePerPeople = oneCasePerPeople;
this.oneDeathPerPeople = oneDeathPerPeople;
this.oneTestPerPeople = oneTestPerPeople;
this.activePerOneMillion = activePerOneMillion;
this.recoveredPerOneMillion = recoveredPerOneMillion;
this.criticalPerOneMillion = criticalPerOneMillion;
}
public CountryModel() {
}
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
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 String getPopulation() {
return population;
}
public void setPopulation(String population) {
this.population = population;
}
public String getContinent() {
return continent;
}
public void setContinent(String continent) {
this.continent = continent;
}
public String getOneCasePerPeople() {
return oneCasePerPeople;
}
public void setOneCasePerPeople(String oneCasePerPeople) {
this.oneCasePerPeople = oneCasePerPeople;
}
public String getOneDeathPerPeople() {
return oneDeathPerPeople;
}
public void setOneDeathPerPeople(String oneDeathPerPeople) {
this.oneDeathPerPeople = oneDeathPerPeople;
}
public String getOneTestPerPeople() {
return oneTestPerPeople;
}
public void setOneTestPerPeople(String oneTestPerPeople) {
this.oneTestPerPeople = oneTestPerPeople;
}
public String getActivePerOneMillion() {
return activePerOneMillion;
}
public void setActivePerOneMillion(String activePerOneMillion) {
this.activePerOneMillion = activePerOneMillion;
}
public String getRecoveredPerOneMillion() {
return recoveredPerOneMillion;
}
public void setRecoveredPerOneMillion(String recoveredPerOneMillion) {
this.recoveredPerOneMillion = recoveredPerOneMillion;
}
public String getCriticalPerOneMillion() {
return criticalPerOneMillion;
}
public void setCriticalPerOneMillion(String criticalPerOneMillion) {
this.criticalPerOneMillion = criticalPerOneMillion;
}
}
package com.jwlee.covid_tracker;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.TextView;
import java.text.DecimalFormat;
public class DetailActivity extends AppCompatActivity {
private int positionCountry;
TextView tvCountry, tvCases,tvRecovered,tvCritical, tvActive,tvTodayCases,tvTotalDeaths,tvTodayDeaths;
TextView tv_casesPerOneMillion, tv_deathsPerOneMillion,tv_tests, tv_testsPerOneMillion,tv_population,tv_continent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
Intent intent = getIntent();
positionCountry = intent.getIntExtra("position",0);
getSupportActionBar().setTitle("Details of "+AffectedCountries.countryModelsList.get(positionCountry).getCountry());
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
tvCountry =findViewById(R.id.tvCountry);
tvCases = findViewById(R.id.tvCases);
tvRecovered = findViewById(R.id.tvRecovered);
tvCritical = findViewById(R.id.tvCritical);
tvActive = findViewById(R.id.tvActive);
tvTodayCases = findViewById(R.id.tvTodayCases2);
tvTotalDeaths = findViewById(R.id.tvDeaths2);
tvTodayDeaths = findViewById(R.id.tvTodayDeaths);
tv_casesPerOneMillion = findViewById(R.id.tv_casesPerOneMillion);
tv_deathsPerOneMillion = findViewById(R.id.tv_deathsPerOneMillion);
tv_tests=findViewById(R.id.tv_tests);
tv_testsPerOneMillion=findViewById(R.id.tv_testsPerOneMillion);
tv_population=findViewById(R.id.tv_population);
tv_continent = findViewById(R.id.tv_continent);
tvCountry.setText(AffectedCountries.countryModelsList.get(positionCountry).getCountry());
tvCases.setText(AffectedCountries.countryModelsList.get(positionCountry).getCases());
tvRecovered.setText(AffectedCountries.countryModelsList.get(positionCountry).getRecovered());
tvCritical.setText(AffectedCountries.countryModelsList.get(positionCountry).getCritical());
tvActive.setText(AffectedCountries.countryModelsList.get(positionCountry).getActive());
tvTodayCases.setText(AffectedCountries.countryModelsList.get(positionCountry).getTodayCases());
tvTotalDeaths.setText(AffectedCountries.countryModelsList.get(positionCountry).getDeaths());
tvTodayDeaths.setText(AffectedCountries.countryModelsList.get(positionCountry).getTodayDeaths());
tv_casesPerOneMillion.setText(AffectedCountries.countryModelsList.get(positionCountry).getCasesPerOneMillion());
tv_deathsPerOneMillion.setText(AffectedCountries.countryModelsList.get(positionCountry).getDeathsPerOneMillion());
tv_tests.setText(AffectedCountries.countryModelsList.get(positionCountry).getTests());
tv_testsPerOneMillion.setText(AffectedCountries.countryModelsList.get(positionCountry).getTestsPerOneMillion());
tv_population.setText(AffectedCountries.countryModelsList.get(positionCountry).getPopulation());
tv_continent.setText(AffectedCountries.countryModelsList.get(positionCountry).getContinent());
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if(item.getItemId()==android.R.id.home)
finish();
return super.onOptionsItemSelected(item);
}
}
package com.jwlee.covid_tracker;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.leo.simplearcloader.SimpleArcLoader;
import org.eazegraph.lib.charts.PieChart;
import org.eazegraph.lib.models.PieModel;
import org.json.JSONException;
import org.json.JSONObject;
public class MainActivity extends AppCompatActivity {
TextView tvCases, tvRecovered, tvCritical, tvActive, tvTodayCases, tvTotalDeaths, tvTodayDeaths, tvAffectedCountries;
SimpleArcLoader simpleArcLoader;
ScrollView scrollView;
PieChart pieChart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvCases = findViewById(R.id.tvCases);
tvRecovered = findViewById(R.id.tvRecovered);
tvCritical = findViewById(R.id.tvCritical);
tvActive = findViewById(R.id.tvActive);
tvTodayCases = findViewById(R.id.tvTodayCasese);
tvTotalDeaths = findViewById(R.id.tvTotalDeaths);
tvTodayDeaths = findViewById(R.id.tvTodayDeaths);
tvAffectedCountries = findViewById(R.id.tvAffectedCountries);
simpleArcLoader = findViewById(R.id.loader);
scrollView = findViewById(R.id.scrollStats);
pieChart = findViewById(R.id.piechart);
fetchData();
}
private void fetchData() {
String url = "https://corona.lmao.ninja/v2/all";
simpleArcLoader.start();
StringRequest request = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try{
JSONObject jsonObject = new JSONObject(response.toString());
tvCases.setText(jsonObject.getString("cases"));
tvRecovered.setText(jsonObject.getString("recovered"));
tvCritical.setText(jsonObject.getString("critical"));
tvActive.setText(jsonObject.getString("active"));
tvTodayCases.setText(jsonObject.getString("todayCases"));
tvTotalDeaths.setText(jsonObject.getString("deaths"));
tvTodayDeaths.setText(jsonObject.getString("todayDeaths"));
tvAffectedCountries.setText(jsonObject.getString("affectedCountries"));
pieChart.addPieSlice(new PieModel("Cases",Integer.parseInt(tvCases.getText().toString()),
Color.parseColor("#ffa726")));
pieChart.addPieSlice(new PieModel("Recovered",Integer.parseInt(tvRecovered.getText().toString()),
Color.parseColor("#66bb6a")));
pieChart.addPieSlice(new PieModel("Deaths",Integer.parseInt(tvTotalDeaths.getText().toString()),
Color.parseColor("#ef5350")));
pieChart.addPieSlice(new PieModel("Active",Integer.parseInt(tvActive.getText().toString()),
Color.parseColor("#29b6f6")));
pieChart.startAnimation();
simpleArcLoader.stop();
simpleArcLoader.setVisibility(View.GONE);
scrollView.setVisibility(View.VISIBLE);
}catch (JSONException e){
e.printStackTrace();
simpleArcLoader.stop();
simpleArcLoader.setVisibility(View.GONE);
scrollView.setVisibility(View.VISIBLE);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
simpleArcLoader.stop();
simpleArcLoader.setVisibility(View.GONE);
scrollView.setVisibility(View.VISIBLE);
Toast.makeText(MainActivity.this, error.getMessage(),Toast.LENGTH_SHORT).show();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(request);
}
public void goTrackCountries(View view) {
startActivity(new Intent(getApplicationContext(),AffectedCountries.class));
}
}
package com.jwlee.covid_tracker;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Filter;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.bumptech.glide.Glide;
import java.util.ArrayList;
import java.util.List;
public class MyCustomAdapter extends ArrayAdapter<CountryModel> {
private Context context;
private List<CountryModel> countryModelList;
private List<CountryModel> countryModelListFiltered;
public MyCustomAdapter( Context context, List<CountryModel>countryModelList) {
super(context, R.layout.list_custom_item,countryModelList);
this.context = context;
this.countryModelList = countryModelList;
this.countryModelListFiltered = countryModelList;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_custom_item,null,true);
TextView tvCountryName = view.findViewById(R.id.tvCountryName);
ImageView imageView = view.findViewById(R.id.imageFlag);
tvCountryName.setText(countryModelListFiltered.get(position).getCountry());
Glide.with(context).load(countryModelListFiltered.get(position).getFlag()).into(imageView);
return view;
}
@Override
public int getCount() {
return countryModelListFiltered.size();
}
@Nullable
@Override
public CountryModel getItem(int position){
return countryModelListFiltered.get(position);
}
@Override
public long getItemId(int position){
return position;
}
@NonNull
@Override
public Filter getFilter(){
Filter filter = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults filterResults = new FilterResults();
if(constraint == null || constraint.length()==0){
filterResults.count = countryModelList.size();
filterResults.values = countryModelList;
}else{
List<CountryModel> resultModel = new ArrayList<>();
String searchStr = constraint.toString().toLowerCase();
for(CountryModel itemModel:countryModelList){
if(itemModel.getCountry().toLowerCase().contains(searchStr)){
resultModel.add(itemModel);
}
filterResults.count = resultModel.size();
filterResults.values = resultModel;
}
}
return filterResults;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
countryModelListFiltered = (List<CountryModel>)results.values;
AffectedCountries.countryModelsList = (List<CountryModel>)results.values;
notifyDataSetChanged();
}
};
return filter;
}
}