Skip to content
Snippets Groups Projects
Commit 2f434d32 authored by John Carlson's avatar John Carlson
Browse files

Use commonmark instead of bypass

parent f866d1ce
No related branches found
No related tags found
No related merge requests found
Showing
with 188 additions and 138 deletions
Loading
Loading
@@ -21,52 +21,6 @@ To build, run the following.
./gradlew assembleDebug
```
 
## Libraries
The following 3rd party libraries and resources are the reason this app works. Rapid development is easily attainable thanks to these fine folks and the work they do:
- AppCompat (https://developer.android.com/tools/support-library/features.html)
- Design (https://developer.android.com/tools/support-library/features.html)
- RecyclerView (https://developer.android.com/tools/support-library/features.html)
- CardView (https://developer.android.com/tools/support-library/features.html)
- Palette (https://developer.android.com/tools/support-library/features.html)
- Picasso (http://square.github.io/picasso/)
- Retrofit (http://square.github.io/retrofit/)
- OkHttp (http://square.github.io/okhttp/)
- Otto (http://square.github.io/otto/)
- RxJava (https://github.com/ReactiveX/RxJava)
- RxAndroid (https://github.com/ReactiveX/RxAndroid)
- Butter Knife (http://jakewharton.github.io/butterknife/)
- Timber (https://github.com/JakeWharton/timber)
- LoganSquare (https://github.com/bluelinelabs/LoganSquare)
- retrofit-logansquare (https://github.com/aurae/retrofit-logansquare)
- Joda Time Android (https://github.com/dlew/joda-time-android)
- Parceler (https://github.com/johncarl81/parceler)
- Bypasses (https://github.com/Commit451/bypasses)
- Easel (https://github.com/Commit451/Easel)
- ElasticDragDismissLayout (https://github.com/Commit451/ElasticDragDismissLayout)
- AdapterLayout (https://github.com/Commit451/AdapterLayout)
- Gimbal (https://github.com/Commit451/Gimbal)
- Teleprinter (https://github.com/Commit451/Teleprinter)
- BypassPicassoImageGetter (https://github.com/Commit451/BypassPicassoImageGetter)
- Jounce (https://github.com/Commit451/Jounce)
- EasyCallback (https://github.com/Commit451/EasyCallback)
- ForegroundViews (https://github.com/Commit451/ForegroundViews)
- Material-ish Progress (https://github.com/pnikosis/materialish-progress)
- PhysicsLayout (https://github.com/Jawnnypoo/PhysicsLayout)
- Material Letter Icon (https://github.com/IvBaranov/MaterialLetterIcon)
- RecyclerViewSquire (https://github.com/AlexKGwyn/RecyclerViewSquire)
- RobotoTextView (https://github.com/johnkil/Android-RobotoTextView)
- GitDiffTextView (https://github.com/alorma/GitDiffTextView)
- MaterialDateTimePicker (https://github.com/wdullaer/MaterialDateTimePicker)
- FlowLayout (https://github.com/blazsolar/FlowLayout)
- SimpleChromeCustomTabs (https://github.com/novoda/simple-chrome-custom-tabs)
- Material Dialogs (https://github.com/afollestad/material-dialogs)
- CircleImageView (https://github.com/hdodenhof/CircleImageView)
- EasyImage (https://github.com/jkwiecien/EasyImage)
- emoji-java (https://github.com/vdurmont/emoji-java)
- Crashlytics (https://www.crashlytics.com)
- highlight.js (https://highlightjs.org/)
## Contributing
Please fork this repository and contribute back! All Merge Requests should be made against the `develop` branch, as it is the active branch for development. Please make your best effort to break up commits as much as possible to improve the reviewing process.
 
Loading
Loading
Loading
Loading
@@ -154,7 +154,6 @@ dependencies {
compile "com.github.Commit451.Reptar:reptar:$reptarVersion"
compile "com.github.Commit451.Reptar:reptar-retrofit:$reptarVersion"
compile "com.github.Commit451.Reptar:reptar-kotlin:$reptarVersion"
compile 'com.github.Commit451:bypasses:1.1.0'
compile 'com.github.Commit451:ElasticDragDismissLayout:1.0.4'
compile "com.github.Commit451.AdapterLayout:adapterlayout:$adapterLayout"
compile ("com.github.Commit451.AdapterLayout:adapterflowlayout:$adapterLayout") {
Loading
Loading
@@ -167,7 +166,6 @@ dependencies {
compile 'com.github.Commit451.Easel:easel:2.1.1'
compile 'com.github.Commit451:Gimbal:2.0.2'
compile 'com.github.Commit451:Teleprinter:1.0.2'
compile 'com.github.Commit451:BypassPicassoImageGetter:1.1.1'
compile 'com.github.Commit451:Jounce:1.0.2'
compile 'com.github.Commit451:ForegroundViews:2.4.0'
compile 'com.github.Commit451:MorphTransitions:2.0.0'
Loading
Loading
@@ -207,6 +205,8 @@ dependencies {
 
compile 'com.github.jkwiecien:EasyImage:2.0.2'
 
compile 'com.atlassian.commonmark:commonmark:0.9.0'
compile('com.github.ozodrukh:CircularReveal:2.0.1@aar') {
transitive = true;
}
Loading
Loading
package com.commit451.gitlab.adapter
 
import `in`.uncod.android.bypass.Bypass
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.ViewGroup
import com.commit451.gitlab.model.api.Issue
import com.commit451.gitlab.model.api.Note
import com.commit451.gitlab.model.api.Project
import com.commit451.gitlab.util.BypassFactory
import com.commit451.gitlab.viewHolder.IssueHeaderViewHolder
import com.commit451.gitlab.viewHolder.IssueLabelsViewHolder
import com.commit451.gitlab.viewHolder.LoadingFooterViewHolder
Loading
Loading
@@ -33,8 +31,6 @@ class IssueDetailsAdapter(context: Context, private var issue: Issue?, private v
private val notes: LinkedList<Note> = LinkedList()
private var loading = false
 
private val bypass: Bypass = BypassFactory.create(context, project)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
if (viewType == TYPE_HEADER) {
return IssueHeaderViewHolder.inflate(parent)
Loading
Loading
@@ -50,12 +46,12 @@ class IssueDetailsAdapter(context: Context, private var issue: Issue?, private v
 
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder is IssueHeaderViewHolder) {
holder.bind(issue!!, bypass, project)
holder.bind(issue!!, project)
} else if (holder is IssueLabelsViewHolder) {
holder.bind(issue!!.labels)
} else if (holder is NoteViewHolder) {
val note = getNoteAt(position)
holder.bind(note, bypass, project)
holder.bind(note, project)
} else if (holder is LoadingFooterViewHolder) {
holder.bind(loading)
}
Loading
Loading
package com.commit451.gitlab.adapter
 
import `in`.uncod.android.bypass.Bypass
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.ViewGroup
import com.commit451.gitlab.model.api.MergeRequest
import com.commit451.gitlab.model.api.Note
import com.commit451.gitlab.model.api.Project
import com.commit451.gitlab.util.BypassFactory
import com.commit451.gitlab.viewHolder.LoadingFooterViewHolder
import com.commit451.gitlab.viewHolder.MergeRequestHeaderViewHolder
import com.commit451.gitlab.viewHolder.NoteViewHolder
Loading
Loading
@@ -31,8 +29,6 @@ class MergeRequestDetailAdapter(context: Context, private val mergeRequest: Merg
private val notes: LinkedList<Note> = LinkedList()
private var loading = false
 
private val bypass: Bypass = BypassFactory.create(context, project)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
if (viewType == TYPE_HEADER) {
return MergeRequestHeaderViewHolder.inflate(parent)
Loading
Loading
@@ -46,10 +42,10 @@ class MergeRequestDetailAdapter(context: Context, private val mergeRequest: Merg
 
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder is MergeRequestHeaderViewHolder) {
holder.bind(mergeRequest, bypass, project)
holder.bind(mergeRequest, project)
} else if (holder is NoteViewHolder) {
val note = getNoteAt(position)
holder.bind(note, bypass, project)
holder.bind(note, project)
} else if (holder is LoadingFooterViewHolder) {
holder.bind(loading)
}
Loading
Loading
Loading
Loading
@@ -6,8 +6,6 @@ import android.text.Spanned
import android.util.Base64
import io.reactivex.Single
 
//String extension methods
fun String.base64Decode(): Single<ByteArray> {
return Single.fromCallable {
Base64.decode(this, Base64.DEFAULT)
Loading
Loading
@@ -18,10 +16,10 @@ fun String.base64Decode(): Single<ByteArray> {
* Assures HTML is formatted the same way pre and post Android N
*/
@Suppress("DEPRECATION")
fun String.formatAsHtml(): Spanned {
fun String.formatAsHtml(imageGetter: Html.ImageGetter? = null, tagHandler: Html.TagHandler? = null): Spanned {
if (Build.VERSION.SDK_INT >= 24) {
return Html.fromHtml(this, Html.FROM_HTML_MODE_LEGACY)
return Html.fromHtml(this, Html.FROM_HTML_MODE_LEGACY, imageGetter, tagHandler)
} else {
return Html.fromHtml(this)
return Html.fromHtml(this, imageGetter, tagHandler)
}
}
\ No newline at end of file
}
package com.commit451.gitlab.extension
import android.widget.TextView
import com.commit451.gitlab.App
import com.commit451.gitlab.model.api.Project
import com.commit451.gitlab.util.ImageGetterFactory
import com.vdurmont.emoji.EmojiParser
import org.commonmark.parser.Parser
import org.commonmark.renderer.html.HtmlRenderer
fun TextView.setMarkdownText(text:String, project: Project? = null) {
val parser = Parser.builder().build()
val document = parser.parse(text)
val renderer = HtmlRenderer.builder().build()
val html = renderer.render(document)
val emojiParsedHtml = EmojiParser.parseToUnicode(html)
//I don't like this too much for its global-ness
val picasso = App.get().picasso
val baseUrl = App.get().currentAccount.serverUrl
val getter = ImageGetterFactory.create(this, picasso, baseUrl, project)
this.text = emojiParsedHtml.formatAsHtml(getter)
}
package com.commit451.gitlab.fragment
 
import `in`.uncod.android.bypass.Bypass
import android.os.Bundle
import android.support.design.widget.Snackbar
import android.support.v4.widget.SwipeRefreshLayout
Loading
Loading
@@ -17,19 +16,16 @@ import com.commit451.gitlab.activity.ProjectActivity
import com.commit451.gitlab.event.ProjectReloadEvent
import com.commit451.gitlab.extension.base64Decode
import com.commit451.gitlab.extension.formatAsHtml
import com.commit451.gitlab.extension.setMarkdownText
import com.commit451.gitlab.extension.setup
import com.commit451.gitlab.model.api.Project
import com.commit451.gitlab.model.api.RepositoryFile
import com.commit451.gitlab.model.api.RepositoryTreeObject
import com.commit451.gitlab.navigation.Navigator
import com.commit451.gitlab.rx.CustomSingleObserver
import com.commit451.gitlab.util.BypassFactory
import com.commit451.gitlab.util.BypassImageGetterFactory
import com.commit451.gitlab.util.InternalLinkMovementMethod
import com.commit451.reptar.Optional
import com.trello.rxlifecycle2.android.FragmentEvent
import com.vdurmont.emoji.EmojiParser
import io.reactivex.Single
import io.reactivex.SingleSource
import io.reactivex.functions.Function
Loading
Loading
@@ -61,8 +57,6 @@ class ProjectFragment : ButterKnifeFragment() {
@BindView(R.id.forks_count) lateinit var textForksCount: TextView
@BindView(R.id.overview_text) lateinit var textOverview: TextView
 
lateinit var bypass: Bypass
var project: Project? = null
var branchName: String? = null
 
Loading
Loading
@@ -150,7 +144,6 @@ class ProjectFragment : ButterKnifeFragment() {
if (activity is ProjectActivity) {
project = (activity as ProjectActivity).project
branchName = (activity as ProjectActivity).getRefRef()
bypass = BypassFactory.create(context, project!!)
bindProject(project)
loadData()
} else {
Loading
Loading
@@ -214,15 +207,10 @@ class ProjectFragment : ButterKnifeFragment() {
override fun success(readmeResult: ReadmeResult) {
swipeRefreshLayout.isRefreshing = false
if (result.repositoryFile != null && result.bytes != null) {
var text = String(result.bytes!!)
val text = String(result.bytes!!)
when (getReadmeType(result.repositoryFile!!.fileName)) {
README_TYPE_MARKDOWN -> {
text = EmojiParser.parseToUnicode(text)
textOverview.text = bypass.markdownToSpannable(text,
BypassImageGetterFactory.create(textOverview,
App.get().picasso,
App.get().getAccount().serverUrl.toString(),
project!!))
textOverview.setMarkdownText(text, project)
}
README_TYPE_HTML -> textOverview.text = text.formatAsHtml()
README_TYPE_TEXT -> textOverview.text = text
Loading
Loading
package com.commit451.gitlab.util
import `in`.uncod.android.bypass.Bypass
import android.content.Context
import com.commit451.gitlab.activity.FullscreenImageActivity
import com.commit451.gitlab.model.api.Project
/**
* Creates [BypassFactory]s which are configured to handle relative Urls
*/
object BypassFactory {
fun create(context: Context): Bypass {
return Bypass(context)
}
fun create(context: Context, project: Project): Bypass {
val bypass = Bypass(context)
bypass.setImageSpanClickListener { view, _, imageUrl ->
val intent = FullscreenImageActivity.newIntent(view.context, project, imageUrl)
context.startActivity(intent)
}
return bypass
}
}
\ No newline at end of file
package com.commit451.gitlab.util
 
import android.text.Html
import android.widget.TextView
import com.commit451.bypasspicassoimagegetter.BypassPicassoImageGetter
import com.commit451.gitlab.model.api.Project
import com.squareup.picasso.Picasso
 
import timber.log.Timber
/**
* Creates [BypassPicassoImageGetter]s which are configured to handle relative Urls
*/
object BypassImageGetterFactory {
object ImageGetterFactory {
 
fun create(textView: TextView, picasso: Picasso, baseUrl: String, project: Project?): BypassPicassoImageGetter {
val getter = BypassPicassoImageGetter(textView, picasso)
getter.setSourceModifier(BypassPicassoImageGetter.SourceModifier { source ->
fun create(textView: TextView, picasso: Picasso, baseUrl: String, project: Project?): Html.ImageGetter {
val getter = PicassoImageGetter(textView, picasso)
getter.setSourceModifier { source ->
if (source.startsWith("/")) {
val url = baseUrl + "/" + project?.pathWithNamespace + source
Timber.d(url)
return@SourceModifier url
return@setSourceModifier url
}
source
})
}
return getter
}
}
}
\ No newline at end of file
package com.commit451.gitlab.util;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.text.Html;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import java.lang.ref.WeakReference;
/**
* Original credits: http://stackoverflow.com/a/25530488/504611
*/
public class PicassoImageGetter implements Html.ImageGetter {
private final Picasso mPicasso;
private final WeakReference<TextView> mTextView;
private int maxWidth = -1;
private SourceModifier mSourceModifier;
public PicassoImageGetter(final TextView textView, final Picasso picasso) {
mTextView = new WeakReference<>(textView);
mPicasso = picasso;
}
@Override
public Drawable getDrawable(String source) {
final BitmapDrawablePlaceHolder result = new BitmapDrawablePlaceHolder();
final String finalSource = mSourceModifier == null ? source : mSourceModifier.modify(source);
new AsyncTask<Void, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(final Void... meh) {
try {
return mPicasso.load(finalSource).get();
} catch (Exception e) {
return null;
}
}
@Override
protected void onPostExecute(final Bitmap bitmap) {
TextView textView = mTextView.get();
if (textView == null) {
return;
}
try {
if (maxWidth == -1) {
int horizontalPadding = textView.getPaddingLeft() + textView.getPaddingRight();
maxWidth = textView.getMeasuredWidth() - horizontalPadding;
if (maxWidth == 0) {
maxWidth = Integer.MAX_VALUE;
}
}
final BitmapDrawable drawable = new BitmapDrawable(textView.getResources(), bitmap);
final double aspectRatio = 1.0 * drawable.getIntrinsicWidth() / drawable.getIntrinsicHeight();
final int width = Math.min(maxWidth, drawable.getIntrinsicWidth());
final int height = (int) (width / aspectRatio);
drawable.setBounds(0, 0, width, height);
result.setDrawable(drawable);
result.setBounds(0, 0, width, height);
textView.setText(textView.getText()); // invalidate() doesn't work correctly...
} catch (Exception e) {
//do something with this?
}
}
}.execute((Void) null);
return result;
}
/**
* Set the {@link SourceModifier}
* @param sourceModifier the new source modifier
*/
public void setSourceModifier(SourceModifier sourceModifier) {
mSourceModifier = sourceModifier;
}
/**
* Allows hooking into the source so that you can do things like modify relative urls
*/
public interface SourceModifier {
/**
* Modify the source url, adding to it in any way you need to
* @param source the source url from the markdown
* @return the modified url which will be loaded by Picasso
*/
String modify(String source);
}
private static class BitmapDrawablePlaceHolder extends BitmapDrawable {
protected Drawable drawable;
@Override
public void draw(final Canvas canvas) {
if (drawable != null) {
drawable.draw(canvas);
}
}
public void setDrawable(Drawable drawable) {
this.drawable = drawable;
}
}
}
package com.commit451.gitlab.viewHolder
 
import `in`.uncod.android.bypass.Bypass
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
Loading
Loading
@@ -11,14 +10,13 @@ import butterknife.BindView
import butterknife.ButterKnife
import com.commit451.gitlab.App
import com.commit451.gitlab.R
import com.commit451.gitlab.extension.setMarkdownText
import com.commit451.gitlab.model.api.Issue
import com.commit451.gitlab.model.api.Project
import com.commit451.gitlab.transformation.CircleTransformation
import com.commit451.gitlab.util.BypassImageGetterFactory
import com.commit451.gitlab.util.DateUtil
import com.commit451.gitlab.util.ImageUtil
import com.commit451.gitlab.util.InternalLinkMovementMethod
import com.vdurmont.emoji.EmojiParser
 
/**
* Header for an issue
Loading
Loading
@@ -44,19 +42,13 @@ class IssueHeaderViewHolder(view: View) : RecyclerView.ViewHolder(view) {
ButterKnife.bind(this, view)
}
 
fun bind(issue: Issue, bypass: Bypass, project: Project) {
fun bind(issue: Issue, project: Project) {
 
if (issue.description.isNullOrEmpty()) {
textDescription.visibility = View.GONE
} else {
textDescription.visibility = View.VISIBLE
val getter = BypassImageGetterFactory.create(textDescription,
App.get().picasso,
App.get().getAccount().serverUrl.toString(),
project)
var description = issue.description
description = EmojiParser.parseToUnicode(description)
textDescription.text = bypass.markdownToSpannable(description, getter)
textDescription.setMarkdownText(issue.description, project)
textDescription.movementMethod = InternalLinkMovementMethod(App.get().getAccount().serverUrl)
}
 
Loading
Loading
package com.commit451.gitlab.viewHolder
 
import `in`.uncod.android.bypass.Bypass
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
Loading
Loading
@@ -11,14 +10,13 @@ import butterknife.BindView
import butterknife.ButterKnife
import com.commit451.gitlab.App
import com.commit451.gitlab.R
import com.commit451.gitlab.extension.setMarkdownText
import com.commit451.gitlab.model.api.MergeRequest
import com.commit451.gitlab.model.api.Project
import com.commit451.gitlab.transformation.CircleTransformation
import com.commit451.gitlab.util.BypassImageGetterFactory
import com.commit451.gitlab.util.DateUtil
import com.commit451.gitlab.util.ImageUtil
import com.commit451.gitlab.util.InternalLinkMovementMethod
import com.vdurmont.emoji.EmojiParser
 
/**
* Header that gives the details of a merge request
Loading
Loading
@@ -42,18 +40,12 @@ class MergeRequestHeaderViewHolder(view: View) : RecyclerView.ViewHolder(view) {
ButterKnife.bind(this, view)
}
 
fun bind(mergeRequest: MergeRequest, bypass: Bypass, project: Project) {
fun bind(mergeRequest: MergeRequest, project: Project) {
if (mergeRequest.description.isNullOrEmpty()) {
textDescription.visibility = View.GONE
} else {
textDescription.visibility = View.VISIBLE
var description = mergeRequest.description
description = EmojiParser.parseToUnicode(description)
textDescription.text = bypass.markdownToSpannable(description,
BypassImageGetterFactory.create(textDescription,
App.get().picasso,
App.get().getAccount().serverUrl.toString(),
project))
textDescription.setMarkdownText(mergeRequest.description, project)
textDescription.movementMethod = InternalLinkMovementMethod(App.get().getAccount().serverUrl)
}
 
Loading
Loading
package com.commit451.gitlab.viewHolder
 
import `in`.uncod.android.bypass.Bypass
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
Loading
Loading
@@ -11,14 +10,13 @@ import butterknife.BindView
import butterknife.ButterKnife
import com.commit451.gitlab.App
import com.commit451.gitlab.R
import com.commit451.gitlab.extension.setMarkdownText
import com.commit451.gitlab.model.api.Note
import com.commit451.gitlab.model.api.Project
import com.commit451.gitlab.transformation.CircleTransformation
import com.commit451.gitlab.util.BypassImageGetterFactory
import com.commit451.gitlab.util.DateUtil
import com.commit451.gitlab.util.ImageUtil
import com.commit451.gitlab.util.InternalLinkMovementMethod
import com.vdurmont.emoji.EmojiParser
 
/**
* Notes, aka comments
Loading
Loading
@@ -43,7 +41,7 @@ class NoteViewHolder(view: View) : RecyclerView.ViewHolder(view) {
ButterKnife.bind(this, view)
}
 
fun bind(note: Note, bypass: Bypass, project: Project) {
fun bind(note: Note, project: Project) {
if (note.createdAt != null) {
textCreationDate.text = DateUtil.getRelativeTimeSpanString(itemView.context, note.createdAt)
}
Loading
Loading
@@ -55,14 +53,9 @@ class NoteViewHolder(view: View) : RecyclerView.ViewHolder(view) {
var summary = ""
if (note.body != null) {
summary = note.body
summary = EmojiParser.parseToUnicode(summary)
}
 
val getter = BypassImageGetterFactory.create(textSummary,
App.get().picasso,
App.get().getAccount().serverUrl.toString(),
project)
textSummary.text = bypass.markdownToSpannable(summary, getter)
textSummary.setMarkdownText(summary, project)
textSummary.movementMethod = InternalLinkMovementMethod(App.get().getAccount().serverUrl)
 
App.get().picasso
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment