Skip to content

Commit

Permalink
First Release
Browse files Browse the repository at this point in the history
  • Loading branch information
induiduel committed Apr 9, 2021
1 parent e33dd6c commit e06acc1
Show file tree
Hide file tree
Showing 35 changed files with 850 additions and 92 deletions.
15 changes: 0 additions & 15 deletions .gitignore

This file was deleted.

1 change: 0 additions & 1 deletion app/.gitignore

This file was deleted.

16 changes: 10 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,28 @@ android {
dependencies {

implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

//HttpAccess
implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.squareup.okhttp3:okhttp:4.8.1'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.3.0'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.2.0'

//Config
implementation 'androidx.preference:preference:1.1.1'

//Design
implementation 'com.github.GrenderG:Toasty:1.5.0'

//Regex
implementation 'org.jsoup:jsoup:1.10.3'

//ImageFromUrl
implementation 'com.squareup.picasso:picasso:2.71828'

implementation project(':wordpress')
}
8 changes: 6 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.induiduel.word">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<application
android:allowBackup="true"
android:usesCleartextTraffic="true"
android:fullBackupContent="@xml/backup_descriptor"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.WordApi"
android:fullBackupContent="@xml/backup_descriptor">
android:usesCleartextTraffic="true">
<activity android:name=".activities.PostActivity"></activity>
<activity android:name=".activities.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
Expand Down
187 changes: 159 additions & 28 deletions app/src/main/java/com/induiduel/word/activities/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
package com.induiduel.word.activities;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import com.induiduel.word.R;
import com.induiduel.word.access.okhttp.RequestNetwork;
import com.induiduel.word.access.okhttp.RequestNetworkController;
import com.induiduel.word.api.wordpress.filter.Parameters;
import com.induiduel.word.api.wordpress.read.ReadPosts;
import com.induiduel.word.config.InitializeApp;
import com.induiduel.word.utils.InvalidUrl;
import com.induiduel.word.utils.JsonConverter;
import com.induiduel.wordpress.config.InitializeApp;
import com.induiduel.wordpress.okhttp.RequestNetwork;
import com.induiduel.wordpress.okhttp.RequestNetworkController;
import com.induiduel.wordpress.wp.filter.Parameters;
import com.induiduel.wordpress.wp.read.ReadPosts;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MainActivity extends AppCompatActivity {

RecyclerView recyclerView;
ArrayList<HashMap<String, Object>> arrayComment;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -31,54 +49,167 @@ protected void onCreate(Bundle savedInstanceState) {
onLayoutInit();
onLogicInit();
onClickInit();


}

public void onCreateInit() {
InitializeApp.url = "https://androidoyun.club/wp-json/wp/v2/";
// InitializeApp.url = "https://androidoyun.club/wp-json/wp/v2/";
InitializeApp.url = "https://notalarim.com/wp-json/wp/v2/";
}

public void onLayoutInit(){

public void onLayoutInit() {
recyclerView = findViewById(R.id.recycler_view);
}

public void onLogicInit() {

try {
Parameters parameters = new Parameters(InitializeApp.url, "posts");
String a = parameters.page(1).postPerPage(50).search("minecraft").order(Parameters.DESC)
.orderBy(0).context(0).type(0).title("abc").apply();

String a = parameters.apply();
Log.wtf("URL CUSTOM", a);
RequestNetwork requestNetwork = new RequestNetwork(this);

requestNetwork.startRequestNetwork(RequestNetworkController.GET, a, "tag", new RequestNetwork.RequestListener() {
@Override
public void onResponse(String tag, String response, HashMap<String, Object> responseHeaders) {

try {
ArrayList<ReadPosts> readPostsArrayList = new Gson().fromJson(response, new TypeToken<ArrayList<ReadPosts>>() {}.getType());
for ( int i = 0; i < readPostsArrayList.size(); i++){

Log.wtf("My Gudniz" , readPostsArrayList.get(i).getSlug());

if(response.contains("rest_invalid_param")){
Log.wtf("REST", response);
}else{
Log.wtf("ELSE WORKS", response);
try {
Log.wtf("TRY WORKS", "a");
PostActivity.RESPONSE = response;
ArrayList<ReadPosts> readPostsArrayList = new Gson().fromJson(response, new TypeToken<ArrayList<ReadPosts>>() {
}.getType());

for (int i = 0; i < readPostsArrayList.size(); i++) {

Log.wtf("POST SLUGS", readPostsArrayList.get(i).getSlug());

}
Log.wtf("POST DATE", readPostsArrayList.get(0).getContentDate());
recyclerView.setAdapter(new RecyclerViewAdapterMain(readPostsArrayList));
recyclerView.setLayoutManager(new LinearLayoutManager(getParent()));

} catch (Exception e) {
e.printStackTrace();
Log.wtf(e.toString(), "response");
}
} catch (Exception e){
Log.wtf(e.toString(), response);
}


}

@Override
public void onErrorResponse(String tag, String message) {
Log.wtf("Oh May Gud Error", message);
Log.wtf("POSTS RESPONSE ERROR", message);
}
});

} catch (Exception e) {
Log.wtf(" sss " , e.toString());
Log.wtf(" TRY CATCH ERROR POST ", e.toString());
}

}

public void onClickInit() {
}

public class RecyclerViewAdapterMain extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
ArrayList<ReadPosts> _data;

public RecyclerViewAdapterMain(ArrayList<ReadPosts> _arr) {
_data = _arr;
}

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater _inflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View _v = _inflater.inflate(R.layout.gridlayout_custom, parent, false);
return new ViewHolder(_v);
}

@SuppressLint("SetTextI18n")
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int _position) {
View _view = holder.itemView;

final LinearLayout lin = _view.findViewById(R.id.lin);
final TextView headerText = _view.findViewById(R.id.headText);
// final TextView excerptText = _view.findViewById(R.id.excerptText);
//final TextView comments = _view.findViewById(R.id.comments);
// final TextView dateText = _view.findViewById(R.id.dateText);
final ImageView image = _view.findViewById(R.id.image);
final Button button = _view.findViewById(R.id.devamBtn);
image.setClipToOutline(true);
GradientDrawable gd = new GradientDrawable();
gd.setCornerRadius(16);
gd.setColor(Color.parseColor("#fefefe"));
lin.setBackground(gd);

GradientDrawable gradientButton = new GradientDrawable();
gradientButton.setCornerRadius(16);
gradientButton.setColor(getColor(R.color.colorGreen));
button.setBackground(gradientButton);

headerText.setText(_data.get(_position).getTitle().getRendered());
//excerptText.setText(Html.fromHtml(_data.get(_position).getExcerpt().getRendered()));

int idPost = _data.get(_position).getContentId();

//String newDate = _data.get(_position).getContentDate().substring(0,_data.get(_position).getContentDate().indexOf("T"));
//dateText.setText(newDate);

Pattern p = Pattern.compile("<p><a href=\\\"(.*?)\"><img loading=\\\"(.*?)\\\" class=\\\"(.*?)\" src=\\\"(.*?)\".*<\\/a>", Pattern.DOTALL);
Matcher m = p.matcher(_data.get(_position).getContent().getRendered());

while (m.find()) {
if (m.group(1).length() > 15) {

Log.wtf("API KEY IS REGEX 1", m.group(1) + "\n\n\n");

Picasso.get().load(m.group(1)).into(image);
GradientDrawable imageShape = new GradientDrawable();
imageShape.setCornerRadius(26);
image.setBackground(imageShape);
}
}
Log.wtf("Media URL", _data.get(_position).getLinks().getWpAttachment().get(0).getHref());
Log.wtf("Comments URL", _data.get(_position).getLinks().getReplies().get(0).getHref());


lin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent intent = new Intent(getApplicationContext(), PostActivity.class);

intent.putExtra("postPosition", _position);
startActivity(intent);
}
});

}

@Override
public long getItemId(int _index) {
return _index;
}

@Override
public int getItemCount() {
return _data.size();
// return (_data == null) ? 0 : _data.size();
}

public class ViewHolder extends RecyclerView.ViewHolder {
public ViewHolder(@NonNull View itemView) {
super(itemView);
}
}
}

public void onClickInit() {}

}
Loading

0 comments on commit e06acc1

Please sign in to comment.