Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 778fdd50 authored by Charlotte Lu's avatar Charlotte Lu Committed by Tom Hsu
Browse files

[WIFI-WEP] Change dalogWindowType to function.

Test: Visual Test
Bug: 328365908
Change-Id: I1fc3405361e0039c91aaeed42cc555168fb85b7f
(cherry picked from commit 5863b807)
parent 1a74c985
Loading
Loading
Loading
Loading
+78 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settingslib.spa

import android.content.Context
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.appcompat.app.AlertDialog
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.ComposeView
import com.android.settingslib.spa.framework.common.LogCategory
import com.android.settingslib.spa.framework.common.SpaEnvironmentFactory
import com.android.settingslib.spa.framework.theme.SettingsTheme

/**
 * Dialog activity when the dialog window type need to be override.
 *
 * Please use [SpaBaseDialogActivity] for all other use cases.
 */
abstract class SpaDialogWindowTypeActivity : ComponentActivity() {
    private val spaEnvironment get() = SpaEnvironmentFactory.instance
    private var dialog: AlertDialogWithType? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        spaEnvironment.logger.message(TAG, "onCreate", category = LogCategory.FRAMEWORK)

        dialog = AlertDialogWithType(this).apply { show() }
    }

    override fun finish() {
        dialog?.dismiss()
        super.finish()
    }

    abstract fun getDialogWindowType(): Int?

    @Composable
    abstract fun Content()

    inner class AlertDialogWithType(context: Context) :
        AlertDialog(context, R.style.Theme_SpaLib_Dialog) {

        init {
            setView(ComposeView(context).apply {
                setContent {
                    SettingsTheme {
                        this@SpaDialogWindowTypeActivity.Content()
                    }
                }
            })
            setOnDismissListener { finish() }
        }

        override fun onCreate(savedInstanceState: Bundle?) {
            getDialogWindowType()?.let { window?.setType(it) }
            super.onCreate(savedInstanceState)
        }
    }

    companion object {
        private const val TAG = "SpaBaseDialogActivity"
    }
}