Merge pull request #105 from AbduAmeen/title_description_seperation

Added separation of title, description and views/date
This commit is contained in:
Farbod 2022-04-04 00:43:26 -07:00 committed by GitHub
commit 3d822947fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 287 additions and 248 deletions

View File

@ -4,7 +4,6 @@ import android.app.Activity
import android.content.Context
import android.content.pm.ActivityInfo
import android.content.res.Configuration
import android.content.res.Resources
import android.net.Uri
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
@ -13,7 +12,6 @@ import android.os.Handler
import android.util.Log
import android.view.*
import android.view.inputmethod.InputMethodManager
import android.widget.FrameLayout
import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.widget.Toolbar
@ -21,21 +19,12 @@ import androidx.constraintlayout.motion.widget.MotionLayout
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.os.bundleOf
import androidx.core.text.HtmlCompat
import androidx.core.view.ViewCompat
import androidx.core.view.ViewCompat.getWindowInsetsController
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.core.view.WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
import androidx.fragment.app.Fragment
import androidx.navigation.NavController
import androidx.navigation.Navigation
import com.google.android.material.bottomnavigation.BottomNavigationView
import androidx.navigation.findNavController
import androidx.navigation.ui.NavigationUI
import androidx.navigation.ui.NavigationUI.onNavDestinationSelected
import androidx.navigation.ui.setupWithNavController
import androidx.preference.PreferenceManager
import com.google.android.exoplayer2.ExoPlayer
import com.google.android.material.color.DynamicColors
import java.lang.Exception
@ -44,6 +33,7 @@ class MainActivity : AppCompatActivity() {
lateinit var bottomNavigationView: BottomNavigationView
lateinit var toolbar: Toolbar
lateinit var navController : NavController
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)

View File

