Ana içeriğe atla
Altbilgiye atla
Ara
Oturum açın
Tam ekran izle
Beğen
Yorumlar
Yer işareti ekle
Paylaş
Çalma Listesine ekle
Bildir
47 - Adjust App Flow and Layout
Mustafa Demirhan
Takip Et
02.09.2024
Kategori
📚
Öğrenme
Döküm
Tüm video dökümünü görüntüle
00:00
Alright guys so let us use this section to modify our user interface with a bit
00:07
more purpose right so far we have our loading page we created a login page we
00:12
know that it works and we can navigate to the main page however what we would
00:18
want to do is probably simulate if you were in one role what you would see if
00:23
you were in another role what would you see because a lot of the times that's
00:27
the situation with mobile apps right or even if it's good to know how we could
00:33
accomplish that so what we want to do is modify what we'll call the fly out item
00:38
so we had modified the file behavior earlier where we change this from
00:42
disabled to fly out and then we have the shell contents the default item is whole
00:49
well it says home we can always change that and the content template is the
00:54
loading page right so that means that you are going to get a default menu
01:00
item called home but that will go to the loading page what happens is that the
01:06
fly out items would be what you get when you tap the pill menu or the pill
01:12
navigation in the top left hand corner of most mobile apps when you tap that
01:16
and it kind of flies out to show you what the menu items are that's what we
01:19
call the fly out item right and then you have you have the ability to set a
01:25
header which is more static and then a footer which is also more static right
01:31
so so far we've only been playing with the body section so what we're going to
01:35
do here is create a new control first of all so I'm going to go ahead and add a
01:43
new item a new folder first and we'll call it controls then we can add a new
01:49
item and the thing is that you can always create the controls and then plug
01:54
it in versus doing it all from C sharp we're actually going to look at how we
01:59
do both of them so I'm going to create a new content view and I'm going to call
02:04
it fly out header so we have the fly out header and I actually want this to be a
02:13
stack stack layout so I'm going to change that here and if I change that
02:19
there I have to change the inheritance over here to stack layout so that's fine
02:24
alright so let us go back to that because I have some things that I need
02:33
to accomplish code wise so I'm going to add another folder I'm just going to
02:36
call this one helpers right and then in this I'm going to create a new class
02:43
which is just going to be a menu builder that's all I'm calling it menu builder
02:50
and this is going to be a public static class so menu builder is going to be in
02:55
charge of you know putting together the menu items based on the role and
03:01
whatever other stipulations we might need right so menu builder is going to
03:09
have method that I'm going to call of course it's going to be a public let's
03:15
make it async it's going to be static it's going to be a task well let me get
03:20
my spelling right task and I'm going to say build menus or build menu because
03:27
we only have one menu so build menu or we'll only build one at a time rather so
03:32
build menu and then from build menu what are we going to be doing I'm going to
03:38
first set the fly out header so I can say shell dot current dot fly out header
03:49
fly out header is equal to a new instance of our fly out header that we
03:58
just created so we're going to of course fly out header not behavior fly out
04:07
header include the missing using reference so we're going to of course
04:12
define what the fly out header looks like in its design and stuff but I'm
04:17
just walking it through the code first so when we say build menu which we're
04:22
probably going to do most likely after the app after the user has authenticated
04:29
then we're going to say build menu then we're going to add the menu header and
04:37
well let me actually start off by clearing anything that might be in the
04:47
shell current item so shell current item so this is where all those fly out items
04:52
get added right so I'm just going to clear it so any menu that might have
04:56
been there clear it and let's start from scratch so we can always go now and
05:02
proceed to get the details of the user now from the app remember that we had
05:09
created user info and user info tells me the username and I also added the role
05:15
right so I can say var role is equal to whatever value is currently stored in
05:24
role then I can say if role is equal to and then let's try administrator once
05:35
again you probably want to abstract these magic strings to like constant
05:39
classes or enums or something but I'm just keeping it simple enough for now we
05:45
can say else if role dot equals user and then you can have as many of those
05:56
as you want right also in the case where you might have multiple rules you
06:02
probably don't even want to use an else if so if the user might be in both
06:06
administrator and user you could probably consider just doing if if if so
06:12
all we do is add fly out items per role right so I'm just giving you ideas of
06:18
course in our situation we know you're either user or administrator but in some
06:22
situations you might be a user and a supervisor so you need access to both
06:27
when they log in so that's I'll defer that to you so let us know decide if the
06:34
person is an administrator what do we do so we can say var and I'm just going to
06:38
say fly out fly out item is equal to a new fly out item so we can in code
06:49
create our own fly out items all right and then what would have is a title so
06:57
title would be equal to let's say car management and I'm going to do the same
07:04
I'm going to do the same fly out item for both but I'm going to name them
07:08
differently so that you can see that you know it's you can make your app as
07:13
dynamic as you need it to because we really only have one place to go anyway
07:16
so the root here is going to be name of and main page because we don't have
07:24
anywhere else to go really based on the design of our app right but of course as
07:29
many pages as you might have and you want them to be navigated to you add the
07:34
root accordingly then fly out display option here it is going to be fly out
07:41
options which is an enum and I'll say as multiple items right so after that we
07:48
can define the items so items would be equal to and this just takes an object
07:55
that has let's say a list of shell content objects so we'll say shell new
08:03
shell content and then we can have as many shell content objects as we need to
08:11
afterwards alright so I'm just going to once again I'm kind of simulating what
08:17
it might look like we can add an icon right so icon would be equal to and then
08:25
pretty much you just define the name of the icon so if you had additional
08:30
resources and additional images so I don't have any additional images but
08:36
let's just say that we wanted the dotnet bot it's a dotnet underscore bot dot SVG
08:43
that's the icon that I would want for argument's sake right so we could do
08:49
that we could say the title here would be admin page one and then the content
08:59
template would be we specify a data template that takes a type so type off
09:10
and then whatever page this should be associated with so type off and in this
09:17
case I'll just use this main page again because we don't have anywhere else to
09:21
go so that's pretty much what the shell content would look like so I am just
09:25
going to duplicate this and call this admin page two let me fix the spelling
09:31
of admin all right and we have too many items for admin and that's that's pretty
09:40
much it I know we have items and then we can close this with an if with a
09:46
semicolon so that's if you're in the admin role then this is what you should
09:51
have new fly out item with all of that so now that we've compiled or fly out
09:58
item I'm going to know have to add it so I'm going to say something like shell
10:03
dot current dot items I can check if it's there before or I can just add it
10:14
so I can say dot contains and then give it the object so I'm basically saying if
10:22
it does not contain this fly out item then I want to add it then shell dot
10:34
current items dot add there we go all right so if let me just review all of
10:40
that with you because it's kind of difficult to absorb once I'm explaining
10:46
and trying to type so let me know that I've typed it let me grow through it I
10:49
go through it again right so if the role is equal to administrator then we want
10:54
to create our new menu items right so we can create a fly out item that has a
10:59
title car management I could easily say admin car management just so it's very
11:04
clear we have the roots that it will go to and then we have the different items
11:09
the shell content items and the content template to say when it's on this
11:16
particular page I will activate I will look active right so that's what our
11:21
content template means it sets or gets the data template to create when the
11:27
shell content becomes active right so that's how that navigation works so
11:31
after we've compiled all of the menu items that an administrator should have
11:36
then we go on to say if this flight item is not in the current set of items then
11:45
go ahead and add it so we've done that for admin guess what very similar steps
11:51
for user so I'm just going to change all references the admin to user right once
11:58
again we're kind of cheating here so we'll just say user user user and then
12:03
we'll add it just the same so one word of advice regarding all of this once
12:11
again with the magic strings maybe stuff like title and it's on you would want to
12:15
type here but maybe like the icons you could create a static class that has all
12:20
of the reference names to all of the icons or images that you would have
12:25
added to your app right so you don't have to magically type that every single
12:29
time also things like maybe the roles and all the things that you know you
12:34
want set in stone you can always abstract those into their own data
12:39
classes now let us turn our attention to the flyout header so we would have
12:44
created the flyout header and we did not do anything else so what I'm going to do
12:51
is create a label so well firstly this I don't want it to be vertically stacked I
12:57
want it to just be a stack right then the first label I'm going to create I'm
13:02
going to give it the label the name username right so label X name equals
13:08
LBL username so I probably didn't mention this before but it's something
13:12
that I practice with WPF and winforms application or code I always try to add
13:20
a prefix to the name so that I can remember what kind of control it is so I
13:27
probably broke that rule a bit for this course but I'm just mentioning it now
13:31
before I reach too far and it's too late to make amends right so I can say LBL
13:38
username and let's say I wanted to say LBL role I wanted to also specify what
13:44
role this user is in and I'll just set up to 20 and that's fine right so here
13:50
we'll see the username and the role displayed in the header now in the code
13:57
behind I need to make sure that those values are set so when I'll just do that
14:02
inside of the constructor or I can just say set values let's create a method
14:07
here that says set values and then inside of this method I am going to say
14:13
if if the user info in the app so if app dot user info is not equal to null
14:25
then I would like to set the username label to have the value well username
14:32
label dot text rather to be equal to app dot user info dot username so that's why
14:41
I said that this static class is very handy because then we don't have to go
14:45
and fetch the token and then these you know decrypt the token and then get the
14:49
data out of the token just by setting this constant in the back end or in the
14:55
code itself in the app itself we can access it easily wherever we need it
15:00
right and we'll do the same thing for the role LBL role right now with those
15:09
done let me try that again there we go so with that done I'm going to call on
15:16
our menu builder in two specific places in the code right and while I'm here I'm
15:25
going to change this from being async because I'm really not doing anything
15:29
asynchronous so I'll just make it a static void so I'm going to call on this
15:34
menu builder two places in the code right one we want to call on it in the
15:40
loading page view model and it becomes useful when we go to main page right so
15:47
I'm just going to put that here menu builder dot build menu menu builder let
15:54
me control dots at the using reference menu build menu when you move across
16:00
right no there are not there are a few other things I want to do here because
16:05
when we're accessing the app fresh we need an instance of the user info again
16:13
right so in the login view model we had done the user info from our JSON web
16:22
token so the other place that I would want to build menu is here so I'm going
16:27
just do the build menu here while I'm in this bit of code so menu builder dot
16:34
build menu go ahead and build up everything and then navigate but I also
16:39
want to borrow this bit of code and do that inside of this section so if if the
16:48
token is valid then go ahead and get the role from the token and then go ahead
16:55
and create the instance of app user info and username here would actually have to
17:01
come from the token this time so our JSON token dot well actually just let's
17:13
jump back over to the API where we compile the token and let's see so
17:20
that username was included as the email claim and once again this is our token
17:31
to compile the way that we need it to be compiled so if for your situation you
17:36
want to change it then you can do that but what I'm going to do in this
17:41
situation seeing that email and username are the same thing and we do have the
17:46
email claim I am going to at this point say get me the token claim that is email
17:56
right so I'm going to do the same thing here that I did for role but claim types
18:02
would be email all right good so once I do that it should be able to go in to
18:08
the token get that email value and store that as username that's a little mismatch
18:16
I can appreciate that the mismatch is there but I hope you get the concept so
18:21
once again this is where naming and context will come into play and govern
18:25
how you build your app regardless though this is all setting that user info
18:31
instance if we hit the loading page and there's still a valid token then we build
18:36
the menu and then we just navigate to the main page so let us test out what
18:42
this would look like all right guys so let us run I'm just going to run without
18:46
debugging so that it will run a bit more quickly and when our app launches
18:53
we get navigated to the login page so let's try this admin at localhost.com
18:59
and then we enter password which is p at sswd1 we sign in then we get our success
19:09
message fine click ok and then it navigates us to our car management page right so now
19:18
if we look we see that we have admin page with the dotnet bot down below so these are
19:23
many items that got added and I'm sure that there are things we can tweak to make sure
19:28
that they don't necessarily get added down below here as well as the fact that if we
19:32
look in the pill menu we see that we have admin at localhost administrator and we have
19:38
our two pages that pretty much go to the same place right so if I close the app let's say I
19:46
actually let me get the hang of this emulator here if I actually bring up the app and close it
19:55
okay that's not working out it's much easier when you're actually using the app itself but
19:59
what I'm going to do or the phone itself what I'm going to do is just rerun this so what it will do
20:04
is restart the app on the device and our token should still be valid well it isn't actually
20:14
reduced it to one minute so that we could test a bit more easily so I'll just log in again
20:20
and then once I've logged in I'm just going to rerun the app so that it will restart the app
20:27
at this point the token should already be on the phone and be valid so when the app starts this
20:32
time it's just going to go straight to our car management page there we go right so we don't
20:39
have to worry about logging in again because the app was valid or the token rather was valid for
20:46
the app now one thing that I did notice is that it could not find the claim that I was looking for
20:53
here right so these are very important points because when we were compiling our our token
21:05
over here we use the JWT registered claims and if we hover over the email value it just says email
21:14
versus when I tried to get that claim in code it actually would have said that was in the loading
21:23
page we actually looked for claim types that email which had this so that is why nothing is going
21:30
back so I just wanted to point that out as well so you have two options either you can use the JWT
21:37
claim items or sub claim items here or you can go back and make sure that the token gets compiled
21:45
with the correct claim type relative to what you expect your users or whoever is building a mobile
21:51
app to use right so you can always do that so if I just do that claim types that email over here
21:59
then that should be fine and we shouldn't have that issue with it blanking out notwithstanding
22:05
that it is evident that we are getting the information that we need accordingly right
22:11
so if I just do this one more time and I'm going to try and log in as a user just so we can confirm
22:17
that the administrator is seeing something different from what the user is seeing so if I
22:23
do user at localhost.com and the same password and then proceed to login successful and then
22:34
when we look we see user page one user page two user page and the user everything is user related
22:41
so just like that we were able to let the administrators see something different from
22:46
the users and while it's a simple example and we only have one page the principles can be transferred
22:55
to any other kind of app that you need to build or you may need to specify what each user sees
23:01
based on the role that they play in the system
Mobile Development with .Net MAUI
23:05
|
Sıradaki
47 - Adjust App Flow and Layout
Mustafa Demirhan
02.09.2024
2:16
49 - Section Summary
Mustafa Demirhan
02.09.2024
27:45
46 - Set Up Login Logic and Flow
Mustafa Demirhan
02.09.2024
6:36
43 - Seed Users and Roles
Mustafa Demirhan
02.09.2024
5:16
48 - Handle Logout
Mustafa Demirhan
02.09.2024
18:50
45 - Set Up JSON Web Token Generation
Mustafa Demirhan
02.09.2024
8:41
41 - Add App Loading Page
Mustafa Demirhan
02.09.2024
15:35
42 - Add App Login Page
Mustafa Demirhan
02.09.2024
17:56
44 - Authentication and Authorization to API
Mustafa Demirhan
02.09.2024
10:11
40 - Set Up Login Endpoint
Mustafa Demirhan
24.08.2024
7:50
34 - Configure Mobile App for Network Connections
Mustafa Demirhan
24.08.2024
8:53
39 - Add Identity to API
Mustafa Demirhan
24.08.2024
1:21
37 - Section Summary
Mustafa Demirhan
24.08.2024
14:00
36 - Essential Fixes
Mustafa Demirhan
24.08.2024
1:08
32 - Prepare Server for API Deployment
Mustafa Demirhan
24.08.2024
0:56
38 - Section Overview
Mustafa Demirhan
24.08.2024
20:07
35 - Refactor MAUI App for API
Mustafa Demirhan
24.08.2024
14:11
33 - Refactor and Publish API To Local Server
Mustafa Demirhan
24.08.2024
4:14
31 - Test API Functions
Mustafa Demirhan
24.08.2024
14:04
30 - Configure API Endpoints
Mustafa Demirhan
24.07.2024
2:39
28 - Setup CORS Policy
Mustafa Demirhan
24.07.2024
10:13
29 - Setup Database
Mustafa Demirhan
24.07.2024
2:29
27 - Setup API Project
Mustafa Demirhan
24.07.2024
8:15
22 - Exploring Storage Options
Mustafa Demirhan
24.07.2024
6:41
26 - Section Overview
Mustafa Demirhan
24.07.2024
14:28
23 - Add SQLite Database to App
Mustafa Demirhan
24.07.2024
6:51
25 - Section Summary
Mustafa Demirhan
24.07.2024
23:31
24 - Setup Form to Add and Delete Records
Mustafa Demirhan
24.07.2024
20:55
21 - Implement a Details Page
Mustafa Demirhan
24.07.2024
10:31
17 - Set Up View Model and Command
Mustafa Demirhan
18.07.2024
14:28
19 - Implement Data Template and Collection View
Mustafa Demirhan
18.07.2024
7:16
20 - Style Our List Page View
Mustafa Demirhan
18.07.2024
6:59
18 - Understanding Dependency Injection
Mustafa Demirhan
18.07.2024
1:05
15 - MVVM Toolkit Updates
Mustafa Demirhan
18.07.2024
14:32
16 - Understanding the MVVM Pattern
Mustafa Demirhan
18.07.2024
3:46
14 - Create Data Access Services
Mustafa Demirhan
18.07.2024
4:46
13 - Create Data Model
Mustafa Demirhan
18.07.2024
0:56
11 - Section Overview
Mustafa Demirhan
18.07.2024
1:07
10 - Section Summary
Mustafa Demirhan
15.07.2024
6:51
09 - Navigating Multiple Pages
Mustafa Demirhan
15.07.2024
5:03
08 - Shared Resources
Mustafa Demirhan
15.07.2024
5:25
07 - Define Platform-Specific Values
Mustafa Demirhan
15.07.2024
16:25
02 - Setup Development Environment
Mustafa Demirhan
15.07.2024
4:56
04 - Create Controls with XAML
Mustafa Demirhan
15.07.2024
7:05
05 - Understand MAUI Layouts
Mustafa Demirhan
15.07.2024
5:10
06 - Set Global Markup Values
Mustafa Demirhan
15.07.2024
11:02
03 - Create Controls with C#
Mustafa Demirhan
15.07.2024
1:32
01 - Introduction
Mustafa Demirhan
15.07.2024
Önerilen
24:19
ALF - Se3 - Ep01 HD Watch
selmabesok20619ee
20.01.2023
21:01
ALF - Se2 - Ep16 - Someone to Watch Over Me (1) HD Watch
selmabesok20619ee
18.01.2023
24:49
ALF - Se2 - Ep15 - We're So Sorry, Uncle Albert HD Watch
selmabesok20619ee
16.01.2023
0:18
Funny Cats Videos 😸😸 #Cats Video #shorts #cat
Mustafa Demirhan
22.03.2025
10:39
Funny animal videos 2023 - Funny catsdogs
Mustafa Demirhan
22.03.2025
0:13
Cat VS Dog Funny Animal Videos #shorts
Mustafa Demirhan
22.03.2025