diff --git a/app/build.gradle b/app/build.gradle index b8551e64..6d6e786a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,8 +13,8 @@ android { applicationId "com.lagradost.cloudstream3" minSdkVersion 21 targetSdkVersion 30 - versionCode 10 - versionName "1.1.8" + versionCode 11 + versionName "1.2.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -52,7 +52,7 @@ dependencies { implementation 'androidx.core:core-ktx:1.6.0' implementation 'androidx.appcompat:appcompat:1.3.1' implementation 'com.google.android.material:material:1.4.0' - implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.constraintlayout:constraintlayout:2.1.0' implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5' implementation 'androidx.navigation:navigation-ui-ktx:2.3.5' implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1' diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt index 6fef5441..6848abeb 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerFragment.kt @@ -797,9 +797,11 @@ class PlayerFragment : Fragment() { //endregion private fun onSubStyleChanged(style : SaveCaptionStyle) { - subStyle = style - subView?.setStyle(fromSaveToStyle(style)) - subView?.translationY = -style.elevation.toPx.toFloat() + context?.let { ctx -> + subStyle = style + subView?.setStyle(ctx.fromSaveToStyle(style)) + subView?.translationY = -style.elevation.toPx.toFloat() + } } @SuppressLint("SetTextI18n") @@ -1129,14 +1131,14 @@ class PlayerFragment : Fragment() { val speedsNumbers = listOf(0.5f, 0.75f, 1f, 1.25f, 1.5f, 1.75f, 2f) val speedIndex = speedsNumbers.indexOf(playbackSpeed) - context?.showDialog(speedsText,speedIndex,"Player Speed", false) { index -> + context?.showDialog(speedsText,speedIndex,"Player Speed", false, { + activity?.hideSystemUI() + }) { index -> playbackSpeed = speedsNumbers[index] requireContext().setKey(PLAYBACK_SPEED_KEY, playbackSpeed) val param = PlaybackParameters(playbackSpeed) exoPlayer.playbackParameters = param player_speed_text.text = "Speed (${playbackSpeed}x)".replace(".0x", "x") - - activity?.hideSystemUI() } } @@ -1158,7 +1160,7 @@ class PlayerFragment : Fragment() { val subtitleList = sourceDialog.findViewById(R.id.sort_subtitles)!! val applyButton = sourceDialog.findViewById(R.id.apply_btt)!! val cancelButton = sourceDialog.findViewById(R.id.cancel_btt)!! - val subsSettings = sourceDialog.findViewById(R.id.subs_settings)!! + val subsSettings = sourceDialog.findViewById(R.id.subs_settings)!! subsSettings.setOnClickListener { SubtitlesFragment.push(activity) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt index eecaf043..f65fe939 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt @@ -1,8 +1,10 @@ package com.lagradost.cloudstream3.ui.settings import android.os.Bundle +import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import com.lagradost.cloudstream3.R +import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard class SettingsFragment : PreferenceFragmentCompat() { @@ -10,4 +12,13 @@ class SettingsFragment : PreferenceFragmentCompat() { hideKeyboard() setPreferencesFromResource(R.xml.settings, rootKey) } + + override fun onPreferenceTreeClick(preference: Preference?): Boolean { + if (preference != null) { + if (preference.key == "subtitle_settings_key") { + SubtitlesFragment.push(activity, false) + } + } + return super.onPreferenceTreeClick(preference) + } } \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/SubtitlesFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/SubtitlesFragment.kt index b0427f2e..6bf2a60c 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/SubtitlesFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/subtitles/SubtitlesFragment.kt @@ -13,6 +13,8 @@ import android.view.View import android.view.ViewGroup import android.widget.TextView import android.widget.Toast +import androidx.annotation.FontRes +import androidx.core.content.res.ResourcesCompat import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentActivity import com.google.android.exoplayer2.text.Cue @@ -38,7 +40,8 @@ data class SaveCaptionStyle( @CaptionStyleCompat.EdgeType var edgeType: Int, var edgeColor: Int, - var typeface: String?, + @FontRes + var typeface: Int?, /**in dp**/ var elevation: Int, ) @@ -47,14 +50,15 @@ class SubtitlesFragment : Fragment() { companion object { val applyStyleEvent = Event() - fun fromSaveToStyle(data: SaveCaptionStyle): CaptionStyleCompat { + fun Context.fromSaveToStyle(data: SaveCaptionStyle): CaptionStyleCompat { + val typeface = data.typeface return CaptionStyleCompat( data.foregroundColor, data.backgroundColor, data.windowColor, data.edgeType, data.edgeColor, - Typeface.SANS_SERIF + if (typeface == null) Typeface.SANS_SERIF else ResourcesCompat.getFont(this, typeface) ) } - fun push(activity: Activity?) { + fun push(activity: Activity?, hide: Boolean = true) { (activity as FragmentActivity?)?.supportFragmentManager?.beginTransaction() ?.setCustomAnimations( R.anim.enter_anim, @@ -64,7 +68,11 @@ class SubtitlesFragment : Fragment() { ) ?.add( R.id.homeRoot, - SubtitlesFragment() + SubtitlesFragment().apply { + arguments = Bundle().apply { + putBoolean("hide", hide) + } + } ) ?.commit() } @@ -106,15 +114,17 @@ class SubtitlesFragment : Fragment() { } private fun onColorSelected(stuff: Pair) { - setColor(stuff.first, stuff.second) - activity?.hideSystemUI() + context?.setColor(stuff.first, stuff.second) + if (hide) + activity?.hideSystemUI() } private fun onDialogDismissed(id: Int) { - activity?.hideSystemUI() + if (hide) + activity?.hideSystemUI() } - private fun setColor(id: Int, color: Int?) { + private fun Context.setColor(id: Int, color: Int?) { val realColor = color ?: getDefColor(id) when (id) { 0 -> state.foregroundColor = realColor @@ -128,7 +138,7 @@ class SubtitlesFragment : Fragment() { updateState() } - private fun updateState() { + private fun Context.updateState() { subtitle_text?.setStyle(fromSaveToStyle(state)) } @@ -153,7 +163,8 @@ class SubtitlesFragment : Fragment() { return inflater.inflate(R.layout.subtitle_settings, container, false) } - lateinit var state: SaveCaptionStyle + private lateinit var state: SaveCaptionStyle + private var hide: Boolean = true override fun onDestroy() { super.onDestroy() @@ -162,13 +173,14 @@ class SubtitlesFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + hide = arguments?.getBoolean("hide") ?: true MainActivity.onColorSelectedEvent += ::onColorSelected MainActivity.onDialogDismissedEvent += ::onDialogDismissed context?.fixPaddingStatusbar(subs_root) state = requireContext().getCurrentSavedStyle() - updateState() + context?.updateState() fun View.setup(id: Int) { this.setOnClickListener { @@ -181,7 +193,7 @@ class SubtitlesFragment : Fragment() { } this.setOnLongClickListener { - setColor(id, null) + it.context.setColor(id, null) Toast.makeText(it.context, R.string.subs_default_reset_toast, Toast.LENGTH_SHORT).show() return@setOnLongClickListener true } @@ -192,6 +204,11 @@ class SubtitlesFragment : Fragment() { subs_background_color.setup(2) subs_window_color.setup(3) + val dismissCallback = { + if (hide) + activity?.hideSystemUI() + } + subs_subtitle_elevation.setOnClickListener { textView -> val elevationTypes = listOf( Pair(0, "None"), @@ -205,17 +222,19 @@ class SubtitlesFragment : Fragment() { elevationTypes.map { it.second }, elevationTypes.map { it.first }.indexOf(state.elevation), (textView as TextView).text.toString(), - false + false, + dismissCallback ) { index -> state.elevation = elevationTypes.map { it.first }[index] - updateState() - activity?.hideSystemUI() + textView.context.updateState() + if (hide) + activity?.hideSystemUI() } } subs_subtitle_elevation.setOnLongClickListener { state.elevation = 0 - updateState() + it.context.updateState() Toast.makeText(it.context, R.string.subs_default_reset_toast, Toast.LENGTH_SHORT).show() return@setOnLongClickListener true } @@ -233,17 +252,53 @@ class SubtitlesFragment : Fragment() { edgeTypes.map { it.second }, edgeTypes.map { it.first }.indexOf(state.edgeType), (textView as TextView).text.toString(), - false + false, + dismissCallback ) { index -> state.edgeType = edgeTypes.map { it.first }[index] - updateState() - activity?.hideSystemUI() + textView.context.updateState() } } subs_edge_type.setOnLongClickListener { state.edgeType = CaptionStyleCompat.EDGE_TYPE_OUTLINE - updateState() + it.context.updateState() + Toast.makeText(it.context, R.string.subs_default_reset_toast, Toast.LENGTH_SHORT).show() + return@setOnLongClickListener true + } + + subs_font.setOnClickListener { textView -> + val fontTypes = listOf( + Pair(null, "Normal"), + Pair(R.font.trebuchet_ms, "Trebuchet MS"), + Pair(R.font.google_sans, "Google Sans"), + Pair(R.font.open_sans, "Open Sans"), + Pair(R.font.futura, "Futura"), + Pair(R.font.consola, "Consola"), + Pair(R.font.gotham, "Gotham"), + Pair(R.font.lucida_grande, "Lucida Grande"), + Pair(R.font.stix_general, "STIX General"), + Pair(R.font.times_new_roman, "Times New Roman"), + Pair(R.font.verdana, "Verdana"), + Pair(R.font.ubuntu_regular, "Ubuntu"), + Pair(R.font.poppins_regular, "Poppins"), + ) + + textView.context.showBottomDialog( + fontTypes.map { it.second }, + fontTypes.map { it.first }.indexOf(state.typeface), + (textView as TextView).text.toString(), + false, + dismissCallback + ) { index -> + state.typeface = fontTypes.map { it.first }[index] + textView.context.updateState() + } + } + + subs_font.setOnLongClickListener { + state.typeface = null + it.context.updateState() Toast.makeText(it.context, R.string.subs_default_reset_toast, Toast.LENGTH_SHORT).show() return@setOnLongClickListener true } @@ -255,7 +310,7 @@ class SubtitlesFragment : Fragment() { apply_btt.setOnClickListener { it.context.saveStyle(state) applyStyleEvent.invoke(state) - fromSaveToStyle(state) + it.context.fromSaveToStyle(state) activity?.popCurrentPage() } diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/SingleSelectionHelper.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/SingleSelectionHelper.kt index 2e7b0ddc..2128ab4c 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/SingleSelectionHelper.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/SingleSelectionHelper.kt @@ -18,7 +18,8 @@ object SingleSelectionHelper { selectedIndex: Int, name: String, showApply: Boolean, - callback: (Int) -> Unit + callback: (Int) -> Unit, + dismissCallback: () -> Unit ) { val listView = dialog.findViewById(R.id.listview1)!! val textView = dialog.findViewById(R.id.text1)!! @@ -46,6 +47,10 @@ object SingleSelectionHelper { var currentIndex = selectedIndex + dialog.setOnDismissListener { + dismissCallback.invoke() + } + listView.setOnItemClickListener { _, _, which, _ -> if (showApply) { currentIndex = which @@ -71,14 +76,15 @@ object SingleSelectionHelper { selectedIndex: Int, name: String, showApply: Boolean, - callback: (Int) -> Unit + dismissCallback: () -> Unit, + callback: (Int) -> Unit, ) { val builder = AlertDialog.Builder(this, R.style.AlertDialogCustom).setView(R.layout.bottom_selection_dialog) val dialog = builder.create() dialog.show() - showDialog(dialog, items, selectedIndex, name, showApply, callback) + showDialog(dialog, items, selectedIndex, name, showApply, callback, dismissCallback) } fun Context.showBottomDialog( @@ -86,13 +92,14 @@ object SingleSelectionHelper { selectedIndex: Int, name: String, showApply: Boolean, - callback: (Int) -> Unit + dismissCallback: () -> Unit, + callback: (Int) -> Unit, ) { val builder = BottomSheetDialog(this) builder.setContentView(R.layout.bottom_selection_dialog) builder.show() - showDialog(builder, items, selectedIndex, name, showApply, callback) + showDialog(builder, items, selectedIndex, name, showApply, callback, dismissCallback) } } \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_outline_subtitles_24.xml b/app/src/main/res/drawable/ic_outline_subtitles_24.xml new file mode 100644 index 00000000..3b0780bf --- /dev/null +++ b/app/src/main/res/drawable/ic_outline_subtitles_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/quick_novel_icon.xml b/app/src/main/res/drawable/quick_novel_icon.xml new file mode 100644 index 00000000..b19aaafe --- /dev/null +++ b/app/src/main/res/drawable/quick_novel_icon.xml @@ -0,0 +1,31 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/shiro_icon.xml b/app/src/main/res/drawable/shiro_icon.xml new file mode 100644 index 00000000..3427d547 --- /dev/null +++ b/app/src/main/res/drawable/shiro_icon.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/subtitles_preview_background.jpg b/app/src/main/res/drawable/subtitles_preview_background.jpg new file mode 100644 index 00000000..c7cd5f2e Binary files /dev/null and b/app/src/main/res/drawable/subtitles_preview_background.jpg differ diff --git a/app/src/main/res/font/consola.ttf b/app/src/main/res/font/consola.ttf new file mode 100644 index 00000000..cd4980c1 Binary files /dev/null and b/app/src/main/res/font/consola.ttf differ diff --git a/app/src/main/res/font/futura.ttf b/app/src/main/res/font/futura.ttf new file mode 100644 index 00000000..1d81d489 Binary files /dev/null and b/app/src/main/res/font/futura.ttf differ diff --git a/app/src/main/res/font/gotham.ttf b/app/src/main/res/font/gotham.ttf new file mode 100644 index 00000000..793dce5e Binary files /dev/null and b/app/src/main/res/font/gotham.ttf differ diff --git a/app/src/main/res/font/lucida_grande.ttf b/app/src/main/res/font/lucida_grande.ttf new file mode 100644 index 00000000..b34124ff Binary files /dev/null and b/app/src/main/res/font/lucida_grande.ttf differ diff --git a/app/src/main/res/font/open_sans.ttf b/app/src/main/res/font/open_sans.ttf new file mode 100644 index 00000000..29bfd35a Binary files /dev/null and b/app/src/main/res/font/open_sans.ttf differ diff --git a/app/src/main/res/font/poppins_regular.ttf b/app/src/main/res/font/poppins_regular.ttf new file mode 100644 index 00000000..be06e7fd Binary files /dev/null and b/app/src/main/res/font/poppins_regular.ttf differ diff --git a/app/src/main/res/font/stix_general.ttf b/app/src/main/res/font/stix_general.ttf new file mode 100644 index 00000000..521c6cd4 Binary files /dev/null and b/app/src/main/res/font/stix_general.ttf differ diff --git a/app/src/main/res/font/times_new_roman.ttf b/app/src/main/res/font/times_new_roman.ttf new file mode 100644 index 00000000..5cdac9ca Binary files /dev/null and b/app/src/main/res/font/times_new_roman.ttf differ diff --git a/app/src/main/res/font/trebuchet_ms.ttf b/app/src/main/res/font/trebuchet_ms.ttf new file mode 100644 index 00000000..b3bd292d Binary files /dev/null and b/app/src/main/res/font/trebuchet_ms.ttf differ diff --git a/app/src/main/res/font/ubuntu_regular.ttf b/app/src/main/res/font/ubuntu_regular.ttf new file mode 100644 index 00000000..dbb834a4 Binary files /dev/null and b/app/src/main/res/font/ubuntu_regular.ttf differ diff --git a/app/src/main/res/font/verdana.ttf b/app/src/main/res/font/verdana.ttf new file mode 100644 index 00000000..2655dc69 Binary files /dev/null and b/app/src/main/res/font/verdana.ttf differ diff --git a/app/src/main/res/layout/player_select_source_and_subs.xml b/app/src/main/res/layout/player_select_source_and_subs.xml index f286da39..d86609cb 100644 --- a/app/src/main/res/layout/player_select_source_and_subs.xml +++ b/app/src/main/res/layout/player_select_source_and_subs.xml @@ -19,10 +19,11 @@ android:orientation="vertical" android:layout_weight="50"> - - + + + + + + + + Edge Type Subtitle Elevation Reset to default value + Preview Background + Font \ No newline at end of file diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 34e954e3..58d49656 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -7,6 +7,13 @@ android:title="Player" app:isPreferenceVisible="true" > + + + + + + + + + + + + + +