OSDN Git Service

FUJIカメラに接続したときの一括ダウンロードが動かなかったのを修正する。
[gokigen/Gr2Control.git] / app / src / main / java / net / osdn / gokigen / gr2control / playback / detail / MyContentDownloader.java
index 263cdcd..1845384 100644 (file)
@@ -51,6 +51,7 @@ public class MyContentDownloader implements IDownloadContentCallback
     private String targetFileName = "";
     private String filepath = "";
     private String mimeType = "image/jpeg";
+    private boolean isDownloading = false;
 
     /**
      *   コンストラクタ
@@ -78,6 +79,7 @@ public class MyContentDownloader implements IDownloadContentCallback
         // Download the image.
         try
         {
+            isDownloading = true;
             Calendar calendar = Calendar.getInstance();
             String extendName = new SimpleDateFormat("yyyyMMdd-HHmmss", Locale.getDefault()).format(calendar.getTime());
             targetFileName = fileInfo.getOriginalFilename().toUpperCase();
@@ -155,6 +157,8 @@ public class MyContentDownloader implements IDownloadContentCallback
                         if (downloadDialog != null) {
                             downloadDialog.dismiss();
                         }
+                        downloadDialog = null;
+                        isDownloading = false;
                         presentMessage(activity.getString(R.string.download_control_save_failed), message);
                     }
                 });
@@ -165,6 +169,23 @@ public class MyContentDownloader implements IDownloadContentCallback
         catch (Exception ex)
         {
             ex.printStackTrace();
+            activity.runOnUiThread(new Runnable() {
+                @Override
+                public void run() {
+                    try
+                    {
+                        if (downloadDialog != null) {
+                            downloadDialog.dismiss();
+                        }
+                    }
+                    catch (Exception e)
+                    {
+                        e.printStackTrace();
+                    }
+                    downloadDialog = null;
+                    isDownloading = false;
+                }
+            });
         }
     }
 
@@ -244,6 +265,8 @@ public class MyContentDownloader implements IDownloadContentCallback
                     {
                         downloadDialog.dismiss();
                     }
+                    downloadDialog = null;
+                    isDownloading = false;
                     View view = activity.findViewById(R.id.fragment1);
                     Snackbar.make(view, activity.getString(R.string.download_control_save_success) + " " + targetFileName, Snackbar.LENGTH_SHORT).show();
                     //Toast.makeText(activity, activity.getString(R.string.download_control_save_success) + " " + targetFileName, Toast.LENGTH_SHORT).show();
@@ -261,6 +284,8 @@ public class MyContentDownloader implements IDownloadContentCallback
                     {
                         downloadDialog.dismiss();
                     }
+                    downloadDialog = null;
+                    isDownloading = false;
                     presentMessage(activity.getString(R.string.download_control_save_failed), message);
                 }
             });
@@ -271,6 +296,7 @@ public class MyContentDownloader implements IDownloadContentCallback
     @Override
     public void onErrorOccurred(Exception e)
     {
+        isDownloading = false;
         final String message = e.getMessage();
         try
         {
@@ -295,6 +321,8 @@ public class MyContentDownloader implements IDownloadContentCallback
                 {
                     downloadDialog.dismiss();
                 }
+                downloadDialog = null;
+                isDownloading = false;
                 presentMessage(activity.getString(R.string.download_control_download_failed), message);
                 System.gc();
             }
@@ -302,6 +330,11 @@ public class MyContentDownloader implements IDownloadContentCallback
         System.gc();
     }
 
+    public boolean isDownloading()
+    {
+        return (isDownloading);
+    }
+
     /**
      *   共有の呼び出し
      *