blob: ef00b9fb6cfd3889900ea7992bba5333e157d093 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.libreoffice.ui;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import org.libreoffice.R;
import java.util.List;
class RecentFilesAdapter extends RecyclerView.Adapter<RecentFilesAdapter.ViewHolder> {
private final LibreOfficeUIActivity mActivity;
private final List<RecentFile> recentFiles;
RecentFilesAdapter(LibreOfficeUIActivity activity, List<RecentFile> recentFiles) {
this.mActivity = activity;
this.recentFiles = recentFiles;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View item = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_recent_files, parent, false);
return new ViewHolder(item);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
final RecentFile entry = recentFiles.get(position);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mActivity.openDocument(entry.getUri());
}
});
final String filename = entry.getDisplayName();
holder.textView.setText(filename);
int compoundDrawableInt = 0;
switch (FileUtilities.getType(filename)) {
case FileUtilities.DOC:
compoundDrawableInt = R.drawable.writer;
break;
case FileUtilities.CALC:
compoundDrawableInt = R.drawable.calc;
break;
case FileUtilities.DRAWING:
compoundDrawableInt = R.drawable.draw;
break;
case FileUtilities.IMPRESS:
compoundDrawableInt = R.drawable.impress;
break;
}
// set icon if known filetype was detected
if (compoundDrawableInt != 0)
holder.imageView.setImageDrawable(ContextCompat.getDrawable(mActivity, compoundDrawableInt));
}
@Override
public int getItemCount() {
return recentFiles.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
TextView textView;
ImageView imageView;
ViewHolder(View itemView) {
super(itemView);
this.textView = itemView.findViewById(R.id.textView);
this.imageView = itemView.findViewById(R.id.imageView);
}
}
}
|