Showing posts with label hybrid-apps. Show all posts
Showing posts with label hybrid-apps. Show all posts

Redesigning Facebook FeedView in Ionic and angular

Facebook feed view in angular.js and ionic

Making Time: Redesigning Concept Facebook Feed For Android with Ionic and angular.js


In UX design, few things are more intricate than time and personal time management — only a good arsenal of mobile design patterns and information architecture principles can save you. This is the story of redesigning the UX for a popular social networking app the Facebook Android app.

Before we get started  redesigning the news feed  we were already checked for what

Disclaimer: This app is not intended to be a fully-featured facebook news feed but rather I want to demonstrate how to implement the same UI/UX method in ionic applications.

This was a weekend project which we coded .
What we took as reference to build is the Android app for facebook



Create a new tab project in ionic
Ionic start facebook_feed tabs

Once the projects gets created move to project directory and  launch the application by providing the command.

Ionic serve


So,Let get Started!
Setting up and Creating a new Blank Project in Ionic:
Now let's create an app. From the terminal, go to your project folder.
Finally navigate to the project directory and add iOS and/or Android platforms to Ionic and test the app.
cd facebook_feed
ionic platform add ios/Android
ionic build ios/Android
ionic emulate ios/android

To complete the app we need to:

  1. Define the front end views

  2. Define controllers that provide data

  3. Define routes to tie the views to the controllers


Since we created a blank apps ,create a template folder and  Navigate to the folder www/templates from your application root directory. This folder contains template files that will be rendered for the app.

Creating Template Files
which we will use for  tabs and fetching and showing feed details  using json data.

A)Create new template/friends-details.html  file and paste the below code to it.
<ion-view title="{{friend.name}}">
<ion-content has-header="true" padding="true">
</ion-content>
</ion-view>

This file contains the html code for presenting the list of friends which we will fetch from friends object in your ionic applications.

Similarly create tab-account and tab-dashboard

Tab-account.html
<ion-view title="{{friend.name}}">
<ion-content has-header="true" padding="true">
</ion-content>
</ion-view>
Tab-dashboard.html
<ion-header-bar class="bar bar-stable title">
<h1 class="title">Dashboard</h1>
<div class="buttons">
<button class="button button-icon ion-android-search"
ng-click="vm.showFilterBar()"></button>
<button class="button button-icon ion-person-add"
ng-click="vm.showFilterBar()"></button>
</div>

</ion-header-bar>
Tab-discovery.html

<ion-header-bar class="bar bar-stable title">
<h1 class="title">News Feed</h1>
<div class="buttons">
<button class="button button-icon ion-android-search"
ng-click="vm.showFilterBar()"></button>
<button class="button button-icon ion-person-add"
ng-click="vm.showFilterBar()"></button>
</div>
</ion-header-bar>



Next ,create the tab-discovery.html template for facebook like feed in ionic

.The tab-discovery.html  has the function of pull-to-refresh functionality which will be used to refresh the feed list.

Steps to Attain feed view design:


1)Create the header bar with title(News Feed) which hold the search and chatlist feature






2)Create the tab view which holds the the different views of the tabs.



3) Creating the feed view with



4) Finally the bottom tab which will have three tabs to update status,Checkin etc.

<div class="tabs-striped tabs-top tabs-background-light tabs-color-positive-dark">
<div class="tabs">
<a class="tab-item active" href="#">
<i class="icon ion-card"></i>
Test
</a>
<a class="tab-item" href="#">
<i class="icon ion-person-stalker"></i>
Favorites
</a>
<a class="tab-item" href="#">
<i class="icon ion-chatbubbles"></i>
Settings
</a>
<a class="tab-item" href="#">
<i class="icon ion-earth"></i>
Settings
</a>
<a class="tab-item" href="#">
<i class="icon ion-navicon"></i>
Settings
</a>
</div>

<ion-content class="padding has-tabs-top" >
<ion-refresher
pulling-text="Pull to refresh..."
on-refresh="doRefresh()">
</ion-refresher>
<ion-list >

<ion-item class="discovery-item" ng-repeat="feed in feeds" type="item-text-wrap" >


<div class="item item-avatar">
<img class="head-img" ng-src="{{feed.profilePic}}">
<h2><b>{{feed.name}}</b></h2>
<p am-time-ago="{{feed.timeStamp}}"></p>
</div>

<div class="item item-body">
<p>
{{feed.status}}
</p>
<img class="feed-content-img" ng-src="{{feed.image}}">

<p>
<b><a href="#" class="subdued">1 likes</a>
<b><a href="#" class="subdued">5 Comments</a>
</p>
</div>

<div class="buttons-share">
<button class="button button-icon icon ion-thumbsup">Like</button>
<button class="button button-icon ion-chatbox">Comment</button>
<button class="button button-icon ion-reply-all">Share</button>
</div>

</ion-item>
</ion-list>
<ion-infinite-scroll
if="!noMoreItemsAvailable"
on-infinite="loadMore(10)"
icon="ion-loading-c"
distance="1%">
</ion-infinite-scroll>
</ion-content>
</ion-view>
Adding the templates and controller to index.html
Include the controller file and template file in the main index.hml to bind all the things at one.by creating three controller
Navigate to js folder and create three js files.controller.js -handling logic of the app
app.js-Defining the routers and controller mappingservice.js-Sending the request to API and updating with response.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>

<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">

<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->

<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/ngCordova/dist/ng-cordova.min.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>

<!-- your app's js -->
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
<script src="js/app.js"></script>
</head>
<body ng-app="app">

<ion-nav-view>
</ion-nav-view>
</body>
</html>



Here Comes the Controller!

Building the controller with angular.js that goes to the backend and does all the work

Navigate to js folder  and add the below code to it.
app.js
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])

.run(function ($ionicPlatform) {
$ionicPlatform.ready(function () {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
})

.config(function ($stateProvider, $urlRouterProvider) {

// Ionic uses AngularUI Router which uses the concept of states
// Learn more here: https://github.com/angular-ui/ui-router
// Set up the various states which the app can be in.
// Each state's controller can be found in controllers.js
$stateProvider

// setup an abstract state for the tabs directive
.state('tab', {
url: "/tab",
abstract: true,
templateUrl: "templates/tabs.html"
})

// Each tab has its own nav history stack:

.state('tab.dash', {
url: '/dash',
views: {
'tab-dash': {
templateUrl: 'templates/tab-dash.html',
controller: 'DashCtrl'
}
}
})
.state('tab.discovery', {
url: '/discovery',
views: {
'tab-discovery': {
templateUrl: 'templates/tab-discovery.html',
controller: 'DiscoveryCtrl'
}
}
})
.state('tab.friends', {
url: '/friends',
views: {
'tab-friends': {
templateUrl: 'templates/tab-friends.html',
controller: 'FriendsCtrl'
}
}
})
.state('tab.friend-detail', {
url: '/friend/:friendId',
views: {
'tab-friends': {
templateUrl: 'templates/friend-detail.html',
controller: 'FriendDetailCtrl'
}
}
})

.state('tab.account', {
url: '/account',
views: {
'tab-account': {
templateUrl: 'templates/tab-account.html',
controller: 'AccountCtrl'
}
}
});

// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/tab/discovery');

});

Creating the Controller.js which will be used which will be used to load the feed in increment whenever the feed reached to bottom a new record is viewed and generates a infinfte scroll view.
angular.module('starter.controllers', ["angularMoment"])

.controller('DashCtrl', function ($scope) {
})

.controller('DiscoveryCtrl', function ($scope, Discovery, $http, $ionicLoading) {
$scope.feeds = [];
$scope.loadedFeeds = Discovery.all();
$scope.noMoreItemsAvailable = false;

$scope.loadMore = function (NumOfFeedToLoad) {
//NumOfFeedToLoad decide how many feed load per loadMore called
for(var i=0;i<NumOfFeedToLoad;i++){
var numOffeeds = $scope.feeds.length;
$scope.feeds.push($scope.loadedFeeds[numOffeeds]);
}

//Stop loadMore while no more data inside loadedFeeds
if ($scope.feeds.length == $scope.loadedFeeds) {
$scope.noMoreItemsAvailable = true;
}

$scope.$broadcast('scroll.infiniteScrollComplete');

}

$scope.showloading = function (durationtime) {

if (!durationtime) {

$ionicLoading.show({
template: 'Loading...',
noBackdrop: true
});
} else {

$ionicLoading.show({
template: 'Loading...',
noBackdrop: true,
duration: durationtime
});
}

};
$scope.hideloading = function () {
$ionicLoading.hide();
};
$scope.doRefresh = function () {
$scope.showloading()
$http.get('/new-items')
.success(function (newItems) {
$scope.feeds = newItems;
})
.finally(function () {
// Stop the ion-refresher from spinning
$scope.hideloading()
$scope.$broadcast('scroll.refreshComplete');
});
};
})
.controller('FriendsCtrl', function ($scope, Friends) {
$scope.friends = Friends.all();
})

.controller('FriendDetailCtrl', function ($scope, $stateParams, Friends) {
$scope.friend = Friends.get($stateParams.friendId);
})

.controller('AccountCtrl', function ($scope) {
});

Setting Up and Calling the API through services.js
angular.module('starter.services', [])

/**
* A simple example service that returns some data.
*/
.factory('Friends', function() {
// Might use a resource here that returns a JSON array


var friends = [
{ id: 0, name: 'Alexa' },
{ id: 1, name: 'Venkates Pillai' },
{ id: 2, name: 'vaibhav Kumar' },
{ id: 3, name: 'Ramesh singh' },
{ id: 4, name: 'Srinivas ' },
{ id: 4, name: 'Ramanujam' },
{ id: 4, name: 'Samavedam' }

];

return {
all: function() {
return friends;
},
get: function(friendId) {
// Simple index lookup
return friends[friendId];
}
}
})
.factory('Discovery',function(){
var feeds = [...
Run the Application:

Ionic_angular.js_facebooklike_feedview

Friends View



Working with Ionic 2,Angular.js and cordova Geolocation

As suggested by some of our readers ,Today we are presenting new post for Ionic-2 with geolocation using angular.js

In this post for a sample we are going to build a weather app using the Forecast API by fetching current location.

Things we are going to do today is building a complete ionic app with side-menu, fetching data from API,asking for user location and much more..  



weather app with ionic and geolocaion


So,Let get Started!
Setting up and Creating a new Blank Project in Ionic:
Now let's create an app. From the terminal, go to your project folder. Type the following command to create a blank app with tabs.
Lets install ionic and cordova first,
npm install -g ionic cordova
Ionic framework now got installed on your machine,now lets create new blank project.
ionic start weatherapp blank

Simply replace tabs in the above line with tab or side menu to create a tab app, or an application with a side menu.
Finally navigate to the project directory and add iOS and/or Android platforms to Ionic and test the app.
cd weatherapp
ionic platform add ios/Android
ionic build ios/Android
ionic emulate ios/android


To complete the app we need to:

  1. Define the front end views
  2. Define controllers that provide data
  3. Define routes to tie the views to the controllers

Since we created a blank apps ,create a template folder and  Navigate to the folder www/templates from your application root directory. This folder contains template files that will be rendered for the app.
Creating template files which we will use for Side-menu and fetching and showing weather UI using Forecast API


A)Create new template/menus.html file and paste the below code to it.
This file contains the html code for creating side-menus in your ionic applications.
We are try to fetch and convert the temperature either to Celsius/Fahrenheit using the ionic-radio component.

<ion-side-menus>
<ion-side-menu-content>
<ion-nav-bar class="bar-stable">
<ion-nav-buttons side="right">
<button class="button button-clear ion-navicon" menu-toggle="right"></button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="menuContent">
</ion-nav-view>

</ion-side-menu-content>
<ion-side-menu side="right">
<ion-header-bar class="bar-stable">
<h1 class="title">Settings</h1>
</ion-header-bar>
<ion-content>
<ion-item class="item-divider icon ion-home"> Home</ion-item>
<ion-radio ng-model="settings.units" ng-value="'us'" menu-close="true" >Fahrenheit</ion-radio>
<ion-radio ng-model="settings.units" ng-value="'si'" menu-close="true" >Celsius</ion-radio>
<ion-item class="item-divider ">Cities</ion-item>
<ion-item class="item-divider">Location</ion-item>
</ion-content>
</ion-side-menu>

</ion-side-menus>


Next ,create the weather.html template which will fetch the weather details from Forecast API and showcase in UI.
The weather.html has the function of pull-to-refresh functionality which will be used to refresh the location.

<ion-view id="weatherContainer">
<ion-content>
<ion-refresher pulling-text="Pull to refresh..." on-refresh ="doRefresh()">
</ion-refresher>


<div id="current-weather" ng-show="haveData">
<h1 class="current-temp">{{currentTemp}}&deg;</h1>
<h2>{{current.summary}}</h2>
<h3>
<span id="temp-hi"><i class="icon ion-arrow-up-c"></i>{{highTemp}}&deg;</span>
<span id="temp-lo"><i class="icon ion-arrow-down-c"></i>{{lowTemp}}&deg;
</span>
</h3> <h3>
<span id="temp-hi"><i class="icon ion-android-pin"></i>{{longi}}&deg;</span>
<span id="temp-lo"><i class="icon ion-android-pin"></i>{{lati}}&deg;
</span>
</h3>
</div>
</ion-content>

</ion-view>

Adding the template and main controller to index.html
Include the controller file and template file in the main index.hml to bind all the things at one.by creating three controller Navigate to js folder and create three js files.controller.js -handling Geolocation of the app by contacting the ngCordova plugin.app.js-Defining the routers and controller mappingservice.js-Sending the request to forecast API and updating with response.



<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>

<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">

<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->

<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/ngCordova/dist/ng-cordova.min.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>

<!-- your app's js -->
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
<script src="js/app.js"></script>
</head>
<body ng-app="app">

<ion-nav-view>
</ion-nav-view>
</body>
</html>

Here Comes the Controller!
Building the controller with angular.js that goes to the backend and does all the work

Navigate to js folder and add the below code to it.

angular.module('app', ['ionic', 'ngCordova', 'app.controllers'])
.constant('FORECASTIO_KEY', 'YOUR-API_KEY')//add your key here.
.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app', {
url: '/app',
abstract: true,
templateUrl: 'templates/menu.html',
controller: 'AppCtrl'
})

.state('app.weather', {
url: '/weather',
views: {
'menuContent': {
templateUrl: 'templates/weather.html',
controller: 'WeatherCtrl'
}
}
});

// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app/weather');
})
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})

Creating the Controller.js which will be used to locate used using cordova geolocation and fetch the data from Forecast API.

Important Methods while working the geolocation:
getCurrentPosition(options)
timeout -Maximum length of time (milliseconds) that is allowed to pass
maximumAge-Accept a cached position whose age is no greater than the specified time in milliseconds
enableHighAccuracy-Provides a hint that the application needs the best possible results
Returns Object with user information, such as id, lastName

watchPosition(options)

timeout-Maximum length of time (milliseconds) that is allowed to pass
maximumAge-Accept a cached position whose age is no greater than the specified time in milliseconds
enableHighAccuracy-Provides a hint that the application needs the best possible results
Returns Object - watchID which is used to clear watch later on.
clearWatch(watchID)

watchID- Uses the watchID returned from watchPosition()

angular.module('app.controllers', ['app.services'])
.controller('AppCtrl', function ($scope, $log, Settings) {
$log.info('AppCtrl Created');
$scope.settings = Settings;
})
.controller('WeatherCtrl', function ($scope, $log, $ionicLoading, $ionicPlatform, $cordovaGeolocation, Location, Weather, Settings) {
$log.info('WeatherCtrl Created');

$ionicPlatform.ready(function () {
if (Location.lat == 0) {
var posOptions = {
timeout: 10000,
enableHighAccuracy: false
};
$cordovaGeolocation
.getCurrentPosition(posOptions)
.then(function (position) {
Location.lat = position.coords.latitude;
Location.long = position.coords.longitude;
getWeather();
}, function (err) {
// error
});
}
});

$scope.haveData = false;
$ionicLoading.show({
template: 'Loading...'
});

function getWeather() {
$scope.haveData = false;
$ionicLoading.show({
template: 'Loading...'
});
Weather.getWeatherAtLocation(Location.lat, Location.long).then(function (resp) {
$log.info(resp);
$scope.longi=resp.data.longitude;
$scope.lati=resp.data.latitude;

$scope.current = resp.data.currently;
$scope.highTemp = Math.ceil(resp.data.daily.data[0].temperatureMax);
$scope.lowTemp = Math.floor(resp.data.daily.data[0].temperatureMin);
$scope.currentTemp = Math.ceil($scope.current.temperature);
$scope.haveData = true;
$ionicLoading.hide();
$scope.$broadcast('scroll.refreshComplete');
}, function (error) {
alert('Unable to get current conditions');
$log.error(error);
});
}

//getWeather();

$scope.doRefresh = function () {
getWeather();
}

$scope.$watch(function () {
return Settings.units
}, function (newVal, oldVal) {
if (newVal !== oldVal) {
getWeather();
}
});
});


Setting Up and Calling the Forecast API through services.js
This will build the URL for forecast API with API key which we generated earlier and authenticate the URL to send request to API.
angular.module('app.services', [])
.factory('Settings', function () {
var Settings = {
units: 'us'
};
return Settings;
})
.factory('Location', function () {
var Location = {
lat: 0,
long: 0
};
return Location;
})
.factory('Weather', function($http, $log, Settings, FORECASTIO_KEY) {
$log.info('Weather Factory');
var url = 'https://api.forecast.io/forecast/' + FORECASTIO_KEY + '/';

return {
getWeatherAtLocation: function(lat, lng) {
return $http.jsonp(url + lat + ',' + lng + '?callback=JSON_CALLBACK&units='+Settings.units);
}
}
});
Run the ApplicationRun your application by below command. Ionic serve





Whats next?

In the next post we may use Google Maps to geolocate and build and learn something exciting!

If you have some suggestion for post to be covered you are welcomed to contact!

Please share,like,tweet with other developers happy Coding!