diff --git a/.idea/misc.xml b/.idea/misc.xml index 97f8bf5..0076403 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -11,6 +11,7 @@ + diff --git a/.idea/misc.xml b/.idea/misc.xml index 97f8bf5..0076403 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -11,6 +11,7 @@ + diff --git a/app/src/main/java/com/lukas/music/instruments/Instrument.kt b/app/src/main/java/com/lukas/music/instruments/Instrument.kt index 8ad90c6..3487ffd 100644 --- a/app/src/main/java/com/lukas/music/instruments/Instrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/Instrument.kt @@ -10,20 +10,26 @@ package com.lukas.music.instruments +import androidx.fragment.app.FragmentManager import com.lukas.music.databinding.FragmentInstrumentBinding import com.lukas.music.song.note.Note import com.lukas.music.song.voice.BassVoice import com.lukas.music.song.voice.ChordVoice import com.lukas.music.song.voice.Voice +import com.lukas.music.ui.fragments.EditInstrumentFragment -abstract class Instrument(private var name: String) { +abstract class Instrument(var name: String) { private var active = false abstract var waveform: Waveform - fun applyToView(binding: FragmentInstrumentBinding) { + fun applyToView(binding: FragmentInstrumentBinding, childFragmentManager: FragmentManager) { binding.instrumentNameText.text = name binding.editInstrumentButton.setOnClickListener { - println("click instrument $name") + EditInstrumentFragment( + this, + binding, + childFragmentManager + ).showNow(childFragmentManager, "") } binding.activeSwitch.setOnCheckedChangeListener { _, newActive -> active = newActive diff --git a/.idea/misc.xml b/.idea/misc.xml index 97f8bf5..0076403 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -11,6 +11,7 @@ + diff --git a/app/src/main/java/com/lukas/music/instruments/Instrument.kt b/app/src/main/java/com/lukas/music/instruments/Instrument.kt index 8ad90c6..3487ffd 100644 --- a/app/src/main/java/com/lukas/music/instruments/Instrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/Instrument.kt @@ -10,20 +10,26 @@ package com.lukas.music.instruments +import androidx.fragment.app.FragmentManager import com.lukas.music.databinding.FragmentInstrumentBinding import com.lukas.music.song.note.Note import com.lukas.music.song.voice.BassVoice import com.lukas.music.song.voice.ChordVoice import com.lukas.music.song.voice.Voice +import com.lukas.music.ui.fragments.EditInstrumentFragment -abstract class Instrument(private var name: String) { +abstract class Instrument(var name: String) { private var active = false abstract var waveform: Waveform - fun applyToView(binding: FragmentInstrumentBinding) { + fun applyToView(binding: FragmentInstrumentBinding, childFragmentManager: FragmentManager) { binding.instrumentNameText.text = name binding.editInstrumentButton.setOnClickListener { - println("click instrument $name") + EditInstrumentFragment( + this, + binding, + childFragmentManager + ).showNow(childFragmentManager, "") } binding.activeSwitch.setOnCheckedChangeListener { _, newActive -> active = newActive diff --git a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt index 8961831..8dc2310 100644 --- a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt +++ b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt @@ -19,9 +19,11 @@ import com.lukas.music.databinding.FragmentInstrumentBinding import com.lukas.music.instruments.Instrument import com.lukas.music.instruments.Waveform +import com.lukas.music.ui.fragments.InstrumentListFragment -class InstrumentAdapter : RecyclerView.Adapter() { +class InstrumentAdapter(val parent: InstrumentListFragment) : + RecyclerView.Adapter() { class InstrumentViewHolder(val binding: FragmentInstrumentBinding) : RecyclerView.ViewHolder(binding.root), AdapterView.OnItemSelectedListener { lateinit var instrument: Instrument @@ -58,7 +60,7 @@ override fun onBindViewHolder(holder: InstrumentViewHolder, position: Int) { val instrument = Instrument.instruments[position] holder.instrument = instrument - instrument.applyToView(holder.binding) + instrument.applyToView(holder.binding, parent.childFragmentManager) } override fun getItemCount(): Int { diff --git a/.idea/misc.xml b/.idea/misc.xml index 97f8bf5..0076403 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -11,6 +11,7 @@ + diff --git a/app/src/main/java/com/lukas/music/instruments/Instrument.kt b/app/src/main/java/com/lukas/music/instruments/Instrument.kt index 8ad90c6..3487ffd 100644 --- a/app/src/main/java/com/lukas/music/instruments/Instrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/Instrument.kt @@ -10,20 +10,26 @@ package com.lukas.music.instruments +import androidx.fragment.app.FragmentManager import com.lukas.music.databinding.FragmentInstrumentBinding import com.lukas.music.song.note.Note import com.lukas.music.song.voice.BassVoice import com.lukas.music.song.voice.ChordVoice import com.lukas.music.song.voice.Voice +import com.lukas.music.ui.fragments.EditInstrumentFragment -abstract class Instrument(private var name: String) { +abstract class Instrument(var name: String) { private var active = false abstract var waveform: Waveform - fun applyToView(binding: FragmentInstrumentBinding) { + fun applyToView(binding: FragmentInstrumentBinding, childFragmentManager: FragmentManager) { binding.instrumentNameText.text = name binding.editInstrumentButton.setOnClickListener { - println("click instrument $name") + EditInstrumentFragment( + this, + binding, + childFragmentManager + ).showNow(childFragmentManager, "") } binding.activeSwitch.setOnCheckedChangeListener { _, newActive -> active = newActive diff --git a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt index 8961831..8dc2310 100644 --- a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt +++ b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt @@ -19,9 +19,11 @@ import com.lukas.music.databinding.FragmentInstrumentBinding import com.lukas.music.instruments.Instrument import com.lukas.music.instruments.Waveform +import com.lukas.music.ui.fragments.InstrumentListFragment -class InstrumentAdapter : RecyclerView.Adapter() { +class InstrumentAdapter(val parent: InstrumentListFragment) : + RecyclerView.Adapter() { class InstrumentViewHolder(val binding: FragmentInstrumentBinding) : RecyclerView.ViewHolder(binding.root), AdapterView.OnItemSelectedListener { lateinit var instrument: Instrument @@ -58,7 +60,7 @@ override fun onBindViewHolder(holder: InstrumentViewHolder, position: Int) { val instrument = Instrument.instruments[position] holder.instrument = instrument - instrument.applyToView(holder.binding) + instrument.applyToView(holder.binding, parent.childFragmentManager) } override fun getItemCount(): Int { diff --git a/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt new file mode 100644 index 0000000..d933194 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2022 Lukas Eisenhauer + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or(at your option) any later version. + * + * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + */ + +package com.lukas.music.ui.fragments + +import android.os.Bundle +import android.text.Editable +import android.text.TextWatcher +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.DialogFragment +import androidx.fragment.app.FragmentManager +import com.lukas.music.databinding.FragmentEditInstrumentBinding +import com.lukas.music.databinding.FragmentInstrumentBinding +import com.lukas.music.instruments.Instrument + +class EditInstrumentFragment( + private val instrument: Instrument, + private val parent: FragmentInstrumentBinding, + private val manager: FragmentManager +) : DialogFragment() { + lateinit var binding: FragmentEditInstrumentBinding + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + binding = FragmentEditInstrumentBinding.inflate(inflater) + binding.instrumentNameTextBox.text.clear() + binding.instrumentNameTextBox.text.append(instrument.name) + binding.instrumentNameTextBox.addTextChangedListener(object : TextWatcher { + override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} + override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {} + + override fun afterTextChanged(s: Editable?) { + instrument.name = binding.instrumentNameTextBox.text.toString() + instrument.applyToView(parent, manager) + } + }) + binding.closeButton.setOnClickListener { + dismiss() + } + return binding.root + } + + override fun onStart() { + super.onStart() + dialog?.window?.setLayout( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) + } +} \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 97f8bf5..0076403 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -11,6 +11,7 @@ + diff --git a/app/src/main/java/com/lukas/music/instruments/Instrument.kt b/app/src/main/java/com/lukas/music/instruments/Instrument.kt index 8ad90c6..3487ffd 100644 --- a/app/src/main/java/com/lukas/music/instruments/Instrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/Instrument.kt @@ -10,20 +10,26 @@ package com.lukas.music.instruments +import androidx.fragment.app.FragmentManager import com.lukas.music.databinding.FragmentInstrumentBinding import com.lukas.music.song.note.Note import com.lukas.music.song.voice.BassVoice import com.lukas.music.song.voice.ChordVoice import com.lukas.music.song.voice.Voice +import com.lukas.music.ui.fragments.EditInstrumentFragment -abstract class Instrument(private var name: String) { +abstract class Instrument(var name: String) { private var active = false abstract var waveform: Waveform - fun applyToView(binding: FragmentInstrumentBinding) { + fun applyToView(binding: FragmentInstrumentBinding, childFragmentManager: FragmentManager) { binding.instrumentNameText.text = name binding.editInstrumentButton.setOnClickListener { - println("click instrument $name") + EditInstrumentFragment( + this, + binding, + childFragmentManager + ).showNow(childFragmentManager, "") } binding.activeSwitch.setOnCheckedChangeListener { _, newActive -> active = newActive diff --git a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt index 8961831..8dc2310 100644 --- a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt +++ b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt @@ -19,9 +19,11 @@ import com.lukas.music.databinding.FragmentInstrumentBinding import com.lukas.music.instruments.Instrument import com.lukas.music.instruments.Waveform +import com.lukas.music.ui.fragments.InstrumentListFragment -class InstrumentAdapter : RecyclerView.Adapter() { +class InstrumentAdapter(val parent: InstrumentListFragment) : + RecyclerView.Adapter() { class InstrumentViewHolder(val binding: FragmentInstrumentBinding) : RecyclerView.ViewHolder(binding.root), AdapterView.OnItemSelectedListener { lateinit var instrument: Instrument @@ -58,7 +60,7 @@ override fun onBindViewHolder(holder: InstrumentViewHolder, position: Int) { val instrument = Instrument.instruments[position] holder.instrument = instrument - instrument.applyToView(holder.binding) + instrument.applyToView(holder.binding, parent.childFragmentManager) } override fun getItemCount(): Int { diff --git a/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt new file mode 100644 index 0000000..d933194 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2022 Lukas Eisenhauer + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or(at your option) any later version. + * + * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + */ + +package com.lukas.music.ui.fragments + +import android.os.Bundle +import android.text.Editable +import android.text.TextWatcher +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.DialogFragment +import androidx.fragment.app.FragmentManager +import com.lukas.music.databinding.FragmentEditInstrumentBinding +import com.lukas.music.databinding.FragmentInstrumentBinding +import com.lukas.music.instruments.Instrument + +class EditInstrumentFragment( + private val instrument: Instrument, + private val parent: FragmentInstrumentBinding, + private val manager: FragmentManager +) : DialogFragment() { + lateinit var binding: FragmentEditInstrumentBinding + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + binding = FragmentEditInstrumentBinding.inflate(inflater) + binding.instrumentNameTextBox.text.clear() + binding.instrumentNameTextBox.text.append(instrument.name) + binding.instrumentNameTextBox.addTextChangedListener(object : TextWatcher { + override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} + override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {} + + override fun afterTextChanged(s: Editable?) { + instrument.name = binding.instrumentNameTextBox.text.toString() + instrument.applyToView(parent, manager) + } + }) + binding.closeButton.setOnClickListener { + dismiss() + } + return binding.root + } + + override fun onStart() { + super.onStart() + dialog?.window?.setLayout( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt index 3f1a910..30ae23b 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt @@ -27,7 +27,7 @@ savedInstanceState: Bundle? ): View? { binding = FragmentInstrumentListBinding.inflate(inflater) - binding.recyclerView.adapter = InstrumentAdapter() + binding.recyclerView.adapter = InstrumentAdapter(this) binding.recyclerView.layoutManager = LinearLayoutManager(context) return binding.root } diff --git a/.idea/misc.xml b/.idea/misc.xml index 97f8bf5..0076403 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -11,6 +11,7 @@ + diff --git a/app/src/main/java/com/lukas/music/instruments/Instrument.kt b/app/src/main/java/com/lukas/music/instruments/Instrument.kt index 8ad90c6..3487ffd 100644 --- a/app/src/main/java/com/lukas/music/instruments/Instrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/Instrument.kt @@ -10,20 +10,26 @@ package com.lukas.music.instruments +import androidx.fragment.app.FragmentManager import com.lukas.music.databinding.FragmentInstrumentBinding import com.lukas.music.song.note.Note import com.lukas.music.song.voice.BassVoice import com.lukas.music.song.voice.ChordVoice import com.lukas.music.song.voice.Voice +import com.lukas.music.ui.fragments.EditInstrumentFragment -abstract class Instrument(private var name: String) { +abstract class Instrument(var name: String) { private var active = false abstract var waveform: Waveform - fun applyToView(binding: FragmentInstrumentBinding) { + fun applyToView(binding: FragmentInstrumentBinding, childFragmentManager: FragmentManager) { binding.instrumentNameText.text = name binding.editInstrumentButton.setOnClickListener { - println("click instrument $name") + EditInstrumentFragment( + this, + binding, + childFragmentManager + ).showNow(childFragmentManager, "") } binding.activeSwitch.setOnCheckedChangeListener { _, newActive -> active = newActive diff --git a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt index 8961831..8dc2310 100644 --- a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt +++ b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt @@ -19,9 +19,11 @@ import com.lukas.music.databinding.FragmentInstrumentBinding import com.lukas.music.instruments.Instrument import com.lukas.music.instruments.Waveform +import com.lukas.music.ui.fragments.InstrumentListFragment -class InstrumentAdapter : RecyclerView.Adapter() { +class InstrumentAdapter(val parent: InstrumentListFragment) : + RecyclerView.Adapter() { class InstrumentViewHolder(val binding: FragmentInstrumentBinding) : RecyclerView.ViewHolder(binding.root), AdapterView.OnItemSelectedListener { lateinit var instrument: Instrument @@ -58,7 +60,7 @@ override fun onBindViewHolder(holder: InstrumentViewHolder, position: Int) { val instrument = Instrument.instruments[position] holder.instrument = instrument - instrument.applyToView(holder.binding) + instrument.applyToView(holder.binding, parent.childFragmentManager) } override fun getItemCount(): Int { diff --git a/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt new file mode 100644 index 0000000..d933194 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2022 Lukas Eisenhauer + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or(at your option) any later version. + * + * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + */ + +package com.lukas.music.ui.fragments + +import android.os.Bundle +import android.text.Editable +import android.text.TextWatcher +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.DialogFragment +import androidx.fragment.app.FragmentManager +import com.lukas.music.databinding.FragmentEditInstrumentBinding +import com.lukas.music.databinding.FragmentInstrumentBinding +import com.lukas.music.instruments.Instrument + +class EditInstrumentFragment( + private val instrument: Instrument, + private val parent: FragmentInstrumentBinding, + private val manager: FragmentManager +) : DialogFragment() { + lateinit var binding: FragmentEditInstrumentBinding + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + binding = FragmentEditInstrumentBinding.inflate(inflater) + binding.instrumentNameTextBox.text.clear() + binding.instrumentNameTextBox.text.append(instrument.name) + binding.instrumentNameTextBox.addTextChangedListener(object : TextWatcher { + override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} + override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {} + + override fun afterTextChanged(s: Editable?) { + instrument.name = binding.instrumentNameTextBox.text.toString() + instrument.applyToView(parent, manager) + } + }) + binding.closeButton.setOnClickListener { + dismiss() + } + return binding.root + } + + override fun onStart() { + super.onStart() + dialog?.window?.setLayout( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt index 3f1a910..30ae23b 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt @@ -27,7 +27,7 @@ savedInstanceState: Bundle? ): View? { binding = FragmentInstrumentListBinding.inflate(inflater) - binding.recyclerView.adapter = InstrumentAdapter() + binding.recyclerView.adapter = InstrumentAdapter(this) binding.recyclerView.layoutManager = LinearLayoutManager(context) return binding.root } diff --git a/app/src/main/res/layout/fragment_edit_instrument.xml b/app/src/main/res/layout/fragment_edit_instrument.xml new file mode 100644 index 0000000..d398b23 --- /dev/null +++ b/app/src/main/res/layout/fragment_edit_instrument.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 97f8bf5..0076403 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -11,6 +11,7 @@ + diff --git a/app/src/main/java/com/lukas/music/instruments/Instrument.kt b/app/src/main/java/com/lukas/music/instruments/Instrument.kt index 8ad90c6..3487ffd 100644 --- a/app/src/main/java/com/lukas/music/instruments/Instrument.kt +++ b/app/src/main/java/com/lukas/music/instruments/Instrument.kt @@ -10,20 +10,26 @@ package com.lukas.music.instruments +import androidx.fragment.app.FragmentManager import com.lukas.music.databinding.FragmentInstrumentBinding import com.lukas.music.song.note.Note import com.lukas.music.song.voice.BassVoice import com.lukas.music.song.voice.ChordVoice import com.lukas.music.song.voice.Voice +import com.lukas.music.ui.fragments.EditInstrumentFragment -abstract class Instrument(private var name: String) { +abstract class Instrument(var name: String) { private var active = false abstract var waveform: Waveform - fun applyToView(binding: FragmentInstrumentBinding) { + fun applyToView(binding: FragmentInstrumentBinding, childFragmentManager: FragmentManager) { binding.instrumentNameText.text = name binding.editInstrumentButton.setOnClickListener { - println("click instrument $name") + EditInstrumentFragment( + this, + binding, + childFragmentManager + ).showNow(childFragmentManager, "") } binding.activeSwitch.setOnCheckedChangeListener { _, newActive -> active = newActive diff --git a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt index 8961831..8dc2310 100644 --- a/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt +++ b/app/src/main/java/com/lukas/music/ui/adapters/InstrumentAdapter.kt @@ -19,9 +19,11 @@ import com.lukas.music.databinding.FragmentInstrumentBinding import com.lukas.music.instruments.Instrument import com.lukas.music.instruments.Waveform +import com.lukas.music.ui.fragments.InstrumentListFragment -class InstrumentAdapter : RecyclerView.Adapter() { +class InstrumentAdapter(val parent: InstrumentListFragment) : + RecyclerView.Adapter() { class InstrumentViewHolder(val binding: FragmentInstrumentBinding) : RecyclerView.ViewHolder(binding.root), AdapterView.OnItemSelectedListener { lateinit var instrument: Instrument @@ -58,7 +60,7 @@ override fun onBindViewHolder(holder: InstrumentViewHolder, position: Int) { val instrument = Instrument.instruments[position] holder.instrument = instrument - instrument.applyToView(holder.binding) + instrument.applyToView(holder.binding, parent.childFragmentManager) } override fun getItemCount(): Int { diff --git a/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt new file mode 100644 index 0000000..d933194 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/EditInstrumentFragment.kt @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2022 Lukas Eisenhauer + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or(at your option) any later version. + * + * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + */ + +package com.lukas.music.ui.fragments + +import android.os.Bundle +import android.text.Editable +import android.text.TextWatcher +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.DialogFragment +import androidx.fragment.app.FragmentManager +import com.lukas.music.databinding.FragmentEditInstrumentBinding +import com.lukas.music.databinding.FragmentInstrumentBinding +import com.lukas.music.instruments.Instrument + +class EditInstrumentFragment( + private val instrument: Instrument, + private val parent: FragmentInstrumentBinding, + private val manager: FragmentManager +) : DialogFragment() { + lateinit var binding: FragmentEditInstrumentBinding + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + binding = FragmentEditInstrumentBinding.inflate(inflater) + binding.instrumentNameTextBox.text.clear() + binding.instrumentNameTextBox.text.append(instrument.name) + binding.instrumentNameTextBox.addTextChangedListener(object : TextWatcher { + override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} + override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {} + + override fun afterTextChanged(s: Editable?) { + instrument.name = binding.instrumentNameTextBox.text.toString() + instrument.applyToView(parent, manager) + } + }) + binding.closeButton.setOnClickListener { + dismiss() + } + return binding.root + } + + override fun onStart() { + super.onStart() + dialog?.window?.setLayout( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt index 3f1a910..30ae23b 100644 --- a/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt +++ b/app/src/main/java/com/lukas/music/ui/fragments/InstrumentListFragment.kt @@ -27,7 +27,7 @@ savedInstanceState: Bundle? ): View? { binding = FragmentInstrumentListBinding.inflate(inflater) - binding.recyclerView.adapter = InstrumentAdapter() + binding.recyclerView.adapter = InstrumentAdapter(this) binding.recyclerView.layoutManager = LinearLayoutManager(context) return binding.root } diff --git a/app/src/main/res/layout/fragment_edit_instrument.xml b/app/src/main/res/layout/fragment_edit_instrument.xml new file mode 100644 index 0000000..d398b23 --- /dev/null +++ b/app/src/main/res/layout/fragment_edit_instrument.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 55730a8..197d2c5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -34,4 +34,7 @@ Go to the next phrase Go to the start of the current phrase Next chord not known yet . . . + Edit instrument + Instrument name: + close this menu \ No newline at end of file