Skip to content

Commit 35715a6

Browse files
committed
More viewbinding
1 parent ec51576 commit 35715a6

4 files changed

Lines changed: 68 additions & 65 deletions

File tree

LogcatCoreUI/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ android {
1313
minSdkVersion 16
1414
project.archivesBaseName = "LogcatCore"
1515
}
16+
buildFeatures {
17+
viewBinding = true
18+
}
1619
namespace 'info.hannes.logcat.ui'
1720

1821
}

LogcatCoreUI/src/main/java/info/hannes/logcat/ui/BothLogActivity.kt

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,41 @@ package info.hannes.logcat.ui
22

33
import android.os.Bundle
44
import android.view.MenuItem
5-
import android.view.View
65
import androidx.appcompat.app.AppCompatActivity
6+
import info.hannes.logcat.ui.databinding.ActivityLogBinding
77

88
class BothLogActivity : AppCompatActivity() {
99

10+
private lateinit var binding: ActivityLogBinding
11+
1012
override fun onCreate(savedInstanceState: Bundle?) {
1113
super.onCreate(savedInstanceState)
12-
setContentView(R.layout.activity_log)
14+
binding = ActivityLogBinding.inflate(layoutInflater)
15+
setContentView(binding.root)
16+
1317
supportActionBar?.setDisplayHomeAsUpEnabled(true)
1418

15-
// Check that the activity is using the layout version with the fragment_container FrameLayout
16-
if (findViewById<View>(R.id.fragment_container) != null) {
17-
// However, if we're being restored from a previous state,
18-
// then we don't need to do anything and should return or else
19-
// we could end up with overlapping fragments.
20-
if (savedInstanceState != null) {
21-
return
22-
}
19+
// However, if we're being restored from a previous state,
20+
// then we don't need to do anything and should return or else
21+
// we could end up with overlapping fragments.
22+
if (savedInstanceState != null) {
23+
return
24+
}
2325

24-
// Create a new Fragment to be placed in the activity layout
25-
val bothLogFragment = BothLogsFragment.newInstance(
26-
"logfile.log",
27-
"search logfile",
28-
"search logcat",
29-
"your@mail.com"
30-
)
26+
// Create a new Fragment to be placed in the activity layout
27+
val bothLogFragment = BothLogsFragment.newInstance(
28+
"logfile.log",
29+
"search logfile",
30+
"search logcat",
31+
"your@mail.com"
32+
)
3133

32-
// In case this activity was started with special instructions from an
33-
// Intent, pass the Intent's extras to the fragment as arguments
34-
// firstFragment.arguments = intent.extras
34+
// In case this activity was started with special instructions from an
35+
// Intent, pass the Intent's extras to the fragment as arguments
36+
// firstFragment.arguments = intent.extras
3537

36-
// Add the fragment to the 'fragment_container' FrameLayout
37-
supportFragmentManager.beginTransaction().add(R.id.fragment_container, bothLogFragment).commit()
38-
}
38+
// Add the fragment to the 'fragment_container' FrameLayout
39+
supportFragmentManager.beginTransaction().add(R.id.fragment_container, bothLogFragment).commit()
3940
}
4041

4142
override fun onOptionsItemSelected(item: MenuItem): Boolean {

LogcatCoreUI/src/main/java/info/hannes/logcat/ui/LogcatActivity.kt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,36 @@ package info.hannes.logcat.ui
22

33
import android.os.Bundle
44
import android.view.MenuItem
5-
import android.view.View
65
import androidx.appcompat.app.AppCompatActivity
6+
import info.hannes.logcat.ui.databinding.ActivityLogBinding
77

88
class LogcatActivity : AppCompatActivity() {
99

10+
private lateinit var binding: ActivityLogBinding
11+
1012
override fun onCreate(savedInstanceState: Bundle?) {
1113
super.onCreate(savedInstanceState)
12-
setContentView(R.layout.activity_log)
13-
supportActionBar?.setDisplayHomeAsUpEnabled(true)
14+
binding = ActivityLogBinding.inflate(layoutInflater)
15+
setContentView(binding.root)
1416

15-
// Check that the activity is using the layout version with the fragment_container FrameLayout
16-
if (findViewById<View>(R.id.fragment_container) != null) {
17+
supportActionBar?.setDisplayHomeAsUpEnabled(true)
1718

18-
// However, if we're being restored from a previous state,
19-
// then we don't need to do anything and should return or else
20-
// we could end up with overlapping fragments.
21-
if (savedInstanceState != null) {
22-
return
23-
}
19+
// However, if we're being restored from a previous state,
20+
// then we don't need to do anything and should return or else
21+
// we could end up with overlapping fragments.
22+
if (savedInstanceState != null) {
23+
return
24+
}
2425

25-
// Create a new Fragment to be placed in the activity layout
26-
val firstFragment = LogcatFragment.newInstance("logcat.log", "search logcat")
26+
// Create a new Fragment to be placed in the activity layout
27+
val firstFragment = LogcatFragment.newInstance("logcat.log", "search logcat")
2728

28-
// In case this activity was started with special instructions from an
29-
// Intent, pass the Intent's extras to the fragment as arguments
30-
// firstFragment.arguments = intent.extras
29+
// In case this activity was started with special instructions from an
30+
// Intent, pass the Intent's extras to the fragment as arguments
31+
// firstFragment.arguments = intent.extras
3132

32-
// Add the fragment to the 'fragment_container' FrameLayout
33-
supportFragmentManager.beginTransaction().add(R.id.fragment_container, firstFragment).commit()
34-
}
33+
// Add the fragment to the 'fragment_container' FrameLayout
34+
supportFragmentManager.beginTransaction().add(R.id.fragment_container, firstFragment).commit()
3535
}
3636

3737
override fun onOptionsItemSelected(item: MenuItem): Boolean {

LogcatCoreUI/src/main/java/info/hannes/logcat/ui/LogfileActivity.kt

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,39 @@ package info.hannes.logcat.ui
22

33
import android.os.Bundle
44
import android.view.MenuItem
5-
import android.view.View
65
import androidx.appcompat.app.AppCompatActivity
6+
import info.hannes.logcat.ui.databinding.ActivityLogBinding
77

88
class LogfileActivity : AppCompatActivity() {
99

10+
private lateinit var binding: ActivityLogBinding
11+
1012
override fun onCreate(savedInstanceState: Bundle?) {
1113
super.onCreate(savedInstanceState)
12-
setContentView(R.layout.activity_log)
13-
supportActionBar?.setDisplayHomeAsUpEnabled(true)
14+
binding = ActivityLogBinding.inflate(layoutInflater)
15+
setContentView(binding.root)
1416

15-
// Check that the activity is using the layout version with the fragment_container FrameLayout
16-
if (findViewById<View>(R.id.fragment_container) != null) {
17-
18-
// However, if we're being restored from a previous state,
19-
// then we don't need to do anything and should return or else
20-
// we could end up with overlapping fragments.
21-
if (savedInstanceState != null) {
22-
return
23-
}
17+
supportActionBar?.setDisplayHomeAsUpEnabled(true)
2418

25-
// Create a new Fragment to be placed in the activity layout
26-
val firstFragment = LogfileFragment.newInstance(
27-
"logfile.log",
28-
"search logfile"
29-
)
19+
// However, if we're being restored from a previous state,
20+
// then we don't need to do anything and should return or else
21+
// we could end up with overlapping fragments.
22+
if (savedInstanceState != null) {
23+
return
24+
}
3025

31-
// In case this activity was started with special instructions from an
32-
// Intent, pass the Intent's extras to the fragment as arguments
33-
// firstFragment.arguments = intent.extras
26+
// Create a new Fragment to be placed in the activity layout
27+
val firstFragment = LogfileFragment.newInstance(
28+
"logfile.log",
29+
"search logfile"
30+
)
3431

35-
// Add the fragment to the 'fragment_container' FrameLayout
36-
supportFragmentManager.beginTransaction().add(R.id.fragment_container, firstFragment).commit()
37-
}
32+
// In case this activity was started with special instructions from an
33+
// Intent, pass the Intent's extras to the fragment as arguments
34+
// firstFragment.arguments = intent.extras
3835

36+
// Add the fragment to the 'fragment_container' FrameLayout
37+
supportFragmentManager.beginTransaction().add(R.id.fragment_container, firstFragment).commit()
3938
}
4039

4140
override fun onOptionsItemSelected(item: MenuItem): Boolean {

0 commit comments

Comments
 (0)