Skip to content

Instantly share code, notes, and snippets.

View Audhil's full-sized avatar
🎯
Focusing

Mohammed Audhil Audhil

🎯
Focusing
View GitHub Profile
@Audhil
Audhil / output.xml
Last active January 24, 2018 06:19
XML - Generation Blog_1
<?xml version="1.0" encoding="UTF-8"?>
<Movies>
<row no="1">
<FL val="TicketId">6000000066015</FL>
<FL val="MovieName">Dunkirk</FL>
<FL val="TimeLog">
<row no="1">
<FL val="date">23/01/2018</FL>
<FL val="startTime">08:00</FL>
</row>
@Audhil
Audhil / gist:efb9feeb4012e8f3be0b7ff630373d7d
Last active January 24, 2018 06:18
XML - Generation Blog_2
val xmlSerializer = Xml.newSerializer()
val writer = StringWriter()
xmlSerializer.setOutput(writer)
xmlSerializer.startDocument("UTF-8", false)
xmlSerializer.startTag("", "Movies")
xmlSerializer.startTag("", "row")
xmlSerializer.attribute("", "no", "1")
xmlSerializer.startTag("", "FL")
xmlSerializer.attribute("", "val", "TicketId")
xmlSerializer.text("6000000066015")
@Audhil
Audhil / gist:921d00eb1657c93ccd93ffe8a401627a
Last active January 24, 2018 06:19
XML - Generation Blog_3
val xmlSerializer = Xml.newSerializer()
val xmlString = xmlSerializer.document {
element("Movies") {
element("row") {
attribute("no", "1")
element("FL", "6000000066015") {
attribute("val", "TicketId")
}
element("FL", "Dunkirk") {
attribute("val", "MovieName")
@Audhil
Audhil / gist:fc24d7055786330fba5e41f67cdb955c
Last active February 13, 2018 08:41
XML - Generation Blog_4
// XML generation by code
fun XmlSerializer.document(docName: String = "UTF-8",
xmlStringWriter: StringWriter = StringWriter(),
init: XmlSerializer.() -> Unit): String {
startDocument(docName, true)
xmlStringWriter.buffer.setLength(0) // refreshing string writer due to reuse
setOutput(xmlStringWriter)
init()
endDocument()
return xmlStringWriter.toString()
@Audhil
Audhil / AppExtnFuncs.kt
Last active February 4, 2018 09:34
Util to Check Internet connectivity, and BroadCast Listener to dynamically keep track inside app
fun Context.isNetworkConnected(): Boolean {
val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager
return connectivityManager?.getNetworkInfo(ConnectivityManager.TYPE_WIFI)?.isConnected!! ||
connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)?.isConnected!!
}
@Audhil
Audhil / AppComponent.kt
Last active February 5, 2018 07:27
SharedPreferences With Kotlin Extn funcs = Life Easy!
@Singleton
@Component(
modules = [(SharedPreferenceModule::class),
(APIModule::class),
(RepositoryModule::class),
(DataBaseModule::class),
(DBRefreshingModule::class), ....]
)
interface AppComponent {
// app's application class
@Audhil
Audhil / gist:d20640f975b2c4a035b2d154a2e21f0d
Created March 19, 2018 10:57
converting Realm Data to LiveData
// realm live data
class RealmLiveData<T : RealmModel>(private val results: RealmResults<T>) : LiveData<RealmResults<T>>() {
private val listener = RealmChangeListener<RealmResults<T>> { results -> value = results }
override fun onActive() {
results.addChangeListener(listener)
}
override fun onInactive() {
results.removeChangeListener(listener)
@Audhil
Audhil / AppsDialogExtnFuncs.kt
Last active April 17, 2018 10:49
Making custom alert dialogs with Kotlin extension functions
/*
* Notes Dialog
*/
inline fun Activity.showNotesAlertDialog(func: NotesDialogHelper.() -> Unit): AlertDialog =
NotesDialogHelper(this).apply {
func()
}.create()
inline fun Fragment.showNotesAlertDialog(func: NotesDialogHelper.() -> Unit): AlertDialog =
NotesDialogHelper(this.context!!).apply {
@Audhil
Audhil / BaseDialogHelper.kt
Last active April 17, 2018 12:33
AlertDialogs with Extn funcs blog_2
abstract class BaseDialogHelper {
abstract val dialogView: View
abstract val builder: AlertDialog.Builder
// required bools
open var cancelable: Boolean = true
open var isBackGroundTransparent: Boolean = true
// dialog
@Audhil
Audhil / NotesDialogHelper.kt
Last active April 17, 2018 13:31
AlertDialogs with Extn funcs blog_3
class NotesDialogHelper(context: Context) : BaseDialogHelper() {
// dialog view
override val dialogView: View by lazy {
LayoutInflater.from(context).inflate(R.layout.notes_dialog, null)
}
override val builder: AlertDialog.Builder = AlertDialog.Builder(context).setView(dialogView)
// notes edit text