Skip to content

Commit

Permalink
Real Release
Browse files Browse the repository at this point in the history
  • Loading branch information
Wayyan committed Jul 6, 2020
1 parent 83fc44a commit 24da94e
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

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

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.devduo.networkimage

object NIVConstants {
const val PREFIX= "https://drive.google.com/uc?export=download&id="
const val DRIVE_INDITIFIER="drive.google.com"
val DRIVE_PATTERN_1= Regex("(.*)://drive.google.com/open?id=(.*)")
val DRIVE_PATTERN_2=Regex("(.*)://drive.google.com/file/d/(.*)/view?usp=sharing")
const val PREFIX = "https://drive.google.com/uc?export=download&id="
const val DRIVE_INDITIFIER = "drive.google.com"
val DRIVE_PATTERN_1 = "drive.google.com/open?id="
val DRIVE_PATTERN_2 = "drive.google.com/file/d/"
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
package com.devduo.networkimage

import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.view.SurfaceHolder
import android.widget.ImageView
import androidx.appcompat.widget.AppCompatImageView


class NetworkImageView(context: Context) : AppCompatImageView(context) {
class NetworkImageView : ImageView {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet? = null) : super(context, attrs)
constructor(
context: Context, attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : super(context, attrs, defStyleAttr)

fun network(link: String, placeHolder: Int) {
fromNetwork(executeLink(link), placeHolder)
}

private fun executeLink(link: String): String {
return if (link.matches(NIVConstants.DRIVE_PATTERN_1)) {
return if (link.contains(NIVConstants.DRIVE_PATTERN_1)) {
NIVConstants.PREFIX.plus(link.split("=")[1])
} else if (link.matches(NIVConstants.DRIVE_PATTERN_2)) {
} else if (link.contains(NIVConstants.DRIVE_PATTERN_2)) {
val firstCut = link.split("d/")[1]
val id = firstCut.split("/")[0]
NIVConstants.PREFIX.plus(id)
Expand Down
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ dependencies {
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

// implementation 'com.github.Wayyan:Network-ImageView:1.0.0'
implementation 'com.squareup.picasso:picasso:2.71828'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package="com.devduo.networkimageview"
>

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/com/devduo/networkimageview/Extensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.devduo.networkimageview

import android.util.Log
import android.widget.ImageView
import androidx.appcompat.widget.AppCompatImageView
import com.squareup.picasso.Picasso

fun ImageView.fromNetwork(link: String, placeHolder: Int) {
Log.e("library",link)
Picasso.get()
.load(link)
.placeholder(placeHolder)
.fit()
.centerInside()
.into(this)
}
6 changes: 6 additions & 0 deletions app/src/main/java/com/devduo/networkimageview/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class MainActivity : AppCompatActivity() {
lateinit var networkImageView: NetworkImageView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
networkImageView = findViewById(R.id.niv)
networkImageView.network(
"https://drive.google.com/file/d/1z-apBy-Ue9p4eLNXXgvTwljrr14nW4hX/view?usp=sharing",
R.drawable.place_holder
)
}
}
8 changes: 8 additions & 0 deletions app/src/main/java/com/devduo/networkimageview/NIVConstants.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.devduo.networkimageview

object NIVConstants {
const val PREFIX = "https://drive.google.com/uc?export=download&id="
const val DRIVE_INDITIFIER = "drive.google.com"
val DRIVE_PATTERN_1 = "drive.google.com/open?id="
val DRIVE_PATTERN_2 = "drive.google.com/file/d/"
}
34 changes: 34 additions & 0 deletions app/src/main/java/com/devduo/networkimageview/NetworkImageView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.devduo.networkimageview

import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.widget.ImageView


class NetworkImageView : ImageView {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet? = null) : super(context, attrs)
constructor(
context: Context, attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : super(context, attrs, defStyleAttr)

fun network(link: String, placeHolder: Int) {
fromNetwork(executeLink(link), placeHolder)
}

private fun executeLink(link: String): String {
Log.e("library,", link)
return if (link.contains(NIVConstants.DRIVE_PATTERN_1)) {
Log.e("library,", NIVConstants.PREFIX.plus(link.split("=")[1]))
NIVConstants.PREFIX.plus(link.split("=")[1])
} else if (link.contains(NIVConstants.DRIVE_PATTERN_2)) {
val firstCut = link.split("d/")[1]
val id = firstCut.split("/")[0]
Log.e("library,", NIVConstants.PREFIX.plus(id))
NIVConstants.PREFIX.plus(id)
} else
link
}
}
Binary file added app/src/main/res/drawable/loading.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/place_holder.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:gravity="center">
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/loading"
android:pivotX="50%"
android:pivotY="50%" />
</item>
</layer-list>
9 changes: 5 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
<com.devduo.networkimageview.NetworkImageView
android:id="@+id/niv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}

Expand Down

0 comments on commit 24da94e

Please sign in to comment.