Change save button to save actionbar icon in notesactivity
This commit is contained in:
parent
922215e324
commit
dbf5b3cd36
|
@ -13,7 +13,22 @@ namespace SimpleNotes;
|
|||
[Activity(Label = "@string/note_page",Theme ="@style/Theme.SimpleNotes")]
|
||||
public class NoteActivity : AppCompatActivity
|
||||
{
|
||||
|
||||
public override bool OnCreateOptionsMenu(IMenu? menu)
|
||||
{
|
||||
MenuInflater.Inflate(Resource.Menu.menu_note,menu);
|
||||
return true;
|
||||
}
|
||||
Func<Task> Save;
|
||||
public override bool OnOptionsItemSelected(IMenuItem item)
|
||||
{
|
||||
int id=item.ItemId;
|
||||
if(id == Resource.Id.action_save)
|
||||
{
|
||||
if(Save != null)
|
||||
Task.Run(Save).Wait(0);
|
||||
}
|
||||
return base.OnOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
protected override async void OnCreate(Bundle? savedInstanceState)
|
||||
{
|
||||
|
@ -21,15 +36,14 @@ public class NoteActivity : AppCompatActivity
|
|||
DynamicColors.ApplyToActivityIfAvailable(this);
|
||||
// Set our view from the "main" layout resource
|
||||
SetContentView(Resource.Layout.activity_note);
|
||||
SetSupportActionBar(FindViewById<AndroidX.AppCompat.Widget.Toolbar>(Resource.Id.toolbar));
|
||||
SetSupportActionBar(FindViewById<AndroidX.AppCompat.Widget.Toolbar>(Resource.Id.toolbar2));
|
||||
var (endpoint,username,password) = MainActivity.GetPrefs(this);
|
||||
|
||||
//check for id
|
||||
var note_title = FindViewById<TextInputEditText>(Resource.Id.note_title);
|
||||
var note_body = FindViewById<TextInputEditText>(Resource.Id.note_body);
|
||||
var note_save = FindViewById<Button>(Resource.Id.note_save);
|
||||
|
||||
if(note_title == null || note_body == null || note_save == null) return;
|
||||
if(note_title == null || note_body == null) return;
|
||||
|
||||
|
||||
long id = Intent?.GetLongExtra("note_id",0) ?? 0;
|
||||
|
@ -68,14 +82,13 @@ public class NoteActivity : AppCompatActivity
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
note_save.Click += async(sender,e)=>{
|
||||
Save = async()=>{
|
||||
|
||||
var note = new Note();
|
||||
note.Id = id;
|
||||
this.RunOnUiThread(()=>{
|
||||
note.Title = note_title.Text ?? "";
|
||||
note.Body = note_body.Text ?? "";
|
||||
note_save.Enabled=false;
|
||||
});
|
||||
if(!string.IsNullOrWhiteSpace(endpoint) && !string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password))
|
||||
{
|
||||
|
@ -84,7 +97,7 @@ public class NoteActivity : AppCompatActivity
|
|||
|
||||
|
||||
this.RunOnUiThread(()=>{
|
||||
note_save.Enabled=true;
|
||||
|
||||
Toast.MakeText(this,"Saved Note",ToastLength.Long)?.Show();
|
||||
});
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 918 B |
Binary file not shown.
After Width: | Height: | Size: 539 B |
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
|
@ -13,7 +13,7 @@
|
|||
android:fitsSystemWindows="true">
|
||||
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:id="@+id/toolbar2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize" />
|
||||
|
||||
|
@ -23,8 +23,7 @@
|
|||
<com.google.android.material.textfield.TextInputEditText android:hint="@string/note_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/note_title" />
|
||||
<com.google.android.material.textfield.TextInputEditText android:hint="@string/note_body" android:layout_below="@+id/note_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/note_body" />
|
||||
|
||||
<Button android:id="@+id/note_save" android:layout_below="@+id/note_body" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/note_save"/>
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="com.example.myapplication.MainActivity">
|
||||
<item
|
||||
android:icon="@drawable/ic_action_save"
|
||||
android:id="@+id/action_save"
|
||||
android:orderInCategory="100"
|
||||
android:title="@string/action_save"
|
||||
app:showAsAction="ifRoom"/>
|
||||
</menu>
|
|
@ -10,6 +10,6 @@
|
|||
|
||||
<string name="note_title">Note Title</string>
|
||||
<string name="note_body">Note Body</string>
|
||||
<string name="note_save">Save</string>
|
||||
<string name="action_save">Save</string>
|
||||
<string name="rvimagebuttondesc">Delete</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue