mirror of
https://github.com/ankidroid/Anki-Android.git
synced 2024-09-20 20:03:05 +02:00
Fixed the DeckPicker bug where it crashed when there was some file ending in '.anki' that was not a real anki file.
This commit is contained in:
parent
b554dd2efe
commit
008ce58291
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.ichi2.anki"
|
package="com.ichi2.anki"
|
||||||
android:versionName="0.2" android:versionCode="4">
|
android:versionName="0.3" android:versionCode="6">
|
||||||
<application android:label="@string/app_name" android:icon="@drawable/anki" android:debuggable="false">
|
<application android:label="@string/app_name" android:icon="@drawable/anki" android:debuggable="false">
|
||||||
<activity android:name=".Ankidroid" android:label="@string/app_name" android:configChanges="orientation"
|
<activity android:name=".Ankidroid" android:label="@string/app_name" android:configChanges="orientation"
|
||||||
>
|
>
|
||||||
|
@ -11,8 +11,10 @@ import android.app.Activity;
|
|||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.SharedPreferences.Editor;
|
import android.content.SharedPreferences.Editor;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
@ -56,7 +58,7 @@ public class Ankidroid extends Activity implements Runnable
|
|||||||
/**
|
/**
|
||||||
* Tag for logging messages
|
* Tag for logging messages
|
||||||
*/
|
*/
|
||||||
private static String TAG = "Ankidroid";
|
private static final String TAG = "Ankidroid";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Menus
|
* Menus
|
||||||
@ -85,6 +87,8 @@ public class Ankidroid extends Activity implements Runnable
|
|||||||
private ProgressDialog dialog;
|
private ProgressDialog dialog;
|
||||||
|
|
||||||
private boolean layoutInitialized;
|
private boolean layoutInitialized;
|
||||||
|
|
||||||
|
private BroadcastReceiver mUnmountReceiver = null;
|
||||||
|
|
||||||
private boolean deckSelected;
|
private boolean deckSelected;
|
||||||
|
|
||||||
@ -198,6 +202,8 @@ public class Ankidroid extends Activity implements Runnable
|
|||||||
|
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
|
|
||||||
|
registerExternalStorageListener();
|
||||||
|
|
||||||
Bundle extras = getIntent().getExtras();
|
Bundle extras = getIntent().getExtras();
|
||||||
|
|
||||||
initResourceValues();
|
initResourceValues();
|
||||||
@ -428,6 +434,7 @@ public class Ankidroid extends Activity implements Runnable
|
|||||||
{
|
{
|
||||||
outState.putString("deckFilename", deckFilename);
|
outState.putString("deckFilename", deckFilename);
|
||||||
}
|
}
|
||||||
|
Log.i(TAG, "onSaveInstanceState - Ending");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -703,4 +710,38 @@ public class Ankidroid extends Activity implements Runnable
|
|||||||
private boolean isSdCardMounted() {
|
private boolean isSdCardMounted() {
|
||||||
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
|
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers an intent to listen for ACTION_MEDIA_EJECT notifications.
|
||||||
|
* The intent will call closeExternalStorageFiles() if the external media
|
||||||
|
* is going to be ejected, so applications can clean up any files they have open.
|
||||||
|
*/
|
||||||
|
public void registerExternalStorageListener() {
|
||||||
|
/*if (mUnmountReceiver == null) {
|
||||||
|
mUnmountReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
String action = intent.getAction();
|
||||||
|
if (action.equals(Intent.ACTION_MEDIA_EJECT)) {
|
||||||
|
//saveQueue(true);
|
||||||
|
//mOneShot = true; // This makes us not save the state again later,
|
||||||
|
// which would be wrong because the song ids and
|
||||||
|
// card id might not match.
|
||||||
|
//closeExternalStorageFiles(intent.getData().getPath());
|
||||||
|
} else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
|
||||||
|
///mMediaMountedCount++;
|
||||||
|
//mCardId = FileUtils.getFatVolumeId(intent.getData().getPath());
|
||||||
|
//reloadQueue();
|
||||||
|
//notifyChange(QUEUE_CHANGED);
|
||||||
|
//notifyChange(META_CHANGED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
IntentFilter iFilter = new IntentFilter();
|
||||||
|
iFilter.addAction(Intent.ACTION_MEDIA_EJECT);
|
||||||
|
iFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
|
||||||
|
iFilter.addDataScheme("file");
|
||||||
|
registerReceiver(mUnmountReceiver, iFilter);
|
||||||
|
}*/
|
||||||
|
}
|
||||||
}
|
}
|
@ -332,6 +332,7 @@ public class Deck
|
|||||||
public static float getLastModified(String deckPath)
|
public static float getLastModified(String deckPath)
|
||||||
{
|
{
|
||||||
float value;
|
float value;
|
||||||
|
//Log.i(TAG, "Deck - getLastModified from deck = " + deckPath);
|
||||||
AnkiDb.openDatabase(deckPath);
|
AnkiDb.openDatabase(deckPath);
|
||||||
Cursor cursor = AnkiDb.database.rawQuery("SELECT modified" + " FROM decks" + " LIMIT 1", null);
|
Cursor cursor = AnkiDb.database.rawQuery("SELECT modified" + " FROM decks" + " LIMIT 1", null);
|
||||||
|
|
||||||
|
@ -34,6 +34,8 @@ import android.widget.SimpleAdapter;
|
|||||||
public class DeckPicker extends Activity implements Runnable
|
public class DeckPicker extends Activity implements Runnable
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private static final String TAG = "Ankidroid";
|
||||||
|
|
||||||
private DeckPicker mSelf;
|
private DeckPicker mSelf;
|
||||||
|
|
||||||
private SimpleAdapter mDeckListAdapter;
|
private SimpleAdapter mDeckListAdapter;
|
||||||
@ -64,6 +66,7 @@ public class DeckPicker extends Activity implements Runnable
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) throws SQLException
|
public void onCreate(Bundle savedInstanceState) throws SQLException
|
||||||
{
|
{
|
||||||
|
Log.i(TAG, "DeckPicker - onCreate");
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
mSelf = this;
|
mSelf = this;
|
||||||
String deckPath = getIntent().getStringExtra("com.ichi2.anki.Ankidroid.DeckPath");
|
String deckPath = getIntent().getStringExtra("com.ichi2.anki.Ankidroid.DeckPath");
|
||||||
@ -98,12 +101,16 @@ public class DeckPicker extends Activity implements Runnable
|
|||||||
|
|
||||||
public void onPause()
|
public void onPause()
|
||||||
{
|
{
|
||||||
|
Log.i(TAG, "DeckPicker - onPause");
|
||||||
|
|
||||||
super.onPause();
|
super.onPause();
|
||||||
waitForDeckLoaderThread();
|
waitForDeckLoaderThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void populateDeckList(String location)
|
private void populateDeckList(String location)
|
||||||
{
|
{
|
||||||
|
Log.i(TAG, "DeckPicker - populateDeckList");
|
||||||
|
|
||||||
Resources res = getResources();
|
Resources res = getResources();
|
||||||
int len = 0;
|
int len = 0;
|
||||||
File[] fileList;
|
File[] fileList;
|
||||||
@ -111,7 +118,7 @@ public class DeckPicker extends Activity implements Runnable
|
|||||||
|
|
||||||
File dir = new File(location);
|
File dir = new File(location);
|
||||||
fileList = dir.listFiles(new AnkiFilter());
|
fileList = dir.listFiles(new AnkiFilter());
|
||||||
|
|
||||||
if (dir.exists() && dir.isDirectory() && fileList != null)
|
if (dir.exists() && dir.isDirectory() && fileList != null)
|
||||||
{
|
{
|
||||||
len = fileList.length;
|
len = fileList.length;
|
||||||
@ -119,19 +126,29 @@ public class DeckPicker extends Activity implements Runnable
|
|||||||
mFileList = fileList;
|
mFileList = fileList;
|
||||||
if (len > 0 && fileList != null)
|
if (len > 0 && fileList != null)
|
||||||
{
|
{
|
||||||
|
Log.i(TAG, "DeckPicker - populateDeckList, number of anki files = " + len);
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
String absPath = fileList[i].getAbsolutePath();
|
String absPath = fileList[i].getAbsolutePath();
|
||||||
|
|
||||||
HashMap<String, String> data = new HashMap<String, String>();
|
Log.i(TAG, "DeckPicker - populateDeckList, file " + i + " :" + fileList[i].getName());
|
||||||
data.put("name", fileList[i].getName().replaceAll(".anki", ""));
|
|
||||||
data.put("due", res.getString(R.string.deckpicker_loaddeck));
|
try
|
||||||
data.put("new", "");
|
{
|
||||||
data.put("mod", String.format("%f", Deck.getLastModified(absPath)));
|
HashMap<String, String> data = new HashMap<String, String>();
|
||||||
data.put("filepath", absPath);
|
data.put("name", fileList[i].getName().replaceAll(".anki", ""));
|
||||||
data.put("showProgress", "true");
|
data.put("due", res.getString(R.string.deckpicker_loaddeck));
|
||||||
|
data.put("new", "");
|
||||||
|
data.put("mod", String.format("%f", Deck.getLastModified(absPath)));
|
||||||
|
data.put("filepath", absPath);
|
||||||
|
data.put("showProgress", "true");
|
||||||
|
|
||||||
|
tree.add(data);
|
||||||
|
} catch (SQLException e)
|
||||||
|
{
|
||||||
|
Log.w(TAG, "DeckPicker - populateDeckList, File " + fileList[i].getName() + " is not a real anki file");
|
||||||
|
}
|
||||||
|
|
||||||
tree.add(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread thread = new Thread(this);
|
Thread thread = new Thread(this);
|
||||||
@ -161,6 +178,7 @@ public class DeckPicker extends Activity implements Runnable
|
|||||||
mDeckList.clear();
|
mDeckList.clear();
|
||||||
mDeckList.addAll(tree);
|
mDeckList.addAll(tree);
|
||||||
mDeckListView.clearChoices();
|
mDeckListView.clearChoices();
|
||||||
|
Log.i(TAG, "DeckPicker - populateDeckList, Ending");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class AnkiFilter implements FileFilter
|
private static final class AnkiFilter implements FileFilter
|
||||||
|
Loading…
Reference in New Issue
Block a user