Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert app to Kotlin #20

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
compileSdkVersion 29
buildToolsVersion '26.0.3'
defaultConfig {
applicationId "com.oatrice.internet_speed_testing"
minSdkVersion 16
targetSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
Expand All @@ -21,13 +26,13 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.0.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.android.support:recyclerview-v7:26.0.2'
compile project(':internet-speed-testing')
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation project(':internet-speed-testing')
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.oatrice.internet_speed_testing

import androidx.test.InstrumentationRegistry
import androidx.test.runner.AndroidJUnit4
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

/**
* Instrumentation test, which will execute on an Android device.
*
* @see [Testing documentation](http://d.android.com/tools/testing)
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
@Throws(Exception::class)
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()

assertEquals("com.oatrice.internet_speed_testing", appContext.getPackageName())
}
}
70 changes: 0 additions & 70 deletions app/src/main/java/com/oatrice/internet_speed_testing/Adapter.java

This file was deleted.

50 changes: 50 additions & 0 deletions app/src/main/java/com/oatrice/internet_speed_testing/Adapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.oatrice.internet_speed_testing

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.internet_speed_testing.ProgressionModel
import kotlinx.android.synthetic.main.view_item.view.*
import java.util.*

class Adapter : RecyclerView.Adapter<MyViewHolder>() {

private val dataList = ArrayList<ProgressionModel>()

fun setDataList(position: Int, data: ProgressionModel) {
if (dataList.size <= position) {
dataList.add(data)

} else {
dataList[position] = data

}

notifyDataSetChanged()
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.view_item, parent, false)
return MyViewHolder(view)
}

override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
holder.bind(dataList[position])
}

override fun getItemCount(): Int = dataList.size

}

class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

@SuppressLint("SetTextI18n")
fun bind(progressionModel: ProgressionModel) {
itemView.tvProgress.text = progressionModel.progressTotal.toString()
itemView.tvDownload.text = progressionModel.downloadSpeed.toString()
itemView.tvUpload.text = progressionModel.uploadSpeed.toString()
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.oatrice.internet_speed_testing

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.internet_speed_testing.InternetSpeedBuilder
import com.example.internet_speed_testing.ProgressionModel
import kotlinx.android.synthetic.main.activity_main.*

class MainJavaActivity : AppCompatActivity() {

private lateinit var adapter: Adapter

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

adapter = Adapter()
recyclerView.layoutManager = LinearLayoutManager(this)
recyclerView.adapter = adapter

val builder = InternetSpeedBuilder(this)
builder.setOnEventInternetSpeedListener(object : InternetSpeedBuilder.OnEventInternetSpeedListener {
override fun onDownloadProgress(count: Int, progressModel: ProgressionModel) {

}

override fun onUploadProgress(count: Int, progressModel: ProgressionModel) {

}

override fun onTotalProgress(count: Int, progressModel: ProgressionModel) {
adapter.setDataList(count, progressModel)

}
})
builder.start("http://2.testdebit.info/fichiers/1Mo.dat", 20)
}
}

This file was deleted.

8 changes: 4 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
Expand Down Expand Up @@ -35,9 +35,9 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent" />

<android.support.v7.widget.RecyclerView
<androidx.recyclerview.widget.RecyclerView
tools:listitem="@layout/view_item"
android:id="@+id/recyclerview"
android:id="@+id/recyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="10dp"
Expand All @@ -46,4 +46,4 @@
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>

</android.support.constraint.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 2 additions & 2 deletions app/src/main/res/layout/view_item.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
Expand Down Expand Up @@ -31,4 +31,4 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent" />

</android.support.constraint.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.oatrice.internet_speed_testing

import org.junit.Test

import org.junit.Assert.*

/**
* Example local unit test, which will execute on the development machine (host).
*
* @see [Testing documentation](http://d.android.com/tools/testing)
*/
class ExampleUnitTest {
@Test
@Throws(Exception::class)
fun addition_isCorrect() {
assertEquals(4, (2 + 2).toLong())
}
}
Loading