Skip to content

Commit

Permalink
refactor: downgrade java 11
Browse files Browse the repository at this point in the history
  • Loading branch information
SherlockGougou committed Jan 13, 2025
1 parent 1cc07f7 commit 009a2e0
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 82 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ https://github.com/user-attachments/assets/070caa63-8e9f-4b11-9240-4cb56440d3c2
}
```
#### Step 2. 在你app的build.gradle中添加依赖:
当前最新版本为:```androidx-8.1.1```
当前最新版本为:```androidx-8.1.2```
```
dependencies {
// 本框架
implementation 'com.github.SherlockGougou:BigImageViewPager:androidx-8.1.1'
implementation 'com.github.SherlockGougou:BigImageViewPager:androidx-8.1.2'
// glide
implementation 'com.github.bumptech.glide:glide:4.16.0'
Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ object ImageLoader {
val safeKey = safeKeyGenerator.getSafeKey(dataCacheKey)
SLog.d(TAG, "safeKey = $safeKey")
val file = File(context.cacheDir, DiskCache.Factory.DEFAULT_DISK_CACHE_DIR)
val diskLruCache =
DiskLruCache.open(file, 1, 1, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE.toLong())
val diskLruCache = DiskLruCache.open(file, 1, 1, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE.toLong())
val value = diskLruCache[safeKey]
return value?.getFile(0)
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.fragment.app.Fragment
import androidx.media3.common.MediaItem
import androidx.media3.common.Player
import androidx.media3.common.VideoSize
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.ui.PlayerView
import cc.shinichi.library.ImagePreview
Expand Down Expand Up @@ -123,6 +124,7 @@ class ImagePreviewFragment : Fragment() {
return view
}

@UnstableApi
private fun initData() {
SLog.d(TAG, "initData: position = $position")
val type = imageInfo.type
Expand All @@ -148,9 +150,17 @@ class ImagePreviewFragment : Fragment() {
dragCloseView.setOnAlphaChangeListener(object : DragCloseView.onAlphaChangedListener {
override fun onTranslationYChanged(event: MotionEvent?, translationY: Float) {
if (translationY > 0) {
ImagePreview.instance.onPageDragListener?.onDrag(imagePreviewActivity, imagePreviewActivity.parentView, event, translationY)
ImagePreview.instance.onPageDragListener?.onDrag(
imagePreviewActivity,
imagePreviewActivity.parentView,
event,
translationY
)
} else {
ImagePreview.instance.onPageDragListener?.onDragEnd(imagePreviewActivity, imagePreviewActivity.parentView)
ImagePreview.instance.onPageDragListener?.onDragEnd(
imagePreviewActivity,
imagePreviewActivity.parentView
)
}
val yAbs = abs(translationY)
val percent = yAbs / phoneHei
Expand Down Expand Up @@ -309,6 +319,7 @@ class ImagePreviewFragment : Fragment() {
}
}

@UnstableApi
private fun initVideoType() {
// 视频类型,隐藏图片
imageStatic.visibility = View.GONE
Expand All @@ -325,7 +336,10 @@ class ImagePreviewFragment : Fragment() {
exoPlayer?.addListener(object : Player.Listener {
override fun onVideoSizeChanged(videoSize: VideoSize) {
super.onVideoSizeChanged(videoSize)
SLog.d(TAG, "onVideoSizeChanged: videoSize = ${videoSize.width} * ${videoSize.height}")
SLog.d(
TAG,
"onVideoSizeChanged: videoSize = ${videoSize.width} * ${videoSize.height}"
)
}

override fun onIsPlayingChanged(isPlaying: Boolean) {
Expand All @@ -344,6 +358,7 @@ class ImagePreviewFragment : Fragment() {
if (playbackState == Player.STATE_READY) {
// 底部控制器处理
setProgress(exoPlayer!!)
videoView.hideController()
} else if (playbackState == Player.STATE_ENDED) {
// 播放结束
exoPlayer?.pause()
Expand All @@ -359,6 +374,7 @@ class ImagePreviewFragment : Fragment() {
})
}
videoView.player = exoPlayer

val mediaItem = MediaItem.fromUri(imageInfo.originUrl)
exoPlayer?.setMediaItem(mediaItem)
exoPlayer?.prepare()
Expand Down Expand Up @@ -536,7 +552,9 @@ class ImagePreviewFragment : Fragment() {
0,
0,
0,
UIUtil.dp2px(imagePreviewActivity, 70f) + PhoneUtil.getNavBarHeight(imagePreviewActivity)
UIUtil.dp2px(imagePreviewActivity, 70f) + PhoneUtil.getNavBarHeight(
imagePreviewActivity
)
)
}
llControllerContainer.layoutParams = layoutParams
Expand Down Expand Up @@ -622,7 +640,8 @@ class ImagePreviewFragment : Fragment() {
// glide加载失败,使用http下载后再次加载
Thread {
val fileFullName = System.currentTimeMillis().toString()
val saveDir = getAvailableCacheDir(imagePreviewActivity)?.absolutePath + File.separator + "image/"
val saveDir =
getAvailableCacheDir(imagePreviewActivity)?.absolutePath + File.separator + "image/"
val downloadFile = downloadFile(url, fileFullName, saveDir)
Handler(Looper.getMainLooper()).post {
if (downloadFile != null && downloadFile.exists() && downloadFile.length() > 0) {
Expand Down Expand Up @@ -719,7 +738,8 @@ class ImagePreviewFragment : Fragment() {
val isWideImage = ImageUtil.isWideImage(imagePath)
if (isLongImage) {
// 长图,高/宽>=3
imageStatic.maxScale = ImageUtil.getLongImageMaxZoomScale(imagePreviewActivity, imagePath)
imageStatic.maxScale =
ImageUtil.getLongImageMaxZoomScale(imagePreviewActivity, imagePath)
imageStatic.setDoubleTapZoomScale(
ImageUtil.getLongImageDoubleZoomScale(
imagePreviewActivity,
Expand All @@ -742,7 +762,8 @@ class ImagePreviewFragment : Fragment() {
}
} else if (isWideImage) {
// 宽图,宽/高>=3
imageStatic.maxScale = ImageUtil.getWideImageMaxZoomScale(imagePreviewActivity, imagePath)
imageStatic.maxScale =
ImageUtil.getWideImageMaxZoomScale(imagePreviewActivity, imagePath)
imageStatic.setDoubleTapZoomScale(
ImageUtil.getWideImageDoubleScale(
imagePreviewActivity,
Expand All @@ -751,7 +772,8 @@ class ImagePreviewFragment : Fragment() {
)
} else {
// 普通图片,其他
imageStatic.maxScale = ImageUtil.getStandardImageMaxZoomScale(imagePreviewActivity, imagePath)
imageStatic.maxScale =
ImageUtil.getStandardImageMaxZoomScale(imagePreviewActivity, imagePath)
imageStatic.setDoubleTapZoomScale(
ImageUtil.getStandardImageDoubleScale(
imagePreviewActivity,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions library/src/main/res/layout/sh_item_photoview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:show_timeout="1500"
app:controller_layout_id="@layout/sh_media_controller" />

</cc.shinichi.library.view.helper.DragCloseView>
Expand Down
10 changes: 5 additions & 5 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ android {
applicationId "cc.shinichi.bigimageviewpager"
minSdkVersion 24
targetSdkVersion 34
versionCode 811
versionName "androidx-8.1.1"
versionCode 812
versionName "androidx-8.1.2"
signingConfig signingConfigs.debug
multiDexEnabled true
}
Expand All @@ -35,8 +35,8 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
sourceSets {
main {
Expand Down Expand Up @@ -79,6 +79,6 @@ dependencies {
implementation "androidx.media3:media3-ui:1.4.1"

// library
// implementation 'com.github.SherlockGougou:BigImageViewPager:androidx-8.1.1'
// implementation 'com.github.SherlockGougou:BigImageViewPager:androidx-8.1.2'
implementation project(':library')
}
133 changes: 70 additions & 63 deletions sample/src/main/res/layout/custom_layout_preview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,77 +68,84 @@

</androidx.constraintlayout.widget.ConstraintLayout>

<TextView
android:id="@+id/tv_indicator"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_marginTop="20dp"
android:background="@drawable/shape_indicator_bg"
android:gravity="center"
android:includeFontPadding="false"
android:text="1 / 9"
android:textColor="#ffffff"
android:textSize="15sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/consBottomController"
android:id="@+id/consControllerOverlay"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent">
android:layout_height="match_parent">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/imgCloseButton"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="10dp"
android:padding="8dp"
android:scaleType="centerInside"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_action_close" />

<FrameLayout
android:id="@+id/fm_image_show_origin_container"
<TextView
android:id="@+id/tv_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_height="20dp"
android:layout_marginTop="20dp"
android:background="@drawable/shape_indicator_bg"
android:gravity="center"
android:includeFontPadding="false"
android:text="1 / 9"
android:textColor="#ffffff"
android:textSize="15sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btn_show_origin"
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/consBottomController"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/imgCloseButton"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="10dp"
android:padding="8dp"
android:scaleType="centerInside"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_action_close" />

<FrameLayout
android:id="@+id/fm_image_show_origin_container"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:background="@drawable/gray_square_circle_bg_white_stroke"
android:gravity="center"
android:includeFontPadding="false"
android:paddingHorizontal="10dp"
android:text="@string/btn_original"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="12sp" />

</FrameLayout>

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/img_download"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="10dp"
android:padding="8dp"
android:scaleType="centerInside"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/icon_download_new" />
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<Button
android:id="@+id/btn_show_origin"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:background="@drawable/gray_square_circle_bg_white_stroke"
android:gravity="center"
android:includeFontPadding="false"
android:paddingHorizontal="10dp"
android:text="@string/btn_original"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="12sp" />

</FrameLayout>

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/img_download"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="10dp"
android:padding="8dp"
android:scaleType="centerInside"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/icon_download_new" />

</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

Expand Down

0 comments on commit 009a2e0

Please sign in to comment.