Skip to content

Commit

Permalink
show num whthout logo
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Apr 17, 2024
1 parent e846340 commit 8407c79
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 39 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
## 更新日志
### v1.1.1
* 优化频道号选台
* 如果没有图标,显示频道号
### v1.1.0
* 优化频道数字显示
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/lizongying/mytv0/ChannelFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class ChannelFragment : Fragment() {
}

fun show(channel: String) {
if (binding.channelContent.text.length > 1) {
return
}
this.channel = "${binding.channelContent.text}$channel".toInt()
handler.removeCallbacks(hideRunnable)
handler.removeCallbacks(playRunnable)
Expand All @@ -43,6 +46,7 @@ class ChannelFragment : Fragment() {
view?.visibility = View.VISIBLE
handler.postDelayed(playRunnable, delay)
} else {
binding.channelContent.text = "${binding.channelContent.text}$channel"
handler.postDelayed(playRunnable, 0)
}
}
Expand Down
41 changes: 35 additions & 6 deletions app/src/main/java/com/lizongying/mytv0/InfoFragment.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.lizongying.mytv0

import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.drawable.BitmapDrawable
import android.os.Bundle
import android.os.Handler
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.SimpleTarget
import com.bumptech.glide.request.transition.Transition
import com.lizongying.mytv0.databinding.InfoBinding
import com.lizongying.mytv0.models.TVModel

Expand All @@ -35,9 +37,36 @@ class InfoFragment : Fragment() {
binding.textView.text = tvViewModel.tv.title

when (tvViewModel.tv.title) {
else -> Glide.with(this)
.load(tvViewModel.tv.logo)
.into(binding.infoLogo)
else -> {
if (tvViewModel.tv.logo.isNullOrBlank()) {
val width = Utils.dpToPx(100)
val height = Utils.dpToPx(60)
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)

val paint = Paint().apply {
color = ContextCompat.getColor(context!!, R.color.blur)
textSize = 100f
textAlign = Paint.Align.CENTER
}
val text = "${tvViewModel.tv.id + 1}"
val x = width / 2f
val y = height / 2f - (paint.descent() + paint.ascent()) / 2
canvas.drawText(text, x, y, paint)

Glide.with(this)
.load(BitmapDrawable(context?.resources, bitmap))
// .centerInside()
.into(binding.infoLogo)
} else {
Glide.with(this)
.load(tvViewModel.tv.logo)
// .centerInside()
.into(binding.infoLogo)
}


}
}

// val program = tvViewModel.getProgramOne()
Expand Down
30 changes: 27 additions & 3 deletions app/src/main/java/com/lizongying/mytv0/ListAdapter.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.lizongying.mytv0

import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.drawable.BitmapDrawable
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.View
Expand Down Expand Up @@ -110,7 +115,7 @@ class ListAdapter(

viewHolder.bindText(tvModel.tv.title)

viewHolder.bindImage(tvModel.tv.logo)
viewHolder.bindImage(tvModel.tv.logo, tvModel.tv.id)
}

override fun getItemCount() = tvListModel.size()
Expand All @@ -121,13 +126,32 @@ class ListAdapter(
binding.textView.text = text
}

fun bindImage(url: String?) {
fun bindImage(url: String?, id: Int) {
if (url.isNullOrBlank()) {
binding.imageView.setImageDrawable(null)
val width = Utils.dpToPx(40)
val height = Utils.dpToPx(40)
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)

val paint = Paint().apply {
color = Color.WHITE
textSize = 32f
textAlign = Paint.Align.CENTER
}
val text = "${id + 1}"
val x = width / 2f
val y = height / 2f - (paint.descent() + paint.ascent()) / 2
canvas.drawText(text, x, y, paint)
Glide.with(context)
.load(BitmapDrawable(context.resources, bitmap))
.centerInside()
.into(binding.imageView)
// binding.imageView.setImageDrawable(null)
} else {
Glide.with(context)
.load(url)
.centerInside()
// .error(BitmapDrawable(context.resources, bitmap))
.into(binding.imageView)
}
}
Expand Down
28 changes: 5 additions & 23 deletions app/src/main/java/com/lizongying/mytv0/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ class MainActivity : FragmentActivity() {
TVList.setPosition(0)
}

if (SP.time) {
timeFragment.show()
}
showTime()
}

fun ready() {
Expand Down Expand Up @@ -273,23 +271,6 @@ class MainActivity : FragmentActivity() {
}
}

private fun getPackageInfo(): PackageInfo {
val flag = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
PackageManager.GET_SIGNATURES
} else {
PackageManager.GET_SIGNING_CERTIFICATES
}

return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
packageManager.getPackageInfo(packageName, flag)
} else {
packageManager.getPackageInfo(
packageName,
PackageManager.PackageInfoFlags.of(PackageManager.GET_SIGNING_CERTIFICATES.toLong())
)
}
}

private fun showChannel(channel: String) {
if (!menuFragment.isHidden) {
return
Expand All @@ -299,9 +280,10 @@ class MainActivity : FragmentActivity() {
return
}

if (SP.channelNum) {
channelFragment.show(channel)
}
// if (SP.channelNum) {
// channelFragment.show(channel)
// }
channelFragment.show(channel)
}


Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/lizongying/mytv0/TimeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class TimeFragment : Fragment() {
savedInstanceState: Bundle?
): View {
_binding = TimeBinding.inflate(inflater, container, false)
_binding!!.root.visibility = View.GONE
return binding.root
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginTop="5dp"
android:layout_marginStart="10dp"
android:layout_marginStart="0dp"
android:layout_marginBottom="2dp"
android:gravity="start"
android:textColor="#FFEEEEEE"
Expand All @@ -33,7 +33,7 @@
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginTop="0dp"
android:layout_marginStart="10dp"
android:layout_marginStart="0dp"
android:layout_marginBottom="5dp"
android:gravity="start"
android:text=""
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</androidx.recyclerview.widget.RecyclerView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
android:layout_width="300dp"
android:layout_width="250dp"
android:layout_height="wrap_content"
>
</androidx.recyclerview.widget.RecyclerView>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<string name="dismiss_error">Dismiss</string>

<string name="title_channel_reversal">换台反转</string>
<string name="title_channel_num">数字选台</string>
<string name="title_channel_num">换台时显示频道号</string>
<string name="check_version">更新</string>
<string name="title_boot_startup">开机自启</string>
<string name="appreciate">赞赏</string>
Expand Down
4 changes: 2 additions & 2 deletions version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version_code": 16779008,
"version_name": "v1.0.7"
"version_code": 16843008,
"version_name": "v1.1.1"
}

0 comments on commit 8407c79

Please sign in to comment.