Skip to content

Commit

Permalink
add PhotoView.
Browse files Browse the repository at this point in the history
  • Loading branch information
YenalyLiew committed Jul 25, 2022
1 parent a2b28cb commit b67559b
Show file tree
Hide file tree
Showing 15 changed files with 291 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@

段子乐第三方**考核用**APP,项目本身全部采用 Kotlin 编写,标准使用 MVVM 架构,Material 3 最新视觉标准,适配 Android 12 动态颜色模式,最低支持 Android 5(API 21)。

## 使用库

1. `Flow`(切换线程,网络数据分发,ViewModel 缓存)
2. `Retrofit`(网络请求)
3. `Jetpack`(基本界面)
4. `Glide`(展示图像)
5. `Jzvd`(展示视频)
6. `PhotoView`(展示图像)
7. `Paging`(分页加载)
8. `SwipeRefreshLayout`(滑动刷新布局)

## 截图

- 主页一览
Expand Down
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ dependencies {
implementation("androidx.paging:paging-runtime:3.1.1")
implementation("androidx.paging:paging-runtime-ktx:3.1.1")
implementation("cn.jzvd:jiaozivideoplayer:7.7.0")
implementation("com.github.chrisbanes:PhotoView:2.3.0")

annotationProcessor("com.github.bumptech.glide:compiler:4.13.2")
testImplementation("junit:junit:4.13.2")
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@
tools:ignore="LockedOrientationActivity">


</activity>
<activity
android:name=".ui.activity.PicViewActivity"
android:configChanges="screenSize|orientation|keyboardHidden"
android:exported="true"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity">


</activity>
</application>

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/yenaly/duanzile/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ const val TO_TEXT_VIDEO_SPLIT_FRAGMENT = "TO_TEXT_VIDEO_SPLIT_FRAGMENT"
const val TO_DUANZI_ACTIVITY_ID = "TO_DUANZI_ACTIVITY_ID"

const val TO_FOLLOW_FAN_ACTIVITY_ID = "TO_FOLLOW_FAN_ACTIVITY_ID"

const val TO_PIC_VIEW_URLS = "TO_PIC_VIEW_URLS"
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.yenaly.duanzile.ui.activity

import android.os.Bundle
import android.widget.LinearLayout
import androidx.viewpager2.widget.ViewPager2
import com.yenaly.duanzile.R
import com.yenaly.duanzile.TO_PIC_VIEW_URLS
import com.yenaly.duanzile.databinding.ActivityPicViewBinding
import com.yenaly.duanzile.ui.adapter.PicViewVpAdapter
import com.yenaly.duanzile.ui.viewmodel.PicViewViewModel
import com.yenaly.yenaly_libs.base.YenalyActivity
import com.yenaly.yenaly_libs.utils.SystemStatusUtil
import com.yenaly.yenaly_libs.utils.intentExtra
import com.yenaly.yenaly_libs.utils.statusBarHeight

/**
* @ProjectName : BlViewer
* @Author : Yenaly Liew
* @Time : 2022/06/01 001 22:59
* @Description : Description...
*/
class PicViewActivity : YenalyActivity<ActivityPicViewBinding, PicViewViewModel>() {

private lateinit var picViewAdapter: PicViewVpAdapter
private val position = 0
private val urlsList by intentExtra(TO_PIC_VIEW_URLS, emptyList<String>())

override fun setUiStyle() {
SystemStatusUtil.fullScreen(window, true)
}

override fun initData(savedInstanceState: Bundle?) {

overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out)

picViewAdapter = PicViewVpAdapter(urlsList)

binding.pvaViewPager.adapter = picViewAdapter
binding.pvaViewPager.setCurrentItem(position, false)
val emptyLayoutParams =
LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, statusBarHeight)
binding.emptyView.layoutParams = emptyLayoutParams

val totalPage = urlsList.size
binding.picPosition.text = getString(R.string.pic_view_position, position + 1, totalPage)
binding.pvaViewPager.registerOnPageChangeCallback(
object : ViewPager2.OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
super.onPageSelected(position)
binding.picPosition.text =
getString(R.string.pic_view_position, position + 1, totalPage)
}
}
)

binding.btnBack.setOnClickListener {
finish()
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out)
}
}

override fun onBackPressed() {
super.onBackPressed()
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out)
}

override fun onNavigateUp(): Boolean {
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out)
return super.onNavigateUp()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.yenaly.duanzile.ftpDecrypt
import com.yenaly.duanzile.logic.model.DuanziListModel
import com.yenaly.duanzile.ui.activity.DuanziActivity
import com.yenaly.duanzile.ui.activity.MainActivity
import com.yenaly.duanzile.ui.activity.PicViewActivity
import com.yenaly.duanzile.ui.activity.UserActivity
import com.yenaly.yenaly_libs.utils.activity
import com.yenaly.yenaly_libs.utils.shareText
Expand Down Expand Up @@ -229,6 +230,13 @@ class DuanziRvAdapter :
)
}
}
viewHolder.binding.image.setOnClickListener {
val position = viewHolder.bindingAdapterPosition
val item = getItem(position)
item?.let {
startActivity<PicViewActivity>(TO_PIC_VIEW_URLS to listOf(item.joke.imageURL.ftpDecrypt()))
}
}
}

