Add Entry in debug to launch Mock activity

This commit is contained in:
ganfra 2022-08-23 19:04:23 +02:00
parent 1151dca9c9
commit 45e3af9a81
7 changed files with 79 additions and 1 deletions

View File

@ -424,6 +424,8 @@ dependencies {
kapt libs.airbnb.epoxyProcessor
implementation libs.airbnb.epoxyPaging
implementation libs.airbnb.mavericks
implementation libs.airbnb.mavericksMocking
implementation libs.airbnb.mavericksLauncher
// Snap Helper https://github.com/rubensousa/GravitySnapHelper
implementation 'com.github.rubensousa:gravitysnaphelper:2.2.2'

View File

@ -11,6 +11,7 @@
<activity android:name=".features.debug.features.DebugFeaturesSettingsActivity" />
<activity android:name=".features.debug.DebugMenuActivity" />
<activity android:name=".features.debug.leak.DebugMemoryLeaksActivity" />
<activity android:name=".features.debug.VectorLauncherMockActivity" />
<activity
android:name="com.facebook.flipper.android.diagnostics.FlipperDiagnosticActivity"

View File

@ -24,6 +24,8 @@ import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.app.Person
import androidx.core.content.getSystemService
import com.airbnb.mvrx.launcher.MavericksLauncherActivity
import com.airbnb.mvrx.launcher.MavericksLauncherMockActivity
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder
@ -82,6 +84,11 @@ class DebugMenuActivity : VectorBaseActivity<ActivityDebugMenuBinding>() {
}
private fun setupViews() {
views.debugMock.setOnClickListener {
MavericksLauncherMockActivity.activityToShowMock = VectorLauncherMockActivity::class
MavericksLauncherActivity.show(this)
}
views.debugFeatures.setOnClickListener { startActivity(Intent(this, DebugFeaturesSettingsActivity::class.java)) }
views.debugPrivateSetting.setOnClickListener { openPrivateSettings() }
views.debugAnalytics.setOnClickListener {

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.app.features.debug
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.airbnb.mvrx.launcher.MavericksLauncherMockActivity
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.databinding.ActivityLauncherMockBinding
@AndroidEntryPoint
class VectorLauncherMockActivity : VectorBaseActivity<ActivityLauncherMockBinding>() {
override fun getBinding() = ActivityLauncherMockBinding.inflate(layoutInflater)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (savedInstanceState == null) {
MavericksLauncherMockActivity.showNextMockFromActivity(
activity = this,
showView = { view ->
// Use commit now to catch errors on initialization.
setFragment(view as Fragment, commitNow = true)
}
)
}
}
protected fun setFragment(fragment: Fragment, commitNow: Boolean = false) {
supportFragmentManager.beginTransaction()
.replace(R.id.container, fragment)
.setPrimaryNavigationFragment(fragment)
.apply {
if (commitNow) commitNow() else commit()
}
}
}

View File

@ -24,6 +24,12 @@
android:padding="@dimen/layout_horizontal_margin"
android:showDividers="middle">
<Button
android:id="@+id/debug_mock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mocks" />
<Button
android:id="@+id/debug_features"
android:layout_width="wrap_content"

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@ -37,6 +37,8 @@ import com.airbnb.epoxy.Carousel
import com.airbnb.epoxy.EpoxyAsyncUtil
import com.airbnb.epoxy.EpoxyController
import com.airbnb.mvrx.Mavericks
import com.airbnb.mvrx.mocking.MavericksMock
import com.airbnb.mvrx.mocking.MockableMavericks
import com.facebook.stetho.Stetho
import com.gabrielittner.threetenbp.LazyThreeTen
import com.github.rubensousa.gravitysnaphelper.GravitySnapHelper
@ -146,7 +148,8 @@ class VectorApplication :
}
logInfo()
LazyThreeTen.init(this)
Mavericks.initialize(debugMode = false)
MockableMavericks.initialize(mocksEnabled = buildMeta.isDebug, debugMode = false, applicationContext = applicationContext)
//Mavericks.initialize(debugMode = false)
configureEpoxy()