1d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd/* 2d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Copyright (C) 2015 The Android Open Source Project 3d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 4d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Licensed under the Apache License, Version 2.0 (the "License"); 5d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * you may not use this file except in compliance with the License. 6d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * You may obtain a copy of the License at 7d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 8d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * http://www.apache.org/licenses/LICENSE-2.0 9d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 10d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Unless required by applicable law or agreed to in writing, software 11d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * distributed under the License is distributed on an "AS IS" BASIS, 12d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * See the License for the specific language governing permissions and 14d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * limitations under the License. 15d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 16d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpackage com.android.messaging.ui; 17d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 18d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.app.Fragment; 19d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.content.Context; 20d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.content.Intent; 21d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.database.Cursor; 22d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.os.Bundle; 23d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.support.v4.widget.CursorAdapter; 24d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.view.LayoutInflater; 25d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.view.View; 26d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.view.ViewGroup; 27d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.widget.ListView; 28d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 29d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.R; 30d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.datamodel.binding.Binding; 31d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.datamodel.binding.BindingBase; 32d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.datamodel.data.BlockedParticipantsData; 33d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.datamodel.data.BlockedParticipantsData.BlockedParticipantsDataListener; 34d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.datamodel.DataModel; 35d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.util.Assert; 36d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 37d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd/** 38d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Show a list of currently blocked participants. 39d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 40d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpublic class BlockedParticipantsFragment extends Fragment 41d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd implements BlockedParticipantsDataListener { 42d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private ListView mListView; 43d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private BlockedParticipantListAdapter mAdapter; 44d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private final Binding<BlockedParticipantsData> mBinding = 45d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd BindingBase.createBinding(this); 46d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 47d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 48d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void onCreate(final Bundle savedInstanceState) { 49d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd super.onCreate(savedInstanceState); 50d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 51d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 52d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 53d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public View onCreateView(final LayoutInflater inflater, final ViewGroup container, 54d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final Bundle savedInstanceState) { 55d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final View view = 56d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd inflater.inflate(R.layout.blocked_participants_fragment, container, false); 57d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mListView = (ListView) view.findViewById(android.R.id.list); 58d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mAdapter = new BlockedParticipantListAdapter(getActivity(), null); 59d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mListView.setAdapter(mAdapter); 60d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mBinding.bind(DataModel.get().createBlockedParticipantsData(getActivity(), this)); 61d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mBinding.getData().init(getLoaderManager(), mBinding); 62d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return view; 63d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 64d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 65d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 66d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { 67d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd super.onActivityResult(requestCode, resultCode, data); 68d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 69d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 70d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 71d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void onDestroy() { 72d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd super.onDestroy(); 73d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mBinding.unbind(); 74d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 75d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 76d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd /** 77d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * An adapter to display ParticipantListItemView based on ParticipantData. 78d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 79d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private class BlockedParticipantListAdapter extends CursorAdapter { 80d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public BlockedParticipantListAdapter(final Context context, final Cursor cursor) { 81d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd super(context, cursor, 0); 82d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 83d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 84d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 85d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public View newView(Context context, Cursor cursor, ViewGroup parent) { 86d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return LayoutInflater.from(context) 87d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd .inflate(R.layout.blocked_participant_list_item_view, parent, false); 88d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 89d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 90d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 91d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void bindView(View view, Context context, Cursor cursor) { 92d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd Assert.isTrue(view instanceof BlockedParticipantListItemView); 93d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ((BlockedParticipantListItemView) view).bind( 94d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mBinding.getData().createParticipantListItemData(cursor)); 95d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 96d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 97d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 98d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 99d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void onBlockedParticipantsCursorUpdated(Cursor cursor) { 100d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mAdapter.swapCursor(cursor); 101d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 102d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd} 103