Skip to content

Commit

Permalink
17ok
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Jan 14, 2024
1 parent 2528cf3 commit 1aade3a
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 79 deletions.
Binary file modified app/src/main/cpp/arm64-v8a/libnative.so
Binary file not shown.
Binary file modified app/src/main/cpp/armeabi-v7a/libnative.so
Binary file not shown.
1 change: 1 addition & 0 deletions app/src/main/java/com/lizongying/mytv/CardAdapter.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lizongying.mytv

import android.graphics.Color
import android.util.Log
import android.view.ContextThemeWrapper
import android.view.View
import android.view.ViewGroup
Expand Down
180 changes: 104 additions & 76 deletions app/src/main/java/com/lizongying/mytv/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class MainActivity : FragmentActivity() {
.add(R.id.main_browse_fragment, infoFragment)
.add(R.id.main_browse_fragment, mainFragment)
.hide(infoFragment)
.hide(mainFragment)
.commit()
mainFragment.view?.requestFocus()
}
Expand Down Expand Up @@ -171,105 +172,132 @@ class MainActivity : FragmentActivity() {
}
}

override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
when (keyCode) {
KeyEvent.KEYCODE_BACK -> {
if (!mainFragmentIsHidden()) {
hideMainFragment()
return true
}
private fun showHelp() {
val versionName = getPackageInfo().versionName

val textView = TextView(this)
textView.text =
"当前版本: $versionName\n获取最新: https://github.com/lizongying/my-tv/releases/"
textView.setBackgroundColor(0xFF263238.toInt())
textView.setPadding(20, 50, 20, 20)

val imageView = ImageView(this)
val drawable = ContextCompat.getDrawable(this, R.drawable.appreciate)
imageView.setImageDrawable(drawable)
imageView.setBackgroundColor(Color.WHITE)

val linearLayout = LinearLayout(this)
linearLayout.orientation = LinearLayout.VERTICAL
linearLayout.addView(textView)
linearLayout.addView(imageView)

val layoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
)
imageView.layoutParams = layoutParams
textView.layoutParams = layoutParams

val builder: AlertDialog.Builder = AlertDialog.Builder(this)
builder
.setView(linearLayout)

val dialog: AlertDialog = builder.create()
dialog.show()
}

if (doubleBackToExitPressedOnce) {
super.onBackPressed()
return true
}
private fun channelUp() {
if (mainFragment.isHidden) {
prev()
} else {
// if (mainFragment.selectedPosition == 0) {
// mainFragment.setSelectedPosition(
// mainFragment.tvListViewModel.maxNum.size - 1,
// false
// )
// }
}
}

this.doubleBackToExitPressedOnce = true
Toast.makeText(this, "再按一次退出", Toast.LENGTH_SHORT).show()
private fun channelDown() {
if (mainFragment.isHidden) {
next()
} else {
// if (mainFragment.selectedPosition == mainFragment.tvListViewModel.maxNum.size - 1) {
//// mainFragment.setSelectedPosition(0, false)
// hideMainFragment()
// return false
// }
}
}

private fun back() {
if (!mainFragmentIsHidden()) {
hideMainFragment()
return
}

if (doubleBackToExitPressedOnce) {
super.onBackPressed()
return
}

doubleBackToExitPressedOnce = true
Toast.makeText(this, "再按一次退出", Toast.LENGTH_SHORT).show()

Handler(Looper.getMainLooper()).postDelayed({
doubleBackToExitPressedOnce = false
}, 2000)
}

Handler(Looper.getMainLooper()).postDelayed({
doubleBackToExitPressedOnce = false
}, 2000)
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
// Toast.makeText(this, "keyCode ${keyCodeToString(keyCode)}", Toast.LENGTH_SHORT).show()
when (keyCode) {
KeyEvent.KEYCODE_ESCAPE -> {
back()
return true
}
KeyEvent.KEYCODE_BACK -> {
back()
return true
}

KeyEvent.KEYCODE_UNKNOWN -> {
showHelp()
return true
}
KeyEvent.KEYCODE_HELP -> {
showHelp()
return true
}
KeyEvent.KEYCODE_SETTINGS -> {
Toast.makeText(this, "KEYCODE_SETTINGS", Toast.LENGTH_SHORT).show()
showHelp()
return true
}
KeyEvent.KEYCODE_MENU -> {
Toast.makeText(this, "KEYCODE_MENU", Toast.LENGTH_SHORT).show()
val versionName = getPackageInfo().versionName

val textView = TextView(this)
textView.text =
"当前版本: $versionName\n获取最新: https://github.com/lizongying/my-tv/releases/"
textView.setBackgroundColor(0xFF263238.toInt())
textView.setPadding(20, 50, 20, 20)


val imageView = ImageView(this)
val drawable = ContextCompat.getDrawable(this, R.drawable.appreciate)
imageView.setImageDrawable(drawable)
imageView.setBackgroundColor(Color.WHITE)

val linearLayout = LinearLayout(this)
linearLayout.orientation = LinearLayout.VERTICAL
linearLayout.addView(textView)
linearLayout.addView(imageView)

val layoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT,
)
textView.layoutParams = layoutParams
val layoutParams2 = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
)
imageView.layoutParams = layoutParams2

val builder: AlertDialog.Builder = AlertDialog.Builder(this)
builder
.setView(linearLayout)

val dialog: AlertDialog = builder.create()
dialog.show()
showHelp()
return true
}

