 Pandit called working with both Singh and Fazli an honour.
package com.krm.tmdb.ui.activities.main

import android.content.Context
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import com.krm.tmdb.data.api.NewsApi
import com.krm.tmdb.ui.activities.base.BaseInteractor
import com.krm.tmdb.R
import com.krm.tmdb.ui.fragments.home.FragmentHome
import com.krm.tmdb.ui.fragments.movies.FragmentMovies
import com.krm.tmdb.ui.fragments.people.FragmentPeople
import com.krm.tmdb.ui.fragments.search.FragmentSearch
import com.krm.tmdb.ui.fragments.tvshows.FragmentTvShow
import com.krm.tmdb.utils.ConstStrings
import javax.inject.Inject

/**
 * Created by <NAME> on 16/02/19.
 */
class InteractorMain<V : InterfaceMainView> @Inject constructor(supportFragment: FragmentManager, context: Context, api: NewsApi) : BaseInteractor<V>(supportFragment, context,api),
    InterfaceMainInteractor<V> {

    private var fragmentSearch = FragmentSearch()
    private var fragmentHome = FragmentHome()
    private var fragmentMovies = FragmentMovies()
    private var fragmentTvShow = FragmentTvShow()

    override fun setFragmentHome() {
        getView().setDrawerUnLock()
        getView().setCheckedNavigationItem(R.id.nav_home)
        getView().closeNavigationDrawer()
        setTitleToolbar(getContext().resources.getString(R.string.home))
        setFragment(fragmentHome)
    }

    override fun setFragmentMovies() {
        getView().setCheckedNavigationItem(R.id.nav_movies)
        getView().closeNavigationDrawer()
        setTitleToolbar(getContext().resources.getString(R.string.movies))
        setFragment(fragmentMovies)
    }

    override fun setFragmentSeries() {
        getView().setCheckedNavigationItem(R.id.nav_tv_shows)
        getView().closeNavigationDrawer()
        setTitleToolbar(getContext().resources.getString(R.string.tv_shows))
        setFragment(fragmentTvShow)
    }

    override fun setFragmentPeople() {
        getView().setCheckedNavigationItem(R.id.nav_people)
        getView().closeNavigationDrawer()
        setTitleToolbar(getContext().resources.getString(R.string.people))
        setFragment(FragmentPeople())
    }

    override fun setFragmentSearch() {
        getView().setDrawerLock()
        getSupportFragmentManager()
               .beginTransaction()
               .disallowAddToBackStack()
               .setCustomAnimations(R.anim.fade_in, R.anim.fade_out)
               .add(R.id.frame_principal, fragmentSearch, ConstStrings.SEARCH_TAG)
               .commit()
    }

    override fun closeFragmentSearch(tag: String) {
        val fragmentManager = getSupportFragmentManager()
        val fragment = fragmentManager.findFragmentByTag(tag)
        if (fragment!= null) {
            fragmentManager
                   .beginTransaction()
                   .disallowAddToBackStack()
                   .setCustomAnimations(R.anim.fade_in, R.anim.fade_out)
                   .remove(fragment)
                   .commitNow()
            getView().setDrawerUnLock()
        }
    }

    override fun getFragmentSearch(): FragmentSearch = fragmentSearch
    override fun getFragmentHome(): FragmentHome = fragmentHome
    override fun getFragmentMovies(): FragmentMovies = fragmentMovies
    override fun getFragmentTvShow(): FragmentTvShow = fragmentTvShow

    private fun setTitleToolbar(title: String) {
        getView().setTitleToolbar(title)
    }

    private fun setFragment(fragment: Fragment) {
        val fragmentManager = getSupportFragmentManager()
        val fragmentNow = fragmentManager.findFragmentByTag(ConstStrings.TYPE_FRAGMENT)
        val trans = fragmentManager.beginTransaction()
        if (fragmentNow!= null) {
            trans.remove(fragmentNow)
        }
        trans.disallowAddToBackStack()
        trans.setCustomAnimations(R.anim.fade_in, R.anim.fade_out)
        trans.replace(R.id.frame_principal, fragment, ConstStrings.TYPE_FRAGMENT)
        trans.commitNow()
    }
}Lämnade Gran Canaria 13.30 i vindhastighet om 20 knop NO vindriktning.
Med blå himmel å blått vatten hoppade vi i plurret. Därefter satte vi saxade segel och pep iväg i 9 knop.
Efter att ha lämnat syd spetsen av Gran Canaria valde vinden helt enkelt att bli dekadent och vrida sig SO riktning och 10 knop.
Detta resulterade att vi valde att hissa "järn genuan" och stånka på i 7 knop under natten.
Skift delades bryskt ut under höga protester och livlig diskussion. Självklart skulle kapten sova.
Andra vakten 02-05 satts av Bob och Carl Anders, som efter allt att döma lyckades hålla sig vakna. Rykten florerar att uppsikten var lite grumlig.
Sista vakten 05-08 satts av de alerta gossarna Pim och Fredrik, som räknade stjärnfall efter 2 timmar hade kapten fått nog och kom upp för att hissa och sedan ta ner seglen. Sedan morgon rodnade solen och bjöd på en fantastisk föreställning.
Efter att ha tagit ner förseglet igen, gick kaptenen bryskt in på diskussionen när klockan ska ställas om till Cap Verde tid. "Om vi ställer om den kl 18, så får vi två happy hour idag". Det finns misstanke om att detta tagits upp vid flertalet tillfällen under natten.
Breakfast is organised chaos after which all except Viola and Uno head for shore clutching their Computers for one last Wi-Fi internet connection.
Frederick is charged with sending off the latest Blog and the latest Pictures, while I try to arrange my return air ticket. Both of us are having problems with the slow speed of the connection and move to the "Sailor", another café further down the road.
No success trying to get online because of the speed. We try with Frederick's Computer but end up having to fill in the details in Spanish, which then fails, as it won't accept a U.K. credit card. After nearly 3 hours I give up and decide to give Shan a call to try it from her end.
Back to the boat and 2pm sees us up anchor as the rain clouds gather over the island and follow us down the coast. We lunch on the way and after several hours we pull into the lee of a headland and everybody jumps overboard for a swim and a fresh water shower on the stern.
Shan's a "Star" and comes up trumps having not only booked the ticket but at a cheaper price. It's going to be long haul though 13hours via Lisbon and Copenhagen.
Pim disappears on the sugars-coop stern with a bucket of vegetable whilst Viola is busy in the galley chopping up a large joint of pork. This cooked in Soy sauce and vinegar served with potatoes and carrots makes for a very tasty dinner to celebrate our first night at sea. The two cardboard box of 65cent wine do prove drinkable! But perhaps not to be repeated.
Watches are set and lots drawn. Viola and Uno 2300-0200, Bob and Charlaners 0200-0500 and the two "boys" Frederick and Pim 0500-0800. As there is an odd on and Lars being Skipper is assumed to be on call so is not counted. Soon everyone sneaks of to their respective Bunks leaving a lonesome Lars the last man standing until the first watch reappear.
As we are now motor sailing, the wind having dropped not long after sunset. There is little to do but check the AIS and keep a lookout, between reading ones book. Occasionally the wind picks up and I try to set the sail but its soon flogging and making a terrible noise and has to be sheeted in.
The time passes quickly and at 0500we are relieved and so to bed.
Most are up and breakfast