Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.lb8
- import android.annotation.SuppressLint
- import androidx.appcompat.app.AppCompatActivity
- import android.os.Bundle
- import android.view.View
- import android.widget.ArrayAdapter
- import android.widget.ListView
- import android.widget.TextView
- import android.widget.Toast
- import androidx.core.os.bundleOf
- import androidx.fragment.app.FragmentTransaction
- interface OnDataListener {
- fun onData(Data: Int)
- fun onAnswer(right: Int?, summary: Int?, difficulty: Int?)
- }
- class MainActivity : AppCompatActivity(), OnDataListener {
- private var rightAnswers: Int= 0
- private var countAnswers: Int = 0
- private var taskDifficulty: Int = 10
- private var isTwoPane = false
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_main)
- isTwoPane = findViewById<View>(R.id.frame_left) != null
- val bundle = bundleOf("Data" to 0, "right" to rightAnswers, "all" to countAnswers, "diff" to taskDifficulty)
- val frag2 = RightFragment()
- frag2.arguments = bundle
- if (isTwoPane) {
- supportFragmentManager.beginTransaction()
- .add(R.id.frame_left, LeftFragment())
- .add(R.id.frame_right, frag2)
- .commit()
- }
- else {
- supportFragmentManager.beginTransaction()
- .add(R.id.container, LeftFragment())
- .commit()
- }
- }
- override fun onData(Data: Int) {
- val bundle = bundleOf("Data" to 0, "right" to rightAnswers, "all" to countAnswers, "diff" to taskDifficulty)
- val frag2 = RightFragment()
- frag2.arguments = bundle
- supportFragmentManager.beginTransaction()
- .replace(
- if (isTwoPane)
- R.id.frame_right
- else
- R.id.container,
- frag2)
- .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
- .addToBackStack(null)
- .commit()
- }
- override fun onAnswer(right: Int?, summary: Int?, diff: Int?) {
- if (right != null) {
- rightAnswers = right
- }
- if (summary != null) {
- countAnswers = summary
- }
- if (diff != null) {
- taskDifficulty = diff
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement