dirents) {
+ if (dirents == null) {
+ if (err != null)
+ showToast(R.string.transfer_list_network_error);
+ return;
+ }
+
+ if (fileCount == 0)
+ showToast(R.string.transfer_download_no_task);
+ else
+ showToast(getString(R.string.transfer_download_started, fileCount));
+
// set download tasks info to adapter in order to update download progress in UI thread
getReposFragment().getAdapter().setDownloadTaskList(txService.getDownloadTaskInfosByPath(repoID, filePath));
getReposFragment().getAdapter().notifyDataSetChanged();
@@ -1492,16 +1507,16 @@ private TransferReceiver() {}
public void onReceive(Context context, Intent intent) {
String type = intent.getStringExtra("type");
- if (type.equals(TransferService.BROADCAST_FILE_DOWNLOAD_PROGRESS)) {
+ if (type.equals(DownloadTaskManager.BROADCAST_FILE_DOWNLOAD_PROGRESS)) {
int taskID = intent.getIntExtra("taskID", 0);
onFileDownloadProgress(taskID);
- } else if (type.equals(TransferService.BROADCAST_FILE_DOWNLOAD_FAILED)) {
+ } else if (type.equals(DownloadTaskManager.BROADCAST_FILE_DOWNLOAD_FAILED)) {
int taskID = intent.getIntExtra("taskID", 0);
onFileDownloadFailed(taskID);
- } else if (type.equals(TransferService.BROADCAST_FILE_UPLOAD_SUCCESS)) {
+ } else if (type.equals(UploadTaskManager.BROADCAST_FILE_UPLOAD_SUCCESS)) {
int taskID = intent.getIntExtra("taskID", 0);
onFileUploaded(taskID);
- } else if (type.equals(TransferService.BROADCAST_FILE_UPLOAD_FAILED)) {
+ } else if (type.equals(UploadTaskManager.BROADCAST_FILE_UPLOAD_FAILED)) {
int taskID = intent.getIntExtra("taskID", 0);
onFileUploadFailed(taskID);
}
diff --git a/src/com/seafile/seadroid2/ui/activity/FileActivity.java b/src/com/seafile/seadroid2/ui/activity/FileActivity.java
index 9e2811261..d0be76ca6 100644
--- a/src/com/seafile/seadroid2/ui/activity/FileActivity.java
+++ b/src/com/seafile/seadroid2/ui/activity/FileActivity.java
@@ -31,6 +31,8 @@
import com.seafile.seadroid2.account.Account;
import com.seafile.seadroid2.data.DataManager;
import com.seafile.seadroid2.transfer.DownloadTaskInfo;
+import com.seafile.seadroid2.transfer.DownloadTaskManager;
+import com.seafile.seadroid2.transfer.TransferManager;
import com.seafile.seadroid2.transfer.TransferService;
import com.seafile.seadroid2.transfer.TransferService.TransferBinder;
import com.seafile.seadroid2.ui.dialog.OpenAsDialog;
@@ -193,7 +195,7 @@ public void onDismiss(DialogInterface dialog) {
private void onTransferSericeConnected() {
// Register broadcast receiver
- IntentFilter filter = new IntentFilter(TransferService.BROADCAST_ACTION);
+ IntentFilter filter = new IntentFilter(TransferManager.BROADCAST_ACTION);
mTransferReceiver = new TransferReceiver();
LocalBroadcastManager.getInstance(this).registerReceiver(mTransferReceiver, filter);
@@ -313,11 +315,11 @@ public void onReceive(Context context, Intent intent) {
if (info == null) {
Log.w(DEBUG_TAG, "download info is null");
}
- if (type.equals(TransferService.BROADCAST_FILE_DOWNLOAD_PROGRESS)) {
+ if (type.equals(DownloadTaskManager.BROADCAST_FILE_DOWNLOAD_PROGRESS)) {
onFileDownloadProgress(info);
- } else if (type.equals(TransferService.BROADCAST_FILE_DOWNLOAD_SUCCESS)) {
+ } else if (type.equals(DownloadTaskManager.BROADCAST_FILE_DOWNLOAD_SUCCESS)) {
onFileDownloaded(info);
- } else if (type.equals(TransferService.BROADCAST_FILE_DOWNLOAD_FAILED)) {
+ } else if (type.equals(DownloadTaskManager.BROADCAST_FILE_DOWNLOAD_FAILED)) {
onFileDownloadFailed(info);
}
}
diff --git a/src/com/seafile/seadroid2/ui/activity/TransferActivity.java b/src/com/seafile/seadroid2/ui/activity/TransferActivity.java
index 5ba05a5ba..f8d926c2c 100644
--- a/src/com/seafile/seadroid2/ui/activity/TransferActivity.java
+++ b/src/com/seafile/seadroid2/ui/activity/TransferActivity.java
@@ -99,7 +99,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
return true;
case R.id.cancel_transfer_tasks:
if (currentPosition == 0) {
- getDownloadTaskFragment().cancelDownloadTasks();
+ getDownloadTaskFragment().cancelAllDownloadTasks();
} else getUploadTaskFragment().cancelUploadTasks();
diff --git a/src/com/seafile/seadroid2/ui/adapter/SeafItemAdapter.java b/src/com/seafile/seadroid2/ui/adapter/SeafItemAdapter.java
index f3655aacd..bd6c81f0d 100644
--- a/src/com/seafile/seadroid2/ui/adapter/SeafItemAdapter.java
+++ b/src/com/seafile/seadroid2/ui/adapter/SeafItemAdapter.java
@@ -67,19 +67,7 @@ public boolean isEmpty() {
}
/**
- * DownloadTask list should not be empty
- *
- * @return true if files added to download list, false otherwise
- */
- public boolean isDownloadTaskListEmpty() {
- if (mDownloadTaskInfos == null || mDownloadTaskInfos.isEmpty()) {
- return true;
- }
- return false;
- }
-
- /**
- * To refresh download status icons of {@link com.seafile.seadroid2.ui.fragment.ReposFragment #mPullRefreshListView} instantly,
+ * To refresh downloading status of {@link com.seafile.seadroid2.ui.fragment.ReposFragment #mPullRefreshListView},
* use this method to update data set.
*
* This method should be called after the download folder button was clicked.
@@ -90,24 +78,6 @@ public void setDownloadTaskList(List downloadTaskInfos) {
this.mDownloadTaskInfos = downloadTaskInfos;
}
- /**
- * To refresh download status icon of one specific item of {@link com.seafile.seadroid2.ui.fragment.ReposFragment #mPullRefreshListView} instantly,
- * use this method to update data set.
- *
- * @param downloadTaskInfo
- */
- public void setDownloadTask(DownloadTaskInfo downloadTaskInfo) {
- if (mDownloadTaskInfos == null) {
- mDownloadTaskInfos = Lists.newArrayList();
- }
- // remove old data
- if (mDownloadTaskInfos.contains(downloadTaskInfo)) {
- mDownloadTaskInfos.remove(downloadTaskInfo);
- }
-
- mDownloadTaskInfos.add(downloadTaskInfo);
- }
-
public void addEntry(SeafItem entry) {
items.add(entry);
// Collections.sort(items);
diff --git a/src/com/seafile/seadroid2/ui/adapter/TransferTaskAdapter.java b/src/com/seafile/seadroid2/ui/adapter/TransferTaskAdapter.java
index a330c6129..d7fd5da60 100644
--- a/src/com/seafile/seadroid2/ui/adapter/TransferTaskAdapter.java
+++ b/src/com/seafile/seadroid2/ui/adapter/TransferTaskAdapter.java
@@ -1,10 +1,5 @@
package com.seafile.seadroid2.ui.adapter;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
-
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
@@ -14,8 +9,6 @@
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
-
-import com.google.common.collect.Maps;
import com.seafile.seadroid2.R;
import com.seafile.seadroid2.transfer.DownloadTaskInfo;
import com.seafile.seadroid2.transfer.TransferTaskInfo;
@@ -23,6 +16,10 @@
import com.seafile.seadroid2.ui.activity.TransferActivity;
import com.seafile.seadroid2.util.Utils;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
/*
* Adapter class for both uploading and downloading tasks
*/
@@ -30,8 +27,7 @@ public class TransferTaskAdapter extends BaseAdapter {
private static final String DEBUG_TAG = "TransferTaskAdapter";
- private List mUploadTaskInfos;
- private List mDownloadTaskInfos;
+ private List extends TransferTaskInfo> mTransferTaskInfos;
private Context mContext;
/** 0 mark as Download Task, 1 mark as Upload Task, the same convention with {@link TransferActivity #currentPosition} */
private int mTransferTaskType = -1;
@@ -46,14 +42,11 @@ public class TransferTaskAdapter extends BaseAdapter {
* set {@link TransferTaskAdapter #mTransferTaskType} 0 to mark as Download Task, 1 mark to mark as Upload Task
*
* @param context
- * @param uploadTaskInfos
- * @param downloadTaskInfos
+ * @param transferTaskInfos
*/
public TransferTaskAdapter(Context context,
- List extends TransferTaskInfo> uploadTaskInfos,
- List extends TransferTaskInfo> downloadTaskInfos) {
- this.mUploadTaskInfos = (List) uploadTaskInfos;
- this.mDownloadTaskInfos = (List) downloadTaskInfos;
+ List extends TransferTaskInfo> transferTaskInfos) {
+ this.mTransferTaskInfos = transferTaskInfos;
this.mContext = context;
}
@@ -89,46 +82,24 @@ public int compare(TransferTaskInfo infoA, TransferTaskInfo infoB) {
}
}
- public void setUploadTaskInfos(List infos) {
- mUploadTaskInfos = infos;
- Collections.sort(mUploadTaskInfos, new TaskInfoComparator());
+ public void setTransferTaskInfos(List extends TransferTaskInfo> infos) {
+ mTransferTaskInfos = infos;
+ Collections.sort(mTransferTaskInfos, new TaskInfoComparator());
}
- public void setDownloadTaskInfos(List infos) {
- mDownloadTaskInfos = infos;
- Collections.sort(mDownloadTaskInfos, new TaskInfoComparator());
- }
-
@Override
public int getCount() {
- if (mTransferTaskType == 0) {
- return mDownloadTaskInfos.size();
- } else if (mTransferTaskType == 1) {
- return mUploadTaskInfos.size();
- }
- return -1;
+ return mTransferTaskInfos.size();
}
@Override
public boolean isEmpty() {
- if (mTransferTaskType == 0) {
- return mDownloadTaskInfos.isEmpty();
- } else if (mTransferTaskType == 1) {
- return mUploadTaskInfos.isEmpty();
- }
-
- return true;
+ return mTransferTaskInfos.isEmpty();
}
@Override
public TransferTaskInfo getItem(int position) {
- if (mTransferTaskType == 0) {
- return mDownloadTaskInfos.get(position);
- } else if (mTransferTaskType == 1) {
- return mUploadTaskInfos.get(position);
- }
-
- return null;
+ return mTransferTaskInfos.get(position);
}
@Override
@@ -215,9 +186,9 @@ public View getView(int position, View convertView, ViewGroup parent) {
viewHolder = (Viewholder) convertView.getTag();
}
- int iconID = 0;
+ int iconID;
if (mTransferTaskType == 0) {
- DownloadTaskInfo taskInfo = mDownloadTaskInfos.get(position);
+ DownloadTaskInfo taskInfo = (DownloadTaskInfo) mTransferTaskInfos.get(position);
iconID = Utils.getFileIcon(taskInfo.pathInRepo);
// the three fileds is not dynamic
viewHolder.icon.setImageResource(iconID);
@@ -225,7 +196,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
viewHolder.fileName.setText(Utils.fileNameFromPath(taskInfo.pathInRepo));
updateTaskView(taskInfo, viewHolder);
} else if (mTransferTaskType == 1) {
- UploadTaskInfo taskInfo = mUploadTaskInfos.get(position);
+ UploadTaskInfo taskInfo = (UploadTaskInfo) mTransferTaskInfos.get(position);
iconID = Utils.getFileIcon(taskInfo.localFilePath);
String fullpath = taskInfo.repoName + taskInfo.parentDir;
// the three fileds is not dynamic
diff --git a/src/com/seafile/seadroid2/ui/fragment/DownloadTaskFragment.java b/src/com/seafile/seadroid2/ui/fragment/DownloadTaskFragment.java
index 7502af402..ac09ec3f1 100644
--- a/src/com/seafile/seadroid2/ui/fragment/DownloadTaskFragment.java
+++ b/src/com/seafile/seadroid2/ui/fragment/DownloadTaskFragment.java
@@ -2,11 +2,12 @@
import android.os.Bundle;
import android.util.Log;
-import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import com.seafile.seadroid2.R;
-import com.seafile.seadroid2.transfer.*;
+import com.seafile.seadroid2.transfer.DownloadTaskInfo;
+import com.seafile.seadroid2.transfer.TaskState;
+import com.seafile.seadroid2.transfer.TransferTaskInfo;
import com.seafile.seadroid2.ui.adapter.TransferTaskAdapter;
import java.util.List;
@@ -19,8 +20,6 @@
public class DownloadTaskFragment extends TransferTaskFragment {
private static final String DEBUG_TAG = "DownloadTaskFragment";
- private boolean isDownloadListVisible;
-
@Override
public void onActivityCreated(Bundle savedInstanceState) {
Log.d(DEBUG_TAG, "onActivityCreated");
@@ -30,77 +29,23 @@ public void onActivityCreated(Bundle savedInstanceState) {
}
@Override
- void setUpTransferList(TransferService txService) {
+ protected List extends TransferTaskInfo> getTransferTaskInfos() {
+ return txService.getAllDownloadTaskInfos();
+ }
+
+ @Override
+ protected void setUpTransferList() {
Log.d(DEBUG_TAG, "bind TransferService");
List infos = txService.getAllDownloadTaskInfos();
- adapter = new TransferTaskAdapter(mActivity, null, infos);
+ adapter = new TransferTaskAdapter(mActivity, infos);
adapter.setCurrentTab(TransferTaskAdapter.DOWNLOAD_LIST_TAB);
mTransferTaskListView.setAdapter(adapter);
}
- @Override
- public void onResume() {
- Log.d(DEBUG_TAG, "onResume");
- isDownloadListVisible = true;
- super.onResume();
- }
-
- @Override
- public void onStop() {
- Log.d(DEBUG_TAG, "onStop");
- super.onStop();
- isDownloadListVisible = false;
- }
-
- boolean isNeedUpdateProgress() {
- // first download list should at foreground
- if (!isDownloadListVisible) {
- return false;
- }
-
- // second there are some downloading tasks
- if (txService == null)
- return false;
-
- if (!txService.isDownloading())
- return false;
-
- return true;
- }
-
- // refresh download list by mTimer
- void startTimer() {
- Log.d(DEBUG_TAG, "timer started");
- mTimer.postDelayed(new Runnable() {
-
- @Override
- public void run() {
- adapter.setDownloadTaskInfos(txService.getAllDownloadTaskInfos());
- adapter.notifyDataSetChanged();
- Log.d(DEBUG_TAG, "timer post refresh signal " + System.currentTimeMillis());
- mTimer.postDelayed(this, 1 * 1000);
- }
- }, 1 * 1000);
- }
-
- @Override
- void refreshView() {
- List infos = txService.getAllDownloadTaskInfos();
- if (infos == null || infos.isEmpty()) {
- mTransferTaskListView.setVisibility(View.GONE);
- emptyView.setVisibility(View.VISIBLE);
- } else {
- if (isNeedUpdateProgress())
- startTimer();
-
- mTransferTaskListView.setVisibility(View.VISIBLE);
- emptyView.setVisibility(View.GONE);
- adapter.setDownloadTaskInfos(infos);
- adapter.notifyDataSetChanged();
- }
-
+ protected boolean isNeedUpdateProgress() {
+ return !txService.getAllDownloadTaskInfos().isEmpty();
}
@Override
@@ -114,50 +59,39 @@ public boolean onContextItemSelected(android.view.MenuItem item) {
ListView listView = mTransferTaskListView;
DownloadTaskInfo taskInfo = (DownloadTaskInfo) listView.getItemAtPosition(info.position);
- TransferManager.TaskState state = taskInfo.state;
+ TaskState state = taskInfo.state;
int taskID = taskInfo.taskID;
- boolean needRefresh = false;
-
switch (item.getItemId()) {
case R.id.cancel:
- if (state == TransferManager.TaskState.INIT || state == TransferManager.TaskState.TRANSFERRING) {
- // txService.cancelDownloadTask(taskID);
+ if (state == TaskState.INIT || state == TaskState.TRANSFERRING) {
txService.cancelDownloadTaskInQue(taskID);
- needRefresh = true;
}
break;
case R.id.retry:
- if (state == TransferManager.TaskState.FAILED || state == TransferManager.TaskState.CANCELLED) {
+ if (state == TaskState.FAILED || state == TaskState.CANCELLED) {
txService.retryDownloadTask(taskID);
- needRefresh = true;
}
break;
case R.id.remove:
- if (state == TransferManager.TaskState.FINISHED || state == TransferManager.TaskState.FAILED || state == TransferManager.TaskState.CANCELLED) {
+ if (state == TaskState.FINISHED || state == TaskState.FAILED || state == TaskState.CANCELLED) {
txService.removeDownloadTask(taskID);
- needRefresh = true;
}
break;
case R.id.remove_all_cancelled:
- if (state == TransferManager.TaskState.CANCELLED) {
- txService.removeAllDownloadTasksByState(TransferManager.TaskState.CANCELLED);
- needRefresh = true;
+ if (state == TaskState.CANCELLED) {
+ txService.removeAllDownloadTasksByState(TaskState.CANCELLED);
}
break;
case R.id.remove_all_finished:
- if (state == TransferManager.TaskState.FINISHED) {
- txService.removeAllDownloadTasksByState(TransferManager.TaskState.FINISHED);
- needRefresh = true;
+ if (state == TaskState.FINISHED) {
+ txService.removeAllDownloadTasksByState(TaskState.FINISHED);
}
break;
default:
return super.onContextItemSelected(item);
}
- if (needRefresh) {
- refreshView();
- }
return true;
}
else
@@ -167,15 +101,10 @@ public boolean onContextItemSelected(android.view.MenuItem item) {
/**
* cancel all download tasks
*/
- public void cancelDownloadTasks() {
+ public void cancelAllDownloadTasks() {
if (txService != null) {
txService.cancellAllDownloadTasks();
}
-
- refreshView();
-
- // stop timer
- stopTimer();
}
}
diff --git a/src/com/seafile/seadroid2/ui/fragment/ReposFragment.java b/src/com/seafile/seadroid2/ui/fragment/ReposFragment.java
index 5c458a894..f7868adbd 100644
--- a/src/com/seafile/seadroid2/ui/fragment/ReposFragment.java
+++ b/src/com/seafile/seadroid2/ui/fragment/ReposFragment.java
@@ -61,6 +61,7 @@ public class ReposFragment extends SherlockListFragment {
private View mListContainer;
private TextView mErrorText;
+ private boolean isTimerStarted;
private final Handler mTimer = new Handler();
private DataManager getDataManager() {
@@ -260,6 +261,10 @@ public void navToDirectory(boolean forceRefresh) {
// refresh download list by mTimer
public void startTimer() {
+ if (isTimerStarted)
+ return;
+
+ isTimerStarted = true;
Log.d(DEBUG_TAG, "timer started");
mTimer.postDelayed(new Runnable() {
@@ -276,6 +281,7 @@ public void run() {
public void stopTimer() {
Log.d(DEBUG_TAG, "timer stopped");
mTimer.removeCallbacksAndMessages(null);
+ isTimerStarted = false;
}
/**
diff --git a/src/com/seafile/seadroid2/ui/fragment/SettingsPreferenceFragment.java b/src/com/seafile/seadroid2/ui/fragment/SettingsPreferenceFragment.java
index b27db4996..111d3d78d 100644
--- a/src/com/seafile/seadroid2/ui/fragment/SettingsPreferenceFragment.java
+++ b/src/com/seafile/seadroid2/ui/fragment/SettingsPreferenceFragment.java
@@ -31,6 +31,7 @@
import com.seafile.seadroid2.cameraupload.CameraUploadService;
import com.seafile.seadroid2.data.DataManager;
import com.seafile.seadroid2.gesturelock.LockPatternUtils;
+import com.seafile.seadroid2.transfer.TransferManager;
import com.seafile.seadroid2.transfer.TransferService;
import com.seafile.seadroid2.ui.SeafileStyleDialogBuilder;
import com.seafile.seadroid2.ui.activity.AccountsActivity;
@@ -90,7 +91,7 @@ public void onAttach(Activity activity) {
LocalBroadcastManager
.getInstance(mActivity)
.registerReceiver(transferReceiver,
- new IntentFilter(TransferService.BROADCAST_ACTION));
+ new IntentFilter(TransferManager.BROADCAST_ACTION));
}
@Override
@@ -197,7 +198,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
LocalBroadcastManager
.getInstance(getActivity().getApplicationContext())
.registerReceiver(transferReceiver,
- new IntentFilter(TransferService.BROADCAST_ACTION));
+ new IntentFilter(TransferManager.BROADCAST_ACTION));
}
diff --git a/src/com/seafile/seadroid2/ui/fragment/TransferTaskFragment.java b/src/com/seafile/seadroid2/ui/fragment/TransferTaskFragment.java
index 2337642c3..54e88e69b 100644
--- a/src/com/seafile/seadroid2/ui/fragment/TransferTaskFragment.java
+++ b/src/com/seafile/seadroid2/ui/fragment/TransferTaskFragment.java
@@ -8,6 +8,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
+import android.util.Log;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.View;
@@ -22,12 +23,15 @@
import com.seafile.seadroid2.ui.activity.TransferActivity;
import com.seafile.seadroid2.ui.adapter.TransferTaskAdapter;
+import java.util.List;
+
/**
* Base class for transfer task fragments
*
* Created by Logan on 14/12/22.
*/
public abstract class TransferTaskFragment extends SherlockListFragment {
+ private String DEBUG_TAG = "TransferTaskFragment";
protected TransferTaskAdapter adapter;
protected TransferActivity mActivity = null;
@@ -70,16 +74,20 @@ public void onActivityCreated(Bundle savedInstanceState) {
mActivity.bindService(bIntent, mConnection, Context.BIND_AUTO_CREATE);
}
- ServiceConnection mConnection = new ServiceConnection() {
+ private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
- TransferService.TransferBinder binder = (TransferService.TransferBinder) service;
- txService = binder.getService();
- setUpTransferList(txService);
- refreshView();
-
// Toast.makeText(mActivity, "Stop loading animations", Toast.LENGTH_LONG).show();
showLoading(false);
+
+ TransferService.TransferBinder binder = (TransferService.TransferBinder) service;
+ txService = binder.getService();
+ if (isNeedUpdateProgress()) {
+ mTransferTaskListView.setVisibility(View.VISIBLE);
+ emptyView.setVisibility(View.GONE);
+ setUpTransferList();
+ startTimer();
+ }
}
@Override
@@ -88,17 +96,18 @@ public void onServiceDisconnected(ComponentName arg0) {
}
};
- abstract void setUpTransferList(TransferService txService);
+ protected abstract List extends TransferTaskInfo> getTransferTaskInfos();
+
+ protected abstract void setUpTransferList();
@Override
public void onResume() {
super.onResume();
- // refreshView();
- if (isNeedUpdateProgress())
- startTimer();
+ mTransferTaskListView.setVisibility(View.GONE);
+ emptyView.setVisibility(View.VISIBLE);
}
- abstract boolean isNeedUpdateProgress();
+ protected abstract boolean isNeedUpdateProgress();
@Override
public void onStop() {
@@ -111,14 +120,24 @@ public void onStop() {
}
// refresh list by mTimer
- abstract void startTimer();
+ private void startTimer() {
+ Log.d(DEBUG_TAG, "timer started");
+ mTimer.postDelayed(new Runnable() {
+
+ @Override
+ public void run() {
+ adapter.setTransferTaskInfos(getTransferTaskInfos());
+ adapter.notifyDataSetChanged();
+ Log.d(DEBUG_TAG, "timer post refresh signal " + System.currentTimeMillis());
+ mTimer.postDelayed(this, 1 * 1000);
+ }
+ }, 1 * 1000);
+ }
public void stopTimer() {
mTimer.removeCallbacksAndMessages(null);
}
- abstract void refreshView();
-
private void showLoading(boolean show) {
if (mActivity == null)
return;
diff --git a/src/com/seafile/seadroid2/ui/fragment/UploadTaskFragment.java b/src/com/seafile/seadroid2/ui/fragment/UploadTaskFragment.java
index d38246f9e..fa09e4f05 100644
--- a/src/com/seafile/seadroid2/ui/fragment/UploadTaskFragment.java
+++ b/src/com/seafile/seadroid2/ui/fragment/UploadTaskFragment.java
@@ -1,12 +1,12 @@
package com.seafile.seadroid2.ui.fragment;
import android.os.Bundle;
-import android.util.Log;
-import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import com.seafile.seadroid2.R;
-import com.seafile.seadroid2.transfer.*;
+import com.seafile.seadroid2.transfer.TaskState;
+import com.seafile.seadroid2.transfer.TransferTaskInfo;
+import com.seafile.seadroid2.transfer.UploadTaskInfo;
import com.seafile.seadroid2.ui.adapter.TransferTaskAdapter;
import java.util.List;
@@ -19,8 +19,6 @@
public class UploadTaskFragment extends TransferTaskFragment {
private static final String DEBUG_TAG = "UploadTaskFragment";
- private boolean isUploadListVisible;
-
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
@@ -30,72 +28,21 @@ public void onActivityCreated(Bundle savedInstanceState) {
}
@Override
- void setUpTransferList(TransferService txService) {
+ protected List extends TransferTaskInfo> getTransferTaskInfos() {
+ return txService.getAllUploadTaskInfos();
+ }
+
+ @Override
+ protected void setUpTransferList() {
List infos = txService.getAllUploadTaskInfos();
- adapter = new TransferTaskAdapter(mActivity, infos, null);
+ adapter = new TransferTaskAdapter(mActivity, infos);
adapter.setCurrentTab(TransferTaskAdapter.UPLOAD_LIST_TAB);
mTransferTaskListView.setAdapter(adapter);
}
@Override
- public void onResume() {
- isUploadListVisible = true;
- super.onResume();
- }
-
- boolean isNeedUpdateProgress() {
- // first upload list should at foreground
- if (!isUploadListVisible) {
- return false;
- }
-
- // second there are some upload tasks
- if(txService == null)
- return false;
-
- if (!txService.isUploading())
- return false;
-
- return true;
- }
-
- @Override
- public void onStop() {
- super.onStop();
- isUploadListVisible = false;
- }
-
- // refresh upload list by mTimer
- void startTimer() {
- Log.d(DEBUG_TAG, "timer started");
- mTimer.postDelayed(new Runnable() {
-
- @Override
- public void run() {
- adapter.setUploadTaskInfos(txService.getAllUploadTaskInfos());
- adapter.notifyDataSetChanged();
- Log.d(DEBUG_TAG, "timer post refresh signal " + System.currentTimeMillis());
- mTimer.postDelayed(this, 1 * 1000);
- }
- }, 1 * 1000);
- }
-
- void refreshView() {
-
- List infos = txService.getAllUploadTaskInfos();
- if (infos == null || infos.isEmpty()) {
- mTransferTaskListView.setVisibility(View.GONE);
- emptyView.setVisibility(View.VISIBLE);
- } else {
- if (isNeedUpdateProgress())
- startTimer();
-
- mTransferTaskListView.setVisibility(View.VISIBLE);
- emptyView.setVisibility(View.GONE);
- adapter.setUploadTaskInfos(infos);
- adapter.notifyDataSetChanged();
- }
-
+ protected boolean isNeedUpdateProgress() {
+ return !txService.getAllUploadTaskInfos().isEmpty();
}
@Override
@@ -109,50 +56,39 @@ public boolean onContextItemSelected(android.view.MenuItem item) {
ListView listView = mTransferTaskListView;
UploadTaskInfo taskInfo = (UploadTaskInfo) listView.getItemAtPosition(info.position);
- TransferManager.TaskState state = taskInfo.state;
+ TaskState state = taskInfo.state;
int taskID = taskInfo.taskID;
- boolean needRefresh = false;
-
switch (item.getItemId()) {
case R.id.cancel:
- if (state == TransferManager.TaskState.INIT || state == TransferManager.TaskState.TRANSFERRING) {
- // txService.cancelUploadTask(taskID);
+ if (state == TaskState.INIT || state == TaskState.TRANSFERRING) {
txService.cancelUploadTaskInQue(taskID);
- needRefresh = true;
}
break;
case R.id.retry:
- if (state == TransferManager.TaskState.FAILED || state == TransferManager.TaskState.CANCELLED) {
+ if (state == TaskState.FAILED || state == TaskState.CANCELLED) {
txService.retryUploadTask(taskID);
- needRefresh = true;
}
break;
case R.id.remove:
- if (state == TransferManager.TaskState.FINISHED || state == TransferManager.TaskState.FAILED || state == TransferManager.TaskState.CANCELLED) {
+ if (state == TaskState.FINISHED || state == TaskState.FAILED || state == TaskState.CANCELLED) {
txService.removeUploadTask(taskID);
- needRefresh = true;
}
break;
case R.id.remove_all_cancelled:
- if (state == TransferManager.TaskState.CANCELLED) {
- txService.removeAllUploadTasksByState(TransferManager.TaskState.CANCELLED);
- needRefresh = true;
+ if (state == TaskState.CANCELLED) {
+ txService.removeAllUploadTasksByState(TaskState.CANCELLED);
}
break;
case R.id.remove_all_finished:
- if (state == TransferManager.TaskState.FINISHED) {
- txService.removeFinishedUploadTasks();
- needRefresh = true;
+ if (state == TaskState.FINISHED) {
+ txService.removeAllUploadTasksByState(TaskState.FINISHED);
}
break;
default:
return super.onContextItemSelected(item);
}
- if (needRefresh) {
- refreshView();
- }
return true;
}
else
@@ -169,10 +105,5 @@ public void cancelUploadTasks() {
if (txService != null) {
txService.cancelAllUploadTasks();
}
-
- refreshView();
-
- // stop timer
- stopTimer();
}
}
\ No newline at end of file