diff --git a/Assignments/CriminalIntent13/.idea/.gitignore b/Assignments/CriminalIntent13/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/Assignments/CriminalIntent13/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/Assignments/CriminalIntent13/.idea/appInsightsSettings.xml b/Assignments/CriminalIntent13/.idea/appInsightsSettings.xml
new file mode 100644
index 0000000..371f2e2
--- /dev/null
+++ b/Assignments/CriminalIntent13/.idea/appInsightsSettings.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Assignments/CriminalIntent13/.idea/compiler.xml b/Assignments/CriminalIntent13/.idea/compiler.xml
new file mode 100644
index 0000000..b589d56
--- /dev/null
+++ b/Assignments/CriminalIntent13/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Assignments/CriminalIntent13/.idea/deploymentTargetDropDown.xml b/Assignments/CriminalIntent13/.idea/deploymentTargetDropDown.xml
new file mode 100644
index 0000000..0c0c338
--- /dev/null
+++ b/Assignments/CriminalIntent13/.idea/deploymentTargetDropDown.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Assignments/CriminalIntent13/.idea/discord.xml b/Assignments/CriminalIntent13/.idea/discord.xml
new file mode 100644
index 0000000..30bab2a
--- /dev/null
+++ b/Assignments/CriminalIntent13/.idea/discord.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Assignments/CriminalIntent13/.idea/gradle.xml b/Assignments/CriminalIntent13/.idea/gradle.xml
new file mode 100644
index 0000000..0897082
--- /dev/null
+++ b/Assignments/CriminalIntent13/.idea/gradle.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Assignments/CriminalIntent13/.idea/migrations.xml b/Assignments/CriminalIntent13/.idea/migrations.xml
new file mode 100644
index 0000000..f8051a6
--- /dev/null
+++ b/Assignments/CriminalIntent13/.idea/migrations.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Assignments/CriminalIntent13/.idea/misc.xml b/Assignments/CriminalIntent13/.idea/misc.xml
new file mode 100644
index 0000000..0ad17cb
--- /dev/null
+++ b/Assignments/CriminalIntent13/.idea/misc.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Assignments/CriminalIntent13/.idea/vcs.xml b/Assignments/CriminalIntent13/.idea/vcs.xml
new file mode 100644
index 0000000..b2bdec2
--- /dev/null
+++ b/Assignments/CriminalIntent13/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Assignments/CriminalIntent13/app/src/main/java/asdv/lisset/criminalintent/CrimeLab.java b/Assignments/CriminalIntent13/app/src/main/java/asdv/lisset/criminalintent/CrimeLab.java
index ea4ae3c..9143cfd 100644
--- a/Assignments/CriminalIntent13/app/src/main/java/asdv/lisset/criminalintent/CrimeLab.java
+++ b/Assignments/CriminalIntent13/app/src/main/java/asdv/lisset/criminalintent/CrimeLab.java
@@ -15,7 +15,6 @@ import asdv.lisset.criminalintent.database.CrimeDbSchema;
public class CrimeLab {
private static CrimeLab crimeLab;
- private List crimes;
private Context mContext;
private SQLiteDatabase mDatabase;
public static CrimeLab get(Context context) {
@@ -58,11 +57,11 @@ public class CrimeLab {
if (cursor.getCount() == 0) {
return null;
}
+ cursor.moveToFirst();
+ return cursor.getCrime();
} finally {
cursor.close();
}
- cursor.moveToFirst();
- return cursor.getCrime();
}
public void updateCrime(Crime crime) {
@@ -97,4 +96,8 @@ public class CrimeLab {
crime.isSolved() ? 1 : 0);
return values;
}
+
+ public void deleteCrime(Crime crime) {
+ mDatabase.delete(CrimeDbSchema.CrimeTable.NAME, "uuid = ?", new String[]{String.valueOf(crime.getId())});
+ }
}
diff --git a/Assignments/CriminalIntent13/app/src/main/java/asdv/lisset/criminalintent/CrimeListFragment.java b/Assignments/CriminalIntent13/app/src/main/java/asdv/lisset/criminalintent/CrimeListFragment.java
index 0c6036f..77cdfcf 100644
--- a/Assignments/CriminalIntent13/app/src/main/java/asdv/lisset/criminalintent/CrimeListFragment.java
+++ b/Assignments/CriminalIntent13/app/src/main/java/asdv/lisset/criminalintent/CrimeListFragment.java
@@ -1,6 +1,9 @@
package asdv.lisset.criminalintent;
+import android.content.Context;
+import android.content.DialogInterface;
import android.content.Intent;
+import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.Layout;
import android.view.LayoutInflater;
@@ -14,17 +17,38 @@ import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
+import androidx.appcompat.app.ActionBar;
+import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
+import java.util.Objects;
public class CrimeListFragment extends Fragment {
private RecyclerView crimeRecyclerView;
private CrimeAdapter adapter;
- private boolean subtitleVisible;
+ private boolean subtitleVisible = true;
+ private Context context;
+ private boolean inDeleteMode;
+ private void showConfirmationDialog(Crime crime) {
+ AlertDialog confirmDialog = new AlertDialog.Builder(requireContext())
+ .setTitle("Title")
+ .setMessage("Do you really want to delete this crime?")
+ .setIcon(android.R.drawable.ic_dialog_alert)
+ .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
+ // Delete the crime
+ CrimeLab.get(requireContext()).deleteCrime(crime);
+ updateUI(); // Update the UI after deletion
+ }
+ })
+ .setNegativeButton(android.R.string.no, null)
+ .show();
+ }
private static final String SAVED_SUBTITLE_VISIBLE = "subtitle";
@@ -66,6 +90,7 @@ public class CrimeListFragment extends Fragment {
View view =
inflater.inflate(R.layout.fragment_crime_list,
container, false);
+ context = requireContext();
crimeRecyclerView = (RecyclerView) view
.findViewById(R.id.crime_recycler_view);
crimeRecyclerView.setLayoutManager(
@@ -100,6 +125,8 @@ public class CrimeListFragment extends Fragment {
private TextView titleTextView;
private TextView dateTextView;
private ImageView solvedImageView;
+ private Context context;
+
public void bind(Crime crime){
this.crime = crime;
titleTextView.setText(this.crime.getTitle());
@@ -113,28 +140,27 @@ public class CrimeListFragment extends Fragment {
dateTextView = itemView.findViewById(R.id.crime_date);
solvedImageView =itemView.findViewById(R.id.imageView_green_cross);
}
-
@Override
public void onClick(View v) {
- //CHAPTER10
-// Intent intent = CrimeActivity.newIntent(getActivity(),
-// crime.getId());
+ if (inDeleteMode) {
+ // Invoke confirmation dialog
+ showConfirmationDialog(crime);
+ inDeleteMode = false;
+ ActionBar actionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar();
+ actionBar.setTitle("Select an crime to remove.");
+ if (actionBar != null) {
+ actionBar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(requireContext(), R.color.black)));
+ }
+ actionBar.setTitle("CriminalIntent");
+ } else {
+ Intent intent =
+ CrimePagerActivity.newIntent(getActivity(),
+ crime.getId());
+ startActivity(intent);
+ }
- //CHAPTER11
- Intent intent =
- CrimePagerActivity.newIntent(getActivity(),
- crime.getId());
- startActivity(intent);
}
- //CHAPTER8
-// Intent intent = new Intent(getActivity(), CrimeActivity.class);
-// startActivity(intent);
-// Toast.makeText(getActivity(),
-// this.crime.getTitle() + " clicked!",
-// Toast.LENGTH_SHORT)
-// .show();
-
}
//ADAPTER
private class CrimeAdapter extends RecyclerView.Adapter{
@@ -174,6 +200,8 @@ public class CrimeListFragment extends Fragment {
inflater.inflate(R.menu.fragment_crime_list,menu);
MenuItem subtitleItem =
menu.findItem(R.id.show_subtitle);
+ ActionBar actionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar();
+ actionBar.setTitle("CriminalIntent");
if (subtitleVisible) {
subtitleItem.setTitle(R.string.hide_subtitle);
} else {
@@ -193,6 +221,15 @@ public class CrimeListFragment extends Fragment {
startActivity(intent);
return true;
}
+ else if (item.getItemId() == R.id.remove_crime) {
+ ActionBar actionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar();
+ actionBar.setTitle("Select a crime to remove.");
+ if (actionBar != null) {
+ actionBar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(requireContext(), R.color.red)));
+ }
+ inDeleteMode = true;
+ return true;
+ }
else if(item.getItemId() == R.id.show_subtitle)
{
subtitleVisible = !subtitleVisible;
diff --git a/Assignments/CriminalIntent13/app/src/main/java/asdv/lisset/criminalintent/SingleFragmentActivity.java b/Assignments/CriminalIntent13/app/src/main/java/asdv/lisset/criminalintent/SingleFragmentActivity.java
index 585d634..693bf6a 100644
--- a/Assignments/CriminalIntent13/app/src/main/java/asdv/lisset/criminalintent/SingleFragmentActivity.java
+++ b/Assignments/CriminalIntent13/app/src/main/java/asdv/lisset/criminalintent/SingleFragmentActivity.java
@@ -1,8 +1,10 @@
package asdv.lisset.criminalintent;
+import android.content.DialogInterface;
import android.os.Bundle;
import androidx.annotation.Nullable;
+import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
diff --git a/Assignments/CriminalIntent13/app/src/main/java/asdv/lisset/criminalintent/database/CrimeBaseHelper.java b/Assignments/CriminalIntent13/app/src/main/java/asdv/lisset/criminalintent/database/CrimeBaseHelper.java
index 8dd9252..e101f4f 100644
--- a/Assignments/CriminalIntent13/app/src/main/java/asdv/lisset/criminalintent/database/CrimeBaseHelper.java
+++ b/Assignments/CriminalIntent13/app/src/main/java/asdv/lisset/criminalintent/database/CrimeBaseHelper.java
@@ -3,6 +3,8 @@ package asdv.lisset.criminalintent.database;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
+import android.util.Log;
+
import asdv.lisset.criminalintent.database.CrimeDbSchema;
public class CrimeBaseHelper extends SQLiteOpenHelper {
@@ -14,12 +16,13 @@ public class CrimeBaseHelper extends SQLiteOpenHelper {
@Override
public void onCreate(SQLiteDatabase db) {
- String executionString = "create table " + CrimeDbSchema.CrimeTable.NAME;
- executionString += " _id integer primary key autoincrement" +
- CrimeDbSchema.CrimeTable.Cols.UUID + ", " +
- CrimeDbSchema.CrimeTable.Cols.TITLE + ", " +
- CrimeDbSchema.CrimeTable.Cols.DATE + ", " +
- CrimeDbSchema.CrimeTable.Cols.SOLVED;
+ String executionString = "CREATE TABLE " + CrimeDbSchema.CrimeTable.NAME;
+ executionString += "( _id INTEGER PRIMARY KEY AUTOINCREMENT, " +
+ CrimeDbSchema.CrimeTable.Cols.UUID + " TEXT, " +
+ CrimeDbSchema.CrimeTable.Cols.TITLE + " TEXT, " +
+ CrimeDbSchema.CrimeTable.Cols.DATE + " DATE, " +
+ CrimeDbSchema.CrimeTable.Cols.SOLVED + " BOOLEAN);";
+ Log.println(Log.INFO, "CriminalIntent", "SQL String: " + executionString);
db.execSQL(executionString);
}
diff --git a/Assignments/CriminalIntent13/app/src/main/res/drawable-anydpi/ic_menu_remove.xml b/Assignments/CriminalIntent13/app/src/main/res/drawable-anydpi/ic_menu_remove.xml
new file mode 100644
index 0000000..d65b6ea
--- /dev/null
+++ b/Assignments/CriminalIntent13/app/src/main/res/drawable-anydpi/ic_menu_remove.xml
@@ -0,0 +1,11 @@
+
+
+
diff --git a/Assignments/CriminalIntent13/app/src/main/res/menu/fragment_crime_list.xml b/Assignments/CriminalIntent13/app/src/main/res/menu/fragment_crime_list.xml
index af3dd97..8bf4489 100644
--- a/Assignments/CriminalIntent13/app/src/main/res/menu/fragment_crime_list.xml
+++ b/Assignments/CriminalIntent13/app/src/main/res/menu/fragment_crime_list.xml
@@ -1,7 +1,13 @@
\ No newline at end of file
diff --git a/Assignments/CriminalIntent13/app/src/main/res/values/colors.xml b/Assignments/CriminalIntent13/app/src/main/res/values/colors.xml
index c8524cd..6f9c89d 100644
--- a/Assignments/CriminalIntent13/app/src/main/res/values/colors.xml
+++ b/Assignments/CriminalIntent13/app/src/main/res/values/colors.xml
@@ -2,4 +2,5 @@
#FF000000
#FFFFFFFF
+ #FF0000
\ No newline at end of file
diff --git a/Assignments/CriminalIntent13/app/src/main/res/values/strings.xml b/Assignments/CriminalIntent13/app/src/main/res/values/strings.xml
index a5d0315..d2cb12f 100644
--- a/Assignments/CriminalIntent13/app/src/main/res/values/strings.xml
+++ b/Assignments/CriminalIntent13/app/src/main/res/values/strings.xml
@@ -7,6 +7,7 @@
Date of crime:
Time of crime:
New Crime
+ Remove Crime
Show Subtitle
Hide Subtitle
%1$d crimes
diff --git a/ZIPs/CriminalIntent-MP5_CalebFontenot.zip b/ZIPs/CriminalIntent-MP5_CalebFontenot.zip
new file mode 100644
index 0000000..34d72f2
Binary files /dev/null and b/ZIPs/CriminalIntent-MP5_CalebFontenot.zip differ
diff --git a/crimeBase.db b/crimeBase.db
new file mode 100644
index 0000000..5331c4c
Binary files /dev/null and b/crimeBase.db differ