Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
483 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using Redux; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using System.Reactive.Linq; | ||
using System.IO; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using System.Collections.Immutable; | ||
using System.Threading; | ||
|
||
namespace Taiste.Redux.AndroidExample | ||
{ | ||
public static class ActionCreators | ||
{ | ||
public static IAction SearchUsers (string query) | ||
{ | ||
return new ThunkAction<State> ((dispatcher, getState) => { | ||
var request = WebRequest.Create (new Uri (String.Format ("https://api.github.com/search/users?q={0}", query))) as HttpWebRequest; | ||
request.UserAgent = "redux.NET thunk example"; | ||
var obs = Observable.FromAsync (() => Task.Factory.FromAsync<WebResponse> (request.BeginGetResponse, request.EndGetResponse, request)); | ||
obs.Subscribe ( | ||
(next) => { | ||
var responseData = new StreamReader (next.GetResponseStream ()).ReadToEnd (); | ||
var results = ImmutableList<string>.Empty; | ||
JObject res = JObject.Parse (responseData); | ||
var items = (JArray)res ["items"]; | ||
foreach (var item in items) { | ||
results = results.Add (item ["login"].Value<string> ()); | ||
} | ||
dispatcher (new SetResultsAction () { Results = results }); | ||
}, | ||
(error) => System.Diagnostics.Debug.WriteLine (error.Message), | ||
CancellationToken.None); | ||
}); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using Redux; | ||
using System.Collections.Immutable; | ||
|
||
namespace Taiste.Redux.AndroidExample | ||
{ | ||
public class SetResultsAction : IAction { | ||
public ImmutableList<string> Results; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Any raw assets you want to be deployed with your application can be placed in | ||
this directory (and child directories) and given a Build Action of "AndroidAsset". | ||
|
||
These files will be deployed with your package and will be accessible using Android's | ||
AssetManager, like this: | ||
|
||
public class ReadAsset : Activity | ||
{ | ||
protected override void OnCreate (Bundle bundle) | ||
{ | ||
base.OnCreate (bundle); | ||
|
||
InputStream input = Assets.Open ("my_asset.txt"); | ||
} | ||
} | ||
|
||
Additionally, some Android functions will automatically load asset files: | ||
|
||
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using Android.App; | ||
using Android.Widget; | ||
using Android.OS; | ||
using Redux; | ||
using System.Collections.Immutable; | ||
using System.Reactive.Linq; | ||
using Android.Text; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Taiste.Redux.AndroidExample | ||
{ | ||
[Activity (Label = "Redux.NET-thunk Android Example", MainLauncher = true, Icon = "@mipmap/icon")] | ||
public class MainActivity : Activity | ||
{ | ||
Store<State> store; | ||
ListView list; | ||
|
||
public MainActivity () | ||
{ | ||
store = new Store<State> (new State (ImmutableList<string>.Empty), Reducers.ReduceState, Middleware.ThunkMiddleware); | ||
} | ||
|
||
protected override void OnCreate (Bundle savedInstanceState) | ||
{ | ||
base.OnCreate (savedInstanceState); | ||
|
||
SetContentView (Resource.Layout.main); | ||
|
||
list = FindViewById<ListView> (Android.Resource.Id.List); | ||
|
||
ArrayAdapter<string> adapter = new ArrayAdapter<string> (this, Android.Resource.Layout.SimpleListItem1, new List<string> ()); | ||
list.Adapter = adapter; | ||
|
||
EditText edit = FindViewById<EditText> (Android.Resource.Id.Edit); | ||
|
||
Observable.FromEventPattern<TextChangedEventArgs> (edit, "TextChanged") | ||
.Throttle (TimeSpan.FromMilliseconds (500)) | ||
.Subscribe (e => store.Dispatch (ActionCreators.SearchUsers (edit.Text.Trim ()))); | ||
|
||
store.Select (s => s.Results) | ||
.DistinctUntilChanged () | ||
.Subscribe (UpdateAdapter); | ||
} | ||
|
||
private void UpdateAdapter (ImmutableList<string> items) | ||
{ | ||
RunOnUiThread (() => { | ||
var adapter = list.Adapter as ArrayAdapter<string>; | ||
adapter.Clear (); | ||
adapter.AddAll (items); | ||
adapter.NotifyDataSetChanged (); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
|
5 changes: 5 additions & 0 deletions
5
redux.NET-thunk.AndroidExample/Properties/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="fi.taiste.redux.thunk_androidexample"> | ||
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="23" /> | ||
<application android:allowBackup="true" android:icon="@mipmap/icon" android:label="@string/app_name"></application> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using Android.App; | ||
|
||
// Information about this assembly is defined by the following attributes. | ||
// Change them to the values specific to your project. | ||
|
||
[assembly: AssemblyTitle ("redux.NET-thunk.AndroidExample")] | ||
[assembly: AssemblyDescription ("")] | ||
[assembly: AssemblyConfiguration ("")] | ||
[assembly: AssemblyCompany ("Taiste")] | ||
[assembly: AssemblyProduct ("")] | ||
[assembly: AssemblyCopyright ("")] | ||
[assembly: AssemblyTrademark ("")] | ||
[assembly: AssemblyCulture ("")] | ||
|
||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". | ||
// The form "{Major}.{Minor}.*" will automatically update the build and revision, | ||
// and "{Major}.{Minor}.{Build}.*" will update just the revision. | ||
|
||
[assembly: AssemblyVersion ("1.0.0")] | ||
|
||
// The following attributes are used to specify the signing key for the assembly, | ||
// if desired. See the Mono documentation for more information about signing. | ||
|
||
//[assembly: AssemblyDelaySign(false)] | ||
//[assembly: AssemblyKeyFile("")] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using Redux; | ||
|
||
namespace Taiste.Redux.AndroidExample | ||
{ | ||
public static class Reducers | ||
{ | ||
public static State ReduceState(State previous, IAction action) | ||
{ | ||
var resultAction = action as SetResultsAction; | ||
if (resultAction != null) | ||
{ | ||
return new State (resultAction.Results); | ||
} | ||
return previous; | ||
} | ||
} | ||
} | ||
|
44 changes: 44 additions & 0 deletions
44
redux.NET-thunk.AndroidExample/Resources/AboutResources.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
Images, layout descriptions, binary blobs and string dictionaries can be included | ||
in your application as resource files. Various Android APIs are designed to | ||
operate on the resource IDs instead of dealing with images, strings or binary blobs | ||
directly. | ||
|
||
For example, a sample Android app that contains a user interface layout (main.axml), | ||
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) | ||
would keep its resources in the "Resources" directory of the application: | ||
|
||
Resources/ | ||
drawable/ | ||
icon.png | ||
|
||
layout/ | ||
main.axml | ||
|
||
values/ | ||
strings.xml | ||
|
||
In order to get the build system to recognize Android resources, set the build action to | ||
"AndroidResource". The native Android APIs do not operate directly with filenames, but | ||
instead operate on resource IDs. When you compile an Android application that uses resources, | ||
the build system will package the resources for distribution and generate a class called "R" | ||
(this is an Android convention) that contains the tokens for each one of the resources | ||
included. For example, for the above Resources layout, this is what the R class would expose: | ||
|
||
public class R { | ||
public class drawable { | ||
public const int icon = 0x123; | ||
} | ||
|
||
public class layout { | ||
public const int main = 0x456; | ||
} | ||
|
||
public class strings { | ||
public const int first_string = 0xabc; | ||
public const int second_string = 0xbcd; | ||
} | ||
} | ||
|
||
You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main | ||
to reference the layout/main.axml file, or R.strings.first_string to reference the first | ||
string in the dictionary file values/strings.xml. |
96 changes: 96 additions & 0 deletions
96
redux.NET-thunk.AndroidExample/Resources/Resource.designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
<EditText | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:id="@android:id/edit" /> | ||
<ListView | ||
android:minWidth="25px" | ||
android:minHeight="25px" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:id="@android:id/list" /> | ||
</LinearLayout> |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string | ||
name="hello">Hello World, Click Me!</string> | ||
<string | ||
name="app_name">redux.NET-thunk.AndroidExample</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Immutable; | ||
|
||
namespace Taiste.Redux.AndroidExample | ||
{ | ||
public class State | ||
{ | ||
public ImmutableList<string> Results { get; } | ||
public State (ImmutableList<string> results) | ||
{ | ||
Results = results; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Newtonsoft.Json" version="8.0.2" targetFramework="MonoAndroid44" /> | ||
<package id="Redux.NET" version="0.3.0" targetFramework="MonoAndroid44" /> | ||
<package id="Rx-Core" version="2.2.5" targetFramework="MonoAndroid44" /> | ||
<package id="Rx-Interfaces" version="2.2.5" targetFramework="MonoAndroid44" /> | ||
<package id="Rx-Linq" version="2.2.5" targetFramework="MonoAndroid44" /> | ||
<package id="Rx-Main" version="2.2.5" targetFramework="MonoAndroid44" /> | ||
<package id="Rx-PlatformServices" version="2.2.5" targetFramework="MonoAndroid44" /> | ||
<package id="System.Collections.Immutable" version="1.1.37" targetFramework="MonoAndroid44" /> | ||
</packages> |
Oops, something went wrong.