allow refreshing media view too

- closes #10
This commit is contained in:
tibbi 2016-07-20 22:41:58 +02:00
parent b31a18e48c
commit 427e44f3bd
2 changed files with 35 additions and 13 deletions

View file

@ -13,6 +13,7 @@ import android.os.Parcelable;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log; import android.util.Log;
import android.util.SparseBooleanArray; import android.util.SparseBooleanArray;
import android.view.ActionMode; import android.view.ActionMode;
@ -44,9 +45,11 @@ import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
public class MediaActivity extends SimpleActivity public class MediaActivity extends SimpleActivity
implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener { implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener,
SwipeRefreshLayout.OnRefreshListener {
private static final String TAG = MediaActivity.class.getSimpleName(); private static final String TAG = MediaActivity.class.getSimpleName();
@BindView(R.id.media_grid) GridView mGridView; @BindView(R.id.media_grid) GridView mGridView;
@BindView(R.id.media_holder) SwipeRefreshLayout mSwipeRefreshLayout;
private static List<Medium> mMedia; private static List<Medium> mMedia;
private static String mPath; private static String mPath;
@ -66,6 +69,10 @@ public class MediaActivity extends SimpleActivity
ButterKnife.bind(this); ButterKnife.bind(this);
mIsGetImageIntent = getIntent().getBooleanExtra(Constants.GET_IMAGE_INTENT, false); mIsGetImageIntent = getIntent().getBooleanExtra(Constants.GET_IMAGE_INTENT, false);
mIsGetVideoIntent = getIntent().getBooleanExtra(Constants.GET_VIDEO_INTENT, false); mIsGetVideoIntent = getIntent().getBooleanExtra(Constants.GET_VIDEO_INTENT, false);
mToBeDeleted = new ArrayList<>();
mSwipeRefreshLayout.setOnRefreshListener(this);
mPath = getIntent().getStringExtra(Constants.DIRECTORY);
mMedia = new ArrayList<>();
} }
@Override @Override
@ -93,9 +100,12 @@ public class MediaActivity extends SimpleActivity
} }
private void initializeGallery() { private void initializeGallery() {
mToBeDeleted = new ArrayList<>(); final List<Medium> newMedia = getMedia();
mPath = getIntent().getStringExtra(Constants.DIRECTORY); if (newMedia.toString().equals(mMedia.toString())) {
mMedia = getMedia(); return;
}
mMedia = newMedia;
if (isDirEmpty()) if (isDirEmpty())
return; return;
@ -347,4 +357,10 @@ public class MediaActivity extends SimpleActivity
return false; return false;
} }
@Override
public void onRefresh() {
initializeGallery();
mSwipeRefreshLayout.setRefreshing(false);
}
} }

View file

@ -6,15 +6,21 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@android:color/black"> android:background="@android:color/black">
<GridView <android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/media_grid" android:id="@+id/media_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content">
android:choiceMode="multipleChoiceModal"
android:columnWidth="@dimen/medium_tmb_size"
android:horizontalSpacing="1dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="1dp"/>
<GridView
android:id="@+id/media_grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="multipleChoiceModal"
android:columnWidth="@dimen/medium_tmb_size"
android:horizontalSpacing="1dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="1dp"/>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout> </android.support.design.widget.CoordinatorLayout>