diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 000000000000..ffa97fd645aa --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,3 @@ +./gradlew spotlessApply +git add `git diff --name-only` +exit 0 diff --git a/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/Theming.kt b/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/Theming.kt index 9be8b7233ff3..8abad45d3db8 100644 --- a/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/Theming.kt +++ b/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/Theming.kt @@ -81,4 +81,3 @@ fun AppCompatActivity.sendThemeChangedBroadcast() { val manager = LocalBroadcastManager.getInstance(applicationContext) manager.sendBroadcast(Intent(BROADCAST_THEME_CHANGED)) } - diff --git a/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/store/ThemingDataStore.kt b/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/store/ThemingDataStore.kt index 2e1fb9a8748f..422048f23c98 100644 --- a/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/store/ThemingDataStore.kt +++ b/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/store/ThemingDataStore.kt @@ -22,4 +22,4 @@ interface ThemingDataStore { var theme: DuckDuckGoTheme -} \ No newline at end of file +} diff --git a/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/store/ThemingSharedPreferences.kt b/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/store/ThemingSharedPreferences.kt index e012a67319b1..178721e357a7 100644 --- a/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/store/ThemingSharedPreferences.kt +++ b/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/store/ThemingSharedPreferences.kt @@ -22,7 +22,7 @@ import androidx.core.content.edit import com.duckduckgo.mobile.android.ui.DuckDuckGoTheme import javax.inject.Inject -class ThemingSharedPreferences @Inject constructor(private val context: Context): ThemingDataStore { +class ThemingSharedPreferences @Inject constructor(private val context: Context) : ThemingDataStore { override var theme: DuckDuckGoTheme get() { @@ -42,4 +42,4 @@ class ThemingSharedPreferences @Inject constructor(private val context: Context) const val FILENAME = "com.duckduckgo.app.settings_activity.settings" const val KEY_THEME = "THEME" } -} \ No newline at end of file +} diff --git a/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/viewbinding/ActivityViewBindingDelegate.kt b/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/viewbinding/ActivityViewBindingDelegate.kt index 68dd3fc2e754..e53a62aec89a 100644 --- a/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/viewbinding/ActivityViewBindingDelegate.kt +++ b/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/viewbinding/ActivityViewBindingDelegate.kt @@ -26,25 +26,25 @@ import kotlin.reflect.KProperty inline fun AppCompatActivity.viewBinding() = ActivityViewBindingDelegate(T::class.java, this) class ActivityViewBindingDelegate( - bindingClass: Class, - val activity: AppCompatActivity + bindingClass: Class, + val activity: AppCompatActivity ) : ReadOnlyProperty { - private var binding: T? = null - private val bindMethod = bindingClass.getMethod("inflate", LayoutInflater::class.java) + private var binding: T? = null + private val bindMethod = bindingClass.getMethod("inflate", LayoutInflater::class.java) - override fun getValue(thisRef: AppCompatActivity, property: KProperty<*>): T { - binding?.let { return it } + override fun getValue(thisRef: AppCompatActivity, property: KProperty<*>): T { + binding?.let { return it } - val lifecycle = thisRef.lifecycle - if (!lifecycle.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) { - error("Cannot access viewBinding activity lifecycle is ${lifecycle.currentState}") - } + val lifecycle = thisRef.lifecycle + if (!lifecycle.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) { + error("Cannot access viewBinding activity lifecycle is ${lifecycle.currentState}") + } - binding = bindMethod.invoke(null, thisRef.layoutInflater).cast() + binding = bindMethod.invoke(null, thisRef.layoutInflater).cast() - return binding!! - } + return binding!! + } } @Suppress("UNCHECKED_CAST") diff --git a/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/viewbinding/FragmentViewBindingDelegate.kt b/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/viewbinding/FragmentViewBindingDelegate.kt index 7ea9cd391eba..82416fcb8625 100644 --- a/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/viewbinding/FragmentViewBindingDelegate.kt +++ b/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/viewbinding/FragmentViewBindingDelegate.kt @@ -30,48 +30,48 @@ import kotlin.reflect.KProperty inline fun Fragment.viewBinding() = FragmentViewBindingDelegate(T::class.java, this) class FragmentViewBindingDelegate( - bindingClass: Class, - private val fragment: Fragment + bindingClass: Class, + private val fragment: Fragment ) : ReadOnlyProperty { - // LazyThreadSafetyMode.NONE because it will never be initialised from ore than one thread - private val nullifyBindingHandler by lazy(LazyThreadSafetyMode.NONE) { Handler(Looper.getMainLooper()) } - private var binding: T? = null + // LazyThreadSafetyMode.NONE because it will never be initialised from ore than one thread + private val nullifyBindingHandler by lazy(LazyThreadSafetyMode.NONE) { Handler(Looper.getMainLooper()) } + private var binding: T? = null - private val bindMethod = bindingClass.getMethod("bind", View::class.java) + private val bindMethod = bindingClass.getMethod("bind", View::class.java) - init { - fragment.viewLifecycleOwnerLiveData.observe(fragment) { lifecycleOwner -> - lifecycleOwner.lifecycle.addObserver(object : LifecycleObserver { - @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) - fun onDestroy() { - nullifyBindingHandler.post { binding = null } + init { + fragment.viewLifecycleOwnerLiveData.observe(fragment) { lifecycleOwner -> + lifecycleOwner.lifecycle.addObserver(object : LifecycleObserver { + @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) + fun onDestroy() { + nullifyBindingHandler.post { binding = null } + } + }) } - }) } - } - override fun getValue(thisRef: Fragment, property: KProperty<*>): T { + override fun getValue(thisRef: Fragment, property: KProperty<*>): T { - // onCreateView maybe be called between the onDestroyView and the next Main thread run-loop. - // Because nullifyBindingHandler has to post to null the binding, it may happen that [binding] - // refers to the previous fragment view. When that happens, ie. bindings's root view does not match - // the current fragment, we just null the [binding] here too - if (binding != null && binding?.root !== thisRef.view) { - binding = null - } + // onCreateView maybe be called between the onDestroyView and the next Main thread run-loop. + // Because nullifyBindingHandler has to post to null the binding, it may happen that [binding] + // refers to the previous fragment view. When that happens, ie. bindings's root view does not match + // the current fragment, we just null the [binding] here too + if (binding != null && binding?.root !== thisRef.view) { + binding = null + } - binding?.let { return it } + binding?.let { return it } - val lifecycle = thisRef.viewLifecycleOwner.lifecycle - if(!lifecycle.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) { - error("Cannot access view bindings, View lifecycle is ${lifecycle.currentState}") - } + val lifecycle = thisRef.viewLifecycleOwner.lifecycle + if (!lifecycle.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) { + error("Cannot access view bindings, View lifecycle is ${lifecycle.currentState}") + } - binding = bindMethod.invoke(null, thisRef.requireView()).cast() + binding = bindMethod.invoke(null, thisRef.requireView()).cast() - return binding!! - } + return binding!! + } } diff --git a/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/viewbinding/ViewBindingDelegate.kt b/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/viewbinding/ViewBindingDelegate.kt index 3e5bd4014140..a4ceed952074 100644 --- a/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/viewbinding/ViewBindingDelegate.kt +++ b/common-ui/src/main/java/com/duckduckgo/mobile/android/ui/viewbinding/ViewBindingDelegate.kt @@ -25,20 +25,20 @@ import kotlin.reflect.KProperty inline fun ViewGroup.viewBinding() = ViewBindingDelegate(T::class.java, this) class ViewBindingDelegate( - bindingClass: Class, - view: ViewGroup + bindingClass: Class, + view: ViewGroup ) : ReadOnlyProperty { - private val binding: T = try { - val inflateMethod = bindingClass.getMethod("inflate", LayoutInflater::class.java, ViewGroup::class.java, Boolean::class.javaPrimitiveType) - inflateMethod.invoke(null, LayoutInflater.from(view.context), view, true).cast() - } catch (e: NoSuchMethodException) { - val inflateMethod = bindingClass.getMethod("inflate", LayoutInflater::class.java, ViewGroup::class.java) - inflateMethod.invoke(null, LayoutInflater.from(view.context), view).cast() - } + private val binding: T = try { + val inflateMethod = bindingClass.getMethod("inflate", LayoutInflater::class.java, ViewGroup::class.java, Boolean::class.javaPrimitiveType) + inflateMethod.invoke(null, LayoutInflater.from(view.context), view, true).cast() + } catch (e: NoSuchMethodException) { + val inflateMethod = bindingClass.getMethod("inflate", LayoutInflater::class.java, ViewGroup::class.java) + inflateMethod.invoke(null, LayoutInflater.from(view.context), view).cast() + } - override fun getValue(thisRef: ViewGroup, property: KProperty<*>): T { - return binding - } + override fun getValue(thisRef: ViewGroup, property: KProperty<*>): T { + return binding + } } @Suppress("UNCHECKED_CAST") diff --git a/common/src/main/java/com/duckduckgo/app/global/exception/UncaughtExceptionRepository.kt b/common/src/main/java/com/duckduckgo/app/global/exception/UncaughtExceptionRepository.kt index 1de88b50e74a..c79bb0d7c741 100644 --- a/common/src/main/java/com/duckduckgo/app/global/exception/UncaughtExceptionRepository.kt +++ b/common/src/main/java/com/duckduckgo/app/global/exception/UncaughtExceptionRepository.kt @@ -47,7 +47,8 @@ class UncaughtExceptionRepositoryDb( val exceptionEntity = UncaughtExceptionEntity( message = rootCause.extractExceptionCause(), exceptionSource = exceptionSource, - version = deviceInfo.appVersion) + version = deviceInfo.appVersion + ) uncaughtExceptionDao.add(exceptionEntity) lastSeenException = e diff --git a/gradle/android-library.gradle b/gradle/android-library.gradle index 478afab13d5f..fe14c3166286 100644 --- a/gradle/android-library.gradle +++ b/gradle/android-library.gradle @@ -14,6 +14,8 @@ * limitations under the License. */ +apply from: "$rootDir/spotless.gradle" + android { compileSdkVersion compile_sdk buildToolsVersion tools_build_version diff --git a/statistics/src/main/AndroidManifest.xml b/statistics/src/main/AndroidManifest.xml index 2057e8751c5e..2b1718e4000a 100644 --- a/statistics/src/main/AndroidManifest.xml +++ b/statistics/src/main/AndroidManifest.xml @@ -17,7 +17,7 @@ - +