diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..e69de29 diff --git a/app/src/androidTest/java/io/github/teccheck/fastlyrics/ExampleInstrumentedTest.kt b/app/src/androidTest/java/io/github/teccheck/fastlyrics/ExampleInstrumentedTest.kt index 5118a7a..9d14c3e 100644 --- a/app/src/androidTest/java/io/github/teccheck/fastlyrics/ExampleInstrumentedTest.kt +++ b/app/src/androidTest/java/io/github/teccheck/fastlyrics/ExampleInstrumentedTest.kt @@ -1,13 +1,11 @@ package io.github.teccheck.fastlyrics -import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 - +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assert.* - /** * Instrumented test, which will execute on an Android device. * @@ -19,6 +17,6 @@ class ExampleInstrumentedTest { fun useAppContext() { // Context of the app under test. val appContext = InstrumentationRegistry.getInstrumentation().targetContext - assertEquals("io.github.teccheck.fastlyrics", appContext.packageName) + Assert.assertEquals("io.github.teccheck.fastlyrics", appContext.packageName) } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/BaseActivity.kt b/app/src/main/java/io/github/teccheck/fastlyrics/BaseActivity.kt index a2cde0b..e89d02a 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/BaseActivity.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/BaseActivity.kt @@ -39,4 +39,4 @@ abstract class BaseActivity : AppCompatActivity() { private fun setNightMode(mode: Int) { AppCompatDelegate.setDefaultNightMode(mode) } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/FastLyricsApp.kt b/app/src/main/java/io/github/teccheck/fastlyrics/FastLyricsApp.kt index a0de93c..60c3128 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/FastLyricsApp.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/FastLyricsApp.kt @@ -13,5 +13,4 @@ class FastLyricsApp : Application() { MediaSession.init(this) ProviderOrder.init(this) } - -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/MainActivity.kt b/app/src/main/java/io/github/teccheck/fastlyrics/MainActivity.kt index 39e7e29..051b84d 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/MainActivity.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/MainActivity.kt @@ -17,7 +17,9 @@ import io.github.teccheck.fastlyrics.ui.permission.PermissionActivity import io.github.teccheck.fastlyrics.ui.saved.SavedActivity import io.github.teccheck.fastlyrics.ui.settings.SettingsActivity -class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedListener { +class MainActivity : + BaseActivity(), + NavigationView.OnNavigationItemSelectedListener { private lateinit var appBarConfiguration: AppBarConfiguration private lateinit var navController: NavController @@ -50,23 +52,20 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList return super.onCreateOptionsMenu(menu) } - override fun onOptionsItemSelected(item: MenuItem): Boolean { - return when (item.itemId) { - R.id.app_bar_search -> { - if (navController.currentDestination?.id != R.id.nav_search) { - navController.navigate(R.id.nav_search) - } - true + override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) { + R.id.app_bar_search -> { + if (navController.currentDestination?.id != R.id.nav_search) { + navController.navigate(R.id.nav_search) } - - else -> super.onOptionsItemSelected(item) + true } - } - override fun onSupportNavigateUp(): Boolean { - return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp() + else -> super.onOptionsItemSelected(item) } + override fun onSupportNavigateUp(): Boolean = + navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp() + override fun onNavigationItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.nav_saved -> startActivity(Intent(this, SavedActivity::class.java)) @@ -80,11 +79,9 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList return false } - fun getSearchMenuItem(): MenuItem? { - return searchMenuItem - } + fun getSearchMenuItem(): MenuItem? = searchMenuItem companion object { private const val TAG = "MainActivity" } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/Settings.kt b/app/src/main/java/io/github/teccheck/fastlyrics/Settings.kt index a95062b..35fcbc6 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/Settings.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/Settings.kt @@ -16,26 +16,18 @@ class Settings(context: Context) { } @StyleRes - fun getMaterialStyle(): Int { - return when (sharedPreferences.getString(KEY_MATERIAL_STYLE, DEFAULT_MATERIAL_STYLE)) { - MATERIAL_STYLE_ONE -> R.style.Theme_FastLyrics_Material1 - MATERIAL_STYLE_TWO -> R.style.Theme_FastLyrics_Material2 - MATERIAL_STYLE_THREE -> R.style.Theme_FastLyrics_Material3 - else -> R.style.Theme_FastLyrics_Material2 - } + fun getMaterialStyle(): Int = when (sharedPreferences.getString(KEY_MATERIAL_STYLE, DEFAULT_MATERIAL_STYLE)) { + MATERIAL_STYLE_ONE -> R.style.Theme_FastLyrics_Material1 + MATERIAL_STYLE_TWO -> R.style.Theme_FastLyrics_Material2 + MATERIAL_STYLE_THREE -> R.style.Theme_FastLyrics_Material3 + else -> R.style.Theme_FastLyrics_Material2 } - fun getIsAutoRefreshEnabled(): Boolean { - return sharedPreferences.getBoolean(KEY_AUTO_REFRESH, false) - } + fun getIsAutoRefreshEnabled(): Boolean = sharedPreferences.getBoolean(KEY_AUTO_REFRESH, false) - fun getSyncedLyricsByDefault(): Boolean { - return sharedPreferences.getBoolean(KEY_SYNCED_LYRICS_BY_DEFAULT, false) - } + fun getSyncedLyricsByDefault(): Boolean = sharedPreferences.getBoolean(KEY_SYNCED_LYRICS_BY_DEFAULT, false) - fun getTextSize(): Int { - return sharedPreferences.getInt(KEY_TEXT_SIZE, 18) - } + fun getTextSize(): Int = sharedPreferences.getInt(KEY_TEXT_SIZE, 18) companion object { private const val KEY_APP_THEME = "app_theme" @@ -51,5 +43,4 @@ class Settings(context: Context) { private const val DEFAULT_APP_THEME = "-1" private const val DEFAULT_MATERIAL_STYLE = MATERIAL_STYLE_TWO } - -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/Tokens.kt b/app/src/main/java/io/github/teccheck/fastlyrics/Tokens.kt index 741ed5e..1d7b887 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/Tokens.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/Tokens.kt @@ -3,4 +3,4 @@ package io.github.teccheck.fastlyrics object Tokens { const val GENIUS_API = "ZTejoT_ojOEasIkT9WrMBhBQOz6eYKK5QULCMECmOhvwqjRZ6WbpamFe3geHnvp3" const val PETIT_LYRICS_API = "p1110417" -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/api/LyricStorage.kt b/app/src/main/java/io/github/teccheck/fastlyrics/api/LyricStorage.kt index 6f9fa90..04f4fee 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/api/LyricStorage.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/api/LyricStorage.kt @@ -4,14 +4,14 @@ import android.content.Context import android.util.Log import androidx.lifecycle.MutableLiveData import androidx.room.Room +import dev.forkhandles.result4k.Result import io.github.teccheck.fastlyrics.api.storage.LyricsDatabase import io.github.teccheck.fastlyrics.exceptions.LyricsApiException import io.github.teccheck.fastlyrics.exceptions.LyricsNotFoundException +import io.github.teccheck.fastlyrics.model.LyricsType import io.github.teccheck.fastlyrics.model.SongWithLyrics import io.github.teccheck.fastlyrics.utils.Utils import java.util.concurrent.Executors -import dev.forkhandles.result4k.Result -import io.github.teccheck.fastlyrics.model.LyricsType object LyricStorage { private const val TAG = "LyricsStorage" @@ -34,15 +34,14 @@ object LyricStorage { executor.submit { liveDataTarget.postValue( Utils.result( - database.songsDao().getAll(), LyricsNotFoundException() + database.songsDao().getAll(), + LyricsNotFoundException() ) ) } } - fun getSongAsync( - id: Long, liveDataTarget: MutableLiveData> - ) { + fun getSongAsync(id: Long, liveDataTarget: MutableLiveData>) { executor.submit { liveDataTarget.postValue( Utils.result(getSong(id), LyricsNotFoundException()) @@ -51,14 +50,14 @@ object LyricStorage { } fun store(song: SongWithLyrics) { - if (findSong(song.title, song.artist, song.type) == null) + if (findSong(song.title, song.artist, song.type) == null) { database.songsDao().insert(song) + } } private fun getSong(id: Long): SongWithLyrics? = database.songsDao().getSong(id) - fun findSong(title: String, artist: String): SongWithLyrics? = - database.songsDao().findSong(title, artist) + fun findSong(title: String, artist: String): SongWithLyrics? = database.songsDao().findSong(title, artist) fun findSong(title: String, artist: String, type: LyricsType): SongWithLyrics? = database.songsDao().findSong(title, artist, type) diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/api/LyricsApi.kt b/app/src/main/java/io/github/teccheck/fastlyrics/api/LyricsApi.kt index 298df92..77d0e34 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/api/LyricsApi.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/api/LyricsApi.kt @@ -70,9 +70,7 @@ object LyricsApi { executor.submit { liveDataTarget.postValue(provider.search(query)) } } - private fun fetchLyrics( - songMeta: SongMeta, synced: Boolean = false - ): Result { + private fun fetchLyrics(songMeta: SongMeta, synced: Boolean = false): Result { Log.d(TAG, "fetchLyrics($songMeta, $synced)") var bestResult: SearchResult? = null var bestResultScore = 0.0 @@ -106,17 +104,26 @@ object LyricsApi { private fun getResultScore(songMeta: SongMeta, searchResult: SearchResult): Double { var score = 0.0 - if (songMeta.title == searchResult.title) score += 0.5 - else if (songMeta.title.startsWith(searchResult.title)) score += 0.4 - else if (searchResult.title.startsWith(songMeta.title)) score += 0.3 + if (songMeta.title == searchResult.title) { + score += 0.5 + } else if (songMeta.title.startsWith(searchResult.title)) { + score += 0.4 + } else if (searchResult.title.startsWith(songMeta.title)) { + score += 0.3 + } - if (songMeta.artist == null) return score - else if (songMeta.artist == searchResult.artist) score += 0.5 - else if (songMeta.artist.startsWith(searchResult.artist)) score += 0.4 - else if (searchResult.artist.startsWith(songMeta.artist)) score += 0.3 + if (songMeta.artist == null) { + return score + } else if (songMeta.artist == searchResult.artist) { + score += 0.5 + } else if (songMeta.artist.startsWith(searchResult.artist)) { + score += 0.4 + } else if (searchResult.artist.startsWith(songMeta.artist)) { + score += 0.3 + } if (songMeta.album == searchResult.album) score += 0.5 return score } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/api/MediaSession.kt b/app/src/main/java/io/github/teccheck/fastlyrics/api/MediaSession.kt index c8d2686..e21ab6e 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/api/MediaSession.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/api/MediaSession.kt @@ -32,11 +32,13 @@ object MediaSession { private var initialized = false fun init(context: Context) { - if (!DummyNotificationListenerService.canAccessNotifications(context)) + if (!DummyNotificationListenerService.canAccessNotifications(context)) { return + } - if (initialized) + if (initialized) { return + } initialized = true @@ -136,14 +138,23 @@ object MediaSession { } private fun isActive(playbackState: PlaybackState?): Boolean { - if (playbackState == null) + if (playbackState == null) { return false + } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { return playbackState.isActive + } return when (playbackState.state) { - PlaybackState.STATE_FAST_FORWARDING, PlaybackState.STATE_REWINDING, PlaybackState.STATE_SKIPPING_TO_PREVIOUS, PlaybackState.STATE_SKIPPING_TO_NEXT, PlaybackState.STATE_SKIPPING_TO_QUEUE_ITEM, PlaybackState.STATE_BUFFERING, PlaybackState.STATE_CONNECTING, PlaybackState.STATE_PLAYING -> true + PlaybackState.STATE_FAST_FORWARDING, + PlaybackState.STATE_REWINDING, + PlaybackState.STATE_SKIPPING_TO_PREVIOUS, + PlaybackState.STATE_SKIPPING_TO_NEXT, + PlaybackState.STATE_SKIPPING_TO_QUEUE_ITEM, + PlaybackState.STATE_BUFFERING, + PlaybackState.STATE_CONNECTING, + PlaybackState.STATE_PLAYING -> true else -> false } } @@ -151,4 +162,4 @@ object MediaSession { fun interface SongMetaCallback { fun onSongMetaChanged(songMeta: SongMeta) } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/Deezer.kt b/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/Deezer.kt index 7d782d3..71b2e65 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/Deezer.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/Deezer.kt @@ -185,16 +185,15 @@ object Deezer : LyricsProvider { ) } - private fun parseSyncedLyrics(lines: JsonArray): String { - return lines.joinToString(separator = "\n") { - val line = it.asJsonObject - "${line.get("lrcTimestamp").asString}${line.get("line").asString}" - } + private fun parseSyncedLyrics(lines: JsonArray): String = lines.joinToString(separator = "\n") { + val line = it.asJsonObject + "${line.get("lrcTimestamp").asString}${line.get("line").asString}" } private fun getAuthToken(): String? { - if (authToken == null) authToken = - apiService.auth()?.execute()?.body()?.get(KEY_JWT)?.asString + if (authToken == null) { + authToken = apiService.auth()?.execute()?.body()?.get(KEY_JWT)?.asString + } return authToken } @@ -245,7 +244,7 @@ object Deezer : LyricsProvider { } } } - """.trimIndent() + """.trimIndent() queryJson.addProperty("query", query) return queryJson } @@ -314,8 +313,6 @@ object Deezer : LyricsProvider { fun auth(): Call? @POST("https://pipe.deezer.com/api") - fun query( - @Body body: JsonObject, @Header("Authorization") authString: String - ): Call? + fun query(@Body body: JsonObject, @Header("Authorization") authString: String): Call? } } diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/Genius.kt b/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/Genius.kt index fa31cca..bcf53c2 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/Genius.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/Genius.kt @@ -14,6 +14,7 @@ import io.github.teccheck.fastlyrics.exceptions.ParseException import io.github.teccheck.fastlyrics.model.LyricsType import io.github.teccheck.fastlyrics.model.SearchResult import io.github.teccheck.fastlyrics.model.SongWithLyrics +import java.io.IOException import okhttp3.OkHttpClient import okhttp3.Request import org.json.JSONException @@ -23,7 +24,6 @@ import retrofit2.converter.gson.GsonConverterFactory import retrofit2.http.GET import retrofit2.http.Path import retrofit2.http.Query -import java.io.IOException object Genius : LyricsProvider { @@ -184,4 +184,4 @@ object Genius : LyricsProvider { @GET("songs/{songId}") fun fetchSongInfo(@Path("songId") songId: Long): Call? } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/LrcLib.kt b/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/LrcLib.kt index f966015..1b38810 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/LrcLib.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/LrcLib.kt @@ -18,6 +18,7 @@ import io.github.teccheck.fastlyrics.model.SearchResult import io.github.teccheck.fastlyrics.model.SongMeta import io.github.teccheck.fastlyrics.model.SongWithLyrics import io.github.teccheck.fastlyrics.utils.Utils.asStringOrNull +import java.io.IOException import okhttp3.OkHttpClient import okhttp3.Request import org.json.JSONException @@ -27,7 +28,6 @@ import retrofit2.converter.gson.GsonConverterFactory import retrofit2.http.GET import retrofit2.http.Path import retrofit2.http.Query -import java.io.IOException object LrcLib : LyricsProvider { private const val TAG = "LrclibProvider" @@ -69,7 +69,10 @@ object LrcLib : LyricsProvider { try { if (songMeta.artist != null) { val call = apiService.get( - songMeta.title, songMeta.artist, songMeta.album, songMeta.duration?.div(1000) + songMeta.title, + songMeta.artist, + songMeta.album, + songMeta.duration?.div(1000) ) call?.let { it.execute().body()?.asJsonObject }?.let { @@ -92,11 +95,13 @@ object LrcLib : LyricsProvider { } val jsonBody = apiService.search( - null, songMeta.title, songMeta.artist, songMeta.album + null, + songMeta.title, + songMeta.artist, + songMeta.album )?.execute()?.body()?.asJsonArray return Success(parseSearchResults(jsonBody)) - } catch (e: IOException) { Log.e(TAG, e.message, e) return Failure(NetworkException()) @@ -167,21 +172,19 @@ object LrcLib : LyricsProvider { } } - private fun parseSongWithLyrics(json: JsonObject): SongWithLyrics { - return SongWithLyrics( - 0, - json.get(TRACK_NAME).asString, - json.get(ARTIST_NAME).asString, - json.get(LYRICS_PLAN).asString, - json.get(LYRICS_SYNCED).asStringOrNull(), - "https://lrclib.net/", - json.get(ALBUM_NAME).asString, - null, - json.get(DURATION).asLong * 1000, - LyricsType.LRC, - getName() - ) - } + private fun parseSongWithLyrics(json: JsonObject): SongWithLyrics = SongWithLyrics( + 0, + json.get(TRACK_NAME).asString, + json.get(ARTIST_NAME).asString, + json.get(LYRICS_PLAN).asString, + json.get(LYRICS_SYNCED).asStringOrNull(), + "https://lrclib.net/", + json.get(ALBUM_NAME).asString, + null, + json.get(DURATION).asLong * 1000, + LyricsType.LRC, + getName() + ) interface ApiService { @GET("search") @@ -189,7 +192,7 @@ object LrcLib : LyricsProvider { @Query("q") query: String?, @Query("track_name") trackName: String? = null, @Query("artist_name") artistName: String? = null, - @Query("album_name") albumName: String? = null, + @Query("album_name") albumName: String? = null ): Call? @GET("get") @@ -197,10 +200,10 @@ object LrcLib : LyricsProvider { @Query("track_name") trackName: String, @Query("artist_name") artistName: String, @Query("album_name") albumName: String? = null, - @Query("duration") duration: Long? = null, + @Query("duration") duration: Long? = null ): Call? @GET("get/{songId}") fun get(@Path("songId") songId: Long): Call? } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/LyricsProvider.kt b/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/LyricsProvider.kt index 40f76fd..fa6f9e0 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/LyricsProvider.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/LyricsProvider.kt @@ -32,10 +32,8 @@ interface LyricsProvider : Serializable { } companion object { - fun getAllProviders(): Array { - return arrayOf(Deezer, Genius, LrcLib, PetitLyrics, Netease) - } + fun getAllProviders(): Array = arrayOf(Deezer, Genius, LrcLib, PetitLyrics, Netease) fun getProviderByName(name: String) = getAllProviders().find { it.getName() == name } } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/Netease.kt b/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/Netease.kt index 0fc3824..0fbb541 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/Netease.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/Netease.kt @@ -78,7 +78,6 @@ object Netease : LyricsProvider { Log.e(TAG, e.message, e) return Failure(NetworkException()) } - } override fun fetchLyrics(songId: Long): Result { @@ -124,7 +123,7 @@ object Netease : LyricsProvider { @Query("limit") csRfToken: Int = 6, @Query("type") type: Int = 1, @Query("offset") offset: Int = 0, - @Query("total") total: Boolean = true, + @Query("total") total: Boolean = true ): Call @GET("song/lyric") @@ -132,7 +131,7 @@ object Netease : LyricsProvider { @Query("id") id: Long, @Query("lv") lv: Int = -1, @Query("kv") kv: Int = -1, - @Query("tv") tv: Int = -1, + @Query("tv") tv: Int = -1 ): Call } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/PetitLyrics.kt b/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/PetitLyrics.kt index fa3b22e..6187cec 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/PetitLyrics.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/api/provider/PetitLyrics.kt @@ -13,6 +13,7 @@ import io.github.teccheck.fastlyrics.model.LyricsType import io.github.teccheck.fastlyrics.model.SearchResult import io.github.teccheck.fastlyrics.model.SongMeta import io.github.teccheck.fastlyrics.model.SongWithLyrics +import javax.xml.parsers.DocumentBuilderFactory import okhttp3.ResponseBody import org.w3c.dom.Document import org.w3c.dom.Element @@ -21,7 +22,6 @@ import retrofit2.Retrofit import retrofit2.http.Field import retrofit2.http.FormUrlEncoded import retrofit2.http.POST -import javax.xml.parsers.DocumentBuilderFactory object PetitLyrics : LyricsProvider { @@ -47,7 +47,7 @@ object PetitLyrics : LyricsProvider { songMeta.title, songMeta.artist ?: "", songMeta.album ?: "", - songMeta.duration, + songMeta.duration )?.execute()?.body() ?: return Failure(LyricsNotFoundException()) return Success(wrapSearchResults(response.string())) @@ -102,7 +102,7 @@ object PetitLyrics : LyricsProvider { artist, lyrics, null, - "https://petitlyrics.com/lyrics/${lyricsId}", + "https://petitlyrics.com/lyrics/$lyricsId", album, null, null, @@ -141,4 +141,4 @@ object PetitLyrics : LyricsProvider { @Field("clientAppId") clientAppId: String = Tokens.PETIT_LYRICS_API ): Call? } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/api/storage/LyricsDatabase.kt b/app/src/main/java/io/github/teccheck/fastlyrics/api/storage/LyricsDatabase.kt index 35171b3..f32e170 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/api/storage/LyricsDatabase.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/api/storage/LyricsDatabase.kt @@ -19,16 +19,16 @@ abstract class LyricsDatabase : RoomDatabase() { companion object { val MIGRATION_3_4 = object : Migration(3, 4) { - override fun migrate(database: SupportSQLiteDatabase) { + override fun migrate(db: SupportSQLiteDatabase) { Log.d("Migration", "Start") - database.execSQL("ALTER TABLE songs ADD COLUMN lyricsPlain TEXT") - database.execSQL("ALTER TABLE songs ADD COLUMN lyricsSynced TEXT") - database.execSQL("UPDATE songs SET lyricsPlain = lyrics") - database.execSQL("UPDATE songs SET lyricsSynced = lyricsPlain WHERE type = 'LRC'") - database.execSQL("UPDATE songs SET lyricsPlain = '' WHERE type = 'LRC'") - database.execSQL("ALTER TABLE songs DROP COLUMN lyrics") + db.execSQL("ALTER TABLE songs ADD COLUMN lyricsPlain TEXT") + db.execSQL("ALTER TABLE songs ADD COLUMN lyricsSynced TEXT") + db.execSQL("UPDATE songs SET lyricsPlain = lyrics") + db.execSQL("UPDATE songs SET lyricsSynced = lyricsPlain WHERE type = 'LRC'") + db.execSQL("UPDATE songs SET lyricsPlain = '' WHERE type = 'LRC'") + db.execSQL("ALTER TABLE songs DROP COLUMN lyrics") Log.d("Migration", "End") } } } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/api/storage/SongsDao.kt b/app/src/main/java/io/github/teccheck/fastlyrics/api/storage/SongsDao.kt index ca37035..f76043b 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/api/storage/SongsDao.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/api/storage/SongsDao.kt @@ -15,7 +15,6 @@ interface SongsDao { @Query("SELECT * FROM songs WHERE title = :title AND artist = :artist") fun findSong(title: String, artist: String): SongWithLyrics? - @Query("SELECT * FROM songs WHERE title = :title AND artist = :artist AND type = :type") fun findSong(title: String, artist: String, type: LyricsType): SongWithLyrics? @@ -27,4 +26,4 @@ interface SongsDao { @Query("DELETE FROM songs WHERE id in (:ids)") fun deleteAll(ids: List) -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/GenericException.kt b/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/GenericException.kt index fa604f3..aa9f11a 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/GenericException.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/GenericException.kt @@ -1,3 +1,3 @@ package io.github.teccheck.fastlyrics.exceptions -class GenericException : LyricsApiException() \ No newline at end of file +class GenericException : LyricsApiException() diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/LyricsApiException.kt b/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/LyricsApiException.kt index 6ca276e..d864277 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/LyricsApiException.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/LyricsApiException.kt @@ -1,3 +1,3 @@ package io.github.teccheck.fastlyrics.exceptions -abstract class LyricsApiException \ No newline at end of file +abstract class LyricsApiException diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/LyricsNotFoundException.kt b/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/LyricsNotFoundException.kt index 2d7e455..72a28a9 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/LyricsNotFoundException.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/LyricsNotFoundException.kt @@ -1,3 +1,3 @@ package io.github.teccheck.fastlyrics.exceptions -class LyricsNotFoundException : LyricsApiException() \ No newline at end of file +class LyricsNotFoundException : LyricsApiException() diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/NetworkException.kt b/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/NetworkException.kt index 3be7ad1..8c01438 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/NetworkException.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/NetworkException.kt @@ -1,3 +1,3 @@ package io.github.teccheck.fastlyrics.exceptions -class NetworkException : LyricsApiException() \ No newline at end of file +class NetworkException : LyricsApiException() diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/NoMusicPlayingException.kt b/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/NoMusicPlayingException.kt index 0197f2c..eaed0f5 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/NoMusicPlayingException.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/NoMusicPlayingException.kt @@ -1,3 +1,3 @@ package io.github.teccheck.fastlyrics.exceptions -class NoMusicPlayingException : LyricsApiException() \ No newline at end of file +class NoMusicPlayingException : LyricsApiException() diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/NoNotifPermsException.kt b/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/NoNotifPermsException.kt index 77c97ae..0008f2d 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/NoNotifPermsException.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/NoNotifPermsException.kt @@ -1,3 +1,3 @@ package io.github.teccheck.fastlyrics.exceptions -class NoNotifPermsException : LyricsApiException() \ No newline at end of file +class NoNotifPermsException : LyricsApiException() diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/ParseException.kt b/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/ParseException.kt index 87c2466..9b01a4b 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/ParseException.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/exceptions/ParseException.kt @@ -1,3 +1,3 @@ package io.github.teccheck.fastlyrics.exceptions -class ParseException : LyricsApiException() \ No newline at end of file +class ParseException : LyricsApiException() diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/model/LyricsType.kt b/app/src/main/java/io/github/teccheck/fastlyrics/model/LyricsType.kt index 6ecf510..3e041c0 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/model/LyricsType.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/model/LyricsType.kt @@ -3,4 +3,4 @@ package io.github.teccheck.fastlyrics.model enum class LyricsType { RAW_TEXT, LRC -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/model/SearchResult.kt b/app/src/main/java/io/github/teccheck/fastlyrics/model/SearchResult.kt index 76950dd..3c9fb82 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/model/SearchResult.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/model/SearchResult.kt @@ -13,7 +13,6 @@ data class SearchResult( val provider: LyricsProvider, val songWithLyrics: SongWithLyrics? = null ) : Serializable { - override fun toString(): String { - return "SearchResult(title='$title', artist='$artist', album=$album, artUrl=$artUrl, url=$url, id=$id, provider=$provider, songWithLyrics=$songWithLyrics)" - } + override fun toString(): String = + "SearchResult(title='$title', artist='$artist', album=$album, artUrl=$artUrl, url=$url, id=$id, provider=$provider, songWithLyrics=$songWithLyrics)" } diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/model/SongMeta.kt b/app/src/main/java/io/github/teccheck/fastlyrics/model/SongMeta.kt index 61d78c3..d19cca5 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/model/SongMeta.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/model/SongMeta.kt @@ -7,11 +7,10 @@ data class SongMeta( val artist: String? = null, val album: String? = null, val art: Bitmap? = null, - val duration: Long? = null, + val duration: Long? = null ) { - override fun toString(): String { - return "SongMeta(title='$title', artist=$artist, album=$album, art=$art, duration=$duration)" - } + override fun toString(): String = + "SongMeta(title='$title', artist=$artist, album=$album, art=$art, duration=$duration)" override fun equals(other: Any?): Boolean { if (this === other) return true @@ -36,4 +35,4 @@ data class SongMeta( result = 31 * result + (duration?.hashCode() ?: 0) return result } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/model/SongWithLyrics.kt b/app/src/main/java/io/github/teccheck/fastlyrics/model/SongWithLyrics.kt index 6239a0b..47d5ecd 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/model/SongWithLyrics.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/model/SongWithLyrics.kt @@ -25,7 +25,6 @@ data class SongWithLyrics( @ColumnInfo(defaultValue = "genius") val provider: String ) : Serializable { - override fun toString(): String { - return "SongWithLyrics(id=$id, title='$title', artist='$artist', lyricsPlain=$lyricsPlain, lyricsSynced=$lyricsSynced, sourceUrl='$sourceUrl', album=$album, artUrl=$artUrl, type=$type, provider='$provider')" - } -} \ No newline at end of file + override fun toString(): String = + "SongWithLyrics(id=$id, title='$title', artist='$artist', lyricsPlain=$lyricsPlain, lyricsSynced=$lyricsSynced, sourceUrl='$sourceUrl', album=$album, artUrl=$artUrl, type=$type, provider='$provider')" +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/model/SyncedLyrics.kt b/app/src/main/java/io/github/teccheck/fastlyrics/model/SyncedLyrics.kt index 1ff6cd5..cb813be 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/model/SyncedLyrics.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/model/SyncedLyrics.kt @@ -41,4 +41,4 @@ object SyncedLyrics { return entries } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/service/DummyNotificationListenerService.kt b/app/src/main/java/io/github/teccheck/fastlyrics/service/DummyNotificationListenerService.kt index d13c90e..6ce2029 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/service/DummyNotificationListenerService.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/service/DummyNotificationListenerService.kt @@ -8,9 +8,8 @@ import androidx.core.app.NotificationManagerCompat class DummyNotificationListenerService : NotificationListenerService() { companion object { - fun canAccessNotifications(context: Context): Boolean { - return NotificationManagerCompat.getEnabledListenerPackages(context) + fun canAccessNotifications(context: Context): Boolean = + NotificationManagerCompat.getEnabledListenerPackages(context) .contains(context.packageName) - } } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/ui/about/AboutActivity.kt b/app/src/main/java/io/github/teccheck/fastlyrics/ui/about/AboutActivity.kt index ae2c1b8..68a0524 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/ui/about/AboutActivity.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/ui/about/AboutActivity.kt @@ -5,8 +5,8 @@ import android.net.Uri import android.os.Bundle import androidx.annotation.StringRes import androidx.recyclerview.widget.LinearLayoutManager -import io.github.teccheck.fastlyrics.BuildConfig import io.github.teccheck.fastlyrics.BaseActivity +import io.github.teccheck.fastlyrics.BuildConfig import io.github.teccheck.fastlyrics.R import io.github.teccheck.fastlyrics.databinding.ActivityAboutBinding @@ -31,4 +31,4 @@ class AboutActivity : BaseActivity() { if (urlRes == null) return startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(urlRes)))) } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/ui/about/RecyclerAdapter.kt b/app/src/main/java/io/github/teccheck/fastlyrics/ui/about/RecyclerAdapter.kt index c6fbd13..7813d95 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/ui/about/RecyclerAdapter.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/ui/about/RecyclerAdapter.kt @@ -11,8 +11,7 @@ import io.github.teccheck.fastlyrics.R import io.github.teccheck.fastlyrics.api.provider.LyricsProvider import io.github.teccheck.fastlyrics.utils.Utils -class RecyclerAdapter(private val urlOpener: UrlOpener) : - RecyclerView.Adapter() { +class RecyclerAdapter(private val urlOpener: UrlOpener) : RecyclerView.Adapter() { class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { private val icon: ImageView = view.findViewById(R.id.icon) @@ -40,4 +39,4 @@ class RecyclerAdapter(private val urlOpener: UrlOpener) : fun interface UrlOpener { fun openUrl(@StringRes linkRes: Int?) } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/ui/fastlyrics/FastLyricsFragment.kt b/app/src/main/java/io/github/teccheck/fastlyrics/ui/fastlyrics/FastLyricsFragment.kt index c1af7ac..2838813 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/ui/fastlyrics/FastLyricsFragment.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/ui/fastlyrics/FastLyricsFragment.kt @@ -10,8 +10,8 @@ import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModelProvider import com.squareup.picasso.Picasso import dev.forkhandles.result4k.Failure -import dev.forkhandles.result4k.Success import dev.forkhandles.result4k.Result +import dev.forkhandles.result4k.Success import dev.forkhandles.result4k.valueOrNull import io.github.teccheck.fastlyrics.R import io.github.teccheck.fastlyrics.Settings @@ -35,9 +35,7 @@ class FastLyricsFragment : Fragment() { private lateinit var settings: Settings - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? - ): View { + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { lyricsViewModel = ViewModelProvider(this)[FastLyricsViewModel::class.java] _binding = FragmentFastLyricsBinding.inflate(inflater, container, false) @@ -104,7 +102,10 @@ class FastLyricsFragment : Fragment() { binding.lyricsView.textLyricsProvider.setText(providerNameRes) binding.lyricsView.textLyricsProvider.setCompoundDrawablesRelativeWithIntrinsicBounds( - providerIconRes, 0, 0, 0 + providerIconRes, + 0, + 0, + 0 ) } @@ -122,7 +123,6 @@ class FastLyricsFragment : Fragment() { if (state.startRefresh) loadLyricsForCurrentSong() - // Apply settings lyricsViewModel.autoRefresh = settings.getIsAutoRefreshEnabled() @@ -132,7 +132,9 @@ class FastLyricsFragment : Fragment() { binding.lyricsView.lyricViewX.apply { setNormalTextSize( TypedValue.applyDimension( - TypedValue.COMPLEX_UNIT_SP, textSize, resources.displayMetrics + TypedValue.COMPLEX_UNIT_SP, + textSize, + resources.displayMetrics ) ) setCurrentColor(resources.getColor(R.color.theme_primary)) @@ -188,4 +190,4 @@ class FastLyricsFragment : Fragment() { companion object { private const val TAG = "FastLyricsFragment" } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/ui/fastlyrics/FastLyricsViewModel.kt b/app/src/main/java/io/github/teccheck/fastlyrics/ui/fastlyrics/FastLyricsViewModel.kt index a61723f..68e6a9b 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/ui/fastlyrics/FastLyricsViewModel.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/ui/fastlyrics/FastLyricsViewModel.kt @@ -86,4 +86,4 @@ class FastLyricsViewModel : ViewModel() { private const val TAG = "FastLyricsViewModel" private const val REFRESH_DELAY = 500L } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/ui/fastlyrics/States.kt b/app/src/main/java/io/github/teccheck/fastlyrics/ui/fastlyrics/States.kt index eef672f..6c90126 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/ui/fastlyrics/States.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/ui/fastlyrics/States.kt @@ -16,7 +16,7 @@ open class UiState( val showError: Boolean, val showText: Boolean, val isRefreshing: Boolean = false, - val startRefresh: Boolean = false, + val startRefresh: Boolean = false ) { // Header open fun getSongTitle(): String = "" @@ -73,4 +73,4 @@ class TextState(private val songMeta: SongMeta?, private val songWithLyrics: Son override fun getSourceUrl() = songWithLyrics.sourceUrl override fun getLyrics() = songWithLyrics.getLyrics(false) override fun getSyncedLyrics() = songWithLyrics.lyricsSynced -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/ui/saved/DetailsLookup.kt b/app/src/main/java/io/github/teccheck/fastlyrics/ui/saved/DetailsLookup.kt index 5e4b102..e33f70b 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/ui/saved/DetailsLookup.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/ui/saved/DetailsLookup.kt @@ -17,12 +17,11 @@ class DetailsLookup(private val recyclerView: RecyclerView) : ItemDetailsLookup< ) } - class SongWithLyricsDetails( - private val position: Int, private val itemId: Long?, val songId: Long? - ) : ItemDetails() { + class SongWithLyricsDetails(private val position: Int, private val itemId: Long?, val songId: Long?) : + ItemDetails() { override fun getPosition() = position override fun getSelectionKey() = itemId } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/ui/saved/RecyclerAdapter.kt b/app/src/main/java/io/github/teccheck/fastlyrics/ui/saved/RecyclerAdapter.kt index 64a439c..a3a4179 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/ui/saved/RecyclerAdapter.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/ui/saved/RecyclerAdapter.kt @@ -15,8 +15,7 @@ import io.github.teccheck.fastlyrics.model.SongWithLyrics import io.github.teccheck.fastlyrics.utils.PlaceholderDrawable import io.github.teccheck.fastlyrics.utils.Utils -class RecyclerAdapter : - RecyclerView.Adapter() { +class RecyclerAdapter : RecyclerView.Adapter() { private var songs: List = listOf() private var selectionTracker: SelectionTracker? = null @@ -78,4 +77,3 @@ class RecyclerAdapter : this.selectionTracker = selectionTracker } } - diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/ui/saved/SavedActivity.kt b/app/src/main/java/io/github/teccheck/fastlyrics/ui/saved/SavedActivity.kt index 655d4ed..6870643 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/ui/saved/SavedActivity.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/ui/saved/SavedActivity.kt @@ -37,17 +37,13 @@ class SavedActivity : BaseActivity() { } private val actionModeCallback = object : ActionMode.Callback { - override fun onCreateActionMode(mode: ActionMode?, menu: Menu?): Boolean { - return this@SavedActivity.onCreateActionMode(menu) - } + override fun onCreateActionMode(mode: ActionMode?, menu: Menu?): Boolean = + this@SavedActivity.onCreateActionMode(menu) - override fun onPrepareActionMode(mode: ActionMode?, menu: Menu?): Boolean { - return false - } + override fun onPrepareActionMode(mode: ActionMode?, menu: Menu?): Boolean = false - override fun onActionItemClicked(mode: ActionMode?, item: MenuItem?): Boolean { - return this@SavedActivity.onActionItemClicked(mode, item) - } + override fun onActionItemClicked(mode: ActionMode?, item: MenuItem?): Boolean = + this@SavedActivity.onActionItemClicked(mode, item) override fun onDestroyActionMode(mode: ActionMode?) { this@SavedActivity.onDestroyActionMode() @@ -98,9 +94,7 @@ class SavedActivity : BaseActivity() { selectionTracker.onRestoreInstanceState(savedInstanceState) } - private fun onItemActivated( - item: ItemDetailsLookup.ItemDetails, e: MotionEvent - ): Boolean { + private fun onItemActivated(item: ItemDetailsLookup.ItemDetails, e: MotionEvent): Boolean { (item as DetailsLookup.SongWithLyricsDetails).songId?.let { viewSong(it) } return false } @@ -124,18 +118,16 @@ class SavedActivity : BaseActivity() { return true } - private fun onActionItemClicked(mode: ActionMode?, item: MenuItem?): Boolean { - return when (item?.itemId) { - R.id.delete -> { - deleteItems(selectionTracker.selection.toList()) - viewModel.fetchSongs() - selectionTracker.clearSelection() - mode?.finish() - true - } - - else -> false + private fun onActionItemClicked(mode: ActionMode?, item: MenuItem?): Boolean = when (item?.itemId) { + R.id.delete -> { + deleteItems(selectionTracker.selection.toList()) + viewModel.fetchSongs() + selectionTracker.clearSelection() + mode?.finish() + true } + + else -> false } private fun onDestroyActionMode() { @@ -151,7 +143,9 @@ class SavedActivity : BaseActivity() { private fun deleteItems(itemIds: List) { val songIds = - itemIds.map { (binding.recyclerView.findViewHolderForItemId(it) as RecyclerAdapter.ViewHolder).getSongId()!! } + itemIds.map { + (binding.recyclerView.findViewHolderForItemId(it) as RecyclerAdapter.ViewHolder).getSongId()!! + } LyricStorage.deleteAsync(songIds) } @@ -160,4 +154,4 @@ class SavedActivity : BaseActivity() { private const val TAG = "SavedFragment" private const val SELECTION_ID = "song-selection" } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/ui/saved/SavedViewModel.kt b/app/src/main/java/io/github/teccheck/fastlyrics/ui/saved/SavedViewModel.kt index 8bb25a4..d0c8c74 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/ui/saved/SavedViewModel.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/ui/saved/SavedViewModel.kt @@ -3,10 +3,10 @@ package io.github.teccheck.fastlyrics.ui.saved import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import dev.forkhandles.result4k.Result import io.github.teccheck.fastlyrics.api.LyricStorage import io.github.teccheck.fastlyrics.exceptions.LyricsApiException import io.github.teccheck.fastlyrics.model.SongWithLyrics -import dev.forkhandles.result4k.Result class SavedViewModel : ViewModel() { private val _songs = MutableLiveData, LyricsApiException>>() @@ -15,4 +15,4 @@ class SavedViewModel : ViewModel() { fun fetchSongs() { LyricStorage.getSongsAsync(_songs) } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/DetailsLookup.kt b/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/DetailsLookup.kt index 35c2fd9..57568b0 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/DetailsLookup.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/DetailsLookup.kt @@ -13,11 +13,10 @@ class DetailsLookup(private val recyclerView: RecyclerView) : ItemDetailsLookup< return SearchResultDetails(viewHolder.adapterPosition, viewHolder.itemId) } - class SearchResultDetails(private val position: Int, private val itemId: Long?) : - ItemDetails() { + class SearchResultDetails(private val position: Int, private val itemId: Long?) : ItemDetails() { override fun getPosition() = position override fun getSelectionKey() = itemId } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/RecyclerAdapter.kt b/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/RecyclerAdapter.kt index c59a2a5..f00390c 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/RecyclerAdapter.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/RecyclerAdapter.kt @@ -12,8 +12,7 @@ import io.github.teccheck.fastlyrics.R import io.github.teccheck.fastlyrics.model.SearchResult import io.github.teccheck.fastlyrics.utils.Utils -class RecyclerAdapter : - RecyclerView.Adapter() { +class RecyclerAdapter : RecyclerView.Adapter() { private var searchResults: List = listOf() @@ -58,4 +57,3 @@ class RecyclerAdapter : notifyDataSetChanged() } } - diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/SearchFragment.kt b/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/SearchFragment.kt index 52faed1..f12616e 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/SearchFragment.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/SearchFragment.kt @@ -39,17 +39,13 @@ class SearchFragment : Fragment() { private var searchMenuItem: MenuItem? = null private var searchView: SearchView? = null - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? - ): View { + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { _binding = FragmentSearchBinding.inflate(inflater, container, false) viewModel = ViewModelProvider(this)[SearchViewModel::class.java] searchMenuItem = (activity as MainActivity).getSearchMenuItem() searchMenuItem?.setOnActionExpandListener(object : MenuItem.OnActionExpandListener { - override fun onMenuItemActionExpand(item: MenuItem): Boolean { - return true - } + override fun onMenuItemActionExpand(item: MenuItem): Boolean = true override fun onMenuItemActionCollapse(item: MenuItem): Boolean { findNavController().navigateUp() @@ -59,13 +55,9 @@ class SearchFragment : Fragment() { searchView = (searchMenuItem?.actionView as SearchView?) searchView?.setOnQueryTextListener(object : SearchView.OnQueryTextListener { - override fun onQueryTextSubmit(query: String?): Boolean { - return this@SearchFragment.onQueryTextSubmit(query) - } + override fun onQueryTextSubmit(query: String?): Boolean = this@SearchFragment.onQueryTextSubmit(query) - override fun onQueryTextChange(newText: String?): Boolean { - return this@SearchFragment.onQueryTextChange(newText) - } + override fun onQueryTextChange(newText: String?): Boolean = this@SearchFragment.onQueryTextChange(newText) }) recyclerAdapter = RecyclerAdapter() @@ -98,8 +90,9 @@ class SearchFragment : Fragment() { } private fun onQueryTextSubmit(query: String?): Boolean { - if (query?.isBlank() != false) + if (query?.isBlank() != false) { return true + } binding.progressIndicator.visibility = View.VISIBLE viewModel.search(query) @@ -111,9 +104,7 @@ class SearchFragment : Fragment() { return true } - private fun onItemActivated( - item: ItemDetailsLookup.ItemDetails, e: MotionEvent - ): Boolean { + private fun onItemActivated(item: ItemDetailsLookup.ItemDetails, e: MotionEvent): Boolean { val viewHolder = item.selectionKey?.let { binding.recyclerView.findViewHolderForItemId(it) } val searchResult = (viewHolder as RecyclerAdapter.ViewHolder).getSearchResult() searchResult?.let { viewSearchResult(it) } @@ -134,4 +125,4 @@ class SearchFragment : Fragment() { private const val TAG = "SearchFragment" private const val SELECTION_ID = "search" } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/SearchTimer.kt b/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/SearchTimer.kt index d5797df..40ab4d4 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/SearchTimer.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/SearchTimer.kt @@ -28,4 +28,4 @@ class SearchTimer(private val queryDispatcher: QueryDispatcher) { companion object { private const val TIMER_DELAY = 800.toLong() } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/SearchViewModel.kt b/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/SearchViewModel.kt index d35dc65..9c11892 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/SearchViewModel.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/SearchViewModel.kt @@ -3,9 +3,9 @@ package io.github.teccheck.fastlyrics.ui.search import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel -import io.github.teccheck.fastlyrics.exceptions.LyricsApiException import dev.forkhandles.result4k.Result import io.github.teccheck.fastlyrics.api.LyricsApi +import io.github.teccheck.fastlyrics.exceptions.LyricsApiException import io.github.teccheck.fastlyrics.model.SearchResult class SearchViewModel : ViewModel() { @@ -15,4 +15,4 @@ class SearchViewModel : ViewModel() { fun search(query: String) { LyricsApi.search(query, _searchResults) } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/SelectionPredicate.kt b/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/SelectionPredicate.kt index 128e413..9db4270 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/SelectionPredicate.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/ui/search/SelectionPredicate.kt @@ -3,15 +3,9 @@ package io.github.teccheck.fastlyrics.ui.search import androidx.recyclerview.selection.SelectionTracker class SelectionPredicate : SelectionTracker.SelectionPredicate() { - override fun canSetStateForKey(key: Long, nextState: Boolean): Boolean { - return false - } + override fun canSetStateForKey(key: Long, nextState: Boolean): Boolean = false - override fun canSetStateAtPosition(position: Int, nextState: Boolean): Boolean { - return false - } + override fun canSetStateAtPosition(position: Int, nextState: Boolean): Boolean = false - override fun canSelectMultiple(): Boolean { - return false - } -} \ No newline at end of file + override fun canSelectMultiple(): Boolean = false +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/ui/settings/ProviderRecyclerAdapter.kt b/app/src/main/java/io/github/teccheck/fastlyrics/ui/settings/ProviderRecyclerAdapter.kt index 1f56216..1683f6f 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/ui/settings/ProviderRecyclerAdapter.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/ui/settings/ProviderRecyclerAdapter.kt @@ -12,8 +12,7 @@ import io.github.teccheck.fastlyrics.api.provider.LyricsProvider import io.github.teccheck.fastlyrics.utils.ProviderOrder import io.github.teccheck.fastlyrics.utils.Utils -class ProviderRecyclerAdapter() : - RecyclerView.Adapter() { +class ProviderRecyclerAdapter : RecyclerView.Adapter() { class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { private val icon: ImageView = view.findViewById(R.id.icon) @@ -48,11 +47,9 @@ class ProviderRecyclerAdapter() : return ViewHolder(view) } - override fun getItemCount(): Int { - return ProviderOrder.getOrderCount() - } + override fun getItemCount(): Int = ProviderOrder.getOrderCount() override fun onBindViewHolder(holder: ViewHolder, position: Int) { holder.bind(ProviderOrder.getProvider(position)) } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/ui/settings/ProviderSettingsFragment.kt b/app/src/main/java/io/github/teccheck/fastlyrics/ui/settings/ProviderSettingsFragment.kt index ff0983c..6054d78 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/ui/settings/ProviderSettingsFragment.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/ui/settings/ProviderSettingsFragment.kt @@ -41,9 +41,7 @@ class ProviderSettingsFragment : Fragment() { override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {} } - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? - ): View { + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { _binding = FragmentProviderSettingsBinding.inflate(inflater, container, false) settings = Settings(requireContext()) @@ -64,4 +62,4 @@ class ProviderSettingsFragment : Fragment() { companion object { private val TAG = Companion::class.java.name } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/ui/settings/SettingsActivity.kt b/app/src/main/java/io/github/teccheck/fastlyrics/ui/settings/SettingsActivity.kt index a45f6cd..7704b45 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/ui/settings/SettingsActivity.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/ui/settings/SettingsActivity.kt @@ -23,4 +23,4 @@ class SettingsActivity : BaseActivity() { .commit() } } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/ui/settings/SettingsFragment.kt b/app/src/main/java/io/github/teccheck/fastlyrics/ui/settings/SettingsFragment.kt index f77d20d..81d0479 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/ui/settings/SettingsFragment.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/ui/settings/SettingsFragment.kt @@ -8,4 +8,4 @@ class SettingsFragment : PreferenceFragmentCompat() { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.root_preferences, rootKey) } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/ui/viewlyrics/ViewLyricsActivity.kt b/app/src/main/java/io/github/teccheck/fastlyrics/ui/viewlyrics/ViewLyricsActivity.kt index ec89c5c..1408a55 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/ui/viewlyrics/ViewLyricsActivity.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/ui/viewlyrics/ViewLyricsActivity.kt @@ -72,7 +72,10 @@ class ViewLyricsActivity : BaseActivity() { binding.lyricsView.textLyricsProvider.setText(nameRes) binding.lyricsView.textLyricsProvider.setCompoundDrawablesRelativeWithIntrinsicBounds( - providerIconRes, 0, 0, 0 + providerIconRes, + 0, + 0, + 0 ) } @@ -93,17 +96,18 @@ class ViewLyricsActivity : BaseActivity() { } } - private fun getSearchResult(intent: Intent): SearchResult? { - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + private fun getSearchResult(intent: Intent): SearchResult? = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { intent.getSerializableExtra(ARG_SEARCH_RESULT, SearchResult::class.java) } else { - @Suppress("DEPRECATION") intent.getSerializableExtra(ARG_SEARCH_RESULT) as SearchResult + @Suppress("DEPRECATION") + intent.getSerializableExtra(ARG_SEARCH_RESULT) + as SearchResult } - } companion object { private const val TAG = "ViewLyricsFragment" const val ARG_SONG_ID = "song_id" const val ARG_SEARCH_RESULT = "search_result" } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/ui/viewlyrics/ViewLyricsViewModel.kt b/app/src/main/java/io/github/teccheck/fastlyrics/ui/viewlyrics/ViewLyricsViewModel.kt index 0a0bd11..46f4b6c 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/ui/viewlyrics/ViewLyricsViewModel.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/ui/viewlyrics/ViewLyricsViewModel.kt @@ -16,13 +16,11 @@ class ViewLyricsViewModel : ViewModel() { val songWithLyrics: LiveData> = _songWithLyrics - fun loadLyricsForSongFromStorage(songId: Long) = - LyricStorage.getSongAsync(songId, _songWithLyrics) + fun loadLyricsForSongFromStorage(songId: Long) = LyricStorage.getSongAsync(songId, _songWithLyrics) - fun loadLyricsForSearchResult(searchResult: SearchResult) = - LyricsApi.getLyricsAsync(searchResult, _songWithLyrics) + fun loadLyricsForSearchResult(searchResult: SearchResult) = LyricsApi.getLyricsAsync(searchResult, _songWithLyrics) companion object { private const val TAG = "ViewLyricsViewModel" } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/utils/DebouncedMutableLiveData.kt b/app/src/main/java/io/github/teccheck/fastlyrics/utils/DebouncedMutableLiveData.kt index 2a06515..0d2664c 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/utils/DebouncedMutableLiveData.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/utils/DebouncedMutableLiveData.kt @@ -8,4 +8,4 @@ class DebouncedMutableLiveData : MutableLiveData() { super.setValue(value) } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/utils/PlaceholderDrawable.kt b/app/src/main/java/io/github/teccheck/fastlyrics/utils/PlaceholderDrawable.kt index bf05e38..5e3bc14 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/utils/PlaceholderDrawable.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/utils/PlaceholderDrawable.kt @@ -9,7 +9,9 @@ class PlaceholderDrawable(context: Context, @DrawableRes drawable: Int) : LayerDrawable( arrayOf( context.resources.getDrawable(R.color.art_placeholder_background), - context.getDrawable(drawable)?.apply { setTint(context.resources.getColor(R.color.art_placeholder_foreground)) } + context.getDrawable(drawable)?.apply { + setTint(context.resources.getColor(R.color.art_placeholder_foreground)) + } ) ) { @@ -17,4 +19,4 @@ class PlaceholderDrawable(context: Context, @DrawableRes drawable: Int) : val padding = context.resources.getDimension(R.dimen.placeholder_drawable_padding).toInt() this.setLayerInset(1, padding, padding, padding, padding) } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/utils/ProviderOrder.kt b/app/src/main/java/io/github/teccheck/fastlyrics/utils/ProviderOrder.kt index 28e9067..d08b2dc 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/utils/ProviderOrder.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/utils/ProviderOrder.kt @@ -26,9 +26,7 @@ object ProviderOrder { this.enabled[provider] = enabled } - fun getEnabled(provider: LyricsProvider): Boolean { - return this.enabled[provider] ?: false - } + fun getEnabled(provider: LyricsProvider): Boolean = this.enabled[provider] ?: false fun getOrderCount(): Int = order.size @@ -52,13 +50,14 @@ object ProviderOrder { val editor = sharedPreferences.edit() this.order.forEachIndexed { index, lyricsProvider -> editor.putInt( - orderKey(lyricsProvider.getName()), index + orderKey(lyricsProvider.getName()), + index ) } this.enabled.forEach { editor.putBoolean(enabledKey(it.key.getName()), it.value) } editor.apply() } - private fun orderKey(name: String) = "${KEY_PREFIX_PROVIDER_ORDER}_${name}" - private fun enabledKey(name: String) = "${KEY_PREFIX_PROVIDER_ENABLED}_${name}" -} \ No newline at end of file + private fun orderKey(name: String) = "${KEY_PREFIX_PROVIDER_ORDER}_$name" + private fun enabledKey(name: String) = "${KEY_PREFIX_PROVIDER_ENABLED}_$name" +} diff --git a/app/src/main/java/io/github/teccheck/fastlyrics/utils/Utils.kt b/app/src/main/java/io/github/teccheck/fastlyrics/utils/Utils.kt index e329291..fd1a852 100644 --- a/app/src/main/java/io/github/teccheck/fastlyrics/utils/Utils.kt +++ b/app/src/main/java/io/github/teccheck/fastlyrics/utils/Utils.kt @@ -30,9 +30,10 @@ import io.github.teccheck.fastlyrics.model.SongWithLyrics import io.github.teccheck.fastlyrics.model.SyncedLyrics object Utils { - fun result(value: T?, exception: E): Result { - return if (value == null) Failure(exception) - else Success(value) + fun result(value: T?, exception: E): Result = if (value == null) { + Failure(exception) + } else { + Success(value) } fun View.setVisible(visible: Boolean) { @@ -43,8 +44,7 @@ object Utils { ContextCompat.getSystemService(context, ClipboardManager::class.java) ?.setPrimaryClip(ClipData.newPlainText(title, text)) - fun openLink(context: Context, link: String) = - context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link))) + fun openLink(context: Context, link: String) = context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link))) fun share(context: Context, songTitle: String, artist: String, text: String) { val title = context.getString(R.string.share_title, songTitle, artist) @@ -57,13 +57,15 @@ object Utils { if (lyricsPlain != null) return lyricsPlain - if (lyricsSynced != null) return SyncedLyrics.parseLrcToList(lyricsSynced) - .joinToString("\n") { it.text } + if (lyricsSynced != null) { + return SyncedLyrics.parseLrcToList(lyricsSynced) + .joinToString("\n") { it.text } + } return "" } - fun JsonElement.asStringOrNull() : String? { + fun JsonElement.asStringOrNull(): String? { if (this.isJsonNull) return null return this.asString } @@ -118,4 +120,4 @@ object Utils { is NoMusicPlayingException -> R.drawable.outline_music_off_24 else -> R.drawable.baseline_error_outline_24 } -} \ No newline at end of file +} diff --git a/app/src/test/java/io/github/teccheck/fastlyrics/ExampleUnitTest.kt b/app/src/test/java/io/github/teccheck/fastlyrics/ExampleUnitTest.kt index 23bc2f4..86a9d0f 100644 --- a/app/src/test/java/io/github/teccheck/fastlyrics/ExampleUnitTest.kt +++ b/app/src/test/java/io/github/teccheck/fastlyrics/ExampleUnitTest.kt @@ -1,9 +1,8 @@ package io.github.teccheck.fastlyrics +import org.junit.Assert import org.junit.Test -import org.junit.Assert.* - /** * Example local unit test, which will execute on the development machine (host). * @@ -12,6 +11,6 @@ import org.junit.Assert.* class ExampleUnitTest { @Test fun addition_isCorrect() { - assertEquals(4, 2 + 2) + Assert.assertEquals(4, 2 + 2) } -} \ No newline at end of file +}