diff options
author | Mohamed Zenadi <mohamed@zenadi.com> | 2015-05-03 17:32:07 +0200 |
---|---|---|
committer | Mohamed Zenadi <mohamed@zenadi.com> | 2015-05-17 18:58:03 +0200 |
commit | ceb183727f758b7c8baa1c01b7280b35013c070a (patch) | |
tree | 0b02becad02abff8b48c687a071dd180dba97608 /app | |
parent | 4975dfdcfaef453f564eb2dadca7580e47a3d2a6 (diff) |
user is able to chose internal/external when creating/cloning
also no longer needed to close to refresh the list
Diffstat (limited to 'app')
6 files changed, 97 insertions, 39 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java index 48e33892..07ed9895 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java @@ -5,7 +5,7 @@ import android.app.Fragment; import android.content.SharedPreferences; import android.os.Bundle; 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.RecyclerView; import android.util.Log; @@ -105,7 +105,7 @@ public class PasswordFragment extends Fragment{ recyclerAdapter.clear(); recyclerAdapter.addAll(PasswordRepository.getPasswords(item.getFile())); - ((ActionBarActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); + ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); } else { ((PasswordStore) getActivity()).decryptPassword(item); } @@ -138,7 +138,7 @@ public class PasswordFragment extends Fragment{ recyclerAdapter.clear(); recyclerAdapter.addAll(PasswordRepository.getPasswords()); - ((ActionBarActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false); + ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false); } /** diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java index a08e7d88..c788821f 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java @@ -10,7 +10,7 @@ import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; 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.util.Log; import android.view.Menu; @@ -29,12 +29,16 @@ import org.eclipse.jgit.api.Git; import java.io.File; -public class PasswordStore extends ActionBarActivity { +public class PasswordStore extends AppCompatActivity { private static final String TAG = "PwdStrAct"; private File currentDir; private SharedPreferences settings; private Activity activity; private PasswordFragment plist; + private AlertDialog selectDestinationDialog; + + private final static int CLONE_REPO_BUTTON = 401; + private final static int NEW_REPO_BUTTON = 402; @Override 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 - if (!dir.exists() || !dir.isDirectory()) { + if (!dir.exists() || !dir.isDirectory() || FileUtils.listFiles(dir, null, false).isEmpty()) { settings.edit().putBoolean("repository_initialized", false).apply(); } @@ -208,10 +212,12 @@ public class PasswordStore extends ActionBarActivity { } } - public void getClone(View view){ - Intent intent = new Intent(this, GitActivity.class); - intent.putExtra("Operation", GitActivity.REQUEST_CLONE); - startActivityForResult(intent, GitActivity.REQUEST_CLONE); + public void cloneExistingRepository(View view) { + initRepository(CLONE_REPO_BUTTON); + } + + public void createNewRepository(View view) { + initRepository(NEW_REPO_BUTTON); } private void createRepository() { @@ -232,7 +238,7 @@ public class PasswordStore extends ActionBarActivity { checkLocalRepository(); } - public void initRepository(View view) { + public void initializeRepositoryInfo() { final String keyId = settings.getString("openpgp_key_ids", ""); if (keyId != null && keyId.isEmpty()) @@ -267,7 +273,13 @@ public class PasswordStore extends ActionBarActivity { if (settings.getBoolean("repository_initialized", false)) { // 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 if (fragmentManager.findFragmentByTag("ToCloneOrNot") != null) { @@ -425,13 +437,55 @@ public class PasswordStore extends ActionBarActivity { refreshListAdapter(); break; case GitActivity.REQUEST_INIT: - initRepository(getCurrentFocus()); + initializeRepositoryInfo(); break; case GitActivity.REQUEST_PULL: updateListAdapter(); 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(); + } } diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java index fbdc7d3d..00e71ae8 100644 --- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java +++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java @@ -110,10 +110,24 @@ public class UserPreference extends AppCompatActivity { 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(); 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); } } diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java b/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java index b763a275..2d8f2e5a 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java @@ -8,7 +8,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.text.Editable; import android.text.TextWatcher; import android.util.Log; @@ -34,7 +34,7 @@ import java.util.regex.Pattern; // TODO move the messages to strings.xml -public class GitActivity extends ActionBarActivity { +public class GitActivity extends AppCompatActivity { private static final String TAG = "GitAct"; private Activity activity; @@ -56,6 +56,7 @@ public class GitActivity extends ActionBarActivity { public static final int REQUEST_INIT = 104; public static final int EDIT_SERVER = 105; public static final int REQUEST_SYNC = 106; + public static final int REQUEST_CREATE = 107; @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/res/layout/fragment_to_clone_or_not.xml b/app/src/main/res/layout/fragment_to_clone_or_not.xml index f1f8cdd9..58e21418 100644 --- a/app/src/main/res/layout/fragment_to_clone_or_not.xml +++ b/app/src/main/res/layout/fragment_to_clone_or_not.xml @@ -9,7 +9,7 @@ <RelativeLayout android:layout_width="match_parent" android:layout_height="0dp" - android:layout_weight="4"> + android:layout_weight="1"> <ImageView android:layout_width="wrap_content" @@ -35,8 +35,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="openSettings" - android:background="@android:color/transparent" - android:textAppearance="?android:attr/textAppearanceSmall" + style="?android:attr/borderlessButtonStyle" android:text="@string/action_settings" android:textColor="@android:color/white" android:layout_alignParentTop="true" @@ -45,32 +44,22 @@ android:layout_marginRight="@dimen/activity_horizontal_margin" android:layout_marginEnd="@dimen/activity_horizontal_margin" android:layout_marginTop="@dimen/activity_vertical_margin" - android:textStyle="bold" android:textAllCaps="true"/> </RelativeLayout> <RelativeLayout android:id="@+id/myRectangleView" android:layout_width="match_parent" - android:layout_height="0dp" - android:layout_weight="2" + android:layout_height="48dp" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" 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 android:layout_width="wrap_content" android:layout_height="wrap_content" - android:background="@android:color/transparent" - android:textStyle="bold" - android:onClick="initRepository" + style="?android:attr/borderlessButtonStyle" + android:onClick="createNewRepository" android:text="@string/initialize" android:id="@+id/button" android:layout_alignTop="@+id/main_clone_button" @@ -80,14 +69,14 @@ android:id="@+id/main_clone_button" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:background="@android:color/transparent" - android:textColor="@color/deep_orange_500" - android:textStyle="bold" - android:onClick="getClone" + style="?android:attr/borderlessButtonStyle" + android:textColor="@color/teal_A700" + android:onClick="cloneExistingRepository" android:text="@string/clone" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" /> + </RelativeLayout> </LinearLayout> diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index a183f724..3fffef42 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -3,7 +3,7 @@ <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <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:textColorPrimary">@color/teal_900</item> <item name="android:textColor">@color/text_color</item> |