10
10
import android .widget .BaseAdapter ;
11
11
import android .widget .ImageView ;
12
12
import android .widget .TextView ;
13
+
13
14
import com .developer .filepicker .R ;
14
15
import com .developer .filepicker .controller .NotifyItemChecked ;
15
16
import com .developer .filepicker .model .DialogConfigs ;
18
19
import com .developer .filepicker .model .MarkedItemList ;
19
20
import com .developer .filepicker .widget .MaterialCheckbox ;
20
21
import com .developer .filepicker .widget .OnCheckedChangeListener ;
21
- import java .text .SimpleDateFormat ;
22
+
23
+ import java .text .DateFormat ;
22
24
import java .util .ArrayList ;
23
25
import java .util .Date ;
24
- import java .util .Locale ;
25
26
26
27
/**
27
28
* @author akshay sunil masram
28
29
*/
29
- public class FileListAdapter extends BaseAdapter {
30
+ public class FileListAdapter extends BaseAdapter {
30
31
private ArrayList <FileListItem > listItem ;
31
32
private Context context ;
32
33
private DialogProperties properties ;
@@ -60,85 +61,74 @@ public View getView(final int i, View view, ViewGroup viewGroup) {
60
61
view = LayoutInflater .from (context ).inflate (R .layout .dialog_file_list_item , viewGroup , false );
61
62
holder = new ViewHolder (view );
62
63
view .setTag (holder );
63
- }
64
- else
65
- { holder = (ViewHolder )view .getTag ();
64
+ } else {
65
+ holder = (ViewHolder ) view .getTag ();
66
66
}
67
67
final FileListItem item = listItem .get (i );
68
68
if (MarkedItemList .hasItem (item .getLocation ())) {
69
- Animation animation = AnimationUtils .loadAnimation (context ,R .anim .marked_item_animation );
69
+ Animation animation = AnimationUtils .loadAnimation (context , R .anim .marked_item_animation );
70
70
view .setAnimation (animation );
71
- }
72
- else {
73
- Animation animation = AnimationUtils .loadAnimation (context ,R .anim .unmarked_item_animation );
71
+ } else {
72
+ Animation animation = AnimationUtils .loadAnimation (context , R .anim .unmarked_item_animation );
74
73
view .setAnimation (animation );
75
74
}
76
75
if (item .isDirectory ()) {
77
76
holder .type_icon .setImageResource (R .mipmap .ic_type_folder );
78
77
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
79
- holder .type_icon .setColorFilter (context .getResources ().getColor (R .color .colorPrimary ,context .getTheme ()));
78
+ holder .type_icon .setColorFilter (context .getResources ().getColor (R .color .colorPrimary , context .getTheme ()));
79
+ } else {
80
+ holder .type_icon .setColorFilter (context .getResources ().getColor (R .color .colorPrimary ));
80
81
}
81
- else
82
- { holder .type_icon .setColorFilter (context .getResources ().getColor (R .color .colorPrimary ));
82
+ if (properties .selection_type == DialogConfigs .FILE_SELECT ) {
83
+ holder .fmark .setVisibility (View .INVISIBLE );
84
+ } else {
85
+ holder .fmark .setVisibility (View .VISIBLE );
83
86
}
84
- if (properties .selection_type == DialogConfigs .FILE_SELECT )
85
- { holder .fmark .setVisibility (View .INVISIBLE );
86
- }
87
- else
88
- { holder .fmark .setVisibility (View .VISIBLE );
89
- }
90
- }
91
- else {
87
+ } else {
92
88
holder .type_icon .setImageResource (R .mipmap .ic_type_file );
93
89
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
94
- holder .type_icon .setColorFilter (context .getResources ().getColor (R .color .colorAccent ,context .getTheme ()));
90
+ holder .type_icon .setColorFilter (context .getResources ().getColor (R .color .colorAccent , context .getTheme ()));
91
+ } else {
92
+ holder .type_icon .setColorFilter (context .getResources ().getColor (R .color .colorAccent ));
95
93
}
96
- else
97
- { holder .type_icon .setColorFilter (context .getResources ().getColor (R .color .colorAccent ));
98
- }
99
- if (properties .selection_type == DialogConfigs .DIR_SELECT )
100
- { holder .fmark .setVisibility (View .INVISIBLE );
101
- }
102
- else
103
- { holder .fmark .setVisibility (View .VISIBLE );
94
+ if (properties .selection_type == DialogConfigs .DIR_SELECT ) {
95
+ holder .fmark .setVisibility (View .INVISIBLE );
96
+ } else {
97
+ holder .fmark .setVisibility (View .VISIBLE );
104
98
}
105
99
}
106
100
holder .type_icon .setContentDescription (item .getFilename ());
107
101
holder .name .setText (item .getFilename ());
108
- SimpleDateFormat sdate = new SimpleDateFormat ( "dd/MM/yyyy" , Locale . getDefault () );
109
- SimpleDateFormat stime = new SimpleDateFormat ( "hh:mm aa" , Locale . getDefault () );
102
+ DateFormat dateFormatter = android . text . format . DateFormat . getMediumDateFormat ( context );
103
+ DateFormat timeFormatter = android . text . format . DateFormat . getTimeFormat ( context );
110
104
Date date = new Date (item .getTime ());
111
- if ( i == 0 && item .getFilename ().startsWith (context .getString (R .string .label_parent_dir ))) {
105
+ if ( i == 0 && item .getFilename ().startsWith (context .getString (R .string .label_parent_dir ))) {
112
106
holder .type .setText (R .string .label_parent_directory );
107
+ } else {
108
+ holder .type .setText (String .format (context .getString (R .string .last_edit ), dateFormatter .format (date ), timeFormatter .format (date )));
113
109
}
114
- else {
115
- holder .type .setText (context .getString (R .string .last_edit ) + sdate .format (date ) + ", " + stime .format (date ));
116
- }
117
- if (holder .fmark .getVisibility ()==View .VISIBLE ) {
118
- if (i ==0 &&item .getFilename ().startsWith (context .getString (R .string .label_parent_dir )))
119
- { holder .fmark .setVisibility (View .INVISIBLE );
110
+ if (holder .fmark .getVisibility () == View .VISIBLE ) {
111
+ if (i == 0 && item .getFilename ().startsWith (context .getString (R .string .label_parent_dir ))) {
112
+ holder .fmark .setVisibility (View .INVISIBLE );
120
113
}
121
114
if (MarkedItemList .hasItem (item .getLocation ())) {
122
115
holder .fmark .setChecked (true );
123
- }
124
- else {
116
+ } else {
125
117
holder .fmark .setChecked (false );
126
118
}
127
119
}
128
-
120
+
129
121
holder .fmark .setOnCheckedChangedListener (new OnCheckedChangeListener () {
130
122
@ Override
131
123
public void onCheckedChanged (MaterialCheckbox checkbox , boolean isChecked ) {
132
124
item .setMarked (isChecked );
133
125
if (item .isMarked ()) {
134
- if (properties .selection_mode == DialogConfigs .MULTI_MODE ) {
126
+ if (properties .selection_mode == DialogConfigs .MULTI_MODE ) {
135
127
MarkedItemList .addSelectedItem (item );
136
- }
137
- else {
128
+ } else {
138
129
MarkedItemList .addSingleFile (item );
139
130
}
140
- }
141
- else {
131
+ } else {
142
132
MarkedItemList .removeSelectedItem (item .getLocation ());
143
133
}
144
134
notifyItemChecked .notifyCheckBoxIsClicked ();
@@ -147,16 +137,16 @@ public void onCheckedChanged(MaterialCheckbox checkbox, boolean isChecked) {
147
137
return view ;
148
138
}
149
139
150
- private class ViewHolder
151
- { ImageView type_icon ;
152
- TextView name ,type ;
140
+ private class ViewHolder {
141
+ ImageView type_icon ;
142
+ TextView name , type ;
153
143
MaterialCheckbox fmark ;
154
144
155
145
ViewHolder (View itemView ) {
156
- name = itemView .findViewById (R .id .fname );
157
- type = itemView .findViewById (R .id .ftype );
158
- type_icon = itemView .findViewById (R .id .image_type );
159
- fmark = itemView .findViewById (R .id .file_mark );
146
+ name = itemView .findViewById (R .id .fname );
147
+ type = itemView .findViewById (R .id .ftype );
148
+ type_icon = itemView .findViewById (R .id .image_type );
149
+ fmark = itemView .findViewById (R .id .file_mark );
160
150
}
161
151
}
162
152
0 commit comments