<commit_before>package com.monstarlab.servicedroid.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;

import com.monstarlab.servicedroid.R;
import com.monstarlab.servicedroid.model.Models.BibleStudies;
import com.monstarlab.servicedroid.model.Models.Calls;
import com.monstarlab.servicedroid.model.Models.Literature;
import com.monstarlab.servicedroid.model.Models.Placements;
import com.monstarlab.servicedroid.model.Models.ReturnVisits;
import com.monstarlab.servicedroid.util.Changelog;
import com.monstarlab.servicedroid.util.TimeUtil;

public class RVShowActivity extends Activity implements OnItemClickListener {
	
	private static final String TAG = "RVShowActivity";
	
	private static final int MENU_EDIT = Menu.FIRST;
	private static final int MENU_PLACEMENT = Menu.FIRST + 1;
	private static final int MENU_RETURN = Menu.FIRST + 2;
	private static final int MENU_STUDY = Menu.FIRST + 3;
	
	
	private static final String[] PROJECTION = new String[] { Calls._ID, Calls.NAME, Calls.ADDRESS, Calls.NOTES, Calls.DATE };
	private static final String[] BIBLE_STUDY_PROJECTION = new String[] { BibleStudies._ID, BibleStudies.DATE_START, BibleStudies.DATE_END, BibleStudies.CALL_ID };
	private static final String[] PLACEMENTS_PROJECTION = new String[] { Placements._ID, Placements.LITERATURE_ID, Placements.CALL_ID, Literature.PUBLICATION, Placements.DATE };
	private static final int ID_COLUMN = 0;
	private static final int NAME_COLUMN = 1;
	private static final int ADDRESS_COLUMN = 2;
	private static final int NOTES_COLUMN = 3; 
	private static final int DATE_COLUMN = 4;

	private static final int DIALOG_PLACEMENT_ID = 0;
	private static final int DIALOG_BIBLESTUDYDELETE_ID = 1;

	private static final int EDIT_ID = 0;
	private static final int DELETE_ID = 1;

	
	
	private Uri mUri;
	private TextView mNameText;
	private TextView mAddressText;
	private TextView mLastVisitText;
	private TextView mNotesText;
	private Cursor mCursor;
	private TimeUtil mTimeHelper;
	private CheckBox mBibleStudyCheckbox;

	private ListView mListView;

	private Cursor mPlacementsCursor;

	//private ListView mListView;
	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		final Intent intent = getIntent();
		//final String action = intent.getAction();
		mUri = intent.getData();
		
		
		setContentView(R.layout.call_show);
		
