Skip to content

Commit

Permalink
Convert settings and about activities to Kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
TacoTheDank committed Feb 18, 2021
1 parent 4d6176d commit 751b95b
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 100 deletions.
55 changes: 0 additions & 55 deletions app/src/main/java/tk/wasdennnoch/scoop/ui/AboutActivity.java

This file was deleted.

54 changes: 54 additions & 0 deletions app/src/main/java/tk/wasdennnoch/scoop/ui/AboutActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package tk.wasdennnoch.scoop.ui

import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.pm.PackageInfoCompat
import androidx.core.net.toUri
import tk.wasdennnoch.scoop.R
import tk.wasdennnoch.scoop.databinding.ActivityAboutBinding

class AboutActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val binding = ActivityAboutBinding.inflate(layoutInflater)
setContentView(binding.root)
setSupportActionBar(binding.aboutToolbar.toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)

binding.aboutCredits.text = getString(
R.string.about_author,
"@MrWasdennnoch (XDA), @paphonb (XDA), @TacoTheDank (GitHub)"
)

try {
val pInfo = packageManager.getPackageInfo(packageName, 0)
binding.aboutVersion.text = String.format(
getString(R.string.about_version),
pInfo.versionName,
PackageInfoCompat.getLongVersionCode(pInfo)
)
} catch (e: PackageManager.NameNotFoundException) {
// No.
}

binding.aboutUpdates.setOnClickListener {
val i = Intent(
Intent.ACTION_VIEW,
"https://github.com/TacoTheDank/Scoop/releases".toUri()
)
startActivity(i)
}
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
finish()
return true
}
return super.onOptionsItemSelected(item)
}
}
45 changes: 0 additions & 45 deletions app/src/main/java/tk/wasdennnoch/scoop/ui/SettingsActivity.java

This file was deleted.

39 changes: 39 additions & 0 deletions app/src/main/java/tk/wasdennnoch/scoop/ui/SettingsActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package tk.wasdennnoch.scoop.ui

import android.os.Bundle
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.commit
import androidx.fragment.app.replace
import androidx.preference.PreferenceFragmentCompat
import tk.wasdennnoch.scoop.R
import tk.wasdennnoch.scoop.databinding.ActivitySettingsBinding

class SettingsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val binding = ActivitySettingsBinding.inflate(layoutInflater)
setContentView(binding.root)
setSupportActionBar(binding.settingsToolbar.toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)

supportFragmentManager.commit {
replace<SettingsFragment>(R.id.settings_container)
}
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
finish()
return true
}
return super.onOptionsItemSelected(item)
}

class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.preferences)
}
}
}

0 comments on commit 751b95b

Please sign in to comment.