1 package net.osdn.gokigen.pkremote.transfer;
3 import android.util.Log;
5 import net.osdn.gokigen.pkremote.R;
6 import net.osdn.gokigen.pkremote.camera.interfaces.IInterfaceProvider;
7 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContent;
8 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContentListCallback;
9 import net.osdn.gokigen.pkremote.playback.detail.MyContentDownloader;
11 import java.util.ArrayList;
12 import java.util.HashMap;
13 import java.util.List;
15 import androidx.annotation.NonNull;
16 import androidx.appcompat.app.AppCompatActivity;
20 * (UIスレッドでは動いていないので注意)
22 class FileAutoTransferMain implements ICameraContentListCallback
24 private final String TAG = this.toString();
26 private final IInterfaceProvider interfaceProvider;
27 private final AppCompatActivity activity;
28 private final ITransferMessage messageInterface;
29 private final MyContentDownloader downloader;
30 private boolean firstContent = false;
31 private List<ICameraContent> baseContentList = null;
32 private List<ICameraContent> currentContentList = null;
33 private HashMap<String, ICameraContent> contentHashMap;
34 private boolean getRaw = false;
35 private boolean smallSize = false;
36 private boolean isChecking = false;
39 FileAutoTransferMain(@NonNull AppCompatActivity context, @NonNull IInterfaceProvider provider, @NonNull ITransferMessage messageInterface)
41 this.activity = context;
42 this.interfaceProvider = provider;
43 this.messageInterface = messageInterface;
44 this.downloader = new MyContentDownloader(context, provider.getPlaybackControl());
45 this.contentHashMap = new HashMap<>();
52 void start(boolean getRaw, boolean smallSize)
54 String message = "TRANSFER START [raw:" + getRaw + "] [small:" + smallSize + "]";
60 baseContentList = null;
61 currentContentList = null;
63 contentHashMap.clear();
66 this.smallSize = smallSize;
68 // RunモードをRecordingに変更する。
69 // (Olympus Air向けだったのだが ... でも liveview が開始されていないと撮影できなさそう...)
70 interfaceProvider.getCameraRunMode().changeRunMode(true);
73 interfaceProvider.getPlaybackControl().getCameraContentList(this);
94 Log.v(TAG, "CHECK FILE");
96 interfaceProvider.getPlaybackControl().getCameraContentList(this);
112 Log.v(TAG, "FINISH");
113 messageInterface.showInformation("");
114 baseContentList = null;
115 currentContentList = null;
117 // RunモードをPlaybackモードに戻す。
118 interfaceProvider.getCameraRunMode().changeRunMode(false);
127 private boolean downloadImages()
129 Log.v(TAG, "downloadImages()");
130 boolean isDownload = false;
133 ArrayList<ICameraContent> addContent = new ArrayList<>();
134 for (ICameraContent content : currentContentList)
136 String key = (content.getContentPath() + "/" + content.getContentName()).toLowerCase();
137 //Log.v(TAG, "KEY : " + key);
140 if (!contentHashMap.containsKey(key))
142 Log.v(TAG, "FILE(add) : " + key);
143 contentHashMap.put(key, content);
144 if ((key.endsWith(".jpg"))||(getRaw))
146 addContent.add(content);
151 // 見つけた画像を(連続して)ダウンロードする (ここから)
152 messageInterface.showInformation(activity.getString(R.string.add_image_pics) + " " + addContent.size());
153 if (addContent.size() > 0)
156 startDownloadBatch(addContent, smallSize);
170 * @param isSmall 小さいサイズ(JPEG)
172 private void startDownloadBatch(final ArrayList<ICameraContent> imageContentList, final boolean isSmall)
177 int totalSize = imageContentList.size();
178 for (ICameraContent content : imageContentList)
180 downloader.startDownload(content, " (" + count + "/" + totalSize + ") ", null, isSmall);
185 // ここでダウンロードが終わるまで、すこし待つ
192 } while (downloader.isDownloading());
202 // ICameraContentListCallback
204 public void onCompleted(List<ICameraContent> contentList)
206 Log.v(TAG, "RECEIVE CONTENT LIST");
211 baseContentList = contentList;
212 if ((baseContentList != null)&&(baseContentList.size() > 0))
214 firstContent = false;
216 // 初期データをHashMapに突っ込んでおく...
217 for (ICameraContent content : baseContentList)
219 String key = (content.getContentPath() + "/" + content.getContentName()).toLowerCase();
220 //Log.v(TAG, "FILE : " + key);
221 contentHashMap.put(key, content);
227 currentContentList = contentList;
229 if ((baseContentList != null)&&(currentContentList != null)&&(currentContentList.size() > 0))
232 int baseSize = baseContentList.size();
233 int currentSize = currentContentList.size();
234 if (baseSize != currentSize)
237 messageInterface.showInformation(activity.getString(R.string.image_checking) + " " + currentSize);
240 if (downloadImages())
242 // 実行がうまくいった場合は表示を更新する
243 messageInterface.showInformation(activity.getString(R.string.image_download_done));
246 //////////////////////////////////////// 現在のカメラ内画像情報を差し替えて、次の増加分にそなえる
247 baseContentList = currentContentList;
248 currentContentList = null;
252 // 画像ファイル数が変わっていない場合は表示を消す
253 messageInterface.showInformation(" ");
264 // ICameraContentListCallback
266 public void onErrorOccurred(Exception e)
268 Log.v(TAG, "RECEIVE FAILURE...");