Skip to content

Commit 8f4adb4

Browse files
authored
Replaced kotlin synthetics with ViewBinding [#47]
1 parent e598160 commit 8f4adb4

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The format is based on the Steamclock [Release Management Guide](https://github.
66
## Unreleased
77

88
- Updated libraries including Sentry (#101)
9+
- Replaced kotlin synthetics with ViewBinding in sample app (#47)
910

1011
---
1112

app/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ buildscript {
77
plugins {
88
id 'com.android.application'
99
id 'kotlin-android'
10-
id 'kotlin-android-extensions'
1110
// Provides auto-uploading of proguard mappings to Sentry
1211
id 'io.sentry.android.gradle' version '2.1.4'
1312
}
@@ -20,6 +19,10 @@ android {
2019
jvmTarget = "1.8"
2120
}
2221

22+
buildFeatures {
23+
viewBinding true
24+
}
25+
2326
defaultConfig {
2427
applicationId "com.steamclock.steamclogsample"
2528
minSdkVersion 21

app/src/main/java/com/steamclock/steamclogsample/MainActivity.kt

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,56 @@ import android.widget.AdapterView
99
import android.widget.Toast
1010
import androidx.appcompat.app.AppCompatActivity
1111
import com.steamclock.steamclog.*
12-
import kotlinx.android.synthetic.main.activity_main.*
12+
import com.steamclock.steamclogsample.databinding.ActivityMainBinding
1313
import kotlinx.coroutines.Dispatchers
1414
import kotlinx.coroutines.GlobalScope
1515
import kotlinx.coroutines.launch
1616

1717

1818
class MainActivity : AppCompatActivity() {
1919

20+
private lateinit var binding: ActivityMainBinding
21+
2022
override fun onCreate(savedInstanceState: Bundle?) {
2123
super.onCreate(savedInstanceState)
22-
setContentView(R.layout.activity_main)
24+
binding = ActivityMainBinding.inflate(layoutInflater)
25+
val view = binding.root
26+
val toolbar = binding.toolbar
2327
setSupportActionBar(toolbar)
2428
title = "SteamClog Test"
29+
setContentView(view)
2530

2631
// UI init
27-
demo_text.text = clog.toString()
28-
log_things.setOnClickListener { testLogging() }
29-
dump_file_button.setOnClickListener { testLogDump() }
30-
non_fatal.setOnClickListener { testNonFatal() }
31-
log_blocked_exception.setOnClickListener { testBlockedException() }
32-
track_analytic.setOnClickListener {
32+
binding.demoText.text = clog.toString()
33+
binding.logThings.setOnClickListener { testLogging() }
34+
binding.dumpFileButton.setOnClickListener { testLogDump() }
35+
binding.nonFatal.setOnClickListener { testNonFatal() }
36+
binding.logBlockedException.setOnClickListener { testBlockedException() }
37+
binding.trackAnalytic.setOnClickListener {
3338
Toast.makeText(applicationContext, "Not supported", Toast.LENGTH_LONG).show()
3439
}
3540

36-
add_user_id.setOnClickListener { clog.setUserId("1234") }
41+
binding.addUserId.setOnClickListener { clog.setUserId("1234") }
3742

38-
demo_text.setOnLongClickListener {
43+
binding.demoText.setOnLongClickListener {
3944
copyFileToClipboard()
4045
true
4146
}
4247

43-
level_selector.setSelection(when (clog.config.logLevel) {
48+
binding.levelSelector.setSelection(when (clog.config.logLevel) {
4449
LogLevelPreset.DebugVerbose -> 0
4550
LogLevelPreset.Debug -> 1
4651
LogLevelPreset.Release -> 2
4752
LogLevelPreset.ReleaseAdvanced -> 3
4853
else -> 0
4954
})
5055

51-
level_selector.onItemSelectedListener = object: AdapterView.OnItemSelectedListener {
56+
binding.levelSelector.onItemSelectedListener = object: AdapterView.OnItemSelectedListener {
5257
override fun onNothingSelected(parent: AdapterView<*>?) {}
5358

5459
override fun onItemSelected(
5560
parent: AdapterView<*>?,
56-
view: View?,
61+
view: View,
5762
position: Int,
5863
id: Long
5964
) {
@@ -74,7 +79,7 @@ class MainActivity : AppCompatActivity() {
7479
LogLevelPreset.DebugVerbose
7580
}
7681
}
77-
demo_text.text = clog.toString()
82+
binding.demoText.text = clog.toString()
7883
clog.warn("LogLevel changed to ${clog.config.logLevel.title}")
7984
}
8085
}
@@ -181,7 +186,7 @@ class MainActivity : AppCompatActivity() {
181186
}
182187

183188
private fun testLogDump() = GlobalScope.launch(Dispatchers.Main) {
184-
demo_text?.text = SteamcLog.getLogFileContents()
189+
binding.demoText.text = SteamcLog.getLogFileContents()
185190
}
186191

187192
private fun simulateCrash() {
@@ -191,7 +196,7 @@ class MainActivity : AppCompatActivity() {
191196

192197
private fun copyFileToClipboard() {
193198
val clipboardManager = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
194-
val clipData = ClipData.newPlainText("File Dump", demo_text?.text)
199+
val clipData = ClipData.newPlainText("File Dump", binding.demoText.text)
195200
clipboardManager.setPrimaryClip(clipData)
196201
Toast.makeText(applicationContext, "Copied to clipboard", Toast.LENGTH_LONG).show()
197202
}

steamclog/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
plugins {
22
id 'com.android.library'
33
id 'kotlin-android'
4-
id 'kotlin-android-extensions'
54
id 'maven-publish'
65
// Note, do not apply sentry plugins here; must be done in application module
76
}

0 commit comments

Comments
 (0)