Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class ImageDisplayFragment : Fragment() {

private lateinit var images: IntArray


fun setImages(_images : IntArray){
images = _images
}


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// If we have arguments
Expand All @@ -40,7 +46,9 @@ class ImageDisplayFragment : Fragment() {
// The recycler view is the root element of the Fragment's layout
// as such the view argument passed to onViewCreated() is the RecyclerView
with (view as RecyclerView) {
adapter = CustomRecyclerAdapter(images)
if (::images.isInitialized) {
adapter = CustomRecyclerAdapter(images)
}
layoutManager = GridLayoutManager(requireContext(), 2)
}
}
Expand Down
55 changes: 55 additions & 0 deletions app/src/main/java/edu/temple/inclassactivity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,73 @@ package edu.temple.inclassactivity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import androidx.lifecycle.ViewModelProvider as ViewModelProvider
import androidx.lifecycle.ViewModelProvider as ViewModelProvider1

class MainActivity : AppCompatActivity() {

lateinit var someVar : Array<Int>

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)


//if(::someVar.isInitialized)


//val mainViewModel = ViewModelProvider(this)[MainViewModel::class.java]


// Fetch images into IntArray called imageArray
val typedArray = resources.obtainTypedArray(R.array.image_ids)
val imageArray = IntArray(typedArray.length()) {typedArray.getResourceId(it, 0)}
typedArray.recycle()

val myButton = findViewById<Button>(R.id.button)

// (supportFragmentManager.findFragmentById(R.id.fragmentContainerView) as ImageDisplayFragment).setImages(imageArray)

myButton.setOnClickListener{
(supportFragmentManager.findFragmentById(R.id.fragmentContainerView) as ImageDisplayFragment).setImages(imageArray)
}




// Attach an instance of ImageDisplayFragment using factory method
//val fragment = ImageDisplayFragment.newInstance(imageArray)
//

// if (supportFragmentManager.findFragmentById(R.id.fragmentContainerView) !is ImageDisplayFragment) {
// supportFragmentManager
// .beginTransaction()
// .add(R.id.fragmentContainerView, ImageDisplayFragment())
// .addToBackStack(null)
// .setReorderingAllowed(true)
// .commit()
// }







}

fun imageSelected(itemId : Int){
Toast.makeText(this,"You selected $itemId", Toast.LENGTH_SHORT).show()
}

// fun setImages(_images : IntArray){
// images = _images
//
// (view as RecyclerView).adapter = CustomRecyclerAdapter(images)
// }

}
24 changes: 23 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,26 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
</androidx.constraintlayout.widget.ConstraintLayout>

<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragmentContainerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="68dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

<!-- android:name="edu.temple.inclassactivity.ImageDisplayFragment"-->