mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-17 04:00:39 +01:00
Implement server feature checking
This commit is contained in:
parent
cebbb39caf
commit
1b7f48c53a
@ -359,6 +359,20 @@ public class Util
|
||||
return Math.min(Math.max(percent,0),100) + " %";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Mark depending on boolean (❌ or ✓)
|
||||
*
|
||||
* @param value Is true or false
|
||||
* @return The corresponding mark.
|
||||
*/
|
||||
public static synchronized String boolToMark(boolean value)
|
||||
{
|
||||
if (value)
|
||||
return "✔️";
|
||||
else
|
||||
return "❌";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts a byte-count to a formatted string suitable for display to the user.
|
||||
@ -606,6 +620,18 @@ public class Util
|
||||
}).show();
|
||||
}
|
||||
|
||||
public static void showDialog(Context context, int icon, int titleId, String message)
|
||||
{
|
||||
new AlertDialog.Builder(context).setIcon(icon).setTitle(titleId).setMessage(message).setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int i)
|
||||
{
|
||||
dialog.dismiss();
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
|
||||
|
||||
public static void sleepQuietly(long millis)
|
||||
{
|
||||
|
@ -29,7 +29,9 @@ import androidx.preference.PreferenceManager
|
||||
import com.google.android.material.navigation.NavigationView
|
||||
import org.koin.android.ext.android.inject
|
||||
import org.koin.android.viewmodel.ext.android.viewModel
|
||||
import org.koin.java.KoinJavaComponent.inject
|
||||
import org.moire.ultrasonic.R
|
||||
import org.moire.ultrasonic.data.ActiveServerProvider
|
||||
import org.moire.ultrasonic.data.ActiveServerProvider.Companion.isOffline
|
||||
import org.moire.ultrasonic.domain.PlayerState
|
||||
import org.moire.ultrasonic.fragment.OnBackPressedHandler
|
||||
@ -368,10 +370,18 @@ class NavigationActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun setMenuForServerSetting() {
|
||||
val visibility = !isOffline()
|
||||
chatMenuItem?.isVisible = visibility
|
||||
bookmarksMenuItem?.isVisible = visibility
|
||||
sharesMenuItem?.isVisible = visibility
|
||||
podcastsMenuItem?.isVisible = visibility
|
||||
if (isOffline())
|
||||
{
|
||||
chatMenuItem?.isVisible = false
|
||||
bookmarksMenuItem?.isVisible = false
|
||||
sharesMenuItem?.isVisible = false
|
||||
podcastsMenuItem?.isVisible = false
|
||||
return
|
||||
}
|
||||
val activeServerProvider = inject(ActiveServerProvider::class.java)
|
||||
chatMenuItem?.isVisible = activeServerProvider.value.getActiveServer().chatSupport
|
||||
bookmarksMenuItem?.isVisible = activeServerProvider.value.getActiveServer().bookmarkSupport
|
||||
sharesMenuItem?.isVisible = activeServerProvider.value.getActiveServer().shareSupport
|
||||
podcastsMenuItem?.isVisible = activeServerProvider.value.getActiveServer().podcastSupport
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
/**
|
||||
* Room Database to be used to store data for Ultrasonic
|
||||
*/
|
||||
@Database(entities = [ServerSetting::class], version = 2)
|
||||
@Database(entities = [ServerSetting::class], version = 3)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
|
||||
/**
|
||||
@ -24,3 +24,12 @@ val MIGRATION_1_2: Migration = object : Migration(1, 2) {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val MIGRATION_2_3: Migration = object : Migration(2, 3) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE ServerSetting ADD COLUMN chatSupport INTEGER NOT NULL DEFAULT(1)")
|
||||
database.execSQL("ALTER TABLE ServerSetting ADD COLUMN bookmarkSupport INTEGER NOT NULL DEFAULT(1)")
|
||||
database.execSQL("ALTER TABLE ServerSetting ADD COLUMN shareSupport INTEGER NOT NULL DEFAULT(1)")
|
||||
database.execSQL("ALTER TABLE ServerSetting ADD COLUMN podcastSupport INTEGER NOT NULL DEFAULT(1)")
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,11 @@ data class ServerSetting(
|
||||
@ColumnInfo(name = "allowSelfSignedCertificate") var allowSelfSignedCertificate: Boolean,
|
||||
@ColumnInfo(name = "ldapSupport") var ldapSupport: Boolean,
|
||||
@ColumnInfo(name = "musicFolderId") var musicFolderId: String?,
|
||||
@ColumnInfo(name = "minimumApiVersion") var minimumApiVersion: String?
|
||||
@ColumnInfo(name = "minimumApiVersion") var minimumApiVersion: String?,
|
||||
@ColumnInfo(name = "chatSupport") var chatSupport: Boolean = true,
|
||||
@ColumnInfo(name = "bookmarkSupport") var bookmarkSupport: Boolean = true,
|
||||
@ColumnInfo(name = "shareSupport") var shareSupport: Boolean = true,
|
||||
@ColumnInfo(name = "podcastSupport") var podcastSupport: Boolean = true
|
||||
) {
|
||||
constructor() : this (
|
||||
-1, 0, "", "", "", "", false, false, false, null, null
|
||||
|
@ -7,6 +7,7 @@ import org.koin.core.qualifier.named
|
||||
import org.koin.dsl.module
|
||||
import org.moire.ultrasonic.data.AppDatabase
|
||||
import org.moire.ultrasonic.data.MIGRATION_1_2
|
||||
import org.moire.ultrasonic.data.MIGRATION_2_3
|
||||
import org.moire.ultrasonic.fragment.ServerSettingsModel
|
||||
import org.moire.ultrasonic.util.Util
|
||||
|
||||
@ -24,7 +25,8 @@ val appPermanentStorage = module {
|
||||
AppDatabase::class.java,
|
||||
"ultrasonic-database"
|
||||
)
|
||||
.addMigrations(MIGRATION_1_2)
|
||||
.addMigrations(MIGRATION_1_2)
|
||||
.addMigrations(MIGRATION_2_3)
|
||||
.fallbackToDestructiveMigrationOnDowngrade()
|
||||
.build()
|
||||
}
|
||||
|
@ -295,14 +295,22 @@ class EditServerFragment : Fragment(), OnBackPressedHandler {
|
||||
* Tests if the network connection to the entered Server Settings can be made
|
||||
*/
|
||||
private fun testConnection() {
|
||||
val task: ModalBackgroundTask<Boolean> = object : ModalBackgroundTask<Boolean>(
|
||||
val task: ModalBackgroundTask<String> = object : ModalBackgroundTask<String>(
|
||||
activity,
|
||||
false
|
||||
) {
|
||||
|
||||
@Throws(Throwable::class)
|
||||
override fun doInBackground(): Boolean {
|
||||
updateProgress(R.string.settings_testing_connection)
|
||||
override fun doInBackground(): String {
|
||||
|
||||
var progressString = """
|
||||
|%s - ${activity.resources.getString(R.string.button_bar_chat)}
|
||||
|%s - ${activity.resources.getString(R.string.button_bar_bookmarks)}
|
||||
|%s - ${activity.resources.getString(R.string.button_bar_shares)}
|
||||
|%s - ${activity.resources.getString(R.string.button_bar_podcasts)}
|
||||
""".trimMargin()
|
||||
updateProgress(String.format(progressString, "⌛", "⌛", "⌛", "⌛"))
|
||||
|
||||
val configuration = SubsonicClientConfiguration(
|
||||
currentServerSetting!!.url,
|
||||
currentServerSetting!!.userName,
|
||||
@ -330,17 +338,65 @@ class EditServerFragment : Fragment(), OnBackPressedHandler {
|
||||
pingResponse = subsonicApiClient.api.ping().execute()
|
||||
ApiCallResponseChecker.checkResponseSuccessful(pingResponse)
|
||||
|
||||
updateProgress(String.format(progressString, "⌛", "⌛", "⌛", "⌛"))
|
||||
|
||||
currentServerSetting!!.chatSupport = try {
|
||||
subsonicApiClient.api.getChatMessages().execute()
|
||||
true
|
||||
} catch (e: Throwable) { false }
|
||||
|
||||
updateProgress(String.format(progressString,
|
||||
Util.boolToMark(currentServerSetting!!.chatSupport),
|
||||
"⌛", "⌛", "⌛"))
|
||||
|
||||
currentServerSetting!!.bookmarkSupport = try {
|
||||
subsonicApiClient.api.getBookmarks().execute()
|
||||
true
|
||||
} catch (e: Throwable) { false }
|
||||
|
||||
updateProgress(String.format(progressString,
|
||||
Util.boolToMark(currentServerSetting!!.chatSupport),
|
||||
Util.boolToMark(currentServerSetting!!.bookmarkSupport),
|
||||
"⌛", "⌛"))
|
||||
|
||||
currentServerSetting!!.shareSupport = try {
|
||||
subsonicApiClient.api.getShares().execute()
|
||||
true
|
||||
} catch (e: Throwable) { false }
|
||||
|
||||
updateProgress(String.format(progressString,
|
||||
Util.boolToMark(currentServerSetting!!.chatSupport),
|
||||
Util.boolToMark(currentServerSetting!!.bookmarkSupport),
|
||||
Util.boolToMark(currentServerSetting!!.shareSupport),
|
||||
"⌛"))
|
||||
|
||||
currentServerSetting!!.podcastSupport = try {
|
||||
subsonicApiClient.api.getPodcasts().execute()
|
||||
true
|
||||
} catch (e: Throwable) { false }
|
||||
|
||||
// Finalize String before displaying it to Dialog
|
||||
progressString = String.format(progressString,
|
||||
Util.boolToMark(currentServerSetting!!.chatSupport),
|
||||
Util.boolToMark(currentServerSetting!!.bookmarkSupport),
|
||||
Util.boolToMark(currentServerSetting!!.shareSupport),
|
||||
Util.boolToMark(currentServerSetting!!.podcastSupport))
|
||||
updateProgress(progressString)
|
||||
|
||||
val licenseResponse = subsonicApiClient.api.getLicense().execute()
|
||||
ApiCallResponseChecker.checkResponseSuccessful(licenseResponse)
|
||||
return licenseResponse.body()!!.license.valid
|
||||
if (!licenseResponse.body()!!.license.valid) {
|
||||
progressString += "\n${activity.resources.getString(R.string.settings_testing_unlicensed)}"
|
||||
}
|
||||
return progressString
|
||||
}
|
||||
|
||||
override fun done(licenseValid: Boolean) {
|
||||
if (licenseValid) {
|
||||
Util.toast(activity, R.string.settings_testing_ok)
|
||||
} else {
|
||||
Util.toast(activity, R.string.settings_testing_unlicensed)
|
||||
}
|
||||
override fun done(responseString: String) {
|
||||
Util.showDialog(
|
||||
activity,
|
||||
android.R.drawable.ic_dialog_info,
|
||||
R.string.settings_testing_ok,
|
||||
responseString)
|
||||
}
|
||||
|
||||
override fun error(error: Throwable) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user