Search in sources :

Example 6 with Content

use of com.meisolsson.githubsdk.model.Content in project gh4a by slapperwan.

the class ContentListContainerFragment method loadModuleMap.

private void loadModuleMap() {
    RepositoryContentService service = ServiceFactory.get(RepositoryContentService.class, false);
    String repoOwner = mRepository.owner().login();
    String repoName = mRepository.name();
    service.getContents(repoOwner, repoName, ".gitmodules", mSelectedRef).map(ApiHelpers::throwOnFailure).map(Optional::of).compose(RxUtils.mapFailureToValue(HttpURLConnection.HTTP_NOT_FOUND, Optional.<Content>absent())).map(contentOpt -> contentOpt.map(content -> StringUtils.fromBase64(content.content()))).map(this::parseModuleMap).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).compose(mRxLoader.makeSingleTransformer(ID_LOADER_MODULEMAP, true)).subscribe(resultOpt -> {
        mGitModuleMap = resultOpt.orNull();
        if (mContentListFragment != null) {
            mContentListFragment.onSubModuleNamesChanged(getSubModuleNames(mContentListFragment));
        }
    }, ((BaseActivity) getActivity())::handleLoadFailure);
}
Also used : PathBreadcrumbs(com.gh4a.widget.PathBreadcrumbs) HttpURLConnection(java.net.HttpURLConnection) Context(android.content.Context) Repository(com.meisolsson.githubsdk.model.Repository) Bundle(android.os.Bundle) FileViewerActivity(com.gh4a.activities.FileViewerActivity) Uri(android.net.Uri) HashMap(java.util.HashMap) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) Stack(java.util.Stack) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Commit(com.meisolsson.githubsdk.model.Commit) SwipeRefreshLayout(com.gh4a.widget.SwipeRefreshLayout) RxLoader(com.philosophicalhacker.lib.RxLoader) Content(com.meisolsson.githubsdk.model.Content) Map(java.util.Map) R(com.gh4a.R) ContentType(com.meisolsson.githubsdk.model.ContentType) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) StringUtils(com.gh4a.utils.StringUtils) ApiHelpers(com.gh4a.utils.ApiHelpers) LayoutInflater(android.view.LayoutInflater) Fragment(android.support.v4.app.Fragment) Set(java.util.Set) TextUtils(android.text.TextUtils) ViewGroup(android.view.ViewGroup) RepositoryContentService(com.meisolsson.githubsdk.service.repositories.RepositoryContentService) FragmentManager(android.support.v4.app.FragmentManager) List(java.util.List) RepositoryActivity(com.gh4a.activities.RepositoryActivity) RxUtils(com.gh4a.utils.RxUtils) Optional(com.gh4a.utils.Optional) Nullable(android.support.annotation.Nullable) ServiceFactory(com.gh4a.ServiceFactory) FragmentTransaction(android.support.v4.app.FragmentTransaction) BaseActivity(com.gh4a.BaseActivity) Content(com.meisolsson.githubsdk.model.Content) RepositoryContentService(com.meisolsson.githubsdk.service.repositories.RepositoryContentService) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 7 with Content

use of com.meisolsson.githubsdk.model.Content in project gh4a by slapperwan.

the class ContentListContainerFragment method onContentsLoaded.

@Override
public void onContentsLoaded(ContentListFragment fragment, List<Content> contents) {
    if (contents == null) {
        return;
    }
    mContentCache.put(fragment.getPath(), new ArrayList<>(contents));
    if (fragment.getPath() == null) {
        for (Content content : contents) {
            if (content.type() == ContentType.File && content.name().equals(".gitmodules")) {
                loadModuleMap();
                break;
            }
        }
    }
    if (mInitialPathToLoad != null && !mInitialPathToLoad.isEmpty() && !mStateSaved) {
        String itemToLoad = mInitialPathToLoad.get(0);
        boolean found = false;
        for (Content content : contents) {
            if (content.type() == ContentType.Directory) {
                if (content.path().equals(itemToLoad)) {
                    onTreeSelected(content);
                    found = true;
                    break;
                }
            }
        }
        if (found) {
            mInitialPathToLoad.remove(0);
        } else {
            mInitialPathToLoad = null;
        }
    }
}
Also used : Content(com.meisolsson.githubsdk.model.Content)

Aggregations

Content (com.meisolsson.githubsdk.model.Content)7 RepositoryContentService (com.meisolsson.githubsdk.service.repositories.RepositoryContentService)3 Uri (android.net.Uri)2 ContextMenuAwareRecyclerView (com.gh4a.widget.ContextMenuAwareRecyclerView)2 RxLoader (com.philosophicalhacker.lib.RxLoader)2 Context (android.content.Context)1 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 Fragment (android.support.v4.app.Fragment)1 FragmentManager (android.support.v4.app.FragmentManager)1 FragmentTransaction (android.support.v4.app.FragmentTransaction)1 TextUtils (android.text.TextUtils)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 BaseActivity (com.gh4a.BaseActivity)1 R (com.gh4a.R)1