Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

likorn / quick_max

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • quick_max
  • ..
  • quickmax
  • ViewUtils.kt
Find file
BlameHistoryPermalink
  • likorn's avatar
    Timing is now managed by TimerFragment · d0276422
    likorn committed 5 years ago
    d0276422
ViewUtils.kt 1.68 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
package com.paktalin.quickmax

import android.content.Context
import android.content.res.Resources
import android.os.Bundle
import android.view.View
import android.widget.FrameLayout
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.commit
import com.google.android.material.card.MaterialCardView

fun getTextView(card: View): TextView {
    return  ((card as MaterialCardView).getChildAt(0) as FrameLayout).getChildAt(0) as TextView
}

fun color(context: Context, id: Int): Int {
    return ContextCompat.getColor(context, id)
}

fun textSize(resources: Resources): Float {
    val screenDensity = resources.displayMetrics.density
    return resources.getDimension(R.dimen.response_text_size) / screenDensity
}

fun addTimerFragment(supportFragmentManager: FragmentManager, millisToSolve: Long) {
    val timerFragment = TimerFragment().apply {
        arguments = Bundle().apply { putLong("millis_to_solve", millisToSolve) }
    }
    supportFragmentManager.commit(true) {
        replace(R.id.fragment_timer, timerFragment, "timer_fragment")
    }
}

fun addButtonNextFragment(supportFragmentManager: FragmentManager, correct: Boolean) {
    val fragmentBtnNext = ButtonNextFragment().apply {
        arguments = Bundle().apply { putBoolean("correct", correct) }
    }
    supportFragmentManager.commit(true) {
        add(R.id.main_layout, fragmentBtnNext, "btn_next_fragment")
    }
}

fun removeButtonNextFragment(supportFragmentManager: FragmentManager) {
    supportFragmentManager.findFragmentByTag("btn_next_fragment")?.let {fragment ->
        supportFragmentManager.commit(true) { remove(fragment) }
    }
}