If you think the Android project TuentiTV listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright (C) 2014 Pedro Vicente Gmez Snchez.
*/*fromwww.java2s.com*/
* 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.github.pedrovgs.tuentitv.presenter;
import com.github.pedrovgs.tuentitv.model.Agenda;
import com.github.pedrovgs.tuentitv.model.Chat;
import com.github.pedrovgs.tuentitv.ui.data.CardInfo;
import javax.inject.Inject;
/**
* Presenter used by DetailFragment and created to implement all the presentation logic related to
* show one contact or one ConversationSummary as detailed information. To work with this
* presenter, the presenter client have to register a view and also indicate which is the element
* id to show.
*
* This class is designed to show information to CardInfo interface instead of ConversationSummary
* or Contact to improve the coupling between view implementations and model knowledge. Agenda and
* Chat objects are going to be used as data repositories to find elements using CardInfo id.
*
* @author Pedro Vicente Gmez Snchez.
*/publicclass DetailPresenter {
privatefinal Agenda agenda;
privatefinal Chat chat;
private View view;
@Inject public DetailPresenter(Agenda agenda, Chat chat) {
this.agenda = agenda;
this.chat = chat;
}
publicvoid setView(View view) {
this.view = view;
}
/**
* Using a content id search a CardInfo instance to show inside user Agenda or user Chat. Once
* the information is ready, this CardInfo instance is used to show that info to the user.
*/publicvoid loadContent(String contentId) {
CardInfo cardInfo = loadCardInfo(contentId);
showBackground(cardInfo);
showCardInfoDetails(cardInfo);
}
private CardInfo loadCardInfo(String contentId) {
CardInfo cardInfo = null;
cardInfo = agenda.getContactById(contentId);
if (cardInfo == null) {
cardInfo = chat.getConversationById(contentId);
}
return cardInfo;
}
privatevoid showBackground(CardInfo cardInfo) {
view.showBackground(cardInfo.getSecondaryImage());
}
privatevoid showCardInfoDetails(CardInfo cardInfo) {
view.showCardInfo(cardInfo);
}
publicinterface View {
void showBackground(String backgroundUrl);
void showCardInfo(CardInfo cardInfo);
}
}