Skip to content

Commit

Permalink
Merge pull request #1 from moazmahdy/habdbranch
Browse files Browse the repository at this point in the history
Habdbranch
  • Loading branch information
moazmahdy authored Feb 1, 2023
2 parents 481cc1e + 4578df0 commit d27b28d
Show file tree
Hide file tree
Showing 90 changed files with 1,977 additions and 168 deletions.
2 changes: 2 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 43 additions & 11 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,55 @@ buildToolsVersion '30.0.3'

dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'com.google.android.material:material:1.7.0'
implementation 'com.google.firebase:firebase-common-ktx:20.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
def lifecycle_version = "2.2.0"
def nav_version = "2.1.0-alpha02"

implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
// ViewModel and LiveData
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"

// alternatively - just LiveData
implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"

// optional - ReactiveStreams support for LiveData
implementation "androidx.lifecycle:lifecycle-reactivestreams-ktx:$lifecycle_version"


testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

implementation platform('com.google.firebase:firebase-bom:31.1.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-auth-ktx'

implementation 'com.google.android.material:material:1.7.0'
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

// alternatively - just ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"

implementation "androidx.core:core-ktx:1.9.0"
implementation "androidx.appcompat:appcompat:1.6.0"
implementation "androidx.fragment:fragment:1.6.0-alpha04"
implementation "androidx.fragment:fragment-ktx:1.6.0-alpha04"

// Firebase
implementation platform('com.google.firebase:firebase-bom:31.1.1')

implementation "com.google.firebase:firebase-core:21.1.1"
implementation "com.google.firebase:firebase-database:20.1.0"
implementation "com.google.firebase:firebase-firestore:24.4.2"
implementation "com.google.firebase:firebase-auth:21.1.0"
implementation "com.google.firebase:firebase-storage:20.1.0"
implementation "com.google.firebase:firebase-messaging:23.1.1"
implementation 'com.google.firebase:firebase-firestore-ktx'
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-auth-ktx:21.1.0'
implementation 'com.google.android.gms:play-services-auth:20.4.1'


var lifecycle_version = "2.5.1"
//calender
implementation 'com.github.prolificinteractive:material-calendarview:2.0.0'

// ViewModel
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version")
// LiveData
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version")
}
24 changes: 15 additions & 9 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,39 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.example.workingtimerv2">

<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:icon="@drawable/timer_ic"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:roundIcon="@drawable/timer_ic"
android:supportsRtl="true"
android:theme="@style/Theme.WorkingTimerV2"
tools:targetApi="31">
<activity
android:name=".ui.home.HomeActivity"
android:name=".ui.manager.ManagerActivity"
android:exported="false" />
<activity
android:name=".ui.login.LoginActivity"
android:exported="false" />
<activity
android:name=".ui.employee.EmployeeActivity"
android:exported="false" />
<activity
android:name=".ui.register.RegisterActivity"
android:exported="true" >
android:exported="false" />
<activity
android:name=".ui.splash.SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.splash.SplashActivity"
android:exported="true">

</activity>
</application>

</manifest>
10 changes: 10 additions & 0 deletions app/src/main/java/com/example/workingtimerv2/Constants.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.workingtimerv2

object Constants {

const val EXTRA_ROOM = "user"

const val SALARY_BER_HOUR = 100

const val MANAGER_ID= "wxnWB4aQCdXHYMHp1Wtvp9fOi9J2"
}
8 changes: 6 additions & 2 deletions app/src/main/java/com/example/workingtimerv2/DataUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import com.example.workingtimerv2.model.AppUser
import com.google.firebase.firestore.auth.User

object DataUtils {

var user: AppUser? = null
var firebaseUser: User? = null
}
}

//object AppName {
// var userName = DataUtils.user?.name
//}

13 changes: 13 additions & 0 deletions app/src/main/java/com/example/workingtimerv2/MyApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.workingtimerv2

import android.app.Application
import com.google.firebase.ktx.Firebase
import com.google.firebase.ktx.initialize

class MyApplication:Application() {

override fun onCreate() {
super.onCreate()
Firebase.initialize(this)
}
}
47 changes: 34 additions & 13 deletions app/src/main/java/com/example/workingtimerv2/base/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding

