Upgrade to Pro — share decks privately, control downloads, hide ads and more …

iOS Architecture with Multiplatform

iOS Architecture with Multiplatform

Kevin Galligan

October 05, 2018
Tweet

More Decks by Kevin Galligan

Other Decks in Programming

Transcript

  1. JRE
 (lang, io, util, etc) Android
 (Context, SQLiteDatabase, Threading, Shared

    Preferences) Gradle Plugin Library Format Testing Support Xcode Support J2ObjC Doppl JRE JUnit Mockito
  2. JRE
 (lang, io, util, etc) Android
 (Context, SQLiteDatabase, Threading, Shared

    Preferences) Gradle Plugin Library Format Retrofit RxJava RxAndroid Gson Dagger SQLDelight Room DB Android Architecture etc… Testing Support Xcode Support J2ObjC Doppl JRE JUnit Mockito
  3. Fractivities Architecture Components Looper, Handler, Message Queue Retrofit SQLite
 (Room,

    etc) java.io.File Android Android Native Stuff ViewControllers Architecture Components Looper, Handler, Message Queue Retrofit SQLite
 (Room, etc) java.io.File iOS iOS Native Stuff
  4. val evenLiveData:EventLiveData init { val query = goFreeze(AppContext.dbHelper. queryWrapper.sessionQueries. sessionById(sessionId))

    evenLiveData = EventLiveData(query) } fun shutDown(){ evenLiveData.removeListener() }
  5. val evenLiveData:EventLiveData init { val query = goFreeze(AppContext.dbHelper. queryWrapper.sessionQueries. sessionById(sessionId))

    evenLiveData = EventLiveData(query) } fun shutDown(){ evenLiveData.removeListener() }
  6. override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {

    eventViewModel.eventModel.evenLiveData. observe(viewLifecycleOwner, Observer { dataRefresh(it) }) return initView(inflater, container) }
  7. override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {

    eventViewModel.eventModel.evenLiveData. observe(viewLifecycleOwner, Observer { dataRefresh(it) }) return initView(inflater, container) }
  8. fun registerForChanges(proc:(sessionInfo:SessionInfo)->Unit){ eventObserver = object : Observer<SessionInfo>{ override fun onChanged(t:

    SessionInfo?){ if(t != null) proc(t) } } eventModel.evenLiveData.observeForever(eventObserver!!) }
  9. interface SessionDetailsView : BaseView { fun updateView(isFavorite: Boolean, session: SessionModel)

    fun setupRatingButtons(rating: SessionRating?) fun setRatingClickable(clickable: Boolean) } override fun updateView(isFavorite: Boolean, session: SessionModel) { collapsingToolbar.title = session.title speakersTextView.text = session.speakers.joinToString(separator = ", ") { it.fullName } timeTextView.text = session.timeString detailsTextView.text = listOfNotNull(session.roomText, session.category).joinToString(", ") descriptionTextView.text = session.descriptionText val online = context?.let { it.isConnected?.and(!it.isAirplaneModeOn) } ?: false for (button in listOf(votingButtonsLayout, favoriteButton)) { func updateView(isFavorite: Bool, session: SessionModel) { titleLabel.text = session.title let startsAt = session.startsAt let endsAt = session.endsAt if (startsAt != nil && endsAt != nil) { timeLabel.text = KotlinPair(first: startsAt, second: endsAt).toReadableString() } let image = UIImage(named: isFavorite ? "star_full" : "star_empty")! favoriteButton.image = image
  10. expect val mainThread:Boolean actual val mainThread: Boolean get() = Looper.myLooper()

    === Looper.getMainLooper() actual val mainThread: Boolean get() = NSThread.isMainThread()
  11. expect val mainThread:Boolean actual val mainThread: Boolean get() = Looper.myLooper()

    === Looper.getMainLooper() actual val mainThread: Boolean get() = NSThread.isMainThread() actual val mainThread: Boolean = true
  12. expect fun currentTimeMillis():Long expect fun <B> backgroundTask(backJob:()-> B, mainJob:(B) ->

    Unit) expect fun backgroundTask(backJob:()->Unit) expect fun networkBackgroundTask(backJob:()->Unit) expect fun initContext():NativeOpenHelperFactory expect fun <T> goFreeze(a:T):T expect fun <T> T.freeze2(): T expect fun simpleGet(url:String):String expect fun logException(t:Throwable) expect fun settingsFactory(): Settings.Factory expect fun createUuid():String
  13. actual class Date(val date:java.util.Date) { actual fun toLongMillis(): Long =

    date.time } actual class DateFormatHelper actual constructor(format: String) { val dateFormatter = object : ThreadLocal<DateFormat>(){ override fun initialValue(): DateFormat = SimpleDateFormat(format) } actual fun toDate(s: String): Date = Date(dateFormatter.get()!!.parse(s)) actual fun format(d: Date): String = dateFormatter.get()!!.format(d.date) }
  14. fun initPlatformClient( staticFileLoader: (filePrefix: String, fileType: String) -> String?, analyticsCallback:

    (name: String, params: Map<String, Any>) -> Unit, clLogCallback: (s: String) -> Unit) {
  15. fun initPlatformClient( staticFileLoader: (filePrefix: String, fileType: String) -> String?, analyticsCallback:

    (name: String, params: Map<String, Any>) -> Unit, clLogCallback: (s: String) -> Unit) { AppContext.initPlatformClient ({filePrefix, fileType -> loadAsset("${filePrefix}.${fileType}")}, {name: String, params: Map<String, Any> -> val event = CustomEvent(name) //Loop Answers.getInstance().logCustom(event) }, { Log.w("MainApp", it) })
  16. let appContext = AppContext() appContext.doInitPlatformClient(staticFileLoader: loadAsset, analyticsCallback: analyticsCallback, clLogCallback: csLog)

    func loadAsset(filePrefix:String, fileType:String) -> String?{ do{ let bundleFile = Bundle.main.path(forResource: filePrefix, ofType: fileType) return try String(contentsOfFile: bundleFile!) } catch { return nil } }
  17. CREATE TABLE session( id TEXT NOT NULL PRIMARY KEY, title

    TEXT NOT NULL, description TEXT NOT NULL, startsAt TEXT AS Date NOT NULL, endsAt TEXT AS Date NOT NULL, serviceSession INTEGER NOT NULL DEFAULT 0, rsvp INTEGER NOT NULL DEFAULT 0, roomId INTEGER, FOREIGN KEY (roomId) REFERENCES room(id) ); insert: INSERT INTO session(id, title, description, startsAt, endsAt, serviceSession, roomId) VALUES (?,?,?,?,?,?,?) ; update: UPDATE session SET title = ?, description = ?, startsAt = ?, endsAt = ?, serviceSession = ?, roomId = ?, rsvp = ? WHERE id = ?; deleteById: DELETE FROM session WHERE id = ?; allSessions: SELECT * FROM session; sessionById: SELECT * FROM session WHERE id = ?;
  18. --Special query for schedule view sessionWithRoom: SELECT session.id, session.title, session.description,

    session.startsAt, session.endsAt, session.serviceSession, session.rsvp, session.roomId, room.name AS roomName, speakers.allNames FROM session LEFT JOIN ( SELECT sessionId,group_concat(fullName, ', ') AS allNames FROM sessionSpeaker JOIN userAccount ON userAccount.id = sessionSpeaker.userAccountId GROUP BY sessionId ) AS speakers ON speakers.sessionId = session.id JOIN room ON session.roomId = room.id ;
  19. public expect class PlatformSettings : Settings { /** * A

    factory that can produce [Settings] instances. */ public class Factory : Settings.Factory { public override fun create(name: String?): Settings } public override fun clear() public override fun remove(key: String) public override fun hasKey(key: String): Boolean public override fun putInt(key: String, value: Int) public override fun getInt(key: String, defaultValue: Int): Int public override fun putLong(key: String, value: Long) public override fun getLong(key: String, defaultValue: Long): Long public override fun putString(key: String, value: String) public override fun getString(key: String, defaultValue: String): String public override fun putFloat(key: String, value: Float) public override fun getFloat(key: String, defaultValue: Float): Float public override fun putDouble(key: String, value: Double) public override fun getDouble(key: String, defaultValue: Double): Double public override fun putBoolean(key: String, value: Boolean) public override fun getBoolean(key: String, defaultValue: Boolean): Boolean }
  20. Q3 Q2 Q4 Q1 Q2 2018 2019 0 .6 v0.7

    v0.8 v0.8.2 v0.9 Coroutines (and other libs)
  21. Q3 Q2 Q4 Q1 Q2 2018 2019 0 .6 v0.7

    v0.8 v0.8.2 v0.9.3 Coroutines?
  22. Q3 Q2 Q4 Q1 Q2 2018 2019 0 .6 v0.7

    v0.8 v0.8.2 v0.9.3 Coroutines? Other Libraries Docs/tutorials