Skip to content

Commit

Permalink
v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
youlalala committed Dec 1, 2023
2 parents 1087d23 + 35e05ec commit 62f5ec4
Show file tree
Hide file tree
Showing 150 changed files with 3,171 additions and 568 deletions.
12 changes: 8 additions & 4 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import java.util.Properties
import java.io.FileInputStream
import java.util.Properties

@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
Expand All @@ -14,14 +14,14 @@ keystoreProperties.load(FileInputStream(keystorePropertiesFile))

android {
namespace = "com.ohdodok.catchytape"
compileSdk = 33
compileSdk = 34

defaultConfig {
applicationId = "com.ohdodok.catchytape"
minSdk = 26
targetSdk = 33
versionCode = 1
versionName = "0.1.0"
versionCode = 2
versionName = "0.2.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -64,6 +64,8 @@ dependencies {
implementation(project(":feature:login"))
implementation(project(":feature:upload"))
implementation(project(":feature:player"))
implementation(project(":feature:playlist"))
implementation(project(":feature:mypage"))
implementation(project(":core:data"))

implementation(libs.core.ktx)
Expand All @@ -75,4 +77,6 @@ dependencies {
implementation(libs.timber)

testImplementation(libs.junit)

implementation(libs.media3.session)
}
17 changes: 12 additions & 5 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<application
android:name=".CtApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/Theme.CatchyTape">
android:theme="@style/Theme.CatchyTape"
android:usesCleartextTraffic="true">
<activity
android:name=".feature.login.LoginActivity"
android:exported="true">
Expand All @@ -22,12 +23,18 @@
</intent-filter>
</activity>


<activity
android:name=".MainActivity"
android:exported="true">
</activity>
android:exported="true" />

<service
android:name=".mediacontrol.PlaybackService"
android:exported="true"
android:foregroundServiceType="mediaPlayback">
<intent-filter>
<action android:name="androidx.media3.session.MediaSessionService" />
</intent-filter>
</service>

</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ class CtApplication : Application() {
super.onCreate()
if (BuildConfig.DEBUG) {
Timber.plant(object : Timber.DebugTree() {
override fun d(message: String?, vararg args: Any?) {
if (message != null && message.isEmpty()) {
super.d(getString(R.string.timber_blank_string), *args)
} else {
super.d(message, *args)
}
}

override fun createStackElementTag(element: StackTraceElement): String {
return String.format(
Expand Down
119 changes: 118 additions & 1 deletion android/app/src/main/java/com/ohdodok/catchytape/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,26 +1,72 @@
package com.ohdodok.catchytape

import android.content.ComponentName
import android.net.ConnectivityManager
import android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.session.MediaController
import androidx.media3.session.SessionToken
import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.fragment.findNavController
import androidx.navigation.ui.setupWithNavController
import com.ohdodok.catchytape.databinding.ActivityMainBinding
import com.ohdodok.catchytape.feature.player.PlayerListener
import com.ohdodok.catchytape.feature.player.PlayerViewModel
import com.ohdodok.catchytape.mediacontrol.PlaybackService
import com.ohdodok.catchytape.feature.player.millisecondsPerSecond
import com.ohdodok.catchytape.feature.player.navigateToPlayer
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import javax.inject.Inject
import com.ohdodok.catchytape.core.ui.R.string as uiString

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

@Inject
lateinit var player: ExoPlayer
private lateinit var binding: ActivityMainBinding
private lateinit var connectivityManager: ConnectivityManager
private val playViewModel: PlayerViewModel by viewModels()


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.viewModel = playViewModel
binding.lifecycleOwner = this

setupBottomNav()
setUpPlayerController()
connectivityManager = getSystemService(ConnectivityManager::class.java)
checkNetworkState()

val networkStateObserver = NetworkStateObserver(connectivityManager, ::checkNetworkState)
lifecycle.addObserver(networkStateObserver)

setupPlayer()
setupPlayButton()
}

override fun onStart() {
super.onStart()
connectToMediaSession()
}

private fun connectToMediaSession() {
val sessionToken = SessionToken(this, ComponentName(this, PlaybackService::class.java))
MediaController.Builder(this, sessionToken).buildAsync()
}

private fun checkNetworkState() {
Expand All @@ -32,4 +78,75 @@ class MainActivity : AppCompatActivity() {
Toast.makeText(this, getString(uiString.check_network), Toast.LENGTH_LONG).show()
}
}

private fun setupBottomNav() {
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
binding.bottomNav.setupWithNavController(navHostFragment.navController)

navHostFragment.findNavController().addOnDestinationChangedListener { _, destination, _ ->
when (destination.id) {
com.ohdodok.catchytape.feature.player.R.id.player_fragment -> {
hideBottomNav()
hidePlayerController()
}

else -> {
showBottomNav()
showPlayerController()
}
}
}
}

private fun setUpPlayerController() {
binding.pcvController.setOnClickListener {
binding.navHostFragment.findNavController().navigateToPlayer()
}
}

private fun hideBottomNav() {
binding.bottomNav.visibility = View.GONE
}

private fun showBottomNav() {
binding.bottomNav.visibility = View.VISIBLE
}

private fun hidePlayerController() {
binding.pcvController.visibility = View.GONE
}

private fun showPlayerController() {
binding.pcvController.visibility = View.VISIBLE
}


private fun setupPlayer() {
player.addListener(PlayerListener(playViewModel))
player.prepare()
setupPlayerTimer()
}

private fun setupPlayerTimer() {
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
while (true) {
delay(1000L)
if (player.isPlaying) {
val positionMs = player.currentPosition.toInt()
playViewModel.updateCurrentPosition(positionMs / millisecondsPerSecond)
}
}
}
}
}


private fun setupPlayButton() {
binding.pcvController.setOnPlayButtonClick {
if (playViewModel.uiState.value.isPlaying) player.pause()
else player.play()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.ohdodok.catchytape.mediacontrol

import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.session.MediaSession
import androidx.media3.session.MediaSessionService
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class PlaybackService : MediaSessionService() {

private var mediaSession: MediaSession? = null
@Inject lateinit var player: ExoPlayer

override fun onCreate() {
super.onCreate()
mediaSession = MediaSession.Builder(this, player).build()
}

override fun onDestroy() {
mediaSession?.run {
player.release()
release()
mediaSession = null
}
super.onDestroy()
}

override fun onGetSession(
controllerInfo: MediaSession.ControllerInfo
): MediaSession? = mediaSession

}
2 changes: 1 addition & 1 deletion android/app/src/main/res/drawable/ic_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<group>
<clip-path android:pathData="M0,0h24v24h-24z" />
<path
android:fillColor="#212121"
android:fillColor="@color/on_surface"
android:fillType="evenOdd"
android:pathData="M10.772,0.688C11.123,0.415 11.555,0.267 12,0.267C12.445,0.267 12.877,0.415 13.228,0.688L21.612,7.208C22.365,7.795 21.949,9 20.997,9H20V17C20,17.53 19.789,18.039 19.414,18.414C19.039,18.789 18.53,19 18,19H6C5.47,19 4.961,18.789 4.586,18.414C4.211,18.039 4,17.53 4,17V9H3.003C2.05,9 1.636,7.794 2.388,7.209L10.772,0.688ZM5.625,7.225C5.854,7.41 6,7.693 6,8.01V17H18V8.01C18,7.693 18.146,7.41 18.375,7.225L12,2.267L5.625,7.225Z" />
</group>
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/res/drawable/ic_home_filled.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<group>
<clip-path android:pathData="M0,0h24v24h-24z" />
<path
android:fillColor="#212121"
android:fillColor="@color/on_surface"
android:fillType="evenOdd"
android:pathData="M10.772,2.688C11.123,2.415 11.555,2.267 12,2.267C12.445,2.267 12.877,2.415 13.228,2.688L21.612,9.208C22.365,9.795 21.949,11 20.997,11H20V19C20,19.53 19.789,20.039 19.414,20.414C19.039,20.789 18.53,21 18,21H6C5.47,21 4.961,20.789 4.586,20.414C4.211,20.039 4,19.53 4,19V11H3.003C2.05,11 1.636,9.794 2.388,9.209L10.772,2.688Z" />
</group>
Expand Down
9 changes: 9 additions & 0 deletions android/app/src/main/res/drawable/ic_my_page.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/on_surface"
android:pathData="M12,2C10.939,2 9.922,2.421 9.172,3.172C8.421,3.922 8,4.939 8,6C8,7.061 8.421,8.078 9.172,8.828C9.922,9.579 10.939,10 12,10C13.061,10 14.078,9.579 14.828,8.828C15.579,8.078 16,7.061 16,6C16,4.939 15.579,3.922 14.828,3.172C14.078,2.421 13.061,2 12,2ZM10,6C10,5.47 10.211,4.961 10.586,4.586C10.961,4.211 11.47,4 12,4C12.53,4 13.039,4.211 13.414,4.586C13.789,4.961 14,5.47 14,6C14,6.53 13.789,7.039 13.414,7.414C13.039,7.789 12.53,8 12,8C11.47,8 10.961,7.789 10.586,7.414C10.211,7.039 10,6.53 10,6ZM17,12H7C6.204,12 5.441,12.316 4.879,12.879C4.316,13.441 4,14.204 4,15C4,17.232 4.918,19.02 6.424,20.23C7.906,21.42 9.894,22 12,22C14.106,22 16.094,21.42 17.576,20.23C19.08,19.02 20,17.232 20,15C20,14.204 19.684,13.441 19.121,12.879C18.559,12.316 17.796,12 17,12ZM7,14H17C17.265,14 17.52,14.105 17.707,14.293C17.895,14.48 18,14.735 18,15C18,16.634 17.35,17.846 16.324,18.67C15.272,19.514 13.76,20 12,20C10.24,20 8.728,19.514 7.676,18.67C6.65,17.846 6,16.634 6,15C6,14.735 6.105,14.48 6.293,14.293C6.48,14.105 6.735,14 7,14Z" />
</vector>
9 changes: 9 additions & 0 deletions android/app/src/main/res/drawable/ic_my_page_filled.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/on_surface"
android:pathData="M12,2C10.939,2 9.922,2.421 9.172,3.172C8.421,3.922 8,4.939 8,6C8,7.061 8.421,8.078 9.172,8.828C9.922,9.579 10.939,10 12,10C13.061,10 14.078,9.579 14.828,8.828C15.579,8.078 16,7.061 16,6C16,4.939 15.579,3.922 14.828,3.172C14.078,2.421 13.061,2 12,2ZM17,12H7C6.204,12 5.441,12.316 4.879,12.879C4.316,13.441 4,14.204 4,15C4,17.232 4.918,19.02 6.424,20.23C7.906,21.42 9.894,22 12,22C14.106,22 16.094,21.42 17.576,20.23C19.08,19.02 20,17.232 20,15C20,14.204 19.684,13.441 19.121,12.879C18.559,12.316 17.796,12 17,12Z" />
</vector>
9 changes: 9 additions & 0 deletions android/app/src/main/res/drawable/ic_playlist_filled.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/on_surface"
android:pathData="M3,6C3,5.801 3.079,5.61 3.22,5.47C3.36,5.329 3.551,5.25 3.75,5.25H20.25C20.449,5.25 20.64,5.329 20.78,5.47C20.921,5.61 21,5.801 21,6C21,6.199 20.921,6.39 20.78,6.53C20.64,6.671 20.449,6.75 20.25,6.75H3.75C3.551,6.75 3.36,6.671 3.22,6.53C3.079,6.39 3,6.199 3,6ZM3.75,12.75H15C15.199,12.75 15.39,12.671 15.53,12.53C15.671,12.39 15.75,12.199 15.75,12C15.75,11.801 15.671,11.61 15.53,11.47C15.39,11.329 15.199,11.25 15,11.25H3.75C3.551,11.25 3.36,11.329 3.22,11.47C3.079,11.61 3,11.801 3,12C3,12.199 3.079,12.39 3.22,12.53C3.36,12.671 3.551,12.75 3.75,12.75ZM10.5,17.25H3.75C3.551,17.25 3.36,17.329 3.22,17.47C3.079,17.61 3,17.801 3,18C3,18.199 3.079,18.39 3.22,18.53C3.36,18.671 3.551,18.75 3.75,18.75H10.5C10.699,18.75 10.89,18.671 11.03,18.53C11.171,18.39 11.25,18.199 11.25,18C11.25,17.801 11.171,17.61 11.03,17.47C10.89,17.329 10.699,17.25 10.5,17.25ZM22.716,10.907L18.966,9.782C18.854,9.748 18.735,9.741 18.62,9.762C18.505,9.782 18.396,9.829 18.302,9.898C18.209,9.968 18.132,10.059 18.08,10.163C18.027,10.268 18,10.383 18,10.5V15.404C17.428,15.074 16.763,14.942 16.108,15.028C15.453,15.114 14.845,15.414 14.378,15.881C13.911,16.348 13.612,16.956 13.526,17.611C13.439,18.266 13.572,18.931 13.903,19.503C14.233,20.075 14.743,20.522 15.353,20.774C15.964,21.027 16.64,21.071 17.278,20.899C17.916,20.728 18.479,20.351 18.881,19.827C19.283,19.303 19.5,18.66 19.5,18V11.508L22.284,12.343C22.379,12.374 22.48,12.386 22.579,12.377C22.679,12.369 22.776,12.341 22.864,12.295C22.953,12.248 23.031,12.185 23.095,12.108C23.159,12.03 23.206,11.941 23.235,11.846C23.264,11.75 23.273,11.649 23.262,11.55C23.252,11.451 23.221,11.354 23.173,11.267C23.125,11.179 23.059,11.103 22.981,11.041C22.902,10.979 22.812,10.933 22.716,10.907Z" />
</vector>
5 changes: 5 additions & 0 deletions android/app/src/main/res/drawable/my_page_tab_selector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_my_page_filled" android:state_selected="true" />
<item android:drawable="@drawable/ic_my_page" />
</selector>
5 changes: 5 additions & 0 deletions android/app/src/main/res/drawable/playlist_tab_selector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_playlist_filled" android:state_selected="true" />
<item android:drawable="@drawable/ic_playlist" />
</selector>
24 changes: 23 additions & 1 deletion android/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

<variable
name="viewModel"
type="com.ohdodok.catchytape.feature.player.PlayerViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -14,12 +21,27 @@
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@id/bottom_nav"
app:layout_constraintBottom_toTopOf="@id/pcv_controller"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/catchytape_navigation" />

<com.ohdodok.catchytape.feature.player.PlayerControlView
android:id="@+id/pcv_controller"
android:layout_width="0dp"
android:layout_height="65dp"
app:artist="@string/artist"
app:duration="@{viewModel.uiState.duration}"
app:playing="@{viewModel.uiState.isPlaying}"
app:layout_constraintBottom_toTopOf="@id/bottom_nav"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:progress="@{viewModel.uiState.currentPositionSecond}"
app:thumbnailUrl="https://picsum.photos/200"
app:title="@string/title" />


<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav"
android:layout_width="0dp"
Expand Down
Loading

0 comments on commit 62f5ec4

Please sign in to comment.