|
8 | 8 |
|
9 | 9 | package com.example.executorchllamademo |
10 | 10 |
|
11 | | -import android.app.AlertDialog |
12 | 11 | import android.os.Build |
13 | 12 | import android.os.Bundle |
14 | | -import android.widget.ImageButton |
15 | | -import android.widget.ListView |
16 | | -import androidx.appcompat.app.AppCompatActivity |
| 13 | +import androidx.activity.ComponentActivity |
| 14 | +import androidx.activity.compose.setContent |
| 15 | +import androidx.compose.foundation.layout.fillMaxSize |
| 16 | +import androidx.compose.material3.Surface |
| 17 | +import androidx.compose.ui.Modifier |
17 | 18 | import androidx.core.content.ContextCompat |
18 | | -import androidx.core.view.ViewCompat |
19 | | -import androidx.core.view.WindowInsetsCompat |
| 19 | +import com.example.executorchllamademo.ui.screens.LogsScreen |
| 20 | +import com.example.executorchllamademo.ui.theme.LlamaDemoTheme |
20 | 21 |
|
21 | | -class LogsActivity : AppCompatActivity() { |
22 | | - |
23 | | - private lateinit var logsAdapter: LogsAdapter |
| 22 | +class LogsActivity : ComponentActivity() { |
24 | 23 |
|
25 | 24 | override fun onCreate(savedInstanceState: Bundle?) { |
26 | 25 | super.onCreate(savedInstanceState) |
27 | | - setContentView(R.layout.activity_logs) |
28 | 26 |
|
29 | 27 | if (Build.VERSION.SDK_INT >= 21) { |
30 | 28 | window.statusBarColor = ContextCompat.getColor(this, R.color.status_bar) |
31 | 29 | window.navigationBarColor = ContextCompat.getColor(this, R.color.nav_bar) |
32 | 30 | } |
33 | 31 |
|
34 | | - ViewCompat.setOnApplyWindowInsetsListener(requireViewById(R.id.main)) { v, insets -> |
35 | | - val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()) |
36 | | - v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom) |
37 | | - insets |
38 | | - } |
39 | | - |
40 | | - setupLogs() |
41 | | - setupClearLogsButton() |
42 | | - } |
43 | | - |
44 | | - override fun onResume() { |
45 | | - super.onResume() |
46 | | - logsAdapter.clear() |
47 | | - logsAdapter.addAll(ETLogging.getInstance().getLogs()) |
48 | | - logsAdapter.notifyDataSetChanged() |
49 | | - } |
50 | | - |
51 | | - private fun setupLogs() { |
52 | | - val logsListView = requireViewById<ListView>(R.id.logsListView) |
53 | | - logsAdapter = LogsAdapter(this, R.layout.logs_message) |
54 | | - |
55 | | - logsListView.adapter = logsAdapter |
56 | | - logsAdapter.addAll(ETLogging.getInstance().getLogs()) |
57 | | - logsAdapter.notifyDataSetChanged() |
58 | | - } |
59 | | - |
60 | | - private fun setupClearLogsButton() { |
61 | | - val clearLogsButton = requireViewById<ImageButton>(R.id.clearLogsButton) |
62 | | - clearLogsButton.setOnClickListener { |
63 | | - AlertDialog.Builder(this) |
64 | | - .setTitle("Delete Logs History") |
65 | | - .setMessage("Do you really want to delete logs history?") |
66 | | - .setIcon(android.R.drawable.ic_dialog_alert) |
67 | | - .setPositiveButton(android.R.string.yes) { _, _ -> |
68 | | - // Clear the messageAdapter and sharedPreference |
69 | | - ETLogging.getInstance().clearLogs() |
70 | | - logsAdapter.clear() |
71 | | - logsAdapter.notifyDataSetChanged() |
| 32 | + setContent { |
| 33 | + LlamaDemoTheme(darkTheme = false) { |
| 34 | + Surface(modifier = Modifier.fillMaxSize()) { |
| 35 | + LogsScreen( |
| 36 | + onBackPressed = { finish() } |
| 37 | + ) |
72 | 38 | } |
73 | | - .setNegativeButton(android.R.string.no, null) |
74 | | - .show() |
| 39 | + } |
75 | 40 | } |
76 | 41 | } |
77 | | - |
78 | | - override fun onDestroy() { |
79 | | - super.onDestroy() |
80 | | - ETLogging.getInstance().saveLogs() |
81 | | - } |
82 | 42 | } |
0 commit comments