Skip to content

Commit e06acc1

Browse files
committed
First Release
1 parent e33dd6c commit e06acc1

35 files changed

+850
-92
lines changed

.gitignore

Lines changed: 0 additions & 15 deletions
This file was deleted.

app/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

app/build.gradle

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,28 @@ android {
3131
dependencies {
3232

3333
implementation 'androidx.appcompat:appcompat:1.2.0'
34-
implementation 'com.google.android.material:material:1.2.1'
34+
implementation 'com.google.android.material:material:1.3.0'
3535
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
36-
testImplementation 'junit:junit:4.13.1'
36+
testImplementation 'junit:junit:4.13.2'
3737
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
3838
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
3939

4040
//HttpAccess
4141
implementation 'com.github.bumptech.glide:glide:4.11.0'
4242
implementation 'com.google.code.gson:gson:2.8.6'
4343
implementation 'com.squareup.okhttp3:okhttp:4.8.1'
44-
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
45-
implementation 'com.squareup.retrofit2:converter-scalars:2.3.0'
46-
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
47-
implementation 'com.squareup.retrofit2:converter-gson:2.2.0'
4844

4945
//Config
5046
implementation 'androidx.preference:preference:1.1.1'
5147

5248
//Design
5349
implementation 'com.github.GrenderG:Toasty:1.5.0'
50+
51+
//Regex
52+
implementation 'org.jsoup:jsoup:1.10.3'
53+
54+
//ImageFromUrl
55+
implementation 'com.squareup.picasso:picasso:2.71828'
56+
57+
implementation project(':wordpress')
5458
}

app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.induiduel.word">
4+
45
<uses-permission android:name="android.permission.INTERNET" />
56
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
67
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
8+
79
<application
810
android:allowBackup="true"
9-
android:usesCleartextTraffic="true"
11+
android:fullBackupContent="@xml/backup_descriptor"
1012
android:hardwareAccelerated="true"
1113
android:icon="@mipmap/ic_launcher"
1214
android:label="@string/app_name"
1315
android:roundIcon="@mipmap/ic_launcher_round"
1416
android:supportsRtl="true"
1517
android:theme="@style/Theme.WordApi"
16-
android:fullBackupContent="@xml/backup_descriptor">
18+
android:usesCleartextTraffic="true">
19+
<activity android:name=".activities.PostActivity"></activity>
1720
<activity android:name=".activities.MainActivity">
1821
<intent-filter>
1922
<action android:name="android.intent.action.MAIN" />
2023

2124
<category android:name="android.intent.category.LAUNCHER" />
2225
</intent-filter>
2326
</activity>
27+
2428
<uses-library
2529
android:name="org.apache.http.legacy"
2630
android:required="false" />
Lines changed: 159 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,46 @@
11
package com.induiduel.word.activities;
22

3-
import androidx.appcompat.app.AppCompatActivity;
43

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;
59
import android.os.Bundle;
610
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;
823

924
import com.google.gson.Gson;
10-
import com.google.gson.annotations.SerializedName;
1125
import com.google.gson.reflect.TypeToken;
1226
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;
2033

2134
import java.util.ArrayList;
2235
import java.util.HashMap;
36+
import java.util.regex.Matcher;
37+
import java.util.regex.Pattern;
2338

2439
public class MainActivity extends AppCompatActivity {
2540

41+
RecyclerView recyclerView;
42+
ArrayList<HashMap<String, Object>> arrayComment;
43+
2644
@Override
2745
protected void onCreate(Bundle savedInstanceState) {
2846
super.onCreate(savedInstanceState);
@@ -31,54 +49,167 @@ protected void onCreate(Bundle savedInstanceState) {
3149
onLayoutInit();
3250
onLogicInit();
3351
onClickInit();
52+
53+
3454
}
3555

3656
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/";
3859
}
3960

40-
public void onLayoutInit(){
41-
61+
public void onLayoutInit() {
62+
recyclerView = findViewById(R.id.recycler_view);
4263
}
4364

4465
public void onLogicInit() {
4566

4667
try {
4768
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);
5171
RequestNetwork requestNetwork = new RequestNetwork(this);
5272

5373
requestNetwork.startRequestNetwork(RequestNetworkController.GET, a, "tag", new RequestNetwork.RequestListener() {
5474
@Override
5575
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");
6398
}
64-
} catch (Exception e){
65-
Log.wtf(e.toString(), response);
6699
}
67100

101+
68102
}
69103

70104
@Override
71105
public void onErrorResponse(String tag, String message) {
72-
Log.wtf("Oh May Gud Error", message);
106+
Log.wtf("POSTS RESPONSE ERROR", message);
73107
}
74108
});
75109

76110
} 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;
78124
}
79125

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+
}
80212
}
81213

82-
public void onClickInit() {}
83214

84215
}

0 commit comments

Comments
 (0)