improved media gallery

This commit is contained in:
Mariotaku Lee 2015-03-04 15:53:20 +08:00
parent 3dce8d9a9f
commit e11e9cb1d4
4 changed files with 76 additions and 35 deletions

View File

@ -28,6 +28,8 @@ import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.support.v7.app.ActionBar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
@ -68,6 +70,17 @@ public final class MediaViewerActivity extends ThemedActionBarActivity implement
return ThemeUtils.getViewerThemeResource(this);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home: {
finish();
return true;
}
}
return super.onOptionsItemSelected(item);
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
@ -83,6 +96,12 @@ public final class MediaViewerActivity extends ThemedActionBarActivity implement
}
@Override
public void onSupportContentChanged() {
super.onSupportContentChanged();
mViewPager = (ViewPager) findViewById(R.id.view_pager);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -104,24 +123,25 @@ public final class MediaViewerActivity extends ThemedActionBarActivity implement
}
}
@Override
public void onSupportContentChanged() {
super.onSupportContentChanged();
mViewPager = (ViewPager) findViewById(R.id.view_pager);
private boolean isBarShowing() {
if (mActionBar == null) return false;
return mActionBar.isShowing();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home: {
finish();
return true;
}
private void setBarVisibility(boolean visible) {
if (mActionBar == null) return;
if (visible) {
mActionBar.show();
} else {
mActionBar.hide();
}
return super.onOptionsItemSelected(item);
}
public static final class MediaPageFragment extends BaseSupportFragment
private void toggleBar() {
setBarVisibility(!isBarShowing());
}
public static final class ImagePageFragment extends BaseSupportFragment
implements DownloadListener, LoaderCallbacks<Result>, OnLayoutChangeListener, OnClickListener, ZoomListener {
private TouchImageView mImageView;
@ -197,9 +217,15 @@ public final class MediaViewerActivity extends ThemedActionBarActivity implement
return inflater.inflate(R.layout.fragment_media_page, container, false);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_media_viewer_image_page, menu);
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setHasOptionsMenu(true);
mImageView.setOnClickListener(this);
mImageView.setZoomListener(this);
loadImage();
@ -285,26 +311,6 @@ public final class MediaViewerActivity extends ThemedActionBarActivity implement
}
}
private void toggleBar() {
setBarVisibility(!isBarShowing());
}
private void setBarVisibility(boolean visible) {
if (mActionBar == null) return;
if (visible) {
mActionBar.show();
} else {
mActionBar.hide();
}
}
private boolean isBarShowing() {
if (mActionBar == null) return false;
return mActionBar.isShowing();
}
private static class MediaPagerAdapter extends SupportFixedFragmentStatePagerAdapter {
private final MediaViewerActivity mActivity;
@ -327,7 +333,7 @@ public final class MediaViewerActivity extends ThemedActionBarActivity implement
final Bundle args = new Bundle();
args.putLong(EXTRA_ACCOUNT_ID, mAccountId);
args.putParcelable(EXTRA_MEDIA, mMedia[position]);
return Fragment.instantiate(mActivity, MediaPageFragment.class.getName(), args);
return Fragment.instantiate(mActivity, ImagePageFragment.class.getName(), args);
}
public void setMedia(long accountId, ParcelableMedia[] media) {

View File

@ -33,7 +33,7 @@ import org.mariotaku.twidere.util.Utils;
public class ConnectivityStateReceiver extends BroadcastReceiver implements Constants {
private static final String RECEIVER_LOGTAG = LOGTAG + "." + "ConnectivityStateReceiver";
private static final String RECEIVER_LOGTAG = LOGTAG + "." + "Connectivity";
@Override
public void onReceive(final Context context, final Intent intent) {

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Twidere - Twitter client for Android
~
~ Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:icon="@drawable/ic_action_refresh"
app:showAsAction="ifRoom"
android:title="@string/refresh"/>
<item
android:icon="@drawable/ic_action_save"
app:showAsAction="ifRoom"
android:title="@string/save_to_gallery"/>
<item
android:icon="@drawable/ic_action_web"
android:title="@string/open_in_browser"/>
</menu>

View File

@ -720,5 +720,6 @@
<string name="edit_tabs">Edit tabs</string>
<string name="no_location">No location</string>
<string name="getting_location">Getting location</string>
<string name="save_to_gallery">Save to gallery</string>
</resources>