Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
./gradlew spotlessApply
git add `git diff --name-only`
exit 0
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,3 @@ fun AppCompatActivity.sendThemeChangedBroadcast() {
val manager = LocalBroadcastManager.getInstance(applicationContext)
manager.sendBroadcast(Intent(BROADCAST_THEME_CHANGED))
}

Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ interface ThemingDataStore {

var theme: DuckDuckGoTheme

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ import kotlin.reflect.KProperty
inline fun <reified T : ViewBinding> AppCompatActivity.viewBinding() = ActivityViewBindingDelegate(T::class.java, this)

class ActivityViewBindingDelegate<T : ViewBinding>(
bindingClass: Class<T>,
val activity: AppCompatActivity
bindingClass: Class<T>,
val activity: AppCompatActivity
) : ReadOnlyProperty<AppCompatActivity, T> {

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<T>()
binding = bindMethod.invoke(null, thisRef.layoutInflater).cast<T>()

return binding!!
}
return binding!!
}
}

@Suppress("UNCHECKED_CAST")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,48 +30,48 @@ 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
bindingClass: Class<T>,
private val fragment: Fragment
) : ReadOnlyProperty<Fragment, T> {

// 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<T>()
binding = bindMethod.invoke(null, thisRef.requireView()).cast<T>()

return binding!!
}
return binding!!
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ import kotlin.reflect.KProperty
inline fun <reified T : ViewBinding> ViewGroup.viewBinding() = ViewBindingDelegate(T::class.java, this)

class ViewBindingDelegate<T : ViewBinding>(
bindingClass: Class<T>,
view: ViewGroup
bindingClass: Class<T>,
view: ViewGroup
) : ReadOnlyProperty<ViewGroup, T> {
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<T>()
} catch (e: NoSuchMethodException) {
val inflateMethod = bindingClass.getMethod("inflate", LayoutInflater::class.java, ViewGroup::class.java)
inflateMethod.invoke(null, LayoutInflater.from(view.context), view).cast<T>()
}
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<T>()
} catch (e: NoSuchMethodException) {
val inflateMethod = bindingClass.getMethod("inflate", LayoutInflater::class.java, ViewGroup::class.java)
inflateMethod.invoke(null, LayoutInflater.from(view.context), view).cast<T>()
}

override fun getValue(thisRef: ViewGroup, property: KProperty<*>): T {
return binding
}
override fun getValue(thisRef: ViewGroup, property: KProperty<*>): T {
return binding
}
}

@Suppress("UNCHECKED_CAST")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions gradle/android-library.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

apply from: "$rootDir/spotless.gradle"

android {
compileSdkVersion compile_sdk
buildToolsVersion tools_build_version
Expand Down
2 changes: 1 addition & 1 deletion statistics/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.duckduckgo.app.statistics">

<instrumentation
android:name="androidx.test.runner.AndroidJUnitRunner"
android:targetPackage="com.duckduckgo.app.statistics"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ import java.util.*
interface VariantManager {

// variant-dependant features listed here
sealed class VariantFeature {

}
sealed class VariantFeature

companion object {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import androidx.work.*
import com.duckduckgo.app.global.plugins.worker.WorkerInjectorPlugin
import com.duckduckgo.di.scopes.AppObjectGraph
import com.squareup.anvil.annotations.ContributesMultibinding
import dagger.multibindings.IntoSet
import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ interface Pixel {
WEB_RENDERER_GONE_CRASH("m_d_wrg_c"),
WEB_RENDERER_GONE_KILLED("m_d_wrg_k"),


COOKIE_DATABASE_NOT_FOUND("m_cdb_nf"),
COOKIE_DATABASE_OPEN_ERROR("m_cdb_oe"),
COOKIE_DATABASE_DELETE_ERROR("m_cdb_de"),
Expand Down