Browse Source
On top this fix, this commit adds support for "My content" and "Favorites" instance radios (fixes #51), as well as clearly separates instance radios from user radios. Radios were a bit unusable when not logged in with an actual authorized user account, this commit fixes the following elements: * Anonymous users get a transient session cookie when starting a radio session that was not stored and forwarded on playback, meaning no radios would play; * Anonymous users do not have their own own content. Thus, only the "Random" radio makes sense in that context. This commit only display the instance radios that are relevant to your authentication status. "My content" radios needs the user ID to function properly, this commit also adds retrieving it from the /api/v1/users/users/me/ endpoint, which now may be used in the future for other purposes.housekeeping/remove-warnings
Antoine POPINEAU
4 years ago
13 changed files with 199 additions and 45 deletions
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
package com.github.apognu.otter.utils |
||||
|
||||
import com.github.kittinunf.fuel.Fuel |
||||
import com.github.kittinunf.fuel.coroutines.awaitObjectResponseResult |
||||
import com.github.kittinunf.fuel.gson.gsonDeserializerOf |
||||
import com.github.kittinunf.result.Result |
||||
import com.preference.PowerPreference |
||||
|
||||
object Userinfo { |
||||
suspend fun get(): User? { |
||||
try { |
||||
val hostname = PowerPreference.getFileByName(AppContext.PREFS_CREDENTIALS).getString("hostname") |
||||
val (_, _, result) = Fuel.get("$hostname/api/v1/users/users/me/") |
||||
.authorize() |
||||
.awaitObjectResponseResult(gsonDeserializerOf(User::class.java)) |
||||
|
||||
return when (result) { |
||||
is Result.Success -> { |
||||
val user = result.get() |
||||
|
||||
PowerPreference.getFileByName(AppContext.PREFS_CREDENTIALS).apply { |
||||
setString("actor_username", user.full_username) |
||||
} |
||||
|
||||
user |
||||
} |
||||
|
||||
else -> null |
||||
} |
||||
} catch (e: Exception) { |
||||
return null |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="24dp" |
||||
android:height="24dp" |
||||
android:viewportWidth="24.0" |
||||
android:viewportHeight="24.0"> |
||||
<path |
||||
android:fillColor="#FF000000" |
||||
android:pathData="M20,2L8,2c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM18,7h-3v5.5c0,1.38 -1.12,2.5 -2.5,2.5S10,13.88 10,12.5s1.12,-2.5 2.5,-2.5c0.57,0 1.08,0.19 1.5,0.51L14,5h4v2zM4,6L2,6v14c0,1.1 0.9,2 2,2h14v-2L4,20L4,6z"/> |
||||
</vector> |
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:background="@color/colorPrimary" |
||||
android:padding="8dp"> |
||||
|
||||
<TextView |
||||
android:id="@+id/label" |
||||
style="@style/AppTheme.ListHeader" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" /> |
||||
|
||||
</LinearLayout> |
Loading…
Reference in new issue