@ -26,6 +26,7 @@ import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.app.ActivityCompat
import androidx.core.net.toUri
import androidx.core.os.bundleOf
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.preference.PreferenceManager
@ -53,7 +54,6 @@ import java.io.IOException
import java.net.URLEncoder
import kotlin.math.abs
var isFullScreen = false
class PlayerFragment : Fragment() {
@ -84,7 +84,8 @@ class PlayerFragment : Fragment() {
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
@ -94,6 +95,8 @@ class PlayerFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
hideKeyboard()
val playerDescription = view.findViewById<TextView>(R.id.player_description)
videoId = videoId!!.replace("/watch?v=", "")
relDownloadVideo = view.findViewById(R.id.relPlayer_download)
val mainActivity = activity as MainActivity
@ -108,7 +111,6 @@ class PlayerFragment : Fragment() {
startId: Int,
endId: Int
) {
}
override fun onTransitionChange(motionLayout: MotionLayout?, startId: Int, endId: Int, progress: Float) {
@ -117,7 +119,6 @@ class PlayerFragment : Fragment() {
mainMotionLayout.progress = abs(progress)
eId = endId
sId = startId
}
override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) {
@ -135,7 +136,6 @@ class PlayerFragment : Fragment() {
view.findViewById<TextView>(R.id.quality_text).visibility = View.VISIBLE
mainMotionLayout.progress = 0.toFloat()
}
}
override fun onTransitionTrigger(
@ -144,8 +144,6 @@ class PlayerFragment : Fragment() {
positive: Boolean,
progress: Float
) {
}
})
playerMotionLayout.progress = 1.toFloat()
@ -158,7 +156,6 @@ class PlayerFragment : Fragment() {
mainActivity.supportFragmentManager.beginTransaction()
.remove(this)
.commit()
}
view.findViewById<ImageButton>(R.id.close_imageButton).setOnClickListener {
motionLayout.transitionToEnd()
@ -180,6 +177,12 @@ class PlayerFragment : Fragment() {
true
}
}
view.findViewById<ConstraintLayout>(R.id.player_title_layout).setOnClickListener {
var visible = playerDescription.isVisible
playerDescription.visibility = if (visible) View.GONE else View.VISIBLE
}
// FullScreen button trigger
view.findViewById<ImageButton>(R.id.fullscreen).setOnClickListener {
// remember to hide everything when new thing added
@ -193,7 +196,6 @@ class PlayerFragment : Fragment() {
val mainActivity = activity as MainActivity
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
isFullScreen=true
}else{
with(motionLayout) {
getConstraintSet(R.id.start).constrainHeight(R.id.player, 0)
@ -205,15 +207,11 @@ class PlayerFragment : Fragment() {
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
isFullScreen = false
}
}
relatedRecView = view.findViewById(R.id.player_recView)
relatedRecView.layoutManager = GridLayoutManager(view.context, resources.getInteger(R.integer.grid_items))
}
override fun onStop() {
super.onStop()
}
@ -225,7 +223,6 @@ class PlayerFragment : Fragment() {
} catch (e: Exception) {}
}
private fun fetchJson(view: View) {
fun run() {
lifecycleScope.launchWhenCreated {
@ -250,10 +247,13 @@ class PlayerFragment : Fragment() {
runOnUiThread {
var subtitle = mutableListOf<SubtitleConfiguration>()
if (response.subtitles!!.isNotEmpty()) {
subtitle?.add(SubtitleConfiguration.Builder(response.subtitles!![0].url!!.toUri())
subtitle?.add(
SubtitleConfiguration.Builder(response.subtitles!![0].url!!.toUri())
.setMimeType(response.subtitles!![0].mimeType!!) // The correct MIME type (required).
.setLanguage(response.subtitles!![0].code) // The subtitle language (optional).
.build())}
.build()
)
}
exoPlayer = ExoPlayer.Builder(view.context)
.setSeekBackIncrementMs(5000)
@ -301,7 +301,6 @@ class PlayerFragment : Fragment() {
}
}
}
}
response.hls != null -> {
val mediaItem: MediaItem = MediaItem.Builder()
@ -335,7 +334,8 @@ class PlayerFragment : Fragment() {
exoPlayer.prepare()
exoPlayer.play()
view.findViewById<TextView>(R.id.title_textView).text = response.title
view.findViewById<TextView>(R.id.player_title).text = response.title
view.findViewById<TextView>(R.id.player_description).text = response.description
view.findViewById<ImageButton>(R.id.quality_select).setOnClickListener {
// Dialog for quality selection
@ -343,7 +343,8 @@ class PlayerFragment : Fragment() {
AlertDialog.Builder(it)
}
builder!!.setTitle(R.string.choose_quality_dialog)
.setItems(videosNameArray,
.setItems(
videosNameArray,
DialogInterface.OnClickListener { _, which ->
whichQuality = which
if (response.subtitles!!.isNotEmpty()) {
@ -381,7 +382,8 @@ class PlayerFragment : Fragment() {
exoPlayer.setMediaSource(mergeSource)
}
view.findViewById<TextView>(R.id.quality_text).text = videosNameArray[which]
})
}
)
val dialog: AlertDialog? = builder?.create()
dialog?.show()
}
@ -389,8 +391,10 @@ class PlayerFragment : Fragment() {
exoPlayer!!.addListener(object : com.google.android.exoplayer2.Player.Listener {
override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) {
exoPlayerView.keepScreenOn = !(playbackState == Player.STATE_IDLE || playbackState == Player.STATE_ENDED ||
!playWhenReady)
exoPlayerView.keepScreenOn = !(
playbackState == Player.STATE_IDLE || playbackState == Player.STATE_ENDED ||
!playWhenReady
)
if (playWhenReady && playbackState == Player.STATE_READY) {
// media actually playing
@ -412,7 +416,7 @@ class PlayerFragment : Fragment() {
} else {
Html.fromHtml(response.description)
}
view.findViewById<TextView>(R.id.player_sub).text = response.views.formatShort() + " views • "+response.uploadDate
view.findViewById<TextView>(R.id.player_views_info).text = response.views.formatShort() + " views • " + response.uploadDate
view.findViewById<TextView>(R.id.textLike).text = response.likes.formatShort()
val channelImage = view.findViewById<ImageView>(R.id.player_channelImage)
Picasso.get().load(response.uploaderAvatar).into(channelImage)
@ -455,10 +459,12 @@ class PlayerFragment : Fragment() {
Log.d("myz", "" + SDK_INT)
if (!Environment.isExternalStorageManager()) {
ActivityCompat.requestPermissions(
mainActivity, arrayOf(
mainActivity,
arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.MANAGE_EXTERNAL_STORAGE
), 1
),
1
) // permission request code is just an int
}
} else {
@ -533,13 +539,12 @@ class PlayerFragment : Fragment() {
Toast.makeText(context, R.string.vlcerror, Toast.LENGTH_SHORT)
.show()
}
}}
}
}
}
}
}
run()
}
private fun isSubscribed(button: MaterialButton, channel_id: String) {
@ -561,13 +566,15 @@ class PlayerFragment : Fragment() {
(context as Activity).theme.resolveAttribute(
android.R.attr.colorPrimary,
colorPrimary,
true)
true
)
val ColorText = TypedValue()
(context as Activity).theme.resolveAttribute(
R.attr.colorOnSurface,
ColorText,
true)
true
)
runOnUiThread {
if (response.subscribed == true) {
@ -581,13 +588,13 @@ class PlayerFragment : Fragment() {
unsubscribe(channel_id)
button.text = getString(R.string.subscribe)
button.setTextColor(colorPrimary.data)
} else {
subscribe(channel_id)
button.text = getString(R.string.unsubscribe)
button.setTextColor(colorPrimary.data)
}
}}
}
}
}
}
}
@ -633,7 +640,6 @@ class PlayerFragment : Fragment() {
run()
}
private fun Fragment?.runOnUiThread(action: () -> Unit) {
this ?: return
if (!isAdded) return // Fragment not attached to an Activity
@ -656,5 +662,4 @@ class PlayerFragment : Fragment() {
override fun onResume() {
super.onResume()
}
}

View File

@ -29,24 +29,68 @@
>
<TextView
android:id="@+id/player_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text=""
android:textSize="15sp"
android:layout_margin="7dp"
android:textStyle="bold" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/player_info_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/player_sub"
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/player_title_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/player_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="8dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="" />
android:text="Title"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@id/player_description_arrow"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/player_views_info"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="TextView"
android:textSize="12sp"
app:layout_constraintEnd_toStartOf="@id/player_description_arrow"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/player_title" />
<ImageView
android:id="@+id/player_description_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:paddingLeft="16dp"
android:src="@drawable/ic_arrow_down"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/player_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:textSize="14sp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/player_title_layout" />
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:layout_width="match_parent"