Implemented functionality to store the repeat settings #35
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* Automatically generated file. DO NOT MODIFY
|
||||||
|
*/
|
||||||
|
package com.example.mear;
|
||||||
|
|
||||||
|
public final class BuildConfig {
|
||||||
|
public static final boolean DEBUG = Boolean.parseBoolean("true");
|
||||||
|
public static final String APPLICATION_ID = "com.example.mear";
|
||||||
|
public static final String BUILD_TYPE = "debug";
|
||||||
|
public static final String FLAVOR = "";
|
||||||
|
public static final int VERSION_CODE = 1;
|
||||||
|
public static final String VERSION_NAME = "1.0";
|
||||||
|
}
|
||||||
@@ -35,14 +35,17 @@ import com.example.mear.playback.service.MusicService
|
|||||||
import com.example.mear.models.PlayControls
|
import com.example.mear.models.PlayControls
|
||||||
import com.example.mear.R
|
import com.example.mear.R
|
||||||
import com.example.mear.constants.ControlTypes
|
import com.example.mear.constants.ControlTypes
|
||||||
|
import com.example.mear.repositories.RepeatRepository
|
||||||
import com.example.mear.repositories.ShuffleRepository
|
import com.example.mear.repositories.ShuffleRepository
|
||||||
|
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private var musicService: MusicService? = null
|
private var musicService: MusicService? = null
|
||||||
|
private var musicHandler: Handler? = Handler()
|
||||||
private var serviceBinded: Boolean? = false
|
private var serviceBinded: Boolean? = false
|
||||||
private var repeatOn: Boolean? = false
|
private var repeatOn: Boolean? = false
|
||||||
|
private var shuffleOn: Boolean? = false
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@@ -86,6 +89,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
try {
|
try {
|
||||||
window.statusBarColor = resources.getColor(R.color.track_seek)
|
window.statusBarColor = resources.getColor(R.color.track_seek)
|
||||||
initializeShuffle()
|
initializeShuffle()
|
||||||
|
initializeRepeat()
|
||||||
initializeServices()
|
initializeServices()
|
||||||
initializeClickListeners()
|
initializeClickListeners()
|
||||||
}
|
}
|
||||||
@@ -136,6 +140,17 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private fun initializeRepeat() {
|
||||||
|
val repeatMode = RepeatRepository(this).getRepeatMode()
|
||||||
|
when (repeatMode) {
|
||||||
|
ControlTypes.REPEAT_ON -> {
|
||||||
|
RepeatTrack.text = resources.getText(R.string.repeat_on)
|
||||||
|
}
|
||||||
|
ControlTypes.REPEAT_OFF -> {
|
||||||
|
RepeatTrack.text = resources.getText(R.string.repeat_off)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun toggleShuffle() {
|
private fun toggleShuffle() {
|
||||||
val shuffleText = ShuffleTracks.text.toString()
|
val shuffleText = ShuffleTracks.text.toString()
|
||||||
@@ -176,6 +191,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
RepeatTrack.text = off
|
RepeatTrack.text = off
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
val playC = PlayControls(null, repeatOn)
|
||||||
|
RepeatRepository(this).updateRepeatMode(playC)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun playSongTrack() {
|
private fun playSongTrack() {
|
||||||
@@ -196,8 +213,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
private fun playNextSongTrack() {
|
private fun playNextSongTrack() {
|
||||||
NextTrack.isEnabled = false
|
NextTrack.isEnabled = false
|
||||||
try {
|
try {
|
||||||
//val controls = PlayControls(shuffleOn!!, repeatOn!!)
|
|
||||||
//musicService!!.playNextTrack(controls)
|
|
||||||
musicService!!.playNextTrack()
|
musicService!!.playNextTrack()
|
||||||
|
|
||||||
configureTrackDisplay()
|
configureTrackDisplay()
|
||||||
@@ -211,8 +226,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
private fun playPreviousSongTrack() {
|
private fun playPreviousSongTrack() {
|
||||||
PreviousTrack.isEnabled = false
|
PreviousTrack.isEnabled = false
|
||||||
try {
|
try {
|
||||||
//val controls = PlayControls(shuffleOn!!, repeatOn!!)
|
|
||||||
//musicService!!.playPreviousTrack(controls)
|
|
||||||
musicService!!.playPreviousTrack()
|
musicService!!.playPreviousTrack()
|
||||||
|
|
||||||
configureTrackDisplay()
|
configureTrackDisplay()
|
||||||
@@ -247,7 +260,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
resetControls()
|
resetControls()
|
||||||
|
|
||||||
|
|
||||||
TrackTitle.text = trackTitle
|
TrackTitle.text = trackTitle
|
||||||
ArtistTitle.text = artistTitle
|
ArtistTitle.text = artistTitle
|
||||||
AlbumTitle.text = albumTitle
|
AlbumTitle.text = albumTitle
|
||||||
@@ -365,9 +377,4 @@ class MainActivity : AppCompatActivity() {
|
|||||||
else {
|
else {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private var musicHandler: Handler? = Handler()
|
|
||||||
private var shuffleOn: Boolean? = false
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,4 +3,6 @@ package com.example.mear.constants
|
|||||||
object ControlTypes {
|
object ControlTypes {
|
||||||
const val SHUFFLE_ON = "Shuffle On"
|
const val SHUFFLE_ON = "Shuffle On"
|
||||||
const val SHUFFLE_OFF = "Shuffle Off"
|
const val SHUFFLE_OFF = "Shuffle Off"
|
||||||
|
const val REPEAT_ON = "Repeat On"
|
||||||
|
const val REPEAT_OFF = "Repeat Off"
|
||||||
}
|
}
|
||||||
@@ -56,10 +56,15 @@ class DatabaseManager(ctx: Context): ManagedSQLiteOpenHelper(ctx, "Mear",
|
|||||||
"Id" to INTEGER + PRIMARY_KEY + UNIQUE,
|
"Id" to INTEGER + PRIMARY_KEY + UNIQUE,
|
||||||
"Mode" to TEXT
|
"Mode" to TEXT
|
||||||
)
|
)
|
||||||
|
db!!.createTable(
|
||||||
|
"Repeat", true,
|
||||||
|
"Id" to INTEGER + PRIMARY_KEY + UNIQUE,
|
||||||
|
"Mode" to TEXT)
|
||||||
}
|
}
|
||||||
catch (ex: Exception) {
|
catch (ex: Exception) {
|
||||||
}
|
}
|
||||||
initializeShuffle(db)
|
initializeShuffle(db)
|
||||||
|
initializeRepeat(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
|
override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
|
||||||
@@ -69,6 +74,7 @@ class DatabaseManager(ctx: Context): ManagedSQLiteOpenHelper(ctx, "Mear",
|
|||||||
db!!.dropTable("PlayCount")
|
db!!.dropTable("PlayCount")
|
||||||
db!!.dropTable("Settings")
|
db!!.dropTable("Settings")
|
||||||
db!!.dropTable("Shuffle")
|
db!!.dropTable("Shuffle")
|
||||||
|
db!!.dropTable("Repeat")
|
||||||
}
|
}
|
||||||
catch (ex: Exception) {
|
catch (ex: Exception) {
|
||||||
}
|
}
|
||||||
@@ -76,13 +82,12 @@ class DatabaseManager(ctx: Context): ManagedSQLiteOpenHelper(ctx, "Mear",
|
|||||||
|
|
||||||
|
|
||||||
private fun initializeShuffle(db: SQLiteDatabase?) {
|
private fun initializeShuffle(db: SQLiteDatabase?) {
|
||||||
try {
|
|
||||||
db!!.insert("Shuffle",
|
db!!.insert("Shuffle",
|
||||||
"Mode" to ControlTypes.SHUFFLE_OFF)
|
"Mode" to ControlTypes.SHUFFLE_OFF)
|
||||||
}
|
}
|
||||||
catch (ex: Exception) {
|
private fun initializeRepeat(db: SQLiteDatabase?) {
|
||||||
val exMsg = ex.message
|
db!!.insert("Repeat",
|
||||||
}
|
"Mode" to ControlTypes.REPEAT_OFF)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import android.content.Intent
|
|||||||
import android.media.MediaPlayer
|
import android.media.MediaPlayer
|
||||||
import android.os.Binder
|
import android.os.Binder
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
|
import android.support.v4.media.VolumeProviderCompat
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
|
||||||
import java.lang.Exception
|
import java.lang.Exception
|
||||||
@@ -15,8 +16,10 @@ import com.example.mear.management.MusicFiles
|
|||||||
import com.example.mear.management.TrackManager
|
import com.example.mear.management.TrackManager
|
||||||
import com.example.mear.models.PlayControls
|
import com.example.mear.models.PlayControls
|
||||||
import com.example.mear.models.Track
|
import com.example.mear.models.Track
|
||||||
|
import com.example.mear.repositories.RepeatRepository
|
||||||
import com.example.mear.repositories.ShuffleRepository
|
import com.example.mear.repositories.ShuffleRepository
|
||||||
import com.example.mear.repositories.TrackRepository
|
import com.example.mear.repositories.TrackRepository
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
class MusicService: Service() {
|
class MusicService: Service() {
|
||||||
@@ -178,6 +181,7 @@ class MusicService: Service() {
|
|||||||
|
|
||||||
private fun fetchSongIndex(playType: PlayTypes): Int {
|
private fun fetchSongIndex(playType: PlayTypes): Int {
|
||||||
var songIndex: Int? = currentSongIndex
|
var songIndex: Int? = currentSongIndex
|
||||||
|
repeatOn = retrieveRepeatMode()
|
||||||
if (repeatOn!!) {
|
if (repeatOn!!) {
|
||||||
return songIndex!!
|
return songIndex!!
|
||||||
}
|
}
|
||||||
@@ -261,6 +265,7 @@ class MusicService: Service() {
|
|||||||
val trackMgr = TrackManager(paths!!)
|
val trackMgr = TrackManager(paths!!)
|
||||||
trackMgr.configureTracks(this)
|
trackMgr.configureTracks(this)
|
||||||
initializeShuffleMode()
|
initializeShuffleMode()
|
||||||
|
initializeRepeatMode()
|
||||||
}
|
}
|
||||||
private fun initializeShuffleMode() {
|
private fun initializeShuffleMode() {
|
||||||
try {
|
try {
|
||||||
@@ -281,6 +286,25 @@ class MusicService: Service() {
|
|||||||
val exMsg = ex.message
|
val exMsg = ex.message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private fun initializeRepeatMode() {
|
||||||
|
try {
|
||||||
|
val repeatMode = RepeatRepository(this).getRepeatMode()
|
||||||
|
when (repeatMode) {
|
||||||
|
ControlTypes.REPEAT_ON -> {
|
||||||
|
repeatOn = true
|
||||||
|
}
|
||||||
|
ControlTypes.REPEAT_OFF -> {
|
||||||
|
repeatOn = false
|
||||||
|
}
|
||||||
|
null -> {
|
||||||
|
repeatOn = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (ex: Exception) {
|
||||||
|
val exMsg = ex.message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun retrieveShuffleMode(): Boolean? {
|
private fun retrieveShuffleMode(): Boolean? {
|
||||||
@@ -300,6 +324,23 @@ class MusicService: Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private fun retrieveRepeatMode(): Boolean? {
|
||||||
|
val repeatMode = RepeatRepository(this).getRepeatMode()
|
||||||
|
when (repeatMode) {
|
||||||
|
ControlTypes.REPEAT_ON -> {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
ControlTypes.REPEAT_OFF -> {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
null -> {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun trackRepositoryEmpty(): Boolean? {
|
private fun trackRepositoryEmpty(): Boolean? {
|
||||||
val trackCount = retrieveSongCount()
|
val trackCount = retrieveSongCount()
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.example.mear.repositories
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
|
||||||
|
import org.jetbrains.anko.db.*
|
||||||
|
|
||||||
|
import com.example.mear.constants.ControlTypes
|
||||||
|
import com.example.mear.database
|
||||||
|
import com.example.mear.models.PlayControls
|
||||||
|
|
||||||
|
class RepeatRepository {
|
||||||
|
var context: Context? = null
|
||||||
|
|
||||||
|
|
||||||
|
constructor(context: Context) {
|
||||||
|
this.context = context
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun getRepeatMode(): String = context!!.database.use {
|
||||||
|
select("Repeat").limit(1)
|
||||||
|
.parseSingle(object: MapRowParser<String>{
|
||||||
|
override fun parseRow(columns: Map<String, Any?>): String {
|
||||||
|
|
||||||
|
return columns.getValue("Mode").toString()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateRepeatMode(playControls: PlayControls?) = context!!.database.use {
|
||||||
|
var repeatMode = ControlTypes.REPEAT_OFF
|
||||||
|
if (playControls!!.repeatOn!!) {
|
||||||
|
repeatMode = ControlTypes.REPEAT_ON
|
||||||
|
}
|
||||||
|
update("Repeat",
|
||||||
|
"Mode" to repeatMode).exec()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user