Commit 20e4023c authored by Mygod's avatar Mygod

Clean up

parent 4126b313
...@@ -42,6 +42,7 @@ object ProfileManager { ...@@ -42,6 +42,7 @@ object ProfileManager {
fun onAdd(profile: Profile) fun onAdd(profile: Profile)
fun onRemove(profileId: Long) fun onRemove(profileId: Long)
fun onCleared() fun onCleared()
fun reloadProfiles()
} }
var listener: Listener? = null var listener: Listener? = null
......
...@@ -25,6 +25,7 @@ import android.app.NotificationManager ...@@ -25,6 +25,7 @@ import android.app.NotificationManager
import android.app.Service import android.app.Service
import android.content.Intent import android.content.Intent
import android.os.IBinder import android.os.IBinder
import android.util.Log
import android.widget.Toast import android.widget.Toast
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
...@@ -154,7 +155,11 @@ class SubscriptionService : Service() { ...@@ -154,7 +155,11 @@ class SubscriptionService : Service() {
Profile.parseJson(JsonStreamParser(json.bufferedReader()).asSequence().single(), feature) { Profile.parseJson(JsonStreamParser(json.bufferedReader()).asSequence().single(), feature) {
subscriptions.computeCompat(it.name to it.formattedAddress) { _, oldProfile -> subscriptions.computeCompat(it.name to it.formattedAddress) { _, oldProfile ->
when (oldProfile?.subscription) { 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 -> { Profile.SubscriptionStatus.Obsolete -> {
oldProfile.password = it.password oldProfile.password = it.password
oldProfile.method = it.method oldProfile.method = it.method
...@@ -175,6 +180,7 @@ class SubscriptionService : Service() { ...@@ -175,6 +180,7 @@ class SubscriptionService : Service() {
} }
profiles?.forEach { profile -> if (toUpdate.contains(profile.id)) ProfileManager.updateProfile(profile) } profiles?.forEach { profile -> if (toUpdate.contains(profile.id)) ProfileManager.updateProfile(profile) }
ProfileManager.listener?.reloadProfiles()
} }
override fun onDestroy() { override fun onDestroy() {
......
...@@ -431,6 +431,12 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener { ...@@ -431,6 +431,12 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
profiles.clear() profiles.clear()
notifyDataSetChanged() notifyDataSetChanged()
} }
override fun reloadProfiles() {
profiles.clear()
ProfileManager.getActiveProfiles()?.let { profiles.addAll(it) }
notifyDataSetChanged()
}
} }
private var selectedItem: ProfileViewHolder? = null 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