Skip to content

Commit

Permalink
Merge pull request #2 from Roaim/animation
Browse files Browse the repository at this point in the history
animation
  • Loading branch information
Roaim authored Aug 18, 2019
2 parents 6f268ea + 69b7864 commit 077f4bb
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sample_pinboard_app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "2.1"
versionName "2.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildConfigField "String", "SAMPLE_JSON_URL", SAMPLE_JSON_URL
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ class ViewHolder private constructor(private val binding: ItemPinBinding, privat
}

companion object {
fun from(parent: ViewGroup, viewModel: PinBoardViewModel): ViewHolder {
fun from(
parent: ViewGroup,
viewModel: PinBoardViewModel
): ViewHolder {
val layoutInflater = LayoutInflater.from(parent.context)
return ItemPinBinding.inflate(layoutInflater, parent, false).run {
vm = viewModel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.roaim.kotlinpinboard.pinboard

import android.view.View
import androidx.core.view.ViewCompat
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.navigation.findNavController
import androidx.navigation.fragment.FragmentNavigatorExtras
import com.roaim.kotlinpinboard.R
import com.roaim.kotlinpinboard.data.PinRepository
import com.roaim.kotlinpinboard.data.model.LoremPicksum
Expand All @@ -20,12 +22,17 @@ class PinBoardViewModel(private val repository: PinRepository = PinRepository())
val pinList = repository.getPins()

fun onPinClick(view: View, pin: LoremPicksum) {
ViewCompat.setTransitionName(view, "rah")
val navigatorExtras = FragmentNavigatorExtras(
view to "rah"
)
view.findNavController().takeIf { it.currentDestination?.id == R.id.pinBoardFragment2 }?.apply {
PinBoardFragmentDirections.actionPinBoardFragment2ToPinDetailsFragment2(
pin.author!!,
Constants.getImageUrl(pin.id!!)
Constants.getImageUrl(pin.id!!),
Constants.getThumbUrl(pin.id!!)
).also {
navigate(it)
navigate(it, navigatorExtras)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,44 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.ViewCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer
import androidx.transition.TransitionInflater
import com.roaim.kotlinpinboard.data.PinRepository
import com.roaim.kotlinpinboard.databinding.PinDetailsFragmentBinding
import com.roaim.kotlinpinboard.utils.PinViewModelFactory

class PinDetailsFragment : Fragment() {

private lateinit var binding: PinDetailsFragmentBinding

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val viewModel by viewModels<PinDetailsViewModel> { PinViewModelFactory(PinRepository()) }
return PinDetailsFragmentBinding.inflate(inflater, container, false).also {
it.viewmodel = viewModel
binding = it
}.run {
lifecycleOwner = this@PinDetailsFragment
val safeArg = PinDetailsFragmentArgs.fromBundle(arguments!!)
viewModel.setTitle(safeArg.title ?: "Something wrong!")
viewModel.downloadImage(safeArg.imgUrl)
viewModel.downloadImage(safeArg.thumbUrl)
root
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
sharedElementEnterTransition = TransitionInflater.from(context).inflateTransition(android.R.transition.move)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
ViewCompat.setTransitionName(binding.frameLayout , "rah")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package com.roaim.kotlinpinboard.utils

object Constants {
fun getImageListUrl(page : Int = 1, limit : Int = 10) = "https://picsum.photos/v2/list?page=$page&limit=$limit"
fun getThumbUrl(id: String, size : Int = 360) = "https://picsum.photos/id/$id/$size/$size"
fun getThumbUrl(id: String, width: Int = 360, height: Int = 480) = "https://picsum.photos/id/$id/$width/$height"
fun getImageUrl(id: String, width : Int = 1080, height : Int = 1920) = "https://picsum.photos/id/$id/$width/$height"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</data>

<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".pindetails.PinDetailsFragment">
Expand Down
6 changes: 6 additions & 0 deletions sample_pinboard_app/src/main/res/navigation/nav.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<argument
android:name="imgUrl"
app:argType="string"/>
<argument
android:name="thumbUrl"
app:argType="string"/>
</action>
</fragment>
<fragment
Expand All @@ -33,6 +36,9 @@
<argument
android:name="imgUrl"
app:argType="string"/>
<argument
android:name="thumbUrl"
app:argType="string"/>

</fragment>
</navigation>

0 comments on commit 077f4bb

Please sign in to comment.