Commit 20e4023c authored by Mygod's avatar Mygod

Clean up

parent 4126b313
......@@ -42,6 +42,7 @@ object ProfileManager {
fun onAdd(profile: Profile)
fun onRemove(profileId: Long)
fun onCleared()
fun reloadProfiles()
}
var listener: Listener? = null
......
......@@ -25,6 +25,7 @@ import android.app.NotificationManager
import android.app.Service
import android.content.Intent
import android.os.IBinder
import android.util.Log
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
......@@ -154,7 +155,11 @@ class SubscriptionService : Service() {
Profile.parseJson(JsonStreamParser(json.bufferedReader()).asSequence().single(), feature) {
subscriptions.computeCompat(it.name to it.formattedAddress) { _, oldProfile ->
when (oldProfile?.subscription) {
Profile.SubscriptionStatus.Active -> oldProfile // skip dup subscription
Profile.SubscriptionStatus.Active -> {
Log.w("SubscriptionService", "Duplicate profiles detected. Please use different profile " +
"names and/or address:port for better subscription support.")
oldProfile
}
Profile.SubscriptionStatus.Obsolete -> {
oldProfile.password = it.password
oldProfile.method = it.method
......@@ -175,6 +180,7 @@ class SubscriptionService : Service() {
}
profiles?.forEach { profile -> if (toUpdate.contains(profile.id)) ProfileManager.updateProfile(profile) }
ProfileManager.listener?.reloadProfiles()
}
override fun onDestroy() {
......
......@@ -431,6 +431,12 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
profiles.clear()
notifyDataSetChanged()
}
override fun reloadProfiles() {
profiles.clear()
ProfileManager.getActiveProfiles()?.let { profiles.addAll(it) }
notifyDataSetChanged()
}
}
private var selectedItem: ProfileViewHolder? = null
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment