@@ -3,26 +3,42 @@ package com.example.gutenbergkit
3
3
import android.os.Bundle
4
4
import android.webkit.WebView
5
5
import android.content.pm.ApplicationInfo
6
+ import androidx.activity.ComponentActivity
7
+ import androidx.activity.compose.setContent
6
8
import androidx.activity.enableEdgeToEdge
7
- import androidx.appcompat.app.AppCompatActivity
8
- import androidx.core.view.ViewCompat
9
- import androidx.core.view.WindowInsetsCompat
9
+ import androidx.compose.foundation.layout.Box
10
+ import androidx.compose.foundation.layout.fillMaxSize
11
+ import androidx.compose.foundation.layout.padding
12
+ import androidx.compose.material.icons.Icons
13
+ import androidx.compose.material.icons.automirrored.filled.ArrowBack
14
+ import androidx.compose.material.icons.automirrored.filled.Redo
15
+ import androidx.compose.material.icons.automirrored.filled.Undo
16
+ import androidx.compose.material.icons.filled.MoreVert
17
+ import androidx.compose.material3.DropdownMenu
18
+ import androidx.compose.material3.DropdownMenuItem
19
+ import androidx.compose.material3.ExperimentalMaterial3Api
20
+ import androidx.compose.material3.Icon
21
+ import androidx.compose.material3.IconButton
22
+ import androidx.compose.material3.Scaffold
23
+ import androidx.compose.material3.Text
24
+ import androidx.compose.material3.TextButton
25
+ import androidx.compose.material3.TopAppBar
26
+ import androidx.compose.runtime.Composable
27
+ import androidx.compose.runtime.getValue
28
+ import androidx.compose.runtime.mutableStateOf
29
+ import androidx.compose.runtime.remember
30
+ import androidx.compose.runtime.setValue
31
+ import androidx.compose.ui.Modifier
32
+ import androidx.compose.ui.viewinterop.AndroidView
10
33
import org.wordpress.gutenberg.EditorConfiguration
11
34
import org.wordpress.gutenberg.GutenbergView
12
35
13
- class EditorActivity : AppCompatActivity () {
36
+ class EditorActivity : ComponentActivity () {
14
37
override fun onCreate (savedInstanceState : Bundle ? ) {
15
38
super .onCreate(savedInstanceState)
16
39
enableEdgeToEdge()
17
- setContentView(R .layout.activity_editor)
18
40
19
- ViewCompat .setOnApplyWindowInsetsListener(findViewById(R .id.editor)) { v, insets ->
20
- val systemBars = insets.getInsets(WindowInsetsCompat .Type .systemBars())
21
- v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
22
- insets
23
- }
24
-
25
- if (0 != (applicationInfo.flags and android.content.pm.ApplicationInfo .FLAG_DEBUGGABLE )) {
41
+ if (0 != (applicationInfo.flags and ApplicationInfo .FLAG_DEBUGGABLE )) {
26
42
WebView .setWebContentsDebuggingEnabled(true )
27
43
}
28
44
@@ -38,7 +54,105 @@ class EditorActivity : AppCompatActivity() {
38
54
intent.getParcelableExtra<EditorConfiguration >(MainActivity .EXTRA_CONFIGURATION )
39
55
} ? : EditorConfiguration .builder().build()
40
56
41
- val gbView = findViewById<GutenbergView >(R .id.gutenbergView)
42
- gbView.start(configuration)
57
+ setContent {
58
+ EditorScreen (
59
+ configuration = configuration,
60
+ onClose = { finish() }
61
+ )
62
+ }
63
+ }
64
+ }
65
+
66
+ @OptIn(ExperimentalMaterial3Api ::class )
67
+ @Composable
68
+ fun EditorScreen (
69
+ configuration : EditorConfiguration ,
70
+ onClose : () -> Unit
71
+ ) {
72
+ var showMenu by remember { mutableStateOf(false ) }
73
+
74
+ Scaffold (
75
+ modifier = Modifier .fillMaxSize(),
76
+ topBar = {
77
+ TopAppBar (
78
+ title = { },
79
+ navigationIcon = {
80
+ IconButton (onClick = onClose) {
81
+ Icon (
82
+ imageVector = Icons .AutoMirrored .Filled .ArrowBack ,
83
+ contentDescription = " Close"
84
+ )
85
+ }
86
+ },
87
+ actions = {
88
+ IconButton (onClick = { }, enabled = false ) {
89
+ Icon (
90
+ imageVector = Icons .AutoMirrored .Filled .Undo ,
91
+ contentDescription = " Undo"
92
+ )
93
+ }
94
+ IconButton (onClick = { }, enabled = false ) {
95
+ Icon (
96
+ imageVector = Icons .AutoMirrored .Filled .Redo ,
97
+ contentDescription = " Redo"
98
+ )
99
+ }
100
+ TextButton (onClick = { }, enabled = false ) {
101
+ Text (" PUBLISH" )
102
+ }
103
+
104
+ // Overflow menu button and dropdown in Box for proper anchoring
105
+ Box {
106
+ IconButton (onClick = { showMenu = true }) {
107
+ Icon (
108
+ imageVector = Icons .Default .MoreVert ,
109
+ contentDescription = " More options"
110
+ )
111
+ }
112
+ DropdownMenu (
113
+ expanded = showMenu,
114
+ onDismissRequest = { showMenu = false }
115
+ ) {
116
+ DropdownMenuItem (
117
+ text = { Text (" Save" ) },
118
+ onClick = { },
119
+ enabled = false
120
+ )
121
+ DropdownMenuItem (
122
+ text = { Text (" Preview" ) },
123
+ onClick = { },
124
+ enabled = false
125
+ )
126
+ DropdownMenuItem (
127
+ text = { Text (" Code editor" ) },
128
+ onClick = { },
129
+ enabled = false
130
+ )
131
+ DropdownMenuItem (
132
+ text = { Text (" Post settings" ) },
133
+ onClick = { },
134
+ enabled = false
135
+ )
136
+ DropdownMenuItem (
137
+ text = { Text (" Help" ) },
138
+ onClick = { },
139
+ enabled = false
140
+ )
141
+ }
142
+ }
143
+ }
144
+ )
145
+ }
146
+ ) { innerPadding ->
147
+ AndroidView (
148
+ factory = { context ->
149
+ GutenbergView (context).apply {
150
+ start(configuration)
151
+ }
152
+ },
153
+ modifier = Modifier
154
+ .fillMaxSize()
155
+ .padding(innerPadding)
156
+ )
43
157
}
44
158
}
0 commit comments