Skip to content

Commit

Permalink
fix crash when bundle data is too large
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirtyDegreesRay committed Sep 14, 2017
1 parent 6f829b2 commit dcf12f2
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ interface View extends IBaseContract.View {

void setCanLoadMore(boolean canLoadMore);

void showLoginPage();

}

interface Presenter extends IBaseContract.Presenter<IRepositoriesContract.View> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.thirtydegreesray.openhub.mvp.presenter;

import android.os.Bundle;

import com.thirtydegreesray.dataautoaccess.annotation.AutoAccess;
import com.thirtydegreesray.openhub.AppConfig;
import com.thirtydegreesray.openhub.common.Event;
Expand Down Expand Up @@ -52,6 +54,12 @@ public RepoInfoPresenter(DaoSession daoSession) {
setEventSubscriber(true);
}

@Override
public void onSaveInstanceState(Bundle outState) {
checkReadmeSourceSize();
super.onSaveInstanceState(outState);
}

@Override
public void onViewInitialized() {
super.onViewInitialized();
Expand Down Expand Up @@ -105,4 +113,13 @@ public void onRepoInfoUpdated(Event.RepoInfoUpdatedEvent event){
mView.showRepoInfo(repository);
}

/**
* check if the string size is too large to save
*/
private void checkReadmeSourceSize(){
if(readmeSource != null && readmeSource.getBytes().length > 128 * 1024){
readmeSource = null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ public void onSearchEvent(@NonNull Event.SearchEvent searchEvent) {
}

private void handleError(Throwable error){
if(!StringUtils.isBlankList(repos)){
if(checkIsUnauthorized(error)){

} else if(!StringUtils.isBlankList(repos)){
mView.showErrorToast(getErrorTip(error));
} else if(error instanceof HttpPageNoFoundError){
mView.showRepositories(new ArrayList<Repository>());
Expand All @@ -197,4 +199,16 @@ public String getUser() {
public RepositoriesFragment.RepositoriesType getType() {
return type;
}

private boolean checkIsUnauthorized(Throwable error){
if(getErrorTip(error).equals("Unauthorized")){
daoSession.getAuthUserDao().delete(AppData.INSTANCE.getAuthUser());
AppData.INSTANCE.setAuthUser(null);
AppData.INSTANCE.setLoggedUser(null);
mView.showLoginPage();
return true;
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.thirtydegreesray.openhub.mvp.presenter;

import android.support.annotation.NonNull;
import android.util.Log;

import com.thirtydegreesray.openhub.AppData;
import com.thirtydegreesray.openhub.dao.AuthUser;
Expand Down Expand Up @@ -97,7 +96,10 @@ private void getUserInfo(final String accessToken) {
HttpObserver<User> httpObserver = new HttpObserver<User>() {
@Override
public void onError(@NonNull Throwable error) {
daoSession.getAuthUserDao().delete(AppData.INSTANCE.getAuthUser());
AppData.INSTANCE.setAuthUser(null);
mView.showErrorToast(getErrorTip(error));
mView.showLoginPage();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.thirtydegreesray.openhub.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand All @@ -31,6 +32,7 @@
import com.thirtydegreesray.openhub.mvp.model.Repository;
import com.thirtydegreesray.openhub.mvp.model.SearchModel;
import com.thirtydegreesray.openhub.mvp.presenter.RepositoriesPresenter;
import com.thirtydegreesray.openhub.ui.activity.LoginActivity;
import com.thirtydegreesray.openhub.ui.activity.RepositoryActivity;
import com.thirtydegreesray.openhub.ui.adapter.RepositoriesAdapter;
import com.thirtydegreesray.openhub.ui.fragment.base.ListFragment;
Expand Down Expand Up @@ -102,6 +104,13 @@ public void showRepositories(ArrayList<Repository> repositoryList) {
adapter.notifyDataSetChanged();
}

@Override
public void showLoginPage() {
getActivity().finishAffinity();
Intent intent = new Intent(getActivity(), LoginActivity.class);
startActivity(intent);
}

@Override
protected int getLayoutId() {
return R.layout.fragment_list;
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ TARGET_SDK_VERSION = 25
#MIN_SDK_VERSION = 21
#TARGET_SDK_VERSION = 26

VERSION_CODE = 3
VERSION_NAME = 1.0.1
VERSION_CODE = 4
VERSION_NAME = 1.0.2

#library
#ANDROID_SUPPORT_VERSION = 26.0.0-alpha1
Expand Down

0 comments on commit dcf12f2

Please sign in to comment.