Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate git profile into user settings #221

Merged
merged 1 commit into from
Aug 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions src/main/java/me/sheimi/android/utils/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,36 @@
import android.content.SharedPreferences;

import me.sheimi.sgit.R;
import me.sheimi.sgit.SGitApplication;
import me.sheimi.sgit.database.models.Repo;

/**
* Created by lee on 2015-02-01.
*/
public class Profile {

private static final String GIT_USER_NAME = "user.name";
private static final String GIT_USER_EMAIL = "user.email";
private static SharedPreferences sSharedPreference;

private static boolean sHasLastCloneFail = false;
private static Repo sLastFailRepo;

private static SharedPreferences getProfileSharedPreference() {
private static SharedPreferences getProfileSharedPreference(Context context) {
if (sSharedPreference == null) {
sSharedPreference = BasicFunctions.getActiveActivity().getSharedPreferences(
BasicFunctions.getActiveActivity().getString(R.string.preference_file_key),
sSharedPreference = context.getSharedPreferences(
context.getString(R.string.preference_file_key),
Context.MODE_PRIVATE);
}
return sSharedPreference;
}

public static String getUsername() {
return getProfileSharedPreference().getString(GIT_USER_NAME, "");
public static String getUsername(Context context) {
String userNamePrefKey = context.getString(R.string.pref_key_git_user_name);
return getProfileSharedPreference(context).getString(userNamePrefKey, "");
}

public static String getEmail() {
return getProfileSharedPreference().getString(GIT_USER_EMAIL, "");
}

public static void setProfileInformation(String username, String email) {
SharedPreferences.Editor editor = getProfileSharedPreference().edit();
editor.putString(Profile.GIT_USER_NAME, username);
editor.putString(Profile.GIT_USER_EMAIL, email);
editor.commit();
public static String getEmail(Context context) {
String userEmailPrefKey = context.getString(R.string.pref_key_git_user_email);
return getProfileSharedPreference(context).getString(userEmailPrefKey, "");
}

public static boolean hasLastCloneFailed() {
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/me/sheimi/sgit/RepoListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import me.sheimi.sgit.adapters.RepoListAdapter;
import me.sheimi.sgit.dialogs.CloneDialog;
import me.sheimi.sgit.dialogs.ImportLocalRepoDialog;
import me.sheimi.sgit.dialogs.ProfileDialog;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
Expand Down Expand Up @@ -62,10 +61,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
CloneDialog cloneDialog = new CloneDialog();
cloneDialog.show(getFragmentManager(), "clone-dialog");
return true;
case R.id.action_git_profile:
ProfileDialog profileDialog = new ProfileDialog();
profileDialog.show(getFragmentManager(), "profile-dialog");
return true;
case R.id.action_import_repo:
intent = new Intent(this, ImportRepositoryActivity.class);
startActivityForResult(intent, REQUEST_IMPORT_REPO);
Expand Down
59 changes: 0 additions & 59 deletions src/main/java/me/sheimi/sgit/dialogs/ProfileDialog.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package me.sheimi.sgit.repo.tasks.repo;

import java.lang.Exception;

import me.sheimi.android.utils.BasicFunctions;
import me.sheimi.android.utils.Profile;
import me.sheimi.sgit.R;
import me.sheimi.sgit.database.models.Repo;
import me.sheimi.sgit.exception.StopTaskException;
import android.content.Context;

import org.eclipse.jgit.api.CommitCommand;
import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
Expand All @@ -16,8 +10,11 @@
import org.eclipse.jgit.api.errors.UnmergedPathsException;
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;

import android.content.Context;
import android.content.SharedPreferences;
import me.sheimi.android.utils.Profile;
import me.sheimi.sgit.R;
import me.sheimi.sgit.SGitApplication;
import me.sheimi.sgit.database.models.Repo;
import me.sheimi.sgit.exception.StopTaskException;

public class CommitChangesTask extends RepoOpTask {

Expand Down Expand Up @@ -68,13 +65,9 @@ public static void commit(Repo repo, boolean stageAll, boolean isAmend,
String msg) throws Exception, NoHeadException, NoMessageException,
UnmergedPathsException, ConcurrentRefUpdateException,
WrongRepositoryStateException, GitAPIException, StopTaskException {
SharedPreferences sharedPreferences = BasicFunctions
.getActiveActivity().getSharedPreferences(
BasicFunctions.getActiveActivity().getString(
R.string.preference_file_key),
Context.MODE_PRIVATE);
String committerName = Profile.getUsername();
String committerEmail = Profile.getEmail();
Context context = SGitApplication.getContext();
String committerName = Profile.getUsername(context);
String committerEmail = Profile.getEmail(context);
if (committerName == "" || committerEmail == "") {
throw new Exception("Please set your name and email");
}
Expand Down
4 changes: 0 additions & 4 deletions src/main/res/menu/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
android:icon="@drawable/ic_action_settings"
android:title="@string/action_settings"
android:showAsAction="ifRoom"/>
<item
android:id="@+id/action_git_profile"
android:showAsAction="never"
android:title="@string/action_git_profile"/>
<item
android:id="@+id/action_add_private_key"
android:showAsAction="never"
Expand Down
5 changes: 5 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,10 @@
<string name="pref_key_repo_root_location">repo_root_path</string>
<string name="action_select_root_dir">Select as Root folder</string>
<string name="action_create_new_dir">Create new folder</string>
<string name="pref_category_title_git_profile">Git Profile</string>
<string name="pref_key_git_user_name">user.name</string>
<string name="preference_git_user_name">User Name</string>
<string name="pref_key_git_user_email">user.email</string>
<string name="preference_git_user_email">User Email</string>

</resources>
23 changes: 23 additions & 0 deletions src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,27 @@
/>
</me.sheimi.sgit.preference.Preference>
</PreferenceCategory>

<PreferenceCategory
android:key="pref_key_storage_root_location"
android:title="@string/pref_category_title_git_profile">

<me.sheimi.sgit.preference.EditTextPreference
android:title="@string/preference_git_user_name"
android:key="@string/pref_key_git_user_name"
android:summary="%s"
android:persistent="true"
>
</me.sheimi.sgit.preference.EditTextPreference>

<me.sheimi.sgit.preference.EditTextPreference
android:title="@string/preference_git_user_email"
android:key="@string/pref_key_git_user_email"
android:summary="%s"
android:persistent="true"
>
</me.sheimi.sgit.preference.EditTextPreference>
</PreferenceCategory>


</PreferenceScreen>