Add menu on topbar
This commit is contained in:
@@ -13,6 +13,7 @@ object ManagerSingleton {
|
|||||||
var videosCount: Int = 0
|
var videosCount: Int = 0
|
||||||
lateinit var settings: SharedPreferences
|
lateinit var settings: SharedPreferences
|
||||||
lateinit var db: Database
|
lateinit var db: Database
|
||||||
|
|
||||||
fun toast(text: String?, context: Context) {
|
fun toast(text: String?, context: Context) {
|
||||||
android.widget.Toast.makeText(context, text, android.widget.Toast.LENGTH_SHORT).show()
|
android.widget.Toast.makeText(context, text, android.widget.Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
@@ -21,6 +22,8 @@ object ManagerSingleton {
|
|||||||
db.logout()
|
db.logout()
|
||||||
user = UserModel()
|
user = UserModel()
|
||||||
token = TokenModel()
|
token = TokenModel()
|
||||||
|
|
||||||
|
// TODO: Close the session in the user instance
|
||||||
}
|
}
|
||||||
|
|
||||||
fun reloadSettings() {
|
fun reloadSettings() {
|
||||||
@@ -36,4 +39,8 @@ object ManagerSingleton {
|
|||||||
nfsw = settings.getBoolean("show_nsfw", false)
|
nfsw = settings.getBoolean("show_nsfw", false)
|
||||||
videosCount = settings.getString("videos_count", "15")!!.toInt()
|
videosCount = settings.getString("videos_count", "15")!!.toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isLogged (): Boolean {
|
||||||
|
return token.token !== ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,12 +28,12 @@ fun MainNavigationBar () {
|
|||||||
selected = false,
|
selected = false,
|
||||||
onClick = {}
|
onClick = {}
|
||||||
)
|
)
|
||||||
NavigationBarItem(
|
// NavigationBarItem(
|
||||||
icon = { Icon(painterResource(R.drawable.ic_menu_slideshow), "home") },
|
// icon = { Icon(painterResource(R.drawable.ic_menu_slideshow), "home") },
|
||||||
label = { Text(stringResource(R.string.playlists), fontSize = 11.sp) },
|
// label = { Text(stringResource(R.string.playlists), fontSize = 11.sp) },
|
||||||
selected = false,
|
// selected = false,
|
||||||
onClick = {}
|
// onClick = {}
|
||||||
)
|
// )
|
||||||
NavigationBarItem(
|
NavigationBarItem(
|
||||||
icon = { Icon(Icons.Filled.AccountCircle, "home") },
|
icon = { Icon(Icons.Filled.AccountCircle, "home") },
|
||||||
label = { Text(stringResource(R.string.you), fontSize = 11.sp) },
|
label = { Text(stringResource(R.string.you), fontSize = 11.sp) },
|
||||||
|
@@ -1,31 +1,72 @@
|
|||||||
package org.libre.agosto.p2play.components
|
package org.libre.agosto.p2play.components
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.MoreVert
|
import androidx.compose.material.icons.filled.MoreVert
|
||||||
import androidx.compose.material.icons.filled.Notifications
|
import androidx.compose.material.icons.filled.Notifications
|
||||||
import androidx.compose.material.icons.filled.Search
|
import androidx.compose.material.icons.filled.Search
|
||||||
|
import androidx.compose.material3.DropdownMenu
|
||||||
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TopAppBar
|
import androidx.compose.material3.TopAppBar
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import org.libre.agosto.p2play.AboutActivity
|
||||||
|
import org.libre.agosto.p2play.ChannelActivity
|
||||||
|
import org.libre.agosto.p2play.LoginActivity
|
||||||
|
import org.libre.agosto.p2play.ManagerSingleton
|
||||||
import org.libre.agosto.p2play.R
|
import org.libre.agosto.p2play.R
|
||||||
|
import org.libre.agosto.p2play.SettingsActivity2
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Preview(showSystemUi = true)
|
@Preview(showSystemUi = true)
|
||||||
@Composable
|
@Composable
|
||||||
fun MainTopAppBar(modifier: Modifier = Modifier) {
|
fun MainTopAppBar(modifier: Modifier = Modifier) {
|
||||||
|
var isMenuOpen by remember { mutableStateOf(false) }
|
||||||
|
val context = LocalContext.current
|
||||||
TopAppBar(
|
TopAppBar(
|
||||||
{ Text(stringResource(R.string.nav_menu_videos)) },
|
{ Text(stringResource(R.string.nav_menu_videos)) },
|
||||||
modifier,
|
modifier,
|
||||||
actions = {
|
actions = {
|
||||||
IconButton({}) { Icon(Icons.Default.Search, "More") }
|
IconButton({}) { Icon(Icons.Default.Search, "More") }
|
||||||
IconButton({}) { Icon(Icons.Default.Notifications, "More") }
|
// IconButton({}) { Icon(Icons.Default.Notifications, "More") }
|
||||||
IconButton({}) { Icon(Icons.Default.MoreVert, "More") }
|
IconButton({ isMenuOpen = true }) {
|
||||||
|
Icon(Icons.Default.MoreVert, "More")
|
||||||
|
DropdownMenu(isMenuOpen, { isMenuOpen = false }) {
|
||||||
|
if (ManagerSingleton.isLogged()) {
|
||||||
|
DropdownMenuItem({ Text(stringResource(R.string.action_logout))}, {
|
||||||
|
isMenuOpen = false
|
||||||
|
ManagerSingleton.logout()
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
DropdownMenuItem({ Text(stringResource(R.string.action_login))}, {
|
||||||
|
isMenuOpen = false
|
||||||
|
val intent = Intent(context, LoginActivity::class.java)
|
||||||
|
context.startActivity(intent)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
DropdownMenuItem({ Text(stringResource(R.string.action_settings))}, {
|
||||||
|
isMenuOpen = false
|
||||||
|
val intent = Intent(context, SettingsActivity2::class.java)
|
||||||
|
context.startActivity(intent)
|
||||||
|
})
|
||||||
|
DropdownMenuItem({ Text(stringResource(R.string.nav_about))}, {
|
||||||
|
isMenuOpen = false
|
||||||
|
val intent = Intent(context, AboutActivity::class.java)
|
||||||
|
context.startActivity(intent)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
Reference in New Issue
Block a user