From d34764f713bf069482e3f2136d36a02ddd22654e Mon Sep 17 00:00:00 2001 From: Osvel Alvarez Date: Mon, 24 May 2021 16:06:58 -0400 Subject: [PATCH] =?UTF-8?q?[FIX]=20NullPointerException=20al=20intentar=20?= =?UTF-8?q?descargar=20Soluci=C3=B3n:=20Ocultar=20el=20bot=C3=B3n=20de=20d?= =?UTF-8?q?escarga=20siempre=20que=20la=20url=20de=20la=20apk=20sea=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apklisupdate/ExampleInstrumentedTest.java | 3 +- apklisupdate/src/main/AndroidManifest.xml | 3 +- .../cu/uci/apklisupdate/LastReleaseApi.kt | 2 - .../cu/uci/apklisupdate/UpdateCallback.kt | 1 - .../cu/uci/apklisupdate/model/LastRelease.kt | 2 +- .../apklisupdate/view/ApklisUpdateDialog.kt | 5 +- .../apklisupdate/view/ApklisUpdateFragment.kt | 4 +- .../uci/apklisupdate/view/UpdateFragment.kt | 10 +- .../main/res/layout/apklis_dialog_update.xml | 100 ++++++------- .../res/layout/apklis_fragment_update.xml | 132 ++++++++---------- .../src/test/kotlin/ApklisUpdateUnitTest.kt | 5 +- 11 files changed, 129 insertions(+), 138 deletions(-) diff --git a/apklisupdate/src/androidTest/java/cu/uci/apklisupdate/ExampleInstrumentedTest.java b/apklisupdate/src/androidTest/java/cu/uci/apklisupdate/ExampleInstrumentedTest.java index 9dd62e5..5261cbf 100644 --- a/apklisupdate/src/androidTest/java/cu/uci/apklisupdate/ExampleInstrumentedTest.java +++ b/apklisupdate/src/androidTest/java/cu/uci/apklisupdate/ExampleInstrumentedTest.java @@ -4,10 +4,11 @@ import androidx.test.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; + import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Instrumented test, which will execute on an Android device. diff --git a/apklisupdate/src/main/AndroidManifest.xml b/apklisupdate/src/main/AndroidManifest.xml index 2e9158e..3950a2f 100644 --- a/apklisupdate/src/main/AndroidManifest.xml +++ b/apklisupdate/src/main/AndroidManifest.xml @@ -1,2 +1 @@ - + diff --git a/apklisupdate/src/main/java/cu/uci/apklisupdate/LastReleaseApi.kt b/apklisupdate/src/main/java/cu/uci/apklisupdate/LastReleaseApi.kt index a4f39ca..2246d9b 100644 --- a/apklisupdate/src/main/java/cu/uci/apklisupdate/LastReleaseApi.kt +++ b/apklisupdate/src/main/java/cu/uci/apklisupdate/LastReleaseApi.kt @@ -1,10 +1,8 @@ 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 /** diff --git a/apklisupdate/src/main/java/cu/uci/apklisupdate/UpdateCallback.kt b/apklisupdate/src/main/java/cu/uci/apklisupdate/UpdateCallback.kt index e32654a..b8f6571 100644 --- a/apklisupdate/src/main/java/cu/uci/apklisupdate/UpdateCallback.kt +++ b/apklisupdate/src/main/java/cu/uci/apklisupdate/UpdateCallback.kt @@ -1,7 +1,6 @@ package cu.uci.apklisupdate import cu.uci.apklisupdate.model.AppUpdateInfo -import java.lang.Exception interface UpdateCallback { fun onNewUpdate(appUpdateInfo: AppUpdateInfo) 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 74e3774..995cb28 100644 --- a/apklisupdate/src/main/java/cu/uci/apklisupdate/model/LastRelease.kt +++ b/apklisupdate/src/main/java/cu/uci/apklisupdate/model/LastRelease.kt @@ -3,7 +3,7 @@ package cu.uci.apklisupdate.model import com.google.gson.annotations.SerializedName data class LastRelease( - @SerializedName("apk_file") var apk_file: String, + @SerializedName("apk_file") var apk_file: String?, @SerializedName("changelog") var changelog: String, @SerializedName("human_readable_size") var human_readable_size: String, @SerializedName("icon") var icon: String, diff --git a/apklisupdate/src/main/java/cu/uci/apklisupdate/view/ApklisUpdateDialog.kt b/apklisupdate/src/main/java/cu/uci/apklisupdate/view/ApklisUpdateDialog.kt index 6cf5583..734b09d 100644 --- a/apklisupdate/src/main/java/cu/uci/apklisupdate/view/ApklisUpdateDialog.kt +++ b/apklisupdate/src/main/java/cu/uci/apklisupdate/view/ApklisUpdateDialog.kt @@ -5,7 +5,7 @@ import android.content.Context import android.content.Intent import android.net.Uri import android.os.Bundle -import android.util.Log +import android.view.View import androidx.annotation.ColorInt import com.squareup.picasso.Picasso import cu.uci.apklisupdate.R @@ -22,6 +22,9 @@ class ApklisUpdateDialog( super.onCreate(savedInstanceState) setContentView(R.layout.apklis_dialog_update) + if (updateInfo.last_release.apk_file == null) + download.visibility = View.GONE + changelog.setHtml("${context.getString(R.string.changelog)}\n${updateInfo.last_release.changelog}") version.text = updateInfo.last_release.version_name title.text = updateInfo.name 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 bebe2b1..fcaba3a 100644 --- a/apklisupdate/src/main/java/cu/uci/apklisupdate/view/ApklisUpdateFragment.kt +++ b/apklisupdate/src/main/java/cu/uci/apklisupdate/view/ApklisUpdateFragment.kt @@ -6,7 +6,6 @@ import android.graphics.drawable.ColorDrawable import android.graphics.drawable.Drawable import android.net.Uri import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -38,6 +37,9 @@ class ApklisUpdateFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + if (updateInfo.last_release.apk_file == null) + download.visibility = View.GONE + changelog.setHtml("${context?.getString(R.string.changelog)}\n${updateInfo.last_release.changelog}") version.text = updateInfo.last_release.version_name title.text = updateInfo.name diff --git a/apklisupdate/src/main/java/cu/uci/apklisupdate/view/UpdateFragment.kt b/apklisupdate/src/main/java/cu/uci/apklisupdate/view/UpdateFragment.kt index 962a938..3d5da3d 100644 --- a/apklisupdate/src/main/java/cu/uci/apklisupdate/view/UpdateFragment.kt +++ b/apklisupdate/src/main/java/cu/uci/apklisupdate/view/UpdateFragment.kt @@ -3,7 +3,6 @@ package cu.uci.apklisupdate.view; import android.content.Intent import android.net.Uri import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -35,6 +34,9 @@ class UpdateFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + if (updateInfo.last_release.apk_file == null) + download.visibility = View.GONE + changelog.setHtml("${context?.getString(R.string.changelog)}\n${updateInfo.last_release.changelog}") version.text = updateInfo.last_release.changelog @@ -59,7 +61,11 @@ class UpdateFragment : Fragment() { companion object { - fun newInstance(updateInfo: AppUpdateInfo, @DrawableRes background: Int = android.R.color.white, @ColorRes actionsColor: Int = android.R.color.black): UpdateFragment { + fun newInstance( + updateInfo: AppUpdateInfo, + @DrawableRes background: Int = android.R.color.white, + @ColorRes actionsColor: Int = android.R.color.black + ): UpdateFragment { return UpdateFragment().apply { this.updateInfo = updateInfo this.background = background diff --git a/apklisupdate/src/main/res/layout/apklis_dialog_update.xml b/apklisupdate/src/main/res/layout/apklis_dialog_update.xml index acea8d0..0d564f6 100644 --- a/apklisupdate/src/main/res/layout/apklis_dialog_update.xml +++ b/apklisupdate/src/main/res/layout/apklis_dialog_update.xml @@ -1,68 +1,70 @@ + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:padding="@dimen/default_padding"> + android:id="@+id/logo" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:gravity="center" + android:maxHeight="120dp" + android:scaleType="center" /> + 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" /> + android:id="@+id/changelog" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_margin="8dp" + android:clickable="false" + android:maxHeight="250dp" + tools:text="Bla Bla Bla" /> + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="end" + 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/layout/apklis_fragment_update.xml b/apklisupdate/src/main/res/layout/apklis_fragment_update.xml index 05599d0..45c10be 100644 --- a/apklisupdate/src/main/res/layout/apklis_fragment_update.xml +++ b/apklisupdate/src/main/res/layout/apklis_fragment_update.xml @@ -1,99 +1,83 @@ + 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:orientation="vertical" + android:padding="@dimen/default_padding"> - - - + android:layout_gravity="center" + android:gravity="center" + android:maxHeight="120dp" + android:scaleType="center" /> + 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" /> + android:id="@+id/changelog" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_margin="8dp" + android:maxHeight="250dp" + tools:text="Bla Bla (...) Bla" /> + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="end" + 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/test/kotlin/ApklisUpdateUnitTest.kt b/apklisupdate/src/test/kotlin/ApklisUpdateUnitTest.kt index eb3f513..59b69cc 100644 --- a/apklisupdate/src/test/kotlin/ApklisUpdateUnitTest.kt +++ b/apklisupdate/src/test/kotlin/ApklisUpdateUnitTest.kt @@ -5,13 +5,10 @@ import cu.uci.apklisupdate.ApklisUpdate import cu.uci.apklisupdate.UpdateCallback import cu.uci.apklisupdate.model.AppUpdateInfo import org.amshove.kluent.mock +import org.junit.Assert.assertTrue import org.junit.Test -import org.mockito.Mock import org.mockito.Mockito -import org.junit.Assert.* -import java.lang.Exception - /** * Example local unit test, which will execute on the development machine (host). *