<commit_before>import Grabber 1.0
import QtMultimedia 5.12
import QtQuick 2.12
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.12

Page {
    id: root

    signal closed()

    property var images
    property int index
    property var image: images[index]

    property bool showHd: false
    property bool showTags: false

    ShareUtils {
        id: shareUtils
    }

    Component {
        id: actionButtons

        RowLayout {
            ToolButton {
                icon.source: showTags ? "/images/icons/image.png" : "/images/icons/tags.png"
                onClicked: showTags = !showTags
            }

            ToolButton {
                icon.source: "/images/icons/share.png"
                onClicked: shareUtils.share("Image", image.fileUrl)
            }

            ToolButton {
                icon.source: "/images/icons/download.png"
                onClicked: backend.downloadImage(image.image)
            }

            ToolButton {
                visible: image.sampleUrl !== image.fileUrl
                icon.source: showHd ? "/images/icons/ld.png" : "/images/icons/hd.png"
                onClicked: showHd = !showHd
            }
        }
    }

    header: ToolBar {
        RowLayout {
            anchors.fill: parent

            ToolButton {
                icon.source: "/images/icons/back.png"
                onClicked: root.closed()
            }

            Label {
                text: qsTr("Image") // TODO: add more info about the image
                elide: Label.ElideRight
                verticalAlignment: Qt.AlignVCenter
                Layout.fillWidth: true
            }

            Loader {
                active: !gSettings.zoom_buttonsAtBottom.value
                sourceComponent: actionButtons
            }
        }
    }

    footer: Loader {
        active: gSettings.zoom_buttonsAtBottom.value
        sourceComponent: Component {
            RowLayout {
                Label {
                    Layout.fillWidth: true
                }

                Loader {
                    sourceComponent: actionButtons
                }
            }
        }
    }

    SwipeView {
        id: swipeView
        currentIndex: root.index
        anchors.fill: parent
        clip: true
        onCurrentIndexChanged: { showHd = false; showTags = false }

        Repeater {
            model: root.images

            Loader {
                active: SwipeView.isPreviousItem || SwipeView.isCurrentItem || SwipeView.isNextItem

                sourceComponent: StackLayout {
                    id: stackLayout
                    clip: true
                    currentIndex: showTags && index == swipeView.currentIndex ? 1 : 0

                    Item {
                        Loader {
                            active: !image.isVideo
                            anchors.fill: parent

                            sourceComponent: ColumnLayout {
                                ZoomableImage {
                                    id: img
                                    Layout.fillWidth: true
                                    Layout.fillHeight: true
                                    source: showHd && index == swipeView.currentIndex ? modelData.fileUrl : modelData.sampleUrl
                                    animated: image.isAnimated
                                    clip: true
                                }

                                ProgressBar {
                                    value: img.progress
                                    visible: img.status != Image.Ready
                                    Layout.fillWidth: true
                                }
                            }
                        }

                        Loader {
                            active: image.isVideo
                            anchors.fill: parent

                            sourceComponent: VideoPlayer {
                                fillMode: VideoOutput.PreserveAspectFit
                                source: showHd && index == swipeView.currentIndex ? modelData.fileUrl : modelData.sampleUrl
                                clip: true
                                autoPlay: index == swipeView.currentIndex
                            }
                        }
                    }

                    ScrollView {<commit_msg>Fix transition from animated to static image on Android (issue #2147)<commit_after>import Grabber 1.0
import QtMultimedia 5.12
import QtQuick 2.12
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.12

Page {
    id: root

    signal closed()

    property var images
    property int index
    property var image: images[index]

    property bool showHd: false
    property bool showTags: false

    ShareUtils {
        id: shareUtils
    }

    Component {
        id: actionButtons

        RowLayout {
            ToolButton {
                icon.source: showTags ? "/images/icons/image.png" : "/images/icons/tags.png"
                onClicked: showTags = !showTags
            }

            ToolButton {
                icon.source: "/images/icons/share.png"
                onClicked: shareUtils.share("Image", image.fileUrl)
            }

            ToolButton {
                icon.source: "/images/icons/download.png"
                onClicked: backend.downloadImage(image.image)
            }

            ToolButton {
                visible: image.sampleUrl !== image.fileUrl
                icon.source: showHd ? "/images/icons/ld.png" : "/images/icons/hd.png"
                onClicked: showHd = !showHd
            }
        }
    }

    header: ToolBar {
        RowLayout {
            anchors.fill: parent

            ToolButton {
                icon.source: "/images/icons/back.png"
                onClicked: root.closed()
            }

            Label {
                text: qsTr("Image") // TODO: add more info about the image
                elide: Label.ElideRight
                verticalAlignment: Qt.AlignVCenter
                Layout.fillWidth: true
            }

            Loader {
                active: !gSettings.zoom_buttonsAtBottom.value
                sourceComponent: actionButtons
            }
        }
    }

    footer: Loader {
        active: gSettings.zoom_buttonsAtBottom.value
        sourceComponent: Component {
            RowLayout {
                Label {
                    Layout.fillWidth: true
                }

                Loader {
                    sourceComponent: actionButtons
                }
            }
        }
    }

    SwipeView {
        id: swipeView
        currentIndex: root.index
        anchors.fill: parent
        clip: true
        onCurrentIndexChanged: { showHd = false; showTags = false }

        Repeater {
            model: root.images

            Loader {
                active: SwipeView.isPreviousItem || SwipeView.isCurrentItem || SwipeView.isNextItem

                sourceComponent: StackLayout {
                    id: stackLayout
                    clip: true
                    currentIndex: showTags && index == swipeView.currentIndex ? 1 : 0

                    Item {
                        Loader {
                            active: !modelData.isVideo
                            anchors.fill: parent

                            sourceComponent: ColumnLayout {
                                ZoomableImage {
                                    id: img
                                    Layout.fillWidth: true
                                    Layout.fillHeight: true
                                    source: showHd && index == swipeView.currentIndex ? modelData.fileUrl : modelData.sampleUrl
                                    animated: modelData.isAnimated
                                    clip: true
                                }

                                ProgressBar {
                                    value: img.progress
                                    visible: img.status != Image.Ready
                                    Layout.fillWidth: true
                                }
                            }
                        }

                        Loader {
                            active: modelData.isVideo
                            anchors.fill: parent

                            sourceComponent: VideoPlayer {
                                fillMode: VideoOutput.PreserveAspectFit
                                source: showHd && index == swipeView.currentIndex ? modelData.fileUrl : modelData.sampleUrl
                                clip: true
                                autoPlay: index == swipeView.currentIndex
                            }
                        }
                    }

                    ScrollView {
{'fraction_non_alphanumeric': 0.06329545454545454, 'fraction_numerical': 0.003863636363636364, 'mean_word_length': 0.9614441720525964, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '358411', 'n_tokens_mistral': 2092, 'n_tokens_neox': 1914, 'n_words': 424}