<commit_before>package org.edx.mobile.view;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

import org.edx.mobile.R;
import org.edx.mobile.base.BaseFragmentActivity;
import org.edx.mobile.base.CourseDetailBaseFragment;
import org.edx.mobile.http.Api;
import org.edx.mobile.interfaces.NetworkObserver;
import org.edx.mobile.model.api.EnrolledCoursesResponse;
import org.edx.mobile.model.api.LectureModel;
import org.edx.mobile.model.api.SectionEntry;
import org.edx.mobile.model.api.SyncLastAccessedSubsectionResponse;
import org.edx.mobile.model.api.VideoResponseModel;
import org.edx.mobile.model.db.DownloadEntry;
import org.edx.mobile.module.prefs.PrefManager;
import org.edx.mobile.task.EnqueueDownloadTask;
import org.edx.mobile.task.GetCourseHierarchyTask;
import org.edx.mobile.task.GetLastAccessedTask;
import org.edx.mobile.task.SyncLastAccessedTask;
import org.edx.mobile.util.AppConstants;
import org.edx.mobile.util.DateUtil;
import org.edx.mobile.util.MediaConsentUtils;
import org.edx.mobile.util.MemoryUtil;
import org.edx.mobile.util.NetworkUtil;
import org.edx.mobile.util.UiUtil;
import org.edx.mobile.view.adapters.ChapterAdapter;
import org.edx.mobile.view.custom.ETextView;
import org.edx.mobile.view.dialog.DownloadSizeExceedDialog;
import org.edx.mobile.view.dialog.IDialogCallback;
import org.edx.mobile.view.dialog.ProgressDialogFragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public class CourseChapterListFragment extends CourseDetailBaseFragment implements NetworkObserver{


    private static final String TAG = CourseChapterListFragment.class.getCanonicalName();
    private static final String SECTION_ENTRIES = TAG + ".sectionEntryMap";

    private ChapterAdapter adapter;
    private String courseId;
    private String openInBrowserUrl;
    private DownloadSizeExceedDialog downloadFragment;
    private ListView chapterListView;
    private static final int MSG_UPDATE_PROGRESS = 1025;
    private boolean isActivityStarted;
    private String lastAccessed_subSectionId;
    private GetLastAccessedTask getLastAccessedTask;
    private EnrolledCoursesResponse enrollment;
    private ETextView courseScheduleTv;
    private String startDate;
    private boolean isTaskRunning = false;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        logger.debug("created: " + getClass().getName());

        final Bundle bundle = getArguments();
        if(bundle!=null){
            enrollment = (EnrolledCoursesResponse) bundle
                    .getSerializable(BaseFragmentActivity.EXTRA_ENROLLMENT);
            if(enrollment!=null) {
                courseId = enrollment.getCourse().getId();
                try {
                    segIO.screenViewsTracking(enrollment.getCourse().getName()
                            + " - Courseware");
                } catch (Exception e) {
                    logger.error(e);
                }
            }
        }
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_chapter_list, container,
                false);

        //Initialize the Course not started text view.
        if (!enrollment.getCourse().isStarted()) {
            startDate = DateUtil.formatCourseNotStartedDate(enrollment.getCourse().getStart());
            if (startDate != null) {
                startDate = "<font color='" + getString(R.color.grey_text_course_not_started) + "'>" + startDate + "</font>";
                String courseScheduledText = getString(R.string.course_content_available_text);
                courseScheduledText = courseScheduledText.replace("START_DATE", startDate);
                courseScheduleTv = (ETextView) view.findViewById(R.id.course_content_available_tv);
                courseScheduleTv.setText(Html.fromHtml(courseScheduledText));
            }
        }

        ArrayList<SectionEntry> savedEntries = null;
        if (savedInstanceState != null) {

            try {
                savedEntries = (ArrayList<SectionEntry>) savedInstanceState.getSerializable(SECTION_ENTRIES);
                adapter.setItems(savedEntries);
            } catch (Exception ex) {
                logger.error(ex);
            }

        }

        chapterListView = (ListView) view
                .findViewById(R.id.chapter_list);

        initializeAdapter();
        chapterListView.setAdapter(adapter);
        chapterListView.setOnItemClickListener(adapter);
        lastClickTime = 0;

        return view;
    }

    @Override
    public void onStart() {
        super.onStart();
        isActivityStarted = true;
        adapter.setStore(db, storage);
        handler.sendEmptyMessage(MSG_UPDATE_PROGRESS);

        fetchLastAccessed(getView());
    }

    @Override
    public void onStop() {
        super.onStop();
        isActivityStarted = false;<commit_msg>Notify the chapter adapter in onStart so that the List is reloaded<commit_after>package org.edx.mobile.view;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

import org.edx.mobile.R;
import org.edx.mobile.base.BaseFragmentActivity;
import org.edx.mobile.base.CourseDetailBaseFragment;
import org.edx.mobile.http.Api;
import org.edx.mobile.interfaces.NetworkObserver;
import org.edx.mobile.model.api.EnrolledCoursesResponse;
import org.edx.mobile.model.api.LectureModel;
import org.edx.mobile.model.api.SectionEntry;
import org.edx.mobile.model.api.SyncLastAccessedSubsectionResponse;
import org.edx.mobile.model.api.VideoResponseModel;
import org.edx.mobile.model.db.DownloadEntry;
import org.edx.mobile.module.prefs.PrefManager;
import org.edx.mobile.task.EnqueueDownloadTask;
import org.edx.mobile.task.GetCourseHierarchyTask;
import org.edx.mobile.task.GetLastAccessedTask;
import org.edx.mobile.task.SyncLastAccessedTask;
import org.edx.mobile.util.AppConstants;
import org.edx.mobile.util.DateUtil;
import org.edx.mobile.util.MediaConsentUtils;
import org.edx.mobile.util.MemoryUtil;
import org.edx.mobile.util.NetworkUtil;
import org.edx.mobile.util.UiUtil;
import org.edx.mobile.view.adapters.ChapterAdapter;
import org.edx.mobile.view.custom.ETextView;
import org.edx.mobile.view.dialog.DownloadSizeExceedDialog;
import org.edx.mobile.view.dialog.IDialogCallback;
import org.edx.mobile.view.dialog.ProgressDialogFragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public class CourseChapterListFragment extends CourseDetailBaseFragment implements NetworkObserver{


    private static final String TAG = CourseChapterListFragment.class.getCanonicalName();
    private static final String SECTION_ENTRIES = TAG + ".sectionEntryMap";

    private ChapterAdapter adapter;
    private String courseId;
    private String openInBrowserUrl;
    private DownloadSizeExceedDialog downloadFragment;
    private ListView chapterListView;
    private static final int MSG_UPDATE_PROGRESS = 1025;
    private boolean isActivityStarted;
    private String lastAccessed_subSectionId;
    private GetLastAccessedTask getLastAccessedTask;
    private EnrolledCoursesResponse enrollment;
    private ETextView courseScheduleTv;
    private String startDate;
    private boolean isTaskRunning = false;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        logger.debug("created: " + getClass().getName());

        final Bundle bundle = getArguments();
        if(bundle!=null){
            enrollment = (EnrolledCoursesResponse) bundle
                    .getSerializable(BaseFragmentActivity.EXTRA_ENROLLMENT);
            if(enrollment!=null) {
                courseId = enrollment.getCourse().getId();
                try {
                    segIO.screenViewsTracking(enrollment.getCourse().getName()
                            + " - Courseware");
                } catch (Exception e) {
                    logger.error(e);
                }
            }
        }
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_chapter_list, container,
                false);

        //Initialize the Course not started text view.
        if (!enrollment.getCourse().isStarted()) {
            startDate = DateUtil.formatCourseNotStartedDate(enrollment.getCourse().getStart());
            if (startDate != null) {
                startDate = "<font color='" + getString(R.color.grey_text_course_not_started) + "'>" + startDate + "</font>";
                String courseScheduledText = getString(R.string.course_content_available_text);
                courseScheduledText = courseScheduledText.replace("START_DATE", startDate);
                courseScheduleTv = (ETextView) view.findViewById(R.id.course_content_available_tv);
                courseScheduleTv.setText(Html.fromHtml(courseScheduledText));
            }
        }

        ArrayList<SectionEntry> savedEntries = null;
        if (savedInstanceState != null) {

            try {
                savedEntries = (ArrayList<SectionEntry>) savedInstanceState.getSerializable(SECTION_ENTRIES);
                adapter.setItems(savedEntries);
            } catch (Exception ex) {
                logger.error(ex);
            }

        }

        chapterListView = (ListView) view
                .findViewById(R.id.chapter_list);

        initializeAdapter();
        chapterListView.setAdapter(adapter);
        chapterListView.setOnItemClickListener(adapter);
        lastClickTime = 0;

        return view;
    }

    @Override
    public void onStart() {
        super.onStart();
        isActivityStarted = true;
        adapter.setStore(db, storage);
        handler.sendEmptyMessage(MSG_UPDATE_PROGRESS);
        if(!adapter.isEmpty()){
            adapter.notifyDataSetChanged();
        }

        fetchLastAccessed(getView());
    }

    @Override
    public void onStop() {
        super.onStop();
        isActivityStarted = false;
{'fraction_non_alphanumeric': 0.09372503772077749, 'fraction_numerical': 0.0014200763291026893, 'mean_word_length': 3.240873165223937, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2407205', 'n_tokens_mistral': 3186, 'n_tokens_neox': 3053, 'n_words': 562}