diff --git a/README.md b/README.md index f6df853..80d8b61 100644 --- a/README.md +++ b/README.md @@ -1 +1,22 @@ -# apklisupdate +# Check app update in [Apklis](https://www.apklis.cu/es/) +[![](https://jitpack.io/v/adrian011494/apklisupdate.svg)](https://jitpack.io/#adrian011494/apklisupdate) + +### Installing +* Step 1. Add the JitPack repository to your build file +```groovy +allprojects { + repositories { + ... + maven { url 'https://jitpack.io' } + } +} +``` +* Step 2. Add the dependency +```groovy +implementation 'com.github.adrian011494:apklisupdate:$VERSION' +``` +### Usage + +```kotlin + +``` diff --git a/apklisupdate/build.gradle b/apklisupdate/build.gradle index 2fc4db6..3ed53b2 100644 --- a/apklisupdate/build.gradle +++ b/apklisupdate/build.gradle @@ -81,7 +81,7 @@ dependencies { implementation 'com.squareup.retrofit2:converter-gson:2.4.0' /** rx java **/ - implementation 'io.reactivex.rxjava2:rxjava:2.2.0' + implementation 'io.reactivex.rxjava2:rxjava:2.2.2' implementation 'io.reactivex.rxjava2:rxkotlin:2.3.0' implementation 'io.reactivex.rxjava2:rxandroid:2.1.0' implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0' @@ -91,6 +91,5 @@ dependencies { //html implementation 'org.sufficientlysecure:html-textview:3.6' - implementation 'com.squareup.picasso:picasso:2.71828' } diff --git a/apklisupdate/src/main/java/cu/uci/apklisupdate/ApklisUpdate.kt b/apklisupdate/src/main/java/cu/uci/apklisupdate/ApklisUpdate.kt index fd1f19a..6aa9d09 100644 --- a/apklisupdate/src/main/java/cu/uci/apklisupdate/ApklisUpdate.kt +++ b/apklisupdate/src/main/java/cu/uci/apklisupdate/ApklisUpdate.kt @@ -4,6 +4,7 @@ import android.annotation.SuppressLint import android.content.Context import android.os.Build import io.reactivex.schedulers.Schedulers +import java.lang.Exception object ApklisUpdate { @@ -26,10 +27,36 @@ object ApklisUpdate { } else { info.versionCode.toLong() } - if (versionCode < it.last_release.version_code && info.versionName != it.last_release.version_name) - callback.onNewUpdate(it) - else - callback.onOldUpdate(it) + + if (it != null) { + if (versionCode < it.last_release.version_code && info.versionName != it.last_release.version_name) + callback.onNewUpdate(it) + else + callback.onOldUpdate(it) + } else + callback.onError(Exception("Not data")) + }, { + it.printStackTrace() + callback.onError(it) + }) + + } + + @SuppressLint("CheckResult") + fun hasAppUpdate(packageName: String, versionCode: Long = 0, callback: UpdateCallback) { + + LastReleaseClient.instance() + .lastRelease(packageName) + .subscribeOn(Schedulers.newThread()) + .subscribe({ + + if (it != null) { + if (versionCode < it.last_release.version_code) + callback.onNewUpdate(it) + else + callback.onOldUpdate(it) + } else + callback.onError(Exception("Not data")) }, { it.printStackTrace() callback.onError(it) diff --git a/apklisupdate/src/main/java/cu/uci/apklisupdate/LastReleaseApi.kt b/apklisupdate/src/main/java/cu/uci/apklisupdate/LastReleaseApi.kt index eef1066..a524ae4 100644 --- a/apklisupdate/src/main/java/cu/uci/apklisupdate/LastReleaseApi.kt +++ b/apklisupdate/src/main/java/cu/uci/apklisupdate/LastReleaseApi.kt @@ -1,16 +1,18 @@ package cu.uci.apklisupdate +import cu.uci.apklisupdate.model.ApiResponce import cu.uci.apklisupdate.model.AppUpdateInfo import io.reactivex.Single import retrofit2.http.GET import retrofit2.http.Path +import retrofit2.http.Query /** * Created by Adrian Arencibia Herrera on 5/29/18. * Email: adrian011494@gmail.com */ interface LastReleaseApi { - @GET("api/v1/application/{package}/") - fun lastRelease(@Path("package") appPackage: String): Single + @GET("api/v1/application/") + fun lastRelease(@Query("package_name") appPackage: String): Single } \ No newline at end of file diff --git a/apklisupdate/src/main/java/cu/uci/apklisupdate/LastReleaseClient.kt b/apklisupdate/src/main/java/cu/uci/apklisupdate/LastReleaseClient.kt index 5634611..91c64ad 100644 --- a/apklisupdate/src/main/java/cu/uci/apklisupdate/LastReleaseClient.kt +++ b/apklisupdate/src/main/java/cu/uci/apklisupdate/LastReleaseClient.kt @@ -11,8 +11,11 @@ import io.reactivex.Single class LastReleaseClient : RestClient(LastReleaseApi::class.java) { - fun lastRelease(appPackage: String): Single { + fun lastRelease(appPackage: String): Single { return mApi.lastRelease(appPackage) + .map { + it.results.firstOrNull() + } } companion object { diff --git a/apklisupdate/src/main/java/cu/uci/apklisupdate/model/ApiResponce.kt b/apklisupdate/src/main/java/cu/uci/apklisupdate/model/ApiResponce.kt new file mode 100644 index 0000000..def7bf2 --- /dev/null +++ b/apklisupdate/src/main/java/cu/uci/apklisupdate/model/ApiResponce.kt @@ -0,0 +1,3 @@ +package cu.uci.apklisupdate.model + +data class ApiResponce(val count: Int = 0, val results: List = listOf()) \ No newline at end of file diff --git a/apklisupdate/src/main/java/cu/uci/apklisupdate/model/LastRelease.kt b/apklisupdate/src/main/java/cu/uci/apklisupdate/model/LastRelease.kt index 8dc1c44..de51e73 100644 --- a/apklisupdate/src/main/java/cu/uci/apklisupdate/model/LastRelease.kt +++ b/apklisupdate/src/main/java/cu/uci/apklisupdate/model/LastRelease.kt @@ -17,5 +17,5 @@ data class LastRelease( var version_sdk: Int, var version_sdk_name: String, var version_target_sdk: Int, - var version_target_sdk_name: Int + var version_target_sdk_name: String ) \ No newline at end of file diff --git a/apklisupdate/src/main/java/cu/uci/apklisupdate/view/ApklisUpdateFragment.kt b/apklisupdate/src/main/java/cu/uci/apklisupdate/view/ApklisUpdateFragment.kt index 9559ec5..b983146 100644 --- a/apklisupdate/src/main/java/cu/uci/apklisupdate/view/ApklisUpdateFragment.kt +++ b/apklisupdate/src/main/java/cu/uci/apklisupdate/view/ApklisUpdateFragment.kt @@ -9,6 +9,8 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.annotation.ColorInt +import androidx.core.content.IntentCompat import androidx.fragment.app.Fragment import com.squareup.picasso.Picasso import cu.uci.apklisupdate.R @@ -38,13 +40,13 @@ class ApklisUpdateFragment : Fragment() { fromApklis.setOnClickListener { val i = Intent(Intent.ACTION_VIEW) i.data = Uri.parse("https://www.apklis.cu/es/application/${updateInfo.package_name}/latest") - requireContext().startActivity(Intent.createChooser(i, "")) + requireContext().startActivity(Intent.createChooser(i, getString(R.string.open_web))) } download.setOnClickListener { val i = Intent(Intent.ACTION_VIEW) i.data = Uri.parse(updateInfo.last_release.apk_file) - requireContext().startActivity(Intent.createChooser(i, "")) + requireContext().startActivity(Intent.createChooser(i, getString(R.string.download))) } Picasso.get().load(updateInfo.last_release.icon).into(logo) @@ -66,7 +68,7 @@ class ApklisUpdateFragment : Fragment() { fun newInstance( updateInfo: AppUpdateInfo, background: Drawable = ColorDrawable(Color.WHITE), - actionsColor: Int = Color.BLACK + @ColorInt actionsColor: Int = Color.BLACK ): ApklisUpdateFragment { return ApklisUpdateFragment().apply { this.updateInfo = updateInfo diff --git a/apklisupdate/src/main/res/layout/apklis_fragment_update.xml b/apklisupdate/src/main/res/layout/apklis_fragment_update.xml index b7d6d1b..ef0c4b7 100644 --- a/apklisupdate/src/main/res/layout/apklis_fragment_update.xml +++ b/apklisupdate/src/main/res/layout/apklis_fragment_update.xml @@ -1,59 +1,59 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/fragmentView" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_gravity="center" + android:background="@android:color/holo_blue_dark"> - - + android:layout_centerInParent="true" + android:layout_margin="@dimen/default_margin"> - + android:orientation="vertical" + android:padding="@dimen/default_padding"> + + + android:id="@+id/title" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center" + android:textAlignment="center" + android:textSize="20sp" + tools:text="Title"/> + android:id="@+id/version" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center" + android:textAlignment="center" + tools:text="0.11.20"/> + Bla"/> + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal" + android:weightSum="2"> + android:id="@+id/fromApklis" + style="@style/Widget.MaterialComponents.Button.TextButton" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1" + android:text="@string/update" + android:textAllCaps="true"/> + android:id="@+id/download" + style="@style/Widget.MaterialComponents.Button.TextButton" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1" + android:text="@string/download" + android:textAllCaps="true" + /> diff --git a/apklisupdate/src/main/res/values/strings.xml b/apklisupdate/src/main/res/values/strings.xml index 176dd24..cfeb4af 100644 --- a/apklisupdate/src/main/res/values/strings.xml +++ b/apklisupdate/src/main/res/values/strings.xml @@ -3,4 +3,5 @@ Abrir en apklis Descargar Principales cambios: + Abrir Apklis diff --git a/app/build.gradle b/app/build.gradle index a9070b1..276f96b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -25,8 +25,10 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'androidx.appcompat:appcompat:1.0.0-beta01' - implementation 'androidx.core:core-ktx:1.1.0-alpha03' - implementation 'androidx.constraintlayout:constraintlayout:1.1.2' + implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'androidx.core:core:1.0.2' + implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2' + implementation 'com.google.android.material:material:1.0.0' + implementation 'androidx.palette:palette:1.0.0' implementation project(':apklisupdate') } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f80959d..89636a7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,7 @@ + + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context=".MainActivity"> - + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 5885930..1c56072 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,7 +1,7 @@ -