Skip to content

Commit

Permalink
Merge pull request #108 from BobbyESP/master
Browse files Browse the repository at this point in the history
feat: Added Quick Lyrics Search Activity
  • Loading branch information
Lambada10 authored Nov 28, 2024
2 parents e5a3aae + 5f6b1e1 commit b72e3a2
Show file tree
Hide file tree
Showing 28 changed files with 1,798 additions and 47 deletions.
5 changes: 5 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ plugins {

android {
namespace = "pl.lambada.songsync"
compileSdk = 34
compileSdk = 35

defaultConfig {
applicationId = "pl.lambada.songsync"
minSdk = 21
//noinspection OldTargetApi
targetSdk = 34
targetSdk = 35
versionCode = 421
versionName = "4.2.1"

Expand Down Expand Up @@ -88,6 +88,6 @@ dependencies {
implementation(libs.ktor.cio)
implementation(libs.taglib)
implementation(libs.datastore.preferences)
debugImplementation(libs.ui.tooling)
debugImplementation(libs.ui.tooling.preview)
implementation(libs.ui.tooling) //NOT RECOMMENDED
implementation(libs.ui.tooling.preview) //NOT RECOMMENDED
}
16 changes: 16 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@
</intent-filter>
</activity>

<activity
android:name=".activities.quicksearch.QuickLyricsSearchActivity"
android:exported="true"
android:excludeFromRecents="true"
android:launchMode="singleInstance"
android:theme="@style/Theme.SongSync.SharingActivity"
android:label="Quick Lyrics Search">

<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />

<data android:mimeType="text/plain" />
</intent-filter>
</activity>

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package pl.lambada.songsync.activities.quicksearch

import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.ModalBottomSheetDefaults
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import coil.ImageLoader
import coil.disk.DiskCache
import coil.memory.MemoryCache
import kotlinx.coroutines.Dispatchers
import pl.lambada.songsync.R
import pl.lambada.songsync.activities.quicksearch.viewmodel.QuickLyricsSearchViewModel
import pl.lambada.songsync.activities.quicksearch.viewmodel.QuickLyricsSearchViewModelFactory
import pl.lambada.songsync.data.UserSettingsController
import pl.lambada.songsync.data.remote.lyrics_providers.LyricsProviderService
import pl.lambada.songsync.ui.theme.SongSyncTheme
import pl.lambada.songsync.util.dataStore

class QuickLyricsSearchActivity : AppCompatActivity() {
private val lyricsProviderService = LyricsProviderService()


@OptIn(ExperimentalMaterial3Api::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val userSettingsController = UserSettingsController(dataStore)
val viewModel: QuickLyricsSearchViewModel by viewModels {
QuickLyricsSearchViewModelFactory(userSettingsController, lyricsProviderService)
}
activityImageLoader = ImageLoader.Builder(this)
.memoryCache {
MemoryCache.Builder(this)
.maxSizePercent(0.35)
.build()
}
.diskCache {
DiskCache.Builder()
.directory(this.cacheDir.resolve("image_cache"))
.maxSizeBytes(7 * 1024 * 1024)
.build()
}
.respectCacheHeaders(false)
.allowHardware(true)
.crossfade(true)
.bitmapFactoryMaxParallelism(12)
.dispatcher(Dispatchers.IO)
.build()

enableEdgeToEdge()
handleShareIntent(intent, sendEvent = viewModel::onEvent)

setContent {
val sheetState = rememberModalBottomSheetState()
val viewModelState = viewModel.state.collectAsStateWithLifecycle()
SongSyncTheme(pureBlack = userSettingsController.pureBlack) {
ModalBottomSheet(
sheetState = sheetState,
properties = ModalBottomSheetDefaults.properties,
onDismissRequest = { finish() }
) {
QuickLyricsSearchPage(
state = viewModelState,
onSendLyrics = { lyrics ->
val resultIntent = Intent().apply {
action = Intent.ACTION_SEND
putExtra("lyrics", lyrics)
type = "text/plain"
}
setResult(RESULT_OK, resultIntent)
finish()
}
)
}
}
}
}


private fun handleShareIntent(
intent: Intent,
sendEvent: (QuickLyricsSearchViewModel.Event) -> Unit
) {
when (intent.action) {
Intent.ACTION_SEND -> {
val songName =
intent.getStringExtra("songName")
val artistName = intent.getStringExtra("artistName")
?: "" // Artist name is optional. This may be misleading sometimes.

if (songName.isNullOrBlank()) {
Toast.makeText(
this,
this.getString(R.string.song_name_not_provided),
Toast.LENGTH_SHORT
).show()
finish()
return
}

sendEvent(
QuickLyricsSearchViewModel.Event.Fetch(
song = songName to artistName,
context = this
)
)
}
}
}

companion object {
lateinit var activityImageLoader: ImageLoader
lateinit var userSettingsController: UserSettingsController
}
}
Loading

0 comments on commit b72e3a2

Please sign in to comment.