aboutsummaryrefslogtreecommitdiff
path: root/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java
diff options
context:
space:
mode:
authorMaxime Biais <maxime.biais@gmail.com>2015-03-17 12:21:21 +0100
committerMaxime Biais <maxime.biais@gmail.com>2015-03-17 12:21:21 +0100
commitb2d5377642ae027c1a458dfde6c43054812e4205 (patch)
tree3f8a2bd8a6dde207750aeb26a5f7ad81182b9df8 /WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java
parenta9e0705af4b26b5de638365973b9accd4f4f2878 (diff)
parentcd0666435f95d03d5de7cedd4dd10e92d2410691 (diff)
downloadgradle-perf-android-medium-b2d5377642ae027c1a458dfde6c43054812e4205.tar.gz
Merge remote-tracking branch 'origin/develop' into feature/modularize-editor
Diffstat (limited to 'WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java')
-rw-r--r--WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java43
1 files changed, 41 insertions, 2 deletions
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java
index 0e86bb0c8..166975662 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java
+++ b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java
@@ -3,9 +3,13 @@ package org.wordpress.android.ui.media;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
+import android.content.BroadcastReceiver;
+import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.database.Cursor;
import android.graphics.drawable.ColorDrawable;
+import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
@@ -36,6 +40,7 @@ import org.wordpress.android.ui.media.MediaGridFragment.Filter;
import org.wordpress.android.ui.media.MediaGridFragment.MediaGridListener;
import org.wordpress.android.ui.media.MediaItemFragment.MediaItemFragmentCallback;
import org.wordpress.android.ui.media.services.MediaDeleteService;
+import org.wordpress.android.util.NetworkUtils;
import org.wordpress.android.widgets.WPAlertDialogFragment;
import org.xmlrpc.android.ApiHelper;
import org.xmlrpc.android.ApiHelper.GetFeatures.Callback;
@@ -66,6 +71,21 @@ public class MediaBrowserActivity extends WPDrawerActivity implements MediaGridL
private FeatureSet mFeatureSet;
private String mQuery;
+ private BroadcastReceiver mReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) {
+ // Coming from zero connection. Continue what's pending for delete
+ String blogId = String.valueOf(WordPress.getCurrentBlog().getLocalTableBlogId());
+ if (WordPress.wpDB.getMediaDeleteQueueItems(blogId).getCount() > 0) {
+ startMediaDeleteService();
+ }
+ }
+ }
+ };
+
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -106,6 +126,18 @@ public class MediaBrowserActivity extends WPDrawerActivity implements MediaGridL
}
@Override
+ public void onStart() {
+ super.onStart();
+ registerReceiver(mReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
+ }
+
+ @Override
+ public void onStop() {
+ unregisterReceiver(mReceiver);
+ super.onStop();
+ }
+
+ @Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(SAVED_QUERY, mQuery);
@@ -136,6 +168,11 @@ public class MediaBrowserActivity extends WPDrawerActivity implements MediaGridL
private final FragmentManager.OnBackStackChangedListener mOnBackStackChangedListener = new FragmentManager.OnBackStackChangedListener() {
public void onBackStackChanged() {
+ FragmentManager manager = getFragmentManager();
+ MediaGridFragment mediaGridFragment = (MediaGridFragment)manager.findFragmentById(R.id.mediaGridFragment);
+ if (mediaGridFragment.isVisible()) {
+ mediaGridFragment.refreshSpinnerAdapter();
+ }
setupBaseLayout();
}
};
@@ -471,7 +508,9 @@ public class MediaBrowserActivity extends WPDrawerActivity implements MediaGridL
}
private void startMediaDeleteService() {
- startService(new Intent(this, MediaDeleteService.class));
+ if (NetworkUtils.isNetworkAvailable(this)) {
+ startService(new Intent(this, MediaDeleteService.class));
+ }
}
@Override
@@ -541,7 +580,7 @@ public class MediaBrowserActivity extends WPDrawerActivity implements MediaGridL
// mark items for delete without actually deleting items yet,
// and then refresh the grid
WordPress.wpDB.setMediaFilesMarkedForDelete(blogId, sanitizedIds);
- startService(new Intent(this, MediaDeleteService.class));
+ startMediaDeleteService();
if (mMediaGridFragment != null) {
mMediaGridFragment.clearSelectedItems();
mMediaGridFragment.refreshMediaFromDB();