From 0f1a5db2141320d1fd688490b2df6b3dc1a74709 Mon Sep 17 00:00:00 2001 From: adya1904 Date: Fri, 27 Mar 2020 10:08:32 +0530 Subject: [PATCH] added heat map suppport --- app/build.gradle | 2 +- app/src/main/AndroidManifest.xml | 2 +- .../java/india/coronavirus/fight/HeatMap.java | 53 ++++++++ .../india/coronavirus/fight/MainActivity.java | 42 ++++++ .../fight/dataAdapter/DataAdapterMain.java | 50 +++++++- .../coronavirus/fight/model/HeaderData.java | 11 +- .../fight/ui/heatmap/HeatMapFrgament.java | 41 ++++++ .../fight/ui/helpline/HelplineFragment.java | 2 +- .../fight/ui/home/HomeViewModel.java | 13 +- .../fight/ui/statewise/StateFragment.java | 18 ++- .../fight/ui/statewise/StateViewModel.java | 2 +- app/src/main/res/drawable/arrow_right.xml | 8 ++ app/src/main/res/drawable/map_marker.xml | 8 ++ app/src/main/res/layout/activity_main.xml | 47 ++++++- app/src/main/res/layout/cardview.xml | 121 +++++++++++------- .../main/res/layout/fragment_statewise.xml | 33 ++++- app/src/main/res/layout/fragment_web.xml | 26 ++++ app/src/main/res/layout/state_layout.xml | 2 +- .../main/res/navigation/mobile_navigation.xml | 1 - app/src/main/res/values/colors.xml | 2 + app/src/main/res/values/strings.xml | 30 +++-- 21 files changed, 426 insertions(+), 88 deletions(-) create mode 100644 app/src/main/java/india/coronavirus/fight/HeatMap.java create mode 100644 app/src/main/java/india/coronavirus/fight/ui/heatmap/HeatMapFrgament.java create mode 100644 app/src/main/res/drawable/arrow_right.xml create mode 100644 app/src/main/res/drawable/map_marker.xml create mode 100644 app/src/main/res/layout/fragment_web.xml diff --git a/app/build.gradle b/app/build.gradle index acda880..22e0516 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -23,7 +23,7 @@ android { minSdkVersion 23 targetSdkVersion 29 versionCode 1 - versionName "1.3" + versionName "1.5" compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 756ffbf..2514dcb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -26,7 +26,7 @@ - + quoteList = new ArrayList<>(); + private Integer i = 0; @Override protected void onCreate(Bundle savedInstanceState) { @@ -41,6 +45,7 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_main); BottomNavigationView navView = findViewById(R.id.nav_view); + MaterialTextView quotetext = findViewById(R.id.quoteText); MaterialTextView textView = findViewById(R.id.marquee); textView.setSelected(true); OneSignal.startInit(this) @@ -51,12 +56,15 @@ protected void onCreate(Bundle savedInstanceState) { SharedPreferences sharedPreferences = this.getSharedPreferences("API", MODE_PRIVATE); editor = sharedPreferences.edit(); + CollectionReference apiCollection = FirebaseFirestore.getInstance().collection("apilink"); apiCollection.addSnapshotListener((queryDocumentSnapshots, e) -> { if (queryDocumentSnapshots != null) { for (DocumentChange documentChange : queryDocumentSnapshots.getDocumentChanges()) { api = documentChange.getDocument().getString("api"); new_version = documentChange.getDocument().getString("version"); + boolean showgraph = documentChange.getDocument().getBoolean("showgraph"); + editor.putBoolean("showgraph", showgraph); editor.putString("new_version", version); editor.putString("API", api); editor.apply(); @@ -84,6 +92,40 @@ protected void onCreate(Bundle savedInstanceState) { startActivity(intent); } }); + quoteList.add("Don't Hoard groceries and essentials. Please ensure that people who are in need don't face a shortage because of you!"); + quoteList.add("Plan ahead! Take a minute and check how much you have at home. Planning ahead let's you buy exactly what you need!"); + quoteList.add("If you have symptoms and suspect you have coronavirus - reach out to your doctor or call state helplines. \uD83D\uDCDE Get help."); + quoteList.add("Panic mode : OFF! ❌ ESSENTIALS ARE ON! ✔️"); + quoteList.add("Help out the elderly by bringing them their groceries and other essentials."); + quoteList.add("Be considerate : While buying essentials remember : You need to share with 130 Crore Others! "); + quoteList.add("Stand Against FAKE News and WhatsApp Forwards! Do NOT ❌ forward a message until you verify the content it contains."); + quoteList.add("Be compassionate! Help those in need like the elderly and poor. They are facing a crisis you cannot even imagine! "); + + thread = new Thread() { + @Override + public void run() { + try { + while (!thread.isInterrupted()) { + Thread.sleep(5000); + runOnUiThread(new Runnable() { + @Override + public void run() { + if (i < quoteList.size()) { + quotetext.setText(quoteList.get(i)); + i++; + } else { + i = 0; + } + } + }); + } + } catch (InterruptedException ignored) { + } + } + }; + thread.start(); + + } @Override diff --git a/app/src/main/java/india/coronavirus/fight/dataAdapter/DataAdapterMain.java b/app/src/main/java/india/coronavirus/fight/dataAdapter/DataAdapterMain.java index 122fe4b..be6a288 100644 --- a/app/src/main/java/india/coronavirus/fight/dataAdapter/DataAdapterMain.java +++ b/app/src/main/java/india/coronavirus/fight/dataAdapter/DataAdapterMain.java @@ -1,9 +1,14 @@ package india.coronavirus.fight.dataAdapter; +import android.annotation.SuppressLint; import android.content.Context; +import android.content.SharedPreferences; +import android.content.res.ColorStateList; +import android.graphics.Color; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.webkit.WebView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; @@ -19,9 +24,12 @@ import india.coronavirus.fight.R; import india.coronavirus.fight.model.HeaderData; +import static android.content.Context.MODE_PRIVATE; + public class DataAdapterMain extends RecyclerView.Adapter { private List headerDataList; private Context mContext; + private SharedPreferences sharedPreferences ; public DataAdapterMain(ArrayList headerDatalist, Context context) { this.headerDataList = headerDatalist; @@ -35,9 +43,47 @@ public DataAdapterMain.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, return new ViewHolder(view); } + @SuppressLint("ResourceAsColor") @Override public void onBindViewHolder(@NonNull DataAdapterMain.ViewHolder holder, int position) { -// Toast.makeText(mContext, String.valueOf(position), Toast.LENGTH_SHORT).show(); + sharedPreferences = mContext.getSharedPreferences("API", MODE_PRIVATE); + if (!sharedPreferences.getBoolean("showgraph",true)) { + holder.grahView.setVisibility(View.GONE); + } + HeaderData headerData = headerDataList.get(position); + holder.grahView.setScrollbarFadingEnabled(true); + holder.grahView.setVerticalScrollBarEnabled(false); + holder.grahView.setHorizontalScrollBarEnabled(false); + if (headerData.getHeader().trim().equals("CONFIRMED")) { + holder.grahView.loadUrl("http://ac41bf31.ngrok.io/api/graphsvg/cases"); + } else if (headerData.getHeader().trim().equals("ACTIVE")) { + holder.grahView.loadUrl("http://ac41bf31.ngrok.io/api/graphsvg/active"); + } else if (headerData.getHeader().trim().equals("RECOVERED")) { + holder.grahView.loadUrl("http://ac41bf31.ngrok.io/api/graphsvg/cured"); + } else if (headerData.getHeader().trim().equals("DEATH")) { + holder.grahView.loadUrl("http://ac41bf31.ngrok.io/api/graphsvg/death"); + } + if (headerData.getColor().trim().equals("red")) { + holder.heading_card.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#34FB0032"))); + holder.heading_card.setTextColor(Color.parseColor("#B0FB0032")); + holder.total_case.setTextColor(Color.parseColor("#B0FB0032")); + holder.new_case.setTextColor(Color.parseColor("#B0FB0032")); + } else if (headerData.getColor().trim().equals("green")) { + holder.heading_card.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#2748A107"))); + holder.heading_card.setTextColor(Color.parseColor("#D348A107")); + holder.total_case.setTextColor(Color.parseColor("#D348A107")); + holder.new_case.setTextColor(Color.parseColor("#D348A107")); + } else if (headerData.getColor().trim().equals("blue")) { + holder.heading_card.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#2000C5F6"))); + holder.heading_card.setTextColor(Color.parseColor("#D300C5F6")); + holder.total_case.setTextColor(Color.parseColor("#D300C5F6")); + holder.new_case.setTextColor(Color.parseColor("#D300C5F6")); + } else if (headerData.getColor().trim().equals("gray")) { + holder.heading_card.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#22828383"))); + holder.heading_card.setTextColor(Color.parseColor("#D0828383")); + holder.total_case.setTextColor(Color.parseColor("#D0828383")); + holder.new_case.setTextColor(Color.parseColor("#D0828383")); + } holder.heading_card.setText(headerDataList.get(position).getHeader()); holder.total_case.setText(headerDataList.get(position).getCases()); holder.sub_heading_1.setText(headerDataList.get(position).getSubheader()); @@ -60,6 +106,8 @@ public static class ViewHolder extends RecyclerView.ViewHolder { MaterialTextView sub_heading_1; @BindView(R.id.subheading2) MaterialTextView sub_heading_2; + @BindView(R.id.graph) + WebView grahView; public ViewHolder(@NonNull View itemView) { super(itemView); diff --git a/app/src/main/java/india/coronavirus/fight/model/HeaderData.java b/app/src/main/java/india/coronavirus/fight/model/HeaderData.java index 59cc9cc..e83e8ce 100644 --- a/app/src/main/java/india/coronavirus/fight/model/HeaderData.java +++ b/app/src/main/java/india/coronavirus/fight/model/HeaderData.java @@ -5,13 +5,22 @@ public class HeaderData { private String header; private String subheader; private String newcase; + private String color; - public HeaderData(String cases, String header, String subheader, String new_case) { + public HeaderData(String cases, String header, String subheader, String new_case, String color) { this.cases = cases; this.header = header; this.subheader = subheader; this.newcase = new_case; + this.color = color; + } + + public String getColor() { + return color; + } + public void setColor(String color) { + this.color = color; } public String getNewcase() { diff --git a/app/src/main/java/india/coronavirus/fight/ui/heatmap/HeatMapFrgament.java b/app/src/main/java/india/coronavirus/fight/ui/heatmap/HeatMapFrgament.java new file mode 100644 index 0000000..b3f45d6 --- /dev/null +++ b/app/src/main/java/india/coronavirus/fight/ui/heatmap/HeatMapFrgament.java @@ -0,0 +1,41 @@ +package india.coronavirus.fight.ui.heatmap; + +import android.annotation.SuppressLint; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.webkit.WebSettings; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import android.widget.ProgressBar; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; + +import butterknife.BindView; +import butterknife.ButterKnife; +import india.coronavirus.fight.R; + +public class HeatMapFrgament extends Fragment { + + @BindView(R.id.progress_bar) + ProgressBar progressBar; + @BindView(R.id.web) + WebView webView; + + @SuppressLint("SetJavaScriptEnabled") + public View onCreateView(@NonNull LayoutInflater inflater, + ViewGroup container, Bundle savedInstanceState) { + + View root = inflater.inflate(R.layout.fragment_web, container, false); + ButterKnife.bind(this, root); + progressBar.setVisibility(View.VISIBLE); + + webView.getSettings().setJavaScriptEnabled(true); + webView.getSettings().setPluginState(WebSettings.PluginState.ON); + webView.loadUrl("http://ac41bf31.ngrok.io/india"); + webView.setWebViewClient(new WebViewClient()); + return root; + } +} diff --git a/app/src/main/java/india/coronavirus/fight/ui/helpline/HelplineFragment.java b/app/src/main/java/india/coronavirus/fight/ui/helpline/HelplineFragment.java index 4a6000d..e148101 100644 --- a/app/src/main/java/india/coronavirus/fight/ui/helpline/HelplineFragment.java +++ b/app/src/main/java/india/coronavirus/fight/ui/helpline/HelplineFragment.java @@ -25,7 +25,7 @@ public class HelplineFragment extends Fragment { private HelplineViewModel notificationsViewModel; private ArrayList> headerDatalist = new ArrayList<>(); - ; + @BindView(R.id.recyclerView) RecyclerView recyclerView; @BindView(R.id.progress_bar) diff --git a/app/src/main/java/india/coronavirus/fight/ui/home/HomeViewModel.java b/app/src/main/java/india/coronavirus/fight/ui/home/HomeViewModel.java index 93a246c..7ca64f4 100644 --- a/app/src/main/java/india/coronavirus/fight/ui/home/HomeViewModel.java +++ b/app/src/main/java/india/coronavirus/fight/ui/home/HomeViewModel.java @@ -67,19 +67,20 @@ public void refreshData() { JSONObject json = new JSONObject(response1); Log.d("response", String.valueOf(json)); String filtered = "{\"stats\": [{\"stat1\":\"" + json.getInt("cases") + - "\"," + "\"oldcount\":\"" + new_cases + "\",\"heading\":\"Total CASES\",\"subheading\":Total}," + + "\"," + "\"oldcount\":\"" + new_cases + "\",\"heading\":\"CONFIRMED\",\"subheading\":Total,\"color\":red}," + + "{\"stat1\":\"" + json.getInt("hospitalized") + + "\"," + "\"oldcount\":\"" + oldhospitalized + "\",\"heading\":\"ACTIVE\",\"subheading\":Active,\"color\":blue}," + "{\"stat1\":\"" + json.getInt("cured") + - "\"," + "\"oldcount\":\"" + new_cured + "\",\"heading\":\"Recovered CASES\",\"subheading\":Recovered}," + + "\"," + "\"oldcount\":\"" + new_cured + "\",\"heading\":\"RECOVERED\",\"subheading\":Recovered,\"color\":green}," + "{\"stat1\":\"" + json.getInt("death") + - "\"," + "\"oldcount\":\"" + new_death + "\",\"heading\":\"Death CASES\",\"subheading\":Deaths}," + - "{\"stat1\":\"" + json.getInt("hospitalized") + - "\"," + "\"oldcount\":\"" + oldhospitalized + "\",\"heading\":\"Hospitalized CASES\",\"subheading\":Hospitalized}]}"; + "\"," + "\"oldcount\":\"" + new_death + "\",\"heading\":\"DEATH\",\"subheading\":Deaths,\"color\":gray}]}"; JSONObject jsonObject2 = new JSONObject(filtered); JSONArray jsonArray = jsonObject2.getJSONArray("stats"); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject1 = jsonArray.getJSONObject(i); - headerData.add(new HeaderData(jsonObject1.getString("stat1"), jsonObject1.getString("heading"), jsonObject1.getString("subheading"), jsonObject1.getString("oldcount"))); + headerData.add(new HeaderData(jsonObject1.getString("stat1"), jsonObject1.getString("heading"), jsonObject1.getString("subheading"), jsonObject1.getString("oldcount"), + jsonObject1.getString("color"))); dataMutableLiveData.setValue(headerData); } } catch (JSONException e) { diff --git a/app/src/main/java/india/coronavirus/fight/ui/statewise/StateFragment.java b/app/src/main/java/india/coronavirus/fight/ui/statewise/StateFragment.java index be5b40e..9ed1501 100644 --- a/app/src/main/java/india/coronavirus/fight/ui/statewise/StateFragment.java +++ b/app/src/main/java/india/coronavirus/fight/ui/statewise/StateFragment.java @@ -1,11 +1,12 @@ package india.coronavirus.fight.ui.statewise; +import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.LinearLayout; import android.widget.ProgressBar; -import android.widget.Toast; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; @@ -16,9 +17,9 @@ import java.util.ArrayList; import java.util.Objects; -import butterknife.BindDimen; import butterknife.BindView; import butterknife.ButterKnife; +import india.coronavirus.fight.HeatMap; import india.coronavirus.fight.R; import india.coronavirus.fight.dataAdapter.StateAdapter; import india.coronavirus.fight.model.StateData; @@ -30,13 +31,14 @@ public class StateFragment extends Fragment { RecyclerView recyclerView; @BindView(R.id.progress_bar) ProgressBar progressBar; - + @BindView(R.id.quote_layout) + LinearLayout linearLayout; public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { StateViewModel stateViewModel = ViewModelProviders.of(this).get(StateViewModel.class); - View root = inflater.inflate(R.layout.fragment_home, container, false); + View root = inflater.inflate(R.layout.fragment_statewise, container, false); ButterKnife.bind(this, root); progressBar.setVisibility(View.VISIBLE); StateAdapter stateAdapter = new StateAdapter(stateDatalist, getContext()); @@ -51,6 +53,14 @@ public View onCreateView(@NonNull LayoutInflater inflater, progressBar.setVisibility(View.GONE); } }); + + linearLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(getContext(), HeatMap.class); + startActivity(intent); + } + }); return root; } diff --git a/app/src/main/java/india/coronavirus/fight/ui/statewise/StateViewModel.java b/app/src/main/java/india/coronavirus/fight/ui/statewise/StateViewModel.java index 558f12a..68e5b00 100644 --- a/app/src/main/java/india/coronavirus/fight/ui/statewise/StateViewModel.java +++ b/app/src/main/java/india/coronavirus/fight/ui/statewise/StateViewModel.java @@ -54,7 +54,7 @@ private void refreshData() { String statename = toTitleCase(js.getString("state")); stateDataArrayList.add(new StateData(statename, js.getString("cases"), js.getString("cured"), js.getString("death"), "Cases", - "Cured", "Deaths")); + "Recovered", "Deaths")); dataMutableLiveData.setValue(stateDataArrayList); } } catch (JSONException e) { diff --git a/app/src/main/res/drawable/arrow_right.xml b/app/src/main/res/drawable/arrow_right.xml new file mode 100644 index 0000000..cefde19 --- /dev/null +++ b/app/src/main/res/drawable/arrow_right.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/map_marker.xml b/app/src/main/res/drawable/map_marker.xml new file mode 100644 index 0000000..c3b9d48 --- /dev/null +++ b/app/src/main/res/drawable/map_marker.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 2159ee4..6e88d69 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,6 +1,7 @@ @@ -21,23 +22,42 @@ android:textStyle="bold" app:layout_constraintTop_toTopOf="parent" /> + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/cardview.xml b/app/src/main/res/layout/cardview.xml index 993d624..77984c5 100644 --- a/app/src/main/res/layout/cardview.xml +++ b/app/src/main/res/layout/cardview.xml @@ -13,69 +13,92 @@ - + app:layout_constraintTop_toBottomOf="@+id/heading"> - + - + - + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_statewise.xml b/app/src/main/res/layout/fragment_statewise.xml index 3ab36a1..ed62c92 100644 --- a/app/src/main/res/layout/fragment_statewise.xml +++ b/app/src/main/res/layout/fragment_statewise.xml @@ -1,19 +1,19 @@ + android:layout_height="wrap_content" /> + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_web.xml b/app/src/main/res/layout/fragment_web.xml new file mode 100644 index 0000000..ce82a2c --- /dev/null +++ b/app/src/main/res/layout/fragment_web.xml @@ -0,0 +1,26 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/state_layout.xml b/app/src/main/res/layout/state_layout.xml index a809821..390d832 100644 --- a/app/src/main/res/layout/state_layout.xml +++ b/app/src/main/res/layout/state_layout.xml @@ -107,7 +107,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" - android:text="Cured" + android:text="@string/recoverd" android:textSize="20sp" app:layout_constraintEnd_toStartOf="@+id/subheading2" diff --git a/app/src/main/res/navigation/mobile_navigation.xml b/app/src/main/res/navigation/mobile_navigation.xml index ef70d84..291f92e 100644 --- a/app/src/main/res/navigation/mobile_navigation.xml +++ b/app/src/main/res/navigation/mobile_navigation.xml @@ -22,7 +22,6 @@ android:name="india.coronavirus.fight.ui.statewise.StateFragment" android:label="@string/title_statewise" tools:layout="@layout/fragment_statewise" /> - #3700B3 #03DAC5 #856200EE + #460D3B8A + #22828383 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9d9a18e..4ab8617 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,15 +1,19 @@ -COVID19 India -Home -News -Helpline -Guides -State Stats -Predicted Infection rate -The Helpline Number for corona–virus : +91–11–23978046 Toll Free No: 1075 -About -Pawan0411 -SpeedX -Update Available :http://tiny.cc/covid-19india -This app is about updates related to coronavirus in India. + COVID19 India + Home + News + Helpline + Guides + State Stats + Predicted Infection rate + The Helpline Number for corona–virus : +91–11–23978046 Toll Free No: 1075 + About + Pawan0411 + SpeedX + Update Available :http://tiny.cc/covid-19india + This app is about updates related to coronavirus in India. \n + All data are fetched from Ministry of Health and Family Welfare website. + Recovered + Heat Map + Try out new Heat Map!