Skip to content
Merged
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
1 change: 1 addition & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions .idea/deploymentTargetDropDown.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package com.udfsoft.androidinfo.lib

import android.os.Build
import androidx.annotation.WorkerThread
import com.udfsoft.androidinfo.lib.command.GetOSInformationCommand
import com.udfsoft.androidinfo.lib.entity.*

@WorkerThread
object DeviceInformationFactory : DeviceInformation {

private const val LOG_TAG = "DeviceInformation"

override fun getGeneralInformation() = GeneralInformation(Build.BRAND, Build.MODEL)

override fun getDesignInformation(): DesignInformation {
Expand All @@ -26,7 +29,8 @@ object DeviceInformationFactory : DeviceInformation {
}

override fun getOSInformation(): OSInformation {
TODO("Not yet implemented")
val getOSInformationCommand = GetOSInformationCommand()
return getOSInformationCommand(Unit)
}

override fun getCPUInformation(): CPUInformation {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.udfsoft.androidinfo.lib.command

interface CommandInterface<P, R> {

operator fun invoke(param: P): R
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.udfsoft.androidinfo.lib.command

import android.os.Build
import com.udfsoft.androidinfo.lib.entity.OSInformation

class GetOSInformationCommand : CommandInterface<Unit, OSInformation> {

override fun invoke(param: Unit): OSInformation {
val manufacturer = Build.MANUFACTURER
val version = Build.VERSION.SDK_INT
val versionRelease = Build.VERSION.RELEASE
val incremental = Build.VERSION.INCREMENTAL
val codeName = Build.VERSION.CODENAME
val linuxVersion = System.getProperty("os.version")

return OSInformation(manufacturer, version, versionRelease, incremental, codeName, linuxVersion)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.udfsoft.androidinfo.lib.entity

class OSInformation {

}
data class OSInformation(
val manufacturer: String,
val version: Int,
val versionRelease: String,
val incremental: String,
val codeName: String,
val linuxVersion: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class MainFragment : Fragment(R.layout.fragment_main) {
viewModel.getGeneralInformationLiveData().observe(viewLifecycleOwner) {
Log.d(TAG, "GeneralInformation: $it")
}

viewModel.getOSInformationLiveData().observe(viewLifecycleOwner) {
Log.d(TAG, "OSInformation: $it")
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.udfsoft.androidinfo.lib.DeviceInformationFactory
import com.udfsoft.androidinfo.lib.entity.GeneralInformation
import com.udfsoft.androidinfo.lib.entity.OSInformation
import com.udfsoft.androidinfo.sample.util.toLiveData
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand All @@ -13,9 +14,14 @@ class MainViewModel : ViewModel() {

private val generalInformationLiveData = MutableLiveData<GeneralInformation>()

fun loadInformation() = viewModelScope.launch(Dispatchers.Main) {
private val osInformationLiveData = MutableLiveData<OSInformation>()

fun loadInformation() = viewModelScope.launch(Dispatchers.IO) {
generalInformationLiveData.postValue(DeviceInformationFactory.getGeneralInformation())
osInformationLiveData.postValue(DeviceInformationFactory.getOSInformation())
}

fun getGeneralInformationLiveData() = generalInformationLiveData.toLiveData()

fun getOSInformationLiveData() = osInformationLiveData.toLiveData()
}