OSDN Git Service

FUJIカメラに接続したときの一括ダウンロードが動かなかったのを修正する。
authorMRSa <mrsa@myad.jp>
Tue, 5 May 2020 04:19:30 +0000 (13:19 +0900)
committerMRSa <mrsa@myad.jp>
Tue, 5 May 2020 04:19:30 +0000 (13:19 +0900)
app/src/main/java/net/osdn/gokigen/gr2control/camera/fuji_x/wrapper/connection/FujiXCameraModeChangeToPlayback.java
app/src/main/java/net/osdn/gokigen/gr2control/playback/ImageGridViewFragment.java
app/src/main/java/net/osdn/gokigen/gr2control/playback/detail/MyContentDownloader.java

index 5439f90..3e6dfc0 100644 (file)
@@ -94,6 +94,10 @@ public class FujiXCameraModeChangeToPlayback implements View.OnClickListener, IF
                     break;
 
                 case IFujiXMessages.SEQ_CHANGE_TO_PLAYBACK_3RD:
+                    //if (callback != null)
+                    {
+                        //callback.receivedMessage(id, rx_body);
+                    }
                     enqueueCommand(id, rx_body, new ChangeToPlayback4th(COMMANDID_CHANGE_TO_PLAYBACK,this));
                     break;
 
index a21f3bb..edb544f 100644 (file)
@@ -122,7 +122,7 @@ public class ImageGridViewFragment extends Fragment implements ICameraRunModeCal
        }
        
        @Override
-       public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
+       public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater)
        {
                inflater.inflate(R.menu.image_grid_view, menu);
                String title = getString(R.string.app_name);
@@ -538,6 +538,19 @@ public class ImageGridViewFragment extends Fragment implements ICameraRunModeCal
 
                                 // 画像の選択を落とす
                                 content.setSelected(false);
+
+                                // ここでダウンロードが終わるまで、すこし待つ
+                                do
+                                {
+                                    try
+                                    {
+                                        Thread.sleep(300);
+                                    }
+                                    catch (Exception e)
+                                    {
+                                        e.printStackTrace();
+                                    }
+                                } while (contentDownloader.isDownloading());
                             }
                         }
 
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);
+    }
+
     /**
      *   共有の呼び出し
      *