Skip to content

Commit d3cbfba

Browse files
authored
Merge pull request #277 from wordpress-mobile/issue/toolbar-media-mode
issue/toolbar-media-mode
2 parents 4dcd7c1 + 7b50e25 commit d3cbfba

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/toolbar/AztecToolbar.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class AztecToolbar : FrameLayout, OnMenuItemClickListener {
2626
private var headingMenu: PopupMenu? = null
2727
private var sourceEditor: SourceViewEditText? = null
2828
private var dialogShortcuts: AlertDialog? = null
29+
private var isMediaModeEnabled: Boolean = false;
2930

3031
constructor(context: Context) : super(context) {
3132
initView()
@@ -228,13 +229,15 @@ class AztecToolbar : FrameLayout, OnMenuItemClickListener {
228229
super.onRestoreInstanceState(savedState.superState)
229230
val restoredState = savedState.state
230231
toggleHtmlMode(restoredState.getBoolean("isSourceVisible"))
232+
enableMediaMode(restoredState.getBoolean("isMediaMode"))
231233
}
232234

233235
override fun onSaveInstanceState(): Parcelable {
234236
val superState = super.onSaveInstanceState()
235237
val savedState = SourceViewEditText.SavedState(superState)
236238
val bundle = Bundle()
237239
bundle.putBoolean("isSourceVisible", sourceEditor?.visibility == View.VISIBLE)
240+
bundle.putBoolean("isMediaMode", isMediaModeEnabled)
238241
savedState.state = bundle
239242
return savedState
240243
}
@@ -408,6 +411,21 @@ class AztecToolbar : FrameLayout, OnMenuItemClickListener {
408411
}
409412
}
410413

414+
fun isMediaModeEnabled(): Boolean {
415+
return isMediaModeEnabled;
416+
}
417+
418+
fun enableMediaMode(isEnabled: Boolean) {
419+
isMediaModeEnabled = isEnabled;
420+
ToolbarAction.values().forEach { action ->
421+
if (action == ToolbarAction.ADD_MEDIA) {
422+
toggleButton(findViewById(action.buttonId), isEnabled)
423+
} else {
424+
toggleButtonState(findViewById(action.buttonId), !isEnabled)
425+
}
426+
}
427+
}
428+
411429
private fun showDialogShortcuts() {
412430
val layout = LayoutInflater.from(context).inflate(R.layout.dialog_shortcuts, null)
413431
val builder = AlertDialog.Builder(context)

aztec/src/main/res/drawable/format_bar_button_media_selector.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
xmlns:android="http://schemas.android.com/apk/res/android" >
55

66
<item android:drawable="@drawable/format_bar_button_media_disabled" android:state_enabled="false" />
7+
<item android:drawable="@drawable/format_bar_button_media_highlighted" android:state_checked="true" />
78
<item android:drawable="@drawable/format_bar_button_media_highlighted" android:state_pressed="true" />
89
<item android:drawable="@drawable/format_bar_button_media_highlighted" android:state_focused="true" />
910
<item android:drawable="@drawable/format_bar_button_media" />

0 commit comments

Comments
 (0)