1010import android .widget .BaseAdapter ;
1111import android .widget .ImageView ;
1212import android .widget .TextView ;
13+
1314import com .developer .filepicker .R ;
1415import com .developer .filepicker .controller .NotifyItemChecked ;
1516import com .developer .filepicker .model .DialogConfigs ;
1819import com .developer .filepicker .model .MarkedItemList ;
1920import com .developer .filepicker .widget .MaterialCheckbox ;
2021import com .developer .filepicker .widget .OnCheckedChangeListener ;
21- import java .text .SimpleDateFormat ;
22+
23+ import java .text .DateFormat ;
2224import java .util .ArrayList ;
2325import java .util .Date ;
24- import java .util .Locale ;
2526
2627/**
2728 * @author akshay sunil masram
2829 */
29- public class FileListAdapter extends BaseAdapter {
30+ public class FileListAdapter extends BaseAdapter {
3031 private ArrayList <FileListItem > listItem ;
3132 private Context context ;
3233 private DialogProperties properties ;
@@ -60,85 +61,74 @@ public View getView(final int i, View view, ViewGroup viewGroup) {
6061 view = LayoutInflater .from (context ).inflate (R .layout .dialog_file_list_item , viewGroup , false );
6162 holder = new ViewHolder (view );
6263 view .setTag (holder );
63- }
64- else
65- { holder = (ViewHolder )view .getTag ();
64+ } else {
65+ holder = (ViewHolder ) view .getTag ();
6666 }
6767 final FileListItem item = listItem .get (i );
6868 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 );
7070 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 );
7473 view .setAnimation (animation );
7574 }
7675 if (item .isDirectory ()) {
7776 holder .type_icon .setImageResource (R .mipmap .ic_type_folder );
7877 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 ));
8081 }
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 );
8386 }
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 {
9288 holder .type_icon .setImageResource (R .mipmap .ic_type_file );
9389 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 ));
9593 }
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 );
10498 }
10599 }
106100 holder .type_icon .setContentDescription (item .getFilename ());
107101 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 );
110104 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 ))) {
112106 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 )));
113109 }
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 );
120113 }
121114 if (MarkedItemList .hasItem (item .getLocation ())) {
122115 holder .fmark .setChecked (true );
123- }
124- else {
116+ } else {
125117 holder .fmark .setChecked (false );
126118 }
127119 }
128-
120+
129121 holder .fmark .setOnCheckedChangedListener (new OnCheckedChangeListener () {
130122 @ Override
131123 public void onCheckedChanged (MaterialCheckbox checkbox , boolean isChecked ) {
132124 item .setMarked (isChecked );
133125 if (item .isMarked ()) {
134- if (properties .selection_mode == DialogConfigs .MULTI_MODE ) {
126+ if (properties .selection_mode == DialogConfigs .MULTI_MODE ) {
135127 MarkedItemList .addSelectedItem (item );
136- }
137- else {
128+ } else {
138129 MarkedItemList .addSingleFile (item );
139130 }
140- }
141- else {
131+ } else {
142132 MarkedItemList .removeSelectedItem (item .getLocation ());
143133 }
144134 notifyItemChecked .notifyCheckBoxIsClicked ();
@@ -147,16 +137,16 @@ public void onCheckedChanged(MaterialCheckbox checkbox, boolean isChecked) {
147137 return view ;
148138 }
149139
150- private class ViewHolder
151- { ImageView type_icon ;
152- TextView name ,type ;
140+ private class ViewHolder {
141+ ImageView type_icon ;
142+ TextView name , type ;
153143 MaterialCheckbox fmark ;
154144
155145 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 );
160150 }
161151 }
162152
0 commit comments