-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
WhatsNewFragment.kt
104 lines (93 loc) · 4.24 KB
/
WhatsNewFragment.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.noto.app.settings.whatsnew
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.addCallback
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.noto.app.R
import com.noto.app.databinding.WhatsNewFragmentBinding
import com.noto.app.domain.model.Release
import com.noto.app.domain.model.Release_1_8_0
import com.noto.app.domain.model.Release_2_0_0
import com.noto.app.domain.model.Release_2_0_1
import com.noto.app.domain.model.Release_2_1_0
import com.noto.app.domain.model.Release_2_1_1
import com.noto.app.domain.model.Release_2_1_2
import com.noto.app.domain.model.Release_2_1_3
import com.noto.app.domain.model.Release_2_1_4
import com.noto.app.domain.model.Release_2_1_5
import com.noto.app.domain.model.Release_2_1_6
import com.noto.app.domain.model.Release_2_2_0
import com.noto.app.domain.model.Release_2_2_1
import com.noto.app.domain.model.Release_2_2_2
import com.noto.app.domain.model.Release_2_2_3
import com.noto.app.util.BounceEdgeEffectFactory
import com.noto.app.util.VerticalListItemAnimator
import com.noto.app.util.navController
import com.noto.app.util.setupMixedTransitions
import com.noto.app.util.stringResource
import com.noto.app.util.withBinding
private const val GitHubReleasesUrl = "https://github.com/alialbaali/Noto/releases"
class WhatsNewFragment : Fragment() {
private val releases: List<Release> by lazy {
context?.let { context ->
listOf(
Release_2_2_3(Release.Changelog(context.stringResource(R.string.release_2_2_3))),
Release_2_2_2(Release.Changelog(context.stringResource(R.string.release_2_2_2))),
Release_2_2_1(Release.Changelog(context.stringResource(R.string.release_2_2_1))),
Release_2_2_0(Release.Changelog(context.stringResource(R.string.release_2_2_0))),
Release_2_1_6(Release.Changelog(context.stringResource(R.string.release_2_1_6))),
Release_2_1_5(Release.Changelog(context.stringResource(R.string.release_2_1_5))),
Release_2_1_4(Release.Changelog(context.stringResource(R.string.release_2_1_4))),
Release_2_1_3(Release.Changelog(context.stringResource(R.string.release_2_1_3))),
Release_2_1_2(Release.Changelog(context.stringResource(R.string.release_2_1_2))),
Release_2_1_1(Release.Changelog(context.stringResource(R.string.release_2_1_1))),
Release_2_1_0(Release.Changelog(context.stringResource(R.string.release_2_1_0))),
Release_2_0_1(Release.Changelog(context.stringResource(R.string.release_2_0_1))),
Release_2_0_0(Release.Changelog(context.stringResource(R.string.release_2_0_0))),
Release_1_8_0(Release.Changelog(context.stringResource(R.string.release_1_8_0))),
)
} ?: emptyList()
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
): View = WhatsNewFragmentBinding.inflate(inflater, container, false).withBinding {
setupMixedTransitions()
setupState()
setupListeners()
}
private fun WhatsNewFragmentBinding.setupState() {
rv.edgeEffectFactory = BounceEdgeEffectFactory()
rv.itemAnimator = VerticalListItemAnimator()
rv.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
rv.withModels {
releases.forEach { release ->
releaseItem {
id(release.version.toString())
release(release)
}
}
}
}
private fun WhatsNewFragmentBinding.setupListeners() {
activity?.onBackPressedDispatcher?.addCallback {
navController?.navigateUp()
}
tvMoreDetails.setOnClickListener {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(GitHubReleasesUrl))
startActivity(intent)
}
tb.setOnClickListener {
rv.smoothScrollToPosition(0)
}
tb.setNavigationOnClickListener {
navController?.navigateUp()
}
}
}