Skip to content

Commit

Permalink
support switch source
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Dec 5, 2024
1 parent 52c7b8a commit 119fdaf
Show file tree
Hide file tree
Showing 44 changed files with 1,061 additions and 430 deletions.
66 changes: 1 addition & 65 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
body_path: history.md

- name: Run build with Gradle wrapper
run: ./gradlew clean && ./gradlew assembleRelease -Pnet=common
run: ./gradlew clean && ./gradlew assembleRelease

- name: Sign app APK
id: sign_app
Expand Down Expand Up @@ -73,70 +73,6 @@ jobs:
asset_name: ${{ env.asset_name }}
asset_content_type: application/vnd.android.package-archive

- name: Run build with Gradle wrapper mobile
run: ./gradlew clean && ./gradlew assembleRelease -Pnet=mobile

- name: Sign app APK mobile
id: sign_app_mobile
uses: r0adkll/sign-android-release@v1
with:
releaseDirectory: app/build/outputs/apk/release
alias: ${{ secrets.ALIAS }}
signingKeyBase64: ${{ secrets.KEYSTORE }}
keyStorePassword: ${{ secrets.KEYSTORE_PASSWORD }}
keyPassword: ${{ secrets.ALIAS_PASSWORD }}
env:
# override default build-tools version (29.0.3) -- optional
BUILD_TOOLS_VERSION: "34.0.0"

- name: Set Asset Name mobile
id: set_asset_name_mobile
run: |
VERSION_WITHOUT_V=$(echo '${{ github.ref_name }}' | sed 's/^v//')
echo "asset_name=my-tv-0.${VERSION_WITHOUT_V}.china-mobile.apk" >> $GITHUB_ENV
- name: Upload Release Asset mobile
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ steps.sign_app_mobile.outputs.signedReleaseFile }}
asset_name: ${{ env.asset_name }}
asset_content_type: application/vnd.android.package-archive

- name: Run build with Gradle wrapper ipv6
run: ./gradlew clean && ./gradlew assembleRelease -Pnet=ipv6

- name: Sign app APK ipv6
id: sign_app_ipv6
uses: r0adkll/sign-android-release@v1
with:
releaseDirectory: app/build/outputs/apk/release
alias: ${{ secrets.ALIAS }}
signingKeyBase64: ${{ secrets.KEYSTORE }}
keyStorePassword: ${{ secrets.KEYSTORE_PASSWORD }}
keyPassword: ${{ secrets.ALIAS_PASSWORD }}
env:
# override default build-tools version (29.0.3) -- optional
BUILD_TOOLS_VERSION: "34.0.0"

- name: Set Asset Name ipv6
id: set_asset_name_ipv6
run: |
VERSION_WITHOUT_V=$(echo '${{ github.ref_name }}' | sed 's/^v//')
echo "asset_name=my-tv-0.${VERSION_WITHOUT_V}.ipv6.apk" >> $GITHUB_ENV
- name: Upload Release Asset ipv6
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ steps.sign_app_ipv6.outputs.signedReleaseFile }}
asset_name: ${{ env.asset_name }}
asset_content_type: application/vnd.android.package-archive

# - name: Gitee Create Release
# run: |
# latest_commit=$(git rev-parse HEAD)
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ local.properties
files
.kotlin/
app/release/
.README.md
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 更新日誌

### v1.3.8.2

* 支持多源選擇

### v1.3.8.1

* 支持rtmp
Expand Down
1 change: 0 additions & 1 deletion app/assets/common.txt

This file was deleted.

1 change: 0 additions & 1 deletion app/assets/mobile.txt

This file was deleted.

69 changes: 0 additions & 69 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,75 +69,6 @@ fun getVersionName(): String {
}
}

task("modifySource") {
val net = project.findProperty("net") ?: ""
println("net: $net")

val channels = when (net) {
"ipv6" -> "assets/ipv6.txt"
"mobile" -> "assets/mobile.txt"
"" -> "assets/mobile.txt"
else -> "assets/common.txt"
}

println("channels: $channels")

inputs.file(channels)
outputs.file("src/main/res/raw/channels.txt")
doLast {
if (channels.isNotEmpty()) {
val sourceFile = file(channels)
val targetFile = file("src/main/res/raw/channels.txt")
targetFile.writeText(sourceFile.readText())
println(targetFile.readText())
}

val url = when (net) {
"ipv6" -> "DEFAULT_CONFIG_URL = \"https://live.fanmingming.com/tv/m3u/ipv6.m3u\""
"mobile" -> "DEFAULT_CONFIG_URL = \"https://live.fanmingming.com/tv/m3u/itv.m3u\""
"" -> "DEFAULT_CONFIG_URL = \"https://live.fanmingming.com/tv/m3u/itv.m3u\""
else -> ""
}

if (url.isNotEmpty()) {
val f = file("src/main/java/com/lizongying/mytv0/SP.kt")
f.writeText(f.readText().replace("DEFAULT_CONFIG_URL = \"\"", url))
}
}
}

