Skip to content

Commit

Permalink
app: use iptv-org for default playlist
Browse files Browse the repository at this point in the history
we no longer provide playlists
  • Loading branch information
hariimurti committed Sep 17, 2021
1 parent b2a7d97 commit 21a36c1
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 43 deletions.
52 changes: 37 additions & 15 deletions app/src/main/java/net/harimurti/tv/adapter/SourcesAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@ import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Context.CLIPBOARD_SERVICE
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.*
import android.widget.Toast
import androidx.appcompat.widget.PopupMenu
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import net.harimurti.tv.BR
import net.harimurti.tv.R
import net.harimurti.tv.databinding.ItemSourceBinding
import net.harimurti.tv.dialog.SettingDialog
import net.harimurti.tv.extra.Preferences
import net.harimurti.tv.model.Source

interface SourceClickListener {
fun onClicked(position: Int)
fun onCheckChanged(view: View, checked: Boolean, position: Int)
fun onlongClicked(view: View, source: Source?): Boolean
fun onlongClicked(view: View, source: Source?, position: Int): Boolean
}

class SourcesAdapter(private val sources: ArrayList<Source>?):
RecyclerView.Adapter<SourcesAdapter.ViewHolder>(), SourceClickListener {
lateinit var context: Context
val preferences = Preferences()

class ViewHolder(var itemBinding: ItemSourceBinding) :
RecyclerView.ViewHolder(itemBinding.root) {
Expand All @@ -46,8 +47,9 @@ class SourcesAdapter(private val sources: ArrayList<Source>?):
viewHolder.bind(source)
viewHolder.itemBinding.position = position
viewHolder.itemBinding.clickListener = this
if (source?.path?.equals(context.getString(R.string.json_playlist)) == true) {
viewHolder.itemBinding.swSource.setText(R.string.default_playlist)
if (position == 0) {
val name = String.format(context.getString(R.string.default_playlist), preferences.countryId.uppercase())
viewHolder.itemBinding.swSource.text = name
viewHolder.itemBinding.btnRemove.visibility = View.GONE
}
}
Expand All @@ -65,22 +67,42 @@ class SourcesAdapter(private val sources: ArrayList<Source>?):
sources?.get(0)?.active = true
notifyItemChanged(0)
}
SettingDialog.isChanged = true
SettingDialog.isSourcesChanged = true
}

