-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from digitalHorizonsCo/develop
Develop
- Loading branch information
Showing
11 changed files
with
334 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
plugins { | ||
id 'com.android.library' | ||
id 'org.jetbrains.kotlin.android' | ||
} | ||
|
||
android { | ||
namespace 'com.digitalhorizons.common' | ||
compileSdk 34 | ||
|
||
defaultConfig { | ||
minSdk 21 | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles "consumer-rules.pro" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
viewBinding{ | ||
enabled = true | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation 'androidx.core:core-ktx:1.12.0' | ||
implementation platform('org.jetbrains.kotlin:kotlin-bom:1.8.0') | ||
implementation 'androidx.appcompat:appcompat:1.6.1' | ||
implementation 'com.google.android.material:material:1.11.0' | ||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.5' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
39 changes: 39 additions & 0 deletions
39
common/src/main/java/com/digitalhorizons/common/binding/ActivityBinding.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.digitalhorizons.common.binding | ||
|
||
|
||
import android.app.Activity | ||
import android.view.LayoutInflater | ||
import androidx.viewbinding.ViewBinding | ||
import kotlin.properties.ReadOnlyProperty | ||
import kotlin.reflect.KProperty | ||
|
||
inline fun <reified T : ViewBinding> Activity.viewBinding() = | ||
ActivityViewBindingDelegate(T::class.java) | ||
|
||
class ActivityViewBindingDelegate<T : ViewBinding>(private val bindingClass: Class<T>) : | ||
ReadOnlyProperty<Activity, T> { | ||
/** | ||
* initiate variable for binding view | ||
*/ | ||
private var binding: T? = null | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
override fun getValue(thisRef: Activity, property: KProperty<*>): T { | ||
binding?.let { return it } | ||
|
||
/** | ||
* inflate View class | ||
*/ | ||
val inflateMethod = bindingClass.getMethod("inflate", LayoutInflater::class.java) | ||
|
||
/** | ||
* Bind layout | ||
*/ | ||
val invokeLayout = inflateMethod.invoke(null, thisRef.layoutInflater) as T | ||
|
||
/** | ||
* Set the content view | ||
*/ | ||
return invokeLayout.also { this.binding = it } | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
common/src/main/java/com/digitalhorizons/common/binding/FragmentBinding.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.digitalhorizons.common.binding | ||
|
||
import android.view.View | ||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.DefaultLifecycleObserver | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.viewbinding.ViewBinding | ||
import kotlin.properties.ReadOnlyProperty | ||
import kotlin.reflect.KProperty | ||
|
||
inline fun <reified T : ViewBinding> Fragment.viewBinding() = | ||
FragmentViewBindingDelegate(T::class.java, this) | ||
|
||
class FragmentViewBindingDelegate<T : ViewBinding>( | ||
bindingClass: Class<T>, | ||
private val fragment: Fragment | ||
) : ReadOnlyProperty<Fragment, T> { | ||
|
||
/** | ||
* initiate variable for binding view | ||
*/ | ||
private var binding: T? = null | ||
|
||
/** | ||
* get the bind method from View class | ||
*/ | ||
private val bindMethod = bindingClass.getMethod("bind", View::class.java) | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
override fun getValue(thisRef: Fragment, property: KProperty<*>): T { | ||
binding?.let { return it } | ||
|
||
/** | ||
* Adding observer to the fragment lifecycle | ||
*/ | ||
fragment.lifecycle.addObserver(object : DefaultLifecycleObserver { | ||
override fun onCreate(owner: LifecycleOwner) { | ||
fragment.viewLifecycleOwnerLiveData.observe(fragment) { viewLifecycleOwner -> | ||
viewLifecycleOwner.lifecycle.addObserver(object : DefaultLifecycleObserver { | ||
override fun onDestroy(owner: LifecycleOwner) { | ||
/** | ||
* Clear the binding when Fragment lifecycle called the onDestroy | ||
*/ | ||
binding = null | ||
} | ||
}) | ||
} | ||
} | ||
}) | ||
|
||
|
||
/** | ||
* Checking the fragment lifecycle | ||
*/ | ||
val lifecycle = fragment.viewLifecycleOwner.lifecycle | ||
if (!lifecycle.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) { | ||
error("Cannot access view bindings. View lifecycle is ${lifecycle.currentState}!") | ||
} | ||
|
||
|
||
/** | ||
* Bind layout | ||
*/ | ||
val invoke = bindMethod.invoke(null, thisRef.requireView()) as T | ||
|
||
return invoke.also { this.binding = it } | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
#Fri Nov 05 01:29:22 BRT 2021 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip | ||
distributionPath=wrapper/dists | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.