Skip to content

Commit 0d0e539

Browse files
Merge pull request #44 from Trendyol/fix/debug-menu-theming
Update DebugMenu component:
2 parents 3c9bb81 + 9b7f4b4 commit 0d0e539

File tree

10 files changed

+47
-33
lines changed

10 files changed

+47
-33
lines changed

libraries/debug-menu/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ android {
3838

3939
ext {
4040
PUBLISH_GROUP_ID = 'com.trendyol.android.devtools'
41-
PUBLISH_VERSION = '0.4.0'
41+
PUBLISH_VERSION = '0.4.1'
4242
PUBLISH_ARTIFACT_ID = 'debug-menu'
4343
PUBLISH_DESCRIPTION = "Android QA Debug Menu"
4444
PUBLISH_URL = "https://github.com/Trendyol/android-dev-tools"

libraries/debug-menu/src/main/java/com/trendyol/android/devtools/debugmenu/DebugMenu.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.trendyol.android.devtools.debugmenu
22

33
import android.content.Context
4-
import android.content.Intent
54
import com.trendyol.android.devtools.debugmenu.internal.di.ContextContainer
65
import com.trendyol.android.devtools.debugmenu.internal.domain.DebugMenuUseCase
76
import com.trendyol.android.devtools.debugmenu.internal.ui.DebugMenuActivity
@@ -10,14 +9,24 @@ object DebugMenu {
109

1110
private lateinit var debugMenuUseCase: DebugMenuUseCase
1211

12+
/**
13+
* Initializes library, should be called earlier than [show].
14+
*
15+
* @param context application context.
16+
*/
1317
fun init(context: Context) {
1418
ContextContainer.setContext(context)
1519
debugMenuUseCase = ContextContainer.debugMenuContainer.debugMenuUseCase
1620
}
1721

18-
fun show() {
22+
/**
23+
* Starts [DebugMenuActivity].
24+
*
25+
* @param title to show above menu. Default is "Debug Menu".
26+
*/
27+
fun show(title: String = "Debug Menu") {
1928
val context = ContextContainer.getContext()
20-
context.startActivity(Intent(context, DebugMenuActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
29+
context.startActivity(DebugMenuActivity.newIntent(context, title))
2130
}
2231

2332
fun addDebugAction(debugAction: DebugActionItem) {

libraries/debug-menu/src/main/java/com/trendyol/android/devtools/debugmenu/internal/di/ContextContainer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import android.content.Context
77
internal object ContextContainer {
88

99
val debugMenuContainer by lazy { DebugMenuContainer() }
10-
1110
private lateinit var context: Context
1211

1312
fun getContext(): Context = if (ContextContainer::context.isInitialized) {
1413
context
1514
} else {
1615
throw NullPointerException(
17-
"Library is not initialized, please call init(Application) on Application.onCreate()"
16+
"Library is not initialized, please call init(Context) earlier than " +
17+
"[com.trendyol.android.devtools.debugmenu.DebugMenu.show]",
1818
)
1919
}
2020

libraries/debug-menu/src/main/java/com/trendyol/android/devtools/debugmenu/internal/ui/DebugMenuActivity.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.trendyol.android.devtools.debugmenu.internal.ui
22

3+
import android.content.Context
4+
import android.content.Intent
35
import android.os.Bundle
46
import androidx.appcompat.app.AppCompatActivity
57
import com.trendyol.android.devtools.debugmenu.R
@@ -21,7 +23,20 @@ internal class DebugMenuActivity : AppCompatActivity() {
2123
private fun startMainFragment() {
2224
supportFragmentManager
2325
.beginTransaction()
24-
.replace(R.id.fragmentContainerViewMain, DebugMenuFragment.newInstance())
26+
.replace(
27+
R.id.fragmentContainerViewMain,
28+
DebugMenuFragment.newInstance(requireNotNull(intent.getStringExtra(KEY_TITLE))),
29+
)
2530
.commit()
2631
}
32+
33+
companion object {
34+
35+
internal const val KEY_TITLE: String = "key_title"
36+
37+
internal fun newIntent(context: Context, title: String): Intent =
38+
Intent(context, DebugMenuActivity::class.java)
39+
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
40+
.putExtra(KEY_TITLE, title)
41+
}
2742
}

libraries/debug-menu/src/main/java/com/trendyol/android/devtools/debugmenu/internal/ui/DebugMenuFragment.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ package com.trendyol.android.devtools.debugmenu.internal.ui
22

33
import android.os.Bundle
44
import android.view.View
5+
import androidx.core.os.bundleOf
56
import androidx.fragment.app.Fragment
67
import androidx.fragment.app.viewModels
78
import com.trendyol.android.devtools.debugmenu.DebugActionItem
89
import com.trendyol.android.devtools.debugmenu.R
910
import com.trendyol.android.devtools.debugmenu.databinding.DebugMenuFragmentBinding
1011
import com.trendyol.android.devtools.debugmenu.internal.di.ContextContainer
1112
import com.trendyol.android.devtools.debugmenu.internal.ext.viewBinding
13+
import com.trendyol.android.devtools.debugmenu.internal.ui.DebugMenuActivity.Companion.KEY_TITLE
1214

1315
internal class DebugMenuFragment : Fragment(R.layout.debug_menu_fragment) {
1416

@@ -22,6 +24,8 @@ internal class DebugMenuFragment : Fragment(R.layout.debug_menu_fragment) {
2224
super.onViewCreated(view, savedInstanceState)
2325
observeViewModel()
2426
initializeRecyclerView()
27+
28+
binding.toolbarDebugMenu.title = requireArguments().getString(KEY_TITLE)
2529
}
2630

2731
private fun observeViewModel() {
@@ -47,8 +51,10 @@ internal class DebugMenuFragment : Fragment(R.layout.debug_menu_fragment) {
4751

4852
companion object {
4953

50-
fun newInstance(): DebugMenuFragment {
51-
return DebugMenuFragment()
54+
fun newInstance(title: String): DebugMenuFragment {
55+
return DebugMenuFragment().apply {
56+
arguments = bundleOf(KEY_TITLE to title)
57+
}
5258
}
5359
}
5460
}

libraries/debug-menu/src/main/res/layout/debug_menu_fragment.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
android:layout_height="wrap_content"
1313
app:layout_constraintEnd_toEndOf="parent"
1414
app:layout_constraintStart_toStartOf="parent"
15+
app:elevation="0dp"
16+
android:backgroundTint="@color/debug_menu_color_background_page"
1517
app:layout_constraintTop_toTopOf="parent">
1618

1719
<androidx.appcompat.widget.Toolbar
1820
android:id="@+id/toolbarDebugMenu"
1921
android:layout_width="match_parent"
2022
android:layout_height="wrap_content"
23+
app:titleTextColor="@color/debug_menu_color_title"
2124
app:title="Debug Menu" />
2225
</com.google.android.material.appbar.AppBarLayout>
2326

libraries/debug-menu/src/main/res/values-night/colors.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<color name="colorPrimary">#ffffff</color>
4-
<color name="colorPrimaryDark">#ffffff</color>
3+
<color name="colorPrimary">#010101</color>
4+
<color name="colorPrimaryDark">#010101</color>
55
<color name="colorAccent">#1B72C0</color>
66

77
<color name="debug_menu_color_background_page">#010101</color>

libraries/debug-menu/src/main/res/values-night/themes.xml

Lines changed: 0 additions & 19 deletions
This file was deleted.

libraries/debug-menu/src/main/res/values/colors.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<color name="colorPrimary">#ffffff</color>
4-
<color name="colorPrimaryDark">#000000</color>
3+
<color name="colorPrimary">#F3F4F9</color>
4+
<color name="colorPrimaryDark">#F3F4F9</color>
55
<color name="colorAccent">#1B72C0</color>
66

77
<color name="debug_menu_color_background_page">#F3F4F9</color>

sample/src/main/java/com/trendyol/android/devtools/ui/main/MainFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class MainFragment : Fragment() {
3232
EnvironmentManager.updateEnvironments(environments)
3333
}
3434
binding.buttonDebugMenu.setOnClickListener {
35-
DebugMenu.show()
35+
DebugMenu.show("Sample Application Debug Menu")
3636
}
3737
binding.buttonAutofillService.setOnClickListener {
3838
(activity as? MainActivity)?.navigateToFragment(

0 commit comments

Comments
 (0)