1 /*
2  * Copyright (C) 2016 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.documentsui.sidebar;
18 
19 import android.view.DragEvent;
20 import android.view.LayoutInflater;
21 import android.view.Menu;
22 import android.view.MenuInflater;
23 import android.view.View;
24 import android.view.ViewGroup;
25 
26 import androidx.annotation.LayoutRes;
27 import androidx.annotation.Nullable;
28 
29 import com.android.documentsui.MenuManager;
30 import com.android.documentsui.R;
31 import com.android.documentsui.base.UserId;
32 
33 /**
34  * Describes a root navigation point of documents. Each one of them is presented as an item in the
35  * sidebar
36  */
37 public abstract class Item {
38     private final @LayoutRes int mLayoutId;
39 
40     public final String title;
41     public final UserId userId;
42     final String stringId;
43 
Item(@ayoutRes int layoutId, String title, String stringId, UserId userId)44     public Item(@LayoutRes int layoutId, String title, String stringId, UserId userId) {
45         mLayoutId = layoutId;
46         this.title = title;
47         this.stringId = stringId;
48         this.userId = userId;
49     }
50 
getView(View convertView, ViewGroup parent)51     public View getView(View convertView, ViewGroup parent) {
52         if (convertView == null
53                 || (Integer) convertView.getTag(R.id.layout_id_tag) != mLayoutId) {
54             convertView = LayoutInflater.from(parent.getContext())
55                     .inflate(mLayoutId, parent, false);
56         }
57         convertView.setTag(R.id.layout_id_tag, mLayoutId);
58         bindView(convertView);
59         return convertView;
60     }
61 
bindView(View convertView)62     abstract void bindView(View convertView);
63 
isRoot()64     abstract boolean isRoot();
65 
open()66     abstract void open();
67 
68     /**
69      * Get the package name string.
70      */
getPackageName()71     public String getPackageName() {
72         return "";
73     }
74 
75     /**
76      * Get the root or app summary such as account information.
77      */
getSummary()78     public @Nullable String getSummary() {
79         return null;
80     }
81 
isDropTarget()82     boolean isDropTarget() {
83         return isRoot();
84     }
85 
dropOn(DragEvent event)86     boolean dropOn(DragEvent event) {
87         return false;
88     }
89 
showAppDetails()90     boolean showAppDetails() {
91         return false;
92     }
93 
createContextMenu(Menu menu, MenuInflater inflater, MenuManager menuManager)94     void createContextMenu(Menu menu, MenuInflater inflater, MenuManager menuManager) {}
95 }
96