<commit_before>package com.daviancorp.android.ui.detail;

import android.content.Context;
import android.content.res.AssetManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.daviancorp.android.data.classes.Monster;
import com.daviancorp.android.data.classes.MonsterAilment;
import com.daviancorp.android.data.classes.MonsterDamage;
import com.daviancorp.android.data.classes.MonsterWeakness;
import com.daviancorp.android.data.database.DataManager;
import com.daviancorp.android.data.database.MonsterAilmentCursor;
import com.daviancorp.android.loader.MonsterAilmentCursorLoader;
import com.daviancorp.android.loader.MonsterLoader;
import com.daviancorp.android.loader.MonsterWeaknessCursorLoader;
import com.daviancorp.android.mh4udatabase.R;

import org.apmem.tools.layouts.FlowLayout;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;

public class MonsterSummaryFragment extends Fragment {
	private static final String ARG_MONSTER_ID = "MONSTER_ID";

	private Bundle mBundle;

	private Monster mMonster;
	private MonsterWeakness mWeakness;

	private TextView mMonsterLabelTextView;
	private ImageView mMonsterIconImageView;

	// Sections to hold icons and text
	private FlowLayout mWeaknessData, mTrapData, mBombData;
	private LinearLayout mAilments;

	// Need to add dividers
    //private View mDividerView;

	public static MonsterSummaryFragment newInstance(long monsterId) {
		Bundle args = new Bundle();
		args.putLong(ARG_MONSTER_ID, monsterId);
		MonsterSummaryFragment f = new MonsterSummaryFragment();
		f.setArguments(args);
		return f;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setRetainInstance(true);

		// Check for a Monster ID as an argument, and find the monster
		Bundle args = getArguments();
		if (args != null) {
			long monsterId = args.getLong(ARG_MONSTER_ID, -1);
			if (monsterId != -1) {
				LoaderManager lm = getLoaderManager();
				lm.initLoader(R.id.monster_detail_fragment, args, new MonsterLoaderCallbacks());
			}
		}
	}

	@Override
	public void onResume() {
		super.onResume();
	}

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

		mMonsterLabelTextView = (TextView) view.findViewById(R.id.detail_monster_label);
		mMonsterIconImageView = (ImageView) view.findViewById(R.id.detail_monster_image);

		mWeaknessData = (FlowLayout) view.findViewById(R.id.weakness_data);
		mTrapData = (FlowLayout) view.findViewById(R.id.trap_data);
		mBombData = (FlowLayout) view.findViewById(R.id.bomb_data);
		mAilments = (LinearLayout) view.findViewById(R.id.ailments_data);

