Skip to content

Commit

Permalink
Merge pull request #32 from tal-sitton/fix-screening-box
Browse files Browse the repository at this point in the history
fixed screenings boxes
  • Loading branch information
tal-sitton authored Sep 15, 2022
2 parents d7d7df3 + c5a1328 commit 81355f2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
5 changes: 5 additions & 0 deletions app/src/main/java/com/example/firstkotlinapp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,13 @@ class MainActivity : MyTemplateActivity() {

private var dateButton: TextView? = null

private lateinit var scrl: ScrollView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Utils.showToast(this, "onCreate")
val scrl: ScrollView = findViewById(R.id.scrl)
scrl.smoothScrollTo(0, 0)

JSONUtils.jsonToList(this)
resetToDefault()
Expand Down Expand Up @@ -138,6 +142,7 @@ class MainActivity : MyTemplateActivity() {

override fun onRestart() {
super.onRestart()
scrl.scrollTo(0, 0)
dateButton?.text = DateActivity.selectedDatStr
if (filter())
createButtons(findViewById(R.id.gl))
Expand Down
39 changes: 26 additions & 13 deletions app/src/main/java/com/example/firstkotlinapp/Screening.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.text.Spannable
import android.text.SpannableString
import android.text.style.RelativeSizeSpan
import android.text.style.StyleSpan
import android.text.style.UnderlineSpan
import android.view.ViewGroup
import android.widget.TextView
import java.time.LocalDateTime
Expand All @@ -27,7 +28,7 @@ class Screening(

val cinema: String = "$theater $city"
var dateTime: LocalDateTime = LocalDateTime.MIN
var dateTimeFormatted: String? = null
var timeFormatted: String

init {
val day = date.split("-")[0].toInt()
Expand All @@ -36,8 +37,8 @@ class Screening(
val hour = time.split(":")[0].toInt()
val minute = time.split(":")[1].toInt()
dateTime = LocalDateTime.of(year, month, day, hour, minute)
dateTimeFormatted =
dateTime.format(DateTimeFormatter.ofPattern("HH:mm - dd.MM"))
timeFormatted =
dateTime.format(DateTimeFormatter.ofPattern("HH:mm"))
}

override fun toString(): String {
Expand All @@ -55,24 +56,36 @@ class Screening(
button.setTextColor(context.resources.getColor(R.color.black, context.theme))

val text: Spannable =
SpannableString("$movie ($type)\n\n$city\n$theater\n$dateTimeFormatted\n")
SpannableString("$timeFormatted\n\n$movie ($type)\n\n$city\n$theater")
text.setSpan(
UnderlineSpan(),
text.indexOf(timeFormatted),
timeFormatted.length,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)
text.setSpan(
StyleSpan(Typeface.BOLD),
text.indexOf(timeFormatted),
timeFormatted.length,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)
text.setSpan(
StyleSpan(Typeface.BOLD),
0,
"$movie ($type)".length,
Spannable.SPAN_INCLUSIVE_INCLUSIVE
text.indexOf(movie),
text.indexOf(type) + type.length + 1,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)
text.setSpan(
RelativeSizeSpan(1.15f),
0,
"$movie ($type)".length,
Spannable.SPAN_INCLUSIVE_INCLUSIVE
text.indexOf(movie),
text.indexOf(type) + type.length + 1,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)
text.setSpan(
StyleSpan(Typeface.BOLD),
"$movie ($type)".length + 2,
"$movie ($type)".length + 1 + "$city\n\n$theater".length,
Spannable.SPAN_INCLUSIVE_INCLUSIVE
text.indexOf(city),
text.indexOf(theater),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)
button.text = text

Expand Down

0 comments on commit 81355f2

Please sign in to comment.