diff --git a/.idea/misc.xml b/.idea/misc.xml
index 98c5c82..41f4f25 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -6,6 +6,13 @@
+
+
+
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index aab399e..31669d5 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -13,10 +13,10 @@
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/Theme.PexelsWallpaper">
-
+
-
+
diff --git a/app/src/main/java/com/mjtech/pexelswallpaper/WallpaperAdapter.java b/app/src/main/java/com/mjtech/pexelswallpaper/Adapters/WallpaperAdapter.java
similarity index 85%
rename from app/src/main/java/com/mjtech/pexelswallpaper/WallpaperAdapter.java
rename to app/src/main/java/com/mjtech/pexelswallpaper/Adapters/WallpaperAdapter.java
index 157e174..70ac11d 100644
--- a/app/src/main/java/com/mjtech/pexelswallpaper/WallpaperAdapter.java
+++ b/app/src/main/java/com/mjtech/pexelswallpaper/Adapters/WallpaperAdapter.java
@@ -1,4 +1,4 @@
-package com.mjtech.pexelswallpaper;
+package com.mjtech.pexelswallpaper.Adapters;
import android.content.Context;
import android.content.Intent;
@@ -11,6 +11,9 @@
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
+import com.mjtech.pexelswallpaper.R;
+import com.mjtech.pexelswallpaper.Models.WallpaperModel;
+import com.mjtech.pexelswallpaper.activities.FullScreenWallpaper;
import java.util.List;
@@ -38,7 +41,7 @@ public void onBindViewHolder(@NonNull WallpaperViewHolder holder, int position)
holder.imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- context.startActivity(new Intent(context,FullScreenWallpaper.class)
+ context.startActivity(new Intent(context, FullScreenWallpaper.class)
.putExtra("originalUrl",wallpaperModelList.get(position).getOriginalUrl()));
}
});
diff --git a/app/src/main/java/com/mjtech/pexelswallpaper/WallpaperModel.java b/app/src/main/java/com/mjtech/pexelswallpaper/Models/WallpaperModel.java
similarity index 94%
rename from app/src/main/java/com/mjtech/pexelswallpaper/WallpaperModel.java
rename to app/src/main/java/com/mjtech/pexelswallpaper/Models/WallpaperModel.java
index 37b5e8d..c290f5c 100644
--- a/app/src/main/java/com/mjtech/pexelswallpaper/WallpaperModel.java
+++ b/app/src/main/java/com/mjtech/pexelswallpaper/Models/WallpaperModel.java
@@ -1,4 +1,4 @@
-package com.mjtech.pexelswallpaper;
+package com.mjtech.pexelswallpaper.Models;
public class WallpaperModel {
diff --git a/app/src/main/java/com/mjtech/pexelswallpaper/FullScreenWallpaper.java b/app/src/main/java/com/mjtech/pexelswallpaper/activities/FullScreenWallpaper.java
similarity index 96%
rename from app/src/main/java/com/mjtech/pexelswallpaper/FullScreenWallpaper.java
rename to app/src/main/java/com/mjtech/pexelswallpaper/activities/FullScreenWallpaper.java
index cf8b3fc..6275643 100644
--- a/app/src/main/java/com/mjtech/pexelswallpaper/FullScreenWallpaper.java
+++ b/app/src/main/java/com/mjtech/pexelswallpaper/activities/FullScreenWallpaper.java
@@ -1,4 +1,4 @@
-package com.mjtech.pexelswallpaper;
+package com.mjtech.pexelswallpaper.activities;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatImageButton;
@@ -16,6 +16,7 @@
import com.bumptech.glide.Glide;
import com.github.chrisbanes.photoview.PhotoView;
+import com.mjtech.pexelswallpaper.R;
import java.io.IOException;
import java.util.Objects;
diff --git a/app/src/main/java/com/mjtech/pexelswallpaper/MainActivity.java b/app/src/main/java/com/mjtech/pexelswallpaper/activities/MainActivity.java
similarity index 74%
rename from app/src/main/java/com/mjtech/pexelswallpaper/MainActivity.java
rename to app/src/main/java/com/mjtech/pexelswallpaper/activities/MainActivity.java
index 4024ae5..197e059 100644
--- a/app/src/main/java/com/mjtech/pexelswallpaper/MainActivity.java
+++ b/app/src/main/java/com/mjtech/pexelswallpaper/activities/MainActivity.java
@@ -1,8 +1,6 @@
-package com.mjtech.pexelswallpaper;
+package com.mjtech.pexelswallpaper.activities;
import androidx.annotation.NonNull;
-import androidx.annotation.RequiresApi;
-import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatEditText;
import androidx.appcompat.widget.AppCompatImageButton;
@@ -10,16 +8,8 @@
import androidx.recyclerview.widget.RecyclerView;
import android.annotation.SuppressLint;
-import android.content.DialogInterface;
-import android.os.Build;
import android.os.Bundle;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
import android.widget.AbsListView;
-import android.widget.Button;
-import android.widget.EditText;
-import android.widget.ImageButton;
import android.widget.Toast;
import com.android.volley.AuthFailureError;
@@ -29,6 +19,9 @@
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
+import com.mjtech.pexelswallpaper.R;
+import com.mjtech.pexelswallpaper.Adapters.WallpaperAdapter;
+import com.mjtech.pexelswallpaper.Models.WallpaperModel;
import org.json.JSONArray;
import org.json.JSONException;
@@ -154,6 +147,7 @@ public Map getHeaders() throws AuthFailureError {
}
+ // Get Data Api Fun
// Uri https://api.pexels.com/v1/curated/?page="+pageNumber+"&per_page=80
public void fetchWallpaper() {
StringRequest request = new StringRequest(Request.Method.GET, "https://api.pexels.com/v1/curated/?page=" + pageNumber + "&per_page=80",
@@ -214,6 +208,7 @@ public Map getHeaders() throws AuthFailureError {
requestQueue.add(request);
}
+ // Old Search Button function
/*
@Override
public boolean onCreateOptionsMenu(Menu menu) {
@@ -309,4 +304,100 @@ public Map getHeaders() throws AuthFailureError {
}
return super.onOptionsItemSelected(item);
}*/
+
+ @Override
+ public void onBackPressed() {
+ super.onBackPressed();
+
+ }
+
+ // Kotlin Code
+ /*
+ private lateinit var recyclerView: RecyclerView
+ private lateinit var edittext: AppCompatEditText
+ private lateinit var searchOption: AppCompatImageButton
+ lateinit var wallpaperAdapter: WallpaperAdapter
+ lateinit var wallpaperModelList: MutableList
+ var pageNumber = 1
+ var isScrolling = false
+ var currentItems:Int = 0
+ var totalItems :Int = 0
+ var scrollOutItems: Int = 0
+
+ supportActionBar?.hide()
+
+
+ recyclerView = findViewById(R.id.recyclerView)
+ searchOption = findViewById(R.id.searchOption)
+ edittext = findViewById(R.id.edittext)
+ wallpaperModelList = ArrayList()
+ wallpaperAdapter = WallpaperAdapter(this, wallpaperModelList)
+
+ recyclerView.adapter = wallpaperAdapter
+
+ val gridLayoutManager = GridLayoutManager(this, 2)
+ recyclerView.layoutManager = gridLayoutManager
+
+ recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
+ override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
+ super.onScrollStateChanged(recyclerView, newState)
+ if (newState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
+ isScrolling = true
+ }
+ }
+
+ override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
+ super.onScrolled(recyclerView, dx, dy)
+ currentItems = gridLayoutManager.childCount
+ totalItems = gridLayoutManager.itemCount
+ scrollOutItems = gridLayoutManager.findFirstCompletelyVisibleItemPosition()
+ if (isScrolling && ((currentItems + scrollOutItems) == totalItems)) {
+ isScrolling = false
+ fetchWallpaper()
+ }
+ }
+ })
+
+ fetchWallpaper()
+ }
+
+ fun fetchWallpaper() {
+ val request: StringRequest = object : StringRequest(
+ Method.GET,
+ "https://api.pexels.com/v1/curated/?page=$pageNumber&per_page=80", // StringRequest request = new StringRequest(Request.Method.GET, url,
+ Response.Listener { response ->
+ try {
+ val jsonObject = JSONObject(response)
+ val jsonArray = jsonObject.getJSONArray("photos")
+ val length = jsonArray.length()
+ for (i in 0 until length) {
+ val `object` = jsonArray.getJSONObject(i)
+ val id = `object`.getInt("id")
+ val objectImages = `object`.getJSONObject("src")
+ val originalUrl = objectImages.getString("original")
+ val mediumUrl = objectImages.getString("medium")
+ val wallpaperModel = WallpaperModel(id, originalUrl, mediumUrl)
+ wallpaperModelList.add(wallpaperModel)
+//
+ }
+ wallpaperAdapter.notifyDataSetChanged()
+ pageNumber++
+
+ } catch (e: JSONException) {
+ e.printStackTrace()
+ Toast.makeText(this@MainActivity, "ERROR" + e.message, Toast.LENGTH_SHORT)
+ .show()
+ }
+ }, Response.ErrorListener { }) {
+ @Throws(AuthFailureError::class)
+ override fun getHeaders(): Map {
+ val params: MutableMap = HashMap()
+ params["Authorization"] = "563492ad6f917000010000016190f711658e4eb1a96ff1213e707d57"
+ return params
+ }
+ }
+ val requestQueue = Volley.newRequestQueue(applicationContext)
+ requestQueue.add(request)
+ }
+ */
}
diff --git a/app/src/main/java/com/mjtech/pexelswallpaper/kotlin/MainActivityKotlin.kt b/app/src/main/java/com/mjtech/pexelswallpaper/kotlin/MainActivityKotlin.kt
new file mode 100644
index 0000000..76f02f4
--- /dev/null
+++ b/app/src/main/java/com/mjtech/pexelswallpaper/kotlin/MainActivityKotlin.kt
@@ -0,0 +1,118 @@
+package com.mjtech.pexelswallpaper.kotlin
+
+/*
+
+import android.os.Bundle
+import android.widget.AbsListView
+import android.widget.Toast
+import androidx.appcompat.app.AppCompatActivity
+import androidx.appcompat.widget.AppCompatEditText
+import androidx.appcompat.widget.AppCompatImageButton
+import androidx.recyclerview.widget.GridLayoutManager
+import androidx.recyclerview.widget.RecyclerView
+import com.android.volley.AuthFailureError
+import com.android.volley.Response
+import com.android.volley.toolbox.StringRequest
+import com.android.volley.toolbox.Volley
+import org.json.JSONException
+import org.json.JSONObject
+
+
+class MainActivityKotlin : AppCompatActivity() {
+ //private lateinit var binding :ActivityMainBinding
+
+ private lateinit var recyclerView: RecyclerView
+ private lateinit var edittext: AppCompatEditText
+ private lateinit var searchOption: AppCompatImageButton
+ lateinit var wallpaperAdapter: WallpaperAdapter
+ lateinit var wallpaperModelList: MutableList
+ var pageNumber = 1
+ var isScrolling = false
+ var currentItems:Int = 0
+ var totalItems :Int = 0
+ var scrollOutItems: Int = 0
+
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ //binding = ActivityMainBinding.inflate(layoutInflater)
+// setContentView(R.layout.activity_main)
+ supportActionBar?.hide()
+
+// binding.webViewSite.loadUrl("file:///android_asset/index.html")
+// binding.webViewSite.settings.javaScriptEnabled = true
+// binding.webViewSite.webViewClient = WebViewClient()
+
+ recyclerView = findViewById(R.id.recyclerView)
+ searchOption = findViewById(R.id.searchOption)
+ edittext = findViewById(R.id.edittext)
+ wallpaperModelList = ArrayList()
+ wallpaperAdapter = WallpaperAdapter(this, wallpaperModelList)
+
+ recyclerView.adapter = wallpaperAdapter
+
+ val gridLayoutManager = GridLayoutManager(this, 2)
+ recyclerView.layoutManager = gridLayoutManager
+
+ recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
+ override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
+ super.onScrollStateChanged(recyclerView, newState)
+ if (newState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
+ isScrolling = true
+ }
+ }
+
+ override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
+ super.onScrolled(recyclerView, dx, dy)
+ currentItems = gridLayoutManager.childCount
+ totalItems = gridLayoutManager.itemCount
+ scrollOutItems = gridLayoutManager.findFirstCompletelyVisibleItemPosition()
+ if (isScrolling && ((currentItems + scrollOutItems) == totalItems)) {
+ isScrolling = false
+ fetchWallpaper()
+ }
+ }
+ })
+
+ fetchWallpaper()
+ }
+
+ fun fetchWallpaper() {
+ val request: StringRequest = object : StringRequest(
+ Method.GET,
+ "https://api.pexels.com/v1/curated/?page=$pageNumber&per_page=80", // StringRequest request = new StringRequest(Request.Method.GET, url,
+ Response.Listener { response ->
+ try {
+ val jsonObject = JSONObject(response)
+ val jsonArray = jsonObject.getJSONArray("photos")
+ val length = jsonArray.length()
+ for (i in 0 until length) {
+ val `object` = jsonArray.getJSONObject(i)
+ val id = `object`.getInt("id")
+ val objectImages = `object`.getJSONObject("src")
+ val originalUrl = objectImages.getString("original")
+ val mediumUrl = objectImages.getString("medium")
+ val wallpaperModel = WallpaperModel(id, originalUrl, mediumUrl)
+ wallpaperModelList.add(wallpaperModel)
+//
+ }
+ wallpaperAdapter.notifyDataSetChanged()
+ pageNumber++
+
+ } catch (e: JSONException) {
+ e.printStackTrace()
+ Toast.makeText(this@MainActivity, "ERROR" + e.message, Toast.LENGTH_SHORT)
+ .show()
+ }
+ }, Response.ErrorListener { }) {
+ @Throws(AuthFailureError::class)
+ override fun getHeaders(): Map {
+ val params: MutableMap = HashMap()
+ params["Authorization"] = "563492ad6f917000010000016190f711658e4eb1a96ff1213e707d57"
+ return params
+ }
+ }
+ val requestQueue = Volley.newRequestQueue(applicationContext)
+ requestQueue.add(request)
+ }
+}*/
diff --git a/app/src/main/java/com/mjtech/pexelswallpaper/kotlin/Models.kt b/app/src/main/java/com/mjtech/pexelswallpaper/kotlin/Models.kt
new file mode 100644
index 0000000..8adfd9d
--- /dev/null
+++ b/app/src/main/java/com/mjtech/pexelswallpaper/kotlin/Models.kt
@@ -0,0 +1,8 @@
+package com.mjtech.pexelswallpaper.kotlin
+
+/*
+data class WallpaperModel(
+ val id: Int,
+ val originalUrl: String,
+ val mediumUrl: String
+)*/
diff --git a/app/src/main/java/com/mjtech/pexelswallpaper/kotlin/WallpaperAdapterKotlin.kt b/app/src/main/java/com/mjtech/pexelswallpaper/kotlin/WallpaperAdapterKotlin.kt
new file mode 100644
index 0000000..a8b11ef
--- /dev/null
+++ b/app/src/main/java/com/mjtech/pexelswallpaper/kotlin/WallpaperAdapterKotlin.kt
@@ -0,0 +1,51 @@
+package com.mjtech.pexelswallpaper.kotlin
+
+class WallpaperAdapterKotlin {
+}
+/*
+
+import android.content.Context
+import android.content.Intent
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.ImageView
+import androidx.recyclerview.widget.RecyclerView
+import com.bumptech.glide.Glide
+
+class WallpaperAdapter(
+ private val context: Context,
+ private val wallpaperModelList: List
+) :
+ RecyclerView.Adapter() {
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WallpaperViewHolder {
+ val view = LayoutInflater.from(context).inflate(R.layout.image_item, parent, false)
+ return WallpaperViewHolder(view)
+ }
+
+ override fun onBindViewHolder(holder: WallpaperViewHolder, position: Int) {
+
+ Glide.with(context).load(wallpaperModelList[position].mediumUrl).into(holder.imageView)
+// Glide.with(context).load(wallpaperModelList[position]).into(holder.imageView)
+
+ holder.imageView.setOnClickListener {
+ context.startActivity(
+ Intent(context, FullScreenWallpaper::class.java)
+ .putExtra("originalUrl", wallpaperModelList[position].originalUrl)
+// .putExtra("originalUrl",wallpaperModelList[position])
+ )
+ }
+ }
+
+ override fun getItemCount(): Int {
+ return wallpaperModelList.size
+ }
+}
+
+class WallpaperViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
+ var imageView: ImageView
+
+ init {
+ imageView = itemView.findViewById(R.id.imageViewItem)
+ }
+}*/
diff --git a/app/src/main/res/layout/activity_full_screen_wallpaper.xml b/app/src/main/res/layout/activity_full_screen_wallpaper.xml
index e8e727a..c5d7d04 100644
--- a/app/src/main/res/layout/activity_full_screen_wallpaper.xml
+++ b/app/src/main/res/layout/activity_full_screen_wallpaper.xml
@@ -6,7 +6,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/DarkMode"
- tools:context=".FullScreenWallpaper">
+ tools:context=".activities.FullScreenWallpaper">
- Pexels Wallpaper
+ Pixels Wallpaper
TODO
Search Any Image Here
- SET Wallpaper
+ Set Wallpaper
\ No newline at end of file