|
2 | 2 |
|
3 | 3 | import java.io.ByteArrayOutputStream; |
4 | 4 | import java.io.File; |
| 5 | +import java.io.FileInputStream; |
5 | 6 | import java.io.FileOutputStream; |
6 | 7 | import java.io.InputStream; |
7 | 8 | import java.net.HttpURLConnection; |
@@ -31,16 +32,48 @@ protected void onCreate(Bundle savedInstanceState) { |
31 | 32 |
|
32 | 33 | siteUrl = (TextView) findViewById(R.id.siteurl); |
33 | 34 | findViewById(R.id.go).setOnClickListener(clickListener); |
| 35 | + findViewById(R.id.go_last).setOnClickListener(clickListener); |
34 | 36 | findViewById(R.id.go_helloworld).setOnClickListener(clickListener); |
35 | 37 | } |
36 | 38 |
|
| 39 | + @Override |
| 40 | + protected void onResume() { |
| 41 | + super.onResume(); |
| 42 | + |
| 43 | + File dir = new File(getFilesDir(), "repo"); |
| 44 | + File site = new File(dir, "site.txt"); |
| 45 | + findViewById(R.id.go_last).setEnabled(site.length() > 0); |
| 46 | + TextView lastUrl = (TextView) findViewById(R.id.last_url); |
| 47 | + lastUrl.setText(null); |
| 48 | + if (site.length() > 0) { |
| 49 | + File file = new File(dir, "lastUrl.txt"); |
| 50 | + try { |
| 51 | + FileInputStream fis = new FileInputStream(file); |
| 52 | + byte[] bytes = new byte[fis.available()]; |
| 53 | + fis.read(bytes); |
| 54 | + fis.close(); |
| 55 | + String url = new String(bytes, "UTF-8"); |
| 56 | + lastUrl.setText(url); |
| 57 | + } catch (Exception e) { |
| 58 | + SiteSpec lastSite = MyApplication.instance().readSite(); |
| 59 | + String url = MyApplication.PRIMARY_SCHEME + "://" |
| 60 | + + lastSite.fragments()[0].host(); |
| 61 | + lastUrl.setText(url); |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + |
37 | 66 | private final View.OnClickListener clickListener = new View.OnClickListener() { |
38 | 67 | @Override |
39 | 68 | public void onClick(View v) { |
40 | 69 | if (v.getId() == R.id.go) { |
41 | 70 | Worker worker = new Worker(siteUrl.getText().toString()); |
42 | 71 | worker.start(); |
43 | 72 | v.setEnabled(false); |
| 73 | + } else if (v.getId() == R.id.go_last) { |
| 74 | + String url = ((TextView) findViewById(R.id.last_url)).getText() |
| 75 | + .toString(); |
| 76 | + startActivity(url); |
44 | 77 | } else if (v.getId() == R.id.go_helloworld) { |
45 | 78 | siteUrl.setText("https://raw.github.com/mmin18/AndroidDynamicLoader/master/site/helloworld/site.txt"); |
46 | 79 | findViewById(R.id.go).performClick(); |
@@ -84,6 +117,7 @@ public void run() { |
84 | 117 | final SiteSpec fSite = new SiteSpec(json); |
85 | 118 |
|
86 | 119 | File dir = new File(getFilesDir(), "repo"); |
| 120 | + new File(dir, "lastUrl.txt").delete(); |
87 | 121 | dir.mkdir(); |
88 | 122 | File local = new File(dir, "site.txt"); |
89 | 123 | File tmp = new File(dir, "site_tmp"); |
|
0 commit comments