blob: 52071957caf97c603c85c12d41960c3b6fa7e2a0 (
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
|
package com.zeapo.pwdstore;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
import android.hardware.display.DisplayManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.io.filefilter.NotFileFilter;
import org.apache.commons.io.filefilter.TrueFileFilter;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryBuilder;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Collection;
public class pwdstore extends Activity implements ToCloneOrNot.OnFragmentInteractionListener, PasswordFragment.OnFragmentInteractionListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pwdstore);
}
@Override
public void onResume(){
super.onResume();
// re-check that there was no change with the repository state
checkLocalRepository();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.pwdstore, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
// int id = item.getItemId();
// if (id == R.id.clone_setting) {
// getClone();
// return true;
// }
return super.onOptionsItemSelected(item);
}
public void getClone(View view){
Intent intent = new Intent(this, GitClone.class);
startActivity(intent);
}
@Override
public void onFragmentInteraction(Uri uri) {
}
@Override
public void onFragmentInteraction(String id) {
}
private void checkLocalRepository() {
int status = 0;
final File localDir = new File(getCacheDir() + "/store");
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
if (localDir.exists()) {
File[] folders = localDir.listFiles((FileFilter) FileFilterUtils.directoryFileFilter());
status = folders.length;
}
// either the repo is empty or it was not correctly cloned
switch (status) {
case 0:
ToCloneOrNot cloneFrag = new ToCloneOrNot();
fragmentTransaction.replace(R.id.main_layout, cloneFrag);
fragmentTransaction.commit();
break;
case 1:
// empty
break;
default:
PasswordFragment passFrag = new PasswordFragment();
fragmentTransaction.replace(R.id.main_layout, passFrag);
fragmentTransaction.commit();
}
}
}
|