forked from omni/OmniCards
initial commit
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
package ru.omni_devel.cards
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.widget.Button
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import org.w3c.dom.Text
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
private lateinit var cardsList: LinearLayout
|
||||
private lateinit var db: DbHelper
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
setContentView(R.layout.activity_main)
|
||||
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
|
||||
}
|
||||
|
||||
db = DbHelper(this, null)
|
||||
cardsList = findViewById(R.id.cardsList)
|
||||
|
||||
val addCardButton: Button = findViewById(R.id.addCardButton)
|
||||
addCardButton.setOnClickListener {
|
||||
startActivity(Intent(this, AddCardActivity::class.java))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
renderCards()
|
||||
}
|
||||
|
||||
private fun renderCards() {
|
||||
val cards = db.getCards()
|
||||
|
||||
cardsList.removeAllViews()
|
||||
|
||||
if (cards.isEmpty()) {
|
||||
val text = TextView(this)
|
||||
|
||||
val params = LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
|
||||
text.text = "Add a card to get started"
|
||||
text.layoutParams = params
|
||||
|
||||
cardsList.addView(text)
|
||||
} else {
|
||||
for (card in cards) {
|
||||
val button = MaterialButton(this)
|
||||
|
||||
val params = LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
params.setMargins(16, 4, 16, 4)
|
||||
|
||||
button.text = card.name
|
||||
button.layoutParams = params
|
||||
button.cornerRadius = (12 * resources.displayMetrics.density).toInt()
|
||||
|
||||
cardsList.addView(button)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user