Skip to content

Commit

Permalink
Merge pull request #27 from itszechs/dev
Browse files Browse the repository at this point in the history
Release 1.1.0
  • Loading branch information
itszechs authored Jun 25, 2022
2 parents f076b88 + 42daec4 commit 29299de
Show file tree
Hide file tree
Showing 42 changed files with 292 additions and 223 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ android {
applicationId "zechs.drive.stream"
minSdk 28
targetSdk 32
versionCode 4
versionName "1.0.3"
versionCode 5
versionName "1.1.0"
archivesBaseName = "${applicationId}-${versionCode}"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/zechs/drive/stream/data/remote/DriveHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import android.content.Intent
import android.util.Log
import com.google.android.gms.auth.GoogleAuthUtil
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInClient
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.google.android.gms.common.Scopes
import com.google.android.gms.common.api.Scope
import com.google.api.client.extensions.android.http.AndroidHttp
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential
Expand Down Expand Up @@ -35,6 +38,17 @@ class DriveHelper @Inject constructor(
var hasSignedIn = false
private set


fun getClient(): GoogleSignInClient {
val signInOptions = GoogleSignInOptions
.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(Scope(Scopes.DRIVE_FULL))
.requestEmail()
.build()

return GoogleSignIn.getClient(context, signInOptions)
}

/**
* Public method to send intent result from
* Google Sign-in flow
Expand Down
47 changes: 47 additions & 0 deletions app/src/main/java/zechs/drive/stream/ui/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.fragment.findNavController
import com.google.android.material.button.MaterialButton
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import zechs.drive.stream.R
import zechs.drive.stream.databinding.FragmentHomeBinding
import zechs.drive.stream.ui.BaseFragment
import zechs.drive.stream.utils.ext.navigateSafe


class HomeFragment : BaseFragment() {

companion object {
Expand All @@ -21,6 +29,8 @@ class HomeFragment : BaseFragment() {
private var _binding: FragmentHomeBinding? = null
private val binding get() = _binding!!

private val viewModel by activityViewModels<HomeViewModel>()

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down Expand Up @@ -75,6 +85,8 @@ class HomeFragment : BaseFragment() {

}

setupToolbar()
observeLogOutState()
}

private fun <T : MaterialButton> navigateToFiles(
Expand All @@ -90,6 +102,41 @@ class HomeFragment : BaseFragment() {
}
}

private fun setupToolbar() {
binding.toolbar.setOnMenuItemClickListener { item ->
if (item.itemId == R.id.action_logOut) {
MaterialAlertDialogBuilder(context!!)
.setTitle(getString(R.string.log_out_dialog_title))
.setNegativeButton(getString(R.string.no)) { dialog, _ ->
dialog.dismiss()
}
.setPositiveButton(getString(R.string.yes)) { dialog, _ ->
dialog.dismiss()
Log.d(TAG, "Logging out...")
viewModel.logOut()
}
.show()
return@setOnMenuItemClickListener true
}
return@setOnMenuItemClickListener false
}
}

private fun observeLogOutState() {
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.hasLoggedOut.collect {
if (it) {
// restart activity
activity!!.finish()
delay(250L)
activity!!.startActivity(activity!!.intent)
}
}
}
}
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/java/zechs/drive/stream/ui/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package zechs.drive.stream.ui.home

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import zechs.drive.stream.data.remote.DriveHelper
import javax.inject.Inject

@HiltViewModel
class HomeViewModel @Inject constructor(
private val driveHelper: DriveHelper
) : ViewModel() {

private val _hasLoggedOut = MutableStateFlow(false)
val hasLoggedOut = _hasLoggedOut.asStateFlow()

fun logOut() = viewModelScope.launch {
delay(250L)
val client = driveHelper.getClient()
// client.revokeAccess()
client.signOut()
_hasLoggedOut.value = true
}

}
12 changes: 1 addition & 11 deletions app/src/main/java/zechs/drive/stream/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.google.android.gms.common.Scopes
import com.google.android.gms.common.api.Scope
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import zechs.drive.stream.R
Expand Down Expand Up @@ -69,13 +65,7 @@ class MainActivity : AppCompatActivity() {
private fun requestSignIn() {
Log.d(TAG, "Requesting sign-in")

val signInOptions = GoogleSignInOptions
.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(Scope(Scopes.DRIVE_FULL))
.requestEmail()
.build()

val client = GoogleSignIn.getClient(this, signInOptions)
val client = viewModel.getClient()

val startForResult = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ class MainViewModel @Inject constructor(
Log.d(TAG, msg)
}

fun getClient() = driveHelper.getClient()
}
53 changes: 53 additions & 0 deletions app/src/main/java/zechs/drive/stream/ui/player/PlayerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import android.content.res.Configuration
import android.net.Uri
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.animation.AccelerateInterpolator
import android.widget.HorizontalScrollView
import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
Expand Down Expand Up @@ -69,6 +71,7 @@ class PlayerActivity : AppCompatActivity() {

// Player views
private lateinit var mainControlsRoot: LinearLayout
private lateinit var controlsScrollView: HorizontalScrollView
private lateinit var progressViewGroup: LinearLayout
private lateinit var toolbar: MaterialToolbar
private lateinit var btnPlay: MaterialButton
Expand All @@ -80,6 +83,8 @@ class PlayerActivity : AppCompatActivity() {
private lateinit var btnPip: MaterialButton
private lateinit var btnSpeed: MaterialButton
private lateinit var btnRotate: MaterialButton
private lateinit var btnLock: MaterialButton
private lateinit var btnUnlock: MaterialButton

// Dialogs
private var audioDialog: Dialog? = null
Expand All @@ -88,6 +93,7 @@ class PlayerActivity : AppCompatActivity() {

// States
private var onStopCalled = false
private var controlsLocked = false

// Configs
private var speed = arrayOf("0.25x", "0.5x", "Normal", "1.25x", "1.5x", "2x")
Expand All @@ -105,6 +111,7 @@ class PlayerActivity : AppCompatActivity() {
playerView = binding.playerView

mainControlsRoot = playerView.findViewById(R.id.mainControls)
controlsScrollView = playerView.findViewById(R.id.controlsScrollView)
progressViewGroup = playerView.findViewById(R.id.linearLayout2)
toolbar = playerView.findViewById(R.id.playerToolbar)
btnPlay = playerView.findViewById(R.id.btnPlay)
Expand All @@ -116,6 +123,8 @@ class PlayerActivity : AppCompatActivity() {
btnPip = playerView.findViewById(R.id.btnPip)
btnSpeed = playerView.findViewById(R.id.btnSpeed)
btnRotate = playerView.findViewById(R.id.btnRotate)
btnLock = playerView.findViewById(R.id.btnLock)
btnUnlock = playerView.findViewById(R.id.btnUnlock)

// Back button
toolbar.setNavigationOnClickListener {
Expand Down Expand Up @@ -194,6 +203,16 @@ class PlayerActivity : AppCompatActivity() {
setOrientation(this@PlayerActivity, orientation)
}

btnLock.setOnClickListener {
controlsLocked = true
handleLockingControls()
}

btnUnlock.setOnClickListener {
controlsLocked = false
handleLockingControls()
}

updateOrientation(resources.configuration)
initPlayer()
playMedia()
Expand Down Expand Up @@ -325,6 +344,40 @@ class PlayerActivity : AppCompatActivity() {
.setSeekForwardIncrementMs(10_000)
.setSeekBackIncrementMs(10_000)
.build()

playerView.setControllerVisibilityListener {
if (it == View.VISIBLE) {
handleLockingControls()
}
}

}

private fun handleLockingControls() {
TransitionManager.beginDelayedTransition(
playerView, AutoTransition().apply {
duration = 150L
}
)
if (controlsLocked) {
lockControls()
} else {
unlockControls()
}
}

private fun lockControls() {
controlsScrollView.visibility = View.GONE
mainControlsRoot.visibility = View.GONE
btnUnlock.visibility = View.VISIBLE
toolbar.visibility = View.GONE
}

private fun unlockControls() {
btnUnlock.visibility = View.GONE
toolbar.visibility = View.VISIBLE
controlsScrollView.visibility = View.VISIBLE
mainControlsRoot.visibility = View.VISIBLE
}

private fun releasePlayer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ enum class Orientation(

fun setOrientation(activity: Activity, orientation: Orientation?) {
activity.requestedOrientation = when (orientation) {
Orientation.LANDSCAPE -> SCREEN_ORIENTATION_LANDSCAPE
Orientation.PORTRAIT -> SCREEN_ORIENTATION_PORTRAIT
Orientation.LANDSCAPE -> SCREEN_ORIENTATION_SENSOR_LANDSCAPE
Orientation.PORTRAIT -> SCREEN_ORIENTATION_SENSOR_PORTRAIT
else -> SCREEN_ORIENTATION_FULL_SENSOR
}
}
Expand Down
30 changes: 0 additions & 30 deletions app/src/main/res/drawable-v24/ic_launcher_foreground.xml

This file was deleted.

Loading

0 comments on commit 29299de

Please sign in to comment.