throwing in the towel
This commit is contained in:
parent
27b2f5f028
commit
0749a4a486
@ -27,6 +27,7 @@ class CourseActivity : AppCompatActivity(), CourseDialogFragment.onCourseEntered
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
mDarkTheme = mSharedPrefs!!.getBoolean(SettingsFragment.PREFERENCE_THEME, false)
|
||||
|
||||
if (mDarkTheme) {
|
||||
setTheme(R.style.DarkTheme)
|
||||
}
|
||||
@ -34,8 +35,6 @@ class CourseActivity : AppCompatActivity(), CourseDialogFragment.onCourseEntered
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_course)
|
||||
|
||||
// mDialog = CourseDialogFragment()
|
||||
|
||||
mCourseListRecyclerView = findViewById(R.id.courseRecyclerView)
|
||||
mCourseDb = CourseDatabase.getInstance(applicationContext)
|
||||
mCourseListRecyclerView = findViewById(R.id.courseRecyclerView)
|
||||
@ -63,31 +62,28 @@ class CourseActivity : AppCompatActivity(), CourseDialogFragment.onCourseEntered
|
||||
//Snackbar.make(findViewById(android.R.id.content), "*proceeds to make raspberry noises*", 5000).show()
|
||||
true
|
||||
}
|
||||
R.id.edit -> {
|
||||
// up comes a dialog box editing the desired list item
|
||||
mDialog = CourseDialogFragment()
|
||||
mDialog.getContext(CourseContext.EDIT, mCourseDb)
|
||||
mDialog.show(supportFragmentManager, "")
|
||||
true
|
||||
}
|
||||
R.id.delete -> {
|
||||
// takes out item.itemId aka deletes record
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCourseEntered(course: String) {
|
||||
override fun onCourseEntered(course: Course) {
|
||||
// Returns subject entered in the SubjectDialogFragment dialog
|
||||
if (course!!.isNotEmpty()) {
|
||||
val c = Course(course)
|
||||
if (mCourseDb.addCourse(c)) {
|
||||
mCourseAdapter?.addCourse(c)
|
||||
Toast.makeText(this@CourseActivity, course, Toast.LENGTH_LONG).show()
|
||||
if (course != null) {
|
||||
if (course.id == 0) {
|
||||
if (mCourseDb.addCourse(course)) {
|
||||
mCourseAdapter?.addCourse(course)
|
||||
//Snackbar.make(this@CourseActivity, "$course entered!", 5000).show()
|
||||
} else {
|
||||
val message = resources.getString("Already exists!".toInt(), course)
|
||||
Toast.makeText(this@CourseActivity, message, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
} else {
|
||||
val message = resources.getString("Already exists!".toInt(), course)
|
||||
Toast.makeText(this@CourseActivity, message, Toast.LENGTH_SHORT).show()
|
||||
if (course.id != 0) {
|
||||
mCourseDb.updateCourse(course)
|
||||
mCourseAdapter?.updateCourse(course)
|
||||
} else {
|
||||
// ??
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -112,13 +108,13 @@ class CourseActivity : AppCompatActivity(), CourseDialogFragment.onCourseEntered
|
||||
fun bind(course: Course) {
|
||||
mCourse = course
|
||||
mTextView.text = course.name
|
||||
mTextView.setBackgroundColor(Color.RED)
|
||||
mTextView.setBackgroundColor(Color.MAGENTA)
|
||||
}
|
||||
|
||||
override fun onClick(view: View) {
|
||||
// Start QuestionActivity, indicating what subject was clicked
|
||||
mDialog = CourseDialogFragment()
|
||||
mDialog.getContext(CourseContext.VIEW, mCourseDb)
|
||||
mDialog.getCourseId(mCourse!!.id)
|
||||
mDialog.show(supportFragmentManager, "")
|
||||
}
|
||||
|
||||
@ -152,7 +148,7 @@ class CourseActivity : AppCompatActivity(), CourseDialogFragment.onCourseEntered
|
||||
|
||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||
// Process action item selection
|
||||
return when (item.getItemId()) {
|
||||
return when (item.itemId) {
|
||||
R.id.delete -> {
|
||||
// Delete from the database and remove from the RecyclerView
|
||||
mCourseDb.deleteCourse(mSelectedCourse)
|
||||
@ -162,12 +158,21 @@ class CourseActivity : AppCompatActivity(), CourseDialogFragment.onCourseEntered
|
||||
mode.finish()
|
||||
true
|
||||
}
|
||||
R.id.edit -> {
|
||||
// up comes a dialog box editing the desired list item
|
||||
mCourseAdapter?.takeCourseIndex()
|
||||
mDialog = CourseDialogFragment()
|
||||
mDialog.getContext(CourseContext.EDIT, mCourseDb)
|
||||
mDialog.getCourseId(mSelectedCourse.id)
|
||||
mDialog.show(supportFragmentManager, "")
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyActionMode(mode: ActionMode) {
|
||||
//mActionMode = null
|
||||
mActionMode = null
|
||||
|
||||
// CAB closing, need to deselect item if not deleted
|
||||
mCourseAdapter?.notifyItemChanged(mSelectedCoursePosition)
|
||||
@ -183,6 +188,8 @@ class CourseActivity : AppCompatActivity(), CourseDialogFragment.onCourseEntered
|
||||
}
|
||||
|
||||
private inner class CourseAdapter(private val mCourseList: MutableList<Course>) : RecyclerView.Adapter<CourseHolder>() {
|
||||
private var mOldCourseIndex = 0
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CourseHolder {
|
||||
val layoutInflater = LayoutInflater.from(applicationContext)
|
||||
return CourseHolder(layoutInflater, parent)
|
||||
@ -196,6 +203,11 @@ class CourseActivity : AppCompatActivity(), CourseDialogFragment.onCourseEntered
|
||||
return mCourseList.size
|
||||
}
|
||||
|
||||
fun takeCourseIndex() {
|
||||
val index = mSelectedCoursePosition
|
||||
mOldCourseIndex = index
|
||||
}
|
||||
|
||||
fun removeCourse(course: Course?) {
|
||||
// Find subject in the list
|
||||
val index = mCourseList.indexOf(course)
|
||||
@ -218,5 +230,12 @@ class CourseActivity : AppCompatActivity(), CourseDialogFragment.onCourseEntered
|
||||
// Scroll to the top
|
||||
mCourseListRecyclerView?.scrollToPosition(0)
|
||||
}
|
||||
|
||||
fun updateCourse(course: Course?) {
|
||||
mCourseList.removeAt(mOldCourseIndex)
|
||||
mCourseList.add(0, course!!)
|
||||
notifyItemChanged(0)
|
||||
mCourseListRecyclerView?.scrollToPosition(0)
|
||||
}
|
||||
}
|
||||
}
|
@ -58,15 +58,16 @@ class CourseDatabase(context: Context?) : SQLiteOpenHelper(context, DATABASE_NAM
|
||||
return courses
|
||||
}
|
||||
|
||||
fun getCourse(courseId: Long): Course {
|
||||
val course = Course()
|
||||
fun getCourse(courseid: Int): Course {
|
||||
var course = Course()
|
||||
val db = this.readableDatabase
|
||||
val sql
|
||||
= "select * from " + CourseTable.TABLE +
|
||||
"where " + CourseTable.COL_ID + " = ?"
|
||||
val cursor = db.rawQuery(sql, arrayOf(courseId.toString()))
|
||||
val sql =
|
||||
"select * from " + CourseTable.TABLE +
|
||||
" where " + CourseTable.COL_ID + " = ?"
|
||||
val cursor = db.rawQuery(sql, arrayOf(java.lang.Float.toString(courseid.toFloat())))
|
||||
|
||||
if (cursor.moveToFirst()) {
|
||||
course.id = cursor.getInt(0)
|
||||
course.name = cursor.getString(1)
|
||||
course.description = cursor.getString(2)
|
||||
course.location = cursor.getString(3)
|
||||
@ -89,14 +90,20 @@ class CourseDatabase(context: Context?) : SQLiteOpenHelper(context, DATABASE_NAM
|
||||
values.put(CourseTable.COL_TIME, course.time)
|
||||
values.put(CourseTable.COL_INSTRUCTOR, course.instructor)
|
||||
val id = db.insert(CourseTable.TABLE, null, values)
|
||||
course.id = id.toInt()
|
||||
return id != -1L
|
||||
}
|
||||
|
||||
fun updateCourse(course: Course) {
|
||||
val db = writableDatabase
|
||||
val values = ContentValues()
|
||||
|
||||
db.update(CourseTable.TABLE, values, CourseTable.COL_NAME + " = ?", arrayOf(course.name))
|
||||
values.put(CourseTable.COL_NAME, course.name)
|
||||
values.put(CourseTable.COL_DESCRIPTION, course.description)
|
||||
values.put(CourseTable.COL_LOCATION, course.location)
|
||||
values.put(CourseTable.COL_DAYOFWEEK, course.dayofweek)
|
||||
values.put(CourseTable.COL_TIME, course.time)
|
||||
values.put(CourseTable.COL_INSTRUCTOR, course.instructor)
|
||||
db.update(CourseTable.TABLE, values, CourseTable.COL_ID + " = " + course.id, null)
|
||||
}
|
||||
|
||||
fun deleteCourse(course: Course) {
|
||||
|
@ -3,6 +3,8 @@ package com.wyattjmiller.classscheduleapp
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.text.Editable
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import android.widget.TextView
|
||||
@ -20,10 +22,19 @@ class CourseDialogFragment : DialogFragment() {
|
||||
private lateinit var mEditTextCourseDescription: EditText
|
||||
private lateinit var mContext: CourseContext
|
||||
private lateinit var mCourseDb: CourseDatabase
|
||||
|
||||
private lateinit var mCourseNameView: TextView
|
||||
private lateinit var mCourseLocationView: TextView
|
||||
private lateinit var mCourseTimeView: TextView
|
||||
private lateinit var mCourseDateView: TextView
|
||||
private lateinit var mCourseInstructor: TextView
|
||||
private lateinit var mCourseDescriptionView: TextView
|
||||
|
||||
|
||||
private var mCourse: Course = Course()
|
||||
|
||||
interface onCourseEnteredListener {
|
||||
fun onCourseEntered(course: String)
|
||||
fun onCourseEntered(course: Course)
|
||||
}
|
||||
|
||||
private lateinit var mDoneButton: Button
|
||||
@ -42,15 +53,59 @@ class CourseDialogFragment : DialogFragment() {
|
||||
mEditTextCourseTime = dialogView.findViewById(R.id.editTextCourseTime)
|
||||
mEditTextCourseDescription = dialogView.findViewById(R.id.editTextCourseDescription)
|
||||
|
||||
mCourseNameView = dialogView.findViewById(R.id.textviewCourseName2)
|
||||
mCourseLocationView = dialogView.findViewById(R.id.textViewCourseLocation2)
|
||||
mCourseDateView = dialogView.findViewById(R.id.textViewCourseDayOfWeek2)
|
||||
mCourseTimeView = dialogView.findViewById(R.id.textViewCourseTime2)
|
||||
mCourseInstructor = dialogView.findViewById(R.id.textViewCourseInstructor2)
|
||||
mCourseDescriptionView = dialogView.findViewById(R.id.textViewCourseDescription2)
|
||||
|
||||
mCourseNameView.visibility = View.GONE
|
||||
mCourseLocationView.visibility = View.GONE
|
||||
mCourseDateView.visibility = View.GONE
|
||||
mCourseTimeView.visibility = View.GONE
|
||||
mCourseInstructor.visibility = View.GONE
|
||||
mCourseDescriptionView.visibility = View.GONE
|
||||
|
||||
when (mContext) {
|
||||
CourseContext.ADD -> {
|
||||
// TODO: set title to add course and when pressing done, add to database
|
||||
mTextViewTitle.text = "Add Course"
|
||||
}
|
||||
CourseContext.EDIT -> {
|
||||
// TODO: set title to edit course and when pressing done, modify record to database
|
||||
var course = mCourseDb.getCourse(mCourse.id)
|
||||
|
||||
mTextViewTitle.text = "Edit Course"
|
||||
mEditTextCourseName.setText(course.name)
|
||||
mEditTextCourseLocation.setText(course.location)
|
||||
mEditTextCourseInstructor.setText(course.instructor)
|
||||
mEditTextDayOfWeek.setText(course.dayofweek)
|
||||
mEditTextCourseTime.setText(course.time)
|
||||
mEditTextCourseDescription.setText(course.description)
|
||||
}
|
||||
CourseContext.VIEW -> {
|
||||
// TODO: set title to view course, make everything text, and when pressing done, close dialog
|
||||
val course = mCourseDb.getCourse(mCourse.id)
|
||||
|
||||
mEditTextCourseName.visibility = View.INVISIBLE
|
||||
mEditTextCourseLocation.visibility = View.INVISIBLE
|
||||
mEditTextCourseInstructor.visibility = View.INVISIBLE
|
||||
mEditTextDayOfWeek.visibility = View.INVISIBLE
|
||||
mEditTextCourseTime.visibility = View.INVISIBLE
|
||||
mEditTextCourseDescription.visibility = View.INVISIBLE
|
||||
|
||||
mCourseNameView.visibility = View.VISIBLE
|
||||
mCourseLocationView.visibility = View.VISIBLE
|
||||
mCourseDateView.visibility = View.VISIBLE
|
||||
mCourseTimeView.visibility = View.VISIBLE
|
||||
mCourseInstructor.visibility = View.VISIBLE
|
||||
mCourseDescriptionView.visibility = View.VISIBLE
|
||||
|
||||
mTextViewTitle.text = "View Course"
|
||||
mCourseNameView.text = course.name
|
||||
mCourseLocationView.text = course.location
|
||||
mCourseDateView.text = course.dayofweek
|
||||
mCourseTimeView.text = course.time
|
||||
mCourseInstructor.text = course.instructor
|
||||
mCourseDescriptionView.text = course.description
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,8 +123,7 @@ class CourseDialogFragment : DialogFragment() {
|
||||
|
||||
val valid = this.validityCheck()
|
||||
if (valid) {
|
||||
val course = mCourse.name
|
||||
mListener?.onCourseEntered(course!!.trim())
|
||||
mListener?.onCourseEntered(mCourse)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
@ -83,8 +137,7 @@ class CourseDialogFragment : DialogFragment() {
|
||||
|
||||
val valid = this.validityCheck()
|
||||
if (valid) {
|
||||
val course = mCourse.name
|
||||
mListener?.onCourseEntered(course!!.trim())
|
||||
mListener?.onCourseEntered(mCourse)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
@ -102,6 +155,10 @@ class CourseDialogFragment : DialogFragment() {
|
||||
mCourseDb = database
|
||||
}
|
||||
|
||||
fun getCourseId(courseId: Int) {
|
||||
mCourse.id = courseId
|
||||
}
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
super.onAttach(context)
|
||||
mListener = context as onCourseEnteredListener
|
||||
@ -118,7 +175,7 @@ class CourseDialogFragment : DialogFragment() {
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val EXTRA_COURSE_ID = "com.wyattjmiller.classscheduleapp.course_id"
|
||||
const val EXTRA_COURSE = "com.wyattjmiller.classscheduleapp.course"
|
||||
}
|
||||
|
||||
}
|
@ -31,6 +31,18 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textViewTitle" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textviewCourseName2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="44dp"
|
||||
android:layout_marginEnd="60dp"
|
||||
android:ems="10"
|
||||
android:inputType="textPersonName"
|
||||
android:visibility="invisible"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textViewTitle" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewTitle"
|
||||
android:layout_width="wrap_content"
|
||||
@ -64,6 +76,18 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/editTextCourseName" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewCourseLocation2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="36dp"
|
||||
android:layout_marginEnd="60dp"
|
||||
android:ems="10"
|
||||
android:inputType="textPersonName"
|
||||
android:visibility="invisible"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/editTextCourseName" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editTextCourseDayOfWeek"
|
||||
android:layout_width="wrap_content"
|
||||
@ -72,6 +96,19 @@
|
||||
android:layout_marginEnd="16dp"
|
||||
android:ems="10"
|
||||
android:inputType="textPersonName"
|
||||
android:visibility="visible"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/editTextCourseLocation" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewCourseDayOfWeek2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="36dp"
|
||||
android:layout_marginEnd="60dp"
|
||||
android:ems="10"
|
||||
android:inputType="textPersonName"
|
||||
android:visibility="invisible"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/editTextCourseLocation" />
|
||||
|
||||
@ -108,6 +145,18 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/editTextCourseDayOfWeek" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewCourseTime2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="36dp"
|
||||
android:layout_marginEnd="60dp"
|
||||
android:ems="10"
|
||||
android:inputType="time"
|
||||
android:visibility="invisible"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/editTextCourseDayOfWeek" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewCourseInstructor"
|
||||
android:layout_width="wrap_content"
|
||||
@ -130,6 +179,18 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/editTextCourseTime" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewCourseInstructor2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="36dp"
|
||||
android:layout_marginEnd="60dp"
|
||||
android:ems="10"
|
||||
android:inputType="textPersonName"
|
||||
android:visibility="invisible"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/editTextCourseTime" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonFinish"
|
||||
android:layout_width="246dp"
|
||||
@ -158,6 +219,23 @@
|
||||
app:layout_constraintTop_toBottomOf="@+id/textViewCourseDescription"
|
||||
app:layout_constraintVertical_bias="0.087" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewCourseDescription2"
|
||||
android:layout_width="327dp"
|
||||
android:layout_height="135dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:ems="10"
|
||||
android:gravity="start|top"
|
||||
android:inputType="textMultiLine"
|
||||
android:visibility="invisible"
|
||||
app:layout_constraintBottom_toTopOf="@+id/buttonFinish"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.461"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textViewCourseDescription"
|
||||
app:layout_constraintVertical_bias="0.087" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewCourseDescription"
|
||||
android:layout_width="wrap_content"
|
||||
|
Loading…
Reference in New Issue
Block a user