diff --git a/app/src/main/java/com/github/libretube/DownloadService.kt b/app/src/main/java/com/github/libretube/DownloadService.kt index e13b766b5..997b383c0 100644 --- a/app/src/main/java/com/github/libretube/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/DownloadService.kt @@ -69,7 +69,6 @@ class DownloadService : Service() { } private fun downloadManager() { - // create folder for temporary files tempDir = File( applicationContext.getExternalFilesDir(DIRECTORY_DOWNLOADS), @@ -255,10 +254,11 @@ class DownloadService : Service() { if (returnCode.toString() != "0") downloadFailedNotification() else downloadSucceededNotification() onDestroy() - }, { - // CALLED WHEN SESSION PRINTS LOGS - Log.e(TAG, it.message.toString()) - } + }, + { + // CALLED WHEN SESSION PRINTS LOGS + Log.e(TAG, it.message.toString()) + } ) { // CALLED WHEN SESSION GENERATES STATISTICS Log.e(TAG + "stat", it.time.toString()) diff --git a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt index efce52157..3ce71ac4a 100644 --- a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt @@ -19,11 +19,11 @@ import com.github.libretube.obj.CommentsPage import com.github.libretube.util.RetrofitInstance import com.github.libretube.util.formatShort import com.squareup.picasso.Picasso -import java.io.IOException import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import retrofit2.HttpException +import java.io.IOException class CommentsAdapter( private val videoId: String, diff --git a/app/src/main/java/com/github/libretube/adapters/PlaylistAdapter.kt b/app/src/main/java/com/github/libretube/adapters/PlaylistAdapter.kt index bfc1e481a..28e9065f0 100644 --- a/app/src/main/java/com/github/libretube/adapters/PlaylistAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/PlaylistAdapter.kt @@ -20,11 +20,11 @@ import com.github.libretube.obj.PlaylistId import com.github.libretube.obj.StreamItem import com.github.libretube.util.RetrofitInstance import com.squareup.picasso.Picasso -import java.io.IOException import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import retrofit2.HttpException +import java.io.IOException class PlaylistAdapter( private val videoFeed: MutableList, diff --git a/app/src/main/java/com/github/libretube/adapters/PlaylistsAdapter.kt b/app/src/main/java/com/github/libretube/adapters/PlaylistsAdapter.kt index 1d3c8e5a2..63fd37428 100644 --- a/app/src/main/java/com/github/libretube/adapters/PlaylistsAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/PlaylistsAdapter.kt @@ -17,10 +17,10 @@ import com.github.libretube.obj.Playlists import com.github.libretube.util.RetrofitInstance import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.squareup.picasso.Picasso -import java.io.IOException import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import retrofit2.HttpException +import java.io.IOException class PlaylistsAdapter( private val playlists: MutableList, diff --git a/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt b/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt index 33b5c705f..d7a8d465d 100644 --- a/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt @@ -85,10 +85,11 @@ class SearchViewHolder( val viewsString = if (item.views?.toInt() != -1) item.views.formatShort() else "" val uploadDate = if (item.uploadedDate != null) item.uploadedDate else "" views.text = - if (viewsString != "" && uploadDate != "") + if (viewsString != "" && uploadDate != "") { "$viewsString • $uploadDate" - else + } else { viewsString + uploadDate + } val channelName = v.findViewById(R.id.search_channel_name) channelName.text = item.uploaderName v.setOnClickListener { @@ -145,9 +146,10 @@ class SearchViewHolder( val playlistChannelName = v.findViewById(R.id.search_name) playlistChannelName.text = item.uploaderName val playlistVideosNumber = v.findViewById(R.id.search_playlist_videos) - if (item.videos?.toInt() != -1) + if (item.videos?.toInt() != -1) { playlistVideosNumber.text = v.context.getString(R.string.videoCount, item.videos.toString()) + } v.setOnClickListener { // playlist clicked val activity = v.context as MainActivity diff --git a/app/src/main/java/com/github/libretube/adapters/SubscriptionAdapter.kt b/app/src/main/java/com/github/libretube/adapters/SubscriptionAdapter.kt index 0db923b83..a05024ce0 100644 --- a/app/src/main/java/com/github/libretube/adapters/SubscriptionAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/SubscriptionAdapter.kt @@ -34,8 +34,9 @@ class SubscriptionAdapter( fun updateItems() { // limitedVideoFeed.add("") i += 10 - if (i > videoFeed.size) + if (i > videoFeed.size) { i = videoFeed.size + } notifyDataSetChanged() } diff --git a/app/src/main/java/com/github/libretube/adapters/SubscriptionChannelAdapter.kt b/app/src/main/java/com/github/libretube/adapters/SubscriptionChannelAdapter.kt index 3ae744511..dcd3b4e03 100644 --- a/app/src/main/java/com/github/libretube/adapters/SubscriptionChannelAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/SubscriptionChannelAdapter.kt @@ -15,11 +15,11 @@ import com.github.libretube.obj.Subscribe import com.github.libretube.obj.Subscription import com.github.libretube.util.RetrofitInstance import com.squareup.picasso.Picasso -import java.io.IOException import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import retrofit2.HttpException +import java.io.IOException class SubscriptionChannelAdapter(private val subscriptions: MutableList) : RecyclerView.Adapter() { diff --git a/app/src/main/java/com/github/libretube/dialogs/AddtoPlaylistDialog.kt b/app/src/main/java/com/github/libretube/dialogs/AddtoPlaylistDialog.kt index 80453c14b..126bdd7e0 100644 --- a/app/src/main/java/com/github/libretube/dialogs/AddtoPlaylistDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/AddtoPlaylistDialog.kt @@ -19,8 +19,8 @@ import com.github.libretube.R import com.github.libretube.obj.PlaylistId import com.github.libretube.util.RetrofitInstance import com.google.android.material.dialog.MaterialAlertDialogBuilder -import java.io.IOException import retrofit2.HttpException +import java.io.IOException class AddtoPlaylistDialog : DialogFragment() { private val TAG = "AddToPlaylistDialog" diff --git a/app/src/main/java/com/github/libretube/dialogs/CreatePlaylistDialog.kt b/app/src/main/java/com/github/libretube/dialogs/CreatePlaylistDialog.kt index d33cf90ee..000bf1897 100644 --- a/app/src/main/java/com/github/libretube/dialogs/CreatePlaylistDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/CreatePlaylistDialog.kt @@ -19,8 +19,8 @@ import com.github.libretube.obj.Playlists import com.github.libretube.util.RetrofitInstance import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.textfield.TextInputEditText -import java.io.IOException import retrofit2.HttpException +import java.io.IOException class CreatePlaylistDialog : DialogFragment() { val TAG = "CreatePlaylistDialog" diff --git a/app/src/main/java/com/github/libretube/dialogs/CustomInstanceDialog.kt b/app/src/main/java/com/github/libretube/dialogs/CustomInstanceDialog.kt index e1f06186a..50e49356c 100644 --- a/app/src/main/java/com/github/libretube/dialogs/CustomInstanceDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/CustomInstanceDialog.kt @@ -52,13 +52,17 @@ class CustomInstanceDialog : DialogFragment() { } catch (e: Exception) { // invalid URL Toast.makeText( - context, getString(R.string.invalid_url), Toast.LENGTH_SHORT + context, + getString(R.string.invalid_url), + Toast.LENGTH_SHORT ).show() } } else { // at least one empty input Toast.makeText( - context, context?.getString(R.string.empty_instance), Toast.LENGTH_SHORT + context, + context?.getString(R.string.empty_instance), + Toast.LENGTH_SHORT ).show() } } diff --git a/app/src/main/java/com/github/libretube/dialogs/LoginDialog.kt b/app/src/main/java/com/github/libretube/dialogs/LoginDialog.kt index ae27c5ca2..8d1cc33f8 100644 --- a/app/src/main/java/com/github/libretube/dialogs/LoginDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/LoginDialog.kt @@ -17,8 +17,8 @@ import com.github.libretube.R import com.github.libretube.obj.Login import com.github.libretube.util.RetrofitInstance import com.google.android.material.dialog.MaterialAlertDialogBuilder -import java.io.IOException import retrofit2.HttpException +import java.io.IOException class LoginDialog : DialogFragment() { private val TAG = "LoginDialog" diff --git a/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt b/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt index 862bf8a4f..94fd2702d 100644 --- a/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt @@ -11,11 +11,11 @@ import com.github.libretube.R import com.github.libretube.obj.PlaylistId import com.github.libretube.util.RetrofitInstance import com.google.android.material.dialog.MaterialAlertDialogBuilder -import java.io.IOException import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import retrofit2.HttpException +import java.io.IOException class PlaylistOptionsDialog( private val playlistId: String, diff --git a/app/src/main/java/com/github/libretube/fragments/ChannelFragment.kt b/app/src/main/java/com/github/libretube/fragments/ChannelFragment.kt index f42f95b69..f2a78c4d5 100644 --- a/app/src/main/java/com/github/libretube/fragments/ChannelFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/ChannelFragment.kt @@ -22,8 +22,8 @@ import com.github.libretube.util.RetrofitInstance import com.github.libretube.util.formatShort import com.google.android.material.button.MaterialButton import com.squareup.picasso.Picasso -import java.io.IOException import retrofit2.HttpException +import java.io.IOException class ChannelFragment : Fragment() { @@ -201,7 +201,10 @@ class ChannelFragment : Fragment() { channelName.text = response.name if (response.verified) { channelName.setCompoundDrawablesWithIntrinsicBounds( - 0, 0, R.drawable.ic_verified, 0 + 0, + 0, + R.drawable.ic_verified, + 0 ) } view.findViewById(R.id.channel_subs).text = resources.getString( @@ -231,7 +234,6 @@ class ChannelFragment : Fragment() { private fun fetchNextPage() { fun run() { - lifecycleScope.launchWhenCreated { val response = try { RetrofitInstance.api.getChannelNextPage(channel_id!!, nextPage!!) diff --git a/app/src/main/java/com/github/libretube/fragments/Home.kt b/app/src/main/java/com/github/libretube/fragments/Home.kt index 5235e72c7..b78d774e3 100644 --- a/app/src/main/java/com/github/libretube/fragments/Home.kt +++ b/app/src/main/java/com/github/libretube/fragments/Home.kt @@ -16,8 +16,8 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import com.github.libretube.R import com.github.libretube.adapters.TrendingAdapter import com.github.libretube.util.RetrofitInstance -import java.io.IOException import retrofit2.HttpException +import java.io.IOException class Home : Fragment() { @@ -34,7 +34,6 @@ class Home : Fragment() { container: ViewGroup?, savedInstanceState: Bundle? ): View? { - // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_home, container, false) } diff --git a/app/src/main/java/com/github/libretube/fragments/Library.kt b/app/src/main/java/com/github/libretube/fragments/Library.kt index 14946625e..812411b4c 100644 --- a/app/src/main/java/com/github/libretube/fragments/Library.kt +++ b/app/src/main/java/com/github/libretube/fragments/Library.kt @@ -19,8 +19,8 @@ import com.github.libretube.adapters.PlaylistsAdapter import com.github.libretube.dialogs.CreatePlaylistDialog import com.github.libretube.util.RetrofitInstance import com.google.android.material.floatingactionbutton.FloatingActionButton -import java.io.IOException import retrofit2.HttpException +import java.io.IOException class Library : Fragment() { diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index 54aa2cad5..10c035f05 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -18,6 +18,7 @@ import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.Button import android.widget.FrameLayout import android.widget.ImageButton import android.widget.ImageView @@ -84,11 +85,11 @@ import com.google.android.material.button.MaterialButton import com.google.android.material.card.MaterialCardView import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.squareup.picasso.Picasso +import org.chromium.net.CronetEngine +import retrofit2.HttpException import java.io.IOException import java.util.concurrent.Executors import kotlin.math.abs -import org.chromium.net.CronetEngine -import retrofit2.HttpException var isFullScreen = false @@ -118,6 +119,7 @@ class PlayerFragment : Fragment() { private lateinit var segmentData: Segments private var relatedStreams: List? = arrayListOf() private var relatedStreamsEnabled = true + private var isPlayerLocked: Boolean = false private lateinit var relDownloadVideo: LinearLayout @@ -182,6 +184,7 @@ class PlayerFragment : Fragment() { val mainMotionLayout = mainActivity.findViewById(R.id.mainMotionLayout) mainMotionLayout.progress = abs(progress) + exoPlayerView.hideController() eId = endId sId = startId } @@ -192,13 +195,11 @@ class PlayerFragment : Fragment() { val mainMotionLayout = mainActivity.findViewById(R.id.mainMotionLayout) if (currentId == eId) { - exoPlayerView.hideController() exoPlayerView.useController = false - mainMotionLayout.progress = 1.toFloat() + mainMotionLayout.progress = 1F } else if (currentId == sId) { - exoPlayerView.showController() exoPlayerView.useController = true - mainMotionLayout.progress = 0.toFloat() + mainMotionLayout.progress = 0F } } @@ -259,8 +260,9 @@ class PlayerFragment : Fragment() { } // FullScreen button trigger - view.findViewById(R.id.fullscreen).setOnClickListener { - // remember to hide everything when new thing added + val fullScreenButton = view.findViewById(R.id.fullscreen) + fullScreenButton.setOnClickListener { + exoPlayerView.hideController() if (!isFullScreen) { with(motionLayout) { getConstraintSet(R.id.start).constrainHeight(R.id.player, -1) @@ -268,6 +270,7 @@ class PlayerFragment : Fragment() { } view.findViewById(R.id.main_container).isClickable = true view.findViewById(R.id.linLayout).visibility = View.GONE + fullScreenButton.setImageResource(R.drawable.ic_fullscreen_exit) val mainActivity = activity as MainActivity mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE isFullScreen = true @@ -278,6 +281,7 @@ class PlayerFragment : Fragment() { } view.findViewById(R.id.main_container).isClickable = false view.findViewById(R.id.linLayout).visibility = View.VISIBLE + fullScreenButton.setImageResource(R.drawable.ic_fullscreen) val mainActivity = activity as MainActivity mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT isFullScreen = false @@ -295,6 +299,23 @@ class PlayerFragment : Fragment() { } } + // lock and unlock the player + val lockPlayerButton = view.findViewById(R.id.lock_player) + lockPlayerButton.setOnClickListener { + // change the locked/unlocked icon + if (!isPlayerLocked) { + lockPlayerButton.setImageResource(R.drawable.ic_locked) + } else { + lockPlayerButton.setImageResource(R.drawable.ic_unlocked) + } + + // show/hide all the controls + lockPlayer(isPlayerLocked) + + // change locked status + isPlayerLocked = !isPlayerLocked + } + val scrollView = view.findViewById(R.id.player_scrollView) scrollView.viewTreeObserver .addOnScrollChangedListener { @@ -362,8 +383,9 @@ class PlayerFragment : Fragment() { exoPlayerView.postDelayed(this::checkForSegments, 100) - if (!::segmentData.isInitialized || segmentData.segments.isEmpty()) + if (!::segmentData.isInitialized || segmentData.segments.isEmpty()) { return + } segmentData.segments.forEach { segment: Segment -> val segmentStart = (segment.segment!![0] * 1000.0f).toLong() @@ -458,7 +480,6 @@ class PlayerFragment : Fragment() { } if (categories.size > 0) { segmentData = try { - RetrofitInstance.api.getSegments( videoId!!, "[\"" + TextUtils.join("\",\"", categories) + "\"]" @@ -523,7 +544,6 @@ class PlayerFragment : Fragment() { playWhenReady: Boolean, playbackState: Int ) { - exoPlayerView.keepScreenOn = !( playbackState == Player.STATE_IDLE || playbackState == Player.STATE_ENDED || @@ -627,7 +647,6 @@ class PlayerFragment : Fragment() { } view.findViewById(R.id.player_channel).setOnClickListener { - val activity = view.context as MainActivity val bundle = bundleOf("channel_id" to response.uploaderUrl) activity.navController.navigate(R.id.channel, bundle) @@ -717,7 +736,6 @@ class PlayerFragment : Fragment() { } for (vid in response.videoStreams!!) { - Log.e(TAG, vid.toString()) // append quality to list if it has the preferred format (e.g. MPEG) if (vid.format.equals(videoFormatPreference)) { // preferred format videosNameArray += vid.quality!! @@ -863,7 +881,6 @@ class PlayerFragment : Fragment() { } private fun initializePlayerNotification(c: Context) { - mediaSession = MediaSessionCompat(c, this.javaClass.name) mediaSession.apply { isActive = true @@ -887,6 +904,15 @@ class PlayerFragment : Fragment() { } } + private fun lockPlayer(isLocked: Boolean) { + val visibility = if (isLocked) View.VISIBLE else View.GONE + exoPlayerView.findViewById(R.id.controls_top_right).visibility = visibility + exoPlayerView.findViewById(R.id.exo_play_pause).visibility = visibility + exoPlayerView.findViewById