add possibility to view avatars fullscreen (#724)
* add possibility to view avatars fullscreen * improve codestyle
This commit is contained in:
parent
133808891d
commit
b5a8915845
4 changed files with 106 additions and 37 deletions
|
@ -32,6 +32,7 @@ import android.support.annotation.ColorInt
|
|||
import android.support.annotation.Px
|
||||
import android.support.design.widget.*
|
||||
import android.support.text.emoji.EmojiCompat
|
||||
import android.support.v4.app.ActivityOptionsCompat
|
||||
import android.support.v4.app.Fragment
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v4.view.ViewCompat
|
||||
|
@ -145,8 +146,6 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasSupportF
|
|||
val intent = intent
|
||||
accountId = intent.getStringExtra(KEY_ACCOUNT_ID)
|
||||
|
||||
loadedAccount = null
|
||||
|
||||
// set toolbar top margin according to system window insets
|
||||
ViewCompat.setOnApplyWindowInsetsListener(accountCoordinatorLayout) { _, insets ->
|
||||
val top = insets.systemWindowInsetTop
|
||||
|
@ -320,6 +319,15 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasSupportF
|
|||
.load(account.header)
|
||||
.into(accountHeaderImageView)
|
||||
|
||||
accountAvatarImageView.setOnClickListener { avatarView ->
|
||||
val intent = ViewMediaActivity.newAvatarIntent(avatarView.context, account.avatar)
|
||||
|
||||
ViewCompat.setTransitionName(avatarView, account.avatar)
|
||||
val options = ActivityOptionsCompat.makeSceneTransitionAnimation(this, avatarView, account.avatar)
|
||||
|
||||
startActivity(intent, options.toBundle())
|
||||
}
|
||||
|
||||
accountFieldAdapter.fields = account.fields ?: emptyList()
|
||||
accountFieldAdapter.emojis = account.emojis ?: emptyList()
|
||||
accountFieldAdapter.notifyDataSetChanged()
|
||||
|
|
|
@ -23,8 +23,6 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
@ -35,6 +33,7 @@ import android.support.annotation.StringRes;
|
|||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
|
@ -44,6 +43,7 @@ import android.widget.Toast;
|
|||
|
||||
import com.keylesspalace.tusky.entity.Attachment;
|
||||
import com.keylesspalace.tusky.fragment.ViewMediaFragment;
|
||||
import com.keylesspalace.tusky.pager.AvatarImagePagerAdapter;
|
||||
import com.keylesspalace.tusky.pager.ImagePagerAdapter;
|
||||
import com.keylesspalace.tusky.view.ImageViewPager;
|
||||
import com.keylesspalace.tusky.viewdata.AttachmentViewData;
|
||||
|
@ -57,14 +57,20 @@ import kotlin.jvm.functions.Function0;
|
|||
|
||||
public final class ViewMediaActivity extends BaseActivity
|
||||
implements ViewMediaFragment.PhotoActionsListener {
|
||||
private static final String ATTACHMENTS_EXTRA = "attachments";
|
||||
private static final String INDEX_EXTRA = "index";
|
||||
private static final String EXTRA_ATTACHMENTS = "attachments";
|
||||
private static final String EXTRA_ATTACHMENT_INDEX = "index";
|
||||
private static final String EXTRA_AVATAR_URL = "avatar";
|
||||
|
||||
public static Intent newIntent(Context context, List<AttachmentViewData> attachments,
|
||||
int index) {
|
||||
public static Intent newIntent(Context context, List<AttachmentViewData> attachments, int index) {
|
||||
final Intent intent = new Intent(context, ViewMediaActivity.class);
|
||||
intent.putParcelableArrayListExtra(ATTACHMENTS_EXTRA, new ArrayList<>(attachments));
|
||||
intent.putExtra(INDEX_EXTRA, index);
|
||||
intent.putParcelableArrayListExtra(EXTRA_ATTACHMENTS, new ArrayList<>(attachments));
|
||||
intent.putExtra(EXTRA_ATTACHMENT_INDEX, index);
|
||||
return intent;
|
||||
}
|
||||
|
||||
public static Intent newAvatarIntent(Context context, String url) {
|
||||
final Intent intent = new Intent(context, ViewMediaActivity.class);
|
||||
intent.putExtra(EXTRA_AVATAR_URL, url);
|
||||
return intent;
|
||||
}
|
||||
|
||||
|
@ -72,9 +78,10 @@ public final class ViewMediaActivity extends BaseActivity
|
|||
|
||||
private ImageViewPager viewPager;
|
||||
private View anyView;
|
||||
private List<AttachmentViewData> attachments;
|
||||
private Toolbar toolbar;
|
||||
|
||||
private List<AttachmentViewData> attachments;
|
||||
|
||||
private boolean isToolbarVisible = true;
|
||||
private final List<ToolbarVisibilityListener> toolbarVisibilityListeners = new ArrayList<>();
|
||||
|
||||
|
@ -106,14 +113,28 @@ public final class ViewMediaActivity extends BaseActivity
|
|||
|
||||
// Gather the parameters.
|
||||
Intent intent = getIntent();
|
||||
attachments = intent.getParcelableArrayListExtra(ATTACHMENTS_EXTRA);
|
||||
int initialPosition = intent.getIntExtra(INDEX_EXTRA, 0);
|
||||
attachments = intent.getParcelableArrayListExtra(EXTRA_ATTACHMENTS);
|
||||
int initialPosition = intent.getIntExtra(EXTRA_ATTACHMENT_INDEX, 0);
|
||||
|
||||
final PagerAdapter adapter;
|
||||
|
||||
if(attachments != null) {
|
||||
List<Attachment> realAttachs =
|
||||
CollectionsKt.map(attachments, AttachmentViewData::getAttachment);
|
||||
// Setup the view pager.
|
||||
final ImagePagerAdapter adapter = new ImagePagerAdapter(getSupportFragmentManager(),
|
||||
adapter = new ImagePagerAdapter(getSupportFragmentManager(),
|
||||
realAttachs, initialPosition);
|
||||
|
||||
} else {
|
||||
String avatarUrl = intent.getStringExtra(EXTRA_AVATAR_URL);
|
||||
|
||||
if(avatarUrl == null) {
|
||||
throw new IllegalArgumentException("attachment list or avatar url has to be set");
|
||||
}
|
||||
|
||||
adapter = new AvatarImagePagerAdapter(getSupportFragmentManager(), avatarUrl);
|
||||
}
|
||||
|
||||
viewPager.setAdapter(adapter);
|
||||
viewPager.setCurrentItem(initialPosition);
|
||||
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||
|
@ -165,17 +186,12 @@ public final class ViewMediaActivity extends BaseActivity
|
|||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
if(attachments != null) {
|
||||
getMenuInflater().inflate(R.menu.view_media_toolbar, menu);
|
||||
// Manually tint all action buttons, because the theme overlay doesn't handle them properly.
|
||||
for (int i = 0; i < menu.size(); i++) {
|
||||
Drawable drawable = menu.getItem(i).getIcon();
|
||||
if (drawable != null) {
|
||||
drawable.mutate();
|
||||
int color = ContextCompat.getColor(this, R.color.text_color_primary_dark);
|
||||
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -62,19 +62,30 @@ public final class ViewMediaFragment extends BaseFragment {
|
|||
private Function0 toolbarVisibiltyDisposable;
|
||||
|
||||
private static final String ARG_START_POSTPONED_TRANSITION = "startPostponedTransition";
|
||||
private static final String ATTACH_ARG = "attach";
|
||||
private static final String ARG_ATTACHMENT = "attach";
|
||||
private static final String ARG_AVATAR_URL = "avatarUrl";
|
||||
|
||||
public static ViewMediaFragment newInstance(@NonNull Attachment attachment,
|
||||
boolean shouldStartPostponedTransition) {
|
||||
Bundle arguments = new Bundle();
|
||||
Bundle arguments = new Bundle(2);
|
||||
ViewMediaFragment fragment = new ViewMediaFragment();
|
||||
arguments.putParcelable(ATTACH_ARG, attachment);
|
||||
arguments.putParcelable(ARG_ATTACHMENT, attachment);
|
||||
arguments.putBoolean(ARG_START_POSTPONED_TRANSITION, shouldStartPostponedTransition);
|
||||
|
||||
fragment.setArguments(arguments);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public static ViewMediaFragment newAvatarInstance(@NonNull String avatarUrl) {
|
||||
Bundle arguments = new Bundle(2);
|
||||
ViewMediaFragment fragment = new ViewMediaFragment();
|
||||
arguments.putString(ARG_AVATAR_URL, avatarUrl);
|
||||
arguments.putBoolean(ARG_START_POSTPONED_TRANSITION, true);
|
||||
|
||||
fragment.setArguments(arguments);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
|
@ -89,13 +100,26 @@ public final class ViewMediaFragment extends BaseFragment {
|
|||
descriptionView = rootView.findViewById(R.id.tv_media_description);
|
||||
|
||||
final Bundle arguments = Objects.requireNonNull(getArguments(), "Empty arguments");
|
||||
final Attachment attachment = arguments.getParcelable(ATTACH_ARG);
|
||||
final String url = attachment.getUrl();
|
||||
final Attachment attachment = arguments.getParcelable(ARG_ATTACHMENT);
|
||||
final String url;
|
||||
|
||||
if(attachment != null) {
|
||||
url = attachment.getUrl();
|
||||
|
||||
@Nullable final String description = attachment.getDescription();
|
||||
|
||||
descriptionView.setText(description);
|
||||
showingDescription = !TextUtils.isEmpty(description);
|
||||
isDescriptionVisible = showingDescription;
|
||||
} else {
|
||||
url = arguments.getString(ARG_AVATAR_URL);
|
||||
if(url == null) {
|
||||
throw new IllegalArgumentException("attachment or avatar url has to be set");
|
||||
}
|
||||
|
||||
showingDescription = false;
|
||||
isDescriptionVisible = false;
|
||||
}
|
||||
|
||||
// Setting visibility without animations so it looks nice when you scroll images
|
||||
//noinspection ConstantConditions
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package com.keylesspalace.tusky.pager
|
||||
|
||||
import android.support.v4.app.Fragment
|
||||
import android.support.v4.app.FragmentManager
|
||||
import android.support.v4.app.FragmentPagerAdapter
|
||||
|
||||
import com.keylesspalace.tusky.fragment.ViewMediaFragment
|
||||
|
||||
class AvatarImagePagerAdapter(fragmentManager: FragmentManager, private val avatarUrl: String) : FragmentPagerAdapter(fragmentManager) {
|
||||
|
||||
override fun getItem(position: Int): Fragment? {
|
||||
return if (position == 0) {
|
||||
ViewMediaFragment.newAvatarInstance(avatarUrl)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
override fun getCount() = 1
|
||||
|
||||
}
|
Loading…
Reference in a new issue