Angular + Asp.net core identity is not easy, you need some custom claims
In Visual Sutdio 2019, Angular+ .net core identity is nearly done by a single click. But that is not easy if you wish to add extra custom claims. I have tried to used IdentityResource or IProfileService to config the Identity server at Startup.cs. That is not successful. That is easier to build own in this case. Mainly, you need to build login service by yourself.
At this stage, I believe the angular code can be reuse. I just need to config it to use my own login url.
Separating the routes in angular
I don't know why the default .net core angular template all routes in the app.modules.ts like this
Code
RouterModule.forRoot([ | |
{ path: '', component: HomeComponent, pathMatch: 'full' }, | |
{ path: 'counter', component: CounterComponent }, | |
{ path: 'fetch-data', component: FetchDataComponent }, | |
]) |
If you build more modules, then the codes will become quite unmanageable. This is not clean at all.
I suggest a better practice, to create app.routes.ts.
This like:
Code
export class AppRoutes { | |
getRoutes() { | |
return [ | |
{ path: '', component: HomeComponent, pathMatch: 'full' }, | |
{ path: 'counter', component: CounterComponent }, | |
| |
{ path: 'fetch-data', component: FetchDataComponent }, | |
]; | |
} | |
} |
Then in the app.modules.ts, it will import the routes
Code
let appRoutes = new AppRoutes(); | |
RouterModule.forRoot(appRoutes.getRoutes()) |
This approach is more clear
RecyclerView only show one element
There is not listview in more modern Android SDK. The replacement of this is RecyclerView, that is more flexible, you can set the layout manager, such as LinearLayoutManager or GridLayoutManager, even you can build your own. But that is more powerful, then that is harder to use. The first program I built, I found it only shows the first element. Then I found in the layout resource file of list adapter, the root element cannot set the height to be "match_parent", if you set "match_parent", the first element will be occupied the whole list, then no room for another elements. So the solution is to the height to be the fixed value or "wrap_content.
Android Orm - Room
There are a lot of ORM for Android. Previously, I have used Ormlite. That is quite good. I got a new personal project of Android App. This is a good to look around new framework I can use. I found Google has their ORM layer. That is not form the standard SDK. This ORM is from the Android Architecture Components. That is quite modern, and similar with others. It used annotations like this to define the mapping
Code
@Entity(tableName = "people") | |
public class Person { | |
@PrimaryKey(autoGenerate = true) | |
public int id; | |
public String name; | |
| |
public int eventId; | |
} |
But the Dao is a strange
public interface DrawingEventDao {
@Query("SELECT * FROM drawEvents")
List loadAll();
}
Because it is a ORM of sqlite. You still need to write the SQL like this. That is the things I do not really like. Maybe I have been LINQ for too long. That is not easy to go back the SQL. But that is still much better than connecting with Sqlite
[Android] OCR with Google ML Kit
Recently, I am playing with OCR with Google ML Kit. A few years ago, I wish OCR in my mobile app, I want to extra some text from the images. That was very very hard to do. Either I need to use some opensource projector in a web server, and the app will post the image to my web api to do OCR. Or I need to buy some expensive libraries to do that. But Now, I can use Google ML Kit to do that. I just need to import library in gradle. And then I need to create an instance of TextRecognizer. Finally, I need to call a method with the image to do the OCR. I can use do that on the device or with CloudAPI. If I choose to do that on the device, that is completely free. Even I use the cloud API, I got first 1,000 users are free. That is a good deal. That is a good choice for an indie developer as myself