diff --git a/app/src/main/cpp/arm64-v8a/libnative.so b/app/src/main/cpp/arm64-v8a/libnative.so index 60bd408f..2a26e7a9 100755 Binary files a/app/src/main/cpp/arm64-v8a/libnative.so and b/app/src/main/cpp/arm64-v8a/libnative.so differ diff --git a/app/src/main/cpp/armeabi-v7a/libnative.so b/app/src/main/cpp/armeabi-v7a/libnative.so index bfd41e65..ab7cfec0 100755 Binary files a/app/src/main/cpp/armeabi-v7a/libnative.so and b/app/src/main/cpp/armeabi-v7a/libnative.so differ diff --git a/app/src/main/java/com/lizongying/mytv/CardAdapter.kt b/app/src/main/java/com/lizongying/mytv/CardAdapter.kt index 9dbafdbf..a3d11588 100644 --- a/app/src/main/java/com/lizongying/mytv/CardAdapter.kt +++ b/app/src/main/java/com/lizongying/mytv/CardAdapter.kt @@ -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 diff --git a/app/src/main/java/com/lizongying/mytv/MainActivity.kt b/app/src/main/java/com/lizongying/mytv/MainActivity.kt index 07253880..88e5887b 100644 --- a/app/src/main/java/com/lizongying/mytv/MainActivity.kt +++ b/app/src/main/java/com/lizongying/mytv/MainActivity.kt @@ -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() } @@ -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 -> { diff --git a/app/src/main/java/com/lizongying/mytv/MainFragment2.kt b/app/src/main/java/com/lizongying/mytv/MainFragment2.kt index fefa6540..2f7c372f 100644 --- a/app/src/main/java/com/lizongying/mytv/MainFragment2.kt +++ b/app/src/main/java/com/lizongying/mytv/MainFragment2.kt @@ -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) @@ -211,7 +216,6 @@ class MainFragment2 : Fragment(), CardAdapter.ItemListener { if (ready == 3) { // request.fetchPage() tvListViewModel.getTVViewModel(itemPosition)?.changed() - (activity as? MainActivity)?.switchMainFragment() } } diff --git a/app/src/main/java/com/lizongying/mytv/Request.kt b/app/src/main/java/com/lizongying/mytv/Request.kt index 2dfc51e7..8d18e0f9 100644 --- a/app/src/main/java/com/lizongying/mytv/Request.kt +++ b/app/src/main/java/com/lizongying/mytv/Request.kt @@ -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) }