@@ -12,113 +12,50 @@ import AndroidKit
1212open class ListViewAdapter : JavaObject {
1313
1414 @JavaMethod
15- @_nonoverride public convenience init ( swiftObject: SwiftObject ! , environment: JNIEnvironment ? = nil )
15+ @_nonoverride public convenience init (
16+ context: AndroidContent . Context ? ,
17+ swiftObject: SwiftObject ? ,
18+ objects: ArrayList < JavaObject > ? ,
19+ environment: JNIEnvironment ? = nil
20+ )
1621
1722 @JavaMethod
18- func getContext( ) -> SwiftObject !
23+ func getSwiftObject( ) -> SwiftObject !
24+
25+ @JavaMethod
26+ func getResourceId( ) -> Int32
1927}
2028
2129@JavaImplementation ( " com.pureswift.swiftandroid.ListViewAdapter " )
2230extension ListViewAdapter {
2331
24- @JavaMethod
25- func hasStableIds( ) -> Bool {
26- log ( " \( self ) . \( #function) " )
27- return true
28- }
29-
30- @JavaMethod
31- func isEmpty( ) -> Bool {
32- log ( " \( self ) . \( #function) " )
33- return context. items. isEmpty
34- }
35-
36- @JavaMethod
37- func getCount( ) -> Int32 {
38- log ( " \( self ) . \( #function) " )
39- return Int32 ( context. items. count)
40- }
41-
42- @JavaMethod
43- func getItem( position: Int32 ) -> JavaObject ? {
44- log ( " \( self ) . \( #function) \( position) " )
45- return JavaString ( context. items [ Int ( position) ] )
46- }
47-
48- @JavaMethod
49- func getItemId( position: Int32 ) -> Int64 {
50- log ( " \( self ) . \( #function) " )
51- return Int64 ( position)
52- }
53-
54- @JavaMethod
55- func getItemViewType( position: Int32 ) -> Int32 {
56- log ( " \( self ) . \( #function) " )
57- return 0
58- }
59-
60- @JavaMethod
61- func getViewTypeCount( ) -> Int32 {
62- log ( " \( self ) . \( #function) " )
63- return 1
64- }
65-
6632 @JavaMethod
6733 func getView( position: Int32 , convertView: AndroidView . View ? , parent: ViewGroup ? ) -> AndroidView . View ? {
6834 log ( " \( self ) . \( #function) \( position) " )
69- guard let parent else {
70- assertionFailure ( )
71- return nil
72- }
73- let view = TextView ( parent. getContext ( ) )
74- let item = context. items [ Int ( position) ]
75- view. text = item
76- return view
77- }
78-
79- @JavaMethod
80- func areAllItemsEnabled( ) -> Bool {
81- log ( " \( self ) . \( #function) " )
82- return true
83- }
84-
85- @JavaMethod
86- func isEnabled( position: Int32 ) -> Bool {
87- log ( " \( self ) . \( #function) \( position) " )
88- return true
89- }
90-
91- @JavaMethod
92- func registerDataSetObserver( observer: JavaObject ? ) {
93- log ( " \( self ) . \( #function) " )
94-
95- }
96-
97- @JavaMethod
98- func unregisterDataSetObserver( observer: JavaObject ? ) {
99- log ( " \( self ) . \( #function) " )
100-
35+ return getView ( position, convertView, parent)
10136 }
10237}
10338
10439public extension ListViewAdapter {
10540
106- struct Context {
107-
108- let items : [ String ]
109- }
41+ typealias GetView = ( Int32 , AndroidView . View ? , ViewGroup ? ) -> AndroidView . View ?
11042
111- var context : Context {
43+ var getView : GetView {
11244 get {
113- getContext ( ) . valueObject ( ) . value as! Context
45+ getSwiftObject ( ) . valueObject ( ) . value as! GetView
11446 }
11547 set {
116- getContext ( ) . valueObject ( ) . value = newValue
48+ getSwiftObject ( ) . valueObject ( ) . value = newValue
11749 }
11850 }
11951
120- convenience init ( _ context: Context , environment: JNIEnvironment ? = nil ) {
121- self . init ( swiftObject: SwiftObject ( context) , environment: environment)
52+ convenience init (
53+ context: AndroidContent . Context ,
54+ getView: @escaping ( Int32 , AndroidView . View ? , ViewGroup ? ) -> AndroidView . View ? ,
55+ objects: ArrayList < JavaObject > ,
56+ environment: JNIEnvironment ? = nil
57+ ) {
58+ self . init ( context: context, swiftObject: SwiftObject ( getView) , objects: objects, environment: environment)
12259 }
12360}
12461
0 commit comments