Skip to content

Commit

Permalink
v2 Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnesan committed Jan 31, 2018
1 parent c792687 commit 653edc6
Show file tree
Hide file tree
Showing 20 changed files with 286 additions and 51 deletions.
14 changes: 13 additions & 1 deletion CryptoNews/CryptoNews.Android/CryptoNews.Android.csproj
Expand Up @@ -39,6 +39,9 @@
<AndroidSupportedAbis>armeabi,armeabi-v7a,x86</AndroidSupportedAbis>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>x86</PlatformTarget>
<AotAssemblies>false</AotAssemblies>
<EnableLLVM>false</EnableLLVM>
<BundleAssemblies>false</BundleAssemblies>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -49,6 +52,9 @@
<WarningLevel>4</WarningLevel>
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
<AotAssemblies>false</AotAssemblies>
<EnableLLVM>false</EnableLLVM>
<BundleAssemblies>false</BundleAssemblies>
</PropertyGroup>
<ItemGroup>
<Reference Include="FormsViewGroup, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
Expand Down Expand Up @@ -127,6 +133,7 @@
<Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.Designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SplashActivity.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config">
Expand All @@ -136,7 +143,6 @@
<None Include="Assets\AboutAssets.txt" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\icon.png" />
<AndroidResource Include="Resources\drawable-hdpi\icon.png" />
<AndroidResource Include="Resources\drawable-xhdpi\icon.png" />
<AndroidResource Include="Resources\drawable-xxhdpi\icon.png" />
Expand All @@ -158,6 +164,12 @@
<ItemGroup>
<AndroidResource Include="Resources\drawable\manage.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\splash.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\icon.png" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion CryptoNews/CryptoNews.Android/MainActivity.cs
Expand Up @@ -9,7 +9,7 @@

namespace CryptoNews.Droid
{
[Activity(Label = "CryptoNews", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[Activity(Label = "CryptoNews", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Portrait)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
Expand Down
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" android:versionCode="2">
<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="25" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down
23 changes: 16 additions & 7 deletions CryptoNews/CryptoNews.Android/Resources/Resource.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified CryptoNews/CryptoNews.Android/Resources/drawable/icon.png
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.
12 changes: 12 additions & 0 deletions CryptoNews/CryptoNews.Android/Resources/values/styles.xml
@@ -1,5 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="Theme.Splash" parent="MainTheme.Base">

<item name="android:windowBackground">@drawable/splash</item>
<item name="windowNoTitle">true</item>
</style>
<style name="splashscreen" parent="Theme.AppCompat.Light.NoActionBar">

<item name="android:windowNoTitle">true</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowIsFloating">false</item>
<item name="android:backgroundDimEnabled">true</item>
</style>

<style name="MainTheme" parent="MainTheme.Base">
</style>
Expand Down
29 changes: 29 additions & 0 deletions CryptoNews/CryptoNews.Android/SplashActivity.cs
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

namespace CryptoNews.Droid
{
[Activity(Theme = "@style/Theme.Splash",
Label = "CRYPTO NEWS",
MainLauncher = true,
NoHistory = true)]
public class SplashActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);

// Create your application here
StartActivity(typeof(MainActivity));
}
}
}
23 changes: 12 additions & 11 deletions CryptoNews/CryptoNews/App.xaml.cs
Expand Up @@ -40,32 +40,33 @@ public static async Task InitializeSeedData()
{
var SampleBlogWebsites = new List<BlogWebsite>();
var Website1 = new BlogWebsite
{
Name = "CryptoClarified",
Url = "https://cryptoclarified.com"
};
var Website2 = new BlogWebsite
{
Name = "CCN",
Url = "https://ccn.com/"
};
var Website2 = new BlogWebsite
{
Name = "CryptoClarified",
Url = "https://cryptoclarified.com"
};

var Website3 = new BlogWebsite
{
Name = "Crypto Junction",
Url = "https://cryptojunction.com/"
Name = "Crypto Scoop",
Url = "http://cryptoscoop.net"
};
var Website4 = new BlogWebsite
{
Name = "Coin Desk",
Url = "https://coindesk.com/"
Name = "Crypto Recorder",
Url = "https://cryptorecorder.com"
};
SampleBlogWebsites.Add(Website1);
SampleBlogWebsites.Add(Website2);
SampleBlogWebsites.Add(Website3);
SampleBlogWebsites.Add(Website4);

foreach(var sampleWebsite in SampleBlogWebsites)

foreach (var sampleWebsite in SampleBlogWebsites)
{
var dbBlogWebsites = database.GetAllBlogWebsites();
if (dbBlogWebsites.Count >= 4)
Expand Down
1 change: 1 addition & 0 deletions CryptoNews/CryptoNews/CryptoNews.csproj
Expand Up @@ -44,6 +44,7 @@
<Compile Include="Models\BlogWebsite.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\PostsRepository.cs" />
<Compile Include="Services\PrettyDate.cs" />
<Compile Include="ViewModels\BlogPostsViewModel.cs" />
<Compile Include="Views\BlogPosts.xaml.cs">
<DependentUpon>BlogPosts.xaml</DependentUpon>
Expand Down
8 changes: 7 additions & 1 deletion CryptoNews/CryptoNews/Database/CryptoNewsDB.cs
@@ -1,4 +1,5 @@
using CryptoNews.Models;
using CryptoNews.Services;
using SQLite;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -51,7 +52,12 @@ public async void ResetBlogWebsite()
#region BlogPosts
public List<BlogPost> GetAllBlogPosts()
{
return database.Table<BlogPost>().ToList();
var posts = database.Table<BlogPost>().ToList();
foreach(var post in posts)
{
post.PrettyDate = PrettyDate.GetPrettyDate(post.Date);
}
return posts;
}

public int AddUpdatedBlogPosts(List<BlogPost> blogPosts)
Expand Down
17 changes: 9 additions & 8 deletions CryptoNews/CryptoNews/Models/BlogPost.cs
Expand Up @@ -8,13 +8,14 @@ namespace CryptoNews.Models
{
public class BlogPost
{

public Guid Id { get; set; }
public string Link { get; set; }
public string Title { get; set; }
public string Excerpt { get; set; }
public DateTime Date { get; set; }
public string FeaturedImage { get; set; }
public string BlogWebsiteName { get; set; }

public Guid Id { get; set; }
public string Link { get; set; }
public string Title { get; set; }
public string Excerpt { get; set; }
public DateTime Date { get; set; }
public string PrettyDate { get; set; }
public string FeaturedImage { get; set; }
public string BlogWebsiteName { get; set; }
}
}
7 changes: 5 additions & 2 deletions CryptoNews/CryptoNews/Services/PostsRepository.cs
Expand Up @@ -9,6 +9,7 @@
using System.Net.Http.Headers;
using Newtonsoft.Json.Linq;
using System.Net;
using System.Text.RegularExpressions;

namespace CryptoNews.Services
{
Expand Down Expand Up @@ -48,13 +49,15 @@ public async Task<List<BlogPost>> GetAllPostsAsync()
blogPost.Link = item.Value<string>("link");

var tempExcerpt = item.Value<JObject>("excerpt").Value<string>("rendered");

if (tempExcerpt.Length > 200)
{
blogPost.Excerpt = tempExcerpt.Substring(0, 200);
tempExcerpt = tempExcerpt.Substring(0, 200);
blogPost.Excerpt = Regex.Replace(tempExcerpt, @"<[^>]*(>|$)|&nbsp;|&zwnj;|&raquo;|&laquo;|&#8217;", string.Empty).Trim();
}
else
{
blogPost.Excerpt = tempExcerpt;
blogPost.Excerpt = Regex.Replace(tempExcerpt, @"<[^>]*(>|$)|&nbsp;|&zwnj;|&raquo;|&laquo;", string.Empty).Trim();
}

blogPost.Date = item.Value<DateTime>("date");
Expand Down
88 changes: 88 additions & 0 deletions CryptoNews/CryptoNews/Services/PrettyDate.cs
@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CryptoNews.Services
{
public class PrettyDate
{
public static string GetPrettyDate(DateTime d)
{
// 1.
// Get time span elapsed since the date.
TimeSpan s = DateTime.Now.Subtract(d);

// 2.
// Get total number of days elapsed.
int dayDiff = (int)s.TotalDays;

// 3.
// Get total number of seconds elapsed.
int secDiff = (int)s.TotalSeconds;

// 4.
// Don't allow out of range values.
if (dayDiff < 0 || dayDiff >= 31)
{
return d.ToString("MM/dd/yyyy");
}

// 5.
// Handle same-day times.
if (dayDiff == 0)
{
// A.
// Less than one minute ago.
if (secDiff < 60)
{
return "just now";
}
// B.
// Less than 2 minutes ago.
if (secDiff < 120)
{
return "1 minute ago";
}
// C.
// Less than one hour ago.
if (secDiff < 3600)
{
return string.Format("{0} minutes ago",
Math.Floor((double)secDiff / 60));
}
// D.
// Less than 2 hours ago.
if (secDiff < 7200)
{
return "1 hour ago";
}
// E.
// Less than one day ago.
if (secDiff < 86400)
{
return string.Format("{0} hours ago",
Math.Floor((double)secDiff / 3600));
}
}
// 6.
// Handle previous days.
if (dayDiff == 1)
{
return "yesterday";
}
if (dayDiff < 7)
{
return string.Format("{0} days ago",
dayDiff);
}
if (dayDiff < 31)
{
return string.Format("{0} weeks ago",
Math.Ceiling((double)dayDiff / 7));
}
return null;
}
}
}

0 comments on commit 653edc6

Please sign in to comment.