		mNameText = (TextView) findViewById(R.id.name);
		mAddressText = (TextView) findViewById(R.id.address);
		mLastVisitText = (TextView) findViewById(R.id.lastVisit);
		mNotesText = (TextView) findViewById(R.id.notes);
		

		
		mListView = (ListView) findViewById(R.id.placements_list);
		mListView.setEmptyView((TextView) findViewById(android.R.id.empty));
        mListView.setOnCreateContextMenuListener(this);
        mListView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY);
        mListView.setOnItemClickListener(this);
		
		mBibleStudyCheckbox = (CheckBox) findViewById(R.id.is_bible_study);
		mBibleStudyCheckbox.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				updateStudyStatus(((CheckBox)v).isChecked());
			}
		});
		
		mTimeHelper = new TimeUtil(this);
		
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		
		refreshCallData();
		refreshPlacementList();
		
	}
	
	private void refreshCallData() {
		mCursor = managedQuery(mUri, PROJECTION, null, null, null);
		if(mCursor != null) {
			mCursor.moveToFirst();
			
			String name = mCursor.getString(NAME_COLUMN);
			String address = mCursor.getString(ADDRESS_COLUMN);
			String notes = mCursor.getString(NOTES_COLUMN);
			boolean isBibleStudy = isBibleStudy();
			
			updateLastVisited();
			
			
			mNameText.setText(name);
			mAddressText.setText(address);
			mNotesText.setText(notes);
			mBibleStudyCheckbox.setChecked(isBibleStudy);
		}
	}
	
	private boolean isBibleStudy() {
		boolean isStudy = false;
		
		if(mUri != null) {
			Cursor c = getCurrentBibleStudyCursor();
			if(c.getCount() > 0) {
				//if we got results, then there is a bible study
				isStudy = true;<commit_msg>bug fix for when RV cursor doesnt return results, dont FC<commit_after>package com.monstarlab.servicedroid.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;

import com.monstarlab.servicedroid.R;
import com.monstarlab.servicedroid.model.Models.BibleStudies;
import com.monstarlab.servicedroid.model.Models.Calls;
import com.monstarlab.servicedroid.model.Models.Literature;
import com.monstarlab.servicedroid.model.Models.Placements;
import com.monstarlab.servicedroid.model.Models.ReturnVisits;
import com.monstarlab.servicedroid.util.Changelog;
import com.monstarlab.servicedroid.util.TimeUtil;

public class RVShowActivity extends Activity implements OnItemClickListener {
	
	private static final String TAG = "RVShowActivity";
	
	private static final int MENU_EDIT = Menu.FIRST;
	private static final int MENU_PLACEMENT = Menu.FIRST + 1;
	private static final int MENU_RETURN = Menu.FIRST + 2;
	private static final int MENU_STUDY = Menu.FIRST + 3;
	
	
	private static final String[] PROJECTION = new String[] { Calls._ID, Calls.NAME, Calls.ADDRESS, Calls.NOTES, Calls.DATE };
	private static final String[] BIBLE_STUDY_PROJECTION = new String[] { BibleStudies._ID, BibleStudies.DATE_START, BibleStudies.DATE_END, BibleStudies.CALL_ID };
	private static final String[] PLACEMENTS_PROJECTION = new String[] { Placements._ID, Placements.LITERATURE_ID, Placements.CALL_ID, Literature.PUBLICATION, Placements.DATE };
	private static final int ID_COLUMN = 0;
	private static final int NAME_COLUMN = 1;
	private static final int ADDRESS_COLUMN = 2;
	private static final int NOTES_COLUMN = 3; 
	private static final int DATE_COLUMN = 4;

	private static final int DIALOG_PLACEMENT_ID = 0;
	private static final int DIALOG_BIBLESTUDYDELETE_ID = 1;

	private static final int EDIT_ID = 0;
	private static final int DELETE_ID = 1;

	
	
	private Uri mUri;
	private TextView mNameText;
	private TextView mAddressText;
	private TextView mLastVisitText;
	private TextView mNotesText;
	private Cursor mCursor;
	private TimeUtil mTimeHelper;
	private CheckBox mBibleStudyCheckbox;

	private ListView mListView;

	private Cursor mPlacementsCursor;

	//private ListView mListView;
	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		final Intent intent = getIntent();
		//final String action = intent.getAction();
		mUri = intent.getData();
		
		
		setContentView(R.layout.call_show);
		
		mNameText = (TextView) findViewById(R.id.name);
		mAddressText = (TextView) findViewById(R.id.address);
		mLastVisitText = (TextView) findViewById(R.id.lastVisit);
		mNotesText = (TextView) findViewById(R.id.notes);
		

		
		mListView = (ListView) findViewById(R.id.placements_list);
		mListView.setEmptyView((TextView) findViewById(android.R.id.empty));
        mListView.setOnCreateContextMenuListener(this);
        mListView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY);
        mListView.setOnItemClickListener(this);
		
		mBibleStudyCheckbox = (CheckBox) findViewById(R.id.is_bible_study);
		mBibleStudyCheckbox.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				updateStudyStatus(((CheckBox)v).isChecked());
			}
		});
		
		mTimeHelper = new TimeUtil(this);
		
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		
		refreshCallData();
		refreshPlacementList();
		
	}
	
	private void refreshCallData() {
		mCursor = managedQuery(mUri, PROJECTION, null, null, null);
		if(mCursor != null) {
			if(mCursor.getCount() == 1) {
			
				mCursor.moveToFirst();
				
				String name = mCursor.getString(NAME_COLUMN);
				String address = mCursor.getString(ADDRESS_COLUMN);
				String notes = mCursor.getString(NOTES_COLUMN);
				boolean isBibleStudy = isBibleStudy();
				
				updateLastVisited();
				
				
				mNameText.setText(name);
				mAddressText.setText(address);
				mNotesText.setText(notes);
				mBibleStudyCheckbox.setChecked(isBibleStudy);
			} else {
				finish();
			}
		}
	}
	
	private boolean isBibleStudy() {
		boolean isStudy = false;
		
		if(mUri != null) {
			Cursor c = getCurrentBibleStudyCursor();
			if(c.getCount() > 0) {
				//if we got results, then there is a bible study
				isStudy = true;
{'fraction_non_alphanumeric': 0.09392977583812735, 'fraction_numerical': 0.0026780400714144018, 'mean_word_length': 4.966272189349112, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6742005', 'n_tokens_mistral': 3536, 'n_tokens_neox': 3075, 'n_words': 705}