Skip to content

Commit

Permalink
rework calendar and keyword dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
newhinton committed Sep 10, 2024
1 parent 3942f94 commit d879536
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class BluetoothDialog(context: Context) : Dialog(context, R.style.AlertDialogCus

when (state) {
0 -> {
binding.bluetoothDialogTitle.text = context.getText(R.string.keyword_dialog_title_title)
binding.bluetoothDialogTitle.text = context.getText(R.string.bluetooth_dialog_title_title)
binding.bluetoothLayout.visibility = View.VISIBLE
}
1 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import de.felixnuesse.timedsilence.handler.volume.VolumeState.Companion.TIME_SET
import de.felixnuesse.timedsilence.handler.volume.VolumeState.Companion.TIME_SETTING_SILENT
import de.felixnuesse.timedsilence.handler.volume.VolumeState.Companion.TIME_SETTING_VIBRATE
import de.felixnuesse.timedsilence.model.data.CalendarObject
import de.felixnuesse.timedsilence.model.data.KeywordObject
import de.felixnuesse.timedsilence.util.SizeUtil
import de.felixnuesse.timedsilence.util.VibrationUtil
import de.felixnuesse.timedsilence.util.WindowUtils
Expand Down Expand Up @@ -57,6 +58,7 @@ class CalendarDialog(context: Context) : Dialog(context, R.style.AlertDialogCust

private var tfrag: CalendarFragment? = null
private lateinit var calHandler: DeviceCalendar
private var calendarObject: CalendarObject? = null


private var radioMap: HashMap<Int,Long> = HashMap()
Expand All @@ -65,13 +67,19 @@ class CalendarDialog(context: Context) : Dialog(context, R.style.AlertDialogCust
private lateinit var binding: DialogCalendarBinding

constructor(context: Context, tfragment: CalendarFragment, calHandler: DeviceCalendar) : this(context) {
tfrag=tfragment
tfrag = tfragment
this.calHandler=calHandler
}


private var state: Int = 0
constructor(context: Context, calendarFragment: CalendarFragment) : this(context) {
tfrag = calendarFragment
calHandler = DeviceCalendar(context)
}

fun setCalendarObject(calendarObject: CalendarObject) {
this.calendarObject = calendarObject
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -88,16 +96,17 @@ class CalendarDialog(context: Context) : Dialog(context, R.style.AlertDialogCust
binding.calendarDialogRbVibrate.visibility = View.GONE
}

if(calendarObject != null) {
when(calendarObject!!.volume) {
TIME_SETTING_LOUD -> binding.calendarDialogRbLoud.isChecked = true
TIME_SETTING_SILENT -> binding.calendarDialogRbSilent.isChecked = true
else -> binding.calendarDialogRbVibrate.isChecked = true
}
}

window!!.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT)
setCanceledOnTouchOutside(true)


hideAll()
binding.calendarBack.visibility = View.INVISIBLE
binding.calendarDialogTitle.text = context.getText(R.string.calendar_dialog_title_title)
binding.calendarIdLayout.visibility = View.VISIBLE


val rg = findViewById<RadioGroup>(R.id.calendar_radio_group)
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater

Expand All @@ -108,8 +117,8 @@ class CalendarDialog(context: Context) : Dialog(context, R.style.AlertDialogCust

radioButton.setText(Html.fromHtml(text), TextView.BufferType.NORMAL)
radioButton.id = View.generateViewId()
radioMap.put(radioButton.id,calObject.externalID)
radioNameMap.put(calObject.externalID,calObject.name)
radioMap[radioButton.id] = calObject.externalID
radioNameMap[calObject.externalID] = calObject.name

val params = RadioGroup.LayoutParams(
RadioGroup.LayoutParams.WRAP_CONTENT,
Expand All @@ -121,22 +130,6 @@ class CalendarDialog(context: Context) : Dialog(context, R.style.AlertDialogCust

rg.check(calHandler.getDeviceCalendars()[0].externalID.toInt())

binding.calendarNext.setOnClickListener {
Log.e(TAG(), "CalendarDialog: next!")

hideAll()
state++
decideState()
}

binding.calendarBack.setOnClickListener {
Log.e(TAG(), "CalendarDialog: back!")

hideAll()
state--
decideState()
}

binding.calendarCancel.setOnClickListener {
Log.e(TAG(), "CalendarDialog: cancel!")
this.cancel()
Expand All @@ -147,10 +140,10 @@ class CalendarDialog(context: Context) : Dialog(context, R.style.AlertDialogCust

val volId = getValueForVolumeRadioGroup();
val calId = getValueForCalendarRadioGroup();
Log.e(TAG(), "CalendarDialog: Volume: "+volId)
Log.e(TAG(), "CalendarDialog: CalID: "+calId)
Log.e(TAG(), "CalendarDialog: Volume: $volId")
Log.e(TAG(), "CalendarDialog: CalID: $calId")
val so = CalendarObject(
0,//calendar_id_select.text.toString(),
calendarObject?.id ?: 0,
calId,
volId
)
Expand All @@ -162,11 +155,6 @@ class CalendarDialog(context: Context) : Dialog(context, R.style.AlertDialogCust
}
}

private fun hideAll() {
binding.calendarIdLayout.visibility = View.GONE
binding.calendarDialogRbVolume.visibility = View.GONE
}

private fun getValueForVolumeRadioGroup(): Int{
when (binding.calendarDialogRbVolume.checkedRadioButtonId) {
R.id.calendar_dialog_rb_loud -> return TIME_SETTING_LOUD
Expand All @@ -178,42 +166,11 @@ class CalendarDialog(context: Context) : Dialog(context, R.style.AlertDialogCust

private fun getValueForCalendarRadioGroup(): Long{
var ret: Long = 0
var key: Int = binding.calendarRadioGroup.checkedRadioButtonId
val key: Int = binding.calendarRadioGroup.checkedRadioButtonId

if(radioMap.containsKey(key)){
ret= radioMap[key]!!
}
return ret;
}

private fun decideState() {

if(state==0){
binding.calendarBack.visibility = View.INVISIBLE
binding.calendarSave.visibility = View.GONE
binding.calendarNext.visibility = View.VISIBLE
}else if (state == 1){
binding.calendarSave.visibility = View.VISIBLE
binding.calendarBack.visibility = View.VISIBLE
binding.calendarNext.visibility = View.GONE
}else {
binding.calendarBack.visibility = View.VISIBLE
binding.calendarNext.visibility = View.VISIBLE
binding.calendarSave.visibility = View.GONE
}

when (state) {
0 -> {
binding.calendarDialogTitle.text = context.getText(R.string.schedule_dialog_title_title)
binding.calendarIdLayout.visibility = View.VISIBLE
}
1 -> {
binding.calendarDialogTitle.text = context.getText(R.string.schedule_dialog_title_volume)
binding.calendarDialogRbVolume.visibility = View.VISIBLE

}

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ import de.felixnuesse.timedsilence.util.WindowUtils
class KeywordDialog(context: Context) : Dialog(context, R.style.AlertDialogCustom) {

private var tfrag: KeywordFragment? = null
private var keyword: KeywordObject? = null

private lateinit var binding: DialogKeywordBinding

constructor(context: Context, tfragment: KeywordFragment) : this(context) {
tfrag=tfragment
}

private var state: Int = 0
fun setKeyword(keyword: KeywordObject) {
this.keyword = keyword
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -75,30 +78,19 @@ class KeywordDialog(context: Context) : Dialog(context, R.style.AlertDialogCusto
binding.keywordDialogRbVibrate.visibility = View.GONE
}

window!!.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT)
setCanceledOnTouchOutside(true)


hideAll()
binding.keywordBack.visibility = View.INVISIBLE
binding.keywordDialogTitle.text = context.getText(R.string.keyword_dialog_title_title)
binding.keywordKeywordLayout.visibility = View.VISIBLE

binding.keywordNext.setOnClickListener {
Log.e(TAG(), "KeywordDialog: next!")

hideAll()
state++
decideState()
if(keyword != null) {
binding.keywordTextfield.setText(keyword!!.keyword)
when(keyword!!.volume) {
TIME_SETTING_LOUD -> binding.keywordDialogRbLoud.isChecked = true
TIME_SETTING_SILENT -> binding.keywordDialogRbSilent.isChecked = true
else -> binding.keywordDialogRbVibrate.isChecked = true
}
}

binding.keywordBack.setOnClickListener {
Log.e(TAG(), "KeywordDialog: back!")
window!!.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT)
setCanceledOnTouchOutside(true)

hideAll()
state--
decideState()
}
binding.keywordDialogTitle.text = context.getText(R.string.keyword_add_new)

binding.keywordCancel.setOnClickListener {
Log.e(TAG(), "KeywordDialog: cancel!")
Expand All @@ -110,7 +102,7 @@ class KeywordDialog(context: Context) : Dialog(context, R.style.AlertDialogCusto

val volId = getValueForVolumeRadioGroup()
val keyword = KeywordObject(
0,
keyword?.id ?: 0,
ALL_CALENDAR,
binding.keywordTextfield.text.toString(),
volId
Expand All @@ -120,48 +112,11 @@ class KeywordDialog(context: Context) : Dialog(context, R.style.AlertDialogCusto
}
}

private fun hideAll() {
binding.keywordKeywordLayout.visibility = View.GONE
binding.keywordDialogRbVolume.visibility = View.GONE
}

private fun getValueForVolumeRadioGroup(): Int{
when (binding.keywordDialogRbVolume.checkedRadioButtonId) {
R.id.keyword_dialog_rb_loud -> return TIME_SETTING_LOUD
R.id.keyword_dialog_rb_silent -> return TIME_SETTING_SILENT
R.id.keyword_dialog_rb_vibrate -> return TIME_SETTING_VIBRATE
}
return TIME_SETTING_VIBRATE;
}

private fun decideState() {

if(state==0){
binding.keywordBack.visibility = View.INVISIBLE
binding.keywordSave.visibility = View.GONE
binding.keywordNext.visibility = View.VISIBLE
}else if (state == 1){
binding.keywordSave.visibility = View.VISIBLE
binding.keywordBack.visibility = View.VISIBLE
binding.keywordNext.visibility = View.GONE
}else {
binding.keywordBack.visibility = View.VISIBLE
binding.keywordNext.visibility = View.VISIBLE
binding.keywordSave.visibility = View.GONE
return when (binding.keywordDialogRbVolume.checkedRadioButtonId) {
R.id.keyword_dialog_rb_loud -> TIME_SETTING_LOUD
R.id.keyword_dialog_rb_silent -> TIME_SETTING_SILENT
else -> TIME_SETTING_VIBRATE
}

when (state) {
0 -> {
binding.keywordDialogTitle.text = context.getText(R.string.keyword_dialog_title_title)
binding.keywordKeywordLayout.visibility = View.VISIBLE
}
1 -> {
binding.keywordDialogTitle.text = context.getText(R.string.schedule_dialog_title_volume)
binding.keywordDialogRbVolume.visibility = View.VISIBLE

}

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class WifiDialog(context: Context) : Dialog(context, R.style.AlertDialogCustom)

hideAll()
binding.wifiBack.visibility = View.INVISIBLE
binding.wifiDialogTitle.text = context.getText(R.string.calendar_dialog_title_title)
binding.wifiDialogTitle.text = context.getText(R.string.wifi_dialog_title_title)
binding.wifiSsidLayout.visibility = View.VISIBLE

binding.wifiNext.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CalendarFragment : Fragment() {

val db = DatabaseHandler(view.context)
viewManager = LinearLayoutManager(view.context)
viewAdapter = CalendarListAdapter(db.getAllCalendarEntries(), calHandler)
viewAdapter = CalendarListAdapter(db.getAllCalendarEntries(), calHandler, this)

binding.calendarFragmentRecylcerListView.apply {
// use this setting to improve performance if you know that changes
Expand Down Expand Up @@ -101,7 +101,8 @@ class CalendarFragment : Fragment() {
val db = DatabaseHandler(context)
db.createCalendarEntry(co)
viewAdapter = CalendarListAdapter(db.getAllCalendarEntries(),
DeviceCalendar(context)
DeviceCalendar(context),
this
)

binding.calendarFragmentRecylcerListView.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class KeywordFragment : Fragment() {

val db = DatabaseHandler(view.context)
viewManager = LinearLayoutManager(view.context)
viewAdapter = KeywordListAdapter(db.getKeywords())
viewAdapter = KeywordListAdapter(db.getKeywords(), this)

binding.calendarFragmentRecylcerListView.apply {
setHasFixedSize(true)
Expand All @@ -59,7 +59,7 @@ class KeywordFragment : Fragment() {
fun saveKeyword(context: Context, keywordObject: KeywordObject){
val db = DatabaseHandler(context)
db.createKeyword(keywordObject)
viewAdapter = KeywordListAdapter(db.getKeywords())
viewAdapter = KeywordListAdapter(db.getKeywords(), this)

binding.calendarFragmentRecylcerListView.apply {
// use this setting to improve performance if you know that changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import androidx.appcompat.content.res.AppCompatResources
import androidx.recyclerview.widget.RecyclerView
import de.felixnuesse.timedsilence.R
import de.felixnuesse.timedsilence.databinding.AdapterCalendarListBinding
import de.felixnuesse.timedsilence.dialogs.CalendarDialog
import de.felixnuesse.timedsilence.dialogs.KeywordDialog
import de.felixnuesse.timedsilence.fragments.CalendarFragment
import de.felixnuesse.timedsilence.fragments.KeywordFragment
import de.felixnuesse.timedsilence.handler.volume.VolumeState.Companion.TIME_SETTING_LOUD
import de.felixnuesse.timedsilence.handler.volume.VolumeState.Companion.TIME_SETTING_SILENT
import de.felixnuesse.timedsilence.handler.volume.VolumeState.Companion.TIME_SETTING_VIBRATE
Expand Down Expand Up @@ -46,7 +50,11 @@ import de.felixnuesse.timedsilence.volumestate.calendar.DeviceCalendar
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
class CalendarListAdapter(private var myDataset: ArrayList<CalendarObject>, private var calHandler: DeviceCalendar) : RecyclerView.Adapter<CalendarListAdapter.CalendarViewHolder>() {
class CalendarListAdapter(
private var myDataset: ArrayList<CalendarObject>,
private var calHandler: DeviceCalendar,
private var calendarFragment: CalendarFragment
) : RecyclerView.Adapter<CalendarListAdapter.CalendarViewHolder>() {

private fun removeAt(position: Int) {
myDataset.removeAt(position)
Expand Down Expand Up @@ -81,6 +89,13 @@ class CalendarListAdapter(private var myDataset: ArrayList<CalendarObject>, priv
removeAt(position)
}

holder.calendarView.textViewCalendarRowTitle.setOnClickListener {
val dialog = CalendarDialog(calendarFragment.requireContext(), calendarFragment)
dialog.setCalendarObject(calObject)
dialog.show()

}

val color = calHandler.getCalendarColor(calObject.name)
holder.calendarView.cardView.setCardBackgroundColor(color)
holder.calendarView.deleteCalendarElement.setColorFilter(color)
Expand All @@ -93,7 +108,6 @@ class CalendarListAdapter(private var myDataset: ArrayList<CalendarObject>, priv
holder.calendarView.volumeState.imageTintList = ColorStateList.valueOf(color)
}


var imageID=R.drawable.icon_volume_up
when (calObject.volume) {
TIME_SETTING_LOUD -> imageID=R.drawable.icon_volume_up
Expand Down
Loading

0 comments on commit d879536

Please sign in to comment.