Browse Source

Many null, some async and update libs

master
Michel Roux 6 years ago
parent
commit
f6a4012d0f
  1. 2
      build.gradle
  2. 6
      ehreader/build.gradle
  3. 2
      ehreader/src/tw/skyarrow/ehreader/BaseApplication.java
  4. 68
      ehreader/src/tw/skyarrow/ehreader/api/DataLoader.java
  5. 13
      ehreader/src/tw/skyarrow/ehreader/app/DrawerActivity.java
  6. 9
      ehreader/src/tw/skyarrow/ehreader/app/gallery/GalleryActivity.java
  7. 6
      ehreader/src/tw/skyarrow/ehreader/app/gallery/GalleryIntentActivity.java
  8. 17
      ehreader/src/tw/skyarrow/ehreader/app/main/MainActivity.java
  9. 6
      ehreader/src/tw/skyarrow/ehreader/app/photo/CropActivity.java
  10. 13
      ehreader/src/tw/skyarrow/ehreader/app/photo/PhotoActivity.java
  11. 6
      ehreader/src/tw/skyarrow/ehreader/app/photo/PhotoDeleteDialog.java
  12. 6
      ehreader/src/tw/skyarrow/ehreader/app/photo/PhotoIntentActivity.java
  13. 4
      ehreader/src/tw/skyarrow/ehreader/app/pref/PrefActivity.java
  14. 4
      ehreader/src/tw/skyarrow/ehreader/app/search/ImageSearchActivity.java
  15. 2
      ehreader/src/tw/skyarrow/ehreader/app/search/ImageSearchSelectFragment.java
  16. 9
      ehreader/src/tw/skyarrow/ehreader/app/search/SearchActivity.java
  17. 4
      ehreader/src/tw/skyarrow/ehreader/db/GalleryBase.java
  18. 3
      ehreader/src/tw/skyarrow/ehreader/provider/PhotoProvider.java
  19. 2
      ehreader/src/tw/skyarrow/ehreader/service/UpdateCheckService.java
  20. 6
      ehreader/src/tw/skyarrow/ehreader/util/HttpRequestHelper.java
  21. 7
      ehreader/src/tw/skyarrow/ehreader/util/LoginHelper.java
  22. 2
      gradle/wrapper/gradle-wrapper.properties

2
build.gradle

@ -4,7 +4,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.1'
classpath 'com.android.tools.build:gradle:1.1.0'
}
}

6
ehreader/build.gradle

