Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ads #101

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

implementation 'com.google.android.gms:play-services-ads:19.3.0'

implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"
implementation "androidx.core:core-ktx:1.3.2"
Expand All @@ -146,6 +148,7 @@ dependencies {

implementation "androidx.dynamicanimation:dynamicanimation-ktx:1.0.0-alpha03"


debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.4'


Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
android:supportsRtl="true"
android:hardwareAccelerated="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3495964067534428~4014718354"/>
<activity
android:name=".SplashScreen"
android:theme="@style/SplashTheme">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ object Constants {
const val CONNECT_PATH = "connection"
const val PROFILE_PATH = "profiles"
const val MEMBERS_PATH = "members"
const val GAMES_PATH = "games"

const val CHARADES_PATH = "charades"
const val WOULD_YOU_RATHER_PATH = "would_you_rather"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2020 - Magnitude Studios - All Rights Reserved
* Unauthorized copying of this file, via any medium is prohibited
* All software is proprietary and confidential
*
*/

package com.magnitudestudios.GameFace.pojo.VideoCall

data class StartGameRequest(
val gameID : String = "",
val version : Int = 0,
val name : String = "",
val senderUID : String = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ package com.magnitudestudios.GameFace.repository

import android.content.Context
import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.work.CoroutineWorker
import androidx.work.ListenableWorker
import androidx.work.Worker
Expand All @@ -40,10 +42,7 @@ import com.magnitudestudios.GameFace.callbacks.RoomCallback
import com.magnitudestudios.GameFace.doOnChildAdded
import com.magnitudestudios.GameFace.pojo.EnumClasses.MemberStatus
import com.magnitudestudios.GameFace.pojo.Helper.Resource
import com.magnitudestudios.GameFace.pojo.VideoCall.EmitMessage
import com.magnitudestudios.GameFace.pojo.VideoCall.IceCandidatePOJO
import com.magnitudestudios.GameFace.pojo.VideoCall.Member
import com.magnitudestudios.GameFace.pojo.VideoCall.SessionInfoPOJO
import com.magnitudestudios.GameFace.pojo.VideoCall.*
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
Expand Down Expand Up @@ -351,4 +350,36 @@ object SessionRepository {
}
}

/**
* Game Server Operations
*/
fun introduceGame(req: StartGameRequest) {
Firebase.database.reference
.child(Constants.ROOMS_PATH)
.child(currentRoom!!)
.child(Constants.GAMES_PATH)
.push()
.setValue(req)
}

fun joinGame(gameID : String) {
Firebase.database.reference
.child(Constants.ROOMS_PATH)
.child(currentRoom!!)
.child(gameID)
.push()
.setValue({Constants.JOINED_KEY to Firebase.auth.currentUser!!.uid})
}

fun listenForNewGames() : LiveData<StartGameRequest> {
val live = MutableLiveData<StartGameRequest>()
Firebase.database.reference.child(Constants.ROOMS_PATH).child(currentRoom!!).child(Constants.GAMES_PATH).doOnChildAdded {
val data = it.getValue(StartGameRequest::class.java)
if (data != null && data.senderUID != Firebase.auth.currentUser!!.uid) {
live.postValue(data!!)
}
}
return live
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2020 - Magnitude Studios - All Rights Reserved
* Unauthorized copying of this file, via any medium is prohibited
* All software is proprietary and confidential
*
*/

package com.magnitudestudios.GameFace.ui.camera

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import androidx.navigation.navGraphViewModels
import com.bumptech.glide.Glide
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.InterstitialAd
import com.magnitudestudios.GameFace.R
import com.magnitudestudios.GameFace.bases.BaseFragment
import com.magnitudestudios.GameFace.databinding.FragmentCallFinishedBinding
import com.magnitudestudios.GameFace.loadProfile
import com.magnitudestudios.GameFace.ui.main.MainViewModel

class CallFinished : BaseFragment() {
lateinit var bind: FragmentCallFinishedBinding
private val viewModel: CameraViewModel by navGraphViewModels(R.id.videoCallGraph)
private lateinit var mainViewModel : MainViewModel
private lateinit var mInterstitialAd: InterstitialAd

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
bind = FragmentCallFinishedBinding.inflate(inflater, container, false)
mainViewModel = requireActivity().run { ViewModelProvider(this).get(MainViewModel::class.java) }!!
mInterstitialAd = InterstitialAd(requireContext())
mInterstitialAd.adUnitId = getString(R.string.interstitial_after_calling)
mInterstitialAd.loadAd(AdRequest.Builder().build())

val callback: OnBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
goToHome()
}
}
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback)
return bind.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val adRequest = AdRequest.Builder().build()
bind.bannerAfterCall.loadAd(adRequest)
mInterstitialAd.show()

viewModel.members.observe(viewLifecycleOwner, Observer { mutableList ->
if (mutableList.isNullOrEmpty()) {
bind.membersNames.text = mainViewModel.profile.value?.data?.username
Glide.with(this).loadProfile(mainViewModel.profile.value?.data?.profilePic, bind.profilePic)
}
else {
bind.membersNames.text = mutableList.mapNotNull { it.profile?.username }.joinToString(", ")
Glide.with(this).loadProfile(mutableList[0].profile?.profilePic, bind.profilePic)
}
})

bind.goHome.setOnClickListener {
goToHome()
}
}
private fun goToHome() {
findNavController().popBackStack(R.id.bottomContainerFragment, false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import android.view.ViewGroup
import android.view.WindowManager
import android.widget.FrameLayout
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
Expand All @@ -50,6 +51,7 @@ import kotlinx.coroutines.launch
import org.webrtc.*
import java.util.concurrent.ConcurrentHashMap


/**
* Camera fragment
*
Expand Down Expand Up @@ -92,14 +94,19 @@ class CameraFragment : BaseFragment(), View.OnClickListener {
ViewModelProvider(this).get(MainViewModel::class.java)
}!!
rootEglBase = EglBase.create()

val callback: OnBackPressedCallback = object : OnBackPressedCallback(true /* enabled by default */) {
override fun handleOnBackPressed() {}
}
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback)
return bind.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
requireActivity().window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