		return view;
	}

	private void updateUI() {

		LayoutInflater inflater = getLayoutInflater(mBundle);

		// Header
		String cellText = mMonster.getName();
		String cellImage = "icons_monster/" + mMonster.getFileLocation();

		mMonsterLabelTextView.setText(cellText);
        AssetManager manager = getActivity().getAssets();
        try {
            InputStream open = manager.open(cellImage);
            Bitmap bitmap = BitmapFactory.decodeStream(open);
            // Assign the bitmap to an ImageView in this layout
            mMonsterIconImageView.setImageBitmap(bitmap);
        } catch (IOException e) {
            e.printStackTrace();
        }

		updateWeaknessUI();

	}

	// Update weakness display after loader callback
	private void updateWeaknessUI(){
		// Weakness Section
		int fire, water, thunder, ice, dragon, poison, paralysis, sleep, pitfalltrap,
				shocktrap, flashbomb, sonicbomb, dungbomb, meat;


		// Load ArrayList of weaknesses without using a loader
		ArrayList<MonsterWeakness> weaknesses = DataManager.get(getActivity()).queryMonsterWeaknessArray(mMonster.getId());

		// Get "Normal" weakness. "Enraged" or "Charge" not yet supported
		mWeakness = weaknesses.get(0);

		// Fire
		evalWeakness(mWeakness.getFire(), mWeaknessData, getResources().getString(R.string.image_location_fire));
		// Water
		evalWeakness(mWeakness.getWater(), mWeaknessData, getResources().getString(R.string.image_location_water));
		// Thunder
		evalWeakness(mWeakness.getThunder(), mWeaknessData, getResources().getString(R.string.image_location_thunder));
		// Ice
		evalWeakness(mWeakness.getIce(), mWeaknessData, getResources().getString(R.string.image_location_ice));
		// Dragon
		evalWeakness(mWeakness.getDragon(), mWeaknessData, getResources().getString(R.string.image_location_dragon));
		// Poison
		evalWeakness(mWeakness.getPoison(), mWeaknessData, getResources().getString(R.string.image_location_poison));
		// Paralysis
		evalWeakness(mWeakness.getParalysis(), mWeaknessData, getResources().getString(R.string.image_location_paralysis));
		// Sleep
		evalWeakness(mWeakness.getSleep(), mWeaknessData, getResources().getString(R.string.image_location_sleep));

		// Pitfall Trap
		if(mWeakness.getPitfalltrap() != 0)
			addIcon(mTrapData, getResources().getString(R.string.image_location_pitfall_trap), null);
		// Shock Trap
		if(mWeakness.getShocktrap() != 0)
			addIcon(mTrapData, getResources().getString(R.string.image_location_shock_trap), null);

		// Flash Bomb
		if(mWeakness.getFlashbomb() != 0)
			addIcon(mBombData, getResources().getString(R.string.image_location_flash_bomb), null);
		// Sonic Bomb
		if(mWeakness.getSonicbomb() != 0)
			addIcon(mBombData, getResources().getString(R.string.image_location_sonic_bomb), null);
		// Dung Bomb
		if(mWeakness.getDungbomb() != 0)
			addIcon(mBombData, getResources().getString(R.string.image_location_dung_bomb), null);

		// Meat

	}

	private void evalWeakness(int weaknessvalue, FlowLayout parentview, String imagelocation){
		// Add icon and modifier to show effectiveness
		switch(weaknessvalue){
			case 1:
				addIcon(parentview, imagelocation, null);
				break;
			case 2:
				addIcon(parentview, imagelocation, getResources().getString(R.string.image_location_effectiveness_2));<commit_msg>Weakness to meat is now displayed in the Summary -> Traps section.<commit_after>package com.daviancorp.android.ui.detail;

import android.content.Context;
import android.content.res.AssetManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.daviancorp.android.data.classes.Monster;
import com.daviancorp.android.data.classes.MonsterAilment;
import com.daviancorp.android.data.classes.MonsterDamage;
import com.daviancorp.android.data.classes.MonsterWeakness;
import com.daviancorp.android.data.database.DataManager;
import com.daviancorp.android.data.database.MonsterAilmentCursor;
import com.daviancorp.android.loader.MonsterAilmentCursorLoader;
import com.daviancorp.android.loader.MonsterLoader;
import com.daviancorp.android.loader.MonsterWeaknessCursorLoader;
import com.daviancorp.android.mh4udatabase.R;

import org.apmem.tools.layouts.FlowLayout;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;

public class MonsterSummaryFragment extends Fragment {
	private static final String ARG_MONSTER_ID = "MONSTER_ID";

	private Bundle mBundle;

	private Monster mMonster;
	private MonsterWeakness mWeakness;

	private TextView mMonsterLabelTextView;
	private ImageView mMonsterIconImageView;

	// Sections to hold icons and text
	private FlowLayout mWeaknessData, mTrapData, mBombData;
	private LinearLayout mAilments;

	// Need to add dividers
    //private View mDividerView;

	public static MonsterSummaryFragment newInstance(long monsterId) {
		Bundle args = new Bundle();
		args.putLong(ARG_MONSTER_ID, monsterId);
		MonsterSummaryFragment f = new MonsterSummaryFragment();
		f.setArguments(args);
		return f;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setRetainInstance(true);

		// Check for a Monster ID as an argument, and find the monster
		Bundle args = getArguments();
		if (args != null) {
			long monsterId = args.getLong(ARG_MONSTER_ID, -1);
			if (monsterId != -1) {
				LoaderManager lm = getLoaderManager();
				lm.initLoader(R.id.monster_detail_fragment, args, new MonsterLoaderCallbacks());
			}
		}
	}

	@Override
	public void onResume() {
		super.onResume();
	}

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

		mMonsterLabelTextView = (TextView) view.findViewById(R.id.detail_monster_label);
		mMonsterIconImageView = (ImageView) view.findViewById(R.id.detail_monster_image);

		mWeaknessData = (FlowLayout) view.findViewById(R.id.weakness_data);
		mTrapData = (FlowLayout) view.findViewById(R.id.trap_data);
		mBombData = (FlowLayout) view.findViewById(R.id.bomb_data);
		mAilments = (LinearLayout) view.findViewById(R.id.ailments_data);

		return view;
	}

	private void updateUI() {

		LayoutInflater inflater = getLayoutInflater(mBundle);

		// Header
		String cellText = mMonster.getName();
		String cellImage = "icons_monster/" + mMonster.getFileLocation();

		mMonsterLabelTextView.setText(cellText);
        AssetManager manager = getActivity().getAssets();
        try {
            InputStream open = manager.open(cellImage);
            Bitmap bitmap = BitmapFactory.decodeStream(open);
            // Assign the bitmap to an ImageView in this layout
            mMonsterIconImageView.setImageBitmap(bitmap);
        } catch (IOException e) {
            e.printStackTrace();
        }

		updateWeaknessUI();

	}

	// Update weakness display after loader callback
	private void updateWeaknessUI(){
		// Weakness Section
		int fire, water, thunder, ice, dragon, poison, paralysis, sleep, pitfalltrap,
				shocktrap, flashbomb, sonicbomb, dungbomb, meat;


		// Load ArrayList of weaknesses without using a loader
		ArrayList<MonsterWeakness> weaknesses = DataManager.get(getActivity()).queryMonsterWeaknessArray(mMonster.getId());

		// Get "Normal" weakness. "Enraged" or "Charge" not yet supported
		mWeakness = weaknesses.get(0);

		// Fire
		evalWeakness(mWeakness.getFire(), mWeaknessData, getResources().getString(R.string.image_location_fire));
		// Water
		evalWeakness(mWeakness.getWater(), mWeaknessData, getResources().getString(R.string.image_location_water));
		// Thunder
		evalWeakness(mWeakness.getThunder(), mWeaknessData, getResources().getString(R.string.image_location_thunder));
		// Ice
		evalWeakness(mWeakness.getIce(), mWeaknessData, getResources().getString(R.string.image_location_ice));
		// Dragon
		evalWeakness(mWeakness.getDragon(), mWeaknessData, getResources().getString(R.string.image_location_dragon));
		// Poison
		evalWeakness(mWeakness.getPoison(), mWeaknessData, getResources().getString(R.string.image_location_poison));
		// Paralysis
		evalWeakness(mWeakness.getParalysis(), mWeaknessData, getResources().getString(R.string.image_location_paralysis));
		// Sleep
		evalWeakness(mWeakness.getSleep(), mWeaknessData, getResources().getString(R.string.image_location_sleep));

		// Pitfall Trap
		if(mWeakness.getPitfalltrap() != 0)
			addIcon(mTrapData, getResources().getString(R.string.image_location_pitfall_trap), null);
		// Shock Trap
		if(mWeakness.getShocktrap() != 0)
			addIcon(mTrapData, getResources().getString(R.string.image_location_shock_trap), null);
		// Meat
		if(mWeakness.getMeat() != 0)
			addIcon(mTrapData, getResources().getString(R.string.image_location_meat), null);

		// Flash Bomb
		if(mWeakness.getFlashbomb() != 0)
			addIcon(mBombData, getResources().getString(R.string.image_location_flash_bomb), null);
		// Sonic Bomb
		if(mWeakness.getSonicbomb() != 0)
			addIcon(mBombData, getResources().getString(R.string.image_location_sonic_bomb), null);
		// Dung Bomb
		if(mWeakness.getDungbomb() != 0)
			addIcon(mBombData, getResources().getString(R.string.image_location_dung_bomb), null);

	}

	private void evalWeakness(int weaknessvalue, FlowLayout parentview, String imagelocation){
		// Add icon and modifier to show effectiveness
		switch(weaknessvalue){
			case 1:
				addIcon(parentview, imagelocation, null);
				break;
			case 2:
				addIcon(parentview, imagelocation, getResources().getString(R.string.image_location_effectiveness_2));
{'fraction_non_alphanumeric': 0.10781226570700254, 'fraction_numerical': 0.0024741340530814214, 'mean_word_length': 5.204186046511628, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '3231263', 'n_tokens_mistral': 4609, 'n_tokens_neox': 4068, 'n_words': 798}