@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion '23.0.1'
buildToolsVersion '23.0.2'
defaultConfig {
minSdkVersion 14
@ -59,8 +59,8 @@ android {
dependencies {
compile 'com.android.support:support-v4:19.0.+'
compile 'com.github.chrisbanes.photoview:library:1.2.3'
compile 'de.greenrobot:greendao:2.0.0'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'de.greenrobot:greendao:2.1.0'
compile 'de.greenrobot:eventbus:2.4.1'
compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
compile 'org.apache.httpcomponents:httpmime:4.5.1'
compile 'com.jakewharton:butterknife:7.0.1'

2
ehreader/src/tw/skyarrow/ehreader/BaseApplication.java

@ -49,7 +49,7 @@ public class BaseApplication extends Application {
updateHelper.setupAlarm();
editor.putBoolean(getString(R.string.pref_first_installed), false);
editor.commit();
editor.apply();
}
}

68
ehreader/src/tw/skyarrow/ehreader/api/DataLoader.java

@ -204,33 +204,36 @@ public class DataLoader {
String content = HttpRequestHelper.readResponse(response);
List<Photo> list = new ArrayList<Photo>();
long galleryId = gallery.getId();
Matcher matcher = pPhotoUrl.matcher(content);
while (matcher.find()) {
String token = matcher.group(2);
int photoPage = Integer.parseInt(matcher.group(4));
Photo photo = getPhotoInDb(galleryId, photoPage);
if (content != null) {
long galleryId = gallery.getId();
Matcher matcher = pPhotoUrl.matcher(content);
L.d("Photo found: {galleryId: %d, token: %s, page: %d}", galleryId, token, photoPage);
while (matcher.find()) {
String token = matcher.group(2);
int photoPage = Integer.parseInt(matcher.group(4));
Photo photo = getPhotoInDb(galleryId, photoPage);
if (photo != null) {
photo.setToken(token);
photoDao.updateInTx(photo);
} else {
photo = new Photo();
L.d("Photo found: {galleryId: %d, token: %s, page: %d}", galleryId, token, photoPage);
photo.setGalleryId(galleryId);
photo.setToken(token);
photo.setPage(photoPage);
photo.setDownloaded(false);
photo.setBookmarked(false);
photo.setInvalid(false);
if (photo != null) {
photo.setToken(token);
photoDao.updateInTx(photo);
} else {
photo = new Photo();
photoDao.insertInTx(photo);
}
photo.setGalleryId(galleryId);
photo.setToken(token);
photo.setPage(photoPage);
photo.setDownloaded(false);
photo.setBookmarked(false);
photo.setInvalid(false);
photoDao.insertInTx(photo);
}
list.add(photo);
list.add(photo);
}
}
return list;
@ -293,7 +296,7 @@ public class DataLoader {
src = "http://" + matcher.group(2) + "=" + matcher.group(3) + "/" + filename;
}
if (src.isEmpty() || filename.isEmpty()) {
if (src == null || src.isEmpty() || filename.isEmpty()) {
throw new ApiCallException(ApiErrorCode.PHOTO_NOT_FOUND);
}
@ -425,19 +428,22 @@ public class DataLoader {
HttpGet httpGet = new HttpGet(url);
HttpResponse response = getHttpResponse(httpGet);
String html = HttpRequestHelper.readResponse(response);
Matcher matcher = pGalleryURL.matcher(html);
JSONArray gidlist = new JSONArray();
while (matcher.find()) {
long id = Long.parseLong(matcher.group(2));
String token = matcher.group(3);
JSONArray arr = new JSONArray();
if (html != null) {
Matcher matcher = pGalleryURL.matcher(html);
arr.put(id);
arr.put(token);
while (matcher.find()) {
long id = Long.parseLong(matcher.group(2));
String token = matcher.group(3);
JSONArray arr = new JSONArray();
L.d("Gallery found: {id: %d, token: %s}", id, token);
gidlist.put(arr);
arr.put(id);
arr.put(token);
L.d("Gallery found: {id: %d, token: %s}", id, token);
gidlist.put(arr);
}
}
return getGalleryList(gidlist);

13
ehreader/src/tw/skyarrow/ehreader/app/DrawerActivity.java

@ -65,8 +65,11 @@ public abstract class DrawerActivity extends FragmentActivity {
drawerLayout.setDrawerListener(drawerToggle);
drawerLayout.setDrawerShadow(R.drawable.navigation_drawer_shadow, Gravity.START);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
}
}
@Override
@ -77,11 +80,7 @@ public abstract class DrawerActivity extends FragmentActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (drawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
return drawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item);
}
public DrawerLayout getDrawerLayout() {

9
ehreader/src/tw/skyarrow/ehreader/app/gallery/GalleryActivity.java

@ -129,8 +129,10 @@ public class GalleryActivity extends MainDrawerActivity {
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
}
long galleryId = getIntent().getLongExtra(EXTRA_GALLERY, 0);
gallery = galleryDao.load(galleryId);
@ -317,8 +319,7 @@ public class GalleryActivity extends MainDrawerActivity {
sp.setSpan(new StyleSpan(Typeface.BOLD), 0, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
for (int i = 0, len = tags.length; i < len; i++) {
String tag = tags[i];
for (String tag : tags) {
int tagLength = tag.length();
sp.setSpan(new TagSpan(tag), length, length + tagLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

6
ehreader/src/tw/skyarrow/ehreader/app/gallery/GalleryIntentActivity.java

@ -67,8 +67,10 @@ public class GalleryIntentActivity extends FragmentActivity {
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
}
Intent intent = getIntent();

17
ehreader/src/tw/skyarrow/ehreader/app/main/MainActivity.java

@ -1,5 +1,6 @@
package tw.skyarrow.ehreader.app.main;
import android.app.ActionBar;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
@ -133,7 +134,11 @@ public class MainActivity extends MainDrawerActivity {
args.putString(MainFragmentWeb.EXTRA_BASE, loggedIn ? Constant.BASE_URL_EX : Constant.BASE_URL);
}
getActionBar().setTitle(actionBarTitle);
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setTitle(actionBarTitle);
}
fragment.setArguments(args);
ft.replace(R.id.container, fragment, tag);
ft.commit();
@ -168,11 +173,17 @@ public class MainActivity extends MainDrawerActivity {
@Override
public void onDrawerOpened(View view) {
getActionBar().setTitle(R.string.app_name);
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setTitle(R.string.app_name);
}
}
@Override
public void onDrawerClosed(View view) {
getActionBar().setTitle(actionBarTitle);
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setTitle(actionBarTitle);
}
}
}

6
ehreader/src/tw/skyarrow/ehreader/app/photo/CropActivity.java

@ -44,8 +44,10 @@ public class CropActivity extends FragmentActivity {
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
}
Intent intent = getIntent();
Uri data = intent.getData();

13
ehreader/src/tw/skyarrow/ehreader/app/photo/PhotoActivity.java

@ -127,7 +127,9 @@ public class PhotoActivity extends FragmentActivity implements View.OnSystemUiVi
pagerAdapter = new PhotoPagerAdapter(getSupportFragmentManager());
pager.setAdapter(pagerAdapter);
actionBar.setDisplayHomeAsUpEnabled(true);
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
if (savedInstanceState != null) {
page = savedInstanceState.getInt(EXTRA_PAGE);
@ -137,7 +139,10 @@ public class PhotoActivity extends FragmentActivity implements View.OnSystemUiVi
if (page < 0 || page >= total) page = 0;
actionBar.setTitle(String.format("%d / %d", page + 1, total));
if (actionBar != null) {
actionBar.setTitle(String.format("%d / %d", page + 1, total));
}
setCurrent(page, false);
seekBar.setMax(total - 1);
seekBar.setProgress(page);
@ -159,7 +164,9 @@ public class PhotoActivity extends FragmentActivity implements View.OnSystemUiVi
@Override
public void onPageSelected(int i) {
seekBar.setProgress(i);
actionBar.setTitle(String.format("%s / %s", i + 1, total));
if (actionBar != null) {
actionBar.setTitle(String.format("%s / %s", i + 1, total));
}
}
@Override

6
ehreader/src/tw/skyarrow/ehreader/app/photo/PhotoDeleteDialog.java

@ -65,11 +65,7 @@ public class PhotoDeleteDialog extends DialogFragment {
File file = photo.getFile();
if (file.exists()) {
return file.delete();
}
return false;
return file.exists() && file.delete();
}
@Override

6
ehreader/src/tw/skyarrow/ehreader/app/photo/PhotoIntentActivity.java

@ -67,8 +67,10 @@ public class PhotoIntentActivity extends FragmentActivity {
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
}
Intent intent = getIntent();

4
ehreader/src/tw/skyarrow/ehreader/app/pref/PrefActivity.java

@ -21,7 +21,9 @@ public class PrefActivity extends FragmentActivity {
setContentView(R.layout.activity_pref);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
FragmentTransaction ft = getFragmentManager().beginTransaction();
Fragment fragment = new PrefFragment();

4
ehreader/src/tw/skyarrow/ehreader/app/search/ImageSearchActivity.java

@ -33,7 +33,9 @@ public class ImageSearchActivity extends MainDrawerActivity {
setDrawerIndicatorEnabled(false);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
Intent intent = getIntent();

2
ehreader/src/tw/skyarrow/ehreader/app/search/ImageSearchSelectFragment.java

@ -157,7 +157,7 @@ public class ImageSearchSelectFragment extends Fragment {
Uri uri = uris[0];
String[] projection = {MediaStore.Images.ImageColumns.DATA};
Cursor cursor = getActivity().getContentResolver().query(uri, projection, null, null, null);
String path = "";
String path;
if (cursor == null) {
path = uri.getPath();

9
ehreader/src/tw/skyarrow/ehreader/app/search/SearchActivity.java

@ -35,7 +35,9 @@ public class SearchActivity extends MainDrawerActivity {
Intent intent = getIntent();
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean loggedIn = preferences.getBoolean(getString(R.string.pref_logged_in), false);
@ -51,7 +53,10 @@ public class SearchActivity extends MainDrawerActivity {
bundle.putString("base", ActionBarHelper.buildSearchUrl(query, loggedIn));
fragment.setArguments(bundle);
suggestions.saveRecentQuery(query, null);
actionBar.setTitle(query);
if (actionBar != null) {
actionBar.setTitle(query);
}
ft.replace(R.id.container, fragment);
ft.commit();

4
ehreader/src/tw/skyarrow/ehreader/db/GalleryBase.java

@ -125,8 +125,6 @@ public abstract class GalleryBase {
subtitle = getTitle();
}
String[] arr = {title, subtitle};
return arr;
return new String[]{title, subtitle};
}
}

3
ehreader/src/tw/skyarrow/ehreader/provider/PhotoProvider.java

@ -131,9 +131,8 @@ public class PhotoProvider extends ContentProvider {
if (match != PHOTO_ID) return null;
long photoId = ContentUris.parseId(uri);
Photo photo = photoDao.load(photoId);
return photo;
return photoDao.load(photoId);
}
private File getPhotoFile(Photo photo) {

2
ehreader/src/tw/skyarrow/ehreader/service/UpdateCheckService.java

@ -92,7 +92,7 @@ public class UpdateCheckService extends Service {
editor.putBoolean(getString(R.string.pref_update_is_interrupted), true);
bus.post(new UpdateCheckEvent(EVENT_ERROR, null));
} finally {
editor.commit();
editor.apply();
updateHelper.setupAlarm();
stopSelf();
}

6
ehreader/src/tw/skyarrow/ehreader/util/HttpRequestHelper.java

@ -17,17 +17,15 @@ public class HttpRequestHelper {
public static HttpResponse get(String url) throws IOException {
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse response = httpClient.execute(httpGet);
return response;
return httpClient.execute(httpGet);
}
public static HttpResponse post(String url) throws IOException {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse response = httpClient.execute(httpPost);
return response;
return httpClient.execute(httpPost);
}
public static String readResponse(HttpResponse response) throws IOException {

7
ehreader/src/tw/skyarrow/ehreader/util/LoginHelper.java

@ -4,7 +4,6 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
@ -84,7 +83,7 @@ public class LoginHelper {
httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
HttpResponse response = client.execute(httpPost, httpContext);
client.execute(httpPost, httpContext);
List<Cookie> cookies = cookieStore.getCookies();
String memberId = "";
String passHash = "";
@ -113,7 +112,7 @@ public class LoginHelper {
editor.putString(PREF_LOGIN_MEMBERID, memberId);
editor.putString(PREF_LOGIN_PASSHASH, passHash);
editor.putString(PREF_LOGIN_SESSIONID, sessionId);
editor.commit();
editor.apply();
EventBus.getDefault().post(new LoginEvent(LoginEvent.LOGIN));
return true;
@ -125,7 +124,7 @@ public class LoginHelper {
editor.putBoolean(PREF_LOGGED_IN, false);
editor.remove(PREF_LOGIN_MEMBERID);
editor.remove(PREF_LOGIN_PASSHASH);
editor.commit();
editor.apply();
EventBus.getDefault().post(new LoginEvent(LoginEvent.LOGOUT));
}

2
gradle/wrapper/gradle-wrapper.properties

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip
distributionUrl=http\://services.gradle.org/distributions/gradle-2.2-all.zip
Loading…
Cancel
Save