Bimba.git

ref: 912f70db2ca99322470dde31169a941352694501

app/src/main/java/xyz/apiote/bimba/czwek/onboarding/OnboardingActivity.kt


 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// SPDX-FileCopyrightText: Adam Evyčędo
//
// SPDX-License-Identifier: GPL-3.0-or-later

package xyz.apiote.bimba.czwek.onboarding

import android.content.Intent
import android.graphics.Typeface
import android.os.Bundle
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.style.RelativeSizeSpan
import android.text.style.StyleSpan
import android.widget.Button
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import xyz.apiote.bimba.czwek.R
import xyz.apiote.bimba.czwek.databinding.ActivityOnboardingBinding
import xyz.apiote.bimba.czwek.settings.ServerChooserActivity

class OnboardingActivity : AppCompatActivity() {
	private var _binding: ActivityOnboardingBinding? = null
	private val binding get() = _binding!!

	private val activityLauncher =
		registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
			if (!getSharedPreferences("shp", MODE_PRIVATE).getBoolean("firstRun", true)) {
				finish()
			}
		}

	override fun onCreate(savedInstanceState: Bundle?) {
		super.onCreate(savedInstanceState)
		_binding = ActivityOnboardingBinding.inflate(layoutInflater)
		setContentView(binding.root)


		prepareButton(
			binding.buttonSimple,
			getString(R.string.onboarding_simple),
			getString(R.string.onboarding_simple_action),
			true
		)
		prepareButton(
			binding.buttonAdvanced,
			getString(R.string.onboarding_advanced),
			getString(R.string.onboarding_advanced_action),
			false
		)
	}

	private fun prepareButton(button: Button, title: String, description: String, simple: Boolean) {
		button.text = SpannableStringBuilder().apply {
			append(
				title,
				StyleSpan(Typeface.BOLD),
				Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
			)
			append("\n")
			append(
				description,
				RelativeSizeSpan(.75f),
				Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
			)
		}
		button.setOnClickListener {
			moveOn(simple)
		}
	}

	private fun moveOn(simple: Boolean) {
		val intent = Intent(this, ServerChooserActivity::class.java).apply {
			putExtra("simple", simple)
		}
		activityLauncher.launch(intent)
	}
}