Java tutorial
/* * Copyright (C) 2016 Oleg Kan * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.simplaapliko.trips.presentation.navigation; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.support.v4.app.FragmentManager; import com.simplaapliko.trips.R; import com.simplaapliko.trips.presentation.activity.EditPlaceActivity; import com.simplaapliko.trips.presentation.activity.EditTripActivity; import com.simplaapliko.trips.presentation.activity.TripActivity; import com.simplaapliko.trips.presentation.activity.TripListPagerActivity; import com.simplaapliko.trips.presentation.adapter.OnArchiveTripListener; import com.simplaapliko.trips.presentation.adapter.OnDeleteListener; import com.simplaapliko.trips.presentation.fragment.ConfirmationDialog; import com.simplaapliko.trips.presentation.fragment.SelectColorDialog; import com.simplaapliko.trips.presentation.fragment.SelectDateDialog; import com.simplaapliko.trips.presentation.fragment.SelectLabelDialog; import com.simplaapliko.trips.presentation.fragment.SelectTimeDialog; import com.simplaapliko.trips.presentation.fragment.SelectTripDateDialog; import com.simplaapliko.trips.presentation.model.PlaceModel; import com.simplaapliko.trips.presentation.model.TripDateModel; import com.simplaapliko.trips.presentation.model.TripModel; import java.util.Date; import java.util.List; import javax.inject.Inject; import javax.inject.Singleton; @Singleton public class Navigator { public interface EventType { int CREATE_TRIP = 1; int EDIT_TRIP = 2; int VIEW_TRIP = 3; int CREATE_PLACE = 4; int EDIT_PLACE = 5; } @Inject Context mContext; @Inject public Navigator() { } public void navigateToAddPlace(Activity activity, long tripId) { if (activity != null) { Intent intentToLaunch = EditPlaceActivity.getAddCallingIntent(activity, tripId); activity.startActivityForResult(intentToLaunch, EventType.CREATE_PLACE); } } public void navigateToEditPlace(Activity activity, long placeId, long tripId) { if (activity != null) { Intent intentToLaunch = EditPlaceActivity.getEditCallingIntent(activity, placeId, tripId); activity.startActivityForResult(intentToLaunch, EventType.EDIT_PLACE); } } public void navigateToAddTrip(Activity activity) { if (activity != null) { Intent intentToLaunch = EditTripActivity.getCallingIntent(activity); activity.startActivityForResult(intentToLaunch, EventType.CREATE_TRIP); } } public void navigateToEditTrip(Activity activity, long tripId) { if (activity != null) { Intent intentToLaunch = EditTripActivity.getCallingIntent(activity, tripId); activity.startActivityForResult(intentToLaunch, EventType.EDIT_TRIP); } } public void navigateToTrip(Activity activity, long tripId) { if (activity != null) { Intent intentToLaunch = TripActivity.getCallingIntent(activity, tripId); activity.startActivityForResult(intentToLaunch, EventType.VIEW_TRIP); } } public void navigateToTripListPager(Context context) { if (context != null) { Intent intentToLaunch = TripListPagerActivity.getCallingIntent(context); context.startActivity(intentToLaunch); } } public void showArchiveTripConfirmationDialog(FragmentManager fragmentManager, OnArchiveTripListener onArchiveTripListener, TripModel tripModel) { OnConfirmTrip.Archive archiveListener = OnConfirmTrip.Archive.getInstance(onArchiveTripListener, tripModel); ConfirmationDialog dialog = ConfirmationDialog .newInstance(mContext.getString(R.string.archive_trip_confirmation)); dialog.setOnConfirmClickListener(archiveListener); dialog.show(fragmentManager, SelectDateDialog.class.getSimpleName()); } public void showDeleteTripConfirmationDialog(FragmentManager fragmentManager, OnDeleteListener<TripModel> onDeleteListener, TripModel tripModel) { OnConfirmTrip.Delete deleteListener = OnConfirmTrip.Delete.getInstance(onDeleteListener, tripModel); ConfirmationDialog dialog = ConfirmationDialog .newInstance(mContext.getString(R.string.delete_trip_confirmation)); dialog.setOnConfirmClickListener(deleteListener); dialog.show(fragmentManager, SelectDateDialog.class.getSimpleName()); } public void showDeletePlaceConfirmationDialog(FragmentManager fragmentManager, OnDeleteListener<PlaceModel> onDeleteListener, PlaceModel placeModel) { OnConfirmPlace.Delete deleteListener = OnConfirmPlace.Delete.getInstance(onDeleteListener, placeModel); ConfirmationDialog dialog = ConfirmationDialog .newInstance(mContext.getString(R.string.delete_place_confirmation)); dialog.setOnConfirmClickListener(deleteListener); dialog.show(fragmentManager, SelectDateDialog.class.getSimpleName()); } public void showSelectColorDialog(FragmentManager fragmentManager, SelectColorDialog.OnColorSelectedListener onColorSelectedListener) { SelectColorDialog dialog = SelectColorDialog.newInstance(); dialog.setOnColorSelectedListener(onColorSelectedListener); dialog.show(fragmentManager, SelectColorDialog.class.getSimpleName()); } public void showSelectDateDialog(FragmentManager fragmentManager, SelectDateDialog.OnDateChangedListener onDateChangedListener) { showSelectDateDialog(fragmentManager, onDateChangedListener, new Date()); } public void showSelectDateDialog(FragmentManager fragmentManager, SelectDateDialog.OnDateChangedListener onDateChangedListener, Date date) { SelectDateDialog dialog = SelectDateDialog.newInstance(date); dialog.setOnDateChangedListener(onDateChangedListener); dialog.show(fragmentManager, SelectDateDialog.class.getSimpleName()); } public void showSelectLabelDialog(FragmentManager fragmentManager, SelectLabelDialog.OnLabelSelectListener onLabelSelectListener) { SelectLabelDialog dialog = SelectLabelDialog.newInstance(); dialog.setOnLabelSelectListener(onLabelSelectListener); dialog.show(fragmentManager, SelectLabelDialog.class.getSimpleName()); } public void showSelectTimeDialog(FragmentManager fragmentManager, SelectTimeDialog.OnTimeChangedListener onTimeChangedListener) { showSelectTimeDialog(fragmentManager, onTimeChangedListener, new Date()); } public void showSelectTimeDialog(FragmentManager fragmentManager, SelectTimeDialog.OnTimeChangedListener onTimeChangedListener, Date date) { SelectTimeDialog dialog = SelectTimeDialog.newInstance(date); dialog.setOnTimeChangedListener(onTimeChangedListener); dialog.show(fragmentManager, SelectTimeDialog.class.getSimpleName()); } public void showSelectTripDateDialog(FragmentManager fragmentManager, SelectTripDateDialog.OnTripDateSelectListener onTripDateSelectListener, List<TripDateModel> tripDateModels) { SelectTripDateDialog dialog = SelectTripDateDialog.newInstance(); dialog.setOnTripDateClickListener(onTripDateSelectListener); dialog.setTripDates(tripDateModels); dialog.show(fragmentManager, SelectTripDateDialog.class.getSimpleName()); } }