diff --git a/TrackCovid19.iml b/TrackCovid19.iml new file mode 100644 index 0000000..c804e04 --- /dev/null +++ b/TrackCovid19.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/.DS_Store b/app/.DS_Store new file mode 100644 index 0000000..a378087 Binary files /dev/null and b/app/.DS_Store differ diff --git a/app/.gitignore b/app/.gitignore new file mode 100755 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/app.iml b/app/app.iml new file mode 100644 index 0000000..c9d2b66 --- /dev/null +++ b/app/app.iml @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100755 index 0000000..e77f57b --- /dev/null +++ b/app/build.gradle @@ -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" +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100755 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -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 diff --git a/app/release/app-release.aab b/app/release/app-release.aab new file mode 100644 index 0000000..4f40b2c Binary files /dev/null and b/app/release/app-release.aab differ diff --git a/app/src/.DS_Store b/app/src/.DS_Store new file mode 100644 index 0000000..73ea1ed Binary files /dev/null and b/app/src/.DS_Store differ diff --git a/app/src/androidTest/java/com/josh/trackcovid19v2/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/josh/trackcovid19v2/ExampleInstrumentedTest.java new file mode 100755 index 0000000..942dcc0 --- /dev/null +++ b/app/src/androidTest/java/com/josh/trackcovid19v2/ExampleInstrumentedTest.java @@ -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 Testing documentation + */ +@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()); + } +} diff --git a/app/src/main/.DS_Store b/app/src/main/.DS_Store new file mode 100644 index 0000000..d434bf3 Binary files /dev/null and b/app/src/main/.DS_Store differ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100755 index 0000000..e4ef645 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/ic_launcher-playstore.png b/app/src/main/ic_launcher-playstore.png new file mode 100644 index 0000000..89b159d Binary files /dev/null and b/app/src/main/ic_launcher-playstore.png differ diff --git a/app/src/main/java/.DS_Store b/app/src/main/java/.DS_Store new file mode 100644 index 0000000..35a54bf Binary files /dev/null and b/app/src/main/java/.DS_Store differ diff --git a/app/src/main/java/com/josh/trackcovid19v2/AppExecutors.java b/app/src/main/java/com/josh/trackcovid19v2/AppExecutors.java new file mode 100755 index 0000000..a4376da --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/AppExecutors.java @@ -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. + *

