Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added Quick Lyrics Search Activity #108

Merged
merged 13 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

2 changes: 1 addition & 1 deletion .idea/misc.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 @@ -89,6 +89,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
BobbyESP marked this conversation as resolved.
Show resolved Hide resolved
}
16 changes: 16 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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
Loading