com.hippo.yorozuya.ObjectUtils Java Examples

The following examples show how to use com.hippo.yorozuya.ObjectUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SecurityScene.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
@Override
public void onPatternDetected(List<LockPatternView.Cell> pattern) {
    MainActivity activity = getActivity2();
    if (null == activity || null == mPatternView) {
        return;
    }

    String enteredPatter = LockPatternUtils.patternToString(pattern);
    String targetPatter = Settings.getSecurity();

    if (ObjectUtils.equal(enteredPatter, targetPatter)) {
        startSceneForCheckStep(CHECK_STEP_SECURITY, getArguments());
        finish();
    } else {
        mPatternView.setDisplayMode(LockPatternView.DisplayMode.Wrong);
        mRetryTimes--;
        if (mRetryTimes <= 0) {
            finish();
        }
    }
}
 
Example #2
Source File: SecurityScene.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
@Override
public void onPatternDetected(List<LockPatternView.Cell> pattern) {
    MainActivity activity = getActivity2();
    if (null == activity || null == mPatternView) {
        return;
    }

    String enteredPatter = LockPatternUtils.patternToString(pattern);
    String targetPatter = Settings.getSecurity();

    if (ObjectUtils.equal(enteredPatter, targetPatter)) {
        startSceneForCheckStep(CHECK_STEP_SECURITY, getArguments());
        finish();
    } else {
        mPatternView.setDisplayMode(LockPatternView.DisplayMode.Wrong);
        mRetryTimes--;
        if (mRetryTimes <= 0) {
            finish();
        }
    }
}
 
Example #3
Source File: SimpleCookieStore.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
public synchronized void remove(URL url, String name) {
    if (url == null) {
        throw new NullPointerException("cookie == null");
    }

    url = cookiesUrl(url);
    List<HttpCookieWithId> cookies = map.get(url);
    if (cookies != null) {
        for (Iterator<HttpCookieWithId> i = cookies.iterator(); i.hasNext(); ) {
            HttpCookieWithId hcwi = i.next();
            HttpCookie cookie = hcwi.httpCookie;
            if (hcwi.hasExpired() || (ObjectUtils.equal(name, hcwi.httpCookie.getName()) &&
                    pathMatches(cookie, url) && portMatches(cookie, url))) {
                i.remove(); // remove expired cookies
                HttpCookieDB.removeCookie(hcwi.id); // remove from DB
            }
        }
    }
}
 
Example #4
Source File: SimpleCookieStore.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
public synchronized HttpCookieWithId getCookie(@NonNull URL url, String name) {
    List<HttpCookieWithId> cookies = map.get(cookiesUrl(url));
    if (cookies != null) {
        for (Iterator<HttpCookieWithId> i = cookies.iterator(); i.hasNext(); ) {
            HttpCookieWithId hcwi = i.next();
            HttpCookie cookie = hcwi.httpCookie;

            if (hcwi.hasExpired()) {
                i.remove(); // remove expired cookies
                HttpCookieDB.removeCookie(hcwi.id); // remove from DB
            } else if (ObjectUtils.equal(name, hcwi.httpCookie.getName()) &&
                    pathMatches(cookie, url) && portMatches(cookie, url)) {
                return hcwi;
            }
        }
    }

    return null;
}
 
Example #5
Source File: CookieRepository.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
public boolean contains(HttpUrl url, String name) {
  for (Cookie cookie : getCookies(url)) {
    if (ObjectUtils.equal(cookie.name(), name)) {
      return true;
    }
  }
  return false;
}
 
Example #6
Source File: GalleryHeader.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.P)
public void setDisplayCutout(@Nullable DisplayCutout displayCutout) {
  if (!ObjectUtils.equal(this.displayCutout, displayCutout)) {
    this.displayCutout = displayCutout;
    requestLayout();
  }
}
 
Example #7
Source File: DownloadsScene.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void onRenameLabel(String from, String to) {
    if (!ObjectUtils.equal(mLabel, from)) {
        return;
    }

    mLabel = to;
    updateForLabel();
    updateView();
}
 
Example #8
Source File: DownloadManager.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
/**
 * @param label Not allow new label
 */
