Home | History | Annotate | Download | only in calllog
      1 /*
      2  * Copyright (C) 2017 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 
     17 package com.android.dialer.calllog;
     18 
     19 import com.android.dialer.calllog.datasources.CallLogDataSource;
     20 import com.android.dialer.calllog.datasources.DataSources;
     21 import com.android.dialer.calllog.datasources.contacts.ContactsDataSource;
     22 import com.android.dialer.calllog.datasources.systemcalllog.SystemCallLogDataSource;
     23 import dagger.Module;
     24 import dagger.Provides;
     25 import java.util.Arrays;
     26 import java.util.Collections;
     27 import java.util.List;
     28 
     29 /** Dagger module which satisfies call log dependencies. */
     30 @Module
     31 public abstract class CallLogModule {
     32 
     33   @Provides
     34   static DataSources provideCallLogDataSources(
     35       SystemCallLogDataSource systemCallLogDataSource, ContactsDataSource contactsDataSource) {
     36     // System call log must be first, see getDataSourcesExcludingSystemCallLog below.
     37     List<CallLogDataSource> allDataSources =
     38         Collections.unmodifiableList(Arrays.asList(systemCallLogDataSource, contactsDataSource));
     39     return new DataSources() {
     40       @Override
     41       public SystemCallLogDataSource getSystemCallLogDataSource() {
     42         return systemCallLogDataSource;
     43       }
     44 
     45       @Override
     46       public List<CallLogDataSource> getDataSourcesIncludingSystemCallLog() {
     47         return allDataSources;
     48       }
     49 
     50       @Override
     51       public List<CallLogDataSource> getDataSourcesExcludingSystemCallLog() {
     52         return allDataSources.subList(1, allDataSources.size());
     53       }
     54     };
     55   }
     56 }
     57