From e06acc11a22b67f6fac483ab3dcc964da9e0f10e Mon Sep 17 00:00:00 2001 From: induiduel Date: Fri, 9 Apr 2021 00:50:54 +0300 Subject: [PATCH] First Release --- .gitignore | 15 -- app/.gitignore | 1 - app/build.gradle | 16 +- app/src/main/AndroidManifest.xml | 8 +- .../word/activities/MainActivity.java | 187 +++++++++++++++--- .../word/activities/PostActivity.java | 148 ++++++++++++++ .../main/res/drawable/bottom_nav_colors.xml | 4 +- app/src/main/res/layout/activity_main.xml | 15 +- app/src/main/res/layout/activity_post.xml | 94 +++++++++ app/src/main/res/layout/bottom_navigation.xml | 2 +- app/src/main/res/layout/custom_post.xml | 148 ++++++++++++++ app/src/main/res/layout/gridlayout_custom.xml | 111 +++++++++++ app/src/main/res/values-night/themes.xml | 16 -- app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/themes.xml | 6 +- .../com/induiduel/word/ExampleUnitTest.java | 4 + settings.gradle | 1 + wordpress/build.gradle | 42 ++++ wordpress/consumer-rules.pro | 0 wordpress/proguard-rules.pro | 21 ++ .../wordpress/ExampleInstrumentedTest.java | 26 +++ wordpress/src/main/AndroidManifest.xml | 9 + .../wordpress}/config/InitializeApp.java | 2 +- .../wordpress}/okhttp/RequestNetwork.java | 2 +- .../okhttp/RequestNetworkController.java | 4 +- .../wordpress}/utils/InvalidUrl.java | 2 +- .../wordpress}/utils/JsonConverter.java | 7 +- .../wordpress/wp}/filter/Parameters.java | 20 +- .../wordpress/wp}/read/ReadCategories.java | 2 +- .../wordpress/wp}/read/ReadComments.java | 2 +- .../wordpress/wp}/read/ReadMedia.java | 2 +- .../wordpress/wp}/read/ReadPosts.java | 3 +- .../wordpress/wp}/read/ReadSearch.java | 2 +- .../wordpress/wp}/read/ReadUsers.java | 2 +- .../induiduel/wordpress/ExampleUnitTest.java | 17 ++ 35 files changed, 850 insertions(+), 92 deletions(-) delete mode 100644 .gitignore delete mode 100644 app/.gitignore create mode 100644 app/src/main/java/com/induiduel/word/activities/PostActivity.java create mode 100644 app/src/main/res/layout/activity_post.xml create mode 100644 app/src/main/res/layout/custom_post.xml create mode 100644 app/src/main/res/layout/gridlayout_custom.xml delete mode 100644 app/src/main/res/values-night/themes.xml create mode 100644 wordpress/build.gradle create mode 100644 wordpress/consumer-rules.pro create mode 100644 wordpress/proguard-rules.pro create mode 100644 wordpress/src/androidTest/java/com/induiduel/wordpress/ExampleInstrumentedTest.java create mode 100644 wordpress/src/main/AndroidManifest.xml rename {app/src/main/java/com/induiduel/word => wordpress/src/main/java/com/induiduel/wordpress}/config/InitializeApp.java (60%) rename {app/src/main/java/com/induiduel/word/access => wordpress/src/main/java/com/induiduel/wordpress}/okhttp/RequestNetwork.java (96%) rename {app/src/main/java/com/induiduel/word/access => wordpress/src/main/java/com/induiduel/wordpress}/okhttp/RequestNetworkController.java (96%) rename {app/src/main/java/com/induiduel/word => wordpress/src/main/java/com/induiduel/wordpress}/utils/InvalidUrl.java (85%) rename {app/src/main/java/com/induiduel/word => wordpress/src/main/java/com/induiduel/wordpress}/utils/JsonConverter.java (81%) rename {app/src/main/java/com/induiduel/word/api/wordpress => wordpress/src/main/java/com/induiduel/wordpress/wp}/filter/Parameters.java (91%) rename {app/src/main/java/com/induiduel/word/api/wordpress => wordpress/src/main/java/com/induiduel/wordpress/wp}/read/ReadCategories.java (98%) rename {app/src/main/java/com/induiduel/word/api/wordpress => wordpress/src/main/java/com/induiduel/wordpress/wp}/read/ReadComments.java (98%) rename {app/src/main/java/com/induiduel/word/api/wordpress => wordpress/src/main/java/com/induiduel/wordpress/wp}/read/ReadMedia.java (99%) rename {app/src/main/java/com/induiduel/word/api/wordpress => wordpress/src/main/java/com/induiduel/wordpress/wp}/read/ReadPosts.java (99%) rename {app/src/main/java/com/induiduel/word/api/wordpress => wordpress/src/main/java/com/induiduel/wordpress/wp}/read/ReadSearch.java (97%) rename {app/src/main/java/com/induiduel/word/api/wordpress => wordpress/src/main/java/com/induiduel/wordpress/wp}/read/ReadUsers.java (98%) create mode 100644 wordpress/src/test/java/com/induiduel/wordpress/ExampleUnitTest.java diff --git a/.gitignore b/.gitignore deleted file mode 100644 index aa724b7..0000000 --- a/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -*.iml -.gradle -/local.properties -/.idea/caches -/.idea/libraries -/.idea/modules.xml -/.idea/workspace.xml -/.idea/navEditor.xml -/.idea/assetWizardSettings.xml -.DS_Store -/build -/captures -.externalNativeBuild -.cxx -local.properties diff --git a/app/.gitignore b/app/.gitignore deleted file mode 100644 index 42afabf..0000000 --- a/app/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index e9879ab..61c7e54 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,9 +31,9 @@ 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' @@ -41,14 +41,18 @@ dependencies { 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') } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9b3a1cc..9b95fc9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,19 +1,22 @@ + + + android:usesCleartextTraffic="true"> + @@ -21,6 +24,7 @@ + diff --git a/app/src/main/java/com/induiduel/word/activities/MainActivity.java b/app/src/main/java/com/induiduel/word/activities/MainActivity.java index e8e52b2..78ecf9c 100644 --- a/app/src/main/java/com/induiduel/word/activities/MainActivity.java +++ b/app/src/main/java/com/induiduel/word/activities/MainActivity.java @@ -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> arrayComment; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -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 responseHeaders) { - - try { - ArrayList readPostsArrayList = new Gson().fromJson(response, new TypeToken>() {}.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 readPostsArrayList = new Gson().fromJson(response, new TypeToken>() { + }.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 { + ArrayList _data; + + public RecyclerViewAdapterMain(ArrayList _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("

", 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() {} } \ No newline at end of file diff --git a/app/src/main/java/com/induiduel/word/activities/PostActivity.java b/app/src/main/java/com/induiduel/word/activities/PostActivity.java new file mode 100644 index 0000000..5e6d3d4 --- /dev/null +++ b/app/src/main/java/com/induiduel/word/activities/PostActivity.java @@ -0,0 +1,148 @@ +package com.induiduel.word.activities; + +import androidx.annotation.RequiresApi; +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Build; +import android.os.Bundle; +import android.text.Html; +import android.util.Log; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import com.induiduel.word.R; + +import com.induiduel.wordpress.wp.read.ReadPosts; +import com.squareup.picasso.Picasso; + +import java.util.ArrayList; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class PostActivity extends AppCompatActivity { + + public static String RESPONSE; + public int position; + ArrayList readPostsArrayList; + ImageView imageView1; + ImageView imageView2; + ImageView imageView3; + TextView headText; + TextView contentText; + + @RequiresApi(api = Build.VERSION_CODES.N) + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_post); + customLogic(); + customUi(); + setValues(); + if (!readPostsArrayList.isEmpty()) { + getImages(); + Log.wtf("PostActivity Read", String.valueOf(getIntent().getIntExtra("postPosition", 0))); + Log.wtf("PostActivity Post", readPostsArrayList.get(position).getLink()); + + } + + } + + private void customLogic() { + readPostsArrayList = new Gson().fromJson(RESPONSE, new TypeToken>() { + }.getType()); + position = getIntent().getIntExtra("postPosition", 0); + } + + @RequiresApi(api = Build.VERSION_CODES.N) + private void setValues(){ + headText.setText(readPostsArrayList.get(position).getTitle().getRendered()); + contentText.setText(removeUrl(Html.fromHtml(readPostsArrayList.get(position).getContent().getRendered(), Html.FROM_HTML_MODE_COMPACT | Html.FROM_HTML_MODE_LEGACY).toString())); + + Log.wtf("Content", contentText.getText().toString().replace("","")); + } + + private void customUi() { + headText = findViewById(R.id.headText); + contentText = findViewById(R.id.contentText); + imageView1 = findViewById(R.id.imageView1); + imageView2 = findViewById(R.id.imageView2); + imageView3 = findViewById(R.id.imageView3); + imageView1.setClipToOutline(true); + imageView2.setClipToOutline(true); + imageView3.setClipToOutline(true); + } + + private void getImages() { + Pattern p = Pattern.compile("\\\".*?\\\" - - + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 3349b1c..1c5b734 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -18,18 +18,21 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" + android:elevation="10dp" android:orientation="horizontal"> + android:paddingStart="4dp" + android:layout_height="match_parent" + tools:ignore="RtlSymmetry"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/bottom_navigation.xml b/app/src/main/res/layout/bottom_navigation.xml index e3f0229..74c4f5b 100644 --- a/app/src/main/res/layout/bottom_navigation.xml +++ b/app/src/main/res/layout/bottom_navigation.xml @@ -5,7 +5,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" - app:backgroundTint="@color/beyaz" + app:backgroundTint="@color/white" app:itemIconTint="@drawable/bottom_nav_colors" app:itemTextColor="@drawable/bottom_nav_colors" app:labelVisibilityMode="labeled" diff --git a/app/src/main/res/layout/custom_post.xml b/app/src/main/res/layout/custom_post.xml new file mode 100644 index 0000000..426673e --- /dev/null +++ b/app/src/main/res/layout/custom_post.xml @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/gridlayout_custom.xml b/app/src/main/res/layout/gridlayout_custom.xml new file mode 100644 index 0000000..a28d072 --- /dev/null +++ b/app/src/main/res/layout/gridlayout_custom.xml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + +