<commit_before>/*
 * [Nayati] ItemDetailActivityFragment.java
 *
 * Implements fragment to view detailed information for an item being tracked.
 *
 * (c) 2015 <NAME> (<EMAIL>)
 *
 * SPDX-License-Identifier: BSD-3-Clause
 *                          (http://spdx.org/licenses/BSD-3-Clause.html)
 *
 */


package self.premi.sanjeev.nayati;

import android.content.Context;
import android.content.DialogInterface;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

import self.premi.sanjeev.nayati.db.DaoTrackInfo;
import self.premi.sanjeev.nayati.db.DaoTrackItem;
import self.premi.sanjeev.nayati.db.DbConst;
import self.premi.sanjeev.nayati.model.TrackInfo;
import self.premi.sanjeev.nayati.model.TrackItem;


/**
 * Fragment to view detailed information for an item being tracked.
 */
public class ItemDetailActivityFragment extends Fragment {

    /**
     * Recycler view for the activity.
     */
    private RecyclerView rv = null;

    /**
     * Linear layout manager for the recycler view
     */
    LinearLayoutManager llm = null;

    /**
     * Adapter for recycler view
     */
    private ItemDetailRvAdapter rva = null;

    /**
     * Tracking number of the item
     */
    private String trackNum;

    /**
     * DAO for items being tracked
     */
    private DaoTrackItem daoTrackItem = null;

    /**
     * DAO for tracking information for an item
     */
    private DaoTrackInfo daoTrackInfo = null;

    /**
     * Items being tracked
     */
    private TrackItem item = null;

    /**
     * Tracking information related to the item
     */
    private List<TrackInfo> info = null;

    /**
     * Text view - Tracking number
     */
    private TextView textTrackNum = null;

    /**
     * Text view - Item Name
     */
    private TextView textItemName = null;


    public ItemDetailActivityFragment() {
        setHasOptionsMenu(true);
    }

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

        if (llm == null) {
            llm = new LinearLayoutManager(getActivity());

            llm.setOrientation(LinearLayoutManager.VERTICAL);
        }

        if (rv == null) {
            rv = (RecyclerView) v.findViewById(R.id.rv_item_detail);

            rv.setHasFixedSize(true);
        }

        //
        // Fetch item from database
        //
        if (daoTrackItem == null) {
            daoTrackItem = new DaoTrackItem(getContext());
        }

        daoTrackItem.open(DbConst.RO_MODE);
        item = daoTrackItem.get(trackNum);
        daoTrackItem.close();

        //
        // Read tracking information related to 'item' from database
        //
        if (daoTrackInfo == null) {
            daoTrackInfo = new DaoTrackInfo(getContext());
        }

        daoTrackInfo.open(DbConst.RO_MODE);

        info = daoTrackInfo.list(item.getId());

        daoTrackInfo.close();

        rva = new ItemDetailRvAdapter(info);

        rv.setAdapter(rva);
        rv.setLayoutManager(llm);

        textTrackNum = (TextView) v.findViewById(R.id.item_detail_text_track_num);
        textItemName = (TextView) v.findViewById(R.id.item_detail_text_track_name);

        textTrackNum.setText(trackNum);
        textItemName.setText(item.getName());

        return v;
    }


    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

        trackNum = ((ItemDetailActivity) getActivity()).getTrackNum();<commit_msg>activity: item-detail: fragment: Show service logo<commit_after>/*
 * [Nayati] ItemDetailActivityFragment.java
 *
 * Implements fragment to view detailed information for an item being tracked.
 *
 * (c) 2015 <NAME> (<EMAIL>)
 *
 * SPDX-License-Identifier: BSD-3-Clause
 *                          (http://spdx.org/licenses/BSD-3-Clause.html)
 *
 */


package self.premi.sanjeev.nayati;

import android.content.Context;
import android.content.DialogInterface;
import android.media.Image;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

