Skip to content

Commit

Permalink
Merge pull request #178 from eddyspaghette/documentation
Browse files Browse the repository at this point in the history
add documentation, optimizez some imports
  • Loading branch information
Khoality-dev authored Aug 9, 2022
2 parents 96a6672 + 0f8532c commit 680daf2
Show file tree
Hide file tree
Showing 22 changed files with 52 additions and 21 deletions.
13 changes: 11 additions & 2 deletions app/src/main/java/com/AERYZ/treasurefind/db/MyFirebase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import com.google.firebase.ktx.Firebase
import com.google.firebase.storage.ktx.storage
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.ByteArrayOutputStream
import java.lang.Exception
import java.util.*
import kotlin.concurrent.schedule

/* Custom objects used to store and retrieve from Firestore */

data class MyUser(
var uid: String = "",
var userName: String = "",
Expand Down Expand Up @@ -73,6 +73,10 @@ class MyFirebase {
private var db = Firebase.firestore
private var storageReference = storage.reference

/* These interface listeners are used for callbacks, since most firebase operations
are asynchronous
*/

interface FirebaseFeedListener {
fun onSuccess(snapshot: QuerySnapshot)
fun onFailure(exception: Exception)
Expand Down Expand Up @@ -107,6 +111,11 @@ class MyFirebase {
fun onFailure(exception: Exception)
}

/* Wrapper functions for Firestore and FireStorage,
most of them include a listener to provide a
callback once data is retrieved
*/

fun getAllTreasures(listener: FirebaseFeedListener) {
db.collection("treasures")
.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.MutableLiveData

/* Camera functionality so we can call it from within other activities easily */
class CameraModule(activity: FragmentActivity, var CameraOutputBitmap: MutableLiveData<Bitmap>) {
private var cameraResultListener: ActivityResultLauncher<Intent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.google.android.gms.maps.model.Marker
import com.google.firebase.firestore.ktx.toObject
import com.mikhaellopez.circularimageview.CircularImageView


/* Info Window for markers on SeekerMap and HiderMap */
class MyInfoWindowAdapter(var activity: Activity,
var seekers: HashMap<String,MutableLiveData<MyUser>>,
var seekersImage: HashMap<String,MutableLiveData<Bitmap>>): GoogleMap.InfoWindowAdapter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.view.View
import android.view.View.OnTouchListener
import kotlin.math.abs

/* Swipe gestures implemented for HiderMap activity */
internal open class OnSwipeTouchListener(c: Context?) :
OnTouchListener {
private val gestureDetector: GestureDetector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class LoginActivity : AppCompatActivity(), MyFirebase.UserInsertionListener {
}
}

/* Send them to the Onboarding activity if they are a new user */

override fun onSuccess() {
val intent = Intent(applicationContext, OnboardingActivity::class.java)
startActivity(intent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.AERYZ.treasurefind.main.services.TrackingService

open class ServiceViewModel:ViewModel(),ServiceConnection {
open class ServiceViewModel:ViewModel(), ServiceConnection {
private var myMessageHandler = MyMessageHandler(Looper.getMainLooper())
private val _location=MutableLiveData<Location>()
val location:LiveData<Location>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.AERYZ.treasurefind.R

class ProgressDialog {

/* Progress Dialog shows an uploading spinner until dismissed */
companion object {
fun progressDialog(context: Context): Dialog {
val dialog = Dialog(context)
Expand All @@ -19,6 +20,8 @@ class ProgressDialog {
return dialog
}

/* Success dialog has to be played for 2.4 seconds for animation to be finished
use with TimerTask */
fun successDialog(context: Context): Dialog {
val dialog = Dialog(context)
val view = LayoutInflater.from(context).inflate(R.layout.dialog_success, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.widget.ImageView
import com.AERYZ.treasurefind.R

class TimerDialog {
/* Show a timer animated vector drawable */
companion object {
fun clockDialog(context: Context): Dialog {
val dialog = Dialog(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import com.AERYZ.treasurefind.db.MyFirebase
import com.AERYZ.treasurefind.db.Treasure
import com.AERYZ.treasurefind.main.entry_point.MainActivity

/*
The FeedFragment is responsible for providing access and information
about the treasures
*/
class FeedFragment : Fragment(), MenuProvider {

private var _binding: FragmentFeedBinding? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class FeedViewModel(private val activity: FragmentActivity): ViewModel(), MyFire

init {
// this retrieves all documents in the treasure collection
// fires off a callback once it is ready
myFirebase.getAllTreasures(this)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import com.firebase.ui.storage.images.FirebaseImageLoader
import com.google.firebase.storage.StorageReference
import java.io.InputStream

/* The Glide Library is used to manipulate images from references found in
Firebase; usages include Caching, Downloading, and inserting them into ImageViews.
*/
@GlideModule
class MyAppGlideModule: AppGlideModule() {
override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.view.View
import android.view.ViewGroup
import com.AERYZ.treasurefind.R

/* Hider is redirected here once he is finished */
class HiderDoneFragment : Fragment() {

override fun onCreateView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.firestore.ktx.toObject
import java.lang.Exception

/* Entry point for the Hider once he starts a session */
class HiderMapActivity : AppCompatActivity(), OnMapReadyCallback, MyFirebase.ImageGetListener {

private lateinit var mMap: GoogleMap
Expand Down Expand Up @@ -303,10 +304,12 @@ class HiderMapActivity : AppCompatActivity(), OnMapReadyCallback, MyFirebase.Ima
}
}

/* This function is used as a callback once getProfileImage returns */
override fun onSuccess() {
mapViewModel.seekers_size.postValue(mapViewModel.seekers_size.value?.plus(1))
}

/* Part of the listener interface callback as above */
override fun onFailure(exception: Exception) {
//TODO("Not yet implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import com.google.firebase.firestore.ktx.toObject
import com.mikhaellopez.circularimageview.CircularImageView


/*
* Hider handles the submit requests from Seekers here
* Hider can determine a winner or swipe to see other submit requests
*/
class HiderValidateFragment : Fragment() {
private lateinit var viewModel: HiderMapViewModel
private lateinit var viewModelFactory: HiderMapViewModelFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import com.AERYZ.treasurefind.main.util.Util
import com.google.firebase.auth.FirebaseAuth
import java.lang.Exception

/*
* Hider place is where users can upload a image to create a session
*/
class HiderPlaceFragment : Fragment(), MyFirebase.TreasureInsertionListener {
private lateinit var viewModel: HiderPlaceViewModel
private lateinit var titleEditText: EditText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Context
import android.util.AttributeSet
import android.view.TextureView

/* Live camera for all seekers that need to upload */
class AutoFitTextureView @JvmOverloads constructor(
context: Context?,
attrs: AttributeSet? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.ktx.Firebase
import com.mikhaellopez.circularimageview.CircularImageView

/* User profile is stored here, the found and own treasures have their own fragments*/
class ProfileFragment : Fragment() {
private lateinit var viewModel: ProfileViewModel
private lateinit var modelFactory: ProfileFragmentViewModelFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.random.Random

/*
* Seeker is redirected here once they accept a treasure session
*/
class SeekerMapActivity : AppCompatActivity(), OnMapReadyCallback, MyFirebase.ImageGetListener {

private lateinit var mMap: GoogleMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import kotlinx.coroutines.launch
import java.util.*
import kotlin.concurrent.schedule


/* Submit fragment for the bottom sheet */
@SuppressLint("ClickableViewAccessibility")
class SeekerSubmitFragment : Fragment(), ImageReader.OnImageAvailableListener {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import android.view.View
import android.view.ViewGroup
import com.AERYZ.treasurefind.R


/* Loading screen once submit request is sent */
class SeekerWaitFragment : Fragment() {


Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
package com.AERYZ.treasurefind.main.ui.treasuredetails

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModelProvider
import com.AERYZ.treasurefind.R
import com.AERYZ.treasurefind.db.MyFirebase
import com.AERYZ.treasurefind.db.Treasure
import com.AERYZ.treasurefind.main.ui.dialogs.ProgressDialog
import com.AERYZ.treasurefind.main.ui.dialogs.TimerDialog
import com.AERYZ.treasurefind.main.ui.feed.FeedFragment
import com.AERYZ.treasurefind.main.ui.hider_map.HiderMapActivity
import com.AERYZ.treasurefind.main.ui.seeker_map.SeekerMapActivity
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.ktx.Firebase
import java.lang.Exception

/*
* Once a user clicks on a treasure in the FeedPage, they are redirected here
*/
class TreasureDetailsActivity : AppCompatActivity() {

private var myFirebase = MyFirebase()
Expand Down
8 changes: 1 addition & 7 deletions app/src/main/java/com/AERYZ/treasurefind/main/util/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import android.content.pm.PackageManager
import android.content.res.Resources
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Color
import android.graphics.Matrix
import android.location.Criteria
import android.location.Location
Expand All @@ -20,22 +19,17 @@ import android.util.DisplayMetrics
import android.util.Log
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.getSystemService
import com.android.volley.Response
import com.android.volley.toolbox.StringRequest
import com.android.volley.toolbox.Volley
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.MarkerOptions
import com.google.android.gms.maps.model.Polyline
import com.google.android.gms.maps.model.PolylineOptions
import com.google.maps.android.PolyUtil
import org.json.JSONObject
import java.lang.Math.pow
import java.lang.Math.sqrt
import kotlin.math.pow

/* Utility functions exist here, such as permissions and other misc functions*/
object Util {
fun checkPermissions(activity: Activity?) {
if (Build.VERSION.SDK_INT < 23) return
Expand Down

0 comments on commit 680daf2

Please sign in to comment.