summaryrefslogtreecommitdiff
path: root/src/se/leap/leapclient/Dashboard.java
blob: 84ddab278f2172994b14b25f923b47e4de04858f (plain)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package se.leap.leapclient;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import se.leap.openvpn.AboutFragment;
import se.leap.openvpn.MainActivity;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewStub;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;

public class Dashboard extends Activity {

	private static SharedPreferences preferences;
	private static Provider provider;

	private TextView providerNameTV;
	private TextView eipTypeTV;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.client_dashboard);

		preferences = getPreferences(MODE_PRIVATE);

		// FIXME provider data!! get parmegv's work so we can stop (or lessen) faking it
		if (preferences.contains("provider") )
			startActivity(new Intent(this, ProviderListActivity.class));
		
		// Get our provider
		provider = Provider.getInstance(preferences);
		
		// Set provider name in textview
		providerNameTV = (TextView) findViewById(R.id.providerName);
		providerNameTV.setText(provider.getName());
		providerNameTV.setTextSize(28); // TODO maybe to some calculating, or a marquee?
		
		// TODO Inflate layout fragments for provider's services
		if ( provider.hasEIP() )
			serviceItemEIP();
	}

	// FIXME!!  We don't want you around here once we have something /real/ going on
	private void fixmePrefsFaker(SharedPreferences fakeit) {
		SharedPreferences.Editor fakes = fakeit.edit();
		
		AssetManager am = getAssets();
		BufferedReader prov = null;
		try {
			prov = new BufferedReader(new InputStreamReader(am.open("providers/bitmask.net_provider.json")));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		BufferedReader serv = null;
		try {
			serv = new BufferedReader(new InputStreamReader(am.open("providers/bitmask.net_eip-service.json")));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		StringBuilder provider = new StringBuilder();
		StringBuilder eip = new StringBuilder();
		
		String line;
		try {
			while ((line = prov.readLine()) != null){
				provider.append(line);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String providerjson = provider.toString();
		try {
			while ((line = serv.readLine()) != null){
				eip.append(line);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String eipjson = eip.toString();
		
		fakes.putString("provider", providerjson);
		fakes.putString("eip", eipjson);
		fakes.commit();
	}

	private void serviceItemEIP() {
		// FIXME Provider service (eip/openvpn)	
		View eipOverview = ((ViewStub) findViewById(R.id.eipOverviewStub)).inflate();

		// Set our EIP type title
		eipTypeTV = (TextView) findViewById(R.id.eipType);
		eipTypeTV.setText(provider.getEIPType());

		// TODO Bind our switch to run our EIP
		// What happens when our VPN stops running?  does it call the listener?
		Switch eipSwitch = (Switch) findViewById(R.id.eipSwitch);
		eipSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if ( isChecked ){
					//TODO startVPN();
				} else {
					//TODO stopVPN();
				}
			}
		});

		//TODO write our info into the view	fragment that will expand with details and a settings button
		// TODO set eip overview subview
		// TODO make eip type clickable, show subview
		// TODO attach vpn status feedback to eip overview view
		// TODO attach settings button to something
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.client_dashboard, menu);
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item){
		Intent intent;
		// Handle item selection
		switch (item.getItemId()){
		case R.id.about_leap:
			// TODO move se.leap.openvpn.AboutFragment into our package
			Fragment aboutFragment = new AboutFragment();
			FragmentTransaction trans = getFragmentManager().beginTransaction();
			trans.replace(R.id.dashboardLayout, aboutFragment);
			trans.addToBackStack(null);
			trans.commit();
			
			//intent = new Intent(this,AboutFragment.class);
			//startActivity(intent);
			return true;
		case R.id.legacy_interface:
			// TODO call se.leap.openvpn.MainActivity
			intent = new Intent(this,MainActivity.class);
			startActivity(intent);
			return true;
		default:
				return super.onOptionsItemSelected(item);
		}
		
	}
	
	@SuppressWarnings("unused")
	private void toggleOverview() {
		// TODO Expand the one line overview item to show some details
	}

}