public void changeLabel(List<DownloadInfo> list, String label) {
    if (null != label && !containLabel(label)) {
        Log.e(TAG, "Not exits label: " + label);
        return;
    }

    List<DownloadInfo> dstList = getInfoListForLabel(label);
    if (dstList == null) {
        Log.e(TAG, "Can't find label with label: " + label);
        return;
    }

    for (DownloadInfo info: list) {
        if (ObjectUtils.equal(info.label, label)) {
            continue;
        }

        List<DownloadInfo> srcList = getInfoListForLabel(info.label);
        if (srcList == null) {
            Log.e(TAG, "Can't find label with label: " + info.label);
            continue;
        }

        srcList.remove(info);
        dstList.add(info);
        info.label = label;
        Collections.sort(dstList, DATE_DESC_COMPARATOR);

        // Save to DB
        EhDB.putDownloadInfo(info);
    }

    for (DownloadInfoListener l: mDownloadInfoListeners) {
        l.onReload();
    }
}
 
Example #9
Source File: CookieRepository.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
public boolean contains(HttpUrl url, String name) {
  for (Cookie cookie : getCookies(url)) {
    if (ObjectUtils.equal(cookie.name(), name)) {
      return true;
    }
  }
  return false;
}
 
Example #10
Source File: CookieSet.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
  if (obj == this) {
    return true;
  }

  if (obj instanceof Key) {
    Key key = (Key) obj;
    return ObjectUtils.equal(key.name, this.name) &&
        ObjectUtils.equal(key.domain, this.domain) &&
        ObjectUtils.equal(key.path, this.path);
  }

  return false;
}
 
Example #11
Source File: DownloadsScene.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void onRenameLabel(String from, String to) {
    if (!ObjectUtils.equal(mLabel, from)) {
        return;
    }

    mLabel = to;
    updateForLabel();
    updateView();
}
 
Example #12
Source File: DownloadManager.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
/**
 * @param label Not allow new label
 */
public void changeLabel(List<DownloadInfo> list, String label) {
    if (null != label && !containLabel(label)) {
        Log.e(TAG, "Not exits label: " + label);
        return;
    }

    List<DownloadInfo> dstList = getInfoListForLabel(label);
    if (dstList == null) {
        Log.e(TAG, "Can't find label with label: " + label);
        return;
    }

    for (DownloadInfo info: list) {
        if (ObjectUtils.equal(info.label, label)) {
            continue;
        }

        List<DownloadInfo> srcList = getInfoListForLabel(info.label);
        if (srcList == null) {
            Log.e(TAG, "Can't find label with label: " + info.label);
            continue;
        }

        srcList.remove(info);
        dstList.add(info);
        info.label = label;
        Collections.sort(dstList, DATE_DESC_COMPARATOR);

        // Save to DB
        EhDB.putDownloadInfo(info);
    }

    for (DownloadInfoListener l: mDownloadInfoListeners) {
        l.onReload();
    }
}
 
Example #13
Source File: CookieSet.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
  if (obj == this) {
    return true;
  }

  if (obj instanceof Key) {
    Key key = (Key) obj;
    return ObjectUtils.equal(key.name, this.name) &&
        ObjectUtils.equal(key.domain, this.domain) &&
        ObjectUtils.equal(key.path, this.path);
  }

  return false;
}
 
Example #14
Source File: ListActivity.java    From Nimingban with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean isTheSame(Post d1, Post d2) {
    return ObjectUtils.equal(d1.getNMBId(), d2.getNMBId());
}
 
