add simple error notice

This commit is contained in:
Kr328 committed 2019-12-07 06:03:08 +08:00
1 parent adffebadbc
commit 53fa597556
13 files changed
+24 -21

No files matched your search

@@ -3,7 +3,6 @@ package com.github.kr328.clash
import android.os.Bundle
import androidx.preference.PreferenceFragmentCompat
import kotlinx.android.synthetic.main.activity_feedback.*
import kotlinx.android.synthetic.main.activity_main.*
class FeedbackActivity : BaseActivity() {
class Fragment : PreferenceFragmentCompat() {
@@ -11,11 +11,11 @@ import com.github.kr328.clash.model.ClashProfile
import com.github.kr328.clash.service.data.ClashProfileEntity
import com.github.kr328.clash.utils.FileUtils
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.activity_import_file.*
import kotlinx.android.synthetic.main.activity_import_url.*
import java.io.FileOutputStream
import java.lang.Exception
import java.net.*
import java.net.InetSocketAddress
import java.net.Proxy
import java.net.URL
import kotlin.concurrent.thread
class ImportUrlActivity : BaseActivity() {
@@ -5,11 +5,9 @@ import android.os.Handler
import androidx.collection.CircularArray
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.github.kr328.clash.adapter.LogAdapter
import com.github.kr328.clash.core.event.Event
import com.github.kr328.clash.core.event.LogEvent
import com.github.kr328.clash.core.utils.Log
import kotlinx.android.synthetic.main.activity_logs.*
@@ -2,19 +2,15 @@ package com.github.kr328.clash
import android.app.Activity
import android.app.AlertDialog
import android.app.Dialog
import android.content.Context
import android.content.Intent
import android.net.VpnService
import android.os.Build
import android.os.Bundle
import android.view.View
import com.github.kr328.clash.core.event.*
import com.github.kr328.clash.core.model.GeneralPacket
import com.github.kr328.clash.core.utils.ByteFormatter
import com.github.kr328.clash.service.ClashService
import com.github.kr328.clash.service.TunService
import com.github.kr328.clash.utils.ServiceUtils
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.activity_main_clash_status.*
import kotlinx.android.synthetic.main.activity_main_profiles.*
@@ -200,4 +196,8 @@ class MainActivity : BaseActivity() {
private fun showAboutDialog() {
AlertDialog.Builder(this).setView(R.layout.dialog_about).show()
}
override fun onErrorEvent(event: ErrorEvent?) {
Snackbar.make(activity_main_root, event?.message ?: "Unknown", Snackbar.LENGTH_LONG).show()
}
}
@@ -6,22 +6,18 @@ import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.PopupMenu
import androidx.appcompat.view.menu.MenuPopupHelper
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.LinearLayoutManager
import com.charleskorn.kaml.Yaml
import com.charleskorn.kaml.YamlConfiguration
import com.github.kr328.clash.adapter.ProfileAdapter
import com.github.kr328.clash.core.Clash
import com.github.kr328.clash.core.event.ErrorEvent
import com.github.kr328.clash.core.event.ProfileChangedEvent
import com.github.kr328.clash.model.ClashProfile
import com.github.kr328.clash.service.data.ClashProfileEntity
import com.github.kr328.clash.utils.FileUtils
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.activity_import_url.*
import kotlinx.android.synthetic.main.activity_profiles.*
import java.io.FileOutputStream
import java.lang.Exception
import java.net.InetSocketAddress
import java.net.Proxy
import java.net.URL
@@ -201,4 +197,8 @@ class ProfilesActivity : BaseActivity() {
}
}
}
override fun onErrorEvent(event: ErrorEvent?) {
Snackbar.make(activity_profiles_root, event?.message ?: "Unknown", Snackbar.LENGTH_LONG).show()
}
}
@@ -3,9 +3,10 @@ package com.github.kr328.clash
import android.os.Bundle
import com.github.kr328.clash.adapter.ProxyAdapter
import com.github.kr328.clash.callback.IUrlTestCallback
import com.github.kr328.clash.core.event.ErrorEvent
import com.github.kr328.clash.core.model.ProxyPacket
import com.github.kr328.clash.core.utils.Log
import com.github.kr328.clash.model.ListProxy
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.activity_proxies.*
class ProxyActivity : BaseActivity() {
@@ -163,4 +164,8 @@ class ProxyActivity : BaseActivity() {
}
}
}
override fun onErrorEvent(event: ErrorEvent?) {
Snackbar.make(activity_proxies_root, event?.message ?: "Unknown", Snackbar.LENGTH_LONG).show()
}
}
@@ -2,7 +2,6 @@ package com.github.kr328.clash
import android.content.ComponentName
import android.content.Context
import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.os.Bundle
import androidx.preference.CheckBoxPreference
@@ -10,7 +9,6 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import com.github.kr328.clash.core.utils.Log
import kotlinx.android.synthetic.main.activity_setting_application.*
import java.lang.Exception
import kotlin.concurrent.thread
class SettingApplicationActivity : BaseActivity() {
@@ -9,7 +9,6 @@ import androidx.collection.CircularArray
import androidx.recyclerview.widget.RecyclerView
import com.github.kr328.clash.R
import com.github.kr328.clash.core.event.LogEvent
import kotlinx.android.synthetic.main.adapter_log.view.*
import java.text.SimpleDateFormat
import java.util.*
@@ -4,7 +4,6 @@ import android.content.Context
import android.content.Intent
import android.net.VpnService
import android.os.Build
import com.github.kr328.clash.MainActivity
import com.github.kr328.clash.MainApplication
import com.github.kr328.clash.service.ClashService
import com.github.kr328.clash.service.TunService
@@ -2,6 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_proxies_root"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -8,6 +8,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class ErrorEvent(val type: Type, val message: String) : Event, Parcelable {
enum class Type {
PROFILE_LOAD,
START_FAILURE,
QUERY_PROXY_FAILURE,
SET_PROXY_SELECTED
@@ -263,6 +263,7 @@ class ClashService : Service(), IClashEventObserver, ClashEventService.Master,
val active = profileService.queryActiveProfile()
if (active == null) {
eventService.performErrorEvent(ErrorEvent(ErrorEvent.Type.PROFILE_LOAD, "No profile activated"))
clash.process.stop()
return@submit
}
@@ -282,6 +283,7 @@ class ClashService : Service(), IClashEventObserver, ClashEventService.Master,
eventService.performProfileReloadEvent(ProfileReloadEvent())
} catch (e: Exception) {
clash.process.stop()
eventService.performErrorEvent(ErrorEvent(ErrorEvent.Type.PROFILE_LOAD, e.message ?: "Unknown"))
Log.w("Load profile failure", e)
}
}