@@ -12,113 +12,50 @@ import AndroidKit
12
12
open class ListViewAdapter : JavaObject {
13
13
14
14
@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
+ )
16
21
17
22
@JavaMethod
18
- func getContext( ) -> SwiftObject !
23
+ func getSwiftObject( ) -> SwiftObject !
24
+
25
+ @JavaMethod
26
+ func getResourceId( ) -> Int32
19
27
}
20
28
21
29
@JavaImplementation ( " com.pureswift.swiftandroid.ListViewAdapter " )
22
30
extension ListViewAdapter {
23
31
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
-
66
32
@JavaMethod
67
33
func getView( position: Int32 , convertView: AndroidView . View ? , parent: ViewGroup ? ) -> AndroidView . View ? {
68
34
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)
101
36
}
102
37
}
103
38
104
39
public extension ListViewAdapter {
105
40
106
- struct Context {
107
-
108
- let items : [ String ]
109
- }
41
+ typealias GetView = ( Int32 , AndroidView . View ? , ViewGroup ? ) -> AndroidView . View ?
110
42
111
- var context : Context {
43
+ var getView : GetView {
112
44
get {
113
- getContext ( ) . valueObject ( ) . value as! Context
45
+ getSwiftObject ( ) . valueObject ( ) . value as! GetView
114
46
}
115
47
set {
116
- getContext ( ) . valueObject ( ) . value = newValue
48
+ getSwiftObject ( ) . valueObject ( ) . value = newValue
117
49
}
118
50
}
119
51
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)
122
59
}
123
60
}
124
61
0 commit comments