Open GoogleCodeExporter opened 8 years ago
The current plan is to implement a delete button, and then add something to
handle
this situation; so I'll defer this until that one is done.
Original comment by kbsriram
on 8 Feb 2010 at 4:11
I've modified my version of Trook so check for the file before the download
begins. If it is there, a dialog box appears and asks if you want Overwrite,
Keep Both, or Cancel. You just push a button on the touch screen.
The change is made in the Trook class. Replace the private class with the code
I put below.
private final class DownloadClicker
implements View.OnClickListener
{
private DownloadClicker
(String base, String[] hrefs, String[] targets, String mimes[])
{
m_base = base;
m_hrefs = hrefs;
m_targets = targets;
m_mimes = mimes;
}
private DownloadClicker
(String base, String href, String target, String mime)
{
m_base = base;
m_hrefs = new String[1]; m_hrefs[0] = href;
m_targets = new String[1]; m_targets[0] = target;
m_mimes = new String[1]; m_mimes[0] = mime;
}
public void onClick(View v)
{
final File start = new File(m_targets[0]);
final File parent = start.getParentFile();
final File cur = new File(parent, start.getName());
if(cur.exists()) {
AlertDialog.Builder alert = new AlertDialog.Builder(Trook.singleton);
alert.setTitle("File exists.");
alert.setMessage("What do you want to do?");
alert.setPositiveButton("Overwrite", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
doTheDownload();
Log.d(TAG, "Overwrite download started.");
}
});
alert.setNeutralButton("Keep both", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
int idx = 0;
File newFile = cur;
while (newFile.exists() && (idx < 50)) {
idx++;
newFile = new File(parent, idx+"_"+start.getName());
}
String prefix = idx+"_";
for (int i=0; i<m_targets.length; i++) {
newFile = new File(m_targets[i]);
m_targets[i] = parent + "/" + prefix + newFile.getName();
}
doTheDownload();
Log.d(TAG, "Keep Both download started.");
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Log.d(TAG, "Download canceled.");
}
});
alert.show();
} else {
doTheDownload();
}
}
private void doTheDownload() {
try {
URI base = new URI(m_base);
for (int i=0; i<m_hrefs.length; i++) {
URI ref = URIUtils.resolve(base, m_hrefs[i]);
// Log.d(TAG, "Found base URL = "+ref);
Intent dsi = new Intent();
dsi.setDataAndType
(Uri.parse(ref.toString()), m_mimes[i]);
dsi.putExtra(DownloadService.TARGET, m_targets[i]);
dsi.setComponent
(new ComponentName
("com.kbs.trook", "com.kbs.trook.DownloadService"));
startService(dsi);
}
displayShortMessage("Starting download in the background");
}
catch (Throwable th) {
Log.d(TAG, "download fails", th);
Trook.this.displayError("Failed to load "+m_hrefs[0]+"\n"+th);
}
}
private final String[] m_hrefs;
private final String m_base;
private final String[] m_targets;
private final String[] m_mimes;
}
Original comment by craftycoder
on 13 Jul 2010 at 5:20
[deleted comment]
Seeing as I rather regularly re-download books via Trook, e.g., because I
modified their metadata or even edited their contents, and since re-downloading
will do no harm in my use-cases, I added a setting specifying whether to
silently overwrite previously-downloaded books (defaults to "no", the current
behavior). I'm attaching a diff relative to r74.
To enable the setting, you have to edit
"/data/data/com.kbs.trook/shared_prefs/TrookPreferences.xml" as follows (or
create it if it doesn't exist):
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
<boolean name="trook.downloads.replace" value="true"/>
</map>
Original comment by mgoetze2...@gmail.com
on 15 Jul 2010 at 9:14
Attachments:
I think the best solution here would be to combine our efforts. Use the dialog
that I created and have a check box for "Save as default behavior."
Original comment by craftycoder
on 15 Jul 2010 at 11:54
But then you'd also have to provide a means of switching back to the
confirmative behavior, in order to keep it user-friendly. :^]
Regardless of that, the only thing combining both ways would take would be to
have the checkbox set the above property to true (which should be possible with
the preferences system).
Original comment by mgoetze2...@gmail.com
on 15 Jul 2010 at 12:06
This has been completely fixed with source and binary attached to issue #41.
http://code.google.com/p/nookapps/issues/detail?id=41
Original comment by craftycoder
on 16 Jul 2010 at 7:45
Original issue reported on code.google.com by
ttn...@gmail.com
on 4 Feb 2010 at 10:58