Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Leaking committed Aug 26, 2015
1 parent 94451d0 commit 434ad50
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.afollestad/material-dialogs/0.7.8.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/cardview-v7/22.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/design/22.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/palette-v7/22.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/22.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/22.2.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.2.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/de.hdodenhof/circleimageview/1.3.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
Expand All @@ -98,10 +99,11 @@
<orderEntry type="library" exported="" name="gson-2.3.1" level="project" />
<orderEntry type="library" exported="" name="palette-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="design-22.2.0" level="project" />
<orderEntry type="library" exported="" name="material-dialogs-0.7.8.1" level="project" />
<orderEntry type="library" exported="" name="butterknife-7.0.1" level="project" />
<orderEntry type="library" exported="" name="circleimageview-1.3.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.2.1" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-22.2.1" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.2.1" level="project" />
Expand Down
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies {
compile 'com.android.support:recyclerview-v7:22.2.0'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
compile 'com.afollestad:material-dialogs:0.7.8.1'
compile project(':httpknife')
compile project(':iconlibrary')
compile project(':breadcrumbs')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.quinn.httpknife.github.Github;
import com.quinn.httpknife.github.GithubError;
import com.quinn.httpknife.github.GithubImpl;
import com.quinn.httpknife.github.OverAuthError;

/**
* Created by Quinn on 8/1/15.
Expand Down Expand Up @@ -71,6 +72,12 @@ public void run() {
msg.what = ERROR;
msg.obj = context.getResources().getString(R.string.auth_error);
handler.sendMessage(msg);
} catch (OverAuthError overAuthError) {
overAuthError.printStackTrace();
Message msg = new Message();
msg.what = ERROR;
msg.obj = context.getResources().getString(R.string.over_auth_error);
handler.sendMessage(msg);
}
}
}).start();;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.accounts.Account;
import android.accounts.AccountAuthenticatorResponse;
import android.accounts.AccountManager;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
Expand All @@ -13,6 +12,7 @@
import android.widget.Button;
import android.widget.EditText;

import com.afollestad.materialdialogs.MaterialDialog;
import com.quinn.githubknife.R;
import com.quinn.githubknife.account.Authenticator;
import com.quinn.githubknife.presenter.CreateTokenPresenter;
Expand All @@ -33,29 +33,34 @@ public class LoginActivity extends BaseActivity implements TokenLoginView {
private AccountAuthenticatorResponse mAccountAuthenticatorResponse = null;
private Bundle mResultBundle = null;

@Nullable @Bind(R.id.toolbar)
@Nullable
@Bind(R.id.toolbar)
Toolbar toolbar;
@Nullable @Bind(R.id.username)
@Nullable
@Bind(R.id.username)
EditText username;
@Nullable @Bind(R.id.password)
@Nullable
@Bind(R.id.password)
EditText password;
@Nullable @Bind(R.id.submit)
@Nullable
@Bind(R.id.submit)
Button submit;

private String accountName;
private String mAuthTokenType;
private String accountType;
private AccountManager mAccountManager;
private CreateTokenPresenter presenter;
private ProgressDialog progressDialog;
private MaterialDialog progressDialog;
private MaterialDialog.Builder builder;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
presenter = new CreateTokenPresenterImpl(this,this);
presenter = new CreateTokenPresenterImpl(this, this);
mAccountManager = AccountManager.get(getBaseContext());
Intent intent = getIntent();
mAccountAuthenticatorResponse =
Expand All @@ -68,13 +73,20 @@ protected void onCreate(Bundle savedInstanceState) {
accountType = intent.getStringExtra(Authenticator.ARG_ACCOUNT_TYPE);

mAuthTokenType = Authenticator.AUTHTOKEN_TYPE_FULL_ACCESS;

builder = new MaterialDialog.Builder(this)
.content(R.string.login)
.cancelable(false)
.progress(true, 0);
}


@OnClick(R.id.submit)
void sumbit() {
presenter.createToken(username.getText().toString(),password.getText().toString());
if (username.getText().toString().isEmpty() || password.getText().toString().isEmpty()) {
ToastUtils.showMsg(this, R.string.input_complete);
return;
}
presenter.createToken(username.getText().toString(), password.getText().toString());
}

@Override
Expand All @@ -100,11 +112,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
}



/**
* Set the result that is to be sent as the result of the request that caused this
* Activity to be launched. If result is null or this method is never called then
* the request will be canceled.
*
* @param result this is returned as the result of the AbstractAccountAuthenticator request
*/
public final void setAccountAuthenticatorResult(Bundle result) {
Expand Down Expand Up @@ -133,20 +145,19 @@ public void finish() {

@Override
public void showProgress() {
progressDialog = ProgressDialog.show(this, "提示", "正在登陆中", true);
progressDialog.setProgressStyle(R.style.AppCompatAlertDialogStyle);
progressDialog = builder.show();
}

@Override
public void hideProgress() {
progressDialog.hide();
progressDialog.dismiss();
}

@Override
public void tokenCreated(String token) {
String accountName = username.getText().toString();
String accountPassword = password.getText().toString();
PreferenceUtils.putString(this,PreferenceUtils.Key.ACCOUNT,accountName);
PreferenceUtils.putString(this, PreferenceUtils.Key.ACCOUNT, accountName);
final Account account = new Account(accountName, accountType);
if (getIntent().getBooleanExtra(Authenticator.ARG_IS_ADDING_NEW_ACCOUNT, true)) {
mAccountManager.addAccountExplicitly(account, accountPassword, null);
Expand All @@ -155,7 +166,7 @@ public void tokenCreated(String token) {
mAccountManager.setPassword(account, accountPassword);
}
Bundle bundle = new Bundle();
bundle.putString(AccountManager.KEY_ACCOUNT_NAME,accountName);
bundle.putString(AccountManager.KEY_ACCOUNT_NAME, accountName);
bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, accountType);
bundle.putString(AccountManager.KEY_AUTHTOKEN, token);
bundle.putString(Authenticator.PARAM_USER_PASS, accountPassword);
Expand All @@ -166,8 +177,7 @@ public void tokenCreated(String token) {

@Override
public void onError(String msg) {
ToastUtils.showMsg(this,msg);
ToastUtils.showMsg(this, msg);
}


}
4 changes: 3 additions & 1 deletion app/src/main/res/layout/activity_user_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/iconStar"
android:text="Starred" />
android:text="Starred"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
/>



Expand Down
9 changes: 8 additions & 1 deletion app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,23 @@
<string name="developing">该模块正在开发中</string>
<string name="network_error">请检查网络,或稍后重试</string>
<string name="auth_error">账号密码错误</string>
<string name="over_auth_error">登陆失败次数太多,请稍后再试</string>
<string name="fail_follow">关注失败: </string>
<string name="fail_unfollow">取消关注失败: </string>
<string name="fail_load_relation">加载好友关系失败</string>
<string name="fail_load_userInfo">加载用户信息失败: </string>
<string name="fail_auth_user">初始化个人信息失败,请检查网络或者稍后重试。</string>
<string name="fail_load_content">获取文件内容</string>
<string name="try_again">重试</string>
<string name="fail_init_warning">初始化失败</string>


<!--提醒-->
<string name="try_again">重试</string>
<string name="input_complete">请输入账号密码</string>
<string name="login">登陆中...</string>



<!--说明-->
<string name="search_warning">你可以输入关键字搜索用户或项目,,,</string>
<string name="username_or_email">用户名或邮箱</string>
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@
<string name="developing">This module is under development!</string>
<string name="network_error">Please check your network</string>
<string name="auth_error">Username or password is incorrect</string>
<string name="over_auth_error">Maximum number of login attempts exceeded. Please try again later.</string>
<string name="fail_follow">Fail to follow </string>
<string name="fail_unfollow">Fail to unfollow </string>
<string name="fail_load_relation">Fail to load relation</string>
<string name="fail_load_userInfo">Fail to load information of </string>
<string name="fail_auth_user">Fail to init your information,You have to check you network condition or try it later. </string>
<string name="fail_load_content">Fail to load file content</string>
<string name="try_again">Try Again</string>
<string name="fail_init_warning">Fail to initial</string>


<!--warning-->
<string name="try_again">Try Again</string>
<string name="input_complete">Input your username and password</string>
<string name="login">Login...</string>


<!--Description-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/**
* Created by Quinn on 8/1/15.
* 账号密码错误抛出该异常
* statusCode 401
*/
public class AuthError extends Exception {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface Github {
*
* @return
*/
public String createToken(String username, String password) throws GithubError, AuthError;
public String createToken(String username, String password) throws GithubError, AuthError,OverAuthError;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ public GithubImpl(Context context) {
public void filterError(Response response) throws GithubError,AuthError{
if (response.isSuccess() == false)
throw githubError;
if (response.statusCode() == 401) {
if (response.statusCode() == _401) {
throw authError;
}
}

@Override
public String createToken(String username, String password)
throws GithubError,AuthError {
throws GithubError,AuthError,OverAuthError {
JSONObject json = new JSONObject();
try {
json.put("note", TOKEN_NOTE);
Expand All @@ -91,10 +91,13 @@ public String createToken(String username, String password)
.basicAuthorization(username, password).json(json).response();
if (response.isSuccess() == false)
throw githubError;
if (response.statusCode() == 401) {
if (response.statusCode() == _401) {
throw new AuthError("username or password is incorrect");
}
if (response.statusCode() == 422) {
if(response.statusCode() == _403){
throw new OverAuthError();
}
if (response.statusCode() == _422) {
removeToken(username, password);
return createToken(username, password);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.quinn.httpknife.github;

/**
* Created by Quinn on 8/26/15.
* 账号密码错误次数太多
* statusCode: 403
*/
public class OverAuthError extends Exception {

public OverAuthError(String exceptionMessage) {
super(exceptionMessage);
}
public OverAuthError(){super();}
}
File renamed without changes

0 comments on commit 434ad50

Please sign in to comment.