Skip to content

Commit 5fc75cb

Browse files
Merge pull request #9 from mrgames13/master
Internationalization of date & time formats, add German translation
2 parents 6d4a2b0 + 88c5bf8 commit 5fc75cb

File tree

12 files changed

+165
-185
lines changed

12 files changed

+165
-185
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
jcenter()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.5.2'
9+
classpath 'com.android.tools.build:gradle:3.5.3'
1010
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
1111

1212
// NOTE: Do not place your application dependencies here; they belong

library/src/main/java/com/developer/filepicker/controller/adapters/FileListAdapter.java

+44-54
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.widget.BaseAdapter;
1111
import android.widget.ImageView;
1212
import android.widget.TextView;
13+
1314
import com.developer.filepicker.R;
1415
import com.developer.filepicker.controller.NotifyItemChecked;
1516
import com.developer.filepicker.model.DialogConfigs;
@@ -18,15 +19,15 @@
1819
import com.developer.filepicker.model.MarkedItemList;
1920
import com.developer.filepicker.widget.MaterialCheckbox;
2021
import com.developer.filepicker.widget.OnCheckedChangeListener;
21-
import java.text.SimpleDateFormat;
22+
23+
import java.text.DateFormat;
2224
import java.util.ArrayList;
2325
import 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

library/src/main/java/com/developer/filepicker/view/FilePickerDialog.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ public void notifyCheckBoxIsClicked() {
128128
int color;
129129
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
130130
color = context.getResources().getColor(R.color.colorAccent, context.getTheme());
131-
}
132-
else {
131+
} else {
133132
color = context.getResources().getColor(R.color.colorAccent);
134133
}
135134
select.setTextColor(Color.argb(128, Color.red(color), Color.green(color), Color.blue(color)));
@@ -139,8 +138,7 @@ public void notifyCheckBoxIsClicked() {
139138
int color;
140139
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
141140
color = context.getResources().getColor(R.color.colorAccent, context.getTheme());
142-
}
143-
else {
141+
} else {
144142
color = context.getResources().getColor(R.color.colorAccent);
145143
}
146144
select.setTextColor(color);
@@ -188,8 +186,8 @@ protected void onStart() {
188186
super.onStart();
189187
positiveBtnNameStr = (
190188
positiveBtnNameStr == null ?
191-
context.getResources().getString(R.string.choose_button_label) :
192-
positiveBtnNameStr
189+
context.getResources().getString(R.string.choose_button_label) :
190+
positiveBtnNameStr
193191
);
194192
select.setText(positiveBtnNameStr);
195193
if (Utility.checkStorageAccessPermissions(context)) {

library/src/main/java/com/developer/filepicker/view/FilePickerPreference.java

+41-49
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class FilePickerPreference extends Preference implements DialogSelectionL
2323

2424
private FilePickerDialog mDialog;
2525
private DialogProperties properties;
26-
private String titleText=null;
26+
private String titleText = null;
2727

2828
public FilePickerPreference(Context context) {
2929
super(context);
@@ -96,18 +96,17 @@ private void showDialog(Bundle state) {
9696

9797
@Override
9898
public void onSelectedFilePaths(String[] files) {
99-
StringBuilder buff=new StringBuilder();
100-
for(String path:files)
101-
{ buff.append(path).append(":");
99+
StringBuilder buff = new StringBuilder();
100+
for (String path : files) {
101+
buff.append(path).append(":");
102102
}
103103
String dFiles = buff.toString();
104104
if (isPersistent()) {
105105
persistString(dFiles);
106106
}
107107
try {
108108
getOnPreferenceChangeListener().onPreferenceChange(this, dFiles);
109-
}
110-
catch (NullPointerException e) {
109+
} catch (NullPointerException e) {
111110
e.printStackTrace();
112111
}
113112
}
@@ -118,8 +117,8 @@ public boolean onPreferenceClick(Preference preference) {
118117
return false;
119118
}
120119

121-
public void setProperties(DialogProperties properties)
122-
{ mDialog.setProperties(properties);
120+
public void setProperties(DialogProperties properties) {
121+
mDialog.setProperties(properties);
123122
}
124123

125124
private static class SavedState extends BaseSavedState {
@@ -141,56 +140,49 @@ public SavedState(Parcelable superState) {
141140
}
142141

143142
public static final Creator<SavedState> CREATOR =
144-
new Creator<SavedState>() {
145-
public SavedState createFromParcel(Parcel in) {
146-
return new SavedState(in);
147-
}
148-
149-
public SavedState[] newArray(int size) {
150-
return new SavedState[size];
151-
}
152-
};
143+
new Creator<SavedState>() {
144+
public SavedState createFromParcel(Parcel in) {
145+
return new SavedState(in);
146+
}
147+
148+
public SavedState[] newArray(int size) {
149+
return new SavedState[size];
150+
}
151+
};
153152
}
154153

155154
private void initProperties(AttributeSet attrs) {
156-
TypedArray tarr=getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.FilePickerPreference,0,0);
155+
TypedArray tarr = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.FilePickerPreference, 0, 0);
157156
final int N = tarr.getIndexCount();
158-
for (int i = 0; i < N; ++i)
159-
{ int attr = tarr.getIndex(i);
157+
for (int i = 0; i < N; ++i) {
158+
int attr = tarr.getIndex(i);
160159
if (attr == R.styleable.FilePickerPreference_selection_mode) {
161-
properties.selection_mode=tarr.getInteger(R.styleable.FilePickerPreference_selection_mode, DialogConfigs.SINGLE_MODE);
162-
}
163-
else if (attr == R.styleable.FilePickerPreference_selection_type) {
164-
properties.selection_type=tarr.getInteger(R.styleable.FilePickerPreference_selection_type,DialogConfigs.FILE_SELECT);
165-
}
166-
else if (attr == R.styleable.FilePickerPreference_root_dir) {
167-
String root_dir=tarr.getString(R.styleable.FilePickerPreference_root_dir);
168-
if(root_dir!=null&&!root_dir.equals(""))
169-
{ properties.root=new File(root_dir);
160+
properties.selection_mode = tarr.getInteger(R.styleable.FilePickerPreference_selection_mode, DialogConfigs.SINGLE_MODE);
161+
} else if (attr == R.styleable.FilePickerPreference_selection_type) {
162+
properties.selection_type = tarr.getInteger(R.styleable.FilePickerPreference_selection_type, DialogConfigs.FILE_SELECT);
163+
} else if (attr == R.styleable.FilePickerPreference_root_dir) {
164+
String root_dir = tarr.getString(R.styleable.FilePickerPreference_root_dir);
165+
if (root_dir != null && !root_dir.equals("")) {
166+
properties.root = new File(root_dir);
170167
}
171-
}
172-
else if (attr == R.styleable.FilePickerPreference_error_dir) {
173-
String error_dir=tarr.getString(R.styleable.FilePickerPreference_error_dir);
174-
if(error_dir!=null&&!error_dir.equals(""))
175-
{ properties.error_dir=new File(error_dir);
168+
} else if (attr == R.styleable.FilePickerPreference_error_dir) {
169+
String error_dir = tarr.getString(R.styleable.FilePickerPreference_error_dir);
170+
if (error_dir != null && !error_dir.equals("")) {
171+
properties.error_dir = new File(error_dir);
176172
}
177-
}
178-
else if (attr == R.styleable.FilePickerPreference_offset_dir) {
179-
String offset_dir=tarr.getString(R.styleable.FilePickerPreference_offset_dir);
180-
if(offset_dir!=null&&!offset_dir.equals(""))
181-
{ properties.offset=new File(offset_dir);
173+
} else if (attr == R.styleable.FilePickerPreference_offset_dir) {
174+
String offset_dir = tarr.getString(R.styleable.FilePickerPreference_offset_dir);
175+
if (offset_dir != null && !offset_dir.equals("")) {
176+
properties.offset = new File(offset_dir);
182177
}
183-
}
184-
else if (attr == R.styleable.FilePickerPreference_extensions) {
185-
String extensions=tarr.getString(R.styleable.FilePickerPreference_extensions);
186-
if(extensions!=null&&!extensions.equals(""))
187-
{ properties.extensions= extensions.split(":");
178+
} else if (attr == R.styleable.FilePickerPreference_extensions) {
179+
String extensions = tarr.getString(R.styleable.FilePickerPreference_extensions);
180+
if (extensions != null && !extensions.equals("")) {
181+
properties.extensions = extensions.split(":");
188182
}
189-
}
190-
else if (attr == R.styleable.FilePickerPreference_title_text) {
191-
titleText=tarr.getString(R.styleable.FilePickerPreference_title_text);
192-
}
193-
else if (attr == R.styleable.FilePickerPreference_show_hidden_files) {
183+
} else if (attr == R.styleable.FilePickerPreference_title_text) {
184+
titleText = tarr.getString(R.styleable.FilePickerPreference_title_text);
185+
} else if (attr == R.styleable.FilePickerPreference_show_hidden_files) {
194186
properties.show_hidden_files = tarr.getBoolean(R.styleable.FilePickerPreference_show_hidden_files, false);
195187
}
196188
}

0 commit comments

Comments
 (0)