diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt index 19ccea60f..f90599354 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/VideoPlayerActivity.kt @@ -1,33 +1,30 @@ package com.simplemobiletools.gallery.pro.activities import android.content.pm.ActivityInfo +import android.content.res.Configuration import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.net.Uri import android.os.Bundle +import android.util.DisplayMetrics import android.view.Menu import android.view.MenuItem import android.view.View import android.view.WindowManager +import android.widget.SeekBar +import com.simplemobiletools.commons.extensions.beInvisibleIf import com.simplemobiletools.commons.extensions.getFilenameFromUri -import com.simplemobiletools.commons.extensions.getParentPath import com.simplemobiletools.commons.extensions.toast +import com.simplemobiletools.commons.extensions.updateTextColors import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE import com.simplemobiletools.commons.helpers.isPiePlus import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.extensions.* -import com.simplemobiletools.gallery.pro.fragments.VideoFragment -import com.simplemobiletools.gallery.pro.fragments.ViewPagerFragment -import com.simplemobiletools.gallery.pro.helpers.MEDIUM -import com.simplemobiletools.gallery.pro.helpers.TYPE_VIDEOS -import com.simplemobiletools.gallery.pro.models.Medium import kotlinx.android.synthetic.main.activity_video_player.* -import java.io.File +import kotlinx.android.synthetic.main.bottom_video_time_holder.* -open class VideoPlayerActivity : SimpleActivity(), ViewPagerFragment.FragmentListener { - private var mMedium: Medium? = null - private var mIsFullScreen = false - private var mFragment: ViewPagerFragment? = null +open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListener { + private var mIsFullscreen = false private var mUri: Uri? = null public override fun onCreate(savedInstanceState: Bundle?) { @@ -36,7 +33,7 @@ open class VideoPlayerActivity : SimpleActivity(), ViewPagerFragment.FragmentLis handlePermission(PERMISSION_WRITE_STORAGE) { if (it) { - checkIntent(savedInstanceState) + initPlayer() } else { toast(R.string.no_storage_permissions) finish() @@ -50,11 +47,16 @@ open class VideoPlayerActivity : SimpleActivity(), ViewPagerFragment.FragmentLis supportActionBar?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) window.statusBarColor = Color.TRANSPARENT window.navigationBarColor = Color.TRANSPARENT + if (config.blackBackground) { + video_player_holder.background = ColorDrawable(Color.BLACK) + } + initTimeHolder() + updateTextColors(video_player_holder) } - private fun checkIntent(savedInstanceState: Bundle? = null) { + private fun initPlayer() { mUri = intent.data ?: return - val filename = getFilenameFromUri(mUri!!) + supportActionBar?.title = getFilenameFromUri(mUri!!) if (isPiePlus()) { window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES @@ -62,28 +64,16 @@ open class VideoPlayerActivity : SimpleActivity(), ViewPagerFragment.FragmentLis } showSystemUI(true) - val bundle = Bundle() - val file = File(mUri.toString()) - val type = TYPE_VIDEOS - - mMedium = Medium(null, filename, mUri.toString(), mUri!!.path.getParentPath(), 0, 0, file.length(), type, 0, false, 0L) - supportActionBar?.title = mMedium!!.name - bundle.putSerializable(MEDIUM, mMedium) - - if (savedInstanceState == null) { - mFragment = VideoFragment() - mFragment!!.listener = this - mFragment!!.arguments = bundle - supportFragmentManager.beginTransaction().replace(R.id.fragment_placeholder, mFragment!!).commit() - } - - if (config.blackBackground) { - fragment_holder.background = ColorDrawable(Color.BLACK) - } - window.decorView.setOnSystemUiVisibilityChangeListener { visibility -> val isFullscreen = visibility and View.SYSTEM_UI_FLAG_FULLSCREEN != 0 - mFragment?.fullscreenToggled(isFullscreen) + fullscreenToggled(isFullscreen) + } + + video_curr_time.setOnClickListener { skip(false) } + video_duration.setOnClickListener { skip(true) } + video_seekbar.setOnClickListener { } + video_player_holder.setOnClickListener { + fullscreenToggled(!mIsFullscreen) } } @@ -93,7 +83,7 @@ open class VideoPlayerActivity : SimpleActivity(), ViewPagerFragment.FragmentLis } override fun onOptionsItemSelected(item: MenuItem): Boolean { - if (mMedium == null || mUri == null) { + if (mUri == null) { return true } @@ -112,21 +102,61 @@ open class VideoPlayerActivity : SimpleActivity(), ViewPagerFragment.FragmentLis } } - override fun fragmentClicked() { - mIsFullScreen = !mIsFullScreen - if (mIsFullScreen) { + private fun fullscreenToggled(isFullScreen: Boolean) { + mIsFullscreen = isFullScreen + if (isFullScreen) { hideSystemUI(true) } else { showSystemUI(true) } - val newAlpha = if (mIsFullScreen) 0f else 1f + val newAlpha = if (isFullScreen) 0f else 1f top_shadow.animate().alpha(newAlpha).start() + video_time_holder.animate().alpha(newAlpha).start() } - override fun videoEnded() = false + private fun initTimeHolder() { + val left = 0 + val top = 0 + var right = 0 + var bottom = 0 - override fun goToPrevItem() {} + if (hasNavBar()) { + if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) { + bottom += navigationBarHeight + } else { + right += navigationBarWidth + bottom += navigationBarHeight + } + } - override fun goToNextItem() {} + video_time_holder.setPadding(left, top, right, bottom) + video_seekbar.setOnSeekBarChangeListener(this) + video_time_holder.beInvisibleIf(mIsFullscreen) + } + + private fun hasNavBar(): Boolean { + val display = windowManager.defaultDisplay + + val realDisplayMetrics = DisplayMetrics() + display.getRealMetrics(realDisplayMetrics) + + val displayMetrics = DisplayMetrics() + display.getMetrics(displayMetrics) + + return (realDisplayMetrics.widthPixels - displayMetrics.widthPixels > 0) || (realDisplayMetrics.heightPixels - displayMetrics.heightPixels > 0) + } + + private fun skip(forward: Boolean) { + + } + + override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { + } + + override fun onStartTrackingTouch(seekBar: SeekBar?) { + } + + override fun onStopTrackingTouch(seekBar: SeekBar?) { + } } diff --git a/app/src/main/res/layout/activity_video_player.xml b/app/src/main/res/layout/activity_video_player.xml index 8b5d7507e..8a0efeeb3 100644 --- a/app/src/main/res/layout/activity_video_player.xml +++ b/app/src/main/res/layout/activity_video_player.xml @@ -1,19 +1,51 @@ - - + + + + + + + + + + diff --git a/app/src/main/res/layout/bottom_video_time_holder.xml b/app/src/main/res/layout/bottom_video_time_holder.xml index cdf1e0c53..5862ced48 100644 --- a/app/src/main/res/layout/bottom_video_time_holder.xml +++ b/app/src/main/res/layout/bottom_video_time_holder.xml @@ -5,7 +5,8 @@ android:id="@+id/video_time_holder" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_alignParentBottom="true"> + android:layout_alignParentBottom="true" + android:background="@drawable/gradient_background">