PlayerAndroid/app/src/main/java/code/name/monkey/retromusic/activities/tageditor/SongTagEditorActivity.kt

140 lines
4.1 KiB
Kotlin
Raw Normal View History

2019-04-20 05:29:45 +00:00
package code.name.monkey.retromusic.activities.tageditor
2018-12-06 08:52:57 +00:00
import android.net.Uri
import android.os.Bundle
2019-11-15 17:44:42 +00:00
import android.text.*
2018-12-25 14:58:47 +00:00
import androidx.core.content.ContextCompat
2018-12-06 08:52:57 +00:00
import code.name.monkey.appthemehelper.ThemeStore
2019-11-15 17:44:42 +00:00
import code.name.monkey.appthemehelper.util.*
2018-12-06 08:52:57 +00:00
import code.name.monkey.retromusic.R
2019-07-30 21:46:50 +00:00
import code.name.monkey.retromusic.extensions.appHandleColor
2018-12-06 08:52:57 +00:00
import code.name.monkey.retromusic.loaders.SongLoader
import kotlinx.android.synthetic.main.activity_song_tag_editor.*
import org.jaudiotagger.tag.FieldKey
import java.util.*
class SongTagEditorActivity : AbsTagEditorActivity(), TextWatcher {
2019-11-15 17:44:42 +00:00
override val contentViewLayout: Int
get() = R.layout.activity_song_tag_editor
private fun setupToolbar() {
appBarLayout.setBackgroundColor(ATHUtil.resolveColor(this, R.attr.colorPrimary))
toolbar.apply {
setBackgroundColor(
ATHUtil.resolveColor(
this@SongTagEditorActivity,
R.attr.colorPrimary
)
)
navigationIcon = TintHelper.createTintedDrawable(
ContextCompat.getDrawable(
context,
R.drawable.ic_keyboard_backspace_black_24dp
), ThemeStore.textColorPrimary(context)
)
setNavigationOnClickListener { onBackPressed() }
setSupportActionBar(toolbar)
}
title = null
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setNoImageMode()
setUpViews()
setupToolbar()
setStatusbarColorAuto()
}
private fun setUpViews() {
fillViewsWithFileTags()
MaterialUtil.setTint(songTextContainer, false)
MaterialUtil.setTint(composerContainer, false)
MaterialUtil.setTint(albumTextContainer, false)
MaterialUtil.setTint(artistContainer, false)
MaterialUtil.setTint(albumArtistContainer, false)
MaterialUtil.setTint(yearContainer, false)
MaterialUtil.setTint(genreContainer, false)
MaterialUtil.setTint(trackNumberContainer, false)
MaterialUtil.setTint(lyricsContainer, false)
songText.appHandleColor().addTextChangedListener(this)
albumText.appHandleColor().addTextChangedListener(this)
albumArtistText.appHandleColor().addTextChangedListener(this)
artistText.appHandleColor().addTextChangedListener(this)
genreText.appHandleColor().addTextChangedListener(this)
yearText.appHandleColor().addTextChangedListener(this)
trackNumberText.appHandleColor().addTextChangedListener(this)
lyricsText.appHandleColor().addTextChangedListener(this)
songComposerText.appHandleColor().addTextChangedListener(this)
}
private fun fillViewsWithFileTags() {
songText.setText(songTitle)
albumArtistText.setText(albumArtist)
albumText.setText(albumTitle)
artistText.setText(artistName)
genreText.setText(genreName)
yearText.setText(songYear)
trackNumberText.setText(trackNumber)
lyricsText.setText(lyrics)
songComposerText.setText(composer)
}
override fun loadCurrentImage() {
}
override fun searchImageOnWeb() {
}
override fun deleteImage() {
}
override fun save() {
val fieldKeyValueMap = EnumMap<FieldKey, String>(FieldKey::class.java)
fieldKeyValueMap[FieldKey.TITLE] = songText.text.toString()
fieldKeyValueMap[FieldKey.ALBUM] = albumText.text.toString()
fieldKeyValueMap[FieldKey.ARTIST] = artistText.text.toString()
fieldKeyValueMap[FieldKey.GENRE] = genreText.text.toString()
fieldKeyValueMap[FieldKey.YEAR] = yearText.text.toString()
fieldKeyValueMap[FieldKey.TRACK] = trackNumberText.text.toString()
fieldKeyValueMap[FieldKey.LYRICS] = lyricsText.text.toString()
fieldKeyValueMap[FieldKey.ALBUM_ARTIST] = albumArtistText.text.toString()
fieldKeyValueMap[FieldKey.COMPOSER] = songComposerText.text.toString()
writeValuesToFiles(fieldKeyValueMap, null)
}
override fun getSongPaths(): List<String> {
val paths = ArrayList<String>(1)
paths.add(SongLoader.getSong(this, id).data)
return paths
}
override fun loadImageFromFile(selectedFile: Uri?) {
}
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) {
dataChanged()
}
companion object {
val TAG: String = SongTagEditorActivity::class.java.simpleName
}
2018-12-06 08:52:57 +00:00
}
2019-07-30 21:46:50 +00:00