<commit_before>package ualberta.g12.adventurecreator.views;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import ualberta.g12.adventurecreator.R;
import ualberta.g12.adventurecreator.controllers.FragmentController;
import ualberta.g12.adventurecreator.data.AdventureCreator;
import ualberta.g12.adventurecreator.data.Fragment;

/**
 * Activity for viewing a fragment.  User can follow choices and will
 * be taken to the next fragment.
 */
public class FragmentViewActivity extends Activity implements FView<Fragment> {

    private TextView fragmentTitleTextView;
    private ListView fragmentPartListView;
    private FragmentPartAdapter adapter;
    private FragmentController fragmentController;
    //private static final String TAG = "FragmentViewActivity";
    private Fragment fragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment_viewer);

        fragmentController = AdventureCreator.getFragmentController();
        
        // obtain the intent
        Intent viewFragIntent = getIntent();
        fragment = (Fragment) viewFragIntent.getSerializableExtra("Fragment");
        
        // get widget references
        fragmentPartListView = (ListView) findViewById(R.id.fragmentViewPartList);
        fragmentTitleTextView = (TextView) findViewById(R.id.fragmentTitleText);

        setListClickListener();
    }

    @Override
    protected void onStart() {
        super.onStart();

        // TODO: This should be in its own method

        // First load fragment parts as that is the same for both modes
        // Loads fragment parts (text, images, videos, sounds, etc)
        adapter = new FragmentPartAdapter(this, R.layout.activity_fragment_editor, fragment);
        fragmentPartListView.setAdapter(adapter);


        // Loads title
        if (fragmentTitleTextView != null) 
            fragmentTitleTextView.setText(fragment.getTitle());
   }

    @Override
    public void update(Fragment model) {
        // TODO reload all fields based on new info from model

    }

    private void setListClickListener() {
        fragmentPartListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                Fragment goToFrag = fragmentController.getLinkedToFragmentOfChoice(fragment, position);
                
                if (goToFrag != null){
                    Intent intent = new Intent(FragmentViewActivity.this, FragmentViewActivity.class);
                    intent.putExtra("Fragment", goToFrag);
                    startActivity(intent);
                    //finish();
                }
            }
        });
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
            ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);<commit_msg>Changed the way FragmentViewActivity works.  Rather than starting a new FragmentViewActivity after each choice selection the fragment that is being displayed is simply swapped out and view is updated.<commit_after>package ualberta.g12.adventurecreator.views;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import ualberta.g12.adventurecreator.R;
import ualberta.g12.adventurecreator.controllers.FragmentController;
import ualberta.g12.adventurecreator.data.AdventureCreator;
import ualberta.g12.adventurecreator.data.Fragment;

/**
 * Activity for viewing a fragment.  User can follow choices and will
 * be taken to the next fragment.
 */
public class FragmentViewActivity extends Activity implements FView<Fragment> {

    private TextView fragmentTitleTextView;
    private ListView fragmentPartListView;
    private FragmentPartAdapter adapter;
    private FragmentController fragmentController;
    //private static final String TAG = "FragmentViewActivity";
    private Fragment fragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment_viewer);

        fragmentController = AdventureCreator.getFragmentController();
        
        // obtain the intent
        Intent viewFragIntent = getIntent();
        fragment = (Fragment) viewFragIntent.getSerializableExtra("Fragment");
        
        // get widget references
        fragmentPartListView = (ListView) findViewById(R.id.fragmentViewPartList);
        fragmentTitleTextView = (TextView) findViewById(R.id.fragmentTitleText);

        setListClickListener();
    }

    @Override
    protected void onStart() {
        super.onStart();    
        update();
   }

    @Override
    public void update(Fragment model) {
        // TODO reload all fields based on new info from model
        update();
    }
    
    private void update() {
        // TODO reload all fields based on new info from model
        
        // Loads title
        if (fragmentTitleTextView != null) 
            fragmentTitleTextView.setText(fragment.getTitle());
        
        // Loads fragment parts (text, images, videos, sounds, etc)
        adapter = new FragmentPartAdapter(this, R.layout.activity_fragment_editor, fragment);
        fragmentPartListView.setAdapter(adapter);
    }

    private void setListClickListener() {
        fragmentPartListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                Fragment goToFrag = fragmentController.getLinkedToFragmentOfChoice(fragment, position);
                
                if (goToFrag != null){
                    fragment = goToFrag;
                    update();
                }
            }
        });
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
            ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
{'fraction_non_alphanumeric': 0.07696951403561726, 'fraction_numerical': 0.003018412315122246, 'mean_word_length': 2.9945750452079567, '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': '532609', 'n_tokens_mistral': 1713, 'n_tokens_neox': 1615, 'n_words': 430}