tasks.whenTaskAdded {
if (name == "assembleRelease") {
dependsOn("modifySource")
doLast {
val net = project.findProperty("net") ?: ""
println("net: $net")

val url = when (net) {
"ipv6" -> "DEFAULT_CONFIG_URL = \"https://live.fanmingming.com/tv/m3u/ipv6.m3u\""
"mobile" -> "DEFAULT_CONFIG_URL = \"https://live.fanmingming.com/tv/m3u/itv.m3u\""
"" -> "DEFAULT_CONFIG_URL = \"https://live.fanmingming.com/tv/m3u/itv.m3u\""
else -> ""
}

if (url.isNotEmpty()) {
val f = file("src/main/java/com/lizongying/mytv0/SP.kt")
f.writeText(f.readText().replace(url, "DEFAULT_CONFIG_URL = \"\""))
}
}
}

if (listOf(
"packageReleaseResources",
"mergeReleaseResources",
"generateReleaseResources",
"mapReleaseSourceSetPaths",
).contains(name)
) {
dependsOn("modifySource")
}
}

dependencies {
// For AGP 7.4+
coreLibraryDesugaring(libs.desugar.jdk.libs)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/lizongying/mytv0/ListAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,14 @@ class ListAdapter(
binding.heart.setImageDrawable(
ContextCompat.getDrawable(
context,
R.drawable.ic_heart
R.drawable.baseline_favorite_24
)
)
} else {
binding.heart.setImageDrawable(
ContextCompat.getDrawable(
context,
R.drawable.ic_heart_empty
R.drawable.baseline_favorite_border_24
)
)
}
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/com/lizongying/mytv0/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,29 @@ class MainActivity : AppCompatActivity() {
}
}

Utils.isp.observe(this) {
Log.i(TAG, "isp $it")
// val id = R.raw.mobile
val id = when (it) {
ISP.CHINA_MOBILE -> R.raw.mobile
else -> 0
}

if (id == 0) {
return@observe
}

resources.openRawResource(id).bufferedReader()
.use { i ->
val channels = i.readText()
if (channels.isNotEmpty()) {
viewModel.tryStr2List(channels, null, "")
} else {
Log.w(TAG, "$it is empty")
}
}
}

server = SimpleServer(this, viewModel)

viewModel.updateConfig()
Expand Down
22 changes: 19 additions & 3 deletions app/src/main/java/com/lizongying/mytv0/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import com.google.gson.JsonSyntaxException
import com.lizongying.mytv0.R
import com.lizongying.mytv0.SP
import com.lizongying.mytv0.Utils.getDateFormat
import com.lizongying.mytv0.data.Source
import com.lizongying.mytv0.data.SourceType
import com.lizongying.mytv0.data.TV
import com.lizongying.mytv0.models.EPGXmlParser
import com.lizongying.mytv0.models.Sources
import com.lizongying.mytv0.models.TVGroupModel
import com.lizongying.mytv0.models.TVListModel
import com.lizongying.mytv0.models.TVModel
Expand All @@ -36,6 +38,8 @@ class MainViewModel : ViewModel() {
private var cacheConfig = ""
private var initialized = false

val sources = Sources()

private val _channelsOk = MutableLiveData<Boolean>()
val channelsOk: LiveData<Boolean>
get() = _channelsOk
Expand Down Expand Up @@ -86,7 +90,7 @@ class MainViewModel : ViewModel() {
groupModel.addTVListModel(TVListModel("全部頻道", 1))

appDirectory = context.filesDir
cacheFile = File(appDirectory, FILE_NAME)
cacheFile = File(appDirectory, CACHE_FILE_NAME)
if (!cacheFile!!.exists()) {
cacheFile!!.createNewFile()
}
Expand Down Expand Up @@ -206,7 +210,14 @@ class MainViewModel : ViewModel() {
if (str2List(str)) {
cacheFile!!.writeText(str)
cacheConfig = str
SP.config = url
if (url.isNotEmpty()) {
SP.config = url
sources.addSource(
Source(
uri = url
)
)
}
_channelsOk.value = true
R.string.channel_import_success.showToast()
} else {
Expand All @@ -222,16 +233,21 @@ class MainViewModel : ViewModel() {
private fun str2List(str: String): Boolean {
var string = str
if (initialized && string == cacheConfig) {
Log.w(TAG, "same config")
return false
}

val g = Gua()
if (g.verify(str)) {
string = g.decode(str)
}
if (string.isEmpty()) {
Log.w(TAG, "config is empty")
return false
}

if (initialized && string == cacheConfig) {
Log.w(TAG, "same config")
return false
}

Expand Down Expand Up @@ -402,6 +418,6 @@ class MainViewModel : ViewModel() {

companion object {
private const val TAG = "MainViewModel"
const val FILE_NAME = "channels.txt"
const val CACHE_FILE_NAME = "channels.txt"
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/lizongying/mytv0/MenuFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MenuFragment : Fragment(), GroupAdapter.ItemListener, ListAdapter.ItemList
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val context = requireActivity()
val application = requireActivity().applicationContext as MyTVApplication
val application = context.applicationContext as MyTVApplication
viewModel = ViewModelProvider(context)[MainViewModel::class.java]

Log.i(TAG, "group size ${viewModel.groupModel.size()}")
Expand Down
Loading

0 comments on commit 119fdaf

Please sign in to comment.