forked from Electrostat-Lab/DBTraining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModelAdapter.java
62 lines (51 loc) · 2.42 KB
/
ModelAdapter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.scrappers.dbtraining.contentRecyclerView;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.widget.LinearLayout;
import com.scrappers.dbtraining.R;
import com.scrappers.dbtraining.javaScriptInterface.CodeEditorInterface;
import java.util.ArrayList;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
public class ModelAdapter extends RecyclerView.Adapter<AdapterHolder> {
private final Context context;
private ArrayList<DataModel> models;
public ModelAdapter(Context context, ArrayList<DataModel> models) {
this.context=context;
this.models=models;
}
@SuppressLint("InflateParams")
@NonNull
@Override
public AdapterHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new AdapterHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.datamodel_iostream,parent,false));
}
@SuppressLint("SetJavaScriptEnabled")
@Override
public void onBindViewHolder(@NonNull AdapterHolder holder, int position) {
holder.title.setText(models.get(position).getTitle());
holder.illustrations.setText(models.get(position).getIllustrations());
WebSettings webSettings=holder.webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setAllowFileAccess(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setDisplayZoomControls(true);
webSettings.setSupportZoom(true);
webSettings.setDisplayZoomControls(true);
holder.editor.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,models.get(position).getEditorHeight()));
holder.webView.loadUrl("file:///android_asset/CodeEditor.html");
CodeEditorInterface codeEditorInterface=new CodeEditorInterface(context);
codeEditorInterface.setCode(models.get(position).getCode());
codeEditorInterface.setMode(models.get(position).getMode());
codeEditorInterface.setContainerHeight(models.get(position).getEditorHeight());
codeEditorInterface.setTheme(models.get(position).getTheme());
holder.webView.addJavascriptInterface(codeEditorInterface,"CodeEditor");
}
@Override
public int getItemCount() {
return models.size();
}
}