+ * Grouping tasks like this avoids the effects of task starvation (e.g. disk reads don't wait behind + * webservice requests). + *

+ * 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); + } + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/HomeActivity.java b/app/src/main/java/com/josh/trackcovid19v2/HomeActivity.java new file mode 100644 index 0000000..760d02b --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/HomeActivity.java @@ -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(); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/MainActivity.java b/app/src/main/java/com/josh/trackcovid19v2/MainActivity.java new file mode 100755 index 0000000..78caab1 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/MainActivity.java @@ -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(); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/SettingsActivity.java b/app/src/main/java/com/josh/trackcovid19v2/SettingsActivity.java new file mode 100644 index 0000000..5fa24de --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/SettingsActivity.java @@ -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); + } + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/SettingsFragment.java b/app/src/main/java/com/josh/trackcovid19v2/SettingsFragment.java new file mode 100644 index 0000000..60a60d8 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/SettingsFragment.java @@ -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); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/CountriesRepository.java b/app/src/main/java/com/josh/trackcovid19v2/data/CountriesRepository.java new file mode 100755 index 0000000..4eff263 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/CountriesRepository.java @@ -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> getCountriesList() { + LiveData> foo = mCountriesDao.getCountriesList(); + return foo; + } + + public void postServiceRequest(ServiceRequest serviceRequest) { + mNetworkDataSource.fetchCountriesData(serviceRequest); + } + + public LiveData> getYesCountriesList() { + LiveData> fie = mYesCountriesDao.getYesCountriesList(); + return fie; + } + + public void postServiceRequest1(ServiceRequest serviceRequest) { + mNetworkDataSource.fetchYesCountriesData(serviceRequest); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/StateRepository.java b/app/src/main/java/com/josh/trackcovid19v2/data/StateRepository.java new file mode 100755 index 0000000..7f882de --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/StateRepository.java @@ -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> getStatesList() { + LiveData> foo = mStatesDao.getStatesList(); + return foo; + } + + public void postServiceRequest(ServiceRequest serviceRequest) { + mNetworkDataSource.fetchStatesData(serviceRequest); + } + + public LiveData> getYesStatesList() { + LiveData> fie = mYesStatesDao.getYesStatesList(); + return fie; + } + + public void postServiceRequest1(ServiceRequest serviceRequest) { + mNetworkDataSource.fetchYesStatesData(serviceRequest); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/WorldRepository.java b/app/src/main/java/com/josh/trackcovid19v2/data/WorldRepository.java new file mode 100755 index 0000000..e960bcd --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/WorldRepository.java @@ -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 getWorld() { + LiveData foo = mWorldDao.getWorld(); + return foo; + } + + public LiveData getYesWorld() { + LiveData foo = mYesWorldDao.getYesWorld(); + return foo; + } + + public void postServiceRequest(ServiceRequest serviceRequest) { + mNetworkDataSource.fetchWorldData(serviceRequest); + } + + public void postServiceRequest1(ServiceRequest serviceRequest) { + mNetworkDataSource.fetchYesWorldData(serviceRequest); + } + +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/database/CountriesDao.java b/app/src/main/java/com/josh/trackcovid19v2/data/database/CountriesDao.java new file mode 100755 index 0000000..9a87165 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/database/CountriesDao.java @@ -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); + + @Query("DELETE FROM countries") + abstract void deleteAll(); + + @Query("Select * FROM countries ORDER BY country ASC") + public abstract LiveData> getCountriesList(); + + @Transaction + public void updateAll(List countries) { + deleteAll(); + bulkInsert(countries); + } + +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/database/CountriesDatabase.java b/app/src/main/java/com/josh/trackcovid19v2/data/database/CountriesDatabase.java new file mode 100755 index 0000000..ab638b5 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/database/CountriesDatabase.java @@ -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(); + +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/database/StateDao.java b/app/src/main/java/com/josh/trackcovid19v2/data/database/StateDao.java new file mode 100755 index 0000000..fd76c6b --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/database/StateDao.java @@ -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); + + @Query("DELETE FROM states") + abstract void deleteAll(); + + @Query("Select * FROM states ORDER BY state ASC") + public abstract LiveData> getStatesList(); + + @Transaction + public void updateAll(List states) { + deleteAll(); + bulkInsert(states); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/database/StatesDatabase.java b/app/src/main/java/com/josh/trackcovid19v2/data/database/StatesDatabase.java new file mode 100755 index 0000000..05f31c2 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/database/StatesDatabase.java @@ -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(); + +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/database/WorldDao.java b/app/src/main/java/com/josh/trackcovid19v2/data/database/WorldDao.java new file mode 100755 index 0000000..a066acf --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/database/WorldDao.java @@ -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 getWorld(); + + @Transaction + public void updateAll(World world) { + deleteAll(); + bulkInsert(world); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/database/WorldDatabase.java b/app/src/main/java/com/josh/trackcovid19v2/data/database/WorldDatabase.java new file mode 100755 index 0000000..1bf4246 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/database/WorldDatabase.java @@ -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(); + +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/database/YesCountriesDao.java b/app/src/main/java/com/josh/trackcovid19v2/data/database/YesCountriesDao.java new file mode 100755 index 0000000..b670bb8 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/database/YesCountriesDao.java @@ -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); + + @Query("DELETE FROM yescountries") + abstract void deleteAll(); + + @Query("Select * FROM yescountries ORDER BY country ASC") + public abstract LiveData> getYesCountriesList(); + + @Transaction + public void updateAll(List yescountries) { + deleteAll(); + bulkInsert(yescountries); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/database/YesCountriesDatabase.java b/app/src/main/java/com/josh/trackcovid19v2/data/database/YesCountriesDatabase.java new file mode 100755 index 0000000..6aa4cab --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/database/YesCountriesDatabase.java @@ -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(); + +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/database/YesStateDao.java b/app/src/main/java/com/josh/trackcovid19v2/data/database/YesStateDao.java new file mode 100755 index 0000000..8c84129 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/database/YesStateDao.java @@ -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); + + @Query("DELETE FROM yesstates") + abstract void deleteAll(); + + @Query("Select * FROM yesstates ORDER BY state ASC") + public abstract LiveData> getYesStatesList(); + + @Transaction + public void updateAll(List yesstates) { + deleteAll(); + bulkInsert(yesstates); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/database/YesStatesDatabase.java b/app/src/main/java/com/josh/trackcovid19v2/data/database/YesStatesDatabase.java new file mode 100755 index 0000000..f31d871 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/database/YesStatesDatabase.java @@ -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(); + +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/database/YesWorldDao.java b/app/src/main/java/com/josh/trackcovid19v2/data/database/YesWorldDao.java new file mode 100755 index 0000000..1f4cb5a --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/database/YesWorldDao.java @@ -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 getYesWorld(); + + @Transaction + public void updateAll(YesWorld yesworld) { + deleteAll(); + bulkInsert(yesworld); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/database/YesWorldDatabase.java b/app/src/main/java/com/josh/trackcovid19v2/data/database/YesWorldDatabase.java new file mode 100755 index 0000000..b780fcd --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/database/YesWorldDatabase.java @@ -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(); + +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/database/entity/Countries.java b/app/src/main/java/com/josh/trackcovid19v2/data/database/entity/Countries.java new file mode 100755 index 0000000..47643a4 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/database/entity/Countries.java @@ -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; +} + diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/database/entity/States.java b/app/src/main/java/com/josh/trackcovid19v2/data/database/entity/States.java new file mode 100755 index 0000000..c5b1b8d --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/database/entity/States.java @@ -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; +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/database/entity/World.java b/app/src/main/java/com/josh/trackcovid19v2/data/database/entity/World.java new file mode 100755 index 0000000..f8b9c07 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/database/entity/World.java @@ -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; + +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/database/entity/YesCountries.java b/app/src/main/java/com/josh/trackcovid19v2/data/database/entity/YesCountries.java new file mode 100755 index 0000000..7347780 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/database/entity/YesCountries.java @@ -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; +} + diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/database/entity/YesStates.java b/app/src/main/java/com/josh/trackcovid19v2/data/database/entity/YesStates.java new file mode 100755 index 0000000..db724c1 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/database/entity/YesStates.java @@ -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; +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/database/entity/YesWorld.java b/app/src/main/java/com/josh/trackcovid19v2/data/database/entity/YesWorld.java new file mode 100755 index 0000000..8d48c07 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/database/entity/YesWorld.java @@ -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; + +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/network/NetworkUtils.java b/app/src/main/java/com/josh/trackcovid19v2/data/network/NetworkUtils.java new file mode 100755 index 0000000..d853fde --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/network/NetworkUtils.java @@ -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> getDataFromService() { + Log.d(LOG_TAG, "Getting data from the server"); + List foo = null; + + RestApi service = getRetrofit().create(RestApi.class); + + Call> call = service.getStates(); + + + return call; + } +*/ + public static Call> getStatesDataFromService() { + Log.d(LOG_TAG, "Getting states data from the server"); + + RestApi service = getRetrofit().create(RestApi.class); + + Call> call = service.getStates(0); + + return call; + } + + public static Call> getYesStatesDataFromService() { + Log.d(LOG_TAG, "Getting yes states data from the server"); + + RestApi service = getRetrofit().create(RestApi.class); + + Call> call = service.getYesStates(1); + + return call; + } + + // For getting countries data + public static Call> getCountriesDataFromService() { + Log.d(LOG_TAG, "Getting countries data from the server"); + //List foo = null; + + RestApi service = getRetrofit().create(RestApi.class); + + Call> call = service.getCountries(0); + + + return call; + } + + public static Call> getYesCountriesDataFromService() { + Log.d(LOG_TAG, "Getting yesterdays countries data from the server"); + //List foo = null; + + RestApi service = getRetrofit().create(RestApi.class); + + Call> call = service.getYesCountries(1); + + + return call; + } + + public static List convertToCountriesList(List data) { + List 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 convertToStatesList(List data) { + List 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 convertToYesStatesList(List data) { + List 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 convertToStatesList1(List data) { + List 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 getWorldDataFromService() { + Log.d(LOG_TAG, "Getting data from the server"); + + RestApi service = getRetrofit().create(RestApi.class); + + Call call = service.getWorld(); + + return call; + } + public static Call getYesWorldDataFromService() { + Log.d(LOG_TAG, "Getting yesterdays data from the server"); + + RestApi service = getRetrofit().create(RestApi.class); + + Call call = service.getYesWorld(); + + return call; + } + + public static List convertToYesCountriesList(List data) { + List 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 convertToStatesList(List data) { + List 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; + } + */ +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/network/RestApi.java b/app/src/main/java/com/josh/trackcovid19v2/data/network/RestApi.java new file mode 100755 index 0000000..ce2e665 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/network/RestApi.java @@ -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> getStatess(); + + @GET("v2/states") + Call> getStates(@Query("yesterday") int y); + + @GET("v2/states") + Call> getYesStates(@Query("yesterday") int y); + + @GET("/v2/countries") + Call> getCountries(@Query("yesterday") int y); + + @GET("/v2/countries") + Call> getYesCountries(@Query("yesterday") int y); + + @GET("v2/all") + Call getWorld(); + + @GET("v2/all?yesterday=true") + Call getYesWorld(); + + //countries/USA + //yesterday/USA + + // + + //Observable> getStates(); +} \ No newline at end of file diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/network/StatesWrapper.java b/app/src/main/java/com/josh/trackcovid19v2/data/network/StatesWrapper.java new file mode 100755 index 0000000..b14153a --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/network/StatesWrapper.java @@ -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 = null; + + public List getStates() { + return states; + } + + public void setStates(List states) { + this.states = states; + } + +} + diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/network/UserNetworkDataSource.java b/app/src/main/java/com/josh/trackcovid19v2/data/network/UserNetworkDataSource.java new file mode 100755 index 0000000..f57a41a --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/network/UserNetworkDataSource.java @@ -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> mDownloadedStatesData; + private final MutableLiveData> mDownloadedYesStatesData; + private final MutableLiveData> mDownloadedCountriesData; + private final MutableLiveData> mDownloadedYesCountriesData; + private final MutableLiveData mDownloadedWorldData; + private final MutableLiveData 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> call = NetworkUtils.getDataFromService(); + call.enqueue(new Callback>() { + @Override + public void onResponse(Call> call, Response> response) { + //Toast.makeText(MainActivity.this,response.body().toString(),Toast.LENGTH_SHORT).show(); + Log.e("Info", "got data"); + //ArrayList foo = new ArrayList(); + List data = response.body(); + setStatesList(NetworkUtils.convertToStatesList(data)); + } + + @Override + public void onFailure(Call> 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> call = NetworkUtils.getStatesDataFromService(); + call.enqueue(new Callback>() { + @Override + public void onResponse(Call> call, Response> response) { + //Toast.makeText(MainActivity.this,response.body().toString(),Toast.LENGTH_SHORT).show(); + Log.e("Info", "got states data"); + //ArrayList foo = new ArrayList(); + List data = response.body(); + setStatesList(NetworkUtils.convertToStatesList(data)); + } + + @Override + public void onFailure(Call> 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> call = NetworkUtils.getYesStatesDataFromService(); + call.enqueue(new Callback>() { + @Override + public void onResponse(Call> call, Response> response) { + //Toast.makeText(MainActivity.this,response.body().toString(),Toast.LENGTH_SHORT).show(); + Log.e("Info", "got yes states data"); + //ArrayList foo = new ArrayList(); + List data = response.body(); + setYesStatesList(NetworkUtils.convertToYesStatesList(data)); + } + + @Override + public void onFailure(Call> 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> call = NetworkUtils.getCountriesDataFromService(); + call.enqueue(new Callback>() { + @Override + public void onResponse(Call> call, Response> response) { + //Toast.makeText(MainActivity.this,response.body().toString(),Toast.LENGTH_SHORT).show(); + Log.e("Info", "got countries data"); + //ArrayList foo = new ArrayList(); + List data = response.body(); + setCountriesList(NetworkUtils.convertToCountriesList(data)); + } + + @Override + public void onFailure(Call> 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> call = NetworkUtils.getYesCountriesDataFromService(); + call.enqueue(new Callback>() { + @Override + public void onResponse(Call> call, Response> response) { + //Toast.makeText(MainActivity.this,response.body().toString(),Toast.LENGTH_SHORT).show(); + Log.e("Info", "got yesterdays countries data"); + //ArrayList foo = new ArrayList(); + List data = response.body(); + setYesCountriesList(NetworkUtils.convertToYesCountriesList(data)); + } + + @Override + public void onFailure(Call> 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 call = NetworkUtils.getWorldDataFromService(); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + //Toast.makeText(MainActivity.this,response.body().toString(),Toast.LENGTH_SHORT).show(); + Log.e("Info", "got world data"); + //ArrayList foo = new ArrayList(); + World data = response.body(); + //setWorld(NetworkUtils.convertToStatesList(data)); + setWorld(data); + } + + @Override + public void onFailure(Call 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 call1 = NetworkUtils.getYesWorldDataFromService(); + call1.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + //Toast.makeText(MainActivity.this,response.body().toString(),Toast.LENGTH_SHORT).show(); + Log.e("Info", "got yesterday's world data"); + //ArrayList foo = new ArrayList(); + YesWorld data = response.body(); + //setWorld(NetworkUtils.convertToStatesList(data)); + setYesWorld(data); + } + + @Override + public void onFailure(Call 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 statesList){ + // mDownloadedData.postValue(statesList); + // } + private void setWorld(World world) { + mDownloadedWorldData.postValue(world); + } + + public LiveData getWorld(){ + return mDownloadedWorldData; + } + + private void setYesWorld(YesWorld yesworld) { + mDownloadedYesWorldData.postValue(yesworld); + } + + public LiveData getYesWorld(){ + return mDownloadedYesWorldData; + } + + private void setStatesList(List statesList){ + mDownloadedStatesData.postValue(statesList); + } + public LiveData> getStatesList(){ + return mDownloadedStatesData; + } + + private void setYesStatesList(List yesstatesList){ + mDownloadedYesStatesData.postValue(yesstatesList); + } + public LiveData> getYesStatesList(){ + return mDownloadedYesStatesData; + } + + private void setCountriesList(List countriesList){ + mDownloadedCountriesData.postValue(countriesList); + } + + public LiveData> getCountriesList(){ + return mDownloadedCountriesData; + } + + private void setYesCountriesList(List yescountriesList){ + mDownloadedYesCountriesData.postValue(yescountriesList); + } + public LiveData> getYesCountriesList(){ + return mDownloadedYesCountriesData; + } + + +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/network/pojo/CountriesPojo.java b/app/src/main/java/com/josh/trackcovid19v2/data/network/pojo/CountriesPojo.java new file mode 100755 index 0000000..9ac9e4b --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/network/pojo/CountriesPojo.java @@ -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; + } +} + + + + diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/network/pojo/CountryInfoPojo.java b/app/src/main/java/com/josh/trackcovid19v2/data/network/pojo/CountryInfoPojo.java new file mode 100644 index 0000000..5182c6b --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/network/pojo/CountryInfoPojo.java @@ -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; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/network/pojo/StatesPojo.java b/app/src/main/java/com/josh/trackcovid19v2/data/network/pojo/StatesPojo.java new file mode 100755 index 0000000..2382f76 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/network/pojo/StatesPojo.java @@ -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; + + +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/network/pojo/YesCountriesPojo.java b/app/src/main/java/com/josh/trackcovid19v2/data/network/pojo/YesCountriesPojo.java new file mode 100755 index 0000000..84f4837 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/network/pojo/YesCountriesPojo.java @@ -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; + } +} + + + + diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/network/pojo/YesCountryInfoPojo.java b/app/src/main/java/com/josh/trackcovid19v2/data/network/pojo/YesCountryInfoPojo.java new file mode 100644 index 0000000..82ca374 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/network/pojo/YesCountryInfoPojo.java @@ -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; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/josh/trackcovid19v2/data/network/pojo/YesStatesPojo.java b/app/src/main/java/com/josh/trackcovid19v2/data/network/pojo/YesStatesPojo.java new file mode 100755 index 0000000..df85f3f --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/data/network/pojo/YesStatesPojo.java @@ -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; + } + + +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/model/Countries.java b/app/src/main/java/com/josh/trackcovid19v2/model/Countries.java new file mode 100755 index 0000000..809fe6c --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/model/Countries.java @@ -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; + + +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/model/CountryData.java b/app/src/main/java/com/josh/trackcovid19v2/model/CountryData.java new file mode 100755 index 0000000..9512042 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/model/CountryData.java @@ -0,0 +1,9 @@ +package com.josh.trackcovid19v2.model; + +public class CountryData { + + public int cases; + public int active; + + +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/model/ServiceRequest.java b/app/src/main/java/com/josh/trackcovid19v2/model/ServiceRequest.java new file mode 100755 index 0000000..4fcf126 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/model/ServiceRequest.java @@ -0,0 +1,10 @@ +package com.josh.trackcovid19v2.model; + +public class ServiceRequest { + + public ServiceRequest() { + + } + + +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/model/ServiceResponse.java b/app/src/main/java/com/josh/trackcovid19v2/model/ServiceResponse.java new file mode 100755 index 0000000..ecf0cf4 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/model/ServiceResponse.java @@ -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 data = null; +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/CountriesTableAdapter.java b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/CountriesTableAdapter.java new file mode 100755 index 0000000..1833c5e --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/CountriesTableAdapter.java @@ -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 { + + 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 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()); + } + +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/CountriesTableViewModel.java b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/CountriesTableViewModel.java new file mode 100755 index 0000000..f0699ee --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/CountriesTableViewModel.java @@ -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 mColumnHeaderModelList; + private List mRowHeaderModelList; + private List> 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 createColumnHeaderModelList() { + List 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> createCellModelList(List countriesList) { + List> 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 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 createRowHeaderList(int size) { + List 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 getColumHeaderModeList() { + return mColumnHeaderModelList; + } + + public List getRowHeaderModelList() { + return mRowHeaderModelList; + } + + public List> getCellModelList() { + return mCellModelList; + } + + + public void generateListForTableView(List countries) { + mColumnHeaderModelList = createColumnHeaderModelList(); + mCellModelList = createCellModelList(countries); + mRowHeaderModelList = createRowHeaderList(countries.size()); + } + +} + + + diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/MyTableAdapter.java b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/MyTableAdapter.java new file mode 100755 index 0000000..15f36e8 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/MyTableAdapter.java @@ -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 { + + 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 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()); + } + +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/MyTableViewListener.java b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/MyTableViewListener.java new file mode 100755 index 0000000..66cfd4e --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/MyTableViewListener.java @@ -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); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/MyTableViewModel.java b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/MyTableViewModel.java new file mode 100755 index 0000000..66ed4aa --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/MyTableViewModel.java @@ -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 mColumnHeaderModelList; + private List mRowHeaderModelList; + private List> 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 createColumnHeaderModelList() { + List 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> createCellModelList(List stateList) { + List> 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 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 createRowHeaderList(int size) { + List 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 getColumHeaderModeList() { + return mColumnHeaderModelList; + } + + public List getRowHeaderModelList() { + return mRowHeaderModelList; + } + + public List> getCellModelList() { + return mCellModelList; + } + + + public void generateListForTableView(List states) { + mColumnHeaderModelList = createColumnHeaderModelList(); + mCellModelList = createCellModelList(states); + mRowHeaderModelList = createRowHeaderList(states.size()); + } + +} + + + diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/holder/CellViewHolder.java b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/holder/CellViewHolder.java new file mode 100755 index 0000000..2bba016 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/holder/CellViewHolder.java @@ -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)); + } + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/holder/ColumnHeaderViewHolder.java b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/holder/ColumnHeaderViewHolder.java new file mode 100755 index 0000000..3e430df --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/holder/ColumnHeaderViewHolder.java @@ -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}; + + +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/holder/MoneyCellViewHolder.java b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/holder/MoneyCellViewHolder.java new file mode 100755 index 0000000..9656d56 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/holder/MoneyCellViewHolder.java @@ -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); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/holder/RowHeaderViewHolder.java b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/holder/RowHeaderViewHolder.java new file mode 100755 index 0000000..46aac9c --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/holder/RowHeaderViewHolder.java @@ -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)); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/model/CellModel.java b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/model/CellModel.java new file mode 100755 index 0000000..4db7b8d --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/model/CellModel.java @@ -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; + } + +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/model/ColumnHeaderModel.java b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/model/ColumnHeaderModel.java new file mode 100755 index 0000000..0ce4e9e --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/model/ColumnHeaderModel.java @@ -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; + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/model/RowHeaderModel.java b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/model/RowHeaderModel.java new file mode 100755 index 0000000..1c7ef34 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/model/RowHeaderModel.java @@ -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; + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/popup/ColumnHeaderLongPressPopup.java b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/popup/ColumnHeaderLongPressPopup.java new file mode 100755 index 0000000..0f7c8bd --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/tableview/popup/ColumnHeaderLongPressPopup.java @@ -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; + } + +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/YourcountriesViewModel.java b/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/YourcountriesViewModel.java new file mode 100644 index 0000000..d733f4b --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/YourcountriesViewModel.java @@ -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> mCountriesData; + private final LiveData> mYesCountriesData; + + public YourcountriesViewModel(CountriesRepository mRepository) { + this.mRepository = mRepository; + this.mCountriesData = mRepository.getCountriesList(); + this.mYesCountriesData = mRepository.getYesCountriesList(); + + } + + public LiveData> getCountriesList() { + return mCountriesData; + } + + public LiveData> getYesCountriesList() { + return mYesCountriesData; + } + + public void postRequest(ServiceRequest serviceRequest) { + mRepository.postServiceRequest(serviceRequest); + mRepository.postServiceRequest1(serviceRequest); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/YourrealcountryViewModel.java b/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/YourrealcountryViewModel.java new file mode 100755 index 0000000..57396b4 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/YourrealcountryViewModel.java @@ -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> mCountriesData; + private final LiveData> mYesCountriesData; + + public YourrealcountryViewModel(CountriesRepository mRepository) { + this.mRepository = mRepository; + this.mCountriesData = mRepository.getCountriesList(); + this.mYesCountriesData = mRepository.getYesCountriesList(); + + } + + public LiveData> getCountriesList() { + return mCountriesData; + } + + public LiveData> getYesCountriesList() { + return mYesCountriesData; + } + + public void postRequest(ServiceRequest serviceRequest) { + mRepository.postServiceRequest(serviceRequest); + mRepository.postServiceRequest1(serviceRequest); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/YourstateViewModel.java b/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/YourstateViewModel.java new file mode 100644 index 0000000..c54ae3c --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/YourstateViewModel.java @@ -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> mStatesData; + private final LiveData> mYesStatesData; + + public YourstateViewModel(StateRepository mRepository) { + this.mRepository = mRepository; + this.mStatesData = mRepository.getStatesList(); + this.mYesStatesData = mRepository.getYesStatesList(); + + } + + public LiveData> getStatesList() { + return mStatesData; + } + + public LiveData> getYesStatesList() { + return mYesStatesData; + } + + public void postRequest(ServiceRequest serviceRequest) { + mRepository.postServiceRequest(serviceRequest); + mRepository.postServiceRequest1(serviceRequest); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/YourworldViewModel.java b/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/YourworldViewModel.java new file mode 100755 index 0000000..eb6d5b0 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/YourworldViewModel.java @@ -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 mWorldData; + private final LiveData mYesWorldData; + + public YourworldViewModel(WorldRepository mRepository) { + this.mRepository = mRepository; + this.mWorldData = mRepository.getWorld(); + this.mYesWorldData = mRepository.getYesWorld(); + } + + public LiveData getWorld() { + return mWorldData; + } + + public void postRequest(ServiceRequest serviceRequest) { + mRepository.postServiceRequest(serviceRequest); + mRepository.postServiceRequest1(serviceRequest); + } + + public LiveData getYesWorld() { + return mYesWorldData; + } + +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/yourCountriesViewModelFactory.java b/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/yourCountriesViewModelFactory.java new file mode 100644 index 0000000..ed7f5f8 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/yourCountriesViewModelFactory.java @@ -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 create(@NonNull Class modelClass) { + //noinspection unchecked + return (T) new YourcountriesViewModel(countriesRepository); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/yourStateViewModelFactory.java b/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/yourStateViewModelFactory.java new file mode 100644 index 0000000..1796526 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/yourStateViewModelFactory.java @@ -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 create(@NonNull Class modelClass) { + //noinspection unchecked + return (T) new YourstateViewModel(stateRepository); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/yourWorldViewModelFactory.java b/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/yourWorldViewModelFactory.java new file mode 100755 index 0000000..80ca501 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/yourWorldViewModelFactory.java @@ -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 create(@NonNull Class modelClass) { + //noinspection unchecked + return (T) new YourworldViewModel(worldRepository); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/yourrealcountryViewModelFactory.java b/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/yourrealcountryViewModelFactory.java new file mode 100755 index 0000000..50faeab --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/viewmodel/yourrealcountryViewModelFactory.java @@ -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 create(@NonNull Class modelClass) { + //noinspection unchecked + return (T) new YourrealcountryViewModel(countriesRepository); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/yourcountries/YourcountriesFragment.java b/app/src/main/java/com/josh/trackcovid19v2/ui/yourcountries/YourcountriesFragment.java new file mode 100755 index 0000000..713ea5d --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/yourcountries/YourcountriesFragment.java @@ -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() { + @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); + } + } +} + + + + + + diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/yourcountries/YourcountriesViewModel.java b/app/src/main/java/com/josh/trackcovid19v2/ui/yourcountries/YourcountriesViewModel.java new file mode 100644 index 0000000..a702cbf --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/yourcountries/YourcountriesViewModel.java @@ -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> mCountriesData; + + public YourcountriesViewModel(CountriesRepository mRepository) { + this.mRepository = mRepository; + this.mCountriesData = mRepository.getCountriesList(); + } + + public LiveData> getCountriesList() { + return mCountriesData; + } + + public void postRequest(ServiceRequest serviceRequest) { + mRepository.postServiceRequest(serviceRequest); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/yourrealcountry/YourrealcountryFragment.java b/app/src/main/java/com/josh/trackcovid19v2/ui/yourrealcountry/YourrealcountryFragment.java new file mode 100644 index 0000000..112b5f7 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/yourrealcountry/YourrealcountryFragment.java @@ -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 adapter = new ArrayAdapter(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("Pick a country from the dropdown below")); + 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("

" + totalCasesWithCommas + "
")); + textView3.setText(Html.fromHtml("" + deathWithCommas + "")); + textView2.setText(Html.fromHtml("" + recoveredWithCommas + "")); + textView1.setText(Html.fromHtml("" + activeCasesWithCommas + "")); + textView4.setText(Html.fromHtml("" + criticalWithCommas + "")); + textView6.setText(Html.fromHtml("" + ToddeathsWithCommas + "")); + textView8.setText(Html.fromHtml("" + TodCasesWithCommas + "")); + textView11.setText(Html.fromHtml("" + testsWithCommas + "")); + textView12.setText(Html.fromHtml("" + testsMilWithcommas + "")); + 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("Daily Increment: " + "" + "+" + TodCasesWithCommas + ""); + 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("Daily Increment: " + "" + "-" + TodCasesWithCommas + ""); + 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("" + "+" + dailyActWithCommas + "")); + } else { + textView9.setText(Html.fromHtml("" + dailyActWithCommas + "")); + } + if ((recovered[0] - yRecovered[0]) >= 0) { + textView7.setText(Html.fromHtml("" + "+" + dailyRecoveredWithCommas + "")); + } else { + textView7.setText(Html.fromHtml("" + dailyRecoveredWithCommas + "")); + } + if ((Toddeaths[0] - yDeaths[0]) >= 0) { + textView6.setText(Html.fromHtml("" + "+" + ToddeathsWithCommas + "")); + } else { + textView6.setText(Html.fromHtml("" + ToddeathsWithCommas + "")); + } + if ((critical[0] - yCritical[0]) >= 0) { + textView5.setText(Html.fromHtml("" + "+" + todCritWithCommas + "")); + } else { + textView5.setText(Html.fromHtml("" + todCritWithCommas + "")); + } + /* + if((Toddeaths[0] - yDeaths[0]) >= 0){ + textView6.setText(Html.fromHtml("" + "+" + ToddeathsWithCommas + "")); + } + else { + textView6.setText(Html.fromHtml("" + "-" + ToddeathsWithCommas + "")); + } + */ + } + + @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); + + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/yourrealcountry/YourrealcountryViewModel.java b/app/src/main/java/com/josh/trackcovid19v2/ui/yourrealcountry/YourrealcountryViewModel.java new file mode 100755 index 0000000..c68be95 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/yourrealcountry/YourrealcountryViewModel.java @@ -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> mCountriesData; + + public YourrealcountryViewModel(CountriesRepository mRepository) { + this.mRepository = mRepository; + this.mCountriesData = mRepository.getCountriesList(); + } + + public LiveData> getCountriesList() { + return mCountriesData; + } + + public void postRequest(ServiceRequest serviceRequest) { + mRepository.postServiceRequest(serviceRequest); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/yourstate/YourstateFragment.java b/app/src/main/java/com/josh/trackcovid19v2/ui/yourstate/YourstateFragment.java new file mode 100644 index 0000000..0c3a681 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/yourstate/YourstateFragment.java @@ -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 adapter = new ArrayAdapter(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("Pick a state from the dropdown below")); + 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("
" + totalCasesWithCommas + "
")); + textView3.setText(Html.fromHtml("" + deathWithCommas + "")); + textView1.setText(Html.fromHtml("" + activeCasesWithCommas + "")); + textView6.setText(Html.fromHtml("" + ToddeathsWithCommas + "")); + textView8.setText(Html.fromHtml("" + TodCasesWithCommas + "")); + textView11.setText(Html.fromHtml("" + testsWithCommas + "")); + textView12.setText(Html.fromHtml("" + testsMilWithcommas + "")); + 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("Daily Increment: " + "" + "+" + TodCasesWithCommas + ""); + 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("Daily Increment: " + "" + "-" + TodCasesWithCommas + ""); + 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("" + "+" + dailyActWithCommas + "")); + } else { + textView9.setText(Html.fromHtml("" + dailyActWithCommas + "")); + } + if ((Toddeaths[0] - yDeaths[0]) >= 0) { + textView6.setText(Html.fromHtml("" + "+" + ToddeathsWithCommas + "")); + } else { + textView6.setText(Html.fromHtml("" + ToddeathsWithCommas + "")); + } + /* + if((Toddeaths[0] - yDeaths[0]) >= 0){ + textView6.setText(Html.fromHtml("" + "+" + ToddeathsWithCommas + "")); + } + else { + textView6.setText(Html.fromHtml("" + "-" + ToddeathsWithCommas + "")); + } + */ + } + + @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); + + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/yourstate/YourstateViewModel.java b/app/src/main/java/com/josh/trackcovid19v2/ui/yourstate/YourstateViewModel.java new file mode 100755 index 0000000..79c4a33 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/yourstate/YourstateViewModel.java @@ -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> mStatesData; + + public YourstateViewModel(StateRepository mRepository) { + this.mRepository = mRepository; + this.mStatesData = mRepository.getStatesList(); + } + + public LiveData> getStatesList() { + return mStatesData; + } + + public void postRequest(ServiceRequest serviceRequest) { + mRepository.postServiceRequest(serviceRequest); + } +} diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/yourworld/YourworldFragment.java b/app/src/main/java/com/josh/trackcovid19v2/ui/yourworld/YourworldFragment.java new file mode 100755 index 0000000..28a8a22 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/yourworld/YourworldFragment.java @@ -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("
" + totalCasesWithCommas + "
")); + textViewa.setText(Html.fromHtml("Total Confirmed Cases")); + textView7.setText(Html.fromHtml("COVID-19 Statistics")); + textView2.setText(Html.fromHtml("" + deathWithCommas + "")); + textView3.setText(Html.fromHtml("" + recoveredWithCommas + "")); + textView5.setText(Html.fromHtml("" + activeCasesWithCommas + "")); + textView6.setText(Html.fromHtml("" + affectedCountriesData + "" + "/251")); + 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("" + percentlegible + "%")); + 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("Daily Increment: " + "" + "+" + dailyIncWithCommas + ""); + 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("Daily Increment: " + "" + "-" + dailyIncWithCommas + ""); 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("" + "+" + dailyActWithCommas + "")); + } + else { + textView9.setText(Html.fromHtml("" + "-" + dailyActWithCommas + "")); + } + if((recovered[0] - yRecovered[0]) >= 0){ + textView10.setText(Html.fromHtml("" + "+" + dailyRecoveredWithCommas + "")); + } + else { + textView10.setText(Html.fromHtml("" + "-" + dailyRecoveredWithCommas + "")); + } + if((Toddeaths[0] - yDeaths[0]) >= 0){ + textView11.setText(Html.fromHtml("" + "+" + dailyDeathWithCommas + "")); + } + else { + textView11.setText(Html.fromHtml("" + "-" + dailyDeathWithCommas + "")); + } + + + + + //setData(vYourworldViewModel,world); + + //final TextView textView5 = view.findViewById(R.id.text_activeCases); + + //String totalCases = Integer.toString(yesworld.cases); + + //textView5.setText(Html.fromHtml("

Yerterday cases

"+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); + } + } + +} + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/josh/trackcovid19v2/ui/yourworld/YourworldViewModel.java b/app/src/main/java/com/josh/trackcovid19v2/ui/yourworld/YourworldViewModel.java new file mode 100755 index 0000000..10e6b80 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/ui/yourworld/YourworldViewModel.java @@ -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 mText; + + public YourworldViewModel() { + mText = new MutableLiveData<>(); + mText.setValue("World Fragment"); + } + + public LiveData getText() { + return mText; + } + + public void setText(String str) { + mText.setValue(str); + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/josh/trackcovid19v2/utility/InjectorUtils.java b/app/src/main/java/com/josh/trackcovid19v2/utility/InjectorUtils.java new file mode 100755 index 0000000..3f00357 --- /dev/null +++ b/app/src/main/java/com/josh/trackcovid19v2/utility/InjectorUtils.java @@ -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); + } + +} diff --git a/app/src/main/res/.DS_Store b/app/src/main/res/.DS_Store new file mode 100644 index 0000000..3834b10 Binary files /dev/null and b/app/src/main/res/.DS_Store differ diff --git a/app/src/main/res/drawable-anydpi/affcountries.xml b/app/src/main/res/drawable-anydpi/affcountries.xml new file mode 100644 index 0000000..9abcb5a --- /dev/null +++ b/app/src/main/res/drawable-anydpi/affcountries.xml @@ -0,0 +1,14 @@ + + + + diff --git a/app/src/main/res/drawable-anydpi/crits.xml b/app/src/main/res/drawable-anydpi/crits.xml new file mode 100644 index 0000000..ca6022b --- /dev/null +++ b/app/src/main/res/drawable-anydpi/crits.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable-anydpi/ic_action_name.xml b/app/src/main/res/drawable-anydpi/ic_action_name.xml new file mode 100644 index 0000000..01b2fba --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_action_name.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable-anydpi/ic_action_name2.xml b/app/src/main/res/drawable-anydpi/ic_action_name2.xml new file mode 100644 index 0000000..60705df --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_action_name2.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable-anydpi/ic_hospital.xml b/app/src/main/res/drawable-anydpi/ic_hospital.xml new file mode 100644 index 0000000..29b34d4 --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_hospital.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable-anydpi/recovered.xml b/app/src/main/res/drawable-anydpi/recovered.xml new file mode 100644 index 0000000..6148002 --- /dev/null +++ b/app/src/main/res/drawable-anydpi/recovered.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable-anydpi/recoveredwhite.xml b/app/src/main/res/drawable-anydpi/recoveredwhite.xml new file mode 100644 index 0000000..3a9067d --- /dev/null +++ b/app/src/main/res/drawable-anydpi/recoveredwhite.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable-hdpi/affcountries.png b/app/src/main/res/drawable-hdpi/affcountries.png new file mode 100644 index 0000000..f20a403 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/affcountries.png differ diff --git a/app/src/main/res/drawable-hdpi/crits.png b/app/src/main/res/drawable-hdpi/crits.png new file mode 100644 index 0000000..700e35b Binary files /dev/null and b/app/src/main/res/drawable-hdpi/crits.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_action_name.png b/app/src/main/res/drawable-hdpi/ic_action_name.png new file mode 100644 index 0000000..a99894b Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_name.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_action_name2.png b/app/src/main/res/drawable-hdpi/ic_action_name2.png new file mode 100644 index 0000000..52f26b7 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_name2.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_hospital.png b/app/src/main/res/drawable-hdpi/ic_hospital.png new file mode 100644 index 0000000..18bfbd1 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_hospital.png differ diff --git a/app/src/main/res/drawable-hdpi/recovered.png b/app/src/main/res/drawable-hdpi/recovered.png new file mode 100644 index 0000000..787fd18 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/recovered.png differ diff --git a/app/src/main/res/drawable-hdpi/recoveredwhite.png b/app/src/main/res/drawable-hdpi/recoveredwhite.png new file mode 100644 index 0000000..4ae07c6 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/recoveredwhite.png differ diff --git a/app/src/main/res/drawable-hdpi/syr.png b/app/src/main/res/drawable-hdpi/syr.png new file mode 100644 index 0000000..59fb63f Binary files /dev/null and b/app/src/main/res/drawable-hdpi/syr.png differ diff --git a/app/src/main/res/drawable-hdpi/syryell.png b/app/src/main/res/drawable-hdpi/syryell.png new file mode 100644 index 0000000..c38555d Binary files /dev/null and b/app/src/main/res/drawable-hdpi/syryell.png differ diff --git a/app/src/main/res/drawable-mdpi/affcountries.png b/app/src/main/res/drawable-mdpi/affcountries.png new file mode 100644 index 0000000..9887310 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/affcountries.png differ diff --git a/app/src/main/res/drawable-mdpi/crits.png b/app/src/main/res/drawable-mdpi/crits.png new file mode 100644 index 0000000..e04a082 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/crits.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_name.png b/app/src/main/res/drawable-mdpi/ic_action_name.png new file mode 100644 index 0000000..69c67dd Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_name.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_name2.png b/app/src/main/res/drawable-mdpi/ic_action_name2.png new file mode 100644 index 0000000..95fd7a1 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_name2.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_hospital.png b/app/src/main/res/drawable-mdpi/ic_hospital.png new file mode 100644 index 0000000..ff11c26 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_hospital.png differ diff --git a/app/src/main/res/drawable-mdpi/recovered.png b/app/src/main/res/drawable-mdpi/recovered.png new file mode 100644 index 0000000..a196aea Binary files /dev/null and b/app/src/main/res/drawable-mdpi/recovered.png differ diff --git a/app/src/main/res/drawable-mdpi/recoveredwhite.png b/app/src/main/res/drawable-mdpi/recoveredwhite.png new file mode 100644 index 0000000..0717fa7 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/recoveredwhite.png differ diff --git a/app/src/main/res/drawable-mdpi/syr.png b/app/src/main/res/drawable-mdpi/syr.png new file mode 100644 index 0000000..05dc059 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/syr.png differ diff --git a/app/src/main/res/drawable-mdpi/syryell.png b/app/src/main/res/drawable-mdpi/syryell.png new file mode 100644 index 0000000..90f9700 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/syryell.png differ diff --git a/app/src/main/res/drawable-v21/icsa.png b/app/src/main/res/drawable-v21/icsa.png new file mode 100644 index 0000000..05afa08 Binary files /dev/null and b/app/src/main/res/drawable-v21/icsa.png differ diff --git a/app/src/main/res/drawable-v21/virusasdfasdfasdf.png b/app/src/main/res/drawable-v21/virusasdfasdfasdf.png new file mode 100644 index 0000000..6181ab0 Binary files /dev/null and b/app/src/main/res/drawable-v21/virusasdfasdfasdf.png differ diff --git a/app/src/main/res/drawable-v24/.DS_Store b/app/src/main/res/drawable-v24/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/app/src/main/res/drawable-v24/.DS_Store differ diff --git a/app/src/main/res/drawable-xhdpi/affcountries.png b/app/src/main/res/drawable-xhdpi/affcountries.png new file mode 100644 index 0000000..229f3fd Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/affcountries.png differ diff --git a/app/src/main/res/drawable-xhdpi/crits.png b/app/src/main/res/drawable-xhdpi/crits.png new file mode 100644 index 0000000..c75f62e Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/crits.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_name.png b/app/src/main/res/drawable-xhdpi/ic_action_name.png new file mode 100644 index 0000000..3d88a9e Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_name.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_name2.png b/app/src/main/res/drawable-xhdpi/ic_action_name2.png new file mode 100644 index 0000000..c289676 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_name2.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_hospital.png b/app/src/main/res/drawable-xhdpi/ic_hospital.png new file mode 100644 index 0000000..3a8ebd4 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_hospital.png differ diff --git a/app/src/main/res/drawable-xhdpi/recovered.png b/app/src/main/res/drawable-xhdpi/recovered.png new file mode 100644 index 0000000..76dea96 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/recovered.png differ diff --git a/app/src/main/res/drawable-xhdpi/recoveredwhite.png b/app/src/main/res/drawable-xhdpi/recoveredwhite.png new file mode 100644 index 0000000..7f274e7 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/recoveredwhite.png differ diff --git a/app/src/main/res/drawable-xhdpi/syr.png b/app/src/main/res/drawable-xhdpi/syr.png new file mode 100644 index 0000000..ad4ba63 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/syr.png differ diff --git a/app/src/main/res/drawable-xhdpi/syryell.png b/app/src/main/res/drawable-xhdpi/syryell.png new file mode 100644 index 0000000..ff6d1c6 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/syryell.png differ diff --git a/app/src/main/res/drawable-xxhdpi/affcountries.png b/app/src/main/res/drawable-xxhdpi/affcountries.png new file mode 100644 index 0000000..02cd3e9 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/affcountries.png differ diff --git a/app/src/main/res/drawable-xxhdpi/crits.png b/app/src/main/res/drawable-xxhdpi/crits.png new file mode 100644 index 0000000..325bcd6 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/crits.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_name.png b/app/src/main/res/drawable-xxhdpi/ic_action_name.png new file mode 100644 index 0000000..80e49bb Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_name.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_name2.png b/app/src/main/res/drawable-xxhdpi/ic_action_name2.png new file mode 100644 index 0000000..9bbe2f6 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_name2.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_hospital.png b/app/src/main/res/drawable-xxhdpi/ic_hospital.png new file mode 100644 index 0000000..4b3a62a Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_hospital.png differ diff --git a/app/src/main/res/drawable-xxhdpi/recovered.png b/app/src/main/res/drawable-xxhdpi/recovered.png new file mode 100644 index 0000000..4cba676 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/recovered.png differ diff --git a/app/src/main/res/drawable-xxhdpi/recoveredwhite.png b/app/src/main/res/drawable-xxhdpi/recoveredwhite.png new file mode 100644 index 0000000..39837cc Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/recoveredwhite.png differ diff --git a/app/src/main/res/drawable-xxhdpi/syr.png b/app/src/main/res/drawable-xxhdpi/syr.png new file mode 100644 index 0000000..feba759 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/syr.png differ diff --git a/app/src/main/res/drawable-xxhdpi/syryell.png b/app/src/main/res/drawable-xxhdpi/syryell.png new file mode 100644 index 0000000..2160e17 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/syryell.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/syr.png b/app/src/main/res/drawable-xxxhdpi/syr.png new file mode 100644 index 0000000..e52b5db Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/syr.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/syryell.png b/app/src/main/res/drawable-xxxhdpi/syryell.png new file mode 100644 index 0000000..45fa594 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/syryell.png differ diff --git a/app/src/main/res/drawable/asdfasdfsadfasdfasdfas.png b/app/src/main/res/drawable/asdfasdfsadfasdfasdfas.png new file mode 100644 index 0000000..9d024f2 Binary files /dev/null and b/app/src/main/res/drawable/asdfasdfsadfasdfasdfas.png differ diff --git a/app/src/main/res/drawable/clip.xml b/app/src/main/res/drawable/clip.xml new file mode 100644 index 0000000..34ccb0f --- /dev/null +++ b/app/src/main/res/drawable/clip.xml @@ -0,0 +1,5 @@ + + \ No newline at end of file diff --git a/app/src/main/res/drawable/color_item_popup.xml b/app/src/main/res/drawable/color_item_popup.xml new file mode 100755 index 0000000..9e034f8 --- /dev/null +++ b/app/src/main/res/drawable/color_item_popup.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/female.png b/app/src/main/res/drawable/female.png new file mode 100755 index 0000000..66354c2 Binary files /dev/null and b/app/src/main/res/drawable/female.png differ diff --git a/app/src/main/res/drawable/frame.xml b/app/src/main/res/drawable/frame.xml new file mode 100644 index 0000000..6f544d8 --- /dev/null +++ b/app/src/main/res/drawable/frame.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/globe.png b/app/src/main/res/drawable/globe.png new file mode 100644 index 0000000..54ee24f Binary files /dev/null and b/app/src/main/res/drawable/globe.png differ diff --git a/app/src/main/res/drawable/hospital.png b/app/src/main/res/drawable/hospital.png new file mode 100644 index 0000000..23e6837 Binary files /dev/null and b/app/src/main/res/drawable/hospital.png differ diff --git a/app/src/main/res/drawable/hospitalclearcorrect1.png b/app/src/main/res/drawable/hospitalclearcorrect1.png new file mode 100644 index 0000000..a3a2f43 Binary files /dev/null and b/app/src/main/res/drawable/hospitalclearcorrect1.png differ diff --git a/app/src/main/res/drawable/ic_check_black_24dp.xml b/app/src/main/res/drawable/ic_check_black_24dp.xml new file mode 100644 index 0000000..cc424b4 --- /dev/null +++ b/app/src/main/res/drawable/ic_check_black_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_down.xml b/app/src/main/res/drawable/ic_down.xml new file mode 100755 index 0000000..0d10009 --- /dev/null +++ b/app/src/main/res/drawable/ic_down.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100755 index 0000000..edd5e7e --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100755 index 0000000..3bb4cdb --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_map_black_24dp.xml b/app/src/main/res/drawable/ic_map_black_24dp.xml new file mode 100644 index 0000000..b9bacc8 --- /dev/null +++ b/app/src/main/res/drawable/ic_map_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_up.xml b/app/src/main/res/drawable/ic_up.xml new file mode 100755 index 0000000..879f38b --- /dev/null +++ b/app/src/main/res/drawable/ic_up.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/iconus.png b/app/src/main/res/drawable/iconus.png new file mode 100644 index 0000000..50eb10e Binary files /dev/null and b/app/src/main/res/drawable/iconus.png differ diff --git a/app/src/main/res/drawable/male.png b/app/src/main/res/drawable/male.png new file mode 100755 index 0000000..881edf2 Binary files /dev/null and b/app/src/main/res/drawable/male.png differ diff --git a/app/src/main/res/drawable/round_rect_shape.xml b/app/src/main/res/drawable/round_rect_shape.xml new file mode 100644 index 0000000..136ad09 --- /dev/null +++ b/app/src/main/res/drawable/round_rect_shape.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/round_rect_shape_blue_clip.xml b/app/src/main/res/drawable/round_rect_shape_blue_clip.xml new file mode 100644 index 0000000..1389c56 --- /dev/null +++ b/app/src/main/res/drawable/round_rect_shape_blue_clip.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/round_rect_shape_little_lighter.xml b/app/src/main/res/drawable/round_rect_shape_little_lighter.xml new file mode 100644 index 0000000..8c86aae --- /dev/null +++ b/app/src/main/res/drawable/round_rect_shape_little_lighter.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/rounded_corner.xml b/app/src/main/res/drawable/rounded_corner.xml new file mode 100644 index 0000000..d1d774e --- /dev/null +++ b/app/src/main/res/drawable/rounded_corner.xml @@ -0,0 +1,16 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/side_nav_bar.xml b/app/src/main/res/drawable/side_nav_bar.xml new file mode 100755 index 0000000..6d81870 --- /dev/null +++ b/app/src/main/res/drawable/side_nav_bar.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/stateicon.png b/app/src/main/res/drawable/stateicon.png new file mode 100644 index 0000000..d053034 Binary files /dev/null and b/app/src/main/res/drawable/stateicon.png differ diff --git a/app/src/main/res/drawable/stateiconfinal.png b/app/src/main/res/drawable/stateiconfinal.png new file mode 100644 index 0000000..d5d66c6 Binary files /dev/null and b/app/src/main/res/drawable/stateiconfinal.png differ diff --git a/app/src/main/res/drawable/uccovid.png b/app/src/main/res/drawable/uccovid.png new file mode 100644 index 0000000..401a301 Binary files /dev/null and b/app/src/main/res/drawable/uccovid.png differ diff --git a/app/src/main/res/drawable/us.png b/app/src/main/res/drawable/us.png new file mode 100644 index 0000000..dfb61fb Binary files /dev/null and b/app/src/main/res/drawable/us.png differ diff --git a/app/src/main/res/drawable/uscolor.jpeg b/app/src/main/res/drawable/uscolor.jpeg new file mode 100644 index 0000000..f548ebb Binary files /dev/null and b/app/src/main/res/drawable/uscolor.jpeg differ diff --git a/app/src/main/res/drawable/virus.png b/app/src/main/res/drawable/virus.png new file mode 100644 index 0000000..5aff43c Binary files /dev/null and b/app/src/main/res/drawable/virus.png differ diff --git a/app/src/main/res/font/alice.xml b/app/src/main/res/font/alice.xml new file mode 100644 index 0000000..17673dc --- /dev/null +++ b/app/src/main/res/font/alice.xml @@ -0,0 +1,7 @@ + + + diff --git a/app/src/main/res/font/aubrey.ttf b/app/src/main/res/font/aubrey.ttf new file mode 100644 index 0000000..d0f8767 Binary files /dev/null and b/app/src/main/res/font/aubrey.ttf differ diff --git a/app/src/main/res/font/cutive.ttf b/app/src/main/res/font/cutive.ttf new file mode 100644 index 0000000..618540e Binary files /dev/null and b/app/src/main/res/font/cutive.ttf differ diff --git a/app/src/main/res/font/montserrat_bold.xml b/app/src/main/res/font/montserrat_bold.xml new file mode 100644 index 0000000..afbba1b --- /dev/null +++ b/app/src/main/res/font/montserrat_bold.xml @@ -0,0 +1,7 @@ + + + diff --git a/app/src/main/res/layout/activity_home.xml b/app/src/main/res/layout/activity_home.xml new file mode 100644 index 0000000..a1c2f08 --- /dev/null +++ b/app/src/main/res/layout/activity_home.xml @@ -0,0 +1,59 @@ + + + + + + + + +