package io.github.izzyleung.zhihudailypurify.task;

import android.os.AsyncTask;

import com.google.gson.GsonBuilder;

import java.util.List;

import io.github.izzyleung.zhihudailypurify.ZhihuDailyPurifyApplication;
import io.github.izzyleung.zhihudailypurify.bean.DailyNews;
import io.github.izzyleung.zhihudailypurify.db.DailyNewsDataSource;

public class SaveNewsListTask extends AsyncTask<Void, Void, Void> {
    private List<DailyNews> newsList;

    public SaveNewsListTask(List<DailyNews> newsList) {
        this.newsList = newsList;
    }

    @Override
    protected Void doInBackground(Void... params) {
        if (newsList != null && newsList.size() > 0) {
            saveNewsList(newsList);
        }

        return null;
    }

    private void saveNewsList(List<DailyNews> newsList) {
        DailyNewsDataSource dataSource = ZhihuDailyPurifyApplication.getDataSource();
        String date = newsList.get(0).getDate();

        List<DailyNews> originalData = dataSource.newsOfTheDay(date);
        boolean isDataUnchanged = originalData == null || originalData.equals(newsList);

        if (!isDataUnchanged) {
            dataSource.insertOrUpdateNewsList(date, new GsonBuilder().create().toJson(newsList));
        }
    }
}
@@ -1002,24 +1002,25 @@
 (date);%0A
+%0A
         
 boolean 
@@ -1015,34 +1015,12 @@
     
-boolean isDataUnchanged = 
+if (
 orig
@@ -1039,16 +1039,17 @@
 null %7C%7C 
+!
 original
@@ -1073,39 +1073,8 @@
 ist)
-;%0A%0A        if (!isDataUnchanged
 ) %7B%0A

Fix save data issue