Kittinun Vantasin
Storage, Networking, Parsing, Routing, Business logic, Display
Business Logic
View Setup / Loading
Model observation
Datasource interaction / Network
Handling permission / API differences
MVP, MVVM, MVI, M** ... (🔮 🙅♂️ we aren't talking about arch today™)
~ 80 % of the time choose List<T>
When you need something more like association e.g. A <-> B tries Map<A, B>
Ownership, does this contains that? picks Set<T>
Need something like a hierarchy use Tree<T>
fun getFoos(): List<Foo> {
val size = bars.size
val arr = ArrayList()
for (i in 1..size) {
arr.add(Foo(bars[i].bar))
}
return arr
}
fun getFoos(): List<Foo> =
bars.map { Foo(it) }
*View should belong to View layer
e.g. View, TextView, CalendarView
*Manager should belong to **Controller** Layer
e.g. LocationManager, AlarmManager, SearchManager
*Data, *Cursor usually a helper to Model layer
e.g. SqlLiteDatabase, SqlLiteCursor
Loads Views
Layout Views
Perform Animation on Views
Show/hide Views
Transition Views
No networking
No data persistent layer
No navigation (Activity™)
No business logic
No model observation
We adjust the style and reuse them
It is not 🙅 |
It is a 🙆♀️ |
---|---|
ShoppingListItemFragment |
ListItemFragment with Adapter that shows ShoppingItem |
AddressFormFragment |
Fragment that shows multiple EditTextFragment as a form item |
ImageView subclass that hits network |
ImageRemoteFragment with an image provider (local / network) |
1. Install/Uninstall + Open app
2. Read What's new
3. Rate App
4. Contextual information
5. Related application
6. Read Description
Logic
Model observation
Determine Action
Observe the state
List related apps
Actions
Uninstall/Install Open
Rate the app
Go to the different app
See the images
Search and more ...
GooglePlayStoreItemInfoFragment
StoreHeaderFragment
StoreWhatsNewFragment
StoreContextualLinkFragment
StoreRelatedItemFragment
StoreDescriptionFragment
StoreItemInfoF
StoreHeaderF
StoreWhatsNewF
StoreContextLinkF
StoreRelatedItemF
StoreDescriptionF
?
?
1. Use appropriate data structures & code structures
2. Naming affects intentions!
3. Activity™ and Fragment are just a regular VIEW
4. Views are usually small™
5. Views are great when they use as composable/reusable units
6. We need an actual place for our logic
Exception java.lang.IllegalStateException:
Can not perform this action after onSaveInstanceState
android.support.v4.app
.FragmentManagerImpl.checkStateLoss (FragmentManagerImpl.java:1538)
android.support.v4.app
.FragmentManagerImpl.enqueueAction (FragmentManagerImpl.java:1556)
android.support.v4.app
.BackStackRecord.commitInternal (BackStackRecord.java:696)
android.support.v4.app
.BackStackRecord.commit (BackStackRecord.java:662)
Activity
Router
Controller 1..n
View
class SampleActivity : AppCompatActivity() {
private lateinit var router: Router
override fun onCreate(bundle: Bundle?) {
super.onCreate(bundle)
setContentView(R.layout.activity_sample)
router = Conductor.attachRouter(
this,
container,
bundle)
if (!router.hasRootController()) {
router.setRoot(RouterTransaction.with(
MainController()
))
}
}
}
<com.bluelinelabs.conductor.
ChangeHandlerFrameLayout
android:id="@+id/container"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
class MainController : Controller() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup): View =
inflater.inflate(R.layout.controller_demo, container, false).apply {
//setup your view
}
}
router.pushController(RouterTransaction.with(
AnotherController()))
router.pushController(
RouterTransaction.with(AnotherController()).
pushChangeHandler(HorizontalChangeHandler()).
popChangeHandler(HorizontalChangeHandler())
)
New instance (init)
onCreateView
Controller is on top!
onDestroyView
Controller is on top again
Send to back / Configuration Change e.g.
Remove from Router / Got killed by System