1/*
2 * Copyright (c) 2018, Daniel Gultsch All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation and/or
12 * other materials provided with the distribution.
13 *
14 * 3. Neither the name of the copyright holder nor the names of its contributors
15 * may be used to endorse or promote products derived from this software without
16 * specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30package eu.siacs.conversations.ui;
31
32
33import android.app.Fragment;
34import android.app.FragmentTransaction;
35import android.databinding.DataBindingUtil;
36import android.os.Bundle;
37import android.support.annotation.IdRes;
38import android.util.Log;
39
40import eu.siacs.conversations.Config;
41import eu.siacs.conversations.R;
42import eu.siacs.conversations.databinding.ActivityConversationsBinding;
43import eu.siacs.conversations.entities.Conversation;
44import eu.siacs.conversations.ui.interfaces.OnConversationArchived;
45import eu.siacs.conversations.ui.interfaces.OnConversationRead;
46import eu.siacs.conversations.ui.interfaces.OnConversationSelected;
47import eu.siacs.conversations.ui.interfaces.OnConversationsListItemUpdated;
48import eu.siacs.conversations.ui.service.EmojiService;
49
50public class ConversationsMainActivity extends XmppActivity implements OnConversationSelected, OnConversationArchived, OnConversationsListItemUpdated, OnConversationRead {
51
52 private ActivityConversationsBinding binding;
53
54 @Override
55 protected void refreshUiReal() {
56
57 }
58
59 @Override
60 void onBackendConnected() {
61 notifyFragment(R.id.main_fragment);
62 notifyFragment(R.id.secondary_fragment);
63 }
64
65 private void notifyFragment(@IdRes int id) {
66 Fragment mainFragment = getFragmentManager().findFragmentById(id);
67 if (mainFragment != null && mainFragment instanceof XmppFragment) {
68 ((XmppFragment) mainFragment).onBackendConnected();
69 }
70 }
71
72 @Override
73 protected void onCreate(final Bundle savedInstanceState) {
74 super.onCreate(savedInstanceState);
75 new EmojiService(this).init();
76 this.binding = DataBindingUtil.setContentView(this,R.layout.activity_conversations);
77 this.initializeFragments();
78 }
79
80 @Override
81 public void onConversationSelected(Conversation conversation) {
82 Log.d(Config.LOGTAG,"selected "+conversation.getName());
83 ConversationFragment conversationFragment = (ConversationFragment) getFragmentManager().findFragmentById(R.id.secondary_fragment);
84 if (conversationFragment == null) {
85 conversationFragment = new ConversationFragment();
86 FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
87 fragmentTransaction.replace(R.id.main_fragment,conversationFragment);
88 fragmentTransaction.commit();
89 }
90 conversationFragment.reInit(conversation);
91 }
92
93 private void initializeFragments() {
94 FragmentTransaction transaction = getFragmentManager().beginTransaction();
95 transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
96 if (binding.secondaryFragment != null) {
97 transaction.replace(R.id.secondary_fragment, new ConversationFragment());
98 }
99 transaction.commit();
100 }
101
102 @Override
103 public void onConversationArchived(Conversation conversation) {
104
105 }
106
107 @Override
108 public void onConversationsListItemUpdated() {
109
110 }
111
112 @Override
113 public void onConversationRead(Conversation conversation) {
114 Log.d(Config.LOGTAG,"read event for "+conversation.getName()+" received");
115 }
116}