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