bind.localVideo.initialize(eglBase = rootEglBase, overlay = true, onTop = true)
bind.localVideo.initialize(eglBase = rootEglBase, overlay = true, onTop = false)

audioManager = context?.getSystemService(Context.AUDIO_SERVICE) as AudioManager
audioManager.isSpeakerphoneOn = true
Expand All @@ -119,7 +126,7 @@ class CameraFragment : BaseFragment(), View.OnClickListener {
bind.callingControls.animate().setDuration(5000).alpha(0f)
}
}
bind.callingControls.setOnClickListener {Log.e("CLICKED","CLICKED")}
bind.callingControls.setOnClickListener {Log.e("CLICKED", "CLICKED")}

bind.addMember.setOnClickListener {
findNavController().navigate(R.id.action_cameraFragment_to_addMembersDialog)
Expand Down Expand Up @@ -150,7 +157,7 @@ class CameraFragment : BaseFragment(), View.OnClickListener {

private fun observeConnection() {
viewModel.connectionStatus.observe(viewLifecycleOwner, Observer {
when(it.status) {
when (it.status) {
Status.ERROR -> connectionFailed(it.message)
Status.LOADING -> setLoading(true)
else -> setLoading(false)
Expand Down Expand Up @@ -188,8 +195,7 @@ class CameraFragment : BaseFragment(), View.OnClickListener {
if (it != null) {
if (args.roomID.isNotEmpty()) {
viewModel.joinRoom(args.roomID)
}
else if (args.callUserUID.isNotEmpty()) {
} else if (args.callUserUID.isNotEmpty()) {
viewModel.createRoom(args.callUserUID)
}
}
Expand Down Expand Up @@ -332,7 +338,7 @@ class CameraFragment : BaseFragment(), View.OnClickListener {
}


private fun gotPeerStream(peerUID: String, stream: MediaStream ) {
private fun gotPeerStream(peerUID: String, stream: MediaStream) {
Log.e(TAG, "gotRemoteStream: " + "GOT REMOTE STREAM")
//we have remote video stream. add to the renderer.
activity?.runOnUiThread {
Expand Down Expand Up @@ -394,7 +400,7 @@ class CameraFragment : BaseFragment(), View.OnClickListener {
e.printStackTrace()
}
if (userDefined) {
findNavController().popBackStack()
findNavController().navigate(R.id.action_cameraFragment_to_callFinished)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import androidx.lifecycle.*
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager
import androidx.work.workDataOf
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.ktx.FirebaseAuthKtxRegistrar
import com.google.firebase.auth.ktx.auth
import com.google.firebase.ktx.Firebase
import com.google.gson.Gson
Expand All @@ -39,6 +41,7 @@ import com.magnitudestudios.GameFace.notifyObserver
import com.magnitudestudios.GameFace.pojo.EnumClasses.MemberStatus
import com.magnitudestudios.GameFace.pojo.EnumClasses.Status
import com.magnitudestudios.GameFace.pojo.Helper.Resource
import com.magnitudestudios.GameFace.pojo.UserInfo.LocalPackInfo
import com.magnitudestudios.GameFace.pojo.VideoCall.*
import com.magnitudestudios.GameFace.repository.SessionRepository
import com.magnitudestudios.GameFace.repository.UserRepository
Expand Down Expand Up @@ -100,6 +103,8 @@ class CameraViewModel(application: Application) : AndroidViewModel(application),
emit(tempIceServers)
}

val newGame = MutableLiveData<StartGameRequest>()

/**
* Add peer
*
Expand Down Expand Up @@ -288,4 +293,20 @@ class CameraViewModel(application: Application) : AndroidViewModel(application),
}


/**
* Game Functions
*/

fun sendGameRequest(req : LocalPackInfo) {
SessionRepository.introduceGame(StartGameRequest(req.id, req.version, req.name, Firebase.auth.currentUser!!.uid))
}

fun onNewGame(startGameRequest: StartGameRequest) {
newGame.value = startGameRequest
}

fun joinGame(gameID : String) {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.NavDestination
import androidx.navigation.findNavController
import com.google.android.gms.ads.MobileAds
import com.magnitudestudios.GameFace.Constants
import com.magnitudestudios.GameFace.R
import com.magnitudestudios.GameFace.bases.BasePermissionsActivity
Expand All @@ -49,6 +50,7 @@ class MainActivity : BasePermissionsActivity() {
private lateinit var viewModel: MainViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
MobileAds.initialize(this) {}
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
viewModel = ViewModelProvider(this)[MainViewModel::class.java]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.magnitudestudios.GameFace.callbacks.RVButtonClick
import com.magnitudestudios.GameFace.databinding.FragmentShopBinding
import com.magnitudestudios.GameFace.databinding.ItemShowcaseBinding
import com.magnitudestudios.GameFace.ui.BottomContainerFragmentDirections
import com.magnitudestudios.GameFace.ui.shop.tabs.EarnFragment
import com.magnitudestudios.GameFace.ui.shop.tabs.InstalledFragment
import com.magnitudestudios.GameFace.ui.shop.tabs.MarketFragment
import com.magnitudestudios.GameFace.views.ShowCaseItemViewHolder
Expand Down Expand Up @@ -120,9 +121,8 @@ class ShopFragment : BaseFragment() {
val fragment = when (position) {
0 -> MarketFragment()
1 -> InstalledFragment()
// 1 -> FriendsFragment()
// 2 -> FriendRequestsFragment()
else -> MarketFragment()
2 -> EarnFragment()
else -> throw IllegalStateException("Unknown Fragment Position: $position")
}
childFragmentManager.beginTransaction().replace(R.id.shopContainer, fragment).setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).commit()
}
Expand Down
Loading