Skip to content

Commit

Permalink
version update
Browse files Browse the repository at this point in the history
  • Loading branch information
ziadulislam committed Oct 31, 2023
1 parent 3a089bc commit a928242
Show file tree
Hide file tree
Showing 18 changed files with 294 additions and 96 deletions.
6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions androidutils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ plugins {
}

android {
compileSdkVersion 30
compileSdkVersion 33
buildToolsVersion "30.0.3"

defaultConfig {
minSdkVersion 19
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName "1.0"

Expand Down Expand Up @@ -49,6 +49,8 @@ dependencies {
implementation "com.github.bumptech.glide:glide:4.11.0"
kapt "com.github.bumptech.glide:compiler:4.11.0"

implementation 'com.google.code.gson:gson:2.10.1'

// jsoup HTML parser library @ https://jsoup.org/
implementation 'org.jsoup:jsoup:1.13.1'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import org.jetbrains.annotations.Nullable

class ScrollDisabledRecyclerView : RecyclerView {

constructor(context: Context?) : super(context!!)
constructor(context: Context?, @Nullable attrs: AttributeSet?) : super(context!!, attrs)
constructor(context: Context?, @Nullable attrs: AttributeSet?, defStyle: Int) : super(
context!!, attrs, defStyle
)
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle)

@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(e: MotionEvent): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import java.util.*
object KotlinExtensionFunctions {



inline fun <T> T.applyIf(condition: Boolean, block: T.() -> Unit): T {
return if (condition) {
this.apply(block)
Expand All @@ -25,7 +24,6 @@ object KotlinExtensionFunctions {
}



/**
*
* uses
Expand Down Expand Up @@ -107,11 +105,11 @@ object KotlinExtensionFunctions {
*/

fun View.snackbar(message: String, duration: Int = Snackbar.LENGTH_LONG) {
fun View.snackBar(message: String, duration: Int = Snackbar.LENGTH_LONG) {
Snackbar.make(this, message, duration).show()
}

fun View.snackbar(@StringRes message: Int, duration: Int = Snackbar.LENGTH_LONG) {
fun View.snackBar(@StringRes message: Int, duration: Int = Snackbar.LENGTH_LONG) {
Snackbar.make(this, message, duration).show()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.xihad.androidutils.extension

import androidx.lifecycle.Observer

/**
* Used as a wrapper for data that is exposed via a LiveData that represents an event.
* Tutorial: https://medium.com/androiddevelopers/livedata-with-snackbar-navigation-and-other-events-the-singleliveevent-case-ac2622673150
*/
open class Event<out T>(private val content: T) {

@Suppress("MemberVisibilityCanBePrivate")
var hasBeenHandled = false
private set // Allow external read but not write

/**
* Returns the content and prevents its use again.
*/
fun getContentIfNotHandled(): T? {
return if (hasBeenHandled) {
null
} else {
hasBeenHandled = true
content
}
}

/**
* Returns the content, even if it's already been handled.
*/
fun peekContent(): T = content
}

/**
* An [Observer] for [Event]s, simplifying the pattern of checking if the [Event]'s content has
* already been handled.
*
* [onEventUnhandledContent] is *only* called if the [Event]'s contents has not been handled.
*/
class EventObserver<T>(private val onEventUnhandledContent: (T) -> Unit) : Observer<Event<T>> {
override fun onChanged(value: Event<T>) {
value.getContentIfNotHandled()?.let {
onEventUnhandledContent(it)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.xihad.androidutils.extension

import java.io.IOException

class ApiException(message: String) : IOException(message)

class AppApiException(message: String, private val code: String) : IOException(message) {
fun getErrorCode(): String {
return code
}
}

class NoInternetException(message: String) : IOException(message)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.xihad.androidutils.extension

/**
* A generic class that holds a value with its loading status.
* @param <T>
*/
sealed class ResResult<out R> {

data class Success<out T>(val data: T) : ResResult<T>()
data class Error(val exception: Exception, val code: String = "-1") : ResResult<Nothing>()
object Loading : ResResult<Nothing>()

override fun toString(): String {
return when (this) {
is Success<*> -> "Success[data=$data]"
is Error -> "Error[code=$code exception=${exception.message}]"
Loading -> "Loading"
}
}
}

/**
* `true` if [ResResult] is of type [Success] & holds non-null [Success.data].
*/
val ResResult<*>.succeeded
get() = this is ResResult.Success && data != null

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,13 @@ object AppUtil {
}


fun deleteCache(context: Context) {
context.cacheDir.deleteRecursively()
}

fun Context.deleteCache() {
this.cacheDir.deleteRecursively()
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,16 @@ object ColorUtil {
return String.format("#%06X", -0x1 and this).replace("#FF", "#")
}


private fun TextView.setTextViewDrawableColor(color: Int) {
for (drawable in this.compoundDrawablesRelative) {
drawable?.mutate()
drawable?.colorFilter = PorterDuffColorFilter(
color, PorterDuff.Mode.SRC_IN
)
}
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.xihad.androidutils.utils

import com.google.gson.Gson
import com.google.gson.JsonObject
import org.json.JSONObject

object JsonUtils {

fun <T> T.toJson(): String {
return Gson().toJson(this)
}

fun JSONObject.toJsonObject(): JsonObject = Gson().fromJson(this.toString(), JsonObject::class.java)
}
Loading

0 comments on commit a928242

Please sign in to comment.