From 9802aac165aada9464072d2eb29b431460401df2 Mon Sep 17 00:00:00 2001 From: KYHSGeekCode Date: Mon, 27 Jan 2020 15:52:03 +0900 Subject: [PATCH] :sparkles: Shows some basic infos. --- .../dereinfo/SongDetailActivity.kt | 4 +- .../dereinfo/SongDetailFragment.kt | 13 +++-- .../kyhsgeekcode/dereinfo/SongListActivity.kt | 15 ++--- .../dereinfo/dummy/DummyContent.kt | 57 ------------------- .../kyhsgeekcode/dereinfo/model/CircleType.kt | 27 +++++++++ .../dereinfo/model/DereDatabaseHelper.kt | 4 ++ .../kyhsgeekcode/dereinfo/model/DereToTW.kt | 13 ----- .../kyhsgeekcode/dereinfo/model/MusicInfo.kt | 12 +++- 8 files changed, 59 insertions(+), 86 deletions(-) delete mode 100644 app/src/main/java/com/kyhsgeekcode/dereinfo/dummy/DummyContent.kt create mode 100644 app/src/main/java/com/kyhsgeekcode/dereinfo/model/CircleType.kt diff --git a/app/src/main/java/com/kyhsgeekcode/dereinfo/SongDetailActivity.kt b/app/src/main/java/com/kyhsgeekcode/dereinfo/SongDetailActivity.kt index d5c5cda..48fd03d 100644 --- a/app/src/main/java/com/kyhsgeekcode/dereinfo/SongDetailActivity.kt +++ b/app/src/main/java/com/kyhsgeekcode/dereinfo/SongDetailActivity.kt @@ -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) ) } } diff --git a/app/src/main/java/com/kyhsgeekcode/dereinfo/SongDetailFragment.kt b/app/src/main/java/com/kyhsgeekcode/dereinfo/SongDetailFragment.kt index 15f9ac7..a9b200d 100644 --- a/app/src/main/java/com/kyhsgeekcode/dereinfo/SongDetailFragment.kt +++ b/app/src/main/java/com/kyhsgeekcode/dereinfo/SongDetailFragment.kt @@ -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.* @@ -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) @@ -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", " ") } } } @@ -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 diff --git a/app/src/main/java/com/kyhsgeekcode/dereinfo/SongListActivity.kt b/app/src/main/java/com/kyhsgeekcode/dereinfo/SongListActivity.kt index e9f2bb5..7985003 100644 --- a/app/src/main/java/com/kyhsgeekcode/dereinfo/SongListActivity.kt +++ b/app/src/main/java/com/kyhsgeekcode/dereinfo/SongListActivity.kt @@ -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.* @@ -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) @@ -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 @@ -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) } @@ -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) { @@ -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 } } } diff --git a/app/src/main/java/com/kyhsgeekcode/dereinfo/dummy/DummyContent.kt b/app/src/main/java/com/kyhsgeekcode/dereinfo/dummy/DummyContent.kt deleted file mode 100644 index 25c7fbf..0000000 --- a/app/src/main/java/com/kyhsgeekcode/dereinfo/dummy/DummyContent.kt +++ /dev/null @@ -1,57 +0,0 @@ -package com.kyhsgeekcode.dereinfo.dummy - -import java.util.ArrayList -import java.util.HashMap - -/** - * Helper class for providing sample content for user interfaces created by - * Android template wizards. - * - * TODO: Replace all uses of this class before publishing your app. - */ -object DummyContent { - - /** - * An array of sample (dummy) items. - */ - val ITEMS: MutableList = ArrayList() - - /** - * A map of sample (dummy) items, by ID. - */ - val ITEM_MAP: MutableMap = HashMap() - - private val COUNT = 25 - - init { - // Add some sample items. - for (i in 1..COUNT) { - addItem(createDummyItem(i)) - } - } - - private fun addItem(item: DummyItem) { - ITEMS.add(item) - ITEM_MAP.put(item.id, item) - } - - private fun createDummyItem(position: Int): DummyItem { - return DummyItem(position.toString(), "Item " + position, makeDetails(position)) - } - - private fun makeDetails(position: Int): String { - val builder = StringBuilder() - builder.append("Details about Item: ").append(position) - for (i in 0..position - 1) { - builder.append("\nMore details information here.") - } - return builder.toString() - } - - /** - * A dummy item representing a piece of content. - */ - data class DummyItem(val id: String, val content: String, val details: String) { - override fun toString(): String = content - } -} diff --git a/app/src/main/java/com/kyhsgeekcode/dereinfo/model/CircleType.kt b/app/src/main/java/com/kyhsgeekcode/dereinfo/model/CircleType.kt new file mode 100644 index 0000000..5e4cdae --- /dev/null +++ b/app/src/main/java/com/kyhsgeekcode/dereinfo/model/CircleType.kt @@ -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 { + 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 = + Color.argb(color[3], color[0], color[1], color[2]) +} + diff --git a/app/src/main/java/com/kyhsgeekcode/dereinfo/model/DereDatabaseHelper.kt b/app/src/main/java/com/kyhsgeekcode/dereinfo/model/DereDatabaseHelper.kt index 0c092c6..b3bf1b2 100644 --- a/app/src/main/java/com/kyhsgeekcode/dereinfo/model/DereDatabaseHelper.kt +++ b/app/src/main/java/com/kyhsgeekcode/dereinfo/model/DereDatabaseHelper.kt @@ -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 diff --git a/app/src/main/java/com/kyhsgeekcode/dereinfo/model/DereToTW.kt b/app/src/main/java/com/kyhsgeekcode/dereinfo/model/DereToTW.kt index 55cf170..6a2d475 100644 --- a/app/src/main/java/com/kyhsgeekcode/dereinfo/model/DereToTW.kt +++ b/app/src/main/java/com/kyhsgeekcode/dereinfo/model/DereToTW.kt @@ -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) { @@ -25,14 +23,3 @@ fun getTWMode(mode: Int): Int { } } -fun getColor(circleType: Int): Array { - 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 = Color.argb(color[3],color[0],color[1],color[2]) diff --git a/app/src/main/java/com/kyhsgeekcode/dereinfo/model/MusicInfo.kt b/app/src/main/java/com/kyhsgeekcode/dereinfo/model/MusicInfo.kt index 10dbb73..8e439d4 100644 --- a/app/src/main/java/com/kyhsgeekcode/dereinfo/model/MusicInfo.kt +++ b/app/src/main/java/com/kyhsgeekcode/dereinfo/model/MusicInfo.kt @@ -9,4 +9,14 @@ class MusicInfo( val soundOffset: Int, val soundLength: Int, val circleType: Int = 4 -) \ No newline at end of file +) { + 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() + } +} \ No newline at end of file