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
val json1 = """ | |
{ | |
"name": "Mark", | |
"address": "London": | |
}""" | |
val student = Gson().fromJson(json1, Student::class.java) |
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
val student = Student("Alex", "Rome, 1500") // instance | |
val jsonString = Gson().toJson(student) // json string |
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
data class Student ( | |
var name: String? = null, | |
var address: String? = null) { | |
} | |
val student = Student("Alex", "Rome") // instance |
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
dependencies { | |
... | |
implementation 'com.google.code.gson:gson:2.8.5' | |
... | |
} |
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
private fun loadWebView(){ | |
val loader = Thread { | |
when { | |
MyReachability.hasServerConnected(this) -> runOnUiThread { | |
hideLoadingDialog() | |
Log.d(classTag, "Loading ${Constants.LANDING_SERVER}") | |
mWebView.loadUrl(Constants.LANDING_SERVER) | |
} | |
MyReachability.hasInternetConnected(this) -> runOnUiThread { |
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
object MyReachability { | |
private fun hasNetworkAvailable(context: Context): Boolean { | |
val service = Context.CONNECTIVITY_SERVICE | |
val manager = context.getSystemService(service) as ConnectivityManager? | |
val network = manager?.activeNetworkInfo | |
Log.d(classTag, "hasNetworkAvailable: ${(network != null)}") | |
return (network?.isConnected) ?: false | |
} |
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
//Constants.LANDING_SERVER = "https://www.myserver.com" | |
fun hasServerConnected(context: Context): Boolean { | |
if (hasNetworkAvailable(context)) { | |
try { | |
val connection = URL(Constants.LANDING_SERVER).openConnection() as HttpURLConnection | |
connection.setRequestProperty("User-Agent", "Test") | |
connection.setRequestProperty("Connection", "close") | |
connection.connectTimeout = 1000 //configurable | |
connection.connect() | |
Logger.d(classTag, "hasServerConnected: ${(connection.responseCode == 200)}") |
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
//Constants.REACHABILITY_SERVER = "https://www.google.com" | |
fun hasInternetConnected(context: Context): Boolean { | |
if (hasNetworkAvailable(context)) { | |
try { | |
val connection = URL(Constants.REACHABILITY_SERVER).openConnection() as HttpURLConnection | |
connection.setRequestProperty("User-Agent", "ConnectionTest") | |
connection.setRequestProperty("Connection", "close") | |
connection.connectTimeout = 1000 // configurable | |
connection.connect() | |
Logger.d(classTag, "hasInternetConnected: ${(connection.responseCode == 200)}") |
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
private fun hasNetworkAvailable(context: Context): Boolean { | |
val service = Context.CONNECTIVITY_SERVICE | |
val manager = context.getSystemService(service) as ConnectivityManager? | |
val network = manager?.activeNetworkInfo | |
Logger.d(classTag, "hasNetworkAvailable: ${(network != null)}") | |
return (network != null) | |
} |
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
set recipientName to "Hissain Khan" | |
set recipientAddress to "hissain.khan@gmail.com" | |
set theSubject to "AppleScript Automated Email Sending" | |
set theContent to "This email was sent using AppleScript! for testing" | |
tell application "Mail" | |
set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true} | |
tell theMessage | |
make new to recipient with properties {name:recipientName, address:recipientAddress} | |
send | |
end tell |