Move callback method to ToolbarFragment
This commit is contained in:
@@ -43,9 +43,6 @@ libraryDependencies ++=
|
||||
"com.google.android.gms" % "play-services-gcm" % "10.0.1" ::
|
||||
"com.j256.ormlite" % "ormlite-android" % "5.0" ::
|
||||
"com.mikepenz" % "materialdrawer" % "5.8.1" ::
|
||||
"com.mikepenz" % "materialize" % "1.0.0" ::
|
||||
"com.mikepenz" % "iconics-core" % "2.8.0" ::
|
||||
"com.mikepenz" % "fastadapter" % "2.1.0" ::
|
||||
"com.twofortyfouram" % "android-plugin-api-for-locale" % "1.0.2" ::
|
||||
"dnsjava" % "dnsjava" % "2.1.7" ::
|
||||
"eu.chainfire" % "libsuperuser" % "1.0.0.201608240809" ::
|
||||
|
||||
@@ -51,10 +51,6 @@ import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem
|
||||
import com.mikepenz.materialdrawer.model.{PrimaryDrawerItem, SecondaryDrawerItem}
|
||||
import com.mikepenz.materialdrawer.{Drawer, DrawerBuilder}
|
||||
|
||||
trait TrafficCallback {
|
||||
def update(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long)
|
||||
}
|
||||
|
||||
object MainActivity {
|
||||
private final val TAG = "ShadowsocksMainActivity"
|
||||
private final val REQUEST_CONNECT = 1
|
||||
@@ -77,8 +73,6 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
|
||||
var currentProfile = new Profile
|
||||
var drawer: Drawer = _
|
||||
|
||||
@volatile var trafficCallback: TrafficCallback = _
|
||||
|
||||
private lazy val profilesFragment = new ProfilesFragment()
|
||||
private lazy val globalSettingsFragment = new GlobalSettingsFragment()
|
||||
|
||||
@@ -140,7 +134,8 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
|
||||
rxText.setText(TrafficMonitor.formatTraffic(rxTotal))
|
||||
txRateText.setText(TrafficMonitor.formatTraffic(txRate) + "/s")
|
||||
rxRateText.setText(TrafficMonitor.formatTraffic(rxRate) + "/s")
|
||||
if (trafficCallback != null) trafficCallback.update(txRate, rxRate, txTotal, rxTotal)
|
||||
val child = getFragmentManager.findFragmentById(R.id.content).asInstanceOf[ToolbarFragment]
|
||||
if (child != null) child.onTrafficUpdated(txRate, rxRate, txTotal, rxTotal)
|
||||
}
|
||||
|
||||
def attachServiceCallback(): Unit = attachService(callback)
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
package com.github.shadowsocks
|
||||
|
||||
import android.app.Activity
|
||||
import android.content._
|
||||
import android.graphics.Typeface
|
||||
import android.os.{Build, Bundle, Handler, UserManager}
|
||||
@@ -33,7 +32,6 @@ import android.support.v7.widget.helper.ItemTouchHelper.SimpleCallback
|
||||
import android.view._
|
||||
import android.widget.{TextView, Toast}
|
||||
import com.github.shadowsocks.ShadowsocksApplication.app
|
||||
import com.github.shadowsocks.aidl.IShadowsocksServiceCallback
|
||||
import com.github.shadowsocks.database.Profile
|
||||
import com.github.shadowsocks.utils.{Action, Parser, TrafficMonitor, Utils}
|
||||
import com.github.shadowsocks.widget.UndoSnackbarManager
|
||||
@@ -214,24 +212,10 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene
|
||||
LocalBroadcastManager.getInstance(getActivity).registerReceiver(profilesListener, filter)
|
||||
}
|
||||
|
||||
override def onAttach(activity: Activity) {
|
||||
super.onAttach(activity)
|
||||
activity.asInstanceOf[MainActivity].trafficCallback = new TrafficCallback {
|
||||
def update(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long): Unit =
|
||||
if (selectedItem != null) selectedItem.updateText(txTotal, rxTotal)
|
||||
}
|
||||
}
|
||||
|
||||
override def onStart() {
|
||||
super.onStart()
|
||||
}
|
||||
|
||||
override def onStop() {
|
||||
super.onStop()
|
||||
}
|
||||
override def onTrafficUpdated(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long): Unit =
|
||||
if (selectedItem != null) selectedItem.updateText(txTotal, rxTotal)
|
||||
|
||||
override def onDetach() {
|
||||
getActivity.asInstanceOf[MainActivity].trafficCallback = null
|
||||
undoManager.flush()
|
||||
super.onDetach()
|
||||
}
|
||||
|
||||
@@ -14,4 +14,6 @@ class ToolbarFragment extends Fragment {
|
||||
val activity = getActivity.asInstanceOf[MainActivity]
|
||||
activity.drawer.setToolbar(activity, toolbar, true)
|
||||
}
|
||||
|
||||
def onTrafficUpdated(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long): Unit = ()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user