override fun onlongClicked(view: View, source: Source?): Boolean {
val clipboard = context.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
val clipData = ClipData.newPlainText("url", source?.path)

clipboard.setPrimaryClip(clipData)
Toast.makeText(context, R.string.link_copied_to_clipboard, Toast.LENGTH_SHORT).show()
override fun onlongClicked(view: View, source: Source?, position: Int): Boolean {
if (position == 0) {
PopupMenu(context, view, Gravity.NO_GRAVITY, R.attr.actionOverflowMenuStyle, 0).apply {
inflate(R.menu.country_list)
setOnMenuItemClickListener { m: MenuItem ->
val mode = when(m.itemId) {
R.id.japan -> "jp"
R.id.malaysia -> "my"
R.id.singapore -> "sg"
R.id.southkorea -> "kr"
else -> "id"
}
preferences.countryId = mode
SettingDialog.isSourcesChanged = true
notifyItemChanged(0)
true
}
show()
}
}
else {
val clipData = ClipData.newPlainText("url", source?.path)
val clipboard = context.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
clipboard.setPrimaryClip(clipData)
Toast.makeText(context, R.string.link_copied_to_clipboard, Toast.LENGTH_SHORT).show()
}

return true
}

override fun onCheckChanged(view: View, checked: Boolean, position: Int) {
sources?.get(position)?.active = checked
SettingDialog.isChanged = true
SettingDialog.isSourcesChanged = true
}

override fun getItemCount(): Int {
Expand All @@ -95,6 +117,6 @@ class SourcesAdapter(private val sources: ArrayList<Source>?):
val position = itemCount
sources?.add(source)
notifyItemInserted(position)
SettingDialog.isChanged = true
SettingDialog.isSourcesChanged = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@ class SettingAppFragment : Fragment() {
isChecked = sortFavorite
setOnClickListener {
sortFavorite = isChecked
SettingDialog.isChanged = true
SettingDialog.isSourcesChanged = true
}
}

binding.sortCategory.apply {
isChecked = sortCategory
setOnClickListener {
sortCategory = isChecked
SettingDialog.isChanged = true
SettingDialog.isSourcesChanged = true
}
}

binding.sortChannel.apply {
isChecked = sortChannel
setOnClickListener {
sortChannel = isChecked
SettingDialog.isChanged = true
SettingDialog.isSourcesChanged = true
}
}

Expand Down
31 changes: 20 additions & 11 deletions app/src/main/java/net/harimurti/tv/dialog/SettingDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ import net.harimurti.tv.databinding.SettingDialogBinding
import net.harimurti.tv.extra.Preferences

class SettingDialog : DialogFragment() {
val preferences = Preferences()
private val tabFragment = arrayOf(SettingSourcesFragment(), SettingAppFragment(), SettingAboutFragment())
private val tabTitle = arrayOf(R.string.tab_sources, R.string.tab_app, R.string.tab_about)
private var revertCountryId = ""
private var isCancelled = true

companion object {
var isChanged = false
var isSourcesChanged = false
}

@Suppress("DEPRECATION")
Expand Down Expand Up @@ -50,10 +53,9 @@ class SettingDialog : DialogFragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
val binding = SettingDialogBinding.inflate(inflater, container, false)
val preferences = Preferences()

// init
isChanged = false
isSourcesChanged = false
SettingAppFragment.launchAtBoot = preferences.launchAtBoot
SettingAppFragment.playLastWatched = preferences.playLastWatched
SettingAppFragment.sortFavorite = preferences.sortFavorite
Expand All @@ -62,6 +64,7 @@ class SettingDialog : DialogFragment() {
SettingAppFragment.optimizePrebuffer = preferences.optimizePrebuffer
SettingAppFragment.reverseNavigation = preferences.reverseNavigation
SettingSourcesFragment.sources = preferences.sources
revertCountryId = preferences.countryId

// view pager
binding.settingViewPager.adapter = FragmentAdapter(childFragmentManager)
Expand All @@ -74,14 +77,7 @@ class SettingDialog : DialogFragment() {
// button ok
binding.settingOkButton.apply {
setOnClickListener {
// playlist sources
val sources = SettingSourcesFragment.sources
if (sources?.filter { s -> s.active }?.size == 0) {
sources[0].active = true
Toast.makeText(context, R.string.warning_none_source_active, Toast.LENGTH_SHORT).show()
}
preferences.sources = sources
if (isChanged) sendUpdatePlaylist(rootView.context)
isCancelled = false
// setting app
preferences.launchAtBoot = SettingAppFragment.launchAtBoot
preferences.playLastWatched = SettingAppFragment.playLastWatched
Expand All @@ -90,13 +86,26 @@ class SettingDialog : DialogFragment() {
preferences.sortChannel = SettingAppFragment.sortChannel
preferences.optimizePrebuffer = SettingAppFragment.optimizePrebuffer
preferences.reverseNavigation = SettingAppFragment.reverseNavigation
// playlist sources
val sources = SettingSourcesFragment.sources
if (sources?.filter { s -> s.active }?.size == 0) {
sources[0].active = true
Toast.makeText(context, R.string.warning_none_source_active, Toast.LENGTH_SHORT).show()
}
preferences.sources = sources
dismiss()
}
}

return binding.root
}

override fun onDestroyView() {
super.onDestroyView()
if (isCancelled) preferences.countryId = revertCountryId
else if (isSourcesChanged) sendUpdatePlaylist(requireContext())
}

private fun sendUpdatePlaylist(context: Context) {
LocalBroadcastManager.getInstance(context).sendBroadcast(
Intent(MainActivity.MAIN_CALLBACK)
Expand Down
27 changes: 18 additions & 9 deletions app/src/main/java/net/harimurti/tv/extra/Preferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Preferences {
private const val CONTRIBUTORS = "CONTRIBUTORS"
private const val RESIZE_MODE = "RESIZE_MODE"
private const val SOURCES_PLAYLIST = "SOURCES_PLAYLIST"
private const val COUNTRY_ID = "COUNTRY_ID"
}

var isFirstTime: Boolean
Expand Down Expand Up @@ -115,23 +116,31 @@ class Preferences {
editor.apply()
}

var countryId: String
get() = preferences.getString(COUNTRY_ID, "id").toString()
set(value) {
editor = preferences.edit()
editor.putString(COUNTRY_ID, value)
editor.apply()
}

var sources: ArrayList<Source>?
get() {
val result = ArrayList<Source>()
val default = Source().apply {
path = context.getString(R.string.json_playlist)
path = String.format(context.getString(R.string.iptv_playlist), countryId)
active = true
}
try {
val json = preferences.getString(SOURCES_PLAYLIST, "").toString()
if (json.isNotBlank()) {
val list = Gson().fromJson(json, Array<Source>::class.java)
if (list.firstOrNull()?.path != default.path) result.add(default)
list.forEach {
if (it.path.isLinkUrl()) result.add(it)
else if (it.path.isPathExist()) result.add(it)
}
} else throw Exception("no playlist sources in preference")
if (json.isBlank()) throw Exception("no playlist sources in preference")
val list = Gson().fromJson(json, Array<Source>::class.java)
if (list == null || list.isEmpty()) throw Exception("cannot parse sources?")
list.first().path = default.path
list.forEach {
if (it.path.isLinkUrl()) result.add(it)
else if (it.path.isPathExist()) result.add(it)
}
} catch (e: Exception) {
e.printStackTrace()
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_source.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
android:text="@{modelSource.path}"
android:checked="@{modelSource.active}"
android:onCheckedChanged="@{(view, checked) -> clickListener.onCheckChanged(view, checked, position)}"
android:onLongClick="@{(view) -> clickListener.onlongClicked(view, modelSource)}"/>
android:onLongClick="@{(view) -> clickListener.onlongClicked(view, modelSource, position)}"/>

<ImageButton
android:id="@+id/btn_remove"
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/menu/country_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/indonesia"
android:title="@string/indonesia" />
<item
android:id="@+id/japan"
android:title="@string/japan" />
<item
android:id="@+id/malaysia"
android:title="@string/malaysia" />
<item
android:id="@+id/singapore"
android:title="@string/singapore" />
<item
android:id="@+id/southkorea"
android:title="@string/south_korea" />
</menu>
2 changes: 1 addition & 1 deletion app/src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<string name="app_tagline_one">Gratis - OpenSource - Tanpa Iklan</string>
<string name="app_tagline_two">Ringan - Simpel - Minimalis</string>
<string name="thanks_to">Terimakasih Kepada :</string>
<string name="thanks_for_support">dan orang yg mendukung proyek ini 😘</string>
<string name="thanks_for_support">iptv-org utk playlist dan orang² yg mendukung proyek ini 😘</string>
<string name="btn_retry">Coba Ulang</string>
<string name="btn_retry_count">Coba Ulang (%d)</string>
<string name="btn_close">Keluar</string>
Expand Down
11 changes: 8 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- json link -->
<string name="website" translatable="false">https://github.com/hariimurti/NontonTV</string>
<string name="telegram_group" translatable="false">https://t.me/paijemdev</string>
<string name="json_playlist" translatable="false">https://github.com/hariimurti/NontonTV/raw/playlist/NontonTV.json</string>
<string name="iptv_playlist" translatable="false">https://iptv-org.github.io/iptv/countries/%s.m3u</string>
<string name="json_release" translatable="false">https://github.com/hariimurti/NontonTV/raw/master/json/release.json</string>
<string name="apk_release" translatable="false">https://github.com/hariimurti/NontonTV/releases/download/%s/net.harimurti.tv_%s_b%d.apk</string>
<string name="gh_contributors" translatable="false">https://api.github.com/repos/hariimurti/NontonTV/contributors</string>
Expand All @@ -15,7 +15,7 @@
<string name="app_tagline_one">Free - OpenSource - No Ads,</string>
<string name="app_tagline_two">Light - Simple - Minimalist</string>
<string name="thanks_to">Thanks To :</string>
<string name="thanks_for_support">and people who support this project 😘</string>
<string name="thanks_for_support">iptv-org for playlist and people who support this project 😘</string>
<string name="btn_retry">Retry</string>
<string name="btn_retry_count">Retry (%d)</string>
<string name="btn_close">Close</string>
Expand Down Expand Up @@ -84,7 +84,7 @@
<string name="input_url">Link URL</string>
<string name="show_hidden" translatable="false">Hidden</string>
<string name="title_select_file_json">Select File Json</string>
<string name="default_playlist" translatable="false">NontonTV (Default)</string>
<string name="default_playlist" translatable="false">IPTV-ORG ( %s )</string>
<string name="null_playlist">No playlists that can be displayed. Check your settings!</string>
<string name="checking_url">checking url…</string>
<string name="link_error">Link Error!</string>
Expand All @@ -93,4 +93,9 @@
<string name="more_information">More Information :</string>
<string name="button_website" translatable="false">Website</string>
<string name="button_telegram" translatable="false">Telegram</string>
<string name="indonesia" translatable="false">Indonesia</string>
<string name="japan" translatable="false">Japan</string>
<string name="malaysia" translatable="false">Malaysia</string>
<string name="singapore" translatable="false">Singapore</string>
<string name="south_korea" translatable="false">South Korea</string>
</resources>

0 comments on commit 21a36c1

Please sign in to comment.