Skip to content

Commit f7f2413

Browse files
authored
Add common githooks folder to share hooks with the team (#1349)
1 parent 468b119 commit f7f2413

File tree

13 files changed

+67
-66
lines changed

13 files changed

+67
-66
lines changed

.githooks/pre-commit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
./gradlew spotlessApply
2+
git add `git diff --name-only`
3+
exit 0

common-ui/src/main/java/com/duckduckgo/mobile/android/ui/Theming.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,3 @@ fun AppCompatActivity.sendThemeChangedBroadcast() {
8181
val manager = LocalBroadcastManager.getInstance(applicationContext)
8282
manager.sendBroadcast(Intent(BROADCAST_THEME_CHANGED))
8383
}
84-

common-ui/src/main/java/com/duckduckgo/mobile/android/ui/store/ThemingDataStore.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ interface ThemingDataStore {
2222

2323
var theme: DuckDuckGoTheme
2424

25-
}
25+
}

common-ui/src/main/java/com/duckduckgo/mobile/android/ui/store/ThemingSharedPreferences.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import androidx.core.content.edit
2222
import com.duckduckgo.mobile.android.ui.DuckDuckGoTheme
2323
import javax.inject.Inject
2424

25-
class ThemingSharedPreferences @Inject constructor(private val context: Context): ThemingDataStore {
25+
class ThemingSharedPreferences @Inject constructor(private val context: Context) : ThemingDataStore {
2626

2727
override var theme: DuckDuckGoTheme
2828
get() {
@@ -42,4 +42,4 @@ class ThemingSharedPreferences @Inject constructor(private val context: Context)
4242
const val FILENAME = "com.duckduckgo.app.settings_activity.settings"
4343
const val KEY_THEME = "THEME"
4444
}
45-
}
45+
}

common-ui/src/main/java/com/duckduckgo/mobile/android/ui/viewbinding/ActivityViewBindingDelegate.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@ import kotlin.reflect.KProperty
2626
inline fun <reified T : ViewBinding> AppCompatActivity.viewBinding() = ActivityViewBindingDelegate(T::class.java, this)
2727

2828
class ActivityViewBindingDelegate<T : ViewBinding>(
29-
bindingClass: Class<T>,
30-
val activity: AppCompatActivity
29+
bindingClass: Class<T>,
30+
val activity: AppCompatActivity
3131
) : ReadOnlyProperty<AppCompatActivity, T> {
3232

33-
private var binding: T? = null
34-
private val bindMethod = bindingClass.getMethod("inflate", LayoutInflater::class.java)
33+
private var binding: T? = null
34+
private val bindMethod = bindingClass.getMethod("inflate", LayoutInflater::class.java)
3535

36-
override fun getValue(thisRef: AppCompatActivity, property: KProperty<*>): T {
37-
binding?.let { return it }
36+
override fun getValue(thisRef: AppCompatActivity, property: KProperty<*>): T {
37+
binding?.let { return it }
3838

39-
val lifecycle = thisRef.lifecycle
40-
if (!lifecycle.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) {
41-
error("Cannot access viewBinding activity lifecycle is ${lifecycle.currentState}")
42-
}
39+
val lifecycle = thisRef.lifecycle
40+
if (!lifecycle.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) {
41+
error("Cannot access viewBinding activity lifecycle is ${lifecycle.currentState}")
42+
}
4343

44-
binding = bindMethod.invoke(null, thisRef.layoutInflater).cast<T>()
44+
binding = bindMethod.invoke(null, thisRef.layoutInflater).cast<T>()
4545

46-
return binding!!
47-
}
46+
return binding!!
47+
}
4848
}
4949

5050
@Suppress("UNCHECKED_CAST")

common-ui/src/main/java/com/duckduckgo/mobile/android/ui/viewbinding/FragmentViewBindingDelegate.kt

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,48 +30,48 @@ import kotlin.reflect.KProperty
3030
inline fun <reified T : ViewBinding> Fragment.viewBinding() = FragmentViewBindingDelegate(T::class.java, this)
3131