return viewHolder
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.yenaly.duanzile.ui.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.yenaly.duanzile.R
import com.yenaly.duanzile.databinding.ItemPicViewBinding
import com.yenaly.yenaly_libs.utils.SystemStatusUtil
import com.yenaly.yenaly_libs.utils.activity
import com.yenaly.yenaly_libs.utils.setSystemBarIconLightMode

/**
* @project Duanzile
* @author Yenaly Liew
* @time 2022/07/25 025 18:32
*/
class PicViewVpAdapter(private val data: List<String>) :
RecyclerView.Adapter<PicViewVpAdapter.ViewHolder>() {

private var recyclerView: RecyclerView? = null

private val context: Context
get() {
checkNotNull(recyclerView) {
"You have not attached adapter to RecyclerView!"
}
return recyclerView!!.context
}

override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
super.onAttachedToRecyclerView(recyclerView)
this.recyclerView = recyclerView
}

inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val binding = ItemPicViewBinding.bind(view)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view =
LayoutInflater.from(parent.context).inflate(R.layout.item_pic_view, parent, false)
val viewHolder = ViewHolder(view)
val activity = context.activity ?: throw NullPointerException("???")
val fullToolbar: View = activity.findViewById(R.id.pva_full_toolbar)
viewHolder.binding.photoView.setOnPhotoTapListener { _, _, _ ->
fullToolbar.isInvisible = fullToolbar.isVisible
SystemStatusUtil.fullScreen(activity.window, true, true)
activity.window.setSystemBarIconLightMode(fullToolbar.isInvisible)
}
return viewHolder
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
Glide.with(context).load(data[position]).into(holder.binding.photoView)
}

override fun getItemCount(): Int {
return data.size
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.yenaly.duanzile.R
import com.yenaly.duanzile.TO_DUANZI_ACTIVITY_ID
import com.yenaly.duanzile.*
import com.yenaly.duanzile.databinding.ItemDuanziSimplifiedBinding
import com.yenaly.duanzile.ftpDecrypt
import com.yenaly.duanzile.isLogin
import com.yenaly.duanzile.logic.model.DuanziListModel
import com.yenaly.duanzile.ui.activity.DuanziActivity
import com.yenaly.duanzile.ui.activity.PicViewActivity
import com.yenaly.duanzile.ui.activity.UserActivity
import com.yenaly.yenaly_libs.utils.activity
import com.yenaly.yenaly_libs.utils.shareText
Expand Down Expand Up @@ -193,6 +192,13 @@ class SimpleDuanziRvAdapter :
)
}
}
viewHolder.binding.image.setOnClickListener {
val position = viewHolder.bindingAdapterPosition
val item = getItem(position)
item?.let {
startActivity<PicViewActivity>(TO_PIC_VIEW_URLS to listOf(item.joke.imageURL.ftpDecrypt()))
}
}
}

return viewHolder
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.yenaly.duanzile.ui.viewmodel

import android.app.Application
import com.yenaly.yenaly_libs.base.YenalyViewModel

/**
* @ProjectName : BlViewer
* @Author : Yenaly Liew
* @Time : 2022/06/01 001 23:03
* @Description : Description...
*/
class PicViewViewModel(application: Application) : YenalyViewModel(application) {

}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_baseline_arrow_back_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="?attr/colorControlNormal" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"/>
</vector>
69 changes: 69 additions & 0 deletions app/src/main/res/layout/activity_pic_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

</data>

<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:background="@color/black">

<androidx.viewpager2.widget.ViewPager2
android:id="@+id/pva_view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<LinearLayout
android:id="@+id/pva_full_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="@color/pic_view_action_bar_color"
android:orientation="vertical">

<View
android:id="@+id/empty_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/pic_view_action_bar_color" />

<androidx.appcompat.widget.Toolbar
android:id="@+id/pva_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:animateLayoutChanges="true"
android:background="@color/pic_view_action_bar_color">

<ImageButton
android:id="@+id/btn_back"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="16dp"
android:background="@drawable/ic_baseline_arrow_back_24"
android:contentDescription="@null"
android:theme="@style/Theme.Material3.Dark" />

<TextView
android:id="@+id/pic_position"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:ellipsize="end"
android:singleLine="true"
android:textAppearance="?attr/textAppearanceTitleLarge"
android:textColor="@color/white"
tools:text="1 of 2" />

</androidx.appcompat.widget.Toolbar>

</LinearLayout>


</androidx.coordinatorlayout.widget.CoordinatorLayout>

</layout>
20 changes: 20 additions & 0 deletions app/src/main/res/layout/item_pic_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

<data>

</data>

<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/photo_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

</layout>
3 changes: 3 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
<color name="white">#FFFFFFFF</color>

<color name="background_color">#FFFBFE</color>

<color name="pic_view_action_bar_color">#66000000</color>
<color name="pic_view_title_mask_color">#66F5F5F5</color>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
<string name="edit_info">编辑资料</string>
<string name="dm">私信</string>
<string name="like_unlike">赞 · 踩</string>
<string name="pic_view_position">%d of %d</string>
<string name="search">搜索</string>
</resources>

0 comments on commit b67559b

Please sign in to comment.