committed by
amazing-username
parent
1a98aec901
commit
96cd2ddcc4
@@ -3,6 +3,7 @@ package com.example.mear.activities
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.app.AppCompatActivity
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
|
import android.widget.ListView
|
||||||
|
|
||||||
import kotlinx.android.synthetic.main.activity_song_view.*
|
import kotlinx.android.synthetic.main.activity_song_view.*
|
||||||
import kotlinx.android.synthetic.main.content_song_view.*
|
import kotlinx.android.synthetic.main.content_song_view.*
|
||||||
@@ -12,10 +13,32 @@ import com.example.mear.repositories.TrackRepository
|
|||||||
|
|
||||||
class SongViewActivity : AppCompatActivity() {
|
class SongViewActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
private lateinit var listView: ListView
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_song_view)
|
setContentView(R.layout.activity_song_view)
|
||||||
setSupportActionBar(toolbar)
|
setSupportActionBar(toolbar)
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
|
|
||||||
|
initializeAdapter()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private fun initializeAdapter() {
|
||||||
|
listView = findViewById<ListView>(R.id.recipe_list_view)
|
||||||
|
// 1
|
||||||
|
val recipeList = Recipe.getRecipesFromFile("recipes.json", this)
|
||||||
|
// 2
|
||||||
|
val listItems = arrayOfNulls<String>(recipeList.size)
|
||||||
|
// 3
|
||||||
|
for (i in 0 until recipeList.size) {
|
||||||
|
val recipe = recipeList[i]
|
||||||
|
listItems[i] = recipe.title
|
||||||
|
}
|
||||||
|
// 4
|
||||||
|
val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, listItems)
|
||||||
|
listView.adapter = adapter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package com.example.mear.com.example.mear.adapters
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.BitmapFactory
|
||||||
|
import android.support.v7.widget.RecyclerView
|
||||||
|
import android.support.v7.widget.RecyclerView.Adapter
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.widget.TextView
|
||||||
|
import android.widget.ImageView
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.BaseAdapter
|
||||||
|
|
||||||
|
import com.example.mear.models.TrackItems
|
||||||
|
import com.example.mear.R
|
||||||
|
|
||||||
|
class RecyclerAdapter(private val context: Context,
|
||||||
|
private val source: ArrayList<TrackItems>): BaseAdapter() {
|
||||||
|
|
||||||
|
|
||||||
|
private val inflater: LayoutInflater
|
||||||
|
= context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||||
|
|
||||||
|
|
||||||
|
override fun getCount(): Int {
|
||||||
|
return source.size
|
||||||
|
}
|
||||||
|
|
||||||
|
//2
|
||||||
|
override fun getItem(position: Int): Any {
|
||||||
|
return source[position]
|
||||||
|
}
|
||||||
|
|
||||||
|
//3
|
||||||
|
override fun getItemId(position: Int): Long {
|
||||||
|
return position.toLong()
|
||||||
|
}
|
||||||
|
|
||||||
|
//4
|
||||||
|
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||||
|
// Get view for row item
|
||||||
|
val rowView = inflater.inflate(R.layout.fragment_song_view, parent, false)
|
||||||
|
|
||||||
|
val trackTitleTextView = rowView.findViewById(R.id.trackTitle) as TextView
|
||||||
|
|
||||||
|
// Get subtitle element
|
||||||
|
val trackArtistTextView= rowView.findViewById(R.id.trackArtist) as TextView
|
||||||
|
|
||||||
|
// Get detail element
|
||||||
|
val trackCoverImageView = rowView.findViewById(R.id.trackCover) as ImageView
|
||||||
|
|
||||||
|
val track = getItem(position) as TrackItems
|
||||||
|
|
||||||
|
// 2
|
||||||
|
trackTitleTextView.text = track.trackTitle
|
||||||
|
trackArtistTextView.text = track.artistTitle
|
||||||
|
trackCoverImageView.setImageBitmap(BitmapFactory.decodeByteArray(track.trackCover, 0, track.trackCover.size))
|
||||||
|
|
||||||
|
|
||||||
|
return rowView
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.example.mear.models
|
||||||
|
|
||||||
|
data class TrackItems(val id: Int, val trackTitle: String, val artistTitle: String, val trackCover: ByteArray) {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,11 +9,9 @@
|
|||||||
tools:showIn="@layout/activity_song_view">
|
tools:showIn="@layout/activity_song_view">
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/SongViewList"
|
android:id="@+id/trackList"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"/>
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
</android.support.v4.widget.NestedScrollView>
|
</android.support.v4.widget.NestedScrollView>
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<android.support.v7.widget.CardView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/cv"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="5dp"
|
||||||
|
android:layout_marginRight="5dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
card_view:cardCornerRadius="5dp">
|
||||||
|
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_margin="10dp"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:background="#c0c0c0"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<android.support.v7.widget.AppCompatImageView
|
||||||
|
android:id="@+id/trackCover"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
card_view:srcCompat="@mipmap/ic_launcher_round" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="290dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="5dp"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/trackTitle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="16sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/trackArtist"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
</android.support.v7.widget.CardView>
|
||||||
Reference in New Issue
Block a user