-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alireza Tizfahm Fard
committed
Dec 30, 2019
1 parent
bafdd31
commit 508daca
Showing
13 changed files
with
153 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="alirezat775.library.networkmonitor"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application> | ||
<activity android:name=".NetworkMonitorActivity" /> | ||
<activity android:name=".view.NetworkMonitorActivity" /> | ||
</application> | ||
|
||
</manifest> |
15 changes: 0 additions & 15 deletions
15
networkmonitor/src/main/java/alirezat775/library/networkmonitor/NetworkLogging.kt
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
networkmonitor/src/main/java/alirezat775/library/networkmonitor/NetworkMonitor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
networkmonitor/src/main/java/alirezat775/library/networkmonitor/NetworkMonitorInterceptor.kt
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
networkmonitor/src/main/java/alirezat775/library/networkmonitor/core/NetworkLogging.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package alirezat775.library.networkmonitor.core | ||
|
||
/** | ||
* Author: Alireza Tizfahm Fard | ||
* Date: 2019-12-30 | ||
*/ | ||
|
||
object NetworkLogging { | ||
|
||
internal val list = mutableListOf<NetworkModel>() | ||
|
||
fun clear() { | ||
list.clear() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...onitor/src/main/java/alirezat775/library/networkmonitor/core/NetworkMonitorInterceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package alirezat775.library.networkmonitor.core | ||
|
||
import okhttp3.Interceptor | ||
import okhttp3.Response | ||
|
||
/** | ||
* Author: Alireza Tizfahm Fard | ||
* Date: 2019-12-29 | ||
* Email: [email protected] | ||
*/ | ||
|
||
class NetworkMonitorInterceptor : Interceptor { | ||
|
||
override fun intercept(chain: Interceptor.Chain): Response { | ||
val rq = chain.request() | ||
val rqModel = | ||
RequestNetworkModel( | ||
rq.url(), | ||
rq.method(), | ||
rq.headers(), | ||
rq.body() | ||
) | ||
val rs = chain.proceed(rq) | ||
val rsModel = | ||
ResponseNetworkModel( | ||
rs.code(), | ||
rs.message(), | ||
rs.headers(), | ||
rs.body()?.string() | ||
) | ||
NetworkLogging.list.add(NetworkModel(rqModel, rsModel)) | ||
return rs | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...orkmonitor/src/main/java/alirezat775/library/networkmonitor/view/NetworkLoggingAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package alirezat775.library.networkmonitor.view | ||
|
||
import alirezat775.library.networkmonitor.R | ||
import alirezat775.library.networkmonitor.core.NetworkModel | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import kotlinx.android.synthetic.main.log_item.view.* | ||
|
||
/** | ||
* Author: Alireza Tizfahm Fard | ||
* Date: 2019-12-30 | ||
*/ | ||
|
||
class NetworkLoggingAdapter : RecyclerView.Adapter<NetworkLoggingAdapter.ViewHolder>() { | ||
|
||
private var list = mutableListOf<NetworkModel>() | ||
|
||
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | ||
val url = itemView.network_url_log | ||
} | ||
|
||
fun addItems(list: MutableList<NetworkModel>) { | ||
this.list = list | ||
} | ||
|
||
fun addItem(networkModel: NetworkModel) { | ||
this.list.add(networkModel) | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
return ViewHolder( | ||
LayoutInflater.from(parent.context).inflate( | ||
R.layout.log_item, | ||
parent, | ||
false | ||
) | ||
) | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return list.size | ||
} | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
holder.url.text = list[position].request.url.encodedPath() | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
.../networkmonitor/NetworkMonitorActivity.kt → ...orkmonitor/view/NetworkMonitorActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:id="@+id/network_url_log" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:padding="16dp" | ||
android:textSize="20sp" /> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters