so they’re both `this`, do I just cast `this` to t...
# getting-started
o
so they’re both
this
, do I just cast
this
to that View when I need to use the view, and use
this
as is when I want to refer to the context?
m
first of all, the presenter should receive an instance of
BooksActivityView
instead of a context
o
great
m
then you don’t need to pass the context
o
I would’ve except for the way the DB access is setup
from an antonleiva article 😛
obviously my case has differed
m
let’s say the view is not an activity, then the cast from context would not work, right?
o
ah yes
it wouldn’t
m
so try to keep the presenter ignorant to which elements it is controlling
o
great
m
maybe it is a view, maybe it is a fragment, etc.
o
that’s its principle anyways, true
m
so my first suggestion if to change
getBooks
to
getBookes(view: BooksActivityView, context: Context)
so you don’t attach one to the other
o
ah I was actually waiting to see if you had a “fix” to the DB access
m
on a second step, I’d would try to move the DB handling layer to a different class, so you don’t need to pass a context to the presenter
o
otherwise yea of course I can pass
this
and
this
to which layer? regardless where you go it’s tied to Context because of that line
m
the rule of thumb is to try and keep your presenters android-free, i.e. without context or any other android specific class
let’s say you have a
DbHandler
which is
class DbHandler(context: Context)
on the activity (or using Dagger) you can inject this DbHandler into the presenter
o
true, there is such a class
m
which means the presenter would never need to know what
DbHandler
depends on
and I think that helps with making the coroutine body a whole lot simpler
o
yea let me see what to do about that, I already have Dagger set up, just didn’t add DBHelper yet
m
😉
o
well I’ve got that set up now, but I’m not sure how things are now replaced
I am able to do dbHelper.doAsync{ } but inside no idea how to replicate the database.use.select
alright, well now it’s like this https://hastebin.com/atalidefav.js
d
@oday Did you try thirtyinch mvp lib, it helps in a lot of presenter wiring code...
o
never heard
I use it in most of my projects, and it's helps a lot for converting messy old code into MVP (which I did quite a few time...)