fix #440, upgrade to Android Studio 3

This commit is contained in:
tibbi 2017-11-07 17:11:20 +01:00
parent 932fc628a3
commit add3760ed2
7 changed files with 57 additions and 60 deletions

View file

@ -3,13 +3,13 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android-extensions'
android { android {
compileSdkVersion 26 compileSdkVersion 27
buildToolsVersion "26.0.2" buildToolsVersion "27.0.1"
defaultConfig { defaultConfig {
applicationId "com.simplemobiletools.gallery" applicationId "com.simplemobiletools.gallery"
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 26 targetSdkVersion 27
versionCode 142 versionCode 142
versionName "2.17.4" versionName "2.17.4"
} }
@ -36,19 +36,22 @@ android {
} }
} }
ext {
leakCanaryVersion = '1.5.4'
}
dependencies { dependencies {
compile 'com.simplemobiletools:commons:2.36.1' compile 'com.simplemobiletools:commons:2.37.1'
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0'
compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0'
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'
compile 'com.google.code.gson:gson:2.8.0' compile 'com.google.code.gson:gson:2.8.2'
compile 'it.sephiroth.android.exif:library:1.0.1' compile 'it.sephiroth.android.exif:library:1.0.1'
compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.8' compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.8'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1' debugCompile "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1' releaseCompile "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion"
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
} }
buildscript { buildscript {

View file

@ -34,15 +34,15 @@ class MyPagerAdapter(val activity: ViewPagerActivity, fm: FragmentManager, val m
return fragment return fragment
} }
override fun getItemPosition(item: Any?) = PagerAdapter.POSITION_NONE override fun getItemPosition(item: Any) = PagerAdapter.POSITION_NONE
override fun instantiateItem(container: ViewGroup?, position: Int): Any { override fun instantiateItem(container: ViewGroup, position: Int): Any {
val fragment = super.instantiateItem(container, position) as ViewPagerFragment val fragment = super.instantiateItem(container, position) as ViewPagerFragment
mFragments.put(position, fragment) mFragments.put(position, fragment)
return fragment return fragment
} }
override fun destroyItem(container: ViewGroup?, position: Int, any: Any?) { override fun destroyItem(container: ViewGroup, position: Int, any: Any) {
mFragments.remove(position) mFragments.remove(position)
super.destroyItem(container, position, any) super.destroyItem(container, position, any)
} }

View file

@ -53,31 +53,31 @@ class PhotoFragment : ViewPagerFragment() {
isFragmentVisible = true isFragmentVisible = true
} }
medium = arguments.getSerializable(MEDIUM) as Medium medium = arguments!!.getSerializable(MEDIUM) as Medium
if (medium.path.startsWith("content://")) { if (medium.path.startsWith("content://")) {
val originalPath = medium.path val originalPath = medium.path
medium.path = context.getRealPathFromURI(Uri.parse(originalPath)) ?: medium.path medium.path = context!!.getRealPathFromURI(Uri.parse(originalPath)) ?: medium.path
if (medium.path.isEmpty()) { if (medium.path.isEmpty()) {
var out: FileOutputStream? = null var out: FileOutputStream? = null
try { try {
var inputStream = context.contentResolver.openInputStream(Uri.parse(originalPath)) var inputStream = context!!.contentResolver.openInputStream(Uri.parse(originalPath))
val exif = ExifInterface() val exif = ExifInterface()
exif.readExif(inputStream, ExifInterface.Options.OPTION_ALL) exif.readExif(inputStream, ExifInterface.Options.OPTION_ALL)
val tag = exif.getTag(ExifInterface.TAG_ORIENTATION) val tag = exif.getTag(ExifInterface.TAG_ORIENTATION)
val orientation = tag?.getValueAsInt(-1) ?: -1 val orientation = tag?.getValueAsInt(-1) ?: -1
inputStream = context.contentResolver.openInputStream(Uri.parse(originalPath)) inputStream = context!!.contentResolver.openInputStream(Uri.parse(originalPath))
val original = BitmapFactory.decodeStream(inputStream) val original = BitmapFactory.decodeStream(inputStream)
val rotated = rotateViaMatrix(original, orientation) val rotated = rotateViaMatrix(original, orientation)
exif.setTagValue(ExifInterface.TAG_ORIENTATION, 1) exif.setTagValue(ExifInterface.TAG_ORIENTATION, 1)
exif.removeCompressedThumbnail() exif.removeCompressedThumbnail()
val file = File(context.externalCacheDir, Uri.parse(originalPath).lastPathSegment) val file = File(context!!.externalCacheDir, Uri.parse(originalPath).lastPathSegment)
out = FileOutputStream(file) out = FileOutputStream(file)
rotated.compress(Bitmap.CompressFormat.JPEG, 100, out) rotated.compress(Bitmap.CompressFormat.JPEG, 100, out)
medium.path = file.absolutePath medium.path = file.absolutePath
} catch (e: Exception) { } catch (e: Exception) {
activity.toast(R.string.unknown_error_occurred) activity!!.toast(R.string.unknown_error_occurred)
return view return view
} finally { } finally {
out?.close() out?.close()
@ -97,13 +97,13 @@ class PhotoFragment : ViewPagerFragment() {
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
storedShowExtendedDetails = context.config.showExtendedDetails storedShowExtendedDetails = context!!.config.showExtendedDetails
storedExtendedDetails = context.config.extendedDetails storedExtendedDetails = context!!.config.extendedDetails
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
if (wasInit && (context.config.showExtendedDetails != storedShowExtendedDetails || context.config.extendedDetails != storedExtendedDetails)) { if (wasInit && (context!!.config.showExtendedDetails != storedShowExtendedDetails || context!!.config.extendedDetails != storedExtendedDetails)) {
checkExtendedDetails() checkExtendedDetails()
} }
} }
@ -169,7 +169,7 @@ class PhotoFragment : ViewPagerFragment() {
private fun loadGif() { private fun loadGif() {
try { try {
gifDrawable = if (medium.path.startsWith("content://") || medium.path.startsWith("file://")) { gifDrawable = if (medium.path.startsWith("content://") || medium.path.startsWith("file://")) {
GifDrawable(context.contentResolver, Uri.parse(medium.path)) GifDrawable(context!!.contentResolver, Uri.parse(medium.path))
} else { } else {
GifDrawable(medium.path) GifDrawable(medium.path)
} }
@ -212,7 +212,7 @@ class PhotoFragment : ViewPagerFragment() {
} else { } else {
val options = RequestOptions() val options = RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.NONE) .diskCacheStrategy(DiskCacheStrategy.NONE)
.transform(GlideRotateTransformation(context, degrees)) .transform(GlideRotateTransformation(context!!, degrees))
Glide.with(this) Glide.with(this)
.asBitmap() .asBitmap()
@ -271,9 +271,9 @@ class PhotoFragment : ViewPagerFragment() {
if (context == null) if (context == null)
return 2f return 2f
return if (context.portrait && bitmapAspectRatio <= 1f) { return if (context!!.portrait && bitmapAspectRatio <= 1f) {
ViewPagerActivity.screenHeight / height.toFloat() ViewPagerActivity.screenHeight / height.toFloat()
} else if (!context.portrait && bitmapAspectRatio >= 1f) { } else if (!context!!.portrait && bitmapAspectRatio >= 1f) {
ViewPagerActivity.screenWidth / width.toFloat() ViewPagerActivity.screenWidth / width.toFloat()
} else { } else {
2f 2f
@ -286,7 +286,7 @@ class PhotoFragment : ViewPagerFragment() {
} }
private fun checkExtendedDetails() { private fun checkExtendedDetails() {
if (context.config.showExtendedDetails) { if (context!!.config.showExtendedDetails) {
view.photo_details.apply { view.photo_details.apply {
text = getMediumExtendedDetails(medium) text = getMediumExtendedDetails(medium)
setTextColor(context.config.textColor) setTextColor(context.config.textColor)
@ -305,8 +305,7 @@ class PhotoFragment : ViewPagerFragment() {
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
context.isKitkatPlus() if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && !activity!!.isDestroyed) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && !activity.isDestroyed) {
Glide.with(context).clear(view.gif_view) Glide.with(context).clear(view.gif_view)
} }
} }
@ -331,9 +330,4 @@ class PhotoFragment : ViewPagerFragment() {
} }
} }
} }
fun refreshBitmap() {
view.subsampling_view.beGone()
loadBitmap()
}
} }

View file

@ -65,7 +65,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
mView = inflater.inflate(R.layout.pager_video_item, container, false) mView = inflater.inflate(R.layout.pager_video_item, container, false)
mTimeHolder = mView.video_time_holder mTimeHolder = mView.video_time_holder
medium = arguments.getSerializable(MEDIUM) as Medium medium = arguments!!.getSerializable(MEDIUM) as Medium
// setMenuVisibility is not called at VideoActivity (third party intent) // setMenuVisibility is not called at VideoActivity (third party intent)
if (!mIsFragmentVisible && activity is VideoActivity) { if (!mIsFragmentVisible && activity is VideoActivity) {
@ -77,7 +77,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
mCurrTime = savedInstanceState.getInt(PROGRESS) mCurrTime = savedInstanceState.getInt(PROGRESS)
} }
mIsFullscreen = activity.window.decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_FULLSCREEN == View.SYSTEM_UI_FLAG_FULLSCREEN mIsFullscreen = activity!!.window.decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_FULLSCREEN == View.SYSTEM_UI_FLAG_FULLSCREEN
checkFullscreen() checkFullscreen()
wasInit = true wasInit = true
@ -86,11 +86,11 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
activity.updateTextColors(mView.video_holder) activity!!.updateTextColors(mView.video_holder)
mView.video_volume_controller.beVisibleIf(context.config.allowVideoGestures) mView.video_volume_controller.beVisibleIf(context!!.config.allowVideoGestures)
mView.video_brightness_controller.beVisibleIf(context.config.allowVideoGestures) mView.video_brightness_controller.beVisibleIf(context!!.config.allowVideoGestures)
if (context.config.showExtendedDetails != mStoredShowExtendedDetails || context.config.extendedDetails != mStoredExtendedDetails) { if (context!!.config.showExtendedDetails != mStoredShowExtendedDetails || context!!.config.extendedDetails != mStoredExtendedDetails) {
checkExtendedDetails() checkExtendedDetails()
} }
} }
@ -98,8 +98,8 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
pauseVideo() pauseVideo()
mStoredShowExtendedDetails = context.config.showExtendedDetails mStoredShowExtendedDetails = context!!.config.showExtendedDetails
mStoredExtendedDetails = context.config.extendedDetails mStoredExtendedDetails = context!!.config.extendedDetails
} }
override fun onDestroy() { override fun onDestroy() {
@ -238,17 +238,17 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
mView.video_holder mView.video_holder
} }
private fun getCurrentVolume() = context.audioManager.getStreamVolume(AudioManager.STREAM_MUSIC) private fun getCurrentVolume() = context!!.audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)
private fun getCurrentBrightness() = Settings.System.getInt(activity.contentResolver, Settings.System.SCREEN_BRIGHTNESS) private fun getCurrentBrightness() = Settings.System.getInt(activity!!.contentResolver, Settings.System.SCREEN_BRIGHTNESS)
private fun volumePercentChanged(percent: Int) { private fun volumePercentChanged(percent: Int) {
val stream = AudioManager.STREAM_MUSIC val stream = AudioManager.STREAM_MUSIC
val maxVolume = context.audioManager.getStreamMaxVolume(stream) val maxVolume = context!!.audioManager.getStreamMaxVolume(stream)
val percentPerPoint = 100 / maxVolume val percentPerPoint = 100 / maxVolume
val addPoints = percent / percentPerPoint val addPoints = percent / percentPerPoint
val newVolume = Math.min(maxVolume, Math.max(0, mTouchDownVolume + addPoints)) val newVolume = Math.min(maxVolume, Math.max(0, mTouchDownVolume + addPoints))
context.audioManager.setStreamVolume(stream, newVolume, 0) context!!.audioManager.setStreamVolume(stream, newVolume, 0)
val absolutePercent = ((newVolume / maxVolume.toFloat()) * 100).toInt() val absolutePercent = ((newVolume / maxVolume.toFloat()) * 100).toInt()
mView.slide_info.apply { mView.slide_info.apply {
@ -274,9 +274,9 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
alpha = 1f alpha = 1f
} }
val attributes = activity.window.attributes val attributes = activity!!.window.attributes
attributes.screenBrightness = absolutePercent / 100f attributes.screenBrightness = absolutePercent / 100f
activity.window.attributes = attributes activity!!.window.attributes = attributes
mSlideInfoFadeHandler.removeCallbacksAndMessages(null) mSlideInfoFadeHandler.removeCallbacksAndMessages(null)
mSlideInfoFadeHandler.postDelayed({ mSlideInfoFadeHandler.postDelayed({
@ -286,7 +286,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
private fun initTimeHolder() { private fun initTimeHolder() {
val res = resources val res = resources
val height = context.navigationBarHeight val height = context!!.navigationBarHeight
val left = mTimeHolder.paddingLeft val left = mTimeHolder.paddingLeft
val top = mTimeHolder.paddingTop val top = mTimeHolder.paddingTop
var right = res.getDimension(R.dimen.timer_padding).toInt() var right = res.getDimension(R.dimen.timer_padding).toInt()
@ -297,7 +297,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
bottom += height bottom += height
} else { } else {
right += height right += height
bottom += context.navigationBarHeight bottom += context!!.navigationBarHeight
} }
mTimeHolder.setPadding(left, top, right, bottom) mTimeHolder.setPadding(left, top, right, bottom)
} }
@ -312,7 +312,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
private fun hasNavBar(): Boolean { private fun hasNavBar(): Boolean {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
val display = context.windowManager.defaultDisplay val display = context!!.windowManager.defaultDisplay
val realDisplayMetrics = DisplayMetrics() val realDisplayMetrics = DisplayMetrics()
display.getRealMetrics(realDisplayMetrics) display.getRealMetrics(realDisplayMetrics)
@ -342,7 +342,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
} }
private fun setupTimer() { private fun setupTimer() {
activity.runOnUiThread(object : Runnable { activity!!.runOnUiThread(object : Runnable {
override fun run() { override fun run() {
if (mMediaPlayer != null && !mIsDragged && mIsPlaying) { if (mMediaPlayer != null && !mIsDragged && mIsPlaying) {
mCurrTime = mMediaPlayer!!.currentPosition / 1000 mCurrTime = mMediaPlayer!!.currentPosition / 1000
@ -401,14 +401,14 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
mPlayOnPrepare = true mPlayOnPrepare = true
} }
mView.video_play_outline.setImageDrawable(null) mView.video_play_outline.setImageDrawable(null)
activity.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) activity!!.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
} }
private fun pauseVideo() { private fun pauseVideo() {
mIsPlaying = false mIsPlaying = false
mMediaPlayer?.pause() mMediaPlayer?.pause()
mView.video_play_outline.setImageDrawable(resources.getDrawable(R.drawable.img_play_outline_big)) mView.video_play_outline.setImageDrawable(resources.getDrawable(R.drawable.img_play_outline_big))
activity.window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) activity!!.window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
} }
private fun initMediaPlayer() { private fun initMediaPlayer() {
@ -470,7 +470,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
setupTimeHolder() setupTimeHolder()
setProgress(mCurrTime) setProgress(mCurrTime)
if (mIsFragmentVisible && (context.config.autoplayVideos || mPlayOnPrepare)) if (mIsFragmentVisible && (context!!.config.autoplayVideos || mPlayOnPrepare))
playVideo() playVideo()
} }
@ -479,7 +479,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
return return
} }
if (listener?.videoEnded() == false && context.config.loopVideos) { if (listener?.videoEnded() == false && context!!.config.loopVideos) {
playVideo() playVideo()
} else { } else {
mSeekBar!!.progress = mSeekBar!!.max mSeekBar!!.progress = mSeekBar!!.max
@ -516,7 +516,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
} }
val videoProportion = mMediaPlayer!!.videoWidth.toFloat() / mMediaPlayer!!.videoHeight.toFloat() val videoProportion = mMediaPlayer!!.videoWidth.toFloat() / mMediaPlayer!!.videoHeight.toFloat()
val display = activity.windowManager.defaultDisplay val display = activity!!.windowManager.defaultDisplay
val screenWidth: Int val screenWidth: Int
val screenHeight: Int val screenHeight: Int
@ -545,7 +545,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
} }
private fun checkExtendedDetails() { private fun checkExtendedDetails() {
if (context.config.showExtendedDetails) { if (context!!.config.showExtendedDetails) {
mView.video_details.apply { mView.video_details.apply {
text = getMediumExtendedDetails(medium) text = getMediumExtendedDetails(medium)
setTextColor(context.config.textColor) setTextColor(context.config.textColor)

View file

@ -27,7 +27,7 @@ abstract class ViewPagerFragment : Fragment() {
val path = "${file.parent.trimEnd('/')}/" val path = "${file.parent.trimEnd('/')}/"
val exif = android.media.ExifInterface(medium.path) val exif = android.media.ExifInterface(medium.path)
val details = StringBuilder() val details = StringBuilder()
val detailsFlag = context.config.extendedDetails val detailsFlag = context!!.config.extendedDetails
if (detailsFlag and EXT_NAME != 0) { if (detailsFlag and EXT_NAME != 0) {
medium.name.let { if (it.isNotEmpty()) details.appendln(it) } medium.name.let { if (it.isNotEmpty()) details.appendln(it) }
} }

View file

@ -5,7 +5,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.3.3' classpath 'com.android.tools.build:gradle:3.0.0'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files

View file

@ -1,6 +1,6 @@
#Fri Mar 03 19:10:52 CET 2017 #Tue Nov 07 16:59:29 CET 2017
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip