user is able to chose internal/external when creating/cloning
also no longer needed to close to refresh the list
This commit is contained in:
parent
4975dfdcfa
commit
ceb183727f
6 changed files with 97 additions and 39 deletions
|
@ -5,7 +5,7 @@ import android.app.Fragment;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -105,7 +105,7 @@ public class PasswordFragment extends Fragment{
|
||||||
recyclerAdapter.clear();
|
recyclerAdapter.clear();
|
||||||
recyclerAdapter.addAll(PasswordRepository.getPasswords(item.getFile()));
|
recyclerAdapter.addAll(PasswordRepository.getPasswords(item.getFile()));
|
||||||
|
|
||||||
((ActionBarActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
((PasswordStore) getActivity()).decryptPassword(item);
|
((PasswordStore) getActivity()).decryptPassword(item);
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ public class PasswordFragment extends Fragment{
|
||||||
recyclerAdapter.clear();
|
recyclerAdapter.clear();
|
||||||
recyclerAdapter.addAll(PasswordRepository.getPasswords());
|
recyclerAdapter.addAll(PasswordRepository.getPasswords());
|
||||||
|
|
||||||
((ActionBarActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -10,7 +10,7 @@ import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.view.MenuItemCompat;
|
import android.support.v4.view.MenuItemCompat;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.SearchView;
|
import android.support.v7.widget.SearchView;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
|
@ -29,12 +29,16 @@ import org.eclipse.jgit.api.Git;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
public class PasswordStore extends ActionBarActivity {
|
public class PasswordStore extends AppCompatActivity {
|
||||||
private static final String TAG = "PwdStrAct";
|
private static final String TAG = "PwdStrAct";
|
||||||
private File currentDir;
|
private File currentDir;
|
||||||
private SharedPreferences settings;
|
private SharedPreferences settings;
|
||||||
private Activity activity;
|
private Activity activity;
|
||||||
private PasswordFragment plist;
|
private PasswordFragment plist;
|
||||||
|
private AlertDialog selectDestinationDialog;
|
||||||
|
|
||||||
|
private final static int CLONE_REPO_BUTTON = 401;
|
||||||
|
private final static int NEW_REPO_BUTTON = 402;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -65,7 +69,7 @@ public class PasswordStore extends ActionBarActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
// uninitialize the repo if the dir does not exist or is absolutely empty
|
// uninitialize the repo if the dir does not exist or is absolutely empty
|
||||||
if (!dir.exists() || !dir.isDirectory()) {
|
if (!dir.exists() || !dir.isDirectory() || FileUtils.listFiles(dir, null, false).isEmpty()) {
|
||||||
settings.edit().putBoolean("repository_initialized", false).apply();
|
settings.edit().putBoolean("repository_initialized", false).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,10 +212,12 @@ public class PasswordStore extends ActionBarActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getClone(View view){
|
public void cloneExistingRepository(View view) {
|
||||||
Intent intent = new Intent(this, GitActivity.class);
|
initRepository(CLONE_REPO_BUTTON);
|
||||||
intent.putExtra("Operation", GitActivity.REQUEST_CLONE);
|
}
|
||||||
startActivityForResult(intent, GitActivity.REQUEST_CLONE);
|
|
||||||
|
public void createNewRepository(View view) {
|
||||||
|
initRepository(NEW_REPO_BUTTON);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createRepository() {
|
private void createRepository() {
|
||||||
|
@ -232,7 +238,7 @@ public class PasswordStore extends ActionBarActivity {
|
||||||
checkLocalRepository();
|
checkLocalRepository();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initRepository(View view) {
|
public void initializeRepositoryInfo() {
|
||||||
final String keyId = settings.getString("openpgp_key_ids", "");
|
final String keyId = settings.getString("openpgp_key_ids", "");
|
||||||
|
|
||||||
if (keyId != null && keyId.isEmpty())
|
if (keyId != null && keyId.isEmpty())
|
||||||
|
@ -267,7 +273,13 @@ public class PasswordStore extends ActionBarActivity {
|
||||||
|
|
||||||
if (settings.getBoolean("repository_initialized", false)) {
|
if (settings.getBoolean("repository_initialized", false)) {
|
||||||
// do not push the fragment if we already have it
|
// do not push the fragment if we already have it
|
||||||
if (fragmentManager.findFragmentByTag("PasswordsList") == null) {
|
if (fragmentManager.findFragmentByTag("PasswordsList") == null || settings.getBoolean("repo_changed", false)) {
|
||||||
|
settings.edit().putBoolean("repo_changed", false).apply();
|
||||||
|
|
||||||
|
// todo move this as it is duplicated upthere!
|
||||||
|
if (fragmentManager.findFragmentByTag("PasswordsList") != null) {
|
||||||
|
fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
||||||
|
}
|
||||||
|
|
||||||
// clean things up
|
// clean things up
|
||||||
if (fragmentManager.findFragmentByTag("ToCloneOrNot") != null) {
|
if (fragmentManager.findFragmentByTag("ToCloneOrNot") != null) {
|
||||||
|
@ -425,13 +437,55 @@ public class PasswordStore extends ActionBarActivity {
|
||||||
refreshListAdapter();
|
refreshListAdapter();
|
||||||
break;
|
break;
|
||||||
case GitActivity.REQUEST_INIT:
|
case GitActivity.REQUEST_INIT:
|
||||||
initRepository(getCurrentFocus());
|
initializeRepositoryInfo();
|
||||||
break;
|
break;
|
||||||
case GitActivity.REQUEST_PULL:
|
case GitActivity.REQUEST_PULL:
|
||||||
updateListAdapter();
|
updateListAdapter();
|
||||||
break;
|
break;
|
||||||
|
case NEW_REPO_BUTTON:
|
||||||
|
initializeRepositoryInfo();
|
||||||
|
break;
|
||||||
|
case CLONE_REPO_BUTTON:
|
||||||
|
Intent intent = new Intent(activity, GitActivity.class);
|
||||||
|
intent.putExtra("Operation", GitActivity.REQUEST_CLONE);
|
||||||
|
startActivityForResult(intent, GitActivity.REQUEST_CLONE);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void initRepository(final int operation) {
|
||||||
|
new AlertDialog.Builder(this)
|
||||||
|
.setTitle("Repositiory location")
|
||||||
|
.setMessage("Select where to create or clone your password repository.")
|
||||||
|
.setPositiveButton("External", new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int whichButton) {
|
||||||
|
settings.edit().putBoolean("git_external", true).apply();
|
||||||
|
|
||||||
|
if (settings.getString("git_external_repo", null) == null) {
|
||||||
|
Intent intent = new Intent(activity, UserPreference.class);
|
||||||
|
intent.putExtra("operation", "git_external");
|
||||||
|
startActivityForResult(intent, operation);
|
||||||
|
} else {
|
||||||
|
checkLocalRepository();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton("Internal", new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int whichButton) {
|
||||||
|
settings.edit().putBoolean("git_external", false).apply();
|
||||||
|
switch (operation) {
|
||||||
|
case NEW_REPO_BUTTON:
|
||||||
|
initializeRepositoryInfo();
|
||||||
|
break;
|
||||||
|
case CLONE_REPO_BUTTON:
|
||||||
|
Intent intent = new Intent(activity, GitActivity.class);
|
||||||
|
intent.putExtra("Operation", GitActivity.REQUEST_CLONE);
|
||||||
|
startActivityForResult(intent, GitActivity.REQUEST_CLONE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,10 +110,24 @@ public class UserPreference extends AppCompatActivity {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
findPreference("pref_select_external").setOnPreferenceClickListener((Preference pref) -> {
|
final Preference externalRepo = findPreference("pref_select_external");
|
||||||
|
externalRepo.setSummary(getPreferenceManager().getSharedPreferences().getString("git_external_repo", "No external repository selected"));
|
||||||
|
externalRepo.setOnPreferenceClickListener((Preference pref) -> {
|
||||||
callingActivity.selectExternalGitRepository();
|
callingActivity.selectExternalGitRepository();
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Preference.OnPreferenceChangeListener resetRepo = new Preference.OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object o) {
|
||||||
|
PasswordRepository.closeRepository();
|
||||||
|
getPreferenceManager().getSharedPreferences().edit().putBoolean("repo_changed", true).apply();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
findPreference("pref_select_external").setOnPreferenceChangeListener(resetRepo);
|
||||||
|
findPreference("git_external").setOnPreferenceChangeListener(resetRepo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -34,7 +34,7 @@ import java.util.regex.Pattern;
|
||||||
|
|
||||||
// TODO move the messages to strings.xml
|
// TODO move the messages to strings.xml
|
||||||
|
|
||||||
public class GitActivity extends ActionBarActivity {
|
public class GitActivity extends AppCompatActivity {
|
||||||
private static final String TAG = "GitAct";
|
private static final String TAG = "GitAct";
|
||||||
|
|
||||||
private Activity activity;
|
private Activity activity;
|
||||||
|
@ -56,6 +56,7 @@ public class GitActivity extends ActionBarActivity {
|
||||||
public static final int REQUEST_INIT = 104;
|
public static final int REQUEST_INIT = 104;
|
||||||
public static final int EDIT_SERVER = 105;
|
public static final int EDIT_SERVER = 105;
|
||||||
public static final int REQUEST_SYNC = 106;
|
public static final int REQUEST_SYNC = 106;
|
||||||
|
public static final int REQUEST_CREATE = 107;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="4">
|
android:layout_weight="1">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -35,8 +35,7 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:onClick="openSettings"
|
android:onClick="openSettings"
|
||||||
android:background="@android:color/transparent"
|
style="?android:attr/borderlessButtonStyle"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
||||||
android:text="@string/action_settings"
|
android:text="@string/action_settings"
|
||||||
android:textColor="@android:color/white"
|
android:textColor="@android:color/white"
|
||||||
android:layout_alignParentTop="true"
|
android:layout_alignParentTop="true"
|
||||||
|
@ -45,32 +44,22 @@
|
||||||
android:layout_marginRight="@dimen/activity_horizontal_margin"
|
android:layout_marginRight="@dimen/activity_horizontal_margin"
|
||||||
android:layout_marginEnd="@dimen/activity_horizontal_margin"
|
android:layout_marginEnd="@dimen/activity_horizontal_margin"
|
||||||
android:layout_marginTop="@dimen/activity_vertical_margin"
|
android:layout_marginTop="@dimen/activity_vertical_margin"
|
||||||
android:textStyle="bold"
|
|
||||||
android:textAllCaps="true"/>
|
android:textAllCaps="true"/>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/myRectangleView"
|
android:id="@+id/myRectangleView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="48dp"
|
||||||
android:layout_weight="2"
|
|
||||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||||
android:background="@android:color/white">
|
android:background="@android:color/white">
|
||||||
<TextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="8dp"
|
|
||||||
android:gravity="center_horizontal"
|
|
||||||
android:text="@string/clone_fragment_text"
|
|
||||||
android:id="@+id/textView" />
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@android:color/transparent"
|
style="?android:attr/borderlessButtonStyle"
|
||||||
android:textStyle="bold"
|
android:onClick="createNewRepository"
|
||||||
android:onClick="initRepository"
|
|
||||||
android:text="@string/initialize"
|
android:text="@string/initialize"
|
||||||
android:id="@+id/button"
|
android:id="@+id/button"
|
||||||
android:layout_alignTop="@+id/main_clone_button"
|
android:layout_alignTop="@+id/main_clone_button"
|
||||||
|
@ -80,14 +69,14 @@
|
||||||
android:id="@+id/main_clone_button"
|
android:id="@+id/main_clone_button"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@android:color/transparent"
|
style="?android:attr/borderlessButtonStyle"
|
||||||
android:textColor="@color/deep_orange_500"
|
android:textColor="@color/teal_A700"
|
||||||
android:textStyle="bold"
|
android:onClick="cloneExistingRepository"
|
||||||
android:onClick="getClone"
|
|
||||||
android:text="@string/clone"
|
android:text="@string/clone"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_alignParentEnd="true" />
|
android:layout_alignParentEnd="true" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<!-- Base application theme. -->
|
<!-- Base application theme. -->
|
||||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||||
<item name="colorPrimary">@color/blue_grey_500</item>
|
<item name="colorPrimary">@color/blue_grey_500</item>
|
||||||
<item name="colorPrimaryDark">@color/blue_grey_500</item>
|
<item name="colorPrimaryDark">@color/blue_grey_700</item>
|
||||||
<item name="android:windowBackground">@color/blue_grey_50</item>
|
<item name="android:windowBackground">@color/blue_grey_50</item>
|
||||||
<item name="android:textColorPrimary">@color/teal_900</item>
|
<item name="android:textColorPrimary">@color/teal_900</item>
|
||||||
<item name="android:textColor">@color/text_color</item>
|
<item name="android:textColor">@color/text_color</item>
|
||||||
|
|
Loading…
Reference in a new issue