2018-02-13 21:02:46 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Paul Schaub
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2018-02-12 02:08:56 +01:00
|
|
|
package de.vanitasvitae.slam.mvp.view;
|
|
|
|
|
2018-02-13 21:02:46 +01:00
|
|
|
import android.content.Intent;
|
2018-02-12 02:08:56 +01:00
|
|
|
import android.os.Bundle;
|
2018-02-13 21:02:46 +01:00
|
|
|
import android.support.v4.app.Fragment;
|
|
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2018-02-12 02:08:56 +01:00
|
|
|
|
|
|
|
import org.jxmpp.jid.BareJid;
|
|
|
|
|
2018-02-13 21:02:46 +01:00
|
|
|
import java.util.ArrayList;
|
2018-02-12 02:08:56 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2018-02-13 21:02:46 +01:00
|
|
|
import butterknife.BindView;
|
|
|
|
import butterknife.ButterKnife;
|
2018-02-12 02:08:56 +01:00
|
|
|
import de.vanitasvitae.slam.R;
|
|
|
|
import de.vanitasvitae.slam.mvp.PresenterFactory;
|
|
|
|
import de.vanitasvitae.slam.mvp.contracts.ContactListContract;
|
2018-02-13 21:02:46 +01:00
|
|
|
import de.vanitasvitae.slam.ui.ContactListEntry;
|
|
|
|
import de.vanitasvitae.slam.xmpp.Contact;
|
2018-02-12 02:08:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Paul Schaub on 11.02.18.
|
|
|
|
*/
|
|
|
|
public class ContactListFragment extends Fragment implements ContactListContract.View {
|
|
|
|
|
2018-02-13 21:02:46 +01:00
|
|
|
@BindView(R.id.recycler_list)
|
|
|
|
RecyclerView recyclerView;
|
|
|
|
|
2018-02-12 02:08:56 +01:00
|
|
|
private final ContactListContract.Presenter presenter;
|
|
|
|
|
2018-02-13 21:02:46 +01:00
|
|
|
private final List<Contact> contacts = new ArrayList<>();
|
|
|
|
|
2018-02-12 02:08:56 +01:00
|
|
|
public ContactListFragment() {
|
|
|
|
super();
|
|
|
|
this.presenter = PresenterFactory.getInstance().createContactListPresenter(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-02-13 21:02:46 +01:00
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
|
Bundle savedInstanceState) {
|
|
|
|
View view = inflater.inflate(R.layout.fragment_conversation_contact_list, container, false);
|
|
|
|
ButterKnife.bind(this, view);
|
|
|
|
return view;
|
|
|
|
}
|
2018-02-12 02:08:56 +01:00
|
|
|
|
2018-02-13 21:02:46 +01:00
|
|
|
@Override
|
|
|
|
public void onViewCreated(final View view, Bundle savedInstanceState) {
|
|
|
|
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
|
|
|
recyclerView.setAdapter(contactsAdapter);
|
|
|
|
contactsAdapter.notifyDataSetChanged();
|
2018-02-12 02:08:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-02-13 21:02:46 +01:00
|
|
|
public void addContactListItems(List<Contact> contacts) {
|
|
|
|
this.contacts.addAll(contacts);
|
|
|
|
contactsAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2018-02-12 02:08:56 +01:00
|
|
|
|
2018-02-13 21:02:46 +01:00
|
|
|
@Override
|
|
|
|
public void clearContactListItems() {
|
|
|
|
this.contacts.clear();
|
|
|
|
contactsAdapter.notifyDataSetChanged();
|
2018-02-12 02:08:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdateContactPresence() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void showContactListLoadingIndicator() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void hideContactListLoadingIndicator() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-13 21:02:46 +01:00
|
|
|
private final RecyclerView.Adapter<ContactListEntry> contactsAdapter = new RecyclerView.Adapter<ContactListEntry>() {
|
|
|
|
@Override
|
|
|
|
public ContactListEntry onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
View contactView = LayoutInflater.from(getActivity()).inflate(R.layout.item_contact, parent, false);
|
|
|
|
return new ContactListEntry(contactView);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(ContactListEntry holder, int position) {
|
|
|
|
final Contact contact = contacts.get(holder.getAdapterPosition());
|
|
|
|
holder.bind(contact);
|
|
|
|
holder.setOnAvatarClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
navigateToContactDetail(contact.getJid());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
return contacts.size();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-02-12 02:08:56 +01:00
|
|
|
@Override
|
|
|
|
public void navigateToConversation(BareJid contact) {
|
|
|
|
ConversationFragment fragment = new ConversationFragment();
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
bundle.putString(ConversationFragment.KEY_JID, contact.toString());
|
|
|
|
fragment.setArguments(bundle);
|
|
|
|
|
|
|
|
getFragmentManager().beginTransaction()
|
|
|
|
.add(R.id.fragment_container, fragment)
|
|
|
|
.addToBackStack("conversation")
|
|
|
|
.commit();
|
|
|
|
}
|
2018-02-13 21:02:46 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void navigateToContactDetail(BareJid contact) {
|
|
|
|
startActivity(new Intent(getContext(), ContactDetailActivity.class));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-12 02:08:56 +01:00
|
|
|
}
|