use of com.meisolsson.githubsdk.model.Content in project gh4a by slapperwan.
the class ContentListFragment method onCreateDataSingle.
@Override
protected Single<List<Content>> onCreateDataSingle(boolean bypassCache) {
ArrayList<Content> contents = getArguments().getParcelableArrayList("contents");
if (contents != null && !contents.isEmpty()) {
return Single.just(contents);
}
RepositoryContentService contentService = ServiceFactory.get(RepositoryContentService.class, bypassCache);
String repoOwner = mRepository.owner().login();
String repoName = mRepository.name();
String ref = mRef != null ? mRef : mRepository.defaultBranch();
return ApiHelpers.PageIterator.toSingle(page -> contentService.getDirectoryContents(repoOwner, repoName, mPath, ref, page)).compose(RxUtils.mapFailureToValue(HttpURLConnection.HTTP_NOT_FOUND, new ArrayList<Content>())).compose(RxUtils.sortList(COMPARATOR));
}
use of com.meisolsson.githubsdk.model.Content in project gh4a by slapperwan.
the class ContentListFragment method onContextItemSelected.
@Override
public boolean onContextItemSelected(MenuItem item) {
ContextMenuAwareRecyclerView.RecyclerContextMenuInfo info = (ContextMenuAwareRecyclerView.RecyclerContextMenuInfo) item.getMenuInfo();
if (info.position >= mAdapter.getItemCount()) {
return false;
}
int id = item.getItemId();
if (id == MENU_HISTORY) {
Content contents = mAdapter.getItemFromAdapterPosition(info.position);
Intent intent = CommitHistoryActivity.makeIntent(getActivity(), mRepository.owner().login(), mRepository.name(), mRef, contents.path(), true);
startActivityForResult(intent, REQUEST_FILE_HISTORY);
return true;
}
return super.onContextItemSelected(item);
}
use of com.meisolsson.githubsdk.model.Content in project gh4a by slapperwan.
the class ContentListContainerFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mRxLoader = new RxLoader(getActivity(), getLoaderManager());
mRepository = getArguments().getParcelable("repository");
mSelectedRef = getArguments().getString("ref");
mStateSaved = false;
if (savedInstanceState != null) {
mDirStack.addAll(savedInstanceState.getStringArrayList(STATE_KEY_DIR_STACK));
int prefixLen = STATE_KEY_CONTENT_CACHE_PREFIX.length();
for (String key : savedInstanceState.keySet()) {
if (key.startsWith(STATE_KEY_CONTENT_CACHE_PREFIX)) {
String cacheKey = key.substring(prefixLen);
if (cacheKey.equals("/")) {
cacheKey = null;
}
ArrayList<Content> content = savedInstanceState.getParcelableArrayList(key);
mContentCache.put(cacheKey, content);
}
}
mInitialPathToLoad = savedInstanceState.getStringArrayList(STATE_KEY_INITIAL_PATH);
} else {
mDirStack.push("");
String initialPath = getArguments().getString("initialpath");
if (initialPath != null) {
mInitialPathToLoad = new ArrayList<>();
int pos = initialPath.indexOf("/");
while (pos > 0) {
mInitialPathToLoad.add(initialPath.substring(0, pos));
pos = initialPath.indexOf("/", pos + 1);
}
mInitialPathToLoad.add(initialPath);
}
}
}
use of com.meisolsson.githubsdk.model.Content in project PocketHub by pockethub.
the class HttpImageGetter method requestRepositoryImage.
/**
* Request an image using the contents API if the source URI is a path to a
* file already in the repository
*
* @param source
* @return
* @throws IOException
*/
private Drawable requestRepositoryImage(final String source) throws IOException {
if (TextUtils.isEmpty(source)) {
return null;
}
Uri uri = Uri.parse(source);
if (!HOST_DEFAULT.equals(uri.getHost())) {
return null;
}
List<String> segments = uri.getPathSegments();
if (segments.size() < 5) {
return null;
}
String prefix = segments.get(2);
// github.com/github/android/blob/master/app/res/drawable-xhdpi/app_icon.png?raw=true
if (!("raw".equals(prefix) || ("blob".equals(prefix) && !TextUtils.isEmpty(uri.getQueryParameter("raw"))))) {
return null;
}
String owner = segments.get(0);
if (TextUtils.isEmpty(owner)) {
return null;
}
String name = segments.get(1);
if (TextUtils.isEmpty(name)) {
return null;
}
String branch = segments.get(3);
if (TextUtils.isEmpty(branch)) {
return null;
}
StringBuilder path = new StringBuilder(segments.get(4));
for (int i = 5; i < segments.size(); i++) {
String segment = segments.get(i);
if (!TextUtils.isEmpty(segment)) {
path.append('/').append(segment);
}
}
if (TextUtils.isEmpty(path)) {
return null;
}
Content contents = ServiceGenerator.createService(context, RepositoryContentService.class).getContents(owner, name, path.toString(), branch).blockingGet().body();
if (contents.content() != null) {
byte[] content = Base64.decode(contents.content(), DEFAULT);
Bitmap bitmap = ImageUtils.getBitmap(content, width, MAX_VALUE);
if (bitmap == null) {
return loading.getDrawable(source);
}
BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap);
drawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
return drawable;
} else {
return null;
}
}
use of com.meisolsson.githubsdk.model.Content in project gh4a by slapperwan.
the class ContentListFragment method onCreateContextMenu.
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
ContextMenuAwareRecyclerView.RecyclerContextMenuInfo info = (ContextMenuAwareRecyclerView.RecyclerContextMenuInfo) menuInfo;
Content contents = mAdapter.getItemFromAdapterPosition(info.position);
Set<String> subModules = mCallback.getSubModuleNames(this);
if (subModules == null || !subModules.contains(contents.name())) {
menu.add(Menu.NONE, MENU_HISTORY, Menu.NONE, R.string.history);
}
}
Aggregations