Skip to content
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
95 changes: 91 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,55 @@ apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

apply plugin: 'realm-android'
apply plugin: "jacoco"

jacoco {
toolVersion = "0.8.4"
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
}
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {

reports {
xml.enabled = true
html.enabled = true
}
def fileFilter = ['**/*.html','**/*.css',
'**/*.png','**/*.jpg','**/*.JPG',
'**/io/ionic*','**/io/ionic**','**/io/ionic**/*.class',
'**/org/*','**/org/**','**/org/**/*.class','**/cordova/*','**/cordova/**','**/cordova/**/*.class',
'**/android/*','**/android/**','**/android/**/*.class','**/apache/commons/**','**/io/realm/**',
'**/com/mikhaellopez/**','**/io/michaelrocks/**','**/io/michaelrocks/**','**/org/apache/**',
'**/databinding/**/*.*',
'**/android/databinding/*Binding.*',
'**/*_ViewBinding*/**/*.class',
'**/*_ViewBinding*/**/*.java',
'**/BR.*',
'**/R.*',
'**/R$*.*',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*_MembersInjector.*',
'**/Dagger*Component.*',
'**/Dagger*Component$Builder.*',
'**/*Module_*Factory.*',
'**/*ParcelConverter.java',
'**/*Parcelable.*',
'**/*_Factory*.*',
'**/*Parcelable*.*',
'**/*_ViewBinding*.*']

def debugTree = fileTree(dir: "${buildDir}/intermediates/javac/debug", excludes: fileFilter)
def mainSrc = fileTree(dir: "${project.projectDir}/src/main/java/com/example/go_git", excludes: fileFilter)

sourceDirectories = files([mainSrc])
classDirectories = files([debugTree])
executionData = fileTree(dir: "$buildDir", includes: [
"jacoco/testDebugUnitTest.exec",
"outputs/code-coverage/connected/*coverage.ec"
])
}
android {
compileSdkVersion 29
buildToolsVersion "29.0.0"
Expand All @@ -17,15 +65,25 @@ android {
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
debug {
testCoverageEnabled = true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
testOptions.unitTests.includeAndroidResources = true

}
def vectordrawable_version = "1.1.0"

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
Expand All @@ -34,14 +92,43 @@ dependencies {
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.google.android.material:material:1.0.0'
implementation 'io.realm:android-adapters:3.1.0'


implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3"

implementation 'org.koin:koin-android:2.0.1'
implementation "org.koin:koin-android-architecture:0.9.1"

implementation "androidx.vectordrawable:vectordrawable:$vectordrawable_version"
/* To be able to animate properties of a VectorDrawable, add the following. Useful for
* illustration purposes or state changes in response to user events
*/
implementation "androidx.vectordrawable:vectordrawable-animated:$vectordrawable_version"

androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

testImplementation group: 'org.mockito', name: 'mockito-inline', version: '2.9.0'
testImplementation 'org.powermock:powermock-api-mockito2:2.0.2'
testImplementation 'org.powermock:powermock-core:2.0.2'
testImplementation 'org.powermock:powermock-module-junit4-rule:2.0.2'
testImplementation 'org.powermock:powermock-module-junit4:2.0.2'
testImplementation 'org.powermock:powermock-classloading-xstream:2.0.2'
implementation 'io.reactivex.rxjava2:rxjava:2.2.16' // had to add this library to support flowable converters for robolectric

testImplementation "org.robolectric:robolectric:4.3.1"
testImplementation 'com.github.nimbl3:robolectric.shadows-supportv4:4.1-SNAPSHOT'





implementation 'com.squareup.moshi:moshi:1.8.0'
kapt 'com.squareup.moshi:moshi-kotlin-codegen:1.8.0'
}
8 changes: 6 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
package="com.aks4125.gorealm">

<application
android:name=".MyApp"
android:allowBackup="true"
android:fullBackupContent="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".ui.EmployeeActivity"></activity>
<activity android:name=".ui.company.AddCompanyActivity" />
<activity
android:name=".ui.main.MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
Expand Down
18 changes: 0 additions & 18 deletions app/src/main/java/com/aks4125/gorealm/CompanyModel.kt

This file was deleted.

17 changes: 0 additions & 17 deletions app/src/main/java/com/aks4125/gorealm/MainActivity.kt

This file was deleted.

35 changes: 35 additions & 0 deletions app/src/main/java/com/aks4125/gorealm/MyApp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.aks4125.gorealm

import android.app.Application
import com.aks4125.gorealm.di.applicationModule
import io.realm.Realm
import io.realm.RealmConfiguration
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.startKoin

class MyApp : Application() {

override fun onCreate() {
super.onCreate()

//koin configuration
startKoin {
androidLogger()
androidContext(this@MyApp)
modules(listOf(applicationModule)) //will add more modules later on
}

// realm configuration
Realm.init(this)
Realm.setDefaultConfiguration(
RealmConfiguration.Builder()
.name("companies")
.deleteRealmIfMigrationNeeded()
.schemaVersion(2)
.compactOnLaunch().build()
)


}
}
144 changes: 144 additions & 0 deletions app/src/main/java/com/aks4125/gorealm/adapter/CompanyAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package com.aks4125.gorealm.adapter

import android.content.Context
import android.content.Intent
import android.graphics.drawable.AnimatedVectorDrawable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Filter
import android.widget.Filterable
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
import com.aks4125.gorealm.R
import com.aks4125.gorealm.model.CompanyModel
import com.aks4125.gorealm.ui.EmployeeActivity
import com.aks4125.gorealm.utils.GoConstants.Companion.FIELD_ID
import kotlinx.android.synthetic.main.list_item_company.view.*


class CompanyAdapter(val context: Context, private val modelList: MutableList<CompanyModel>) :
RecyclerView.Adapter<CompanyAdapter.CompanyHolder>(), Filterable {
var filterList = modelList

private val customFilter: Filter = object : Filter() {
override fun performFiltering(constraint: CharSequence): FilterResults {
filterList =
modelList.filter {
it.name!!.contains(constraint, true)
}.toMutableList()



return FilterResults().apply {
values = filterList
count = filterList.size
}
}

override fun publishResults(constraint: CharSequence, results: FilterResults) {
notifyDataSetChanged()
}
}

override fun getFilter(): Filter = customFilter
override fun getItemCount() = filterList.size

/**
* diffutils to submit updates
*/
fun notifyChanges(oldList: MutableList<CompanyModel>, newList: MutableList<CompanyModel>) {
val diff = DiffUtil.calculateDiff(object : DiffUtil.Callback() {
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
return oldList[oldItemPosition].id == newList[newItemPosition].id
}

override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
return oldList[oldItemPosition] == newList[newItemPosition]
}

override fun getOldListSize() = oldList.size
override fun getNewListSize() = newList.size
})
diff.dispatchUpdatesTo(this)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CompanyHolder {
return CompanyHolder(
LayoutInflater.from(parent.context)
.inflate(R.layout.list_item_company, parent, false)
)
}

override fun onBindViewHolder(holder: CompanyHolder, position: Int) {
holder.bind(filterList[position])
}

fun updateList(mList: MutableList<CompanyModel>) {
with(filterList) {
clear()
addAll(mList)
notifyDataSetChanged()
}
}

var onItemClick: ((CompanyModel) -> Unit)? = null

inner class CompanyHolder(view: View) : RecyclerView.ViewHolder(view) {

private val name = view.name
private val tvEmpCount = view.tvEmpCount
private val tvAddress = view.tvAddress
private val btnClaps = view.btnClaps
private val imgHeart = view.imageHeart
private val emptyView = view.emptyView
private var mVector: AnimatedVectorDrawable? = null
private var mVectorCompat: AnimatedVectorDrawableCompat? = null
private val mParent = view.mParent


fun bind(data: CompanyModel) {
if (adapterPosition == itemCount - 1)
emptyView.visibility = View.VISIBLE
else
emptyView.visibility = View.GONE


name.text = data.name
tvEmpCount.text = itemView.context.getString(R.string.total_emp, data.empCount)
tvAddress.text = data.address
btnClaps.text = data.claps.toString()

val heartDrawable = imgHeart.drawable

btnClaps.setOnClickListener {
//RealmRecyclerViewAdapter alternative but requires managed objects
filterList[adapterPosition].claps = filterList[adapterPosition].claps!! + 1
notifyItemChanged(adapterPosition)
onItemClick?.invoke(filterList[adapterPosition])

imgHeart.alpha = 0.75f
if (heartDrawable is AnimatedVectorDrawable) {
mVector = heartDrawable
mVector?.start()
} else if (heartDrawable is AnimatedVectorDrawableCompat) {
mVectorCompat = heartDrawable
mVectorCompat?.start()
}

}
mParent.setOnClickListener {
context.startActivity(
Intent(
context,
EmployeeActivity::class.java
).putExtra(FIELD_ID, filterList[adapterPosition].id)
)
}


}
}

}
Loading