From 372d10386a7eff57cbfeac1135906499e146dd4e Mon Sep 17 00:00:00 2001 From: "bilgehan.kalkan" <%&PrhD6U> Date: Wed, 28 Jul 2021 14:50:02 +0300 Subject: [PATCH 1/3] Create HttpDebug Library without complete ui. - Create :common for common needs on both :dev-tools and :http-debug - Implement pages on HttpDebug: List, Detail, Request and Response tabs. --- build.gradle | 2 +- common/.gitignore | 1 + common/build.gradle | 47 ++++++++++++ common/consumer-rules.pro | 0 common/proguard-rules.pro | 21 ++++++ common/src/main/AndroidManifest.xml | 5 ++ .../trendyol/devtools/common/BaseViewModel.kt | 14 ++++ .../common}/FragmentViewBindingDelegate.kt | 2 +- .../devtools/common}/SingleLiveEvent.kt | 4 +- common/src/main/res/values/styles.xml | 5 ++ dev-tools/build.gradle | 23 +++--- .../com/trendyol/devtools/TrendyolDevTools.kt | 2 + .../internal/debugmenu/DebugMenuFragment.kt | 2 +- .../internal/debugmenu/DebugMenuUseCase.kt | 2 +- .../internal/domain/EnvironmentUseCase.kt | 2 +- .../devtools/internal/main/MainFragment.kt | 7 +- .../devtools/internal/main/MainViewModel.kt | 2 +- .../res/layout/dev_tools_fragment_main.xml | 12 ++- dev-tools/src/main/res/values/strings.xml | 1 + http-debug/.gitignore | 1 + http-debug/build.gradle | 54 ++++++++++++++ http-debug/consumer-rules.pro | 0 http-debug/proguard-rules.pro | 21 ++++++ http-debug/src/main/AndroidManifest.xml | 11 +++ .../trendyol/devtools/httpdebug/HttpDebug.kt | 30 ++++++++ .../httpdebug/HttpDebugInterceptor.kt | 21 ++++++ .../httpdebug/internal/di/ContextContainer.kt | 24 ++++++ .../httpdebug/internal/di/DetailContainer.kt | 16 ++++ .../httpdebug/internal/di/MainContainer.kt | 11 +++ .../internal/di/RequestListContainer.kt | 23 ++++++ .../internal/di/RequestTabContainer.kt | 19 +++++ .../internal/di/ResponseTabContainer.kt | 20 +++++ .../domain/GetActiveRequestsUseCase.kt | 23 ++++++ .../internal/domain/GetRequestUseCase.kt | 25 +++++++ .../internal/domain/GetResponseUseCase.kt | 25 +++++++ .../internal/domain/IdGeneratorUseCase.kt | 8 ++ .../internal/domain/ManipulatorUseCase.kt | 63 ++++++++++++++++ .../internal/domain/SkipRequestUseCase.kt | 19 +++++ .../internal/model/HttpDebugRequest.kt | 13 ++++ .../internal/model/HttpDebugResponse.kt | 5 ++ .../internal/model/RequestResponse.kt | 12 +++ .../httpdebug/internal/model/State.kt | 5 ++ .../internal/ui/HttpDebugActivity.kt | 44 +++++++++++ .../internal/ui/detail/DetailFragment.kt | 74 +++++++++++++++++++ .../internal/ui/detail/DetailViewModel.kt | 15 ++++ .../ui/detail/request/RequestTabFragment.kt | 40 ++++++++++ .../ui/detail/request/RequestTabViewModel.kt | 22 ++++++ .../ui/detail/request/RequestTabViewState.kt | 18 +++++ .../ui/detail/response/ResponseTabFragment.kt | 40 ++++++++++ .../detail/response/ResponseTabViewModel.kt | 22 ++++++ .../detail/response/ResponseTabViewState.kt | 6 ++ .../internal/ui/list/ListFragment.kt | 62 ++++++++++++++++ .../internal/ui/list/ListItemDiffCallback.kt | 13 ++++ .../internal/ui/list/ListViewModel.kt | 35 +++++++++ .../internal/ui/list/RequestListAdapter.kt | 38 ++++++++++ .../ic_dev_tools_http_debug_double_arrow.xml | 13 ++++ .../layout/dev_tools_http_debug_activity.xml | 10 +++ .../dev_tools_http_debug_fragment_detail.xml | 42 +++++++++++ .../dev_tools_http_debug_fragment_list.xml | 25 +++++++ ..._tools_http_debug_fragment_request_tab.xml | 10 +++ ...tools_http_debug_fragment_response_tab.xml | 10 +++ .../layout/dev_tools_http_debug_item_list.xml | 52 +++++++++++++ http-debug/src/main/res/values/strings.xml | 7 ++ http-debug/src/main/res/values/styles.xml | 9 +++ sample/build.gradle | 7 +- .../main/java/com/trendyol/devtools/App.kt | 7 +- settings.gradle | 2 + 67 files changed, 1199 insertions(+), 27 deletions(-) create mode 100644 common/.gitignore create mode 100644 common/build.gradle create mode 100644 common/consumer-rules.pro create mode 100644 common/proguard-rules.pro create mode 100644 common/src/main/AndroidManifest.xml create mode 100644 common/src/main/java/com/trendyol/devtools/common/BaseViewModel.kt rename {dev-tools/src/main/java/com/trendyol/devtools/internal/fragment => common/src/main/java/com/trendyol/devtools/common}/FragmentViewBindingDelegate.kt (97%) rename {dev-tools/src/main/java/com/trendyol/devtools/internal/util => common/src/main/java/com/trendyol/devtools/common}/SingleLiveEvent.kt (93%) create mode 100644 common/src/main/res/values/styles.xml create mode 100644 http-debug/.gitignore create mode 100644 http-debug/build.gradle create mode 100644 http-debug/consumer-rules.pro create mode 100644 http-debug/proguard-rules.pro create mode 100644 http-debug/src/main/AndroidManifest.xml create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/HttpDebug.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/HttpDebugInterceptor.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/di/ContextContainer.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/di/DetailContainer.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/di/MainContainer.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/di/RequestListContainer.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/di/RequestTabContainer.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/di/ResponseTabContainer.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/domain/GetActiveRequestsUseCase.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/domain/GetRequestUseCase.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/domain/GetResponseUseCase.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/domain/IdGeneratorUseCase.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/domain/ManipulatorUseCase.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/domain/SkipRequestUseCase.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/model/HttpDebugRequest.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/model/HttpDebugResponse.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/model/RequestResponse.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/model/State.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/ui/HttpDebugActivity.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/ui/detail/DetailFragment.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/ui/detail/DetailViewModel.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/ui/detail/request/RequestTabFragment.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/ui/detail/request/RequestTabViewModel.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/ui/detail/request/RequestTabViewState.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/ui/detail/response/ResponseTabFragment.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/ui/detail/response/ResponseTabViewModel.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/ui/detail/response/ResponseTabViewState.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/ui/list/ListFragment.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/ui/list/ListItemDiffCallback.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/ui/list/ListViewModel.kt create mode 100644 http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/ui/list/RequestListAdapter.kt create mode 100644 http-debug/src/main/res/drawable/ic_dev_tools_http_debug_double_arrow.xml create mode 100644 http-debug/src/main/res/layout/dev_tools_http_debug_activity.xml create mode 100644 http-debug/src/main/res/layout/dev_tools_http_debug_fragment_detail.xml create mode 100644 http-debug/src/main/res/layout/dev_tools_http_debug_fragment_list.xml create mode 100644 http-debug/src/main/res/layout/dev_tools_http_debug_fragment_request_tab.xml create mode 100644 http-debug/src/main/res/layout/dev_tools_http_debug_fragment_response_tab.xml create mode 100644 http-debug/src/main/res/layout/dev_tools_http_debug_item_list.xml create mode 100644 http-debug/src/main/res/values/strings.xml create mode 100644 http-debug/src/main/res/values/styles.xml diff --git a/build.gradle b/build.gradle index 2b72d2e..f18b6de 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ buildscript { } dependencies { - classpath "com.android.tools.build:gradle:4.2.1" + classpath "com.android.tools.build:gradle:4.2.2" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath("org.jlleitschuh.gradle:ktlint-gradle:10.0.0") diff --git a/common/.gitignore b/common/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/common/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/common/build.gradle b/common/build.gradle new file mode 100644 index 0000000..5ae51d6 --- /dev/null +++ b/common/build.gradle @@ -0,0 +1,47 @@ +plugins { + id 'com.android.library' + id 'kotlin-android' +} + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.3" + + defaultConfig { + minSdkVersion 21 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles "consumer-rules.pro" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + kotlinOptions.jvmTarget = '1.8' + + buildFeatures { + buildConfig false + viewBinding true + } +} + +dependencies { + + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + implementation 'androidx.core:core-ktx:1.6.0' + implementation 'androidx.appcompat:appcompat:1.3.0' + implementation 'com.google.android.material:material:1.4.0' + testImplementation 'junit:junit:4.+' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + + implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version" + + implementation 'io.reactivex.rxjava3:rxjava:3.0.12' +} \ No newline at end of file diff --git a/common/consumer-rules.pro b/common/consumer-rules.pro new file mode 100644 index 0000000..e69de29 diff --git a/common/proguard-rules.pro b/common/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/common/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/common/src/main/AndroidManifest.xml b/common/src/main/AndroidManifest.xml new file mode 100644 index 0000000..cf17631 --- /dev/null +++ b/common/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/common/src/main/java/com/trendyol/devtools/common/BaseViewModel.kt b/common/src/main/java/com/trendyol/devtools/common/BaseViewModel.kt new file mode 100644 index 0000000..5b5793a --- /dev/null +++ b/common/src/main/java/com/trendyol/devtools/common/BaseViewModel.kt @@ -0,0 +1,14 @@ +package com.trendyol.devtools.common + +import androidx.lifecycle.ViewModel +import io.reactivex.rxjava3.disposables.CompositeDisposable + +open class BaseViewModel : ViewModel() { + + protected val disposable = CompositeDisposable() + + override fun onCleared() { + disposable.dispose() + super.onCleared() + } +} diff --git a/dev-tools/src/main/java/com/trendyol/devtools/internal/fragment/FragmentViewBindingDelegate.kt b/common/src/main/java/com/trendyol/devtools/common/FragmentViewBindingDelegate.kt similarity index 97% rename from dev-tools/src/main/java/com/trendyol/devtools/internal/fragment/FragmentViewBindingDelegate.kt rename to common/src/main/java/com/trendyol/devtools/common/FragmentViewBindingDelegate.kt index 41a5152..ba0d062 100644 --- a/dev-tools/src/main/java/com/trendyol/devtools/internal/fragment/FragmentViewBindingDelegate.kt +++ b/common/src/main/java/com/trendyol/devtools/common/FragmentViewBindingDelegate.kt @@ -1,4 +1,4 @@ -package com.trendyol.devtools.internal.fragment +package com.trendyol.devtools.common // https://github.com/Zhuinden/fragmentviewbindingdelegate-kt diff --git a/dev-tools/src/main/java/com/trendyol/devtools/internal/util/SingleLiveEvent.kt b/common/src/main/java/com/trendyol/devtools/common/SingleLiveEvent.kt similarity index 93% rename from dev-tools/src/main/java/com/trendyol/devtools/internal/util/SingleLiveEvent.kt rename to common/src/main/java/com/trendyol/devtools/common/SingleLiveEvent.kt index a81456d..0f6650a 100644 --- a/dev-tools/src/main/java/com/trendyol/devtools/internal/util/SingleLiveEvent.kt +++ b/common/src/main/java/com/trendyol/devtools/common/SingleLiveEvent.kt @@ -1,4 +1,4 @@ -package com.trendyol.devtools.internal.util +package com.trendyol.devtools.common import androidx.annotation.MainThread import androidx.annotation.Nullable @@ -19,7 +19,7 @@ import java.util.concurrent.atomic.AtomicBoolean * * see JoaquimLey/SingleLiveEvent.kt */ -internal class SingleLiveEvent : MutableLiveData() { +class SingleLiveEvent : MutableLiveData() { private val mPending = AtomicBoolean(false) diff --git a/common/src/main/res/values/styles.xml b/common/src/main/res/values/styles.xml new file mode 100644 index 0000000..5e96784 --- /dev/null +++ b/common/src/main/res/values/styles.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/sample/build.gradle b/sample/build.gradle index 4469f55..f7cbfd9 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -49,11 +49,12 @@ android { dependencies { debugImplementation project(':dev-tools') + debugImplementation project(':http-debug') implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation 'androidx.core:core-ktx:1.3.2' - implementation 'androidx.appcompat:appcompat:1.2.0' - implementation 'com.google.android.material:material:1.3.0' + implementation 'androidx.core:core-ktx:1.6.0' + implementation 'androidx.appcompat:appcompat:1.3.1' + implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1' diff --git a/sample/src/main/java/com/trendyol/devtools/App.kt b/sample/src/main/java/com/trendyol/devtools/App.kt index 6f7914f..5cd560b 100644 --- a/sample/src/main/java/com/trendyol/devtools/App.kt +++ b/sample/src/main/java/com/trendyol/devtools/App.kt @@ -8,6 +8,11 @@ class App : Application() { override fun onCreate() { super.onCreate() TrendyolDevTools.init(this) - TrendyolDevTools.addDebugAction(DebugActionItem("Toggle SSL Pinning")) + TrendyolDevTools.addDebugActionItems( + listOf( + DebugActionItem("Toggle SSL Pinning"), + DebugActionItem("Inspect") + ) + ) } } diff --git a/settings.gradle b/settings.gradle index 17b2a22..f67c8f5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,5 @@ rootProject.name = "dev-tools" include ':sample' include ':dev-tools' +include ':http-debug' +include ':common' From ec95c9aeeb17fbdfb343469bac93beacdbdd6691 Mon Sep 17 00:00:00 2001 From: "bilgehan.kalkan" <%&PrhD6U> Date: Thu, 29 Jul 2021 01:02:26 +0300 Subject: [PATCH 2/3] Fix build warnings --- .../httpdebug/internal/domain/GetActiveRequestsUseCase.kt | 2 +- .../devtools/httpdebug/internal/ui/list/RequestListAdapter.kt | 2 +- .../main/java/com/trendyol/devtools/ui/main/MainFragment.kt | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/domain/GetActiveRequestsUseCase.kt b/http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/domain/GetActiveRequestsUseCase.kt index 2edf1bd..faaf884 100644 --- a/http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/domain/GetActiveRequestsUseCase.kt +++ b/http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/domain/GetActiveRequestsUseCase.kt @@ -14,7 +14,7 @@ internal class GetActiveRequestsUseCase(private val manipulatorUseCase: Manipula .concatMap { Observable.fromIterable(it.values) .filter { requestResponse -> - requestResponse.response != null && requestResponse.response!!.state == State.BLOCKED + requestResponse.response.state == State.BLOCKED } .toList() .toObservable() diff --git a/http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/ui/list/RequestListAdapter.kt b/http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/ui/list/RequestListAdapter.kt index 5c7d18c..464222b 100644 --- a/http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/ui/list/RequestListAdapter.kt +++ b/http-debug/src/main/java/com/trendyol/devtools/httpdebug/internal/ui/list/RequestListAdapter.kt @@ -30,7 +30,7 @@ internal class RequestListAdapter(private val onRequestClicked: (String) -> Unit with(binding) { devToolsHttpDebugTextMethod.text = item.request.request.method devToolsHttpDebugTextUrl.text = item.request.request.url.toString() - devToolsHttpDebugTextResponseCode.text = item.response?.response?.code?.toString() + devToolsHttpDebugTextResponseCode.text = item.response.response?.code?.toString() devToolsHttpDebugTextResponseCode.visibility = item.getResponseCodeVisibility() } } diff --git a/sample/src/main/java/com/trendyol/devtools/ui/main/MainFragment.kt b/sample/src/main/java/com/trendyol/devtools/ui/main/MainFragment.kt index 2f25c43..74a725a 100644 --- a/sample/src/main/java/com/trendyol/devtools/ui/main/MainFragment.kt +++ b/sample/src/main/java/com/trendyol/devtools/ui/main/MainFragment.kt @@ -20,8 +20,8 @@ class MainFragment : Fragment() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View = MainFragmentBinding.inflate(inflater, container, false).also { binding = it }.root - override fun onActivityCreated(savedInstanceState: Bundle?) { - super.onActivityCreated(savedInstanceState) + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) viewModel = ViewModelProvider(this).get(MainViewModel::class.java) binding.button.setOnClickListener { From f1f086f5a1593fcc63d5d33d94023e555719f0de Mon Sep 17 00:00:00 2001 From: "bilgehan.kalkan" <%&PrhD6U> Date: Thu, 29 Jul 2021 01:03:21 +0300 Subject: [PATCH 3/3] Update versions: - Kotlin: 1.5.0 to 1.5.21 - AGP: 4.2.2 to 7.0.0 - Gradle Plugin: 6.7.1 to 7.0.2 --- build.gradle | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index f18b6de..74aff00 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = "1.5.0" + ext.kotlin_version = "1.5.21" ext.lifecycle_version = "2.3.1" ext.coroutines_version = "1.4.3" @@ -11,7 +11,7 @@ buildscript { } dependencies { - classpath "com.android.tools.build:gradle:4.2.2" + classpath "com.android.tools.build:gradle:7.0.0" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath("org.jlleitschuh.gradle:ktlint-gradle:10.0.0") diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8320ca7..cb29fa8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon May 10 14:20:15 TRT 2021 +#Thu Jul 29 00:57:25 TRT 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME