Refactor media views (#866)
* Migrate ImagePagerAdapter to kotlin * Migrate ViewMediaFragment to kotlin * Make images and videos share the same activity/pager * Show descriptions above videos * Cleanup * Address code review feedback * Migrate media fragments to constraint layout
This commit is contained in:
parent
1556a88d05
commit
952d2a6512
16 changed files with 632 additions and 594 deletions
|
@ -1,42 +0,0 @@
|
|||
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.entity.Attachment;
|
||||
import com.keylesspalace.tusky.fragment.ViewMediaFragment;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public final class ImagePagerAdapter extends FragmentPagerAdapter {
|
||||
|
||||
private List<Attachment> attachments;
|
||||
private int initialPosition;
|
||||
|
||||
public ImagePagerAdapter(FragmentManager fragmentManager, List<Attachment> attachments, int initialPosition) {
|
||||
super(fragmentManager);
|
||||
this.attachments = attachments;
|
||||
this.initialPosition = initialPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
if (position >= 0 && position < attachments.size()) {
|
||||
return ViewMediaFragment.newInstance(attachments.get(position), position == initialPosition);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return attachments.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
return String.format(Locale.getDefault(), "%d/%d", position + 1, attachments.size());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.keylesspalace.tusky.pager
|
||||
|
||||
import android.support.v4.app.Fragment
|
||||
import android.support.v4.app.FragmentManager
|
||||
import android.support.v4.app.FragmentStatePagerAdapter
|
||||
|
||||
import com.keylesspalace.tusky.entity.Attachment
|
||||
import com.keylesspalace.tusky.fragment.ViewMediaFragment
|
||||
|
||||
import java.util.Locale
|
||||
|
||||
class ImagePagerAdapter(
|
||||
fragmentManager: FragmentManager,
|
||||
private val attachments: List<Attachment>,
|
||||
private val initialPosition: Int
|
||||
) : FragmentStatePagerAdapter(fragmentManager) {
|
||||
|
||||
override fun getItem(position: Int): Fragment? {
|
||||
return if (position >= 0 && position < attachments.size) {
|
||||
ViewMediaFragment.newInstance(attachments[position], position == initialPosition)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
override fun getCount(): Int {
|
||||
return attachments.size
|
||||
}
|
||||
|
||||
override fun getPageTitle(position: Int): CharSequence {
|
||||
return String.format(Locale.getDefault(), "%d/%d", position + 1, attachments.size)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue