Skip to content

Commit

Permalink
rework some code
Browse files Browse the repository at this point in the history
  • Loading branch information
jbdamiano committed Feb 6, 2018
1 parent de78b6f commit beefa66
Show file tree
Hide file tree
Showing 59 changed files with 302 additions and 534 deletions.
14 changes: 7 additions & 7 deletions mainActivity/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
android:label="@string/app_name"
android:theme="@style/Theme.Avactionbar">
<activity
android:name=".MainActivity"
android:name=".activity.MainActivity"
android:theme="@style/AppTheme"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
Expand All @@ -28,24 +28,24 @@
</intent-filter>
</activity>
<activity
android:name=".SettingsActivity"
android:name=".activity.SettingsActivity"
android:theme="@style/AppTheme" />
<activity
android:name=".ObjectConfigureActivity"
android:name=".activity.ObjectConfigureActivity"
android:theme="@style/AppTheme" />
<activity
android:name=".AuthorizationActivity"
android:name=".activity.AuthorizationActivity"
android:configChanges="orientation|screenSize"
android:label="@string/app_name" />
<activity android:name=".TestFragmentActivity" />
<activity android:name=".activity.TestFragmentActivity" />

<service android:name=".service.MonitoringService" />

<meta-data
android:name="io.fabric.ApiKey"
android:value="de8a3057ae740f20f5f7b26850063e7abb9a5cd1" />
android:value="9a96a8b13fb7d66d3faa24132dfc4d1891d1604e" />

<activity android:name=".ObjectDataActivity"
<activity android:name=".activity.ObjectDataActivity"
android:theme="@style/AppTheme"/>
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import android.content.Intent
import android.text.Spanned
import android.view.View
import android.widget.TextView
import android.widget.Toast
import com.sierrawireless.avphone.activity.AuthorizationActivity
import com.sierrawireless.avphone.auth.AuthenticationManager
import com.sierrawireless.avphone.message.IMessageDisplayer
import com.sierrawireless.avphone.task.SyncWithAvListener
import org.jetbrains.anko.toast

abstract class AvPhoneFragment : Fragment(), IMessageDisplayer {

Expand All @@ -36,7 +37,7 @@ abstract class AvPhoneFragment : Fragment(), IMessageDisplayer {

override fun showSuccess(id: Int, vararg params: Any) {
this.hideErrorMessage()
this.toast(id)
this.lToast(id)
}

private fun showErrorMessage(id: Int, vararg params: Any) {
Expand All @@ -59,14 +60,10 @@ abstract class AvPhoneFragment : Fragment(), IMessageDisplayer {
errorMessageView.visibility = View.GONE
}

private fun toast(id: Int) {
private fun lToast(id: Int) {
toast(activity.getString(id))
}

private fun toast(message: String) {
Toast.makeText(activity, message, Toast.LENGTH_SHORT).show()
}

protected fun requestAuthentication() {

val intent = Intent(this.activity, AuthorizationActivity::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView
import android.widget.TextView
import com.baoyz.swipemenulistview.SwipeMenuCreator
import com.baoyz.swipemenulistview.SwipeMenuItem
import com.sierrawireless.avphone.activity.AuthorizationActivity
import com.sierrawireless.avphone.activity.MainActivity
import com.sierrawireless.avphone.activity.ObjectConfigureActivity
import com.sierrawireless.avphone.adapter.ObjectAdapter
import com.sierrawireless.avphone.auth.AuthUtils
import com.sierrawireless.avphone.task.IAsyncTaskFactory
import com.sierrawireless.avphone.task.SyncWithAvParams
import com.sierrawireless.avphone.tools.DeviceInfo
import com.sierrawireless.avphone.tools.Tools
import kotlinx.android.synthetic.main.fragment_configure.*
import net.airvantage.utils.PreferenceUtils
Expand Down Expand Up @@ -104,7 +107,6 @@ open class ConfigureFragment : AvPhoneFragment() {

objectConfigure.onItemClickListener = AdapterView.OnItemClickListener { _, view, i, _ ->
//Open a new intent with the selected Object
Log.d(TAG, "onItemClick: " + i + " " + menu[i])
val intent = Intent(view.context, ObjectConfigureActivity::class.java)
intent.putExtra(INDEX, i)

Expand Down Expand Up @@ -222,7 +224,6 @@ open class ConfigureFragment : AvPhoneFragment() {
syncTask.execute(syncParams)

syncTask.addProgressListener { result ->
Log.d(TAG, "onSynced: ICI")
if (delete) {
objectsManager!!.removeSavedObject()
}
Expand All @@ -238,7 +239,6 @@ open class ConfigureFragment : AvPhoneFragment() {
}

companion object {
private const val TAG = "ConfigureFragment"
var INDEX = "index"
var CONFIGURE = 0
var POS = "position"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.sierrawireless.avphone

import com.sierrawireless.avphone.listener.CustomLabelsListener

interface CustomLabelsManager {
fun setCustomLabelsListener(listener: CustomLabelsListener)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.content.Intent
import android.view.View
import android.widget.ListView
import android.widget.TextView
import com.sierrawireless.avphone.activity.MainActivity
import com.sierrawireless.avphone.adapter.RunListViewAdapter
import com.sierrawireless.avphone.service.LogMessage
import com.sierrawireless.avphone.service.NewData
Expand Down Expand Up @@ -84,8 +85,8 @@ class DataViewUpdater(private val view: View, private val activity: MainActivity
val listPhone = ArrayList<HashMap<String, String>>()

val rssi: String = when {
data.rssi != null -> data.rssi!!.toString() + " dBm (RSSI)"
data.rsrp != null -> data.rsrp!!.toString() + " dBm (RSRP)"
data.rssi != null -> data.rssi!!.toString() + " dBm"
data.rsrp != null -> data.rsrp!!.toString() + " dBm"
else -> "Unknown"
}

Expand Down Expand Up @@ -152,19 +153,16 @@ class DataViewUpdater(private val view: View, private val activity: MainActivity
phoneListView.adapter = adapter
phoneListView.invalidateViews()


setCustomDataValues()

}

private fun setCustomDataValues() {

val objectListView = view.findViewById<ListView>(R.id.objectLstView)
objectsManager = ObjectsManager.getInstance()
val `object` = objectsManager!!.currentObject
val obj = objectsManager!!.currentObject
var temp: HashMap<String, String>
val listObject = ArrayList<HashMap<String, String>>()
for (ldata in `object`!!.datas) {
for (ldata in obj!!.datas) {
temp = HashMap()
temp[Tools.NAME] = ldata.name
if (ldata.isInteger) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,34 @@ import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.crashlytics.android.Crashlytics
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
import com.sierrawireless.avphone.tools.DeviceInfo
import kotlinx.android.synthetic.main.fragment_home.*
import net.airvantage.model.User
import net.airvantage.utils.PreferenceUtils

class HomeFragment : AvPhoneFragment(), IMessageDisplayer {

private val TAG = this::class.java.name
private var lView: View? = null

private var authForSync: Authentication? = null
private var retrySync: Boolean = false



private var taskFactory: IAsyncTaskFactory? = null

private var user: User? = null

private val infoMessageView: TextView
get() = home_info_message

override var errorMessageView: TextView
get() = home_error_message
set(textView) {

}

init {
retrySync = false
taskFactory = null
}

fun setTaskFactory(taskFactory: IAsyncTaskFactory) {
this.taskFactory = taskFactory
if (retrySync) {
Expand All @@ -67,8 +57,7 @@ class HomeFragment : AvPhoneFragment(), IMessageDisplayer {
@SuppressWarnings("deprecation")
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {

this.lView = inflater.inflate(R.layout.fragment_home, container, false)

lView = inflater.inflate(R.layout.fragment_home, container, false)

return lView
}
Expand All @@ -84,16 +73,13 @@ class HomeFragment : AvPhoneFragment(), IMessageDisplayer {
}

login_btn.setOnClickListener { requestAuthentication() }

logout_btn.setOnClickListener { logout() }

if (authManager!!.isLogged) {
showLoggedInState()
} else {
showLoggedOutState()
}


}

override fun onResume() {
Expand All @@ -109,8 +95,6 @@ class HomeFragment : AvPhoneFragment(), IMessageDisplayer {
private fun showCurrentServer() {
val phonePrefs = PreferenceUtils.getAvPhonePrefs(activity)



val message: String
message = when {
phonePrefs.usesNA() -> getString(R.string.logged_on_na)
Expand All @@ -127,7 +111,6 @@ class HomeFragment : AvPhoneFragment(), IMessageDisplayer {
}

private fun hideCurrentServer() {

infoMessageView.visibility = View.GONE
home_login.visibility = View.GONE
infoMessageView.text = ""
Expand Down Expand Up @@ -158,7 +141,6 @@ class HomeFragment : AvPhoneFragment(), IMessageDisplayer {
return
}


val displayer = this
val getUserTask = taskFactory!!.getUserTak(avPhonePrefs.serverHost!!, auth.accessToken!!)

Expand All @@ -172,19 +154,16 @@ class HomeFragment : AvPhoneFragment(), IMessageDisplayer {
showLoggedInState()
user = result.user
user!!.server = avPhonePrefs.serverHost
MainActivity.instance.setUser(user!!)
MainActivity.instance.user = user!!

}
}

val params = GetUserParams()

getUserTask.execute(params)

}

private fun syncWithAv(auth: Authentication?) {

hideErrorMessage()

val avPhonePrefs = PreferenceUtils.getAvPhonePrefs(activity)
Expand Down Expand Up @@ -224,7 +203,6 @@ class HomeFragment : AvPhoneFragment(), IMessageDisplayer {
params.activity = activity as MainActivity

syncAvTask.execute(params)

}

private fun showLoggedInState() {
Expand All @@ -233,12 +211,10 @@ class HomeFragment : AvPhoneFragment(), IMessageDisplayer {
syncGetUser(authManager!!.authentication!!)
} else {
user!!.server = avPhonePrefs.serverHost
MainActivity.instance.setUser(user!!)
MainActivity.instance.user = user!!
}
showCurrentServer()
showLogoutButton()


}

private fun showLoggedOutState() {
Expand All @@ -247,26 +223,23 @@ class HomeFragment : AvPhoneFragment(), IMessageDisplayer {
}

private fun logout() {

val avPhonePrefs = PreferenceUtils.getAvPhonePrefs(activity)

val accessToken = authManager!!.authentication!!.accessToken

val logoutTask = taskFactory!!.logoutTask(avPhonePrefs.serverHost!!, accessToken!!)

logoutTask.execute()

try {
logoutTask.get()
} catch (e: Exception) {
Log.w(LOGTAG, "Exception while logging out")
Log.w(TAG, "Exception while logging out")
Crashlytics.logException(e)
} finally {
authManager!!.forgetAuthentication()

showLoggedOutState()
}

}

private fun showLogoutButton() {
Expand All @@ -281,9 +254,4 @@ class HomeFragment : AvPhoneFragment(), IMessageDisplayer {

home_login_message.visibility = View.VISIBLE
}

companion object {

private val LOGTAG = HomeFragment::class.java.name
}
}

This file was deleted.

Loading

0 comments on commit beefa66

Please sign in to comment.