open abstract class BaseActivity<DB: ViewDataBinding , VM: BaseViewModel<*>>: AppCompatActivity() {
abstract class BaseActivity<DB: ViewDataBinding, VM: BaseViewModel<*>>: AppCompatActivity() {

lateinit var viewModel:VM
// Variables to hold the viewmodel and viewdatabinding instances
lateinit var viewModel: VM
lateinit var viewDataBinding: DB

// Overriding the onCreate method to set the content view, initialize the viewmodel and subscribe to live data
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
viewDataBinding = DataBindingUtil.setContentView(this,getLayoutId())
viewDataBinding = DataBindingUtil.setContentView(this, getLayoutId())
viewModel = initViewModel()
subscribeToLiveData()
}

// Method to subscribe to live data and update the UI accordingly
fun subscribeToLiveData(){
viewModel.messageLiveData.observe(this) {
showDialog(it)
Expand All @@ -31,39 +34,57 @@ open abstract class BaseActivity<DB: ViewDataBinding , VM: BaseViewModel<*>>: Ap
}
}

// Variable to hold the alert dialog
var alertDialog : AlertDialog?= null
fun showDialog(message: String,
posActionName:String? = null, posAction: DialogInterface.OnClickListener?=null,
negActionName:String? = null, negAction: DialogInterface.OnClickListener?=null,
cancelable : Boolean = true){

// Method to show a dialog with given message, positive and negative action buttons, and cancelability
private fun showDialog(
message: String,
posActionName: String? = null, posAction: DialogInterface.OnClickListener? = null,
negActionName: String? = null, negAction: DialogInterface.OnClickListener? = null,
cancelable: Boolean = true
) {

// Default action to dismiss the dialog
val defAction = DialogInterface.OnClickListener { dialog, which -> dialog!!.dismiss() }

// Creating the dialog builder with the given message
val builder = AlertDialog.Builder(this).setMessage(message)
if (posActionName!=null) builder.setPositiveButton(posActionName, posAction ?: defAction)
if (negActionName!=null) builder.setPositiveButton(negActionName, negAction ?: defAction)

if (posActionName != null) builder.setPositiveButton(posActionName, posAction ?: defAction)

if (negActionName != null) builder.setPositiveButton(negActionName, negAction ?: defAction)

// Setting the cancellability of the dialog
builder.setCancelable(cancelable)

// Showing the dialog
alertDialog = builder.show()
}

// Method to hide the dialog
fun hideDialog(){
alertDialog?.dismiss()
alertDialog = null
}


// Variable to hold the progress dialog
var progressDialog: ProgressDialog? = null

// Method to show the loading progress dialog
fun showLoading(){
progressDialog = ProgressDialog(this)
progressDialog?.setMessage("Loading....")
progressDialog?.setCancelable(false)
progressDialog?.show()
}

// Method to hide the loading progress dialog
fun hideLoading(){
progressDialog?.dismiss()
progressDialog = null
}

abstract fun getLayoutId():Int
abstract fun initViewModel():VM
}
abstract fun getLayoutId(): Int
abstract fun initViewModel(): VM
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.example.workingtimerv2.model.AppUser
import com.google.android.gms.tasks.OnFailureListener
import com.google.android.gms.tasks.OnSuccessListener
import com.google.firebase.firestore.CollectionReference
import com.google.firebase.firestore.DocumentSnapshot
import com.google.firebase.firestore.QuerySnapshot
import com.google.firebase.firestore.ktx.firestore
import com.google.firebase.ktx.Firebase

Expand All @@ -20,4 +22,23 @@ fun addUserToFirestore(user: AppUser,
userDoc.set(user)
.addOnSuccessListener(onSuccessListener)
.addOnFailureListener(onFailureListener)
}
fun signIn(uid: String,
onSuccessListener: OnSuccessListener<DocumentSnapshot>,
onFailureListener: OnFailureListener
){
val db = Firebase.firestore
val userCollection = db.collection(AppUser.COLLECTION_NAME)
userCollection.document(uid)
.get()
.addOnSuccessListener(onSuccessListener)
.addOnFailureListener(onFailureListener)
}

fun getUsers(onSuccessListener: OnSuccessListener<QuerySnapshot>,
onFailureListener: OnFailureListener){
val collection = getCollection(AppUser.COLLECTION_NAME)
collection.get()
.addOnSuccessListener(onSuccessListener)
.addOnFailureListener(onFailureListener)
}
16 changes: 11 additions & 5 deletions app/src/main/java/com/example/workingtimerv2/model/AppUser.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package com.example.workingtimerv2.model

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
data class AppUser(
var id: String? = null,
var name: String? = null,
val email: String?= null
)
{
companion object{
val email: String? = null,
var yesterday: Long? = 0L,
var week: Long? = 0L,
var month: Long? = 0L
) : Parcelable {
companion object {
const val COLLECTION_NAME = "users"
}
}
}
Loading

0 comments on commit d27b28d

Please sign in to comment.