3232
class FragmentViewBindingDelegate<T : ViewBinding>(
33-
bindingClass: Class<T>,
34-
private val fragment: Fragment
33+
bindingClass: Class<T>,
34+
private val fragment: Fragment
3535
) : ReadOnlyProperty<Fragment, T> {
3636

37-
// LazyThreadSafetyMode.NONE because it will never be initialised from ore than one thread
38-
private val nullifyBindingHandler by lazy(LazyThreadSafetyMode.NONE) { Handler(Looper.getMainLooper()) }
39-
private var binding: T? = null
37+
// LazyThreadSafetyMode.NONE because it will never be initialised from ore than one thread
38+
private val nullifyBindingHandler by lazy(LazyThreadSafetyMode.NONE) { Handler(Looper.getMainLooper()) }
39+
private var binding: T? = null
4040

41-
private val bindMethod = bindingClass.getMethod("bind", View::class.java)
41+
private val bindMethod = bindingClass.getMethod("bind", View::class.java)
4242

43-
init {
44-
fragment.viewLifecycleOwnerLiveData.observe(fragment) { lifecycleOwner ->
45-
lifecycleOwner.lifecycle.addObserver(object : LifecycleObserver {
46-
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
47-
fun onDestroy() {
48-
nullifyBindingHandler.post { binding = null }
43+
init {
44+
fragment.viewLifecycleOwnerLiveData.observe(fragment) { lifecycleOwner ->
45+
lifecycleOwner.lifecycle.addObserver(object : LifecycleObserver {
46+
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
47+
fun onDestroy() {
48+
nullifyBindingHandler.post { binding = null }
49+
}
50+
})
4951
}
50-
})
5152
}
52-
}
5353

54-
override fun getValue(thisRef: Fragment, property: KProperty<*>): T {
54+
override fun getValue(thisRef: Fragment, property: KProperty<*>): T {
5555

56-
// onCreateView maybe be called between the onDestroyView and the next Main thread run-loop.
57-
// Because nullifyBindingHandler has to post to null the binding, it may happen that [binding]
58-
// refers to the previous fragment view. When that happens, ie. bindings's root view does not match
59-
// the current fragment, we just null the [binding] here too
60-
if (binding != null && binding?.root !== thisRef.view) {
61-
binding = null
62-
}
56+
// onCreateView maybe be called between the onDestroyView and the next Main thread run-loop.
57+
// Because nullifyBindingHandler has to post to null the binding, it may happen that [binding]
58+
// refers to the previous fragment view. When that happens, ie. bindings's root view does not match
59+
// the current fragment, we just null the [binding] here too
60+
if (binding != null && binding?.root !== thisRef.view) {
61+
binding = null
62+
}
6363

64-
binding?.let { return it }
64+
binding?.let { return it }
6565

66-
val lifecycle = thisRef.viewLifecycleOwner.lifecycle
67-
if(!lifecycle.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) {
68-
error("Cannot access view bindings, View lifecycle is ${lifecycle.currentState}")
69-
}
66+
val lifecycle = thisRef.viewLifecycleOwner.lifecycle
67+
if (!lifecycle.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) {
68+
error("Cannot access view bindings, View lifecycle is ${lifecycle.currentState}")
69+
}
7070

71-
binding = bindMethod.invoke(null, thisRef.requireView()).cast<T>()
71+
binding = bindMethod.invoke(null, thisRef.requireView()).cast<T>()
7272

73-
return binding!!
74-
}
73+
return binding!!
74+
}
7575

7676
}
7777

common-ui/src/main/java/com/duckduckgo/mobile/android/ui/viewbinding/ViewBindingDelegate.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ import kotlin.reflect.KProperty
2525
inline fun <reified T : ViewBinding> ViewGroup.viewBinding() = ViewBindingDelegate(T::class.java, this)
2626

2727
class ViewBindingDelegate<T : ViewBinding>(
28-
bindingClass: Class<T>,
29-
view: ViewGroup
28+
bindingClass: Class<T>,
29+
view: ViewGroup
3030
) : ReadOnlyProperty<ViewGroup, T> {
31-
private val binding: T = try {
32-
val inflateMethod = bindingClass.getMethod("inflate", LayoutInflater::class.java, ViewGroup::class.java, Boolean::class.javaPrimitiveType)
33-
inflateMethod.invoke(null, LayoutInflater.from(view.context), view, true).cast<T>()
34-
} catch (e: NoSuchMethodException) {
35-
val inflateMethod = bindingClass.getMethod("inflate", LayoutInflater::class.java, ViewGroup::class.java)
36-
inflateMethod.invoke(null, LayoutInflater.from(view.context), view).cast<T>()
37-
}
31+
private val binding: T = try {
32+
val inflateMethod = bindingClass.getMethod("inflate", LayoutInflater::class.java, ViewGroup::class.java, Boolean::class.javaPrimitiveType)
33+
inflateMethod.invoke(null, LayoutInflater.from(view.context), view, true).cast<T>()
34+
} catch (e: NoSuchMethodException) {
35+
val inflateMethod = bindingClass.getMethod("inflate", LayoutInflater::class.java, ViewGroup::class.java)
36+
inflateMethod.invoke(null, LayoutInflater.from(view.context), view).cast<T>()
37+
}
3838

39-
override fun getValue(thisRef: ViewGroup, property: KProperty<*>): T {
40-
return binding
41-
}
39+
override fun getValue(thisRef: ViewGroup, property: KProperty<*>): T {
40+
return binding
41+
}
4242
}
4343

4444
@Suppress("UNCHECKED_CAST")

common/src/main/java/com/duckduckgo/app/global/exception/UncaughtExceptionRepository.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class UncaughtExceptionRepositoryDb(
4747
val exceptionEntity = UncaughtExceptionEntity(
4848
message = rootCause.extractExceptionCause(),
4949
exceptionSource = exceptionSource,
50-
version = deviceInfo.appVersion)
50+
version = deviceInfo.appVersion
51+
)
5152
uncaughtExceptionDao.add(exceptionEntity)
5253

5354
lastSeenException = e

gradle/android-library.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
apply from: "$rootDir/spotless.gradle"
18+
1719
android {
1820
compileSdkVersion compile_sdk
1921
buildToolsVersion tools_build_version

statistics/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
1919
package="com.duckduckgo.app.statistics">
20-
20+
2121
<instrumentation
2222
android:name="androidx.test.runner.AndroidJUnitRunner"
2323
android:targetPackage="com.duckduckgo.app.statistics"

0 commit comments

Comments
 (0)