From 3750f55ebe8de527aae9dae7d3daa3aa448820f9 Mon Sep 17 00:00:00 2001 From: Jean-bernard Damiano Date: Fri, 9 Mar 2018 15:58:01 +0100 Subject: [PATCH] Fix logout button migration sdk 27 --- mainActivity/build.gradle | 2 +- mainActivity/src/main/AndroidManifest.xml | 2 +- .../sierrawireless/avphone/HomeFragment.kt | 28 ------------------- .../avphone/activity/MainActivity.kt | 16 ++++++----- .../avphone/task/SystemClient.kt | 16 +++++------ .../com/sierrawireless/avphone/tools/Tools.kt | 2 ++ .../net/airvantage/utils/AirVantageClient.kt | 8 +++--- 7 files changed, 25 insertions(+), 49 deletions(-) diff --git a/mainActivity/build.gradle b/mainActivity/build.gradle index cda94f9..6451a40 100644 --- a/mainActivity/build.gradle +++ b/mainActivity/build.gradle @@ -29,7 +29,7 @@ android { applicationId 'com.sierrawireless.avphone' minSdkVersion 22 targetSdkVersion 27 - versionName '2.0.0alpha12' + versionName '2.0.0alpha14' } buildTypes { diff --git a/mainActivity/src/main/AndroidManifest.xml b/mainActivity/src/main/AndroidManifest.xml index f5888b9..f233ad2 100644 --- a/mainActivity/src/main/AndroidManifest.xml +++ b/mainActivity/src/main/AndroidManifest.xml @@ -1,7 +1,7 @@ + android:versionCode="39"> diff --git a/mainActivity/src/main/java/com/sierrawireless/avphone/HomeFragment.kt b/mainActivity/src/main/java/com/sierrawireless/avphone/HomeFragment.kt index dae5752..dca3667 100644 --- a/mainActivity/src/main/java/com/sierrawireless/avphone/HomeFragment.kt +++ b/mainActivity/src/main/java/com/sierrawireless/avphone/HomeFragment.kt @@ -15,7 +15,6 @@ import com.sierrawireless.avphone.activity.MainActivity import com.sierrawireless.avphone.auth.AuthUtils import com.sierrawireless.avphone.auth.Authentication import com.sierrawireless.avphone.message.IMessageDisplayer -import com.sierrawireless.avphone.task.GetUserParams import com.sierrawireless.avphone.task.IAsyncTaskFactory import com.sierrawireless.avphone.task.SyncWithAvListener import com.sierrawireless.avphone.task.SyncWithAvParams @@ -23,7 +22,6 @@ import com.sierrawireless.avphone.tools.DeviceInfo import kotlinx.android.synthetic.main.fragment_home.* import net.airvantage.model.User import net.airvantage.utils.PreferenceUtils -import org.jetbrains.anko.runOnUiThread class HomeFragment : AvPhoneFragment(), IMessageDisplayer { private var lView: View? = null @@ -76,32 +74,12 @@ class HomeFragment : AvPhoneFragment(), IMessageDisplayer { logout_btn.setOnClickListener { logout() } showLoggedOutState() - } override fun onResume() { super.onResume() showLoggedOutState() - - } - - private fun showCurrentServer() { - val phonePrefs = PreferenceUtils.getAvPhonePrefs(activity) - - val message: String - message = when { - phonePrefs.usesNA() -> getString(R.string.logged_on_na) - phonePrefs.usesEU() -> getString(R.string.logged_on_eu) - else -> getString(R.string.logged_on_custom, phonePrefs.serverHost) - } - - infoMessageView?.text = message - infoMessageView?.visibility = View.VISIBLE - if (user != null) { - home_login.text = String.format("%s %s", getString(R.string.welcome), user!!.name) - home_login.visibility = View.VISIBLE - } } private fun hideCurrentServer() { @@ -201,12 +179,6 @@ class HomeFragment : AvPhoneFragment(), IMessageDisplayer { } } - private fun showLogoutButton() { - logout_btn.visibility = View.VISIBLE - login_btn.visibility = View.GONE - home_login_message.visibility = View.GONE - } - private fun hideLogoutButton() { logout_btn.visibility = View.GONE login_btn.visibility = View.VISIBLE diff --git a/mainActivity/src/main/java/com/sierrawireless/avphone/activity/MainActivity.kt b/mainActivity/src/main/java/com/sierrawireless/avphone/activity/MainActivity.kt index 9f45486..3923f18 100644 --- a/mainActivity/src/main/java/com/sierrawireless/avphone/activity/MainActivity.kt +++ b/mainActivity/src/main/java/com/sierrawireless/avphone/activity/MainActivity.kt @@ -708,13 +708,15 @@ class MainActivity : FragmentActivity(), LoginListener, AuthenticationManager, O if (backStackEntry == 0) { val homeFragment = fragmentsMapping[FRAGMENT_LOGIN] - Handler().post({ - fragmentManager - .beginTransaction() - .add(R.id.content_frame, homeFragment) - .addToBackStack("HOME") - .commitAllowingStateLoss() - }) + if (homeFragment != null) { + Handler().post({ + fragmentManager + .beginTransaction() + .add(R.id.content_frame, homeFragment) + .addToBackStack("HOME") + .commitAllowingStateLoss() + }) + } } Handler().post({ diff --git a/mainActivity/src/main/java/com/sierrawireless/avphone/task/SystemClient.kt b/mainActivity/src/main/java/com/sierrawireless/avphone/task/SystemClient.kt index 2b0b3e7..9336143 100644 --- a/mainActivity/src/main/java/com/sierrawireless/avphone/task/SystemClient.kt +++ b/mainActivity/src/main/java/com/sierrawireless/avphone/task/SystemClient.kt @@ -26,17 +26,17 @@ class SystemClient internal constructor(private val client: AirVantageClient) : applicationUid: String, deviceName: String, userName: String, imei: String): net.airvantage.model.AvSystem { val system = net.airvantage.model.AvSystem() - val exist = client.getGateway((serialNumber + "-ANDROID-" + type + "-" + deviceName.replace(" ", "_")).toUpperCase()) + val uid = client.getGateway((serialNumber + "-ANDROID-" + type + "-" + deviceName.replace(" ", "_")).toUpperCase()) val gateway = net.airvantage.model.AvSystem.Gateway() - if (!(exist!!)) { + if (uid == null) { gateway.serialNumber = (serialNumber + "-ANDROID-" + type + "-" + deviceName.replace(" ", "_")).toUpperCase() // gateway.imei = imei + type; gateway.type = type } else { - gateway.serialNumber = (serialNumber + "-ANDROID-" + type + "-" + deviceName.replace(" ", "_")).toUpperCase() + gateway.uid = uid } - system.name = "$deviceName de $userName ($type)" + system.name = Tools.buildSystemName(deviceName, userName, type) system.gateway = gateway @@ -63,17 +63,17 @@ class SystemClient internal constructor(private val client: AirVantageClient) : applicationUid: String, deviceName: String, userName: String, imei: String) { - val exist = client.getGateway((serialNumber + "-ANDROID-" + type + "-" + deviceName.replace(" ", "_")).toUpperCase()) + val uid = client.getGateway((serialNumber + "-ANDROID-" + type + "-" + deviceName.replace(" ", "_")).toUpperCase()) val gateway = net.airvantage.model.AvSystem.Gateway() - if (!(exist!!)) { + if (uid == null) { gateway.serialNumber = (serialNumber + "-ANDROID-" + type + "-" + deviceName.replace(" ", "_")).toUpperCase() // gateway.imei = imei + type; gateway.type = type } else { - gateway.serialNumber = (serialNumber + "-ANDROID-" + type + "-" + deviceName.replace(" ", "_")).toUpperCase() + gateway.uid = uid } - system.name = "$deviceName de $userName ($type)" + system.name = Tools.buildSystemName(deviceName, userName, type) system.gateway = gateway diff --git a/mainActivity/src/main/java/com/sierrawireless/avphone/tools/Tools.kt b/mainActivity/src/main/java/com/sierrawireless/avphone/tools/Tools.kt index 0fd6a76..6053aa7 100644 --- a/mainActivity/src/main/java/com/sierrawireless/avphone/tools/Tools.kt +++ b/mainActivity/src/main/java/com/sierrawireless/avphone/tools/Tools.kt @@ -37,4 +37,6 @@ object Tools { fun buildDefaultPath(name:String, pos:Int):String = name + "." + AvPhoneData.CUSTOM + pos.toString() + fun buildSystemName(deviceName: String, userName: String, type: String) = "$type for $deviceName ($userName)" + } diff --git a/mainActivity/src/main/java/net/airvantage/utils/AirVantageClient.kt b/mainActivity/src/main/java/net/airvantage/utils/AirVantageClient.kt index 4f921b0..17d7d88 100644 --- a/mainActivity/src/main/java/net/airvantage/utils/AirVantageClient.kt +++ b/mainActivity/src/main/java/net/airvantage/utils/AirVantageClient.kt @@ -140,7 +140,7 @@ class AirVantageClient(private val server: String, private val access_token: Str } @Throws(IOException::class, AirVantageException::class) - fun getGateway(serialNumber: String): Boolean? { + fun getGateway(serialNumber: String): String? { val urlString = buildEndpoint("/gateways") val url = URL(urlString) val inputStream = this[url] @@ -161,14 +161,14 @@ class AirVantageClient(private val server: String, private val access_token: Str val entry = jsonValues.getJSONObject(i) val name = entry.getString("serialNumber") if (name == serialNumber) { - return true + return entry.getString("uid") } } } catch (e: JSONException) { - return false + return null } - return false + return null } @Throws(IOException::class, AirVantageException::class)