|
@@ -10,33 +10,55 @@ import android.widget.TextView;
|
|
|
|
|
|
import org.json.JSONArray;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONObject;
|
|
import org.json.JSONObject;
|
|
|
|
+import org.w3c.dom.Text;
|
|
|
|
|
|
-public class MainActivity extends Activity implements Interface {
|
|
|
|
|
|
+public class MainActivity extends Activity implements Share {
|
|
|
|
|
|
- private Interface context;
|
|
|
|
|
|
+ private Share context;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void Main(final JSONArray array) {
|
|
|
|
|
|
+ public void ParseNews(final JSONArray array) {
|
|
|
|
|
|
runOnUiThread(new Runnable() {
|
|
runOnUiThread(new Runnable() {
|
|
@Override
|
|
@Override
|
|
public void run() {
|
|
public void run() {
|
|
-
|
|
|
|
- LinearLayout news = findViewById(R.id.newContainer);
|
|
|
|
|
|
+ LinearLayout news = findViewById(R.id.newsContainer);
|
|
|
|
|
|
try {
|
|
try {
|
|
for (int i = 0; i < array.length(); i++) {
|
|
for (int i = 0; i < array.length(); i++) {
|
|
|
|
|
|
JSONObject o = array.getJSONObject(i);
|
|
JSONObject o = array.getJSONObject(i);
|
|
|
|
|
|
|
|
+ LinearLayout.LayoutParams newsItemLayout = new LinearLayout.LayoutParams(
|
|
|
|
+ LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
|
+ LinearLayout.LayoutParams.WRAP_CONTENT
|
|
|
|
+ );
|
|
|
|
+ newsItemLayout.bottomMargin = 20;
|
|
|
|
+
|
|
|
|
+ LinearLayout newsItem = new LinearLayout(getApplicationContext());
|
|
|
|
+ newsItem.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
+ newsItem.setBackgroundColor(Color.WHITE);
|
|
|
|
+ newsItem.setPadding(20, 20, 20, 20);
|
|
|
|
+ newsItem.setLayoutParams(newsItemLayout);
|
|
|
|
+
|
|
TextView caption = new TextView(getApplicationContext());
|
|
TextView caption = new TextView(getApplicationContext());
|
|
|
|
|
|
if (o.has("Caption")) {
|
|
if (o.has("Caption")) {
|
|
caption.setText(o.getString("Caption"));
|
|
caption.setText(o.getString("Caption"));
|
|
- caption.setPadding(0, 20, 0, 20);
|
|
|
|
- caption.setTextColor(Color.RED);
|
|
|
|
- news.addView(caption);
|
|
|
|
|
|
+ caption.setTextSize(20);
|
|
|
|
+ caption.setPadding(0, 0, 0, 40);
|
|
|
|
+ newsItem.addView(caption);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TextView preview = new TextView(getApplicationContext());
|
|
|
|
+
|
|
|
|
+ if (o.has("Preview")) {
|
|
|
|
+ preview.setText(o.getString("Preview"));
|
|
|
|
+ preview.setLines(6);
|
|
|
|
+ newsItem.addView(preview);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ news.addView(newsItem);
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
@@ -54,14 +76,12 @@ public class MainActivity extends Activity implements Interface {
|
|
context = this;
|
|
context = this;
|
|
|
|
|
|
Button button = findViewById(R.id.button);
|
|
Button button = findViewById(R.id.button);
|
|
|
|
+
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
@Override
|
|
public void onClick(View view) {
|
|
public void onClick(View view) {
|
|
- API api = new API();
|
|
|
|
- api.url = "https:/ktk-45.ru/news";
|
|
|
|
- api.param = "{\"Page\": 0,\"Limit\": 10}";
|
|
|
|
- api.context = context;
|
|
|
|
- api.start();
|
|
|
|
|
|
+ Fetch fetch = new Fetch("https://ktk-45.ru/news", "{\"Page\": 0,\"Limit\": 10}", context);
|
|
|
|
+ fetch.start();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|