Skip to content

Commit 2ab32b0

Browse files
author
CNCoderX
committed
2017-12-01
1 parent b7dbaa7 commit 2ab32b0

File tree

131 files changed

+4317
-1285
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+4317
-1285
lines changed

app/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ android {
3939
dependencies {
4040
compile fileTree(include: ['*.jar'], dir: 'libs')
4141
testCompile 'junit:junit:4.12'
42+
4243
compile 'com.android.support:appcompat-v7:25.3.1'
4344
// compile 'com.android.support:design:25.3.1'
4445

@@ -52,5 +53,7 @@ dependencies {
5253
// exclude group: 'com.google.code.findbugs', module: 'jsr305'
5354
// exclude module: 'jsr305:2.0.1'
5455
// }
55-
compile project(':githubsdk')
56+
// compile project(':githubsdk')
57+
releaseCompile project(path: ':githubsdk', configuration: 'release')
58+
debugCompile project(path: ':githubsdk', configuration: 'debug')
5659
}

app/src/androidTest/java/com/cncoderx/github/ApplicationTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ public class ApplicationTest extends ApplicationTestCase<Application> {
1010
public ApplicationTest() {
1111
super(Application.class);
1212
}
13+
1314
}

app/src/main/AndroidManifest.xml

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
android:windowSoftInputMode="stateHidden|stateUnchanged"
4545
android:label="@string/search">
4646
</activity>
47-
<activity android:name=".ui.activity.RepoDetailActivity"
47+
<activity android:name=".ui.activity.RepositoryActivity"
4848
android:label="@string/repositories">
4949
</activity>
50-
<activity android:name=".ui.activity.CodeContentActivity"
50+
<activity android:name=".ui.activity.TextFileReviewActivity"
5151
android:label="">
5252
</activity>
5353
<activity android:name=".ui.activity.IssueCommentActivity"
@@ -57,18 +57,16 @@
5757
android:label="@string/pull_requests">
5858
</activity>
5959
<activity android:name=".ui.activity.ProfileActivity"
60-
android:label=""
61-
android:launchMode="singleTask">
60+
android:label="">
6261
</activity>
6362
<activity android:name=".ui.activity.OrganizationActivity"
64-
android:label=""
65-
android:launchMode="singleTask">
63+
android:label="">
6664
</activity>
6765
<activity android:name=".ui.activity.FollowerListActivity"
68-
android:label="@string/followers">
66+
android:label="@string/followers2">
6967
</activity>
7068
<activity android:name=".ui.activity.FollowingListActivity"
71-
android:label="@string/following">
69+
android:label="@string/following2">
7270
</activity>
7371
<activity android:name=".ui.activity.GistActivity"
7472
android:label="@string/gists">
@@ -79,6 +77,24 @@
7977
<activity android:name=".ui.activity.SettingActivity"
8078
android:label="@string/settings">
8179
</activity>
80+
<activity android:name=".ui.activity.RepoListActivity"
81+
android:label="@string/repositories">
82+
</activity>
83+
<activity android:name=".ui.activity.GistListActivity"
84+
android:label="@string/gists">
85+
</activity>
86+
<activity android:name=".ui.activity.OrganListActivity"
87+
android:label="@string/organizations">
88+
</activity>
89+
<activity android:name=".ui.activity.MemberListActivity"
90+
android:label="@string/members">
91+
</activity>
92+
<activity android:name=".ui.activity.AccountListActivity"
93+
android:label="@string/accounts">
94+
</activity>
95+
<activity android:name=".ui.activity.AboutActivity"
96+
android:label="@string/about">
97+
</activity>
8298

8399
<service android:name=".service.AccountAuthenticatorService"
84100
android:exported="false">

app/src/main/assets/icon.ttf

864 Bytes
Binary file not shown.

app/src/main/java/com/cncoderx/github/AppContext.java

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.support.annotation.Nullable;
88
import android.util.DisplayMetrics;
99

10+
import com.cncoderx.github.accounts.GitAccountManager;
1011
import com.cncoderx.github.preference.SettingPreference;
1112
import com.cncoderx.github.sdk.AuthorizationInterceptor;
1213
import com.cncoderx.github.sdk.HttpConfig;
@@ -32,6 +33,8 @@ public void onCreate() {
3233
super.onCreate();
3334
instance = this;
3435

36+
GitAccountManager.initialize(this);
37+
3538
AuthorizationInterceptor.addAccessURLPath("/applications");
3639
AuthorizationInterceptor.addAccessURLPath("/authorizations");
3740

@@ -43,30 +46,17 @@ public void onCreate() {
4346

4447
Typefaces.replaceSystemDefaultFont(this, "Arial.ttf");
4548

46-
int lang = new SettingPreference(this).getLanguage();
47-
switch (lang) {
48-
case 0:
49-
setLocale(Locale.getDefault());
50-
break;
51-
case 1:
52-
setLocale(Locale.ENGLISH);
53-
break;
54-
case 2:
55-
setLocale(Locale.SIMPLIFIED_CHINESE);
56-
break;
57-
case 3:
58-
setLocale(Locale.TRADITIONAL_CHINESE);
59-
break;
60-
}
49+
Locale locale = new SettingPreference(this).getLocale();
50+
setLocale(locale);
6151
}
6252

63-
public String getLoginName() {
64-
return TokenStore.getInstance(this).getName();
65-
}
66-
67-
public void setLoginName(String loginName) {
68-
TokenStore.getInstance(this).setName(loginName);
69-
}
53+
// public String getLoginName() {
54+
// return TokenStore.getInstance(this).getName();
55+
// }
56+
//
57+
// public void setLoginName(String loginName) {
58+
// TokenStore.getInstance(this).setName(loginName);
59+
// }
7060

7161
public void setToken(String token) {
7262
TokenStore.getInstance(this).setToken(token);

app/src/main/java/com/cncoderx/github/accounts/AccountAuthenticator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public Bundle editProperties(AccountAuthenticatorResponse response, String accou
3434
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException {
3535
Intent intent = new Intent(mContext, LoginActivity.class);
3636
intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
37-
intent.putExtra(AccountManager.KEY_BOOLEAN_RESULT, true); // new account
37+
intent.putExtra(AccountManager.KEY_BOOLEAN_RESULT, true); // new name
3838
Bundle bundle = new Bundle();
3939
bundle.putParcelable(AccountManager.KEY_INTENT, intent);
4040
return bundle;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.cncoderx.github.accounts;
2+
3+
import android.support.annotation.NonNull;
4+
5+
/**
6+
* @author cncoderx
7+
*/
8+
public class GitAccount implements Comparable<GitAccount> {
9+
String name;
10+
String password;
11+
String token;
12+
String avatar;
13+
long updated;
14+
15+
public String getName() {
16+
return name;
17+
}
18+
19+
public String getPassword() {
20+
return password;
21+
}
22+
23+
public String getToken() {
24+
return token;
25+
}
26+
27+
public String getAvatar() {
28+
return avatar;
29+
}
30+
31+
public long getUpdated() {
32+
return updated;
33+
}
34+
35+
@Override
36+
public int compareTo(@NonNull GitAccount account) {
37+
return (int) (account.updated - updated);
38+
}
39+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package com.cncoderx.github.accounts;
2+
3+
import android.accounts.Account;
4+
import android.accounts.AccountManager;
5+
import android.app.Activity;
6+
import android.content.Context;
7+
import android.os.Build;
8+
import android.text.TextUtils;
9+
10+
import com.cncoderx.github.utils.Constants;
11+
12+
import java.util.Arrays;
13+
import java.util.HashMap;
14+
15+
/**
16+
* @author cncoderx
17+
*/
18+
public class GitAccountManager {
19+
private static AccountManager sAccountManager;
20+
private static HashMap<String, Account> sAccountPools;
21+
22+
public static void initialize(Context context) {
23+
sAccountManager = AccountManager.get(context);
24+
sAccountPools = new HashMap<>();
25+
}
26+
27+
public static GitAccount[] getGitAccounts() {
28+
Account[] accounts = sAccountManager.getAccountsByType(Constants.ACCOUNT_TYPE);
29+
int length = accounts.length;
30+
if (length > 0) {
31+
GitAccount[] gitAccounts = new GitAccount[length];
32+
int index = 0;
33+
for (Account account : accounts) {
34+
GitAccount gitAccount = new GitAccount();
35+
gitAccount.name = account.name;
36+
gitAccount.password = sAccountManager.getPassword(account);
37+
gitAccount.token = sAccountManager.peekAuthToken(account, Constants.TOKEN_TYPE);
38+
gitAccount.avatar = sAccountManager.getUserData(account, ACCOUNT_AVATAR);
39+
String updated = sAccountManager.getUserData(account, ACCOUNT_UPDATED);
40+
gitAccount.updated = TextUtils.isEmpty(updated) ? 0 : Long.parseLong(updated);
41+
gitAccounts[index++] = gitAccount;
42+
}
43+
Arrays.sort(gitAccounts);
44+
return gitAccounts;
45+
}
46+
return new GitAccount[0];
47+
}
48+
49+
public static boolean addGitAccount(String user, String pwd, String token) {
50+
Account account = obtainAccount(user);
51+
boolean result = sAccountManager.addAccountExplicitly(account, pwd, null);
52+
if (result) {
53+
sAccountManager.setAuthToken(account, Constants.TOKEN_TYPE, token);
54+
sAccountManager.setUserData(account, ACCOUNT_UPDATED, Long.toString(System.currentTimeMillis()));
55+
}
56+
return result;
57+
}
58+
59+
public static void updateGitAccount(String user, String pwd, String token) {
60+
Account account = obtainAccount(user);
61+
sAccountManager.setPassword(account, pwd);
62+
sAccountManager.setAuthToken(account, Constants.TOKEN_TYPE, token);
63+
sAccountManager.setUserData(account, ACCOUNT_UPDATED, Long.toString(System.currentTimeMillis()));
64+
}
65+
66+
public static void removeGitAccount(Activity activity, String user) {
67+
Account account = obtainAccount(user);
68+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
69+
sAccountManager.removeAccount(account, activity, null, null);
70+
} else {
71+
sAccountManager.removeAccount(account, null, null);
72+
}
73+
}
74+
75+
public static void updateGitAccountAvatar(String user, String avatar) {
76+
Account account = obtainAccount(user);
77+
sAccountManager.setUserData(account, ACCOUNT_AVATAR, avatar);
78+
}
79+
80+
public static void getGitAccountAvatar(String user) {
81+
Account account = obtainAccount(user);
82+
sAccountManager.getUserData(account, ACCOUNT_AVATAR);
83+
}
84+
85+
public static String getGitAccountToken(String user) {
86+
Account account = obtainAccount(user);
87+
return sAccountManager.peekAuthToken(account, Constants.TOKEN_TYPE);
88+
}
89+
90+
public static void invalidateAuthToken(String token) {
91+
sAccountManager.invalidateAuthToken(Constants.ACCOUNT_TYPE, token);
92+
}
93+
94+
private static Account obtainAccount(String user) {
95+
Account account = sAccountPools.get(user);
96+
if (account == null) {
97+
account = new Account(user, Constants.ACCOUNT_TYPE);
98+
sAccountPools.put(user, account);
99+
}
100+
return account;
101+
}
102+
103+
static final String ACCOUNT_AVATAR = "avatar";
104+
static final String ACCOUNT_UPDATED = "updated";
105+
106+
}

app/src/main/java/com/cncoderx/github/preference/BasePreference.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,35 @@ public BasePreference(Context context, String name, int mode) {
1818
mSharedPreferences = context.getApplicationContext().getSharedPreferences(name, mode);
1919
}
2020

21-
protected SharedPreferences.Editor putString(String key, String value) {
21+
public SharedPreferences.Editor putString(String key, String value) {
2222
return getEditor().putString(key, value);
2323
}
2424

25-
protected SharedPreferences.Editor putStringSet(String key, Set<String> values) {
25+
public SharedPreferences.Editor putStringSet(String key, Set<String> values) {
2626
return getEditor().putStringSet(key, values);
2727
}
2828

29-
protected SharedPreferences.Editor putInt(String key, int value) {
29+
public SharedPreferences.Editor putInt(String key, int value) {
3030
return getEditor().putInt(key, value);
3131
}
3232

33-
protected SharedPreferences.Editor putLong(String key, long value) {
33+
public SharedPreferences.Editor putLong(String key, long value) {
3434
return getEditor().putLong(key, value);
3535
}
3636

37-
protected SharedPreferences.Editor putFloat(String key, float value) {
37+
public SharedPreferences.Editor putFloat(String key, float value) {
3838
return getEditor().putFloat(key, value);
3939
}
4040

41-
protected SharedPreferences.Editor putBoolean(String key, boolean value) {
41+
public SharedPreferences.Editor putBoolean(String key, boolean value) {
4242
return getEditor().putBoolean(key, value);
4343
}
4444

45-
protected SharedPreferences.Editor remove(String key) {
45+
public SharedPreferences.Editor remove(String key) {
4646
return getEditor().remove(key);
4747
}
4848

49-
protected SharedPreferences.Editor clear() {
49+
public SharedPreferences.Editor clear() {
5050
return getEditor().clear();
5151
}
5252

@@ -56,35 +56,35 @@ private SharedPreferences.Editor getEditor() {
5656
return mEditor;
5757
}
5858

59-
protected Map<String, ?> getAll() {
59+
public Map<String, ?> getAll() {
6060
return mSharedPreferences.getAll();
6161
}
6262

63-
protected String getString(String key) {
63+
public String getString(String key) {
6464
return mSharedPreferences.getString(key, "");
6565
}
6666

67-
protected Set<String> getStringSet(String key) {
67+
public Set<String> getStringSet(String key) {
6868
return mSharedPreferences.getStringSet(key, null);
6969
}
7070

71-
protected int getInt(String key) {
71+
public int getInt(String key) {
7272
return mSharedPreferences.getInt(key, 0);
7373
}
7474

75-
protected long getLong(String key) {
75+
public long getLong(String key) {
7676
return mSharedPreferences.getLong(key, 0L);
7777
}
7878

79-
protected float getFloat(String key) {
79+
public float getFloat(String key) {
8080
return mSharedPreferences.getFloat(key, 0f);
8181
}
8282

83-
protected boolean getBoolean(String key) {
83+
public boolean getBoolean(String key) {
8484
return mSharedPreferences.getBoolean(key, false);
8585
}
8686

87-
protected boolean contains(String key) {
87+
public boolean contains(String key) {
8888
return mSharedPreferences.contains(key);
8989
}
9090

0 commit comments

Comments
 (0)