Skip to content
This repository was archived by the owner on Dec 18, 2022. It is now read-only.

Commit 15a783b

Browse files
committed
implement changes in the Sample App
1 parent dbcc1a6 commit 15a783b

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

sampleapp/src/main/java/io/matthewnelson/sampleapp/App.kt

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ class App: Application() {
163163
stopServiceTimeDelay: Long,
164164
stopServiceOnTaskRemoved: Boolean,
165165
buildConfigDebug: Boolean
166-
) {
167-
TorServiceController.Builder(
166+
): TorServiceController.Builder {
167+
return TorServiceController.Builder(
168168
application = application,
169169
torServiceNotificationBuilder = serviceNotificationBuilder,
170170
backgroundManagerPolicy = backgroundManagerPolicy,
@@ -178,7 +178,6 @@ class App: Application() {
178178
.disableStopServiceOnTaskRemoved(stopServiceOnTaskRemoved)
179179
.setBuildConfigDebug(buildConfigDebug)
180180
.setEventBroadcaster(eventBroadcaster = MyEventBroadcaster())
181-
.build()
182181
}
183182
}
184183

@@ -196,8 +195,8 @@ class App: Application() {
196195

197196
stopTorDelaySettingAtAppStartup = LibraryPrefs.getControllerStopDelaySetting(prefs).toString()
198197

199-
try {
200-
setupTorServices(
198+
199+
val builder = setupTorServices(
201200
this,
202201
serviceNotificationBuilder,
203202
generateBackgroundManagerPolicy(prefs),
@@ -206,20 +205,36 @@ class App: Application() {
206205
LibraryPrefs.getControllerDisableStopServiceOnTaskRemovedSetting(prefs),
207206
LibraryPrefs.getControllerBuildConfigDebugSetting(prefs)
208207
)
209-
210-
TorServiceController.appEventBroadcaster?.let {
211-
(it as MyEventBroadcaster).broadcastLogMessage(
212-
"SampleApp|Application|Process ID: ${Process.myPid()}"
213-
)
214-
}
208+
try {
209+
builder.build()
215210
} catch (e: Exception) {
216211
e.message?.let {
217212
DashboardFragment.showMessage(
218213
DashMessage(
219-
"${DashMessage.EXCEPTION}$it", R.drawable.dash_message_color_red, 5_000
214+
"${DashMessage.EXCEPTION}$it",
215+
R.drawable.dash_message_color_red,
216+
5_000
220217
)
221218
)
222219
}
220+
221+
// Would not normally need any of this, but b/c the sample application allows for
222+
// modifying these settings to show off capabilities, it's necessary.
223+
setupTorServices(
224+
this,
225+
serviceNotificationBuilder,
226+
generateBackgroundManagerPolicy(prefs, BackgroundPolicy.RUN_IN_FOREGROUND, true),
227+
LibraryPrefs.getControllerRestartDelaySetting(prefs),
228+
stopTorDelaySettingAtAppStartup.toLong(),
229+
LibraryPrefs.getControllerDisableStopServiceOnTaskRemovedSetting(prefs),
230+
LibraryPrefs.getControllerBuildConfigDebugSetting(prefs)
231+
).build()
232+
}
233+
234+
TorServiceController.appEventBroadcaster?.let {
235+
(it as MyEventBroadcaster).broadcastLogMessage(
236+
"SampleApp|Application|Process ID: ${Process.myPid()}"
237+
)
223238
}
224239
}
225240
}

sampleapp/src/main/java/io/matthewnelson/sampleapp/ui/fragments/settings/library/SettingsLibraryFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class SettingsLibraryFragment : Fragment() {
152152
controllerOptions.getStopDelayTime(),
153153
controllerOptions.disableStopServiceOnTaskRemoved,
154154
controllerOptions.buildConfigDebug
155-
)
155+
).build()
156156
} catch (e: Exception) {
157157
e.message?.let {
158158
val msg = if (it.contains(BackgroundPolicy.RUN_IN_FOREGROUND))

0 commit comments

Comments
 (0)