add an option to use filename as song title if the title isnt available
This commit is contained in:
parent
0b036f299b
commit
1bd07a6c34
20 changed files with 98 additions and 18 deletions
|
@ -45,7 +45,7 @@ ext {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:3.10.10'
|
||||
implementation 'com.simplemobiletools:commons:3.10.13'
|
||||
implementation 'com.squareup:otto:1.3.8'
|
||||
implementation 'com.facebook.stetho:stetho:1.5.0'
|
||||
|
||||
|
|
|
@ -9,6 +9,9 @@ import com.simplemobiletools.commons.extensions.useEnglishToggled
|
|||
import com.simplemobiletools.commons.models.RadioItem
|
||||
import com.simplemobiletools.musicplayer.R
|
||||
import com.simplemobiletools.musicplayer.extensions.config
|
||||
import com.simplemobiletools.musicplayer.helpers.SHOW_FILENAME_ALWAYS
|
||||
import com.simplemobiletools.musicplayer.helpers.SHOW_FILENAME_IF_UNAVAILABLE
|
||||
import com.simplemobiletools.musicplayer.helpers.SHOW_FILENAME_NEVER
|
||||
import com.simplemobiletools.musicplayer.services.MusicService
|
||||
import kotlinx.android.synthetic.main.activity_settings.*
|
||||
import java.util.*
|
||||
|
@ -28,6 +31,7 @@ class SettingsActivity : SimpleActivity() {
|
|||
setupAvoidWhatsNew()
|
||||
setupShowInfoBubble()
|
||||
setupEqualizer()
|
||||
setupReplaceTitle()
|
||||
updateTextColors(settings_scrollview)
|
||||
}
|
||||
|
||||
|
@ -82,4 +86,25 @@ class SettingsActivity : SimpleActivity() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupReplaceTitle() {
|
||||
settings_show_filename.text = getShowFilenameText()
|
||||
settings_show_filename_holder.setOnClickListener {
|
||||
val items = arrayListOf(
|
||||
RadioItem(SHOW_FILENAME_NEVER, getString(R.string.never)),
|
||||
RadioItem(SHOW_FILENAME_IF_UNAVAILABLE, getString(R.string.title_is_not_available)),
|
||||
RadioItem(SHOW_FILENAME_ALWAYS, getString(R.string.always)))
|
||||
|
||||
RadioGroupDialog(this@SettingsActivity, items, config.showFilename) {
|
||||
config.showFilename = it as Int
|
||||
settings_show_filename.text = getShowFilenameText()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getShowFilenameText() = getString(when (config.showFilename) {
|
||||
SHOW_FILENAME_NEVER -> R.string.never
|
||||
SHOW_FILENAME_IF_UNAVAILABLE -> R.string.title_is_not_available
|
||||
else -> R.string.always
|
||||
})
|
||||
}
|
||||
|
|
|
@ -42,4 +42,8 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
currIgnoredPaths.addAll(paths)
|
||||
ignoredPaths = currIgnoredPaths
|
||||
}
|
||||
|
||||
var showFilename: Int
|
||||
get() = prefs.getInt(SHOW_FILENAME, SHOW_FILENAME_IF_UNAVAILABLE)
|
||||
set(showFilename) = prefs.edit().putInt(SHOW_FILENAME, showFilename).apply()
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ const val REPEAT_SONG = "repeat_song"
|
|||
const val AUTOPLAY = "autoplay"
|
||||
const val IGNORED_PATHS = "ignored_paths"
|
||||
const val CURRENT_PLAYLIST = "current_playlist"
|
||||
const val SHOW_FILENAME = "show_filename"
|
||||
|
||||
// sorting
|
||||
const val SORT_BY_TITLE = 1
|
||||
|
@ -39,3 +40,7 @@ const val SORT_BY_DURATION = 8
|
|||
|
||||
const val LIST_HEADERS_COUNT = 2
|
||||
const val LOWER_ALPHA = 0.5f
|
||||
|
||||
const val SHOW_FILENAME_NEVER = 1
|
||||
const val SHOW_FILENAME_IF_UNAVAILABLE = 2
|
||||
const val SHOW_FILENAME_ALWAYS = 3
|
||||
|
|
|
@ -241,6 +241,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
|
||||
val ITEMS_PER_GROUP = 50
|
||||
val songs = ArrayList<Song>(paths.size)
|
||||
val showFilename = context.config.showFilename
|
||||
|
||||
val parts = paths.size / ITEMS_PER_GROUP
|
||||
for (i in 0..parts) {
|
||||
|
@ -260,7 +261,8 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
val path = cursor.getStringValue(MediaStore.Audio.Media.DATA)
|
||||
val duration = cursor.getIntValue(MediaStore.Audio.Media.DURATION) / 1000
|
||||
val album = cursor.getStringValue(MediaStore.Audio.Media.ALBUM)
|
||||
val song = Song(id, title, artist, path, duration, album)
|
||||
val newTitle = getSongTitle(title, showFilename, path)
|
||||
val song = Song(id, newTitle, artist, path, duration, album)
|
||||
songs.add(song)
|
||||
pathsMap.remove(path)
|
||||
} while (cursor.moveToNext())
|
||||
|
@ -272,8 +274,9 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
|
||||
pathsMap.forEach {
|
||||
val file = File(it)
|
||||
val unknown = context.getString(R.string.unknown)
|
||||
val song = Song(0, file.getSongTitle() ?: unknown, file.getArtist() ?: unknown, it, file.getDurationSeconds(), "")
|
||||
val unknown = MediaStore.UNKNOWN_STRING
|
||||
val title = file.getSongTitle() ?: unknown
|
||||
val song = Song(0, getSongTitle(title, showFilename, it), file.getArtist() ?: unknown, it, file.getDurationSeconds(), "")
|
||||
songs.add(song)
|
||||
}
|
||||
|
||||
|
@ -281,4 +284,12 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
}
|
||||
|
||||
private fun getQuestionMarks(cnt: Int) = "?" + ",?".repeat(Math.max(cnt - 1, 0))
|
||||
|
||||
private fun getSongTitle(title: String, showFilename: Int, path: String): String {
|
||||
return when (showFilename) {
|
||||
SHOW_FILENAME_NEVER -> title
|
||||
SHOW_FILENAME_IF_UNAVAILABLE -> if (title == MediaStore.UNKNOWN_STRING) path.getFilenameFromPath() else title
|
||||
else -> path.getFilenameFromPath()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -143,5 +143,40 @@
|
|||
android:clickable="false"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_show_filename_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/medium_margin"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:paddingBottom="@dimen/bigger_margin"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/bigger_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/settings_show_filename_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toLeftOf="@+id/settings_show_filename"
|
||||
android:layout_toStartOf="@+id/settings_show_filename"
|
||||
android:paddingLeft="@dimen/medium_margin"
|
||||
android:paddingRight="@dimen/medium_margin"
|
||||
android:text="@string/show_filename"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/settings_show_filename"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_marginEnd="@dimen/small_margin"
|
||||
android:layout_marginRight="@dimen/small_margin"
|
||||
android:background="@null"
|
||||
android:clickable="false"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<string name="folder_contains_no_audio">Der ausgewählte Ordner enthält keine Audiodateien</string>
|
||||
<string name="delete_current_song">Aktuellen Song löschen</string>
|
||||
<string name="remove_current_song">Aktuellen Song aus Playlist entfernen</string>
|
||||
<string name="show_filename">Verwende Dateinamen als Songtitel</string>
|
||||
<string name="show_filename">Verwende Dateinamen als Songtitel:</string>
|
||||
<string name="title_is_not_available">Titel nicht verfügbar</string>
|
||||
|
||||
<!-- Settings -->
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<string name="folder_contains_no_audio">The selected folder contains no audio files</string>
|
||||
<string name="delete_current_song">Delete current song</string>
|
||||
<string name="remove_current_song">Remove current song from playlist</string>
|
||||
<string name="show_filename">Show filename as song title if</string>
|
||||
<string name="show_filename">Show filename as song title if:</string>
|
||||
<string name="title_is_not_available">Title is not available</string>
|
||||
|
||||
<!-- Settings -->
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<string name="folder_contains_no_audio">O cartafol seleccionado non contén ficheiros de audio</string>
|
||||
<string name="delete_current_song">Delete current song</string>
|
||||
<string name="remove_current_song">Remove current song from playlist</string>
|
||||
<string name="show_filename">Show filename as song title if</string>
|
||||
<string name="show_filename">Show filename as song title if:</string>
|
||||
<string name="title_is_not_available">Title is not available</string>
|
||||
|
||||
<!-- Settings -->
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<string name="folder_contains_no_audio">The selected folder contains no audio files</string>
|
||||
<string name="delete_current_song">Delete current song</string>
|
||||
<string name="remove_current_song">Remove current song from playlist</string>
|
||||
<string name="show_filename">Show filename as song title if</string>
|
||||
<string name="show_filename">Show filename as song title if:</string>
|
||||
<string name="title_is_not_available">Title is not available</string>
|
||||
|
||||
<!-- Settings -->
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<string name="folder_contains_no_audio">The selected folder contains no audio files</string>
|
||||
<string name="delete_current_song">Delete current song</string>
|
||||
<string name="remove_current_song">Remove current song from playlist</string>
|
||||
<string name="show_filename">Show filename as song title if</string>
|
||||
<string name="show_filename">Show filename as song title if:</string>
|
||||
<string name="title_is_not_available">Title is not available</string>
|
||||
|
||||
<!-- Settings -->
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<string name="folder_contains_no_audio">The selected folder contains no audio files</string>
|
||||
<string name="delete_current_song">Delete current song</string>
|
||||
<string name="remove_current_song">Remove current song from playlist</string>
|
||||
<string name="show_filename">Show filename as song title if</string>
|
||||
<string name="show_filename">Show filename as song title if:</string>
|
||||
<string name="title_is_not_available">Title is not available</string>
|
||||
|
||||
<!-- Settings -->
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<string name="folder_contains_no_audio">선택된 폴더에는 오디오파일이 없습니다.</string>
|
||||
<string name="delete_current_song">Delete current song</string>
|
||||
<string name="remove_current_song">Remove current song from playlist</string>
|
||||
<string name="show_filename">Show filename as song title if</string>
|
||||
<string name="show_filename">Show filename as song title if:</string>
|
||||
<string name="title_is_not_available">Title is not available</string>
|
||||
|
||||
<!-- Settings -->
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<string name="folder_contains_no_audio">De geselecteerde map bevat geen geluidsbestanden</string>
|
||||
<string name="delete_current_song">Huidige nummer verwijderen</string>
|
||||
<string name="remove_current_song">Huidige nummer uit afspeellijst verwijderen</string>
|
||||
<string name="show_filename">Bestandsnaam als titel tonen als</string>
|
||||
<string name="show_filename">Bestandsnaam als titel tonen als:</string>
|
||||
<string name="title_is_not_available">Titel niet beschikbaar</string>
|
||||
|
||||
<!-- Settings -->
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<string name="folder_contains_no_audio">Wybrany folder nie zawiera plików audio</string>
|
||||
<string name="delete_current_song">Delete current song</string>
|
||||
<string name="remove_current_song">Remove current song from playlist</string>
|
||||
<string name="show_filename">Show filename as song title if</string>
|
||||
<string name="show_filename">Show filename as song title if:</string>
|
||||
<string name="title_is_not_available">Title is not available</string>
|
||||
|
||||
<!-- Settings -->
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<string name="folder_contains_no_audio">A pasta selecionada não contém ficheiros de áudio</string>
|
||||
<string name="delete_current_song">Delete current song</string>
|
||||
<string name="remove_current_song">Remove current song from playlist</string>
|
||||
<string name="show_filename">Show filename as song title if</string>
|
||||
<string name="show_filename">Show filename as song title if:</string>
|
||||
<string name="title_is_not_available">Title is not available</string>
|
||||
|
||||
<!-- Settings -->
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<string name="folder_contains_no_audio">Выбранная папка не содержит аудиофайлов</string>
|
||||
<string name="delete_current_song">Delete current song</string>
|
||||
<string name="remove_current_song">Remove current song from playlist</string>
|
||||
<string name="show_filename">Show filename as song title if</string>
|
||||
<string name="show_filename">Show filename as song title if:</string>
|
||||
<string name="title_is_not_available">Title is not available</string>
|
||||
|
||||
<!-- Settings -->
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<string name="folder_contains_no_audio">Zvolený priečinok neobsahuje žiadne audio súbory</string>
|
||||
<string name="delete_current_song">Vymazať súčasnú skladbu</string>
|
||||
<string name="remove_current_song">Odstrániť súčasnú skladbu zo zoznamu skladieb</string>
|
||||
<string name="show_filename">Zobraziť názov súboru namiesto názvu skladby ak</string>
|
||||
<string name="show_filename">Zobraziť názov súboru namiesto názvu skladby ak:</string>
|
||||
<string name="title_is_not_available">Názov skladby nie je dostupý</string>
|
||||
|
||||
<!-- Settings -->
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<string name="folder_contains_no_audio">Den valda mappen innehåller inga ljudfiler</string>
|
||||
<string name="delete_current_song">Delete current song</string>
|
||||
<string name="remove_current_song">Remove current song from playlist</string>
|
||||
<string name="show_filename">Show filename as song title if</string>
|
||||
<string name="show_filename">Show filename as song title if:</string>
|
||||
<string name="title_is_not_available">Title is not available</string>
|
||||
|
||||
<!-- Settings -->
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<string name="folder_contains_no_audio">The selected folder contains no audio files</string>
|
||||
<string name="delete_current_song">Delete current song</string>
|
||||
<string name="remove_current_song">Remove current song from playlist</string>
|
||||
<string name="show_filename">Show filename as song title if</string>
|
||||
<string name="show_filename">Show filename as song title if:</string>
|
||||
<string name="title_is_not_available">Title is not available</string>
|
||||
|
||||
<!-- Settings -->
|
||||
|
|
Loading…
Reference in a new issue