-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSessionControllerFactory.cs
More file actions
97 lines (79 loc) · 3.69 KB
/
SessionControllerFactory.cs
File metadata and controls
97 lines (79 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using Android.App;
using Android.Content;
namespace WPC_Android.AppLayer
{
//Class that manages the login session and the session logout of the accounts saving data in shared preferences on the device
class SessionControllerFactory
{
//-------------------------------------------------------------------------//
// Data //
//-------------------------------------------------------------------------//
private string _sessionNumber;
private Context _context;
private ISharedPreferences _session;
private static string _accountSessionPref = "accountPrefs";
private static SessionControllerFactory _instance;
//-------------------------------------------------------------------------//
// Constructors //
//-------------------------------------------------------------------------//
public SessionControllerFactory(Context context)
{
_context = context;
_session = _context.GetSharedPreferences(_accountSessionPref, FileCreationMode.Private);
}
//-------------------------------------------------------------------------//
//-------------------------------------------------------------------------//
// Main Functions //
//-------------------------------------------------------------------------//
//Get the instance or create if not exist
public static SessionControllerFactory Instance
{
get
{
if (_instance == null)
{
_instance = new SessionControllerFactory(Application.Context);
}
return _instance;
}
}
//-------------------------------------------------------------------------//
//Function to cancel the current account's session
public void Logout()
{
ISharedPreferencesEditor editor = _session.Edit();
editor.Clear();
editor.Commit();
}
//-------------------------------------------------------------------------//
//Function for save the current account's session
public void SaveLoginSession(string number)
{
_sessionNumber = number;
ISharedPreferencesEditor session_editor = _session.Edit();
session_editor.PutString("number", _sessionNumber);
session_editor.Commit();
}
//------------------------------------------------------------s-------------//
//Function for check the current accounts's number
public bool CheckCredentials()
{
ISharedPreferences preferences = _context.GetSharedPreferences(_accountSessionPref, FileCreationMode.Private);
string number = preferences.GetString("number", "");
if (!number.Equals(""))
{
return true;
}
return false;
}
//-------------------------------------------------------------------------//
public string GetNumberSession()
{
ISharedPreferences preferences = _context.GetSharedPreferences(_accountSessionPref, FileCreationMode.Private);
String number = preferences.GetString("number", "");
return number;
}
}
//-------------------------------------------------------------------------//
}