Commit cbc5b96c by fengquan

feat: 咨询师详情页改版

parent de89a4c2
......@@ -24,6 +24,7 @@
android:theme="@style/consultant_Transparent"/>
<activity android:name=".preview.GPreviewActivity"
android:screenOrientation="portrait"
android:theme="@style/consultant_Transparent"/>
</application>
......
package com.yidianling.consultant.preview;
import android.animation.ObjectAnimator;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.yidianling.consultant.R;
import java.util.ArrayList;
import java.util.List;
/**
* @author rainb
*/
public class GPreviewActivity extends AppCompatActivity {
protected boolean isTransformOut = false;
/*** 图片的地址***/
private List<IThumbViewInfo> imgUrls;
/*** 当前图片的位置 ***/
protected int currentIndex;
/***指示器类型枚举***/
private GPreviewBuilder.IndicatorType type;
/***默认显示***/
private boolean isShow = true;
/*** 展示图片的viewPager ***/
private PhotoViewPager viewPager;
/*** 图片的展示的Fragment***/
private List<BasePhotoFragment> fragments = new ArrayList<>();
private View backIv;
private View btnLL;
private View titleBar;
private TextView selectPosition;
private TextView total;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initData();
setContentView(R.layout.consultant_image_preview_photo);
initView();
}
private void initView() {
viewPager = findViewById(R.id.viewPager);
//viewPager的适配器
PhotoPagerAdapter adapter = new PhotoPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(adapter);
viewPager.setCurrentItem(currentIndex);
backIv = findViewById(R.id.ivBack);
btnLL = findViewById(R.id.btnLL);
selectPosition = findViewById(R.id.select_position);
total = findViewById(R.id.total);
titleBar = findViewById(R.id.titleBar);
backIv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
transformOutAnim();
transformOut();
}
});
selectPosition.setText((currentIndex + 1) + "");
total.setText(imgUrls == null ? "0" : imgUrls.size() + "");
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
selectPosition.setText((position + 1) + "");
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
// viewPager.setOffscreenPageLimit(3);
}
private void initData() {
imgUrls = getIntent().getParcelableArrayListExtra("imagePaths");
currentIndex = getIntent().getIntExtra("position", -1);
type = (GPreviewBuilder.IndicatorType) getIntent().getSerializableExtra("type");
isShow = getIntent().getBooleanExtra("isShow", true);
boolean isFullscreen = getIntent().getBooleanExtra("isFullscreen", false);
boolean isScale = getIntent().getBooleanExtra("isScale", false);
SmoothImageView.setFullscreen(isFullscreen);
SmoothImageView.setIsScale(isScale);
if (isFullscreen) {
setTheme(android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
}
initFragment(imgUrls, currentIndex, BasePhotoFragment.class);
}
private void initFragment(List<IThumbViewInfo> imgUrls, int currentIndex, Class<BasePhotoFragment> className) {
if (imgUrls != null) {
int size = imgUrls.size();
for (int i = 0; i < size; i++) {
fragments.add(BasePhotoFragment.
getInstance(className, imgUrls.get(i),
currentIndex == i,
getIntent().getBooleanExtra("isSingleFling", false),
getIntent().getBooleanExtra("isDrag", false),
getIntent().getFloatExtra("sensitivity", 0.5f))
);
}
} else {
finish();
}
}
@Override
protected void onDestroy() {
ZoomMediaLoader.getInstance().getLoader().clearMemory(this);
if (viewPager != null) {
viewPager.setAdapter(null);
viewPager.clearOnPageChangeListeners();
viewPager.removeAllViews();
viewPager = null;
}
if (fragments != null) {
fragments.clear();
fragments = null;
}
if (imgUrls != null) {
imgUrls.clear();
imgUrls = null;
}
super.onDestroy();
}
/***
* 得到PhotoViewPager
* @return PhotoViewPager
* **/
public PhotoViewPager getViewPager() {
return viewPager;
}
public void transformOut() {
if (isTransformOut) {
return;
}
getViewPager().setEnabled(false);
isTransformOut = true;
int currentItem = viewPager.getCurrentItem();
if (currentItem < imgUrls.size()) {
if (TextUtils.isEmpty(imgUrls.get(currentItem).getVideoUrl())) {
BasePhotoFragment fragment = fragments.get(currentItem);
fragment.changeBg(Color.TRANSPARENT);
fragment.transformOut(new SmoothImageView.onTransformListener() {
@Override
public void onTransformCompleted(SmoothImageView.Status status) {
getViewPager().setEnabled(true);
exit();
}
});
} else {
exit();
}
} else {
exit();
}
}
/**
* 关闭页面
*/
private void exit() {
finish();
overridePendingTransition(0, 0);
}
@Override
public void onBackPressed() {
isTransformOut = false;
transformOut();
}
@Override
public void finish() {
// BasePhotoFragment.listener=null;
super.finish();
}
/**
* pager的适配器
*/
private class PhotoPagerAdapter extends FragmentStatePagerAdapter {
PhotoPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return fragments.get(position);
}
@Override
public int getCount() {
return fragments == null ? 0 : fragments.size();
}
}
public void hindView() {
titleBar.setVisibility(View.GONE);
btnLL.setVisibility(View.GONE);
}
public void showView() {
titleBar.setVisibility(View.VISIBLE);
btnLL.setVisibility(View.VISIBLE);
}
public void transformOutAnim() {
ObjectAnimator animator1 = ObjectAnimator.ofFloat(titleBar, "alpha", 1.0f, 0.0f);
animator1.setDuration(200);
animator1.start();
ObjectAnimator animator2 = ObjectAnimator.ofFloat(btnLL, "alpha", 1.0f, 0.0f);
animator2.setDuration(200);
animator2.start();
}
}
package com.yidianling.consultant.preview
import android.animation.ObjectAnimator
import android.annotation.SuppressLint
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.text.TextUtils
import android.view.View
import android.view.WindowManager
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.ViewPager
import com.yidianling.consultant.R
import com.yidianling.consultant.preview.GPreviewBuilder.IndicatorType
import com.yidianling.consultant.preview.SmoothImageView.onTransformListener
import java.util.*
/**
* @author rainb
*/
class GPreviewActivity : AppCompatActivity() {
protected var isTransformOut = false
/*** 图片的地址 */
private var imgUrls: MutableList<IThumbViewInfo>? = null
/*** 当前图片的位置 */
protected var currentIndex = 0
/***指示器类型枚举 */
private var type: IndicatorType? = null
/***默认显示 */
private var isShow = true
/***
* 得到PhotoViewPager
* @return PhotoViewPager
*/
/*** 展示图片的viewPager */
var viewPager: PhotoViewPager? = null
private set
/*** 图片的展示的Fragment */
private var fragments: MutableList<BasePhotoFragment>? = ArrayList()
private var backIv: View? = null
private var btnLL: View? = null
private var titleBar: View? = null
private var selectPosition: TextView? = null
private var total: TextView? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
initData()
setContentView(R.layout.consultant_image_preview_photo)
initView()
initStatusBar()
}
/**
* 初始化状态栏位置
*/
private fun initStatusBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
window?.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
window?.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window?.statusBarColor = Color.WHITE
window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
}
}
private fun initView() {
viewPager = findViewById(R.id.viewPager)
//viewPager的适配器
val adapter = PhotoPagerAdapter(supportFragmentManager)
viewPager?.adapter = adapter
viewPager?.currentItem = currentIndex
backIv = findViewById(R.id.ivBack)
btnLL = findViewById(R.id.btnLL)
selectPosition = findViewById(R.id.select_position)
total = findViewById(R.id.total)
titleBar = findViewById(R.id.titleBar)
backIv?.setOnClickListener(View.OnClickListener {
transformOutAnim()
transformOut()
})
selectPosition?.setText((currentIndex + 1).toString() + "")
total?.setText(if (imgUrls == null) "0" else imgUrls!!.size.toString() + "")
viewPager?.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
override fun onPageScrolled(
position: Int,
positionOffset: Float,
positionOffsetPixels: Int
) {
}
override fun onPageSelected(position: Int) {
selectPosition?.setText((position + 1).toString() + "")
}
override fun onPageScrollStateChanged(state: Int) {}
})
// viewPager.setOffscreenPageLimit(3);
}
private fun initData() {
imgUrls = intent.getParcelableArrayListExtra("imagePaths")
currentIndex = intent.getIntExtra("position", -1)
type = intent.getSerializableExtra("type") as IndicatorType
isShow = intent.getBooleanExtra("isShow", true)
val isScale = intent.getBooleanExtra("isScale", false)
SmoothImageView.setIsScale(isScale)
initFragment(imgUrls, currentIndex, BasePhotoFragment::class.java)
}
private fun initFragment(
imgUrls: List<IThumbViewInfo>?,
currentIndex: Int,
className: Class<BasePhotoFragment>
) {
if (imgUrls != null) {
val size = imgUrls.size
for (i in 0 until size) {
fragments!!.add(
BasePhotoFragment.getInstance(
className, imgUrls[i],
currentIndex == i,
intent.getBooleanExtra("isSingleFling", false),
intent.getBooleanExtra("isDrag", false),
intent.getFloatExtra("sensitivity", 0.5f)
)
)
}
} else {
finish()
}
}
override fun onDestroy() {
ZoomMediaLoader.getInstance().loader.clearMemory(this)
if (viewPager != null) {
viewPager!!.adapter = null
viewPager!!.clearOnPageChangeListeners()
viewPager!!.removeAllViews()
viewPager = null
}
if (fragments != null) {
fragments!!.clear()
fragments = null
}
if (imgUrls != null) {
imgUrls!!.clear()
imgUrls = null
}
super.onDestroy()
}
/***
* 得到PhotoViewPager
* @return PhotoViewPager
*/
@JvmName("getViewPager1")
fun getViewPager(): PhotoViewPager? {
return viewPager
}
fun transformOut() {
if (isTransformOut) {
return
}
viewPager!!.isEnabled = false
isTransformOut = true
val currentItem = viewPager!!.currentItem
if (currentItem < imgUrls!!.size) {
if (TextUtils.isEmpty(imgUrls!![currentItem].videoUrl)) {
val fragment = fragments!![currentItem]
fragment.changeBg(Color.TRANSPARENT)
fragment.transformOut(onTransformListener {
getViewPager()?.setEnabled(true)
exit()
})
} else {
exit()
}
} else {
exit()
}
}
/**
* 关闭页面
*/
private fun exit() {
finish()
overridePendingTransition(0, 0)
}
override fun onBackPressed() {
isTransformOut = false
transformOutAnim()
transformOut()
}
override fun finish() {
// BasePhotoFragment.listener=null;
super.finish()
}
/**
* pager的适配器
*/
private inner class PhotoPagerAdapter internal constructor(fm: FragmentManager?) :
FragmentStatePagerAdapter(fm!!) {
override fun getItem(position: Int): Fragment {
return fragments!![position]
}
override fun getCount(): Int {
return if (fragments == null) 0 else fragments!!.size
}
}
fun hindView() {
titleBar!!.visibility = View.GONE
btnLL!!.visibility = View.GONE
}
fun showView() {
titleBar!!.visibility = View.VISIBLE
btnLL!!.visibility = View.VISIBLE
}
@SuppressLint("ObjectAnimatorBinding")
fun transformOutAnim() {
val animator1 = ObjectAnimator.ofFloat(titleBar, "alpha", 1.0f, 0.0f)
animator1.duration = 200
animator1.start()
val animator2 = ObjectAnimator.ofFloat(btnLL, "alpha", 1.0f, 0.0f)
animator2.duration = 200
animator2.start()
}
}
\ No newline at end of file
......@@ -18,7 +18,7 @@
android:layout_alignParentBottom="true"
android:layout_marginBottom="@dimen/platform_dp_40">
<Button
<TextView
android:id="@+id/chatBtn"
android:layout_width="148dp"
android:layout_height="47dp"
......@@ -26,11 +26,12 @@
android:layout_marginLeft="@dimen/platform_dp_20"
android:background="@drawable/consultant_bg_btn_chat"
android:text="立即私聊"
android:gravity="center"
android:textColor="@color/white"
android:textSize="17sp"
android:textStyle="bold" />
<Button
<TextView
android:id="@+id/bookingBtn"
android:layout_width="148dp"
android:layout_height="47dp"
......@@ -39,6 +40,7 @@
android:layout_marginRight="@dimen/platform_dp_20"
android:background="@drawable/consultant_bg_btn_book"
android:text="立即预约"
android:gravity="center"
android:textColor="@color/white"
android:textSize="17sp"
android:textStyle="bold" />
......
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="consultant_FilterTextViewStyle">
<item name="android:layout_height">40dp</item>
......@@ -38,11 +38,11 @@
<item name="android:backgroundDimEnabled">true</item>
</style>
<style name="consultant_Transparent" parent="@style/Base.Theme.AppCompat">
<item name="colorPrimary">@color/transparent</item>
<item name="colorPrimaryDark">@color/transparent</item>
<style name="consultant_Transparent" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="android:windowBackground">@color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsTranslucent">true</item>
</style>
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment