NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package com.apnabazaar.util;

import java.util.HashMap;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import com.apnabazaar.activities.LoginActivity;
import com.apnabazaar.activities.MainActivity;
import com.apnabazaar.pojo.UserDetailsPojo;

/**
* Created by Trixie on 06-07-2017.
*/

public class SessionManager {
// Shared Preferences
SharedPreferences pref;

// Editor for Shared preferences
Editor editor;

// Context
Context context;

// Shared pref mode
int PRIVATE_MODE = 0;

// Sharedpref file name
private static final String PREF_NAME = "ApnaBazaarPref";

// All Shared Preferences Keys
private static final String IS_LOGIN = "IsLoggedIn";

// User name (make variable public to access from outside)
public static final String KEY_ID = "Id";

// Email address (make variable public to access from outside)
public static final String KEY_PASSWORD = "password";
public static final String KEY_NAME = "Name";
public static final String KEY_EMAIL = "Email";
public static final String KEY_MOBILE = "Mobile";
public static final String KEY_CITY = "City";
public static final String KEY_STREET = "Street";
public static final String KEY_HOUSE_NUMBER = "HouseNumber";
public static final String KEY_ZIP = "Zip";
public static final String KEY_STATE = "State";
public static final String KEY_COUNTRY = "Country";
// Constructor
public SessionManager(Context context){
this.context = context;
pref = context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
editor = pref.edit();
}

/**
* Create login session
* */
public void createLoginSession(UserDetailsPojo userDetailsPojo,String password){
// Storing login value as TRUE
editor.putBoolean(IS_LOGIN, true);

// Storing name in pref
editor.putString(KEY_ID, userDetailsPojo.getId());
editor.putString(KEY_NAME, userDetailsPojo.getName());
editor.putString(KEY_EMAIL, userDetailsPojo.getEmail());
editor.putString(KEY_CITY, userDetailsPojo.getCity());
editor.putString(KEY_MOBILE, userDetailsPojo.getMobile());
editor.putString(KEY_STATE, userDetailsPojo.getState());
editor.putString(KEY_COUNTRY, userDetailsPojo.getCountry());
editor.putString(KEY_ZIP, userDetailsPojo.getZip());
editor.putString(KEY_STREET, userDetailsPojo.getStreet());
editor.putString(KEY_HOUSE_NUMBER, userDetailsPojo.getHouseNumber());
editor.putString(KEY_PASSWORD, password);

editor.commit();
}

/**
* Check login method wil check user login status
* If false it will redirect user to login page
* Else won't do anything
* */
public void checkLogin(){
// Check login status

// user is not logged in redirect him to Login Activity

Intent i = new Intent(context, LoginActivity.class);
// Closing all the Activities
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

// Add new Flag to start new Activity
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

// Staring Login Activity
context.startActivity(i);
}







/**
* Get stored session data
* */
public HashMap<String, String> getUserDetails(){
HashMap<String, String> user = new HashMap<String, String>();
// user name
user.put(KEY_ID, pref.getString(KEY_ID, null));
user.put(KEY_PASSWORD, pref.getString(KEY_PASSWORD, null));
user.put(KEY_NAME, pref.getString(KEY_NAME, null));
user.put(KEY_MOBILE, pref.getString(KEY_MOBILE, null));
user.put(KEY_EMAIL, pref.getString(KEY_EMAIL, null));
user.put(KEY_HOUSE_NUMBER, pref.getString(KEY_HOUSE_NUMBER, null));
user.put(KEY_STREET, pref.getString(KEY_STREET, null));
user.put(KEY_CITY, pref.getString(KEY_CITY, null));
user.put(KEY_STATE, pref.getString(KEY_STATE, null));
user.put(KEY_COUNTRY, pref.getString(KEY_COUNTRY, null));
user.put(KEY_ZIP, pref.getString(KEY_ZIP, null));
// return user
return user;
}

/**
* Clear session details
* */
public void logoutUser(){
// Clearing all data from Shared Preferences
editor.clear();
editor.commit();

// After logout redirect user to Loing Activity
Intent i = new Intent(context, LoginActivity.class);
// Closing all the Activities
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

// Add new Flag to start new Activity
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

// Staring Login Activity
context.startActivity(i);
}

/**
* Quick check for login
* **/
// Get Login State
public boolean isLoggedIn()
{
return pref.getBoolean(IS_LOGIN, false);
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.