This file contains hidden or 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
<?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> |
This file contains hidden or 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 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") |
This file contains hidden or 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 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") |
This file contains hidden or 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
// 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() |
This file contains hidden or 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
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!! | |
} |
This file contains hidden or 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
@Singleton | |
@Component( | |
modules = [(SharedPreferenceModule::class), | |
(APIModule::class), | |
(RepositoryModule::class), | |
(DataBaseModule::class), | |
(DBRefreshingModule::class), ....] | |
) | |
interface AppComponent { | |
// app's application class |
This file contains hidden or 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
// 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) |
This file contains hidden or 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
/* | |
* 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 { |
This file contains hidden or 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
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 |
This file contains hidden or 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
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 |