-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
android: Loader - load early (before service thread) both in activity…
… and service. Loader converted from java to kotlin. Instead of loading libmpd when the service thread is started, the service will not start the the thread if libmpd failed to load. The loader is also accessed by the view data to let the ui adjust if failed to load, by showing the failure reason and disabling the Start MPD button.
- Loading branch information
1 parent
ae1c5e3
commit f1e43cb
Showing
7 changed files
with
155 additions
and
60 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
// Copyright The Music Player Daemon Project | ||
package org.musicpd | ||
|
||
import android.content.Context | ||
import android.os.Build | ||
import android.util.Log | ||
|
||
object Loader { | ||
private const val TAG = "Loader" | ||
|
||
private var loaded: Boolean = false | ||
private var error: String? = null | ||
private val failReason: String get() = error ?: "" | ||
|
||
val isLoaded: Boolean get() = loaded | ||
|
||
init { | ||
load() | ||
} | ||
|
||
private fun load() { | ||
if (loaded) return | ||
loaded = try { | ||
error = null | ||
System.loadLibrary("mpd") | ||
Log.i(TAG, "mpd lib loaded") | ||
true | ||
} catch (e: Throwable) { | ||
error = e.message ?: e.javaClass.simpleName | ||
Log.e(TAG, "failed to load mpd lib: $failReason") | ||
false | ||
} | ||
} | ||
|
||
fun loadFailureMessage(context: Context): String { | ||
return context.getString( | ||
R.string.mpd_load_failure_message, | ||
Build.SUPPORTED_ABIS.joinToString(), | ||
Build.PRODUCT, | ||
Build.FINGERPRINT, | ||
failReason | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<resources> | ||
<string name="app_name">MPD</string> | ||
<string name="notification_title_mpd_running">Music Player Daemon is running</string> | ||
<string name="notification_text_mpd_running">Touch for MPD options.</string> | ||
<string name="toggle_button_run_on">MPD is running</string> | ||
<string name="toggle_button_run_off">MPD is not running</string> | ||
<string name="checkbox_run_on_boot">Run MPD automatically on boot</string> | ||
<string name="checkbox_wakelock">Prevent suspend when MPD is running (Wakelock)</string> | ||
<string name="checkbox_pause_on_headphones_disconnect">Pause MPD when headphones disconnect</string> | ||
<string name="external_files_permission_request">MPD requires access to external files to play local music. Please grant the permission.</string> | ||
<string name="title_open_app_info">Open app info</string> | ||
<string name="app_name">MPD</string> | ||
<string name="notification_title_mpd_running">Music Player Daemon is running</string> | ||
<string name="notification_text_mpd_running">Touch for MPD options.</string> | ||
<string name="toggle_button_run_on">MPD is running</string> | ||
<string name="toggle_button_run_off">MPD is not running</string> | ||
<string name="checkbox_run_on_boot">Run MPD automatically on boot</string> | ||
<string name="checkbox_wakelock">Prevent suspend when MPD is running (Wakelock)</string> | ||
<string name="checkbox_pause_on_headphones_disconnect">Pause MPD when headphones disconnect</string> | ||
<string name="external_files_permission_request">MPD requires access to external files to play local music. Please grant the permission.</string> | ||
<string name="title_open_app_info">Open app info</string> | ||
<string name="mpd_load_failure_message">"Failed to load the native MPD library. | ||
Report this problem to us, and include the following information: | ||
SUPPORTED_ABIS=%1$s | ||
PRODUCT=%2$s | ||
FINGERPRINT=%3$s | ||
error=%4$s" | ||
</string> | ||
<string name="stopped">Stopped</string> | ||
<string name="running">Running</string> | ||
<string name="stopMPD">Stop MPD</string> | ||
<string name="startMPD">Start MPD</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<style name="Theme.MPD" parent="android:Theme.Material.Light.NoActionBar" /> | ||
<color name="red_500">#F44336</color> | ||
<color name="red_900">#B71C1C</color> | ||
<color name="green_300">#81C784</color> | ||
<color name="green_700">#388E3C</color> | ||
|
||
<color name="colorErrorOnLight">@color/red_900</color> | ||
<color name="colorErrorOnDark">@color/red_500</color> | ||
|
||
<color name="colorSuccessOnLight">@color/green_700</color> | ||
<color name="colorSuccessOnDark">@color/green_300</color> | ||
|
||
<attr name="appColorNegative" format="color|reference" /> | ||
<attr name="appColorPositive" format="color|reference" /> | ||
|
||
<style name="Theme.MPD" parent="android:Theme.Material.Light.NoActionBar"> | ||
<item name="appColorNegative">@color/colorErrorOnLight</item> | ||
<item name="appColorPositive">@color/colorSuccessOnLight</item> | ||
</style> | ||
</resources> |