<commit_before>package in.vshukla.thed.activities;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

import hugo.weaving.DebugLog;
import in.vshukla.thed.R;
import in.vshukla.thed.models.Article;
import in.vshukla.thed.utils.AppConstants;

import static in.vshukla.thed.utils.AppUtils.getDateDiffString;

public class MainActivity extends Activity {

    private static final String TAG = "MainActivity";

    private RecyclerView recyclerView;
    private LinearLayoutManager linearLayoutManager;

    private SharedPreferences prefs;

    private FirebaseDatabase firebaseDatabase;
    private DatabaseReference firebaseDatabaseReference;
    private FirebaseRecyclerAdapter<Article, ArticleViewHolder> firebaseAdapter;
    private ChildEventListener childEventListener;

    static class ArticleViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        TextView tvDate, tvKind, tvTitle, tvAuthor, tvKey;
        Article article;
        Context context;

        ArticleViewHolder(View itemView) {
            super(itemView);
            tvAuthor = (TextView) itemView.findViewById(R.id.tv_list_author);
            tvDate = (TextView) itemView.findViewById(R.id.tv_list_date);
            tvKind = (TextView) itemView.findViewById(R.id.tv_list_kind);
            tvKey = (TextView) itemView.findViewById(R.id.tv_list_key);
            tvTitle = (TextView) itemView.findViewById(R.id.tv_list_title);
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            Intent readerActivityIntent = new Intent(context, ReaderActivity.class);
            Bundle extras = new Bundle();
            extras.putSerializable(AppConstants.EXTRAS_ARTICLE, article);
            readerActivityIntent.putExtras(extras);
            context.startActivity(readerActivityIntent);
        }
    }

    @Override
    @DebugLog
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler_list);

        // Initialise the shared preferences
        prefs = getSharedPreferences(getString(R.string.pref_file_key), Context.MODE_PRIVATE);

        // Initialize firebase database
        firebaseDatabase = FirebaseDatabase.getInstance();
        firebaseDatabaseReference = firebaseDatabase.getReference();

        // Populate the recycler list view
        recyclerView = (RecyclerView) findViewById(R.id.list_recycle_parent);
        setUpRecyclerView();

    }

    @DebugLog
    private void setUpRecyclerView() {
        firebaseAdapter = new FirebaseRecyclerAdapter<Article, ArticleViewHolder>(
                Article.class,
                R.layout.article_list_item,
                ArticleViewHolder.class,
                firebaseDatabaseReference.child(AppConstants.DB_FEED_NEWSFEED)
        ) {
            @DebugLog
            @Override
            protected void populateViewHolder(ArticleViewHolder holder, Article article, int position) {
                holder.tvAuthor.setText(article.getAuthor());
                holder.tvKind.setText(article.getCategory());
                holder.tvKey.setText(article.getId());
                holder.tvTitle.setText(article.getTitle());
                holder.tvDate.setText(getDateDiffString(article.getPublishedDate()));<commit_msg>For offline storage of data, enabled persistence<commit_after>package in.vshukla.thed.activities;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

import hugo.weaving.DebugLog;
import in.vshukla.thed.R;
import in.vshukla.thed.models.Article;
import in.vshukla.thed.utils.AppConstants;

import static in.vshukla.thed.utils.AppUtils.getDateDiffString;

public class MainActivity extends Activity {

    private static final String TAG = "MainActivity";

    private RecyclerView recyclerView;
    private LinearLayoutManager linearLayoutManager;

    private SharedPreferences prefs;

    private FirebaseDatabase firebaseDatabase;
    private DatabaseReference firebaseDatabaseReference;
    private FirebaseRecyclerAdapter<Article, ArticleViewHolder> firebaseAdapter;
    private ChildEventListener childEventListener;

    static class ArticleViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        TextView tvDate, tvKind, tvTitle, tvAuthor, tvKey;
        Article article;
        Context context;

        ArticleViewHolder(View itemView) {
            super(itemView);
            tvAuthor = (TextView) itemView.findViewById(R.id.tv_list_author);
            tvDate = (TextView) itemView.findViewById(R.id.tv_list_date);
            tvKind = (TextView) itemView.findViewById(R.id.tv_list_kind);
            tvKey = (TextView) itemView.findViewById(R.id.tv_list_key);
            tvTitle = (TextView) itemView.findViewById(R.id.tv_list_title);
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            Intent readerActivityIntent = new Intent(context, ReaderActivity.class);
            Bundle extras = new Bundle();
            extras.putSerializable(AppConstants.EXTRAS_ARTICLE, article);
            readerActivityIntent.putExtras(extras);
            context.startActivity(readerActivityIntent);
        }
    }

    @Override
    @DebugLog
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler_list);

        // Initialise the shared preferences
        prefs = getSharedPreferences(getString(R.string.pref_file_key), Context.MODE_PRIVATE);

        // Initialize firebase database
        firebaseDatabase = FirebaseDatabase.getInstance();
        firebaseDatabase.setPersistenceEnabled(true);
        firebaseDatabaseReference = firebaseDatabase.getReference();

        // Populate the recycler list view
        recyclerView = (RecyclerView) findViewById(R.id.list_recycle_parent);
        setUpRecyclerView();

    }

    @DebugLog
    private void setUpRecyclerView() {
        firebaseAdapter = new FirebaseRecyclerAdapter<Article, ArticleViewHolder>(
                Article.class,
                R.layout.article_list_item,
                ArticleViewHolder.class,
                firebaseDatabaseReference.child(AppConstants.DB_FEED_NEWSFEED)
        ) {
            @DebugLog
            @Override
            protected void populateViewHolder(ArticleViewHolder holder, Article article, int position) {
                holder.tvAuthor.setText(article.getAuthor());
                holder.tvKind.setText(article.getCategory());
                holder.tvKey.setText(article.getId());
                holder.tvTitle.setText(article.getTitle());
                holder.tvDate.setText(getDateDiffString(article.getPublishedDate()));
{'fraction_non_alphanumeric': 0.0821280342095334, 'fraction_numerical': 0.0005030813734121495, 'mean_word_length': 3.3287969515514426, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6742487', 'n_tokens_mistral': 2159, 'n_tokens_neox': 2044, 'n_words': 386}