Example #15
Source File: FavoritesScene.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
private void updateSearchBar() {
    Context context = getContext2();
    if (null == context || null == mUrlBuilder || null == mSearchBar || null == mFavCatArray) {
        return;
    }

    // Update title
    int favCat = mUrlBuilder.getFavCat();
    String favCatName;
    if (favCat >= 0 && favCat < 10) {
        favCatName = mFavCatArray[favCat];
    } else if (favCat == FavListUrlBuilder.FAV_CAT_LOCAL) {
        favCatName = getString(R.string.local_favorites) + " - " + currentSource;
    } else {
        favCatName = getString(R.string.cloud_favorites);
    }
    String keyword = mUrlBuilder.getKeyword();
    if (TextUtils.isEmpty(keyword)) {
        if (!ObjectUtils.equal(favCatName, mOldFavCat)) {
            mSearchBar.setTitle(getString(R.string.favorites_title, favCatName));
        }
    } else {
        if (!ObjectUtils.equal(favCatName, mOldFavCat) || !ObjectUtils.equal(keyword, mOldKeyword)) {
            mSearchBar.setTitle(getString(R.string.favorites_title_2, favCatName, keyword));
        }
    }

    // Update hint
    if (!ObjectUtils.equal(favCatName, mOldFavCat)) {
        Drawable searchImage = DrawableManager.getVectorDrawable(context, R.drawable.v_magnify_x24);
        SpannableStringBuilder ssb = new SpannableStringBuilder("   ");
        ssb.append(getString(R.string.favorites_search_bar_hint, favCatName));
        int textSize = (int) (mSearchBar.getEditTextTextSize() * 1.25);
        if (searchImage != null) {
            searchImage.setBounds(0, 0, textSize, textSize);
            ssb.setSpan(new ImageSpan(searchImage), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        mSearchBar.setEditTextHint(ssb);
    }

    mOldFavCat = favCatName;
    mOldKeyword = keyword;

    // Save recent fav cat
    Settings.putRecentFavCat(mUrlBuilder.getFavCat());
}
 
Example #16
Source File: EhDB.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
/**
 * @param file The db file
 * @return error string, null for no error
 */
public static synchronized String importDB(Context context, File file) {
    try {
        SQLiteDatabase db = SQLiteDatabase.openDatabase(
                file.getPath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
        int newVersion = DaoMaster.SCHEMA_VERSION;
        int oldVersion = db.getVersion();
        if (oldVersion < newVersion) {
            upgradeDB(db, oldVersion);
            db.setVersion(newVersion);
        } else if (oldVersion > newVersion) {
            return context.getString(R.string.cant_read_the_file);
        }

        DaoMaster daoMaster = new DaoMaster(db);
        DaoSession session = daoMaster.newSession();

        // Downloads
        DownloadManager manager = EhApplication.getDownloadManager(context);
        List<DownloadInfo> downloadInfoList = session.getDownloadsDao().queryBuilder().list();
        manager.addDownload(downloadInfoList);

        // Download label
        List<DownloadLabel> downloadLabelList = session.getDownloadLabelDao().queryBuilder().list();
        manager.addDownloadLabel(downloadLabelList);

        // Download dirname
        List<DownloadDirname> downloadDirnameList = session.getDownloadDirnameDao().queryBuilder().list();
        for (DownloadDirname dirname: downloadDirnameList) {
            putDownloadDirname(dirname.getGid(), dirname.getDirname());
        }

        // History
        List<HistoryInfo> historyInfoList = session.getHistoryDao().queryBuilder().list();
        putHistoryInfo(historyInfoList);

        // QuickSearch
        List<QuickSearch> quickSearchList = session.getQuickSearchDao().queryBuilder().list();
        List<QuickSearch> currentQuickSearchList = sDaoSession.getQuickSearchDao().queryBuilder().list();
        for (QuickSearch quickSearch: quickSearchList) {
            String name = quickSearch.name;
            for (QuickSearch q: currentQuickSearchList) {
                if (ObjectUtils.equal(q.name, name)) {
                    // The same name
                    name = null;
                    break;
                }
            }
            if (null == name) {
                continue;
            }
            insertQuickSearch(quickSearch);
        }

        // LocalFavorites
        List<LocalFavoriteInfo> localFavoriteInfoList = session.getLocalFavoritesDao().queryBuilder().list();
        for (LocalFavoriteInfo info: localFavoriteInfoList) {
            putLocalFavorites(info);
        }

        // Bookmarks
        // TODO

        // Filter
        List<Filter> filterList = session.getFilterDao().queryBuilder().list();
        List<Filter> currentFilterList = sDaoSession.getFilterDao().queryBuilder().list();
        for (Filter filter: filterList) {
            if (!currentFilterList.contains(filter)) {
                addFilter(filter);
            }
        }

        return null;
    } catch (Throwable e) {
        ExceptionUtils.throwIfFatal(e);
        // Ignore
        return context.getString(R.string.cant_read_the_file);
    }
}
 
Example #17
Source File: EhDB.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
/**
 * @param file The db file
 * @return error string, null for no error
 */
public static synchronized String importDB(Context context, File file) {
    try {
        SQLiteDatabase db = SQLiteDatabase.openDatabase(
                file.getPath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
        int newVersion = DaoMaster.SCHEMA_VERSION;
        int oldVersion = db.getVersion();
        if (oldVersion < newVersion) {
            upgradeDB(db, oldVersion);
            db.setVersion(newVersion);
        } else if (oldVersion > newVersion) {
            return context.getString(R.string.cant_read_the_file);
        }

        DaoMaster daoMaster = new DaoMaster(db);
        DaoSession session = daoMaster.newSession();

        // Downloads
        DownloadManager manager = EhApplication.getDownloadManager(context);
        List<DownloadInfo> downloadInfoList = session.getDownloadsDao().queryBuilder().list();
        manager.addDownload(downloadInfoList);

        // Download label
        List<DownloadLabel> downloadLabelList = session.getDownloadLabelDao().queryBuilder().list();
        manager.addDownloadLabel(downloadLabelList);

        // Download dirname
        List<DownloadDirname> downloadDirnameList = session.getDownloadDirnameDao().queryBuilder().list();
        for (DownloadDirname dirname : downloadDirnameList) {
            putDownloadDirname(dirname.getGid(), dirname.getDirname());
        }

        // History
        List<HistoryInfo> historyInfoList = session.getHistoryDao().queryBuilder().list();
        putHistoryInfo(historyInfoList);

        // QuickSearch
        List<QuickSearch> quickSearchList = session.getQuickSearchDao().queryBuilder().list();
        List<QuickSearch> currentQuickSearchList = sDaoSession.getQuickSearchDao().queryBuilder().list();
        for (QuickSearch quickSearch : quickSearchList) {
            String name = quickSearch.name;
            for (QuickSearch q : currentQuickSearchList) {
                if (ObjectUtils.equal(q.name, name)) {
                    // The same name
                    name = null;
                    break;
                }
            }
            if (null == name) {
                continue;
            }
            insertQuickSearch(quickSearch);
        }

        // LocalFavorites
        List<LocalFavoriteInfo> localFavoriteInfoList = session.getLocalFavoritesDao().queryBuilder().list();
        for (LocalFavoriteInfo info : localFavoriteInfoList) {
            putLocalFavorites(info);
        }

        // Bookmarks
        // TODO

        List<ReadingRecord> readingRecordList = session.getReadingRecordDao().queryBuilder().list();
        for (ReadingRecord record : readingRecordList) {
            putReadingRecord(record);
        }

        // Filter
        List<Filter> filterList = session.getFilterDao().queryBuilder().list();
        List<Filter> currentFilterList = sDaoSession.getFilterDao().queryBuilder().list();
        for (Filter filter : filterList) {
            if (!currentFilterList.contains(filter)) {
                addFilter(filter);
            }
        }

        return null;
    } catch (Throwable e) {
        ExceptionUtils.throwIfFatal(e);
        // Ignore
        return context.getString(R.string.cant_read_the_file);
    }
}
 
Example #18
Source File: FavoritesScene.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
private void updateSearchBar() {
    Context context = getContext2();
    if (null == context || null == mUrlBuilder || null == mSearchBar || null == mFavCatArray) {
        return;
    }

    // Update title
    int favCat = mUrlBuilder.getFavCat();
    String favCatName;
    if (favCat >= 0 && favCat < 10) {
        favCatName = mFavCatArray[favCat];
    } else if (favCat == FavListUrlBuilder.FAV_CAT_LOCAL) {
        favCatName = getString(R.string.local_favorites);
    } else {
        favCatName = getString(R.string.cloud_favorites);
    }
    String keyword = mUrlBuilder.getKeyword();
    if (TextUtils.isEmpty(keyword)) {
        if (!ObjectUtils.equal(favCatName, mOldFavCat)) {
            mSearchBar.setTitle(getString(R.string.favorites_title, favCatName));
        }
    } else {
        if (!ObjectUtils.equal(favCatName, mOldFavCat) || !ObjectUtils.equal(keyword, mOldKeyword)) {
            mSearchBar.setTitle(getString(R.string.favorites_title_2, favCatName, keyword));
        }
    }

    // Update hint
    if (!ObjectUtils.equal(favCatName, mOldFavCat)) {
        Drawable searchImage = DrawableManager.getVectorDrawable(context, R.drawable.v_magnify_x24);
        SpannableStringBuilder ssb = new SpannableStringBuilder("   ");
        ssb.append(getString(R.string.favorites_search_bar_hint, favCatName));
        int textSize = (int) (mSearchBar.getEditTextTextSize() * 1.25);
        if (searchImage != null) {
            searchImage.setBounds(0, 0, textSize, textSize);
            ssb.setSpan(new ImageSpan(searchImage), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        mSearchBar.setEditTextHint(ssb);
    }

    mOldFavCat = favCatName;
    mOldKeyword = keyword;

    // Save recent fav cat
    Settings.putRecentFavCat(mUrlBuilder.getFavCat());
}