mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 10:46:53 -04:00
Filewriter integration + finally added my name to AUTHORS :)
This commit is contained in:
parent
bc33527bfc
commit
7ce625c173
@ -179,7 +179,6 @@ public class ZimFileSelectActivity extends FragmentActivity
|
||||
}
|
||||
|
||||
mCursorAdapter.notifyDataSetChanged();
|
||||
|
||||
}
|
||||
|
||||
// Get the data of our cursor and wrap it all in our ArrayAdapter.
|
||||
@ -190,14 +189,25 @@ public class ZimFileSelectActivity extends FragmentActivity
|
||||
|
||||
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
|
||||
// Check if file exists
|
||||
if (new File(cursor.getString(2)).exists()) {
|
||||
files.add(new DataModel(cursor.getString(1), cursor.getString(2)));
|
||||
} else {
|
||||
Log.e("kiwix", cursor.getString(2) + "does not exist");
|
||||
//if (new File(cursor.getString(2)).exists()) {
|
||||
files.add(new DataModel(cursor.getString(1), cursor.getString(2)));
|
||||
//} else {
|
||||
Log.e("kiwix", cursor.getString(2) + " does not exist");
|
||||
//}
|
||||
}
|
||||
|
||||
files = new FileWriter(ZimFileSelectActivity.this, files).getDataModelList();
|
||||
|
||||
for (int i = 0; i < files.size(); i++) {
|
||||
|
||||
if (!new File(files.get(i).getPath()).exists()) {
|
||||
files.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
files = sortDataModel(files);
|
||||
mFiles = files;
|
||||
|
||||
return new RescanDataAdapter(ZimFileSelectActivity.this, 0, files);
|
||||
}
|
||||
|
||||
@ -212,7 +222,7 @@ public class ZimFileSelectActivity extends FragmentActivity
|
||||
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
|
||||
files.add(cursor.getString(2));
|
||||
}
|
||||
// updateMediaStore(files);
|
||||
updateMediaStore(files);
|
||||
|
||||
}
|
||||
|
||||
@ -251,6 +261,19 @@ public class ZimFileSelectActivity extends FragmentActivity
|
||||
mNeedsUpdate = false;
|
||||
}
|
||||
|
||||
public ArrayList<DataModel> sortDataModel(ArrayList<DataModel> data) {
|
||||
|
||||
// Sorting the data in alphabetical order
|
||||
Collections.sort(data, new Comparator<DataModel>() {
|
||||
@Override
|
||||
public int compare(DataModel a, DataModel b) {
|
||||
return a.getTitle().compareToIgnoreCase(b.getTitle());
|
||||
}
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<Cursor> cursorLoader) {
|
||||
mCursorAdapter.swapCursor(null);
|
||||
@ -327,6 +350,87 @@ public class ZimFileSelectActivity extends FragmentActivity
|
||||
finishResult(file);
|
||||
}
|
||||
|
||||
// This items class stores the Data for the ArrayAdapter.
|
||||
// We Have to implement Parcelable, so we can store ArrayLists with this generic type in the Bundle
|
||||
// of onSaveInstanceState() and retrieve it later on in onRestoreInstanceState()
|
||||
public static class DataModel implements Parcelable {
|
||||
|
||||
// Interface that must be implemented and provided as a public CREATOR field.
|
||||
// It generates instances of our Parcelable class from a Parcel.
|
||||
public Parcelable.Creator<DataModel> CREATOR = new Parcelable.Creator<DataModel>() {
|
||||
|
||||
@Override
|
||||
public DataModel createFromParcel(Parcel source) {
|
||||
return new DataModel(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return super.equals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataModel[] newArray(int size) {
|
||||
return new DataModel[size];
|
||||
}
|
||||
};
|
||||
|
||||
private String mTitle;
|
||||
|
||||
private String mPath;
|
||||
|
||||
public DataModel(String title, String path) {
|
||||
mTitle = title;
|
||||
mPath = path;
|
||||
}
|
||||
|
||||
// This constructor will be called when this class is generated by a Parcel.
|
||||
// We have to read the previously written Data in this Parcel.
|
||||
public DataModel(Parcel parcel) {
|
||||
String[] data = new String[2];
|
||||
parcel.readStringArray(data);
|
||||
mTitle = data[0];
|
||||
mTitle = data[1];
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return mTitle;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return mPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
// Write the data to the Parcel, so we can restore this Data later on.
|
||||
// It will be restored by the DataModel(Parcel parcel) constructor.
|
||||
dest.writeArray(new String[]{mTitle, mPath});
|
||||
}
|
||||
|
||||
// Override equals(Object) so we can compare objects. Specifically, so List#contains() works.
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
boolean isEqual = false;
|
||||
|
||||
if (object != null && object instanceof DataModel) {
|
||||
isEqual = (this.mPath.equals(((DataModel) object).mPath));
|
||||
}
|
||||
|
||||
return isEqual;
|
||||
}
|
||||
}
|
||||
|
||||
// This AsyncTask will scan the file system for files with the Extension ".zim" or ".zimaa"
|
||||
private class RescanFileSystem extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
@ -355,6 +459,8 @@ public class ZimFileSelectActivity extends FragmentActivity
|
||||
mProgressBarMessage.setVisibility(View.GONE);
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
|
||||
new FileWriter(ZimFileSelectActivity.this).saveArray(mFiles);
|
||||
|
||||
super.onPostExecute(result);
|
||||
}
|
||||
|
||||
@ -423,13 +529,7 @@ public class ZimFileSelectActivity extends FragmentActivity
|
||||
data.add(new DataModel(getTitleFromFilePath(file), file));
|
||||
}
|
||||
|
||||
// Sorting the data in alphabetical order
|
||||
Collections.sort(data, new Comparator<DataModel>() {
|
||||
@Override
|
||||
public int compare(DataModel a, DataModel b) {
|
||||
return a.getTitle().compareToIgnoreCase(b.getTitle());
|
||||
}
|
||||
});
|
||||
data = sortDataModel(data);
|
||||
|
||||
return data;
|
||||
}
|
||||
@ -440,65 +540,6 @@ public class ZimFileSelectActivity extends FragmentActivity
|
||||
}
|
||||
}
|
||||
|
||||
// This items class stores the Data for the ArrayAdapter.
|
||||
// We Have to implement Parcelable, so we can store ArrayLists with this generic type in the Bundle
|
||||
// of onSaveInstanceState() and retrieve it later on in onRestoreInstanceState()
|
||||
private class DataModel implements Parcelable {
|
||||
|
||||
// Interface that must be implemented and provided as a public CREATOR field.
|
||||
// It generates instances of your Parcelable class from a Parcel.
|
||||
public Parcelable.Creator<DataModel> CREATOR = new Parcelable.Creator<DataModel>() {
|
||||
|
||||
@Override
|
||||
public DataModel createFromParcel(Parcel source) {
|
||||
return new DataModel(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataModel[] newArray(int size) {
|
||||
return new DataModel[size];
|
||||
}
|
||||
};
|
||||
|
||||
private String mTitle;
|
||||
|
||||
private String mPath;
|
||||
|
||||
private DataModel(String title, String path) {
|
||||
mTitle = title;
|
||||
mPath = path;
|
||||
}
|
||||
|
||||
// This constructor will be called when this class is generated by a Parcel.
|
||||
// We have to read the previously written Data in this Parcel.
|
||||
public DataModel(Parcel parcel) {
|
||||
String[] data = new String[2];
|
||||
parcel.readStringArray(data);
|
||||
mTitle = data[0];
|
||||
mTitle = data[1];
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return mTitle;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return mPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
// Write the data to the Parcel, so we can restore this Data later on.
|
||||
// It will be restored by the DataModel(Parcel parcel) constructor.
|
||||
dest.writeArray(new String[]{mTitle, mPath});
|
||||
}
|
||||
}
|
||||
|
||||
// The Adapter for the ListView for when the ListView is populated with the rescanned files
|
||||
private class RescanDataAdapter extends ArrayAdapter<DataModel> {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user