-
-
Notifications
You must be signed in to change notification settings - Fork 218
/
FragmentSample.kt
86 lines (74 loc) · 2.4 KB
/
FragmentSample.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
package io.ak1.pixsample.samples
import android.net.Uri
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import io.ak1.pix.helpers.*
import io.ak1.pixsample.R
import io.ak1.pixsample.TAG
import io.ak1.pixsample.commons.Adapter
import io.ak1.pixsample.custom.fragmentBody
import io.ak1.pixsample.options
/**
* Created By Akshay Sharma on 20,June,2021
* https://ak1.io
*/
class FragmentSample : AppCompatActivity() {
private val resultsFragment = ResultsFragment {
showCameraFragment()
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_fragment_sample)
setupScreen()
supportActionBar?.hide()
showResultsFragment()
}
private fun showCameraFragment() {
addPixToActivity(R.id.container, options) {
when (it.status) {
PixEventCallback.Status.SUCCESS -> {
showResultsFragment()
it.data.forEach {
Log.e(TAG, "showCameraFragment: ${it.path}")
}
resultsFragment.setList(it.data)
}
PixEventCallback.Status.BACK_PRESSED -> {
supportFragmentManager.popBackStack()
}
}
}
}
private fun showResultsFragment() {
showStatusBar()
supportFragmentManager.beginTransaction()
.replace(R.id.container, resultsFragment).commit()
}
override fun onBackPressed() {
val f = supportFragmentManager.findFragmentById(R.id.container)
if (f is ResultsFragment)
super.onBackPressed()
else
PixBus.onBackPressedEvent()
}
}
class ResultsFragment(private val clickCallback: View.OnClickListener) : Fragment() {
private val customAdapter = Adapter()
fun setList(list: List<Uri>) {
customAdapter.apply {
this.list.clear()
this.list.addAll(list)
notifyDataSetChanged()
}
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View = fragmentBody(requireActivity(), customAdapter, clickCallback)
}