Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
[Android TV] Fixed a bug where pressing the back button would exit the
app instead of going back to the previous page
  • Loading branch information
Carlos Pérez committed Jul 5, 2022
1 parent fe404ee commit a26477a
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions android/app/src/main/kotlin/tech/logica10/soniclair/TvActivity.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package tech.logica10.soniclair

import android.app.Activity
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.IBinder
import android.util.Log
import android.view.View
import android.widget.Button
import android.widget.ImageView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -50,6 +49,16 @@ class TvActivity : AppCompatActivity() {
}
}

override fun onBackPressed() {
val count = supportFragmentManager.backStackEntryCount
if (count == 0) {
super.onBackPressed()
//additional code
} else {
supportFragmentManager.popBackStack()
}
}

inner class TvActivityObserver : IBroadcastObserver {
override fun update(action: String?, value: String?) {
if (action == "WS") {
Expand Down Expand Up @@ -95,6 +104,8 @@ class TvActivity : AppCompatActivity() {
supportFragmentManager
.beginTransaction()
.replace(R.id.fg_container, _playingFragment)
.addToBackStack(null)

.commit()
}

Expand All @@ -112,6 +123,8 @@ class TvActivity : AppCompatActivity() {
supportFragmentManager
.beginTransaction()
.replace(R.id.fg_container, _playingFragment)
.addToBackStack(null)

.commit()
}

Expand All @@ -130,6 +143,8 @@ class TvActivity : AppCompatActivity() {
supportFragmentManager
.beginTransaction()
.replace(R.id.fg_container, _playingFragment)
.addToBackStack(null)

.commit()
}

Expand Down Expand Up @@ -164,6 +179,7 @@ class TvActivity : AppCompatActivity() {
supportFragmentManager
.beginTransaction()
.replace(R.id.fg_container, _homeFragment)
.addToBackStack(null)
.commit()
// Bind to LocalService
val intent = Intent(App.context, MusicService::class.java)
Expand All @@ -179,41 +195,53 @@ class TvActivity : AppCompatActivity() {
supportFragmentManager
.beginTransaction()
.replace(R.id.fg_container, _homeFragment)
.addToBackStack(null)

.commit()
}
val playingButton: Button = findViewById(R.id.btn_playing)
playingButton.setOnClickListener {
supportFragmentManager
.beginTransaction()
.replace(R.id.fg_container, _playingFragment)
.addToBackStack(null)

.commit()
}
val jukeboxButton: Button = findViewById(R.id.btn_jukebox)
jukeboxButton.setOnClickListener {
supportFragmentManager
.beginTransaction()
.replace(R.id.fg_container, _jukeboxFragment)
.addToBackStack(null)

.commit()
}
val searchButton: Button = findViewById(R.id.btn_search)
searchButton.setOnClickListener {
supportFragmentManager
.beginTransaction()
.replace(R.id.fg_container, _searchFragment)
.addToBackStack(null)

.commit()
}
val playlistsButton: Button = findViewById(R.id.btn_playlists)
playlistsButton.setOnClickListener {
supportFragmentManager
.beginTransaction()
.replace(R.id.fg_container, _playlistFragment)
.addToBackStack(null)

.commit()
}
val accountButton: Button = findViewById(R.id.btn_account)
accountButton.setOnClickListener {
supportFragmentManager
.beginTransaction()
.replace(R.id.fg_container, _accountFragment)
.addToBackStack(null)

.commit()
}
}
Expand Down

1 comment on commit a26477a

@vercel
Copy link

@vercel vercel bot commented on a26477a Jul 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

soniclair – ./

soniclair.vercel.app
soniclair-thelinkin3000.vercel.app
soniclair-git-main-thelinkin3000.vercel.app

Please sign in to comment.