Skip to content

Commit 296b04b

Browse files
committed
WIP Show text
1 parent b5e86e5 commit 296b04b

14 files changed

Lines changed: 201 additions & 19 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
3+
namespace BasicPlainTextReaderApp.Library
4+
{
5+
public class TextModel
6+
{
7+
public string Text { get; }
8+
public string DataString { get; }
9+
public string Type { get; }
10+
public string DataPath { get; }
11+
12+
public TextModel(string txt, string dt, string t, string dp)
13+
{
14+
Text = txt ?? "_null_";
15+
DataString = dt ?? "_null_";
16+
Type = t ?? "_null_";
17+
DataPath = dp ?? "_null";
18+
}
19+
}
20+
}

BasicPlainTextReaderApp.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ VisualStudioVersion = 16.0.30406.217
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicPlainTextReaderApp.Android", "BasicPlainTextReaderApp\BasicPlainTextReaderApp.Android\BasicPlainTextReaderApp.Android.csproj", "{C1C3CE2C-4ABB-442E-96BE-1F5B2AD8DBDC}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicPlainTextReaderApp", "BasicPlainTextReaderApp\BasicPlainTextReaderApp\BasicPlainTextReaderApp.csproj", "{CA1AEA98-AE84-4763-A402-A993868615F1}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicPlainTextReaderApp", "BasicPlainTextReaderApp\BasicPlainTextReaderApp\BasicPlainTextReaderApp.csproj", "{CA1AEA98-AE84-4763-A402-A993868615F1}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicPlainTextReaderApp.Library", "BasicPlainTextReaderApp.Library\BasicPlainTextReaderApp.Library.csproj", "{F889341B-08D1-4416-A989-D0E03D434B11}"
911
EndProject
1012
Global
1113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -25,6 +27,10 @@ Global
2527
{CA1AEA98-AE84-4763-A402-A993868615F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
2628
{CA1AEA98-AE84-4763-A402-A993868615F1}.Release|Any CPU.Build.0 = Release|Any CPU
2729
{CA1AEA98-AE84-4763-A402-A993868615F1}.Release|Any CPU.Deploy.0 = Release|Any CPU
30+
{F889341B-08D1-4416-A989-D0E03D434B11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31+
{F889341B-08D1-4416-A989-D0E03D434B11}.Debug|Any CPU.Build.0 = Debug|Any CPU
32+
{F889341B-08D1-4416-A989-D0E03D434B11}.Release|Any CPU.ActiveCfg = Release|Any CPU
33+
{F889341B-08D1-4416-A989-D0E03D434B11}.Release|Any CPU.Build.0 = Release|Any CPU
2834
EndGlobalSection
2935
GlobalSection(SolutionProperties) = preSolution
3036
HideSolutionNode = FALSE

BasicPlainTextReaderApp/BasicPlainTextReaderApp.Android/BasicPlainTextReaderApp.Android.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@
8888
<AndroidResource Include="Resources\drawable\tab_feed.png" />
8989
</ItemGroup>
9090
<ItemGroup>
91+
<ProjectReference Include="..\..\BasicPlainTextReaderApp.Library\BasicPlainTextReaderApp.Library.csproj">
92+
<Project>{F889341B-08D1-4416-A989-D0E03D434B11}</Project>
93+
<Name>BasicPlainTextReaderApp.Library</Name>
94+
</ProjectReference>
9195
<ProjectReference Include="..\BasicPlainTextReaderApp\BasicPlainTextReaderApp.csproj">
9296
<Project>{6327818D-35B3-4749-82F8-108F4C4ED810}</Project>
9397
<Name>BasicPlainTextReaderApp</Name>

BasicPlainTextReaderApp/BasicPlainTextReaderApp.Android/MainActivity.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.IO;
1111
using Android.Provider;
1212
using System.Text;
13+
using BasicPlainTextReaderApp.Library;
1314

1415
namespace BasicPlainTextReaderApp.Droid
1516
{
@@ -25,9 +26,10 @@ protected override void OnCreate(Bundle savedInstanceState)
2526
{
2627
string action = Intent.Action;
2728
string type = Intent.Type;
28-
StringBuilder sb = null;
2929

30-
if(Intent.ActionView.Equals(action) && !string.IsNullOrEmpty(type))
30+
TextModel data = null;
31+
32+
if (Intent.ActionView.Equals(action) && !string.IsNullOrEmpty(type))
3133
{
3234
Android.Net.Uri fileUri = Intent.Data;
3335
if (fileUri != null)
@@ -40,17 +42,17 @@ protected override void OnCreate(Bundle savedInstanceState)
4042
using (var bufferedReader = new Java.IO.BufferedReader(reader))
4143
{
4244
string line;
43-
sb = new StringBuilder();
45+
var sb = new StringBuilder();
4446
while ((line = bufferedReader.ReadLine()) != null)
4547
{
4648
sb.AppendLine(line);
4749
}
50+
data = new TextModel(sb.ToString(), Intent.DataString, Intent.Type, Intent.Data.Path);
4851
}
4952
}
5053
catch (Exception e)
5154
{
52-
sb = new StringBuilder();
53-
sb.AppendLine(e.ToString());
55+
data = new TextModel(e.ToString(), "error", "error", "error");
5456
}
5557
}
5658
}
@@ -62,7 +64,7 @@ protected override void OnCreate(Bundle savedInstanceState)
6264

6365
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
6466
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
65-
LoadApplication(new App(sb.ToString()));
67+
LoadApplication(new App(data));
6668
}
6769
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
6870
{

BasicPlainTextReaderApp/BasicPlainTextReaderApp/App.xaml.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,34 @@
22
using Xamarin.Forms;
33
using Xamarin.Forms.Xaml;
44
using BasicPlainTextReaderApp.Views;
5+
using BasicPlainTextReaderApp.Library;
56

67
namespace BasicPlainTextReaderApp
78
{
89
public partial class App : Application
910
{
10-
string _text;
11-
public App(string text = null)
11+
readonly TextModel _data;
12+
public App(TextModel data = null)
1213
{
1314
InitializeComponent();
1415

15-
_text = text;
16-
MainPage = new AppShell();
16+
_data = data;
17+
MainPage = new AppShell(this);
18+
}
19+
20+
public void GoToCurrentTextPage()
21+
{
22+
var page = new TextPage(_data);
23+
Shell.Current.Navigation.PushAsync(page);
24+
Shell.Current.FlyoutIsPresented = false;
1725
}
1826

1927
protected override void OnStart()
2028
{
29+
if(_data != null)
30+
{
31+
GoToCurrentTextPage();
32+
}
2133
}
2234

2335
protected override void OnSleep()

BasicPlainTextReaderApp/BasicPlainTextReaderApp/AppShell.xaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,19 @@
8181
-->
8282
<FlyoutItem FlyoutDisplayOptions="AsMultipleItems">
8383
<ShellContent Title="About" Icon="tab_about.png" Route="AboutPage" ContentTemplate="{DataTemplate local:AboutPage}" />
84-
<!-- <ShellContent Title="Browse" Icon="tab_feed.png" ContentTemplate="{DataTemplate local:ItemsPage}" /> -->
8584
</FlyoutItem>
8685

8786
<!-- When the Flyout is visible this will be a menu item you can tie a click behavior to -->
88-
<!-- <MenuItem Text="Logout" StyleClass="MenuItemLayoutStyle" Clicked="OnMenuItemClicked">
89-
</MenuItem> -->
90-
87+
<MenuItem Text="Current Text" StyleClass="MenuItemLayoutStyle" Clicked="OnMenuItemClicked" IconImageSource="tab_feed.png">
88+
</MenuItem>
89+
9190
<!--
9291
This defines content that won't show up in a flyout menu. When this content is active the flyout menu won't be available.
9392
This is useful for creating areas of the application where you don't want users to be able to navigate away from.
9493
If you would like to navigate to this content you can do so by calling
9594
await Shell.Current.GoToAsync("//LoginPage");
9695
-->
97-
<!-- <ShellContent Route="LoginPage" Shell.FlyoutBehavior="Disabled" ContentTemplate="{DataTemplate local:LoginPage}" /> -->
96+
<!--<ShellContent Route="TextPage" Shell.FlyoutBehavior="Disabled" ContentTemplate="{DataTemplate local:TextPage}" />-->
9897

9998
<!-- Optional Templates
10099
// These may be provided inline as below or as separate classes.
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using BasicPlainTextReaderApp.Library;
34
using BasicPlainTextReaderApp.ViewModels;
45
using BasicPlainTextReaderApp.Views;
56
using Xamarin.Forms;
@@ -8,10 +9,17 @@ namespace BasicPlainTextReaderApp
89
{
910
public partial class AppShell : Xamarin.Forms.Shell
1011
{
11-
public AppShell()
12+
readonly App _parent;
13+
public AppShell(App parent)
1214
{
1315
InitializeComponent();
16+
_parent = parent;
17+
Shell.SetTabBarIsVisible(this, false);
1418
}
1519

20+
private void OnMenuItemClicked(object sender, EventArgs e)
21+
{
22+
_parent.GoToCurrentTextPage();
23+
}
1624
}
1725
}

BasicPlainTextReaderApp/BasicPlainTextReaderApp/BasicPlainTextReaderApp.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,14 @@
1414
<Folder Include="Models\" />
1515
<Folder Include="Services\" />
1616
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\..\BasicPlainTextReaderApp.Library\BasicPlainTextReaderApp.Library.csproj" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<EmbeddedResource Update="Views\TextPage.xaml">
24+
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
25+
</EmbeddedResource>
26+
</ItemGroup>
1727
</Project>

BasicPlainTextReaderApp/BasicPlainTextReaderApp/ViewModels/AboutViewModel.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public AboutViewModel()
1111
{
1212
Title = "About";
1313
OpenWebCommand = new Command(async () => await Browser.OpenAsync(Constants.AboutUrl));
14-
OpenWebCommand = new Command(async () => await Shell.Current.GoToAsync("//LoginPage"));
1514
}
1615

1716
public ICommand OpenWebCommand { get; }

0 commit comments

Comments
 (0)