Skip to content

Commit

Permalink
Merge pull request #12 from RoberteFlaherty/app-improvements
Browse files Browse the repository at this point in the history
app-improvements add daily deaths date
  • Loading branch information
BillelBmsd authored May 8, 2020
2 parents 4c201a9 + ffba16c commit 5a20714
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 25 deletions.
29 changes: 26 additions & 3 deletions app/src/main/java/com/covidvirus/app/ui/home/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.covidvirus.app.R;
import com.covidvirus.app.data.network.model.Location;
Expand All @@ -26,6 +27,9 @@
import com.covidvirus.app.ui.home.profile.ProfileFragment;

import java.util.ArrayList;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import butterknife.BindView;
import butterknife.ButterKnife;
Expand All @@ -46,6 +50,9 @@ public class MainActivity extends BaseActivity<MainViewModel> {
private InterstitialAd mInterstitialAd;





@Override
public MainViewModel createViewModel() {
MainViewModelFactory factory = new MainViewModelFactory(DataManager.getInstance().getLocationService());
Expand All @@ -64,10 +71,13 @@ protected void onCreate(Bundle savedInstanceState) {
if (DataManager.getInstance().getDefaultCountry() == null) {
viewModel.loadLocationData();
viewModel.getLocationData().observe(this, new LocationDataObserver());
} else
} else {
loadFragment(R.id.profileContainer, new ProfileFragment());
setMainPagerAdapter();
mainTabLayout.setupWithViewPager(mainPager, true);
setMainPagerAdapter();
mainTabLayout.setupWithViewPager(mainPager, true);
}


}

private void initAdMob(){
Expand Down Expand Up @@ -123,6 +133,7 @@ private void setMainPagerAdapter() {
titles.add(this.getResources().getString(R.string.countries_fragment));
mainAdapter.addTitles(titles);
mainPager.setAdapter(mainAdapter);

}

private void loadFragment(int viewId, Fragment fragment) {
Expand All @@ -134,6 +145,16 @@ private void loadFragment(int viewId, Fragment fragment) {
}
}

private void changeText()
{
Date date = new Date();
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
//format() method Formats a Date into a date/time string.
String testDateString = df.format(date);
TextView textView = (TextView) findViewById(R.id.deathText);
textView.setText("AAA");
}

private class LocationDataObserver implements Observer<Location> {
@Override
public void onChanged(Location location) {
Expand All @@ -144,4 +165,6 @@ public void onChanged(Location location) {
}
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import com.covidvirus.app.data.DataManager;
import com.covidvirus.app.data.network.model.CountryDataModel;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
Expand Down Expand Up @@ -125,6 +128,7 @@ private void setupDialogView(View dialogView, CountryDataModel country){
((ProgressBar)dialogView.findViewById(R.id.progressBarDetail)).setVisibility(View.GONE);
}


private void cleanDialogView(View dialogView){
Glide.with(this).load("").into((ImageView)dialogView.findViewById(R.id.flag_img));
((TextView)dialogView.findViewById(R.id.countryTitle)).setText("");
Expand All @@ -134,6 +138,14 @@ private void cleanDialogView(View dialogView){
((TextView)dialogView.findViewById(R.id.totalDeathValue)).setText("");
((TextView)dialogView.findViewById(R.id.todayDeathValue)).setText("");
((TextView)dialogView.findViewById(R.id.recoverValue)).setText("");

Date date = new Date();
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
//format() method Formats a Date into a date/time string.
String testDateString = df.format(date);
((TextView)dialogView.findViewById(R.id.deathText)).setText("Deaths Today \n (" + testDateString + ")");


((ProgressBar)dialogView.findViewById(R.id.progressBarDetail)).setVisibility(View.VISIBLE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@

import com.covidvirus.app.ui.base.BaseFragment;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import static com.covidvirus.app.R.id.deathText;

public class ProfileFragment extends BaseFragment<ProfileViewModel> {
private static final String TAG = "ProfileFragment";
private ProfileViewModel viewModel;
Expand Down Expand Up @@ -111,6 +117,7 @@ public void onChanged(CountryDataModel country) {
setTotalDeathCases(String.valueOf(country.getNbrDeath()));
setTodayDeathCases(String.valueOf(country.getTodayDeaths()));
setRecoverCases(String.valueOf(country.getNbrRecovered()));
setTodayDeathdate();

setProfileVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE);
Expand Down Expand Up @@ -146,6 +153,14 @@ private void setTodayDeathCases(String deathCases) {
( (TextView) this.deathItem.findViewById(R.id.todayDeathValue)).setText(deathCases);
}

private void setTodayDeathdate() {
Date date = new Date();
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
//format() method Formats a Date into a date/time string.
String testDateString = df.format(date);
( (TextView) this.deathItem.findViewById(R.id.deathText)).setText("Deaths today \n (" + testDateString + ")");
}

private void setRecoverCases(String recoverCases) {

( (TextView) this.recoverItem.findViewById(R.id.recoverValue)).setText(recoverCases);
Expand Down
22 changes: 11 additions & 11 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@
android:layout_height="match_parent"
android:orientation="vertical">

<com.google.android.material.tabs.TabLayout
android:background="@drawable/bg_tabs"
app:tabTextColor="@color/colorHintText"
android:id="@+id/mainTabs"
android:layout_width="match_parent"
android:layout_height="50dp"
app:tabGravity="fill"
app:tabMode="fixed"
app:tabIndicatorColor="@color/colorAccent"
app:tabSelectedTextColor="@color/colorPrimary" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/mainTabs"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/bg_tabs"
app:tabGravity="fill"
app:tabIndicatorColor="@color/colorAccent"
app:tabMode="fixed"
app:tabSelectedTextColor="@color/colorPrimary"
app:tabTextColor="@color/colorHintText" />

<androidx.viewpager.widget.ViewPager
<androidx.viewpager.widget.ViewPager
android:background="@drawable/bg_pager"
android:id="@+id/mainPager"
android:layout_width="match_parent"
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/res/layout/death_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@
android:textStyle="bold"/>

<TextView
android:layout_width="120dp"
android:layout_height="20dp"
android:id="@+id/deathText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorHintTextDark"
android:textStyle="italic"
android:textSize="12sp"
android:text="@string/today_death_title"/>
android:textStyle="italic" />
<!-- android:text="@string/today_death_title" -->


</LinearLayout>

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/detail_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
android:id="@+id/deathItem"
layout="@layout/death_item"
android:layout_width="match_parent"
android:layout_height="50dp" />
android:layout_height="wrap_content" />

<include
android:id="@+id/recoverItem"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
android:id="@+id/deathItem"
layout="@layout/death_item"
android:layout_width="match_parent"
android:layout_height="50dp" />
android:layout_height="wrap_content" />

<include
android:id="@+id/recoverItem"
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
<string name="app_name" translatable="false">Covid-19</string>
<string name="total_cases_title">Total cases</string>
<string name="active_cases_title">Active cases</string>
<string name="today_cases_title">Today cases</string>
<string name="today_cases_title">Todays cases</string>
<string name="total_death_title">Total deaths</string>
<string name="today_death_title">Today deaths</string>
<string name="total_recover_title">Total recovers</string>
<string name="global_fragment">Global State</string>
<string name="countries_fragment">Countries State</string>
<string name="today_death_title">Todays death count</string>
<string name="total_recover_title">Total recoveries</string>
<string name="global_fragment">Global Cases</string>
<string name="countries_fragment">Cases By Country</string>
<string name="default_country">Algeria</string>
<string name="details">Details</string>


<!-- About section-->
<string name="about">About</string>
<string name="version" translatable="false">v1.0.2</string>
Expand Down

0 comments on commit 5a20714

Please sign in to comment.