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 package com.android.documentsui.inspector;
17 
18 import android.content.Context;
19 import android.text.format.Formatter;
20 import android.util.AttributeSet;
21 
22 import com.android.documentsui.DocumentsApplication;
23 import com.android.documentsui.R;
24 import com.android.documentsui.base.DocumentInfo;
25 import com.android.documentsui.base.Lookup;
26 import com.android.documentsui.inspector.InspectorController.DetailsDisplay;
27 
28 /**
29  * Displays the basic details about a file.
30  */
31 public class DetailsView extends TableView implements DetailsDisplay {
32 
DetailsView(Context context)33     public DetailsView(Context context) {
34         this(context, null);
35     }
36 
DetailsView(Context context, AttributeSet attrs)37     public DetailsView(Context context, AttributeSet attrs) {
38         this(context, attrs, 0);
39     }
40 
DetailsView(Context context, AttributeSet attrs, int defStyleAttr)41     public DetailsView(Context context, AttributeSet attrs, int defStyleAttr) {
42         super(context, attrs, defStyleAttr);
43     }
44 
45     @Override
accept(DocumentInfo doc, String displayName)46     public void accept(DocumentInfo doc, String displayName) {
47 
48         putTitle(displayName, false);
49 
50         Lookup<String, String> fileTypeLookup =
51                 DocumentsApplication.getFileTypeLookup(getContext());
52 
53         String mimeType = fileTypeLookup.lookup(doc.mimeType);
54 
55         put(R.string.sort_dimension_file_type, mimeType);
56 
57         // TODO: Each of these rows need to be removed if the condition is false and previously
58         // set.
59         if (doc.size >= 0 && !doc.isDirectory()) {
60             put(R.string.sort_dimension_size, Formatter.formatFileSize(getContext(), doc.size));
61         }
62 
63         if (doc.lastModified > 0) {
64             put(R.string.sort_dimension_date,
65                     DateUtils.formatDate(this.getContext(), doc.lastModified));
66         }
67 
68         // We only show summary field when doc is partial (meaning an active download).
69         // The rest of the time "summary" tends to be less than useful. For example
70         // after a download is completed DownloadsProvider include the orig filename
71         // in the summary field. This is confusing to folks in-and-if-itself, but
72         // after the file is renamed, it creates even more confusion (since it still
73         // shows the original). For that reason, and others. We only display on partial files.
74         if (doc.isPartial() && doc.summary != null) {
75             put(R.string.sort_dimension_summary, doc.summary);
76         }
77     }
78 
79     @Override
setChildrenCount(int count)80     public void setChildrenCount(int count) {
81         put(R.string.directory_items, String.valueOf(count));
82     }
83 }
84