1
1
package com .induiduel .word .activities ;
2
2
3
- import androidx .appcompat .app .AppCompatActivity ;
4
3
4
+ import android .annotation .SuppressLint ;
5
+ import android .content .Context ;
6
+ import android .content .Intent ;
7
+ import android .graphics .Color ;
8
+ import android .graphics .drawable .GradientDrawable ;
5
9
import android .os .Bundle ;
6
10
import android .util .Log ;
7
- import android .widget .Toast ;
11
+ import android .view .LayoutInflater ;
12
+ import android .view .View ;
13
+ import android .view .ViewGroup ;
14
+ import android .widget .Button ;
15
+ import android .widget .ImageView ;
16
+ import android .widget .LinearLayout ;
17
+ import android .widget .TextView ;
18
+
19
+ import androidx .annotation .NonNull ;
20
+ import androidx .appcompat .app .AppCompatActivity ;
21
+ import androidx .recyclerview .widget .LinearLayoutManager ;
22
+ import androidx .recyclerview .widget .RecyclerView ;
8
23
9
24
import com .google .gson .Gson ;
10
- import com .google .gson .annotations .SerializedName ;
11
25
import com .google .gson .reflect .TypeToken ;
12
26
import com .induiduel .word .R ;
13
- import com .induiduel .word .access .okhttp .RequestNetwork ;
14
- import com .induiduel .word .access .okhttp .RequestNetworkController ;
15
- import com .induiduel .word .api .wordpress .filter .Parameters ;
16
- import com .induiduel .word .api .wordpress .read .ReadPosts ;
17
- import com .induiduel .word .config .InitializeApp ;
18
- import com .induiduel .word .utils .InvalidUrl ;
19
- import com .induiduel .word .utils .JsonConverter ;
27
+ import com .induiduel .wordpress .config .InitializeApp ;
28
+ import com .induiduel .wordpress .okhttp .RequestNetwork ;
29
+ import com .induiduel .wordpress .okhttp .RequestNetworkController ;
30
+ import com .induiduel .wordpress .wp .filter .Parameters ;
31
+ import com .induiduel .wordpress .wp .read .ReadPosts ;
32
+ import com .squareup .picasso .Picasso ;
20
33
21
34
import java .util .ArrayList ;
22
35
import java .util .HashMap ;
36
+ import java .util .regex .Matcher ;
37
+ import java .util .regex .Pattern ;
23
38
24
39
public class MainActivity extends AppCompatActivity {
25
40
41
+ RecyclerView recyclerView ;
42
+ ArrayList <HashMap <String , Object >> arrayComment ;
43
+
26
44
@ Override
27
45
protected void onCreate (Bundle savedInstanceState ) {
28
46
super .onCreate (savedInstanceState );
@@ -31,54 +49,167 @@ protected void onCreate(Bundle savedInstanceState) {
31
49
onLayoutInit ();
32
50
onLogicInit ();
33
51
onClickInit ();
52
+
53
+
34
54
}
35
55
36
56
public void onCreateInit () {
37
- InitializeApp .url = "https://androidoyun.club/wp-json/wp/v2/" ;
57
+ // InitializeApp.url = "https://androidoyun.club/wp-json/wp/v2/";
58
+ InitializeApp .url = "https://notalarim.com/wp-json/wp/v2/" ;
38
59
}
39
60
40
- public void onLayoutInit (){
41
-
61
+ public void onLayoutInit () {
62
+ recyclerView = findViewById ( R . id . recycler_view );
42
63
}
43
64
44
65
public void onLogicInit () {
45
66
46
67
try {
47
68
Parameters parameters = new Parameters (InitializeApp .url , "posts" );
48
- String a = parameters .page (1 ).postPerPage (50 ).search ("minecraft" ).order (Parameters .DESC )
49
- .orderBy (0 ).context (0 ).type (0 ).title ("abc" ).apply ();
50
-
69
+ String a = parameters .apply ();
70
+ Log .wtf ("URL CUSTOM" , a );
51
71
RequestNetwork requestNetwork = new RequestNetwork (this );
52
72
53
73
requestNetwork .startRequestNetwork (RequestNetworkController .GET , a , "tag" , new RequestNetwork .RequestListener () {
54
74
@ Override
55
75
public void onResponse (String tag , String response , HashMap <String , Object > responseHeaders ) {
56
-
57
- try {
58
- ArrayList <ReadPosts > readPostsArrayList = new Gson ().fromJson (response , new TypeToken <ArrayList <ReadPosts >>() {}.getType ());
59
- for ( int i = 0 ; i < readPostsArrayList .size (); i ++){
60
-
61
- Log .wtf ("My Gudniz" , readPostsArrayList .get (i ).getSlug ());
62
-
76
+ if (response .contains ("rest_invalid_param" )){
77
+ Log .wtf ("REST" , response );
78
+ }else {
79
+ Log .wtf ("ELSE WORKS" , response );
80
+ try {
81
+ Log .wtf ("TRY WORKS" , "a" );
82
+ PostActivity .RESPONSE = response ;
83
+ ArrayList <ReadPosts > readPostsArrayList = new Gson ().fromJson (response , new TypeToken <ArrayList <ReadPosts >>() {
84
+ }.getType ());
85
+
86
+ for (int i = 0 ; i < readPostsArrayList .size (); i ++) {
87
+
88
+ Log .wtf ("POST SLUGS" , readPostsArrayList .get (i ).getSlug ());
89
+
90
+ }
91
+ Log .wtf ("POST DATE" , readPostsArrayList .get (0 ).getContentDate ());
92
+ recyclerView .setAdapter (new RecyclerViewAdapterMain (readPostsArrayList ));
93
+ recyclerView .setLayoutManager (new LinearLayoutManager (getParent ()));
94
+
95
+ } catch (Exception e ) {
96
+ e .printStackTrace ();
97
+ Log .wtf (e .toString (), "response" );
63
98
}
64
- } catch (Exception e ){
65
- Log .wtf (e .toString (), response );
66
99
}
67
100
101
+
68
102
}
69
103
70
104
@ Override
71
105
public void onErrorResponse (String tag , String message ) {
72
- Log .wtf ("Oh May Gud Error " , message );
106
+ Log .wtf ("POSTS RESPONSE ERROR " , message );
73
107
}
74
108
});
75
109
76
110
} catch (Exception e ) {
77
- Log .wtf (" sss " , e .toString ());
111
+ Log .wtf (" TRY CATCH ERROR POST " , e .toString ());
112
+ }
113
+
114
+ }
115
+
116
+ public void onClickInit () {
117
+ }
118
+
119
+ public class RecyclerViewAdapterMain extends RecyclerView .Adapter <RecyclerView .ViewHolder > {
120
+ ArrayList <ReadPosts > _data ;
121
+
122
+ public RecyclerViewAdapterMain (ArrayList <ReadPosts > _arr ) {
123
+ _data = _arr ;
78
124
}
79
125
126
+ @ NonNull
127
+ @ Override
128
+ public RecyclerView .ViewHolder onCreateViewHolder (@ NonNull ViewGroup parent , int viewType ) {
129
+ LayoutInflater _inflater = (LayoutInflater ) getBaseContext ().getSystemService (Context .LAYOUT_INFLATER_SERVICE );
130
+ View _v = _inflater .inflate (R .layout .gridlayout_custom , parent , false );
131
+ return new ViewHolder (_v );
132
+ }
133
+
134
+ @ SuppressLint ("SetTextI18n" )
135
+ @ Override
136
+ public void onBindViewHolder (@ NonNull RecyclerView .ViewHolder holder , final int _position ) {
137
+ View _view = holder .itemView ;
138
+
139
+ final LinearLayout lin = _view .findViewById (R .id .lin );
140
+ final TextView headerText = _view .findViewById (R .id .headText );
141
+ // final TextView excerptText = _view.findViewById(R.id.excerptText);
142
+ //final TextView comments = _view.findViewById(R.id.comments);
143
+ // final TextView dateText = _view.findViewById(R.id.dateText);
144
+ final ImageView image = _view .findViewById (R .id .image );
145
+ final Button button = _view .findViewById (R .id .devamBtn );
146
+ image .setClipToOutline (true );
147
+ GradientDrawable gd = new GradientDrawable ();
148
+ gd .setCornerRadius (16 );
149
+ gd .setColor (Color .parseColor ("#fefefe" ));
150
+ lin .setBackground (gd );
151
+
152
+ GradientDrawable gradientButton = new GradientDrawable ();
153
+ gradientButton .setCornerRadius (16 );
154
+ gradientButton .setColor (getColor (R .color .colorGreen ));
155
+ button .setBackground (gradientButton );
156
+
157
+ headerText .setText (_data .get (_position ).getTitle ().getRendered ());
158
+ //excerptText.setText(Html.fromHtml(_data.get(_position).getExcerpt().getRendered()));
159
+
160
+ int idPost = _data .get (_position ).getContentId ();
161
+
162
+ //String newDate = _data.get(_position).getContentDate().substring(0,_data.get(_position).getContentDate().indexOf("T"));
163
+ //dateText.setText(newDate);
164
+
165
+ Pattern p = Pattern .compile ("<p><a href=\\ \" (.*?)\" ><img loading=\\ \" (.*?)\\ \" class=\\ \" (.*?)\" src=\\ \" (.*?)\" .*<\\ /a>" , Pattern .DOTALL );
166
+ Matcher m = p .matcher (_data .get (_position ).getContent ().getRendered ());
167
+
168
+ while (m .find ()) {
169
+ if (m .group (1 ).length () > 15 ) {
170
+
171
+ Log .wtf ("API KEY IS REGEX 1" , m .group (1 ) + "\n \n \n " );
172
+
173
+ Picasso .get ().load (m .group (1 )).into (image );
174
+ GradientDrawable imageShape = new GradientDrawable ();
175
+ imageShape .setCornerRadius (26 );
176
+ image .setBackground (imageShape );
177
+ }
178
+ }
179
+ Log .wtf ("Media URL" , _data .get (_position ).getLinks ().getWpAttachment ().get (0 ).getHref ());
180
+ Log .wtf ("Comments URL" , _data .get (_position ).getLinks ().getReplies ().get (0 ).getHref ());
181
+
182
+
183
+ lin .setOnClickListener (new View .OnClickListener () {
184
+ @ Override
185
+ public void onClick (View v ) {
186
+
187
+ Intent intent = new Intent (getApplicationContext (), PostActivity .class );
188
+
189
+ intent .putExtra ("postPosition" , _position );
190
+ startActivity (intent );
191
+ }
192
+ });
193
+
194
+ }
195
+
196
+ @ Override
197
+ public long getItemId (int _index ) {
198
+ return _index ;
199
+ }
200
+
201
+ @ Override
202
+ public int getItemCount () {
203
+ return _data .size ();
204
+ // return (_data == null) ? 0 : _data.size();
205
+ }
206
+
207
+ public class ViewHolder extends RecyclerView .ViewHolder {
208
+ public ViewHolder (@ NonNull View itemView ) {
209
+ super (itemView );
210
+ }
211
+ }
80
212
}
81
213
82
- public void onClickInit () {}
83
214
84
215
}
0 commit comments