Skip to content

Commit

Permalink
✨ Shows some basic infos.
Browse files Browse the repository at this point in the history
  • Loading branch information
yhs0602 committed Jan 27, 2020
1 parent 5f0f5f0 commit 9802aac
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class SongDetailActivity : AppCompatActivity() {
// using a fragment transaction.
val fragment = SongDetailFragment().apply {
arguments = Bundle().apply {
putString(
putInt(
SongDetailFragment.ARG_ITEM_ID,
intent.getStringExtra(SongDetailFragment.ARG_ITEM_ID)
intent.getIntExtra(SongDetailFragment.ARG_ITEM_ID,-1)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.kyhsgeekcode.dereinfo

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.kyhsgeekcode.dereinfo.dummy.DummyContent
import androidx.fragment.app.Fragment
import com.kyhsgeekcode.dereinfo.model.DereDatabaseHelper
import com.kyhsgeekcode.dereinfo.model.MusicInfo
import kotlinx.android.synthetic.main.activity_song_detail.*
import kotlinx.android.synthetic.main.song_detail.view.*

Expand All @@ -20,7 +21,7 @@ class SongDetailFragment : Fragment() {
/**
* The dummy content this fragment is presenting.
*/
private var item: DummyContent.DummyItem? = null
private var item: MusicInfo? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -30,8 +31,8 @@ class SongDetailFragment : Fragment() {
// Load the dummy content specified by the fragment
// arguments. In a real-world scenario, use a Loader
// to load content from a content provider.
item = DummyContent.ITEM_MAP[it.getString(ARG_ITEM_ID)]
activity?.toolbar_layout?.title = item?.content
item = DereDatabaseHelper.theInstance.musicIDToInfo[it[ARG_ITEM_ID]]
activity?.toolbar_layout?.title = item?.name?.replace("\\n", " ")
}
}
}
Expand All @@ -44,7 +45,7 @@ class SongDetailFragment : Fragment() {

// Show the dummy content as text in a TextView.
item?.let {
rootView.song_detail.text = it.details
rootView.song_detail.text = it.toString()
}

return rootView
Expand Down
15 changes: 8 additions & 7 deletions app/src/main/java/com/kyhsgeekcode/dereinfo/SongListActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.snackbar.Snackbar
import com.kyhsgeekcode.dereinfo.dummy.DummyContent
import com.kyhsgeekcode.dereinfo.model.CircleType.getColor
import com.kyhsgeekcode.dereinfo.model.CircleType.makeRGB
import com.kyhsgeekcode.dereinfo.model.DereDatabaseHelper
import com.kyhsgeekcode.dereinfo.model.MusicInfo
import com.kyhsgeekcode.dereinfo.model.getColor
import com.kyhsgeekcode.dereinfo.model.makeRGB

import com.tingyik90.snackprogressbar.SnackProgressBar
import com.tingyik90.snackprogressbar.SnackProgressBarManager
import kotlinx.android.synthetic.main.activity_song_list.*
Expand Down Expand Up @@ -74,6 +74,7 @@ class SongListActivity : AppCompatActivity() {
snackProgressBarManager.show(circularType, SnackProgressBarManager.LENGTH_INDEFINITE)
CoroutineScope(Dispatchers.IO).launch {
dereDatabaseHelper = DereDatabaseHelper(this@SongListActivity)
DereDatabaseHelper.theInstance = dereDatabaseHelper
dereDatabaseHelper.parseDatabases({ current, total, musicInfo ->
CoroutineScope(Dispatchers.Main).launch {
adapter.addItem(musicInfo)
Expand Down Expand Up @@ -114,7 +115,7 @@ class SongListActivity : AppCompatActivity() {
if (twoPane) {
val fragment = SongDetailFragment().apply {
arguments = Bundle().apply {
putString(SongDetailFragment.ARG_ITEM_ID, item.name)
putInt(SongDetailFragment.ARG_ITEM_ID, item.id)
}
}
parentActivity.supportFragmentManager
Expand All @@ -123,7 +124,7 @@ class SongListActivity : AppCompatActivity() {
.commit()
} else {
val intent = Intent(v.context, SongDetailActivity::class.java).apply {
putExtra(SongDetailFragment.ARG_ITEM_ID, item.name)
putExtra(SongDetailFragment.ARG_ITEM_ID, item.id)
}
v.context.startActivity(intent)
}
Expand All @@ -138,7 +139,7 @@ class SongListActivity : AppCompatActivity() {

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val item = values[position]
holder.idView.text = item.name.replace("\\n"," ")
holder.idView.text = item.name.replace("\\n", " ")
holder.contentView.text = item.composer
holder.backgroundLayout.setBackgroundColor(makeRGB(getColor(item.circleType)))
with(holder.itemView) {
Expand All @@ -158,7 +159,7 @@ class SongListActivity : AppCompatActivity() {
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val idView: TextView = view.id_text
val contentView: TextView = view.content
val backgroundLayout : LinearLayout = view.listitem_background
val backgroundLayout: LinearLayout = view.listitem_background
}
}
}
57 changes: 0 additions & 57 deletions app/src/main/java/com/kyhsgeekcode/dereinfo/dummy/DummyContent.kt

This file was deleted.

27 changes: 27 additions & 0 deletions app/src/main/java/com/kyhsgeekcode/dereinfo/model/CircleType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.kyhsgeekcode.dereinfo.model

import android.graphics.Color

object CircleType {
fun getDesc(circleType:Int):String = when(circleType) {
1->"Cute"
2->"Cool"
3->"Passion"
4->"All"
else->"Unknown(${circleType})"
}

fun getColor(circleType: Int): Array<Int> {
return when (circleType) {
1 -> arrayOf(255, 0x74, 0x77, 255) // red
2 -> arrayOf(0x53, 0x6A, 0xDE, 255) // blue
3 -> arrayOf(0xFA, 0xCC, 0x43, 255) // yellow
4 -> arrayOf(0xC7, 0xF9, 0xF4, 255) // white
else -> arrayOf(0, 0, 0, 255)
}
}

fun makeRGB(color: Array<Int>): Int =
Color.argb(color[3], color[0], color[1], color[2])
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ import android.database.sqlite.SQLiteDatabase
import android.util.Log
import android.util.SparseIntArray
import com.github.doyaaaaaken.kotlincsv.dsl.csvReader
import com.kyhsgeekcode.dereinfo.model.CircleType.getColor
import java.io.File

//This allows access to dere database
class DereDatabaseHelper(context: Context) {
companion object {
lateinit var theInstance : DereDatabaseHelper
}
val TAG = "DereDBHelper"
val manifestFile: File
val fumensDBFile: File
Expand Down
13 changes: 0 additions & 13 deletions app/src/main/java/com/kyhsgeekcode/dereinfo/model/DereToTW.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.kyhsgeekcode.dereinfo.model

import android.graphics.Color

//None left right up down
fun getTW5Flick(status: Int): Int {
return when (status) {
Expand All @@ -25,14 +23,3 @@ fun getTWMode(mode: Int): Int {
}
}

fun getColor(circleType: Int): Array<Int> {
return when (circleType) {
1 -> arrayOf(255, 0x74, 0x77, 255) // red
2 -> arrayOf(0x53, 0x6A, 0xDE, 255) // blue
3 -> arrayOf(0xFA, 0xCC, 0x43, 255) // yellow
4 -> arrayOf(0xC7, 0xF9, 0xF4, 255) // white
else -> arrayOf(0, 0, 0, 255)
}
}

fun makeRGB(color: Array<Int>): Int = Color.argb(color[3],color[0],color[1],color[2])
12 changes: 11 additions & 1 deletion app/src/main/java/com/kyhsgeekcode/dereinfo/model/MusicInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,14 @@ class MusicInfo(
val soundOffset: Int,
val soundLength: Int,
val circleType: Int = 4
)
) {
override fun toString(): String {
val lineSeparator = System.lineSeparator()
return StringBuilder("name:").append(name).append(lineSeparator)
.append("bpm:").append(bpm).append(lineSeparator)
.append("composer:").append(composer).append(lineSeparator)
.append("lyricist:").append(lyricist).append(lineSeparator)
.append("duration:").append(soundLength).append(lineSeparator)
.append("type:").append(CircleType.getDesc(circleType)).toString()
}
}

0 comments on commit 9802aac

Please sign in to comment.