Upload files to "Tugas HelloWord"
This commit is contained in:
		
							parent
							
								
									b1bf405e69
								
							
						
					
					
						commit
						2be97be605
					
				@ -1,26 +1,62 @@
 | 
			
		||||
package com.example.hellobila
 | 
			
		||||
package com.example.sorting
 | 
			
		||||
 | 
			
		||||
import android.os.Bundle
 | 
			
		||||
import androidx.activity.ComponentActivity
 | 
			
		||||
import androidx.activity.compose.setContent
 | 
			
		||||
import androidx.activity.enableEdgeToEdge
 | 
			
		||||
import androidx.appcompat.app.AppCompatActivity
 | 
			
		||||
import androidx.core.view.ViewCompat
 | 
			
		||||
import androidx.core.view.WindowInsetsCompat
 | 
			
		||||
import androidx.compose.foundation.layout.Column
 | 
			
		||||
import androidx.compose.foundation.layout.fillMaxSize
 | 
			
		||||
import androidx.compose.material3.MaterialTheme
 | 
			
		||||
import androidx.compose.material3.Surface
 | 
			
		||||
import androidx.compose.material3.Text
 | 
			
		||||
import androidx.compose.runtime.*
 | 
			
		||||
import androidx.compose.ui.Modifier
 | 
			
		||||
import androidx.compose.ui.tooling.preview.Preview
 | 
			
		||||
import com.example.sorting.ui.theme.SortingTheme
 | 
			
		||||
 | 
			
		||||
class MainActivity : AppCompatActivity() {
 | 
			
		||||
class MainActivity : ComponentActivity() {
 | 
			
		||||
    override fun onCreate(savedInstanceState: Bundle?) {
 | 
			
		||||
        super.onCreate(savedInstanceState)
 | 
			
		||||
 | 
			
		||||
        // Mengaktifkan tampilan edge-to-edge agar aplikasi memenuhi seluruh layar
 | 
			
		||||
        enableEdgeToEdge()
 | 
			
		||||
        setContent {
 | 
			
		||||
            SortingTheme {
 | 
			
		||||
                Surface(
 | 
			
		||||
                    modifier = Modifier.fillMaxSize(),
 | 
			
		||||
                    color = MaterialTheme.colorScheme.background
 | 
			
		||||
                ) {
 | 
			
		||||
                    SortIntarray()
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
        // Menghubungkan layout XML (activity_main.xml) dengan activity ini
 | 
			
		||||
        setContentView(R.layout.activity_main)
 | 
			
		||||
@Composable
 | 
			
		||||
fun SortIntarray() {
 | 
			
		||||
    // Angka yang mau diurutkan
 | 
			
		||||
    val numbers = listOf(1, 7, 99, 46, 90, 600, 98, 76, 52)
 | 
			
		||||
 | 
			
		||||
        // Menambahkan padding pada layout utama agar tidak tertimpa oleh status bar atau navigation bar
 | 
			
		||||
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
 | 
			
		||||
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
 | 
			
		||||
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
 | 
			
		||||
            insets
 | 
			
		||||
    // State sebelum dan sesudah
 | 
			
		||||
    var before by remember { mutableStateOf("") }
 | 
			
		||||
    var after by remember { mutableStateOf("") }
 | 
			
		||||
 | 
			
		||||
    // Proses sortir
 | 
			
		||||
    LaunchedEffect(Unit) {
 | 
			
		||||
        before = numbers.joinToString(", ")
 | 
			
		||||
        val sorted = numbers.sorted()
 | 
			
		||||
        after = sorted.joinToString(", ")
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Column {
 | 
			
		||||
        Text(text = "Sebelum diurutkan: $before")
 | 
			
		||||
        Text(text = "Sesudah diurutkan: $after")
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Preview(showBackground = true)
 | 
			
		||||
@Composable
 | 
			
		||||
fun PreviewSortIntarray() {
 | 
			
		||||
    SortingTheme {
 | 
			
		||||
        SortIntarray()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user