fix: HelpCatologueActivity and DocumentationActivity lag
This commit is contained in:
@@ -117,6 +117,7 @@ dependencies {
|
|||||||
compile 'com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1'
|
compile 'com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1'
|
||||||
compile 'com.yqritc:recyclerview-flexibledivider:1.4.0'
|
compile 'com.yqritc:recyclerview-flexibledivider:1.4.0'
|
||||||
compile 'com.ashokvarma.android:bottom-navigation-bar:2.0.1'
|
compile 'com.ashokvarma.android:bottom-navigation-bar:2.0.1'
|
||||||
|
compile 'com.wang.avi:library:2.1.3'
|
||||||
// Tasker Plugin
|
// Tasker Plugin
|
||||||
compile 'com.twofortyfouram:android-plugin-client-sdk-for-locale:[4.0.2, 5.0['
|
compile 'com.twofortyfouram:android-plugin-client-sdk-for-locale:[4.0.2, 5.0['
|
||||||
compile 'com.android.volley:volley:1.0.0'
|
compile 'com.android.volley:volley:1.0.0'
|
||||||
|
|||||||
5
app/proguard-rules.pro
vendored
5
app/proguard-rules.pro
vendored
@@ -127,3 +127,8 @@
|
|||||||
-keepnames class * implements android.os.Parcelable {
|
-keepnames class * implements android.os.Parcelable {
|
||||||
public static final ** CREATOR;
|
public static final ** CREATOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# AVLoadingView
|
||||||
|
|
||||||
|
-keep class com.wang.avi.** { *; }
|
||||||
|
-keep class com.wang.avi.indicators.** { *; }
|
||||||
@@ -3,11 +3,15 @@ package com.stardust.scriptdroid.ui.help;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.webkit.WebView;
|
||||||
|
|
||||||
import com.stardust.pio.PFile;
|
import com.stardust.pio.PFile;
|
||||||
import com.stardust.scriptdroid.ui.BaseActivity;
|
import com.stardust.scriptdroid.ui.BaseActivity;
|
||||||
|
import com.stardust.theme.ThemeColorManagerCompat;
|
||||||
|
import com.stardust.util.UnderuseExecutors;
|
||||||
import com.stardust.widget.CommonMarkdownView;
|
import com.stardust.widget.CommonMarkdownView;
|
||||||
import com.stardust.scriptdroid.R;
|
import com.stardust.scriptdroid.R;
|
||||||
|
import com.wang.avi.AVLoadingIndicatorView;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -27,46 +31,60 @@ public class DocumentationActivity extends BaseActivity {
|
|||||||
.putExtra("path", assetPath));
|
.putExtra("path", assetPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openDocumentation(Context context, String title, int rawResId) {
|
private volatile String mDocumentation;
|
||||||
context.startActivity(new Intent(context, DocumentationActivity.class)
|
|
||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
||||||
.putExtra("title", title)
|
|
||||||
.putExtra("resId", rawResId));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String mDocumentation;
|
|
||||||
private String mTitle;
|
private String mTitle;
|
||||||
|
private AVLoadingIndicatorView mLoadingIndicatorView;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
handleIntent(getIntent());
|
|
||||||
setUpUI();
|
setUpUI();
|
||||||
|
handleIntent(getIntent());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleIntent(Intent intent) {
|
private void handleIntent(Intent intent) {
|
||||||
mTitle = intent.getStringExtra("title");
|
mTitle = intent.getStringExtra("title");
|
||||||
String path = intent.getStringExtra("path");
|
final String path = intent.getStringExtra("path");
|
||||||
int rawId = intent.getIntExtra("resId", 0);
|
if (path == null)
|
||||||
if (path != null) {
|
return;
|
||||||
try {
|
UnderuseExecutors.execute(new Runnable() {
|
||||||
mDocumentation = PFile.read(getAssets().open("help/" + path));
|
@Override
|
||||||
} catch (IOException e) {
|
public void run() {
|
||||||
e.printStackTrace();
|
try {
|
||||||
|
mDocumentation = PFile.read(getAssets().open("help/" + path));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
loadDocument();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else if (rawId != 0) {
|
});
|
||||||
mDocumentation = PFile.read(getResources().openRawResource(rawId));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpUI() {
|
private void setUpUI() {
|
||||||
setContentView(R.layout.activity_document);
|
setContentView(R.layout.activity_document);
|
||||||
setToolbarAsBack(mTitle);
|
setToolbarAsBack(mTitle);
|
||||||
loadDocument();
|
setUpLoadingView();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setUpLoadingView() {
|
||||||
|
mLoadingIndicatorView = $(R.id.loading);
|
||||||
|
mLoadingIndicatorView.setIndicatorColor(ThemeColorManagerCompat.getColorPrimary());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadDocument() {
|
private void loadDocument() {
|
||||||
mCommonMarkdownView = $(R.id.markdown);
|
mCommonMarkdownView = $(R.id.markdown);
|
||||||
|
mCommonMarkdownView.setOnPageFinishedListener(new CommonMarkdownView.OnPageFinishedListener() {
|
||||||
|
@Override
|
||||||
|
public void onPageFinished(WebView view, String url) {
|
||||||
|
mLoadingIndicatorView.hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
try {
|
try {
|
||||||
mCommonMarkdownView.loadMarkdown(mDocumentation);
|
mCommonMarkdownView.loadMarkdown(mDocumentation);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import android.os.Bundle;
|
|||||||
import android.support.annotation.Keep;
|
import android.support.annotation.Keep;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.widget.DividerItemDecoration;
|
import android.support.v7.widget.DividerItemDecoration;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -20,6 +19,9 @@ import com.stardust.scriptdroid.ui.BaseActivity;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import com.stardust.scriptdroid.R;
|
import com.stardust.scriptdroid.R;
|
||||||
|
import com.stardust.theme.ThemeColorManagerCompat;
|
||||||
|
import com.stardust.util.UnderuseExecutors;
|
||||||
|
import com.wang.avi.AVLoadingIndicatorView;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
@@ -48,7 +50,7 @@ public class HelpCatalogueActivity extends BaseActivity {
|
|||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Map<String, List<Item>> CATALOGUES;
|
private static Map<String, List<Item>> CATALOGUES;
|
||||||
|
|
||||||
private static class Item extends JSONObject {
|
private static class Item extends JSONObject {
|
||||||
|
|
||||||
@@ -86,6 +88,7 @@ public class HelpCatalogueActivity extends BaseActivity {
|
|||||||
|
|
||||||
List<Item> mItems;
|
List<Item> mItems;
|
||||||
private RecyclerView mRecyclerView;
|
private RecyclerView mRecyclerView;
|
||||||
|
private AVLoadingIndicatorView mLoadingIndicatorView;
|
||||||
private String mTitle;
|
private String mTitle;
|
||||||
private View.OnClickListener mOnItemClickListener = new View.OnClickListener() {
|
private View.OnClickListener mOnItemClickListener = new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -100,8 +103,29 @@ public class HelpCatalogueActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
handleIntent();
|
|
||||||
setUpUI();
|
setUpUI();
|
||||||
|
if (CATALOGUES == null) {
|
||||||
|
readCatalogues();
|
||||||
|
} else {
|
||||||
|
mLoadingIndicatorView.hide();
|
||||||
|
handleIntent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void readCatalogues() {
|
||||||
|
UnderuseExecutors.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
readCatalogues("help/catalogue.json");
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mLoadingIndicatorView.hide();
|
||||||
|
handleIntent();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleIntent() {
|
private void handleIntent() {
|
||||||
@@ -112,21 +136,27 @@ public class HelpCatalogueActivity extends BaseActivity {
|
|||||||
if (mTitle == null)
|
if (mTitle == null)
|
||||||
mTitle = getString(R.string.text_help);
|
mTitle = getString(R.string.text_help);
|
||||||
mItems = CATALOGUES.get(catalogue);
|
mItems = CATALOGUES.get(catalogue);
|
||||||
|
mRecyclerView.setAdapter(new Adapter());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpUI() {
|
private void setUpUI() {
|
||||||
setContentView(R.layout.activity_help);
|
setContentView(R.layout.activity_help);
|
||||||
setToolbarAsBack(mTitle);
|
setToolbarAsBack(mTitle);
|
||||||
setUpRecyclerView();
|
setUpRecyclerView();
|
||||||
|
setUpLoadingView();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpRecyclerView() {
|
private void setUpRecyclerView() {
|
||||||
mRecyclerView = $(R.id.catalogue);
|
mRecyclerView = $(R.id.catalogue);
|
||||||
mRecyclerView.setLayoutManager(new WrapContentLinearLayoutManager(this));
|
mRecyclerView.setLayoutManager(new WrapContentLinearLayoutManager(this));
|
||||||
mRecyclerView.setAdapter(new Adapter());
|
|
||||||
mRecyclerView.addItemDecoration(new DividerItemDecoration(this, RecyclerView.VERTICAL));
|
mRecyclerView.addItemDecoration(new DividerItemDecoration(this, RecyclerView.VERTICAL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setUpLoadingView() {
|
||||||
|
mLoadingIndicatorView = $(R.id.loading);
|
||||||
|
mLoadingIndicatorView.setIndicatorColor(ThemeColorManagerCompat.getColorPrimary());
|
||||||
|
}
|
||||||
|
|
||||||
private class Adapter extends RecyclerView.Adapter<ViewHolder> {
|
private class Adapter extends RecyclerView.Adapter<ViewHolder> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -166,10 +196,10 @@ public class HelpCatalogueActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
private static void readCatalogues(String path) {
|
||||||
Map<String, List<Item>> fromJson;
|
Map<String, List<Item>> fromJson;
|
||||||
try {
|
try {
|
||||||
String json = PFile.read(App.getApp().getAssets().open("help/catalogue.json"));
|
String json = PFile.read(App.getApp().getAssets().open(path));
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
Type type = new TypeToken<Map<String, List<Item>>>() {
|
Type type = new TypeToken<Map<String, List<Item>>>() {
|
||||||
}.getType();
|
}.getType();
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ import java.util.Collections;
|
|||||||
|
|
||||||
public class CommonMarkdownView extends WebView {
|
public class CommonMarkdownView extends WebView {
|
||||||
|
|
||||||
|
public interface OnPageFinishedListener {
|
||||||
|
void onPageFinished(WebView view, String url);
|
||||||
|
}
|
||||||
|
|
||||||
private Parser mParser = Parser.builder().build();
|
private Parser mParser = Parser.builder().build();
|
||||||
private HtmlRenderer mHtmlRender = HtmlRenderer.builder()
|
private HtmlRenderer mHtmlRender = HtmlRenderer.builder()
|
||||||
.extensions(Collections.singleton(new HeadingAnchorExtension.Builder().build()))
|
.extensions(Collections.singleton(new HeadingAnchorExtension.Builder().build()))
|
||||||
@@ -35,6 +39,7 @@ public class CommonMarkdownView extends WebView {
|
|||||||
|
|
||||||
private String mMarkdownHtml;
|
private String mMarkdownHtml;
|
||||||
private String mPadding = "16px";
|
private String mPadding = "16px";
|
||||||
|
private OnPageFinishedListener mOnPageFinishedListener;
|
||||||
|
|
||||||
public CommonMarkdownView(Context context) {
|
public CommonMarkdownView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -60,6 +65,9 @@ public class CommonMarkdownView extends WebView {
|
|||||||
@Override
|
@Override
|
||||||
public void onPageFinished(WebView view, String url) {
|
public void onPageFinished(WebView view, String url) {
|
||||||
loadUrl("javascript:document.body.style.margin=\"" + mPadding + "\"; void 0");
|
loadUrl("javascript:document.body.style.margin=\"" + mPadding + "\"; void 0");
|
||||||
|
if (mOnPageFinishedListener != null) {
|
||||||
|
mOnPageFinishedListener.onPageFinished(view, url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||||
@@ -89,6 +97,10 @@ public class CommonMarkdownView extends WebView {
|
|||||||
loadHtml(mMarkdownHtml);
|
loadHtml(mMarkdownHtml);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setOnPageFinishedListener(OnPageFinishedListener onPageFinishedListener) {
|
||||||
|
mOnPageFinishedListener = onPageFinishedListener;
|
||||||
|
}
|
||||||
|
|
||||||
private void loadHtml(String html) {
|
private void loadHtml(String html) {
|
||||||
loadDataWithBaseURL(null, html, "text/html", "utf-8", null);
|
loadDataWithBaseURL(null, html, "text/html", "utf-8", null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,9 +20,26 @@
|
|||||||
|
|
||||||
</android.support.design.widget.AppBarLayout>
|
</android.support.design.widget.AppBarLayout>
|
||||||
|
|
||||||
<com.stardust.widget.CommonMarkdownView
|
<FrameLayout
|
||||||
android:id="@+id/markdown"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent">
|
||||||
android:textColor="@android:color/secondary_text_light"/>
|
|
||||||
|
|
||||||
|
<com.stardust.widget.CommonMarkdownView
|
||||||
|
android:id="@+id/markdown"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:textColor="@android:color/secondary_text_light"/>
|
||||||
|
|
||||||
|
<com.wang.avi.AVLoadingIndicatorView
|
||||||
|
android:id="@+id/loading"
|
||||||
|
style="@style/AVLoadingIndicatorView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
app:indicatorName="BallSpinFadeLoaderIndicator"/>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -21,8 +21,24 @@
|
|||||||
|
|
||||||
</android.support.design.widget.AppBarLayout>
|
</android.support.design.widget.AppBarLayout>
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
|
||||||
android:id="@+id/catalogue"
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"/>
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<android.support.v7.widget.RecyclerView
|
||||||
|
android:id="@+id/catalogue"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"/>
|
||||||
|
|
||||||
|
<com.wang.avi.AVLoadingIndicatorView
|
||||||
|
android:id="@+id/loading"
|
||||||
|
style="@style/AVLoadingIndicatorView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
app:indicatorName="BallSpinFadeLoaderIndicator"/>
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
Reference in New Issue
Block a user