Skip to content

Commit

Permalink
Merge pull request #16 from alirezat775/refactor-package-name
Browse files Browse the repository at this point in the history
refactor package name
  • Loading branch information
alirezat775 authored Feb 29, 2020
2 parents ee51204 + ca04fe4 commit f189d4b
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 80 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,19 @@ v 1.0.0 Released!
- okHttp interceptor
- list api call
- detail api call (response & request)

v 1.0.1 Released!

- support persian

v 1.0.2 Released!

- fix minor bug

v 1.0.3 Released!

- fix HTTP response parsing

v 1.0.4 Released!

- refactor package name
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Useful library for monitoring android network request with okhttp

Options
- okHttp interceptor
- list api call
- detail api call (response & request)
- list api calls
- info api call (response & request)

### Issue
- [bug report](.github/ISSUE_TEMPLATE/bug_report.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package alirezat775.app.networkmonitor

import alirezat775.networkmonitor.NetworkMonitor
import alirezat775.networkmonitor.core.NetworkMonitorInterceptor
import alirezat775.lib.networkmonitor.NetworkMonitor
import alirezat775.lib.networkmonitor.core.NetworkMonitorInterceptor
import android.os.Bundle
import android.os.Handler
import androidx.appcompat.app.AppCompatActivity
Expand All @@ -11,7 +11,8 @@ import java.io.IOException

class MainActivity : AppCompatActivity() {

private var networkMonitor = NetworkMonitor(this)
private var networkMonitor =
NetworkMonitor(this)
private val client by lazy {
OkHttpClient.Builder()
.addInterceptor(NetworkMonitorInterceptor())
Expand Down Expand Up @@ -59,7 +60,6 @@ class MainActivity : AppCompatActivity() {
}

private fun okHttpPost(body: String) {

val body = jsonObject.toString()
val requestBody: RequestBody =
RequestBody.create(MediaType.parse("application/json; charset=utf-8"), body)
Expand Down
6 changes: 3 additions & 3 deletions networkmonitor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
defaultConfig {
minSdkVersion 17
targetSdkVersion 29
versionCode 4
versionName "1.0.3"
versionCode 5
versionName "1.0.4"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
Expand All @@ -28,7 +28,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
api 'com.squareup:seismic:1.0.2'
Expand Down
9 changes: 3 additions & 6 deletions networkmonitor/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
package="alirezat775.networkmonitor">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application>
<activity
android:name=".view.NetworkMonitorActivity"
android:launchMode="singleTop" />
<activity
android:name=".view.NetworkMonitorDetailActivity"
android:launchMode="singleTop" />
<activity android:name="alirezat775.lib.networkmonitor.view.NetworkMonitorActivity" />
<activity android:name="alirezat775.lib.networkmonitor.view.NetworkMonitorDetailActivity" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package alirezat775.networkmonitor
package alirezat775.lib.networkmonitor

import alirezat775.networkmonitor.core.NetworkLogging
import alirezat775.networkmonitor.view.NetworkMonitorActivity
import alirezat775.lib.networkmonitor.core.NetworkLogging
import alirezat775.lib.networkmonitor.view.NetworkMonitorActivity
import android.content.Context
import android.content.Context.SENSOR_SERVICE
import android.content.Intent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package alirezat775.networkmonitor
package alirezat775.lib.networkmonitor

import android.text.TextUtils
import okhttp3.Request
Expand Down Expand Up @@ -82,12 +82,9 @@ object OkHttpHelper {
) {
return true
}
val contentLength = stringToLong(
response.header("Content-Length")
)
val contentLength = stringToLong(response.header("Content-Length"))
return contentLength != -1L || "chunked".equals(
response.header("Transfer-Encoding"),
ignoreCase = true
response.header("Transfer-Encoding"), ignoreCase = true
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package alirezat775.networkmonitor.core
package alirezat775.lib.networkmonitor.core

/**
* Author: Alireza Tizfahm Fard
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package alirezat775.networkmonitor.core
package alirezat775.lib.networkmonitor.core

import okhttp3.Headers

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package alirezat775.networkmonitor.core
package alirezat775.lib.networkmonitor.core

import alirezat775.networkmonitor.OkHttpHelper
import alirezat775.lib.networkmonitor.OkHttpHelper
import okhttp3.Interceptor
import okhttp3.Response
import java.nio.charset.Charset
Expand Down Expand Up @@ -35,21 +35,9 @@ class NetworkMonitorInterceptor : Interceptor {
responseString = buffer.clone().readString(charset)
}
}
val rsModel =
ResponseNetworkModel(
rs.code(),
rs.message(),
rs.headers(),
responseString
)
val rsModel = ResponseNetworkModel(rs.code(), rs.message(), rs.headers(), responseString)
val uuid = UUID.randomUUID().toString() + System.currentTimeMillis()
NetworkLogging.list.add(
NetworkModel(
uuid,
rqModel,
rsModel
)
)
NetworkLogging.list.add(NetworkModel(uuid, rqModel, rsModel))
NetworkLogging.addItemListener?.itemAdded()

return rs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package alirezat775.networkmonitor.core
package alirezat775.lib.networkmonitor.core

/**
* Author: Alireza Tizfahm Fard
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package alirezat775.networkmonitor.view
package alirezat775.lib.networkmonitor.view

import alirezat775.networkmonitor.R
import alirezat775.networkmonitor.core.NetworkModel
import alirezat775.lib.networkmonitor.core.NetworkModel
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package alirezat775.networkmonitor.view
package alirezat775.lib.networkmonitor.view

import alirezat775.lib.networkmonitor.core.NetworkLogging
import alirezat775.lib.networkmonitor.core.OnAddItemListener
import alirezat775.networkmonitor.R
import alirezat775.networkmonitor.core.NetworkLogging
import alirezat775.networkmonitor.core.OnAddItemListener
import android.content.Intent
import android.os.Bundle
import android.os.Handler
Expand All @@ -29,8 +29,7 @@ class NetworkMonitorActivity : AppCompatActivity() {
recyclerView.adapter = adapter
adapter.addItems(NetworkLogging.list)
adapter.notifyDataSetChanged()
adapter.clickItem = object :
NetworkLoggingAdapter.ClickItem {
adapter.clickItem = object : NetworkLoggingAdapter.ClickItem {
override fun onClick(uuid: String) {
val myIntent =
Intent(this@NetworkMonitorActivity, NetworkMonitorDetailActivity::class.java)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package alirezat775.networkmonitor.view
package alirezat775.lib.networkmonitor.view

import alirezat775.lib.networkmonitor.core.NetworkLogging
import alirezat775.networkmonitor.R
import alirezat775.networkmonitor.core.NetworkLogging
import android.graphics.Color
import android.os.Bundle
import android.text.Spannable
Expand All @@ -25,26 +25,17 @@ class NetworkMonitorDetailActivity : AppCompatActivity() {
if (it.uuid == uuid) {
val rqUrl: Spannable = SpannableString("url: ${it.request.url}")
rqUrl.setSpan(
ForegroundColorSpan(Color.BLACK),
0,
4,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
ForegroundColorSpan(Color.BLACK), 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)

val rqHeaders: Spannable = SpannableString("headers: ${it.request.headers}")
rqHeaders.setSpan(
ForegroundColorSpan(Color.BLACK),
0,
8,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
ForegroundColorSpan(Color.BLACK), 0, 8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)

val rqBody: Spannable = SpannableString("body: ${it.request.body}")
rqBody.setSpan(
ForegroundColorSpan(Color.BLACK),
0,
5,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
ForegroundColorSpan(Color.BLACK), 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)

network_request_url.text = rqUrl
Expand All @@ -53,34 +44,22 @@ class NetworkMonitorDetailActivity : AppCompatActivity() {

val rsCode: Spannable = SpannableString("code: ${it.response.code}")
rsCode.setSpan(
ForegroundColorSpan(Color.BLACK),
0,
5,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
ForegroundColorSpan(Color.BLACK), 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)

val rsMessage: Spannable = SpannableString("message: ${it.response.message}")
rsMessage.setSpan(
ForegroundColorSpan(Color.BLACK),
0,
8,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
ForegroundColorSpan(Color.BLACK), 0, 8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)

val rsHeaders: Spannable = SpannableString("headers: ${it.response.headers}")
rsHeaders.setSpan(
ForegroundColorSpan(Color.BLACK),
0,
8,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
ForegroundColorSpan(Color.BLACK), 0, 8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)

val rsBody: Spannable = SpannableString("body: ${it.response.body}")
rsBody.setSpan(
ForegroundColorSpan(Color.BLACK),
0,
5,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
ForegroundColorSpan(Color.BLACK), 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)

network_response_code.text = rsCode
Expand Down

0 comments on commit f189d4b

Please sign in to comment.