KeyEvent.KEYCODE_ENTER -> {
Toast.makeText(this, "KEYCODE_ENTER", Toast.LENGTH_SHORT).show()
switchMainFragment()
}

KeyEvent.KEYCODE_DPAD_CENTER -> {
Toast.makeText(this, "KEYCODE_DPAD_CENTER", Toast.LENGTH_SHORT).show()
switchMainFragment()
}

KeyEvent.KEYCODE_DPAD_UP -> {
if (mainFragment.isHidden) {
prev()
} else {
// if (mainFragment.selectedPosition == 0) {
// mainFragment.setSelectedPosition(
// mainFragment.tvListViewModel.maxNum.size - 1,
// false
// )
// }
}
channelUp()
}
KeyEvent.KEYCODE_CHANNEL_UP -> {
channelUp()
}

KeyEvent.KEYCODE_DPAD_DOWN -> {
if (mainFragment.isHidden) {
next()
} else {
// if (mainFragment.selectedPosition == mainFragment.tvListViewModel.maxNum.size - 1) {
//// mainFragment.setSelectedPosition(0, false)
// hideMainFragment()
// return false
// }
}
channelDown()
}
KeyEvent.KEYCODE_CHANNEL_DOWN -> {
channelDown()
}

KeyEvent.KEYCODE_DPAD_LEFT -> {
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/lizongying/mytv/MainFragment2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ class MainFragment2 : Fragment(), CardAdapter.ItemListener {
}

override fun onItemClicked(tvViewModel: TVViewModel) {
if (this.isHidden) {
(activity as? MainActivity)?.switchMainFragment()
return
}

if (itemPosition != tvViewModel.id.value!!) {
itemPosition = tvViewModel.id.value!!
tvListViewModel.setItemPosition(itemPosition)
Expand Down Expand Up @@ -211,7 +216,6 @@ class MainFragment2 : Fragment(), CardAdapter.ItemListener {
if (ready == 3) {
// request.fetchPage()
tvListViewModel.getTVViewModel(itemPosition)?.changed()
(activity as? MainActivity)?.switchMainFragment()
}
}

Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/com/lizongying/mytv/Request.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ class Request {
val title = tvModel.title.value

tvModel.seq = 0
Log.i(TAG, "test1")
val data = ysp?.switch(tvModel)
Log.i(TAG, "test2")
val request = data?.let { LiveInfoRequest(it) }
call = request?.let { yspApiService.getLiveInfo("guid=${ysp?.getGuid()}; $cookie", it) }

Expand Down

0 comments on commit 1aade3a

Please sign in to comment.