Skip to content

Commit

Permalink
knowledgeBase is suppported webview
Browse files Browse the repository at this point in the history
  • Loading branch information
Itgel G committed Nov 24, 2020
1 parent 0410c10 commit dc76656
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@
import androidx.appcompat.app.AppCompatActivity;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Base64;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

Expand All @@ -28,6 +36,8 @@ public class FaqDetailActivity extends AppCompatActivity {
private Point size;
private Config config;
private ImageView backImageView, cancelImageView;
private View loaderView;
private WebView webView;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -44,6 +54,7 @@ private void load_findViewByid(){
container = this.findViewById(R.id.container);
backImageView = this.findViewById(R.id.backImageView);
cancelImageView = this.findViewById(R.id.cancelImageView);
loaderView = this.findViewById(R.id.loaderView);
initIcon();

size = ErxesHelper.display_configure(this,container,"#00000000");
Expand Down Expand Up @@ -92,7 +103,7 @@ public void onClick(View v) {
TextView articleHeader = this.findViewById(R.id.article_header);
TextView date = this.findViewById(R.id.article_date);
TextView content1 = this.findViewById(R.id.article_content1);
TextView content2 = this.findViewById(R.id.article_content2);
webView = this.findViewById(R.id.article_content2);

String id = getIntent().getStringExtra("id");
String categoryId = getIntent().getStringExtra("categoryId");
Expand All @@ -114,14 +125,39 @@ public void onClick(View v) {
}
}
if (knowledgeBaseArticle != null) {
Log.e("TAG", "load_findViewByid: " + knowledgeBaseArticle.createdDate );
general.setText(knowledgeBaseArticle.title);
date.setText("Created : " + config.FullDate(knowledgeBaseArticle.createdDate));
articleHeader.setText(knowledgeBaseArticle.title);
content1.setText(Html.fromHtml(knowledgeBaseArticle.summary));
content1.setMovementMethod(LinkMovementMethod.getInstance());
content2.setText(Html.fromHtml(knowledgeBaseArticle.content));
content2.setMovementMethod(LinkMovementMethod.getInstance());
webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);

webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setLoadsImagesAutomatically(true);
webView.clearCache(false);
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
loaderView.setVisibility(View.GONE);
}

@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
Log.e("TAG", "onReceivedError: " + error.toString() );
}

});

String newhtml_code = Base64.encodeToString(knowledgeBaseArticle.content.getBytes(), Base64.NO_PADDING);

webView.getSettings().setJavaScriptEnabled(true);
webView.loadData(newhtml_code, "text/html", "base64");

}
}
}
Expand All @@ -141,4 +177,13 @@ protected void onResume() {
super.onResume();
config.setActivityConfig(this);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
webView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
21 changes: 13 additions & 8 deletions erxeslibrary/src/main/res/layout/activity_faq_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/main_margin"
android:layout_marginTop="@dimen/main_margin"
android:layout_marginRight="@dimen/main_margin"
android:layout_height="match_parent"
android:padding="@dimen/main_margin"
android:background="#fff"
android:orientation="vertical">

Expand Down Expand Up @@ -56,11 +54,18 @@
android:layout_marginBottom="10dp"
android:textColor="#494949" />

<TextView
android:id="@+id/article_content2"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#494949" />
android:layout_height="match_parent">

<WebView
android:id="@+id/article_content2"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<include layout="@layout/loader_view"/>
</RelativeLayout>

</LinearLayout>
</ScrollView>

Expand Down

0 comments on commit dc76656

Please sign in to comment.