From afc55ef147ec39fb408439b82a80afe0f2565914 Mon Sep 17 00:00:00 2001 From: Tomislav Date: Thu, 28 Nov 2019 23:12:55 +0100 Subject: [PATCH] Updated Horizontal & Vertical Item Offset Decorators. --- app/build.gradle | 4 +-- app/src/main/AndroidManifest.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- build.gradle | 6 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- utils/build.gradle | 33 +++++++------------ .../java/com/bornfight/utils/Analytics.kt | 18 ---------- .../java/com/bornfight/utils/ImageUtils.kt | 14 ++++---- .../java/com/bornfight/utils/LocationUtils.kt | 29 ++-------------- .../java/com/bornfight/utils/PaginatedData.kt | 1 + .../utils/views/HorizontalOffsetDecoration.kt | 13 ++++++-- .../views/SimpleGridItemDividerDecoration.kt | 33 ------------------- .../utils/views/VerticalOffsetDecoration.kt | 22 +++++++++++-- 13 files changed, 60 insertions(+), 119 deletions(-) delete mode 100644 utils/src/main/java/com/bornfight/utils/views/SimpleGridItemDividerDecoration.kt diff --git a/app/build.gradle b/app/build.gradle index 353691c..edf1736 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -27,8 +27,8 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'androidx.appcompat:appcompat:1.0.2' - implementation 'androidx.constraintlayout:constraintlayout:1.1.2' + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.1-alpha01' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1-alpha01' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4352b2b..6d9f8ea 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -5,7 +5,7 @@ diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 83c0518..cd328bf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,3 @@ - Bornfight Android Framework + Bornfight Android Framework diff --git a/build.gradle b/build.gradle index be23678..d58967d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,13 +1,13 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.31' + ext.kotlin_version = '1.3.50' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.1' - classpath 'com.google.gms:google-services:4.2.0' + classpath 'com.android.tools.build:gradle:3.5.2' + classpath 'com.google.gms:google-services:4.3.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "com.github.dcendents:android-maven-gradle-plugin:2.1" // NOTE: Do not place your application dependencies here; they belong diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index aae52c3..2e8b0bf 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip diff --git a/utils/build.gradle b/utils/build.gradle index 7f48a3a..5665869 100644 --- a/utils/build.gradle +++ b/utils/build.gradle @@ -3,8 +3,8 @@ apply plugin: 'kotlin-android' apply plugin: 'com.github.dcendents.android-maven' // JitPack -group="degordian.com" -version="0.96" +group="bornfight.com" +version="0.97" android { @@ -38,43 +38,32 @@ dependencies { // Various dependencies ======================================== implementation 'org.ocpsoft.prettytime:prettytime:4.0.1.Final' - implementation 'com.github.bumptech.glide:glide:4.9.0' + implementation 'com.github.bumptech.glide:glide:4.10.0' // ============================================================== // AndroidX Extensions - implementation 'androidx.appcompat:appcompat:1.0.2' - implementation 'androidx.recyclerview:recyclerview:1.0.0' + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.recyclerview:recyclerview:1.1.0' implementation 'androidx.browser:browser:1.0.0' // Google implementation 'com.google.android.material:material:1.0.0' // RxJava2 - implementation 'io.reactivex.rxjava2:rxandroid:2.0.1' - implementation 'io.reactivex.rxjava2:rxjava:2.2.6' - implementation 'com.artemzin.rxjava:proguard-rules:1.1.5.0' + implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' + implementation 'io.reactivex.rxjava2:rxjava:2.2.11' + implementation 'com.artemzin.rxjava:proguard-rules:1.3.3.0' //Retrofit & Networking - implementation 'com.squareup.retrofit2:retrofit:2.5.0' - implementation 'com.squareup.retrofit2:converter-gson:2.5.0' - - // Play Services - //implementation 'com.google.android.gms:play-services-location:16.0.0' - implementation 'com.google.android.gms:play-services-maps:17.0.0' - - + implementation 'com.squareup.retrofit2:retrofit:2.6.1' + // Firebase - implementation 'com.google.firebase:firebase-core:17.0.0' + implementation 'com.google.firebase:firebase-core:17.2.1' // Kotlin implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - // Crashlytics - implementation('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') { - transitive = true - } - // Tests androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0-beta01', { exclude group: 'com.android.support', module: 'support-annotations' diff --git a/utils/src/main/java/com/bornfight/utils/Analytics.kt b/utils/src/main/java/com/bornfight/utils/Analytics.kt index 49a9559..76fed22 100644 --- a/utils/src/main/java/com/bornfight/utils/Analytics.kt +++ b/utils/src/main/java/com/bornfight/utils/Analytics.kt @@ -4,8 +4,6 @@ package com.bornfight.utils import android.os.Bundle -import com.crashlytics.android.answers.Answers -import com.crashlytics.android.answers.CustomEvent import com.google.firebase.analytics.FirebaseAnalytics /** @@ -27,19 +25,3 @@ fun logFirebaseEvent( bundle.putString(FirebaseAnalytics.Param.CONTENT, content) firebaseAnalytics.logEvent(eventName, bundle) } - -/** - * Logs a Crashlytics [Answers] event. - * @param answers analytics object fetched via [Answers.getInstance] - * @param eventName event name for [CustomEvent] - * @param customAttributes a map of custom attributes for this event - */ -fun logAnswersEvent(answers: Answers, eventName: String, customAttributes: Map) { - val ce = CustomEvent(eventName) - customAttributes.entries.forEach { (attributeKey, attributeValue) -> - ce.putCustomAttribute( - attributeKey, attributeValue.substring(0, Math.min(attributeValue.length, 99)) - ) - } - answers.logCustom(ce) -} diff --git a/utils/src/main/java/com/bornfight/utils/ImageUtils.kt b/utils/src/main/java/com/bornfight/utils/ImageUtils.kt index 6ba4d50..61f182e 100644 --- a/utils/src/main/java/com/bornfight/utils/ImageUtils.kt +++ b/utils/src/main/java/com/bornfight/utils/ImageUtils.kt @@ -5,7 +5,6 @@ import android.graphics.* import android.media.ExifInterface import android.net.Uri import android.util.Log -import com.crashlytics.android.Crashlytics import io.reactivex.Observable import java.io.File import java.io.FileOutputStream @@ -21,18 +20,20 @@ object ImageUtils { /** * Resizes the image, and returns it as [Observable]. Max resolution will be 1080x1080, with 80% quality */ - fun getResizedImagePath(context: Context, imageUri: Uri): Observable { + fun getResizedImagePath( + context: Context, + imageUri: Uri, + targetWidth: Int = 1080, + targetHeight: Int = 1080 + ): Observable { return Observable.fromCallable { - // Get the dimensions of the View - val targetW = 1080 - val targetH = 1080 // Get the dimensions of the bitmap val bmOptions = BitmapFactory.Options() bmOptions.inJustDecodeBounds = true BitmapFactory.decodeFile(imageUri.path, bmOptions) - val inSampleSize = calculateInSampleSize(bmOptions, targetW, targetH) + val inSampleSize = calculateInSampleSize(bmOptions, targetWidth, targetHeight) Log.d("ImageUtils", "Image resize scale factor $inSampleSize") // Decode the image file into a Bitmap sized to fill the View @@ -49,7 +50,6 @@ object ImageUtils { Uri.Builder().path(imageUri.path).build() ) } catch (e: OutOfMemoryError) { - Crashlytics.logException(e) e.printStackTrace() } diff --git a/utils/src/main/java/com/bornfight/utils/LocationUtils.kt b/utils/src/main/java/com/bornfight/utils/LocationUtils.kt index bcf534d..03f652c 100644 --- a/utils/src/main/java/com/bornfight/utils/LocationUtils.kt +++ b/utils/src/main/java/com/bornfight/utils/LocationUtils.kt @@ -1,10 +1,5 @@ package com.bornfight.utils -import android.location.Location - -import com.google.android.gms.maps.GoogleMap -import com.google.android.gms.maps.model.LatLng - /** * A helper object containing various methods for work with maps. */ @@ -30,26 +25,8 @@ object LocationUtil { * @param map [GoogleMap] instance, from which the zoom is fetched.] * @return the equation result */ - fun getRadius(map: GoogleMap): Int { - val zoom = map.cameraPosition.zoom - - val scale = Math.exp(16 - zoom * Math.log(2.0)).toFloat() + fun getRadius(googleMapZoom: Float): Int { + val scale = Math.exp(16 - googleMapZoom * Math.log(2.0)).toFloat() return scale.toInt() * 2 } - -} - -/** - * Calculates the distance between the two [LatLng] objects using the [Location.distanceBetween] method. - */ -fun LatLng.distanceTo(a: LatLng): Float { - val distance = FloatArray(1) - Location.distanceBetween(a.latitude, a.longitude, latitude, longitude, distance) - return distance[0] -} - -/** - * Performs a [Location] - [LatLng] cast - */ -fun Location.latLng(): LatLng = LatLng(latitude, longitude) - +} \ No newline at end of file diff --git a/utils/src/main/java/com/bornfight/utils/PaginatedData.kt b/utils/src/main/java/com/bornfight/utils/PaginatedData.kt index a83bcbe..eb95abd 100644 --- a/utils/src/main/java/com/bornfight/utils/PaginatedData.kt +++ b/utils/src/main/java/com/bornfight/utils/PaginatedData.kt @@ -119,6 +119,7 @@ class PaginatedData(val limit: Int, private val load: (limit: Int, page: Int) page = 1 loadingEnabled = true reachedEnd = false + oldItems.clear() } @Deprecated(message = "Use reachedEnd instead") diff --git a/utils/src/main/java/com/bornfight/utils/views/HorizontalOffsetDecoration.kt b/utils/src/main/java/com/bornfight/utils/views/HorizontalOffsetDecoration.kt index 0ba46d6..ffb5875 100755 --- a/utils/src/main/java/com/bornfight/utils/views/HorizontalOffsetDecoration.kt +++ b/utils/src/main/java/com/bornfight/utils/views/HorizontalOffsetDecoration.kt @@ -19,9 +19,18 @@ class HorizontalOffsetDecoration(context: Context, offset: Float) : RecyclerView outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State ) { + val itemPosition = parent.getChildAdapterPosition(view) - outRect.left = offset / 2 - outRect.right = offset / 2 + if (itemPosition == 0) { + outRect.left = 0 + } else { + outRect.left = offset / 2 + } + if (itemPosition == (parent.adapter?.itemCount ?: 0) - 1) { + outRect.right = 0 + } else { + outRect.right = offset / 2 + } } } \ No newline at end of file diff --git a/utils/src/main/java/com/bornfight/utils/views/SimpleGridItemDividerDecoration.kt b/utils/src/main/java/com/bornfight/utils/views/SimpleGridItemDividerDecoration.kt deleted file mode 100644 index 178cf95..0000000 --- a/utils/src/main/java/com/bornfight/utils/views/SimpleGridItemDividerDecoration.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.bornfight.utils.views - -import android.content.Context -import android.graphics.Rect -import android.util.TypedValue -import android.view.View -import androidx.recyclerview.widget.RecyclerView - -/** - * Created by tomislav on 20/10/2016. - */ - -class SimpleGridItemDividerDecoration(context: Context, spacingDp: Float) : RecyclerView.ItemDecoration() { - - private var spacingPx: Int = 0 - - init { - this.spacingPx = TypedValue.applyDimension( - TypedValue.COMPLEX_UNIT_DIP, spacingDp, - context.resources.displayMetrics - ).toInt() - } - - override fun getItemOffsets( - outRect: Rect, view: View, - parent: RecyclerView, state: RecyclerView.State - ) { - outRect.right = spacingPx / 2 - outRect.bottom = spacingPx / 2 - outRect.left = spacingPx / 2 - outRect.top = spacingPx / 2 - } -} diff --git a/utils/src/main/java/com/bornfight/utils/views/VerticalOffsetDecoration.kt b/utils/src/main/java/com/bornfight/utils/views/VerticalOffsetDecoration.kt index 91dd7d7..88e3e79 100755 --- a/utils/src/main/java/com/bornfight/utils/views/VerticalOffsetDecoration.kt +++ b/utils/src/main/java/com/bornfight/utils/views/VerticalOffsetDecoration.kt @@ -10,7 +10,14 @@ import androidx.recyclerview.widget.RecyclerView * Created by tomislav on 07/03/2017. */ -class VerticalOffsetDecoration(context: Context, offset: Float) : RecyclerView.ItemDecoration() { +class VerticalOffsetDecoration constructor( + context: Context, + offset: Float, + private val spanCount: Int +) : RecyclerView.ItemDecoration() { + + @Deprecated("Please specify span count") + constructor(context: Context, offset: Float) : this(context, offset, 1) private val offset: Int = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, offset, context.resources.displayMetrics).toInt() @@ -20,8 +27,17 @@ class VerticalOffsetDecoration(context: Context, offset: Float) : RecyclerView.I parent: RecyclerView, state: RecyclerView.State ) { - outRect.top = offset / 2 - outRect.bottom = offset / 2 + val itemPosition = parent.getChildAdapterPosition(view) + if (itemPosition < spanCount) { + outRect.top = 0 + } else { + outRect.top = offset / 2 + } + if ((parent.adapter?.itemCount ?: 0) - parent.getChildAdapterPosition(view) < spanCount) { + outRect.bottom = 0 + } else { + outRect.bottom = offset / 2 + } } } \ No newline at end of file