Activity for level selection; has some unnecessary classes for fragments
This commit is contained in:
parent
4216961b5b
commit
b8602d4677
|
@ -47,6 +47,8 @@ dependencies {
|
|||
implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.0.0'
|
||||
implementation 'androidx.preference:preference:1.1.0-rc01'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.0.0'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
|
|
|
@ -9,11 +9,14 @@
|
|||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".LevelSelectActivity" android:parentActivityName=".MainActivity"></activity>
|
||||
<activity
|
||||
android:name=".TrainingActivity"
|
||||
android:parentActivityName=".MainActivity"
|
||||
android:windowSoftInputMode="stateAlwaysVisible">
|
||||
<meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".MainActivity" />
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".MainActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".CWSettingsActivity"
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package com.example.ecwt
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.widget.AbsListView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.example.ecwt.dummy.DummyContent
|
||||
|
||||
class LevelSelectAdaptor : RecyclerView.Adapter<LevelSelectAdaptor.LevelSelectViewHolder>() {
|
||||
class LevelSelectViewHolder(val textView : LinearLayout) : RecyclerView.ViewHolder(textView)
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return 3
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LevelSelectViewHolder {
|
||||
val itemView = LayoutInflater.from(parent.context).inflate(R.layout.fragment_training_level, parent, false) as LinearLayout
|
||||
|
||||
return LevelSelectViewHolder(itemView)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: LevelSelectViewHolder, position: Int) {
|
||||
holder.textView.findViewById<TextView>(R.id.content).text = "OMG"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class LevelSelectActivity : AppCompatActivity(),
|
||||
TrainingLevelFragment.OnListFragmentInteractionListener {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_level_select)
|
||||
|
||||
mLevelSelectLayoutManager = LinearLayoutManager(this)
|
||||
mLevelSelectViewAdapter = LevelSelectAdaptor()
|
||||
|
||||
mLevelSelectView = findViewById<RecyclerView>(R.id.levelSelection_view).apply {
|
||||
setHasFixedSize(true)
|
||||
layoutManager = mLevelSelectLayoutManager
|
||||
adapter = mLevelSelectViewAdapter
|
||||
}
|
||||
}
|
||||
|
||||
override fun onListFragmentInteraction(item: DummyContent.DummyItem?) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
|
||||
private lateinit var mLevelSelectView : RecyclerView
|
||||
private lateinit var mLevelSelectLayoutManager : RecyclerView.LayoutManager
|
||||
private lateinit var mLevelSelectViewAdapter : LevelSelectAdaptor
|
||||
}
|
|
@ -53,4 +53,10 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
fun openKochLevelSelect(view :View) {
|
||||
val intent = Intent(this, LevelSelectActivity::class.java).apply {
|
||||
}
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
package com.example.ecwt
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
||||
import com.example.ecwt.dummy.DummyContent
|
||||
import com.example.ecwt.dummy.DummyContent.DummyItem
|
||||
|
||||
/**
|
||||
* A fragment representing a list of Items.
|
||||
* Activities containing this fragment MUST implement the
|
||||
* [TrainingLevelFragment.OnListFragmentInteractionListener] interface.
|
||||
*/
|
||||
class TrainingLevelFragment : Fragment() {
|
||||
|
||||
// TODO: Customize parameters
|
||||
private var columnCount = 1
|
||||
|
||||
private var listener: OnListFragmentInteractionListener? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
arguments?.let {
|
||||
columnCount = it.getInt(ARG_COLUMN_COUNT)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
val view = inflater.inflate(R.layout.fragment_training_level_list, container, false)
|
||||
|
||||
// Set the adapter
|
||||
if (view is RecyclerView) {
|
||||
with(view) {
|
||||
layoutManager = when {
|
||||
columnCount <= 1 -> LinearLayoutManager(context)
|
||||
else -> GridLayoutManager(context, columnCount)
|
||||
}
|
||||
adapter = TrainingLevelRecyclerViewAdapter(DummyContent.ITEMS, listener)
|
||||
}
|
||||
}
|
||||
return view
|
||||
}
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
super.onAttach(context)
|
||||
if (context is OnListFragmentInteractionListener) {
|
||||
listener = context
|
||||
} else {
|
||||
throw RuntimeException(context.toString() + " must implement OnListFragmentInteractionListener")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetach() {
|
||||
super.onDetach()
|
||||
listener = null
|
||||
}
|
||||
|
||||
/**
|
||||
* This interface must be implemented by activities that contain this
|
||||
* fragment to allow an interaction in this fragment to be communicated
|
||||
* to the activity and potentially other fragments contained in that
|
||||
* activity.
|
||||
*
|
||||
*
|
||||
* See the Android Training lesson
|
||||
* [Communicating with Other Fragments](http://developer.android.com/training/basics/fragments/communicating.html)
|
||||
* for more information.
|
||||
*/
|
||||
interface OnListFragmentInteractionListener {
|
||||
// TODO: Update argument type and name
|
||||
fun onListFragmentInteraction(item: DummyItem?)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
// TODO: Customize parameter argument names
|
||||
const val ARG_COLUMN_COUNT = "column-count"
|
||||
|
||||
// TODO: Customize parameter initialization
|
||||
@JvmStatic
|
||||
fun newInstance(columnCount: Int) =
|
||||
TrainingLevelFragment().apply {
|
||||
arguments = Bundle().apply {
|
||||
putInt(ARG_COLUMN_COUNT, columnCount)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.example.ecwt
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
|
||||
|
||||
import com.example.ecwt.TrainingLevelFragment.OnListFragmentInteractionListener
|
||||
import com.example.ecwt.dummy.DummyContent.DummyItem
|
||||
|
||||
import kotlinx.android.synthetic.main.fragment_training_level.view.*
|
||||
|
||||
/**
|
||||
* [RecyclerView.Adapter] that can display a [DummyItem] and makes a call to the
|
||||
* specified [OnListFragmentInteractionListener].
|
||||
* TODO: Replace the implementation with code for your data type.
|
||||
*/
|
||||
class TrainingLevelRecyclerViewAdapter(
|
||||
private val mValues: List<DummyItem>,
|
||||
private val mListener: OnListFragmentInteractionListener?
|
||||
) : RecyclerView.Adapter<TrainingLevelRecyclerViewAdapter.ViewHolder>() {
|
||||
|
||||
private val mOnClickListener: View.OnClickListener
|
||||
|
||||
init {
|
||||
mOnClickListener = View.OnClickListener { v ->
|
||||
val item = v.tag as DummyItem
|
||||
// Notify the active callbacks interface (the activity, if the fragment is attached to
|
||||
// one) that an item has been selected.
|
||||
mListener?.onListFragmentInteraction(item)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val view = LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.fragment_training_level, parent, false)
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val item = mValues[position]
|
||||
holder.mIdView.text = item.id
|
||||
holder.mContentView.text = item.content
|
||||
|
||||
with(holder.mView) {
|
||||
tag = item
|
||||
setOnClickListener(mOnClickListener)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = mValues.size
|
||||
|
||||
inner class ViewHolder(val mView: View) : RecyclerView.ViewHolder(mView) {
|
||||
val mIdView: TextView = mView.item_number
|
||||
val mContentView: TextView = mView.content
|
||||
|
||||
override fun toString(): String {
|
||||
return super.toString() + " '" + mContentView.text + "'"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".LevelSelectActivity">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/levelSelection_view"
|
||||
android:name="com.example.ecwt.TrainingLevelFragment"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -24,7 +24,8 @@
|
|||
android:id="@+id/button2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Button" />
|
||||
android:onClick="openKochLevelSelect"
|
||||
android:text="Koch Training" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button3"
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_number"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/text_margin"
|
||||
android:textAppearance="?attr/textAppearanceListItem" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/text_margin"
|
||||
android:textAppearance="?attr/textAppearanceListItem" />
|
||||
</LinearLayout>
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/list"
|
||||
android:name="com.example.ecwt.TrainingLevelFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
app:layoutManager="LinearLayoutManager"
|
||||
tools:context=".TrainingLevelFragment"
|
||||
tools:listitem="@layout/fragment_training_level" />
|
|
@ -1,3 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<dimen name="fab_margin">16dp</dimen>
|
||||
<dimen name="text_margin">16dp</dimen>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue