package io.github.izzyleung.zhihudailypurify.ui.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;

import io.github.izzyleung.zhihudailypurify.R;
import io.github.izzyleung.zhihudailypurify.support.Constants;
import io.github.izzyleung.zhihudailypurify.ui.fragment.NewsListFragment;

public class SingleDayNewsActivity extends BaseActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle bundle = getIntent().getExtras();
        Fragment newFragment = new NewsListFragment();

        String dateString = bundle.getString(Constants.BundleKeys.DATE);
        Date date;
        try {
            date = Constants.Dates.simpleDateFormat.parse(dateString);
        } catch (ParseException e) {
            // This shall never happen.
            date = Constants.Dates.birthday;
        }

        //noinspection ConstantConditions
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle(DateFormat.getDateInstance().format(date));

        bundle.putString(Constants.BundleKeys.DATE, dateString);
        bundle.putBoolean(Constants.BundleKeys.IS_FIRST_PAGE,
                isSameDay(date, Calendar.getInstance().getTime()));
        bundle.putBoolean(Constants.BundleKeys.IS_SINGLE, true);

        newFragment.setArguments(bundle);

        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.fragment_frame, newFragment)
                .commit();
    }

    private boolean isSameDay(Date first, Date second) {
        return first.equals(second);
    }
}

@@ -781,17 +781,50 @@
     
-Date date
+Calendar calendar = Calendar.getInstance()
 ;%0A  
@@ -839,32 +839,37 @@
 y %7B%0A            
+Date 
 date = Constants
@@ -923,121 +923,131 @@
     
-%7D catch (P
+    calend
 ar
+.
 se
-Exception e) %7B%0A            // This shall never happen.%0A            date = Constants.Dates.birthday;
+tTime(date);%0A            calendar.add(Calendar.DAY_OF_YEAR, -1);%0A        %7D catch (ParseException ignored) %7B%0A
 %0A   
@@ -1234,20 +1234,34 @@
 .format(
-date
+calendar.getTime()
 ));%0A%0A   
@@ -1410,20 +1410,24 @@
 SameDay(
-date
+calendar
 , Calend
@@ -1442,26 +1442,16 @@
 stance()
-.getTime()
 ));%0A    
@@ -1754,24 +1754,32 @@
 Day(
-Date first, Date
+Calendar first, Calendar
  sec
@@ -1810,21 +1810,141 @@
 rst.
-equals(second
+get(Calendar.YEAR) == second.get(Calendar.YEAR)%0A                && first.get(Calendar.DAY_OF_YEAR) == second.get(Calendar.DAY_OF_YEAR
 );%0A 

Fix date display issue