Update dependencies
This commit is contained in:
parent
13536302cc
commit
ab4c80dca5
@ -4,8 +4,8 @@ import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import ru.noties.debug.AndroidLogDebugOutput;
|
||||
import ru.noties.debug.Debug;
|
||||
import io.noties.debug.AndroidLogDebugOutput;
|
||||
import io.noties.debug.Debug;
|
||||
|
||||
public class App extends Application {
|
||||
|
||||
|
@ -13,7 +13,7 @@ import android.widget.TextView;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import io.noties.markwon.Markwon;
|
||||
import ru.noties.debug.Debug;
|
||||
import io.noties.debug.Debug;
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
|
||||
|
@ -24,7 +24,7 @@ import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import ru.noties.debug.Debug;
|
||||
import io.noties.debug.Debug;
|
||||
|
||||
@ActivityScope
|
||||
public class MarkdownLoader {
|
||||
|
@ -33,7 +33,7 @@ import io.noties.markwon.syntax.Prism4jThemeDefault;
|
||||
import io.noties.markwon.syntax.SyntaxHighlightPlugin;
|
||||
import io.noties.markwon.urlprocessor.UrlProcessor;
|
||||
import io.noties.markwon.urlprocessor.UrlProcessorRelativeToAbsolute;
|
||||
import ru.noties.debug.Debug;
|
||||
import io.noties.debug.Debug;
|
||||
import ru.noties.prism4j.Prism4j;
|
||||
|
||||
@ActivityScope
|
||||
|
@ -69,8 +69,8 @@ ext {
|
||||
'jlatexmath-android' : 'ru.noties:jlatexmath-android:0.1.0',
|
||||
'okhttp' : 'com.squareup.okhttp3:okhttp:3.9.0',
|
||||
'prism4j' : 'ru.noties:prism4j:1.1.0',
|
||||
'debug' : 'ru.noties:debug:3.0.0@jar',
|
||||
'adapt' : 'ru.noties:adapt:1.1.0',
|
||||
'debug' : 'io.noties:debug:5.0.0@jar',
|
||||
'adapt' : 'io.noties:adapt:2.0.0',
|
||||
'dagger' : "com.google.dagger:dagger:$daggerVersion",
|
||||
'picasso' : 'com.squareup.picasso:picasso:2.71828',
|
||||
'glide' : 'com.github.bumptech.glide:glide:4.9.0'
|
||||
|
@ -8,20 +8,20 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.noties.adapt.Adapt;
|
||||
import io.noties.adapt.Item;
|
||||
import io.noties.debug.AndroidLogDebugOutput;
|
||||
import io.noties.debug.Debug;
|
||||
import io.noties.markwon.Markwon;
|
||||
import io.noties.markwon.sample.basicplugins.BasicPluginsActivity;
|
||||
import io.noties.markwon.sample.core.CoreActivity;
|
||||
import io.noties.markwon.sample.customextension.CustomExtensionActivity;
|
||||
import io.noties.markwon.sample.latex.LatexActivity;
|
||||
import io.noties.markwon.sample.recycler.RecyclerActivity;
|
||||
import ru.noties.adapt.Adapt;
|
||||
import ru.noties.adapt.OnClickViewProcessor;
|
||||
import ru.noties.debug.AndroidLogDebugOutput;
|
||||
import ru.noties.debug.Debug;
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
|
||||
@ -38,21 +38,20 @@ public class MainActivity extends Activity {
|
||||
// here we are creating as core markwon (no additional plugins are registered)
|
||||
final Markwon markwon = Markwon.create(this);
|
||||
|
||||
final Adapt<SampleItem> adapt = Adapt.builder(SampleItem.class)
|
||||
.include(SampleItem.class, new SampleItemView(markwon), new OnClickViewProcessor<SampleItem>() {
|
||||
@Override
|
||||
public void onClick(@NonNull SampleItem item, @NonNull View view) {
|
||||
showSample(item);
|
||||
}
|
||||
})
|
||||
.build();
|
||||
adapt.setItems(Arrays.asList(SampleItem.values()));
|
||||
final Adapt adapt = Adapt.create();
|
||||
|
||||
final List<Item> items = new ArrayList<>();
|
||||
final SampleItem.OnClickListener onClickListener = this::showSample;
|
||||
for (Sample sample : Sample.values()) {
|
||||
items.add(new SampleItem(sample, markwon, onClickListener));
|
||||
}
|
||||
adapt.setItems(items);
|
||||
|
||||
final RecyclerView recyclerView = findViewById(R.id.recycler_view);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
recyclerView.setHasFixedSize(true);
|
||||
recyclerView.addItemDecoration(createSampleItemDecoration());
|
||||
recyclerView.setAdapter(adapt.recyclerViewAdapter());
|
||||
recyclerView.setAdapter(adapt);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@ -66,12 +65,12 @@ public class MainActivity extends Activity {
|
||||
);
|
||||
}
|
||||
|
||||
private void showSample(@NonNull SampleItem item) {
|
||||
private void showSample(@NonNull Sample item) {
|
||||
startActivity(sampleItemIntent(this, item));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static Intent sampleItemIntent(@NonNull Context context, @NonNull SampleItem item) {
|
||||
static Intent sampleItemIntent(@NonNull Context context, @NonNull Sample item) {
|
||||
|
||||
final Class<? extends Activity> activity;
|
||||
|
||||
|
30
sample/src/main/java/io/noties/markwon/sample/Sample.java
Normal file
30
sample/src/main/java/io/noties/markwon/sample/Sample.java
Normal file
@ -0,0 +1,30 @@
|
||||
package io.noties.markwon.sample;
|
||||
|
||||
import android.support.annotation.StringRes;
|
||||
|
||||
public enum Sample {
|
||||
|
||||
// all usages of markwon without plugins (parse, render, setMarkwon, etc)
|
||||
CORE(R.string.sample_core),
|
||||
|
||||
BASIC_PLUGINS(R.string.sample_basic_plugins),
|
||||
|
||||
LATEX(R.string.sample_latex),
|
||||
|
||||
CUSTOM_EXTENSION(R.string.sample_custom_extension),
|
||||
|
||||
RECYCLER(R.string.sample_recycler),
|
||||
|
||||
;
|
||||
|
||||
private final int textResId;
|
||||
|
||||
Sample(@StringRes int textResId) {
|
||||
this.textResId = textResId;
|
||||
}
|
||||
|
||||
@StringRes
|
||||
public int textResId() {
|
||||
return textResId;
|
||||
}
|
||||
}
|
@ -1,30 +1,79 @@
|
||||
package io.noties.markwon.sample;
|
||||
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.Spanned;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
public enum SampleItem {
|
||||
import io.noties.adapt.Item;
|
||||
import io.noties.markwon.Markwon;
|
||||
import io.noties.markwon.utils.NoCopySpannableFactory;
|
||||
|
||||
// all usages of markwon without plugins (parse, render, setMarkwon, etc)
|
||||
CORE(R.string.sample_core),
|
||||
class SampleItem extends Item<SampleItem.SampleHolder> {
|
||||
|
||||
BASIC_PLUGINS(R.string.sample_basic_plugins),
|
||||
|
||||
LATEX(R.string.sample_latex),
|
||||
|
||||
CUSTOM_EXTENSION(R.string.sample_custom_extension),
|
||||
|
||||
RECYCLER(R.string.sample_recycler),
|
||||
|
||||
;
|
||||
|
||||
private final int textResId;
|
||||
|
||||
SampleItem(@StringRes int textResId) {
|
||||
this.textResId = textResId;
|
||||
interface OnClickListener {
|
||||
void onClick(@NonNull Sample sample);
|
||||
}
|
||||
|
||||
@StringRes
|
||||
public int textResId() {
|
||||
return textResId;
|
||||
private final Sample sample;
|
||||
|
||||
private final Markwon markwon;
|
||||
|
||||
private final OnClickListener onClickListener;
|
||||
|
||||
// instance specific cache
|
||||
private Spanned cache;
|
||||
|
||||
SampleItem(@NonNull Sample sample, @NonNull Markwon markwon, @NonNull OnClickListener onClickListener) {
|
||||
super(sample.ordinal());
|
||||
this.sample = sample;
|
||||
this.markwon = markwon;
|
||||
this.onClickListener = onClickListener;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public SampleHolder createHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
|
||||
|
||||
final SampleHolder holder = new SampleHolder(inflater.inflate(
|
||||
R.layout.adapt_sample_item,
|
||||
parent,
|
||||
false));
|
||||
|
||||
// set Spannable.Factory so when TextView will receive a new content
|
||||
// it won't create new Spannable and copy all the spans but instead
|
||||
// re-use existing Spannable thus improving performance
|
||||
holder.textView.setSpannableFactory(NoCopySpannableFactory.getInstance());
|
||||
|
||||
return holder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(@NonNull SampleHolder holder) {
|
||||
|
||||
// retrieve an item from cache or create new one
|
||||
// simple lazy loading pattern (cache on first call then re-use)
|
||||
Spanned spanned = this.cache;
|
||||
if (spanned == null) {
|
||||
spanned = cache = markwon.toMarkdown(
|
||||
holder.textView.getResources().getString(sample.textResId()));
|
||||
}
|
||||
|
||||
holder.textView.setText(spanned);
|
||||
|
||||
holder.itemView.setOnClickListener(v -> onClickListener.onClick(sample));
|
||||
}
|
||||
|
||||
static class SampleHolder extends Item.Holder {
|
||||
|
||||
final TextView textView;
|
||||
|
||||
SampleHolder(@NonNull View view) {
|
||||
super(view);
|
||||
|
||||
this.textView = requireView(R.id.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,75 +0,0 @@
|
||||
package io.noties.markwon.sample;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.Spannable;
|
||||
import android.text.Spanned;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.EnumMap;
|
||||
|
||||
import io.noties.markwon.Markwon;
|
||||
import io.noties.markwon.utils.NoCopySpannableFactory;
|
||||
import ru.noties.adapt.Holder;
|
||||
import ru.noties.adapt.ItemView;
|
||||
|
||||
class SampleItemView extends ItemView<SampleItem, SampleItemView.SampleHolder> {
|
||||
|
||||
private final Markwon markwon;
|
||||
|
||||
// instance specific factory
|
||||
private final Spannable.Factory factory;
|
||||
|
||||
// instance specific cache
|
||||
private final EnumMap<SampleItem, Spanned> cache;
|
||||
|
||||
SampleItemView(@NonNull Markwon markwon) {
|
||||
this.markwon = markwon;
|
||||
this.factory = NoCopySpannableFactory.getInstance();
|
||||
this.cache = new EnumMap<>(SampleItem.class);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public SampleHolder createHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
|
||||
|
||||
final SampleHolder holder = new SampleHolder(inflater.inflate(
|
||||
R.layout.adapt_sample_item,
|
||||
parent,
|
||||
false));
|
||||
|
||||
// set Spannable.Factory so when TextView will receive a new content
|
||||
// it won't create new Spannable and copy all the spans but instead
|
||||
// re-use existing Spannable thus improving performance
|
||||
holder.textView.setSpannableFactory(factory);
|
||||
|
||||
return holder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindHolder(@NonNull SampleHolder holder, @NonNull SampleItem item) {
|
||||
|
||||
// retrieve an item from cache or create new one
|
||||
// simple lazy loading pattern (cache on first call then re-use)
|
||||
Spanned spanned = cache.get(item);
|
||||
if (spanned == null) {
|
||||
spanned = markwon.toMarkdown(context(holder).getString(item.textResId()));
|
||||
cache.put(item, spanned);
|
||||
}
|
||||
|
||||
holder.textView.setText(spanned);
|
||||
}
|
||||
|
||||
static class SampleHolder extends Holder {
|
||||
|
||||
final TextView textView;
|
||||
|
||||
SampleHolder(@NonNull View view) {
|
||||
super(view);
|
||||
|
||||
this.textView = requireView(R.id.text);
|
||||
}
|
||||
}
|
||||
}
|
@ -32,8 +32,8 @@ import io.noties.markwon.recycler.table.TableEntryPlugin;
|
||||
import io.noties.markwon.sample.R;
|
||||
import io.noties.markwon.urlprocessor.UrlProcessor;
|
||||
import io.noties.markwon.urlprocessor.UrlProcessorRelativeToAbsolute;
|
||||
import ru.noties.debug.AndroidLogDebugOutput;
|
||||
import ru.noties.debug.Debug;
|
||||
import io.noties.debug.AndroidLogDebugOutput;
|
||||
import io.noties.debug.Debug;
|
||||
|
||||
public class RecyclerActivity extends Activity {
|
||||
|
||||
|
@ -17,7 +17,7 @@ public class MainActivityTest {
|
||||
@Test
|
||||
public void all_sample_items_have_activity_associated() {
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
for (SampleItem item : SampleItem.values()) {
|
||||
for (Sample item : Sample.values()) {
|
||||
// we assert as not null, but in case of an error this method should throw
|
||||
assertNotNull(MainActivity.sampleItemIntent(context, item));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user