Skip to content

Commit

Permalink
Updated Horizontal & Vertical Item Offset Decorators.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmrecki committed Nov 28, 2019
1 parent ddcf66b commit afc55ef
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 119 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:label="@string/bornfight_utils"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="app_name">Bornfight Android Framework</string>
<string name="bornfight_utils">Bornfight Android Framework</string>
</resources>
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 11 additions & 22 deletions utils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'
Expand Down
18 changes: 0 additions & 18 deletions utils/src/main/java/com/bornfight/utils/Analytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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<String, String>) {
val ce = CustomEvent(eventName)
customAttributes.entries.forEach { (attributeKey, attributeValue) ->
ce.putCustomAttribute(
attributeKey, attributeValue.substring(0, Math.min(attributeValue.length, 99))
)
}
answers.logCustom(ce)
}
14 changes: 7 additions & 7 deletions utils/src/main/java/com/bornfight/utils/ImageUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Uri> {
fun getResizedImagePath(
context: Context,
imageUri: Uri,
targetWidth: Int = 1080,
targetHeight: Int = 1080
): Observable<Uri> {
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
Expand All @@ -49,7 +50,6 @@ object ImageUtils {
Uri.Builder().path(imageUri.path).build()
)
} catch (e: OutOfMemoryError) {
Crashlytics.logException(e)
e.printStackTrace()
}

Expand Down
29 changes: 3 additions & 26 deletions utils/src/main/java/com/bornfight/utils/LocationUtils.kt
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand All @@ -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)

}
1 change: 1 addition & 0 deletions utils/src/main/java/com/bornfight/utils/PaginatedData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class PaginatedData<T>(val limit: Int, private val load: (limit: Int, page: Int)
page = 1
loadingEnabled = true
reachedEnd = false
oldItems.clear()
}

@Deprecated(message = "Use reachedEnd instead")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
}
}
}

0 comments on commit afc55ef

Please sign in to comment.