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