Skip to content

Commit

Permalink
androidx.core:core-ktx 和 kotlin-jdk7包都升级
Browse files Browse the repository at this point in the history
  • Loading branch information
aaatttcccc committed Feb 25, 2022
1 parent 8c23b2d commit d6497de
Show file tree
Hide file tree
Showing 18 changed files with 410 additions and 404 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/com/zhongjh/cameraapp/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// 某些手机拍摄没有自带宽高,那么我们可以自己获取
if (localFile.getWidth() == 0 && localFile.isVideo()) {
MediaExtraInfo mediaExtraInfo = MediaUtils.getVideoSize(getApplication(), localFile.getPath());
localFile.setWidth(mediaExtraInfo.width);
localFile.setHeight(mediaExtraInfo.height);
localFile.setDuration(mediaExtraInfo.duration);
localFile.setWidth(mediaExtraInfo.getWidth());
localFile.setHeight(mediaExtraInfo.getHeight());
localFile.setDuration(mediaExtraInfo.getDuration());
}
Log.i(TAG, "onResult 宽高: " + localFile.getWidth() + "x" + localFile.getHeight());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,9 @@ public void onResult(List<LocalFile> result) {
// 某些手机拍摄没有自带宽高,那么我们可以自己获取
if (localFile.getWidth() == 0 && localFile.isVideo()) {
MediaExtraInfo mediaExtraInfo = MediaUtils.getVideoSize(getApplication(), localFile.getPath());
localFile.setWidth(mediaExtraInfo.width);
localFile.setHeight(mediaExtraInfo.height);
localFile.setDuration(mediaExtraInfo.duration);
localFile.setWidth(mediaExtraInfo.getWidth());
localFile.setHeight(mediaExtraInfo.getHeight());
localFile.setDuration(mediaExtraInfo.getDuration());
}
Log.d(TAG, "onResult 宽高: " + localFile.getWidth() + "x" + localFile.getHeight());
Log.d(TAG, UriUtils.uriToFile(getApplicationContext(), localFile.getUri()).getPath());
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.3.72'
ext.kotlin_version = '1.5.20'
repositories {
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
Expand Down Expand Up @@ -50,4 +50,6 @@ ext {
gsonVersion = '2.6.2'

butterknifeVersion = '8.4.0'

ktx_version = '1.6.0'
}
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ android {
dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.core:core-ktx:1.5.0'
implementation "androidx.core:core-ktx:$rootProject.ext.ktx_version"
implementation "androidx.appcompat:appcompat:$rootProject.ext.appcompatSdkVersion"
implementation "com.google.android.material:material:$rootProject.ext.androidMaterialSdkVersion"
implementation 'androidx.exifinterface:exifinterface:1.3.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ open class LocalFile : Parcelable {
} else if (isVideo()) {
// 有些手机视频拍照没有宽高的
if (localFile.width == 0) {
val mediaExtraInfo = MediaUtils.getVideoSize(context, this.path)
val mediaExtraInfo = MediaUtils.getVideoSize(context, compressionFile.absolutePath)
height = mediaExtraInfo.height
width = mediaExtraInfo.width
duration = mediaExtraInfo.duration
Expand Down
76 changes: 76 additions & 0 deletions common/src/main/java/com/zhongjh/common/entity/MultiMedia.kt
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,82 @@ open class MultiMedia : LocalFile, Parcelable {
cursor.getInt(cursor.getColumnIndex(MediaColumns.WIDTH)),
cursor.getInt(cursor.getColumnIndex(MediaColumns.HEIGHT)))
}

/**
* 获取相同数据的索引
*
* @param items 数据列表
* @param item 当前数据
* @return 索引
*/
@JvmStatic
fun checkedNumOf(items: List<MultiMedia>, item: MultiMedia): Int {
var index = -1
if (item.uri != null) {
for (i in items.indices) {
if (items[i].uri != null && items[i].uri == item.uri
&& items[i].multiMediaId == item.multiMediaId
) {
index = i
break
}
}
} else if (item.drawableId != -1) {
for (i in items.indices) {
if (items[i].drawableId != -1 && items[i].drawableId == item.drawableId && items[i].multiMediaId == item.multiMediaId) {
index = i
break
}
}
} else if (item.url != null) {
for (i in items.indices) {
if (items[i].url != null && items[i].url == item.url
&& items[i].multiMediaId == item.multiMediaId
) {
index = i
break
}
}
}
// 如果选择的为 -1 就是未选状态,否则选择基础数量+1
return if (index == -1) Int.MIN_VALUE else index + 1
}

/**
* 获取相同数据的對象
*
* @param items 数据列表
* @param item 当前数据
* @return 索引
*/
@JvmStatic
fun checkedMultiMediaOf(items: List<MultiMedia>, item: MultiMedia): MultiMedia? {
var multiMedia: MultiMedia? = null
if (item.uri != null) {
for (i in items.indices) {
if (items[i].uri == item.uri) {
multiMedia = items[i]
break
}
}
} else if (item.drawableId != -1) {
for (i in items.indices) {
if (items[i].drawableId == item.drawableId) {
multiMedia = items[i]
break
}
}
} else if (item.url != null) {
for (i in items.indices) {
if (items[i].url == item.url) {
multiMedia = items[i]
break
}
}
}
return multiMedia
}

}


Expand Down
2 changes: 1 addition & 1 deletion imageeditKotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ android {
dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.5.0'
implementation "androidx.core:core-ktx:$rootProject.ext.ktx_version"
implementation "androidx.appcompat:appcompat:$rootProject.ext.appcompatSdkVersion"
implementation "com.google.android.material:material:$rootProject.ext.androidMaterialSdkVersion"
implementation "androidx.constraintlayout:constraintlayout:$rootProject.ext.constraintlayoutSdkVersion"
Expand Down
10 changes: 9 additions & 1 deletion multilibrary/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
apply plugin: 'com.android.library'
plugins {
id 'com.android.library'
id 'kotlin-android'
}
//============================== JitPack 上传插件配置 =====================
apply plugin: 'com.github.dcendents.android-maven'
group='com.github.zhongjhATC'
Expand Down Expand Up @@ -27,10 +30,15 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "androidx.core:core-ktx:$rootProject.ext.ktx_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

implementation "androidx.recyclerview:recyclerview:$rootProject.ext.recyclerviewSdkVersion"
implementation "androidx.appcompat:appcompat:$rootProject.ext.appcompatSdkVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.zhongjh.albumcamerarecorder.album.entity.SelectedCountMessage;
import com.zhongjh.albumcamerarecorder.album.utils.PhotoMetadataUtils;
import com.zhongjh.albumcamerarecorder.settings.AlbumSpec;
import com.zhongjh.albumcamerarecorder.utils.MultiMediaUtils;
import com.zhongjh.albumcamerarecorder.utils.SelectableUtils;
import com.zhongjh.common.entity.IncapableCause;
import com.zhongjh.common.entity.LocalFile;
Expand Down Expand Up @@ -168,7 +167,7 @@ public boolean add(MultiMedia item) {
*/
public boolean remove(MultiMedia item) {
boolean removed;
MultiMedia multiMedia = MultiMediaUtils.checkedMultiMediaOf(mItems, item);
MultiMedia multiMedia = MultiMedia.checkedMultiMediaOf(mItems, item);
removed = mItems.remove(multiMedia);
if (removed) {
if (mItems.size() == 0) {
Expand Down Expand Up @@ -421,7 +420,7 @@ public int count() {
* @return 选择的索引,最终返回的选择了第几个
*/
public int checkedNumOf(MultiMedia item) {
return MultiMediaUtils.checkedNumOf(new ArrayList<>(mItems), item);
return MultiMedia.checkedNumOf(new ArrayList<>(mItems), item);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ public void onFail(Throwable t) {
private void confirm(File newFile) {
Intent intent = new Intent();
MediaExtraInfo mediaExtraInfo = MediaUtils.getVideoSize(getApplicationContext(), newFile.getPath());
mLocalFile.setWidth(mediaExtraInfo.width);
mLocalFile.setHeight(mediaExtraInfo.height);
mLocalFile.setWidth(mediaExtraInfo.getWidth());
mLocalFile.setHeight(mediaExtraInfo.getHeight());
Uri uri = MediaStoreUtils.displayToGallery(getApplicationContext(), newFile, TYPE_VIDEO, mLocalFile.getDuration(),
mLocalFile.getWidth(), mLocalFile.getHeight(),
mVideoMediaStoreCompat.getSaveStrategy().getDirectory(), mVideoMediaStoreCompat);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.zhongjh.albumcamerarecorder.album.model.SelectedItemCollection;
import com.zhongjh.albumcamerarecorder.preview.adapter.PreviewPagerAdapter;
import com.zhongjh.albumcamerarecorder.settings.GlobalSpec;
import com.zhongjh.albumcamerarecorder.utils.MultiMediaUtils;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -100,7 +99,7 @@ private void initItems(List<MultiMedia> items) {
mIsAlreadySetPosition = true;
MultiMedia selected = getIntent().getParcelableExtra(EXTRA_ITEM);
// -1是爲了拿到索引
int selectedIndex = MultiMediaUtils.checkedNumOf(items, selected) - 1;
int selectedIndex = MultiMedia.checkedNumOf(items, selected) - 1;
mViewHolder.pager.setCurrentItem(selectedIndex, false);
mPreviousPos = selectedIndex;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.zhongjh.albumcamerarecorder.utils

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentManager
import com.zhongjh.albumcamerarecorder.listener.HandleBackInterface

/**
* 处理fragment的回退事件
* @author zhongjh
*/
object HandleBackUtil {

@JvmStatic
fun handleBackPress(fragment: Fragment): Boolean {
return handleBackPress(fragment.childFragmentManager)
}

@JvmStatic
fun handleBackPress(fragmentActivity: FragmentActivity): Boolean {
return handleBackPress(fragmentActivity.supportFragmentManager)
}

/**
* 将back事件分发给 FragmentManager 中管理的子Fragment,如果该 FragmentManager 中的所有Fragment都
* 没有处理back事件,则尝试 FragmentManager.popBackStack()
*
* @return 如果处理了back键则返回 **true**
* @see .handleBackPress
* @see .handleBackPress
*/
private fun handleBackPress(fragmentManager: FragmentManager): Boolean {
val fragments = fragmentManager.fragments
for (i in fragments.indices.reversed()) {
val child = fragments[i]
if (isFragmentBackHandled(child)) {
return true
}
}
if (fragmentManager.backStackEntryCount > 0) {
fragmentManager.popBackStack()
return true
}
return false
}

/**
* 判断Fragment是否处理了Back键
*
* @return 如果处理了back键则返回 **true**
*/
private fun isFragmentBackHandled(fragment: Fragment): Boolean {
return (fragment.isVisible
&& fragment.userVisibleHint // for ViewPager
&& fragment is HandleBackInterface
&& (fragment as HandleBackInterface).onBackPressed())
}
}
Loading

0 comments on commit d6497de

Please sign in to comment.