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