import self.premi.sanjeev.nayati.db.DaoTrackInfo;
import self.premi.sanjeev.nayati.db.DaoTrackItem;
import self.premi.sanjeev.nayati.db.DbConst;
import self.premi.sanjeev.nayati.model.TrackInfo;
import self.premi.sanjeev.nayati.model.TrackItem;
import self.premi.sanjeev.nayati.model.TrackNum;


/**
 * Fragment to view detailed information for an item being tracked.
 */
public class ItemDetailActivityFragment extends Fragment {

    /**
     * Recycler view for the activity.
     */
    private RecyclerView rv = null;

    /**
     * Linear layout manager for the recycler view
     */
    LinearLayoutManager llm = null;

    /**
     * Adapter for recycler view
     */
    private ItemDetailRvAdapter rva = null;

    /**
     * Tracking number of the item
     */
    private String trackNum;

    /**
     * DAO for items being tracked
     */
    private DaoTrackItem daoTrackItem = null;

    /**
     * DAO for tracking information for an item
     */
    private DaoTrackInfo daoTrackInfo = null;

    /**
     * Items being tracked
     */
    private TrackItem item = null;

    /**
     * Tracking information related to the item
     */
    private List<TrackInfo> info = null;

    /**
     * Text view - Tracking number
     */
    private TextView textTrackNum = null;

    /**
     * Text view - Item Name
     */
    private TextView textItemName = null;

    /**
     * Image view - Mail service logo
     */
    private ImageView logoSvc = null;


    public ItemDetailActivityFragment() {
        setHasOptionsMenu(true);
    }

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

        if (llm == null) {
            llm = new LinearLayoutManager(getActivity());

            llm.setOrientation(LinearLayoutManager.VERTICAL);
        }

        if (rv == null) {
            rv = (RecyclerView) v.findViewById(R.id.rv_item_detail);

            rv.setHasFixedSize(true);
        }

        //
        // Fetch item from database
        //
        if (daoTrackItem == null) {
            daoTrackItem = new DaoTrackItem(getContext());
        }

        daoTrackItem.open(DbConst.RO_MODE);
        item = daoTrackItem.get(trackNum);
        daoTrackItem.close();

        //
        // Read tracking information related to 'item' from database
        //
        if (daoTrackInfo == null) {
            daoTrackInfo = new DaoTrackInfo(getContext());
        }

        daoTrackInfo.open(DbConst.RO_MODE);

        info = daoTrackInfo.list(item.getId());

        daoTrackInfo.close();

        rva = new ItemDetailRvAdapter(info);

        rv.setAdapter(rva);
        rv.setLayoutManager(llm);

        textTrackNum = (TextView) v.findViewById(R.id.item_detail_text_track_num);
        textItemName = (TextView) v.findViewById(R.id.item_detail_text_track_name);

        textTrackNum.setText(trackNum);
        textItemName.setText(item.getName());

        logoSvc = (ImageView) v.findViewById(R.id.item_detail_image_post);

        TrackNum t = new TrackNum(trackNum);

        switch (t.identify()) {
            case TrackNum.F_EMS:
                logoSvc.setImageResource(R.drawable.logo_ems);
                break;

            case TrackNum.F_REG:
                logoSvc.setImageResource(R.drawable.logo_reg);
                break;

            case TrackNum.F_EPP:
                logoSvc.setImageResource(R.drawable.logo_epp);
                break;

            case TrackNum.F_EMO:
                logoSvc.setImageResource(R.drawable.logo_emo);
                break;

            default:
        }

        return v;
    }


    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

        trackNum = ((ItemDetailActivity) getActivity()).getTrackNum();
{'fraction_non_alphanumeric': 0.10208768267223382, 'fraction_numerical': 0.0020876826722338203, 'mean_word_length': 2.5577422948384703, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '681464', 'n_tokens_mistral': 2939, 'n_tokens_neox': 2781, 'n_words': 595}